当前位置: 首页>>代码示例>>PHP>>正文


PHP ResourceInterface::getSrcFilename方法代码示例

本文整理汇总了PHP中PhpSpec\Locator\ResourceInterface::getSrcFilename方法的典型用法代码示例。如果您正苦于以下问题:PHP ResourceInterface::getSrcFilename方法的具体用法?PHP ResourceInterface::getSrcFilename怎么用?PHP ResourceInterface::getSrcFilename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PhpSpec\Locator\ResourceInterface的用法示例。


在下文中一共展示了ResourceInterface::getSrcFilename方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generate

 /**
  * @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);
 }
开发者ID:franzliedke,项目名称:phpspec,代码行数:19,代码来源:ReturnConstantGenerator.php

示例2: array

    function it_generates_class_method_from_resource($io, $tpl, $fs, ResourceInterface $resource)
    {
        $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');
        $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')));
    }
开发者ID:edwardricardo,项目名称:zenska,代码行数:32,代码来源:MethodGeneratorSpec.php

示例3: array

 function it_should_not_dispatch_an_event_if_the_file_already_existed($dispatcher, $filesystem, ResourceInterface $resource)
 {
     $path = '/foo';
     $resource->getSrcFilename()->willReturn($path);
     $filesystem->pathExists($path)->willReturn(true);
     $this->generate($resource, array());
     $dispatcher->dispatch('afterFileCreation', Argument::any())->shouldNotHaveBeenCalled();
 }
开发者ID:focuslife,项目名称:v0.1,代码行数:8,代码来源:NewFileNotifyingGeneratorSpec.php

示例4: generate

 /**
  * @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);
 }
开发者ID:focuslife,项目名称:v0.1,代码行数:14,代码来源:NamedConstructorGenerator.php

示例5: generate

 /**
  * @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);
 }
开发者ID:franzliedke,项目名称:phpspec,代码行数:15,代码来源:NamedConstructorGenerator.php

示例6:

 function it_asks_confirmation_if_class_already_exists($io, $tpl, $fs, ResourceInterface $resource)
 {
     $resource->getName()->willReturn('App');
     $resource->getSrcFilename()->willReturn('/project/src/Acme/App.php');
     $resource->getSrcNamespace()->willReturn('Acme');
     $resource->getSrcClassname()->willReturn('Acme\\App');
     $fs->pathExists('/project/src/Acme/App.php')->willReturn(true);
     $io->askConfirmation(Argument::type('string'), false)->willReturn(false);
     $fs->putFileContents(Argument::cetera())->shouldNotBeCalled();
     $this->generate($resource);
 }
开发者ID:kpaxer,项目名称:shcms,代码行数:11,代码来源:ClassGeneratorSpec.php

示例7: generate

 /**
  * @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);
 }
开发者ID:araines,项目名称:phpspec,代码行数:15,代码来源:PrivateConstructorGenerator.php

示例8: generate

 /**
  * @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);
 }
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:15,代码来源:PrivateConstructorGenerator.php

示例9: generateCodeForResource

 protected function generateCodeForResource(ResourceInterface $resource, array $data)
 {
     $structure = Object::make($resource->getSrcClassname());
     $structure->makeFinal();
     $handle = Method::make('handle');
     $handle->addArgument(Argument::make($data['handles'], 'command'));
     $handle->setBody("        // TODO write your own implementation");
     $structure->addMethod($handle);
     $file = File::make($resource->getSrcFilename())->setStructure($structure);
     $prettyPrinter = Build::prettyPrinter();
     return $prettyPrinter->generateCode($file);
 }
开发者ID:ulabox,项目名称:bus-spec,代码行数:12,代码来源:HandlerGenerator.php

示例10: generate

 /**
  * @param ResourceInterface $resource
  * @param array $data
  */
 public function generate(ResourceInterface $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);
 }
开发者ID:edwardricardo,项目名称:zenska,代码行数:17,代码来源:MethodSignatureGenerator.php

