add nova
This commit is contained in:
48
nova/src/Support/Fluent.php
Normal file
48
nova/src/Support/Fluent.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Nova\Support;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Nova\Makeable;
|
||||
|
||||
class Fluent extends \Illuminate\Support\Fluent
|
||||
{
|
||||
use Makeable;
|
||||
|
||||
/**
|
||||
* Fill the model with an array of attributes.
|
||||
*
|
||||
* @param array<string, mixed> $attributes
|
||||
* @return $this
|
||||
*/
|
||||
public function fill(array $attributes)
|
||||
{
|
||||
foreach ($attributes as $key => $value) {
|
||||
$attribute = Str::replace('->', '.', $key);
|
||||
|
||||
if (! Arr::has($this->attributes, $attribute)) {
|
||||
Arr::set($this->attributes, $attribute, $value);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill the model with an array of attributes.
|
||||
*
|
||||
* @param array<string, mixed> $attributes
|
||||
* @return $this
|
||||
*/
|
||||
public function forceFill(array $attributes)
|
||||
{
|
||||
foreach ($attributes as $key => $value) {
|
||||
$attribute = Str::replace('->', '.', $key);
|
||||
|
||||
Arr::set($this->attributes, $attribute, $value);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
119
nova/src/Support/PendingTranslation.php
Normal file
119
nova/src/Support/PendingTranslation.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Nova\Support;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Traits\ForwardsCalls;
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* @mixin \Illuminate\Support\Stringable
|
||||
*/
|
||||
class PendingTranslation implements JsonSerializable
|
||||
{
|
||||
use ForwardsCalls;
|
||||
|
||||
/**
|
||||
* The translation string.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $key;
|
||||
|
||||
/**
|
||||
* The translation replacement.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public $replace = [];
|
||||
|
||||
/**
|
||||
* The translation locale.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $locale = null;
|
||||
|
||||
/**
|
||||
* The translation transformation callback.
|
||||
*
|
||||
* @var (callable(\Illuminate\Support\Stringable):(\Stringable|string))|null
|
||||
*/
|
||||
public $transformCallback;
|
||||
|
||||
/**
|
||||
* Create a new pending translation.
|
||||
*
|
||||
* @param string|null $key
|
||||
* @param array<string, string> $replace
|
||||
* @param string|null $locale
|
||||
*/
|
||||
public function __construct($key = null, $replace = [], $locale = null)
|
||||
{
|
||||
$this->key = $key;
|
||||
$this->replace = $replace;
|
||||
$this->locale = $locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the translation.
|
||||
*
|
||||
* @param (callable(\Illuminate\Support\Stringable):(\Stringable|string)) $transformCallback
|
||||
* @return $this
|
||||
*/
|
||||
public function transform(callable $transformCallback)
|
||||
{
|
||||
$this->transformCallback = $transformCallback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the resolved value.
|
||||
*
|
||||
* @param string|null $locale
|
||||
* @return string
|
||||
*/
|
||||
public function value($locale = null)
|
||||
{
|
||||
$locale = $locale ?? $this->locale;
|
||||
|
||||
return (string) with(Str::of(
|
||||
transform(__($this->key, $this->replace, $locale), function ($translation) {
|
||||
return is_string($translation) ? $translation : $this->key;
|
||||
}) ?? ''
|
||||
), $this->transformCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically proxy method calls to Stringable.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
return $this->forwardCallTo(Str::of($this->value()), $method, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the translation as string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->value();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the translation as json.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function jsonSerialize(): string
|
||||
{
|
||||
return $this->value();
|
||||
}
|
||||
}
|
||||
31
nova/src/Support/UndefinedValue.php
Normal file
31
nova/src/Support/UndefinedValue.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Nova\Support;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class UndefinedValue implements \JsonSerializable
|
||||
{
|
||||
/**
|
||||
* Determine if value is equivalent to "undefined" or "null".
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public static function equalsTo($value)
|
||||
{
|
||||
return $value instanceof UndefinedValue || is_null($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value as json.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user