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


PHP FileGenerator::setRequiredFiles方法代碼示例

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


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

示例1: getContents

 /**
  * getContents()
  *
  * @return string
  */
 public function getContents()
 {
     $filter = new \Zend\Filter\Word\DashToCamelCase();
     $className = $filter->filter($this->_forClassName) . 'Test';
     $codeGenFile = new FileGenerator();
     $codeGenFile->setRequiredFiles(array('PHPUnit/Framework/TestCase.php'));
     $codeGenFile->setClasses(array(new ClassGenerator($className, null, null, 'PHPUnit_Framework_TestCase', array(), array(), array(new MethodGenerator('setUp', array(), MethodGenerator::FLAG_PUBLIC, '        /* Setup Routine */'), new MethodGenerator('tearDown', array(), MethodGenerator::FLAG_PUBLIC, '        /* Tear Down Routine */')))));
     return $codeGenFile->generate();
 }
開發者ID:nevvermind,項目名稱:zf2,代碼行數:14,代碼來源:TestLibraryFile.php

示例2: getGeneratedFile


//.........這裏部分代碼省略.........
                     if ($injectionParameter->getClassName()) {
                         $this->factoryGenerator->processFileForClass($injectionParameter->getClassName());
                     }
                     if ($injectionParameter->getFactoryName()) {
                         $this->usedFactories[] = $injectionParameter->getFactoryName();
                     }
                     $body .= '    ' . $injectionParameter->getProcessingBody();
                 } catch (\Exception $e) {
                     $body .= '    ' . $injectionParameter->getDefaultProcessingBody();
                 }
             }
             $body .= '}' . PHP_EOL;
             $body .= 'else if (array_key_exists(0, $parameters)) {' . PHP_EOL;
             foreach ($arguments as $argument) {
                 /** @var \ReflectionParameter $argument */
                 $injectionParameter = new \rg\injektor\generators\InjectionParameter($argument, $classConfig, $this->config, $this->dic, InjectionParameter::MODE_NUMERIC);
                 try {
                     if ($injectionParameter->getClassName()) {
                         $this->factoryGenerator->processFileForClass($injectionParameter->getClassName());
                     }
                     if ($injectionParameter->getFactoryName()) {
                         $this->usedFactories[] = $injectionParameter->getFactoryName();
                     }
                     $body .= '    ' . $injectionParameter->getProcessingBody();
                 } catch (\Exception $e) {
                     $body .= '    ' . $injectionParameter->getDefaultProcessingBody();
                 }
             }
             $body .= '}' . PHP_EOL;
             $body .= 'else {' . PHP_EOL;
             foreach ($arguments as $argument) {
                 /** @var \ReflectionParameter $argument */
                 $injectionParameter = new \rg\injektor\generators\InjectionParameter($argument, $classConfig, $this->config, $this->dic, InjectionParameter::MODE_STRING);
                 try {
                     if ($injectionParameter->getClassName()) {
                         $this->factoryGenerator->processFileForClass($injectionParameter->getClassName());
                     }
                     if ($injectionParameter->getFactoryName()) {
                         $this->usedFactories[] = $injectionParameter->getFactoryName();
                     }
                     $body .= '    ' . $injectionParameter->getProcessingBody();
                 } catch (\Exception $e) {
                     $body .= '    ' . $injectionParameter->getDefaultProcessingBody();
                 }
             }
             $body .= '}' . PHP_EOL;
         }
         // Property injection
         $this->injectProperties($classConfig, $classReflection);
         if (count($this->injectableProperties) > 0) {
             $proxyName = $this->dic->getProxyClassName($this->fullClassName);
             if ($this->dic->isSingleton($classReflection)) {
                 $file->setClass($this->createProxyClass($proxyName));
                 $body .= PHP_EOL . '$instance = ' . $proxyName . '::getInstance(' . implode(', ', $this->constructorArgumentStringParts) . ');' . PHP_EOL;
             } else {
                 $file->setClass($this->createProxyClass($proxyName));
                 $body .= PHP_EOL . '$instance = new ' . $proxyName . '(' . implode(', ', $this->constructorArgumentStringParts) . ');' . PHP_EOL;
             }
         } else {
             if ($this->dic->isSingleton($classReflection)) {
                 $body .= PHP_EOL . '$instance = \\' . $this->fullClassName . '::getInstance(' . implode(', ', $this->constructorArgumentStringParts) . ');' . PHP_EOL;
             } else {
                 $body .= PHP_EOL . '$instance = new \\' . $this->fullClassName . '(' . implode(', ', $this->constructorArgumentStringParts) . ');' . PHP_EOL;
             }
         }
     }
     if ($isSingleton) {
         $body .= 'self::$instance[$singletonKey] = $instance;' . PHP_EOL;
     }
     if ($isService) {
         $body .= 'self::$instance = $instance;' . PHP_EOL;
     }
     foreach ($this->injectableArguments as $injectableArgument) {
         $body .= '$instance->propertyInjection' . $injectableArgument->getName() . '();' . PHP_EOL;
     }
     $body .= 'return $instance;' . PHP_EOL;
     $instanceMethod->setBody($body);
     $instanceMethod->setStatic(true);
     $factoryClass->addMethodFromGenerator($instanceMethod);
     // Add Factory Method
     $methods = $classReflection->getMethods();
     foreach ($methods as $method) {
         /** @var \ReflectionMethod $method */
         if ($method->isPublic() && substr($method->name, 0, 2) !== '__') {
             $factoryMethod = $this->getFactoryMethod($method, $classConfig);
             $factoryClass->addMethodFromGenerator($factoryMethod);
         }
     }
     // Generate File
     $file->setNamespace('rg\\injektor\\generated');
     $this->usedFactories = array_unique($this->usedFactories);
     foreach ($this->usedFactories as &$usedFactory) {
         $usedFactory = str_replace('rg\\injektor\\generated\\', '', $usedFactory);
         $usedFactory = $usedFactory . '.php';
     }
     $file->setRequiredFiles($this->usedFactories);
     $file->setClass($factoryClass);
     $file->setFilename($this->factoryPath . DIRECTORY_SEPARATOR . $factoryName . '.php');
     return $file;
 }
開發者ID:researchgate,項目名稱:injektor,代碼行數:101,代碼來源:FileGenerator.php


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