parameter() final public static method

final public static parameter ( string $name, string | null $typeHint = null, Expression $defaultValue = null, boolean $isPassedByReference = false, boolean $isVariadic = false ) : ParameterExpression
$name string
$typeHint string | null
$defaultValue Expression
$isPassedByReference boolean
$isVariadic boolean
return ParameterExpression
コード例 #1
0
 /**
  * @dataProvider interpreters
  */
 public function testParameterExpressions()
 {
     $this->assertParametersAre(function ($i) {
     }, [O\Expression::parameter('i')]);
     $this->assertParametersAre(function ($i, $foo) {
     }, [O\Expression::parameter('i'), O\Expression::parameter('foo')]);
     $this->assertParametersAre(function ($i = null) {
     }, [O\Expression::parameter('i', null, O\Expression::value(null))]);
     $this->assertParametersAre(function ($i = 'bar') {
     }, [O\Expression::parameter('i', null, O\Expression::value('bar'))]);
     $this->assertParametersAre(function (\DateTime $i) {
     }, [O\Expression::parameter('i', '\\DateTime')]);
     $this->assertParametersAre(function (self $i) {
     }, [O\Expression::parameter('i', '\\' . __CLASS__)]);
     $this->assertParametersAre(function (parent $i) {
     }, [O\Expression::parameter('i', '\\' . get_parent_class())]);
     $this->assertParametersAre(function (MiscInterpreterTest $i) {
     }, [O\Expression::parameter('i', '\\' . __CLASS__)]);
     $this->assertParametersAre(function (ParameterClassTest $i) {
     }, [O\Expression::parameter('i', '\\' . __NAMESPACE__ . '\\ParameterClassTest')]);
     $this->assertParametersAre(function (namespace\ParameterClassTest $i) {
     }, [O\Expression::parameter('i', '\\' . __NAMESPACE__ . '\\ParameterClassTest')]);
     $this->assertParametersAre(function (&$i) {
     }, [O\Expression::parameter('i', null, null, true)]);
     $this->assertParametersAre(function (\stdClass &$i = null, array $array = ['foo']) {
     }, [O\Expression::parameter('i', '\\stdClass', O\Expression::value(null), true), O\Expression::parameter('array', 'array', O\Expression::value(['foo']))]);
     $this->assertParametersAre(function (callable &$v = null) {
     }, [O\Expression::parameter('v', 'callable', O\Expression::value(null), true)]);
     $this->assertParametersAre(function ($v = [1, 2, 3, 'test' => 'foo', [2 => 'boo', '']]) {
     }, [O\Expression::parameter('v', null, O\Expression::value([1, 2, 3, 'test' => 'foo', [2 => 'boo', '']]))]);
 }
コード例 #2
0
 public function testWalksBodyAndParameterExpressions()
 {
     $processor = $this->getMock('Pinq\\Providers\\DSL\\Compilation\\Processors\\Expression\\ExpressionProcessor', ['walkValue']);
     $processor->expects($this->exactly(2))->method('walkValue')->will($this->returnValue(O\Expression::value('updated')));
     /** @var ExpressionProcessor $processor */
     $function = new Functions\ElementProjection('', null, null, [], [O\Expression::parameter('param', 'abc', O\Expression::value('default'))], [O\Expression::value('body')]);
     $processedFunction = $processor->processFunction($function);
     $this->assertEquals([O\Expression::value('updated')], $processedFunction->getBodyExpressions());
     $this->assertEquals(O\Expression::parameter('param', 'abc', O\Expression::value('updated')), $processedFunction->getParameters()->getValue());
 }
コード例 #3
0
ファイル: AggregatorTest.php プロジェクト: timetoogo/pinq
 public function testFullParameters()
 {
     /** @var $function Functions\Aggregator */
     $function = $this->buildFunction('', null, null, [], [O\Expression::parameter('aggregate'), O\Expression::parameter('value')]);
     $this->assertSame(true, $function->getParameters()->hasAggregateValue());
     $this->assertSame('aggregate', $function->getParameters()->getAggregateValue()->getName());
     $this->assertSame(true, $function->getParameters()->hasValue());
     $this->assertSame('value', $function->getParameters()->getValue()->getName());
     $this->assertSame(false, $function->getParameters()->hasRequiredUnusedParameters());
     $this->assertSame([], $function->getParameters()->getRequiredUnusedParameters());
     $this->assertSame([], $function->getParameters()->getUnused());
     $this->assertSame([], $function->getParameters()->getUnusedParameterDefaultMap());
 }
