|
|
|
@ -18,10 +18,17 @@ abstract class ResourceLocator { |
|
|
|
|
|
|
|
|
|
protected $resources = array(); |
|
|
|
|
|
|
|
|
|
/** @var \OCP\ILogger */ |
|
|
|
|
protected $logger; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param \OCP\ILogger $logger |
|
|
|
|
* @param string $theme |
|
|
|
|
* @param array $core_map |
|
|
|
|
* @param array $party_map |
|
|
|
|
*/ |
|
|
|
|
public function __construct( $theme, $core_map, $party_map ) { |
|
|
|
|
public function __construct(\OCP\ILogger $logger, $theme, $core_map, $party_map) { |
|
|
|
|
$this->logger = $logger; |
|
|
|
|
$this->theme = $theme; |
|
|
|
|
$this->mapping = $core_map + $party_map; |
|
|
|
|
$this->serverroot = key($core_map); |
|
|
|
@ -29,41 +36,82 @@ abstract class ResourceLocator { |
|
|
|
|
$this->webroot = $this->mapping[$this->serverroot]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
abstract public function doFind( $resource ); |
|
|
|
|
abstract public function doFindTheme( $resource ); |
|
|
|
|
/** |
|
|
|
|
* @param string $resource |
|
|
|
|
*/ |
|
|
|
|
abstract public function doFind($resource); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param string $resource |
|
|
|
|
*/ |
|
|
|
|
abstract public function doFindTheme($resource); |
|
|
|
|
|
|
|
|
|
public function find( $resources ) { |
|
|
|
|
try { |
|
|
|
|
foreach($resources as $resource) { |
|
|
|
|
/** |
|
|
|
|
* Finds the resources and adds them to the list |
|
|
|
|
* |
|
|
|
|
* @param array $resources |
|
|
|
|
*/ |
|
|
|
|
public function find($resources) { |
|
|
|
|
foreach ($resources as $resource) { |
|
|
|
|
try { |
|
|
|
|
$this->doFind($resource); |
|
|
|
|
} catch (ResourceNotFoundException $e) { |
|
|
|
|
$resourceApp = substr($resource, 0, strpos($resource, '/')); |
|
|
|
|
$this->logger->error('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
|
|
|
} |
|
|
|
|
if (!empty($this->theme)) { |
|
|
|
|
foreach($resources as $resource) { |
|
|
|
|
} |
|
|
|
|
if (!empty($this->theme)) { |
|
|
|
|
foreach ($resources as $resource) { |
|
|
|
|
try { |
|
|
|
|
$this->doFindTheme($resource); |
|
|
|
|
} catch (ResourceNotFoundException $e) { |
|
|
|
|
$resourceApp = substr($resource, 0, strpos($resource, '/')); |
|
|
|
|
$this->logger->error('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (\Exception $e) { |
|
|
|
|
throw new \Exception($e->getMessage().' serverroot:'.$this->serverroot); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
/** |
|
|
|
|
* append the $file resource if exist at $root |
|
|
|
|
* |
|
|
|
|
* @param string $root path to check |
|
|
|
|
* @param string $file the filename |
|
|
|
|
* @param string|null $webroot base for path, default map $root to $webroot |
|
|
|
|
* @param string|null $webRoot base for path, default map $root to $webRoot |
|
|
|
|
* @return bool True if the resource was found, false otherwise |
|
|
|
|
*/ |
|
|
|
|
protected function appendIfExist($root, $file, $webroot = null) { |
|
|
|
|
protected function appendIfExist($root, $file, $webRoot = null) { |
|
|
|
|
if (is_file($root.'/'.$file)) { |
|
|
|
|
if (!$webroot) { |
|
|
|
|
$webroot = $this->mapping[$root]; |
|
|
|
|
} |
|
|
|
|
$this->resources[] = array($root, $webroot, $file); |
|
|
|
|
$this->append($root, $file, $webRoot, false); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* append the $file resource at $root |
|
|
|
|
* |
|
|
|
|
* @param string $root path to check |
|
|
|
|
* @param string $file the filename |
|
|
|
|
* @param string|null $webRoot base for path, default map $root to $webRoot |
|
|
|
|
* @param bool $throw Throw an exception, when the route does not exist |
|
|
|
|
* @throws ResourceNotFoundException Only thrown when $throw is true and the resource is missing |
|
|
|
|
*/ |
|
|
|
|
protected function append($root, $file, $webRoot = null, $throw = true) { |
|
|
|
|
if (!$webRoot) { |
|
|
|
|
$webRoot = $this->mapping[$root]; |
|
|
|
|
} |
|
|
|
|
$this->resources[] = array($root, $webRoot, $file); |
|
|
|
|
|
|
|
|
|
if ($throw && !is_file($root . '/' . $file)) { |
|
|
|
|
throw new ResourceNotFoundException($file, $webRoot); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the list of all resources that should be loaded |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public function getResources() { |
|
|
|
|
return $this->resources; |
|
|
|
|
} |
|
|
|
|