PHP Classes

File: src/bootstrap.php

Recommend this page to a friend!
  Classes of Axel Pardemann   PHP Regular Expression Functions Extension   src/bootstrap.php   Download  
File: src/bootstrap.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: PHP Regular Expression Functions Extension
Extend a string type with regular expression match
Author: By
Last change:
Date: 5 years ago
Size: 1,022 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

namespace
NorseBlue\StringExtensions\Regex;

use
NorseBlue\ScalarObjects\Types\StringType;
use
Symfony\Component\Finder\Finder;
use function
NorseBlue\ScalarObjects\path_merge;

/**
 * @codeCoverageIgnore
 */
(static function (): void {
   
$extensions_path = path_merge(__DIR__, 'Extensions');
   
$extensions = array_keys(
       
iterator_to_array(
           
Finder::create()
                ->
in($extensions_path)
                ->
name("String*Extension.php")
                ->
files()
        )
    );

    foreach (
$extensions as $path) {
       
$pattern = '%^' . path_merge($extensions_path, 'String') . '(.+)Extension\.php$%';
       
$name = preg_replace($pattern, '\1', $path);

       
$extension = path_merge(
           
'NorseBlue\StringExtensions\Regex',
            [
               
'Extensions',
               
"String{$name}Extension",
            ],
           
'\\'
       
);

       
StringType::registerExtensionMethod(lcfirst($name), $extension);
    }
})();