コード例 #4
0
 public function testFullParameters()
 {
     /** @var $function Functions\ConnectorProjection */
     $function = $this->buildFunction('', null, null, [], [O\Expression::parameter('outer-value'), O\Expression::parameter('inner-value'), O\Expression::parameter('outer-key'), O\Expression::parameter('inner-key')]);
     $this->assertSame(true, $function->getParameters()->hasOuterKey());
     $this->assertSame('outer-value', $function->getParameters()->getOuterValue()->getName());
     $this->assertSame(true, $function->getParameters()->hasInnerValue());
     $this->assertSame('inner-value', $function->getParameters()->getInnerValue()->getName());
     $this->assertSame(true, $function->getParameters()->hasOuterKey());
     $this->assertSame('outer-key', $function->getParameters()->getOuterKey()->getName());
     $this->assertSame(true, $function->getParameters()->hasInnerKey());
     $this->assertSame('inner-key', $function->getParameters()->getInnerKey()->getName());
     $this->assertSame(false, $function->getParameters()->hasRequiredUnusedParameters());
     $this->assertSame([], $function->getParameters()->getRequiredUnusedParameters());
     $this->assertSame([], $function->getParameters()->getUnused());
     $this->assertSame([], $function->getParameters()->getUnusedParameterDefaultMap());
 }
コード例 #5
0
 public function testFunctionWithDefaultRelativeConstant()
 {
     /** @var $function Functions\ElementProjection */
     $function = $this->buildFunction('', null, __NAMESPACE__, [], [O\Expression::parameter('value'), O\Expression::parameter('key'), O\Expression::parameter('excessive1', null, O\Expression::constant('__RELATIVE_CONSTANT')), O\Expression::parameter('excessive2', null, O\Expression::value([false]))]);
     $this->assertSame(false, $function->getParameters()->hasRequiredUnusedParameters());
     $this->assertEquals([], $function->getParameters()->getRequiredUnusedParameters());
     $this->assertEquals([O\Expression::parameter('excessive1', null, O\Expression::constant('__RELATIVE_CONSTANT')), O\Expression::parameter('excessive2', null, O\Expression::value([false]))], $function->getParameters()->getUnused());
     $this->assertEquals(['excessive1' => O\Expression::constant('__RELATIVE_CONSTANT'), 'excessive2' => O\Expression::value([false])], $function->getParameters()->getUnusedParameterDefaultMap());
     //This fails in PHP due to strange behaviour with closures and relative constants.
     //Bug reported: https://bugs.php.net/bug.php?id=67897
     if (defined('HHVM_VERSION')) {
         define('__RELATIVE_CONSTANT', 'in global namespace');
         $this->assertEquals(['excessive1' => 'in global namespace', 'excessive2' => [false]], $function->getEvaluationContextFactory()->getEvaluationContext()->getVariableTable());
         //Should take precedence
         define(__NAMESPACE__ . '\\__RELATIVE_CONSTANT', 'in relative namespace');
         $this->assertEquals(['excessive1' => 'in relative namespace', 'excessive2' => [false]], $function->getEvaluationContextFactory()->getEvaluationContext()->getVariableTable());
     }
 }
コード例 #6
0
ファイル: FunctionTest.php プロジェクト: timetoogo/pinq
 public function testFunctionWithReturnStatement()
 {
     $function = $this->functionWithReturnStatement();
     $this->assertSame('', $function->getCallableId());
     $this->assertSame(1, $function->getParameters()->count());
     $this->assertEquals([O\Expression::parameter('foo')], $function->getParameters()->getAll());
     $this->assertEquals(['param' => 'scope'], $function->getParameterScopedVariableMap());
     $this->assertEquals(['', 'param'], $function->getParameterIds());
     $this->assertSame(true, $function->hasScopeType());
     $this->assertSame(__CLASS__, $function->getScopeType());
     $this->assertSame(true, $function->hasNamespace());
     $this->assertSame(__NAMESPACE__, $function->getNamespace());
     $this->assertSame(4, $function->countBodyExpressions());
     $this->assertSame(2, $function->countBodyExpressionsUntilReturn());
     $this->assertEquals([O\Expression::value('before'), O\Expression::returnExpression(O\Expression::value('return')), O\Expression::value('after'), O\Expression::functionCall(O\Expression::value('boom'))], $function->getBodyExpressions());
     $this->assertEquals([O\Expression::value('before'), O\Expression::returnExpression(O\Expression::value('return'))], $function->getBodyExpressionsUntilReturn());
     $this->assertEquals(new O\EvaluationContext(__NAMESPACE__, __CLASS__, null, ['scope' => 'value']), $function->getEvaluationContextFactory()->getEvaluationContext(new ResolvedParameterRegistry(['param' => 'value'])));
 }
コード例 #7
0
 /**
  * @dataProvider parsers
  */
 public function testOnlyArraysByRef()
 {
     $this->assertParsedAs([$this->parameters, 'onlyArraysByRef'], [O\Expression::closure(false, false, [O\Expression::parameter('arguments', 'array', null, true, true)], [], [])]);
 }
