2013-04-12 17:05:13 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the NelmioApiDocBundle.
|
|
|
|
*
|
|
|
|
* (c) Nelmio <hello@nelm.io>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Nelmio\ApiDocBundle\Extractor\Handler;
|
|
|
|
|
2013-04-29 12:10:42 +03:00
|
|
|
use JMS\SecurityExtraBundle\Annotation\PreAuthorize;
|
2013-04-12 17:05:13 +02:00
|
|
|
use Nelmio\ApiDocBundle\Extractor\HandlerInterface;
|
2013-04-16 13:46:15 +02:00
|
|
|
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
|
|
|
use Symfony\Component\Routing\Route;
|
2013-04-17 13:41:28 +02:00
|
|
|
use JMS\SecurityExtraBundle\Annotation\Secure;
|
2013-04-12 17:05:13 +02:00
|
|
|
|
2013-04-16 13:46:15 +02:00
|
|
|
class JmsSecurityExtraHandler implements HandlerInterface
|
2013-04-12 17:05:13 +02:00
|
|
|
{
|
2013-04-17 14:24:45 +02:00
|
|
|
public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method)
|
2013-04-12 17:05:13 +02:00
|
|
|
{
|
|
|
|
foreach ($annotations as $annot) {
|
2013-06-24 14:27:22 +02:00
|
|
|
if ($annot instanceof PreAuthorize) {
|
2013-04-12 17:05:13 +02:00
|
|
|
$annotation->setAuthentication(true);
|
2013-12-11 01:59:59 +01:00
|
|
|
} elseif ($annot instanceof Secure) {
|
2013-06-24 14:27:22 +02:00
|
|
|
$annotation->setAuthentication(true);
|
|
|
|
$annotation->setAuthenticationRoles(is_array($annot->roles) ? $annot->roles : explode(',', $annot->roles));
|
2013-04-12 17:05:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|