PHP code example of phf / collection
1. Go to this page and download the library: Download phf/collection 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/ */
phf / collection example snippets
class Foo
{
public StringCollection $bar;
public function __construct()
{
$this->bar = new StringCollection();
}
}
$foo = new Foo();
$foo->bar[] = 123; // throws InvalidArgumentException
class BarEntity
{
public string $baz;
}
class BarCollection extends \PhF\Collection\Collection
{
protected static $invalidElementMessageAllowed = BarEntity::class;
public function validate(
$value
): bool {
return $value instanceof BarEntity;
}
}
class Foo
{
public BarCollection $bar;
public function __construct()
{
$this->bar = new BarCollection();
}
}