本文整理汇总了PHP中Zend\Code\Generator\FileGenerator::setFilename方法的典型用法代码示例。如果您正苦于以下问题:PHP FileGenerator::setFilename方法的具体用法?PHP FileGenerator::setFilename怎么用?PHP FileGenerator::setFilename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Code\Generator\FileGenerator
的用法示例。
在下文中一共展示了FileGenerator::setFilename方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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();
}
示例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: getCodeGenerator
//.........这里部分代码省略.........
continue;
}
$methodName = isset($methodData['name']) ? $methodData['name'] : $methodData['method'];
$methodParams = $methodData['params'];
// Create method parameter representation
foreach ($methodParams as $key => $param) {
if (null === $param || is_scalar($param) || is_array($param)) {
$string = var_export($param, 1);
if (strstr($string, '::__set_state(')) {
throw new Exception\RuntimeException('Arguments in definitions may not contain objects');
}
$methodParams[$key] = $string;
} elseif ($param instanceof GeneratorInstance) {
$methodParams[$key] = sprintf('$this->%s()', $this->normalizeAlias($param->getName()));
} else {
$message = sprintf('Unable to use object arguments when generating method calls. Encountered with class "%s", method "%s", parameter of type "%s"', $name, $methodName, get_class($param));
throw new Exception\RuntimeException($message);
}
}
// Strip null arguments from the end of the params list
$reverseParams = array_reverse($methodParams, true);
foreach ($reverseParams as $key => $param) {
if ('NULL' === $param) {
unset($methodParams[$key]);
continue;
}
break;
}
$methods .= sprintf("\$object->%s(%s);\n", $methodName, implode(', ', $methodParams));
}
// Generate caching statement
$storage = '';
if ($im->hasSharedInstance($name, $params)) {
$storage = sprintf("\$this->services['%s'] = \$object;\n", $name);
}
// Start creating getter
$getterBody = '';
// Create fetch of stored service
if ($im->hasSharedInstance($name, $params)) {
$getterBody .= sprintf("if (isset(\$this->services['%s'])) {\n", $name);
$getterBody .= sprintf("%sreturn \$this->services['%s'];\n}\n\n", $indent, $name);
}
// Creation and method calls
$getterBody .= sprintf("%s\n", $creation);
$getterBody .= $methods;
// Stored service
$getterBody .= $storage;
// End getter body
$getterBody .= "return \$object;\n";
$getterDef = new MethodGenerator();
$getterDef->setName($getter);
$getterDef->setBody($getterBody);
$getters[] = $getterDef;
// Get cases for case statements
$cases = array($name);
if (isset($aliases[$name])) {
$cases = array_merge($aliases[$name], $cases);
}
// Build case statement and store
$statement = '';
foreach ($cases as $value) {
$statement .= sprintf("%scase '%s':\n", $indent, $value);
}
$statement .= sprintf("%sreturn \$this->%s();\n", str_repeat($indent, 2), $getter);
$caseStatements[] = $statement;
}
// Build switch statement
$switch = sprintf("switch (%s) {\n%s\n", '$name', implode("\n", $caseStatements));
$switch .= sprintf("%sdefault:\n%sreturn parent::get(%s, %s);\n", $indent, str_repeat($indent, 2), '$name', '$params');
$switch .= "}\n\n";
// Build get() method
$nameParam = new ParameterGenerator();
$nameParam->setName('name');
$paramsParam = new ParameterGenerator();
$paramsParam->setName('params')->setType('array')->setDefaultValue(array());
$get = new MethodGenerator();
$get->setName('get');
$get->setParameters(array($nameParam, $paramsParam));
$get->setBody($switch);
// Create getters for aliases
$aliasMethods = array();
foreach ($aliases as $class => $classAliases) {
foreach ($classAliases as $alias) {
$aliasMethods[] = $this->getCodeGenMethodFromAlias($alias, $class);
}
}
// Create class code generation object
$container = new ClassGenerator();
$container->setName($this->containerClass)->setExtendedClass('ServiceLocator')->addMethodFromGenerator($get)->addMethods($getters)->addMethods($aliasMethods);
// Create PHP file code generation object
$classFile = new FileGenerator();
$classFile->setUse('Zend\\Di\\ServiceLocator')->setClass($container);
if (null !== $this->namespace) {
$classFile->setNamespace($this->namespace);
}
if (null !== $filename) {
$classFile->setFilename($filename);
}
return $classFile;
}
示例7: getContents
/**
* getContents()
*
* @return string
*/
public function getContents()
{
$className = $this->_moduleName ? ucfirst($this->_moduleName) . '\\' : '';
$className .= ucfirst($this->_controllerName) . 'Controller';
$codeGenFile = new FileGenerator();
$codeGenFile->setFilename($this->getPath());
$cg = new ClassGenerator($className);
$cg->setMethod(new MethodGenerator('init', array(), null, '/* Initialize action controller here */'));
$codeGenFile->setClass($cg);
if ($className == 'ErrorController') {
$codeGenFile = new FileGenerator();
$codeGenFile->setFilename($this->getPath());
$cg = new ClassGenerator($className);
$cg->setMethods(array(new MethodGenerator('errorAction', array(), null, <<<'EOS'
$errors = $this->_getParam('error_handler');
if (!$errors || !$errors instanceof \ArrayObject) {
$this->view->vars()->message = 'You have reached the error page';
return;
}
switch ($errors->type) {
case \Zend\Controller\Plugin\ErrorHandler::EXCEPTION_NO_ROUTE:
case \Zend\Controller\Plugin\ErrorHandler::EXCEPTION_NO_CONTROLLER:
case \Zend\Controller\Plugin\ErrorHandler::EXCEPTION_NO_ACTION:
// 404 error -- controller or action not found
$this->getResponse()->setHttpResponseCode(404);
$priority = \Zend\Log\Logger::NOTICE;
$this->view->vars()->message = 'Page not found';
break;
default:
// application error
$this->getResponse()->setHttpResponseCode(500);
$priority = \Zend\Log\Logger::CRIT;
$this->view->vars()->message = 'Application error';
break;
}
// Log exception, if logger available
if (($log = $this->getLog())) {
$log->log($this->view->vars()->message, $priority, $errors->exception);
$log->log('Request Parameters', $priority, $errors->request->getParams());
}
// conditionally display exceptions
if ($this->getInvokeArg('displayExceptions') == true) {
$this->view->vars()->exception = $errors->exception;
}
$this->view->vars()->request = $errors->request;
EOS
), new MethodGenerator('getLog', array(), null, <<<'EOS'
/* @var $bootstrap Zend\Application\Bootstrap */
$bootstrap = $this->getInvokeArg('bootstrap');
if (!$bootstrap->getBroker()->hasPlugin('Log')) {
return false;
}
$log = $bootstrap->getResource('Log');
return $log;
EOS
)));
}
// store the generator into the registry so that the addAction command can use the same object later
FileGeneratorRegistry::registerFileCodeGenerator($codeGenFile);
// REQUIRES filename to be set
return $codeGenFile->generate();
}
示例8: controllerAction
public function controllerAction()
{
$config = $this->getServiceLocator()->get('config');
$moduleName = $config['VisioCrudModeler']['params']['moduleName'];
$modulePath = $config['VisioCrudModeler']['params']['modulesDirectory'];
$db = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter');
$dataSourceDescriptor = new DbDataSourceDescriptor($db, 'K08_www_biedronka_pl');
$listDataSets = $dataSourceDescriptor->listDataSets();
$filter = new \Zend\Filter\Word\UnderscoreToCamelCase();
foreach ($listDataSets as $d) {
$className = $filter->filter($d) . 'Controller';
$file = new FileGenerator();
$file->setFilename($className);
$file->setNamespace($moduleName)->setUse('Zend\\Mvc\\Controller\\AbstractActionController');
$foo = new ClassGenerator();
$docblock = DocBlockGenerator::fromArray(array('shortDescription' => 'Sample generated class', 'longDescription' => 'This is a class generated with Zend\\Code\\Generator.', 'tags' => array(array('name' => 'version', 'description' => '$Rev:$'), array('name' => 'license', 'description' => 'New BSD'))));
$foo->setName($className);
$foo->setExtendedClass('Base' . $className);
$foo->setDocblock($docblock);
$file->setClass($foo);
echo '<pre>';
echo htmlentities($file->generate());
echo '</pre>';
$fileView = new FileGenerator();
$body = "echo '{$className}';";
$fileView->setBody($body);
echo '<pre>';
echo htmlentities($fileView->generate());
echo '</pre>';
}
echo '<hr />';
foreach ($listDataSets as $d) {
$className = 'Base' . $filter->filter($d) . 'Controller';
$fileBase = new FileGenerator();
$fileBase->setFilename($className);
$fileBase->setNamespace($moduleName)->setUse('Zend\\Mvc\\Controller\\AbstractActionController');
$fooBase = new ClassGenerator();
$docblockBase = DocBlockGenerator::fromArray(array('shortDescription' => 'Sample generated class', 'longDescription' => 'This is a class generated with Zend\\Code\\Generator.', 'tags' => array(array('name' => 'version', 'description' => '$Rev:$'), array('name' => 'license', 'description' => 'New BSD'))));
$fooBase->setName($className);
$index = new MethodGenerator();
$index->setName('indexAction');
$create = new MethodGenerator();
$create->setName('createAction');
$read = new MethodGenerator();
$read->setName('readAction');
$update = new MethodGenerator();
$update->setName('updateAction');
$delete = new MethodGenerator();
$delete->setName('deleteAction');
$fooBase->setExtendedClass('AbstractActionController');
//$fooBase->set
$fooBase->setDocblock($docblock);
$fooBase->addMethodFromGenerator($index);
$fooBase->addMethodFromGenerator($create);
$fooBase->addMethodFromGenerator($read);
$fooBase->addMethodFromGenerator($update);
$fooBase->addMethodFromGenerator($delete);
$fileBase->setClass($fooBase);
echo '<pre>';
echo htmlentities($fileBase->generate());
echo '</pre>';
}
exit;
}
示例9: 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();
}
}
}
示例10: 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;
}
示例11: 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'];
}
示例12: generateModelFromMetadata
/**
* Generate Madel class from metadata
*
* @param stdClass $metadata
* @return Generator\ClassGenerator|null
*/
protected function generateModelFromMetadata($metadata)
{
$console = $this->getServiceLocator()->get('console');
$name = $metadata->Name;
$ucName = ucfirst($name);
// Create Api Class
$class = new Generator\ClassGenerator($ucName, 'Mailjet\\Model');
$class->setImplementedInterfaces(array('ModelInterface'))->setDocBlock(new Generator\DocBlockGenerator($class->getName() . ' Model', $metadata->Description, array()));
$this->addProperties($class, $metadata->Properties);
// Create and Write Api Class File
$file = new Generator\FileGenerator();
$file->setClass($class);
$file->setDocBlock(new Generator\DocBlockGenerator('MailJet Model', self::LICENSE));
$file->setFilename(dirname(__DIR__) . '/Model/' . $class->getName() . '.php');
if (file_put_contents($file->getFilename(), $file->generate())) {
$console->writeLine(sprintf("The Model '%s' has been created.", $class->getName()), Color::GREEN);
return $class;
} else {
$console->writeLine(sprintf("There was an error during '%s' Model creation.", $class->getName()), Color::RED);
}
return $class;
}
示例13: generateBaseController
/**
* generates base controller for given dataSet
*
* @param DataSetDescriptorInterface $dataSet
* @return string generated controller full class name
*/
protected function generateBaseController(DataSetDescriptorInterface $dataSet)
{
$name = $dataSet->getName();
$className = 'Base' . $this->underscoreToCamelCase->filter($name) . 'Controller';
$namespace = $this->params->getParam("moduleName") . '\\Controller\\Base';
$fullClassName = '\\' . $namespace . '\\' . $className;
$moduleName = $this->params->getParam("moduleName");
$fileBase = new FileGenerator();
$fileBase->setFilename($className);
$fileBase->setNamespace($namespace);
$class = new ClassGenerator();
$class->setName($className)->setExtendedClass('\\' . $this->extendedController);
$docBlock = new \Zend\Code\Generator\DocblockGenerator(sprintf($this->codeLibrary()->get('controller.standardBaseControllerDescription'), $name));
$docBlock->setTag(new GenericTag('author', $this->params->getParam('author')))->setTag(new GenericTag('project', $this->params->getParam('project')))->setTag(new GenericTag('license', $this->params->getParam('license')))->setTag(new GenericTag('copyright', $this->params->getParam('copyright')));
$class->setDocBlock($docBlock);
$this->addControllerMethods($class, $dataSet);
$fileBase->setClass($class);
$modelClassFilePath = $this->moduleRoot() . "/src/" . $this->params->getParam("moduleName") . "/Controller/Base/" . $className . ".php";
file_put_contents($modelClassFilePath, $fileBase->generate());
return $fullClassName;
}
示例14: 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;
}
示例15: 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');