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());
 }
 /**
  * @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;
 }
 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
0
 /**
  * @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
0
 /**
  * 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
0
 /**
  * getCodeGenerator()
  *
  * @return \Zend\Code\Generator\FileGenerator
  */
 public function getCodeGenerator()
 {
     $codeGenFile = FileGenerator::fromReflectedFileName($this->getPath());
     $codeGenFileClasses = $codeGenFile->getClasses();
     $class = array_shift($codeGenFileClasses);
     return $class;
 }
Пример #7
0
 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
0
 public function removeBackslashes($path)
 {
     $generator = $this->fileGenerator->fromReflectedFileName($path);
     $source = explode("\n", $generator->getSourceContent());
     $tokens = token_get_all(file_get_contents($path));
 }
Пример #9
0
 /**
  * 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
0
 /**
  *
  * @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
0
 /**
  * @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();
 }
 /**
  * @return ClassGenerator
  */
 protected function getClassTemplate() : ClassGenerator
 {
     return FileGenerator::fromReflectedFileName(__DIR__ . DIRECTORY_SEPARATOR . "templates" . DIRECTORY_SEPARATOR . "shared_proxy.php")->getClass("SharedProxy");
 }
 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);
 }