public static function guests($location)
 {
     $userRepository = Injector::call('\\Nanozen\\Repositories\\userRepository');
     if (!$userRepository->hasLogged()) {
         static::to($location);
     }
 }
 public static function _for($role, $redirectLocation)
 {
     $userRepository = Injector::call('\\Nanozen\\Repositories\\UserRepository');
     if ($role == self::LOGGED) {
         if ($userRepository->hasLogged()) {
             Redirect::to($redirectLocation);
             return;
         }
         return;
     }
     if ($role == self::GUESTS) {
         if (!$userRepository->hasLogged()) {
             Redirect::to($redirectLocation);
             return;
         }
         return;
     }
     $loggedUser = $userRepository->find(['id' => Session::get('id')]);
     if (is_string($role) && $role != "") {
         if (self::checkSingleRole($role, $loggedUser)) {
             Redirect::to($redirectLocation);
         }
     }
     if (is_array($role) && !empty($role)) {
         if (self::checkForManyRoles($role, $loggedUser)) {
             Redirect::to($redirectLocation);
         }
     }
     return true;
 }
Beispiel #3
0
 public function index()
 {
     $query = "SELECT value FROM options WHERE name = 'app_homepage'";
     $homePageId = $this->db()->query($query)->fetch(\PDO::FETCH_ASSOC, false)['value'];
     if (is_numeric($homePageId)) {
         $homepageExists = $this->pageRepository->find(['id' => $homePageId], false);
         if ($homepageExists) {
             $pagesController = Injector::call('\\Nanozen\\Controllers\\PagesController');
             $pagesController->show($homePageId, false);
         }
     }
     $this->view()->render('home.index');
 }
 public function dispatch($target, $variables)
 {
     $this->validateToken();
     if (!$target) {
         $this->throw404();
     }
     if (is_callable($target)) {
         call_user_func($target);
         exit;
     }
     // Here call the target if it's comming from the automatic route matching mechanism.
     if (is_array($target) && !empty($target) && $target['type'] == 'automatic_match') {
         $this->controller = Injector::call($target['controller']);
         $this->action = $target['action'];
         $this->params = $target['params'];
         $this->injectBindingModelIfAny();
         call_user_func_array([$this->controller, $this->action], $this->params);
         exit;
     }
     if (strpos($target, '|')) {
         $this->isAreaRoute = true;
         list($areaFolderPrefix, $targetControllerAndAction) = explode('|', $target);
         $target = $targetControllerAndAction;
     }
     list($this->controller, $this->action) = $this->extractControllerAndActionFromTarget($target);
     $this->controller = $this->configProviderContract->get('namespaces.controllers') . $this->controller;
     if ($this->isAreaRoute) {
         $areasNamespace = $this->configProviderContract->get('namespaces.areas');
         $this->controller = explode('\\', $this->controller);
         $this->controller = $areasNamespace . $areaFolderPrefix . '\\Controllers\\' . end($this->controller);
     }
     if ($this->controllerExists($this->controller)) {
         $variablesCount = count($variables);
         $actionRequiredParametersCount = (new \ReflectionMethod($this->controller, $this->action))->getNumberOfRequiredParameters();
         if ($actionRequiredParametersCount > $variablesCount) {
             $message = "Action {$action} requires {$actionRequiredParametersCount} parameters.\n                {$variablesCount} given. Change the route's parameters or the action's ones.";
             throw new \Exception($message);
         }
         if ($this->actionExists($this->controller, $this->action)) {
             $this->controller = Injector::call($this->controller);
             $this->injectBindingModelIfAny();
             call_user_func_array([$this->controller, $this->action], $variables);
             exit;
         }
     }
 }
 public function setupRoutes(CustomRoutingProviderContract $router)
 {
     include Injector::call('\\Nanozen\\Providers\\Config\\ConfigProvider')->get('paths.routes_file');
 }
Beispiel #6
0
<?php

use Nanozen\App\Injector;
use Nanozen\App\InjectorTypes;
/**
 * Preparing some dependency injections.
 * 
 */
