Refactored namespace for Symfony/Uid

This commit is contained in:
Netkas 2022-08-11 14:28:27 -04:00
parent 2e11ee89ea
commit 9263ce2cae
50 changed files with 757 additions and 158 deletions

View file

@ -3,8 +3,8 @@ autoload:
make src/ncc/ThirdParty/defuse/php-encryption/autoload_spl.php make src/ncc/ThirdParty/defuse/php-encryption/autoload_spl.php
make src/ncc/ThirdParty/Symfony/polyfill-ctype/autoload_spl.php make src/ncc/ThirdParty/Symfony/polyfill-ctype/autoload_spl.php
make src/ncc/ThirdParty/Symfony/polyfill-mbstring/autoload_spl.php make src/ncc/ThirdParty/Symfony/polyfill-mbstring/autoload_spl.php
make src/ncc/ThirdParty/Symfony/process/autoload_spl.php make src/ncc/ThirdParty/Symfony/Process/autoload_spl.php
make src/ncc/ThirdParty/Symfony/uid/autoload_spl.php make src/ncc/ThirdParty/Symfony/Uid/autoload_spl.php
make src/ncc/autoload_spl.php make src/ncc/autoload_spl.php
cp src/autoload/autoload.php src/ncc/autoload.php cp src/autoload/autoload.php src/ncc/autoload.php
@ -20,13 +20,13 @@ src/ncc/ThirdParty/Symfony/polyfill-mbstring/autoload_spl.php:
phpab --output src/ncc/ThirdParty/Symfony/polyfill-mbstring/autoload_spl.php \ phpab --output src/ncc/ThirdParty/Symfony/polyfill-mbstring/autoload_spl.php \
src/ncc/ThirdParty/Symfony/polyfill-mbstring src/ncc/ThirdParty/Symfony/polyfill-mbstring
src/ncc/ThirdParty/Symfony/process/autoload_spl.php: src/ncc/ThirdParty/Symfony/Process/autoload_spl.php:
phpab --output src/ncc/ThirdParty/Symfony/process/autoload_spl.php \ phpab --output src/ncc/ThirdParty/Symfony/Process/autoload_spl.php \
src/ncc/ThirdParty/Symfony/process src/ncc/ThirdParty/Symfony/Process
src/ncc/ThirdParty/Symfony/uid/autoload_spl.php: src/ncc/ThirdParty/Symfony/Uid/autoload_spl.php:
phpab --output src/ncc/ThirdParty/Symfony/uid/autoload_spl.php \ phpab --output src/ncc/ThirdParty/Symfony/Uid/autoload_spl.php \
src/ncc/ThirdParty/Symfony/uid src/ncc/ThirdParty/Symfony/Uid
src/ncc/autoload_spl.php: src/ncc/autoload_spl.php:
phpab --output src/ncc/autoload_spl.php \ phpab --output src/ncc/autoload_spl.php \
@ -60,5 +60,5 @@ clean:
rm -f src/ncc/ThirdParty/defuse/php-encryption/autoload_spl.php rm -f src/ncc/ThirdParty/defuse/php-encryption/autoload_spl.php
rm -f src/ncc/ThirdParty/Symfony/polyfill-ctype/autoload_spl.php rm -f src/ncc/ThirdParty/Symfony/polyfill-ctype/autoload_spl.php
rm -f src/ncc/ThirdParty/Symfony/polyfill-mbstring/autoload_spl.php rm -f src/ncc/ThirdParty/Symfony/polyfill-mbstring/autoload_spl.php
rm -f src/ncc/ThirdParty/Symfony/process/autoload_spl.php rm -f src/ncc/ThirdParty/Symfony/Process/autoload_spl.php
rm -f src/ncc/ThirdParty/Symfony/uid/autoload_spl.php rm -f src/ncc/ThirdParty/Symfony/Uid/autoload_spl.php

View file

@ -19,7 +19,7 @@
$third_party_path . 'Symfony' . DIRECTORY_SEPARATOR . 'polyfill-mbstring' . DIRECTORY_SEPARATOR . 'autoload_spl.php', $third_party_path . 'Symfony' . DIRECTORY_SEPARATOR . 'polyfill-mbstring' . DIRECTORY_SEPARATOR . 'autoload_spl.php',
$third_party_path . 'Symfony' . DIRECTORY_SEPARATOR . 'polyfill-mbstring' . DIRECTORY_SEPARATOR . 'bootstrap.php', $third_party_path . 'Symfony' . DIRECTORY_SEPARATOR . 'polyfill-mbstring' . DIRECTORY_SEPARATOR . 'bootstrap.php',
$third_party_path . 'Symfony' . DIRECTORY_SEPARATOR . 'Process' . DIRECTORY_SEPARATOR . 'autoload_spl.php', $third_party_path . 'Symfony' . DIRECTORY_SEPARATOR . 'Process' . DIRECTORY_SEPARATOR . 'autoload_spl.php',
$third_party_path . 'Symfony' . DIRECTORY_SEPARATOR . 'uid' . DIRECTORY_SEPARATOR . 'autoload_spl.php', $third_party_path . 'Symfony' . DIRECTORY_SEPARATOR . 'Uid' . DIRECTORY_SEPARATOR . 'autoload_spl.php',
]; ];
foreach($target_files as $file) foreach($target_files as $file)

View file

