/** * Return. * * @param KConfigInterface $config An optional KConfig object with configuration options * @param KServiceInterface $container A KServiceInterface object * * @return KServiceInstantiatable */ public static function getInstance(KConfigInterface $config, KServiceInterface $container) { if (!$container->has($config->service_identifier)) { $identifier = self::_identifier($config->service_identifier); $instance = AnDomain::getRepository($identifier, $config->toArray()); $container->set($config->service_identifier, $instance); } return $container->get($config->service_identifier); }
public static function getInstance(KConfigInterface $config, KServiceInterface $container) { $identifier = clone $config->service_identifier; $activity = $config->activity; if ($identifier->name != $activity->package) { $identifier->name = $activity->package; if (file_exists($identifier->filepath)) { // Use package activity message instead. return KService::get($identifier, $config->toArray()); } } $classname = $config->service_identifier->classname; return new $classname($config); }
/** * Attribute factory method. * * @param KConfigInterface $config An optional KConfig object with configuration options * * @return KServiceInstantiatable */ public static function setAttribute(KConfigInterface $config) { $description = $config->description; if (!$description) { throw new AnDomainAttributeException('description [AnDomainDescriptionAbstract] option is required'); } if (empty($config->type)) { $config->append(array('column' => KInflector::underscore($config->name))); $config->column = $description->getRepository()->getResources()->getColumn($config->column); if ($config->column) { $config->type = $config->column->type; } else { $config->type = 'string'; } } //if a default options is set then //making the property requires allows using default options //for cases when a property is null unless stated otherwise if (isset($config->default)) { /* $config->append(array( 'required'=>true )); */ } //prevents having a null value if //a default option is set or the require is set /* if ( $config->required || $config->default ) { $config->append(array( 'required' => true, 'default' => $config->type )); }*/ $config->append(array('column' => KInflector::underscore($config->name))); if (is_string($config->column)) { $config->column = $description->getRepository()->getResources()->getColumn($config->column); } if (!$config->column) { throw new AnDomainPropertyException('Property ' . $config->name . ' is mapped to an invalid column for entity ' . $description->getEntityIdentifier()); } $property = AnDomainPropertyAbstract::getInstance('attribute.property', $config); if ($config->key) { $description->addIdentifyingProperty($property); } return $property; }