Remove deprecated features

This commit is contained in:
Giuseppe Criscione 2020-12-16 22:08:07 +01:00
parent 29e1ea9366
commit 83d2b69169
14 changed files with 18 additions and 286 deletions

View File

@ -114,7 +114,7 @@ class Validator
}
try {
return date('Y-m-d', Date::toTimestamp($value, null, true));
return date('Y-m-d', Date::toTimestamp($value));
} catch (InvalidArgumentException $e) {
throw new ValidationException('Invalid value for field "' . $field->name() . '" of type "' . $field->type() . '":' . Str::after($e->getMessage(), ':'));
}

View File

@ -234,28 +234,6 @@ class User extends DataGetter
return $this->data['color-scheme'];
}
/**
* @inheritdoc
*
* @deprecated Access data directly from class methods
*/
public function get($key, $default = null)
{
trigger_error('Using ' . static::class . '::get() is deprecated since Formwork 1.10.0', E_USER_DEPRECATED);
return parent::get($key, $default);
}
/**
* @inheritdoc
*
* @deprecated
*/
public function has($key): bool
{
trigger_error('Using ' . static::class . '::has() is deprecated since Formwork 1.10.0', E_USER_DEPRECATED);
return parent::has($key);
}
public function __debugInfo(): array
{
$data = $this->data;

View File

@ -307,15 +307,9 @@ abstract class AbstractPage
/**
* Get page data by key
*
* @param string $key
* @param mixed $default Default value if key is not set
*/
public function get($key, $default = null)
public function get(string $key, $default = null)
{
if (!is_string($key)) {
trigger_error('Using ' . static::class . '::get() with a non-string $key argument is deprecated since Formwork 1.10.0', E_USER_DEPRECATED);
}
if (property_exists($this, $key)) {
// Call getter method if exists and property is null
if ($this->$key === null && method_exists($this, $key)) {
@ -326,37 +320,22 @@ abstract class AbstractPage
if (Arr::has($this->data, $key)) {
return Arr::get($this->data, $key, $default);
}
if (method_exists($this, $key)) {
trigger_error('Accessing non-getter methods from ' . static::class . '::get() is deprecated since Formwork 1.3.0, use $page->' . $key . '() instead', E_USER_DEPRECATED);
return $this->$key();
}
return $default;
}
/**
* Return whether page data has a key
*
* @param string $key
*/
public function has($key): bool
public function has(string $key): bool
{
if (!is_string($key)) {
trigger_error('Using ' . static::class . '::has() with a non-string $key argument is deprecated since Formwork 1.10.0', E_USER_DEPRECATED);
$key = (string) $key;
}
return property_exists($this, $key) || Arr::has($this->data, $key);
}
/**
* Set page data
*
* @param string $key
*/
public function set($key, $value): void
public function set(string $key, $value): void
{
if (!is_string($key)) {
trigger_error('Using ' . static::class . '::set() with a non-string $key argument is deprecated since Formwork 1.10.0', E_USER_DEPRECATED);
}
$this->data[$key] = $value;
}

View File

@ -264,17 +264,6 @@ class Page extends AbstractPage
return $this->filename === null;
}
/**
* Return page id
*
* @deprecated Use Page::name() instead
*/
public function id(): string
{
trigger_error(static::class . '::id() is deprecated since Formwork 1.11.0, use ' . static::class . '::name() instead', E_USER_DEPRECATED);
return $this->name();
}
/**
* @inheritdoc
*/
@ -419,21 +408,6 @@ class Page extends AbstractPage
$this->__construct($this->path);
}
/**
* Return a file path relative to Formwork root
*
* @param string $file Name of the file
*
* @return string|null File path or null if file is not found
*
* @deprecated Access files from Page::files()
*/
public function file(string $file): ?string
{
trigger_error(static::class . '::file() is deprecated since Formwork 1.4.0, access files from ' . static::class . '::files() instead', E_USER_DEPRECATED);
return $this->files()->has($file) ? Str::removeStart($this->files()->get($file)->path(), ROOT_PATH) : null;
}
/**
* Return a Files collection containing only images
*/

View File

@ -6,6 +6,7 @@ use Formwork\Data\Collection;
use Formwork\Utils\Arr;
use Formwork\Utils\FileSystem;
use Formwork\Utils\Str;
use InvalidArgumentException;
class PageCollection extends Collection
{
@ -116,9 +117,9 @@ class PageCollection extends Collection
/**
* Sort collection items
*
* @param int|string $direction Sorting direction (SORT_ASC or 1 for ascending order, SORT_DESC or -1 for descending)
* @param int $direction Sorting direction (SORT_ASC or 1 for ascending order, SORT_DESC or -1 for descending)
*/
public function sort(string $property = self::DEFAULT_SORT_PROPERTY, $direction = SORT_ASC): self
public function sort(string $property = self::DEFAULT_SORT_PROPERTY, int $direction = SORT_ASC): self
{
$pageCollection = clone $this;
@ -126,18 +127,12 @@ class PageCollection extends Collection
return $pageCollection;
}
if (is_string($direction)) {
trigger_error('Using ' . static::class . '::sort() with a string as $direction argument is deprecated since Formwork 1.11.0. Use SORT_ASC or 1 for ascending order, SORT_DESC or -1 for descending', E_USER_DEPRECATED);
$direction = strtolower($direction);
}
if ($direction === SORT_ASC || $direction === 'asc' || $direction === 1) {
if ($direction === SORT_ASC || $direction === 1) {
$direction = 1;
} elseif ($direction === SORT_DESC || $direction === 'desc' || $direction === -1) {
} elseif ($direction === SORT_DESC || $direction === -1) {
$direction = -1;
} else {
trigger_error('Using ' . static::class . '::sort() with an invalid $direction argument is deprecated Formwork 1.11.0. Use SORT_ASC or 1 for ascending order, SORT_DESC or -1 for descending', E_USER_DEPRECATED);
$direction = 1;
throw new InvalidArgumentException('Invalid sorting direction. Use SORT_ASC or 1 for ascending order, SORT_DESC or -1 for descending');
}
usort($pageCollection->items, static function (Page $item1, Page $item2) use ($property, $direction): int {

View File

@ -181,17 +181,6 @@ class Site extends AbstractPage
return $errorPage;
}
/**
* Get site language
*
* @deprecated Use Site::languages()->default() instead
*/
public function lang(): ?string
{
trigger_error(static::class . '::lang() is deprecated since Formwork 1.2.0, use ' . static::class . '::languages()->default() instead', E_USER_DEPRECATED);
return $this->languages()->default() ?? ($this->data['lang'] ?? 'en');
}
/**
* @inheritdoc
*/

View File

@ -8,8 +8,6 @@ class AssociativeCollection extends Collection
{
/**
* Get data by key returning a default value if key is not present
*
* @param mixed|null $default
*/
public function get(string $key, $default = null)
{
@ -18,15 +16,9 @@ class AssociativeCollection extends Collection
/**
* Return whether a key is present
*
* @param string $key
*/
public function has($key): bool
public function has(string $key): bool
{
if (!is_string($key)) {
trigger_error('Using ' . static::class . '::has() with a non-string $key argument is deprecated since Formwork 1.10.0', E_USER_DEPRECATED);
$key = (string) $key;
}
return Arr::has($this->items, $key);
}
}

View File

@ -23,34 +23,17 @@ class DataGetter
/**
* Get data by key returning a default value if key is not present
*
* @param string $key
* @param mixed|null $default
*/
public function get($key, $default = null)
public function get(string $key, $default = null)
{
if (!is_string($key)) {
trigger_error('Using ' . static::class . '::get() with a non-string $key argument is deprecated since Formwork 1.10.0', E_USER_DEPRECATED);
$key = (string) $key;
}
return Arr::get($this->data, $key, $default);
}
/**
* Return whether a key is present
*
* @param array|string $key
*/
public function has($key): bool
public function has(string $key): bool
{
if (is_array($key)) {
trigger_error('Using ' . static::class . '::has() with an array as $key argument is deprecated since Formwork 1.10.0, use ' . static::class . '::hasMultiple() instead', E_USER_DEPRECATED);
return $this->hasMultiple($key);
}
if (!is_string($key)) {
trigger_error('Using ' . static::class . '::has() with a non-string $key argument is deprecated since Formwork 1.10.0', E_USER_DEPRECATED);
$key = (string) $key;
}
return Arr::has($this->data, $key);
}

View File

@ -6,14 +6,9 @@ class DataSetter extends DataGetter
{
/**
* Set a data value by key
*
* @param string $key
*/
public function set($key, $value): void
public function set(string $key, $value): void
{
if (!is_string($key)) {
trigger_error('Using ' . static::class . '::set() with a non-string $key argument is deprecated since Formwork 1.10.0', E_USER_DEPRECATED);
}
$this->data[$key] = $value;
}

View File

@ -41,29 +41,6 @@ class Scheme extends DataGetter
if (!$this->has('title')) {
$this->data['title'] = $this->name;
}
if ($this->has('pages')) {
if ($this->data['pages'] === false) {
$this->data['children'] = false;
}
if (is_array($this->data['pages'])) {
$this->data['children']['templates'] = $this->data['pages'];
}
unset($this->data['pages']);
trigger_error('Property "pages" in page schemes is deprecated since Formwork 1.2.0, use "children" or "children.templates" instead', E_USER_DEPRECATED);
}
if ($this->has('reverse-children')) {
$this->data['children']['reverse'] = $this->data['reverse-children'];
unset($this->data['reverse-children']);
trigger_error('Property "reverse-children" in page schemes is deprecated since Formwork 1.2.0, use "children.reverse" instead', E_USER_DEPRECATED);
}
if ($this->has('sortable-children')) {
$this->data['children']['sortable'] = $this->data['sortable-children'];
unset($this->data['sortable-children']);
trigger_error('Property "sortable-children" in page schemes is deprecated since Formwork 1.2.0, use "children.sortable" instead', E_USER_DEPRECATED);
}
}
/**

View File

@ -11,10 +11,8 @@ class Date
{
/**
* Parse a date according to a given format (or the default format if not given) and return the timestamp
*
* @param $throwOnError Whether to throw an Exception when the method fails or trigger a deprecation error (@internal)
*/
public static function toTimestamp(string $date, string $format = null, bool $throwOnError = false): int
public static function toTimestamp(string $date, string $format = null): int
{
$isFormatGiven = $format !== null;
@ -31,12 +29,7 @@ class Date
try {
$dateTime = new DateTime($date);
} catch (Exception $e) {
$message = 'Invalid date "' . $date . '": ' . static::getLastDateTimeError();
// TODO: this will always be the case in 2.0
if ($throwOnError) {
throw new InvalidArgumentException($message, $e->getCode(), $e->getPrevious());
}
trigger_error('Using invalid dates is deprecated since Formwork 1.11.0. ' . $message, E_USER_DEPRECATED);
throw new InvalidArgumentException('Invalid date "' . $date . '": ' . static::getLastDateTimeError(), $e->getCode(), $e->getPrevious());
}
}

View File

@ -116,18 +116,6 @@ class FileSystem
return @file_exists($path);
}
/**
* Assert a file exists or not
*
* @deprecated Use FileSystem::assertExists() instead
*/
public static function assert(string $path): bool
{
trigger_error(static::class . '::assert() is deprecated since Formwork 1.11.0, use ' . static::class . '::assertExists() instead', E_USER_DEPRECATED);
static::assertExists($path);
return true;
}
/**
* Assert a file exists or not
*
@ -486,28 +474,6 @@ class FileSystem
throw new RuntimeException('Cannot create directory ' . $directory);
}
/**
* Alias of createFile method
*
* @deprecated Use FileSystem::createFile() instead
*/
public static function create(string $file): bool
{
trigger_error(static::class . '::create() is deprecated since Formwork 1.10.0, use ' . static::class . '::createFile() instead', E_USER_DEPRECATED);
return static::createFile($file);
}
/**
* Return a path with a single trailing slash
*
* @deprecated Use FileSystem::normalizePath($path . DS) instead
*/
public static function normalize(string $path): string
{
trigger_error(static::class . '::normalize($path) is deprecated since Formwork 1.10.0, use ' . static::class . '::normalizePath($path . DS) instead', E_USER_DEPRECATED);
return static::normalizePath($path . DS);
}
/**
* Normalize path slashes
*/
@ -524,53 +490,6 @@ class FileSystem
return Path::join($paths, DS);
}
/**
* Scan a path for files and directories
*
* @deprecated Use generator-based FileSystem::listContents() instead
*
* @param bool $all Whether to return only visible or all files
*/
public static function scan(string $path, bool $all = false): array
{
trigger_error(static::class . '::scan() is deprecated since Formwork 1.8.0, use ' . static::class . '::listContents() instead', E_USER_DEPRECATED);
static::assertExists($path);
if (!static::isDirectory($path)) {
throw new RuntimeException('Unable to list: ' . $path . ', specified path is not a directory');
}
$items = @scandir($path);
if (!is_array($items)) {
return [];
}
$items = array_diff($items, self::IGNORED_FILES);
if (!$all) {
$items = array_filter($items, [static::class, 'isVisible']);
}
return $items;
}
/**
* Recursively scan a path for files and directories
*
* @deprecated Use generator-based FileSystem::listRecursive() instead
*
* @param bool $all Whether to return only visible or all files
*/
public static function scanRecursive(string $path, bool $all = false): array
{
trigger_error(static::class . '::scanRecursive() is deprecated since Formwork 1.8.0, use ' . static::class . '::listRecursive() instead', E_USER_DEPRECATED);
$list = [];
$path = static::normalize($path);
foreach (FileSystem::scan($path, $all) as $item) {
if (FileSystem::isDirectory($path . $item)) {
$list = array_merge($list, static::scanRecursive($path . $item, $all));
} else {
$list[] = $path . $item;
}
}
return $list;
}
/**
* List files and directories contained in a path
*
@ -691,17 +610,6 @@ class FileSystem
return $prefix . bin2hex(random_bytes(8));
}
/**
* Generate a temporary file name
*
* @param string $prefix Optional file name prefix
*/
public static function temporaryName(string $prefix = ''): string
{
trigger_error(static::class . '::temporaryName() is deprecated since Formwork 1.11.0, use ' . static::class . '::randomName() instead', E_USER_DEPRECATED);
return static::randomName($prefix);
}
/**
* Return the message string of the last stream error
*/

View File

@ -168,18 +168,9 @@ class MimeType
/**
* Get the extension associated to a MIME type
*
* @param bool $mixedReturn Whether to return an array of results if multiple associated extensions are found
* (should be always false, since this possibility is deprecated from Formwork 1.11.0)
*
* @return array|string
*/
public static function toExtension(string $mimeType, bool $mixedReturn = true)
public static function toExtension(string $mimeType): ?string
{
if ($mixedReturn) {
trigger_error('The possibility to return an array or a string with ' . static::class . '::toExtension() is deprecated since Formwork 1.11.0, use ' . static::class . '::toExtension($mimeType, false) to disable this error and always get the first (preferred) associated extension as string', E_USER_DEPRECATED);
}
$results = static::getAssociatedExtensions($mimeType);
return count($results) > 1 && $mixedReturn ? $results : array_shift($results);
return static::getAssociatedExtensions($mimeType)[0] ?? null;
}
}

View File

@ -102,17 +102,6 @@ class Uri
return static::parseComponent($uri, PHP_URL_PATH);
}
/**
* Get the relative path of current or a given URI
*
* @deprecated Use Uri::path() instead
*/
public static function relativePath(string $uri = null): ?string
{
trigger_error(static::class . '::relativePath() is deprecated since Formwork 1.11.0, use ' . static::class . '::path() instead', E_USER_DEPRECATED);
return static::path($uri);
}
/**
* Get the absolute path of current or a given URI
*/
@ -271,17 +260,6 @@ class Uri
return static::make(['path' => Path::resolve($uriPath, $basePath)], $base);
}
/**
* Resolve a relative URI against current or a given base URI
*
* @deprecated Use Uri::resolveRelative() instead
*/
public static function resolveRelativeUri(string $uri, string $base = null): string
{
trigger_error(static::class . '::resolveRelativeUri() is deprecated since Formwork 1.11.0, use ' . static::class . '::resolveRelative() instead', E_USER_DEPRECATED);
return static::resolveRelative($uri, $base);
}
/**
* Parse URI component, throwing an exception when the URI is invalid
*/