php Zend-Code-Generator-FileGenerator类(方法)实例源码

下面列出了php Zend-Code-Generator-FileGenerator 类(方法)源码代码实例,从而了解它的用法。

作者:rafalwrzeszc    项目:zf   
public function getContents()
 {
     $className = $this->getFullClassName($this->_dbTableName, 'Model\\DbTable');
     $codeGenFile = new FileGenerator($this->getPath());
     $codeGenFile->setClass(new ClassGenerator($className, null, null, '\\Zend\\Db\\Table\\AbstractTable', null, array(new PropertyGenerator('_name', $this->_actualTableName, PropertyGenerator::FLAG_PROTECTED))));
     return $codeGenFile->generate();
 }

作者:slavomirkuzm    项目:itc-bundl   
/**
  * (non-PHPdoc)
  *
  * @see \Symfony\Component\Console\Command\Command::execute()
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $document = $this->getDocument($input->getArgument('document'));
     $items = $document->getElement();
     $directory = sprintf($input->getArgument('elementOutput'), $document->getFileInfo()->getBasename('.dtd'));
     $namespace = sprintf($input->getArgument('elementNamespace'), $document->getFileInfo()->getBasename('.dtd'));
     $parentClass = $input->getArgument('elementParentClass');
     $description = str_replace("\\", " ", $namespace);
     if (!file_exists($directory)) {
         mkdir($directory, 0777, true);
     }
     $progressBar = new ProgressBar($output, $items->count());
     $progressBar->setFormat('verbose');
     foreach ($items as $item) {
         $name = sprintf("%sElement", Source::camelCase($item->getName()));
         $filename = sprintf("%s/%s.php", $directory, $name);
         $classDescription = sprintf("%s %s", $description, $name);
         $datetime = new \DateTime();
         $properties = array((new PropertyGenerator("name", $item->getName()))->setDocBlock(new DocBlockGenerator(sprintf("%s Name", $classDescription), "", array(new Tag("var", "string")))), (new PropertyGenerator("value", $item->getValue()))->setDocBlock(new DocBlockGenerator(sprintf("%s Value", $classDescription), "", array(new Tag("var", "string")))));
         $docblock = new DocBlockGenerator($classDescription, "", array(new Tag("author", "ITC Generator " . $datetime->format("d.m.Y h:m:s")), new Tag("copyright", "LGPL")));
         $fileGenerator = new FileGenerator();
         $fileGenerator->setClass(new ClassGenerator($name, $namespace, null, $parentClass, array(), $properties, array(), $docblock));
         file_put_contents($filename, $fileGenerator->generate());
         $progressBar->advance();
     }
     $progressBar->finish();
 }

作者:harold    项目:xsd2ph   
protected function convert(AbstractConverter $converter, array $schemas, array $targets, OutputInterface $output)
 {
     $generator = new ClassGenerator();
     $generator->setTargetPhpVersion($converter->getTargetPhpVersion());
     $generator->setBaseClass($converter->getBaseClass());
     $pathGenerator = new Psr4PathGenerator($targets);
     $progress = $this->getHelperSet()->get('progress');
     $items = $converter->convert($schemas);
     $progress->start($output, count($items));
     foreach ($items as $item) {
         $progress->advance(1, true);
         $output->write(" Creating <info>" . $output->getFormatter()->escape($item->getFullName()) . "</info>... ");
         $path = $pathGenerator->getPath($item);
         $fileGen = new FileGenerator();
         $fileGen->setFilename($path);
         $classGen = new \Zend\Code\Generator\ClassGenerator();
         if ($generator->generate($classGen, $item)) {
             $fileGen->setClass($classGen);
             $fileGen->write();
             $output->writeln("done.");
         } else {
             $output->write("skip.");
         }
     }
     $progress->finish();
 }

作者:rafalwrzeszc    项目:zf   
/**
     * getContents()
     *
     * @return string
     */
    public function getContents()
    {
        $codeGenerator = new FileGenerator();
        $codeGenerator->setBody(<<<EOS
// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'testing'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));

require_once 'Zend/Loader/StandardAutoloader.php';
\$loader = new Zend\\Loader\\StandardAutoloader(array(
    'fallback_autoloader' => true,
))
\$loader->register();

EOS
);
        return $codeGenerator->generate();
    }

作者:sandrokei    项目:prooph-cl   
/**
  * @interitdoc
  */
 public function writeClass($filename, FileGenerator $fileGenerator)
 {
     $dir = dirname($filename);
     if (!@mkdir($dir, 0755, true) && !is_dir($dir)) {
         throw new RuntimeException(sprintf('Could not create "%s" directory.', $dir));
     }
     file_put_contents($filename, $fileGenerator->generate());
 }

