1. Go to this page and download the library: Download fangx/php-enum 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/ */
fangx / php-enum example snippets
namespace Enums;
use Fangx\Enum\AbstractEnum;
class FooEnum extends AbstractEnum
{
const FOO = "f", __FOO = "foo";
const BAR = "b", __BAR = "bar";
}
class FooFilter implements \Fangx\Enum\Contracts\Filter
{
public function __invoke(\Fangx\Enum\Contracts\Definition $definition)
{
return $definition->getKey() !== 'f';
}
}
/**
* ['f' => 'foo']
*/
$fooFilter = new FooFilter();
$barFilter = new BarFilter();
FooEnum::toArray(null, $fooFilter, $barFilter);
FooEnum::addFilter($fooFilter)->addFilter($barFilter)->toArray(); # ^1.3
class BarEnum extends \Fangx\Enum\AbstractEnum
{
public function all()
{
return [
new \Fangx\Enum\Definition('f', 'foo'),
new \Fangx\Enum\Definition('b', 'bar'),
];
}
}
declare(strict_types=1);
namespace Fangx\Tests\Stubs;
use Fangx\Enum\WithoutDefault;
class HasDefaultFiltersEnum extends ExampleEnum
{
public function filters()
{
return [
new WithoutDefault(),
new WithoutDefault('unknown'),
];
}
}
declare(strict_types=1);
namespace Fangx\Tests\Stubs;
use Fangx\Enum\Contracts\Format;
class HasDefaultFormatEnum extends ExampleEnum
{
public function format(): ?Format
{
return new CustomFormat();
}
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.