2020-05-28 04:55:58 +00:00
|
|
|
<?php
|
2020-12-14 01:49:07 +00:00
|
|
|
/**
|
|
|
|
* MadLisp language
|
|
|
|
* @link http://madlisp.com/
|
|
|
|
* @copyright Copyright (c) 2020 Pekka Laiho
|
|
|
|
*/
|
|
|
|
|
2020-05-28 04:55:58 +00:00
|
|
|
namespace MadLisp;
|
|
|
|
|
|
|
|
abstract class Collection
|
|
|
|
{
|
2020-12-06 14:05:04 +00:00
|
|
|
public static function new(array $data = []): self
|
|
|
|
{
|
|
|
|
// late static binding
|
|
|
|
return new static($data);
|
|
|
|
}
|
|
|
|
|
2020-05-28 04:55:58 +00:00
|
|
|
protected array $data = [];
|
|
|
|
|
|
|
|
public function __construct(array $data = [])
|
|
|
|
{
|
|
|
|
$this->data = $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function count(): int
|
|
|
|
{
|
|
|
|
return count($this->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function has(string $key): bool
|
|
|
|
{
|
|
|
|
return array_key_exists($key, $this->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getData(): array
|
|
|
|
{
|
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
}
|