function view()
 {
     // Grab the view to easily assign variables
     $view = $this->getView();
     // Get all warnings from Ajde_Dump::warn()
     if (Ajde_Dump::getWarnings()) {
         $view->assign('warn', Ajde_Dump::getWarnings());
     }
     // Get all dumps from Ajde_Dump::dump() [Aliased as a global function dump()]
     if (Ajde_Dump::getAll()) {
         $view->assign('dump', Ajde_Dump::getAll());
     }
     // Get request parameters
     $view->assign('request', Ajde::app()->getRequest());
     // Get Configuration stage
     $view->assign('configstage', Config::$stage);
     // Get database queries
     if (Ajde_Core_Autoloader::exists('Ajde_Db_PDO')) {
         $view->assign('database', Ajde_Db_PDO::getLog());
     }
     // Get language
     $view->assign('lang', Ajde_Lang::getInstance()->getLang());
     // Get session
     $view->assign('session', $_SESSION);
     // Get ACL
     if (Ajde_Core_Autoloader::exists('Ajde_Acl')) {
         $view->assign('acl', Ajde_Acl::getLog());
     }
     // Get the application timer
     Ajde::app()->endTimer(0);
     Ajde::app()->endTimer(Ajde::app()->getLastTimerKey());
     $view->assign('timers', Ajde::app()->getTimers());
     return $this->render();
 }
Esempio n. 2
0
 public static function registerAll()
 {
     $dirs = Ajde_FS_Find::findFiles(MODULE_DIR, '*/model');
     foreach ($dirs as $dir) {
         Ajde_Core_Autoloader::addDir($dir . '/');
     }
 }
Esempio n. 3
0
 public static function fromType($type)
 {
     $className = __CLASS__ . '_' . ucfirst($type);
     if (!Ajde_Core_Autoloader::exists($className)) {
         throw new Ajde_Exception(sprintf("Compressor for type %s not found", $type), 90017);
     }
     return new $className();
 }
Esempio n. 4
0
 public static function beautifyHtml($html, $config = array("output-xhtml" => true, "char-encoding" => "utf8", "indent" => true, "indent-spaces" => 4, "wrap" => 0))
 {
     if (!Ajde_Core_Autoloader::exists('Tidy')) {
         throw new Ajde_Exception('Class Tidy not found', 90023);
     }
     $tidy = new Tidy();
     // http://bugs.php.net/bug.php?id=35647
     return $tidy->repairString($html, $config, 'utf8');
 }
 protected function _getResource($className)
 {
     // get resource from request
     $fingerprint = Ajde::app()->getRequest()->getRaw('id');
     if (!Ajde_Core_Autoloader::exists($className)) {
         throw new Ajde_Controller_Exception("Resource type could not be loaded");
     }
     //$resource = call_user_func_array(array($className,"fromHash"), array($hash));
     $resource = call_user_func_array(array($className, "fromFingerprint"), array($this->getFormat(), $fingerprint));
     return $resource->getContents();
 }
Esempio n. 6
0
 public static function beautifyHtml($html, $config = array("output-xhtml" => true, "char-encoding" => "utf8", "indent" => true, "indent-spaces" => 4, "wrap" => 0))
 {
     if (!Ajde_Core_Autoloader::exists('Tidy')) {
         throw new Ajde_Exception('Class Tidy not found', 90023);
     }
     $tidy = new Tidy();
     // tidy does not produce valid utf8 when the encoding is specified in the config
     // so we provide a third parameter, 'utf8' to fix this
     // @see http://bugs.php.net/bug.php?id=35647
     return $tidy->repairString($html, $config, 'utf8');
 }
Esempio n. 7
0
 /**
  *
  * @param string $name
  * @param Ajde_Shop_Transaction $transaction
  * @return Ajde_Shop_Transaction_Provider
  * @throws Ajde_Exception 
  */
 public static function getProvider($name, $transaction = null)
 {
     $providerClass = 'Ajde_Shop_Transaction_Provider_' . ucfirst($name);
     if (!Ajde_Core_Autoloader::exists($providerClass)) {
         // TODO:
         throw new Ajde_Exception('Payment provider ' . $name . ' not found');
     }
     $obj = new $providerClass();
     if ($transaction) {
         $obj->setTransaction($transaction);
     }
     return $obj;
 }
