├── .gitignore
├── .twig_cache
└── .gitignore
├── resources
└── css
│ └── app.css
├── templates
├── _boolean.twig
├── error.twig
├── inputData.twig
├── home.twig
├── _page.twig
└── data.twig
├── composer.json
├── README.md
├── LICENSE
├── index.php
└── composer.lock
/.gitignore:
--------------------------------------------------------------------------------
1 | vendor/
2 |
--------------------------------------------------------------------------------
/.twig_cache/.gitignore:
--------------------------------------------------------------------------------
1 | !.gitignore
2 |
3 |
--------------------------------------------------------------------------------
/resources/css/app.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding-top: 70px;
3 | }
4 |
5 | dt, dd {
6 | line-height: 2.75;
7 | }
8 |
9 | .tooltip-inner {
10 | max-width: 400px;
11 | }
12 |
13 | #country-list {
14 | max-height: 500px;
15 | }
16 |
--------------------------------------------------------------------------------
/templates/_boolean.twig:
--------------------------------------------------------------------------------
1 | {% if v == true %}
2 | true
3 | {% elseif v == false %}
4 | false
5 | {% else %}
6 | Boolean value not passed in
7 | {% endif %}
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "description": "An example site using libphonenumber-for-php",
3 | "license": "MIT",
4 | "authors": [
5 | {
6 | "name": "Joshua Gigg",
7 | "email": "giggsey@gmail.com",
8 | "homepage": "http://giggsey.com/"
9 | }
10 | ],
11 | "require": {
12 | "php": ">=7.4",
13 | "ext-json": "*",
14 | "giggsey/libphonenumber-for-php": "^8.0",
15 | "twig/twig": "^3.0",
16 | "umpirsky/country-list": "^2.0"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | libphonenumber-example
2 | ======================
3 |
4 | A simple demo application highlighting common features from [libphonenumber-for-php](https://github.com/giggsey/libphonenumber-for-php), hosted on [giggsey.com](https://giggsey.com/libphonenumber/).
5 |
6 | ### Installation
7 |
8 | - Clone the repository
9 | - Run `composer install`
10 |
11 | ### Support
12 |
13 | Support is not offered directly with this demo repository.
14 |
15 | If you're having issues with libphonenumber-for-php, this demo can be used to check example numbers. Otherwise, check the [FAQ](https://github.com/giggsey/libphonenumber-for-php#faq) for libphonenumber-for-php.
16 |
--------------------------------------------------------------------------------
/templates/error.twig:
--------------------------------------------------------------------------------
1 | {% extends '_page.twig' %}
2 | {% block title %}libphonenumber-for-php Demo » Error{% endblock %}
3 | {% block content %}
4 |
« Back to form
5 |
6 | {% include 'inputData.twig' %}
7 |
8 |
9 |
10 |
11 | Exception Thrown: {{ get_class(exception) }} ({{ exception.getCode() }})
13 |
14 |
{{ exception.getMessage() }}
15 |
16 |
17 |
18 | {% endblock %}
19 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Joshua Gigg (giggsey)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OTHER IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/templates/inputData.twig:
--------------------------------------------------------------------------------
1 | Input Data
2 |
36 |
--------------------------------------------------------------------------------
/templates/home.twig:
--------------------------------------------------------------------------------
1 | {% extends '_page.twig' %}
2 | {% block title %}libphonenumber-for-php Demo{% endblock %}
3 | {% block content %}
4 | libphonenumber-for-php Demo
5 |
54 | {% endblock %}
55 |
--------------------------------------------------------------------------------
/templates/_page.twig:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | {% block title %}{% endblock %}
7 |
8 |
9 |
11 |
14 |
16 |
17 |
18 |
19 |
20 |
23 |
24 |
25 |
39 |
40 |
41 |
42 | {% block content %}{% endblock %}
43 |
44 |
45 |
54 |
55 |
58 |
75 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 | addGlobal('baseurl', $_SERVER['SCRIPT_NAME']);
9 | $twig->addGlobal('phpversion', phpversion());
10 | $twig->addGlobal('version', \Composer\InstalledVersions::getVersion('giggsey/libphonenumber-for-php'));
11 |
12 | $twig->addFunction(new \Twig\TwigFunction('get_class', 'get_class'));
13 |
14 | /* Check if we have loaded variables */
15 | if (isset($_GET['phonenumber']) && $_GET['phonenumber'] != '') {
16 |
17 | $input = array();
18 | $input['phonenumber'] = $_GET['phonenumber'];
19 | $input['country'] = (isset($_GET['country'])) ? $_GET['country'] : null;
20 | $input['language'] = (isset($_GET['language']) && $_GET['language'] != '') ? $_GET['language'] : 'en';
21 | $input['region'] = (isset($_GET['region']) && $_GET['region'] != '') ? $_GET['region'] : null;
22 |
23 |
24 | $phoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance();
25 | $shortNumberInfo = \libphonenumber\ShortNumberInfo::getInstance();
26 | $phoneNumberGeocoder = \libphonenumber\geocoding\PhoneNumberOfflineGeocoder::getInstance();
27 |
28 | $validNumber = false;
29 | $validNumberForRegion = false;
30 | $possibleNumber = false;
31 | $isPossibleNumberWithReason = null;
32 | $geolocation = null;
33 | $phoneNumberToCarrierInfo = null;
34 | $timezone = null;
35 |
36 | try {
37 | $phoneNumber = $phoneNumberUtil->parse($input['phonenumber'], $input['country'], null, true);
38 | $possibleNumber = $phoneNumberUtil->isPossibleNumber($phoneNumber);
39 | $isPossibleNumberWithReason = $phoneNumberUtil->isPossibleNumberWithReason($phoneNumber);
40 | $validNumber = $phoneNumberUtil->isValidNumber($phoneNumber);
41 | $validNumberForRegion = $phoneNumberUtil->isValidNumberForRegion($phoneNumber, $input['country']);
42 | $phoneNumberRegion = $phoneNumberUtil->getRegionCodeForNumber($phoneNumber);
43 | $phoneNumberType = $phoneNumberUtil->getNumberType($phoneNumber);
44 |
45 | $geolocation = $phoneNumberGeocoder->getDescriptionForNumber(
46 | $phoneNumber,
47 | $input['language'],
48 | $input['region']
49 | );
50 |
51 | $phoneNumberToCarrierInfo = \libphonenumber\PhoneNumberToCarrierMapper::getInstance()->getNameForNumber(
52 | $phoneNumber,
53 | $input['language']
54 | );
55 | $timezone = \libphonenumber\PhoneNumberToTimeZonesMapper::getInstance()->getTimeZonesForNumber($phoneNumber);
56 |
57 | } catch (\Exception $e) {
58 | echo $twig->render(
59 | 'error.twig',
60 | array(
61 | 'input' => $input,
62 | 'exception' => $e,
63 | )
64 | );
65 | exit;
66 | }
67 |
68 | $regions = $phoneNumberUtil->getSupportedRegions();
69 |
70 | asort($regions);
71 |
72 | $baseLanguagePath = __DIR__ . '/vendor/umpirsky/country-list/data/';
73 |
74 | $resolvedPath = realpath($baseLanguagePath . $input['language'] . '/country.php');
75 | if (strpos($resolvedPath, $baseLanguagePath) === 0 && file_exists($resolvedPath)) {
76 | $countries = require $resolvedPath;
77 | } else {
78 | $countries = require $baseLanguagePath . 'en/country.php';
79 | }
80 |
81 | echo $twig->render(
82 | 'data.twig',
83 | array(
84 | 'phoneNumberObj' => $phoneNumber,
85 | 'phoneUtil' => $phoneNumberUtil,
86 | 'possibleNumber' => $possibleNumber,
87 | 'isPossibleNumberWithReason' => $isPossibleNumberWithReason,
88 | 'validNumber' => $validNumber,
89 | 'validNumberForRegion' => $validNumberForRegion,
90 | 'phoneNumberRegion' => $phoneNumberRegion,
91 | 'phoneNumberType' => $phoneNumberType,
92 | 'geolocation' => $geolocation,
93 | 'timezone' => $timezone,
94 | 'carrierinfo' => $phoneNumberToCarrierInfo,
95 | 'shortNumber' => $shortNumberInfo,
96 | 'input' => $input,
97 | 'regions' => $regions,
98 | 'countries' => $countries,
99 | )
100 | );
101 | } else {
102 | echo $twig->render('home.twig');
103 | }
104 |
--------------------------------------------------------------------------------
/composer.lock:
--------------------------------------------------------------------------------
1 | {
2 | "_readme": [
3 | "This file locks the dependencies of your project to a known state",
4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5 | "This file is @generated automatically"
6 | ],
7 | "content-hash": "b07c85841268267cc8310de3800de897",
8 | "packages": [
9 | {
10 | "name": "giggsey/libphonenumber-for-php",
11 | "version": "8.12.57",
12 | "source": {
13 | "type": "git",
14 | "url": "https://github.com/giggsey/libphonenumber-for-php.git",
15 | "reference": "033a7285fd1102c13c4415e300734b7ce7ca0ae0"
16 | },
17 | "dist": {
18 | "type": "zip",
19 | "url": "https://api.github.com/repos/giggsey/libphonenumber-for-php/zipball/033a7285fd1102c13c4415e300734b7ce7ca0ae0",
20 | "reference": "033a7285fd1102c13c4415e300734b7ce7ca0ae0",
21 | "shasum": ""
22 | },
23 | "require": {
24 | "giggsey/locale": "^1.7|^2.0",
25 | "php": ">=5.3.2",
26 | "symfony/polyfill-mbstring": "^1.17"
27 | },
28 | "require-dev": {
29 | "pear/pear-core-minimal": "^1.9",
30 | "pear/pear_exception": "^1.0",
31 | "pear/versioncontrol_git": "^0.5",
32 | "phing/phing": "^2.7",
33 | "php-coveralls/php-coveralls": "^1.0|^2.0",
34 | "symfony/console": "^2.8|^3.0|^v4.4|^v5.2",
35 | "symfony/phpunit-bridge": "^4.2 || ^5"
36 | },
37 | "type": "library",
38 | "extra": {
39 | "branch-alias": {
40 | "dev-master": "8.x-dev"
41 | }
42 | },
43 | "autoload": {
44 | "psr-4": {
45 | "libphonenumber\\": "src/"
46 | },
47 | "exclude-from-classmap": [
48 | "/src/data/",
49 | "/src/carrier/data/",
50 | "/src/geocoding/data/",
51 | "/src/timezone/data/"
52 | ]
53 | },
54 | "notification-url": "https://packagist.org/downloads/",
55 | "license": [
56 | "Apache-2.0"
57 | ],
58 | "authors": [
59 | {
60 | "name": "Joshua Gigg",
61 | "email": "giggsey@gmail.com",
62 | "homepage": "https://giggsey.com/"
63 | }
64 | ],
65 | "description": "PHP Port of Google's libphonenumber",
66 | "homepage": "https://github.com/giggsey/libphonenumber-for-php",
67 | "keywords": [
68 | "geocoding",
69 | "geolocation",
70 | "libphonenumber",
71 | "mobile",
72 | "phonenumber",
73 | "validation"
74 | ],
75 | "support": {
76 | "irc": "irc://irc.appliedirc.com/lobby",
77 | "issues": "https://github.com/giggsey/libphonenumber-for-php/issues",
78 | "source": "https://github.com/giggsey/libphonenumber-for-php"
79 | },
80 | "time": "2022-10-14T07:52:28+00:00"
81 | },
82 | {
83 | "name": "giggsey/locale",
84 | "version": "2.3",
85 | "source": {
86 | "type": "git",
87 | "url": "https://github.com/giggsey/Locale.git",
88 | "reference": "5f035523740be40d40ac768a123c9bcc1ae12f56"
89 | },
90 | "dist": {
91 | "type": "zip",
92 | "url": "https://api.github.com/repos/giggsey/Locale/zipball/5f035523740be40d40ac768a123c9bcc1ae12f56",
93 | "reference": "5f035523740be40d40ac768a123c9bcc1ae12f56",
94 | "shasum": ""
95 | },
96 | "require": {
97 | "php": ">=7.2"
98 | },
99 | "require-dev": {
100 | "ext-json": "*",
101 | "pear/pear-core-minimal": "^1.9",
102 | "pear/pear_exception": "^1.0",
103 | "pear/versioncontrol_git": "^0.5",
104 | "phing/phing": "^2.7",
105 | "php-coveralls/php-coveralls": "^2.0",
106 | "phpunit/phpunit": "^8.5|^9.5",
107 | "symfony/console": "^5.0|^6.0",
108 | "symfony/filesystem": "^5.0|^6.0",
109 | "symfony/finder": "^5.0|^6.0",
110 | "symfony/process": "^5.0|^6.0"
111 | },
112 | "type": "library",
113 | "autoload": {
114 | "psr-4": {
115 | "Giggsey\\Locale\\": "src/"
116 | }
117 | },
118 | "notification-url": "https://packagist.org/downloads/",
119 | "license": [
120 | "MIT"
121 | ],
122 | "authors": [
123 | {
124 | "name": "Joshua Gigg",
125 | "email": "giggsey@gmail.com",
126 | "homepage": "https://giggsey.com/"
127 | }
128 | ],
129 | "description": "Locale functions required by libphonenumber-for-php",
130 | "support": {
131 | "issues": "https://github.com/giggsey/Locale/issues",
132 | "source": "https://github.com/giggsey/Locale/tree/2.3"
133 | },
134 | "time": "2022-10-19T20:03:30+00:00"
135 | },
136 | {
137 | "name": "symfony/deprecation-contracts",
138 | "version": "v3.0.2",
139 | "source": {
140 | "type": "git",
141 | "url": "https://github.com/symfony/deprecation-contracts.git",
142 | "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c"
143 | },
144 | "dist": {
145 | "type": "zip",
146 | "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/26954b3d62a6c5fd0ea8a2a00c0353a14978d05c",
147 | "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c",
148 | "shasum": ""
149 | },
150 | "require": {
151 | "php": ">=8.0.2"
152 | },
153 | "type": "library",
154 | "extra": {
155 | "branch-alias": {
156 | "dev-main": "3.0-dev"
157 | },
158 | "thanks": {
159 | "name": "symfony/contracts",
160 | "url": "https://github.com/symfony/contracts"
161 | }
162 | },
163 | "autoload": {
164 | "files": [
165 | "function.php"
166 | ]
167 | },
168 | "notification-url": "https://packagist.org/downloads/",
169 | "license": [
170 | "MIT"
171 | ],
172 | "authors": [
173 | {
174 | "name": "Nicolas Grekas",
175 | "email": "p@tchwork.com"
176 | },
177 | {
178 | "name": "Symfony Community",
179 | "homepage": "https://symfony.com/contributors"
180 | }
181 | ],
182 | "description": "A generic function and convention to trigger deprecation notices",
183 | "homepage": "https://symfony.com",
184 | "support": {
185 | "source": "https://github.com/symfony/deprecation-contracts/tree/v3.0.2"
186 | },
187 | "funding": [
188 | {
189 | "url": "https://symfony.com/sponsor",
190 | "type": "custom"
191 | },
192 | {
193 | "url": "https://github.com/fabpot",
194 | "type": "github"
195 | },
196 | {
197 | "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
198 | "type": "tidelift"
199 | }
200 | ],
201 | "time": "2022-01-02T09:55:41+00:00"
202 | },
203 | {
204 | "name": "symfony/polyfill-ctype",
205 | "version": "v1.31.0",
206 | "source": {
207 | "type": "git",
208 | "url": "https://github.com/symfony/polyfill-ctype.git",
209 | "reference": "a3cc8b044a6ea513310cbd48ef7333b384945638"
210 | },
211 | "dist": {
212 | "type": "zip",
213 | "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/a3cc8b044a6ea513310cbd48ef7333b384945638",
214 | "reference": "a3cc8b044a6ea513310cbd48ef7333b384945638",
215 | "shasum": ""
216 | },
217 | "require": {
218 | "php": ">=7.2"
219 | },
220 | "provide": {
221 | "ext-ctype": "*"
222 | },
223 | "suggest": {
224 | "ext-ctype": "For best performance"
225 | },
226 | "type": "library",
227 | "extra": {
228 | "thanks": {
229 | "name": "symfony/polyfill",
230 | "url": "https://github.com/symfony/polyfill"
231 | }
232 | },
233 | "autoload": {
234 | "files": [
235 | "bootstrap.php"
236 | ],
237 | "psr-4": {
238 | "Symfony\\Polyfill\\Ctype\\": ""
239 | }
240 | },
241 | "notification-url": "https://packagist.org/downloads/",
242 | "license": [
243 | "MIT"
244 | ],
245 | "authors": [
246 | {
247 | "name": "Gert de Pagter",
248 | "email": "BackEndTea@gmail.com"
249 | },
250 | {
251 | "name": "Symfony Community",
252 | "homepage": "https://symfony.com/contributors"
253 | }
254 | ],
255 | "description": "Symfony polyfill for ctype functions",
256 | "homepage": "https://symfony.com",
257 | "keywords": [
258 | "compatibility",
259 | "ctype",
260 | "polyfill",
261 | "portable"
262 | ],
263 | "support": {
264 | "source": "https://github.com/symfony/polyfill-ctype/tree/v1.31.0"
265 | },
266 | "funding": [
267 | {
268 | "url": "https://symfony.com/sponsor",
269 | "type": "custom"
270 | },
271 | {
272 | "url": "https://github.com/fabpot",
273 | "type": "github"
274 | },
275 | {
276 | "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
277 | "type": "tidelift"
278 | }
279 | ],
280 | "time": "2024-09-09T11:45:10+00:00"
281 | },
282 | {
283 | "name": "symfony/polyfill-mbstring",
284 | "version": "v1.31.0",
285 | "source": {
286 | "type": "git",
287 | "url": "https://github.com/symfony/polyfill-mbstring.git",
288 | "reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341"
289 | },
290 | "dist": {
291 | "type": "zip",
292 | "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/85181ba99b2345b0ef10ce42ecac37612d9fd341",
293 | "reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341",
294 | "shasum": ""
295 | },
296 | "require": {
297 | "php": ">=7.2"
298 | },
299 | "provide": {
300 | "ext-mbstring": "*"
301 | },
302 | "suggest": {
303 | "ext-mbstring": "For best performance"
304 | },
305 | "type": "library",
306 | "extra": {
307 | "thanks": {
308 | "name": "symfony/polyfill",
309 | "url": "https://github.com/symfony/polyfill"
310 | }
311 | },
312 | "autoload": {
313 | "files": [
314 | "bootstrap.php"
315 | ],
316 | "psr-4": {
317 | "Symfony\\Polyfill\\Mbstring\\": ""
318 | }
319 | },
320 | "notification-url": "https://packagist.org/downloads/",
321 | "license": [
322 | "MIT"
323 | ],
324 | "authors": [
325 | {
326 | "name": "Nicolas Grekas",
327 | "email": "p@tchwork.com"
328 | },
329 | {
330 | "name": "Symfony Community",
331 | "homepage": "https://symfony.com/contributors"
332 | }
333 | ],
334 | "description": "Symfony polyfill for the Mbstring extension",
335 | "homepage": "https://symfony.com",
336 | "keywords": [
337 | "compatibility",
338 | "mbstring",
339 | "polyfill",
340 | "portable",
341 | "shim"
342 | ],
343 | "support": {
344 | "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.31.0"
345 | },
346 | "funding": [
347 | {
348 | "url": "https://symfony.com/sponsor",
349 | "type": "custom"
350 | },
351 | {
352 | "url": "https://github.com/fabpot",
353 | "type": "github"
354 | },
355 | {
356 | "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
357 | "type": "tidelift"
358 | }
359 | ],
360 | "time": "2024-09-09T11:45:10+00:00"
361 | },
362 | {
363 | "name": "symfony/polyfill-php81",
364 | "version": "v1.31.0",
365 | "source": {
366 | "type": "git",
367 | "url": "https://github.com/symfony/polyfill-php81.git",
368 | "reference": "4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c"
369 | },
370 | "dist": {
371 | "type": "zip",
372 | "url": "https://api.github.com/repos/symfony/polyfill-php81/zipball/4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c",
373 | "reference": "4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c",
374 | "shasum": ""
375 | },
376 | "require": {
377 | "php": ">=7.2"
378 | },
379 | "type": "library",
380 | "extra": {
381 | "thanks": {
382 | "name": "symfony/polyfill",
383 | "url": "https://github.com/symfony/polyfill"
384 | }
385 | },
386 | "autoload": {
387 | "files": [
388 | "bootstrap.php"
389 | ],
390 | "psr-4": {
391 | "Symfony\\Polyfill\\Php81\\": ""
392 | },
393 | "classmap": [
394 | "Resources/stubs"
395 | ]
396 | },
397 | "notification-url": "https://packagist.org/downloads/",
398 | "license": [
399 | "MIT"
400 | ],
401 | "authors": [
402 | {
403 | "name": "Nicolas Grekas",
404 | "email": "p@tchwork.com"
405 | },
406 | {
407 | "name": "Symfony Community",
408 | "homepage": "https://symfony.com/contributors"
409 | }
410 | ],
411 | "description": "Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions",
412 | "homepage": "https://symfony.com",
413 | "keywords": [
414 | "compatibility",
415 | "polyfill",
416 | "portable",
417 | "shim"
418 | ],
419 | "support": {
420 | "source": "https://github.com/symfony/polyfill-php81/tree/v1.31.0"
421 | },
422 | "funding": [
423 | {
424 | "url": "https://symfony.com/sponsor",
425 | "type": "custom"
426 | },
427 | {
428 | "url": "https://github.com/fabpot",
429 | "type": "github"
430 | },
431 | {
432 | "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
433 | "type": "tidelift"
434 | }
435 | ],
436 | "time": "2024-09-09T11:45:10+00:00"
437 | },
438 | {
439 | "name": "twig/twig",
440 | "version": "v3.14.0",
441 | "source": {
442 | "type": "git",
443 | "url": "https://github.com/twigphp/Twig.git",
444 | "reference": "126b2c97818dbff0cdf3fbfc881aedb3d40aae72"
445 | },
446 | "dist": {
447 | "type": "zip",
448 | "url": "https://api.github.com/repos/twigphp/Twig/zipball/126b2c97818dbff0cdf3fbfc881aedb3d40aae72",
449 | "reference": "126b2c97818dbff0cdf3fbfc881aedb3d40aae72",
450 | "shasum": ""
451 | },
452 | "require": {
453 | "php": ">=8.0.2",
454 | "symfony/deprecation-contracts": "^2.5|^3",
455 | "symfony/polyfill-ctype": "^1.8",
456 | "symfony/polyfill-mbstring": "^1.3",
457 | "symfony/polyfill-php81": "^1.29"
458 | },
459 | "require-dev": {
460 | "psr/container": "^1.0|^2.0",
461 | "symfony/phpunit-bridge": "^5.4.9|^6.4|^7.0"
462 | },
463 | "type": "library",
464 | "autoload": {
465 | "files": [
466 | "src/Resources/core.php",
467 | "src/Resources/debug.php",
468 | "src/Resources/escaper.php",
469 | "src/Resources/string_loader.php"
470 | ],
471 | "psr-4": {
472 | "Twig\\": "src/"
473 | }
474 | },
475 | "notification-url": "https://packagist.org/downloads/",
476 | "license": [
477 | "BSD-3-Clause"
478 | ],
479 | "authors": [
480 | {
481 | "name": "Fabien Potencier",
482 | "email": "fabien@symfony.com",
483 | "homepage": "http://fabien.potencier.org",
484 | "role": "Lead Developer"
485 | },
486 | {
487 | "name": "Twig Team",
488 | "role": "Contributors"
489 | },
490 | {
491 | "name": "Armin Ronacher",
492 | "email": "armin.ronacher@active-4.com",
493 | "role": "Project Founder"
494 | }
495 | ],
496 | "description": "Twig, the flexible, fast, and secure template language for PHP",
497 | "homepage": "https://twig.symfony.com",
498 | "keywords": [
499 | "templating"
500 | ],
501 | "support": {
502 | "issues": "https://github.com/twigphp/Twig/issues",
503 | "source": "https://github.com/twigphp/Twig/tree/v3.14.0"
504 | },
505 | "funding": [
506 | {
507 | "url": "https://github.com/fabpot",
508 | "type": "github"
509 | },
510 | {
511 | "url": "https://tidelift.com/funding/github/packagist/twig/twig",
512 | "type": "tidelift"
513 | }
514 | ],
515 | "time": "2024-09-09T17:55:12+00:00"
516 | },
517 | {
518 | "name": "umpirsky/country-list",
519 | "version": "2.0.6",
520 | "source": {
521 | "type": "git",
522 | "url": "https://github.com/umpirsky/country-list.git",
523 | "reference": "6dddae6983c1bc4d314b513c5decb7c8c6c879dc"
524 | },
525 | "dist": {
526 | "type": "zip",
527 | "url": "https://api.github.com/repos/umpirsky/country-list/zipball/6dddae6983c1bc4d314b513c5decb7c8c6c879dc",
528 | "reference": "6dddae6983c1bc4d314b513c5decb7c8c6c879dc",
529 | "shasum": ""
530 | },
531 | "require": {
532 | "php": "^7.0 || ^8.0"
533 | },
534 | "require-dev": {
535 | "slowprog/composer-copy-file": "^0.2",
536 | "symfony/intl": "^4.3",
537 | "umpirsky/list-generator": "^1.2"
538 | },
539 | "type": "library",
540 | "extra": {
541 | "copy-file": {
542 | "vendor/umpirsky/list-generator/Dockerfile": "./",
543 | "vendor/umpirsky/list-generator/docker-compose.yml": "./"
544 | }
545 | },
546 | "notification-url": "https://packagist.org/downloads/",
547 | "license": [
548 | "MIT"
549 | ],
550 | "authors": [
551 | {
552 | "name": "Saša Stamenković",
553 | "email": "umpirsky@gmail.com"
554 | }
555 | ],
556 | "description": "List of all countries with names and ISO 3166-1 codes in all languages and data formats.",
557 | "support": {
558 | "issues": "https://github.com/umpirsky/country-list/issues",
559 | "source": "https://github.com/umpirsky/country-list/tree/2.0.6"
560 | },
561 | "time": "2020-12-03T10:09:09+00:00"
562 | }
563 | ],
564 | "packages-dev": [],
565 | "aliases": [],
566 | "minimum-stability": "stable",
567 | "stability-flags": [],
568 | "prefer-stable": false,
569 | "prefer-lowest": false,
570 | "platform": {
571 | "php": ">=7.4",
572 | "ext-json": "*"
573 | },
574 | "platform-dev": [],
575 | "plugin-api-version": "2.6.0"
576 | }
577 |
--------------------------------------------------------------------------------
/templates/data.twig:
--------------------------------------------------------------------------------
1 | {% extends '_page.twig' %}
2 | {% block title %}libphonenumber Demo{% endblock %}
3 | {% block content %}
4 | {% set tableWidth='auto' %}
5 | « Back to form
6 |
7 | {% include 'inputData.twig' %}
8 |
9 |
10 | {{ get_class(phoneNumberObj) }} Object
11 |
12 |
13 |
14 |
15 |
16 | Function
17 | Value
18 |
19 |
20 |
21 |
22 | getCountryCode()
23 | {{ phoneNumberObj.getCountryCode }}
24 |
25 |
26 | getNationalNumber()
27 | {{ phoneNumberObj.getNationalNumber }}
28 |
29 |
30 | getExtension()
31 | {{ phoneNumberObj.getExtension }}
32 |
33 |
34 |
35 | getCountryCodeSource()
36 |
37 | {% if phoneNumberObj.getCountryCodeSource == 0 %}
38 | FROM_NUMBER_WITH_PLUS_SIGN
39 | {% elseif phoneNumberObj.getCountryCodeSource == 1 %}
40 | FROM_NUMBER_WITH_IDD
41 | {% elseif phoneNumberObj.getCountryCodeSource == 2 %}
42 | FROM_NUMBER_WITHOUT_PLUS_SIGN
43 | {% elseif phoneNumberObj.getCountryCodeSource == 3 %}
44 | FROM_DEFAULT_COUNTRY
45 | {% endif %}
46 |
47 |
48 |
49 | isItalianLeadingZero()
50 | {% include '_boolean.twig' with {'v': phoneNumberObj.isItalianLeadingZero} %}
51 |
52 |
53 | getRawInput()
54 | {{ phoneNumberObj.getRawInput }}
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 | Validation Results
65 |
66 |
67 |
68 |
69 |
70 | Function
71 | Value
72 |
73 |
74 |
75 |
76 |
77 |
79 | isPossibleNumber()
80 |
81 |
82 | {% include '_boolean.twig' with {'v': possibleNumber} %}
83 |
84 | {% if possibleNumber == false %}
85 |
86 |
88 | isPossibleNumberWithReason()
90 |
91 |
92 |
93 | {% if isPossibleNumberWithReason == 0 %}
94 | IS_POSSIBLE
95 | {% elseif isPossibleNumberWithReason == 1 %}
96 | INVALID_COUNTRY_CODE
97 | {% elseif isPossibleNumberWithReason == 2 %}
98 | TOO_SHORT
99 | {% elseif isPossibleNumberWithReason == 3 %}
100 | TOO_LONG
101 | {% endif %}
102 |
103 | {% else %}
104 |
105 |
106 |
108 | isValidNumber()
109 |
110 |
111 | {% include '_boolean.twig' with {'v': validNumber} %}
112 |
113 |
114 |
115 |
117 | isValidNumberForRegion()
119 |
120 |
121 | {% include '_boolean.twig' with {'v': validNumberForRegion} %}
122 |
123 |
124 |
125 |
126 |
128 | getRegionCodeForNumber()
130 |
131 |
132 |
133 | {% if phoneNumberRegion %}
134 |
139 | {% endif %}
140 | {{ phoneNumberRegion }}
141 |
142 |
143 |
144 |
145 |
147 | getNumberType()
148 |
149 |
150 | {% if phoneNumberType == 0 %}
151 | FIXED_LINE
152 | {% elseif phoneNumberType == 1 %}
153 | MOBILE
154 | {% elseif phoneNumberType == 2 %}
155 | FIXED_LINE_OR_MOBILE
156 | {% elseif phoneNumberType == 3 %}
157 | TOLL_FREE
158 | {% elseif phoneNumberType == 4 %}
159 | PREMIUM_RATE
160 | {% elseif phoneNumberType == 5 %}
161 | SHARED_COST
162 | {% elseif phoneNumberType == 6 %}
163 | VOIP
164 | {% elseif phoneNumberType == 7 %}
165 | PERSONAL_NUMBER
166 | {% elseif phoneNumberType == 8 %}
167 | PAGER
168 | {% elseif phoneNumberType == 9 %}
169 | UAN
170 | {% elseif phoneNumberType == 10 %}
171 | UNKNOWN
172 | {% elseif phoneNumberType == 27 %}
173 | EMERGENCY
174 | {% elseif phoneNumberType == 28 %}
175 | VOICEMAIL
176 | {% elseif phoneNumberType == 29 %}
177 | SHORT_CODE
178 | {% elseif phoneNumberType == 30 %}
179 | STANDARD_RATE
180 | {% endif %}
181 |
182 |
183 | {% endif %}
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 | Formatting
193 |
194 |
201 |
202 |
203 |
204 |
205 |
206 |
207 | Format
208 | Value
209 |
210 |
211 |
212 |
213 | E164
214 |
215 | {% if validNumber == true %}
216 | {{ phoneUtil.format(phoneNumberObj, 0) }}
217 | {% else %}
218 | Invalid Number
219 | {% endif %}
220 |
221 |
222 |
223 |
224 | National
225 |
226 | {% if validNumber == true %}
227 | {{ phoneUtil.format(phoneNumberObj, 2) }}
228 | {% else %}
229 | Invalid Number
230 | {% endif %}
231 |
232 |
233 |
234 |
235 | International
236 |
237 | {% if validNumber == true %}
238 | {{ phoneUtil.format(phoneNumberObj, 1) }}
239 | {% else %}
240 | Invalid Number
241 | {% endif %}
242 |
243 |
244 |
245 | RFC3966
246 |
247 | {% if validNumber == true %}
248 | {{ phoneUtil.format(phoneNumberObj, 3) }}
249 | {% else %}
250 | Invalid Number
251 | {% endif %}
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 | {% if validNumber == true %}
261 |
268 |
269 |
270 |
271 |
272 |
273 | Region
274 |
275 |
277 | formatOutOfCountryCallingNumber()
279 |
280 |
281 |
282 |
284 | formatNumberForMobileDialing()
286 |
287 |
288 |
289 |
290 |
293 |
294 |
295 |
296 | {% if countries[region] is defined %}
297 | {{ countries[region] }}
298 | {% else %}
299 | {{ region }}
300 | {% endif %}
301 |
302 |
303 | {{ phoneUtil.formatOutOfCountryCallingNumber(phoneNumberObj, region) }}
304 | {{ phoneUtil.formatNumberForMobileDialing(phoneNumberObj, region, true) }}
305 |
306 | {% endfor %}
307 |
308 |
309 |
310 |
311 | {% endif %}
312 |
313 |
314 |
315 |
316 | ShortNumberInfo
317 |
318 |
319 |
320 |
321 |
322 | Function
323 | Value
324 |
325 |
326 |
327 |
328 |
329 |
330 |
332 | isPossibleShortNumber()
333 |
334 |
335 | {% include '_boolean.twig' with {'v': shortNumber.isPossibleShortNumber(phoneNumberObj)} %}
336 |
337 |
338 |
339 |
340 |
342 | isValidShortNumber()
343 |
344 |
345 | {% include '_boolean.twig' with {'v': shortNumber.isValidShortNumber(phoneNumberObj)} %}
346 |
347 |
348 |
349 |
350 |
352 | isPossibleShortNumberForRegion()
353 |
354 |
355 | {% include '_boolean.twig' with {'v': shortNumber.isPossibleShortNumberForRegion(phoneNumberObj, phoneNumberRegion)} %}
356 |
357 |
358 |
359 |
360 |
362 | isValidShortNumberForRegion()
363 |
364 |
365 | {% include '_boolean.twig' with {'v': shortNumber.isValidShortNumberForRegion(phoneNumberObj, phoneNumberRegion)} %}
366 |
367 |
368 |
369 |
370 |
371 |
373 | getExpectedCost()
374 |
375 |
376 | {% set getExpectedCost = shortNumber.getExpectedCost(phoneNumberObj) %}
377 | {% if getExpectedCost == 3 %}TOLL_FREE
378 | {% elseif getExpectedCost == 4 %}PREMIUM_RATE
379 | {% elseif getExpectedCost == 30 %}STANDARD_RATE
380 | {% elseif getExpectedCost == 10 %}UNKNOWN_COST
381 | {% endif %}
382 |
383 |
384 |
385 |
386 |
387 |
388 |
390 | getExpectedCostForRegion()
391 |
392 |
393 | {% set getExpectedCostForRegion = shortNumber.getExpectedCostForRegion(phoneNumberObj, phoneNumberRegion) %}
394 | {% if getExpectedCostForRegion == 3 %}TOLL_FREE
395 | {% elseif getExpectedCostForRegion == 4 %}PREMIUM_RATE
396 | {% elseif getExpectedCostForRegion == 30 %}STANDARD_RATE
397 | {% elseif getExpectedCostForRegion == 10 %}UNKNOWN_COST
398 | {% endif %}
399 |
400 |
401 |
402 |
403 |
404 |
406 | isEmergencyNumber()
407 |
408 |
409 | {% include '_boolean.twig' with {'v': shortNumber.isEmergencyNumber(input['phonenumber'], input['country'])} %}
410 |
411 |
412 |
413 |
414 |
416 | connectsToEmergencyNumber()
417 |
418 |
419 | {% include '_boolean.twig' with {'v': shortNumber.connectsToEmergencyNumber(input['phonenumber'], input['country'])} %}
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 | Example Numbers
431 |
432 |
433 |
434 |
435 |
436 | Function
437 | Value
438 |
439 |
440 |
441 |
442 |
443 |
444 |
446 | getExampleNumber()
448 |
449 |
450 | {{ phoneUtil.getExampleNumber(input['country']) }}
451 |
452 |
453 |
454 |
455 |
457 | getExampleNumberForType
459 |
460 |
461 | {{ phoneUtil.getExampleNumberForType(input['country'], phoneNumberType) }}
462 |
463 |
464 |
465 |
466 |
468 | getExampleShortNumber
470 |
471 |
472 | {{ shortNumber.getExampleShortNumber(input['country']) }}
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 | Phone Number Offline Geocoder Result
484 |
508 |
509 |
510 |
511 |
512 | Phone Number To Carrier Mapper Result
513 |
514 |
515 |
516 |
517 |
518 | Function
519 | Value
520 |
521 |
522 |
523 |
524 |
525 |
527 | getNameForNumber()
529 |
530 |
531 | {{ carrierinfo }}
532 |
533 |
534 |
535 |
536 |
537 |
538 |
539 |
540 |
541 | Phone Number To Time Zones Mapper Result
542 |
543 |
544 |
545 |
546 |
547 | Function
548 | Value
549 |
550 |
551 |
552 |
553 |
554 |
556 | getTimeZonesForNumber()
558 |
559 |
560 |
561 |
562 | {% for tz in timezone %}
563 | {{ tz }}
564 | {% endfor %}
565 |
566 |
567 |
568 |
569 |
570 |
571 |
572 | {% endblock %}
573 |
--------------------------------------------------------------------------------