Inheritance: extends Nette\Object
 /**
  * @param string $fileName
  * @return string
  */
 public function getRelativePath($fileName)
 {
     foreach ($this->configuration->getOption(CO::SOURCE) as $directory) {
         if (strpos($fileName, $directory) === 0) {
             return $this->getFileNameWithoutSourcePath($fileName, $directory);
         }
     }
     throw new InvalidArgumentException(sprintf('Could not determine "%s" relative path', $fileName));
 }
 public function generate()
 {
     $annotations = $this->configuration->getOption(CO::ANNOTATION_GROUPS);
     foreach ($annotations as $annotation) {
         $template = $this->templateFactory->createNamedForElement(TemplateFactory::ELEMENT_ANNOTATION_GROUP, $annotation);
         $template = $this->setElementsWithAnnotationToTemplate($template, $annotation);
         $template->save();
     }
 }
 /**
  * @return array
  */
 private function getParameters()
 {
     if ($this->parameters === null) {
         $parameters = ['annotationGroups' => $this->configuration->getOption(CO::ANNOTATION_GROUPS), 'namespace' => null, 'package' => null, 'class' => null, 'constant' => null, 'function' => null, 'namespaces' => array_keys($this->elementStorage->getNamespaces()), 'packages' => array_keys($this->elementStorage->getPackages()), 'classes' => array_filter($this->elementStorage->getClasses(), $this->getMainFilter()), 'interfaces' => array_filter($this->elementStorage->getInterfaces(), $this->getMainFilter()), 'traits' => array_filter($this->elementStorage->getTraits(), $this->getMainFilter()), 'exceptions' => array_filter($this->elementStorage->getExceptions(), $this->getMainFilter()), 'constants' => array_filter($this->elementStorage->getConstants(), $this->getMainFilter()), 'functions' => array_filter($this->elementStorage->getFunctions(), $this->getMainFilter()), 'elements' => $this->autocompleteElements->getElements()];
         if ($this->configuration->getOption(CO::DOWNLOAD)) {
             $parameters['archive'] = basename($this->configuration->getZipFileName());
         }
         $this->parameters = $parameters;
     }
     return $this->parameters;
 }
 /**
  * @return array
  */
 public function annotationFilter(array $annotations, array $customToRemove = [])
 {
     $annotations = $this->filterOut($annotations, $this->remove);
     $annotations = $this->filterOut($annotations, $customToRemove);
     if (!$this->configuration->getOption(CO::INTERNAL)) {
         unset($annotations['internal']);
     }
     if (!$this->configuration->getOption(CO::TODO)) {
         unset($annotations['todo']);
     }
     return $annotations;
 }
 /**
  * @return array
  */
 public function sort(array $groups)
 {
     if ($this->isNoneGroupOnly($groups)) {
         return [];
     }
     $this->groups = $groups;
     $groupNames = array_keys($groups);
     $this->lowercasedGroupNames = $this->convertGroupNamesToLower($groupNames);
     foreach ($groupNames as $groupName) {
         $this->addMissingParentGroups($groupName);
         $this->addMissingElementTypes($groupName);
     }
     uksort($this->groups, function ($one, $two) {
         return $this->compareGroups($one, $two, $this->configuration->getOption(CO::MAIN));
     });
     return $this->groups;
 }
Exemple #6
0
 /**
  * @return array
  */
 private function prepareOptions(array $cliOptions)
 {
     $options = $this->convertDashKeysToCamel($cliOptions);
     $options = $this->loadOptionsFromConfig($options);
     $this->warnAboutDeprecatedOptions($options);
     $options = $this->unsetDeprecatedOptions($options);
     return $this->configuration->resolveOptions($options);
 }
