Advertisement
Guest User

Untitled

a guest
Jun 30th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1.  
  2.     /**
  3.      * Maps given class
  4.      *
  5.      * @param string $class Class to map
  6.      *
  7.      * @return boolean Whether class was mapped properly or not
  8.      *
  9.      * @author Manulaiko <manulaiko@gmail.com>
  10.      */
  11.     public function mapNamespace(string $class) : boolean
  12.     {
  13.         //Delete Root namespace
  14.         if(strpos($class, 0, 1) == "\\") {
  15.             $class = substr($class, 1);
  16.         }
  17.        
  18.         foreach($this->_mappedNamespaces as $mapNamespace => $mapClass) {
  19.             //Check that $class starts with $mapNamespace
  20.             if(strpos($mapNamespace, $class) === 0) {
  21.                 //Retrieve $class without $mapNamespace
  22.                 $className = substr($class, strlen($mapNamespace));
  23.  
  24.                 //Check that $className isn't a namespace
  25.                 if(strpos($className, "\\") !== 0) {
  26.                     continue;
  27.                 }
  28.  
  29.                 //Add class alias
  30.                 class_alias($class, $mapClass);
  31.                
  32.                 return true;
  33.             }
  34.         }
  35.  
  36.         return false;
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement