Beispiel #1
0
 /**
  * 
  */
 public function unserialize($data)
 {
     $data = unserialize($data);
     $this->_repository = AnDomain::getRepository($data['identifier']);
     $this->_data = new AnDomainEntityData(new KConfig(array('entity' => $this)));
     $this->_data->setRowData($data['row']);
     $this->__service_container = $this->_repository->getService();
     $this->__service_identifier = $this->_repository->getIdentifier($data['identifier']);
 }
Beispiel #2
0
 /**
  * Constructor.
  *
  * @param KConfig $config An optional KConfig object with configuration options.
  */
 public function __construct(KConfig $config)
 {
     $this->_initialize($config);
     if (!empty($config->aliases)) {
         foreach ($config->aliases as $alias => $property) {
             $this->setAlias($property, $alias);
         }
     }
     $this->_entity_identifier = $config->entity_identifier;
     $this->_repository = $config->repository;
     if (!$this->_repository) {
         throw new AnDomainDescriptionException('repository [AnDomainRepositoryAbstract] option is required');
     }
     if ($config->inheritance) {
         $this->_inheritance_column = $config->inheritance->column;
         //an object can only be abstract if it's
         //supports single table inheritance
         $this->_is_abstract = $config->inheritance->abstract;
         if ($config->inheritance->ignore) {
             $ignore = (array) $config->inheritance['ignore'];
             foreach ($ignore as $class) {
                 $this->_class_alias[$class] = '';
             }
         }
     }
     if (is_string($this->_inheritance_column)) {
         $this->_inheritance_column = $this->_repository->getResources()->getColumn($this->_inheritance_column);
     }
     $this->_entity_identifier = $this->_repository->getIdentifier($config->entity_identifier);
     if (!$config->identity_property) {
         $columns = $this->_repository->getResources()->main()->getColumns();
         foreach ($columns as $column) {
             if ($column->primary) {
                 $config->identity_property = KInflector::variablize($column->name);
                 break;
             }
         }
     }
     $this->_identity_property = $config->identity_property;
     //try to generate some of the propreties
     //from the database columns
     if ($config->auto_generate) {
         //if auto generate default set the identity property with the primary key
         $config->append(array('attributes' => array($this->_identity_property => array('key' => true))));
         $attributes = $config['attributes'];
         $columns = $this->_repository->getResources()->main()->getColumns();
         foreach ($columns as $column) {
             $name = KInflector::variablize($column->name);
             //merge the existing attributes
             $attributes[$name] = array_merge(array('required' => $column->required, 'column' => $column, 'type' => $column->type, 'default' => $column->default), isset($attributes[$name]) ? $attributes[$name] : array());
         }
         $config['attributes'] = $attributes;
     }
 }