Ejemplo n.º 1
0
 /**
  * @return ConcreteMethod
  */
 protected function generateCallMethod()
 {
     $this->typeCheck->generateCallMethod(func_get_args());
     $method = new ConcreteMethod(new Identifier('__call'), AccessModifier::PUBLIC_());
     $method->addParameter(new Parameter(new Identifier('name')));
     $method->addParameter(new Parameter(new Identifier('arguments'), new ArrayTypeHint()));
     return $method;
 }
 /**
  * @return ConcreteMethod
  */
 protected function generateExpectedTypeMethod()
 {
     $this->typeCheck->generateExpectedTypeMethod(func_get_args());
     $expectedTypeIdentifier = new Identifier('expectedType');
     $method = new ConcreteMethod($expectedTypeIdentifier, AccessModifier::PUBLIC_());
     $method->statementBlock()->add(new ReturnStatement(new Member(new Variable(new Identifier('this')), new Constant($expectedTypeIdentifier))));
     return $method;
 }
Ejemplo n.º 3
0
 /**
  * @return ConcreteMethod
  */
 protected function generateTypeMethod()
 {
     $this->typeCheck->generateTypeMethod(func_get_args());
     $valueIdentifier = new Identifier('value');
     $valueVariable = new Variable($valueIdentifier);
     $maxIterationsIdentifier = new Identifier('maxIterations');
     $maxIterationsVariable = new Variable($maxIterationsIdentifier);
     $nativeTypeVariable = new Variable(new Identifier('nativeType'));
     $thisVariable = new Variable(new Identifier('this'));
     $method = new ConcreteMethod(new Identifier('type'), AccessModifier::PUBLIC_());
     $method->addParameter(new Parameter($valueIdentifier));
     $maxIterationsParameter = new Parameter($maxIterationsIdentifier);
     $maxIterationsParameter->setDefaultValue(new Literal(10));
     $method->addParameter($maxIterationsParameter);
     $gettypeCall = new Call(QualifiedIdentifier::fromString('\\gettype'));
     $gettypeCall->add($valueVariable);
     $method->statementBlock()->add(new ExpressionStatement(new Assign($nativeTypeVariable, $gettypeCall)));
     $arrayTypeIf = new IfStatement(new StrictEquals(new Literal('array'), $nativeTypeVariable));
     $arrayTypeCall = new Call(new Member($thisVariable, new Constant(new Identifier('arrayType'))));
     $arrayTypeCall->add($valueVariable);
     $arrayTypeCall->add($maxIterationsVariable);
     $arrayTypeIf->trueBranch()->add(new ReturnStatement($arrayTypeCall));
     $method->statementBlock()->add($arrayTypeIf);
     $doubleTypeIf = new IfStatement(new StrictEquals(new Literal('double'), $nativeTypeVariable));
     $doubleTypeIf->trueBranch()->add(new ReturnStatement(new Literal('float')));
     $method->statementBlock()->add($doubleTypeIf);
     $nullTypeIf = new IfStatement(new StrictEquals(new Literal('NULL'), $nativeTypeVariable));
     $nullTypeIf->trueBranch()->add(new ReturnStatement(new Literal('null')));
     $method->statementBlock()->add($nullTypeIf);
     $objectTypeIf = new IfStatement(new StrictEquals(new Literal('object'), $nativeTypeVariable));
     $objectTypeCall = new Call(new Member($thisVariable, new Constant(new Identifier('objectType'))));
     $objectTypeCall->add($valueVariable);
     $objectTypeCall->add($maxIterationsVariable);
     $objectTypeIf->trueBranch()->add(new ReturnStatement($objectTypeCall));
     $method->statementBlock()->add($objectTypeIf);
     $resourceTypeIf = new IfStatement(new StrictEquals(new Literal('resource'), $nativeTypeVariable));
     $resourceTypeCall = new Call(new Member($thisVariable, new Constant(new Identifier('resourceType'))));
     $resourceTypeCall->add($valueVariable);
     $resourceTypeIf->trueBranch()->add(new ReturnStatement($resourceTypeCall));
     $method->statementBlock()->add($resourceTypeIf);
     $method->statementBlock()->add(new ReturnStatement($nativeTypeVariable));
     return $method;
 }
 /**
  * @return ConcreteMethod
  */
 protected function generateCallMethod()
 {
     $this->typeCheck->generateCallMethod(func_get_args());
     $nameIdentifier = new Identifier('name');
     $nameVariable = new Variable($nameIdentifier);
     $argumentsIdentifier = new Identifier('arguments');
     $validatorMethodNameVariable = new Variable(new Identifier('validatorMethodName'));
     $thisVariable = new Variable(new Identifier('this'));
     $reflectorMember = new Member($thisVariable, new Constant(new Identifier('reflector')));
     $method = new ConcreteMethod(new Identifier('__call'), AccessModifier::PUBLIC_());
     $method->addParameter(new Parameter($nameIdentifier));
     $method->addParameter(new Parameter($argumentsIdentifier, new ArrayTypeHint()));
     $ltrimCall = new Call(QualifiedIdentifier::fromString('\\ltrim'));
     $ltrimCall->add($nameVariable);
     $ltrimCall->add(new Literal('_'));
     $ucfirstCall = new Call(QualifiedIdentifier::fromString('\\ucfirst'));
     $ucfirstCall->add($ltrimCall);
     $validatorMethodNameSprintfCall = new Call(QualifiedIdentifier::fromString('\\sprintf'));
     $validatorMethodNameSprintfCall->add(new Literal('validate%s'));
     $validatorMethodNameSprintfCall->add($ucfirstCall);
     $method->statementBlock()->add(new ExpressionStatement(new Assign($validatorMethodNameVariable, $validatorMethodNameSprintfCall)));
     $reflectorHasMethodCall = new Call(new Member($reflectorMember, new Constant(new Identifier('hasMethod'))));
     $reflectorHasMethodCall->add($validatorMethodNameVariable);
     $undefinedMethodIf = new IfStatement(new LogicalNot($reflectorHasMethodCall));
     $exceptionMessageSprintfCall = new Call(QualifiedIdentifier::fromString('\\sprintf'));
     $exceptionMessageSprintfCall->add(new Literal('Call to undefined method %s::%s().'));
     $exceptionMessageSprintfCall->add(new Constant(new Identifier('__CLASS__')));
     $exceptionMessageSprintfCall->add($nameVariable);
     $newBadMethodCallExceptionCall = new Call(QualifiedIdentifier::fromString('\\BadMethodCallException'));
     $newBadMethodCallExceptionCall->add($exceptionMessageSprintfCall);
     $undefinedMethodIf->trueBranch()->add(new ThrowStatement(new NewOperator($newBadMethodCallExceptionCall)));
     $method->statementBlock()->add($undefinedMethodIf);
     $getMethodCall = new Call(new Member($reflectorMember, new Constant(new Identifier('getMethod'))));
     $getMethodCall->add($validatorMethodNameVariable);
     $invokeArgsCall = new Call(new Member($getMethodCall, new Constant(new Identifier('invokeArgs'))));
     $invokeArgsCall->add($thisVariable);
     $invokeArgsCall->add(new Variable($argumentsIdentifier));
     $method->statementBlock()->add(new ReturnStatement($invokeArgsCall));
     return $method;
 }
