public static function fromType($type) { $className = __CLASS__ . '_' . ucfirst($type); if (!Autoloader::exists($className)) { throw new Exception(sprintf("Compressor for type %s not found", $type), 90017); } return new $className(); }
/** * * @param string $name * @return Ajde_Crud_Cms_Meta_Type * @throws Ajde_Exception */ public function getType($name) { $className = "Ajde_Crud_Cms_Meta_Type_" . ucfirst(str_replace(' ', '', strtolower($name))); if (!Autoloader::exists($className)) { // TODO: throw new Exception('Meta field class ' . $className . ' could not be found'); } return new $className(); }
/** * * @param string $name * @param Ajde_Shop_Transaction $transaction * @return Ajde_Shop_Transaction_Provider * @throws Ajde_Exception */ public static function getProvider($name, $transaction = null) { $providerClass = ExternalLibs::getClassname('Ajde_Shop_Transaction_Provider_' . self::classnameToUppercase($name)); if (!Autoloader::exists($providerClass)) { // TODO: throw new Exception('Payment provider ' . $name . ' not found'); } $obj = new $providerClass(); if ($transaction) { $obj->setTransaction($transaction); } return $obj; }
/** * * @param type $code * @return Ajde_Embed */ public static function fromCode($code) { $embedClass = 'Ajde_Embed'; foreach (self::$_detect as $provider => $test) { if (is_array($test)) { foreach ($test as $testPart) { if (substr_count($code, $testPart) > 0) { $providerClass = 'Ajde_Embed_' . ucfirst($provider); if (Autoloader::exists($providerClass)) { $embedClass = $providerClass; } } } } else { if (substr_count($code, $test) > 0) { $providerClass = 'Ajde_Embed_' . ucfirst($provider); if (Autoloader::exists($providerClass)) { $embedClass = $providerClass; } } } } return new $embedClass($code); }
protected static function className($object) { if (is_object($object)) { return get_class($object); } elseif (is_string($object) && Autoloader::exists($object)) { return $object; } throw new Exception('No classname or object instance given, or classname is incorrect', 90012); }
public static function registerDocumentProcessor($format, $registerOn = 'layout') { $documentProcessors = Config::get('documentProcessors'); if (is_array($documentProcessors) && isset($documentProcessors[$format])) { foreach ($documentProcessors[$format] as $processor) { $processorClass = 'Ajde_Document_Processor_' . ucfirst($format) . '_' . $processor; if (!Autoloader::exists($processorClass)) { // TODO: throw new Exception('Processor ' . $processorClass . ' not found', 90022); } if ($registerOn == 'layout') { Dispatcher::register('Ajde_Layout', 'beforeGetContents', $processorClass . '::preProcess'); Dispatcher::register('Ajde_Layout', 'afterGetContents', $processorClass . '::postProcess'); } elseif ($registerOn == 'compressor') { Dispatcher::register('Ajde_Resource_Local_Compressor', 'beforeCompress', $processorClass . '::preCompress'); Dispatcher::register('Ajde_Resource_Local_Compressor', 'afterCompress', $processorClass . '::postCompress'); } else { // TODO: throw new Exception('Document processor must be registered on either \'layout\' or \'compressor\''); } } } }
/** * * @param Ajde_Core_Route $route * @return Ajde_Controller */ public static function fromRoute(Route $route) { if ($controller = $route->getController()) { $moduleController = ucfirst($route->getModule()) . ucfirst($controller) . 'Controller'; } else { $moduleController = ucfirst($route->getModule()) . 'Controller'; } if (!Autoloader::exists($moduleController)) { // Prevent resursive 404 routing if (isset(Config::getInstance()->responseCodeRoute[Response::RESPONSE_TYPE_NOTFOUND])) { $notFoundRoute = new Route(Config::getInstance()->responseCodeRoute[Response::RESPONSE_TYPE_NOTFOUND]); if ($route->buildRoute() == $notFoundRoute->buildRoute()) { Response::setResponseType(404); die('<h2>Ouch, something broke.</h2><p>This is serious. We tried to give you a nice error page, but even that failed.</p><button onclick="location.href=\'' . Config::get('site_root') . '\';">Go back to homepage</button>'); } } if (Autoloader::exists('Ajde_Exception')) { $exception = new Routing("Controller {$moduleController} for module {$route->getModule()} not found", 90008); } else { // Normal exception here to prevent [Class 'Ajde_Exception' not found] errors... $exception = new Exception("Controller {$moduleController} for module {$route->getModule()} not found"); } Ajde::routingError($exception); } $controller = new $moduleController($route->getAction(), $route->getFormat()); $controller->_route = $route; foreach ($route->values() as $part => $value) { $controller->set($part, $value); } return $controller; }
public static function routingError(Exception $exception) { if (Config::get("debug") === true) { throw $exception; } else { if (Autoloader::exists('Ajde_Exception_Log')) { Log::logException($exception); } Response::redirectNotFound(); } }