### Constant Replacement Example Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ChangeEnumerator.md Demonstrates how to prefix constants when enabled. This is useful for namespacing configuration constants. ```php // Original symbol Symbol: MY_CONSTANT // With constant_prefix = "PREFIX_" // Result Replacement: PREFIX_MY_CONSTANT ``` -------------------------------- ### File Path Mapping Example Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/FileEnumerator.md Illustrates how files are mapped from their source location to the target directory, preserving the vendor-relative path. ```text Source: /path/to/vendor/symfony/console/src/Application.php ↓ Vendor Path: symfony/console/src/Application.php ↓ Target: /path/to/vendor-prefixed/symfony/console/src/Application.php ``` -------------------------------- ### Function Replacement Example Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ChangeEnumerator.md Shows how to prefix global functions when enabled. This helps in namespacing utility functions to avoid conflicts. ```php // Original symbol Symbol: my_helper_function // With function_prefix = "my_plugin_" // Result Replacement: my_plugin_my_helper_function ``` -------------------------------- ### Custom Pattern Replacement Example Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ChangeEnumerator.md Provides a concrete example of a custom namespace replacement using `preg_replace()` logic. This shows the transformation from an original to a replaced symbol. ```php // Original BrianHenryIE\Stripe\Client // Pattern: ~BrianHenryIE\(.*)~ // Replacement: BrianHenryIE\WC_Cash_App_Gateway\$1 // Result BrianHenryIE\WC_Cash_App_Gateway\Stripe\Client ``` -------------------------------- ### Configure composer.json scripts for Composer dependency installation Source: https://github.com/brianhenryie/strauss/blob/master/README.md Sets up Composer scripts to use the locally installed Strauss for namespace prefixing and autoloading. ```json "scripts": { "prefix-namespaces": [ "strauss", "@php composer dump-autoload" ], "post-install-cmd": [ "@prefix-namespaces" ], "post-update-cmd": [ "@prefix-namespaces" ], "post-autoload-dump": [ "strauss include-autoloader" ] } ``` -------------------------------- ### Getting Configuration Values Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/StraussConfig.md Methods for retrieving current configuration settings. ```APIDOC ## getTargetDirectory ### Description Returns the target directory path where prefixed packages are copied. ### Method GET (conceptual) ### Endpoint N/A (SDK method) ### Returns - **string**: The target directory path. ``` ```APIDOC ## getAbsoluteTargetDirectory ### Description Returns the absolute target directory path. ### Method GET (conceptual) ### Endpoint N/A (SDK method) ### Returns - **string**: The absolute target directory path. ``` ```APIDOC ## getNamespacePrefix ### Description Returns the namespace prefix string (e.g., `BrianHenryIE\MyProject\`). ### Method GET (conceptual) ### Endpoint N/A (SDK method) ### Returns - **?string**: The namespace prefix or null if not set. ``` ```APIDOC ## getClassmapPrefix ### Description Returns the global classname prefix (e.g., `BrianHenryIE_MyProject_`). ### Method GET (conceptual) ### Endpoint N/A (SDK method) ### Returns - **?string**: The classmap prefix or null if not set. ``` ```APIDOC ## getPackages ### Description Returns an associative array of packages to process, keyed by package name. ### Method GET (conceptual) ### Endpoint N/A (SDK method) ### Returns - **ComposerPackage[]**: An array of Composer packages. ``` ```APIDOC ## getUpdateCallSites ### Description Returns the list of paths where references should be updated, or null to auto-detect from autoload configuration. ### Method GET (conceptual) ### Endpoint N/A (SDK method) ### Returns - **?array**: An array of paths or null. ``` -------------------------------- ### Target Path Mapping Example Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/Copier.md Illustrates how a source file path is transformed into its target path, preserving vendor directory structure. ```text Source: /path/to/vendor/symfony/console/src/Application.php Vendor Relative: symfony/console/src/Application.php Target: /path/to/vendor-prefixed/symfony/console/src/Application.php ``` -------------------------------- ### Namespace Replacement Example Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ChangeEnumerator.md Demonstrates how to replace a namespace for a given symbol. This is useful for refactoring or organizing code. ```php // Original symbol Symbol: Symfony\Console\Application // With namespace_prefix = "BrianHenryIE\MyProject\" // Result Replacement: BrianHenryIE\MyProject\Symfony\Console\Application ``` -------------------------------- ### Namespace Prefixing Example Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/README.md Demonstrates how Strauss prepends a custom prefix to existing namespaces. This is useful for isolating project code. ```text Original: Symfony\Console\Application Prefix: MyCompany\MyPlugin\ Result: MyCompany\MyPlugin\Symfony\Console\Application ``` -------------------------------- ### Install Strauss with Composer Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/README.md Use this command to install Strauss as a development dependency in your project. ```bash composer require --dev brianhenryie/strauss ``` -------------------------------- ### Multi-Level Namespace Prefixing Example Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ChangeEnumerator.md Demonstrates how entire namespace trees are prefixed. The original namespace is prepended with the specified prefix, resulting in a new, fully qualified namespace. ```text Namespace: Symfony\Console Prefix: BrianHenryIE\MyProject\ Result: BrianHenryIE\MyProject\Symfony\Console ``` -------------------------------- ### Get All Discovered Files Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ComposerPackage.md Retrieves a list of all files discovered within the package, including their dependency information. ```php public function getFiles(): FileWithDependency[] ``` -------------------------------- ### Licenser Usage Example Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/Licenser.md Demonstrates how to instantiate and use the Licenser class to copy license files and update modified files with attribution information. Requires configuration, package details, author info, a filesystem object, and a logger. ```php use BrianHenryIE\Strauss\Pipeline\Licenser; use BrianHenryIE\Strauss\Pipeline\Prefixer; // Get author info $author = trim(shell_exec('git config user.name') ?: '') . ' <' . trim(shell_exec('git config user.email') ?: '') . '>'; // Create licenser $licenser = new Licenser( $config, $packages, $author, $filesystem, $logger ); // Copy all license files $licenser->copyLicenses(); echo "License files copied"; // Update modified files with headers $prefixer = new Prefixer($config, $filesystem, $logger); $prefixer->replaceInFiles($symbols, $files); $modified = $prefixer->getModifiedFiles(); $licenser->addInformationToUpdatedFiles($modified); echo "File headers updated with modification info"; ``` -------------------------------- ### Get Package License Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ComposerPackage.md Returns the license identifier for the package, such as 'MIT' or 'GPL-3.0+'. ```php public function getLicense(): string ``` -------------------------------- ### Directory Structure Preservation Example Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/Copier.md Shows how the copier maintains the original package directory structure when copying files. ```text vendor/ ├── symfony/ │ └── console/ │ ├── src/ │ ├── Resources/ │ └── composer.json Becomes: vendor-prefixed/ ├── symfony/ │ └── console/ │ ├── src/ │ ├── Resources/ │ └── composer.json ``` -------------------------------- ### Strauss File Usage Example Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/File.md Demonstrates the typical lifecycle of a File object during Strauss processing, including creation, configuration, symbol registration, and tracking modifications. ```php use BrianHenryIE\Strauss\Files\File; use BrianHenryIE\Strauss\Types\ClassSymbol; // Create a file object $file = new File( '/absolute/path/vendor/symfony/console/src/Application.php', 'symfony/console/src/Application.php' ); // Configure what to do with it $file->setDoCopy(true); $file->setDoPrefix(true); $file->setIsAutoloaded(false); $file->setAbsoluteTargetPath('/absolute/path/vendor-prefixed/symfony/console/src/Application.php'); // Later, register discovered symbols $appClass = new ClassSymbol('Application', $file); $file->addDiscoveredSymbol($appClass); // Check what was found if ($file->isPhpFile()) { $symbols = $file->getDiscoveredSymbols(); echo count($symbols); // 1 } // Track processing $file->setDidUpdate(); $file->setDidDelete(true); ``` -------------------------------- ### Classmap Prefixing Example Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/README.md Shows how Strauss prefixes classes in the global namespace using underscores. This ensures uniqueness when merging code. ```text Original: MyGlobalClass Prefix: MyCompany_MyPlugin_ Result: MyCompany_MyPlugin_MyGlobalClass ``` -------------------------------- ### Configure composer.json scripts for .phar installation Source: https://github.com/brianhenryie/strauss/blob/master/README.md Sets up Composer scripts to download and run the Strauss .phar for namespace prefixing and autoloading. ```json "scripts": { "prefix-namespaces": [ "sh -c 'test -f ./bin/strauss.phar || curl -o bin/strauss.phar -L -C - https://github.com/BrianHenryIE/strauss/releases/latest/download/strauss.phar'", "@php bin/strauss.phar", "@composer dump-autoload" ], "post-install-cmd": [ "@prefix-namespaces" ], "post-update-cmd": [ "@prefix-namespaces" ], "post-autoload-dump": [ "@php bin/strauss.phar include-autoloader" ] } ``` -------------------------------- ### Getting Files in Package Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ComposerPackage.md Demonstrates iterating through the files associated with a Composer package and accessing their source paths. ```APIDOC ## Get Files in Package ### Description Retrieves a list of files within the Composer package. ### Method `getFiles(): array ### Response #### Success Response (200) - **array** - A list of file objects, each representing a file in the package. ## Get Source Path of a File ### Description Retrieves the source path of a file within the package. ### Method `getSourcePath(): string ### Response #### Success Response (200) - **string** - The absolute path to the source file. ``` -------------------------------- ### Classmap (Global Class) Replacement Example Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ChangeEnumerator.md Illustrates how to prefix global classes not within a namespace. This is typically used for legacy code or specific project structures. ```php // Original symbol Symbol: MyGlobalClass // With classmap_prefix = "BrianHenryIE_MyProject_" // Result Replacement: BrianHenryIE_MyProject_MyGlobalClass ``` -------------------------------- ### Enumerate Project Dependencies with Strauss Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/DependenciesEnumerator.md This example demonstrates how to use the DependenciesEnumerator to load composer configuration and retrieve a list of project dependencies. It iterates through the found packages, displaying their names, licenses, absolute paths, and whether they are marked for deletion. ```php use BrianHenryIE\Strauss\Pipeline\DependenciesEnumerator; use Composer\Factory; use Composer\IO\NullIO; // Load composer.json and lock file $composer = Factory::create(new NullIO(), getcwd()); // Create enumerator $enumerator = new DependenciesEnumerator($config, $logger); // Get all packages to process $packages = $enumerator->getProjectDependencies($composer); echo "Found " . count($packages) . " packages to process"; foreach ($packages as $name => $package) { echo "- $name"; echo " License: " . $package->getLicense(); echo " Path: " . $package->getPackageAbsolutePath(); // Check if should be deleted if ($package->isDelete()) { echo " (will be deleted after processing)"; } } ``` -------------------------------- ### Example Strauss Configuration: Explicit Package List Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/DependenciesEnumerator.md When the 'packages' array is provided in the 'strauss' extra configuration, only the specified packages are included in the processing. ```json { "extra": { "strauss": { "packages": [ "symfony/console", "symfony/process", "monolog/monolog" ] } } } ``` -------------------------------- ### Get Packages to Process Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/StraussConfig.md Retrieves an associative array of Composer packages that Strauss will process. The array is keyed by package name. ```php public function getPackages(): ComposerPackage[] ``` -------------------------------- ### Example Strauss Configuration: Excluded Packages Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/DependenciesEnumerator.md Packages listed in 'exclude_from_copy.packages' within the 'strauss' extra configuration are excluded from being copied or prefixed. ```json { "extra": { "strauss": { "exclude_from_copy": { "packages": ["psr/log", "psr/simple-cache"] } } } } ``` -------------------------------- ### Run Strauss Prefix Namespaces Source: https://github.com/brianhenryie/strauss/blob/master/README.md Execute Strauss directly from the command line to prefix namespaces. This command is available after installing Strauss via Composer. ```bash composer prefix-namespaces ``` -------------------------------- ### Get Absolute Package Path Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ComposerPackage.md Returns the absolute filesystem path for the package. Returns null if the package is virtual or does not exist on disk. ```php public function getPackageAbsolutePath(): ?string ``` -------------------------------- ### Get Complete Autoload Configuration Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ComposerPackage.md Retrieves the entire autoload configuration for the package, including files, PSR-4, PSR-0, and classmap entries. ```php public function getAutoload(): AutoloadKeyArray ``` ```php [ 'files' => ['path/to/file.php'], 'psr-4' => ['Namespace\' => 'src/'], 'psr-0' => ['Namespace' => 'lib/'], 'classmap' => ['map/'], ] ``` -------------------------------- ### Generated File Header Example Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/Licenser.md This snippet shows the format of a generated file header by Strauss, including namespace renaming information and modification details. ```php */ // Original file code follows... ``` -------------------------------- ### Set and Get Absolute Target Path Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/File.md Manages the absolute target path where the file will be copied. If not explicitly set, it defaults to the source path. ```php public function setAbsoluteTargetPath(string $absoluteTargetPath): void public function getAbsoluteTargetPath(): string ``` -------------------------------- ### Get Git Author Information Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/Licenser.md Shows how to retrieve the Git user name and email to construct author information. This is used by the licenser as a fallback if system user information is not sufficient. ```bash git config user.name # "John Doe" git config user.email # "john@example.com" ``` -------------------------------- ### Instantiate and Use Prefixer Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/Prefixer.md Demonstrates how to create a Prefixer instance and use it to rewrite dependency files and update project call sites. Ensure you have discovered symbols and defined dependency files and project paths. ```php use BrianHenryIE\Strauss\Pipeline\Prefixer; use BrianHenryIE\Strauss\Types\DiscoveredSymbols; // Create prefixer $prefixer = new Prefixer($config, $filesystem, $logger); // Rewrite dependency files $symbols = new DiscoveredSymbols(); // ... discover symbols ... $prefixer->replaceInFiles($symbols, $dependencyFiles); // Get list of modified files for licensing $modified = $prefixer->getModifiedFiles(); foreach ($modified as $filePath => $package) { echo "$filePath was modified"; if ($package) { echo " from package " . $package->getPackageName(); } } // Update project call sites $projectPaths = [ '/path/to/project/includes/bootstrap.php', ]; $prefixer->replaceInProjectFiles($symbols, $projectPaths); ``` -------------------------------- ### Constructor Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/Prefixer.md Initializes the Prefixer with configuration, filesystem abstraction, and a logger. ```APIDOC ## Constructor ### Description Initializes the Prefixer with configuration, filesystem abstraction, and a logger. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```php $prefixer = new Prefixer($config, $filesystem, $logger); ``` ### Response None ``` -------------------------------- ### Instantiate and Use Copier Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/Copier.md Demonstrates how to instantiate the Copier class and use its prepareTarget and copy methods. Ensure files are enumerated and marked for copying beforehand. ```php use BrianHenryIE\Strauss\Pipeline\Copier; use BrianHenryIE\Strauss\Files\DiscoveredFiles; // Enumerate files first $files = new DiscoveredFiles(); // ... populate $files ... // Create copier $copier = new Copier($files, $config, $filesystem, $logger); // Prepare target (delete existing files, create directory) $copier->prepareTarget(); // Copy all marked files $copier->copy(); echo "Files copied to: " . $config->getAbsoluteTargetDirectory(); ``` -------------------------------- ### Get Package Name Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ComposerPackage.md Retrieves the full, qualified name of the Composer package. ```php public function getPackageName(): string ``` -------------------------------- ### Get Files Autoload Entries Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ComposerPackage.md Extracts and returns only the files autoload configuration entries. ```php public function getFiles(): array ``` -------------------------------- ### Instantiate Copier Class Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/Copier.md Demonstrates how to create an instance of the Copier class, requiring dependencies like discovered files, configuration, a filesystem abstraction, and a logger. ```php $copier = new Copier($files, $config, $filesystem, $logger); ``` -------------------------------- ### Get Classmap Autoload Entries Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ComposerPackage.md Extracts and returns only the classmap autoload configuration entries. ```php public function getClassmap(): array ``` -------------------------------- ### Prepare Target Directory Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/Copier.md Use this method to set up the target directory before copying files. It ensures the directory exists and removes any pre-existing files that will be overwritten. ```php $copier->prepareTarget(); // Set up the target directory ``` -------------------------------- ### Get PSR-0 Autoload Entries Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ComposerPackage.md Extracts and returns only the PSR-0 autoload configuration entries. ```php public function getPsr0(): array ``` -------------------------------- ### Initialize Strauss Application Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/Application.md Instantiate the Strauss CLI application with its version and run it. This is typically done in the application's entry point script (e.g., bin/strauss). ```php $app = new BrianHenryIE\Strauss\Console\Application('0.28.0'); $app->run(); ``` -------------------------------- ### Get PSR-4 Autoload Entries Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ComposerPackage.md Extracts and returns only the PSR-4 autoload configuration entries. ```php public function getPsr4(): array ``` -------------------------------- ### Get Discovered Symbols Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/File.md Returns an associative array of all discovered symbols indexed by their original name. ```APIDOC ## getDiscoveredSymbols ### Description Returns an associative array of all discovered symbols indexed by their original name. ### Method ```php public function getDiscoveredSymbols(): array ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (array) Returns an associative array of discovered symbols indexed by their original name. Example: ```json { "MyClass": "ClassSymbol", "myFunction": "FunctionSymbol", "MY_CONST": "ConstantSymbol", "MyNamespace": "NamespaceSymbol" } ``` #### Response Example None ``` -------------------------------- ### Instantiate Licenser Class Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/Licenser.md Constructs a new Licenser instance with configuration, packages, author information, a filesystem abstraction, and a logger. ```php public function __construct( LicenserConfigInterface $config, ComposerPackage[] $packages, string $author, FileSystem $filesystem, LoggerInterface $logger ) ``` -------------------------------- ### File Constructor Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/File.md Initializes a new File instance with its source and vendor-relative paths. ```APIDOC ## File Constructor ### Description Initializes a new File instance with its source and vendor-relative paths. ### Signature ```php public function __construct(string $sourceAbsolutePath, string $vendorRelativePath) ``` ### Parameters #### Path Parameters - **sourceAbsolutePath** (string) - Absolute filesystem path to the file - **vendorRelativePath** (string) - Path relative to vendor directory (for display and organization) ``` -------------------------------- ### prepareTarget() Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/Copier.md Prepares the target directory by creating it if it doesn't exist and removing any pre-existing files that are about to be copied. ```APIDOC ## prepareTarget(): void ### Description Prepares the target directory for file copying by ensuring it exists and clearing out any files that will be overwritten. ### Method `prepareTarget` ### Endpoint N/A (Method Call) ### Parameters None ### Request Example ```php $copier->prepareTarget(); ``` ### Response #### Success Response (void) This method does not return a value. #### Throws `FilesystemException` on filesystem errors ``` -------------------------------- ### Get Direct Package Dependencies Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ComposerPackage.md Retrieves a list of direct package dependencies specified in the 'require' field. ```php public function getRequiresNames(): array ``` -------------------------------- ### Create bin directory and .gitkeep file Source: https://github.com/brianhenryie/strauss/blob/master/README.md Ensures the bin/ directory exists in your project root for the .phar file. ```bash mkdir bin touch bin/.gitkeep ``` -------------------------------- ### Get Source Path Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/File.md Retrieves the absolute filesystem path to the file. This is the primary location of the file on the disk. ```php public function getSourcePath(): string ``` -------------------------------- ### Prefixer Constructor Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/Prefixer.md Initializes the Prefixer with configuration, filesystem abstraction, and a logger. ```php public function __construct( PrefixerConfigInterface $config, FileSystem $filesystem, LoggerInterface $logger ) ``` -------------------------------- ### compileFileList Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/FileEnumerator.md Enumerates all files in the provided Composer packages. This method is used to discover files that belong to installed packages. ```APIDOC ## compileFileList(ComposerPackage[] $packages): DiscoveredFiles ### Description Enumerates all files in the provided packages. ### Method `compileFileList` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters #### packages - **packages** (array of ComposerPackage) - Required - Array of ComposerPackage objects to scan ### Response #### Success Response - **DiscoveredFiles** - A collection containing all discovered files. ### Request Example ```php $enumerator = new FileEnumerator($config, $filesystem, $logger); $discoveredFiles = $enumerator->compileFileList($packagesToProcess); echo "Found " . count($discoveredFiles) . " files"; ``` ``` -------------------------------- ### Constructor Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/FileSymbolScanner.md Initializes the FileSymbolScanner with configuration, a discovered symbols collection, and a filesystem abstraction. ```APIDOC ## Constructor ```php public function __construct( FileSymbolScannerConfigInterface $config, DiscoveredSymbols $discoveredSymbols, FileSystem $filesystem ) ``` ### Parameters - **config** (FileSymbolScannerConfigInterface) - Required - Configuration for which symbols to scan and how - **discoveredSymbols** (DiscoveredSymbols) - Required - Symbol collection to add discovered symbols to - **filesystem** (FileSystem) - Required - Filesystem abstraction for reading files ``` -------------------------------- ### Modification Header Without Author Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/Licenser.md Example of a modification header when the author information is excluded. This occurs when `getIncludeAuthor()` is false. ```php run(); ``` ``` -------------------------------- ### Modification Header Without Date Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/Licenser.md Example of a modification header when the modification date is excluded. This occurs when `getIncludeModifiedDate()` is false. ```php */ ``` -------------------------------- ### Instantiate FileEnumerator Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/FileEnumerator.md Demonstrates how to instantiate the FileEnumerator class with its required dependencies. ```php public function __construct( FileEnumeratorConfigInterface $config, FileSystem $filesystem, LoggerInterface $logger ) ``` -------------------------------- ### Get Namespace Prefix Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/StraussConfig.md Retrieves the configured namespace prefix. This prefix is applied to all discovered namespaces during the prefixing process. ```php public function getNamespacePrefix(): ?string ``` -------------------------------- ### Programmatic Usage of Strauss Pipeline Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/README.md Demonstrates how to use individual Strauss pipeline stages programmatically. This requires instantiating configuration, filesystem, and logger objects. ```php $config = new StraussConfig($composer); $filesystem = new FileSystem(); // Use individual pipeline stages $enumerator = new DependenciesEnumerator($config, $logger); $packages = $enumerator->getProjectDependencies($composer); $fileEnum = new FileEnumerator($config, $filesystem, $logger); $files = $fileEnum->compileFileList($packages); $scanner = new FileSymbolScanner($config, $symbols, $filesystem); $scanner->findInFiles($files); ``` -------------------------------- ### Prefix Constants Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/Prefixer.md Demonstrates how constants, both in definition and usage, are prefixed. ```php define('MY_CONST', 'value'); echo MY_CONST; ``` ```php define('PREFIX_MY_CONST', 'value'); echo PREFIX_MY_CONST; ``` -------------------------------- ### Get Classmap Prefix Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/StraussConfig.md Retrieves the global classname prefix. This is used for generating prefixed class names, often for compatibility. ```php public function getClassmapPrefix(): ?string ``` -------------------------------- ### Get Relative Package Path Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ComposerPackage.md Returns the path to the package relative to the project root. Returns null for virtual packages. ```php public function getRelativePath(): ?string ``` -------------------------------- ### Copy and Prefix Dependencies with Defaults Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/DependenciesCommand.md Reads configuration from composer.json extra.strauss and copies all require packages to the configured target directory with automatic namespace prefixing. ```bash strauss dependencies ``` -------------------------------- ### Creating Virtual Packages Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ComposerPackage.md Illustrates how to create virtual packages using Composer package data, which do not have physical composer.json files. ```APIDOC ## Create Virtual Package from Array ### Description Creates a ComposerPackage instance from an array representation, typically used for virtual packages. ### Method `ComposerPackage::fromComposerJsonArray(array $composerJsonData) ### Parameters #### Path Parameters - **composerJsonData** (array) - Required - An associative array containing package details like 'name', 'version', and 'type'. ### Response #### Success Response (200) - **ComposerPackage** - An instance of the ComposerPackage class representing the virtual package. ## Get Package Absolute Path (for Virtual Packages) ### Description Retrieves the absolute path of the package. Returns `null` for virtual packages. ### Method `getPackageAbsolutePath(): ?string ### Response #### Success Response (200) - **?string** - The absolute path to the package, or `null` if it's a virtual package. ## Get Relative Path (for Virtual Packages) ### Description Retrieves the relative path of the package. Returns `null` for virtual packages. ### Method `getRelativePath(): ?string ### Response #### Success Response (200) - **?string** - The relative path to the package, or `null` if it's a virtual package. ``` -------------------------------- ### Instantiate and Use ChangeEnumerator Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ChangeEnumerator.md Demonstrates how to create an instance of ChangeEnumerator, analyze discovered symbols, and retrieve information about namespace and class renames. Ensure you have a configuration object and a logger instance available. ```php use BrianHenryIE\Strauss\Pipeline\ChangeEnumerator; use BrianHenryIE\Strauss\Types\DiscoveredSymbols; use BrianHenryIE\Strauss\Types\ClassSymbol; // Create enumerator $enumerator = new ChangeEnumerator($config, $logger); // Analyze discovered symbols $symbols = new DiscoveredSymbols(); // ... scan and add symbols ... $enumerator->determineReplacements($symbols); // Check which symbols will be prefixed $namespaceChanges = $symbols->getDiscoveredNamespaceChanges(); echo "Will rename " . count($namespaceChanges) . " namespaces"; $classChanges = $symbols->getGlobalClassChanges(); echo "Will rename " . count($classChanges) . " classes"; // Get replacement values foreach ($classChanges as $className => $classSymbol) { echo "$className -> " . $classSymbol->getReplacement(); } ``` -------------------------------- ### Minimal Modification Header Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/Licenser.md Example of a minimal modification header when both date and author information are excluded. This occurs when both `getIncludeModifiedDate()` and `getIncludeAuthor()` are false. ```php run(); // Runs CLI // Or use components directly $config = new StraussConfig($composer); // ... use other classes ``` -------------------------------- ### Get Absolute Target Directory Path Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/StraussConfig.md Retrieves the absolute path to the target directory. This is useful for ensuring correct file system operations. ```php public function getAbsoluteTargetDirectory(): string ``` -------------------------------- ### Enable Verbose Output Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/DependenciesCommand.md Print detailed debug information about each step of the process for enhanced troubleshooting. ```bash strauss dependencies --debug ``` -------------------------------- ### Specify Packages to Process Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/configuration.md Provide an explicit list of package names to process. If empty, all packages in the `require` section are included. ```json { "extra": { "strauss": { "packages": [ "symfony/console", "monolog/monolog" ] } } } ``` -------------------------------- ### Get Vendor Relative Path Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/File.md Retrieves the path of the file relative to the vendor directory. This is useful for maintaining organizational structure and display purposes. ```php public function getVendorRelativePath(): string ``` -------------------------------- ### Prefix Namespace Declaration Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/Prefixer.md Demonstrates how a standard namespace declaration is transformed to include a project-specific prefix. ```php namespace Symfony\Console; ``` ```php namespace BrianHenryIE\MyProject\Symfony\Console; ``` -------------------------------- ### Modification Header with Date and Author Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/Licenser.md Example of a modification header including both the modification date and author information. This is the default behavior when both `getIncludeModifiedDate()` and `getIncludeAuthor()` are true. ```php */ namespace BrianHenryIE\MyProject\Symfony\Console; ``` -------------------------------- ### Set Target Directory Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/configuration.md Configure the output directory for prefixed packages. Defaults to `vendor-prefixed`. ```json { "extra": { "strauss": { "target_directory": "vendor-prefixed" } } } ``` -------------------------------- ### FileSymbolScanner Constructor Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/FileSymbolScanner.md Initializes the FileSymbolScanner with configuration, a symbol collection, and a filesystem abstraction. ```php public function __construct( FileSymbolScannerConfigInterface $config, DiscoveredSymbols $discoveredSymbols, FileSystem $filesystem ) ``` -------------------------------- ### Get Target Directory Path Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/StraussConfig.md Retrieves the target directory path where prefixed packages are copied. Use this to determine the output location for modified packages. ```php public function getTargetDirectory(): string ``` -------------------------------- ### Set and Get Autoload Status Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/File.md Marks whether this file is directly loaded via `autoload.files`. This is important for understanding load order and for symbol scanning. ```php public function setIsAutoloaded(bool $isAutoloaded): void public function isAutoloaded(): bool ``` -------------------------------- ### Initialize and Use FileSymbolScanner Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/FileSymbolScanner.md This snippet shows how to create an instance of FileSymbolScanner, find symbols within a set of discovered files, and then retrieve the discovered classes. ```php use BrianHenryIE\Strauss\Pipeline\FileSymbolScanner; use BrianHenryIE\Strauss\Files\DiscoveredFiles; use BrianHenryIE\Strauss\Types\DiscoveredSymbols; use BrianHenryIE\Strauss\Helpers\FileSystem; // Create scanner $symbols = new DiscoveredSymbols(); $filesystem = new FileSystem(); $scanner = new FileSymbolScanner($config, $symbols, $filesystem); // Scan files $discoveredFiles = new DiscoveredFiles(); // ... add files to discoveredFiles ... $scanner->findInFiles($discoveredFiles); // Get discovered classes $classes = $symbols->getAllClasses(); foreach ($classes as $className => $classSymbol) { echo $className; // e.g., "Symfony\Console\Application" echo $classSymbol->getSourceFiles()[0]->getSourcePath(); } ``` -------------------------------- ### ComposerPackage::fromFile() Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ComposerPackage.md Creates a ComposerPackage instance by parsing a composer.json file located at the specified absolute path. An optional autoload configuration can be provided to override the package's default autoload settings. ```APIDOC ## ComposerPackage::fromFile() ### Description Creates a ComposerPackage by parsing a composer.json file. The overrideAutoload parameter allows replacing the package's autoload configuration, useful when a package has no autoloader or when you want to use a specific autoload strategy. ### Method `static public function fromFile(string $absolutePath, ?array $overrideAutoload = null): ComposerPackage` ### Parameters #### Path Parameters - **absolutePath** (string) - Required - Absolute path to composer.json file - **overrideAutoload** (array|null) - Optional - Optional autoload configuration to replace the package's own ### Throws `Exception` if the file cannot be parsed or Composer factory fails ``` -------------------------------- ### Get Update Call Sites Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/StraussConfig.md Retrieves the list of paths where references to renamed classes should be updated. If null, Strauss attempts to auto-detect these paths from the autoload configuration. ```php public function getUpdateCallSites(): ?array ``` -------------------------------- ### Verbose Output for All Matches Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ReplaceCommand.md Enable debug mode with the --debug flag to see every match and detailed information about the replacement process. This is helpful for troubleshooting. ```bash strauss replace \ --from "DeprecatedNamespace" \ --to "NewNamespace" \ --paths "." \ --debug ``` -------------------------------- ### Enable Updating Project Files Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/DependenciesCommand.md After prefixing dependencies, automatically update all PHP files in the project's autoload directories to use the new prefixed class names. ```bash strauss dependencies --updateCallSites=true ``` -------------------------------- ### PHP: Enumerate Project Files with FileEnumerator Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/FileEnumerator.md Use FileEnumerator to discover files after enumerating project dependencies. This snippet shows how to get a list of all files and then filter them based on the isDoCopy flag. ```php use BrianHenryIE\Strauss\Pipeline\FileEnumerator; use BrianHenryIE\Strauss\Pipeline\DependenciesEnumerator; // Enumerate dependencies first $depEnumerator = new DependenciesEnumerator($config, $logger); $packages = $depEnumerator->getProjectDependencies($composer); // Then enumerate files $fileEnumerator = new FileEnumerator($config, $filesystem, $logger); $files = $fileEnumerator->compileFileList($packages); // Check what was found echo "Total files: " . count($files); echo "Files to copy: " . count(array_filter( $files->getFiles(), fn($f) => $f->isDoCopy() )); // For project files specifically $projectPaths = ['/path/to/project/includes']; $projectFiles = $fileEnumerator->compileFileListForPaths($projectPaths); ``` -------------------------------- ### DependenciesCommand CLI Usage Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/DependenciesCommand.md This is the basic command-line interface for executing the DependenciesCommand. It accepts various options to customize its behavior. ```bash strauss dependencies [options] ``` -------------------------------- ### Get Project Dependencies Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/DependenciesEnumerator.md Retrieves a flat array of Composer packages to process, keyed by package name. This method respects explicit package lists and exclusion rules defined in the configuration. ```php public function getProjectDependencies( Composer $composer ): array ``` ```php [ 'symfony/console' => ComposerPackage, 'monolog/monolog' => ComposerPackage, 'psr/log' => ComposerPackage, ] ``` ```php $enumerator = new DependenciesEnumerator($config, $logger); $packages = $enumerator->getProjectDependencies($composer); foreach ($packages as $packageName => $package) { echo "Processing: $packageName"; echo " License: " . $package->getLicense(); } ``` -------------------------------- ### Strauss CLI Commands Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/OVERVIEW.md Demonstrates the main commands available for the Strauss CLI tool. These commands are used for dependency analysis, namespace replacement, and autoloader inclusion. ```bash strauss dependencies ``` ```bash strauss replace --from "Old\Namespace" --to "New\Namespace" ``` ```bash strauss include-autoloader ``` -------------------------------- ### Override Package Autoload Configurations Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/configuration.md Use 'override_autoload' to specify custom autoload configurations for particular packages. This allows you to replace the default autoload definitions for a given package, for example, to change PSR-4 mappings. ```json { "extra": { "strauss": { "override_autoload": { "vendor/package": { "psr-4": { "Namespace\\": "src/" } } } } } } ``` -------------------------------- ### Compile File List from Packages Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/FileEnumerator.md Enumerates all files within the provided Composer packages. Use this method to scan files defined in package manifests. ```php public function compileFileList( array $packages ): DiscoveredFiles ``` ```php $enumerator = new FileEnumerator($config, $filesystem, $logger); $discoveredFiles = $enumerator->compileFileList($packagesToProcess); echo "Found " . count($discoveredFiles) . " files"; ``` -------------------------------- ### ComposerPackage Constructor Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ComposerPackage.md Initializes a new ComposerPackage instance. It requires a Composer instance and optionally accepts an array to override autoload definitions. ```APIDOC ## Constructor ### Signature ```php public function __construct(Composer $composer, ?array $overrideAutoload = null) ``` ### Parameters #### composer - **Type**: Composer - **Description**: The Composer instance representing the package. #### overrideAutoload - **Type**: array|null - **Default**: null - **Description**: Optional autoload definition to use instead of the package's own. ``` -------------------------------- ### Dry Run to Preview Changes Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/DependenciesCommand.md Print all intended changes to standard output without modifying any files, allowing for a preview of the operation. ```bash strauss dependencies --dry-run ``` -------------------------------- ### Set Target Directory Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/StraussConfig.md Sets the output directory where prefixed packages will be copied. This path can be absolute or relative. ```php public function setTargetDirectory(string $directory): void ``` -------------------------------- ### Prefix Use Statement Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/Prefixer.md Shows the transformation of a 'use' statement to incorporate the project's namespace prefix. ```php use Symfony\Console\Application; ``` ```php use BrianHenryIE\MyProject\Symfony\Console\Application; ``` -------------------------------- ### Mark Package for Copying Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ComposerPackage.md Sets a flag to indicate whether this package should be copied to the target directory during processing. ```php public function setIsCopy(bool $isCopy): void ``` -------------------------------- ### Create ComposerPackage from File Source: https://github.com/brianhenryie/strauss/blob/master/_autodocs/api-reference/ComposerPackage.md Use this method to create a ComposerPackage instance by parsing a composer.json file. The `overrideAutoload` parameter can be used to replace the package's own autoload configuration. ```php public static function fromFile(string $absolutePath, ?array $overrideAutoload = null): ComposerPackage ```