summaryrefslogtreecommitdiffstats
path: root/b452b5aa962b21316492c762639b6b4b659c8c6e.patch
blob: c0fe317eefc9f4a25a4f8b6225571be559ea63f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
From b452b5aa962b21316492c762639b6b4b659c8c6e Mon Sep 17 00:00:00 2001
From: Jan Schneider <jan@horde.org>
Date: Mon, 13 Feb 2017 18:38:59 +0100
Subject: [PATCH] Don't use create_function().

It's deprecated and unsafe and closures should be used instead.
---
 lib/Horde/Date/Parser.php             | 13 ++++++++++++-
 lib/Horde/Date/Parser/Locale/Base.php | 31 +++++++++++++++++++++++++------
 lib/Horde/Date/Parser/Locale/Pt.php   |  4 +++-
 lib/Horde/Date/Parser/Result.php      | 16 ++++++++++++----
 lib/Horde/Date/Parser/Token.php       | 14 ++++++++++++--
 5 files changed, 64 insertions(+), 14 deletions(-)

diff --git a/lib/Horde/Date/Parser.php b/lib/Horde/Date/Parser.php
index b297932..29c542e 100644
--- a/lib/Horde/Date/Parser.php
+++ b/lib/Horde/Date/Parser.php
@@ -44,7 +44,18 @@ public static function getLocales()
         foreach (new DirectoryIterator($dir) as $f) {
             if ($f->isFile()) {
                 $locale = str_replace('.php', '', $f->getFilename());
-                $locale = preg_replace_callback('/([A-Z][a-z]*)([A-Z].*)?/', create_function('$m', 'if (!isset($m[2])) { return Horde_String::lower($m[1]); } else { return Horde_String::lower($m[1]) . "_" . Horde_String::upper($m[2]); }'), $locale);
+                $locale = preg_replace_callback(
+                    '/([A-Z][a-z]*)([A-Z].*)?/',
+                    function ($m) {
+                        if (!isset($m[2])) {
+                            return Horde_String::lower($m[1]);
+                        } else {
+                            return Horde_String::lower($m[1])
+                                . '_' . Horde_String::upper($m[2]);
+                        }
+                    },
+                    $locale
+                );
                 $locales[] = $locale;
             }
         }
diff --git a/lib/Horde/Date/Parser/Locale/Base.php b/lib/Horde/Date/Parser/Locale/Base.php
index 882e0fc..647b2fc 100644
--- a/lib/Horde/Date/Parser/Locale/Base.php
+++ b/lib/Horde/Date/Parser/Locale/Base.php
@@ -97,7 +97,9 @@ public function parse($text, $specifiedOptions = array())
         }
 
         // strip any non-tagged tokens
-        $taggedTokens = array_values(array_filter($tokens, create_function('$t', 'return $t->tagged();')));
+        $taggedTokens = array_values(array_filter(
+            $tokens, function ($t) { return $t->tagged(); }
+        ));
 
         // Remove tokens we know we don't want - for example, if the first token
         // is a separator, drop it.