Ejemplo n.º 5
0
 /**
  * @return ConcreteMethod
  */
 protected function generateRuntimeGenerationMethod()
 {
     $this->typeCheck->generateRuntimeGenerationMethod(func_get_args());
     $method = new ConcreteMethod(new Identifier('runtimeGeneration'), AccessModifier::PUBLIC_(), true);
     $method->statementBlock()->add(new ReturnStatement(new StaticMember(new Constant(new Identifier('static')), new Variable(new Identifier('runtimeGeneration')))));
     return $method;
 }
 /**
  * @return ConcreteMethod
  */
 protected function generateConstructor()
 {
     $this->typeCheck->generateConstructor(func_get_args());
     $messageIdentifier = new Identifier('message');
     $previousIdentifier = new Identifier('previous');
     $method = new ConcreteMethod(new Identifier('__construct'), AccessModifier::PUBLIC_());
     $method->addParameter(new Parameter($messageIdentifier));
     $previousParameter = new Parameter($previousIdentifier, new ObjectTypeHint(QualifiedIdentifier::fromString('\\Exception')));
     $previousParameter->setDefaultValue(new Literal(null));
     $method->addParameter($previousParameter);
     $parentConstructCall = new Call(new StaticMember(new Constant(new Identifier('parent')), new Constant(new Identifier('__construct'))));
     $parentConstructCall->add(new Variable($messageIdentifier));
     $parentConstructCall->add(new Literal(0));
     $parentConstructCall->add(new Variable($previousIdentifier));
     $method->statementBlock()->add(new ExpressionStatement($parentConstructCall));
     return $method;
 }