Skip to content

Commit

Permalink
slugify
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Loges committed Aug 28, 2018
1 parent 36ead78 commit e9911c5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"ornicar/gravatar-bundle": "^1.2",
"knplabs/knp-menu-bundle": "^2.0",
"austinsmorris/doctrine-dbal-datetimeutc": "^2.0",
"cocur/slugify": "^3.1",

"oomphinc/composer-installers-extender": "^1.1",
"npm-asset/fortawesome--fontawesome-free": "~5.2",
Expand Down
18 changes: 13 additions & 5 deletions src/Controller/PackageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
namespace Shapecode\Devliver\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Routing\Annotation\Route;
use Shapecode\Devliver\Entity\Package;
use Shapecode\Devliver\Form\Type\Forms\PackageAbandonType;
use Shapecode\Devliver\Form\Type\Forms\PackageType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Constraints\Callback;

/**
Expand All @@ -18,13 +18,13 @@
* @package Shapecode\Devliver\Controller
* @author Nikita Loges
*
* @Route("/packages", name="devliver_package_")
* @Route("/package", name="devliver_package_")
*/
class PackageController extends Controller
{

/**
* @Route("", name="index")
* @Route("s", name="index")
* @Template()
*
* @param Request $request
Expand Down Expand Up @@ -168,21 +168,29 @@ public function disableAction(Request $request, Package $package)
}

/**
* @Route("/{package}/view", name="view")
* @Route("/{package}/view", name="view", requirements={"package"="\d+"})
* @Route("/{package}/{slug}", name="view_slug", requirements={"package"="\d+"})
* @Template()
*
* @param Package $package
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response|array
*/
public function viewAction(Package $package)
public function viewAction(Request $request, Package $package)
{
if (!$package->getVersions()->count()) {
return $this->redirectToRoute('devliver_package_update', [
'package' => $package->getId()
]);
}

if ($request->get('_route') === 'devliver_package_view') {
return $this->redirectToRoute('devliver_package_view_slug', [
'package' => $package->getId(),
'slug' => $this->get('cocur_slugify_custom')->slugify($package->getName())
]);
}

$packages = $package->getPackages();
$stable = $package->getLastStablePackage();

Expand Down
4 changes: 4 additions & 0 deletions src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ parameters:

services:

cocur_slugify_custom:
class: Cocur\Slugify\Slugify
public: true

cache.tag.app:
class: Symfony\Component\Cache\Adapter\TagAwareAdapter
decorates: cache.app
Expand Down

0 comments on commit e9911c5

Please sign in to comment.