2011-02-27 12:20:20 +01:00
|
|
|
<?php
|
2016-08-19 00:51:35 +02:00
|
|
|
|
|
|
|
namespace SilverStripe\Core\Manifest;
|
|
|
|
|
2016-09-09 08:43:05 +02:00
|
|
|
use SilverStripe\Assets\FileFinder;
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2011-02-27 12:20:20 +01:00
|
|
|
/**
|
|
|
|
* An extension to the default file finder with some extra filters to faciliate
|
|
|
|
* autoload and template manifest generation:
|
2011-12-22 03:17:41 +01:00
|
|
|
* - Only modules with _config.php files are scanned.
|
2011-02-27 12:20:20 +01:00
|
|
|
* - If a _manifest_exclude file is present inside a directory it is ignored.
|
|
|
|
* - Assets and module language directories are ignored.
|
|
|
|
* - Module tests directories are skipped if the ignore_tests option is not
|
|
|
|
* set to false.
|
|
|
|
*/
|
2016-09-09 08:43:05 +02:00
|
|
|
class ManifestFileFinder extends FileFinder {
|
2011-02-27 12:20:20 +01:00
|
|
|
|
|
|
|
const CONFIG_FILE = '_config.php';
|
2011-12-22 03:17:41 +01:00
|
|
|
const CONFIG_DIR = '_config';
|
2011-02-27 12:20:20 +01:00
|
|
|
const EXCLUDE_FILE = '_manifest_exclude';
|
|
|
|
const LANG_DIR = 'lang';
|
|
|
|
const TESTS_DIR = 'tests';
|
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
protected static $default_options = array(
|
2011-02-27 12:20:20 +01:00
|
|
|
'include_themes' => false,
|
|
|
|
'ignore_tests' => true,
|
2016-02-29 09:17:38 +01:00
|
|
|
'min_depth' => 1,
|
|
|
|
'ignore_dirs' => array('node_modules')
|
2011-02-27 12:20:20 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
public function acceptDir($basename, $pathname, $depth) {
|
|
|
|
// Skip over the assets directory in the site root.
|
|
|
|
if ($depth == 1 && $basename == ASSETS_DIR) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip over any lang directories in the top level of the module.
|
|
|
|
if ($depth == 2 && $basename == self::LANG_DIR) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-12 05:16:21 +02:00
|
|
|
// Skip over the vendor directories
|
|
|
|
if (($depth == 1 || $depth == 2) && $basename == 'vendor') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-31 04:58:23 +02:00
|
|
|
// If we're not in testing mode, then skip over any tests directories.
|
|
|
|
if ($this->getOption('ignore_tests') && $basename == self::TESTS_DIR) {
|
2011-02-27 12:20:20 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore any directories which contain a _manifest_exclude file.
|
|
|
|
if (file_exists($pathname . '/' . self::EXCLUDE_FILE)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only include top level module directories which have a configuration
|
|
|
|
// _config.php file. However, if we're in themes mode then include
|
|
|
|
// the themes dir without a config file.
|
|
|
|
$lackingConfig = (
|
|
|
|
$depth == 1
|
|
|
|
&& !($this->getOption('include_themes') && $basename == THEMES_DIR)
|
|
|
|
&& !file_exists($pathname . '/' . self::CONFIG_FILE)
|
2011-12-22 03:17:41 +01:00
|
|
|
&& !file_exists($pathname . '/' . self::CONFIG_DIR)
|
2016-09-12 05:16:21 +02:00
|
|
|
&& $basename !== self::CONFIG_DIR // include a root config dir
|
|
|
|
&& !file_exists("$pathname/../" . self::CONFIG_DIR) // include all paths if a root config dir exists
|
2011-02-27 12:20:20 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if ($lackingConfig) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::acceptDir($basename, $pathname, $depth);
|
|
|
|
}
|
|
|
|
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|