作者:nevvermin    项目:zf   
/**
  * 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();
 }

作者:Code-Mine-Developmen    项目:CommandQueryGenerato   
private function makeSureConfigFileExist()
 {
     if (FALSE === file_exists($this->confPath)) {
         $fileGenerator = new FileGenerator();
         $body = $this->getConfigTemplate();
         $fileGenerator->setBody($body);
         file_put_contents($this->confPath, $fileGenerator->generate());
     }
 }

作者:phpr    项目:soap-clien   
/**
  * @param FileGenerator $file
  * @param Type          $type
  *
  * @return string
  */
 public function generate(FileGenerator $file, $type)
 {
     $class = $file->getClass() ?: new ClassGenerator();
     $class->setNamespaceName($type->getNamespace());
     $class->setName($type->getName());
     $this->ruleSet->applyRules(new TypeContext($class, $type));
     foreach ($type->getProperties() as $property) {
         $this->ruleSet->applyRules(new PropertyContext($class, $type, $property));
     }
     $file->setClass($class);
     return $file->generate();
 }

作者:goetas-webservice    项目:xsd2ph   
public function write(array $items)
 {
     foreach ($items as $item) {
         $path = $this->pathGenerator->getPath($item);
         $fileGen = new FileGenerator();
         $fileGen->setFilename($path);
         $fileGen->setClass($item);
         $fileGen->write();
         $this->logger->debug(sprintf("Written PHP class file %s", $path));
     }
     $this->logger->info(sprintf("Written %s STUB classes", count($items)));
 }

作者:CHRISTOPHERVANDOMM    项目:zf2comple   
/**
  * Registry for the Zend\Code package.
  *
  * @param  FileGenerator $fileCodeGenerator
  * @param  string $fileName
  * @throws RuntimeException
  */
 public static function registerFileCodeGenerator(FileGenerator $fileCodeGenerator, $fileName = null)
 {
     if ($fileName === null) {
         $fileName = $fileCodeGenerator->getFilename();
     }
     if ($fileName == '') {
         throw new RuntimeException('FileName does not exist.');
     }
     // cannot use realpath since the file might not exist, but we do need to have the index
     // in the same DIRECTORY_SEPARATOR that realpath would use:
     $fileName = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $fileName);
     static::$fileCodeGenerators[$fileName] = $fileCodeGenerator;
 }

作者:jchoi92    项目:php-ew   
protected function convert(AbstractConverter $converter, array $schemas, array $targets, OutputInterface $output)
 {
     $generator = new ClassGenerator();
     $pathGenerator = new Psr4PathGenerator($targets);
     $progress = $this->getHelperSet()->get('progress');
     $converter->addAliasMap('http://schemas.microsoft.com/exchange/services/2006/types', 'Or', function ($type) use($schemas) {
         return "OrElement";
     });
     $converter->addAliasMap('http://schemas.microsoft.com/exchange/services/2006/types', 'And', function ($type) use($schemas) {
         return "AndElement";
     });
     $converter->addAliasMap('http://schemas.microsoft.com/exchange/services/2006/types', 'EmailAddress', function ($type) use($schemas) {
         return "jamesiarmes\\PEWS\\API\\Type\\EmailAddressType";
     });
     $items = $converter->convert($schemas);
     $progress->start($output, count($items));
     $classMap = [];
     foreach ($items as $item) {
         /** @var PHPClass $item */
         $progress->advance(1, true);
         $output->write(" Creating <info>" . $output->getFormatter()->escape($item->getFullName()) . "</info>... ");
         $path = $pathGenerator->getPath($item);
         $fileGen = new FileGenerator();
         $fileGen->setFilename($path);
         $classGen = new \Zend\Code\Generator\ClassGenerator();
         $itemClass = $item->getNamespace() . '\\' . $item->getName();
         if (class_exists($itemClass)) {
             $existingClass = Generator\ClassGenerator::fromReflection(new ClassReflection($itemClass));
             $classGen = $existingClass;
         }
         if ($generator->generate($classGen, $item)) {
             $fileGen->setClass($classGen);
             $fileGen->write();
             $output->writeln("done.");
             if (isset($item->type) && $item->type->getName() != "") {
                 $classMap[$item->type->getName()] = '\\' . $classGen->getNamespaceName() . '\\' . $classGen->getName();
             }
         } else {
             $output->write("skip.");
         }
     }
     $mappingClassReflection = new ClassReflection(ClassMap::class);
     $mappingClass = Generator\ClassGenerator::fromReflection($mappingClassReflection);
     $mappingClass->getProperty('classMap')->setDefaultValue($classMap);
     $fileGen = new FileGenerator();
     $fileGen->setFilename($mappingClassReflection->getFileName());
     $fileGen->setClass($mappingClass);
     $fileGen->write();
     $progress->finish();
 }

