Beispiel #1
0
 protected function __construct()
 {
     parent::__construct();
     $front = Front::getInstance();
     $this->setBasePath($front->getModuleName());
     // send the label Manager to the view
     $this->_vars['labels'] = \Nf\LabelManager::getInstance();
 }
Beispiel #2
0
 function go()
 {
     if (php_sapi_name() == 'cli') {
         $inAction = $this->initCliEnvironment();
         $uri = $inAction['uri'];
         Error\Handler::setErrorDisplaying();
         $front = Front::getInstance();
         $request = new Front\Request\Cli($uri);
         $front->setRequest($request);
         $request->setAdditionalCliParams();
         $response = new Front\Response\Cli();
         $front->setResponse($response);
         $front->setApplicationNamespace($this->_applicationNamespace);
         $this->setTimezone();
         // routing
         $router = Router::getInstance();
         $front->setRouter($router);
         $router->addAllRoutes();
         // order in finding routes
         $router->setStructuredRoutes();
         $front->addModuleDirectory($this->_applicationNamespace, Registry::get('applicationPath') . '/application/cli/');
         $front->addModuleDirectory('library', Registry::get('libraryPath') . '/php/application/cli/');
         $labelManager = LabelManager::getInstance();
         $labelManager->loadLabels(Registry::get('locale'));
         $localization = Localization::getInstance();
         $localization->setLocale(Registry::get('locale'));
         if ($inAction['type'] == 'default') {
             $testDispatch = $front->dispatch();
             if ($testDispatch) {
                 if ($front->init() !== false) {
                     $front->launchAction();
                     $front->postLaunchAction();
                 }
                 $response->sendResponse();
             } else {
                 throw new \Exception('Action not found : ' . $uri);
             }
         } else {
             $front->parseParameters($inAction['uri']);
             $className = array();
             // $inAction['uri'] might be a class name with a static method like \Nf\Make::compress
             if (strpos($inAction['uri'], '\\') !== false) {
                 if (strpos($inAction['uri'], '::') === false) {
                     throw new \Exception('You have to specify the model and method to call, or just choose a method from the "Nf\\Make" class.');
                 } else {
                     $uriSplit = explode('::', $inAction['uri']);
                     $className = $uriSplit[0];
                     $methodName = $uriSplit[1];
                     $obj = new $className();
                     $className::$methodName();
                 }
             } else {
                 // or an already integrated method in Nf\Make
                 $methodName = $inAction['uri'];
                 \Nf\Make::$methodName();
             }
         }
     } else {
         $this->initHttpEnvironment();
         Error\Handler::setErrorDisplaying();
         $front = Front::getInstance();
         $request = new Front\Request\Http();
         $front->setRequest($request);
         $response = new Front\Response\Http();
         $front->setResponse($response);
         $front->setApplicationNamespace($this->_applicationNamespace);
         $this->setTimezone();
         // routing
         $router = Router::getInstance();
         $front->setRouter($router);
         $router->addAllRoutes();
         // order in finding routes
         $router->setRoutesFromFiles();
         $router->setRootRoutes();
         $router->setStructuredRoutes();
         // modules directory for this version
         $front->addModuleDirectory($this->_applicationNamespace, Registry::get('applicationPath') . '/application/' . Registry::get('version') . '/');
         $front->addModuleDirectory('library', Registry::get('libraryPath') . '/php/application/' . Registry::get('version') . '/');
         $config = Registry::get('config');
         if (isset($config->session->handler)) {
             $front->setSession(Session::start());
         }
         $labelManager = LabelManager::getInstance();
         $labelManager->loadLabels(Registry::get('locale'));
         $localization = Localization::getInstance();
         Localization::setLocale(Registry::get('locale'));
         $testDispatch = $front->dispatch();
         $requestIsClean = $request->sanitizeUri();
         if ($requestIsClean) {
             if ($testDispatch === true) {
                 $request->setPutFromRequest();
                 if (!$request->redirectForTrailingSlash()) {
                     if ($front->init() !== false) {
                         if (!$front->response->isRedirect()) {
                             $front->launchAction();
                         }
                         if (!$front->response->isRedirect()) {
                             $front->postLaunchAction();
                         }
                     }
                 }
             } else {
                 Error\Handler::handleNotFound(404);
             }
         } else {
             Error\Handler::handleForbidden(403);
         }
         $response->sendResponse();
     }
 }