コード例 #8
0
ファイル: AST.php プロジェクト: timetoogo/pinq
 private function parseParameterNode(Node\Param $node)
 {
     $type = $node->type;
     if ($type !== null) {
         $type = (string) $type;
         $lowerType = strtolower($type);
         if ($type[0] !== '\\' && $lowerType !== 'array' && $lowerType !== 'callable') {
             $type = '\\' . $type;
         }
     }
     return Expression::parameter($node->name, $type, $node->default === null ? null : $this->parseNode($node->default), $node->byRef, $node->variadic);
 }
コード例 #9
0
ファイル: MiscExpressionTest.php プロジェクト: timetoogo/pinq
 public function testNamedParameterExpressionAsVariableMethod()
 {
     $this->assertEquals(O\Expression::variable(O\Expression::value('foo')), O\Expression::parameter('foo')->asVariable());
     $this->assertEquals(O\Expression::variable(O\Expression::value('foobar')), O\Expression::closureUsedVariable('foobar')->asVariable());
 }
コード例 #10
0
ファイル: FunctionSignature.php プロジェクト: timetoogo/pinq
 private static function getParameterExpression(\ReflectionParameter $parameter)
 {
     $typeHint = null;
     if ($parameter->isArray()) {
         $typeHint = 'array';
     } elseif ($parameter->isCallable()) {
         $typeHint = 'callable';
     } elseif ($parameter->getClass() !== null) {
         $typeHint = $parameter->getClass()->getName();
         $typeHint = $typeHint[0] === '\\' ? $typeHint : '\\' . $typeHint;
     }
     return O\Expression::parameter($parameter->getName(), $typeHint, $parameter->isDefaultValueAvailable() ? O\Expression::value($parameter->getDefaultValue()) : null, $parameter->isPassedByReference(), method_exists($parameter, 'isVariadic') && $parameter->isVariadic());
 }
コード例 #11
0
ファイル: ProjectionBaseTest.php プロジェクト: timetoogo/pinq
 protected function functionWithEmptyReturnStatement()
 {
     return $this->buildFunction('', __CLASS__, __NAMESPACE__, ['param' => 'scope'], [O\Expression::parameter('foo')], [O\Expression::value('before'), O\Expression::returnExpression(), O\Expression::value('after'), O\Expression::functionCall(O\Expression::value('boom'))]);
 }
コード例 #12
0
ファイル: ExpressionTest.php プロジェクト: timetoogo/pinq
 public function expressions()
 {
     return [[O\Expression::arrayExpression([])], [O\Expression::arrayItem(null, O\Expression::value(0), false)], [O\Expression::assign(O\Expression::value(0), O\Operators\Assignment::EQUAL, O\Expression::value(0))], [O\Expression::binaryOperation(O\Expression::value(0), O\Operators\Binary::ADDITION, O\Expression::value(0))], [O\Expression::unaryOperation(O\Operators\Unary::PLUS, O\Expression::value(0))], [O\Expression::cast(O\Operators\Cast::STRING, O\Expression::value(0))], [O\Expression::closure(false, false, [], [], [])], [O\Expression::closureUsedVariable('var')], [O\Expression::emptyExpression(O\Expression::value(0))], [O\Expression::field(O\Expression::value(0), O\Expression::value(0))], [O\Expression::functionCall(O\Expression::value(0))], [O\Expression::index(O\Expression::value(0), O\Expression::value(0))], [O\Expression::invocation(O\Expression::value(0))], [O\Expression::issetExpression([O\Expression::value(0)])], [O\Expression::unsetExpression([O\Expression::value(0)])], [O\Expression::methodCall(O\Expression::value(0), O\Expression::value(0))], [O\Expression::newExpression(O\Expression::value(0))], [O\Expression::parameter('')], [O\Expression::argument(O\Expression::value(0))], [O\Expression::returnExpression()], [O\Expression::staticMethodCall(O\Expression::value(0), O\Expression::value(0))], [O\Expression::staticField(O\Expression::value(0), O\Expression::value(0))], [O\Expression::ternary(O\Expression::value(0), null, O\Expression::value(0))], [O\Expression::throwExpression(O\Expression::value(0))], [O\Expression::value(0)], [O\Expression::variable(O\Expression::value(0))], [O\Expression::constant('foo')], [O\Expression::classConstant(O\Expression::value(0), 'foo')]];
 }
コード例 #13
0
ファイル: MutatorBaseTest.php プロジェクト: timetoogo/pinq
 protected function functionWithFirstParameterReference()
 {
     return $this->buildFunction('', __CLASS__, __NAMESPACE__, [], [O\Expression::parameter('true', null, null, true)], []);
 }
