1. Go to this page and download the library: Download matthewpatterson/carpenter 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/ */
matthewpatterson / carpenter example snippets
use Carpenter\Annotation\Factory;
/** @Factory("stdclass") */
class BoringFactory
{
}
use Carpenter\Annotation\Factory;
/** @Factory("\Project\Model\User") */
class UserFactory
{
public $firstName;
public function firstName()
{
$faker = Faker\Factory::create();
return $faker->firstName;
}
}
$user = Carpenter\Factory::build('User');
$user->firstName == "Quincy";
$user = Carpenter\Factory::build('User', ["firstName" => "George"]);
$user->firstName == "George";
use Carpenter\Annotation\Factory;
use Carpenter\Annotation\Modifier;
/** @Factory("\Project\Model\User") */
class UserFactory
{
public $admin = false;
public $roles = [];
/** @Modifier */
public function admin()
{
$this->admin = true;
$this->roles = Roles::getAll();
}
/** @Modifier */
public function moderator()
{
$this->roles = ['delete_posts', 'edit_posts', 'ban_users'];
}
}
$adminUser = Carpenter\Factory::build('User', 'admin');
$moderatorUser = Carpenter\Factory::build('User', 'admin', 'moderator'); // Will have $admin == true but the roles of a moderator
$otherModerator = Carpenter\Factory::build('User', 'admin', ["roles" => ["ban_users"]]); // Will have $admin == true but only the ban_users role
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.