Skip to content

Commit

Permalink
Merge pull request #124 from agiuliano/master
Browse files Browse the repository at this point in the history
Abstract routes for future formats
  • Loading branch information
liuggio committed Jul 1, 2014
2 parents bde0372 + e32634b commit b83e13c
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 212 deletions.
4 changes: 2 additions & 2 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ pugx_badge:
- { name: 'total', label: 'Total Downloads', route: "pugx_badge_download" }
- { name: 'latest_unstable_version', label: 'Latest Unstable Version', route: "pugx_badge_version_latest", latest: 'unstable'}
- { name: 'license', label: 'License', route: "pugx_badge_license"}
- { name: 'monthly', label: 'Monthly Downloads', route: "pugx_badge_download_type_png", type: 'monthly'}
- { name: 'daily', label: 'Daily Downloads', route: "pugx_badge_download_type_png", type: 'daily'}
- { name: 'monthly', label: 'Monthly Downloads', route: "pugx_badge_download_type", type: 'monthly'}
- { name: 'daily', label: 'Daily Downloads', route: "pugx_badge_download_type", type: 'daily'}
- { name: 'version', label: 'Version', route: "pugx_badge_version" }


Expand Down
8 changes: 7 additions & 1 deletion app/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ pugx_badge_shieldio:
host: "img.shields.io"
requirements:
vendor: "[A-Za-z0-9_.-]+"
value: "[A-Za-z0-9_.-]+"
value: "[A-Za-z0-9_.-]+"

redirects:
resource: "@PUGXBadgeBundle/Resources/config/routing/routing_redirects.yml"