示例11: generate

 /**
  * @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);
 }
开发者ID:focuslife,项目名称:v0.1,代码行数:18,代码来源:MethodGenerator.php

示例12: generate

 /**
  * @param ResourceInterface $resource
  * @param array $data
  *
  * @return mixed
  */
 public function generate(ResourceInterface $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);
 }
开发者ID:amir20202000,项目名称:phpspec-typehintedmethods,代码行数:21,代码来源:TypeHintedMethodGenerator.php

示例13: it_stages_files_created_as_a_result_of_delegation_of_generation

 public function it_stages_files_created_as_a_result_of_delegation_of_generation($delegate, ResourceInterface $resource, $filesystem, $repository)
 {
     $srcFilePath = '/foo/bar.php';
     $specFilePath = '/foo/barspec.php';
     $resource->getSrcFilename()->willReturn($srcFilePath);
     $resource->getSpecFilename()->willReturn($specFilePath);
     $filesystem->pathExists($srcFilePath)->willReturn(false);
     $filesystem->pathExists($specFilePath)->willReturn(true);
     $delegate->generate(Argument::cetera())->will(function () use($filesystem, $srcFilePath) {
         $filesystem->pathExists($srcFilePath)->willReturn(true);
     });
     $this->generate($resource, []);
     $repository->stageFile($srcFilePath)->shouldHaveBeenCalled();
     $repository->stageFile($specFilePath)->shouldNotHaveBeenCalled();
 }
开发者ID:nick-jones,项目名称:phpspec-git-extension,代码行数:15,代码来源:GitAddingGeneratorSpec.php

示例14: generate

 public function generate(ResourceInterface $resource, array $data = array())
 {
     $filepath = $resource->getSrcFilename();
     if ($this->filesystem->pathExists($filepath)) {
         $message = sprintf('File "%s" already exists. Overwrite?', basename($filepath));
         if (!$this->io->askConfirmation($message, false)) {
             return;
         }
         $this->io->writeln();
     }
     $path = dirname($filepath);
     if (!$this->filesystem->isDirectory($path)) {
         $this->filesystem->makeDirectory($path);
     }
     $values = array('%filepath%' => $filepath, '%name%' => $resource->getName(), '%namespace%' => $resource->getSrcNamespace(), '%namespace_block%' => '' !== $resource->getSrcNamespace() ? sprintf("\n\nnamespace %s;", $resource->getSrcNamespace()) : '');
     if (!($content = $this->templates->render('wp_class', $values))) {
         $content = $this->templates->renderString(file_get_contents(__DIR__ . '/templates/generic_class.template'), $values);
     }
     $this->filesystem->putFileContents($filepath, $content);
     $this->io->writeln(sprintf("<info>WP class <value>%s</value> created in <value>'%s'</value>.</info>\n", $resource->getSrcClassname(), $filepath));
 }
开发者ID:sourcerer-mike,项目名称:phpspec-wordpress,代码行数:21,代码来源:WpGenerator.php

示例15: generateCodeForResource

    protected function generateCodeForResource(ResourceInterface $resource, array $data)
    {
        $structure = Object::make($resource->getSrcClassname());
        $structure->makeFinal();
        $construct = Method::make('__construct');
        $structure->addMethod($construct);
        $constructBody = [];
        foreach ($data['params'] as $param) {
            $structure->addProperty(Property::make($param));
            $body = <<<METHOD
        return \$this->{$param};
METHOD;
            $construct->addArgument(Argument::make('mixed', $param));
            $constructBody[] = "        \$this->{$param} = \${$param};";
            $method = Method::make($param)->setBody($body);
            $structure->addMethod($method);
        }
        $construct->setBody(implode("\n", $constructBody));
        $file = File::make($resource->getSrcFilename())->setStructure($structure);
        $prettyPrinter = Build::prettyPrinter();
        return $prettyPrinter->generateCode($file);
    }
开发者ID:ulabox,项目名称:bus-spec,代码行数:22,代码来源:CommandGenerator.php


注:本文中的PhpSpec\Locator\ResourceInterface::getSrcFilename方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。