/**
  * @param ResourceInterface $resource
  * @param array $data
  */
 public function generate(ResourceInterface $resource, array $data)
 {
     $filepath = $resource->getSrcFilename();
     if (!($content = $this->templates->render('private-constructor', array()))) {
         $content = $this->templates->renderString($this->getTemplate(), array());
     }
     $code = $this->filesystem->getFileContents($filepath);
     $code = $this->codeWriter->insertMethodFirstInClass($code, $content);
     $this->filesystem->putFileContents($filepath, $code);
     $this->io->writeln("<info>Private constructor has been created.</info>\n", 2);
 }
Esempio n. 2
0
 /**
  * @param string $methodName
  * @param string $snippetToInsert
  * @param string $code
  * @return string
  */
 private function getUpdatedCode($methodName, $snippetToInsert, $code)
 {
     if ('__construct' === $methodName) {
         return $this->codeWriter->insertMethodFirstInClass($code, $snippetToInsert);
     }
     return $this->codeWriter->insertMethodLastInClass($code, $snippetToInsert);
 }
 /**
  * @param string $code
  * @param string $method
  * @return string
  */
 private function appendMethodToCode($code, $method)
 {
     try {
         return $this->codeWriter->insertAfterMethod($code, '__construct', $method);
     } catch (NamedMethodNotFoundException $e) {
         return $this->codeWriter->insertMethodFirstInClass($code, $method);
     }
 }