1. Go to this page and download the library: Download afterflow/recipe 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/ */
// Full syntax
$recipe = (new ClassRecipe())->with($data)->render();
// Pass data into constructor:
$recipe = (new ClassRecipe($data))->render();
// Less braces:
$recipe = ClassRecipe::make($data);
// If your recipe defines a template or a custom render() function:
$string = ClassRecipe::quickRender($data);
// Compile data only:
$data = ClassRecipe::quickBuild($data);
// ...
public function name($value)
{
return $this->input('name', $value);
}
public function value($value)
{
return $this->input('value', $value);
}
public function const()
{
return $this->input('const', true);
}
// ...
/**
* This recipe nests other recipes and shows alternative syntax to pass data through constructor
*/
$data = ClassRecipe::make()->namespace('App')->name('User')->content(
/**
* See ClassVarRecipe to learn how to render things without template
*/
Recipe::sequence([
ClassVarRecipe::make()->protected()->name('$name')->docBlock('// First Name')->render(),
ClassVarRecipe::make()->protected()->name('$lastName')->docBlock('// Last Name')->render(),
/**
* See ClassVarRecipe to learn how to filter data before render
*/
ConstructorRecipe::make()->arguments([
'string $name',
'string $lastName',
])->body('$this->name = $name;' . eol() . '$this->lastName = $lastName;')->render(),
FunctionRecipe::make()->name('getLastName')->return('$this->lastName;')->render(),
FunctionRecipe::make()->name('getName')->return('$this->name;')->render(),
], eol(2))
)->render();
namespace App;
class User
{
// First Name
protected $name = "Vlad";
// Last Name
protected $lastName;
function __construct(string $name, string $lastName)
{
$this->name = $name;
$this->lastName = $lastName;
}
function getLastName()
{
return $this->lastName;
}
function getName()
{
return $this->name;
}
}