1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92:
<?php
namespace Chippyash\Math\Matrix;
use Chippyash\Math\Matrix\Exceptions\MathMatrixException;
use Chippyash\Math\Matrix\Special\SpecialMatrixInterface;
use Chippyash\Type\String\StringType;
class SpecialMatrix
{
const ERR1 = 'You need at least the name of the special matrix to create it!';
const ERR2 = 'Matrix named %s does not exist';
const ERR3 = 'Matrix named %s does not implement SpecialMatrixInterface';
const NS = '\\Chippyash\\Math\\Matrix\\Special\\';
public function __invoke()
{
$args = func_get_args();
$nArgs = func_num_args();
if ($nArgs === 0) {
throw new MathMatrixException(self::ERR1);
}
$temp = array_shift($args);
$mName = ($temp instanceof StringType ? $temp : new StringType($temp));
return $this->create($mName, $args);
}
public function create(StringType $matrixName, array $args = [])
{
$mName = self::NS . ucfirst($matrixName);
if (!class_exists($mName)) {
throw new MathMatrixException(sprintf(self::ERR2, $mName));
}
$mClass = new $mName();
if (!$mClass instanceof SpecialMatrixInterface) {
throw new MathMatrixException(sprintf(self::ERR3, $mName));
}
return $mClass->create($args);
}
}