From ee64e114f21bca18844f402fc22dfac893883cc1 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 31 Dec 2021 09:19:09 -0500 Subject: [PATCH] =?UTF-8?q?Add=20=E2=80=9C#[\ReturnTypeWillChange]?= =?UTF-8?q?=E2=80=9D=20comments=20to=20all=20InteratorAggregate,=20Countab?= =?UTF-8?q?le=20and=20PDOStatement=20interface=20classes=20to=20stop=20PHP?= =?UTF-8?q?=208.1=20notices=20per=20https://php.watch/versions/8.1/interna?= =?UTF-8?q?l-method-return-types=20and=20processwire/processwire-issues#14?= =?UTF-8?q?67=20...=20someday=20when=20all=20PHP=205.x=20support=20can=20b?= =?UTF-8?q?e=20dropped=20these=20will=20be=20converted=20to=20PHP=207.1+?= =?UTF-8?q?=20return=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wire/core/Fieldtypes.php | 1 + wire/core/FilenameArray.php | 2 ++ wire/core/Fuel.php | 1 + wire/core/InputfieldWrapper.php | 2 ++ wire/core/Page.php | 2 ++ wire/core/PageArray.php | 1 + wire/core/PageTraversal.php | 2 +- wire/core/PageimageVariations.php | 25 ++++++++++++++++--- wire/core/PagesPathFinder.php | 3 ++- wire/core/PagesType.php | 1 + wire/core/Permissions.php | 1 + wire/core/Session.php | 23 ++++++++++++----- wire/core/WireArray.php | 7 ++++++ wire/core/WireData.php | 6 ++++- wire/core/WireDataDB.php | 4 ++- wire/core/WireDatabasePDO.php | 1 + wire/core/WireDatabasePDOStatement.php | 2 ++ wire/core/WireInputData.php | 6 +++++ wire/core/WireInputDataCookie.php | 1 + wire/core/WireSaveableItems.php | 1 + wire/modules/LanguageSupport/Languages.php | 1 + .../LanguagesPageFieldValue.php | 1 + .../Markup/MarkupPagerNav/PagerNav.php | 1 + 23 files changed, 82 insertions(+), 13 deletions(-) diff --git a/wire/core/Fieldtypes.php b/wire/core/Fieldtypes.php index f019004b..4ab471c0 100644 --- a/wire/core/Fieldtypes.php +++ b/wire/core/Fieldtypes.php @@ -224,6 +224,7 @@ class Fieldtypes extends WireArray { protected function filterData($selectors, $not = false) { $this->preload(); return parent::filterData($selectors, $not); } public function makeCopy() { $this->preload(); return parent::makeCopy(); } public function makeNew() { $this->preload(); return parent::makeNew(); } + #[\ReturnTypeWillChange] public function getIterator() { $this->preload(); return parent::getIterator(); } public function getNext($item, $strict = true) { $this->preload(); return parent::getNext($item, $strict); } public function getPrev($item, $strict = true) { $this->preload(); return parent::getPrev($item, $strict); } diff --git a/wire/core/FilenameArray.php b/wire/core/FilenameArray.php index a5c156e9..e7b650ac 100644 --- a/wire/core/FilenameArray.php +++ b/wire/core/FilenameArray.php @@ -81,6 +81,7 @@ class FilenameArray implements \IteratorAggregate, \Countable { * @return \ArrayObject * */ + #[\ReturnTypeWillChange] public function getIterator() { return new \ArrayObject($this->data); } @@ -138,6 +139,7 @@ class FilenameArray implements \IteratorAggregate, \Countable { * @return int * */ + #[\ReturnTypeWillChange] public function count() { return count($this->data); } diff --git a/wire/core/Fuel.php b/wire/core/Fuel.php index af24a769..31084a68 100644 --- a/wire/core/Fuel.php +++ b/wire/core/Fuel.php @@ -130,6 +130,7 @@ class Fuel implements \IteratorAggregate { return isset($this->data[$key]) ? $this->data[$key] : null; } + #[\ReturnTypeWillChange] public function getIterator() { return new \ArrayObject($this->data); } diff --git a/wire/core/InputfieldWrapper.php b/wire/core/InputfieldWrapper.php index bc7aa117..829eca01 100644 --- a/wire/core/InputfieldWrapper.php +++ b/wire/core/InputfieldWrapper.php @@ -1372,6 +1372,7 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre * @return InputfieldsArray * */ + #[\ReturnTypeWillChange] public function getIterator() { return $this->children(); } @@ -1384,6 +1385,7 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre * @return int * */ + #[\ReturnTypeWillChange] public function count() { return count($this->children()); } diff --git a/wire/core/Page.php b/wire/core/Page.php index 31f898fd..077d8f25 100644 --- a/wire/core/Page.php +++ b/wire/core/Page.php @@ -2922,6 +2922,7 @@ class Page extends WireData implements \Countable, WireMatchable { * @see Page::hasChildren(), Page::numChildren() * */ + #[\ReturnTypeWillChange] public function count() { if($this->outputFormatting) return $this->numChildren(true); return $this->numChildren(false); @@ -2945,6 +2946,7 @@ class Page extends WireData implements \Countable, WireMatchable { * @return \ArrayObject * */ + #[\ReturnTypeWillChange] public function getIterator() { $a = $this->settings; $template = $this->template(); diff --git a/wire/core/PageArray.php b/wire/core/PageArray.php index 046e68c4..52cbfc71 100644 --- a/wire/core/PageArray.php +++ b/wire/core/PageArray.php @@ -597,6 +597,7 @@ class PageArray extends PaginatedArray implements WirePaginatable { * @return Page[]|\ArrayObject|PageArrayIterator * */ + #[\ReturnTypeWillChange] public function getIterator() { if($this->lazyLoad) return new PageArrayIterator($this->data, $this->finderOptions); return parent::getIterator(); diff --git a/wire/core/PageTraversal.php b/wire/core/PageTraversal.php index ed37d2c8..186a281d 100644 --- a/wire/core/PageTraversal.php +++ b/wire/core/PageTraversal.php @@ -862,7 +862,7 @@ class PageTraversal { if($options === true || (is_array($options) && !empty($options['http']))) { if(strpos($url, '://') === false) { - $url = ($https ? 'https://' : 'http://') . $config->httpHost . $url; + $url = ($https || $config->https ? 'https://' : 'http://') . $config->httpHost . $url; } } diff --git a/wire/core/PageimageVariations.php b/wire/core/PageimageVariations.php index 8d2d5a2a..b5f1179a 100644 --- a/wire/core/PageimageVariations.php +++ b/wire/core/PageimageVariations.php @@ -45,6 +45,7 @@ class PageimageVariations extends Wire implements \IteratorAggregate, \Countable parent::__construct(); } + #[\ReturnTypeWillChange] public function getIterator() { return $this->find(); } @@ -58,6 +59,7 @@ class PageimageVariations extends Wire implements \IteratorAggregate, \Countable * @return int * */ + #[\ReturnTypeWillChange] public function count($options = array()) { if($this->variations) { $count = $this->variations->count(); @@ -227,9 +229,26 @@ class PageimageVariations extends Wire implements \IteratorAggregate, \Countable ); foreach($this->pageimage->extras() as $name => $extra) { - if(!$extra->exists()) continue; - $info["{$name}Url"] = $extra->url(false); - $info["{$name}Path"] = $extra->filename(); + + if($extra->exists()) { + $info["{$name}Url"] = $extra->url(false); + $info["{$name}Path"] = $extra->filename(); + continue; + } + + $f = "$basename.$extra->ext"; // useSrcExt, i.e. file.png.webp + if(is_readable($this->pagefiles->path . $f)) { + $info["{$name}Url"] = $this->pagefiles->url . $f; + $info["{$name}Path"] = $this->pagefiles->path . $f; + continue; + } + + $f = basename($basename, '.' . $this->pageimage->ext()) . ".$extra->ext"; + if(is_readable($this->pagefiles->path . $f)) { + $info["{$name}Url"] = $this->pagefiles->url . $f; + $info["{$name}Path"] = $this->pagefiles->path . $f; + continue; + } } if(empty($info['crop'])) { diff --git a/wire/core/PagesPathFinder.php b/wire/core/PagesPathFinder.php index 4283f65e..a5e81c93 100644 --- a/wire/core/PagesPathFinder.php +++ b/wire/core/PagesPathFinder.php @@ -432,7 +432,7 @@ class PagesPathFinder extends Wire { if(empty($result['language']['name'])) $this->setResultLanguage($language); } if(!isset($namesByLanguage[$language->name])) $namesByLanguage[$language->name] = array(); - $namesByLanguage[$language->name][] = strlen($nameLanguage) ? $nameLanguage : $nameDefault; + $namesByLanguage[$language->name][] = strlen("$nameLanguage") ? $nameLanguage : $nameDefault; } } @@ -1348,6 +1348,7 @@ class PagesPathFinder extends Wire { * */ protected function pageNameToUTF8($name) { + $name = (string) $name; if($this->pageNameCharset !== 'UTF8') return $name; if(strpos($name, 'xn-') !== 0) return $name; return $this->wire()->sanitizer->pageName($name, Sanitizer::toUTF8); diff --git a/wire/core/PagesType.php b/wire/core/PagesType.php index a4d821e8..fe7cf216 100644 --- a/wire/core/PagesType.php +++ b/wire/core/PagesType.php @@ -494,6 +494,7 @@ class PagesType extends Wire implements \IteratorAggregate, \Countable { * #pw-internal * */ + #[\ReturnTypeWillChange] public function getIterator() { return $this->find("id>0, sort=name", array( 'caller' => $this->className() . '.getIterator()' diff --git a/wire/core/Permissions.php b/wire/core/Permissions.php index aa92feac..7837ce1d 100644 --- a/wire/core/Permissions.php +++ b/wire/core/Permissions.php @@ -256,6 +256,7 @@ class Permissions extends PagesType { * @return \ArrayObject * */ + #[\ReturnTypeWillChange] public function getIterator() { return parent::getIterator(); } diff --git a/wire/core/Session.php b/wire/core/Session.php index 170919b0..b5fb697b 100644 --- a/wire/core/Session.php +++ b/wire/core/Session.php @@ -801,6 +801,7 @@ class Session extends Wire implements \IteratorAggregate { * @return \ArrayObject * */ + #[\ReturnTypeWillChange] public function getIterator() { $data = $this->sessionInit ? $_SESSION[$this->sessionKey] : $this->data; return new \ArrayObject($data); @@ -1291,9 +1292,14 @@ class Session extends Wire implements \IteratorAggregate { * ~~~~~ * * @param string $url URL to redirect to - * @param bool|int $status Specify true for 301 permanent redirect, false for 302 temporary redirect, or - * in 3.0.166+ you can also specify the status code (integer) rather than boolean. - * Default is 301 (permanent). + * @param bool|int $status One of the following (or omit for 301): + * - `true` (bool): Permanent redirect (same as 301). + * - `false` (bool): Temporary redirect (same as 302). + * - `301` (int): Permanent redirect using GET. (3.0.166+) + * - `302` (int): “Found”, Temporary redirect using GET. (3.0.166+) + * - `303` (int): “See other”, Temporary redirect using GET. (3.0.166+) + * - `307` (int): Temporary redirect using current request method such as POST (repeat that request). (3.0.166+) + * @see Session::location() * */ public function ___redirect($url, $status = 301) { @@ -1354,17 +1360,22 @@ class Session extends Wire implements \IteratorAggregate { } /** - * Perform a temporary (302) redirect + * Perform a temporary redirect * * This is an alias of `$session->redirect($url, false);` that sends only the * location header, which translates to a 302 redirect. * * @param string $url + * @param int $status One of the following HTTP status codes, or omit for 302 (added 3.0.192): + * - `302` (int): “Found”, Temporary redirect using GET. (default) + * - `303` (int): “See other”, Temporary redirect using GET. + * - `307` (int): Temporary redirect using current request method such as POST (repeat that request). * @since 3.0.166 + * @see Session::redirect() * */ - public function location($url) { - $this->redirect($url, false); + public function location($url, $status = 302) { + $this->redirect($url, $status); } /** diff --git a/wire/core/WireArray.php b/wire/core/WireArray.php index e5704f0c..d6dc1cc4 100644 --- a/wire/core/WireArray.php +++ b/wire/core/WireArray.php @@ -1401,6 +1401,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count // check for items that resolve to blank if(is_null($key) || (is_string($key) && !strlen(trim($key)))) { + // @todo option to allow for these to be sorted regularly $unidentified[] = $item; continue; } @@ -1758,6 +1759,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count * @return \ArrayObject|Wire[] * */ + #[\ReturnTypeWillChange] public function getIterator() { return new \ArrayObject($this->data); } @@ -1778,6 +1780,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count * @return int * */ + #[\ReturnTypeWillChange] public function count() { return count($this->data); } @@ -1793,6 +1796,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count * @param Wire|mixed $value Value of item. * */ + #[\ReturnTypeWillChange] public function offsetSet($key, $value) { $this->set($key, $value); } @@ -1806,6 +1810,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count * @return Wire|mixed|bool Value of item requested, or false if it doesn't exist. * */ + #[\ReturnTypeWillChange] public function offsetGet($key) { if($this->offsetExists($key)) { return $this->data[$key]; @@ -1825,6 +1830,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count * @return bool True if item existed and was unset. False if item didn't exist. * */ + #[\ReturnTypeWillChange] public function offsetUnset($key) { if($this->offsetExists($key)) { $this->remove($key); @@ -1845,6 +1851,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count * @return bool True if the item exists, false if not. * */ + #[\ReturnTypeWillChange] public function offsetExists($key) { return array_key_exists($key, $this->data); } diff --git a/wire/core/WireData.php b/wire/core/WireData.php index a3121846..7dce3f8c 100644 --- a/wire/core/WireData.php +++ b/wire/core/WireData.php @@ -378,6 +378,7 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess { * @return \ArrayObject * */ + #[\ReturnTypeWillChange] public function getIterator() { return new \ArrayObject($this->data); } @@ -482,6 +483,7 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess { * @param int|string|array|object $value Value of item. * */ + #[\ReturnTypeWillChange] public function offsetSet($key, $value) { $this->set($key, $value); } @@ -495,6 +497,7 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess { * @return int|string|array|object Value of item requested, or false if it doesn't exist. * */ + #[\ReturnTypeWillChange] public function offsetGet($key) { $value = $this->get($key); return is_null($value) ? false : $value; @@ -511,6 +514,7 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess { * @return bool True if item existed and was unset. False if item didn't exist. * */ + #[\ReturnTypeWillChange] public function offsetUnset($key) { if($this->__isset($key)) { $this->remove($key); @@ -520,7 +524,6 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess { } } - /** * Determines if the given index exists in this WireData. * @@ -532,6 +535,7 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess { * @return bool True if the item exists, false if not. * */ + #[\ReturnTypeWillChange] public function offsetExists($key) { return $this->__isset($key); } diff --git a/wire/core/WireDataDB.php b/wire/core/WireDataDB.php index 32827df9..85492bd4 100644 --- a/wire/core/WireDataDB.php +++ b/wire/core/WireDataDB.php @@ -253,6 +253,7 @@ class WireDataDB extends WireData implements \Countable { * @return int * */ + #[\ReturnTypeWillChange] public function count() { $table = $this->table(); $sql = "SELECT COUNT(*) FROM `$table` WHERE source_id=:source_id"; @@ -354,7 +355,8 @@ class WireDataDB extends WireData implements \Countable { $this->wire('database')->exec("DROP TABLE `$table`"); return true; } - + + #[\ReturnTypeWillChange] public function getIterator() { return new \ArrayObject($this->getArray()); } diff --git a/wire/core/WireDatabasePDO.php b/wire/core/WireDatabasePDO.php index 1ad7dc8a..79a8f548 100644 --- a/wire/core/WireDatabasePDO.php +++ b/wire/core/WireDatabasePDO.php @@ -1551,6 +1551,7 @@ class WireDatabasePDO extends Wire implements WireDatabase { * */ public function closeConnection() { + $this->pdoLast = null; $this->reader['pdo'] = null; $this->writer['pdo'] = null; $this->reader['init'] = false; diff --git a/wire/core/WireDatabasePDOStatement.php b/wire/core/WireDatabasePDOStatement.php index 1ce24225..bd91aeb3 100644 --- a/wire/core/WireDatabasePDOStatement.php +++ b/wire/core/WireDatabasePDOStatement.php @@ -123,6 +123,7 @@ class WireDatabasePDOStatement extends \PDOStatement { * @return bool * */ + #[\ReturnTypeWillChange] public function bindValue($parameter, $value, $data_type = \PDO::PARAM_STR) { $result = parent::bindValue($parameter, $value, $data_type); if($this->debugMode && strpos($parameter, ':') === 0) { @@ -141,6 +142,7 @@ class WireDatabasePDOStatement extends \PDOStatement { * @throws \PDOException * */ + #[\ReturnTypeWillChange] public function execute($input_parameters = NULL) { if($this->debugMode) { return $this->executeDebug($input_parameters); diff --git a/wire/core/WireInputData.php b/wire/core/WireInputData.php index 71db5a6f..427a15eb 100644 --- a/wire/core/WireInputData.php +++ b/wire/core/WireInputData.php @@ -415,6 +415,7 @@ class WireInputData extends Wire implements \ArrayAccess, \IteratorAggregate, \C return $value; } + #[\ReturnTypeWillChange] public function getIterator() { if($this->lazy) { $data = $this->getArray(); @@ -424,23 +425,28 @@ class WireInputData extends Wire implements \ArrayAccess, \IteratorAggregate, \C } } + #[\ReturnTypeWillChange] public function offsetExists($key) { return isset($this->data[$key]); } + #[\ReturnTypeWillChange] public function offsetGet($key) { return $this->__get($key); } + #[\ReturnTypeWillChange] public function offsetSet($key, $value) { $this->__set($key, $value); } + #[\ReturnTypeWillChange] public function offsetUnset($key) { unset($this->data[$key]); if($this->lazy && isset($this->unlazyKeys[$key])) unset($this->unlazyKeys[$key]); } + #[\ReturnTypeWillChange] public function count() { return count($this->data); } diff --git a/wire/core/WireInputDataCookie.php b/wire/core/WireInputDataCookie.php index f6aef808..c3386f82 100644 --- a/wire/core/WireInputDataCookie.php +++ b/wire/core/WireInputDataCookie.php @@ -445,6 +445,7 @@ class WireInputDataCookie extends WireInputData { * @param mixed $key * */ + #[\ReturnTypeWillChange] public function offsetUnset($key) { if(!$this->allowSetCookie($key)) return; parent::offsetUnset($key); diff --git a/wire/core/WireSaveableItems.php b/wire/core/WireSaveableItems.php index f44ea2a5..15d0cd4f 100644 --- a/wire/core/WireSaveableItems.php +++ b/wire/core/WireSaveableItems.php @@ -386,6 +386,7 @@ abstract class WireSaveableItems extends Wire implements \IteratorAggregate { return $this->getAll()->find($selectors); } + #[\ReturnTypeWillChange] public function getIterator() { return $this->getAll(); } diff --git a/wire/modules/LanguageSupport/Languages.php b/wire/modules/LanguageSupport/Languages.php index 56f94e30..e4e9cddb 100644 --- a/wire/modules/LanguageSupport/Languages.php +++ b/wire/modules/LanguageSupport/Languages.php @@ -251,6 +251,7 @@ class Languages extends PagesType { * @return PageArray * */ + #[\ReturnTypeWillChange] public function getIterator() { if($this->languages && count($this->languages)) return $this->languages; $languages = $this->wire('pages')->newPageArray(); diff --git a/wire/modules/LanguageSupport/LanguagesPageFieldValue.php b/wire/modules/LanguageSupport/LanguagesPageFieldValue.php index 7ca6b971..b87ea3d1 100644 --- a/wire/modules/LanguageSupport/LanguagesPageFieldValue.php +++ b/wire/modules/LanguageSupport/LanguagesPageFieldValue.php @@ -387,6 +387,7 @@ class LanguagesPageFieldValue extends Wire implements LanguagesValueInterface, \ * @return \ArrayObject * */ + #[\ReturnTypeWillChange] public function getIterator() { return new \ArrayObject($this->data); } diff --git a/wire/modules/Markup/MarkupPagerNav/PagerNav.php b/wire/modules/Markup/MarkupPagerNav/PagerNav.php index 3830fb56..a524c0e7 100644 --- a/wire/modules/Markup/MarkupPagerNav/PagerNav.php +++ b/wire/modules/Markup/MarkupPagerNav/PagerNav.php @@ -243,6 +243,7 @@ class PagerNav implements \IteratorAggregate { return $this->pager; } + #[\ReturnTypeWillChange] public function getIterator() { return new \ArrayObject($this->getPager()); } public function getFirstItem() { return $this->firstItem; } public function getItemsPerPage() { return $this->itemsPerPage; }