PHP code example of eudiegoborgs / hyperf-cgen

1. Go to this page and download the library: Download eudiegoborgs/hyperf-cgen library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

eudiegoborgs / hyperf-cgen example snippets




declare(strict_types=1);

return [
    'generator' => [
        'example_type' => [
            'namespace' => 'CyBorgs\\Hyperf\\CGen\\Custom',
            'stub' => __DIR__ . '/stubs/class.stub',
            'run_previous' => [
                'other_type',
                'interface'
            ]
        ],
        'other_type' => [
            'namespace' => 'CyBorgs\\Hyperf\\CGen\\OtherCustom',
            'stub' => __DIR__ . '/stubs/other_class.stub',
            'prefix' => 'Prefix',
            'suffix' => 'Suffix',
        ],
        'interface' => [
            'namespace' => 'CyBorgs\\Hyperf\\CGen\\Custom\\%CLASS%\\Interfaces',
            'stub' => __DIR__ . '/stubs/interface.stub',
            'suffix' => 'Interface',
        ],
    ],
    'default' => [
        'stub' => 'path/to/real/stub/example_type.stub',
        'namespace' => 'App\\Example\\Default'
    ]
];


// path/to/real/stub/other_type.stub


declare(strict_types=1);

namespace %NAMESPACE%;

class %CLASS%
{

}

// path/to/real/stub/example_type_interface.stub


declare(strict_types=1);

namespace %NAMESPACE%;

interface %CLASS%
{

}

// path/to/real/stub/example_type_interface.stub


declare(strict_types=1);

namespace %NAMESPACE%;

use %other_type.NAMESPACE%\%other_type.CLASS%;

class %CLASS%
{
    public function __construct(
        private %other_type.CLASS% %other_type.VARIABLE_NAME%
    ) {}
}



declare(strict_types=1);

namespace CyBorgs\Hyperf\CGen\OtherCustom;

class PrefixMyClassNameSuffix
{
    
}



declare(strict_types=1);

namespace CyBorgs\Hyperf\CGen\Custom\MyClassName\Interfaces;

class MyClassNameInterface
{
    
}



declare(strict_types=1);

namespace CyBorgs\Hyperf\CGen\Custom;

use CyBorgs\Hyperf\CGen\OtherCustom\PrefixMyClassNameSuffix;

class MyClassName
{
    public function __construct(
        private PrefixMyClassNameSuffix $classTest
    ) {}
}
 
php bin/hyperf.php vendor:publish eudiegoborgs/hyperf-cgen
 
config/autoload/cgen.php
 
php bin/hyperf.php cgen:create example_type MyClassName 
 
src/
    - Example/
        - Namespace/
            - MyClassName/
                - Interfaces/
                    - MyClassNameInterface.php
            - MyClassName.php
        - OtherNamespace/
            PrefixMyClassNameSuffix.php