Esempio n. 8
0
 public static function register($controller)
 {
     // Extend Ajde_Controller
     if (!Ajde_Event::has('Ajde_Controller', 'call', 'Ajde_Collection::extendController')) {
         Ajde_Event::register('Ajde_Controller', 'call', 'Ajde_Collection::extendController');
     }
     // Extend autoloader
     if ($controller instanceof Ajde_Controller) {
         Ajde_Core_Autoloader::addDir(MODULE_DIR . $controller->getModule() . '/model/');
     } elseif ($controller === '*') {
         self::registerAll();
     } else {
         Ajde_Core_Autoloader::addDir(MODULE_DIR . $controller . '/model/');
     }
 }
Esempio n. 9
0
 /**
  *
  * @param Ajde_Core_Route $route
  * @return Ajde_Controller
  */
 public static function fromRoute(Ajde_Core_Route $route)
 {
     if ($controller = $route->getController()) {
         $moduleController = ucfirst($route->getModule()) . ucfirst($controller) . 'Controller';
     } else {
         $moduleController = ucfirst($route->getModule()) . 'Controller';
     }
     if (!Ajde_Core_Autoloader::exists($moduleController)) {
         $exception = new Ajde_Exception("Controller {$moduleController} for module {$route->getModule()} not found", 90008);
         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;
 }
Esempio n. 10
0
// Set include path for addFile function
$testPath = $_SERVER['DOCUMENT_ROOT'] . '/test/';
$rootPath = $_SERVER['DOCUMENT_ROOT'] . '/';
set_include_path(get_include_path() . PATH_SEPARATOR . $testPath . PATH_SEPARATOR . $rootPath);
// Define paths
define('PRIVATE_DIR', 'private/');
define('PUBLIC_DIR', 'public/');
define('TEMPLATE_DIR', 'template/');
define('APP_DIR', PRIVATE_DIR . 'application/');
define('LIB_DIR', PRIVATE_DIR . 'lib/');
define('VAR_DIR', PRIVATE_DIR . 'var/');
define('CACHE_DIR', VAR_DIR . 'cache/');
define('CONFIG_DIR', APP_DIR . 'config/');
define('LAYOUT_DIR', APP_DIR . 'layout/');
define('LOG_DIR', VAR_DIR . 'log/');
define('MODULE_DIR', APP_DIR . 'modules/');
// Configure the autoloader
require_once '../' . LIB_DIR . 'Ajde/Core/Autoloader.php';
$dirPrepend = $_SERVER['DOCUMENT_ROOT'] . '/';
Ajde_Core_Autoloader::register($dirPrepend);
class AllTests extends TestSuite
{
    function __construct()
    {
        $this->TestSuite('Ajde test suite');
        $this->addFile('testCore.php');
        $this->addFile('testXhtml.php');
        $this->addFile('testPhtml.php');
        $this->addFile('testZend.php');
    }
}
Esempio n. 11
0
 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 (!Ajde_Core_Autoloader::exists($processorClass)) {
                 // TODO:
                 throw new Ajde_Exception('Processor ' . $processorClass . ' not found', 90022);
             }
             if ($registerOn == 'layout') {
                 Ajde_Event::register('Ajde_Layout', 'beforeGetContents', $processorClass . '::preProcess');
                 Ajde_Event::register('Ajde_Layout', 'afterGetContents', $processorClass . '::postProcess');
             } elseif ($registerOn == 'compressor') {
                 Ajde_Event::register('Ajde_Resource_Local_Compressor', 'beforeCompress', $processorClass . '::preCompress');
                 Ajde_Event::register('Ajde_Resource_Local_Compressor', 'afterCompress', $processorClass . '::postCompress');
             } else {
                 // TODO:
                 throw new Ajde_Exception('Document processor must be registered on either \'layout\' or \'compressor\'');
             }
         }
     }
 }
Esempio n. 12
0
 protected static function className($object)
 {
     if (is_object($object)) {
         return get_class($object);
     } elseif (is_string($object) && Ajde_Core_Autoloader::exists($object)) {
         return $object;
     }
     throw new Ajde_Exception('No classname or object instance given, or classname is incorrect', 90012);
 }
Esempio n. 13
0
define('PUBLIC_DIR', 'public/');
define('TEMPLATE_DIR', 'template/');
define('APP_DIR', PRIVATE_DIR . 'application/');
define('LIB_DIR', PRIVATE_DIR . 'lib/');
define('VAR_DIR', PRIVATE_DIR . 'var/');
define('CONFIG_DIR', APP_DIR . 'config/');
define('LAYOUT_DIR', APP_DIR . 'layout/');
define('MODULE_DIR', APP_DIR . 'modules/');
define('LANG_DIR', APP_DIR . 'lang/');
define('CACHE_DIR', VAR_DIR . 'cache/');
define('LOG_DIR', VAR_DIR . 'log/');
//	--------------------
//	Configure the autoloader
//	--------------------
require_once LIB_DIR . "Ajde/Core/Autoloader.php";
Ajde_Core_Autoloader::register();
/*********************
 * GLOBAL FUNCTIONS
 *********************/