Exemple #7
0
 /**
  * @param string $destination
  */
 public function copyToDestination($destination)
 {
     $resources = $this->configuration->getOption(CO::TEMPLATE)['resources'];
     foreach ($resources as $resourceSource => $resourceDestination) {
         // File
         if (is_file($resourceSource)) {
             copy($resourceSource, $this->fileSystem->forceDir($destination . '/' . $resourceDestination));
             continue;
         }
         // Dir
         /** @var RecursiveDirectoryIterator $iterator */
         $iterator = Finder::findFiles('*')->from($resourceSource)->getIterator();
         foreach ($iterator as $item) {
             /** @var SplFileInfo $item */
             copy($item->getPathName(), $this->fileSystem->forceDir($destination . '/' . $resourceDestination . '/' . $iterator->getSubPathName()));
         }
     }
 }
 /**
  * @return Template
  */
 private function buildTemplate()
 {
     if ($this->builtTemplate === NULL) {
         $options = $this->configuration->getOptions();
         $template = new Template($this->latteEngine);
         $template->setParameters(['config' => ArrayHash::from($options), 'basePath' => $options[CO::TEMPLATE][TCO::TEMPLATES_PATH]]);
         $this->builtTemplate = $template;
     }
     return $this->templateElementsLoader->addElementsToTemplate($this->builtTemplate);
 }
 /**
  * @return array
  */
 private function prepareOptions(array $cliOptions)
 {
     $cliOptions = $this->convertDashKeysToCamel($cliOptions);
     $configFile = $cliOptions[CO::CONFIG];
     $options = $cliOptions;
     if (file_exists($configFile)) {
         // get reader by file extension
         $configFileOptions = ConfigurationReader::getReader($configFile)->read();
         $options = array_merge($options, $configFileOptions);
     }
     return $this->configuration->resolveOptions($options);
 }
Exemple #10
0
 /**
  * @param string $text
  * @return string
  */
 private function resolveInternalAnnotation($text)
 {
     $pattern = '~\\{@(\\w+)(?:(?:\\s+((?>(?R)|[^{}]+)*)\\})|\\})~';
     return preg_replace_callback($pattern, function ($matches) {
         if ($matches[1] !== 'internal') {
             return $matches[0];
         }
         if ($this->configuration->getOption(CO::INTERNAL) && isset($matches[2])) {
             return $matches[2];
         }
         return '';
     }, $text);
 }
 /**
  * @param ReflectionElement|ReflectionConstant $element
  * @param bool $withLine Include file line number into the link
  * @return string
  */
 public function sourceUrl(ReflectionElement $element, $withLine = TRUE)
 {
     $file = '';
     if ($this->isDirectUrl($element)) {
         $elementName = $element->getName();
         if ($element instanceof ReflectionClass) {
             $file = 'class-';
         } elseif ($element instanceof ReflectionConstant) {
             $file = 'constant-';
         } elseif ($element instanceof ReflectionFunction) {
             $file = 'function-';
         }
     } else {
         $elementName = $element->getDeclaringClassName();
         $file = 'class-';
     }
     $file .= $this->urlize($elementName);
     $url = sprintf($this->configuration->getOption(CO::TEMPLATE)['templates']['source']['filename'], $file);
     if ($withLine) {
         $url .= $this->getElementLinesAnchor($element);
     }
     return $url;
 }
 private function sortNamespacesAndPackages()
 {
     $areNamespacesEnabled = $this->configuration->areNamespacesEnabled($this->getNamespaceCount(), $this->getPackageCount());
     $arePackagesEnabled = $this->configuration->arePackagesEnabled($areNamespacesEnabled);
     if ($areNamespacesEnabled) {
         $this->namespaces = $this->groupSorter->sort($this->namespaces);
         $this->packages = [];
     } elseif ($arePackagesEnabled) {
         $this->namespaces = [];
         $this->packages = $this->groupSorter->sort($this->packages);
     } else {
         $this->namespaces = [];
         $this->packages = [];
     }
 }
 /**
  * @param string $name
  * @return string
  */
 public function namespaceUrl($name)
 {
     return sprintf($this->configuration->getOption(CO::TEMPLATE)['templates']['namespace']['filename'], $this->urlize($name));
 }
 /**
  * {@inheritdoc}
  */
 public function isAllowed()
 {
     return (bool) $this->configuration->getOption(CO::DOWNLOAD);
 }
 /**
  * @return string
  */
 private function getDestination()
 {
     return $this->configuration->getOption(CO::DESTINATION);
 }
 /**
  * @return bool
  */
 public function isAllowed()
 {
     return (bool) $this->configuration->getOption(CO::BASE_URL);
 }
 /**
  * {@inheritdoc}
  */
 public function isAllowed()
 {
     $options = $this->configuration->getOptions();
     return $options[CO::GOOGLE_CSE_ID] && $options[CO::BASE_URL];
 }
 /**
  * {@inheritdoc}
  */
 public function isAllowed()
 {
     return $this->configuration->getOption(CO::SOURCE_CODE);
 }
Exemple #19
0
 /**
  * {@inheritdoc}
  */
 public function isAllowed()
 {
     return $this->configuration->getOption(CO::TREE);
 }
 /**
  * @param string $name
  * @return string
  */
 public function createForAnnotationGroup($name)
 {
     return sprintf($this->configuration->getOption(CO::TEMPLATE)['templates'][TCO::ANNOTATION_GROUP]['filename'], Filters::urlize($name));
 }