Пример #1
0
 /**
  * Attempts to find the example contents for the given descriptor.
  *
  * @param ExampleDescriptor $descriptor
  *
  * @return string
  */
 public function find(ExampleDescriptor $descriptor)
 {
     $filename = $descriptor->getFilePath();
     $file = $this->getExampleFileContents($filename);
     if (!$file) {
         return "** File not found : {$filename} **";
     }
     return implode('', array_slice($file, $descriptor->getStartingLine() - 1, $descriptor->getLineCount()));
 }
Пример #2
0
 /**
  * Creates a new Descriptor from the given Reflector.
  *
  * @param ExampleTag $data
  *
  * @throws \InvalidArgumentException if the provided parameter is not of type ExampleTag; the interface won't let
  *   up typehint the signature.
  *
  * @return ExampleDescriptor
  */
 public function create($data)
 {
     if (!$data instanceof ExampleTag) {
         throw new \InvalidArgumentException('The ExampleAssembler expected an ExampleTag object to base the descriptor on');
     }
     $descriptor = new ExampleDescriptor($data->getName());
     $descriptor->setFilePath((string) $data->getFilePath());
     $descriptor->setStartingLine($data->getStartingLine());
     $descriptor->setLineCount($data->getLineCount());
     $descriptor->setDescription($data->getDescription());
     $descriptor->setExample($this->finder->find($descriptor));
     return $descriptor;
 }
Пример #3
0
 /**
  * Returns an ExampleDescriptor with the given filename set.
  *
  * @param string $path
  *
  * @return ExampleDescriptor
  */
 private function givenADescriptorWithExamplePath($path)
 {
     $descriptor = new ExampleDescriptor('example');
     $descriptor->setFilePath($path);
     return $descriptor;
 }