Merge pull request #15335 from mauriciofauth/old-container

Removes custom dependency injection container in favor of Symfony Dependency Injection Container.
This commit is contained in:
Maurício Meneghini Fauth 2019-06-17 18:38:27 -03:00 committed by GitHub
commit d00665c652
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 306 additions and 1154 deletions

View File

@ -50,7 +50,6 @@
"phpmyadmin/shapefile": "^2.0",
"phpmyadmin/sql-parser": "^5.0",
"phpseclib/phpseclib": "^2.0",
"psr/container": "^1.0",
"symfony/config": "^4.2.8",
"symfony/dependency-injection": "^4.2.8",
"symfony/expression-language": "^4.2",

View File

@ -9,7 +9,6 @@ declare(strict_types=1);
use PhpMyAdmin\Controllers\Database\SqlController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\Response;
use PhpMyAdmin\SqlQueryForm;
@ -17,10 +16,9 @@ if (! defined('ROOT_PATH')) {
define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
}
require_once ROOT_PATH . 'libraries/common.inc.php';
global $containerBuilder;
$container = Container::getDefaultContainer();
$container->set(Response::class, Response::getInstance());
require_once ROOT_PATH . 'libraries/common.inc.php';
/** @var Response $response */
$response = $containerBuilder->get(Response::class);

View File

@ -10,7 +10,6 @@ declare(strict_types=1);
use PhpMyAdmin\Bookmark;
use PhpMyAdmin\Core;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\Encoding;
use PhpMyAdmin\File;
use PhpMyAdmin\Import;

View File

@ -14,7 +14,6 @@ use PhpMyAdmin\Database\DatabaseList;
use PhpMyAdmin\Dbi\DbiDummy;
use PhpMyAdmin\Dbi\DbiExtension;
use PhpMyAdmin\Dbi\DbiMysqli;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\SqlParser\Context;
/**

View File

@ -1,50 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Holds the PhpMyAdmin\Di\AliasItem class
*
* @package PhpMyAdmin\Di
*/
declare(strict_types=1);
namespace PhpMyAdmin\Di;
/**
* Class AliasItem
*
* @package PhpMyAdmin\Di
*/
class AliasItem implements Item
{
/** @var Container */
protected $container;
/** @var string */
protected $target;
/**
* Constructor
*
* @param Container $container Container
* @param string $target Target
*/
public function __construct(Container $container, $target)
{
$this->container = $container;
$this->target = $target;
}
/**
* Get the target item
*
* @param array $params Parameters
* @return mixed
* @throws ContainerException
* @throws NotFoundException
*/
public function get(array $params = [])
{
return $this->container->get($this->target, $params);
}
}

View File

@ -1,191 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Holds the PhpMyAdmin\Di\Container class
*
* @package PhpMyAdmin\Di
*/
declare(strict_types=1);
namespace PhpMyAdmin\Di;
use Psr\Container\ContainerInterface;
/**
* Class Container
*
* @package PhpMyAdmin\Di
*/
class Container implements ContainerInterface
{
/**
* @var Item[] $content
*/
protected $content = [];
/**
* @var Container
*/
protected static $defaultContainer;
/**
* Create a dependency injection container
*
* @param Container $base Container
*/
public function __construct(Container $base = null)
{
if (isset($base)) {
$this->content = $base->content;
} else {
$this->alias('container', 'Container');
}
$this->set('Container', $this);
}
/**
* Get an object with given name and parameters
*
* @param string $name Name
* @param array $params Parameters
*
* @throws NotFoundException No entry was found for **this** identifier.
* @throws ContainerException Error while retrieving the entry.
*
* @return mixed
*/
public function get($name, array $params = [])
{
if (! $this->has($name)) {
throw new NotFoundException("No entry was found for $name identifier.");
}
if (isset($this->content[$name])) {
return $this->content[$name]->get($params);
} elseif (isset($GLOBALS[$name])) {
return $GLOBALS[$name];
} else {
throw new ContainerException("Error while retrieving the entry.");
}
}
/**
* Returns true if the container can return an entry for the given identifier.
* Returns false otherwise.
*
* `has($name)` returning true does not mean that `get($name)` will not throw an exception.
* It does however mean that `get($name)` will not throw a `NotFoundException`.
*
* @param string $name Identifier of the entry to look for.
*
* @return bool
*/
public function has($name)
{
return isset($this->content[$name]) || isset($GLOBALS[$name]);
}
/**
* Remove an object from container
*
* @param string $name Name
*
* @return void
*/
public function remove($name)
{
unset($this->content[$name]);
}
/**
* Rename an object in container
*
* @param string $name Name
* @param string $newName New name
*
* @return void
*/
public function rename($name, $newName)
{
$this->content[$newName] = $this->content[$name];
$this->remove($name);
}
/**
* Set values in the container
*
* @param string|array $name Name
* @param mixed $value Value
*
* @return void
*/
public function set($name, $value = null)
{
if (is_array($name)) {
foreach ($name as $key => $val) {
$this->set($key, $val);
}
return;
}
$this->content[$name] = new ValueItem($value);
}
/**
* Register a service in the container
*
* @param string $name Name
* @param mixed $service Service
*
* @return void
*/
public function service($name, $service = null)
{
if (! isset($service)) {
$service = $name;
}
$this->content[$name] = new ServiceItem($this, $service);
}
/**
* Register a factory in the container
*
* @param string $name Name
* @param mixed $factory Factory
*
* @return void
*/
public function factory($name, $factory = null)
{
if (! isset($factory)) {
$factory = $name;
}
$this->content[$name] = new FactoryItem($this, $factory);
}
/**
* Register an alias in the container
*
* @param string $name Name
* @param string $target Target
*
* @return void
*/
public function alias($name, $target)
{
// The target may be not defined yet
$this->content[$name] = new AliasItem($this, $target);
}
/**
* Get the global default container
*
* @return Container
*/
public static function getDefaultContainer()
{
if (! isset(static::$defaultContainer)) {
static::$defaultContainer = new Container();
}
return static::$defaultContainer;
}
}

View File

@ -1,23 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Holds the PhpMyAdmin\Di\ContainerException class
*
* @package PhpMyAdmin\Di
*/
declare(strict_types=1);
namespace PhpMyAdmin\Di;
use Exception;
use Psr\Container\ContainerExceptionInterface;
/**
* Class ContainerException
*
* @package PhpMyAdmin\Di
*/
class ContainerException extends Exception implements ContainerExceptionInterface
{
}

View File

