Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function entity($metadata) : QueryInterface
 {
     if (is_string($metadata)) {
         // Remove old namespace
         $metadata = strpos($metadata, '\\samson\\activerecord\\') !== false ? str_replace('\\samson\\activerecord\\', '', $metadata) : $metadata;
         $metadata = strpos($metadata, 'samson\\activerecord\\') !== false ? str_replace('samson\\activerecord\\', '', $metadata) : $metadata;
         // Capitalize and add cms namespace
         $metadata = strpos($metadata, '\\') === false ? 'samsoncms\\api\\generated\\' . ucfirst($metadata) : $metadata;
         $this->metadata = TableMetadata::fromClassName($metadata);
     } else {
         $this->metadata = $metadata;
     }
     $this->flush();
     return $this;
 }
Exemplo n.º 2
0
 /**
  * Fill entity instance fields from row column values according to entity value attributes.
  *
  * @param mixed $instance Entity instance
  * @param TableMetadata $metadata
  * @param array $row Database results row
  */
 protected function fillEntityFieldValues($instance, TableMetadata $metadata, array $row)
 {
     foreach ($row as $columnName => $columnValue) {
         // If database row has aliased field column
         if ($metadata->isColumnExists($columnName)) {
             $columnName = $metadata->getTableColumnAlias($columnName);
             // Store attribute value
             $instance->{$columnName} = $columnValue;
         }
     }
     // FIXME: Old activerecord pattern behavior
     $instance->id = (int) $row[$metadata->primaryField];
     // FIXME: Old activerecord pattern behavior
     $instance->attached = true;
     // Call handler for object filling
     $instance->filled();
 }
Exemplo n.º 3
0
 /** @see ArrayAccess::offsetExists() */
 public function offsetExists($offset)
 {
     return property_exists($this, $offset) || $this->metadata->isColumnExists($offset);
 }