本文整理汇总了PHP中Zend\Code\Generator\FileGenerator::setBody方法的典型用法代码示例。如果您正苦于以下问题:PHP FileGenerator::setBody方法的具体用法?PHP FileGenerator::setBody怎么用?PHP FileGenerator::setBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Code\Generator\FileGenerator
的用法示例。
在下文中一共展示了FileGenerator::setBody方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getContents
/**
* 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();
}
示例2: makeSureConfigFileExist
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());
}
}
示例3: 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');
示例4: updateConfiguration
/**
* @param array $configData
* @param $configFile
* @param boolean $align
*
* @return bool
*/
public function updateConfiguration(array $configData, $configFile, $align = false)
{
// set old file
$oldFile = str_replace('.php', '.old', $configFile);
// copy to old file
if (file_exists($configFile)) {
copy($configFile, $oldFile);
}
// create config array
$array = new ValueGenerator();
$array->initEnvironmentConstants();
$array->setValue($configData);
$array->setArrayDepth(0);
// generate body
$body = 'return ' . $array->generate() . ';' . AbstractGenerator::LINE_FEED;
// check for alignment
if ($align) {
// Align "=>" operators to match coding standard
preg_match_all('(\\n\\s+([^=]+)=>)', $body, $matches, PREG_SET_ORDER);
$maxWidth = 0;
foreach ($matches as $match) {
$maxWidth = max($maxWidth, strlen($match[1]));
}
$body = preg_replace('(\\n\\s+([^=]+)=>)e', "'\n \\1' . str_repeat(' ', " . $maxWidth . " - strlen('\\1')) . '=>'", $body);
}
// create file with file generator
$file = new FileGenerator();
$file->setBody($body);
// add optional doc block
if ($this->flagCreateApiDocs) {
$file->setDocBlock(new DocBlockGenerator('Configuration file generated by FrilleZFTool', 'The previous configuration file is stored in ' . $oldFile, array($this->generateSeeTag())));
}
// write application configuration
if (!file_put_contents($configFile, $file->generate())) {
return false;
}
return true;
}
示例5: createModuleConfig
/**
* creates module config files
*
* @return string returns config path
*/
protected function createModuleConfig()
{
$config = array();
$configPath = $this->moduleRoot() . '/config/module.config.php';
if (file_exists($configPath)) {
$config = (require $configPath);
}
$moduleConfig = new FileGenerator();
$moduleConfig->setDocBlock($this->getFileDocBlock());
$moduleConfig->getDocBlock()->setShortDescription(sprintf($this->codeLibrary()->get('module.standardConfigDescription'), $this->params->getParam('moduleName')));
$moduleConfig->setBody('return ' . var_export($config, true) . ';');
$this->console('writing module config file');
file_put_contents($this->moduleRoot() . '/config/module.config.php', $moduleConfig->generate());
return $configPath;
}
示例6: 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;
}
示例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: writeModuleConfig
/**
* writes module config
*
* @param array $config
* @param string $path
*/
protected function writeModuleConfig(array $config, $path)
{
$moduleName = $this->params->getParam('moduleName');
$generatorConfig = new FileGenerator();
$docBlock = new DocBlockGenerator();
$docBlock->setTag(new GenericTag('author', $this->params->getParam('author')));
$docBlock->setTag(new GenericTag('project', $this->params->getParam('project')));
$docBlock->setTag(new GenericTag('license', $this->params->getParam('license')));
$docBlock->setTag(new GenericTag('copyright', $this->params->getParam('copyright')));
$docBlock->setShortDescription(sprintf($this->codeLibrary()->get('module.generatedConfigDescription'), $moduleName));
$generatorConfig->setDocBlock($docBlock);
$configString = var_export($config, true);
$configString = str_replace("'/../view'", '__DIR__ . \'/../view\'', $configString);
$generatorConfig->setBody('return ' . $configString . ';');
file_put_contents($path, $generatorConfig->generate());
}