├── tests
├── Functional
│ ├── Resources
│ │ └── services.yml
│ └── BundleInitializationTest.php
└── DependencyInjection
│ └── ConfigurationTest.php
├── src
├── Exception
│ └── BlazeException.php
├── HappyrBlazeBundle.php
├── Twig
│ ├── BlazeExtension.php
│ └── BlazeRuntime.php
├── Service
│ ├── BlazeManagerInterface.php
│ └── BlazeManager.php
├── DependencyInjection
│ ├── HappyrBlazeExtension.php
│ └── Configuration.php
├── Resources
│ └── config
│ │ └── services.xml
└── Model
│ ├── ConfigurationInterface.php
│ └── Configuration.php
├── LICENSE
├── composer.json
└── README.md
/tests/Functional/Resources/services.yml:
--------------------------------------------------------------------------------
1 | services:
2 | test.happyr.blaze:
3 | public: true
4 | alias: Happyr\BlazeBundle\Service\BlazeManager
5 |
--------------------------------------------------------------------------------
/src/Exception/BlazeException.php:
--------------------------------------------------------------------------------
1 |
7 | */
8 | class BlazeException extends \Exception
9 | {
10 | }
11 |
--------------------------------------------------------------------------------
/src/HappyrBlazeBundle.php:
--------------------------------------------------------------------------------
1 |
9 | */
10 | class HappyrBlazeBundle extends Bundle
11 | {
12 | }
13 |
--------------------------------------------------------------------------------
/src/Twig/BlazeExtension.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | class BlazeExtension extends AbstractExtension
13 | {
14 | public function getFilters()
15 | {
16 | return [
17 | new TwigFilter('blaze', [BlazeRuntime::class, 'blaze']),
18 | ];
19 | }
20 |
21 | public function getFunctions()
22 | {
23 | return [
24 | new TwigFunction('blaze', [BlazeRuntime::class, 'blaze']),
25 | ];
26 | }
27 |
28 | /**
29 | * @inherit
30 | *
31 | * @return string
32 | */
33 | public function getName()
34 | {
35 | return 'blaze_extension';
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Service/BlazeManagerInterface.php:
--------------------------------------------------------------------------------
1 |
7 | */
8 | interface BlazeManagerInterface
9 | {
10 | /**
11 | * Alias for getPath with $absolute=true.
12 | *
13 | * @param object $object
14 | * @param string $action
15 | * @param array $cmpObj
16 | *
17 | * @return string url
18 | */
19 | public function getUrl($object, $action, array $cmpObj = []);
20 |
21 | /**
22 | * Get the path.
23 | *
24 | * @param object $object
25 | * @param string $action
26 | * @param array $cmpObj complementary objects that might be needed to generate the route
27 | * @param bool $absolute if true we return the url
28 | *
29 | * @return string url
30 | */
31 | public function getPath($object, $action, array $cmpObj = [], $absolute = false);
32 | }
33 |
--------------------------------------------------------------------------------
/src/DependencyInjection/HappyrBlazeExtension.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class HappyrBlazeExtension extends Extension
14 | {
15 | /**
16 | * {@inheritdoc}
17 | */
18 | public function load(array $configs, ContainerBuilder $container)
19 | {
20 | $configuration = new Configuration();
21 | $config = $this->processConfiguration($configuration, $configs);
22 |
23 | $container->setParameter('happyr.blaze.objects', $config['objects']);
24 |
25 | $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
26 | $loader->load('services.xml');
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/tests/DependencyInjection/ConfigurationTest.php:
--------------------------------------------------------------------------------
1 | assertConfigurationIsValid([
21 | [
22 | 'objects' => [
23 | 'Acme\Foo' => [
24 | 'edit' => [
25 | 'route' => 'foo_edit',
26 | 'parameters' => ['id' => 'getId'],
27 | ],
28 | ],
29 | ],
30 | ],
31 | ]);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/tests/Functional/BundleInitializationTest.php:
--------------------------------------------------------------------------------
1 | createKernel();
20 |
21 | // Add some configuration
22 | $kernel->addConfigFile(__DIR__.'/Resources/services.yml');
23 |
24 | // Boot the kernel.
25 | $this->bootKernel();
26 |
27 | // Get the containter
28 | $container = $this->getContainer();
29 |
30 | // Test if you services exists
31 | $this->assertTrue($container->has('test.happyr.blaze'));
32 | $service = $container->get('test.happyr.blaze');
33 | $this->assertInstanceOf(BlazeManagerInterface::class, $service);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2013 Tobias Nyholm
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/Resources/config/services.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 | %happyr.blaze.objects%
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/src/Twig/BlazeRuntime.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class BlazeRuntime implements RuntimeExtensionInterface
12 | {
13 | /**
14 | * @var BlazeManagerInterface blaze
15 | */
16 | protected $blaze;
17 |
18 | /**
19 | * @param BlazeManagerInterface $blaze
20 | */
21 | public function __construct(BlazeManagerInterface $blaze)
22 | {
23 | $this->blaze = $blaze;
24 | }
25 |
26 | /**
27 | * Call the blaze service.
28 | *
29 | * @param mixed $object
30 | * @param string $action
31 | * @param bool $absolute
32 | *
33 | * @return string
34 | */
35 | public function blaze($object, $action, $absolute = false)
36 | {
37 | $compObjects = [];
38 |
39 | if (is_array($object)) {
40 | $compObjects = $object;
41 | $object = array_shift($compObjects);
42 | }
43 |
44 | if ($absolute) {
45 | return $this->blaze->getUrl($object, $action, $compObjects);
46 | } else {
47 | return $this->blaze->getPath($object, $action, $compObjects);
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "happyr/blaze-bundle",
3 | "type": "symfony-bundle",
4 | "description": "Write down your routing mapping at one place",
5 | "keywords": ["routing", "blaze", "dynamic", "route"],
6 | "homepage": "http://developer.happyr.com/symfony2-bundles/happyr-blaze-bundle",
7 | "license": "MIT",
8 | "authors": [
9 | {
10 | "name": "Tobias Nyholm",
11 | "email": "tobias@happyr.com"
12 | }
13 | ],
14 | "require": {
15 | "php": "^7.2",
16 | "symfony/config": "^4.4 || ^5.0",
17 | "symfony/dependency-injection": "^4.4 || ^5.0",
18 | "symfony/http-kernel": "^4.4 || ^5.0",
19 | "symfony/routing": "^4.4 || ^5.0",
20 | "symfony/yaml": "^4.4 || ^5.0",
21 | "twig/twig": "^2.1 || ^3.0"
22 | },
23 | "require-dev": {
24 | "matthiasnoback/symfony-config-test": "^4.1",
25 | "nyholm/symfony-bundle-test": "^1.6.1",
26 | "symfony/framework-bundle": "^4.4 || ^5.0",
27 | "symfony/phpunit-bridge": "^4.4 || ^5.0"
28 | },
29 | "autoload": {
30 | "psr-4": {
31 | "Happyr\\BlazeBundle\\": "src/"
32 | }
33 | },
34 | "autoload-dev": {
35 | "psr-4": {
36 | "tests\\Happyr\\BlazeBundle\\": "tests/"
37 | }
38 | },
39 | "scripts": {
40 | "test": "vendor/bin/simple-phpunit",
41 | "test-ci": "vendor/bin/simple-phpunit --coverage-text --coverage-clover=build/coverage.xml"
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/Model/ConfigurationInterface.php:
--------------------------------------------------------------------------------
1 |
7 | */
8 | interface ConfigurationInterface
9 | {
10 | /**
11 | * Does this class exist?
12 | *
13 | * @param string $class
14 | *
15 | * @return bool
16 | */
17 | public function classExist($class);
18 |
19 | /**
20 | * Does this action exists for that class?
21 | *
22 | * @param string $class
23 | * @param string $action
24 | *
25 | * @return bool
26 | */
27 | public function actionExist($class, $action);
28 |
29 | /**
30 | * Get the actions for a specific class.
31 | *
32 | * @param string $class
33 | *
34 | * @return array
35 | */
36 | public function getActions($class);
37 |
38 | /**
39 | * Get the route for a class and action.
40 | *
41 | * @param string $class
42 | * @param string $action
43 | *
44 | * @return string
45 | */
46 | public function getRoute($class, $action);
47 |
48 | /**
49 | * Get the parameters for the route.
50 | *
51 | * @param string $class
52 | * @param string $action
53 | *
54 | * @return array where key=>value is routeParam=>function
55 | */
56 | public function getParameters($class, $action);
57 |
58 | /**
59 | * Get the complementary objects.
60 | *
61 | * @param string $class
62 | * @param string $action
63 | *
64 | * @return array
65 | */
66 | public function getComplementaryObjects($class, $action);
67 | }
68 |
--------------------------------------------------------------------------------
/src/Model/Configuration.php:
--------------------------------------------------------------------------------
1 |
7 | */
8 | class Configuration implements ConfigurationInterface
9 | {
10 | /**
11 | * @var array config
12 | *
13 | * This holds the configuration from the file
14 | */
15 | protected $config;
16 |
17 | /**
18 | * @param array $config
19 | */
20 | public function __construct(array $config)
21 | {
22 | $this->config = $config;
23 | }
24 |
25 | /**
26 | * {@inheritdoc}
27 | */
28 | public function getClasses()
29 | {
30 | return array_keys($this->config);
31 | }
32 |
33 | /**
34 | * {@inheritdoc}
35 | */
36 | public function getActions($class)
37 | {
38 | return array_keys($this->config[$class]);
39 | }
40 |
41 | /**
42 | * {@inheritdoc}
43 | */
44 | public function getRoute($class, $action)
45 | {
46 | return $this->config[$class][$action]['route'];
47 | }
48 |
49 | /**
50 | * {@inheritdoc}
51 | */
52 | public function getParameters($class, $action)
53 | {
54 | return $this->config[$class][$action]['parameters'];
55 | }
56 |
57 | /**
58 | * {@inheritdoc}
59 | */
60 | public function getComplementaryObjects($class, $action)
61 | {
62 | if (!isset($this->config[$class][$action]['complementaryObjects'])) {
63 | return [];
64 | }
65 |
66 | return $this->config[$class][$action]['complementaryObjects'];
67 | }
68 |
69 | /**
70 | * {@inheritdoc}
71 | */
72 | public function actionExist($class, $action)
73 | {
74 | return array_key_exists($action, $this->config[$class]);
75 | }
76 |
77 | /**
78 | * {@inheritdoc}
79 | */
80 | public function classExist($class)
81 | {
82 | return array_key_exists($class, $this->config);
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/DependencyInjection/Configuration.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Configuration implements ConfigurationInterface
14 | {
15 | /**
16 | * {@inheritdoc}
17 | */
18 | public function getConfigTreeBuilder()
19 | {
20 | $treeBuilder = new TreeBuilder('happyr_blaze');
21 | $rootNode = $treeBuilder->getRootNode();
22 |
23 | $rootNode->children()
24 | ->arrayNode('objects')
25 | ->requiresAtLeastOneElement()
26 | ->useAttributeAsKey('name')
27 | ->prototype('variable')
28 | ->treatNullLike([])
29 |
30 | //make sure that there is some config after each object
31 | ->validate()
32 | ->ifTrue(
33 | function ($objects) {
34 | foreach ($objects as $o) {
35 | if (!is_array($o)) {
36 | return true;
37 | }
38 | }
39 |
40 | return false;
41 | }
42 | )
43 | ->thenInvalid('The happyr_blaze.objects config %s must be an array.')
44 | ->end()
45 |
46 | //make sure route and parameters is set
47 | ->validate()
48 | ->ifTrue(
49 | function ($objects) {
50 | foreach ($objects as $o) {
51 | if (!isset($o['route']) || !isset($o['parameters'])) {
52 | return true;
53 | }
54 | }
55 |
56 | return false;
57 | }
58 | )
59 | ->thenInvalid('%s must contain "route" and "parameters".')
60 | ->end()
61 | ->end()
62 | ->end();
63 |
64 | return $treeBuilder;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Happyr BlazeBundle
2 |
3 | [](https://github.com/Happyr/BlazeBundle/releases)
4 | [](https://travis-ci.org/Happyr/BlazeBundle)
5 | [](https://scrutinizer-ci.com/g/Happyr/BlazeBundle)
6 | [](https://scrutinizer-ci.com/g/Happyr/BlazeBundle)
7 | [](https://packagist.org/packages/happyr/blaze-bundle)
8 |
9 | This bundle lets you configure dynamic routes. A piece of code explains the benefit:
10 |
11 | ```html
12 | // Generate the path /blog-post/{post_id}/comment/{comment_id}/edit
13 | Click here
14 | Click here
15 | ```
16 |
17 | ## Installation
18 |
19 | ### Step 1: Using Composer
20 |
21 | ```bash
22 | $ composer require happyr/blaze-bundle
23 | ```
24 |
25 | ### Step 2: Register the bundle
26 |
27 | To register the bundles with your kernel:
28 |
29 | ```php
30 | // in AppKernel::registerBundles()
31 | $bundles = array(
32 | // ...
33 | new Happyr\BlazeBundle\HappyrBlazeBundle(),
34 | // ...
35 | );
36 | ```
37 |
38 | ### Step 3: Configure the bundle
39 |
40 | ``` yaml
41 | # app/config/config.yml
42 |
43 | happyr_blaze:
44 | objects:
45 | Acme\DemoBundle\Entity\Foo:
46 | edit:
47 | route: 'foo_edit'
48 | parameters: {id:'getId'}
49 | show:
50 | route: 'foo_show'
51 | parameters: {id:'getId'}
52 |
53 | Acme\DemoBundle\Entity\Bar:
54 | show:
55 | route: 'bar_show'
56 | parameters: {id:'getId'}
57 |
58 | Acme\DemoBundle\Entity\Baz:
59 | anything:
60 | route: 'baz_show'
61 | parameters: {id:'getId', foo_id:'getFoo.getId'}
62 |
63 | #if you need support for routes where the objects have no relation:
64 | Acme\DemoBundle\Entity\FooBar:
65 | manage:
66 | route: 'foobar_manage'
67 | parameters: [{id: 'getId'}, {baz_id: 'getId', baz_name: 'getName'}, {bazbar_id: 'getSlug'}]
68 | complementaryObjects: ["Acme\DemoBundle\Entity\Baz", "Acme\DemoBundle\Entity\BazBar"]
69 | ```
70 |
71 |
72 |
73 | ## Usage
74 |
75 | ### Twig
76 | ```html
77 | {# foo is a Foo object #}
78 | Show Foo
79 |
80 | {# baz is a Baz object #}
81 | Show Baz
82 |
83 | {# and the multiple objects .. #}
84 | Show Baz
85 | ```
86 |
87 | ### PHP
88 |
89 | ```php
90 | use Happyr\BlazeBundle\Service\BlazeManagerInterface;
91 |
92 | class MyController
93 | {
94 | private $blaze;
95 | public function __construct(BlazeManagerInterface $blaze) {
96 | $this->blaze = $blaze;
97 | }
98 |
99 | public function SomeAction() {
100 | $blaze = $this->get(BlazeManagerInterface::class);
101 |
102 | $showUrl = $blaze->getPath($foo, 'show');
103 | $manageUrl = $blaze->getPath($foobar, 'show', array($baz, $bazbar));
104 |
105 | // ...
106 | }
107 | }
108 | ```
109 |
--------------------------------------------------------------------------------
/src/Service/BlazeManager.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class BlazeManager implements BlazeManagerInterface
14 | {
15 | /**
16 | * @var RouterInterface router
17 | */
18 | protected $router;
19 |
20 | /**
21 | * @var \Happyr\BlazeBundle\Model\ConfigurationInterface config
22 | */
23 | protected $config;
24 |
25 | /**
26 | * @param ConfigurationInterface $config
27 | * @param RouterInterface $router
28 | */
29 | public function __construct(ConfigurationInterface $config, RouterInterface $router)
30 | {
31 | $this->config = $config;
32 | $this->router = $router;
33 | }
34 |
35 | /**
36 | * Get the route and the params.
37 | *
38 | * @param object $object
39 | * @param string $action
40 | *
41 | * @return array array($route, $params, $cmpObj)
42 | *
43 | * @throws BlazeException
44 | */
45 | protected function getRoute($object, $action)
46 | {
47 | if (null == $object) {
48 | throw new BlazeException(sprintf('Blaze: Cant find route for non-object.'));
49 | }
50 |
51 | $class = $this->getClass($object);
52 |
53 | if (!$this->config->actionExist($class, $action)) {
54 | throw new BlazeException(sprintf('Action "%s" for class %s does not exist in Blaze config.', $action, $class));
55 | }
56 |
57 | $route = $this->config->getRoute($class, $action);
58 | $params = $this->config->getParameters($class, $action);
59 | $cmpObj = $this->config->getComplementaryObjects($class, $action);
60 |
61 | return [$route, $params, $cmpObj];
62 | }
63 |
64 | /**
65 | * {@inheritdoc}
66 | */
67 | public function getUrl($object, $action, array $cmpObj = [])
68 | {
69 | return $this->getPath($object, $action, $cmpObj, true);
70 | }
71 |
72 | /**
73 | * {@inheritdoc}
74 | */
75 | public function getPath($object, $action, array $cmpObj = [], $absolute = false)
76 | {
77 | list($route, $params, $confCmpObj) = $this->getRoute($object, $action);
78 |
79 | // make sure that $confCmpObj and $cmpObj is matching
80 | foreach ($confCmpObj as $key => $class) {
81 | if (!isset($cmpObj[$key])) {
82 | throw new BlazeException(sprintf('The %d parameter of complementary objects was expected to be %s but you gave me nothing!', $key, $class));
83 | }
84 |
85 | if ($this->getClass($cmpObj[$key]) != $class) {
86 | throw new BlazeException(sprintf('The %d parameter of complementary objects was expected to be %s but instance of %s was given', $key, $class, get_class($cmpObj[$key])));
87 | }
88 | }
89 |
90 | $routeParams = $this->getRouteParams($object, $params, $cmpObj);
91 |
92 | $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH;
93 | if ($absolute) {
94 | $referenceType = UrlGeneratorInterface::ABSOLUTE_URL;
95 | }
96 |
97 | return $this->router->generate($route, $routeParams, $referenceType);
98 | }
99 |
100 | /**
101 | * Get the parameters to send to the @router.
102 | *
103 | * @param object $object
104 | * @param array $params
105 | * @param array $cmpObj
106 | *
107 | * @return array
108 | */
109 | protected function getRouteParams($object, array $params, array $cmpObj = [])
110 | {
111 | /*
112 | * Assert: I know for sure that $object is not null
113 | */
114 | $routeParams = [];
115 | foreach ($params as $key => $func) {
116 | //if there is complementary objects
117 | if (is_array($func)) {
118 | /*
119 | * the first element should use the $object
120 | * other elements should use objects in the $cmpObj.
121 | */
122 | if (0 == $key) {
123 | //make sure that the size of $params is equal to $cmpObj + the $obejct
124 | if (count($params) != count($cmpObj) + 1) {
125 | throw new BlazeException(sprintf('There is a mismatch in the number of route params and the number of objects. This is '.'usually cased by a configuration error or that you forgotten to send the complementary'.' objects to the Blaze service. We found %s parameter arrays but %d objects', count($params), count($cmpObj) + 1));
126 | }
127 |
128 | $routeParams = array_merge($routeParams, $this->getRouteParams($object, $func));
129 |
130 | continue;
131 | } else {
132 | /*
133 | * We know for sure that $cmpObj[$key-1] and is of type like the config says
134 | */
135 |
136 | //get the route params with the complementary object
137 | $routeParams = array_merge($routeParams, $this->getRouteParams($cmpObj[$key - 1], $func));
138 |
139 | continue;
140 | }
141 | }
142 |
143 | $routeParams[$key] = $this->getSingleRouteParam($object, $func);
144 | }
145 |
146 | return $routeParams;
147 | }
148 |
149 | /**
150 | * Get a route param.
151 | *
152 | * @param object $object
153 | * @param string $function
154 | *
155 | * @return mixed
156 | *
157 | * @throws BlazeException
158 | */
159 | protected function getSingleRouteParam($object, $function)
160 | {
161 | //if there is a chain of functions
162 | if (strstr($function, '.')) {
163 | $funcs = explode('.', $function);
164 | $returnValue = $object;
165 | foreach ($funcs as $f) {
166 | $returnValue = $this->callObjectFunction($returnValue, $f);
167 |
168 | if (null === $returnValue) {
169 | throw new BlazeException(sprintf('Function "%s" ended up with returning non-object (null) after "%s".', $function, $f));
170 | }
171 | }
172 |
173 | return $returnValue;
174 | } else {
175 | return $this->callObjectFunction($object, $function);
176 | }
177 | }
178 |
179 | /**
180 | * Call a $function on the object.
181 | *
182 | * @param object $object
183 | * @param string $function
184 | *
185 | * @return mixed
186 | */
187 | private function callObjectFunction($object, $function)
188 | {
189 | try {
190 | return $object->$function();
191 | } catch (\Exception $e) {
192 | if (null === $object) {
193 | throw new BlazeException(sprintf('Called "%s" on a non-object', $function));
194 | }
195 |
196 | if (!method_exists($object, $function)) {
197 | throw new BlazeException(sprintf('Method %s does not exits on object %s', $function, get_class($object)));
198 | }
199 | }
200 | }
201 |
202 | /**
203 | * Get the class in the config.
204 | * If the class of $object is not found, try the parent of $object.
205 | *
206 | * @param object $object
207 | *
208 | * @return string
209 | */
210 | protected function getClass($object)
211 | {
212 | if (!is_object($object)) {
213 | //we assume that $object is a string and namespace
214 | if (class_exists($object)) {
215 | return $object;
216 | }
217 |
218 | //class not loaded
219 | throw new BlazeException(sprintf('Blaze must receive an object or a fully qualified name of a loaded class. We got "%s"', $object));
220 | }
221 |
222 | $class = get_class($object);
223 |
224 | //Do max 3 times
225 | for ($i = 0; $i < 3 && $class; ++$i) {
226 | if ($this->config->classExist($class)) {
227 | return $class;
228 | }
229 | $class = get_parent_class($class);
230 | }
231 |
232 | throw new BlazeException(sprintf('Class %s does not exist in Blaze config.', get_class($object)));
233 | }
234 | }
235 |
--------------------------------------------------------------------------------