/**
  * @URL package	 
  * @Get
  * @param string $name
  * @param string $version
  */
 public function index($name, $version = null)
 {
     if ($version != null) {
         $package = $this->packageDao->get($name, $version);
     } else {
         $package = $this->packageDao->getLatestPackage($name);
         if (isset($package['packageVersion'])) {
             $version = $package['packageVersion'];
         }
     }
     if (!$package) {
         header("HTTP/1.0 404 Not Found");
         $this->content->addHtmlElement(new TwigTemplate($this->twig, 'src/views/packageAnalyzer/404.twig', array("packageName" => $name, "packageVersion" => $version)));
         $this->template->toHtml();
         return;
     }
     $allPackages = $this->packageDao->getPackagesByName($name);
     $otherVersions = [];
     foreach ($allPackages as $package2) {
         if ($package2['packageVersion'] != $version) {
             $otherVersions[] = $package2['packageVersion'];
         }
     }
     $itemsList = $this->itemDao->findItemsByPackageVersion($name, $version);
     // Let's sort alphabetically.
     $itemsList->sort(['name' => 1]);
     $this->template->setTitle('Packanalyst | Package ' . $name . ' (' . $version . ')');
     \Mouf::getSearchBlock()->setSearch($name);
     // Let's add the twig file to the template.
     $this->content->addHtmlElement(new TwigTemplate($this->twig, 'src/views/packageAnalyzer/index.twig', array("package" => $package, "itemsList" => $itemsList, "otherVersions" => $otherVersions)));
     $this->template->toHtml();
 }
    /**
     * @URL /
     */
    public function index() {
        // TODO: write content of action here

        // Let's add the twig file to the template.
        $this->content->addHtmlElement(new TwigTemplate($this->twig, 'views/root/index.twig', array("message"=>"world")));

        return new HtmlResponse($this->template);
    }
