123456789101112131415161718192021222324252627282930313233 |
- <?php
- namespace Juju\PDO;
- class Filter {
- private static $filters = [];
- private $name;
- private $filter;
- private function __construct(string $name, string $filter){
- $this->name = $name;
- self::$filters[$name] = $this;
- }
- public function name(){
- return $this->name;
- }
- public function __toString(){
- return $this->filter;
- }
- public static function named(string $name){
- if(!isset(self::$filters[$name])){
- throw new \Exception("Filter {$name} is not defined");
- }
- return self::$filters[$name];
- }
- public static function add(string $name, string $filter){
- if(isset(self::$filters[$name])){
- throw new \Exception("Filter {$name} is already defined");
- }
- return new Filter($name, $filter);
- }
- }
- Filter::add('not null', 'is not null');
- Filter::add('null', 'is null');
- ?>
|