putFileContents() public method

public putFileContents ( string $path, string $content )
$path string
$content string
 /**
  * @param ResourceInterface $resource
  * @param array             $data
  */
 public function generate(ResourceInterface $resource, array $data = array())
 {
     $filepath = $resource->getSrcFilename();
     $methodName = $data['name'];
     $arguments = $data['arguments'];
     $content = $this->getContent($resource, $methodName, $arguments);
     $code = $this->appendMethodToCode($this->filesystem->getFileContents($filepath), $content);
     $this->filesystem->putFileContents($filepath, $code);
     $this->io->writeln(sprintf("<info>Method <value>%s::%s()</value> has been created.</info>\n", $resource->getSrcClassname(), $methodName), 2);
 }
 /**
  * @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);
 }
 /**
  * @param ResourceInterface $resource
  * @param array             $data
  */
 public function generate(ResourceInterface $resource, array $data = array())
 {
     $filepath = $resource->getSrcFilename();
     $methodName = $data['name'];
     $arguments = $data['arguments'];
     $content = $this->getContent($resource, $methodName, $arguments);
     $code = $this->filesystem->getFileContents($filepath);
     $code = preg_replace('/}[ \\n]*$/', rtrim($content) . "\n}\n", trim($code));
     $this->filesystem->putFileContents($filepath, $code);
     $this->io->writeln(sprintf("\n<info>Method <value>%s::%s()</value> has been created.</info>", $resource->getSrcClassname(), $methodName), 2);
 }
 /**
  * @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 = preg_replace('/}[ \\n]*$/', rtrim($content) . "\n}\n", trim($code));
     $this->filesystem->putFileContents($filepath, $code);
     $this->io->writeln("<info>Private constructor has been created.</info>\n", 2);
 }
示例#5
0
 public function generate($moduleName)
 {
     if ($this->moduleFileExists($moduleName)) {
         return;
     }
     $values = array('%module_name%' => $moduleName, '%code_pool%' => $this->codePool);
     if (!$this->fileSystem->pathExists($this->path)) {
         $this->fileSystem->makeDirectory($this->path);
     }
     $this->fileSystem->putFileContents($this->getFilePath($moduleName), strtr(file_get_contents(__DIR__ . '/templates/module.template'), $values));
 }
示例#6
0
 /**
  * @param ResourceInterface $resource
  * @param array             $data
  */
 public function generate(ResourceInterface $resource, array $data = array())
 {
     $filepath = $resource->getSrcFilename();
     $name = $data['name'];
     $arguments = $data['arguments'];
     $argString = count($arguments) ? '$argument' . implode(', $argument', range(1, count($arguments))) : '';
     $values = array('%name%' => $name, '%arguments%' => $argString);
     if (!($content = $this->templates->render('method', $values))) {
         $content = $this->templates->renderString($this->getTemplate(), $values);
     }
     $code = $this->filesystem->getFileContents($filepath);
     $this->filesystem->putFileContents($filepath, $this->getUpdatedCode($name, $content, $code));
     $this->io->writeln(sprintf("<info>Method <value>%s::%s()</value> has been created.</info>\n", $resource->getSrcClassname(), $name), 2);
 }
示例#7
0
 /**
  * @param ResourceInterface $resource
  * @param array $data
  */
 public function generate(ResourceInterface $resource, array $data)
 {
     $destination = $this->getSavePath($resource);
     if (file_exists($destination) && !$this->io->askConfirmation(sprintf('File "%s" already exists. Overwrite?', basename($destination)), false)) {
         return;
     }
     $directory = dirname($destination);
     if (!file_exists($directory)) {
         $this->createDir($directory);
     }
     $code = $this->generateCodeForResource($resource, $data);
     $this->filesystem->putFileContents($destination, $code);
     $this->io->writeln($this->getPromptMessage($resource, $resource->getSrcFilename()));
 }
 /**
  * @param ResourceInterface $resource
  * @param array $data
  */
 public function generate(ResourceInterface $resource, array $data)
 {
     $method = $data['method'];
     $expected = $data['expected'];
     $code = $this->filesystem->getFileContents($resource->getSrcFilename());
     $values = array('%constant%' => var_export($expected, true));
     if (!($content = $this->templates->render('method', $values))) {
         $content = $this->templates->renderString($this->getTemplate(), $values);
     }
     $pattern = '/' . '(function\\s+' . preg_quote($method, '/') . '\\s*\\([^\\)]*\\))\\s+{[^}]*?}/';
     $replacement = '$1' . $content;
     $modifiedCode = preg_replace($pattern, $replacement, $code);
     $this->filesystem->putFileContents($resource->getSrcFilename(), $modifiedCode);
     $this->io->writeln(sprintf("\n<info>Method <value>%s::%s()</value> has been modified.</info>", $resource->getSrcClassname(), $method), 2);
 }
 /**
  * @param Resource $resource
  * @param array $data
  *
  * @return mixed
  */
 public function generate(Resource $resource, array $data = array())
 {
     $filepath = $resource->getSrcFilename();
     $name = $data['name'];
     $arguments = $data['arguments'];
     $argString = $this->argumentBuilder->buildFrom($arguments);
     $values = array('%name%' => $name, '%arguments%' => $argString);
     if (!($content = $this->templates->render('method', $values))) {
         $content = $this->templates->renderString($this->getTemplate(), $values);
     }
     $code = $this->filesystem->getFileContents($filepath);
     $code = preg_replace('/}[ \\n]*$/', rtrim($content) . "\n}\n", trim($code));
     $this->filesystem->putFileContents($filepath, $code);
     $this->io->writeln(sprintf("\n<info>Method <value>%s::%s()</value> has been created.</info>", $resource->getSrcClassname(), $name), 2);
 }
示例#10
0
 /**
  * @param string $xml
  */
 private function writeConfigFile($xml)
 {
     if (!$this->filesystem->isDirectory($this->directory)) {
         $this->filesystem->makeDirectory($this->directory);
     }
     $this->filesystem->putFileContents($this->getFilePath(), $xml);
 }
示例#11
0
 /**
  * @param ResourceInterface $resource
  * @param string            $filepath
  */
 private function generateFileAndRenderTemplate(ResourceInterface $resource, $filepath)
 {
     $content = $this->renderTemplate($resource, $filepath);
     $this->filesystem->putFileContents($filepath, $content);
     $this->io->writeln($this->getGeneratedMessage($resource, $filepath));
 }
 /**
  * @param string $filepath
  * @param string $content
  */
 private function insertMethodSignature($filepath, $content)
 {
     $code = $this->filesystem->getFileContents($filepath);
     $code = preg_replace('/}[ \\n]*$/', rtrim($content) . "\n}\n", trim($code));
     $this->filesystem->putFileContents($filepath, $code);
 }