updated-packages
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace Doctrine\DBAL\Tools\Console\Command;
|
||||
|
||||
use Doctrine\DBAL\Driver\PDOConnection;
|
||||
use Doctrine\DBAL\Driver\PDOStatement;
|
||||
use Doctrine\DBAL\Driver\PDO\Connection as PDOConnection;
|
||||
use Doctrine\DBAL\Driver\PDO\Statement as PDOStatement;
|
||||
use InvalidArgumentException;
|
||||
use PDOException;
|
||||
use RuntimeException;
|
||||
@@ -11,14 +11,17 @@ use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use const PHP_EOL;
|
||||
|
||||
use function assert;
|
||||
use function error_get_last;
|
||||
use function file_exists;
|
||||
use function file_get_contents;
|
||||
use function is_readable;
|
||||
use function realpath;
|
||||
use function sprintf;
|
||||
|
||||
use const PHP_EOL;
|
||||
|
||||
/**
|
||||
* Task for executing arbitrary SQL that can come from a file or directly from
|
||||
* the command line.
|
||||
@@ -27,9 +30,7 @@ use function sprintf;
|
||||
*/
|
||||
class ImportCommand extends Command
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
/** @return void */
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
@@ -49,6 +50,8 @@ EOT
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
@@ -57,7 +60,7 @@ EOT
|
||||
$fileNames = $input->getArgument('file');
|
||||
|
||||
if ($fileNames === null) {
|
||||
return null;
|
||||
return 0;
|
||||
}
|
||||
|
||||
foreach ((array) $fileNames as $fileName) {
|
||||
@@ -72,14 +75,27 @@ EOT
|
||||
throw new InvalidArgumentException(
|
||||
sprintf("SQL file '<info>%s</info>' does not exist.", $filePath)
|
||||
);
|
||||
} elseif (! is_readable($filePath)) {
|
||||
}
|
||||
|
||||
if (! is_readable($filePath)) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf("SQL file '<info>%s</info>' does not have read permissions.", $filePath)
|
||||
);
|
||||
}
|
||||
|
||||
$output->write(sprintf("Processing file '<info>%s</info>'... ", $filePath));
|
||||
$sql = file_get_contents($filePath);
|
||||
$sql = @file_get_contents($filePath);
|
||||
|
||||
if ($sql === false) {
|
||||
$message = sprintf("Unable to read SQL file '<info>%s</info>'", $filePath);
|
||||
$error = error_get_last();
|
||||
|
||||
if ($error !== null) {
|
||||
$message .= ': ' . $error['message'];
|
||||
}
|
||||
|
||||
throw new RuntimeException($message);
|
||||
}
|
||||
|
||||
if ($conn instanceof PDOConnection) {
|
||||
// PDO Drivers
|
||||
@@ -124,6 +140,6 @@ EOT
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ namespace Doctrine\DBAL\Tools\Console\Command;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Platforms\Keywords\DB2Keywords;
|
||||
use Doctrine\DBAL\Platforms\Keywords\KeywordList;
|
||||
use Doctrine\DBAL\Platforms\Keywords\MySQL57Keywords;
|
||||
use Doctrine\DBAL\Platforms\Keywords\MySQL80Keywords;
|
||||
use Doctrine\DBAL\Platforms\Keywords\MySQLKeywords;
|
||||
@@ -21,18 +22,25 @@ use Doctrine\DBAL\Platforms\Keywords\SQLServer2005Keywords;
|
||||
use Doctrine\DBAL\Platforms\Keywords\SQLServer2008Keywords;
|
||||
use Doctrine\DBAL\Platforms\Keywords\SQLServer2012Keywords;
|
||||
use Doctrine\DBAL\Platforms\Keywords\SQLServerKeywords;
|
||||
use Doctrine\DBAL\Tools\Console\ConnectionProvider;
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use function array_keys;
|
||||
use function assert;
|
||||
use function count;
|
||||
use function implode;
|
||||
use function is_array;
|
||||
use function is_string;
|
||||
|
||||
class ReservedWordsCommand extends Command
|
||||
{
|
||||
/** @var string[] */
|
||||
/** @var array<string,class-string<KeywordList>> */
|
||||
private $keywordListClasses = [
|
||||
'mysql' => MySQLKeywords::class,
|
||||
'mysql57' => MySQL57Keywords::class,
|
||||
@@ -53,11 +61,29 @@ class ReservedWordsCommand extends Command
|
||||
'sqlanywhere16' => SQLAnywhere16Keywords::class,
|
||||
];
|
||||
|
||||
/** @var ConnectionProvider|null */
|
||||
private $connectionProvider;
|
||||
|
||||
public function __construct(?ConnectionProvider $connectionProvider = null)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->connectionProvider = $connectionProvider;
|
||||
if ($connectionProvider !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Deprecation::trigger(
|
||||
'doctrine/dbal',
|
||||
'https://github.com/doctrine/dbal/pull/3956',
|
||||
'Not passing a connection provider as the first constructor argument is deprecated'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* If you want to add or replace a keywords list use this command.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $class
|
||||
* @param string $name
|
||||
* @param class-string<KeywordList> $class
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -66,20 +92,20 @@ class ReservedWordsCommand extends Command
|
||||
$this->keywordListClasses[$name] = $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
/** @return void */
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('dbal:reserved-words')
|
||||
->setDescription('Checks if the current database contains identifiers that are reserved.')
|
||||
->setDefinition([new InputOption(
|
||||
'list',
|
||||
'l',
|
||||
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
|
||||
'Keyword-List name.'
|
||||
),
|
||||
->setDefinition([
|
||||
new InputOption('connection', null, InputOption::VALUE_REQUIRED, 'The named database connection'),
|
||||
new InputOption(
|
||||
'list',
|
||||
'l',
|
||||
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
|
||||
'Keyword-List name.'
|
||||
),
|
||||
])
|
||||
->setHelp(<<<EOT
|
||||
Checks if the current database contains tables and columns
|
||||
@@ -119,13 +145,21 @@ EOT
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
/** @var Connection $conn */
|
||||
$conn = $this->getHelper('db')->getConnection();
|
||||
$conn = $this->getConnection($input);
|
||||
|
||||
$keywordLists = $input->getOption('list');
|
||||
|
||||
if (is_string($keywordLists)) {
|
||||
$keywordLists = [$keywordLists];
|
||||
} elseif (! is_array($keywordLists)) {
|
||||
$keywordLists = [];
|
||||
}
|
||||
|
||||
$keywordLists = (array) $input->getOption('list');
|
||||
if (! $keywordLists) {
|
||||
$keywordLists = [
|
||||
'mysql',
|
||||
@@ -154,11 +188,15 @@ EOT
|
||||
'Known lists: ' . implode(', ', array_keys($this->keywordListClasses))
|
||||
);
|
||||
}
|
||||
|
||||
$class = $this->keywordListClasses[$keywordList];
|
||||
$keywords[] = new $class();
|
||||
}
|
||||
|
||||
$output->write('Checking keyword violations for <comment>' . implode(', ', $keywordLists) . '</comment>...', true);
|
||||
$output->write(
|
||||
'Checking keyword violations for <comment>' . implode(', ', $keywordLists) . '</comment>...',
|
||||
true
|
||||
);
|
||||
|
||||
$schema = $conn->getSchemaManager()->createSchema();
|
||||
$visitor = new ReservedKeywordsValidator($keywords);
|
||||
@@ -166,7 +204,12 @@ EOT
|
||||
|
||||
$violations = $visitor->getViolations();
|
||||
if (count($violations) !== 0) {
|
||||
$output->write('There are <error>' . count($violations) . '</error> reserved keyword violations in your database schema:', true);
|
||||
$output->write(
|
||||
'There are <error>' . count($violations) . '</error> reserved keyword violations'
|
||||
. ' in your database schema:',
|
||||
true
|
||||
);
|
||||
|
||||
foreach ($violations as $violation) {
|
||||
$output->write(' - ' . $violation, true);
|
||||
}
|
||||
@@ -178,4 +221,24 @@ EOT
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function getConnection(InputInterface $input): Connection
|
||||
{
|
||||
$connectionName = $input->getOption('connection');
|
||||
assert(is_string($connectionName) || $connectionName === null);
|
||||
|
||||
if ($this->connectionProvider === null) {
|
||||
if ($connectionName !== null) {
|
||||
throw new Exception('Specifying a connection is only supported when a ConnectionProvider is used.');
|
||||
}
|
||||
|
||||
return $this->getHelper('db')->getConnection();
|
||||
}
|
||||
|
||||
if ($connectionName !== null) {
|
||||
return $this->connectionProvider->getConnection($connectionName);
|
||||
}
|
||||
|
||||
return $this->connectionProvider->getDefaultConnection();
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,11 @@
|
||||
|
||||
namespace Doctrine\DBAL\Tools\Console\Command;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Tools\Console\ConnectionProvider;
|
||||
use Doctrine\DBAL\Tools\Dumper;
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
use Exception;
|
||||
use LogicException;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
@@ -10,7 +14,10 @@ use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use function assert;
|
||||
use function is_numeric;
|
||||
use function is_string;
|
||||
use function stripos;
|
||||
|
||||
/**
|
||||
@@ -19,31 +26,53 @@ use function stripos;
|
||||
*/
|
||||
class RunSqlCommand extends Command
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
/** @var ConnectionProvider|null */
|
||||
private $connectionProvider;
|
||||
|
||||
public function __construct(?ConnectionProvider $connectionProvider = null)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->connectionProvider = $connectionProvider;
|
||||
if ($connectionProvider !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Deprecation::trigger(
|
||||
'doctrine/dbal',
|
||||
'https://github.com/doctrine/dbal/pull/3956',
|
||||
'Not passing a connection provider as the first constructor argument is deprecated'
|
||||
);
|
||||
}
|
||||
|
||||
/** @return void */
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('dbal:run-sql')
|
||||
->setDescription('Executes arbitrary SQL directly from the command line.')
|
||||
->setDefinition([
|
||||
new InputOption('connection', null, InputOption::VALUE_REQUIRED, 'The named database connection'),
|
||||
new InputArgument('sql', InputArgument::REQUIRED, 'The SQL statement to execute.'),
|
||||
new InputOption('depth', null, InputOption::VALUE_REQUIRED, 'Dumping depth of result set.', 7),
|
||||
new InputOption('depth', null, InputOption::VALUE_REQUIRED, 'Dumping depth of result set.', '7'),
|
||||
new InputOption('force-fetch', null, InputOption::VALUE_NONE, 'Forces fetching the result.'),
|
||||
])
|
||||
->setHelp(<<<EOT
|
||||
Executes arbitrary SQL directly from the command line.
|
||||
The <info>%command.name%</info> command executes the given SQL query and
|
||||
outputs the results:
|
||||
|
||||
<info>php %command.full_name% "SELECT * FROM users"</info>
|
||||
EOT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$conn = $this->getHelper('db')->getConnection();
|
||||
$conn = $this->getConnection($input);
|
||||
|
||||
$sql = $input->getArgument('sql');
|
||||
|
||||
@@ -51,6 +80,8 @@ EOT
|
||||
throw new RuntimeException("Argument 'SQL' is required in order to execute this command correctly.");
|
||||
}
|
||||
|
||||
assert(is_string($sql));
|
||||
|
||||
$depth = $input->getOption('depth');
|
||||
|
||||
if (! is_numeric($depth)) {
|
||||
@@ -58,11 +89,33 @@ EOT
|
||||
}
|
||||
|
||||
if (stripos($sql, 'select') === 0 || $input->getOption('force-fetch')) {
|
||||
$resultSet = $conn->fetchAll($sql);
|
||||
$resultSet = $conn->fetchAllAssociative($sql);
|
||||
} else {
|
||||
$resultSet = $conn->executeUpdate($sql);
|
||||
$resultSet = $conn->executeStatement($sql);
|
||||
}
|
||||
|
||||
$output->write(Dumper::dump($resultSet, (int) $depth));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function getConnection(InputInterface $input): Connection
|
||||
{
|
||||
$connectionName = $input->getOption('connection');
|
||||
assert(is_string($connectionName) || $connectionName === null);
|
||||
|
||||
if ($this->connectionProvider === null) {
|
||||
if ($connectionName !== null) {
|
||||
throw new Exception('Specifying a connection is only supported when a ConnectionProvider is used.');
|
||||
}
|
||||
|
||||
return $this->getHelper('db')->getConnection();
|
||||
}
|
||||
|
||||
if ($connectionName !== null) {
|
||||
return $this->connectionProvider->getConnection($connectionName);
|
||||
}
|
||||
|
||||
return $this->connectionProvider->getDefaultConnection();
|
||||
}
|
||||
}
|
||||
|
9
vendor/doctrine/dbal/lib/Doctrine/DBAL/Tools/Console/ConnectionNotFound.php
vendored
Normal file
9
vendor/doctrine/dbal/lib/Doctrine/DBAL/Tools/Console/ConnectionNotFound.php
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\DBAL\Tools\Console;
|
||||
|
||||
use OutOfBoundsException;
|
||||
|
||||
final class ConnectionNotFound extends OutOfBoundsException
|
||||
{
|
||||
}
|
15
vendor/doctrine/dbal/lib/Doctrine/DBAL/Tools/Console/ConnectionProvider.php
vendored
Normal file
15
vendor/doctrine/dbal/lib/Doctrine/DBAL/Tools/Console/ConnectionProvider.php
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\DBAL\Tools\Console;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
|
||||
interface ConnectionProvider
|
||||
{
|
||||
public function getDefaultConnection(): Connection;
|
||||
|
||||
/**
|
||||
* @throws ConnectionNotFound in case a connection with the given name does not exist.
|
||||
*/
|
||||
public function getConnection(string $name): Connection;
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\DBAL\Tools\Console\ConnectionProvider;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Tools\Console\ConnectionNotFound;
|
||||
use Doctrine\DBAL\Tools\Console\ConnectionProvider;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
class SingleConnectionProvider implements ConnectionProvider
|
||||
{
|
||||
/** @var Connection */
|
||||
private $connection;
|
||||
|
||||
/** @var string */
|
||||
private $defaultConnectionName;
|
||||
|
||||
public function __construct(Connection $connection, string $defaultConnectionName = 'default')
|
||||
{
|
||||
$this->connection = $connection;
|
||||
$this->defaultConnectionName = $defaultConnectionName;
|
||||
}
|
||||
|
||||
public function getDefaultConnection(): Connection
|
||||
{
|
||||
return $this->connection;
|
||||
}
|
||||
|
||||
public function getConnection(string $name): Connection
|
||||
{
|
||||
if ($name !== $this->defaultConnectionName) {
|
||||
throw new ConnectionNotFound(sprintf('Connection with name "%s" does not exist.', $name));
|
||||
}
|
||||
|
||||
return $this->connection;
|
||||
}
|
||||
}
|
@@ -8,9 +8,13 @@ use Doctrine\DBAL\Tools\Console\Command\ReservedWordsCommand;
|
||||
use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand;
|
||||
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
|
||||
use Doctrine\DBAL\Version;
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use TypeError;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Handles running the Console Tools inside Symfony Console context.
|
||||
@@ -20,6 +24,8 @@ class ConsoleRunner
|
||||
/**
|
||||
* Create a Symfony Console HelperSet
|
||||
*
|
||||
* @deprecated use a ConnectionProvider instead.
|
||||
*
|
||||
* @return HelperSet
|
||||
*/
|
||||
public static function createHelperSet(Connection $connection)
|
||||
@@ -30,20 +36,41 @@ class ConsoleRunner
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs console with the given helperset.
|
||||
* Runs console with the given connection provider or helperset (deprecated).
|
||||
*
|
||||
* @param Command[] $commands
|
||||
* @param ConnectionProvider|HelperSet $helperSetOrConnectionProvider
|
||||
* @param Command[] $commands
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function run(HelperSet $helperSet, $commands = [])
|
||||
public static function run($helperSetOrConnectionProvider, $commands = [])
|
||||
{
|
||||
$cli = new Application('Doctrine Command Line Interface', Version::VERSION);
|
||||
|
||||
$cli->setCatchExceptions(true);
|
||||
$cli->setHelperSet($helperSet);
|
||||
|
||||
self::addCommands($cli);
|
||||
$connectionProvider = null;
|
||||
if ($helperSetOrConnectionProvider instanceof HelperSet) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/dbal',
|
||||
'https://github.com/doctrine/dbal/pull/3956',
|
||||
'Passing an instance of "%s" as the first argument is deprecated. Pass an instance of "%s" instead.',
|
||||
HelperSet::class,
|
||||
ConnectionProvider::class
|
||||
);
|
||||
$connectionProvider = null;
|
||||
$cli->setHelperSet($helperSetOrConnectionProvider);
|
||||
} elseif ($helperSetOrConnectionProvider instanceof ConnectionProvider) {
|
||||
$connectionProvider = $helperSetOrConnectionProvider;
|
||||
} else {
|
||||
throw new TypeError(sprintf(
|
||||
'First argument must be an instance of "%s" or "%s"',
|
||||
HelperSet::class,
|
||||
ConnectionProvider::class
|
||||
));
|
||||
}
|
||||
|
||||
self::addCommands($cli, $connectionProvider);
|
||||
|
||||
$cli->addCommands($commands);
|
||||
$cli->run();
|
||||
@@ -52,17 +79,19 @@ class ConsoleRunner
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function addCommands(Application $cli)
|
||||
public static function addCommands(Application $cli, ?ConnectionProvider $connectionProvider = null)
|
||||
{
|
||||
$cli->addCommands([
|
||||
new RunSqlCommand(),
|
||||
new RunSqlCommand($connectionProvider),
|
||||
new ImportCommand(),
|
||||
new ReservedWordsCommand(),
|
||||
new ReservedWordsCommand($connectionProvider),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the instructions to create a configuration file
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function printCliConfigTemplate()
|
||||
{
|
||||
@@ -72,14 +101,17 @@ project, which is required to get the Doctrine-DBAL Console working. You can use
|
||||
following sample as a template:
|
||||
|
||||
<?php
|
||||
use Doctrine\DBAL\Tools\Console\ConsoleRunner;
|
||||
|
||||
// replace with the mechanism to retrieve DBAL connection in your app
|
||||
$connection = getDBALConnection();
|
||||
use Doctrine\DBAL\Tools\Console\ConnectionProvider\SingleConnectionProvider;
|
||||
|
||||
// You can append new commands to $commands array, if needed
|
||||
|
||||
return ConsoleRunner::createHelperSet($connection);
|
||||
// replace with the mechanism to retrieve DBAL connection(s) in your app
|
||||
// and return a Doctrine\DBAL\Tools\Console\ConnectionProvider instance.
|
||||
$connection = getDBALConnection();
|
||||
|
||||
// in case you have a single connection you can use SingleConnectionProvider
|
||||
// otherwise you need to implement the Doctrine\DBAL\Tools\Console\ConnectionProvider interface with your custom logic
|
||||
return new SingleConnectionProvider($connection);
|
||||
|
||||
HELP;
|
||||
}
|
||||
|
@@ -7,6 +7,8 @@ use Symfony\Component\Console\Helper\Helper;
|
||||
|
||||
/**
|
||||
* Doctrine CLI Connection Helper.
|
||||
*
|
||||
* @deprecated use a ConnectionProvider instead.
|
||||
*/
|
||||
class ConnectionHelper extends Helper
|
||||
{
|
||||
|
@@ -8,7 +8,9 @@ use DateTimeInterface;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Persistence\Proxy;
|
||||
use stdClass;
|
||||
|
||||
use function array_keys;
|
||||
use function assert;
|
||||
use function class_exists;
|
||||
use function count;
|
||||
use function end;
|
||||
@@ -16,13 +18,14 @@ use function explode;
|
||||
use function extension_loaded;
|
||||
use function get_class;
|
||||
use function html_entity_decode;
|
||||
use function ini_get;
|
||||
use function ini_set;
|
||||
use function is_array;
|
||||
use function is_object;
|
||||
use function is_string;
|
||||
use function ob_get_clean;
|
||||
use function ob_start;
|
||||
use function strip_tags;
|
||||
use function strlen;
|
||||
use function strrpos;
|
||||
use function substr;
|
||||
use function var_dump;
|
||||
@@ -37,6 +40,8 @@ final class Dumper
|
||||
{
|
||||
/**
|
||||
* Private constructor (prevents instantiation).
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
@@ -50,16 +55,13 @@ final class Dumper
|
||||
* @param mixed $var The variable to dump.
|
||||
* @param int $maxDepth The maximum nesting level for object properties.
|
||||
*/
|
||||
public static function dump($var, int $maxDepth = 2) : string
|
||||
public static function dump($var, int $maxDepth = 2): string
|
||||
{
|
||||
$html = ini_get('html_errors');
|
||||
|
||||
if ($html !== true) {
|
||||
ini_set('html_errors', true);
|
||||
}
|
||||
$html = ini_set('html_errors', '1');
|
||||
assert(is_string($html));
|
||||
|
||||
if (extension_loaded('xdebug')) {
|
||||
ini_set('xdebug.var_display_max_depth', $maxDepth);
|
||||
ini_set('xdebug.var_display_max_depth', (string) $maxDepth);
|
||||
}
|
||||
|
||||
$var = self::export($var, $maxDepth);
|
||||
@@ -68,7 +70,10 @@ final class Dumper
|
||||
var_dump($var);
|
||||
|
||||
try {
|
||||
return strip_tags(html_entity_decode(ob_get_clean()));
|
||||
$output = ob_get_clean();
|
||||
assert(is_string($output));
|
||||
|
||||
return strip_tags(html_entity_decode($output));
|
||||
} finally {
|
||||
ini_set('html_errors', $html);
|
||||
}
|
||||
@@ -148,6 +153,7 @@ final class Dumper
|
||||
if ($aux[0] === '') {
|
||||
$name .= ':' . ($aux[1] === '*' ? 'protected' : $aux[1] . ':private');
|
||||
}
|
||||
|
||||
$return->$name = self::export($clone[$key], $maxDepth - 1);
|
||||
}
|
||||
|
||||
@@ -157,7 +163,7 @@ final class Dumper
|
||||
/**
|
||||
* @param object $object
|
||||
*/
|
||||
private static function getClass($object) : string
|
||||
private static function getClass($object): string
|
||||
{
|
||||
$class = get_class($object);
|
||||
|
||||
@@ -171,6 +177,6 @@ final class Dumper
|
||||
return $class;
|
||||
}
|
||||
|
||||
return substr($class, $pos + Proxy::MARKER_LENGTH + 2);
|
||||
return substr($class, $pos + strlen(Proxy::MARKER) + 2);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user