@ -4,74 +4,74 @@ CHANGELOG
5.2.0 5.2.0
----- -----
* added `Process::setOptions()` to set `Process` specific options * added `process::setOptions()` to set `process` specific options
* added option `create_new_console` to allow a subprocess to continue * added option `create_new_console` to allow a subprocess to continue
to run after the main script exited, both on Linux and on Windows to run after the main script exited, both on Linux and on Windows
5.1.0 5.1.0
----- -----
* added `Process::getStartTime()` to retrieve the start time of the process as float * added `process::getStartTime()` to retrieve the start time of the process as float
5.0.0 5.0.0
----- -----
* removed `Process::inheritEnvironmentVariables()` * removed `process::inheritEnvironmentVariables()`
* removed `PhpProcess::setPhpBinary()` * removed `Phpprocess::setPhpBinary()`
* `Process` must be instantiated with a command array, use `Process::fromShellCommandline()` when the command should be parsed by the shell * `process` must be instantiated with a command array, use `process::fromShellCommandline()` when the command should be parsed by the shell
* removed `Process::setCommandLine()` * removed `process::setCommandLine()`
4.4.0 4.4.0
----- -----
* deprecated `Process::inheritEnvironmentVariables()`: env variables are always inherited. * deprecated `process::inheritEnvironmentVariables()`: env variables are always inherited.
* added `Process::getLastOutputTime()` method * added `process::getLastOutputTime()` method
4.2.0 4.2.0
----- -----
* added the `Process::fromShellCommandline()` to run commands in a shell wrapper * added the `process::fromShellCommandline()` to run commands in a shell wrapper
* deprecated passing a command as string when creating a `Process` instance * deprecated passing a command as string when creating a `process` instance
* deprecated the `Process::setCommandline()` and the `PhpProcess::setPhpBinary()` methods * deprecated the `process::setCommandline()` and the `Phpprocess::setPhpBinary()` methods
* added the `Process::waitUntil()` method to wait for the process only for a * added the `process::waitUntil()` method to wait for the process only for a
specific output, then continue the normal execution of your application specific output, then continue the normal execution of your application
4.1.0 4.1.0
----- -----
* added the `Process::isTtySupported()` method that allows to check for TTY support * added the `process::isTtySupported()` method that allows to check for TTY support
* made `PhpExecutableFinder` look for the `PHP_BINARY` env var when searching the php binary * made `PhpExecutableFinder` look for the `PHP_BINARY` env var when searching the php binary
* added the `ProcessSignaledException` class to properly catch signaled process errors * added the `processSignaledException` class to properly catch signaled process errors
4.0.0 4.0.0
----- -----
* environment variables will always be inherited * environment variables will always be inherited
* added a second `array $env = []` argument to the `start()`, `run()`, * added a second `array $env = []` argument to the `start()`, `run()`,
`mustRun()`, and `restart()` methods of the `Process` class `mustRun()`, and `restart()` methods of the `process` class
* added a second `array $env = []` argument to the `start()` method of the * added a second `array $env = []` argument to the `start()` method of the
`PhpProcess` class `Phpprocess` class
* the `ProcessUtils::escapeArgument()` method has been removed * the `processUtils::escapeArgument()` method has been removed
* the `areEnvironmentVariablesInherited()`, `getOptions()`, and `setOptions()` * the `areEnvironmentVariablesInherited()`, `getOptions()`, and `setOptions()`
methods of the `Process` class have been removed methods of the `process` class have been removed
* support for passing `proc_open()` options has been removed * support for passing `proc_open()` options has been removed
* removed the `ProcessBuilder` class, use the `Process` class instead * removed the `processBuilder` class, use the `process` class instead
* removed the `getEnhanceWindowsCompatibility()` and `setEnhanceWindowsCompatibility()` methods of the `Process` class * removed the `getEnhanceWindowsCompatibility()` and `setEnhanceWindowsCompatibility()` methods of the `process` class
* passing a not existing working directory to the constructor of the `Symfony\Component\Process\Process` class is not * passing a not existing working directory to the constructor of the `Symfony\Component\process\process` class is not
supported anymore supported anymore
3.4.0 3.4.0
----- -----
* deprecated the ProcessBuilder class * deprecated the processBuilder class
* deprecated calling `Process::start()` without setting a valid working directory beforehand (via `setWorkingDirectory()` or constructor) * deprecated calling `process::start()` without setting a valid working directory beforehand (via `setWorkingDirectory()` or constructor)
3.3.0 3.3.0
----- -----
* added command line arrays in the `Process` class * added command line arrays in the `process` class
* added `$env` argument to `Process::start()`, `run()`, `mustRun()` and `restart()` methods * added `$env` argument to `process::start()`, `run()`, `mustRun()` and `restart()` methods
* deprecated the `ProcessUtils::escapeArgument()` method * deprecated the `processUtils::escapeArgument()` method
* deprecated not inheriting environment variables * deprecated not inheriting environment variables
* deprecated configuring `proc_open()` options * deprecated configuring `proc_open()` options
* deprecated configuring enhanced Windows compatibility * deprecated configuring enhanced Windows compatibility
@ -82,9 +82,9 @@ CHANGELOG
* added support for PTY mode * added support for PTY mode
* added the convenience method "mustRun" * added the convenience method "mustRun"
* deprecation: Process::setStdin() is deprecated in favor of Process::setInput() * deprecation: process::setStdin() is deprecated in favor of process::setInput()
* deprecation: Process::getStdin() is deprecated in favor of Process::getInput() * deprecation: process::getStdin() is deprecated in favor of process::getInput()
* deprecation: Process::setInput() and ProcessBuilder::setInput() do not accept non-scalar types * deprecation: process::setInput() and processBuilder::setInput() do not accept non-scalar types
2.4.0 2.4.0
----- -----
@ -94,23 +94,23 @@ CHANGELOG
2.3.0 2.3.0
----- -----
* added ProcessUtils::escapeArgument() to fix the bug in escapeshellarg() function on Windows * added processUtils::escapeArgument() to fix the bug in escapeshellarg() function on Windows
* added Process::signal() * added process::signal()
* added Process::getPid() * added process::getPid()
* added support for a TTY mode * added support for a TTY mode
2.2.0 2.2.0
----- -----
* added ProcessBuilder::setArguments() to reset the arguments on a builder * added processBuilder::setArguments() to reset the arguments on a builder
* added a way to retrieve the standard and error output incrementally * added a way to retrieve the standard and error output incrementally
* added Process:restart() * added process:restart()
2.1.0 2.1.0
----- -----
* added support for non-blocking processes (start(), wait(), isRunning(), stop()) * added support for non-blocking processes (start(), wait(), isRunning(), stop())
* enhanced Windows compatibility * enhanced Windows compatibility
* added Process::getExitCodeText() that returns a string representation for * added process::getExitCodeText() that returns a string representation for
the exit code returned by the process the exit code returned by the process
* added ProcessBuilder * added processBuilder

View file

@ -12,7 +12,7 @@
namespace ncc\ThirdParty\Symfony\process\Exception; namespace ncc\ThirdParty\Symfony\process\Exception;
/** /**
* Marker Interface for the Process Component. * Marker Interface for the process Component.
* *
* @author Johannes M. Schmitt <schmittjoh@gmail.com> * @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/ */

View file

@ -12,7 +12,7 @@
namespace ncc\ThirdParty\Symfony\process\Exception; namespace ncc\ThirdParty\Symfony\process\Exception;
/** /**
* InvalidArgumentException for the Process Component. * InvalidArgumentException for the process Component.
* *
* @author Romain Neutron <imprec@gmail.com> * @author Romain Neutron <imprec@gmail.com>
*/ */

View file

@ -12,7 +12,7 @@
namespace ncc\ThirdParty\Symfony\process\Exception; namespace ncc\ThirdParty\Symfony\process\Exception;
/** /**
* LogicException for the Process Component. * LogicException for the process Component.
* *
* @author Romain Neutron <imprec@gmail.com> * @author Romain Neutron <imprec@gmail.com>
*/ */

View file

