Merge pull request #6938 from robbieaverill/pulls/4.0/remove-create-function

Remove createMethod and create_function implementations, replace with closures
This commit is contained in:
Damian Mooyman 2017-05-19 21:30:53 +12:00 committed by GitHub
commit 2284121a91
5 changed files with 7 additions and 20 deletions

View File

@ -1295,6 +1295,7 @@ After (`mysite/_config/config.yml`):
* `Injector` now complies with [PSR-11](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md).
Accordingly, `hasService()` has been renamed to `has()`, and `get()` will throw
`SilverStripe\Core\Injector\InjectorNotFoundException` when the service can't be found.
* Removed `CustomMethods::createMethod()`. Use closures instead.
#### <a name="overview-general-deprecated"></a>General and Core Deprecated API

View File

@ -292,20 +292,4 @@ trait CustomMethods
'method' => $method
);
}
/**
* Add an extra method using raw PHP code passed as a string
*
* @param string $method the method name
* @param string $code the PHP code - arguments will be in an array called $args, while you can access this object
* by using $obj. Note that you cannot call protected methods, as the method is actually an external
* function
*/
protected function createMethod($method, $code)
{
$class = get_class($this);
self::$extra_methods[$class][strtolower($method)] = array (
'function' => create_function('$obj, $args', $code)
);
}
}

View File

@ -1389,7 +1389,9 @@ class Installer extends InstallRequirements {
$locale = isset($_POST['locale']) ? addcslashes($_POST['locale'], "\'") : 'en_US';
$type = addcslashes($config['db']['type'], "\'");
$dbConfig = $config['db'][$type];
$dbConfig = array_map(create_function('$v', 'return addcslashes($v, "\\\'");'), $dbConfig);
foreach ($dbConfig as &$configValue) {
$configValue = addcslashes($configValue, "\\\'");
}
if(!isset($dbConfig['path'])) $dbConfig['path'] = '';
if(!$dbConfig) {
echo "<p style=\"color: red\">Bad config submitted</p><pre>";

View File

@ -826,7 +826,9 @@ class Form extends ViewableData implements HasRequestHandler
$attrs = $this->getAttributes();
// Remove empty
$attrs = array_filter((array)$attrs, create_function('$v', 'return ($v || $v === 0);'));
$attrs = array_filter((array)$attrs, function ($value) {
return ($value || $value === 0);
});
// Remove excluded
if ($exclude) {

View File

@ -25,8 +25,6 @@ class T2 extends Object
$this->addMethodsFrom('failover');
$this->addMethodsFrom('failoverArr', 0);
$this->addMethodsFrom('failoverArr', 1);
$this->createMethod('testCreateMethod', 'return "created";');
}
public function wrappedMethod($val)