소스 검색

For php >=8.x

Hi pico team! 🚀 I'm update core pico for php> = 8 but not tested it's very early project ;D In this month i think complete it  PicoLovers ❤️
David 4 년 전
부모
커밋
5b94b0fb6e
6개의 변경된 파일211개의 추가작업 그리고 214개의 파일을 삭제
  1. 1 1
      composer.json
  2. 19 19
      lib/AbstractPicoPlugin.php
  3. 143 150
      lib/Pico.php
  4. 10 10
      lib/PicoPluginInterface.php
  5. 37 33
      lib/PicoTwigExtension.php
  6. 1 1
      plugins/DummyPlugin.php

+ 1 - 1
composer.json

@@ -31,7 +31,7 @@
         "source": "https://github.com/picocms/Pico"
     },
     "require": {
-        "php": ">=7.0.8",
+        "php": ">=8.0",
         "ext-mbstring": "*",
         "twig/twig": "^2.12",
         "symfony/yaml" : "^3.4",

+ 19 - 19
lib/AbstractPicoPlugin.php

@@ -31,7 +31,7 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface
      * @see PicoPluginInterface::getPico()
      * @var Pico
      */
-    protected $pico;
+    protected Pico $pico;
 
     /**
      * Boolean indicating if this plugin is enabled (TRUE) or disabled (FALSE)
@@ -40,7 +40,7 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface
      * @see PicoPluginInterface::setEnabled()
      * @var bool|null
      */
-    protected $enabled;
+    protected ?bool $enabled;
 
     /**
      * Boolean indicating if this plugin was ever enabled/disabled manually
@@ -48,7 +48,7 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface
      * @see PicoPluginInterface::isStatusChanged()
      * @var bool
      */
-    protected $statusChanged = false;
+    protected bool $statusChanged = false;
 
     /**
      * Boolean indicating whether this plugin matches Pico's API version
@@ -56,7 +56,7 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface
      * @see AbstractPicoPlugin::checkCompatibility()
      * @var bool|null
      */
-    protected $nativePlugin;
+    protected ?bool $nativePlugin;
 
     /**
      * List of plugins which this plugin depends on
@@ -65,7 +65,7 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface
      * @see PicoPluginInterface::getDependencies()
      * @var string[]
      */
-    protected $dependsOn = array();
+    protected array $dependsOn = array();
 
     /**
      * List of plugin which depend on this plugin
@@ -74,7 +74,7 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface
      * @see PicoPluginInterface::getDependants()
      * @var object[]|null
      */
-    protected $dependants;
+    protected ?array $dependants;
 
     /**
      * Constructs a new instance of a Pico plugin
@@ -89,7 +89,7 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface
     /**
      * {@inheritDoc}
      */
-    public function handleEvent($eventName, array $params)
+    public function handleEvent(string $eventName, array $params)
     {
         // plugins can be enabled/disabled using the config
         if ($eventName === 'onConfigLoaded') {
@@ -132,10 +132,10 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface
     /**
      * {@inheritDoc}
      */
-    public function setEnabled($enabled, $recursive = true, $auto = false)
+    public function setEnabled(bool $enabled, bool $recursive = true, bool $auto = false)
     {
-        $this->statusChanged = (!$this->statusChanged) ? !$auto : true;
-        $this->enabled = (bool) $enabled;
+        $this->statusChanged = !(!$this->statusChanged) || !$auto;
+        $this->enabled = $enabled;
 
         if ($enabled) {
             $this->checkCompatibility();
@@ -148,7 +148,7 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface
     /**
      * {@inheritDoc}
      */
-    public function isEnabled()
+    public function isEnabled(): bool|null
     {
         return $this->enabled;
     }
@@ -156,7 +156,7 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface
     /**
      * {@inheritDoc}
      */
-    public function isStatusChanged()
+    public function isStatusChanged(): bool
     {
         return $this->statusChanged;
     }
@@ -164,7 +164,7 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface
     /**
      * {@inheritDoc}
      */
-    public function getPico()
+    public function getPico(): Pico
     {
         return $this->pico;
     }
@@ -262,21 +262,21 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface
     /**
      * {@inheritDoc}
      */
-    public function getDependencies()
+    public function getDependencies(): array
     {
-        return (array) $this->dependsOn;
+        return $this->dependsOn;
     }
 
     /**
      * Disables all plugins which depend on this plugin
      *
-     * @see PicoPluginInterface::getDependants()
-     *
      * @param bool $recursive disabled dependant plugins automatically
      *
      * @throws RuntimeException thrown when a dependency fails
+     * @see PicoPluginInterface::getDependants()
+     *
      */
-    protected function checkDependants($recursive)
+    protected function checkDependants(bool $recursive)
     {
         $dependants = $this->getDependants();
         if ($dependants) {
@@ -307,7 +307,7 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface
     /**
      * {@inheritDoc}
      */
-    public function getDependants()
+    public function getDependants(): array
     {
         if ($this->dependants === null) {
             $this->dependants = array();

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 143 - 150
lib/Pico.php


+ 10 - 10
lib/PicoPluginInterface.php

@@ -36,14 +36,11 @@ interface PicoPluginInterface
      * @param string $eventName name of the triggered event
      * @param array  $params    passed parameters
      */
-    public function handleEvent($eventName, array $params);
+    public function handleEvent(string $eventName, array $params);
 
     /**
      * Enables or disables this plugin
      *
-     * @see PicoPluginInterface::isEnabled()
-     * @see PicoPluginInterface::isStatusChanged()
-     *
      * @param bool $enabled   enable (TRUE) or disable (FALSE) this plugin
      * @param bool $recursive when TRUE, enable or disable recursively.
      *     In other words, if you enable a plugin, all required plugins are
@@ -55,8 +52,11 @@ interface PicoPluginInterface
      *     parameter is optional and defaults to FALSE.
      *
      * @throws RuntimeException thrown when a dependency fails
+     *@see PicoPluginInterface::isEnabled()
+     * @see PicoPluginInterface::isStatusChanged()
+     *
      */
-    public function setEnabled($enabled, $recursive = true, $auto = false);
+    public function setEnabled(bool $enabled, bool $recursive = true, bool $auto = false);
 
     /**
      * Returns a boolean indicating whether this plugin is enabled or not
@@ -69,7 +69,7 @@ interface PicoPluginInterface
      *
      * @return bool|null plugin is enabled (TRUE) or disabled (FALSE)
      */
-    public function isEnabled();
+    public function isEnabled(): ?bool;
 
     /**
      * Returns TRUE if the plugin was ever enabled/disabled manually
@@ -78,21 +78,21 @@ interface PicoPluginInterface
      *
      * @return bool plugin is in its default state (TRUE), FALSE otherwise
      */
-    public function isStatusChanged();
+    public function isStatusChanged(): bool;
 
     /**
      * Returns a list of names of plugins required by this plugin
      *
      * @return string[] required plugins
      */
-    public function getDependencies();
+    public function getDependencies(): array;
 
     /**
      * Returns a list of plugins which depend on this plugin
      *
      * @return object[] dependant plugins
      */
-    public function getDependants();
+    public function getDependants(): array;
 
     /**
      * Returns the plugin's instance of Pico
@@ -101,5 +101,5 @@ interface PicoPluginInterface
      *
      * @return Pico the plugin's instance of Pico
      */
-    public function getPico();
+    public function getPico(): Pico;
 }

+ 37 - 33
lib/PicoTwigExtension.php

@@ -10,6 +10,8 @@
  * License-Filename: LICENSE
  */
 
+use JetBrains\PhpStorm\ArrayShape;
+
 /**
  * Pico's Twig extension to implement additional filters
  *
@@ -26,7 +28,7 @@ class PicoTwigExtension extends Twig_Extension
      * @see PicoTwigExtension::getPico()
      * @var Pico
      */
-    private $pico;
+    private Pico $pico;
 
     /**
      * Constructs a new instance of this Twig extension
@@ -45,7 +47,7 @@ class PicoTwigExtension extends Twig_Extension
      *
      * @return Pico the extension's instance of Pico
      */
-    public function getPico()
+    public function getPico(): Pico
     {
         return $this->pico;
     }
@@ -57,7 +59,7 @@ class PicoTwigExtension extends Twig_Extension
      *
      * @return string the extension name
      */
-    public function getName()
+    public function getName(): string
     {
         return 'PicoTwigExtension';
     }
@@ -69,7 +71,8 @@ class PicoTwigExtension extends Twig_Extension
      *
      * @return Twig_SimpleFilter[] array of Pico's Twig filters
      */
-    public function getFilters()
+    #[ArrayShape(['markdown' => "\Twig_SimpleFilter", 'map' => "\Twig_SimpleFilter", 'sort_by' => "\Twig_SimpleFilter", 'link' => "\Twig_SimpleFilter", 'url' => "\Twig_SimpleFilter"])]
+    public function getFilters(): array
     {
         return array(
             'markdown' => new Twig_SimpleFilter(
@@ -91,7 +94,8 @@ class PicoTwigExtension extends Twig_Extension
      *
      * @return Twig_SimpleFunction[] array of Pico's Twig functions
      */
-    public function getFunctions()
+    #[ArrayShape(['url_param' => "\Twig_SimpleFunction", 'form_param' => "\Twig_SimpleFunction", 'pages' => "\Twig_SimpleFunction"])]
+    public function getFunctions(): array
     {
         return array(
             'url_param' => new Twig_SimpleFunction('url_param', array($this, 'urlParamFunction')),
@@ -108,16 +112,16 @@ class PicoTwigExtension extends Twig_Extension
      * Don't use it to parse the contents of a page, use the `content` filter
      * instead, what ensures the proper preparation of the contents.
      *
-     * @see Pico::substituteFileContent()
-     * @see Pico::parseFileContent()
-     *
      * @param string $markdown   markdown to parse
      * @param array  $meta       meta data to use for %meta.*% replacement
-     * @param bool   $singleLine whether to parse just a single line of markup
+     * @param bool $singleLine whether to parse just a single line of markup
      *
      * @return string parsed HTML
+     * @see Pico::substituteFileContent()
+     * @see Pico::parseFileContent()
+     *
      */
-    public function markdownFilter($markdown, array $meta = array(), $singleLine = false)
+    public function markdownFilter(string $markdown, array $meta = array(), bool $singleLine = false): string
     {
         $markdown = $this->getPico()->substituteFileContent($markdown, $meta);
         return $this->getPico()->parseFileContent($markdown, $singleLine);
@@ -129,7 +133,7 @@ class PicoTwigExtension extends Twig_Extension
      * This method is registered as the Twig `map` filter. You can use this
      * filter to e.g. get all page titles (`{{ pages|map("title") }}`).
      *
-     * @param array|Traversable $var        variable to map
+     * @param Traversable|array $var        variable to map
      * @param mixed             $mapKeyPath key to map; either a scalar or a
      *     array interpreted as key path (i.e. ['foo', 'bar'] will return all
      *     $item['foo']['bar'] values)
@@ -138,7 +142,7 @@ class PicoTwigExtension extends Twig_Extension
      *
      * @throws Twig_Error_Runtime
      */
-    public function mapFilter($var, $mapKeyPath)
+    public function mapFilter(Traversable|array $var, mixed $mapKeyPath): array
     {
         if (!is_array($var) && (!is_object($var) || !($var instanceof Traversable))) {
             throw new Twig_Error_Runtime(sprintf(
@@ -166,11 +170,11 @@ class PicoTwigExtension extends Twig_Extension
      * always sorted in ascending order, apply Twigs `reverse` filter to
      * achieve a descending order.
      *
-     * @param array|Traversable $var         variable to sort
+     * @param Traversable|array $var         variable to sort
      * @param mixed             $sortKeyPath key to use for sorting; either
      *     a scalar or a array interpreted as key path (i.e. ['foo', 'bar']
      *     will sort $var by $item['foo']['bar'])
-     * @param string            $fallback    specify what to do with items
+     * @param string $fallback    specify what to do with items
      *     which don't contain the specified sort key; use "bottom" (default)
      *     to move these items to the end of the sorted array, "top" to rank
      *     them first, "keep" to keep the original order, or "remove" to remove
@@ -180,7 +184,7 @@ class PicoTwigExtension extends Twig_Extension
      *
      * @throws Twig_Error_Runtime
      */
-    public function sortByFilter($var, $sortKeyPath, $fallback = 'bottom')
+    public function sortByFilter(Traversable|array $var, mixed $sortKeyPath, string $fallback = 'bottom'): Traversable|array
     {
         if (is_object($var) && ($var instanceof Traversable)) {
             $var = iterator_to_array($var, true);
@@ -243,7 +247,7 @@ class PicoTwigExtension extends Twig_Extension
      * Returns the value of a variable item specified by a scalar key or a
      * arbitrary deep sub-key using a key path
      *
-     * @param array|Traversable|ArrayAccess|object $var     base variable
+     * @param Traversable|ArrayAccess|array $var     base variable
      * @param mixed                                $keyPath scalar key or a
      *     array interpreted as key path (when passing e.g. ['foo', 'bar'],
      *     the method will return $var['foo']['bar']) specifying the value
@@ -251,7 +255,7 @@ class PicoTwigExtension extends Twig_Extension
      * @return mixed the requested value or NULL when the given key or key path
      *     didn't match
      */
-    public static function getKeyOfVar($var, $keyPath)
+    public static function getKeyOfVar(Traversable|ArrayAccess|array $var, mixed $keyPath): mixed
     {
         if (!$keyPath) {
             return null;
@@ -298,21 +302,21 @@ class PicoTwigExtension extends Twig_Extension
      *
      * The Twig function disallows the use of the `callback` filter.
      *
-     * @see Pico::getUrlParameter()
-     *
      * @param string                    $name    name of the URL GET parameter
      *     to filter
-     * @param int|string                $filter  the filter to apply
-     * @param mixed|array               $options either a associative options
+     * @param int|string $filter  the filter to apply
+     * @param mixed|null $options either a associative options
      *     array to be used by the filter or a scalar default value
-     * @param int|string|int[]|string[] $flags   flags and flag strings to be
+     * @param int|string|int[]|string[]|null $flags   flags and flag strings to be
      *     used by the filter
      *
      * @return mixed either the filtered data, FALSE if the filter fails, or
      *     NULL if the URL GET parameter doesn't exist and no default value is
      *     given
+     *@see Pico::getUrlParameter()
+     *
      */
-    public function urlParamFunction($name, $filter = '', $options = null, $flags = null)
+    public function urlParamFunction(string $name, int|string $filter = '', mixed $options = null, array|int|string $flags = null): mixed
     {
         $filter = $filter ? (is_string($filter) ? filter_id($filter) : (int) $filter) : false;
         if (!$filter || ($filter === FILTER_CALLBACK)) {
@@ -327,21 +331,21 @@ class PicoTwigExtension extends Twig_Extension
      *
      * The Twig function disallows the use of the `callback` filter.
      *
-     * @see Pico::getFormParameter()
-     *
      * @param string                    $name    name of the HTTP POST
      *     parameter to filter
-     * @param int|string                $filter  the filter to apply
-     * @param mixed|array               $options either a associative options
+     * @param int|string $filter  the filter to apply
+     * @param mixed|null $options either a associative options
      *     array to be used by the filter or a scalar default value
-     * @param int|string|int[]|string[] $flags   flags and flag strings to be
+     * @param int|string|int[]|string[]|null $flags   flags and flag strings to be
      *     used by the filter
      *
      * @return mixed either the filtered data, FALSE if the filter fails, or
      *     NULL if the HTTP POST parameter doesn't exist and no default value
      *     is given
+     *@see Pico::getFormParameter()
+     *
      */
-    public function formParamFunction($name, $filter = '', $options = null, $flags = null)
+    public function formParamFunction(string $name, int|string $filter = '', mixed $options = null, array|int|string $flags = null): mixed
     {
         $filter = $filter ? (is_string($filter) ? filter_id($filter) : (int) $filter) : false;
         if (!$filter || ($filter === FILTER_CALLBACK)) {
@@ -411,19 +415,19 @@ class PicoTwigExtension extends Twig_Extension
      * this together with `$offset = -1` is equivalent to `$start = ""` and
      * `$offset = 0`.
      *
-     * @param string   $start       name of the node to start from
+     * @param string $start       name of the node to start from
      * @param int|null $depth       return pages until the given maximum depth;
      *     pass NULL to return all descendant pages; defaults to 0
-     * @param int      $depthOffset start returning pages from the given
+     * @param int $depthOffset start returning pages from the given
      *     minimum depth; defaults to 0
-     * @param int      $offset      ascend (positive) or descend (negative) the
+     * @param int $offset      ascend (positive) or descend (negative) the
      *     given number of branches before returning pages; defaults to 1
      *
      * @return array[] the data of the matched pages
      *
      * @throws Twig_Error_Runtime
      */
-    public function pagesFunction($start = '', $depth = 0, $depthOffset = 0, $offset = 1)
+    public function pagesFunction(string $start = '', ?int $depth = 0, int $depthOffset = 0, int $offset = 1): array
     {
         $start = (string) $start;
         if (basename($start) === 'index') {

+ 1 - 1
plugins/DummyPlugin.php

@@ -55,7 +55,7 @@ class DummyPlugin extends AbstractPicoPlugin
      * @see AbstractPicoPlugin::$enabled
      * @var bool|null
      */
-    protected $enabled = false;
+    protected ?bool $enabled = false;
 
     /**
      * This plugin depends on ...

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.