PHP Classes

File: src/bootstrap.php

Recommend this page to a friend!
  Classes of Axel Pardemann  >  PHP String Extensions Inflections  >  src/bootstrap.php  >  Download  
File: src/bootstrap.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP String Extensions Inflections
Extend the StringType class to provide inflections
Author: By
Last change:
Date: 2 years ago
Size: 1,034 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

namespace
NorseBlue\StringExtensions\Inflections;

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\Inflections',
            [
               
'Extensions',
               
"String{$name}Extension",
            ],
           
'\\'
       
);

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

For more information send a message to info at phpclasses dot org.