diff --git a/composer.lock b/composer.lock index 4fd4205..d16d29b 100755 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5b473d61a686e8c4b2fa6f5e279e2940", + "content-hash": "825ed2a6ced61ac313919d3cfa47c31c", "packages": [ { "name": "doctrine/annotations", diff --git a/docs/feed.xml b/docs/feed.xml index e63460a..b67f623 100644 --- a/docs/feed.xml +++ b/docs/feed.xml @@ -1 +1 @@ -Jekyll2020-09-23T13:08:16+02:00splashsync.github.io/Widgets-Bundle/feed.xmlWidgets BundleA full stack bundle for fast integration generic dashboard widgets on Symfony applications. \ No newline at end of file +Jekyll2020-09-23T14:38:49+02:00splashsync.github.io/Widgets-Bundle/feed.xmlWidgets BundleA full stack bundle for fast integration generic dashboard widgets on Symfony applications. \ No newline at end of file diff --git a/docs/fr/feed.xml b/docs/fr/feed.xml index 5f33485..0b8c2d0 100644 --- a/docs/fr/feed.xml +++ b/docs/fr/feed.xml @@ -1 +1 @@ -Jekyll2020-09-23T13:08:16+02:00splashsync.github.io/Widgets-Bundle/feed.xmlWidgets BundleA full stack bundle for fast integration generic dashboard widgets on Symfony applications. \ No newline at end of file +Jekyll2020-09-23T14:38:49+02:00splashsync.github.io/Widgets-Bundle/feed.xmlWidgets BundleA full stack bundle for fast integration generic dashboard widgets on Symfony applications. \ No newline at end of file diff --git a/src/Event/ListingEvent.php b/src/Event/ListingEvent.php new file mode 100644 index 0000000..d93dcb2 --- /dev/null +++ b/src/Event/ListingEvent.php @@ -0,0 +1,25 @@ + + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Splash\Widgets\Event; + +use Symfony\Component\EventDispatcher\GenericEvent; + +/** + * Splash Widget Listing Event + */ +class ListingEvent extends GenericEvent +{ +} diff --git a/src/Resources/config/test.yml b/src/Resources/config/test.yml index 1957417..0ebd775 100755 --- a/src/Resources/config/test.yml +++ b/src/Resources/config/test.yml @@ -1,12 +1,10 @@ services: - # Test Widgets Factroy Service + # Test Widgets Factory Service splash.widgets.test.factory: class: Splash\Widgets\Tests\Services\SamplesFactoryService arguments: ["@splash.widgets.factory"] public: true tags: - - { name: kernel.event_listener, event: splash.widgets.list.test, method: onListingAction } - - { name: kernel.event_listener, event: splash.widgets.list.tested, method: onListingAction } - - { name: kernel.event_listener, event: splash.widgets.list.demo, method: onListingAction } + - { name: kernel.event_listener, event: Splash\Widgets\Event\ListingEvent, method: onListingAction } diff --git a/src/Services/ManagerService.php b/src/Services/ManagerService.php index dc3be94..eee0089 100755 --- a/src/Services/ManagerService.php +++ b/src/Services/ManagerService.php @@ -16,8 +16,11 @@ namespace Splash\Widgets\Services; use Exception; +use ReflectionException; +use ReflectionMethod; use Splash\Widgets\Entity\Widget; use Splash\Widgets\Entity\WidgetCache; +use Splash\Widgets\Event\ListingEvent; use Splash\Widgets\Models\Interfaces\WidgetProviderInterface; use Splash\Widgets\Repository\WidgetCacheRepository; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -342,7 +345,7 @@ public function getList(string $mode = self::USER_WIDGETS) : array //====================================================================// // Execute Listing Event /** @var GenericEvent $list */ - $list = $this->dispatcher->dispatch($mode, new GenericEvent()); + $list = $this->dispatch(new ListingEvent($mode)); $widgets = $list->getArguments(); //====================================================================// @@ -434,4 +437,31 @@ public function cleanCache() : void { $this->cacheRep->cleanUp(); } + + /** + * Dispatch an Event with Args Detection + * + * @param ListingEvent $event + * + * @return null|ListingEvent + */ + private function dispatch(ListingEvent $event): ?ListingEvent + { + try { + $reflection = new ReflectionMethod($this->dispatcher, "dispatch"); + $args = array(); + foreach ($reflection->getParameters() as $param) { + if ("event" == $param->getName()) { + $args[] = $event; + } + if ("eventName" == $param->getName()) { + $args[] = get_class($event); + } + } + } catch (ReflectionException $ex) { + return null; + } + + return $reflection->invokeArgs($this->dispatcher, $args); + } } diff --git a/tests/Controller/A001InitialisationControllerTest.php b/tests/Controller/A001InitialisationControllerTest.php index be376d0..eea475d 100755 --- a/tests/Controller/A001InitialisationControllerTest.php +++ b/tests/Controller/A001InitialisationControllerTest.php @@ -56,8 +56,15 @@ public function testDisplayLogo() : void public function testCacheClear(string $environement) : void { //====================================================================// - // Create Process - $process = new Process("php bin/console cache:clear --no-debug --env=".$environement); + // Create Command + $command = "php bin/console cache:clear --no-debug --env=".$environement; + //====================================================================// + // Execute Test (SF 3&4 Versions) + try { + $process = Process::fromShellCommandline($command); + } catch (\Error $exception) { + $process = new Process($command); + } //====================================================================// // Clean Working Dir diff --git a/tests/Services/SamplesFactoryService.php b/tests/Services/SamplesFactoryService.php index fee4fe1..1ec1961 100755 --- a/tests/Services/SamplesFactoryService.php +++ b/tests/Services/SamplesFactoryService.php @@ -34,6 +34,10 @@ class SamplesFactoryService extends Base */ public function onListingAction(GenericEvent $event) : void { + $mode = $event->getSubject(); + if (!is_string($mode) || !in_array($mode, array("test", "tested", "demo"), true)) { + return; + } $event["Test"] = $this->buildWidgetDefinition("Test")->getWidget(); } } diff --git a/tests/grumphp/phpstan.neon b/tests/grumphp/phpstan.neon index be47b63..6b78f49 100755 --- a/tests/grumphp/phpstan.neon +++ b/tests/grumphp/phpstan.neon @@ -15,4 +15,6 @@ parameters: # Splash Widgets Blocks Methods - '#Call to an undefined method [a-zA-Z0-9\\_]+BaseBlock::[a-zA-Z0-9\\_]+().#' - '#Call to an undefined method [a-zA-Z0-9\\_]+FactoryService::[a-zA-Z0-9\\_]+().#' - + # For Compat with Symfony 3 & 4 + - '#Parameter \#1 \$command of class [a-zA-Z0-9\\]+Process constructor expects array, string given.#' + - '#Call to an undefined static method [a-zA-Z0-9\\]+Process::fromShellCommandline().#' diff --git a/web/app.php b/web/app.php index a2658b0..fd32755 100755 --- a/web/app.php +++ b/web/app.php @@ -19,14 +19,7 @@ /** @var \Composer\Autoload\ClassLoader $loader */ $loader = require __DIR__.'/../app/autoload.php'; -if (PHP_VERSION_ID < 70000) { - include_once __DIR__.'/../var/bootstrap.php.cache'; -} - $kernel = new AppKernel('dev', true); -if (PHP_VERSION_ID < 70000) { - $kernel->loadClassCache(); -} $request = Request::createFromGlobals(); $response = $kernel->handle($request); diff --git a/web/app_test.php b/web/app_test.php index 38ec140..cfa957f 100755 --- a/web/app_test.php +++ b/web/app_test.php @@ -29,10 +29,6 @@ require_once __DIR__.'/../app/AppKernel.php'; $kernel = new AppKernel('test', true); -if (PHP_VERSION_ID < 70000) { - $kernel->loadClassCache(); -} - $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send();