當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ParameterGenerator::generate方法代碼示例

本文整理匯總了PHP中Zend\Code\Generator\ParameterGenerator::generate方法的典型用法代碼示例。如果您正苦於以下問題:PHP ParameterGenerator::generate方法的具體用法?PHP ParameterGenerator::generate怎麽用?PHP ParameterGenerator::generate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend\Code\Generator\ParameterGenerator的用法示例。


在下文中一共展示了ParameterGenerator::generate方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testGenerateIsCorrect

 public function testGenerateIsCorrect()
 {
     $parameterGenerator = new ParameterGenerator();
     $parameterGenerator->setType('Foo');
     $parameterGenerator->setName('bar');
     $parameterGenerator->setDefaultValue(15);
     $this->assertEquals('Foo $bar = 15', $parameterGenerator->generate());
     $parameterGenerator->setDefaultValue('foo');
     $this->assertEquals('Foo $bar = \'foo\'', $parameterGenerator->generate());
 }
開發者ID:rikaix,項目名稱:zf2,代碼行數:10,代碼來源:ParameterGeneratorTest.php

示例2: getMethods

 protected function getMethods()
 {
     $methods = [$this->getConstructor()];
     foreach ($this->properties as $propertyName) {
         $setterParam = new ParameterGenerator($propertyName);
         $methodGenerator = new MethodGenerator('set' . ucfirst($propertyName), [$setterParam]);
         $methodGenerator->setBody('$this->' . $propertyName . ' = ' . $setterParam->generate() . ';' . PHP_EOL . PHP_EOL . 'return $this;');
         $methods[] = $methodGenerator;
         $methodGenerator = new MethodGenerator('get' . ucfirst($propertyName));
         $methodGenerator->setBody('return $this->' . $propertyName . ';');
         $methods[] = $methodGenerator;
     }
     foreach ($this->edgeProperties as $edgeCollection => $targetCollection) {
         $setterParam = new ParameterGenerator(lcfirst($edgeCollection));
         $methodGenerator = new MethodGenerator('add' . $edgeCollection, [$setterParam]);
         $methodGenerator->setBody('$this->lazyAddNeighbor($this, \'' . $edgeCollection . '\', ' . $setterParam->generate() . ');');
         $methods[] = $methodGenerator;
         $setterParam = new ParameterGenerator(lcfirst($edgeCollection));
         $methodGenerator = new MethodGenerator('remove' . $edgeCollection, [$setterParam]);
         $methodGenerator->setBody('$this->lazyRemoveNeighbor($this, \'' . $edgeCollection . '\', ' . $setterParam->generate() . ');');
         $methods[] = $methodGenerator;
         $setterParam = new ParameterGenerator(lcfirst($edgeCollection));
         $methodGenerator = new MethodGenerator('set' . $edgeCollection, [$setterParam]);
         $methodGenerator->setBody('$this->lazySetNeighbor($this, \'' . $edgeCollection . '\', ' . $setterParam->generate() . ');');
         $methods[] = $methodGenerator;
         $defaultValue = new ValueGenerator([], ValueGenerator::TYPE_ARRAY);
         $setterParam = new ParameterGenerator('filter', null, $defaultValue);
         $methodGenerator = new MethodGenerator('get' . $edgeCollection, [$setterParam]);
         $methodGenerator->setBody('return $this->lazyGetNeighbor(\'' . $edgeCollection . '\', \'' . $targetCollection . '\', $filter);');
         $methods[] = $methodGenerator;
     }
     return $methods;
 }
開發者ID:cyberrebell,項目名稱:arango-odm,代碼行數:33,代碼來源:DocumentGenerator.php

示例3: testGeneratedParametersHaveEscapedDefaultValues

 /**
  * @group 6023
  *
  * @coversNothing
  */
 public function testGeneratedParametersHaveEscapedDefaultValues()
 {
     $parameter = new ParameterGenerator();
     $parameter->setName('foo');
     $parameter->setDefaultValue("\\'");
     $parameter->setType('stdClass');
     $this->assertSame("stdClass \$foo = '\\\\\\''", $parameter->generate());
 }
開發者ID:pnaq57,項目名稱:zf2demo,代碼行數:13,代碼來源:ParameterGeneratorTest.php


注:本文中的Zend\Code\Generator\ParameterGenerator::generate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。