/** * 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 - plg.type.plugin.[.path].name * @return string|false Return object on success, returns FALSE on failure */ public function findClass(KServiceIdentifier $identifier) { $classpath = KInflector::camelize(implode('_', $identifier->path)); $classname = 'Plg' . ucfirst($identifier->package) . $classpath . ucfirst($identifier->name); //Don't allow the auto-loader to load plugin classes if they don't exists yet if (!class_exists($classname)) { $classname = false; } return $classname; }
/** * Create an instance of a class based on a class identifier * * This factory will try to create an generic or default object based on the identifier information * if the actual object cannot be found using a predefined fallback sequence. * * Fallback sequence : -> Named Component Specific * -> Named Component Default * -> Default Component Specific * -> Default Component Default * -> Framework Specific * -> Framework Default * * @param mixed Identifier or Identifier object - com:[//application/]component.view.[.path].name * @param object An optional KConfig object with configuration options * @return object|false Return object on success, returns FALSE on failure */ public function instantiate($identifier, KConfig $config) { $path = KInflector::camelize(implode('_', $identifier->path)); $classname = 'Com'.ucfirst($identifier->package).$path.ucfirst($identifier->name); //Don't allow the auto-loader to load component classes if they don't exists yet if (!class_exists( $classname, false )) { //Find the file if($path = KLoader::load($identifier)) { //Don't allow the auto-loader to load component classes if they don't exists yet if (!class_exists( $classname, false )) { throw new KFactoryAdapterException("Class [$classname] not found in file [".$path."]" ); } } else { $classpath = $identifier->path; $classtype = !empty($classpath) ? array_shift($classpath) : ''; //Create the fallback path and make an exception for views $path = ($classtype != 'view') ? KInflector::camelize(implode('_', $classpath)) : ''; /* * Find the classname to fallback too and auto-load the class * * Fallback sequence : -> Named Component Specific * -> Named Component Default * -> Default Component Specific * -> Default Component Defaukt * -> Framework Specific * -> Framework Default */ if(class_exists('Com'.ucfirst($identifier->package).ucfirst($classtype).$path.ucfirst($identifier->name))) { $classname = 'Com'.ucfirst($identifier->package).ucfirst($classtype).$path.ucfirst($identifier->name); } elseif(class_exists('Com'.ucfirst($identifier->package).ucfirst($classtype).$path.'Default')) { $classname = 'Com'.ucfirst($identifier->package).ucfirst($classtype).$path.'Default'; } elseif(class_exists('ComDefault'.ucfirst($classtype).$path.ucfirst($identifier->name))) { $classname = 'ComDefault'.ucfirst($classtype).$path.ucfirst($identifier->name); } elseif(class_exists('ComDefault'.ucfirst($classtype).$path.'Default')) { $classname = 'ComDefault'.ucfirst($classtype).$path.'Default'; } elseif(class_exists( 'K'.ucfirst($classtype).$path.ucfirst($identifier->name))) { $classname = 'K'.ucfirst($classtype).$path.ucfirst($identifier->name); } elseif(class_exists('K'.ucfirst($classtype).$path.'Default')) { $classname = 'K'.ucfirst($classtype).$path.'Default'; } else { $classname = false; } } } return $classname; }
protected function _beforeSubmit(KCommandContext $context) { $item = $this->getModel()->getItem(); if ($this->fieldsProperty) { $prop = $this->fieldsProperty; $item = $item->{$prop}; } foreach ($this->verifyConfig as $type => $fieldName) { $method = '__verify' . KInflector::camelize($type); if (!$this->{$method}($item, $context->data->toArray(), $fieldName)) { return false; } } return true; }
/** * Get the classname based on an identifier * * This locator will try to create an generic or default classname on the identifier information * if the actual class cannot be found using a predefined fallback sequence. * * Fallback sequence : -> Named Module Specific * -> Named Module Default * -> Default Module Specific * -> Default Module Default * -> Framework Specific * -> Framework Default * * @param mixed An identifier object - mod:[//application/]module.[.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 = 'Mod' . ucfirst($identifier->package) . $path . ucfirst($identifier->name); //Don't allow the auto-loader to load module classes if they don't exists yet if (!$this->getService('koowa:loader')->loadClass($classname, $identifier->basepath)) { $classpath = $identifier->path; $classtype = !empty($classpath) ? array_shift($classpath) : 'view'; //Create the fallback path and make an exception for views $com_path = $classtype != 'view' ? ucfirst($classtype) . KInflector::camelize(implode('_', $classpath)) : ucfirst($classtype); $mod_path = $classtype != 'view' ? ucfirst($classtype) . KInflector::camelize(implode('_', $classpath)) : ''; /* * Find the classname to fallback too and auto-load the class * * Fallback sequence : -> Named Module Specific * -> Named Module Default * -> Default Module Specific * -> Default Module Default * -> Default Component Specific * -> Default Component Default * -> Framework Specific * -> Framework Default */ if (class_exists('Mod' . ucfirst($identifier->package) . $mod_path . ucfirst($identifier->name))) { $classname = 'Mod' . ucfirst($identifier->package) . $mod_path . ucfirst($identifier->name); } elseif (class_exists('Mod' . ucfirst($identifier->package) . $mod_path . 'Default')) { $classname = 'Mod' . ucfirst($identifier->package) . $mod_path . 'Default'; } elseif (class_exists('ModDefault' . $mod_path . ucfirst($identifier->name))) { $classname = 'ModDefault' . $mod_path . ucfirst($identifier->name); } elseif (class_exists('ModDefault' . $mod_path . 'Default')) { $classname = 'ModDefault' . $mod_path . 'Default'; } elseif (class_exists('ComDefault' . $com_path . ucfirst($identifier->name))) { $classname = 'ComDefault' . $com_path . ucfirst($identifier->name); } elseif (class_exists('ComDefault' . $com_path . 'Default')) { $classname = 'ComDefault' . $com_path . 'Default'; } elseif (class_exists('K' . $com_path . ucfirst($identifier->name))) { $classname = 'K' . $com_path . ucfirst($identifier->name); } elseif (class_exists('K' . $com_path . 'Default')) { $classname = 'K' . $com_path . 'Default'; } else { $classname = false; } } return $classname; }
/** * Create an instance of a class based on a class identifier * * @param mixed Identifier or Identifier object - plg.type.plugin.[.path].name * @param object An optional KConfig object with configuration options * @return object|false Return object on success, returns FALSE on failure */ public function instantiate($identifier, KConfig $config) { $classname = false; if ($identifier->type == 'plg') { $classpath = KInflector::camelize(implode('_', $identifier->path)); $classname = 'Plg' . ucfirst($identifier->package) . $classpath . ucfirst($identifier->name); //Don't allow the auto-loader to load plugin classes if they don't exists yet if (!class_exists($classname, false)) { //Find the file if ($path = KLoader::load($identifier)) { //Don't allow the auto-loader to load plugin classes if they don't exists yet if (!class_exists($classname, false)) { throw new KFactoryAdapterException("Class [{$classname}] not found in file [" . $path . "]"); } } } } return $classname; }
/** * Creates and initialize a property. The instantiation happens through cloning rather * then creating a new instance. * * @param string $property The property type * @param KConfig $config The property configuration * * @return AnDomainPropertyAbstract */ public static function getInstance($property, KConfig $config) { $description = $config['description']; $name = $config['name']; if (!$name || !$description) { throw new AnDomainPropertyException('name [string] or desription [AnDomainDescriptionAbstract] options are missing'); } if ($description->getProperty($name)) { $instance = $description->getProperty($name); } else { if (!isset(self::$_instances[$property])) { $classname = 'AnDomain' . KInflector::camelize($property); self::$_instances[$property] = new $classname(); } $instance = clone self::$_instances[$property]; } $instance->setConfig($config); $description->setProperty($instance); return $instance; }
/** * Create an instance of a class based on a class identifier * * This factory will try to create an generic or default object based on the identifier information * if the actual object cannot be found using a predefined fallback sequence. * * Fallback sequence : -> Named Module * -> Default Module * -> Framework Specific * -> Framework Default * * @param mixed Identifier or Identifier object - application::mod.module.[.path].name * @param object An optional KConfig object with configuration options * @return object|false Return object on success, returns FALSE on failure */ public function instantiate($identifier, KConfig $config) { $classname = false; if ($identifier->type == 'mod') { $path = KInflector::camelize(implode('_', $identifier->path)); $classname = 'Mod' . ucfirst($identifier->package) . $path . ucfirst($identifier->name); //Don't allow the auto-loader to load module classes if they don't exists yet if (!class_exists($classname, false)) { //Find the file if ($path = KLoader::load($identifier)) { //Don't allow the auto-loader to load module classes if they don't exists yet if (!class_exists($classname, false)) { throw new KFactoryAdapterException("Class [{$classname}] not found in file [" . $path . "]"); } } else { $classpath = $identifier->path; $classtype = !empty($classpath) ? array_shift($classpath) : $identifier->name; /* * Find the classname to fallback too and auto-load the class * * Fallback sequence : -> Named Module * -> Default Module * -> Framework Specific * -> Framework Default */ if (class_exists('Mod' . ucfirst($identifier->package) . ucfirst($identifier->name))) { $classname = 'Mod' . ucfirst($identifier->package) . ucfirst($identifier->name); } elseif (class_exists('ModDefault' . ucfirst($identifier->name))) { $classname = 'ModDefault' . ucfirst($identifier->name); } elseif (class_exists('K' . ucfirst($classtype) . $path . ucfirst($identifier->name))) { $classname = 'K' . ucfirst($classtype) . ucfirst($identifier->name); } elseif (class_exists('K' . ucfirst($classtype) . 'Default')) { $classname = 'K' . ucfirst($classtype) . 'Default'; } else { $classname = false; } } } } return $classname; }
/** * Find a class * * @param KServiceIdentifier $identifier * * @return string */ protected function _findClass($identifier) { $loader = $this->getService('koowa:loader'); $classname = null; //Create the fallback path and make an exception for views $classpath = $identifier->path; $classtype = !empty($classpath) ? array_shift($classpath) : ''; $paths = array(); $paths[] = ucfirst($classtype) . KInflector::camelize(implode('_', $classpath)); if ($classtype == 'view') { $paths[] = ucfirst($classtype); } $paths = array_unique($paths); $namespaces = array(); $namespaces[] = 'Com' . ucfirst($identifier->package); $namespaces[] = 'Lib' . ucfirst($identifier->package); $namespaces[] = 'ComBase'; $namespaces[] = 'LibBase'; $namespaces[] = 'ComDefault'; $namespaces[] = 'An'; $namespaces[] = 'K'; $namespaces = array_unique($namespaces); $classes = array(); foreach ($namespaces as $namespace) { foreach ($paths as $path) { $names = array(); $names[] = ucfirst($identifier->name); $names[] = empty($path) ? ucfirst($identifier->name) . 'Default' : 'Default'; foreach ($names as $name) { $class = $namespace . $path . $name; $classes[] = $class; if ($loader->findPath($class, $identifier->basepath) && $loader->loadClass($class, $identifier->basepath)) { $classname = $class; break 3; } } } } return $classname; }
/** * @dataProvider provideNames */ public function testUnderscoredToCamelize($classified, $separator, $split, $exploded, $camelized, $underscored) { $this->assertEquals(KInflector::camelize($underscored), $camelized); }
/** * Calls the methods _beforeLayout($layout) and _layout[Layout] and runs the command * before.load if there are any commands in the queue. For any layout rendered through the view * the data of the view is passed to the template regardless. If $data has duplicate keys as the * $view->data then $data values replaces the values with duplicate keys. * * @param string $layout The layout * @param array $data The data */ public function load($template, array $data = array()) { if (method_exists($this, '_beforeLayout')) { $this->_beforeLayout($template); } $method = '_layout' . KInflector::camelize($template); if (method_exists($this, $method)) { $this->{$method}(); } $data = array_merge($this->_data, $data); $output = $this->getTemplate()->loadTemplate($template, $data)->render(); return $output; }