On passe de Pimple à Simplex pour le conteneur.

Mise à jour :
```
svn update
composer install
```

Effectivement à la base le conteneur Pimple était là bien avant l’arrivée de PSR11 (et des suites comme le ServiceProviderInterface),
et le fork Simplex a été fait pour suivre nativement entre autres la ConteneurInterface tout en ayant la même fonctionnement que Pimple.
https://github.com/mnapoli/simplex

Par cohérence avec la ConteneurInterface, on utilise ->has() ou ->get() pour tester ou obtenir un élément du conteneur.
Et par cohérence avec ça, on utilise ->set(x, y) pour définir un élément.
svn/root/trunk
marcimat@rezo.net 5 years ago
parent 98a95c8788
commit 5396afad47

@ -7,8 +7,8 @@
"php": "^5.4|^7",
"symfony/console": "^2.8",
"symfony/finder": "^2.8",
"pimple/pimple" : "^3.2",
"symfony/process": "^2.8"
"symfony/process": "^2.8",
"mnapoli/simplex": "^0.5.0"
},
"config": {
"platform": {

67
composer.lock generated

@ -4,38 +4,65 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "0a25b59cb6da483a570507d308fd73c8",
"content-hash": "364764948e467588201febae4143b59e",
"packages": [
{
"name": "pimple/pimple",
"version": "v3.2.3",
"name": "container-interop/service-provider",
"version": "v0.4.0",
"source": {
"type": "git",
"url": "https://github.com/silexphp/Pimple.git",
"reference": "9e403941ef9d65d20cba7d54e29fe906db42cf32"
"url": "https://github.com/container-interop/service-provider.git",
"reference": "4969b9e49460690b7430b3f1a87cab07be61418a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/silexphp/Pimple/zipball/9e403941ef9d65d20cba7d54e29fe906db42cf32",
"reference": "9e403941ef9d65d20cba7d54e29fe906db42cf32",
"url": "https://api.github.com/repos/container-interop/service-provider/zipball/4969b9e49460690b7430b3f1a87cab07be61418a",
"reference": "4969b9e49460690b7430b3f1a87cab07be61418a",
"shasum": ""
},
"require": {
"psr/container": "^1.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Interop\\Container\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Promoting container interoperability through standard service providers",
"homepage": "https://github.com/container-interop/service-provider",
"time": "2017-09-20T14:13:36+00:00"
},
{
"name": "mnapoli/simplex",
"version": "0.5.0",
"source": {
"type": "git",
"url": "https://github.com/mnapoli/simplex.git",
"reference": "cdc81c738262739f4f35e911f6888da9ee59016b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mnapoli/simplex/zipball/cdc81c738262739f4f35e911f6888da9ee59016b",
"reference": "cdc81c738262739f4f35e911f6888da9ee59016b",
"shasum": ""
},
"require": {
"container-interop/service-provider": "~0.4.0",
"php": ">=5.3.0",
"psr/container": "^1.0"
},
"require-dev": {
"symfony/phpunit-bridge": "^3.2"
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.2.x-dev"
}
},
"autoload": {
"psr-0": {
"Pimple": "src/"
"psr-4": {
"Simplex\\": "src/Simplex"
}
},
"notification-url": "https://packagist.org/downloads/",
@ -46,15 +73,19 @@
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Matthieu Napoli",
"email": "matthieu@mnapoli.fr"
}
],
"description": "Pimple, a simple Dependency Injection Container",
"homepage": "http://pimple.sensiolabs.org",
"description": "Pimple fork with full container-interop support",
"homepage": "https://github.com/mnapoli/simplex",
"keywords": [
"container",
"dependency injection"
],
"time": "2018-01-21T07:42:36+00:00"
"time": "2018-02-13T08:14:36+00:00"
},
{
"name": "psr/container",

@ -2,7 +2,8 @@
namespace Spip\Cli;
use Pimple\Container;
use Psr\Container\ContainerInterface;
use Simplex\Container;
use Spip\Cli\Console\Style\SpipCliStyle;
use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Input\ArgvInput;
@ -15,8 +16,9 @@ use Symfony\Component\Console\Output\OutputInterface;
class Application extends ConsoleApplication {
const NAME = "Spip Cli";
const VERSION = "0.4.1";
protected $options = [];
const VERSION = "0.5.0";
/** @var Container */
protected $container;
/**
@ -30,7 +32,7 @@ class Application extends ConsoleApplication {
public function __construct(array $options = []) {
parent::__construct(self::NAME, self::VERSION);
$this->container = new Container([
$this->container = new Container([], $options + [
'debug' => false,
'spip.directory' => null,
'spip.webmestre.email' => '',
@ -40,11 +42,6 @@ class Application extends ConsoleApplication {
'cwd' => getcwd()
]);
// todo: config file
foreach ($options as $key => $value) {
$this->container[$key] = $value;
}
$this->setTimezone();
$this->registerServices();
$this->registerCommandsInProject(/*self::class*/ __CLASS__);
@ -56,7 +53,7 @@ class Application extends ConsoleApplication {
protected function registerServices() {
$app = $this;
$container = $this->container;
$container['console.io'] = function() use ($app) {
$container->set('console.io', function() use ($app) {
return function(InputInterface $input = null, OutputInterface $output = null) use ($app) {
if (null === $input) {
$input = new ArgvInput();
@ -67,20 +64,20 @@ class Application extends ConsoleApplication {
}
return new Console\Style\SpipCliStyle($input, $output);
};
};
$container['loader.spip'] = function ($container) {
$spip = new Loader\Spip($container['spip.directory']);
});
$container->set('loader.spip', function (ContainerInterface $container) {
$spip = new Loader\Spip($container->get('spip.directory'));
$spip->setContainer($container);
return $spip;
};
$container['sql.query'] = function ($container) {
$connect = $container['loader.spip']->getPathConnect();
});
$container->set('sql.query', function (ContainerInterface $container) {
$connect = $container->get('loader.spip')->getPathConnect();
if (!is_file($connect)) {
throw new \Exception('SPIP database is not configured');
}
$sql = new Loader\Sql($connect);
return new Sql\Query($sql);
};
});
}
/**
@ -91,7 +88,7 @@ class Application extends ConsoleApplication {
*/
public function loadSpip() {
try {
$spip = $this->container['loader.spip'];
$spip = $this->container->get('loader.spip');
$spip->load();
} catch (\Exception $e) {
$io = $this->getIo();
@ -148,7 +145,7 @@ class Application extends ConsoleApplication {
try {
global $spip_racine, $spip_loaded, $cwd;
$cwd = getcwd();
$spip = $this->container['loader.spip'];
$spip = $this->container->get('loader.spip');
$spip_racine = $spip->getDirectory();
$spip_loaded = $spip->load();
} catch (\Exception $e) {
@ -164,7 +161,7 @@ class Application extends ConsoleApplication {
*/
public function registerSpipCliPluginsCommands() {
try {
$spip = $this->container['loader.spip'];
$spip = $this->container->get('loader.spip');
if (!$spip->load()) {
return false;
}
@ -207,7 +204,7 @@ class Application extends ConsoleApplication {
}
public function getService($name) {
return $this->container[$name];
return $this->container->get($name);
}
/**
@ -216,7 +213,8 @@ class Application extends ConsoleApplication {
* @return SpipCliStyle
*/
public function getIo(InputInterface $input = null, OutputInterface $output = null) {
return $this->container['console.io']($input, $output);
$io = $this->container->get('console.io');
return $io($input, $output);
}

@ -95,7 +95,6 @@ class PluginsLister extends Command {
public function getExportFile(InputInterface $input) {
$name = $input->getOption('name') . '.txt';
$file = _DIR_TMP . $name;
return _DIR_TMP . $name;
}

@ -3,9 +3,9 @@
namespace Spip\Cli\Command;
use Spip\Cli\Console\Command;
use Spip\Cli\Console\Style\SpipCliStyle;
use Spip\Cli\Loader\Spip;
use Spip\Cli\Loader\Sql;
use Spip\Cli\Sql\Query;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@ -101,13 +101,15 @@ class TestSpip extends Command
$io = $this->io;
try {
/** @var Sql $sql */
/** @var Query $sql */
$sql = $this->getService('sql.query');
$pdo = $sql->getPdo();
} catch (\Exception $e) {
$io->fail('Echec de chargement du PDO');
if ($sql) {
$io->fail('DSN: ' . $sql->getPdoDsn($sql->getInfo()));
/** @var Sql $loader */
$loader = $sql->getLoaderSql();
$io->fail('DSN: ' . $loader->getPdoDsn($loader->getInfo()));
}
$io->fail($e->getMessage());
return false;
@ -141,7 +143,7 @@ class TestSpip extends Command
public function affchicherUrlSite() {
$io = $this->io;
try {
/** @var Sql $sql */
/** @var Query $sql */
$sql = $this->getService('sql.query');
$adresse = $sql->getMeta('adresse_site');
$nom = $sql->getMeta('nom_site');

@ -2,6 +2,7 @@
namespace Spip\Cli\Console;
use Simplex\Container;
use Spip\Cli\Console\Style\SpipCliStyle;
use Spip\Cli\Loader\Spip;
use Symfony\Component\Console\Command\Command as BaseCommand;
@ -34,7 +35,7 @@ abstract class Command extends BaseCommand
/**
* Returns the application container.
* @return \Pimple\Container
* @return Container
*/
public function getContainer() {
return $this->getApplication()->getContainer();

@ -2,7 +2,7 @@
namespace Spip\Cli\Loader;
use Pimple\Container;
use Psr\Container\ContainerInterface;
use Spip\Cli\Sql\Query;
use Spip\Cli\Tools\Files;
@ -31,8 +31,8 @@ class Spip {
/** @var bool */
private $exists;
/** @var Container */
private $app;
/** @var ContainerInterface */
private $container;
/**
* Loader constructor.
@ -294,7 +294,7 @@ class Spip {
$puce;
// Éviter des notices. Il faudrait utiliser HTTPFondation\Request dans SPIP.
if (!$this->app['debug']) {
if (!$this->container->get('debug')) {
foreach (['SERVER_NAME', 'SERVER_PORT', 'REQUEST_METHOD', 'REQUEST_URI'] as $key) {
if (!isset($_SERVER[$key])) {
$_SERVER[$key] = null;
@ -337,12 +337,12 @@ class Spip {
/**
* Sets a pimple instance onto this application.
* Sets a container instance onto this application.
*
* @param Container $app
* @param ContainerInterface $container
* @return void
*/
public function setContainer(Container $app) {
$this->app = $app;
public function setContainer(ContainerInterface $container) {
$this->container = $container;
}
}

@ -2,7 +2,7 @@
namespace Spip\Cli\Mutualisation;
use Pimple\Container;
use Simplex\Container;
use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Input\InputInterface;
@ -24,16 +24,11 @@ class Application extends ConsoleApplication {
public function __construct(array $options = []) {
parent::__construct(self::NAME, self::VERSION);
$this->container = new Container([
$this->container = new Container([],$options + [
'debug' => false,
'spip.directory' => null,
'path.spip-cli' => '/usr/local/bin/spip',
]);
// todo: config file
foreach ($options as $key => $value) {
$this->container[$key] = $value;
}
}
@ -81,7 +76,7 @@ class Application extends ConsoleApplication {
}
public function getService($name) {
return $this->container[$name];
return $this->container->get($name);
}
}

@ -28,6 +28,14 @@ class Query {
return $this->sql->getPdo();
}
/**
* Retourne le loader SQL
* @return Sql
*/
public function getLoaderSql() {
return $this->sql;
}
/**
* Retourne la valeur dune meta (table spip_meta de spip)
*

Loading…
Cancel
Save