From 081565c5a66d4e3af790f6b315686298ea4a9f16 Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Wed, 26 Jul 2023 12:50:59 -0400 Subject: [PATCH] updating stubs for 5.2.3 --- src/Cache/Adapter/Weak.php | 20 +++ src/Config/Adapter/Json.php | 14 +- src/DataMapper/Pdo/Profiler/Profiler.php | 18 +- src/Di/Injectable.php | 3 +- src/Encryption/Security/JWT/Builder.php | 22 +-- src/Encryption/Security/JWT/Token/Parser.php | 25 +-- src/Http/Request.php | 1 + src/Http/Response.php | 26 ++- src/Mvc/Model/MetaData.php | 9 + src/Mvc/Model/Row.php | 2 +- src/Mvc/View.php | 1 + src/Storage/Adapter/Stream.php | 12 ++ src/Storage/Adapter/Weak.php | 164 +++++++++++++++++++ src/Storage/Serializer/Json.php | 44 +++-- src/Support/Debug/Dump.php | 18 +- src/Support/Helper/Json/Decode.php | 11 +- src/Support/Helper/Json/Encode.php | 14 +- 17 files changed, 294 insertions(+), 110 deletions(-) create mode 100644 src/Cache/Adapter/Weak.php create mode 100644 src/Storage/Adapter/Weak.php diff --git a/src/Cache/Adapter/Weak.php b/src/Cache/Adapter/Weak.php new file mode 100644 index 00000000..e429aafb --- /dev/null +++ b/src/Cache/Adapter/Weak.php @@ -0,0 +1,20 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ +namespace Phalcon\Cache\Adapter; + +use Phalcon\Cache\Adapter\AdapterInterface as CacheAdapterInterface; +use Phalcon\Storage\Adapter\Weak as StorageWeak; + +/** + * WeakCache implementation based on WeakReference + */ +class Weak extends \Phalcon\Storage\Adapter\Weak implements CacheAdapterInterface +{ +} diff --git a/src/Config/Adapter/Json.php b/src/Config/Adapter/Json.php index a06d5804..08314f13 100644 --- a/src/Config/Adapter/Json.php +++ b/src/Config/Adapter/Json.php @@ -9,8 +9,8 @@ */ namespace Phalcon\Config\Adapter; -use InvalidArgumentException; use Phalcon\Config\Config; +use Phalcon\Support\Helper\Json\Decode; /** * Reads JSON files and converts them to Phalcon\Config\Config objects. @@ -42,16 +42,4 @@ class Json extends Config public function __construct(string $filePath) { } - - /** - * @todo This will be removed when traits are introduced - * @param string $data - * @param bool $associative - * @param int $depth - * @param int $options - * @return mixed - */ - private function decode(string $data, bool $associative = false, int $depth = 512, int $options = 0) - { - } } diff --git a/src/DataMapper/Pdo/Profiler/Profiler.php b/src/DataMapper/Pdo/Profiler/Profiler.php index 4eecdf30..109493b7 100644 --- a/src/DataMapper/Pdo/Profiler/Profiler.php +++ b/src/DataMapper/Pdo/Profiler/Profiler.php @@ -9,10 +9,10 @@ */ namespace Phalcon\DataMapper\Pdo\Profiler; -use InvalidArgumentException; use Phalcon\DataMapper\Pdo\Exception\Exception; use Phalcon\Logger\Enum; use Phalcon\Logger\LoggerInterface; +use Phalcon\Support\Helper\Json\Encode; /** * Sends query profiles to a logger. @@ -44,6 +44,11 @@ class Profiler implements \Phalcon\DataMapper\Pdo\Profiler\ProfilerInterface */ protected $logger; + /** + * @var Encode + */ + private $encode; + /** * Constructor. * @@ -142,15 +147,4 @@ public function setLogLevel(string $logLevel): ProfilerInterface public function start(string $method): void { } - - /** - * @todo This will be removed when traits are introduced - * @param mixed $data - * @param int $options - * @param int $depth - * @return string - */ - private function encode($data, int $options = 0, int $depth = 512): string - { - } } diff --git a/src/Di/Injectable.php b/src/Di/Injectable.php index 6b982807..1d60e5a2 100644 --- a/src/Di/Injectable.php +++ b/src/Di/Injectable.php @@ -9,6 +9,7 @@ */ namespace Phalcon\Di; +use stdClass; use Phalcon\Di\Di; use Phalcon\Session\BagInterface; @@ -41,7 +42,7 @@ * @property \Phalcon\Session\Bag|\Phalcon\Session\BagInterface $persistent * @property \Phalcon\Mvc\View|\Phalcon\Mvc\ViewInterface $view */ -abstract class Injectable implements \Phalcon\Di\InjectionAwareInterface +abstract class Injectable extends stdClass implements \Phalcon\Di\InjectionAwareInterface { /** * Dependency Injector diff --git a/src/Encryption/Security/JWT/Builder.php b/src/Encryption/Security/JWT/Builder.php index 560995de..12423772 100644 --- a/src/Encryption/Security/JWT/Builder.php +++ b/src/Encryption/Security/JWT/Builder.php @@ -9,15 +9,15 @@ */ namespace Phalcon\Encryption\Security\JWT; -use InvalidArgumentException; -use Phalcon\Support\Collection; -use Phalcon\Support\Collection\CollectionInterface; use Phalcon\Encryption\Security\JWT\Exceptions\ValidatorException; use Phalcon\Encryption\Security\JWT\Signer\SignerInterface; use Phalcon\Encryption\Security\JWT\Token\Enum; use Phalcon\Encryption\Security\JWT\Token\Item; use Phalcon\Encryption\Security\JWT\Token\Signature; use Phalcon\Encryption\Security\JWT\Token\Token; +use Phalcon\Support\Collection; +use Phalcon\Support\Collection\CollectionInterface; +use Phalcon\Support\Helper\Json\Encode; /** * JWT Builder @@ -31,6 +31,11 @@ class Builder */ private $claims; + /** + * @var Encode + */ + private $encode; + /** * @var CollectionInterface */ @@ -321,15 +326,4 @@ protected function setClaim(string $name, $value): Builder private function encodeUrl(string $input): string { } - - /** - * @todo This will be removed when traits are introduced - * @param mixed $data - * @param int $options - * @param int $depth - * @return string - */ - private function encode($data, int $options = 0, int $depth = 512): string - { - } } diff --git a/src/Encryption/Security/JWT/Token/Parser.php b/src/Encryption/Security/JWT/Token/Parser.php index cd609636..b19e59ed 100644 --- a/src/Encryption/Security/JWT/Token/Parser.php +++ b/src/Encryption/Security/JWT/Token/Parser.php @@ -10,6 +10,7 @@ namespace Phalcon\Encryption\Security\JWT\Token; use InvalidArgumentException; +use Phalcon\Support\Helper\Json\Decode; /** * Token Parser class. @@ -20,6 +21,18 @@ */ class Parser { + /** + * @var Decode + */ + private $decode; + + /** + * @param \Phalcon\Support\Helper\Json\Decode $decode + */ + public function __construct(\Phalcon\Support\Helper\Json\Decode $decode = null) + { + } + /** * Parse a token and return it * @@ -76,18 +89,6 @@ private function parseToken(string $token): array { } - /** - * @todo This will be removed when traits are introduced - * @param string $data - * @param bool $associative - * @param int $depth - * @param int $options - * @return mixed - */ - private function decode(string $data, bool $associative = false, int $depth = 512, int $options = 0) - { - } - /** * @todo This will be removed when traits are introduced * @param string $input diff --git a/src/Http/Request.php b/src/Http/Request.php index a30d203c..f9ce7096 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -17,6 +17,7 @@ use Phalcon\Http\Request\File; use Phalcon\Http\Request\FileInterface; use Phalcon\Http\Request\Exception; +use Phalcon\Support\Helper\Json\Decode; use UnexpectedValueException; use stdClass; diff --git a/src/Http/Response.php b/src/Http/Response.php index 592966a5..8d9113b7 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -11,19 +11,19 @@ use DateTime; use DateTimeZone; -use InvalidArgumentException; use Phalcon\Di\Di; use Phalcon\Di\DiInterface; +use Phalcon\Di\InjectionAwareInterface; +use Phalcon\Events\EventsAwareInterface; +use Phalcon\Events\ManagerInterface; use Phalcon\Http\Message\ResponseStatusCodeInterface; +use Phalcon\Http\Response\CookiesInterface; use Phalcon\Http\Response\Exception; use Phalcon\Http\Response\HeadersInterface; -use Phalcon\Http\Response\CookiesInterface; use Phalcon\Mvc\Url\UrlInterface; use Phalcon\Mvc\ViewInterface; use Phalcon\Http\Response\Headers; -use Phalcon\Di\InjectionAwareInterface; -use Phalcon\Events\EventsAwareInterface; -use Phalcon\Events\ManagerInterface; +use Phalcon\Support\Helper\Json\Encode; /** * Part of the HTTP cycle is return responses to the clients. @@ -81,6 +81,11 @@ class Response implements \Phalcon\Http\ResponseInterface, \Phalcon\Di\Injection */ protected $statusCodes = []; + /** + * @var Encode + */ + private $encode; + /** * Phalcon\Http\Response constructor * @@ -517,15 +522,4 @@ public function setRawHeader(string $header): ResponseInterface private function getBasename(string $uri, $suffix = null): string { } - - /** - * @todo This will be removed when traits are introduced - * @param mixed $data - * @param int $options - * @param int $depth - * @return string - */ - private function encode($data, int $options = 0, int $depth = 512): string - { - } } diff --git a/src/Mvc/Model/MetaData.php b/src/Mvc/Model/MetaData.php index 65d7707d..a69b669f 100644 --- a/src/Mvc/Model/MetaData.php +++ b/src/Mvc/Model/MetaData.php @@ -95,6 +95,15 @@ abstract class MetaData implements \Phalcon\Di\InjectionAwareInterface, \Phalcon */ protected $strategy = null; + /** + * Return the internal cache adapter + * + * @return CacheAdapterInterface|null + */ + public function getAdapter(): ?CacheAdapterInterface + { + } + /** * Returns table attributes names (fields) * diff --git a/src/Mvc/Model/Row.php b/src/Mvc/Model/Row.php index b65161d7..86e60957 100644 --- a/src/Mvc/Model/Row.php +++ b/src/Mvc/Model/Row.php @@ -18,7 +18,7 @@ * This component allows Phalcon\Mvc\Model to return rows without an associated entity. * This objects implements the ArrayAccess interface to allow access the object as object->x or array[x]. */ -class Row implements \Phalcon\Mvc\EntityInterface, \Phalcon\Mvc\Model\ResultInterface, \ArrayAccess, \JsonSerializable +class Row extends \stdClass implements \Phalcon\Mvc\EntityInterface, \Phalcon\Mvc\Model\ResultInterface, \ArrayAccess, \JsonSerializable { /** * Serializes the object for json_encode diff --git a/src/Mvc/View.php b/src/Mvc/View.php index e7a3e75c..99f0bd3c 100644 --- a/src/Mvc/View.php +++ b/src/Mvc/View.php @@ -486,6 +486,7 @@ public function getRender(string $controllerName, string $actionName, array $par /** * Returns a parameter previously set in the view * + * @return mixed|null * @param string $key */ public function getVar(string $key) diff --git a/src/Storage/Adapter/Stream.php b/src/Storage/Adapter/Stream.php index 05616436..edb4c38f 100644 --- a/src/Storage/Adapter/Stream.php +++ b/src/Storage/Adapter/Stream.php @@ -184,6 +184,18 @@ private function getFilepath(string $key): string { } + /** + * Check if the key has the prefix and remove it, otherwise just return the + * key unaltered + * + * @param string $key + * + * @return string + */ + private function getKeyWithoutPrefix(string $key): string + { + } + /** * Returns an iterator for the directory contents * diff --git a/src/Storage/Adapter/Weak.php b/src/Storage/Adapter/Weak.php new file mode 100644 index 00000000..53df27db --- /dev/null +++ b/src/Storage/Adapter/Weak.php @@ -0,0 +1,164 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ +namespace Phalcon\Storage\Adapter; + +use DateInterval; +use Exception as BaseException; +use Phalcon\Storage\SerializerFactory; +use Phalcon\Support\Exception as SupportException; +use Phalcon\Storage\Serializer\SerializerInterface; + +/** + * Weak Adapter + */ +class Weak extends \Phalcon\Storage\Adapter\AbstractAdapter +{ + /** + * @var int|null + */ + protected $fetching = null; + + /** + * @var array + */ + protected $weakList = []; + + /** + * @var array + */ + protected $options = []; + + /** + * Constructor, there are no options + * + * @param array $options = [] + * @throws SupportException + * @param \Phalcon\Storage\SerializerFactory $factory + */ + public function __construct(\Phalcon\Storage\SerializerFactory $factory, array $options = []) + { + } + + /** + * Flushes/clears the cache + * + * @return bool + */ + public function clear(): bool + { + } + + /** + * Decrements a stored number + * + * @param string $key + * @param int $value + * + * @return bool|int + */ + public function decrement(string $key, int $value = 1) + { + } + + /** + * Deletes data from the adapter + * + * @param string $key + * + * @return bool + */ + public function delete(string $key): bool + { + } + + /** + * Stores data in the adapter + * + * @param string $prefix + * + * @return array + */ + public function getKeys(string $prefix = ''): array + { + } + + /** + * Increments a stored number + * + * @param string $key + * @param int $value + * + * @return bool|int + */ + public function increment(string $key, int $value = 1) + { + } + + /** + * Reads data from the adapter + * + * @param string $key + * @param mixed|null $defaultValue * + * @return mixed + */ + public function get(string $key, $defaultValue = null) + { + } + + /** + * Checks if an element exists in the cache + * + * @param string $key * + * @return bool + */ + public function has(string $key): bool + { + } + + /** + * Stores data in the adapter. If the TTL is `null` (default) or not defined + * then the default TTL will be used, as set in this adapter. If the TTL + * is `0` or a negative number, a `delete()` will be issued, since this + * item has expired. If you need to set this key forever, you should use + * the `setForever()` method. + * + * @param string $key + * @param mixed $value + * @param DateInterval|int|null $ttl + * + * @return bool + * @throws BaseException + */ + public function set(string $key, $value, $ttl = null): bool + { + } + + /** + * For compatiblity only, there is no Forever with WeakReference. + * + * @param string $key + * @param mixed $value + * + * @return bool + */ + public function setForever(string $key, $value): bool + { + } + + /** + * will never set a serializer, WeakReference cannot be serialized + * + * @param string $serializer + * @return void + */ + public function setDefaultSerializer(string $serializer): void + { + } +} diff --git a/src/Storage/Serializer/Json.php b/src/Storage/Serializer/Json.php index 9b94aa1b..38f95870 100644 --- a/src/Storage/Serializer/Json.php +++ b/src/Storage/Serializer/Json.php @@ -11,6 +11,8 @@ use InvalidArgumentException; use JsonSerializable; +use Phalcon\Support\Helper\Json\Decode; +use Phalcon\Support\Helper\Json\Encode; /** * This file is part of the Phalcon Framework. @@ -23,45 +25,41 @@ class Json extends \Phalcon\Storage\Serializer\AbstractSerializer { /** - * Serializes data - * - * @return JsonSerializable|mixed|string + * @var Decode */ - public function serialize() - { - } + private $decode; /** - * Unserializes data - * - * @param mixed $data + * @var Encode + */ + private $encode; + + /** + * AbstractSerializer constructor. * - * @return void + * @param mixed|null $data */ - public function unserialize($data): void + public function __construct($data = null) { } /** - * @todo Remove this when we get traits - * @param string $data - * @param bool $associative - * @param int $depth - * @param int $options - * @return mixed + * Serializes data + * + * @return JsonSerializable|mixed|string */ - private function getDecode(string $data, bool $associative = false, int $depth = 512, int $options = 0) + public function serialize() { } /** - * @todo Remove this when we get traits + * Unserializes data + * * @param mixed $data - * @param int $options - * @param int $depth - * @return string + * + * @return void */ - private function getEncode($data, int $options = 0, int $depth = 512): string + public function unserialize($data): void { } } diff --git a/src/Support/Debug/Dump.php b/src/Support/Debug/Dump.php index 7fc39116..48ed8d2a 100644 --- a/src/Support/Debug/Dump.php +++ b/src/Support/Debug/Dump.php @@ -9,8 +9,8 @@ */ namespace Phalcon\Support\Debug; -use InvalidArgumentException; use Phalcon\Di\Di; +use Phalcon\Support\Helper\Json\Encode; use Reflection; use ReflectionClass; use ReflectionProperty; @@ -50,6 +50,11 @@ class Dump */ protected $styles = []; + /** + * @var Encode + */ + private $encode; + /** * Phalcon\Debug\Dump constructor * @@ -182,15 +187,4 @@ protected function getStyle(string $type): string protected function output($variable, string $name = null, int $tab = 1): string { } - - /** - * @todo This will be removed when traits are introduced - * @param mixed $data - * @param int $options - * @param int $depth - * @return string - */ - private function encode($data, int $options = 0, int $depth = 512): string - { - } } diff --git a/src/Support/Helper/Json/Decode.php b/src/Support/Helper/Json/Decode.php index d44c484b..2fb9fcd4 100644 --- a/src/Support/Helper/Json/Decode.php +++ b/src/Support/Helper/Json/Decode.php @@ -14,6 +14,15 @@ /** * Decodes a string using `json_decode` and throws an exception if the * JSON data cannot be decoded + * + * The following options are used if none specified for json_encode + * + * JSON_HEX_TAG, JSON_HEX_APOS, JSON_HEX_AMP, JSON_HEX_QUOT, + * JSON_UNESCAPED_SLASHES + * + * If JSON_THROW_ON_ERROR is defined in the options a JsonException will be + * thrown in the case of an error. Otherwise, any error will throw + * InvalidArgumentException */ class Decode { @@ -28,7 +37,7 @@ class Decode * @throws InvalidArgumentException if the JSON cannot be decoded. * @link https://www.php.net/manual/en/function.json-decode.php */ - public function __invoke(string $data, bool $associative = false, int $depth = 512, int $options = 0) + public function __invoke(string $data, bool $associative = false, int $depth = 512, int $options = 79) { } } diff --git a/src/Support/Helper/Json/Encode.php b/src/Support/Helper/Json/Encode.php index c7b1a26d..f14899fb 100644 --- a/src/Support/Helper/Json/Encode.php +++ b/src/Support/Helper/Json/Encode.php @@ -9,7 +9,7 @@ */ namespace Phalcon\Support\Helper\Json; -use JsonException; +use InvalidArgumentException; /** * Encodes a string using `json_encode` and throws an exception if the @@ -18,7 +18,11 @@ * The following options are used if none specified for json_encode * * JSON_HEX_TAG, JSON_HEX_APOS, JSON_HEX_AMP, JSON_HEX_QUOT, - * JSON_UNESCAPED_SLASHES, JSON_THROW_ON_ERROR + * JSON_UNESCAPED_SLASHES + * + * If JSON_THROW_ON_ERROR is defined in the options a JsonException will be + * thrown in the case of an error. Otherwise, any error will throw + * InvalidArgumentException * * @see https://www.ietf.org/rfc/rfc4627.txt */ @@ -26,15 +30,15 @@ class Encode { /** * @param mixed $data JSON data to parse - * @param int $options Bitmask of JSON decode options. + * @param int $options Bitmask of JSON encode options. * @param int $depth Recursion depth. * * @return string * - * @throws JsonException if the JSON cannot be encoded. + * @throws InvalidArgumentException if the JSON cannot be encoded. * @link https://www.php.net/manual/en/function.json-encode.php */ - public function __invoke($data, int $options = 4194383, int $depth = 512): string + public function __invoke($data, int $options = 79, int $depth = 512): string { } }