
Maravel-Framework 10.57.0 Maravel 10.52.0 Maravelith 10.52.0
The demo page for Maravelith template 10.52.0 with kernel maravel-framework 10.57.0 and with maravel-rest-wizard has been deployed.
The latest versions of the Maravel (micro-framework) and Maravelith templates (10.52.0) have both App\Request and App\Application classes, allowing some new features from maravel-framework 10.57.0 :
- Introduce registerExplicitBindingsMap boot improvement
This means that for the macroable classes that can be retrieved from the container, the developer can register them as raw in the \App\Application for minimizing the boot time impact:
Maravelith:
<?php
namespace App;
class Application extends \Illuminate\Foundation\Application
{
/**
* Set all the container bindings that should be registered when the app is instantiated
* @see \Illuminate\Container\Container::getClosure for Closure format
* @see static::registerCoreContainerAliases to handle alias changes if impacted by this function
* Must set array shape:
* [
* "{$abstractString}" => [
* 'concrete' => \Closure,
* 'shared' => bool
* ],
* ]
*/
protected function registerExplicitBindingsMap(): void
{
// $this->bindings = [
// \Illuminate\Http\Request::class => [
// 'concrete' => function (
// \Illuminate\Contracts\Container\Container $container,
// array $parameters = []
// ): \Illuminate\Http\Request {
// return $container->resolve(
// \App\Requests\Request::class, // your child class
// $parameters,
// false
// );
// },
// 'shared' => false
// ],
// ];
}
/**
* Register the core class aliases in the container.
* Both $aliases and $abstractAliases properties must be synced acc. to \Illuminate\Container\Container::alias logic
*/
public function registerCoreContainerAliases(): void
{
parent::registerCoreContainerAliases();
$this->abstractAliases['app'][] = static::class;
$this->abstractAliases['request'][] = \App\Request::class;
$this->aliases[static::class] = 'app';
$this->aliases[\App\Request::class] = 'request';
}
}
Maravel:
/**
* Set all the container bindings that should be registered when the app is instantiated
* @see \Illuminate\Container\Container::getClosure for Closure format
* @see static::registerContainerAliases to handle alias changes if impacted by this function
* Must set array shape:
* [
* "{$abstractString}" => [
* 'concrete' => \Closure,
* 'shared' => bool
* ],
* ]
*/
protected function registerExplicitBindingsMap(): void
{
// $this->bindings = [
// \Illuminate\Http\Request::class => [
// 'concrete' => function (
// \Illuminate\Contracts\Container\Container $container,
// array $parameters = []
// ): \Illuminate\Http\Request {
// return $container->resolve(
// \App\Requests\Request::class, // your child class
// $parameters,
// false
// );
// },
// 'shared' => false
// ],
// ];
}
- Define as raw aliases and abstractAliases avoiding loop calls to \Illuminate\Container\Container::alias
This shortens the execution steps for registering the aliases in Maravelith, Maravel had already this feature.
- Move Illuminate\Console\GeneratorCommand back from maravel-framework-dev because it is used by \Maatwebsite\Excel\Console\ExportMakeCommand (bug introduced in version 10.55.0)
- The new custom \App\Request contains the macros from laravel-crud-wizard-free: forceOffsetUnset, forceReplace and getFiltered.
<?php
namespace App;
use Illuminate\Support\Facades\Log;
class Request extends \Laravel\Lumen\Http\Request // or \Illuminate\Http\Request
{
public function forceOffsetUnset(string $offset): static
{
$this->query->remove($offset);
$this->request->remove($offset);
$this->offsetUnset($offset);
return $this;
}
public function forceReplace(array $data): static
{
$this->query->replace();
$this->request->replace();
$this->replace($data);
return $this;
}
/**
* @param string|int $filter can be 'alpha', 'alnum', 'digits' or an int flag
* @see ParameterBag::filter(), \filter_var() for $filter and $options
* @see ParameterBag::getAlpha()
* @see ParameterBag::getAlnum()
* @see ParameterBag::getDigits()
* @see ParameterBag::getInt()
* @see ParameterBag::getBoolean()
*/
public function getFiltered(
string $key,
mixed $default = null,
string|int $filter = \FILTER_DEFAULT,
array|int $options = [],
): mixed {
if (\is_int($filter)) {
try {
if ($this->attributes->has($key)) {
return $this->attributes->filter($key, $default, $filter, $options);
}
if ($this->query->has($key)) {
return $this->query->filter($key, $default, $filter, $options);
}
if ($this->request->has($key)) {
return $this->request->filter($key, $default, $filter, $options);
}
} catch (\UnexpectedValueException $e) {
// if (REQUEST_GET_FILTERED_MACRO_SHOULD_THROW_ON_FAILURE) {
// throw $e;
// }
if (!\is_array($options) && $options) {
$options = ['flags' => $options];
}
return ($options['flags'] ?? 0) & \FILTER_NULL_ON_FAILURE ? null : false;
}
return $default;
}
if ($filter !== '') {
$filter = \ucfirst(\strtolower($filter));
if (!\in_array($filter, ['Alpha', 'Alnum', 'Digits'], true)) {
$filter = '';
}
}
try {
if ($this->attributes->has($key)) {
return $this->attributes->{'get' . $filter}($key, $default);
}
if ($this->query->has($key)) {
return $this->query->{'get' . $filter}($key, $default);
}
if ($this->request->has($key)) {
return $this->request->{'get' . $filter}($key, $default);
}
} catch (\UnexpectedValueException) {
} catch (\Throwable $e) {
Log::error( __FILE__. ':' . __LINE__. ' Request::getFiltered error: ' .
$e->getMessage() . ' for: ' . \json_encode(\func_get_args()), $e->getTrace());
}
return $default;
}
}
Top comments (0)