@ -1,31 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Holds the PhpMyAdmin\Di\FactoryItem class
*
* @package PhpMyAdmin\Di
*/
declare(strict_types=1);
namespace PhpMyAdmin\Di;
/**
* Factory manager
*
* @package PhpMyAdmin\Di
*/
class FactoryItem extends ReflectorItem
{
/**
* Construct an instance
*
* @param array $params Parameters
*
* @return mixed
*/
public function get(array $params = [])
{
return $this->invoke($params);
}
}

View File

@ -1,27 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Holds the PhpMyAdmin\Di\Item class
*
* @package PhpMyAdmin\Di
*/
declare(strict_types=1);
namespace PhpMyAdmin\Di;
/**
* Interface Item
*
* @package PhpMyAdmin\Di
*/
interface Item
{
/**
* Get a value from the item
*
* @param array $params Parameters
* @return mixed
*/
public function get(array $params = []);
}

View File

@ -1,22 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Holds the PhpMyAdmin\Di\NotFoundException class
*
* @package PhpMyAdmin\Di
*/
declare(strict_types=1);
namespace PhpMyAdmin\Di;
use Psr\Container\NotFoundExceptionInterface;
/**
* Class NotFoundException
*
* @package PhpMyAdmin\Di
*/
class NotFoundException extends ContainerException implements NotFoundExceptionInterface
{
}

View File

@ -1,145 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Holds the PhpMyAdmin\Di\ReflectorItem class
*
* @package PhpMyAdmin\Di
*/
declare(strict_types=1);
namespace PhpMyAdmin\Di;
use ReflectionClass;
use ReflectionException;
use ReflectionFunction;
use ReflectionFunctionAbstract;
use ReflectionMethod;
use ReflectionParameter;
use Reflector;
/**
* Reflector manager
*
* @package PhpMyAdmin\Di
*/
abstract class ReflectorItem implements Item
{
/** @var Container */
private $_container;
/**
* A \Reflector
* @var ReflectionClass|ReflectionMethod|ReflectionFunction
*/
private $_reflector;
/**
* Constructor
*
* @param Container $container Container
* @param mixed $definition Definition
* @throws ReflectionException
*/
public function __construct(Container $container, $definition)
{
$this->_container = $container;
$this->_reflector = self::_resolveReflector($definition);
}
/**
* Invoke the reflector with given parameters
*
* @param array $params Parameters
* @return mixed
* @throws ContainerException
*/
protected function invoke(array $params = [])
{
$args = [];
$reflector = $this->_reflector;
if ($reflector instanceof ReflectionClass) {
$constructor = $reflector->getConstructor();
if (isset($constructor)) {
$args = $this->_resolveArgs(
$constructor->getParameters(),
$params
);
}
return $reflector->newInstanceArgs($args);
}
/** @var ReflectionFunctionAbstract $reflector */
$args = $this->_resolveArgs(
$reflector->getParameters(),
$params
);
if ($reflector instanceof ReflectionMethod) {
/** @var ReflectionMethod $reflector */
return $reflector->invokeArgs(null, $args);
}
/** @var ReflectionFunction $reflector */
return $reflector->invokeArgs($args);
}
/**
* Getting required arguments with given parameters
*
* @param ReflectionParameter[] $required Arguments
* @param array $params Parameters
*
* @return array
* @throws ContainerException
*/
private function _resolveArgs($required, array $params = [])
{
$args = [];
foreach ($required as $param) {
$name = $param->getName();
$type = $param->getClass();
if (isset($type)) {
$type = $type->getName();
}
if (isset($params[$name])) {
$args[] = $params[$name];
} elseif (is_string($type) && isset($params[$type])) {
$args[] = $params[$type];
} else {
try {
$content = $this->_container->get($name);
if (isset($content)) {
$args[] = $content;
} elseif (is_string($type)) {
$args[] = $this->_container->get($type);
} else {
$args[] = null;
}
} catch (NotFoundException $e) {
$args[] = null;
}
}
}
return $args;
}
/**
* Resolve the reflection
*
* @param mixed $definition Definition
*
* @return Reflector
* @throws ReflectionException
*/
private static function _resolveReflector($definition)
{
if (function_exists($definition)) {
return new ReflectionFunction($definition);
}
if (is_string($definition)) {
$definition = explode('::', $definition);
}
if (! isset($definition[1])) {
return new ReflectionClass($definition[0]);
}
return new ReflectionMethod($definition[0], $definition[1]);
}
}

View File

@ -1,36 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Holds the PhpMyAdmin\Di\ServiceItem class
*
* @package PhpMyAdmin\Di
*/
declare(strict_types=1);
namespace PhpMyAdmin\Di;
/**
* Service manager
*
* @package PhpMyAdmin\Di
*/
class ServiceItem extends ReflectorItem
{
/** @var mixed */
protected $instance;
/**
* Get the instance of the service
*
* @param array $params Parameters
* @return mixed
*/
public function get(array $params = [])
{
if (! isset($this->instance)) {
$this->instance = $this->invoke();
}
return $this->instance;
}
}

View File

@ -1,43 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Holds the PhpMyAdmin\Di\ValueItem class
*
* @package PhpMyAdmin\Di
*/
declare(strict_types=1);
namespace PhpMyAdmin\Di;
/**
* Value manager
*
* @package PhpMyAdmin\Di
*/
class ValueItem implements Item
{
/** @var mixed */
protected $value;
/**
* Constructor
*
* @param mixed $value Value
*/
public function __construct($value)
{
$this->value = $value;
}
/**
* Get the value
*
* @param array $params Parameters
* @return mixed
*/
public function get(array $params = [])
{
return $this->value;
}
}

View File