Beispiel #3
0
 public function setBasePath($path)
 {
     $config = \Nf\Registry::get('config');
     // configuration de Smarty
     $this->_smarty->setTemplateDir(array(\Nf\Registry::get('applicationPath') . '/application/' . \Nf\Registry::get('version') . '/' . $path . '/views/', \Nf\Registry::get('libraryPath') . '/php/application/' . \Nf\Registry::get('version') . '/' . $path . '/views/'));
     // répertoire du cache Smarty
     $cacheDirectory = realpath(\Nf\Registry::get('applicationPath')) . '/cache/smarty/' . \Nf\Registry::get('version') . '/' . \Nf\Registry::get('locale') . '/' . $path . '/';
     // répertoire des templates compilés
     $compileDirectory = realpath(\Nf\Registry::get('applicationPath')) . '/cache/templates_c/' . \Nf\Registry::get('version') . '/' . \Nf\Registry::get('locale') . '/' . $path . '/';
     $configDirectory = realpath(\Nf\Registry::get('applicationPath')) . '/configs/' . \Nf\Registry::get('version') . '/' . \Nf\Registry::get('locale') . '/' . $path . '/';
     $pluginsDirectories = array(realpath(\Nf\Registry::get('applicationPath') . '/plugins/'), realpath(\Nf\Registry::get('libraryPath') . '/php/plugins/'), realpath(\Nf\Registry::get('libraryPath') . '/php/classes/Smarty/plugins/'));
     \Nf\File::mkdir($cacheDirectory, 0755, true);
     \Nf\File::mkdir($compileDirectory, 0755, true);
     $this->_smarty->setUseSubDirs(true);
     // répertoire de cache de smarty
     $this->_smarty->setCacheDir($cacheDirectory);
     // répertoire de compilation
     $this->_smarty->setCompileDir($compileDirectory);
     // répertoire des configs smarty des applis
     $this->_smarty->setConfigDir($configDirectory);
     // répertoire des plugins
     foreach ($pluginsDirectories as $pluginsDirectory) {
         $this->_smarty->addPluginsDir($pluginsDirectory);
     }
     $this->_smarty->left_delimiter = $config->view->smarty->leftDelimiter;
     $this->_smarty->right_delimiter = $config->view->smarty->rightDelimiter;
     // dev : we disable Smarty's caching
     if (\Nf\Registry::get('environment') == 'dev') {
         $this->_smarty->caching = false;
         $this->_smarty->force_compile = true;
         $this->_smarty->setCompileCheck(true);
     }
     // only one file generated for each rendering
     $this->_smarty->merge_compiled_includes = true;
     // send the registry to the view
     $this->_smarty->assign('_registry', \Nf\Registry::getInstance());
     // send the label Manager to the view
     $this->_smarty->assign('_labels', \Nf\LabelManager::getInstance());
     // $this->_smarty->testInstall();
 }
Beispiel #4
0
require $libraryPath . '/Nf/Autoloader.php';
$autoloader = new \Nf\Autoloader();
$autoloader->addNamespaceRoot($applicationNamespace, $applicationPath . '/models');
$autoloader->addNamespaceRoot('Nf', $libraryPath . '/Nf');
$autoloader->addNamespaceRoot('Library', $libraryPath . '/php/models');
$autoloader->addNamespaceRoot('', $applicationPath . '/models');
$autoloader->register();
\Nf\Registry::set('libraryPath', $libraryPath);
\Nf\Registry::set('applicationPath', $applicationPath);
$urlIni = \Nf\Ini::parse(\Nf\Registry::get('applicationPath') . '/configs/url.ini', true);
\Nf\Registry::set('urlIni', $urlIni);
\Nf\Registry::set('environment', 'test');
\Nf\Registry::set('locale', $urlIni->i18n->defaultLocale);
\Nf\Registry::set('version', 'cli');
$config = \Nf\Ini::parse(\Nf\Registry::get('applicationPath') . '/configs/config.ini', true, \Nf\Registry::get('locale') . '_' . \Nf\Registry::get('environment') . '_' . \Nf\Registry::get('version'));
\Nf\Registry::set('config', $config);
\Nf\Error\Handler::setErrorDisplaying();
$front = \Nf\Front::getInstance();
$request = new \Nf\Front\Request\Cli('/');
$front->setRequest($request);
$response = new \Nf\Front\Response\Cli();
$front->setResponse($response);
$front->setApplicationNamespace($applicationNamespace);
// routing
$router = \Nf\Router::getInstance();
$front->setRouter($router);
$router->addAllRoutes();
$labelManager = \Nf\LabelManager::getInstance();
$labelManager->loadLabels(\Nf\Registry::get('locale'));
$localization = \Nf\Localization::getInstance();
$localization->setLocale(\Nf\Registry::get('locale'));
 public function getLabel($lbl)
 {
     return \Nf\LabelManager::get($lbl);
 }