small/class-manipulator

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

2.3.2 2024-10-14 20:04 UTC

This package is auto-updated.

Last update: 2024-11-14 20:10:54 UTC


README

Small Class Manipulator

        

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 require small/class-manipulator

Parsing and generating classes

Manipulator instanciation

To parse a class, you must instanciate ClassManipulator :

$classManipulator = \Small\ClassManipulator\ClassManipulator::fromProject('/usr/src/my-app');

A composer.json must be present in the folder indicated by path

Parsing

You can now parse a class :

$classFile = $this->classManipulator->getClass(\App\Service\Test::class)
    ->parse()
;

This will return a ClassFile

The returned object allow you to manipulate class :

$classFile->getClass()->setFinal(true);

Here, we have transformed class to final class.

Writing modifications to disk

Now just write class to save manipulations :

$classFile->write();