Beispiel #3
0
 /**
  * @URL /search
  * @param string $q The query string
  */
 public function search($q, $page = 0)
 {
     // If query is a valid item of package, let's go to the dedicated page.
     $item = $this->itemDao->getItemsByName($q);
     if ($item->count() != 0) {
         header("Location: " . ROOT_URL . "class?q=" . urlencode($q));
         return;
     }
     $package = $this->packageDao->getLatestPackage($q);
     if ($package != null) {
         // Let's grab the first
         header("Location: " . ROOT_URL . "package?name=" . urlencode($q) . "&version=" . $package['packageVersion']);
         return;
     }
     $searchResults = $this->elasticSearchService->suggestItemName2($q, 50, $page * 50);
     $totalCount = $searchResults['total'];
     $hits = $searchResults['hits'];
     $nbPages = floor($totalCount / 50);
     $this->template->setTitle('Packanalyst | Search results for ' . $q);
     \Mouf::getSearchBlock()->setSearch($q);
     $this->content->addHtmlElement(new TwigTemplate($this->twig, 'src/views/root/search.twig', array("searchResults" => $hits, "totalCount" => $totalCount, "query" => $q, "nbPages" => $nbPages, "page" => $page)));
     $this->template->toHtml();
 }
 /**
  * This page is for a user profil.
  *
  * @Logged
  * @URL /profil
  */
 public function profil()
 {
     $user = $this->userService->getLoggedUser();
     $this->content->addHtmlElement(new TwigTemplate($this->twig, 'views/profil/profil.twig', array('user' => $user)));
     $this->template->toHtml();
 }
 /**
  * @URL /
  */
 public function index()
 {
     // Let's add the twig file to the template.
     $this->content->addHtmlElement(new TwigTemplate($this->twig, 'views/root/index.twig'));
     return new HtmlResponse($this->template);
 }
 /**
  * Returns the list of classes/interfaces/traits that inherits/extends the class/interface/trait passed
  * in parameter.
  * Result is returned as a JSON result.
  * 
  * @URL api/v1/inherits
  * @Get
  * @param string $q
  */
 public function inherits($q)
 {
     // Remove front \
     $q = ltrim($q, '\\');
     $graphItems = $this->findItemsInheriting($q);
     $rootNodesCollection = $this->itemDao->getItemsByName($q);
     // If there is no root node (for instance if the class is "Exception")
     if ($rootNodesCollection->count() == 0) {
         // If this class has never been used, we might want to wonder if the class exists at all.
         if (count($graphItems) == 0) {
             // Let's go on a 404.
             return new JsonResponse(["status" => "error", "message" => "Item '{$q}' does not exist."], 404);
         }
         $rootNodes = [["name" => $q]];
     } else {
         $rootNodes = [];
         foreach ($rootNodesCollection as $key => $item) {
             $rootNodes[$key] = $item;
             $packageName = $item['packageName'];
             if (!isset($this->packagesCache[$packageName])) {
                 $this->packagesCache[$packageName] = $this->packageDao->getPackagesByName($packageName)->getNext();
             }
             $rootNodes[$key]['package'] = $this->packagesCache[$packageName];
         }
     }
     $graph = new Graph($rootNodes, $graphItems);
     // Let's extract the PHPDoc from the latest version (dev version):
     foreach ($rootNodes as $rootNode) {
         if (isset($rootNode['packageVersion']) && strpos($rootNode['packageVersion'], "-dev") !== false) {
             break;
         }
     }
     if ($rootNode && isset($rootNode['phpDoc'])) {
         $docBlock = new MoufPhpDocComment($rootNode['phpDoc']);
         $md = $docBlock->getComment();
         $description = MarkdownExtra::defaultTransform($md);
         // Let's purify HTML to avoid any attack:
         $config = \HTMLPurifier_Config::createDefault();
         $purifier = new \HTMLPurifier($config);
         $description = $purifier->purify($description);
     } else {
         $description = '';
     }
     if ($rootNode && isset($rootNode['type'])) {
         $type = $rootNode['type'];
     } else {
         $type = "class";
     }
     // Let's compute the pointer to the source.
     if (isset($rootNode['packageName'])) {
         // TODO: improve to get the link to the best package
         $package = $this->packageDao->get($rootNode['packageName'], $rootNode['packageVersion']);
         $sourceUrl = null;
         if (isset($package['sourceUrl']) && strpos($package['sourceUrl'], 'https://github.com') === 0) {
             if (strpos($package['sourceUrl'], '.git') === strlen($package['sourceUrl']) - 4) {
                 if (isset($rootNode['fileName']) && $rootNode['fileName']) {
                     $sourceUrl = substr($package['sourceUrl'], 0, strlen($package['sourceUrl']) - 4);
                     $version = str_replace(['dev-', '.x-dev'], ['', ''], $package['packageVersion']);
                     $sourceUrl .= '/blob/' . $version . $rootNode['fileName'];
                 }
             }
         }
     } else {
         $sourceUrl = null;
     }
     // Now, let's find all the classes/interfaces we extend from (recursively...)
     $inheritNodes = $this->getNode($q);
     // Compute the revert depth of all elements.
     $inheritNodes->getRevertDepth();
     // We put the graph of the extending classes INTO the revert graph of the classes we extend from.
     $inheritNodes->replaceNodeRenderingWith($graph);
     // Finally, let's get the list of classes/interfaces/traits/functions using this item
     $usedInItems = $this->itemDao->findItemsUsing($q)->limit(1000);
     // Let's add the twig file to the template.
     $this->template->setTitle('Packanalyst | ' . ucfirst($type) . ' ' . $q);
     $this->template->getWebLibraryManager()->addLibrary(new WebLibrary([ROOT_URL . 'src/views/classAnalyzer/classAnalyzer.js']));
     \Mouf::getSearchBlock()->setSearch($q);
     $this->content->addHtmlElement(new TwigTemplate($this->twig, 'src/views/classAnalyzer/index.twig', array("class" => $q, "description" => $description, "type" => $type, "inheritNodesHtml" => $inheritNodes->getHtmlRevert(), "sourceUrl" => $sourceUrl, "usedInItems" => $usedInItems)));
     $this->template->toHtml();
 }