Ejemplo n.º 1
0
 public function testStoreItemName()
 {
     $elasticSearchService = \Mouf::getElasticSearchService();
     try {
         $elasticSearchService->createIndex();
     } catch (\Exception $e) {
         // Ignore if index already exist.
     }
     try {
         $elasticSearchService->deleteItemName("unique_test_case");
     } catch (\Exception $e) {
         // Ignore if key does not exists.
     }
     $elasticSearchService->storeItemName("unique_test_case");
     $results = $elasticSearchService->suggestItemName2("unique_test_case");
     $this->assertEquals(1, $results['total']);
     $this->assertEquals(null, $results['hits'][0]['_source']['type']);
     $elasticSearchService->storeItemName("unique_test_case", "class");
     $results = $elasticSearchService->suggestItemName2("unique_test_case");
     $this->assertEquals(1, $results['total']);
     $this->assertEquals("class", $results['hits'][0]['_source']['type']);
     // TODO: write test to test ID, update, and so on!!!
     // TODO: write test to test ID, update, and so on!!!
     // TODO: write test to test ID, update, and so on!!!
     // TODO: write test to test ID, update, and so on!!!
     // TODO: write test to test ID, update, and so on!!!
     // TODO: write test to test ID, update, and so on!!!
     // TODO: write test to test ID, update, and so on!!!
     // TODO: write test to test ID, update, and so on!!!
     // TODO: write test to test ID, update, and so on!!!
     $elasticSearchService->deleteItemName("unique_test_case");
 }
Ejemplo n.º 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $itemDao = \Mouf::getItemDao();
     $packageDao = \Mouf::getPackageDao();
     $itemDao->createIndex();
     $packageDao->createIndex();
     $packageDao->refreshAllPackages();
 }
Ejemplo n.º 3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $itemDao = \Mouf::getItemDao();
     $packageDao = \Mouf::getPackageDao();
     $itemDao->drop();
     $itemDao->createIndex();
     $packageDao->drop();
     $packageDao->createIndex();
     //$fetchDataService = \Mouf::getFetchDataService();
     //$fetchDataService->reset();
     $elasticSearchService = \Mouf::getElasticSearchService();
     $elasticSearchService->deleteIndex();
     $elasticSearchService->createIndex();
 }
Ejemplo n.º 4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     \Mouf::getDownloadLock()->acquireLock();
     $fetchDataService = \Mouf::getFetchDataService();
     $fetchDataService->setDownloadManager($this->getDownloadManager());
     $fetchDataService->setPackagistRepository($this->getPackagistRepository());
     $package = $input->getOption('package');
     $retry = $input->getOption('retry');
     $force = $input->getOption('force');
     if ($package) {
         $fetchDataService->setForcedPackage($package);
     }
     if ($retry) {
         $fetchDataService->setRetryOnError(true);
     }
     if ($force) {
         $fetchDataService->setForce(true);
     }
     $fetchDataService->run();
 }
Ejemplo n.º 5
0
<?php

use Composer\Package\Package;
require_once 'mouf/Mouf.php';
/*require_once 'vendor/autoload.php';

use Composer\Repository\CompositeRepository;
use Composer\Repository\PlatformRepository;
use Composer\Factory;
// init repos
            $repos = new CompositeRepository(array_merge(
                array(new PlatformRepository()),
                Factory::createDefaultRepositories($this->getIO())
            ));
*/
$package = new Package('test/test', '1.0.0', '1.0.0');
$package->setReleaseDate(new DateTime());
Mouf::getPackageVersionRepository()->findOrCreatePackageVersion($package);
//Mouf::getPackageRepository()->findOrCreatePackage('mouf/mouf');
Mouf::getNeo4jEntityManager()->flush();
Ejemplo n.º 6
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();
 }
Ejemplo n.º 7
0
 /**
  * @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();
 }
Ejemplo n.º 8
0
 /**
  * Renders the tree, in reverse order!
  */
 public function getHtmlRevert()
 {
     ob_start();
     \Mouf::getDefaultRenderer()->render($this, "revert");
     return ob_get_clean();
 }
Ejemplo n.º 9
0
 /**
  * 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();
 }
Ejemplo n.º 10
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $elasticSearchService = \Mouf::getElasticSearchService();
     $elasticSearchService->reindexAll();
 }
Ejemplo n.º 11
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     \Mouf::getPackagistStatsLock()->acquireLock();
     $packagistScoreService = \Mouf::getPackagistScoreService();
     $packagistScoreService->updateAllScores();
 }