first commit

This commit is contained in:
Olu Amey
2021-09-13 06:53:04 -04:00
commit 32eb3ab418
3602 changed files with 875408 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
<?php
/**
* This file is part of the CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CodeIgniter\Entity\Cast;
/**
* Class ArrayCast
*/
class ArrayCast extends BaseCast
{
/**
* @inheritDoc
*/
public static function get($value, array $params = []): array
{
if (is_string($value) && (strpos($value, 'a:') === 0 || strpos($value, 's:') === 0))
{
$value = unserialize($value);
}
return (array) $value;
}
/**
* @inheritDoc
*/
public static function set($value, array $params = []): string
{
return serialize($value);
}
}
+44
View File
@@ -0,0 +1,44 @@
<?php
/**
* This file is part of the CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CodeIgniter\Entity\Cast;
/**
* Class BaseCast
*/
abstract class BaseCast implements CastInterface
{
/**
* Get
*
* @param mixed $value Data
* @param array $params Additional param
*
* @return mixed
*/
public static function get($value, array $params = [])
{
return $value;
}
/**
* Set
*
* @param mixed $value Data
* @param array $params Additional param
*
* @return mixed
*/
public static function set($value, array $params = [])
{
return $value;
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
/**
* This file is part of the CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CodeIgniter\Entity\Cast;
/**
* Class BooleanCast
*/
class BooleanCast extends BaseCast
{
/**
* @inheritDoc
*/
public static function get($value, array $params = []): bool
{
return (bool) $value;
}
}
+34
View File
@@ -0,0 +1,34 @@
<?php
/**
* This file is part of the CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CodeIgniter\Entity\Cast;
/**
* Class CSVCast
*/
class CSVCast extends BaseCast
{
/**
* @inheritDoc
*/
public static function get($value, array $params = []): array
{
return explode(',', $value);
}
/**
* @inheritDoc
*/
public static function set($value, array $params = []): string
{
return implode(',', $value);
}
}
+38
View File
@@ -0,0 +1,38 @@
<?php
/**
* This file is part of the CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CodeIgniter\Entity\Cast;
/**
* Interface CastInterface
*/
interface CastInterface
{
/**
* Get
*
* @param mixed $value Data
* @param array $params Additional param
*
* @return mixed
*/
public static function get($value, array $params = []);
/**
* Set
*
* @param mixed $value Data
* @param array $params Additional param
*
* @return mixed
*/
public static function set($value, array $params = []);
}
+52
View File
@@ -0,0 +1,52 @@
<?php
/**
* This file is part of the CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CodeIgniter\Entity\Cast;
use CodeIgniter\I18n\Time;
use DateTime;
use Exception;
/**
* Class DatetimeCast
*/
class DatetimeCast extends BaseCast
{
/**
* @inheritDoc
*
* @throws Exception
*/
public static function get($value, array $params = [])
{
if ($value instanceof Time)
{
return $value;
}
if ($value instanceof DateTime)
{
return Time::instance($value);
}
if (is_numeric($value))
{
return Time::createFromTimestamp($value);
}
if (is_string($value))
{
return Time::parse($value);
}
return $value;
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
/**
* This file is part of the CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CodeIgniter\Entity\Cast;
/**
* Class FloatCast
*/
class FloatCast extends BaseCast
{
/**
* @inheritDoc
*/
public static function get($value, array $params = []): float
{
return (float) $value;
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
/**
* This file is part of the CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CodeIgniter\Entity\Cast;
/**
* Class IntegerCast
*/
class IntegerCast extends BaseCast
{
/**
* @inheritDoc
*/
public static function get($value, array $params = []): int
{
return (int) $value;
}
}
+71
View File
@@ -0,0 +1,71 @@
<?php
/**
* This file is part of the CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CodeIgniter\Entity\Cast;
use CodeIgniter\Entity\Exceptions\CastException;
use JsonException;
use stdClass;
/**
* Class JsonCast
*/
class JsonCast extends BaseCast
{
/**
* @inheritDoc
*/
public static function get($value, array $params = [])
{
$associative = in_array('array', $params, true);
$tmp = ! is_null($value) ? ($associative ? [] : new stdClass) : null;
if (function_exists('json_decode')
&& ((is_string($value)
&& strlen($value) > 1
&& in_array($value[0], ['[', '{', '"'], true))
|| is_numeric($value)
)
)
{
try
{
$tmp = json_decode($value, $associative, 512, JSON_THROW_ON_ERROR);
}
catch (JsonException $e)
{
throw CastException::forInvalidJsonFormat($e->getCode());
}
}
return $tmp;
}
/**
* @inheritDoc
*/
public static function set($value, array $params = []): string
{
if (function_exists('json_encode'))
{
try
{
$value = json_encode($value, JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR);
}
catch (JsonException $e)
{
throw CastException::forInvalidJsonFormat($e->getCode());
}
}
return $value;
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
/**
* This file is part of the CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CodeIgniter\Entity\Cast;
/**
* Class ObjectCast
*/
class ObjectCast extends BaseCast
{
/**
* @inheritDoc
*/
public static function get($value, array $params = []): object
{
return (object) $value;
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
/**
* This file is part of the CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CodeIgniter\Entity\Cast;
/**
* Class StringCast
*/
class StringCast extends BaseCast
{
/**
* @inheritDoc
*/
public static function get($value, array $params = []): string
{
return (string) $value;
}
}
+35
View File
@@ -0,0 +1,35 @@
<?php
/**
* This file is part of the CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CodeIgniter\Entity\Cast;
use CodeIgniter\Entity\Exceptions\CastException;
/**
* Class TimestampCast
*/
class TimestampCast extends BaseCast
{
/**
* @inheritDoc
*/
public static function get($value, array $params = [])
{
$value = strtotime($value);
if ($value === false)
{
throw CastException::forInvalidTimestamp();
}
return $value;
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
/**
* This file is part of the CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CodeIgniter\Entity\Cast;
use CodeIgniter\HTTP\URI;
/**
* Class URICast
*/
class URICast extends BaseCast
{
/**
* @inheritDoc
*/
public static function get($value, array $params = []): URI
{
return $value instanceof URI ? $value : new URI($value);
}
}