/**
  * Language constructor.
  * @param string $domain
  * @param string $code
  */
 public function __construct(Manager $manager, $domain, $code)
 {
     $this->manager = $manager;
     //
     $languages = $manager->getLanguages();
     if (isset($languages[$code]) && !empty($languages[$code])) {
         $info = $languages[$code];
         $this->code = $code;
         //
         $this->info = $info['info'];
         $this->name = $info['name'];
         $this->locale = $info['locale'];
         $this->direction = $info['dir'];
     } else {
         $code = 'en';
     }
     $this->domain = $domain;
     //
     $pathName = Inflector::classify($domain);
     if ($pathName == 'Nova') {
         $basePath = SYSTEMDIR;
     } else {
         if ($pathName == 'Shared') {
             $basePath = ROOTDIR . 'shared' . DS;
         } else {
             if (is_dir(APPDIR . 'Modules' . DS . $pathName)) {
                 $basePath = APPDIR . 'Modules/' . $pathName . DS;
             } else {
                 if (is_dir(APPDIR . 'Templates' . DS . $pathName)) {
                     $basePath = APPDIR . 'Templates/' . $pathName . DS;
                 } else {
                     $basePath = APPDIR;
                 }
             }
         }
     }
     $filePath = $basePath . 'Language' . DS . ucfirst($code) . DS . 'messages.php';
     // Check if the language file is readable.
     if (!is_readable($filePath)) {
         return;
     }
     // Get the Domain's messages from the Language file.
     $messages = (include $filePath);
     // A final consistency check.
     if (is_array($messages) && !empty($messages)) {
         $this->messages = $messages;
     }
 }
Esempio n. 2
0
 protected function dispatchFile($uri)
 {
     // For properly Assets serving, the file URI should be as following:
     //
     // /templates/default/assets/css/style.css
     // /modules/blog/assets/css/style.css
     // /assets/css/style.css
     $filePath = '';
     if (preg_match('#^assets/(.*)$#i', $uri, $matches)) {
         $filePath = ROOTDIR . 'assets' . DS . $matches[1];
     } else {
         if (preg_match('#^(templates|modules)/(.+)/assets/(.*)$#i', $uri, $matches)) {
             // We need to classify the path name (the Module/Template path).
             $basePath = ucfirst($matches[1]) . DS . Inflector::classify($matches[2]);
             $filePath = APPDIR . $basePath . DS . 'Assets' . DS . $matches[3];
         }
     }
     if (!empty($filePath)) {
         // Serve the specified Asset File.
         Response::serveFile($filePath);
         return true;
     }
     return false;
 }
Esempio n. 3
0
 /**
  * Ability to call controllers in their module/directory/controller/method/param way.
  *
  * NOTE: This Auto-Dispatch routing use the styles:
  *      <DIR><directory><controller><method><params>
  *      <DIR><module><directory><controller><method><params>
  *
  * @param $uri
  * @return bool
  */
 public function autoDispatch($uri)
 {
     // Explode the URI in its parts.
     $parts = explode('/', trim($uri, '/'));
     // Loop through URI parts, checking for the Controller file including its path.
     $controller = '';
     if (!empty($parts)) {
         // Classify, to permit: '<DIR>/file_manager/admin/' -> '<APPDIR>/Modules/FileManager/Admin/
         $controller = Inflector::classify(array_shift($parts));
     }
     // Verify if the first URI part match a Module.
     $testPath = APPDIR . 'Modules' . DS . $controller;
     if (!empty($controller) && is_dir($testPath)) {
         // Walking in a Module path.
         $moduleName = $controller;
         $basePath = 'Modules/' . $controller . '/Controllers/';
         // Go further only if have other URI Parts, to permit URL mappings like:
         // '<DIR>/clients' -> '<APPDIR>/app/Modules/Clients/Controllers/Clients.php'
         if (!empty($parts)) {
             $controller = Inflector::classify(array_shift($parts));
         }
     } else {
         $moduleName = '';
         $basePath = 'Controllers/';
     }
     // Check for the Controller, even in sub-directories.
     $directory = '';
     while (!empty($parts)) {
         $testPath = APPDIR . str_replace('/', DS, $basePath . $directory . $controller);
         if (!is_readable($testPath . '.php') && is_dir($testPath)) {
             $directory .= $controller . DS;
             $controller = Inflector::classify(array_shift($parts));
             continue;
         }
         break;
     }
     // Get the normalized Controller
     $defaultOne = !empty($moduleName) ? $moduleName : DEFAULT_CONTROLLER;
     $controller = !empty($controller) ? $controller : $defaultOne;
     // Get the normalized Method
     $method = !empty($parts) ? array_shift($parts) : DEFAULT_METHOD;
     // Prepare the Controller's class name.
     $controller = str_replace(array('//', '/'), '\\', 'App/' . $basePath . $directory . $controller);
     // The Method shouldn't start with '_'; also check if the Controller's class exists.
     if ($method[0] !== '_' && class_exists($controller)) {
         // Get the parameters, if any.
         $params = !empty($parts) ? $parts : array();
         // Invoke the Controller's Method with the given arguments.
         return $this->invokeController($controller, $method, $params);
     }
     return false;
 }