1. Go to this page and download the library: Download michaeljennings/refinery 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/ */
michaeljennings / refinery example snippets
// Here we have a product we want to refine
class Product
{
public $price = 10
public $description = 'Something really cool!'
}
// So we create a product refinery where we set the product template
class ProductRefinery extends Refinery
{
public function setTemplate($product)
{
return [
'price' => number_format($product->price, 2),
'description' => $product->description,
'full_description' => $product->description . ' For only £' . number_format($product->price, 2),
];
}
}
// Then we create the instances and refine the product
$product = new Product();
$refinery = new ProductRefinery();
var_dump($refinery->refine($product));
// The above will output:
// ['price' => '10.00', 'description' => 'Something really cool!', 'full_description' => 'Something really cool! For only £10.00']
use Michaeljennings\Refinery\Refinery;
class Foo extends Refinery
{
}
class Foo extends Refinery
{
public function setTemplate($data)
{
// Refine data
}
}
class ProductRefinery extends Refinery
{
public function setTemplate($product)
{
return [
'name' => $product['name'],
'description' => $product['description'],
'price' => '£' . number_format($product['price'], 2),
];
}
public function category()
{
return $this->attach(CategoryRefinery::class);
}
public function variants()
{
return $this->attach(CategoryRefinery::class);
}
}
// Will just refine the product data.
$refinedProduct = $productRefinery->refine($product);
// Will refine the product, category, and the variants.
$refinedProductWithAttachments $productRefinery->bring('category', 'variants')->refine($product);