Exemple #1
0
 private function getHelper($helper)
 {
     $helperPlural = Ntentan::plural($helper);
     $helper = $helperPlural == null ? $helper : $helperPlural;
     if ($helper === null) {
         return false;
     }
     if (!isset($this->loadedHelpers[$this->plugin . $helper])) {
         $camelizedHelper = Ntentan::camelize($helper) . "Helper";
         $helperFile = Ntentan::$modulesPath . "/helpers/{$helper}/{$camelizedHelper}.php";
         if (file_exists($helperFile)) {
             require_once $helperFile;
             $helperClass = "\\" . Ntentan::$namespace . "\\helpers\\{$helper}\\{$camelizedHelper}";
         } else {
             if ($this->pluginMode) {
                 $path = Ntentan::getPluginPath("{$this->plugin}/helpers/{$helper}");
                 Ntentan::addIncludePath("{$this->plugin}");
                 $helperClass = "\\ntentan\\plugins\\{$this->plugin}\\helpers\\{$helper}\\{$camelizedHelper}";
             } else {
                 if (file_exists(Ntentan::getFilePath("lib/views/helpers/{$helper}"))) {
                     $path = Ntentan::getFilePath("lib/views/helpers/{$helper}");
                     $helperClass = "\\ntentan\\views\\helpers\\{$helper}\\{$camelizedHelper}";
                 } else {
                     return false;
                 }
             }
         }
         Ntentan::addIncludePath($path);
         $helperInstance = new $helperClass();
         $this->loadedHelpers[$this->plugin . $helper] = $helperInstance;
     }
     return $this->loadedHelpers[$this->plugin . $helper];
 }
Exemple #2
0
 /**
  * Loads the widget.
  * 
  * @todo this method should store in the cache the location of the widget
  */
 public function loadWidget($widget)
 {
     $widgetFile = Ntentan::$modulesPath . "/widgets/{$widget}/" . Ntentan::camelize($widget) . "Widget.php";
     if (file_exists($widgetFile)) {
         require_once $widgetFile;
         $widgetClass = "\\" . Ntentan::$namespace . "\\widgets\\{$widget}\\" . Ntentan::camelize($widget) . 'Widget';
         $path = Ntentan::$namespace . "/widgets/{$widget}";
     } else {
         if ($this->pluginMode) {
             $widgetClass = "\\ntentan\\plugins\\{$this->plugin}\\widgets\\{$widget}\\" . Ntentan::camelize($widget) . 'Widget';
             $path = "plugins/{$this->plugin}/widgets/{$widget}";
         } else {
             if (file_exists(Ntentan::getFilePath("lib/views/widgets/{$widget}/" . Ntentan::camelize($widget) . "Widget.php"))) {
                 Ntentan::addIncludePath(Ntentan::getFilePath("lib/controllers/widgets/{$widget}"));
                 $widgetClass = "\\ntentan\\views\\widgets\\{$widget}\\" . Ntentan::camelize($widget) . 'Widget';
                 $path = Ntentan::getFilePath("lib/views/widgets/{$widget}");
             } else {
                 return false;
             }
         }
     }
     $widgetClass = new ReflectionClass($widgetClass);
     $widgetInstance = $widgetClass->newInstance();
     $widgetInstance->filePath = $path;
     $widgetInstance->name = $widget;
     $widgetInstance->plugin = $this->plugin;
     return $widgetInstance;
 }
Exemple #3
0
 public static function getEngineInstance($template)
 {
     $last = explode(".", $template);
     $engine = end($last);
     if (!isset(TemplateEngine::$loadedInstances[$engine])) {
         Ntentan::addIncludePath(Ntentan::getFilePath("lib/views/template_engines/" . $engine));
         $engineClass = "ntentan\\views\\template_engines\\{$engine}\\" . Ntentan::camelize($engine);
         try {
             $engineInstance = new $engineClass();
         } catch (\Exception $e) {
             throw new \ntentan\exceptions\ClassNotFoundException("Could not load template engine class [{$engineClass}] for {$template}");
         }
         TemplateEngine::$loadedInstances[$engine] = $engineInstance;
     }
     TemplateEngine::$loadedInstances[$engine]->template = $template;
     return TemplateEngine::$loadedInstances[$engine];
 }
