mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-10 17:28:40 +00:00
fix templates
This commit is contained in:
parent
1d49ceb5a0
commit
121e6b4486
|
|
@ -1327,7 +1327,7 @@ final class ReadMapper extends DataMapperAbstract
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function paginate(string $member, string $ptype, mixed $offset) : self
|
public function paginate(string $member, ?string $ptype, mixed $offset) : self
|
||||||
{
|
{
|
||||||
if ($ptype === 'p') {
|
if ($ptype === 'p') {
|
||||||
$this->where($member, $offset ?? 0, '<');
|
$this->where($member, $offset ?? 0, '<');
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ declare(strict_types=1);
|
||||||
namespace phpOMS\Dispatcher;
|
namespace phpOMS\Dispatcher;
|
||||||
|
|
||||||
use phpOMS\Application\ApplicationAbstract;
|
use phpOMS\Application\ApplicationAbstract;
|
||||||
use phpOMS\Autoloader;
|
|
||||||
use phpOMS\System\File\PathException;
|
use phpOMS\System\File\PathException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -81,102 +80,34 @@ final class Dispatcher implements DispatcherInterface
|
||||||
// In a different language the Api functions would require a return type
|
// In a different language the Api functions would require a return type
|
||||||
// If null is returned (i.e. void functions) these get ignored later in the response renderer as null is not "rendered"
|
// If null is returned (i.e. void functions) these get ignored later in the response renderer as null is not "rendered"
|
||||||
if (\is_string($controller)) {
|
if (\is_string($controller)) {
|
||||||
$views += $this->dispatchString($controller, $data);
|
$dispatch = \explode(':', $controller);
|
||||||
} elseif (\is_array($controller)) {
|
|
||||||
$views += $this->dispatchArray($controller, $data);
|
|
||||||
} else {
|
|
||||||
$views[] = $this->dispatchClosure($controller, $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $views;
|
if (($c = \count($dispatch)) === 3) {
|
||||||
}
|
/* Handling static functions */
|
||||||
|
$function = $dispatch[0] . '::' . $dispatch[2];
|
||||||
|
|
||||||
/**
|
$views[$controller] = $data === null ? $function() : $function(...$data);
|
||||||
* Dispatch string.
|
} elseif ($c === 2) {
|
||||||
*
|
$obj = $this->getController($dispatch[0]);
|
||||||
* The dispatcher can dispatch static functions.
|
$views[$controller] = $data === null
|
||||||
* String: `some/namespace/path::myStaticFunction`
|
? $obj->{$dispatch[1]}()
|
||||||
*
|
: $obj->{$dispatch[1]}(...$data);
|
||||||
* Additionally it's also possible to dispatch functions of modules.
|
}
|
||||||
* Modules are classes which can get instantiated with `new Class(ApplicationAbstract $app)`
|
} elseif (\is_array($controller)) {
|
||||||
* String: `some/namespace/path:myMethod`
|
foreach ($controller as $controllerSingle) {
|
||||||
*
|
$views += $data === null
|
||||||
* @param string $controller Controller string
|
? $this->dispatch($controllerSingle)
|
||||||
* @param null|array $data Data
|
: $this->dispatch($controllerSingle, ...$data);
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @throws PathException this exception is thrown if the function cannot be autoloaded
|
|
||||||
* @throws \Exception this exception is thrown if the function is not callable
|
|
||||||
* @throws \UnexpectedValueException this exception is thrown if the controller string is malformed
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private function dispatchString(string $controller, ?array $data = null) : array
|
|
||||||
{
|
|
||||||
$views = [];
|
|
||||||
$dispatch = \explode(':', $controller);
|
|
||||||
|
|
||||||
if (!Autoloader::exists($dispatch[0]) && !isset($this->controllers[$dispatch[0]])) {
|
|
||||||
throw new PathException($dispatch[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (($c = \count($dispatch)) === 3) {
|
|
||||||
/* Handling static functions */
|
|
||||||
$function = $dispatch[0] . '::' . $dispatch[2];
|
|
||||||
|
|
||||||
if (!\is_callable($function)) {
|
|
||||||
throw new \Exception('Endpoint "'. $function .'" is not callable!');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$views[$controller] = $data === null ? $function() : $function(...$data);
|
|
||||||
} elseif ($c === 2) {
|
|
||||||
$obj = $this->getController($dispatch[0]);
|
|
||||||
$views[$controller] = $data === null
|
|
||||||
? $obj->{$dispatch[1]}()
|
|
||||||
: $obj->{$dispatch[1]}(...$data);
|
|
||||||
} else {
|
} else {
|
||||||
throw new \UnexpectedValueException('Unexpected function.');
|
$views[] = $data === null
|
||||||
|
? $controller($this->app)
|
||||||
|
: $controller($this->app, ...$data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $views;
|
return $views;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Dispatch array.
|
|
||||||
*
|
|
||||||
* @param array $controller Controller string
|
|
||||||
* @param null|array $data Data
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private function dispatchArray(array $controller, ?array $data = null) : array
|
|
||||||
{
|
|
||||||
$views = [];
|
|
||||||
foreach ($controller as $controllerSingle) {
|
|
||||||
$views += $data === null ? $this->dispatch($controllerSingle) : $this->dispatch($controllerSingle, ...$data);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $views;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dispatch closure.
|
|
||||||
*
|
|
||||||
* @param Callable $controller Controller string
|
|
||||||
* @param null|array $data Data
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private function dispatchClosure(callable $controller, ?array $data = null) : mixed
|
|
||||||
{
|
|
||||||
return $data === null ? $controller($this->app) : $controller($this->app, ...$data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispatch controller.
|
* Dispatch controller.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -307,6 +307,22 @@ class View extends ViewAbstract
|
||||||
return \htmlspecialchars($this->getText($translation, $module, $theme));
|
return \htmlspecialchars($this->getText($translation, $module, $theme));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print html output.
|
||||||
|
*
|
||||||
|
* @param ?string $text Text
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function printTextarea(?string $text) : string
|
||||||
|
{
|
||||||
|
return $text === null
|
||||||
|
? ''
|
||||||
|
: \trim(\str_replace(["\r\n", "\n"], [' ', ' '], \htmlspecialchars($text)));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print a numeric value
|
* Print a numeric value
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user