Injector::prepare(InjectorTypes::TYPE_CLASS, 'configProviderContract', '\\Nanozen\\Providers\\Config\\ConfigProvider');
Injector::prepare(InjectorTypes::TYPE_CLASS, 'dispatchingProviderContract', '\\Nanozen\\Providers\\Dispatching\\DispatchingProvider');
Injector::prepare(InjectorTypes::TYPE_CLASS, 'autoRoutingProviderContract', '\\Nanozen\\Providers\\AutoRouting\\AutoRoutingProvider');
Injector::prepare(InjectorTypes::TYPE_CLASS, 'viewProviderContract', '\\Nanozen\\Providers\\View\\ViewProvider');
Injector::prepare(InjectorTypes::TYPE_CLASS, 'commonDataInjector', '\\Nanozen\\Providers\\View\\CommonDataInjector');
Injector::prepare(InjectorTypes::TYPE_SINGLETON, 'viewCommonDataProviderContract', '\\Nanozen\\Providers\\View\\ViewCommonDataProvider');
Injector::prepare(InjectorTypes::TYPE_SINGLETON, 'databaseProviderContract', '\\Nanozen\\Providers\\Database\\DatabaseProvider', ['mysql', 'localhost', 'nanozen_cms', 'root', 'root']);
Injector::prepare(InjectorTypes::TYPE_SINGLETON, 'customRoutingProviderContract', '\\Nanozen\\Providers\\CustomRouting\\CustomRoutingProvider', ['\\Nanozen\\Providers\\CustomRouting\\DispatchingProvider']);
// CMS specific:
Injector::prepare(InjectorTypes::TYPE_CLASS, 'userRepository', '\\Nanozen\\Repositories\\UserRepository');
Beispiel #7
0
 public function __construct()
 {
     $this->userRepository = Injector::call('\\Nanozen\\Repositories\\UserRepository');
 }
<?php

use Nanozen\App\Injector;
use Nanozen\App\InjectorTypes;
/**
 * Preparing some dependency injections.
 * 
 */
Injector::prepare(InjectorTypes::TYPE_CLASS, 'configProviderContract', '\\Nanozen\\Providers\\Config\\ConfigProvider');
Injector::prepare(InjectorTypes::TYPE_CLASS, 'dispatchingProviderContract', '\\Nanozen\\Providers\\Dispatching\\DispatchingProvider');
Injector::prepare(InjectorTypes::TYPE_CLASS, 'autoRoutingProviderContract', '\\Nanozen\\Providers\\AutoRouting\\AutoRoutingProvider');
Injector::prepare(InjectorTypes::TYPE_CLASS, 'viewProviderContract', '\\Nanozen\\Providers\\View\\ViewProvider');
Injector::prepare(InjectorTypes::TYPE_CLASS, 'commonDataInjector', '\\Nanozen\\Providers\\View\\CommonDataInjector');
Injector::prepare(InjectorTypes::TYPE_SINGLETON, 'viewCommonDataProviderContract', '\\Nanozen\\Providers\\View\\ViewCommonDataProvider');
Injector::prepare(InjectorTypes::TYPE_SINGLETON, 'databaseProviderContract', '\\Nanozen\\Providers\\Database\\DatabaseProvider', ['mysql', 'localhost', 'nanozen_framework', 'root', 'root']);
Injector::prepare(InjectorTypes::TYPE_SINGLETON, 'customRoutingProviderContract', '\\Nanozen\\Providers\\CustomRouting\\CustomRoutingProvider', ['\\Nanozen\\Providers\\CustomRouting\\DispatchingProvider']);
 private function getBlocksByActiveStatus($active = false)
 {
     $blocksRepository = Injector::call('\\Nanozen\\Repositories\\BlockRepository');
     $blocks = $blocksRepository->all($active);
     $blocksRepository = [];
     foreach ($blocks as $block) {
         $blocksRepository[] = BlockFactory::make($block);
     }
     return $blocksRepository;
 }
 public function __construct()
 {
     $this->settingsRepository = Injector::call('\\Nanozen\\Repositories\\SettingRepository');
 }
Beispiel #11
0
 public function __construct()
 {
     $this->blockRepository = Injector::call('\\Nanozen\\Repositories\\BlockRepository');
     $this->pageRepository = Injector::call('\\Nanozen\\Repositories\\PageRepository');
     $this->regions = $this->pageRepository->getRegions();
 }
 private function setDefaultPath()
 {
     $config = Injector::call('\\Nanozen\\Providers\\Config\\configProvider');
     $this->path = $config->get('paths.views');
     return $this;
 }