Skip to content

A simple class for creating objects object-oriented way

License

Notifications You must be signed in to change notification settings

SunnyFlail/ObjectCreator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ObjectCreator

A simple class providing object oriented interface over class invoking

Usage

First you need to import it by requiring composer autoloader AND then importing it in class that will use it

use SunnyFlail\ObjectCreator\ObjectCreator;

Creating object

First you need a common object creator instance and then invoke ObjectCreator::create passing fully qualified class name as an argument (the namespaced CANNOT contain leading backslashes). This returns a mutable copy of ObjectCreator

$creator = new ObjectCreator();
$concreteCreator = $creator->create(Entity::class);

Setting properties

To set properties just invoke ObjectCreator::withProperty on initialised copy, passing name of the property as first value, and value as second. This returns the copy so you can chain it.

$concreteCreator->withProperty("propertyName", "value");

Getting object

To get the object invoke ObjectCreator::getObject on initalised copy.

$object = $concreteCreator->getObject();

Extending

You can make your custom implementation of this by implementing interface IObjectCreator.

About

A simple class for creating objects object-oriented way

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages