Inheritance: extends Eloquent\Enumeration\AbstractEnumeration
 /**
  * Parse a ColumnAnnotation and return a Column object
  *
  * @param ColumnAnnotation $column_annotation
  * @param string           $name
  * @return Column
  */
 private function parseColumnAnnotation(ColumnAnnotation $column_annotation, $name)
 {
     $column = new Column($name);
     /** @noinspection PhpParamsInspection */
     $column->setType(FieldType::memberByValue($column_annotation->type));
     $column->setName($column_annotation->name);
     $column->setGetter($column_annotation->getter);
     $column->setSetter($column_annotation->setter);
     $column->setClassName($column_annotation->class_name);
     return $column;
 }
示例#2
0
 /**
  * Deserialise the entity
  *
  * @param Entity         $metadata Metadata object to match the entity
  * @param SerialisedData $data     Data to deserialise
  * @param object         $entity   Entity to hydrate
  */
 public function deserialise(Entity $metadata, SerialisedData $data, $entity)
 {
     // Using $assoc = true is ~ 10-20% quicker on PHP 5.3
     // Source: http://stackoverflow.com/questions/8498114/should-i-use-an-associative-array-or-an-object
     $raw = json_decode($data->getData(), true, self::ENCODE_DEPTH);
     foreach ($metadata->getColumns() as $column) {
         $setter = $column->getSetter();
         $field = $column->getName();
         $value = isset($raw[$field]) ? $raw[$field] : null;
         switch ($column->getType()) {
             default:
                 break;
             case FieldType::DATETIME():
                 $entity->{$setter}($this->deserialiseDateTime($value));
                 break;
             case FieldType::INT():
                 $entity->{$setter}((int) $value);
                 break;
             case FieldType::STRING():
                 $entity->{$setter}((string) $value);
                 break;
             case FieldType::DECIMAL():
                 $entity->{$setter}((double) $value);
                 break;
             case FieldType::BOOL():
                 $entity->{$setter}((bool) $value);
                 break;
             case FieldType::SET():
                 $entity->{$setter}(json_decode($value, true));
                 break;
             case FieldType::OBJECT():
                 $entity->{$setter}($this->deserialiseObject($value, $column->getClassName()));
                 break;
         }
     }
 }
示例#3
0
文件: Column.php 项目: bravo3/orm
 /**
  * @param string $property
  */
 public function __construct($property)
 {
     $this->property = $property;
     $this->type = FieldType::STRING();
 }
示例#4
0
文件: YamlMapper.php 项目: bravo3/orm
 /**
  * Create a column from schema
  *
  * @param string $property
  * @param array  $column_schema
  * @return Column
  */
 private function createColumn($property, array $column_schema)
 {
     $column = new Column($property);
     $column->setId($this->getNode($column_schema, Schema::COLUMN_ID, false, false));
     $column->setGetter($this->getNode($column_schema, Schema::GETTER, false));
     $column->setSetter($this->getNode($column_schema, Schema::SETTER, false));
     $column->setClassName($this->getNode($column_schema, Schema::COLUMN_CLASS, false));
     $column->setProperty($property);
     /** @var FieldType $type */
     $type = FieldType::memberByValue($this->getNode($column_schema, Schema::COLUMN_TYPE, false, 'string'));
     $column->setType($type);
     return $column;
 }