作者:slavomirkuzm    项目:itc-bundl   
/**
  *
  * @param DTDDocument $document        	
  * @param string $outputDirectory        	
  * @param string $namespace        	
  * @param string $parentClass        	
  */
 public function generate(DTDDocument $document, $outputDirectory, $namespace, $parentClass)
 {
     if (!file_exists($outputDirectory)) {
         mkdir($outputDirectory, 0777, true);
     }
     $name = ucfirst($document->getFileInfo()->getBasename('.dtd'));
     $filename = sprintf("%s/%s.php", $outputDirectory, $name);
     $classGenerator = new ClassGenerator($name, $namespace, null, $parentClass);
     $fileGenerator = new FileGenerator();
     $fileGenerator->setClass($classGenerator);
     $fileDocblock = new DocBlockGenerator(sprintf("%s %s", str_replace("\\", " ", $namespace), $name));
     $fileDocblock->setTag(new Tag("author", "Generator"));
     $fileDocblock->setTag(new Tag("licence", "LGPL"));
     $fileGenerator->setDocBlock($fileDocblock);
     file_put_contents($filename, $fileGenerator->generate());
 }

作者:fabiopaiv    项目:PDOSimpleMigratio   
private function generate($version)
 {
     $generator = new ClassGenerator();
     $docblock = DocBlockGenerator::fromArray(array('shortDescription' => 'PDO Simple Migration Class', 'longDescription' => 'Add your queries below'));
     $generator->setName('PDOSimpleMigration\\Migrations\\Migration' . $version)->setExtendedClass('AbstractMigration')->addUse('PDOSimpleMigration\\Library\\AbstractMigration')->setDocblock($docblock)->addProperties(array(array('description', 'Migration description', PropertyGenerator::FLAG_STATIC)))->addMethods(array(MethodGenerator::fromArray(array('name' => 'up', 'parameters' => array(), 'body' => '//$this->addSql(/*Sql instruction*/);', 'docblock' => DocBlockGenerator::fromArray(array('shortDescription' => 'Migrate up', 'longDescription' => null)))), MethodGenerator::fromArray(array('name' => 'down', 'parameters' => array(), 'body' => '//$this->addSql(/*Sql instruction*/);', 'docblock' => DocBlockGenerator::fromArray(array('shortDescription' => 'Migrate down', 'longDescription' => null))))));
     $file = FileGenerator::fromArray(array('classes' => array($generator)));
     return $file->generate();
 }

作者:phpr    项目:soap-clien   
function it_generates_types(RuleSetInterface $ruleSet, FileGenerator $file, ClassGenerator $class)
 {
     $type = new Type('MyNamespace', 'MyType', ['prop1' => 'string']);
     $property = $type->getProperties()[0];
     $file->generate()->willReturn('code');
     $file->getClass()->willReturn($class);
     $class->setNamespaceName('MyNamespace')->shouldBeCalled();
     $class->setName('MyType')->shouldBeCalled();
     $file->setClass($class)->shouldBeCalled();
     $ruleSet->applyRules(Argument::that(function (ContextInterface $context) use($type) {
         return $context instanceof TypeContext && $context->getType() === $type;
     }))->shouldBeCalled();
     $ruleSet->applyRules(Argument::that(function (ContextInterface $context) use($type, $property) {
         return $context instanceof PropertyContext && $context->getType() === $type && $context->getProperty() === $property;
     }))->shouldBeCalled();
     $this->generate($file, $type)->shouldReturn('code');
 }

作者:jsiefe    项目:class-mocke   
/**
  * FileGenerator constructor.
  */
 public function __construct()
 {
     parent::__construct();
     $mockTag = new GenericTag();
     $mockTag->setName('mock');
     $author = new AuthorTag('ClassMocker');
     $docBlock = new DocBlockGenerator();
     $docBlock->setShortDescription("Auto generated file by ClassMocker, do not change");
     $docBlock->setTag($author);
     $docBlock->setTag($mockTag);
     $this->setDocBlock($docBlock);
 }

作者:slavomirkuzm    项目:itc-bundl   
public function generate(DTDDocument $document, $outputDirectory, $namespace, $parentClass)
 {
     $items = $document->getElement();
     $directory = sprintf($outputDirectory, $document->getFileInfo()->getBasename('.dtd'));
     $namespace = sprintf($namespace, $document->getFileInfo()->getBasename('.dtd'));
     $description = str_replace("\\", " ", $namespace);
     if (!file_exists($directory)) {
         mkdir($directory, 0777, true);
     }
     foreach ($items as $item) {
         $name = sprintf("%sElement", Source::camelCase($item->getName()));
         $filename = sprintf("%s/%s.php", $directory, $name);
         $classDescription = sprintf("%s %s", $description, $name);
         $datetime = new \DateTime();
         $properties = array((new PropertyGenerator("name", $item->getName()))->setDocBlock(new DocBlockGenerator(sprintf("%s Name", $classDescription), "", array(new Tag("var", "string")))), (new PropertyGenerator("value", $item->getValue()))->setDocBlock(new DocBlockGenerator(sprintf("%s Value", $classDescription), "", array(new Tag("var", "string")))));
         $docblock = new DocBlockGenerator($classDescription, "", array(new Tag("author", "ITC Generator " . $datetime->format("d.m.Y h:m:s")), new Tag("copyright", "LGPL")));
         $fileGenerator = new FileGenerator();
         $fileGenerator->setClass(new ClassGenerator($name, $namespace, null, $parentClass, array(), $properties, array(), $docblock));
         file_put_contents($filename, $fileGenerator->generate());
     }
 }

