mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
API Add experimental getResource() to Module
This commit is contained in:
parent
416b3dd724
commit
874c6ccdd4
@ -4,6 +4,7 @@ namespace SilverStripe\Core\Manifest;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Serializable;
|
use Serializable;
|
||||||
|
use SilverStripe\Assets\File;
|
||||||
|
|
||||||
class Module implements Serializable
|
class Module implements Serializable
|
||||||
{
|
{
|
||||||
@ -148,4 +149,33 @@ class Module implements Serializable
|
|||||||
$this->composerData = $result;
|
$this->composerData = $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets path to physical file resource relative to base directory.
|
||||||
|
* Directories included
|
||||||
|
*
|
||||||
|
* This method makes no distinction between public / local resources,
|
||||||
|
* which may change in the near future.
|
||||||
|
*
|
||||||
|
* @internal Experimental API and may change
|
||||||
|
* @param string $path File or directory path relative to module directory
|
||||||
|
* @return string Path relative to base directory
|
||||||
|
*/
|
||||||
|
public function getResource($path)
|
||||||
|
{
|
||||||
|
return File::join_paths($this->getRelativePath(), $path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this module has a given resource
|
||||||
|
*
|
||||||
|
* @internal Experimental API and may change
|
||||||
|
* @param string $path
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function hasResource($path)
|
||||||
|
{
|
||||||
|
$resource = $this->getResource($path);
|
||||||
|
return file_exists($this->basePath . '/' . $resource);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,18 @@ class ModuleLoader
|
|||||||
return self::$instance ? self::$instance : self::$instance = new self();
|
return self::$instance ? self::$instance : self::$instance = new self();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get module by name from the current manifest.
|
||||||
|
* Alias for ::instance()->getManifest()->getModule()
|
||||||
|
*
|
||||||
|
* @param string $module
|
||||||
|
* @return Module
|
||||||
|
*/
|
||||||
|
public static function getModule($module)
|
||||||
|
{
|
||||||
|
return static::instance()->getManifest()->getModule($module);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the currently active class manifest instance that is used for
|
* Returns the currently active class manifest instance that is used for
|
||||||
* loading classes.
|
* loading classes.
|
||||||
|
@ -69,4 +69,19 @@ class ModuleManifestTest extends SapphireTest
|
|||||||
$this->assertEquals('moduleb', $module->getShortName());
|
$this->assertEquals('moduleb', $module->getShortName());
|
||||||
$this->assertEquals('moduleb', $module->getRelativePath());
|
$this->assertEquals('moduleb', $module->getRelativePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Note: Tests experimental API
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
public function testGetResource()
|
||||||
|
{
|
||||||
|
$module = $this->manifest->getModule('moduleb');
|
||||||
|
$this->assertTrue($module->hasResource('composer.json'));
|
||||||
|
$this->assertFalse($module->hasResource('package.json'));
|
||||||
|
$this->assertEquals(
|
||||||
|
'moduleb/composer.json',
|
||||||
|
$module->getResource('composer.json')
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user