composer update && composer upgrade

This commit is contained in:
synox 2019-03-11 19:59:53 +07:00
parent d835806a28
commit c24beb2cdf
72 changed files with 2033 additions and 881 deletions

8
composer.lock generated
View file

@ -111,13 +111,13 @@
"version": "2.0.0",
"source": {
"type": "git",
"url": "git@github.com:gnugat/PronounceableWord.git",
"reference": "60a19dc7148e92de35ea536b9f873b86365d48f0"
"url": "https://github.com/gnugat-legacy/PronounceableWord.git",
"reference": "fcdc0dc39775fa625040c37003727019657d001b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/gnugat/PronounceableWord/zipball/60a19dc7148e92de35ea536b9f873b86365d48f0",
"reference": "60a19dc7148e92de35ea536b9f873b86365d48f0",
"url": "https://api.github.com/repos/gnugat-legacy/PronounceableWord/zipball/fcdc0dc39775fa625040c37003727019657d001b",
"reference": "fcdc0dc39775fa625040c37003727019657d001b",
"shasum": ""
},
"require": {

View file

@ -55,6 +55,7 @@ class ClassLoader
private $classMap = array();
private $classMapAuthoritative = false;
private $missingClasses = array();
private $apcuPrefix;
public function getPrefixes()
{
@ -271,6 +272,26 @@ class ClassLoader
return $this->classMapAuthoritative;
}
/**
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
*
* @param string|null $apcuPrefix
*/
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
}
/**
* The APCu prefix in use, or null if APCu caching is not enabled.
*
* @return string|null
*/
public function getApcuPrefix()
{
return $this->apcuPrefix;
}
/**
* Registers this instance as an autoloader.
*
@ -313,11 +334,6 @@ class ClassLoader
*/
public function findFile($class)
{
// work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
if ('\\' == $class[0]) {
$class = substr($class, 1);
}
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
@ -325,6 +341,12 @@ class ClassLoader
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
}
if (null !== $this->apcuPrefix) {
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
if ($hit) {
return $file;
}
}
$file = $this->findFileWithExtension($class, '.php');
@ -333,6 +355,10 @@ class ClassLoader
$file = $this->findFileWithExtension($class, '.hh');
}
if (null !== $this->apcuPrefix) {
apcu_add($this->apcuPrefix.$class, $file);
}
if (false === $file) {
// Remember that this class does not exist.
$this->missingClasses[$class] = true;
@ -348,10 +374,14 @@ class ClassLoader
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
if (0 === strpos($class, $prefix)) {
foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
$subPath = $class;
while (false !== $lastPos = strrpos($subPath, '\\')) {
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath . '\\';
if (isset($this->prefixDirsPsr4[$search])) {
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
foreach ($this->prefixDirsPsr4[$search] as $dir) {
if (file_exists($file = $dir . $pathEnd)) {
return $file;
}
}

View file

@ -1,5 +1,5 @@
Copyright (c) 2016 Nils Adermann, Jordi Boggiano
Copyright (c) Nils Adermann, Jordi Boggiano
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View file

@ -7,6 +7,5 @@ $baseDir = dirname(dirname($vendorDir));
return array(
'PronounceableWord_' => array($vendorDir . '/gnugat/PronounceableWord/src'),
'PhpImap' => array($vendorDir . '/php-imap/php-imap/src'),
'HTMLPurifier' => array($vendorDir . '/ezyang/htmlpurifier/library'),
);

View file

@ -6,5 +6,6 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname(dirname($vendorDir));
return array(
'PhpImap\\' => array($vendorDir . '/php-imap/php-imap/src/PhpImap'),
'Moment\\' => array($vendorDir . '/fightbulc/moment/src'),
);

View file

@ -23,7 +23,7 @@ class ComposerAutoloaderInit125dddd280a32cf75b181166154246ec
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit125dddd280a32cf75b181166154246ec', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION');
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';

View file

@ -11,6 +11,10 @@ class ComposerStaticInit125dddd280a32cf75b181166154246ec
);
public static $prefixLengthsPsr4 = array (
'P' =>
array (
'PhpImap\\' => 8,
),
'M' =>
array (
'Moment\\' => 7,
@ -18,6 +22,10 @@ class ComposerStaticInit125dddd280a32cf75b181166154246ec
);
public static $prefixDirsPsr4 = array (
'PhpImap\\' =>
array (
0 => __DIR__ . '/..' . '/php-imap/php-imap/src/PhpImap',
),
'Moment\\' =>
array (
0 => __DIR__ . '/..' . '/fightbulc/moment/src',
@ -31,10 +39,6 @@ class ComposerStaticInit125dddd280a32cf75b181166154246ec
array (
0 => __DIR__ . '/..' . '/gnugat/PronounceableWord/src',
),
'PhpImap' =>
array (
0 => __DIR__ . '/..' . '/php-imap/php-imap/src',
),
),
'H' =>
array (

View file

@ -1,93 +1,4 @@
[
{
"name": "php-imap/php-imap",
"version": "2.0.3",
"version_normalized": "2.0.3.0",
"source": {
"type": "git",
"url": "https://github.com/barbushin/php-imap.git",
"reference": "cc1a49a3f68090db182183c59ffbc09055d59f5b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/barbushin/php-imap/zipball/cc1a49a3f68090db182183c59ffbc09055d59f5b",
"reference": "cc1a49a3f68090db182183c59ffbc09055d59f5b",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"time": "2015-09-16 07:40:39",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"PhpImap": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD 3-Clause"
],
"authors": [
{
"name": "Sergey Barbushin",
"email": "barbushin@gmail.com",
"homepage": "http://linkedin.com/in/barbushin"
}
],
"description": "PHP class to access mailbox by POP3/IMAP/NNTP using IMAP extension",
"homepage": "https://github.com/barbushin/php-imap",
"keywords": [
"imap",
"mail",
"php"
]
},
{
"name": "gnugat/PronounceableWord",
"version": "2.0.0",
"version_normalized": "2.0.0.0",
"source": {
"type": "git",
"url": "git@github.com:gnugat/PronounceableWord.git",
"reference": "60a19dc7148e92de35ea536b9f873b86365d48f0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/gnugat/PronounceableWord/zipball/60a19dc7148e92de35ea536b9f873b86365d48f0",
"reference": "60a19dc7148e92de35ea536b9f873b86365d48f0",
"shasum": ""
},
"require": {
"php": ">=5.2"
},
"time": "2012-01-08 19:36:58",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"PronounceableWord_": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Loïc Chardonnet"
}
],
"description": "A light, customizable and simple library generating random and pronounceable words without using dictionaries or Markov chains.",
"homepage": "https://github.com/gnugat/PronounceableWord",
"keywords": [
"generator",
"pronounceable",
"word"
],
"abandoned": true
},
{
"name": "ezyang/htmlpurifier",
"version": "v4.10.0",
@ -109,7 +20,7 @@
"require-dev": {
"simpletest/simpletest": "^1.1"
},
"time": "2018-02-23 01:58:20",
"time": "2018-02-23T01:58:20+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
@ -139,26 +50,26 @@
},
{
"name": "fightbulc/moment",
"version": "1.26.10",
"version_normalized": "1.26.10.0",
"version": "1.29.0",
"version_normalized": "1.29.0.0",
"source": {
"type": "git",
"url": "https://github.com/fightbulc/moment.php.git",
"reference": "2fe6607fdbbd45b48708f539c70fde89ca9d10e6"
"reference": "bd57bba6d00dfa012e7b7b167e7006c6247ce3c8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fightbulc/moment.php/zipball/2fe6607fdbbd45b48708f539c70fde89ca9d10e6",
"reference": "2fe6607fdbbd45b48708f539c70fde89ca9d10e6",
"url": "https://api.github.com/repos/fightbulc/moment.php/zipball/bd57bba6d00dfa012e7b7b167e7006c6247ce3c8",
"reference": "bd57bba6d00dfa012e7b7b167e7006c6247ce3c8",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "4.2.*"
"phpunit/phpunit": "^4.8.36 || ^5.5 || ^6.5 || ^7.5"
},
"time": "2017-08-14 05:06:04",
"time": "2019-01-07T11:16:45+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
@ -171,16 +82,6 @@
"MIT"
],
"authors": [
{
"name": "Ashish Tilara",
"email": "ashish@itcutives.com",
"role": "developer"
},
{
"name": "Jaroslaw Kozak",
"email": "jaroslaw.kozak68@gmail.com",
"role": "developer"
},
{
"name": "Tino Ehrich",
"email": "tino@bigpun.me",
@ -201,5 +102,103 @@
"translation",
"validate"
]
},
{
"name": "gnugat/PronounceableWord",
"version": "2.0.0",
"version_normalized": "2.0.0.0",
"source": {
"type": "git",
"url": "https://github.com/gnugat-legacy/PronounceableWord.git",
"reference": "fcdc0dc39775fa625040c37003727019657d001b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/gnugat-legacy/PronounceableWord/zipball/fcdc0dc39775fa625040c37003727019657d001b",
"reference": "fcdc0dc39775fa625040c37003727019657d001b",
"shasum": ""
},
"require": {
"php": ">=5.2"
},
"time": "2012-01-08T19:36:58+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"PronounceableWord_": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Loïc Chardonnet"
}
],
"description": "A light, customizable and simple library generating random and pronounceable words without using dictionaries or Markov chains.",
"homepage": "https://github.com/gnugat/PronounceableWord",
"keywords": [
"generator",
"pronounceable",
"word"
],
"abandoned": true
},
{
"name": "php-imap/php-imap",
"version": "3.0.6",
"version_normalized": "3.0.6.0",
"source": {
"type": "git",
"url": "https://github.com/barbushin/php-imap.git",
"reference": "d4f8ef4504dfb555857241aa7d1e414a1c229079"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/barbushin/php-imap/zipball/d4f8ef4504dfb555857241aa7d1e414a1c229079",
"reference": "d4f8ef4504dfb555857241aa7d1e414a1c229079",
"shasum": ""
},
"require": {
"ext-imap": "*",
"php": ">=5.5"
},
"time": "2017-12-22T12:53:34+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"PhpImap\\": "src/PhpImap"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Sergey Barbushin",
"email": "barbushin@gmail.com",
"homepage": "http://linkedin.com/in/barbushin"
}
],
"description": "Manage mailboxes, filter/get/delete emails in PHP (supports IMAP/POP3/NNTP)",
"homepage": "https://github.com/barbushin/php-imap",
"keywords": [
"imap",
"mail",
"mailbox",
"php",
"pop3",
"receive emails"
]
}
]

0
src/vendor/ezyang/htmlpurifier/maintenance/compile-doxygen.sh vendored Executable file → Normal file
View file

View file

0
src/vendor/ezyang/htmlpurifier/maintenance/generate-entity-file.php vendored Executable file → Normal file
View file

0
src/vendor/ezyang/htmlpurifier/maintenance/generate-standalone.php vendored Executable file → Normal file
View file

0
src/vendor/ezyang/htmlpurifier/maintenance/merge-library.php vendored Executable file → Normal file
View file

0
src/vendor/ezyang/htmlpurifier/maintenance/regenerate-docs.sh vendored Executable file → Normal file
View file

View file

@ -1,16 +1,19 @@
language: php
php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
matrix:
allow_failures:
- php: hhvm
env: PHP_VERSION=7.0.1
- php: nightly
include:
- php: 5.3
dist: precise
- php: 5.5
- php: 5.6
- php: 7.0
- php: 7.1
- php: 7.2
- php: nightly
before_install:
- composer self-update

View file

