Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.

Commit bff56aa

Browse files
committed
Change 'a' to return 'A' since Intl always seems to return AM/PM vs am/pm in my tests.
Throwing Exception when unimplemented symbol is used. Adding license file and updating README
1 parent b467545 commit bff56aa

File tree

4 files changed

+761
-467
lines changed

4 files changed

+761
-467
lines changed

LICENSE.txt

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
The MIT License
2+
3+
Copyright 2017
4+
Cake Development Corporation
5+
1785 E. Sahara Avenue, Suite 490-423
6+
Las Vegas, Nevada 89104
7+
Phone: +1 702 425 5085
8+
https://www.cakedc.com
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a copy
11+
of this software and associated documentation files (the "Software"), to deal
12+
in the Software without restriction, including without limitation the rights
13+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
copies of the Software, and to permit persons to whom the Software is
15+
furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included in all
18+
copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
SOFTWARE.

README.md

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
CakeDC Intl Plugin
2+
===================
3+
4+
This plugin library was created to help developers that do not have access to install the PHP intl extension.
5+
It is not met to be a full replace for the PHP extension since it is limited in functionality and should be used with caution.
6+
7+
Versions and branches
8+
============
9+
10+
**This code is still in ALPHA stages**
11+
12+
13+
Requirements
14+
============
15+
16+
* CakePHP 3.0+
17+
* PHP 5.6+ without intl extension (it will still install, but what is the point if you the extension).
18+
19+
Installation
20+
============
21+
22+
Composer
23+
------
24+
Replace my_app with name of directory you will use.
25+
```
26+
composer self-update && composer create-project --prefer-dist cakephp/app my_app_name --ignore-platform-reqs
27+
composer require cakedc/intl
28+
composer update
29+
```
30+
Changes needed in CakePHP
31+
------
32+
33+
in config/bootstrap.php change
34+
```
35+
if (!extension_loaded('intl')) {
36+
trigger_error('You must enable the intl extension to use CakePHP.', E_USER_ERROR);
37+
}
38+
```
39+
to
40+
41+
```
42+
if (!extension_loaded('intl')) {
43+
//trigger_error('You must enable the intl extension to use CakePHP.', E_USER_ERROR);
44+
}
45+
```
46+
47+
48+
Support
49+
============
50+
51+
For bugs and feature requests, please use the [issues](https://github.com/CakeDC/users/issues) section of this repository.
52+
53+
Commercial support is also available, [contact us](https://www.cakedc.com/contact) for more information.
54+
55+
Contributing
56+
============
57+
58+
This repository follows the [CakeDC Plugin Standard](https://www.cakedc.com/plugin-standard). If you'd like to contribute new features, enhancements or bug fixes to the plugin, please read our [Contribution Guidelines](https://www.cakedc.com/contribution-guidelines) for detailed instructions.
59+
60+
License
61+
============
62+
63+
Copyright 2017 Cake Development Corporation (CakeDC). All rights reserved.
64+
65+
Licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php) License. Redistributions of the source code included in this repository must retain the copyright notice found in each file.

src/Utility/PatternParser.php

+13-10
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ class PatternParser
2020
*/
2121
private $symbols =
2222
[
23-
'GGGGG' => 'A',
24-
'GGGGG' => 'A',
25-
'GGGG' => 'Anno Domini',
26-
'GGG' => 'AD',
27-
'GG' => 'AD',
28-
'G' => 'AD',
2923
'yyyy' => 'Y',
3024
'yy' => 'y',
3125
'y' => 'Y',
@@ -55,7 +49,7 @@ class PatternParser
5549
'ccc' => 'D',
5650
'cc' => 'N',
5751
'c' => 'N',
58-
'a' => 'a',
52+
'a' => 'A',
5953
'hh' => 'h',
6054
'h' => 'g',
6155
'HH' => 'H',
@@ -77,6 +71,12 @@ class PatternParser
7771

7872
private $exceptions =
7973
[
74+
'GGGGG',
75+
'GGGGG',
76+
'GGGG',
77+
'GGG',
78+
'GG',
79+
'G',
8080
'u',
8181
'U',
8282
'r',
@@ -166,6 +166,7 @@ public function setPattern($pattern)
166166
public function format()
167167
{
168168
$string = $this->pattern;
169+
$date = '';
169170

170171
if (preg_match('/\'(?<match>[^\']+)\'(?<date>[^\'.]+)/uism', $string, $found)) {
171172
$string = $this->escapeString($found['match']);
@@ -188,7 +189,7 @@ public function escapeString($string)
188189
{
189190
$escape = '\\';
190191
$chars = str_split($string);
191-
return $escape . implode($escape, $chars);;
192+
return $escape . implode($escape, $chars);
192193
}
193194

194195
/**
@@ -200,8 +201,10 @@ protected function parse($string)
200201
$matched = [];
201202

202203
foreach ($this->exceptions as $exception) {
203-
if (strpos($string, $exception)) {
204-
throw new \Exception('This library does not implement these charecters, install intl extention to use http://php.net/manual/en/book.intl.php');
204+
$pos = strpos($string, $exception);
205+
if ($pos !== false) {
206+
throw new \Exception("This library does not implement the $exception sybmol, install intl extention to use http://php.net/manual/en/book.intl.php");
207+
break;
205208
}
206209
}
207210

0 commit comments

Comments
 (0)