Commit 1d0662f2 authored by Ehsan Fakhraie's avatar Ehsan Fakhraie

Sms Panel Completed

Pages and front added
parent 1e2d938d
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="SqlDialectMappings"> <component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/database/db.php" dialect="GenericSQL" /> <file url="file://$PROJECT_DIR$/components/database/db.php" dialect="GenericSQL" />
</component> </component>
</project> </project>
\ No newline at end of file
...@@ -2,14 +2,8 @@ ...@@ -2,14 +2,8 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="775582b5-a7ad-4195-9e5c-b03955643ffa" name="Default Changelist" comment=""> <list default="true" id="775582b5-a7ad-4195-9e5c-b03955643ffa" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/.idea/.gitignore" afterDir="false" /> <change afterPath="$PROJECT_DIR$/api/smsVerification.php" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/dataSources.xml" afterDir="false" /> <change afterPath="$PROJECT_DIR$/components/functions.php" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/php.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/sqldialects.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/database/data.json" afterDir="false" />
<change afterPath="$PROJECT_DIR$/libs/composer.json" afterDir="false" />
<change afterPath="$PROJECT_DIR$/libs/composer.lock" afterDir="false" />
<change afterPath="$PROJECT_DIR$/libs/vendor/autoload.php" afterDir="false" /> <change afterPath="$PROJECT_DIR$/libs/vendor/autoload.php" afterDir="false" />
<change afterPath="$PROJECT_DIR$/libs/vendor/composer/ClassLoader.php" afterDir="false" /> <change afterPath="$PROJECT_DIR$/libs/vendor/composer/ClassLoader.php" afterDir="false" />
<change afterPath="$PROJECT_DIR$/libs/vendor/composer/LICENSE" afterDir="false" /> <change afterPath="$PROJECT_DIR$/libs/vendor/composer/LICENSE" afterDir="false" />
...@@ -127,17 +121,29 @@ ...@@ -127,17 +121,29 @@
<change afterPath="$PROJECT_DIR$/libs/vendor/ralouphie/getallheaders/README.md" afterDir="false" /> <change afterPath="$PROJECT_DIR$/libs/vendor/ralouphie/getallheaders/README.md" afterDir="false" />
<change afterPath="$PROJECT_DIR$/libs/vendor/ralouphie/getallheaders/composer.json" afterDir="false" /> <change afterPath="$PROJECT_DIR$/libs/vendor/ralouphie/getallheaders/composer.json" afterDir="false" />
<change afterPath="$PROJECT_DIR$/libs/vendor/ralouphie/getallheaders/src/getallheaders.php" afterDir="false" /> <change afterPath="$PROJECT_DIR$/libs/vendor/ralouphie/getallheaders/src/getallheaders.php" afterDir="false" />
<change afterPath="$PROJECT_DIR$/smsPanel.php" afterDir="false" /> <change afterPath="$PROJECT_DIR$/pages/Information.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/profile-manager.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/profile-manager.iml" afterDir="false" /> <change afterPath="$PROJECT_DIR$/pages/login.html" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pages/login.php" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pages/register.html" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pages/register.php" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pages/script/ChangeNumbers.min.js" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pages/style.css" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pages/upload_section.html" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pages/verify.html" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pages/verify.php" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pages/welcome_page.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/sqldialects.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/sqldialects.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/database/db.php" beforeDir="false" afterPath="$PROJECT_DIR$/database/db.php" afterDir="false" /> <change beforePath="$PROJECT_DIR$/database/data.json" beforeDir="false" afterPath="$PROJECT_DIR$/components/database/data.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/database/db.php" beforeDir="false" afterPath="$PROJECT_DIR$/components/database/db.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/smsPanel.php" beforeDir="false" afterPath="$PROJECT_DIR$/components/smsPanel.php" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" /> <option name="LAST_RESOLUTION" value="IGNORE" />
</component> </component>
<component name="ComposerSettings" synchronizationState="SYNCHRONIZE"> <component name="ComposerSettings" doNotAsk="true" synchronizationState="SYNCHRONIZE">
<pharConfigPath>$PROJECT_DIR$/libs/composer.json</pharConfigPath> <pharConfigPath>$PROJECT_DIR$/libs/composer.json</pharConfigPath>
<execution> <execution>
<executable /> <executable />
...@@ -157,6 +163,13 @@ ...@@ -157,6 +163,13 @@
<expand /> <expand />
<select /> <select />
</component> </component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="CSS File" />
</list>
</option>
</component>
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component> </component>
...@@ -192,15 +205,19 @@ ...@@ -192,15 +205,19 @@
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" /> <property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" /> <property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" /> <property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" /> <property name="last_opened_file_path" value="$PROJECT_DIR$/pages/script" />
<property name="list.type.of.created.stylesheet" value="CSS" />
</component> </component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="G:\xampp2\htdocs\profile-manager\database" />
</key>
<key name="CopyFile.RECENT_KEYS"> <key name="CopyFile.RECENT_KEYS">
<recent name="G:\xampp2\htdocs\profile-manager\pages\script" />
<recent name="G:\xampp2\htdocs\profile-manager\pages" />
<recent name="G:\xampp2\htdocs\profile-manager" /> <recent name="G:\xampp2\htdocs\profile-manager" />
</key> </key>
<key name="MoveFile.RECENT_KEYS">
<recent name="G:\xampp2\htdocs\profile-manager\Components" />
<recent name="G:\xampp2\htdocs\profile-manager\database" />
</key>
</component> </component>
<component name="ServiceViewManager"> <component name="ServiceViewManager">
<option name="viewStates"> <option name="viewStates">
...@@ -225,8 +242,17 @@ ...@@ -225,8 +242,17 @@
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1579253465503</updated> <updated>1579253465503</updated>
<workItem from="1579253466623" duration="12836000" /> <workItem from="1579253466623" duration="12836000" />
<workItem from="1579269058943" duration="4253000" /> <workItem from="1579269058943" duration="4581000" />
<workItem from="1579358190270" duration="12820000" />
</task>
<task id="LOCAL-00001" summary="Database Created,&#10;Sms Panel Added">
<created>1579273628530</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1579273628530</updated>
</task> </task>
<option name="localTasksCounter" value="2" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
...@@ -234,6 +260,8 @@ ...@@ -234,6 +260,8 @@
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" /> <option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
<MESSAGE value="Database Created,&#10;Sms Panel Added" />
<option name="LAST_COMMIT_MESSAGE" value="Database Created,&#10;Sms Panel Added" />
</component> </component>
<component name="WindowStateProjectService"> <component name="WindowStateProjectService">
<state x="552" y="179" key="#SQL_Dialects" timestamp="1579259504374"> <state x="552" y="179" key="#SQL_Dialects" timestamp="1579259504374">
...@@ -244,17 +272,29 @@ ...@@ -244,17 +272,29 @@
<screen x="0" y="0" width="1920" height="1040" /> <screen x="0" y="0" width="1920" height="1040" />
</state> </state>
<state x="552" y="179" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1579259246781" /> <state x="552" y="179" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1579259246781" />
<state x="795" y="444" key="NewPhpFileDialog" timestamp="1579261625385"> <state x="585" y="115" key="CommitChangelistDialog2" timestamp="1579273627240">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="585" y="115" key="CommitChangelistDialog2/0.0.1920.1040@0.0.1920.1040" timestamp="1579273627240" />
<state x="184" y="92" key="DiffContextDialog" timestamp="1579273377744">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="184" y="92" key="DiffContextDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1579273377744" />
<state x="795" y="444" key="NewPhpFileDialog" timestamp="1579367021667">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="795" y="444" key="NewPhpFileDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1579367021667" />
<state x="552" y="253" key="Vcs.Push.Dialog.v2" timestamp="1579273634065">
<screen x="0" y="0" width="1920" height="1040" /> <screen x="0" y="0" width="1920" height="1040" />
</state> </state>
<state x="795" y="444" key="NewPhpFileDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1579261625385" /> <state x="552" y="253" key="Vcs.Push.Dialog.v2/0.0.1920.1040@0.0.1920.1040" timestamp="1579273634065" />
<state x="655" y="344" key="com.intellij.ide.util.TipDialog" timestamp="1579269063579"> <state x="655" y="344" key="com.intellij.ide.util.TipDialog" timestamp="1579358192722">
<screen x="0" y="0" width="1920" height="1040" /> <screen x="0" y="0" width="1920" height="1040" />
</state> </state>
<state x="655" y="344" key="com.intellij.ide.util.TipDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1579269063579" /> <state x="655" y="344" key="com.intellij.ide.util.TipDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1579358192722" />
<state x="623" y="225" width="672" height="678" key="search.everywhere.popup" timestamp="1579264998252"> <state x="623" y="225" width="672" height="678" key="search.everywhere.popup" timestamp="1579370071419">
<screen x="0" y="0" width="1920" height="1040" /> <screen x="0" y="0" width="1920" height="1040" />
</state> </state>
<state x="623" y="225" width="672" height="678" key="search.everywhere.popup/0.0.1920.1040@0.0.1920.1040" timestamp="1579264998252" /> <state x="623" y="225" width="672" height="678" key="search.everywhere.popup/0.0.1920.1040@0.0.1920.1040" timestamp="1579370071419" />
</component> </component>
</project> </project>
\ No newline at end of file
<?php
require_once "../components/database/db.php";
if(isset($_GET["phone"])&&isset($_GET["code"])){
if(checkValidationCode($_GET["phone"],$_GET["code"])){
echo("1");
echo isPhoneVerified($_GET["phone"]);
}else{
echo("0");
}
}else{
echo("0");
}
...@@ -17,9 +17,11 @@ class User ...@@ -17,9 +17,11 @@ class User
public $address; public $address;
public $movies; public $movies;
public $registered; public $registered;
public $phoneVerified;
} }
class ValidationCode{ class ValidationCode
{
public $number; public $number;
public $date; public $date;
public $code; public $code;
...@@ -32,7 +34,7 @@ mysqli_set_charset($conn, "utf8"); ...@@ -32,7 +34,7 @@ mysqli_set_charset($conn, "utf8");
if ($conn->connect_error) { if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error); die("Connection failed: " . $conn->connect_error);
} else { } else {
insertValidationCode("09392291379");
} }
function getAllUsers() function getAllUsers()
...@@ -43,16 +45,7 @@ function getAllUsers() ...@@ -43,16 +45,7 @@ function getAllUsers()
$userArray = new ArrayObject(array()); $userArray = new ArrayObject(array());
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
$user = new User(); $userArray->append(sqlDataToUser($row));
$user->id = $row["id"];
$user->name = $row["full_name"];
$user->email = $row["email"];
$user->phone = $row["phone"];
$user->password = $row["password"];
$user->nationalCode = $row["national_code"];
$user->address = $row["address"];
$user->movies = $row["movies"];
$userArray->append($user);
} }
return $userArray; return $userArray;
...@@ -66,15 +59,7 @@ function getUser($id) ...@@ -66,15 +59,7 @@ function getUser($id)
$user = new User(); $user = new User();
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
$user = sqlDataToUser($row);
$user->id = $row["id"];
$user->name = $row["full_name"];
$user->email = $row["email"];
$user->phone = $row["phone"];
$user->password = $row["password"];
$user->nationalCode = $row["national_code"];
$user->address = $row["address"];
$user->movies = $row["movies"];
} }
return $user; return $user;
...@@ -83,8 +68,6 @@ function getUser($id) ...@@ -83,8 +68,6 @@ function getUser($id)
function deleteUser($id) function deleteUser($id)
{ {
global $conn; global $conn;
// sql to delete a record // sql to delete a record
$sql = "DELETE FROM users WHERE id=" . $id; $sql = "DELETE FROM users WHERE id=" . $id;
...@@ -96,11 +79,21 @@ function deleteUser($id) ...@@ -96,11 +79,21 @@ function deleteUser($id)
} }
function createNewUser($phone){
global $conn;
$sql="INSERT INTO users (phone) values ('$phone')";
if ($conn->query($sql) === TRUE) {
return $last_id = $conn->insert_id;
} else {
return 0;
}
}
function insertUser(User $user) function insertUser(User $user)
{ {
global $conn; global $conn;
$sql = "INSERT INTO `users` (`registered`, `full_name`, `email`, `phone`, `password`, `national_code`, `address`, `movies`) VALUES ('".$user->registered."', $sql = "INSERT INTO `users` (`registered`, `full_name`, `email`, `phone`, `password`, `national_code`, `address`, `movies`) VALUES ('" . $user->registered . "',
'".$user->name."', '".$user->email."', '".$user->phone."', '".$user->password."', '".$user->nationalCode."', '".$user->address."', '".$user->movies."')"; '" . $user->name . "', '" . $user->email . "', '" . $user->phone . "', '" . $user->password . "', '" . $user->nationalCode . "', '" . $user->address . "', '" . $user->movies . "')";
if ($conn->query($sql) === TRUE) { if ($conn->query($sql) === TRUE) {
return 1; return 1;
} else { } else {
...@@ -108,55 +101,93 @@ function insertUser(User $user) ...@@ -108,55 +101,93 @@ function insertUser(User $user)
} }
} }
function sqlDataToUser($d)
{
$user = new User();
$user->registered = $d["registered"];
$user->name = $d["full_name"];
$user->email = $d["email"];
$user->phone = $d["phone"];
$user->password = "";
$user->nationalCode = $d["national_code"];
$user->address = $d["address"];
$user->movies = $d["movies"];
$user->phoneVerified = $d["phone_verified"];
return $user;
}
function insertUsersByJson($file) function insertUsersByJson($file)
{ {
$studentjsondata = file_get_contents($file); $studentjsondata = file_get_contents($file);
$data = json_decode($studentjsondata, true); $data = json_decode($studentjsondata, true);
$d = ""; $d = "";
foreach ($data as $d) { foreach ($data as $d) {
echo $d["full_name"] . "<br/>"; insertUser(sqlDataToUser($d));
$user=new User();
$user->registered=$d["registered"];
$user->name=$d["full_name"];
$user->email=$d["email"];
$user->phone=$d["phone"];
$user->password="";
$user->nationalCode=$d["national_code"];
$user->address=$d["address"];
$user->movies=$d["movies"];
insertUser($user);
} }
} }
function insertValidationCode($phone){ function insertValidationCode($phone)
$code=generateRandomString(5); {
$code = generateRandomString(5);
global $conn; global $conn;
$date=date("h:i:s Y/m/d"); $date = date("h:i:s Y/m/d");
$sql="select * from phone_verification where phone=".$phone; $sql = "select * from phone_verification where phone=" . $phone;
$sql2="Insert into phone_verification (date,phone,vcode) values ('$date' ,'$phone','$code')"; $sql2 = "Insert into phone_verification (date,phone,vcode) values ('$date' ,'$phone','$code')";
$sql3="UPDATE `phone_verification` SET `date`='$date',`phone`='$phone',`vcode`='$code' WHERE phone = '$phone'"; $sql3 = "UPDATE `phone_verification` SET `date`='$date',`phone`='$phone',`vcode`='$code' WHERE phone = '$phone'";
$result=$conn->query($sql); $result = $conn->query($sql);
if($result->num_rows == 0) { if ($result->num_rows == 0) {
if($conn->query($sql2)){ if ($conn->query($sql2)) {
return $code; return $code;
}else{ } else {
return "error"; return "error";
} }
} else { } else {
if($conn->query($sql3)){ if ($conn->query($sql3)) {
return $code; return $code;
}else{ } else {
return "error"; return "error";
} }
} }
} }
function generateRandomString($length) { function checkValidationCode($phone, $code)
{
global $conn;
$sql = "select * from phone_verification where phone= " . $phone . " AND vcode= " . $code;
$sql2 = "UPDATE users SET phone_verified=1 where phone=" . $phone;
$result = $conn->query($sql);
if ($result->num_rows == 0) {
return 0;
} else {
if ($conn->query($sql2)) {
return 1;
} else
return 0;
}
}
function isPhoneVerified($phone){
global $conn;
$sql = "select * from users where phone= " . $phone;
if($result = $conn->query($sql)){
while ($row = $result->fetch_assoc()) {
if($row["phone_verified"]){
return 1;
}else
return 0;
}
}else
return 0;
}
function generateRandomString($length)
{
$characters = '0123456789'; $characters = '0123456789';
$charactersLength = strlen($characters); $charactersLength = strlen($characters);
$randomString = ''; $randomString = '';
......
<?php
function css_include(){
return "
<link rel=\"stylesheet\" media=\"screen\" href=\"https://fontlibrary.org/face/iranian-sans\" type=\"text/css\"/>
<link rel=\"stylesheet\" href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css\" integrity=\"sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh\" crossorigin=\"anonymous\">
<link rel='stylesheet' href='style.css'>
<script src=\"script/ChangeNumbers.min.js\"></script>
";
}
function script_include(){
return "
<script src=\"https://code.jquery.com/jquery-3.3.1.slim.min.js\" integrity=\"sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo\" crossorigin=\"anonymous\"></script>
<script src=\"https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js\" integrity=\"sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1\" crossorigin=\"anonymous\"></script>
<script src=\"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js\" integrity=\"sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM\" crossorigin=\"anonymous\"></script>";
}
function fa_number($number)
{
$en = array("0","1","2","3","4","5","6","7","8","9");
$fa = array("۰","۱","۲","۳","۴","۵","۶","۷","۸","۹");
return str_replace($en, $fa, $number);}
\ No newline at end of file
...@@ -11,7 +11,7 @@ $UserApiKey = "d47a0cc110357aa5e57e003a"; ...@@ -11,7 +11,7 @@ $UserApiKey = "d47a0cc110357aa5e57e003a";
$SecretKey = "it66)%#teBC!@*&03984"; $SecretKey = "it66)%#teBC!@*&03984";
$LineNumber = "3000782121"; $LineNumber = "3000782121";
sendCode("09392291379");
function sendCode($phone) function sendCode($phone)
{ {
...@@ -38,7 +38,7 @@ function sendCode($phone) ...@@ -38,7 +38,7 @@ function sendCode($phone)
$SmsIR_SendMessage = new SmsIR_SendMessage($APIKey, $SecretKey, $LineNumber, $APIURL); $SmsIR_SendMessage = new SmsIR_SendMessage($APIKey, $SecretKey, $LineNumber, $APIURL);
$SendMessage = $SmsIR_SendMessage->sendMessage($MobileNumbers, $Messages, $SendDateTime); $SendMessage = $SmsIR_SendMessage->sendMessage($MobileNumbers, $Messages, $SendDateTime);
var_dump($SendMessage); // var_dump($SendMessage);
} catch (Exeption $e) { } catch (Exeption $e) {
echo 'Error SendMessage : '.$e->getMessage(); echo 'Error SendMessage : '.$e->getMessage();
......
<?php
// autoload.php @generated by Composer
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit8de50260f05224fc92be9c39f5a54826::getLoader();
This diff is collapsed.
Copyright (c) Nils Adermann, Jordi Boggiano
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);
<?php
// autoload_files.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'7b11c4dc42b3b3023073cb14e519683c' => $vendorDir . '/ralouphie/getallheaders/src/getallheaders.php',
'a0edc8309cc5e1d60e3047b5df6b7052' => $vendorDir . '/guzzlehttp/psr7/src/functions_include.php',
'c964ee0ededf28c96ebd9db5099ef910' => $vendorDir . '/guzzlehttp/promises/src/functions_include.php',
'37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php',
);
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-message/src'),
'GuzzleHttp\\Psr7\\' => array($vendorDir . '/guzzlehttp/psr7/src'),
'GuzzleHttp\\Promise\\' => array($vendorDir . '/guzzlehttp/promises/src'),
'GuzzleHttp\\' => array($vendorDir . '/guzzlehttp/guzzle/src'),
);
<?php
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit8de50260f05224fc92be9c39f5a54826
{
private static $loader;
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/ClassLoader.php';
}
}
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit8de50260f05224fc92be9c39f5a54826', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit8de50260f05224fc92be9c39f5a54826', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit8de50260f05224fc92be9c39f5a54826::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
$map = require __DIR__ . '/autoload_psr4.php';
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
}
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit8de50260f05224fc92be9c39f5a54826::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire8de50260f05224fc92be9c39f5a54826($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequire8de50260f05224fc92be9c39f5a54826($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
}
}
<?php
// autoload_static.php @generated by Composer
namespace Composer\Autoload;
class ComposerStaticInit8de50260f05224fc92be9c39f5a54826
{
public static $files = array (
'7b11c4dc42b3b3023073cb14e519683c' => __DIR__ . '/..' . '/ralouphie/getallheaders/src/getallheaders.php',
'a0edc8309cc5e1d60e3047b5df6b7052' => __DIR__ . '/..' . '/guzzlehttp/psr7/src/functions_include.php',
'c964ee0ededf28c96ebd9db5099ef910' => __DIR__ . '/..' . '/guzzlehttp/promises/src/functions_include.php',
'37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php',
);
public static $prefixLengthsPsr4 = array (
'P' =>
array (
'Psr\\Http\\Message\\' => 17,
),
'G' =>
array (
'GuzzleHttp\\Psr7\\' => 16,
'GuzzleHttp\\Promise\\' => 19,
'GuzzleHttp\\' => 11,
),
);
public static $prefixDirsPsr4 = array (
'Psr\\Http\\Message\\' =>
array (
0 => __DIR__ . '/..' . '/psr/http-message/src',
),
'GuzzleHttp\\Psr7\\' =>
array (
0 => __DIR__ . '/..' . '/guzzlehttp/psr7/src',
),
'GuzzleHttp\\Promise\\' =>
array (
0 => __DIR__ . '/..' . '/guzzlehttp/promises/src',
),
'GuzzleHttp\\' =>
array (
0 => __DIR__ . '/..' . '/guzzlehttp/guzzle/src',
),
);
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit8de50260f05224fc92be9c39f5a54826::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit8de50260f05224fc92be9c39f5a54826::$prefixDirsPsr4;
}, null, ClassLoader::class);
}
}
[
{
"name": "ralouphie/getallheaders",
"version": "3.0.3",
"version_normalized": "3.0.3.0",
"source": {
"type": "git",
"url": "https://github.com/ralouphie/getallheaders.git",
"reference": "120b605dfeb996808c31b6477290a714d356e822"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822",
"reference": "120b605dfeb996808c31b6477290a714d356e822",
"shasum": ""
},
"require": {
"php": ">=5.6"
},
"require-dev": {
"php-coveralls/php-coveralls": "^2.1",
"phpunit/phpunit": "^5 || ^6.5"
},
"time": "2019-03-08T08:55:37+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"files": [
"src/getallheaders.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Ralph Khattar",
"email": "ralph.khattar@gmail.com"
}
],
"description": "A polyfill for getallheaders."
},
{
"name": "psr/http-message",
"version": "1.0.1",
"version_normalized": "1.0.1.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"time": "2016-08-06T14:39:51+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for HTTP messages",
"homepage": "https://github.com/php-fig/http-message",
"keywords": [
"http",
"http-message",
"psr",
"psr-7",
"request",
"response"
]
},
{
"name": "guzzlehttp/psr7",
"version": "1.6.1",
"version_normalized": "1.6.1.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "239400de7a173fe9901b9ac7c06497751f00727a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/239400de7a173fe9901b9ac7c06497751f00727a",
"reference": "239400de7a173fe9901b9ac7c06497751f00727a",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"psr/http-message": "~1.0",
"ralouphie/getallheaders": "^2.0.5 || ^3.0.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"ext-zlib": "*",
"phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8"
},
"suggest": {
"zendframework/zend-httphandlerrunner": "Emit PSR-7 responses"
},
"time": "2019-07-01T23:21:34+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.6-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Tobias Schultze",
"homepage": "https://github.com/Tobion"
}
],
"description": "PSR-7 message implementation that also provides common utility methods",
"keywords": [
"http",
"message",
"psr-7",
"request",
"response",
"stream",
"uri",
"url"
]
},
{
"name": "guzzlehttp/promises",
"version": "v1.3.1",
"version_normalized": "1.3.1.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646",
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646",
"shasum": ""
},
"require": {
"php": ">=5.5.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0"
},
"time": "2016-12-20T10:07:11+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"GuzzleHttp\\Promise\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle promises library",
"keywords": [
"promise"
]
},
{
"name": "guzzlehttp/guzzle",
"version": "6.5.2",
"version_normalized": "6.5.2.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "43ece0e75098b7ecd8d13918293029e555a50f82"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/43ece0e75098b7ecd8d13918293029e555a50f82",
"reference": "43ece0e75098b7ecd8d13918293029e555a50f82",
"shasum": ""
},
"require": {
"ext-json": "*",
"guzzlehttp/promises": "^1.0",
"guzzlehttp/psr7": "^1.6.1",
"php": ">=5.5"
},
"require-dev": {
"ext-curl": "*",
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0",
"psr/log": "^1.1"
},
"suggest": {
"ext-intl": "Required for Internationalized Domain Name (IDN) support",
"psr/log": "Required for using the Log middleware"
},
"time": "2019-12-23T11:57:10+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "6.5-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"GuzzleHttp\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle is a PHP HTTP client library",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"rest",
"web service"
]
}
]
<?php
$config = PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'declare_strict_types' => false,
'concat_space' => ['spacing'=>'one'],
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
'ordered_imports' => true,
// 'phpdoc_align' => ['align'=>'vertical'],
// 'native_function_invocation' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
->name('*.php')
)
;
return $config;
This diff is collapsed.
FROM composer:latest as setup
RUN mkdir /guzzle
WORKDIR /guzzle
RUN set -xe \
&& composer init --name=guzzlehttp/test --description="Simple project for testing Guzzle scripts" --author="Márk Sági-Kazár <mark.sagikazar@gmail.com>" --no-interaction \
&& composer require guzzlehttp/guzzle
FROM php:7.3
RUN mkdir /guzzle
WORKDIR /guzzle
COPY --from=setup /guzzle /guzzle
Copyright (c) 2011-2018 Michael Dowling, https://github.com/mtdowling <mtdowling@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Guzzle, PHP HTTP client
=======================
[![Latest Version](https://img.shields.io/github/release/guzzle/guzzle.svg?style=flat-square)](https://github.com/guzzle/guzzle/releases)
[![Build Status](https://img.shields.io/travis/guzzle/guzzle.svg?style=flat-square)](https://travis-ci.org/guzzle/guzzle)
[![Total Downloads](https://img.shields.io/packagist/dt/guzzlehttp/guzzle.svg?style=flat-square)](https://packagist.org/packages/guzzlehttp/guzzle)
Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and
trivial to integrate with web services.
- Simple interface for building query strings, POST requests, streaming large
uploads, streaming large downloads, using HTTP cookies, uploading JSON data,
etc...
- Can send both synchronous and asynchronous requests using the same interface.
- Uses PSR-7 interfaces for requests, responses, and streams. This allows you
to utilize other PSR-7 compatible libraries with Guzzle.
- Abstracts away the underlying HTTP transport, allowing you to write
environment and transport agnostic code; i.e., no hard dependency on cURL,
PHP streams, sockets, or non-blocking event loops.
- Middleware system allows you to augment and compose client behavior.
```php
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', 'https://api.github.com/repos/guzzle/guzzle');
echo $response->getStatusCode(); # 200
echo $response->getHeaderLine('content-type'); # 'application/json; charset=utf8'
echo $response->getBody(); # '{"id": 1420053, "name": "guzzle", ...}'
# Send an asynchronous request.
$request = new \GuzzleHttp\Psr7\Request('GET', 'http://httpbin.org');
$promise = $client->sendAsync($request)->then(function ($response) {
echo 'I completed! ' . $response->getBody();
});
$promise->wait();
```
## Help and docs
- [Documentation](http://guzzlephp.org/)
- [Stack Overflow](http://stackoverflow.com/questions/tagged/guzzle)
- [Gitter](https://gitter.im/guzzle/guzzle)
## Installing Guzzle
The recommended way to install Guzzle is through
[Composer](http://getcomposer.org).
```bash
# Install Composer
curl -sS https://getcomposer.org/installer | php
```
Next, run the Composer command to install the latest stable version of Guzzle:
```bash
composer require guzzlehttp/guzzle
```
After installing, you need to require Composer's autoloader:
```php
require 'vendor/autoload.php';
```
You can then later update Guzzle using composer:
```bash
composer update
```
## Version Guidance
| Version | Status | Packagist | Namespace | Repo | Docs | PSR-7 | PHP Version |
|---------|------------|---------------------|--------------|---------------------|---------------------|-------|-------------|
| 3.x | EOL | `guzzle/guzzle` | `Guzzle` | [v3][guzzle-3-repo] | [v3][guzzle-3-docs] | No | >= 5.3.3 |
| 4.x | EOL | `guzzlehttp/guzzle` | `GuzzleHttp` | [v4][guzzle-4-repo] | N/A | No | >= 5.4 |
| 5.x | EOL | `guzzlehttp/guzzle` | `GuzzleHttp` | [v5][guzzle-5-repo] | [v5][guzzle-5-docs] | No | >= 5.4 |
| 6.x | Latest | `guzzlehttp/guzzle` | `GuzzleHttp` | [v6][guzzle-6-repo] | [v6][guzzle-6-docs] | Yes | >= 5.5 |
[guzzle-3-repo]: https://github.com/guzzle/guzzle3
[guzzle-4-repo]: https://github.com/guzzle/guzzle/tree/4.x
[guzzle-5-repo]: https://github.com/guzzle/guzzle/tree/5.3
[guzzle-6-repo]: https://github.com/guzzle/guzzle
[guzzle-3-docs]: http://guzzle3.readthedocs.org
[guzzle-5-docs]: http://guzzle.readthedocs.org/en/5.3/
[guzzle-6-docs]: http://guzzle.readthedocs.org/en/latest/
This diff is collapsed.
{
"name": "guzzlehttp/guzzle",
"type": "library",
"description": "Guzzle is a PHP HTTP client library",
"keywords": [
"framework",
"http",
"rest",
"web service",
"curl",
"client",
"HTTP client"
],
"homepage": "http://guzzlephp.org/",
"license": "MIT",
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"require": {
"php": ">=5.5",
"ext-json": "*",
"guzzlehttp/promises": "^1.0",
"guzzlehttp/psr7": "^1.6.1"
},
"require-dev": {
"ext-curl": "*",
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0",
"psr/log": "^1.1"
},
"suggest": {
"psr/log": "Required for using the Log middleware",
"ext-intl": "Required for Internationalized Domain Name (IDN) support"
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "6.5-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"autoload-dev": {
"psr-4": {
"GuzzleHttp\\Tests\\": "tests/"
}
}
}
This diff is collapsed.
<?php
namespace GuzzleHttp;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Promise\PromiseInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;
/**
* Client interface for sending HTTP requests.
*/
interface ClientInterface
{
/**
* @deprecated Will be removed in Guzzle 7.0.0
*/
const VERSION = '6.5.1';
/**
* Send an HTTP request.
*
* @param RequestInterface $request Request to send
* @param array $options Request options to apply to the given
* request and to the transfer.
*
* @return ResponseInterface
* @throws GuzzleException
*/
public function send(RequestInterface $request, array $options = []);
/**
* Asynchronously send an HTTP request.
*
* @param RequestInterface $request Request to send
* @param array $options Request options to apply to the given
* request and to the transfer.
*
* @return PromiseInterface
*/
public function sendAsync(RequestInterface $request, array $options = []);
/**
* Create and send an HTTP request.
*
* Use an absolute path to override the base path of the client, or a
* relative path to append to the base path of the client. The URL can
* contain the query string as well.
*
* @param string $method HTTP method.
* @param string|UriInterface $uri URI object or string.
* @param array $options Request options to apply.
*
* @return ResponseInterface
* @throws GuzzleException
*/
public function request($method, $uri, array $options = []);
/**
* Create and send an asynchronous HTTP request.
*
* Use an absolute path to override the base path of the client, or a
* relative path to append to the base path of the client. The URL can
* contain the query string as well. Use an array to provide a URL
* template and additional variables to use in the URL template expansion.
*
* @param string $method HTTP method
* @param string|UriInterface $uri URI object or string.
* @param array $options Request options to apply.
*
* @return PromiseInterface
*/
public function requestAsync($method, $uri, array $options = []);
/**
* Get a client configuration option.
*
* These options include default request options of the client, a "handler"
* (if utilized by the concrete client), and a "base_uri" if utilized by
* the concrete client.
*
* @param string|null $option The config option to retrieve.
*
* @return mixed
*/
public function getConfig($option = null);
}
<?php
namespace GuzzleHttp\Cookie;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
/**
* Cookie jar that stores cookies as an array
*/
class CookieJar implements CookieJarInterface
{
/** @var SetCookie[] Loaded cookie data */
private $cookies = [];
/** @var bool */
private $strictMode;
/**
* @param bool $strictMode Set to true to throw exceptions when invalid
* cookies are added to the cookie jar.
* @param array $cookieArray Array of SetCookie objects or a hash of
* arrays that can be used with the SetCookie
* constructor
*/
public function __construct($strictMode = false, $cookieArray = [])
{
$this->strictMode = $strictMode;
foreach ($cookieArray as $cookie) {
if (!($cookie instanceof SetCookie)) {
$cookie = new SetCookie($cookie);
}
$this->setCookie($cookie);
}
}
/**
* Create a new Cookie jar from an associative array and domain.
*
* @param array $cookies Cookies to create the jar from
* @param string $domain Domain to set the cookies to
*
* @return self
*/
public static function fromArray(array $cookies, $domain)
{
$cookieJar = new self();
foreach ($cookies as $name => $value) {
$cookieJar->setCookie(new SetCookie([
'Domain' => $domain,
'Name' => $name,
'Value' => $value,
'Discard' => true
]));
}
return $cookieJar;
}
/**
* @deprecated
*/
public static function getCookieValue($value)
{
return $value;
}
/**
* Evaluate if this cookie should be persisted to storage
* that survives between requests.
*
* @param SetCookie $cookie Being evaluated.
* @param bool $allowSessionCookies If we should persist session cookies
* @return bool
*/
public static function shouldPersist(
SetCookie $cookie,
$allowSessionCookies = false
) {
if ($cookie->getExpires() || $allowSessionCookies) {
if (!$cookie->getDiscard()) {
return true;
}
}
return false;
}
/**
* Finds and returns the cookie based on the name
*
* @param string $name cookie name to search for
* @return SetCookie|null cookie that was found or null if not found
*/
public function getCookieByName($name)
{
// don't allow a non string name
if ($name === null || !is_scalar($name)) {
return null;
}
foreach ($this->cookies as $cookie) {
if ($cookie->getName() !== null && strcasecmp($cookie->getName(), $name) === 0) {
return $cookie;
}
}
return null;
}
public function toArray()
{
return array_map(function (SetCookie $cookie) {
return $cookie->toArray();
}, $this->getIterator()->getArrayCopy());
}
public function clear($domain = null, $path = null, $name = null)
{
if (!$domain) {
$this->cookies = [];
return;
} elseif (!$path) {
$this->cookies = array_filter(
$this->cookies,
function (SetCookie $cookie) use ($domain) {
return !$cookie->matchesDomain($domain);
}
);
} elseif (!$name) {
$this->cookies = array_filter(
$this->cookies,
function (SetCookie $cookie) use ($path, $domain) {
return !($cookie->matchesPath($path) &&
$cookie->matchesDomain($domain));
}
);
} else {
$this->cookies = array_filter(
$this->cookies,
function (SetCookie $cookie) use ($path, $domain, $name) {
return !($cookie->getName() == $name &&
$cookie->matchesPath($path) &&
$cookie->matchesDomain($domain));
}
);
}
}
public function clearSessionCookies()
{
$this->cookies = array_filter(
$this->cookies,
function (SetCookie $cookie) {
return !$cookie->getDiscard() && $cookie->getExpires();
}
);
}
public function setCookie(SetCookie $cookie)
{
// If the name string is empty (but not 0), ignore the set-cookie
// string entirely.
$name = $cookie->getName();
if (!$name && $name !== '0') {
return false;
}
// Only allow cookies with set and valid domain, name, value
$result = $cookie->validate();
if ($result !== true) {
if ($this->strictMode) {
throw new \RuntimeException('Invalid cookie: ' . $result);
} else {
$this->removeCookieIfEmpty($cookie);
return false;
}
}
// Resolve conflicts with previously set cookies
foreach ($this->cookies as $i => $c) {
// Two cookies are identical, when their path, and domain are
// identical.
if ($c->getPath() != $cookie->getPath() ||
$c->getDomain() != $cookie->getDomain() ||
$c->getName() != $cookie->getName()
) {
continue;
}
// The previously set cookie is a discard cookie and this one is
// not so allow the new cookie to be set
if (!$cookie->getDiscard() && $c->getDiscard()) {
unset($this->cookies[$i]);
continue;
}
// If the new cookie's expiration is further into the future, then
// replace the old cookie
if ($cookie->getExpires() > $c->getExpires()) {
unset($this->cookies[$i]);
continue;
}
// If the value has changed, we better change it
if ($cookie->getValue() !== $c->getValue()) {
unset($this->cookies[$i]);
continue;
}
// The cookie exists, so no need to continue
return false;
}
$this->cookies[] = $cookie;
return true;
}
public function count()
{
return count($this->cookies);
}
public function getIterator()
{
return new \ArrayIterator(array_values($this->cookies));
}
public function extractCookies(
RequestInterface $request,
ResponseInterface $response
) {
if ($cookieHeader = $response->getHeader('Set-Cookie')) {
foreach ($cookieHeader as $cookie) {
$sc = SetCookie::fromString($cookie);
if (!$sc->getDomain()) {
$sc->setDomain($request->getUri()->getHost());
}
if (0 !== strpos($sc->getPath(), '/')) {
$sc->setPath($this->getCookiePathFromRequest($request));
}
$this->setCookie($sc);
}
}
}
/**
* Computes cookie path following RFC 6265 section 5.1.4
*
* @link https://tools.ietf.org/html/rfc6265#section-5.1.4
*
* @param RequestInterface $request
* @return string
*/
private function getCookiePathFromRequest(RequestInterface $request)
{
$uriPath = $request->getUri()->getPath();
if ('' === $uriPath) {
return '/';
}
if (0 !== strpos($uriPath, '/')) {
return '/';
}
if ('/' === $uriPath) {
return '/';
}
if (0 === $lastSlashPos = strrpos($uriPath, '/')) {
return '/';
}
return substr($uriPath, 0, $lastSlashPos);
}
public function withCookieHeader(RequestInterface $request)
{
$values = [];
$uri = $request->getUri();
$scheme = $uri->getScheme();
$host = $uri->getHost();
$path = $uri->getPath() ?: '/';
foreach ($this->cookies as $cookie) {
if ($cookie->matchesPath($path) &&
$cookie->matchesDomain($host) &&
!$cookie->isExpired() &&
(!$cookie->getSecure() || $scheme === 'https')
) {
$values[] = $cookie->getName() . '='
. $cookie->getValue();
}
}
return $values
? $request->withHeader('Cookie', implode('; ', $values))
: $request;
}
/**
* If a cookie already exists and the server asks to set it again with a
* null value, the cookie must be deleted.
*
* @param SetCookie $cookie
*/
private function removeCookieIfEmpty(SetCookie $cookie)
{
$cookieValue = $cookie->getValue();
if ($cookieValue === null || $cookieValue === '') {
$this->clear(
$cookie->getDomain(),
$cookie->getPath(),
$cookie->getName()
);
}
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment