├── README.md ├── classes └── Users.php ├── composer.json ├── composer.lock ├── config └── database.php ├── v1 ├── create-project-api.php ├── create-user-api.php ├── list-all-projects-api.php ├── login-api.php ├── read-data.php └── user-projects-api.php └── vendor ├── autoload.php ├── composer ├── ClassLoader.php ├── LICENSE ├── autoload_classmap.php ├── autoload_namespaces.php ├── autoload_psr4.php ├── autoload_real.php └── installed.json └── firebase └── php-jwt ├── LICENSE ├── README.md ├── composer.json └── src ├── BeforeValidException.php ├── ExpiredException.php ├── JWT.php └── SignatureInvalidException.php /README.md: -------------------------------------------------------------------------------- 1 | # Online Web Tutor Blog 2 | 3 | ![Online Web Tutor Blog](https://onlinewebtutorblog.com/wp-content/uploads/2020/10/Online-Web-Tutor-Blog-Web-Development-Programming-Blogs.png) 4 | 5 | This is a developed community where you will find several interesting blog articles with short and cool codes. It contains Laravel 8, CodeIgniter 4, MySQL, WordPress, Node Js etc. Please visit once and see the power of learning from this blog. 6 | 7 | ## Find your Article 8 | * [Laravel 8](https://onlinewebtutorblog.com/category/laravel-8/) 9 | * [CakePHP 4](https://onlinewebtutorblog.com/category/cakephp-4/) 10 | * [CodeIgniter 4](https://onlinewebtutorblog.com/category/codeigniter-4/) 11 | * [WordPress](https://onlinewebtutorblog.com/category/wordpress/) 12 | * [MySQL](https://onlinewebtutorblog.com/category/mysql/) 13 | * [Node Js with Sequelize](https://onlinewebtutorblog.com/category/node-js-sequelize-orm/) 14 | 15 | ## CakePHP 4 16 | 17 | * An Introduction to CakePHP 4 basics – Complete Beginners Guide 18 | * An Introduction to CakePHP 4 Routes Tutorial – Complete Guide 19 | * CakePHP 4 CRUD Tutorial with MySQL (Create, Read, Update & Delete) 20 | * CakePHP 4 Custom Validation Rule For Form Inputs 21 | * CakePHP 4 Form Validation with Example 22 | * How Auth Works in CakePHP 4 ? Authentication Tutorial in CakePHP 4 23 | * Working with CakePHP 4 Cron Jobs 24 | 25 | ## CodeIgniter 4 26 | 27 | * Ajax Request in CodeIgniter 4 | Form Data Submit by Ajax 28 | * CodeIgniter 4 Cookie Helper Tutorial 29 | * CodeIgniter 4 CRUD Tutorial | CRUD Example in CodeIgniter 4 30 | * CodeIgniter 4 CSRF Token | Implementation of CSRF Token in Application 31 | * CodeIgniter 4 Custom Library | How can Create Custom Library in CodeIgniter ? 32 | * CodeIgniter 4 Database Query – Complete Methods to Execute Queries 33 | * CodeIgniter 4 Form Validation Library – Easy & Complete Guide 34 | * CodeIgniter 4 Image Upload with Form data | CodeIgniter 4 Image Upload 35 | * CodeIgniter 4 Language Localization | CodeIgniter 4 Website in Multi Language 36 | * Codeigniter 4 Login and Registration | CodeIgniter 4 Signup Login 37 | * Codeigniter 4 Remove Public and Index.php From URL 38 | * CodeIgniter 4 REST APIs Development | CRUD APIs in CodeIgniter 4 39 | * CodeIgniter 4 RESTful APIs with JWT Authentication 40 | * CodeIgniter 4 Server Side DataTable Using SSP Library 41 | * CodeIgniter 4 Spark Module – CLI Tool To manage Database – Step by Step Guide 42 | * CodeIgniter 4 Upload Image with Form data using Ajax Request 43 | * CodeIgniter 4 Working with Multiple Databases & Connection Groups 44 | * Complete CodeIgniter 4 Basics Tutorial for Beginners 45 | * How to Fix Session Fixation Session Hijacking Attack in CodeIgniter ? 46 | * Joins in CodeIgniter 4 | Working with MySQL Joins in CodeIgniter 4 Application 47 | * Working with CodeIgniter 4 Model and Entity 48 | 49 | ## Laravel 8 50 | 51 | * Laravel 8 Installation Guide – PHP Framework 52 | * Laravel 8 Routing Tutorial Step by Step Guide 53 | 54 | ## MySQL 55 | 56 | * 10 Basic Commands of MySQL for Beginners – PhpMyAdmin 57 | * Basics Overview of MySQL Stored Procedures ? Very easy guide to learn. 58 | * Step by Step to Create & Call MySQL Stored Procedure – Code Basics 59 | 60 | ## Node Js Sequelize ORM 61 | 62 | * Create Models in Node Js Sequelize ORM 63 | * Node Express Sequelize ORM CRUD APIs with MySQL 64 | 65 | ## Wordpress 66 | 67 | * An Introduction to WordPress Global Variables- Step by Step Complete Guide 68 | * How can we create a Basic Widget Plugin in WordPress, Step by Step Tutorial 69 | * How to Perform Insert, Update & Delete with WordPress Global Database Object? 70 | * How to Use & Work with jQuery UI in WordPress ? Complete Guide to learn. 71 | * Step by Step Complete Basics Overview of WordPress Widget – What & Why ? 72 | * Step by Step guide to use WordPress Database Object – Find or Search Custom Queries. 73 | * WordPress Built-in Functions & Custom Queries using $wpdb in Widget Development 74 | * WordPress Theme Development Tutorial – Step by Step Beginner’s Guide 75 | * WordPress WP CLI Command Line Tool – Complete Guide to Work 76 | -------------------------------------------------------------------------------- /classes/Users.php: -------------------------------------------------------------------------------- 1 | conn = $db; 20 | $this->users_tbl = "tbl_users"; 21 | $this->projects_tbl = "tbl_projects"; 22 | } 23 | 24 | public function create_user(){ 25 | 26 | $user_query = "INSERT INTO ".$this->users_tbl." SET name = ?, email = ?, password = ?"; 27 | 28 | $user_obj = $this->conn->prepare($user_query); 29 | 30 | $user_obj->bind_param("sss", $this->name, $this->email, $this->password); 31 | 32 | if($user_obj->execute()){ 33 | return true; 34 | } 35 | 36 | return false; 37 | } 38 | 39 | public function check_email(){ 40 | 41 | $email_query = "SELECT * from ".$this->users_tbl." WHERE email = ?"; 42 | 43 | $usr_obj = $this->conn->prepare($email_query); 44 | 45 | $usr_obj->bind_param("s", $this->email); 46 | 47 | if($usr_obj->execute()){ 48 | 49 | $data = $usr_obj->get_result(); 50 | 51 | return $data->fetch_assoc(); 52 | } 53 | 54 | return array(); 55 | } 56 | 57 | public function check_login(){ 58 | 59 | $email_query = "SELECT * from ".$this->users_tbl." WHERE email = ?"; 60 | 61 | $usr_obj = $this->conn->prepare($email_query); 62 | 63 | $usr_obj->bind_param("s", $this->email); 64 | 65 | if($usr_obj->execute()){ 66 | 67 | $data = $usr_obj->get_result(); 68 | 69 | return $data->fetch_assoc(); 70 | } 71 | 72 | return array(); 73 | } 74 | 75 | // to create projects 76 | public function create_project(){ 77 | 78 | $project_query = "INSERT into ".$this->projects_tbl." SET user_id = ?, name = ?, description = ?, status = ?"; 79 | 80 | $project_obj = $this->conn->prepare($project_query); 81 | // sanitize input variables 82 | $project_name = htmlspecialchars(strip_tags($this->project_name)); 83 | $description = htmlspecialchars(strip_tags($this->description)); 84 | $status = htmlspecialchars(strip_tags($this->status)); 85 | // bind parameters 86 | $project_obj->bind_param("isss", $this->user_id, $project_name, $description, $status); 87 | 88 | if($project_obj->execute()){ 89 | return true; 90 | } 91 | 92 | return false; 93 | 94 | } 95 | 96 | // used to list all projects 97 | public function get_all_projects(){ 98 | 99 | $project_query = "SELECT * from ".$this->projects_tbl." ORDER BY id DESC"; 100 | 101 | $project_obj = $this->conn->prepare($project_query); 102 | 103 | $project_obj->execute(); 104 | 105 | return $project_obj->get_result(); 106 | 107 | } 108 | 109 | public function get_user_all_projects(){ 110 | 111 | $project_query = "SELECT * from ".$this->projects_tbl." WHERE user_id = ? ORDER BY id DESC"; 112 | 113 | $project_obj = $this->conn->prepare($project_query); 114 | 115 | $project_obj->bind_param("i", $this->user_id); 116 | 117 | $project_obj->execute(); 118 | 119 | return $project_obj->get_result(); 120 | 121 | } 122 | } 123 | 124 | ?> 125 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "firebase/php-jwt": "^5.0" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "hash": "c6c57c99ab1a548f30322e1122d1c51d", 8 | "content-hash": "7f97fc9c4d2beaf06d019ba50f7efcbc", 9 | "packages": [ 10 | { 11 | "name": "firebase/php-jwt", 12 | "version": "v5.0.0", 13 | "source": { 14 | "type": "git", 15 | "url": "https://github.com/firebase/php-jwt.git", 16 | "reference": "9984a4d3a32ae7673d6971ea00bae9d0a1abba0e" 17 | }, 18 | "dist": { 19 | "type": "zip", 20 | "url": "https://api.github.com/repos/firebase/php-jwt/zipball/9984a4d3a32ae7673d6971ea00bae9d0a1abba0e", 21 | "reference": "9984a4d3a32ae7673d6971ea00bae9d0a1abba0e", 22 | "shasum": "" 23 | }, 24 | "require": { 25 | "php": ">=5.3.0" 26 | }, 27 | "require-dev": { 28 | "phpunit/phpunit": " 4.8.35" 29 | }, 30 | "type": "library", 31 | "autoload": { 32 | "psr-4": { 33 | "Firebase\\JWT\\": "src" 34 | } 35 | }, 36 | "notification-url": "https://packagist.org/downloads/", 37 | "license": [ 38 | "BSD-3-Clause" 39 | ], 40 | "authors": [ 41 | { 42 | "name": "Neuman Vong", 43 | "email": "neuman+pear@twilio.com", 44 | "role": "Developer" 45 | }, 46 | { 47 | "name": "Anant Narayanan", 48 | "email": "anant@php.net", 49 | "role": "Developer" 50 | } 51 | ], 52 | "description": "A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.", 53 | "homepage": "https://github.com/firebase/php-jwt", 54 | "time": "2017-06-27 22:17:23" 55 | } 56 | ], 57 | "packages-dev": [], 58 | "aliases": [], 59 | "minimum-stability": "stable", 60 | "stability-flags": [], 61 | "prefer-stable": false, 62 | "prefer-lowest": false, 63 | "platform": [], 64 | "platform-dev": [] 65 | } 66 | -------------------------------------------------------------------------------- /config/database.php: -------------------------------------------------------------------------------- 1 | hostname = "localhost"; 15 | $this->dbname = "rest_php_api"; 16 | $this->username = "root"; 17 | $this->password = "root"; 18 | 19 | $this->conn = new mysqli($this->hostname, $this->username, $this->password, $this->dbname); 20 | if($this->conn->connect_errno){ 21 | // true => it means that it has some error 22 | print_r($this->conn->connect_error); 23 | exit; 24 | }else{ 25 | // false => it means no error in connection details 26 | return $this->conn; 27 | //echo "--successful connection--"; 28 | //print_r($this->conn); 29 | } 30 | } 31 | } 32 | 33 | //$db = new Database(); 34 | //$db->connect(); 35 | 36 | ?> 37 | -------------------------------------------------------------------------------- /v1/create-project-api.php: -------------------------------------------------------------------------------- 1 | connect(); 21 | 22 | $user_obj = new Users($connection); 23 | 24 | if($_SERVER['REQUEST_METHOD'] === "POST"){ 25 | 26 | // body 27 | $data = json_decode(file_get_contents("php://input")); 28 | 29 | $headers = getallheaders(); 30 | 31 | if(!empty($data->name) && !empty($data->description) && !empty($data->status)){ 32 | 33 | try{ 34 | 35 | $jwt = $headers["Authorization"]; 36 | 37 | $secret_key = "owt125"; 38 | 39 | $decoded_data = JWT::decode($jwt, $secret_key, array('HS512')); 40 | 41 | $user_obj->user_id = $decoded_data->data->id; 42 | $user_obj->project_name = $data->name; 43 | $user_obj->description = $data->description; 44 | $user_obj->status = $data->status; 45 | 46 | if($user_obj->create_project()){ 47 | 48 | http_response_code(200); // ok 49 | echo json_encode(array( 50 | "status" => 1, 51 | "message" => "Project has been created" 52 | )); 53 | }else{ 54 | 55 | http_response_code(500); //server error 56 | echo json_encode(array( 57 | 58 | "status" => 0, 59 | "message" => "Failed to create project" 60 | )); 61 | } 62 | }catch(Exception $ex){ 63 | 64 | http_response_code(500); //server error 65 | echo json_encode(array( 66 | "status" => 0, 67 | "message" => $ex->getMessage() 68 | )); 69 | } 70 | }else{ 71 | 72 | http_response_code(404); // not found 73 | echo json_encode(array( 74 | "status" => 0, 75 | "message" => "All data needed" 76 | )); 77 | } 78 | } 79 | 80 | ?> 81 | -------------------------------------------------------------------------------- /v1/create-user-api.php: -------------------------------------------------------------------------------- 1 | connect(); 15 | 16 | $user_obj = new Users($connection); 17 | 18 | if($_SERVER['REQUEST_METHOD'] === "POST"){ 19 | 20 | $data = json_decode(file_get_contents("php://input")); 21 | 22 | if(!empty($data->name) && !empty($data->email) && !empty($data->password)){ 23 | 24 | $user_obj->name = $data->name; 25 | $user_obj->email = $data->email; 26 | $user_obj->password = password_hash($data->password, PASSWORD_DEFAULT); 27 | 28 | $email_data = $user_obj->check_email(); 29 | 30 | if(!empty($email_data)){ 31 | // some data we have - insert should not go 32 | http_response_code(500); 33 | echo json_encode(array( 34 | "status" => 0, 35 | "message" => "User already exists, try another email address" 36 | )); 37 | }else{ 38 | if($user_obj->create_user()){ 39 | 40 | http_response_code(200); 41 | echo json_encode(array( 42 | "status" => 1, 43 | "message" => "User has been created" 44 | )); 45 | }else{ 46 | 47 | http_response_code(500); 48 | echo json_encode(array( 49 | "status" => 0, 50 | "message" => "Failed to save user" 51 | )); 52 | } 53 | } 54 | }else{ 55 | http_response_code(500); 56 | echo json_encode(array( 57 | "status" => 0, 58 | "message" => "All data needed" 59 | )); 60 | } 61 | }else{ 62 | 63 | http_response_code(503); 64 | echo json_encode(array( 65 | "status" => 0, 66 | "message" => "Access Denied" 67 | )); 68 | } 69 | 70 | ?> 71 | -------------------------------------------------------------------------------- /v1/list-all-projects-api.php: -------------------------------------------------------------------------------- 1 | connect(); 17 | 18 | $user_obj = new Users($connection); 19 | 20 | if($_SERVER['REQUEST_METHOD'] === "GET"){ 21 | 22 | $projects = $user_obj->get_all_projects(); 23 | 24 | if($projects->num_rows > 0){ 25 | 26 | $projects_arr = array(); 27 | 28 | while($row = $projects->fetch_assoc()){ 29 | 30 | $projects_arr[] = array( 31 | "id" => $row['id'], 32 | "name" => $row["name"], 33 | "description" => $row['description'], 34 | "user_id" => $row["user_id"], 35 | "status" => $row["status"], 36 | "created_at" => $row["created_at"] 37 | ); 38 | } 39 | 40 | http_response_code(200); // Ok 41 | echo json_encode(array( 42 | "status" => 1, 43 | "projects" => $projects_arr 44 | )); 45 | 46 | }else{ 47 | http_response_code(404); // no data found 48 | echo json_encode(array( 49 | "status" => 0, 50 | "message" => "No Projects found" 51 | )); 52 | 53 | } 54 | } 55 | 56 | ?> 57 | -------------------------------------------------------------------------------- /v1/login-api.php: -------------------------------------------------------------------------------- 1 | connect(); 20 | 21 | $user_obj = new Users($connection); 22 | 23 | if($_SERVER['REQUEST_METHOD'] === "POST"){ 24 | 25 | $data = json_decode(file_get_contents("php://input")); 26 | 27 | if(!empty($data->email) && !empty($data->password)){ 28 | 29 | $user_obj->email = $data->email; 30 | //$user_obj->password = $data->password; 31 | 32 | $user_data = $user_obj->check_login(); 33 | 34 | if(!empty($user_data)){ 35 | 36 | $name = $user_data['name']; 37 | $email = $user_data['email']; 38 | $password = $user_data['password']; 39 | 40 | if(password_verify($data->password, $password)){ // normal password, hashed password 41 | 42 | $iss = "localhost"; 43 | $iat = time(); 44 | $nbf = $iat + 10; 45 | $exp = $iat + 180; 46 | $aud = "myusers"; 47 | $user_arr_data = array( 48 | "id" => $user_data['id'], 49 | "name" => $user_data['name'], 50 | "email" => $user_data['email'] 51 | ); 52 | 53 | $secret_key = "owt125"; 54 | 55 | $payload_info = array( 56 | "iss"=> $iss, 57 | "iat"=> $iat, 58 | "nbf"=> $nbf, 59 | "exp"=> $exp, 60 | "aud"=> $aud, 61 | "data"=> $user_arr_data 62 | ); 63 | 64 | $jwt = JWT::encode($payload_info, $secret_key, 'HS512'); 65 | 66 | http_response_code(200); 67 | echo json_encode(array( 68 | "status" => 1, 69 | "jwt" => $jwt, 70 | "message" => "User logged in successfully" 71 | )); 72 | }else{ 73 | 74 | http_response_code(404); 75 | echo json_encode(array( 76 | "status" => 0, 77 | "message" => "Invalid credentials" 78 | )); 79 | } 80 | }else{ 81 | 82 | http_response_code(404); 83 | echo json_encode(array( 84 | "status" => 0, 85 | "message" => "Invalid credentials" 86 | )); 87 | } 88 | }else{ 89 | 90 | http_response_code(404); 91 | echo json_encode(array( 92 | "status" => 0, 93 | "message" => "All data needed" 94 | )); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /v1/read-data.php: -------------------------------------------------------------------------------- 1 | connect(); 18 | 19 | $user_obj = new Users($connection); 20 | 21 | if($_SERVER['REQUEST_METHOD'] === "POST"){ 22 | 23 | //$data = json_decode(file_get_contents("php://input")); 24 | 25 | $all_headers = getallheaders(); 26 | 27 | $data->jwt = $all_headers['Authorization']; 28 | 29 | if(!empty($data->jwt)){ 30 | 31 | try{ 32 | 33 | $secret_key = "owt125"; 34 | 35 | $decoded_data = JWT::decode($data->jwt, $secret_key, array('HS512')); 36 | 37 | http_response_code(200); 38 | 39 | $user_id = $decoded_data->data->id; 40 | 41 | echo json_encode(array( 42 | "status" => 1, 43 | "message" => "We got JWT Token", 44 | "user_data" => $decoded_data, 45 | "user_id" => $user_id 46 | )); 47 | }catch(Exception $ex){ 48 | 49 | http_response_code(500); // server error 50 | echo json_encode(array( 51 | "status" => 0, 52 | "message" => $ex->getMessage() 53 | )); 54 | } 55 | 56 | } 57 | 58 | } 59 | ?> 60 | -------------------------------------------------------------------------------- /v1/user-projects-api.php: -------------------------------------------------------------------------------- 1 | connect(); 19 | 20 | $user_obj = new Users($connection); 21 | 22 | if($_SERVER['REQUEST_METHOD'] === "GET"){ 23 | 24 | $headers = getallheaders(); 25 | 26 | $jwt = $headers["Authorization"]; 27 | 28 | try{ 29 | 30 | $secret_key = "owt125"; 31 | 32 | $decoded_data = JWT::decode($jwt, $secret_key, array('HS512')); 33 | 34 | $user_obj->user_id = $decoded_data->data->id; 35 | 36 | $projects = $user_obj->get_user_all_projects(); 37 | 38 | if($projects->num_rows > 0){ 39 | 40 | $projects_arr = array(); 41 | 42 | while($row = $projects->fetch_assoc()){ 43 | 44 | $projects_arr[] = array( 45 | "id" => $row['id'], 46 | "name" => $row["name"], 47 | "description" => $row['description'], 48 | "user_id" => $row["user_id"], 49 | "status" => $row["status"], 50 | "created_at" => $row["created_at"] 51 | ); 52 | } 53 | 54 | http_response_code(200); // Ok 55 | echo json_encode(array( 56 | "status" => 1, 57 | "projects" => $projects_arr 58 | )); 59 | 60 | }else{ 61 | http_response_code(404); // no data found 62 | echo json_encode(array( 63 | "status" => 0, 64 | "message" => "No Projects found" 65 | )); 66 | 67 | } 68 | }catch(Exception $ex){ 69 | http_response_code(500); // no data found 70 | echo json_encode(array( 71 | "status" => 0, 72 | "message" => $ex->getMessage() 73 | )); 74 | } 75 | 76 | } 77 | 78 | ?> 79 | -------------------------------------------------------------------------------- /vendor/autoload.php: -------------------------------------------------------------------------------- 1 | 7 | * Jordi Boggiano 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Composer\Autoload; 14 | 15 | /** 16 | * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. 17 | * 18 | * $loader = new \Composer\Autoload\ClassLoader(); 19 | * 20 | * // register classes with namespaces 21 | * $loader->add('Symfony\Component', __DIR__.'/component'); 22 | * $loader->add('Symfony', __DIR__.'/framework'); 23 | * 24 | * // activate the autoloader 25 | * $loader->register(); 26 | * 27 | * // to enable searching the include path (eg. for PEAR packages) 28 | * $loader->setUseIncludePath(true); 29 | * 30 | * In this example, if you try to use a class in the Symfony\Component 31 | * namespace or one of its children (Symfony\Component\Console for instance), 32 | * the autoloader will first look for the class under the component/ 33 | * directory, and it will then fallback to the framework/ directory if not 34 | * found before giving up. 35 | * 36 | * This class is loosely based on the Symfony UniversalClassLoader. 37 | * 38 | * @author Fabien Potencier 39 | * @author Jordi Boggiano 40 | * @see http://www.php-fig.org/psr/psr-0/ 41 | * @see http://www.php-fig.org/psr/psr-4/ 42 | */ 43 | class ClassLoader 44 | { 45 | // PSR-4 46 | private $prefixLengthsPsr4 = array(); 47 | private $prefixDirsPsr4 = array(); 48 | private $fallbackDirsPsr4 = array(); 49 | 50 | // PSR-0 51 | private $prefixesPsr0 = array(); 52 | private $fallbackDirsPsr0 = array(); 53 | 54 | private $useIncludePath = false; 55 | private $classMap = array(); 56 | 57 | private $classMapAuthoritative = false; 58 | 59 | public function getPrefixes() 60 | { 61 | if (!empty($this->prefixesPsr0)) { 62 | return call_user_func_array('array_merge', $this->prefixesPsr0); 63 | } 64 | 65 | return array(); 66 | } 67 | 68 | public function getPrefixesPsr4() 69 | { 70 | return $this->prefixDirsPsr4; 71 | } 72 | 73 | public function getFallbackDirs() 74 | { 75 | return $this->fallbackDirsPsr0; 76 | } 77 | 78 | public function getFallbackDirsPsr4() 79 | { 80 | return $this->fallbackDirsPsr4; 81 | } 82 | 83 | public function getClassMap() 84 | { 85 | return $this->classMap; 86 | } 87 | 88 | /** 89 | * @param array $classMap Class to filename map 90 | */ 91 | public function addClassMap(array $classMap) 92 | { 93 | if ($this->classMap) { 94 | $this->classMap = array_merge($this->classMap, $classMap); 95 | } else { 96 | $this->classMap = $classMap; 97 | } 98 | } 99 | 100 | /** 101 | * Registers a set of PSR-0 directories for a given prefix, either 102 | * appending or prepending to the ones previously set for this prefix. 103 | * 104 | * @param string $prefix The prefix 105 | * @param array|string $paths The PSR-0 root directories 106 | * @param bool $prepend Whether to prepend the directories 107 | */ 108 | public function add($prefix, $paths, $prepend = false) 109 | { 110 | if (!$prefix) { 111 | if ($prepend) { 112 | $this->fallbackDirsPsr0 = array_merge( 113 | (array) $paths, 114 | $this->fallbackDirsPsr0 115 | ); 116 | } else { 117 | $this->fallbackDirsPsr0 = array_merge( 118 | $this->fallbackDirsPsr0, 119 | (array) $paths 120 | ); 121 | } 122 | 123 | return; 124 | } 125 | 126 | $first = $prefix[0]; 127 | if (!isset($this->prefixesPsr0[$first][$prefix])) { 128 | $this->prefixesPsr0[$first][$prefix] = (array) $paths; 129 | 130 | return; 131 | } 132 | if ($prepend) { 133 | $this->prefixesPsr0[$first][$prefix] = array_merge( 134 | (array) $paths, 135 | $this->prefixesPsr0[$first][$prefix] 136 | ); 137 | } else { 138 | $this->prefixesPsr0[$first][$prefix] = array_merge( 139 | $this->prefixesPsr0[$first][$prefix], 140 | (array) $paths 141 | ); 142 | } 143 | } 144 | 145 | /** 146 | * Registers a set of PSR-4 directories for a given namespace, either 147 | * appending or prepending to the ones previously set for this namespace. 148 | * 149 | * @param string $prefix The prefix/namespace, with trailing '\\' 150 | * @param array|string $paths The PSR-4 base directories 151 | * @param bool $prepend Whether to prepend the directories 152 | * 153 | * @throws \InvalidArgumentException 154 | */ 155 | public function addPsr4($prefix, $paths, $prepend = false) 156 | { 157 | if (!$prefix) { 158 | // Register directories for the root namespace. 159 | if ($prepend) { 160 | $this->fallbackDirsPsr4 = array_merge( 161 | (array) $paths, 162 | $this->fallbackDirsPsr4 163 | ); 164 | } else { 165 | $this->fallbackDirsPsr4 = array_merge( 166 | $this->fallbackDirsPsr4, 167 | (array) $paths 168 | ); 169 | } 170 | } elseif (!isset($this->prefixDirsPsr4[$prefix])) { 171 | // Register directories for a new namespace. 172 | $length = strlen($prefix); 173 | if ('\\' !== $prefix[$length - 1]) { 174 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); 175 | } 176 | $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; 177 | $this->prefixDirsPsr4[$prefix] = (array) $paths; 178 | } elseif ($prepend) { 179 | // Prepend directories for an already registered namespace. 180 | $this->prefixDirsPsr4[$prefix] = array_merge( 181 | (array) $paths, 182 | $this->prefixDirsPsr4[$prefix] 183 | ); 184 | } else { 185 | // Append directories for an already registered namespace. 186 | $this->prefixDirsPsr4[$prefix] = array_merge( 187 | $this->prefixDirsPsr4[$prefix], 188 | (array) $paths 189 | ); 190 | } 191 | } 192 | 193 | /** 194 | * Registers a set of PSR-0 directories for a given prefix, 195 | * replacing any others previously set for this prefix. 196 | * 197 | * @param string $prefix The prefix 198 | * @param array|string $paths The PSR-0 base directories 199 | */ 200 | public function set($prefix, $paths) 201 | { 202 | if (!$prefix) { 203 | $this->fallbackDirsPsr0 = (array) $paths; 204 | } else { 205 | $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; 206 | } 207 | } 208 | 209 | /** 210 | * Registers a set of PSR-4 directories for a given namespace, 211 | * replacing any others previously set for this namespace. 212 | * 213 | * @param string $prefix The prefix/namespace, with trailing '\\' 214 | * @param array|string $paths The PSR-4 base directories 215 | * 216 | * @throws \InvalidArgumentException 217 | */ 218 | public function setPsr4($prefix, $paths) 219 | { 220 | if (!$prefix) { 221 | $this->fallbackDirsPsr4 = (array) $paths; 222 | } else { 223 | $length = strlen($prefix); 224 | if ('\\' !== $prefix[$length - 1]) { 225 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); 226 | } 227 | $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; 228 | $this->prefixDirsPsr4[$prefix] = (array) $paths; 229 | } 230 | } 231 | 232 | /** 233 | * Turns on searching the include path for class files. 234 | * 235 | * @param bool $useIncludePath 236 | */ 237 | public function setUseIncludePath($useIncludePath) 238 | { 239 | $this->useIncludePath = $useIncludePath; 240 | } 241 | 242 | /** 243 | * Can be used to check if the autoloader uses the include path to check 244 | * for classes. 245 | * 246 | * @return bool 247 | */ 248 | public function getUseIncludePath() 249 | { 250 | return $this->useIncludePath; 251 | } 252 | 253 | /** 254 | * Turns off searching the prefix and fallback directories for classes 255 | * that have not been registered with the class map. 256 | * 257 | * @param bool $classMapAuthoritative 258 | */ 259 | public function setClassMapAuthoritative($classMapAuthoritative) 260 | { 261 | $this->classMapAuthoritative = $classMapAuthoritative; 262 | } 263 | 264 | /** 265 | * Should class lookup fail if not found in the current class map? 266 | * 267 | * @return bool 268 | */ 269 | public function isClassMapAuthoritative() 270 | { 271 | return $this->classMapAuthoritative; 272 | } 273 | 274 | /** 275 | * Registers this instance as an autoloader. 276 | * 277 | * @param bool $prepend Whether to prepend the autoloader or not 278 | */ 279 | public function register($prepend = false) 280 | { 281 | spl_autoload_register(array($this, 'loadClass'), true, $prepend); 282 | } 283 | 284 | /** 285 | * Unregisters this instance as an autoloader. 286 | */ 287 | public function unregister() 288 | { 289 | spl_autoload_unregister(array($this, 'loadClass')); 290 | } 291 | 292 | /** 293 | * Loads the given class or interface. 294 | * 295 | * @param string $class The name of the class 296 | * @return bool|null True if loaded, null otherwise 297 | */ 298 | public function loadClass($class) 299 | { 300 | if ($file = $this->findFile($class)) { 301 | includeFile($file); 302 | 303 | return true; 304 | } 305 | } 306 | 307 | /** 308 | * Finds the path to the file where the class is defined. 309 | * 310 | * @param string $class The name of the class 311 | * 312 | * @return string|false The path if found, false otherwise 313 | */ 314 | public function findFile($class) 315 | { 316 | // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731 317 | if ('\\' == $class[0]) { 318 | $class = substr($class, 1); 319 | } 320 | 321 | // class map lookup 322 | if (isset($this->classMap[$class])) { 323 | return $this->classMap[$class]; 324 | } 325 | if ($this->classMapAuthoritative) { 326 | return false; 327 | } 328 | 329 | $file = $this->findFileWithExtension($class, '.php'); 330 | 331 | // Search for Hack files if we are running on HHVM 332 | if ($file === null && defined('HHVM_VERSION')) { 333 | $file = $this->findFileWithExtension($class, '.hh'); 334 | } 335 | 336 | if ($file === null) { 337 | // Remember that this class does not exist. 338 | return $this->classMap[$class] = false; 339 | } 340 | 341 | return $file; 342 | } 343 | 344 | private function findFileWithExtension($class, $ext) 345 | { 346 | // PSR-4 lookup 347 | $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; 348 | 349 | $first = $class[0]; 350 | if (isset($this->prefixLengthsPsr4[$first])) { 351 | foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { 352 | if (0 === strpos($class, $prefix)) { 353 | foreach ($this->prefixDirsPsr4[$prefix] as $dir) { 354 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { 355 | return $file; 356 | } 357 | } 358 | } 359 | } 360 | } 361 | 362 | // PSR-4 fallback dirs 363 | foreach ($this->fallbackDirsPsr4 as $dir) { 364 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { 365 | return $file; 366 | } 367 | } 368 | 369 | // PSR-0 lookup 370 | if (false !== $pos = strrpos($class, '\\')) { 371 | // namespaced class name 372 | $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) 373 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); 374 | } else { 375 | // PEAR-like class name 376 | $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; 377 | } 378 | 379 | if (isset($this->prefixesPsr0[$first])) { 380 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { 381 | if (0 === strpos($class, $prefix)) { 382 | foreach ($dirs as $dir) { 383 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { 384 | return $file; 385 | } 386 | } 387 | } 388 | } 389 | } 390 | 391 | // PSR-0 fallback dirs 392 | foreach ($this->fallbackDirsPsr0 as $dir) { 393 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { 394 | return $file; 395 | } 396 | } 397 | 398 | // PSR-0 include paths. 399 | if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { 400 | return $file; 401 | } 402 | } 403 | } 404 | 405 | /** 406 | * Scope isolated include. 407 | * 408 | * Prevents access to $this/self from included files. 409 | */ 410 | function includeFile($file) 411 | { 412 | include $file; 413 | } 414 | -------------------------------------------------------------------------------- /vendor/composer/LICENSE: -------------------------------------------------------------------------------- 1 | Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: Composer 3 | Upstream-Contact: Jordi Boggiano 4 | Source: https://github.com/composer/composer 5 | 6 | Files: * 7 | Copyright: 2016, Nils Adermann 8 | 2016, Jordi Boggiano 9 | License: Expat 10 | 11 | Files: res/cacert.pem 12 | Copyright: 2015, Mozilla Foundation 13 | License: MPL-2.0 14 | 15 | Files: src/Composer/Util/RemoteFilesystem.php 16 | src/Composer/Util/TlsHelper.php 17 | Copyright: 2016, Nils Adermann 18 | 2016, Jordi Boggiano 19 | 2013, Evan Coury 20 | License: Expat and BSD-2-Clause 21 | 22 | License: BSD-2-Clause 23 | Redistribution and use in source and binary forms, with or without modification, 24 | are permitted provided that the following conditions are met: 25 | . 26 | * Redistributions of source code must retain the above copyright notice, 27 | this list of conditions and the following disclaimer. 28 | . 29 | * Redistributions in binary form must reproduce the above copyright notice, 30 | this list of conditions and the following disclaimer in the documentation 31 | and/or other materials provided with the distribution. 32 | . 33 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 34 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 35 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 36 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 37 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 38 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 40 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 41 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 42 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 43 | 44 | License: Expat 45 | Permission is hereby granted, free of charge, to any person obtaining a copy 46 | of this software and associated documentation files (the "Software"), to deal 47 | in the Software without restriction, including without limitation the rights 48 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 49 | copies of the Software, and to permit persons to whom the Software is furnished 50 | to do so, subject to the following conditions: 51 | . 52 | The above copyright notice and this permission notice shall be included in all 53 | copies or substantial portions of the Software. 54 | . 55 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 56 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 57 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 58 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 59 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 60 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 61 | THE SOFTWARE. 62 | 63 | License: MPL-2.0 64 | 1. Definitions 65 | -------------- 66 | . 67 | 1.1. "Contributor" 68 | means each individual or legal entity that creates, contributes to 69 | the creation of, or owns Covered Software. 70 | . 71 | 1.2. "Contributor Version" 72 | means the combination of the Contributions of others (if any) used 73 | by a Contributor and that particular Contributor's Contribution. 74 | . 75 | 1.3. "Contribution" 76 | means Covered Software of a particular Contributor. 77 | . 78 | 1.4. "Covered Software" 79 | means Source Code Form to which the initial Contributor has attached 80 | the notice in Exhibit A, the Executable Form of such Source Code 81 | Form, and Modifications of such Source Code Form, in each case 82 | including portions thereof. 83 | . 84 | 1.5. "Incompatible With Secondary Licenses" 85 | means 86 | . 87 | (a) that the initial Contributor has attached the notice described 88 | in Exhibit B to the Covered Software; or 89 | . 90 | (b) that the Covered Software was made available under the terms of 91 | version 1.1 or earlier of the License, but not also under the 92 | terms of a Secondary License. 93 | . 94 | 1.6. "Executable Form" 95 | means any form of the work other than Source Code Form. 96 | . 97 | 1.7. "Larger Work" 98 | means a work that combines Covered Software with other material, in 99 | a separate file or files, that is not Covered Software. 100 | . 101 | 1.8. "License" 102 | means this document. 103 | . 104 | 1.9. "Licensable" 105 | means having the right to grant, to the maximum extent possible, 106 | whether at the time of the initial grant or subsequently, any and 107 | all of the rights conveyed by this License. 108 | . 109 | 1.10. "Modifications" 110 | means any of the following: 111 | . 112 | (a) any file in Source Code Form that results from an addition to, 113 | deletion from, or modification of the contents of Covered 114 | Software; or 115 | . 116 | (b) any new file in Source Code Form that contains any Covered 117 | Software. 118 | . 119 | 1.11. "Patent Claims" of a Contributor 120 | means any patent claim(s), including without limitation, method, 121 | process, and apparatus claims, in any patent Licensable by such 122 | Contributor that would be infringed, but for the grant of the 123 | License, by the making, using, selling, offering for sale, having 124 | made, import, or transfer of either its Contributions or its 125 | Contributor Version. 126 | . 127 | 1.12. "Secondary License" 128 | means either the GNU General Public License, Version 2.0, the GNU 129 | Lesser General Public License, Version 2.1, the GNU Affero General 130 | Public License, Version 3.0, or any later versions of those 131 | licenses. 132 | . 133 | 1.13. "Source Code Form" 134 | means the form of the work preferred for making modifications. 135 | . 136 | 1.14. "You" (or "Your") 137 | means an individual or a legal entity exercising rights under this 138 | License. For legal entities, "You" includes any entity that 139 | controls, is controlled by, or is under common control with You. For 140 | purposes of this definition, "control" means (a) the power, direct 141 | or indirect, to cause the direction or management of such entity, 142 | whether by contract or otherwise, or (b) ownership of more than 143 | fifty percent (50%) of the outstanding shares or beneficial 144 | ownership of such entity. 145 | . 146 | 2. License Grants and Conditions 147 | -------------------------------- 148 | . 149 | 2.1. Grants 150 | . 151 | Each Contributor hereby grants You a world-wide, royalty-free, 152 | non-exclusive license: 153 | . 154 | (a) under intellectual property rights (other than patent or trademark) 155 | Licensable by such Contributor to use, reproduce, make available, 156 | modify, display, perform, distribute, and otherwise exploit its 157 | Contributions, either on an unmodified basis, with Modifications, or 158 | as part of a Larger Work; and 159 | . 160 | (b) under Patent Claims of such Contributor to make, use, sell, offer 161 | for sale, have made, import, and otherwise transfer either its 162 | Contributions or its Contributor Version. 163 | . 164 | 2.2. Effective Date 165 | . 166 | The licenses granted in Section 2.1 with respect to any Contribution 167 | become effective for each Contribution on the date the Contributor first 168 | distributes such Contribution. 169 | . 170 | 2.3. Limitations on Grant Scope 171 | . 172 | The licenses granted in this Section 2 are the only rights granted under 173 | this License. No additional rights or licenses will be implied from the 174 | distribution or licensing of Covered Software under this License. 175 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 176 | Contributor: 177 | . 178 | (a) for any code that a Contributor has removed from Covered Software; 179 | or 180 | . 181 | (b) for infringements caused by: (i) Your and any other third party's 182 | modifications of Covered Software, or (ii) the combination of its 183 | Contributions with other software (except as part of its Contributor 184 | Version); or 185 | . 186 | (c) under Patent Claims infringed by Covered Software in the absence of 187 | its Contributions. 188 | . 189 | This License does not grant any rights in the trademarks, service marks, 190 | or logos of any Contributor (except as may be necessary to comply with 191 | the notice requirements in Section 3.4). 192 | . 193 | 2.4. Subsequent Licenses 194 | . 195 | No Contributor makes additional grants as a result of Your choice to 196 | distribute the Covered Software under a subsequent version of this 197 | License (see Section 10.2) or under the terms of a Secondary License (if 198 | permitted under the terms of Section 3.3). 199 | . 200 | 2.5. Representation 201 | . 202 | Each Contributor represents that the Contributor believes its 203 | Contributions are its original creation(s) or it has sufficient rights 204 | to grant the rights to its Contributions conveyed by this License. 205 | . 206 | 2.6. Fair Use 207 | . 208 | This License is not intended to limit any rights You have under 209 | applicable copyright doctrines of fair use, fair dealing, or other 210 | equivalents. 211 | . 212 | 2.7. Conditions 213 | . 214 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 215 | in Section 2.1. 216 | . 217 | 3. Responsibilities 218 | ------------------- 219 | . 220 | 3.1. Distribution of Source Form 221 | . 222 | All distribution of Covered Software in Source Code Form, including any 223 | Modifications that You create or to which You contribute, must be under 224 | the terms of this License. You must inform recipients that the Source 225 | Code Form of the Covered Software is governed by the terms of this 226 | License, and how they can obtain a copy of this License. You may not 227 | attempt to alter or restrict the recipients' rights in the Source Code 228 | Form. 229 | . 230 | 3.2. Distribution of Executable Form 231 | . 232 | If You distribute Covered Software in Executable Form then: 233 | . 234 | (a) such Covered Software must also be made available in Source Code 235 | Form, as described in Section 3.1, and You must inform recipients of 236 | the Executable Form how they can obtain a copy of such Source Code 237 | Form by reasonable means in a timely manner, at a charge no more 238 | than the cost of distribution to the recipient; and 239 | . 240 | (b) You may distribute such Executable Form under the terms of this 241 | License, or sublicense it under different terms, provided that the 242 | license for the Executable Form does not attempt to limit or alter 243 | the recipients' rights in the Source Code Form under this License. 244 | . 245 | 3.3. Distribution of a Larger Work 246 | . 247 | You may create and distribute a Larger Work under terms of Your choice, 248 | provided that You also comply with the requirements of this License for 249 | the Covered Software. If the Larger Work is a combination of Covered 250 | Software with a work governed by one or more Secondary Licenses, and the 251 | Covered Software is not Incompatible With Secondary Licenses, this 252 | License permits You to additionally distribute such Covered Software 253 | under the terms of such Secondary License(s), so that the recipient of 254 | the Larger Work may, at their option, further distribute the Covered 255 | Software under the terms of either this License or such Secondary 256 | License(s). 257 | . 258 | 3.4. Notices 259 | . 260 | You may not remove or alter the substance of any license notices 261 | (including copyright notices, patent notices, disclaimers of warranty, 262 | or limitations of liability) contained within the Source Code Form of 263 | the Covered Software, except that You may alter any license notices to 264 | the extent required to remedy known factual inaccuracies. 265 | . 266 | 3.5. Application of Additional Terms 267 | . 268 | You may choose to offer, and to charge a fee for, warranty, support, 269 | indemnity or liability obligations to one or more recipients of Covered 270 | Software. However, You may do so only on Your own behalf, and not on 271 | behalf of any Contributor. You must make it absolutely clear that any 272 | such warranty, support, indemnity, or liability obligation is offered by 273 | You alone, and You hereby agree to indemnify every Contributor for any 274 | liability incurred by such Contributor as a result of warranty, support, 275 | indemnity or liability terms You offer. You may include additional 276 | disclaimers of warranty and limitations of liability specific to any 277 | jurisdiction. 278 | . 279 | 4. Inability to Comply Due to Statute or Regulation 280 | --------------------------------------------------- 281 | . 282 | If it is impossible for You to comply with any of the terms of this 283 | License with respect to some or all of the Covered Software due to 284 | statute, judicial order, or regulation then You must: (a) comply with 285 | the terms of this License to the maximum extent possible; and (b) 286 | describe the limitations and the code they affect. Such description must 287 | be placed in a text file included with all distributions of the Covered 288 | Software under this License. Except to the extent prohibited by statute 289 | or regulation, such description must be sufficiently detailed for a 290 | recipient of ordinary skill to be able to understand it. 291 | . 292 | 5. Termination 293 | -------------- 294 | . 295 | 5.1. The rights granted under this License will terminate automatically 296 | if You fail to comply with any of its terms. However, if You become 297 | compliant, then the rights granted under this License from a particular 298 | Contributor are reinstated (a) provisionally, unless and until such 299 | Contributor explicitly and finally terminates Your grants, and (b) on an 300 | ongoing basis, if such Contributor fails to notify You of the 301 | non-compliance by some reasonable means prior to 60 days after You have 302 | come back into compliance. Moreover, Your grants from a particular 303 | Contributor are reinstated on an ongoing basis if such Contributor 304 | notifies You of the non-compliance by some reasonable means, this is the 305 | first time You have received notice of non-compliance with this License 306 | from such Contributor, and You become compliant prior to 30 days after 307 | Your receipt of the notice. 308 | . 309 | 5.2. If You initiate litigation against any entity by asserting a patent 310 | infringement claim (excluding declaratory judgment actions, 311 | counter-claims, and cross-claims) alleging that a Contributor Version 312 | directly or indirectly infringes any patent, then the rights granted to 313 | You by any and all Contributors for the Covered Software under Section 314 | 2.1 of this License shall terminate. 315 | . 316 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 317 | end user license agreements (excluding distributors and resellers) which 318 | have been validly granted by You or Your distributors under this License 319 | prior to termination shall survive termination. 320 | . 321 | ************************************************************************ 322 | * * 323 | * 6. Disclaimer of Warranty * 324 | * ------------------------- * 325 | * * 326 | * Covered Software is provided under this License on an "as is" * 327 | * basis, without warranty of any kind, either expressed, implied, or * 328 | * statutory, including, without limitation, warranties that the * 329 | * Covered Software is free of defects, merchantable, fit for a * 330 | * particular purpose or non-infringing. The entire risk as to the * 331 | * quality and performance of the Covered Software is with You. * 332 | * Should any Covered Software prove defective in any respect, You * 333 | * (not any Contributor) assume the cost of any necessary servicing, * 334 | * repair, or correction. This disclaimer of warranty constitutes an * 335 | * essential part of this License. No use of any Covered Software is * 336 | * authorized under this License except under this disclaimer. * 337 | * * 338 | ************************************************************************ 339 | . 340 | ************************************************************************ 341 | * * 342 | * 7. Limitation of Liability * 343 | * -------------------------- * 344 | * * 345 | * Under no circumstances and under no legal theory, whether tort * 346 | * (including negligence), contract, or otherwise, shall any * 347 | * Contributor, or anyone who distributes Covered Software as * 348 | * permitted above, be liable to You for any direct, indirect, * 349 | * special, incidental, or consequential damages of any character * 350 | * including, without limitation, damages for lost profits, loss of * 351 | * goodwill, work stoppage, computer failure or malfunction, or any * 352 | * and all other commercial damages or losses, even if such party * 353 | * shall have been informed of the possibility of such damages. This * 354 | * limitation of liability shall not apply to liability for death or * 355 | * personal injury resulting from such party's negligence to the * 356 | * extent applicable law prohibits such limitation. Some * 357 | * jurisdictions do not allow the exclusion or limitation of * 358 | * incidental or consequential damages, so this exclusion and * 359 | * limitation may not apply to You. * 360 | * * 361 | ************************************************************************ 362 | . 363 | 8. Litigation 364 | ------------- 365 | . 366 | Any litigation relating to this License may be brought only in the 367 | courts of a jurisdiction where the defendant maintains its principal 368 | place of business and such litigation shall be governed by laws of that 369 | jurisdiction, without reference to its conflict-of-law provisions. 370 | Nothing in this Section shall prevent a party's ability to bring 371 | cross-claims or counter-claims. 372 | . 373 | 9. Miscellaneous 374 | ---------------- 375 | . 376 | This License represents the complete agreement concerning the subject 377 | matter hereof. If any provision of this License is held to be 378 | unenforceable, such provision shall be reformed only to the extent 379 | necessary to make it enforceable. Any law or regulation which provides 380 | that the language of a contract shall be construed against the drafter 381 | shall not be used to construe this License against a Contributor. 382 | . 383 | 10. Versions of the License 384 | --------------------------- 385 | . 386 | 10.1. New Versions 387 | . 388 | Mozilla Foundation is the license steward. Except as provided in Section 389 | 10.3, no one other than the license steward has the right to modify or 390 | publish new versions of this License. Each version will be given a 391 | distinguishing version number. 392 | . 393 | 10.2. Effect of New Versions 394 | . 395 | You may distribute the Covered Software under the terms of the version 396 | of the License under which You originally received the Covered Software, 397 | or under the terms of any subsequent version published by the license 398 | steward. 399 | . 400 | 10.3. Modified Versions 401 | . 402 | If you create software not governed by this License, and you want to 403 | create a new license for such software, you may create and use a 404 | modified version of this License if you rename the license and remove 405 | any references to the name of the license steward (except to note that 406 | such modified license differs from this License). 407 | . 408 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 409 | Licenses 410 | . 411 | If You choose to distribute Source Code Form that is Incompatible With 412 | Secondary Licenses under the terms of this version of the License, the 413 | notice described in Exhibit B of this License must be attached. 414 | . 415 | Exhibit A - Source Code Form License Notice 416 | ------------------------------------------- 417 | . 418 | This Source Code Form is subject to the terms of the Mozilla Public 419 | License, v. 2.0. If a copy of the MPL was not distributed with this 420 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 421 | . 422 | If it is not possible or desirable to put the notice in a particular 423 | file, then You may include the notice in a location (such as a LICENSE 424 | file in a relevant directory) where a recipient would be likely to look 425 | for such a notice. 426 | . 427 | You may add additional accurate notices of copyright ownership. 428 | . 429 | Exhibit B - "Incompatible With Secondary Licenses" Notice 430 | --------------------------------------------------------- 431 | . 432 | This Source Code Form is "Incompatible With Secondary Licenses", as 433 | defined by the Mozilla Public License, v. 2.0. 434 | -------------------------------------------------------------------------------- /vendor/composer/autoload_classmap.php: -------------------------------------------------------------------------------- 1 | array($vendorDir . '/firebase/php-jwt/src'), 10 | ); 11 | -------------------------------------------------------------------------------- /vendor/composer/autoload_real.php: -------------------------------------------------------------------------------- 1 | $path) { 28 | $loader->set($namespace, $path); 29 | } 30 | 31 | $map = require __DIR__ . '/autoload_psr4.php'; 32 | foreach ($map as $namespace => $path) { 33 | $loader->setPsr4($namespace, $path); 34 | } 35 | 36 | $classMap = require __DIR__ . '/autoload_classmap.php'; 37 | if ($classMap) { 38 | $loader->addClassMap($classMap); 39 | } 40 | 41 | $loader->register(true); 42 | 43 | return $loader; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /vendor/composer/installed.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "firebase/php-jwt", 4 | "version": "v5.0.0", 5 | "version_normalized": "5.0.0.0", 6 | "source": { 7 | "type": "git", 8 | "url": "https://github.com/firebase/php-jwt.git", 9 | "reference": "9984a4d3a32ae7673d6971ea00bae9d0a1abba0e" 10 | }, 11 | "dist": { 12 | "type": "zip", 13 | "url": "https://api.github.com/repos/firebase/php-jwt/zipball/9984a4d3a32ae7673d6971ea00bae9d0a1abba0e", 14 | "reference": "9984a4d3a32ae7673d6971ea00bae9d0a1abba0e", 15 | "shasum": "" 16 | }, 17 | "require": { 18 | "php": ">=5.3.0" 19 | }, 20 | "require-dev": { 21 | "phpunit/phpunit": " 4.8.35" 22 | }, 23 | "time": "2017-06-27 22:17:23", 24 | "type": "library", 25 | "installation-source": "dist", 26 | "autoload": { 27 | "psr-4": { 28 | "Firebase\\JWT\\": "src" 29 | } 30 | }, 31 | "notification-url": "https://packagist.org/downloads/", 32 | "license": [ 33 | "BSD-3-Clause" 34 | ], 35 | "authors": [ 36 | { 37 | "name": "Neuman Vong", 38 | "email": "neuman+pear@twilio.com", 39 | "role": "Developer" 40 | }, 41 | { 42 | "name": "Anant Narayanan", 43 | "email": "anant@php.net", 44 | "role": "Developer" 45 | } 46 | ], 47 | "description": "A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.", 48 | "homepage": "https://github.com/firebase/php-jwt" 49 | } 50 | ] 51 | -------------------------------------------------------------------------------- /vendor/firebase/php-jwt/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011, Neuman Vong 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following 13 | disclaimer in the documentation and/or other materials provided 14 | with the distribution. 15 | 16 | * Neither the name of Neuman Vong nor the names of other 17 | contributors may be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /vendor/firebase/php-jwt/README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/firebase/php-jwt.png?branch=master)](https://travis-ci.org/firebase/php-jwt) 2 | [![Latest Stable Version](https://poser.pugx.org/firebase/php-jwt/v/stable)](https://packagist.org/packages/firebase/php-jwt) 3 | [![Total Downloads](https://poser.pugx.org/firebase/php-jwt/downloads)](https://packagist.org/packages/firebase/php-jwt) 4 | [![License](https://poser.pugx.org/firebase/php-jwt/license)](https://packagist.org/packages/firebase/php-jwt) 5 | 6 | PHP-JWT 7 | ======= 8 | A simple library to encode and decode JSON Web Tokens (JWT) in PHP, conforming to [RFC 7519](https://tools.ietf.org/html/rfc7519). 9 | 10 | Installation 11 | ------------ 12 | 13 | Use composer to manage your dependencies and download PHP-JWT: 14 | 15 | ```bash 16 | composer require firebase/php-jwt 17 | ``` 18 | 19 | Example 20 | ------- 21 | ```php 22 | "http://example.org", 28 | "aud" => "http://example.com", 29 | "iat" => 1356999524, 30 | "nbf" => 1357000000 31 | ); 32 | 33 | /** 34 | * IMPORTANT: 35 | * You must specify supported algorithms for your application. See 36 | * https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40 37 | * for a list of spec-compliant algorithms. 38 | */ 39 | $jwt = JWT::encode($token, $key); 40 | $decoded = JWT::decode($jwt, $key, array('HS256')); 41 | 42 | print_r($decoded); 43 | 44 | /* 45 | NOTE: This will now be an object instead of an associative array. To get 46 | an associative array, you will need to cast it as such: 47 | */ 48 | 49 | $decoded_array = (array) $decoded; 50 | 51 | /** 52 | * You can add a leeway to account for when there is a clock skew times between 53 | * the signing and verifying servers. It is recommended that this leeway should 54 | * not be bigger than a few minutes. 55 | * 56 | * Source: http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#nbfDef 57 | */ 58 | JWT::$leeway = 60; // $leeway in seconds 59 | $decoded = JWT::decode($jwt, $key, array('HS256')); 60 | 61 | ?> 62 | ``` 63 | Example with RS256 (openssl) 64 | ---------------------------- 65 | ```php 66 | "example.org", 98 | "aud" => "example.com", 99 | "iat" => 1356999524, 100 | "nbf" => 1357000000 101 | ); 102 | 103 | $jwt = JWT::encode($token, $privateKey, 'RS256'); 104 | echo "Encode:\n" . print_r($jwt, true) . "\n"; 105 | 106 | $decoded = JWT::decode($jwt, $publicKey, array('RS256')); 107 | 108 | /* 109 | NOTE: This will now be an object instead of an associative array. To get 110 | an associative array, you will need to cast it as such: 111 | */ 112 | 113 | $decoded_array = (array) $decoded; 114 | echo "Decode:\n" . print_r($decoded_array, true) . "\n"; 115 | ?> 116 | ``` 117 | 118 | Changelog 119 | --------- 120 | 121 | #### 5.0.0 / 2017-06-26 122 | - Support RS384 and RS512. 123 | See [#117](https://github.com/firebase/php-jwt/pull/117). Thanks [@joostfaassen](https://github.com/joostfaassen)! 124 | - Add an example for RS256 openssl. 125 | See [#125](https://github.com/firebase/php-jwt/pull/125). Thanks [@akeeman](https://github.com/akeeman)! 126 | - Detect invalid Base64 encoding in signature. 127 | See [#162](https://github.com/firebase/php-jwt/pull/162). Thanks [@psignoret](https://github.com/psignoret)! 128 | - Update `JWT::verify` to handle OpenSSL errors. 129 | See [#159](https://github.com/firebase/php-jwt/pull/159). Thanks [@bshaffer](https://github.com/bshaffer)! 130 | - Add `array` type hinting to `decode` method 131 | See [#101](https://github.com/firebase/php-jwt/pull/101). Thanks [@hywak](https://github.com/hywak)! 132 | - Add all JSON error types. 133 | See [#110](https://github.com/firebase/php-jwt/pull/110). Thanks [@gbalduzzi](https://github.com/gbalduzzi)! 134 | - Bugfix 'kid' not in given key list. 135 | See [#129](https://github.com/firebase/php-jwt/pull/129). Thanks [@stampycode](https://github.com/stampycode)! 136 | - Miscellaneous cleanup, documentation and test fixes. 137 | See [#107](https://github.com/firebase/php-jwt/pull/107), [#115](https://github.com/firebase/php-jwt/pull/115), 138 | [#160](https://github.com/firebase/php-jwt/pull/160), [#161](https://github.com/firebase/php-jwt/pull/161), and 139 | [#165](https://github.com/firebase/php-jwt/pull/165). Thanks [@akeeman](https://github.com/akeeman), 140 | [@chinedufn](https://github.com/chinedufn), and [@bshaffer](https://github.com/bshaffer)! 141 | 142 | #### 4.0.0 / 2016-07-17 143 | - Add support for late static binding. See [#88](https://github.com/firebase/php-jwt/pull/88) for details. Thanks to [@chappy84](https://github.com/chappy84)! 144 | - Use static `$timestamp` instead of `time()` to improve unit testing. See [#93](https://github.com/firebase/php-jwt/pull/93) for details. Thanks to [@josephmcdermott](https://github.com/josephmcdermott)! 145 | - Fixes to exceptions classes. See [#81](https://github.com/firebase/php-jwt/pull/81) for details. Thanks to [@Maks3w](https://github.com/Maks3w)! 146 | - Fixes to PHPDoc. See [#76](https://github.com/firebase/php-jwt/pull/76) for details. Thanks to [@akeeman](https://github.com/akeeman)! 147 | 148 | #### 3.0.0 / 2015-07-22 149 | - Minimum PHP version updated from `5.2.0` to `5.3.0`. 150 | - Add `\Firebase\JWT` namespace. See 151 | [#59](https://github.com/firebase/php-jwt/pull/59) for details. Thanks to 152 | [@Dashron](https://github.com/Dashron)! 153 | - Require a non-empty key to decode and verify a JWT. See 154 | [#60](https://github.com/firebase/php-jwt/pull/60) for details. Thanks to 155 | [@sjones608](https://github.com/sjones608)! 156 | - Cleaner documentation blocks in the code. See 157 | [#62](https://github.com/firebase/php-jwt/pull/62) for details. Thanks to 158 | [@johanderuijter](https://github.com/johanderuijter)! 159 | 160 | #### 2.2.0 / 2015-06-22 161 | - Add support for adding custom, optional JWT headers to `JWT::encode()`. See 162 | [#53](https://github.com/firebase/php-jwt/pull/53/files) for details. Thanks to 163 | [@mcocaro](https://github.com/mcocaro)! 164 | 165 | #### 2.1.0 / 2015-05-20 166 | - Add support for adding a leeway to `JWT:decode()` that accounts for clock skew 167 | between signing and verifying entities. Thanks to [@lcabral](https://github.com/lcabral)! 168 | - Add support for passing an object implementing the `ArrayAccess` interface for 169 | `$keys` argument in `JWT::decode()`. Thanks to [@aztech-dev](https://github.com/aztech-dev)! 170 | 171 | #### 2.0.0 / 2015-04-01 172 | - **Note**: It is strongly recommended that you update to > v2.0.0 to address 173 | known security vulnerabilities in prior versions when both symmetric and 174 | asymmetric keys are used together. 175 | - Update signature for `JWT::decode(...)` to require an array of supported 176 | algorithms to use when verifying token signatures. 177 | 178 | 179 | Tests 180 | ----- 181 | Run the tests using phpunit: 182 | 183 | ```bash 184 | $ pear install PHPUnit 185 | $ phpunit --configuration phpunit.xml.dist 186 | PHPUnit 3.7.10 by Sebastian Bergmann. 187 | ..... 188 | Time: 0 seconds, Memory: 2.50Mb 189 | OK (5 tests, 5 assertions) 190 | ``` 191 | 192 | New Lines in private keys 193 | ----- 194 | 195 | If your private key contains `\n` characters, be sure to wrap it in double quotes `""` 196 | and not single quotes `''` in order to properly interpret the escaped characters. 197 | 198 | License 199 | ------- 200 | [3-Clause BSD](http://opensource.org/licenses/BSD-3-Clause). 201 | -------------------------------------------------------------------------------- /vendor/firebase/php-jwt/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "firebase/php-jwt", 3 | "description": "A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.", 4 | "homepage": "https://github.com/firebase/php-jwt", 5 | "authors": [ 6 | { 7 | "name": "Neuman Vong", 8 | "email": "neuman+pear@twilio.com", 9 | "role": "Developer" 10 | }, 11 | { 12 | "name": "Anant Narayanan", 13 | "email": "anant@php.net", 14 | "role": "Developer" 15 | } 16 | ], 17 | "license": "BSD-3-Clause", 18 | "require": { 19 | "php": ">=5.3.0" 20 | }, 21 | "autoload": { 22 | "psr-4": { 23 | "Firebase\\JWT\\": "src" 24 | } 25 | }, 26 | "require-dev": { 27 | "phpunit/phpunit": " 4.8.35" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /vendor/firebase/php-jwt/src/BeforeValidException.php: -------------------------------------------------------------------------------- 1 | 18 | * @author Anant Narayanan 19 | * @license http://opensource.org/licenses/BSD-3-Clause 3-clause BSD 20 | * @link https://github.com/firebase/php-jwt 21 | */ 22 | class JWT 23 | { 24 | 25 | /** 26 | * When checking nbf, iat or expiration times, 27 | * we want to provide some extra leeway time to 28 | * account for clock skew. 29 | */ 30 | public static $leeway = 0; 31 | 32 | /** 33 | * Allow the current timestamp to be specified. 34 | * Useful for fixing a value within unit testing. 35 | * 36 | * Will default to PHP time() value if null. 37 | */ 38 | public static $timestamp = null; 39 | 40 | public static $supported_algs = array( 41 | 'HS256' => array('hash_hmac', 'SHA256'), 42 | 'HS512' => array('hash_hmac', 'SHA512'), 43 | 'HS384' => array('hash_hmac', 'SHA384'), 44 | 'RS256' => array('openssl', 'SHA256'), 45 | 'RS384' => array('openssl', 'SHA384'), 46 | 'RS512' => array('openssl', 'SHA512'), 47 | ); 48 | 49 | /** 50 | * Decodes a JWT string into a PHP object. 51 | * 52 | * @param string $jwt The JWT 53 | * @param string|array $key The key, or map of keys. 54 | * If the algorithm used is asymmetric, this is the public key 55 | * @param array $allowed_algs List of supported verification algorithms 56 | * Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256' 57 | * 58 | * @return object The JWT's payload as a PHP object 59 | * 60 | * @throws UnexpectedValueException Provided JWT was invalid 61 | * @throws SignatureInvalidException Provided JWT was invalid because the signature verification failed 62 | * @throws BeforeValidException Provided JWT is trying to be used before it's eligible as defined by 'nbf' 63 | * @throws BeforeValidException Provided JWT is trying to be used before it's been created as defined by 'iat' 64 | * @throws ExpiredException Provided JWT has since expired, as defined by the 'exp' claim 65 | * 66 | * @uses jsonDecode 67 | * @uses urlsafeB64Decode 68 | */ 69 | public static function decode($jwt, $key, array $allowed_algs = array()) 70 | { 71 | $timestamp = is_null(static::$timestamp) ? time() : static::$timestamp; 72 | 73 | if (empty($key)) { 74 | throw new InvalidArgumentException('Key may not be empty'); 75 | } 76 | $tks = explode('.', $jwt); 77 | if (count($tks) != 3) { 78 | throw new UnexpectedValueException('Wrong number of segments'); 79 | } 80 | list($headb64, $bodyb64, $cryptob64) = $tks; 81 | if (null === ($header = static::jsonDecode(static::urlsafeB64Decode($headb64)))) { 82 | throw new UnexpectedValueException('Invalid header encoding'); 83 | } 84 | if (null === $payload = static::jsonDecode(static::urlsafeB64Decode($bodyb64))) { 85 | throw new UnexpectedValueException('Invalid claims encoding'); 86 | } 87 | if (false === ($sig = static::urlsafeB64Decode($cryptob64))) { 88 | throw new UnexpectedValueException('Invalid signature encoding'); 89 | } 90 | if (empty($header->alg)) { 91 | throw new UnexpectedValueException('Empty algorithm'); 92 | } 93 | if (empty(static::$supported_algs[$header->alg])) { 94 | throw new UnexpectedValueException('Algorithm not supported'); 95 | } 96 | if (!in_array($header->alg, $allowed_algs)) { 97 | throw new UnexpectedValueException('Algorithm not allowed'); 98 | } 99 | if (is_array($key) || $key instanceof \ArrayAccess) { 100 | if (isset($header->kid)) { 101 | if (!isset($key[$header->kid])) { 102 | throw new UnexpectedValueException('"kid" invalid, unable to lookup correct key'); 103 | } 104 | $key = $key[$header->kid]; 105 | } else { 106 | throw new UnexpectedValueException('"kid" empty, unable to lookup correct key'); 107 | } 108 | } 109 | 110 | // Check the signature 111 | if (!static::verify("$headb64.$bodyb64", $sig, $key, $header->alg)) { 112 | throw new SignatureInvalidException('Signature verification failed'); 113 | } 114 | 115 | // Check if the nbf if it is defined. This is the time that the 116 | // token can actually be used. If it's not yet that time, abort. 117 | if (isset($payload->nbf) && $payload->nbf > ($timestamp + static::$leeway)) { 118 | throw new BeforeValidException( 119 | 'Cannot handle token prior to ' . date(DateTime::ISO8601, $payload->nbf) 120 | ); 121 | } 122 | 123 | // Check that this token has been created before 'now'. This prevents 124 | // using tokens that have been created for later use (and haven't 125 | // correctly used the nbf claim). 126 | if (isset($payload->iat) && $payload->iat > ($timestamp + static::$leeway)) { 127 | throw new BeforeValidException( 128 | 'Cannot handle token prior to ' . date(DateTime::ISO8601, $payload->iat) 129 | ); 130 | } 131 | 132 | // Check if this token has expired. 133 | if (isset($payload->exp) && ($timestamp - static::$leeway) >= $payload->exp) { 134 | throw new ExpiredException('Expired token'); 135 | } 136 | 137 | return $payload; 138 | } 139 | 140 | /** 141 | * Converts and signs a PHP object or array into a JWT string. 142 | * 143 | * @param object|array $payload PHP object or array 144 | * @param string $key The secret key. 145 | * If the algorithm used is asymmetric, this is the private key 146 | * @param string $alg The signing algorithm. 147 | * Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256' 148 | * @param mixed $keyId 149 | * @param array $head An array with header elements to attach 150 | * 151 | * @return string A signed JWT 152 | * 153 | * @uses jsonEncode 154 | * @uses urlsafeB64Encode 155 | */ 156 | public static function encode($payload, $key, $alg = 'HS256', $keyId = null, $head = null) 157 | { 158 | $header = array('typ' => 'JWT', 'alg' => $alg); 159 | if ($keyId !== null) { 160 | $header['kid'] = $keyId; 161 | } 162 | if ( isset($head) && is_array($head) ) { 163 | $header = array_merge($head, $header); 164 | } 165 | $segments = array(); 166 | $segments[] = static::urlsafeB64Encode(static::jsonEncode($header)); 167 | $segments[] = static::urlsafeB64Encode(static::jsonEncode($payload)); 168 | $signing_input = implode('.', $segments); 169 | 170 | $signature = static::sign($signing_input, $key, $alg); 171 | $segments[] = static::urlsafeB64Encode($signature); 172 | 173 | return implode('.', $segments); 174 | } 175 | 176 | /** 177 | * Sign a string with a given key and algorithm. 178 | * 179 | * @param string $msg The message to sign 180 | * @param string|resource $key The secret key 181 | * @param string $alg The signing algorithm. 182 | * Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256' 183 | * 184 | * @return string An encrypted message 185 | * 186 | * @throws DomainException Unsupported algorithm was specified 187 | */ 188 | public static function sign($msg, $key, $alg = 'HS256') 189 | { 190 | if (empty(static::$supported_algs[$alg])) { 191 | throw new DomainException('Algorithm not supported'); 192 | } 193 | list($function, $algorithm) = static::$supported_algs[$alg]; 194 | switch($function) { 195 | case 'hash_hmac': 196 | return hash_hmac($algorithm, $msg, $key, true); 197 | case 'openssl': 198 | $signature = ''; 199 | $success = openssl_sign($msg, $signature, $key, $algorithm); 200 | if (!$success) { 201 | throw new DomainException("OpenSSL unable to sign data"); 202 | } else { 203 | return $signature; 204 | } 205 | } 206 | } 207 | 208 | /** 209 | * Verify a signature with the message, key and method. Not all methods 210 | * are symmetric, so we must have a separate verify and sign method. 211 | * 212 | * @param string $msg The original message (header and body) 213 | * @param string $signature The original signature 214 | * @param string|resource $key For HS*, a string key works. for RS*, must be a resource of an openssl public key 215 | * @param string $alg The algorithm 216 | * 217 | * @return bool 218 | * 219 | * @throws DomainException Invalid Algorithm or OpenSSL failure 220 | */ 221 | private static function verify($msg, $signature, $key, $alg) 222 | { 223 | if (empty(static::$supported_algs[$alg])) { 224 | throw new DomainException('Algorithm not supported'); 225 | } 226 | 227 | list($function, $algorithm) = static::$supported_algs[$alg]; 228 | switch($function) { 229 | case 'openssl': 230 | $success = openssl_verify($msg, $signature, $key, $algorithm); 231 | if ($success === 1) { 232 | return true; 233 | } elseif ($success === 0) { 234 | return false; 235 | } 236 | // returns 1 on success, 0 on failure, -1 on error. 237 | throw new DomainException( 238 | 'OpenSSL error: ' . openssl_error_string() 239 | ); 240 | case 'hash_hmac': 241 | default: 242 | $hash = hash_hmac($algorithm, $msg, $key, true); 243 | if (function_exists('hash_equals')) { 244 | return hash_equals($signature, $hash); 245 | } 246 | $len = min(static::safeStrlen($signature), static::safeStrlen($hash)); 247 | 248 | $status = 0; 249 | for ($i = 0; $i < $len; $i++) { 250 | $status |= (ord($signature[$i]) ^ ord($hash[$i])); 251 | } 252 | $status |= (static::safeStrlen($signature) ^ static::safeStrlen($hash)); 253 | 254 | return ($status === 0); 255 | } 256 | } 257 | 258 | /** 259 | * Decode a JSON string into a PHP object. 260 | * 261 | * @param string $input JSON string 262 | * 263 | * @return object Object representation of JSON string 264 | * 265 | * @throws DomainException Provided string was invalid JSON 266 | */ 267 | public static function jsonDecode($input) 268 | { 269 | if (version_compare(PHP_VERSION, '5.4.0', '>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE > 4)) { 270 | /** In PHP >=5.4.0, json_decode() accepts an options parameter, that allows you 271 | * to specify that large ints (like Steam Transaction IDs) should be treated as 272 | * strings, rather than the PHP default behaviour of converting them to floats. 273 | */ 274 | $obj = json_decode($input, false, 512, JSON_BIGINT_AS_STRING); 275 | } else { 276 | /** Not all servers will support that, however, so for older versions we must 277 | * manually detect large ints in the JSON string and quote them (thus converting 278 | *them to strings) before decoding, hence the preg_replace() call. 279 | */ 280 | $max_int_length = strlen((string) PHP_INT_MAX) - 1; 281 | $json_without_bigints = preg_replace('/:\s*(-?\d{'.$max_int_length.',})/', ': "$1"', $input); 282 | $obj = json_decode($json_without_bigints); 283 | } 284 | 285 | if (function_exists('json_last_error') && $errno = json_last_error()) { 286 | static::handleJsonError($errno); 287 | } elseif ($obj === null && $input !== 'null') { 288 | throw new DomainException('Null result with non-null input'); 289 | } 290 | return $obj; 291 | } 292 | 293 | /** 294 | * Encode a PHP object into a JSON string. 295 | * 296 | * @param object|array $input A PHP object or array 297 | * 298 | * @return string JSON representation of the PHP object or array 299 | * 300 | * @throws DomainException Provided object could not be encoded to valid JSON 301 | */ 302 | public static function jsonEncode($input) 303 | { 304 | $json = json_encode($input); 305 | if (function_exists('json_last_error') && $errno = json_last_error()) { 306 | static::handleJsonError($errno); 307 | } elseif ($json === 'null' && $input !== null) { 308 | throw new DomainException('Null result with non-null input'); 309 | } 310 | return $json; 311 | } 312 | 313 | /** 314 | * Decode a string with URL-safe Base64. 315 | * 316 | * @param string $input A Base64 encoded string 317 | * 318 | * @return string A decoded string 319 | */ 320 | public static function urlsafeB64Decode($input) 321 | { 322 | $remainder = strlen($input) % 4; 323 | if ($remainder) { 324 | $padlen = 4 - $remainder; 325 | $input .= str_repeat('=', $padlen); 326 | } 327 | return base64_decode(strtr($input, '-_', '+/')); 328 | } 329 | 330 | /** 331 | * Encode a string with URL-safe Base64. 332 | * 333 | * @param string $input The string you want encoded 334 | * 335 | * @return string The base64 encode of what you passed in 336 | */ 337 | public static function urlsafeB64Encode($input) 338 | { 339 | return str_replace('=', '', strtr(base64_encode($input), '+/', '-_')); 340 | } 341 | 342 | /** 343 | * Helper method to create a JSON error. 344 | * 345 | * @param int $errno An error number from json_last_error() 346 | * 347 | * @return void 348 | */ 349 | private static function handleJsonError($errno) 350 | { 351 | $messages = array( 352 | JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', 353 | JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON', 354 | JSON_ERROR_CTRL_CHAR => 'Unexpected control character found', 355 | JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON', 356 | JSON_ERROR_UTF8 => 'Malformed UTF-8 characters' //PHP >= 5.3.3 357 | ); 358 | throw new DomainException( 359 | isset($messages[$errno]) 360 | ? $messages[$errno] 361 | : 'Unknown JSON error: ' . $errno 362 | ); 363 | } 364 | 365 | /** 366 | * Get the number of bytes in cryptographic strings. 367 | * 368 | * @param string 369 | * 370 | * @return int 371 | */ 372 | private static function safeStrlen($str) 373 | { 374 | if (function_exists('mb_strlen')) { 375 | return mb_strlen($str, '8bit'); 376 | } 377 | return strlen($str); 378 | } 379 | } 380 | -------------------------------------------------------------------------------- /vendor/firebase/php-jwt/src/SignatureInvalidException.php: -------------------------------------------------------------------------------- 1 |