1. Go to this page and download the library: Download mooti/factory 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/ */
mooti / factory example snippets
namespace My;
class Foo
{
private $firstName;
private $lastName;
public function __construct($firstName, $lastName) {
$this->firstName = $firstName;
$this->lastName = $lastName;
}
public function hello()
{
return 'hello '.$this->firstName. ' ' . $this->lastName;
}
}
namespace Your;
use Mooti\Factory\Factory;
use My\Foo;
class Bar
{
use Factory;
public function speak($firstName, $lastName)
{
$foo = $this->createNew(Foo::class, $firstName, $lastName);
return $foo->hello();
}
}
= new \Your\Bar();
echo $bar->speak('Ken', 'Lalobo');