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'));
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(); } }
public static function formatDate($inShortFormatDateOrTimestamp, $hasMinutes = false) { $tstp = Localization::dateToTimestamp($inShortFormatDateOrTimestamp, Localization::SHORT, $hasMinutes ? Localization::SHORT : Localization::NONE, true); if ($hasMinutes) { return date('Y-m-d', $tstp); } else { return date('Y-m-d H:i:s', $tstp); } }