private function getCurrentConfigXml($moduleName) { if (!$this->moduleFileExists($moduleName)) { $values = array('%module_name%' => $moduleName); return strtr(file_get_contents(__DIR__ . '/templates/config.template'), $values); } return $this->filesystem->getFileContents($this->getFilePath()); }
/** * @param string $name * @param array $values * * @return string */ public function render($name, array $values = array()) { foreach ($this->locations as $location) { $path = $location . DIRECTORY_SEPARATOR . $this->normalizeLocation($name, true) . '.tpl'; if ($this->filesystem->pathExists($path)) { return $this->renderString($this->filesystem->getFileContents($path), $values); } } }
/** * @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 = 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 = $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) { $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); }
/** * @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); }
/** * @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); }
private function findSpecClassname($path) { // Find namespace and class name $namespace = ''; $content = $this->filesystem->getFileContents($path); $tokens = token_get_all($content); $count = count($tokens); for ($i = 0; $i < $count; $i++) { if ($tokens[$i][0] === T_NAMESPACE) { for ($j = $i + 1; $j < $count; $j++) { if ($tokens[$j][0] === T_STRING) { $namespace .= $tokens[$j][1] . '\\'; } elseif ($tokens[$j] === '{' || $tokens[$j] === ';') { break; } } } if ($tokens[$i][0] === T_CLASS) { for ($j = $i + 1; $j < $count; $j++) { if ($tokens[$j] === '{') { return $namespace . $tokens[$i + 2][1]; } } } } // No class found return null; }
/** * @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); }