PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Aleksandar Zivanovic   File Entity   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example of how to use fEntity
Class: File Entity
Store and retrieve objects in encrypted files
Author: By
Last change:
Date: 8 years ago
Size: 1,677 bytes
 

Contents

Class file image Download
<?php

require_once 'fEntity.php';

/**
 * Basic example of how to use fEntity (File Entity) class
 *
 * First we need class that will extend our fEntity.
 */
class ExampleEntity extends fEntity
{
   
/**
     * Primary key field holds value that represents
     * name of primary key.
     *
     * Primary key is used for method fEntity::get
     *
     * @var string
     */
   
protected $primaryKey = 'firstName';

   
/**
     * getName is required method.
     * It is used to get entity's name
     *
     * @return string
     */
   
public function getName()
    {
        return
'example';
    }
}

/**
 * Entity acts same as stdClass, so it means that properties that we want to store
 * doesn't need to be defined in class itself.
 *
 * Only property that presents fEntity::$primaryKey MUST be defined.
 */


/**
 * Holds empty instance of ExampleEntity class
 * that we will use to test our fEntity
 *
 * @var ExampleEntity
 */
$entity = new ExampleEntity();

// Set one property
$entity->firstName = 'First';

// Set another propety
$entity->lastName = 'Last';

/**
 * Trigger save - save will create encoded file
 * in directory that is defined in fEntity class
 *
 * In case that entity already exists
 * default action is "do nothing", but if we
 * pass firts parameter of fEntity::save as true
 * or positive value - it will overwrite existing
 *
 */
$entity->save();


/**
 * Using fEntity::get(value) we fetch our file entity
 * it will use fEntity::$primaryKey to map with get() value
 */
var_dump($entity->get('First'));


// More updates comming soon
// Next release will allow multiple criteria
// better storing system