### Quickstart: Execute and Capture Output Source: https://github.com/rectorphp/rector/blob/main/vendor/react/child-process/README.md Demonstrates how to start a child process, listen for data on its standard output, and handle its exit event. ```php $process = new React\ChildProcess\Process('echo foo'); $process->start(); $process->stdout->on('data', function ($chunk) { echo $chunk; }); $process->on('exit', function($exitCode, $termSignal) { echo 'Process exited with code ' . $exitCode . PHP_EOL; }); ``` -------------------------------- ### Socket Client Quickstart Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md An example of a ReactPHP Socket client that connects to a server, pipes the server's output to STDOUT, and sends a greeting message. ```APIDOC ## Socket Client Quickstart ### Description This example demonstrates how to create a simple TCP client using `React\Socket\Connector`. It connects to a specified address, pipes all incoming data from the server to the standard output, and sends a "Hello World!" message to the server. ### Method ```php $connector = new React\Socket\Connector(); $connector->connect(string $address) ``` ### Endpoint `127.0.0.1:8080` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```php $connector = new React\Socket\Connector(); $connector->connect('127.0.0.1:8080')->then(function (React\Socket\ConnectionInterface $connection) { $connection->pipe(new React\Stream\WritableResourceStream(STDOUT)); $connection->write("Hello World!\n"); }, function (Exception $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; }); ``` ### Response #### Success Response (200) None explicitly defined for connection, but data received from the server is piped to STDOUT. #### Response Example None ``` -------------------------------- ### Socket Server Quickstart Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md A basic example of a ReactPHP Socket server that writes a welcome message to connected clients and closes the connection if any data is received. ```APIDOC ## Socket Server Quickstart ### Description This example demonstrates how to create a simple TCP server using `React\Socket\SocketServer`. It accepts incoming connections, sends a welcome message including the remote address, and then closes the connection when any data is received from the client. ### Method ```php new React\Socket\SocketServer(string $address) ``` ### Endpoint `127.0.0.1:8080` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```php $socket = new React\Socket\SocketServer('127.0.0.1:8080'); $socket->on('connection', function (React\Socket\ConnectionInterface $connection) { $connection->write("Hello " . $connection->getRemoteAddress() . "!\n"); $connection->write("Welcome to this amazing server!\n"); $connection->write("Here's a tip: don't say anything.\n"); $connection->on('data', function ($data) use ($connection) { $connection->close(); }); }); ``` ### Response #### Success Response (200) None explicitly defined for server instantiation, but connection events are handled. #### Response Example None ``` -------------------------------- ### Install CPU Core Counter Package Source: https://github.com/rectorphp/rector/blob/main/vendor/fidry/cpu-core-counter/README.md Install the package using Composer. ```sh composer require fidry/cpu-core-counter ``` -------------------------------- ### Composer Installation Source: https://github.com/rectorphp/rector/blob/main/vendor/react/stream/README.md Command to install the react/stream library using Composer. ```bash composer require react/stream:^1.4 ``` -------------------------------- ### Install phpstan/phpdoc-parser Source: https://github.com/rectorphp/rector/blob/main/vendor/phpstan/phpdoc-parser/README.md Install the library using Composer. ```bash composer require phpstan/phpdoc-parser ``` -------------------------------- ### Install Webmozart Assert using Composer Source: https://github.com/rectorphp/rector/blob/main/vendor/webmozart/assert/README.md Install the webmozart/assert package using Composer. ```bash composer require webmozart/assert ``` -------------------------------- ### Install Composer Semver Source: https://github.com/rectorphp/rector/blob/main/vendor/composer/semver/README.md Install the latest version of the composer/semver library using Composer. ```bash composer require composer/semver ``` -------------------------------- ### Execute a Simple Command Source: https://github.com/rectorphp/rector/blob/main/vendor/react/child-process/README.md Instantiate and start a process with a basic command string. ```php $process = new Process('echo test'); $process->start(); ``` -------------------------------- ### Install Dependencies and Check Platform Requirements Source: https://github.com/rectorphp/rector/blob/main/CONTRIBUTING.md Install project dependencies using Composer and verify that your PHP environment meets the project's platform requirements. ```bash composer update composer check-platform-reqs ``` -------------------------------- ### Install React Cache via Composer Source: https://github.com/rectorphp/rector/blob/main/vendor/react/cache/README.md Installs the React Cache library using Composer. This is the recommended installation method. ```bash composer require react/cache:^1.2 ``` -------------------------------- ### Install via Composer Source: https://github.com/rectorphp/rector/blob/main/vendor/clue/ndjson-react/README.md Install the library using Composer by requiring the specific package version. ```bash composer require clue/ndjson-react:^1.3 ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/rectorphp/rector/blob/main/vendor/react/cache/README.md Installs all project dependencies, including development tools like PHPUnit, using Composer. ```bash composer install ``` -------------------------------- ### Install CI Detector via Composer Source: https://github.com/rectorphp/rector/blob/main/vendor/ondram/ci-detector/README.md Install the library using Composer to manage dependencies. ```sh $ composer require ondram/ci-detector ``` -------------------------------- ### Bash: Install React Promise with Composer (Specific Version) Source: https://github.com/rectorphp/rector/blob/main/vendor/react/promise/README.md Installs the react/promise library version 3.2 using Composer. This command ensures you get the latest supported version from the 3.x branch. ```bash composer require react/promise:^3.2 ``` -------------------------------- ### ReactPHP Socket Server Quickstart Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md Sets up a basic TCP server that writes a welcome message to new connections and closes the connection if any data is received. ```php $socket = new React\Socket\SocketServer('127.0.0.1:8080'); $socket->on('connection', function (React\Socket\ConnectionInterface $connection) { $connection->write("Hello " . $connection->getRemoteAddress() . "!\n"); $connection->write("Welcome to this amazing server!\n"); $connection->write("Here's a tip: don't say anything.\n"); $connection->on('data', function ($data) use ($connection) { $connection->close(); }); }); ``` -------------------------------- ### Install React Child Process via Composer Source: https://github.com/rectorphp/rector/blob/main/vendor/react/child-process/README.md Use this command to install the recommended version of the React Child Process library. ```bash composer require react/child-process:^0.6.7 ``` -------------------------------- ### Install Nette Utils via Composer Source: https://github.com/rectorphp/rector/blob/main/vendor/nette/utils/readme.md Use Composer to install the Nette Utils library. This is the recommended method for integrating the package into your project. ```bash composer require nette/utils ``` -------------------------------- ### Create a Default English Inflector Instance Source: https://github.com/rectorphp/rector/blob/main/vendor/doctrine/inflector/docs/en/index.rst Instantiate the Inflector using the InflectorFactory for default English language rules. This is the simplest way to get started. ```php use Doctrine\Inflector\InflectorFactory; $inflector = InflectorFactory::create()->build(); ``` -------------------------------- ### Install React DNS with Composer Source: https://github.com/rectorphp/rector/blob/main/vendor/react/dns/README.md Use this command to install the latest supported version of the React DNS library via Composer. ```bash composer require react/dns:^1.14 ``` -------------------------------- ### Install Composer PCRE Source: https://github.com/rectorphp/rector/blob/main/vendor/composer/pcre/README.md Install the latest version of the composer/pcre library using Composer. ```bash $ composer require composer/pcre ``` -------------------------------- ### Install React Event Loop via Composer Source: https://github.com/rectorphp/rector/blob/main/vendor/react/event-loop/README.md Install the latest supported version of the React Event Loop library using Composer. ```bash composer require react/event-loop:^1.6 ``` -------------------------------- ### ReactPHP Socket Client Quickstart Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md Connects to a server, pipes its output to STDOUT, and sends a "Hello World!" message. Handles connection errors by echoing the error message. ```php $connector = new React\Socket\Connector(); $connector->connect('127.0.0.1:8080')->then(function (React\Socket\ConnectionInterface $connection) { $connection->pipe(new React\Stream\WritableResourceStream(STDOUT)); $connection->write("Hello World!\n"); }, function (Exception $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; }); ``` -------------------------------- ### Install React Socket via Composer Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md Use this command to install the latest supported version of the react/socket library through Composer. ```bash composer require react/socket:^1.17 ``` -------------------------------- ### Run Full Build with Make Source: https://github.com/rectorphp/rector/blob/main/vendor/phpstan/phpdoc-parser/README.md Execute the full build process, which includes linting and coding standards checks. Ensure you have run 'composer install' or 'composer update' beforehand. ```bash make ``` -------------------------------- ### CSV Alternative Example Source: https://github.com/rectorphp/rector/blob/main/vendor/clue/ndjson-react/README.md This example demonstrates how the same data might be represented in CSV format, highlighting potential issues with line breaks within fields. ```text name,age,comment Alice,30,"Yes, I like cheese" Bob,50,"Hello World!" ``` -------------------------------- ### Install Composer Xdebug Handler Source: https://github.com/rectorphp/rector/blob/main/vendor/composer/xdebug-handler/README.md Install the latest version of the xdebug-handler package using Composer. ```bash composer require composer/xdebug-handler ``` -------------------------------- ### Install Rector Source: https://github.com/rectorphp/rector/blob/main/README.md Install Rector as a development dependency using Composer. ```bash composer require rector/rector --dev ``` -------------------------------- ### Bash: Install React Promise with Composer (Multiple Versions) Source: https://github.com/rectorphp/rector/blob/main/vendor/react/promise/README.md Installs the react/promise library, supporting versions 3.x, 2.x, and 1.x using Composer. This allows targeting multiple PHP versions. ```bash composer require "react/promise:^3 || ^2 || ^1" ``` -------------------------------- ### NDJSON Example Source: https://github.com/rectorphp/rector/blob/main/vendor/clue/ndjson-react/README.md This example shows two user records in NDJSON format. Each line is a valid JSON object. ```json {"name":"Alice","age":30,"comment":"Yes, I like cheese"} {"name":"Bob","age":50,"comment":"Hello\nWorld!"} ``` -------------------------------- ### Execute Sequential Processes with Event Handling Source: https://github.com/rectorphp/rector/blob/main/vendor/react/child-process/README.md Launch processes one after another, using the 'exit' event to conditionally start the next process. ```php $first = new Process('cat first'); $first->start(); $first->on('exit', function () { $second = new Process('cat second'); $second->start(); }); ``` -------------------------------- ### Run Rector with Xdebug Source: https://github.com/rectorphp/rector/blob/main/README.md Enable Xdebug integration by adding the --xdebug option. Ensure Xdebug is installed and configured correctly. ```bash vendor/bin/rector src/Controller --dry-run --xdebug ``` -------------------------------- ### Instantiate SecureServer with Specific TLS Version Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md Explicitly choose the TLS version for negotiation by setting the 'crypto_method' option in the TLS context. This example sets it to TLSv1.2. ```php $server = new React\Socket\TcpServer(8000); $server = new React\Socket\SecureServer($server, null, array( 'local_cert' => 'server.pem', 'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_SERVER )); ``` -------------------------------- ### Instantiate Limiting Server Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md Wrap an existing server with LimitingServer to restrict the number of concurrent connections. A maximum of 100 connections is set in this example. The server emits a 'connection' event for valid connections. ```php $server = new React\Socket\LimitingServer($server, 100); $server->on('connection', function (React\Socket\ConnectionInterface $connection) { $connection->write('hello there!' . PHP_EOL); … }); ``` -------------------------------- ### Create Symfony Container PHP Source: https://github.com/rectorphp/rector/blob/main/vendor/rector/rector-symfony/README.md Example of how to create a Symfony container PHP file for Rector to use. This ensures the container is fully booted and accessible. ```php // tests/symfony-container.php use App\Kernel; require __DIR__ . '/bootstrap.php'; $appKernel = new Kernel('test', false); $appKernel->boot(); return $appKernel->getContainer(); ``` -------------------------------- ### Detect CI Environment and Get Build Info Source: https://github.com/rectorphp/rector/blob/main/vendor/ondram/ci-detector/README.md Instantiate the detector, check if running on CI, and retrieve CI details. Use this to conditionally execute code or log build information. ```php isCiDetected()) { // Make sure we are on CI environment echo 'You are running this script on CI server!'; $ci = $ciDetector->detect(); // Returns class implementing CiInterface or throws CiNotDetectedException // Example output when run inside GitHub Actions build: echo $ci->getCiName(); // "GitHub Actions" echo $ci->getBuildNumber(); // "33" echo $ci->getBranch(); // "feature/foo-bar" or empty string if not detected // Conditional code for pull request: if ($ci->isPullRequest()->yes()) { echo 'This is pull request. The target branch is: '; echo $ci->getTargetBranch(); // "main" } // Conditional code for specific CI server: if ($ci->getCiName() === OndraM\CiDetector\CiDetector::CI_GITHUB_ACTIONS) { echo 'This is being built on GitHub Actions'; } // Describe all detected values in human-readable form: print_r($ci->describe()); // Array // ( // [ci-name] => GitHub Actions // [build-number] => 33 // [build-url] => https://github.com/OndraM/ci-detector/commit/abcd/checks // [commit] => fad3f7bdbf3515d1e9285b8aa80feeff74507bde // [branch] => feature/foo-bar // [target-branch] => main // [repository-name] => OndraM/ci-detector // [repository-url] => https://github.com/OndraM/ci-detector // [is-pull-request] => Yes // ) } else { echo 'This script is not run on CI server'; } ``` -------------------------------- ### Configure Rector with Rules and Sets Source: https://github.com/rectorphp/rector/blob/main/README.md Configure Rector by creating a `rector.php` file in the project root. This example registers a single rule and enables prepared sets for dead code and code quality. ```php use Rector\Config\RectorConfig; use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector; return RectorConfig::configure() ->withRules([ TypedPropertyFromStrictConstructorRector::class ]) ->withPreparedSets( deadCode: true, codeQuality: true ); ``` -------------------------------- ### Configure TCP Socket Context Options Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md Customize the underlying TCP socket stream with context options. This example sets the backlog size and enables SO_REUSEPORT for the IPv6 listener. ```php $socket = new React\Socket\SocketServer('[::1]:8080', array( 'tcp' => array( 'backlog' => 200, 'so_reuseport' => true, 'ipv6_v6only' => true ) )); ``` -------------------------------- ### Listen on IPv6 Address Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md To listen on an IPv6 address, enclose the host address in square brackets. This example listens on the IPv6 localhost address. ```php $socket = new React\Socket\SocketServer('[::1]:8080'); ``` -------------------------------- ### Parse and Read PHPDoc String Source: https://github.com/rectorphp/rector/blob/main/vendor/phpstan/phpdoc-parser/README.md Demonstrates basic setup for parsing a PHPDoc string into an AST and accessing its components. Ensure autoloader is included. ```php tokenize('/** @param Lorem $a */')); $phpDocNode = $phpDocParser->parse($tokens); // PhpDocNode $paramTags = $phpDocNode->getParamTagValues(); // ParamTagValueNode[] echo $paramTags[0]->parameterName; // '$a' echo $paramTags[0]->type; // IdentifierTypeNode - 'Lorem' ``` -------------------------------- ### Install sebastian/diff with Composer Source: https://github.com/rectorphp/rector/blob/main/vendor/sebastian/diff/README.md Add the sebastian/diff library to your project dependencies using Composer. Use the --dev flag for development-time dependencies. ```bash composer require sebastian/diff ``` ```bash composer require --dev sebastian/diff ``` -------------------------------- ### Fallback Get with Promises Source: https://github.com/rectorphp/rector/blob/main/vendor/react/cache/README.md Demonstrates a common pattern of attempting to retrieve a value from the cache and, if not found, fetching it from a data source using Promises. ```php $cache ->get('foo') ->then(function ($result) { if ($result === null) { return getFooFromDb(); } return $result; }) ->then('var_dump'); ``` -------------------------------- ### Get Active Connections Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md Retrieve an array of all currently active connections managed by the server. This allows you to iterate through and interact with each active connection, for example, by sending a message to all of them. ```php foreach ($server->getConnection() as $connection) { $connection->write('Hi!'); } ``` -------------------------------- ### Get CPU Core Count with Fallback Finder Source: https://github.com/rectorphp/rector/blob/main/vendor/fidry/cpu-core-counter/README.md Instantiate CpuCoreCounter with a custom set of finders, including a fallback dummy finder. This ensures a value is always returned, even if other finders fail. ```php $counter = new CpuCoreCounter([ ...CpuCoreCounter::getDefaultFinders(), new DummyCpuCoreFinder(1), // Fallback value ]); ``` -------------------------------- ### Handle Runtime Exception for Port Conflicts Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md A RuntimeException is thrown if the server fails to start listening, for example, if the specified port is already in use or requires elevated privileges (e.g., ports below 1024). ```php $first = new React\Socket\SocketServer('127.0.0.1:8080'); // throws RuntimeException because port is already in use $second = new React\Socket\SocketServer('127.0.0.1:8080'); ``` -------------------------------- ### Unhandled Promise Rejection Example Source: https://github.com/rectorphp/rector/blob/main/vendor/react/promise/README.md Demonstrates how a promise rejection becomes 'unhandled' when local references are lost without a registered rejection handler, leading to an error message. ```php function incorrect(): int { $promise = React\Promise\reject(new RuntimeException('Request failed')); // Commented out: No rejection handler registered here. // $promise->then(null, function (\Throwable $e): void { /* ignore */ }); // Returning from a function will remove all local variable references, hence why // this will report an unhandled promise rejection here. return 42; } // Calling this function will log an error message plus its stack trace: // Unhandled promise rejection with RuntimeException: Request failed in example.php:10 incorrect(); ``` -------------------------------- ### Configure TcpConnector with Socket Context Options Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md TcpConnector can be instantiated with an optional event loop and an array of socket context options. This example shows how to specify a bind address. ```php $tcpConnector = new React\Socket\TcpConnector(null, array( 'bindto' => '192.168.0.1:0' )); ``` -------------------------------- ### Create Basic DNS Resolver Source: https://github.com/rectorphp/rector/blob/main/vendor/react/dns/README.md Loads system configuration and creates a DNS resolver instance. Apply a default nameserver if none is found in the system configuration. This operation should ideally be executed once before the event loop starts. ```php $config = React\Dns\Config\Config::loadSystemConfigBlocking(); if (!$config->nameservers) { $config->nameservers[] = '8.8.8.8'; } $factory = new React\Dns\Resolver\Factory(); $dns = $factory->create($config); $dns->resolve('igor.io')->then(function ($ip) { echo "Host: $ip\n"; }); ``` -------------------------------- ### Forwarding Socket with Plain PHP Source: https://github.com/rectorphp/rector/blob/main/vendor/react/child-process/README.md This example demonstrates how to forward a socket connection using plain PHP, suitable for scenarios where external helpers are not desired. It's designed to be run with the `php -r` command. ```php $code = '$s=stream_socket_client($argv[1]);do{fwrite($s,$d=fread(STDIN, 8192));}while(isset($d[0]));'; $command = 'ping example.com | php -r ' . escapeshellarg($code) . ' ' . escapeshellarg($server->getAddress()); $process = new Process($command, null, null, array()); $process->start(); ``` -------------------------------- ### Create a Streaming Connection with Connector Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md Instantiate the Connector and use it to establish a streaming connection. Handle connection success or failure using promises. ```php $connector = new React\Socket\Connector(); $connector->connect($uri)->then(function (React\Socket\ConnectionInterface $connection) { $connection->write('...'); $connection->end(); }, function (Exception $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; }); ``` -------------------------------- ### TcpServer Initialization Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md Demonstrates various ways to initialize the TcpServer, including specifying ports, hosts, and handling IPv6 addresses. ```APIDOC ## TcpServer Initialization ### Description Instantiate a `TcpServer` to accept plaintext TCP/IP connections. ### Method `new React\Socket\TcpServer(string|int $port, ?LoopInterface $loop = null, array $context = [])` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **$port** (string|int) - Required - The port number or URI to listen on. Can be a port number (e.g., 8080), a host and port (e.g., '127.0.0.1:8080'), or an IPv6 address and port (e.g., '[::1]:8080'). Using port 0 assigns a random available port. - **$loop** (?LoopInterface) - Optional - The event loop instance to use. Defaults to the default loop if null. - **$context** (array) - Optional - An array of socket context options to configure the underlying stream socket resource. ### Request Example ```php // Listen on port 8080 on localhost $server = new React\Socket\TcpServer(8080); // Listen on port 8080 on a specific IP address $server = new React\Socket\TcpServer('192.168.0.1:8080'); // Listen on port 8080 on IPv6 localhost $server = new React\Socket\TcpServer('[::1]:8080'); // Use a random port $server = new React\Socket\TcpServer(0); $address = $server->getAddress(); // With custom socket context options $server = new React\Socket\TcpServer('[::1]:8080', null, [ 'backlog' => 200, 'so_reuseport' => true, 'ipv6_v6only' => true ]); ``` ### Response #### Success Response (200) N/A (Constructor does not return a value directly) #### Response Example N/A ``` -------------------------------- ### PHP: Mixed Resolution and Rejection Forwarding Source: https://github.com/rectorphp/rector/blob/main/vendor/react/promise/README.md Demonstrates how to mix promise resolutions and rejections, showing how to handle rejections and forward results predictably. This example illustrates handling a rejection and returning a new value without rethrowing. ```php $deferred = new React\Promise\Deferred(); $deferred->promise() ->then(function ($x) { return $x + 1; }) ->then(function ($x) { throw new \Exception($x + 1); }) ->catch(function (\Exception $x) { // Handle the rejection, and don't propagate. // This is like catch without a rethrow return $x->getMessage() + 1; }) ->then(function ($x) { echo 'Mixed ' . $x; // 4 }); $deferred->resolve(1); // Prints "Mixed 4" ``` -------------------------------- ### Customizing Finders: Specifying Finder Order Source: https://github.com/rectorphp/rector/blob/main/vendor/fidry/cpu-core-counter/README.md Create a CpuCoreCounter instance with a custom array of finders, explicitly defining the order and selection of finders to be used. This example prioritizes CpuInfoFinder and omits the Nproc finder. ```php // Use CPUInfo first & don't use Nproc $finders = [ new CpuInfoFinder(), new WindowsWmicFinder(), new HwLogicalFinder(), ]; $cores = (new CpuCoreCounter($finders))->getCount(); ``` -------------------------------- ### Streaming Output via Redirection to Socket Source: https://github.com/rectorphp/rector/blob/main/vendor/react/child-process/README.md This example demonstrates streaming command output by redirecting standard I/O streams to a socket. It involves spawning an additional process to forward streams, which avoids modifying the child process itself. ```php $server = new React\Socket\Server('127.0.0.1:0'); $server->on('connection', function (React\Socket\ConnectionInterface $connection) { $connection->on('data', function ($chunk) { echo $chunk; }); }); $command = 'ping example.com | foobar ' . escapeshellarg($server->getAddress()); $process = new Process($command, null, null, array()); $process->start(); $process->on('exit', function ($exitcode) use ($server) { $server->close(); echo 'exit with ' . $exitcode . PHP_EOL; }); ``` -------------------------------- ### Basic Resolver Creation Source: https://github.com/rectorphp/rector/blob/main/vendor/react/dns/README.md Demonstrates how to create a basic DNS resolver using the factory and resolve a domain name. ```APIDOC ## Basic Resolver Creation ### Description Creates a DNS resolver using the factory and resolves a domain name to an IP address. ### Method Factory method `create()` ### Parameters #### Request Body - **config** (React\Dns\Config\Config) - Configuration object for the resolver. ### Request Example ```php $config = React\Dns\Config\Config::loadSystemConfigBlocking(); if (!$config->nameservers) { $config->nameservers[] = '8.8.8.8'; } $factory = new React\Dns\Resolver\Factory(); $dns = $factory->create($config); $dns->resolve('igor.io')->then(function ($ip) { echo "Host: $ip\n"; }); ``` ### Response #### Success Response (Promise) - **ip** (string) - The resolved IPv4 address for the domain. ``` -------------------------------- ### Install Doctrine Inflector with Composer Source: https://github.com/rectorphp/rector/blob/main/vendor/doctrine/inflector/docs/en/index.rst Use Composer to install the Doctrine Inflector library. This is the recommended method for adding the dependency to your project. ```bash $ composer require doctrine/inflector ``` -------------------------------- ### Async HTTP Server with EventLoop Source: https://github.com/rectorphp/rector/blob/main/vendor/react/event-loop/README.md An example demonstrating an async HTTP server using the event loop to handle incoming connections and stream responses. It includes adding read and write streams, and a periodic timer for memory usage reporting. ```php get('foo') ->then(function ($result) { if ($result === null) { return $this->getAndCacheFooFromDb(); } return $result; }) ->then('var_dump'); public function getAndCacheFooFromDb() { return $this->db ->get('foo') ->then(array($this, 'cacheFooFromDb')); } public function cacheFooFromDb($foo) { $this->cache->set('foo', $foo); return $foo; } ``` -------------------------------- ### Install Dependencies in Docker Container Source: https://github.com/rectorphp/rector/blob/main/CONTRIBUTING.md Install project dependencies within a Docker container using Composer. The --rm flag removes the container after execution. ```bash docker compose run --rm php composer install ``` -------------------------------- ### Get CPU Core Count with Type-Safe Fallback Source: https://github.com/rectorphp/rector/blob/main/vendor/fidry/cpu-core-counter/README.md Use the type-safe getCountWithFallback method to get the CPU core count, providing a default value if none can be found. ```php $counter->getCountWithFallback(1); ``` -------------------------------- ### Get CPU Core Count with Exception Handling Source: https://github.com/rectorphp/rector/blob/main/vendor/fidry/cpu-core-counter/README.md Get the total number of CPU cores, defaulting to logical cores. Includes exception handling for cases where the core count cannot be determined, providing a fallback value. ```php try { $counter->getCount(); // e.g. 8 } catch (NumberOfCpuCoreNotFound) { return 1; // Fallback value } ``` -------------------------------- ### Instantiate SecureServer with Certificate Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md Instantiate a SecureServer by wrapping a TcpServer and providing TLS context options, including the local certificate file. The certificate is loaded when an incoming connection initializes its TLS context. ```php $server = new React\Socket\TcpServer(8000); $server = new React\Socket\SecureServer($server, null, array( 'local_cert' => 'server.pem' )); ``` -------------------------------- ### grapheme_strlen Source: https://github.com/rectorphp/rector/blob/main/vendor/symfony/polyfill-intl-grapheme/README.md Get string length in grapheme units. ```APIDOC ## grapheme_strlen ### Description Get the length of a string in grapheme units. ### Method Not applicable (PHP function) ### Parameters - **haystack** (string) - The string to get the length of. - **encoding** (string) - Optional. The encoding of the string (defaults to UTF-8). ### Response #### Success Response - Returns the length of the string in grapheme units as an integer. ``` -------------------------------- ### Run Test Suite Source: https://github.com/rectorphp/rector/blob/main/vendor/react/cache/README.md Executes the project's test suite using PHPUnit from the vendor directory. ```bash vendor/bin/phpunit ``` -------------------------------- ### Loop::get Source: https://github.com/rectorphp/rector/blob/main/vendor/react/event-loop/README.md Gets the current default event loop instance. ```APIDOC ## get ### Description Gets the current default event loop instance. ### Method `Loop::get(): LoopInterface` ### Request Example ```php $loop = Loop::get(); ``` ### Response Returns the `LoopInterface` instance. ``` -------------------------------- ### Loop::run Source: https://github.com/rectorphp/rector/blob/main/vendor/react/event-loop/README.md Starts the event loop, processing events until `stop()` is called. ```APIDOC ## run ### Description Starts the event loop, processing events until `stop()` is called. ### Method `Loop::run()` ### Request Example ```php Loop::run(); ``` ### Response This method blocks execution until the event loop is stopped. ``` -------------------------------- ### Using the Global EventLoop Accessor Source: https://github.com/rectorphp/rector/blob/main/vendor/react/event-loop/README.md Demonstrates the concise way to use the default event loop via the `Loop` class, including adding and canceling timers. ```php use React\EventLoop\Loop; $timer = Loop::addPeriodicTimer(0.1, function () { echo 'Tick' . PHP_EOL; }); Loop::addTimer(1.0, function () use ($timer) { Loop::cancelTimer($timer); echo 'Done' . PHP_EOL; }); ``` -------------------------------- ### Unified Diff Output Example Source: https://github.com/rectorphp/rector/blob/main/vendor/sebastian/diff/README.md The output generated by UnifiedDiffOutputBuilder, showing additions and deletions in a standard diff format. ```diff --- Original +++ New @@ @@ -foo +bar ``` -------------------------------- ### Install PSR Log via Composer Source: https://github.com/rectorphp/rector/blob/main/vendor/psr/log/README.md Use this command to add the PSR-3 logger interface package to your project dependencies. ```bash composer require psr/log ``` -------------------------------- ### Using PhpConfig for Sub-process Management Source: https://github.com/rectorphp/rector/blob/main/vendor/composer/xdebug-handler/README.md Demonstrates how to use the PhpConfig helper class to invoke PHP sub-processes with different Xdebug configurations. Use `useOriginal()` to load Xdebug, `useStandard()` to not load Xdebug, and `usePersistent()` for persistent settings. ```php use Composer\XdebugHandler\PhpConfig; $config = new PhpConfig; $options = $config->useOriginal(); # $options: empty array # environment: PHPRC and PHP_INI_SCAN_DIR set to original values $options = $config->useStandard(); # $options: [-n, -c, tmpIni] # environment: PHPRC and PHP_INI_SCAN_DIR set to original values $options = $config->usePersistent(); # $options: empty array # environment: PHPRC=tmpIni, PHP_INI_SCAN_DIR='' ``` -------------------------------- ### Constructor with Assertions for Employee ID Source: https://github.com/rectorphp/rector/blob/main/vendor/webmozart/assert/README.md Example of using Assert::integer and Assert::greaterThan in a constructor to validate an employee ID. ```php use Webmozart\Assert\Assert; class Employee { public function __construct($id) { Assert::integer($id, 'The employee ID must be an integer. Got: %s'); Assert::greaterThan($id, 0, 'The employee ID must be a positive integer. Got: %s'); } } ``` -------------------------------- ### Getting Server Address Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md Retrieves the address the server is listening on, particularly useful when using port 0 for random assignment. ```APIDOC ## Getting Server Address ### Description Obtain the address the `TcpServer` is currently listening on. ### Method `$server->getAddress(): string` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```php $server = new React\Socket\TcpServer(0); // Listen on a random port $address = $server->getAddress(); echo 'Server listening on: ' . $address . PHP_EOL; ``` ### Response #### Success Response (200) - **string** - The address (host:port) the server is listening on. ``` -------------------------------- ### Use Custom DNS Resolver Instance Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md Configure the Connector to use a custom React\Dns\Resolver\ResolverInterface instance. This example creates a cached resolver. ```php $dnsResolverFactory = new React\Dns\Resolver\Factory(); $resolver = $dnsResolverFactory->createCached('127.0.0.1'); $connector = new React\Socket\Connector(array( 'dns' => $resolver )); $connector->connect('localhost:80')->then(function (React\Socket\ConnectionInterface $connection) { $connection->write('...'); $connection->end(); }); ``` -------------------------------- ### Default Process Construction on Windows Source: https://github.com/rectorphp/rector/blob/main/vendor/react/child-process/README.md On Windows, constructing a child process with default pipes will throw a LogicException. This is due to PHP's inability to access standard I/O pipes without blocking on Windows. ```php // throws LogicException on Windows $process = new Process('ping example.com'); $process->start(); ``` -------------------------------- ### Query IPv6 Address with TcpTransportExecutor Source: https://github.com/rectorphp/rector/blob/main/vendor/react/dns/README.md Use TcpTransportExecutor to send DNS queries over TCP/IP. This example looks up the IPv6 address for reactphp.org. ```php $executor = new TcpTransportExecutor('8.8.8.8:53'); $executor->query( new Query($name, Message::TYPE_AAAA, Message::CLASS_IN) )->then(function (Message $message) { foreach ($message->answers as $answer) { echo 'IPv6: ' . $answer->data . PHP_EOL; } }, 'printf'); ``` -------------------------------- ### Explicit EventLoop Instance Usage Source: https://github.com/rectorphp/rector/blob/main/vendor/react/event-loop/README.md Shows how to explicitly create and manage an event loop instance, including adding timers and running the loop. ```php $loop = React\EventLoop\Loop::get(); // or deprecated React\EventLoop\Factory::create(); $timer = $loop->addPeriodicTimer(0.1, function () { echo 'Tick' . PHP_EOL; }); $loop->addTimer(1.0, function () use ($loop, $timer) { $loop->cancelTimer($timer); echo 'Done' . PHP_EOL; }); $loop->run(); ``` -------------------------------- ### Listen for Unix Server Connections Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md Set up an event listener for the 'connection' event on a Unix server. This callback is executed for each new client connection, allowing you to interact with the client, such as sending data. ```php $server->on('connection', function (React\Socket\ConnectionInterface $connection) { echo 'New connection' . PHP_EOL; $connection->write('hello there!' . PHP_EOL); … }); ``` -------------------------------- ### Get Server Listening Address Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md Retrieves the full address (URI) the server is currently listening on. Returns null if the address cannot be determined. ```php $address = $socket->getAddress(); echo 'Server listening on ' . $address . PHP_EOL; ``` -------------------------------- ### Get Local Connection Address Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md Retrieves the full local address (URI) where the connection was established. Returns null if the address cannot be determined. ```php $address = $connection->getLocalAddress(); echo 'Connection with ' . $address . PHP_EOL; ``` -------------------------------- ### Instantiate Unix Server Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md Create a new Unix domain socket server instance. The URI can be a socket path or prefixed with 'unix://'. Listening may fail if the socket is in use or inaccessible, throwing a RuntimeException. ```php $server = new React\Socket\UnixServer('/tmp/server.sock'); ``` -------------------------------- ### Get Remote Connection Address Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md Retrieves the full remote address (URI) of an established connection. Returns null if the address cannot be determined. ```php $address = $connection->getRemoteAddress(); echo 'Connection with ' . $address . PHP_EOL; ``` -------------------------------- ### CiInterface Methods Source: https://github.com/rectorphp/rector/blob/main/vendor/ondram/ci-detector/README.md The CiInterface provides methods to get details about the CI environment. These methods are available on the object returned by $ciDetector->detect(). ```APIDOC ## getCiName() ### Description Retrieves the name of the CI server. ### Method `getCiName()` ### Return Value string - The name of the CI server, one of `CiDetector::CI_*` constants. ### Example Value `GitHub Actions` ``` ```APIDOC ## getBuildNumber() ### Description Gets the number of the current concrete build. ### Method `getBuildNumber()` ### Return Value string - The build number, typically a human-readable increasing sequence. Can be an alphanumeric hash if a simple number is not available. ### Example Value `33` ``` ```APIDOC ## getBuildUrl() ### Description Gets the URL where the current build can be found and viewed. ### Method `getBuildUrl()` ### Return Value string - The URL of the build, or an empty string if it cannot be determined. ### Example Value `https://github.com/OndraM/ci-detector/commit/abcd/checks` ``` ```APIDOC ## getCommit() ### Description Gets the hash of the commit being built. ### Method `getCommit()` ### Return Value string - The commit hash. ### Example Value `b9173d94(...)` ``` ```APIDOC ## getBranch() ### Description Gets the name of the git (or other VCS) branch which is being built. ### Method `getBranch()` ### Return Value string - The branch name, or an empty string if it cannot be determined. Use `getTargetBranch()` for the target branch of a pull request. ### Example Value `my-feature` ``` ```APIDOC ## getTargetBranch() ### Description Gets the name of the target branch of a pull request. ### Method `getTargetBranch()` ### Return Value string - The target branch name, or an empty string if it cannot be determined. ### Example Value `main` ``` ```APIDOC ## getRepositoryName() ### Description Gets the name of the git (or other VCS) repository which is being built. ### Method `getRepositoryName()` ### Return Value string - The repository name, usually in the format "user/repository", or an empty string if it cannot be determined. ### Example Value `OndraM/ci-detector` ``` ```APIDOC ## getRepositoryUrl() ### Description Gets the URL where the repository which is being built can be found. ### Method `getRepositoryUrl()` ### Return Value string - The repository URL (e.g., HTTP or SSH), or an empty string if it cannot be determined. ### Example Value `https://github.com/OndraM/ci-detector` ``` -------------------------------- ### Piping File Contents Asynchronously Source: https://github.com/rectorphp/rector/blob/main/vendor/react/stream/README.md Example of piping data from a source file to a destination file without loading the entire file into memory. ```php $source = new React\Stream\ReadableResourceStream(fopen('source.txt', 'r')); $dest = new React\Stream\WritableResourceStream(fopen('destination.txt', 'w')); $source->pipe($dest); ``` -------------------------------- ### Configuring File Handles for Child Process Output Source: https://github.com/rectorphp/rector/blob/main/vendor/react/child-process/README.md To capture command output after execution, file handles can be configured for the child process instead of pipes. This example uses tmpfile() for demonstration, but filesystem operations are inherently blocking and not recommended for async programs. ```php $process = new Process('ping example.com', null, null, array( array('file', 'nul', 'r'), $stdout = tmpfile(), array('file', 'nul', 'w') )); $process->start(); $process->on('exit', function ($exitcode) use ($stdout) { echo 'exit with ' . $exitcode . PHP_EOL; // rewind to start and then read full file (demo only, this is blocking). // reading from shared file is only safe if you have some synchronization in place // or after the child process has terminated. rewind($stdout); echo stream_get_contents($stdout); fclose($stdout); }); ``` -------------------------------- ### Instantiate Limiting Server with Pause Option Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md Create a LimitingServer that pauses accepting new connections when the limit is reached, instead of immediately rejecting them. This can be useful for protocols that expect a response before proceeding. ```php $server = new React\Socket\LimitingServer($server, 100, true); $server->on('connection', function (React\Socket\ConnectionInterface $connection) { $connection->write('hello there!' . PHP_EOL); … }); ``` -------------------------------- ### Query Localhost with HostsFileExecutor Source: https://github.com/rectorphp/rector/blob/main/vendor/react/dns/README.md Use HostsFileExecutor to include entries from the hosts file when performing DNS lookups. This example queries the 'localhost' A record. ```php $hosts = ``` ```text ``` -------------------------------- ### Create and Use DnsConnector Source: https://github.com/rectorphp/rector/blob/main/vendor/react/socket/README.md Instantiate a DnsConnector by providing a TCP connector and a DNS resolver. Use it to connect to a hostname, which will be resolved via DNS before establishing the TCP connection. The connection promise can be cancelled. ```php $dnsResolverFactory = new React\Dns\Resolver\Factory(); $dns = $dnsResolverFactory->createCached('8.8.8.8'); $dnsConnector = new React\Socket\DnsConnector($tcpConnector, $dns); $dnsConnector->connect('www.google.com:80')->then(function (React\Socket\ConnectionInterface $connection) { $connection->write('...'); $connection->end(); }); ``` ```php $promise = $dnsConnector->connect('www.google.com:80'); $promise->cancel(); ```