getColumns() публичный Метод

Get columns
public getColumns ( ) : Column[]
Результат Column[]
Пример #1
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;
         }
     }
 }
Пример #2
0
 /**
  * Compiles all columns for an entity
  *
  * @param Entity $md
  * @return array
  */
 private function compileColumns(Entity $md)
 {
     $out = [];
     $columns = $md->getColumns();
     foreach ($columns as $column) {
         $data = [Schema::COLUMN_TYPE => $column->getType()->value()];
         if ($column->isId()) {
             $data[Schema::COLUMN_ID] = true;
         }
         $default_getter = 'get' . Inflector::classify($column->getProperty());
         if ($column->getGetter() && $column->getGetter() != $default_getter) {
             $data[Schema::GETTER] = $column->getGetter();
         }
         $default_setter = 'set' . Inflector::classify($column->getProperty());
         if ($column->getSetter() && $column->getSetter() != $default_setter) {
             $data[Schema::SETTER] = $column->getSetter();
         }
         if ($column->getClassName()) {
             $data[Schema::COLUMN_CLASS] = $column->getClassName();
         }
         $out[$column->getName()] = $data;
     }
     $relationships = $md->getRelationships();
     foreach ($relationships as $relationship) {
         $data = [Schema::REL_ASSOCIATION => $relationship->getRelationshipType()->value(), Schema::REL_TARGET => $relationship->getTarget()];
         $default_getter = 'get' . Inflector::classify($relationship->getName());
         if ($relationship->getGetter() && $relationship->getGetter() != $default_getter) {
             $data[Schema::GETTER] = $relationship->getGetter();
         }
         $default_setter = 'set' . Inflector::classify($relationship->getName());
         if ($relationship->getSetter() && $relationship->getSetter() != $default_setter) {
             $data[Schema::SETTER] = $relationship->getSetter();
         }
         if ($relationship->getInversedBy()) {
             $data[Schema::REL_INVERSED_BY] = $relationship->getInversedBy();
         }
         if ($relationship->getSortableBy()) {
             $data[Schema::SORT_INDICES] = $this->compileSortables($relationship->getSortableBy());
         }
         $out[$relationship->getName()] = $data;
     }
     return $out;
 }