@ -18,11 +18,11 @@ use ncc\ThirdParty\Symfony\process\process;
* *
* @author Johannes M. Schmitt <schmittjoh@gmail.com> * @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/ */
class ProcessFailedException extends RuntimeException class processFailedException extends RuntimeException
{ {
private $process; private $process;
public function __construct(Process $process) public function __construct(process $process)
{ {
if ($process->isSuccessful()) { if ($process->isSuccessful()) {
throw new InvalidArgumentException('Expected a failed process, but the given process was successful.'); throw new InvalidArgumentException('Expected a failed process, but the given process was successful.');
@ -47,7 +47,7 @@ class ProcessFailedException extends RuntimeException
$this->process = $process; $this->process = $process;
} }
public function getProcess() public function getprocess()
{ {
return $this->process; return $this->process;
} }

View file

@ -18,24 +18,24 @@ use ncc\ThirdParty\Symfony\process\process;
* *
* @author Sullivan Senechal <soullivaneuh@gmail.com> * @author Sullivan Senechal <soullivaneuh@gmail.com>
*/ */
final class ProcessSignaledException extends RuntimeException final class processSignaledException extends RuntimeException
{ {
private $process; private $process;
public function __construct(Process $process) public function __construct(process $process)
{ {
$this->process = $process; $this->process = $process;
parent::__construct(sprintf('The process has been signaled with signal "%s".', $process->getTermSignal())); parent::__construct(sprintf('The process has been signaled with signal "%s".', $process->getTermSignal()));
} }
public function getProcess(): Process public function getprocess(): process
{ {
return $this->process; return $this->process;
} }
public function getSignal(): int public function getSignal(): int
{ {
return $this->getProcess()->getTermSignal(); return $this->getprocess()->getTermSignal();
} }
} }

View file

@ -18,7 +18,7 @@ use ncc\ThirdParty\Symfony\process\process;
* *
* @author Johannes M. Schmitt <schmittjoh@gmail.com> * @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/ */
class ProcessTimedOutException extends RuntimeException class processTimedOutException extends RuntimeException
{ {
public const TYPE_GENERAL = 1; public const TYPE_GENERAL = 1;
public const TYPE_IDLE = 2; public const TYPE_IDLE = 2;
@ -26,7 +26,7 @@ class ProcessTimedOutException extends RuntimeException
private $process; private $process;
private $timeoutType; private $timeoutType;
public function __construct(Process $process, int $timeoutType) public function __construct(process $process, int $timeoutType)
{ {
$this->process = $process; $this->process = $process;
$this->timeoutType = $timeoutType; $this->timeoutType = $timeoutType;
@ -38,7 +38,7 @@ class ProcessTimedOutException extends RuntimeException
)); ));
} }
public function getProcess() public function getprocess()
{ {
return $this->process; return $this->process;
} }

View file

@ -12,7 +12,7 @@
namespace ncc\ThirdParty\Symfony\process\Exception; namespace ncc\ThirdParty\Symfony\process\Exception;
/** /**
* RuntimeException for the Process Component. * RuntimeException for the process Component.
* *
* @author Johannes M. Schmitt <schmittjoh@gmail.com> * @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/ */

View file

@ -14,7 +14,7 @@ namespace ncc\ThirdParty\Symfony\process;
use ncc\ThirdParty\Symfony\process\Exception\RuntimeException; use ncc\ThirdParty\Symfony\process\Exception\RuntimeException;
/** /**
* Provides a way to continuously write to the input of a Process until the InputStream is closed. * Provides a way to continuously write to the input of a process until the InputStream is closed.
* *
* @author Nicolas Grekas <p@tchwork.com> * @author Nicolas Grekas <p@tchwork.com>
* *
@ -49,7 +49,7 @@ class InputStream implements \IteratorAggregate
if ($this->isClosed()) { if ($this->isClosed()) {
throw new RuntimeException(sprintf('"%s" is closed.', static::class)); throw new RuntimeException(sprintf('"%s" is closed.', static::class));
} }
$this->input[] = ProcessUtils::validateInput(__METHOD__, $input); $this->input[] = processUtils::validateInput(__METHOD__, $input);
} }
/** /**

View file

@ -15,15 +15,15 @@ use ncc\ThirdParty\Symfony\process\Exception\LogicException;
use ncc\ThirdParty\Symfony\process\Exception\RuntimeException; use ncc\ThirdParty\Symfony\process\Exception\RuntimeException;
/** /**
* PhpProcess runs a PHP script in an independent process. * Phpprocess runs a PHP script in an independent process.
* *
* $p = new PhpProcess('<?php echo "foo"; ?>'); * $p = new Phpprocess('<?php echo "foo"; ?>');
* $p->run(); * $p->run();
* print $p->getOutput()."\n"; * print $p->getOutput()."\n";
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*/ */
class PhpProcess extends Process class Phpprocess extends process
{ {
/** /**
* @param string $script The PHP script to run (as a string) * @param string $script The PHP script to run (as a string)

View file

@ -11,7 +11,7 @@
namespace ncc\ThirdParty\Symfony\process\Pipes; namespace ncc\ThirdParty\Symfony\process\Pipes;
use ncc\ThirdParty\Symfony\process\Process; use ncc\ThirdParty\Symfony\process\process;
/** /**
* UnixPipes implementation uses unix pipes as handles. * UnixPipes implementation uses unix pipes as handles.
@ -73,7 +73,7 @@ class UnixPipes extends AbstractPipes
]; ];
} }
if ($this->ptyMode && Process::isPtySupported()) { if ($this->ptyMode && process::isPtySupported()) {
return [ return [
['pty'], ['pty'],
['pty'], ['pty'],
@ -110,7 +110,7 @@ class UnixPipes extends AbstractPipes
// let's have a look if something changed in streams // let's have a look if something changed in streams
set_error_handler($this->handleError(...)); set_error_handler($this->handleError(...));
if (($r || $w) && false === stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1E6 : 0)) { if (($r || $w) && false === stream_select($r, $w, $e, 0, $blocking ? process::TIMEOUT_PRECISION * 1E6 : 0)) {
restore_error_handler(); restore_error_handler();
// if a system call has been interrupted, forget about it, let's try again // if a system call has been interrupted, forget about it, let's try again
// otherwise, an error occurred, let's reset pipes // otherwise, an error occurred, let's reset pipes

View file

@ -12,7 +12,7 @@
namespace ncc\ThirdParty\Symfony\process\Pipes; namespace ncc\ThirdParty\Symfony\process\Pipes;
use ncc\ThirdParty\Symfony\process\Exception\RuntimeException; use ncc\ThirdParty\Symfony\process\Exception\RuntimeException;
use ncc\ThirdParty\Symfony\process\Process; use ncc\ThirdParty\Symfony\process\process;
/** /**
* WindowsPipes implementation uses temporary files as handles. * WindowsPipes implementation uses temporary files as handles.
@ -30,8 +30,8 @@ class WindowsPipes extends AbstractPipes
private $fileHandles = []; private $fileHandles = [];
private $lockHandles = []; private $lockHandles = [];
private $readBytes = [ private $readBytes = [
Process::STDOUT => 0, process::STDOUT => 0,
Process::STDERR => 0, process::STDERR => 0,
]; ];
private $haveReadSupport; private $haveReadSupport;
@ -45,8 +45,8 @@ class WindowsPipes extends AbstractPipes
// //
// @see https://bugs.php.net/51800 // @see https://bugs.php.net/51800
$pipes = [ $pipes = [
Process::STDOUT => Process::OUT, process::STDOUT => process::OUT,
Process::STDERR => Process::ERR, process::STDERR => process::ERR,
]; ];
$tmpDir = sys_get_temp_dir(); $tmpDir = sys_get_temp_dir();
$lastError = 'unknown reason'; $lastError = 'unknown reason';
@ -147,9 +147,9 @@ class WindowsPipes extends AbstractPipes
if ($blocking) { if ($blocking) {
if ($w) { if ($w) {
@stream_select($r, $w, $e, 0, Process::TIMEOUT_PRECISION * 1E6); @stream_select($r, $w, $e, 0, process::TIMEOUT_PRECISION * 1E6);
} elseif ($this->fileHandles) { } elseif ($this->fileHandles) {
usleep(Process::TIMEOUT_PRECISION * 1E6); usleep(process::TIMEOUT_PRECISION * 1E6);
} }
} }
foreach ($this->fileHandles as $type => $fileHandle) { foreach ($this->fileHandles as $type => $fileHandle) {

View file

@ -13,16 +13,16 @@ namespace ncc\ThirdParty\Symfony\process;
use ncc\ThirdParty\Symfony\process\Exception\InvalidArgumentException; use ncc\ThirdParty\Symfony\process\Exception\InvalidArgumentException;
use ncc\ThirdParty\Symfony\process\Exception\LogicException; use ncc\ThirdParty\Symfony\process\Exception\LogicException;
use ncc\ThirdParty\Symfony\process\Exception\ProcessFailedException; use ncc\ThirdParty\Symfony\process\Exception\processFailedException;
use ncc\ThirdParty\Symfony\process\Exception\ProcessSignaledException; use ncc\ThirdParty\Symfony\process\Exception\processSignaledException;
use ncc\ThirdParty\Symfony\process\Exception\ProcessTimedOutException; use ncc\ThirdParty\Symfony\process\Exception\processTimedOutException;
use ncc\ThirdParty\Symfony\process\Exception\RuntimeException; use ncc\ThirdParty\Symfony\process\Exception\RuntimeException;
use ncc\ThirdParty\Symfony\process\Pipes\PipesInterface; use ncc\ThirdParty\Symfony\process\Pipes\PipesInterface;
use ncc\ThirdParty\Symfony\process\Pipes\UnixPipes; use ncc\ThirdParty\Symfony\process\Pipes\UnixPipes;
use ncc\ThirdParty\Symfony\process\Pipes\WindowsPipes; use ncc\ThirdParty\Symfony\process\Pipes\WindowsPipes;
/** /**
* Process is a thin wrapper around proc_* functions to easily * process is a thin wrapper around proc_* functions to easily
* start independent PHP processes. * start independent PHP processes.
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
@ -30,7 +30,7 @@ use ncc\ThirdParty\Symfony\process\Pipes\WindowsPipes;
* *
* @implements \IteratorAggregate<string, string> * @implements \IteratorAggregate<string, string>
*/ */
class Process implements \IteratorAggregate class process implements \IteratorAggregate
{ {
public const ERR = 'err'; public const ERR = 'err';
public const OUT = 'out'; public const OUT = 'out';
@ -103,7 +103,7 @@ class Process implements \IteratorAggregate
131 => 'Quit and dump core', 131 => 'Quit and dump core',
132 => 'Illegal instruction', 132 => 'Illegal instruction',
133 => 'Trace/breakpoint trap', 133 => 'Trace/breakpoint trap',
134 => 'Process aborted', 134 => 'process aborted',
135 => 'Bus error: "access to undefined portion of memory object"', 135 => 'Bus error: "access to undefined portion of memory object"',
136 => 'Floating point exception: "erroneous arithmetic operation"', 136 => 'Floating point exception: "erroneous arithmetic operation"',
137 => 'Kill (terminate immediately)', 137 => 'Kill (terminate immediately)',
@ -143,7 +143,7 @@ class Process implements \IteratorAggregate
public function __construct(array $command, string $cwd = null, array $env = null, mixed $input = null, ?float $timeout = 60) public function __construct(array $command, string $cwd = null, array $env = null, mixed $input = null, ?float $timeout = 60)
{ {
if (!\function_exists('proc_open')) { if (!\function_exists('proc_open')) {
throw new LogicException('The Process class relies on proc_open, which is not available on your PHP installation.'); throw new LogicException('The process class relies on proc_open, which is not available on your PHP installation.');
} }
$this->commandline = $command; $this->commandline = $command;
@ -167,7 +167,7 @@ class Process implements \IteratorAggregate
} }
/** /**
* Creates a Process instance as a command-line to be run in a shell wrapper. * Creates a process instance as a command-line to be run in a shell wrapper.
* *
* Command-lines are parsed by the shell of your OS (/bin/sh on Unix-like, cmd.exe on Windows.) * Command-lines are parsed by the shell of your OS (/bin/sh on Unix-like, cmd.exe on Windows.)
* This allows using e.g. pipes or conditional execution. In this mode, signals are sent to the * This allows using e.g. pipes or conditional execution. In this mode, signals are sent to the
@ -176,7 +176,7 @@ class Process implements \IteratorAggregate
* In order to inject dynamic values into command-lines, we strongly recommend using placeholders. * In order to inject dynamic values into command-lines, we strongly recommend using placeholders.
* This will save escaping values, which is not portable nor secure anyway: * This will save escaping values, which is not portable nor secure anyway:
* *
* $process = Process::fromShellCommandline('my_command "${:MY_VAR}"'); * $process = process::fromShellCommandline('my_command "${:MY_VAR}"');
* $process->run(null, ['MY_VAR' => $theValue]); * $process->run(null, ['MY_VAR' => $theValue]);
* *
* @param string $command The command line to pass to the shell of the OS * @param string $command The command line to pass to the shell of the OS
@ -216,7 +216,7 @@ class Process implements \IteratorAggregate
public function __clone() public function __clone()
{ {
$this->resetProcessData(); $this->resetprocessData();
} }
/** /**
@ -236,8 +236,8 @@ class Process implements \IteratorAggregate
* *
* @throws RuntimeException When process can't be launched * @throws RuntimeException When process can't be launched
* @throws RuntimeException When process is already running * @throws RuntimeException When process is already running
* @throws ProcessTimedOutException When process timed out * @throws processTimedOutException When process timed out
* @throws ProcessSignaledException When process stopped after receiving signal * @throws processSignaledException When process stopped after receiving signal
* @throws LogicException In case a callback is provided and output has been disabled * @throws LogicException In case a callback is provided and output has been disabled
* *
* @final * @final
@ -257,14 +257,14 @@ class Process implements \IteratorAggregate
* *
* @return $this * @return $this
* *
* @throws ProcessFailedException if the process didn't terminate successfully * @throws processFailedException if the process didn't terminate successfully
* *
* @final * @final
*/ */
public function mustRun(callable $callback = null, array $env = []): static public function mustRun(callable $callback = null, array $env = []): static
{ {
if (0 !== $this->run($callback, $env)) { if (0 !== $this->run($callback, $env)) {
throw new ProcessFailedException($this); throw new processFailedException($this);
} }
return $this; return $this;
@ -292,10 +292,10 @@ class Process implements \IteratorAggregate
public function start(callable $callback = null, array $env = []) public function start(callable $callback = null, array $env = [])
{ {
if ($this->isRunning()) { if ($this->isRunning()) {
throw new RuntimeException('Process is already running.'); throw new RuntimeException('process is already running.');
} }
$this->resetProcessData(); $this->resetprocessData();
$this->starttime = $this->lastOutputTime = microtime(true); $this->starttime = $this->lastOutputTime = microtime(true);
$this->callback = $this->buildCallback($callback); $this->callback = $this->buildCallback($callback);
$this->hasCallback = null !== $callback; $this->hasCallback = null !== $callback;
@ -381,7 +381,7 @@ class Process implements \IteratorAggregate
public function restart(callable $callback = null, array $env = []): static public function restart(callable $callback = null, array $env = []): static
{ {
if ($this->isRunning()) { if ($this->isRunning()) {
throw new RuntimeException('Process is already running.'); throw new RuntimeException('process is already running.');
} }
$process = clone $this; $process = clone $this;
@ -401,20 +401,20 @@ class Process implements \IteratorAggregate
* *
* @return int The exitcode of the process * @return int The exitcode of the process
* *
* @throws ProcessTimedOutException When process timed out * @throws processTimedOutException When process timed out
* @throws ProcessSignaledException When process stopped after receiving signal * @throws processSignaledException When process stopped after receiving signal
* @throws LogicException When process is not yet started * @throws LogicException When process is not yet started
*/ */
public function wait(callable $callback = null): int public function wait(callable $callback = null): int
{ {
$this->requireProcessIsStarted(__FUNCTION__); $this->requireprocessIsStarted(__FUNCTION__);
$this->updateStatus(false); $this->updateStatus(false);
if (null !== $callback) { if (null !== $callback) {
if (!$this->processPipes->haveReadSupport()) { if (!$this->processPipes->haveReadSupport()) {
$this->stop(0); $this->stop(0);
throw new LogicException('Pass the callback to the "Process::start" method or call enableOutput to use a callback with "Process::wait".'); throw new LogicException('Pass the callback to the "process::start" method or call enableOutput to use a callback with "process::wait".');
} }
$this->callback = $this->buildCallback($callback); $this->callback = $this->buildCallback($callback);
} }
@ -431,7 +431,7 @@ class Process implements \IteratorAggregate
} }
if ($this->processInformation['signaled'] && $this->processInformation['termsig'] !== $this->latestSignal) { if ($this->processInformation['signaled'] && $this->processInformation['termsig'] !== $this->latestSignal) {
throw new ProcessSignaledException($this); throw new processSignaledException($this);
} }
return $this->exitcode; return $this->exitcode;
@ -446,16 +446,16 @@ class Process implements \IteratorAggregate
* *
* @throws RuntimeException When process timed out * @throws RuntimeException When process timed out
* @throws LogicException When process is not yet started * @throws LogicException When process is not yet started
* @throws ProcessTimedOutException In case the timeout was reached * @throws processTimedOutException In case the timeout was reached
*/ */
public function waitUntil(callable $callback): bool public function waitUntil(callable $callback): bool
{ {
$this->requireProcessIsStarted(__FUNCTION__); $this->requireprocessIsStarted(__FUNCTION__);
$this->updateStatus(false); $this->updateStatus(false);
if (!$this->processPipes->haveReadSupport()) { if (!$this->processPipes->haveReadSupport()) {
$this->stop(0); $this->stop(0);
throw new LogicException('Pass the callback to the "Process::start" method or call enableOutput to use a callback with "Process::waitUntil".'); throw new LogicException('Pass the callback to the "process::start" method or call enableOutput to use a callback with "process::waitUntil".');
} }
$callback = $this->buildCallback($callback); $callback = $this->buildCallback($callback);
@ -600,9 +600,9 @@ class Process implements \IteratorAggregate
} }
/** /**
* Returns an iterator to the output of the process, with the output type as keys (Process::OUT/ERR). * Returns an iterator to the output of the process, with the output type as keys (process::OUT/ERR).
* *
* @param int $flags A bit field of Process::ITER_* flags * @param int $flags A bit field of process::ITER_* flags
* *
* @throws LogicException in case the output has been disabled * @throws LogicException in case the output has been disabled
* @throws LogicException In case the process is not started * @throws LogicException In case the process is not started
@ -726,7 +726,7 @@ class Process implements \IteratorAggregate
/** /**
* Returns the exit code returned by the process. * Returns the exit code returned by the process.
* *
* @return int|null The exit status code, null if the Process is not terminated * @return int|null The exit status code, null if the process is not terminated
*/ */
public function getExitCode(): ?int public function getExitCode(): ?int
{ {
@ -741,7 +741,7 @@ class Process implements \IteratorAggregate
* This method relies on the Unix exit code status standardization * This method relies on the Unix exit code status standardization
* and might not be relevant for other operating systems. * and might not be relevant for other operating systems.
* *
* @return string|null A string representation for the exit status code, null if the Process is not terminated * @return string|null A string representation for the exit status code, null if the process is not terminated
* *
* @see http://tldp.org/LDP/abs/html/exitcodes.html * @see http://tldp.org/LDP/abs/html/exitcodes.html
* @see http://en.wikipedia.org/wiki/Unix_signal * @see http://en.wikipedia.org/wiki/Unix_signal
@ -772,7 +772,7 @@ class Process implements \IteratorAggregate
*/ */
public function hasBeenSignaled(): bool public function hasBeenSignaled(): bool
{ {
$this->requireProcessIsTerminated(__FUNCTION__); $this->requireprocessIsTerminated(__FUNCTION__);
return $this->processInformation['signaled']; return $this->processInformation['signaled'];
} }
@ -787,7 +787,7 @@ class Process implements \IteratorAggregate
*/ */
public function getTermSignal(): int public function getTermSignal(): int
{ {
$this->requireProcessIsTerminated(__FUNCTION__); $this->requireprocessIsTerminated(__FUNCTION__);
if ($this->isSigchildEnabled() && -1 === $this->processInformation['termsig']) { if ($this->isSigchildEnabled() && -1 === $this->processInformation['termsig']) {
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal cannot be retrieved.'); throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal cannot be retrieved.');
@ -805,7 +805,7 @@ class Process implements \IteratorAggregate
*/ */
public function hasBeenStopped(): bool public function hasBeenStopped(): bool
{ {
$this->requireProcessIsTerminated(__FUNCTION__); $this->requireprocessIsTerminated(__FUNCTION__);
return $this->processInformation['stopped']; return $this->processInformation['stopped'];
} }
@ -819,7 +819,7 @@ class Process implements \IteratorAggregate
*/ */
public function getStopSignal(): int public function getStopSignal(): int
{ {
$this->requireProcessIsTerminated(__FUNCTION__); $this->requireprocessIsTerminated(__FUNCTION__);
return $this->processInformation['stopsig']; return $this->processInformation['stopsig'];
} }
@ -1101,7 +1101,7 @@ class Process implements \IteratorAggregate
} }
/** /**
* Gets the Process input. * Gets the process input.
* *
* @return resource|string|\Iterator|null * @return resource|string|\Iterator|null
*/ */
@ -1127,7 +1127,7 @@ class Process implements \IteratorAggregate
throw new LogicException('Input cannot be set while the process is running.'); throw new LogicException('Input cannot be set while the process is running.');
} }
$this->input = ProcessUtils::validateInput(__METHOD__, $input); $this->input = processUtils::validateInput(__METHOD__, $input);
return $this; return $this;
} }
@ -1138,7 +1138,7 @@ class Process implements \IteratorAggregate
* In case you run a background process (with the start method), you should * In case you run a background process (with the start method), you should
* trigger this method regularly to ensure the process timeout * trigger this method regularly to ensure the process timeout
* *
* @throws ProcessTimedOutException In case the timeout was reached * @throws processTimedOutException In case the timeout was reached
*/ */
public function checkTimeout() public function checkTimeout()
{ {
@ -1149,13 +1149,13 @@ class Process implements \IteratorAggregate
if (null !== $this->timeout && $this->timeout < microtime(true) - $this->starttime) { if (null !== $this->timeout && $this->timeout < microtime(true) - $this->starttime) {
$this->stop(0); $this->stop(0);
throw new ProcessTimedOutException($this, ProcessTimedOutException::TYPE_GENERAL); throw new processTimedOutException($this, processTimedOutException::TYPE_GENERAL);
} }
if (null !== $this->idleTimeout && $this->idleTimeout < microtime(true) - $this->lastOutputTime) { if (null !== $this->idleTimeout && $this->idleTimeout < microtime(true) - $this->lastOutputTime) {
$this->stop(0); $this->stop(0);
throw new ProcessTimedOutException($this, ProcessTimedOutException::TYPE_IDLE); throw new processTimedOutException($this, processTimedOutException::TYPE_IDLE);
} }
} }
@ -1333,7 +1333,7 @@ class Process implements \IteratorAggregate
throw new LogicException('Output has been disabled.'); throw new LogicException('Output has been disabled.');
} }
$this->requireProcessIsStarted($caller); $this->requireprocessIsStarted($caller);
$this->updateStatus($blocking); $this->updateStatus($blocking);
} }
@ -1411,7 +1411,7 @@ class Process implements \IteratorAggregate
/** /**
* Resets data related to the latest run of the process. * Resets data related to the latest run of the process.
*/ */
private function resetProcessData() private function resetprocessData()
{ {
$this->starttime = null; $this->starttime = null;
$this->callback = null; $this->callback = null;
@ -1532,10 +1532,10 @@ class Process implements \IteratorAggregate
* *
* @throws LogicException if the process has not run * @throws LogicException if the process has not run
*/ */
private function requireProcessIsStarted(string $functionName) private function requireprocessIsStarted(string $functionName)
{ {
if (!$this->isStarted()) { if (!$this->isStarted()) {
throw new LogicException(sprintf('Process must be started before calling "%s()".', $functionName)); throw new LogicException(sprintf('process must be started before calling "%s()".', $functionName));
} }
} }
@ -1544,10 +1544,10 @@ class Process implements \IteratorAggregate
* *
* @throws LogicException if the process is not yet terminated * @throws LogicException if the process is not yet terminated
*/ */
private function requireProcessIsTerminated(string $functionName) private function requireprocessIsTerminated(string $functionName)
{ {
if (!$this->isTerminated()) { if (!$this->isTerminated()) {
throw new LogicException(sprintf('Process must be terminated before calling "%s()".', $functionName)); throw new LogicException(sprintf('process must be terminated before calling "%s()".', $functionName));
} }
} }

View file

@ -14,13 +14,13 @@ namespace ncc\ThirdParty\Symfony\process;
use ncc\ThirdParty\Symfony\process\Exception\InvalidArgumentException; use ncc\ThirdParty\Symfony\process\Exception\InvalidArgumentException;
/** /**
* ProcessUtils is a bunch of utility methods. * processUtils is a bunch of utility methods.
* *
* This class contains static methods only and is not meant to be instantiated. * This class contains static methods only and is not meant to be instantiated.
* *
* @author Martin Hasoň <martin.hason@gmail.com> * @author Martin Hasoň <martin.hason@gmail.com>
*/ */
class ProcessUtils class processUtils
{ {
/** /**
* This class should not be instantiated. * This class should not be instantiated.
@ -30,7 +30,7 @@ class ProcessUtils
} }
/** /**
* Validates and normalizes a Process input. * Validates and normalizes a process input.
* *
* @param string $caller The name of method call that validates the input * @param string $caller The name of method call that validates the input
* @param mixed $input The input to validate * @param mixed $input The input to validate
@ -49,7 +49,7 @@ class ProcessUtils
if (\is_scalar($input)) { if (\is_scalar($input)) {
return (string) $input; return (string) $input;
} }
if ($input instanceof Process) { if ($input instanceof process) {
return $input->getIterator($input::ITER_SKIP_ERR); return $input->getIterator($input::ITER_SKIP_ERR);
} }
if ($input instanceof \Iterator) { if ($input instanceof \Iterator) {

View file

@ -1,12 +1,12 @@
Process Component process Component
================= =================
The Process component executes commands in sub-processes. The process component executes commands in sub-processes.
Sponsor Sponsor
------- -------
The Process component for Symfony 6.1 is [backed][1] by [SensioLabs][2]. The process component for Symfony 6.1 is [backed][1] by [SensioLabs][2].
As the creator of Symfony, SensioLabs supports companies using Symfony, with an As the creator of Symfony, SensioLabs supports companies using Symfony, with an
offering encompassing consultancy, expertise, services, training, and technical offering encompassing consultancy, expertise, services, training, and technical

View file

@ -9,7 +9,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace ncc\Symfony\Component\Uid; namespace ncc\ThirdParty\Symfony\Uid;
/** /**
* @author Nicolas Grekas <p@tchwork.com> * @author Nicolas Grekas <p@tchwork.com>

View file

@ -9,7 +9,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace ncc\Symfony\Component\Uid; namespace ncc\ThirdParty\Symfony\Uid;
/** /**
* @internal * @internal

View file

@ -0,0 +1,29 @@
CHANGELOG
=========
5.4
---
* Add `NilUlid`
5.3
---
* The component is not marked as `@experimental` anymore
* Add `AbstractUid::fromBinary()`, `AbstractUid::fromBase58()`, `AbstractUid::fromBase32()` and `AbstractUid::fromRfc4122()`
* [BC BREAK] Replace `UuidV1::getTime()`, `UuidV6::getTime()` and `Ulid::getTime()` by `UuidV1::getDateTime()`, `UuidV6::getDateTime()` and `Ulid::getDateTime()`
* Add `Uuid::NAMESPACE_*` constants from RFC4122
* Add `UlidFactory`, `UuidFactory`, `RandomBasedUuidFactory`, `TimeBasedUuidFactory` and `NameBasedUuidFactory`
* Add commands to generate and inspect UUIDs and ULIDs
5.2.0
-----
* made UUIDv6 always return truly random node fields to prevent leaking the MAC of the host
5.1.0
-----
* added support for UUID
* added support for ULID
* added the component

View file

@ -0,0 +1,122 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ncc\ThirdParty\Symfony\uid\Command;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use ncc\ThirdParty\Symfony\Uid\Factory\UlidFactory;
#[AsCommand(name: 'ulid:generate', description: 'Generate a ULID')]
class GenerateUlidCommand extends Command
{
private const FORMAT_OPTIONS = [
'base32',
'base58',
'rfc4122',
];
private UlidFactory $factory;
public function __construct(UlidFactory $factory = null)
{
$this->factory = $factory ?? new UlidFactory();
parent::__construct();
}
/**
* {@inheritdoc}
*/
protected function configure(): void
{
$this
->setDefinition([
new InputOption('time', null, InputOption::VALUE_REQUIRED, 'The ULID timestamp: a parsable date/time string'),
new InputOption('count', 'c', InputOption::VALUE_REQUIRED, 'The number of ULID to generate', 1),
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'The ULID output format: base32, base58 or rfc4122', 'base32'),
])
->setHelp(<<<'EOF'
The <info>%command.name%</info> command generates a ULID.
<info>php %command.full_name%</info>
To specify the timestamp:
<info>php %command.full_name% --time="2021-02-16 14:09:08"</info>
To generate several ULIDs:
<info>php %command.full_name% --count=10</info>
To output a specific format:
<info>php %command.full_name% --format=rfc4122</info>
EOF
)
;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
if (null !== $time = $input->getOption('time')) {
try {
$time = new \DateTimeImmutable($time);
} catch (\Exception $e) {
$io->error(sprintf('Invalid timestamp "%s": %s', $time, str_replace('DateTimeImmutable::__construct(): ', '', $e->getMessage())));
return 1;
}
}
$formatOption = $input->getOption('format');
if (\in_array($formatOption, self::FORMAT_OPTIONS)) {
$format = 'to'.ucfirst($formatOption);
} else {
$io->error(sprintf('Invalid format "%s", did you mean "base32", "base58" or "rfc4122"?', $input->getOption('format')));
return 1;
}
$count = (int) $input->getOption('count');
try {
for ($i = 0; $i < $count; ++$i) {
$output->writeln($this->factory->create($time)->$format());
}
} catch (\Exception $e) {
$io->error($e->getMessage());
return 1;
}
return 0;
}
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
{
if ($input->mustSuggestOptionValuesFor('format')) {
$suggestions->suggestValues(self::FORMAT_OPTIONS);
}
}
}

View file

@ -0,0 +1,216 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ncc\ThirdParty\Symfony\uid\Command;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use ncc\ThirdParty\Symfony\Uid\Factory\UuidFactory;
use ncc\ThirdParty\Symfony\uid\Uuid;
#[AsCommand(name: 'uuid:generate', description: 'Generate a UUID')]
class GenerateUuidCommand extends Command
{
private UuidFactory $factory;
public function __construct(UuidFactory $factory = null)
{
$this->factory = $factory ?? new UuidFactory();
parent::__construct();
}
/**
* {@inheritdoc}
*/
protected function configure(): void
{
$this
->setDefinition([
new InputOption('time-based', null, InputOption::VALUE_REQUIRED, 'The timestamp, to generate a time-based UUID: a parsable date/time string'),
new InputOption('node', null, InputOption::VALUE_REQUIRED, 'The UUID whose node part should be used as the node of the generated UUID'),
new InputOption('name-based', null, InputOption::VALUE_REQUIRED, 'The name, to generate a name-based UUID'),
new InputOption('namespace', null, InputOption::VALUE_REQUIRED, 'The UUID to use at the namespace for named-based UUIDs, predefined namespaces keywords "dns", "url", "oid" and "x500" are accepted'),
new InputOption('random-based', null, InputOption::VALUE_NONE, 'To generate a random-based UUID'),
new InputOption('count', 'c', InputOption::VALUE_REQUIRED, 'The number of UUID to generate', 1),
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'The UUID output format: rfc4122, base58 or base32', 'rfc4122'),
])
->setHelp(<<<'EOF'
The <info>%command.name%</info> generates a UUID.
<info>php %command.full_name%</info>
To generate a time-based UUID:
<info>php %command.full_name% --time-based=now</info>
To specify a time-based UUID's node:
<info>php %command.full_name% --time-based=@1613480254 --node=fb3502dc-137e-4849-8886-ac90d07f64a7</info>
To generate a name-based UUID:
<info>php %command.full_name% --name-based=foo</info>
To specify a name-based UUID's namespace:
<info>php %command.full_name% --name-based=bar --namespace=fb3502dc-137e-4849-8886-ac90d07f64a7</info>
To generate a random-based UUID:
<info>php %command.full_name% --random-based</info>
To generate several UUIDs:
<info>php %command.full_name% --count=10</info>
To output a specific format:
<info>php %command.full_name% --format=base58</info>
EOF
)
;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
$time = $input->getOption('time-based');
$node = $input->getOption('node');
$name = $input->getOption('name-based');
$namespace = $input->getOption('namespace');
$random = $input->getOption('random-based');
if (false !== ($time ?? $name ?? $random) && 1 < ((null !== $time) + (null !== $name) + $random)) {
$io->error('Only one of "--time-based", "--name-based" or "--random-based" can be provided at a time.');
return 1;
}
if (null === $time && null !== $node) {
$io->error('Option "--node" can only be used with "--time-based".');
return 1;
}
if (null === $name && null !== $namespace) {
$io->error('Option "--namespace" can only be used with "--name-based".');
return 1;
}
switch (true) {
case null !== $time:
if (null !== $node) {
try {
$node = Uuid::fromString($node);
} catch (\InvalidArgumentException $e) {
$io->error(sprintf('Invalid node "%s": %s', $node, $e->getMessage()));
return 1;
}
}
try {
new \DateTimeImmutable($time);
} catch (\Exception $e) {
$io->error(sprintf('Invalid timestamp "%s": %s', $time, str_replace('DateTimeImmutable::__construct(): ', '', $e->getMessage())));
return 1;
}
$create = function () use ($node, $time): Uuid {
return $this->factory->timeBased($node)->create(new \DateTimeImmutable($time));
};
break;
case null !== $name:
if ($namespace && !\in_array($namespace, ['dns', 'url', 'oid', 'x500'], true)) {
try {
$namespace = Uuid::fromString($namespace);
} catch (\InvalidArgumentException $e) {
$io->error(sprintf('Invalid namespace "%s": %s', $namespace, $e->getMessage()));
return 1;
}
}
$create = function () use ($namespace, $name): Uuid {
try {
$factory = $this->factory->nameBased($namespace);
} catch (\LogicException) {
throw new \InvalidArgumentException('Missing namespace: use the "--namespace" option or configure a default namespace in the underlying factory.');
}
return $factory->create($name);
};
break;
case $random:
$create = $this->factory->randomBased()->create(...);
break;
default:
$create = $this->factory->create(...);
break;
}
$formatOption = $input->getOption('format');
if (\in_array($formatOption, $this->getAvailableFormatOptions())) {
$format = 'to'.ucfirst($formatOption);
} else {
$io->error(sprintf('Invalid format "%s", did you mean "base32", "base58" or "rfc4122"?', $formatOption));
return 1;
}
$count = (int) $input->getOption('count');
try {
for ($i = 0; $i < $count; ++$i) {
$output->writeln($create()->$format());
}
} catch (\Exception $e) {
$io->error($e->getMessage());
return 1;
}
return 0;
}
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
{
if ($input->mustSuggestOptionValuesFor('format')) {
$suggestions->suggestValues($this->getAvailableFormatOptions());
}
}
private function getAvailableFormatOptions(): array
{
return [
'base32',
'base58',
'rfc4122',
];
}
}

View file

@ -0,0 +1,72 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ncc\ThirdParty\Symfony\uid\Command;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\TableSeparator;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use ncc\ThirdParty\Symfony\uid\Ulid;
#[AsCommand(name: 'ulid:inspect', description: 'Inspect a ULID')]
class InspectUlidCommand extends Command
{
/**
* {@inheritdoc}
*/
protected function configure(): void
{
$this
->setDefinition([
new InputArgument('ulid', InputArgument::REQUIRED, 'The ULID to inspect'),
])
->setHelp(<<<'EOF'
The <info>%command.name%</info> displays information about a ULID.
<info>php %command.full_name% 01EWAKBCMWQ2C94EXNN60ZBS0Q</info>
<info>php %command.full_name% 1BVdfLn3ERmbjYBLCdaaLW</info>
<info>php %command.full_name% 01771535-b29c-b898-923b-b5a981f5e417</info>
EOF
)
;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
try {
$ulid = Ulid::fromString($input->getArgument('ulid'));
} catch (\InvalidArgumentException $e) {
$io->error($e->getMessage());
return 1;
}
$io->table(['Label', 'Value'], [
['toBase32 (canonical)', (string) $ulid],
['toBase58', $ulid->toBase58()],
['toRfc4122', $ulid->toRfc4122()],
new TableSeparator(),
['Time', $ulid->getDateTime()->format('Y-m-d H:i:s.v \U\T\C')],
]);
return 0;
}
}

View file

@ -0,0 +1,87 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ncc\ThirdParty\Symfony\uid\Command;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\TableSeparator;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use ncc\ThirdParty\Symfony\uid\Uuid;
use ncc\ThirdParty\Symfony\uid\UuidV1;
use ncc\ThirdParty\Symfony\uid\UuidV6;
#[AsCommand(name: 'uuid:inspect', description: 'Inspect a UUID')]
class InspectUuidCommand extends Command
{
/**
* {@inheritdoc}
*/
protected function configure(): void
{
$this
->setDefinition([
new InputArgument('uuid', InputArgument::REQUIRED, 'The UUID to inspect'),
])
->setHelp(<<<'EOF'
The <info>%command.name%</info> displays information about a UUID.
<info>php %command.full_name% a7613e0a-5986-11eb-a861-2bf05af69e52</info>
<info>php %command.full_name% MfnmaUvvQ1h8B14vTwt6dX</info>
<info>php %command.full_name% 57C4Z0MPC627NTGR9BY1DFD7JJ</info>
EOF
)
;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
try {
/** @var Uuid $uuid */
$uuid = Uuid::fromString($input->getArgument('uuid'));
} catch (\InvalidArgumentException $e) {
$io->error($e->getMessage());
return 1;
}
if (-1 === $version = uuid_type($uuid)) {
$version = 'nil';
} elseif (0 === $version || 2 === $version || 6 < $version) {
$version = 'unknown';
}
$rows = [
['Version', $version],
['toRfc4122 (canonical)', (string) $uuid],
['toBase58', $uuid->toBase58()],
['toBase32', $uuid->toBase32()],
];
if ($uuid instanceof UuidV1 || $uuid instanceof UuidV6) {
$rows[] = new TableSeparator();
$rows[] = ['Time', $uuid->getDateTime()->format('Y-m-d H:i:s.u \U\T\C')];
}
$io->table(['Label', 'Value'], $rows);
return 0;
}
}

View file

@ -9,11 +9,11 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace ncc\Symfony\Component\Uid\Factory; namespace ncc\ThirdParty\Symfony\uid\Factory;
use ncc\Symfony\Component\Uid\Uuid; use ncc\ThirdParty\Symfony\uid\Uuid;
use ncc\Symfony\Component\Uid\UuidV3; use ncc\ThirdParty\Symfony\uid\UuidV3;
use ncc\Symfony\Component\Uid\UuidV5; use ncc\ThirdParty\Symfony\uid\UuidV5;
class NameBasedUuidFactory class NameBasedUuidFactory
{ {

View file

@ -9,9 +9,9 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace ncc\Symfony\Component\Uid\Factory; namespace ncc\ThirdParty\Symfony\uid\Factory;
use ncc\Symfony\Component\Uid\UuidV4; use ncc\ThirdParty\Symfony\uid\UuidV4;
class RandomBasedUuidFactory class RandomBasedUuidFactory
{ {

View file

@ -9,11 +9,11 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace ncc\Symfony\Component\Uid\Factory; namespace ncc\ThirdParty\Symfony\uid\Factory;
use ncc\Symfony\Component\Uid\Uuid; use ncc\ThirdParty\Symfony\uid\Uuid;
use ncc\Symfony\Component\Uid\UuidV1; use ncc\ThirdParty\Symfony\uid\UuidV1;
use ncc\Symfony\Component\Uid\UuidV6; use ncc\ThirdParty\Symfony\uid\UuidV6;
class TimeBasedUuidFactory class TimeBasedUuidFactory
{ {

View file

@ -9,9 +9,9 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace ncc\Symfony\Component\Uid\Factory; namespace ncc\ThirdParty\Symfony\uid\Factory;
use ncc\Symfony\Component\Uid\Ulid; use ncc\ThirdParty\Symfony\uid\Ulid;
class UlidFactory class UlidFactory
{ {

View file

@ -9,13 +9,13 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace ncc\Symfony\Component\Uid\Factory; namespace ncc\ThirdParty\Symfony\uid\Factory;
use ncc\Symfony\Component\Uid\Uuid; use ncc\ThirdParty\Symfony\uid\Uuid;
use ncc\Symfony\Component\Uid\UuidV1; use ncc\ThirdParty\Symfony\uid\UuidV1;
use ncc\Symfony\Component\Uid\UuidV4; use ncc\ThirdParty\Symfony\uid\UuidV4;
use ncc\Symfony\Component\Uid\UuidV5; use ncc\ThirdParty\Symfony\uid\UuidV5;
use ncc\Symfony\Component\Uid\UuidV6; use ncc\ThirdParty\Symfony\uid\UuidV6;
class UuidFactory class UuidFactory
{ {

View file

@ -9,7 +9,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace ncc\Symfony\Component\Uid; namespace ncc\ThirdParty\Symfony\Uid;
class NilUlid extends Ulid class NilUlid extends Ulid
{ {

View file

@ -9,7 +9,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace ncc\Symfony\Component\Uid; namespace ncc\ThirdParty\Symfony\Uid;
/** /**
* @author Grégoire Pineau <lyrixx@lyrixx.info> * @author Grégoire Pineau <lyrixx@lyrixx.info>

View file

@ -9,7 +9,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace ncc\Symfony\Component\Uid; namespace ncc\ThirdParty\Symfony\Uid;
/** /**
* A ULID is lexicographically sortable and contains a 48-bit timestamp and 80-bit of crypto-random entropy. * A ULID is lexicographically sortable and contains a 48-bit timestamp and 80-bit of crypto-random entropy.

View file

@ -9,7 +9,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace ncc\Symfony\Component\Uid; namespace ncc\ThirdParty\Symfony\Uid;
/** /**
* @author Grégoire Pineau <lyrixx@lyrixx.info> * @author Grégoire Pineau <lyrixx@lyrixx.info>
@ -72,7 +72,6 @@ class Uuid extends AbstractUid
UuidV6::TYPE => new UuidV6($uuid), UuidV6::TYPE => new UuidV6($uuid),
default => new self($uuid), default => new self($uuid),
}; };
} }
final public static function v1(): UuidV1 final public static function v1(): UuidV1

View file

@ -9,7 +9,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace ncc\Symfony\Component\Uid; namespace ncc\ThirdParty\Symfony\Uid;
/** /**
* A v1 UUID contains a 60-bit timestamp and 62 extra unique bits. * A v1 UUID contains a 60-bit timestamp and 62 extra unique bits.

View file

@ -9,7 +9,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace ncc\Symfony\Component\Uid; namespace ncc\ThirdParty\Symfony\Uid;
/** /**
* A v3 UUID contains an MD5 hash of another UUID and a name. * A v3 UUID contains an MD5 hash of another UUID and a name.

View file

@ -9,7 +9,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace ncc\Symfony\Component\Uid; namespace ncc\ThirdParty\Symfony\Uid;
/** /**
* A v4 UUID contains a 122-bit random number. * A v4 UUID contains a 122-bit random number.

View file

@ -9,7 +9,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace ncc\Symfony\Component\Uid; namespace ncc\ThirdParty\Symfony\Uid;
/** /**
* A v5 UUID contains a SHA1 hash of another UUID and a name. * A v5 UUID contains a SHA1 hash of another UUID and a name.

View file

@ -9,7 +9,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace ncc\Symfony\Component\Uid; namespace ncc\ThirdParty\Symfony\Uid;
/** /**
* A v6 UUID is lexicographically sortable and contains a 60-bit timestamp and 62 extra unique bits. * A v6 UUID is lexicographically sortable and contains a 60-bit timestamp and 62 extra unique bits.

View file

@ -0,0 +1 @@
6.1.3

View file

@ -0,0 +1,40 @@
<?php
// @codingStandardsIgnoreFile
// @codeCoverageIgnoreStart
// this is an autogenerated file - do not edit
spl_autoload_register(
function($class) {
static $classes = null;
if ($classes === null) {
$classes = array(
'ncc\\thirdparty\\symfony\\uid\\abstractuid' => '/AbstractUid.php',
'ncc\\thirdparty\\symfony\\uid\\binaryutil' => '/BinaryUtil.php',
'ncc\\thirdparty\\symfony\\uid\\command\\generateulidcommand' => '/Command/GenerateUlidCommand.php',
'ncc\\thirdparty\\symfony\\uid\\command\\generateuuidcommand' => '/Command/GenerateUuidCommand.php',
'ncc\\thirdparty\\symfony\\uid\\command\\inspectulidcommand' => '/Command/InspectUlidCommand.php',
'ncc\\thirdparty\\symfony\\uid\\command\\inspectuuidcommand' => '/Command/InspectUuidCommand.php',
'ncc\\thirdparty\\symfony\\uid\\factory\\namebaseduuidfactory' => '/Factory/NameBasedUuidFactory.php',
'ncc\\thirdparty\\symfony\\uid\\factory\\randombaseduuidfactory' => '/Factory/RandomBasedUuidFactory.php',
'ncc\\thirdparty\\symfony\\uid\\factory\\timebaseduuidfactory' => '/Factory/TimeBasedUuidFactory.php',
'ncc\\thirdparty\\symfony\\uid\\factory\\ulidfactory' => '/Factory/UlidFactory.php',
'ncc\\thirdparty\\symfony\\uid\\factory\\uuidfactory' => '/Factory/UuidFactory.php',
'ncc\\thirdparty\\symfony\\uid\\nilulid' => '/NilUlid.php',
'ncc\\thirdparty\\symfony\\uid\\niluuid' => '/NilUuid.php',
'ncc\\thirdparty\\symfony\\uid\\ulid' => '/Ulid.php',
'ncc\\thirdparty\\symfony\\uid\\uuid' => '/Uuid.php',
'ncc\\thirdparty\\symfony\\uid\\uuidv1' => '/UuidV1.php',
'ncc\\thirdparty\\symfony\\uid\\uuidv3' => '/UuidV3.php',
'ncc\\thirdparty\\symfony\\uid\\uuidv4' => '/UuidV4.php',
'ncc\\thirdparty\\symfony\\uid\\uuidv5' => '/UuidV5.php',
'ncc\\thirdparty\\symfony\\uid\\uuidv6' => '/UuidV6.php'
);
}
$cn = strtolower($class);
if (isset($classes[$cn])) {
require __DIR__ . $classes[$cn];
}
},
true,
false
);
// @codeCoverageIgnoreEnd

View file

@ -1 +0,0 @@
6.1.0

34
src/ncc/autoload.php Normal file
View file

@ -0,0 +1,34 @@
<?php
/**
* NCC Autoloader file v1.0
*
* This file attempts to autoload all the required files for NCC and
* initialize NCC immediately, this file checks for initialization
* before proceeding to improve performance.
*/
if(defined('NCC_INIT') == false)
{
$third_party_path = __DIR__ . DIRECTORY_SEPARATOR . 'ThirdParty' . DIRECTORY_SEPARATOR;
$target_files = [
__DIR__ . DIRECTORY_SEPARATOR . 'autoload_spl.php',
$third_party_path . 'defuse' . DIRECTORY_SEPARATOR . 'php-encryption' . DIRECTORY_SEPARATOR . 'autoload_spl.php',
$third_party_path . 'Symfony' . DIRECTORY_SEPARATOR . 'polyfill-ctype' . DIRECTORY_SEPARATOR . 'autoload_spl.php',
$third_party_path . 'Symfony' . DIRECTORY_SEPARATOR . 'polyfill-ctype' . DIRECTORY_SEPARATOR . 'bootstrap.php',
$third_party_path . 'Symfony' . DIRECTORY_SEPARATOR . 'polyfill-mbstring' . DIRECTORY_SEPARATOR . 'autoload_spl.php',
$third_party_path . 'Symfony' . DIRECTORY_SEPARATOR . 'polyfill-mbstring' . DIRECTORY_SEPARATOR . 'bootstrap.php',
$third_party_path . 'Symfony' . DIRECTORY_SEPARATOR . 'Process' . DIRECTORY_SEPARATOR . 'autoload_spl.php',
$third_party_path . 'Symfony' . DIRECTORY_SEPARATOR . 'Uid' . DIRECTORY_SEPARATOR . 'autoload_spl.php',
];
foreach($target_files as $file)
{
require_once($file);
}
if(\ncc\ncc::initialize() == false)
{
trigger_error('NCC Failed to initialize', E_USER_WARNING);
}
}