aliases:
resource: "@PUGXBadgeBundle/Resources/config/routing/routing_aliases.yml"
21 changes: 11 additions & 10 deletions src/PUGX/BadgeBundle/Controller/BadgeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* @author Giulio De Donato <[email protected]>
* @author Leonardo Proietti <[email protected]>
* @author Simone Fumagalli <[email protected]>
* @author Andrea Giuliano <[email protected]>
*/
class BadgeController extends Controller
{
Expand Down Expand Up @@ -64,15 +65,15 @@ public function searchPackagistAction(Request $request)
* @param string $repository repository
* @param string $type badge type
*
* @Route("/{repository}/downloads.svg",
* @Route("/{repository}/downloads",
* name = "pugx_badge_download",
* defaults = {"type" = "total"},
* requirements = {
* "repository" = "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
* }
* )
* @Route("/{repository}/d/{type}.svg",
* @Route("/{repository}/d/{type}",
* name = "pugx_badge_download_type",
* defaults = {"type" = "total"},
* requirements = {
* "type" = "total|daily|monthly",
* "repository" = "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
Expand All @@ -83,7 +84,7 @@ public function searchPackagistAction(Request $request)
*
* @return StreamedResponse
*/
public function downloadsAction($repository, $type = 'total')
public function downloadsAction($repository, $type)
{
$imageCreator = $this->getImageCreator();
$status = 500;
Expand Down Expand Up @@ -125,15 +126,15 @@ public function downloadsAction($repository, $type = 'total')
* @param string $repository repository
* @param string $latest latest
*
* @Route("/{repository}/version.svg",
* @Route("/{repository}/version",
* name="pugx_badge_version",
* defaults = {"latest" = "stable"},
* requirements={"repository" = "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"}
* )
* @Route("/{repository}/v/{latest}.svg",
* @Route("/{repository}/v/{latest}",
* name = "pugx_badge_version_latest",
* defaults = {"latest" = "stable"},
* requirements = {
* "type" = "stable|unstable",
* "latest" = "stable|unstable",
* "repository" = "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
* }
* )
Expand All @@ -142,7 +143,7 @@ public function downloadsAction($repository, $type = 'total')
*
* @return StreamedResponse
*/
public function versionAction($repository, $latest = 'stable')
public function versionAction($repository, $latest)
{
$image = null;
$error = self::ERROR_TEXT_GENERIC;
Expand Down Expand Up @@ -182,7 +183,7 @@ public function versionAction($repository, $latest = 'stable')
*
* @param string $repository repository
*
* @Route("/{repository}/license.svg",
* @Route("/{repository}/license",
* name="pugx_badge_license",
* requirements={"repository" = "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"}
* )
Expand Down
138 changes: 0 additions & 138 deletions src/PUGX/BadgeBundle/Controller/PngBadgeController.php

This file was deleted.

45 changes: 45 additions & 0 deletions src/PUGX/BadgeBundle/Resources/config/routing/routing_aliases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
download_svg_alias:
path: /{repository}/downloads.svg
defaults:
_controller: PUGXBadgeBundle:Badge:downloads
type: "total"
requirements:
repository: "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
methods: [GET]

download_type_svg_alias:
path: /{repository}/d/{type}.svg
defaults:
_controller: PUGXBadgeBundle:Badge:downloads
type: "total"
requirements:
repository: "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
type: "total|daily|monthly"
methods: [GET]

badge_version_svg_alias:
path: /{repository}/version.svg
defaults:
_controller: PUGXBadgeBundle:Badge:version
latest: "stable"
requirements:
repository: "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
methods: [GET]

version_latest_svg_alias:
path: /{repository}/v/{latest}.svg
defaults:
_controller: PUGXBadgeBundle:Badge:version
latest: "stable"
requirements:
repository: "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
latest: "stable|unstable"
methods: [GET]

badge_license_svg_alias:
path: /{repository}/license.svg
defaults:
_controller: PUGXBadgeBundle:Badge:license
requirements:
repository: "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
methods: [GET]
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
download_png_redirect:
path: /{repository}/downloads.png
defaults:
_controller: FrameworkBundle:Redirect:redirect
route: pugx_badge_download
permanent: true
requirements:
repository: "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
methods: [GET]

download_type_png_redirect:
path: /{repository}/d/{type}.png
defaults:
_controller: FrameworkBundle:Redirect:redirect
route: pugx_badge_download_type
permanent: true
type: "total"
requirements:
repository: "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
type: "total|daily|monthly"
methods: [GET]

badge_version_png_redirect:
path: /{repository}/version.png
defaults:
_controller: FrameworkBundle:Redirect:redirect
route: pugx_badge_version
permanent: true
requirements:
repository: "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
methods: [GET]

version_latest_png_redirect:
path: /{repository}/v/{latest}.png
defaults:
_controller: FrameworkBundle:Redirect:redirect
route: pugx_badge_version_latest
permanent: true
latest: "stable"
requirements:
repository: "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
type: "stable|unstable"
methods: [GET]

badge_license_png_redirect:
path: /{repository}/license.png
defaults:
_controller: FrameworkBundle:Redirect:redirect
route: pugx_badge_license
permanent: true
requirements:
repository: "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
methods: [GET]
10 changes: 5 additions & 5 deletions src/PUGX/BadgeBundle/Tests/Controller/BadgeControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ public function testDownloadsAction()
$client = static::createClient();
static::$kernel->getContainer()->set('packagist_client', $this->packagistClient);
static::$kernel->getContainer()->set('image_http_client', $this->imageHttpClient);
$client->request('GET', '/pugx/badge-poser/d/total.svg');
$client->request('GET', '/pugx/badge-poser/d/total');
$this->assertTrue($client->getResponse()->isSuccessful());
}

public function testLatestStableAction()
{
$client = static::createClient();
static::$kernel->getContainer()->set('packagist_client', $this->packagistClient);
$client->request('GET', '/pugx/badge-poser/version.svg');
$client->request('GET', '/pugx/badge-poser/version');
$this->assertTrue($client->getResponse()->isSuccessful());
}

public function testLatestUnstableAction()
{
$client = static::createClient();
static::$kernel->getContainer()->set('packagist_client', $this->packagistClient);
$client->request('GET', '/pugx/badge-poser/v/unstable.svg');
$client->request('GET', '/pugx/badge-poser/v/unstable');

$this->assertTrue($client->getResponse()->isSuccessful());
$response = $client->getResponse();
Expand All @@ -61,7 +61,7 @@ public function testLicenseAction()
{
$client = static::createClient();
static::$kernel->getContainer()->set('packagist_client', $this->packagistClient);
$client->request('GET', '/pugx/badge-poser/license.svg');
$client->request('GET', '/pugx/badge-poser/license');
$this->assertTrue($client->getResponse()->isSuccessful());
}

Expand All @@ -74,7 +74,7 @@ public function testIfPackageDoesntExist()
$client = static::createClient();
static::$kernel->getContainer()->set('packagist_client', $packagistClient);
static::$kernel->getContainer()->set('image_http_client', $this->imageHttpClient);
$client->request('GET', '/pugx/microsoft-lover/d/total.svg');
$client->request('GET', '/pugx/microsoft-lover/d/total');
$this->assertTrue($client->getResponse()->isServerError());
}

Expand Down
Loading

0 comments on commit b83e13c

Please sign in to comment.