' . htmlspecialchars($source) . ''; 78 | } 79 | } 80 | 81 | return $source; 82 | } 83 | 84 | /** 85 | * @return mixed[]|null 86 | */ 87 | public function getComposerInformation(RepositoryInterface $repository): ?array 88 | { 89 | if (! ($repository instanceof VcsRepository)) { 90 | return null; 91 | } 92 | 93 | try { 94 | $driver = $repository->getDriver(); 95 | } catch (Throwable $e) { 96 | return null; 97 | } 98 | 99 | if ($driver === null) { 100 | return null; 101 | } 102 | 103 | return $driver->getComposerInformation($driver->getRootIdentifier()); 104 | } 105 | 106 | public function getComposerDistUrl( 107 | string $package, 108 | string $ref, 109 | string $type = 'zip' 110 | ): string { 111 | $distUrl = $this->router->generate('app_repository_dist', [ 112 | 'vendor' => 'PACK', 113 | 'project' => 'AGE', 114 | 'ref' => 'REF', 115 | 'type' => 'TYPE', 116 | ], UrlGeneratorInterface::ABSOLUTE_URL); 117 | 118 | $distUrl = str_replace( 119 | [ 120 | 'PACK/AGE', 121 | 'REF', 122 | 'TYPE', 123 | ], 124 | [ 125 | $package, 126 | $ref, 127 | $type, 128 | ], 129 | $distUrl 130 | ); 131 | 132 | return $distUrl; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/Twig/Extension/DevliverExtension.php: -------------------------------------------------------------------------------- 1 | registry = $registry; 30 | $this->router = $router; 31 | } 32 | 33 | /** 34 | * @inheritdoc 35 | */ 36 | public function getFunctions(): array 37 | { 38 | return [ 39 | new TwigFunction('version_downloads', [$this, 'getVersionDownloadsCounter']), 40 | new TwigFunction('package_downloads', [$this, 'getPackageDownloadsCounter']), 41 | new TwigFunction('package_download_url', [$this, 'getPackageDownloadUrl']), 42 | new TwigFunction('package_url', [$this, 'getPackageUrl']), 43 | new TwigFunction('package_adapter', [$this, 'getPackageAdapter']), 44 | ]; 45 | } 46 | 47 | /** 48 | * @inheritdoc 49 | */ 50 | public function getFilters(): array 51 | { 52 | return [ 53 | new TwigFilter('sha1', 'sha1'), 54 | new TwigFilter('package_adapter', [$this, 'getPackageAdapter']), 55 | new TwigFilter('gravatar', [$this, 'getGravatarUrl']), 56 | ]; 57 | } 58 | 59 | public function getPackageDownloadsCounter(Package $package): int 60 | { 61 | $repo = $this->registry->getRepository(Download::class); 62 | 63 | return $repo->countPackageDownloads($package); 64 | } 65 | 66 | public function getVersionDownloadsCounter(Version $version): int 67 | { 68 | $repo = $this->registry->getRepository(Download::class); 69 | 70 | return $repo->countVersionDownloads($version); 71 | } 72 | 73 | public function getPackageAdapter(CompletePackageInterface $package): PackageAdapter 74 | { 75 | return new PackageAdapter($package); 76 | } 77 | 78 | public function getPackageUrl(string $name): string 79 | { 80 | $repo = $this->registry->getRepository(Package::class); 81 | 82 | $package = $repo->findOneBy([ 83 | 'name' => $name, 84 | ]); 85 | 86 | if ($package !== null) { 87 | return $this->router->generate('app_package_view', [ 88 | 'package' => $package->getId(), 89 | ]); 90 | } 91 | 92 | return 'https://packagist.org/packages/' . $name; 93 | } 94 | 95 | public function getPackageDownloadUrl(CompletePackageInterface $package): string 96 | { 97 | $adapter = $this->getPackageAdapter($package); 98 | 99 | return $this->router->generate('app_repository_dist_web', [ 100 | 'vendor' => $adapter->getVendorName(), 101 | 'project' => $adapter->getProjectName(), 102 | 'ref' => $package->getSourceReference(), 103 | 'type' => 'zip', 104 | ]); 105 | } 106 | 107 | public function getGravatarUrl(string $email, int $size): string 108 | { 109 | $gravatar = new Gravatar([], true); 110 | 111 | return $gravatar->avatar($email, ['s' => $size]); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /templates/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicklog/devliver/e086cbc711a54c5c9c836a39ab5ccf00c7589d15/templates/.gitkeep -------------------------------------------------------------------------------- /templates/_partials/footer.html.twig: -------------------------------------------------------------------------------- 1 |
{{ knp_pagination_sortable(pagination, 'Name', ['p.name']) }} | 22 |Token | 23 |24 | |
---|---|---|
28 | 29 | {{ client.name }} 30 | 31 | | 32 |33 | {{ client.token }} 34 | | 35 |36 | 46 | | 47 |
{{ knp_pagination_sortable(pagination, 'Mail address', ['p.email']) }} | 22 |23 | |
---|---|
27 | 28 | {{ user.email }} 29 | 30 | | 31 |32 | 43 | | 44 |