Exemple #4
0
 public function __construct()
 {
     Ntentan::addIncludePath(Ntentan::getFilePath("lib/views/helpers/forms/api"));
     Ntentan::addIncludePath(Ntentan::getFilePath("lib/views/helpers/forms/api/renderers"));
     \ntentan\views\template_engines\TemplateEngine::appendPath(Ntentan::getFilePath("lib/views/helpers/forms/views"));
 }
Exemple #5
0
 /**
  * The main entry point of the Ntentan application. This method ensures that
  * ntentan is properly setup for service. It takes the configuration
  * data as a parameter. The details of the configuration parameter are
  * extracted from the config file.
  * 
  * @param array $ntentan The configuration data for ntentan
  * @param array $app The configuration data for the application
  */
 public static function setup($ntentan, $app = false)
 {
     // setup autoloader
     spl_autoload_register("ntentan\\Ntentan::autoload");
     $configFile = Ntentan::$configPath . 'app.ini';
     if ($app === false && !file_exists($configFile)) {
         throw new exceptions\ApiIniFileNotFoundException("Config file *app.ini* not found");
     } else {
         $app = $app === false ? parse_ini_file($configFile, true) : $app;
     }
     // hook in the custom exception handler
     set_exception_handler(array("\\ntentan\\Ntentan", "exceptionHandler"));
     // setup paths
     Ntentan::$home = $ntentan['home'];
     Ntentan::$namespace = $ntentan['namespace'];
     Ntentan::$modulesPath = isset($ntentan['modules_path']) ? $ntentan['modules_path'] : $ntentan['namespace'];
     Ntentan::$pluginsHome = $ntentan['plugins'] == '' ? Ntentan::$pluginsHome : $ntentan['plugins'];
     Ntentan::$appHome = $app['home'] == '' ? '.' : $app['home'];
     Ntentan::$appName = $ntentan['app'];
     Ntentan::$prefix = $app['prefix'];
     Ntentan::$context = $app['context'];
     Ntentan::$cacheMethod = $app[Ntentan::$context]['caching'] == '' ? Ntentan::$cacheMethod : $app[Ntentan::$context]['caching'];
     Ntentan::$debug = $app[Ntentan::$context]['debug'] == 'true' || $app[Ntentan::$context]['debug'] == 1 ? true : false;
     unset($app['home']);
     unset($app['plugins']);
     unset($app['prefix']);
     unset($app['context']);
     Ntentan::$config = $app;
     // setup include paths
     Ntentan::addIncludePath(array('lib/controllers/', 'lib/models/', 'lib/models/datastores/', 'lib/models/exceptions/', 'lib/views/', 'lib/views/template_engines/', 'lib/views/widgets/', 'lib/exceptions/', 'lib/caching/', 'lib/sessions', '/', "./", Ntentan::$namespace, Ntentan::$viewsPath, Ntentan::$pluginsHome), Ntentan::$home);
     // load cached items
     if (Cache::exists('nt_camelisations')) {
         Ntentan::$camelisations = Cache::get('nt_camelisations');
     } else {
         Ntentan::$camelisations = array();
     }
     $camelisations = count(Ntentan::$camelisations);
     if (!defined('STDOUT')) {
         sessions\Manager::start();
     }
 }