作者:slavomirkuzm    项目:itc-bundl   
/**
  * (non-PHPdoc)
  *
  * @see \Symfony\Component\Console\Command\Command::execute()
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $document = $this->getDocument($input->getArgument('document'));
     $directory = $input->getArgument('output');
     $namespace = $input->getArgument('namespace');
     $parentClass = $input->getArgument('parentClass');
     if (!file_exists($directory)) {
         mkdir($directory, 0777, true);
     }
     $name = ucfirst($document->getFileInfo()->getBasename('.dtd'));
     $output->writeln("Generating Document " . $name);
     $filename = sprintf("%s/%s.php", $directory, $name);
     $classGenerator = new ClassGenerator($name, $namespace, null, $parentClass);
     $fileGenerator = new FileGenerator();
     $fileGenerator->setClass($classGenerator);
     $fileDocblock = new DocBlockGenerator(sprintf("%s %s", str_replace("\\", " ", $namespace), $name));
     $fileDocblock->setTag(new Tag("author", "Generator"));
     $fileDocblock->setTag(new Tag("licence", "LGPL"));
     $fileGenerator->setDocBlock($fileDocblock);
     file_put_contents($filename, $fileGenerator->generate());
 }

作者:djmattyg00    项目:autocodeloade   
/**
  * @param string $className
  * @return \Zend\Code\Generator\ClassGenerator
  */
 public function handle(string $className)
 {
     if (!preg_match(static::MATCH_PATTERN, $className, $matches)) {
         return null;
     }
     $baseName = $matches[1];
     $namespace = $this->deriveNamespaceFromClassName($className);
     $class = FileGenerator::fromReflectedFileName(__DIR__ . DIRECTORY_SEPARATOR . "templates" . DIRECTORY_SEPARATOR . "factory.php")->getClass("Factory");
     $class->setNamespaceName($namespace)->setName("{$baseName}Factory");
     $createMethod = $class->getMethod("create");
     $createMethod->setBody('return $this->diContainer->newInstance(' . $baseName . '::class, $params);')->setReturnType("{$namespace}\\{$baseName}");
     return $class;
 }

作者:nilportugue    项目:php-namespace-checke   
private function expectedPathForPsr4(array $filePaths, $namespace)
 {
     foreach ($filePaths as $file) {
         $generator = FileGenerator::fromReflectedFileName($file);
         $phpClassName = $generator->getClass()->getName();
         $fileClassName = pathinfo($file, PATHINFO_FILENAME);
         $phpClassNamespace = $generator->getClass()->getNamespaceName();
         if (false === strpos($namespace, $phpClassName)) {
             throw new \Exception(sprintf("File '%s' namespace is not valid.\nExpected to be under the '%s' namespace, found '%s'.", $file, $namespace, $phpClassNamespace));
         }
     }
     print_r(func_get_args());
     die;
 }

作者:proophsoftwar    项目:prooph-cl   
/**
  * Search for unnecessary namespace imports and definitions and replace occurrences.
  *
  * @param FileGenerator $fileGenerator
  * @return string Generated code
  */
 public function replaceNamespace(FileGenerator $fileGenerator)
 {
     $uses = [];
     $search = [];
     $replace = [];
     foreach ($fileGenerator->getUses() as $import) {
         $namespace = trim(substr($import[0], 0, strrpos($import[0], '\\')), '\\');
         if ($fileGenerator->getNamespace() !== $namespace) {
             $uses[] = $import;
         }
         $name = trim(substr($import[0], strrpos($import[0], '\\')), '\\');
         $search[] = '\\' . $import[0];
         $search[] = ', \\' . $import[0];
         $replace[] = $name;
         $replace[] = ', ' . $name;
     }
     // workaround to reset use imports
     $reflection = new \ReflectionClass($fileGenerator);
     $property = $reflection->getProperty('uses');
     $property->setAccessible(true);
     $property->setValue($fileGenerator, $uses);
     $code = $fileGenerator->generate();
     return str_replace($search, $replace, $code);
 }


问题


面经


文章

微信
公众号

扫码关注公众号