Unverified Commit 0c2a74f7 authored by Johan Cwiklinski's avatar Johan Cwiklinski Committed by GitHub
Browse files

Use Laminas instead of Zend; closes #6742 (#6760)



* Use Laminas instead of Zend; closes #6742

* Use Laminas namespace

* Update unit test to remove zend class existence check
Co-authored-by: default avatarCédric Anne <cedric.anne@gmail.com>
parent bfb98910
......@@ -40,6 +40,7 @@ The present file will list all changes made to the project; according to the
- jQuery library has been upgraded from 2.2.x to 3.4.x. jQuery Migrate is used to ensure backward compatibility in most cases.
- `DBmysqlIterator::handleOrderClause()` supports QueryExpressions
- Use Laminas instead of deprecated ZendFramework
#### Deprecated
......
This diff is collapsed.
......@@ -55,7 +55,7 @@ global $CFG_GLPI, $TRANSLATE;
// Get messages from translator component
$messages = $TRANSLATE->getAllMessages($_GET['domain']);
if (!($messages instanceof \Zend\I18n\Translator\TextDomain)) {
if (!($messages instanceof \Laminas\I18n\Translator\TextDomain)) {
Toolbox::logError(sprintf('Unable to get messages from domain "%s".', $_GET['domain']));
exit('[]');
}
......
......@@ -181,7 +181,7 @@ class Auth extends CommonGLPI {
$ssl = 'TLS';
}
$imap = new \Zend\Mail\Protocol\Imap();
$imap = new \Laminas\Mail\Protocol\Imap();
$imap->connect(
$config['address'],
$config['port'],
......
......@@ -37,8 +37,8 @@ if (!defined('GLPI_ROOT')) {
}
use Psr\SimpleCache\CacheInterface;
use Zend\Cache\Psr\SimpleCache\SimpleCacheDecorator;
use Zend\Cache\Storage\StorageInterface;
use Laminas\Cache\Psr\SimpleCache\SimpleCacheDecorator;
use Laminas\Cache\Storage\StorageInterface;
class SimpleCache extends SimpleCacheDecorator implements CacheInterface {
......
......@@ -33,10 +33,10 @@
use Glpi\Cache\SimpleCache;
use Glpi\Exception\PasswordTooWeakException;
use Glpi\System\RequirementsManager;
use Laminas\Cache\Storage\AvailableSpaceCapableInterface;
use Laminas\Cache\Storage\FlushableInterface;
use Laminas\Cache\Storage\TotalSpaceCapableInterface;
use PHPMailer\PHPMailer\PHPMailer;
use Zend\Cache\Storage\AvailableSpaceCapableInterface;
use Zend\Cache\Storage\TotalSpaceCapableInterface;
use Zend\Cache\Storage\FlushableInterface;
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
......@@ -2013,12 +2013,12 @@ class Config extends CommonDBTM {
'check' => 'Sabre\\Uri\\Version' ],
[ 'name' => 'sabre/vobject',
'check' => 'Sabre\\VObject\\Component' ],
[ 'name' => 'zendframework/zend-cache',
'check' => 'Zend\\Cache\\Module' ],
[ 'name' => 'zendframework/zend-i18n',
'check' => 'Zend\\I18n\\Module' ],
[ 'name' => 'zendframework/zend-serializer',
'check' => 'Zend\\Serializer\\Module' ],
[ 'name' => 'laminas/laminas-cache',
'check' => 'Laminas\\Cache\\Module' ],
[ 'name' => 'laminas/laminas-i18n',
'check' => 'Laminas\\I18n\\Module' ],
[ 'name' => 'laminas/laminas-serializer',
'check' => 'Laminas\\Serializer\\Module' ],
[ 'name' => 'monolog/monolog',
'check' => 'Monolog\\Logger' ],
[ 'name' => 'sebastian/diff',
......@@ -2029,10 +2029,10 @@ class Config extends CommonDBTM {
'check' => 'Symfony\\Component\\Console\\Application' ],
[ 'name' => 'scssphp/scssphp',
'check' => 'ScssPhp\ScssPhp\Compiler' ],
[ 'name' => 'zendframework/zend-mail',
'check' => 'Zend\\Mail\\Protocol\\Imap' ],
[ 'name' => 'zendframework/zend-mime',
'check' => 'Zend\\Mime\\Mime' ],
[ 'name' => 'laminas/laminas-mail',
'check' => 'Laminas\\Mail\\Protocol\\Imap' ],
[ 'name' => 'laminas/laminas-mime',
'check' => 'Laminas\\Mime\\Mime' ],
[ 'name' => 'rlanvin/php-rrule',
'check' => 'RRule\\RRule' ],
[ 'name' => 'blueimp/jquery-file-upload',
......@@ -3046,9 +3046,9 @@ class Config extends CommonDBTM {
*
* @param string $optname name of the configuration field
* @param string $context name of the configuration context (default 'core')
* @param boolean $psr16 Whether to return a PSR16 compliant obkect or not (since ZendTranslator is NOT PSR16 compliant).
* @param boolean $psr16 Whether to return a PSR16 compliant obkect or not (since Laminas Translator is NOT PSR16 compliant).
*
* @return Psr\SimpleCache\CacheInterface|Zend\Cache\Storage\StorageInterface object
* @return Psr\SimpleCache\CacheInterface|Laminas\Cache\Storage\StorageInterface object
*/
public static function getCache($optname, $context = 'core', $psr16 = true) {
global $DB;
......@@ -3116,7 +3116,7 @@ class Config extends CommonDBTM {
$is_computed_config = true;
} else {
// Adapter names can be written using case variations.
// see Zend\Cache\Storage\AdapterPluginManager::$aliases
// see Laminas\Cache\Storage\AdapterPluginManager::$aliases
$opt['adapter'] = strtolower($opt['adapter']);
switch ($opt['adapter']) {
......@@ -3193,7 +3193,7 @@ class Config extends CommonDBTM {
// Create adapter
try {
$storage = Zend\Cache\StorageFactory::factory($opt);
$storage = Laminas\Cache\StorageFactory::factory($opt);
} catch (Exception $e) {
if (!$is_computed_config) {
Toolbox::logError($e->getMessage());
......@@ -3215,7 +3215,7 @@ class Config extends CommonDBTM {
mkdir($opt['options']['cache_dir']);
}
try {
$storage = Zend\Cache\StorageFactory::factory($opt);
$storage = Laminas\Cache\StorageFactory::factory($opt);
$fallback = true;
} catch (Exception $e1) {
Toolbox::logError($e1->getMessage());
......@@ -3229,7 +3229,7 @@ class Config extends CommonDBTM {
if ($fallback === false) {
$opt = ['adapter' => 'memory'];
$storage = Zend\Cache\StorageFactory::factory($opt);
$storage = Laminas\Cache\StorageFactory::factory($opt);
}
if (isset($_SESSION['glpi_use_mode'])
&& Session::DEBUG_MODE == $_SESSION['glpi_use_mode']) {
......
......@@ -314,7 +314,7 @@ class Application extends BaseApplication {
/**
* Initialize GLPI cache.
*
* @global Zend\Cache\Storage\StorageInterface $GLPI_CACHE
* @global Laminas\Cache\Storage\StorageInterface $GLPI_CACHE
*
* @return void
*/
......
......@@ -785,7 +785,7 @@ class Html {
echo "<li><a href='#debugsession$rand'>SESSION VARIABLE</a></li>";
}
echo "<li><a href='#debugserver$rand'>SERVER VARIABLE</a></li>";
if ($GLPI_CACHE instanceof Zend\Cache\Storage\IterableInterface) {
if ($GLPI_CACHE instanceof Laminas\Cache\Storage\IterableInterface) {
echo "<li><a href='#debugcache$rand'>CACHE VARIABLE</a></li>";
}
}
......@@ -832,7 +832,7 @@ class Html {
self::printCleanArray($_SERVER, 0, true);
echo "</div>";
if ($GLPI_CACHE instanceof Zend\Cache\Storage\IterableInterface) {
if ($GLPI_CACHE instanceof Laminas\Cache\Storage\IterableInterface) {
echo "<div id='debugcache$rand'>";
$cache_keys = $GLPI_CACHE->getIterator();
$cache_contents = [];
......
......@@ -35,7 +35,7 @@ if (!defined('GLPI_ROOT')) {
}
use LitEmoji\LitEmoji;
use Zend\Mime\Mime as Zend_Mime;
use Laminas\Mime\Mime as Laminas_Mime;
/**
* MailCollector class
......@@ -52,7 +52,7 @@ class MailCollector extends CommonDBTM {
// Specific one
/**
* IMAP / POP connection
* @var Zend\Mail\Storage\AbstractStorage
* @var Laminas\Mail\Storage\AbstractStorage
*/
private $storage;
/// UID of the current message
......@@ -370,7 +370,7 @@ class MailCollector extends CommonDBTM {
public function displayFoldersList($input_id = "") {
try {
$this->connect();
} catch (\Zend\Mail\Protocol\Exception\RuntimeException $e) {
} catch (\Laminas\Mail\Protocol\Exception\RuntimeException $e) {
Toolbox::logError($e->getMessage());
echo __('An error occured trying to connect to collector.');
return;
......@@ -667,7 +667,7 @@ class MailCollector extends CommonDBTM {
//Connect to the Mail Box
try {
$this->connect();
} catch (\Zend\Mail\Protocol\Exception\RuntimeException $e) {
} catch (\Laminas\Mail\Protocol\Exception\RuntimeException $e) {
Toolbox::logError($e->getTraceAsString());
Session::addMessageAfterRedirect(
__('An error occured trying to connect to collector.') . "<br/>" . $e->getMessage(),
......@@ -894,7 +894,7 @@ class MailCollector extends CommonDBTM {
*
* @return array ticket fields
*/
function buildTicket($uid, \Zend\Mail\Storage\Message $message, $options = []) {
function buildTicket($uid, \Laminas\Mail\Storage\Message $message, $options = []) {
global $CFG_GLPI;
$play_rules = (isset($options['play_rules']) && $options['play_rules']);
......@@ -1264,7 +1264,7 @@ class MailCollector extends CommonDBTM {
}
try {
$class = '\Zend\Mail\Storage\\';
$class = '\Laminas\Mail\Storage\\';
$class .= ($config['type']== 'pop' ? 'Pop3' : 'Imap');
$this->storage = new $class($params);
if ($this->fields['errors'] > 0) {
......@@ -1324,7 +1324,7 @@ class MailCollector extends CommonDBTM {
*
* @return array
**/
function getAdditionnalHeaders(\Zend\Mail\Storage\Message $message) {
function getAdditionnalHeaders(\Laminas\Mail\Storage\Message $message) {
$head = [];
$headers = $message->getHeaders();
......@@ -1360,7 +1360,7 @@ class MailCollector extends CommonDBTM {
* from => From address of mail
* fromName => Form Name of Mail
**/
function getHeaders(\Zend\Mail\Storage\Message $message) {
function getHeaders(\Laminas\Mail\Storage\Message $message) {
$h_sender = $message->getHeader('from')->getAddressList();
$sender = $h_sender->current();
......@@ -1404,7 +1404,7 @@ class MailCollector extends CommonDBTM {
// secu on subject setting
try {
$subject = $message->getHeader('subject')->getFieldValue();
} catch (Zend\Mail\Storage\Exception\InvalidArgumentException $e) {
} catch (Laminas\Mail\Storage\Exception\InvalidArgumentException $e) {
$subject = '';
}
......@@ -1463,7 +1463,7 @@ class MailCollector extends CommonDBTM {
*
* @return void
**/
private function getRecursiveAttached(\Zend\Mail\Storage\Part $part, $path, $maxsize, $subject, $subpart = "") {
private function getRecursiveAttached(\Laminas\Mail\Storage\Part $part, $path, $maxsize, $subject, $subpart = "") {
if ($part->isMultipart()) {
$index = 0;
foreach (new RecursiveIteratorIterator($part) as $mypart) {
......@@ -1480,8 +1480,8 @@ class MailCollector extends CommonDBTM {
//not an attachment
return false;
} else {
if (strtok($part->contentDisposition, ';') != Zend_Mime::DISPOSITION_ATTACHMENT
&& strtok($part->contentDisposition, ';') != Zend_Mime::DISPOSITION_INLINE
if (strtok($part->contentDisposition, ';') != Laminas_Mime::DISPOSITION_ATTACHMENT
&& strtok($part->contentDisposition, ';') != Laminas_Mime::DISPOSITION_INLINE
) {
//not an attachment
return false;
......@@ -1614,14 +1614,14 @@ class MailCollector extends CommonDBTM {
*
* @return array containing extracted filenames in file/_tmp
**/
public function getAttached(\Zend\Mail\Storage\Message $message, $path, $maxsize) {
public function getAttached(\Laminas\Mail\Storage\Message $message, $path, $maxsize) {
$this->files = [];
$this->altfiles = [];
$this->addtobody = "";
try {
$subject = $message->getHeader('subject')->getFieldValue();
} catch (Zend\Mail\Storage\Exception\InvalidArgumentException $e) {
} catch (Laminas\Mail\Storage\Exception\InvalidArgumentException $e) {
$subject = null;
}
......@@ -1636,7 +1636,7 @@ class MailCollector extends CommonDBTM {
*
* @param Message $message Message
**/
function getBody(\Zend\Mail\Storage\Message $message) {
function getBody(\Laminas\Mail\Storage\Message $message) {
$content = null;
//if message is not multipart, just return its content
......@@ -1990,7 +1990,7 @@ class MailCollector extends CommonDBTM {
*
* @return string
*/
public function getDecodedContent(\Zend\Mail\Storage\Part $part) {
public function getDecodedContent(\Laminas\Mail\Storage\Part $part) {
$contents = $part->getContent();
$encoding = null;
......@@ -2015,7 +2015,7 @@ class MailCollector extends CommonDBTM {
}
$contentType = $part->getHeader('contentType');
if ($contentType instanceof \Zend\Mail\Header\ContentType
if ($contentType instanceof \Laminas\Mail\Header\ContentType
&& preg_match('/^text\//', $contentType->getType())
&& mb_detect_encoding($contents) != 'UTF-8') {
$contents = Toolbox::encodeInUtf8($contents, $contentType->getEncoding());
......
......@@ -624,7 +624,7 @@ class Session {
if (isset($CFG_GLPI["languages"][$trytoload][5])) {
$_SESSION['glpipluralnumber'] = $CFG_GLPI["languages"][$trytoload][5];
}
$TRANSLATE = new Zend\I18n\Translator\Translator;
$TRANSLATE = new Laminas\I18n\Translator\Translator;
$TRANSLATE->setLocale($trytoload);
\Locale::setDefault($trytoload);
......
......@@ -30,7 +30,7 @@
* ---------------------------------------------------------------------
*/
use Zend\Cache\Psr\SimpleCache\SimpleCacheDecorator;
use Laminas\Cache\Psr\SimpleCache\SimpleCacheDecorator;
// Main GLPI test case. All tests should extends this class.
......@@ -55,9 +55,9 @@ class GLPITestCase extends atoum {
global $GLPI_CACHE;
//run with cache
define('CACHED_TESTS', true);
//ZendCache does not works with PHP5 acpu...
//LaminasCache does not works with PHP5 acpu...
$adapter = (version_compare(PHP_VERSION, '7.0.0') >= 0) ? 'apcu' : 'apc';
$storage = \Zend\Cache\StorageFactory::factory([
$storage = \Laminas\Cache\StorageFactory::factory([
'adapter' => $adapter,
'options' => [
'namespace' => $this->nscache
......
......@@ -56,7 +56,7 @@ class SimpleCache extends \GLPITestCase {
$footprint_file = vfsStream::url('glpi/cache/' . $cache_namespace . '.json');
$this->newTestedInstance(
new \mock\Zend\Cache\Storage\Adapter\Memory(['namespace' => $cache_namespace]),
new \mock\Laminas\Cache\Storage\Adapter\Memory(['namespace' => $cache_namespace]),
$cache_dir
);
......@@ -86,7 +86,7 @@ class SimpleCache extends \GLPITestCase {
$footprint_file = vfsStream::url('glpi/cache/' . $cache_namespace . '.json');
$this->newTestedInstance(
new \mock\Zend\Cache\Storage\Adapter\Memory(['namespace' => $cache_namespace]),
new \mock\Laminas\Cache\Storage\Adapter\Memory(['namespace' => $cache_namespace]),
$cache_dir
);
......@@ -118,7 +118,7 @@ class SimpleCache extends \GLPITestCase {
$footprint_file = vfsStream::url('glpi/cache/' . $cache_namespace . '.json');
$this->newTestedInstance(
new \mock\Zend\Cache\Storage\Adapter\Memory(['namespace' => $cache_namespace]),
new \mock\Laminas\Cache\Storage\Adapter\Memory(['namespace' => $cache_namespace]),
$cache_dir
);
......@@ -151,7 +151,7 @@ class SimpleCache extends \GLPITestCase {
$this->when(
function() use ($self, $cache_dir, $cache_namespace) {
$self->newTestedInstance(
new \mock\Zend\Cache\Storage\Adapter\Memory(['namespace' => $cache_namespace]),
new \mock\Laminas\Cache\Storage\Adapter\Memory(['namespace' => $cache_namespace]),
$cache_dir
);
}
......@@ -183,7 +183,7 @@ class SimpleCache extends \GLPITestCase {
// Simulate existing cache with footprint.
$this->newTestedInstance(
new \mock\Zend\Cache\Storage\Adapter\Memory(['namespace' => $cache_namespace]),
new \mock\Laminas\Cache\Storage\Adapter\Memory(['namespace' => $cache_namespace]),
$cache_dir
);
......@@ -198,7 +198,7 @@ class SimpleCache extends \GLPITestCase {
$this->when(
function() use ($self, $cache_dir, $cache_namespace) {
$self->newTestedInstance(
new \mock\Zend\Cache\Storage\Adapter\Memory(['namespace' => $cache_namespace]),
new \mock\Laminas\Cache\Storage\Adapter\Memory(['namespace' => $cache_namespace]),
$cache_dir
);
}
......
......@@ -36,10 +36,10 @@ class ExtensionClass extends \GLPITestCase {
public function testCheckOnExistingExtensionByClass() {
$this->newTestedInstance('zend-cache', 'Zend\\Cache\\StorageFactory');
$this->newTestedInstance('psr-log', 'Psr\\Log\\NullLogger');
$this->boolean($this->testedInstance->isValidated())->isEqualTo(true);
$this->array($this->testedInstance->getValidationMessages())
->isEqualTo(['zend-cache extension is installed']);
->isEqualTo(['psr-log extension is installed']);
}
public function testCheckOnExistingExtensionByInterface() {
......
......@@ -135,7 +135,7 @@ echo "+ Done\n";
+ Done
+ Entities: 299598
+ Cache: Zend\Cache\Storage\Adapter\Apcu
+ Cache: Laminas\Cache\Storage\Adapter\Apcu
+ Clear sons cache
+ Run with empty cache
> time: 2.8290
......@@ -144,7 +144,7 @@ echo "+ Done\n";
+ Done
+ Entities: 299598
+ Cache: Zend\Cache\Storage\Adapter\Memcache
+ Cache: Laminas\Cache\Storage\Adapter\Memcache
+ Clear sons cache
+ Run with empty cache
> time: 3.0366
......@@ -153,7 +153,7 @@ echo "+ Done\n";
+ Done
+ Entities: 299598
+ Cache: Zend\Cache\Storage\Adapter\Redis
+ Cache: Laminas\Cache\Storage\Adapter\Redis
+ Clear sons cache
+ Run with empty cache
> time: 2.9524
......@@ -162,7 +162,7 @@ echo "+ Done\n";
+ Done
+ Entities: 299593
+ Cache: Zend\Cache\Storage\Adapter\WinCache
+ Cache: Laminas\Cache\Storage\Adapter\WinCache
+ Clear sons cache
+ Run with empty cache
> time: 5.1352
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment