PHP code example of envorradev / file-class-resolver

1. Go to this page and download the library: Download envorradev/file-class-resolver 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/ */

    

envorradev / file-class-resolver example snippets


namespace SomeNamespace\SomeFolder;

class SomeClass {
    public function __construct(
        public string $aRequiredString,
        public int $anOptionalInt = 5,
    ) {}
}

$filename = __DIR__.'/SomeFolder/SomeClass.php';

use Envorra\FileClassResolver\ClassResolver;

ClassResolver::resolve($filename);

ClassResolver::make($someOtherClassPath);

ClassResolver::make($filename, ['string value', 10]);

ClassResolver::make($filename, ['string value']);

ClassResolver::make($filename, ['aRequiredString' => 'string value', 'anOptionalInt' => 7]);

ClassResolver::make($filename, ['anOptionalInt' => 7, 'aRequiredString' => 'string value']);

ClassResolver::resolver($filename);

$resolver = ClassResolver::resolve($filename);

$resolver->getClass();

'SomeNamespace\SomeFolder\SomeClass'

$resolver->getClassInstance(['string']);

$resolver->getClassName();

'SomeClass'

$resolver->getClassNode();

PhpParser\Node\Stmt\Class_ {#8563
    +name: PhpParser\Node\Identifier {#8550
        +name: "SomeClass",
    },
    +stmts: [
        PhpParser\Node\Stmt\ClassMethod {#8562
            +flags: 1,
            +byRef: false,
            +name: PhpParser\Node\Identifier {#8551
                +name: "__construct",
            },
            +params: [
                PhpParser\Node\Param {#8554
                    +type: PhpParser\Node\Identifier {#8553
                        +name: "string",
                    },
                    +byRef: false,
                    +variadic: false,
                    +var: PhpParser\Node\Expr\Variable {#8552
                        +name: "aRequiredString",
                    },
                    +default: null,
                    +flags: 1,
                    +attrGroups: [],
                },
                PhpParser\Node\Param {#8557
                    +type: PhpParser\Node\Identifier {#8556
                        +name: "int",
                    },
                    +byRef: false,
                    +variadic: false,
                    +var: PhpParser\Node\Expr\Variable {#8555
                        +name: "anOptionalInt",
                    },
                    +default: null,
                    +flags: 1,
                    +attrGroups: [],
                },
            ],
            +returnType: null,
            +stmts: [],
            +attrGroups: [],
        },
    ],
    +attrGroups: [],
    +namespacedName: null,
    +flags: 0,
    +extends: null,
    +implements: [],
}

$resolver->getFullyQualifiedClassName();

'SomeNamespace\SomeFolder\SomeClass'

$resolver->getNamespace();

'SomeNamespace\SomeFolder'

$resolver->getNamespaceNode();

PhpParser\Node\Stmt\Namespace_ {#8549
    +name: PhpParser\Node\Name {#8548
        +parts: [
            "SomeNamespace",
            "SomeFolder",
        ],
    },
    +stmts: [
        PhpParser\Node\Stmt\Class_ {#8563
            +name: PhpParser\Node\Identifier {#8550
                +name: "SomeClass",
            },
            +stmts: [
                PhpParser\Node\Stmt\ClassMethod {#8562
                    +flags: 1,
                    +byRef: false,
                    +name: PhpParser\Node\Identifier {#8551
                        +name: "__construct",
                    },
                    +params: [
                        PhpParser\Node\Param {#8554
                            +type: PhpParser\Node\Identifier {#8553
                                +name: "string",
                            },
                            +byRef: false,
                            +variadic: false,
                            +var: PhpParser\Node\Expr\Variable {#8552
                                +name: "aRequiredString",
                            },
                            +default: null,
                            +flags: 1,
                            +attrGroups: [],
                        },
                        PhpParser\Node\Param {#8557
                            +type: PhpParser\Node\Identifier {#8556
                                +name: "int",
                            },
                            +byRef: false,
                            +variadic: false,
                            +var: PhpParser\Node\Expr\Variable {#8555
                                +name: "anOptionalInt",
                            },
                            +default: null,
                            +flags: 1,
                            +attrGroups: [],
                        },
                    ],
                    +returnType: null,
                    +stmts: [],
                    +attrGroups: [],
                },
            ],
            +attrGroups: [],
            +namespacedName: null,
            +flags: 0,
            +extends: null,
            +implements: [],
        },
    ],
}