Permalink
Browse files

added traits for the routes

  • Loading branch information...
1 parent 3266c73 commit a439ae7f1e52c4d53cf784ca8ec31eaae87952b1 @fabpot committed Jun 17, 2012
Showing with 31 additions and 0 deletions.
  1. +31 −0 src/Silex/Route/SecurityTrait.php
@@ -0,0 +1,31 @@
+<?php
+
+/*
+ * This file is part of the Silex framework.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Silex\Route;
+
+use Symfony\Component\Security\Core\Exception\AccessDeniedException;
+
+/**
+ * Security trait.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+trait SecurityTrait
+{
+ public function secure($roles)
+ {
+ $this->before(function ($request, $app) use ($roles) {
+ if (!$app['security']->isGranted($roles)) {
+ throw new AccessDeniedException();
+ }
+ });
+ }
+}

0 comments on commit a439ae7

Please sign in to comment.