-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
395 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\ResourceBundle\Routing; | ||
|
||
use Sylius\Component\Resource\Annotation\SyliusRoute; | ||
use Sylius\Component\Resource\Reflection\ClassReflection; | ||
use Symfony\Component\Routing\Route; | ||
use Symfony\Component\Routing\RouteCollection; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class RouteAttributesFactory implements RouteAttributesFactoryInterface | ||
{ | ||
public function createRouteForClass(RouteCollection $routeCollection, string $className): void | ||
{ | ||
$attributes = ClassReflection::getClassAttributes($className, SyliusRoute::class); | ||
|
||
foreach ($attributes as $reflectionAttribute) { | ||
$arguments = $reflectionAttribute->getArguments(); | ||
|
||
Assert::keyExists($arguments, 'name', 'Your route should have a name attribute.'); | ||
|
||
$syliusOptions = []; | ||
|
||
if (isset($arguments['template'])) { | ||
$syliusOptions['template'] = $arguments['template']; | ||
} | ||
|
||
if (isset($arguments['vars'])) { | ||
$syliusOptions['vars'] = $arguments['vars']; | ||
} | ||
|
||
if (isset($arguments['criteria'])) { | ||
$syliusOptions['criteria'] = $arguments['criteria']; | ||
} | ||
|
||
if (isset($arguments['repository'])) { | ||
$syliusOptions['repository'] = $arguments['repository']; | ||
} | ||
|
||
if (isset($arguments['serializationGroups'])) { | ||
$syliusOptions['serialization_groups'] = $arguments['serializationGroups']; | ||
} | ||
|
||
if (isset($arguments['serializationVersion'])) { | ||
$syliusOptions['serialization_version'] = $arguments['serializationVersion']; | ||
} | ||
|
||
$route = new Route( | ||
$arguments['path'], | ||
[ | ||
'_controller' => $arguments['controller'] ?? null, | ||
'_sylius' => $syliusOptions, | ||
], | ||
$arguments['requirements'] ?? [], | ||
$arguments['options'] ?? [], | ||
$arguments['host'] ?? '', | ||
$arguments['schemes'] ?? [], | ||
$arguments['methods'] ?? [] | ||
); | ||
|
||
$routeCollection->add($arguments['name'], $route, $arguments['priority'] ?? 0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\ResourceBundle\Routing; | ||
|
||
use Sylius\Component\Resource\Annotation\SyliusRoute; | ||
use Symfony\Component\Routing\Route; | ||
use Symfony\Component\Routing\RouteCollection; | ||
use Webmozart\Assert\Assert; | ||
|
||
interface RouteAttributesFactoryInterface | ||
{ | ||
public function createRouteForClass(RouteCollection $routeCollection, string $className): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.