PHP code example of hail / optimize

1. Go to this page and download the library: Download hail/optimize 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/ */

    

hail / optimize example snippets


use Hail\Optimize\OptimizeTrait;

class Example
{
    use OptimizeTrait;
    
    private string $folder;
    
    public function __construct(string $folder)
    {
        $this->folder = $folder;
    }
    
    public function dataReader(string $file): array
    {
        return unserialize(file_get_contents($file));
    }
    
    public function get(string $name): array
    {
        $file = $this->folder . DIRECTORY_SEPARATOR . $name . '.json';
        return $this->optimize()->load($file);
    }
    
    public function getSerializeData($name): array
    {
        $file = $this->folder . DIRECTORY_SEPARATOR . $name . '.data';

        return $this->optimize()->load($file, [$this, 'dataReader']);
    }
}