getSrcFilename() public méthode

public getSrcFilename ( ) : string
Résultat string
 /**
  * @param Resource $resource
  * @param array             $data
  */
 public function generate(Resource $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("<info>Method <value>%s::%s()</value> has been modified.</info>\n", $resource->getSrcClassname(), $method), 2);
 }
    function it_generates_class_method_from_resource($io, $tpl, $fs, Resource $resource, CodeWriter $codeWriter)
    {
        $codeWithoutMethod = <<<CODE
<?php

namespace Acme;

class App
{
}

CODE;
        $codeWithMethod = <<<CODE
<?php

namespace Acme;

class App
{
METHOD
}

CODE;
        $values = array('%name%' => 'setName', '%arguments%' => '$argument1');
        $resource->getSrcFilename()->willReturn('/project/src/Acme/App.php');
        $resource->getSrcClassname()->willReturn('Acme\\App');
        $tpl->render('method', $values)->willReturn(null);
        $tpl->renderString(Argument::type('string'), $values)->willReturn('METHOD');
        $codeWriter->insertMethodLastInClass($codeWithoutMethod, 'METHOD')->willReturn($codeWithMethod);
        $fs->getFileContents('/project/src/Acme/App.php')->willReturn($codeWithoutMethod);
        $fs->putFileContents('/project/src/Acme/App.php', $codeWithMethod)->shouldBeCalled();
        $this->generate($resource, array('name' => 'setName', 'arguments' => array('everzet')));
    }
    function it_generates_static_constructor_method_from_resource($io, $tpl, $fs, Resource $resource, CodeWriter $codeWriter)
    {
        $codeWithoutMethod = <<<CODE
<?php

namespace Acme;

class App
{
}

CODE;
        $codeWithMethod = <<<CODE
<?php

namespace Acme;

class App
{
METHOD
}

CODE;
        $values = array('%methodName%' => 'setName', '%arguments%' => '$argument1', '%returnVar%' => '$app', '%className%' => 'App', '%constructorArguments%' => '');
        $resource->getSrcFilename()->willReturn('/project/src/Acme/App.php');
        $resource->getSrcClassname()->willReturn('Acme\\App');
        $resource->getName()->willReturn('App');
        $tpl->render('named_constructor_create_object', $values)->willReturn(null);
        $tpl->renderString(Argument::type('string'), $values)->willReturn('METHOD');
        $codeWriter->insertAfterMethod($codeWithoutMethod, '__construct', 'METHOD')->willReturn($codeWithMethod);
        $fs->getFileContents('/project/src/Acme/App.php')->willReturn($codeWithoutMethod);
        $fs->putFileContents('/project/src/Acme/App.php', $codeWithMethod)->shouldBeCalled();
        $this->generate($resource, array('name' => 'setName', 'arguments' => array('jmurphy')));
    }
 function it_should_not_dispatch_an_event_if_the_file_already_existed($dispatcher, $filesystem, Resource $resource)
 {
     $path = '/foo';
     $resource->getSrcFilename()->willReturn($path);
     $filesystem->pathExists($path)->willReturn(true);
     $this->generate($resource, array());
     $dispatcher->dispatch('afterFileCreation', Argument::any())->shouldNotHaveBeenCalled();
 }
 function it_calls_the_command_bus(CommandBus $commandBus, Resource $resource)
 {
     $resource->getSrcFilename()->willReturn(self::FILE_NAME);
     $resource->getSrcNamespace()->willReturn(self::NAME_SPACE);
     $resource->getSrcClassname()->willReturn(self::CLASS_NAME);
     $data = ['name' => self::METHOD_NAME, 'arguments' => []];
     $command = Argument::type(GenerateConstructor::class);
     $commandBus->handle($command)->shouldbeCalled();
     $this->generate($resource, $data);
 }
 /**
  * @param Resource $resource
  * @param array             $data
  */
 public function generate(Resource $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 Resource $resource
  * @param array $data
  */
 public function generate(Resource $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 Resource $resource
  * @param array             $data
  */
 public function generate(Resource $resource, array $data = array())
 {
     $filepath = $resource->getSrcFilename();
     $name = $data['name'];
     $arguments = $data['arguments'];
     $argString = $this->buildArgumentString($arguments);
     $values = array('%name%' => $name, '%arguments%' => $argString);
     if (!($content = $this->templates->render('interface-method-signature', $values))) {
         $content = $this->templates->renderString($this->getTemplate(), $values);
     }
     $this->insertMethodSignature($filepath, $content);
     $this->io->writeln(sprintf("<info>Method signature <value>%s::%s()</value> has been created.</info>\n", $resource->getSrcClassname(), $name), 2);
 }
Exemple #9
0
 /**
  * @param Resource $resource
  * @param array             $data
  */
 public function generate(Resource $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 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);
 }
Exemple #11
0
 /**
  * @param Resource $resource
  *
  * @return string
  */
 protected function getFilePath(Resource $resource)
 {
     return $resource->getSrcFilename();
 }
 function it_records_that_class_was_created_in_executioncontext(Resource $resource, ExecutionContext $executionContext)
 {
     $resource->getName()->willReturn('App');
     $resource->getSrcFilename()->willReturn('/project/src/Acme/App.php');
     $resource->getSrcNamespace()->willReturn('Acme');
     $resource->getSrcClassname()->willReturn('Acme\\App');
     $this->generate($resource);
     $executionContext->addGeneratedType('Acme\\App')->shouldHaveBeenCalled();
 }
Exemple #13
0
 public function generate(Resource $resource, array $data = [])
 {
     $generateMethod = new GenerateMethod($resource->getSrcFilename(), $resource->getSrcClassName(), $data['name'], $data['arguments']);
     $this->commandBus->handle($generateMethod);
 }