Exemple #6
0
 /**
  * A utility method to load a controller. This method loads the controller
  * and fetches the contents of the controller into the Controller::$contents
  * variable if the get_contents parameter is set to true on call. If a
  * controller doesn't exist in the module path, a ModelController is loaded
  * to help manipulate the contents of the model. If no model exists in that
  * location, it is asumed to be a package and a package controller is
  * loaded.
  *
  * @param $path                 The path for the model to be loaded.
  * @param $returnInstanceOnly   Fources the method to return only the instance of the controller object.
  * @return Controller
  */
 public static function load($route, $returnInstanceOnly = false)
 {
     $controllerRoute = '';
     $routeArray = explode('/', $route);
     // Loop through the filtered path and extract the controller class
     for ($i = 0; $i < count($routeArray); $i++) {
         $p = $routeArray[$i];
         $pCamelized = Ntentan::camelize($p);
         $filePath = Ntentan::$modulesPath . "/modules/{$controllerRoute}/{$p}/";
         if (file_exists($filePath . "{$pCamelized}Controller.php")) {
             $controllerName = $pCamelized . "Controller";
             $controllerRoute .= "/{$p}";
             $modelRoute .= "{$p}";
             if ($controllerRoute[0] == "/") {
                 $controllerRoute = substr($controllerRoute, 1);
             }
             if ($controllerName == "") {
                 Ntentan::error("Path not found! [{$route}]");
             } else {
                 Ntentan::addIncludePath(Ntentan::$modulesPath . "/{$controllerRoute}/");
                 //$controllerName.php";
                 $controllerNamespace = "\\" . str_replace("/", "\\", Ntentan::$namespace . "/modules/{$controllerRoute}/");
                 $controllerName = $controllerNamespace . $controllerName;
                 if (class_exists($controllerName)) {
                     $controller = new $controllerName();
                     foreach ($controller->components as $component) {
                         $controller->addComponent($component);
                     }
                     $controller->setRoute($controllerRoute);
                     $controller->setName($controllerName);
                     $controller->modelRoute = $modelRoute;
                     $controller->filePath = $filePath;
                     $controller->init();
                     if ($returnInstanceOnly) {
                         return $controller;
                     }
                     // Trap for the cache
                     if (Cache::exists("view_" . Ntentan::getRouteKey()) && Ntentan::$debug === false) {
                         echo Cache::get('view_' . Ntentan::$route);
                         return;
                     }
                     if ($controller->method == '') {
                         $controller->method = $routeArray[$i + 1] != '' ? Ntentan::camelize($routeArray[$i + 1], ".", "", true) : $controller->defaultMethodName;
                         $controller->rawMethod = $routeArray[$i + 1] != '' ? $routeArray[$i + 1] : $controller->defaultMethodName;
                     }
                     if (!$controller->hasMethod()) {
                         $modelRoute .= ".";
                         continue;
                     }
                 } else {
                     Ntentan::error("Controller class *{$controllerName}* not found.");
                 }
                 $controller->runMethod(array_slice($routeArray, $i + 2));
                 return;
             }
         } else {
             $controllerRoute .= "/{$p}";
             $modelRoute .= "{$p}.";
         }
     }
     if (is_object($controller)) {
         $message = "Controller method *{$routeArray[$i - 1]}()* not found for the *{$controllerName}* controller.";
     } else {
         $message = "Controller not found for route *{$route}*";
     }
     Ntentan::error($message);
 }
Exemple #7
0
 public function login()
 {
     Ntentan::addIncludePath(Ntentan::getFilePath('lib/controllers/components/auth/methods'));
     $authenticatorClass = __NAMESPACE__ . '\\methods\\' . Ntentan::camelize($this->authMethod);
     if (class_exists($authenticatorClass)) {
         $this->authMethodInstance = new $authenticatorClass();
         $this->authMethodInstance->usersModel = $this->_usersModel;
     } else {
         print Ntentan::message("Authenticator class *{$authenticatorClass}* not found.");
     }
     if ($this->loggedIn()) {
         $this->performSuccessOperation();
     } else {
         if ($this->authMethodInstance->login()) {
             $this->performSuccessOperation();
         } else {
             switch ($this->onFailure) {
                 case AuthComponent::CALL_FUNCTION:
                     $decomposed = explode("::", $this->failureFunction);
                     $className = $decomposed[0];
                     $methodName = $decomposed[1];
                     $method = new \ReflectionMethod($className, $methodName);
                     $method->invoke(null, $this->controller);
                     break;
                 case AuthComponent::REDIRECT:
                     $this->loginRoute = $this->loginRoute == null ? $this->controller->route . "/login" : $this->loginRoute;
                     $this->logoutRoute = $this->logoutRoute == null ? $this->controller->route . "/logout" : $this->logoutRoute;
                     $this->redirectToLogin();
                     break;
                 default:
                     $this->set('login_status', false);
                     break;
             }
         }
     }
 }