/**
  * @return ConcreteMethod
  */
 protected function generateStreamTypeMethod()
 {
     $this->typeCheck->generateStreamTypeMethod(func_get_args());
     $valueIdentifier = new Identifier('value');
     $valueVariable = new Variable($valueIdentifier);
     $metaDataVariable = new Variable(new Identifier('metaData'));
     $metaDataModeSubscript = new Subscript($metaDataVariable, new Literal('mode'));
     $readableVariable = new Variable(new Identifier('readable'));
     $writableVariable = new Variable(new Identifier('writable'));
     $method = new ConcreteMethod(new Identifier('streamType'), AccessModifier::PROTECTED_());
     $method->addParameter(new Parameter($valueIdentifier));
     $streamGetMetaDataCall = new Call(QualifiedIdentifier::fromString('\\stream_get_meta_data'));
     $streamGetMetaDataCall->add($valueVariable);
     $method->statementBlock()->add(new ExpressionStatement(new Assign($metaDataVariable, $streamGetMetaDataCall)));
     $readablePregMatchCall = new Call(QualifiedIdentifier::fromString('\\preg_match'));
     $readablePregMatchCall->add(new Literal('/[r+]/'));
     $readablePregMatchCall->add($metaDataModeSubscript);
     $readableIf = new IfStatement($readablePregMatchCall, new StatementBlock(), new StatementBlock());
     $readableIf->trueBranch()->add(new ExpressionStatement(new Assign($readableVariable, new Literal('true'))));
     $readableIf->falseBranch()->add(new ExpressionStatement(new Assign($readableVariable, new Literal('false'))));
     $method->statementBlock()->add($readableIf);
     $writablePregMatchCall = new Call(QualifiedIdentifier::fromString('\\preg_match'));
     $writablePregMatchCall->add(new Literal('/[waxc+]/'));
     $writablePregMatchCall->add($metaDataModeSubscript);
     $writableIf = new IfStatement($writablePregMatchCall, new StatementBlock(), new StatementBlock());
     $writableIf->trueBranch()->add(new ExpressionStatement(new Assign($writableVariable, new Literal('true'))));
     $writableIf->falseBranch()->add(new ExpressionStatement(new Assign($writableVariable, new Literal('false'))));
     $method->statementBlock()->add($writableIf);
     $sprintfCall = new Call(QualifiedIdentifier::fromString('\\sprintf'));
     $sprintfCall->add(new Literal('stream {readable: %s, writable: %s}'));
     $sprintfCall->add($readableVariable);
     $sprintfCall->add($writableVariable);
     $method->statementBlock()->add(new ReturnStatement($sprintfCall));
     return $method;
 }
Exemple #2
0
 /**
  * @param RuntimeConfiguration $configuration
  *
  * @return ConcreteMethod
  */
 protected function generateConfigurationMethod(RuntimeConfiguration $configuration)
 {
     $this->typeCheck->generateConfigurationMethod(func_get_args());
     $method = new ConcreteMethod(new Identifier('configuration'), AccessModifier::PROTECTED_(), true);
     $method->statementBlock()->add(new ReturnStatement($this->configurationGenerator()->generate($configuration)));
     return $method;
 }