本文整理汇总了PHP中Zend\Code\Generator\FileGenerator::write方法的典型用法代码示例。如果您正苦于以下问题:PHP FileGenerator::write方法的具体用法?PHP FileGenerator::write怎么用?PHP FileGenerator::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Code\Generator\FileGenerator
的用法示例。
在下文中一共展示了FileGenerator::write方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convert
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();
}
示例2: write
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)));
}
示例3: convert
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();
}
示例4: realpath
require __DIR__ . "/../vendor/autoload.php";
$namespace = "CallFire\\Common\\Resource";
$extendedClass = "AbstractResource";
$xsdUrl = 'https://www.callfire.com/api/1.1/wsdl/callfire-data.xsd';
$sourceDirectory = realpath(__DIR__ . "/../src") . '/' . str_replace('\\', '/', $namespace);
$queryMapPath = realpath(__DIR__ . "/../src") . '/CallFire/Api/Rest/querymap.php';
$xsdContent = file_get_contents($xsdUrl);
$xsdDocument = new DOMDocument();
$xsdDocument->loadXML($xsdContent);
unset($xsdContent);
$resourceGenerator = new ResourceGenerator();
$resourceGenerator->setXsd($xsdDocument);
$resourceClassGenerator = new ClassGenerator();
$resourceClassGenerator->setExtendedClass($extendedClass);
$resourceClassGenerator->setNamespaceName($namespace);
$resourceGenerator->setClassGenerator($resourceClassGenerator);
$resourceGenerator->generate();
$resourceFiles = $resourceGenerator->generateResourceFiles();
$queryMap = $resourceGenerator->getQueryMap();
if (!is_dir($sourceDirectory)) {
mkdir($sourceDirectory, 0777, true);
}
foreach ($resourceFiles as $resourceFile) {
$resourceFile->setFilename("{$sourceDirectory}/{$resourceFile->getClass()->getName()}.php");
$resourceFile->write();
}
$queryMapFile = new FileGenerator();
$queryMapFile->setFilename($queryMapPath);
$queryMapFile->setBody('return ' . (new ValueGenerator($queryMap))->generate() . ';');
$queryMapFile->write();
passthru('php ' . __DIR__ . '/../vendor/fabpot/php-cs-fixer/php-cs-fixer fix ' . __DIR__ . '/../src/CallFire/Common/Resource/ --level=all');
示例5: writeClass
/**
* @param ClassGenerator $class
*/
protected function writeClass(ClassGenerator $class)
{
$generator = new FileGenerator();
$generator->setClass($class);
$generator->setFilename('src/Flex/Code/Html/Tag/' . $class->getName() . '.php');
$generator->write();
}
示例6: generatePHPFiles
protected static function generatePHPFiles(array $schemas)
{
$phpcreator = new PhpConverter(new ShortNamingStrategy());
$phpcreator->addNamespace('http://www.opentravel.org/OTA/2003/05', self::$namespace);
$phpcreator->addAliasMapType('http://www.opentravel.org/OTA/2003/05', 'DateOrTimeOrDateTimeType', 'Goetas\\Xsd\\XsdToPhp\\Tests\\JmsSerializer\\OTA\\OTADateTime');
$phpcreator->addAliasMapType('http://www.opentravel.org/OTA/2003/05', 'DateOrDateTimeType', 'Goetas\\Xsd\\XsdToPhp\\Tests\\JmsSerializer\\OTA\\OTADateTime');
$phpcreator->addAliasMapType('http://www.opentravel.org/OTA/2003/05', 'TimeOrDateTimeType', 'Goetas\\Xsd\\XsdToPhp\\Tests\\JmsSerializer\\OTA\\OTADateTime');
$items = $phpcreator->convert($schemas);
$generator = new ClassGenerator();
$pathGenerator = new Psr4PathGenerator(array(self::$namespace . "\\" => self::$phpDir));
foreach ($items as $item) {
$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();
}
}
}
示例7: elseif
$extendedClass = $resourceFile->getClass()->getExtendedClass();
if (in_array($resourceFile->getClass()->getName(), $requestTypes) || in_array($extendedClass, $requestTypes)) {
$type = $requestNamespacePart;
$resourceFile->getClass()->setNamespaceName($requestNamespace);
if (!$extendedClass) {
$resourceFile->getClass()->setExtendedClass(SoapGenerator::ABSTRACT_REQUEST_ALIAS)->addUse("{$namespace}\\{$soapNamespace}\\AbstractRequest", SoapGenerator::ABSTRACT_REQUEST_ALIAS);
}
} elseif (in_array($resourceFile->getClass()->getName(), $responseTypes) || in_array($extendedClass, $responseTypes)) {
$type = $responseNamespacePart;
$resourceFile->getClass()->setNamespaceName($responseNamespace);
if (!$extendedClass) {
$resourceFile->getClass()->setExtendedClass(SoapGenerator::ABSTRACT_RESPONSE_ALIAS)->addUse("{$namespace}\\{$soapNamespace}\\AbstractResult", SoapGenerator::ABSTRACT_RESPONSE_ALIAS);
}
} else {
$type = $structureNamespacePart;
$resourceFile->getClass()->setNamespaceName($structureNamespace);
}
$resourceFile->setFilename("{$sourceDirectory}/{$soapNamespace}/{$type}/{$resourceFile->getClass()->getName()}.php");
$resourceFile->write();
$classmap[$resourceFile->getClass()->getName()] = $resourceFile->getClass()->getNamespaceName() . '\\' . $resourceFile->getClass()->getName();
}
foreach (glob("{$commonResourceDirectory}/*.php") as $fileName) {
$className = basename($fileName, ".php");
$classmap[$className] = "{$commonResourceNamespace}\\{$className}";
}
$classmapValueGenerator = new ValueGenerator($classmap);
$classmapFileGenerator = new FileGenerator();
$classmapFileGenerator->setBody('return ' . $classmapValueGenerator->generate() . ';');
$classmapFileGenerator->setFilename("{$sourceDirectory}/{$soapNamespace}/classmap.php");
$classmapFileGenerator->write();
passthru('php ' . __DIR__ . '/../vendor/fabpot/php-cs-fixer/php-cs-fixer fix ' . __DIR__ . '/../src/CallFire/Api/Soap/ --level=all');
示例8: getDiDefinitions
/**
* @param $config
* @param null|Di $di
* @return string
*/
protected function getDiDefinitions($config, Di $di = null)
{
ErrorHandler::start();
if ($arrayDefinitions = (include $config['ocra_di_compiler']['compiled_di_definitions_filename'])) {
ErrorHandler::stop();
return $config['ocra_di_compiler']['compiled_di_definitions_filename'];
}
ErrorHandler::stop();
if (!$di) {
$di = new Di();
if (isset($config['di'])) {
$diConfig = new DiConfig($config['di']);
$diConfig->configure($di);
}
}
$dumper = new Dumper($di);
$definitionsCompiler = new ClassListCompilerDefinition();
$definitionsCompiler->addClassesToProcess($dumper->getAllClasses());
$definitionsCompiler->compile();
$fileGenerator = new FileGenerator();
$fileGenerator->setFilename($config['ocra_di_compiler']['compiled_di_definitions_filename']);
$fileGenerator->setBody('return ' . var_export($definitionsCompiler->toArrayDefinition()->toArray(), true) . ';');
$fileGenerator->write();
return $config['ocra_di_compiler']['compiled_di_definitions_filename'];
}
示例9: convert
protected function convert(AbstractConverter $converter, array $schemas, array $targets, OutputInterface $output)
{
$this->setClientMethodDocblocks();
$generator = new ClassGenerator();
$pathGenerator = new Psr4PathGenerator($targets);
$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 "garethp\\ews\\API\\Type\\EmailAddressType";
});
$items = $converter->convert($schemas);
$progress = new ProgressBar($output, count($items));
$progress->start(count($items));
$classMap = [];
foreach ($items as $item) {
/** @var PHPClass $item */
$progress->advance(1, true);
$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)) {
$fileGen = FileGenerator::fromReflectedFileName($path);
$fileGen->setFilename($path);
$classGen = Generator\ClassGenerator::fromReflection(new ClassReflection($itemClass));
}
if ($generator->generate($classGen, $item)) {
$namespace = $classGen->getNamespaceName();
$fileGen->setClass($classGen);
$fileGen->write();
if (isset($item->type) && $item->type->getName() != "" && $item->getNamespace() !== Enumeration::class) {
$classMap[$item->type->getName()] = '\\' . $namespace . '\\' . $classGen->getName();
}
} else {
}
}
$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();
}
示例10: buildProxyClass
private function buildProxyClass(string $entityInterfaceName, string $proxyNamespace, string $proxyClassName) : string
{
$reflectionClass = new ReflectionClass($entityInterfaceName);
if (!$reflectionClass->isInterface()) {
throw InvalidInterfaceException::fromInvalidInterface($entityInterfaceName);
}
$classGenerator = new ClassGenerator();
$classGenerator->setNamespaceName($proxyNamespace);
$classGenerator->setName($proxyClassName);
$classGenerator->setImplementedInterfaces([$entityInterfaceName, ProxyInterface::class]);
$classGenerator->addProperty('initializer', null, PropertyGenerator::FLAG_PRIVATE);
$classGenerator->addProperty('relationId', null, PropertyGenerator::FLAG_PRIVATE);
$classGenerator->addProperty('realEntity', null, PropertyGenerator::FLAG_PRIVATE);
$constructorGenerator = new MethodGenerator('__construct', [['name' => 'initializer', 'type' => 'callable'], ['name' => 'relationId']]);
$constructorGenerator->setBody('
$this->initializer = $initializer;
$this->relationId = $relationId;
');
$classGenerator->addMethodFromGenerator($constructorGenerator);
$getRelationIdGenerator = new MethodGenerator('__getRelationId');
$getRelationIdGenerator->setBody('
return $this->relationId;
');
$classGenerator->addMethodFromGenerator($getRelationIdGenerator);
$getRealEntityGenerator = new MethodGenerator('__getRealEntity');
$getRealEntityGenerator->setBody('
if (null === $this->realEntity) {
$this->realEntity = ($this->initializer)();
\\Assert\\Assertion::isInstanceOf($this->realEntity, \\' . $entityInterfaceName . '::class);
};
return $this->realEntity;
');
$classGenerator->addMethodFromGenerator($getRealEntityGenerator);
foreach ($reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC) as $reflectionMethod) {
$parameters = [];
$parameterGenerators = [];
$returnType = $reflectionMethod->getReturnType();
foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
$parameterGenerator = new ParameterGenerator($reflectionParameter->getName(), $reflectionParameter->getType(), $reflectionParameter->isDefaultValueAvailable() ? $reflectionParameter->getDefaultValue() : null);
$parameterGenerator->setVariadic($reflectionParameter->isVariadic());
$parameterGenerators[] = $parameterGenerator;
if ($reflectionParameter->isVariadic()) {
$parameters[] = '...$' . $reflectionParameter->getName();
} else {
$parameters[] = '$' . $reflectionParameter->getName();
}
}
$methodGenerator = new MethodGenerator();
$methodGenerator->setName($reflectionMethod->getName());
$methodGenerator->setVisibility(MethodGenerator::VISIBILITY_PUBLIC);
$methodGenerator->setParameters($parameterGenerators);
$methodGenerator->setReturnType($returnType);
$body = '
if (null === $this->realEntity) {
$this->realEntity = ($this->initializer)();
\\Assert\\Assertion::isInstanceOf($this->realEntity, \\' . $entityInterfaceName . '::class);
};
';
if ('void' !== $returnType) {
$body .= 'return ';
}
$body .= '$this->realEntity->' . $reflectionMethod->getName() . '(' . implode(', ', $parameters) . ');';
$methodGenerator->setBody($body);
$classGenerator->addMethodFromGenerator($methodGenerator);
}
$fileGenerator = new FileGenerator();
$fileGenerator->setClass($classGenerator);
$filename = null === $this->proxyFolder ? tempnam(sys_get_temp_dir(), $proxyClassName) : sprintf('%s/%s.php', $this->proxyFolder, $proxyClassName);
$fileGenerator->setFilename($filename);
$fileGenerator->write();
return $filename;
}
示例11: convert
/**
* @param PhpConverter $converter
* @param array $schemas
* @param array $targets
* @param XsdGeneratePhpArgs $input
* @param XsdGeneratePhpCommand $command
* @throws \Goetas\Xsd\XsdToPhp\PathGenerator\PathGeneratorException
*/
protected function convert(PhpConverter $converter, array $schemas, array $targets, XsdGeneratePhpArgs $input, XsdGeneratePhpCommand $command)
{
$generator = new ClassGenerator();
$pathGenerator = new Psr4PathGenerator($targets);
$items = $converter->convert($schemas);
/** @var ProgressBar $progressBar */
$progressBar = new ProgressBar($this->output, count($items));
$progressBar->start();
$extendClass = null;
if ($input->hasExtendedClass()) {
$extendClass = new PHPClass($input->getExtendedClassName(), $input->getExtendedClassNamespaceName());
}
$this->outputWriteLine("Generating PHP files");
$skippedFiles = array();
/** @var PHPClass $item */
foreach ($items as $item) {
$progressBar->advance();
$path = $pathGenerator->getPath($item);
$fileGen = new FileGenerator();
$fileGen->setFilename($path);
$classGen = new \Zend\Code\Generator\ClassGenerator();
if (!$item->getExtends() instanceof PHPClass && $extendClass instanceof PHPClass) {
$item->setExtends($extendClass);
}
if (!$generator->generate($classGen, $item)) {
$skippedFiles[] = $item->getFullName();
}
$fileGen->setClass($classGen);
$fileGen->write();
}
$progressBar->finish();
if (!empty($skippedFiles)) {
foreach ($skippedFiles as $skippedFile) {
$this->outputWriteLine(" + <info>" . $this->outputFormatterEscape($skippedFile) . "</info>... ");
}
}
}