added simple math and charts modules

This commit is contained in:
2024-12-10 23:53:23 +01:00
parent 62a5f3c97c
commit 688ff42752
196 changed files with 20285 additions and 8 deletions

View File

@@ -0,0 +1,66 @@
<?php
/**
* @author Serge Rodovnichenko <serge@syrnik.com>
* @copyright Serge Rodovnichenko, 2019
* @license BSD 2.0
*/
namespace Andileco\Util\EvalMath;
use ArrayAccess;
use Countable;
use RuntimeException;
use Andileco\Util\EvalMath\Methods\AbstractMethod;
class MethodsRegistry implements ArrayAccess, Countable
{
protected $methods = [];
public function set(AbstractMethod $method)
{
$this->methods[$method->getName()] = clone $method;
return $this;
}
public function unsetByName($name)
{
unset($this->methods[$name]);
return $this;
}
/**
* @param $name
* @return AbstractMethod|null
*/
public function findByName($name)
{
return (isset($this->methods[$name]) and $this->methods[$name] instanceof AbstractMethod) ? $this->methods[$name] : null;
}
public function offsetExists($offset): bool
{
return isset($this->methods[$offset]);
}
public function offsetGet($offset): mixed
{
$m = $this->findByName($offset);
return $m ? $m->getArgumentCount() : null;
}
public function offsetSet($offset, $value): void
{
throw new RuntimeException('Use set() method instead');
}
public function offsetUnset($offset): void
{
$this->unsetByName($offset);
}
public function count(): int
{
return count($this->methods);
}
}