예제 #1
0
파일: ModuleManager.php 프로젝트: n2n/n2n
 /**
  * Returns the module which the passed type is part of.
  * @param string $typeName
  * @param bool $required
  * @throws UnknownModuleException if $required is true and type is not part of any module.
  * @return Module or null if $required is false and type is not part of any module.
  */
 public function getModuleOfTypeName(string $typeName, bool $required = true)
 {
     $typeName = trim($typeName, '\\');
     $module = null;
     $nsLength = 0;
     foreach ($this->modules as $curNamespace => $curModule) {
         if (!StringUtils::startsWith($curNamespace . '\\', $typeName)) {
             continue;
         }
         $curNsLength = strlen($curNamespace);
         if ($curNsLength > $nsLength) {
             $module = $curModule;
             $nsLength = $curNsLength;
         }
     }
     if (!$required || $module !== null) {
         return $module;
     }
     throw new UnknownModuleException('Type is not part of any installed modules: ' . $typeName);
 }
예제 #2
0
 private function extractPathParts(GroupReader $groupReader, string $prefix = null)
 {
     $names = array();
     foreach ($groupReader->getNames() as $key) {
         if ($prefix !== null) {
             if (!StringUtils::startsWith($prefix, $key)) {
                 continue;
             }
             $key = ltrim(mb_substr($key, mb_strlen($prefix)), self::DEFAULT_LEVEL_SEPARATOR);
         }
         $keyParts = explode(self::DEFAULT_LEVEL_SEPARATOR, $key, 2);
         $names[] = $keyParts[0];
     }
     return $names;
 }
예제 #3
0
파일: TypeLoader.php 프로젝트: n2n/n2n
 public static function removeIncludePathOfFilePath($filePath)
 {
     foreach (self::$includePaths as $includePath) {
         if (!StringUtils::startsWith($includePath, $filePath)) {
             continue;
         }
         return mb_substr($filePath, strlen($includePath));
     }
     throw new FileIsNotPartOfIncludePathException('File path is not part of a include path: ' . $filePath);
 }