//	--------------------
//	The only thing missing in PHP < 5.3
//	In PHP 5.3 you can use: return $test ?: false;
//	This translates in Ajde to return issetor($test);
//	--------------------
function issetor(&$what, $else = null)
{
    // @see http://fabien.potencier.org/article/48/the-php-ternary-operator-fast-or-not
    if (isset($what)) {
        return $what;
    } else {
        return $else;
Esempio n. 14
0
 public static function autoload($className)
 {
     $debug = false;
     // turn on for performance checking of the autoloader
     if (in_array($className, self::$incompatibleClasses)) {
         throw new Ajde_Exception('Could not create instance of incompatible class ' . $className . '.', 90018);
     }
     self::$files = array();
     $isNamespace = false;
     foreach (self::$namespaces as $namespace) {
         if (substr($className, 0, strlen($namespace . '_')) == $namespace . '_') {
             $isNamespace = true;
             break;
         }
     }
     if ($isNamespace) {
         // LIB class
         $dirs = array(LIB_DIR);
         self::initFiles($className);
     } else {
         // Non LIB related classes
         if (substr_count($className, 'Controller') > 0) {
             $dirs = array(MODULE_DIR);
             $controllerName = str_replace('Controller', '', $className);
             if (strtolower(substr($controllerName, 1)) != substr($controllerName, 1)) {
                 // See if we got more capitals
                 // ModuleSubcontrollerController.php naming
                 $combinedName = substr($controllerName, 0, 1) . preg_replace('/([A-Z])/', ':\\1', substr($controllerName, 1));
                 list($moduleName, $controllerName) = explode(":", $combinedName);
                 self::addFile(strtolower($moduleName) . "/" . $moduleName . $controllerName . 'Controller.php');
             } else {
                 // ModuleController.php naming
                 self::addFile(strtolower(str_replace('Controller', '', $className)) . "/" . $className . '.php');
             }
         } elseif (substr_count($className, 'Config') > 0) {
             $dirs = array(CONFIG_DIR);
             // Namespace_Class.php naming
             self::addFile($className . ".php");
         } else {
             $dirs = self::$dirs;
             // FooModel.php, BarCollection.php, etc. naming
             self::addFile($className . '.php');
         }
     }
     /*// In order to use Ajde_Event here, require neccesary files statically :(
     		require_once(LIB_DIR.'Ajde/Object/Object.php');
     		require_once(LIB_DIR.'Ajde/Object/Static.php');
     		require_once(LIB_DIR.'Ajde/Event/Event.php');
     		require_once(LIB_DIR.'Ajde/Exception/Exception.php');
     		Ajde_Event::trigger('Ajde_Core_Autoloader', 'beforeSearch', array($className));*/
     if ($debug) {
         self::$queries++;
         echo "<span style='color:orange;'>LOOKING FOR</span> {$className} <br/>";
     }
     foreach ($dirs as $dir) {
         foreach (self::$files as $file) {
             $path = self::$dirPrepend . $dir . $file;
             if (is_file($path)) {
                 // TODO: performance gain?
                 // if (class_exists('Ajde_Cache')) {
                 // 	Ajde_Cache::getInstance()->addFile($path);
                 // }
                 if ($debug) {
                     echo "<span style='color:green;'>FOUND</span> {$path} <br/>";
                     echo "<span style='font-size:smaller;color:gray;'>stats : (missed/lookups) : " . self::$missed . "/" . self::$queries . " : " . (int) (self::$missed / self::$queries * 100) . "% missed</span><br/>";
                 }
                 require_once $path;
                 return;
             } else {
                 if ($debug) {
                     echo "<span style='color:red;'>CONTINUE</span> {$path} <br/>";
                     self::$missed++;
                 }
             }
         }
     }
     /*
      * Throwing exceptions is only possible as of PHP 5.3.0
      * See: http://php.net/manual/en/language.oop5.autoload.php
      */
     if (version_compare(PHP_VERSION, '5.3.0') >= 0 && self::exists('Ajde_Core_Autoloader_Exception')) {
         // TODO: Custom Exceptions are still causing problems
         // throw new Ajde_Core_Autoloader_Exception("Unable to load $className", 90005);
         throw new Exception("Unable to load {$className}", 90005);
     }
 }