/** * Configurator * * @param KConfig $config Property Configuration * * @return void */ public function setConfig(KConfig $config) { $identifier = $config->description->getRepository()->getIdentifier(); if ($config->parent) { $this->_parent = KService::getIdentifier($config->parent); //adopt the child application if (!$this->_parent->application) { $this->_parent->application = $identifier->application; } } parent::setConfig($config); if ($config->child) { if (strpos($config->child, '.') === false) { $identifier = clone $this->_parent; $identifier->name = $config->child; $config->child = $identifier; } $this->_child = KService::getIdentifier($config->child); //adopt the parent application if (!$this->_child->application) { $this->_child->application = $identifier->application; } } $this->_parent_key = $config->parent_key; if (is_array($config->query)) { $config->query = new KConfig($config->query); } $this->_query_filters = $config->query; }
/** * Gets the service identifier. * * @return KServiceIdentifier * @see KObjectServiceable */ public final function getIdentifier($identifier = null) { if (isset($identifier)) { $result = $this->__service_container->getIdentifier($identifier); } else { $result = $this->__service_identifier; } return $result; }
/** * Gets the service identifier. * * @throws KObjectException if the service container has not been defined. * @return KServiceIdentifier * @see KObjectServiceable */ public final function getIdentifier($identifier = null) { if (isset($identifier)) { if (!isset($this->__service_container)) { throw new KObjectException("Failed to call " . get_class($this) . "::getIdentifier(). No service_container object defined."); } $result = $this->__service_container->getIdentifier($identifier); } else { $result = $this->__service_identifier; } return $result; }
/** * Configurator * * @param KConfig $config Property Configuration * * @return void */ public function setConfig(KConfig $config) { $identifier = $config->description->getRepository()->getIdentifier(); $config->child = $config->through; parent::setConfig($config); $this->_target = KService::getIdentifier($config->target); if (!$this->_target->application) { $this->_target->application = $identifier->application; } $this->_target_child_key = $config->target_child_key; $this->_target_parent_key = $config->target_parent_key; //set the junction alias (the connecting table alias) $this->_junction_alias = $config->as; }
/** * Adds an authorizer. * * @param LibBaseDomainAuthorizerAbstract $authorizer The authorizer object */ public function addAuthorizer($authorizer) { if (!$authorizer instanceof LibBaseDomainAuthorizerAbstract) { if (is_string($authorizer) && strpos($authorizer, '.') === false) { //create identifier $identifier = clone $this->_repository->getIdentifier(); $identifier->path = array('domain', 'authorizer'); $identifier->name = $authorizer; register_default(array('identifier' => $identifier, 'prefix' => $this->_repository->getClone())); } else { $identifier = KService::getIdentifier($authorizer); } $authorizer = $identifier; $authorizer = KService::get($authorizer); } array_unshift($this->_authorizers, $authorizer); }
/** * Constructor */ public function __construct($dispatcher, $config = array()) { if (!$config instanceof KConfig) { $config = new KConfig($config); } //Inject the identifier $config->service_identifier = KService::getIdentifier('plg:koowa.' . $config['name']); //Inject the service container $config->service_container = KService::getInstance(); parent::__construct($config); //Set the plugin params if (is_string($config->params)) { $config->params = $this->_parseParams($config->params); } $this->_params = $config->params; //Setup lazy wiring for publishers we are subscribing too foreach ($config->event_publishers as $publisher) { KService::setConfig($publisher, array('event_subscribers' => array($this))); } if ($dispatcher instanceof KEventDispatcher) { $dispatcher->addEventSubscriber($this); } }
/** * Get a filter by identifier * * @return KTemplateFilterInterface */ public function getFilter($filter) { //Create the complete identifier if a partial identifier was passed if (is_string($filter) && strpos($filter, '.') === false) { $identifier = clone $this->getIdentifier(); $identifier->path = array('template', 'filter'); $identifier->name = $filter; } else { $identifier = KService::getIdentifier($filter); } if (!isset($this->_filters[$identifier->name])) { $filter = KService::get($identifier); if (!$filter instanceof KTemplateFilterInterface) { throw new KTemplateException("Template filter {$identifier} does not implement KTemplateFilterInterface"); } } else { $filter = $this->_filters[$identifier->name]; } return $filter; }
/** * Load a class based on an identifier * * @param string|object The identifier or identifier object * @return boolean Returns TRUE on success throws exception on failure */ public function loadIdentifier($identifier) { $result = false; $identifier = KService::getIdentifier($identifier); //Get the path $path = $identifier->filepath; if ($path !== false) { $result = self::loadFile($path); } return $result; }
/** * Constructor */ function __construct($dispatcher, $config = array()) { if (isset($config['params'])) { if ($config['params'] instanceof JRegistry) { $this->_params = $config['params']; } else { $this->_params = new JRegistry(); $this->_params->loadINI($config['params']); } } if (isset($config['name'])) { $this->_name = $config['name']; } if (isset($config['type'])) { $this->_type = $config['type']; } //Inject the identifier $config['service_identifier'] = KService::getIdentifier('plg:koowa.' . $this->_name); //Inject the service container $config['service_container'] = KService::getInstance(); //Inject the dispatcher $config['dispatcher'] = $dispatcher; parent::__construct(new KConfig($config)); }
static function renderComponent($name, $params = array()) { global $mainframe, $option; // Define component path define('JPATH_COMPONENT', JPATH_BASE . DS . 'components' . DS . $name); define('JPATH_COMPONENT_SITE', JPATH_SITE . DS . 'components' . DS . $name); define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR . DS . 'components' . DS . $name); if (!file_exists(JPATH_COMPONENT)) { JError::raiseError(404, JText::_('Component Not Found')); } $file = substr($name, 4); // get component path if ($mainframe->isAdmin() && file_exists(JPATH_COMPONENT . DS . 'admin.' . $file . '.php')) { $path = JPATH_COMPONENT . DS . 'admin.' . $file . '.php'; } else { $path = JPATH_COMPONENT . DS . $file . '.php'; } $identifier = KService::getIdentifier("com:{$file}.aliases"); $identifier->application = $mainframe->isAdmin() ? 'admin' : 'site'; $lang =& JFactory::getLanguage(); $lang->load($name); KLoader::getInstance()->loadIdentifier($identifier); //new way of doing it if (!file_exists($path)) { $identifier->name = 'dispatcher'; register_default(array('identifier' => $identifier, 'default' => 'ComBaseDispatcherDefault')); $dispatcher = ComBaseDispatcher::getInstance(); KService::setAlias('component.dispatcher', $dispatcher->getIdentifier()); KService::set('component.dispatcher', $dispatcher); return $dispatcher->dispatch(); } else { $contents = self::_renderComponent($path); // Build the component toolbar jimport('joomla.application.helper'); if (($path = JApplicationHelper::getPath('toolbar')) && $mainframe->isAdmin()) { // Get the task again, in case it has changed $task = JRequest::getString('task'); // Make the toolbar include_once $path; } return $contents; } }
/** * Instantiate a new entity based on the passed data This method is called from _create. * * @param string $identifier The identifier of the entity to instantiate * @param array $data The raw data * * @return AnDomainEntityAbstract */ protected function _instantiateEntity($identifier, $data) { //since the identifier doesn't have an //application set, it gets the application of the parent //repository $identifier = KService::getIdentifier($identifier); $identifier->application = $this->getIdentifier()->application; return clone AnDomain::getRepository($identifier)->getClone(); }
/** * Materialize a many-to-one relationship for the entity and the data from * the database. * * @param AnDomainEntityAbstract $instance The entity whose relationship it's materializing for * @param array $data The row data * * @return AnDomainProxyEntity */ public function materialize(array $data, $instance) { if (empty($data)) { return; } if (!$this->isMaterializable($data)) { throw new AnDomainExceptionMapping($this->getName() . ' Mapping Failed'); } $child_key = $this->_child_column->key(); //get parent value $parent_value = $data[$child_key]; //get parent class identifier //if relationsip is polymorphic then get the type from //the data if ($this->_polymorphic) { $key = $this->_type_column->key(); $parent = isset($data[$key]) ? $data[$key] : null; if ($parent) { $parent = KService::getIdentifier($parent); if (!$parent->application) { $parent->application = $this->_child->application; } } } else { $parent = $this->_parent; } //if any of the parent and parent value is missing then //nullify the relationship if (empty($parent) || empty($parent_value)) { return; } $config = array(); $config['relationship'] = $this; $config['value'] = $parent_value; $config['property'] = $this->_parent_key; $config['service_identifier'] = AnDomain::getRepository($parent)->getDescription()->getEntityIdentifier(); return new AnDomainEntityProxy(new KConfig($config)); }
/** * Constructor */ function __construct($dispatcher, $config = array()) { if (isset($config['params'])) { if ($config['params'] instanceof JRegistry) { $this->_params = $config['params']; } else { $this->_params = new JRegistry(); if (version_compare(JVERSION, '1.6', '<')) { $this->_params->loadINI($config['params']); } else { $this->_params->loadString($config['params'], 'INI'); } } } if (isset($config['name'])) { $this->_name = $config['name']; } if (isset($config['type'])) { $this->_type = $config['type']; } //Inject the identifier $config['service_identifier'] = KService::getIdentifier('plg:koowa.' . $this->_name); //Inject the service container $config['service_container'] = KService::getInstance(); //Inject the dispatcher $config['dispatcher'] = KService::get('com://admin/default.event.dispatcher'); parent::__construct(new KConfig($config)); }
/** * Entity Identifers must have application in their path. This method set the * application of an identifier if the path is missing. * * @param string $identifier Entity Identifier * * @return KServiceIdentifier */ public static function getEntityIdentifier($identifier) { $identifier = KService::getIdentifier($identifier); if (!$identifier->basepath) { $adapters = KService::get('koowa:loader')->getAdapters(); $basepath = pick($adapters[$identifier->type]->getBasePath(), JPATH_BASE); $applications = array_flip(KServiceIdentifier::getApplications()); if (isset($applications[$basepath])) { $identifier->application = $applications[$basepath]; $identifier->basepath = $basepath; } } return $identifier; }