コード例 #14
0
ファイル: ComplexParserTest.php プロジェクト: timetoogo/pinq
 /**
  * @dataProvider parsers
  */
 public function testThatChainedMethodCalls()
 {
     $this->assertReturn(function (\Pinq\ITraversable $traversable) {
         return $traversable->asArray();
     }, O\Expression::methodCall(O\Expression::variable(O\Expression::value('traversable')), O\Expression::value('asArray')));
     $this->assertReturn(function (\Pinq\ITraversable $traversable) {
         return $traversable->where(function ($i) {
             return $i > 0;
         })->all(function ($i) {
             return $i % 2 === 0;
         });
     }, O\Expression::methodCall(O\Expression::methodCall(O\Expression::variable(O\Expression::value('traversable')), O\Expression::value('where'), [O\Expression::argument(O\Expression::closure(false, false, [O\Expression::parameter('i')], [], [O\Expression::returnExpression(O\Expression::binaryOperation(O\Expression::variable(O\Expression::value('i')), O\Operators\Binary::GREATER_THAN, O\Expression::value(0)))]))]), O\Expression::value('all'), [O\Expression::argument(O\Expression::closure(false, false, [O\Expression::parameter('i')], [], [O\Expression::returnExpression(O\Expression::binaryOperation(O\Expression::binaryOperation(O\Expression::variable(O\Expression::value('i')), O\Operators\Binary::MODULUS, O\Expression::value(2)), O\Operators\Binary::IDENTITY, O\Expression::value(0)))]))]));
 }
コード例 #15
0
ファイル: ReflectionTest.php プロジェクト: timetoogo/pinq
 public function testFunction()
 {
     $reflection = $this->interpreter->getReflection(__NAMESPACE__ . '\\func');
     $location = $reflection->getLocation();
     $scope = $reflection->getScope();
     $signature = $reflection->getSignature();
     $this->assertSame(__FILE__, $location->getFilePath());
     $this->assertSame(true, $location->inNamespace());
     $this->assertSame(__NAMESPACE__, $location->getNamespace());
     $this->assertSame(func()['start'], $location->getStartLine());
     $this->assertSame(func()['end'], $location->getEndLine());
     $this->assertSame(null, $scope->getThis());
     $this->assertEquals([], $scope->getVariableTable());
     $this->assertSame(null, $scope->getScopeType());
     $this->assertSame(null, $scope->getThisType());
     $this->assertSame(IFunctionSignature::TYPE_FUNCTION, $signature->getType());
     $this->assertSame(null, $signature->getAccessModifier());
     $this->assertSame(null, $signature->isStatic());
     $this->assertSame(false, $signature->returnsReference());
     $this->assertSame(null, $signature->getPolymorphModifier());
     $this->assertSame('func', $signature->getName());
     $this->assertEquals([O\Expression::parameter('foo', null, O\Expression::value(func()['start']))], $signature->getParameterExpressions());
     $this->assertEquals(null, $signature->getScopedVariableNames());
 }
コード例 #16
0
ファイル: QueryParsingTest.php プロジェクト: timetoogo/pinq
 protected function exampleFromDocsQuery()
 {
     $rowExpression = O\Expression::variable(O\Expression::value('row'));
     return $this->scopeRequest([new Q\Segments\Filter(new Q\Functions\ElementProjection($this->parameter(), self::SCOPE_TYPE, self::SCOPE_NAMESPACE, [$this->parameter() => 'this'], [O\Expression::parameter('row')], [O\Expression::returnExpression(O\Expression::binaryOperation(O\Expression::index($rowExpression, O\Expression::value('age')), O\Operators\Binary::LESS_THAN_OR_EQUAL_TO, O\Expression::value(50)))])), new Q\Segments\OrderBy([new Q\Segments\Ordering($this->indexProjection('firstName'), $this->parameter()), new Q\Segments\Ordering($this->indexProjection('lastName'), $this->parameter())]), new Q\Segments\Range($this->parameter(), $this->parameter()), new Q\Segments\IndexBy($this->indexProjection('phoneNumber')), new Q\Segments\Select(new Q\Functions\ElementProjection($this->parameter(), self::SCOPE_TYPE, self::SCOPE_NAMESPACE, [$this->parameter() => 'this'], [O\Expression::parameter('row')], [O\Expression::returnExpression(O\Expression::arrayExpression([O\Expression::arrayItem(O\Expression::value('fullName'), O\Expression::binaryOperation(O\Expression::binaryOperation(O\Expression::index($rowExpression, O\Expression::value('firstName')), O\Operators\Binary::CONCATENATION, O\Expression::value(' ')), O\Operators\Binary::CONCATENATION, O\Expression::index($rowExpression, O\Expression::value('lastName')))), O\Expression::arrayItem(O\Expression::value('address'), O\Expression::index($rowExpression, O\Expression::value('address'))), O\Expression::arrayItem(O\Expression::value('dateOfBirth'), O\Expression::index($rowExpression, O\Expression::value('dateOfBirth')))]))]))]);
 }