small/class-manipulator

There is no license information available for the latest version (1.1.0) of this package.

Allows you to manipulate classes by loading then into structured objects and then writing them back to the filesystem.

1.1.0 2023-09-17 22:37 UTC

This package is auto-updated.

Last update: 2024-04-13 21:46:17 UTC


README

This lib allow you to read and parse a php file containing class into a php object.

You can then easily add or remove components and rewrite file with modifications.

install

$ composer install small/class-manipulator

Parsing and generating classes

Manipulator instanciation

To parse a class, you must instanciate ClassManipulator :

$classManipulator = new ClassManipulator([
        'rootDir' => __DIR__ . '/../data',
        'selectors' => [
            'test' => [
                'testing' => [
                    'namespace' => 'DataTest\Testing',
                    'path' => 'DataTest',
                ], 'empty' => [
                    'namespace' => 'Empty',
                    'path' => 'Empty',
                ],
            ]
        ],
    ]);

The "rootDir" parameter is your "src" directory.

The selectors allow you to isolate namespaces params by categories. Here we have injecting only a "test" selector.

In the test selector, we have as many of namespaces we want and each namespace must contain a namespace and corresponding directory path.

Parsing

You can now parse a class :

$classFile = $this->classManipulator->getClass('test', \Empty\Testing\TestClass::class);

This will return a ClassFile

Unit test

To run unit tests, you are required to install docker and docker-compose :

$ apt-get install docker docker-compose

Then go to root of lib and run :

$ docker-compose up -d --build

If the tests fail the command will return an error.

In development, you can set argument "BUILD" to 0 in docker-compose.yml, then the container will not stop, allow you to run tests using :

$ bin/test