Ejemplo n.º 1
0
 /**
  * Determine file path of a resource provided by an extension
  *
  * @param $ext string, extension name; use 'civicrm' for core
  * @param $file string, file path -- relative to the extension base dir
  *
  * @return bool|string (string|bool), full file path or FALSE if not found
  */
 public function getPath($ext, $file)
 {
     // TODO consider caching results
     $path = $this->extMapper->keyToBasePath($ext) . '/' . $file;
     if (is_file($path)) {
         return $path;
     }
     return FALSE;
 }
Ejemplo n.º 2
0
 /**
  * Determine file path of a resource provided by an extension.
  *
  * @param string $ext
  *   extension name; use 'civicrm' for core.
  * @param string|NULL $file
  *   file path -- relative to the extension base dir.
  *
  * @return bool|string
  *   full file path or FALSE if not found
  */
 public function getPath($ext, $file = NULL)
 {
     // TODO consider caching results
     $base = $this->paths->hasVariable($ext) ? rtrim($this->paths->getVariable($ext, 'path'), '/') : $this->extMapper->keyToBasePath($ext);
     if ($file === NULL) {
         return $base;
     }
     $path = $base . '/' . $file;
     if (is_file($path)) {
         return $path;
     }
     return FALSE;
 }
Ejemplo n.º 3
0
 /**
  * @return \Composer\Autoload\ClassLoader
  * @throws \CRM_Extension_Exception
  * @throws \Exception
  */
 public function buildClassLoader()
 {
     $loader = new \Composer\Autoload\ClassLoader();
     $statuses = $this->manager->getStatuses();
     foreach ($statuses as $key => $status) {
         if ($status !== CRM_Extension_Manager::STATUS_INSTALLED) {
             continue;
         }
         $path = $this->mapper->keyToBasePath($key);
         $info = $this->mapper->keyToInfo($key);
         if (!empty($info->classloader)) {
             foreach ($info->classloader as $mapping) {
                 switch ($mapping['type']) {
                     case 'psr4':
                         $loader->setPsr4($mapping['prefix'], $path . '/' . $mapping['path']);
                         break;
                 }
                 $result[] = $mapping;
             }
         }
     }
     return $loader;
 }