Adds support for using the newer ConfigStaticManifest from the 4.0/master branch. If the developer is doing something weird that involves accessing the 'getStatics()', they can simply delete the ConfigStaticManifest40.php file to bring back full compatibility. My reasoning for this addition is that it reduces the /dev/build process greatly and increases the programmers productivity and improves their quality of life (in my opinion anyway, less waiting for 7-12s for private static changes).

I'm thinking this should go into 3.3.
This commit is contained in:
Silbinary Wolf 2015-12-26 20:06:52 +11:00 committed by Sam Minnée
parent f16d7e1838
commit 65ac23098e
2 changed files with 75 additions and 1 deletions

View File

@ -78,6 +78,9 @@ require_once 'core/manifest/ManifestCache.php';
require_once 'core/manifest/ClassLoader.php';
require_once 'core/manifest/ConfigManifest.php';
require_once 'core/manifest/ConfigStaticManifest.php';
if (file_exists('core/manifest/ConfigStaticManifest40.php')) {
require_once 'core/manifest/ConfigStaticManifest40.php';
}
require_once 'core/manifest/ClassManifest.php';
require_once 'core/manifest/ManifestFileFinder.php';
require_once 'core/manifest/TemplateLoader.php';
@ -116,7 +119,11 @@ if(file_exists(BASE_PATH . '/vendor/autoload.php')) {
require_once(BASE_PATH . '/framework/model/fieldtypes/compat/autoload.php');
// Now that the class manifest is up, load the static configuration
if (class_exists('SS_ConfigStaticManifest_40')) {
$configManifest = new SS_ConfigStaticManifest_40(BASE_PATH, false, $flush);
} else {
$configManifest = new SS_ConfigStaticManifest(BASE_PATH, false, $flush);
}
Config::inst()->pushConfigStaticManifest($configManifest);
// And then the yaml configuration

View File

@ -0,0 +1,67 @@
<?php
/**
* Allows access to config values set on classes using private statics.
*
* @package framework
* @subpackage manifest
*/
class SS_ConfigStaticManifest_40 extends SS_ConfigStaticManifest {
/**
* Constructs and initialises a new config static manifest, either loading the data
* from the cache or re-scanning for classes.
*
* @param string $base The manifest base path.
* @param bool $includeTests Include the contents of "tests" directories.
* @param bool $forceRegen Force the manifest to be regenerated.
* @param bool $cache If the manifest is regenerated, cache it.
*/
public function __construct($base, $includeTests = false, $forceRegen = false, $cache = true) {
// Stubbed as these parameters are not needed for the newer SS_ConficStaticManifest version.
}
/**
* Completely regenerates the manifest file.
*/
public function regenerate($cache = true) {
Deprecation::notice('3.3', 'This is no longer available as SS_ConfigStaticManifest now uses Reflection.');
}
/**
* @param string $class
* @param string $name
* @param null $default
*
* @return mixed|null
*/
public function get($class, $name, $default = null) {
if(class_exists($class)) {
// The config system is case-sensitive so we need to check the exact value
$reflection = new ReflectionClass($class);
if(strcmp($reflection->name, $class) === 0) {
if($reflection->hasProperty($name)) {
$property = $reflection->getProperty($name);
if($property->isStatic()) {
if(!$property->isPrivate()) {
Deprecation::notice('3.3', "Config static $class::\$$name must be marked as private",
Deprecation::SCOPE_GLOBAL);
return null;
}
$property->setAccessible(true);
return $property->getValue();
}
}
}
}
return null;
}
public function getStatics() {
Deprecation::notice('3.3', 'This is no longer available as SS_ConfigStaticManifest now uses Reflection.');
return array();
}
}