本文整理汇总了PHP中Zend\Code\Generator\FileGenerator::fromReflectedFileName方法的典型用法代码示例。如果您正苦于以下问题:PHP FileGenerator::fromReflectedFileName方法的具体用法?PHP FileGenerator::fromReflectedFileName怎么用?PHP FileGenerator::fromReflectedFileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Code\Generator\FileGenerator
的用法示例。
在下文中一共展示了FileGenerator::fromReflectedFileName方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addToConfigObjects
private function addToConfigObjects($objectName, $objectHandlerName, $objectHandlerFactoryName)
{
$conf = (include $this->confPath);
$fileGenerator = FileGenerator::fromReflectedFileName($this->confPath);
$conf['service_manager']['factories'][$objectHandlerName] = $objectHandlerFactoryName;
$conf['tactician']['handler-map'][$objectName] = $objectHandlerName;
$body = sprintf('return %s;', var_export($conf, TRUE));
$newFile = new FileGenerator();
$newFile->setUses($fileGenerator->getUses());
$newFile->setBody($body);
file_put_contents($this->confPath, $newFile->generate());
}
示例2: handle
/**
* @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;
}
示例3: expectedPathForPsr4
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;
}
示例4: __invoke
/**
* @inheritDoc
*/
public function __invoke($fcqn, $namespace, $commandName)
{
$commandName = ucfirst($commandName);
$reflectionClass = new ClassReflection($fcqn);
$fileGenerator = FileGenerator::fromReflectedFileName($reflectionClass->getFileName());
$fileGenerator->setFilename($reflectionClass->getFileName());
$fileGenerator->setUse(ltrim($namespace, '\\') . '\\' . $commandName);
$classGenerator = $fileGenerator->getClass();
// workaround for import namespace
if ($classToExtend = $classGenerator->getExtendedClass()) {
$classGenerator->setExtendedClass(substr($classToExtend, strrpos($classToExtend, '\\') + 1));
}
$classGenerator->addMethodFromGenerator($this->methodWhenEvent($commandName));
return $fileGenerator;
}
示例5: hasActionMethod
/**
* hasActionMethod()
*
* @param string $controllerPath
* @param string $actionName
* @return bool
*/
public static function hasActionMethod($controllerPath, $actionName)
{
if (!file_exists($controllerPath)) {
return false;
}
$controllerCodeGenFile = FileGenerator::fromReflectedFileName($controllerPath, true, true);
return $controllerCodeGenFile->getClass()->hasMethod($actionName . 'Action');
}
示例6: getCodeGenerator
/**
* getCodeGenerator()
*
* @return \Zend\Code\Generator\FileGenerator
*/
public function getCodeGenerator()
{
$codeGenFile = FileGenerator::fromReflectedFileName($this->getPath());
$codeGenFileClasses = $codeGenFile->getClasses();
$class = array_shift($codeGenFileClasses);
return $class;
}
示例7: testGeneratedClassesHaveUses
public function testGeneratedClassesHaveUses()
{
$generator = FileGenerator::fromReflectedFileName(__DIR__ . '/TestAsset/ClassWithUses.php');
$class = $generator->getClass();
$expectedUses = array('ZendTest\\Code\\Generator\\TestAsset\\ClassWithNamespace');
$this->assertEquals($expectedUses, $class->getUses());
}
示例8: removeBackslashes
public function removeBackslashes($path)
{
$generator = $this->fileGenerator->fromReflectedFileName($path);
$source = explode("\n", $generator->getSourceContent());
$tokens = token_get_all(file_get_contents($path));
}
示例9: patchExistingFile
/**
* This method tries to patch an existing type class.
*
* @param TypeGenerator $generator
* @param Type $type
* @param string $path
*
* @return bool
*/
protected function patchExistingFile(TypeGenerator $generator, Type $type, $path)
{
try {
$this->filesystem->createBackup($path);
$file = FileGenerator::fromReflectedFileName($path);
$this->generateType($file, $generator, $type, $path);
} catch (\Exception $e) {
$this->output->writeln('<fg=red>' . $e->getMessage() . '</fg=red>');
$this->filesystem->removeBackup($path);
return false;
}
return true;
}
示例10: getFiles
/**
*
* @return FileCollection
*/
public function getFiles(Settings $settings = NULL)
{
if (NULL !== $settings) {
$this->setSettings($settings);
}
if (null === $this->files) {
$reflections = parent::getFiles();
$files = [];
foreach ($reflections as $reflection) {
$files[] = \Zend\Code\Generator\FileGenerator::fromReflectedFileName($reflection->getName());
}
$this->setFiles(new FileCollection($files));
}
return $this->files;
}
示例11: setClientMethodDocblocks
/**
* @return array
*/
protected function setClientMethodDocblocks()
{
$client = new \SoapClient(__DIR__ . '/../../Resources/wsdl/services.wsdl');
$functions = $client->__getFunctions();
sort($functions);
$functions = array_map(function ($function) {
return preg_replace("~^[a-z]+\\s([a-z]+) ?\\(.+\\)\$~i", "\$1", $function);
}, $functions);
$exchangeWebServicesReflection = new ClassReflection(ExchangeWebServices::class);
$fileGen = Generator\FileGenerator::fromReflectedFileName($exchangeWebServicesReflection->getFileName());
$fileGen->setFilename($exchangeWebServicesReflection->getFileName());
$exchangeWebServicesClass = Generator\ClassGenerator::fromReflection($exchangeWebServicesReflection);
$docblock = $exchangeWebServicesClass->getDocBlock();
$reflection = new \ReflectionClass($docblock);
$property = $reflection->getProperty('tags');
$property->setAccessible(true);
$property->setValue($docblock, []);
$docblock->setWordWrap(false);
$tags = [];
$tags[] = new Generator\DocBlock\Tag\GenericTag('@package php-ews\\Client');
$tags[] = new EmptyDocblockTag();
foreach ($functions as $function) {
$tag = new MethodWIthRequestTag($function, ['Type']);
$tags[] = $tag;
}
$docblock->setTags($tags);
$exchangeWebServicesClass->getDocBlock()->setSourceDirty(true);
$fileGen->setClass($exchangeWebServicesClass);
$fileGen->write();
}
示例12: getClassTemplate
/**
* @return ClassGenerator
*/
protected function getClassTemplate() : ClassGenerator
{
return FileGenerator::fromReflectedFileName(__DIR__ . DIRECTORY_SEPARATOR . "templates" . DIRECTORY_SEPARATOR . "shared_proxy.php")->getClass("SharedProxy");
}
示例13: fileCreate
public function fileCreate($filename, $classGenerator)
{
if (file_exists($this->getFilePath())) {
$content = file_get_contents($this->getFilePath());
//Get protected code
$protectedPos = strpos($content, PROTECTED_ZONE);
$protectedCode = '';
if ($protectedPos !== false) {
$protectedCode = explode(PROTECTED_ZONE, $content);
$this->setProtectedCode($protectedCode[1]);
}
$generator = FileGenerator::fromReflectedFileName($this->getFilePath());
$generator->setClass($classGenerator);
$content = $generator->generate();
// Insert the protected code into the new string
$this->insertString($content, '}', $this->buildProtectedZone());
// print_r($content);exit;
} else {
$generator = new FileGenerator();
$generator->setClass($classGenerator);
$content = $generator->generate();
$this->insertString($content, '}', $this->buildProtectedZone());
}
$this->filePutContents($filename, $content);
}