public static function boot($dispatch = TRUE) { parent::boot(); self::$dispatcher = new \apf\web\core\Dispatcher(); if ($dispatch) { return self::$dispatcher->dispatch(); } }
/** *Gets a form element instance according to the context obtained from the within the Kernel::getSAPI method * *@param string $type The *type* of the element, input, select, etc> *@param ElementConfigInterface The configuration for said element. *@param string $ui User Interface for the given element type, web, cli, etc */ public static function getInstanceFromUIContext($type, $ui = NULL) { $type = trim($type); /** *An element type is mandatory. This "type" is the type of element one wishes to create *an input element, a select element, etc. */ if (empty($type)) { throw new \InvalidArgumentException("Must specify element type!"); } /** * If no $ui is specified, autodetect the user interface through the Kernel::getSAPI object */ if ($ui === NULL) { $ui = Kernel::getSAPI()->getName(); } $class = self::getElementClassByTypeAndUI($type, $ui); /** * Return a new element type instance, configured with a name, a value and a layout container. */ return new $class(); }
public function setController($controller) { $cfg =& DI::get("config")->framework; $appName = $cfg->appName; $ds = DIRECTORY_SEPARATOR; $cPath = sprintf('%s/controller', \apf\core\Kernel::getAppDir()); $controller = ucwords(preg_replace("/\\W/", '', $controller)); $this->setControllerPath($cPath); $dir = new \DirectoryIterator($cPath); foreach ($dir as $file) { $file = $file->getFileName(); if ($file == '.' || $file == '..') { continue; } $file = substr($file, 0, strpos($file, 'Controller')); if (strtolower($file) == strtolower($controller)) { $controller = $file; break; } } $_controller = sprintf('%s%s', $controller, 'Controller'); $ctrl = sprintf('%s%s%s.class.php', $cPath, $ds, $_controller); if (!file_exists($ctrl)) { if (empty($cfg->default_controller)) { $this->status = 404; return; } $ctrl = sprintf('%s%s%s%s.class.php', $cPath, $ds, ucwords($cfg->default_controller), "Controller"); if (!file_exists($ctrl)) { $this->status = 404; return; } $controller = sprintf('%s', ucwords($cfg->default_controller)); } $this->controller = ucwords($controller); return $this; }
/** * Gets a form instance according to the context obtained from the within the Kernel::getSAPI method * * @return \apf\ui\form\Cli If the autodetected context is cli or if the $ui argument is equal to cli * @return \apf\ui\form\Web If the autodetected context is web or if the $ui argument is equal to web */ public static function getInstanceFromUIContext($ui = NULL) { /** * If no $ui is specified, autodetect it through the Kernel::getSAPI object */ if ($ui === NULL) { $ui = Kernel::getSAPI()->getName(); } /** * Compose the class name */ $class = sprintf('\\apf\\ui\\form\\%s', ucwords($ui)); /** * Corroborate that the given form UI class does in fact exists */ if (!class_exists($class)) { throw new \InvalidArgumentException("No Form UI named \"{$ui}\" was found, perhaps you'd like to help and create it?"); } /** * Create a new form instance of the corresponding form considering the context * where PHP is being called, i.e cli, web, etc */ return new $class(); }