@ -28,12 +28,8 @@ PHP 5.3 or later since moment.php is based on php's [DateTime Class](http://php.
Easy install via composer. Still no idea what composer is? Inform yourself [here](http://getcomposer.org).
```json
{
"require": {
"fightbulc/moment": "*"
}
}
```
composer require fightbulc/moment
```
-------------------------------------------------
@ -115,10 +111,11 @@ __Supported languages so far:__
```fr_FR``` French (Europe)
```de_DE``` German (Germany)
```hu_HU``` Hungarian
```in_ID``` Indonesian
```id_ID``` Indonesian
```it_IT``` Italian
```ja_JP``` Japanese
```oc_LNC``` Lengadocian
```oc_LNC``` Lengadocian
```lv_LV``` Latvian (Latviešu)
```pl_PL``` Polish
```pt_BR``` Portuguese (Brazil)
```pt_PT``` Portuguese (Portugal)
@ -417,6 +414,30 @@ You can now run through the result and put it formatted into a drop-down field o
# Changelog
### 1.29.0
- updated Italian locale
- added:
- custom formats for en_US
- flag for loading similar locale
### 1.28.3
- fixed typehint issue
### 1.28.2
- fixed:
- missing relativeTime format
- allow 9-digit unixtime
### 1.28.1
- fixed RFC2822 as valid format
### 1.28.0
- fixed relative time
- added Norwegian locale
### 1.27.0
- fixes and locale additions [(see commits for the 22.11.2018)](https://github.com/fightbulc/moment.php/commits/master)
### 1.26.10
- fixed:
- Occitan locale

View file

@ -1,47 +1,42 @@
{
"name": "fightbulc/moment",
"description": "Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js",
"type": "library",
"keywords": [
"date",
"time",
"parse",
"validate",
"manipulate",
"display",
"format",
"i18n",
"translation",
"locale",
"moment"
],
"license": "MIT",
"authors": [
{
"name": "Tino Ehrich",
"email": "tino@bigpun.me",
"role": "developer"
},
{
"name": "Ashish Tilara",
"email": "ashish@itcutives.com",
"role": "developer"
},
{
"name": "Jaroslaw Kozak",
"email": "jaroslaw.kozak68@gmail.com",
"role": "developer"
}
],
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "4.2.*"
},
"autoload": {
"psr-4": {
"Moment\\": "src/"
}
"name": "fightbulc/moment",
"description": "Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js",
"type": "library",
"keywords": [
"date",
"time",
"parse",
"validate",
"manipulate",
"display",
"format",
"i18n",
"translation",
"locale",
"moment"
],
"license": "MIT",
"authors": [
{
"name": "Tino Ehrich",
"email": "tino@bigpun.me",
"role": "developer"
}
],
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.36 || ^5.5 || ^6.5 || ^7.5"
},
"autoload": {
"psr-4": {
"Moment\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Moment\\": "tests/"
}
}
}

View file

@ -61,6 +61,7 @@ class MomentJs implements FormatsInterface
"Z" => "P", // -07:00 -06:00 ... +06:00 +07:00
"ZZ" => "O", // -0700 -0600 ... +0600 +0700
"X" => "U", // 1360013296
"LTS" => "g:i:s A", // 8:30:15 PM
"LT" => "g:i A", // 8:30 PM
"L" => "m/d/Y", // 09/04/1986
"l" => "n/j/Y", // 9/4/1986
@ -112,7 +113,7 @@ class MomentJs implements FormatsInterface
$tokens = $this->getTokens();
// find all tokens from string, using regular expression
$regExp = "/(\[[^\[]*\])|(\\\\)?(LT|LL?L?L?|l{1,4}|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|SS?S?|X|zz?|ZZ?|.)/";
$regExp = "/(\[[^\[]*\])|(\\\\)?(LTS?|LL?L?L?|l{1,4}|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|SS?S?|X|zz?|ZZ?|.)/";
$matches = array();
preg_match_all($regExp, $format, $matches);

View file

@ -4,10 +4,10 @@
// author: Tarek Morgéne https://www.satoripop.com/
return array(
"months" => explode('_', 'جانفي_فيفري_مارس_أفريل_ماي_جوان_جويلية_أوت_سبتمبر_أكتوبر_نوفمبر_ديسمبر'),
"monthsShort" => explode('_', انفي_فيفري_مارس_أفريل_ماي_جوان_جويلية_أوت_سبتمبر_أكتوبر_نوفمبر_ديسمبر'),
"weekdays" => explode('_', 'الأحد_الإثنين_الثلاثاء_الأربعاء_الخميس_الجمعة_السبت'),
"weekdaysShort" => explode('_', 'أحد_إثنين_ثلاثاء_أربعاء_خميس_جمعة_سبت'),
"months" => explode('_', 'يناير_فبراير_مارس_أبريل_مايو_يونيو_يوليو_أغسطس_سبتمبر_أكتوبر_نوفمبر_ديسمبر'),
"monthsShort" => explode('_', انفي_فبراير_مارس_أبريل_مايو_يونيو_يوليو_أغسطس_سبتمبر_أكتوبر_نوفمبر_ديسمبر'),
"weekdays" => explode('_', 'الاثنين_الثلاثاء_الأربعاء_الخميس_الجمعة_السبت_الأحد'),
"weekdaysShort" => explode('_', 'أحد_اثنين_ثلاثاء_أربعاء_خميس_جمعة_سبت'),
"calendar" => array(
"sameDay" => '[اليوم]',
"nextDay" => '[غدا ]',
@ -21,6 +21,7 @@ return array(
"future" => 'في %s',
"past" => 'منذ %s',
"s" => 'ثوان',
"ss" => '%d ثانية',
"m" => 'دقيقة',
"mm" => '%d دقائق',
"h" => 'ساعة',

View file

@ -3,24 +3,27 @@
// locale: Catalan (ca_ES)
// author: CROWD Studio https://github.com/crowd-studio
use Moment\Moment;
return array(
"months" => explode('_', 'gener_febrer_març_abril_maig_juny_juliol_agost_setembre_octubre_novembre_desembre'),
"monthsShort" => explode('_', 'gen._febr._mar._abr._mai._jun._jul._ag._set._oct._nov._des.'),
"weekdays" => explode('_', 'diumenge_dilluns_dimarts_dimecres_dijous_divendres_dissabte'),
"weekdaysShort" => explode('_', 'dg._dl._dt._dc._dj._dv._ds.'),
"weekdays" => explode('_', 'dilluns_dimarts_dimecres_dijous_divendres_dissabte_diumenge'),
"weekdaysShort" => explode('_', 'dl._dt._dc._dj._dv._ds._dg.'),
"calendar" => array(
"sameDay" => '[avui]',
"nextDay" => '[demà]',
"lastDay" => '[ahir]',
"lastWeek" => '[el] l',
"sameElse" => 'l',
"withTime" => function (Moment $moment) { return '[a' . ($moment->getHour() !== 1 ? ' les' : null) . '] H:i'; },
"withTime" => function (Moment $moment) { return '[a' . ($moment->getHour() != 1 ? ' les ' : ' l\'') . ']G.i [h]'; },
"default" => 'd/m/Y',
),
"relativeTime" => array(
"future" => 'en %s',
"past" => 'fa %s',
"s" => 'uns segons',
"ss" => '%d segons',
"m" => 'un minut',
"mm" => '%d minuts',
"h" => 'una hora',
@ -37,19 +40,19 @@ return array(
switch ($number) {
case 1:
$ouput = 'r';
$output = 'r';
break;
case 2:
$ouput = 'n';
$output = 'n';
break;
case 3:
$ouput = 'r';
$output = 'r';
break;
case 4:
$ouput = 't';
$output = 't';
break;
default:
$ouput = 'è';
$output = 'è';
break;
}
@ -59,4 +62,4 @@ return array(
"dow" => 1, // Monday is the first day of the week.
"doy" => 4 // The week that contains Jan 4th is the first week of the year.
),
);
);

View file

@ -47,37 +47,52 @@ return array(
"relativeTime" => array(
"future" => 'za %s',
"past" => 'před %s',
"s" => function ($count, $direction, Moment $m) use ($ifPast) {
"s" => function ($count, $direction, Moment $m) use ($ifPast)
{
return $ifPast($direction, 'okamžikem', 'okamžik');
},
"m" => function ($count, $direction, Moment $m) use ($ifPast) {
"ss" => function ($count, $direction, Moment $m) use ($ifPast)
{
return $ifPast($direction, 'okamžikem', 'okamžik');
},
"m" => function ($count, $direction, Moment $m) use ($ifPast)
{
return $ifPast($direction, 'minutou', 'minutu');
},
"mm" => function ($count, $direction, Moment $m) use ($ifPast, $ifCountSmaller) {
"mm" => function ($count, $direction, Moment $m) use ($ifPast, $ifCountSmaller)
{
return $ifPast($direction, '%d minutami', $ifCountSmaller($count, 5, '%d minuty', '%d minut'));
},
"h" => function ($count, $direction, Moment $m) use ($ifPast, $ifCountSmaller) {
"h" => function ($count, $direction, Moment $m) use ($ifPast, $ifCountSmaller)
{
return $ifPast($direction, 'hodinou', 'hodinu');
},
"hh" => function ($count, $direction, Moment $m) use ($ifPast, $ifCountSmaller) {
$ifPast($direction, '%d hodinami', $ifCountSmaller($count, 5, '%d hodiny', '%d hodin'));
"hh" => function ($count, $direction, Moment $m) use ($ifPast, $ifCountSmaller)
{
return $ifPast($direction, '%d hodinami', $ifCountSmaller($count, 5, '%d hodiny', '%d hodin'));
},
"d" => function ($count, $direction, Moment $m) use ($ifPast) {
"d" => function ($count, $direction, Moment $m) use ($ifPast)
{
return $ifPast($direction, 'dnem', 'den');
},
"dd" => function ($count, $direction, Moment $m) use ($ifPast, $ifCountSmaller) {
"dd" => function ($count, $direction, Moment $m) use ($ifPast, $ifCountSmaller)
{
return $ifPast($direction, '%d dny', $ifCountSmaller($count, 5, '%d dny', '%d dnů'));
},
"M" => function ($count, $direction, Moment $m) use ($ifPast) {
"M" => function ($count, $direction, Moment $m) use ($ifPast)
{
return $ifPast($direction, 'měsícem', 'měsíc');
},
"MM" => function ($count, $direction, Moment $m) use ($ifPast, $ifCountSmaller) {
"MM" => function ($count, $direction, Moment $m) use ($ifPast, $ifCountSmaller)
{
return $ifPast($direction, '%d měsíci', $ifCountSmaller($count, 5, '%d měsíce', '%d měsíců'));
},
"y" => function ($count, $direction, Moment $m) use ($ifPast) {
"y" => function ($count, $direction, Moment $m) use ($ifPast)
{
return $ifPast($direction, 'rokem', 'rok');
},
"yy" => function ($count, $direction, Moment $m) use ($ifPast, $ifCountSmaller) {
"yy" => function ($count, $direction, Moment $m) use ($ifPast, $ifCountSmaller)
{
return $ifPast($direction, $ifCountSmaller($count, 5, '%d roky', '%d lety'), $ifCountSmaller($count, 5, '%d roky', '%d let'));
},
),

72
src/vendor/fightbulc/moment/src/Locales/da_DK.php vendored Executable file → Normal file
View file

@ -4,40 +4,40 @@
// author: Morten Wulff https://github.com/wulff
return array(
"months" => explode('_', 'januar_februar_marts_april_maj_juni_juli_august_september_oktober_november_december'),
"monthsShort" => explode('_', 'jan_feb_mar_apr_maj_jun_jul_aug_sep_okt_nov_dec'),
"weekdays" => explode('_', 'mandag_tirsdag_onsdag_torsdag_fredag_lørdag_søndag'),
"weekdaysShort" => explode('_', 'man_tir_ons_tor_fre_lør_søn'),
"calendar" => array(
"sameDay" => '[I dag]',
"nextDay" => '[I morgen]',
"lastDay" => '[I går]',
"lastWeek" => '[Sidste] l',
"sameElse" => 'l',
"withTime" => '[kl] H:i',
"default" => 'd/m/Y',
),
"relativeTime" => array(
"future" => 'om %s',
"past" => '%s siden',
"s" => 'få sekunder',
"m" => 'et minut',
"mm" => '%d minutter',
"h" => 'en time',
"hh" => '%d timer',
"d" => 'en dag',
"dd" => '%d dage',
"M" => 'en måned',
"MM" => '%d måneder',
"y" => 'et år',
"yy" => '%d år',
),
"ordinal" => function ($number)
{
return $number . '.';
},
"week" => array(
"dow" => 1, // Monday is the first day of the week.
"doy" => 4 // The week that contains Jan 4th is the first week of the year.
),
"months" => explode('_', 'januar_februar_marts_april_maj_juni_juli_august_september_oktober_november_december'),
"monthsShort" => explode('_', 'jan_feb_mar_apr_maj_jun_jul_aug_sep_okt_nov_dec'),
"weekdays" => explode('_', 'mandag_tirsdag_onsdag_torsdag_fredag_lørdag_søndag'),
"weekdaysShort" => explode('_', 'man_tir_ons_tor_fre_lør_søn'),
"calendar" => array(
"sameDay" => '[I dag]',
"nextDay" => '[I morgen]',
"lastDay" => '[I går]',
"lastWeek" => '[Sidste] l',
"sameElse" => 'l',
"withTime" => '[kl] H:i',
"default" => 'd/m/Y',
),
"relativeTime" => array(
"future" => 'om %s',
"past" => '%s siden',
"s" => 'få sekunder',
"ss" => '%d sekunder',
"m" => 'et minut',
"mm" => '%d minutter',
"h" => 'en time',
"hh" => '%d timer',
"d" => 'en dag',
"dd" => '%d dage',
"M" => 'en måned',
"MM" => '%d måneder',
"y" => 'et år',
"yy" => '%d år',
),
"ordinal" => function ($number) {
return $number . '.';
},
"week" => array(
"dow" => 1, // Monday is the first day of the week.
"doy" => 4 // The week that contains Jan 4th is the first week of the year.
),
);

View file

@ -14,13 +14,14 @@ return array(
"lastDay" => '[Gestern]',
"lastWeek" => '[Letzten] l',
"sameElse" => 'l',
"withTime" => '[um] H:i',
"withTime" => '[um] G:i [Uhr]',
"default" => 'd.m.Y',
),
"relativeTime" => array(
"future" => 'in %s',
"past" => 'vor %s',
"s" => 'ein paar Sekunden',
"ss" => '%d Sekunden',
"m" => 'einer Minute',
"mm" => '%d Minuten',
"h" => 'einer Stunde',
@ -40,4 +41,4 @@ return array(
"dow" => 1, // Monday is the first day of the week.
"doy" => 4 // The week that contains Jan 4th is the first week of the year.
),
);
);

View file

@ -22,6 +22,7 @@ return array(
"future" => 'in %s',
"past" => '%s ago',
"s" => 'a few seconds',
"ss" => '%d seconds',
"m" => 'a minute',
"mm" => '%d minutes',
"h" => 'an hour',
@ -49,4 +50,16 @@ return array(
"dow" => 1, // Monday is the first day of the week.
"doy" => 4 // The week that contains Jan 4th is the first week of the year.
),
"customFormats" => array(
"LT" => "G:i", // 22:00
"LTS" => "G:i:s", // 22:00:00
"L" => "d/m/Y", // 12/06/2010
"l" => "j/n/Y", // 12/6/2010
"LL" => "j F Y", // 12 June 2010
"ll" => "j M Y", // 12 Jun 2010
"LLL" => "j F Y G:i", // 12 June 2010 22:00
"lll" => "j M Y G:i", // 12 Jun 2010 22:00
"LLLL" => "l, j F F Y G:i", // Saturday, 12 June June 2010 22:00
"llll" => "D, j M Y G:i", // Sat, 12 Jun 2010 22:00
),
);

View file

@ -6,5 +6,16 @@ $locale = require __DIR__ . '/en_GB.php';
$locale['calendar']['withTime'] = '[at] h:i A';
$locale['calendar']['default'] = 'm/d/Y';
$locale['week']['dow'] = 7;
$locale["customFormats"] = array(
"LT" => "g:i A", // 8:30 PM
"L" => "m/d/Y", // 09/04/1986
"l" => "n/j/Y", // 9/4/1986
"LL" => "F j, Y", // September 4, 1986
"ll" => "M j, Y", // Sep 4, 1986
"LLL" => "F j, Y g:i A", // September 4, 1986 8:30 PM
"lll" => "M j, Y g:i A", // Sep 4, 1986 8:30 PM
"LLLL" => "l, F j, Y g:i A", // Thursday, September 4, 1986 8:30 PM
"llll" => "D, M j, Y g:i A", // Thu, Sep 4, 1986 8:30 PM
);
return $locale;

View file

@ -16,13 +16,14 @@ return array(
"lastDay" => '[ayer]',
"lastWeek" => '[el] l',
"sameElse" => 'l',
"withTime" => function (Moment $moment) { return '[a la' . ($moment->getHour() !== 1 ? 's' : null) . '] H:i'; },
"withTime" => function (Moment $moment) { return '[a la' . ($moment->getHour() != 1 ? 's' : null) . '] G:i [h]'; },
"default" => 'd/m/Y',
),
"relativeTime" => array(
"future" => 'en %s',
"past" => 'hace %s',
"s" => 'unos segundos',
"ss" => '%d segundos',
"m" => 'un minuto',
"mm" => '%d minutos',
"h" => 'una hora',
@ -42,4 +43,4 @@ return array(
"dow" => 1, // Monday is the first day of the week.
"doy" => 4 // The week that contains Jan 4th is the first week of the year.
),
);
);

View file

@ -14,13 +14,14 @@ return array(
"lastDay" => '[Hier]',
"lastWeek" => 'l [dernier]',
"sameElse" => 'l',
"withTime" => '[à] H:i',
"withTime" => '[à] G [h] i',
"default" => 'd/m/Y',
),
"relativeTime" => array(
"future" => 'dans %s',
"past" => 'il y a %s',
"s" => 'quelques secondes',
"ss" => '%d secondes',
"m" => 'une minute',
"mm" => '%d minutes',
"h" => 'une heure',
@ -34,7 +35,7 @@ return array(
),
"ordinal" => function ($number)
{
return $number . ($number === 1 ? '[er]' : '');
return $number . ($number === 1 || $number === '1' ? '[er]' : '');
},
"week" => array(
"dow" => 1, // Monday is the first day of the week.

View file

@ -15,7 +15,7 @@ return array(
"lastDay" => '[tegnap] l[-kor]',
"lastWeek" => function($n, $dir, \Moment\Moment $Moment){
$weekEndings = explode('_','vasárnap hétfőn kedden szerdán csütörtökön pénteken szombaton');
return '[múlt] [' . weekEndings[$Moment->getDay()] . '] l[-kor]';
return '[múlt] [' . $weekEndings[$Moment->getDay()] . '] l[-kor]';
},
"sameElse" => 'l',
"withTime" => 'H:i[-kor]',
@ -27,6 +27,9 @@ return array(
"s" => function($n, $dir){
return ($dir === 'future') ? 'néhány másodperc' : 'néhány másodperce';
},
"ss" => function($n, $dir){
return "$n " . ($dir === 'future' ? 'másodperc' : 'másodperce');
},
"m" => function($n, $dir){
return 'egy ' . ($dir === 'future' ? 'perc' : 'perce');
},

View file

@ -18,11 +18,12 @@ return array(
"default" => 'd/m/Y',
),
"relativeTime" => array(
"future" => '%s',
"past" => '%s',
"s" => 'beberapa detik yang lalu',
"m" => 'satu menit yang lalu',
"mm" => '%d menit yang lalu',
"future" => 'dalam %s',
"past" => '%s yang lalu',
"s" => 'beberapa detik',
"ss" => '%d detik',
"m" => 'semenit',
"mm" => '%d menit',
"h" => 'satu jam',
"hh" => '%d jam',
"d" => 'satu hari',

View file

@ -1,29 +1,48 @@
<?php
// locale: italia italiano (it_IT)
// author: Marco Micheli https://github.com/macfighterpilot
// author: Marco Manfredini https://github.com/Manfre98
use Moment\Moment;
return array(
"months" => explode('_', 'Gennaio_Febbraio_Marzo_Aprile_Maggio_Giugno_Luglio_Agosto_Settembre_Ottobre_Novembre_Dicembre'),
"monthsShort" => explode('_', 'Gen_Feb_Mar_Apr_Mag_Giu_Lug_Ago_Set_Ott_Nov_Dic'),
"weekdays" => explode('_', 'Lunedì_Martedì_Mercoledì_Giovedì_Venerdì_Sabato_Domenica'),
"weekdaysShort" => explode('_', 'Lun_Mar_Mer_Gio_Ven_Sab_Dom'),
"months" => explode('_', 'gennaio_febbraio_marzo_aprile_maggio_giugno_luglio_agosto_settembre_ottobre_novembre_dicembre'),
"monthsShort" => explode('_', 'gen_feb_mar_apr_mag_giu_lug_ago_set_ott_nov_dic'),
"weekdays" => explode('_', 'lunedì_martedì_mercoledì_giovedì_venerdì_sabato_domenica'),
"weekdaysShort" => explode('_', 'lun_mar_mer_gio_ven_sab_dom'),
"calendar" => array(
"sameDay" => '[Oggi]',
"nextDay" => '[Domani]',
"lastDay" => '[Ieri]',
"lastWeek" => '[Scorsa] l',
"lastWeek" => function (Moment $moment) {
switch ($moment->getWeekday()) {
case 7:
return 'l [scorsa]';
default:
return 'l [scorso]';
}
},
"sameElse" => 'l',
"withTime" => '[alle] H:i',
"withTime" => function (Moment $moment) {
switch ($moment->getHour()) {
case 0:
return '[a] G:i';
case 1:
return '[all\']G:i';
default:
return '[alle] G:i';
}
},
"default" => 'd/m/Y',
),
"relativeTime" => array(
"future" => 'tra %s',
"past" => '%s fa',
"s" => 'pochi secondi',
"s" => 'alcuni secondi',
"ss" => '%d secondi',
"m" => 'un minuto',
"mm" => '%d minuti',
"h" => 'una ora',
"h" => 'un\'ora',
"hh" => '%d ore',
"d" => 'un giorno',
"dd" => '%d giorni',
@ -34,10 +53,22 @@ return array(
),
"ordinal" => function ($number)
{
return $number . '';
return $number . 'º';
},
"week" => array(
"dow" => 1, // Monday is the first day of the week.
"doy" => 4 // The week that contains Jan 4th is the first week of the year.
"doy" => 4 // The week that contains Jan 4th is the first week of the year.
),
"customFormats" => array(
"LT" => "G:i", // 22:00
"LTS" => "G:i:s", // 22:00:00
"L" => "d/m/Y", // 12/06/2010
"l" => "j/n/Y", // 12/6/2010
"LL" => "j F Y", // 12 giugno 2010
"ll" => "j M Y", // 12 giu 2010
"LLL" => "j F Y, G:i", // 12 giugno 2010, 22:00
"lll" => "j M Y, G:i", // 12 giu 2010, 22:00
"LLLL" => "l j F Y, G:i", // sabato 12 giugno 2010, 22:00
"llll" => "D j M Y, G:i", // sab 12 giu 2010, 22:00
),
);

View file

@ -19,6 +19,7 @@ return array(
"future" => '%s後',
"past" => '%s前',
"s" => '数秒',
"ss" => '%d秒',
"m" => '1分',
"mm" => '%d分',
"h" => '1時間',

View file

@ -0,0 +1,59 @@
<?php
// locale: Korean
// author: amouro https://github.com/amouro
return array(
"months" => explode('_', '1월_2월_3월_4월_5월_6월_7월_8월_9월_10월_11월_12월'),
"monthsShort" => explode('_', '1월_2월_3월_4월_5월_6월_7월_8월_9월_10월_11월_12월'),
"weekdays" => explode('_', '일요일_월요일_화요일_수요일_목요일_금요일_토요일'),
"weekdaysShort" => explode('_', '일_월_화_수_목_금_토'),
"weekdaysMin" => explode('_', '일_월_화_수_목_금_토'),
"calendar" => array(
"sameDay" => '[오늘] LT',
"nextDay" => '[내일] LT',
"lastDay" => '[어제] LT',
"lastWeek" => '[지난주] dddd LT',
"sameElse" => 'L',
"withTime" => 'H:i',
"default" => 'Y년 m월 d일',
),
"relativeTime" => array(
"future" => '%s 후',
"past" => '%s 전',
"s" => '몇 초',
"ss" => '%d 초',
"m" => '1 분',
"mm" => '%d 분',
"h" => '한 시간',
"hh" => '%d 시간',
"d" => '하루',
"dd" => '%d 일',
"M" => '한 달',
"MM" => '%d 달',
"y" => '일 년',
"yy" => '%d 년',
),
"ordinal" => function ($number, $token)
{
$symbol = null;
switch ($token)
{
case 'd':
case 'D':
case 'DDD':
$symbol = '일';
case 'M':
$symbol = '월';
case 'w':
case 'W':
$symbol = '주';
default:
}
return $number . $symbol;
},
"week" => array(
"dow" => 1, // Monday is the first day of the week.
"doy" => 4 // The week that contains Jan 4th is the first week of the year.
),
);

View file

@ -0,0 +1,56 @@
<?php
// locale: Latviešu (Latvian) (lv_LV)
// author: Artjoms Nemiro https://github.com/LinMAD
return array(
'months' => explode(
'_',
'Janvārī_Februārī_Martā_Aprīlī_Maijā_Jūnijā_Jūlijā_Augustā_Septembrī_Oktobrī_Novembrī_Decembrī'
),
'monthsNominative' => explode(
'_',
'Janvāris_Februāris_Marts_Aprīlis_Maijs_Jūnijs_Jūlijs_Augusts_Septembris_Oktobris_Novembris_Decembris'
),
'monthsShort' => explode(
'_',
'Janv_Febr_Mar_Apr_Maijs_Jūn_Jūl_Aug_Sept_Okt_Nov_Dec'
),
'weekdays' => explode(
'_',
'Pirmdiena_Otrdiena_Trešdiena_Ceturtdiena_Piektdiena_Sestdiena_Svētdiena'
),
'weekdaysShort' => explode('_', 'Pr_Ot_Tr_Ce_Pk_Se_Sv'),
'calendar' => array(
'sameDay' => '[Šodien]',
'nextDay' => '[Rītdien]',
'lastDay' => '[Vakardien]',
'lastWeek' => '[Pagājušā] l',
'sameElse' => 'l',
'withTime' => '[plkst.] H:i',
'default' => 'd.m.Y',
),
'relativeTime' => array(
'future' => 'pēc %s',
'past' => 'pirms %s',
's' => 'dažām sekundēm',
'ss' => '%d sekundēm',
'm' => 'minūtes',
'mm' => '%d minūtēm',
'h' => 'stundas',
'hh' => '%d stundām',
'd' => 'dienas',
'dd' => '%d dienām',
'M' => 'mēneša',
'MM' => '%d mēnešiem',
'y' => 'gada',
'yy' => '%d gadiem',
),
'ordinal' => function ($number) {
return $number . '.';
},
'week' => array(
'dow' => 1, // Monday is the first day of the week.
'doy' => 4 // The week that contains Jan 4th is the first week of the year.
),
);

View file

@ -21,6 +21,7 @@ return array(
"future" => 'in %s',
"past" => '%s geleden',
"s" => 'een paar seconden',
"ss" => '%d seconden',
"m" => 'een minuut',
"mm" => '%d minuten',
"h" => 'een uur',
@ -41,6 +42,7 @@ return array(
"doy" => 4 // The week that contains Jan 4th is the first week of the year.
),
"customFormats" => array(
"LTS" => "G:i:s", // 20:30:15
"LT" => "G:i", // 20:30
"L" => "d/m/Y", // 04/09/1986
"l" => "j/n/Y", // 4/9/1986

View file

@ -0,0 +1,43 @@
<?php
// locale: norweigan (no-NO)
return array(
"months" => explode('_', 'januar_februar_mars_april_mai_juni_juli_august_september_oktober_november_desember'),
"monthsShort" => explode('_', 'jan_feb_mars_apr_mai_jun_jul_aug_sep_okt_nov_des'),
"weekdays" => explode('_', 'mandag_tirsdag_onsdag_torsdag_fredag_lørdag_søndag'),
"weekdaysShort" => explode('_', 'man_tir_ons_tor_fre_lør_søn'),
"calendar" => array(
"sameDay" => '[I dag]',
"nextDay" => '[I morgen]',
"lastDay" => '[I går]',
"lastWeek" => '[Sidste] l',
"sameElse" => 'l',
"withTime" => '[kl] H:i',
"default" => 'd/m/Y',
),
"relativeTime" => array(
"future" => 'om %s',
"past" => '%s siden',
"s" => 'få sekunder',
"ss" => '%d sekunder',
"m" => 'ett minutt',
"mm" => '%d minutter',
"h" => 'en time',
"hh" => '%d timer',
"d" => 'en dag',
"dd" => '%d dager',
"M" => 'en måned',
"MM" => '%d måneder',
"y" => 'et år',
"yy" => '%d år',
),
"ordinal" => function ($number) {
return $number . '.';
},
"week" => array(
"dow" => 1, // Monday is the first day of the week.
"doy" => 4 // The week that contains Jan 4th is the first week of the year.
),
);

View file

@ -21,6 +21,7 @@ return array(
"future" => 'dins %s',
"past" => 'fa %s',
"s" => 'unas segondas',
"ss" => '%d segondas',
"m" => 'una minuta',
"mm" => '%d minutas',
"h" => 'una ora',

View file

@ -46,6 +46,10 @@ return array(
"future" => 'za %s',
"past" => '%s temu',
"s" => 'kilka sekund',
"ss" => function ($count) use ($ifLastDigitIsSpecial)
{
return $ifLastDigitIsSpecial($count, '%d sekundy', '%d sekund');
},
"m" => '1 minutę',
"mm" => function ($count) use ($ifLastDigitIsSpecial)
{

View file

@ -14,7 +14,7 @@ return array(
"sameDay" => '[hoje]',
"nextDay" => '[amanhã]',
"lastDay" => '[ontem]',
"lastWeek" => '[útimo] l',
"lastWeek" => '[último] l',
"sameElse" => 'eu',
"withTime" => function (Moment $moment) { return '[à' . ($moment->getHour() !== 1 ? 's' : null) . '] H:i'; },
"default" => 'd/m/Y',
@ -23,6 +23,7 @@ return array(
"future" => 'em %s',
"past" => 'há %s',
"s" => 'alguns segundos',
"ss" => '%d segundos',
"m" => 'um minuto',
"mm" => '%d minutos',
"h" => 'uma hora',

View file

@ -43,6 +43,7 @@ return array(
"future" => 'peste %s',
"past" => 'În urmă cu %s',
"s" => 'câteva secunde',
"ss" => '%d secunde',
"m" => 'un minut',
"mm" => function ($count, $direction, Moment $m) use ($rtwp)
{

View file

@ -61,6 +61,10 @@ return array(
'future' => 'через %s',
'past' => '%s назад',
's' => 'несколько секунд',
'ss' => function ($number) use ($getNumEnding)
{
return $getNumEnding($number, array('%d секунду', '%d секунды', '%d секунд'));
},
'm' => 'минуту',
'mm' => function ($number) use ($getNumEnding)
{

View file

@ -21,6 +21,7 @@ return array(
"future" => 'om %s',
"past" => '%s sen',
"s" => 'några sekunder',
"ss" => '%d sekunder',
"m" => 'en minut',
"mm" => '%d minuter',
"h" => 'en timme',

View file

@ -21,6 +21,7 @@ return array(
"future" => 'อีก %s',
"past" => '%s ที่แล้ว',
"s" => 'ไม่กี่วินาที',
"ss" => '%d วินาที',
"m" => '1 นาที',
"mm" => '%d นาที',
"h" => '1 ชั่วโมง',

View file

@ -24,6 +24,7 @@ return array(
"future" => '%s sonra',
"past" => '%s önce',
"s" => 'birkaç saniye',
"ss" => '%d saniye',
"m" => 'bir dakika',
"mm" => '%d dakika',
"h" => 'bir saat',

View file

@ -68,6 +68,7 @@ return array(
},
'past' => '%s тому',
's' => 'кілька секунд',
'ss' => 'кілька секунд', // needs review by native speaker see https://github.com/fightbulc/moment.php/issues/166
'm' => 'хвилину',
'mm' => function ($number) use ($getNumEnding)
{

View file

@ -22,6 +22,7 @@ return array(
"future" => 'vào %s',
"past" => '%s trước đây',
"s" => 'một vài giây',
"ss" => '%d giây',
"m" => 'một phút',
"mm" => '%d phút',
"h" => 'một giờ',

View file

@ -25,6 +25,7 @@ return array(
"future" => '%s内',
"past" => '%s前',
"s" => '几秒',
"ss" => '%d秒',
"m" => '1分钟',
"mm" => '%d分钟',
"h" => '1小时',

View file

@ -7,7 +7,7 @@
return array(
"months" => explode('_', '一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月'),
"monthsShort" => explode('_', '1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月'),
"monthsShort" => explode('_', '1 月_2 月_3 月_4 月_5 月_6 月_7 月_8 月_9 月_10 月_11 月_12 月'),
"weekdays" => explode('_', '星期一_星期二_星期三_星期四_星期五_星期六_星期日'),
"weekdaysShort" => explode('_', '週一_週二_週三_週四_週五_週六_週日'),
"weekdaysMin" => explode('_', '一_二_三_四_五_六_日'),
@ -24,16 +24,17 @@ return array(
"future" => '%s內',
"past" => '%s前',
"s" => '幾秒',
"m" => '一分鐘',
"mm" => '%d分鐘',
"h" => '一小時',
"hh" => '%d小時',
"d" => '一天',
"dd" => '%d天',
"M" => '一個月',
"MM" => '%d個月',
"y" => '一年',
"yy" => '%d年',
"ss" => '%d秒',
"m" => '1 分鐘',
"mm" => '%d 分鐘',
"h" => '1 小時',
"hh" => '%d 小時',
"d" => '1 天',
"dd" => '%d 天',
"M" => '1 個月',
"MM" => '%d 個月',
"y" => '1 年',
"yy" => '%d 年',
),
"ordinal" => function ($number, $token)
{

View file

@ -37,13 +37,14 @@ class Moment extends \DateTime
/**
* @param string $locale
* @param bool $findSimilar
*
* @throws MomentException
*/
public static function setLocale($locale)
public static function setLocale($locale, $findSimilar = false)
{
// set current language
MomentLocale::setLocale($locale);
MomentLocale::setLocale($locale, $findSimilar);
}
/**
@ -58,9 +59,64 @@ class Moment extends \DateTime
}
/**
* @param string $dateTime
* Creates a new Moment from a DateTime
*
* @param \DateTimeInterface $date
*
* @return Moment
* @throws MomentException
*/
public static function fromDateTime(\DateTimeInterface $date)
{
$moment = new static('@' . $date->format('U'));
$moment->setTimezone($date->getTimezone());
if ($date instanceof \DateTimeImmutable)
{
$moment->setImmutableMode(true);
}
return $moment;
}
/**
* Workaround for {@see https://bugs.php.net/bug.php?id=60302} and
* {@see https://github.com/fightbulc/moment.php/issues/89}
*
* @param string $format format of the date
* @param string $time date string to parse
* @param null|\DateTimeZone $timezone optional timezone to parse the string with
* @param null|FormatsInterface $formatsInterface optional interface to use for {@see $format}.
*
* @return static
* @throws MomentException
*/
public static function createFromFormat($format, $time, $timezone = null, FormatsInterface $formatsInterface = null)
{
// handle diverse format types
if ($formatsInterface instanceof FormatsInterface)
{
// merge localized custom formats
$localeContent = MomentLocale::getLocaleContent();
if (isset($localeContent['customFormats']) && is_array($localeContent['customFormats']))
{
$formatsInterface->setTokens($localeContent['customFormats']);
}
$format = $formatsInterface->format($format);
}
$date = $timezone ?
parent::createFromFormat($format, $time, $timezone) :
parent::createFromFormat($format, $time);
return static::fromDateTime($date);
}
/**
* @param string $dateTime
* @param string|null $timezone
* @param bool $immutableMode
* @param bool $immutableMode
*
* @throws MomentException
*/
@ -103,11 +159,14 @@ class Moment extends \DateTime
*
* @return $this
* @throws MomentException
* @throws \Exception
*/
public function resetDateTime($dateTime = 'now', $timezone = null)
{
$lengthDateTime = strlen((int)$dateTime);
// unix timestamp helper
if (strlen((int)$dateTime) === 10)
if ($lengthDateTime >= 9 && $lengthDateTime <= 10)
{
$dateTime = '@' . $dateTime;
}
@ -129,7 +188,7 @@ class Moment extends \DateTime
parent::__construct($dateTime, $this->getDateTimeZone($timezone));
// set timezone if unix time
if (strpos($dateTime, '@') !== false)
if (strpos($dateTime, '@') !== false && $timezone)
{
$this->setTimezone($timezone);
}
@ -144,7 +203,7 @@ class Moment extends \DateTime
}
/**
* @param string $timezone
* @param string|\DateTimeZone $timezone
*
* @return \DateTime|Moment
*/
@ -155,6 +214,11 @@ class Moment extends \DateTime
return $this->implicitCloning(__FUNCTION__, func_get_args());
}
if ($timezone instanceof \DateTimeZone)
{
$timezone = $timezone->getName();
}
$this->setTimezoneString($timezone);
parent::setTimezone($this->getDateTimeZone($timezone));
@ -163,7 +227,7 @@ class Moment extends \DateTime
}
/**
* @param null|string $format
* @param null|string $format
* @param null|FormatsInterface $formatsInterface
*
* @return string
@ -616,8 +680,8 @@ class Moment extends \DateTime
}
/**
* @param int $hour
* @param int $minute
* @param int $hour
* @param int $minute
* @param int|null $second
* @param int|null $microseconds
*
@ -637,9 +701,10 @@ class Moment extends \DateTime
/**
* @param string|Moment $fromMoment
* @param null $timezoneString
* @param null $timezoneString
*
* @return MomentFromVo
* @throws MomentException
*/
public function from($fromMoment = 'now', $timezoneString = null)
{
@ -669,6 +734,7 @@ class Moment extends \DateTime
* @param null $timezoneString
*
* @return MomentFromVo
* @throws MomentException
*/
public function fromNow($timezoneString = null)
{
@ -690,7 +756,7 @@ class Moment extends \DateTime
/**
* @param string $type
* @param int $value
* @param int $value
*
* @return Moment
*/
@ -835,7 +901,7 @@ class Moment extends \DateTime
}
/**
* @param bool $withTime
* @param bool $withTime
* @param Moment|null $refMoment
*
* @return string
@ -1020,11 +1086,11 @@ class Moment extends \DateTime
/**
* @param string $method
* @param array $params
* @param array $params
*
* @return self
*/
private function implicitCloning($method, $params = array())
protected function implicitCloning($method, $params = array())
{
$clone = $this->cloning();
@ -1037,7 +1103,7 @@ class Moment extends \DateTime
/**
* @param array $weekdayNumbers
* @param int $forUpcomingWeeks
* @param int $forUpcomingWeeks
*
* @return Moment[]
* @throws MomentException
@ -1083,7 +1149,7 @@ class Moment extends \DateTime
* Check if a moment is the same as another moment
*
* @param string|Moment $dateTime
* @param string $period 'seconds|minute|hour|day|month|year'
* @param string $period 'seconds|minute|hour|day|month|year'
*
* @return bool
* @throws MomentException
@ -1099,7 +1165,7 @@ class Moment extends \DateTime
* Checks if Moment is before given time
*
* @param string|Moment $dateTime
* @param string $period 'seconds|minute|hour|day|month|year'
* @param string $period 'seconds|minute|hour|day|month|year'
*
* @return bool
* @throws MomentException
@ -1115,7 +1181,7 @@ class Moment extends \DateTime
* Checks if Moment is after given time
*
* @param string|Moment $dateTime
* @param string $period 'seconds|minute|hour|day|month|year'
* @param string $period 'seconds|minute|hour|day|month|year'
*
* @return bool
* @throws MomentException
@ -1132,8 +1198,8 @@ class Moment extends \DateTime
*
* @param string|Moment $minDateTime
* @param string|Moment $maxDateTime
* @param boolean $closed
* @param string $period 'seconds|minute|hour|day|month|year'
* @param boolean $closed
* @param string $period 'seconds|minute|hour|day|month|year'
*
* @return bool
* @throws MomentException
@ -1304,12 +1370,33 @@ class Moment extends \DateTime
$momentDateTime = $this->format(self::NO_TIME);
}
return $rawDateTime === $momentDateTime;
$isValid = $rawDateTime === $momentDateTime;
// TODO: hack until we include a proper validation
if (!$isValid)
{
$rfcs = array(
self::RFC2822,
self::RFC822,
self::RFC1036,
);
foreach ($rfcs as $rfc)
{
if ($this->format($rfc) === $rawDateTime)
{
return true;
}
}
}
return $isValid;
}
/**
* @param string $type
* @param int $value
* @param int $value
*
* @return Moment
*/
@ -1326,7 +1413,7 @@ class Moment extends \DateTime
}
/**
* @param int $number
* @param int $number
* @param string $token
*
* @return string
@ -1336,4 +1423,5 @@ class Moment extends \DateTime
{
return (string)call_user_func(MomentLocale::getLocaleString(array('ordinal')), $number, $token);
}
}

View file

@ -225,47 +225,52 @@ class MomentFromVo
{
$formatArgs = array();
if ($this->valueInRange($this->getSeconds(), 0, 45))
if ($this->valueInRange($this->getSeconds(), 0, 3))
{
$localeKeys = array('relativeTime', 's');
$formatArgs[] = 1;
}
elseif ($this->valueInRange($this->getSeconds(), 45, 90))
elseif ($this->valueInRange($this->getSeconds(), 4, 59))
{
$localeKeys = array('relativeTime', 'ss');
$formatArgs[] = $this->roundAbs($this->getSeconds());
}
elseif ($this->valueInRange($this->getSeconds(), 60, 89))
{
$localeKeys = array('relativeTime', 'm');
$formatArgs[] = 1;
}
elseif ($this->valueInRange($this->getSeconds(), 90, 45 * 60))
elseif ($this->valueInRange($this->getSeconds(), 90, (45 * 60)-1))
{
$localeKeys = array('relativeTime', 'mm');
$formatArgs[] = $this->roundAbs($this->getMinutes());
}
elseif ($this->valueInRange($this->getMinutes(), 45, 90))
elseif ($this->valueInRange($this->getMinutes(), 45, 89))
{
$localeKeys = array('relativeTime', 'h');
$formatArgs[] = 1;
}
elseif ($this->valueInRange($this->getMinutes(), 90, 22 * 60))
elseif ($this->valueInRange($this->getMinutes(), 90, (22 * 60)-1))
{
$localeKeys = array('relativeTime', 'hh');
$formatArgs[] = $this->roundAbs($this->getHours());
}
elseif ($this->valueInRange($this->getHours(), 22, 36))
elseif ($this->valueInRange($this->getHours(), 22, 35))
{
$localeKeys = array('relativeTime', 'd');
$formatArgs[] = 1;
}
elseif ($this->valueInRange($this->getHours(), 36, 25 * 24))
elseif ($this->valueInRange($this->getHours(), 36, (25 * 24)-1))
{
$localeKeys = array('relativeTime', 'dd');
$formatArgs[] = $this->roundAbs($this->getDays());
}
elseif ($this->valueInRange($this->getDays(), 25, 45))
elseif ($this->valueInRange($this->getDays(), 25, 44))
{
$localeKeys = array('relativeTime', 'M');
$formatArgs[] = 1;
}
elseif ($this->valueInRange($this->getDays(), 25, 345))
elseif ($this->valueInRange($this->getDays(), 45, 344))
{
$localeKeys = array('relativeTime', 'MM');
$formatArgs[] = $this->roundAbs($this->getMonths());
@ -313,4 +318,4 @@ class MomentFromVo
{
return round(abs($number));
}
}
}

View file

@ -19,6 +19,11 @@ class MomentLocale
*/
private static $locale = 'en_GB';
/**
* @var boolean
*/
private static $findSimilar = false;
/**
* @var array
*/
@ -33,14 +38,16 @@ class MomentLocale
}
/**
* @param $locale
* @param string $locale
* @param bool $findSimilar
*
* @return void
* @throws MomentException
*/
public static function setLocale($locale)
public static function setLocale($locale, $findSimilar = false)
{
self::$locale = $locale;
self::$findSimilar = $findSimilar;
self::loadLocaleContent();
}
@ -50,13 +57,14 @@ class MomentLocale
*/
public static function loadLocaleContent()
{
$pathFile = __DIR__ . '/Locales/' . self::$locale . '.php';
$pathFile = self::findLocaleFile();
if (file_exists($pathFile) === false)
if (!$pathFile)
{
throw new MomentException('Locale does not exist: ' . $pathFile);
}
/** @noinspection PhpIncludeInspection */
self::$localeContent = require $pathFile;
}
@ -82,6 +90,12 @@ class MomentLocale
{
if (isset($string[$key]) === false)
{
if ($key == 'monthsNominative' && isset($string['months']))
{
$string = $string['months'];
continue;
}
throw new MomentException('Locale string does not exist for key: ' . join(' > ', $keys));
}
@ -96,6 +110,7 @@ class MomentLocale
* @param array $formatArgs
*
* @return string
* @throws MomentException
*/
public static function renderLocaleString(array $localeKeys, array $formatArgs = array())
{
@ -140,6 +155,7 @@ class MomentLocale
* @param string $format
*
* @return string
* @throws MomentException
*/
public static function renderSpecialLocaleTags($format)
{
@ -170,4 +186,42 @@ class MomentLocale
return $format;
}
/**
* @return null|string
*/
private static function findLocaleFile()
{
$basePathFile = __DIR__ . '/Locales/' . self::$locale;
$pathFile = $basePathFile . '.php';
if (file_exists($pathFile) === false)
{
$pathFile = null;
if (self::$findSimilar && $similarLocales = self::fetchSimilarLocales($basePathFile))
{
$pathFile = $similarLocales[0];
}
}
return $pathFile;
}
/**
* @param string $path
*
* @return null|array
*/
private static function fetchSimilarLocales($path)
{
$locales = glob($path . '*.php');
if ($locales && !empty($locales))
{
return $locales;
}
return null;
}
}

View file

@ -6,4 +6,9 @@
<directory>unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="false">
<directory suffix=".php">../src/</directory>
</whitelist>
</filter>
</phpunit>

View file

@ -116,15 +116,15 @@
<p>{{test07.00}}</p>
<p><strong>Default locale (L):</strong> {{test07.01}}</p>
<p><strong>fr_FR locale (LT):</strong> {{test07.02}}</p>
<p><strong>fr_FR locale (L):</strong> {{test07.03}}</p>
<p><strong>fr_FR locale (l):</strong> {{test07.04}}</p>
<p><strong>fr_FR locale (LL):</strong> {{test07.05}}</p>
<p><strong>fr_FR locale (ll):</strong> {{test07.06}}</p>
<p><strong>fr_FR locale (LLL):</strong> {{test07.07}}</p>
<p><strong>fr_FR locale (lll):</strong> {{test07.08}}</p>
<p><strong>fr_FR locale (LLLL):</strong> {{test07.09}}</p>
<p><strong>fr_FR locale (llll):</strong> {{test07.10}}</p>
<p><strong>{{test07.locale}} locale (LT):</strong> {{test07.02}}</p>
<p><strong>{{test07.locale}} locale (L):</strong> {{test07.03}}</p>
<p><strong>{{test07.locale}} locale (l):</strong> {{test07.04}}</p>
<p><strong>{{test07.locale}} locale (LL):</strong> {{test07.05}}</p>
<p><strong>{{test07.locale}} locale (ll):</strong> {{test07.06}}</p>
<p><strong>{{test07.locale}} locale (LLL):</strong> {{test07.07}}</p>
<p><strong>{{test07.locale}} locale (lll):</strong> {{test07.08}}</p>
<p><strong>{{test07.locale}} locale (LLLL):</strong> {{test07.09}}</p>
<p><strong>{{test07.locale}} locale (llll):</strong> {{test07.10}}</p>
</div>
<div>

View file

@ -57,12 +57,13 @@ $response['test06.02'] = $m->setTimezone('UTC')->format();
// ------------------------------------------
$response['test07.locale'] = isset($_GET['locale']) ? $_GET['locale'] : 'fr_FR';
$m = new \Moment\Moment('2012-04-25T15:00:00', 'CET');
$response['test07.00'] = $m->format('l, dS F Y / H:i (e)');
$momentJs = new \Moment\CustomFormats\MomentJs();
$response['test07.01'] = $m->format('LT', $momentJs);
$m->setLocale('fr_FR');
$m->setLocale($response['test07.locale'], true);
$response['test07.02'] = $m->format('LT', $momentJs);
$response['test07.03'] = $m->format('L', $momentJs);
$response['test07.04'] = $m->format('l', $momentJs);

View file

@ -0,0 +1,144 @@
<?php
// locale: British English (en_GB)
// author: https://github.com/blacknell
namespace Moment;
use Moment\CustomFormats\MomentJs;
use PHPUnit\Framework\TestCase;
class MomentBritishEnglishLocaleTest extends TestCase
{
public function setUp()
{
Moment::setLocale('en_GB');
}
public function testWeekdayNames()
{
$startingDate = '2015-01-04T00:00:00+0000';
$moment = new Moment($startingDate);
$weekdayNames = array(
1 => array('Mon', 'Monday'),
2 => array('Tue', 'Tuesday'),
3 => array('Wed', 'Wednesday'),
4 => array('Thu', 'Thursday'),
5 => array('Fri', 'Friday'),
6 => array('Sat', 'Saturday'),
7 => array('Sun', 'Sunday'),
);
for ($d = 1; $d < 7; $d++) {
self::assertEquals($weekdayNames[$moment->getWeekday()][0], $moment->getWeekdayNameShort(), 'weekday short name failed');
self::assertEquals($weekdayNames[$moment->getWeekday()][1], $moment->getWeekdayNameLong(), 'weekday long name failed');
$moment->addDays(1);
}
}
public function testMonthNames()
{
$startingDate = '2015-01-04T00:00:00+0000';
$moment = new Moment($startingDate);
$monthNames = array(
1 => array('Jan', 'January'),
2 => array('Feb', 'February'),
3 => array('Mar', 'March'),
4 => array('Apr', 'April'),
5 => array('May', 'May'),
6 => array('Jun', 'June'),
7 => array('Jul', 'July'),
8 => array('Aug', 'August'),
9 => array('Sep', 'September'),
10 => array('Oct', 'October'),
11 => array('Nov', 'November'),
12 => array('Dec', 'December'),
);
for ($d = 1; $d < 12; $d++) {
self::assertEquals($monthNames[$moment->format('n')][0], $moment->getMonthNameShort(), 'month short name failed');
self::assertEquals($monthNames[$moment->format('n')][1], $moment->getMonthNameLong(), 'month long name failed');
$moment->addMonths(1);
}
}
public function testFormat()
{
$a = array(
array('l, d F Y, G:i:s', 'Saturday, 12 June 2010, 22:00:00'),
array('D, gA', 'Sat, 10PM'),
array('n m F M', '6 06 June Jun'),
array('Y y', '2010 10'),
array('j d', '12 12'),
array('[the] z [day of the year]', 'the 162 day of the year')
);
$b = new Moment('2010-06-12 22:00:00');
for ($i = 0; $i < count($a); $i++) {
self::assertEquals($a[$i][1], $b->format($a[$i][0]));
}
}
public function testCustomLocaleFormat()
{
$a = array(
array('LT', '22:00',),
array('LTS', '22:00:00'),
array('L', '12/06/2010'),
array('l', '12/6/2010'),
array('LL', '12 June 2010'),
array('ll', '12 Jun 2010'),
array('LLL', '12 June 2010 22:00'),
array('lll', '12 Jun 2010 22:00'),
array('LLLL', 'Saturday, 12 June June 2010 22:00'),
array('llll', 'Sat, 12 Jun 2010 22:00')
);
$b = new Moment('2010-06-12 22:00:00');
for ($i = 0; $i < count($a); $i++) {
self::assertEquals($a[$i][1], $b->format($a[$i][0], new MomentJs()));
}
}
public function testOrdinalsFormat()
{
$moment = new Moment('2010-06-02T00:00:00+0000');
self::assertEquals('2nd', $moment->format('jS'));
$moment = new Moment('2010-06-12T00:00:00+0000');
self::assertEquals('12th', $moment->format('jS'));
}
public function testRelative()
{
Moment::setLocale('en_GB');
$beginningMoment = new Moment('2010-06-12 00:00:00', 'Europe/London');
$a = array(
array(new Moment('2010-06-12 00:00:01', 'Europe/London'), 'in a few seconds', 'a few seconds ago', '0s - 3s'),
array(new Moment('2010-06-12 00:00:07', 'Europe/London'), 'in 7 seconds', '7 seconds ago', '4s - 59s'),
array(new Moment('2010-06-12 00:01:10', 'Europe/London'), 'in a minute', 'a minute ago', '60s - 89s'),
array(new Moment('2010-06-12 00:05:45', 'Europe/London'), 'in 6 minutes', '6 minutes ago', '90s - 45m'),
array(new Moment('2010-06-12 00:45:45', 'Europe/London'), 'in an hour', 'an hour ago', '45m - 89m'),
array(new Moment('2010-06-12 08:00:45', 'Europe/London'), 'in 8 hours', '8 hours ago', '90m - 22h'),
array(new Moment('2010-06-12 23:00:45', 'Europe/London'), 'in a day', 'a day ago', '22h - 35h'),
array(new Moment('2010-06-13 15:00:45', 'Europe/London'), 'in 2 days', '2 days ago', '36h - 25d'),
array(new Moment('2010-07-12 00:00:45', 'Europe/London'), 'in a month', 'a month ago', '25d - 44d'),
array(new Moment('2010-08-12 00:00:45', 'Europe/London'), 'in 2 months', '2 months ago', '45ds - 344d'),
array(new Moment('2011-06-12 00:00:45', 'Europe/London'), 'in a year', 'a year ago', '345d - 547d'),
array(new Moment('2013-06-12 00:00:45', 'Europe/London'), 'in 3 years', '3 years ago', '547d -'),
);
for ($i = 0; $i < count($a); $i++) {
$endMoment = $a[$i][0];
self::assertEquals($a[$i][1], $endMoment->from($beginningMoment)->getRelative(), $a[$i][3]);
self::assertEquals($a[$i][2], $beginningMoment->from($endMoment)->getRelative(), $a[$i][3]);
}
}
}

View file

@ -2,7 +2,9 @@
namespace Moment;
class MomentFrenchLocaleTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;
class MomentFrenchLocaleTest extends TestCase
{
public function setUp()
{
@ -27,8 +29,8 @@ class MomentFrenchLocaleTest extends \PHPUnit_Framework_TestCase
for ($d = 1; $d < 7; $d++)
{
$this->assertEquals($weekdayNames[$moment->getWeekday()][0], $moment->getWeekdayNameShort(), 'weekday short name failed');
$this->assertEquals($weekdayNames[$moment->getWeekday()][1], $moment->getWeekdayNameLong(), 'weekday long name failed');
self::assertEquals($weekdayNames[$moment->getWeekday()][0], $moment->getWeekdayNameShort(), 'weekday short name failed');
self::assertEquals($weekdayNames[$moment->getWeekday()][1], $moment->getWeekdayNameLong(), 'weekday long name failed');
$moment->addDays(1);
}
@ -57,8 +59,8 @@ class MomentFrenchLocaleTest extends \PHPUnit_Framework_TestCase
for ($d = 1; $d < 12; $d++)
{
$this->assertEquals($monthNames[$moment->format('n')][0], $moment->getMonthNameShort(), 'month short name failed');
$this->assertEquals($monthNames[$moment->format('n')][1], $moment->getMonthNameLong(), 'month long name failed');
self::assertEquals($monthNames[$moment->format('n')][0], $moment->getMonthNameShort(), 'month short name failed');
self::assertEquals($monthNames[$moment->format('n')][1], $moment->getMonthNameLong(), 'month long name failed');
$moment->addMonths(1);
}
@ -76,7 +78,7 @@ class MomentFrenchLocaleTest extends \PHPUnit_Framework_TestCase
);
$b = new Moment('2010-02-14 15:25:50');
for ($i = 0; $i < count($a); $i++) {
$this->assertEquals($a[$i][1], $b->format($a[$i][0]));
self::assertEquals($a[$i][1], $b->format($a[$i][0]));
}
}
@ -84,7 +86,7 @@ class MomentFrenchLocaleTest extends \PHPUnit_Framework_TestCase
{
$beginningMoment = new Moment('2015-06-14 20:46:22', 'Europe/Berlin');
$endMoment = new Moment('2015-06-14 20:48:32', 'Europe/Berlin');
$this->assertEquals('dans 2 minutes', $endMoment->from($beginningMoment)->getRelative());
$this->assertEquals('il y a 2 minutes', $beginningMoment->from($endMoment)->getRelative());
self::assertEquals('dans 2 minutes', $endMoment->from($beginningMoment)->getRelative());
self::assertEquals('il y a 2 minutes', $beginningMoment->from($endMoment)->getRelative());
}
}

View file

@ -2,7 +2,9 @@
namespace Moment;
class MomentGermanLocaleTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;
class MomentGermanLocaleTest extends TestCase
{
public function setUp()
{
@ -27,8 +29,8 @@ class MomentGermanLocaleTest extends \PHPUnit_Framework_TestCase
for ($d = 1; $d < 7; $d++)
{
$this->assertEquals($weekdayNames[$moment->getWeekday()][0], $moment->getWeekdayNameShort(), 'weekday short name failed');
$this->assertEquals($weekdayNames[$moment->getWeekday()][1], $moment->getWeekdayNameLong(), 'weekday long name failed');
self::assertEquals($weekdayNames[$moment->getWeekday()][0], $moment->getWeekdayNameShort(), 'weekday short name failed');
self::assertEquals($weekdayNames[$moment->getWeekday()][1], $moment->getWeekdayNameLong(), 'weekday long name failed');
$moment->addDays(1);
}
@ -57,8 +59,8 @@ class MomentGermanLocaleTest extends \PHPUnit_Framework_TestCase
for ($d = 1; $d < 12; $d++)
{
$this->assertEquals($monthNames[$moment->format('n')][0], $moment->getMonthNameShort(), 'month short name failed');
$this->assertEquals($monthNames[$moment->format('n')][1], $moment->getMonthNameLong(), 'month long name failed');
self::assertEquals($monthNames[$moment->format('n')][0], $moment->getMonthNameShort(), 'month short name failed');
self::assertEquals($monthNames[$moment->format('n')][1], $moment->getMonthNameLong(), 'month long name failed');
$moment->addMonths(1);
}
@ -70,11 +72,11 @@ class MomentGermanLocaleTest extends \PHPUnit_Framework_TestCase
$string = '2015-06-14 20:46:22';
$moment = new Moment($string, 'Europe/Berlin');
$this->assertEquals('14. Juni', $moment->format('d. F'));
self::assertEquals('14. Juni', $moment->format('d. F'));
$string = '2015-03-08T15:14:53-0500';
$moment = new Moment($string, 'Europe/Berlin');
$this->assertEquals('08. März', $moment->format('d. F'));
self::assertEquals('08. März', $moment->format('d. F'));
}
public function testHirbodIssueLocaleDate002()
@ -82,6 +84,12 @@ class MomentGermanLocaleTest extends \PHPUnit_Framework_TestCase
// @see: https://github.com/fightbulc/moment.php/issues/61
$moment = new Moment('2016-01-03 16:17:07', 'Europe/Berlin');
$this->assertEquals('03. Dezember', $moment->subtractMonths(1)->format('d. F'));
self::assertEquals('03. Dezember', $moment->subtractMonths(1)->format('d. F'));
}
}
public function testMonthsNominativeFallback()
{
$moment = new Moment('2016-01-03 16:17:07', 'Europe/Berlin');
self::assertEquals('Januar 2016', $moment->format('f Y'));
}
}

View file

@ -0,0 +1,184 @@
<?php
namespace Moment;
use PHPUnit\Framework\TestCase;
class MomentLatvianLocaleTest extends TestCase
{
public function setUp()
{
Moment::setLocale('lv_LV');
}
public function testWeekdayNames()
{
$startingDate = '2017-10-20T00:00:00+0000';
$moment = new Moment($startingDate);
$weekdayNames = array(
1 => array('Pr', 'Pirmdiena'),
2 => array('Ot', 'Otrdiena'),
3 => array('Tr', 'Trešdiena'),
4 => array('Ce', 'Ceturtdiena'),
5 => array('Pk', 'Piektdiena'),
6 => array('Se', 'Sestdiena'),
7 => array('Sv', 'Svētdiena'),
);
for ($d = 1; $d < 7; $d++) {
// Check short names
self::assertEquals(
$weekdayNames[$moment->getWeekday()][0],
$moment->getWeekdayNameShort(),
'weekday short name failed'
);
// Check long names
self::assertEquals(
$weekdayNames[$moment->getWeekday()][1],
$moment->getWeekdayNameLong(),
'weekday long name failed'
);
$moment->addDays(); // Add one day
}
}
public function testMonthFormat()
{
$startingDate = '2016-01-01T00:00:00+0000';
$moment = new Moment($startingDate);
$months = array(
'01' => array('Janv', 'Janvāris', 'Janvārī'),
'02' => array('Febr', 'Februāris', 'Februārī'),
'03' => array('Mar', 'Marts', 'Martā'),
'04' => array('Apr', 'Aprīlis', 'Aprīlī'),
'05' => array('Maijs', 'Maijs', 'Maijā'),
'06' => array('Jūn', 'Jūnijs', 'Jūnijā'),
'07' => array('Jūl', 'Jūlijs', 'Jūlijā'),
'08' => array('Aug', 'Augusts', 'Augustā'),
'09' => array('Sept', 'Septembris', 'Septembrī'),
'10' => array('Okt', 'Oktobris', 'Oktobrī'),
'11' => array('Nov', 'Novembris', 'Novembrī'),
'12' => array('Dec', 'Decembris', 'Decembrī'),
);
$moment->format('f');
for ($d = 1, $dMax = \count($months); $d < $dMax; $d++) {
// Check short names
self::assertEquals(
$months[$moment->getMonth()][0],
$moment->getMonthNameShort(),
'moths short name failed'
);
// Check long names months
self::assertEquals(
$months[$moment->getMonth()][1],
$moment->format('f'),
'moths long name failed'
);
// Check long names nominative
self::assertEquals(
$months[$moment->getMonth()][2],
$moment->getMonthNameLong(),
'moths long name in nominative failed'
);
$moment->addMonths();
}
}
public function testDayMonthFormat001()
{
$string = '2015-06-14 20:46:22';
$moment = new Moment($string, 'Europe/Riga');
self::assertEquals('14 Jūnijā', $moment->format('j F'));
$string = '2015-03-08T15:14:53-0500';
$moment = new Moment($string, 'Europe/Riga');
self::assertEquals('8 Martā', $moment->format('j F'));
}
public function testMinutes()
{
$past = new Moment('2016-01-03 16:17:07', 'Europe/Riga');
$relative = $past->from('2016-01-03 16:34:07');
self::assertEquals('pirms 17 minūtēm', $relative->getRelative());
}
public function testShowRelativeCalendarDates()
{
$past = new Moment('2016-04-10 16:30:07');
self::assertEquals('Pagājušā Svētdiena plkst. 16:30', $past->calendar(true, new Moment('2016-04-12')));
$past = new Moment('2016-04-10');
self::assertEquals('Pagājušā Svētdiena', $past->calendar(false, new Moment('2016-04-13')));
$past = new Moment('2016-04-13');
self::assertEquals('Trešdiena', $past->calendar(false, new Moment('2016-04-11')));
$past = new Moment('2016-04-13');
self::assertEquals('Vakardien', $past->calendar(false, new Moment('2016-04-14')));
$past = new Moment('2016-04-12');
self::assertEquals('Šodien', $past->calendar(false, new Moment('2016-04-12')));
$past = new Moment('2016-04-13');
self::assertEquals('Rītdien', $past->calendar(false, new Moment('2016-04-12')));
$past = new Moment('2116-04-15');
self::assertEquals('15.04.2116', $past->calendar(false, new Moment('2017-04-23')));
}
public function testFutureRelative()
{
$date = new Moment('2017-01-11 01:00:00');
self::assertEquals('pēc dažām sekundēm', $date->from('2017-01-11 00:59:59')->getRelative(), 'seconds');
self::assertEquals('pēc 2 minūtēm', $date->from('2017-01-11 00:58:00')->getRelative(), 'minutes');
self::assertEquals('pēc 2 stundām', $date->from('2017-01-10 23:00:00')->getRelative(), 'hours');
self::assertEquals('pēc dienas', $date->from('2017-01-10 00:00:00')->getRelative(), 'days');
self::assertEquals('pēc 10 dienām', $date->from('2017-01-01 00:00:00')->getRelative(), 'days');
self::assertEquals('pēc mēneša', $date->from('2016-12-11 00:00:00')->getRelative(), 'month');
self::assertEquals('pēc 3 mēnešiem', $date->from('2016-10-11 00:00:00')->getRelative(), 'month');
self::assertEquals('pēc gada', $date->from('2016-01-11 00:00:00')->getRelative(), 'year');
self::assertEquals('pēc 7 gadiem', $date->from('2010-01-11 00:00:00')->getRelative(), 'year');
}
public function testPastRelative()
{
$date = new Moment('2010-01-11 01:00:00');
self::assertEquals('pirms dažām sekundēm', $date->from('2010-01-11 01:00:01')->getRelative(), 'seconds');
self::assertEquals('pirms 10 sekundēm', $date->from('2010-01-11 01:00:10')->getRelative(), 'seconds');
self::assertEquals('pirms 2 minūtēm', $date->from('2010-01-11 01:02:00')->getRelative(), 'minutes');
self::assertEquals('pirms 2 stundām', $date->from('2010-01-11 03:00:00')->getRelative(), 'hours');
self::assertEquals('pirms dienas', $date->from('2010-01-12 01:00:00')->getRelative(), 'days');
self::assertEquals('pirms 10 dienām', $date->from('2010-01-21 01:00:00')->getRelative(), 'days');
self::assertEquals('pirms mēneša', $date->from('2010-02-11 01:00:00')->getRelative(), 'month');
self::assertEquals('pirms 3 mēnešiem', $date->from('2010-04-11 01:00:00')->getRelative(), 'month');
self::assertEquals('pirms gada', $date->from('2011-01-11 01:00:00')->getRelative(), 'year');
self::assertEquals('pirms 5 gadiem', $date->from('2015-01-11 01:00:00')->getRelative(), 'year');
}
public function testOrdinalFormat()
{
$date = new Moment('2017-01-01 01:00:00', 'Europe/Riga');
self::assertEquals('1. Janvāris 2017', $date->format('jS f Y'));
$date = new Moment('2017-03-12 01:00:00', 'Europe/Riga');
self::assertEquals('12. Marts 2017', $date->format('jS f Y'));
$date = new Moment('2017-06-23 01:00:00', 'Europe/Riga');
self::assertEquals('23. Jūnijs 2017', $date->format('jS f Y'));
$date = new Moment('2017-10-03 01:00:00', 'Europe/Riga');
self::assertEquals('3. Oktobris 2017', $date->format('jS f Y'));
}
}

View file

@ -2,7 +2,9 @@
namespace Moment;
class MomentPolishLocaleTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;
class MomentPolishLocaleTest extends TestCase
{
public function setUp()
{
@ -26,8 +28,8 @@ class MomentPolishLocaleTest extends \PHPUnit_Framework_TestCase
);
for ($d = 1; $d < 7; $d++) {
$this->assertEquals($weekdayNames[$moment->getWeekday()][0], $moment->getWeekdayNameShort(), 'weekday short name failed');
$this->assertEquals($weekdayNames[$moment->getWeekday()][1], $moment->getWeekdayNameLong(), 'weekday long name failed');
self::assertEquals($weekdayNames[$moment->getWeekday()][0], $moment->getWeekdayNameShort(), 'weekday short name failed');
self::assertEquals($weekdayNames[$moment->getWeekday()][1], $moment->getWeekdayNameLong(), 'weekday long name failed');
$moment->addDays(1);
}
@ -37,17 +39,17 @@ class MomentPolishLocaleTest extends \PHPUnit_Framework_TestCase
{
$string = '2015-06-14 20:46:22';
$moment = new Moment($string, 'Europe/Berlin');
$this->assertEquals('14 czerwca', $moment->format('j F'));
self::assertEquals('14 czerwca', $moment->format('j F'));
$string = '2015-03-08T15:14:53-0500';
$moment = new Moment($string, 'Europe/Berlin');
$this->assertEquals('8 marca', $moment->format('j F'));
self::assertEquals('8 marca', $moment->format('j F'));
}
public function testDayMonthFormat002()
{
$moment = new Moment('2016-01-03 16:17:07', 'Europe/Berlin');
$this->assertEquals('3 grudnia', $moment->subtractMonths(1)->format('j F'));
self::assertEquals('3 grudnia', $moment->subtractMonths(1)->format('j F'));
}
public function testMonthFormatFN()
@ -72,7 +74,7 @@ class MomentPolishLocaleTest extends \PHPUnit_Framework_TestCase
);
for ($d = 1; $d < count($monthsNominative); $d++) {
$this->assertEquals($monthsNominative[$moment->format('n')], $moment->format('f'), 'month nominative failed');
self::assertEquals($monthsNominative[$moment->format('n')], $moment->format('f'), 'month nominative failed');
$moment->addMonths(1);
}
@ -84,39 +86,39 @@ class MomentPolishLocaleTest extends \PHPUnit_Framework_TestCase
$past = new Moment('2016-01-03 16:17:07', 'Europe/Berlin');
$relative = $past->from('2016-01-03 16:34:07');
$this->assertEquals('17 minut temu', $relative->getRelative());
self::assertEquals('17 minut temu', $relative->getRelative());
$relative = $past->from('2016-01-03 16:40:07');
$this->assertEquals('23 minuty temu', $relative->getRelative());
self::assertEquals('23 minuty temu', $relative->getRelative());
$relative = $past->from('2016-01-03 16:30:07');
$this->assertEquals('13 minut temu', $relative->getRelative());
self::assertEquals('13 minut temu', $relative->getRelative());
}
public function testLastWeekWeekend()
{
$past = new Moment('2016-04-10');
$this->assertEquals('ostatnia niedziela', $past->calendar(false, new Moment('2016-04-12')));
self::assertEquals('ostatnia niedziela', $past->calendar(false, new Moment('2016-04-12')));
$past = new Moment('2016-04-11');
$this->assertEquals('ostatni poniedziałek', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('ostatni poniedziałek', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-12');
$this->assertEquals('ostatni wtorek', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('ostatni wtorek', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-13');
$this->assertEquals('ostatnia środa', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('ostatnia środa', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-14');
$this->assertEquals('ostatni czwartek', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('ostatni czwartek', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-15');
$this->assertEquals('ostatni piątek', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('ostatni piątek', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-16');
$this->assertEquals('wczoraj', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('wczoraj', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-16');
$this->assertEquals('ostatnia sobota', $past->calendar(false, new Moment('2016-04-18')));
self::assertEquals('ostatnia sobota', $past->calendar(false, new Moment('2016-04-18')));
}
}
}

View file

@ -2,7 +2,9 @@
namespace Moment;
class MomentRussianLocaleTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;
class MomentRussianLocaleTest extends TestCase
{
public function setUp()
{
@ -26,8 +28,8 @@ class MomentRussianLocaleTest extends \PHPUnit_Framework_TestCase
);
for ($d = 1; $d < 7; $d++) {
$this->assertEquals($weekdayNames[$moment->getWeekday()][0], $moment->getWeekdayNameShort(), 'weekday short name failed');
$this->assertEquals($weekdayNames[$moment->getWeekday()][1], $moment->getWeekdayNameLong(), 'weekday long name failed');
self::assertEquals($weekdayNames[$moment->getWeekday()][0], $moment->getWeekdayNameShort(), 'weekday short name failed');
self::assertEquals($weekdayNames[$moment->getWeekday()][1], $moment->getWeekdayNameLong(), 'weekday long name failed');
$moment->addDays(1);
}
@ -37,17 +39,17 @@ class MomentRussianLocaleTest extends \PHPUnit_Framework_TestCase
{
$string = '2015-06-14 20:46:22';
$moment = new Moment($string, 'Europe/Moscow');
$this->assertEquals('14 июня', $moment->format('j F'));
self::assertEquals('14 июня', $moment->format('j F'));
$string = '2015-03-08T15:14:53-0500';
$moment = new Moment($string, 'Europe/Moscow');
$this->assertEquals('8 марта', $moment->format('j F'));
self::assertEquals('8 марта', $moment->format('j F'));
}
public function testDayMonthFormat002()
{
$moment = new Moment('2016-01-03 16:17:07', 'Europe/Moscow');
$this->assertEquals('3 декабря', $moment->subtractMonths(1)->format('j F'));
self::assertEquals('3 декабря', $moment->subtractMonths(1)->format('j F'));
}
public function testMonthFormatFN()
@ -72,7 +74,7 @@ class MomentRussianLocaleTest extends \PHPUnit_Framework_TestCase
);
for ($d = 1; $d < count($monthsNominative); $d++) {
$this->assertEquals($monthsNominative[$moment->format('n')], $moment->format('f'), 'month nominative failed');
self::assertEquals($monthsNominative[$moment->format('n')], $moment->format('f'), 'month nominative failed');
$moment->addMonths(1);
}
@ -84,67 +86,82 @@ class MomentRussianLocaleTest extends \PHPUnit_Framework_TestCase
$past = new Moment('2016-01-03 16:17:07', 'Europe/Moscow');
$relative = $past->from('2016-01-03 16:34:07');
$this->assertEquals('17 минут назад', $relative->getRelative());
self::assertEquals('17 минут назад', $relative->getRelative());
$relative = $past->from('2016-01-03 16:40:07');
$this->assertEquals('23 минуты назад', $relative->getRelative());
self::assertEquals('23 минуты назад', $relative->getRelative());
$relative = $past->from('2016-01-03 16:30:07');
$this->assertEquals('13 минут назад', $relative->getRelative());
self::assertEquals('13 минут назад', $relative->getRelative());
}
public function testSeconds()
{
$past = new Moment('2017-08-30 20:49:30', 'Europe/Samara');
$relative = $past->from('2017-08-30 20:49:31');
self::assertEquals('несколько секунд назад', $relative->getRelative());
$relative = $past->from('2017-08-30 20:49:34');
self::assertEquals('4 секунды назад', $relative->getRelative());
$relative = $past->from('2017-08-30 20:49:35');
self::assertEquals('5 секунд назад', $relative->getRelative());
}
public function testLastWeekWeekend()
{
$past = new Moment('2016-04-10 16:30:07');
$this->assertEquals('воскресенье в 16:30', $past->calendar(true, new Moment('2016-04-12')));
self::assertEquals('воскресенье в 16:30', $past->calendar(true, new Moment('2016-04-12')));
$past = new Moment('2016-04-11');
$this->assertEquals('понедельник', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('понедельник', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-12');
$this->assertEquals('вторник', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('вторник', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-13');
$this->assertEquals('среда', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('среда', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-14');
$this->assertEquals('четверг', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('четверг', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-15');
$this->assertEquals('пятница', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('пятница', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-16');
$this->assertEquals('вчера', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('вчера', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-16');
$this->assertEquals('суббота', $past->calendar(false, new Moment('2016-04-18')));
self::assertEquals('суббота', $past->calendar(false, new Moment('2016-04-18')));
}
public function testFutureRelative()
{
$date = new Moment('2017-01-11 01:00:00');
$this->assertEquals('через несколько секунд', $date->from('2017-01-11 00:59:59')->getRelative(), 'seconds');
$this->assertEquals('через 2 минуты', $date->from('2017-01-11 00:58:00')->getRelative(), 'minutes');
$this->assertEquals('через 2 часа', $date->from('2017-01-10 23:00:00')->getRelative(), 'hours');
$this->assertEquals('через день', $date->from('2017-01-10 00:00:00')->getRelative(), 'days');
$this->assertEquals('через месяц', $date->from('2016-12-11 00:00:00')->getRelative(), 'month');
$this->assertEquals('через год', $date->from('2016-01-11 00:00:00')->getRelative(), 'year');
self::assertEquals('через несколько секунд', $date->from('2017-01-11 00:59:59')->getRelative(), 'seconds');
self::assertEquals('через 30 секунд', $date->from('2017-01-11 00:59:30')->getRelative(), 'seconds');
self::assertEquals('через 2 минуты', $date->from('2017-01-11 00:58:00')->getRelative(), 'minutes');
self::assertEquals('через 2 часа', $date->from('2017-01-10 23:00:00')->getRelative(), 'hours');
self::assertEquals('через день', $date->from('2017-01-10 00:00:00')->getRelative(), 'days');
self::assertEquals('через месяц', $date->from('2016-12-11 00:00:00')->getRelative(), 'month');
self::assertEquals('через год', $date->from('2016-01-11 00:00:00')->getRelative(), 'year');
}
public function testOrdinalFormat()
{
$date = new Moment('2017-01-01 01:00:00');
$this->assertEquals('1е января 2017', $date->format('jS F Y'));
self::assertEquals('1е января 2017', $date->format('jS F Y'));
$date = new Moment('2017-01-12 01:00:00');
$this->assertEquals('12е января 2017', $date->format('jS F Y'));
self::assertEquals('12е января 2017', $date->format('jS F Y'));
$date = new Moment('2017-01-23 01:00:00');
$this->assertEquals('23е января 2017', $date->format('jS F Y'));
self::assertEquals('23е января 2017', $date->format('jS F Y'));
$date = new Moment('2017-01-25 01:00:00');
$this->assertEquals('25е января 2017', $date->format('jS F Y'));
self::assertEquals('25е января 2017', $date->format('jS F Y'));
}
}

View file

@ -0,0 +1,14 @@
<?php
namespace Moment;
class MomentSimilarLocaleTest extends MomentBritishEnglishLocaleTest
{
/**
* @throws MomentException
*/
public function setUp()
{
Moment::setLocale('en', true);
}
}

View file

@ -2,52 +2,54 @@
namespace Moment;
class MomentTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;
class MomentTest extends TestCase
{
public function testMoment()
{
$data = '1923-12-31 12:30:00';
$m = new Moment($data);
$this->assertEquals('1923-12-31T12:30:00+0000', $m->format());
self::assertEquals('1923-12-31T12:30:00+0000', $m->format());
$data = '1923-12-31T12:30:00.000';
$m = new Moment($data);
$this->assertEquals('1923-12-31T12:30:00+0000', $m->format());
self::assertEquals('1923-12-31T12:30:00+0000', $m->format());
$data = '1923-12-31T12:30:00.123';
$m = new Moment($data);
$this->assertEquals('1923-12-31T12:30:00+0000', $m->format());
self::assertEquals('1923-12-31T12:30:00+0000', $m->format());
$data = '1923-12-31T12:30:00.123+02:00';
$m = new Moment($data);
$this->assertEquals('1923-12-31T12:30:00+0200', $m->format());
self::assertEquals('1923-12-31T12:30:00+0200', $m->format());
$data = '1923-12-31T12:30:00.123+0200';
$m = new Moment($data);
$this->assertEquals('1923-12-31T12:30:00+0200', $m->format());
self::assertEquals('1923-12-31T12:30:00+0200', $m->format());
$data = '1923-12-31T12:30:00.123Z';
$m = new Moment($data);
$this->assertEquals('1923-12-31T12:30:00+0000', $m->format());
self::assertEquals('1923-12-31T12:30:00+0000', $m->format());
$data = '1923-12-31T12:30:00.123Europe/Warsaw';
$m = new Moment($data);
$this->assertEquals('1923-12-31T12:30:00+0100', $m->format());
self::assertEquals('1923-12-31T12:30:00+0100', $m->format());
$data = '1923-12-31T12:30:00.123Europe/Warsaw';
$m = new Moment($data, 'UTC');
$this->assertEquals('1923-12-31T12:30:00+0100', $m->format());
self::assertEquals('1923-12-31T12:30:00+0100', $m->format());
$data = '1923-12-31T12:30:00.123UTC';
$m = new Moment($data, 'Europe/Warsaw');
$this->assertEquals('1923-12-31T12:30:00+0000', $m->format());
self::assertEquals('1923-12-31T12:30:00+0000', $m->format());
}
public function testIsMoment()
{
$m = new Moment();
$this->assertFalse($m->isMoment('2012-12-01T12:00:00'));
$this->assertTrue($m->isMoment(new Moment('2012-12-01T12:00:00')));
self::assertFalse($m->isMoment('2012-12-01T12:00:00'));
self::assertTrue($m->isMoment(new Moment('2012-12-01T12:00:00')));
}
public function testFromOnLeapYear()
@ -55,113 +57,113 @@ class MomentTest extends \PHPUnit_Framework_TestCase
$m = new Moment('2017-01-01 00:00:00');
$from = $m->from('2016-01-01 00:00:00');
$this->assertEquals(-366, $from->getSeconds() / 60 / 60 / 24);
self::assertEquals(-366, $from->getSeconds() / 60 / 60 / 24);
}
public function testIsBefore()
{
$s = new Moment('2014-01-01T10:10:11');
$i = new Moment('2014-01-01T10:10:12');
$this->assertTrue($s->isBefore($i));
$this->assertFalse($i->isBefore($s));
self::assertTrue($s->isBefore($i));
self::assertFalse($i->isBefore($s));
$this->assertFalse($s->isBefore($i, 'minute'));
$this->assertFalse($i->isBefore($s, 'minute'));
self::assertFalse($s->isBefore($i, 'minute'));
self::assertFalse($i->isBefore($s, 'minute'));
$s = new Moment('2014-01-01T10:10:11');
$i = new Moment('2014-01-01T10:12:12');
$this->assertTrue($s->isBefore($i, 'minute'));
$this->assertFalse($i->isBefore($s, 'minute'));
self::assertTrue($s->isBefore($i, 'minute'));
self::assertFalse($i->isBefore($s, 'minute'));
$this->assertFalse($s->isBefore($i, 'hour'));
$this->assertFalse($i->isBefore($s, 'hour'));
self::assertFalse($s->isBefore($i, 'hour'));
self::assertFalse($i->isBefore($s, 'hour'));
$s = new Moment('2014-01-01T10:10:11');
$i = new Moment('2014-01-01T12:12:12');
$this->assertTrue($s->isBefore($i, 'minute'));
$this->assertFalse($i->isBefore($s, 'minute'));
self::assertTrue($s->isBefore($i, 'minute'));
self::assertFalse($i->isBefore($s, 'minute'));
$this->assertFalse($s->isBefore($i, 'day'));
$this->assertFalse($i->isBefore($s, 'day'));
self::assertFalse($s->isBefore($i, 'day'));
self::assertFalse($i->isBefore($s, 'day'));
$s = new Moment('2014-01-01T10:10:11');
$i = new Moment('2014-01-02T12:12:12');
$this->assertTrue($s->isBefore($i, 'day'));
$this->assertFalse($i->isBefore($s, 'day'));
self::assertTrue($s->isBefore($i, 'day'));
self::assertFalse($i->isBefore($s, 'day'));
$this->assertFalse($s->isBefore($i, 'month'));
$this->assertFalse($i->isBefore($s, 'month'));
self::assertFalse($s->isBefore($i, 'month'));
self::assertFalse($i->isBefore($s, 'month'));
$s = new Moment('2014-01-01T10:10:11');
$i = new Moment('2014-02-02T12:12:12');
$this->assertTrue($s->isBefore($i, 'month'));
$this->assertFalse($i->isBefore($s, 'month'));
self::assertTrue($s->isBefore($i, 'month'));
self::assertFalse($i->isBefore($s, 'month'));
$this->assertFalse($s->isBefore($i, 'year'));
$this->assertFalse($i->isBefore($s, 'year'));
self::assertFalse($s->isBefore($i, 'year'));
self::assertFalse($i->isBefore($s, 'year'));
//from string
$s = new Moment('2014-01-01T10:10:11');
$i = '2014-01-01T10:12:12';
$this->assertTrue($s->isBefore($i, 'minute'));
self::assertTrue($s->isBefore($i, 'minute'));
$s = '2014-01-01T10:10:11';
$i = new Moment('2014-01-01T10:12:12');
$this->assertFalse($i->isBefore($s, 'minute'));
self::assertFalse($i->isBefore($s, 'minute'));
}
public function testIsAfter()
{
$s = new Moment('2014-01-01T10:10:11');
$i = new Moment('2014-01-01T10:10:12');
$this->assertTrue($i->isAfter($s));
$this->assertFalse($s->isAfter($i));
self::assertTrue($i->isAfter($s));
self::assertFalse($s->isAfter($i));
$this->assertFalse($s->isAfter($i, 'minute'));
$this->assertFalse($i->isAfter($s, 'minute'));
self::assertFalse($s->isAfter($i, 'minute'));
self::assertFalse($i->isAfter($s, 'minute'));
$s = new Moment('2014-01-01T10:10:11');
$i = new Moment('2014-01-01T10:12:12');
$this->assertFalse($s->isAfter($i, 'minute'));
$this->assertTrue($i->isAfter($s, 'minute'));
self::assertFalse($s->isAfter($i, 'minute'));
self::assertTrue($i->isAfter($s, 'minute'));
$this->assertFalse($s->isAfter($i, 'hour'));
$this->assertFalse($i->isAfter($s, 'hour'));
self::assertFalse($s->isAfter($i, 'hour'));
self::assertFalse($i->isAfter($s, 'hour'));
$s = new Moment('2014-01-01T10:10:11');
$i = new Moment('2014-01-01T12:12:12');
$this->assertFalse($s->isAfter($i, 'minute'));
$this->assertTrue($i->isAfter($s, 'minute'));
self::assertFalse($s->isAfter($i, 'minute'));
self::assertTrue($i->isAfter($s, 'minute'));
$this->assertFalse($s->isAfter($i, 'day'));
$this->assertFalse($i->isAfter($s, 'day'));
self::assertFalse($s->isAfter($i, 'day'));
self::assertFalse($i->isAfter($s, 'day'));
$s = new Moment('2014-01-01T10:10:11');
$i = new Moment('2014-01-02T12:12:12');
$this->assertFalse($s->isAfter($i, 'day'));
$this->assertTrue($i->isAfter($s, 'day'));
self::assertFalse($s->isAfter($i, 'day'));
self::assertTrue($i->isAfter($s, 'day'));
$this->assertFalse($s->isAfter($i, 'month'));
$this->assertFalse($i->isAfter($s, 'month'));
self::assertFalse($s->isAfter($i, 'month'));
self::assertFalse($i->isAfter($s, 'month'));
$s = new Moment('2014-01-01T10:10:11');
$i = new Moment('2014-02-02T12:12:12');
$this->assertFalse($s->isAfter($i, 'month'));
$this->assertTrue($i->isAfter($s, 'month'));
self::assertFalse($s->isAfter($i, 'month'));
self::assertTrue($i->isAfter($s, 'month'));
$this->assertFalse($s->isAfter($i, 'year'));
$this->assertFalse($i->isAfter($s, 'year'));
self::assertFalse($s->isAfter($i, 'year'));
self::assertFalse($i->isAfter($s, 'year'));
//from string
$s = new Moment('2014-01-01T10:10:11');
$i = '2014-01-01T10:12:12';
$this->assertFalse($s->isAfter($i, 'minute'));
self::assertFalse($s->isAfter($i, 'minute'));
$s = '2014-01-01T10:10:11';
$i = new Moment('2014-01-01T10:12:12');
$this->assertTrue($i->isAfter($s, 'minute'));
self::assertTrue($i->isAfter($s, 'minute'));
}
public function testIsAfterTz()
@ -169,26 +171,26 @@ class MomentTest extends \PHPUnit_Framework_TestCase
$s = new Moment('2014-01-01T10:10:00+0100');
$i = new Moment('2014-01-01T10:10:00+0000');
$this->assertTrue($i->isAfter($s));
$this->assertFalse($s->isAfter($i));
self::assertTrue($i->isAfter($s));
self::assertFalse($s->isAfter($i));
$s = new Moment('2014-01-01T10:10:00+0100');
$i = new Moment('2014-01-01T10:10:01+0000');
$this->assertTrue($i->isAfter($s));
$this->assertFalse($s->isAfter($i));
self::assertTrue($i->isAfter($s));
self::assertFalse($s->isAfter($i));
$s = new Moment('2014-01-01T10:10:00CET');
$i = new Moment('2014-01-01T09:10:00UTC');
$this->assertFalse($i->isAfter($s));
$this->assertFalse($s->isAfter($i));
self::assertFalse($i->isAfter($s));
self::assertFalse($s->isAfter($i));
$s = new Moment('2014-01-01T10:10:00Europe/Warsaw');
$i = new Moment('2014-01-01T09:10:01UTC');
$this->assertTrue($i->isAfter($s));
$this->assertFalse($s->isAfter($i));
self::assertTrue($i->isAfter($s));
self::assertFalse($s->isAfter($i));
}
public function testIsSame()
@ -196,38 +198,38 @@ class MomentTest extends \PHPUnit_Framework_TestCase
$s = new Moment('2014-01-01T10:10:00+0100');
$i = new Moment('2014-01-01T10:10:00+0000');
$this->assertFalse($i->isSame($s));
$this->assertFalse($s->isSame($i));
self::assertFalse($i->isSame($s));
self::assertFalse($s->isSame($i));
$s = new Moment('2014-01-01T10:10:00+0100');
$i = new Moment('2014-01-01T10:10:00CET');
$this->assertTrue($i->isSame($s));
self::assertTrue($i->isSame($s));
$s = new Moment('2014-01-01T10:10:00+0100');
$i = new Moment('2014-01-01T10:10:00Europe/Warsaw');
$this->assertTrue($i->isSame($s));
self::assertTrue($i->isSame($s));
$s = new Moment('2014-01-01T10:10:00CET');
$i = new Moment('2014-01-01T09:10:00UTC');
$this->assertTrue($i->isSame($s));
self::assertTrue($i->isSame($s));
$s = new Moment('2014-01-01T10:10:00+0100');
$i = '2014-01-01T10:10:00Europe/Warsaw';
$this->assertTrue($s->isSame($i));
self::assertTrue($s->isSame($i));
//Periods
$s = new Moment('2014-01-01T10:10:00+0100');
$i = new Moment('2014-01-01T09:10:01+0000');
$this->assertFalse($i->isSame($s));
self::assertFalse($i->isSame($s));
$this->assertTrue($i->isSame($s, 'minute'));
self::assertTrue($i->isSame($s, 'minute'));
$i = new Moment('2014-01-01T09:11:01+0000');
$this->assertFalse($i->isSame($s, 'minute'));
$this->assertTrue($i->isSame($s, 'hour'));
self::assertFalse($i->isSame($s, 'minute'));
self::assertTrue($i->isSame($s, 'hour'));
}
public function testIsSameHour()
@ -236,20 +238,20 @@ class MomentTest extends \PHPUnit_Framework_TestCase
$s = new Moment('2014-01-01T09:40:00+0030');
$i = new Moment('2014-01-01T09:10:00+0000');
$this->assertTrue($i->isSame($s));
$this->assertTrue($s->isSame($i));
self::assertTrue($i->isSame($s));
self::assertTrue($s->isSame($i));
$s = new Moment('2014-01-01T10:05:00+0045');
$i = new Moment('2014-01-01T09:20:00+0000');
$this->assertTrue($i->isSame($s));
$this->assertTrue($s->isSame($i));
self::assertTrue($i->isSame($s));
self::assertTrue($s->isSame($i));
$s = new Moment('2014-01-01T10:04:00+0045');
$i = new Moment('2014-01-01T09:20:00+0000');
$this->assertTrue($i->isSame($s, 'hour'));
$this->assertTrue($s->isSame($i, 'hour'));
self::assertTrue($i->isSame($s, 'hour'));
self::assertTrue($s->isSame($i, 'hour'));
}
public function testIsSameDay()
@ -257,20 +259,20 @@ class MomentTest extends \PHPUnit_Framework_TestCase
$s = new Moment('2014-01-01T00:14:00+0230');
$i = new Moment('2013-12-31T23:45:00+0000');
$this->assertFalse($i->isSame($s));
$this->assertFalse($s->isSame($i));
self::assertFalse($i->isSame($s));
self::assertFalse($s->isSame($i));
$this->assertFalse($i->isSame($s, 'hour'));
$this->assertFalse($s->isSame($i, 'hour'));
self::assertFalse($i->isSame($s, 'hour'));
self::assertFalse($s->isSame($i, 'hour'));
$this->assertTrue($i->isSame($s, 'day'));
$this->assertTrue($s->isSame($i, 'day'));
self::assertTrue($i->isSame($s, 'day'));
self::assertTrue($s->isSame($i, 'day'));
$this->assertTrue($i->isSame($s, 'month'));
$this->assertTrue($s->isSame($i, 'month'));
self::assertTrue($i->isSame($s, 'month'));
self::assertTrue($s->isSame($i, 'month'));
$this->assertTrue($i->isSame($s, 'year'));
$this->assertTrue($s->isSame($i, 'year'));
self::assertTrue($i->isSame($s, 'year'));
self::assertTrue($s->isSame($i, 'year'));
}
public function testIsSameMonth()
@ -278,20 +280,20 @@ class MomentTest extends \PHPUnit_Framework_TestCase
$s = new Moment('2014-01-01T00:14:00+0230');
$i = new Moment('2013-12-30T23:45:00+0000');
$this->assertFalse($i->isSame($s));
$this->assertFalse($s->isSame($i));
self::assertFalse($i->isSame($s));
self::assertFalse($s->isSame($i));
$this->assertFalse($i->isSame($s, 'hour'));
$this->assertFalse($s->isSame($i, 'hour'));
self::assertFalse($i->isSame($s, 'hour'));
self::assertFalse($s->isSame($i, 'hour'));
$this->assertFalse($i->isSame($s, 'day'));
$this->assertFalse($s->isSame($i, 'day'));
self::assertFalse($i->isSame($s, 'day'));
self::assertFalse($s->isSame($i, 'day'));
$this->assertTrue($i->isSame($s, 'month'));
$this->assertTrue($s->isSame($i, 'month'));
self::assertTrue($i->isSame($s, 'month'));
self::assertTrue($s->isSame($i, 'month'));
$this->assertTrue($i->isSame($s, 'year'));
$this->assertTrue($s->isSame($i, 'year'));
self::assertTrue($i->isSame($s, 'year'));
self::assertTrue($s->isSame($i, 'year'));
}
public function testIsSameYear()
@ -299,20 +301,20 @@ class MomentTest extends \PHPUnit_Framework_TestCase
$s = new Moment('2014-01-01T00:14:00+0230');
$i = new Moment('2013-11-30T23:45:00+0000');
$this->assertFalse($i->isSame($s));
$this->assertFalse($s->isSame($i));
self::assertFalse($i->isSame($s));
self::assertFalse($s->isSame($i));
$this->assertFalse($i->isSame($s, 'hour'));
$this->assertFalse($s->isSame($i, 'hour'));
self::assertFalse($i->isSame($s, 'hour'));
self::assertFalse($s->isSame($i, 'hour'));
$this->assertFalse($i->isSame($s, 'day'));
$this->assertFalse($s->isSame($i, 'day'));
self::assertFalse($i->isSame($s, 'day'));
self::assertFalse($s->isSame($i, 'day'));
$this->assertFalse($i->isSame($s, 'month'));
$this->assertFalse($s->isSame($i, 'month'));
self::assertFalse($i->isSame($s, 'month'));
self::assertFalse($s->isSame($i, 'month'));
$this->assertTrue($i->isSame($s, 'year'));
$this->assertTrue($s->isSame($i, 'year'));
self::assertTrue($i->isSame($s, 'year'));
self::assertTrue($s->isSame($i, 'year'));
}
public function testIsBetween()
@ -321,76 +323,76 @@ class MomentTest extends \PHPUnit_Framework_TestCase
$r = new Moment('2014-01-01T12:00:00Z');
$n = $l->cloning();
$this->assertTrue($n->isBetween($l, $r, true));
$this->assertFalse($n->isBetween($l, $r, false));
self::assertTrue($n->isBetween($l, $r, true));
self::assertFalse($n->isBetween($l, $r, false));
$n = $r->cloning();
$this->assertTrue($n->isBetween($l, $r, true));
$this->assertFalse($n->isBetween($l, $r, false));
self::assertTrue($n->isBetween($l, $r, true));
self::assertFalse($n->isBetween($l, $r, false));
//Minutes
$l = new Moment('2014-01-01T10:30:30Z');
$r = new Moment('2014-01-01T12:30:30Z');
$n = new Moment('2014-01-01T10:30:00Z');
$this->assertFalse($n->isBetween($l, $r, true));
self::assertFalse($n->isBetween($l, $r, true));
$n = new Moment('2014-01-01T12:30:45Z');
$this->assertFalse($n->isBetween($l, $r, true));
self::assertFalse($n->isBetween($l, $r, true));
$n = new Moment('2014-01-01T10:30:00Z');
$this->assertTrue($n->isBetween($l, $r, true, 'minute'));
self::assertTrue($n->isBetween($l, $r, true, 'minute'));
$n = new Moment('2014-01-01T12:30:45Z');
$this->assertTrue($n->isBetween($l, $r, true, 'minute'));
self::assertTrue($n->isBetween($l, $r, true, 'minute'));
//Hour
$n = new Moment('2014-01-01T10:29:00Z');
$this->assertFalse($n->isBetween($l, $r, true, 'minute'));
self::assertFalse($n->isBetween($l, $r, true, 'minute'));
$n = new Moment('2014-01-01T12:31:45Z');
$this->assertFalse($n->isBetween($l, $r, true, 'minute'));
self::assertFalse($n->isBetween($l, $r, true, 'minute'));
$n = new Moment('2014-01-01T10:29:00Z');
$this->assertTrue($n->isBetween($l, $r, true, 'hour'));
self::assertTrue($n->isBetween($l, $r, true, 'hour'));
$n = new Moment('2014-01-01T12:31:45Z');
$this->assertTrue($n->isBetween($l, $r, true, 'hour'));
self::assertTrue($n->isBetween($l, $r, true, 'hour'));
//Day
$n = new Moment('2014-01-01T09:29:00Z');
$this->assertFalse($n->isBetween($l, $r, true, 'hour'));
self::assertFalse($n->isBetween($l, $r, true, 'hour'));
$n = new Moment('2014-01-01T13:31:45Z');
$this->assertFalse($n->isBetween($l, $r, true, 'hour'));
self::assertFalse($n->isBetween($l, $r, true, 'hour'));
$n = new Moment('2014-01-01T10:29:00Z');
$this->assertTrue($n->isBetween($l, $r, true, 'day'));
self::assertTrue($n->isBetween($l, $r, true, 'day'));
$n = new Moment('2014-01-01T12:31:45Z');
$this->assertTrue($n->isBetween($l, $r, true, 'day'));
self::assertTrue($n->isBetween($l, $r, true, 'day'));
//Month
$l = new Moment('2014-01-10T10:30:30Z');
$r = new Moment('2014-01-20T12:30:30Z');
$n = new Moment('2014-01-09T09:29:00Z');
$this->assertFalse($n->isBetween($l, $r, true, 'day'));
self::assertFalse($n->isBetween($l, $r, true, 'day'));
$n = new Moment('2014-01-21T13:31:45Z');
$this->assertFalse($n->isBetween($l, $r, true, 'day'));
self::assertFalse($n->isBetween($l, $r, true, 'day'));
$n = new Moment('2014-01-09T10:29:00Z');
$this->assertTrue($n->isBetween($l, $r, true, 'month'));
self::assertTrue($n->isBetween($l, $r, true, 'month'));
$n = new Moment('2014-01-21T12:31:45Z');
$this->assertTrue($n->isBetween($l, $r, true, 'month'));
self::assertTrue($n->isBetween($l, $r, true, 'month'));
//year
$l = new Moment('2014-04-10T10:30:30Z');
$r = new Moment('2015-08-20T12:30:30Z');
$n = new Moment('2014-03-09T09:29:00Z');
$this->assertFalse($n->isBetween($l, $r, true, 'month'));
self::assertFalse($n->isBetween($l, $r, true, 'month'));
$n = new Moment('2015-09-21T13:31:45Z');
$this->assertFalse($n->isBetween($l, $r, true, 'month'));
self::assertFalse($n->isBetween($l, $r, true, 'month'));
$n = new Moment('2014-03-09T10:29:00Z');
$this->assertTrue($n->isBetween($l, $r, true, 'year'));
self::assertTrue($n->isBetween($l, $r, true, 'year'));
$n = new Moment('2015-09-21T12:31:45Z');
$this->assertTrue($n->isBetween($l, $r, true, 'year'));
self::assertTrue($n->isBetween($l, $r, true, 'year'));
}
public function testLocaleDow()
@ -405,20 +407,20 @@ class MomentTest extends \PHPUnit_Framework_TestCase
//Current date: Middle of the week
$gb = new Moment('2015-04-28T10:29:00Z');
$this->assertTrue($gb->cloning()->startOf('week')->isSame($gb_start));
$this->assertTrue($gb->cloning()->endOf('week')->isSame($gb_end));
self::assertTrue($gb->cloning()->startOf('week')->isSame($gb_start));
self::assertTrue($gb->cloning()->endOf('week')->isSame($gb_end));
//Current Date: Beginning of the week
$gb = new Moment('2015-04-27T10:29:00Z');
$this->assertTrue($gb->cloning()->startOf('week')->isSame($gb_start));
$this->assertTrue($gb->cloning()->endOf('week')->isSame($gb_end));
self::assertTrue($gb->cloning()->startOf('week')->isSame($gb_start));
self::assertTrue($gb->cloning()->endOf('week')->isSame($gb_end));
//Current Date: End of week
$gb = new Moment('2015-05-03T10:29:00Z');
$this->assertTrue($gb->cloning()->startOf('week')->isSame($gb_start));
$this->assertTrue($gb->cloning()->endOf('week')->isSame($gb_end));
self::assertTrue($gb->cloning()->startOf('week')->isSame($gb_start));
self::assertTrue($gb->cloning()->endOf('week')->isSame($gb_end));
//Test en_US for Sunday start of week
@ -431,31 +433,68 @@ class MomentTest extends \PHPUnit_Framework_TestCase
//Current date: Middle of the week
$us = new Moment('2015-04-28T10:29:00Z');
$this->assertTrue($us->cloning()->startOf('week')->isSame($us_start));
$this->assertTrue($us->cloning()->endOf('week')->isSame($us_end));
self::assertTrue($us->cloning()->startOf('week')->isSame($us_start));
self::assertTrue($us->cloning()->endOf('week')->isSame($us_end));
//Current Date: Beginning of the week
$us = new Moment('2015-04-26T10:29:00Z');
$this->assertTrue($us->cloning()->startOf('week')->isSame($us_start));
$this->assertTrue($us->cloning()->endOf('week')->isSame($us_end));
self::assertTrue($us->cloning()->startOf('week')->isSame($us_start));
self::assertTrue($us->cloning()->endOf('week')->isSame($us_end));
//Current Date: End of week
$us = new Moment('2015-05-02T10:29:00Z');
$this->assertTrue($us->cloning()->startOf('week')->isSame($us_start));
$this->assertTrue($us->cloning()->endOf('week')->isSame($us_end));
self::assertTrue($us->cloning()->startOf('week')->isSame($us_start));
self::assertTrue($us->cloning()->endOf('week')->isSame($us_end));
}
public function testImplicitCloning()
{
$origin = new Moment('1923-12-31 12:30:00', 'UTC', true);
$this->assertNotSame($origin, $origin->addMonths(1));
self::assertNotSame($origin, $origin->addMonths(1));
$origin->setImmutableMode(false);
$this->assertSame($origin, $origin->addMonths(1));
self::assertSame($origin, $origin->addMonths(1));
$origin->setImmutableMode(true);
$this->assertNotSame($origin, $origin->addMonths(1));
self::assertNotSame($origin, $origin->addMonths(1));
}
public function testRFC2822Parsing()
{
$tz = 'CET';
$format = 'Y-m-d H:i';
$dates = array(
array(
'input' => 'Tue, 11 Dec 2018 14:12:01 +0000',
'output' => '2018-12-11 15:12',
),
array(
'input' => 'Tue, 11 Dec 2018 07:46:41 -0500',
'output' => '2018-12-11 13:46',
),
);
foreach ($dates as $date)
{
$m = new Moment($date['input']);
self::assertEquals($date['output'], $m->setTimezone($tz)->format($format));
}
}
public function testValidUnixtimeLength()
{
$dates = array(
999992800, // September 9th, 2001 1:46 AM
1544652373 // December 12th, 2018 11:06 PM
);
foreach ($dates as $date)
{
$m = new Moment($date);
self::assertEquals($date, $m->format('U'));
}
}
/**

View file

@ -7,7 +7,9 @@
namespace Moment;
class MomentTurkishLocaleTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;
class MomentTurkishLocaleTest extends TestCase
{
public function setUp()
{
@ -30,8 +32,8 @@ class MomentTurkishLocaleTest extends \PHPUnit_Framework_TestCase
7 => array('Paz', 'Pazar'),
);
for ($d = 1; $d < 7; $d++) {
$this->assertEquals($weekdayNames[$moment->getWeekday()][0], $moment->getWeekdayNameShort(), 'weekday short name failed');
$this->assertEquals($weekdayNames[$moment->getWeekday()][1], $moment->getWeekdayNameLong(), 'weekday long name failed');
self::assertEquals($weekdayNames[$moment->getWeekday()][0], $moment->getWeekdayNameShort(), 'weekday short name failed');
self::assertEquals($weekdayNames[$moment->getWeekday()][1], $moment->getWeekdayNameLong(), 'weekday long name failed');
$moment->addDays(1);
}
@ -59,8 +61,8 @@ class MomentTurkishLocaleTest extends \PHPUnit_Framework_TestCase
);
for ($d = 1; $d <= 12; $d++) {
$this->assertEquals($monthNames[$moment->format('n')][0], $moment->getMonthNameShort(), 'month short name failed');
$this->assertEquals($monthNames[$moment->format('n')][1], $moment->getMonthNameLong(), 'month long name failed');
self::assertEquals($monthNames[$moment->format('n')][0], $moment->getMonthNameShort(), 'month short name failed');
self::assertEquals($monthNames[$moment->format('n')][1], $moment->getMonthNameLong(), 'month long name failed');
$moment->addMonths(1);
}
@ -78,7 +80,7 @@ class MomentTurkishLocaleTest extends \PHPUnit_Framework_TestCase
);
$b = new Moment('2010-02-14 15:25:50');
for ($i = 0; $i < count($a); $i++) {
$this->assertEquals($a[$i][1], $b->format($a[$i][0]));
self::assertEquals($a[$i][1], $b->format($a[$i][0]));
}
}
@ -86,8 +88,8 @@ class MomentTurkishLocaleTest extends \PHPUnit_Framework_TestCase
{
$beginningMoment = new Moment('2015-06-14 20:46:22', 'Europe/Istanbul');
$endMoment = new Moment('2015-06-14 20:48:32', 'Europe/Istanbul');
$this->assertEquals('2 dakika sonra', $endMoment->from($beginningMoment)->getRelative());
$this->assertEquals('2 dakika önce', $beginningMoment->from($endMoment)->getRelative());
self::assertEquals('2 dakika sonra', $endMoment->from($beginningMoment)->getRelative());
self::assertEquals('2 dakika önce', $beginningMoment->from($endMoment)->getRelative());
}
public function testMinutes()
@ -95,42 +97,42 @@ class MomentTurkishLocaleTest extends \PHPUnit_Framework_TestCase
$past = new Moment('2016-01-03 16:17:07', 'Europe/Kiev');
$relative = $past->from('2016-01-03 16:34:07');
$this->assertEquals('17 dakika önce', $relative->getRelative());
self::assertEquals('17 dakika önce', $relative->getRelative());
$relative = $past->from('2016-01-03 16:40:07');
$this->assertEquals('23 dakika önce', $relative->getRelative());
self::assertEquals('23 dakika önce', $relative->getRelative());
$relative = $past->from('2016-01-03 16:30:07');
$this->assertEquals('13 dakika önce', $relative->getRelative());
self::assertEquals('13 dakika önce', $relative->getRelative());
}
public function testLastWeekWeekend()
{
$past = new Moment('2016-04-10 16:30:07');
$this->assertEquals('Geçen hafta Pazar 16:30', $past->calendar(true, new Moment('2016-04-12')));
self::assertEquals('Geçen hafta Pazar 16:30', $past->calendar(true, new Moment('2016-04-12')));
$past = new Moment('2016-09-24 11:30:07');
$this->assertEquals('Geçen hafta Cumartesi 11:30', $past->calendar(true, new Moment('2016-09-26')));
self::assertEquals('Geçen hafta Cumartesi 11:30', $past->calendar(true, new Moment('2016-09-26')));
$past = new Moment('2016-04-11');
$this->assertEquals('Geçen hafta Pazartesi', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('Geçen hafta Pazartesi', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-12');
$this->assertEquals('Geçen hafta Salı', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('Geçen hafta Salı', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-13');
$this->assertEquals('Geçen hafta Çarşamba', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('Geçen hafta Çarşamba', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-14');
$this->assertEquals('Geçen hafta Perşembe', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('Geçen hafta Perşembe', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-15');
$this->assertEquals('Geçen hafta Cuma', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('Geçen hafta Cuma', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-16');
$this->assertEquals('Dün', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('Dün', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-16');
$this->assertEquals('Geçen hafta Cumartesi', $past->calendar(false, new Moment('2016-04-18')));
self::assertEquals('Geçen hafta Cumartesi', $past->calendar(false, new Moment('2016-04-18')));
}
}

View file

@ -2,7 +2,9 @@
namespace Moment;
class MomentUkrainianLocaleTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;
class MomentUkrainianLocaleTest extends TestCase
{
public function setUp()
{
@ -26,8 +28,8 @@ class MomentUkrainianLocaleTest extends \PHPUnit_Framework_TestCase
);
for ($d = 1; $d < 7; $d++) {
$this->assertEquals($weekdayNames[$moment->getWeekday()][0], $moment->getWeekdayNameShort(), 'weekday short name failed');
$this->assertEquals($weekdayNames[$moment->getWeekday()][1], $moment->getWeekdayNameLong(), 'weekday long name failed');
self::assertEquals($weekdayNames[$moment->getWeekday()][0], $moment->getWeekdayNameShort(), 'weekday short name failed');
self::assertEquals($weekdayNames[$moment->getWeekday()][1], $moment->getWeekdayNameLong(), 'weekday long name failed');
$moment->addDays(1);
}
@ -37,17 +39,17 @@ class MomentUkrainianLocaleTest extends \PHPUnit_Framework_TestCase
{
$string = '2015-06-14 20:46:22';
$moment = new Moment($string, 'Europe/Kiev');
$this->assertEquals('14 червня', $moment->format('j F'));
self::assertEquals('14 червня', $moment->format('j F'));
$string = '2015-03-08T15:14:53-0500';
$moment = new Moment($string, 'Europe/Kiev');
$this->assertEquals('8 березня', $moment->format('j F'));
self::assertEquals('8 березня', $moment->format('j F'));
}
public function testDayMonthFormat002()
{
$moment = new Moment('2016-01-03 16:17:07', 'Europe/Kiev');
$this->assertEquals('3 грудня', $moment->subtractMonths(1)->format('j F'));
self::assertEquals('3 грудня', $moment->subtractMonths(1)->format('j F'));
}
public function testMonthFormatFN()
@ -72,7 +74,7 @@ class MomentUkrainianLocaleTest extends \PHPUnit_Framework_TestCase
);
for ($d = 1; $d < count($monthsNominative); $d++) {
$this->assertEquals($monthsNominative[$moment->format('n')], $moment->format('f'), 'month nominative failed');
self::assertEquals($monthsNominative[$moment->format('n')], $moment->format('f'), 'month nominative failed');
$moment->addMonths(1);
}
@ -84,42 +86,42 @@ class MomentUkrainianLocaleTest extends \PHPUnit_Framework_TestCase
$past = new Moment('2016-01-03 16:17:07', 'Europe/Kiev');
$relative = $past->from('2016-01-03 16:34:07');
$this->assertEquals('17 хвилин тому', $relative->getRelative());
self::assertEquals('17 хвилин тому', $relative->getRelative());
$relative = $past->from('2016-01-03 16:40:07');
$this->assertEquals('23 хвилини тому', $relative->getRelative());
self::assertEquals('23 хвилини тому', $relative->getRelative());
$relative = $past->from('2016-01-03 16:30:07');
$this->assertEquals('13 хвилин тому', $relative->getRelative());
self::assertEquals('13 хвилин тому', $relative->getRelative());
}
public function testLastWeekWeekend()
{
$past = new Moment('2016-04-10 16:30:07');
$this->assertEquals('неділя о 16:30', $past->calendar(true, new Moment('2016-04-12')));
self::assertEquals('неділя о 16:30', $past->calendar(true, new Moment('2016-04-12')));
$past = new Moment('2016-09-24 11:30:07');
$this->assertEquals('субота об 11:30', $past->calendar(true, new Moment('2016-09-26')));
self::assertEquals('субота об 11:30', $past->calendar(true, new Moment('2016-09-26')));
$past = new Moment('2016-04-11');
$this->assertEquals('понеділок', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('понеділок', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-12');
$this->assertEquals('вівторок', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('вівторок', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-13');
$this->assertEquals('середа', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('середа', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-14');
$this->assertEquals('четвер', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('четвер', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-15');
$this->assertEquals('п’ятниця', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('п’ятниця', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-16');
$this->assertEquals('вчора', $past->calendar(false, new Moment('2016-04-17')));
self::assertEquals('вчора', $past->calendar(false, new Moment('2016-04-17')));
$past = new Moment('2016-04-16');
$this->assertEquals('субота', $past->calendar(false, new Moment('2016-04-18')));
self::assertEquals('субота', $past->calendar(false, new Moment('2016-04-18')));
}
}

View file

@ -1,22 +0,0 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

View file

@ -1,32 +1,21 @@
ImapMailbox
The MIT License (MIT)
Copyright (c) 2012 by Barbushin Sergey <barbushin@gmail.com>.
All rights reserved.
Copyright (c) 2012 Sergey Barbushin <barbushin@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* The names of the contributors may not be used to endorse or
promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View file

@ -1,50 +1,49 @@
ImapMailbox is PHP class to access mailbox by POP3/IMAP/NNTP using IMAP extension
# PHP IMAP
[![Author](http://img.shields.io/badge/author-@barbushin-blue.svg?style=flat-square)](https://www.linkedin.com/in/barbushin)
[![GitHub release](https://img.shields.io/github/release/barbushin/php-imap.svg?maxAge=86400&style=flat-square)](https://packagist.org/packages/php-imap/php-imap)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
[![Packagist](https://img.shields.io/packagist/dt/php-imap/php-imap.svg?maxAge=86400&style=flat-square)](https://packagist.org/packages/php-imap/php-imap)
### Features
* Connect to mailbox by POP3/IMAP/NNTP (see [imap_open](http://php.net/imap_open))
* Get mailbox status (see [imap_check](http://php.net/imap_check))
* Receive emails (+attachments, +html body images)
* Search emails by custom criteria (see [imap_search](http://php.net/imap_search))
* Change email status (see [imap_setflag_full](http://php.net/imap_setflag_full))
* Delete email
* Connect to mailbox by POP3/IMAP/NNTP, using [PHP IMAP extension](http://php.net/manual/book.imap.php)
* Get emails with attachments and inline images
* Get emails filtered or sorted by custom criteria
* Mark emails as seen/unseen
* Delete emails
* Manage mailbox folders
### Requirements
* IMAP extension must be present; so make sure this line is active in your php.ini: `extension=php_imap.dll`
### Installation by Composer
{
"require": {
"php-imap/php-imap": "~2.0"
}
}
$ composer require php-imap/php-imap
### Integration with frameworks
Or
* Symfony - https://github.com/secit-pl/imap-bundle
$ composer require php-imap/php-imap ~2.0
### Migration from `v1.*` to `v2.*`
Just add following code in the head of your script:
use PhpImap\Mailbox as ImapMailbox;
use PhpImap\IncomingMail;
use PhpImap\IncomingMailAttachment;
### [Usage example](https://github.com/barbushin/php-imap/blob/master/example/index.php)
### Usage example
```php
// 4. argument is the directory into which attachments are to be saved:
$mailbox = new PhpImap\Mailbox('{imap.gmail.com:993/imap/ssl}INBOX', 'some@gmail.com', '*********', __DIR__);
$mails = array();
$mailsIds = $mailbox->searchMailBox('ALL');
// Read all messaged into an array:
$mailsIds = $mailbox->searchMailbox('ALL');
if(!$mailsIds) {
die('Mailbox is empty');
}
$mailId = reset($mailsIds);
$mail = $mailbox->getMail($mailId);
// Get the first message and save its attachment(s) to disk:
$mail = $mailbox->getMail($mailsIds[0]);
var_dump($mail);
var_dump($mail->getAttachments());
print_r($mail);
echo "\n\nAttachments:\n";
print_r($mail->getAttachments());
```
### Recommended

View file

@ -1,28 +1,36 @@
{
"name": "php-imap/php-imap",
"description": "PHP class to access mailbox by POP3/IMAP/NNTP using IMAP extension",
"keywords": [
"PHP",
"IMAP",
"mail"
],
"homepage": "https://github.com/barbushin/php-imap",
"license": "BSD 3-Clause",
"type": "library",
"authors": [
{
"name": "Sergey Barbushin",
"homepage": "http://linkedin.com/in/barbushin",
"email": "barbushin@gmail.com"
}
],
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-0": {
"PhpImap": "src/"
}
},
"minimum-stability": "stable"
"name": "php-imap/php-imap",
"description": "Manage mailboxes, filter/get/delete emails in PHP (supports IMAP/POP3/NNTP)",
"keywords": [
"PHP",
"mail",
"IMAP",
"POP3",
"mailbox",
"receive emails"
],
"homepage": "https://github.com/barbushin/php-imap",
"license": "MIT",
"type": "library",
"authors": [
{
"name": "Sergey Barbushin",
"homepage": "http://linkedin.com/in/barbushin",
"email": "barbushin@gmail.com"
}
],
"require": {
"php": ">=5.5",
"ext-imap": "*"
},
"autoload": {
"psr-4": {
"PhpImap\\": "src/PhpImap"
}
},
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
}
}

View file

@ -4,27 +4,19 @@
* @see https://github.com/barbushin/php-imap
* @author Barbushin Sergey http://linkedin.com/in/barbushin
*/
class IncomingMail {
public $id;
public $date;
public $subject;
public $fromName;
public $fromAddress;
public $to = array();
public $toString;
public $cc = array();
public $replyTo = array();
public $messageId;
class IncomingMail extends IncomingMailHeader {
public $textPlain;
public $textHtml;
/** @var IncomingMailAttachment[] */
protected $attachments = array();
public function setHeader(IncomingMailHeader $header) {
foreach(get_object_vars($header) as $property => $value) {
$this->$property = $value;
}
}
public function addAttachment(IncomingMailAttachment $attachment) {
$this->attachments[$attachment->id] = $attachment;
}
@ -48,18 +40,16 @@ class IncomingMail {
public function replaceInternalLinks($baseUri) {
$baseUri = rtrim($baseUri, '\\/') . '/';
$fetchedHtml = $this->textHtml;
$search = array();
$replace = array();
foreach($this->getInternalLinksPlaceholders() as $attachmentId => $placeholder) {
if(isset($this->attachments[$attachmentId])) {
$fetchedHtml = str_replace($placeholder, $baseUri . basename($this->attachments[$attachmentId]->filePath), $fetchedHtml);
foreach($this->attachments as $attachment) {
if($attachment->contentId == $attachmentId) {
$search[] = $placeholder;
$replace[] = $baseUri . basename($this->attachments[$attachment->id]->filePath);
}
}
}
return $fetchedHtml;
return str_replace($search, $replace, $fetchedHtml);
}
}
class IncomingMailAttachment {
public $id;
public $name;
public $filePath;
}

View file

@ -0,0 +1,14 @@
<?php namespace PhpImap;
/**
* @see https://github.com/barbushin/php-imap
* @author Barbushin Sergey http://linkedin.com/in/barbushin
*/
class IncomingMailAttachment {
public $id;
public $contentId;
public $name;
public $filePath;
public $disposition;
}

View file

@ -0,0 +1,26 @@
<?php namespace PhpImap;
/**
* @see https://github.com/barbushin/php-imap
* @author Barbushin Sergey http://linkedin.com/in/barbushin
*/
class IncomingMailHeader {
/** @var int|string $id The IMAP message ID - not the "Message-ID:"-header of the email */
public $id;
public $date;
public $headersRaw;
public $headers;
public $subject;
public $fromName;
public $fromAddress;
public $to = array();
public $toString;
public $cc = array();
public $bcc = array();
public $replyTo = array();
public $messageId;
}

View file

@ -11,12 +11,25 @@ class Mailbox {
protected $imapPath;
protected $imapLogin;
protected $imapPassword;
protected $connectionRetry = 0;
protected $connectionRetryDelay = 100;
protected $imapOptions = 0;
protected $imapRetriesNum = 0;
protected $imapParams = array();
protected $imapParams = [];
protected $serverEncoding;
protected $attachmentsDir;
protected $attachmentsDir = null;
protected $expungeOnDisconnect = true;
protected $timeouts = [];
private $imapStream;
/**
* @param string $imapPath
* @param string $login
* @param string $password
* @param string $attachmentsDir
* @param string $serverEncoding
* @throws Exception
*/
public function __construct($imapPath, $login, $password, $attachmentsDir = null, $serverEncoding = 'UTF-8') {
$this->imapPath = $imapPath;
$this->imapLogin = $login;
@ -30,6 +43,29 @@ class Mailbox {
}
}
public function getServerEncoding() {
return $this->serverEncoding;
}
public function setServerEncoding($serverEncoding) {
$this->serverEncoding = $serverEncoding;
}
/**
* @param int $timeout Timeout in seconds
* @param array $types One of the following: IMAP_OPENTIMEOUT, IMAP_READTIMEOUT, IMAP_WRITETIMEOUT, IMAP_CLOSETIMEOUT
*/
public function setTimeouts($timeout, $types = [IMAP_OPENTIMEOUT, IMAP_READTIMEOUT, IMAP_WRITETIMEOUT, IMAP_CLOSETIMEOUT]) {
$this->timeouts = array_fill_keys($types, $timeout);
}
/**
* @return string
*/
public function getLogin() {
return $this->imapLogin;
}
/**
* Set custom connection arguments of imap_open method. See http://php.net/imap_open
* @param int $options
@ -42,40 +78,91 @@ class Mailbox {
$this->imapParams = $params;
}
/**
* Set custom folder for attachments in case you want to have tree of folders for each email
* i.e. a/1 b/1 c/1 where a,b,c - senders, i.e. john@smith.com
* @param string $dir folder where to save attachments
*
* @return void
*/
public function setAttachmentsDir($dir) {
$this->attachmentsDir = $dir;
}
public function setConnectionRetry($maxAttempts) {
$this->connectionRetry = $maxAttempts;
}
public function setConnectionRetryDelay($milliseconds) {
$this->connectionRetryDelay = $milliseconds;
}
/**
* Get IMAP mailbox connection stream
* @param bool $forceConnection Initialize connection if it's not initialized
* @return null|resource
*/
public function getImapStream($forceConnection = true) {
static $imapStream;
if($forceConnection) {
if($imapStream && (!is_resource($imapStream) || !imap_ping($imapStream))) {
if($this->imapStream && (!is_resource($this->imapStream) || !imap_ping($this->imapStream))) {
$this->disconnect();
$imapStream = null;
$this->imapStream = null;
}
if(!$imapStream) {
$imapStream = $this->initImapStream();
if(!$this->imapStream) {
$this->imapStream = $this->initImapStreamWithRetry();
}
}
return $imapStream;
return $this->imapStream;
}
/**
* Switch mailbox without opening a new connection
*
* @param string $imapPath
* @throws Exception
*/
public function switchMailbox($imapPath) {
$this->imapPath = $imapPath;
$this->imap('reopen', $this->imapPath);
}
protected function initImapStreamWithRetry() {
$retry = $this->connectionRetry;
do {
try {
return $this->initImapStream();
}
catch(ConnectionException $exception) {
}
}
while(--$retry > 0 && (!$this->connectionRetryDelay || !usleep($this->connectionRetryDelay * 1000)));
throw $exception;
}
protected function initImapStream() {
$imapStream = @imap_open($this->imapPath, $this->imapLogin, $this->imapPassword, $this->imapOptions, $this->imapRetriesNum, $this->imapParams);
if(!$imapStream) {
throw new Exception('Connection error: ' . imap_last_error());
foreach($this->timeouts as $type => $timeout) {
$this->imap('timeout', [$type, $timeout], false);
}
return $imapStream;
return $this->imap('open', [$this->imapPath, $this->imapLogin, $this->imapPassword, $this->imapOptions, $this->imapRetriesNum, $this->imapParams], false, ConnectionException::class);
}
protected function disconnect() {
public function disconnect() {
$imapStream = $this->getImapStream(false);
if($imapStream && is_resource($imapStream)) {
imap_close($imapStream, CL_EXPUNGE);
$this->imap('close', [$imapStream, $this->expungeOnDisconnect ? CL_EXPUNGE : 0], false, null);
}
}
/**
* Sets 'expunge on disconnect' parameter
* @param bool $isEnabled
*/
public function setExpungeOnDisconnect($isEnabled) {
$this->expungeOnDisconnect = $isEnabled;
}
/**
* Get information about the current mailbox.
*
@ -89,17 +176,32 @@ class Mailbox {
* @return stdClass
*/
public function checkMailbox() {
return imap_check($this->getImapStream());
return $this->imap('check');
}
/**
* Creates a new mailbox specified by mailbox.
*
* @return bool
* Creates a new mailbox
* @param $name
*/
public function createMailbox($name) {
$this->imap('createmailbox', $this->imapPath . '.' . $name);
}
public function createMailbox() {
return imap_createmailbox($this->getImapStream(), imap_utf7_encode($this->imapPath));
/**
* Delete mailbox
* @param $name
*/
public function deleteMailbox($name) {
$this->imap('deletemailbox', $this->imapPath . '.' . $name);
}
/**
* Rename mailbox
* @param $oldName
* @param $newName
*/
public function renameMailbox($oldName, $newName) {
$this->imap('renamemailbox', [$this->imapPath . '.' . $oldName, $this->imapPath . '.' . $newName]);
}
/**
@ -108,147 +210,128 @@ class Mailbox {
* This function returns an object containing status information.
* The object has the following properties: messages, recent, unseen, uidnext, and uidvalidity.
*
* @return stdClass if the box doesn't exist
* @return stdClass
*/
public function statusMailbox() {
return imap_status($this->getImapStream(), $this->imapPath, SA_ALL);
return $this->imap('status', [$this->imapPath, SA_ALL]);
}
/**
* Gets listing the folders
*
* This function returns an object containing listing the folders.
* The object has the following properties: messages, recent, unseen, uidnext, and uidvalidity.
*
* @param string $pattern
* @return array listing the folders
*/
public function getListingFolders() {
$folders = imap_list($this->getImapStream(), $this->imapPath, "*");
foreach ($folders as $key => $folder)
{
$folder = str_replace($this->imapPath, "", imap_utf7_decode($folder));
$folders[$key] = $folder;
public function getListingFolders($pattern = '*') {
$folders = $this->imap('list', [$this->imapPath, $pattern]) ?: [];
foreach($folders as &$folder) {
$folder = imap_utf7_decode($folder);
}
return $folders;
}
/**
* This function performs a search on the mailbox currently opened in the given IMAP stream.
* This function uses imap_search() to perform a search on the mailbox currently opened in the given IMAP stream.
* For example, to match all unanswered mails sent by Mom, you'd use: "UNANSWERED FROM mom".
* Searches appear to be case insensitive. This list of criteria is from a reading of the UW
* c-client source code and may be incomplete or inaccurate (see also RFC2060, section 6.4.4).
*
* @param string $criteria String, delimited by spaces, in which the following keywords are allowed. Any multi-word arguments (e.g. FROM "joey smith") must be quoted. Results will match all criteria entries.
* ALL - return all mails matching the rest of the criteria
* ANSWERED - match mails with the \\ANSWERED flag set
* BCC "string" - match mails with "string" in the Bcc: field
* BEFORE "date" - match mails with Date: before "date"
* BODY "string" - match mails with "string" in the body of the mail
* CC "string" - match mails with "string" in the Cc: field
* DELETED - match deleted mails
* FLAGGED - match mails with the \\FLAGGED (sometimes referred to as Important or Urgent) flag set
* FROM "string" - match mails with "string" in the From: field
* KEYWORD "string" - match mails with "string" as a keyword
* NEW - match new mails
* OLD - match old mails
* ON "date" - match mails with Date: matching "date"
* RECENT - match mails with the \\RECENT flag set
* SEEN - match mails that have been read (the \\SEEN flag is set)
* SINCE "date" - match mails with Date: after "date"
* SUBJECT "string" - match mails with "string" in the Subject:
* TEXT "string" - match mails with text "string"
* TO "string" - match mails with "string" in the To:
* UNANSWERED - match mails that have not been answered
* UNDELETED - match mails that are not deleted
* UNFLAGGED - match mails that are not flagged
* UNKEYWORD "string" - match mails that do not have the keyword "string"
* UNSEEN - match mails which have not been read yet
*
* @return array Mails ids
* @param string $criteria See http://php.net/imap_search for a complete list of available criteria
* @return array mailsIds (or empty array)
*/
public function searchMailbox($criteria = 'ALL') {
$mailsIds = imap_search($this->getImapStream(), $criteria, SE_UID, $this->serverEncoding);
return $mailsIds ? $mailsIds : array();
return $this->imap('search', [$criteria, SE_UID, $this->serverEncoding]) ?: [];
}
/**
* Save mail body.
* @return bool
* @param $mailId
* @param string $filename
*/
public function saveMail($mailId, $filename = 'email.eml') {
return imap_savebody($this->getImapStream(), $filename, $mailId, "", FT_UID);
$this->imap('savebody', [$filename, $mailId, "", FT_UID]);
}
/**
* Marks mails listed in mailId for deletion.
* @return bool
* @param $mailId
*/
public function deleteMail($mailId) {
return imap_delete($this->getImapStream(), $mailId, FT_UID);
$this->imap('delete', [$mailId . ':' . $mailId, FT_UID]);
}
/**
* Moves mails listed in mailId into new mailbox
* @param $mailId
* @param $mailBox
*/
public function moveMail($mailId, $mailBox) {
return imap_mail_move($this->getImapStream(), $mailId, $mailBox, CP_UID) && $this->expungeDeletedMails();
$this->imap('mail_move', [$mailId, $mailBox, CP_UID]) && $this->expungeDeletedMails();
}
/**
* Copys mails listed in mailId into new mailbox
* @param $mailId
* @param $mailBox
*/
public function copyMail($mailId, $mailBox) {
$this->imap('mail_copy', [$mailId, $mailBox, CP_UID]) && $this->expungeDeletedMails();
}
/**
* Deletes all the mails marked for deletion by imap_delete(), imap_mail_move(), or imap_setflag_full().
* @return bool
*/
public function expungeDeletedMails() {
return imap_expunge($this->getImapStream());
$this->imap('expunge');
}
/**
* Add the flag \Seen to a mail.
* @return bool
* @param $mailId
*/
public function markMailAsRead($mailId) {
return $this->setFlag(array($mailId), '\\Seen');
$this->setFlag([$mailId], '\\Seen');
}
/**
* Remove the flag \Seen from a mail.
* @return bool
* @param $mailId
*/
public function markMailAsUnread($mailId) {
return $this->clearFlag(array($mailId), '\\Seen');
$this->clearFlag([$mailId], '\\Seen');
}
/**
* Add the flag \Flagged to a mail.
* @return bool
* @param $mailId
*/
public function markMailAsImportant($mailId) {
return $this->setFlag(array($mailId), '\\Flagged');
$this->setFlag([$mailId], '\\Flagged');
}
/**
* Add the flag \Seen to a mails.
* @return bool
* @param array $mailId
*/
public function markMailsAsRead(array $mailId) {
return $this->setFlag($mailId, '\\Seen');
$this->setFlag($mailId, '\\Seen');
}
/**
* Remove the flag \Seen from some mails.
* @return bool
* @param array $mailId
*/
public function markMailsAsUnread(array $mailId) {
return $this->clearFlag($mailId, '\\Seen');
$this->clearFlag($mailId, '\\Seen');
}
/**
* Add the flag \Flagged to some mails.
* @return bool
* @param array $mailId
*/
public function markMailsAsImportant(array $mailId) {
return $this->setFlag($mailId, '\\Flagged');
$this->setFlag($mailId, '\\Flagged');
}
/**
@ -256,10 +339,9 @@ class Mailbox {
*
* @param array $mailsIds
* @param string $flag which you can set are \Seen, \Answered, \Flagged, \Deleted, and \Draft as defined by RFC2060.
* @return bool
*/
public function setFlag(array $mailsIds, $flag) {
return imap_setflag_full($this->getImapStream(), implode(',', $mailsIds), $flag, ST_UID);
$this->imap('setflag_full', [implode(',', $mailsIds), $flag, ST_UID]);
}
/**
@ -267,10 +349,9 @@ class Mailbox {
*
* @param array $mailsIds
* @param string $flag which you can set are \Seen, \Answered, \Flagged, \Deleted, and \Draft as defined by RFC2060.
* @return bool
*/
public function clearFlag(array $mailsIds, $flag) {
return imap_clearflag_full($this->getImapStream(), implode(',', $mailsIds), $flag, ST_UID);
$this->imap('clearflag_full', [implode(',', $mailsIds), $flag, ST_UID]);
}
/**
@ -298,11 +379,9 @@ class Mailbox {
* @return array
*/
public function getMailsInfo(array $mailsIds) {
$mails = imap_fetch_overview($this->getImapStream(), implode(',', $mailsIds), FT_UID);
if(is_array($mails) && count($mails))
{
foreach($mails as &$mail)
{
$mails = $this->imap('fetch_overview', [implode(',', $mailsIds), FT_UID]);
if(is_array($mails) && count($mails)) {
foreach($mails as &$mail) {
if(isset($mail->subject)) {
$mail->subject = $this->decodeMimeStr($mail->subject, $this->serverEncoding);
}
@ -317,6 +396,17 @@ class Mailbox {
return $mails;
}
/**
* Get headers for all messages in the defined mailbox,
* returns an array of string formatted with header info,
* one element per mail message.
*
* @return array
*/
public function getMailboxHeaders() {
return $this->imap('headers');
}
/**
* Get information about the current mailbox.
*
@ -330,11 +420,11 @@ class Mailbox {
* Deleted - number of deleted messages
* Size - mailbox size
*
* @return object Object with info | FALSE on failure
* @return object Object with info
*/
public function getMailboxInfo() {
return imap_mailboxmsginfo($this->getImapStream());
return $this->imap('mailboxmsginfo');
}
/**
@ -354,7 +444,7 @@ class Mailbox {
* @return array Mails ids
*/
public function sortMails($criteria = SORTARRIVAL, $reverse = true) {
return imap_sort($this->getImapStream(), $criteria, $reverse, SE_UID);
return $this->imap('sort', [$criteria, $reverse, SE_UID]);
}
/**
@ -362,88 +452,128 @@ class Mailbox {
* @return int
*/
public function countMails() {
return imap_num_msg($this->getImapStream());
return $this->imap('num_msg');
}
/**
* Retrieve the quota settings per user
* @return array - FALSE in the case of call failure
* @return array
*/
protected function getQuota() {
return imap_get_quotaroot($this->getImapStream(), 'INBOX');
return $this->imap('get_quotaroot', 'INBOX');
}
/**
* Return quota limit in KB
* @return int - FALSE in the case of call failure
* @return int
*/
public function getQuotaLimit() {
$quota = $this->getQuota();
if(is_array($quota)) {
$quota = $quota['STORAGE']['limit'];
}
return $quota;
return isset($quota['STORAGE']['limit']) ? $quota['STORAGE']['limit'] : 0;
}
/**
* Return quota usage in KB
* @return int - FALSE in the case of call failure
* @return int FALSE in the case of call failure
*/
public function getQuotaUsage() {
$quota = $this->getQuota();
if(is_array($quota)) {
$quota = $quota['STORAGE']['usage'];
}
return $quota;
return isset($quota['STORAGE']['usage']) ? $quota['STORAGE']['usage'] : 0;
}
/**
* Get mail data
*
* @param $mailId
* @param bool $markAsSeen
* @return IncomingMail
*/
public function getMail($mailId, $markAsSeen = true) {
$head = imap_rfc822_parse_headers(imap_fetchheader($this->getImapStream(), $mailId, FT_UID));
/**
* Get raw mail data
*
* @param $msgId
* @param bool $markAsSeen
* @return mixed
*/
public function getRawMail($msgId, $markAsSeen = true) {
$options = FT_UID;
if(!$markAsSeen) {
$options |= FT_PEEK;
}
$mail = new IncomingMail();
$mail->id = $mailId;
$mail->date = date('Y-m-d H:i:s', isset($head->date) ? strtotime(preg_replace('/\(.*?\)/', '', $head->date)) : time());
$mail->subject = isset($head->subject) ? $this->decodeMimeStr($head->subject, $this->serverEncoding) : null;
$mail->fromName = isset($head->from[0]->personal) ? $this->decodeMimeStr($head->from[0]->personal, $this->serverEncoding) : null;
$mail->fromAddress = strtolower($head->from[0]->mailbox . '@' . $head->from[0]->host);
return $this->imap('fetchbody', [$msgId, '', $options]);
}
/**
* Get mail header
*
* @param $mailId
* @return IncomingMailHeader
*/
public function getMailHeader($mailId) {
$headersRaw = $this->imap('fetchheader', [$mailId, FT_UID]);
$head = imap_rfc822_parse_headers($headersRaw);
$header = new IncomingMailHeader();
$header->headersRaw = $headersRaw;
$header->headers = $head;
$header->id = $mailId;
$header->date = date('Y-m-d H:i:s', isset($head->date) ? strtotime(preg_replace('/\(.*?\)/', '', $head->date)) : time());
$header->subject = isset($head->subject) ? $this->decodeMimeStr($head->subject, $this->serverEncoding) : null;
if(isset($head->from)) {
$header->fromName = isset($head->from[0]->personal) ? $this->decodeMimeStr($head->from[0]->personal, $this->serverEncoding) : null;
$header->fromAddress = strtolower($head->from[0]->mailbox . '@' . $head->from[0]->host);
}
elseif(preg_match("/smtp.mailfrom=[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+.[a-zA-Z]{2,4}/", $headersRaw, $matches)) {
$header->fromAddress = substr($matches[0], 14);
}
if(isset($head->to)) {
$toStrings = array();
$toStrings = [];
foreach($head->to as $to) {
if(!empty($to->mailbox) && !empty($to->host)) {
$toEmail = strtolower($to->mailbox . '@' . $to->host);
$toName = isset($to->personal) ? $this->decodeMimeStr($to->personal, $this->serverEncoding) : null;
$toStrings[] = $toName ? "$toName <$toEmail>" : $toEmail;
$mail->to[$toEmail] = $toName;
$header->to[$toEmail] = $toName;
}
}
$mail->toString = implode(', ', $toStrings);
$header->toString = implode(', ', $toStrings);
}
if(isset($head->cc)) {
foreach($head->cc as $cc) {
$mail->cc[strtolower($cc->mailbox . '@' . $cc->host)] = isset($cc->personal) ? $this->decodeMimeStr($cc->personal, $this->serverEncoding) : null;
if(!empty($cc->mailbox) && !empty($cc->host)) {
$header->cc[strtolower($cc->mailbox . '@' . $cc->host)] = isset($cc->personal) ? $this->decodeMimeStr($cc->personal, $this->serverEncoding) : null;
}
}
}
if(isset($head->bcc)) {
foreach($head->bcc as $bcc) {
if(!empty($bcc->mailbox) && !empty($bcc->host)) {
$header->bcc[strtolower($bcc->mailbox . '@' . $bcc->host)] = isset($bcc->personal) ? $this->decodeMimeStr($bcc->personal, $this->serverEncoding) : null;
}
}
}
if(isset($head->reply_to)) {
foreach($head->reply_to as $replyTo) {
$mail->replyTo[strtolower($replyTo->mailbox . '@' . $replyTo->host)] = isset($replyTo->personal) ? $this->decodeMimeStr($replyTo->personal, $this->serverEncoding) : null;
$header->replyTo[strtolower($replyTo->mailbox . '@' . $replyTo->host)] = isset($replyTo->personal) ? $this->decodeMimeStr($replyTo->personal, $this->serverEncoding) : null;
}
}
if(isset($head->message_id)) {
$mail->messageId = $head->message_id;
$header->messageId = $head->message_id;
}
$mailStructure = imap_fetchstructure($this->getImapStream(), $mailId, FT_UID);
return $header;
}
/**
* Get mail data
*
* @param $mailId
* @param bool $markAsSeen
* @return IncomingMail
*/
public function getMail($mailId, $markAsSeen = true) {
$mail = new IncomingMail();
$mail->setHeader($this->getMailHeader($mailId));
$mailStructure = $this->imap('fetchstructure', [$mailId, FT_UID]);
if(empty($mailStructure->parts)) {
$this->initMailPart($mail, $mailStructure, 0, $markAsSeen);
@ -458,11 +588,17 @@ class Mailbox {
}
protected function initMailPart(IncomingMail $mail, $partStructure, $partNum, $markAsSeen = true) {
$options = FT_UID;
if(!$markAsSeen) {
$options |= FT_PEEK;
}
$data = $partNum ? imap_fetchbody($this->getImapStream(), $mail->id, $partNum, $options) : imap_body($this->getImapStream(), $mail->id, $options);
$options = FT_UID;
if(!$markAsSeen) {
$options |= FT_PEEK;
}
if($partNum) { // don't use ternary operator to optimize memory usage / parsing speed (see http://fabien.potencier.org/the-php-ternary-operator-fast-or-not.html)
$data = $this->imap('fetchbody', [$mail->id, $partNum, $options]);
}
else {
$data = $this->imap('body', [$mail->id, $options]);
}
if($partStructure->encoding == 1) {
$data = imap_utf8($data);
@ -478,10 +614,10 @@ class Mailbox {
$data = quoted_printable_decode($data);
}
$params = array();
$params = [];
if(!empty($partStructure->parameters)) {
foreach($partStructure->parameters as $param) {
$params[strtolower($param->attribute)] = $param->value;
$params[strtolower($param->attribute)] = $this->decodeMimeStr($param->value);
}
}
if(!empty($partStructure->dparameters)) {
@ -496,12 +632,16 @@ class Mailbox {
}
}
// attachments
$attachmentId = $partStructure->ifid
? trim($partStructure->id, " <>")
: (isset($params['filename']) || isset($params['name']) ? mt_rand() . mt_rand() : null);
$isAttachment = $partStructure->ifid || isset($params['filename']) || isset($params['name']);
// ignore contentId on body when mail isn't multipart (https://github.com/barbushin/php-imap/issues/71)
if(!$partNum && TYPETEXT === $partStructure->type) {
$isAttachment = false;
}
if($isAttachment) {
$attachmentId = mt_rand() . mt_rand();
if($attachmentId) {
if(empty($params['filename']) && empty($params['name'])) {
$fileName = $attachmentId . '.' . strtolower($partStructure->subtype);
}
@ -510,18 +650,27 @@ class Mailbox {
$fileName = $this->decodeMimeStr($fileName, $this->serverEncoding);
$fileName = $this->decodeRFC2231($fileName, $this->serverEncoding);
}
$attachment = new IncomingMailAttachment();
$attachment->id = $attachmentId;
$attachment->contentId = $partStructure->ifid ? trim($partStructure->id, " <>") : null;
$attachment->name = $fileName;
$attachment->disposition = (isset($partStructure->disposition) ? $partStructure->disposition : null);
if($this->attachmentsDir) {
$replace = array(
$replace = [
'/\s/' => '_',
'/[^0-9a-zаіїє_\.]/iu' => '',
'/_+/' => '_',
'/(^_)|(_$)/' => '',
);
];
$fileSysName = preg_replace('~[\\\\/]~', '', $mail->id . '_' . $attachmentId . '_' . preg_replace(array_keys($replace), $replace, $fileName));
$attachment->filePath = $this->attachmentsDir . DIRECTORY_SEPARATOR . $fileSysName;
if(strlen($attachment->filePath) > 255) {
$ext = pathinfo($attachment->filePath, PATHINFO_EXTENSION);
$attachment->filePath = substr($attachment->filePath, 0, 255 - 1 - strlen($ext)) . "." . $ext;
}
file_put_contents($attachment->filePath, $data);
}
$mail->addAttachment($attachment);
@ -544,7 +693,7 @@ class Mailbox {
}
if(!empty($partStructure->parts)) {
foreach($partStructure->parts as $subPartNum => $subPartStructure) {
if($partStructure->type == 2 && $partStructure->subtype == 'RFC822') {
if($partStructure->type == 2 && $partStructure->subtype == 'RFC822' && (!isset($partStructure->disposition) || $partStructure->disposition !== "attachment")) {
$this->initMailPart($mail, $subPartStructure, $partNum, $markAsSeen);
}
else {
@ -554,21 +703,20 @@ class Mailbox {
}
}
protected function decodeMimeStr($string, $charset = 'utf-8') {
protected function decodeMimeStr($string, $toCharset = 'utf-8') {
$newString = '';
$elements = imap_mime_header_decode($string);
for($i = 0; $i < count($elements); $i++) {
if($elements[$i]->charset == 'default') {
$elements[$i]->charset = 'iso-8859-1';
foreach(imap_mime_header_decode($string) as $element) {
if(isset($element->text)) {
$fromCharset = !isset($element->charset) || $element->charset == 'default' ? 'iso-8859-1' : $element->charset;
$newString .= $this->convertStringEncoding($element->text, $fromCharset, $toCharset);
}
$newString .= $this->convertStringEncoding($elements[$i]->text, $elements[$i]->charset, $charset);
}
return $newString;
}
function isUrlEncoded($string) {
$hasInvalidChars = preg_match( '#[^%a-zA-Z0-9\-_\.\+]#', $string );
$hasEscapedChars = preg_match( '#%[a-zA-Z0-9]{2}#', $string );
$hasInvalidChars = preg_match('#[^%a-zA-Z0-9\-_\.\+]#', $string);
$hasEscapedChars = preg_match('#%[a-zA-Z0-9]{2}#', $string);
return !$hasInvalidChars && $hasEscapedChars;
}
@ -589,23 +737,143 @@ class Mailbox {
* @param string $fromEncoding
* @param string $toEncoding
* @return string Converted string if conversion was successful, or the original string if not
* @throws Exception
*/
protected function convertStringEncoding($string, $fromEncoding, $toEncoding) {
$convertedString = null;
if($string && $fromEncoding != $toEncoding) {
$convertedString = @iconv($fromEncoding, $toEncoding . '//IGNORE', $string);
if(!$convertedString && extension_loaded('mbstring')) {
$convertedString = @mb_convert_encoding($string, $toEncoding, $fromEncoding);
}
if(!$string || $fromEncoding == $toEncoding) {
return $string;
}
return $convertedString ?: $string;
$convertedString = function_exists('iconv') ? @iconv($fromEncoding, $toEncoding . '//IGNORE', $string) : null;
if(!$convertedString && extension_loaded('mbstring')) {
$convertedString = @mb_convert_encoding($string, $toEncoding, $fromEncoding);
}
if(!$convertedString) {
throw new Exception('Mime string encoding conversion failed');
}
return $convertedString;
}
public function __destruct() {
$this->disconnect();
}
/**
* Gets imappath
* @return string
*/
public function getImapPath() {
return $this->imapPath;
}
/**
* Get message in MBOX format
* @param $mailId
* @return string
*/
public function getMailMboxFormat($mailId) {
return imap_fetchheader($this->getImapStream(), $mailId, FT_UID && FT_PREFETCHTEXT) . imap_body($this->getImapStream(), $mailId, FT_UID);
}
/**
* Get folders list
* @param string $search
* @return array
*/
public function getMailboxes($search = "*") {
$arr = [];
if($t = imap_getmailboxes($this->getImapStream(), $this->imapPath, $search)) {
foreach($t as $item) {
$arr[] = [
"fullpath" => $item->name,
"attributes" => $item->attributes,
"delimiter" => $item->delimiter,
"shortpath" => substr($item->name, strpos($item->name, '}') + 1),
];
}
}
return $arr;
}
/**
* Get folders list
* @param string $search
* @return array
*/
public function getSubscribedMailboxes($search = "*") {
$arr = [];
if($t = imap_getsubscribed($this->getImapStream(), $this->imapPath, $search)) {
foreach($t as $item) {
$arr[] = [
"fullpath" => $item->name,
"attributes" => $item->attributes,
"delimiter" => $item->delimiter,
"shortpath" => substr($item->name, strpos($item->name, '}') + 1),
];
}
}
return $arr;
}
/**
* @param $mailbox
* @throws Exception
*/
public function subscribeMailbox($mailbox) {
$this->imap('subscribe', $this->imapPath . '.' . $mailbox);
}
/**
* @param $mailbox
* @throws Exception
*/
public function unsubscribeMailbox($mailbox) {
$this->imap('unsubscribe', $this->imapPath . '.' . $mailbox);
}
/**
* Call IMAP extension function call wrapped with utf7 args conversion & errors handling
*
* @param $methodShortName
* @param array|string $args
* @param bool $prependConnectionAsFirstArg
* @param string|null $throwExceptionClass
* @return mixed
* @throws Exception
*/
public function imap($methodShortName, $args = [], $prependConnectionAsFirstArg = true, $throwExceptionClass = Exception::class) {
if(!is_array($args)) {
$args = [$args];
}
foreach($args as &$arg) {
if(is_string($arg)) {
$arg = imap_utf7_encode($arg);
}
}
if($prependConnectionAsFirstArg) {
array_unshift($args, $this->getImapStream());
}
imap_errors(); // flush errors
$result = @call_user_func_array("imap_$methodShortName", $args);
if(!$result) {
$errors = imap_errors();
if($errors) {
if($throwExceptionClass) {
throw new $throwExceptionClass("IMAP method imap_$methodShortName() failed with error: " . implode('. ', $errors));
}
else {
return false;
}
}
}
return $result;
}
}
class Exception extends \Exception {
}
class ConnectionException extends Exception {
}