PHP code example of eclipxe / micro-catalog

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

    

eclipxe / micro-catalog example snippets




declare(strict_types=1);

use Eclipxe\MicroCatalog\MicroCatalog;

/**
 * ResultCodes is an example class to show the basic usage
 *
 * @method bool isOk()
 * @method bool isWarning()
 * @method bool isError()
 */
final class ResultCodes extends MicroCatalog
{
    public static function getEntriesArray(): array
    {
        return [
            0 => 'Ok',
            1 => 'Warning',
            2 => 'Error',
        ];
    }

    public function getEntryValueOnUndefined(): string
    {
        return '#N/A';
    }

    public function getEntryId(): string
    {
        return strval($this->getEntryValue());
    }
}

$warning = new ResultCodes(1);
var_dump($warning->isWarning());        // bool(true)
var_dump($warning->getEntryIndex());    // int(1)
var_dump($warning->getEntryValue());    // string(7) "Warning"
var_dump($warning->getEntryId());       // string(7) "Warning" (method was overriden)
var_dump($warning->isUndefined());      // bool(false)

$other = new ResultCodes(99);
var_dump($other->isUndefined());        // bool(true)
var_dump($other->getEntryIndex());      // int(99)
var_dump($other->getEntryValue());      // string(4) "#N/A"