@@ -197,7 +199,10 @@ public function numericizeOrdinals($text)
      */
     public function preTokenize($text)
     {
-        return array_map(create_function('$w', 'return new Horde_Date_Parser_Token($w);'), preg_split('/\s+/', $text));
+        return array_map(
+            function ($w) { return new Horde_Date_Parser_Token($w); },
+            preg_split('/\s+/', $text)
+        );
     }
 
     /**
@@ -292,7 +297,9 @@ public function tokensToSpan($tokens, $options)
         // maybe it's a specific date
         foreach ($this->definitions['date'] as $handler) {
             if ($handler->match($tokens, $this->definitions)) {
-                $goodTokens = array_values(array_filter($tokens, create_function('$o', 'return !$o->getTag("separator");')));
+                $goodTokens = array_values(array_filter(
+                    $tokens, function ($o) { return !$o->getTag('separator'); }
+                ));
                 $this->debug($handler->handlerMethod, $goodTokens, $options);
                 return call_user_func(array($this, $handler->handlerMethod), $goodTokens, $options);
             }
@@ -301,7 +308,9 @@ public function tokensToSpan($tokens, $options)
         // I guess it's not a specific date, maybe it's just an anchor
         foreach ($this->definitions['anchor'] as $handler) {
             if ($handler->match($tokens, $this->definitions)) {
-                $goodTokens = array_values(array_filter($tokens, create_function('$o', 'return !$o->getTag("separator");')));
+                $goodTokens = array_values(array_filter(
+                    $tokens, function ($o) { return !$o->getTag('separator'); }
+                ));
                 $this->debug($handler->handlerMethod, $goodTokens, $options);
                 return call_user_func(array($this, $handler->handlerMethod), $goodTokens, $options);
             }
@@ -310,7 +319,14 @@ public function tokensToSpan($tokens, $options)
         // not an anchor, perhaps it's an arrow
         foreach ($this->definitions['arrow'] as $handler) {
             if ($handler->match($tokens, $this->definitions)) {
-                $goodTokens = array_values(array_filter($tokens, create_function('$o', 'return !$o->getTag("separator_at") && !$o->getTag("separator_slash_or_dash") && !$o->getTag("separator_comma");')));
+                $goodTokens = array_values(array_filter(
+                    $tokens,
+                    function ($o) {
+                        return !$o->getTag('separator_at') &&
+                            !$o->getTag('separator_slash_or_dash') &&
+                            !$o->getTag('separator_comma');
+                    }
+                ));
                 $this->debug($handler->handlerMethod, $goodTokens, $options);
                 return call_user_func(array($this, $handler->handlerMethod), $goodTokens, $options);
             }
@@ -603,7 +619,10 @@ public function getRepeaters($tokens)
         }
 
         // Return repeaters in order from widest (years) to smallest (seconds)
-        usort($repeaters, create_function('$a, $b', 'return $b->width() > $a->width();'));
+        usort(
+            $repeaters,
+            function ($a, $b) { return $b->width() > $a->width(); }
+        );
         return $repeaters;
     }
 
diff --git a/lib/Horde/Date/Parser/Locale/Pt.php b/lib/Horde/Date/Parser/Locale/Pt.php
index 79d43b3..f5f2e40 100644
--- a/lib/Horde/Date/Parser/Locale/Pt.php
+++ b/lib/Horde/Date/Parser/Locale/Pt.php
@@ -100,7 +100,9 @@ public function parse($text, $specifiedOptions = array())
         }
 
         // strip any non-tagged tokens
-        $taggedTokens = array_values(array_filter($tokens, create_function('$t', 'return $t->tagged();')));
+        $taggedTokens = array_values(array_filter(
+            $tokens, function ($t) { return $t->tagged(); }
+        ));
 
         // Remove tokens we know we don't want - for example, if the first
         // token is a separator, drop it.
diff --git a/lib/Horde/Date/Parser/Result.php b/lib/Horde/Date/Parser/Result.php
index 415b77c..859d14a 100644
--- a/lib/Horde/Date/Parser/Result.php
+++ b/lib/Horde/Date/Parser/Result.php
@@ -28,14 +28,22 @@ public function guess()
 
     public function taggedText()
     {
-        $taggedTokens = array_values(array_filter($this->tokens, create_function('$t', 'return $t->tagged();')));
-        return implode(' ', array_map(create_function('$t', 'return $t->word;'), $taggedTokens));
+        $taggedTokens = array_values(array_filter(
+            $this->tokens, function ($t) { return $t->tagged(); }
+        ));
+        return implode(
+            ' ', array_map(function ($t) { return $t->word; }, $taggedTokens)
+        );
     }
 
     public function untaggedText()
     {
-        $untaggedTokens = array_values(array_filter($this->tokens, create_function('$t', 'return ! $t->tagged();')));
-        return implode(' ', array_map(create_function('$t', 'return $t->word;'), $untaggedTokens));
+        $untaggedTokens = array_values(array_filter(
+            $this->tokens, function ($t) { return !$t->tagged(); }
+        ));
+        return implode(
+            ' ', array_map(function ($t) { return $t->word; }, $untaggedTokens)
+        );
     }
 
 }
diff --git a/lib/Horde/Date/Parser/Token.php b/lib/Horde/Date/Parser/Token.php
index 39aeca4..5e88d74 100644
--- a/lib/Horde/Date/Parser/Token.php
+++ b/lib/Horde/Date/Parser/Token.php
@@ -23,7 +23,12 @@ public function tag($tagClass, $tag)
      */
     public function untag($tagClass)
     {
-        $this->tags = array_filter($this->tags, create_function('$t', 'return substr($t[0], 0, ' . strlen($tagClass) . ') != "' . $tagClass . '";'));
+        $this->tags = array_filter(
+            $this->tags,
+            function ($t) use ($tagClass) {
+                return substr($t[0], 0, strlen($tagClass)) != $tagClass;
+            }
+        );
     }
 
     /**
@@ -39,7 +44,12 @@ public function tagged()
      */
     public function getTag($tagClass)
     {
-        $matches = array_filter($this->tags, create_function('$t', 'return substr($t[0], 0, ' . strlen($tagClass) . ') == "' . $tagClass . '";'));
+        $matches = array_filter(
+            $this->tags,
+            function ($t) use ($tagClass) {
+                return substr($t[0], 0, strlen($tagClass)) == $tagClass;
+            }
+        );
         $match = array_shift($matches);
         return $match[1];
     }