64 lines
1.7 KiB
PHP
64 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* Copyright 2018 Kacper Donat
|
|
*
|
|
* @author Kacper "Kadet" Donat <kacper@kadet.net>
|
|
*
|
|
* Full license available in separate LICENSE file
|
|
*/
|
|
|
|
namespace Kadet\Functional\Reflection;
|
|
|
|
|
|
use Kadet\Functional\Utils\CurriedFunction;
|
|
use Kadet\Functional\Utils\PartiallyAppliedFunction;
|
|
|
|
class ReflectionPartiallyAppliedFunction extends \ReflectionFunction
|
|
{
|
|
public $applied;
|
|
|
|
public function __construct(PartiallyAppliedFunction $applied)
|
|
{
|
|
parent::__construct($applied->getDecorated());
|
|
$this->applied = $applied;
|
|
}
|
|
|
|
public function getNumberOfParameters()
|
|
{
|
|
return max(parent::getNumberOfParameters() - count($this->applied->getArguments()), 0);
|
|
}
|
|
|
|
public function getNumberOfRequiredParameters()
|
|
{
|
|
return max(parent::getNumberOfRequiredParameters() - count($this->applied->getArguments()), 0);
|
|
}
|
|
|
|
public function getNumberOfAppliedParameters()
|
|
{
|
|
return count($this->applied->getArguments());
|
|
}
|
|
|
|
public function getAppliedParameters()
|
|
{
|
|
$applied = $this->applied->getArguments();
|
|
$parameters = array_intersect_key(parent::getParameters(), $applied);
|
|
|
|
return array_map(function (\ReflectionParameter $parameter) use ($applied) {
|
|
return new ReflectionAppliedParameter(
|
|
$this->applied->getDecorated(),
|
|
$parameter->name,
|
|
$applied[$parameter->getPosition()]
|
|
);
|
|
}, $parameters);
|
|
}
|
|
|
|
public function getParameters()
|
|
{
|
|
return array_diff_key(parent::getParameters(), $this->applied->getArguments());
|
|
}
|
|
|
|
public function isCurried()
|
|
{
|
|
return $this->applied instanceof CurriedFunction;
|
|
}
|
|
} |