@ -35,7 +35,6 @@ declare(strict_types=1);
use PhpMyAdmin\Config;
use PhpMyAdmin\Core;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\Di\Migration;
use PhpMyAdmin\ErrorHandler;
use PhpMyAdmin\LanguageManager;
@ -97,9 +96,6 @@ $loader->load('../services_controllers.yml');
/** @var Migration $diMigration */
$diMigration = $containerBuilder->get('di_migration');
/** @var Container $oldContainer */
$oldContainer = Container::getDefaultContainer();
/**
* Load gettext functions.
*/
@ -333,8 +329,6 @@ if (! defined('PMA_MINIMUM_COMMON')) {
*/
$containerBuilder->set(DatabaseInterface::class, DatabaseInterface::load());
$containerBuilder->setAlias('dbi', DatabaseInterface::class);
$oldContainer->set(DatabaseInterface::class, $containerBuilder->get(DatabaseInterface::class));
$oldContainer->alias('dbi', DatabaseInterface::class);
// get LoginCookieValidity from preferences cache
// no generic solution for loading preferences from cache as some settings

View File

@ -34,6 +34,9 @@ services:
dbi: '@dbi'
relation: '@relation'
display_export:
class: 'PhpMyAdmin\Display\Export'
error_handler:
class: 'PhpMyAdmin\ErrorHandler'
@ -54,6 +57,10 @@ services:
import:
class: 'PhpMyAdmin\Import'
insert_edit:
class: 'PhpMyAdmin\InsertEdit'
arguments: ['@dbi']
di_migration:
factory: 'PhpMyAdmin\Di\Migration::getInstance'
arguments: ['@service_container']
@ -80,6 +87,10 @@ services:
class: 'PhpMyAdmin\Relation'
arguments: ['@dbi', '@template']
relation_cleanup:
class: 'PhpMyAdmin\RelationCleanup'
arguments: ['@dbi', '@relation']
replication:
class: 'PhpMyAdmin\Replication'
@ -92,6 +103,13 @@ services:
response:
factory: 'PhpMyAdmin\Response::getInstance'
server_privileges:
class: 'PhpMyAdmin\Server\Privileges'
arguments: ['@template', '@dbi', '@relation', '@relation_cleanup']
sql:
class: 'PhpMyAdmin\Sql'
sql_query_form:
class: 'PhpMyAdmin\SqlQueryForm'
@ -115,6 +133,10 @@ services:
transformations:
class: 'PhpMyAdmin\Transformations'
user_password:
class: 'PhpMyAdmin\UserPassword'
arguments: ['@server_privileges']
#Aliases
PhpMyAdmin\Response: '@response'

16
sql.php
View File

@ -12,7 +12,6 @@ declare(strict_types=1);
use PhpMyAdmin\CheckUserPrivileges;
use PhpMyAdmin\Config\PageSettings;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\ParseAnalyze;
use PhpMyAdmin\Response;
use PhpMyAdmin\Sql;
@ -23,20 +22,18 @@ if (! defined('ROOT_PATH')) {
define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
}
global $cfg, $pmaThemeImage;
global $cfg, $containerBuilder, $pmaThemeImage;
require_once ROOT_PATH . 'libraries/common.inc.php';
$container = Container::getDefaultContainer();
$container->set(Response::class, Response::getInstance());
/** @var Response $response */
$response = $container->get(Response::class);
$response = $containerBuilder->get(Response::class);
/** @var DatabaseInterface $dbi */
$dbi = $container->get(DatabaseInterface::class);
$dbi = $containerBuilder->get(DatabaseInterface::class);
$checkUserPrivileges = new CheckUserPrivileges($dbi);
/** @var CheckUserPrivileges $checkUserPrivileges */
$checkUserPrivileges = $containerBuilder->get('check_user_privileges');
$checkUserPrivileges->getPrivileges();
PageSettings::showGroup('Browse');
@ -49,7 +46,8 @@ $scripts->addFile('indexes.js');
$scripts->addFile('gis_data_editor.js');
$scripts->addFile('multi_column_sort.js');
$sql = new Sql();
/** @var Sql $sql */
$sql = $containerBuilder->get('sql');
/**
* Set ajax_reload in the response if it was already set

View File

@ -9,7 +9,6 @@ declare(strict_types=1);
use PhpMyAdmin\Config\PageSettings;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\InsertEdit;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Response;
@ -20,18 +19,15 @@ if (! defined('ROOT_PATH')) {
define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
}
global $cfg, $db, $table, $text_dir;
global $cfg, $containerBuilder, $db, $table, $text_dir;
require_once ROOT_PATH . 'libraries/common.inc.php';
$container = Container::getDefaultContainer();
$container->set(Response::class, Response::getInstance());
/** @var Response $response */
$response = $container->get(Response::class);
$response = $containerBuilder->get(Response::class);
/** @var DatabaseInterface $dbi */
$dbi = $container->get(DatabaseInterface::class);
$dbi = $containerBuilder->get(DatabaseInterface::class);
PageSettings::showGroup('Edit');
@ -40,7 +36,8 @@ PageSettings::showGroup('Edit');
*/
require_once ROOT_PATH . 'libraries/db_table_exists.inc.php';
$insertEdit = new InsertEdit($dbi);
/** @var InsertEdit $insertEdit */
$insertEdit = $containerBuilder->get('insert_edit');
/**
* Determine whether Insert or Edit and set global variables

View File

@ -9,7 +9,6 @@ declare(strict_types=1);
use PhpMyAdmin\Config\PageSettings;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\Display\Export;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Response;
@ -18,18 +17,15 @@ if (! defined('ROOT_PATH')) {
define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
}
global $db, $url_query;
global $containerBuilder, $db, $url_query;
require_once ROOT_PATH . 'libraries/common.inc.php';
$container = Container::getDefaultContainer();
$container->set(Response::class, Response::getInstance());
/** @var Response $response */
$response = $container->get(Response::class);
$response = $containerBuilder->get(Response::class);
/** @var DatabaseInterface $dbi */
$dbi = $container->get(DatabaseInterface::class);
$dbi = $containerBuilder->get(DatabaseInterface::class);
PageSettings::showGroup('Export');
@ -42,7 +38,8 @@ $scripts->addFile('export.js');
$relation = $containerBuilder->get('relation');
$cfgRelation = $relation->getRelationsParam();
$displayExport = new Export();
/** @var Export $displayExport */
$displayExport = $containerBuilder->get('display_export');
// handling export template actions
if (isset($_POST['templateAction']) && $cfgRelation['exporttemplateswork']) {

View File

@ -8,8 +8,6 @@
declare(strict_types=1);
use PhpMyAdmin\Controllers\Table\GisVisualizationController;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\Response;
use PhpMyAdmin\Util;
use Symfony\Component\DependencyInjection\Definition;

View File

@ -15,7 +15,6 @@ declare(strict_types=1);
use PhpMyAdmin\Core;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\File;
use PhpMyAdmin\InsertEdit;
use PhpMyAdmin\Message;
@ -30,18 +29,15 @@ if (! defined('ROOT_PATH')) {
define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
}
global $db, $table, $url_params;
global $containerBuilder, $db, $table, $url_params;
require_once ROOT_PATH . 'libraries/common.inc.php';
$container = Container::getDefaultContainer();
$container->set(Response::class, Response::getInstance());
/** @var Response $response */
$response = $container->get(Response::class);
$response = $containerBuilder->get(Response::class);
/** @var DatabaseInterface $dbi */
$dbi = $container->get(DatabaseInterface::class);
$dbi = $containerBuilder->get(DatabaseInterface::class);
// Check parameters
Util::checkParameters(['db', 'table', 'goto']);
@ -65,7 +61,8 @@ $scripts->addFile('gis_data_editor.js');
$relation = $containerBuilder->get('relation');
/** @var Transformations $transformations */
$transformations = $containerBuilder->get('transformations');
$insertEdit = new InsertEdit($dbi);
/** @var InsertEdit $insertEdit */
$insertEdit = $containerBuilder->get('insert_edit');
// check whether insert row mode, if so include tbl_change.php
$insertEdit->isInsertRow();

View File

@ -11,27 +11,19 @@
declare(strict_types=1);
use PhpMyAdmin\Controllers\Table\SearchController;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\Response;
use Symfony\Component\DependencyInjection\Definition;
if (! defined('ROOT_PATH')) {
define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
}
global $url_query;
global $containerBuilder, $url_query;
require_once ROOT_PATH . 'libraries/common.inc.php';
require_once ROOT_PATH . 'libraries/tbl_common.inc.php';
$container = Container::getDefaultContainer();
$container->set(Response::class, Response::getInstance());
$container->alias('response', Response::class);
/* Define dependencies for the concerned controller */
$dependency_definitions = [
'db' => $container->get('db'),
'table' => $container->get('table'),
'searchType' => 'normal',
'url_query' => &$url_query,
];

View File

@ -9,19 +9,16 @@ declare(strict_types=1);
use PhpMyAdmin\Controllers\Table\SqlController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\Response;
use PhpMyAdmin\SqlQueryForm;
use Symfony\Component\DependencyInjection\Definition;
if (! defined('ROOT_PATH')) {
define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
}
require_once ROOT_PATH . 'libraries/common.inc.php';
global $containerBuilder;
$container = Container::getDefaultContainer();
$container->set(Response::class, Response::getInstance());
require_once ROOT_PATH . 'libraries/common.inc.php';
/** @var Response $response */
$response = $containerBuilder->get(Response::class);

View File

@ -10,8 +10,6 @@
declare(strict_types=1);
use PhpMyAdmin\Controllers\Table\SearchController;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\Response;
use Symfony\Component\DependencyInjection\Definition;
if (! defined('ROOT_PATH')) {
@ -23,14 +21,8 @@ global $url_query;
require_once ROOT_PATH . 'libraries/common.inc.php';
require_once ROOT_PATH . 'libraries/tbl_common.inc.php';
$container = Container::getDefaultContainer();
$container->set(Response::class, Response::getInstance());
$container->alias('response', Response::class);
/* Define dependencies for the concerned controller */
$dependency_definitions = [
'db' => $container->get('db'),
'table' => $container->get('table'),
'searchType' => 'zoom',
'url_query' => &$url_query,
];

View File

@ -9,7 +9,6 @@ declare(strict_types=1);
use PhpMyAdmin\Config;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\LanguageManager;
use PhpMyAdmin\MoTranslator\Loader;
use PhpMyAdmin\Theme;
@ -80,9 +79,7 @@ define('PMA_MAJOR_VERSION', $GLOBALS['PMA_Config']->get('PMA_MAJOR_VERSION'));
LanguageManager::getInstance()->getLanguage('en')->activate();
/* Load Database interface */
$oldContainer = Container::getDefaultContainer();
$oldContainer->set(DatabaseInterface::class, DatabaseInterface::load());
$oldContainer->alias('dbi', DatabaseInterface::class);
$GLOBALS['dbi'] = DatabaseInterface::load();
// Set proxy information from env, if available
$http_proxy = getenv('http_proxy');

View File

@ -9,7 +9,6 @@ declare(strict_types=1);
use PhpMyAdmin\Config;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\MoTranslator\Loader;
if (! defined('ROOT_PATH')) {
@ -39,6 +38,4 @@ $GLOBALS['PMA_Config']->enableBc();// Defines constants, phpstan:level=1
Loader::loadFunctions();
$oldContainer = Container::getDefaultContainer();
$oldContainer->set(DatabaseInterface::class, DatabaseInterface::load());
$oldContainer->alias('dbi', DatabaseInterface::class);
$GLOBALS['dbi'] = DatabaseInterface::load();

View File

@ -13,11 +13,9 @@ namespace PhpMyAdmin\Tests\Controllers\Database;
use PhpMyAdmin\Controllers\Database\StructureController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\RecentFavoriteTable;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Replication;
use PhpMyAdmin\Response;
use PhpMyAdmin\Table;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\PmaTestCase;
@ -48,6 +46,11 @@ class StructureControllerTest extends PmaTestCase
*/
private $replication;
/**
* @var Template
*/
private $template;
/**
* Prepares environment for the test.
*
@ -82,15 +85,8 @@ class StructureControllerTest extends PmaTestCase
$GLOBALS['dbi'] = $dbi;
$container = Container::getDefaultContainer();
$container->set('db', 'db');
$container->set('table', 'table');
$container->set('dbi', $GLOBALS['dbi']);
$container->set('template', new Template());
$this->template = new Template();
$this->response = new ResponseStub();
$container->set(Response::class, $this->response);
$container->alias('response', Response::class);
$this->relation = new Relation($dbi);
$this->replication = new Replication();
}
@ -103,22 +99,14 @@ class StructureControllerTest extends PmaTestCase
*/
public function testGetValuesForInnodbTable()
{
$container = Container::getDefaultContainer();
$container->set('db', 'db');
$container->set('table', 'table');
$container->set('dbi', $GLOBALS['dbi']);
$response = new ResponseStub();
$container->set(Response::class, $response);
$container->alias('response', Response::class);
$class = new ReflectionClass(StructureController::class);
$method = $class->getMethod('getValuesForInnodbTable');
$method->setAccessible(true);
$controller = new StructureController(
$container->get('response'),
$container->get('dbi'),
$container->get('template'),
$container->get('db'),
$this->response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$this->relation,
$this->replication
);
@ -176,10 +164,10 @@ class StructureControllerTest extends PmaTestCase
// Not showing statistics
$is_show_stats = false;
$controller = new StructureController(
$container->get('response'),
$container->get('dbi'),
$container->get('template'),
$container->get('db'),
$this->response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$this->relation,
$this->replication
);
@ -217,16 +205,15 @@ class StructureControllerTest extends PmaTestCase
*/
public function testGetValuesForAriaTable()
{
$container = Container::getDefaultContainer();
$class = new ReflectionClass(StructureController::class);
$method = $class->getMethod('getValuesForAriaTable');
$method->setAccessible(true);
$controller = new StructureController(
$container->get('response'),
$container->get('dbi'),
$container->get('template'),
$container->get('db'),
$this->response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$this->relation,
$this->replication
);
@ -285,10 +272,10 @@ class StructureControllerTest extends PmaTestCase
$this->assertEquals(0, $overheadSize);
$controller = new StructureController(
$container->get('response'),
$container->get('dbi'),
$container->get('template'),
$container->get('db'),
$this->response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$this->relation,
$this->replication
);
@ -307,10 +294,10 @@ class StructureControllerTest extends PmaTestCase
$this->assertEquals(0, $sumSize);
$controller = new StructureController(
$container->get('response'),
$container->get('dbi'),
$container->get('template'),
$container->get('db'),
$this->response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$this->relation,
$this->replication
);
@ -337,16 +324,15 @@ class StructureControllerTest extends PmaTestCase
*/
public function testHasTable()
{
$container = Container::getDefaultContainer();
$class = new ReflectionClass(StructureController::class);
$method = $class->getMethod('hasTable');
$method->setAccessible(true);
$controller = new StructureController(
$container->get('response'),
$container->get('dbi'),
$container->get('template'),
$container->get('db'),
$this->response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$this->relation,
$this->replication
);
@ -384,16 +370,15 @@ class StructureControllerTest extends PmaTestCase
*/
public function testCheckFavoriteTable()
{
$container = Container::getDefaultContainer();
$class = new ReflectionClass(StructureController::class);
$method = $class->getMethod('checkFavoriteTable');
$method->setAccessible(true);
$controller = new StructureController(
$container->get('response'),
$container->get('dbi'),
$container->get('template'),
$container->get('db'),
$this->response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$this->relation,
$this->replication
);
@ -424,7 +409,6 @@ class StructureControllerTest extends PmaTestCase
*/
public function testSynchronizeFavoriteTables()
{
$container = Container::getDefaultContainer();
$favoriteInstance = $this->getMockBuilder(RecentFavoriteTable::class)
->disableOriginalConstructor()
->getMock();
@ -443,10 +427,10 @@ class StructureControllerTest extends PmaTestCase
$method->setAccessible(true);
$controller = new StructureController(
$container->get('response'),
$container->get('dbi'),
$container->get('template'),
$container->get('db'),
$this->response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$this->relation,
$this->replication
);
@ -476,13 +460,11 @@ class StructureControllerTest extends PmaTestCase
*/
public function testHandleRealRowCountRequestAction()
{
$container = Container::getDefaultContainer();
$controller = new StructureController(
$container->get('response'),
$container->get('dbi'),
$container->get('template'),
$container->get('db'),
$this->response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$this->relation,
$this->replication
);

View File

@ -12,7 +12,6 @@ namespace PhpMyAdmin\Tests\Controllers\Server;
use PhpMyAdmin\Config;
use PhpMyAdmin\Controllers\Server\VariablesController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\Response;
use PhpMyAdmin\Template;
use PhpMyAdmin\Url;
@ -153,9 +152,11 @@ class VariablesControllerTest extends TestCase
$method = $class->getMethod('formatVariable');
$method->setAccessible(true);
$container = Container::getDefaultContainer();
$container->factory(VariablesController::class);
$controller = $container->get(VariablesController::class);
$controller = new VariablesController(
Response::getInstance(),
$GLOBALS['dbi'],
new Template()
);
$nameForValueByte = 'byte_variable';
$nameForValueNotByte = 'not_a_byte_variable';

View File

@ -9,7 +9,6 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests\Controllers\Table;
use PhpMyAdmin\Controllers\Table\IndexesController;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\Index;
use PhpMyAdmin\Message;
use PhpMyAdmin\Response;
@ -96,21 +95,14 @@ class IndexesControllerTest extends PmaTestCase
$GLOBALS['dbi']->expects($this->any())->method('getTable')
->will($this->returnValue($table));
$container = Container::getDefaultContainer();
$container->set('db', 'db');
$container->set('table', 'table');
$container->set('template', new Template());
$container->set('dbi', $GLOBALS['dbi']);
$response = new ResponseStub();
$container->set('PhpMyAdmin\Response', $response);
$container->alias('response', 'PhpMyAdmin\Response');
$ctrl = new IndexesController(
$container->get('response'),
$container->get('dbi'),
$container->get('template'),
$container->get('db'),
$container->get('table'),
$response,
$GLOBALS['dbi'],
new Template(),
$GLOBALS['db'],
$GLOBALS['table'],
null
);
@ -156,22 +148,15 @@ class IndexesControllerTest extends PmaTestCase
$GLOBALS['dbi']->expects($this->any())->method('getTable')
->will($this->returnValue($table));
$container = Container::getDefaultContainer();
$container->set('db', 'db');
$container->set('table', 'table');
$container->set('template', new Template());
$container->set('dbi', $GLOBALS['dbi']);
$response = new ResponseStub();
$container->set('PhpMyAdmin\Response', $response);
$container->alias('response', 'PhpMyAdmin\Response');
$index = new Index();
$ctrl = new IndexesController(
$container->get('response'),
$container->get('dbi'),
$container->get('template'),
$container->get('db'),
$container->get('table'),
$response,
$GLOBALS['dbi'],
new Template(),
$GLOBALS['db'],
$GLOBALS['table'],
$index
);

View File

@ -9,9 +9,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests\Controllers\Table;
use PhpMyAdmin\Controllers\Table\RelationController;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Response;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\PmaTestCase;
use PhpMyAdmin\Tests\Stubs\Response as ResponseStub;
@ -28,6 +26,11 @@ class RelationControllerTest extends PmaTestCase
*/
private $_response;
/**
* @var Template
*/
private $template;
/**
* Configures environment
*
@ -83,16 +86,8 @@ class RelationControllerTest extends PmaTestCase
$GLOBALS['dbi'] = $dbi;
$container = Container::getDefaultContainer();
$container->set('db', 'db');
$container->set('table', 'table');
$template = new Template();
$container->set('template', $template);
$container->set('relation', new Relation($dbi, $template));
$container->set('dbi', $GLOBALS['dbi']);
$this->_response = new ResponseStub();
$container->set(Response::class, $this->_response);
$container->alias('response', Response::class);
$this->template = new Template();
}
/**
@ -123,13 +118,20 @@ class RelationControllerTest extends PmaTestCase
$GLOBALS['dbi']->expects($this->any())->method('getTable')
->will($this->returnValue($tableMock));
$container = Container::getDefaultContainer();
$container->set('dbi', $GLOBALS['dbi']);
$container->factory(RelationController::class);
/**
* @var RelationController $ctrl
*/
$ctrl = $container->get(RelationController::class);
$ctrl = new RelationController(
$this->_response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$GLOBALS['table'],
null,
null,
null,
null,
null,
null,
new Relation($GLOBALS['dbi'], $this->template)
);
$ctrl->getDropdownValueForTableAction();
$json = $this->_response->getJSONResult();
@ -165,10 +167,20 @@ class RelationControllerTest extends PmaTestCase
$GLOBALS['dbi']->expects($this->any())->method('getTable')
->will($this->returnValue($tableMock));
$container = Container::getDefaultContainer();
$container->set('dbi', $GLOBALS['dbi']);
$container->factory(RelationController::class);
$ctrl = $container->get(RelationController::class);
$ctrl = new RelationController(
$this->_response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$GLOBALS['table'],
null,
null,
null,
null,
null,
null,
new Relation($GLOBALS['dbi'], $this->template)
);
$ctrl->getDropdownValueForTableAction();
$json = $this->_response->getJSONResult();
@ -206,12 +218,19 @@ class RelationControllerTest extends PmaTestCase
)
);
$container = Container::getDefaultContainer();
$container->set('dbi', $GLOBALS['dbi']);
$container->factory(RelationController::class);
$ctrl = $container->get(
RelationController::class,
['tbl_storage_engine' => 'INNODB']
$ctrl = new RelationController(
$this->_response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$GLOBALS['table'],
null,
null,
'INNODB',
null,
null,
null,
new Relation($GLOBALS['dbi'], $this->template)
);
$_POST['foreign'] = 'true';
@ -248,12 +267,19 @@ class RelationControllerTest extends PmaTestCase
)
);
$container = Container::getDefaultContainer();
$container->set('dbi', $GLOBALS['dbi']);
$container->factory(RelationController::class);
$ctrl = $container->get(
RelationController::class,
['tbl_storage_engine' => 'INNODB']
$ctrl = new RelationController(
$this->_response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$GLOBALS['table'],
null,
null,
'INNODB',
null,
null,
null,
new Relation($GLOBALS['dbi'], $this->template)
);
$_POST['foreign'] = 'false';

View File

@ -10,7 +10,6 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests\Controllers\Table;
use PhpMyAdmin\Controllers\Table\SearchController;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\PmaTestCase;
@ -31,6 +30,11 @@ class SearchControllerTest extends PmaTestCase
*/
private $_response;
/**
* @var Template
*/
private $template;
/**
* Setup function for test cases
*
@ -45,8 +49,8 @@ class SearchControllerTest extends PmaTestCase
$_POST['zoom_submit'] = 'zoom';
$GLOBALS['server'] = 1;
$GLOBALS['db'] = 'db';
$GLOBALS['table'] = 'table';
$GLOBALS['db'] = 'PMA';
$GLOBALS['table'] = 'PMA_BookMark';
$GLOBALS['PMA_PHP_SELF'] = 'index.php';
$relation = new Relation($GLOBALS['dbi']);
$GLOBALS['cfgRelation'] = $relation->getRelationsParam();
@ -94,16 +98,7 @@ class SearchControllerTest extends PmaTestCase
$relation->dbi = $dbi;
$this->_response = new ResponseStub();
$container = Container::getDefaultContainer();
$container->set('db', 'PMA');
$container->set('table', 'PMA_BookMark');
$template = new Template();
$container->set('template', $template);
$container->set('dbi', $GLOBALS['dbi']);
$container->set('response', $this->_response);
$container->set('searchType', 'replace');
$container->set('relation', new Relation($dbi, $template));
$this->template = new Template();
}
/**
@ -123,17 +118,15 @@ class SearchControllerTest extends PmaTestCase
*/
public function testReplace()
{
$container = Container::getDefaultContainer();
$tableSearch = new SearchController(
$container->get('response'),
$container->get('dbi'),
$container->get('template'),
$container->get('db'),
$container->get('table'),
$this->_response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$GLOBALS['table'],
"zoom",
null,
new Relation($container->get('dbi'), $container->get('template'))
new Relation($GLOBALS['dbi'], $this->template)
);
$columnIndex = 0;
$find = "Field";
@ -172,20 +165,18 @@ class SearchControllerTest extends PmaTestCase
$_POST['order'] = "asc";
$_POST['customWhereClause'] = "name='pma'";
$container = Container::getDefaultContainer();
$class = new ReflectionClass(SearchController::class);
$method = $class->getMethod('_buildSqlQuery');
$method->setAccessible(true);
$tableSearch = new SearchController(
$container->get('response'),
$container->get('dbi'),
$container->get('template'),
$container->get('db'),
$container->get('table'),
$this->_response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$GLOBALS['table'],
"zoom",
null,
new Relation($container->get('dbi'), $container->get('template'))
new Relation($GLOBALS['dbi'], $this->template)
);
$sql = $method->invoke($tableSearch);
@ -273,14 +264,16 @@ class SearchControllerTest extends PmaTestCase
$GLOBALS['dbi']->expects($this->any())->method('fetchSingleRow')
->will($this->returnArgument(0));
$container = Container::getDefaultContainer();
$container->set('dbi', $GLOBALS['dbi']);
$container->factory('PhpMyAdmin\Controllers\Table\SearchController');
$container->alias(
'SearchController',
'PhpMyAdmin\Controllers\Table\SearchController'
$ctrl = new SearchController(
$this->_response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$GLOBALS['table'],
'replace',
null,
new Relation($GLOBALS['dbi'], $this->template)
);
$ctrl = $container->get('SearchController');
$result = $ctrl->getColumnMinMax('column');
$expected = 'SELECT MIN(`column`) AS `min`, '
@ -310,13 +303,16 @@ class SearchControllerTest extends PmaTestCase
$method = $class->getMethod('_generateWhereClause');
$method->setAccessible(true);
$container = Container::getDefaultContainer();
$container->factory('\PhpMyAdmin\Controllers\Table\SearchController');
$container->alias(
'SearchController',
'PhpMyAdmin\Controllers\Table\SearchController'
$ctrl = new SearchController(
$this->_response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$GLOBALS['table'],
'replace',
null,
new Relation($GLOBALS['dbi'], $this->template)
);
$ctrl = $container->get('SearchController');
$_POST['customWhereClause'] = '`table` = \'PMA_BookMark\'';
$result = $method->invoke($ctrl);
@ -402,14 +398,16 @@ class SearchControllerTest extends PmaTestCase
)
);
$container = Container::getDefaultContainer();
$container->set('dbi', $GLOBALS['dbi']);
$container->factory('\PhpMyAdmin\Controllers\Table\SearchController');
$container->alias(
'SearchController',
'PhpMyAdmin\Controllers\Table\SearchController'
$ctrl = new SearchController(
$this->_response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$GLOBALS['table'],
'replace',
null,
new Relation($GLOBALS['dbi'], $this->template)
);
$ctrl = $container->get('SearchController');
$_POST['db'] = 'PMA';
$_POST['table'] = 'PMA_BookMark';

View File

@ -13,9 +13,7 @@ namespace PhpMyAdmin\Tests\Controllers\Table;
use PhpMyAdmin\Controllers\Table\StructureController;
use PhpMyAdmin\CreateAddField;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Response;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\PmaTestCase;
use PhpMyAdmin\Tests\Stubs\Response as ResponseStub;
@ -37,6 +35,11 @@ class StructureControllerTest extends PmaTestCase
*/
private $_response;
/**
* @var Template
*/
private $template;
/**
* Prepares environment for the test.
*
@ -63,18 +66,8 @@ class StructureControllerTest extends PmaTestCase
$GLOBALS['dbi'] = $dbi;
$container = Container::getDefaultContainer();
$container->set('db', 'db');
$container->set('table', 'table');
$template = new Template();
$container->set('template', $template);
$container->set('dbi', $GLOBALS['dbi']);
$this->_response = new ResponseStub();
$container->set(Response::class, $this->_response);
$container->alias('response', Response::class);
$container->set('relation', new Relation($dbi, $template));
$container->set('transformations', new Transformations());
$container->set('createAddField', new CreateAddField($dbi));
$this->template = new Template();
}
/**
@ -94,14 +87,23 @@ class StructureControllerTest extends PmaTestCase
$method = $class->getMethod('getKeyForTablePrimary');
$method->setAccessible(true);
$container = Container::getDefaultContainer();
$container->set('dbi', $GLOBALS['dbi']);
$container->factory(StructureController::class);
$container->alias(
'StructureController',
StructureController::class
$ctrl = new StructureController(
$this->_response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$GLOBALS['table'],
null,
null,
null,
null,
null,
null,
new Relation($GLOBALS['dbi'], $this->template),
new Transformations(),
new CreateAddField($GLOBALS['dbi'])
);
$ctrl = $container->get('StructureController');
// No primary key in db.table2
$this->assertEquals(
'',
@ -143,14 +145,23 @@ class StructureControllerTest extends PmaTestCase
$method = $class->getMethod('getKeyForTablePrimary');
$method->setAccessible(true);
$container = Container::getDefaultContainer();
$container->set('dbi', $GLOBALS['dbi']);
$container->factory('PhpMyAdmin\Controllers\Table\StructureController');
$container->alias(
'StructureController',
'PhpMyAdmin\Controllers\Table\StructureController'
$ctrl = new StructureController(
$this->_response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$GLOBALS['table'],
null,
null,
null,
null,
null,
null,
new Relation($GLOBALS['dbi'], $this->template),
new Transformations(),
new CreateAddField($GLOBALS['dbi'])
);
$ctrl = $container->get('StructureController');
// With db.table, it has a primary key `column`
$this->assertEquals(
'column, ',
@ -170,14 +181,22 @@ class StructureControllerTest extends PmaTestCase
$method = $class->getMethod('adjustColumnPrivileges');
$method->setAccessible(true);
$container = Container::getDefaultContainer();
$container->set('dbi', $GLOBALS['dbi']);
$container->factory('PhpMyAdmin\Controllers\Table\StructureController');
$container->alias(
'StructureController',
'PhpMyAdmin\Controllers\Table\StructureController'
$ctrl = new StructureController(
$this->_response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$GLOBALS['table'],
null,
null,
null,
null,
null,
null,
new Relation($GLOBALS['dbi'], $this->template),
new Transformations(),
new CreateAddField($GLOBALS['dbi'])
);
$ctrl = $container->get('StructureController');
$this->assertEquals(
false,
@ -197,14 +216,22 @@ class StructureControllerTest extends PmaTestCase
$method = $class->getMethod('getMultipleFieldCommandType');
$method->setAccessible(true);
$container = Container::getDefaultContainer();
$container->set('dbi', $GLOBALS['dbi']);
$container->factory('PhpMyAdmin\Controllers\Table\StructureController');
$container->alias(
'StructureController',
'PhpMyAdmin\Controllers\Table\StructureController'
$ctrl = new StructureController(
$this->_response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$GLOBALS['table'],
null,
null,
null,
null,
null,
null,
new Relation($GLOBALS['dbi'], $this->template),
new Transformations(),
new CreateAddField($GLOBALS['dbi'])
);
$ctrl = $container->get('StructureController');
$this->assertEquals(
null,
@ -261,14 +288,22 @@ class StructureControllerTest extends PmaTestCase
$method = $class->getMethod('getDataForSubmitMult');
$method->setAccessible(true);
$container = Container::getDefaultContainer();
$container->set('dbi', $dbi);
$container->factory('PhpMyAdmin\Controllers\Table\StructureController');
$container->alias(
'StructureController',
'PhpMyAdmin\Controllers\Table\StructureController'
$ctrl = new StructureController(
$this->_response,
$GLOBALS['dbi'],
$this->template,
$GLOBALS['db'],
$GLOBALS['table'],
null,
null,
null,
null,
null,
null,
new Relation($GLOBALS['dbi'], $this->template),
new Transformations(),
new CreateAddField($GLOBALS['dbi'])
);
$ctrl = $container->get('StructureController');
$submit_mult = "index";
$db = "PMA_db";

View File

@ -1,76 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Tests for PhpMyAdmin\Di\ContainerException class
*
* @package PhpMyAdmin-test
*/
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Di;
use PhpMyAdmin\Di\ContainerException;
use PhpMyAdmin\Tests\PmaTestCase;
/**
* Tests for PhpMyAdmin\Di\ContainerException class
*
* @package PhpMyAdmin-test
*/
class ContainerExceptionTest extends PmaTestCase
{
/**
* @access protected
*/
protected $exception;
/**
* Sets up the fixture.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp(): void
{
$this->exception = new ContainerException();
}
/**
* Tears down the fixture.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown(): void
{
unset($this->exception);
}
/**
* Test for ContainerException
*
* @return void
*/
public function testContainerExceptionImplementsInteface()
{
$this->assertInstanceOf(
'Psr\Container\ContainerExceptionInterface',
$this->exception
);
}
/**
* Test for ContainerException
*
* @return void
*/
public function testContainerExceptionExtendsException()
{
$this->assertInstanceOf(
'Exception',
$this->exception
);
}
}

View File

@ -1,94 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Tests for PhpMyAdmin\Di\Container class
*
* @package PhpMyAdmin-test
*/
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Di;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\Tests\PmaTestCase;
use Psr\Container\NotFoundExceptionInterface;
/**
* Tests for PhpMyAdmin\Di\Container class
*
* @package PhpMyAdmin-test
*/
class ContainerTest extends PmaTestCase
{
/**
* @access protected
*/
protected $container;
/**
* Sets up the fixture.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp(): void
{
$this->container = new Container();
}
/**
* Tears down the fixture.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown(): void
{
unset($this->container);
}
/**
* Test for get
*
* @return void
*/
public function testGetWithValidEntry()
{
$this->container->set('name', 'value');
$this->assertSame('value', $this->container->get('name'));
}
/**
* Test for get
*
* @return void
*/
public function testGetThrowsNotFoundException()
{
$this->expectException(NotFoundExceptionInterface::class);
$this->container->get('name');
}
/**
* Test for has
*
* @return void
*/
public function testHasReturnsTrueForValidEntry()
{
$this->container->set('name', 'value');
$this->assertTrue($this->container->has('name'));
}
/**
* Test for has
*
* @return void
*/
public function testHasReturnsFalseForInvalidEntry()
{
$this->assertFalse($this->container->has('name'));
}
}

View File

@ -1,89 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Tests for PhpMyAdmin\Di\NotFoundException class
*
* @package PhpMyAdmin-test
*/
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Di;
use PhpMyAdmin\Di\NotFoundException;
use PhpMyAdmin\Tests\PmaTestCase;
/**
* Tests for PhpMyAdmin\Di\NotFoundException class
*
* @package PhpMyAdmin-test
*/
class NotFoundExceptionTest extends PmaTestCase
{
/**
* @access protected
*/
protected $exception;
/**
* Sets up the fixture.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp(): void
{
$this->exception = new NotFoundException();
}
/**
* Tears down the fixture.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown(): void
{
unset($this->exception);
}
/**
* Test for NotFoundException
*
* @return void
*/
public function testNotFoundExceptionImplementsInteface()
{
$this->assertInstanceOf(
'Psr\Container\NotFoundExceptionInterface',
$this->exception
);
}
/**
* Test for NotFoundException
*
* @return void
*/
public function testNotFoundExceptionExtendsContainerExceptionInteface()
{
$this->assertInstanceOf(
'Psr\Container\ContainerExceptionInterface',
$this->exception
);
}
/**
* Test for NotFoundException
*
* @return void
*/
public function testContainerExceptionExtendsException()
{
$this->assertInstanceOf(
'Exception',
$this->exception
);
}
}

View File

@ -9,7 +9,6 @@ declare(strict_types=1);
use PhpMyAdmin\Controllers\TransformationOverviewController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\Response;
if (! defined('ROOT_PATH')) {
@ -18,14 +17,11 @@ if (! defined('ROOT_PATH')) {
require_once ROOT_PATH . 'libraries/common.inc.php';
$container = Container::getDefaultContainer();
$container->set(Response::class, Response::getInstance());
/** @var Response $response */
$response = $container->get(Response::class);
$response = $containerBuilder->get(Response::class);
/** @var DatabaseInterface $dbi */
$dbi = $container->get(DatabaseInterface::class);
$dbi = $containerBuilder->get(DatabaseInterface::class);
$header = $response->getHeader();
$header->disableMenuAndConsole();

View File

@ -9,14 +9,9 @@
declare(strict_types=1);
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\Display\ChangePassword;
use PhpMyAdmin\Message;
use PhpMyAdmin\Relation;
use PhpMyAdmin\RelationCleanup;
use PhpMyAdmin\Response;
use PhpMyAdmin\Server\Privileges;
use PhpMyAdmin\Template;
use PhpMyAdmin\UserPassword;
if (! defined('ROOT_PATH')) {
@ -27,27 +22,19 @@ global $cfg;
require_once ROOT_PATH . 'libraries/common.inc.php';
$container = Container::getDefaultContainer();
$container->set(Response::class, Response::getInstance());
/** @var Response $response */
$response = $container->get(Response::class);
$response = $containerBuilder->get(Response::class);
/** @var DatabaseInterface $dbi */
$dbi = $container->get(DatabaseInterface::class);
$dbi = $containerBuilder->get(DatabaseInterface::class);
$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('server/privileges.js');
$scripts->addFile('vendor/zxcvbn.js');
/** @var Template $template */
$template = $containerBuilder->get('template');
/** @var Relation $relation */
$relation = $containerBuilder->get('relation');
$relationCleanup = new RelationCleanup($dbi, $relation);
$serverPrivileges = new Privileges($template, $dbi, $relation, $relationCleanup);
$userPassword = new UserPassword($serverPrivileges);
/** @var UserPassword $userPassword */
$userPassword = $containerBuilder->get('user_password');
/**
* Displays an error message and exits if the user isn't allowed to use this

View File

@ -11,7 +11,6 @@ declare(strict_types=1);
use PhpMyAdmin\Core;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\Message;
use PhpMyAdmin\Response;
use PhpMyAdmin\Template;
@ -26,14 +25,11 @@ global $text_dir;
require_once ROOT_PATH . 'libraries/common.inc.php';
require ROOT_PATH . 'libraries/db_common.inc.php';
$container = Container::getDefaultContainer();
$container->set(Response::class, Response::getInstance());
/** @var Response $response */
$response = $container->get(Response::class);
$response = $containerBuilder->get(Response::class);
/** @var DatabaseInterface $dbi */
$dbi = $container->get(DatabaseInterface::class);
$dbi = $containerBuilder->get(DatabaseInterface::class);
$url_params['goto'] = 'tbl_structure.php';
$url_params['back'] = 'view_create.php';