Skip to content

Commit

Permalink
WIP: Sf4 Compat
Browse files Browse the repository at this point in the history
BadPixxel committed Sep 23, 2020
1 parent 7532b90 commit 654614d
Showing 11 changed files with 77 additions and 22 deletions.
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/feed.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.8.7">Jekyll</generator><link href="splashsync.github.io/Widgets-Bundle/feed.xml" rel="self" type="application/atom+xml" /><link href="splashsync.github.io/Widgets-Bundle/" rel="alternate" type="text/html" /><updated>2020-09-23T13:08:16+02:00</updated><id>splashsync.github.io/Widgets-Bundle/feed.xml</id><title type="html">Widgets Bundle</title><subtitle>A full stack bundle for fast integration generic dashboard widgets on Symfony applications.</subtitle></feed>
<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.8.7">Jekyll</generator><link href="splashsync.github.io/Widgets-Bundle/feed.xml" rel="self" type="application/atom+xml" /><link href="splashsync.github.io/Widgets-Bundle/" rel="alternate" type="text/html" /><updated>2020-09-23T14:38:49+02:00</updated><id>splashsync.github.io/Widgets-Bundle/feed.xml</id><title type="html">Widgets Bundle</title><subtitle>A full stack bundle for fast integration generic dashboard widgets on Symfony applications.</subtitle></feed>
2 changes: 1 addition & 1 deletion docs/fr/feed.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.8.7">Jekyll</generator><link href="splashsync.github.io/Widgets-Bundle/fr/feed.xml" rel="self" type="application/atom+xml" /><link href="splashsync.github.io/Widgets-Bundle/fr/" rel="alternate" type="text/html" /><updated>2020-09-23T13:08:16+02:00</updated><id>splashsync.github.io/Widgets-Bundle/feed.xml</id><title type="html">Widgets Bundle</title><subtitle>A full stack bundle for fast integration generic dashboard widgets on Symfony applications.</subtitle></feed>
<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.8.7">Jekyll</generator><link href="splashsync.github.io/Widgets-Bundle/fr/feed.xml" rel="self" type="application/atom+xml" /><link href="splashsync.github.io/Widgets-Bundle/fr/" rel="alternate" type="text/html" /><updated>2020-09-23T14:38:49+02:00</updated><id>splashsync.github.io/Widgets-Bundle/feed.xml</id><title type="html">Widgets Bundle</title><subtitle>A full stack bundle for fast integration generic dashboard widgets on Symfony applications.</subtitle></feed>
25 changes: 25 additions & 0 deletions src/Event/ListingEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/*
* This file is part of SplashSync Project.
*
* Copyright (C) 2015-2020 Splash Sync <www.splashsync.com>
*
* 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
{
}
6 changes: 2 additions & 4 deletions src/Resources/config/test.yml
Original file line number Diff line number Diff line change
@@ -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 }

32 changes: 31 additions & 1 deletion src/Services/ManagerService.php
Original file line number Diff line number Diff line change
@@ -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);
}
}
11 changes: 9 additions & 2 deletions tests/Controller/A001InitialisationControllerTest.php
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions tests/Services/SamplesFactoryService.php
Original file line number Diff line number Diff line change
@@ -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();
}
}
4 changes: 3 additions & 1 deletion tests/grumphp/phpstan.neon
Original file line number Diff line number Diff line change
@@ -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().#'
7 changes: 0 additions & 7 deletions web/app.php
Original file line number Diff line number Diff line change
@@ -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);
4 changes: 0 additions & 4 deletions web/app_test.php
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit 654614d

Please sign in to comment.