diff --git a/README.md b/README.md index a31d3c0..5d84d1e 100755 --- a/README.md +++ b/README.md @@ -130,7 +130,7 @@ Alternatively you may choose to download the zip file and unzip it in your direc ### Installation using Docker -@scyto maintains Docker containers for quick and easy deployment of the UniFi API browser tool. Please refer to [this Wiki page](https://github.com/Art-of-WiFi/UniFi-API-browser/wiki/Docker-Hosting) within the repository for more details: +@scyto maintains Docker containers for quick and easy deployment of the UniFi API browser tool. Please refer to [this Wiki page](https://github.com/Art-of-WiFi/UniFi-API-browser/wiki/Docker-Hosting) within the repository for more details. Please note we don't provide support related to Docker-based installs. ### Configuration diff --git a/ajax/fetch_collection.php b/ajax/fetch_collection.php index 09cb268..8560251 100755 --- a/ajax/fetch_collection.php +++ b/ajax/fetch_collection.php @@ -110,15 +110,12 @@ switch ($method) { case 'stat_5minutes_gateway': $params = [null, null, $gateway_stats_attribs]; - break; case 'stat_hourly_gateway': $params = [null, null, $gateway_stats_attribs]; - break; case 'stat_daily_gateway': $params = [null, null, $gateway_stats_attribs]; - break; case 'stat_monthly_gateway': $params = [null, null, $gateway_stats_attribs]; } @@ -217,4 +214,4 @@ header('Content-Type: application/json; charset=utf-8'); echo (json_encode($results)); -$_SESSION['memory_used'] = round(memory_get_peak_usage(false) / 1024 / 1024, 2) . 'MB'; \ No newline at end of file +$_SESSION['memory_used'] = round(memory_get_peak_usage(false) / 1024 / 1024, 2) . 'MB'; diff --git a/common.php b/common.php index 0246f98..07a5893 100755 --- a/common.php +++ b/common.php @@ -5,7 +5,7 @@ * * This file is subject to the MIT license that is bundled with this package in the file LICENSE.md */ -define('TOOL_VERSION', '2.0.18'); +define('TOOL_VERSION', '2.0.19'); /** * gather some basic information for the About modal diff --git a/composer.lock b/composer.lock index aa506fb..3cfdbfb 100755 --- a/composer.lock +++ b/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "art-of-wifi/unifi-api-client", - "version": "v1.1.69", + "version": "v1.1.72", "source": { "type": "git", "url": "https://github.com/Art-of-WiFi/UniFi-API-client.git", - "reference": "474578a9d5e571ae2742a173d750d88890afc5f8" + "reference": "9cca43557c7f6454eb044d5c04a676630825872a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Art-of-WiFi/UniFi-API-client/zipball/474578a9d5e571ae2742a173d750d88890afc5f8", - "reference": "474578a9d5e571ae2742a173d750d88890afc5f8", + "url": "https://api.github.com/repos/Art-of-WiFi/UniFi-API-client/zipball/9cca43557c7f6454eb044d5c04a676630825872a", + "reference": "9cca43557c7f6454eb044d5c04a676630825872a", "shasum": "" }, "require": { @@ -39,7 +39,7 @@ { "name": "Art of WiFi", "email": "info@artofowifi.net", - "homepage": "http://artofwifi.net" + "homepage": "https://artofwifi.net" } ], "description": "API client class for use with Ubiquiti's UniFi controller", @@ -54,9 +54,9 @@ ], "support": { "issues": "https://github.com/Art-of-WiFi/UniFi-API-client/issues", - "source": "https://github.com/Art-of-WiFi/UniFi-API-client/tree/v1.1.69" + "source": "https://github.com/Art-of-WiFi/UniFi-API-client/tree/v.1.1.72" }, - "time": "2021-03-21T15:08:55+00:00" + "time": "2021-10-19T08:39:17+00:00" }, { "name": "kint-php/kint", @@ -134,16 +134,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.22.1", + "version": "v1.23.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "c6c942b1ac76c82448322025e084cadc56048b4e" + "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/c6c942b1ac76c82448322025e084cadc56048b4e", - "reference": "c6c942b1ac76c82448322025e084cadc56048b4e", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/46cd95797e9df938fdd2b03693b5fca5e64b01ce", + "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce", "shasum": "" }, "require": { @@ -155,7 +155,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.22-dev" + "dev-main": "1.23-dev" }, "thanks": { "name": "symfony/polyfill", @@ -193,7 +193,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.22.1" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.23.0" }, "funding": [ { @@ -209,20 +209,20 @@ "type": "tidelift" } ], - "time": "2021-01-07T16:49:33+00:00" + "time": "2021-02-19T12:13:01+00:00" }, { "name": "twig/twig", - "version": "v1.44.2", + "version": "v1.44.5", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "138c493c5b8ee7cff3821f80b8896d371366b5fe" + "reference": "dd4353357c5a116322e92a00d16043a31881a81e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/138c493c5b8ee7cff3821f80b8896d371366b5fe", - "reference": "138c493c5b8ee7cff3821f80b8896d371366b5fe", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/dd4353357c5a116322e92a00d16043a31881a81e", + "reference": "dd4353357c5a116322e92a00d16043a31881a81e", "shasum": "" }, "require": { @@ -275,7 +275,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v1.44.2" + "source": "https://github.com/twigphp/Twig/tree/v1.44.5" }, "funding": [ { @@ -287,7 +287,7 @@ "type": "tidelift" } ], - "time": "2021-01-05T10:10:05+00:00" + "time": "2021-09-17T08:35:19+00:00" } ], "packages-dev": [], diff --git a/vendor/art-of-wifi/unifi-api-client/.gitignore b/vendor/art-of-wifi/unifi-api-client/.gitignore index ac22271..33306ea 100755 --- a/vendor/art-of-wifi/unifi-api-client/.gitignore +++ b/vendor/art-of-wifi/unifi-api-client/.gitignore @@ -10,4 +10,7 @@ .phpdoc-md # ignore XML files -*.xml \ No newline at end of file +*.xml + +# ignore PHPStorm files +.idea/* \ No newline at end of file diff --git a/vendor/art-of-wifi/unifi-api-client/README.md b/vendor/art-of-wifi/unifi-api-client/README.md index d89fe16..ff62269 100755 --- a/vendor/art-of-wifi/unifi-api-client/README.md +++ b/vendor/art-of-wifi/unifi-api-client/README.md @@ -1,40 +1,59 @@ ## UniFi Controller API client class -A PHP class that provides access to Ubiquiti's [**UniFi Network Controller**](https://unifi-network.ui.com/) API, versions 4.X.X, 5.X.X and 6.0.X of the UniFi Network Controller software are supported (version 6.0.43 has been confirmed to work) as well as UniFi OS-based controllers (version 5.12.59 has been confirmed to work). This class is used by our API browser tool which can be found [here](https://github.com/Art-of-WiFi/UniFi-API-browser). +A PHP class that provides access to Ubiquiti's [**UniFi Network Controller**](https://unifi-network.ui.com/) API. -The package can be installed manually or by using composer/[packagist](https://packagist.org/packages/art-of-wifi/unifi-api-client) for easy inclusion in your projects. +UniFi Network Controller software versions 4.X.X, 5.X.X and 6.X.X are supported +(version 6.4.54 has been confirmed to work) as well as UniFi OS-based controllers . +This class is used by our API browser tool which can be found [here](https://github.com/Art-of-WiFi/UniFi-API-browser). +The package can be installed manually or by using +composer/[packagist](https://packagist.org/packages/art-of-wifi/unifi-api-client) for +easy inclusion in your projects. ## Requirements -- a server with PHP, version 5.5.0 or higher, and the PHP cURL module installed (tested on Apache 2.4 with PHP Version 5.6.1 and cURL 7.42.1 and with PHP 7.2.24 and cURL 7.58.0) -- direct network connectivity between this server and the host and port (normally TCP port 8443) where the UniFi Controller is running -- you must use **local accounts**, not UniFi Cloud accounts, to access the UniFi Controller API through this class - +- a server with: + - PHP version 5.5.0 or higher + - PHP json and PHP cURL modules + - tested on Apache 2.4 with PHP Version 5.6.1 and cURL 7.42.1 and with PHP 7.2.24 and cURL 7.58.0 +- direct network connectivity between this server and the host and port (normally TCP +port 8443 or port 443 for + UniFi OS) where the UniFi Controller is running +- you must use **accounts with local access**, not pure UniFi Cloud accounts, +to access the UniFi Controller API through this class ## UniFi OS Support -Support for UniFi OS-based controllers (UniFi Dream Machine Pro or Cloud Key Gen2/Cloud Key Gen2 Plus with firmware version 2.0.24 or higher) has been added as of version 1.1.47. The class automatically detects UniFi OS devices and adjusts URLs and several functions/methods accordingly. If your own code applies strict validation of the URL that is passed to the constructor, please adapt your logic to allow URLs without a port suffix when dealing with a UniFi OS-based controller. - -Please test all methods you plan on using thoroughly before using the API Client with UniFi OS devices in a production environment. +Support for UniFi OS-based controllers (UniFi Dream Machine, UniFi Dream Machine Pro +or Cloud Key Gen2/Cloud Key Gen2 Plus with firmware version 2.0.24 or higher) has +been added as of version 1.1.47. The class automatically detects UniFi OS devices and +adjusts URLs and several functions/methods accordingly. If your own code implements strict +validation of the URL that is passed to the constructor, please adapt your logic to +allow URLs without a port suffix or with port 443 when dealing with a UniFi OS-based +controller. +Please test all methods you plan on using thoroughly before using the API Client with +UniFi OS devices in a production environment. ## Installation -Use [Composer](#composer), [Git](#git) or simply [Download the Release](#download-the-release) to install the API client class. - +Use [Composer](#composer), [Git](#git) or simply [Download the Release](#download-the-release) to install the +API client class. ### Composer -The preferred installation method is through [composer](https://getcomposer.org). Follow these [installation instructions](https://getcomposer.org/doc/00-intro.md) if you do not already have composer installed. +The preferred installation method is through [composer](https://getcomposer.org). +Follow these [installation instructions](https://getcomposer.org/doc/00-intro.md) if you don't have composer +installed already. -Once composer is installed, simply execute this command from the shell in your project directory: +Once composer is installed, simply execute this command from the shell in your project +directory: ```sh composer require art-of-wifi/unifi-api-client ``` - Or manually add the package to your composer.json file: +Or manually add the package to your composer.json file: ```javascript { @@ -50,7 +69,6 @@ Finally, be sure to include the autoloader in your code: require_once 'vendor/autoload.php'; ``` - ### Git Execute the following `git` command from the shell in your project directory: @@ -65,16 +83,16 @@ When git is done cloning, include the file containing the class like so in your require_once 'path/to/src/Client.php'; ``` - ### Download the Release -If you prefer not to use composer or git, simply [download the package](https://github.com/Art-of-WiFi/UniFi-API-client/archive/master.zip), uncompress the zip file, then include the file containing the class in your code like so: +If you prefer not to use composer or git, +simply [download the package](https://github.com/Art-of-WiFi/UniFi-API-client/archive/master.zip), uncompress the zip +file, then include the file containing the class in your code like so: ```php require_once 'path/to/src/Client.php'; ``` - ## Example usage A basic example how to use the class: @@ -86,31 +104,36 @@ A basic example how to use the class: require_once 'vendor/autoload.php'; /** - * initialize the Unifi API connection class, log in to the controller and request the alarms collection + * initialize the UniFi API connection class, log in to the controller and request the alarms collection * (this example assumes you have already assigned the correct values to the variables used) */ -$unifi_connection = new UniFi_API\Client($controller_user, $controller_password, $controller_url, $site_id, $controller_version, true); +$unifi_connection = new UniFi_API\Client($controller_user, $controller_password $controller_url, $site_id, $controller_version, true); $login = $unifi_connection->login(); $results = $unifi_connection->list_alarms(); // returns a PHP array containing alarm objects ``` -Please refer to the `examples/` directory for some more detailed examples which can be used as a starting point for your own PHP code. - +Please refer to the `examples/` directory for some more detailed examples which can be used as a starting point for your +own PHP code. #### IMPORTANT NOTES: -1. In the above example, `$site_id` is the short site "name" (usually 8 characters long) that is visible in the URL when managing the site in the UniFi Network Controller. For example with this URL: +1. In the above example, `$site_id` is the short site "name" (usually 8 characters long) that is visible in the URL when + managing the site in the UniFi Network Controller. For example with this URL: `https://:8443/manage/site/jl3z2shm/dashboard` `jl3z2shm` is the short site "name" and the value to assign to $site_id. -2. The last optional parameter that is passed to the constructor in the above example (`true`), enables validation of the controller's SSL certificate which is otherwise **disabled** by default. It is **highly recommended** to enable this feature in production environments where you have a valid SSL cert installed on the UniFi Controller that is associated with the FQDN in the `controller_url` parameter. This option was added with API client version 1.1.16. - +2. The 6th optional parameter that is passed to the constructor in the above example (`true`), enables validation of + the controller's SSL certificate which is otherwise **disabled** by default. It is **highly recommended** to enable + this feature in production environments where you have a valid SSL cert installed on the UniFi Controller that is + associated with the FQDN in the `controller_url` parameter. This option was added with API client version 1.1.16. ## Functions/methods supported -The class currently supports the following functions/methods to GET/POST/PUT/DELETE data through the UniFi Controller API. Please refer to the comments in the source code for more details on the functions/methods and their respective parameters. +The class currently supports the following functions/methods to GET/POST/PUT/DELETE data +through the UniFi Controller API. Please refer to the comments in the source code for +more details on the functions/methods and their respective parameters. - login() - logout() @@ -120,10 +143,10 @@ The class currently supports the following functions/methods to GET/POST/PUT/DEL - authorize_guest() - block_sta() - cancel_rolling_upgrade() -- cmd_stat() -- count_alarms() - check_controller_update() - check_firmware_update() +- cmd_stat() +- count_alarms() - create_apgroup() (supported with controller versions 6.0.X and higher) - create_dynamicdns() - create_firewallgroup() @@ -163,8 +186,8 @@ The class currently supports the following functions/methods to GET/POST/PUT/DEL - list_country_codes() - list_current_channels() - list_dashboard() -- list_devices() - list_device_name_mappings() +- list_devices() - list_dpi_stats() - list_dynamicdns() - list_events() @@ -245,24 +268,24 @@ The class currently supports the following functions/methods to GET/POST/PUT/DEL - stat_daily_gateway() (supported on controller version 5.7.X and higher) - stat_daily_site() - stat_daily_user() (supported on controller version 5.7.X and higher) +- stat_full_status() - stat_hourly_aps() - stat_hourly_gateway() (supported on controller version 5.7.X and higher) - stat_hourly_site() - stat_hourly_user() (supported on controller version 5.7.X and higher) - stat_ips_events() (supported on controller version 5.9.10 and higher) +- stat_monthly_aps() +- stat_monthly_gateway() +- stat_monthly_site() +- stat_monthly_user() - stat_payment() - stat_sessions() - stat_sites() - stat_speedtest_results() - stat_sta_sessions_latest() - stat_status() -- stat_full_status() - stat_sysinfo() - stat_voucher() -- stat_monthly_aps() -- stat_monthly_gateway() -- stat_monthly_site() -- stat_monthly_user() - unauthorize_guest() - unblock_sta() - unset_locate_ap() (deprecated but still available as alias) @@ -272,49 +295,57 @@ The class currently supports the following functions/methods to GET/POST/PUT/DEL Other functions, getters/setters: - get_class_version() -- get_connection_timeout() - get_cookie() (renamed from getcookie(), deprecated but still available, use get_cookies() instead) - get_cookies() +- get_curl_connection_timeout() +- get_curl_http_version() +- get_curl_method() +- get_curl_request_timeout() +- get_curl_request_timeout() +- get_curl_ssl_verify_host() +- get_curl_ssl_verify_peer() - get_debug() - get_is_unifi_os() - get_last_error_message() - get_last_results_raw() -- get_request_method() - get_site() -- get_ssl_verify_host() -- get_ssl_verify_peer() - set_connection_timeout() - set_cookies() +- set_curl_http_version() +- set_curl_request_timeout() +- set_curl_ssl_verify_host() +- set_curl_ssl_verify_peer() - set_debug() - set_is_unifi_os() - set_request_method() +- set_request_timeout() - set_site() -- set_ssl_verify_host() -- set_ssl_verify_peer() - ## Need help or have suggestions? -There is still work to be done to add functionality and further improve the usability of this class, so all suggestions/comments are welcome. Please use the GitHub [issue list](https://github.com/Art-of-WiFi/UniFi-API-client/issues) or the Ubiquiti Community forums (https://community.ubnt.com/t5/UniFi-Wireless/PHP-class-to-access-the-UniFi-controller-API-updates-and/td-p/1512870) to share your suggestions and questions. - +There is still work to be done to add functionality and further improve the usability of +this class, so all suggestions/comments are welcome. Please use the GitHub +[issue list](https://github.com/Art-of-WiFi/UniFi-API-client/issues) or the Ubiquiti +Community forums (https://community.ubnt.com/t5/UniFi-Wireless/PHP-class-to-access-the-UniFi-controller-API-updates-and/td-p/1512870) +to share your suggestions and questions. ## Contribute -If you would like to contribute code (improvements), please open an issue and include your code there or else create a pull request. - +If you would like to contribute code (improvements), please open an issue and include +your code there or else create a pull request. ## Credits This class is based on the initial work by the following developers: -- domwo: http://community.ubnt.com/t5/UniFi-Wireless/little-php-class-for-unifi-api/m-p/603051 +- domwo: https://community.ui.com/questions/little-php-class-for-unifi-api/933d3fb3-b401-4499-993a-f9af079a4a3a - fbagnol: https://github.com/fbagnol/class.unifi.php and the API as published by Ubiquiti: -- https://dl.ui.com/unifi/6.0.41/unifi_sh_api - +- https://dl.ui.com/unifi/6.2.26/unifi_sh_api ## Important Disclaimer -Many of the functions in this API client class are not officially supported by UBNT and as such, may not be supported in future versions of the UniFi Controller API. +Many of the functions in this API client class are not officially supported by Ubiquiti +and as such, may not be supported in future versions of the UniFi Controller API. diff --git a/vendor/art-of-wifi/unifi-api-client/composer.json b/vendor/art-of-wifi/unifi-api-client/composer.json index 9232c7e..3b55f7a 100755 --- a/vendor/art-of-wifi/unifi-api-client/composer.json +++ b/vendor/art-of-wifi/unifi-api-client/composer.json @@ -1,6 +1,6 @@ { - "name": "art-of-wifi/unifi-api-client", - "type": "library", + "name": "art-of-wifi/unifi-api-client", + "type": "library", "description": "API client class for use with Ubiquiti's UniFi controller", "keywords": [ "ubnt", @@ -10,13 +10,13 @@ "api", "client" ], - "homepage": "https://github.com/Art-of-WiFi/UniFi-API-client", - "license": "MIT", + "homepage": "https://github.com/Art-of-WiFi/UniFi-API-client", + "license": "MIT", "authors": [ { - "name": "Art of WiFi", - "email": "info@artofowifi.net", - "homepage": "http://artofwifi.net" + "name": "Art of WiFi", + "email": "info@artofowifi.net", + "homepage": "https://artofwifi.net" } ], "require": { @@ -29,4 +29,4 @@ "UniFi_API\\": "src/" } } -} \ No newline at end of file +} diff --git a/vendor/art-of-wifi/unifi-api-client/examples/README.md b/vendor/art-of-wifi/unifi-api-client/examples/README.md index a79468b..90c696c 100755 --- a/vendor/art-of-wifi/unifi-api-client/examples/README.md +++ b/vendor/art-of-wifi/unifi-api-client/examples/README.md @@ -1,18 +1,21 @@ ## API client class usage examples -This directory contains some PHP code examples which demonstrate usage of the PHP API client class and can be used as a good starting point for your own custom code. +This directory contains some PHP code examples which demonstrate usage of the PHP API client class and can be used as a +good starting point for your own custom code. ### Usage -Copy the appropriate example file to your working directory together with a copy of the config.template.php file which should be renamed to config.php. -Then update the contents of your new config.php with your controller details and credentials and modify the example file as required to fit your needs. +Copy the appropriate example file to your working directory together with a copy of the config.template.php file which +should be renamed to config.php. Then update the contents of your new config.php with your controller details and +credentials and modify the example file as required to fit your needs. -Also make sure to update the path for the composer autoloader file (`vendor/autoload.php`) or the file containing the Class itself (`src/Client.php`) in your `require_once()` statement as required. +Also make sure to update the path for the composer autoloader file (`vendor/autoload.php`) or the file containing the +Class itself (`src/Client.php`) in your `require_once()` statement as required. #### Executing scripts from the CLI -Most of the included example scripts can be run from the CLI or shell as follows after the necessary credentials and parameters have been added or updated: - +Most of the included example scripts can be run from the CLI or shell as follows after the necessary credentials and +parameters have been added or updated: ```sh $ php list_site_health.php @@ -22,7 +25,8 @@ NOTE: this does require the `php-cli` module to be installed ### Contribute -If you would like to share your own example file(s), please open an issue and include your code there or else create a pull request. +If you would like to share your own example file(s), please open an issue and include your code there or else create a +pull request. ## Important Disclaimer diff --git a/vendor/art-of-wifi/unifi-api-client/examples/test_connection.php b/vendor/art-of-wifi/unifi-api-client/examples/test_connection.php index 8de4653..bd3d379 100755 --- a/vendor/art-of-wifi/unifi-api-client/examples/test_connection.php +++ b/vendor/art-of-wifi/unifi-api-client/examples/test_connection.php @@ -15,8 +15,9 @@ /** * Check whether the cURL module supports SSL + * http://www.php.net/manual/en/function.curl-version.php */ -if (!curl_version()['features'] & CURL_VERSION_SSL) { +if (!(curl_version()['features'] & CURL_VERSION_SSL)) { print PHP_EOL . 'SSL is not supported with this cURL installation!' . PHP_EOL; } @@ -25,9 +26,9 @@ */ $ch = curl_init(); -if (is_resource($ch)) { +if (is_resource($ch) || is_object($ch)) { /** - * If we have a resource, we proceed and set the required cURL options + * If we have a resource or object (for PHP > 8.0), we proceed and set the required cURL options */ curl_setopt($ch, CURLOPT_URL, $controllerurl); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); @@ -64,9 +65,13 @@ print PHP_EOL . 'cURL error: ' . curl_error($ch) . PHP_EOL; } - print PHP_EOL . '$results:' . PHP_EOL; - print_r($results); - print PHP_EOL; + print PHP_EOL . 'test result:' . PHP_EOL; + if ($results) { + print 'Controller connection success' . PHP_EOL; + die; + } + + print 'Controller connection failed' . PHP_EOL; } else { print PHP_EOL . 'ERROR: cURL could not be initialized!' . PHP_EOL; } diff --git a/vendor/art-of-wifi/unifi-api-client/src/Client.php b/vendor/art-of-wifi/unifi-api-client/src/Client.php index 448cd50..32f3df0 100755 --- a/vendor/art-of-wifi/unifi-api-client/src/Client.php +++ b/vendor/art-of-wifi/unifi-api-client/src/Client.php @@ -1,18 +1,19 @@ /unifi_sh_api + * https://dl.ui.com/unifi//unifi_sh_api * * @package UniFi_Controller_API_Client_Class * @author Art of WiFi - * @version Release: 1.1.69 + * @version Release: 1.1.71 * @license This class is subject to the MIT license that is bundled with this package in the file LICENSE.md * @example This directory in the package repository contains a collection of examples: * https://github.com/Art-of-WiFi/UniFi-API-client/tree/master/examples @@ -21,40 +22,45 @@ class Client { /** * private and protected properties - */ - private $class_version = '1.1.69'; - protected $baseurl = 'https://127.0.0.1:8443'; - protected $user = ''; - protected $password = ''; - protected $site = 'default'; - protected $version = '6.0.43'; - protected $debug = false; - protected $curl_ssl_verify_peer = false; - protected $curl_ssl_verify_host = false; - protected $is_loggedin = false; - protected $is_unifi_os = false; - protected $exec_retries = 0; - protected $cookies = ''; - protected $headers = []; - protected $request_method = 'GET'; - protected $request_methods_allowed = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH']; - protected $connect_timeout = 10; - protected $last_results_raw = null; - protected $last_error_message = null; + * + * NOTE: + * do not modify the values here, instead user the constructor or the getter and setter functions/methods + */ + const CLASS_VERSION = '1.1.72'; + protected $baseurl = 'https://127.0.0.1:8443'; + protected $user = ''; + protected $password = ''; + protected $site = 'default'; + protected $version = '6.2.26'; + protected $debug = false; + protected $is_loggedin = false; + protected $is_unifi_os = false; + protected $exec_retries = 0; + protected $cookies = ''; + protected $last_results_raw = null; + protected $last_error_message = null; + protected $curl_ssl_verify_peer = false; + protected $curl_ssl_verify_host = false; + protected $curl_http_version = CURL_HTTP_VERSION_1_1; + protected $curl_headers = []; + protected $curl_method = 'GET'; + protected $curl_methods_allowed = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH']; + protected $curl_request_timeout = 30; + protected $curl_connect_timeout = 10; /** * Construct an instance of the UniFi API client class * - * @param string $user user name to use when connecting to the UniFi controller - * @param string $password password to use when connecting to the UniFi controller - * @param string $baseurl optional, base URL of the UniFi controller which *must* include an 'https://' prefix, - * a port suffix (e.g. :8443) is required for non-UniFi OS controllers, - * do not add trailing slashes, default value is 'https://127.0.0.1:8443' - * @param string $site optional, short site name to access, defaults to 'default' - * @param string $version optional, the version number of the controller - * @param bool $ssl_verify optional, whether to validate the controller's SSL certificate or not, a value of true is - * recommended for production environments to prevent potential MitM attacks, default value (false) - * disables validation of the controller certificate + * @param string $user username to use when connecting to the UniFi controller + * @param string $password password to use when connecting to the UniFi controller + * @param string $baseurl optional, base URL of the UniFi controller which *must* include an 'https://' prefix, + * a port suffix (e.g. :8443) is required for non-UniFi OS controllers, + * do not add trailing slashes, default value is 'https://127.0.0.1:8443' + * @param string $site optional, short site name to access, defaults to 'default' + * @param string $version optional, the version number of the controller + * @param bool $ssl_verify optional, whether to validate the controller's SSL certificate or not, a value of true + * is recommended for production environments to prevent potential MitM attacks, default + * value (false) disables validation of the controller certificate */ public function __construct($user, $password, $baseurl = '', $site = '', $version = '', $ssl_verify = false) { @@ -79,7 +85,7 @@ public function __construct($user, $password, $baseurl = '', $site = '', $versio $this->version = trim($version); } - if ((boolean) $ssl_verify === true) { + if ((boolean)$ssl_verify === true) { $this->curl_ssl_verify_peer = true; $this->curl_ssl_verify_host = 2; } @@ -111,7 +117,7 @@ public function __destruct() /** * Login to the UniFi controller * - * @return bool returns true upon success + * @return bool|int returns true upon success, false or HTTP status upon error */ public function login() { @@ -124,15 +130,13 @@ public function login() if ($this->update_unificookie()) { $this->is_loggedin = true; - return true; } /** - * check whether this is a "regular" controller or one based on UniFi OS, - * prepare cURL and options + * prepare cURL and options to check whether this is a "regular" controller or one based on UniFi OS */ - if (!($ch = $this->get_curl_resource())) { + if (!($ch = $this->get_curl_handle())) { return false; } @@ -163,7 +167,7 @@ public function login() CURLOPT_POSTFIELDS => json_encode(['username' => $this->user, 'password' => $this->password]), CURLOPT_HTTPHEADER => [ 'content-type: application/json', - 'Expect:' + 'Expect:', ], CURLOPT_REFERER => $this->baseurl . '/login', CURLOPT_URL => $this->baseurl . '/api/login', @@ -211,9 +215,10 @@ public function login() curl_close($ch); /** - * extract the cookies + * check the HTTP response code */ if ($http_code >= 200 && $http_code < 400) { + $this->is_loggedin = true; return $this->is_loggedin; } @@ -230,32 +235,32 @@ public function logout() /** * prepare cURL and options */ - if (!($ch = $this->get_curl_resource())) { + if (!($ch = $this->get_curl_handle())) { return false; } $curl_options = [ CURLOPT_HEADER => true, - CURLOPT_POST => true + CURLOPT_POST => true, ]; /** - * constuct HTTP request headers as required + * construct the HTTP request headers as required */ - $this->headers = [ + $this->curl_headers = [ 'content-length: 0', - 'Expect:' + 'Expect:', ]; - $logout_path = '/logout'; + $logout_path = '/logout'; if ($this->is_unifi_os) { - $logout_path = '/api/auth/logout'; + $logout_path = '/api/auth/logout'; $curl_options[CURLOPT_CUSTOMREQUEST] = 'POST'; $this->create_x_csrf_token_header(); } - $curl_options[CURLOPT_HTTPHEADER] = $this->headers; + $curl_options[CURLOPT_HTTPHEADER] = $this->curl_headers; $curl_options[CURLOPT_URL] = $this->baseurl . $logout_path; curl_setopt_array($ch, $curl_options); @@ -267,13 +272,13 @@ public function logout() if (curl_errno($ch)) { trigger_error('cURL error: ' . curl_error($ch)); + return false; } curl_close($ch); $this->is_loggedin = false; $this->cookies = ''; - return true; } @@ -284,13 +289,14 @@ public function logout() /** * Authorize a client device * - * @param string $mac client MAC address - * @param int $minutes minutes (from now) until authorization expires - * @param int $up optional, upload speed limit in kbps - * @param int $down optional, download speed limit in kbps - * @param int $megabytes optional, data transfer limit in MB - * @param int $ap_mac optional, AP MAC address to which client is connected, should result in faster authorization - * @return bool returns true upon success + * @param string $mac client MAC address + * @param int $minutes minutes (from now) until authorization expires + * @param int $up optional, upload speed limit in kbps + * @param int $down optional, download speed limit in kbps + * @param int $megabytes optional, data transfer limit in MB + * @param int $ap_mac optional, AP MAC address to which client is connected, should result in faster + * authorization + * @return bool returns true upon success */ public function authorize_guest($mac, $minutes, $up = null, $down = null, $megabytes = null, $ap_mac = null) { @@ -321,52 +327,48 @@ public function authorize_guest($mac, $minutes, $up = null, $down = null, $megab /** * Unauthorize a client device * - * @param string $mac client MAC address - * @return bool returns true upon success + * @param string $mac client MAC address + * @return bool returns true upon success */ public function unauthorize_guest($mac) { $payload = ['cmd' => 'unauthorize-guest', 'mac' => strtolower($mac)]; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/stamgr', $payload); } /** * Reconnect a client device * - * @param string $mac client MAC address - * @return bool returns true upon success + * @param string $mac client MAC address + * @return bool returns true upon success */ public function reconnect_sta($mac) { $payload = ['cmd' => 'kick-sta', 'mac' => strtolower($mac)]; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/stamgr', $payload); } /** * Block a client device * - * @param string $mac client MAC address - * @return bool returns true upon success + * @param string $mac client MAC address + * @return bool returns true upon success */ public function block_sta($mac) { $payload = ['cmd' => 'block-sta', 'mac' => strtolower($mac)]; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/stamgr', $payload); } /** * Unblock a client device * - * @param string $mac client MAC address - * @return bool returns true upon success + * @param string $mac client MAC address + * @return bool returns true upon success */ public function unblock_sta($mac) { $payload = ['cmd' => 'unblock-sta', 'mac' => strtolower($mac)]; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/stamgr', $payload); } @@ -377,27 +379,27 @@ public function unblock_sta($mac) * only supported with controller versions 5.9.X and higher, can be * slow (up to 5 minutes) on larger controllers * - * @param array $macs array of client MAC addresses (strings) - * @return bool returns true upon success + * @param array $macs array of client MAC addresses (strings) + * @return bool returns true upon success */ public function forget_sta($macs) { $payload = ['cmd' => 'forget-sta', 'macs' => array_map('strtolower', $macs)]; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/stamgr', $payload); } /** * Create a new user/client-device * - * @param string $mac client MAC address - * @param string $user_group_id _id value for the user group the new user/client-device should belong to which - * can be obtained from the output of list_usergroups() - * @param string $name optional, name to be given to the new user/client-device - * @param string $note optional, note to be applied to the new user/client-device - * @param bool $is_guest optional, defines whether the new user/client-device is a guest or not - * @param bool $is_wired optional, defines whether the new user/client-device is wired or not - * @return array|bool returns an array with a single object containing details of the new user/client-device on success, else returns false + * @param string $mac client MAC address + * @param string $user_group_id _id value for the user group the new user/client-device should belong to which + * can be obtained from the output of list_usergroups() + * @param string $name optional, name to be given to the new user/client-device + * @param string $note optional, note to be applied to the new user/client-device + * @param bool $is_guest optional, defines whether the new user/client-device is a guest or not + * @param bool $is_wired optional, defines whether the new user/client-device is wired or not + * @return array|bool returns an array with a single object containing details of the new user/client-device on + * success, else returns false */ public function create_user($mac, $user_group_id, $name = null, $note = null, $is_guest = null, $is_wired = null) { @@ -407,7 +409,7 @@ public function create_user($mac, $user_group_id, $name = null, $note = null, $i } if (!empty($note)) { - $new_user['note'] = $note; + $new_user['note'] = $note; } if (!empty($is_guest) && is_bool($is_guest)) { @@ -426,31 +428,28 @@ public function create_user($mac, $user_group_id, $name = null, $note = null, $i /** * Add/modify/remove a client-device note * - * @param string $user_id id of the client-device to be modified - * @param string $note optional, note to be applied to the client-device, when empty or not set, - * the existing note for the client-device is removed and "noted" attribute set to false - * @return bool returns true upon success + * @param string $user_id id of the client-device to be modified + * @param string $note optional, note to be applied to the client-device, when empty or not set, + * the existing note for the client-device is removed and "noted" attribute set to false + * @return bool returns true upon success */ public function set_sta_note($user_id, $note = null) { - //$noted = empty($note) ? false : true; $payload = ['note' => $note]; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/upd/user/' . trim($user_id), $payload); } /** * Add/modify/remove a client device name * - * @param string $user_id id of the client-device to be modified - * @param string $name optional, name to be applied to the client device, when empty or not set, - * the existing name for the client device is removed - * @return bool returns true upon success + * @param string $user_id id of the client-device to be modified + * @param string $name optional, name to be applied to the client device, when empty or not set, + * the existing name for the client device is removed + * @return bool returns true upon success */ public function set_sta_name($user_id, $name = null) { $payload = ['name' => $name]; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/upd/user/' . trim($user_id), $payload); } @@ -463,9 +462,9 @@ public function set_sta_name($user_id, $name = null) * - make sure that the retention policy for 5 minutes stats is set to the correct value in * the controller settings * - * @param int $start optional, Unix timestamp in milliseconds - * @param int $end optional, Unix timestamp in milliseconds - * @return array returns an array of 5-minute stats objects for the current site + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @return array returns an array of 5-minute stats objects for the current site */ public function stat_5minutes_site($start = null, $end = null) { @@ -479,10 +478,9 @@ public function stat_5minutes_site($start = null, $end = null) 'num_sta', 'lan-num_sta', 'wlan-num_sta', - 'time' + 'time', ]; $payload = ['attrs' => $attribs, 'start' => $start, 'end' => $end]; - return $this->fetch_results('/api/s/' . $this->site . '/stat/report/5minutes.site', $payload); } @@ -493,9 +491,9 @@ public function stat_5minutes_site($start = null, $end = null) * - defaults to the past 7*24 hours * - "bytes" are no longer returned with controller version 4.9.1 and later * - * @param int $start optional, Unix timestamp in milliseconds - * @param int $end optional, Unix timestamp in milliseconds - * @return array returns an array of hourly stats objects for the current site + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @return array returns an array of hourly stats objects for the current site */ public function stat_hourly_site($start = null, $end = null) { @@ -509,10 +507,9 @@ public function stat_hourly_site($start = null, $end = null) 'num_sta', 'lan-num_sta', 'wlan-num_sta', - 'time' + 'time', ]; $payload = ['attrs' => $attribs, 'start' => $start, 'end' => $end]; - return $this->fetch_results('/api/s/' . $this->site . '/stat/report/hourly.site', $payload); } @@ -523,9 +520,9 @@ public function stat_hourly_site($start = null, $end = null) * - defaults to the past 52*7*24 hours * - "bytes" are no longer returned with controller version 4.9.1 and later * - * @param int $start optional, Unix timestamp in milliseconds - * @param int $end optional, Unix timestamp in milliseconds - * @return array returns an array of daily stats objects for the current site + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @return array returns an array of daily stats objects for the current site */ public function stat_daily_site($start = null, $end = null) { @@ -539,10 +536,9 @@ public function stat_daily_site($start = null, $end = null) 'num_sta', 'lan-num_sta', 'wlan-num_sta', - 'time' + 'time', ]; $payload = ['attrs' => $attribs, 'start' => $start, 'end' => $end]; - return $this->fetch_results('/api/s/' . $this->site . '/stat/report/daily.site', $payload); } @@ -553,9 +549,9 @@ public function stat_daily_site($start = null, $end = null) * - defaults to the past 52 weeks (52*7*24 hours) * - "bytes" are no longer returned with controller version 4.9.1 and later * - * @param int $start optional, Unix timestamp in milliseconds - * @param int $end optional, Unix timestamp in milliseconds - * @return array returns an array of monthly stats objects for the current site + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @return array returns an array of monthly stats objects for the current site */ public function stat_monthly_site($start = null, $end = null) { @@ -569,10 +565,9 @@ public function stat_monthly_site($start = null, $end = null) 'num_sta', 'lan-num_sta', 'wlan-num_sta', - 'time' + 'time', ]; $payload = ['attrs' => $attribs, 'start' => $start, 'end' => $end]; - return $this->fetch_results('/api/s/' . $this->site . '/stat/report/monthly.site', $payload); } @@ -585,11 +580,11 @@ public function stat_monthly_site($start = null, $end = null) * - make sure that the retention policy for 5 minutes stats is set to the correct value in * the controller settings * - * @param int $start optional, Unix timestamp in milliseconds - * @param int $end optional, Unix timestamp in milliseconds - * @param string $mac optional, AP MAC address to return stats for, when empty, - * stats for all APs are returned - * @return array returns an array of 5-minute stats objects + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @param string $mac optional, AP MAC address to return stats for, when empty, + * stats for all APs are returned + * @return array returns an array of 5-minute stats objects */ public function stat_5minutes_aps($start = null, $end = null, $mac = null) { @@ -612,11 +607,11 @@ public function stat_5minutes_aps($start = null, $end = null, $mac = null) * - make sure that the retention policy for hourly stats is set to the correct value in * the controller settings * - * @param int $start optional, Unix timestamp in milliseconds - * @param int $end optional, Unix timestamp in milliseconds - * @param string $mac optional, AP MAC address to return stats for, when empty, + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @param string $mac optional, AP MAC address to return stats for, when empty, * stats for all APs are returned - * @return array returns an array of hourly stats objects + * @return array returns an array of hourly stats objects */ public function stat_hourly_aps($start = null, $end = null, $mac = null) { @@ -639,11 +634,11 @@ public function stat_hourly_aps($start = null, $end = null, $mac = null) * - make sure that the retention policy for hourly stats is set to the correct value in * the controller settings * - * @param int $start optional, Unix timestamp in milliseconds - * @param int $end optional, Unix timestamp in milliseconds - * @param string $mac optional, AP MAC address to return stats for, when empty, - * stats for all APs are returned - * @return array returns an array of daily stats objects + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @param string $mac optional, AP MAC address to return stats for, when empty, + * stats for all APs are returned + * @return array returns an array of daily stats objects */ public function stat_daily_aps($start = null, $end = null, $mac = null) { @@ -666,11 +661,11 @@ public function stat_daily_aps($start = null, $end = null, $mac = null) * - make sure that the retention policy for hourly stats is set to the correct value in * the controller settings * - * @param int $start optional, Unix timestamp in milliseconds - * @param int $end optional, Unix timestamp in milliseconds - * @param string $mac optional, AP MAC address to return stats for, when empty, - * stats for all APs are returned - * @return array returns an array of monthly stats objects + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @param string $mac optional, AP MAC address to return stats for, when empty, + * stats for all APs are returned + * @return array returns an array of monthly stats objects */ public function stat_monthly_aps($start = null, $end = null, $mac = null) { @@ -693,15 +688,16 @@ public function stat_monthly_aps($start = null, $end = null, $mac = null) * - only supported with UniFi controller versions 5.8.X and higher * - make sure that the retention policy for 5 minutes stats is set to the correct value in * the controller settings - * - make sure that "Clients Historical Data" has been enabled in the UniFi controller settings in the Maintenance section + * - make sure that "Clients Historical Data" has been enabled in the UniFi controller settings in the Maintenance + * section * - * @param string $mac MAC address of user/client device to return stats for - * @param int $start optional, Unix timestamp in milliseconds - * @param int $end optional, Unix timestamp in milliseconds - * @param array $attribs array containing attributes (strings) to be returned, valid values are: - * rx_bytes, tx_bytes, signal, rx_rate, tx_rate, rx_retries, tx_retries, rx_packets, tx_packets - * default is ['rx_bytes', 'tx_bytes'] - * @return array returns an array of 5-minute stats objects + * @param string $mac MAC address of user/client device to return stats for + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @param array $attribs array containing attributes (strings) to be returned, valid values are: + * rx_bytes, tx_bytes, signal, rx_rate, tx_rate, rx_retries, tx_retries, rx_packets, + * tx_packets default is ['rx_bytes', 'tx_bytes'] + * @return array returns an array of 5-minute stats objects */ public function stat_5minutes_user($mac, $start = null, $end = null, $attribs = null) { @@ -709,7 +705,6 @@ public function stat_5minutes_user($mac, $start = null, $end = null, $attribs = $start = empty($start) ? $end - (12 * 3600 * 1000) : intval($start); $attribs = empty($attribs) ? ['time', 'rx_bytes', 'tx_bytes'] : array_merge(['time'], $attribs); $payload = ['attrs' => $attribs, 'start' => $start, 'end' => $end, 'mac' => strtolower($mac)]; - return $this->fetch_results('/api/s/' . $this->site . '/stat/report/5minutes.user', $payload); } @@ -721,23 +716,23 @@ public function stat_5minutes_user($mac, $start = null, $end = null, $attribs = * - only supported with UniFi controller versions 5.8.X and higher * - make sure that the retention policy for hourly stats is set to the correct value in * the controller settings - * - make sure that "Clients Historical Data" has been enabled in the UniFi controller settings in the Maintenance section + * - make sure that "Clients Historical Data" has been enabled in the UniFi controller settings in the Maintenance + * section * - * @param string $mac MAC address of user/client device to return stats fo - * @param int $start optional, Unix timestamp in milliseconds - * @param int $end optional, Unix timestamp in milliseconds - * @param array $attribs array containing attributes (strings) to be returned, valid values are: - * rx_bytes, tx_bytes, signal, rx_rate, tx_rate, rx_retries, tx_retries, rx_packets, tx_packets - * default is ['rx_bytes', 'tx_bytes'] - * @return array returns an array of hourly stats objects + * @param string $mac MAC address of user/client device to return stats fo + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @param array $attribs array containing attributes (strings) to be returned, valid values are: + * rx_bytes, tx_bytes, signal, rx_rate, tx_rate, rx_retries, tx_retries, rx_packets, + * tx_packets default is ['rx_bytes', 'tx_bytes'] + * @return array returns an array of hourly stats objects */ - public function stat_hourly_user($mac, $start = null, $end = null, $attribs = null) + public function stat_hourly_user($mac, $start = null, $end = null, array $attribs = null) { $end = empty($end) ? time() * 1000 : intval($end); $start = empty($start) ? $end - (7 * 24 * 3600 * 1000) : intval($start); $attribs = empty($attribs) ? ['time', 'rx_bytes', 'tx_bytes'] : array_merge(['time'], $attribs); $payload = ['attrs' => $attribs, 'start' => $start, 'end' => $end, 'mac' => strtolower($mac)]; - return $this->fetch_results('/api/s/' . $this->site . '/stat/report/hourly.user', $payload); } @@ -749,15 +744,16 @@ public function stat_hourly_user($mac, $start = null, $end = null, $attribs = nu * - only supported with UniFi controller versions 5.8.X and higher * - make sure that the retention policy for daily stats is set to the correct value in * the controller settings - * - make sure that "Clients Historical Data" has been enabled in the UniFi controller settings in the Maintenance section + * - make sure that "Clients Historical Data" has been enabled in the UniFi controller settings in the Maintenance + * section * - * @param string $mac MAC address of user/client device to return stats for - * @param int $start optional, Unix timestamp in milliseconds - * @param int $end optional, Unix timestamp in milliseconds - * @param array $attribs array containing attributes (strings) to be returned, valid values are: - * rx_bytes, tx_bytes, signal, rx_rate, tx_rate, rx_retries, tx_retries, rx_packets, tx_packets - * default is ['rx_bytes', 'tx_bytes'] - * @return array returns an array of daily stats objects + * @param string $mac MAC address of user/client device to return stats for + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @param array $attribs array containing attributes (strings) to be returned, valid values are: + * rx_bytes, tx_bytes, signal, rx_rate, tx_rate, rx_retries, tx_retries, rx_packets, + * tx_packets default is ['rx_bytes', 'tx_bytes'] + * @return array returns an array of daily stats objects */ public function stat_daily_user($mac, $start = null, $end = null, $attribs = null) { @@ -765,7 +761,6 @@ public function stat_daily_user($mac, $start = null, $end = null, $attribs = nul $start = empty($start) ? $end - (7 * 24 * 3600 * 1000) : intval($start); $attribs = empty($attribs) ? ['time', 'rx_bytes', 'tx_bytes'] : array_merge(['time'], $attribs); $payload = ['attrs' => $attribs, 'start' => $start, 'end' => $end, 'mac' => strtolower($mac)]; - return $this->fetch_results('/api/s/' . $this->site . '/stat/report/daily.user', $payload); } @@ -777,15 +772,16 @@ public function stat_daily_user($mac, $start = null, $end = null, $attribs = nul * - only supported with UniFi controller versions 5.8.X and higher * - make sure that the retention policy for monthly stats is set to the correct value in * the controller settings - * - make sure that "Clients Historical Data" has been enabled in the UniFi controller settings in the Maintenance section + * - make sure that "Clients Historical Data" has been enabled in the UniFi controller settings in the Maintenance + * section * - * @param string $mac MAC address of user/client device to return stats for - * @param int $start optional, Unix timestamp in milliseconds - * @param int $end optional, Unix timestamp in milliseconds - * @param array $attribs array containing attributes (strings) to be returned, valid values are: - * rx_bytes, tx_bytes, signal, rx_rate, tx_rate, rx_retries, tx_retries, rx_packets, tx_packets - * default is ['rx_bytes', 'tx_bytes'] - * @return array returns an array of monthly stats objects + * @param string $mac MAC address of user/client device to return stats for + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @param array $attribs array containing attributes (strings) to be returned, valid values are: + * rx_bytes, tx_bytes, signal, rx_rate, tx_rate, rx_retries, tx_retries, rx_packets, + * tx_packets default is ['rx_bytes', 'tx_bytes'] + * @return array returns an array of monthly stats objects */ public function stat_monthly_user($mac, $start = null, $end = null, $attribs = null) { @@ -793,7 +789,6 @@ public function stat_monthly_user($mac, $start = null, $end = null, $attribs = n $start = empty($start) ? $end - (13 * 7 * 24 * 3600 * 1000) : intval($start); $attribs = empty($attribs) ? ['time', 'rx_bytes', 'tx_bytes'] : array_merge(['time'], $attribs); $payload = ['attrs' => $attribs, 'start' => $start, 'end' => $end, 'mac' => strtolower($mac)]; - return $this->fetch_results('/api/s/' . $this->site . '/stat/report/monthly.user', $payload); } @@ -807,13 +802,13 @@ public function stat_monthly_user($mac, $start = null, $end = null, $attribs = n * the controller settings * - requires a USG * - * @param int $start optional, Unix timestamp in milliseconds - * @param int $end optional, Unix timestamp in milliseconds - * @param array $attribs array containing attributes (strings) to be returned, valid values are: - * mem, cpu, loadavg_5, lan-rx_errors, lan-tx_errors, lan-rx_bytes, - * lan-tx_bytes, lan-rx_packets, lan-tx_packets, lan-rx_dropped, lan-tx_dropped - * default is ['time', 'mem', 'cpu', 'loadavg_5'] - * @return array returns an array of 5-minute stats objects for the gateway belonging to the current site + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @param array $attribs array containing attributes (strings) to be returned, valid values are: + * mem, cpu, loadavg_5, lan-rx_errors, lan-tx_errors, lan-rx_bytes, + * lan-tx_bytes, lan-rx_packets, lan-tx_packets, lan-rx_dropped, lan-tx_dropped + * default is ['time', 'mem', 'cpu', 'loadavg_5'] + * @return array returns an array of 5-minute stats objects for the gateway belonging to the current site */ public function stat_5minutes_gateway($start = null, $end = null, $attribs = null) { @@ -821,7 +816,6 @@ public function stat_5minutes_gateway($start = null, $end = null, $attribs = nul $start = empty($start) ? $end - (12 * 3600 * 1000) : intval($start); $attribs = empty($attribs) ? ['time', 'mem', 'cpu', 'loadavg_5'] : array_merge(['time'], $attribs); $payload = ['attrs' => $attribs, 'start' => $start, 'end' => $end]; - return $this->fetch_results('/api/s/' . $this->site . '/stat/report/5minutes.gw', $payload); } @@ -832,13 +826,13 @@ public function stat_5minutes_gateway($start = null, $end = null, $attribs = nul * - defaults to the past 7*24 hours * - requires a USG * - * @param int $start optional, Unix timestamp in milliseconds - * @param int $end optional, Unix timestamp in milliseconds - * @param array $attribs array containing attributes (strings) to be returned, valid values are: - * mem, cpu, loadavg_5, lan-rx_errors, lan-tx_errors, lan-rx_bytes, - * lan-tx_bytes, lan-rx_packets, lan-tx_packets, lan-rx_dropped, lan-tx_dropped - * default is ['time', 'mem', 'cpu', 'loadavg_5'] - * @return array returns an array of hourly stats objects for the gateway belonging to the current site + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @param array $attribs array containing attributes (strings) to be returned, valid values are: + * mem, cpu, loadavg_5, lan-rx_errors, lan-tx_errors, lan-rx_bytes, + * lan-tx_bytes, lan-rx_packets, lan-tx_packets, lan-rx_dropped, lan-tx_dropped + * default is ['time', 'mem', 'cpu', 'loadavg_5'] + * @return array returns an array of hourly stats objects for the gateway belonging to the current site */ public function stat_hourly_gateway($start = null, $end = null, $attribs = null) { @@ -846,7 +840,6 @@ public function stat_hourly_gateway($start = null, $end = null, $attribs = null) $start = empty($start) ? $end - (7 * 24 * 3600 * 1000) : intval($start); $attribs = empty($attribs) ? ['time', 'mem', 'cpu', 'loadavg_5'] : array_merge(['time'], $attribs); $payload = ['attrs' => $attribs, 'start' => $start, 'end' => $end]; - return $this->fetch_results('/api/s/' . $this->site . '/stat/report/hourly.gw', $payload); } @@ -857,13 +850,13 @@ public function stat_hourly_gateway($start = null, $end = null, $attribs = null) * - defaults to the past 52 weeks (52*7*24 hours) * - requires a USG * - * @param int $start optional, Unix timestamp in milliseconds - * @param int $end optional, Unix timestamp in milliseconds - * @param array $attribs array containing attributes (strings) to be returned, valid values are: - * mem, cpu, loadavg_5, lan-rx_errors, lan-tx_errors, lan-rx_bytes, - * lan-tx_bytes, lan-rx_packets, lan-tx_packets, lan-rx_dropped, lan-tx_dropped - * default is ['time', 'mem', 'cpu', 'loadavg_5'] - * @return array returns an array of hourly stats objects for the gateway belonging to the current site + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @param array $attribs array containing attributes (strings) to be returned, valid values are: + * mem, cpu, loadavg_5, lan-rx_errors, lan-tx_errors, lan-rx_bytes, + * lan-tx_bytes, lan-rx_packets, lan-tx_packets, lan-rx_dropped, lan-tx_dropped + * default is ['time', 'mem', 'cpu', 'loadavg_5'] + * @return array returns an array of hourly stats objects for the gateway belonging to the current site */ public function stat_daily_gateway($start = null, $end = null, $attribs = null) { @@ -871,7 +864,6 @@ public function stat_daily_gateway($start = null, $end = null, $attribs = null) $start = empty($start) ? $end - (52 * 7 * 24 * 3600 * 1000) : intval($start); $attribs = empty($attribs) ? ['time', 'mem', 'cpu', 'loadavg_5'] : array_merge(['time'], $attribs); $payload = ['attrs' => $attribs, 'start' => $start, 'end' => $end]; - return $this->fetch_results('/api/s/' . $this->site . '/stat/report/daily.gw', $payload); } @@ -882,13 +874,13 @@ public function stat_daily_gateway($start = null, $end = null, $attribs = null) * - defaults to the past 52 weeks (52*7*24 hours) * - requires a USG * - * @param int $start optional, Unix timestamp in milliseconds - * @param int $end optional, Unix timestamp in milliseconds - * @param array $attribs array containing attributes (strings) to be returned, valid values are: - * mem, cpu, loadavg_5, lan-rx_errors, lan-tx_errors, lan-rx_bytes, - * lan-tx_bytes, lan-rx_packets, lan-tx_packets, lan-rx_dropped, lan-tx_dropped - * default is ['time', 'mem', 'cpu', 'loadavg_5'] - * @return array returns an array of monthly stats objects for the gateway belonging to the current site + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @param array $attribs array containing attributes (strings) to be returned, valid values are: + * mem, cpu, loadavg_5, lan-rx_errors, lan-tx_errors, lan-rx_bytes, + * lan-tx_bytes, lan-rx_packets, lan-tx_packets, lan-rx_dropped, lan-tx_dropped + * default is ['time', 'mem', 'cpu', 'loadavg_5'] + * @return array returns an array of monthly stats objects for the gateway belonging to the current site */ public function stat_monthly_gateway($start = null, $end = null, $attribs = null) { @@ -896,7 +888,6 @@ public function stat_monthly_gateway($start = null, $end = null, $attribs = null $start = empty($start) ? $end - (52 * 7 * 24 * 3600 * 1000) : intval($start); $attribs = empty($attribs) ? ['time', 'mem', 'cpu', 'loadavg_5'] : array_merge(['time'], $attribs); $payload = ['attrs' => $attribs, 'start' => $start, 'end' => $end]; - return $this->fetch_results('/api/s/' . $this->site . '/stat/report/monthly.gw', $payload); } @@ -907,16 +898,15 @@ public function stat_monthly_gateway($start = null, $end = null, $attribs = null * - defaults to the past 24 hours * - requires a USG * - * @param int $start optional, Unix timestamp in milliseconds - * @param int $end optional, Unix timestamp in milliseconds - * @return array returns an array of speed test result objects + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @return array returns an array of speed test result objects */ public function stat_speedtest_results($start = null, $end = null) { $end = empty($end) ? time() * 1000 : intval($end); $start = empty($start) ? $end - (24 * 3600 * 1000) : intval($start); $payload = ['attrs' => ['xput_download', 'xput_upload', 'latency', 'time'], 'start' => $start, 'end' => $end]; - return $this->fetch_results('/api/s/' . $this->site . '/stat/report/archive.speedtest', $payload); } @@ -929,10 +919,10 @@ public function stat_speedtest_results($start = null, $end = null) * - requires a USG * - supported in UniFi controller versions 5.9.X and higher * - * @param int $start optional, Unix timestamp in milliseconds - * @param int $end optional, Unix timestamp in milliseconds - * @param int $limit optional, maximum number of events to return, defaults to 10000 - * @return array returns an array of IPS/IDS event objects + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @param int $limit optional, maximum number of events to return, defaults to 10000 + * @return array returns an array of IPS/IDS event objects */ public function stat_ips_events($start = null, $end = null, $limit = null) { @@ -940,7 +930,6 @@ public function stat_ips_events($start = null, $end = null, $limit = null) $start = empty($start) ? $end - (24 * 3600 * 1000) : intval($start); $limit = empty($limit) ? 10000 : intval($limit); $payload = ['start' => $start, 'end' => $end, '_limit' => $limit]; - return $this->fetch_results('/api/s/' . $this->site . '/stat/ips/event', $payload); } @@ -950,11 +939,13 @@ public function stat_ips_events($start = null, $end = null, $limit = null) * NOTES: * - defaults to the past 7*24 hours * - * @param int $start optional, Unix timestamp in milliseconds - * @param int $end optional, Unix timestamp in milliseconds - * @param string $mac optional, client MAC address to return sessions for (can only be used when start and end are also provided) - * @param string $type optional, client type to return sessions for, can be 'all', 'guest' or 'user'; default value is 'all' - * @return array returns an array of login session objects for all devices or a single device + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @param string $mac optional, client MAC address to return sessions for (can only be used when start and end + * are also provided) + * @param string $type optional, client type to return sessions for, can be 'all', 'guest' or 'user'; default + * value is 'all' + * @return array|false returns an array of login session objects for all devices or a single device */ public function stat_sessions($start = null, $end = null, $mac = null, $type = 'all') { @@ -978,15 +969,14 @@ public function stat_sessions($start = null, $end = null, $mac = null, $type = ' * NOTES: * - defaults to the past 7*24 hours * - * @param string $mac client MAC address - * @param int $limit optional, maximum number of sessions to get (default value is 5) - * @return array returns an array of login session objects for all devices or a single device + * @param string $mac client MAC address + * @param int $limit optional, maximum number of sessions to get (default value is 5) + * @return array returns an array of login session objects for all devices or a single device */ public function stat_sta_sessions_latest($mac, $limit = null) { $limit = empty($limit) ? 5 : intval($limit); - $payload = ['mac' => strtolower($mac), '_limit' => $limit, '_sort'=> '-assoc_time']; - + $payload = ['mac' => strtolower($mac), '_limit' => $limit, '_sort' => '-assoc_time']; return $this->fetch_results('/api/s/' . $this->site . '/stat/session', $payload); } @@ -996,16 +986,15 @@ public function stat_sta_sessions_latest($mac, $limit = null) * NOTES: * - defaults to the past 7*24 hours * - * @param int $start optional, Unix timestamp in milliseconds - * @param int $end optional, Unix timestamp in milliseconds - * @return array returns an array of authorization objects + * @param int $start optional, Unix timestamp in milliseconds + * @param int $end optional, Unix timestamp in milliseconds + * @return array returns an array of authorization objects */ public function stat_auths($start = null, $end = null) { $end = empty($end) ? time() : intval($end); $start = empty($start) ? $end - (7 * 24 * 3600) : intval($start); $payload = ['start' => $start, 'end' => $end]; - return $this->fetch_results('/api/s/' . $this->site . '/stat/authorization', $payload); } @@ -1016,13 +1005,12 @@ public function stat_auths($start = null, $end = null) * - is only used to select clients that were online within that period, * the returned stats per client are all-time totals, irrespective of the value of * - * @param int $historyhours optional, hours to go back (default is 8760 hours or 1 year) - * @return array returns an array of client device objects + * @param int $historyhours optional, hours to go back (default is 8760 hours or 1 year) + * @return array returns an array of client device objects */ public function stat_allusers($historyhours = 8760) { $payload = ['type' => 'all', 'conn' => 'all', 'within' => intval($historyhours)]; - return $this->fetch_results('/api/s/' . $this->site . '/stat/alluser', $payload); } @@ -1032,21 +1020,23 @@ public function stat_allusers($historyhours = 8760) * NOTES: * - defaults to the past 7*24 hours * - * @param int $within optional, time frame in hours to go back to list guests with valid access (default = 24*365 hours) - * @return array returns an array of guest device objects with valid access + * @param int $within optional, time frame in hours to go back to list guests with valid access (default = 24*365 + * hours) + * @return array returns an array of guest device objects with valid access */ public function list_guests($within = 8760) { $payload = ['within' => intval($within)]; - return $this->fetch_results('/api/s/' . $this->site . '/stat/guest', $payload); } /** * Fetch online client device(s) * - * @param string $client_mac optional, the MAC address of a single online client device for which the call must be made - * @return array returns an array of online client device objects, or in case of a single device request, returns a single client device object + * @param string $client_mac optional, the MAC address of a single online client device for which the call must be + * made + * @return array returns an array of online client device objects, or in case of a single device request, returns a + * single client device object */ public function list_clients($client_mac = null) { @@ -1056,8 +1046,8 @@ public function list_clients($client_mac = null) /** * Fetch details for a single client device * - * @param string $client_mac optional, client device MAC address - * @return array returns an object with the client device information + * @param string $client_mac optional, client device MAC address + * @return array returns an object with the client device information */ public function stat_client($client_mac) { @@ -1067,25 +1057,24 @@ public function stat_client($client_mac) /** * Assign client device to another group * - * @param string $user_id id of the user device to be modified - * @param string $group_id id of the user group to assign user to - * @return bool returns true upon success + * @param string $user_id id of the user device to be modified + * @param string $group_id id of the user group to assign user to + * @return bool returns true upon success */ public function set_usergroup($user_id, $group_id) { $payload = ['usergroup_id' => $group_id]; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/upd/user/' . trim($user_id), $payload); } /** * Update client fixedip (using REST) * - * @param string $client_id _id value for the client - * @param bool $use_fixedip determines whether use_fixedip is true or false - * @param string $network_id optional, _id value for the network where the ip belongs to - * @param string $fixed_ip optional, IP address, value of client's fixed_ip field - * @return array returns an array containing a single object with attributes of the updated client on success + * @param string $client_id _id value for the client + * @param bool $use_fixedip determines whether use_fixedip is true or false + * @param string $network_id optional, _id value for the network where the ip belongs to + * @param string $fixed_ip optional, IP address, value of client's fixed_ip field + * @return array|false returns an array containing a single object with attributes of the updated client on success */ public function edit_client_fixedip($client_id, $use_fixedip, $network_id = null, $fixed_ip = null) { @@ -1093,10 +1082,10 @@ public function edit_client_fixedip($client_id, $use_fixedip, $network_id = null return false; } - $this->request_method = 'PUT'; - $payload = [ + $this->curl_method = 'PUT'; + $payload = [ '_id' => $client_id, - 'use_fixedip' => $use_fixedip + 'use_fixedip' => $use_fixedip, ]; if ($use_fixedip) { @@ -1125,59 +1114,61 @@ public function list_usergroups() /** * Create user group (using REST) * - * @param string $group_name name of the user group - * @param int $group_dn limit download bandwidth in Kbps (default = -1, which sets bandwidth to unlimited) - * @param int $group_up limit upload bandwidth in Kbps (default = -1, which sets bandwidth to unlimited) - * @return array containing a single object with attributes of the new usergroup ("_id", "name", "qos_rate_max_down", "qos_rate_max_up", "site_id") on success + * @param string $group_name name of the user group + * @param int $group_dn limit download bandwidth in Kbps (default = -1, which sets bandwidth to unlimited) + * @param int $group_up limit upload bandwidth in Kbps (default = -1, which sets bandwidth to unlimited) + * @return array containing a single object with attributes of the new usergroup ("_id", "name", + * "qos_rate_max_down", "qos_rate_max_up", "site_id") on success */ public function create_usergroup($group_name, $group_dn = -1, $group_up = -1) { - $payload = ['name' => $group_name, 'qos_rate_max_down' => intval($group_dn), 'qos_rate_max_up' => intval($group_up)]; - + $payload = [ + 'name' => $group_name, + 'qos_rate_max_down' => intval($group_dn), + 'qos_rate_max_up' => intval($group_up), + ]; return $this->fetch_results('/api/s/' . $this->site . '/rest/usergroup', $payload); } /** * Modify user group (using REST) * - * @param string $group_id _id value of the user group - * @param string $site_id _id value of the site - * @param string $group_name name of the user group - * @param int $group_dn limit download bandwidth in Kbps (default = -1, which sets bandwidth to unlimited) - * @param int $group_up limit upload bandwidth in Kbps (default = -1, which sets bandwidth to unlimited) - * @return array returns an array containing a single object with attributes of the updated usergroup on success + * @param string $group_id _id value of the user group + * @param string $site_id _id value of the site + * @param string $group_name name of the user group + * @param int $group_dn limit download bandwidth in Kbps (default = -1, which sets bandwidth to unlimited) + * @param int $group_up limit upload bandwidth in Kbps (default = -1, which sets bandwidth to unlimited) + * @return array returns an array containing a single object with attributes of the updated usergroup on success */ public function edit_usergroup($group_id, $site_id, $group_name, $group_dn = -1, $group_up = -1) { - $this->request_method = 'PUT'; - $payload = [ + $this->curl_method = 'PUT'; + $payload = [ '_id' => $group_id, 'name' => $group_name, 'qos_rate_max_down' => intval($group_dn), 'qos_rate_max_up' => intval($group_up), - 'site_id' => $site_id + 'site_id' => $site_id, ]; - return $this->fetch_results('/api/s/' . $this->site . '/rest/usergroup/' . trim($group_id), $payload); } /** * Delete user group (using REST) * - * @param string $group_id _id value of the user group to delete - * @return bool returns true on success + * @param string $group_id _id value of the user group to delete + * @return bool returns true on success */ public function delete_usergroup($group_id) { - $this->request_method = 'DELETE'; - + $this->curl_method = 'DELETE'; return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/usergroup/' . trim($group_id)); } /** * Fetch AP groups * - * @return array containing the current AP groups on success + * @return array containing the current AP groups on success */ public function list_apgroups() { @@ -1187,57 +1178,55 @@ public function list_apgroups() /** * Create AP group * - * @param string $group_name name to assign to the AP group - * @param array $device_macs optional, array containing the MAC addresses (strings) of the APs to add to the new group - * @return object returns a single object with attributes of the new AP group on success + * @param string $group_name name to assign to the AP group + * @param array $device_macs optional, array containing the MAC addresses (strings) of the APs to add to the new + * group + * @return array containing a single object with attributes of the new AP group on success */ public function create_apgroup($group_name, $device_macs = []) { $payload = ['device_macs' => $device_macs, 'name' => $group_name]; - return $this->fetch_results('/v2/api/site/' . $this->site . '/apgroups', $payload); } /** * Modify AP group * - * @param string $group_id _id value of the AP group to modify - * @param string $group_name name to assign to the AP group - * @param array $device_macs array containing the members of the AP group which overwrites the existing - * group_members (passing an empty array clears the AP member list) - * @return object returns a single object with attributes of the updated AP group on success + * @param string $group_id _id value of the AP group to modify + * @param string $group_name name to assign to the AP group + * @param array $device_macs array containing the members of the AP group which overwrites the existing + * group_members (passing an empty array clears the AP member list) + * @return array|bool containing a single object with attributes of the updated AP group on success */ public function edit_apgroup($group_id, $group_name, $device_macs) { - $this->request_method = 'PUT'; - $payload = [ + $this->curl_method = 'PUT'; + $payload = [ '_id' => $group_id, 'attr_no_delete' => false, 'name' => $group_name, - 'device_macs' => $device_macs + 'device_macs' => $device_macs, ]; - return $this->fetch_results('/v2/api/site/' . $this->site . '/apgroups/' . trim($group_id), $payload); } /** * Delete AP group * - * @param string $group_id _id value of the AP group to delete - * @return bool returns true on success + * @param string $group_id _id value of the AP group to delete + * @return bool returns true on success */ public function delete_apgroup($group_id) { - $this->request_method = 'DELETE'; - + $this->curl_method = 'DELETE'; return $this->fetch_results_boolean('/v2/api/site/' . $this->site . '/apgroups/' . trim($group_id)); } /** * Fetch firewall groups (using REST) * - * @param string $group_id optional, _id value of the single firewall group to list - * @return array containing the current firewall groups or the selected firewall group on success + * @param string $group_id optional, _id value of the single firewall group to list + * @return array containing the current firewall groups or the selected firewall group on success */ public function list_firewallgroups($group_id = '') { @@ -1247,11 +1236,12 @@ public function list_firewallgroups($group_id = '') /** * Create firewall group (using REST) * - * @param string $group_name name to assign to the firewall group - * @param string $group_type firewall group type; valid values are address-group, ipv6-address-group, port-group - * @param array $group_members array containing the members of the new group (IPv4 addresses, IPv6 addresses or port numbers) - * (default is an empty array) - * @return array containing a single object with attributes of the new firewall group on success + * @param string $group_name name to assign to the firewall group + * @param string $group_type firewall group type; valid values are address-group, ipv6-address-group, port-group + * @param array $group_members array containing the members of the new group (IPv4 addresses, IPv6 addresses or + * port numbers) + * (default is an empty array) + * @return array|false containing a single object with attributes of the new firewall group on success */ public function create_firewallgroup($group_name, $group_type, $group_members = []) { @@ -1260,21 +1250,21 @@ public function create_firewallgroup($group_name, $group_type, $group_members = } $payload = ['name' => $group_name, 'group_type' => $group_type, 'group_members' => $group_members]; - return $this->fetch_results('/api/s/' . $this->site . '/rest/firewallgroup', $payload); } /** * Modify firewall group (using REST) * - * @param string $group_id _id value of the firewall group to modify - * @param string $site_id site_id value of the firewall group to modify - * @param string $group_name name of the firewall group - * @param string $group_type firewall group type; valid values are address-group, ipv6-address-group, port-group, - * group_type cannot be changed for an existing firewall group! - * @param array $group_members array containing the members of the group (IPv4 addresses, IPv6 addresses or port numbers) - * which overwrites the existing group_members (default is an empty array) - * @return array containing a single object with attributes of the updated firewall group on success + * @param string $group_id _id value of the firewall group to modify + * @param string $site_id site_id value of the firewall group to modify + * @param string $group_name name of the firewall group + * @param string $group_type firewall group type; valid values are address-group, ipv6-address-group, + * port-group, + * group_type cannot be changed for an existing firewall group! + * @param array $group_members array containing the members of the group (IPv4 addresses, IPv6 addresses or port + * numbers) which overwrites the existing group_members (default is an empty array) + * @return array|false containing a single object with attributes of the updated firewall group on success */ public function edit_firewallgroup($group_id, $site_id, $group_name, $group_type, $group_members = []) { @@ -1282,35 +1272,33 @@ public function edit_firewallgroup($group_id, $site_id, $group_name, $group_type return false; } - $this->request_method = 'PUT'; - $payload = [ + $this->curl_method = 'PUT'; + $payload = [ '_id' => $group_id, 'name' => $group_name, 'group_type' => $group_type, 'group_members' => $group_members, - 'site_id' => $site_id + 'site_id' => $site_id, ]; - return $this->fetch_results('/api/s/' . $this->site . '/rest/firewallgroup/' . trim($group_id), $payload); } /** * Delete firewall group (using REST) * - * @param string $group_id _id value of the firewall group to delete - * @return bool returns true on success + * @param string $group_id _id value of the firewall group to delete + * @return bool returns true on success */ public function delete_firewallgroup($group_id) { - $this->request_method = 'DELETE'; - + $this->curl_method = 'DELETE'; return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/firewallgroup/' . trim($group_id)); } /** * Fetch firewall rules (using REST) * - * @return array containing the current firewall rules on success + * @return array containing the current firewall rules on success */ public function list_firewallrules() { @@ -1320,8 +1308,8 @@ public function list_firewallrules() /** * Fetch static routing settings (using REST) * - * @param string $route_id _id value of the static route to get settings for - * @return array containing the static routes and their settings + * @param string $route_id _id value of the static route to get settings for + * @return array containing the static routes and their settings */ public function list_routing($route_id = '') { @@ -1341,21 +1329,20 @@ public function list_health() /** * Fetch dashboard metrics * - * @param boolean $five_minutes when true, return stats based on 5 minute intervals, - * returns hourly stats by default (supported on controller versions 5.5.* and higher) - * @return array containing dashboard metric objects (available since controller version 4.9.1.alpha) + * @param boolean $five_minutes when true, return stats based on 5 minute intervals, + * returns hourly stats by default (supported on controller versions 5.5.* and higher) + * @return array containing dashboard metric objects (available since controller version 4.9.1.alpha) */ public function list_dashboard($five_minutes = false) { $path_suffix = $five_minutes ? '?scale=5minutes' : null; - return $this->fetch_results('/api/s/' . $this->site . '/stat/dashboard' . $path_suffix); } /** * Fetch client devices * - * @return array containing known client device objects + * @return array containing known client device objects */ public function list_users() { @@ -1365,8 +1352,8 @@ public function list_users() /** * Fetch UniFi devices * - * @param string $device_mac optional, the MAC address of a single UniFi device for which the call must be made - * @return array containing known UniFi device objects (or a single device when using the parameter) + * @param string $device_mac optional, the MAC address of a single UniFi device for which the call must be made + * @return array containing known UniFi device objects (or a single device when using the parameter) */ public function list_devices($device_mac = null) { @@ -1378,7 +1365,7 @@ public function list_devices($device_mac = null) * * NOTES: this endpoint was introduced with controller versions 5.5.X * - * @return array containing known device tag objects + * @return array containing known device tag objects */ public function list_tags() { @@ -1388,20 +1375,19 @@ public function list_tags() /** * Fetch rogue/neighboring access points * - * @param int $within optional, hours to go back to list discovered "rogue" access points (default = 24 hours) - * @return array containing rogue/neighboring access point objects + * @param int $within optional, hours to go back to list discovered "rogue" access points (default = 24 hours) + * @return array containing rogue/neighboring access point objects */ public function list_rogueaps($within = 24) { $payload = ['within' => intval($within)]; - return $this->fetch_results('/api/s/' . $this->site . '/stat/rogueap', $payload); } /** * Fetch known rogue access points * - * @return array containing known rogue access point objects + * @return array containing known rogue access point objects */ public function list_known_rogueaps() { @@ -1414,31 +1400,29 @@ public function list_known_rogueaps() * NOTES: * this is an experimental function, please do not use unless you know exactly what you're doing * - * @return string URL from where the backup file can be downloaded once generated + * @return bool|array|string URL from where the backup file can be downloaded once generated, false upon failure */ public function generate_backup() { $payload = ['cmd' => 'backup']; - return $this->fetch_results('/api/s/' . $this->site . '/cmd/backup', $payload); } /** * Fetch auto backups * - * @return array containing objects with backup details on success + * @return array containing objects with backup details on success */ public function list_backups() { $payload = ['cmd' => 'list-backups']; - return $this->fetch_results('/api/s/' . $this->site . '/cmd/backup', $payload); } /** * Fetch sites * - * @return array containing a list of sites hosted on this controller with some details + * @return array containing a list of sites hosted on this controller with some details */ public function list_sites() { @@ -1450,7 +1434,7 @@ public function list_sites() * * NOTES: this endpoint was introduced with controller version 5.2.9 * - * @return array containing statistics for all sites hosted on this controller + * @return array containing statistics for all sites hosted on this controller */ public function stat_sites() { @@ -1459,26 +1443,25 @@ public function stat_sites() /** * Create a site - * @param string $description the long name for the new site - * @return array containing a single object with attributes of the new site ("_id", "desc", "name") on success + * + * @param string $description the long name for the new site + * @return array containing a single object with attributes of the new site ("_id", "desc", "name") on success */ public function create_site($description) { $payload = ['desc' => $description, 'cmd' => 'add-site']; - return $this->fetch_results('/api/s/' . $this->site . '/cmd/sitemgr', $payload); } /** * Delete a site * - * @param string $site_id _id value of the site to delete - * @return bool true on success + * @param string $site_id _id value of the site to delete + * @return bool true on success */ public function delete_site($site_id) { $payload = ['site' => $site_id, 'cmd' => 'delete-site']; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/sitemgr', $payload); } @@ -1487,81 +1470,83 @@ public function delete_site($site_id) * * NOTES: immediately after being changed, the site is available in the output of the list_sites() function * - * @param string $site_name the new long name for the current site - * @return bool true on success + * @param string $site_name the new long name for the current site + * @return bool true on success */ public function set_site_name($site_name) { $payload = ['cmd' => 'update-site', 'desc' => $site_name]; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/sitemgr', $payload); } /** * Update site country * - * @param string $country_id _id value of the country key - * @param object|array $payload stdClass object or associative array containing the configuration to apply to the site, must be a (partial) - * object/array structured in the same manner as is returned by list_settings() for the section with the "country" key. - * Valid country codes can be obtained using the list_country_codes() function/method. - * Do not include the _id property, it is assigned by the controller and returned upon success. - * @return bool true on success + * @param string $country_id _id value of the country key + * @param object|array $payload stdClass object or associative array containing the configuration to apply to + * the site, must be a (partial) object/array structured in the same manner as is + * returned by list_settings() for the section with the "country" key. Valid + * country codes can be obtained using the list_country_codes() function/method. Do + * not include the _id property, it is assigned by the controller and returned upon + * success. + * @return bool true on success */ public function set_site_country($country_id, $payload) { - $this->request_method = 'PUT'; - - return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/setting/country/' . trim($country_id), $payload); + $this->curl_method = 'PUT'; + return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/setting/country/' . trim($country_id), + $payload); } /** * Update site locale * - * @param string $locale_id _id value of the locale section - * @param object|array $payload stdClass object or associative array containing the configuration to apply to the site, must be a (partial) - * object/array structured in the same manner as is returned by list_settings() for section with the the "locale" key. - * Valid timezones can be obtained in Javascript as explained here: - * https://stackoverflow.com/questions/38399465/how-to-get-list-of-all-timezones-in-javascript - * or in PHP using timezone_identifiers_list(). - * Do not include the _id property, it is assigned by the controller and returned upon success. - * @return bool true on success + * @param string $locale_id _id value of the locale section + * @param object|array $payload stdClass object or associative array containing the configuration to apply to the + * site, must be a (partial) object/array structured in the same manner as is + * returned by list_settings() for section with the the "locale" key. Valid + * timezones can be obtained in Javascript as explained here: + * https://stackoverflow.com/questions/38399465/how-to-get-list-of-all-timezones-in-javascript + * or in PHP using timezone_identifiers_list(). Do not include the _id property, it + * is assigned by the controller and returned upon success. + * @return bool true on success */ public function set_site_locale($locale_id, $payload) { - $this->request_method = 'PUT'; - - return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/setting/locale/' . trim($locale_id), $payload); + $this->curl_method = 'PUT'; + return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/setting/locale/' . trim($locale_id), + $payload); } /** * Update site snmp * - * @param string $snmp_id _id value of the snmp section - * @param object|array $payload stdClass object or associative array containing the configuration to apply to the site, must be a (partial) - * object/array structured in the same manner as is returned by list_settings() for the section with the "snmp" key. - * Do not include the _id property, it is assigned by the controller and returned upon success. - * @return bool true on success + * @param string $snmp_id _id value of the snmp section + * @param object|array $payload stdClass object or associative array containing the configuration to apply to the + * site, must be a (partial) object/array structured in the same manner as is returned + * by list_settings() for the section with the "snmp" key. Do not include the _id + * property, it is assigned by the controller and returned upon success. + * @return bool true on success */ public function set_site_snmp($snmp_id, $payload) { - $this->request_method = 'PUT'; - + $this->curl_method = 'PUT'; return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/setting/snmp/' . trim($snmp_id), $payload); } /** * Update site mgmt * - * @param string $mgmt_id _id value of the mgmt section - * @param object|array $payload stdClass object or associative array containing the configuration to apply to the site, must be a (partial) - * object/array structured in the same manner as is returned by list_settings() for the section with the "mgmt" key. - * Do not include the _id property, it is assigned by the controller and returned upon success. - * @return bool true on success + * @param string $mgmt_id _id value of the mgmt section + * @param object|array $payload stdClass object or associative array containing the configuration to apply to the + * site, must be a (partial) object/array structured in the same manner as is returned + * by list_settings() for the section with the "mgmt" key. Do not include the _id + * property, it is assigned by the controller and returned upon success. + * @return bool true on success */ public function set_site_mgmt($mgmt_id, $payload) { - $this->request_method = 'PUT'; - + $this->curl_method = 'PUT'; return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/setting/mgmt/' . trim($mgmt_id), $payload); } @@ -1569,66 +1554,69 @@ public function set_site_mgmt($mgmt_id, $payload) * Update site guest access * * @param string $guest_access_id _id value of the guest_access section - * @param object|array $payload stdClass object or associative array containing the configuration to apply to the site, must be a (partial) - * object/array structured in the same manner as is returned by list_settings() for the section with the "guest_access" key. - * Do not include the _id property, it is assigned by the controller and returned upon success. - * @return bool true on success + * @param object|array $payload stdClass object or associative array containing the configuration to apply + * to the site, must be a (partial) object/array structured in the same manner + * as is returned by list_settings() for the section with the "guest_access" + * key. Do not include the _id property, it is assigned by the controller and + * returned upon success. + * @return bool true on success */ public function set_site_guest_access($guest_access_id, $payload) { - $this->request_method = 'PUT'; - - return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/setting/guest_access/' . trim($guest_access_id), $payload); + $this->curl_method = 'PUT'; + return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/setting/guest_access/' . trim($guest_access_id), + $payload); } /** * Update site ntp * - * @param string $ntp_id _id value of the ntp section - * @param object|array $payload stdClass object or associative array containing the configuration to apply to the site, must be a (partial) - * object/array structured in the same manner as is returned by list_settings() for the section with the "ntp" key. - * Do not include the _id property, it is assigned by the controller and returned upon success. - * @return bool true on success + * @param string $ntp_id _id value of the ntp section + * @param object|array $payload stdClass object or associative array containing the configuration to apply to the + * site, must be a (partial) object/array structured in the same manner as is returned + * by list_settings() for the section with the "ntp" key. Do not include the _id + * property, it is assigned by the controller and returned upon success. + * @return bool true on success */ public function set_site_ntp($ntp_id, $payload) { - $this->request_method = 'PUT'; - + $this->curl_method = 'PUT'; return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/setting/ntp/' . trim($ntp_id), $payload); } /** * Update site connectivity * - * @param string $connectivity_id _id value of the connectivity section - * @param object|array $payload stdClass object or associative array containing the configuration to apply to the site, must be a (partial) - * object/array structured in the same manner as is returned by list_settings() for the section with the "connectivity" key. - * Do not include the _id property, it is assigned by the controller and returned upon success. - * @return bool true on success + * @param string $connectivity_id _id value of the connectivity section + * @param object|array $payload stdClass object or associative array containing the configuration to apply + * to the site, must be a (partial) object/array structured in the same manner + * as is returned by list_settings() for the section with the "connectivity" + * key. Do not include the _id property, it is assigned by the controller and + * returned upon success. + * @return bool true on success */ public function set_site_connectivity($connectivity_id, $payload) { - $this->request_method = 'PUT'; - - return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/setting/connectivity/' . trim($connectivity_id), $payload); + $this->curl_method = 'PUT'; + return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/setting/connectivity/' . trim($connectivity_id), + $payload); } /** * Fetch admins * - * @return array containing administrator objects for selected site + * @return array containing administrator objects for selected site */ public function list_admins() { $payload = ['cmd' => 'get-admins']; - return $this->fetch_results('/api/s/' . $this->site . '/cmd/sitemgr', $payload); } /** * Fetch all admins * - * @return array containing administrator objects for all sites + * @return array containing administrator objects for all sites */ public function list_all_admins() { @@ -1642,33 +1630,32 @@ public function list_all_admins() * - after issuing a valid request, an invite is sent to the email address provided * - issuing this command against an existing admin triggers a "re-invite" * - * @param string $name name to assign to the new admin user - * @param string $email email address to assign to the new admin user - * @param bool $enable_sso optional, whether or not SSO is allowed for the new admin - * default value is true which enables the SSO capability - * @param bool $readonly optional, whether or not the new admin has readonly - * permissions, default value is false which gives the new admin - * Administrator permissions - * @param bool $device_adopt optional, whether or not the new admin has permissions to - * adopt devices, default value is false. With versions < 5.9.X this only applies - * when readonly is true. - * @param bool $device_restart optional, whether or not the new admin has permissions to - * restart devices, default value is false. With versions < 5.9.X this only applies - * when readonly is true. - * @return bool true on success + * @param string $name name to assign to the new admin user + * @param string $email email address to assign to the new admin user + * @param bool $enable_sso optional, whether SSO is allowed for the new admin + * default value is true which enables the SSO capability + * @param bool $readonly optional, whether the new admin has readonly + * permissions, default value is false which gives the new admin + * Administrator permissions + * @param bool $device_adopt optional, whether the new admin has permissions to + * adopt devices, default value is false. With versions < 5.9.X this only applies + * when readonly is true. + * @param bool $device_restart optional, whether the new admin has permissions to + * restart devices, default value is false. With versions < 5.9.X this only applies + * when readonly is true. + * @return bool true on success */ public function invite_admin( $name, $email, - $enable_sso = true, - $readonly = false, - $device_adopt = false, + $enable_sso = true, + $readonly = false, + $device_adopt = false, $device_restart = false ) { $email_valid = filter_var(trim($email), FILTER_VALIDATE_EMAIL); if (!$email_valid) { trigger_error('The email address provided is invalid!'); - return false; } @@ -1678,7 +1665,7 @@ public function invite_admin( 'for_sso' => $enable_sso, 'cmd' => 'invite-admin', 'role' => 'admin', - 'permissions' => [] + 'permissions' => [], ]; if ($readonly) { @@ -1699,18 +1686,18 @@ public function invite_admin( /** * Assign an existing admin to the current site * - * @param string $admin_id _id value of the admin user to assign, can be obtained using the - * list_all_admins() method/function - * @param bool $readonly optional, whether or not the new admin has readonly - * permissions, default value is false which gives the new admin - * Administrator permissions - * @param bool $device_adopt optional, whether or not the new admin has permissions to - * adopt devices, default value is false. With versions < 5.9.X this only applies - * when readonly is true. - * @param bool $device_restart optional, whether or not the new admin has permissions to - * restart devices, default value is false. With versions < 5.9.X this only applies - * when readonly is true. - * @return bool true on success + * @param string $admin_id _id value of the admin user to assign, can be obtained using the + * list_all_admins() method/function + * @param bool $readonly optional, whether or not the new admin has readonly + * permissions, default value is false which gives the new admin + * Administrator permissions + * @param bool $device_adopt optional, whether or not the new admin has permissions to + * adopt devices, default value is false. With versions < 5.9.X this only applies + * when readonly is true. + * @param bool $device_restart optional, whether or not the new admin has permissions to + * restart devices, default value is false. With versions < 5.9.X this only applies + * when readonly is true. + * @return bool true on success */ public function assign_existing_admin($admin_id, $readonly = false, $device_adopt = false, $device_restart = false) { @@ -1718,7 +1705,7 @@ public function assign_existing_admin($admin_id, $readonly = false, $device_adop 'cmd' => 'grant-admin', 'admin' => trim($admin_id), 'role' => 'admin', - 'permissions' => [] + 'permissions' => [], ]; if ($readonly) { @@ -1742,21 +1729,20 @@ public function assign_existing_admin($admin_id, $readonly = false, $device_adop * NOTES: * only non-superadmin accounts can be revoked * - * @param string $admin_id _id value of the admin to revoke, can be obtained using the - * list_all_admins() method/function - * @return bool true on success + * @param string $admin_id _id value of the admin to revoke, can be obtained using the + * list_all_admins() method/function + * @return bool true on success */ public function revoke_admin($admin_id) { $payload = ['cmd' => 'revoke-admin', 'admin' => $admin_id]; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/sitemgr', $payload); } /** * Fetch wlan_groups * - * @return array containing known wlan_groups + * @return array containing known wlan_groups */ public function list_wlan_groups() { @@ -1766,7 +1752,7 @@ public function list_wlan_groups() /** * Fetch sysinfo * - * @return array containing known sysinfo data + * @return array containing known sysinfo data */ public function stat_sysinfo() { @@ -1792,12 +1778,11 @@ public function stat_status() * NOTES: * login not required * - * @return bool|array staus array upon success, false upon failure + * @return bool|array status array upon success, false upon failure */ public function stat_full_status() { $this->fetch_results_boolean('/status', null, false); - return json_decode($this->get_last_results_raw()); } @@ -1807,19 +1792,18 @@ public function stat_full_status() * NOTES: * login not required * - * @return bool|array mappings array upon success, false upon failure + * @return bool|array mappings array upon success, false upon failure */ public function list_device_name_mappings() { $this->fetch_results_boolean('/dl/firmware/bundles.json', null, false); - return json_decode($this->get_last_results_raw()); } /** * Fetch self * - * @return array containing information about the logged in user + * @return array containing information about the logged in user */ public function list_self() { @@ -1829,36 +1813,34 @@ public function list_self() /** * Fetch vouchers * - * @param int $create_time optional, create time of the vouchers to fetch in Unix timestamp in seconds - * @return array containing hotspot voucher objects + * @param int $create_time optional, create time of the vouchers to fetch in Unix timestamp in seconds + * @return array containing hotspot voucher objects */ public function stat_voucher($create_time = null) { $payload = isset($create_time) ? ['create_time' => intval($create_time)] : []; - return $this->fetch_results('/api/s/' . $this->site . '/stat/voucher', $payload); } /** * Fetch payments * - * @param int $within optional, number of hours to go back to fetch payments - * @return array containing hotspot payments + * @param int $within optional, number of hours to go back to fetch payments + * @return array containing hotspot payments */ public function stat_payment($within = null) { $path_suffix = isset($within) ? '?within=' . intval($within) : ''; - return $this->fetch_results('/api/s/' . $this->site . '/stat/payment' . $path_suffix); } /** * Create hotspot operator (using REST) * - * @param string $name name for the hotspot operator - * @param string $x_password clear text password for the hotspot operator - * @param string $note optional, note to attach to the hotspot operator - * @return bool true upon success + * @param string $name name for the hotspot operator + * @param string $x_password clear text password for the hotspot operator + * @param string $note optional, note to attach to the hotspot operator + * @return bool true upon success */ public function create_hotspotop($name, $x_password, $note = null) { @@ -1873,7 +1855,7 @@ public function create_hotspotop($name, $x_password, $note = null) /** * Fetch hotspot operators (using REST) * - * @return array containing hotspot operators + * @return array containing hotspot operators */ public function list_hotspotop() { @@ -1885,30 +1867,30 @@ public function list_hotspotop() * * NOTES: please use the stat_voucher() method/function to retrieve the newly created voucher(s) by create_time * - * @param int $minutes minutes the voucher is valid after activation (expiration time) - * @param int $count number of vouchers to create, default value is 1 - * @param int $quota single-use or multi-use vouchers, value '0' is for multi-use, '1' is for single-use, - * 'n' is for multi-use n times - * @param string $note note text to add to voucher when printing - * @param int $up upload speed limit in kbps - * @param int $down download speed limit in kbps - * @param int $megabytes data transfer limit in MB - * @return array containing a single object which contains the create_time(stamp) of the voucher(s) created + * @param int $minutes minutes the voucher is valid after activation (expiration time) + * @param int $count number of vouchers to create, default value is 1 + * @param int $quota single-use or multi-use vouchers, value '0' is for multi-use, '1' is for single-use, + * 'n' is for multi-use n times + * @param string $note note text to add to voucher when printing + * @param int $up upload speed limit in kbps + * @param int $down download speed limit in kbps + * @param int $megabytes data transfer limit in MB + * @return array containing a single object which contains the create_time(stamp) of the voucher(s) created */ public function create_voucher( $minutes, - $count = 1, - $quota = 0, - $note = null, - $up = null, - $down = null, + $count = 1, + $quota = 0, + $note = null, + $up = null, + $down = null, $megabytes = null ) { $payload = [ 'cmd' => 'create-voucher', 'expire' => intval($minutes), 'n' => intval($count), - 'quota' => intval($quota) + 'quota' => intval($quota), ]; if (!is_null($note)) { @@ -1933,33 +1915,31 @@ public function create_voucher( /** * Revoke voucher * - * @param string $voucher_id _id value of the voucher to revoke - * @return bool true on success + * @param string $voucher_id _id value of the voucher to revoke + * @return bool true on success */ public function revoke_voucher($voucher_id) { $payload = ['_id' => $voucher_id, 'cmd' => 'delete-voucher']; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/hotspot', $payload); } /** * Extend guest authorization * - * @param string $guest_id _id value of the guest to extend the authorization for - * @return bool true on success + * @param string $guest_id _id value of the guest to extend the authorization for + * @return bool true on success */ public function extend_guest_validity($guest_id) { $payload = ['_id' => $guest_id, 'cmd' => 'extend']; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/hotspot', $payload); } /** * Fetch port forwarding stats * - * @return array containing port forwarding stats + * @return array containing port forwarding stats */ public function list_portforward_stats() { @@ -1969,7 +1949,7 @@ public function list_portforward_stats() /** * Fetch DPI stats * - * @return array containing DPI stats + * @return array containing DPI stats */ public function list_dpi_stats() { @@ -1979,13 +1959,13 @@ public function list_dpi_stats() /** * Fetch filtered DPI stats * - * @param string $type optional, whether to returns stats by app or by category, valid values: - * 'by_cat' or 'by_app' - * @param array $cat_filter optional, array containing numeric category ids to filter by, - * only to be combined with a "by_app" value for $type - * @return array containing filtered DPI stats + * @param string $type optional, whether to returns stats by app or by category, valid values: + * 'by_cat' or 'by_app' + * @param array $cat_filter optional, array containing numeric category ids to filter by, + * only to be combined with a "by_app" value for $type + * @return array|false containing filtered DPI stats */ - public function list_dpi_stats_filtered($type = 'by_cat', $cat_filter = null) + public function list_dpi_stats_filtered($type = 'by_cat', array $cat_filter = null) { if (!in_array($type, ['by_cat', 'by_app'])) { return false; @@ -1993,7 +1973,7 @@ public function list_dpi_stats_filtered($type = 'by_cat', $cat_filter = null) $payload = ['type' => $type]; - if (!is_null($cat_filter) && $type == 'by_app' && is_array($cat_filter)) { + if (is_array($cat_filter) && $type == 'by_app') { $payload['cats'] = $cat_filter; } @@ -2003,7 +1983,7 @@ public function list_dpi_stats_filtered($type = 'by_cat', $cat_filter = null) /** * Fetch current channels * - * @return array containing currently allowed channels + * @return array containing currently allowed channels */ public function list_current_channels() { @@ -2017,7 +1997,7 @@ public function list_current_channels() * these codes following the ISO standard: * https://en.wikipedia.org/wiki/ISO_3166-1_numeric * - * @return array containing available country codes + * @return array containing available country codes */ public function list_country_codes() { @@ -2027,7 +2007,7 @@ public function list_country_codes() /** * Fetch port forwarding settings * - * @return array containing port forwarding settings + * @return array containing port forwarding settings */ public function list_portforwarding() { @@ -2037,7 +2017,7 @@ public function list_portforwarding() /** * Fetch port configurations * - * @return array containing port configurations + * @return array containing port configurations */ public function list_portconf() { @@ -2047,7 +2027,7 @@ public function list_portconf() /** * Fetch VoIP extensions * - * @return array containing VoIP extensions + * @return array containing VoIP extensions */ public function list_extension() { @@ -2057,7 +2037,7 @@ public function list_extension() /** * Fetch site settings * - * @return array containing site configuration settings + * @return array containing site configuration settings */ public function list_settings() { @@ -2067,26 +2047,52 @@ public function list_settings() /** * Adopt a device to the selected site * - * @param string $mac device MAC address - * @return bool true on success + * @param string $mac device MAC address + * @return bool true on success */ public function adopt_device($mac) { $payload = ['mac' => strtolower($mac), 'cmd' => 'adopt']; + return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/devmgr', $payload); + } + /** + * Adopt a device using custom SSH credentials + * + * @param string $mac device MAC address + * @param string $ip IP to use for SSH connection + * @param string $username SSH username + * @param string $password SSH password + * @param string $url inform URL to point the device to + * @param int $port optional, SSH port + * @param bool $ssh_key_verify optional, whether to verify device SSH key + * @return bool true on success + */ + public function advanced_adopt_device($mac, $ip, $username, $password, $url, $port = 22, $ssh_key_verify = true) + { + $payload = [ + 'cmd' => 'adv-adopt', + 'mac' => strtolower($mac), + 'ip' => $ip, + 'username' => $username, + 'password' => $password, + 'url' => $url, + 'port' => $port, + 'sshKeyVerify' => $ssh_key_verify, + ]; return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/devmgr', $payload); } /** * Reboot a device * - * @param string $mac device MAC address - * @param string $reboot_type optional, two options: 'soft' or 'hard', defaults to soft - * soft can be used for all devices, requests a plain restart of that device - * hard is special for PoE switches and besides the restart also requests a - * power cycle on all PoE capable ports. Keep in mind that a 'hard' reboot - * does *NOT* trigger a factory-reset. - * @return bool true on success + * @param string $mac device MAC address + * @param string $reboot_type optional, two options: 'soft' or 'hard', defaults to soft + * soft can be used for all devices, requests a plain restart of that device + * hard is special for PoE switches and besides the restart also requests a + * power cycle on all PoE capable ports. Keep in mind that a 'hard' reboot + * does *NOT* trigger a factory-reset. + * @return bool true on success */ public function restart_device($mac, $reboot_type = 'soft') { @@ -2101,13 +2107,12 @@ public function restart_device($mac, $reboot_type = 'soft') /** * Force provision of a device * - * @param string $mac device MAC address - * @return bool true on success + * @param string $mac device MAC address + * @return bool true on success */ public function force_provision($mac) { $payload = ['mac' => strtolower($mac), 'cmd' => 'force-provision']; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/devmgr', $payload); } @@ -2122,7 +2127,6 @@ public function force_provision($mac) public function reboot_cloudkey() { $payload = ['cmd' => 'reboot']; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/system', $payload); } @@ -2134,9 +2138,9 @@ public function reboot_cloudkey() * - appears to only be supported for access points * - available since controller versions 5.2.X * - * @param string $ap_id value of _id for the access point which can be obtained from the device list - * @param bool $disable true disables the device, false enables the device - * @return bool true on success + * @param string $ap_id value of _id for the access point which can be obtained from the device list + * @param bool $disable true disables the device, false enables the device + * @return bool true on success */ public function disable_ap($ap_id, $disable) { @@ -2144,9 +2148,8 @@ public function disable_ap($ap_id, $disable) return false; } - $this->request_method = 'PUT'; - $payload = ['disabled' => $disable]; - + $this->curl_method = 'PUT'; + $payload = ['disabled' => $disable]; return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/device/' . trim($ap_id), $payload); } @@ -2156,11 +2159,11 @@ public function disable_ap($ap_id, $disable) * NOTES: * - available since controller versions 5.2.X * - * @param string $device_id value of _id for the device which can be obtained from the device list - * @param string $override_mode off/on/default; "off" disables the LED of the device, - * "on" enables the LED of the device, - * "default" applies the site-wide setting for device LEDs - * @return bool true on success + * @param string $device_id value of _id for the device which can be obtained from the device list + * @param string $override_mode off/on/default; "off" disables the LED of the device, + * "on" enables the LED of the device, + * "default" applies the site-wide setting for device LEDs + * @return bool true on success */ public function led_override($device_id, $override_mode) { @@ -2168,9 +2171,8 @@ public function led_override($device_id, $override_mode) return false; } - $this->request_method = 'PUT'; - $payload = ['led_override' => $override_mode]; - + $this->curl_method = 'PUT'; + $payload = ['led_override' => $override_mode]; return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/device/' . trim($device_id), $payload); } @@ -2180,9 +2182,9 @@ public function led_override($device_id, $override_mode) * NOTES: * replaces the old set_locate_ap() and unset_locate_ap() methods/functions * - * @param string $mac device MAC address - * @param bool $enable true enables flashing LED, false disables flashing LED - * @return bool true on success + * @param string $mac device MAC address + * @param bool $enable true enables flashing LED, false disables flashing LED + * @return bool true on success */ public function locate_ap($mac, $enable) { @@ -2192,15 +2194,14 @@ public function locate_ap($mac, $enable) $cmd = $enable ? 'set-locate' : 'unset-locate'; $payload = ['cmd' => $cmd, 'mac' => strtolower($mac)]; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/devmgr', $payload); } /** * Toggle LEDs of all the access points ON or OFF * - * @param bool $enable true switches LEDs of all the access points ON, false switches them OFF - * @return bool true on success + * @param bool $enable true switches LEDs of all the access points ON, false switches them OFF + * @return bool true on success */ public function site_leds($enable) { @@ -2209,7 +2210,6 @@ public function site_leds($enable) } $payload = ['led_enabled' => $enable]; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/set/setting/mgmt', $payload); } @@ -2219,13 +2219,13 @@ public function site_leds($enable) * NOTES: * - only supported on pre-5.X.X controller versions * - * @param string $ap_id the "_id" value for the access point you wish to update - * @param string $radio radio to update, default=ng - * @param int $channel channel to apply - * @param int $ht channel width, default=20 - * @param string $tx_power_mode power level, "low", "medium", or "high" - * @param int $tx_power transmit power level, default=0 - * @return bool true on success + * @param string $ap_id the "_id" value for the access point you wish to update + * @param string $radio radio to update, default=ng + * @param int $channel channel to apply + * @param int $ht channel width, default=20 + * @param string $tx_power_mode power level, "low", "medium", or "high" + * @param int $tx_power transmit power level, default=0 + * @return bool true on success */ public function set_ap_radiosettings($ap_id, $radio, $channel, $ht, $tx_power_mode, $tx_power) { @@ -2235,20 +2235,19 @@ public function set_ap_radiosettings($ap_id, $radio, $channel, $ht, $tx_power_mo 'channel' => $channel, 'ht' => $ht, 'tx_power_mode' => $tx_power_mode, - 'tx_power' => $tx_power - ] + 'tx_power' => $tx_power, + ], ]; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/upd/device/' . trim($ap_id), $payload); } /** * Assign access point to another WLAN group * - * @param string $type_id WLAN type, can be either 'ng' (for WLANs 2G (11n/b/g)) or 'na' (WLANs 5G (11n/a/ac)) - * @param string $device_id _id value of the access point to be modified - * @param string $group_id _id value of the WLAN group to assign device to - * @return bool true on success + * @param string $type_id WLAN type, can be either 'ng' (for WLANs 2G (11n/b/g)) or 'na' (WLANs 5G (11n/a/ac)) + * @param string $device_id _id value of the access point to be modified + * @param string $group_id _id value of the WLAN group to assign device to + * @return bool true on success */ public function set_ap_wlangroup($type_id, $device_id, $group_id) { @@ -2258,9 +2257,8 @@ public function set_ap_wlangroup($type_id, $device_id, $group_id) $payload = [ 'wlan_overrides' => [], - 'wlangroup_id_' . $type_id => $group_id + 'wlangroup_id_' . $type_id => $group_id, ]; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/upd/device/' . trim($device_id), $payload); } @@ -2270,16 +2268,16 @@ public function set_ap_wlangroup($type_id, $device_id, $group_id) * NOTES: * - both portal parameters are set to the same value! * - * @param bool $portal_enabled enable/disable the captive portal - * @param bool $portal_customized enable/disable captive portal customizations - * @param bool $redirect_enabled enable/disable captive portal redirect - * @param string $redirect_url url to redirect to, must include the http/https prefix, no trailing slashes - * @param string $x_password the captive portal (simple) password - * @param int $expire_number number of units for the authorization expiry - * @param int $expire_unit number of minutes within a unit (a value 60 is required for hours) - * @param string $section_id value of _id for the site settings section where key = "guest_access", settings can be obtained - * using the list_settings() function - * @return bool true on success + * @param bool $portal_enabled enable/disable the captive portal + * @param bool $portal_customized enable/disable captive portal customizations + * @param bool $redirect_enabled enable/disable captive portal redirect + * @param string $redirect_url url to redirect to, must include the http/https prefix, no trailing slashes + * @param string $x_password the captive portal (simple) password + * @param int $expire_number number of units for the authorization expiry + * @param int $expire_unit number of minutes within a unit (a value 60 is required for hours) + * @param string $section_id value of _id for the site settings section where key = "guest_access", settings + * can be obtained using the list_settings() function + * @return bool true on success */ public function set_guestlogin_settings( $portal_enabled, @@ -2299,18 +2297,20 @@ public function set_guestlogin_settings( 'x_password' => $x_password, 'expire_number' => $expire_number, 'expire_unit' => $expire_unit, - '_id' => $section_id + '_id' => $section_id, ]; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/set/setting/guest_access/' . $section_id, $payload); + return $this->fetch_results_boolean('/api/s/' . $this->site . '/set/setting/guest_access/' . $section_id, + $payload); } /** * Update guest login settings, base * - * @param object|array $payload stdClass object or associative array containing the configuration to apply to the guest login, must be a (partial) - * object/array structured in the same manner as is returned by list_settings() for the "guest_access" section. - * @return bool true on success + * @param object|array $payload stdClass object or associative array containing the configuration to apply to the + * guest login, must be a (partial) object/array structured in the same manner as is + * returned by list_settings() for the "guest_access" section. + * @return bool true on success */ public function set_guestlogin_settings_base($payload, $section_id = '') { @@ -2318,15 +2318,17 @@ public function set_guestlogin_settings_base($payload, $section_id = '') $section_id = '/' . $section_id; } - return $this->fetch_results_boolean('/api/s/' . $this->site . '/set/setting/guest_access' . $section_id, $payload); + return $this->fetch_results_boolean('/api/s/' . $this->site . '/set/setting/guest_access' . $section_id, + $payload); } /** * Update IPS/IDS settings, base * - * @param object|array $payload stdClass object or associative array containing the IPS/IDS settings to apply, must be a (partial) - * object/array structured in the same manner as is returned by list_settings() for the "ips" section. - * @return bool true on success + * @param object|array $payload stdClass object or associative array containing the IPS/IDS settings to apply, must + * be a (partial) object/array structured in the same manner as is returned by + * list_settings() for the "ips" section. + * @return bool true on success */ public function set_ips_settings_base($payload) { @@ -2336,90 +2338,93 @@ public function set_ips_settings_base($payload) /** * Update "Super Management" settings, base * - * @param string $settings_id value of _id for the site settings section where key = "super_mgmt", settings can be obtained - * using the list_settings() function - * @param object|array $payload stdClass object or associative array containing the "Super Management" settings to apply, must be a (partial) - * object/array structured in the same manner as is returned by list_settings() for the "super_mgmt" section. - * @return bool true on success + * @param string $settings_id value of _id for the site settings section where key = "super_mgmt", settings + * can be obtained using the list_settings() function + * @param object|array $payload stdClass object or associative array containing the "Super Management" settings + * to apply, must be a (partial) object/array structured in the same manner as is + * returned by list_settings() for the "super_mgmt" section. + * @return bool true on success */ public function set_super_mgmt_settings_base($settings_id, $payload) { - return $this->fetch_results_boolean('/api/s/' . $this->site . '/set/setting/super_mgmt/' . trim($settings_id), $payload); + return $this->fetch_results_boolean('/api/s/' . $this->site . '/set/setting/super_mgmt/' . trim($settings_id), + $payload); } /** * Update "Super SMTP" settings, base * - * @param string $settings_id value of _id for the site settings section where key = "super_smtp", settings can be obtained - * using the list_settings() function - * @param object|array $payload stdClass object or associative array containing the "Super SMTP" settings to apply, must be a (partial) - * object/array structured in the same manner as is returned by list_settings() for the "super_smtp" section. - * @return bool true on success + * @param string $settings_id value of _id for the site settings section where key = "super_smtp", settings + * can be obtained using the list_settings() function + * @param object|array $payload stdClass object or associative array containing the "Super SMTP" settings to + * apply, must be a (partial) object/array structured in the same manner as is + * returned by list_settings() for the "super_smtp" section. + * @return bool true on success */ public function set_super_smtp_settings_base($settings_id, $payload) { - return $this->fetch_results_boolean('/api/s/' . $this->site . '/set/setting/super_smtp/' . trim($settings_id), $payload); + return $this->fetch_results_boolean('/api/s/' . $this->site . '/set/setting/super_smtp/' . trim($settings_id), + $payload); } /** * Update "Super Controller Identity" settings, base * - * @param string $settings_id value of _id for the site settings section where key = "super_identity", settings can be obtained - * using the list_settings() function - * @param object|array $payload stdClass object or associative array containing the "Super Controller Identity" settings to apply, must be a (partial) - * object/array structured in the same manner as is returned by list_settings() for the "super_identity" section. - * @return bool true on success + * @param string $settings_id value of _id for the site settings section where key = "super_identity", + * settings can be obtained using the list_settings() function + * @param object|array $payload stdClass object or associative array containing the "Super Controller Identity" + * settings to apply, must be a (partial) object/array structured in the same + * manner as is returned by list_settings() for the "super_identity" section. + * @return bool true on success */ public function set_super_identity_settings_base($settings_id, $payload) { - return $this->fetch_results_boolean('/api/s/' . $this->site . '/set/setting/super_identity/' . trim($settings_id), $payload); + return $this->fetch_results_boolean('/api/s/' . $this->site . '/set/setting/super_identity/' . trim($settings_id), + $payload); } /** * Rename access point * - * @param string $ap_id _id of the access point to rename - * @param string $apname new name to assign to the access point - * @return bool true on success + * @param string $ap_id _id of the access point to rename + * @param string $apname new name to assign to the access point + * @return bool true on success */ public function rename_ap($ap_id, $apname) { $payload = ['name' => $apname]; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/upd/device/' . trim($ap_id), $payload); } /** * Move a device to another site * - * @param string $mac MAC address of the device to move - * @param string $site_id _id (24 char string) of the site to move the device to - * @return bool true on success + * @param string $mac MAC address of the device to move + * @param string $site_id _id (24 char string) of the site to move the device to + * @return bool true on success */ public function move_device($mac, $site_id) { $payload = ['site' => $site_id, 'mac' => strtolower($mac), 'cmd' => 'move-device']; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/sitemgr', $payload); } /** * Delete a device from the current site * - * @param string $mac MAC address of the device to delete - * @return bool true on success + * @param string $mac MAC address of the device to delete + * @return bool true on success */ public function delete_device($mac) { $payload = ['mac' => strtolower($mac), 'cmd' => 'delete-device']; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/sitemgr', $payload); } /** * Fetch dynamic DNS settings (using REST) * - * @return array containing dynamic DNS settings + * @return array containing dynamic DNS settings */ public function list_dynamicdns() { @@ -2429,9 +2434,11 @@ public function list_dynamicdns() /** * Create dynamic DNS settings, base (using REST) * - * @param object|array $payload stdClass object or associative array containing the configuration to apply to the site, must be a - * (partial) object/array structured in the same manner as is returned by list_dynamicdns() for the site. - * @return bool true on success + * @param object|array $payload stdClass object or associative array containing the configuration to apply to the + * site, must be a + * (partial) object/array structured in the same manner as is returned by + * list_dynamicdns() for the site. + * @return bool true on success */ public function create_dynamicdns($payload) { @@ -2441,22 +2448,25 @@ public function create_dynamicdns($payload) /** * Update site dynamic DNS, base (using REST) * - * @param string $dynamicdns_id _id of the settings which can be found with the list_dynamicdns() function - * @param object|array $payload stdClass object or associative array containing the configuration to apply to the site, must be a - * (partial) object/array structured in the same manner as is returned by list_dynamicdns() for the site. - * @return bool true on success + * @param string $dynamicdns_id _id of the settings which can be found with the list_dynamicdns() function + * @param object|array $payload stdClass object or associative array containing the configuration to apply to + * the site, must be a + * (partial) object/array structured in the same manner as is returned by + * list_dynamicdns() for the site. + * @return bool true on success */ public function set_dynamicdns($dynamicdns_id, $payload) { - $this->request_method = 'PUT'; - - return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/dynamicdns/' . trim($dynamicdns_id), $payload); + $this->curl_method = 'PUT'; + return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/dynamicdns/' . trim($dynamicdns_id), + $payload); } /** * Fetch network settings (using REST) - * @param string $network_id optional, _id value of the network to get settings for - * @return array containing (non-wireless) networks and their settings + * + * @param string $network_id optional, _id value of the network to get settings for + * @return array containing (non-wireless) networks and their settings */ public function list_networkconf($network_id = '') { @@ -2466,10 +2476,11 @@ public function list_networkconf($network_id = '') /** * Create a network (using REST) * - * @param object|array $payload stdClass object or associative array containing the configuration to apply to the network, must be a (partial) - * object structured in the same manner as is returned by list_networkconf() for the specific network type. - * Do not include the _id property, it is assigned by the controller and returned upon success. - * @return array|bool containing a single object with details of the new network on success, else returns false + * @param object|array $payload stdClass object or associative array containing the configuration to apply to the + * network, must be a (partial) object structured in the same manner as is returned by + * list_networkconf() for the specific network type. Do not include the _id property, + * it is assigned by the controller and returned upon success. + * @return array|bool containing a single object with details of the new network on success, else returns false */ public function create_network($payload) { @@ -2479,37 +2490,37 @@ public function create_network($payload) /** * Update network settings, base (using REST) * - * @param string $network_id the "_id" value for the network you wish to update - * @param object|array $payload stdClass object or associative array containing the configuration to apply to the network, must be a (partial) - * object/array structured in the same manner as is returned by list_networkconf() for the network. - * @return bool true on success + * @param string $network_id the "_id" value for the network you wish to update + * @param object|array $payload stdClass object or associative array containing the configuration to apply to + * the network, must be a (partial) object/array structured in the same manner as + * is returned by list_networkconf() for the network. + * @return bool true on success */ public function set_networksettings_base($network_id, $payload) { - $this->request_method = 'PUT'; - - return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/networkconf/' . trim($network_id), $payload); + $this->curl_method = 'PUT'; + return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/networkconf/' . trim($network_id), + $payload); } /** * Delete a network (using REST) * - * @param string $network_id _id value of the network which can be found with the list_networkconf() function - * @return bool true on success + * @param string $network_id _id value of the network which can be found with the list_networkconf() function + * @return bool true on success */ public function delete_network($network_id) { - $this->request_method = 'DELETE'; - + $this->curl_method = 'DELETE'; return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/networkconf/' . trim($network_id)); } /** * Fetch wlan settings (using REST) * - * @param string $wlan_id optional, _id value of the wlan to fetch the settings for - * @return array containing wireless networks and their settings, or an array containing a single wireless network when using - * the parameter + * @param string $wlan_id optional, _id value of the wlan to fetch the settings for + * @return array containing wireless networks and their settings, or an array containing a single wireless network + * when using the parameter */ public function list_wlanconf($wlan_id = null) { @@ -2519,42 +2530,43 @@ public function list_wlanconf($wlan_id = null) /** * Create a wlan * - * @param string $name SSID - * @param string $x_passphrase new pre-shared key, minimal length is 8 characters, maximum length is 63, - * assign a value of null when security = 'open' - * @param string $usergroup_id user group id that can be found using the list_usergroups() function - * @param string $wlangroup_id wlan group id that can be found using the list_wlan_groups() function - * @param boolean $enabled optional, enable/disable wlan - * @param boolean $hide_ssid optional, hide/unhide wlan SSID - * @param boolean $is_guest optional, apply guest policies or not - * @param string $security optional, security type (open, wep, wpapsk, wpaeap) - * @param string $wpa_mode optional, wpa mode (wpa, wpa2, ..) - * @param string $wpa_enc optional, encryption (auto, ccmp) - * @param boolean $vlan_enabled optional, enable/disable vlan for this wlan - * @param int $vlan optional, vlan id - * @param boolean $uapsd_enabled optional, enable/disable Unscheduled Automatic Power Save Delivery - * @param boolean $schedule_enabled optional, enable/disable wlan schedule - * @param array $schedule optional, schedule rules - * @param array $ap_group_ids optional, array of ap group ids, required for UniFi controller versions 6.0.X and higher - * @return bool true on success + * @param string $name SSID + * @param string $x_passphrase new pre-shared key, minimal length is 8 characters, maximum length is 63, + * assign a value of null when security = 'open' + * @param string $usergroup_id user group id that can be found using the list_usergroups() function + * @param string $wlangroup_id wlan group id that can be found using the list_wlan_groups() function + * @param boolean $enabled optional, enable/disable wlan + * @param boolean $hide_ssid optional, hide/unhide wlan SSID + * @param boolean $is_guest optional, apply guest policies or not + * @param string $security optional, security type (open, wep, wpapsk, wpaeap) + * @param string $wpa_mode optional, wpa mode (wpa, wpa2, ..) + * @param string $wpa_enc optional, encryption (auto, ccmp) + * @param boolean $vlan_enabled optional, enable/disable vlan for this wlan + * @param int $vlan optional, vlan id + * @param boolean $uapsd_enabled optional, enable/disable Unscheduled Automatic Power Save Delivery + * @param boolean $schedule_enabled optional, enable/disable wlan schedule + * @param array $schedule optional, schedule rules + * @param array $ap_group_ids optional, array of ap group ids, required for UniFi controller versions 6.0.X + * and higher + * @return bool true on success */ public function create_wlan( $name, $x_passphrase, $usergroup_id, $wlangroup_id, - $enabled = true, - $hide_ssid = false, - $is_guest = false, - $security = 'open', - $wpa_mode = 'wpa2', - $wpa_enc = 'ccmp', - $vlan_enabled = false, - $vlan = null, - $uapsd_enabled = false, + $enabled = true, + $hide_ssid = false, + $is_guest = false, + $security = 'open', + $wpa_mode = 'wpa2', + $wpa_enc = 'ccmp', + $vlan_enabled = false, + $vlan = null, + $uapsd_enabled = false, $schedule_enabled = false, - $schedule = [], - $ap_group_ids = null + $schedule = [], + $ap_group_ids = null ) { $payload = [ 'name' => $name, @@ -2590,15 +2602,16 @@ public function create_wlan( /** * Update wlan settings, base (using REST) * - * @param string $wlan_id the "_id" value for the WLAN which can be found with the list_wlanconf() function - * @param object|array $payload stdClass object or associative array containing the configuration to apply to the wlan, must be a - * (partial) object/array structured in the same manner as is returned by list_wlanconf() for the wlan. - * @return bool true on success + * @param string $wlan_id the "_id" value for the WLAN which can be found with the list_wlanconf() function + * @param object|array $payload stdClass object or associative array containing the configuration to apply to the + * wlan, must be a + * (partial) object/array structured in the same manner as is returned by + * list_wlanconf() for the wlan. + * @return bool true on success */ public function set_wlansettings_base($wlan_id, $payload) { - $this->request_method = 'PUT'; - + $this->curl_method = 'PUT'; return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/wlanconf/' . trim($wlan_id), $payload); } @@ -2609,11 +2622,11 @@ public function set_wlansettings_base($wlan_id, $payload) * @param string $x_passphrase new pre-shared key, minimal length is 8 characters, maximum length is 63, * is ignored if set to null * @param string $name optional, SSID - * @return bool true on success + * @return bool true on success */ public function set_wlansettings($wlan_id, $x_passphrase, $name = null) { - $payload = []; + $payload = []; $payload['x_passphrase'] = trim($x_passphrase); if (!empty($name)) { @@ -2626,9 +2639,9 @@ public function set_wlansettings($wlan_id, $x_passphrase, $name = null) /** * Disable/Enable wlan * - * @param string $wlan_id the "_id" value for the WLAN which can be found with the list_wlanconf() function - * @param bool $disable true disables the wlan, false enables it - * @return bool true on success + * @param string $wlan_id the "_id" value for the WLAN which can be found with the list_wlanconf() function + * @param bool $disable true disables the wlan, false enables it + * @return bool true on success */ public function disable_wlan($wlan_id, $disable) { @@ -2636,35 +2649,34 @@ public function disable_wlan($wlan_id, $disable) return false; } - $action = $disable ? false : true; + $action = !$disable; $payload = ['enabled' => $action]; - return $this->set_wlansettings_base($wlan_id, $payload); } /** * Delete a wlan (using REST) * - * @param string $wlan_id the "_id" value for the WLAN which can be found with the list_wlanconf() function - * @return bool true on success + * @param string $wlan_id the "_id" value for the WLAN which can be found with the list_wlanconf() function + * @return bool true on success */ public function delete_wlan($wlan_id) { - $this->request_method = 'DELETE'; - + $this->curl_method = 'DELETE'; return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/wlanconf/' . trim($wlan_id)); } /** * Update MAC filter for a wlan * - * @param string $wlan_id the "_id" value for the WLAN which can be found with the list_wlanconf() function - * @param string $mac_filter_policy string, "allow" or "deny"; default MAC policy to apply - * @param bool $mac_filter_enabled true enables the policy, false disables it - * @param array $macs must contain valid MAC strings to be placed in the MAC filter list, - * replacing existing values. Existing MAC filter list can be obtained - * through list_wlanconf(). - * @return bool true on success + * @param string $wlan_id the "_id" value for the WLAN which can be found with the list_wlanconf() + * function + * @param string $mac_filter_policy string, "allow" or "deny"; default MAC policy to apply + * @param bool $mac_filter_enabled true enables the policy, false disables it + * @param array $macs must contain valid MAC strings to be placed in the MAC filter list, + * replacing existing values. Existing MAC filter list can be obtained + * through list_wlanconf(). + * @return bool true on success */ public function set_wlan_mac_filter($wlan_id, $mac_filter_policy, $mac_filter_enabled, array $macs) { @@ -2678,9 +2690,9 @@ public function set_wlan_mac_filter($wlan_id, $mac_filter_policy, $mac_filter_en $macs = array_map('strtolower', $macs); $payload = [ - 'mac_filter_enabled' => (bool) $mac_filter_enabled, + 'mac_filter_enabled' => (bool)$mac_filter_enabled, 'mac_filter_policy' => $mac_filter_policy, - 'mac_filter_list' => $macs + 'mac_filter_list' => $macs, ]; return $this->set_wlansettings_base($wlan_id, $payload); @@ -2689,10 +2701,11 @@ public function set_wlan_mac_filter($wlan_id, $mac_filter_policy, $mac_filter_en /** * Fetch events * - * @param integer $historyhours optional, hours to go back, default value is 720 hours - * @param integer $start optional, which event number to start with (useful for paging of results), default value is 0 - * @param integer $limit optional, number of events to return, default value is 3000 - * @return array containing known events + * @param integer $historyhours optional, hours to go back, default value is 720 hours + * @param integer $start optional, which event number to start with (useful for paging of results), default + * value is 0 + * @param integer $limit optional, number of events to return, default value is 3000 + * @return array containing known events */ public function list_events($historyhours = 720, $start = 0, $limit = 3000) { @@ -2701,19 +2714,18 @@ public function list_events($historyhours = 720, $start = 0, $limit = 3000) 'within' => intval($historyhours), 'type' => null, '_start' => intval($start), - '_limit' => intval($limit) + '_limit' => intval($limit), ]; - return $this->fetch_results('/api/s/' . $this->site . '/stat/event', $payload); } /** * Fetch alarms * - * @param array $payload optional, array of flags to filter by - * Example: ["archived" => false, "key" => "EVT_GW_WANTransition"] - * return only unarchived for a specific key - * @return array containing known alarms + * @param array $payload optional, array of flags to filter by + * Example: ["archived" => false, "key" => "EVT_GW_WANTransition"] + * return only unarchived for a specific key + * @return array containing known alarms */ public function list_alarms($payload = []) { @@ -2723,23 +2735,22 @@ public function list_alarms($payload = []) /** * Count alarms * - * @param bool $archived optional, if true all alarms are counted, if false only non-archived (active) alarms are counted, - * by default all alarms are counted - * @return array containing the alarm count + * @param bool $archived optional, if true all alarms are counted, if false only non-archived (active) alarms are + * counted, by default all alarms are counted + * @return array containing the alarm count */ public function count_alarms($archived = null) { $path_suffix = $archived === false ? '?archived=false' : null; - return $this->fetch_results('/api/s/' . $this->site . '/cnt/alarm' . $path_suffix); } /** * Archive alarms(s) * - * @param string $alarm_id optional, _id of the alarm to archive which can be found with the list_alarms() function, - * by default all alarms are archived - * @return bool true on success + * @param string $alarm_id optional, _id of the alarm to archive which can be found with the list_alarms() function, + * by default all alarms are archived + * @return bool true on success */ public function archive_alarm($alarm_id = null) { @@ -2757,8 +2768,8 @@ public function archive_alarm($alarm_id = null) * NOTE: * triggers an update of the controller cached known latest version. * - * @return array|bool returns an array with a single object containing details of the current known latest controller version info - * on success, else returns false + * @return array|bool returns an array with a single object containing details of the current known latest + * controller version info on success, else returns false */ public function check_controller_update() { @@ -2776,7 +2787,6 @@ public function check_controller_update() public function check_firmware_update() { $payload = ['cmd' => 'check-firmware-update']; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/productinfo', $payload); } @@ -2786,13 +2796,12 @@ public function check_firmware_update() * NOTES: * - updates the device to the latest STABLE firmware known to the controller * - * @param string $device_mac MAC address of the device to upgrade - * @return bool returns true upon success + * @param string $device_mac MAC address of the device to upgrade + * @return bool returns true upon success */ public function upgrade_device($device_mac) { $payload = ['mac' => strtolower($device_mac)]; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/devmgr/upgrade', $payload); } @@ -2803,14 +2812,13 @@ public function upgrade_device($device_mac) * - updates the device to the firmware file at the given URL * - please take great care to select a valid firmware file for the device! * - * @param string $firmware_url URL for the firmware file to upgrade the device to - * @param string $device_mac MAC address of the device to upgrade - * @return bool returns true upon success + * @param string $firmware_url URL for the firmware file to upgrade the device to + * @param string $device_mac MAC address of the device to upgrade + * @return bool returns true upon success */ public function upgrade_device_external($firmware_url, $device_mac) { $payload = ['url' => filter_var($firmware_url, FILTER_SANITIZE_URL), 'mac' => strtolower($device_mac)]; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/devmgr/upgrade-external', $payload); } @@ -2826,7 +2834,6 @@ public function upgrade_device_external($firmware_url, $device_mac) public function start_rolling_upgrade() { $payload = ['cmd' => 'set-rollupgrade']; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/devmgr', $payload); } @@ -2838,16 +2845,15 @@ public function start_rolling_upgrade() public function cancel_rolling_upgrade() { $payload = ['cmd' => 'unset-rollupgrade']; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/devmgr', $payload); } /** * Fetch firmware versions * - * @param string $type optional, "available" or "cached", determines which firmware types to return, - * default value is "available" - * @return array containing firmware versions + * @param string $type optional, "available" or "cached", determines which firmware types to return, + * default value is "available" + * @return array|false containing firmware versions */ public function list_firmware($type = 'available') { @@ -2856,7 +2862,6 @@ public function list_firmware($type = 'available') } $payload = ['cmd' => 'list-' . $type]; - return $this->fetch_results('/api/s/' . $this->site . '/cmd/firmware', $payload); } @@ -2867,35 +2872,34 @@ public function list_firmware($type = 'available') * - only applies to switches and their PoE ports... * - port must be actually providing power * - * @param string $switch_mac main MAC address of the switch - * @param int $port_idx port number/index of the port to be affected - * @return bool returns true upon success + * @param string $switch_mac main MAC address of the switch + * @param int $port_idx port number/index of the port to be affected + * @return bool returns true upon success */ public function power_cycle_switch_port($switch_mac, $port_idx) { $payload = ['mac' => strtolower($switch_mac), 'port_idx' => intval($port_idx), 'cmd' => 'power-cycle']; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/devmgr', $payload); } /** * Trigger an RF scan by an AP * - * @param string $ap_mac MAC address of the AP - * @return bool returns true upon success + * @param string $ap_mac MAC address of the AP + * @return bool returns true upon success */ public function spectrum_scan($ap_mac) { $payload = ['cmd' => 'spectrum-scan', 'mac' => strtolower($ap_mac)]; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/devmgr', $payload); } /** * Check the RF scanning state of an AP * - * @param string $ap_mac MAC address of the AP - * @return object containing relevant information (results if available) regarding the RF scanning state of the AP + * @param string $ap_mac MAC address of the AP + * @return array|bool containing relevant information (results if available) regarding the RF scanning state of the + * AP */ public function spectrum_scan_state($ap_mac) { @@ -2905,15 +2909,16 @@ public function spectrum_scan_state($ap_mac) /** * Update device settings, base (using REST) * - * @param string $device_id _id of the device which can be found with the list_devices() function - * @param object|array $payload stdClass object or associative array containing the configuration to apply to the device, must be a - * (partial) object/array structured in the same manner as is returned by list_devices() for the device. - * @return bool true on success + * @param string $device_id _id of the device which can be found with the list_devices() function + * @param object|array $payload stdClass object or associative array containing the configuration to apply to the + * device, must be a + * (partial) object/array structured in the same manner as is returned by + * list_devices() for the device. + * @return bool true on success */ public function set_device_settings_base($device_id, $payload) { - $this->request_method = 'PUT'; - + $this->curl_method = 'PUT'; return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/device/' . trim($device_id), $payload); } @@ -2951,7 +2956,7 @@ public function list_radius_accounts() * * @param string $name name for the new account * @param string $x_password password for the new account - * @param int $tunnel_type must be one of the following values: + * @param int $tunnel_type optional, must be one of the following values: * 1 Point-to-Point Tunneling Protocol (PPTP) * 2 Layer Two Forwarding (L2F) * 3 Layer Two Tunneling Protocol (L2TP) @@ -2965,7 +2970,7 @@ public function list_radius_accounts() * 11 Bay Dial Virtual Services (DVS) * 12 IP-in-IP Tunneling * 13 Virtual LANs (VLAN) - * @param int $tunnel_medium_type must be one of the following values: + * @param int $tunnel_medium_type optional, must be one of the following values: * 1 IPv4 (IP version 4) * 2 IPv6 (IP version 6) * 3 NSAP @@ -2982,25 +2987,31 @@ public function list_radius_accounts() * 14 Banyan Vines * 15 E.164 with NSAP format subaddress * @param int $vlan optional, VLAN to assign to the account - * @return array containing a single object for the newly created account upon success, else returns false + * @return bool|array containing a single object for the newly created account upon success, else returns false */ - public function create_radius_account($name, $x_password, $tunnel_type, $tunnel_medium_type, $vlan = null) + public function create_radius_account($name, $x_password, $tunnel_type = null, $tunnel_medium_type = null, $vlan = null) { $tunnel_types = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; $tunnel_medium_types = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; - if (!in_array($tunnel_type, $tunnel_types) || !in_array($tunnel_medium_type, $tunnel_medium_types)) { + if ((!is_null($tunnel_type) && !in_array($tunnel_type, $tunnel_types)) || (!is_null($tunnel_medium_type) && !in_array($tunnel_medium_type, $tunnel_medium_types)) || ($tunnel_type ^ $tunnel_medium_type)) { return false; } $payload = [ - 'name' => $name, - 'x_password' => $x_password, - 'tunnel_type' => (int) $tunnel_type, - 'tunnel_medium_type' => (int) $tunnel_medium_type + 'name' => $name, + 'x_password' => $x_password, ]; + if (!is_null($tunnel_type)) { + $payload['tunnel_type'] = (int)$tunnel_type; + } + + if (!is_null($tunnel_medium_type)) { + $payload['tunnel_medium_type'] = (int)$tunnel_medium_type; + } + if (!is_null($vlan)) { - $payload['vlan'] = (int) $vlan; + $payload['vlan'] = (int)$vlan; } return $this->fetch_results('/api/s/' . $this->site . '/rest/account', $payload); @@ -3012,15 +3023,15 @@ public function create_radius_account($name, $x_password, $tunnel_type, $tunnel_ * NOTES: * - this function/method is only supported on controller versions 5.5.19 and later * - * @param string $account_id _id of the account which can be found with the list_radius_accounts() function - * @param object|array $payload stdClass object or associative array containing the new profile to apply to the account, must be a (partial) - * object/array structured in the same manner as is returned by list_radius_accounts() for the account. - * @return bool true on success + * @param string $account_id _id of the account which can be found with the list_radius_accounts() function + * @param object|array $payload stdClass object or associative array containing the new profile to apply to the + * account, must be a (partial) object/array structured in the same manner as is + * returned by list_radius_accounts() for the account. + * @return bool true on success */ public function set_radius_account_base($account_id, $payload) { - $this->request_method = 'PUT'; - + $this->curl_method = 'PUT'; return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/account/' . trim($account_id), $payload); } @@ -3030,39 +3041,38 @@ public function set_radius_account_base($account_id, $payload) * NOTES: * - this function/method is only supported on controller versions 5.5.19 and later * - * @param string $account_id _id of the account which can be found with the list_radius_accounts() function - * @return bool true on success + * @param string $account_id _id of the account which can be found with the list_radius_accounts() function + * @return bool true on success */ public function delete_radius_account($account_id) { - $this->request_method = 'DELETE'; - + $this->curl_method = 'DELETE'; return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/account/' . trim($account_id)); } /** * Execute specific stats command * - * @param string $command command to execute, known valid values: - * 'reset-dpi', resets all DPI counters for the current site - * @return bool true on success + * @param string $command command to execute, known valid values: + * 'reset-dpi', resets all DPI counters for the current site, + * to be extended in the future + * @return bool true on success */ public function cmd_stat($command) { - if (!in_array($command, ['reset-dpi'])) { + if ($command != 'reset-dpi') { return false; } $payload = ['cmd' => trim($command)]; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/cmd/stat', $payload); } /** * Toggle Element Adoption ON or OFF * - * @param bool $enable true enables Element Adoption, false disables Element Adoption - * @return bool true on success + * @param bool $enable true enables Element Adoption, false disables Element Adoption + * @return bool true on success */ public function set_element_adoption($enable) { @@ -3071,7 +3081,6 @@ public function set_element_adoption($enable) } $payload = ['enabled' => $enable]; - return $this->fetch_results_boolean('/api/s/' . $this->site . '/set/setting/element_adopt', $payload); } @@ -3086,7 +3095,7 @@ public function set_element_adoption($enable) */ public function list_device_states() { - $device_states = [ + return [ 0 => 'offline', 1 => 'connected', 2 => 'pending adoption', @@ -3095,28 +3104,30 @@ public function list_device_states() 6 => 'unreachable', 7 => 'adopting', 9 => 'adoption error', - 11 => 'isolated' + 10 => 'adoption failed', + 11 => 'isolated', ]; - - return $device_states; } /** * Custom API request * * NOTE: - * Only use this method when you fully understand the behavior of the UniFi controller API. No input validation is performed, to be used with care! + * Only use this method when you fully understand the behavior of the UniFi controller API. No input validation is + * performed, to be used with care! * - * @param string $path suffix of the URL (following the port number) to pass request to, *must* start with a "/" character - * @param string $request_method optional, HTTP request type, can be GET (default), POST, PUT, PATCH, or DELETE - * @param object|array $payload optional, stdClass object or associative array containing the payload to pass - * @param string $return optional, string; determines how to return results, when "boolean" the method must return a - * boolean result (true/false) or "array" when the method must return an array - * @return bool|array returns results as requested, returns false on incorrect parameters + * @param string $path suffix of the URL (following the port number) to pass request to, *must* start with + * a "/" character + * @param string $method optional, HTTP request type, can be GET (default), POST, PUT, PATCH, or DELETE + * @param object|array $payload optional, stdClass object or associative array containing the payload to pass + * @param string $return optional, string; determines how to return results, when "boolean" the method must + * return a boolean result (true/false) or "array" when the method must return an + * array + * @return bool|array returns results as requested, returns false on incorrect parameters */ - public function custom_api_request($path, $request_method = 'GET', $payload = null, $return = 'array') + public function custom_api_request($path, $method = 'GET', $payload = null, $return = 'array') { - if (!in_array($request_method, $this->request_methods_allowed)) { + if (!in_array($method, $this->curl_methods_allowed)) { return false; } @@ -3124,7 +3135,7 @@ public function custom_api_request($path, $request_method = 'GET', $payload = nu return false; } - $this->request_method = $request_method; + $this->curl_method = $method; if ($return === 'array') { return $this->fetch_results($path, $payload); @@ -3146,8 +3157,8 @@ public function custom_api_request($path, $request_method = 'GET', $payload = nu * NOTE: * changed function/method name to fit it's purpose * - * @param string $device_mac optional, the MAC address of a single device for which the call must be made - * @return array containing known device objects (or a single device when using the parameter) + * @param string $device_mac optional, the MAC address of a single device for which the call must be made + * @return array containing known device objects (or a single device when using the parameter) */ public function list_aps($device_mac = null) { @@ -3162,8 +3173,8 @@ public function list_aps($device_mac = null) /** * Start flashing LED of an access point for locating purposes * - * @param string $mac device MAC address - * @return bool true on success + * @param string $mac device MAC address + * @return bool true on success */ public function set_locate_ap($mac) { @@ -3178,8 +3189,8 @@ public function set_locate_ap($mac) /** * Stop flashing LED of an access point for locating purposes * - * @param string $mac device MAC address - * @return bool true on success + * @param string $mac device MAC address + * @return bool true on success */ public function unset_locate_ap($mac) { @@ -3224,8 +3235,8 @@ public function site_ledsoff() /** * Reboot an access point * - * @param string $mac device MAC address - * @return bool true on success + * @param string $mac device MAC address + * @return bool true on success */ public function restart_ap($mac) { @@ -3247,15 +3258,14 @@ public function restart_ap($mac) * NOTE: * this method is useful to switch between sites * - * @param string $site string; must be the short site name of a site to which the - * provided credentials have access - * @return string the new (short) site name + * @param string $site must be the short site name of a site to which the + * provided credentials have access + * @return string the new (short) site name */ public function set_site($site) { $this->check_site($site); $this->site = trim($site); - return $this->site; } @@ -3272,14 +3282,13 @@ public function get_site() /** * Set debug mode * - * @param bool $enable true enables debug mode, false disables debug mode - * @return bool false when a non-boolean parameter was passed + * @param bool $enable true enables debug mode, false disables debug mode + * @return bool false when a non-boolean parameter was passed */ public function set_debug($enable) { if ($enable === true || $enable === false) { $this->debug = $enable; - return true; } @@ -3301,9 +3310,9 @@ public function get_debug() /** * Get last raw results * - * @param boolean $return_json true returns the results in "pretty printed" json format, - * false returns PHP stdClass Object format (default) - * @return object|string the raw results as returned by the controller API + * @param boolean $return_json true returns the results in "pretty printed" json format, + * false returns PHP stdClass Object format (default) + * @return object|string the raw results as returned by the controller API */ public function get_last_results_raw($return_json = false) { @@ -3321,7 +3330,8 @@ public function get_last_results_raw($return_json = false) /** * Get last error message * - * @return object|bool the error message of the last method called in PHP stdClass Object format, returns false if unavailable + * @return object|bool the error message of the last method called in PHP stdClass Object format, returns false if + * unavailable */ public function get_last_error_message() { @@ -3363,7 +3373,7 @@ public function get_cookies() */ public function get_class_version() { - return $this->class_version; + return self::CLASS_VERSION; } /** @@ -3381,25 +3391,25 @@ public function set_cookies($cookies_value) * * @return string request type */ - public function get_request_method() + public function get_curl_method() { - return $this->request_method; + return $this->curl_method; } /** * Set request method * - * @param string $request_method a valid HTTP request method - * @return bool whether request was successful or not + * @param string $curl_method a valid HTTP request method + * @return bool whether request was successful or not */ - public function set_request_method($request_method) + public function set_curl_method($curl_method) { - if (!in_array($request_method, $this->request_methods_allowed)) { + if (!in_array($curl_method, $this->curl_methods_allowed)) { return false; } - $this->request_method = $request_method; + $this->curl_method = $curl_method; return true; } @@ -3409,9 +3419,9 @@ public function set_request_method($request_method) * * https://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYPEER.html * - * @return bool value of private property $curl_ssl_verify_peer (cURL option CURLOPT_SSL_VERIFYPEER) + * @return bool value of private property $ssl_verify_peer (cURL option CURLOPT_SSL_VERIFYPEER) */ - public function get_ssl_verify_peer() + public function get_curl_ssl_verify_peer() { return $this->curl_ssl_verify_peer; } @@ -3421,15 +3431,15 @@ public function get_ssl_verify_peer() * * https://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYPEER.html * - * @param int|bool $ssl_verify_peer should be 0/false or 1/true + * @param int|bool $curl_ssl_verify_peer should be 0/false or 1/true */ - public function set_ssl_verify_peer($ssl_verify_peer) + public function set_curl_ssl_verify_peer($curl_ssl_verify_peer) { - if (!in_array($ssl_verify_peer, [0, false, 1, true])) { + if (!in_array($curl_ssl_verify_peer, [0, false, 1, true])) { return false; } - $this->curl_ssl_verify_peer = $ssl_verify_peer; + $this->curl_ssl_verify_peer = $curl_ssl_verify_peer; return true; } @@ -3439,9 +3449,9 @@ public function set_ssl_verify_peer($ssl_verify_peer) * * https://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYHOST.html * - * @return bool value of private property $curl_ssl_verify_peer (cURL option CURLOPT_SSL_VERIFYHOST) + * @return bool value of private property $ssl_verify_peer (cURL option CURLOPT_SSL_VERIFYHOST) */ - public function get_ssl_verify_host() + public function get_curl_ssl_verify_host() { return $this->curl_ssl_verify_host; } @@ -3451,15 +3461,15 @@ public function get_ssl_verify_host() * * https://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYHOST.html * - * @param int|bool $ssl_verify_host should be 0/false or 2 + * @param int|bool $curl_ssl_verify_host should be 0/false or 2 */ - public function set_ssl_verify_host($ssl_verify_host) + public function set_curl_ssl_verify_host($curl_ssl_verify_host) { - if (!in_array($ssl_verify_host, [0, false, 2])) { + if (!in_array($curl_ssl_verify_host, [0, false, 2])) { return false; } - $this->curl_ssl_verify_host = $ssl_verify_host; + $this->curl_ssl_verify_host = $curl_ssl_verify_host; return true; } @@ -3477,8 +3487,8 @@ public function get_is_unifi_os() /** * Set value for private property $is_unifi_os * - * @param bool|int $is_unifi_os new value, must be 0, 1, true or false - * @return bool whether request was successful or not + * @param bool|int $is_unifi_os new value, must be 0, 1, true or false + * @return bool whether request was successful or not */ public function set_is_unifi_os($is_unifi_os) { @@ -3498,17 +3508,64 @@ public function set_is_unifi_os($is_unifi_os) */ public function set_connection_timeout($timeout) { - $this->connect_timeout = $timeout; + $this->curl_connect_timeout = $timeout; } /** * Get current value of the private property $connect_timeout * - * @return int current value if $connect_timeout + * @return int current value of $connect_timeout */ public function get_connection_timeout() { - return $this->connect_timeout; + return $this->curl_connect_timeout; + } + + /** + * Set value for the private property $request_timeout + * + * @param int $timeout new value for $request_timeout in seconds + */ + public function set_curl_request_timeout($timeout) + { + $this->curl_request_timeout = $timeout; + } + + /** + * Get current value of the private property $request_timeout + * + * @return int current value of $request_timeout + */ + public function get_curl_request_timeout() + { + return $this->curl_request_timeout; + } + + /** + * Set value for the private property $curl_http_version + * + * NOTES: + * - as of cURL version 7.62.0 the default value is CURL_HTTP_VERSION_2TLS which may cause issues + * - the default value used in this class is CURL_HTTP_VERSION_1_1 + * - https://curl.se/libcurl/c/CURLOPT_HTTP_VERSION.html + * + * @param int $http_version new value for $curl_http_version, can be CURL_HTTP_VERSION_1_1 int(2) + * or CURL_HTTP_VERSION_2TLS int(4) + */ + public function set_curl_http_version($http_version) + { + $this->curl_http_version = $http_version; + } + + /** + * Get current value of the private property $curl_http_version + * + * @return int current value of $request_timeout, can be CURL_HTTP_VERSION_1_1 int(2) or + * CURL_HTTP_VERSION_2TLS int(4) + */ + public function get_curl_http_version() + { + return $this->curl_http_version; } /**************************************************************** @@ -3520,12 +3577,13 @@ public function get_connection_timeout() * * execute the cURL request and return results * - * @param string $path request path - * @param object|array $payload optional, PHP associative array or stdClass Object, payload to pass with the request - * @param boolean $boolean optional, whether the method should return a boolean result, else return - * the "data" array - * @param boolean $login_required optional, whether the method requires to be logged in or not - * @return bool|array [description] + * @param string $path request path + * @param object|array $payload optional, PHP associative array or stdClass Object, payload to pass with the + * request + * @param boolean $boolean optional, whether the method should return a boolean result, else return + * the "data" array + * @param boolean $login_required optional, whether the method requires to be logged in or not + * @return bool|array [description] */ protected function fetch_results($path, $payload = null, $boolean = false, $login_required = true) { @@ -3575,9 +3633,11 @@ protected function fetch_results($path, $payload = null, $boolean = false, $logi trigger_error('Debug: Last error message: ' . $this->last_error_message); } } - } else { - return $response; + + return false; } + + return $response; } } @@ -3589,10 +3649,11 @@ protected function fetch_results($path, $payload = null, $boolean = false, $logi * * execute the cURL request and return a boolean value * - * @param string $path request path - * @param object|array $payload optional, PHP associative array or stdClass Object, payload to pass with the request - * @param bool $login_required optional, whether the method requires to be logged in or not - * @return bool [description] + * @param string $path request path + * @param object|array $payload optional, PHP associative array or stdClass Object, payload to pass with the + * request + * @param bool $login_required optional, whether the method requires to be logged in or not + * @return bool [description] */ protected function fetch_results_boolean($path, $payload = null, $login_required = true) { @@ -3607,6 +3668,7 @@ protected function fetch_results_boolean($path, $payload = null, $login_required protected function catch_json_last_error() { if ($this->debug) { + $error = 'Unknown JSON error occurred'; switch (json_last_error()) { case JSON_ERROR_NONE: // JSON is valid, no error has occurred and return true early @@ -3638,18 +3700,20 @@ protected function catch_json_last_error() case JSON_ERROR_UNSUPPORTED_TYPE: $error = 'A value of a type that cannot be encoded was given'; break; - case JSON_ERROR_INVALID_PROPERTY_NAME: - // PHP >= 7.0.0 - $error = 'A property name that cannot be encoded was given'; - break; - case JSON_ERROR_UTF16: - // PHP >= 7.0.0 - $error = 'Malformed UTF-16 characters, possibly incorrectly encoded'; - break; - default: - // an unknown error occurred - $error = 'Unknown JSON error occurred'; - break; + } + + /** + * check whether we have PHP >= 7.0.0 + */ + if (defined('JSON_ERROR_INVALID_PROPERTY_NAME') && defined('JSON_ERROR_UTF16')) { + switch (json_last_error()) { + case JSON_ERROR_INVALID_PROPERTY_NAME: + $error = 'A property name that cannot be encoded was given'; + break; + case JSON_ERROR_UTF16: + $error = 'Malformed UTF-16 characters, possibly incorrectly encoded'; + break; + } } trigger_error('JSON decode error: ' . $error); @@ -3663,14 +3727,13 @@ protected function catch_json_last_error() /** * Validate the submitted base URL * - * @param string $baseurl the base URL to validate - * @return bool true if base URL is a valid URL, else returns false + * @param string $baseurl the base URL to validate + * @return bool true if base URL is a valid URL, else returns false */ protected function check_base_url($baseurl) { if (!filter_var($baseurl, FILTER_VALIDATE_URL) || substr($baseurl, -1) === '/') { trigger_error('The URL provided is incomplete, invalid or ends with a / character!'); - return false; } @@ -3680,14 +3743,13 @@ protected function check_base_url($baseurl) /** * Check the (short) site name * - * @param string $site the (short) site name to check - * @return bool true if (short) site name is valid, else returns false + * @param string $site the (short) site name to check + * @return bool true if (short) site name is valid, else returns false */ protected function check_site($site) { if ($this->debug && preg_match("/\s/", $site)) { trigger_error('The provided (short) site name may not contain any spaces'); - return false; } @@ -3718,43 +3780,36 @@ protected function update_unificookie() } /** - * Add a cURL header containing the CSRF token from our Cookie string + * Add a cURL header containing the CSRF token from the TOKEN in our Cookie string * - * @return bool true upon success or false when unable to extract the CSRF token + * @return void */ protected function create_x_csrf_token_header() { if (!empty($this->cookies) && strpos($this->cookies, 'TOKEN') !== false) { $cookie_bits = explode('=', $this->cookies); - if (!empty($cookie_bits) && array_key_exists(1, $cookie_bits)) { - $jwt = $cookie_bits[1]; - } else { - return false; + if (empty($cookie_bits) || !array_key_exists(1, $cookie_bits)) { + return; } - $jwt_components = explode('.', $jwt); - if (!empty($jwt_components) && array_key_exists(1, $jwt_components)) { - $jwt_payload = $jwt_components[1]; - } else { - return false; + $jwt_components = explode('.', $cookie_bits[1]); + if (empty($jwt_components) || !array_key_exists(1, $jwt_components)) { + return; } - $this->headers[] = 'x-csrf-token: ' . json_decode(base64_decode($jwt_payload))->csrfToken; - - return true; + $this->curl_headers[] = 'x-csrf-token: ' . json_decode(base64_decode($jwt_components[1]))->csrfToken; } - - return false; } /** * Callback function for cURL to extract and store cookies as needed * - * @param object|resource $ch the cURL instance - * @param int $header_line the response header line number - * @return int length of the header line + * @param object|resource $ch the cURL instance + * @param int $header_line the response header line number + * @return int length of the header line */ - protected function response_header_callback($ch, $header_line) { + protected function response_header_callback($ch, $header_line) + { if (strpos($header_line, 'unifises') !== false || strpos($header_line, 'TOKEN') !== false) { $cookie = trim(str_replace(['set-cookie: ', 'Set-Cookie: '], '', $header_line)); @@ -3786,41 +3841,37 @@ protected function response_header_callback($ch, $header_line) { /** * Execute the cURL request * - * @param string $path path for the request - * @param object|array $payload optional, payload to pass with the request - * @return bool|array|string response returned by the controller API, false upon error + * @param string $path path for the request + * @param object|array $payload optional, payload to pass with the request + * @return bool|array|string response returned by the controller API, false upon error */ protected function exec_curl($path, $payload = null) { - if (!in_array($this->request_method, $this->request_methods_allowed)) { - trigger_error('an invalid HTTP request type was used: ' . $this->request_method); + if (!in_array($this->curl_method, $this->curl_methods_allowed)) { + trigger_error('an invalid HTTP request type was used: ' . $this->curl_method); + return false; } - if (!($ch = $this->get_curl_resource())) { - trigger_error('get_curl_resource() did not return a resource'); - + if (!($ch = $this->get_curl_handle())) { + trigger_error('get_curl_handle() did not return a resource'); return false; } - $this->headers = []; + $this->curl_headers = []; + $url = $this->baseurl . $path; if ($this->is_unifi_os) { $url = $this->baseurl . '/proxy/network' . $path; - } else { - $url = $this->baseurl . $path; } - /** - * prepare cURL options - */ $curl_options = [ - CURLOPT_URL => $url + CURLOPT_URL => $url, ]; /** * when a payload is passed */ - $json_payload = ''; + $json_payload = ''; if (!empty($payload)) { $json_payload = json_encode($payload, JSON_UNESCAPED_SLASHES); $curl_options[CURLOPT_POSTFIELDS] = $json_payload; @@ -3828,21 +3879,21 @@ protected function exec_curl($path, $payload = null) /** * add empty Expect header to prevent cURL from injecting an "Expect: 100-continue" header */ - $this->headers = [ + $this->curl_headers = [ 'content-type: application/json', - 'Expect:' + 'Expect:', ]; /** * should not use GET (the default request type) or DELETE when passing a payload, * switch to POST instead */ - if ($this->request_method === 'GET' || $this->request_method === 'DELETE') { - $this->request_method = 'POST'; + if ($this->curl_method === 'GET' || $this->curl_method === 'DELETE') { + $this->curl_method = 'POST'; } } - switch ($this->request_method) { + switch ($this->curl_method) { case 'POST': $curl_options[CURLOPT_POST] = true; break; @@ -3857,12 +3908,12 @@ protected function exec_curl($path, $payload = null) break; } - if ($this->is_unifi_os && $this->request_method !== 'GET') { + if ($this->is_unifi_os && $this->curl_method !== 'GET') { $this->create_x_csrf_token_header(); } - if (count($this->headers) > 0) { - $curl_options[CURLOPT_HTTPHEADER] = $this->headers; + if (count($this->curl_headers) > 0) { + $curl_options[CURLOPT_HTTPHEADER] = $this->curl_headers; } curl_setopt_array($ch, $curl_options); @@ -3934,10 +3985,9 @@ protected function exec_curl($path, $payload = null) print $url . PHP_EOL; if (empty($json_payload)) { print 'empty payload'; - } else { - print $json_payload; } + print $json_payload; print PHP_EOL . '----------RESPONSE-----------' . PHP_EOL; print $response; print PHP_EOL . '-----------------------------' . PHP_EOL; @@ -3947,27 +3997,28 @@ protected function exec_curl($path, $payload = null) curl_close($ch); /** - * set request_method value back to default, just in case + * set method back to default value, just in case */ - $this->request_method = 'GET'; - + $this->curl_method = 'GET'; return $response; } /** - * Create a new cURL resource and return a cURL handle + * Create and return a new cURL handle * - * @return object|bool|resource cURL handle upon success, false upon failure + * @return object|bool|resource cURL handle (object or resource) upon success, false upon failure */ - protected function get_curl_resource() + protected function get_curl_handle() { $ch = curl_init(); if (is_object($ch) || is_resource($ch)) { $curl_options = [ - CURLOPT_PROTOCOLS => CURLPROTO_HTTPS | CURLPROTO_HTTP, + CURLOPT_PROTOCOLS => CURLPROTO_HTTPS, + CURLOPT_HTTP_VERSION => $this->curl_http_version, CURLOPT_SSL_VERIFYPEER => $this->curl_ssl_verify_peer, CURLOPT_SSL_VERIFYHOST => $this->curl_ssl_verify_host, - CURLOPT_CONNECTTIMEOUT => $this->connect_timeout, + CURLOPT_CONNECTTIMEOUT => $this->curl_connect_timeout, + CURLOPT_TIMEOUT => $this->curl_request_timeout, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_HEADERFUNCTION => [$this, 'response_header_callback'], @@ -3983,10 +4034,9 @@ protected function get_curl_resource() } curl_setopt_array($ch, $curl_options); - return $ch; } return false; } -} \ No newline at end of file +} diff --git a/vendor/composer/InstalledVersions.php b/vendor/composer/InstalledVersions.php index 0d0f6b6..3abb462 100644 --- a/vendor/composer/InstalledVersions.php +++ b/vendor/composer/InstalledVersions.php @@ -20,6 +20,8 @@ + + class InstalledVersions { private static $installed = array ( @@ -30,7 +32,7 @@ class InstalledVersions 'aliases' => array ( ), - 'reference' => '4d6534826048ace8aef1778e158d3edf683494ee', + 'reference' => '2f1522139be5bc7c8bb6aae19d911501dfef1a84', 'name' => '__root__', ), 'versions' => @@ -42,16 +44,16 @@ class InstalledVersions 'aliases' => array ( ), - 'reference' => '4d6534826048ace8aef1778e158d3edf683494ee', + 'reference' => '2f1522139be5bc7c8bb6aae19d911501dfef1a84', ), 'art-of-wifi/unifi-api-client' => array ( - 'pretty_version' => 'v1.1.69', - 'version' => '1.1.69.0', + 'pretty_version' => 'v1.1.72', + 'version' => '1.1.72.0', 'aliases' => array ( ), - 'reference' => '474578a9d5e571ae2742a173d750d88890afc5f8', + 'reference' => '9cca43557c7f6454eb044d5c04a676630825872a', ), 'kint-php/kint' => array ( @@ -64,21 +66,21 @@ class InstalledVersions ), 'symfony/polyfill-ctype' => array ( - 'pretty_version' => 'v1.22.1', - 'version' => '1.22.1.0', + 'pretty_version' => 'v1.23.0', + 'version' => '1.23.0.0', 'aliases' => array ( ), - 'reference' => 'c6c942b1ac76c82448322025e084cadc56048b4e', + 'reference' => '46cd95797e9df938fdd2b03693b5fca5e64b01ce', ), 'twig/twig' => array ( - 'pretty_version' => 'v1.44.2', - 'version' => '1.44.2.0', + 'pretty_version' => 'v1.44.5', + 'version' => '1.44.5.0', 'aliases' => array ( ), - 'reference' => '138c493c5b8ee7cff3821f80b8896d371366b5fe', + 'reference' => 'dd4353357c5a116322e92a00d16043a31881a81e', ), ), ); @@ -98,7 +100,6 @@ public static function getInstalledPackages() $packages[] = array_keys($installed['versions']); } - if (1 === \count($packages)) { return $packages[0]; } @@ -294,6 +295,7 @@ public static function reload($data) + private static function getInstalled() { if (null === self::$canGetVendors) { diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 320cc3a..5360750 100755 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -2,17 +2,17 @@ "packages": [ { "name": "art-of-wifi/unifi-api-client", - "version": "v1.1.69", - "version_normalized": "1.1.69.0", + "version": "v1.1.72", + "version_normalized": "1.1.72.0", "source": { "type": "git", "url": "https://github.com/Art-of-WiFi/UniFi-API-client.git", - "reference": "474578a9d5e571ae2742a173d750d88890afc5f8" + "reference": "9cca43557c7f6454eb044d5c04a676630825872a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Art-of-WiFi/UniFi-API-client/zipball/474578a9d5e571ae2742a173d750d88890afc5f8", - "reference": "474578a9d5e571ae2742a173d750d88890afc5f8", + "url": "https://api.github.com/repos/Art-of-WiFi/UniFi-API-client/zipball/9cca43557c7f6454eb044d5c04a676630825872a", + "reference": "9cca43557c7f6454eb044d5c04a676630825872a", "shasum": "" }, "require": { @@ -20,7 +20,7 @@ "ext-json": "*", "php": ">=5.5.0" }, - "time": "2021-03-21T15:08:55+00:00", + "time": "2021-10-19T08:39:17+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -36,7 +36,7 @@ { "name": "Art of WiFi", "email": "info@artofowifi.net", - "homepage": "http://artofwifi.net" + "homepage": "https://artofwifi.net" } ], "description": "API client class for use with Ubiquiti's UniFi controller", @@ -51,7 +51,7 @@ ], "support": { "issues": "https://github.com/Art-of-WiFi/UniFi-API-client/issues", - "source": "https://github.com/Art-of-WiFi/UniFi-API-client/tree/v1.1.69" + "source": "https://github.com/Art-of-WiFi/UniFi-API-client/tree/v.1.1.72" }, "install-path": "../art-of-wifi/unifi-api-client" }, @@ -134,17 +134,17 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.22.1", - "version_normalized": "1.22.1.0", + "version": "v1.23.0", + "version_normalized": "1.23.0.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "c6c942b1ac76c82448322025e084cadc56048b4e" + "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/c6c942b1ac76c82448322025e084cadc56048b4e", - "reference": "c6c942b1ac76c82448322025e084cadc56048b4e", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/46cd95797e9df938fdd2b03693b5fca5e64b01ce", + "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce", "shasum": "" }, "require": { @@ -153,11 +153,11 @@ "suggest": { "ext-ctype": "For best performance" }, - "time": "2021-01-07T16:49:33+00:00", + "time": "2021-02-19T12:13:01+00:00", "type": "library", "extra": { "branch-alias": { - "dev-main": "1.22-dev" + "dev-main": "1.23-dev" }, "thanks": { "name": "symfony/polyfill", @@ -196,7 +196,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.22.1" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.23.0" }, "funding": [ { @@ -216,17 +216,17 @@ }, { "name": "twig/twig", - "version": "v1.44.2", - "version_normalized": "1.44.2.0", + "version": "v1.44.5", + "version_normalized": "1.44.5.0", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "138c493c5b8ee7cff3821f80b8896d371366b5fe" + "reference": "dd4353357c5a116322e92a00d16043a31881a81e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/138c493c5b8ee7cff3821f80b8896d371366b5fe", - "reference": "138c493c5b8ee7cff3821f80b8896d371366b5fe", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/dd4353357c5a116322e92a00d16043a31881a81e", + "reference": "dd4353357c5a116322e92a00d16043a31881a81e", "shasum": "" }, "require": { @@ -237,7 +237,7 @@ "psr/container": "^1.0", "symfony/phpunit-bridge": "^4.4.9|^5.0.9" }, - "time": "2021-01-05T10:10:05+00:00", + "time": "2021-09-17T08:35:19+00:00", "type": "library", "extra": { "branch-alias": { @@ -279,6 +279,10 @@ "keywords": [ "templating" ], + "support": { + "issues": "https://github.com/twigphp/Twig/issues", + "source": "https://github.com/twigphp/Twig/tree/v1.44.5" + }, "funding": [ { "url": "https://github.com/fabpot", diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 8b72db8..19eec0a 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -6,7 +6,7 @@ 'aliases' => array ( ), - 'reference' => '4d6534826048ace8aef1778e158d3edf683494ee', + 'reference' => '2f1522139be5bc7c8bb6aae19d911501dfef1a84', 'name' => '__root__', ), 'versions' => @@ -18,16 +18,16 @@ 'aliases' => array ( ), - 'reference' => '4d6534826048ace8aef1778e158d3edf683494ee', + 'reference' => '2f1522139be5bc7c8bb6aae19d911501dfef1a84', ), 'art-of-wifi/unifi-api-client' => array ( - 'pretty_version' => 'v1.1.69', - 'version' => '1.1.69.0', + 'pretty_version' => 'v1.1.72', + 'version' => '1.1.72.0', 'aliases' => array ( ), - 'reference' => '474578a9d5e571ae2742a173d750d88890afc5f8', + 'reference' => '9cca43557c7f6454eb044d5c04a676630825872a', ), 'kint-php/kint' => array ( @@ -40,21 +40,21 @@ ), 'symfony/polyfill-ctype' => array ( - 'pretty_version' => 'v1.22.1', - 'version' => '1.22.1.0', + 'pretty_version' => 'v1.23.0', + 'version' => '1.23.0.0', 'aliases' => array ( ), - 'reference' => 'c6c942b1ac76c82448322025e084cadc56048b4e', + 'reference' => '46cd95797e9df938fdd2b03693b5fca5e64b01ce', ), 'twig/twig' => array ( - 'pretty_version' => 'v1.44.2', - 'version' => '1.44.2.0', + 'pretty_version' => 'v1.44.5', + 'version' => '1.44.5.0', 'aliases' => array ( ), - 'reference' => '138c493c5b8ee7cff3821f80b8896d371366b5fe', + 'reference' => 'dd4353357c5a116322e92a00d16043a31881a81e', ), ), ); diff --git a/vendor/symfony/polyfill-ctype/composer.json b/vendor/symfony/polyfill-ctype/composer.json index 995978c..f0621a3 100644 --- a/vendor/symfony/polyfill-ctype/composer.json +++ b/vendor/symfony/polyfill-ctype/composer.json @@ -28,7 +28,7 @@ "minimum-stability": "dev", "extra": { "branch-alias": { - "dev-main": "1.22-dev" + "dev-main": "1.23-dev" }, "thanks": { "name": "symfony/polyfill", diff --git a/vendor/twig/twig/.github/workflows/ci.yml b/vendor/twig/twig/.github/workflows/ci.yml index 8e327cc..a77b8a0 100644 --- a/vendor/twig/twig/.github/workflows/ci.yml +++ b/vendor/twig/twig/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: runs-on: 'ubuntu-latest' - continue-on-error: true + continue-on-error: ${{ matrix.experimental }} strategy: matrix: @@ -24,6 +24,10 @@ jobs: - '7.3' - '7.4' - '8.0' + composer-options: [''] + experimental: [false] + include: + - { php-version: '8.1', experimental: true, composer-options: '--ignore-platform-req=php' } steps: - name: "Checkout code" @@ -51,7 +55,7 @@ jobs: key: ${{ runner.os }}-${{ matrix.php-version }}-composer-${{ hashFiles('composer.json') }} restore-keys: ${{ runner.os }}-${{ matrix.php-version }}-composer- - - run: composer install + - run: composer install ${{ matrix.composer-options }} - name: "Install PHPUnit" run: vendor/bin/simple-phpunit install @@ -90,5 +94,5 @@ jobs: ini-values: memory_limit=-1 tools: composer:v2 - - run: ./drupal_test.sh + - run: bash ./tests/drupal_test.sh shell: "bash" diff --git a/vendor/twig/twig/.php_cs.dist b/vendor/twig/twig/.php-cs-fixer.dist.php similarity index 88% rename from vendor/twig/twig/.php_cs.dist rename to vendor/twig/twig/.php-cs-fixer.dist.php index b81882f..b07ac7f 100644 --- a/vendor/twig/twig/.php_cs.dist +++ b/vendor/twig/twig/.php-cs-fixer.dist.php @@ -1,6 +1,6 @@ setRules([ '@Symfony' => true, '@Symfony:risky' => true, @@ -16,5 +16,5 @@ 'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'all'], ]) ->setRiskyAllowed(true) - ->setFinder(PhpCsFixer\Finder::create()->in(__DIR__)) + ->setFinder((new PhpCsFixer\Finder())->in(__DIR__)) ; diff --git a/vendor/twig/twig/CHANGELOG b/vendor/twig/twig/CHANGELOG index ee87b57..055d460 100644 --- a/vendor/twig/twig/CHANGELOG +++ b/vendor/twig/twig/CHANGELOG @@ -1,3 +1,17 @@ +# 1.44.5 (2021-09-17) + + * Improve compatibility with PHP 8.1 + * Explicitly specify the encoding for mb_ord in JS escaper + +# 1.44.4 (2021-05-16) + + * Revert "Throw a proper exception when a template name is an absolute path (as it has never been supported)" + +# 1.44.3 (2021-05-12) + + * Fix PHP 8.1 compatibility + * Throw a proper exception when a template name is an absolute path (as it has never been supported) + # 1.44.2 (2021-01-05) * Fix "odd" not working for negative numbers diff --git a/vendor/twig/twig/README.rst b/vendor/twig/twig/README.rst index d896ff5..7bd3954 100644 --- a/vendor/twig/twig/README.rst +++ b/vendor/twig/twig/README.rst @@ -7,6 +7,9 @@ and documentation). Twig uses a syntax similar to the Django and Jinja template languages which inspired the Twig runtime environment. +**Twig version 1 will stop being maintained at the end of November 2021.** +Please, upgrade at your earliest convenience. + Sponsors -------- diff --git a/vendor/twig/twig/doc/filters/abs.rst b/vendor/twig/twig/doc/filters/abs.rst index 77d5cf0..fea1175 100644 --- a/vendor/twig/twig/doc/filters/abs.rst +++ b/vendor/twig/twig/doc/filters/abs.rst @@ -15,4 +15,4 @@ The ``abs`` filter returns the absolute value. Internally, Twig uses the PHP `abs`_ function. -.. _`abs`: https://secure.php.net/abs +.. _`abs`: https://www.php.net/abs diff --git a/vendor/twig/twig/doc/filters/convert_encoding.rst b/vendor/twig/twig/doc/filters/convert_encoding.rst index 5bfa379..9269efd 100644 --- a/vendor/twig/twig/doc/filters/convert_encoding.rst +++ b/vendor/twig/twig/doc/filters/convert_encoding.rst @@ -25,5 +25,5 @@ Arguments * ``to``: The output charset * ``from``: The input charset -.. _`iconv`: https://secure.php.net/iconv -.. _`mbstring`: https://secure.php.net/mbstring +.. _`iconv`: https://www.php.net/iconv +.. _`mbstring`: https://www.php.net/mbstring diff --git a/vendor/twig/twig/doc/filters/date.rst b/vendor/twig/twig/doc/filters/date.rst index 3186368..f719dc6 100644 --- a/vendor/twig/twig/doc/filters/date.rst +++ b/vendor/twig/twig/doc/filters/date.rst @@ -93,8 +93,8 @@ Arguments * ``format``: The date format * ``timezone``: The date timezone -.. _`strtotime`: https://secure.php.net/strtotime -.. _`DateTime`: https://secure.php.net/DateTime -.. _`DateInterval`: https://secure.php.net/DateInterval -.. _`date`: https://secure.php.net/date -.. _`DateInterval::format`: https://secure.php.net/DateInterval.format +.. _`strtotime`: https://www.php.net/strtotime +.. _`DateTime`: https://www.php.net/DateTime +.. _`DateInterval`: https://www.php.net/DateInterval +.. _`date`: https://www.php.net/date +.. _`DateInterval::format`: https://www.php.net/DateInterval.format diff --git a/vendor/twig/twig/doc/filters/date_modify.rst b/vendor/twig/twig/doc/filters/date_modify.rst index 8d50097..7cd50c2 100644 --- a/vendor/twig/twig/doc/filters/date_modify.rst +++ b/vendor/twig/twig/doc/filters/date_modify.rst @@ -20,5 +20,5 @@ Arguments * ``modifier``: The modifier -.. _`strtotime`: https://secure.php.net/strtotime -.. _`DateTime`: https://secure.php.net/DateTime +.. _`strtotime`: https://www.php.net/strtotime +.. _`DateTime`: https://www.php.net/DateTime diff --git a/vendor/twig/twig/doc/filters/escape.rst b/vendor/twig/twig/doc/filters/escape.rst index a0ecbdc..1592460 100644 --- a/vendor/twig/twig/doc/filters/escape.rst +++ b/vendor/twig/twig/doc/filters/escape.rst @@ -126,4 +126,4 @@ Arguments * ``strategy``: The escaping strategy * ``charset``: The string charset -.. _`htmlspecialchars`: https://secure.php.net/htmlspecialchars +.. _`htmlspecialchars`: https://www.php.net/htmlspecialchars diff --git a/vendor/twig/twig/doc/filters/first.rst b/vendor/twig/twig/doc/filters/first.rst index 7ed72d1..30bde3a 100644 --- a/vendor/twig/twig/doc/filters/first.rst +++ b/vendor/twig/twig/doc/filters/first.rst @@ -23,4 +23,4 @@ a string: It also works with objects implementing the `Traversable`_ interface. -.. _`Traversable`: https://secure.php.net/manual/en/class.traversable.php +.. _`Traversable`: https://www.php.net/manual/en/class.traversable.php diff --git a/vendor/twig/twig/doc/filters/format.rst b/vendor/twig/twig/doc/filters/format.rst index 00c09bd..ec1eb00 100644 --- a/vendor/twig/twig/doc/filters/format.rst +++ b/vendor/twig/twig/doc/filters/format.rst @@ -11,7 +11,7 @@ The ``format`` filter formats a given string by replacing the placeholders {# outputs I like foo and bar if the foo parameter equals to the foo string. #} -.. _`sprintf`: https://secure.php.net/sprintf +.. _`sprintf`: https://www.php.net/sprintf .. seealso:: diff --git a/vendor/twig/twig/doc/filters/json_encode.rst b/vendor/twig/twig/doc/filters/json_encode.rst index 434e2f1..34e7136 100644 --- a/vendor/twig/twig/doc/filters/json_encode.rst +++ b/vendor/twig/twig/doc/filters/json_encode.rst @@ -19,5 +19,5 @@ Arguments Combine constants using :ref:`bitwise operators`: ``{{ data|json_encode(constant('JSON_PRETTY_PRINT') b-or constant('JSON_HEX_QUOT')) }}`` -.. _`json_encode`: https://secure.php.net/json_encode -.. _`json_encode options`: https://secure.php.net/manual/en/json.constants.php +.. _`json_encode`: https://www.php.net/json_encode +.. _`json_encode options`: https://www.php.net/manual/en/json.constants.php diff --git a/vendor/twig/twig/doc/filters/last.rst b/vendor/twig/twig/doc/filters/last.rst index e8f92eb..b9f5ef0 100644 --- a/vendor/twig/twig/doc/filters/last.rst +++ b/vendor/twig/twig/doc/filters/last.rst @@ -23,4 +23,4 @@ a string: It also works with objects implementing the `Traversable`_ interface. -.. _`Traversable`: https://secure.php.net/manual/en/class.traversable.php +.. _`Traversable`: https://www.php.net/manual/en/class.traversable.php diff --git a/vendor/twig/twig/doc/filters/length.rst b/vendor/twig/twig/doc/filters/length.rst index 8b504ed..37209f8 100644 --- a/vendor/twig/twig/doc/filters/length.rst +++ b/vendor/twig/twig/doc/filters/length.rst @@ -14,7 +14,7 @@ return value of the ``count()`` method. For objects that implement the ``__toString()`` magic method (and not ``Countable``), it will return the length of the string provided by that method. -For objects that implement the ``IteratorAggregate`` interface, ``length`` will use the return value of the ``iterator_count()`` method. +For objects that implement the ``Traversable`` interface, ``length`` will use the return value of the ``iterator_count()`` method. .. code-block:: twig diff --git a/vendor/twig/twig/doc/filters/merge.rst b/vendor/twig/twig/doc/filters/merge.rst index e26e51c..40146b5 100644 --- a/vendor/twig/twig/doc/filters/merge.rst +++ b/vendor/twig/twig/doc/filters/merge.rst @@ -45,4 +45,4 @@ overridden. Internally, Twig uses the PHP `array_merge`_ function. It supports Traversable objects by transforming those to arrays. -.. _`array_merge`: https://secure.php.net/array_merge +.. _`array_merge`: https://www.php.net/array_merge diff --git a/vendor/twig/twig/doc/filters/number_format.rst b/vendor/twig/twig/doc/filters/number_format.rst index 014cd30..a417154 100644 --- a/vendor/twig/twig/doc/filters/number_format.rst +++ b/vendor/twig/twig/doc/filters/number_format.rst @@ -52,4 +52,4 @@ Arguments * ``decimal_point``: The character(s) to use for the decimal point * ``thousand_sep``: The character(s) to use for the thousands separator -.. _`number_format`: https://secure.php.net/number_format +.. _`number_format`: https://www.php.net/number_format diff --git a/vendor/twig/twig/doc/filters/reverse.rst b/vendor/twig/twig/doc/filters/reverse.rst index 5d581f8..ee40aac 100644 --- a/vendor/twig/twig/doc/filters/reverse.rst +++ b/vendor/twig/twig/doc/filters/reverse.rst @@ -45,4 +45,4 @@ Arguments * ``preserve_keys``: Preserve keys when reversing a mapping or a sequence. -.. _`Traversable`: https://secure.php.net/Traversable +.. _`Traversable`: https://www.php.net/Traversable diff --git a/vendor/twig/twig/doc/filters/slice.rst b/vendor/twig/twig/doc/filters/slice.rst index a36e01b..d34f2d6 100644 --- a/vendor/twig/twig/doc/filters/slice.rst +++ b/vendor/twig/twig/doc/filters/slice.rst @@ -66,7 +66,7 @@ Arguments * ``length``: The size of the slice * ``preserve_keys``: Whether to preserve key or not (when the input is an array) -.. _`Traversable`: https://secure.php.net/manual/en/class.traversable.php -.. _`array_slice`: https://secure.php.net/array_slice -.. _`mb_substr` : https://secure.php.net/mb-substr -.. _`substr`: https://secure.php.net/substr +.. _`Traversable`: https://www.php.net/manual/en/class.traversable.php +.. _`array_slice`: https://www.php.net/array_slice +.. _`mb_substr`: https://www.php.net/mb-substr +.. _`substr`: https://www.php.net/substr diff --git a/vendor/twig/twig/doc/filters/sort.rst b/vendor/twig/twig/doc/filters/sort.rst index f7c0329..e8c9b2b 100644 --- a/vendor/twig/twig/doc/filters/sort.rst +++ b/vendor/twig/twig/doc/filters/sort.rst @@ -15,4 +15,4 @@ The ``sort`` filter sorts an array: association. It supports Traversable objects by transforming those to arrays. -.. _`asort`: https://secure.php.net/asort +.. _`asort`: https://www.php.net/asort diff --git a/vendor/twig/twig/doc/filters/split.rst b/vendor/twig/twig/doc/filters/split.rst index e3cf884..7b714ad 100644 --- a/vendor/twig/twig/doc/filters/split.rst +++ b/vendor/twig/twig/doc/filters/split.rst @@ -50,5 +50,5 @@ Arguments * ``delimiter``: The delimiter * ``limit``: The limit argument -.. _`explode`: https://secure.php.net/explode -.. _`str_split`: https://secure.php.net/str_split +.. _`explode`: https://www.php.net/explode +.. _`str_split`: https://www.php.net/str_split diff --git a/vendor/twig/twig/doc/filters/striptags.rst b/vendor/twig/twig/doc/filters/striptags.rst index 7a0aabd..d5f542b 100644 --- a/vendor/twig/twig/doc/filters/striptags.rst +++ b/vendor/twig/twig/doc/filters/striptags.rst @@ -26,4 +26,4 @@ Arguments * ``allowable_tags``: Tags which should not be stripped -.. _`strip_tags`: https://secure.php.net/strip_tags +.. _`strip_tags`: https://www.php.net/strip_tags diff --git a/vendor/twig/twig/doc/filters/trim.rst b/vendor/twig/twig/doc/filters/trim.rst index 7ec2566..d830866 100644 --- a/vendor/twig/twig/doc/filters/trim.rst +++ b/vendor/twig/twig/doc/filters/trim.rst @@ -42,6 +42,6 @@ Arguments * ``side``: The default is to strip from the left and the right (`both`) sides, but `left` and `right` will strip from either the left side or right side only -.. _`trim`: https://secure.php.net/trim -.. _`ltrim`: https://secure.php.net/ltrim -.. _`rtrim`: https://secure.php.net/rtrim +.. _`trim`: https://www.php.net/trim +.. _`ltrim`: https://www.php.net/ltrim +.. _`rtrim`: https://www.php.net/rtrim diff --git a/vendor/twig/twig/doc/filters/url_encode.rst b/vendor/twig/twig/doc/filters/url_encode.rst index e355d59..eac04f9 100644 --- a/vendor/twig/twig/doc/filters/url_encode.rst +++ b/vendor/twig/twig/doc/filters/url_encode.rst @@ -31,6 +31,6 @@ or an array as query string: that as of Twig 1.16.0, ``urlencode`` **always** uses ``rawurlencode`` (the ``raw`` argument was removed.) -.. _`urlencode`: https://secure.php.net/urlencode -.. _`rawurlencode`: https://secure.php.net/rawurlencode -.. _`http_build_query`: https://secure.php.net/http_build_query +.. _`urlencode`: https://www.php.net/urlencode +.. _`rawurlencode`: https://www.php.net/rawurlencode +.. _`http_build_query`: https://www.php.net/http_build_query diff --git a/vendor/twig/twig/doc/functions/date.rst b/vendor/twig/twig/doc/functions/date.rst index 38614de..25eb43e 100644 --- a/vendor/twig/twig/doc/functions/date.rst +++ b/vendor/twig/twig/doc/functions/date.rst @@ -52,4 +52,4 @@ Arguments * ``date``: The date * ``timezone``: The timezone -.. _`date and time formats`: https://secure.php.net/manual/en/datetime.formats.php +.. _`date and time formats`: https://www.php.net/manual/en/datetime.formats.php diff --git a/vendor/twig/twig/doc/functions/dump.rst b/vendor/twig/twig/doc/functions/dump.rst index 13e4fd1..24b9825 100644 --- a/vendor/twig/twig/doc/functions/dump.rst +++ b/vendor/twig/twig/doc/functions/dump.rst @@ -67,4 +67,4 @@ Arguments * ``context``: The context to dump .. _`XDebug`: https://xdebug.org/docs/display -.. _`var_dump`: https://secure.php.net/var_dump +.. _`var_dump`: https://www.php.net/var_dump diff --git a/vendor/twig/twig/doc/functions/range.rst b/vendor/twig/twig/doc/functions/range.rst index a1f0e7c..e537b11 100644 --- a/vendor/twig/twig/doc/functions/range.rst +++ b/vendor/twig/twig/doc/functions/range.rst @@ -55,4 +55,4 @@ Arguments * ``high``: The highest possible value of the sequence. * ``step``: The increment between elements of the sequence. -.. _`range`: https://secure.php.net/range +.. _`range`: https://www.php.net/range diff --git a/vendor/twig/twig/doc/intro.rst b/vendor/twig/twig/doc/intro.rst index 2bb1cf7..d28e0fc 100644 --- a/vendor/twig/twig/doc/intro.rst +++ b/vendor/twig/twig/doc/intro.rst @@ -23,6 +23,10 @@ Twig is used by many Open-Source projects like Symfony, Drupal8, eZPublish, phpBB, Matomo, OroCRM; and many frameworks have support for it as well like Slim, Yii, Laravel, and Codeigniter — just to name a few. +.. admonition:: Screencast + + Like to learn from video tutorials? Check out the `SymfonyCasts Twig Tutorial`_! + Prerequisites ------------- @@ -72,3 +76,5 @@ filesystem loader:: ]); echo $twig->render('index.html', ['name' => 'Fabien']); + +.. _`SymfonyCasts Twig Tutorial`: https://symfonycasts.com/screencast/twig diff --git a/vendor/twig/twig/doc/recipes.rst b/vendor/twig/twig/doc/recipes.rst index efd7482..453bcaa 100644 --- a/vendor/twig/twig/doc/recipes.rst +++ b/vendor/twig/twig/doc/recipes.rst @@ -565,4 +565,4 @@ include in your templates: 'tag_variable' => ['{[', ']}'], ])); -.. _callback: https://secure.php.net/manual/en/function.is-callable.php +.. _callback: https://www.php.net/manual/en/function.is-callable.php diff --git a/vendor/twig/twig/doc/tags/flush.rst b/vendor/twig/twig/doc/tags/flush.rst index 47efbda..140728f 100644 --- a/vendor/twig/twig/doc/tags/flush.rst +++ b/vendor/twig/twig/doc/tags/flush.rst @@ -15,4 +15,4 @@ The ``flush`` tag tells Twig to flush the output buffer: Internally, Twig uses the PHP `flush`_ function. -.. _`flush`: https://secure.php.net/flush +.. _`flush`: https://www.php.net/flush diff --git a/vendor/twig/twig/doc/templates.rst b/vendor/twig/twig/doc/templates.rst index 7636c3c..943a004 100644 --- a/vendor/twig/twig/doc/templates.rst +++ b/vendor/twig/twig/doc/templates.rst @@ -890,7 +890,7 @@ Twig can be extended. If you want to create your own extensions, read the .. _`other Twig syntax mode`: https://github.com/muxx/Twig-HTML.mode .. _`Notepad++ Twig Highlighter`: https://github.com/Banane9/notepadplusplus-twig .. _`web-mode.el`: http://web-mode.org/ -.. _`regular expressions`: https://secure.php.net/manual/en/pcre.pattern.php +.. _`regular expressions`: https://www.php.net/manual/en/pcre.pattern.php .. _`PHP-twig for atom`: https://github.com/reesef/php-twig .. _`TwigFiddle`: https://twigfiddle.com/ .. _`Twig pack`: https://marketplace.visualstudio.com/items?itemName=bajdzis.vscode-twig-pack diff --git a/vendor/twig/twig/drupal_test.sh b/vendor/twig/twig/drupal_test.sh deleted file mode 100755 index ca493f9..0000000 --- a/vendor/twig/twig/drupal_test.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash - -set -x -set -e - -REPO=`pwd` -cd /tmp -rm -rf drupal-twig-test -composer create-project --no-interaction drupal/recommended-project:8.9.x-dev drupal-twig-test -cd drupal-twig-test -(cd vendor/twig && rm -rf twig && ln -sf $REPO twig) -php ./web/core/scripts/drupal install --no-interaction demo_umami > output -perl -p -i -e 's/^([A-Za-z]+)\: (.+)$/export DRUPAL_\1=\2/' output -source output -#echo '$config["system.logging"]["error_level"] = "verbose";' >> web/sites/default/settings.php - -wget https://get.symfony.com/cli/installer -O - | bash -export PATH="$HOME/.symfony/bin:$PATH" -symfony server:start -d --no-tls - -curl -OLsS https://get.blackfire.io/blackfire-player.phar -chmod +x blackfire-player.phar -cat > drupal-tests.bkf < | - +----------------------------------------------------------------------+ - */ - -#ifndef PHP_TWIG_H -#define PHP_TWIG_H - -#define PHP_TWIG_VERSION "1.42.5-DEV" - -#include "php.h" - -extern zend_module_entry twig_module_entry; -#define phpext_twig_ptr &twig_module_entry -#ifndef PHP_WIN32 -zend_module_entry *get_module(void); -#endif - -#ifdef ZTS -#include "TSRM.h" -#endif - -PHP_FUNCTION(twig_template_get_attributes); -PHP_RSHUTDOWN_FUNCTION(twig); - -#endif diff --git a/vendor/twig/twig/ext/twig/twig.c b/vendor/twig/twig/ext/twig/twig.c deleted file mode 100644 index 171ed10..0000000 --- a/vendor/twig/twig/ext/twig/twig.c +++ /dev/null @@ -1,1217 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Twig Extension | - +----------------------------------------------------------------------+ - | Copyright (c) 2011 Derick Rethans | - +----------------------------------------------------------------------+ - | Redistribution and use in source and binary forms, with or without | - | modification, are permitted provided that the conditions mentioned | - | in the accompanying LICENSE file are met (BSD-3-Clause). | - +----------------------------------------------------------------------+ - | Author: Derick Rethans | - +----------------------------------------------------------------------+ - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" -#include "php_twig.h" -#include "ext/standard/php_var.h" -#include "ext/standard/php_string.h" -#include "ext/standard/php_smart_str.h" -#include "ext/spl/spl_exceptions.h" - -#include "Zend/zend_object_handlers.h" -#include "Zend/zend_interfaces.h" -#include "Zend/zend_exceptions.h" - -#ifndef Z_ADDREF_P -#define Z_ADDREF_P(pz) (pz)->refcount++ -#endif - -#ifndef E_USER_DEPRECATED -#define E_USER_DEPRECATED (1<<14L) -#endif - -#define FREE_DTOR(z) \ - zval_dtor(z); \ - efree(z); - -#if PHP_VERSION_ID >= 50300 - #define APPLY_TSRMLS_DC TSRMLS_DC - #define APPLY_TSRMLS_CC TSRMLS_CC - #define APPLY_TSRMLS_FETCH() -#else - #define APPLY_TSRMLS_DC - #define APPLY_TSRMLS_CC - #define APPLY_TSRMLS_FETCH() TSRMLS_FETCH() -#endif - -ZEND_BEGIN_ARG_INFO_EX(twig_template_get_attribute_args, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 6) - ZEND_ARG_INFO(0, template) - ZEND_ARG_INFO(0, object) - ZEND_ARG_INFO(0, item) - ZEND_ARG_INFO(0, arguments) - ZEND_ARG_INFO(0, type) - ZEND_ARG_INFO(0, isDefinedTest) -ZEND_END_ARG_INFO() - -#ifndef PHP_FE_END -#define PHP_FE_END { NULL, NULL, NULL} -#endif - -static const zend_function_entry twig_functions[] = { - PHP_FE(twig_template_get_attributes, twig_template_get_attribute_args) - PHP_FE_END -}; - -PHP_RSHUTDOWN_FUNCTION(twig) -{ -#if ZEND_DEBUG - CG(unclean_shutdown) = 0; /* get rid of PHPUnit's exit() and report memleaks */ -#endif - return SUCCESS; -} - -zend_module_entry twig_module_entry = { - STANDARD_MODULE_HEADER, - "twig", - twig_functions, - NULL, - NULL, - NULL, - PHP_RSHUTDOWN(twig), - NULL, - PHP_TWIG_VERSION, - STANDARD_MODULE_PROPERTIES -}; - - -#ifdef COMPILE_DL_TWIG -ZEND_GET_MODULE(twig) -#endif - -static int TWIG_ARRAY_KEY_EXISTS(zval *array, zval *key) -{ - if (Z_TYPE_P(array) != IS_ARRAY) { - return 0; - } - - switch (Z_TYPE_P(key)) { - case IS_NULL: - return zend_hash_exists(Z_ARRVAL_P(array), "", 1); - - case IS_BOOL: - case IS_DOUBLE: - convert_to_long(key); - case IS_LONG: - return zend_hash_index_exists(Z_ARRVAL_P(array), Z_LVAL_P(key)); - - default: - convert_to_string(key); - return zend_symtable_exists(Z_ARRVAL_P(array), Z_STRVAL_P(key), Z_STRLEN_P(key) + 1); - } -} - -static int TWIG_INSTANCE_OF(zval *object, zend_class_entry *interface TSRMLS_DC) -{ - if (Z_TYPE_P(object) != IS_OBJECT) { - return 0; - } - return instanceof_function(Z_OBJCE_P(object), interface TSRMLS_CC); -} - -static int TWIG_INSTANCE_OF_USERLAND(zval *object, char *interface TSRMLS_DC) -{ - zend_class_entry **pce; - if (Z_TYPE_P(object) != IS_OBJECT) { - return 0; - } - if (zend_lookup_class(interface, strlen(interface), &pce TSRMLS_CC) == FAILURE) { - return 0; - } - return instanceof_function(Z_OBJCE_P(object), *pce TSRMLS_CC); -} - -static zval *TWIG_GET_ARRAYOBJECT_ELEMENT(zval *object, zval *offset TSRMLS_DC) -{ - zend_class_entry *ce = Z_OBJCE_P(object); - zval *retval; - - if (Z_TYPE_P(object) == IS_OBJECT) { - SEPARATE_ARG_IF_REF(offset); - zend_call_method_with_1_params(&object, ce, NULL, "offsetget", &retval, offset); - - zval_ptr_dtor(&offset); - - if (!retval) { - if (!EG(exception)) { - zend_error(E_ERROR, "Undefined offset for object of type %s used as array.", ce->name); - } - return NULL; - } - - return retval; - } - return NULL; -} - -static int TWIG_ISSET_ARRAYOBJECT_ELEMENT(zval *object, zval *offset TSRMLS_DC) -{ - zend_class_entry *ce = Z_OBJCE_P(object); - zval *retval; - - if (Z_TYPE_P(object) == IS_OBJECT) { - SEPARATE_ARG_IF_REF(offset); - zend_call_method_with_1_params(&object, ce, NULL, "offsetexists", &retval, offset); - - zval_ptr_dtor(&offset); - - if (!retval) { - if (!EG(exception)) { - zend_error(E_ERROR, "Undefined offset for object of type %s used as array.", ce->name); - } - return 0; - } - - return (retval && Z_TYPE_P(retval) == IS_BOOL && Z_LVAL_P(retval)); - } - return 0; -} - -static char *TWIG_STRTOLOWER(const char *str, int str_len) -{ - char *item_dup; - - item_dup = estrndup(str, str_len); - php_strtolower(item_dup, str_len); - return item_dup; -} - -static zval *TWIG_CALL_USER_FUNC_ARRAY(zval *object, char *function, zval *arguments TSRMLS_DC) -{ - zend_fcall_info fci; - zval ***args = NULL; - int arg_count = 0; - HashTable *table; - HashPosition pos; - int i = 0; - zval *retval_ptr; - zval *zfunction; - - if (arguments) { - table = HASH_OF(arguments); - args = safe_emalloc(sizeof(zval **), table->nNumOfElements, 0); - - zend_hash_internal_pointer_reset_ex(table, &pos); - - while (zend_hash_get_current_data_ex(table, (void **)&args[i], &pos) == SUCCESS) { - i++; - zend_hash_move_forward_ex(table, &pos); - } - arg_count = table->nNumOfElements; - } - - MAKE_STD_ZVAL(zfunction); - ZVAL_STRING(zfunction, function, 1); - fci.size = sizeof(fci); - fci.function_table = EG(function_table); - fci.function_name = zfunction; - fci.symbol_table = NULL; -#if PHP_VERSION_ID >= 50300 - fci.object_ptr = object; -#else - fci.object_pp = &object; -#endif - fci.retval_ptr_ptr = &retval_ptr; - fci.param_count = arg_count; - fci.params = args; - fci.no_separation = 0; - - if (zend_call_function(&fci, NULL TSRMLS_CC) == FAILURE) { - ALLOC_INIT_ZVAL(retval_ptr); - ZVAL_BOOL(retval_ptr, 0); - } - - if (args) { - efree(fci.params); - } - FREE_DTOR(zfunction); - return retval_ptr; -} - -static int TWIG_CALL_BOOLEAN(zval *object, char *functionName TSRMLS_DC) -{ - zval *ret; - int res; - - ret = TWIG_CALL_USER_FUNC_ARRAY(object, functionName, NULL TSRMLS_CC); - res = Z_LVAL_P(ret); - zval_ptr_dtor(&ret); - return res; -} - -static zval *TWIG_GET_STATIC_PROPERTY(zval *class, char *prop_name TSRMLS_DC) -{ - zval **tmp_zval; - zend_class_entry *ce; - - if (class == NULL || Z_TYPE_P(class) != IS_OBJECT) { - return NULL; - } - - ce = zend_get_class_entry(class TSRMLS_CC); -#if PHP_VERSION_ID >= 50400 - tmp_zval = zend_std_get_static_property(ce, prop_name, strlen(prop_name), 0, NULL TSRMLS_CC); -#else - tmp_zval = zend_std_get_static_property(ce, prop_name, strlen(prop_name), 0 TSRMLS_CC); -#endif - return *tmp_zval; -} - -static zval *TWIG_GET_ARRAY_ELEMENT_ZVAL(zval *class, zval *prop_name TSRMLS_DC) -{ - zval **tmp_zval; - - if (class == NULL || Z_TYPE_P(class) != IS_ARRAY) { - if (class != NULL && Z_TYPE_P(class) == IS_OBJECT && TWIG_INSTANCE_OF(class, zend_ce_arrayaccess TSRMLS_CC)) { - // array access object - return TWIG_GET_ARRAYOBJECT_ELEMENT(class, prop_name TSRMLS_CC); - } - return NULL; - } - - switch(Z_TYPE_P(prop_name)) { - case IS_NULL: - zend_hash_find(HASH_OF(class), "", 1, (void**) &tmp_zval); - return *tmp_zval; - - case IS_BOOL: - case IS_DOUBLE: - convert_to_long(prop_name); - case IS_LONG: - zend_hash_index_find(HASH_OF(class), Z_LVAL_P(prop_name), (void **) &tmp_zval); - return *tmp_zval; - - case IS_STRING: - zend_symtable_find(HASH_OF(class), Z_STRVAL_P(prop_name), Z_STRLEN_P(prop_name) + 1, (void**) &tmp_zval); - return *tmp_zval; - } - - return NULL; -} - -static zval *TWIG_GET_ARRAY_ELEMENT(zval *class, char *prop_name, int prop_name_length TSRMLS_DC) -{ - zval **tmp_zval; - - if (class == NULL/* || Z_TYPE_P(class) != IS_ARRAY*/) { - return NULL; - } - - if (class != NULL && Z_TYPE_P(class) == IS_OBJECT && TWIG_INSTANCE_OF(class, zend_ce_arrayaccess TSRMLS_CC)) { - // array access object - zval *tmp_name_zval; - zval *tmp_ret_zval; - - ALLOC_INIT_ZVAL(tmp_name_zval); - ZVAL_STRING(tmp_name_zval, prop_name, 1); - tmp_ret_zval = TWIG_GET_ARRAYOBJECT_ELEMENT(class, tmp_name_zval TSRMLS_CC); - FREE_DTOR(tmp_name_zval); - return tmp_ret_zval; - } - - if (zend_symtable_find(HASH_OF(class), prop_name, prop_name_length+1, (void**)&tmp_zval) == SUCCESS) { - return *tmp_zval; - } - return NULL; -} - -static zval *TWIG_PROPERTY(zval *object, zval *propname TSRMLS_DC) -{ - zval *tmp = NULL; - - if (Z_OBJ_HT_P(object)->read_property) { -#if PHP_VERSION_ID >= 50400 - tmp = Z_OBJ_HT_P(object)->read_property(object, propname, BP_VAR_IS, NULL TSRMLS_CC); -#else - tmp = Z_OBJ_HT_P(object)->read_property(object, propname, BP_VAR_IS TSRMLS_CC); -#endif - if (tmp == EG(uninitialized_zval_ptr)) { - ZVAL_NULL(tmp); - } - } - return tmp; -} - -static int TWIG_HAS_PROPERTY(zval *object, zval *propname TSRMLS_DC) -{ - if (Z_OBJ_HT_P(object)->has_property) { -#if PHP_VERSION_ID >= 50400 - return Z_OBJ_HT_P(object)->has_property(object, propname, 0, NULL TSRMLS_CC); -#else - return Z_OBJ_HT_P(object)->has_property(object, propname, 0 TSRMLS_CC); -#endif - } - return 0; -} - -static int TWIG_HAS_DYNAMIC_PROPERTY(zval *object, char *prop, int prop_len TSRMLS_DC) -{ - if (Z_OBJ_HT_P(object)->get_properties) { - return zend_hash_quick_exists( - Z_OBJ_HT_P(object)->get_properties(object TSRMLS_CC), // the properties hash - prop, // property name - prop_len + 1, // property length - zend_get_hash_value(prop, prop_len + 1) // hash value - ); - } - return 0; -} - -static zval *TWIG_PROPERTY_CHAR(zval *object, char *propname TSRMLS_DC) -{ - zval *tmp_name_zval, *tmp; - - ALLOC_INIT_ZVAL(tmp_name_zval); - ZVAL_STRING(tmp_name_zval, propname, 1); - tmp = TWIG_PROPERTY(object, tmp_name_zval TSRMLS_CC); - FREE_DTOR(tmp_name_zval); - return tmp; -} - -static zval *TWIG_CALL_S(zval *object, char *method, char *arg0 TSRMLS_DC) -{ - zend_fcall_info fci; - zval **args[1]; - zval *argument; - zval *zfunction; - zval *retval_ptr; - - MAKE_STD_ZVAL(argument); - ZVAL_STRING(argument, arg0, 1); - args[0] = &argument; - - MAKE_STD_ZVAL(zfunction); - ZVAL_STRING(zfunction, method, 1); - fci.size = sizeof(fci); - fci.function_table = EG(function_table); - fci.function_name = zfunction; - fci.symbol_table = NULL; -#if PHP_VERSION_ID >= 50300 - fci.object_ptr = object; -#else - fci.object_pp = &object; -#endif - fci.retval_ptr_ptr = &retval_ptr; - fci.param_count = 1; - fci.params = args; - fci.no_separation = 0; - - if (zend_call_function(&fci, NULL TSRMLS_CC) == FAILURE) { - FREE_DTOR(zfunction); - zval_ptr_dtor(&argument); - return 0; - } - FREE_DTOR(zfunction); - zval_ptr_dtor(&argument); - return retval_ptr; -} - -static int TWIG_CALL_SB(zval *object, char *method, char *arg0 TSRMLS_DC) -{ - zval *retval_ptr; - int success; - - retval_ptr = TWIG_CALL_S(object, method, arg0 TSRMLS_CC); - success = (retval_ptr && (Z_TYPE_P(retval_ptr) == IS_BOOL) && Z_LVAL_P(retval_ptr)); - - if (retval_ptr) { - zval_ptr_dtor(&retval_ptr); - } - - return success; -} - -static int TWIG_CALL_ZZ(zval *object, char *method, zval *arg1, zval *arg2 TSRMLS_DC) -{ - zend_fcall_info fci; - zval **args[2]; - zval *zfunction; - zval *retval_ptr; - int success; - - args[0] = &arg1; - args[1] = &arg2; - - MAKE_STD_ZVAL(zfunction); - ZVAL_STRING(zfunction, method, 1); - fci.size = sizeof(fci); - fci.function_table = EG(function_table); - fci.function_name = zfunction; - fci.symbol_table = NULL; -#if PHP_VERSION_ID >= 50300 - fci.object_ptr = object; -#else - fci.object_pp = &object; -#endif - fci.retval_ptr_ptr = &retval_ptr; - fci.param_count = 2; - fci.params = args; - fci.no_separation = 0; - - if (zend_call_function(&fci, NULL TSRMLS_CC) == FAILURE) { - FREE_DTOR(zfunction); - return 0; - } - - FREE_DTOR(zfunction); - - success = (retval_ptr && (Z_TYPE_P(retval_ptr) == IS_BOOL) && Z_LVAL_P(retval_ptr)); - if (retval_ptr) { - zval_ptr_dtor(&retval_ptr); - } - - return success; -} - -#ifndef Z_SET_REFCOUNT_P -# define Z_SET_REFCOUNT_P(pz, rc) pz->refcount = rc -# define Z_UNSET_ISREF_P(pz) pz->is_ref = 0 -#endif - -static void TWIG_NEW(zval *object, char *class, zval *arg0, zval *arg1 TSRMLS_DC) -{ - zend_class_entry **pce; - - if (zend_lookup_class(class, strlen(class), &pce TSRMLS_CC) == FAILURE) { - return; - } - - Z_TYPE_P(object) = IS_OBJECT; - object_init_ex(object, *pce); - Z_SET_REFCOUNT_P(object, 1); - Z_UNSET_ISREF_P(object); - - TWIG_CALL_ZZ(object, "__construct", arg0, arg1 TSRMLS_CC); -} - -static int twig_add_array_key_to_string(void *pDest APPLY_TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) -{ - smart_str *buf; - char *joiner; - APPLY_TSRMLS_FETCH(); - - buf = va_arg(args, smart_str*); - joiner = va_arg(args, char*); - - if (buf->len != 0) { - smart_str_appends(buf, joiner); - } - - if (hash_key->nKeyLength == 0) { - smart_str_append_long(buf, (long) hash_key->h); - } else { - char *key, *tmp_str; - int key_len, tmp_len; - key = php_addcslashes(hash_key->arKey, hash_key->nKeyLength - 1, &key_len, 0, "'\\", 2 TSRMLS_CC); - tmp_str = php_str_to_str_ex(key, key_len, "\0", 1, "' . \"\\0\" . '", 12, &tmp_len, 0, NULL); - - smart_str_appendl(buf, tmp_str, tmp_len); - efree(key); - efree(tmp_str); - } - - return 0; -} - -static char *TWIG_IMPLODE_ARRAY_KEYS(char *joiner, zval *array TSRMLS_DC) -{ - smart_str collector = { 0, 0, 0 }; - - smart_str_appendl(&collector, "", 0); - zend_hash_apply_with_arguments(HASH_OF(array) APPLY_TSRMLS_CC, twig_add_array_key_to_string, 2, &collector, joiner); - smart_str_0(&collector); - - return collector.c; -} - -static void TWIG_RUNTIME_ERROR(zval *template TSRMLS_DC, char *message, ...) -{ - char *buffer; - va_list args; - zend_class_entry **pce; - zval *ex; - zval *constructor; - zval *zmessage; - zval *lineno; - zval *filename_func; - zval *filename; - zval *constructor_args[3]; - zval *constructor_retval; - - if (zend_lookup_class("Twig_Error_Runtime", strlen("Twig_Error_Runtime"), &pce TSRMLS_CC) == FAILURE) { - return; - } - - va_start(args, message); - vspprintf(&buffer, 0, message, args); - va_end(args); - - MAKE_STD_ZVAL(ex); - object_init_ex(ex, *pce); - - // Call Twig_Error constructor - MAKE_STD_ZVAL(constructor); - MAKE_STD_ZVAL(zmessage); - MAKE_STD_ZVAL(lineno); - MAKE_STD_ZVAL(filename); - MAKE_STD_ZVAL(filename_func); - MAKE_STD_ZVAL(constructor_retval); - - ZVAL_STRINGL(constructor, "__construct", sizeof("__construct")-1, 1); - ZVAL_STRING(zmessage, buffer, 1); - ZVAL_LONG(lineno, -1); - - // Get template filename - ZVAL_STRINGL(filename_func, "getTemplateName", sizeof("getTemplateName")-1, 1); - call_user_function(EG(function_table), &template, filename_func, filename, 0, 0 TSRMLS_CC); - - constructor_args[0] = zmessage; - constructor_args[1] = lineno; - constructor_args[2] = filename; - call_user_function(EG(function_table), &ex, constructor, constructor_retval, 3, constructor_args TSRMLS_CC); - - zval_ptr_dtor(&constructor_retval); - zval_ptr_dtor(&zmessage); - zval_ptr_dtor(&lineno); - zval_ptr_dtor(&filename); - FREE_DTOR(constructor); - FREE_DTOR(filename_func); - efree(buffer); - - zend_throw_exception_object(ex TSRMLS_CC); -} - -static char *TWIG_GET_CLASS_NAME(zval *object TSRMLS_DC) -{ - char *class_name; - zend_uint class_name_len; - - if (Z_TYPE_P(object) != IS_OBJECT) { - return ""; - } -#if PHP_API_VERSION >= 20100412 - zend_get_object_classname(object, (const char **) &class_name, &class_name_len TSRMLS_CC); -#else - zend_get_object_classname(object, &class_name, &class_name_len TSRMLS_CC); -#endif - return class_name; -} - -static int twig_add_method_to_class(void *pDest APPLY_TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) -{ - zend_class_entry *ce; - zval *retval; - char *item; - size_t item_len; - zend_function *mptr = (zend_function *) pDest; - APPLY_TSRMLS_FETCH(); - - if (!(mptr->common.fn_flags & ZEND_ACC_PUBLIC)) { - return 0; - } - - ce = *va_arg(args, zend_class_entry**); - retval = va_arg(args, zval*); - - item_len = strlen(mptr->common.function_name); - item = estrndup(mptr->common.function_name, item_len); - php_strtolower(item, item_len); - - if (strcmp("getenvironment", item) == 0) { - zend_class_entry **twig_template_ce; - if (zend_lookup_class("Twig_Template", strlen("Twig_Template"), &twig_template_ce TSRMLS_CC) == FAILURE) { - return 0; - } - if (instanceof_function(ce, *twig_template_ce TSRMLS_CC)) { - return 0; - } - } - - add_assoc_stringl_ex(retval, item, item_len+1, item, item_len, 0); - - return 0; -} - -static int twig_add_property_to_class(void *pDest APPLY_TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) -{ - zend_class_entry *ce; - zval *retval; - char *class_name, *prop_name; - zend_property_info *pptr = (zend_property_info *) pDest; - APPLY_TSRMLS_FETCH(); - - if (!(pptr->flags & ZEND_ACC_PUBLIC) || (pptr->flags & ZEND_ACC_STATIC)) { - return 0; - } - - ce = *va_arg(args, zend_class_entry**); - retval = va_arg(args, zval*); - -#if PHP_API_VERSION >= 20100412 - zend_unmangle_property_name(pptr->name, pptr->name_length, (const char **) &class_name, (const char **) &prop_name); -#else - zend_unmangle_property_name(pptr->name, pptr->name_length, &class_name, &prop_name); -#endif - - add_assoc_string(retval, prop_name, prop_name, 1); - - return 0; -} - -static void twig_add_class_to_cache(zval *cache, zval *object, char *class_name TSRMLS_DC) -{ - zval *class_info, *class_methods, *class_properties; - zend_class_entry *class_ce; - - class_ce = zend_get_class_entry(object TSRMLS_CC); - - ALLOC_INIT_ZVAL(class_info); - ALLOC_INIT_ZVAL(class_methods); - ALLOC_INIT_ZVAL(class_properties); - array_init(class_info); - array_init(class_methods); - array_init(class_properties); - // add all methods to self::cache[$class]['methods'] - zend_hash_apply_with_arguments(&class_ce->function_table APPLY_TSRMLS_CC, twig_add_method_to_class, 2, &class_ce, class_methods); - zend_hash_apply_with_arguments(&class_ce->properties_info APPLY_TSRMLS_CC, twig_add_property_to_class, 2, &class_ce, class_properties); - - add_assoc_zval(class_info, "methods", class_methods); - add_assoc_zval(class_info, "properties", class_properties); - add_assoc_zval(cache, class_name, class_info); -} - -/* {{{ proto mixed twig_template_get_attributes(TwigTemplate template, mixed object, mixed item, array arguments, string type, boolean isDefinedTest, boolean ignoreStrictCheck) - A C implementation of TwigTemplate::getAttribute() */ -PHP_FUNCTION(twig_template_get_attributes) -{ - zval *template; - zval *object; - char *item; - int item_len; - zval *zitem, ztmpitem; - zval *arguments = NULL; - zval *ret = NULL; - char *type = NULL; - int type_len = 0; - zend_bool isDefinedTest = 0; - zend_bool ignoreStrictCheck = 0; - int free_ret = 0; - zval *tmp_self_cache; - char *class_name = NULL; - zval *tmp_class; - char *type_name; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ozz|asbb", &template, &object, &zitem, &arguments, &type, &type_len, &isDefinedTest, &ignoreStrictCheck) == FAILURE) { - return; - } - - // convert the item to a string - ztmpitem = *zitem; - zval_copy_ctor(&ztmpitem); - convert_to_string(&ztmpitem); - item_len = Z_STRLEN(ztmpitem); - item = estrndup(Z_STRVAL(ztmpitem), item_len); - zval_dtor(&ztmpitem); - - if (!type) { - type = "any"; - } - -/* - // array - if (\Twig\Template::METHOD_CALL !== $type) { - $arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item; - - if ((is_array($object) && array_key_exists($arrayItem, $object)) - || ($object instanceof ArrayAccess && isset($object[$arrayItem])) - ) { - if ($isDefinedTest) { - return true; - } - - return $object[$arrayItem]; - } -*/ - - - if (strcmp("method", type) != 0) { - if ((TWIG_ARRAY_KEY_EXISTS(object, zitem)) - || (TWIG_INSTANCE_OF(object, zend_ce_arrayaccess TSRMLS_CC) && TWIG_ISSET_ARRAYOBJECT_ELEMENT(object, zitem TSRMLS_CC)) - ) { - - if (isDefinedTest) { - efree(item); - RETURN_TRUE; - } - - ret = TWIG_GET_ARRAY_ELEMENT_ZVAL(object, zitem TSRMLS_CC); - - if (!ret) { - ret = &EG(uninitialized_zval); - } - RETVAL_ZVAL(ret, 1, 0); - if (free_ret) { - zval_ptr_dtor(&ret); - } - efree(item); - return; - } -/* - if (\Twig\Template::ARRAY_CALL === $type) { - if ($isDefinedTest) { - return false; - } - if ($ignoreStrictCheck || !$this->env->isStrictVariables()) { - return null; - } -*/ - if (strcmp("array", type) == 0 || Z_TYPE_P(object) != IS_OBJECT) { - if (isDefinedTest) { - efree(item); - RETURN_FALSE; - } - if (ignoreStrictCheck || !TWIG_CALL_BOOLEAN(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "isStrictVariables" TSRMLS_CC)) { - efree(item); - return; - } -/* - if ($object instanceof ArrayAccess) { - $message = sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist', $arrayItem, get_class($object)); - } elseif (is_object($object)) { - $message = sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface', $item, get_class($object)); - } elseif (is_array($object)) { - if (empty($object)) { - $message = sprintf('Key "%s" does not exist as the array is empty', $arrayItem); - } else { - $message = sprintf('Key "%s" for array with keys "%s" does not exist', $arrayItem, implode(', ', array_keys($object))); - } - } elseif (\Twig\Template::ARRAY_CALL === $type) { - if (null === $object) { - $message = sprintf('Impossible to access a key ("%s") on a null variable', $item); - } else { - $message = sprintf('Impossible to access a key ("%s") on a %s variable ("%s")', $item, gettype($object), $object); - } - } elseif (null === $object) { - $message = sprintf('Impossible to access an attribute ("%s") on a null variable', $item); - } else { - $message = sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s")', $item, gettype($object), $object); - } - throw new \Twig\Error\RuntimeError($message, -1, $this->getTemplateName()); - } - } -*/ - if (TWIG_INSTANCE_OF(object, zend_ce_arrayaccess TSRMLS_CC)) { - TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Key \"%s\" in object with ArrayAccess of class \"%s\" does not exist.", item, TWIG_GET_CLASS_NAME(object TSRMLS_CC)); - } else if (Z_TYPE_P(object) == IS_OBJECT) { - TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Impossible to access a key \"%s\" on an object of class \"%s\" that does not implement ArrayAccess interface.", item, TWIG_GET_CLASS_NAME(object TSRMLS_CC)); - } else if (Z_TYPE_P(object) == IS_ARRAY) { - if (0 == zend_hash_num_elements(Z_ARRVAL_P(object))) { - TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Key \"%s\" does not exist as the array is empty.", item); - } else { - char *array_keys = TWIG_IMPLODE_ARRAY_KEYS(", ", object TSRMLS_CC); - TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Key \"%s\" for array with keys \"%s\" does not exist.", item, array_keys); - efree(array_keys); - } - } else { - char *type_name = zend_zval_type_name(object); - Z_ADDREF_P(object); - if (Z_TYPE_P(object) == IS_NULL) { - convert_to_string(object); - TWIG_RUNTIME_ERROR(template TSRMLS_CC, - (strcmp("array", type) == 0) - ? "Impossible to access a key (\"%s\") on a %s variable." - : "Impossible to access an attribute (\"%s\") on a %s variable.", - item, type_name); - } else { - convert_to_string(object); - TWIG_RUNTIME_ERROR(template TSRMLS_CC, - (strcmp("array", type) == 0) - ? "Impossible to access a key (\"%s\") on a %s variable (\"%s\")." - : "Impossible to access an attribute (\"%s\") on a %s variable (\"%s\").", - item, type_name, Z_STRVAL_P(object)); - } - zval_ptr_dtor(&object); - } - efree(item); - return; - } - } - -/* - if (!is_object($object)) { - if ($isDefinedTest) { - return false; - } -*/ - - if (Z_TYPE_P(object) != IS_OBJECT) { - if (isDefinedTest) { - efree(item); - RETURN_FALSE; - } -/* - if ($ignoreStrictCheck || !$this->env->isStrictVariables()) { - return null; - } - - if (null === $object) { - $message = sprintf('Impossible to invoke a method ("%s") on a null variable', $item); - } elseif (is_array($object)) { - $message = sprintf('Impossible to invoke a method ("%s") on an array.', $item); - } else { - $message = sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s")', $item, gettype($object), $object); - } - - throw new \Twig\Error\RuntimeError($message, -1, $this->getTemplateName()); - } -*/ - if (ignoreStrictCheck || !TWIG_CALL_BOOLEAN(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "isStrictVariables" TSRMLS_CC)) { - efree(item); - return; - } - - type_name = zend_zval_type_name(object); - Z_ADDREF_P(object); - if (Z_TYPE_P(object) == IS_NULL) { - TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Impossible to invoke a method (\"%s\") on a null variable.", item); - } else if (Z_TYPE_P(object) == IS_ARRAY) { - TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Impossible to invoke a method (\"%s\") on an array.", item); - } else { - convert_to_string_ex(&object); - - TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Impossible to invoke a method (\"%s\") on a %s variable (\"%s\").", item, type_name, Z_STRVAL_P(object)); - } - - zval_ptr_dtor(&object); - efree(item); - return; - } -/* - $class = get_class($object); -*/ - - class_name = TWIG_GET_CLASS_NAME(object TSRMLS_CC); - tmp_self_cache = TWIG_GET_STATIC_PROPERTY(template, "cache" TSRMLS_CC); - tmp_class = TWIG_GET_ARRAY_ELEMENT(tmp_self_cache, class_name, strlen(class_name) TSRMLS_CC); - - if (!tmp_class) { - twig_add_class_to_cache(tmp_self_cache, object, class_name TSRMLS_CC); - tmp_class = TWIG_GET_ARRAY_ELEMENT(tmp_self_cache, class_name, strlen(class_name) TSRMLS_CC); - } - efree(class_name); - -/* - // object property - if (\Twig\Template::METHOD_CALL !== $type && !$object instanceof \Twig\Template) { - if (isset($object->$item) || array_key_exists((string) $item, $object)) { - if ($isDefinedTest) { - return true; - } - - if ($this->env->hasExtension('\Twig\Extension\SandboxExtension')) { - $this->env->getExtension('\Twig\Extension\SandboxExtension')->checkPropertyAllowed($object, $item); - } - - return $object->$item; - } - } -*/ - if (strcmp("method", type) != 0 && !TWIG_INSTANCE_OF_USERLAND(object, "Twig_Template" TSRMLS_CC)) { - zval *tmp_properties, *tmp_item; - - tmp_properties = TWIG_GET_ARRAY_ELEMENT(tmp_class, "properties", strlen("properties") TSRMLS_CC); - tmp_item = TWIG_GET_ARRAY_ELEMENT(tmp_properties, item, item_len TSRMLS_CC); - - if (tmp_item || TWIG_HAS_PROPERTY(object, zitem TSRMLS_CC) || TWIG_HAS_DYNAMIC_PROPERTY(object, item, item_len TSRMLS_CC)) { - if (isDefinedTest) { - efree(item); - RETURN_TRUE; - } - if (TWIG_CALL_SB(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "hasExtension", "Twig_Extension_Sandbox" TSRMLS_CC)) { - TWIG_CALL_ZZ(TWIG_CALL_S(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "getExtension", "Twig_Extension_Sandbox" TSRMLS_CC), "checkPropertyAllowed", object, zitem TSRMLS_CC); - } - if (EG(exception)) { - efree(item); - return; - } - - ret = TWIG_PROPERTY(object, zitem TSRMLS_CC); - efree(item); - RETURN_ZVAL(ret, 1, 0); - } - } -/* - // object method - if (!isset(self::$cache[$class]['methods'])) { - if ($object instanceof self) { - $ref = new \ReflectionClass($class); - $methods = []; - - foreach ($ref->getMethods(ReflectionMethod::IS_PUBLIC) as $refMethod) { - $methodName = strtolower($refMethod->name); - - // Accessing the environment from templates is forbidden to prevent untrusted changes to the environment - if ('getenvironment' !== $methodName) { - $methods[$methodName] = true; - } - } - - self::$cache[$class]['methods'] = $methods; - } else { - self::$cache[$class]['methods'] = array_change_key_case(array_flip(get_class_methods($object))); - } - } - - $call = false; - $lcItem = strtolower($item); - if (isset(self::$cache[$class]['methods'][$lcItem])) { - $method = (string) $item; - } elseif (isset(self::$cache[$class]['methods']['get'.$lcItem])) { - $method = 'get'.$item; - } elseif (isset(self::$cache[$class]['methods']['is'.$lcItem])) { - $method = 'is'.$item; - } elseif (isset(self::$cache[$class]['methods']['__call'])) { - $method = (string) $item; - $call = true; -*/ - { - int call = 0; - char *lcItem = TWIG_STRTOLOWER(item, item_len); - int lcItem_length; - char *method = NULL; - char *methodForDeprecation = NULL; - char *tmp_method_name_get; - char *tmp_method_name_is; - zval *zmethod; - zval *tmp_methods; - - lcItem_length = strlen(lcItem); - tmp_method_name_get = emalloc(4 + lcItem_length); - tmp_method_name_is = emalloc(3 + lcItem_length); - - sprintf(tmp_method_name_get, "get%s", lcItem); - sprintf(tmp_method_name_is, "is%s", lcItem); - - tmp_methods = TWIG_GET_ARRAY_ELEMENT(tmp_class, "methods", strlen("methods") TSRMLS_CC); - methodForDeprecation = emalloc(item_len + 1); - sprintf(methodForDeprecation, "%s", item); - - if (TWIG_GET_ARRAY_ELEMENT(tmp_methods, lcItem, lcItem_length TSRMLS_CC)) { - method = item; - } else if (TWIG_GET_ARRAY_ELEMENT(tmp_methods, tmp_method_name_get, lcItem_length + 3 TSRMLS_CC)) { - method = tmp_method_name_get; - } else if (TWIG_GET_ARRAY_ELEMENT(tmp_methods, tmp_method_name_is, lcItem_length + 2 TSRMLS_CC)) { - method = tmp_method_name_is; - } else if (TWIG_GET_ARRAY_ELEMENT(tmp_methods, "__call", 6 TSRMLS_CC)) { - method = item; - call = 1; -/* - } else { - if ($isDefinedTest) { - return false; - } - - if ($ignoreStrictCheck || !$this->env->isStrictVariables()) { - return null; - } - - throw new \Twig\Error\RuntimeError(sprintf('Method "%s" for object "%s" does not exist.', $item, get_class($object)), -1, $this->getTemplateName()); - } - - if ($isDefinedTest) { - return true; - } -*/ - } else { - efree(tmp_method_name_get); - efree(tmp_method_name_is); - efree(lcItem); - - if (isDefinedTest) { - efree(item); - RETURN_FALSE; - } - if (ignoreStrictCheck || !TWIG_CALL_BOOLEAN(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "isStrictVariables" TSRMLS_CC)) { - efree(item); - return; - } - TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Neither the property \"%s\" nor one of the methods \"%s()\", \"get%s()\"/\"is%s()\" or \"__call()\" exist and have public access in class \"%s\".", item, item, item, item, TWIG_GET_CLASS_NAME(object TSRMLS_CC)); - efree(item); - return; - } - - if (isDefinedTest) { - efree(tmp_method_name_get); - efree(tmp_method_name_is); - efree(lcItem);efree(item); - RETURN_TRUE; - } -/* - if ($this->env->hasExtension('\Twig\Extension\SandboxExtension')) { - $this->env->getExtension('\Twig\Extension\SandboxExtension')->checkMethodAllowed($object, $method); - } -*/ - MAKE_STD_ZVAL(zmethod); - ZVAL_STRING(zmethod, method, 1); - if (TWIG_CALL_SB(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "hasExtension", "Twig_Extension_Sandbox" TSRMLS_CC)) { - TWIG_CALL_ZZ(TWIG_CALL_S(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "getExtension", "Twig_Extension_Sandbox" TSRMLS_CC), "checkMethodAllowed", object, zmethod TSRMLS_CC); - } - zval_ptr_dtor(&zmethod); - if (EG(exception)) { - efree(tmp_method_name_get); - efree(tmp_method_name_is); - efree(lcItem);efree(item); - return; - } -/* - // Some objects throw exceptions when they have __call, and the method we try - // to call is not supported. If ignoreStrictCheck is true, we should return null. - try { - $ret = call_user_func_array([$object, $method], $arguments); - } catch (\BadMethodCallException $e) { - if ($call && ($ignoreStrictCheck || !$this->env->isStrictVariables())) { - return null; - } - throw $e; - } -*/ - ret = TWIG_CALL_USER_FUNC_ARRAY(object, method, arguments TSRMLS_CC); - if (EG(exception) && TWIG_INSTANCE_OF(EG(exception), spl_ce_BadMethodCallException TSRMLS_CC)) { - if (ignoreStrictCheck || !TWIG_CALL_BOOLEAN(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "isStrictVariables" TSRMLS_CC)) { - efree(tmp_method_name_get); - efree(tmp_method_name_is); - efree(lcItem);efree(item); - zend_clear_exception(TSRMLS_C); - return; - } - } - free_ret = 1; - efree(tmp_method_name_get); - efree(tmp_method_name_is); - efree(lcItem); -/* - // @deprecated in 1.28 - if ($object instanceof Twig_TemplateInterface) { - $self = $object->getTemplateName() === $this->getTemplateName(); - $message = sprintf('Calling "%s" on template "%s" from template "%s" is deprecated since version 1.28 and won\'t be supported anymore in 2.0.', $item, $object->getTemplateName(), $this->getTemplateName()); - if ('renderBlock' === $method || 'displayBlock' === $method) { - $message .= sprintf(' Use block("%s"%s) instead).', $arguments[0], $self ? '' : ', template'); - } elseif ('hasBlock' === $method) { - $message .= sprintf(' Use "block("%s"%s) is defined" instead).', $arguments[0], $self ? '' : ', template'); - } elseif ('render' === $method || 'display' === $method) { - $message .= sprintf(' Use include("%s") instead).', $object->getTemplateName()); - } - @trigger_error($message, E_USER_DEPRECATED); - - return $ret === '' ? '' : new \Twig\Markup($ret, $this->env->getCharset()); - } - - return $ret; -*/ - efree(item); - // ret can be null, if e.g. the called method throws an exception - if (ret) { - if (TWIG_INSTANCE_OF_USERLAND(object, "Twig_TemplateInterface" TSRMLS_CC)) { - int self; - int old_error_reporting; - zval *object_filename; - zval *this_filename; - zval *filename_func; - char *deprecation_message_complement = NULL; - char *deprecation_message = NULL; - - MAKE_STD_ZVAL(object_filename); - MAKE_STD_ZVAL(this_filename); - MAKE_STD_ZVAL(filename_func); - - // Get templates names - ZVAL_STRINGL(filename_func, "getTemplateName", sizeof("getTemplateName")-1, 1); - call_user_function(EG(function_table), &object, filename_func, object_filename, 0, 0 TSRMLS_CC); - ZVAL_STRINGL(filename_func, "getTemplateName", sizeof("getTemplateName")-1, 1); - call_user_function(EG(function_table), &template, filename_func, this_filename, 0, 0 TSRMLS_CC); - - self = (strcmp(Z_STRVAL_P(object_filename), Z_STRVAL_P(this_filename)) == 0); - - if (strcmp(methodForDeprecation, "renderBlock") == 0 || strcmp(methodForDeprecation, "displayBlock") == 0) { - zval **arg0; - zend_hash_index_find(HASH_OF(arguments), 0, (void **) &arg0); - asprintf( - &deprecation_message_complement, - " Use block(\"%s\"%s) instead).", - Z_STRVAL_PP(arg0), - self ? "" : ", template" - ); - } else if (strcmp(methodForDeprecation, "hasBlock") == 0) { - zval **arg0; - zend_hash_index_find(HASH_OF(arguments), 0, (void **) &arg0); - asprintf( - &deprecation_message_complement, - " Use \"block(\"%s\"%s) is defined\" instead).", - Z_STRVAL_PP(arg0), - self ? "" : ", template" - ); - } else if (strcmp(methodForDeprecation, "render") == 0 || strcmp(methodForDeprecation, "display") == 0) { - asprintf( - &deprecation_message_complement, - " Use include(\"%s\") instead).", - Z_STRVAL_P(object_filename) - ); - } else { - deprecation_message_complement = (char*)calloc(0, sizeof(char)); - } - - asprintf( - &deprecation_message, - "Calling \"%s\" on template \"%s\" from template \"%s\" is deprecated since version 1.28 and won't be supported anymore in 2.0.%s", - methodForDeprecation, - Z_STRVAL_P(object_filename), - Z_STRVAL_P(this_filename), - deprecation_message_complement - ); - - old_error_reporting = EG(error_reporting); - EG(error_reporting) = 0; - zend_error(E_USER_DEPRECATED, "%s", deprecation_message); - EG(error_reporting) = old_error_reporting; - - FREE_DTOR(filename_func) - FREE_DTOR(object_filename) - FREE_DTOR(this_filename) - free(deprecation_message); - free(deprecation_message_complement); - - if (Z_STRLEN_P(ret) != 0) { - zval *charset = TWIG_CALL_USER_FUNC_ARRAY(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "getCharset", NULL TSRMLS_CC); - TWIG_NEW(return_value, "Twig_Markup", ret, charset TSRMLS_CC); - zval_ptr_dtor(&charset); - if (ret) { - zval_ptr_dtor(&ret); - } - efree(methodForDeprecation); - return; - } - } - - RETVAL_ZVAL(ret, 1, 0); - if (free_ret) { - zval_ptr_dtor(&ret); - } - } - - efree(methodForDeprecation); - } -} diff --git a/vendor/twig/twig/lib/Twig/Autoloader.php b/vendor/twig/twig/lib/Twig/Autoloader.php index e34e214..4b4d856 100644 --- a/vendor/twig/twig/lib/Twig/Autoloader.php +++ b/vendor/twig/twig/lib/Twig/Autoloader.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -@trigger_error('The Twig_Autoloader class is deprecated since version 1.21 and will be removed in 2.0. Use Composer instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Autoloader class is deprecated since version 1.21 and will be removed in 2.0. Use Composer instead.', \E_USER_DEPRECATED); /** * Autoloads Twig classes. @@ -27,7 +27,7 @@ class Twig_Autoloader */ public static function register($prepend = false) { - @trigger_error('Using Twig_Autoloader is deprecated since version 1.21. Use Composer instead.', E_USER_DEPRECATED); + @trigger_error('Using Twig_Autoloader is deprecated since version 1.21. Use Composer instead.', \E_USER_DEPRECATED); spl_autoload_register([__CLASS__, 'autoload'], true, $prepend); } diff --git a/vendor/twig/twig/lib/Twig/Filter.php b/vendor/twig/twig/lib/Twig/Filter.php index da4191e..3a1ff3d 100644 --- a/vendor/twig/twig/lib/Twig/Filter.php +++ b/vendor/twig/twig/lib/Twig/Filter.php @@ -11,7 +11,7 @@ use Twig\Node\Node; -@trigger_error('The Twig_Filter class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFilter instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Filter class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFilter instead.', \E_USER_DEPRECATED); /** * Represents a template filter. diff --git a/vendor/twig/twig/lib/Twig/Filter/Function.php b/vendor/twig/twig/lib/Twig/Filter/Function.php index 011d4cc..5648b3a 100644 --- a/vendor/twig/twig/lib/Twig/Filter/Function.php +++ b/vendor/twig/twig/lib/Twig/Filter/Function.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -@trigger_error('The Twig_Filter_Function class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFilter instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Filter_Function class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFilter instead.', \E_USER_DEPRECATED); /** * Represents a function template filter. diff --git a/vendor/twig/twig/lib/Twig/Filter/Method.php b/vendor/twig/twig/lib/Twig/Filter/Method.php index 5cd0628..1d505f4 100644 --- a/vendor/twig/twig/lib/Twig/Filter/Method.php +++ b/vendor/twig/twig/lib/Twig/Filter/Method.php @@ -11,7 +11,7 @@ use Twig\Extension\ExtensionInterface; -@trigger_error('The Twig_Filter_Method class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFilter instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Filter_Method class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFilter instead.', \E_USER_DEPRECATED); /** * Represents a method template filter. diff --git a/vendor/twig/twig/lib/Twig/Filter/Node.php b/vendor/twig/twig/lib/Twig/Filter/Node.php index 8bb2899..31c5021 100644 --- a/vendor/twig/twig/lib/Twig/Filter/Node.php +++ b/vendor/twig/twig/lib/Twig/Filter/Node.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -@trigger_error('The Twig_Filter_Node class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFilter instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Filter_Node class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFilter instead.', \E_USER_DEPRECATED); /** * Represents a template filter as a node. diff --git a/vendor/twig/twig/lib/Twig/Function.php b/vendor/twig/twig/lib/Twig/Function.php index 6646e74..d47bbc5 100644 --- a/vendor/twig/twig/lib/Twig/Function.php +++ b/vendor/twig/twig/lib/Twig/Function.php @@ -11,7 +11,7 @@ use Twig\Node\Node; -@trigger_error('The Twig_Function class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFunction instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Function class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFunction instead.', \E_USER_DEPRECATED); /** * Represents a template function. diff --git a/vendor/twig/twig/lib/Twig/Function/Function.php b/vendor/twig/twig/lib/Twig/Function/Function.php index 605d8d3..2e2498e 100644 --- a/vendor/twig/twig/lib/Twig/Function/Function.php +++ b/vendor/twig/twig/lib/Twig/Function/Function.php @@ -10,7 +10,7 @@ * file that was distributed with this source code. */ -@trigger_error('The Twig_Function_Function class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFunction instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Function_Function class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFunction instead.', \E_USER_DEPRECATED); /** * Represents a function template function. diff --git a/vendor/twig/twig/lib/Twig/Function/Method.php b/vendor/twig/twig/lib/Twig/Function/Method.php index 9e472c5..dd798cf 100644 --- a/vendor/twig/twig/lib/Twig/Function/Method.php +++ b/vendor/twig/twig/lib/Twig/Function/Method.php @@ -12,7 +12,7 @@ use Twig\Extension\ExtensionInterface; -@trigger_error('The Twig_Function_Method class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFunction instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Function_Method class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFunction instead.', \E_USER_DEPRECATED); /** * Represents a method template function. diff --git a/vendor/twig/twig/lib/Twig/Function/Node.php b/vendor/twig/twig/lib/Twig/Function/Node.php index 8148ec3..8b906ca 100644 --- a/vendor/twig/twig/lib/Twig/Function/Node.php +++ b/vendor/twig/twig/lib/Twig/Function/Node.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -@trigger_error('The Twig_Function_Node class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFunction instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Function_Node class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFunction instead.', \E_USER_DEPRECATED); /** * Represents a template function as a node. diff --git a/vendor/twig/twig/lib/Twig/Loader/String.php b/vendor/twig/twig/lib/Twig/Loader/String.php index cb3b2a0..0beaed8 100644 --- a/vendor/twig/twig/lib/Twig/Loader/String.php +++ b/vendor/twig/twig/lib/Twig/Loader/String.php @@ -14,7 +14,7 @@ use Twig\Loader\SourceContextLoaderInterface; use Twig\Source; -@trigger_error('The Twig_Loader_String class is deprecated since version 1.18.1 and will be removed in 2.0. Use "Twig\Loader\ArrayLoader" instead or "Twig\Environment::createTemplate()".', E_USER_DEPRECATED); +@trigger_error('The Twig_Loader_String class is deprecated since version 1.18.1 and will be removed in 2.0. Use "Twig\Loader\ArrayLoader" instead or "Twig\Environment::createTemplate()".', \E_USER_DEPRECATED); /** * Loads a template from a string. @@ -36,7 +36,7 @@ class Twig_Loader_String implements LoaderInterface, ExistsLoaderInterface, Sour { public function getSource($name) { - @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', static::class), E_USER_DEPRECATED); + @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', static::class), \E_USER_DEPRECATED); return $name; } diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/ExtensionReference.php b/vendor/twig/twig/lib/Twig/Node/Expression/ExtensionReference.php index 9b8927a..298067f 100644 --- a/vendor/twig/twig/lib/Twig/Node/Expression/ExtensionReference.php +++ b/vendor/twig/twig/lib/Twig/Node/Expression/ExtensionReference.php @@ -12,7 +12,7 @@ use Twig\Compiler; use Twig\Node\Expression\AbstractExpression; -@trigger_error('The Twig_Node_Expression_ExtensionReference class is deprecated since version 1.23 and will be removed in 2.0.', E_USER_DEPRECATED); +@trigger_error('The Twig_Node_Expression_ExtensionReference class is deprecated since version 1.23 and will be removed in 2.0.', \E_USER_DEPRECATED); /** * Represents an extension call node. diff --git a/vendor/twig/twig/lib/Twig/TemplateInterface.php b/vendor/twig/twig/lib/Twig/TemplateInterface.php index 0f767b8..966bf2e 100644 --- a/vendor/twig/twig/lib/Twig/TemplateInterface.php +++ b/vendor/twig/twig/lib/Twig/TemplateInterface.php @@ -20,9 +20,9 @@ */ interface Twig_TemplateInterface { - const ANY_CALL = 'any'; - const ARRAY_CALL = 'array'; - const METHOD_CALL = 'method'; + public const ANY_CALL = 'any'; + public const ARRAY_CALL = 'array'; + public const METHOD_CALL = 'method'; /** * Renders the template with the given context and returns it as string. diff --git a/vendor/twig/twig/lib/Twig/Test.php b/vendor/twig/twig/lib/Twig/Test.php index d032284..1613284 100644 --- a/vendor/twig/twig/lib/Twig/Test.php +++ b/vendor/twig/twig/lib/Twig/Test.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -@trigger_error('The Twig_Test class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigTest instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Test class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigTest instead.', \E_USER_DEPRECATED); /** * Represents a template test. diff --git a/vendor/twig/twig/lib/Twig/Test/Function.php b/vendor/twig/twig/lib/Twig/Test/Function.php index a789c40..4f125df 100644 --- a/vendor/twig/twig/lib/Twig/Test/Function.php +++ b/vendor/twig/twig/lib/Twig/Test/Function.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -@trigger_error('The Twig_Test_Function class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigTest instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Test_Function class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigTest instead.', \E_USER_DEPRECATED); /** * Represents a function template test. diff --git a/vendor/twig/twig/lib/Twig/Test/Method.php b/vendor/twig/twig/lib/Twig/Test/Method.php index 4f16142..1618566 100644 --- a/vendor/twig/twig/lib/Twig/Test/Method.php +++ b/vendor/twig/twig/lib/Twig/Test/Method.php @@ -11,7 +11,7 @@ use Twig\Extension\ExtensionInterface; -@trigger_error('The Twig_Test_Method class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigTest instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Test_Method class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigTest instead.', \E_USER_DEPRECATED); /** * Represents a method template test. diff --git a/vendor/twig/twig/lib/Twig/Test/Node.php b/vendor/twig/twig/lib/Twig/Test/Node.php index 6b5de15..96f2076 100644 --- a/vendor/twig/twig/lib/Twig/Test/Node.php +++ b/vendor/twig/twig/lib/Twig/Test/Node.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -@trigger_error('The Twig_Test_Node class is deprecated since version 1.12 and will be removed in 2.0.', E_USER_DEPRECATED); +@trigger_error('The Twig_Test_Node class is deprecated since version 1.12 and will be removed in 2.0.', \E_USER_DEPRECATED); /** * Represents a template test as a Node. diff --git a/vendor/twig/twig/lib/Twig/TokenParserBroker.php b/vendor/twig/twig/lib/Twig/TokenParserBroker.php index 8cca809..5f30ff0 100644 --- a/vendor/twig/twig/lib/Twig/TokenParserBroker.php +++ b/vendor/twig/twig/lib/Twig/TokenParserBroker.php @@ -33,7 +33,7 @@ class Twig_TokenParserBroker implements Twig_TokenParserBrokerInterface public function __construct($parsers = [], $brokers = [], $triggerDeprecationError = true) { if ($triggerDeprecationError) { - @trigger_error('The '.__CLASS__.' class is deprecated since version 1.12 and will be removed in 2.0.', E_USER_DEPRECATED); + @trigger_error('The '.__CLASS__.' class is deprecated since version 1.12 and will be removed in 2.0.', \E_USER_DEPRECATED); } foreach ($parsers as $parser) { diff --git a/vendor/twig/twig/src/Cache/FilesystemCache.php b/vendor/twig/twig/src/Cache/FilesystemCache.php index b7c1e43..cd6b663 100644 --- a/vendor/twig/twig/src/Cache/FilesystemCache.php +++ b/vendor/twig/twig/src/Cache/FilesystemCache.php @@ -18,7 +18,7 @@ */ class FilesystemCache implements CacheInterface { - const FORCE_BYTECODE_INVALIDATION = 1; + public const FORCE_BYTECODE_INVALIDATION = 1; private $directory; private $options; @@ -67,7 +67,7 @@ public function write($key, $content) if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) { // Compile cached file into bytecode cache - if (\function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN)) { + if (\function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN)) { @opcache_invalidate($key, true); } elseif (\function_exists('apc_compile_file')) { apc_compile_file($key); diff --git a/vendor/twig/twig/src/Compiler.php b/vendor/twig/twig/src/Compiler.php index e47003a..e8ddf7b 100644 --- a/vendor/twig/twig/src/Compiler.php +++ b/vendor/twig/twig/src/Compiler.php @@ -41,7 +41,7 @@ public function __construct(Environment $env) */ public function getFilename() { - @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), \E_USER_DEPRECATED); return $this->filename; } @@ -143,7 +143,7 @@ public function write() */ public function addIndentation() { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use write(\'\') instead.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use write(\'\') instead.', \E_USER_DEPRECATED); $this->source .= str_repeat(' ', $this->indentation * 4); @@ -174,14 +174,14 @@ public function string($value) public function repr($value) { if (\is_int($value) || \is_float($value)) { - if (false !== $locale = setlocale(LC_NUMERIC, '0')) { - setlocale(LC_NUMERIC, 'C'); + if (false !== $locale = setlocale(\LC_NUMERIC, '0')) { + setlocale(\LC_NUMERIC, 'C'); } $this->raw(var_export($value, true)); if (false !== $locale) { - setlocale(LC_NUMERIC, $locale); + setlocale(\LC_NUMERIC, $locale); } } elseif (null === $value) { $this->raw('null'); @@ -221,7 +221,7 @@ public function addDebugInfo(\Twig_NodeInterface $node) // mb_substr_count() replaces substr_count() // but they have different signatures! if (((int) ini_get('mbstring.func_overload')) & 2) { - @trigger_error('Support for having "mbstring.func_overload" different from 0 is deprecated version 1.29 and will be removed in 2.0.', E_USER_DEPRECATED); + @trigger_error('Support for having "mbstring.func_overload" different from 0 is deprecated version 1.29 and will be removed in 2.0.', \E_USER_DEPRECATED); // this is much slower than the "right" version $this->sourceLine += mb_substr_count(mb_substr($this->source, $this->sourceOffset), "\n"); diff --git a/vendor/twig/twig/src/Environment.php b/vendor/twig/twig/src/Environment.php index e3243fa..c4eba5b 100644 --- a/vendor/twig/twig/src/Environment.php +++ b/vendor/twig/twig/src/Environment.php @@ -41,12 +41,12 @@ */ class Environment { - const VERSION = '1.44.2'; - const VERSION_ID = 14402; - const MAJOR_VERSION = 1; - const MINOR_VERSION = 44; - const RELEASE_VERSION = 2; - const EXTRA_VERSION = ''; + public const VERSION = '1.44.5'; + public const VERSION_ID = 14405; + public const MAJOR_VERSION = 1; + public const MINOR_VERSION = 44; + public const RELEASE_VERSION = 5; + public const EXTRA_VERSION = ''; protected $charset; protected $loader; @@ -124,7 +124,7 @@ public function __construct(LoaderInterface $loader = null, $options = []) if (null !== $loader) { $this->setLoader($loader); } else { - @trigger_error('Not passing a "Twig\Lodaer\LoaderInterface" as the first constructor argument of "Twig\Environment" is deprecated since version 1.21.', E_USER_DEPRECATED); + @trigger_error('Not passing a "Twig\Lodaer\LoaderInterface" as the first constructor argument of "Twig\Environment" is deprecated since version 1.21.', \E_USER_DEPRECATED); } $options = array_merge([ @@ -139,7 +139,7 @@ public function __construct(LoaderInterface $loader = null, $options = []) ], $options); $this->debug = (bool) $options['debug']; - $this->charset = strtoupper($options['charset']); + $this->charset = null === $options['charset'] ? null : strtoupper($options['charset']); $this->baseTemplateClass = $options['base_template_class']; $this->autoReload = null === $options['auto_reload'] ? $this->debug : (bool) $options['auto_reload']; $this->strictVariables = (bool) $options['strict_variables']; @@ -154,14 +154,14 @@ public function __construct(LoaderInterface $loader = null, $options = []) if (\is_string($this->originalCache)) { $r = new \ReflectionMethod($this, 'writeCacheFile'); if (__CLASS__ !== $r->getDeclaringClass()->getName()) { - @trigger_error('The Twig\Environment::writeCacheFile method is deprecated since version 1.22 and will be removed in Twig 2.0.', E_USER_DEPRECATED); + @trigger_error('The Twig\Environment::writeCacheFile method is deprecated since version 1.22 and will be removed in Twig 2.0.', \E_USER_DEPRECATED); $this->bcWriteCacheFile = true; } $r = new \ReflectionMethod($this, 'getCacheFilename'); if (__CLASS__ !== $r->getDeclaringClass()->getName()) { - @trigger_error('The Twig\Environment::getCacheFilename method is deprecated since version 1.22 and will be removed in Twig 2.0.', E_USER_DEPRECATED); + @trigger_error('The Twig\Environment::getCacheFilename method is deprecated since version 1.22 and will be removed in Twig 2.0.', \E_USER_DEPRECATED); $this->bcGetCacheFilename = true; } @@ -301,13 +301,13 @@ public function setCache($cache) $this->originalCache = $cache; $this->cache = new NullCache(); } elseif (null === $cache) { - @trigger_error('Using "null" as the cache strategy is deprecated since version 1.23 and will be removed in Twig 2.0.', E_USER_DEPRECATED); + @trigger_error('Using "null" as the cache strategy is deprecated since version 1.23 and will be removed in Twig 2.0.', \E_USER_DEPRECATED); $this->originalCache = false; $this->cache = new NullCache(); } elseif ($cache instanceof CacheInterface) { $this->originalCache = $this->cache = $cache; } else { - throw new \LogicException(sprintf('Cache can only be a string, false, or a \Twig\Cache\CacheInterface implementation.')); + throw new \LogicException('Cache can only be a string, false, or a \Twig\Cache\CacheInterface implementation.'); } } @@ -322,7 +322,7 @@ public function setCache($cache) */ public function getCacheFilename($name) { - @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), \E_USER_DEPRECATED); $key = $this->cache->generateKey($name, $this->getTemplateClass($name)); @@ -362,7 +362,7 @@ public function getTemplateClass($name, $index = null) */ public function getTemplateClassPrefix() { - @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), \E_USER_DEPRECATED); return $this->templateClassPrefix; } @@ -626,7 +626,7 @@ public function resolveTemplate($names) */ public function clearTemplateCache() { - @trigger_error(sprintf('The %s method is deprecated since version 1.18.3 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s method is deprecated since version 1.18.3 and will be removed in Twig 2.0.', __METHOD__), \E_USER_DEPRECATED); $this->loadedTemplates = []; } @@ -638,7 +638,7 @@ public function clearTemplateCache() */ public function clearCacheFiles() { - @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), \E_USER_DEPRECATED); if (\is_string($this->originalCache)) { foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->originalCache), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { @@ -658,7 +658,7 @@ public function clearCacheFiles() */ public function getLexer() { - @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), \E_USER_DEPRECATED); if (null === $this->lexer) { $this->lexer = new Lexer($this); @@ -685,7 +685,7 @@ public function setLexer(\Twig_LexerInterface $lexer) public function tokenize($source, $name = null) { if (!$source instanceof Source) { - @trigger_error(sprintf('Passing a string as the $source argument of %s() is deprecated since version 1.27. Pass a Twig\Source instance instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('Passing a string as the $source argument of %s() is deprecated since version 1.27. Pass a Twig\Source instance instead.', __METHOD__), \E_USER_DEPRECATED); $source = new Source($source, $name); } @@ -705,7 +705,7 @@ public function tokenize($source, $name = null) */ public function getParser() { - @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), \E_USER_DEPRECATED); if (null === $this->parser) { $this->parser = new Parser($this); @@ -744,7 +744,7 @@ public function parse(TokenStream $stream) */ public function getCompiler() { - @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), \E_USER_DEPRECATED); if (null === $this->compiler) { $this->compiler = new Compiler($this); @@ -785,7 +785,7 @@ public function compile(\Twig_NodeInterface $node) public function compileSource($source, $name = null) { if (!$source instanceof Source) { - @trigger_error(sprintf('Passing a string as the $source argument of %s() is deprecated since version 1.27. Pass a Twig\Source instance instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('Passing a string as the $source argument of %s() is deprecated since version 1.27. Pass a Twig\Source instance instead.', __METHOD__), \E_USER_DEPRECATED); $source = new Source($source, $name); } @@ -802,7 +802,7 @@ public function compileSource($source, $name = null) public function setLoader(LoaderInterface $loader) { if (!$loader instanceof SourceContextLoaderInterface && 0 !== strpos(\get_class($loader), 'Mock_')) { - @trigger_error(sprintf('Twig loader "%s" should implement Twig\Loader\SourceContextLoaderInterface since version 1.27.', \get_class($loader)), E_USER_DEPRECATED); + @trigger_error(sprintf('Twig loader "%s" should implement Twig\Loader\SourceContextLoaderInterface since version 1.27.', \get_class($loader)), \E_USER_DEPRECATED); } $this->loader = $loader; @@ -857,7 +857,7 @@ public function initRuntime() $parentClass = $m->getDeclaringClass()->getName(); if ('Twig_Extension' !== $parentClass && 'Twig\Extension\AbstractExtension' !== $parentClass) { - @trigger_error(sprintf('Defining the initRuntime() method in the "%s" extension is deprecated since version 1.23. Use the `needs_environment` option to get the \Twig_Environment instance in filters, functions, or tests; or explicitly implement Twig\Extension\InitRuntimeInterface if needed (not recommended).', $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Defining the initRuntime() method in the "%s" extension is deprecated since version 1.23. Use the `needs_environment` option to get the \Twig_Environment instance in filters, functions, or tests; or explicitly implement Twig\Extension\InitRuntimeInterface if needed (not recommended).', $name), \E_USER_DEPRECATED); } } @@ -883,7 +883,7 @@ public function hasExtension($class) if (isset($this->extensions[$class])) { if ($class !== \get_class($this->extensions[$class])) { - @trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), E_USER_DEPRECATED); + @trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), \E_USER_DEPRECATED); } return true; @@ -918,7 +918,7 @@ public function getExtension($class) if (isset($this->extensions[$class])) { if ($class !== \get_class($this->extensions[$class])) { - @trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), E_USER_DEPRECATED); + @trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), \E_USER_DEPRECATED); } return $this->extensions[$class]; @@ -965,7 +965,7 @@ public function addExtension(ExtensionInterface $extension) if ($class !== $extension->getName()) { if (isset($this->extensions[$extension->getName()])) { unset($this->extensions[$extension->getName()], $this->extensionsByClass[$class]); - @trigger_error(sprintf('The possibility to register the same extension twice ("%s") is deprecated since version 1.23 and will be removed in Twig 2.0. Use proper PHP inheritance instead.', $extension->getName()), E_USER_DEPRECATED); + @trigger_error(sprintf('The possibility to register the same extension twice ("%s") is deprecated since version 1.23 and will be removed in Twig 2.0. Use proper PHP inheritance instead.', $extension->getName()), \E_USER_DEPRECATED); } } @@ -986,7 +986,7 @@ public function addExtension(ExtensionInterface $extension) */ public function removeExtension($name) { - @trigger_error(sprintf('The %s method is deprecated since version 1.12 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s method is deprecated since version 1.12 and will be removed in Twig 2.0.', __METHOD__), \E_USER_DEPRECATED); if ($this->extensionInitialized) { throw new \LogicException(sprintf('Unable to remove extension "%s" as extensions have already been initialized.', $name)); @@ -1001,7 +1001,7 @@ public function removeExtension($name) if (isset($this->extensions[$class])) { if ($class !== \get_class($this->extensions[$class])) { - @trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), E_USER_DEPRECATED); + @trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), \E_USER_DEPRECATED); } unset($this->extensions[$class]); @@ -1120,7 +1120,7 @@ public function addFilter($name, $filter = null) $filter = $name; $name = $filter->getName(); } else { - @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleFilter" instead when defining filter "%s".', __METHOD__, $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleFilter" instead when defining filter "%s".', __METHOD__, $name), \E_USER_DEPRECATED); } if ($this->extensionInitialized) { @@ -1215,7 +1215,7 @@ public function addTest($name, $test = null) $test = $name; $name = $test->getName(); } else { - @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleTest" instead when defining test "%s".', __METHOD__, $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleTest" instead when defining test "%s".', __METHOD__, $name), \E_USER_DEPRECATED); } if ($this->extensionInitialized) { @@ -1292,7 +1292,7 @@ public function addFunction($name, $function = null) $function = $name; $name = $function->getName(); } else { - @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleFunction" instead when defining function "%s".', __METHOD__, $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleFunction" instead when defining function "%s".', __METHOD__, $name), \E_USER_DEPRECATED); } if ($this->extensionInitialized) { @@ -1389,7 +1389,7 @@ public function addGlobal($name, $value) if (!\array_key_exists($name, $this->globals)) { // The deprecation notice must be turned into the following exception in Twig 2.0 - @trigger_error(sprintf('Registering global variable "%s" at runtime or when the extensions have already been initialized is deprecated since version 1.21.', $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Registering global variable "%s" at runtime or when the extensions have already been initialized is deprecated since version 1.21.', $name), \E_USER_DEPRECATED); //throw new \LogicException(sprintf('Unable to add global "%s" as the runtime or the extensions have already been initialized.', $name)); } } @@ -1479,7 +1479,7 @@ public function getBinaryOperators() */ public function computeAlternatives($name, $items) { - @trigger_error(sprintf('The %s method is deprecated since version 1.23 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s method is deprecated since version 1.23 and will be removed in Twig 2.0.', __METHOD__), \E_USER_DEPRECATED); return SyntaxError::computeAlternatives($name, $items); } @@ -1496,7 +1496,7 @@ protected function initGlobals() $parentClass = $m->getDeclaringClass()->getName(); if ('Twig_Extension' !== $parentClass && 'Twig\Extension\AbstractExtension' !== $parentClass) { - @trigger_error(sprintf('Defining the getGlobals() method in the "%s" extension without explicitly implementing Twig\Extension\GlobalsInterface is deprecated since version 1.23.', $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Defining the getGlobals() method in the "%s" extension without explicitly implementing Twig\Extension\GlobalsInterface is deprecated since version 1.23.', $name), \E_USER_DEPRECATED); } } @@ -1548,7 +1548,7 @@ protected function initExtension(ExtensionInterface $extension) if ($filter instanceof TwigFilter) { $name = $filter->getName(); } else { - @trigger_error(sprintf('Using an instance of "%s" for filter "%s" is deprecated since version 1.21. Use \Twig_SimpleFilter instead.', \get_class($filter), $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Using an instance of "%s" for filter "%s" is deprecated since version 1.21. Use \Twig_SimpleFilter instead.', \get_class($filter), $name), \E_USER_DEPRECATED); } $this->filters[$name] = $filter; @@ -1559,7 +1559,7 @@ protected function initExtension(ExtensionInterface $extension) if ($function instanceof TwigFunction) { $name = $function->getName(); } else { - @trigger_error(sprintf('Using an instance of "%s" for function "%s" is deprecated since version 1.21. Use \Twig_SimpleFunction instead.', \get_class($function), $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Using an instance of "%s" for function "%s" is deprecated since version 1.21. Use \Twig_SimpleFunction instead.', \get_class($function), $name), \E_USER_DEPRECATED); } $this->functions[$name] = $function; @@ -1570,7 +1570,7 @@ protected function initExtension(ExtensionInterface $extension) if ($test instanceof TwigTest) { $name = $test->getName(); } else { - @trigger_error(sprintf('Using an instance of "%s" for test "%s" is deprecated since version 1.21. Use \Twig_SimpleTest instead.', \get_class($test), $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Using an instance of "%s" for test "%s" is deprecated since version 1.21. Use \Twig_SimpleTest instead.', \get_class($test), $name), \E_USER_DEPRECATED); } $this->tests[$name] = $test; @@ -1581,7 +1581,7 @@ protected function initExtension(ExtensionInterface $extension) if ($parser instanceof TokenParserInterface) { $this->parsers->addTokenParser($parser); } elseif ($parser instanceof \Twig_TokenParserBrokerInterface) { - @trigger_error('Registering a \Twig_TokenParserBrokerInterface instance is deprecated since version 1.21.', E_USER_DEPRECATED); + @trigger_error('Registering a \Twig_TokenParserBrokerInterface instance is deprecated since version 1.21.', \E_USER_DEPRECATED); $this->parsers->addTokenParserBroker($parser); } else { @@ -1623,8 +1623,8 @@ private function updateOptionsHash() array_keys($this->extensions), [ (int) \function_exists('twig_template_get_attributes'), - PHP_MAJOR_VERSION, - PHP_MINOR_VERSION, + \PHP_MAJOR_VERSION, + \PHP_MINOR_VERSION, self::VERSION, (int) $this->debug, $this->baseTemplateClass, diff --git a/vendor/twig/twig/src/Error/Error.php b/vendor/twig/twig/src/Error/Error.php index 2aa70f1..3b781ff 100644 --- a/vendor/twig/twig/src/Error/Error.php +++ b/vendor/twig/twig/src/Error/Error.php @@ -96,7 +96,7 @@ public function getRawMessage() */ public function getTemplateFile() { - @trigger_error(sprintf('The "%s" method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The "%s" method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), \E_USER_DEPRECATED); return $this->filename; } @@ -110,7 +110,7 @@ public function getTemplateFile() */ public function setTemplateFile($name) { - @trigger_error(sprintf('The "%s" method is deprecated since version 1.27 and will be removed in 2.0. Use setSourceContext() instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The "%s" method is deprecated since version 1.27 and will be removed in 2.0. Use setSourceContext() instead.', __METHOD__), \E_USER_DEPRECATED); $this->filename = $name; @@ -126,7 +126,7 @@ public function setTemplateFile($name) */ public function getTemplateName() { - @trigger_error(sprintf('The "%s" method is deprecated since version 1.29 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The "%s" method is deprecated since version 1.29 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), \E_USER_DEPRECATED); return $this->filename; } @@ -140,7 +140,7 @@ public function getTemplateName() */ public function setTemplateName($name) { - @trigger_error(sprintf('The "%s" method is deprecated since version 1.29 and will be removed in 2.0. Use setSourceContext() instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The "%s" method is deprecated since version 1.29 and will be removed in 2.0. Use setSourceContext() instead.', __METHOD__), \E_USER_DEPRECATED); $this->filename = $name; $this->sourceCode = $this->sourcePath = null; @@ -264,11 +264,11 @@ protected function guessTemplateInfo() $template = null; $templateClass = null; - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); + $backtrace = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS | \DEBUG_BACKTRACE_PROVIDE_OBJECT); foreach ($backtrace as $trace) { if (isset($trace['object']) && $trace['object'] instanceof Template && 'Twig_Template' !== \get_class($trace['object'])) { $currentClass = \get_class($trace['object']); - $isEmbedContainer = 0 === strpos($templateClass, $currentClass); + $isEmbedContainer = null === $templateClass ? false : 0 === strpos($templateClass, $currentClass); if (null === $this->filename || ($this->filename == $trace['object']->getTemplateName() && !$isEmbedContainer)) { $template = $trace['object']; $templateClass = \get_class($trace['object']); diff --git a/vendor/twig/twig/src/ExpressionParser.php b/vendor/twig/twig/src/ExpressionParser.php index fa480a0..83d8802 100644 --- a/vendor/twig/twig/src/ExpressionParser.php +++ b/vendor/twig/twig/src/ExpressionParser.php @@ -43,8 +43,8 @@ */ class ExpressionParser { - const OPERATOR_LEFT = 1; - const OPERATOR_RIGHT = 2; + public const OPERATOR_LEFT = 1; + public const OPERATOR_RIGHT = 2; protected $parser; protected $unaryOperators; @@ -61,7 +61,7 @@ public function __construct(Parser $parser, $env = null) $this->unaryOperators = $env->getUnaryOperators(); $this->binaryOperators = $env->getBinaryOperators(); } else { - @trigger_error('Passing the operators as constructor arguments to '.__METHOD__.' is deprecated since version 1.27. Pass the environment instead.', E_USER_DEPRECATED); + @trigger_error('Passing the operators as constructor arguments to '.__METHOD__.' is deprecated since version 1.27. Pass the environment instead.', \E_USER_DEPRECATED); $this->env = $parser->getEnvironment(); $this->unaryOperators = func_get_arg(1); @@ -632,7 +632,7 @@ public function parseArguments($namedArguments = false, $definition = false, $al $value = $this->parsePrimaryExpression(); if (!$this->checkConstantExpression($value)) { - throw new SyntaxError(sprintf('A default value for an argument must be a constant (a boolean, a string, a number, or an array).'), $token->getLine(), $stream->getSourceContext()); + throw new SyntaxError('A default value for an argument must be a constant (a boolean, a string, a number, or an array).', $token->getLine(), $stream->getSourceContext()); } } else { $value = $this->parseExpression(0, $allowArrow); @@ -758,7 +758,7 @@ private function getTestNodeClass($test) $src = $stream->getSourceContext(); $message .= sprintf(' in %s at line %d.', $src->getPath() ?: $src->getName(), $stream->getCurrent()->getLine()); - @trigger_error($message, E_USER_DEPRECATED); + @trigger_error($message, \E_USER_DEPRECATED); } if ($test instanceof TwigTest) { @@ -788,7 +788,7 @@ protected function getFunctionNodeClass($name, $line) $src = $this->parser->getStream()->getSourceContext(); $message .= sprintf(' in %s at line %d.', $src->getPath() ?: $src->getName(), $line); - @trigger_error($message, E_USER_DEPRECATED); + @trigger_error($message, \E_USER_DEPRECATED); } if ($function instanceof TwigFunction) { @@ -818,7 +818,7 @@ protected function getFilterNodeClass($name, $line) $src = $this->parser->getStream()->getSourceContext(); $message .= sprintf(' in %s at line %d.', $src->getPath() ?: $src->getName(), $line); - @trigger_error($message, E_USER_DEPRECATED); + @trigger_error($message, \E_USER_DEPRECATED); } if ($filter instanceof TwigFilter) { diff --git a/vendor/twig/twig/src/Extension/CoreExtension.php b/vendor/twig/twig/src/Extension/CoreExtension.php index b52cb29..e64696b 100644 --- a/vendor/twig/twig/src/Extension/CoreExtension.php +++ b/vendor/twig/twig/src/Extension/CoreExtension.php @@ -349,7 +349,7 @@ function twig_cycle($values, $position) function twig_random(Environment $env, $values = null, $max = null) { if (null === $values) { - return null === $max ? mt_rand() : mt_rand(0, $max); + return null === $max ? mt_rand() : mt_rand(0, (int) $max); } if (\is_int($values) || \is_float($values)) { @@ -366,7 +366,7 @@ function twig_random(Environment $env, $values = null, $max = null) $max = $max; } - return mt_rand($min, $max); + return mt_rand((int) $min, (int) $max); } if (\is_string($values)) { @@ -489,6 +489,10 @@ function twig_date_converter(Environment $env, $date = null, $timezone = null) } if (null === $date || 'now' === $date) { + if (null === $date) { + $date = 'now'; + } + return new \DateTime($date, false !== $timezone ? $timezone : $env->getExtension('\Twig\Extension\CoreExtension')->getTimezone()); } @@ -511,14 +515,14 @@ function twig_date_converter(Environment $env, $date = null, $timezone = null) * * @param string $str String to replace in * @param array|\Traversable $from Replace values - * @param string|null $to Replace to, deprecated (@see https://secure.php.net/manual/en/function.strtr.php) + * @param string|null $to Replace to, deprecated (@see https://www.php.net/manual/en/function.strtr.php) * * @return string */ function twig_replace_filter($str, $from, $to = null) { if (\is_string($from) && \is_string($to)) { - @trigger_error('Using "replace" with character by character replacement is deprecated since version 1.22 and will be removed in Twig 2.0', E_USER_DEPRECATED); + @trigger_error('Using "replace" with character by character replacement is deprecated since version 1.22 and will be removed in Twig 2.0', \E_USER_DEPRECATED); return strtr($str, $from, $to); } @@ -595,7 +599,7 @@ function twig_urlencode_filter($url) { if (\is_array($url)) { if (\defined('PHP_QUERY_RFC3986')) { - return http_build_query($url, '', '&', PHP_QUERY_RFC3986); + return http_build_query($url, '', '&', \PHP_QUERY_RFC3986); } return http_build_query($url, '', '&'); @@ -1043,7 +1047,7 @@ function twig_escape_filter(Environment $env, $string, $strategy = 'html', $char switch ($strategy) { case 'html': - // see https://secure.php.net/htmlspecialchars + // see https://www.php.net/htmlspecialchars // Using a static variable to avoid initializing the array // each time the function is called. Moving the declaration on the @@ -1066,18 +1070,18 @@ function twig_escape_filter(Environment $env, $string, $strategy = 'html', $char ]; if (isset($htmlspecialcharsCharsets[$charset])) { - return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset); + return htmlspecialchars($string, \ENT_QUOTES | \ENT_SUBSTITUTE, $charset); } if (isset($htmlspecialcharsCharsets[strtoupper($charset)])) { // cache the lowercase variant for future iterations $htmlspecialcharsCharsets[$charset] = true; - return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset); + return htmlspecialchars($string, \ENT_QUOTES | \ENT_SUBSTITUTE, $charset); } $string = twig_convert_encoding($string, 'UTF-8', $charset); - $string = htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); + $string = htmlspecialchars($string, \ENT_QUOTES | \ENT_SUBSTITUTE, 'UTF-8'); return twig_convert_encoding($string, $charset, 'UTF-8'); @@ -1233,7 +1237,7 @@ function _twig_escape_js_callback($matches) return $shortMap[$char]; } - $codepoint = mb_ord($char); + $codepoint = mb_ord($char, 'UTF-8'); if (0x10000 > $codepoint) { return sprintf('\u%04X', $codepoint); } @@ -1381,7 +1385,7 @@ function twig_lower_filter(Environment $env, $string) function twig_title_string_filter(Environment $env, $string) { if (null !== $charset = $env->getCharset()) { - return mb_convert_case($string, MB_CASE_TITLE, $charset); + return mb_convert_case($string, \MB_CASE_TITLE, $charset); } return ucwords(strtolower($string)); diff --git a/vendor/twig/twig/src/Extension/EscaperExtension.php b/vendor/twig/twig/src/Extension/EscaperExtension.php index fc7f6df..fc3e30b 100644 --- a/vendor/twig/twig/src/Extension/EscaperExtension.php +++ b/vendor/twig/twig/src/Extension/EscaperExtension.php @@ -60,13 +60,13 @@ public function setDefaultStrategy($defaultStrategy) { // for BC if (true === $defaultStrategy) { - @trigger_error('Using "true" as the default strategy is deprecated since version 1.21. Use "html" instead.', E_USER_DEPRECATED); + @trigger_error('Using "true" as the default strategy is deprecated since version 1.21. Use "html" instead.', \E_USER_DEPRECATED); $defaultStrategy = 'html'; } if ('filename' === $defaultStrategy) { - @trigger_error('Using "filename" as the default strategy is deprecated since version 1.27. Use "name" instead.', E_USER_DEPRECATED); + @trigger_error('Using "filename" as the default strategy is deprecated since version 1.27. Use "name" instead.', \E_USER_DEPRECATED); $defaultStrategy = 'name'; } diff --git a/vendor/twig/twig/src/Extension/StagingExtension.php b/vendor/twig/twig/src/Extension/StagingExtension.php index 049c5c7..a60ea21 100644 --- a/vendor/twig/twig/src/Extension/StagingExtension.php +++ b/vendor/twig/twig/src/Extension/StagingExtension.php @@ -35,7 +35,7 @@ class StagingExtension extends AbstractExtension public function addFunction($name, $function) { if (isset($this->functions[$name])) { - @trigger_error(sprintf('Overriding function "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Overriding function "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), \E_USER_DEPRECATED); } $this->functions[$name] = $function; @@ -49,7 +49,7 @@ public function getFunctions() public function addFilter($name, $filter) { if (isset($this->filters[$name])) { - @trigger_error(sprintf('Overriding filter "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Overriding filter "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), \E_USER_DEPRECATED); } $this->filters[$name] = $filter; @@ -73,7 +73,7 @@ public function getNodeVisitors() public function addTokenParser(TokenParserInterface $parser) { if (isset($this->tokenParsers[$parser->getTag()])) { - @trigger_error(sprintf('Overriding tag "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $parser->getTag()), E_USER_DEPRECATED); + @trigger_error(sprintf('Overriding tag "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $parser->getTag()), \E_USER_DEPRECATED); } $this->tokenParsers[$parser->getTag()] = $parser; @@ -97,7 +97,7 @@ public function getGlobals() public function addTest($name, $test) { if (isset($this->tests[$name])) { - @trigger_error(sprintf('Overriding test "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Overriding test "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), \E_USER_DEPRECATED); } $this->tests[$name] = $test; diff --git a/vendor/twig/twig/src/FileExtensionEscapingStrategy.php b/vendor/twig/twig/src/FileExtensionEscapingStrategy.php index bc95f33..d79106c 100644 --- a/vendor/twig/twig/src/FileExtensionEscapingStrategy.php +++ b/vendor/twig/twig/src/FileExtensionEscapingStrategy.php @@ -41,7 +41,7 @@ public static function guess($name) $name = substr($name, 0, -5); } - $extension = pathinfo($name, PATHINFO_EXTENSION); + $extension = pathinfo($name, \PATHINFO_EXTENSION); switch ($extension) { case 'js': diff --git a/vendor/twig/twig/src/Lexer.php b/vendor/twig/twig/src/Lexer.php index 67d94ab..cf13d49 100644 --- a/vendor/twig/twig/src/Lexer.php +++ b/vendor/twig/twig/src/Lexer.php @@ -40,18 +40,18 @@ class Lexer implements \Twig_LexerInterface private $source; - const STATE_DATA = 0; - const STATE_BLOCK = 1; - const STATE_VAR = 2; - const STATE_STRING = 3; - const STATE_INTERPOLATION = 4; - - const REGEX_NAME = '/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/A'; - const REGEX_NUMBER = '/[0-9]+(?:\.[0-9]+)?([Ee][\+\-][0-9]+)?/A'; - const REGEX_STRING = '/"([^#"\\\\]*(?:\\\\.[^#"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As'; - const REGEX_DQ_STRING_DELIM = '/"/A'; - const REGEX_DQ_STRING_PART = '/[^#"\\\\]*(?:(?:\\\\.|#(?!\{))[^#"\\\\]*)*/As'; - const PUNCTUATION = '()[]{}?:.,|'; + public const STATE_DATA = 0; + public const STATE_BLOCK = 1; + public const STATE_VAR = 2; + public const STATE_STRING = 3; + public const STATE_INTERPOLATION = 4; + + public const REGEX_NAME = '/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/A'; + public const REGEX_NUMBER = '/[0-9]+(?:\.[0-9]+)?([Ee][\+\-][0-9]+)?/A'; + public const REGEX_STRING = '/"([^#"\\\\]*(?:\\\\.[^#"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As'; + public const REGEX_DQ_STRING_DELIM = '/"/A'; + public const REGEX_DQ_STRING_PART = '/[^#"\\\\]*(?:(?:\\\\.|#(?!\{))[^#"\\\\]*)*/As'; + public const PUNCTUATION = '()[]{}?:.,|'; public function __construct(Environment $env, array $options = []) { @@ -163,14 +163,14 @@ public function __construct(Environment $env, array $options = []) public function tokenize($code, $name = null) { if (!$code instanceof Source) { - @trigger_error(sprintf('Passing a string as the $code argument of %s() is deprecated since version 1.27 and will be removed in 2.0. Pass a \Twig\Source instance instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('Passing a string as the $code argument of %s() is deprecated since version 1.27 and will be removed in 2.0. Pass a \Twig\Source instance instead.', __METHOD__), \E_USER_DEPRECATED); $this->source = new Source($code, $name); } else { $this->source = $code; } if (((int) ini_get('mbstring.func_overload')) & 2) { - @trigger_error('Support for having "mbstring.func_overload" different from 0 is deprecated version 1.29 and will be removed in 2.0.', E_USER_DEPRECATED); + @trigger_error('Support for having "mbstring.func_overload" different from 0 is deprecated version 1.29 and will be removed in 2.0.', \E_USER_DEPRECATED); } if (\function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { @@ -192,7 +192,7 @@ public function tokenize($code, $name = null) $this->position = -1; // find all token starts in one go - preg_match_all($this->regexes['lex_tokens_start'], $this->code, $matches, PREG_OFFSET_CAPTURE); + preg_match_all($this->regexes['lex_tokens_start'], $this->code, $matches, \PREG_OFFSET_CAPTURE); $this->positions = $matches; while ($this->cursor < $this->end) { @@ -351,7 +351,7 @@ protected function lexExpression() // numbers elseif (preg_match(self::REGEX_NUMBER, $this->code, $match, 0, $this->cursor)) { $number = (float) $match[0]; // floats - if (ctype_digit($match[0]) && $number <= PHP_INT_MAX) { + if (ctype_digit($match[0]) && $number <= \PHP_INT_MAX) { $number = (int) $match[0]; // integers lower than the maximum } $this->pushToken(Token::NUMBER_TYPE, $number); @@ -398,10 +398,10 @@ protected function lexExpression() protected function lexRawData($tag) { if ('raw' === $tag) { - @trigger_error(sprintf('Twig Tag "raw" is deprecated since version 1.21. Use "verbatim" instead in %s at line %d.', $this->filename, $this->lineno), E_USER_DEPRECATED); + @trigger_error(sprintf('Twig Tag "raw" is deprecated since version 1.21. Use "verbatim" instead in %s at line %d.', $this->filename, $this->lineno), \E_USER_DEPRECATED); } - if (!preg_match(str_replace('%s', $tag, $this->regexes['lex_raw_data']), $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { + if (!preg_match(str_replace('%s', $tag, $this->regexes['lex_raw_data']), $this->code, $match, \PREG_OFFSET_CAPTURE, $this->cursor)) { throw new SyntaxError(sprintf('Unexpected end of file: Unclosed "%s" block.', $tag), $this->lineno, $this->source); } @@ -425,7 +425,7 @@ protected function lexRawData($tag) protected function lexComment() { - if (!preg_match($this->regexes['lex_comment'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { + if (!preg_match($this->regexes['lex_comment'], $this->code, $match, \PREG_OFFSET_CAPTURE, $this->cursor)) { throw new SyntaxError('Unclosed comment.', $this->lineno, $this->source); } diff --git a/vendor/twig/twig/src/Loader/ArrayLoader.php b/vendor/twig/twig/src/Loader/ArrayLoader.php index e2c7b33..5f2a1af 100644 --- a/vendor/twig/twig/src/Loader/ArrayLoader.php +++ b/vendor/twig/twig/src/Loader/ArrayLoader.php @@ -53,7 +53,7 @@ public function setTemplate($name, $template) public function getSource($name) { - @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', static::class), E_USER_DEPRECATED); + @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', static::class), \E_USER_DEPRECATED); $name = (string) $name; if (!isset($this->templates[$name])) { diff --git a/vendor/twig/twig/src/Loader/ChainLoader.php b/vendor/twig/twig/src/Loader/ChainLoader.php index d1c0867..1df226c 100644 --- a/vendor/twig/twig/src/Loader/ChainLoader.php +++ b/vendor/twig/twig/src/Loader/ChainLoader.php @@ -52,7 +52,7 @@ public function getLoaders() public function getSource($name) { - @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', static::class), E_USER_DEPRECATED); + @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', static::class), \E_USER_DEPRECATED); $exceptions = []; foreach ($this->loaders as $loader) { diff --git a/vendor/twig/twig/src/Loader/FilesystemLoader.php b/vendor/twig/twig/src/Loader/FilesystemLoader.php index 54303ff..1912e05 100644 --- a/vendor/twig/twig/src/Loader/FilesystemLoader.php +++ b/vendor/twig/twig/src/Loader/FilesystemLoader.php @@ -22,7 +22,7 @@ class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface { /** Identifier of the main namespace. */ - const MAIN_NAMESPACE = '__main__'; + public const MAIN_NAMESPACE = '__main__'; protected $paths = []; protected $cache = []; @@ -37,7 +37,7 @@ class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, Source public function __construct($paths = [], $rootPath = null) { $this->rootPath = (null === $rootPath ? getcwd() : $rootPath).\DIRECTORY_SEPARATOR; - if (false !== $realPath = realpath($rootPath)) { + if (null !== $rootPath && false !== ($realPath = realpath($rootPath))) { $this->rootPath = $realPath.\DIRECTORY_SEPARATOR; } @@ -138,7 +138,7 @@ public function prependPath($path, $namespace = self::MAIN_NAMESPACE) public function getSource($name) { - @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', static::class), E_USER_DEPRECATED); + @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', static::class), \E_USER_DEPRECATED); if (null === ($path = $this->findTemplate($name)) || false === $path) { return ''; @@ -180,7 +180,7 @@ public function exists($name) try { return null !== ($path = $this->findTemplate($name, false)) && false !== $path; } catch (LoaderError $e) { - @trigger_error(sprintf('In %s::findTemplate(), you must accept a second argument that when set to "false" returns "false" instead of throwing an exception. Not supporting this argument is deprecated since version 1.27.', static::class), E_USER_DEPRECATED); + @trigger_error(sprintf('In %s::findTemplate(), you must accept a second argument that when set to "false" returns "false" instead of throwing an exception. Not supporting this argument is deprecated since version 1.27.', static::class), \E_USER_DEPRECATED); return false; } @@ -315,7 +315,7 @@ private function isAbsolutePath($file) && ':' === substr($file, 1, 1) && strspn($file, '/\\', 2, 1) ) - || null !== parse_url($file, PHP_URL_SCHEME) + || null !== parse_url($file, \PHP_URL_SCHEME) ; } } diff --git a/vendor/twig/twig/src/Markup.php b/vendor/twig/twig/src/Markup.php index 107941c..384f41e 100644 --- a/vendor/twig/twig/src/Markup.php +++ b/vendor/twig/twig/src/Markup.php @@ -32,6 +32,9 @@ public function __toString() return $this->content; } + /** + * @return int + */ public function count() { return \function_exists('mb_get_info') ? mb_strlen($this->content, $this->charset) : \strlen($this->content); diff --git a/vendor/twig/twig/src/Node/Expression/BlockReferenceExpression.php b/vendor/twig/twig/src/Node/Expression/BlockReferenceExpression.php index 7e3c3e4..309da58 100644 --- a/vendor/twig/twig/src/Node/Expression/BlockReferenceExpression.php +++ b/vendor/twig/twig/src/Node/Expression/BlockReferenceExpression.php @@ -28,7 +28,7 @@ class BlockReferenceExpression extends AbstractExpression public function __construct(\Twig_NodeInterface $name, $template, $lineno, $tag = null) { if (\is_bool($template)) { - @trigger_error(sprintf('The %s method "$asString" argument is deprecated since version 1.28 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s method "$asString" argument is deprecated since version 1.28 and will be removed in 2.0.', __METHOD__), \E_USER_DEPRECATED); $template = null; } diff --git a/vendor/twig/twig/src/Node/Expression/GetAttrExpression.php b/vendor/twig/twig/src/Node/Expression/GetAttrExpression.php index 06511c7..b8855f4 100644 --- a/vendor/twig/twig/src/Node/Expression/GetAttrExpression.php +++ b/vendor/twig/twig/src/Node/Expression/GetAttrExpression.php @@ -30,7 +30,7 @@ public function __construct(AbstractExpression $node, AbstractExpression $attrib public function compile(Compiler $compiler) { if ($this->getAttribute('disable_c_ext')) { - @trigger_error(sprintf('Using the "disable_c_ext" attribute on %s is deprecated since version 1.30 and will be removed in 2.0.', __CLASS__), E_USER_DEPRECATED); + @trigger_error(sprintf('Using the "disable_c_ext" attribute on %s is deprecated since version 1.30 and will be removed in 2.0.', __CLASS__), \E_USER_DEPRECATED); } if (\function_exists('twig_template_get_attributes') && !$this->getAttribute('disable_c_ext')) { diff --git a/vendor/twig/twig/src/Node/MacroNode.php b/vendor/twig/twig/src/Node/MacroNode.php index 6eb6795..50b0a8d 100644 --- a/vendor/twig/twig/src/Node/MacroNode.php +++ b/vendor/twig/twig/src/Node/MacroNode.php @@ -21,7 +21,7 @@ */ class MacroNode extends Node { - const VARARGS_NAME = 'varargs'; + public const VARARGS_NAME = 'varargs'; public function __construct($name, \Twig_NodeInterface $body, \Twig_NodeInterface $arguments, $lineno, $tag = null) { diff --git a/vendor/twig/twig/src/Node/ModuleNode.php b/vendor/twig/twig/src/Node/ModuleNode.php index 89d602b..325b925 100644 --- a/vendor/twig/twig/src/Node/ModuleNode.php +++ b/vendor/twig/twig/src/Node/ModuleNode.php @@ -31,7 +31,7 @@ class ModuleNode extends Node public function __construct(\Twig_NodeInterface $body, ?AbstractExpression $parent, \Twig_NodeInterface $blocks, \Twig_NodeInterface $macros, \Twig_NodeInterface $traits, $embeddedTemplates, $name, $source = '') { if (!$name instanceof Source) { - @trigger_error(sprintf('Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a \Twig\Source instance instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a \Twig\Source instance instead.', __METHOD__), \E_USER_DEPRECATED); $source = new Source($source, $name); } else { $source = $name; diff --git a/vendor/twig/twig/src/Node/Node.php b/vendor/twig/twig/src/Node/Node.php index 5ec7a73..68e0fd3 100644 --- a/vendor/twig/twig/src/Node/Node.php +++ b/vendor/twig/twig/src/Node/Node.php @@ -40,7 +40,7 @@ public function __construct(array $nodes = [], array $attributes = [], $lineno = { foreach ($nodes as $name => $node) { if (!$node instanceof \Twig_NodeInterface) { - @trigger_error(sprintf('Using "%s" for the value of node "%s" of "%s" is deprecated since version 1.25 and will be removed in 2.0.', \is_object($node) ? \get_class($node) : (null === $node ? 'null' : \gettype($node)), $name, static::class), E_USER_DEPRECATED); + @trigger_error(sprintf('Using "%s" for the value of node "%s" of "%s" is deprecated since version 1.25 and will be removed in 2.0.', \is_object($node) ? \get_class($node) : (null === $node ? 'null' : \gettype($node)), $name, static::class), \E_USER_DEPRECATED); } } $this->nodes = $nodes; @@ -82,7 +82,7 @@ public function __toString() */ public function toXml($asDom = false) { - @trigger_error(sprintf('%s is deprecated since version 1.16.1 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('%s is deprecated since version 1.16.1 and will be removed in 2.0.', __METHOD__), \E_USER_DEPRECATED); $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->formatOutput = true; @@ -129,7 +129,7 @@ public function getTemplateLine() */ public function getLine() { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getTemplateLine() instead.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getTemplateLine() instead.', \E_USER_DEPRECATED); return $this->lineno; } @@ -196,7 +196,7 @@ public function getNode($name) public function setNode($name, $node = null) { if (!$node instanceof \Twig_NodeInterface) { - @trigger_error(sprintf('Using "%s" for the value of node "%s" of "%s" is deprecated since version 1.25 and will be removed in 2.0.', \is_object($node) ? \get_class($node) : (null === $node ? 'null' : \gettype($node)), $name, static::class), E_USER_DEPRECATED); + @trigger_error(sprintf('Using "%s" for the value of node "%s" of "%s" is deprecated since version 1.25 and will be removed in 2.0.', \is_object($node) ? \get_class($node) : (null === $node ? 'null' : \gettype($node)), $name, static::class), \E_USER_DEPRECATED); } $this->nodes[$name] = $node; @@ -207,11 +207,17 @@ public function removeNode($name) unset($this->nodes[$name]); } + /** + * @return int + */ public function count() { return \count($this->nodes); } + /** + * @return \Traversable + */ public function getIterator() { return new \ArrayIterator($this->nodes); @@ -252,7 +258,7 @@ public function getSourceContext() */ public function setFilename($name) { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use setTemplateName() instead.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use setTemplateName() instead.', \E_USER_DEPRECATED); $this->setTemplateName($name); } @@ -262,7 +268,7 @@ public function setFilename($name) */ public function getFilename() { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getTemplateName() instead.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getTemplateName() instead.', \E_USER_DEPRECATED); return $this->name; } diff --git a/vendor/twig/twig/src/NodeVisitor/OptimizerNodeVisitor.php b/vendor/twig/twig/src/NodeVisitor/OptimizerNodeVisitor.php index e5ea9b7..2af5d45 100644 --- a/vendor/twig/twig/src/NodeVisitor/OptimizerNodeVisitor.php +++ b/vendor/twig/twig/src/NodeVisitor/OptimizerNodeVisitor.php @@ -43,11 +43,11 @@ */ class OptimizerNodeVisitor extends AbstractNodeVisitor { - const OPTIMIZE_ALL = -1; - const OPTIMIZE_NONE = 0; - const OPTIMIZE_FOR = 2; - const OPTIMIZE_RAW_FILTER = 4; - const OPTIMIZE_VAR_ACCESS = 8; + public const OPTIMIZE_ALL = -1; + public const OPTIMIZE_NONE = 0; + public const OPTIMIZE_FOR = 2; + public const OPTIMIZE_RAW_FILTER = 4; + public const OPTIMIZE_VAR_ACCESS = 8; protected $loops = []; protected $loopsTargets = []; diff --git a/vendor/twig/twig/src/Parser.php b/vendor/twig/twig/src/Parser.php index 9fb6a83..8763a4e 100644 --- a/vendor/twig/twig/src/Parser.php +++ b/vendor/twig/twig/src/Parser.php @@ -60,7 +60,7 @@ public function __construct(Environment $env) */ public function getEnvironment() { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', \E_USER_DEPRECATED); return $this->env; } @@ -75,7 +75,7 @@ public function getVarName() */ public function getFilename() { - @trigger_error(sprintf('The "%s" method is deprecated since version 1.27 and will be removed in 2.0. Use $parser->getStream()->getSourceContext()->getPath() instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The "%s" method is deprecated since version 1.27 and will be removed in 2.0. Use $parser->getStream()->getSourceContext()->getPath() instead.', __METHOD__), \E_USER_DEPRECATED); return $this->stream->getSourceContext()->getName(); } @@ -229,7 +229,7 @@ public function subparse($test, $dropNeedle = false) */ public function addHandler($name, $class) { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', \E_USER_DEPRECATED); $this->handlers[$name] = $class; } @@ -239,7 +239,7 @@ public function addHandler($name, $class) */ public function addNodeVisitor(NodeVisitorInterface $visitor) { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', \E_USER_DEPRECATED); $this->visitors[] = $visitor; } diff --git a/vendor/twig/twig/src/Profiler/Profile.php b/vendor/twig/twig/src/Profiler/Profile.php index d83da40..60ae02e 100644 --- a/vendor/twig/twig/src/Profiler/Profile.php +++ b/vendor/twig/twig/src/Profiler/Profile.php @@ -18,10 +18,10 @@ */ class Profile implements \IteratorAggregate, \Serializable { - const ROOT = 'ROOT'; - const BLOCK = 'block'; - const TEMPLATE = 'template'; - const MACRO = 'macro'; + public const ROOT = 'ROOT'; + public const BLOCK = 'block'; + public const TEMPLATE = 'template'; + public const MACRO = 'macro'; private $template; private $name; @@ -153,17 +153,17 @@ public function reset() $this->enter(); } - public function getIterator() + public function getIterator(): \Traversable { return new \ArrayIterator($this->profiles); } - public function serialize() + public function serialize(): string { return serialize($this->__serialize()); } - public function unserialize($data) + public function unserialize($data): void { $this->__unserialize(unserialize($data)); } @@ -171,7 +171,7 @@ public function unserialize($data) /** * @internal */ - public function __serialize() + public function __serialize(): array { return [$this->template, $this->name, $this->type, $this->starts, $this->ends, $this->profiles]; } @@ -179,7 +179,7 @@ public function __serialize() /** * @internal */ - public function __unserialize(array $data) + public function __unserialize(array $data): void { list($this->template, $this->name, $this->type, $this->starts, $this->ends, $this->profiles) = $data; } diff --git a/vendor/twig/twig/src/Template.php b/vendor/twig/twig/src/Template.php index 032efe3..876d1ca 100644 --- a/vendor/twig/twig/src/Template.php +++ b/vendor/twig/twig/src/Template.php @@ -80,7 +80,7 @@ public function getDebugInfo() */ public function getSource() { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', \E_USER_DEPRECATED); return ''; } @@ -100,7 +100,7 @@ public function getSourceContext() */ public function getEnvironment() { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.20 and will be removed in 2.0.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.20 and will be removed in 2.0.', \E_USER_DEPRECATED); return $this->env; } @@ -233,7 +233,7 @@ public function displayBlock($name, array $context, array $blocks = [], $useBloc } elseif (false !== $parent = $this->getParent($context)) { $parent->displayBlock($name, $context, array_merge($this->blocks, $blocks), false); } else { - @trigger_error(sprintf('Silent display of undefined block "%s" in template "%s" is deprecated since version 1.29 and will throw an exception in 2.0. Use the "block(\'%s\') is defined" expression to test for block existence.', $name, $this->getTemplateName(), $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Silent display of undefined block "%s" in template "%s" is deprecated since version 1.29 and will throw an exception in 2.0. Use the "block(\'%s\') is defined" expression to test for block existence.', $name, $this->getTemplateName(), $name), \E_USER_DEPRECATED); } } @@ -301,7 +301,7 @@ public function renderBlock($name, array $context, array $blocks = [], $useBlock public function hasBlock($name, array $context = null, array $blocks = []) { if (null === $context) { - @trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.', \E_USER_DEPRECATED); return isset($this->blocks[(string) $name]); } @@ -335,7 +335,7 @@ public function hasBlock($name, array $context = null, array $blocks = []) public function getBlockNames(array $context = null, array $blocks = []) { if (null === $context) { - @trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.', \E_USER_DEPRECATED); return array_keys($this->blocks); } @@ -719,7 +719,7 @@ protected function getAttribute($object, $item, array $arguments = [], $type = s } elseif ('render' === $method || 'display' === $method) { $message .= sprintf(' Use include("%s") instead).', $object->getTemplateName()); } - @trigger_error($message, E_USER_DEPRECATED); + @trigger_error($message, \E_USER_DEPRECATED); return '' === $ret ? '' : new Markup($ret, $this->env->getCharset()); } diff --git a/vendor/twig/twig/src/Test/IntegrationTestCase.php b/vendor/twig/twig/src/Test/IntegrationTestCase.php index 905f972..c968364 100644 --- a/vendor/twig/twig/src/Test/IntegrationTestCase.php +++ b/vendor/twig/twig/src/Test/IntegrationTestCase.php @@ -120,7 +120,7 @@ public function getTests($name, $legacyTests = false) $condition = $match[2]; $templates = self::parseTemplates($match[3]); $exception = false; - preg_match_all('/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\-\-DATA\-\-|$)/s', $test, $outputs, PREG_SET_ORDER); + preg_match_all('/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\-\-DATA\-\-|$)/s', $test, $outputs, \PREG_SET_ORDER); } else { throw new \InvalidArgumentException(sprintf('Test "%s" is not valid.', str_replace($fixturesDir.'/', '', $file))); } @@ -245,7 +245,7 @@ protected function doIntegrationTest($file, $message, $condition, $templates, $e protected static function parseTemplates($test) { $templates = []; - preg_match_all('/--TEMPLATE(?:\((.*?)\))?--(.*?)(?=\-\-TEMPLATE|$)/s', $test, $matches, PREG_SET_ORDER); + preg_match_all('/--TEMPLATE(?:\((.*?)\))?--(.*?)(?=\-\-TEMPLATE|$)/s', $test, $matches, \PREG_SET_ORDER); foreach ($matches as $match) { $templates[($match[1] ?: 'index.twig')] = $match[2]; } diff --git a/vendor/twig/twig/src/Token.php b/vendor/twig/twig/src/Token.php index a0bb11a..4c49a1d 100644 --- a/vendor/twig/twig/src/Token.php +++ b/vendor/twig/twig/src/Token.php @@ -25,20 +25,20 @@ class Token protected $type; protected $lineno; - const EOF_TYPE = -1; - const TEXT_TYPE = 0; - const BLOCK_START_TYPE = 1; - const VAR_START_TYPE = 2; - const BLOCK_END_TYPE = 3; - const VAR_END_TYPE = 4; - const NAME_TYPE = 5; - const NUMBER_TYPE = 6; - const STRING_TYPE = 7; - const OPERATOR_TYPE = 8; - const PUNCTUATION_TYPE = 9; - const INTERPOLATION_START_TYPE = 10; - const INTERPOLATION_END_TYPE = 11; - const ARROW_TYPE = 12; + public const EOF_TYPE = -1; + public const TEXT_TYPE = 0; + public const BLOCK_START_TYPE = 1; + public const VAR_START_TYPE = 2; + public const BLOCK_END_TYPE = 3; + public const VAR_END_TYPE = 4; + public const NAME_TYPE = 5; + public const NUMBER_TYPE = 6; + public const STRING_TYPE = 7; + public const OPERATOR_TYPE = 8; + public const PUNCTUATION_TYPE = 9; + public const INTERPOLATION_START_TYPE = 10; + public const INTERPOLATION_END_TYPE = 11; + public const ARROW_TYPE = 12; /** * @param int $type The type of the token diff --git a/vendor/twig/twig/src/TokenParser/AutoEscapeTokenParser.php b/vendor/twig/twig/src/TokenParser/AutoEscapeTokenParser.php index 2cd0cc6..6dda37b 100644 --- a/vendor/twig/twig/src/TokenParser/AutoEscapeTokenParser.php +++ b/vendor/twig/twig/src/TokenParser/AutoEscapeTokenParser.php @@ -57,7 +57,7 @@ public function parse(Token $token) } if ($compat && $stream->test(Token::NAME_TYPE)) { - @trigger_error('Using the autoescape tag with "true" or "false" before the strategy name is deprecated since version 1.21.', E_USER_DEPRECATED); + @trigger_error('Using the autoescape tag with "true" or "false" before the strategy name is deprecated since version 1.21.', \E_USER_DEPRECATED); if (false === $value) { throw new SyntaxError('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); diff --git a/vendor/twig/twig/src/TokenStream.php b/vendor/twig/twig/src/TokenStream.php index 4597816..d4a4846 100644 --- a/vendor/twig/twig/src/TokenStream.php +++ b/vendor/twig/twig/src/TokenStream.php @@ -38,7 +38,7 @@ public function __construct(array $tokens, $name = null, $source = null) { if (!$name instanceof Source) { if (null !== $name || null !== $source) { - @trigger_error(sprintf('Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a \Twig\Source instance instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a \Twig\Source instance instead.', __METHOD__), \E_USER_DEPRECATED); } $this->source = new Source($source, $name); } else { @@ -164,7 +164,7 @@ public function getCurrent() */ public function getFilename() { - @trigger_error(sprintf('The %s() method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s() method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), \E_USER_DEPRECATED); return $this->source->getName(); } @@ -180,7 +180,7 @@ public function getFilename() */ public function getSource() { - @trigger_error(sprintf('The %s() method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s() method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), \E_USER_DEPRECATED); return $this->source->getCode(); } diff --git a/vendor/twig/twig/src/Util/DeprecationCollector.php b/vendor/twig/twig/src/Util/DeprecationCollector.php index 09917e9..4a8ff53 100644 --- a/vendor/twig/twig/src/Util/DeprecationCollector.php +++ b/vendor/twig/twig/src/Util/DeprecationCollector.php @@ -83,7 +83,7 @@ public function collect(\Traversable $iterator) */ public function errorHandler($type, $msg) { - if (E_USER_DEPRECATED === $type) { + if (\E_USER_DEPRECATED === $type) { $this->deprecations[] = $msg; } }