add wp-rocket

This commit is contained in:
nguyen dung
2022-02-18 19:09:35 +07:00
parent 39b8cb3612
commit 3110d00ee7
927 changed files with 271703 additions and 2 deletions

View File

@@ -0,0 +1,26 @@
<?php
namespace WP_Rocket\Engine\Container\Argument;
use WP_Rocket\Engine\Container\ImmutableContainerAwareInterface;
use ReflectionFunctionAbstract;
interface ArgumentResolverInterface extends ImmutableContainerAwareInterface
{
/**
* Resolve an array of arguments to their concrete implementations.
*
* @param array $arguments
* @return array
*/
public function resolveArguments(array $arguments);
/**
* Resolves the correct arguments to be passed to a method.
*
* @param \ReflectionFunctionAbstract $method
* @param array $args
* @return array
*/
public function reflectArguments(ReflectionFunctionAbstract $method, array $args = []);
}

View File

@@ -0,0 +1,82 @@
<?php
namespace WP_Rocket\Engine\Container\Argument;
use WP_Rocket\Engine\Container\Exception\NotFoundException;
use WP_Rocket\Engine\Container\ReflectionContainer;
use ReflectionFunctionAbstract;
use ReflectionParameter;
trait ArgumentResolverTrait
{
/**
* {@inheritdoc}
*/
public function resolveArguments(array $arguments)
{
foreach ($arguments as &$arg) {
if ($arg instanceof RawArgumentInterface) {
$arg = $arg->getValue();
continue;
}
if (! is_string($arg)) {
continue;
}
$container = $this->getContainer();
if (is_null($container) && $this instanceof ReflectionContainer) {
$container = $this;
}
if (! is_null($container) && $container->has($arg)) {
$arg = $container->get($arg);
if ($arg instanceof RawArgumentInterface) {
$arg = $arg->getValue();
}
continue;
}
}
return $arguments;
}
/**
* {@inheritdoc}
*/
public function reflectArguments(ReflectionFunctionAbstract $method, array $args = [])
{
$arguments = array_map(function (ReflectionParameter $param) use ($method, $args) {
$name = $param->getName();
$class = $param->getClass();
if (array_key_exists($name, $args)) {
return $args[$name];
}
if (! is_null($class)) {
return $class->getName();
}
if ($param->isDefaultValueAvailable()) {
return $param->getDefaultValue();
}
throw new NotFoundException(sprintf(
'Unable to resolve a value for parameter (%s) in the function/method (%s)',
$name,
$method->getName()
));
}, $method->getParameters());
return $this->resolveArguments($arguments);
}
/**
* @return \WP_Rocket\Engine\Container\ContainerInterface
*/
abstract public function getContainer();
}

View File

@@ -0,0 +1,27 @@
<?php
namespace WP_Rocket\Engine\Container\Argument;
class RawArgument implements RawArgumentInterface
{
/**
* @var mixed
*/
protected $value;
/**
* {@inheritdoc}
*/
public function __construct($value)
{
$this->value = $value;
}
/**
* {@inheritdoc}
*/
public function getValue()
{
return $this->value;
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace WP_Rocket\Engine\Container\Argument;
interface RawArgumentInterface
{
/**
* Return the value of the raw argument.
*
* @return mixed
*/
public function getValue();
}