/** * 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) { $identifier = clone $identifier; $identifier->package = str_replace('com_', '', $data['option']); register_default(array('identifier' => $identifier, 'default' => array('ComComponentsDomainEntityComponent', 'LibComponentsDomainEntityComponent'))); return clone AnDomain::getRepository($identifier)->getClone(); }
/** * Sets the default view to the comment views. * * @param stirng $view * * @return ComBaseControllerComment */ public function setView($view) { parent::setView($view); if (!$this->_view instanceof LibBaseViewAbstract) { $view = KInflector::isPlural($view) ? 'comments' : 'comment'; $defaults[] = 'ComBaseView' . ucfirst($view) . ucfirst($this->_view->name); register_default(array('identifier' => $this->_view, 'default' => $defaults)); } return $this; }
/** * Get a toolbar by identifier. * * @return KControllerToolbarAbstract */ public function getToolbar($toolbar, $config = array()) { if (is_string($toolbar)) { //if actorbar or menu alawys default to the base if (in_array($toolbar, array('actorbar', 'menubar'))) { $identifier = clone $this->getIdentifier(); $identifier->path = array('controller', 'toolbar'); $identifier->name = $toolbar; register_default(array('identifier' => $identifier, 'default' => 'ComBaseControllerToolbar' . ucfirst($toolbar))); $toolbar = $identifier; } } return parent::getToolbar($toolbar, $config); }
/** * Constructor. * * @param object An optional KConfig object with configuration options */ public function __construct(KConfig $config) { parent::__construct($config); $identfier = clone $this->getIdentifier(); $identfier->path = array('template'); $identfier->name = 'parser'; register_default(array('identifier' => $identfier, 'default' => 'ComBaseTemplateDefault')); $this->_template = $this->getService($identfier); foreach ($config->filters as $filter) { $this->_template->addFilter($filter); } $this->_template->getFilter('alias')->append(KConfig::unbox($config->alias)); JFactory::getLanguage()->load('com_stories'); $this->_template->addSearchPath(KConfig::unbox($config->paths), true); }
/** * 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); }
/** * Sets the validator. * * @param string $validator */ public function setValidator($validator) { if (!$validator instanceof LibBaseControllerValidatorAbstract) { if (is_string($validator) && strpos($validator, '.') === false) { $identifier = clone $this->getIdentifier(); $identifier->path = array('controller', 'validator'); $identifier->name = $validator; register_default(array('identifier' => $identifier, 'prefix' => $this)); } else { $identifier = $this->getIdentifier($validator); } if ($identifier->path[1] != 'validator') { throw new KControllerBehaviorException('Identifier: ' . $identifier . ' is not a validator identifier'); } $validator = $identifier; } $this->_validator = $validator; }
public function __construct($console, $components, $check_max_version = true) { $this->_console = $console; $console->loadFramework(); $components = array_map(function ($item) { return 'com_' . str_replace('com_', '', $item); }, $components); $paths = new DirectoryFilter($components, array(WWW_ROOT . '/administrator/components')); $this->_event_dispatcher = \KService::get('koowa:event.dispatcher'); foreach ($paths as $path) { $component = str_replace('com_', '', basename($path)); $identifier = 'com://admin/' . $component . '.schema.migration'; register_default(array('identifier' => $identifier, 'default' => 'ComMigratorMigrationDefault')); $migrator = \KService::get($identifier, array('event_dispatcher' => $this->_event_dispatcher)); if ($check_max_version && $migrator->getMaxVersion() > 0 || !$check_max_version) { $this->_migrators[] = $migrator; } } }
/** * Force creation of a singleton * * @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) { $strIdentifier = (string) $config->service_identifier; $registery = $container->get('application.registry', array('key' => $strIdentifier . '_default_class')); if (!$registery->offsetExists($strIdentifier)) { try { $identifier = clone $config->service_identifier; $identifier->type = 'repos'; $identifier->path = array('domain', 'entity'); $default = array('prefix' => $container->get($identifier)->getClone(), 'fallback' => 'ComBaseControllerDefault'); } catch (Exception $e) { $default = 'Com' . ucfirst($config->service_identifier->package) . 'ControllerDefault'; $default = array('default' => array($default, 'ComBaseControllerResource')); } $default['identifier'] = $config->service_identifier; register_default($default); $classname = AnServiceClass::findDefaultClass($config->service_identifier); $config->service_identifier->classname = $classname; $registery->offsetSet($strIdentifier, $classname); } $classname = $registery->offsetGet($strIdentifier); $instance = new $classname($config); return $instance; }
/** * 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) { if (!isset($this->_filters[$filter])) { $identifier = clone $this->getIdentifier(); $identifier->path = array('template', 'filter'); $identifier->name = $filter; register_default(array('identifier' => $identifier, 'prefix' => $this)); $filter = $identifier; } } return parent::getFilter($filter); }
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; } }
/** * Set the transport object * * @param mixed ${property_name} * * @return LibBaseDispatcherResponse */ public function setTransport($transport) { if (!$transport instanceof LibBaseDispatcherResponseTransportAbstract) { if (is_string($transport) && strpos($transport, '.') === false) { $identifier = 'com:base.dispatcher.response.transport.' . $transport; } else { $identifier = $this->getIdentifier($transport); } register_default(array('identifier' => $identifier, 'default' => array('ComBaseDispatcherResponseTransportDefault'))); $transport = $identifier; } $this->_transport = $transport; return $this; }
/** * Method to set the validator. * * @param mixed $validator Validator object. Can be an KServiceIdentifier or string * * @return AnDomainBehaviorValidatable */ public function setValidator($validator) { if (!$validator instanceof AnDomainValidatorAbstract) { if (is_string($validator) && strpos($validator, '.') === false) { $identifier = clone $this->getIdentifier(); $identifier->path = array('domain', 'validator'); $identifier->name = $validator; } else { $identifier = $this->getIdentifier($validator); } register_default(array('identifier' => $identifier, 'prefix' => $this->_repository->getClone())); $validator = $identifier; } $this->_validator = $validator; return $this; }
/** * Initializes the default configuration for the object * * Called from {@link __construct()} as a first step of object instantiation. * * @param KConfig $config An optional KConfig object with configuration options. * * @return void */ protected function _initialize(KConfig $config) { $identifier = clone $this->getIdentifier(); $identifier->path = array('domain', 'repository'); register_default(array('identifier' => $identifier, 'prefix' => $this)); $config->append(array('attributes' => array(), 'relationships' => array(), 'repository' => $identifier, 'entity_identifier' => $this->getIdentifier())); parent::_initialize($config); }
/** * Get a toolbar by identifier. * * @return KControllerToolbarAbstract */ public function getToolbar($toolbar, $config = array()) { if (is_string($toolbar)) { if (strpos($toolbar, '.') === false) { $identifier = clone $this->getIdentifier(); $identifier->path = array('controller', 'toolbar'); $identifier->name = $toolbar; register_default(array('identifier' => $identifier, 'prefix' => $this)); $toolbar = $identifier; } } return parent::getToolbar($toolbar, $config); }
/** * Return the email view. * * @return ComMailerViewTemplate */ public function getEmailTemplateView() { if (!$this->_template_view instanceof LibBaseViewTemplate) { if (!isset($this->_template_view)) { $this->_template_view = clone $this->_mixer->getIdentifier(); $this->_template_view->path = array('emails'); $this->_template_view->name = 'template'; } $identifier = clone $this->_mixer->getIdentifier(); $identifier->path = array('emails'); $paths[] = dirname($identifier->filepath); $paths[] = implode(DS, array(JPATH_THEMES, JFactory::getApplication()->getTemplate(), 'emails', $identifier->type . '_' . $identifier->package)); $paths[] = implode(DS, array(JPATH_THEMES, JFactory::getApplication()->getTemplate(), 'emails')); $config = array('base_url' => $this->_base_url, 'template_paths' => $paths); register_default(array('identifier' => $this->_template_view, 'default' => 'LibBaseViewTemplate')); $this->_template_view = $this->getService($this->_template_view, $config); } return $this->_template_view; }
/** * Return a filter object. * * @param string $filter Filter name * * @return KFilterChain */ public function getFilter($filter) { if (!$filter instanceof KFilterAbstract) { $filter = (string) $filter; if (!isset($this->_filters[$filter])) { if (is_string($filter) && strpos($filter, '.') === false) { $identifier = clone $this->getIdentifier(); $identifier->path = array('filter'); $identifier->name = $filter; register_default(array('identifier' => $identifier, 'prefix' => $this)); } else { $identifier = $this->getIdentifier($filter); } $this->_filters[$filter] = $this->getService($identifier); } $filter = $this->_filters[$filter]; } return $filter; }
/** * Method to set a template object attached to the view. * * @param mixed An object that implements KObjectIdentifiable, an object that * implements KIndentifierInterface or valid identifier string * * @throws KDatabaseRowsetException If the identifier is not a table identifier * * @return LibBaseViewAbstract */ public function setTemplate($template) { if (!$template instanceof KTemplateAbstract) { if (is_string($template) && strpos($template, '.') === false) { $identifier = clone $this->getIdentifier(); $identifier->path = array('template'); $identifier->name = $template; } else { $identifier = $this->getIdentifier($template); } if ($identifier->path[0] != 'template') { throw new KViewException('Identifier: ' . $identifier . ' is not a template identifier'); } register_default(array('identifier' => $identifier, 'prefix' => $this, 'name' => array('Template' . ucfirst($this->getName()), 'TemplateDefault'))); $template = $identifier; } $this->_template = $template; return $this; }
/** * Set the serializer * * @param AnDomainSerializerAbstract|string $serializer * * @return void */ public function setSerializer($serializer) { if (!$serializer instanceof AnDomainSerializerAbstract) { if (is_string($serializer) && strpos($serializer, '.') === false) { $identifier = clone $this->_repository->getIdentifier(); $identifier->path = array('domain', 'serializer'); $identifier->name = $serializer; register_default(array('identifier' => $identifier, 'prefix' => $this->_repository->getClone())); } else { $identifier = $this->getIdentifier($serializer); } $serializer = $identifier; } $this->_serializer = $serializer; }
/** * Get a behavior by identifier. * * @param mixed $behavior Behavior name * @param array $config An array of options to configure the behavior with * * @see KMixinBehavior::getBehavior() * * @return AnDomainBehaviorAbstract */ public function getBehavior($behavior, $config = array()) { if (is_string($behavior)) { if (strpos($behavior, '.') === false) { $identifier = clone $this->getIdentifier(); $identifier->path = array('domain', 'behavior'); $identifier->name = $behavior; register_default(array('identifier' => $identifier, 'prefix' => $this->_prototype)); $behavior = $identifier; } } return parent::__call('getBehavior', array($behavior, $config)); }