Esempio n. 1
0
 /**
  * Returns routePaths
  *
  * @param mixed $paths
  * @return array
  */
 public static function getRoutePaths($paths = null)
 {
     if ($paths !== null) {
         if (is_string($paths)) {
             $moduleName = null;
             $controllerName = null;
             $actionName = null;
             // Explode the short paths using the :: separator
             $parts = explode('::', $paths);
             // Create the array paths dynamically
             switch (count($parts)) {
                 case 3:
                     $moduleName = $parts[0];
                     $controllerName = $parts[1];
                     $actionName = $parts[2];
                     break;
                 case 2:
                     $controllerName = $parts[0];
                     $actionName = $parts[1];
                     break;
                 case 1:
                     $controllerName = $parts[0];
                     break;
             }
             $routePaths = [];
             // Process module name
             if ($moduleName !== null) {
                 $routePaths['module'] = $moduleName;
             }
             // Process controller name
             if ($controllerName !== null) {
                 // Check if we need to obtain the namespace
                 if (strpos($controllerName, '\\') !== false) {
                     $classWithNamespace = get_class($controllerName);
                     $pos = strrpos($classWithNamespace, '\\');
                     if ($pos !== false) {
                         //Extract the namespace from the namespaced class
                         $namespaceName = substr($classWithNamespace, 0, $pos);
                         //Extract the real class name from the namespaced class
                         $realClassName = substr($classWithNamespace, $pos);
                         //Update the namespace
                         if ($namespaceName) {
                             $routePaths['namespace'] = $namespaceName;
                         }
                     } else {
                         $realClassName = $classWithNamespace;
                     }
                 } else {
                     $realClassName = $controllerName;
                 }
                 // Always pass the controller to lowercase
                 $routePaths["controller"] = Text::uncamelize($realClassName);
             }
             // Process action name
             if ($actionName !== null) {
                 $routePaths['action'] = $actionName;
             }
         } else {
             $routePaths = $paths;
         }
     } else {
         $routePaths = [];
     }
     if (!is_array($routePaths)) {
         throw new Exception("The route contains invalid paths");
     }
     return $routePaths;
 }
Esempio n. 2
0
 /**
  * Returns collection name mapped in the model
  *
  * @return string
  */
 public function getSource()
 {
     $source = $this->_source;
     if (!$source) {
         $collection = $this;
         $source = Text::uncamelize(basename(get_class($this)));
         $this->_source = $source;
     }
     return $source;
 }