/** * Get the classname based on an identifier. * * @param mixed An identifier object - koowa:[path].name * * @return string|false Return object on success, returns FALSE on failure */ public function findClass(KServiceIdentifier $identifier) { $classname = 'Tmpl' . ucfirst($identifier->package) . KInflector::implode($identifier->path) . ucfirst($identifier->name); if (!$this->getService('koowa:loader')->loadClass($classname, $identifier->basepath)) { $classname = AnServiceClass::findDefaultClass($identifier); if (!$classname) { //$path = KInflector::implode($identifier->path); $classpath = $identifier->path; $classtype = !empty($classpath) ? array_shift($classpath) : ''; //Create the fallback path and make an exception for views $path = $classtype != 'view' ? ucfirst($classtype) . KInflector::camelize(implode('_', $classpath)) : ucfirst($classtype); $classes[] = 'Tmpl' . ucfirst($identifier->package) . $path . ucfirst($identifier->name); $classes[] = 'Tmpl' . ucfirst($identifier->package) . $path . 'Default'; $classes[] = 'ComApplication' . $path . ucfirst($identifier->name); $classes[] = 'ComApplication' . $path . 'Default'; $classes[] = 'LibApplication' . $path . ucfirst($identifier->name); $classes[] = 'LibApplication' . $path . 'Default'; $classes[] = 'LibBase' . $path . ucfirst($identifier->name); $classes[] = 'LibBase' . $path . 'Default'; $classes[] = 'K' . $path . ucfirst($identifier->name); $classes[] = 'K' . $path . 'Default'; foreach ($classes as $class) { if ($this->getService('koowa:loader')->loadClass($class, $identifier->basepath)) { $classname = $class; break; } } if ($classname) { AnServiceClass::setDefaultClass($identifier, $classname); } } } return $classname; }
/** * Get the classname based on an identifier. * * @param mixed An identifier object - koowa:[path].name * * @return string|false Return object on success, returns FALSE on failure */ public function findClass(KServiceIdentifier $identifier) { $classname = 'An' . ucfirst($identifier->package) . KInflector::implode($identifier->path) . ucfirst($identifier->name); if (!class_exists($classname)) { $classname = AnServiceClass::findDefaultClass($identifier); if (!$classname) { // use default class instead $classname = 'An' . ucfirst($identifier->package) . KInflector::implode($identifier->path) . 'Default'; if (!class_exists($classname)) { $classname = false; } } } return $classname; }
/** * Get the classname based on an identifier * * @param mixed An identifier object - koowa:[path].name * @return string|false Return object on success, returns FALSE on failure */ public function findClass(KServiceIdentifier $identifier) { $path = KInflector::camelize(implode('_', $identifier->path)); $classname = 'Com' . ucfirst($identifier->package) . $path . ucfirst($identifier->name); $loader = $this->getService('koowa:loader'); //Manually load the class to set the basepath if (!$loader->loadClass($classname, $identifier->basepath)) { //the default can be in either in the default folder //be a registered default class $classname = AnServiceClass::findDefaultClass($identifier); //hack if ($classname == 'AnDomainBehaviorDefault') { $classname = null; } if (!$classname) { $classname = $this->_findClass($identifier); } } return $classname; }
/** * 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; }