Version Description
- Updated AWS lib to 1.5.2
- Security improvements
- Updated MS Azure to 4.1.0
- Updated RSC lib to 1.7.10
- Updatet oAuth lib for Dropbox
- increased memory on db dump
Download this release
Release Info
Developer | danielhuesken |
Plugin | BackWPup – WordPress Backup Plugin |
Version | 2.1.8 |
Comparing to | |
See all releases |
Code changes from version 2.1.7 to 2.1.8
- backwpup.php +2 -2
- job/backup_create.php +1 -1
- job/db_dump.php +1 -1
- job/dest_gstorage.php +2 -3
- job/dest_s3.php +1 -2
- job/job_run.php +2 -2
- job/show_working.php +3 -3
- job/wp_export_generate.php +2 -2
- libs/Microsoft/Console/Command.php +427 -0
- libs/Microsoft/Console/Command/ParameterSource/Argv.php +80 -0
- libs/Microsoft/Console/Command/ParameterSource/ConfigFile.php +111 -0
- libs/Microsoft/Console/Command/ParameterSource/Env.php +84 -0
- libs/Microsoft/Console/Command/ParameterSource/ParameterSourceInterface.php +57 -0
- libs/Microsoft/Console/Command/ParameterSource/Prompt.php +75 -0
- libs/Microsoft/Console/Command/ParameterSource/StdIn.php +90 -0
- libs/Microsoft/Console/Exception.php +48 -0
- libs/Microsoft/Http/Client.php +1427 -1427
- libs/Microsoft/Http/Client/Adapter/Curl.php +489 -489
- libs/Microsoft/Http/Client/Adapter/Exception.php +38 -38
- libs/Microsoft/Http/Client/Adapter/Interface.php +78 -78
- libs/Microsoft/Http/Client/Adapter/Proxy.php +259 -259
- libs/Microsoft/Http/Client/Adapter/Socket.php +523 -523
- libs/Microsoft/Http/Client/Adapter/Stream.php +46 -46
- libs/Microsoft/Http/Client/Exception.php +36 -36
- libs/Microsoft/Http/Cookie.php +408 -408
- libs/Microsoft/Http/CookieJar.php +395 -395
- libs/Microsoft/Http/Exception.php +1 -1
- libs/Microsoft/Http/Response.php +664 -664
- libs/Microsoft/Http/Response/Stream.php +240 -240
- libs/Microsoft/Log.php +426 -426
- libs/Microsoft/Log/Exception.php +48 -48
- libs/Microsoft/Log/FactoryInterface.php +38 -38
- libs/Microsoft/Log/Filter/Abstract.php +55 -55
- libs/Microsoft/Log/Filter/Interface.php +40 -40
- libs/Microsoft/Log/Filter/Message.php +87 -87
- libs/Microsoft/Log/Filter/Priority.php +103 -103
- libs/Microsoft/Log/Filter/Suppress.php +79 -79
- libs/Microsoft/Log/Formatter/Interface.php +41 -41
- libs/Microsoft/Log/Writer/Abstract.php +133 -133
- libs/Microsoft/SqlAzure/CommandLine/SqlAzure.php +298 -0
- libs/Microsoft/SqlAzure/Exception.php +48 -0
- libs/Microsoft/SqlAzure/Management/Client.php +564 -0
- libs/Microsoft/SqlAzure/Management/Exception.php +51 -0
- libs/Microsoft/SqlAzure/Management/FirewallRuleInstance.php +70 -0
- libs/Microsoft/SqlAzure/Management/ServerInstance.php +72 -0
- libs/Microsoft/SqlAzure/Management/ServiceEntityAbstract.php +84 -0
- libs/Microsoft/Uri.php +193 -193
- libs/Microsoft/Uri/Exception.php +37 -37
- libs/Microsoft/Uri/Http.php +761 -761
- libs/Microsoft/WindowsAzure/CommandLine/Certificate.php +187 -0
- libs/Microsoft/WindowsAzure/CommandLine/Deployment.php +745 -0
- libs/Microsoft/WindowsAzure/CommandLine/GetAsynchronousOperation.php +106 -0
- libs/Microsoft/WindowsAzure/CommandLine/Package.php +181 -0
- libs/Microsoft/WindowsAzure/CommandLine/PackageScaffolder/PackageScaffolderAbstract.php +324 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolder.php +193 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/build.bat +1 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/index.php +176 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/bin/add-environment-variables.cmd +8 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/bin/add-environment-variables.ps1 +14 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/bin/install-php-impl.cmd +13 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/bin/install-php.cmd +19 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/bin/install-php.ps1 +37 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/bin/monitor-environment.cmd +7 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/bin/monitor-environment.ps1 +53 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/diagnostics.wadcfg +35 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/php/ext/readme.txt +2 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/php/php.ini +21 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/resources/WebPICmdLine/Microsoft.Web.Deployment.dll +0 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/resources/WebPICmdLine/Microsoft.Web.PlatformInstaller.UI.dll +0 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/resources/WebPICmdLine/Microsoft.Web.PlatformInstaller.dll +0 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/resources/WebPICmdLine/WebpiCmdLine.exe +0 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/resources/WebPICmdLine/license.rtf +41 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/CommonWorker/run.bat +1 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/CommonWorker/worker.php +7 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/PhpOnAzure.Web/Web.config +20 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/PhpOnAzure.Web/bin/add-environment-variables.cmd +7 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/PhpOnAzure.Web/bin/add-environment-variables.ps1 +16 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/PhpOnAzure.Web/bin/install-php-impl.cmd +12 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/PhpOnAzure.Web/bin/install-php.cmd +11 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/PhpOnAzure.Web/bin/install-php.ps1 +30 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/PhpOnAzure.Web/diagnostics.wadcfg +35 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/PhpOnAzure.Web/php/ext/readme.txt +2 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/PhpOnAzure.Web/php/php.ini +21 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/PhpOnAzure.Web/resources/WebPICmdLine/Microsoft.Web.Deployment.dll +0 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/PhpOnAzure.Web/resources/WebPICmdLine/Microsoft.Web.PlatformInstaller.UI.dll +0 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/PhpOnAzure.Web/resources/WebPICmdLine/Microsoft.Web.PlatformInstaller.dll +0 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/PhpOnAzure.Web/resources/WebPICmdLine/WebpiCmdLine.exe +0 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/PhpOnAzure.Web/resources/WebPICmdLine/license.rtf +41 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/ServiceConfiguration.Web.cscfg +6 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/ServiceConfiguration.Worker.cscfg +6 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/ServiceConfiguration.cscfg +4 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/ServiceDefinition.Web.csdef +28 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/ServiceDefinition.Worker.csdef +23 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/ServiceDefinition.csdef +4 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/ScaffoldTemplateScaffolder/build.bat +1 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/ScaffoldTemplateScaffolder/index.php +87 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/ScaffoldTemplateScaffolder/resources/build.bat +1 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/ScaffoldTemplateScaffolder/resources/index.php +41 -0
- libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/ScaffoldTemplateScaffolder/resources/resources/readme.txt +1 -0
- libs/Microsoft/WindowsAzure/CommandLine/Service.php +209 -0
- libs/Microsoft/WindowsAzure/CommandLine/Storage.php +281 -0
- libs/Microsoft/WindowsAzure/CommandLine/sample.php +54 -0
- libs/Microsoft/WindowsAzure/Credentials/CredentialsAbstract.php +193 -252
- libs/Microsoft/WindowsAzure/Credentials/SharedAccessSignature.php +310 -310
- libs/Microsoft/WindowsAzure/Credentials/SharedKey.php +183 -185
- libs/Microsoft/WindowsAzure/Credentials/SharedKeyLite.php +162 -164
- libs/Microsoft/WindowsAzure/Exception.php +1 -1
- libs/Microsoft/WindowsAzure/Log/Formatter/WindowsAzure.php +80 -80
- libs/Microsoft/WindowsAzure/Log/Writer/WindowsAzure.php +186 -186
- libs/Microsoft/WindowsAzure/Management/AffinityGroupInstance.php +3 -3
- libs/Microsoft/WindowsAzure/Management/CertificateInstance.php +3 -3
- libs/Microsoft/WindowsAzure/Management/Client.php +252 -87
- libs/Microsoft/WindowsAzure/Management/DeploymentInstance.php +12 -6
- libs/Microsoft/WindowsAzure/Management/Exception.php +3 -3
- libs/Microsoft/WindowsAzure/Management/HostedServiceInstance.php +3 -3
- libs/Microsoft/WindowsAzure/Management/LocationInstance.php +3 -3
- libs/Microsoft/WindowsAzure/Management/OperatingSystemFamilyInstance.php +3 -3
- libs/Microsoft/WindowsAzure/Management/OperatingSystemInstance.php +3 -3
- libs/Microsoft/WindowsAzure/Management/OperationStatusInstance.php +3 -3
- libs/Microsoft/WindowsAzure/Management/ServiceEntityAbstract.php +3 -3
- libs/Microsoft/WindowsAzure/Management/StorageServiceInstance.php +3 -3
- libs/Microsoft/WindowsAzure/Management/SubscriptionOperationInstance.php +22 -16
- libs/Microsoft/WindowsAzure/RetryPolicy/Exception.php +1 -1
- libs/Microsoft/WindowsAzure/RetryPolicy/NoRetry.php +1 -1
- libs/Microsoft/WindowsAzure/RetryPolicy/RetryN.php +1 -1
- libs/Microsoft/WindowsAzure/RoleEnvironment.php +190 -0
- libs/Microsoft/WindowsAzure/SessionHandler.php +7 -0
- libs/Microsoft/WindowsAzure/Storage.php +113 -45
- libs/Microsoft/WindowsAzure/Storage/Batch.php +11 -8
- libs/Microsoft/WindowsAzure/Storage/BatchStorageAbstract.php +3 -4
- libs/Microsoft/WindowsAzure/Storage/Blob.php +43 -49
- libs/Microsoft/WindowsAzure/Storage/BlobContainer.php +1 -1
- libs/Microsoft/WindowsAzure/Storage/BlobInstance.php +1 -1
- libs/Microsoft/WindowsAzure/Storage/Queue.php +21 -24
- libs/Microsoft/WindowsAzure/Storage/Table.php +24 -35
- libs/Microsoft/WindowsAzure/Storage/TableEntityQuery.php +19 -44
- libs/Microsoft/WindowsAzure/bin/RoleEnvironmentProxy.exe +0 -0
- libs/Microsoft/WindowsAzure/bin/RoleEnvironmentProxy.exe.config +6 -0
- libs/aws/authentication/signable.interface.php +48 -48
- libs/aws/authentication/signature_v2query.class.php +163 -163
- libs/aws/authentication/signature_v3json.class.php +235 -0
- libs/aws/authentication/signature_v3query.class.php +192 -192
- libs/aws/authentication/signer.abstract.php +58 -68
backwpup.php
CHANGED
@@ -4,7 +4,7 @@ Plugin Name: BackWPup
|
|
4 |
Plugin URI: http://backwpup.com
|
5 |
Description: WordPress Backup and more...
|
6 |
Author: Daniel Hüsken
|
7 |
-
Version: 2.1.
|
8 |
Author URI: http://danielhuesken.de
|
9 |
Text Domain: backwpup
|
10 |
Domain Path: /lang/
|
@@ -32,7 +32,7 @@ Domain Path: /lang/
|
|
32 |
define('BACKWPUP_PLUGIN_BASEDIR', dirname(plugin_basename(__FILE__)));
|
33 |
define('BACKWPUP_PLUGIN_BASEURL',plugins_url('',__FILE__));
|
34 |
//Set Plugin Version
|
35 |
-
define('BACKWPUP_VERSION', '2.1.
|
36 |
//Set Min Wordpress Version
|
37 |
define('BACKWPUP_MIN_WORDPRESS_VERSION', '3.1');
|
38 |
//Set User Capability
|
4 |
Plugin URI: http://backwpup.com
|
5 |
Description: WordPress Backup and more...
|
6 |
Author: Daniel Hüsken
|
7 |
+
Version: 2.1.8
|
8 |
Author URI: http://danielhuesken.de
|
9 |
Text Domain: backwpup
|
10 |
Domain Path: /lang/
|
32 |
define('BACKWPUP_PLUGIN_BASEDIR', dirname(plugin_basename(__FILE__)));
|
33 |
define('BACKWPUP_PLUGIN_BASEURL',plugins_url('',__FILE__));
|
34 |
//Set Plugin Version
|
35 |
+
define('BACKWPUP_VERSION', '2.1.8');
|
36 |
//Set Min Wordpress Version
|
37 |
define('BACKWPUP_MIN_WORDPRESS_VERSION', '3.1');
|
38 |
//Set User Capability
|
job/backup_create.php
CHANGED
@@ -58,7 +58,7 @@ function backup_create() {
|
|
58 |
$files[$i][79003]=$filelist[$i]['OUTFILE'];
|
59 |
$files[$i][79004]=$filelist[$i]['MTIME'];
|
60 |
}
|
61 |
-
need_free_memory('
|
62 |
$zipbackupfile = new PclZip($STATIC['JOB']['backupdir'].$STATIC['backupfile']);
|
63 |
if (0==$zipbackupfile->create($files,PCLZIP_CB_POST_ADD,'_pclzipPostAddCallBack')) {
|
64 |
trigger_error(sprintf(__('Zip archive create error: %s','backwpup'),$zipbackupfile->errorInfo(true)),E_USER_ERROR);
|
58 |
$files[$i][79003]=$filelist[$i]['OUTFILE'];
|
59 |
$files[$i][79004]=$filelist[$i]['MTIME'];
|
60 |
}
|
61 |
+
need_free_memory('40M'); //40MB free memory for zip
|
62 |
$zipbackupfile = new PclZip($STATIC['JOB']['backupdir'].$STATIC['backupfile']);
|
63 |
if (0==$zipbackupfile->create($files,PCLZIP_CB_POST_ADD,'_pclzipPostAddCallBack')) {
|
64 |
trigger_error(sprintf(__('Zip archive create error: %s','backwpup'),$zipbackupfile->errorInfo(true)),E_USER_ERROR);
|
job/db_dump.php
CHANGED
@@ -55,7 +55,7 @@ function db_dump() {
|
|
55 |
if (in_array($table, $WORKING['DB_DUMP']['DONETABLE']))
|
56 |
continue;
|
57 |
trigger_error(sprintf(__('Dump database table "%s"','backwpup'),$table),E_USER_NOTICE);
|
58 |
-
need_free_memory(($status[$table]['Data_length']+$status[$table]['Index_length'])*
|
59 |
_db_dump_table($table,$status[$table],$file);
|
60 |
$WORKING['DB_DUMP']['DONETABLE'][]=$table;
|
61 |
$WORKING['STEPDONE']=count($WORKING['DB_DUMP']['DONETABLE']);
|
55 |
if (in_array($table, $WORKING['DB_DUMP']['DONETABLE']))
|
56 |
continue;
|
57 |
trigger_error(sprintf(__('Dump database table "%s"','backwpup'),$table),E_USER_NOTICE);
|
58 |
+
need_free_memory(($status[$table]['Data_length']+$status[$table]['Index_length'])*3); //get more memory if needed
|
59 |
_db_dump_table($table,$status[$table],$file);
|
60 |
$WORKING['DB_DUMP']['DONETABLE'][]=$table;
|
61 |
$WORKING['STEPDONE']=count($WORKING['DB_DUMP']['DONETABLE']);
|
job/dest_gstorage.php
CHANGED
@@ -8,8 +8,7 @@ function dest_gstorage() {
|
|
8 |
require_once(dirname(__FILE__).'/../libs/aws/sdk.class.php');
|
9 |
need_free_memory(26214400*1.1);
|
10 |
try {
|
11 |
-
|
12 |
-
$gstorage = new AmazonS3();
|
13 |
//set up s3 for google
|
14 |
$gstorage->set_hostname('commondatastorage.googleapis.com');
|
15 |
$gstorage->allow_hostname_override(false);
|
@@ -26,7 +25,7 @@ function dest_gstorage() {
|
|
26 |
if ($result["status"]=200 and $result["status"]<300) {
|
27 |
$WORKING['STEPTODO']=1+filesize($STATIC['JOB']['backupdir'].$STATIC['backupfile']);
|
28 |
trigger_error(sprintf(__('Backup transferred to %s','backwpup'),"https://sandbox.google.com/storage/".$STATIC['JOB']['GStorageBucket']."/".$STATIC['JOB']['GStoragedir'].$STATIC['backupfile']),E_USER_NOTICE);
|
29 |
-
$STATIC['JOB']['lastbackupdownloadurl']
|
30 |
$WORKING['STEPSDONE'][]='DEST_GSTORAGE'; //set done
|
31 |
} else {
|
32 |
trigger_error(sprintf(__('Can not transfer backup to GStorage! (%1$d) %2$s','backwpup'),$result["status"],$result["Message"]),E_USER_ERROR);
|
8 |
require_once(dirname(__FILE__).'/../libs/aws/sdk.class.php');
|
9 |
need_free_memory(26214400*1.1);
|
10 |
try {
|
11 |
+
$gstorage = new AmazonS3(array('key'=>$STATIC['JOB']['GStorageAccessKey'],'secret'=>$STATIC['JOB']['GStorageSecret'],'certificate_authority'=>true));
|
|
|
12 |
//set up s3 for google
|
13 |
$gstorage->set_hostname('commondatastorage.googleapis.com');
|
14 |
$gstorage->allow_hostname_override(false);
|
25 |
if ($result["status"]=200 and $result["status"]<300) {
|
26 |
$WORKING['STEPTODO']=1+filesize($STATIC['JOB']['backupdir'].$STATIC['backupfile']);
|
27 |
trigger_error(sprintf(__('Backup transferred to %s','backwpup'),"https://sandbox.google.com/storage/".$STATIC['JOB']['GStorageBucket']."/".$STATIC['JOB']['GStoragedir'].$STATIC['backupfile']),E_USER_NOTICE);
|
28 |
+
$STATIC['JOB']['lastbackupdownloadurl']="https://sandbox.google.com/storage/" . $STATIC['JOB']['GStorageBucket'] . "/" . $STATIC['JOB']['GStoragedir'] . $STATIC['backupfile'];
|
29 |
$WORKING['STEPSDONE'][]='DEST_GSTORAGE'; //set done
|
30 |
} else {
|
31 |
trigger_error(sprintf(__('Can not transfer backup to GStorage! (%1$d) %2$s','backwpup'),$result["status"],$result["Message"]),E_USER_ERROR);
|
job/dest_s3.php
CHANGED
@@ -9,8 +9,7 @@ function dest_s3() {
|
|
9 |
need_free_memory(26214400*1.1);
|
10 |
|
11 |
try {
|
12 |
-
|
13 |
-
$s3 = new AmazonS3();
|
14 |
if ($s3->if_bucket_exists($STATIC['JOB']['awsBucket'])) {
|
15 |
trigger_error(sprintf(__('Connected to S3 Bucket: %s','backwpup'),$STATIC['JOB']['awsBucket']),E_USER_NOTICE);
|
16 |
//Transfer Backup to S3
|
9 |
need_free_memory(26214400*1.1);
|
10 |
|
11 |
try {
|
12 |
+
$s3 = new AmazonS3(array('key'=>$STATIC['JOB']['awsAccessKey'],'secret'=>$STATIC['JOB']['awsSecretKey'],'certificate_authority'=>true));
|
|
|
13 |
if ($s3->if_bucket_exists($STATIC['JOB']['awsBucket'])) {
|
14 |
trigger_error(sprintf(__('Connected to S3 Bucket: %s','backwpup'),$STATIC['JOB']['awsBucket']),E_USER_NOTICE);
|
15 |
//Transfer Backup to S3
|
job/job_run.php
CHANGED
@@ -48,7 +48,7 @@ if (empty($STATIC) or !file_exists($STATIC['LOGFILE'])) {
|
|
48 |
die('No logfile found!');
|
49 |
}
|
50 |
//load translation
|
51 |
-
if (
|
52 |
require($STATIC['WP']['ABSPATH'].$STATIC['WP']['WPINC'].'/pomo/mo.php');
|
53 |
$TRANSLATE = new MO();
|
54 |
$TRANSLATE->import_from_file(dirname(__FILE__).'/../lang/backwpup-'.$STATIC['WP']['WPLANG'].'.mo');
|
@@ -99,7 +99,7 @@ mysql_update();
|
|
99 |
foreach($WORKING['STEPS'] as $step) {
|
100 |
$stepfile=strtolower($step).'.php';
|
101 |
if ($step!='JOB_END') {
|
102 |
-
if (
|
103 |
require_once(BACKWPUP_JOBRUN_FOLDER.$stepfile);
|
104 |
} else {
|
105 |
trigger_error(sprintf(__('Can not find job step file: %s','backwpup'),$stepfile),E_USER_ERROR);
|
48 |
die('No logfile found!');
|
49 |
}
|
50 |
//load translation
|
51 |
+
if (file_exists(dirname(__FILE__).'/../lang/backwpup-'.$STATIC['WP']['WPLANG'].'.mo')) {
|
52 |
require($STATIC['WP']['ABSPATH'].$STATIC['WP']['WPINC'].'/pomo/mo.php');
|
53 |
$TRANSLATE = new MO();
|
54 |
$TRANSLATE->import_from_file(dirname(__FILE__).'/../lang/backwpup-'.$STATIC['WP']['WPLANG'].'.mo');
|
99 |
foreach($WORKING['STEPS'] as $step) {
|
100 |
$stepfile=strtolower($step).'.php';
|
101 |
if ($step!='JOB_END') {
|
102 |
+
if (file_exists(BACKWPUP_JOBRUN_FOLDER.$stepfile)) {
|
103 |
require_once(BACKWPUP_JOBRUN_FOLDER.$stepfile);
|
104 |
} else {
|
105 |
trigger_error(sprintf(__('Can not find job step file: %s','backwpup'),$stepfile),E_USER_ERROR);
|
job/show_working.php
CHANGED
@@ -63,7 +63,7 @@ function backwpup_read_logheader($logfile) {
|
|
63 |
|
64 |
$_POST['logfile']=trim(str_replace(array(':','@','../','//','\\'),'',$_POST['logfile']));
|
65 |
$_POST['BackWPupJobTemp']=trim(str_replace(array(':','@','../','//','\\'),'',$_POST['BackWPupJobTemp']));
|
66 |
-
if (
|
67 |
$_POST['logfile']=$_POST['logfile'].'.gz';
|
68 |
|
69 |
// check given file is a backwpup logfile
|
@@ -71,8 +71,8 @@ if (substr(trim($_POST['logfile']),-3)!='.gz' and substr($_POST['logfile'],-8)!=
|
|
71 |
die();
|
72 |
|
73 |
$log='';
|
74 |
-
if (
|
75 |
-
if (
|
76 |
if ($infile=backwpup_get_working_file()) {
|
77 |
$warnings=$infile['WORKING']['WARNING'];
|
78 |
$errors=$infile['WORKING']['ERROR'];
|
63 |
|
64 |
$_POST['logfile']=trim(str_replace(array(':','@','../','//','\\'),'',$_POST['logfile']));
|
65 |
$_POST['BackWPupJobTemp']=trim(str_replace(array(':','@','../','//','\\'),'',$_POST['BackWPupJobTemp']));
|
66 |
+
if (file_exists($_POST['logfile'].'.gz'))
|
67 |
$_POST['logfile']=$_POST['logfile'].'.gz';
|
68 |
|
69 |
// check given file is a backwpup logfile
|
71 |
die();
|
72 |
|
73 |
$log='';
|
74 |
+
if (file_exists($_POST['logfile'])) {
|
75 |
+
if (file_exists($_POST['BackWPupJobTemp'].'.running')) {
|
76 |
if ($infile=backwpup_get_working_file()) {
|
77 |
$warnings=$infile['WORKING']['WARNING'];
|
78 |
$errors=$infile['WORKING']['ERROR'];
|
job/wp_export_generate.php
CHANGED
@@ -7,12 +7,12 @@ define('DONOTCACHCEOBJECT', true);
|
|
7 |
define('W3TC_IN_MINIFY',false); //W3TC will not loaded
|
8 |
|
9 |
$_POST['BackWPupJobTemp']=str_replace(array(':','@','../','//','\\'),'',$_POST['BackWPupJobTemp']);
|
10 |
-
if (
|
11 |
$runningfile=file_get_contents(trim($_POST['BackWPupJobTemp']).'.running');
|
12 |
$infile=array();
|
13 |
if (!empty($runningfile))
|
14 |
$infile=unserialize(trim($runningfile));
|
15 |
-
if (
|
16 |
require_once(trim($infile['ABSPATH']).'wp-load.php'); /** Setup WordPress environment */
|
17 |
require_once(trim($infile['ABSPATH']).'wp-admin/includes/export.php');
|
18 |
export_wp();
|
7 |
define('W3TC_IN_MINIFY',false); //W3TC will not loaded
|
8 |
|
9 |
$_POST['BackWPupJobTemp']=str_replace(array(':','@','../','//','\\'),'',$_POST['BackWPupJobTemp']);
|
10 |
+
if (file_exists(trim($_POST['BackWPupJobTemp']).'.running'))
|
11 |
$runningfile=file_get_contents(trim($_POST['BackWPupJobTemp']).'.running');
|
12 |
$infile=array();
|
13 |
if (!empty($runningfile))
|
14 |
$infile=unserialize(trim($runningfile));
|
15 |
+
if (file_exists(trim($infile['ABSPATH']).'wp-load.php') and $_POST['nonce']==$infile['WORKING']['NONCE'] and $_POST['type']=='getxmlexport') {
|
16 |
require_once(trim($infile['ABSPATH']).'wp-load.php'); /** Setup WordPress environment */
|
17 |
require_once(trim($infile['ABSPATH']).'wp-admin/includes/export.php');
|
18 |
export_wp();
|
libs/Microsoft/Console/Command.php
ADDED
@@ -0,0 +1,427 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_Console
|
30 |
+
* @version $Id: Exception.php 55733 2011-01-03 09:17:16Z unknown $
|
31 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
32 |
+
* @license http://phpazure.codeplex.com/license
|
33 |
+
*/
|
34 |
+
|
35 |
+
/**
|
36 |
+
* @see Microsoft_AutoLoader
|
37 |
+
*/
|
38 |
+
require_once dirname(__FILE__) . '/../AutoLoader.php';
|
39 |
+
|
40 |
+
/**
|
41 |
+
* @category Microsoft
|
42 |
+
* @package Microsoft_Console
|
43 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
44 |
+
* @license http://phpazure.codeplex.com/license
|
45 |
+
*/
|
46 |
+
class Microsoft_Console_Command
|
47 |
+
{
|
48 |
+
/**
|
49 |
+
* The handler.
|
50 |
+
*
|
51 |
+
* @var array
|
52 |
+
*/
|
53 |
+
protected $_handler;
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Gets the handler.
|
57 |
+
*
|
58 |
+
* @return array
|
59 |
+
*/
|
60 |
+
public function getHandler()
|
61 |
+
{
|
62 |
+
return $this->_handler;
|
63 |
+
}
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Sets the handler.
|
67 |
+
*
|
68 |
+
* @param array $handler
|
69 |
+
* @return Microsoft_Console_Command
|
70 |
+
*/
|
71 |
+
public function setHandler($handler)
|
72 |
+
{
|
73 |
+
$this->_handler = $handler;
|
74 |
+
return $this;
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Replaces PHP's error handler
|
79 |
+
*
|
80 |
+
* @param mixed $errno
|
81 |
+
* @param mixed $errstr
|
82 |
+
* @param mixed $errfile
|
83 |
+
* @param mixed $errline
|
84 |
+
*/
|
85 |
+
public static function phpstderr($errno, $errstr, $errfile, $errline)
|
86 |
+
{
|
87 |
+
self::stderr($errno . ': Error in ' . $errfile . ':' . $errline . ' - ' . $errstr);
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Replaces PHP's exception handler
|
92 |
+
*
|
93 |
+
* @param Exception $exception
|
94 |
+
*/
|
95 |
+
public static function phpstdex($exception)
|
96 |
+
{
|
97 |
+
self::stderr('Error: ' . $exception->getMessage());
|
98 |
+
}
|
99 |
+
|
100 |
+
/**
|
101 |
+
* Writes output to STDERR, followed by a newline (optional)
|
102 |
+
*
|
103 |
+
* @param string $errorMessage
|
104 |
+
* @param string $newLine
|
105 |
+
*/
|
106 |
+
public static function stderr($errorMessage, $newLine = true)
|
107 |
+
{
|
108 |
+
if (error_reporting() === 0) {
|
109 |
+
return;
|
110 |
+
}
|
111 |
+
file_put_contents('php://stderr', $errorMessage . ($newLine ? "\r\n" : ''));
|
112 |
+
}
|
113 |
+
|
114 |
+
/**
|
115 |
+
* Bootstrap the shell command.
|
116 |
+
*
|
117 |
+
* @param array $argv PHP argument values.
|
118 |
+
*/
|
119 |
+
public static function bootstrap($argv)
|
120 |
+
{
|
121 |
+
// Abort bootstrapping depending on the MICROSOFT_CONSOLE_COMMAND_HOST constant.
|
122 |
+
if (defined('MICROSOFT_CONSOLE_COMMAND_HOST') && strtolower(MICROSOFT_CONSOLE_COMMAND_HOST) != 'console') {
|
123 |
+
return;
|
124 |
+
}
|
125 |
+
|
126 |
+
// Replace error handler
|
127 |
+
set_error_handler(array('Microsoft_Console_Command', 'phpstderr'));
|
128 |
+
set_exception_handler(array('Microsoft_Console_Command', 'phpstdex'));
|
129 |
+
|
130 |
+
// Build the application model
|
131 |
+
$model = self::_buildModel();
|
132 |
+
|
133 |
+
// Find a class that corresponds to the $argv[0] script name
|
134 |
+
$requiredHandlerName = str_replace('.bat', '', str_replace('.sh', '', str_replace('.php', '', strtolower(basename($argv[0])))));
|
135 |
+
$handler = null;
|
136 |
+
foreach ($model as $possibleHandler) {
|
137 |
+
if ($possibleHandler->handler == strtolower($requiredHandlerName)) {
|
138 |
+
$handler = $possibleHandler;
|
139 |
+
break;
|
140 |
+
}
|
141 |
+
}
|
142 |
+
if (is_null($handler)) {
|
143 |
+
self::stderr("No class found that implements handler '" . $requiredHandlerName . "'. Create a class that is named '" . $requiredHandlerName . "' and extends Microsoft_Console_Command or is decorated with a docblock comment '@command-handler " . $requiredHandlerName . "'. Make sure it is loaded either through an autoloader or explicitly using require_once().");
|
144 |
+
die();
|
145 |
+
}
|
146 |
+
|
147 |
+
// Find a method that matches the command name
|
148 |
+
$command = null;
|
149 |
+
foreach ($handler->commands as $possibleCommand) {
|
150 |
+
if (in_array(strtolower(isset($argv[1]) ? $argv[1] : '<default>'), $possibleCommand->aliases)) {
|
151 |
+
$command = $possibleCommand;
|
152 |
+
break;
|
153 |
+
}
|
154 |
+
}
|
155 |
+
if (is_null($command)) {
|
156 |
+
$commandName = (isset($argv[1]) ? $argv[1] : '<default>');
|
157 |
+
self::stderr("No method found that implements command " . $commandName . ". Create a method in class '" . $handler->class . "' that is named '" . strtolower($commandName) . "Command' or is decorated with a docblock comment '@command-name " . $commandName . "'.");
|
158 |
+
die();
|
159 |
+
}
|
160 |
+
|
161 |
+
// Parse parameter values
|
162 |
+
$parameterValues = array();
|
163 |
+
$missingParameterValues = array();
|
164 |
+
$parameterInputs = array_splice($argv, 2);
|
165 |
+
foreach ($command->parameters as $parameter) {
|
166 |
+
// Default value: null
|
167 |
+
$value = null;
|
168 |
+
|
169 |
+
// Consult value providers for value. First one wins.
|
170 |
+
foreach ($parameter->valueproviders as $valueProviderName) {
|
171 |
+
if (!class_exists($valueProviderName)) {
|
172 |
+
$valueProviderName = 'Microsoft_Console_Command_ParameterSource_' . $valueProviderName;
|
173 |
+
}
|
174 |
+
$valueProvider = new $valueProviderName();
|
175 |
+
|
176 |
+
$value = $valueProvider->getValueForParameter($parameter, $parameterInputs);
|
177 |
+
if (!is_null($value)) {
|
178 |
+
break;
|
179 |
+
}
|
180 |
+
}
|
181 |
+
if (is_null($value) && $parameter->required) {
|
182 |
+
$missingParameterValues[] = $parameter->aliases[0];
|
183 |
+
} else if (is_null($value)) {
|
184 |
+
$value = $parameter->defaultvalue;
|
185 |
+
}
|
186 |
+
|
187 |
+
// Set value
|
188 |
+
$parameterValues[] = $value;
|
189 |
+
$argvValues[$parameter->aliases[0]] = $value;
|
190 |
+
}
|
191 |
+
|
192 |
+
// Mising parameters?
|
193 |
+
if (count($missingParameterValues) > 0) {
|
194 |
+
self::stderr("Some parameters are missing:\r\n" . implode("\r\n", $missingParameterValues));
|
195 |
+
die();
|
196 |
+
}
|
197 |
+
|
198 |
+
// Supply argv in a nice way
|
199 |
+
$parameterValues['argv'] = $parameterInputs;
|
200 |
+
|
201 |
+
// Run the command
|
202 |
+
$className = $handler->class;
|
203 |
+
$classInstance = new $className();
|
204 |
+
$classInstance->setHandler($handler);
|
205 |
+
call_user_func_array(array($classInstance, $command->method), $parameterValues);
|
206 |
+
|
207 |
+
// Restore error handler
|
208 |
+
restore_exception_handler();
|
209 |
+
restore_error_handler();
|
210 |
+
}
|
211 |
+
|
212 |
+
/**
|
213 |
+
* Builds the handler model.
|
214 |
+
*
|
215 |
+
* @return array
|
216 |
+
*/
|
217 |
+
protected static function _buildModel()
|
218 |
+
{
|
219 |
+
$model = array();
|
220 |
+
|
221 |
+
$classes = get_declared_classes();
|
222 |
+
foreach ($classes as $class) {
|
223 |
+
$type = new ReflectionClass($class);
|
224 |
+
|
225 |
+
$handlers = self::_findValueForDocComment('@command-handler', $type->getDocComment());
|
226 |
+
if (count($handlers) == 0 && $type->isSubclassOf('Microsoft_Console_Command')) {
|
227 |
+
// Fallback: if the class extends Microsoft_Console_Command, register it as
|
228 |
+
// a command handler.
|
229 |
+
$handlers[] = $class;
|
230 |
+
}
|
231 |
+
$handlerDescriptions = self::_findValueForDocComment('@command-handler-description', $type->getDocComment());
|
232 |
+
$handlerHeaders = self::_findValueForDocComment('@command-handler-header', $type->getDocComment());
|
233 |
+
$handlerFooters = self::_findValueForDocComment('@command-handler-footer', $type->getDocComment());
|
234 |
+
|
235 |
+
for ($hi = 0; $hi < count($handlers); $hi++) {
|
236 |
+
$handler = $handlers[$hi];
|
237 |
+
$handlerDescription = isset($handlerDescriptions[$hi]) ? $handlerDescriptions[$hi] : isset($handlerDescriptions[0]) ? $handlerDescriptions[0] : '';
|
238 |
+
$handlerDescription = str_replace('\r\n', "\r\n", $handlerDescription);
|
239 |
+
$handlerDescription = str_replace('\n', "\n", $handlerDescription);
|
240 |
+
|
241 |
+
$handlerModel = (object)array(
|
242 |
+
'handler' => strtolower($handler),
|
243 |
+
'description' => $handlerDescription,
|
244 |
+
'headers' => $handlerHeaders,
|
245 |
+
'footers' => $handlerFooters,
|
246 |
+
'class' => $class,
|
247 |
+
'commands' => array()
|
248 |
+
);
|
249 |
+
|
250 |
+
$methods = $type->getMethods();
|
251 |
+
foreach ($methods as $method) {
|
252 |
+
$commands = self::_findValueForDocComment('@command-name', $method->getDocComment());
|
253 |
+
if (substr($method->getName(), -7) == 'Command' && !in_array(substr($method->getName(), 0, -7), $commands)) {
|
254 |
+
// Fallback: if the method is named <commandname>Command,
|
255 |
+
// register it as a command.
|
256 |
+
$commands[] = substr($method->getName(), 0, -7);
|
257 |
+
}
|
258 |
+
for ($x = 0; $x < count($commands); $x++) {
|
259 |
+
$commands[$x] = strtolower($commands[$x]);
|
260 |
+
}
|
261 |
+
$commands = array_unique($commands);
|
262 |
+
$commandDescriptions = self::_findValueForDocComment('@command-description', $method->getDocComment());
|
263 |
+
$commandExamples = self::_findValueForDocComment('@command-example', $method->getDocComment());
|
264 |
+
|
265 |
+
if (count($commands) > 0) {
|
266 |
+
$command = $commands[0];
|
267 |
+
$commandDescription = isset($commandDescriptions[0]) ? $commandDescriptions[0] : '';
|
268 |
+
|
269 |
+
$commandModel = (object)array(
|
270 |
+
'command' => $command,
|
271 |
+
'aliases' => $commands,
|
272 |
+
'description' => $commandDescription,
|
273 |
+
'examples' => $commandExamples,
|
274 |
+
'class' => $class,
|
275 |
+
'method' => $method->getName(),
|
276 |
+
'parameters' => array()
|
277 |
+
);
|
278 |
+
|
279 |
+
$parameters = $method->getParameters();
|
280 |
+
$parametersFor = self::_findValueForDocComment('@command-parameter-for', $method->getDocComment());
|
281 |
+
for ($pi = 0; $pi < count($parameters); $pi++) {
|
282 |
+
// Initialize
|
283 |
+
$parameter = $parameters[$pi];
|
284 |
+
$parameterFor = null;
|
285 |
+
$parameterForDefaultValue = null;
|
286 |
+
|
287 |
+
// Is it a "catch-all" parameter?
|
288 |
+
if ($parameter->getName() == 'argv') {
|
289 |
+
continue;
|
290 |
+
}
|
291 |
+
|
292 |
+
// Find the $parametersFor with the same name defined
|
293 |
+
foreach ($parametersFor as $possibleParameterFor) {
|
294 |
+
$possibleParameterFor = explode(' ', $possibleParameterFor, 4);
|
295 |
+
if ($possibleParameterFor[0] == '$' . $parameter->getName()) {
|
296 |
+
$parameterFor = $possibleParameterFor;
|
297 |
+
break;
|
298 |
+
}
|
299 |
+
}
|
300 |
+
if (is_null($parameterFor)) {
|
301 |
+
die('@command-parameter-for missing for parameter $' . $parameter->getName());
|
302 |
+
}
|
303 |
+
|
304 |
+
if (is_null($parameterForDefaultValue) && $parameter->isOptional()) {
|
305 |
+
$parameterForDefaultValue = $parameter->getDefaultValue();
|
306 |
+
}
|
307 |
+
|
308 |
+
$parameterModel = (object)array(
|
309 |
+
'name' => '$' . $parameter->getName(),
|
310 |
+
'defaultvalue' => $parameterForDefaultValue,
|
311 |
+
'valueproviders' => explode('|', $parameterFor[1]),
|
312 |
+
'aliases' => explode('|', $parameterFor[2]),
|
313 |
+
'description' => (isset($parameterFor[3]) ? $parameterFor[3] : ''),
|
314 |
+
'required' => (isset($parameterFor[3]) ? strpos(strtolower($parameterFor[3]), 'required') !== false && strpos(strtolower($parameterFor[3]), 'required if') === false : false),
|
315 |
+
);
|
316 |
+
|
317 |
+
// Add to model
|
318 |
+
$commandModel->parameters[] = $parameterModel;
|
319 |
+
}
|
320 |
+
|
321 |
+
// Add to model
|
322 |
+
$handlerModel->commands[] = $commandModel;
|
323 |
+
}
|
324 |
+
}
|
325 |
+
|
326 |
+
// Add to model
|
327 |
+
$model[] = $handlerModel;
|
328 |
+
}
|
329 |
+
}
|
330 |
+
|
331 |
+
return $model;
|
332 |
+
}
|
333 |
+
|
334 |
+
/**
|
335 |
+
* Finds the value for a specific docComment.
|
336 |
+
*
|
337 |
+
* @param string $docCommentName Comment name
|
338 |
+
* @param unknown_type $docComment Comment object
|
339 |
+
* @return array
|
340 |
+
*/
|
341 |
+
protected static function _findValueForDocComment($docCommentName, $docComment)
|
342 |
+
{
|
343 |
+
$returnValue = array();
|
344 |
+
|
345 |
+
$commentLines = explode("\n", $docComment);
|
346 |
+
foreach ($commentLines as $commentLine) {
|
347 |
+
if (strpos($commentLine, $docCommentName . ' ') !== false) {
|
348 |
+
$returnValue[] = trim(substr($commentLine, strpos($commentLine, $docCommentName) + strlen($docCommentName) + 1));
|
349 |
+
}
|
350 |
+
}
|
351 |
+
|
352 |
+
return $returnValue;
|
353 |
+
}
|
354 |
+
|
355 |
+
/**
|
356 |
+
* Display information on an object
|
357 |
+
*
|
358 |
+
* @param object $object Object
|
359 |
+
* @param array $propertiesToDump Property names to display
|
360 |
+
*/
|
361 |
+
protected function _displayObjectInformation($object, $propertiesToDump = array())
|
362 |
+
{
|
363 |
+
foreach ($propertiesToDump as $property) {
|
364 |
+
printf('%-16s: %s' . "\r\n", $property, $object->$property);
|
365 |
+
}
|
366 |
+
printf("\r\n");
|
367 |
+
}
|
368 |
+
|
369 |
+
/**
|
370 |
+
* Displays the help information.
|
371 |
+
*
|
372 |
+
* @command-name <default>
|
373 |
+
* @command-name -h
|
374 |
+
* @command-name -help
|
375 |
+
* @command-description Displays the current help information.
|
376 |
+
*/
|
377 |
+
public function helpCommand() {
|
378 |
+
$handler = $this->getHandler();
|
379 |
+
$newline = "\r\n";
|
380 |
+
|
381 |
+
if (count($handler->headers) > 0) {
|
382 |
+
foreach ($handler->headers as $header) {
|
383 |
+
printf('%s%s', $header, $newline);
|
384 |
+
}
|
385 |
+
printf($newline);
|
386 |
+
}
|
387 |
+
printf('%s%s', $handler->description, $newline);
|
388 |
+
printf($newline);
|
389 |
+
printf('Available commands:%s', $newline);
|
390 |
+
foreach ($handler->commands as $command) {
|
391 |
+
$description = str_split($command->description, 50);
|
392 |
+
printf(' %-25s %s%s', implode(', ', $command->aliases), $description[0], $newline);
|
393 |
+
for ($di = 1; $di < count($description); $di++) {
|
394 |
+
printf(' %-25s %s%s', '', $description[$di], $newline);
|
395 |
+
}
|
396 |
+
printf($newline);
|
397 |
+
|
398 |
+
if (count($command->parameters) > 0) {
|
399 |
+
foreach ($command->parameters as $parameter) {
|
400 |
+
$description = str_split($parameter->description, 50);
|
401 |
+
printf(' %-23s %s%s', implode(', ', $parameter->aliases), $description[0], $newline);
|
402 |
+
for ($di = 1; $di < count($description); $di++) {
|
403 |
+
printf(' %-23s %s%s', '', $description[$di], $newline);
|
404 |
+
}
|
405 |
+
printf($newline);
|
406 |
+
}
|
407 |
+
}
|
408 |
+
printf($newline);
|
409 |
+
|
410 |
+
if (count($command->examples) > 0) {
|
411 |
+
printf(' Example usage:%s', $newline);
|
412 |
+
foreach ($command->examples as $example) {
|
413 |
+
printf(' %s%s', $example, $newline);
|
414 |
+
}
|
415 |
+
printf($newline);
|
416 |
+
}
|
417 |
+
}
|
418 |
+
|
419 |
+
if (count($handler->footers) > 0) {
|
420 |
+
printf($newline);
|
421 |
+
foreach ($handler->footers as $footer) {
|
422 |
+
printf('%s%s', $footer, $newline);
|
423 |
+
}
|
424 |
+
printf($newline);
|
425 |
+
}
|
426 |
+
}
|
427 |
+
}
|
libs/Microsoft/Console/Command/ParameterSource/Argv.php
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_Console
|
30 |
+
* @subpackage Exception
|
31 |
+
* @version $Id: Exception.php 55733 2011-01-03 09:17:16Z unknown $
|
32 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
33 |
+
* @license http://phpazure.codeplex.com/license
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @see Microsoft_AutoLoader
|
38 |
+
*/
|
39 |
+
require_once dirname(__FILE__) . '/../../../AutoLoader.php';
|
40 |
+
|
41 |
+
/**
|
42 |
+
* @category Microsoft
|
43 |
+
* @package Microsoft_Console
|
44 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
45 |
+
* @license http://phpazure.codeplex.com/license
|
46 |
+
*/
|
47 |
+
class Microsoft_Console_Command_ParameterSource_Argv
|
48 |
+
implements Microsoft_Console_Command_ParameterSource_ParameterSourceInterface
|
49 |
+
{
|
50 |
+
/**
|
51 |
+
* Get value for a named parameter.
|
52 |
+
*
|
53 |
+
* @param mixed $parameter Parameter to get a value for
|
54 |
+
* @param array $argv Argument values passed to the script when run in console.
|
55 |
+
* @return mixed
|
56 |
+
*/
|
57 |
+
public function getValueForParameter($parameter, $argv = array())
|
58 |
+
{
|
59 |
+
// Default value
|
60 |
+
$parameterValue = null;
|
61 |
+
|
62 |
+
// Loop parameter inputs
|
63 |
+
foreach ($argv as $parameterInput) {
|
64 |
+
$parameterInput = explode('=', $parameterInput, 2);
|
65 |
+
|
66 |
+
if (in_array($parameterInput[0], $parameter->aliases)) {
|
67 |
+
$parameterValue = isset($parameterInput[1]) ? $parameterInput[1] : true;
|
68 |
+
break;
|
69 |
+
}
|
70 |
+
}
|
71 |
+
if (strtolower($parameterValue) == 'true') {
|
72 |
+
$parameterValue = true;
|
73 |
+
} else if (strtolower($parameterValue) == 'false') {
|
74 |
+
$parameterValue = false;
|
75 |
+
}
|
76 |
+
|
77 |
+
// Done!
|
78 |
+
return $parameterValue;
|
79 |
+
}
|
80 |
+
}
|
libs/Microsoft/Console/Command/ParameterSource/ConfigFile.php
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_Console
|
30 |
+
* @subpackage Exception
|
31 |
+
* @version $Id: Exception.php 55733 2011-01-03 09:17:16Z unknown $
|
32 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
33 |
+
* @license http://phpazure.codeplex.com/license
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @see Microsoft_AutoLoader
|
38 |
+
*/
|
39 |
+
require_once dirname(__FILE__) . '/../../../AutoLoader.php';
|
40 |
+
|
41 |
+
/**
|
42 |
+
* @category Microsoft
|
43 |
+
* @package Microsoft_Console
|
44 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
45 |
+
* @license http://phpazure.codeplex.com/license
|
46 |
+
*/
|
47 |
+
class Microsoft_Console_Command_ParameterSource_ConfigFile
|
48 |
+
implements Microsoft_Console_Command_ParameterSource_ParameterSourceInterface
|
49 |
+
{
|
50 |
+
/**
|
51 |
+
* Get value for a named parameter.
|
52 |
+
*
|
53 |
+
* @param mixed $parameter Parameter to get a value for
|
54 |
+
* @param array $argv Argument values passed to the script when run in console.
|
55 |
+
* @return mixed
|
56 |
+
*/
|
57 |
+
public function getValueForParameter($parameter, $argv = array())
|
58 |
+
{
|
59 |
+
// Configuration file path
|
60 |
+
$configurationFilePath = null;
|
61 |
+
|
62 |
+
// Check if a path to a configuration file is specified
|
63 |
+
foreach ($argv as $parameterInput) {
|
64 |
+
$parameterInput = explode('=', $parameterInput, 2);
|
65 |
+
|
66 |
+
if (strtolower($parameterInput[0]) == '--configfile' || strtolower($parameterInput[0]) == '-f') {
|
67 |
+
if (!isset($parameterInput[1])) {
|
68 |
+
throw new Microsoft_Console_Exception("No path to a configuration file is given. Specify the path using the --ConfigFile or -F switch.");
|
69 |
+
}
|
70 |
+
$configurationFilePath = $parameterInput[1];
|
71 |
+
break;
|
72 |
+
}
|
73 |
+
}
|
74 |
+
|
75 |
+
// Value given?
|
76 |
+
if (is_null($configurationFilePath)) {
|
77 |
+
return null;
|
78 |
+
}
|
79 |
+
if (!file_exists($configurationFilePath)) {
|
80 |
+
throw new Microsoft_Console_Exception("Invalid configuration file given. Specify the correct path using the --ConfigFile or -F switch.");
|
81 |
+
}
|
82 |
+
|
83 |
+
// Parse values
|
84 |
+
$iniValues = parse_ini_file($configurationFilePath);
|
85 |
+
|
86 |
+
// Default value
|
87 |
+
$parameterValue = null;
|
88 |
+
|
89 |
+
// Loop aliases
|
90 |
+
foreach ($parameter->aliases as $alias) {
|
91 |
+
if (array_key_exists($alias, $iniValues)) {
|
92 |
+
$parameterValue = $iniValues[$alias]; break;
|
93 |
+
} else if (array_key_exists(strtolower($alias), $iniValues)) {
|
94 |
+
$parameterValue = $iniValues[strtolower($alias)]; break;
|
95 |
+
} else if (array_key_exists(str_replace('-', '', $alias), $iniValues)) {
|
96 |
+
$parameterValue = $iniValues[str_replace('-', '', $alias)]; break;
|
97 |
+
} else if (array_key_exists(strtolower(str_replace('-', '', $alias)), $iniValues)) {
|
98 |
+
$parameterValue = $iniValues[strtolower(str_replace('-', '', $alias))]; break;
|
99 |
+
}
|
100 |
+
}
|
101 |
+
|
102 |
+
if (strtolower($parameterValue) == 'true') {
|
103 |
+
$parameterValue = true;
|
104 |
+
} else if (strtolower($parameterValue) == 'false') {
|
105 |
+
$parameterValue = false;
|
106 |
+
}
|
107 |
+
|
108 |
+
// Done!
|
109 |
+
return $parameterValue;
|
110 |
+
}
|
111 |
+
}
|
libs/Microsoft/Console/Command/ParameterSource/Env.php
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_Console
|
30 |
+
* @subpackage Exception
|
31 |
+
* @version $Id: Exception.php 55733 2011-01-03 09:17:16Z unknown $
|
32 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
33 |
+
* @license http://phpazure.codeplex.com/license
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @see Microsoft_AutoLoader
|
38 |
+
*/
|
39 |
+
require_once dirname(__FILE__) . '/../../../AutoLoader.php';
|
40 |
+
|
41 |
+
/**
|
42 |
+
* @category Microsoft
|
43 |
+
* @package Microsoft_Console
|
44 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
45 |
+
* @license http://phpazure.codeplex.com/license
|
46 |
+
*/
|
47 |
+
class Microsoft_Console_Command_ParameterSource_Env
|
48 |
+
implements Microsoft_Console_Command_ParameterSource_ParameterSourceInterface
|
49 |
+
{
|
50 |
+
/**
|
51 |
+
* Get value for a named parameter.
|
52 |
+
*
|
53 |
+
* @param mixed $parameter Parameter to get a value for
|
54 |
+
* @param array $argv Argument values passed to the script when run in console.
|
55 |
+
* @return mixed
|
56 |
+
*/
|
57 |
+
public function getValueForParameter($parameter, $argv = array())
|
58 |
+
{
|
59 |
+
// Default value
|
60 |
+
$parameterValue = null;
|
61 |
+
|
62 |
+
// Fetch value for parameter
|
63 |
+
foreach ($parameter->aliases as $alias) {
|
64 |
+
while (strpos($alias, '-') !== false) {
|
65 |
+
$alias = substr($alias, 1);
|
66 |
+
}
|
67 |
+
$value = getenv($alias);
|
68 |
+
|
69 |
+
if (!is_null($value) && $value !== false) {
|
70 |
+
$parameterValue = $value;
|
71 |
+
break;
|
72 |
+
}
|
73 |
+
}
|
74 |
+
|
75 |
+
if (strtolower($parameterValue) == 'true') {
|
76 |
+
$parameterValue = true;
|
77 |
+
} else if (strtolower($parameterValue) == 'false') {
|
78 |
+
$parameterValue = false;
|
79 |
+
}
|
80 |
+
|
81 |
+
// Done!
|
82 |
+
return $parameterValue;
|
83 |
+
}
|
84 |
+
}
|
libs/Microsoft/Console/Command/ParameterSource/ParameterSourceInterface.php
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_Console
|
30 |
+
* @subpackage Exception
|
31 |
+
* @version $Id: Exception.php 55733 2011-01-03 09:17:16Z unknown $
|
32 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
33 |
+
* @license http://phpazure.codeplex.com/license
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @see Microsoft_AutoLoader
|
38 |
+
*/
|
39 |
+
require_once dirname(__FILE__) . '/../../../AutoLoader.php';
|
40 |
+
|
41 |
+
/**
|
42 |
+
* @category Microsoft
|
43 |
+
* @package Microsoft_Console
|
44 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
45 |
+
* @license http://phpazure.codeplex.com/license
|
46 |
+
*/
|
47 |
+
interface Microsoft_Console_Command_ParameterSource_ParameterSourceInterface
|
48 |
+
{
|
49 |
+
/**
|
50 |
+
* Get value for a named parameter.
|
51 |
+
*
|
52 |
+
* @param mixed $parameter Parameter to get a value for
|
53 |
+
* @param array $argv Argument values passed to the script when run in console.
|
54 |
+
* @return mixed
|
55 |
+
*/
|
56 |
+
public function getValueForParameter($parameter, $argv = array());
|
57 |
+
}
|
libs/Microsoft/Console/Command/ParameterSource/Prompt.php
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_Console
|
30 |
+
* @subpackage Exception
|
31 |
+
* @version $Id: Exception.php 55733 2011-01-03 09:17:16Z unknown $
|
32 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
33 |
+
* @license http://phpazure.codeplex.com/license
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @see Microsoft_AutoLoader
|
38 |
+
*/
|
39 |
+
require_once dirname(__FILE__) . '/../../../AutoLoader.php';
|
40 |
+
|
41 |
+
/**
|
42 |
+
* @category Microsoft
|
43 |
+
* @package Microsoft_Console
|
44 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
45 |
+
* @license http://phpazure.codeplex.com/license
|
46 |
+
*/
|
47 |
+
class Microsoft_Console_Command_ParameterSource_Prompt
|
48 |
+
implements Microsoft_Console_Command_ParameterSource_ParameterSourceInterface
|
49 |
+
{
|
50 |
+
/**
|
51 |
+
* Get value for a named parameter.
|
52 |
+
*
|
53 |
+
* @param mixed $parameter Parameter to get a value for
|
54 |
+
* @param array $argv Argument values passed to the script when run in console.
|
55 |
+
* @return mixed
|
56 |
+
*/
|
57 |
+
public function getValueForParameter($parameter, $argv = array())
|
58 |
+
{
|
59 |
+
// Default value
|
60 |
+
$parameterValue = null;
|
61 |
+
|
62 |
+
// Prompt the user
|
63 |
+
fwrite(STDOUT, "Supply a value for " . $parameter->aliases[0] . ": ");
|
64 |
+
/*if ($parameter->description != '' && !is_null($parameter->description)) {
|
65 |
+
fwrite(STDOUT, $parameter->description . ".\r\n");
|
66 |
+
}*/
|
67 |
+
|
68 |
+
while (is_null($parameterValue) || $parameterValue == '') {
|
69 |
+
$parameterValue = trim(fgets(STDIN));
|
70 |
+
}
|
71 |
+
|
72 |
+
// Done!
|
73 |
+
return $parameterValue;
|
74 |
+
}
|
75 |
+
}
|
libs/Microsoft/Console/Command/ParameterSource/StdIn.php
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_Console
|
30 |
+
* @subpackage Exception
|
31 |
+
* @version $Id: Exception.php 55733 2011-01-03 09:17:16Z unknown $
|
32 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
33 |
+
* @license http://phpazure.codeplex.com/license
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @see Microsoft_AutoLoader
|
38 |
+
*/
|
39 |
+
require_once dirname(__FILE__) . '/../../../AutoLoader.php';
|
40 |
+
|
41 |
+
/**
|
42 |
+
* @category Microsoft
|
43 |
+
* @package Microsoft_Console
|
44 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
45 |
+
* @license http://phpazure.codeplex.com/license
|
46 |
+
*/
|
47 |
+
class Microsoft_Console_Command_ParameterSource_StdIn
|
48 |
+
implements Microsoft_Console_Command_ParameterSource_ParameterSourceInterface
|
49 |
+
{
|
50 |
+
/**
|
51 |
+
* Get value for a named parameter.
|
52 |
+
*
|
53 |
+
* @param mixed $parameter Parameter to get a value for
|
54 |
+
* @param array $argv Argument values passed to the script when run in console.
|
55 |
+
* @return mixed
|
56 |
+
*/
|
57 |
+
public function getValueForParameter($parameter, $argv = array())
|
58 |
+
{
|
59 |
+
// Default value
|
60 |
+
$parameterValue = null;
|
61 |
+
|
62 |
+
// Check STDIN for data
|
63 |
+
if (ftell(STDIN) !== false) {
|
64 |
+
// Read from STDIN
|
65 |
+
$fs = fopen("php://stdin", "r");
|
66 |
+
if ($fs !== false) {
|
67 |
+
/*
|
68 |
+
while (!feof($fs)) {
|
69 |
+
$data = fread($fs, 1);
|
70 |
+
var_dump($data);
|
71 |
+
$parameterValue .= $data;
|
72 |
+
} */
|
73 |
+
$parameterValue = stream_get_contents($fs);
|
74 |
+
fclose($fs);
|
75 |
+
}
|
76 |
+
|
77 |
+
// Remove ending \r\n
|
78 |
+
$parameterValue = rtrim($parameterValue);
|
79 |
+
|
80 |
+
if (strtolower($parameterValue) == 'true') {
|
81 |
+
$parameterValue = true;
|
82 |
+
} else if (strtolower($parameterValue) == 'false') {
|
83 |
+
$parameterValue = false;
|
84 |
+
}
|
85 |
+
}
|
86 |
+
|
87 |
+
// Done!
|
88 |
+
return $parameterValue;
|
89 |
+
}
|
90 |
+
}
|
libs/Microsoft/Console/Exception.php
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_Console
|
30 |
+
* @subpackage Exception
|
31 |
+
* @version $Id: Exception.php 55733 2011-01-03 09:17:16Z unknown $
|
32 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
33 |
+
* @license http://phpazure.codeplex.com/license
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @see Microsoft_AutoLoader
|
38 |
+
*/
|
39 |
+
require_once dirname(__FILE__) . '/../AutoLoader.php';
|
40 |
+
|
41 |
+
/**
|
42 |
+
* @category Microsoft
|
43 |
+
* @package Microsoft_Console
|
44 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
45 |
+
* @license http://phpazure.codeplex.com/license
|
46 |
+
*/
|
47 |
+
class Microsoft_Console_Exception extends Microsoft_Exception
|
48 |
+
{}
|
libs/Microsoft/Http/Client.php
CHANGED
@@ -1,1427 +1,1427 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Zend Framework
|
5 |
-
*
|
6 |
-
* LICENSE
|
7 |
-
*
|
8 |
-
* This source file is subject to the new BSD license that is bundled
|
9 |
-
* with this package in the file LICENSE.txt.
|
10 |
-
* It is also available through the world-wide-web at this URL:
|
11 |
-
* http://framework.zend.com/license/new-bsd
|
12 |
-
* If you did not receive a copy of the license and are unable to
|
13 |
-
* obtain it through the world-wide-web, please send an email
|
14 |
-
* to license@zend.com so we can send you a copy immediately.
|
15 |
-
*
|
16 |
-
* @category Microsoft
|
17 |
-
* @package Microsoft_Http
|
18 |
-
* @subpackage Client
|
19 |
-
* @version $Id: Client.php 19661 2009-12-15 18:03:07Z matthew $
|
20 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
21 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
22 |
-
*/
|
23 |
-
|
24 |
-
|
25 |
-
/**
|
26 |
-
* @see Microsoft_AutoLoader
|
27 |
-
*/
|
28 |
-
require_once dirname(__FILE__) . '/../AutoLoader.php';
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Microsoft_Http_Client is an implemetation of an HTTP client in PHP. The client
|
32 |
-
* supports basic features like sending different HTTP requests and handling
|
33 |
-
* redirections, as well as more advanced features like proxy settings, HTTP
|
34 |
-
* authentication and cookie persistance (using a Microsoft_Http_CookieJar object)
|
35 |
-
*
|
36 |
-
* @todo Implement proxy settings
|
37 |
-
* @category Microsoft
|
38 |
-
* @package Microsoft_Http
|
39 |
-
* @subpackage Client
|
40 |
-
* @throws Microsoft_Http_Client_Exception
|
41 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
42 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
43 |
-
*/
|
44 |
-
class Microsoft_Http_Client
|
45 |
-
{
|
46 |
-
/**
|
47 |
-
* HTTP request methods
|
48 |
-
*/
|
49 |
-
const GET = 'GET';
|
50 |
-
const POST = 'POST';
|
51 |
-
const PUT = 'PUT';
|
52 |
-
const HEAD = 'HEAD';
|
53 |
-
const DELETE = 'DELETE';
|
54 |
-
const TRACE = 'TRACE';
|
55 |
-
const OPTIONS = 'OPTIONS';
|
56 |
-
const CONNECT = 'CONNECT';
|
57 |
-
const MERGE = 'MERGE';
|
58 |
-
|
59 |
-
/**
|
60 |
-
* Supported HTTP Authentication methods
|
61 |
-
*/
|
62 |
-
const AUTH_BASIC = 'basic';
|
63 |
-
//const AUTH_DIGEST = 'digest'; <-- not implemented yet
|
64 |
-
|
65 |
-
/**
|
66 |
-
* HTTP protocol versions
|
67 |
-
*/
|
68 |
-
const HTTP_1 = '1.1';
|
69 |
-
const HTTP_0 = '1.0';
|
70 |
-
|
71 |
-
/**
|
72 |
-
* Content attributes
|
73 |
-
*/
|
74 |
-
const CONTENT_TYPE = 'Content-Type';
|
75 |
-
const CONTENT_LENGTH = 'Content-Length';
|
76 |
-
|
77 |
-
/**
|
78 |
-
* POST data encoding methods
|
79 |
-
*/
|
80 |
-
const ENC_URLENCODED = 'application/x-www-form-urlencoded';
|
81 |
-
const ENC_FORMDATA = 'multipart/form-data';
|
82 |
-
|
83 |
-
/**
|
84 |
-
* Configuration array, set using the constructor or using ::setConfig()
|
85 |
-
*
|
86 |
-
* @var array
|
87 |
-
*/
|
88 |
-
protected $config = array(
|
89 |
-
'maxredirects' => 5,
|
90 |
-
'strictredirects' => false,
|
91 |
-
'useragent' => 'Microsoft_Http_Client',
|
92 |
-
'timeout' => 10,
|
93 |
-
'adapter' => 'Microsoft_Http_Client_Adapter_Socket',
|
94 |
-
'httpversion' => self::HTTP_1,
|
95 |
-
'keepalive' => false,
|
96 |
-
'storeresponse' => true,
|
97 |
-
'strict' => true,
|
98 |
-
'output_stream' => false,
|
99 |
-
);
|
100 |
-
|
101 |
-
/**
|
102 |
-
* The adapter used to preform the actual connection to the server
|
103 |
-
*
|
104 |
-
* @var Microsoft_Http_Client_Adapter_Interface
|
105 |
-
*/
|
106 |
-
protected $adapter = null;
|
107 |
-
|
108 |
-
/**
|
109 |
-
* Request URI
|
110 |
-
*
|
111 |
-
* @var Microsoft_Uri_Http
|
112 |
-
*/
|
113 |
-
protected $uri = null;
|
114 |
-
|
115 |
-
/**
|
116 |
-
* Associative array of request headers
|
117 |
-
*
|
118 |
-
* @var array
|
119 |
-
*/
|
120 |
-
protected $headers = array();
|
121 |
-
|
122 |
-
/**
|
123 |
-
* HTTP request method
|
124 |
-
*
|
125 |
-
* @var string
|
126 |
-
*/
|
127 |
-
protected $method = self::GET;
|
128 |
-
|
129 |
-
/**
|
130 |
-
* Associative array of GET parameters
|
131 |
-
*
|
132 |
-
* @var array
|
133 |
-
*/
|
134 |
-
protected $paramsGet = array();
|
135 |
-
|
136 |
-
/**
|
137 |
-
* Assiciative array of POST parameters
|
138 |
-
*
|
139 |
-
* @var array
|
140 |
-
*/
|
141 |
-
protected $paramsPost = array();
|
142 |
-
|
143 |
-
/**
|
144 |
-
* Request body content type (for POST requests)
|
145 |
-
*
|
146 |
-
* @var string
|
147 |
-
*/
|
148 |
-
protected $enctype = null;
|
149 |
-
|
150 |
-
/**
|
151 |
-
* The raw post data to send. Could be set by setRawData($data, $enctype).
|
152 |
-
*
|
153 |
-
* @var string
|
154 |
-
*/
|
155 |
-
protected $raw_post_data = null;
|
156 |
-
|
157 |
-
/**
|
158 |
-
* HTTP Authentication settings
|
159 |
-
*
|
160 |
-
* Expected to be an associative array with this structure:
|
161 |
-
* $this->auth = array('user' => 'username', 'password' => 'password', 'type' => 'basic')
|
162 |
-
* Where 'type' should be one of the supported authentication types (see the AUTH_*
|
163 |
-
* constants), for example 'basic' or 'digest'.
|
164 |
-
*
|
165 |
-
* If null, no authentication will be used.
|
166 |
-
*
|
167 |
-
* @var array|null
|
168 |
-
*/
|
169 |
-
protected $auth;
|
170 |
-
|
171 |
-
/**
|
172 |
-
* File upload arrays (used in POST requests)
|
173 |
-
*
|
174 |
-
* An associative array, where each element is of the format:
|
175 |
-
* 'name' => array('filename.txt', 'text/plain', 'This is the actual file contents')
|
176 |
-
*
|
177 |
-
* @var array
|
178 |
-
*/
|
179 |
-
protected $files = array();
|
180 |
-
|
181 |
-
/**
|
182 |
-
* The client's cookie jar
|
183 |
-
*
|
184 |
-
* @var Microsoft_Http_CookieJar
|
185 |
-
*/
|
186 |
-
protected $cookiejar = null;
|
187 |
-
|
188 |
-
/**
|
189 |
-
* The last HTTP request sent by the client, as string
|
190 |
-
*
|
191 |
-
* @var string
|
192 |
-
*/
|
193 |
-
protected $last_request = null;
|
194 |
-
|
195 |
-
/**
|
196 |
-
* The last HTTP response received by the client
|
197 |
-
*
|
198 |
-
* @var Microsoft_Http_Response
|
199 |
-
*/
|
200 |
-
protected $last_response = null;
|
201 |
-
|
202 |
-
/**
|
203 |
-
* Redirection counter
|
204 |
-
*
|
205 |
-
* @var int
|
206 |
-
*/
|
207 |
-
protected $redirectCounter = 0;
|
208 |
-
|
209 |
-
/**
|
210 |
-
* Fileinfo magic database resource
|
211 |
-
*
|
212 |
-
* This varaiable is populated the first time _detectFileMimeType is called
|
213 |
-
* and is then reused on every call to this method
|
214 |
-
*
|
215 |
-
* @var resource
|
216 |
-
*/
|
217 |
-
static protected $_fileInfoDb = null;
|
218 |
-
|
219 |
-
/**
|
220 |
-
* Contructor method. Will create a new HTTP client. Accepts the target
|
221 |
-
* URL and optionally configuration array.
|
222 |
-
*
|
223 |
-
* @param Microsoft_Uri_Http|string $uri
|
224 |
-
* @param array $config Configuration key-value pairs.
|
225 |
-
*/
|
226 |
-
public function __construct($uri = null, $config = null)
|
227 |
-
{
|
228 |
-
if ($uri !== null) {
|
229 |
-
$this->setUri($uri);
|
230 |
-
}
|
231 |
-
if ($config !== null) {
|
232 |
-
$this->setConfig($config);
|
233 |
-
}
|
234 |
-
}
|
235 |
-
|
236 |
-
/**
|
237 |
-
* Set the URI for the next request
|
238 |
-
*
|
239 |
-
* @param Microsoft_Uri_Http|string $uri
|
240 |
-
* @return Microsoft_Http_Client
|
241 |
-
* @throws Microsoft_Http_Client_Exception
|
242 |
-
*/
|
243 |
-
public function setUri($uri)
|
244 |
-
{
|
245 |
-
if (is_string($uri)) {
|
246 |
-
$uri = Microsoft_Uri::factory($uri);
|
247 |
-
}
|
248 |
-
|
249 |
-
if (!$uri instanceof Microsoft_Uri_Http) {
|
250 |
-
/** @see Microsoft_Http_Client_Exception */
|
251 |
-
require_once 'Microsoft/Http/Client/Exception.php';
|
252 |
-
throw new Microsoft_Http_Client_Exception('Passed parameter is not a valid HTTP URI.');
|
253 |
-
}
|
254 |
-
|
255 |
-
// Set auth if username and password has been specified in the uri
|
256 |
-
if ($uri->getUsername() && $uri->getPassword()) {
|
257 |
-
$this->setAuth($uri->getUsername(), $uri->getPassword());
|
258 |
-
}
|
259 |
-
|
260 |
-
// We have no ports, set the defaults
|
261 |
-
if (! $uri->getPort()) {
|
262 |
-
$uri->setPort(($uri->getScheme() == 'https' ? 443 : 80));
|
263 |
-
}
|
264 |
-
|
265 |
-
$this->uri = $uri;
|
266 |
-
|
267 |
-
return $this;
|
268 |
-
}
|
269 |
-
|
270 |
-
/**
|
271 |
-
* Get the URI for the next request
|
272 |
-
*
|
273 |
-
* @param boolean $as_string If true, will return the URI as a string
|
274 |
-
* @return Microsoft_Uri_Http|string
|
275 |
-
*/
|
276 |
-
public function getUri($as_string = false)
|
277 |
-
{
|
278 |
-
if ($as_string && $this->uri instanceof Microsoft_Uri_Http) {
|
279 |
-
return $this->uri->__toString();
|
280 |
-
} else {
|
281 |
-
return $this->uri;
|
282 |
-
}
|
283 |
-
}
|
284 |
-
|
285 |
-
/**
|
286 |
-
* Set configuration parameters for this HTTP client
|
287 |
-
*
|
288 |
-
* @param Microsoft_Config | array $config
|
289 |
-
* @return Microsoft_Http_Client
|
290 |
-
* @throws Microsoft_Http_Client_Exception
|
291 |
-
*/
|
292 |
-
public function setConfig($config = array())
|
293 |
-
{
|
294 |
-
if ($config instanceof Microsoft_Config) {
|
295 |
-
$config = $config->toArray();
|
296 |
-
|
297 |
-
} elseif (! is_array($config)) {
|
298 |
-
/** @see Microsoft_Http_Client_Exception */
|
299 |
-
require_once 'Microsoft/Http/Client/Exception.php';
|
300 |
-
throw new Microsoft_Http_Client_Exception('Array expected, got ' . gettype($config));
|
301 |
-
}
|
302 |
-
|
303 |
-
foreach ($config as $k => $v) {
|
304 |
-
$this->config[strtolower($k)] = $v;
|
305 |
-
}
|
306 |
-
|
307 |
-
// Pass configuration options to the adapter if it exists
|
308 |
-
if ($this->adapter instanceof Microsoft_Http_Client_Adapter_Interface) {
|
309 |
-
$this->adapter->setConfig($config);
|
310 |
-
}
|
311 |
-
|
312 |
-
return $this;
|
313 |
-
}
|
314 |
-
|
315 |
-
/**
|
316 |
-
* Set the next request's method
|
317 |
-
*
|
318 |
-
* Validated the passed method and sets it. If we have files set for
|
319 |
-
* POST requests, and the new method is not POST, the files are silently
|
320 |
-
* dropped.
|
321 |
-
*
|
322 |
-
* @param string $method
|
323 |
-
* @return Microsoft_Http_Client
|
324 |
-
* @throws Microsoft_Http_Client_Exception
|
325 |
-
*/
|
326 |
-
public function setMethod($method = self::GET)
|
327 |
-
{
|
328 |
-
if (! preg_match('/^[^\x00-\x1f\x7f-\xff\(\)<>@,;:\\\\"\/\[\]\?={}\s]+$/', $method)) {
|
329 |
-
/** @see Microsoft_Http_Client_Exception */
|
330 |
-
require_once 'Microsoft/Http/Client/Exception.php';
|
331 |
-
throw new Microsoft_Http_Client_Exception("'{$method}' is not a valid HTTP request method.");
|
332 |
-
}
|
333 |
-
|
334 |
-
if ($method == self::POST && $this->enctype === null) {
|
335 |
-
$this->setEncType(self::ENC_URLENCODED);
|
336 |
-
}
|
337 |
-
|
338 |
-
$this->method = $method;
|
339 |
-
|
340 |
-
return $this;
|
341 |
-
}
|
342 |
-
|
343 |
-
/**
|
344 |
-
* Set one or more request headers
|
345 |
-
*
|
346 |
-
* This function can be used in several ways to set the client's request
|
347 |
-
* headers:
|
348 |
-
* 1. By providing two parameters: $name as the header to set (eg. 'Host')
|
349 |
-
* and $value as it's value (eg. 'www.example.com').
|
350 |
-
* 2. By providing a single header string as the only parameter
|
351 |
-
* eg. 'Host: www.example.com'
|
352 |
-
* 3. By providing an array of headers as the first parameter
|
353 |
-
* eg. array('host' => 'www.example.com', 'x-foo: bar'). In This case
|
354 |
-
* the function will call itself recursively for each array item.
|
355 |
-
*
|
356 |
-
* @param string|array $name Header name, full header string ('Header: value')
|
357 |
-
* or an array of headers
|
358 |
-
* @param mixed $value Header value or null
|
359 |
-
* @return Microsoft_Http_Client
|
360 |
-
* @throws Microsoft_Http_Client_Exception
|
361 |
-
*/
|
362 |
-
public function setHeaders($name, $value = null)
|
363 |
-
{
|
364 |
-
// If we got an array, go recusive!
|
365 |
-
if (is_array($name)) {
|
366 |
-
foreach ($name as $k => $v) {
|
367 |
-
if (is_string($k)) {
|
368 |
-
$this->setHeaders($k, $v);
|
369 |
-
} else {
|
370 |
-
$this->setHeaders($v, null);
|
371 |
-
}
|
372 |
-
}
|
373 |
-
} else {
|
374 |
-
// Check if $name needs to be split
|
375 |
-
if ($value === null && (strpos($name, ':') > 0)) {
|
376 |
-
list($name, $value) = explode(':', $name, 2);
|
377 |
-
}
|
378 |
-
|
379 |
-
// Make sure the name is valid if we are in strict mode
|
380 |
-
if ($this->config['strict'] && (! preg_match('/^[a-zA-Z0-9-]+$/', $name))) {
|
381 |
-
/** @see Microsoft_Http_Client_Exception */
|
382 |
-
require_once 'Microsoft/Http/Client/Exception.php';
|
383 |
-
throw new Microsoft_Http_Client_Exception("{$name} is not a valid HTTP header name");
|
384 |
-
}
|
385 |
-
|
386 |
-
$normalized_name = strtolower($name);
|
387 |
-
|
388 |
-
// If $value is null or false, unset the header
|
389 |
-
if ($value === null || $value === false) {
|
390 |
-
unset($this->headers[$normalized_name]);
|
391 |
-
|
392 |
-
// Else, set the header
|
393 |
-
} else {
|
394 |
-
// Header names are stored lowercase internally.
|
395 |
-
if (is_string($value)) {
|
396 |
-
$value = trim($value);
|
397 |
-
}
|
398 |
-
$this->headers[$normalized_name] = array($name, $value);
|
399 |
-
}
|
400 |
-
}
|
401 |
-
|
402 |
-
return $this;
|
403 |
-
}
|
404 |
-
|
405 |
-
/**
|
406 |
-
* Get the value of a specific header
|
407 |
-
*
|
408 |
-
* Note that if the header has more than one value, an array
|
409 |
-
* will be returned.
|
410 |
-
*
|
411 |
-
* @param string $key
|
412 |
-
* @return string|array|null The header value or null if it is not set
|
413 |
-
*/
|
414 |
-
public function getHeader($key)
|
415 |
-
{
|
416 |
-
$key = strtolower($key);
|
417 |
-
if (isset($this->headers[$key])) {
|
418 |
-
return $this->headers[$key][1];
|
419 |
-
} else {
|
420 |
-
return null;
|
421 |
-
}
|
422 |
-
}
|
423 |
-
|
424 |
-
/**
|
425 |
-
* Set a GET parameter for the request. Wrapper around _setParameter
|
426 |
-
*
|
427 |
-
* @param string|array $name
|
428 |
-
* @param string $value
|
429 |
-
* @return Microsoft_Http_Client
|
430 |
-
*/
|
431 |
-
public function setParameterGet($name, $value = null)
|
432 |
-
{
|
433 |
-
if (is_array($name)) {
|
434 |
-
foreach ($name as $k => $v)
|
435 |
-
$this->_setParameter('GET', $k, $v);
|
436 |
-
} else {
|
437 |
-
$this->_setParameter('GET', $name, $value);
|
438 |
-
}
|
439 |
-
|
440 |
-
return $this;
|
441 |
-
}
|
442 |
-
|
443 |
-
/**
|
444 |
-
* Set a POST parameter for the request. Wrapper around _setParameter
|
445 |
-
*
|
446 |
-
* @param string|array $name
|
447 |
-
* @param string $value
|
448 |
-
* @return Microsoft_Http_Client
|
449 |
-
*/
|
450 |
-
public function setParameterPost($name, $value = null)
|
451 |
-
{
|
452 |
-
if (is_array($name)) {
|
453 |
-
foreach ($name as $k => $v)
|
454 |
-
$this->_setParameter('POST', $k, $v);
|
455 |
-
} else {
|
456 |
-
$this->_setParameter('POST', $name, $value);
|
457 |
-
}
|
458 |
-
|
459 |
-
return $this;
|
460 |
-
}
|
461 |
-
|
462 |
-
/**
|
463 |
-
* Set a GET or POST parameter - used by SetParameterGet and SetParameterPost
|
464 |
-
*
|
465 |
-
* @param string $type GET or POST
|
466 |
-
* @param string $name
|
467 |
-
* @param string $value
|
468 |
-
* @return null
|
469 |
-
*/
|
470 |
-
protected function _setParameter($type, $name, $value)
|
471 |
-
{
|
472 |
-
$parray = array();
|
473 |
-
$type = strtolower($type);
|
474 |
-
switch ($type) {
|
475 |
-
case 'get':
|
476 |
-
$parray = &$this->paramsGet;
|
477 |
-
break;
|
478 |
-
case 'post':
|
479 |
-
$parray = &$this->paramsPost;
|
480 |
-
break;
|
481 |
-
}
|
482 |
-
|
483 |
-
if ($value === null) {
|
484 |
-
if (isset($parray[$name])) unset($parray[$name]);
|
485 |
-
} else {
|
486 |
-
$parray[$name] = $value;
|
487 |
-
}
|
488 |
-
}
|
489 |
-
|
490 |
-
/**
|
491 |
-
* Get the number of redirections done on the last request
|
492 |
-
*
|
493 |
-
* @return int
|
494 |
-
*/
|
495 |
-
public function getRedirectionsCount()
|
496 |
-
{
|
497 |
-
return $this->redirectCounter;
|
498 |
-
}
|
499 |
-
|
500 |
-
/**
|
501 |
-
* Set HTTP authentication parameters
|
502 |
-
*
|
503 |
-
* $type should be one of the supported types - see the self::AUTH_*
|
504 |
-
* constants.
|
505 |
-
*
|
506 |
-
* To enable authentication:
|
507 |
-
* <code>
|
508 |
-
* $this->setAuth('shahar', 'secret', Microsoft_Http_Client::AUTH_BASIC);
|
509 |
-
* </code>
|
510 |
-
*
|
511 |
-
* To disable authentication:
|
512 |
-
* <code>
|
513 |
-
* $this->setAuth(false);
|
514 |
-
* </code>
|
515 |
-
*
|
516 |
-
* @see http://www.faqs.org/rfcs/rfc2617.html
|
517 |
-
* @param string|false $user User name or false disable authentication
|
518 |
-
* @param string $password Password
|
519 |
-
* @param string $type Authentication type
|
520 |
-
* @return Microsoft_Http_Client
|
521 |
-
* @throws Microsoft_Http_Client_Exception
|
522 |
-
*/
|
523 |
-
public function setAuth($user, $password = '', $type = self::AUTH_BASIC)
|
524 |
-
{
|
525 |
-
// If we got false or null, disable authentication
|
526 |
-
if ($user === false || $user === null) {
|
527 |
-
$this->auth = null;
|
528 |
-
|
529 |
-
// Clear the auth information in the uri instance as well
|
530 |
-
if ($this->uri instanceof Microsoft_Uri_Http) {
|
531 |
-
$this->getUri()->setUsername('');
|
532 |
-
$this->getUri()->setPassword('');
|
533 |
-
}
|
534 |
-
// Else, set up authentication
|
535 |
-
} else {
|
536 |
-
// Check we got a proper authentication type
|
537 |
-
if (! defined('self::AUTH_' . strtoupper($type))) {
|
538 |
-
/** @see Microsoft_Http_Client_Exception */
|
539 |
-
require_once 'Microsoft/Http/Client/Exception.php';
|
540 |
-
throw new Microsoft_Http_Client_Exception("Invalid or not supported authentication type: '$type'");
|
541 |
-
}
|
542 |
-
|
543 |
-
$this->auth = array(
|
544 |
-
'user' => (string) $user,
|
545 |
-
'password' => (string) $password,
|
546 |
-
'type' => $type
|
547 |
-
);
|
548 |
-
}
|
549 |
-
|
550 |
-
return $this;
|
551 |
-
}
|
552 |
-
|
553 |
-
/**
|
554 |
-
* Set the HTTP client's cookie jar.
|
555 |
-
*
|
556 |
-
* A cookie jar is an object that holds and maintains cookies across HTTP requests
|
557 |
-
* and responses.
|
558 |
-
*
|
559 |
-
* @param Microsoft_Http_CookieJar|boolean $cookiejar Existing cookiejar object, true to create a new one, false to disable
|
560 |
-
* @return Microsoft_Http_Client
|
561 |
-
* @throws Microsoft_Http_Client_Exception
|
562 |
-
*/
|
563 |
-
public function setCookieJar($cookiejar = true)
|
564 |
-
{
|
565 |
-
if (! class_exists('Microsoft_Http_CookieJar')) {
|
566 |
-
require_once 'Microsoft/Http/CookieJar.php';
|
567 |
-
}
|
568 |
-
|
569 |
-
if ($cookiejar instanceof Microsoft_Http_CookieJar) {
|
570 |
-
$this->cookiejar = $cookiejar;
|
571 |
-
} elseif ($cookiejar === true) {
|
572 |
-
$this->cookiejar = new Microsoft_Http_CookieJar();
|
573 |
-
} elseif (! $cookiejar) {
|
574 |
-
$this->cookiejar = null;
|
575 |
-
} else {
|
576 |
-
/** @see Microsoft_Http_Client_Exception */
|
577 |
-
require_once 'Microsoft/Http/Client/Exception.php';
|
578 |
-
throw new Microsoft_Http_Client_Exception('Invalid parameter type passed as CookieJar');
|
579 |
-
}
|
580 |
-
|
581 |
-
return $this;
|
582 |
-
}
|
583 |
-
|
584 |
-
/**
|
585 |
-
* Return the current cookie jar or null if none.
|
586 |
-
*
|
587 |
-
* @return Microsoft_Http_CookieJar|null
|
588 |
-
*/
|
589 |
-
public function getCookieJar()
|
590 |
-
{
|
591 |
-
return $this->cookiejar;
|
592 |
-
}
|
593 |
-
|
594 |
-
/**
|
595 |
-
* Add a cookie to the request. If the client has no Cookie Jar, the cookies
|
596 |
-
* will be added directly to the headers array as "Cookie" headers.
|
597 |
-
*
|
598 |
-
* @param Microsoft_Http_Cookie|string $cookie
|
599 |
-
* @param string|null $value If "cookie" is a string, this is the cookie value.
|
600 |
-
* @return Microsoft_Http_Client
|
601 |
-
* @throws Microsoft_Http_Client_Exception
|
602 |
-
*/
|
603 |
-
public function setCookie($cookie, $value = null)
|
604 |
-
{
|
605 |
-
if (! class_exists('Microsoft_Http_Cookie')) {
|
606 |
-
require_once 'Microsoft/Http/Cookie.php';
|
607 |
-
}
|
608 |
-
|
609 |
-
if (is_array($cookie)) {
|
610 |
-
foreach ($cookie as $c => $v) {
|
611 |
-
if (is_string($c)) {
|
612 |
-
$this->setCookie($c, $v);
|
613 |
-
} else {
|
614 |
-
$this->setCookie($v);
|
615 |
-
}
|
616 |
-
}
|
617 |
-
|
618 |
-
return $this;
|
619 |
-
}
|
620 |
-
|
621 |
-
if ($value !== null) {
|
622 |
-
$value = urlencode($value);
|
623 |
-
}
|
624 |
-
|
625 |
-
if (isset($this->cookiejar)) {
|
626 |
-
if ($cookie instanceof Microsoft_Http_Cookie) {
|
627 |
-
$this->cookiejar->addCookie($cookie);
|
628 |
-
} elseif (is_string($cookie) && $value !== null) {
|
629 |
-
$cookie = Microsoft_Http_Cookie::fromString("{$cookie}={$value}", $this->uri);
|
630 |
-
$this->cookiejar->addCookie($cookie);
|
631 |
-
}
|
632 |
-
} else {
|
633 |
-
if ($cookie instanceof Microsoft_Http_Cookie) {
|
634 |
-
$name = $cookie->getName();
|
635 |
-
$value = $cookie->getValue();
|
636 |
-
$cookie = $name;
|
637 |
-
}
|
638 |
-
|
639 |
-
if (preg_match("/[=,; \t\r\n\013\014]/", $cookie)) {
|
640 |
-
/** @see Microsoft_Http_Client_Exception */
|
641 |
-
require_once 'Microsoft/Http/Client/Exception.php';
|
642 |
-
throw new Microsoft_Http_Client_Exception("Cookie name cannot contain these characters: =,; \t\r\n\013\014 ({$cookie})");
|
643 |
-
}
|
644 |
-
|
645 |
-
$value = addslashes($value);
|
646 |
-
|
647 |
-
if (! isset($this->headers['cookie'])) {
|
648 |
-
$this->headers['cookie'] = array('Cookie', '');
|
649 |
-
}
|
650 |
-
$this->headers['cookie'][1] .= $cookie . '=' . $value . '; ';
|
651 |
-
}
|
652 |
-
|
653 |
-
return $this;
|
654 |
-
}
|
655 |
-
|
656 |
-
/**
|
657 |
-
* Set a file to upload (using a POST request)
|
658 |
-
*
|
659 |
-
* Can be used in two ways:
|
660 |
-
*
|
661 |
-
* 1. $data is null (default): $filename is treated as the name if a local file which
|
662 |
-
* will be read and sent. Will try to guess the content type using mime_content_type().
|
663 |
-
* 2. $data is set - $filename is sent as the file name, but $data is sent as the file
|
664 |
-
* contents and no file is read from the file system. In this case, you need to
|
665 |
-
* manually set the Content-Type ($ctype) or it will default to
|
666 |
-
* application/octet-stream.
|
667 |
-
*
|
668 |
-
* @param string $filename Name of file to upload, or name to save as
|
669 |
-
* @param string $formname Name of form element to send as
|
670 |
-
* @param string $data Data to send (if null, $filename is read and sent)
|
671 |
-
* @param string $ctype Content type to use (if $data is set and $ctype is
|
672 |
-
* null, will be application/octet-stream)
|
673 |
-
* @return Microsoft_Http_Client
|
674 |
-
* @throws Microsoft_Http_Client_Exception
|
675 |
-
*/
|
676 |
-
public function setFileUpload($filename, $formname, $data = null, $ctype = null)
|
677 |
-
{
|
678 |
-
if ($data === null) {
|
679 |
-
if (($data = @file_get_contents($filename)) === false) {
|
680 |
-
/** @see Microsoft_Http_Client_Exception */
|
681 |
-
require_once 'Microsoft/Http/Client/Exception.php';
|
682 |
-
throw new Microsoft_Http_Client_Exception("Unable to read file '{$filename}' for upload");
|
683 |
-
}
|
684 |
-
|
685 |
-
if (! $ctype) {
|
686 |
-
$ctype = $this->_detectFileMimeType($filename);
|
687 |
-
}
|
688 |
-
}
|
689 |
-
|
690 |
-
// Force enctype to multipart/form-data
|
691 |
-
$this->setEncType(self::ENC_FORMDATA);
|
692 |
-
|
693 |
-
$this->files[] = array(
|
694 |
-
'formname' => $formname,
|
695 |
-
'filename' => basename($filename),
|
696 |
-
'ctype' => $ctype,
|
697 |
-
'data' => $data
|
698 |
-
);
|
699 |
-
|
700 |
-
return $this;
|
701 |
-
}
|
702 |
-
|
703 |
-
/**
|
704 |
-
* Set the encoding type for POST data
|
705 |
-
*
|
706 |
-
* @param string $enctype
|
707 |
-
* @return Microsoft_Http_Client
|
708 |
-
*/
|
709 |
-
public function setEncType($enctype = self::ENC_URLENCODED)
|
710 |
-
{
|
711 |
-
$this->enctype = $enctype;
|
712 |
-
|
713 |
-
return $this;
|
714 |
-
}
|
715 |
-
|
716 |
-
/**
|
717 |
-
* Set the raw (already encoded) POST data.
|
718 |
-
*
|
719 |
-
* This function is here for two reasons:
|
720 |
-
* 1. For advanced user who would like to set their own data, already encoded
|
721 |
-
* 2. For backwards compatibilty: If someone uses the old post($data) method.
|
722 |
-
* this method will be used to set the encoded data.
|
723 |
-
*
|
724 |
-
* $data can also be stream (such as file) from which the data will be read.
|
725 |
-
*
|
726 |
-
* @param string|resource $data
|
727 |
-
* @param string $enctype
|
728 |
-
* @return Microsoft_Http_Client
|
729 |
-
*/
|
730 |
-
public function setRawData($data, $enctype = null)
|
731 |
-
{
|
732 |
-
$this->raw_post_data = $data;
|
733 |
-
$this->setEncType($enctype);
|
734 |
-
if (is_resource($data)) {
|
735 |
-
// We've got stream data
|
736 |
-
$stat = @fstat($data);
|
737 |
-
if($stat) {
|
738 |
-
$this->setHeaders(self::CONTENT_LENGTH, $stat['size']);
|
739 |
-
}
|
740 |
-
}
|
741 |
-
return $this;
|
742 |
-
}
|
743 |
-
|
744 |
-
/**
|
745 |
-
* Clear all GET and POST parameters
|
746 |
-
*
|
747 |
-
* Should be used to reset the request parameters if the client is
|
748 |
-
* used for several concurrent requests.
|
749 |
-
*
|
750 |
-
* clearAll parameter controls if we clean just parameters or also
|
751 |
-
* headers and last_*
|
752 |
-
*
|
753 |
-
* @param bool $clearAll Should all data be cleared?
|
754 |
-
* @return Microsoft_Http_Client
|
755 |
-
*/
|
756 |
-
public function resetParameters($clearAll = false)
|
757 |
-
{
|
758 |
-
// Reset parameter data
|
759 |
-
$this->paramsGet = array();
|
760 |
-
$this->paramsPost = array();
|
761 |
-
$this->files = array();
|
762 |
-
$this->raw_post_data = null;
|
763 |
-
|
764 |
-
if($clearAll) {
|
765 |
-
$this->headers = array();
|
766 |
-
$this->last_request = null;
|
767 |
-
$this->last_response = null;
|
768 |
-
} else {
|
769 |
-
// Clear outdated headers
|
770 |
-
if (isset($this->headers[strtolower(self::CONTENT_TYPE)])) {
|
771 |
-
unset($this->headers[strtolower(self::CONTENT_TYPE)]);
|
772 |
-
}
|
773 |
-
if (isset($this->headers[strtolower(self::CONTENT_LENGTH)])) {
|
774 |
-
unset($this->headers[strtolower(self::CONTENT_LENGTH)]);
|
775 |
-
}
|
776 |
-
}
|
777 |
-
|
778 |
-
return $this;
|
779 |
-
}
|
780 |
-
|
781 |
-
/**
|
782 |
-
* Get the last HTTP request as string
|
783 |
-
*
|
784 |
-
* @return string
|
785 |
-
*/
|
786 |
-
public function getLastRequest()
|
787 |
-
{
|
788 |
-
return $this->last_request;
|
789 |
-
}
|
790 |
-
|
791 |
-
/**
|
792 |
-
* Get the last HTTP response received by this client
|
793 |
-
*
|
794 |
-
* If $config['storeresponse'] is set to false, or no response was
|
795 |
-
* stored yet, will return null
|
796 |
-
*
|
797 |
-
* @return Microsoft_Http_Response or null if none
|
798 |
-
*/
|
799 |
-
public function getLastResponse()
|
800 |
-
{
|
801 |
-
return $this->last_response;
|
802 |
-
}
|
803 |
-
|
804 |
-
/**
|
805 |
-
* Load the connection adapter
|
806 |
-
*
|
807 |
-
* While this method is not called more than one for a client, it is
|
808 |
-
* seperated from ->request() to preserve logic and readability
|
809 |
-
*
|
810 |
-
* @param Microsoft_Http_Client_Adapter_Interface|string $adapter
|
811 |
-
* @return null
|
812 |
-
* @throws Microsoft_Http_Client_Exception
|
813 |
-
*/
|
814 |
-
public function setAdapter($adapter)
|
815 |
-
{
|
816 |
-
if (is_string($adapter)) {
|
817 |
-
if (!class_exists($adapter)) {
|
818 |
-
@require_once( str_replace('_', '/', $adapter) . '.php' );
|
819 |
-
}
|
820 |
-
|
821 |
-
$adapter = new $adapter;
|
822 |
-
}
|
823 |
-
|
824 |
-
if (! $adapter instanceof Microsoft_Http_Client_Adapter_Interface) {
|
825 |
-
/** @see Microsoft_Http_Client_Exception */
|
826 |
-
require_once 'Microsoft/Http/Client/Exception.php';
|
827 |
-
throw new Microsoft_Http_Client_Exception('Passed adapter is not a HTTP connection adapter');
|
828 |
-
}
|
829 |
-
|
830 |
-
$this->adapter = $adapter;
|
831 |
-
$config = $this->config;
|
832 |
-
unset($config['adapter']);
|
833 |
-
$this->adapter->setConfig($config);
|
834 |
-
}
|
835 |
-
|
836 |
-
/**
|
837 |
-
* Load the connection adapter
|
838 |
-
*
|
839 |
-
* @return Microsoft_Http_Client_Adapter_Interface $adapter
|
840 |
-
*/
|
841 |
-
public function getAdapter()
|
842 |
-
{
|
843 |
-
return $this->adapter;
|
844 |
-
}
|
845 |
-
|
846 |
-
/**
|
847 |
-
* Set streaming for received data
|
848 |
-
*
|
849 |
-
* @param string|boolean $streamfile Stream file, true for temp file, false/null for no streaming
|
850 |
-
* @return Microsoft_Http_Client
|
851 |
-
*/
|
852 |
-
public function setStream($streamfile = true)
|
853 |
-
{
|
854 |
-
$this->setConfig(array("output_stream" => $streamfile));
|
855 |
-
return $this;
|
856 |
-
}
|
857 |
-
|
858 |
-
/**
|
859 |
-
* Get status of streaming for received data
|
860 |
-
* @return boolean|string
|
861 |
-
*/
|
862 |
-
public function getStream()
|
863 |
-
{
|
864 |
-
return $this->config["output_stream"];
|
865 |
-
}
|
866 |
-
|
867 |
-
/**
|
868 |
-
* Create temporary stream
|
869 |
-
*
|
870 |
-
* @return resource
|
871 |
-
*/
|
872 |
-
protected function _openTempStream()
|
873 |
-
{
|
874 |
-
$this->_stream_name = $this->config['output_stream'];
|
875 |
-
if(!is_string($this->_stream_name)) {
|
876 |
-
// If name is not given, create temp name
|
877 |
-
$this->_stream_name = tempnam(isset($this->config['stream_tmp_dir'])?$this->config['stream_tmp_dir']:sys_get_temp_dir(),
|
878 |
-
'Microsoft_Http_Client');
|
879 |
-
}
|
880 |
-
|
881 |
-
$fp = fopen($this->_stream_name, "w+b");
|
882 |
-
if(!$fp) {
|
883 |
-
$this->close();
|
884 |
-
require_once 'Microsoft/Http/Client/Exception.php';
|
885 |
-
throw new Microsoft_Http_Client_Exception("Could not open temp file $name");
|
886 |
-
|
887 |
-
}
|
888 |
-
return $fp;
|
889 |
-
}
|
890 |
-
|
891 |
-
/**
|
892 |
-
* Send the HTTP request and return an HTTP response object
|
893 |
-
*
|
894 |
-
* @param string $method
|
895 |
-
* @return Microsoft_Http_Response
|
896 |
-
* @throws Microsoft_Http_Client_Exception
|
897 |
-
*/
|
898 |
-
public function request($method = null)
|
899 |
-
{
|
900 |
-
if (! $this->uri instanceof Microsoft_Uri_Http) {
|
901 |
-
/** @see Microsoft_Http_Client_Exception */
|
902 |
-
require_once 'Microsoft/Http/Client/Exception.php';
|
903 |
-
throw new Microsoft_Http_Client_Exception('No valid URI has been passed to the client');
|
904 |
-
}
|
905 |
-
|
906 |
-
if ($method) {
|
907 |
-
$this->setMethod($method);
|
908 |
-
}
|
909 |
-
$this->redirectCounter = 0;
|
910 |
-
$response = null;
|
911 |
-
|
912 |
-
// Make sure the adapter is loaded
|
913 |
-
if ($this->adapter == null) {
|
914 |
-
$this->setAdapter($this->config['adapter']);
|
915 |
-
}
|
916 |
-
|
917 |
-
// Send the first request. If redirected, continue.
|
918 |
-
do {
|
919 |
-
// Clone the URI and add the additional GET parameters to it
|
920 |
-
$uri = clone $this->uri;
|
921 |
-
if (! empty($this->paramsGet)) {
|
922 |
-
$query = $uri->getQuery();
|
923 |
-
if (! empty($query)) {
|
924 |
-
$query .= '&';
|
925 |
-
}
|
926 |
-
$query .= http_build_query($this->paramsGet, null, '&');
|
927 |
-
|
928 |
-
$uri->setQuery($query);
|
929 |
-
}
|
930 |
-
|
931 |
-
$body = $this->_prepareBody();
|
932 |
-
$headers = $this->_prepareHeaders();
|
933 |
-
|
934 |
-
// check that adapter supports streaming before using it
|
935 |
-
if(is_resource($body) && !($this->adapter instanceof Microsoft_Http_Client_Adapter_Stream)) {
|
936 |
-
/** @see Microsoft_Http_Client_Exception */
|
937 |
-
require_once 'Microsoft/Http/Client/Exception.php';
|
938 |
-
throw new Microsoft_Http_Client_Exception('Adapter does not support streaming');
|
939 |
-
}
|
940 |
-
|
941 |
-
// Open the connection, send the request and read the response
|
942 |
-
$this->adapter->connect($uri->getHost(), $uri->getPort(),
|
943 |
-
($uri->getScheme() == 'https' ? true : false));
|
944 |
-
|
945 |
-
if($this->config['output_stream']) {
|
946 |
-
if($this->adapter instanceof Microsoft_Http_Client_Adapter_Stream) {
|
947 |
-
$stream = $this->_openTempStream();
|
948 |
-
$this->adapter->setOutputStream($stream);
|
949 |
-
} else {
|
950 |
-
/** @see Microsoft_Http_Client_Exception */
|
951 |
-
require_once 'Microsoft/Http/Client/Exception.php';
|
952 |
-
throw new Microsoft_Http_Client_Exception('Adapter does not support streaming');
|
953 |
-
}
|
954 |
-
}
|
955 |
-
|
956 |
-
$this->last_request = $this->adapter->write($this->method,
|
957 |
-
$uri, $this->config['httpversion'], $headers, $body);
|
958 |
-
|
959 |
-
$response = $this->adapter->read();
|
960 |
-
if (! $response) {
|
961 |
-
/** @see Microsoft_Http_Client_Exception */
|
962 |
-
require_once 'Microsoft/Http/Client/Exception.php';
|
963 |
-
throw new Microsoft_Http_Client_Exception('Unable to read response, or response is empty');
|
964 |
-
}
|
965 |
-
|
966 |
-
if($this->config['output_stream']) {
|
967 |
-
rewind($stream);
|
968 |
-
// cleanup the adapter
|
969 |
-
$this->adapter->setOutputStream(null);
|
970 |
-
$response = Microsoft_Http_Response_Stream::fromStream($response, $stream);
|
971 |
-
$response->setStreamName($this->_stream_name);
|
972 |
-
if(!is_string($this->config['output_stream'])) {
|
973 |
-
// we used temp name, will need to clean up
|
974 |
-
$response->setCleanup(true);
|
975 |
-
}
|
976 |
-
} else {
|
977 |
-
$response = Microsoft_Http_Response::fromString($response);
|
978 |
-
}
|
979 |
-
|
980 |
-
if ($this->config['storeresponse']) {
|
981 |
-
$this->last_response = $response;
|
982 |
-
}
|
983 |
-
|
984 |
-
// Load cookies into cookie jar
|
985 |
-
if (isset($this->cookiejar)) {
|
986 |
-
$this->cookiejar->addCookiesFromResponse($response, $uri);
|
987 |
-
}
|
988 |
-
|
989 |
-
// If we got redirected, look for the Location header
|
990 |
-
if ($response->isRedirect() && ($location = $response->getHeader('location'))) {
|
991 |
-
|
992 |
-
// Check whether we send the exact same request again, or drop the parameters
|
993 |
-
// and send a GET request
|
994 |
-
if ($response->getStatus() == 303 ||
|
995 |
-
((! $this->config['strictredirects']) && ($response->getStatus() == 302 ||
|
996 |
-
$response->getStatus() == 301))) {
|
997 |
-
|
998 |
-
$this->resetParameters();
|
999 |
-
$this->setMethod(self::GET);
|
1000 |
-
}
|
1001 |
-
|
1002 |
-
// If we got a well formed absolute URI
|
1003 |
-
if (Microsoft_Uri_Http::check($location)) {
|
1004 |
-
$this->setHeaders('host', null);
|
1005 |
-
$this->setUri($location);
|
1006 |
-
|
1007 |
-
} else {
|
1008 |
-
|
1009 |
-
// Split into path and query and set the query
|
1010 |
-
if (strpos($location, '?') !== false) {
|
1011 |
-
list($location, $query) = explode('?', $location, 2);
|
1012 |
-
} else {
|
1013 |
-
$query = '';
|
1014 |
-
}
|
1015 |
-
$this->uri->setQuery($query);
|
1016 |
-
|
1017 |
-
// Else, if we got just an absolute path, set it
|
1018 |
-
if(strpos($location, '/') === 0) {
|
1019 |
-
$this->uri->setPath($location);
|
1020 |
-
|
1021 |
-
// Else, assume we have a relative path
|
1022 |
-
} else {
|
1023 |
-
// Get the current path directory, removing any trailing slashes
|
1024 |
-
$path = $this->uri->getPath();
|
1025 |
-
$path = rtrim(substr($path, 0, strrpos($path, '/')), "/");
|
1026 |
-
$this->uri->setPath($path . '/' . $location);
|
1027 |
-
}
|
1028 |
-
}
|
1029 |
-
++$this->redirectCounter;
|
1030 |
-
|
1031 |
-
} else {
|
1032 |
-
// If we didn't get any location, stop redirecting
|
1033 |
-
break;
|
1034 |
-
}
|
1035 |
-
|
1036 |
-
} while ($this->redirectCounter < $this->config['maxredirects']);
|
1037 |
-
|
1038 |
-
return $response;
|
1039 |
-
}
|
1040 |
-
|
1041 |
-
/**
|
1042 |
-
* Prepare the request headers
|
1043 |
-
*
|
1044 |
-
* @return array
|
1045 |
-
*/
|
1046 |
-
protected function _prepareHeaders()
|
1047 |
-
{
|
1048 |
-
$headers = array();
|
1049 |
-
|
1050 |
-
// Set the host header
|
1051 |
-
if (! isset($this->headers['host'])) {
|
1052 |
-
$host = $this->uri->getHost();
|
1053 |
-
|
1054 |
-
// If the port is not default, add it
|
1055 |
-
if (! (($this->uri->getScheme() == 'http' && $this->uri->getPort() == 80) ||
|
1056 |
-
($this->uri->getScheme() == 'https' && $this->uri->getPort() == 443))) {
|
1057 |
-
$host .= ':' . $this->uri->getPort();
|
1058 |
-
}
|
1059 |
-
|
1060 |
-
$headers[] = "Host: {$host}";
|
1061 |
-
}
|
1062 |
-
|
1063 |
-
// Set the connection header
|
1064 |
-
if (! isset($this->headers['connection'])) {
|
1065 |
-
if (! $this->config['keepalive']) {
|
1066 |
-
$headers[] = "Connection: close";
|
1067 |
-
}
|
1068 |
-
}
|
1069 |
-
|
1070 |
-
// Set the Accept-encoding header if not set - depending on whether
|
1071 |
-
// zlib is available or not.
|
1072 |
-
if (! isset($this->headers['accept-encoding'])) {
|
1073 |
-
if (function_exists('gzinflate')) {
|
1074 |
-
$headers[] = 'Accept-encoding: gzip, deflate';
|
1075 |
-
} else {
|
1076 |
-
$headers[] = 'Accept-encoding: identity';
|
1077 |
-
}
|
1078 |
-
}
|
1079 |
-
|
1080 |
-
// Set the Content-Type header
|
1081 |
-
if ($this->method == self::POST &&
|
1082 |
-
(! isset($this->headers[strtolower(self::CONTENT_TYPE)]) && isset($this->enctype))) {
|
1083 |
-
|
1084 |
-
$headers[] = self::CONTENT_TYPE . ': ' . $this->enctype;
|
1085 |
-
}
|
1086 |
-
|
1087 |
-
// Set the user agent header
|
1088 |
-
if (! isset($this->headers['user-agent']) && isset($this->config['useragent'])) {
|
1089 |
-
$headers[] = "User-Agent: {$this->config['useragent']}";
|
1090 |
-
}
|
1091 |
-
|
1092 |
-
// Set HTTP authentication if needed
|
1093 |
-
if (is_array($this->auth)) {
|
1094 |
-
$auth = self::encodeAuthHeader($this->auth['user'], $this->auth['password'], $this->auth['type']);
|
1095 |
-
$headers[] = "Authorization: {$auth}";
|
1096 |
-
}
|
1097 |
-
|
1098 |
-
// Load cookies from cookie jar
|
1099 |
-
if (isset($this->cookiejar)) {
|
1100 |
-
$cookstr = $this->cookiejar->getMatchingCookies($this->uri,
|
1101 |
-
true, Microsoft_Http_CookieJar::COOKIE_STRING_CONCAT);
|
1102 |
-
|
1103 |
-
if ($cookstr) {
|
1104 |
-
$headers[] = "Cookie: {$cookstr}";
|
1105 |
-
}
|
1106 |
-
}
|
1107 |
-
|
1108 |
-
// Add all other user defined headers
|
1109 |
-
foreach ($this->headers as $header) {
|
1110 |
-
list($name, $value) = $header;
|
1111 |
-
if (is_array($value)) {
|
1112 |
-
$value = implode(', ', $value);
|
1113 |
-
}
|
1114 |
-
|
1115 |
-
$headers[] = "$name: $value";
|
1116 |
-
}
|
1117 |
-
|
1118 |
-
return $headers;
|
1119 |
-
}
|
1120 |
-
|
1121 |
-
/**
|
1122 |
-
* Prepare the request body (for POST and PUT requests)
|
1123 |
-
*
|
1124 |
-
* @return string
|
1125 |
-
* @throws Microsoft_Http_Client_Exception
|
1126 |
-
*/
|
1127 |
-
protected function _prepareBody()
|
1128 |
-
{
|
1129 |
-
// According to RFC2616, a TRACE request should not have a body.
|
1130 |
-
if ($this->method == self::TRACE) {
|
1131 |
-
return '';
|
1132 |
-
}
|
1133 |
-
|
1134 |
-
if (isset($this->raw_post_data) && is_resource($this->raw_post_data)) {
|
1135 |
-
return $this->raw_post_data;
|
1136 |
-
}
|
1137 |
-
// If mbstring overloads substr and strlen functions, we have to
|
1138 |
-
// override it's internal encoding
|
1139 |
-
if (function_exists('mb_internal_encoding') &&
|
1140 |
-
((int) ini_get('mbstring.func_overload')) & 2) {
|
1141 |
-
|
1142 |
-
$mbIntEnc = mb_internal_encoding();
|
1143 |
-
mb_internal_encoding('ASCII');
|
1144 |
-
}
|
1145 |
-
|
1146 |
-
// If we have raw_post_data set, just use it as the body.
|
1147 |
-
if (isset($this->raw_post_data)) {
|
1148 |
-
$this->setHeaders(self::CONTENT_LENGTH, strlen($this->raw_post_data));
|
1149 |
-
if (isset($mbIntEnc)) {
|
1150 |
-
mb_internal_encoding($mbIntEnc);
|
1151 |
-
}
|
1152 |
-
|
1153 |
-
return $this->raw_post_data;
|
1154 |
-
}
|
1155 |
-
|
1156 |
-
$body = '';
|
1157 |
-
|
1158 |
-
// If we have files to upload, force enctype to multipart/form-data
|
1159 |
-
if (count ($this->files) > 0) {
|
1160 |
-
$this->setEncType(self::ENC_FORMDATA);
|
1161 |
-
}
|
1162 |
-
|
1163 |
-
// If we have POST parameters or files, encode and add them to the body
|
1164 |
-
if (count($this->paramsPost) > 0 || count($this->files) > 0) {
|
1165 |
-
switch($this->enctype) {
|
1166 |
-
case self::ENC_FORMDATA:
|
1167 |
-
// Encode body as multipart/form-data
|
1168 |
-
$boundary = '---ZENDHTTPCLIENT-' . md5(microtime());
|
1169 |
-
$this->setHeaders(self::CONTENT_TYPE, self::ENC_FORMDATA . "; boundary={$boundary}");
|
1170 |
-
|
1171 |
-
// Get POST parameters and encode them
|
1172 |
-
$params = self::_flattenParametersArray($this->paramsPost);
|
1173 |
-
foreach ($params as $pp) {
|
1174 |
-
$body .= self::encodeFormData($boundary, $pp[0], $pp[1]);
|
1175 |
-
}
|
1176 |
-
|
1177 |
-
// Encode files
|
1178 |
-
foreach ($this->files as $file) {
|
1179 |
-
$fhead = array(self::CONTENT_TYPE => $file['ctype']);
|
1180 |
-
$body .= self::encodeFormData($boundary, $file['formname'], $file['data'], $file['filename'], $fhead);
|
1181 |
-
}
|
1182 |
-
|
1183 |
-
$body .= "--{$boundary}--\r\n";
|
1184 |
-
break;
|
1185 |
-
|
1186 |
-
case self::ENC_URLENCODED:
|
1187 |
-
// Encode body as application/x-www-form-urlencoded
|
1188 |
-
$this->setHeaders(self::CONTENT_TYPE, self::ENC_URLENCODED);
|
1189 |
-
$body = http_build_query($this->paramsPost, '', '&');
|
1190 |
-
break;
|
1191 |
-
|
1192 |
-
default:
|
1193 |
-
if (isset($mbIntEnc)) {
|
1194 |
-
mb_internal_encoding($mbIntEnc);
|
1195 |
-
}
|
1196 |
-
|
1197 |
-
/** @see Microsoft_Http_Client_Exception */
|
1198 |
-
require_once 'Microsoft/Http/Client/Exception.php';
|
1199 |
-
throw new Microsoft_Http_Client_Exception("Cannot handle content type '{$this->enctype}' automatically." .
|
1200 |
-
" Please use Microsoft_Http_Client::setRawData to send this kind of content.");
|
1201 |
-
break;
|
1202 |
-
}
|
1203 |
-
}
|
1204 |
-
|
1205 |
-
// Set the Content-Length if we have a body or if request is POST/PUT
|
1206 |
-
if ($body || $this->method == self::POST || $this->method == self::PUT) {
|
1207 |
-
$this->setHeaders(self::CONTENT_LENGTH, strlen($body));
|
1208 |
-
}
|
1209 |
-
|
1210 |
-
if (isset($mbIntEnc)) {
|
1211 |
-
mb_internal_encoding($mbIntEnc);
|
1212 |
-
}
|
1213 |
-
|
1214 |
-
return $body;
|
1215 |
-
}
|
1216 |
-
|
1217 |
-
/**
|
1218 |
-
* Helper method that gets a possibly multi-level parameters array (get or
|
1219 |
-
* post) and flattens it.
|
1220 |
-
*
|
1221 |
-
* The method returns an array of (key, value) pairs (because keys are not
|
1222 |
-
* necessarily unique. If one of the parameters in as array, it will also
|
1223 |
-
* add a [] suffix to the key.
|
1224 |
-
*
|
1225 |
-
* This method is deprecated since Zend Framework 1.9 in favour of
|
1226 |
-
* self::_flattenParametersArray() and will be dropped in 2.0
|
1227 |
-
*
|
1228 |
-
* @deprecated since 1.9
|
1229 |
-
*
|
1230 |
-
* @param array $parray The parameters array
|
1231 |
-
* @param bool $urlencode Whether to urlencode the name and value
|
1232 |
-
* @return array
|
1233 |
-
*/
|
1234 |
-
protected function _getParametersRecursive($parray, $urlencode = false)
|
1235 |
-
{
|
1236 |
-
// Issue a deprecated notice
|
1237 |
-
trigger_error("The " . __METHOD__ . " method is deprecated and will be dropped in 2.0.",
|
1238 |
-
E_USER_NOTICE);
|
1239 |
-
|
1240 |
-
if (! is_array($parray)) {
|
1241 |
-
return $parray;
|
1242 |
-
}
|
1243 |
-
$parameters = array();
|
1244 |
-
|
1245 |
-
foreach ($parray as $name => $value) {
|
1246 |
-
if ($urlencode) {
|
1247 |
-
$name = urlencode($name);
|
1248 |
-
}
|
1249 |
-
|
1250 |
-
// If $value is an array, iterate over it
|
1251 |
-
if (is_array($value)) {
|
1252 |
-
$name .= ($urlencode ? '%5B%5D' : '[]');
|
1253 |
-
foreach ($value as $subval) {
|
1254 |
-
if ($urlencode) {
|
1255 |
-
$subval = urlencode($subval);
|
1256 |
-
}
|
1257 |
-
$parameters[] = array($name, $subval);
|
1258 |
-
}
|
1259 |
-
} else {
|
1260 |
-
if ($urlencode) {
|
1261 |
-
$value = urlencode($value);
|
1262 |
-
}
|
1263 |
-
$parameters[] = array($name, $value);
|
1264 |
-
}
|
1265 |
-
}
|
1266 |
-
|
1267 |
-
return $parameters;
|
1268 |
-
}
|
1269 |
-
|
1270 |
-
/**
|
1271 |
-
* Attempt to detect the MIME type of a file using available extensions
|
1272 |
-
*
|
1273 |
-
* This method will try to detect the MIME type of a file. If the fileinfo
|
1274 |
-
* extension is available, it will be used. If not, the mime_magic
|
1275 |
-
* extension which is deprected but is still available in many PHP setups
|
1276 |
-
* will be tried.
|
1277 |
-
*
|
1278 |
-
* If neither extension is available, the default application/octet-stream
|
1279 |
-
* MIME type will be returned
|
1280 |
-
*
|
1281 |
-
* @param string $file File path
|
1282 |
-
* @return string MIME type
|
1283 |
-
*/
|
1284 |
-
protected function _detectFileMimeType($file)
|
1285 |
-
{
|
1286 |
-
$type = null;
|
1287 |
-
|
1288 |
-
// First try with fileinfo functions
|
1289 |
-
if (function_exists('finfo_open')) {
|
1290 |
-
if (self::$_fileInfoDb === null) {
|
1291 |
-
self::$_fileInfoDb = @finfo_open(FILEINFO_MIME);
|
1292 |
-
}
|
1293 |
-
|
1294 |
-
if (self::$_fileInfoDb) {
|
1295 |
-
$type = finfo_file(self::$_fileInfoDb, $file);
|
1296 |
-
}
|
1297 |
-
|
1298 |
-
} elseif (function_exists('mime_content_type')) {
|
1299 |
-
$type = mime_content_type($file);
|
1300 |
-
}
|
1301 |
-
|
1302 |
-
// Fallback to the default application/octet-stream
|
1303 |
-
if (! $type) {
|
1304 |
-
$type = 'application/octet-stream';
|
1305 |
-
}
|
1306 |
-
|
1307 |
-
return $type;
|
1308 |
-
}
|
1309 |
-
|
1310 |
-
/**
|
1311 |
-
* Encode data to a multipart/form-data part suitable for a POST request.
|
1312 |
-
*
|
1313 |
-
* @param string $boundary
|
1314 |
-
* @param string $name
|
1315 |
-
* @param mixed $value
|
1316 |
-
* @param string $filename
|
1317 |
-
* @param array $headers Associative array of optional headers @example ("Content-Transfer-Encoding" => "binary")
|
1318 |
-
* @return string
|
1319 |
-
*/
|
1320 |
-
public static function encodeFormData($boundary, $name, $value, $filename = null, $headers = array()) {
|
1321 |
-
$ret = "--{$boundary}\r\n" .
|
1322 |
-
'Content-Disposition: form-data; name="' . $name .'"';
|
1323 |
-
|
1324 |
-
if ($filename) {
|
1325 |
-
$ret .= '; filename="' . $filename . '"';
|
1326 |
-
}
|
1327 |
-
$ret .= "\r\n";
|
1328 |
-
|
1329 |
-
foreach ($headers as $hname => $hvalue) {
|
1330 |
-
$ret .= "{$hname}: {$hvalue}\r\n";
|
1331 |
-
}
|
1332 |
-
$ret .= "\r\n";
|
1333 |
-
|
1334 |
-
$ret .= "{$value}\r\n";
|
1335 |
-
|
1336 |
-
return $ret;
|
1337 |
-
}
|
1338 |
-
|
1339 |
-
/**
|
1340 |
-
* Create a HTTP authentication "Authorization:" header according to the
|
1341 |
-
* specified user, password and authentication method.
|
1342 |
-
*
|
1343 |
-
* @see http://www.faqs.org/rfcs/rfc2617.html
|
1344 |
-
* @param string $user
|
1345 |
-
* @param string $password
|
1346 |
-
* @param string $type
|
1347 |
-
* @return string
|
1348 |
-
* @throws Microsoft_Http_Client_Exception
|
1349 |
-
*/
|
1350 |
-
public static function encodeAuthHeader($user, $password, $type = self::AUTH_BASIC)
|
1351 |
-
{
|
1352 |
-
$authHeader = null;
|
1353 |
-
|
1354 |
-
switch ($type) {
|
1355 |
-
case self::AUTH_BASIC:
|
1356 |
-
// In basic authentication, the user name cannot contain ":"
|
1357 |
-
if (strpos($user, ':') !== false) {
|
1358 |
-
/** @see Microsoft_Http_Client_Exception */
|
1359 |
-
require_once 'Microsoft/Http/Client/Exception.php';
|
1360 |
-
throw new Microsoft_Http_Client_Exception("The user name cannot contain ':' in 'Basic' HTTP authentication");
|
1361 |
-
}
|
1362 |
-
|
1363 |
-
$authHeader = 'Basic ' . base64_encode($user . ':' . $password);
|
1364 |
-
break;
|
1365 |
-
|
1366 |
-
//case self::AUTH_DIGEST:
|
1367 |
-
/**
|
1368 |
-
* @todo Implement digest authentication
|
1369 |
-
*/
|
1370 |
-
// break;
|
1371 |
-
|
1372 |
-
default:
|
1373 |
-
/** @see Microsoft_Http_Client_Exception */
|
1374 |
-
require_once 'Microsoft/Http/Client/Exception.php';
|
1375 |
-
throw new Microsoft_Http_Client_Exception("Not a supported HTTP authentication type: '$type'");
|
1376 |
-
}
|
1377 |
-
|
1378 |
-
return $authHeader;
|
1379 |
-
}
|
1380 |
-
|
1381 |
-
/**
|
1382 |
-
* Convert an array of parameters into a flat array of (key, value) pairs
|
1383 |
-
*
|
1384 |
-
* Will flatten a potentially multi-dimentional array of parameters (such
|
1385 |
-
* as POST parameters) into a flat array of (key, value) paris. In case
|
1386 |
-
* of multi-dimentional arrays, square brackets ([]) will be added to the
|
1387 |
-
* key to indicate an array.
|
1388 |
-
*
|
1389 |
-
* @since 1.9
|
1390 |
-
*
|
1391 |
-
* @param array $parray
|
1392 |
-
* @param string $prefix
|
1393 |
-
* @return array
|
1394 |
-
*/
|
1395 |
-
static protected function _flattenParametersArray($parray, $prefix = null)
|
1396 |
-
{
|
1397 |
-
if (! is_array($parray)) {
|
1398 |
-
return $parray;
|
1399 |
-
}
|
1400 |
-
|
1401 |
-
$parameters = array();
|
1402 |
-
|
1403 |
-
foreach($parray as $name => $value) {
|
1404 |
-
|
1405 |
-
// Calculate array key
|
1406 |
-
if ($prefix) {
|
1407 |
-
if (is_int($name)) {
|
1408 |
-
$key = $prefix . '[]';
|
1409 |
-
} else {
|
1410 |
-
$key = $prefix . "[$name]";
|
1411 |
-
}
|
1412 |
-
} else {
|
1413 |
-
$key = $name;
|
1414 |
-
}
|
1415 |
-
|
1416 |
-
if (is_array($value)) {
|
1417 |
-
$parameters = array_merge($parameters, self::_flattenParametersArray($value, $key));
|
1418 |
-
|
1419 |
-
} else {
|
1420 |
-
$parameters[] = array($key, $value);
|
1421 |
-
}
|
1422 |
-
}
|
1423 |
-
|
1424 |
-
return $parameters;
|
1425 |
-
}
|
1426 |
-
|
1427 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Zend Framework
|
5 |
+
*
|
6 |
+
* LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the new BSD license that is bundled
|
9 |
+
* with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://framework.zend.com/license/new-bsd
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@zend.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category Microsoft
|
17 |
+
* @package Microsoft_Http
|
18 |
+
* @subpackage Client
|
19 |
+
* @version $Id: Client.php 19661 2009-12-15 18:03:07Z matthew $
|
20 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
21 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
22 |
+
*/
|
23 |
+
|
24 |
+
|
25 |
+
/**
|
26 |
+
* @see Microsoft_AutoLoader
|
27 |
+
*/
|
28 |
+
require_once dirname(__FILE__) . '/../AutoLoader.php';
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Microsoft_Http_Client is an implemetation of an HTTP client in PHP. The client
|
32 |
+
* supports basic features like sending different HTTP requests and handling
|
33 |
+
* redirections, as well as more advanced features like proxy settings, HTTP
|
34 |
+
* authentication and cookie persistance (using a Microsoft_Http_CookieJar object)
|
35 |
+
*
|
36 |
+
* @todo Implement proxy settings
|
37 |
+
* @category Microsoft
|
38 |
+
* @package Microsoft_Http
|
39 |
+
* @subpackage Client
|
40 |
+
* @throws Microsoft_Http_Client_Exception
|
41 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
42 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
43 |
+
*/
|
44 |
+
class Microsoft_Http_Client
|
45 |
+
{
|
46 |
+
/**
|
47 |
+
* HTTP request methods
|
48 |
+
*/
|
49 |
+
const GET = 'GET';
|
50 |
+
const POST = 'POST';
|
51 |
+
const PUT = 'PUT';
|
52 |
+
const HEAD = 'HEAD';
|
53 |
+
const DELETE = 'DELETE';
|
54 |
+
const TRACE = 'TRACE';
|
55 |
+
const OPTIONS = 'OPTIONS';
|
56 |
+
const CONNECT = 'CONNECT';
|
57 |
+
const MERGE = 'MERGE';
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Supported HTTP Authentication methods
|
61 |
+
*/
|
62 |
+
const AUTH_BASIC = 'basic';
|
63 |
+
//const AUTH_DIGEST = 'digest'; <-- not implemented yet
|
64 |
+
|
65 |
+
/**
|
66 |
+
* HTTP protocol versions
|
67 |
+
*/
|
68 |
+
const HTTP_1 = '1.1';
|
69 |
+
const HTTP_0 = '1.0';
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Content attributes
|
73 |
+
*/
|
74 |
+
const CONTENT_TYPE = 'Content-Type';
|
75 |
+
const CONTENT_LENGTH = 'Content-Length';
|
76 |
+
|
77 |
+
/**
|
78 |
+
* POST data encoding methods
|
79 |
+
*/
|
80 |
+
const ENC_URLENCODED = 'application/x-www-form-urlencoded';
|
81 |
+
const ENC_FORMDATA = 'multipart/form-data';
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Configuration array, set using the constructor or using ::setConfig()
|
85 |
+
*
|
86 |
+
* @var array
|
87 |
+
*/
|
88 |
+
protected $config = array(
|
89 |
+
'maxredirects' => 5,
|
90 |
+
'strictredirects' => false,
|
91 |
+
'useragent' => 'Microsoft_Http_Client',
|
92 |
+
'timeout' => 10,
|
93 |
+
'adapter' => 'Microsoft_Http_Client_Adapter_Socket',
|
94 |
+
'httpversion' => self::HTTP_1,
|
95 |
+
'keepalive' => false,
|
96 |
+
'storeresponse' => true,
|
97 |
+
'strict' => true,
|
98 |
+
'output_stream' => false,
|
99 |
+
);
|
100 |
+
|
101 |
+
/**
|
102 |
+
* The adapter used to preform the actual connection to the server
|
103 |
+
*
|
104 |
+
* @var Microsoft_Http_Client_Adapter_Interface
|
105 |
+
*/
|
106 |
+
protected $adapter = null;
|
107 |
+
|
108 |
+
/**
|
109 |
+
* Request URI
|
110 |
+
*
|
111 |
+
* @var Microsoft_Uri_Http
|
112 |
+
*/
|
113 |
+
protected $uri = null;
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Associative array of request headers
|
117 |
+
*
|
118 |
+
* @var array
|
119 |
+
*/
|
120 |
+
protected $headers = array();
|
121 |
+
|
122 |
+
/**
|
123 |
+
* HTTP request method
|
124 |
+
*
|
125 |
+
* @var string
|
126 |
+
*/
|
127 |
+
protected $method = self::GET;
|
128 |
+
|
129 |
+
/**
|
130 |
+
* Associative array of GET parameters
|
131 |
+
*
|
132 |
+
* @var array
|
133 |
+
*/
|
134 |
+
protected $paramsGet = array();
|
135 |
+
|
136 |
+
/**
|
137 |
+
* Assiciative array of POST parameters
|
138 |
+
*
|
139 |
+
* @var array
|
140 |
+
*/
|
141 |
+
protected $paramsPost = array();
|
142 |
+
|
143 |
+
/**
|
144 |
+
* Request body content type (for POST requests)
|
145 |
+
*
|
146 |
+
* @var string
|
147 |
+
*/
|
148 |
+
protected $enctype = null;
|
149 |
+
|
150 |
+
/**
|
151 |
+
* The raw post data to send. Could be set by setRawData($data, $enctype).
|
152 |
+
*
|
153 |
+
* @var string
|
154 |
+
*/
|
155 |
+
protected $raw_post_data = null;
|
156 |
+
|
157 |
+
/**
|
158 |
+
* HTTP Authentication settings
|
159 |
+
*
|
160 |
+
* Expected to be an associative array with this structure:
|
161 |
+
* $this->auth = array('user' => 'username', 'password' => 'password', 'type' => 'basic')
|
162 |
+
* Where 'type' should be one of the supported authentication types (see the AUTH_*
|
163 |
+
* constants), for example 'basic' or 'digest'.
|
164 |
+
*
|
165 |
+
* If null, no authentication will be used.
|
166 |
+
*
|
167 |
+
* @var array|null
|
168 |
+
*/
|
169 |
+
protected $auth;
|
170 |
+
|
171 |
+
/**
|
172 |
+
* File upload arrays (used in POST requests)
|
173 |
+
*
|
174 |
+
* An associative array, where each element is of the format:
|
175 |
+
* 'name' => array('filename.txt', 'text/plain', 'This is the actual file contents')
|
176 |
+
*
|
177 |
+
* @var array
|
178 |
+
*/
|
179 |
+
protected $files = array();
|
180 |
+
|
181 |
+
/**
|
182 |
+
* The client's cookie jar
|
183 |
+
*
|
184 |
+
* @var Microsoft_Http_CookieJar
|
185 |
+
*/
|
186 |
+
protected $cookiejar = null;
|
187 |
+
|
188 |
+
/**
|
189 |
+
* The last HTTP request sent by the client, as string
|
190 |
+
*
|
191 |
+
* @var string
|
192 |
+
*/
|
193 |
+
protected $last_request = null;
|
194 |
+
|
195 |
+
/**
|
196 |
+
* The last HTTP response received by the client
|
197 |
+
*
|
198 |
+
* @var Microsoft_Http_Response
|
199 |
+
*/
|
200 |
+
protected $last_response = null;
|
201 |
+
|
202 |
+
/**
|
203 |
+
* Redirection counter
|
204 |
+
*
|
205 |
+
* @var int
|
206 |
+
*/
|
207 |
+
protected $redirectCounter = 0;
|
208 |
+
|
209 |
+
/**
|
210 |
+
* Fileinfo magic database resource
|
211 |
+
*
|
212 |
+
* This varaiable is populated the first time _detectFileMimeType is called
|
213 |
+
* and is then reused on every call to this method
|
214 |
+
*
|
215 |
+
* @var resource
|
216 |
+
*/
|
217 |
+
static protected $_fileInfoDb = null;
|
218 |
+
|
219 |
+
/**
|
220 |
+
* Contructor method. Will create a new HTTP client. Accepts the target
|
221 |
+
* URL and optionally configuration array.
|
222 |
+
*
|
223 |
+
* @param Microsoft_Uri_Http|string $uri
|
224 |
+
* @param array $config Configuration key-value pairs.
|
225 |
+
*/
|
226 |
+
public function __construct($uri = null, $config = null)
|
227 |
+
{
|
228 |
+
if ($uri !== null) {
|
229 |
+
$this->setUri($uri);
|
230 |
+
}
|
231 |
+
if ($config !== null) {
|
232 |
+
$this->setConfig($config);
|
233 |
+
}
|
234 |
+
}
|
235 |
+
|
236 |
+
/**
|
237 |
+
* Set the URI for the next request
|
238 |
+
*
|
239 |
+
* @param Microsoft_Uri_Http|string $uri
|
240 |
+
* @return Microsoft_Http_Client
|
241 |
+
* @throws Microsoft_Http_Client_Exception
|
242 |
+
*/
|
243 |
+
public function setUri($uri)
|
244 |
+
{
|
245 |
+
if (is_string($uri)) {
|
246 |
+
$uri = Microsoft_Uri::factory($uri);
|
247 |
+
}
|
248 |
+
|
249 |
+
if (!$uri instanceof Microsoft_Uri_Http) {
|
250 |
+
/** @see Microsoft_Http_Client_Exception */
|
251 |
+
require_once 'Microsoft/Http/Client/Exception.php';
|
252 |
+
throw new Microsoft_Http_Client_Exception('Passed parameter is not a valid HTTP URI.');
|
253 |
+
}
|
254 |
+
|
255 |
+
// Set auth if username and password has been specified in the uri
|
256 |
+
if ($uri->getUsername() && $uri->getPassword()) {
|
257 |
+
$this->setAuth($uri->getUsername(), $uri->getPassword());
|
258 |
+
}
|
259 |
+
|
260 |
+
// We have no ports, set the defaults
|
261 |
+
if (! $uri->getPort()) {
|
262 |
+
$uri->setPort(($uri->getScheme() == 'https' ? 443 : 80));
|
263 |
+
}
|
264 |
+
|
265 |
+
$this->uri = $uri;
|
266 |
+
|
267 |
+
return $this;
|
268 |
+
}
|
269 |
+
|
270 |
+
/**
|
271 |
+
* Get the URI for the next request
|
272 |
+
*
|
273 |
+
* @param boolean $as_string If true, will return the URI as a string
|
274 |
+
* @return Microsoft_Uri_Http|string
|
275 |
+
*/
|
276 |
+
public function getUri($as_string = false)
|
277 |
+
{
|
278 |
+
if ($as_string && $this->uri instanceof Microsoft_Uri_Http) {
|
279 |
+
return $this->uri->__toString();
|
280 |
+
} else {
|
281 |
+
return $this->uri;
|
282 |
+
}
|
283 |
+
}
|
284 |
+
|
285 |
+
/**
|
286 |
+
* Set configuration parameters for this HTTP client
|
287 |
+
*
|
288 |
+
* @param Microsoft_Config | array $config
|
289 |
+
* @return Microsoft_Http_Client
|
290 |
+
* @throws Microsoft_Http_Client_Exception
|
291 |
+
*/
|
292 |
+
public function setConfig($config = array())
|
293 |
+
{
|
294 |
+
if ($config instanceof Microsoft_Config) {
|
295 |
+
$config = $config->toArray();
|
296 |
+
|
297 |
+
} elseif (! is_array($config)) {
|
298 |
+
/** @see Microsoft_Http_Client_Exception */
|
299 |
+
require_once 'Microsoft/Http/Client/Exception.php';
|
300 |
+
throw new Microsoft_Http_Client_Exception('Array expected, got ' . gettype($config));
|
301 |
+
}
|
302 |
+
|
303 |
+
foreach ($config as $k => $v) {
|
304 |
+
$this->config[strtolower($k)] = $v;
|
305 |
+
}
|
306 |
+
|
307 |
+
// Pass configuration options to the adapter if it exists
|
308 |
+
if ($this->adapter instanceof Microsoft_Http_Client_Adapter_Interface) {
|
309 |
+
$this->adapter->setConfig($config);
|
310 |
+
}
|
311 |
+
|
312 |
+
return $this;
|
313 |
+
}
|
314 |
+
|
315 |
+
/**
|
316 |
+
* Set the next request's method
|
317 |
+
*
|
318 |
+
* Validated the passed method and sets it. If we have files set for
|
319 |
+
* POST requests, and the new method is not POST, the files are silently
|
320 |
+
* dropped.
|
321 |
+
*
|
322 |
+
* @param string $method
|
323 |
+
* @return Microsoft_Http_Client
|
324 |
+
* @throws Microsoft_Http_Client_Exception
|
325 |
+
*/
|
326 |
+
public function setMethod($method = self::GET)
|
327 |
+
{
|
328 |
+
if (! preg_match('/^[^\x00-\x1f\x7f-\xff\(\)<>@,;:\\\\"\/\[\]\?={}\s]+$/', $method)) {
|
329 |
+
/** @see Microsoft_Http_Client_Exception */
|
330 |
+
require_once 'Microsoft/Http/Client/Exception.php';
|
331 |
+
throw new Microsoft_Http_Client_Exception("'{$method}' is not a valid HTTP request method.");
|
332 |
+
}
|
333 |
+
|
334 |
+
if ($method == self::POST && $this->enctype === null) {
|
335 |
+
$this->setEncType(self::ENC_URLENCODED);
|
336 |
+
}
|
337 |
+
|
338 |
+
$this->method = $method;
|
339 |
+
|
340 |
+
return $this;
|
341 |
+
}
|
342 |
+
|
343 |
+
/**
|
344 |
+
* Set one or more request headers
|
345 |
+
*
|
346 |
+
* This function can be used in several ways to set the client's request
|
347 |
+
* headers:
|
348 |
+
* 1. By providing two parameters: $name as the header to set (eg. 'Host')
|
349 |
+
* and $value as it's value (eg. 'www.example.com').
|
350 |
+
* 2. By providing a single header string as the only parameter
|
351 |
+
* eg. 'Host: www.example.com'
|
352 |
+
* 3. By providing an array of headers as the first parameter
|
353 |
+
* eg. array('host' => 'www.example.com', 'x-foo: bar'). In This case
|
354 |
+
* the function will call itself recursively for each array item.
|
355 |
+
*
|
356 |
+
* @param string|array $name Header name, full header string ('Header: value')
|
357 |
+
* or an array of headers
|
358 |
+
* @param mixed $value Header value or null
|
359 |
+
* @return Microsoft_Http_Client
|
360 |
+
* @throws Microsoft_Http_Client_Exception
|
361 |
+
*/
|
362 |
+
public function setHeaders($name, $value = null)
|
363 |
+
{
|
364 |
+
// If we got an array, go recusive!
|
365 |
+
if (is_array($name)) {
|
366 |
+
foreach ($name as $k => $v) {
|
367 |
+
if (is_string($k)) {
|
368 |
+
$this->setHeaders($k, $v);
|
369 |
+
} else {
|
370 |
+
$this->setHeaders($v, null);
|
371 |
+
}
|
372 |
+
}
|
373 |
+
} else {
|
374 |
+
// Check if $name needs to be split
|
375 |
+
if ($value === null && (strpos($name, ':') > 0)) {
|
376 |
+
list($name, $value) = explode(':', $name, 2);
|
377 |
+
}
|
378 |
+
|
379 |
+
// Make sure the name is valid if we are in strict mode
|
380 |
+
if ($this->config['strict'] && (! preg_match('/^[a-zA-Z0-9-]+$/', $name))) {
|
381 |
+
/** @see Microsoft_Http_Client_Exception */
|
382 |
+
require_once 'Microsoft/Http/Client/Exception.php';
|
383 |
+
throw new Microsoft_Http_Client_Exception("{$name} is not a valid HTTP header name");
|
384 |
+
}
|
385 |
+
|
386 |
+
$normalized_name = strtolower($name);
|
387 |
+
|
388 |
+
// If $value is null or false, unset the header
|
389 |
+
if ($value === null || $value === false) {
|
390 |
+
unset($this->headers[$normalized_name]);
|
391 |
+
|
392 |
+
// Else, set the header
|
393 |
+
} else {
|
394 |
+
// Header names are stored lowercase internally.
|
395 |
+
if (is_string($value)) {
|
396 |
+
$value = trim($value);
|
397 |
+
}
|
398 |
+
$this->headers[$normalized_name] = array($name, $value);
|
399 |
+
}
|
400 |
+
}
|
401 |
+
|
402 |
+
return $this;
|
403 |
+
}
|
404 |
+
|
405 |
+
/**
|
406 |
+
* Get the value of a specific header
|
407 |
+
*
|
408 |
+
* Note that if the header has more than one value, an array
|
409 |
+
* will be returned.
|
410 |
+
*
|
411 |
+
* @param string $key
|
412 |
+
* @return string|array|null The header value or null if it is not set
|
413 |
+
*/
|
414 |
+
public function getHeader($key)
|
415 |
+
{
|
416 |
+
$key = strtolower($key);
|
417 |
+
if (isset($this->headers[$key])) {
|
418 |
+
return $this->headers[$key][1];
|
419 |
+
} else {
|
420 |
+
return null;
|
421 |
+
}
|
422 |
+
}
|
423 |
+
|
424 |
+
/**
|
425 |
+
* Set a GET parameter for the request. Wrapper around _setParameter
|
426 |
+
*
|
427 |
+
* @param string|array $name
|
428 |
+
* @param string $value
|
429 |
+
* @return Microsoft_Http_Client
|
430 |
+
*/
|
431 |
+
public function setParameterGet($name, $value = null)
|
432 |
+
{
|
433 |
+
if (is_array($name)) {
|
434 |
+
foreach ($name as $k => $v)
|
435 |
+
$this->_setParameter('GET', $k, $v);
|
436 |
+
} else {
|
437 |
+
$this->_setParameter('GET', $name, $value);
|
438 |
+
}
|
439 |
+
|
440 |
+
return $this;
|
441 |
+
}
|
442 |
+
|
443 |
+
/**
|
444 |
+
* Set a POST parameter for the request. Wrapper around _setParameter
|
445 |
+
*
|
446 |
+
* @param string|array $name
|
447 |
+
* @param string $value
|
448 |
+
* @return Microsoft_Http_Client
|
449 |
+
*/
|
450 |
+
public function setParameterPost($name, $value = null)
|
451 |
+
{
|
452 |
+
if (is_array($name)) {
|
453 |
+
foreach ($name as $k => $v)
|
454 |
+
$this->_setParameter('POST', $k, $v);
|
455 |
+
} else {
|
456 |
+
$this->_setParameter('POST', $name, $value);
|
457 |
+
}
|
458 |
+
|
459 |
+
return $this;
|
460 |
+
}
|
461 |
+
|
462 |
+
/**
|
463 |
+
* Set a GET or POST parameter - used by SetParameterGet and SetParameterPost
|
464 |
+
*
|
465 |
+
* @param string $type GET or POST
|
466 |
+
* @param string $name
|
467 |
+
* @param string $value
|
468 |
+
* @return null
|
469 |
+
*/
|
470 |
+
protected function _setParameter($type, $name, $value)
|
471 |
+
{
|
472 |
+
$parray = array();
|
473 |
+
$type = strtolower($type);
|
474 |
+
switch ($type) {
|
475 |
+
case 'get':
|
476 |
+
$parray = &$this->paramsGet;
|
477 |
+
break;
|
478 |
+
case 'post':
|
479 |
+
$parray = &$this->paramsPost;
|
480 |
+
break;
|
481 |
+
}
|
482 |
+
|
483 |
+
if ($value === null) {
|
484 |
+
if (isset($parray[$name])) unset($parray[$name]);
|
485 |
+
} else {
|
486 |
+
$parray[$name] = $value;
|
487 |
+
}
|
488 |
+
}
|
489 |
+
|
490 |
+
/**
|
491 |
+
* Get the number of redirections done on the last request
|
492 |
+
*
|
493 |
+
* @return int
|
494 |
+
*/
|
495 |
+
public function getRedirectionsCount()
|
496 |
+
{
|
497 |
+
return $this->redirectCounter;
|
498 |
+
}
|
499 |
+
|
500 |
+
/**
|
501 |
+
* Set HTTP authentication parameters
|
502 |
+
*
|
503 |
+
* $type should be one of the supported types - see the self::AUTH_*
|
504 |
+
* constants.
|
505 |
+
*
|
506 |
+
* To enable authentication:
|
507 |
+
* <code>
|
508 |
+
* $this->setAuth('shahar', 'secret', Microsoft_Http_Client::AUTH_BASIC);
|
509 |
+
* </code>
|
510 |
+
*
|
511 |
+
* To disable authentication:
|
512 |
+
* <code>
|
513 |
+
* $this->setAuth(false);
|
514 |
+
* </code>
|
515 |
+
*
|
516 |
+
* @see http://www.faqs.org/rfcs/rfc2617.html
|
517 |
+
* @param string|false $user User name or false disable authentication
|
518 |
+
* @param string $password Password
|
519 |
+
* @param string $type Authentication type
|
520 |
+
* @return Microsoft_Http_Client
|
521 |
+
* @throws Microsoft_Http_Client_Exception
|
522 |
+
*/
|
523 |
+
public function setAuth($user, $password = '', $type = self::AUTH_BASIC)
|
524 |
+
{
|
525 |
+
// If we got false or null, disable authentication
|
526 |
+
if ($user === false || $user === null) {
|
527 |
+
$this->auth = null;
|
528 |
+
|
529 |
+
// Clear the auth information in the uri instance as well
|
530 |
+
if ($this->uri instanceof Microsoft_Uri_Http) {
|
531 |
+
$this->getUri()->setUsername('');
|
532 |
+
$this->getUri()->setPassword('');
|
533 |
+
}
|
534 |
+
// Else, set up authentication
|
535 |
+
} else {
|
536 |
+
// Check we got a proper authentication type
|
537 |
+
if (! defined('self::AUTH_' . strtoupper($type))) {
|
538 |
+
/** @see Microsoft_Http_Client_Exception */
|
539 |
+
require_once 'Microsoft/Http/Client/Exception.php';
|
540 |
+
throw new Microsoft_Http_Client_Exception("Invalid or not supported authentication type: '$type'");
|
541 |
+
}
|
542 |
+
|
543 |
+
$this->auth = array(
|
544 |
+
'user' => (string) $user,
|
545 |
+
'password' => (string) $password,
|
546 |
+
'type' => $type
|
547 |
+
);
|
548 |
+
}
|
549 |
+
|
550 |
+
return $this;
|
551 |
+
}
|
552 |
+
|
553 |
+
/**
|
554 |
+
* Set the HTTP client's cookie jar.
|
555 |
+
*
|
556 |
+
* A cookie jar is an object that holds and maintains cookies across HTTP requests
|
557 |
+
* and responses.
|
558 |
+
*
|
559 |
+
* @param Microsoft_Http_CookieJar|boolean $cookiejar Existing cookiejar object, true to create a new one, false to disable
|
560 |
+
* @return Microsoft_Http_Client
|
561 |
+
* @throws Microsoft_Http_Client_Exception
|
562 |
+
*/
|
563 |
+
public function setCookieJar($cookiejar = true)
|
564 |
+
{
|
565 |
+
if (! class_exists('Microsoft_Http_CookieJar')) {
|
566 |
+
require_once 'Microsoft/Http/CookieJar.php';
|
567 |
+
}
|
568 |
+
|
569 |
+
if ($cookiejar instanceof Microsoft_Http_CookieJar) {
|
570 |
+
$this->cookiejar = $cookiejar;
|
571 |
+
} elseif ($cookiejar === true) {
|
572 |
+
$this->cookiejar = new Microsoft_Http_CookieJar();
|
573 |
+
} elseif (! $cookiejar) {
|
574 |
+
$this->cookiejar = null;
|
575 |
+
} else {
|
576 |
+
/** @see Microsoft_Http_Client_Exception */
|
577 |
+
require_once 'Microsoft/Http/Client/Exception.php';
|
578 |
+
throw new Microsoft_Http_Client_Exception('Invalid parameter type passed as CookieJar');
|
579 |
+
}
|
580 |
+
|
581 |
+
return $this;
|
582 |
+
}
|
583 |
+
|
584 |
+
/**
|
585 |
+
* Return the current cookie jar or null if none.
|
586 |
+
*
|
587 |
+
* @return Microsoft_Http_CookieJar|null
|
588 |
+
*/
|
589 |
+
public function getCookieJar()
|
590 |
+
{
|
591 |
+
return $this->cookiejar;
|
592 |
+
}
|
593 |
+
|
594 |
+
/**
|
595 |
+
* Add a cookie to the request. If the client has no Cookie Jar, the cookies
|
596 |
+
* will be added directly to the headers array as "Cookie" headers.
|
597 |
+
*
|
598 |
+
* @param Microsoft_Http_Cookie|string $cookie
|
599 |
+
* @param string|null $value If "cookie" is a string, this is the cookie value.
|
600 |
+
* @return Microsoft_Http_Client
|
601 |
+
* @throws Microsoft_Http_Client_Exception
|
602 |
+
*/
|
603 |
+
public function setCookie($cookie, $value = null)
|
604 |
+
{
|
605 |
+
if (! class_exists('Microsoft_Http_Cookie')) {
|
606 |
+
require_once 'Microsoft/Http/Cookie.php';
|
607 |
+
}
|
608 |
+
|
609 |
+
if (is_array($cookie)) {
|
610 |
+
foreach ($cookie as $c => $v) {
|
611 |
+
if (is_string($c)) {
|
612 |
+
$this->setCookie($c, $v);
|
613 |
+
} else {
|
614 |
+
$this->setCookie($v);
|
615 |
+
}
|
616 |
+
}
|
617 |
+
|
618 |
+
return $this;
|
619 |
+
}
|
620 |
+
|
621 |
+
if ($value !== null) {
|
622 |
+
$value = urlencode($value);
|
623 |
+
}
|
624 |
+
|
625 |
+
if (isset($this->cookiejar)) {
|
626 |
+
if ($cookie instanceof Microsoft_Http_Cookie) {
|
627 |
+
$this->cookiejar->addCookie($cookie);
|
628 |
+
} elseif (is_string($cookie) && $value !== null) {
|
629 |
+
$cookie = Microsoft_Http_Cookie::fromString("{$cookie}={$value}", $this->uri);
|
630 |
+
$this->cookiejar->addCookie($cookie);
|
631 |
+
}
|
632 |
+
} else {
|
633 |
+
if ($cookie instanceof Microsoft_Http_Cookie) {
|
634 |
+
$name = $cookie->getName();
|
635 |
+
$value = $cookie->getValue();
|
636 |
+
$cookie = $name;
|
637 |
+
}
|
638 |
+
|
639 |
+
if (preg_match("/[=,; \t\r\n\013\014]/", $cookie)) {
|
640 |
+
/** @see Microsoft_Http_Client_Exception */
|
641 |
+
require_once 'Microsoft/Http/Client/Exception.php';
|
642 |
+
throw new Microsoft_Http_Client_Exception("Cookie name cannot contain these characters: =,; \t\r\n\013\014 ({$cookie})");
|
643 |
+
}
|
644 |
+
|
645 |
+
$value = addslashes($value);
|
646 |
+
|
647 |
+
if (! isset($this->headers['cookie'])) {
|
648 |
+
$this->headers['cookie'] = array('Cookie', '');
|
649 |
+
}
|
650 |
+
$this->headers['cookie'][1] .= $cookie . '=' . $value . '; ';
|
651 |
+
}
|
652 |
+
|
653 |
+
return $this;
|
654 |
+
}
|
655 |
+
|
656 |
+
/**
|
657 |
+
* Set a file to upload (using a POST request)
|
658 |
+
*
|
659 |
+
* Can be used in two ways:
|
660 |
+
*
|
661 |
+
* 1. $data is null (default): $filename is treated as the name if a local file which
|
662 |
+
* will be read and sent. Will try to guess the content type using mime_content_type().
|
663 |
+
* 2. $data is set - $filename is sent as the file name, but $data is sent as the file
|
664 |
+
* contents and no file is read from the file system. In this case, you need to
|
665 |
+
* manually set the Content-Type ($ctype) or it will default to
|
666 |
+
* application/octet-stream.
|
667 |
+
*
|
668 |
+
* @param string $filename Name of file to upload, or name to save as
|
669 |
+
* @param string $formname Name of form element to send as
|
670 |
+
* @param string $data Data to send (if null, $filename is read and sent)
|
671 |
+
* @param string $ctype Content type to use (if $data is set and $ctype is
|
672 |
+
* null, will be application/octet-stream)
|
673 |
+
* @return Microsoft_Http_Client
|
674 |
+
* @throws Microsoft_Http_Client_Exception
|
675 |
+
*/
|
676 |
+
public function setFileUpload($filename, $formname, $data = null, $ctype = null)
|
677 |
+
{
|
678 |
+
if ($data === null) {
|
679 |
+
if (($data = @file_get_contents($filename)) === false) {
|
680 |
+
/** @see Microsoft_Http_Client_Exception */
|
681 |
+
require_once 'Microsoft/Http/Client/Exception.php';
|
682 |
+
throw new Microsoft_Http_Client_Exception("Unable to read file '{$filename}' for upload");
|
683 |
+
}
|
684 |
+
|
685 |
+
if (! $ctype) {
|
686 |
+
$ctype = $this->_detectFileMimeType($filename);
|
687 |
+
}
|
688 |
+
}
|
689 |
+
|
690 |
+
// Force enctype to multipart/form-data
|
691 |
+
$this->setEncType(self::ENC_FORMDATA);
|
692 |
+
|
693 |
+
$this->files[] = array(
|
694 |
+
'formname' => $formname,
|
695 |
+
'filename' => basename($filename),
|
696 |
+
'ctype' => $ctype,
|
697 |
+
'data' => $data
|
698 |
+
);
|
699 |
+
|
700 |
+
return $this;
|
701 |
+
}
|
702 |
+
|
703 |
+
/**
|
704 |
+
* Set the encoding type for POST data
|
705 |
+
*
|
706 |
+
* @param string $enctype
|
707 |
+
* @return Microsoft_Http_Client
|
708 |
+
*/
|
709 |
+
public function setEncType($enctype = self::ENC_URLENCODED)
|
710 |
+
{
|
711 |
+
$this->enctype = $enctype;
|
712 |
+
|
713 |
+
return $this;
|
714 |
+
}
|
715 |
+
|
716 |
+
/**
|
717 |
+
* Set the raw (already encoded) POST data.
|
718 |
+
*
|
719 |
+
* This function is here for two reasons:
|
720 |
+
* 1. For advanced user who would like to set their own data, already encoded
|
721 |
+
* 2. For backwards compatibilty: If someone uses the old post($data) method.
|
722 |
+
* this method will be used to set the encoded data.
|
723 |
+
*
|
724 |
+
* $data can also be stream (such as file) from which the data will be read.
|
725 |
+
*
|
726 |
+
* @param string|resource $data
|
727 |
+
* @param string $enctype
|
728 |
+
* @return Microsoft_Http_Client
|
729 |
+
*/
|
730 |
+
public function setRawData($data, $enctype = null)
|
731 |
+
{
|
732 |
+
$this->raw_post_data = $data;
|
733 |
+
$this->setEncType($enctype);
|
734 |
+
if (is_resource($data)) {
|
735 |
+
// We've got stream data
|
736 |
+
$stat = @fstat($data);
|
737 |
+
if($stat) {
|
738 |
+
$this->setHeaders(self::CONTENT_LENGTH, $stat['size']);
|
739 |
+
}
|
740 |
+
}
|
741 |
+
return $this;
|
742 |
+
}
|
743 |
+
|
744 |
+
/**
|
745 |
+
* Clear all GET and POST parameters
|
746 |
+
*
|
747 |
+
* Should be used to reset the request parameters if the client is
|
748 |
+
* used for several concurrent requests.
|
749 |
+
*
|
750 |
+
* clearAll parameter controls if we clean just parameters or also
|
751 |
+
* headers and last_*
|
752 |
+
*
|
753 |
+
* @param bool $clearAll Should all data be cleared?
|
754 |
+
* @return Microsoft_Http_Client
|
755 |
+
*/
|
756 |
+
public function resetParameters($clearAll = false)
|
757 |
+
{
|
758 |
+
// Reset parameter data
|
759 |
+
$this->paramsGet = array();
|
760 |
+
$this->paramsPost = array();
|
761 |
+
$this->files = array();
|
762 |
+
$this->raw_post_data = null;
|
763 |
+
|
764 |
+
if($clearAll) {
|
765 |
+
$this->headers = array();
|
766 |
+
$this->last_request = null;
|
767 |
+
$this->last_response = null;
|
768 |
+
} else {
|
769 |
+
// Clear outdated headers
|
770 |
+
if (isset($this->headers[strtolower(self::CONTENT_TYPE)])) {
|
771 |
+
unset($this->headers[strtolower(self::CONTENT_TYPE)]);
|
772 |
+
}
|
773 |
+
if (isset($this->headers[strtolower(self::CONTENT_LENGTH)])) {
|
774 |
+
unset($this->headers[strtolower(self::CONTENT_LENGTH)]);
|
775 |
+
}
|
776 |
+
}
|
777 |
+
|
778 |
+
return $this;
|
779 |
+
}
|
780 |
+
|
781 |
+
/**
|
782 |
+
* Get the last HTTP request as string
|
783 |
+
*
|
784 |
+
* @return string
|
785 |
+
*/
|
786 |
+
public function getLastRequest()
|
787 |
+
{
|
788 |
+
return $this->last_request;
|
789 |
+
}
|
790 |
+
|
791 |
+
/**
|
792 |
+
* Get the last HTTP response received by this client
|
793 |
+
*
|
794 |
+
* If $config['storeresponse'] is set to false, or no response was
|
795 |
+
* stored yet, will return null
|
796 |
+
*
|
797 |
+
* @return Microsoft_Http_Response or null if none
|
798 |
+
*/
|
799 |
+
public function getLastResponse()
|
800 |
+
{
|
801 |
+
return $this->last_response;
|
802 |
+
}
|
803 |
+
|
804 |
+
/**
|
805 |
+
* Load the connection adapter
|
806 |
+
*
|
807 |
+
* While this method is not called more than one for a client, it is
|
808 |
+
* seperated from ->request() to preserve logic and readability
|
809 |
+
*
|
810 |
+
* @param Microsoft_Http_Client_Adapter_Interface|string $adapter
|
811 |
+
* @return null
|
812 |
+
* @throws Microsoft_Http_Client_Exception
|
813 |
+
*/
|
814 |
+
public function setAdapter($adapter)
|
815 |
+
{
|
816 |
+
if (is_string($adapter)) {
|
817 |
+
if (!class_exists($adapter)) {
|
818 |
+
@require_once( str_replace('_', '/', $adapter) . '.php' );
|
819 |
+
}
|
820 |
+
|
821 |
+
$adapter = new $adapter;
|
822 |
+
}
|
823 |
+
|
824 |
+
if (! $adapter instanceof Microsoft_Http_Client_Adapter_Interface) {
|
825 |
+
/** @see Microsoft_Http_Client_Exception */
|
826 |
+
require_once 'Microsoft/Http/Client/Exception.php';
|
827 |
+
throw new Microsoft_Http_Client_Exception('Passed adapter is not a HTTP connection adapter');
|
828 |
+
}
|
829 |
+
|
830 |
+
$this->adapter = $adapter;
|
831 |
+
$config = $this->config;
|
832 |
+
unset($config['adapter']);
|
833 |
+
$this->adapter->setConfig($config);
|
834 |
+
}
|
835 |
+
|
836 |
+
/**
|
837 |
+
* Load the connection adapter
|
838 |
+
*
|
839 |
+
* @return Microsoft_Http_Client_Adapter_Interface $adapter
|
840 |
+
*/
|
841 |
+
public function getAdapter()
|
842 |
+
{
|
843 |
+
return $this->adapter;
|
844 |
+
}
|
845 |
+
|
846 |
+
/**
|
847 |
+
* Set streaming for received data
|
848 |
+
*
|
849 |
+
* @param string|boolean $streamfile Stream file, true for temp file, false/null for no streaming
|
850 |
+
* @return Microsoft_Http_Client
|
851 |
+
*/
|
852 |
+
public function setStream($streamfile = true)
|
853 |
+
{
|
854 |
+
$this->setConfig(array("output_stream" => $streamfile));
|
855 |
+
return $this;
|
856 |
+
}
|
857 |
+
|
858 |
+
/**
|
859 |
+
* Get status of streaming for received data
|
860 |
+
* @return boolean|string
|
861 |
+
*/
|
862 |
+
public function getStream()
|
863 |
+
{
|
864 |
+
return $this->config["output_stream"];
|
865 |
+
}
|
866 |
+
|
867 |
+
/**
|
868 |
+
* Create temporary stream
|
869 |
+
*
|
870 |
+
* @return resource
|
871 |
+
*/
|
872 |
+
protected function _openTempStream()
|
873 |
+
{
|
874 |
+
$this->_stream_name = $this->config['output_stream'];
|
875 |
+
if(!is_string($this->_stream_name)) {
|
876 |
+
// If name is not given, create temp name
|
877 |
+
$this->_stream_name = tempnam(isset($this->config['stream_tmp_dir'])?$this->config['stream_tmp_dir']:sys_get_temp_dir(),
|
878 |
+
'Microsoft_Http_Client');
|
879 |
+
}
|
880 |
+
|
881 |
+
$fp = fopen($this->_stream_name, "w+b");
|
882 |
+
if(!$fp) {
|
883 |
+
$this->close();
|
884 |
+
require_once 'Microsoft/Http/Client/Exception.php';
|
885 |
+
throw new Microsoft_Http_Client_Exception("Could not open temp file $name");
|
886 |
+
|
887 |
+
}
|
888 |
+
return $fp;
|
889 |
+
}
|
890 |
+
|
891 |
+
/**
|
892 |
+
* Send the HTTP request and return an HTTP response object
|
893 |
+
*
|
894 |
+
* @param string $method
|
895 |
+
* @return Microsoft_Http_Response
|
896 |
+
* @throws Microsoft_Http_Client_Exception
|
897 |
+
*/
|
898 |
+
public function request($method = null)
|
899 |
+
{
|
900 |
+
if (! $this->uri instanceof Microsoft_Uri_Http) {
|
901 |
+
/** @see Microsoft_Http_Client_Exception */
|
902 |
+
require_once 'Microsoft/Http/Client/Exception.php';
|
903 |
+
throw new Microsoft_Http_Client_Exception('No valid URI has been passed to the client');
|
904 |
+
}
|
905 |
+
|
906 |
+
if ($method) {
|
907 |
+
$this->setMethod($method);
|
908 |
+
}
|
909 |
+
$this->redirectCounter = 0;
|
910 |
+
$response = null;
|
911 |
+
|
912 |
+
// Make sure the adapter is loaded
|
913 |
+
if ($this->adapter == null) {
|
914 |
+
$this->setAdapter($this->config['adapter']);
|
915 |
+
}
|
916 |
+
|
917 |
+
// Send the first request. If redirected, continue.
|
918 |
+
do {
|
919 |
+
// Clone the URI and add the additional GET parameters to it
|
920 |
+
$uri = clone $this->uri;
|
921 |
+
if (! empty($this->paramsGet)) {
|
922 |
+
$query = $uri->getQuery();
|
923 |
+
if (! empty($query)) {
|
924 |
+
$query .= '&';
|
925 |
+
}
|
926 |
+
$query .= http_build_query($this->paramsGet, null, '&');
|
927 |
+
|
928 |
+
$uri->setQuery($query);
|
929 |
+
}
|
930 |
+
|
931 |
+
$body = $this->_prepareBody();
|
932 |
+
$headers = $this->_prepareHeaders();
|
933 |
+
|
934 |
+
// check that adapter supports streaming before using it
|
935 |
+
if(is_resource($body) && !($this->adapter instanceof Microsoft_Http_Client_Adapter_Stream)) {
|
936 |
+
/** @see Microsoft_Http_Client_Exception */
|
937 |
+
require_once 'Microsoft/Http/Client/Exception.php';
|
938 |
+
throw new Microsoft_Http_Client_Exception('Adapter does not support streaming');
|
939 |
+
}
|
940 |
+
|
941 |
+
// Open the connection, send the request and read the response
|
942 |
+
$this->adapter->connect($uri->getHost(), $uri->getPort(),
|
943 |
+
($uri->getScheme() == 'https' ? true : false));
|
944 |
+
|
945 |
+
if($this->config['output_stream']) {
|
946 |
+
if($this->adapter instanceof Microsoft_Http_Client_Adapter_Stream) {
|
947 |
+
$stream = $this->_openTempStream();
|
948 |
+
$this->adapter->setOutputStream($stream);
|
949 |
+
} else {
|
950 |
+
/** @see Microsoft_Http_Client_Exception */
|
951 |
+
require_once 'Microsoft/Http/Client/Exception.php';
|
952 |
+
throw new Microsoft_Http_Client_Exception('Adapter does not support streaming');
|
953 |
+
}
|
954 |
+
}
|
955 |
+
|
956 |
+
$this->last_request = $this->adapter->write($this->method,
|
957 |
+
$uri, $this->config['httpversion'], $headers, $body);
|
958 |
+
|
959 |
+
$response = $this->adapter->read();
|
960 |
+
if (! $response) {
|
961 |
+
/** @see Microsoft_Http_Client_Exception */
|
962 |
+
require_once 'Microsoft/Http/Client/Exception.php';
|
963 |
+
throw new Microsoft_Http_Client_Exception('Unable to read response, or response is empty');
|
964 |
+
}
|
965 |
+
|
966 |
+
if($this->config['output_stream']) {
|
967 |
+
rewind($stream);
|
968 |
+
// cleanup the adapter
|
969 |
+
$this->adapter->setOutputStream(null);
|
970 |
+
$response = Microsoft_Http_Response_Stream::fromStream($response, $stream);
|
971 |
+
$response->setStreamName($this->_stream_name);
|
972 |
+
if(!is_string($this->config['output_stream'])) {
|
973 |
+
// we used temp name, will need to clean up
|
974 |
+
$response->setCleanup(true);
|
975 |
+
}
|
976 |
+
} else {
|
977 |
+
$response = Microsoft_Http_Response::fromString($response);
|
978 |
+
}
|
979 |
+
|
980 |
+
if ($this->config['storeresponse']) {
|
981 |
+
$this->last_response = $response;
|
982 |
+
}
|
983 |
+
|
984 |
+
// Load cookies into cookie jar
|
985 |
+
if (isset($this->cookiejar)) {
|
986 |
+
$this->cookiejar->addCookiesFromResponse($response, $uri);
|
987 |
+
}
|
988 |
+
|
989 |
+
// If we got redirected, look for the Location header
|
990 |
+
if ($response->isRedirect() && ($location = $response->getHeader('location'))) {
|
991 |
+
|
992 |
+
// Check whether we send the exact same request again, or drop the parameters
|
993 |
+
// and send a GET request
|
994 |
+
if ($response->getStatus() == 303 ||
|
995 |
+
((! $this->config['strictredirects']) && ($response->getStatus() == 302 ||
|
996 |
+
$response->getStatus() == 301))) {
|
997 |
+
|
998 |
+
$this->resetParameters();
|
999 |
+
$this->setMethod(self::GET);
|
1000 |
+
}
|
1001 |
+
|
1002 |
+
// If we got a well formed absolute URI
|
1003 |
+
if (Microsoft_Uri_Http::check($location)) {
|
1004 |
+
$this->setHeaders('host', null);
|
1005 |
+
$this->setUri($location);
|
1006 |
+
|
1007 |
+
} else {
|
1008 |
+
|
1009 |
+
// Split into path and query and set the query
|
1010 |
+
if (strpos($location, '?') !== false) {
|
1011 |
+
list($location, $query) = explode('?', $location, 2);
|
1012 |
+
} else {
|
1013 |
+
$query = '';
|
1014 |
+
}
|
1015 |
+
$this->uri->setQuery($query);
|
1016 |
+
|
1017 |
+
// Else, if we got just an absolute path, set it
|
1018 |
+
if(strpos($location, '/') === 0) {
|
1019 |
+
$this->uri->setPath($location);
|
1020 |
+
|
1021 |
+
// Else, assume we have a relative path
|
1022 |
+
} else {
|
1023 |
+
// Get the current path directory, removing any trailing slashes
|
1024 |
+
$path = $this->uri->getPath();
|
1025 |
+
$path = rtrim(substr($path, 0, strrpos($path, '/')), "/");
|
1026 |
+
$this->uri->setPath($path . '/' . $location);
|
1027 |
+
}
|
1028 |
+
}
|
1029 |
+
++$this->redirectCounter;
|
1030 |
+
|
1031 |
+
} else {
|
1032 |
+
// If we didn't get any location, stop redirecting
|
1033 |
+
break;
|
1034 |
+
}
|
1035 |
+
|
1036 |
+
} while ($this->redirectCounter < $this->config['maxredirects']);
|
1037 |
+
|
1038 |
+
return $response;
|
1039 |
+
}
|
1040 |
+
|
1041 |
+
/**
|
1042 |
+
* Prepare the request headers
|
1043 |
+
*
|
1044 |
+
* @return array
|
1045 |
+
*/
|
1046 |
+
protected function _prepareHeaders()
|
1047 |
+
{
|
1048 |
+
$headers = array();
|
1049 |
+
|
1050 |
+
// Set the host header
|
1051 |
+
if (! isset($this->headers['host'])) {
|
1052 |
+
$host = $this->uri->getHost();
|
1053 |
+
|
1054 |
+
// If the port is not default, add it
|
1055 |
+
if (! (($this->uri->getScheme() == 'http' && $this->uri->getPort() == 80) ||
|
1056 |
+
($this->uri->getScheme() == 'https' && $this->uri->getPort() == 443))) {
|
1057 |
+
$host .= ':' . $this->uri->getPort();
|
1058 |
+
}
|
1059 |
+
|
1060 |
+
$headers[] = "Host: {$host}";
|
1061 |
+
}
|
1062 |
+
|
1063 |
+
// Set the connection header
|
1064 |
+
if (! isset($this->headers['connection'])) {
|
1065 |
+
if (! $this->config['keepalive']) {
|
1066 |
+
$headers[] = "Connection: close";
|
1067 |
+
}
|
1068 |
+
}
|
1069 |
+
|
1070 |
+
// Set the Accept-encoding header if not set - depending on whether
|
1071 |
+
// zlib is available or not.
|
1072 |
+
if (! isset($this->headers['accept-encoding'])) {
|
1073 |
+
if (function_exists('gzinflate')) {
|
1074 |
+
$headers[] = 'Accept-encoding: gzip, deflate';
|
1075 |
+
} else {
|
1076 |
+
$headers[] = 'Accept-encoding: identity';
|
1077 |
+
}
|
1078 |
+
}
|
1079 |
+
|
1080 |
+
// Set the Content-Type header
|
1081 |
+
if ($this->method == self::POST &&
|
1082 |
+
(! isset($this->headers[strtolower(self::CONTENT_TYPE)]) && isset($this->enctype))) {
|
1083 |
+
|
1084 |
+
$headers[] = self::CONTENT_TYPE . ': ' . $this->enctype;
|
1085 |
+
}
|
1086 |
+
|
1087 |
+
// Set the user agent header
|
1088 |
+
if (! isset($this->headers['user-agent']) && isset($this->config['useragent'])) {
|
1089 |
+
$headers[] = "User-Agent: {$this->config['useragent']}";
|
1090 |
+
}
|
1091 |
+
|
1092 |
+
// Set HTTP authentication if needed
|
1093 |
+
if (is_array($this->auth)) {
|
1094 |
+
$auth = self::encodeAuthHeader($this->auth['user'], $this->auth['password'], $this->auth['type']);
|
1095 |
+
$headers[] = "Authorization: {$auth}";
|
1096 |
+
}
|
1097 |
+
|
1098 |
+
// Load cookies from cookie jar
|
1099 |
+
if (isset($this->cookiejar)) {
|
1100 |
+
$cookstr = $this->cookiejar->getMatchingCookies($this->uri,
|
1101 |
+
true, Microsoft_Http_CookieJar::COOKIE_STRING_CONCAT);
|
1102 |
+
|
1103 |
+
if ($cookstr) {
|
1104 |
+
$headers[] = "Cookie: {$cookstr}";
|
1105 |
+
}
|
1106 |
+
}
|
1107 |
+
|
1108 |
+
// Add all other user defined headers
|
1109 |
+
foreach ($this->headers as $header) {
|
1110 |
+
list($name, $value) = $header;
|
1111 |
+
if (is_array($value)) {
|
1112 |
+
$value = implode(', ', $value);
|
1113 |
+
}
|
1114 |
+
|
1115 |
+
$headers[] = "$name: $value";
|
1116 |
+
}
|
1117 |
+
|
1118 |
+
return $headers;
|
1119 |
+
}
|
1120 |
+
|
1121 |
+
/**
|
1122 |
+
* Prepare the request body (for POST and PUT requests)
|
1123 |
+
*
|
1124 |
+
* @return string
|
1125 |
+
* @throws Microsoft_Http_Client_Exception
|
1126 |
+
*/
|
1127 |
+
protected function _prepareBody()
|
1128 |
+
{
|
1129 |
+
// According to RFC2616, a TRACE request should not have a body.
|
1130 |
+
if ($this->method == self::TRACE) {
|
1131 |
+
return '';
|
1132 |
+
}
|
1133 |
+
|
1134 |
+
if (isset($this->raw_post_data) && is_resource($this->raw_post_data)) {
|
1135 |
+
return $this->raw_post_data;
|
1136 |
+
}
|
1137 |
+
// If mbstring overloads substr and strlen functions, we have to
|
1138 |
+
// override it's internal encoding
|
1139 |
+
if (function_exists('mb_internal_encoding') &&
|
1140 |
+
((int) ini_get('mbstring.func_overload')) & 2) {
|
1141 |
+
|
1142 |
+
$mbIntEnc = mb_internal_encoding();
|
1143 |
+
mb_internal_encoding('ASCII');
|
1144 |
+
}
|
1145 |
+
|
1146 |
+
// If we have raw_post_data set, just use it as the body.
|
1147 |
+
if (isset($this->raw_post_data)) {
|
1148 |
+
$this->setHeaders(self::CONTENT_LENGTH, strlen($this->raw_post_data));
|
1149 |
+
if (isset($mbIntEnc)) {
|
1150 |
+
mb_internal_encoding($mbIntEnc);
|
1151 |
+
}
|
1152 |
+
|
1153 |
+
return $this->raw_post_data;
|
1154 |
+
}
|
1155 |
+
|
1156 |
+
$body = '';
|
1157 |
+
|
1158 |
+
// If we have files to upload, force enctype to multipart/form-data
|
1159 |
+
if (count ($this->files) > 0) {
|
1160 |
+
$this->setEncType(self::ENC_FORMDATA);
|
1161 |
+
}
|
1162 |
+
|
1163 |
+
// If we have POST parameters or files, encode and add them to the body
|
1164 |
+
if (count($this->paramsPost) > 0 || count($this->files) > 0) {
|
1165 |
+
switch($this->enctype) {
|
1166 |
+
case self::ENC_FORMDATA:
|
1167 |
+
// Encode body as multipart/form-data
|
1168 |
+
$boundary = '---ZENDHTTPCLIENT-' . md5(microtime());
|
1169 |
+
$this->setHeaders(self::CONTENT_TYPE, self::ENC_FORMDATA . "; boundary={$boundary}");
|
1170 |
+
|
1171 |
+
// Get POST parameters and encode them
|
1172 |
+
$params = self::_flattenParametersArray($this->paramsPost);
|
1173 |
+
foreach ($params as $pp) {
|
1174 |
+
$body .= self::encodeFormData($boundary, $pp[0], $pp[1]);
|
1175 |
+
}
|
1176 |
+
|
1177 |
+
// Encode files
|
1178 |
+
foreach ($this->files as $file) {
|
1179 |
+
$fhead = array(self::CONTENT_TYPE => $file['ctype']);
|
1180 |
+
$body .= self::encodeFormData($boundary, $file['formname'], $file['data'], $file['filename'], $fhead);
|
1181 |
+
}
|
1182 |
+
|
1183 |
+
$body .= "--{$boundary}--\r\n";
|
1184 |
+
break;
|
1185 |
+
|
1186 |
+
case self::ENC_URLENCODED:
|
1187 |
+
// Encode body as application/x-www-form-urlencoded
|
1188 |
+
$this->setHeaders(self::CONTENT_TYPE, self::ENC_URLENCODED);
|
1189 |
+
$body = http_build_query($this->paramsPost, '', '&');
|
1190 |
+
break;
|
1191 |
+
|
1192 |
+
default:
|
1193 |
+
if (isset($mbIntEnc)) {
|
1194 |
+
mb_internal_encoding($mbIntEnc);
|
1195 |
+
}
|
1196 |
+
|
1197 |
+
/** @see Microsoft_Http_Client_Exception */
|
1198 |
+
require_once 'Microsoft/Http/Client/Exception.php';
|
1199 |
+
throw new Microsoft_Http_Client_Exception("Cannot handle content type '{$this->enctype}' automatically." .
|
1200 |
+
" Please use Microsoft_Http_Client::setRawData to send this kind of content.");
|
1201 |
+
break;
|
1202 |
+
}
|
1203 |
+
}
|
1204 |
+
|
1205 |
+
// Set the Content-Length if we have a body or if request is POST/PUT
|
1206 |
+
if ($body || $this->method == self::POST || $this->method == self::PUT) {
|
1207 |
+
$this->setHeaders(self::CONTENT_LENGTH, strlen($body));
|
1208 |
+
}
|
1209 |
+
|
1210 |
+
if (isset($mbIntEnc)) {
|
1211 |
+
mb_internal_encoding($mbIntEnc);
|
1212 |
+
}
|
1213 |
+
|
1214 |
+
return $body;
|
1215 |
+
}
|
1216 |
+
|
1217 |
+
/**
|
1218 |
+
* Helper method that gets a possibly multi-level parameters array (get or
|
1219 |
+
* post) and flattens it.
|
1220 |
+
*
|
1221 |
+
* The method returns an array of (key, value) pairs (because keys are not
|
1222 |
+
* necessarily unique. If one of the parameters in as array, it will also
|
1223 |
+
* add a [] suffix to the key.
|
1224 |
+
*
|
1225 |
+
* This method is deprecated since Zend Framework 1.9 in favour of
|
1226 |
+
* self::_flattenParametersArray() and will be dropped in 2.0
|
1227 |
+
*
|
1228 |
+
* @deprecated since 1.9
|
1229 |
+
*
|
1230 |
+
* @param array $parray The parameters array
|
1231 |
+
* @param bool $urlencode Whether to urlencode the name and value
|
1232 |
+
* @return array
|
1233 |
+
*/
|
1234 |
+
protected function _getParametersRecursive($parray, $urlencode = false)
|
1235 |
+
{
|
1236 |
+
// Issue a deprecated notice
|
1237 |
+
trigger_error("The " . __METHOD__ . " method is deprecated and will be dropped in 2.0.",
|
1238 |
+
E_USER_NOTICE);
|
1239 |
+
|
1240 |
+
if (! is_array($parray)) {
|
1241 |
+
return $parray;
|
1242 |
+
}
|
1243 |
+
$parameters = array();
|
1244 |
+
|
1245 |
+
foreach ($parray as $name => $value) {
|
1246 |
+
if ($urlencode) {
|
1247 |
+
$name = urlencode($name);
|
1248 |
+
}
|
1249 |
+
|
1250 |
+
// If $value is an array, iterate over it
|
1251 |
+
if (is_array($value)) {
|
1252 |
+
$name .= ($urlencode ? '%5B%5D' : '[]');
|
1253 |
+
foreach ($value as $subval) {
|
1254 |
+
if ($urlencode) {
|
1255 |
+
$subval = urlencode($subval);
|
1256 |
+
}
|
1257 |
+
$parameters[] = array($name, $subval);
|
1258 |
+
}
|
1259 |
+
} else {
|
1260 |
+
if ($urlencode) {
|
1261 |
+
$value = urlencode($value);
|
1262 |
+
}
|
1263 |
+
$parameters[] = array($name, $value);
|
1264 |
+
}
|
1265 |
+
}
|
1266 |
+
|
1267 |
+
return $parameters;
|
1268 |
+
}
|
1269 |
+
|
1270 |
+
/**
|
1271 |
+
* Attempt to detect the MIME type of a file using available extensions
|
1272 |
+
*
|
1273 |
+
* This method will try to detect the MIME type of a file. If the fileinfo
|
1274 |
+
* extension is available, it will be used. If not, the mime_magic
|
1275 |
+
* extension which is deprected but is still available in many PHP setups
|
1276 |
+
* will be tried.
|
1277 |
+
*
|
1278 |
+
* If neither extension is available, the default application/octet-stream
|
1279 |
+
* MIME type will be returned
|
1280 |
+
*
|
1281 |
+
* @param string $file File path
|
1282 |
+
* @return string MIME type
|
1283 |
+
*/
|
1284 |
+
protected function _detectFileMimeType($file)
|
1285 |
+
{
|
1286 |
+
$type = null;
|
1287 |
+
|
1288 |
+
// First try with fileinfo functions
|
1289 |
+
if (function_exists('finfo_open')) {
|
1290 |
+
if (self::$_fileInfoDb === null) {
|
1291 |
+
self::$_fileInfoDb = @finfo_open(FILEINFO_MIME);
|
1292 |
+
}
|
1293 |
+
|
1294 |
+
if (self::$_fileInfoDb) {
|
1295 |
+
$type = finfo_file(self::$_fileInfoDb, $file);
|
1296 |
+
}
|
1297 |
+
|
1298 |
+
} elseif (function_exists('mime_content_type')) {
|
1299 |
+
$type = mime_content_type($file);
|
1300 |
+
}
|
1301 |
+
|
1302 |
+
// Fallback to the default application/octet-stream
|
1303 |
+
if (! $type) {
|
1304 |
+
$type = 'application/octet-stream';
|
1305 |
+
}
|
1306 |
+
|
1307 |
+
return $type;
|
1308 |
+
}
|
1309 |
+
|
1310 |
+
/**
|
1311 |
+
* Encode data to a multipart/form-data part suitable for a POST request.
|
1312 |
+
*
|
1313 |
+
* @param string $boundary
|
1314 |
+
* @param string $name
|
1315 |
+
* @param mixed $value
|
1316 |
+
* @param string $filename
|
1317 |
+
* @param array $headers Associative array of optional headers @example ("Content-Transfer-Encoding" => "binary")
|
1318 |
+
* @return string
|
1319 |
+
*/
|
1320 |
+
public static function encodeFormData($boundary, $name, $value, $filename = null, $headers = array()) {
|
1321 |
+
$ret = "--{$boundary}\r\n" .
|
1322 |
+
'Content-Disposition: form-data; name="' . $name .'"';
|
1323 |
+
|
1324 |
+
if ($filename) {
|
1325 |
+
$ret .= '; filename="' . $filename . '"';
|
1326 |
+
}
|
1327 |
+
$ret .= "\r\n";
|
1328 |
+
|
1329 |
+
foreach ($headers as $hname => $hvalue) {
|
1330 |
+
$ret .= "{$hname}: {$hvalue}\r\n";
|
1331 |
+
}
|
1332 |
+
$ret .= "\r\n";
|
1333 |
+
|
1334 |
+
$ret .= "{$value}\r\n";
|
1335 |
+
|
1336 |
+
return $ret;
|
1337 |
+
}
|
1338 |
+
|
1339 |
+
/**
|
1340 |
+
* Create a HTTP authentication "Authorization:" header according to the
|
1341 |
+
* specified user, password and authentication method.
|
1342 |
+
*
|
1343 |
+
* @see http://www.faqs.org/rfcs/rfc2617.html
|
1344 |
+
* @param string $user
|
1345 |
+
* @param string $password
|
1346 |
+
* @param string $type
|
1347 |
+
* @return string
|
1348 |
+
* @throws Microsoft_Http_Client_Exception
|
1349 |
+
*/
|
1350 |
+
public static function encodeAuthHeader($user, $password, $type = self::AUTH_BASIC)
|
1351 |
+
{
|
1352 |
+
$authHeader = null;
|
1353 |
+
|
1354 |
+
switch ($type) {
|
1355 |
+
case self::AUTH_BASIC:
|
1356 |
+
// In basic authentication, the user name cannot contain ":"
|
1357 |
+
if (strpos($user, ':') !== false) {
|
1358 |
+
/** @see Microsoft_Http_Client_Exception */
|
1359 |
+
require_once 'Microsoft/Http/Client/Exception.php';
|
1360 |
+
throw new Microsoft_Http_Client_Exception("The user name cannot contain ':' in 'Basic' HTTP authentication");
|
1361 |
+
}
|
1362 |
+
|
1363 |
+
$authHeader = 'Basic ' . base64_encode($user . ':' . $password);
|
1364 |
+
break;
|
1365 |
+
|
1366 |
+
//case self::AUTH_DIGEST:
|
1367 |
+
/**
|
1368 |
+
* @todo Implement digest authentication
|
1369 |
+
*/
|
1370 |
+
// break;
|
1371 |
+
|
1372 |
+
default:
|
1373 |
+
/** @see Microsoft_Http_Client_Exception */
|
1374 |
+
require_once 'Microsoft/Http/Client/Exception.php';
|
1375 |
+
throw new Microsoft_Http_Client_Exception("Not a supported HTTP authentication type: '$type'");
|
1376 |
+
}
|
1377 |
+
|
1378 |
+
return $authHeader;
|
1379 |
+
}
|
1380 |
+
|
1381 |
+
/**
|
1382 |
+
* Convert an array of parameters into a flat array of (key, value) pairs
|
1383 |
+
*
|
1384 |
+
* Will flatten a potentially multi-dimentional array of parameters (such
|
1385 |
+
* as POST parameters) into a flat array of (key, value) paris. In case
|
1386 |
+
* of multi-dimentional arrays, square brackets ([]) will be added to the
|
1387 |
+
* key to indicate an array.
|
1388 |
+
*
|
1389 |
+
* @since 1.9
|
1390 |
+
*
|
1391 |
+
* @param array $parray
|
1392 |
+
* @param string $prefix
|
1393 |
+
* @return array
|
1394 |
+
*/
|
1395 |
+
static protected function _flattenParametersArray($parray, $prefix = null)
|
1396 |
+
{
|
1397 |
+
if (! is_array($parray)) {
|
1398 |
+
return $parray;
|
1399 |
+
}
|
1400 |
+
|
1401 |
+
$parameters = array();
|
1402 |
+
|
1403 |
+
foreach($parray as $name => $value) {
|
1404 |
+
|
1405 |
+
// Calculate array key
|
1406 |
+
if ($prefix) {
|
1407 |
+
if (is_int($name)) {
|
1408 |
+
$key = $prefix . '[]';
|
1409 |
+
} else {
|
1410 |
+
$key = $prefix . "[$name]";
|
1411 |
+
}
|
1412 |
+
} else {
|
1413 |
+
$key = $name;
|
1414 |
+
}
|
1415 |
+
|
1416 |
+
if (is_array($value)) {
|
1417 |
+
$parameters = array_merge($parameters, self::_flattenParametersArray($value, $key));
|
1418 |
+
|
1419 |
+
} else {
|
1420 |
+
$parameters[] = array($key, $value);
|
1421 |
+
}
|
1422 |
+
}
|
1423 |
+
|
1424 |
+
return $parameters;
|
1425 |
+
}
|
1426 |
+
|
1427 |
+
}
|
libs/Microsoft/Http/Client/Adapter/Curl.php
CHANGED
@@ -1,489 +1,489 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Zend Framework
|
5 |
-
*
|
6 |
-
* LICENSE
|
7 |
-
*
|
8 |
-
* This source file is subject to the new BSD license that is bundled
|
9 |
-
* with this package in the file LICENSE.txt.
|
10 |
-
* It is also available through the world-wide-web at this URL:
|
11 |
-
* http://framework.zend.com/license/new-bsd
|
12 |
-
* If you did not receive a copy of the license and are unable to
|
13 |
-
* obtain it through the world-wide-web, please send an email
|
14 |
-
* to license@zend.com so we can send you a copy immediately.
|
15 |
-
*
|
16 |
-
* @category Microsoft
|
17 |
-
* @package Microsoft_Http
|
18 |
-
* @subpackage Client_Adapter
|
19 |
-
* @version $Id: Curl.php 19238 2009-11-25 17:13:38Z bate $
|
20 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
21 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
22 |
-
*/
|
23 |
-
|
24 |
-
/**
|
25 |
-
* @see Microsoft_AutoLoader
|
26 |
-
*/
|
27 |
-
require_once dirname(__FILE__) . '/../../../AutoLoader.php';
|
28 |
-
|
29 |
-
/**
|
30 |
-
* An adapter class for Microsoft_Http_Client based on the curl extension.
|
31 |
-
* Curl requires libcurl. See for full requirements the PHP manual: http://php.net/curl
|
32 |
-
*
|
33 |
-
* @category Microsoft
|
34 |
-
* @package Microsoft_Http
|
35 |
-
* @subpackage Client_Adapter
|
36 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
37 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
38 |
-
*/
|
39 |
-
class Microsoft_Http_Client_Adapter_Curl implements Microsoft_Http_Client_Adapter_Interface, Microsoft_Http_Client_Adapter_Stream
|
40 |
-
{
|
41 |
-
/**
|
42 |
-
* Parameters array
|
43 |
-
*
|
44 |
-
* @var array
|
45 |
-
*/
|
46 |
-
protected $_config = array();
|
47 |
-
|
48 |
-
/**
|
49 |
-
* What host/port are we connected to?
|
50 |
-
*
|
51 |
-
* @var array
|
52 |
-
*/
|
53 |
-
protected $_connected_to = array(null, null);
|
54 |
-
|
55 |
-
/**
|
56 |
-
* The curl session handle
|
57 |
-
*
|
58 |
-
* @var resource|null
|
59 |
-
*/
|
60 |
-
protected $_curl = null;
|
61 |
-
|
62 |
-
/**
|
63 |
-
* List of cURL options that should never be overwritten
|
64 |
-
*
|
65 |
-
* @var array
|
66 |
-
*/
|
67 |
-
protected $_invalidOverwritableCurlOptions = array(
|
68 |
-
CURLOPT_HTTPGET,
|
69 |
-
CURLOPT_POST,
|
70 |
-
CURLOPT_PUT,
|
71 |
-
CURLOPT_CUSTOMREQUEST,
|
72 |
-
CURLOPT_HEADER,
|
73 |
-
CURLOPT_RETURNTRANSFER,
|
74 |
-
CURLOPT_HTTPHEADER,
|
75 |
-
CURLOPT_POSTFIELDS,
|
76 |
-
CURLOPT_INFILE,
|
77 |
-
CURLOPT_INFILESIZE,
|
78 |
-
CURLOPT_PORT,
|
79 |
-
CURLOPT_MAXREDIRS,
|
80 |
-
CURLOPT_CONNECTTIMEOUT,
|
81 |
-
CURL_HTTP_VERSION_1_1,
|
82 |
-
CURL_HTTP_VERSION_1_0,
|
83 |
-
);
|
84 |
-
|
85 |
-
/**
|
86 |
-
* Response gotten from server
|
87 |
-
*
|
88 |
-
* @var string
|
89 |
-
*/
|
90 |
-
protected $_response = null;
|
91 |
-
|
92 |
-
/**
|
93 |
-
* Stream for storing output
|
94 |
-
*
|
95 |
-
* @var resource
|
96 |
-
*/
|
97 |
-
protected $out_stream;
|
98 |
-
|
99 |
-
/**
|
100 |
-
* Adapter constructor
|
101 |
-
*
|
102 |
-
* Config is set using setConfig()
|
103 |
-
*
|
104 |
-
* @return void
|
105 |
-
* @throws Microsoft_Http_Client_Adapter_Exception
|
106 |
-
*/
|
107 |
-
public function __construct()
|
108 |
-
{
|
109 |
-
if (!extension_loaded('curl')) {
|
110 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
111 |
-
throw new Microsoft_Http_Client_Adapter_Exception('cURL extension has to be loaded to use this Microsoft_Http_Client adapter.');
|
112 |
-
}
|
113 |
-
}
|
114 |
-
|
115 |
-
/**
|
116 |
-
* Set the configuration array for the adapter
|
117 |
-
*
|
118 |
-
* @throws Microsoft_Http_Client_Adapter_Exception
|
119 |
-
* @param array $config
|
120 |
-
* @return Microsoft_Http_Client_Adapter_Curl
|
121 |
-
*/
|
122 |
-
public function setConfig($config = array())
|
123 |
-
{
|
124 |
-
if (! is_array($config)) {
|
125 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
126 |
-
throw new Microsoft_Http_Client_Adapter_Exception(
|
127 |
-
'Array expected, got ' . gettype($config)
|
128 |
-
);
|
129 |
-
}
|
130 |
-
|
131 |
-
if(isset($config['proxy_user']) && isset($config['proxy_pass'])) {
|
132 |
-
$this->setCurlOption(CURLOPT_PROXYUSERPWD, $config['proxy_user'].":".$config['proxy_pass']);
|
133 |
-
unset($config['proxy_user'], $config['proxy_pass']);
|
134 |
-
}
|
135 |
-
|
136 |
-
foreach ($config as $k => $v) {
|
137 |
-
$option = strtolower($k);
|
138 |
-
switch($option) {
|
139 |
-
case 'proxy_host':
|
140 |
-
$this->setCurlOption(CURLOPT_PROXY, $v);
|
141 |
-
break;
|
142 |
-
case 'proxy_port':
|
143 |
-
$this->setCurlOption(CURLOPT_PROXYPORT, $v);
|
144 |
-
break;
|
145 |
-
default:
|
146 |
-
$this->_config[$option] = $v;
|
147 |
-
break;
|
148 |
-
}
|
149 |
-
}
|
150 |
-
|
151 |
-
return $this;
|
152 |
-
}
|
153 |
-
|
154 |
-
/**
|
155 |
-
* Retrieve the array of all configuration options
|
156 |
-
*
|
157 |
-
* @return array
|
158 |
-
*/
|
159 |
-
public function getConfig()
|
160 |
-
{
|
161 |
-
return $this->_config;
|
162 |
-
}
|
163 |
-
|
164 |
-
/**
|
165 |
-
* Direct setter for cURL adapter related options.
|
166 |
-
*
|
167 |
-
* @param string|int $option
|
168 |
-
* @param mixed $value
|
169 |
-
* @return Microsoft_Http_Adapter_Curl
|
170 |
-
*/
|
171 |
-
public function setCurlOption($option, $value)
|
172 |
-
{
|
173 |
-
if (!isset($this->_config['curloptions'])) {
|
174 |
-
$this->_config['curloptions'] = array();
|
175 |
-
}
|
176 |
-
$this->_config['curloptions'][$option] = $value;
|
177 |
-
return $this;
|
178 |
-
}
|
179 |
-
|
180 |
-
/**
|
181 |
-
* Initialize curl
|
182 |
-
*
|
183 |
-
* @param string $host
|
184 |
-
* @param int $port
|
185 |
-
* @param boolean $secure
|
186 |
-
* @return void
|
187 |
-
* @throws Microsoft_Http_Client_Adapter_Exception if unable to connect
|
188 |
-
*/
|
189 |
-
public function connect($host, $port = 80, $secure = false)
|
190 |
-
{
|
191 |
-
// If we're already connected, disconnect first
|
192 |
-
if ($this->_curl) {
|
193 |
-
$this->close();
|
194 |
-
}
|
195 |
-
|
196 |
-
// If we are connected to a different server or port, disconnect first
|
197 |
-
if ($this->_curl
|
198 |
-
&& is_array($this->_connected_to)
|
199 |
-
&& ($this->_connected_to[0] != $host
|
200 |
-
|| $this->_connected_to[1] != $port)
|
201 |
-
) {
|
202 |
-
$this->close();
|
203 |
-
}
|
204 |
-
|
205 |
-
// Do the actual connection
|
206 |
-
$this->_curl = curl_init();
|
207 |
-
if ($port != 80) {
|
208 |
-
curl_setopt($this->_curl, CURLOPT_PORT, intval($port));
|
209 |
-
}
|
210 |
-
|
211 |
-
// Set timeout
|
212 |
-
curl_setopt($this->_curl, CURLOPT_CONNECTTIMEOUT, $this->_config['timeout']);
|
213 |
-
|
214 |
-
// Set Max redirects
|
215 |
-
curl_setopt($this->_curl, CURLOPT_MAXREDIRS, $this->_config['maxredirects']);
|
216 |
-
|
217 |
-
if (!$this->_curl) {
|
218 |
-
$this->close();
|
219 |
-
|
220 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
221 |
-
throw new Microsoft_Http_Client_Adapter_Exception('Unable to Connect to ' . $host . ':' . $port);
|
222 |
-
}
|
223 |
-
|
224 |
-
if ($secure !== false) {
|
225 |
-
// Behave the same like Microsoft_Http_Adapter_Socket on SSL options.
|
226 |
-
if (isset($this->_config['sslcert'])) {
|
227 |
-
curl_setopt($this->_curl, CURLOPT_SSLCERT, $this->_config['sslcert']);
|
228 |
-
}
|
229 |
-
if (isset($this->_config['sslpassphrase'])) {
|
230 |
-
curl_setopt($this->_curl, CURLOPT_SSLCERTPASSWD, $this->_config['sslpassphrase']);
|
231 |
-
}
|
232 |
-
}
|
233 |
-
|
234 |
-
// Update connected_to
|
235 |
-
$this->_connected_to = array($host, $port);
|
236 |
-
}
|
237 |
-
|
238 |
-
/**
|
239 |
-
* Send request to the remote server
|
240 |
-
*
|
241 |
-
* @param string $method
|
242 |
-
* @param Microsoft_Uri_Http $uri
|
243 |
-
* @param float $http_ver
|
244 |
-
* @param array $headers
|
245 |
-
* @param string $body
|
246 |
-
* @return string $request
|
247 |
-
* @throws Microsoft_Http_Client_Adapter_Exception If connection fails, connected to wrong host, no PUT file defined, unsupported method, or unsupported cURL option
|
248 |
-
*/
|
249 |
-
public function write($method, $uri, $httpVersion = 1.1, $headers = array(), $body = '')
|
250 |
-
{
|
251 |
-
// Make sure we're properly connected
|
252 |
-
if (!$this->_curl) {
|
253 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
254 |
-
throw new Microsoft_Http_Client_Adapter_Exception("Trying to write but we are not connected");
|
255 |
-
}
|
256 |
-
|
257 |
-
if ($this->_connected_to[0] != $uri->getHost() || $this->_connected_to[1] != $uri->getPort()) {
|
258 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
259 |
-
throw new Microsoft_Http_Client_Adapter_Exception("Trying to write but we are connected to the wrong host");
|
260 |
-
}
|
261 |
-
|
262 |
-
// set URL
|
263 |
-
curl_setopt($this->_curl, CURLOPT_URL, $uri->__toString());
|
264 |
-
|
265 |
-
// ensure correct curl call
|
266 |
-
$curlValue = true;
|
267 |
-
switch ($method) {
|
268 |
-
case Microsoft_Http_Client::GET:
|
269 |
-
$curlMethod = CURLOPT_HTTPGET;
|
270 |
-
break;
|
271 |
-
|
272 |
-
case Microsoft_Http_Client::POST:
|
273 |
-
$curlMethod = CURLOPT_POST;
|
274 |
-
break;
|
275 |
-
|
276 |
-
case Microsoft_Http_Client::PUT:
|
277 |
-
// There are two different types of PUT request, either a Raw Data string has been set
|
278 |
-
// or CURLOPT_INFILE and CURLOPT_INFILESIZE are used.
|
279 |
-
if(is_resource($body)) {
|
280 |
-
$this->_config['curloptions'][CURLOPT_INFILE] = $body;
|
281 |
-
}
|
282 |
-
if (isset($this->_config['curloptions'][CURLOPT_INFILE])) {
|
283 |
-
// Now we will probably already have Content-Length set, so that we have to delete it
|
284 |
-
// from $headers at this point:
|
285 |
-
foreach ($headers AS $k => $header) {
|
286 |
-
if (preg_match('/Content-Length:\s*(\d+)/i', $header, $m)) {
|
287 |
-
if(is_resource($body)) {
|
288 |
-
$this->_config['curloptions'][CURLOPT_INFILESIZE] = (int)$m[1];
|
289 |
-
}
|
290 |
-
unset($headers[$k]);
|
291 |
-
}
|
292 |
-
}
|
293 |
-
|
294 |
-
if (!isset($this->_config['curloptions'][CURLOPT_INFILESIZE])) {
|
295 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
296 |
-
throw new Microsoft_Http_Client_Adapter_Exception("Cannot set a file-handle for cURL option CURLOPT_INFILE without also setting its size in CURLOPT_INFILESIZE.");
|
297 |
-
}
|
298 |
-
|
299 |
-
if(is_resource($body)) {
|
300 |
-
$body = '';
|
301 |
-
}
|
302 |
-
|
303 |
-
$curlMethod = CURLOPT_PUT;
|
304 |
-
} else {
|
305 |
-
$curlMethod = CURLOPT_CUSTOMREQUEST;
|
306 |
-
$curlValue = "PUT";
|
307 |
-
}
|
308 |
-
break;
|
309 |
-
|
310 |
-
case Microsoft_Http_Client::DELETE:
|
311 |
-
$curlMethod = CURLOPT_CUSTOMREQUEST;
|
312 |
-
$curlValue = "DELETE";
|
313 |
-
break;
|
314 |
-
|
315 |
-
case Microsoft_Http_Client::OPTIONS:
|
316 |
-
$curlMethod = CURLOPT_CUSTOMREQUEST;
|
317 |
-
$curlValue = "OPTIONS";
|
318 |
-
break;
|
319 |
-
|
320 |
-
case Microsoft_Http_Client::TRACE:
|
321 |
-
$curlMethod = CURLOPT_CUSTOMREQUEST;
|
322 |
-
$curlValue = "TRACE";
|
323 |
-
break;
|
324 |
-
|
325 |
-
default:
|
326 |
-
// For now, through an exception for unsupported request methods
|
327 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
328 |
-
throw new Microsoft_Http_Client_Adapter_Exception("Method currently not supported");
|
329 |
-
}
|
330 |
-
|
331 |
-
if(is_resource($body) && $curlMethod != CURLOPT_PUT) {
|
332 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
333 |
-
throw new Microsoft_Http_Client_Adapter_Exception("Streaming requests are allowed only with PUT");
|
334 |
-
}
|
335 |
-
|
336 |
-
// get http version to use
|
337 |
-
$curlHttp = ($httpVersion == 1.1) ? CURL_HTTP_VERSION_1_1 : CURL_HTTP_VERSION_1_0;
|
338 |
-
|
339 |
-
// mark as HTTP request and set HTTP method
|
340 |
-
curl_setopt($this->_curl, $curlHttp, true);
|
341 |
-
curl_setopt($this->_curl, $curlMethod, $curlValue);
|
342 |
-
|
343 |
-
if($this->out_stream) {
|
344 |
-
// headers will be read into the response
|
345 |
-
curl_setopt($this->_curl, CURLOPT_HEADER, false);
|
346 |
-
curl_setopt($this->_curl, CURLOPT_HEADERFUNCTION, array($this, "readHeader"));
|
347 |
-
// and data will be written into the file
|
348 |
-
curl_setopt($this->_curl, CURLOPT_FILE, $this->out_stream);
|
349 |
-
} else {
|
350 |
-
// ensure headers are also returned
|
351 |
-
curl_setopt($this->_curl, CURLOPT_HEADER, true);
|
352 |
-
|
353 |
-
// ensure actual response is returned
|
354 |
-
curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, true);
|
355 |
-
}
|
356 |
-
|
357 |
-
// set additional headers
|
358 |
-
$headers['Accept'] = '';
|
359 |
-
curl_setopt($this->_curl, CURLOPT_HTTPHEADER, $headers);
|
360 |
-
|
361 |
-
/**
|
362 |
-
* Make sure POSTFIELDS is set after $curlMethod is set:
|
363 |
-
* @link http://de2.php.net/manual/en/function.curl-setopt.php#81161
|
364 |
-
*/
|
365 |
-
if ($method == Microsoft_Http_Client::POST) {
|
366 |
-
curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $body);
|
367 |
-
} elseif ($curlMethod == CURLOPT_PUT) {
|
368 |
-
// this covers a PUT by file-handle:
|
369 |
-
// Make the setting of this options explicit (rather than setting it through the loop following a bit lower)
|
370 |
-
// to group common functionality together.
|
371 |
-
curl_setopt($this->_curl, CURLOPT_INFILE, $this->_config['curloptions'][CURLOPT_INFILE]);
|
372 |
-
curl_setopt($this->_curl, CURLOPT_INFILESIZE, $this->_config['curloptions'][CURLOPT_INFILESIZE]);
|
373 |
-
unset($this->_config['curloptions'][CURLOPT_INFILE]);
|
374 |
-
unset($this->_config['curloptions'][CURLOPT_INFILESIZE]);
|
375 |
-
} elseif ($method == Microsoft_Http_Client::PUT) {
|
376 |
-
// This is a PUT by a setRawData string, not by file-handle
|
377 |
-
curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $body);
|
378 |
-
}
|
379 |
-
|
380 |
-
// set additional curl options
|
381 |
-
if (isset($this->_config['curloptions'])) {
|
382 |
-
foreach ((array)$this->_config['curloptions'] as $k => $v) {
|
383 |
-
if (!in_array($k, $this->_invalidOverwritableCurlOptions)) {
|
384 |
-
if (curl_setopt($this->_curl, $k, $v) == false) {
|
385 |
-
require_once 'Microsoft/Http/Client/Exception.php';
|
386 |
-
throw new Microsoft_Http_Client_Exception(sprintf("Unknown or erroreous cURL option '%s' set", $k));
|
387 |
-
}
|
388 |
-
}
|
389 |
-
}
|
390 |
-
}
|
391 |
-
|
392 |
-
// send the request
|
393 |
-
$response = curl_exec($this->_curl);
|
394 |
-
|
395 |
-
// if we used streaming, headers are already there
|
396 |
-
if(!is_resource($this->out_stream)) {
|
397 |
-
$this->_response = $response;
|
398 |
-
}
|
399 |
-
|
400 |
-
$request = curl_getinfo($this->_curl, CURLINFO_HEADER_OUT);
|
401 |
-
$request .= $body;
|
402 |
-
|
403 |
-
if (empty($this->_response)) {
|
404 |
-
require_once 'Microsoft/Http/Client/Exception.php';
|
405 |
-
throw new Microsoft_Http_Client_Exception("Error in cURL request: " . curl_error($this->_curl));
|
406 |
-
}
|
407 |
-
|
408 |
-
// cURL automatically decodes chunked-messages, this means we have to disallow the Microsoft_Http_Response to do it again
|
409 |
-
if (stripos($this->_response, "Transfer-Encoding: chunked\r\n")) {
|
410 |
-
$this->_response = str_ireplace("Transfer-Encoding: chunked\r\n", '', $this->_response);
|
411 |
-
}
|
412 |
-
|
413 |
-
// Eliminate multiple HTTP responses.
|
414 |
-
do {
|
415 |
-
$parts = preg_split('|(?:\r?\n){2}|m', $this->_response, 2);
|
416 |
-
$again = false;
|
417 |
-
|
418 |
-
if (isset($parts[1]) && preg_match("|^HTTP/1\.[01](.*?)\r\n|mi", $parts[1])) {
|
419 |
-
$this->_response = $parts[1];
|
420 |
-
$again = true;
|
421 |
-
}
|
422 |
-
} while ($again);
|
423 |
-
|
424 |
-
// cURL automatically handles Proxy rewrites, remove the "HTTP/1.0 200 Connection established" string:
|
425 |
-
if (stripos($this->_response, "HTTP/1.0 200 Connection established\r\n\r\n") !== false) {
|
426 |
-
$this->_response = str_ireplace("HTTP/1.0 200 Connection established\r\n\r\n", '', $this->_response);
|
427 |
-
}
|
428 |
-
|
429 |
-
return $request;
|
430 |
-
}
|
431 |
-
|
432 |
-
/**
|
433 |
-
* Return read response from server
|
434 |
-
*
|
435 |
-
* @return string
|
436 |
-
*/
|
437 |
-
public function read()
|
438 |
-
{
|
439 |
-
return $this->_response;
|
440 |
-
}
|
441 |
-
|
442 |
-
/**
|
443 |
-
* Close the connection to the server
|
444 |
-
*
|
445 |
-
*/
|
446 |
-
public function close()
|
447 |
-
{
|
448 |
-
if(is_resource($this->_curl)) {
|
449 |
-
curl_close($this->_curl);
|
450 |
-
}
|
451 |
-
$this->_curl = null;
|
452 |
-
$this->_connected_to = array(null, null);
|
453 |
-
}
|
454 |
-
|
455 |
-
/**
|
456 |
-
* Get cUrl Handle
|
457 |
-
*
|
458 |
-
* @return resource
|
459 |
-
*/
|
460 |
-
public function getHandle()
|
461 |
-
{
|
462 |
-
return $this->_curl;
|
463 |
-
}
|
464 |
-
|
465 |
-
/**
|
466 |
-
* Set output stream for the response
|
467 |
-
*
|
468 |
-
* @param resource $stream
|
469 |
-
* @return Microsoft_Http_Client_Adapter_Socket
|
470 |
-
*/
|
471 |
-
public function setOutputStream($stream)
|
472 |
-
{
|
473 |
-
$this->out_stream = $stream;
|
474 |
-
return $this;
|
475 |
-
}
|
476 |
-
|
477 |
-
/**
|
478 |
-
* Header reader function for CURL
|
479 |
-
*
|
480 |
-
* @param resource $curl
|
481 |
-
* @param string $header
|
482 |
-
* @return int
|
483 |
-
*/
|
484 |
-
public function readHeader($curl, $header)
|
485 |
-
{
|
486 |
-
$this->_response .= $header;
|
487 |
-
return strlen($header);
|
488 |
-
}
|
489 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Zend Framework
|
5 |
+
*
|
6 |
+
* LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the new BSD license that is bundled
|
9 |
+
* with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://framework.zend.com/license/new-bsd
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@zend.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category Microsoft
|
17 |
+
* @package Microsoft_Http
|
18 |
+
* @subpackage Client_Adapter
|
19 |
+
* @version $Id: Curl.php 19238 2009-11-25 17:13:38Z bate $
|
20 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
21 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
22 |
+
*/
|
23 |
+
|
24 |
+
/**
|
25 |
+
* @see Microsoft_AutoLoader
|
26 |
+
*/
|
27 |
+
require_once dirname(__FILE__) . '/../../../AutoLoader.php';
|
28 |
+
|
29 |
+
/**
|
30 |
+
* An adapter class for Microsoft_Http_Client based on the curl extension.
|
31 |
+
* Curl requires libcurl. See for full requirements the PHP manual: http://php.net/curl
|
32 |
+
*
|
33 |
+
* @category Microsoft
|
34 |
+
* @package Microsoft_Http
|
35 |
+
* @subpackage Client_Adapter
|
36 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
37 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
38 |
+
*/
|
39 |
+
class Microsoft_Http_Client_Adapter_Curl implements Microsoft_Http_Client_Adapter_Interface, Microsoft_Http_Client_Adapter_Stream
|
40 |
+
{
|
41 |
+
/**
|
42 |
+
* Parameters array
|
43 |
+
*
|
44 |
+
* @var array
|
45 |
+
*/
|
46 |
+
protected $_config = array();
|
47 |
+
|
48 |
+
/**
|
49 |
+
* What host/port are we connected to?
|
50 |
+
*
|
51 |
+
* @var array
|
52 |
+
*/
|
53 |
+
protected $_connected_to = array(null, null);
|
54 |
+
|
55 |
+
/**
|
56 |
+
* The curl session handle
|
57 |
+
*
|
58 |
+
* @var resource|null
|
59 |
+
*/
|
60 |
+
protected $_curl = null;
|
61 |
+
|
62 |
+
/**
|
63 |
+
* List of cURL options that should never be overwritten
|
64 |
+
*
|
65 |
+
* @var array
|
66 |
+
*/
|
67 |
+
protected $_invalidOverwritableCurlOptions = array(
|
68 |
+
CURLOPT_HTTPGET,
|
69 |
+
CURLOPT_POST,
|
70 |
+
CURLOPT_PUT,
|
71 |
+
CURLOPT_CUSTOMREQUEST,
|
72 |
+
CURLOPT_HEADER,
|
73 |
+
CURLOPT_RETURNTRANSFER,
|
74 |
+
CURLOPT_HTTPHEADER,
|
75 |
+
CURLOPT_POSTFIELDS,
|
76 |
+
CURLOPT_INFILE,
|
77 |
+
CURLOPT_INFILESIZE,
|
78 |
+
CURLOPT_PORT,
|
79 |
+
CURLOPT_MAXREDIRS,
|
80 |
+
CURLOPT_CONNECTTIMEOUT,
|
81 |
+
CURL_HTTP_VERSION_1_1,
|
82 |
+
CURL_HTTP_VERSION_1_0,
|
83 |
+
);
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Response gotten from server
|
87 |
+
*
|
88 |
+
* @var string
|
89 |
+
*/
|
90 |
+
protected $_response = null;
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Stream for storing output
|
94 |
+
*
|
95 |
+
* @var resource
|
96 |
+
*/
|
97 |
+
protected $out_stream;
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Adapter constructor
|
101 |
+
*
|
102 |
+
* Config is set using setConfig()
|
103 |
+
*
|
104 |
+
* @return void
|
105 |
+
* @throws Microsoft_Http_Client_Adapter_Exception
|
106 |
+
*/
|
107 |
+
public function __construct()
|
108 |
+
{
|
109 |
+
if (!extension_loaded('curl')) {
|
110 |
+
//require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
111 |
+
throw new Microsoft_Http_Client_Adapter_Exception('cURL extension has to be loaded to use this Microsoft_Http_Client adapter.');
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Set the configuration array for the adapter
|
117 |
+
*
|
118 |
+
* @throws Microsoft_Http_Client_Adapter_Exception
|
119 |
+
* @param array $config
|
120 |
+
* @return Microsoft_Http_Client_Adapter_Curl
|
121 |
+
*/
|
122 |
+
public function setConfig($config = array())
|
123 |
+
{
|
124 |
+
if (! is_array($config)) {
|
125 |
+
//require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
126 |
+
throw new Microsoft_Http_Client_Adapter_Exception(
|
127 |
+
'Array expected, got ' . gettype($config)
|
128 |
+
);
|
129 |
+
}
|
130 |
+
|
131 |
+
if(isset($config['proxy_user']) && isset($config['proxy_pass'])) {
|
132 |
+
$this->setCurlOption(CURLOPT_PROXYUSERPWD, $config['proxy_user'].":".$config['proxy_pass']);
|
133 |
+
unset($config['proxy_user'], $config['proxy_pass']);
|
134 |
+
}
|
135 |
+
|
136 |
+
foreach ($config as $k => $v) {
|
137 |
+
$option = strtolower($k);
|
138 |
+
switch($option) {
|
139 |
+
case 'proxy_host':
|
140 |
+
$this->setCurlOption(CURLOPT_PROXY, $v);
|
141 |
+
break;
|
142 |
+
case 'proxy_port':
|
143 |
+
$this->setCurlOption(CURLOPT_PROXYPORT, $v);
|
144 |
+
break;
|
145 |
+
default:
|
146 |
+
$this->_config[$option] = $v;
|
147 |
+
break;
|
148 |
+
}
|
149 |
+
}
|
150 |
+
|
151 |
+
return $this;
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Retrieve the array of all configuration options
|
156 |
+
*
|
157 |
+
* @return array
|
158 |
+
*/
|
159 |
+
public function getConfig()
|
160 |
+
{
|
161 |
+
return $this->_config;
|
162 |
+
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
* Direct setter for cURL adapter related options.
|
166 |
+
*
|
167 |
+
* @param string|int $option
|
168 |
+
* @param mixed $value
|
169 |
+
* @return Microsoft_Http_Adapter_Curl
|
170 |
+
*/
|
171 |
+
public function setCurlOption($option, $value)
|
172 |
+
{
|
173 |
+
if (!isset($this->_config['curloptions'])) {
|
174 |
+
$this->_config['curloptions'] = array();
|
175 |
+
}
|
176 |
+
$this->_config['curloptions'][$option] = $value;
|
177 |
+
return $this;
|
178 |
+
}
|
179 |
+
|
180 |
+
/**
|
181 |
+
* Initialize curl
|
182 |
+
*
|
183 |
+
* @param string $host
|
184 |
+
* @param int $port
|
185 |
+
* @param boolean $secure
|
186 |
+
* @return void
|
187 |
+
* @throws Microsoft_Http_Client_Adapter_Exception if unable to connect
|
188 |
+
*/
|
189 |
+
public function connect($host, $port = 80, $secure = false)
|
190 |
+
{
|
191 |
+
// If we're already connected, disconnect first
|
192 |
+
if ($this->_curl) {
|
193 |
+
$this->close();
|
194 |
+
}
|
195 |
+
|
196 |
+
// If we are connected to a different server or port, disconnect first
|
197 |
+
if ($this->_curl
|
198 |
+
&& is_array($this->_connected_to)
|
199 |
+
&& ($this->_connected_to[0] != $host
|
200 |
+
|| $this->_connected_to[1] != $port)
|
201 |
+
) {
|
202 |
+
$this->close();
|
203 |
+
}
|
204 |
+
|
205 |
+
// Do the actual connection
|
206 |
+
$this->_curl = curl_init();
|
207 |
+
if ($port != 80) {
|
208 |
+
curl_setopt($this->_curl, CURLOPT_PORT, intval($port));
|
209 |
+
}
|
210 |
+
|
211 |
+
// Set timeout
|
212 |
+
curl_setopt($this->_curl, CURLOPT_CONNECTTIMEOUT, $this->_config['timeout']);
|
213 |
+
|
214 |
+
// Set Max redirects
|
215 |
+
curl_setopt($this->_curl, CURLOPT_MAXREDIRS, $this->_config['maxredirects']);
|
216 |
+
|
217 |
+
if (!$this->_curl) {
|
218 |
+
$this->close();
|
219 |
+
|
220 |
+
//require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
221 |
+
throw new Microsoft_Http_Client_Adapter_Exception('Unable to Connect to ' . $host . ':' . $port);
|
222 |
+
}
|
223 |
+
|
224 |
+
if ($secure !== false) {
|
225 |
+
// Behave the same like Microsoft_Http_Adapter_Socket on SSL options.
|
226 |
+
if (isset($this->_config['sslcert'])) {
|
227 |
+
curl_setopt($this->_curl, CURLOPT_SSLCERT, $this->_config['sslcert']);
|
228 |
+
}
|
229 |
+
if (isset($this->_config['sslpassphrase'])) {
|
230 |
+
curl_setopt($this->_curl, CURLOPT_SSLCERTPASSWD, $this->_config['sslpassphrase']);
|
231 |
+
}
|
232 |
+
}
|
233 |
+
|
234 |
+
// Update connected_to
|
235 |
+
$this->_connected_to = array($host, $port);
|
236 |
+
}
|
237 |
+
|
238 |
+
/**
|
239 |
+
* Send request to the remote server
|
240 |
+
*
|
241 |
+
* @param string $method
|
242 |
+
* @param Microsoft_Uri_Http $uri
|
243 |
+
* @param float $http_ver
|
244 |
+
* @param array $headers
|
245 |
+
* @param string $body
|
246 |
+
* @return string $request
|
247 |
+
* @throws Microsoft_Http_Client_Adapter_Exception If connection fails, connected to wrong host, no PUT file defined, unsupported method, or unsupported cURL option
|
248 |
+
*/
|
249 |
+
public function write($method, $uri, $httpVersion = 1.1, $headers = array(), $body = '')
|
250 |
+
{
|
251 |
+
// Make sure we're properly connected
|
252 |
+
if (!$this->_curl) {
|
253 |
+
//require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
254 |
+
throw new Microsoft_Http_Client_Adapter_Exception("Trying to write but we are not connected");
|
255 |
+
}
|
256 |
+
|
257 |
+
if ($this->_connected_to[0] != $uri->getHost() || $this->_connected_to[1] != $uri->getPort()) {
|
258 |
+
//require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
259 |
+
throw new Microsoft_Http_Client_Adapter_Exception("Trying to write but we are connected to the wrong host");
|
260 |
+
}
|
261 |
+
|
262 |
+
// set URL
|
263 |
+
curl_setopt($this->_curl, CURLOPT_URL, $uri->__toString());
|
264 |
+
|
265 |
+
// ensure correct curl call
|
266 |
+
$curlValue = true;
|
267 |
+
switch ($method) {
|
268 |
+
case Microsoft_Http_Client::GET:
|
269 |
+
$curlMethod = CURLOPT_HTTPGET;
|
270 |
+
break;
|
271 |
+
|
272 |
+
case Microsoft_Http_Client::POST:
|
273 |
+
$curlMethod = CURLOPT_POST;
|
274 |
+
break;
|
275 |
+
|
276 |
+
case Microsoft_Http_Client::PUT:
|
277 |
+
// There are two different types of PUT request, either a Raw Data string has been set
|
278 |
+
// or CURLOPT_INFILE and CURLOPT_INFILESIZE are used.
|
279 |
+
if(is_resource($body)) {
|
280 |
+
$this->_config['curloptions'][CURLOPT_INFILE] = $body;
|
281 |
+
}
|
282 |
+
if (isset($this->_config['curloptions'][CURLOPT_INFILE])) {
|
283 |
+
// Now we will probably already have Content-Length set, so that we have to delete it
|
284 |
+
// from $headers at this point:
|
285 |
+
foreach ($headers AS $k => $header) {
|
286 |
+
if (preg_match('/Content-Length:\s*(\d+)/i', $header, $m)) {
|
287 |
+
if(is_resource($body)) {
|
288 |
+
$this->_config['curloptions'][CURLOPT_INFILESIZE] = (int)$m[1];
|
289 |
+
}
|
290 |
+
unset($headers[$k]);
|
291 |
+
}
|
292 |
+
}
|
293 |
+
|
294 |
+
if (!isset($this->_config['curloptions'][CURLOPT_INFILESIZE])) {
|
295 |
+
//require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
296 |
+
throw new Microsoft_Http_Client_Adapter_Exception("Cannot set a file-handle for cURL option CURLOPT_INFILE without also setting its size in CURLOPT_INFILESIZE.");
|
297 |
+
}
|
298 |
+
|
299 |
+
if(is_resource($body)) {
|
300 |
+
$body = '';
|
301 |
+
}
|
302 |
+
|
303 |
+
$curlMethod = CURLOPT_PUT;
|
304 |
+
} else {
|
305 |
+
$curlMethod = CURLOPT_CUSTOMREQUEST;
|
306 |
+
$curlValue = "PUT";
|
307 |
+
}
|
308 |
+
break;
|
309 |
+
|
310 |
+
case Microsoft_Http_Client::DELETE:
|
311 |
+
$curlMethod = CURLOPT_CUSTOMREQUEST;
|
312 |
+
$curlValue = "DELETE";
|
313 |
+
break;
|
314 |
+
|
315 |
+
case Microsoft_Http_Client::OPTIONS:
|
316 |
+
$curlMethod = CURLOPT_CUSTOMREQUEST;
|
317 |
+
$curlValue = "OPTIONS";
|
318 |
+
break;
|
319 |
+
|
320 |
+
case Microsoft_Http_Client::TRACE:
|
321 |
+
$curlMethod = CURLOPT_CUSTOMREQUEST;
|
322 |
+
$curlValue = "TRACE";
|
323 |
+
break;
|
324 |
+
|
325 |
+
default:
|
326 |
+
// For now, through an exception for unsupported request methods
|
327 |
+
//require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
328 |
+
throw new Microsoft_Http_Client_Adapter_Exception("Method currently not supported");
|
329 |
+
}
|
330 |
+
|
331 |
+
if(is_resource($body) && $curlMethod != CURLOPT_PUT) {
|
332 |
+
//require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
333 |
+
throw new Microsoft_Http_Client_Adapter_Exception("Streaming requests are allowed only with PUT");
|
334 |
+
}
|
335 |
+
|
336 |
+
// get http version to use
|
337 |
+
$curlHttp = ($httpVersion == 1.1) ? CURL_HTTP_VERSION_1_1 : CURL_HTTP_VERSION_1_0;
|
338 |
+
|
339 |
+
// mark as HTTP request and set HTTP method
|
340 |
+
curl_setopt($this->_curl, $curlHttp, true);
|
341 |
+
curl_setopt($this->_curl, $curlMethod, $curlValue);
|
342 |
+
|
343 |
+
if($this->out_stream) {
|
344 |
+
// headers will be read into the response
|
345 |
+
curl_setopt($this->_curl, CURLOPT_HEADER, false);
|
346 |
+
curl_setopt($this->_curl, CURLOPT_HEADERFUNCTION, array($this, "readHeader"));
|
347 |
+
// and data will be written into the file
|
348 |
+
curl_setopt($this->_curl, CURLOPT_FILE, $this->out_stream);
|
349 |
+
} else {
|
350 |
+
// ensure headers are also returned
|
351 |
+
curl_setopt($this->_curl, CURLOPT_HEADER, true);
|
352 |
+
|
353 |
+
// ensure actual response is returned
|
354 |
+
curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, true);
|
355 |
+
}
|
356 |
+
|
357 |
+
// set additional headers
|
358 |
+
$headers['Accept'] = '';
|
359 |
+
curl_setopt($this->_curl, CURLOPT_HTTPHEADER, $headers);
|
360 |
+
|
361 |
+
/**
|
362 |
+
* Make sure POSTFIELDS is set after $curlMethod is set:
|
363 |
+
* @link http://de2.php.net/manual/en/function.curl-setopt.php#81161
|
364 |
+
*/
|
365 |
+
if ($method == Microsoft_Http_Client::POST) {
|
366 |
+
curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $body);
|
367 |
+
} elseif ($curlMethod == CURLOPT_PUT) {
|
368 |
+
// this covers a PUT by file-handle:
|
369 |
+
// Make the setting of this options explicit (rather than setting it through the loop following a bit lower)
|
370 |
+
// to group common functionality together.
|
371 |
+
curl_setopt($this->_curl, CURLOPT_INFILE, $this->_config['curloptions'][CURLOPT_INFILE]);
|
372 |
+
curl_setopt($this->_curl, CURLOPT_INFILESIZE, $this->_config['curloptions'][CURLOPT_INFILESIZE]);
|
373 |
+
unset($this->_config['curloptions'][CURLOPT_INFILE]);
|
374 |
+
unset($this->_config['curloptions'][CURLOPT_INFILESIZE]);
|
375 |
+
} elseif ($method == Microsoft_Http_Client::PUT) {
|
376 |
+
// This is a PUT by a setRawData string, not by file-handle
|
377 |
+
curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $body);
|
378 |
+
}
|
379 |
+
|
380 |
+
// set additional curl options
|
381 |
+
if (isset($this->_config['curloptions'])) {
|
382 |
+
foreach ((array)$this->_config['curloptions'] as $k => $v) {
|
383 |
+
if (!in_array($k, $this->_invalidOverwritableCurlOptions)) {
|
384 |
+
if (curl_setopt($this->_curl, $k, $v) == false) {
|
385 |
+
//require_once 'Microsoft/Http/Client/Exception.php';
|
386 |
+
throw new Microsoft_Http_Client_Exception(sprintf("Unknown or erroreous cURL option '%s' set", $k));
|
387 |
+
}
|
388 |
+
}
|
389 |
+
}
|
390 |
+
}
|
391 |
+
|
392 |
+
// send the request
|
393 |
+
$response = curl_exec($this->_curl);
|
394 |
+
|
395 |
+
// if we used streaming, headers are already there
|
396 |
+
if(!is_resource($this->out_stream)) {
|
397 |
+
$this->_response = $response;
|
398 |
+
}
|
399 |
+
|
400 |
+
$request = curl_getinfo($this->_curl, CURLINFO_HEADER_OUT);
|
401 |
+
$request .= $body;
|
402 |
+
|
403 |
+
if (empty($this->_response)) {
|
404 |
+
//require_once 'Microsoft/Http/Client/Exception.php';
|
405 |
+
throw new Microsoft_Http_Client_Exception("Error in cURL request: " . curl_error($this->_curl));
|
406 |
+
}
|
407 |
+
|
408 |
+
// cURL automatically decodes chunked-messages, this means we have to disallow the Microsoft_Http_Response to do it again
|
409 |
+
if (stripos($this->_response, "Transfer-Encoding: chunked\r\n")) {
|
410 |
+
$this->_response = str_ireplace("Transfer-Encoding: chunked\r\n", '', $this->_response);
|
411 |
+
}
|
412 |
+
|
413 |
+
// Eliminate multiple HTTP responses.
|
414 |
+
do {
|
415 |
+
$parts = preg_split('|(?:\r?\n){2}|m', $this->_response, 2);
|
416 |
+
$again = false;
|
417 |
+
|
418 |
+
if (isset($parts[1]) && preg_match("|^HTTP/1\.[01](.*?)\r\n|mi", $parts[1])) {
|
419 |
+
$this->_response = $parts[1];
|
420 |
+
$again = true;
|
421 |
+
}
|
422 |
+
} while ($again);
|
423 |
+
|
424 |
+
// cURL automatically handles Proxy rewrites, remove the "HTTP/1.0 200 Connection established" string:
|
425 |
+
if (stripos($this->_response, "HTTP/1.0 200 Connection established\r\n\r\n") !== false) {
|
426 |
+
$this->_response = str_ireplace("HTTP/1.0 200 Connection established\r\n\r\n", '', $this->_response);
|
427 |
+
}
|
428 |
+
|
429 |
+
return $request;
|
430 |
+
}
|
431 |
+
|
432 |
+
/**
|
433 |
+
* Return read response from server
|
434 |
+
*
|
435 |
+
* @return string
|
436 |
+
*/
|
437 |
+
public function read()
|
438 |
+
{
|
439 |
+
return $this->_response;
|
440 |
+
}
|
441 |
+
|
442 |
+
/**
|
443 |
+
* Close the connection to the server
|
444 |
+
*
|
445 |
+
*/
|
446 |
+
public function close()
|
447 |
+
{
|
448 |
+
if(is_resource($this->_curl)) {
|
449 |
+
curl_close($this->_curl);
|
450 |
+
}
|
451 |
+
$this->_curl = null;
|
452 |
+
$this->_connected_to = array(null, null);
|
453 |
+
}
|
454 |
+
|
455 |
+
/**
|
456 |
+
* Get cUrl Handle
|
457 |
+
*
|
458 |
+
* @return resource
|
459 |
+
*/
|
460 |
+
public function getHandle()
|
461 |
+
{
|
462 |
+
return $this->_curl;
|
463 |
+
}
|
464 |
+
|
465 |
+
/**
|
466 |
+
* Set output stream for the response
|
467 |
+
*
|
468 |
+
* @param resource $stream
|
469 |
+
* @return Microsoft_Http_Client_Adapter_Socket
|
470 |
+
*/
|
471 |
+
public function setOutputStream($stream)
|
472 |
+
{
|
473 |
+
$this->out_stream = $stream;
|
474 |
+
return $this;
|
475 |
+
}
|
476 |
+
|
477 |
+
/**
|
478 |
+
* Header reader function for CURL
|
479 |
+
*
|
480 |
+
* @param resource $curl
|
481 |
+
* @param string $header
|
482 |
+
* @return int
|
483 |
+
*/
|
484 |
+
public function readHeader($curl, $header)
|
485 |
+
{
|
486 |
+
$this->_response .= $header;
|
487 |
+
return strlen($header);
|
488 |
+
}
|
489 |
+
}
|
libs/Microsoft/Http/Client/Adapter/Exception.php
CHANGED
@@ -1,38 +1,38 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Zend Framework
|
4 |
-
*
|
5 |
-
* LICENSE
|
6 |
-
*
|
7 |
-
* This source file is subject to the new BSD license that is bundled
|
8 |
-
* with this package in the file LICENSE.txt.
|
9 |
-
* It is also available through the world-wide-web at this URL:
|
10 |
-
* http://framework.zend.com/license/new-bsd
|
11 |
-
* If you did not receive a copy of the license and are unable to
|
12 |
-
* obtain it through the world-wide-web, please send an email
|
13 |
-
* to license@zend.com so we can send you a copy immediately.
|
14 |
-
*
|
15 |
-
* @category Microsoft
|
16 |
-
* @package Microsoft_Http
|
17 |
-
* @subpackage Client_Adapter_Exception
|
18 |
-
* @version $Id: Exception.php 17026 2009-07-24 09:09:19Z shahar $
|
19 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
20 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
21 |
-
*/
|
22 |
-
|
23 |
-
/**
|
24 |
-
* @see Microsoft_AutoLoader
|
25 |
-
*/
|
26 |
-
require_once dirname(__FILE__) . '/../../../AutoLoader.php';
|
27 |
-
|
28 |
-
/**
|
29 |
-
* @category Microsoft
|
30 |
-
* @package Microsoft_Http
|
31 |
-
* @subpackage Client_Adapter
|
32 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
33 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
34 |
-
*/
|
35 |
-
class Microsoft_Http_Client_Adapter_Exception extends Microsoft_Http_Client_Exception
|
36 |
-
{
|
37 |
-
const READ_TIMEOUT = 1000;
|
38 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Zend Framework
|
4 |
+
*
|
5 |
+
* LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the new BSD license that is bundled
|
8 |
+
* with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://framework.zend.com/license/new-bsd
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@zend.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* @category Microsoft
|
16 |
+
* @package Microsoft_Http
|
17 |
+
* @subpackage Client_Adapter_Exception
|
18 |
+
* @version $Id: Exception.php 17026 2009-07-24 09:09:19Z shahar $
|
19 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
20 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
21 |
+
*/
|
22 |
+
|
23 |
+
/**
|
24 |
+
* @see Microsoft_AutoLoader
|
25 |
+
*/
|
26 |
+
require_once dirname(__FILE__) . '/../../../AutoLoader.php';
|
27 |
+
|
28 |
+
/**
|
29 |
+
* @category Microsoft
|
30 |
+
* @package Microsoft_Http
|
31 |
+
* @subpackage Client_Adapter
|
32 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
33 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
34 |
+
*/
|
35 |
+
class Microsoft_Http_Client_Adapter_Exception extends Microsoft_Http_Client_Exception
|
36 |
+
{
|
37 |
+
const READ_TIMEOUT = 1000;
|
38 |
+
}
|
libs/Microsoft/Http/Client/Adapter/Interface.php
CHANGED
@@ -1,78 +1,78 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Zend Framework
|
5 |
-
*
|
6 |
-
* LICENSE
|
7 |
-
*
|
8 |
-
* This source file is subject to the new BSD license that is bundled
|
9 |
-
* with this package in the file LICENSE.txt.
|
10 |
-
* It is also available through the world-wide-web at this URL:
|
11 |
-
* http://framework.zend.com/license/new-bsd
|
12 |
-
* If you did not receive a copy of the license and are unable to
|
13 |
-
* obtain it through the world-wide-web, please send an email
|
14 |
-
* to license@zend.com so we can send you a copy immediately.
|
15 |
-
*
|
16 |
-
* @category Microsoft
|
17 |
-
* @package Microsoft_Http
|
18 |
-
* @subpackage Client_Adapter
|
19 |
-
* @version $Id: Interface.php 16214 2009-06-21 19:34:03Z thomas $
|
20 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
21 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
22 |
-
*/
|
23 |
-
|
24 |
-
/**
|
25 |
-
* An interface description for Microsoft_Http_Client_Adapter classes.
|
26 |
-
*
|
27 |
-
* These classes are used as connectors for Microsoft_Http_Client, performing the
|
28 |
-
* tasks of connecting, writing, reading and closing connection to the server.
|
29 |
-
*
|
30 |
-
* @category Microsoft
|
31 |
-
* @package Microsoft_Http
|
32 |
-
* @subpackage Client_Adapter
|
33 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
34 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
35 |
-
*/
|
36 |
-
interface Microsoft_Http_Client_Adapter_Interface
|
37 |
-
{
|
38 |
-
/**
|
39 |
-
* Set the configuration array for the adapter
|
40 |
-
*
|
41 |
-
* @param array $config
|
42 |
-
*/
|
43 |
-
public function setConfig($config = array());
|
44 |
-
|
45 |
-
/**
|
46 |
-
* Connect to the remote server
|
47 |
-
*
|
48 |
-
* @param string $host
|
49 |
-
* @param int $port
|
50 |
-
* @param boolean $secure
|
51 |
-
*/
|
52 |
-
public function connect($host, $port = 80, $secure = false);
|
53 |
-
|
54 |
-
/**
|
55 |
-
* Send request to the remote server
|
56 |
-
*
|
57 |
-
* @param string $method
|
58 |
-
* @param Microsoft_Uri_Http $url
|
59 |
-
* @param string $http_ver
|
60 |
-
* @param array $headers
|
61 |
-
* @param string $body
|
62 |
-
* @return string Request as text
|
63 |
-
*/
|
64 |
-
public function write($method, $url, $http_ver = '1.1', $headers = array(), $body = '');
|
65 |
-
|
66 |
-
/**
|
67 |
-
* Read response from server
|
68 |
-
*
|
69 |
-
* @return string
|
70 |
-
*/
|
71 |
-
public function read();
|
72 |
-
|
73 |
-
/**
|
74 |
-
* Close the connection to the server
|
75 |
-
*
|
76 |
-
*/
|
77 |
-
public function close();
|
78 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Zend Framework
|
5 |
+
*
|
6 |
+
* LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the new BSD license that is bundled
|
9 |
+
* with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://framework.zend.com/license/new-bsd
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@zend.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category Microsoft
|
17 |
+
* @package Microsoft_Http
|
18 |
+
* @subpackage Client_Adapter
|
19 |
+
* @version $Id: Interface.php 16214 2009-06-21 19:34:03Z thomas $
|
20 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
21 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
22 |
+
*/
|
23 |
+
|
24 |
+
/**
|
25 |
+
* An interface description for Microsoft_Http_Client_Adapter classes.
|
26 |
+
*
|
27 |
+
* These classes are used as connectors for Microsoft_Http_Client, performing the
|
28 |
+
* tasks of connecting, writing, reading and closing connection to the server.
|
29 |
+
*
|
30 |
+
* @category Microsoft
|
31 |
+
* @package Microsoft_Http
|
32 |
+
* @subpackage Client_Adapter
|
33 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
34 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
35 |
+
*/
|
36 |
+
interface Microsoft_Http_Client_Adapter_Interface
|
37 |
+
{
|
38 |
+
/**
|
39 |
+
* Set the configuration array for the adapter
|
40 |
+
*
|
41 |
+
* @param array $config
|
42 |
+
*/
|
43 |
+
public function setConfig($config = array());
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Connect to the remote server
|
47 |
+
*
|
48 |
+
* @param string $host
|
49 |
+
* @param int $port
|
50 |
+
* @param boolean $secure
|
51 |
+
*/
|
52 |
+
public function connect($host, $port = 80, $secure = false);
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Send request to the remote server
|
56 |
+
*
|
57 |
+
* @param string $method
|
58 |
+
* @param Microsoft_Uri_Http $url
|
59 |
+
* @param string $http_ver
|
60 |
+
* @param array $headers
|
61 |
+
* @param string $body
|
62 |
+
* @return string Request as text
|
63 |
+
*/
|
64 |
+
public function write($method, $url, $http_ver = '1.1', $headers = array(), $body = '');
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Read response from server
|
68 |
+
*
|
69 |
+
* @return string
|
70 |
+
*/
|
71 |
+
public function read();
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Close the connection to the server
|
75 |
+
*
|
76 |
+
*/
|
77 |
+
public function close();
|
78 |
+
}
|
libs/Microsoft/Http/Client/Adapter/Proxy.php
CHANGED
@@ -1,259 +1,259 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Zend Framework
|
5 |
-
*
|
6 |
-
* LICENSE
|
7 |
-
*
|
8 |
-
* This source file is subject to the new BSD license that is bundled
|
9 |
-
* with this package in the file LICENSE.txt.
|
10 |
-
* It is also available through the world-wide-web at this URL:
|
11 |
-
* http://framework.zend.com/license/new-bsd
|
12 |
-
* If you did not receive a copy of the license and are unable to
|
13 |
-
* obtain it through the world-wide-web, please send an email
|
14 |
-
* to license@zend.com so we can send you a copy immediately.
|
15 |
-
*
|
16 |
-
* @category Microsoft
|
17 |
-
* @package Microsoft_Http
|
18 |
-
* @subpackage Client_Adapter
|
19 |
-
* @version $Id: Proxy.php 17059 2009-07-25 11:24:49Z shahar $
|
20 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
21 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
22 |
-
*/
|
23 |
-
|
24 |
-
/**
|
25 |
-
* @see Microsoft_AutoLoader
|
26 |
-
*/
|
27 |
-
require_once dirname(__FILE__) . '/../../../AutoLoader.php';
|
28 |
-
|
29 |
-
/**
|
30 |
-
* HTTP Proxy-supporting Microsoft_Http_Client adapter class, based on the default
|
31 |
-
* socket based adapter.
|
32 |
-
*
|
33 |
-
* Should be used if proxy HTTP access is required. If no proxy is set, will
|
34 |
-
* fall back to Microsoft_Http_Client_Adapter_Socket behavior. Just like the
|
35 |
-
* default Socket adapter, this adapter does not require any special extensions
|
36 |
-
* installed.
|
37 |
-
*
|
38 |
-
* @category Microsoft
|
39 |
-
* @package Microsoft_Http
|
40 |
-
* @subpackage Client_Adapter
|
41 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
42 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
43 |
-
*/
|
44 |
-
class Microsoft_Http_Client_Adapter_Proxy extends Microsoft_Http_Client_Adapter_Socket
|
45 |
-
{
|
46 |
-
/**
|
47 |
-
* Parameters array
|
48 |
-
*
|
49 |
-
* @var array
|
50 |
-
*/
|
51 |
-
protected $config = array(
|
52 |
-
'ssltransport' => 'ssl',
|
53 |
-
'sslcert' => null,
|
54 |
-
'sslpassphrase' => null,
|
55 |
-
'proxy_host' => '',
|
56 |
-
'proxy_port' => 8080,
|
57 |
-
'proxy_user' => '',
|
58 |
-
'proxy_pass' => '',
|
59 |
-
'proxy_auth' => Microsoft_Http_Client::AUTH_BASIC,
|
60 |
-
'persistent' => false
|
61 |
-
);
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Whether HTTPS CONNECT was already negotiated with the proxy or not
|
65 |
-
*
|
66 |
-
* @var boolean
|
67 |
-
*/
|
68 |
-
protected $negotiated = false;
|
69 |
-
|
70 |
-
/**
|
71 |
-
* Connect to the remote server
|
72 |
-
*
|
73 |
-
* Will try to connect to the proxy server. If no proxy was set, will
|
74 |
-
* fall back to the target server (behave like regular Socket adapter)
|
75 |
-
*
|
76 |
-
* @param string $host
|
77 |
-
* @param int $port
|
78 |
-
* @param boolean $secure
|
79 |
-
*/
|
80 |
-
public function connect($host, $port = 80, $secure = false)
|
81 |
-
{
|
82 |
-
// If no proxy is set, fall back to Socket adapter
|
83 |
-
if (! $this->config['proxy_host']) {
|
84 |
-
return parent::connect($host, $port, $secure);
|
85 |
-
}
|
86 |
-
|
87 |
-
// Connect (a non-secure connection) to the proxy server
|
88 |
-
return parent::connect(
|
89 |
-
$this->config['proxy_host'],
|
90 |
-
$this->config['proxy_port'],
|
91 |
-
false
|
92 |
-
);
|
93 |
-
}
|
94 |
-
|
95 |
-
/**
|
96 |
-
* Send request to the proxy server
|
97 |
-
*
|
98 |
-
* @param string $method
|
99 |
-
* @param Microsoft_Uri_Http $uri
|
100 |
-
* @param string $http_ver
|
101 |
-
* @param array $headers
|
102 |
-
* @param string $body
|
103 |
-
* @return string Request as string
|
104 |
-
*/
|
105 |
-
public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
|
106 |
-
{
|
107 |
-
// If no proxy is set, fall back to default Socket adapter
|
108 |
-
if (! $this->config['proxy_host']) return parent::write($method, $uri, $http_ver, $headers, $body);
|
109 |
-
|
110 |
-
// Make sure we're properly connected
|
111 |
-
if (! $this->socket) {
|
112 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
113 |
-
throw new Microsoft_Http_Client_Adapter_Exception("Trying to write but we are not connected");
|
114 |
-
}
|
115 |
-
|
116 |
-
$host = $this->config['proxy_host'];
|
117 |
-
$port = $this->config['proxy_port'];
|
118 |
-
|
119 |
-
if ($this->connected_to[0] != "tcp://$host" || $this->connected_to[1] != $port) {
|
120 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
121 |
-
throw new Microsoft_Http_Client_Adapter_Exception("Trying to write but we are connected to the wrong proxy server");
|
122 |
-
}
|
123 |
-
|
124 |
-
// Add Proxy-Authorization header
|
125 |
-
if ($this->config['proxy_user'] && ! isset($headers['proxy-authorization'])) {
|
126 |
-
$headers['proxy-authorization'] = Microsoft_Http_Client::encodeAuthHeader(
|
127 |
-
$this->config['proxy_user'], $this->config['proxy_pass'], $this->config['proxy_auth']
|
128 |
-
);
|
129 |
-
}
|
130 |
-
|
131 |
-
// if we are proxying HTTPS, preform CONNECT handshake with the proxy
|
132 |
-
if ($uri->getScheme() == 'https' && (! $this->negotiated)) {
|
133 |
-
$this->connectHandshake($uri->getHost(), $uri->getPort(), $http_ver, $headers);
|
134 |
-
$this->negotiated = true;
|
135 |
-
}
|
136 |
-
|
137 |
-
// Save request method for later
|
138 |
-
$this->method = $method;
|
139 |
-
|
140 |
-
// Build request headers
|
141 |
-
if ($this->negotiated) {
|
142 |
-
$path = $uri->getPath();
|
143 |
-
if ($uri->getQuery()) {
|
144 |
-
$path .= '?' . $uri->getQuery();
|
145 |
-
}
|
146 |
-
$request = "$method $path HTTP/$http_ver\r\n";
|
147 |
-
} else {
|
148 |
-
$request = "$method $uri HTTP/$http_ver\r\n";
|
149 |
-
}
|
150 |
-
|
151 |
-
// Add all headers to the request string
|
152 |
-
foreach ($headers as $k => $v) {
|
153 |
-
if (is_string($k)) $v = "$k: $v";
|
154 |
-
$request .= "$v\r\n";
|
155 |
-
}
|
156 |
-
|
157 |
-
// Add the request body
|
158 |
-
$request .= "\r\n" . $body;
|
159 |
-
|
160 |
-
// Send the request
|
161 |
-
if (! @fwrite($this->socket, $request)) {
|
162 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
163 |
-
throw new Microsoft_Http_Client_Adapter_Exception("Error writing request to proxy server");
|
164 |
-
}
|
165 |
-
|
166 |
-
return $request;
|
167 |
-
}
|
168 |
-
|
169 |
-
/**
|
170 |
-
* Preform handshaking with HTTPS proxy using CONNECT method
|
171 |
-
*
|
172 |
-
* @param string $host
|
173 |
-
* @param integer $port
|
174 |
-
* @param string $http_ver
|
175 |
-
* @param array $headers
|
176 |
-
*/
|
177 |
-
protected function connectHandshake($host, $port = 443, $http_ver = '1.1', array &$headers = array())
|
178 |
-
{
|
179 |
-
$request = "CONNECT $host:$port HTTP/$http_ver\r\n" .
|
180 |
-
"Host: " . $this->config['proxy_host'] . "\r\n";
|
181 |
-
|
182 |
-
// Add the user-agent header
|
183 |
-
if (isset($this->config['useragent'])) {
|
184 |
-
$request .= "User-agent: " . $this->config['useragent'] . "\r\n";
|
185 |
-
}
|
186 |
-
|
187 |
-
// If the proxy-authorization header is set, send it to proxy but remove
|
188 |
-
// it from headers sent to target host
|
189 |
-
if (isset($headers['proxy-authorization'])) {
|
190 |
-
$request .= "Proxy-authorization: " . $headers['proxy-authorization'] . "\r\n";
|
191 |
-
unset($headers['proxy-authorization']);
|
192 |
-
}
|
193 |
-
|
194 |
-
$request .= "\r\n";
|
195 |
-
|
196 |
-
// Send the request
|
197 |
-
if (! @fwrite($this->socket, $request)) {
|
198 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
199 |
-
throw new Microsoft_Http_Client_Adapter_Exception("Error writing request to proxy server");
|
200 |
-
}
|
201 |
-
|
202 |
-
// Read response headers only
|
203 |
-
$response = '';
|
204 |
-
$gotStatus = false;
|
205 |
-
while ($line = @fgets($this->socket)) {
|
206 |
-
$gotStatus = $gotStatus || (strpos($line, 'HTTP') !== false);
|
207 |
-
if ($gotStatus) {
|
208 |
-
$response .= $line;
|
209 |
-
if (!chop($line)) break;
|
210 |
-
}
|
211 |
-
}
|
212 |
-
|
213 |
-
// Check that the response from the proxy is 200
|
214 |
-
if (Microsoft_Http_Response::extractCode($response) != 200) {
|
215 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
216 |
-
throw new Microsoft_Http_Client_Adapter_Exception("Unable to connect to HTTPS proxy. Server response: " . $response);
|
217 |
-
}
|
218 |
-
|
219 |
-
// If all is good, switch socket to secure mode. We have to fall back
|
220 |
-
// through the different modes
|
221 |
-
$modes = array(
|
222 |
-
STREAM_CRYPTO_METHOD_TLS_CLIENT,
|
223 |
-
STREAM_CRYPTO_METHOD_SSLv3_CLIENT,
|
224 |
-
STREAM_CRYPTO_METHOD_SSLv23_CLIENT,
|
225 |
-
STREAM_CRYPTO_METHOD_SSLv2_CLIENT
|
226 |
-
);
|
227 |
-
|
228 |
-
$success = false;
|
229 |
-
foreach($modes as $mode) {
|
230 |
-
$success = stream_socket_enable_crypto($this->socket, true, $mode);
|
231 |
-
if ($success) break;
|
232 |
-
}
|
233 |
-
|
234 |
-
if (! $success) {
|
235 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
236 |
-
throw new Microsoft_Http_Client_Adapter_Exception("Unable to connect to" .
|
237 |
-
" HTTPS server through proxy: could not negotiate secure connection.");
|
238 |
-
}
|
239 |
-
}
|
240 |
-
|
241 |
-
/**
|
242 |
-
* Close the connection to the server
|
243 |
-
*
|
244 |
-
*/
|
245 |
-
public function close()
|
246 |
-
{
|
247 |
-
parent::close();
|
248 |
-
$this->negotiated = false;
|
249 |
-
}
|
250 |
-
|
251 |
-
/**
|
252 |
-
* Destructor: make sure the socket is disconnected
|
253 |
-
*
|
254 |
-
*/
|
255 |
-
public function __destruct()
|
256 |
-
{
|
257 |
-
if ($this->socket) $this->close();
|
258 |
-
}
|
259 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Zend Framework
|
5 |
+
*
|
6 |
+
* LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the new BSD license that is bundled
|
9 |
+
* with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://framework.zend.com/license/new-bsd
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@zend.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category Microsoft
|
17 |
+
* @package Microsoft_Http
|
18 |
+
* @subpackage Client_Adapter
|
19 |
+
* @version $Id: Proxy.php 17059 2009-07-25 11:24:49Z shahar $
|
20 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
21 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
22 |
+
*/
|
23 |
+
|
24 |
+
/**
|
25 |
+
* @see Microsoft_AutoLoader
|
26 |
+
*/
|
27 |
+
require_once dirname(__FILE__) . '/../../../AutoLoader.php';
|
28 |
+
|
29 |
+
/**
|
30 |
+
* HTTP Proxy-supporting Microsoft_Http_Client adapter class, based on the default
|
31 |
+
* socket based adapter.
|
32 |
+
*
|
33 |
+
* Should be used if proxy HTTP access is required. If no proxy is set, will
|
34 |
+
* fall back to Microsoft_Http_Client_Adapter_Socket behavior. Just like the
|
35 |
+
* default Socket adapter, this adapter does not require any special extensions
|
36 |
+
* installed.
|
37 |
+
*
|
38 |
+
* @category Microsoft
|
39 |
+
* @package Microsoft_Http
|
40 |
+
* @subpackage Client_Adapter
|
41 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
42 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
43 |
+
*/
|
44 |
+
class Microsoft_Http_Client_Adapter_Proxy extends Microsoft_Http_Client_Adapter_Socket
|
45 |
+
{
|
46 |
+
/**
|
47 |
+
* Parameters array
|
48 |
+
*
|
49 |
+
* @var array
|
50 |
+
*/
|
51 |
+
protected $config = array(
|
52 |
+
'ssltransport' => 'ssl',
|
53 |
+
'sslcert' => null,
|
54 |
+
'sslpassphrase' => null,
|
55 |
+
'proxy_host' => '',
|
56 |
+
'proxy_port' => 8080,
|
57 |
+
'proxy_user' => '',
|
58 |
+
'proxy_pass' => '',
|
59 |
+
'proxy_auth' => Microsoft_Http_Client::AUTH_BASIC,
|
60 |
+
'persistent' => false
|
61 |
+
);
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Whether HTTPS CONNECT was already negotiated with the proxy or not
|
65 |
+
*
|
66 |
+
* @var boolean
|
67 |
+
*/
|
68 |
+
protected $negotiated = false;
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Connect to the remote server
|
72 |
+
*
|
73 |
+
* Will try to connect to the proxy server. If no proxy was set, will
|
74 |
+
* fall back to the target server (behave like regular Socket adapter)
|
75 |
+
*
|
76 |
+
* @param string $host
|
77 |
+
* @param int $port
|
78 |
+
* @param boolean $secure
|
79 |
+
*/
|
80 |
+
public function connect($host, $port = 80, $secure = false)
|
81 |
+
{
|
82 |
+
// If no proxy is set, fall back to Socket adapter
|
83 |
+
if (! $this->config['proxy_host']) {
|
84 |
+
return parent::connect($host, $port, $secure);
|
85 |
+
}
|
86 |
+
|
87 |
+
// Connect (a non-secure connection) to the proxy server
|
88 |
+
return parent::connect(
|
89 |
+
$this->config['proxy_host'],
|
90 |
+
$this->config['proxy_port'],
|
91 |
+
false
|
92 |
+
);
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Send request to the proxy server
|
97 |
+
*
|
98 |
+
* @param string $method
|
99 |
+
* @param Microsoft_Uri_Http $uri
|
100 |
+
* @param string $http_ver
|
101 |
+
* @param array $headers
|
102 |
+
* @param string $body
|
103 |
+
* @return string Request as string
|
104 |
+
*/
|
105 |
+
public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
|
106 |
+
{
|
107 |
+
// If no proxy is set, fall back to default Socket adapter
|
108 |
+
if (! $this->config['proxy_host']) return parent::write($method, $uri, $http_ver, $headers, $body);
|
109 |
+
|
110 |
+
// Make sure we're properly connected
|
111 |
+
if (! $this->socket) {
|
112 |
+
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
113 |
+
throw new Microsoft_Http_Client_Adapter_Exception("Trying to write but we are not connected");
|
114 |
+
}
|
115 |
+
|
116 |
+
$host = $this->config['proxy_host'];
|
117 |
+
$port = $this->config['proxy_port'];
|
118 |
+
|
119 |
+
if ($this->connected_to[0] != "tcp://$host" || $this->connected_to[1] != $port) {
|
120 |
+
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
121 |
+
throw new Microsoft_Http_Client_Adapter_Exception("Trying to write but we are connected to the wrong proxy server");
|
122 |
+
}
|
123 |
+
|
124 |
+
// Add Proxy-Authorization header
|
125 |
+
if ($this->config['proxy_user'] && ! isset($headers['proxy-authorization'])) {
|
126 |
+
$headers['proxy-authorization'] = Microsoft_Http_Client::encodeAuthHeader(
|
127 |
+
$this->config['proxy_user'], $this->config['proxy_pass'], $this->config['proxy_auth']
|
128 |
+
);
|
129 |
+
}
|
130 |
+
|
131 |
+
// if we are proxying HTTPS, preform CONNECT handshake with the proxy
|
132 |
+
if ($uri->getScheme() == 'https' && (! $this->negotiated)) {
|
133 |
+
$this->connectHandshake($uri->getHost(), $uri->getPort(), $http_ver, $headers);
|
134 |
+
$this->negotiated = true;
|
135 |
+
}
|
136 |
+
|
137 |
+
// Save request method for later
|
138 |
+
$this->method = $method;
|
139 |
+
|
140 |
+
// Build request headers
|
141 |
+
if ($this->negotiated) {
|
142 |
+
$path = $uri->getPath();
|
143 |
+
if ($uri->getQuery()) {
|
144 |
+
$path .= '?' . $uri->getQuery();
|
145 |
+
}
|
146 |
+
$request = "$method $path HTTP/$http_ver\r\n";
|
147 |
+
} else {
|
148 |
+
$request = "$method $uri HTTP/$http_ver\r\n";
|
149 |
+
}
|
150 |
+
|
151 |
+
// Add all headers to the request string
|
152 |
+
foreach ($headers as $k => $v) {
|
153 |
+
if (is_string($k)) $v = "$k: $v";
|
154 |
+
$request .= "$v\r\n";
|
155 |
+
}
|
156 |
+
|
157 |
+
// Add the request body
|
158 |
+
$request .= "\r\n" . $body;
|
159 |
+
|
160 |
+
// Send the request
|
161 |
+
if (! @fwrite($this->socket, $request)) {
|
162 |
+
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
163 |
+
throw new Microsoft_Http_Client_Adapter_Exception("Error writing request to proxy server");
|
164 |
+
}
|
165 |
+
|
166 |
+
return $request;
|
167 |
+
}
|
168 |
+
|
169 |
+
/**
|
170 |
+
* Preform handshaking with HTTPS proxy using CONNECT method
|
171 |
+
*
|
172 |
+
* @param string $host
|
173 |
+
* @param integer $port
|
174 |
+
* @param string $http_ver
|
175 |
+
* @param array $headers
|
176 |
+
*/
|
177 |
+
protected function connectHandshake($host, $port = 443, $http_ver = '1.1', array &$headers = array())
|
178 |
+
{
|
179 |
+
$request = "CONNECT $host:$port HTTP/$http_ver\r\n" .
|
180 |
+
"Host: " . $this->config['proxy_host'] . "\r\n";
|
181 |
+
|
182 |
+
// Add the user-agent header
|
183 |
+
if (isset($this->config['useragent'])) {
|
184 |
+
$request .= "User-agent: " . $this->config['useragent'] . "\r\n";
|
185 |
+
}
|
186 |
+
|
187 |
+
// If the proxy-authorization header is set, send it to proxy but remove
|
188 |
+
// it from headers sent to target host
|
189 |
+
if (isset($headers['proxy-authorization'])) {
|
190 |
+
$request .= "Proxy-authorization: " . $headers['proxy-authorization'] . "\r\n";
|
191 |
+
unset($headers['proxy-authorization']);
|
192 |
+
}
|
193 |
+
|
194 |
+
$request .= "\r\n";
|
195 |
+
|
196 |
+
// Send the request
|
197 |
+
if (! @fwrite($this->socket, $request)) {
|
198 |
+
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
199 |
+
throw new Microsoft_Http_Client_Adapter_Exception("Error writing request to proxy server");
|
200 |
+
}
|
201 |
+
|
202 |
+
// Read response headers only
|
203 |
+
$response = '';
|
204 |
+
$gotStatus = false;
|
205 |
+
while ($line = @fgets($this->socket)) {
|
206 |
+
$gotStatus = $gotStatus || (strpos($line, 'HTTP') !== false);
|
207 |
+
if ($gotStatus) {
|
208 |
+
$response .= $line;
|
209 |
+
if (!chop($line)) break;
|
210 |
+
}
|
211 |
+
}
|
212 |
+
|
213 |
+
// Check that the response from the proxy is 200
|
214 |
+
if (Microsoft_Http_Response::extractCode($response) != 200) {
|
215 |
+
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
216 |
+
throw new Microsoft_Http_Client_Adapter_Exception("Unable to connect to HTTPS proxy. Server response: " . $response);
|
217 |
+
}
|
218 |
+
|
219 |
+
// If all is good, switch socket to secure mode. We have to fall back
|
220 |
+
// through the different modes
|
221 |
+
$modes = array(
|
222 |
+
STREAM_CRYPTO_METHOD_TLS_CLIENT,
|
223 |
+
STREAM_CRYPTO_METHOD_SSLv3_CLIENT,
|
224 |
+
STREAM_CRYPTO_METHOD_SSLv23_CLIENT,
|
225 |
+
STREAM_CRYPTO_METHOD_SSLv2_CLIENT
|
226 |
+
);
|
227 |
+
|
228 |
+
$success = false;
|
229 |
+
foreach($modes as $mode) {
|
230 |
+
$success = stream_socket_enable_crypto($this->socket, true, $mode);
|
231 |
+
if ($success) break;
|
232 |
+
}
|
233 |
+
|
234 |
+
if (! $success) {
|
235 |
+
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
236 |
+
throw new Microsoft_Http_Client_Adapter_Exception("Unable to connect to" .
|
237 |
+
" HTTPS server through proxy: could not negotiate secure connection.");
|
238 |
+
}
|
239 |
+
}
|
240 |
+
|
241 |
+
/**
|
242 |
+
* Close the connection to the server
|
243 |
+
*
|
244 |
+
*/
|
245 |
+
public function close()
|
246 |
+
{
|
247 |
+
parent::close();
|
248 |
+
$this->negotiated = false;
|
249 |
+
}
|
250 |
+
|
251 |
+
/**
|
252 |
+
* Destructor: make sure the socket is disconnected
|
253 |
+
*
|
254 |
+
*/
|
255 |
+
public function __destruct()
|
256 |
+
{
|
257 |
+
if ($this->socket) $this->close();
|
258 |
+
}
|
259 |
+
}
|
libs/Microsoft/Http/Client/Adapter/Socket.php
CHANGED
@@ -1,523 +1,523 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Zend Framework
|
5 |
-
*
|
6 |
-
* LICENSE
|
7 |
-
*
|
8 |
-
* This source file is subject to the new BSD license that is bundled
|
9 |
-
* with this package in the file LICENSE.txt.
|
10 |
-
* It is also available through the world-wide-web at this URL:
|
11 |
-
* http://framework.zend.com/license/new-bsd
|
12 |
-
* If you did not receive a copy of the license and are unable to
|
13 |
-
* obtain it through the world-wide-web, please send an email
|
14 |
-
* to license@zend.com so we can send you a copy immediately.
|
15 |
-
*
|
16 |
-
* @category Microsoft
|
17 |
-
* @package Microsoft_Http
|
18 |
-
* @subpackage Client_Adapter
|
19 |
-
* @version $Id: Socket.php 19219 2009-11-24 22:25:36Z stas $
|
20 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
21 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
22 |
-
*/
|
23 |
-
|
24 |
-
/**
|
25 |
-
* @see Microsoft_AutoLoader
|
26 |
-
*/
|
27 |
-
require_once dirname(__FILE__) . '/../../../AutoLoader.php';
|
28 |
-
|
29 |
-
/**
|
30 |
-
* A sockets based (stream_socket_client) adapter class for Microsoft_Http_Client. Can be used
|
31 |
-
* on almost every PHP environment, and does not require any special extensions.
|
32 |
-
*
|
33 |
-
* @category Microsoft
|
34 |
-
* @package Microsoft_Http
|
35 |
-
* @subpackage Client_Adapter
|
36 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
37 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
38 |
-
*/
|
39 |
-
class Microsoft_Http_Client_Adapter_Socket implements Microsoft_Http_Client_Adapter_Interface, Microsoft_Http_Client_Adapter_Stream
|
40 |
-
{
|
41 |
-
/**
|
42 |
-
* The socket for server connection
|
43 |
-
*
|
44 |
-
* @var resource|null
|
45 |
-
*/
|
46 |
-
protected $socket = null;
|
47 |
-
|
48 |
-
/**
|
49 |
-
* What host/port are we connected to?
|
50 |
-
*
|
51 |
-
* @var array
|
52 |
-
*/
|
53 |
-
protected $connected_to = array(null, null);
|
54 |
-
|
55 |
-
/**
|
56 |
-
* Stream for storing output
|
57 |
-
*
|
58 |
-
* @var resource
|
59 |
-
*/
|
60 |
-
protected $out_stream = null;
|
61 |
-
|
62 |
-
/**
|
63 |
-
* Parameters array
|
64 |
-
*
|
65 |
-
* @var array
|
66 |
-
*/
|
67 |
-
protected $config = array(
|
68 |
-
'persistent' => false,
|
69 |
-
'ssltransport' => 'ssl',
|
70 |
-
'sslcert' => null,
|
71 |
-
'sslpassphrase' => null
|
72 |
-
);
|
73 |
-
|
74 |
-
/**
|
75 |
-
* Request method - will be set by write() and might be used by read()
|
76 |
-
*
|
77 |
-
* @var string
|
78 |
-
*/
|
79 |
-
protected $method = null;
|
80 |
-
|
81 |
-
/**
|
82 |
-
* Stream context
|
83 |
-
*
|
84 |
-
* @var resource
|
85 |
-
*/
|
86 |
-
protected $_context = null;
|
87 |
-
|
88 |
-
/**
|
89 |
-
* Adapter constructor, currently empty. Config is set using setConfig()
|
90 |
-
*
|
91 |
-
*/
|
92 |
-
public function __construct()
|
93 |
-
{
|
94 |
-
}
|
95 |
-
|
96 |
-
/**
|
97 |
-
* Set the configuration array for the adapter
|
98 |
-
*
|
99 |
-
* @param array $config
|
100 |
-
*/
|
101 |
-
public function setConfig($config = array())
|
102 |
-
{
|
103 |
-
if (! is_array($config)) {
|
104 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
105 |
-
throw new Microsoft_Http_Client_Adapter_Exception(
|
106 |
-
'Array expected, got ' . gettype($config)
|
107 |
-
);
|
108 |
-
}
|
109 |
-
|
110 |
-
foreach ($config as $k => $v) {
|
111 |
-
$this->config[strtolower($k)] = $v;
|
112 |
-
}
|
113 |
-
}
|
114 |
-
|
115 |
-
/**
|
116 |
-
* Retrieve the array of all configuration options
|
117 |
-
*
|
118 |
-
* @return array
|
119 |
-
*/
|
120 |
-
public function getConfig()
|
121 |
-
{
|
122 |
-
return $this->config;
|
123 |
-
}
|
124 |
-
|
125 |
-
/**
|
126 |
-
* Set the stream context for the TCP connection to the server
|
127 |
-
*
|
128 |
-
* Can accept either a pre-existing stream context resource, or an array
|
129 |
-
* of stream options, similar to the options array passed to the
|
130 |
-
* stream_context_create() PHP function. In such case a new stream context
|
131 |
-
* will be created using the passed options.
|
132 |
-
*
|
133 |
-
* @since Zend Framework 1.9
|
134 |
-
*
|
135 |
-
* @param mixed $context Stream context or array of context options
|
136 |
-
* @return Microsoft_Http_Client_Adapter_Socket
|
137 |
-
*/
|
138 |
-
public function setStreamContext($context)
|
139 |
-
{
|
140 |
-
if (is_resource($context) && get_resource_type($context) == 'stream-context') {
|
141 |
-
$this->_context = $context;
|
142 |
-
|
143 |
-
} elseif (is_array($context)) {
|
144 |
-
$this->_context = stream_context_create($context);
|
145 |
-
|
146 |
-
} else {
|
147 |
-
// Invalid parameter
|
148 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
149 |
-
throw new Microsoft_Http_Client_Adapter_Exception(
|
150 |
-
"Expecting either a stream context resource or array, got " . gettype($context)
|
151 |
-
);
|
152 |
-
}
|
153 |
-
|
154 |
-
return $this;
|
155 |
-
}
|
156 |
-
|
157 |
-
/**
|
158 |
-
* Get the stream context for the TCP connection to the server.
|
159 |
-
*
|
160 |
-
* If no stream context is set, will create a default one.
|
161 |
-
*
|
162 |
-
* @return resource
|
163 |
-
*/
|
164 |
-
public function getStreamContext()
|
165 |
-
{
|
166 |
-
if (! $this->_context) {
|
167 |
-
$this->_context = stream_context_create();
|
168 |
-
}
|
169 |
-
|
170 |
-
return $this->_context;
|
171 |
-
}
|
172 |
-
|
173 |
-
/**
|
174 |
-
* Connect to the remote server
|
175 |
-
*
|
176 |
-
* @param string $host
|
177 |
-
* @param int $port
|
178 |
-
* @param boolean $secure
|
179 |
-
*/
|
180 |
-
public function connect($host, $port = 80, $secure = false)
|
181 |
-
{
|
182 |
-
// If the URI should be accessed via SSL, prepend the Hostname with ssl://
|
183 |
-
$host = ($secure ? $this->config['ssltransport'] : 'tcp') . '://' . $host;
|
184 |
-
|
185 |
-
// If we are connected to the wrong host, disconnect first
|
186 |
-
if (($this->connected_to[0] != $host || $this->connected_to[1] != $port)) {
|
187 |
-
if (is_resource($this->socket)) $this->close();
|
188 |
-
}
|
189 |
-
|
190 |
-
// Now, if we are not connected, connect
|
191 |
-
if (! is_resource($this->socket) || ! $this->config['keepalive']) {
|
192 |
-
$context = $this->getStreamContext();
|
193 |
-
if ($secure) {
|
194 |
-
if ($this->config['sslcert'] !== null) {
|
195 |
-
if (! stream_context_set_option($context, 'ssl', 'local_cert',
|
196 |
-
$this->config['sslcert'])) {
|
197 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
198 |
-
throw new Microsoft_Http_Client_Adapter_Exception('Unable to set sslcert option');
|
199 |
-
}
|
200 |
-
}
|
201 |
-
if ($this->config['sslpassphrase'] !== null) {
|
202 |
-
if (! stream_context_set_option($context, 'ssl', 'passphrase',
|
203 |
-
$this->config['sslpassphrase'])) {
|
204 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
205 |
-
throw new Microsoft_Http_Client_Adapter_Exception('Unable to set sslpassphrase option');
|
206 |
-
}
|
207 |
-
}
|
208 |
-
}
|
209 |
-
|
210 |
-
$flags = STREAM_CLIENT_CONNECT;
|
211 |
-
if ($this->config['persistent']) $flags |= STREAM_CLIENT_PERSISTENT;
|
212 |
-
|
213 |
-
$this->socket = @stream_socket_client($host . ':' . $port,
|
214 |
-
$errno,
|
215 |
-
$errstr,
|
216 |
-
(int) $this->config['timeout'],
|
217 |
-
$flags,
|
218 |
-
$context);
|
219 |
-
|
220 |
-
if (! $this->socket) {
|
221 |
-
$this->close();
|
222 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
223 |
-
throw new Microsoft_Http_Client_Adapter_Exception(
|
224 |
-
'Unable to Connect to ' . $host . ':' . $port . '. Error #' . $errno . ': ' . $errstr);
|
225 |
-
}
|
226 |
-
|
227 |
-
// Set the stream timeout
|
228 |
-
if (! stream_set_timeout($this->socket, (int) $this->config['timeout'])) {
|
229 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
230 |
-
throw new Microsoft_Http_Client_Adapter_Exception('Unable to set the connection timeout');
|
231 |
-
}
|
232 |
-
|
233 |
-
// Update connected_to
|
234 |
-
$this->connected_to = array($host, $port);
|
235 |
-
}
|
236 |
-
}
|
237 |
-
|
238 |
-
/**
|
239 |
-
* Send request to the remote server
|
240 |
-
*
|
241 |
-
* @param string $method
|
242 |
-
* @param Microsoft_Uri_Http $uri
|
243 |
-
* @param string $http_ver
|
244 |
-
* @param array $headers
|
245 |
-
* @param string $body
|
246 |
-
* @return string Request as string
|
247 |
-
*/
|
248 |
-
public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
|
249 |
-
{
|
250 |
-
// Make sure we're properly connected
|
251 |
-
if (! $this->socket) {
|
252 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
253 |
-
throw new Microsoft_Http_Client_Adapter_Exception('Trying to write but we are not connected');
|
254 |
-
}
|
255 |
-
|
256 |
-
$host = $uri->getHost();
|
257 |
-
$host = (strtolower($uri->getScheme()) == 'https' ? $this->config['ssltransport'] : 'tcp') . '://' . $host;
|
258 |
-
if ($this->connected_to[0] != $host || $this->connected_to[1] != $uri->getPort()) {
|
259 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
260 |
-
throw new Microsoft_Http_Client_Adapter_Exception('Trying to write but we are connected to the wrong host');
|
261 |
-
}
|
262 |
-
|
263 |
-
// Save request method for later
|
264 |
-
$this->method = $method;
|
265 |
-
|
266 |
-
// Build request headers
|
267 |
-
$path = $uri->getPath();
|
268 |
-
if ($uri->getQuery()) $path .= '?' . $uri->getQuery();
|
269 |
-
$request = "{$method} {$path} HTTP/{$http_ver}\r\n";
|
270 |
-
foreach ($headers as $k => $v) {
|
271 |
-
if (is_string($k)) $v = ucfirst($k) . ": $v";
|
272 |
-
$request .= "$v\r\n";
|
273 |
-
}
|
274 |
-
|
275 |
-
if(is_resource($body)) {
|
276 |
-
$request .= "\r\n";
|
277 |
-
} else {
|
278 |
-
// Add the request body
|
279 |
-
$request .= "\r\n" . $body;
|
280 |
-
}
|
281 |
-
|
282 |
-
// Send the request
|
283 |
-
if (! @fwrite($this->socket, $request)) {
|
284 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
285 |
-
throw new Microsoft_Http_Client_Adapter_Exception('Error writing request to server');
|
286 |
-
}
|
287 |
-
|
288 |
-
if(is_resource($body)) {
|
289 |
-
if(stream_copy_to_stream($body, $this->socket) == 0) {
|
290 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
291 |
-
throw new Microsoft_Http_Client_Adapter_Exception('Error writing request to server');
|
292 |
-
}
|
293 |
-
}
|
294 |
-
|
295 |
-
return $request;
|
296 |
-
}
|
297 |
-
|
298 |
-
/**
|
299 |
-
* Read response from server
|
300 |
-
*
|
301 |
-
* @return string
|
302 |
-
*/
|
303 |
-
public function read()
|
304 |
-
{
|
305 |
-
// First, read headers only
|
306 |
-
$response = '';
|
307 |
-
$gotStatus = false;
|
308 |
-
$stream = !empty($this->config['stream']);
|
309 |
-
|
310 |
-
while (($line = @fgets($this->socket)) !== false) {
|
311 |
-
$gotStatus = $gotStatus || (strpos($line, 'HTTP') !== false);
|
312 |
-
if ($gotStatus) {
|
313 |
-
$response .= $line;
|
314 |
-
if (rtrim($line) === '') break;
|
315 |
-
}
|
316 |
-
}
|
317 |
-
|
318 |
-
$this->_checkSocketReadTimeout();
|
319 |
-
|
320 |
-
$statusCode = Microsoft_Http_Response::extractCode($response);
|
321 |
-
|
322 |
-
// Handle 100 and 101 responses internally by restarting the read again
|
323 |
-
if ($statusCode == 100 || $statusCode == 101) return $this->read();
|
324 |
-
|
325 |
-
// Check headers to see what kind of connection / transfer encoding we have
|
326 |
-
$headers = Microsoft_Http_Response::extractHeaders($response);
|
327 |
-
|
328 |
-
/**
|
329 |
-
* Responses to HEAD requests and 204 or 304 responses are not expected
|
330 |
-
* to have a body - stop reading here
|
331 |
-
*/
|
332 |
-
if ($statusCode == 304 || $statusCode == 204 ||
|
333 |
-
$this->method == Microsoft_Http_Client::HEAD) {
|
334 |
-
|
335 |
-
// Close the connection if requested to do so by the server
|
336 |
-
if (isset($headers['connection']) && $headers['connection'] == 'close') {
|
337 |
-
$this->close();
|
338 |
-
}
|
339 |
-
return $response;
|
340 |
-
}
|
341 |
-
|
342 |
-
// If we got a 'transfer-encoding: chunked' header
|
343 |
-
if (isset($headers['transfer-encoding'])) {
|
344 |
-
|
345 |
-
if (strtolower($headers['transfer-encoding']) == 'chunked') {
|
346 |
-
|
347 |
-
do {
|
348 |
-
$line = @fgets($this->socket);
|
349 |
-
$this->_checkSocketReadTimeout();
|
350 |
-
|
351 |
-
$chunk = $line;
|
352 |
-
|
353 |
-
// Figure out the next chunk size
|
354 |
-
$chunksize = trim($line);
|
355 |
-
if (! ctype_xdigit($chunksize)) {
|
356 |
-
$this->close();
|
357 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
358 |
-
throw new Microsoft_Http_Client_Adapter_Exception('Invalid chunk size "' .
|
359 |
-
$chunksize . '" unable to read chunked body');
|
360 |
-
}
|
361 |
-
|
362 |
-
// Convert the hexadecimal value to plain integer
|
363 |
-
$chunksize = hexdec($chunksize);
|
364 |
-
|
365 |
-
// Read next chunk
|
366 |
-
$read_to = ftell($this->socket) + $chunksize;
|
367 |
-
|
368 |
-
do {
|
369 |
-
$current_pos = ftell($this->socket);
|
370 |
-
if ($current_pos >= $read_to) break;
|
371 |
-
|
372 |
-
if($this->out_stream) {
|
373 |
-
if(stream_copy_to_stream($this->socket, $this->out_stream, $read_to - $current_pos) == 0) {
|
374 |
-
$this->_checkSocketReadTimeout();
|
375 |
-
break;
|
376 |
-
}
|
377 |
-
} else {
|
378 |
-
$line = @fread($this->socket, $read_to - $current_pos);
|
379 |
-
if ($line === false || strlen($line) === 0) {
|
380 |
-
$this->_checkSocketReadTimeout();
|
381 |
-
break;
|
382 |
-
}
|
383 |
-
$chunk .= $line;
|
384 |
-
}
|
385 |
-
} while (! feof($this->socket));
|
386 |
-
|
387 |
-
$chunk .= @fgets($this->socket);
|
388 |
-
$this->_checkSocketReadTimeout();
|
389 |
-
|
390 |
-
if(!$this->out_stream) {
|
391 |
-
$response .= $chunk;
|
392 |
-
}
|
393 |
-
} while ($chunksize > 0);
|
394 |
-
} else {
|
395 |
-
$this->close();
|
396 |
-
throw new Microsoft_Http_Client_Adapter_Exception('Cannot handle "' .
|
397 |
-
$headers['transfer-encoding'] . '" transfer encoding');
|
398 |
-
}
|
399 |
-
|
400 |
-
// We automatically decode chunked-messages when writing to a stream
|
401 |
-
// this means we have to disallow the Microsoft_Http_Response to do it again
|
402 |
-
if ($this->out_stream) {
|
403 |
-
$response = str_ireplace("Transfer-Encoding: chunked\r\n", '', $response);
|
404 |
-
}
|
405 |
-
// Else, if we got the content-length header, read this number of bytes
|
406 |
-
} elseif (isset($headers['content-length'])) {
|
407 |
-
|
408 |
-
$current_pos = ftell($this->socket);
|
409 |
-
$chunk = '';
|
410 |
-
|
411 |
-
for ($read_to = $current_pos + $headers['content-length'];
|
412 |
-
$read_to > $current_pos;
|
413 |
-
$current_pos = ftell($this->socket)) {
|
414 |
-
|
415 |
-
if($this->out_stream) {
|
416 |
-
if(@stream_copy_to_stream($this->socket, $this->out_stream, $read_to - $current_pos) == 0) {
|
417 |
-
$this->_checkSocketReadTimeout();
|
418 |
-
break;
|
419 |
-
}
|
420 |
-
} else {
|
421 |
-
$chunk = @fread($this->socket, $read_to - $current_pos);
|
422 |
-
if ($chunk === false || strlen($chunk) === 0) {
|
423 |
-
$this->_checkSocketReadTimeout();
|
424 |
-
break;
|
425 |
-
}
|
426 |
-
|
427 |
-
$response .= $chunk;
|
428 |
-
}
|
429 |
-
|
430 |
-
// Break if the connection ended prematurely
|
431 |
-
if (feof($this->socket)) break;
|
432 |
-
}
|
433 |
-
|
434 |
-
// Fallback: just read the response until EOF
|
435 |
-
} else {
|
436 |
-
|
437 |
-
do {
|
438 |
-
if($this->out_stream) {
|
439 |
-
if(@stream_copy_to_stream($this->socket, $this->out_stream) == 0) {
|
440 |
-
$this->_checkSocketReadTimeout();
|
441 |
-
break;
|
442 |
-
}
|
443 |
-
} else {
|
444 |
-
$buff = @fread($this->socket, 8192);
|
445 |
-
if ($buff === false || strlen($buff) === 0) {
|
446 |
-
$this->_checkSocketReadTimeout();
|
447 |
-
break;
|
448 |
-
} else {
|
449 |
-
$response .= $buff;
|
450 |
-
}
|
451 |
-
}
|
452 |
-
|
453 |
-
} while (feof($this->socket) === false);
|
454 |
-
|
455 |
-
$this->close();
|
456 |
-
}
|
457 |
-
|
458 |
-
// Close the connection if requested to do so by the server
|
459 |
-
if (isset($headers['connection']) && $headers['connection'] == 'close') {
|
460 |
-
$this->close();
|
461 |
-
}
|
462 |
-
|
463 |
-
return $response;
|
464 |
-
}
|
465 |
-
|
466 |
-
/**
|
467 |
-
* Close the connection to the server
|
468 |
-
*
|
469 |
-
*/
|
470 |
-
public function close()
|
471 |
-
{
|
472 |
-
if (is_resource($this->socket)) @fclose($this->socket);
|
473 |
-
$this->socket = null;
|
474 |
-
$this->connected_to = array(null, null);
|
475 |
-
}
|
476 |
-
|
477 |
-
/**
|
478 |
-
* Check if the socket has timed out - if so close connection and throw
|
479 |
-
* an exception
|
480 |
-
*
|
481 |
-
* @throws Microsoft_Http_Client_Adapter_Exception with READ_TIMEOUT code
|
482 |
-
*/
|
483 |
-
protected function _checkSocketReadTimeout()
|
484 |
-
{
|
485 |
-
if ($this->socket) {
|
486 |
-
$info = stream_get_meta_data($this->socket);
|
487 |
-
$timedout = $info['timed_out'];
|
488 |
-
if ($timedout) {
|
489 |
-
$this->close();
|
490 |
-
require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
491 |
-
throw new Microsoft_Http_Client_Adapter_Exception(
|
492 |
-
"Read timed out after {$this->config['timeout']} seconds",
|
493 |
-
Microsoft_Http_Client_Adapter_Exception::READ_TIMEOUT
|
494 |
-
);
|
495 |
-
}
|
496 |
-
}
|
497 |
-
}
|
498 |
-
|
499 |
-
/**
|
500 |
-
* Set output stream for the response
|
501 |
-
*
|
502 |
-
* @param resource $stream
|
503 |
-
* @return Microsoft_Http_Client_Adapter_Socket
|
504 |
-
*/
|
505 |
-
public function setOutputStream($stream)
|
506 |
-
{
|
507 |
-
$this->out_stream = $stream;
|
508 |
-
return $this;
|
509 |
-
}
|
510 |
-
|
511 |
-
/**
|
512 |
-
* Destructor: make sure the socket is disconnected
|
513 |
-
*
|
514 |
-
* If we are in persistent TCP mode, will not close the connection
|
515 |
-
*
|
516 |
-
*/
|
517 |
-
public function __destruct()
|
518 |
-
{
|
519 |
-
if (! $this->config['persistent']) {
|
520 |
-
if ($this->socket) $this->close();
|
521 |
-
}
|
522 |
-
}
|
523 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Zend Framework
|
5 |
+
*
|
6 |
+
* LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the new BSD license that is bundled
|
9 |
+
* with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://framework.zend.com/license/new-bsd
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@zend.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category Microsoft
|
17 |
+
* @package Microsoft_Http
|
18 |
+
* @subpackage Client_Adapter
|
19 |
+
* @version $Id: Socket.php 19219 2009-11-24 22:25:36Z stas $
|
20 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
21 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
22 |
+
*/
|
23 |
+
|
24 |
+
/**
|
25 |
+
* @see Microsoft_AutoLoader
|
26 |
+
*/
|
27 |
+
require_once dirname(__FILE__) . '/../../../AutoLoader.php';
|
28 |
+
|
29 |
+
/**
|
30 |
+
* A sockets based (stream_socket_client) adapter class for Microsoft_Http_Client. Can be used
|
31 |
+
* on almost every PHP environment, and does not require any special extensions.
|
32 |
+
*
|
33 |
+
* @category Microsoft
|
34 |
+
* @package Microsoft_Http
|
35 |
+
* @subpackage Client_Adapter
|
36 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
37 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
38 |
+
*/
|
39 |
+
class Microsoft_Http_Client_Adapter_Socket implements Microsoft_Http_Client_Adapter_Interface, Microsoft_Http_Client_Adapter_Stream
|
40 |
+
{
|
41 |
+
/**
|
42 |
+
* The socket for server connection
|
43 |
+
*
|
44 |
+
* @var resource|null
|
45 |
+
*/
|
46 |
+
protected $socket = null;
|
47 |
+
|
48 |
+
/**
|
49 |
+
* What host/port are we connected to?
|
50 |
+
*
|
51 |
+
* @var array
|
52 |
+
*/
|
53 |
+
protected $connected_to = array(null, null);
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Stream for storing output
|
57 |
+
*
|
58 |
+
* @var resource
|
59 |
+
*/
|
60 |
+
protected $out_stream = null;
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Parameters array
|
64 |
+
*
|
65 |
+
* @var array
|
66 |
+
*/
|
67 |
+
protected $config = array(
|
68 |
+
'persistent' => false,
|
69 |
+
'ssltransport' => 'ssl',
|
70 |
+
'sslcert' => null,
|
71 |
+
'sslpassphrase' => null
|
72 |
+
);
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Request method - will be set by write() and might be used by read()
|
76 |
+
*
|
77 |
+
* @var string
|
78 |
+
*/
|
79 |
+
protected $method = null;
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Stream context
|
83 |
+
*
|
84 |
+
* @var resource
|
85 |
+
*/
|
86 |
+
protected $_context = null;
|
87 |
+
|
88 |
+
/**
|
89 |
+
* Adapter constructor, currently empty. Config is set using setConfig()
|
90 |
+
*
|
91 |
+
*/
|
92 |
+
public function __construct()
|
93 |
+
{
|
94 |
+
}
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Set the configuration array for the adapter
|
98 |
+
*
|
99 |
+
* @param array $config
|
100 |
+
*/
|
101 |
+
public function setConfig($config = array())
|
102 |
+
{
|
103 |
+
if (! is_array($config)) {
|
104 |
+
//require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
105 |
+
throw new Microsoft_Http_Client_Adapter_Exception(
|
106 |
+
'Array expected, got ' . gettype($config)
|
107 |
+
);
|
108 |
+
}
|
109 |
+
|
110 |
+
foreach ($config as $k => $v) {
|
111 |
+
$this->config[strtolower($k)] = $v;
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Retrieve the array of all configuration options
|
117 |
+
*
|
118 |
+
* @return array
|
119 |
+
*/
|
120 |
+
public function getConfig()
|
121 |
+
{
|
122 |
+
return $this->config;
|
123 |
+
}
|
124 |
+
|
125 |
+
/**
|
126 |
+
* Set the stream context for the TCP connection to the server
|
127 |
+
*
|
128 |
+
* Can accept either a pre-existing stream context resource, or an array
|
129 |
+
* of stream options, similar to the options array passed to the
|
130 |
+
* stream_context_create() PHP function. In such case a new stream context
|
131 |
+
* will be created using the passed options.
|
132 |
+
*
|
133 |
+
* @since Zend Framework 1.9
|
134 |
+
*
|
135 |
+
* @param mixed $context Stream context or array of context options
|
136 |
+
* @return Microsoft_Http_Client_Adapter_Socket
|
137 |
+
*/
|
138 |
+
public function setStreamContext($context)
|
139 |
+
{
|
140 |
+
if (is_resource($context) && get_resource_type($context) == 'stream-context') {
|
141 |
+
$this->_context = $context;
|
142 |
+
|
143 |
+
} elseif (is_array($context)) {
|
144 |
+
$this->_context = stream_context_create($context);
|
145 |
+
|
146 |
+
} else {
|
147 |
+
// Invalid parameter
|
148 |
+
//require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
149 |
+
throw new Microsoft_Http_Client_Adapter_Exception(
|
150 |
+
"Expecting either a stream context resource or array, got " . gettype($context)
|
151 |
+
);
|
152 |
+
}
|
153 |
+
|
154 |
+
return $this;
|
155 |
+
}
|
156 |
+
|
157 |
+
/**
|
158 |
+
* Get the stream context for the TCP connection to the server.
|
159 |
+
*
|
160 |
+
* If no stream context is set, will create a default one.
|
161 |
+
*
|
162 |
+
* @return resource
|
163 |
+
*/
|
164 |
+
public function getStreamContext()
|
165 |
+
{
|
166 |
+
if (! $this->_context) {
|
167 |
+
$this->_context = stream_context_create();
|
168 |
+
}
|
169 |
+
|
170 |
+
return $this->_context;
|
171 |
+
}
|
172 |
+
|
173 |
+
/**
|
174 |
+
* Connect to the remote server
|
175 |
+
*
|
176 |
+
* @param string $host
|
177 |
+
* @param int $port
|
178 |
+
* @param boolean $secure
|
179 |
+
*/
|
180 |
+
public function connect($host, $port = 80, $secure = false)
|
181 |
+
{
|
182 |
+
// If the URI should be accessed via SSL, prepend the Hostname with ssl://
|
183 |
+
$host = ($secure ? $this->config['ssltransport'] : 'tcp') . '://' . $host;
|
184 |
+
|
185 |
+
// If we are connected to the wrong host, disconnect first
|
186 |
+
if (($this->connected_to[0] != $host || $this->connected_to[1] != $port)) {
|
187 |
+
if (is_resource($this->socket)) $this->close();
|
188 |
+
}
|
189 |
+
|
190 |
+
// Now, if we are not connected, connect
|
191 |
+
if (! is_resource($this->socket) || ! $this->config['keepalive']) {
|
192 |
+
$context = $this->getStreamContext();
|
193 |
+
if ($secure) {
|
194 |
+
if ($this->config['sslcert'] !== null) {
|
195 |
+
if (! stream_context_set_option($context, 'ssl', 'local_cert',
|
196 |
+
$this->config['sslcert'])) {
|
197 |
+
//require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
198 |
+
throw new Microsoft_Http_Client_Adapter_Exception('Unable to set sslcert option');
|
199 |
+
}
|
200 |
+
}
|
201 |
+
if ($this->config['sslpassphrase'] !== null) {
|
202 |
+
if (! stream_context_set_option($context, 'ssl', 'passphrase',
|
203 |
+
$this->config['sslpassphrase'])) {
|
204 |
+
//require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
205 |
+
throw new Microsoft_Http_Client_Adapter_Exception('Unable to set sslpassphrase option');
|
206 |
+
}
|
207 |
+
}
|
208 |
+
}
|
209 |
+
|
210 |
+
$flags = STREAM_CLIENT_CONNECT;
|
211 |
+
if ($this->config['persistent']) $flags |= STREAM_CLIENT_PERSISTENT;
|
212 |
+
|
213 |
+
$this->socket = @stream_socket_client($host . ':' . $port,
|
214 |
+
$errno,
|
215 |
+
$errstr,
|
216 |
+
(int) $this->config['timeout'],
|
217 |
+
$flags,
|
218 |
+
$context);
|
219 |
+
|
220 |
+
if (! $this->socket) {
|
221 |
+
$this->close();
|
222 |
+
//require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
223 |
+
throw new Microsoft_Http_Client_Adapter_Exception(
|
224 |
+
'Unable to Connect to ' . $host . ':' . $port . '. Error #' . $errno . ': ' . $errstr);
|
225 |
+
}
|
226 |
+
|
227 |
+
// Set the stream timeout
|
228 |
+
if (! stream_set_timeout($this->socket, (int) $this->config['timeout'])) {
|
229 |
+
//require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
230 |
+
throw new Microsoft_Http_Client_Adapter_Exception('Unable to set the connection timeout');
|
231 |
+
}
|
232 |
+
|
233 |
+
// Update connected_to
|
234 |
+
$this->connected_to = array($host, $port);
|
235 |
+
}
|
236 |
+
}
|
237 |
+
|
238 |
+
/**
|
239 |
+
* Send request to the remote server
|
240 |
+
*
|
241 |
+
* @param string $method
|
242 |
+
* @param Microsoft_Uri_Http $uri
|
243 |
+
* @param string $http_ver
|
244 |
+
* @param array $headers
|
245 |
+
* @param string $body
|
246 |
+
* @return string Request as string
|
247 |
+
*/
|
248 |
+
public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
|
249 |
+
{
|
250 |
+
// Make sure we're properly connected
|
251 |
+
if (! $this->socket) {
|
252 |
+
//require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
253 |
+
throw new Microsoft_Http_Client_Adapter_Exception('Trying to write but we are not connected');
|
254 |
+
}
|
255 |
+
|
256 |
+
$host = $uri->getHost();
|
257 |
+
$host = (strtolower($uri->getScheme()) == 'https' ? $this->config['ssltransport'] : 'tcp') . '://' . $host;
|
258 |
+
if ($this->connected_to[0] != $host || $this->connected_to[1] != $uri->getPort()) {
|
259 |
+
//require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
260 |
+
throw new Microsoft_Http_Client_Adapter_Exception('Trying to write but we are connected to the wrong host');
|
261 |
+
}
|
262 |
+
|
263 |
+
// Save request method for later
|
264 |
+
$this->method = $method;
|
265 |
+
|
266 |
+
// Build request headers
|
267 |
+
$path = $uri->getPath();
|
268 |
+
if ($uri->getQuery()) $path .= '?' . $uri->getQuery();
|
269 |
+
$request = "{$method} {$path} HTTP/{$http_ver}\r\n";
|
270 |
+
foreach ($headers as $k => $v) {
|
271 |
+
if (is_string($k)) $v = ucfirst($k) . ": $v";
|
272 |
+
$request .= "$v\r\n";
|
273 |
+
}
|
274 |
+
|
275 |
+
if(is_resource($body)) {
|
276 |
+
$request .= "\r\n";
|
277 |
+
} else {
|
278 |
+
// Add the request body
|
279 |
+
$request .= "\r\n" . $body;
|
280 |
+
}
|
281 |
+
|
282 |
+
// Send the request
|
283 |
+
if (! @fwrite($this->socket, $request)) {
|
284 |
+
//require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
285 |
+
throw new Microsoft_Http_Client_Adapter_Exception('Error writing request to server');
|
286 |
+
}
|
287 |
+
|
288 |
+
if(is_resource($body)) {
|
289 |
+
if(stream_copy_to_stream($body, $this->socket) == 0) {
|
290 |
+
//require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
291 |
+
throw new Microsoft_Http_Client_Adapter_Exception('Error writing request to server');
|
292 |
+
}
|
293 |
+
}
|
294 |
+
|
295 |
+
return $request;
|
296 |
+
}
|
297 |
+
|
298 |
+
/**
|
299 |
+
* Read response from server
|
300 |
+
*
|
301 |
+
* @return string
|
302 |
+
*/
|
303 |
+
public function read()
|
304 |
+
{
|
305 |
+
// First, read headers only
|
306 |
+
$response = '';
|
307 |
+
$gotStatus = false;
|
308 |
+
$stream = !empty($this->config['stream']);
|
309 |
+
|
310 |
+
while (($line = @fgets($this->socket)) !== false) {
|
311 |
+
$gotStatus = $gotStatus || (strpos($line, 'HTTP') !== false);
|
312 |
+
if ($gotStatus) {
|
313 |
+
$response .= $line;
|
314 |
+
if (rtrim($line) === '') break;
|
315 |
+
}
|
316 |
+
}
|
317 |
+
|
318 |
+
$this->_checkSocketReadTimeout();
|
319 |
+
|
320 |
+
$statusCode = Microsoft_Http_Response::extractCode($response);
|
321 |
+
|
322 |
+
// Handle 100 and 101 responses internally by restarting the read again
|
323 |
+
if ($statusCode == 100 || $statusCode == 101) return $this->read();
|
324 |
+
|
325 |
+
// Check headers to see what kind of connection / transfer encoding we have
|
326 |
+
$headers = Microsoft_Http_Response::extractHeaders($response);
|
327 |
+
|
328 |
+
/**
|
329 |
+
* Responses to HEAD requests and 204 or 304 responses are not expected
|
330 |
+
* to have a body - stop reading here
|
331 |
+
*/
|
332 |
+
if ($statusCode == 304 || $statusCode == 204 ||
|
333 |
+
$this->method == Microsoft_Http_Client::HEAD) {
|
334 |
+
|
335 |
+
// Close the connection if requested to do so by the server
|
336 |
+
if (isset($headers['connection']) && $headers['connection'] == 'close') {
|
337 |
+
$this->close();
|
338 |
+
}
|
339 |
+
return $response;
|
340 |
+
}
|
341 |
+
|
342 |
+
// If we got a 'transfer-encoding: chunked' header
|
343 |
+
if (isset($headers['transfer-encoding'])) {
|
344 |
+
|
345 |
+
if (strtolower($headers['transfer-encoding']) == 'chunked') {
|
346 |
+
|
347 |
+
do {
|
348 |
+
$line = @fgets($this->socket);
|
349 |
+
$this->_checkSocketReadTimeout();
|
350 |
+
|
351 |
+
$chunk = $line;
|
352 |
+
|
353 |
+
// Figure out the next chunk size
|
354 |
+
$chunksize = trim($line);
|
355 |
+
if (! ctype_xdigit($chunksize)) {
|
356 |
+
$this->close();
|
357 |
+
//require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
358 |
+
throw new Microsoft_Http_Client_Adapter_Exception('Invalid chunk size "' .
|
359 |
+
$chunksize . '" unable to read chunked body');
|
360 |
+
}
|
361 |
+
|
362 |
+
// Convert the hexadecimal value to plain integer
|
363 |
+
$chunksize = hexdec($chunksize);
|
364 |
+
|
365 |
+
// Read next chunk
|
366 |
+
$read_to = ftell($this->socket) + $chunksize;
|
367 |
+
|
368 |
+
do {
|
369 |
+
$current_pos = ftell($this->socket);
|
370 |
+
if ($current_pos >= $read_to) break;
|
371 |
+
|
372 |
+
if($this->out_stream) {
|
373 |
+
if(stream_copy_to_stream($this->socket, $this->out_stream, $read_to - $current_pos) == 0) {
|
374 |
+
$this->_checkSocketReadTimeout();
|
375 |
+
break;
|
376 |
+
}
|
377 |
+
} else {
|
378 |
+
$line = @fread($this->socket, $read_to - $current_pos);
|
379 |
+
if ($line === false || strlen($line) === 0) {
|
380 |
+
$this->_checkSocketReadTimeout();
|
381 |
+
break;
|
382 |
+
}
|
383 |
+
$chunk .= $line;
|
384 |
+
}
|
385 |
+
} while (! feof($this->socket));
|
386 |
+
|
387 |
+
$chunk .= @fgets($this->socket);
|
388 |
+
$this->_checkSocketReadTimeout();
|
389 |
+
|
390 |
+
if(!$this->out_stream) {
|
391 |
+
$response .= $chunk;
|
392 |
+
}
|
393 |
+
} while ($chunksize > 0);
|
394 |
+
} else {
|
395 |
+
$this->close();
|
396 |
+
throw new Microsoft_Http_Client_Adapter_Exception('Cannot handle "' .
|
397 |
+
$headers['transfer-encoding'] . '" transfer encoding');
|
398 |
+
}
|
399 |
+
|
400 |
+
// We automatically decode chunked-messages when writing to a stream
|
401 |
+
// this means we have to disallow the Microsoft_Http_Response to do it again
|
402 |
+
if ($this->out_stream) {
|
403 |
+
$response = str_ireplace("Transfer-Encoding: chunked\r\n", '', $response);
|
404 |
+
}
|
405 |
+
// Else, if we got the content-length header, read this number of bytes
|
406 |
+
} elseif (isset($headers['content-length'])) {
|
407 |
+
|
408 |
+
$current_pos = ftell($this->socket);
|
409 |
+
$chunk = '';
|
410 |
+
|
411 |
+
for ($read_to = $current_pos + $headers['content-length'];
|
412 |
+
$read_to > $current_pos;
|
413 |
+
$current_pos = ftell($this->socket)) {
|
414 |
+
|
415 |
+
if($this->out_stream) {
|
416 |
+
if(@stream_copy_to_stream($this->socket, $this->out_stream, $read_to - $current_pos) == 0) {
|
417 |
+
$this->_checkSocketReadTimeout();
|
418 |
+
break;
|
419 |
+
}
|
420 |
+
} else {
|
421 |
+
$chunk = @fread($this->socket, $read_to - $current_pos);
|
422 |
+
if ($chunk === false || strlen($chunk) === 0) {
|
423 |
+
$this->_checkSocketReadTimeout();
|
424 |
+
break;
|
425 |
+
}
|
426 |
+
|
427 |
+
$response .= $chunk;
|
428 |
+
}
|
429 |
+
|
430 |
+
// Break if the connection ended prematurely
|
431 |
+
if (feof($this->socket)) break;
|
432 |
+
}
|
433 |
+
|
434 |
+
// Fallback: just read the response until EOF
|
435 |
+
} else {
|
436 |
+
|
437 |
+
do {
|
438 |
+
if($this->out_stream) {
|
439 |
+
if(@stream_copy_to_stream($this->socket, $this->out_stream) == 0) {
|
440 |
+
$this->_checkSocketReadTimeout();
|
441 |
+
break;
|
442 |
+
}
|
443 |
+
} else {
|
444 |
+
$buff = @fread($this->socket, 8192);
|
445 |
+
if ($buff === false || strlen($buff) === 0) {
|
446 |
+
$this->_checkSocketReadTimeout();
|
447 |
+
break;
|
448 |
+
} else {
|
449 |
+
$response .= $buff;
|
450 |
+
}
|
451 |
+
}
|
452 |
+
|
453 |
+
} while (feof($this->socket) === false);
|
454 |
+
|
455 |
+
$this->close();
|
456 |
+
}
|
457 |
+
|
458 |
+
// Close the connection if requested to do so by the server
|
459 |
+
if (isset($headers['connection']) && $headers['connection'] == 'close') {
|
460 |
+
$this->close();
|
461 |
+
}
|
462 |
+
|
463 |
+
return $response;
|
464 |
+
}
|
465 |
+
|
466 |
+
/**
|
467 |
+
* Close the connection to the server
|
468 |
+
*
|
469 |
+
*/
|
470 |
+
public function close()
|
471 |
+
{
|
472 |
+
if (is_resource($this->socket)) @fclose($this->socket);
|
473 |
+
$this->socket = null;
|
474 |
+
$this->connected_to = array(null, null);
|
475 |
+
}
|
476 |
+
|
477 |
+
/**
|
478 |
+
* Check if the socket has timed out - if so close connection and throw
|
479 |
+
* an exception
|
480 |
+
*
|
481 |
+
* @throws Microsoft_Http_Client_Adapter_Exception with READ_TIMEOUT code
|
482 |
+
*/
|
483 |
+
protected function _checkSocketReadTimeout()
|
484 |
+
{
|
485 |
+
if ($this->socket) {
|
486 |
+
$info = stream_get_meta_data($this->socket);
|
487 |
+
$timedout = $info['timed_out'];
|
488 |
+
if ($timedout) {
|
489 |
+
$this->close();
|
490 |
+
//require_once 'Microsoft/Http/Client/Adapter/Exception.php';
|
491 |
+
throw new Microsoft_Http_Client_Adapter_Exception(
|
492 |
+
"Read timed out after {$this->config['timeout']} seconds",
|
493 |
+
Microsoft_Http_Client_Adapter_Exception::READ_TIMEOUT
|
494 |
+
);
|
495 |
+
}
|
496 |
+
}
|
497 |
+
}
|
498 |
+
|
499 |
+
/**
|
500 |
+
* Set output stream for the response
|
501 |
+
*
|
502 |
+
* @param resource $stream
|
503 |
+
* @return Microsoft_Http_Client_Adapter_Socket
|
504 |
+
*/
|
505 |
+
public function setOutputStream($stream)
|
506 |
+
{
|
507 |
+
$this->out_stream = $stream;
|
508 |
+
return $this;
|
509 |
+
}
|
510 |
+
|
511 |
+
/**
|
512 |
+
* Destructor: make sure the socket is disconnected
|
513 |
+
*
|
514 |
+
* If we are in persistent TCP mode, will not close the connection
|
515 |
+
*
|
516 |
+
*/
|
517 |
+
public function __destruct()
|
518 |
+
{
|
519 |
+
if (! $this->config['persistent']) {
|
520 |
+
if ($this->socket) $this->close();
|
521 |
+
}
|
522 |
+
}
|
523 |
+
}
|
libs/Microsoft/Http/Client/Adapter/Stream.php
CHANGED
@@ -1,46 +1,46 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Zend Framework
|
5 |
-
*
|
6 |
-
* LICENSE
|
7 |
-
*
|
8 |
-
* This source file is subject to the new BSD license that is bundled
|
9 |
-
* with this package in the file LICENSE.txt.
|
10 |
-
* It is also available through the world-wide-web at this URL:
|
11 |
-
* http://framework.zend.com/license/new-bsd
|
12 |
-
* If you did not receive a copy of the license and are unable to
|
13 |
-
* obtain it through the world-wide-web, please send an email
|
14 |
-
* to license@zend.com so we can send you a copy immediately.
|
15 |
-
*
|
16 |
-
* @category Microsoft
|
17 |
-
* @package Microsoft_Http
|
18 |
-
* @subpackage Client_Adapter
|
19 |
-
* @version $Id: Interface.php 16214 2009-06-21 19:34:03Z thomas $
|
20 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
21 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
22 |
-
*/
|
23 |
-
|
24 |
-
/**
|
25 |
-
* An interface description for Microsoft_Http_Client_Adapter_Stream classes.
|
26 |
-
*
|
27 |
-
* This interface decribes Microsoft_Http_Client_Adapter which supports streaming.
|
28 |
-
*
|
29 |
-
* @category Microsoft
|
30 |
-
* @package Microsoft_Http
|
31 |
-
* @subpackage Client_Adapter
|
32 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
33 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
34 |
-
*/
|
35 |
-
interface Microsoft_Http_Client_Adapter_Stream
|
36 |
-
{
|
37 |
-
/**
|
38 |
-
* Set output stream
|
39 |
-
*
|
40 |
-
* This function sets output stream where the result will be stored.
|
41 |
-
*
|
42 |
-
* @param resource $stream Stream to write the output to
|
43 |
-
*
|
44 |
-
*/
|
45 |
-
function setOutputStream($stream);
|
46 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Zend Framework
|
5 |
+
*
|
6 |
+
* LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the new BSD license that is bundled
|
9 |
+
* with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://framework.zend.com/license/new-bsd
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@zend.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category Microsoft
|
17 |
+
* @package Microsoft_Http
|
18 |
+
* @subpackage Client_Adapter
|
19 |
+
* @version $Id: Interface.php 16214 2009-06-21 19:34:03Z thomas $
|
20 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
21 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
22 |
+
*/
|
23 |
+
|
24 |
+
/**
|
25 |
+
* An interface description for Microsoft_Http_Client_Adapter_Stream classes.
|
26 |
+
*
|
27 |
+
* This interface decribes Microsoft_Http_Client_Adapter which supports streaming.
|
28 |
+
*
|
29 |
+
* @category Microsoft
|
30 |
+
* @package Microsoft_Http
|
31 |
+
* @subpackage Client_Adapter
|
32 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
33 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
34 |
+
*/
|
35 |
+
interface Microsoft_Http_Client_Adapter_Stream
|
36 |
+
{
|
37 |
+
/**
|
38 |
+
* Set output stream
|
39 |
+
*
|
40 |
+
* This function sets output stream where the result will be stored.
|
41 |
+
*
|
42 |
+
* @param resource $stream Stream to write the output to
|
43 |
+
*
|
44 |
+
*/
|
45 |
+
function setOutputStream($stream);
|
46 |
+
}
|
libs/Microsoft/Http/Client/Exception.php
CHANGED
@@ -1,36 +1,36 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Zend Framework
|
4 |
-
*
|
5 |
-
* LICENSE
|
6 |
-
*
|
7 |
-
* This source file is subject to the new BSD license that is bundled
|
8 |
-
* with this package in the file LICENSE.txt.
|
9 |
-
* It is also available through the world-wide-web at this URL:
|
10 |
-
* http://framework.zend.com/license/new-bsd
|
11 |
-
* If you did not receive a copy of the license and are unable to
|
12 |
-
* obtain it through the world-wide-web, please send an email
|
13 |
-
* to license@zend.com so we can send you a copy immediately.
|
14 |
-
*
|
15 |
-
* @category Microsoft
|
16 |
-
* @package Microsoft_Http
|
17 |
-
* @subpackage Client_Exception
|
18 |
-
* @version $Id: Exception.php 16872 2009-07-20 11:47:08Z mikaelkael $
|
19 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
20 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
21 |
-
*/
|
22 |
-
|
23 |
-
/**
|
24 |
-
* @see Microsoft_AutoLoader
|
25 |
-
*/
|
26 |
-
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
27 |
-
|
28 |
-
/**
|
29 |
-
* @category Microsoft
|
30 |
-
* @package Microsoft_Http
|
31 |
-
* @subpackage Client
|
32 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
33 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
34 |
-
*/
|
35 |
-
class Microsoft_Http_Client_Exception extends Microsoft_Http_Exception
|
36 |
-
{}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Zend Framework
|
4 |
+
*
|
5 |
+
* LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the new BSD license that is bundled
|
8 |
+
* with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://framework.zend.com/license/new-bsd
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@zend.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* @category Microsoft
|
16 |
+
* @package Microsoft_Http
|
17 |
+
* @subpackage Client_Exception
|
18 |
+
* @version $Id: Exception.php 16872 2009-07-20 11:47:08Z mikaelkael $
|
19 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
20 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
21 |
+
*/
|
22 |
+
|
23 |
+
/**
|
24 |
+
* @see Microsoft_AutoLoader
|
25 |
+
*/
|
26 |
+
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
27 |
+
|
28 |
+
/**
|
29 |
+
* @category Microsoft
|
30 |
+
* @package Microsoft_Http
|
31 |
+
* @subpackage Client
|
32 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
33 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
34 |
+
*/
|
35 |
+
class Microsoft_Http_Client_Exception extends Microsoft_Http_Exception
|
36 |
+
{}
|
libs/Microsoft/Http/Cookie.php
CHANGED
@@ -1,408 +1,408 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Zend Framework
|
5 |
-
*
|
6 |
-
* LICENSE
|
7 |
-
*
|
8 |
-
* This source file is subject to the new BSD license that is bundled
|
9 |
-
* with this package in the file LICENSE.txt.
|
10 |
-
* It is also available through the world-wide-web at this URL:
|
11 |
-
* http://framework.zend.com/license/new-bsd
|
12 |
-
* If you did not receive a copy of the license and are unable to
|
13 |
-
* obtain it through the world-wide-web, please send an email
|
14 |
-
* to license@zend.com so we can send you a copy immediately.
|
15 |
-
*
|
16 |
-
* @category Microsoft
|
17 |
-
* @package Microsoft_Http
|
18 |
-
* @subpackage Cookie
|
19 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
20 |
-
* @version $Id: Cookie.php 17131 2009-07-26 10:03:39Z shahar $
|
21 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
22 |
-
*/
|
23 |
-
|
24 |
-
/**
|
25 |
-
* @see Microsoft_AutoLoader
|
26 |
-
*/
|
27 |
-
require_once dirname(__FILE__) . '/../AutoLoader.php';
|
28 |
-
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Microsoft_Http_Cookie is a class describing an HTTP cookie and all it's parameters.
|
32 |
-
*
|
33 |
-
* Microsoft_Http_Cookie is a class describing an HTTP cookie and all it's parameters. The
|
34 |
-
* class also enables validating whether the cookie should be sent to the server in
|
35 |
-
* a specified scenario according to the request URI, the expiry time and whether
|
36 |
-
* session cookies should be used or not. Generally speaking cookies should be
|
37 |
-
* contained in a Cookiejar object, or instantiated manually and added to an HTTP
|
38 |
-
* request.
|
39 |
-
*
|
40 |
-
* See http://wp.netscape.com/newsref/std/cookie_spec.html for some specs.
|
41 |
-
*
|
42 |
-
* @category Microsoft
|
43 |
-
* @package Microsoft_Http
|
44 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
45 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
46 |
-
*/
|
47 |
-
class Microsoft_Http_Cookie
|
48 |
-
{
|
49 |
-
/**
|
50 |
-
* Cookie name
|
51 |
-
*
|
52 |
-
* @var string
|
53 |
-
*/
|
54 |
-
protected $name;
|
55 |
-
|
56 |
-
/**
|
57 |
-
* Cookie value
|
58 |
-
*
|
59 |
-
* @var string
|
60 |
-
*/
|
61 |
-
protected $value;
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Cookie expiry date
|
65 |
-
*
|
66 |
-
* @var int
|
67 |
-
*/
|
68 |
-
protected $expires;
|
69 |
-
|
70 |
-
/**
|
71 |
-
* Cookie domain
|
72 |
-
*
|
73 |
-
* @var string
|
74 |
-
*/
|
75 |
-
protected $domain;
|
76 |
-
|
77 |
-
/**
|
78 |
-
* Cookie path
|
79 |
-
*
|
80 |
-
* @var string
|
81 |
-
*/
|
82 |
-
protected $path;
|
83 |
-
|
84 |
-
/**
|
85 |
-
* Whether the cookie is secure or not
|
86 |
-
*
|
87 |
-
* @var boolean
|
88 |
-
*/
|
89 |
-
protected $secure;
|
90 |
-
|
91 |
-
/**
|
92 |
-
* Cookie object constructor
|
93 |
-
*
|
94 |
-
* @todo Add validation of each one of the parameters (legal domain, etc.)
|
95 |
-
*
|
96 |
-
* @param string $name
|
97 |
-
* @param string $value
|
98 |
-
* @param string $domain
|
99 |
-
* @param int $expires
|
100 |
-
* @param string $path
|
101 |
-
* @param bool $secure
|
102 |
-
*/
|
103 |
-
public function __construct($name, $value, $domain, $expires = null, $path = null, $secure = false)
|
104 |
-
{
|
105 |
-
if (preg_match("/[=,; \t\r\n\013\014]/", $name)) {
|
106 |
-
require_once 'Microsoft/Http/Exception.php';
|
107 |
-
throw new Microsoft_Http_Exception("Cookie name cannot contain these characters: =,; \\t\\r\\n\\013\\014 ({$name})");
|
108 |
-
}
|
109 |
-
|
110 |
-
if (! $this->name = (string) $name) {
|
111 |
-
require_once 'Microsoft/Http/Exception.php';
|
112 |
-
throw new Microsoft_Http_Exception('Cookies must have a name');
|
113 |
-
}
|
114 |
-
|
115 |
-
if (! $this->domain = (string) $domain) {
|
116 |
-
require_once 'Microsoft/Http/Exception.php';
|
117 |
-
throw new Microsoft_Http_Exception('Cookies must have a domain');
|
118 |
-
}
|
119 |
-
|
120 |
-
$this->value = (string) $value;
|
121 |
-
$this->expires = ($expires === null ? null : (int) $expires);
|
122 |
-
$this->path = ($path ? $path : '/');
|
123 |
-
$this->secure = $secure;
|
124 |
-
}
|
125 |
-
|
126 |
-
/**
|
127 |
-
* Get Cookie name
|
128 |
-
*
|
129 |
-
* @return string
|
130 |
-
*/
|
131 |
-
public function getName()
|
132 |
-
{
|
133 |
-
return $this->name;
|
134 |
-
}
|
135 |
-
|
136 |
-
/**
|
137 |
-
* Get cookie value
|
138 |
-
*
|
139 |
-
* @return string
|
140 |
-
*/
|
141 |
-
public function getValue()
|
142 |
-
{
|
143 |
-
return $this->value;
|
144 |
-
}
|
145 |
-
|
146 |
-
/**
|
147 |
-
* Get cookie domain
|
148 |
-
*
|
149 |
-
* @return string
|
150 |
-
*/
|
151 |
-
public function getDomain()
|
152 |
-
{
|
153 |
-
return $this->domain;
|
154 |
-
}
|
155 |
-
|
156 |
-
/**
|
157 |
-
* Get the cookie path
|
158 |
-
*
|
159 |
-
* @return string
|
160 |
-
*/
|
161 |
-
public function getPath()
|
162 |
-
{
|
163 |
-
return $this->path;
|
164 |
-
}
|
165 |
-
|
166 |
-
/**
|
167 |
-
* Get the expiry time of the cookie, or null if no expiry time is set
|
168 |
-
*
|
169 |
-
* @return int|null
|
170 |
-
*/
|
171 |
-
public function getExpiryTime()
|
172 |
-
{
|
173 |
-
return $this->expires;
|
174 |
-
}
|
175 |
-
|
176 |
-
/**
|
177 |
-
* Check whether the cookie should only be sent over secure connections
|
178 |
-
*
|
179 |
-
* @return boolean
|
180 |
-
*/
|
181 |
-
public function isSecure()
|
182 |
-
{
|
183 |
-
return $this->secure;
|
184 |
-
}
|
185 |
-
|
186 |
-
/**
|
187 |
-
* Check whether the cookie has expired
|
188 |
-
*
|
189 |
-
* Always returns false if the cookie is a session cookie (has no expiry time)
|
190 |
-
*
|
191 |
-
* @param int $now Timestamp to consider as "now"
|
192 |
-
* @return boolean
|
193 |
-
*/
|
194 |
-
public function isExpired($now = null)
|
195 |
-
{
|
196 |
-
if ($now === null) $now = time();
|
197 |
-
if (is_int($this->expires) && $this->expires < $now) {
|
198 |
-
return true;
|
199 |
-
} else {
|
200 |
-
return false;
|
201 |
-
}
|
202 |
-
}
|
203 |
-
|
204 |
-
/**
|
205 |
-
* Check whether the cookie is a session cookie (has no expiry time set)
|
206 |
-
*
|
207 |
-
* @return boolean
|
208 |
-
*/
|
209 |
-
public function isSessionCookie()
|
210 |
-
{
|
211 |
-
return ($this->expires === null);
|
212 |
-
}
|
213 |
-
|
214 |
-
/**
|
215 |
-
* Checks whether the cookie should be sent or not in a specific scenario
|
216 |
-
*
|
217 |
-
* @param string|Microsoft_Uri_Http $uri URI to check against (secure, domain, path)
|
218 |
-
* @param boolean $matchSessionCookies Whether to send session cookies
|
219 |
-
* @param int $now Override the current time when checking for expiry time
|
220 |
-
* @return boolean
|
221 |
-
*/
|
222 |
-
public function match($uri, $matchSessionCookies = true, $now = null)
|
223 |
-
{
|
224 |
-
if (is_string ($uri)) {
|
225 |
-
$uri = Microsoft_Uri_Http::factory($uri);
|
226 |
-
}
|
227 |
-
|
228 |
-
// Make sure we have a valid Microsoft_Uri_Http object
|
229 |
-
if (! ($uri->valid() && ($uri->getScheme() == 'http' || $uri->getScheme() =='https'))) {
|
230 |
-
require_once 'Microsoft/Http/Exception.php';
|
231 |
-
throw new Microsoft_Http_Exception('Passed URI is not a valid HTTP or HTTPS URI');
|
232 |
-
}
|
233 |
-
|
234 |
-
// Check that the cookie is secure (if required) and not expired
|
235 |
-
if ($this->secure && $uri->getScheme() != 'https') return false;
|
236 |
-
if ($this->isExpired($now)) return false;
|
237 |
-
if ($this->isSessionCookie() && ! $matchSessionCookies) return false;
|
238 |
-
|
239 |
-
// Check if the domain matches
|
240 |
-
if (! self::matchCookieDomain($this->getDomain(), $uri->getHost())) {
|
241 |
-
return false;
|
242 |
-
}
|
243 |
-
|
244 |
-
// Check that path matches using prefix match
|
245 |
-
if (! self::matchCookiePath($this->getPath(), $uri->getPath())) {
|
246 |
-
return false;
|
247 |
-
}
|
248 |
-
|
249 |
-
// If we didn't die until now, return true.
|
250 |
-
return true;
|
251 |
-
}
|
252 |
-
|
253 |
-
/**
|
254 |
-
* Get the cookie as a string, suitable for sending as a "Cookie" header in an
|
255 |
-
* HTTP request
|
256 |
-
*
|
257 |
-
* @return string
|
258 |
-
*/
|
259 |
-
public function __toString()
|
260 |
-
{
|
261 |
-
return $this->name . '=' . urlencode($this->value) . ';';
|
262 |
-
}
|
263 |
-
|
264 |
-
/**
|
265 |
-
* Generate a new Cookie object from a cookie string
|
266 |
-
* (for example the value of the Set-Cookie HTTP header)
|
267 |
-
*
|
268 |
-
* @param string $cookieStr
|
269 |
-
* @param Microsoft_Uri_Http|string $ref_uri Reference URI for default values (domain, path)
|
270 |
-
* @return Microsoft_Http_Cookie A new Microsoft_Http_Cookie object or false on failure.
|
271 |
-
*/
|
272 |
-
public static function fromString($cookieStr, $ref_uri = null)
|
273 |
-
{
|
274 |
-
// Set default values
|
275 |
-
if (is_string($ref_uri)) {
|
276 |
-
$ref_uri = Microsoft_Uri_Http::factory($ref_uri);
|
277 |
-
}
|
278 |
-
|
279 |
-
$name = '';
|
280 |
-
$value = '';
|
281 |
-
$domain = '';
|
282 |
-
$path = '';
|
283 |
-
$expires = null;
|
284 |
-
$secure = false;
|
285 |
-
$parts = explode(';', $cookieStr);
|
286 |
-
|
287 |
-
// If first part does not include '=', fail
|
288 |
-
if (strpos($parts[0], '=') === false) return false;
|
289 |
-
|
290 |
-
// Get the name and value of the cookie
|
291 |
-
list($name, $value) = explode('=', trim(array_shift($parts)), 2);
|
292 |
-
$name = trim($name);
|
293 |
-
$value = urldecode(trim($value));
|
294 |
-
|
295 |
-
// Set default domain and path
|
296 |
-
if ($ref_uri instanceof Microsoft_Uri_Http) {
|
297 |
-
$domain = $ref_uri->getHost();
|
298 |
-
$path = $ref_uri->getPath();
|
299 |
-
$path = substr($path, 0, strrpos($path, '/'));
|
300 |
-
}
|
301 |
-
|
302 |
-
// Set other cookie parameters
|
303 |
-
foreach ($parts as $part) {
|
304 |
-
$part = trim($part);
|
305 |
-
if (strtolower($part) == 'secure') {
|
306 |
-
$secure = true;
|
307 |
-
continue;
|
308 |
-
}
|
309 |
-
|
310 |
-
$keyValue = explode('=', $part, 2);
|
311 |
-
if (count($keyValue) == 2) {
|
312 |
-
list($k, $v) = $keyValue;
|
313 |
-
switch (strtolower($k)) {
|
314 |
-
case 'expires':
|
315 |
-
if(($expires = strtotime($v)) === false) {
|
316 |
-
/**
|
317 |
-
* The expiration is past Tue, 19 Jan 2038 03:14:07 UTC
|
318 |
-
* the maximum for 32-bit signed integer. Microsoft_Date
|
319 |
-
* can get around that limit.
|
320 |
-
*
|
321 |
-
* @see Microsoft_Date
|
322 |
-
*/
|
323 |
-
require_once 'Microsoft/Date.php';
|
324 |
-
|
325 |
-
$expireDate = new Microsoft_Date($v);
|
326 |
-
$expires = $expireDate->getTimestamp();
|
327 |
-
}
|
328 |
-
break;
|
329 |
-
|
330 |
-
case 'path':
|
331 |
-
$path = $v;
|
332 |
-
break;
|
333 |
-
|
334 |
-
case 'domain':
|
335 |
-
$domain = $v;
|
336 |
-
break;
|
337 |
-
|
338 |
-
default:
|
339 |
-
break;
|
340 |
-
}
|
341 |
-
}
|
342 |
-
}
|
343 |
-
|
344 |
-
if ($name !== '') {
|
345 |
-
return new self($name, $value, $domain, $expires, $path, $secure);
|
346 |
-
} else {
|
347 |
-
return false;
|
348 |
-
}
|
349 |
-
}
|
350 |
-
|
351 |
-
/**
|
352 |
-
* Check if a cookie's domain matches a host name.
|
353 |
-
*
|
354 |
-
* Used by Microsoft_Http_Cookie and Microsoft_Http_CookieJar for cookie matching
|
355 |
-
*
|
356 |
-
* @param string $cookieDomain
|
357 |
-
* @param string $host
|
358 |
-
*
|
359 |
-
* @return boolean
|
360 |
-
*/
|
361 |
-
public static function matchCookieDomain($cookieDomain, $host)
|
362 |
-
{
|
363 |
-
if (! $cookieDomain) {
|
364 |
-
require_once 'Microsoft/Http/Exception.php';
|
365 |
-
throw new Microsoft_Http_Exception("\$cookieDomain is expected to be a cookie domain");
|
366 |
-
}
|
367 |
-
|
368 |
-
if (! $host) {
|
369 |
-
require_once 'Microsoft/Http/Exception.php';
|
370 |
-
throw new Microsoft_Http_Exception("\$host is expected to be a host name");
|
371 |
-
}
|
372 |
-
|
373 |
-
$cookieDomain = strtolower($cookieDomain);
|
374 |
-
$host = strtolower($host);
|
375 |
-
|
376 |
-
if ($cookieDomain[0] == '.') {
|
377 |
-
$cookieDomain = substr($cookieDomain, 1);
|
378 |
-
}
|
379 |
-
|
380 |
-
// Check for either exact match or suffix match
|
381 |
-
return ($cookieDomain == $host ||
|
382 |
-
preg_match("/\.$cookieDomain$/", $host));
|
383 |
-
}
|
384 |
-
|
385 |
-
/**
|
386 |
-
* Check if a cookie's path matches a URL path
|
387 |
-
*
|
388 |
-
* Used by Microsoft_Http_Cookie and Microsoft_Http_CookieJar for cookie matching
|
389 |
-
*
|
390 |
-
* @param string $cookiePath
|
391 |
-
* @param string $path
|
392 |
-
* @return boolean
|
393 |
-
*/
|
394 |
-
public static function matchCookiePath($cookiePath, $path)
|
395 |
-
{
|
396 |
-
if (! $cookiePath) {
|
397 |
-
require_once 'Microsoft/Http/Exception.php';
|
398 |
-
throw new Microsoft_Http_Exception("\$cookiePath is expected to be a cookie path");
|
399 |
-
}
|
400 |
-
|
401 |
-
if (! $path) {
|
402 |
-
require_once 'Microsoft/Http/Exception.php';
|
403 |
-
throw new Microsoft_Http_Exception("\$path is expected to be a host name");
|
404 |
-
}
|
405 |
-
|
406 |
-
return (strpos($path, $cookiePath) === 0);
|
407 |
-
}
|
408 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Zend Framework
|
5 |
+
*
|
6 |
+
* LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the new BSD license that is bundled
|
9 |
+
* with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://framework.zend.com/license/new-bsd
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@zend.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category Microsoft
|
17 |
+
* @package Microsoft_Http
|
18 |
+
* @subpackage Cookie
|
19 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
20 |
+
* @version $Id: Cookie.php 17131 2009-07-26 10:03:39Z shahar $
|
21 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
22 |
+
*/
|
23 |
+
|
24 |
+
/**
|
25 |
+
* @see Microsoft_AutoLoader
|
26 |
+
*/
|
27 |
+
require_once dirname(__FILE__) . '/../AutoLoader.php';
|
28 |
+
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Microsoft_Http_Cookie is a class describing an HTTP cookie and all it's parameters.
|
32 |
+
*
|
33 |
+
* Microsoft_Http_Cookie is a class describing an HTTP cookie and all it's parameters. The
|
34 |
+
* class also enables validating whether the cookie should be sent to the server in
|
35 |
+
* a specified scenario according to the request URI, the expiry time and whether
|
36 |
+
* session cookies should be used or not. Generally speaking cookies should be
|
37 |
+
* contained in a Cookiejar object, or instantiated manually and added to an HTTP
|
38 |
+
* request.
|
39 |
+
*
|
40 |
+
* See http://wp.netscape.com/newsref/std/cookie_spec.html for some specs.
|
41 |
+
*
|
42 |
+
* @category Microsoft
|
43 |
+
* @package Microsoft_Http
|
44 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
45 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
46 |
+
*/
|
47 |
+
class Microsoft_Http_Cookie
|
48 |
+
{
|
49 |
+
/**
|
50 |
+
* Cookie name
|
51 |
+
*
|
52 |
+
* @var string
|
53 |
+
*/
|
54 |
+
protected $name;
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Cookie value
|
58 |
+
*
|
59 |
+
* @var string
|
60 |
+
*/
|
61 |
+
protected $value;
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Cookie expiry date
|
65 |
+
*
|
66 |
+
* @var int
|
67 |
+
*/
|
68 |
+
protected $expires;
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Cookie domain
|
72 |
+
*
|
73 |
+
* @var string
|
74 |
+
*/
|
75 |
+
protected $domain;
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Cookie path
|
79 |
+
*
|
80 |
+
* @var string
|
81 |
+
*/
|
82 |
+
protected $path;
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Whether the cookie is secure or not
|
86 |
+
*
|
87 |
+
* @var boolean
|
88 |
+
*/
|
89 |
+
protected $secure;
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Cookie object constructor
|
93 |
+
*
|
94 |
+
* @todo Add validation of each one of the parameters (legal domain, etc.)
|
95 |
+
*
|
96 |
+
* @param string $name
|
97 |
+
* @param string $value
|
98 |
+
* @param string $domain
|
99 |
+
* @param int $expires
|
100 |
+
* @param string $path
|
101 |
+
* @param bool $secure
|
102 |
+
*/
|
103 |
+
public function __construct($name, $value, $domain, $expires = null, $path = null, $secure = false)
|
104 |
+
{
|
105 |
+
if (preg_match("/[=,; \t\r\n\013\014]/", $name)) {
|
106 |
+
require_once 'Microsoft/Http/Exception.php';
|
107 |
+
throw new Microsoft_Http_Exception("Cookie name cannot contain these characters: =,; \\t\\r\\n\\013\\014 ({$name})");
|
108 |
+
}
|
109 |
+
|
110 |
+
if (! $this->name = (string) $name) {
|
111 |
+
require_once 'Microsoft/Http/Exception.php';
|
112 |
+
throw new Microsoft_Http_Exception('Cookies must have a name');
|
113 |
+
}
|
114 |
+
|
115 |
+
if (! $this->domain = (string) $domain) {
|
116 |
+
require_once 'Microsoft/Http/Exception.php';
|
117 |
+
throw new Microsoft_Http_Exception('Cookies must have a domain');
|
118 |
+
}
|
119 |
+
|
120 |
+
$this->value = (string) $value;
|
121 |
+
$this->expires = ($expires === null ? null : (int) $expires);
|
122 |
+
$this->path = ($path ? $path : '/');
|
123 |
+
$this->secure = $secure;
|
124 |
+
}
|
125 |
+
|
126 |
+
/**
|
127 |
+
* Get Cookie name
|
128 |
+
*
|
129 |
+
* @return string
|
130 |
+
*/
|
131 |
+
public function getName()
|
132 |
+
{
|
133 |
+
return $this->name;
|
134 |
+
}
|
135 |
+
|
136 |
+
/**
|
137 |
+
* Get cookie value
|
138 |
+
*
|
139 |
+
* @return string
|
140 |
+
*/
|
141 |
+
public function getValue()
|
142 |
+
{
|
143 |
+
return $this->value;
|
144 |
+
}
|
145 |
+
|
146 |
+
/**
|
147 |
+
* Get cookie domain
|
148 |
+
*
|
149 |
+
* @return string
|
150 |
+
*/
|
151 |
+
public function getDomain()
|
152 |
+
{
|
153 |
+
return $this->domain;
|
154 |
+
}
|
155 |
+
|
156 |
+
/**
|
157 |
+
* Get the cookie path
|
158 |
+
*
|
159 |
+
* @return string
|
160 |
+
*/
|
161 |
+
public function getPath()
|
162 |
+
{
|
163 |
+
return $this->path;
|
164 |
+
}
|
165 |
+
|
166 |
+
/**
|
167 |
+
* Get the expiry time of the cookie, or null if no expiry time is set
|
168 |
+
*
|
169 |
+
* @return int|null
|
170 |
+
*/
|
171 |
+
public function getExpiryTime()
|
172 |
+
{
|
173 |
+
return $this->expires;
|
174 |
+
}
|
175 |
+
|
176 |
+
/**
|
177 |
+
* Check whether the cookie should only be sent over secure connections
|
178 |
+
*
|
179 |
+
* @return boolean
|
180 |
+
*/
|
181 |
+
public function isSecure()
|
182 |
+
{
|
183 |
+
return $this->secure;
|
184 |
+
}
|
185 |
+
|
186 |
+
/**
|
187 |
+
* Check whether the cookie has expired
|
188 |
+
*
|
189 |
+
* Always returns false if the cookie is a session cookie (has no expiry time)
|
190 |
+
*
|
191 |
+
* @param int $now Timestamp to consider as "now"
|
192 |
+
* @return boolean
|
193 |
+
*/
|
194 |
+
public function isExpired($now = null)
|
195 |
+
{
|
196 |
+
if ($now === null) $now = time();
|
197 |
+
if (is_int($this->expires) && $this->expires < $now) {
|
198 |
+
return true;
|
199 |
+
} else {
|
200 |
+
return false;
|
201 |
+
}
|
202 |
+
}
|
203 |
+
|
204 |
+
/**
|
205 |
+
* Check whether the cookie is a session cookie (has no expiry time set)
|
206 |
+
*
|
207 |
+
* @return boolean
|
208 |
+
*/
|
209 |
+
public function isSessionCookie()
|
210 |
+
{
|
211 |
+
return ($this->expires === null);
|
212 |
+
}
|
213 |
+
|
214 |
+
/**
|
215 |
+
* Checks whether the cookie should be sent or not in a specific scenario
|
216 |
+
*
|
217 |
+
* @param string|Microsoft_Uri_Http $uri URI to check against (secure, domain, path)
|
218 |
+
* @param boolean $matchSessionCookies Whether to send session cookies
|
219 |
+
* @param int $now Override the current time when checking for expiry time
|
220 |
+
* @return boolean
|
221 |
+
*/
|
222 |
+
public function match($uri, $matchSessionCookies = true, $now = null)
|
223 |
+
{
|
224 |
+
if (is_string ($uri)) {
|
225 |
+
$uri = Microsoft_Uri_Http::factory($uri);
|
226 |
+
}
|
227 |
+
|
228 |
+
// Make sure we have a valid Microsoft_Uri_Http object
|
229 |
+
if (! ($uri->valid() && ($uri->getScheme() == 'http' || $uri->getScheme() =='https'))) {
|
230 |
+
require_once 'Microsoft/Http/Exception.php';
|
231 |
+
throw new Microsoft_Http_Exception('Passed URI is not a valid HTTP or HTTPS URI');
|
232 |
+
}
|
233 |
+
|
234 |
+
// Check that the cookie is secure (if required) and not expired
|
235 |
+
if ($this->secure && $uri->getScheme() != 'https') return false;
|
236 |
+
if ($this->isExpired($now)) return false;
|
237 |
+
if ($this->isSessionCookie() && ! $matchSessionCookies) return false;
|
238 |
+
|
239 |
+
// Check if the domain matches
|
240 |
+
if (! self::matchCookieDomain($this->getDomain(), $uri->getHost())) {
|
241 |
+
return false;
|
242 |
+
}
|
243 |
+
|
244 |
+
// Check that path matches using prefix match
|
245 |
+
if (! self::matchCookiePath($this->getPath(), $uri->getPath())) {
|
246 |
+
return false;
|
247 |
+
}
|
248 |
+
|
249 |
+
// If we didn't die until now, return true.
|
250 |
+
return true;
|
251 |
+
}
|
252 |
+
|
253 |
+
/**
|
254 |
+
* Get the cookie as a string, suitable for sending as a "Cookie" header in an
|
255 |
+
* HTTP request
|
256 |
+
*
|
257 |
+
* @return string
|
258 |
+
*/
|
259 |
+
public function __toString()
|
260 |
+
{
|
261 |
+
return $this->name . '=' . urlencode($this->value) . ';';
|
262 |
+
}
|
263 |
+
|
264 |
+
/**
|
265 |
+
* Generate a new Cookie object from a cookie string
|
266 |
+
* (for example the value of the Set-Cookie HTTP header)
|
267 |
+
*
|
268 |
+
* @param string $cookieStr
|
269 |
+
* @param Microsoft_Uri_Http|string $ref_uri Reference URI for default values (domain, path)
|
270 |
+
* @return Microsoft_Http_Cookie A new Microsoft_Http_Cookie object or false on failure.
|
271 |
+
*/
|
272 |
+
public static function fromString($cookieStr, $ref_uri = null)
|
273 |
+
{
|
274 |
+
// Set default values
|
275 |
+
if (is_string($ref_uri)) {
|
276 |
+
$ref_uri = Microsoft_Uri_Http::factory($ref_uri);
|
277 |
+
}
|
278 |
+
|
279 |
+
$name = '';
|
280 |
+
$value = '';
|
281 |
+
$domain = '';
|
282 |
+
$path = '';
|
283 |
+
$expires = null;
|
284 |
+
$secure = false;
|
285 |
+
$parts = explode(';', $cookieStr);
|
286 |
+
|
287 |
+
// If first part does not include '=', fail
|
288 |
+
if (strpos($parts[0], '=') === false) return false;
|
289 |
+
|
290 |
+
// Get the name and value of the cookie
|
291 |
+
list($name, $value) = explode('=', trim(array_shift($parts)), 2);
|
292 |
+
$name = trim($name);
|
293 |
+
$value = urldecode(trim($value));
|
294 |
+
|
295 |
+
// Set default domain and path
|
296 |
+
if ($ref_uri instanceof Microsoft_Uri_Http) {
|
297 |
+
$domain = $ref_uri->getHost();
|
298 |
+
$path = $ref_uri->getPath();
|
299 |
+
$path = substr($path, 0, strrpos($path, '/'));
|
300 |
+
}
|
301 |
+
|
302 |
+
// Set other cookie parameters
|
303 |
+
foreach ($parts as $part) {
|
304 |
+
$part = trim($part);
|
305 |
+
if (strtolower($part) == 'secure') {
|
306 |
+
$secure = true;
|
307 |
+
continue;
|
308 |
+
}
|
309 |
+
|
310 |
+
$keyValue = explode('=', $part, 2);
|
311 |
+
if (count($keyValue) == 2) {
|
312 |
+
list($k, $v) = $keyValue;
|
313 |
+
switch (strtolower($k)) {
|
314 |
+
case 'expires':
|
315 |
+
if(($expires = strtotime($v)) === false) {
|
316 |
+
/**
|
317 |
+
* The expiration is past Tue, 19 Jan 2038 03:14:07 UTC
|
318 |
+
* the maximum for 32-bit signed integer. Microsoft_Date
|
319 |
+
* can get around that limit.
|
320 |
+
*
|
321 |
+
* @see Microsoft_Date
|
322 |
+
*/
|
323 |
+
require_once 'Microsoft/Date.php';
|
324 |
+
|
325 |
+
$expireDate = new Microsoft_Date($v);
|
326 |
+
$expires = $expireDate->getTimestamp();
|
327 |
+
}
|
328 |
+
break;
|
329 |
+
|
330 |
+
case 'path':
|
331 |
+
$path = $v;
|
332 |
+
break;
|
333 |
+
|
334 |
+
case 'domain':
|
335 |
+
$domain = $v;
|
336 |
+
break;
|
337 |
+
|
338 |
+
default:
|
339 |
+
break;
|
340 |
+
}
|
341 |
+
}
|
342 |
+
}
|
343 |
+
|
344 |
+
if ($name !== '') {
|
345 |
+
return new self($name, $value, $domain, $expires, $path, $secure);
|
346 |
+
} else {
|
347 |
+
return false;
|
348 |
+
}
|
349 |
+
}
|
350 |
+
|
351 |
+
/**
|
352 |
+
* Check if a cookie's domain matches a host name.
|
353 |
+
*
|
354 |
+
* Used by Microsoft_Http_Cookie and Microsoft_Http_CookieJar for cookie matching
|
355 |
+
*
|
356 |
+
* @param string $cookieDomain
|
357 |
+
* @param string $host
|
358 |
+
*
|
359 |
+
* @return boolean
|
360 |
+
*/
|
361 |
+
public static function matchCookieDomain($cookieDomain, $host)
|
362 |
+
{
|
363 |
+
if (! $cookieDomain) {
|
364 |
+
require_once 'Microsoft/Http/Exception.php';
|
365 |
+
throw new Microsoft_Http_Exception("\$cookieDomain is expected to be a cookie domain");
|
366 |
+
}
|
367 |
+
|
368 |
+
if (! $host) {
|
369 |
+
require_once 'Microsoft/Http/Exception.php';
|
370 |
+
throw new Microsoft_Http_Exception("\$host is expected to be a host name");
|
371 |
+
}
|
372 |
+
|
373 |
+
$cookieDomain = strtolower($cookieDomain);
|
374 |
+
$host = strtolower($host);
|
375 |
+
|
376 |
+
if ($cookieDomain[0] == '.') {
|
377 |
+
$cookieDomain = substr($cookieDomain, 1);
|
378 |
+
}
|
379 |
+
|
380 |
+
// Check for either exact match or suffix match
|
381 |
+
return ($cookieDomain == $host ||
|
382 |
+
preg_match("/\.$cookieDomain$/", $host));
|
383 |
+
}
|
384 |
+
|
385 |
+
/**
|
386 |
+
* Check if a cookie's path matches a URL path
|
387 |
+
*
|
388 |
+
* Used by Microsoft_Http_Cookie and Microsoft_Http_CookieJar for cookie matching
|
389 |
+
*
|
390 |
+
* @param string $cookiePath
|
391 |
+
* @param string $path
|
392 |
+
* @return boolean
|
393 |
+
*/
|
394 |
+
public static function matchCookiePath($cookiePath, $path)
|
395 |
+
{
|
396 |
+
if (! $cookiePath) {
|
397 |
+
require_once 'Microsoft/Http/Exception.php';
|
398 |
+
throw new Microsoft_Http_Exception("\$cookiePath is expected to be a cookie path");
|
399 |
+
}
|
400 |
+
|
401 |
+
if (! $path) {
|
402 |
+
require_once 'Microsoft/Http/Exception.php';
|
403 |
+
throw new Microsoft_Http_Exception("\$path is expected to be a host name");
|
404 |
+
}
|
405 |
+
|
406 |
+
return (strpos($path, $cookiePath) === 0);
|
407 |
+
}
|
408 |
+
}
|
libs/Microsoft/Http/CookieJar.php
CHANGED
@@ -1,395 +1,395 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Zend Framework
|
4 |
-
*
|
5 |
-
* LICENSE
|
6 |
-
*
|
7 |
-
* This source file is subject to the new BSD license that is bundled
|
8 |
-
* with this package in the file LICENSE.txt.
|
9 |
-
* It is also available through the world-wide-web at this URL:
|
10 |
-
* http://framework.zend.com/license/new-bsd
|
11 |
-
* If you did not receive a copy of the license and are unable to
|
12 |
-
* obtain it through the world-wide-web, please send an email
|
13 |
-
* to license@zend.com so we can send you a copy immediately.
|
14 |
-
*
|
15 |
-
* @category Microsoft
|
16 |
-
* @package Microsoft_Http
|
17 |
-
* @subpackage CookieJar
|
18 |
-
* @version $Id: CookieJar.php 17131 2009-07-26 10:03:39Z shahar $
|
19 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
20 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
21 |
-
*/
|
22 |
-
|
23 |
-
/**
|
24 |
-
* @see Microsoft_AutoLoader
|
25 |
-
*/
|
26 |
-
require_once dirname(__FILE__) . '/../AutoLoader.php';
|
27 |
-
|
28 |
-
/**
|
29 |
-
* A Microsoft_Http_CookieJar object is designed to contain and maintain HTTP cookies, and should
|
30 |
-
* be used along with Microsoft_Http_Client in order to manage cookies across HTTP requests and
|
31 |
-
* responses.
|
32 |
-
*
|
33 |
-
* The class contains an array of Microsoft_Http_Cookie objects. Cookies can be added to the jar
|
34 |
-
* automatically from a request or manually. Then, the jar can find and return the cookies
|
35 |
-
* needed for a specific HTTP request.
|
36 |
-
*
|
37 |
-
* A special parameter can be passed to all methods of this class that return cookies: Cookies
|
38 |
-
* can be returned either in their native form (as Microsoft_Http_Cookie objects) or as strings -
|
39 |
-
* the later is suitable for sending as the value of the "Cookie" header in an HTTP request.
|
40 |
-
* You can also choose, when returning more than one cookie, whether to get an array of strings
|
41 |
-
* (by passing Microsoft_Http_CookieJar::COOKIE_STRING_ARRAY) or one unified string for all cookies
|
42 |
-
* (by passing Microsoft_Http_CookieJar::COOKIE_STRING_CONCAT).
|
43 |
-
*
|
44 |
-
* @link http://wp.netscape.com/newsref/std/cookie_spec.html for some specs.
|
45 |
-
*
|
46 |
-
* @category Microsoft
|
47 |
-
* @package Microsoft_Http
|
48 |
-
* @subpackage CookieJar
|
49 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
50 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
51 |
-
*/
|
52 |
-
class Microsoft_Http_CookieJar implements Countable, IteratorAggregate
|
53 |
-
{
|
54 |
-
/**
|
55 |
-
* Return cookie(s) as a Microsoft_Http_Cookie object
|
56 |
-
*
|
57 |
-
*/
|
58 |
-
const COOKIE_OBJECT = 0;
|
59 |
-
|
60 |
-
/**
|
61 |
-
* Return cookie(s) as a string (suitable for sending in an HTTP request)
|
62 |
-
*
|
63 |
-
*/
|
64 |
-
const COOKIE_STRING_ARRAY = 1;
|
65 |
-
|
66 |
-
/**
|
67 |
-
* Return all cookies as one long string (suitable for sending in an HTTP request)
|
68 |
-
*
|
69 |
-
*/
|
70 |
-
const COOKIE_STRING_CONCAT = 2;
|
71 |
-
|
72 |
-
/**
|
73 |
-
* Array storing cookies
|
74 |
-
*
|
75 |
-
* Cookies are stored according to domain and path:
|
76 |
-
* $cookies
|
77 |
-
* + www.mydomain.com
|
78 |
-
* + /
|
79 |
-
* - cookie1
|
80 |
-
* - cookie2
|
81 |
-
* + /somepath
|
82 |
-
* - othercookie
|
83 |
-
* + www.otherdomain.net
|
84 |
-
* + /
|
85 |
-
* - alsocookie
|
86 |
-
*
|
87 |
-
* @var array
|
88 |
-
*/
|
89 |
-
protected $cookies = array();
|
90 |
-
|
91 |
-
/**
|
92 |
-
* The Microsoft_Http_Cookie array
|
93 |
-
*
|
94 |
-
* @var array
|
95 |
-
*/
|
96 |
-
protected $_rawCookies = array();
|
97 |
-
|
98 |
-
/**
|
99 |
-
* Construct a new CookieJar object
|
100 |
-
*
|
101 |
-
*/
|
102 |
-
public function __construct()
|
103 |
-
{ }
|
104 |
-
|
105 |
-
/**
|
106 |
-
* Add a cookie to the jar. Cookie should be passed either as a Microsoft_Http_Cookie object
|
107 |
-
* or as a string - in which case an object is created from the string.
|
108 |
-
*
|
109 |
-
* @param Microsoft_Http_Cookie|string $cookie
|
110 |
-
* @param Microsoft_Uri_Http|string $ref_uri Optional reference URI (for domain, path, secure)
|
111 |
-
*/
|
112 |
-
public function addCookie($cookie, $ref_uri = null)
|
113 |
-
{
|
114 |
-
if (is_string($cookie)) {
|
115 |
-
$cookie = Microsoft_Http_Cookie::fromString($cookie, $ref_uri);
|
116 |
-
}
|
117 |
-
|
118 |
-
if ($cookie instanceof Microsoft_Http_Cookie) {
|
119 |
-
$domain = $cookie->getDomain();
|
120 |
-
$path = $cookie->getPath();
|
121 |
-
if (! isset($this->cookies[$domain])) $this->cookies[$domain] = array();
|
122 |
-
if (! isset($this->cookies[$domain][$path])) $this->cookies[$domain][$path] = array();
|
123 |
-
$this->cookies[$domain][$path][$cookie->getName()] = $cookie;
|
124 |
-
$this->_rawCookies[] = $cookie;
|
125 |
-
} else {
|
126 |
-
require_once 'Microsoft/Http/Exception.php';
|
127 |
-
throw new Microsoft_Http_Exception('Supplient argument is not a valid cookie string or object');
|
128 |
-
}
|
129 |
-
}
|
130 |
-
|
131 |
-
/**
|
132 |
-
* Parse an HTTP response, adding all the cookies set in that response
|
133 |
-
* to the cookie jar.
|
134 |
-
*
|
135 |
-
* @param Microsoft_Http_Response $response
|
136 |
-
* @param Microsoft_Uri_Http|string $ref_uri Requested URI
|
137 |
-
*/
|
138 |
-
public function addCookiesFromResponse($response, $ref_uri)
|
139 |
-
{
|
140 |
-
if (! $response instanceof Microsoft_Http_Response) {
|
141 |
-
require_once 'Microsoft/Http/Exception.php';
|
142 |
-
throw new Microsoft_Http_Exception('$response is expected to be a Response object, ' .
|
143 |
-
gettype($response) . ' was passed');
|
144 |
-
}
|
145 |
-
|
146 |
-
$cookie_hdrs = $response->getHeader('Set-Cookie');
|
147 |
-
|
148 |
-
if (is_array($cookie_hdrs)) {
|
149 |
-
foreach ($cookie_hdrs as $cookie) {
|
150 |
-
$this->addCookie($cookie, $ref_uri);
|
151 |
-
}
|
152 |
-
} elseif (is_string($cookie_hdrs)) {
|
153 |
-
$this->addCookie($cookie_hdrs, $ref_uri);
|
154 |
-
}
|
155 |
-
}
|
156 |
-
|
157 |
-
/**
|
158 |
-
* Get all cookies in the cookie jar as an array
|
159 |
-
*
|
160 |
-
* @param int $ret_as Whether to return cookies as objects of Microsoft_Http_Cookie or as strings
|
161 |
-
* @return array|string
|
162 |
-
*/
|
163 |
-
public function getAllCookies($ret_as = self::COOKIE_OBJECT)
|
164 |
-
{
|
165 |
-
$cookies = $this->_flattenCookiesArray($this->cookies, $ret_as);
|
166 |
-
return $cookies;
|
167 |
-
}
|
168 |
-
|
169 |
-
/**
|
170 |
-
* Return an array of all cookies matching a specific request according to the request URI,
|
171 |
-
* whether session cookies should be sent or not, and the time to consider as "now" when
|
172 |
-
* checking cookie expiry time.
|
173 |
-
*
|
174 |
-
* @param string|Microsoft_Uri_Http $uri URI to check against (secure, domain, path)
|
175 |
-
* @param boolean $matchSessionCookies Whether to send session cookies
|
176 |
-
* @param int $ret_as Whether to return cookies as objects of Microsoft_Http_Cookie or as strings
|
177 |
-
* @param int $now Override the current time when checking for expiry time
|
178 |
-
* @return array|string
|
179 |
-
*/
|
180 |
-
public function getMatchingCookies($uri, $matchSessionCookies = true,
|
181 |
-
$ret_as = self::COOKIE_OBJECT, $now = null)
|
182 |
-
{
|
183 |
-
if (is_string($uri)) $uri = Microsoft_Uri::factory($uri);
|
184 |
-
if (! $uri instanceof Microsoft_Uri_Http) {
|
185 |
-
require_once 'Microsoft/Http/Exception.php';
|
186 |
-
throw new Microsoft_Http_Exception("Invalid URI string or object passed");
|
187 |
-
}
|
188 |
-
|
189 |
-
// First, reduce the array of cookies to only those matching domain and path
|
190 |
-
$cookies = $this->_matchDomain($uri->getHost());
|
191 |
-
$cookies = $this->_matchPath($cookies, $uri->getPath());
|
192 |
-
$cookies = $this->_flattenCookiesArray($cookies, self::COOKIE_OBJECT);
|
193 |
-
|
194 |
-
// Next, run Cookie->match on all cookies to check secure, time and session mathcing
|
195 |
-
$ret = array();
|
196 |
-
foreach ($cookies as $cookie)
|
197 |
-
if ($cookie->match($uri, $matchSessionCookies, $now))
|
198 |
-
$ret[] = $cookie;
|
199 |
-
|
200 |
-
// Now, use self::_flattenCookiesArray again - only to convert to the return format ;)
|
201 |
-
$ret = $this->_flattenCookiesArray($ret, $ret_as);
|
202 |
-
|
203 |
-
return $ret;
|
204 |
-
}
|
205 |
-
|
206 |
-
/**
|
207 |
-
* Get a specific cookie according to a URI and name
|
208 |
-
*
|
209 |
-
* @param Microsoft_Uri_Http|string $uri The uri (domain and path) to match
|
210 |
-
* @param string $cookie_name The cookie's name
|
211 |
-
* @param int $ret_as Whether to return cookies as objects of Microsoft_Http_Cookie or as strings
|
212 |
-
* @return Microsoft_Http_Cookie|string
|
213 |
-
*/
|
214 |
-
public function getCookie($uri, $cookie_name, $ret_as = self::COOKIE_OBJECT)
|
215 |
-
{
|
216 |
-
if (is_string($uri)) {
|
217 |
-
$uri = Microsoft_Uri::factory($uri);
|
218 |
-
}
|
219 |
-
|
220 |
-
if (! $uri instanceof Microsoft_Uri_Http) {
|
221 |
-
require_once 'Microsoft/Http/Exception.php';
|
222 |
-
throw new Microsoft_Http_Exception('Invalid URI specified');
|
223 |
-
}
|
224 |
-
|
225 |
-
// Get correct cookie path
|
226 |
-
$path = $uri->getPath();
|
227 |
-
$path = substr($path, 0, strrpos($path, '/'));
|
228 |
-
if (! $path) $path = '/';
|
229 |
-
|
230 |
-
if (isset($this->cookies[$uri->getHost()][$path][$cookie_name])) {
|
231 |
-
$cookie = $this->cookies[$uri->getHost()][$path][$cookie_name];
|
232 |
-
|
233 |
-
switch ($ret_as) {
|
234 |
-
case self::COOKIE_OBJECT:
|
235 |
-
return $cookie;
|
236 |
-
break;
|
237 |
-
|
238 |
-
case self::COOKIE_STRING_ARRAY:
|
239 |
-
case self::COOKIE_STRING_CONCAT:
|
240 |
-
return $cookie->__toString();
|
241 |
-
break;
|
242 |
-
|
243 |
-
default:
|
244 |
-
require_once 'Microsoft/Http/Exception.php';
|
245 |
-
throw new Microsoft_Http_Exception("Invalid value passed for \$ret_as: {$ret_as}");
|
246 |
-
break;
|
247 |
-
}
|
248 |
-
} else {
|
249 |
-
return false;
|
250 |
-
}
|
251 |
-
}
|
252 |
-
|
253 |
-
/**
|
254 |
-
* Helper function to recursivly flatten an array. Shoud be used when exporting the
|
255 |
-
* cookies array (or parts of it)
|
256 |
-
*
|
257 |
-
* @param Microsoft_Http_Cookie|array $ptr
|
258 |
-
* @param int $ret_as What value to return
|
259 |
-
* @return array|string
|
260 |
-
*/
|
261 |
-
protected function _flattenCookiesArray($ptr, $ret_as = self::COOKIE_OBJECT) {
|
262 |
-
if (is_array($ptr)) {
|
263 |
-
$ret = ($ret_as == self::COOKIE_STRING_CONCAT ? '' : array());
|
264 |
-
foreach ($ptr as $item) {
|
265 |
-
if ($ret_as == self::COOKIE_STRING_CONCAT) {
|
266 |
-
$ret .= $this->_flattenCookiesArray($item, $ret_as);
|
267 |
-
} else {
|
268 |
-
$ret = array_merge($ret, $this->_flattenCookiesArray($item, $ret_as));
|
269 |
-
}
|
270 |
-
}
|
271 |
-
return $ret;
|
272 |
-
} elseif ($ptr instanceof Microsoft_Http_Cookie) {
|
273 |
-
switch ($ret_as) {
|
274 |
-
case self::COOKIE_STRING_ARRAY:
|
275 |
-
return array($ptr->__toString());
|
276 |
-
break;
|
277 |
-
|
278 |
-
case self::COOKIE_STRING_CONCAT:
|
279 |
-
return $ptr->__toString();
|
280 |
-
break;
|
281 |
-
|
282 |
-
case self::COOKIE_OBJECT:
|
283 |
-
default:
|
284 |
-
return array($ptr);
|
285 |
-
break;
|
286 |
-
}
|
287 |
-
}
|
288 |
-
|
289 |
-
return null;
|
290 |
-
}
|
291 |
-
|
292 |
-
/**
|
293 |
-
* Return a subset of the cookies array matching a specific domain
|
294 |
-
*
|
295 |
-
* @param string $domain
|
296 |
-
* @return array
|
297 |
-
*/
|
298 |
-
protected function _matchDomain($domain)
|
299 |
-
{
|
300 |
-
$ret = array();
|
301 |
-
|
302 |
-
foreach (array_keys($this->cookies) as $cdom) {
|
303 |
-
if (Microsoft_Http_Cookie::matchCookieDomain($cdom, $domain)) {
|
304 |
-
$ret[$cdom] = $this->cookies[$cdom];
|
305 |
-
}
|
306 |
-
}
|
307 |
-
|
308 |
-
return $ret;
|
309 |
-
}
|
310 |
-
|
311 |
-
/**
|
312 |
-
* Return a subset of a domain-matching cookies that also match a specified path
|
313 |
-
*
|
314 |
-
* @param array $dom_array
|
315 |
-
* @param string $path
|
316 |
-
* @return array
|
317 |
-
*/
|
318 |
-
protected function _matchPath($domains, $path)
|
319 |
-
{
|
320 |
-
$ret = array();
|
321 |
-
|
322 |
-
foreach ($domains as $dom => $paths_array) {
|
323 |
-
foreach (array_keys($paths_array) as $cpath) {
|
324 |
-
if (Microsoft_Http_Cookie::matchCookiePath($cpath, $path)) {
|
325 |
-
if (! isset($ret[$dom])) {
|
326 |
-
$ret[$dom] = array();
|
327 |
-
}
|
328 |
-
|
329 |
-
$ret[$dom][$cpath] = $paths_array[$cpath];
|
330 |
-
}
|
331 |
-
}
|
332 |
-
}
|
333 |
-
|
334 |
-
return $ret;
|
335 |
-
}
|
336 |
-
|
337 |
-
/**
|
338 |
-
* Create a new CookieJar object and automatically load into it all the
|
339 |
-
* cookies set in an Http_Response object. If $uri is set, it will be
|
340 |
-
* considered as the requested URI for setting default domain and path
|
341 |
-
* of the cookie.
|
342 |
-
*
|
343 |
-
* @param Microsoft_Http_Response $response HTTP Response object
|
344 |
-
* @param Microsoft_Uri_Http|string $uri The requested URI
|
345 |
-
* @return Microsoft_Http_CookieJar
|
346 |
-
* @todo Add the $uri functionality.
|
347 |
-
*/
|
348 |
-
public static function fromResponse(Microsoft_Http_Response $response, $ref_uri)
|
349 |
-
{
|
350 |
-
$jar = new self();
|
351 |
-
$jar->addCookiesFromResponse($response, $ref_uri);
|
352 |
-
return $jar;
|
353 |
-
}
|
354 |
-
|
355 |
-
/**
|
356 |
-
* Required by Countable interface
|
357 |
-
*
|
358 |
-
* @return int
|
359 |
-
*/
|
360 |
-
public function count()
|
361 |
-
{
|
362 |
-
return count($this->_rawCookies);
|
363 |
-
}
|
364 |
-
|
365 |
-
/**
|
366 |
-
* Required by IteratorAggregate interface
|
367 |
-
*
|
368 |
-
* @return ArrayIterator
|
369 |
-
*/
|
370 |
-
public function getIterator()
|
371 |
-
{
|
372 |
-
return new ArrayIterator($this->_rawCookies);
|
373 |
-
}
|
374 |
-
|
375 |
-
/**
|
376 |
-
* Tells if the jar is empty of any cookie
|
377 |
-
*
|
378 |
-
* @return bool
|
379 |
-
*/
|
380 |
-
public function isEmpty()
|
381 |
-
{
|
382 |
-
return count($this) == 0;
|
383 |
-
}
|
384 |
-
|
385 |
-
/**
|
386 |
-
* Empties the cookieJar of any cookie
|
387 |
-
*
|
388 |
-
* @return Microsoft_Http_CookieJar
|
389 |
-
*/
|
390 |
-
public function reset()
|
391 |
-
{
|
392 |
-
$this->cookies = $this->_rawCookies = array();
|
393 |
-
return $this;
|
394 |
-
}
|
395 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Zend Framework
|
4 |
+
*
|
5 |
+
* LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the new BSD license that is bundled
|
8 |
+
* with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://framework.zend.com/license/new-bsd
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@zend.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* @category Microsoft
|
16 |
+
* @package Microsoft_Http
|
17 |
+
* @subpackage CookieJar
|
18 |
+
* @version $Id: CookieJar.php 17131 2009-07-26 10:03:39Z shahar $
|
19 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
20 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
21 |
+
*/
|
22 |
+
|
23 |
+
/**
|
24 |
+
* @see Microsoft_AutoLoader
|
25 |
+
*/
|
26 |
+
require_once dirname(__FILE__) . '/../AutoLoader.php';
|
27 |
+
|
28 |
+
/**
|
29 |
+
* A Microsoft_Http_CookieJar object is designed to contain and maintain HTTP cookies, and should
|
30 |
+
* be used along with Microsoft_Http_Client in order to manage cookies across HTTP requests and
|
31 |
+
* responses.
|
32 |
+
*
|
33 |
+
* The class contains an array of Microsoft_Http_Cookie objects. Cookies can be added to the jar
|
34 |
+
* automatically from a request or manually. Then, the jar can find and return the cookies
|
35 |
+
* needed for a specific HTTP request.
|
36 |
+
*
|
37 |
+
* A special parameter can be passed to all methods of this class that return cookies: Cookies
|
38 |
+
* can be returned either in their native form (as Microsoft_Http_Cookie objects) or as strings -
|
39 |
+
* the later is suitable for sending as the value of the "Cookie" header in an HTTP request.
|
40 |
+
* You can also choose, when returning more than one cookie, whether to get an array of strings
|
41 |
+
* (by passing Microsoft_Http_CookieJar::COOKIE_STRING_ARRAY) or one unified string for all cookies
|
42 |
+
* (by passing Microsoft_Http_CookieJar::COOKIE_STRING_CONCAT).
|
43 |
+
*
|
44 |
+
* @link http://wp.netscape.com/newsref/std/cookie_spec.html for some specs.
|
45 |
+
*
|
46 |
+
* @category Microsoft
|
47 |
+
* @package Microsoft_Http
|
48 |
+
* @subpackage CookieJar
|
49 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
50 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
51 |
+
*/
|
52 |
+
class Microsoft_Http_CookieJar implements Countable, IteratorAggregate
|
53 |
+
{
|
54 |
+
/**
|
55 |
+
* Return cookie(s) as a Microsoft_Http_Cookie object
|
56 |
+
*
|
57 |
+
*/
|
58 |
+
const COOKIE_OBJECT = 0;
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Return cookie(s) as a string (suitable for sending in an HTTP request)
|
62 |
+
*
|
63 |
+
*/
|
64 |
+
const COOKIE_STRING_ARRAY = 1;
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Return all cookies as one long string (suitable for sending in an HTTP request)
|
68 |
+
*
|
69 |
+
*/
|
70 |
+
const COOKIE_STRING_CONCAT = 2;
|
71 |
+
|
72 |
+
/**
|
73 |
+
* Array storing cookies
|
74 |
+
*
|
75 |
+
* Cookies are stored according to domain and path:
|
76 |
+
* $cookies
|
77 |
+
* + www.mydomain.com
|
78 |
+
* + /
|
79 |
+
* - cookie1
|
80 |
+
* - cookie2
|
81 |
+
* + /somepath
|
82 |
+
* - othercookie
|
83 |
+
* + www.otherdomain.net
|
84 |
+
* + /
|
85 |
+
* - alsocookie
|
86 |
+
*
|
87 |
+
* @var array
|
88 |
+
*/
|
89 |
+
protected $cookies = array();
|
90 |
+
|
91 |
+
/**
|
92 |
+
* The Microsoft_Http_Cookie array
|
93 |
+
*
|
94 |
+
* @var array
|
95 |
+
*/
|
96 |
+
protected $_rawCookies = array();
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Construct a new CookieJar object
|
100 |
+
*
|
101 |
+
*/
|
102 |
+
public function __construct()
|
103 |
+
{ }
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Add a cookie to the jar. Cookie should be passed either as a Microsoft_Http_Cookie object
|
107 |
+
* or as a string - in which case an object is created from the string.
|
108 |
+
*
|
109 |
+
* @param Microsoft_Http_Cookie|string $cookie
|
110 |
+
* @param Microsoft_Uri_Http|string $ref_uri Optional reference URI (for domain, path, secure)
|
111 |
+
*/
|
112 |
+
public function addCookie($cookie, $ref_uri = null)
|
113 |
+
{
|
114 |
+
if (is_string($cookie)) {
|
115 |
+
$cookie = Microsoft_Http_Cookie::fromString($cookie, $ref_uri);
|
116 |
+
}
|
117 |
+
|
118 |
+
if ($cookie instanceof Microsoft_Http_Cookie) {
|
119 |
+
$domain = $cookie->getDomain();
|
120 |
+
$path = $cookie->getPath();
|
121 |
+
if (! isset($this->cookies[$domain])) $this->cookies[$domain] = array();
|
122 |
+
if (! isset($this->cookies[$domain][$path])) $this->cookies[$domain][$path] = array();
|
123 |
+
$this->cookies[$domain][$path][$cookie->getName()] = $cookie;
|
124 |
+
$this->_rawCookies[] = $cookie;
|
125 |
+
} else {
|
126 |
+
require_once 'Microsoft/Http/Exception.php';
|
127 |
+
throw new Microsoft_Http_Exception('Supplient argument is not a valid cookie string or object');
|
128 |
+
}
|
129 |
+
}
|
130 |
+
|
131 |
+
/**
|
132 |
+
* Parse an HTTP response, adding all the cookies set in that response
|
133 |
+
* to the cookie jar.
|
134 |
+
*
|
135 |
+
* @param Microsoft_Http_Response $response
|
136 |
+
* @param Microsoft_Uri_Http|string $ref_uri Requested URI
|
137 |
+
*/
|
138 |
+
public function addCookiesFromResponse($response, $ref_uri)
|
139 |
+
{
|
140 |
+
if (! $response instanceof Microsoft_Http_Response) {
|
141 |
+
require_once 'Microsoft/Http/Exception.php';
|
142 |
+
throw new Microsoft_Http_Exception('$response is expected to be a Response object, ' .
|
143 |
+
gettype($response) . ' was passed');
|
144 |
+
}
|
145 |
+
|
146 |
+
$cookie_hdrs = $response->getHeader('Set-Cookie');
|
147 |
+
|
148 |
+
if (is_array($cookie_hdrs)) {
|
149 |
+
foreach ($cookie_hdrs as $cookie) {
|
150 |
+
$this->addCookie($cookie, $ref_uri);
|
151 |
+
}
|
152 |
+
} elseif (is_string($cookie_hdrs)) {
|
153 |
+
$this->addCookie($cookie_hdrs, $ref_uri);
|
154 |
+
}
|
155 |
+
}
|
156 |
+
|
157 |
+
/**
|
158 |
+
* Get all cookies in the cookie jar as an array
|
159 |
+
*
|
160 |
+
* @param int $ret_as Whether to return cookies as objects of Microsoft_Http_Cookie or as strings
|
161 |
+
* @return array|string
|
162 |
+
*/
|
163 |
+
public function getAllCookies($ret_as = self::COOKIE_OBJECT)
|
164 |
+
{
|
165 |
+
$cookies = $this->_flattenCookiesArray($this->cookies, $ret_as);
|
166 |
+
return $cookies;
|
167 |
+
}
|
168 |
+
|
169 |
+
/**
|
170 |
+
* Return an array of all cookies matching a specific request according to the request URI,
|
171 |
+
* whether session cookies should be sent or not, and the time to consider as "now" when
|
172 |
+
* checking cookie expiry time.
|
173 |
+
*
|
174 |
+
* @param string|Microsoft_Uri_Http $uri URI to check against (secure, domain, path)
|
175 |
+
* @param boolean $matchSessionCookies Whether to send session cookies
|
176 |
+
* @param int $ret_as Whether to return cookies as objects of Microsoft_Http_Cookie or as strings
|
177 |
+
* @param int $now Override the current time when checking for expiry time
|
178 |
+
* @return array|string
|
179 |
+
*/
|
180 |
+
public function getMatchingCookies($uri, $matchSessionCookies = true,
|
181 |
+
$ret_as = self::COOKIE_OBJECT, $now = null)
|
182 |
+
{
|
183 |
+
if (is_string($uri)) $uri = Microsoft_Uri::factory($uri);
|
184 |
+
if (! $uri instanceof Microsoft_Uri_Http) {
|
185 |
+
require_once 'Microsoft/Http/Exception.php';
|
186 |
+
throw new Microsoft_Http_Exception("Invalid URI string or object passed");
|
187 |
+
}
|
188 |
+
|
189 |
+
// First, reduce the array of cookies to only those matching domain and path
|
190 |
+
$cookies = $this->_matchDomain($uri->getHost());
|
191 |
+
$cookies = $this->_matchPath($cookies, $uri->getPath());
|
192 |
+
$cookies = $this->_flattenCookiesArray($cookies, self::COOKIE_OBJECT);
|
193 |
+
|
194 |
+
// Next, run Cookie->match on all cookies to check secure, time and session mathcing
|
195 |
+
$ret = array();
|
196 |
+
foreach ($cookies as $cookie)
|
197 |
+
if ($cookie->match($uri, $matchSessionCookies, $now))
|
198 |
+
$ret[] = $cookie;
|
199 |
+
|
200 |
+
// Now, use self::_flattenCookiesArray again - only to convert to the return format ;)
|
201 |
+
$ret = $this->_flattenCookiesArray($ret, $ret_as);
|
202 |
+
|
203 |
+
return $ret;
|
204 |
+
}
|
205 |
+
|
206 |
+
/**
|
207 |
+
* Get a specific cookie according to a URI and name
|
208 |
+
*
|
209 |
+
* @param Microsoft_Uri_Http|string $uri The uri (domain and path) to match
|
210 |
+
* @param string $cookie_name The cookie's name
|
211 |
+
* @param int $ret_as Whether to return cookies as objects of Microsoft_Http_Cookie or as strings
|
212 |
+
* @return Microsoft_Http_Cookie|string
|
213 |
+
*/
|
214 |
+
public function getCookie($uri, $cookie_name, $ret_as = self::COOKIE_OBJECT)
|
215 |
+
{
|
216 |
+
if (is_string($uri)) {
|
217 |
+
$uri = Microsoft_Uri::factory($uri);
|
218 |
+
}
|
219 |
+
|
220 |
+
if (! $uri instanceof Microsoft_Uri_Http) {
|
221 |
+
require_once 'Microsoft/Http/Exception.php';
|
222 |
+
throw new Microsoft_Http_Exception('Invalid URI specified');
|
223 |
+
}
|
224 |
+
|
225 |
+
// Get correct cookie path
|
226 |
+
$path = $uri->getPath();
|
227 |
+
$path = substr($path, 0, strrpos($path, '/'));
|
228 |
+
if (! $path) $path = '/';
|
229 |
+
|
230 |
+
if (isset($this->cookies[$uri->getHost()][$path][$cookie_name])) {
|
231 |
+
$cookie = $this->cookies[$uri->getHost()][$path][$cookie_name];
|
232 |
+
|
233 |
+
switch ($ret_as) {
|
234 |
+
case self::COOKIE_OBJECT:
|
235 |
+
return $cookie;
|
236 |
+
break;
|
237 |
+
|
238 |
+
case self::COOKIE_STRING_ARRAY:
|
239 |
+
case self::COOKIE_STRING_CONCAT:
|
240 |
+
return $cookie->__toString();
|
241 |
+
break;
|
242 |
+
|
243 |
+
default:
|
244 |
+
require_once 'Microsoft/Http/Exception.php';
|
245 |
+
throw new Microsoft_Http_Exception("Invalid value passed for \$ret_as: {$ret_as}");
|
246 |
+
break;
|
247 |
+
}
|
248 |
+
} else {
|
249 |
+
return false;
|
250 |
+
}
|
251 |
+
}
|
252 |
+
|
253 |
+
/**
|
254 |
+
* Helper function to recursivly flatten an array. Shoud be used when exporting the
|
255 |
+
* cookies array (or parts of it)
|
256 |
+
*
|
257 |
+
* @param Microsoft_Http_Cookie|array $ptr
|
258 |
+
* @param int $ret_as What value to return
|
259 |
+
* @return array|string
|
260 |
+
*/
|
261 |
+
protected function _flattenCookiesArray($ptr, $ret_as = self::COOKIE_OBJECT) {
|
262 |
+
if (is_array($ptr)) {
|
263 |
+
$ret = ($ret_as == self::COOKIE_STRING_CONCAT ? '' : array());
|
264 |
+
foreach ($ptr as $item) {
|
265 |
+
if ($ret_as == self::COOKIE_STRING_CONCAT) {
|
266 |
+
$ret .= $this->_flattenCookiesArray($item, $ret_as);
|
267 |
+
} else {
|
268 |
+
$ret = array_merge($ret, $this->_flattenCookiesArray($item, $ret_as));
|
269 |
+
}
|
270 |
+
}
|
271 |
+
return $ret;
|
272 |
+
} elseif ($ptr instanceof Microsoft_Http_Cookie) {
|
273 |
+
switch ($ret_as) {
|
274 |
+
case self::COOKIE_STRING_ARRAY:
|
275 |
+
return array($ptr->__toString());
|
276 |
+
break;
|
277 |
+
|
278 |
+
case self::COOKIE_STRING_CONCAT:
|
279 |
+
return $ptr->__toString();
|
280 |
+
break;
|
281 |
+
|
282 |
+
case self::COOKIE_OBJECT:
|
283 |
+
default:
|
284 |
+
return array($ptr);
|
285 |
+
break;
|
286 |
+
}
|
287 |
+
}
|
288 |
+
|
289 |
+
return null;
|
290 |
+
}
|
291 |
+
|
292 |
+
/**
|
293 |
+
* Return a subset of the cookies array matching a specific domain
|
294 |
+
*
|
295 |
+
* @param string $domain
|
296 |
+
* @return array
|
297 |
+
*/
|
298 |
+
protected function _matchDomain($domain)
|
299 |
+
{
|
300 |
+
$ret = array();
|
301 |
+
|
302 |
+
foreach (array_keys($this->cookies) as $cdom) {
|
303 |
+
if (Microsoft_Http_Cookie::matchCookieDomain($cdom, $domain)) {
|
304 |
+
$ret[$cdom] = $this->cookies[$cdom];
|
305 |
+
}
|
306 |
+
}
|
307 |
+
|
308 |
+
return $ret;
|
309 |
+
}
|
310 |
+
|
311 |
+
/**
|
312 |
+
* Return a subset of a domain-matching cookies that also match a specified path
|
313 |
+
*
|
314 |
+
* @param array $dom_array
|
315 |
+
* @param string $path
|
316 |
+
* @return array
|
317 |
+
*/
|
318 |
+
protected function _matchPath($domains, $path)
|
319 |
+
{
|
320 |
+
$ret = array();
|
321 |
+
|
322 |
+
foreach ($domains as $dom => $paths_array) {
|
323 |
+
foreach (array_keys($paths_array) as $cpath) {
|
324 |
+
if (Microsoft_Http_Cookie::matchCookiePath($cpath, $path)) {
|
325 |
+
if (! isset($ret[$dom])) {
|
326 |
+
$ret[$dom] = array();
|
327 |
+
}
|
328 |
+
|
329 |
+
$ret[$dom][$cpath] = $paths_array[$cpath];
|
330 |
+
}
|
331 |
+
}
|
332 |
+
}
|
333 |
+
|
334 |
+
return $ret;
|
335 |
+
}
|
336 |
+
|
337 |
+
/**
|
338 |
+
* Create a new CookieJar object and automatically load into it all the
|
339 |
+
* cookies set in an Http_Response object. If $uri is set, it will be
|
340 |
+
* considered as the requested URI for setting default domain and path
|
341 |
+
* of the cookie.
|
342 |
+
*
|
343 |
+
* @param Microsoft_Http_Response $response HTTP Response object
|
344 |
+
* @param Microsoft_Uri_Http|string $uri The requested URI
|
345 |
+
* @return Microsoft_Http_CookieJar
|
346 |
+
* @todo Add the $uri functionality.
|
347 |
+
*/
|
348 |
+
public static function fromResponse(Microsoft_Http_Response $response, $ref_uri)
|
349 |
+
{
|
350 |
+
$jar = new self();
|
351 |
+
$jar->addCookiesFromResponse($response, $ref_uri);
|
352 |
+
return $jar;
|
353 |
+
}
|
354 |
+
|
355 |
+
/**
|
356 |
+
* Required by Countable interface
|
357 |
+
*
|
358 |
+
* @return int
|
359 |
+
*/
|
360 |
+
public function count()
|
361 |
+
{
|
362 |
+
return count($this->_rawCookies);
|
363 |
+
}
|
364 |
+
|
365 |
+
/**
|
366 |
+
* Required by IteratorAggregate interface
|
367 |
+
*
|
368 |
+
* @return ArrayIterator
|
369 |
+
*/
|
370 |
+
public function getIterator()
|
371 |
+
{
|
372 |
+
return new ArrayIterator($this->_rawCookies);
|
373 |
+
}
|
374 |
+
|
375 |
+
/**
|
376 |
+
* Tells if the jar is empty of any cookie
|
377 |
+
*
|
378 |
+
* @return bool
|
379 |
+
*/
|
380 |
+
public function isEmpty()
|
381 |
+
{
|
382 |
+
return count($this) == 0;
|
383 |
+
}
|
384 |
+
|
385 |
+
/**
|
386 |
+
* Empties the cookieJar of any cookie
|
387 |
+
*
|
388 |
+
* @return Microsoft_Http_CookieJar
|
389 |
+
*/
|
390 |
+
public function reset()
|
391 |
+
{
|
392 |
+
$this->cookies = $this->_rawCookies = array();
|
393 |
+
return $this;
|
394 |
+
}
|
395 |
+
}
|
libs/Microsoft/Http/Exception.php
CHANGED
@@ -28,7 +28,7 @@
|
|
28 |
* @category Microsoft
|
29 |
* @package Microsoft_Http
|
30 |
* @subpackage Exception
|
31 |
-
* @version $Id: Exception.php
|
32 |
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
33 |
* @license http://phpazure.codeplex.com/license
|
34 |
*/
|
28 |
* @category Microsoft
|
29 |
* @package Microsoft_Http
|
30 |
* @subpackage Exception
|
31 |
+
* @version $Id: Exception.php 61042 2011-04-19 10:03:39Z unknown $
|
32 |
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
33 |
* @license http://phpazure.codeplex.com/license
|
34 |
*/
|
libs/Microsoft/Http/Response.php
CHANGED
@@ -1,664 +1,664 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Zend Framework
|
5 |
-
*
|
6 |
-
* LICENSE
|
7 |
-
*
|
8 |
-
* This source file is subject to the new BSD license that is bundled
|
9 |
-
* with this package in the file LICENSE.txt.
|
10 |
-
* It is also available through the world-wide-web at this URL:
|
11 |
-
* http://framework.zend.com/license/new-bsd
|
12 |
-
* If you did not receive a copy of the license and are unable to
|
13 |
-
* obtain it through the world-wide-web, please send an email
|
14 |
-
* to license@zend.com so we can send you a copy immediately.
|
15 |
-
*
|
16 |
-
* @category Microsoft
|
17 |
-
* @package Microsoft_Http
|
18 |
-
* @subpackage Response
|
19 |
-
* @version $Id: Response.php
|
20 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
21 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
22 |
-
*/
|
23 |
-
|
24 |
-
/**
|
25 |
-
* Microsoft_Http_Response represents an HTTP 1.0 / 1.1 response message. It
|
26 |
-
* includes easy access to all the response's different elemts, as well as some
|
27 |
-
* convenience methods for parsing and validating HTTP responses.
|
28 |
-
*
|
29 |
-
* @package Microsoft_Http
|
30 |
-
* @subpackage Response
|
31 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
32 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
33 |
-
*/
|
34 |
-
class Microsoft_Http_Response
|
35 |
-
{
|
36 |
-
/**
|
37 |
-
* List of all known HTTP response codes - used by responseCodeAsText() to
|
38 |
-
* translate numeric codes to messages.
|
39 |
-
*
|
40 |
-
* @var array
|
41 |
-
*/
|
42 |
-
protected static $messages = array(
|
43 |
-
// Informational 1xx
|
44 |
-
100 => 'Continue',
|
45 |
-
101 => 'Switching Protocols',
|
46 |
-
|
47 |
-
// Success 2xx
|
48 |
-
200 => 'OK',
|
49 |
-
201 => 'Created',
|
50 |
-
202 => 'Accepted',
|
51 |
-
203 => 'Non-Authoritative Information',
|
52 |
-
204 => 'No Content',
|
53 |
-
205 => 'Reset Content',
|
54 |
-
206 => 'Partial Content',
|
55 |
-
|
56 |
-
// Redirection 3xx
|
57 |
-
300 => 'Multiple Choices',
|
58 |
-
301 => 'Moved Permanently',
|
59 |
-
302 => 'Found', // 1.1
|
60 |
-
303 => 'See Other',
|
61 |
-
304 => 'Not Modified',
|
62 |
-
305 => 'Use Proxy',
|
63 |
-
// 306 is deprecated but reserved
|
64 |
-
307 => 'Temporary Redirect',
|
65 |
-
|
66 |
-
// Client Error 4xx
|
67 |
-
400 => 'Bad Request',
|
68 |
-
401 => 'Unauthorized',
|
69 |
-
402 => 'Payment Required',
|
70 |
-
403 => 'Forbidden',
|
71 |
-
404 => 'Not Found',
|
72 |
-
405 => 'Method Not Allowed',
|
73 |
-
406 => 'Not Acceptable',
|
74 |
-
407 => 'Proxy Authentication Required',
|
75 |
-
408 => 'Request Timeout',
|
76 |
-
409 => 'Conflict',
|
77 |
-
410 => 'Gone',
|
78 |
-
411 => 'Length Required',
|
79 |
-
412 => 'Precondition Failed',
|
80 |
-
413 => 'Request Entity Too Large',
|
81 |
-
414 => 'Request-URI Too Long',
|
82 |
-
415 => 'Unsupported Media Type',
|
83 |
-
416 => 'Requested Range Not Satisfiable',
|
84 |
-
417 => 'Expectation Failed',
|
85 |
-
|
86 |
-
// Server Error 5xx
|
87 |
-
500 => 'Internal Server Error',
|
88 |
-
501 => 'Not Implemented',
|
89 |
-
502 => 'Bad Gateway',
|
90 |
-
503 => 'Service Unavailable',
|
91 |
-
504 => 'Gateway Timeout',
|
92 |
-
505 => 'HTTP Version Not Supported',
|
93 |
-
509 => 'Bandwidth Limit Exceeded'
|
94 |
-
);
|
95 |
-
|
96 |
-
/**
|
97 |
-
* The HTTP version (1.0, 1.1)
|
98 |
-
*
|
99 |
-
* @var string
|
100 |
-
*/
|
101 |
-
protected $version;
|
102 |
-
|
103 |
-
/**
|
104 |
-
* The HTTP response code
|
105 |
-
*
|
106 |
-
* @var int
|
107 |
-
*/
|
108 |
-
protected $code;
|
109 |
-
|
110 |
-
/**
|
111 |
-
* The HTTP response code as string
|
112 |
-
* (e.g. 'Not Found' for 404 or 'Internal Server Error' for 500)
|
113 |
-
*
|
114 |
-
* @var string
|
115 |
-
*/
|
116 |
-
protected $message;
|
117 |
-
|
118 |
-
/**
|
119 |
-
* The HTTP response headers array
|
120 |
-
*
|
121 |
-
* @var array
|
122 |
-
*/
|
123 |
-
protected $headers = array();
|
124 |
-
|
125 |
-
/**
|
126 |
-
* The HTTP response body
|
127 |
-
*
|
128 |
-
* @var string
|
129 |
-
*/
|
130 |
-
protected $body;
|
131 |
-
|
132 |
-
/**
|
133 |
-
* HTTP response constructor
|
134 |
-
*
|
135 |
-
* In most cases, you would use Microsoft_Http_Response::fromString to parse an HTTP
|
136 |
-
* response string and create a new Microsoft_Http_Response object.
|
137 |
-
*
|
138 |
-
* NOTE: The constructor no longer accepts nulls or empty values for the code and
|
139 |
-
* headers and will throw an exception if the passed values do not form a valid HTTP
|
140 |
-
* responses.
|
141 |
-
*
|
142 |
-
* If no message is passed, the message will be guessed according to the response code.
|
143 |
-
*
|
144 |
-
* @param int $code Response code (200, 404, ...)
|
145 |
-
* @param array $headers Headers array
|
146 |
-
* @param string $body Response body
|
147 |
-
* @param string $version HTTP version
|
148 |
-
* @param string $message Response code as text
|
149 |
-
* @throws Microsoft_Http_Exception
|
150 |
-
*/
|
151 |
-
public function __construct($code, $headers, $body = null, $version = '1.1', $message = null)
|
152 |
-
{
|
153 |
-
// Make sure the response code is valid and set it
|
154 |
-
if (self::responseCodeAsText($code) === null) {
|
155 |
-
require_once 'Microsoft/Http/Exception.php';
|
156 |
-
throw new Microsoft_Http_Exception("{$code} is not a valid HTTP response code");
|
157 |
-
}
|
158 |
-
|
159 |
-
$this->code = $code;
|
160 |
-
|
161 |
-
// Make sure we got valid headers and set them
|
162 |
-
if (! is_array($headers)) {
|
163 |
-
require_once 'Microsoft/Http/Exception.php';
|
164 |
-
throw new Microsoft_Http_Exception('No valid headers were passed');
|
165 |
-
}
|
166 |
-
|
167 |
-
foreach ($headers as $name => $value) {
|
168 |
-
if (is_int($name))
|
169 |
-
list($name, $value) = explode(": ", $value, 1);
|
170 |
-
|
171 |
-
$this->headers[ucwords(strtolower($name))] = $value;
|
172 |
-
}
|
173 |
-
|
174 |
-
// Set the body
|
175 |
-
$this->body = $body;
|
176 |
-
|
177 |
-
// Set the HTTP version
|
178 |
-
if (! preg_match('|^\d\.\d$|', $version)) {
|
179 |
-
require_once 'Microsoft/Http/Exception.php';
|
180 |
-
throw new Microsoft_Http_Exception("Invalid HTTP response version: $version");
|
181 |
-
}
|
182 |
-
|
183 |
-
$this->version = $version;
|
184 |
-
|
185 |
-
// If we got the response message, set it. Else, set it according to
|
186 |
-
// the response code
|
187 |
-
if (is_string($message)) {
|
188 |
-
$this->message = $message;
|
189 |
-
} else {
|
190 |
-
$this->message = self::responseCodeAsText($code);
|
191 |
-
}
|
192 |
-
}
|
193 |
-
|
194 |
-
/**
|
195 |
-
* Check whether the response is an error
|
196 |
-
*
|
197 |
-
* @return boolean
|
198 |
-
*/
|
199 |
-
public function isError()
|
200 |
-
{
|
201 |
-
$restype = floor($this->code / 100);
|
202 |
-
if ($restype == 4 || $restype == 5) {
|
203 |
-
return true;
|
204 |
-
}
|
205 |
-
|
206 |
-
return false;
|
207 |
-
}
|
208 |
-
|
209 |
-
/**
|
210 |
-
* Check whether the response in successful
|
211 |
-
*
|
212 |
-
* @return boolean
|
213 |
-
*/
|
214 |
-
public function isSuccessful()
|
215 |
-
{
|
216 |
-
$restype = floor($this->code / 100);
|
217 |
-
if ($restype == 2 || $restype == 1) { // Shouldn't 3xx count as success as well ???
|
218 |
-
return true;
|
219 |
-
}
|
220 |
-
|
221 |
-
return false;
|
222 |
-
}
|
223 |
-
|
224 |
-
/**
|
225 |
-
* Check whether the response is a redirection
|
226 |
-
*
|
227 |
-
* @return boolean
|
228 |
-
*/
|
229 |
-
public function isRedirect()
|
230 |
-
{
|
231 |
-
$restype = floor($this->code / 100);
|
232 |
-
if ($restype == 3) {
|
233 |
-
return true;
|
234 |
-
}
|
235 |
-
|
236 |
-
return false;
|
237 |
-
}
|
238 |
-
|
239 |
-
/**
|
240 |
-
* Get the response body as string
|
241 |
-
*
|
242 |
-
* This method returns the body of the HTTP response (the content), as it
|
243 |
-
* should be in it's readable version - that is, after decoding it (if it
|
244 |
-
* was decoded), deflating it (if it was gzip compressed), etc.
|
245 |
-
*
|
246 |
-
* If you want to get the raw body (as transfered on wire) use
|
247 |
-
* $this->getRawBody() instead.
|
248 |
-
*
|
249 |
-
* @return string
|
250 |
-
*/
|
251 |
-
public function getBody()
|
252 |
-
{
|
253 |
-
$body = '';
|
254 |
-
|
255 |
-
// Decode the body if it was transfer-encoded
|
256 |
-
switch (strtolower($this->getHeader('transfer-encoding'))) {
|
257 |
-
|
258 |
-
// Handle chunked body
|
259 |
-
case 'chunked':
|
260 |
-
$body = self::decodeChunkedBody($this->body);
|
261 |
-
break;
|
262 |
-
|
263 |
-
// No transfer encoding, or unknown encoding extension:
|
264 |
-
// return body as is
|
265 |
-
default:
|
266 |
-
$body = $this->body;
|
267 |
-
break;
|
268 |
-
}
|
269 |
-
|
270 |
-
// Decode any content-encoding (gzip or deflate) if needed
|
271 |
-
switch (strtolower($this->getHeader('content-encoding'))) {
|
272 |
-
|
273 |
-
// Handle gzip encoding
|
274 |
-
case 'gzip':
|
275 |
-
$body = self::decodeGzip($body);
|
276 |
-
break;
|
277 |
-
|
278 |
-
// Handle deflate encoding
|
279 |
-
case 'deflate':
|
280 |
-
$body = self::decodeDeflate($body);
|
281 |
-
break;
|
282 |
-
|
283 |
-
default:
|
284 |
-
break;
|
285 |
-
}
|
286 |
-
|
287 |
-
return $body;
|
288 |
-
}
|
289 |
-
|
290 |
-
/**
|
291 |
-
* Get the raw response body (as transfered "on wire") as string
|
292 |
-
*
|
293 |
-
* If the body is encoded (with Transfer-Encoding, not content-encoding -
|
294 |
-
* IE "chunked" body), gzip compressed, etc. it will not be decoded.
|
295 |
-
*
|
296 |
-
* @return string
|
297 |
-
*/
|
298 |
-
public function getRawBody()
|
299 |
-
{
|
300 |
-
return $this->body;
|
301 |
-
}
|
302 |
-
|
303 |
-
/**
|
304 |
-
* Get the HTTP version of the response
|
305 |
-
*
|
306 |
-
* @return string
|
307 |
-
*/
|
308 |
-
public function getVersion()
|
309 |
-
{
|
310 |
-
return $this->version;
|
311 |
-
}
|
312 |
-
|
313 |
-
/**
|
314 |
-
* Get the HTTP response status code
|
315 |
-
*
|
316 |
-
* @return int
|
317 |
-
*/
|
318 |
-
public function getStatus()
|
319 |
-
{
|
320 |
-
return $this->code;
|
321 |
-
}
|
322 |
-
|
323 |
-
/**
|
324 |
-
* Return a message describing the HTTP response code
|
325 |
-
* (Eg. "OK", "Not Found", "Moved Permanently")
|
326 |
-
*
|
327 |
-
* @return string
|
328 |
-
*/
|
329 |
-
public function getMessage()
|
330 |
-
{
|
331 |
-
return $this->message;
|
332 |
-
}
|
333 |
-
|
334 |
-
/**
|
335 |
-
* Get the response headers
|
336 |
-
*
|
337 |
-
* @return array
|
338 |
-
*/
|
339 |
-
public function getHeaders()
|
340 |
-
{
|
341 |
-
return $this->headers;
|
342 |
-
}
|
343 |
-
|
344 |
-
/**
|
345 |
-
* Get a specific header as string, or null if it is not set
|
346 |
-
*
|
347 |
-
* @param string$header
|
348 |
-
* @return string|array|null
|
349 |
-
*/
|
350 |
-
public function getHeader($header)
|
351 |
-
{
|
352 |
-
$header = ucwords(strtolower($header));
|
353 |
-
if (! is_string($header) || ! isset($this->headers[$header])) return null;
|
354 |
-
|
355 |
-
return $this->headers[$header];
|
356 |
-
}
|
357 |
-
|
358 |
-
/**
|
359 |
-
* Get all headers as string
|
360 |
-
*
|
361 |
-
* @param boolean $status_line Whether to return the first status line (IE "HTTP 200 OK")
|
362 |
-
* @param string $br Line breaks (eg. "\n", "\r\n", "<br />")
|
363 |
-
* @return string
|
364 |
-
*/
|
365 |
-
public function getHeadersAsString($status_line = true, $br = "\n")
|
366 |
-
{
|
367 |
-
$str = '';
|
368 |
-
|
369 |
-
if ($status_line) {
|
370 |
-
$str = "HTTP/{$this->version} {$this->code} {$this->message}{$br}";
|
371 |
-
}
|
372 |
-
|
373 |
-
// Iterate over the headers and stringify them
|
374 |
-
foreach ($this->headers as $name => $value)
|
375 |
-
{
|
376 |
-
if (is_string($value))
|
377 |
-
$str .= "{$name}: {$value}{$br}";
|
378 |
-
|
379 |
-
elseif (is_array($value)) {
|
380 |
-
foreach ($value as $subval) {
|
381 |
-
$str .= "{$name}: {$subval}{$br}";
|
382 |
-
}
|
383 |
-
}
|
384 |
-
}
|
385 |
-
|
386 |
-
return $str;
|
387 |
-
}
|
388 |
-
|
389 |
-
/**
|
390 |
-
* Get the entire response as string
|
391 |
-
*
|
392 |
-
* @param string $br Line breaks (eg. "\n", "\r\n", "<br />")
|
393 |
-
* @return string
|
394 |
-
*/
|
395 |
-
public function asString($br = "\n")
|
396 |
-
{
|
397 |
-
return $this->getHeadersAsString(true, $br) . $br . $this->getRawBody();
|
398 |
-
}
|
399 |
-
|
400 |
-
/**
|
401 |
-
* Implements magic __toString()
|
402 |
-
*
|
403 |
-
* @return string
|
404 |
-
*/
|
405 |
-
public function __toString()
|
406 |
-
{
|
407 |
-
return $this->asString();
|
408 |
-
}
|
409 |
-
|
410 |
-
/**
|
411 |
-
* A convenience function that returns a text representation of
|
412 |
-
* HTTP response codes. Returns 'Unknown' for unknown codes.
|
413 |
-
* Returns array of all codes, if $code is not specified.
|
414 |
-
*
|
415 |
-
* Conforms to HTTP/1.1 as defined in RFC 2616 (except for 'Unknown')
|
416 |
-
* See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10 for reference
|
417 |
-
*
|
418 |
-
* @param int $code HTTP response code
|
419 |
-
* @param boolean $http11 Use HTTP version 1.1
|
420 |
-
* @return string
|
421 |
-
*/
|
422 |
-
public static function responseCodeAsText($code = null, $http11 = true)
|
423 |
-
{
|
424 |
-
$messages = self::$messages;
|
425 |
-
if (! $http11) $messages[302] = 'Moved Temporarily';
|
426 |
-
|
427 |
-
if ($code === null) {
|
428 |
-
return $messages;
|
429 |
-
} elseif (isset($messages[$code])) {
|
430 |
-
return $messages[$code];
|
431 |
-
} else {
|
432 |
-
return 'Unknown';
|
433 |
-
}
|
434 |
-
}
|
435 |
-
|
436 |
-
/**
|
437 |
-
* Extract the response code from a response string
|
438 |
-
*
|
439 |
-
* @param string $response_str
|
440 |
-
* @return int
|
441 |
-
*/
|
442 |
-
public static function extractCode($response_str)
|
443 |
-
{
|
444 |
-
preg_match("|^HTTP/[\d\.x]+ (\d+)|", $response_str, $m);
|
445 |
-
|
446 |
-
if (isset($m[1])) {
|
447 |
-
return (int) $m[1];
|
448 |
-
} else {
|
449 |
-
return false;
|
450 |
-
}
|
451 |
-
}
|
452 |
-
|
453 |
-
/**
|
454 |
-
* Extract the HTTP message from a response
|
455 |
-
*
|
456 |
-
* @param string $response_str
|
457 |
-
* @return string
|
458 |
-
*/
|
459 |
-
public static function extractMessage($response_str)
|
460 |
-
{
|
461 |
-
preg_match("|^HTTP/[\d\.x]+ \d+ ([^\r\n]+)|", $response_str, $m);
|
462 |
-
|
463 |
-
if (isset($m[1])) {
|
464 |
-
return $m[1];
|
465 |
-
} else {
|
466 |
-
return false;
|
467 |
-
}
|
468 |
-
}
|
469 |
-
|
470 |
-
/**
|
471 |
-
* Extract the HTTP version from a response
|
472 |
-
*
|
473 |
-
* @param string $response_str
|
474 |
-
* @return string
|
475 |
-
*/
|
476 |
-
public static function extractVersion($response_str)
|
477 |
-
{
|
478 |
-
preg_match("|^HTTP/([\d\.x]+) \d+|", $response_str, $m);
|
479 |
-
|
480 |
-
if (isset($m[1])) {
|
481 |
-
return $m[1];
|
482 |
-
} else {
|
483 |
-
return false;
|
484 |
-
}
|
485 |
-
}
|
486 |
-
|
487 |
-
/**
|
488 |
-
* Extract the headers from a response string
|
489 |
-
*
|
490 |
-
* @param string $response_str
|
491 |
-
* @return array
|
492 |
-
*/
|
493 |
-
public static function extractHeaders($response_str)
|
494 |
-
{
|
495 |
-
$headers = array();
|
496 |
-
|
497 |
-
// First, split body and headers
|
498 |
-
$parts = preg_split('|(?:\r?\n){2}|m', $response_str, 2);
|
499 |
-
if (! $parts[0]) return $headers;
|
500 |
-
|
501 |
-
// Split headers part to lines
|
502 |
-
$lines = explode("\n", $parts[0]);
|
503 |
-
unset($parts);
|
504 |
-
$last_header = null;
|
505 |
-
|
506 |
-
foreach($lines as $line) {
|
507 |
-
$line = trim($line, "\r\n");
|
508 |
-
if ($line == "") break;
|
509 |
-
|
510 |
-
if (preg_match("|^([\w-]+):\s+(.+)|", $line, $m)) {
|
511 |
-
unset($last_header);
|
512 |
-
$h_name = strtolower($m[1]);
|
513 |
-
$h_value = $m[2];
|
514 |
-
|
515 |
-
if (isset($headers[$h_name])) {
|
516 |
-
if (! is_array($headers[$h_name])) {
|
517 |
-
$headers[$h_name] = array($headers[$h_name]);
|
518 |
-
}
|
519 |
-
|
520 |
-
$headers[$h_name][] = $h_value;
|
521 |
-
} else {
|
522 |
-
$headers[$h_name] = $h_value;
|
523 |
-
}
|
524 |
-
$last_header = $h_name;
|
525 |
-
} elseif (preg_match("|^\s+(.+)$|", $line, $m) && $last_header !== null) {
|
526 |
-
if (is_array($headers[$last_header])) {
|
527 |
-
end($headers[$last_header]);
|
528 |
-
$last_header_key = key($headers[$last_header]);
|
529 |
-
$headers[$last_header][$last_header_key] .= $m[1];
|
530 |
-
} else {
|
531 |
-
$headers[$last_header] .= $m[1];
|
532 |
-
}
|
533 |
-
}
|
534 |
-
}
|
535 |
-
|
536 |
-
return $headers;
|
537 |
-
}
|
538 |
-
|
539 |
-
/**
|
540 |
-
* Extract the body from a response string
|
541 |
-
*
|
542 |
-
* @param string $response_str
|
543 |
-
* @return string
|
544 |
-
*/
|
545 |
-
public static function extractBody($response_str)
|
546 |
-
{
|
547 |
-
$parts = preg_split('|(?:\r?\n){2}|m', $response_str, 2);
|
548 |
-
if (isset($parts[1])) {
|
549 |
-
return $parts[1];
|
550 |
-
}
|
551 |
-
return '';
|
552 |
-
}
|
553 |
-
|
554 |
-
/**
|
555 |
-
* Decode a "chunked" transfer-encoded body and return the decoded text
|
556 |
-
*
|
557 |
-
* @param string $body
|
558 |
-
* @return string
|
559 |
-
*/
|
560 |
-
public static function decodeChunkedBody($body)
|
561 |
-
{
|
562 |
-
$decBody = '';
|
563 |
-
|
564 |
-
// If mbstring overloads substr and strlen functions, we have to
|
565 |
-
// override it's internal encoding
|
566 |
-
if (function_exists('mb_internal_encoding') &&
|
567 |
-
((int) ini_get('mbstring.func_overload')) & 2) {
|
568 |
-
|
569 |
-
$mbIntEnc = mb_internal_encoding();
|
570 |
-
mb_internal_encoding('ASCII');
|
571 |
-
}
|
572 |
-
|
573 |
-
while (trim($body)) {
|
574 |
-
if (! preg_match("/^([\da-fA-F]+)[^\r\n]*\r\n/sm", $body, $m)) {
|
575 |
-
require_once 'Microsoft/Http/Exception.php';
|
576 |
-
throw new Microsoft_Http_Exception("Error parsing body - doesn't seem to be a chunked message");
|
577 |
-
}
|
578 |
-
|
579 |
-
$length = hexdec(trim($m[1]));
|
580 |
-
$cut = strlen($m[0]);
|
581 |
-
$decBody .= substr($body, $cut, $length);
|
582 |
-
$body = substr($body, $cut + $length + 2);
|
583 |
-
}
|
584 |
-
|
585 |
-
if (isset($mbIntEnc)) {
|
586 |
-
mb_internal_encoding($mbIntEnc);
|
587 |
-
}
|
588 |
-
|
589 |
-
return $decBody;
|
590 |
-
}
|
591 |
-
|
592 |
-
/**
|
593 |
-
* Decode a gzip encoded message (when Content-encoding = gzip)
|
594 |
-
*
|
595 |
-
* Currently requires PHP with zlib support
|
596 |
-
*
|
597 |
-
* @param string $body
|
598 |
-
* @return string
|
599 |
-
*/
|
600 |
-
public static function decodeGzip($body)
|
601 |
-
{
|
602 |
-
if (! function_exists('gzinflate')) {
|
603 |
-
require_once 'Microsoft/Http/Exception.php';
|
604 |
-
throw new Microsoft_Http_Exception(
|
605 |
-
'zlib extension is required in order to decode "gzip" encoding'
|
606 |
-
);
|
607 |
-
}
|
608 |
-
|
609 |
-
return gzinflate(substr($body, 10));
|
610 |
-
}
|
611 |
-
|
612 |
-
/**
|
613 |
-
* Decode a zlib deflated message (when Content-encoding = deflate)
|
614 |
-
*
|
615 |
-
* Currently requires PHP with zlib support
|
616 |
-
*
|
617 |
-
* @param string $body
|
618 |
-
* @return string
|
619 |
-
*/
|
620 |
-
public static function decodeDeflate($body)
|
621 |
-
{
|
622 |
-
if (! function_exists('gzuncompress')) {
|
623 |
-
require_once 'Microsoft/Http/Exception.php';
|
624 |
-
throw new Microsoft_Http_Exception(
|
625 |
-
'zlib extension is required in order to decode "deflate" encoding'
|
626 |
-
);
|
627 |
-
}
|
628 |
-
|
629 |
-
/**
|
630 |
-
* Some servers (IIS ?) send a broken deflate response, without the
|
631 |
-
* RFC-required zlib header.
|
632 |
-
*
|
633 |
-
* We try to detect the zlib header, and if it does not exsit we
|
634 |
-
* teat the body is plain DEFLATE content.
|
635 |
-
*
|
636 |
-
* This method was adapted from PEAR HTTP_Request2 by (c) Alexey Borzov
|
637 |
-
*
|
638 |
-
* @link http://framework.zend.com/issues/browse/ZF-6040
|
639 |
-
*/
|
640 |
-
$zlibHeader = unpack('n', substr($body, 0, 2));
|
641 |
-
if ($zlibHeader[1] % 31 == 0) {
|
642 |
-
return gzuncompress($body);
|
643 |
-
} else {
|
644 |
-
return gzinflate($body);
|
645 |
-
}
|
646 |
-
}
|
647 |
-
|
648 |
-
/**
|
649 |
-
* Create a new Microsoft_Http_Response object from a string
|
650 |
-
*
|
651 |
-
* @param string $response_str
|
652 |
-
* @return Microsoft_Http_Response
|
653 |
-
*/
|
654 |
-
public static function fromString($response_str)
|
655 |
-
{
|
656 |
-
$code = self::extractCode($response_str);
|
657 |
-
$headers = self::extractHeaders($response_str);
|
658 |
-
$body = self::extractBody($response_str);
|
659 |
-
$version = self::extractVersion($response_str);
|
660 |
-
$message = self::extractMessage($response_str);
|
661 |
-
|
662 |
-
return new Microsoft_Http_Response($code, $headers, $body, $version, $message);
|
663 |
-
}
|
664 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Zend Framework
|
5 |
+
*
|
6 |
+
* LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the new BSD license that is bundled
|
9 |
+
* with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://framework.zend.com/license/new-bsd
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@zend.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category Microsoft
|
17 |
+
* @package Microsoft_Http
|
18 |
+
* @subpackage Response
|
19 |
+
* @version $Id: Response.php 35835 2009-12-17 09:40:36Z unknown $
|
20 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
21 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
22 |
+
*/
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Microsoft_Http_Response represents an HTTP 1.0 / 1.1 response message. It
|
26 |
+
* includes easy access to all the response's different elemts, as well as some
|
27 |
+
* convenience methods for parsing and validating HTTP responses.
|
28 |
+
*
|
29 |
+
* @package Microsoft_Http
|
30 |
+
* @subpackage Response
|
31 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
32 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
33 |
+
*/
|
34 |
+
class Microsoft_Http_Response
|
35 |
+
{
|
36 |
+
/**
|
37 |
+
* List of all known HTTP response codes - used by responseCodeAsText() to
|
38 |
+
* translate numeric codes to messages.
|
39 |
+
*
|
40 |
+
* @var array
|
41 |
+
*/
|
42 |
+
protected static $messages = array(
|
43 |
+
// Informational 1xx
|
44 |
+
100 => 'Continue',
|
45 |
+
101 => 'Switching Protocols',
|
46 |
+
|
47 |
+
// Success 2xx
|
48 |
+
200 => 'OK',
|
49 |
+
201 => 'Created',
|
50 |
+
202 => 'Accepted',
|
51 |
+
203 => 'Non-Authoritative Information',
|
52 |
+
204 => 'No Content',
|
53 |
+
205 => 'Reset Content',
|
54 |
+
206 => 'Partial Content',
|
55 |
+
|
56 |
+
// Redirection 3xx
|
57 |
+
300 => 'Multiple Choices',
|
58 |
+
301 => 'Moved Permanently',
|
59 |
+
302 => 'Found', // 1.1
|
60 |
+
303 => 'See Other',
|
61 |
+
304 => 'Not Modified',
|
62 |
+
305 => 'Use Proxy',
|
63 |
+
// 306 is deprecated but reserved
|
64 |
+
307 => 'Temporary Redirect',
|
65 |
+
|
66 |
+
// Client Error 4xx
|
67 |
+
400 => 'Bad Request',
|
68 |
+
401 => 'Unauthorized',
|
69 |
+
402 => 'Payment Required',
|
70 |
+
403 => 'Forbidden',
|
71 |
+
404 => 'Not Found',
|
72 |
+
405 => 'Method Not Allowed',
|
73 |
+
406 => 'Not Acceptable',
|
74 |
+
407 => 'Proxy Authentication Required',
|
75 |
+
408 => 'Request Timeout',
|
76 |
+
409 => 'Conflict',
|
77 |
+
410 => 'Gone',
|
78 |
+
411 => 'Length Required',
|
79 |
+
412 => 'Precondition Failed',
|
80 |
+
413 => 'Request Entity Too Large',
|
81 |
+
414 => 'Request-URI Too Long',
|
82 |
+
415 => 'Unsupported Media Type',
|
83 |
+
416 => 'Requested Range Not Satisfiable',
|
84 |
+
417 => 'Expectation Failed',
|
85 |
+
|
86 |
+
// Server Error 5xx
|
87 |
+
500 => 'Internal Server Error',
|
88 |
+
501 => 'Not Implemented',
|
89 |
+
502 => 'Bad Gateway',
|
90 |
+
503 => 'Service Unavailable',
|
91 |
+
504 => 'Gateway Timeout',
|
92 |
+
505 => 'HTTP Version Not Supported',
|
93 |
+
509 => 'Bandwidth Limit Exceeded'
|
94 |
+
);
|
95 |
+
|
96 |
+
/**
|
97 |
+
* The HTTP version (1.0, 1.1)
|
98 |
+
*
|
99 |
+
* @var string
|
100 |
+
*/
|
101 |
+
protected $version;
|
102 |
+
|
103 |
+
/**
|
104 |
+
* The HTTP response code
|
105 |
+
*
|
106 |
+
* @var int
|
107 |
+
*/
|
108 |
+
protected $code;
|
109 |
+
|
110 |
+
/**
|
111 |
+
* The HTTP response code as string
|
112 |
+
* (e.g. 'Not Found' for 404 or 'Internal Server Error' for 500)
|
113 |
+
*
|
114 |
+
* @var string
|
115 |
+
*/
|
116 |
+
protected $message;
|
117 |
+
|
118 |
+
/**
|
119 |
+
* The HTTP response headers array
|
120 |
+
*
|
121 |
+
* @var array
|
122 |
+
*/
|
123 |
+
protected $headers = array();
|
124 |
+
|
125 |
+
/**
|
126 |
+
* The HTTP response body
|
127 |
+
*
|
128 |
+
* @var string
|
129 |
+
*/
|
130 |
+
protected $body;
|
131 |
+
|
132 |
+
/**
|
133 |
+
* HTTP response constructor
|
134 |
+
*
|
135 |
+
* In most cases, you would use Microsoft_Http_Response::fromString to parse an HTTP
|
136 |
+
* response string and create a new Microsoft_Http_Response object.
|
137 |
+
*
|
138 |
+
* NOTE: The constructor no longer accepts nulls or empty values for the code and
|
139 |
+
* headers and will throw an exception if the passed values do not form a valid HTTP
|
140 |
+
* responses.
|
141 |
+
*
|
142 |
+
* If no message is passed, the message will be guessed according to the response code.
|
143 |
+
*
|
144 |
+
* @param int $code Response code (200, 404, ...)
|
145 |
+
* @param array $headers Headers array
|
146 |
+
* @param string $body Response body
|
147 |
+
* @param string $version HTTP version
|
148 |
+
* @param string $message Response code as text
|
149 |
+
* @throws Microsoft_Http_Exception
|
150 |
+
*/
|
151 |
+
public function __construct($code, $headers, $body = null, $version = '1.1', $message = null)
|
152 |
+
{
|
153 |
+
// Make sure the response code is valid and set it
|
154 |
+
if (self::responseCodeAsText($code) === null) {
|
155 |
+
require_once 'Microsoft/Http/Exception.php';
|
156 |
+
throw new Microsoft_Http_Exception("{$code} is not a valid HTTP response code");
|
157 |
+
}
|
158 |
+
|
159 |
+
$this->code = $code;
|
160 |
+
|
161 |
+
// Make sure we got valid headers and set them
|
162 |
+
if (! is_array($headers)) {
|
163 |
+
require_once 'Microsoft/Http/Exception.php';
|
164 |
+
throw new Microsoft_Http_Exception('No valid headers were passed');
|
165 |
+
}
|
166 |
+
|
167 |
+
foreach ($headers as $name => $value) {
|
168 |
+
if (is_int($name))
|
169 |
+
list($name, $value) = explode(": ", $value, 1);
|
170 |
+
|
171 |
+
$this->headers[ucwords(strtolower($name))] = $value;
|
172 |
+
}
|
173 |
+
|
174 |
+
// Set the body
|
175 |
+
$this->body = $body;
|
176 |
+
|
177 |
+
// Set the HTTP version
|
178 |
+
if (! preg_match('|^\d\.\d$|', $version)) {
|
179 |
+
require_once 'Microsoft/Http/Exception.php';
|
180 |
+
throw new Microsoft_Http_Exception("Invalid HTTP response version: $version");
|
181 |
+
}
|
182 |
+
|
183 |
+
$this->version = $version;
|
184 |
+
|
185 |
+
// If we got the response message, set it. Else, set it according to
|
186 |
+
// the response code
|
187 |
+
if (is_string($message)) {
|
188 |
+
$this->message = $message;
|
189 |
+
} else {
|
190 |
+
$this->message = self::responseCodeAsText($code);
|
191 |
+
}
|
192 |
+
}
|
193 |
+
|
194 |
+
/**
|
195 |
+
* Check whether the response is an error
|
196 |
+
*
|
197 |
+
* @return boolean
|
198 |
+
*/
|
199 |
+
public function isError()
|
200 |
+
{
|
201 |
+
$restype = floor($this->code / 100);
|
202 |
+
if ($restype == 4 || $restype == 5) {
|
203 |
+
return true;
|
204 |
+
}
|
205 |
+
|
206 |
+
return false;
|
207 |
+
}
|
208 |
+
|
209 |
+
/**
|
210 |
+
* Check whether the response in successful
|
211 |
+
*
|
212 |
+
* @return boolean
|
213 |
+
*/
|
214 |
+
public function isSuccessful()
|
215 |
+
{
|
216 |
+
$restype = floor($this->code / 100);
|
217 |
+
if ($restype == 2 || $restype == 1) { // Shouldn't 3xx count as success as well ???
|
218 |
+
return true;
|
219 |
+
}
|
220 |
+
|
221 |
+
return false;
|
222 |
+
}
|
223 |
+
|
224 |
+
/**
|
225 |
+
* Check whether the response is a redirection
|
226 |
+
*
|
227 |
+
* @return boolean
|
228 |
+
*/
|
229 |
+
public function isRedirect()
|
230 |
+
{
|
231 |
+
$restype = floor($this->code / 100);
|
232 |
+
if ($restype == 3) {
|
233 |
+
return true;
|
234 |
+
}
|
235 |
+
|
236 |
+
return false;
|
237 |
+
}
|
238 |
+
|
239 |
+
/**
|
240 |
+
* Get the response body as string
|
241 |
+
*
|
242 |
+
* This method returns the body of the HTTP response (the content), as it
|
243 |
+
* should be in it's readable version - that is, after decoding it (if it
|
244 |
+
* was decoded), deflating it (if it was gzip compressed), etc.
|
245 |
+
*
|
246 |
+
* If you want to get the raw body (as transfered on wire) use
|
247 |
+
* $this->getRawBody() instead.
|
248 |
+
*
|
249 |
+
* @return string
|
250 |
+
*/
|
251 |
+
public function getBody()
|
252 |
+
{
|
253 |
+
$body = '';
|
254 |
+
|
255 |
+
// Decode the body if it was transfer-encoded
|
256 |
+
switch (strtolower($this->getHeader('transfer-encoding'))) {
|
257 |
+
|
258 |
+
// Handle chunked body
|
259 |
+
case 'chunked':
|
260 |
+
$body = self::decodeChunkedBody($this->body);
|
261 |
+
break;
|
262 |
+
|
263 |
+
// No transfer encoding, or unknown encoding extension:
|
264 |
+
// return body as is
|
265 |
+
default:
|
266 |
+
$body = $this->body;
|
267 |
+
break;
|
268 |
+
}
|
269 |
+
|
270 |
+
// Decode any content-encoding (gzip or deflate) if needed
|
271 |
+
switch (strtolower($this->getHeader('content-encoding'))) {
|
272 |
+
|
273 |
+
// Handle gzip encoding
|
274 |
+
case 'gzip':
|
275 |
+
$body = self::decodeGzip($body);
|
276 |
+
break;
|
277 |
+
|
278 |
+
// Handle deflate encoding
|
279 |
+
case 'deflate':
|
280 |
+
$body = self::decodeDeflate($body);
|
281 |
+
break;
|
282 |
+
|
283 |
+
default:
|
284 |
+
break;
|
285 |
+
}
|
286 |
+
|
287 |
+
return $body;
|
288 |
+
}
|
289 |
+
|
290 |
+
/**
|
291 |
+
* Get the raw response body (as transfered "on wire") as string
|
292 |
+
*
|
293 |
+
* If the body is encoded (with Transfer-Encoding, not content-encoding -
|
294 |
+
* IE "chunked" body), gzip compressed, etc. it will not be decoded.
|
295 |
+
*
|
296 |
+
* @return string
|
297 |
+
*/
|
298 |
+
public function getRawBody()
|
299 |
+
{
|
300 |
+
return $this->body;
|
301 |
+
}
|
302 |
+
|
303 |
+
/**
|
304 |
+
* Get the HTTP version of the response
|
305 |
+
*
|
306 |
+
* @return string
|
307 |
+
*/
|
308 |
+
public function getVersion()
|
309 |
+
{
|
310 |
+
return $this->version;
|
311 |
+
}
|
312 |
+
|
313 |
+
/**
|
314 |
+
* Get the HTTP response status code
|
315 |
+
*
|
316 |
+
* @return int
|
317 |
+
*/
|
318 |
+
public function getStatus()
|
319 |
+
{
|
320 |
+
return $this->code;
|
321 |
+
}
|
322 |
+
|
323 |
+
/**
|
324 |
+
* Return a message describing the HTTP response code
|
325 |
+
* (Eg. "OK", "Not Found", "Moved Permanently")
|
326 |
+
*
|
327 |
+
* @return string
|
328 |
+
*/
|
329 |
+
public function getMessage()
|
330 |
+
{
|
331 |
+
return $this->message;
|
332 |
+
}
|
333 |
+
|
334 |
+
/**
|
335 |
+
* Get the response headers
|
336 |
+
*
|
337 |
+
* @return array
|
338 |
+
*/
|
339 |
+
public function getHeaders()
|
340 |
+
{
|
341 |
+
return $this->headers;
|
342 |
+
}
|
343 |
+
|
344 |
+
/**
|
345 |
+
* Get a specific header as string, or null if it is not set
|
346 |
+
*
|
347 |
+
* @param string$header
|
348 |
+
* @return string|array|null
|
349 |
+
*/
|
350 |
+
public function getHeader($header)
|
351 |
+
{
|
352 |
+
$header = ucwords(strtolower($header));
|
353 |
+
if (! is_string($header) || ! isset($this->headers[$header])) return null;
|
354 |
+
|
355 |
+
return $this->headers[$header];
|
356 |
+
}
|
357 |
+
|
358 |
+
/**
|
359 |
+
* Get all headers as string
|
360 |
+
*
|
361 |
+
* @param boolean $status_line Whether to return the first status line (IE "HTTP 200 OK")
|
362 |
+
* @param string $br Line breaks (eg. "\n", "\r\n", "<br />")
|
363 |
+
* @return string
|
364 |
+
*/
|
365 |
+
public function getHeadersAsString($status_line = true, $br = "\n")
|
366 |
+
{
|
367 |
+
$str = '';
|
368 |
+
|
369 |
+
if ($status_line) {
|
370 |
+
$str = "HTTP/{$this->version} {$this->code} {$this->message}{$br}";
|
371 |
+
}
|
372 |
+
|
373 |
+
// Iterate over the headers and stringify them
|
374 |
+
foreach ($this->headers as $name => $value)
|
375 |
+
{
|
376 |
+
if (is_string($value))
|
377 |
+
$str .= "{$name}: {$value}{$br}";
|
378 |
+
|
379 |
+
elseif (is_array($value)) {
|
380 |
+
foreach ($value as $subval) {
|
381 |
+
$str .= "{$name}: {$subval}{$br}";
|
382 |
+
}
|
383 |
+
}
|
384 |
+
}
|
385 |
+
|
386 |
+
return $str;
|
387 |
+
}
|
388 |
+
|
389 |
+
/**
|
390 |
+
* Get the entire response as string
|
391 |
+
*
|
392 |
+
* @param string $br Line breaks (eg. "\n", "\r\n", "<br />")
|
393 |
+
* @return string
|
394 |
+
*/
|
395 |
+
public function asString($br = "\n")
|
396 |
+
{
|
397 |
+
return $this->getHeadersAsString(true, $br) . $br . $this->getRawBody();
|
398 |
+
}
|
399 |
+
|
400 |
+
/**
|
401 |
+
* Implements magic __toString()
|
402 |
+
*
|
403 |
+
* @return string
|
404 |
+
*/
|
405 |
+
public function __toString()
|
406 |
+
{
|
407 |
+
return $this->asString();
|
408 |
+
}
|
409 |
+
|
410 |
+
/**
|
411 |
+
* A convenience function that returns a text representation of
|
412 |
+
* HTTP response codes. Returns 'Unknown' for unknown codes.
|
413 |
+
* Returns array of all codes, if $code is not specified.
|
414 |
+
*
|
415 |
+
* Conforms to HTTP/1.1 as defined in RFC 2616 (except for 'Unknown')
|
416 |
+
* See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10 for reference
|
417 |
+
*
|
418 |
+
* @param int $code HTTP response code
|
419 |
+
* @param boolean $http11 Use HTTP version 1.1
|
420 |
+
* @return string
|
421 |
+
*/
|
422 |
+
public static function responseCodeAsText($code = null, $http11 = true)
|
423 |
+
{
|
424 |
+
$messages = self::$messages;
|
425 |
+
if (! $http11) $messages[302] = 'Moved Temporarily';
|
426 |
+
|
427 |
+
if ($code === null) {
|
428 |
+
return $messages;
|
429 |
+
} elseif (isset($messages[$code])) {
|
430 |
+
return $messages[$code];
|
431 |
+
} else {
|
432 |
+
return 'Unknown';
|
433 |
+
}
|
434 |
+
}
|
435 |
+
|
436 |
+
/**
|
437 |
+
* Extract the response code from a response string
|
438 |
+
*
|
439 |
+
* @param string $response_str
|
440 |
+
* @return int
|
441 |
+
*/
|
442 |
+
public static function extractCode($response_str)
|
443 |
+
{
|
444 |
+
preg_match("|^HTTP/[\d\.x]+ (\d+)|", $response_str, $m);
|
445 |
+
|
446 |
+
if (isset($m[1])) {
|
447 |
+
return (int) $m[1];
|
448 |
+
} else {
|
449 |
+
return false;
|
450 |
+
}
|
451 |
+
}
|
452 |
+
|
453 |
+
/**
|
454 |
+
* Extract the HTTP message from a response
|
455 |
+
*
|
456 |
+
* @param string $response_str
|
457 |
+
* @return string
|
458 |
+
*/
|
459 |
+
public static function extractMessage($response_str)
|
460 |
+
{
|
461 |
+
preg_match("|^HTTP/[\d\.x]+ \d+ ([^\r\n]+)|", $response_str, $m);
|
462 |
+
|
463 |
+
if (isset($m[1])) {
|
464 |
+
return $m[1];
|
465 |
+
} else {
|
466 |
+
return false;
|
467 |
+
}
|
468 |
+
}
|
469 |
+
|
470 |
+
/**
|
471 |
+
* Extract the HTTP version from a response
|
472 |
+
*
|
473 |
+
* @param string $response_str
|
474 |
+
* @return string
|
475 |
+
*/
|
476 |
+
public static function extractVersion($response_str)
|
477 |
+
{
|
478 |
+
preg_match("|^HTTP/([\d\.x]+) \d+|", $response_str, $m);
|
479 |
+
|
480 |
+
if (isset($m[1])) {
|
481 |
+
return $m[1];
|
482 |
+
} else {
|
483 |
+
return false;
|
484 |
+
}
|
485 |
+
}
|
486 |
+
|
487 |
+
/**
|
488 |
+
* Extract the headers from a response string
|
489 |
+
*
|
490 |
+
* @param string $response_str
|
491 |
+
* @return array
|
492 |
+
*/
|
493 |
+
public static function extractHeaders($response_str)
|
494 |
+
{
|
495 |
+
$headers = array();
|
496 |
+
|
497 |
+
// First, split body and headers
|
498 |
+
$parts = preg_split('|(?:\r?\n){2}|m', $response_str, 2);
|
499 |
+
if (! $parts[0]) return $headers;
|
500 |
+
|
501 |
+
// Split headers part to lines
|
502 |
+
$lines = explode("\n", $parts[0]);
|
503 |
+
unset($parts);
|
504 |
+
$last_header = null;
|
505 |
+
|
506 |
+
foreach($lines as $line) {
|
507 |
+
$line = trim($line, "\r\n");
|
508 |
+
if ($line == "") break;
|
509 |
+
|
510 |
+
if (preg_match("|^([\w-]+):\s+(.+)|", $line, $m)) {
|
511 |
+
unset($last_header);
|
512 |
+
$h_name = strtolower($m[1]);
|
513 |
+
$h_value = $m[2];
|
514 |
+
|
515 |
+
if (isset($headers[$h_name])) {
|
516 |
+
if (! is_array($headers[$h_name])) {
|
517 |
+
$headers[$h_name] = array($headers[$h_name]);
|
518 |
+
}
|
519 |
+
|
520 |
+
$headers[$h_name][] = $h_value;
|
521 |
+
} else {
|
522 |
+
$headers[$h_name] = $h_value;
|
523 |
+
}
|
524 |
+
$last_header = $h_name;
|
525 |
+
} elseif (preg_match("|^\s+(.+)$|", $line, $m) && $last_header !== null) {
|
526 |
+
if (is_array($headers[$last_header])) {
|
527 |
+
end($headers[$last_header]);
|
528 |
+
$last_header_key = key($headers[$last_header]);
|
529 |
+
$headers[$last_header][$last_header_key] .= $m[1];
|
530 |
+
} else {
|
531 |
+
$headers[$last_header] .= $m[1];
|
532 |
+
}
|
533 |
+
}
|
534 |
+
}
|
535 |
+
|
536 |
+
return $headers;
|
537 |
+
}
|
538 |
+
|
539 |
+
/**
|
540 |
+
* Extract the body from a response string
|
541 |
+
*
|
542 |
+
* @param string $response_str
|
543 |
+
* @return string
|
544 |
+
*/
|
545 |
+
public static function extractBody($response_str)
|
546 |
+
{
|
547 |
+
$parts = preg_split('|(?:\r?\n){2}|m', $response_str, 2);
|
548 |
+
if (isset($parts[1])) {
|
549 |
+
return $parts[1];
|
550 |
+
}
|
551 |
+
return '';
|
552 |
+
}
|
553 |
+
|
554 |
+
/**
|
555 |
+
* Decode a "chunked" transfer-encoded body and return the decoded text
|
556 |
+
*
|
557 |
+
* @param string $body
|
558 |
+
* @return string
|
559 |
+
*/
|
560 |
+
public static function decodeChunkedBody($body)
|
561 |
+
{
|
562 |
+
$decBody = '';
|
563 |
+
|
564 |
+
// If mbstring overloads substr and strlen functions, we have to
|
565 |
+
// override it's internal encoding
|
566 |
+
if (function_exists('mb_internal_encoding') &&
|
567 |
+
((int) ini_get('mbstring.func_overload')) & 2) {
|
568 |
+
|
569 |
+
$mbIntEnc = mb_internal_encoding();
|
570 |
+
mb_internal_encoding('ASCII');
|
571 |
+
}
|
572 |
+
|
573 |
+
while (trim($body)) {
|
574 |
+
if (! preg_match("/^([\da-fA-F]+)[^\r\n]*\r\n/sm", $body, $m)) {
|
575 |
+
require_once 'Microsoft/Http/Exception.php';
|
576 |
+
throw new Microsoft_Http_Exception("Error parsing body - doesn't seem to be a chunked message");
|
577 |
+
}
|
578 |
+
|
579 |
+
$length = hexdec(trim($m[1]));
|
580 |
+
$cut = strlen($m[0]);
|
581 |
+
$decBody .= substr($body, $cut, $length);
|
582 |
+
$body = substr($body, $cut + $length + 2);
|
583 |
+
}
|
584 |
+
|
585 |
+
if (isset($mbIntEnc)) {
|
586 |
+
mb_internal_encoding($mbIntEnc);
|
587 |
+
}
|
588 |
+
|
589 |
+
return $decBody;
|
590 |
+
}
|
591 |
+
|
592 |
+
/**
|
593 |
+
* Decode a gzip encoded message (when Content-encoding = gzip)
|
594 |
+
*
|
595 |
+
* Currently requires PHP with zlib support
|
596 |
+
*
|
597 |
+
* @param string $body
|
598 |
+
* @return string
|
599 |
+
*/
|
600 |
+
public static function decodeGzip($body)
|
601 |
+
{
|
602 |
+
if (! function_exists('gzinflate')) {
|
603 |
+
require_once 'Microsoft/Http/Exception.php';
|
604 |
+
throw new Microsoft_Http_Exception(
|
605 |
+
'zlib extension is required in order to decode "gzip" encoding'
|
606 |
+
);
|
607 |
+
}
|
608 |
+
|
609 |
+
return gzinflate(substr($body, 10));
|
610 |
+
}
|
611 |
+
|
612 |
+
/**
|
613 |
+
* Decode a zlib deflated message (when Content-encoding = deflate)
|
614 |
+
*
|
615 |
+
* Currently requires PHP with zlib support
|
616 |
+
*
|
617 |
+
* @param string $body
|
618 |
+
* @return string
|
619 |
+
*/
|
620 |
+
public static function decodeDeflate($body)
|
621 |
+
{
|
622 |
+
if (! function_exists('gzuncompress')) {
|
623 |
+
require_once 'Microsoft/Http/Exception.php';
|
624 |
+
throw new Microsoft_Http_Exception(
|
625 |
+
'zlib extension is required in order to decode "deflate" encoding'
|
626 |
+
);
|
627 |
+
}
|
628 |
+
|
629 |
+
/**
|
630 |
+
* Some servers (IIS ?) send a broken deflate response, without the
|
631 |
+
* RFC-required zlib header.
|
632 |
+
*
|
633 |
+
* We try to detect the zlib header, and if it does not exsit we
|
634 |
+
* teat the body is plain DEFLATE content.
|
635 |
+
*
|
636 |
+
* This method was adapted from PEAR HTTP_Request2 by (c) Alexey Borzov
|
637 |
+
*
|
638 |
+
* @link http://framework.zend.com/issues/browse/ZF-6040
|
639 |
+
*/
|
640 |
+
$zlibHeader = unpack('n', substr($body, 0, 2));
|
641 |
+
if ($zlibHeader[1] % 31 == 0) {
|
642 |
+
return gzuncompress($body);
|
643 |
+
} else {
|
644 |
+
return gzinflate($body);
|
645 |
+
}
|
646 |
+
}
|
647 |
+
|
648 |
+
/**
|
649 |
+
* Create a new Microsoft_Http_Response object from a string
|
650 |
+
*
|
651 |
+
* @param string $response_str
|
652 |
+
* @return Microsoft_Http_Response
|
653 |
+
*/
|
654 |
+
public static function fromString($response_str)
|
655 |
+
{
|
656 |
+
$code = self::extractCode($response_str);
|
657 |
+
$headers = self::extractHeaders($response_str);
|
658 |
+
$body = self::extractBody($response_str);
|
659 |
+
$version = self::extractVersion($response_str);
|
660 |
+
$message = self::extractMessage($response_str);
|
661 |
+
|
662 |
+
return new Microsoft_Http_Response($code, $headers, $body, $version, $message);
|
663 |
+
}
|
664 |
+
}
|
libs/Microsoft/Http/Response/Stream.php
CHANGED
@@ -1,240 +1,240 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Zend Framework
|
5 |
-
*
|
6 |
-
* LICENSE
|
7 |
-
*
|
8 |
-
* This source file is subject to the new BSD license that is bundled
|
9 |
-
* with this package in the file LICENSE.txt.
|
10 |
-
* It is also available through the world-wide-web at this URL:
|
11 |
-
* http://framework.zend.com/license/new-bsd
|
12 |
-
* If you did not receive a copy of the license and are unable to
|
13 |
-
* obtain it through the world-wide-web, please send an email
|
14 |
-
* to license@zend.com so we can send you a copy immediately.
|
15 |
-
*
|
16 |
-
* @category Microsoft
|
17 |
-
* @package Microsoft_Http
|
18 |
-
* @subpackage Response
|
19 |
-
* @version $Id: Response.php 17131 2009-07-26 10:03:39Z shahar $
|
20 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
21 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
22 |
-
*/
|
23 |
-
|
24 |
-
/**
|
25 |
-
* @see Microsoft_AutoLoader
|
26 |
-
*/
|
27 |
-
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
28 |
-
|
29 |
-
/**
|
30 |
-
* Microsoft_Http_Response represents an HTTP 1.0 / 1.1 response message. It
|
31 |
-
* includes easy access to all the response's different elemts, as well as some
|
32 |
-
* convenience methods for parsing and validating HTTP responses.
|
33 |
-
*
|
34 |
-
* @package Microsoft_Http
|
35 |
-
* @subpackage Response
|
36 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
37 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
38 |
-
*/
|
39 |
-
class Microsoft_Http_Response_Stream extends Microsoft_Http_Response
|
40 |
-
{
|
41 |
-
/**
|
42 |
-
* Response as stream
|
43 |
-
*
|
44 |
-
* @var resource
|
45 |
-
*/
|
46 |
-
protected $stream;
|
47 |
-
|
48 |
-
/**
|
49 |
-
* The name of the file containing the stream
|
50 |
-
*
|
51 |
-
* Will be empty if stream is not file-based.
|
52 |
-
*
|
53 |
-
* @var string
|
54 |
-
*/
|
55 |
-
protected $stream_name;
|
56 |
-
|
57 |
-
/**
|
58 |
-
* Should we clean up the stream file when this response is closed?
|
59 |
-
*
|
60 |
-
* @var boolean
|
61 |
-
*/
|
62 |
-
protected $_cleanup;
|
63 |
-
|
64 |
-
/**
|
65 |
-
* Get the response as stream
|
66 |
-
*
|
67 |
-
* @return resourse
|
68 |
-
*/
|
69 |
-
public function getStream()
|
70 |
-
{
|
71 |
-
return $this->stream;
|
72 |
-
}
|
73 |
-
|
74 |
-
/**
|
75 |
-
* Set the response stream
|
76 |
-
*
|
77 |
-
* @param resourse $stream
|
78 |
-
* @return Microsoft_Http_Response_Stream
|
79 |
-
*/
|
80 |
-
public function setStream($stream)
|
81 |
-
{
|
82 |
-
$this->stream = $stream;
|
83 |
-
return $this;
|
84 |
-
}
|
85 |
-
|
86 |
-
/**
|
87 |
-
* Get the cleanup trigger
|
88 |
-
*
|
89 |
-
* @return boolean
|
90 |
-
*/
|
91 |
-
public function getCleanup() {
|
92 |
-
return $this->_cleanup;
|
93 |
-
}
|
94 |
-
|
95 |
-
/**
|
96 |
-
* Set the cleanup trigger
|
97 |
-
*
|
98 |
-
* @param $cleanup Set cleanup trigger
|
99 |
-
*/
|
100 |
-
public function setCleanup($cleanup = true) {
|
101 |
-
$this->_cleanup = $cleanup;
|
102 |
-
}
|
103 |
-
|
104 |
-
/**
|
105 |
-
* Get file name associated with the stream
|
106 |
-
*
|
107 |
-
* @return string
|
108 |
-
*/
|
109 |
-
public function getStreamName() {
|
110 |
-
return $this->stream_name;
|
111 |
-
}
|
112 |
-
|
113 |
-
/**
|
114 |
-
* Set file name associated with the stream
|
115 |
-
*
|
116 |
-
* @param string $stream_name Name to set
|
117 |
-
* @return Microsoft_Http_Response_Stream
|
118 |
-
*/
|
119 |
-
public function setStreamName($stream_name) {
|
120 |
-
$this->stream_name = $stream_name;
|
121 |
-
return $this;
|
122 |
-
}
|
123 |
-
|
124 |
-
|
125 |
-
/**
|
126 |
-
* HTTP response constructor
|
127 |
-
*
|
128 |
-
* In most cases, you would use Microsoft_Http_Response::fromString to parse an HTTP
|
129 |
-
* response string and create a new Microsoft_Http_Response object.
|
130 |
-
*
|
131 |
-
* NOTE: The constructor no longer accepts nulls or empty values for the code and
|
132 |
-
* headers and will throw an exception if the passed values do not form a valid HTTP
|
133 |
-
* responses.
|
134 |
-
*
|
135 |
-
* If no message is passed, the message will be guessed according to the response code.
|
136 |
-
*
|
137 |
-
* @param int $code Response code (200, 404, ...)
|
138 |
-
* @param array $headers Headers array
|
139 |
-
* @param string $body Response body
|
140 |
-
* @param string $version HTTP version
|
141 |
-
* @param string $message Response code as text
|
142 |
-
* @throws Microsoft_Http_Exception
|
143 |
-
*/
|
144 |
-
public function __construct($code, $headers, $body = null, $version = '1.1', $message = null)
|
145 |
-
{
|
146 |
-
|
147 |
-
if(is_resource($body)) {
|
148 |
-
$this->setStream($body);
|
149 |
-
$body = '';
|
150 |
-
}
|
151 |
-
parent::__construct($code, $headers, $body, $version, $message);
|
152 |
-
}
|
153 |
-
|
154 |
-
/**
|
155 |
-
* Create a new Microsoft_Http_Response_Stream object from a string
|
156 |
-
*
|
157 |
-
* @param string $response_str
|
158 |
-
* @param resource $stream
|
159 |
-
* @return Microsoft_Http_Response_Stream
|
160 |
-
*/
|
161 |
-
public static function fromStream($response_str, $stream)
|
162 |
-
{
|
163 |
-
$code = self::extractCode($response_str);
|
164 |
-
$headers = self::extractHeaders($response_str);
|
165 |
-
$version = self::extractVersion($response_str);
|
166 |
-
$message = self::extractMessage($response_str);
|
167 |
-
|
168 |
-
return new self($code, $headers, $stream, $version, $message);
|
169 |
-
}
|
170 |
-
|
171 |
-
/**
|
172 |
-
* Get the response body as string
|
173 |
-
*
|
174 |
-
* This method returns the body of the HTTP response (the content), as it
|
175 |
-
* should be in it's readable version - that is, after decoding it (if it
|
176 |
-
* was decoded), deflating it (if it was gzip compressed), etc.
|
177 |
-
*
|
178 |
-
* If you want to get the raw body (as transfered on wire) use
|
179 |
-
* $this->getRawBody() instead.
|
180 |
-
*
|
181 |
-
* @return string
|
182 |
-
*/
|
183 |
-
public function getBody()
|
184 |
-
{
|
185 |
-
if($this->stream != null) {
|
186 |
-
$this->readStream();
|
187 |
-
}
|
188 |
-
return parent::getBody();
|
189 |
-
}
|
190 |
-
|
191 |
-
/**
|
192 |
-
* Get the raw response body (as transfered "on wire") as string
|
193 |
-
*
|
194 |
-
* If the body is encoded (with Transfer-Encoding, not content-encoding -
|
195 |
-
* IE "chunked" body), gzip compressed, etc. it will not be decoded.
|
196 |
-
*
|
197 |
-
* @return string
|
198 |
-
*/
|
199 |
-
public function getRawBody()
|
200 |
-
{
|
201 |
-
if($this->stream) {
|
202 |
-
$this->readStream();
|
203 |
-
}
|
204 |
-
return $this->body;
|
205 |
-
}
|
206 |
-
|
207 |
-
/**
|
208 |
-
* Read stream content and return it as string
|
209 |
-
*
|
210 |
-
* Function reads the remainder of the body from the stream and closes the stream.
|
211 |
-
*
|
212 |
-
* @return string
|
213 |
-
*/
|
214 |
-
protected function readStream()
|
215 |
-
{
|
216 |
-
if(!is_resource($this->stream)) {
|
217 |
-
return '';
|
218 |
-
}
|
219 |
-
|
220 |
-
if(isset($headers['content-length'])) {
|
221 |
-
$this->body = stream_get_contents($this->stream, $headers['content-length']);
|
222 |
-
} else {
|
223 |
-
$this->body = stream_get_contents($this->stream);
|
224 |
-
}
|
225 |
-
fclose($this->stream);
|
226 |
-
$this->stream = null;
|
227 |
-
}
|
228 |
-
|
229 |
-
public function __destruct()
|
230 |
-
{
|
231 |
-
if(is_resource($this->stream)) {
|
232 |
-
fclose($this->stream);
|
233 |
-
$this->stream = null;
|
234 |
-
}
|
235 |
-
if($this->_cleanup) {
|
236 |
-
@unlink($this->stream_name);
|
237 |
-
}
|
238 |
-
}
|
239 |
-
|
240 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Zend Framework
|
5 |
+
*
|
6 |
+
* LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the new BSD license that is bundled
|
9 |
+
* with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://framework.zend.com/license/new-bsd
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@zend.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category Microsoft
|
17 |
+
* @package Microsoft_Http
|
18 |
+
* @subpackage Response
|
19 |
+
* @version $Id: Response.php 17131 2009-07-26 10:03:39Z shahar $
|
20 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
21 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
22 |
+
*/
|
23 |
+
|
24 |
+
/**
|
25 |
+
* @see Microsoft_AutoLoader
|
26 |
+
*/
|
27 |
+
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Microsoft_Http_Response represents an HTTP 1.0 / 1.1 response message. It
|
31 |
+
* includes easy access to all the response's different elemts, as well as some
|
32 |
+
* convenience methods for parsing and validating HTTP responses.
|
33 |
+
*
|
34 |
+
* @package Microsoft_Http
|
35 |
+
* @subpackage Response
|
36 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
37 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
38 |
+
*/
|
39 |
+
class Microsoft_Http_Response_Stream extends Microsoft_Http_Response
|
40 |
+
{
|
41 |
+
/**
|
42 |
+
* Response as stream
|
43 |
+
*
|
44 |
+
* @var resource
|
45 |
+
*/
|
46 |
+
protected $stream;
|
47 |
+
|
48 |
+
/**
|
49 |
+
* The name of the file containing the stream
|
50 |
+
*
|
51 |
+
* Will be empty if stream is not file-based.
|
52 |
+
*
|
53 |
+
* @var string
|
54 |
+
*/
|
55 |
+
protected $stream_name;
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Should we clean up the stream file when this response is closed?
|
59 |
+
*
|
60 |
+
* @var boolean
|
61 |
+
*/
|
62 |
+
protected $_cleanup;
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Get the response as stream
|
66 |
+
*
|
67 |
+
* @return resourse
|
68 |
+
*/
|
69 |
+
public function getStream()
|
70 |
+
{
|
71 |
+
return $this->stream;
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Set the response stream
|
76 |
+
*
|
77 |
+
* @param resourse $stream
|
78 |
+
* @return Microsoft_Http_Response_Stream
|
79 |
+
*/
|
80 |
+
public function setStream($stream)
|
81 |
+
{
|
82 |
+
$this->stream = $stream;
|
83 |
+
return $this;
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Get the cleanup trigger
|
88 |
+
*
|
89 |
+
* @return boolean
|
90 |
+
*/
|
91 |
+
public function getCleanup() {
|
92 |
+
return $this->_cleanup;
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Set the cleanup trigger
|
97 |
+
*
|
98 |
+
* @param $cleanup Set cleanup trigger
|
99 |
+
*/
|
100 |
+
public function setCleanup($cleanup = true) {
|
101 |
+
$this->_cleanup = $cleanup;
|
102 |
+
}
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Get file name associated with the stream
|
106 |
+
*
|
107 |
+
* @return string
|
108 |
+
*/
|
109 |
+
public function getStreamName() {
|
110 |
+
return $this->stream_name;
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Set file name associated with the stream
|
115 |
+
*
|
116 |
+
* @param string $stream_name Name to set
|
117 |
+
* @return Microsoft_Http_Response_Stream
|
118 |
+
*/
|
119 |
+
public function setStreamName($stream_name) {
|
120 |
+
$this->stream_name = $stream_name;
|
121 |
+
return $this;
|
122 |
+
}
|
123 |
+
|
124 |
+
|
125 |
+
/**
|
126 |
+
* HTTP response constructor
|
127 |
+
*
|
128 |
+
* In most cases, you would use Microsoft_Http_Response::fromString to parse an HTTP
|
129 |
+
* response string and create a new Microsoft_Http_Response object.
|
130 |
+
*
|
131 |
+
* NOTE: The constructor no longer accepts nulls or empty values for the code and
|
132 |
+
* headers and will throw an exception if the passed values do not form a valid HTTP
|
133 |
+
* responses.
|
134 |
+
*
|
135 |
+
* If no message is passed, the message will be guessed according to the response code.
|
136 |
+
*
|
137 |
+
* @param int $code Response code (200, 404, ...)
|
138 |
+
* @param array $headers Headers array
|
139 |
+
* @param string $body Response body
|
140 |
+
* @param string $version HTTP version
|
141 |
+
* @param string $message Response code as text
|
142 |
+
* @throws Microsoft_Http_Exception
|
143 |
+
*/
|
144 |
+
public function __construct($code, $headers, $body = null, $version = '1.1', $message = null)
|
145 |
+
{
|
146 |
+
|
147 |
+
if(is_resource($body)) {
|
148 |
+
$this->setStream($body);
|
149 |
+
$body = '';
|
150 |
+
}
|
151 |
+
parent::__construct($code, $headers, $body, $version, $message);
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Create a new Microsoft_Http_Response_Stream object from a string
|
156 |
+
*
|
157 |
+
* @param string $response_str
|
158 |
+
* @param resource $stream
|
159 |
+
* @return Microsoft_Http_Response_Stream
|
160 |
+
*/
|
161 |
+
public static function fromStream($response_str, $stream)
|
162 |
+
{
|
163 |
+
$code = self::extractCode($response_str);
|
164 |
+
$headers = self::extractHeaders($response_str);
|
165 |
+
$version = self::extractVersion($response_str);
|
166 |
+
$message = self::extractMessage($response_str);
|
167 |
+
|
168 |
+
return new self($code, $headers, $stream, $version, $message);
|
169 |
+
}
|
170 |
+
|
171 |
+
/**
|
172 |
+
* Get the response body as string
|
173 |
+
*
|
174 |
+
* This method returns the body of the HTTP response (the content), as it
|
175 |
+
* should be in it's readable version - that is, after decoding it (if it
|
176 |
+
* was decoded), deflating it (if it was gzip compressed), etc.
|
177 |
+
*
|
178 |
+
* If you want to get the raw body (as transfered on wire) use
|
179 |
+
* $this->getRawBody() instead.
|
180 |
+
*
|
181 |
+
* @return string
|
182 |
+
*/
|
183 |
+
public function getBody()
|
184 |
+
{
|
185 |
+
if($this->stream != null) {
|
186 |
+
$this->readStream();
|
187 |
+
}
|
188 |
+
return parent::getBody();
|
189 |
+
}
|
190 |
+
|
191 |
+
/**
|
192 |
+
* Get the raw response body (as transfered "on wire") as string
|
193 |
+
*
|
194 |
+
* If the body is encoded (with Transfer-Encoding, not content-encoding -
|
195 |
+
* IE "chunked" body), gzip compressed, etc. it will not be decoded.
|
196 |
+
*
|
197 |
+
* @return string
|
198 |
+
*/
|
199 |
+
public function getRawBody()
|
200 |
+
{
|
201 |
+
if($this->stream) {
|
202 |
+
$this->readStream();
|
203 |
+
}
|
204 |
+
return $this->body;
|
205 |
+
}
|
206 |
+
|
207 |
+
/**
|
208 |
+
* Read stream content and return it as string
|
209 |
+
*
|
210 |
+
* Function reads the remainder of the body from the stream and closes the stream.
|
211 |
+
*
|
212 |
+
* @return string
|
213 |
+
*/
|
214 |
+
protected function readStream()
|
215 |
+
{
|
216 |
+
if(!is_resource($this->stream)) {
|
217 |
+
return '';
|
218 |
+
}
|
219 |
+
|
220 |
+
if(isset($headers['content-length'])) {
|
221 |
+
$this->body = stream_get_contents($this->stream, $headers['content-length']);
|
222 |
+
} else {
|
223 |
+
$this->body = stream_get_contents($this->stream);
|
224 |
+
}
|
225 |
+
fclose($this->stream);
|
226 |
+
$this->stream = null;
|
227 |
+
}
|
228 |
+
|
229 |
+
public function __destruct()
|
230 |
+
{
|
231 |
+
if(is_resource($this->stream)) {
|
232 |
+
fclose($this->stream);
|
233 |
+
$this->stream = null;
|
234 |
+
}
|
235 |
+
if($this->_cleanup) {
|
236 |
+
@unlink($this->stream_name);
|
237 |
+
}
|
238 |
+
}
|
239 |
+
|
240 |
+
}
|
libs/Microsoft/Log.php
CHANGED
@@ -1,426 +1,426 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Zend Framework
|
4 |
-
*
|
5 |
-
* LICENSE
|
6 |
-
*
|
7 |
-
* This source file is subject to the new BSD license that is bundled
|
8 |
-
* with this package in the file LICENSE.txt.
|
9 |
-
* It is also available through the world-wide-web at this URL:
|
10 |
-
* http://framework.zend.com/license/new-bsd
|
11 |
-
* If you did not receive a copy of the license and are unable to
|
12 |
-
* obtain it through the world-wide-web, please send an email
|
13 |
-
* to license@zend.com so we can send you a copy immediately.
|
14 |
-
*
|
15 |
-
* @category Microsoft
|
16 |
-
* @package Microsoft_Log
|
17 |
-
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
18 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
19 |
-
* @version $Id: Log.php 22632 2010-07-18 18:30:08Z ramon $
|
20 |
-
*/
|
21 |
-
|
22 |
-
/**
|
23 |
-
* @see Microsoft_AutoLoader
|
24 |
-
*/
|
25 |
-
require_once dirname(__FILE__) . '/AutoLoader.php';
|
26 |
-
|
27 |
-
/**
|
28 |
-
* @category Microsoft
|
29 |
-
* @package Microsoft_Log
|
30 |
-
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
31 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
32 |
-
* @version $Id: Log.php 22632 2010-07-18 18:30:08Z ramon $
|
33 |
-
*/
|
34 |
-
class Microsoft_Log
|
35 |
-
{
|
36 |
-
const EMERG = 0; // Emergency: system is unusable
|
37 |
-
const ALERT = 1; // Alert: action must be taken immediately
|
38 |
-
const CRIT = 2; // Critical: critical conditions
|
39 |
-
const ERR = 3; // Error: error conditions
|
40 |
-
const WARN = 4; // Warning: warning conditions
|
41 |
-
const NOTICE = 5; // Notice: normal but significant condition
|
42 |
-
const INFO = 6; // Informational: informational messages
|
43 |
-
const DEBUG = 7; // Debug: debug messages
|
44 |
-
|
45 |
-
/**
|
46 |
-
* @var array of priorities where the keys are the
|
47 |
-
* priority numbers and the values are the priority names
|
48 |
-
*/
|
49 |
-
protected $_priorities = array();
|
50 |
-
|
51 |
-
/**
|
52 |
-
* @var array of Microsoft_Log_Writer_Abstract
|
53 |
-
*/
|
54 |
-
protected $_writers = array();
|
55 |
-
|
56 |
-
/**
|
57 |
-
* @var array of Microsoft_Log_Filter_Interface
|
58 |
-
*/
|
59 |
-
protected $_filters = array();
|
60 |
-
|
61 |
-
/**
|
62 |
-
* @var array of extra log event
|
63 |
-
*/
|
64 |
-
protected $_extras = array();
|
65 |
-
|
66 |
-
/**
|
67 |
-
*
|
68 |
-
* @var string
|
69 |
-
*/
|
70 |
-
protected $_defaultWriterNamespace = 'Microsoft_Log_Writer';
|
71 |
-
|
72 |
-
/**
|
73 |
-
*
|
74 |
-
* @var string
|
75 |
-
*/
|
76 |
-
protected $_defaultFilterNamespace = 'Microsoft_Log_Filter';
|
77 |
-
|
78 |
-
|
79 |
-
/**
|
80 |
-
* Class constructor. Create a new logger
|
81 |
-
*
|
82 |
-
* @param Microsoft_Log_Writer_Abstract|null $writer default writer
|
83 |
-
*/
|
84 |
-
public function __construct(Microsoft_Log_Writer_Abstract $writer = null)
|
85 |
-
{
|
86 |
-
$r = new ReflectionClass($this);
|
87 |
-
$this->_priorities = array_flip($r->getConstants());
|
88 |
-
|
89 |
-
if ($writer !== null) {
|
90 |
-
$this->addWriter($writer);
|
91 |
-
}
|
92 |
-
}
|
93 |
-
|
94 |
-
/**
|
95 |
-
* Factory to construct the logger and one or more writers
|
96 |
-
* based on the configuration array
|
97 |
-
*
|
98 |
-
* @param array $config
|
99 |
-
* @return Microsoft_Log
|
100 |
-
*/
|
101 |
-
static public function factory($config = array())
|
102 |
-
{
|
103 |
-
if (!is_array($config) || empty($config)) {
|
104 |
-
/** @see Microsoft_Log_Exception */
|
105 |
-
require_once 'Microsoft/Log/Exception.php';
|
106 |
-
throw new Microsoft_Log_Exception('Configuration must be an array');
|
107 |
-
}
|
108 |
-
|
109 |
-
$log = new Microsoft_Log;
|
110 |
-
|
111 |
-
if (!is_array(current($config))) {
|
112 |
-
$log->addWriter(current($config));
|
113 |
-
} else {
|
114 |
-
foreach($config as $writer) {
|
115 |
-
$log->addWriter($writer);
|
116 |
-
}
|
117 |
-
}
|
118 |
-
|
119 |
-
return $log;
|
120 |
-
}
|
121 |
-
|
122 |
-
|
123 |
-
/**
|
124 |
-
* Construct a writer object based on a configuration array
|
125 |
-
*
|
126 |
-
* @param array $spec config array with writer spec
|
127 |
-
* @return Microsoft_Log_Writer_Abstract
|
128 |
-
*/
|
129 |
-
protected function _constructWriterFromConfig($config)
|
130 |
-
{
|
131 |
-
$writer = $this->_constructFromConfig('writer', $config, $this->_defaultWriterNamespace);
|
132 |
-
|
133 |
-
if (!$writer instanceof Microsoft_Log_Writer_Abstract) {
|
134 |
-
$writerName = is_object($writer)
|
135 |
-
? get_class($writer)
|
136 |
-
: 'The specified writer';
|
137 |
-
/** @see Microsoft_Log_Exception */
|
138 |
-
require_once 'Microsoft/Log/Exception.php';
|
139 |
-
throw new Microsoft_Log_Exception("{$writerName} does not extend Microsoft_Log_Writer_Abstract!");
|
140 |
-
}
|
141 |
-
|
142 |
-
if (isset($config['filterName'])) {
|
143 |
-
$filter = $this->_constructFilterFromConfig($config);
|
144 |
-
$writer->addFilter($filter);
|
145 |
-
}
|
146 |
-
|
147 |
-
return $writer;
|
148 |
-
}
|
149 |
-
|
150 |
-
/**
|
151 |
-
* Construct filter object from configuration array or Microsoft_Config object
|
152 |
-
*
|
153 |
-
* @param array $config
|
154 |
-
* @return Microsoft_Log_Filter_Interface
|
155 |
-
*/
|
156 |
-
protected function _constructFilterFromConfig($config)
|
157 |
-
{
|
158 |
-
$filter = $this->_constructFromConfig('filter', $config, $this->_defaultFilterNamespace);
|
159 |
-
|
160 |
-
if (!$filter instanceof Microsoft_Log_Filter_Interface) {
|
161 |
-
$filterName = is_object($filter)
|
162 |
-
? get_class($filter)
|
163 |
-
: 'The specified filter';
|
164 |
-
/** @see Microsoft_Log_Exception */
|
165 |
-
require_once 'Microsoft/Log/Exception.php';
|
166 |
-
throw new Microsoft_Log_Exception("{$filterName} does not implement Microsoft_Log_Filter_Interface");
|
167 |
-
}
|
168 |
-
|
169 |
-
return $filter;
|
170 |
-
}
|
171 |
-
|
172 |
-
/**
|
173 |
-
* Construct a filter or writer from config
|
174 |
-
*
|
175 |
-
* @param string $type 'writer' of 'filter'
|
176 |
-
* @param array $config
|
177 |
-
* @param string $namespace
|
178 |
-
* @return object
|
179 |
-
*/
|
180 |
-
protected function _constructFromConfig($type, $config, $namespace)
|
181 |
-
{
|
182 |
-
if (!is_array($config) || empty($config)) {
|
183 |
-
require_once 'Microsoft/Log/Exception.php';
|
184 |
-
throw new Microsoft_Log_Exception('Configuration must be an array');
|
185 |
-
}
|
186 |
-
|
187 |
-
$params = isset($config[ $type .'Params' ]) ? $config[ $type .'Params' ] : array();
|
188 |
-
$className = $this->getClassName($config, $type, $namespace);
|
189 |
-
if (!class_exists($className)) {
|
190 |
-
require_once 'Microsoft/Loader.php';
|
191 |
-
Microsoft_Loader::loadClass($className);
|
192 |
-
}
|
193 |
-
|
194 |
-
$reflection = new ReflectionClass($className);
|
195 |
-
if (!$reflection->implementsInterface('Microsoft_Log_FactoryInterface')) {
|
196 |
-
require_once 'Zend/Log/Exception.php';
|
197 |
-
throw new Microsoft_Log_Exception(
|
198 |
-
'Driver does not implement Microsoft_Log_FactoryInterface and can not be constructed from config.'
|
199 |
-
);
|
200 |
-
}
|
201 |
-
|
202 |
-
return call_user_func(array($className, 'factory'), $params);
|
203 |
-
}
|
204 |
-
|
205 |
-
/**
|
206 |
-
* Get the writer or filter full classname
|
207 |
-
*
|
208 |
-
* @param array $config
|
209 |
-
* @param string $type filter|writer
|
210 |
-
* @param string $defaultNamespace
|
211 |
-
* @return string full classname
|
212 |
-
*/
|
213 |
-
protected function getClassName($config, $type, $defaultNamespace)
|
214 |
-
{
|
215 |
-
if (!isset($config[ $type . 'Name' ])) {
|
216 |
-
require_once 'Zend/Log/Exception.php';
|
217 |
-
throw new Microsoft_Log_Exception("Specify {$type}Name in the configuration array");
|
218 |
-
}
|
219 |
-
$className = $config[ $type . 'Name' ];
|
220 |
-
|
221 |
-
$namespace = $defaultNamespace;
|
222 |
-
if (isset($config[ $type . 'Namespace' ])) {
|
223 |
-
$namespace = $config[ $type . 'Namespace' ];
|
224 |
-
}
|
225 |
-
|
226 |
-
$fullClassName = $namespace . '_' . $className;
|
227 |
-
return $fullClassName;
|
228 |
-
}
|
229 |
-
|
230 |
-
/**
|
231 |
-
* Class destructor. Shutdown log writers
|
232 |
-
*
|
233 |
-
* @return void
|
234 |
-
*/
|
235 |
-
public function __destruct()
|
236 |
-
{
|
237 |
-
foreach($this->_writers as $writer) {
|
238 |
-
$writer->shutdown();
|
239 |
-
}
|
240 |
-
}
|
241 |
-
|
242 |
-
/**
|
243 |
-
* Undefined method handler allows a shortcut:
|
244 |
-
* $log->priorityName('message')
|
245 |
-
* instead of
|
246 |
-
* $log->log('message', Microsoft_Log::PRIORITY_NAME)
|
247 |
-
*
|
248 |
-
* @param string $method priority name
|
249 |
-
* @param string $params message to log
|
250 |
-
* @return void
|
251 |
-
* @throws Microsoft_Log_Exception
|
252 |
-
*/
|
253 |
-
public function __call($method, $params)
|
254 |
-
{
|
255 |
-
$priority = strtoupper($method);
|
256 |
-
if (($priority = array_search($priority, $this->_priorities)) !== false) {
|
257 |
-
switch (count($params)) {
|
258 |
-
case 0:
|
259 |
-
/** @see Microsoft_Log_Exception */
|
260 |
-
require_once 'Microsoft_/Log/Exception.php';
|
261 |
-
throw new Microsoft_Log_Exception('Missing log message');
|
262 |
-
case 1:
|
263 |
-
$message = array_shift($params);
|
264 |
-
$extras = null;
|
265 |
-
break;
|
266 |
-
default:
|
267 |
-
$message = array_shift($params);
|
268 |
-
$extras = array_shift($params);
|
269 |
-
break;
|
270 |
-
}
|
271 |
-
$this->log($message, $priority, $extras);
|
272 |
-
} else {
|
273 |
-
/** @see Microsoft_Log_Exception */
|
274 |
-
require_once 'Microsoft/Log/Exception.php';
|
275 |
-
throw new Microsoft_Log_Exception('Bad log priority');
|
276 |
-
}
|
277 |
-
}
|
278 |
-
|
279 |
-
/**
|
280 |
-
* Log a message at a priority
|
281 |
-
*
|
282 |
-
* @param string $message Message to log
|
283 |
-
* @param integer $priority Priority of message
|
284 |
-
* @param mixed $extras Extra information to log in event
|
285 |
-
* @return void
|
286 |
-
* @throws Microsoft_Log_Exception
|
287 |
-
*/
|
288 |
-
public function log($message, $priority, $extras = null)
|
289 |
-
{
|
290 |
-
// sanity checks
|
291 |
-
if (empty($this->_writers)) {
|
292 |
-
/** @see Microsoft_Log_Exception */
|
293 |
-
require_once 'Microsoft/Log/Exception.php';
|
294 |
-
throw new Microsoft_Log_Exception('No writers were added');
|
295 |
-
}
|
296 |
-
|
297 |
-
if (! isset($this->_priorities[$priority])) {
|
298 |
-
/** @see Microsoft_Log_Exception */
|
299 |
-
require_once 'Microsoft/Log/Exception.php';
|
300 |
-
throw new Microsoft_Log_Exception('Bad log priority');
|
301 |
-
}
|
302 |
-
|
303 |
-
// pack into event required by filters and writers
|
304 |
-
$event = array_merge(array('timestamp' => date('c'),
|
305 |
-
'message' => $message,
|
306 |
-
'priority' => $priority,
|
307 |
-
'priorityName' => $this->_priorities[$priority]),
|
308 |
-
$this->_extras);
|
309 |
-
|
310 |
-
// Check to see if any extra information was passed
|
311 |
-
if (!empty($extras)) {
|
312 |
-
$info = array();
|
313 |
-
if (is_array($extras)) {
|
314 |
-
foreach ($extras as $key => $value) {
|
315 |
-
if (is_string($key)) {
|
316 |
-
$event[$key] = $value;
|
317 |
-
} else {
|
318 |
-
$info[] = $value;
|
319 |
-
}
|
320 |
-
}
|
321 |
-
} else {
|
322 |
-
$info = $extras;
|
323 |
-
}
|
324 |
-
if (!empty($info)) {
|
325 |
-
$event['info'] = $info;
|
326 |
-
}
|
327 |
-
}
|
328 |
-
|
329 |
-
// abort if rejected by the global filters
|
330 |
-
foreach ($this->_filters as $filter) {
|
331 |
-
if (! $filter->accept($event)) {
|
332 |
-
return;
|
333 |
-
}
|
334 |
-
}
|
335 |
-
|
336 |
-
// send to each writer
|
337 |
-
foreach ($this->_writers as $writer) {
|
338 |
-
$writer->write($event);
|
339 |
-
}
|
340 |
-
}
|
341 |
-
|
342 |
-
/**
|
343 |
-
* Add a custom priority
|
344 |
-
*
|
345 |
-
* @param string $name Name of priority
|
346 |
-
* @param integer $priority Numeric priority
|
347 |
-
*/
|
348 |
-
public function addPriority($name, $priority)
|
349 |
-
{
|
350 |
-
// Priority names must be uppercase for predictability.
|
351 |
-
$name = strtoupper($name);
|
352 |
-
|
353 |
-
if (isset($this->_priorities[$priority])
|
354 |
-
|| false !== array_search($name, $this->_priorities)) {
|
355 |
-
/** @see Microsoft_Log_Exception */
|
356 |
-
require_once 'Microsoft/Log/Exception.php';
|
357 |
-
throw new Microsoft_Log_Exception('Existing priorities cannot be overwritten');
|
358 |
-
}
|
359 |
-
|
360 |
-
$this->_priorities[$priority] = $name;
|
361 |
-
}
|
362 |
-
|
363 |
-
/**
|
364 |
-
* Add a filter that will be applied before all log writers.
|
365 |
-
* Before a message will be received by any of the writers, it
|
366 |
-
* must be accepted by all filters added with this method.
|
367 |
-
*
|
368 |
-
* @param int|Microsoft_Log_Filter_Interface $filter
|
369 |
-
* @return void
|
370 |
-
*/
|
371 |
-
public function addFilter($filter)
|
372 |
-
{
|
373 |
-
if (is_integer($filter)) {
|
374 |
-
/** @see Microsoft_Log_Filter_Priority */
|
375 |
-
require_once 'Microsoft/Log/Filter/Priority.php';
|
376 |
-
$filter = new Microsoft_Log_Filter_Priority($filter);
|
377 |
-
|
378 |
-
} elseif ($filter instanceof Microsoft_Config || is_array($filter)) {
|
379 |
-
$filter = $this->_constructFilterFromConfig($filter);
|
380 |
-
|
381 |
-
} elseif(! $filter instanceof Microsoft_Log_Filter_Interface) {
|
382 |
-
/** @see Microsoft_Log_Exception */
|
383 |
-
require_once 'Microsoft/Log/Exception.php';
|
384 |
-
throw new Microsoft_Log_Exception('Invalid filter provided');
|
385 |
-
}
|
386 |
-
|
387 |
-
$this->_filters[] = $filter;
|
388 |
-
}
|
389 |
-
|
390 |
-
/**
|
391 |
-
* Add a writer. A writer is responsible for taking a log
|
392 |
-
* message and writing it out to storage.
|
393 |
-
*
|
394 |
-
* @param mixed $writer Microsoft_Log_Writer_Abstract or Config array
|
395 |
-
* @return void
|
396 |
-
*/
|
397 |
-
public function addWriter($writer)
|
398 |
-
{
|
399 |
-
if (is_array($writer)) {
|
400 |
-
$writer = $this->_constructWriterFromConfig($writer);
|
401 |
-
}
|
402 |
-
|
403 |
-
if (!$writer instanceof Microsoft_Log_Writer_Abstract) {
|
404 |
-
/** @see Microsoft_Log_Exception */
|
405 |
-
require_once 'Microsoft/Log/Exception.php';
|
406 |
-
throw new Microsoft_Log_Exception(
|
407 |
-
'Writer must be an instance of Microsoft_Log_Writer_Abstract'
|
408 |
-
. ' or you should pass a configuration array'
|
409 |
-
);
|
410 |
-
}
|
411 |
-
|
412 |
-
$this->_writers[] = $writer;
|
413 |
-
}
|
414 |
-
|
415 |
-
/**
|
416 |
-
* Set an extra item to pass to the log writers.
|
417 |
-
*
|
418 |
-
* @param $name Name of the field
|
419 |
-
* @param $value Value of the field
|
420 |
-
* @return void
|
421 |
-
*/
|
422 |
-
public function setEventItem($name, $value)
|
423 |
-
{
|
424 |
-
$this->_extras = array_merge($this->_extras, array($name => $value));
|
425 |
-
}
|
426 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Zend Framework
|
4 |
+
*
|
5 |
+
* LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the new BSD license that is bundled
|
8 |
+
* with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://framework.zend.com/license/new-bsd
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@zend.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* @category Microsoft
|
16 |
+
* @package Microsoft_Log
|
17 |
+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
18 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
19 |
+
* @version $Id: Log.php 22632 2010-07-18 18:30:08Z ramon $
|
20 |
+
*/
|
21 |
+
|
22 |
+
/**
|
23 |
+
* @see Microsoft_AutoLoader
|
24 |
+
*/
|
25 |
+
require_once dirname(__FILE__) . '/AutoLoader.php';
|
26 |
+
|
27 |
+
/**
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_Log
|
30 |
+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
31 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
32 |
+
* @version $Id: Log.php 22632 2010-07-18 18:30:08Z ramon $
|
33 |
+
*/
|
34 |
+
class Microsoft_Log
|
35 |
+
{
|
36 |
+
const EMERG = 0; // Emergency: system is unusable
|
37 |
+
const ALERT = 1; // Alert: action must be taken immediately
|
38 |
+
const CRIT = 2; // Critical: critical conditions
|
39 |
+
const ERR = 3; // Error: error conditions
|
40 |
+
const WARN = 4; // Warning: warning conditions
|
41 |
+
const NOTICE = 5; // Notice: normal but significant condition
|
42 |
+
const INFO = 6; // Informational: informational messages
|
43 |
+
const DEBUG = 7; // Debug: debug messages
|
44 |
+
|
45 |
+
/**
|
46 |
+
* @var array of priorities where the keys are the
|
47 |
+
* priority numbers and the values are the priority names
|
48 |
+
*/
|
49 |
+
protected $_priorities = array();
|
50 |
+
|
51 |
+
/**
|
52 |
+
* @var array of Microsoft_Log_Writer_Abstract
|
53 |
+
*/
|
54 |
+
protected $_writers = array();
|
55 |
+
|
56 |
+
/**
|
57 |
+
* @var array of Microsoft_Log_Filter_Interface
|
58 |
+
*/
|
59 |
+
protected $_filters = array();
|
60 |
+
|
61 |
+
/**
|
62 |
+
* @var array of extra log event
|
63 |
+
*/
|
64 |
+
protected $_extras = array();
|
65 |
+
|
66 |
+
/**
|
67 |
+
*
|
68 |
+
* @var string
|
69 |
+
*/
|
70 |
+
protected $_defaultWriterNamespace = 'Microsoft_Log_Writer';
|
71 |
+
|
72 |
+
/**
|
73 |
+
*
|
74 |
+
* @var string
|
75 |
+
*/
|
76 |
+
protected $_defaultFilterNamespace = 'Microsoft_Log_Filter';
|
77 |
+
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Class constructor. Create a new logger
|
81 |
+
*
|
82 |
+
* @param Microsoft_Log_Writer_Abstract|null $writer default writer
|
83 |
+
*/
|
84 |
+
public function __construct(Microsoft_Log_Writer_Abstract $writer = null)
|
85 |
+
{
|
86 |
+
$r = new ReflectionClass($this);
|
87 |
+
$this->_priorities = array_flip($r->getConstants());
|
88 |
+
|
89 |
+
if ($writer !== null) {
|
90 |
+
$this->addWriter($writer);
|
91 |
+
}
|
92 |
+
}
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Factory to construct the logger and one or more writers
|
96 |
+
* based on the configuration array
|
97 |
+
*
|
98 |
+
* @param array $config
|
99 |
+
* @return Microsoft_Log
|
100 |
+
*/
|
101 |
+
static public function factory($config = array())
|
102 |
+
{
|
103 |
+
if (!is_array($config) || empty($config)) {
|
104 |
+
/** @see Microsoft_Log_Exception */
|
105 |
+
require_once 'Microsoft/Log/Exception.php';
|
106 |
+
throw new Microsoft_Log_Exception('Configuration must be an array');
|
107 |
+
}
|
108 |
+
|
109 |
+
$log = new Microsoft_Log;
|
110 |
+
|
111 |
+
if (!is_array(current($config))) {
|
112 |
+
$log->addWriter(current($config));
|
113 |
+
} else {
|
114 |
+
foreach($config as $writer) {
|
115 |
+
$log->addWriter($writer);
|
116 |
+
}
|
117 |
+
}
|
118 |
+
|
119 |
+
return $log;
|
120 |
+
}
|
121 |
+
|
122 |
+
|
123 |
+
/**
|
124 |
+
* Construct a writer object based on a configuration array
|
125 |
+
*
|
126 |
+
* @param array $spec config array with writer spec
|
127 |
+
* @return Microsoft_Log_Writer_Abstract
|
128 |
+
*/
|
129 |
+
protected function _constructWriterFromConfig($config)
|
130 |
+
{
|
131 |
+
$writer = $this->_constructFromConfig('writer', $config, $this->_defaultWriterNamespace);
|
132 |
+
|
133 |
+
if (!$writer instanceof Microsoft_Log_Writer_Abstract) {
|
134 |
+
$writerName = is_object($writer)
|
135 |
+
? get_class($writer)
|
136 |
+
: 'The specified writer';
|
137 |
+
/** @see Microsoft_Log_Exception */
|
138 |
+
require_once 'Microsoft/Log/Exception.php';
|
139 |
+
throw new Microsoft_Log_Exception("{$writerName} does not extend Microsoft_Log_Writer_Abstract!");
|
140 |
+
}
|
141 |
+
|
142 |
+
if (isset($config['filterName'])) {
|
143 |
+
$filter = $this->_constructFilterFromConfig($config);
|
144 |
+
$writer->addFilter($filter);
|
145 |
+
}
|
146 |
+
|
147 |
+
return $writer;
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* Construct filter object from configuration array or Microsoft_Config object
|
152 |
+
*
|
153 |
+
* @param array $config
|
154 |
+
* @return Microsoft_Log_Filter_Interface
|
155 |
+
*/
|
156 |
+
protected function _constructFilterFromConfig($config)
|
157 |
+
{
|
158 |
+
$filter = $this->_constructFromConfig('filter', $config, $this->_defaultFilterNamespace);
|
159 |
+
|
160 |
+
if (!$filter instanceof Microsoft_Log_Filter_Interface) {
|
161 |
+
$filterName = is_object($filter)
|
162 |
+
? get_class($filter)
|
163 |
+
: 'The specified filter';
|
164 |
+
/** @see Microsoft_Log_Exception */
|
165 |
+
require_once 'Microsoft/Log/Exception.php';
|
166 |
+
throw new Microsoft_Log_Exception("{$filterName} does not implement Microsoft_Log_Filter_Interface");
|
167 |
+
}
|
168 |
+
|
169 |
+
return $filter;
|
170 |
+
}
|
171 |
+
|
172 |
+
/**
|
173 |
+
* Construct a filter or writer from config
|
174 |
+
*
|
175 |
+
* @param string $type 'writer' of 'filter'
|
176 |
+
* @param array $config
|
177 |
+
* @param string $namespace
|
178 |
+
* @return object
|
179 |
+
*/
|
180 |
+
protected function _constructFromConfig($type, $config, $namespace)
|
181 |
+
{
|
182 |
+
if (!is_array($config) || empty($config)) {
|
183 |
+
require_once 'Microsoft/Log/Exception.php';
|
184 |
+
throw new Microsoft_Log_Exception('Configuration must be an array');
|
185 |
+
}
|
186 |
+
|
187 |
+
$params = isset($config[ $type .'Params' ]) ? $config[ $type .'Params' ] : array();
|
188 |
+
$className = $this->getClassName($config, $type, $namespace);
|
189 |
+
if (!class_exists($className)) {
|
190 |
+
require_once 'Microsoft/Loader.php';
|
191 |
+
Microsoft_Loader::loadClass($className);
|
192 |
+
}
|
193 |
+
|
194 |
+
$reflection = new ReflectionClass($className);
|
195 |
+
if (!$reflection->implementsInterface('Microsoft_Log_FactoryInterface')) {
|
196 |
+
require_once 'Zend/Log/Exception.php';
|
197 |
+
throw new Microsoft_Log_Exception(
|
198 |
+
'Driver does not implement Microsoft_Log_FactoryInterface and can not be constructed from config.'
|
199 |
+
);
|
200 |
+
}
|
201 |
+
|
202 |
+
return call_user_func(array($className, 'factory'), $params);
|
203 |
+
}
|
204 |
+
|
205 |
+
/**
|
206 |
+
* Get the writer or filter full classname
|
207 |
+
*
|
208 |
+
* @param array $config
|
209 |
+
* @param string $type filter|writer
|
210 |
+
* @param string $defaultNamespace
|
211 |
+
* @return string full classname
|
212 |
+
*/
|
213 |
+
protected function getClassName($config, $type, $defaultNamespace)
|
214 |
+
{
|
215 |
+
if (!isset($config[ $type . 'Name' ])) {
|
216 |
+
require_once 'Zend/Log/Exception.php';
|
217 |
+
throw new Microsoft_Log_Exception("Specify {$type}Name in the configuration array");
|
218 |
+
}
|
219 |
+
$className = $config[ $type . 'Name' ];
|
220 |
+
|
221 |
+
$namespace = $defaultNamespace;
|
222 |
+
if (isset($config[ $type . 'Namespace' ])) {
|
223 |
+
$namespace = $config[ $type . 'Namespace' ];
|
224 |
+
}
|
225 |
+
|
226 |
+
$fullClassName = $namespace . '_' . $className;
|
227 |
+
return $fullClassName;
|
228 |
+
}
|
229 |
+
|
230 |
+
/**
|
231 |
+
* Class destructor. Shutdown log writers
|
232 |
+
*
|
233 |
+
* @return void
|
234 |
+
*/
|
235 |
+
public function __destruct()
|
236 |
+
{
|
237 |
+
foreach($this->_writers as $writer) {
|
238 |
+
$writer->shutdown();
|
239 |
+
}
|
240 |
+
}
|
241 |
+
|
242 |
+
/**
|
243 |
+
* Undefined method handler allows a shortcut:
|
244 |
+
* $log->priorityName('message')
|
245 |
+
* instead of
|
246 |
+
* $log->log('message', Microsoft_Log::PRIORITY_NAME)
|
247 |
+
*
|
248 |
+
* @param string $method priority name
|
249 |
+
* @param string $params message to log
|
250 |
+
* @return void
|
251 |
+
* @throws Microsoft_Log_Exception
|
252 |
+
*/
|
253 |
+
public function __call($method, $params)
|
254 |
+
{
|
255 |
+
$priority = strtoupper($method);
|
256 |
+
if (($priority = array_search($priority, $this->_priorities)) !== false) {
|
257 |
+
switch (count($params)) {
|
258 |
+
case 0:
|
259 |
+
/** @see Microsoft_Log_Exception */
|
260 |
+
require_once 'Microsoft_/Log/Exception.php';
|
261 |
+
throw new Microsoft_Log_Exception('Missing log message');
|
262 |
+
case 1:
|
263 |
+
$message = array_shift($params);
|
264 |
+
$extras = null;
|
265 |
+
break;
|
266 |
+
default:
|
267 |
+
$message = array_shift($params);
|
268 |
+
$extras = array_shift($params);
|
269 |
+
break;
|
270 |
+
}
|
271 |
+
$this->log($message, $priority, $extras);
|
272 |
+
} else {
|
273 |
+
/** @see Microsoft_Log_Exception */
|
274 |
+
require_once 'Microsoft/Log/Exception.php';
|
275 |
+
throw new Microsoft_Log_Exception('Bad log priority');
|
276 |
+
}
|
277 |
+
}
|
278 |
+
|
279 |
+
/**
|
280 |
+
* Log a message at a priority
|
281 |
+
*
|
282 |
+
* @param string $message Message to log
|
283 |
+
* @param integer $priority Priority of message
|
284 |
+
* @param mixed $extras Extra information to log in event
|
285 |
+
* @return void
|
286 |
+
* @throws Microsoft_Log_Exception
|
287 |
+
*/
|
288 |
+
public function log($message, $priority, $extras = null)
|
289 |
+
{
|
290 |
+
// sanity checks
|
291 |
+
if (empty($this->_writers)) {
|
292 |
+
/** @see Microsoft_Log_Exception */
|
293 |
+
require_once 'Microsoft/Log/Exception.php';
|
294 |
+
throw new Microsoft_Log_Exception('No writers were added');
|
295 |
+
}
|
296 |
+
|
297 |
+
if (! isset($this->_priorities[$priority])) {
|
298 |
+
/** @see Microsoft_Log_Exception */
|
299 |
+
require_once 'Microsoft/Log/Exception.php';
|
300 |
+
throw new Microsoft_Log_Exception('Bad log priority');
|
301 |
+
}
|
302 |
+
|
303 |
+
// pack into event required by filters and writers
|
304 |
+
$event = array_merge(array('timestamp' => date('c'),
|
305 |
+
'message' => $message,
|
306 |
+
'priority' => $priority,
|
307 |
+
'priorityName' => $this->_priorities[$priority]),
|
308 |
+
$this->_extras);
|
309 |
+
|
310 |
+
// Check to see if any extra information was passed
|
311 |
+
if (!empty($extras)) {
|
312 |
+
$info = array();
|
313 |
+
if (is_array($extras)) {
|
314 |
+
foreach ($extras as $key => $value) {
|
315 |
+
if (is_string($key)) {
|
316 |
+
$event[$key] = $value;
|
317 |
+
} else {
|
318 |
+
$info[] = $value;
|
319 |
+
}
|
320 |
+
}
|
321 |
+
} else {
|
322 |
+
$info = $extras;
|
323 |
+
}
|
324 |
+
if (!empty($info)) {
|
325 |
+
$event['info'] = $info;
|
326 |
+
}
|
327 |
+
}
|
328 |
+
|
329 |
+
// abort if rejected by the global filters
|
330 |
+
foreach ($this->_filters as $filter) {
|
331 |
+
if (! $filter->accept($event)) {
|
332 |
+
return;
|
333 |
+
}
|
334 |
+
}
|
335 |
+
|
336 |
+
// send to each writer
|
337 |
+
foreach ($this->_writers as $writer) {
|
338 |
+
$writer->write($event);
|
339 |
+
}
|
340 |
+
}
|
341 |
+
|
342 |
+
/**
|
343 |
+
* Add a custom priority
|
344 |
+
*
|
345 |
+
* @param string $name Name of priority
|
346 |
+
* @param integer $priority Numeric priority
|
347 |
+
*/
|
348 |
+
public function addPriority($name, $priority)
|
349 |
+
{
|
350 |
+
// Priority names must be uppercase for predictability.
|
351 |
+
$name = strtoupper($name);
|
352 |
+
|
353 |
+
if (isset($this->_priorities[$priority])
|
354 |
+
|| false !== array_search($name, $this->_priorities)) {
|
355 |
+
/** @see Microsoft_Log_Exception */
|
356 |
+
require_once 'Microsoft/Log/Exception.php';
|
357 |
+
throw new Microsoft_Log_Exception('Existing priorities cannot be overwritten');
|
358 |
+
}
|
359 |
+
|
360 |
+
$this->_priorities[$priority] = $name;
|
361 |
+
}
|
362 |
+
|
363 |
+
/**
|
364 |
+
* Add a filter that will be applied before all log writers.
|
365 |
+
* Before a message will be received by any of the writers, it
|
366 |
+
* must be accepted by all filters added with this method.
|
367 |
+
*
|
368 |
+
* @param int|Microsoft_Log_Filter_Interface $filter
|
369 |
+
* @return void
|
370 |
+
*/
|
371 |
+
public function addFilter($filter)
|
372 |
+
{
|
373 |
+
if (is_integer($filter)) {
|
374 |
+
/** @see Microsoft_Log_Filter_Priority */
|
375 |
+
require_once 'Microsoft/Log/Filter/Priority.php';
|
376 |
+
$filter = new Microsoft_Log_Filter_Priority($filter);
|
377 |
+
|
378 |
+
} elseif ($filter instanceof Microsoft_Config || is_array($filter)) {
|
379 |
+
$filter = $this->_constructFilterFromConfig($filter);
|
380 |
+
|
381 |
+
} elseif(! $filter instanceof Microsoft_Log_Filter_Interface) {
|
382 |
+
/** @see Microsoft_Log_Exception */
|
383 |
+
require_once 'Microsoft/Log/Exception.php';
|
384 |
+
throw new Microsoft_Log_Exception('Invalid filter provided');
|
385 |
+
}
|
386 |
+
|
387 |
+
$this->_filters[] = $filter;
|
388 |
+
}
|
389 |
+
|
390 |
+
/**
|
391 |
+
* Add a writer. A writer is responsible for taking a log
|
392 |
+
* message and writing it out to storage.
|
393 |
+
*
|
394 |
+
* @param mixed $writer Microsoft_Log_Writer_Abstract or Config array
|
395 |
+
* @return void
|
396 |
+
*/
|
397 |
+
public function addWriter($writer)
|
398 |
+
{
|
399 |
+
if (is_array($writer)) {
|
400 |
+
$writer = $this->_constructWriterFromConfig($writer);
|
401 |
+
}
|
402 |
+
|
403 |
+
if (!$writer instanceof Microsoft_Log_Writer_Abstract) {
|
404 |
+
/** @see Microsoft_Log_Exception */
|
405 |
+
require_once 'Microsoft/Log/Exception.php';
|
406 |
+
throw new Microsoft_Log_Exception(
|
407 |
+
'Writer must be an instance of Microsoft_Log_Writer_Abstract'
|
408 |
+
. ' or you should pass a configuration array'
|
409 |
+
);
|
410 |
+
}
|
411 |
+
|
412 |
+
$this->_writers[] = $writer;
|
413 |
+
}
|
414 |
+
|
415 |
+
/**
|
416 |
+
* Set an extra item to pass to the log writers.
|
417 |
+
*
|
418 |
+
* @param $name Name of the field
|
419 |
+
* @param $value Value of the field
|
420 |
+
* @return void
|
421 |
+
*/
|
422 |
+
public function setEventItem($name, $value)
|
423 |
+
{
|
424 |
+
$this->_extras = array_merge($this->_extras, array($name => $value));
|
425 |
+
}
|
426 |
+
}
|
libs/Microsoft/Log/Exception.php
CHANGED
@@ -1,48 +1,48 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Copyright (c) 2009 -
|
4 |
-
* All rights reserved.
|
5 |
-
*
|
6 |
-
* Redistribution and use in source and binary forms, with or without
|
7 |
-
* modification, are permitted provided that the following conditions are met:
|
8 |
-
* * Redistributions of source code must retain the above copyright
|
9 |
-
* notice, this list of conditions and the following disclaimer.
|
10 |
-
* * Redistributions in binary form must reproduce the above copyright
|
11 |
-
* notice, this list of conditions and the following disclaimer in the
|
12 |
-
* documentation and/or other materials provided with the distribution.
|
13 |
-
* * Neither the name of RealDolmen nor the
|
14 |
-
* names of its contributors may be used to endorse or promote products
|
15 |
-
* derived from this software without specific prior written permission.
|
16 |
-
*
|
17 |
-
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
-
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
-
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
-
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
-
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
-
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
-
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
-
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
-
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
-
*
|
28 |
-
* @category Microsoft
|
29 |
-
* @package Microsoft_Log
|
30 |
-
* @subpackage Exception
|
31 |
-
* @version $Id: Exception.php 45259 2010-04-16 12:13:55Z unknown $
|
32 |
-
* @copyright Copyright (c) 2009 -
|
33 |
-
* @license http://phpazure.codeplex.com/license
|
34 |
-
*/
|
35 |
-
|
36 |
-
/**
|
37 |
-
* @see Microsoft_AutoLoader
|
38 |
-
*/
|
39 |
-
require_once dirname(__FILE__) . '/../AutoLoader.php';
|
40 |
-
|
41 |
-
/**
|
42 |
-
* @category Microsoft
|
43 |
-
* @package Microsoft_Log
|
44 |
-
* @copyright Copyright (c) 2009 -
|
45 |
-
* @license http://phpazure.codeplex.com/license
|
46 |
-
*/
|
47 |
-
class Microsoft_Log_Exception extends Zend_Exception
|
48 |
-
{}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_Log
|
30 |
+
* @subpackage Exception
|
31 |
+
* @version $Id: Exception.php 45259 2010-04-16 12:13:55Z unknown $
|
32 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
33 |
+
* @license http://phpazure.codeplex.com/license
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @see Microsoft_AutoLoader
|
38 |
+
*/
|
39 |
+
require_once dirname(__FILE__) . '/../AutoLoader.php';
|
40 |
+
|
41 |
+
/**
|
42 |
+
* @category Microsoft
|
43 |
+
* @package Microsoft_Log
|
44 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
45 |
+
* @license http://phpazure.codeplex.com/license
|
46 |
+
*/
|
47 |
+
class Microsoft_Log_Exception extends Zend_Exception
|
48 |
+
{}
|
libs/Microsoft/Log/FactoryInterface.php
CHANGED
@@ -1,38 +1,38 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Zend Framework
|
4 |
-
*
|
5 |
-
* LICENSE
|
6 |
-
*
|
7 |
-
* This source file is subject to the new BSD license that is bundled
|
8 |
-
* with this package in the file LICENSE.txt.
|
9 |
-
* It is also available through the world-wide-web at this URL:
|
10 |
-
* http://framework.zend.com/license/new-bsd
|
11 |
-
* If you did not receive a copy of the license and are unable to
|
12 |
-
* obtain it through the world-wide-web, please send an email
|
13 |
-
* to license@zend.com so we can send you a copy immediately.
|
14 |
-
*
|
15 |
-
* @category Microsoft
|
16 |
-
* @package Microsoft_Log
|
17 |
-
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
18 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
19 |
-
* @version $Id$
|
20 |
-
*/
|
21 |
-
|
22 |
-
/**
|
23 |
-
* @category Microsoft
|
24 |
-
* @package Microsoft_Log
|
25 |
-
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
26 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
27 |
-
* @version $Id$
|
28 |
-
*/
|
29 |
-
interface Microsoft_Log_FactoryInterface
|
30 |
-
{
|
31 |
-
/**
|
32 |
-
* Construct a Microsoft_Log driver
|
33 |
-
*
|
34 |
-
* @param array $config
|
35 |
-
* @return Microsoft_Log_FactoryInterface
|
36 |
-
*/
|
37 |
-
static public function factory($config);
|
38 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Zend Framework
|
4 |
+
*
|
5 |
+
* LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the new BSD license that is bundled
|
8 |
+
* with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://framework.zend.com/license/new-bsd
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@zend.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* @category Microsoft
|
16 |
+
* @package Microsoft_Log
|
17 |
+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
18 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
19 |
+
* @version $Id$
|
20 |
+
*/
|
21 |
+
|
22 |
+
/**
|
23 |
+
* @category Microsoft
|
24 |
+
* @package Microsoft_Log
|
25 |
+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
26 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
27 |
+
* @version $Id$
|
28 |
+
*/
|
29 |
+
interface Microsoft_Log_FactoryInterface
|
30 |
+
{
|
31 |
+
/**
|
32 |
+
* Construct a Microsoft_Log driver
|
33 |
+
*
|
34 |
+
* @param array $config
|
35 |
+
* @return Microsoft_Log_FactoryInterface
|
36 |
+
*/
|
37 |
+
static public function factory($config);
|
38 |
+
}
|
libs/Microsoft/Log/Filter/Abstract.php
CHANGED
@@ -1,55 +1,55 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Zend Framework
|
4 |
-
*
|
5 |
-
* LICENSE
|
6 |
-
*
|
7 |
-
* This source file is subject to the new BSD license that is bundled
|
8 |
-
* with this package in the file LICENSE.txt.
|
9 |
-
* It is also available through the world-wide-web at this URL:
|
10 |
-
* http://framework.zend.com/license/new-bsd
|
11 |
-
* If you did not receive a copy of the license and are unable to
|
12 |
-
* obtain it through the world-wide-web, please send an email
|
13 |
-
* to license@zend.com so we can send you a copy immediately.
|
14 |
-
*
|
15 |
-
* @category Microsoft
|
16 |
-
* @package Microsoft_Log
|
17 |
-
* @subpackage Writer
|
18 |
-
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
19 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
20 |
-
* @version $Id$
|
21 |
-
*/
|
22 |
-
|
23 |
-
/**
|
24 |
-
* @see Microsoft_AutoLoader
|
25 |
-
*/
|
26 |
-
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
27 |
-
|
28 |
-
/**
|
29 |
-
* @category Microsoft
|
30 |
-
* @package Microsoft_Log
|
31 |
-
* @subpackage Writer
|
32 |
-
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
33 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
34 |
-
* @version $Id$
|
35 |
-
*/
|
36 |
-
abstract class Microsoft_Log_Filter_Abstract
|
37 |
-
implements Microsoft_Log_Filter_Interface, Microsoft_Log_FactoryInterface
|
38 |
-
{
|
39 |
-
/**
|
40 |
-
* Validate and optionally convert the config to array
|
41 |
-
*
|
42 |
-
* @param array $config
|
43 |
-
* @return array
|
44 |
-
* @throws Microsoft_Log_Exception
|
45 |
-
*/
|
46 |
-
static protected function _parseConfig($config)
|
47 |
-
{
|
48 |
-
if (!is_array($config)) {
|
49 |
-
require_once 'Microsoft/Log/Exception.php';
|
50 |
-
throw new Microsoft_Log_Exception('Configuration must be an array');
|
51 |
-
}
|
52 |
-
|
53 |
-
return $config;
|
54 |
-
}
|
55 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Zend Framework
|
4 |
+
*
|
5 |
+
* LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the new BSD license that is bundled
|
8 |
+
* with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://framework.zend.com/license/new-bsd
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@zend.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* @category Microsoft
|
16 |
+
* @package Microsoft_Log
|
17 |
+
* @subpackage Writer
|
18 |
+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
19 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
20 |
+
* @version $Id$
|
21 |
+
*/
|
22 |
+
|
23 |
+
/**
|
24 |
+
* @see Microsoft_AutoLoader
|
25 |
+
*/
|
26 |
+
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
27 |
+
|
28 |
+
/**
|
29 |
+
* @category Microsoft
|
30 |
+
* @package Microsoft_Log
|
31 |
+
* @subpackage Writer
|
32 |
+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
33 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
34 |
+
* @version $Id$
|
35 |
+
*/
|
36 |
+
abstract class Microsoft_Log_Filter_Abstract
|
37 |
+
implements Microsoft_Log_Filter_Interface, Microsoft_Log_FactoryInterface
|
38 |
+
{
|
39 |
+
/**
|
40 |
+
* Validate and optionally convert the config to array
|
41 |
+
*
|
42 |
+
* @param array $config
|
43 |
+
* @return array
|
44 |
+
* @throws Microsoft_Log_Exception
|
45 |
+
*/
|
46 |
+
static protected function _parseConfig($config)
|
47 |
+
{
|
48 |
+
if (!is_array($config)) {
|
49 |
+
require_once 'Microsoft/Log/Exception.php';
|
50 |
+
throw new Microsoft_Log_Exception('Configuration must be an array');
|
51 |
+
}
|
52 |
+
|
53 |
+
return $config;
|
54 |
+
}
|
55 |
+
}
|
libs/Microsoft/Log/Filter/Interface.php
CHANGED
@@ -1,40 +1,40 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Zend Framework
|
4 |
-
*
|
5 |
-
* LICENSE
|
6 |
-
*
|
7 |
-
* This source file is subject to the new BSD license that is bundled
|
8 |
-
* with this package in the file LICENSE.txt.
|
9 |
-
* It is also available through the world-wide-web at this URL:
|
10 |
-
* http://framework.zend.com/license/new-bsd
|
11 |
-
* If you did not receive a copy of the license and are unable to
|
12 |
-
* obtain it through the world-wide-web, please send an email
|
13 |
-
* to license@zend.com so we can send you a copy immediately.
|
14 |
-
*
|
15 |
-
* @category Micorosft
|
16 |
-
* @package Microsoft_Log
|
17 |
-
* @subpackage Filter
|
18 |
-
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
19 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
20 |
-
* @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
|
21 |
-
*/
|
22 |
-
|
23 |
-
/**
|
24 |
-
* @category Microsoft
|
25 |
-
* @package Microsoft_Log
|
26 |
-
* @subpackage Filter
|
27 |
-
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
28 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
29 |
-
* @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
|
30 |
-
*/
|
31 |
-
interface Microsoft_Log_Filter_Interface
|
32 |
-
{
|
33 |
-
/**
|
34 |
-
* Returns TRUE to accept the message, FALSE to block it.
|
35 |
-
*
|
36 |
-
* @param array $event event data
|
37 |
-
* @return boolean accepted?
|
38 |
-
*/
|
39 |
-
public function accept($event);
|
40 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Zend Framework
|
4 |
+
*
|
5 |
+
* LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the new BSD license that is bundled
|
8 |
+
* with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://framework.zend.com/license/new-bsd
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@zend.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* @category Micorosft
|
16 |
+
* @package Microsoft_Log
|
17 |
+
* @subpackage Filter
|
18 |
+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
19 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
20 |
+
* @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
|
21 |
+
*/
|
22 |
+
|
23 |
+
/**
|
24 |
+
* @category Microsoft
|
25 |
+
* @package Microsoft_Log
|
26 |
+
* @subpackage Filter
|
27 |
+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
28 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
29 |
+
* @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
|
30 |
+
*/
|
31 |
+
interface Microsoft_Log_Filter_Interface
|
32 |
+
{
|
33 |
+
/**
|
34 |
+
* Returns TRUE to accept the message, FALSE to block it.
|
35 |
+
*
|
36 |
+
* @param array $event event data
|
37 |
+
* @return boolean accepted?
|
38 |
+
*/
|
39 |
+
public function accept($event);
|
40 |
+
}
|
libs/Microsoft/Log/Filter/Message.php
CHANGED
@@ -1,87 +1,87 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Zend Framework
|
4 |
-
*
|
5 |
-
* LICENSE
|
6 |
-
*
|
7 |
-
* This source file is subject to the new BSD license that is bundled
|
8 |
-
* with this package in the file LICENSE.txt.
|
9 |
-
* It is also available through the world-wide-web at this URL:
|
10 |
-
* http://framework.zend.com/license/new-bsd
|
11 |
-
* If you did not receive a copy of the license and are unable to
|
12 |
-
* obtain it through the world-wide-web, please send an email
|
13 |
-
* to license@zend.com so we can send you a copy immediately.
|
14 |
-
*
|
15 |
-
* @category Microsoft
|
16 |
-
* @package Microsoft_Log
|
17 |
-
* @subpackage Filter
|
18 |
-
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
19 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
20 |
-
* @version $Id: Message.php 20982 2010-02-08 15:51:36Z matthew $
|
21 |
-
*/
|
22 |
-
|
23 |
-
/**
|
24 |
-
* @see Microsoft_AutoLoader
|
25 |
-
*/
|
26 |
-
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
27 |
-
|
28 |
-
/**
|
29 |
-
* @category Microsoft
|
30 |
-
* @package Microsoft_Log
|
31 |
-
* @subpackage Filter
|
32 |
-
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
33 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
34 |
-
* @version $Id: Message.php 20982 2010-02-08 15:51:36Z matthew $
|
35 |
-
*/
|
36 |
-
class Microsoft_Log_Filter_Message extends Microsoft_Log_Filter_Abstract
|
37 |
-
{
|
38 |
-
/**
|
39 |
-
* @var string
|
40 |
-
*/
|
41 |
-
protected $_regexp;
|
42 |
-
|
43 |
-
/**
|
44 |
-
* Filter out any log messages not matching $regexp.
|
45 |
-
*
|
46 |
-
* @param string $regexp Regular expression to test the log message
|
47 |
-
* @throws Microsoft_Log_Exception
|
48 |
-
*/
|
49 |
-
public function __construct($regexp)
|
50 |
-
{
|
51 |
-
if (@preg_match($regexp, '') === false) {
|
52 |
-
require_once 'Microsoft/Log/Exception.php';
|
53 |
-
throw new Microsoft_Log_Exception("Invalid regular expression '$regexp'");
|
54 |
-
}
|
55 |
-
$this->_regexp = $regexp;
|
56 |
-
}
|
57 |
-
|
58 |
-
/**
|
59 |
-
* Create a new instance of Microsoft_Log_Filter_Message
|
60 |
-
*
|
61 |
-
* @param array $config
|
62 |
-
* @return Microsoft_Log_Filter_Message
|
63 |
-
* @throws Microsoft_Log_Exception
|
64 |
-
*/
|
65 |
-
static public function factory($config)
|
66 |
-
{
|
67 |
-
$config = self::_parseConfig($config);
|
68 |
-
$config = array_merge(array(
|
69 |
-
'regexp' => null
|
70 |
-
), $config);
|
71 |
-
|
72 |
-
return new self(
|
73 |
-
$config['regexp']
|
74 |
-
);
|
75 |
-
}
|
76 |
-
|
77 |
-
/**
|
78 |
-
* Returns TRUE to accept the message, FALSE to block it.
|
79 |
-
*
|
80 |
-
* @param array $event event data
|
81 |
-
* @return boolean accepted?
|
82 |
-
*/
|
83 |
-
public function accept($event)
|
84 |
-
{
|
85 |
-
return preg_match($this->_regexp, $event['message']) > 0;
|
86 |
-
}
|
87 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Zend Framework
|
4 |
+
*
|
5 |
+
* LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the new BSD license that is bundled
|
8 |
+
* with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://framework.zend.com/license/new-bsd
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@zend.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* @category Microsoft
|
16 |
+
* @package Microsoft_Log
|
17 |
+
* @subpackage Filter
|
18 |
+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
19 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
20 |
+
* @version $Id: Message.php 20982 2010-02-08 15:51:36Z matthew $
|
21 |
+
*/
|
22 |
+
|
23 |
+
/**
|
24 |
+
* @see Microsoft_AutoLoader
|
25 |
+
*/
|
26 |
+
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
27 |
+
|
28 |
+
/**
|
29 |
+
* @category Microsoft
|
30 |
+
* @package Microsoft_Log
|
31 |
+
* @subpackage Filter
|
32 |
+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
33 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
34 |
+
* @version $Id: Message.php 20982 2010-02-08 15:51:36Z matthew $
|
35 |
+
*/
|
36 |
+
class Microsoft_Log_Filter_Message extends Microsoft_Log_Filter_Abstract
|
37 |
+
{
|
38 |
+
/**
|
39 |
+
* @var string
|
40 |
+
*/
|
41 |
+
protected $_regexp;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Filter out any log messages not matching $regexp.
|
45 |
+
*
|
46 |
+
* @param string $regexp Regular expression to test the log message
|
47 |
+
* @throws Microsoft_Log_Exception
|
48 |
+
*/
|
49 |
+
public function __construct($regexp)
|
50 |
+
{
|
51 |
+
if (@preg_match($regexp, '') === false) {
|
52 |
+
require_once 'Microsoft/Log/Exception.php';
|
53 |
+
throw new Microsoft_Log_Exception("Invalid regular expression '$regexp'");
|
54 |
+
}
|
55 |
+
$this->_regexp = $regexp;
|
56 |
+
}
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Create a new instance of Microsoft_Log_Filter_Message
|
60 |
+
*
|
61 |
+
* @param array $config
|
62 |
+
* @return Microsoft_Log_Filter_Message
|
63 |
+
* @throws Microsoft_Log_Exception
|
64 |
+
*/
|
65 |
+
static public function factory($config)
|
66 |
+
{
|
67 |
+
$config = self::_parseConfig($config);
|
68 |
+
$config = array_merge(array(
|
69 |
+
'regexp' => null
|
70 |
+
), $config);
|
71 |
+
|
72 |
+
return new self(
|
73 |
+
$config['regexp']
|
74 |
+
);
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Returns TRUE to accept the message, FALSE to block it.
|
79 |
+
*
|
80 |
+
* @param array $event event data
|
81 |
+
* @return boolean accepted?
|
82 |
+
*/
|
83 |
+
public function accept($event)
|
84 |
+
{
|
85 |
+
return preg_match($this->_regexp, $event['message']) > 0;
|
86 |
+
}
|
87 |
+
}
|
libs/Microsoft/Log/Filter/Priority.php
CHANGED
@@ -1,103 +1,103 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Zend Framework
|
4 |
-
*
|
5 |
-
* LICENSE
|
6 |
-
*
|
7 |
-
* This source file is subject to the new BSD license that is bundled
|
8 |
-
* with this package in the file LICENSE.txt.
|
9 |
-
* It is also available through the world-wide-web at this URL:
|
10 |
-
* http://framework.zend.com/license/new-bsd
|
11 |
-
* If you did not receive a copy of the license and are unable to
|
12 |
-
* obtain it through the world-wide-web, please send an email
|
13 |
-
* to license@zend.com so we can send you a copy immediately.
|
14 |
-
*
|
15 |
-
* @category Microsoft
|
16 |
-
* @package Microsoft_Log
|
17 |
-
* @subpackage Filter
|
18 |
-
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
19 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
20 |
-
* @version $Id: Priority.php 20260 2010-01-13 18:29:22Z ralph $
|
21 |
-
*/
|
22 |
-
|
23 |
-
/**
|
24 |
-
* @see Microsoft_AutoLoader
|
25 |
-
*/
|
26 |
-
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
27 |
-
|
28 |
-
/**
|
29 |
-
* @category Microsoft
|
30 |
-
* @package Microsoft_Log
|
31 |
-
* @subpackage Filter
|
32 |
-
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
33 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
34 |
-
* @version $Id: Priority.php 20260 2010-01-13 18:29:22Z ralph $
|
35 |
-
*/
|
36 |
-
class Microsoft_Log_Filter_Priority extends Microsoft_Log_Filter_Abstract
|
37 |
-
{
|
38 |
-
/**
|
39 |
-
* @var integer
|
40 |
-
*/
|
41 |
-
protected $_priority;
|
42 |
-
|
43 |
-
/**
|
44 |
-
* @var string
|
45 |
-
*/
|
46 |
-
protected $_operator;
|
47 |
-
|
48 |
-
/**
|
49 |
-
* Filter logging by $priority. By default, it will accept any log
|
50 |
-
* event whose priority value is less than or equal to $priority.
|
51 |
-
*
|
52 |
-
* @param integer $priority Priority
|
53 |
-
* @param string $operator Comparison operator
|
54 |
-
* @throws Microsoft_Log_Exception
|
55 |
-
*/
|
56 |
-
public function __construct($priority, $operator = NULL)
|
57 |
-
{
|
58 |
-
if (! is_integer($priority)) {
|
59 |
-
require_once 'Microsoft/Log/Exception.php';
|
60 |
-
throw new Microsoft_Log_Exception('Priority must be an integer');
|
61 |
-
}
|
62 |
-
|
63 |
-
$this->_priority = $priority;
|
64 |
-
$this->_operator = is_null($operator) ? '<=' : $operator;
|
65 |
-
}
|
66 |
-
|
67 |
-
/**
|
68 |
-
* Create a new instance of Microsoft_Log_Filter_Priority
|
69 |
-
*
|
70 |
-
* @param array $config
|
71 |
-
* @return Microsoft_Log_Filter_Priority
|
72 |
-
* @throws Microsoft_Log_Exception
|
73 |
-
*/
|
74 |
-
static public function factory($config)
|
75 |
-
{
|
76 |
-
$config = self::_parseConfig($config);
|
77 |
-
$config = array_merge(array(
|
78 |
-
'priority' => null,
|
79 |
-
'operator' => null,
|
80 |
-
), $config);
|
81 |
-
|
82 |
-
// Add support for constants
|
83 |
-
if (!is_numeric($config['priority']) && isset($config['priority']) && defined($config['priority'])) {
|
84 |
-
$config['priority'] = constant($config['priority']);
|
85 |
-
}
|
86 |
-
|
87 |
-
return new self(
|
88 |
-
(int) $config['priority'],
|
89 |
-
$config['operator']
|
90 |
-
);
|
91 |
-
}
|
92 |
-
|
93 |
-
/**
|
94 |
-
* Returns TRUE to accept the message, FALSE to block it.
|
95 |
-
*
|
96 |
-
* @param array $event event data
|
97 |
-
* @return boolean accepted?
|
98 |
-
*/
|
99 |
-
public function accept($event)
|
100 |
-
{
|
101 |
-
return version_compare($event['priority'], $this->_priority, $this->_operator);
|
102 |
-
}
|
103 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Zend Framework
|
4 |
+
*
|
5 |
+
* LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the new BSD license that is bundled
|
8 |
+
* with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://framework.zend.com/license/new-bsd
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@zend.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* @category Microsoft
|
16 |
+
* @package Microsoft_Log
|
17 |
+
* @subpackage Filter
|
18 |
+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
19 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
20 |
+
* @version $Id: Priority.php 20260 2010-01-13 18:29:22Z ralph $
|
21 |
+
*/
|
22 |
+
|
23 |
+
/**
|
24 |
+
* @see Microsoft_AutoLoader
|
25 |
+
*/
|
26 |
+
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
27 |
+
|
28 |
+
/**
|
29 |
+
* @category Microsoft
|
30 |
+
* @package Microsoft_Log
|
31 |
+
* @subpackage Filter
|
32 |
+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
33 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
34 |
+
* @version $Id: Priority.php 20260 2010-01-13 18:29:22Z ralph $
|
35 |
+
*/
|
36 |
+
class Microsoft_Log_Filter_Priority extends Microsoft_Log_Filter_Abstract
|
37 |
+
{
|
38 |
+
/**
|
39 |
+
* @var integer
|
40 |
+
*/
|
41 |
+
protected $_priority;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* @var string
|
45 |
+
*/
|
46 |
+
protected $_operator;
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Filter logging by $priority. By default, it will accept any log
|
50 |
+
* event whose priority value is less than or equal to $priority.
|
51 |
+
*
|
52 |
+
* @param integer $priority Priority
|
53 |
+
* @param string $operator Comparison operator
|
54 |
+
* @throws Microsoft_Log_Exception
|
55 |
+
*/
|
56 |
+
public function __construct($priority, $operator = NULL)
|
57 |
+
{
|
58 |
+
if (! is_integer($priority)) {
|
59 |
+
require_once 'Microsoft/Log/Exception.php';
|
60 |
+
throw new Microsoft_Log_Exception('Priority must be an integer');
|
61 |
+
}
|
62 |
+
|
63 |
+
$this->_priority = $priority;
|
64 |
+
$this->_operator = is_null($operator) ? '<=' : $operator;
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Create a new instance of Microsoft_Log_Filter_Priority
|
69 |
+
*
|
70 |
+
* @param array $config
|
71 |
+
* @return Microsoft_Log_Filter_Priority
|
72 |
+
* @throws Microsoft_Log_Exception
|
73 |
+
*/
|
74 |
+
static public function factory($config)
|
75 |
+
{
|
76 |
+
$config = self::_parseConfig($config);
|
77 |
+
$config = array_merge(array(
|
78 |
+
'priority' => null,
|
79 |
+
'operator' => null,
|
80 |
+
), $config);
|
81 |
+
|
82 |
+
// Add support for constants
|
83 |
+
if (!is_numeric($config['priority']) && isset($config['priority']) && defined($config['priority'])) {
|
84 |
+
$config['priority'] = constant($config['priority']);
|
85 |
+
}
|
86 |
+
|
87 |
+
return new self(
|
88 |
+
(int) $config['priority'],
|
89 |
+
$config['operator']
|
90 |
+
);
|
91 |
+
}
|
92 |
+
|
93 |
+
/**
|
94 |
+
* Returns TRUE to accept the message, FALSE to block it.
|
95 |
+
*
|
96 |
+
* @param array $event event data
|
97 |
+
* @return boolean accepted?
|
98 |
+
*/
|
99 |
+
public function accept($event)
|
100 |
+
{
|
101 |
+
return version_compare($event['priority'], $this->_priority, $this->_operator);
|
102 |
+
}
|
103 |
+
}
|
libs/Microsoft/Log/Filter/Suppress.php
CHANGED
@@ -1,79 +1,79 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Zend Framework
|
4 |
-
*
|
5 |
-
* LICENSE
|
6 |
-
*
|
7 |
-
* This source file is subject to the new BSD license that is bundled
|
8 |
-
* with this package in the file LICENSE.txt.
|
9 |
-
* It is also available through the world-wide-web at this URL:
|
10 |
-
* http://framework.zend.com/license/new-bsd
|
11 |
-
* If you did not receive a copy of the license and are unable to
|
12 |
-
* obtain it through the world-wide-web, please send an email
|
13 |
-
* to license@zend.com so we can send you a copy immediately.
|
14 |
-
*
|
15 |
-
* @category Microsoft
|
16 |
-
* @package Microsoft_Log
|
17 |
-
* @subpackage Filter
|
18 |
-
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
19 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
20 |
-
* @version $Id: Suppress.php 20096 2010-01-06 02:05:09Z bkarwin $
|
21 |
-
*/
|
22 |
-
|
23 |
-
/**
|
24 |
-
* @see Microsoft_AutoLoader
|
25 |
-
*/
|
26 |
-
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
27 |
-
|
28 |
-
/**
|
29 |
-
* @category Microsoft
|
30 |
-
* @package Microsoft_Log
|
31 |
-
* @subpackage Filter
|
32 |
-
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
33 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
34 |
-
* @version $Id: Suppress.php 20096 2010-01-06 02:05:09Z bkarwin $
|
35 |
-
*/
|
36 |
-
class Microsoft_Log_Filter_Suppress extends Microsoft_Log_Filter_Abstract
|
37 |
-
{
|
38 |
-
/**
|
39 |
-
* @var boolean
|
40 |
-
*/
|
41 |
-
protected $_accept = true;
|
42 |
-
|
43 |
-
/**
|
44 |
-
* This is a simple boolean filter.
|
45 |
-
*
|
46 |
-
* Call suppress(true) to suppress all log events.
|
47 |
-
* Call suppress(false) to accept all log events.
|
48 |
-
*
|
49 |
-
* @param boolean $suppress Should all log events be suppressed?
|
50 |
-
* @return void
|
51 |
-
*/
|
52 |
-
public function suppress($suppress)
|
53 |
-
{
|
54 |
-
$this->_accept = (! $suppress);
|
55 |
-
}
|
56 |
-
|
57 |
-
/**
|
58 |
-
* Returns TRUE to accept the message, FALSE to block it.
|
59 |
-
*
|
60 |
-
* @param array $event event data
|
61 |
-
* @return boolean accepted?
|
62 |
-
*/
|
63 |
-
public function accept($event)
|
64 |
-
{
|
65 |
-
return $this->_accept;
|
66 |
-
}
|
67 |
-
|
68 |
-
/**
|
69 |
-
* Create a new instance of Microsoft_Log_Filter_Suppress
|
70 |
-
*
|
71 |
-
* @param array $config
|
72 |
-
* @return Microsoft_Log_Filter_Suppress
|
73 |
-
* @throws Microsoft_Log_Exception
|
74 |
-
*/
|
75 |
-
static public function factory($config)
|
76 |
-
{
|
77 |
-
return new self();
|
78 |
-
}
|
79 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Zend Framework
|
4 |
+
*
|
5 |
+
* LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the new BSD license that is bundled
|
8 |
+
* with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://framework.zend.com/license/new-bsd
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@zend.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* @category Microsoft
|
16 |
+
* @package Microsoft_Log
|
17 |
+
* @subpackage Filter
|
18 |
+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
19 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
20 |
+
* @version $Id: Suppress.php 20096 2010-01-06 02:05:09Z bkarwin $
|
21 |
+
*/
|
22 |
+
|
23 |
+
/**
|
24 |
+
* @see Microsoft_AutoLoader
|
25 |
+
*/
|
26 |
+
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
27 |
+
|
28 |
+
/**
|
29 |
+
* @category Microsoft
|
30 |
+
* @package Microsoft_Log
|
31 |
+
* @subpackage Filter
|
32 |
+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
33 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
34 |
+
* @version $Id: Suppress.php 20096 2010-01-06 02:05:09Z bkarwin $
|
35 |
+
*/
|
36 |
+
class Microsoft_Log_Filter_Suppress extends Microsoft_Log_Filter_Abstract
|
37 |
+
{
|
38 |
+
/**
|
39 |
+
* @var boolean
|
40 |
+
*/
|
41 |
+
protected $_accept = true;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* This is a simple boolean filter.
|
45 |
+
*
|
46 |
+
* Call suppress(true) to suppress all log events.
|
47 |
+
* Call suppress(false) to accept all log events.
|
48 |
+
*
|
49 |
+
* @param boolean $suppress Should all log events be suppressed?
|
50 |
+
* @return void
|
51 |
+
*/
|
52 |
+
public function suppress($suppress)
|
53 |
+
{
|
54 |
+
$this->_accept = (! $suppress);
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Returns TRUE to accept the message, FALSE to block it.
|
59 |
+
*
|
60 |
+
* @param array $event event data
|
61 |
+
* @return boolean accepted?
|
62 |
+
*/
|
63 |
+
public function accept($event)
|
64 |
+
{
|
65 |
+
return $this->_accept;
|
66 |
+
}
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Create a new instance of Microsoft_Log_Filter_Suppress
|
70 |
+
*
|
71 |
+
* @param array $config
|
72 |
+
* @return Microsoft_Log_Filter_Suppress
|
73 |
+
* @throws Microsoft_Log_Exception
|
74 |
+
*/
|
75 |
+
static public function factory($config)
|
76 |
+
{
|
77 |
+
return new self();
|
78 |
+
}
|
79 |
+
}
|
libs/Microsoft/Log/Formatter/Interface.php
CHANGED
@@ -1,41 +1,41 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Zend Framework
|
4 |
-
*
|
5 |
-
* LICENSE
|
6 |
-
*
|
7 |
-
* This source file is subject to the new BSD license that is bundled
|
8 |
-
* with this package in the file LICENSE.txt.
|
9 |
-
* It is also available through the world-wide-web at this URL:
|
10 |
-
* http://framework.zend.com/license/new-bsd
|
11 |
-
* If you did not receive a copy of the license and are unable to
|
12 |
-
* obtain it through the world-wide-web, please send an email
|
13 |
-
* to license@zend.com so we can send you a copy immediately.
|
14 |
-
*
|
15 |
-
* @category Microsoft
|
16 |
-
* @package Microsoft_Log
|
17 |
-
* @subpackage Formatter
|
18 |
-
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
19 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
20 |
-
* @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
|
21 |
-
*/
|
22 |
-
|
23 |
-
/**
|
24 |
-
* @category Microsoft
|
25 |
-
* @package Microsoft_Log
|
26 |
-
* @subpackage Formatter
|
27 |
-
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
28 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
29 |
-
* @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
|
30 |
-
*/
|
31 |
-
interface Microsoft_Log_Formatter_Interface
|
32 |
-
{
|
33 |
-
/**
|
34 |
-
* Formats data into a single line to be written by the writer.
|
35 |
-
*
|
36 |
-
* @param array $event event data
|
37 |
-
* @return string formatted line to write to the log
|
38 |
-
*/
|
39 |
-
public function format($event);
|
40 |
-
|
41 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Zend Framework
|
4 |
+
*
|
5 |
+
* LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the new BSD license that is bundled
|
8 |
+
* with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://framework.zend.com/license/new-bsd
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@zend.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* @category Microsoft
|
16 |
+
* @package Microsoft_Log
|
17 |
+
* @subpackage Formatter
|
18 |
+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
19 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
20 |
+
* @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
|
21 |
+
*/
|
22 |
+
|
23 |
+
/**
|
24 |
+
* @category Microsoft
|
25 |
+
* @package Microsoft_Log
|
26 |
+
* @subpackage Formatter
|
27 |
+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
28 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
29 |
+
* @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
|
30 |
+
*/
|
31 |
+
interface Microsoft_Log_Formatter_Interface
|
32 |
+
{
|
33 |
+
/**
|
34 |
+
* Formats data into a single line to be written by the writer.
|
35 |
+
*
|
36 |
+
* @param array $event event data
|
37 |
+
* @return string formatted line to write to the log
|
38 |
+
*/
|
39 |
+
public function format($event);
|
40 |
+
|
41 |
+
}
|
libs/Microsoft/Log/Writer/Abstract.php
CHANGED
@@ -1,133 +1,133 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Zend Framework
|
4 |
-
*
|
5 |
-
* LICENSE
|
6 |
-
*
|
7 |
-
* This source file is subject to the new BSD license that is bundled
|
8 |
-
* with this package in the file LICENSE.txt.
|
9 |
-
* It is also available through the world-wide-web at this URL:
|
10 |
-
* http://framework.zend.com/license/new-bsd
|
11 |
-
* If you did not receive a copy of the license and are unable to
|
12 |
-
* obtain it through the world-wide-web, please send an email
|
13 |
-
* to license@zend.com so we can send you a copy immediately.
|
14 |
-
*
|
15 |
-
* @category Microsoft
|
16 |
-
* @package Microsoft_Log
|
17 |
-
* @subpackage Writer
|
18 |
-
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
19 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
20 |
-
* @version $Id: Abstract.php 22632 2010-07-18 18:30:08Z ramon $
|
21 |
-
*/
|
22 |
-
|
23 |
-
/**
|
24 |
-
* @see Microsoft_AutoLoader
|
25 |
-
*/
|
26 |
-
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
27 |
-
|
28 |
-
/**
|
29 |
-
* @category Microsoft
|
30 |
-
* @package Microsoft_Log
|
31 |
-
* @subpackage Writer
|
32 |
-
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
33 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
34 |
-
* @version $Id: Abstract.php 22632 2010-07-18 18:30:08Z ramon $
|
35 |
-
*/
|
36 |
-
abstract class Microsoft_Log_Writer_Abstract implements Microsoft_Log_FactoryInterface
|
37 |
-
{
|
38 |
-
/**
|
39 |
-
* @var array of Microsoft_Log_Filter_Interface
|
40 |
-
*/
|
41 |
-
protected $_filters = array();
|
42 |
-
|
43 |
-
/**
|
44 |
-
* Formats the log message before writing.
|
45 |
-
* @var Microsoft_Log_Formatter_Interface
|
46 |
-
*/
|
47 |
-
protected $_formatter;
|
48 |
-
|
49 |
-
/**
|
50 |
-
* Add a filter specific to this writer.
|
51 |
-
*
|
52 |
-
* @param Microsoft_Log_Filter_Interface $filter
|
53 |
-
* @return void
|
54 |
-
*/
|
55 |
-
public function addFilter($filter)
|
56 |
-
{
|
57 |
-
if (is_integer($filter)) {
|
58 |
-
$filter = new Microsoft_Log_Filter_Priority($filter);
|
59 |
-
}
|
60 |
-
|
61 |
-
if (!$filter instanceof Microsoft_Log_Filter_Interface) {
|
62 |
-
/** @see Microsoft_Log_Exception */
|
63 |
-
require_once 'Microsoft/Log/Exception.php';
|
64 |
-
throw new Microsoft_Log_Exception('Invalid filter provided');
|
65 |
-
}
|
66 |
-
|
67 |
-
$this->_filters[] = $filter;
|
68 |
-
}
|
69 |
-
|
70 |
-
/**
|
71 |
-
* Log a message to this writer.
|
72 |
-
*
|
73 |
-
* @param array $event log data event
|
74 |
-
* @return void
|
75 |
-
*/
|
76 |
-
public function write($event)
|
77 |
-
{
|
78 |
-
foreach ($this->_filters as $filter) {
|
79 |
-
if (! $filter->accept($event)) {
|
80 |
-
return;
|
81 |
-
}
|
82 |
-
}
|
83 |
-
|
84 |
-
// exception occurs on error
|
85 |
-
$this->_write($event);
|
86 |
-
}
|
87 |
-
|
88 |
-
/**
|
89 |
-
* Set a new formatter for this writer
|
90 |
-
*
|
91 |
-
* @param Microsoft_Log_Formatter_Interface $formatter
|
92 |
-
* @return void
|
93 |
-
*/
|
94 |
-
public function setFormatter(Microsoft_Log_Formatter_Interface $formatter)
|
95 |
-
{
|
96 |
-
$this->_formatter = $formatter;
|
97 |
-
}
|
98 |
-
|
99 |
-
/**
|
100 |
-
* Perform shutdown activites such as closing open resources
|
101 |
-
*
|
102 |
-
* @return void
|
103 |
-
*/
|
104 |
-
public function shutdown()
|
105 |
-
{}
|
106 |
-
|
107 |
-
/**
|
108 |
-
* Write a message to the log.
|
109 |
-
*
|
110 |
-
* @param array $event log data event
|
111 |
-
* @return void
|
112 |
-
*/
|
113 |
-
abstract protected function _write($event);
|
114 |
-
|
115 |
-
/**
|
116 |
-
* Validate and optionally convert the config to array
|
117 |
-
*
|
118 |
-
* @param array $config
|
119 |
-
* @return array
|
120 |
-
* @throws Zend_Log_Exception
|
121 |
-
*/
|
122 |
-
static protected function _parseConfig($config)
|
123 |
-
{
|
124 |
-
if (!is_array($config)) {
|
125 |
-
require_once 'Microsoft/Log/Exception.php';
|
126 |
-
throw new Microsoft_Log_Exception(
|
127 |
-
'Configuration must be an array'
|
128 |
-
);
|
129 |
-
}
|
130 |
-
|
131 |
-
return $config;
|
132 |
-
}
|
133 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Zend Framework
|
4 |
+
*
|
5 |
+
* LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the new BSD license that is bundled
|
8 |
+
* with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://framework.zend.com/license/new-bsd
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@zend.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* @category Microsoft
|
16 |
+
* @package Microsoft_Log
|
17 |
+
* @subpackage Writer
|
18 |
+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
19 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
20 |
+
* @version $Id: Abstract.php 22632 2010-07-18 18:30:08Z ramon $
|
21 |
+
*/
|
22 |
+
|
23 |
+
/**
|
24 |
+
* @see Microsoft_AutoLoader
|
25 |
+
*/
|
26 |
+
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
27 |
+
|
28 |
+
/**
|
29 |
+
* @category Microsoft
|
30 |
+
* @package Microsoft_Log
|
31 |
+
* @subpackage Writer
|
32 |
+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
33 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
34 |
+
* @version $Id: Abstract.php 22632 2010-07-18 18:30:08Z ramon $
|
35 |
+
*/
|
36 |
+
abstract class Microsoft_Log_Writer_Abstract implements Microsoft_Log_FactoryInterface
|
37 |
+
{
|
38 |
+
/**
|
39 |
+
* @var array of Microsoft_Log_Filter_Interface
|
40 |
+
*/
|
41 |
+
protected $_filters = array();
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Formats the log message before writing.
|
45 |
+
* @var Microsoft_Log_Formatter_Interface
|
46 |
+
*/
|
47 |
+
protected $_formatter;
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Add a filter specific to this writer.
|
51 |
+
*
|
52 |
+
* @param Microsoft_Log_Filter_Interface $filter
|
53 |
+
* @return void
|
54 |
+
*/
|
55 |
+
public function addFilter($filter)
|
56 |
+
{
|
57 |
+
if (is_integer($filter)) {
|
58 |
+
$filter = new Microsoft_Log_Filter_Priority($filter);
|
59 |
+
}
|
60 |
+
|
61 |
+
if (!$filter instanceof Microsoft_Log_Filter_Interface) {
|
62 |
+
/** @see Microsoft_Log_Exception */
|
63 |
+
require_once 'Microsoft/Log/Exception.php';
|
64 |
+
throw new Microsoft_Log_Exception('Invalid filter provided');
|
65 |
+
}
|
66 |
+
|
67 |
+
$this->_filters[] = $filter;
|
68 |
+
}
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Log a message to this writer.
|
72 |
+
*
|
73 |
+
* @param array $event log data event
|
74 |
+
* @return void
|
75 |
+
*/
|
76 |
+
public function write($event)
|
77 |
+
{
|
78 |
+
foreach ($this->_filters as $filter) {
|
79 |
+
if (! $filter->accept($event)) {
|
80 |
+
return;
|
81 |
+
}
|
82 |
+
}
|
83 |
+
|
84 |
+
// exception occurs on error
|
85 |
+
$this->_write($event);
|
86 |
+
}
|
87 |
+
|
88 |
+
/**
|
89 |
+
* Set a new formatter for this writer
|
90 |
+
*
|
91 |
+
* @param Microsoft_Log_Formatter_Interface $formatter
|
92 |
+
* @return void
|
93 |
+
*/
|
94 |
+
public function setFormatter(Microsoft_Log_Formatter_Interface $formatter)
|
95 |
+
{
|
96 |
+
$this->_formatter = $formatter;
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Perform shutdown activites such as closing open resources
|
101 |
+
*
|
102 |
+
* @return void
|
103 |
+
*/
|
104 |
+
public function shutdown()
|
105 |
+
{}
|
106 |
+
|
107 |
+
/**
|
108 |
+
* Write a message to the log.
|
109 |
+
*
|
110 |
+
* @param array $event log data event
|
111 |
+
* @return void
|
112 |
+
*/
|
113 |
+
abstract protected function _write($event);
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Validate and optionally convert the config to array
|
117 |
+
*
|
118 |
+
* @param array $config
|
119 |
+
* @return array
|
120 |
+
* @throws Zend_Log_Exception
|
121 |
+
*/
|
122 |
+
static protected function _parseConfig($config)
|
123 |
+
{
|
124 |
+
if (!is_array($config)) {
|
125 |
+
require_once 'Microsoft/Log/Exception.php';
|
126 |
+
throw new Microsoft_Log_Exception(
|
127 |
+
'Configuration must be an array'
|
128 |
+
);
|
129 |
+
}
|
130 |
+
|
131 |
+
return $config;
|
132 |
+
}
|
133 |
+
}
|
libs/Microsoft/SqlAzure/CommandLine/SqlAzure.php
ADDED
@@ -0,0 +1,298 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_Console
|
30 |
+
* @subpackage Exception
|
31 |
+
* @version $Id: Exception.php 55733 2011-01-03 09:17:16Z unknown $
|
32 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
33 |
+
* @license http://phpazure.codeplex.com/license
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @see Microsoft_AutoLoader
|
38 |
+
*/
|
39 |
+
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Service commands
|
43 |
+
*
|
44 |
+
* @category Microsoft
|
45 |
+
* @package Microsoft_SqlAzure_CommandLine
|
46 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
47 |
+
* @license http://phpazure.codeplex.com/license
|
48 |
+
*
|
49 |
+
* @command-handler sqlazure
|
50 |
+
* @command-handler-description Sql Azure Server commands
|
51 |
+
* @command-handler-header Windows Azure SDK for PHP
|
52 |
+
* @command-handler-header Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
53 |
+
* @command-handler-footer Note: Parameters that are common across all commands can be stored
|
54 |
+
* @command-handler-footer in two dedicated environment variables.
|
55 |
+
* @command-handler-footer - SubscriptionId: The Windows Azure Subscription Id to operate on.
|
56 |
+
* @command-handler-footer - Certificate The Windows Azure .cer Management Certificate.
|
57 |
+
* @command-handler-footer
|
58 |
+
* @command-handler-footer All commands support the --ConfigurationFile or -F parameter.
|
59 |
+
* @command-handler-footer The parameter file is a simple INI file carrying one parameter
|
60 |
+
* @command-handler-footer value per line. It accepts the same parameters as one can
|
61 |
+
* @command-handler-footer use from the command line command.
|
62 |
+
*/
|
63 |
+
class Microsoft_SqlAzure_CommandLine_SqlAzure
|
64 |
+
extends Microsoft_Console_Command
|
65 |
+
{
|
66 |
+
/**
|
67 |
+
* List servers for a specified subscription.
|
68 |
+
*
|
69 |
+
* @command-name List
|
70 |
+
* @command-description List servers for a specified subscription.
|
71 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
72 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
73 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed.
|
74 |
+
* @command-example List servers for a specified subscription:
|
75 |
+
* @command-example List -sid="<your_subscription_id>" -cert="mycert.pem"
|
76 |
+
*/
|
77 |
+
public function listCommand($subscriptionId, $certificate, $certificatePassphrase)
|
78 |
+
{
|
79 |
+
$client = new Microsoft_SqlAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
80 |
+
$result = $client->listServers();
|
81 |
+
|
82 |
+
if (count($result) == 0) {
|
83 |
+
echo 'No data to display.';
|
84 |
+
}
|
85 |
+
foreach ($result as $object) {
|
86 |
+
$this->_displayObjectInformation($object, array('Name', 'AdministratorLogin'));
|
87 |
+
}
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Get server properties.
|
92 |
+
*
|
93 |
+
* @command-name GetProperties
|
94 |
+
* @command-description Get server properties.
|
95 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
96 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
97 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed.
|
98 |
+
* @command-parameter-for $serverName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env|Microsoft_Console_Command_ParameterSource_StdIn --Name Required. The server name to operate on.
|
99 |
+
* @command-example Get server properties for server "ie2l1ph28":
|
100 |
+
* @command-example GetProperties -sid="<your_subscription_id>" -cert="mycert.pem"
|
101 |
+
* @command-example --Name="ie2l1ph28"
|
102 |
+
*/
|
103 |
+
public function getPropertiesCommand($subscriptionId, $certificate, $certificatePassphrase, $serverName)
|
104 |
+
{
|
105 |
+
$client = new Microsoft_SqlAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
106 |
+
$result = $client->listServers();
|
107 |
+
|
108 |
+
$server = null;
|
109 |
+
foreach ($result as $serverInstance) {
|
110 |
+
if ($serverInstance->Name == $serverName) {
|
111 |
+
$server = $serverInstance;
|
112 |
+
break;
|
113 |
+
}
|
114 |
+
}
|
115 |
+
|
116 |
+
$this->_displayObjectInformation($server, array('Name', 'DnsName', 'AdministratorLogin', 'Location'));
|
117 |
+
}
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Get server property.
|
121 |
+
*
|
122 |
+
* @command-name GetProperty
|
123 |
+
* @command-description Get server property.
|
124 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
125 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
126 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed.
|
127 |
+
* @command-parameter-for $serverName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env|Microsoft_Console_Command_ParameterSource_StdIn --Name Required. The server name to operate on.
|
128 |
+
* @command-parameter-for $property Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Property|-prop Required. The property to retrieve for the server.
|
129 |
+
* @command-example Get server property "Name" for service "ie2l1ph28":
|
130 |
+
* @command-example GetProperty -sid="<your_subscription_id>" -cert="mycert.pem"
|
131 |
+
* @command-example --Name="ie2l1ph28" --Property=Name
|
132 |
+
*/
|
133 |
+
public function getPropertyCommand($subscriptionId, $certificate, $certificatePassphrase, $serverName, $property)
|
134 |
+
{
|
135 |
+
$client = new Microsoft_SqlAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
136 |
+
$result = $client->listServers();
|
137 |
+
|
138 |
+
$server = null;
|
139 |
+
foreach ($result as $serverInstance) {
|
140 |
+
if ($serverInstance->Name == $serverName) {
|
141 |
+
$server = $serverInstance;
|
142 |
+
break;
|
143 |
+
}
|
144 |
+
}
|
145 |
+
|
146 |
+
printf("%s\r\n", $server->$property);
|
147 |
+
}
|
148 |
+
|
149 |
+
/**
|
150 |
+
* Create server.
|
151 |
+
*
|
152 |
+
* @command-name Create
|
153 |
+
* @command-description Create server.
|
154 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
155 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
156 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed.
|
157 |
+
* @command-parameter-for $administratorLogin Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Login|-l Required. The administrator login name for the server.
|
158 |
+
* @command-parameter-for $administratorPassword Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Password|-pass Required. The administrator password for the server.
|
159 |
+
* @command-parameter-for $location Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Location Required. The location where the server will be created.
|
160 |
+
* @command-parameter-for $waitForOperation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete?
|
161 |
+
* @command-example Create server in West Europe
|
162 |
+
* @command-example Create -p="phpazure" --Login="sqladm" --Password="PHP@zure11" --Location="West Europe"
|
163 |
+
*/
|
164 |
+
public function createCommand($subscriptionId, $certificate, $certificatePassphrase, $administratorLogin, $administratorPassword, $location, $waitForOperation = false)
|
165 |
+
{
|
166 |
+
$client = new Microsoft_SqlAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
167 |
+
$server = $client->createServer($administratorLogin, $administratorPassword, $location);
|
168 |
+
echo $server->Name;
|
169 |
+
}
|
170 |
+
|
171 |
+
/**
|
172 |
+
* Drop server.
|
173 |
+
*
|
174 |
+
* @command-name Drop
|
175 |
+
* @command-description Drop server.
|
176 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
177 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
178 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed.
|
179 |
+
* @command-parameter-for $serverName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_StdIn --Name Required. The server name to operate on.
|
180 |
+
* @command-parameter-for $waitForOperation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete?
|
181 |
+
* @command-example Drop server "ie2l1ph28":
|
182 |
+
* @command-example Drop -p="phpazure" --Name="ie2l1ph28"
|
183 |
+
*/
|
184 |
+
public function dropCommand($subscriptionId, $certificate, $certificatePassphrase, $serverName, $waitForOperation = false)
|
185 |
+
{
|
186 |
+
$client = new Microsoft_SqlAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
187 |
+
$server = $client->dropServer($serverName);
|
188 |
+
}
|
189 |
+
|
190 |
+
/**
|
191 |
+
* Update administrator password for server.
|
192 |
+
*
|
193 |
+
* @command-name UpdatePassword
|
194 |
+
* @command-description Update administrator password for server.
|
195 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
196 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
197 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed.
|
198 |
+
* @command-parameter-for $serverName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_StdIn --Name Required. The server name to operate on.
|
199 |
+
* @command-parameter-for $administratorPassword Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Password|-pass Required. The administrator password for the server.
|
200 |
+
* @command-parameter-for $waitForOperation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete?
|
201 |
+
* @command-example Update administrator password for server "ie2l1ph28":
|
202 |
+
* @command-example UpdatePassword -p="phpazure" --Name="ie2l1ph28" --Password="PHP@zure11"
|
203 |
+
*/
|
204 |
+
public function updatePasswordCommand($subscriptionId, $certificate, $certificatePassphrase, $serverName, $administratorPassword, $waitForOperation = false)
|
205 |
+
{
|
206 |
+
$client = new Microsoft_SqlAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
207 |
+
$server = $client->setAdministratorPassword($serverName, $administratorPassword);
|
208 |
+
}
|
209 |
+
|
210 |
+
/**
|
211 |
+
* Create firewall rule for server.
|
212 |
+
*
|
213 |
+
* @command-name CreateFirewallRule
|
214 |
+
* @command-description Create firewall rule for server.
|
215 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
216 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
217 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed.
|
218 |
+
* @command-parameter-for $serverName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_StdIn --Name Required. The server name to operate on.
|
219 |
+
* @command-parameter-for $ruleName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --RuleName|-r Required. Firewall rule name.
|
220 |
+
* @command-parameter-for $startIpAddress Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --StartIp|-start Required. Start IP address.
|
221 |
+
* @command-parameter-for $endIpAddress Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --EndIp|-end Required. End IP address.
|
222 |
+
* @command-parameter-for $waitForOperation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete?
|
223 |
+
* @command-example Create firewall rule for server "ie2l1ph28":
|
224 |
+
* @command-example CreateFirewallRule -p="phpazure" --Name="ie2l1ph28" -r="Rule1" -start="1.2.3.4" -end="1.2.3.4"
|
225 |
+
*/
|
226 |
+
public function createFirewallRuleCommand($subscriptionId, $certificate, $certificatePassphrase, $serverName, $ruleName, $startIpAddress, $endIpAddress, $waitForOperation = false)
|
227 |
+
{
|
228 |
+
$client = new Microsoft_SqlAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
229 |
+
$rule = $client->createFirewallRule($serverName, $ruleName, $startIpAddress, $endIpAddress);
|
230 |
+
}
|
231 |
+
|
232 |
+
/**
|
233 |
+
* Allow access from Windows Azure to SQL Azure.
|
234 |
+
*
|
235 |
+
* @command-name AllowWindowsAzure
|
236 |
+
* @command-description Allow access from Windows Azure to SQL Azure.
|
237 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
238 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
239 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed.
|
240 |
+
* @command-parameter-for $serverName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_StdIn --Name Required. The server name to operate on.
|
241 |
+
* @command-parameter-for $allow Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Allow|-a Required. Allow access from Windows Azure true/false.
|
242 |
+
* @command-parameter-for $waitForOperation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete?
|
243 |
+
* @command-example Allow access from Windows Azure to SQL Azure for server "ie2l1ph28":
|
244 |
+
* @command-example AllowWindowsAzure -p="phpazure" --Name="ie2l1ph28" -Allow:true
|
245 |
+
*/
|
246 |
+
public function allowWindowsAzureCommand($subscriptionId, $certificate, $certificatePassphrase, $serverName, $allow = false, $waitForOperation = false)
|
247 |
+
{
|
248 |
+
$client = new Microsoft_SqlAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
249 |
+
$rule = $client->createFirewallRuleForMicrosoftServices($serverName, $allow);
|
250 |
+
}
|
251 |
+
|
252 |
+
/**
|
253 |
+
* Delete firewall rule for server.
|
254 |
+
*
|
255 |
+
* @command-name DeleteFirewallRule
|
256 |
+
* @command-description Delete firewall rule for server.
|
257 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
258 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
259 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed.
|
260 |
+
* @command-parameter-for $serverName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_StdIn --Name Required. The server name to operate on.
|
261 |
+
* @command-parameter-for $ruleName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --RuleName|-r Required. Firewall rule name.
|
262 |
+
* @command-parameter-for $waitForOperation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete?
|
263 |
+
* @command-example Delete firewall rule for server "ie2l1ph28":
|
264 |
+
* @command-example DeleteFirewallRule -p="phpazure" --Name="ie2l1ph28" -r="Rule1"
|
265 |
+
*/
|
266 |
+
public function deleteFirewallRuleCommand($subscriptionId, $certificate, $certificatePassphrase, $serverName, $ruleName, $waitForOperation = false)
|
267 |
+
{
|
268 |
+
$client = new Microsoft_SqlAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
269 |
+
$rule = $client->deleteFirewallRule($serverName, $ruleName);
|
270 |
+
}
|
271 |
+
|
272 |
+
/**
|
273 |
+
* List firewall rules for a specified server.
|
274 |
+
*
|
275 |
+
* @command-name ListFirewallRules
|
276 |
+
* @command-description List firewall rules for a specified server.
|
277 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
278 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
279 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed.
|
280 |
+
* @command-parameter-for $serverName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_StdIn --Name Required. The server name to operate on.
|
281 |
+
* @command-example List firewall rules for server "ie2l1ph28":
|
282 |
+
* @command-example ListFirewallRules -sid="<your_subscription_id>" --Name="ie2l1ph28"
|
283 |
+
*/
|
284 |
+
public function listFirewallRuleCommand($subscriptionId, $certificate, $certificatePassphrase, $serverName)
|
285 |
+
{
|
286 |
+
$client = new Microsoft_SqlAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
287 |
+
$result = $client->listFirewallRules($serverName);
|
288 |
+
|
289 |
+
if (count($result) == 0) {
|
290 |
+
echo 'No data to display.';
|
291 |
+
}
|
292 |
+
foreach ($result as $object) {
|
293 |
+
$this->_displayObjectInformation($object, array('Name', 'StartIpAddress', 'EndIpAddress'));
|
294 |
+
}
|
295 |
+
}
|
296 |
+
}
|
297 |
+
|
298 |
+
Microsoft_Console_Command::bootstrap($_SERVER['argv']);
|
libs/Microsoft/SqlAzure/Exception.php
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_WindowsAzure
|
30 |
+
* @subpackage Exception
|
31 |
+
* @version $Id: Exception.php 61042 2011-04-19 10:03:39Z unknown $
|
32 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
33 |
+
* @license http://phpazure.codeplex.com/license
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @see Microsoft_AutoLoader
|
38 |
+
*/
|
39 |
+
require_once dirname(__FILE__) . '/../AutoLoader.php';
|
40 |
+
|
41 |
+
/**
|
42 |
+
* @category Microsoft
|
43 |
+
* @package Microsoft_SqlAzure
|
44 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
45 |
+
* @license http://phpazure.codeplex.com/license
|
46 |
+
*/
|
47 |
+
class Microsoft_SqlAzure_Exception extends Microsoft_Exception
|
48 |
+
{}
|
libs/Microsoft/SqlAzure/Management/Client.php
ADDED
@@ -0,0 +1,564 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_WindowsAzure
|
30 |
+
* @subpackage Management
|
31 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
32 |
+
* @license http://phpazure.codeplex.com/license
|
33 |
+
* @version $Id: Storage.php 51671 2010-09-30 08:33:45Z unknown $
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @see Microsoft_AutoLoader
|
38 |
+
*/
|
39 |
+
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
40 |
+
|
41 |
+
/**
|
42 |
+
* @category Microsoft
|
43 |
+
* @package Microsoft_SqlAzure
|
44 |
+
* @subpackage Management
|
45 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
46 |
+
* @license http://phpazure.codeplex.com/license
|
47 |
+
*/
|
48 |
+
class Microsoft_SqlAzure_Management_Client
|
49 |
+
{
|
50 |
+
/**
|
51 |
+
* Management service URL
|
52 |
+
*/
|
53 |
+
const URL_MANAGEMENT = "https://management.database.windows.net:8443";
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Operations
|
57 |
+
*/
|
58 |
+
const OP_OPERATIONS = "operations";
|
59 |
+
const OP_SERVERS = "servers";
|
60 |
+
const OP_FIREWALLRULES = "firewallrules";
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Current API version
|
64 |
+
*
|
65 |
+
* @var string
|
66 |
+
*/
|
67 |
+
protected $_apiVersion = '1.0';
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Subscription ID
|
71 |
+
*
|
72 |
+
* @var string
|
73 |
+
*/
|
74 |
+
protected $_subscriptionId = '';
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Management certificate path (.PEM)
|
78 |
+
*
|
79 |
+
* @var string
|
80 |
+
*/
|
81 |
+
protected $_certificatePath = '';
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Management certificate passphrase
|
85 |
+
*
|
86 |
+
* @var string
|
87 |
+
*/
|
88 |
+
protected $_certificatePassphrase = '';
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Microsoft_Http_Client channel used for communication with REST services
|
92 |
+
*
|
93 |
+
* @var Microsoft_Http_Client
|
94 |
+
*/
|
95 |
+
protected $_httpClientChannel = null;
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract instance
|
99 |
+
*
|
100 |
+
* @var Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract
|
101 |
+
*/
|
102 |
+
protected $_retryPolicy = null;
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Returns the last request ID
|
106 |
+
*
|
107 |
+
* @var string
|
108 |
+
*/
|
109 |
+
protected $_lastRequestId = null;
|
110 |
+
|
111 |
+
/**
|
112 |
+
* Creates a new Microsoft_SqlAzure_Management_Client instance
|
113 |
+
*
|
114 |
+
* @param string $subscriptionId Subscription ID
|
115 |
+
* @param string $certificatePath Management certificate path (.PEM)
|
116 |
+
* @param string $certificatePassphrase Management certificate passphrase
|
117 |
+
* @param Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy Retry policy to use when making requests
|
118 |
+
*/
|
119 |
+
public function __construct(
|
120 |
+
$subscriptionId,
|
121 |
+
$certificatePath,
|
122 |
+
$certificatePassphrase,
|
123 |
+
Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy = null
|
124 |
+
) {
|
125 |
+
$this->_subscriptionId = $subscriptionId;
|
126 |
+
$this->_certificatePath = $certificatePath;
|
127 |
+
$this->_certificatePassphrase = $certificatePassphrase;
|
128 |
+
|
129 |
+
$this->_retryPolicy = $retryPolicy;
|
130 |
+
if (is_null($this->_retryPolicy)) {
|
131 |
+
$this->_retryPolicy = Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract::noRetry();
|
132 |
+
}
|
133 |
+
|
134 |
+
// Setup default Microsoft_Http_Client channel
|
135 |
+
$options = array(
|
136 |
+
'adapter' => 'Microsoft_Http_Client_Adapter_Socket',
|
137 |
+
'ssltransport' => 'ssl',
|
138 |
+
'sslcert' => $this->_certificatePath,
|
139 |
+
'sslpassphrase' => $this->_certificatePassphrase,
|
140 |
+
'sslusecontext' => true,
|
141 |
+
);
|
142 |
+
if (function_exists('curl_init')) {
|
143 |
+
// Set cURL options if cURL is used afterwards
|
144 |
+
$options['curloptions'] = array(
|
145 |
+
CURLOPT_FOLLOWLOCATION => true,
|
146 |
+
CURLOPT_TIMEOUT => 120,
|
147 |
+
);
|
148 |
+
}
|
149 |
+
$this->_httpClientChannel = new Microsoft_Http_Client(null, $options);
|
150 |
+
}
|
151 |
+
|
152 |
+
/**
|
153 |
+
* Set the HTTP client channel to use
|
154 |
+
*
|
155 |
+
* @param Microsoft_Http_Client_Adapter_Interface|string $adapterInstance Adapter instance or adapter class name.
|
156 |
+
*/
|
157 |
+
public function setHttpClientChannel($adapterInstance = 'Microsoft_Http_Client_Adapter_Socket')
|
158 |
+
{
|
159 |
+
$this->_httpClientChannel->setAdapter($adapterInstance);
|
160 |
+
}
|
161 |
+
|
162 |
+
/**
|
163 |
+
* Retrieve HTTP client channel
|
164 |
+
*
|
165 |
+
* @return Microsoft_Http_Client_Adapter_Interface
|
166 |
+
*/
|
167 |
+
public function getHttpClientChannel()
|
168 |
+
{
|
169 |
+
return $this->_httpClientChannel;
|
170 |
+
}
|
171 |
+
|
172 |
+
/**
|
173 |
+
* Returns the Windows Azure subscription ID
|
174 |
+
*
|
175 |
+
* @return string
|
176 |
+
*/
|
177 |
+
public function getSubscriptionId()
|
178 |
+
{
|
179 |
+
return $this->_subscriptionId;
|
180 |
+
}
|
181 |
+
|
182 |
+
/**
|
183 |
+
* Returns the last request ID.
|
184 |
+
*
|
185 |
+
* @return string
|
186 |
+
*/
|
187 |
+
public function getLastRequestId()
|
188 |
+
{
|
189 |
+
return $this->_lastRequestId;
|
190 |
+
}
|
191 |
+
|
192 |
+
/**
|
193 |
+
* Get base URL for creating requests
|
194 |
+
*
|
195 |
+
* @return string
|
196 |
+
*/
|
197 |
+
public function getBaseUrl()
|
198 |
+
{
|
199 |
+
return self::URL_MANAGEMENT . '/' . $this->_subscriptionId;
|
200 |
+
}
|
201 |
+
|
202 |
+
/**
|
203 |
+
* Perform request using Microsoft_Http_Client channel
|
204 |
+
*
|
205 |
+
* @param string $path Path
|
206 |
+
* @param array $query Query parameters
|
207 |
+
* @param string $httpVerb HTTP verb the request will use
|
208 |
+
* @param array $headers x-ms headers to add
|
209 |
+
* @param mixed $rawData Optional RAW HTTP data to be sent over the wire
|
210 |
+
* @return Microsoft_Http_Response
|
211 |
+
*/
|
212 |
+
protected function _performRequest(
|
213 |
+
$path = '/',
|
214 |
+
$query = array(),
|
215 |
+
$httpVerb = Microsoft_Http_Client::GET,
|
216 |
+
$headers = array(),
|
217 |
+
$rawData = null
|
218 |
+
) {
|
219 |
+
// Clean path
|
220 |
+
if (strpos($path, '/') !== 0) {
|
221 |
+
$path = '/' . $path;
|
222 |
+
}
|
223 |
+
|
224 |
+
// Clean headers
|
225 |
+
if (is_null($headers)) {
|
226 |
+
$headers = array();
|
227 |
+
}
|
228 |
+
|
229 |
+
// Ensure cUrl will also work correctly:
|
230 |
+
// - disable Content-Type if required
|
231 |
+
// - disable Expect: 100 Continue
|
232 |
+
if (!isset($headers["Content-Type"])) {
|
233 |
+
$headers["Content-Type"] = '';
|
234 |
+
}
|
235 |
+
//$headers["Expect"] = '';
|
236 |
+
|
237 |
+
// Add version header
|
238 |
+
$headers['x-ms-version'] = $this->_apiVersion;
|
239 |
+
|
240 |
+
// Generate URL and sign request
|
241 |
+
$requestUrl = $this->getBaseUrl() . rawurlencode($path);
|
242 |
+
$requestHeaders = $headers;
|
243 |
+
if (count($query) > 0) {
|
244 |
+
$queryString = '';
|
245 |
+
foreach ($query as $key => $value) {
|
246 |
+
$queryString .= ($queryString ? '&' : '?') . rawurlencode($key) . '=' . rawurlencode($value);
|
247 |
+
}
|
248 |
+
$requestUrl .= $queryString;
|
249 |
+
}
|
250 |
+
|
251 |
+
// Prepare request
|
252 |
+
$this->_httpClientChannel->resetParameters(true);
|
253 |
+
$this->_httpClientChannel->setUri($requestUrl);
|
254 |
+
$this->_httpClientChannel->setHeaders($requestHeaders);
|
255 |
+
$this->_httpClientChannel->setRawData($rawData);
|
256 |
+
|
257 |
+
// Execute request
|
258 |
+
$response = $this->_retryPolicy->execute(
|
259 |
+
array($this->_httpClientChannel, 'request'),
|
260 |
+
array($httpVerb)
|
261 |
+
);
|
262 |
+
|
263 |
+
// Store request id
|
264 |
+
$this->_lastRequestId = $response->getHeader('x-ms-request-id');
|
265 |
+
|
266 |
+
return $response;
|
267 |
+
}
|
268 |
+
|
269 |
+
/**
|
270 |
+
* Parse result from Microsoft_Http_Response
|
271 |
+
*
|
272 |
+
* @param Microsoft_Http_Response $response Response from HTTP call
|
273 |
+
* @return object
|
274 |
+
* @throws Microsoft_WindowsAzure_Exception
|
275 |
+
*/
|
276 |
+
protected function _parseResponse(Microsoft_Http_Response $response = null)
|
277 |
+
{
|
278 |
+
if (is_null($response)) {
|
279 |
+
throw new Microsoft_SqlAzure_Exception('Response should not be null.');
|
280 |
+
}
|
281 |
+
|
282 |
+
$xml = @simplexml_load_string($response->getBody());
|
283 |
+
|
284 |
+
if ($xml !== false) {
|
285 |
+
// Fetch all namespaces
|
286 |
+
$namespaces = array_merge($xml->getNamespaces(true), $xml->getDocNamespaces(true));
|
287 |
+
|
288 |
+
// Register all namespace prefixes
|
289 |
+
foreach ($namespaces as $prefix => $ns) {
|
290 |
+
if ($prefix != '') {
|
291 |
+
$xml->registerXPathNamespace($prefix, $ns);
|
292 |
+
}
|
293 |
+
}
|
294 |
+
}
|
295 |
+
|
296 |
+
return $xml;
|
297 |
+
}
|
298 |
+
|
299 |
+
/**
|
300 |
+
* Get error message from Microsoft_Http_Response
|
301 |
+
*
|
302 |
+
* @param Microsoft_Http_Response $response Repsonse
|
303 |
+
* @param string $alternativeError Alternative error message
|
304 |
+
* @return string
|
305 |
+
*/
|
306 |
+
protected function _getErrorMessage(Microsoft_Http_Response $response, $alternativeError = 'Unknown error.')
|
307 |
+
{
|
308 |
+
$response = $this->_parseResponse($response);
|
309 |
+
if ($response && $response->Message) {
|
310 |
+
return (string)$response->Message;
|
311 |
+
} else {
|
312 |
+
return $alternativeError;
|
313 |
+
}
|
314 |
+
}
|
315 |
+
|
316 |
+
/**
|
317 |
+
* The Create Server operation adds a new SQL Azure server to a subscription.
|
318 |
+
*
|
319 |
+
* @param string $administratorLogin Administrator login.
|
320 |
+
* @param string $administratorPassword Administrator password.
|
321 |
+
* @param string $location Location of the server.
|
322 |
+
* @return Microsoft_SqlAzure_Management_ServerInstance Server information.
|
323 |
+
* @throws Microsoft_SqlAzure_Management_Exception
|
324 |
+
*/
|
325 |
+
public function createServer($administratorLogin, $administratorPassword, $location)
|
326 |
+
{
|
327 |
+
if ($administratorLogin == '' || is_null($administratorLogin)) {
|
328 |
+
throw new Microsoft_SqlAzure_Management_Exception('Administrator login should be specified.');
|
329 |
+
}
|
330 |
+
if ($administratorPassword == '' || is_null($administratorPassword)) {
|
331 |
+
throw new Microsoft_SqlAzure_Management_Exception('Administrator password should be specified.');
|
332 |
+
}
|
333 |
+
if (is_null($location) && is_null($affinityGroup)) {
|
334 |
+
throw new Microsoft_SqlAzure_Management_Exception('Please specify a location for the server.');
|
335 |
+
}
|
336 |
+
|
337 |
+
$response = $this->_performRequest(self::OP_SERVERS, array(),
|
338 |
+
Microsoft_Http_Client::POST,
|
339 |
+
array('Content-Type' => 'application/xml; charset=utf-8'),
|
340 |
+
'<Server xmlns="http://schemas.microsoft.com/sqlazure/2010/12/"><AdministratorLogin>' . $administratorLogin . '</AdministratorLogin><AdministratorLoginPassword>' . $administratorPassword . '</AdministratorLoginPassword><Location>' . $location . '</Location></Server>');
|
341 |
+
|
342 |
+
if ($response->isSuccessful()) {
|
343 |
+
$xml = $this->_parseResponse($response);
|
344 |
+
|
345 |
+
return new Microsoft_SqlAzure_Management_ServerInstance(
|
346 |
+
(string)$xml,
|
347 |
+
$administratorLogin,
|
348 |
+
$location
|
349 |
+
);
|
350 |
+
} else {
|
351 |
+
throw new Microsoft_SqlAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
|
352 |
+
}
|
353 |
+
}
|
354 |
+
|
355 |
+
/**
|
356 |
+
* The Get Servers operation enumerates SQL Azure servers that are provisioned for a subscription.
|
357 |
+
*
|
358 |
+
* @return array An array of Microsoft_SqlAzure_Management_ServerInstance.
|
359 |
+
* @throws Microsoft_SqlAzure_Management_Exception
|
360 |
+
*/
|
361 |
+
public function listServers()
|
362 |
+
{
|
363 |
+
$response = $this->_performRequest(self::OP_SERVERS);
|
364 |
+
|
365 |
+
if ($response->isSuccessful()) {
|
366 |
+
$xml = $this->_parseResponse($response);
|
367 |
+
$xmlServices = null;
|
368 |
+
|
369 |
+
if (!$xml->Server) {
|
370 |
+
return array();
|
371 |
+
}
|
372 |
+
if (count($xml->Server) > 1) {
|
373 |
+
$xmlServices = $xml->Server;
|
374 |
+
} else {
|
375 |
+
$xmlServices = array($xml->Server);
|
376 |
+
}
|
377 |
+
|
378 |
+
$services = array();
|
379 |
+
if (!is_null($xmlServices)) {
|
380 |
+
for ($i = 0; $i < count($xmlServices); $i++) {
|
381 |
+
$services[] = new Microsoft_SqlAzure_Management_ServerInstance(
|
382 |
+
(string)$xmlServices[$i]->Name,
|
383 |
+
(string)$xmlServices[$i]->AdministratorLogin,
|
384 |
+
(string)$xmlServices[$i]->Location
|
385 |
+
);
|
386 |
+
}
|
387 |
+
}
|
388 |
+
return $services;
|
389 |
+
} else {
|
390 |
+
throw new Microsoft_SqlAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
|
391 |
+
}
|
392 |
+
}
|
393 |
+
|
394 |
+
/**
|
395 |
+
* The Drop Server operation drops a SQL Azure server from a subscription.
|
396 |
+
*
|
397 |
+
* @param string $serverName Server to drop.
|
398 |
+
* @throws Microsoft_SqlAzure_Management_Exception
|
399 |
+
*/
|
400 |
+
public function dropServer($serverName)
|
401 |
+
{
|
402 |
+
if ($serverName == '' || is_null($serverName)) {
|
403 |
+
throw new Microsoft_SqlAzure_Management_Exception('Server name should be specified.');
|
404 |
+
}
|
405 |
+
|
406 |
+
$response = $this->_performRequest(self::OP_SERVERS . '/' . $serverName, array(), Microsoft_Http_Client::DELETE);
|
407 |
+
|
408 |
+
if (!$response->isSuccessful()) {
|
409 |
+
throw new Microsoft_SqlAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
|
410 |
+
}
|
411 |
+
}
|
412 |
+
|
413 |
+
/**
|
414 |
+
* The Set Server Administrator Password operation sets the administrative password of a SQL Azure server for a subscription.
|
415 |
+
*
|
416 |
+
* @param string $serverName Server to set password for.
|
417 |
+
* @param string $administratorPassword Administrator password.
|
418 |
+
* @throws Microsoft_SqlAzure_Management_Exception
|
419 |
+
*/
|
420 |
+
public function setAdministratorPassword($serverName, $administratorPassword)
|
421 |
+
{
|
422 |
+
if ($serverName == '' || is_null($serverName)) {
|
423 |
+
throw new Microsoft_SqlAzure_Management_Exception('Server name should be specified.');
|
424 |
+
}
|
425 |
+
if ($administratorPassword == '' || is_null($administratorPassword)) {
|
426 |
+
throw new Microsoft_SqlAzure_Management_Exception('Administrator password should be specified.');
|
427 |
+
}
|
428 |
+
|
429 |
+
$response = $this->_performRequest(self::OP_SERVERS . '/' . $serverName, array('op' => 'ResetPassword'),
|
430 |
+
Microsoft_Http_Client::POST,
|
431 |
+
array('Content-Type' => 'application/xml; charset=utf-8'),
|
432 |
+
'<AdministratorLoginPassword xmlns="http://schemas.microsoft.com/sqlazure/2010/12/">' . $administratorPassword . '</AdministratorLoginPassword>');
|
433 |
+
|
434 |
+
if (!$response->isSuccessful()) {
|
435 |
+
throw new Microsoft_SqlAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
|
436 |
+
}
|
437 |
+
}
|
438 |
+
|
439 |
+
/**
|
440 |
+
* The Set Server Firewall Rule operation updates an existing firewall rule or adds a new firewall rule for a SQL Azure server that belongs to a subscription.
|
441 |
+
*
|
442 |
+
* @param string $serverName Server name.
|
443 |
+
* @param string $ruleName Firewall rule name.
|
444 |
+
* @param string $startIpAddress Start IP address.
|
445 |
+
* @param string $endIpAddress End IP address.
|
446 |
+
* @return Microsoft_SqlAzure_Management_FirewallRuleInstance
|
447 |
+
* @throws Microsoft_SqlAzure_Management_Exception
|
448 |
+
*/
|
449 |
+
public function createFirewallRule($serverName, $ruleName, $startIpAddress, $endIpAddress)
|
450 |
+
{
|
451 |
+
if ($serverName == '' || is_null($serverName)) {
|
452 |
+
throw new Microsoft_SqlAzure_Management_Exception('Server name should be specified.');
|
453 |
+
}
|
454 |
+
if ($ruleName == '' || is_null($ruleName)) {
|
455 |
+
throw new Microsoft_SqlAzure_Management_Exception('Rule name should be specified.');
|
456 |
+
}
|
457 |
+
if ($startIpAddress == '' || is_null($startIpAddress) || !filter_var($startIpAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
|
458 |
+
throw new Microsoft_SqlAzure_Management_Exception('Start IP address should be specified.');
|
459 |
+
}
|
460 |
+
if ($endIpAddress == '' || is_null($endIpAddress) || !filter_var($endIpAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
|
461 |
+
throw new Microsoft_SqlAzure_Management_Exception('End IP address should be specified.');
|
462 |
+
}
|
463 |
+
|
464 |
+
$response = $this->_performRequest(self::OP_SERVERS . '/' . $serverName . '/' . self::OP_FIREWALLRULES . '/' . $ruleName, array(),
|
465 |
+
Microsoft_Http_Client::PUT,
|
466 |
+
array('Content-Type' => 'application/xml; charset=utf-8'),
|
467 |
+
'<FirewallRule xmlns="http://schemas.microsoft.com/sqlazure/2010/12/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.microsoft.com/sqlazure/2010/12/ FirewallRule.xsd"><StartIpAddress>' . $startIpAddress . '</StartIpAddress><EndIpAddress>' . $endIpAddress . '</EndIpAddress></FirewallRule>');
|
468 |
+
|
469 |
+
if ($response->isSuccessful()) {
|
470 |
+
return new Microsoft_SqlAzure_Management_FirewallRuleInstance(
|
471 |
+
$ruleName,
|
472 |
+
$startIpAddress,
|
473 |
+
$endIpAddress
|
474 |
+
);
|
475 |
+
} else {
|
476 |
+
throw new Microsoft_SqlAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
|
477 |
+
}
|
478 |
+
}
|
479 |
+
|
480 |
+
/**
|
481 |
+
* The Get Server Firewall Rules operation retrieves a list of all the firewall rules for a SQL Azure server that belongs to a subscription.
|
482 |
+
*
|
483 |
+
* @param string $serverName Server name.
|
484 |
+
* @return Array of Microsoft_SqlAzure_Management_FirewallRuleInstance.
|
485 |
+
* @throws Microsoft_SqlAzure_Management_Exception
|
486 |
+
*/
|
487 |
+
public function listFirewallRules($serverName)
|
488 |
+
{
|
489 |
+
if ($serverName == '' || is_null($serverName)) {
|
490 |
+
throw new Microsoft_SqlAzure_Management_Exception('Server name should be specified.');
|
491 |
+
}
|
492 |
+
|
493 |
+
$response = $this->_performRequest(self::OP_SERVERS . '/' . $serverName . '/' . self::OP_FIREWALLRULES);
|
494 |
+
|
495 |
+
if ($response->isSuccessful()) {
|
496 |
+
$xml = $this->_parseResponse($response);
|
497 |
+
$xmlServices = null;
|
498 |
+
|
499 |
+
if (!$xml->FirewallRule) {
|
500 |
+
return array();
|
501 |
+
}
|
502 |
+
if (count($xml->FirewallRule) > 1) {
|
503 |
+
$xmlServices = $xml->FirewallRule;
|
504 |
+
} else {
|
505 |
+
$xmlServices = array($xml->FirewallRule);
|
506 |
+
}
|
507 |
+
|
508 |
+
$services = array();
|
509 |
+
if (!is_null($xmlServices)) {
|
510 |
+
for ($i = 0; $i < count($xmlServices); $i++) {
|
511 |
+
$services[] = new Microsoft_SqlAzure_Management_FirewallRuleInstance(
|
512 |
+
(string)$xmlServices[$i]->Name,
|
513 |
+
(string)$xmlServices[$i]->StartIpAddress,
|
514 |
+
(string)$xmlServices[$i]->EndIpAddress
|
515 |
+
);
|
516 |
+
}
|
517 |
+
}
|
518 |
+
return $services;
|
519 |
+
} else {
|
520 |
+
throw new Microsoft_SqlAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
|
521 |
+
}
|
522 |
+
}
|
523 |
+
|
524 |
+
/**
|
525 |
+
* The Delete Server Firewall Rule operation deletes a firewall rule from a SQL Azure server that belongs to a subscription.
|
526 |
+
*
|
527 |
+
* @param string $serverName Server name.
|
528 |
+
* @param string $ruleName Rule name.
|
529 |
+
* @throws Microsoft_SqlAzure_Management_Exception
|
530 |
+
*/
|
531 |
+
public function deleteFirewallRule($serverName, $ruleName)
|
532 |
+
{
|
533 |
+
if ($serverName == '' || is_null($serverName)) {
|
534 |
+
throw new Microsoft_SqlAzure_Management_Exception('Server name should be specified.');
|
535 |
+
}
|
536 |
+
if ($ruleName == '' || is_null($ruleName)) {
|
537 |
+
throw new Microsoft_SqlAzure_Management_Exception('Rule name should be specified.');
|
538 |
+
}
|
539 |
+
|
540 |
+
$response = $this->_performRequest(self::OP_SERVERS . '/' . $serverName . '/' . self::OP_FIREWALLRULES . '/' . $ruleName, array(),
|
541 |
+
Microsoft_Http_Client::DELETE);
|
542 |
+
|
543 |
+
if (!$response->isSuccessful()) {
|
544 |
+
throw new Microsoft_SqlAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
|
545 |
+
}
|
546 |
+
}
|
547 |
+
|
548 |
+
/**
|
549 |
+
* Creates a firewall rule for Microsoft Services. This is required if access to SQL Azure is required from other services like Windows Azure.
|
550 |
+
*
|
551 |
+
* @param string $serverName Server name.
|
552 |
+
* @param boolean $allowAccess Allow access from other Microsoft Services?
|
553 |
+
* @throws Microsoft_SqlAzure_Management_Exception
|
554 |
+
*/
|
555 |
+
public function createFirewallRuleForMicrosoftServices($serverName, $allowAccess)
|
556 |
+
{
|
557 |
+
if ($allowAccess) {
|
558 |
+
$this->createFirewallRule($serverName, 'MicrosoftServices', '0.0.0.0', '0.0.0.0');
|
559 |
+
} else {
|
560 |
+
$this->deleteFirewallRule($serverName, 'MicrosoftServices');
|
561 |
+
}
|
562 |
+
}
|
563 |
+
|
564 |
+
}
|
libs/Microsoft/SqlAzure/Management/Exception.php
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_WindowsAzure
|
30 |
+
* @subpackage Management
|
31 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
32 |
+
* @license http://phpazure.codeplex.com/license
|
33 |
+
* @version $Id: Storage.php 45989 2010-05-03 12:19:10Z unknown $
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @see Microsoft_AutoLoader
|
38 |
+
*/
|
39 |
+
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
40 |
+
|
41 |
+
/**
|
42 |
+
* @category Microsoft
|
43 |
+
* @package Microsoft_SqlAzure
|
44 |
+
* @subpackage Management
|
45 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
46 |
+
* @license http://phpazure.codeplex.com/license
|
47 |
+
*/
|
48 |
+
class Microsoft_SqlAzure_Management_Exception
|
49 |
+
extends Microsoft_SqlAzure_Exception
|
50 |
+
{
|
51 |
+
}
|
libs/Microsoft/SqlAzure/Management/FirewallRuleInstance.php
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_WindowsAzure
|
30 |
+
* @subpackage Management
|
31 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
32 |
+
* @license http://phpazure.codeplex.com/license
|
33 |
+
* @version $Id: BlobInstance.php 53615 2010-11-16 20:45:11Z unknown $
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @see Microsoft_AutoLoader
|
38 |
+
*/
|
39 |
+
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
40 |
+
|
41 |
+
/**
|
42 |
+
* @category Microsoft
|
43 |
+
* @package Microsoft_SqlAzure
|
44 |
+
* @subpackage Management
|
45 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
46 |
+
* @license http://phpazure.codeplex.com/license
|
47 |
+
*
|
48 |
+
* @property string $Name The name of the firewall rule.
|
49 |
+
* @property string $StartIpAddress The start IP address.
|
50 |
+
* @property string $EndIpAddress The end IP address.
|
51 |
+
*/
|
52 |
+
class Microsoft_SqlAzure_Management_FirewallRuleInstance
|
53 |
+
extends Microsoft_SqlAzure_Management_ServiceEntityAbstract
|
54 |
+
{
|
55 |
+
/**
|
56 |
+
* Constructor
|
57 |
+
*
|
58 |
+
* @param string $name The name of the firewall rule.
|
59 |
+
* @param string $startIpAddress The start IP address.
|
60 |
+
* @param string $endIpAddress The end IP address.
|
61 |
+
*/
|
62 |
+
public function __construct($name, $startIpAddress, $endIpAddress)
|
63 |
+
{
|
64 |
+
$this->_data = array(
|
65 |
+
'name' => $name,
|
66 |
+
'startipaddress' => $startIpAddress,
|
67 |
+
'endipaddress' => $endIpAddress
|
68 |
+
);
|
69 |
+
}
|
70 |
+
}
|
libs/Microsoft/SqlAzure/Management/ServerInstance.php
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_WindowsAzure
|
30 |
+
* @subpackage Management
|
31 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
32 |
+
* @license http://phpazure.codeplex.com/license
|
33 |
+
* @version $Id: BlobInstance.php 53615 2010-11-16 20:45:11Z unknown $
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @see Microsoft_AutoLoader
|
38 |
+
*/
|
39 |
+
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
40 |
+
|
41 |
+
/**
|
42 |
+
* @category Microsoft
|
43 |
+
* @package Microsoft_SqlAzure
|
44 |
+
* @subpackage Management
|
45 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
46 |
+
* @license http://phpazure.codeplex.com/license
|
47 |
+
*
|
48 |
+
* @property string $Name The name of the server.
|
49 |
+
* @property string $DnsName The DNS name of the server.
|
50 |
+
* @property string $AdministratorLogin The administrator login.
|
51 |
+
* @property string $Location The location of the server in Windows Azure.
|
52 |
+
*/
|
53 |
+
class Microsoft_SqlAzure_Management_ServerInstance
|
54 |
+
extends Microsoft_SqlAzure_Management_ServiceEntityAbstract
|
55 |
+
{
|
56 |
+
/**
|
57 |
+
* Constructor
|
58 |
+
*
|
59 |
+
* @param string $name The name of the server.
|
60 |
+
* @param string $administratorLogin The administrator login.
|
61 |
+
* @param string $location The location of the server in Windows Azure.
|
62 |
+
*/
|
63 |
+
public function __construct($name, $administratorLogin, $location)
|
64 |
+
{
|
65 |
+
$this->_data = array(
|
66 |
+
'name' => $name,
|
67 |
+
'dnsname' => $name . '.database.windows.net',
|
68 |
+
'administratorlogin' => $administratorLogin,
|
69 |
+
'location' => $location
|
70 |
+
);
|
71 |
+
}
|
72 |
+
}
|
libs/Microsoft/SqlAzure/Management/ServiceEntityAbstract.php
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_WindowsAzure
|
30 |
+
* @subpackage Management
|
31 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
32 |
+
* @license http://phpazure.codeplex.com/license
|
33 |
+
* @version $Id: BlobInstance.php 53615 2010-11-16 20:45:11Z unknown $
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @see Microsoft_AutoLoader
|
38 |
+
*/
|
39 |
+
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
40 |
+
|
41 |
+
/**
|
42 |
+
* @category Microsoft
|
43 |
+
* @package Microsoft_SqlAzure
|
44 |
+
* @subpackage Management
|
45 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
46 |
+
* @license http://phpazure.codeplex.com/license
|
47 |
+
*/
|
48 |
+
abstract class Microsoft_SqlAzure_Management_ServiceEntityAbstract
|
49 |
+
{
|
50 |
+
/**
|
51 |
+
* Data
|
52 |
+
*
|
53 |
+
* @var array
|
54 |
+
*/
|
55 |
+
protected $_data = null;
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Magic overload for setting properties
|
59 |
+
*
|
60 |
+
* @param string $name Name of the property
|
61 |
+
* @param string $value Value to set
|
62 |
+
*/
|
63 |
+
public function __set($name, $value) {
|
64 |
+
if (array_key_exists(strtolower($name), $this->_data)) {
|
65 |
+
$this->_data[strtolower($name)] = $value;
|
66 |
+
return;
|
67 |
+
}
|
68 |
+
|
69 |
+
throw new Microsoft_SqlAzure_Management_Exception("Unknown property: " . $name);
|
70 |
+
}
|
71 |
+
|
72 |
+
/**
|
73 |
+
* Magic overload for getting properties
|
74 |
+
*
|
75 |
+
* @param string $name Name of the property
|
76 |
+
*/
|
77 |
+
public function __get($name) {
|
78 |
+
if (array_key_exists(strtolower($name), $this->_data)) {
|
79 |
+
return $this->_data[strtolower($name)];
|
80 |
+
}
|
81 |
+
|
82 |
+
throw new Microsoft_SqlAzure_Management_Exception("Unknown property: " . $name);
|
83 |
+
}
|
84 |
+
}
|
libs/Microsoft/Uri.php
CHANGED
@@ -1,193 +1,193 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Zend Framework
|
4 |
-
*
|
5 |
-
* LICENSE
|
6 |
-
*
|
7 |
-
* This source file is subject to the new BSD license that is bundled
|
8 |
-
* with this package in the file LICENSE.txt.
|
9 |
-
* It is also available through the world-wide-web at this URL:
|
10 |
-
* http://framework.zend.com/license/new-bsd
|
11 |
-
* If you did not receive a copy of the license and are unable to
|
12 |
-
* obtain it through the world-wide-web, please send an email
|
13 |
-
* to license@zend.com so we can send you a copy immediately.
|
14 |
-
*
|
15 |
-
* @category Microsoft
|
16 |
-
* @package Microsoft_Uri
|
17 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
18 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
19 |
-
* @version $Id: Uri.php 18950 2009-11-12 15:37:56Z alexander $
|
20 |
-
*/
|
21 |
-
|
22 |
-
/**
|
23 |
-
* @see Microsoft_AutoLoader
|
24 |
-
*/
|
25 |
-
require_once dirname(__FILE__) . '/AutoLoader.php';
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Abstract class for all Microsoft_Uri handlers
|
29 |
-
*
|
30 |
-
* @category Microsoft
|
31 |
-
* @package Microsoft_Uri
|
32 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
33 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
34 |
-
*/
|
35 |
-
abstract class Microsoft_Uri
|
36 |
-
{
|
37 |
-
/**
|
38 |
-
* Scheme of this URI (http, ftp, etc.)
|
39 |
-
*
|
40 |
-
* @var string
|
41 |
-
*/
|
42 |
-
protected $_scheme = '';
|
43 |
-
|
44 |
-
/**
|
45 |
-
* Global configuration array
|
46 |
-
*
|
47 |
-
* @var array
|
48 |
-
*/
|
49 |
-
static protected $_config = array(
|
50 |
-
'allow_unwise' => false
|
51 |
-
);
|
52 |
-
|
53 |
-
/**
|
54 |
-
* Return a string representation of this URI.
|
55 |
-
*
|
56 |
-
* @see getUri()
|
57 |
-
* @return string
|
58 |
-
*/
|
59 |
-
public function __toString()
|
60 |
-
{
|
61 |
-
return $this->getUri();
|
62 |
-
}
|
63 |
-
|
64 |
-
/**
|
65 |
-
* Convenience function, checks that a $uri string is well-formed
|
66 |
-
* by validating it but not returning an object. Returns TRUE if
|
67 |
-
* $uri is a well-formed URI, or FALSE otherwise.
|
68 |
-
*
|
69 |
-
* @param string $uri The URI to check
|
70 |
-
* @return boolean
|
71 |
-
*/
|
72 |
-
public static function check($uri)
|
73 |
-
{
|
74 |
-
try {
|
75 |
-
$uri = self::factory($uri);
|
76 |
-
} catch (Exception $e) {
|
77 |
-
return false;
|
78 |
-
}
|
79 |
-
|
80 |
-
return $uri->valid();
|
81 |
-
}
|
82 |
-
|
83 |
-
/**
|
84 |
-
* Create a new Microsoft_Uri object for a URI. If building a new URI, then $uri should contain
|
85 |
-
* only the scheme (http, ftp, etc). Otherwise, supply $uri with the complete URI.
|
86 |
-
*
|
87 |
-
* @param string $uri The URI form which a Microsoft_Uri instance is created
|
88 |
-
* @throws Microsoft_Uri_Exception When an empty string was supplied for the scheme
|
89 |
-
* @throws Microsoft_Uri_Exception When an illegal scheme is supplied
|
90 |
-
* @throws Microsoft_Uri_Exception When the scheme is not supported
|
91 |
-
* @return Microsoft_Uri
|
92 |
-
* @link http://www.faqs.org/rfcs/rfc2396.html
|
93 |
-
*/
|
94 |
-
public static function factory($uri = 'http')
|
95 |
-
{
|
96 |
-
// Separate the scheme from the scheme-specific parts
|
97 |
-
$uri = explode(':', $uri, 2);
|
98 |
-
$scheme = strtolower($uri[0]);
|
99 |
-
$schemeSpecific = isset($uri[1]) === true ? $uri[1] : '';
|
100 |
-
|
101 |
-
if (strlen($scheme) === 0) {
|
102 |
-
require_once 'Microsoft/Uri/Exception.php';
|
103 |
-
throw new Microsoft_Uri_Exception('An empty string was supplied for the scheme');
|
104 |
-
}
|
105 |
-
|
106 |
-
// Security check: $scheme is used to load a class file, so only alphanumerics are allowed.
|
107 |
-
if (ctype_alnum($scheme) === false) {
|
108 |
-
require_once 'Microsoft/Uri/Exception.php';
|
109 |
-
throw new Microsoft_Uri_Exception('Illegal scheme supplied, only alphanumeric characters are permitted');
|
110 |
-
}
|
111 |
-
|
112 |
-
/**
|
113 |
-
* Create a new Microsoft_Uri object for the $uri. If a subclass of Microsoft_Uri exists for the
|
114 |
-
* scheme, return an instance of that class. Otherwise, a Microsoft_Uri_Exception is thrown.
|
115 |
-
*/
|
116 |
-
switch ($scheme) {
|
117 |
-
case 'http':
|
118 |
-
// Break intentionally omitted
|
119 |
-
case 'https':
|
120 |
-
$className = 'Microsoft_Uri_Http';
|
121 |
-
break;
|
122 |
-
|
123 |
-
case 'mailto':
|
124 |
-
// TODO
|
125 |
-
default:
|
126 |
-
require_once 'Microsoft/Uri/Exception.php';
|
127 |
-
throw new Microsoft_Uri_Exception("Scheme \"$scheme\" is not supported");
|
128 |
-
break;
|
129 |
-
}
|
130 |
-
|
131 |
-
if (!class_exists($className)) {
|
132 |
-
require_once str_replace('_', '/', $className) . '.php';
|
133 |
-
}
|
134 |
-
$schemeHandler = new $className($scheme, $schemeSpecific);
|
135 |
-
|
136 |
-
return $schemeHandler;
|
137 |
-
}
|
138 |
-
|
139 |
-
/**
|
140 |
-
* Get the URI's scheme
|
141 |
-
*
|
142 |
-
* @return string|false Scheme or false if no scheme is set.
|
143 |
-
*/
|
144 |
-
public function getScheme()
|
145 |
-
{
|
146 |
-
if (empty($this->_scheme) === false) {
|
147 |
-
return $this->_scheme;
|
148 |
-
} else {
|
149 |
-
return false;
|
150 |
-
}
|
151 |
-
}
|
152 |
-
|
153 |
-
/**
|
154 |
-
* Set global configuration options
|
155 |
-
*
|
156 |
-
* @param Microsoft_Config|array $config
|
157 |
-
*/
|
158 |
-
static public function setConfig($config)
|
159 |
-
{
|
160 |
-
if ($config instanceof Microsoft_Config) {
|
161 |
-
$config = $config->toArray();
|
162 |
-
} elseif (!is_array($config)) {
|
163 |
-
throw new Microsoft_Uri_Exception("Config must be an array or an instance of Microsoft_Config.");
|
164 |
-
}
|
165 |
-
|
166 |
-
foreach ($config as $k => $v) {
|
167 |
-
self::$_config[$k] = $v;
|
168 |
-
}
|
169 |
-
}
|
170 |
-
|
171 |
-
/**
|
172 |
-
* Microsoft_Uri and its subclasses cannot be instantiated directly.
|
173 |
-
* Use Microsoft_Uri::factory() to return a new Microsoft_Uri object.
|
174 |
-
*
|
175 |
-
* @param string $scheme The scheme of the URI
|
176 |
-
* @param string $schemeSpecific The scheme-specific part of the URI
|
177 |
-
*/
|
178 |
-
abstract protected function __construct($scheme, $schemeSpecific = '');
|
179 |
-
|
180 |
-
/**
|
181 |
-
* Return a string representation of this URI.
|
182 |
-
*
|
183 |
-
* @return string
|
184 |
-
*/
|
185 |
-
abstract public function getUri();
|
186 |
-
|
187 |
-
/**
|
188 |
-
* Returns TRUE if this URI is valid, or FALSE otherwise.
|
189 |
-
*
|
190 |
-
* @return boolean
|
191 |
-
*/
|
192 |
-
abstract public function valid();
|
193 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Zend Framework
|
4 |
+
*
|
5 |
+
* LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the new BSD license that is bundled
|
8 |
+
* with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://framework.zend.com/license/new-bsd
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@zend.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* @category Microsoft
|
16 |
+
* @package Microsoft_Uri
|
17 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
18 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
19 |
+
* @version $Id: Uri.php 18950 2009-11-12 15:37:56Z alexander $
|
20 |
+
*/
|
21 |
+
|
22 |
+
/**
|
23 |
+
* @see Microsoft_AutoLoader
|
24 |
+
*/
|
25 |
+
require_once dirname(__FILE__) . '/AutoLoader.php';
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Abstract class for all Microsoft_Uri handlers
|
29 |
+
*
|
30 |
+
* @category Microsoft
|
31 |
+
* @package Microsoft_Uri
|
32 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
33 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
34 |
+
*/
|
35 |
+
abstract class Microsoft_Uri
|
36 |
+
{
|
37 |
+
/**
|
38 |
+
* Scheme of this URI (http, ftp, etc.)
|
39 |
+
*
|
40 |
+
* @var string
|
41 |
+
*/
|
42 |
+
protected $_scheme = '';
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Global configuration array
|
46 |
+
*
|
47 |
+
* @var array
|
48 |
+
*/
|
49 |
+
static protected $_config = array(
|
50 |
+
'allow_unwise' => false
|
51 |
+
);
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Return a string representation of this URI.
|
55 |
+
*
|
56 |
+
* @see getUri()
|
57 |
+
* @return string
|
58 |
+
*/
|
59 |
+
public function __toString()
|
60 |
+
{
|
61 |
+
return $this->getUri();
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Convenience function, checks that a $uri string is well-formed
|
66 |
+
* by validating it but not returning an object. Returns TRUE if
|
67 |
+
* $uri is a well-formed URI, or FALSE otherwise.
|
68 |
+
*
|
69 |
+
* @param string $uri The URI to check
|
70 |
+
* @return boolean
|
71 |
+
*/
|
72 |
+
public static function check($uri)
|
73 |
+
{
|
74 |
+
try {
|
75 |
+
$uri = self::factory($uri);
|
76 |
+
} catch (Exception $e) {
|
77 |
+
return false;
|
78 |
+
}
|
79 |
+
|
80 |
+
return $uri->valid();
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Create a new Microsoft_Uri object for a URI. If building a new URI, then $uri should contain
|
85 |
+
* only the scheme (http, ftp, etc). Otherwise, supply $uri with the complete URI.
|
86 |
+
*
|
87 |
+
* @param string $uri The URI form which a Microsoft_Uri instance is created
|
88 |
+
* @throws Microsoft_Uri_Exception When an empty string was supplied for the scheme
|
89 |
+
* @throws Microsoft_Uri_Exception When an illegal scheme is supplied
|
90 |
+
* @throws Microsoft_Uri_Exception When the scheme is not supported
|
91 |
+
* @return Microsoft_Uri
|
92 |
+
* @link http://www.faqs.org/rfcs/rfc2396.html
|
93 |
+
*/
|
94 |
+
public static function factory($uri = 'http')
|
95 |
+
{
|
96 |
+
// Separate the scheme from the scheme-specific parts
|
97 |
+
$uri = explode(':', $uri, 2);
|
98 |
+
$scheme = strtolower($uri[0]);
|
99 |
+
$schemeSpecific = isset($uri[1]) === true ? $uri[1] : '';
|
100 |
+
|
101 |
+
if (strlen($scheme) === 0) {
|
102 |
+
require_once 'Microsoft/Uri/Exception.php';
|
103 |
+
throw new Microsoft_Uri_Exception('An empty string was supplied for the scheme');
|
104 |
+
}
|
105 |
+
|
106 |
+
// Security check: $scheme is used to load a class file, so only alphanumerics are allowed.
|
107 |
+
if (ctype_alnum($scheme) === false) {
|
108 |
+
require_once 'Microsoft/Uri/Exception.php';
|
109 |
+
throw new Microsoft_Uri_Exception('Illegal scheme supplied, only alphanumeric characters are permitted');
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Create a new Microsoft_Uri object for the $uri. If a subclass of Microsoft_Uri exists for the
|
114 |
+
* scheme, return an instance of that class. Otherwise, a Microsoft_Uri_Exception is thrown.
|
115 |
+
*/
|
116 |
+
switch ($scheme) {
|
117 |
+
case 'http':
|
118 |
+
// Break intentionally omitted
|
119 |
+
case 'https':
|
120 |
+
$className = 'Microsoft_Uri_Http';
|
121 |
+
break;
|
122 |
+
|
123 |
+
case 'mailto':
|
124 |
+
// TODO
|
125 |
+
default:
|
126 |
+
require_once 'Microsoft/Uri/Exception.php';
|
127 |
+
throw new Microsoft_Uri_Exception("Scheme \"$scheme\" is not supported");
|
128 |
+
break;
|
129 |
+
}
|
130 |
+
|
131 |
+
if (!class_exists($className)) {
|
132 |
+
require_once str_replace('_', '/', $className) . '.php';
|
133 |
+
}
|
134 |
+
$schemeHandler = new $className($scheme, $schemeSpecific);
|
135 |
+
|
136 |
+
return $schemeHandler;
|
137 |
+
}
|
138 |
+
|
139 |
+
/**
|
140 |
+
* Get the URI's scheme
|
141 |
+
*
|
142 |
+
* @return string|false Scheme or false if no scheme is set.
|
143 |
+
*/
|
144 |
+
public function getScheme()
|
145 |
+
{
|
146 |
+
if (empty($this->_scheme) === false) {
|
147 |
+
return $this->_scheme;
|
148 |
+
} else {
|
149 |
+
return false;
|
150 |
+
}
|
151 |
+
}
|
152 |
+
|
153 |
+
/**
|
154 |
+
* Set global configuration options
|
155 |
+
*
|
156 |
+
* @param Microsoft_Config|array $config
|
157 |
+
*/
|
158 |
+
static public function setConfig($config)
|
159 |
+
{
|
160 |
+
if ($config instanceof Microsoft_Config) {
|
161 |
+
$config = $config->toArray();
|
162 |
+
} elseif (!is_array($config)) {
|
163 |
+
throw new Microsoft_Uri_Exception("Config must be an array or an instance of Microsoft_Config.");
|
164 |
+
}
|
165 |
+
|
166 |
+
foreach ($config as $k => $v) {
|
167 |
+
self::$_config[$k] = $v;
|
168 |
+
}
|
169 |
+
}
|
170 |
+
|
171 |
+
/**
|
172 |
+
* Microsoft_Uri and its subclasses cannot be instantiated directly.
|
173 |
+
* Use Microsoft_Uri::factory() to return a new Microsoft_Uri object.
|
174 |
+
*
|
175 |
+
* @param string $scheme The scheme of the URI
|
176 |
+
* @param string $schemeSpecific The scheme-specific part of the URI
|
177 |
+
*/
|
178 |
+
abstract protected function __construct($scheme, $schemeSpecific = '');
|
179 |
+
|
180 |
+
/**
|
181 |
+
* Return a string representation of this URI.
|
182 |
+
*
|
183 |
+
* @return string
|
184 |
+
*/
|
185 |
+
abstract public function getUri();
|
186 |
+
|
187 |
+
/**
|
188 |
+
* Returns TRUE if this URI is valid, or FALSE otherwise.
|
189 |
+
*
|
190 |
+
* @return boolean
|
191 |
+
*/
|
192 |
+
abstract public function valid();
|
193 |
+
}
|
libs/Microsoft/Uri/Exception.php
CHANGED
@@ -1,37 +1,37 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Zend Framework
|
4 |
-
*
|
5 |
-
* LICENSE
|
6 |
-
*
|
7 |
-
* This source file is subject to the new BSD license that is bundled
|
8 |
-
* with this package in the file LICENSE.txt.
|
9 |
-
* It is also available through the world-wide-web at this URL:
|
10 |
-
* http://framework.zend.com/license/new-bsd
|
11 |
-
* If you did not receive a copy of the license and are unable to
|
12 |
-
* obtain it through the world-wide-web, please send an email
|
13 |
-
* to license@zend.com so we can send you a copy immediately.
|
14 |
-
*
|
15 |
-
* @category Microsoft
|
16 |
-
* @package Microsoft_Uri
|
17 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
18 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
19 |
-
* @version $Id: Exception.php 16208 2009-06-21 19:19:26Z thomas $
|
20 |
-
*/
|
21 |
-
|
22 |
-
/**
|
23 |
-
* @see Microsoft_AutoLoader
|
24 |
-
*/
|
25 |
-
require_once dirname(__FILE__) . '/../AutoLoader.php';
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Exceptions for Microsoft_Uri
|
29 |
-
*
|
30 |
-
* @category Microsoft
|
31 |
-
* @package Microsoft_Uri
|
32 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
33 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
34 |
-
*/
|
35 |
-
class Microsoft_Uri_Exception extends Microsoft_Exception
|
36 |
-
{
|
37 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Zend Framework
|
4 |
+
*
|
5 |
+
* LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the new BSD license that is bundled
|
8 |
+
* with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://framework.zend.com/license/new-bsd
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@zend.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* @category Microsoft
|
16 |
+
* @package Microsoft_Uri
|
17 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
18 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
19 |
+
* @version $Id: Exception.php 16208 2009-06-21 19:19:26Z thomas $
|
20 |
+
*/
|
21 |
+
|
22 |
+
/**
|
23 |
+
* @see Microsoft_AutoLoader
|
24 |
+
*/
|
25 |
+
require_once dirname(__FILE__) . '/../AutoLoader.php';
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Exceptions for Microsoft_Uri
|
29 |
+
*
|
30 |
+
* @category Microsoft
|
31 |
+
* @package Microsoft_Uri
|
32 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
33 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
34 |
+
*/
|
35 |
+
class Microsoft_Uri_Exception extends Microsoft_Exception
|
36 |
+
{
|
37 |
+
}
|
libs/Microsoft/Uri/Http.php
CHANGED
@@ -1,761 +1,761 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Zend Framework
|
4 |
-
*
|
5 |
-
* LICENSE
|
6 |
-
*
|
7 |
-
* This source file is subject to the new BSD license that is bundled
|
8 |
-
* with this package in the file LICENSE.txt.
|
9 |
-
* It is also available through the world-wide-web at this URL:
|
10 |
-
* http://framework.zend.com/license/new-bsd
|
11 |
-
* If you did not receive a copy of the license and are unable to
|
12 |
-
* obtain it through the world-wide-web, please send an email
|
13 |
-
* to license@zend.com so we can send you a copy immediately.
|
14 |
-
*
|
15 |
-
* @category Microsoft
|
16 |
-
* @package Microsoft_Uri
|
17 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
18 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
19 |
-
* @version $Id: Http.php 19041 2009-11-19 15:19:07Z sgehrig $
|
20 |
-
*/
|
21 |
-
|
22 |
-
/**
|
23 |
-
* @see Microsoft_AutoLoader
|
24 |
-
*/
|
25 |
-
require_once dirname(__FILE__) . '/../AutoLoader.php';
|
26 |
-
|
27 |
-
/**
|
28 |
-
* HTTP(S) URI handler
|
29 |
-
*
|
30 |
-
* @category Microsoft
|
31 |
-
* @package Microsoft_Uri
|
32 |
-
* @uses Microsoft_Uri
|
33 |
-
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
34 |
-
* @license http://framework.zend.com/license/new-bsd New BSD License
|
35 |
-
*/
|
36 |
-
class Microsoft_Uri_Http extends Microsoft_Uri
|
37 |
-
{
|
38 |
-
/**
|
39 |
-
* Character classes for validation regular expressions
|
40 |
-
*/
|
41 |
-
const CHAR_ALNUM = 'A-Za-z0-9';
|
42 |
-
const CHAR_MARK = '-_.!~*\'()\[\]';
|
43 |
-
const CHAR_RESERVED = ';\/?:@&=+$,';
|
44 |
-
const CHAR_SEGMENT = ':@&=+$,;';
|
45 |
-
const CHAR_UNWISE = '{}|\\\\^`';
|
46 |
-
|
47 |
-
/**
|
48 |
-
* HTTP username
|
49 |
-
*
|
50 |
-
* @var string
|
51 |
-
*/
|
52 |
-
protected $_username = '';
|
53 |
-
|
54 |
-
/**
|
55 |
-
* HTTP password
|
56 |
-
*
|
57 |
-
* @var string
|
58 |
-
*/
|
59 |
-
protected $_password = '';
|
60 |
-
|
61 |
-
/**
|
62 |
-
* HTTP host
|
63 |
-
*
|
64 |
-
* @var string
|
65 |
-
*/
|
66 |
-
protected $_host = '';
|
67 |
-
|
68 |
-
/**
|
69 |
-
* HTTP post
|
70 |
-
*
|
71 |
-
* @var string
|
72 |
-
*/
|
73 |
-
protected $_port = '';
|
74 |
-
|
75 |
-
/**
|
76 |
-
* HTTP part
|
77 |
-
*
|
78 |
-
* @var string
|
79 |
-
*/
|
80 |
-
protected $_path = '';
|
81 |
-
|
82 |
-
/**
|
83 |
-
* HTTP query
|
84 |
-
*
|
85 |
-
* @var string
|
86 |
-
*/
|
87 |
-
protected $_query = '';
|
88 |
-
|
89 |
-
/**
|
90 |
-
* HTTP fragment
|
91 |
-
*
|
92 |
-
* @var string
|
93 |
-
*/
|
94 |
-
protected $_fragment = '';
|
95 |
-
|
96 |
-
/**
|
97 |
-
* Regular expression grammar rules for validation; values added by constructor
|
98 |
-
*
|
99 |
-
* @var array
|
100 |
-
*/
|
101 |
-
protected $_regex = array();
|
102 |
-
|
103 |
-
/**
|
104 |
-
* Constructor accepts a string $scheme (e.g., http, https) and a scheme-specific part of the URI
|
105 |
-
* (e.g., example.com/path/to/resource?query=param#fragment)
|
106 |
-
*
|
107 |
-
* @param string $scheme The scheme of the URI
|
108 |
-
* @param string $schemeSpecific The scheme-specific part of the URI
|
109 |
-
* @throws Microsoft_Uri_Exception When the URI is not valid
|
110 |
-
*/
|
111 |
-
protected function __construct($scheme, $schemeSpecific = '')
|
112 |
-
{
|
113 |
-
// Set the scheme
|
114 |
-
$this->_scheme = $scheme;
|
115 |
-
|
116 |
-
// Set up grammar rules for validation via regular expressions. These
|
117 |
-
// are to be used with slash-delimited regular expression strings.
|
118 |
-
|
119 |
-
// Escaped special characters (eg. '%25' for '%')
|
120 |
-
$this->_regex['escaped'] = '%[[:xdigit:]]{2}';
|
121 |
-
|
122 |
-
// Unreserved characters
|
123 |
-
$this->_regex['unreserved'] = '[' . self::CHAR_ALNUM . self::CHAR_MARK . ']';
|
124 |
-
|
125 |
-
// Segment can use escaped, unreserved or a set of additional chars
|
126 |
-
$this->_regex['segment'] = '(?:' . $this->_regex['escaped'] . '|[' .
|
127 |
-
self::CHAR_ALNUM . self::CHAR_MARK . self::CHAR_SEGMENT . '])*';
|
128 |
-
|
129 |
-
// Path can be a series of segmets char strings seperated by '/'
|
130 |
-
$this->_regex['path'] = '(?:\/(?:' . $this->_regex['segment'] . ')?)+';
|
131 |
-
|
132 |
-
// URI characters can be escaped, alphanumeric, mark or reserved chars
|
133 |
-
$this->_regex['uric'] = '(?:' . $this->_regex['escaped'] . '|[' .
|
134 |
-
self::CHAR_ALNUM . self::CHAR_MARK . self::CHAR_RESERVED .
|
135 |
-
|
136 |
-
// If unwise chars are allowed, add them to the URI chars class
|
137 |
-
(self::$_config['allow_unwise'] ? self::CHAR_UNWISE : '') . '])';
|
138 |
-
|
139 |
-
// If no scheme-specific part was supplied, the user intends to create
|
140 |
-
// a new URI with this object. No further parsing is required.
|
141 |
-
if (strlen($schemeSpecific) === 0) {
|
142 |
-
return;
|
143 |
-
}
|
144 |
-
|
145 |
-
// Parse the scheme-specific URI parts into the instance variables.
|
146 |
-
$this->_parseUri($schemeSpecific);
|
147 |
-
|
148 |
-
// Validate the URI
|
149 |
-
if ($this->valid() === false) {
|
150 |
-
require_once 'Microsoft/Uri/Exception.php';
|
151 |
-
throw new Microsoft_Uri_Exception('Invalid URI supplied');
|
152 |
-
}
|
153 |
-
}
|
154 |
-
|
155 |
-
/**
|
156 |
-
* Creates a Microsoft_Uri_Http from the given string
|
157 |
-
*
|
158 |
-
* @param string $uri String to create URI from, must start with
|
159 |
-
* 'http://' or 'https://'
|
160 |
-
* @throws InvalidArgumentException When the given $uri is not a string or
|
161 |
-
* does not start with http:// or https://
|
162 |
-
* @throws Microsoft_Uri_Exception When the given $uri is invalid
|
163 |
-
* @return Microsoft_Uri_Http
|
164 |
-
*/
|
165 |
-
public static function fromString($uri)
|
166 |
-
{
|
167 |
-
if (is_string($uri) === false) {
|
168 |
-
require_once 'Microsoft/Uri/Exception.php';
|
169 |
-
throw new Microsoft_Uri_Exception('$uri is not a string');
|
170 |
-
}
|
171 |
-
|
172 |
-
$uri = explode(':', $uri, 2);
|
173 |
-
$scheme = strtolower($uri[0]);
|
174 |
-
$schemeSpecific = isset($uri[1]) === true ? $uri[1] : '';
|
175 |
-
|
176 |
-
if (in_array($scheme, array('http', 'https')) === false) {
|
177 |
-
require_once 'Microsoft/Uri/Exception.php';
|
178 |
-
throw new Microsoft_Uri_Exception("Invalid scheme: '$scheme'");
|
179 |
-
}
|
180 |
-
|
181 |
-
$schemeHandler = new Microsoft_Uri_Http($scheme, $schemeSpecific);
|
182 |
-
return $schemeHandler;
|
183 |
-
}
|
184 |
-
|
185 |
-
/**
|
186 |
-
* Parse the scheme-specific portion of the URI and place its parts into instance variables.
|
187 |
-
*
|
188 |
-
* @param string $schemeSpecific The scheme-specific portion to parse
|
189 |
-
* @throws Microsoft_Uri_Exception When scheme-specific decoposition fails
|
190 |
-
* @throws Microsoft_Uri_Exception When authority decomposition fails
|
191 |
-
* @return void
|
192 |
-
*/
|
193 |
-
protected function _parseUri($schemeSpecific)
|
194 |
-
{
|
195 |
-
// High-level decomposition parser
|
196 |
-
$pattern = '~^((//)([^/?#]*))([^?#]*)(\?([^#]*))?(#(.*))?$~';
|
197 |
-
$status = @preg_match($pattern, $schemeSpecific, $matches);
|
198 |
-
if ($status === false) {
|
199 |
-
require_once 'Microsoft/Uri/Exception.php';
|
200 |
-
throw new Microsoft_Uri_Exception('Internal error: scheme-specific decomposition failed');
|
201 |
-
}
|
202 |
-
|
203 |
-
// Failed decomposition; no further processing needed
|
204 |
-
if ($status === false) {
|
205 |
-
return;
|
206 |
-
}
|
207 |
-
|
208 |
-
// Save URI components that need no further decomposition
|
209 |
-
$this->_path = isset($matches[4]) === true ? $matches[4] : '';
|
210 |
-
$this->_query = isset($matches[6]) === true ? $matches[6] : '';
|
211 |
-
$this->_fragment = isset($matches[8]) === true ? $matches[8] : '';
|
212 |
-
|
213 |
-
// Additional decomposition to get username, password, host, and port
|
214 |
-
$combo = isset($matches[3]) === true ? $matches[3] : '';
|
215 |
-
$pattern = '~^(([^:@]*)(:([^@]*))?@)?([^:]+)(:(.*))?$~';
|
216 |
-
$status = @preg_match($pattern, $combo, $matches);
|
217 |
-
if ($status === false) {
|
218 |
-
require_once 'Microsoft/Uri/Exception.php';
|
219 |
-
throw new Microsoft_Uri_Exception('Internal error: authority decomposition failed');
|
220 |
-
}
|
221 |
-
|
222 |
-
// Failed decomposition; no further processing needed
|
223 |
-
if ($status === false) {
|
224 |
-
return;
|
225 |
-
}
|
226 |
-
|
227 |
-
// Save remaining URI components
|
228 |
-
$this->_username = isset($matches[2]) === true ? $matches[2] : '';
|
229 |
-
$this->_password = isset($matches[4]) === true ? $matches[4] : '';
|
230 |
-
$this->_host = isset($matches[5]) === true ? $matches[5] : '';
|
231 |
-
$this->_port = isset($matches[7]) === true ? $matches[7] : '';
|
232 |
-
|
233 |
-
}
|
234 |
-
|
235 |
-
/**
|
236 |
-
* Returns a URI based on current values of the instance variables. If any
|
237 |
-
* part of the URI does not pass validation, then an exception is thrown.
|
238 |
-
*
|
239 |
-
* @throws Microsoft_Uri_Exception When one or more parts of the URI are invalid
|
240 |
-
* @return string
|
241 |
-
*/
|
242 |
-
public function getUri()
|
243 |
-
{
|
244 |
-
if ($this->valid() === false) {
|
245 |
-
require_once 'Microsoft/Uri/Exception.php';
|
246 |
-
throw new Microsoft_Uri_Exception('One or more parts of the URI are invalid');
|
247 |
-
}
|
248 |
-
|
249 |
-
$password = strlen($this->_password) > 0 ? ":$this->_password" : '';
|
250 |
-
$auth = strlen($this->_username) > 0 ? "$this->_username$password@" : '';
|
251 |
-
$port = strlen($this->_port) > 0 ? ":$this->_port" : '';
|
252 |
-
$query = strlen($this->_query) > 0 ? "?$this->_query" : '';
|
253 |
-
$fragment = strlen($this->_fragment) > 0 ? "#$this->_fragment" : '';
|
254 |
-
|
255 |
-
return $this->_scheme
|
256 |
-
. '://'
|
257 |
-
. $auth
|
258 |
-
. $this->_host
|
259 |
-
. $port
|
260 |
-
. $this->_path
|
261 |
-
. $query
|
262 |
-
. $fragment;
|
263 |
-
}
|
264 |
-
|
265 |
-
/**
|
266 |
-
* Validate the current URI from the instance variables. Returns true if and only if all
|
267 |
-
* parts pass validation.
|
268 |
-
*
|
269 |
-
* @return boolean
|
270 |
-
*/
|
271 |
-
public function valid()
|
272 |
-
{
|
273 |
-
// Return true if and only if all parts of the URI have passed validation
|
274 |
-
return $this->validateUsername()
|
275 |
-
and $this->validatePassword()
|
276 |
-
and $this->validateHost()
|
277 |
-
and $this->validatePort()
|
278 |
-
and $this->validatePath()
|
279 |
-
and $this->validateQuery()
|
280 |
-
and $this->validateFragment();
|
281 |
-
}
|
282 |
-
|
283 |
-
/**
|
284 |
-
* Returns the username portion of the URL, or FALSE if none.
|
285 |
-
*
|
286 |
-
* @return string
|
287 |
-
*/
|
288 |
-
public function getUsername()
|
289 |
-
{
|
290 |
-
return strlen($this->_username) > 0 ? $this->_username : false;
|
291 |
-
}
|
292 |
-
|
293 |
-
/**
|
294 |
-
* Returns true if and only if the username passes validation. If no username is passed,
|
295 |
-
* then the username contained in the instance variable is used.
|
296 |
-
*
|
297 |
-
* @param string $username The HTTP username
|
298 |
-
* @throws Microsoft_Uri_Exception When username validation fails
|
299 |
-
* @return boolean
|
300 |
-
* @link http://www.faqs.org/rfcs/rfc2396.html
|
301 |
-
*/
|
302 |
-
public function validateUsername($username = null)
|
303 |
-
{
|
304 |
-
if ($username === null) {
|
305 |
-
$username = $this->_username;
|
306 |
-
}
|
307 |
-
|
308 |
-
// If the username is empty, then it is considered valid
|
309 |
-
if (strlen($username) === 0) {
|
310 |
-
return true;
|
311 |
-
}
|
312 |
-
|
313 |
-
// Check the username against the allowed values
|
314 |
-
$status = @preg_match('/^(?:' . $this->_regex['escaped'] . '|[' .
|
315 |
-
self::CHAR_ALNUM . self::CHAR_MARK . ';:&=+$,' . '])+$/', $username);
|
316 |
-
|
317 |
-
if ($status === false) {
|
318 |
-
require_once 'Microsoft/Uri/Exception.php';
|
319 |
-
throw new Microsoft_Uri_Exception('Internal error: username validation failed');
|
320 |
-
}
|
321 |
-
|
322 |
-
return $status === 1;
|
323 |
-
}
|
324 |
-
|
325 |
-
/**
|
326 |
-
* Sets the username for the current URI, and returns the old username
|
327 |
-
*
|
328 |
-
* @param string $username The HTTP username
|
329 |
-
* @throws Microsoft_Uri_Exception When $username is not a valid HTTP username
|
330 |
-
* @return string
|
331 |
-
*/
|
332 |
-
public function setUsername($username)
|
333 |
-
{
|
334 |
-
if ($this->validateUsername($username) === false) {
|
335 |
-
require_once 'Microsoft/Uri/Exception.php';
|
336 |
-
throw new Microsoft_Uri_Exception("Username \"$username\" is not a valid HTTP username");
|
337 |
-
}
|
338 |
-
|
339 |
-
$oldUsername = $this->_username;
|
340 |
-
$this->_username = $username;
|
341 |
-
|
342 |
-
return $oldUsername;
|
343 |
-
}
|
344 |
-
|
345 |
-
/**
|
346 |
-
* Returns the password portion of the URL, or FALSE if none.
|
347 |
-
*
|
348 |
-
* @return string
|
349 |
-
*/
|
350 |
-
public function getPassword()
|
351 |
-
{
|
352 |
-
return strlen($this->_password) > 0 ? $this->_password : false;
|
353 |
-
}
|
354 |
-
|
355 |
-
/**
|
356 |
-
* Returns true if and only if the password passes validation. If no password is passed,
|
357 |
-
* then the password contained in the instance variable is used.
|
358 |
-
*
|
359 |
-
* @param string $password The HTTP password
|
360 |
-
* @throws Microsoft_Uri_Exception When password validation fails
|
361 |
-
* @return boolean
|
362 |
-
* @link http://www.faqs.org/rfcs/rfc2396.html
|
363 |
-
*/
|
364 |
-
public function validatePassword($password = null)
|
365 |
-
{
|
366 |
-
if ($password === null) {
|
367 |
-
$password = $this->_password;
|
368 |
-
}
|
369 |
-
|
370 |
-
// If the password is empty, then it is considered valid
|
371 |
-
if (strlen($password) === 0) {
|
372 |
-
return true;
|
373 |
-
}
|
374 |
-
|
375 |
-
// If the password is nonempty, but there is no username, then it is considered invalid
|
376 |
-
if (strlen($password) > 0 and strlen($this->_username) === 0) {
|
377 |
-
return false;
|
378 |
-
}
|
379 |
-
|
380 |
-
// Check the password against the allowed values
|
381 |
-
$status = @preg_match('/^(?:' . $this->_regex['escaped'] . '|[' .
|
382 |
-
self::CHAR_ALNUM . self::CHAR_MARK . ';:&=+$,' . '])+$/', $password);
|
383 |
-
|
384 |
-
if ($status === false) {
|
385 |
-
require_once 'Microsoft/Uri/Exception.php';
|
386 |
-
throw new Microsoft_Uri_Exception('Internal error: password validation failed.');
|
387 |
-
}
|
388 |
-
|
389 |
-
return $status == 1;
|
390 |
-
}
|
391 |
-
|
392 |
-
/**
|
393 |
-
* Sets the password for the current URI, and returns the old password
|
394 |
-
*
|
395 |
-
* @param string $password The HTTP password
|
396 |
-
* @throws Microsoft_Uri_Exception When $password is not a valid HTTP password
|
397 |
-
* @return string
|
398 |
-
*/
|
399 |
-
public function setPassword($password)
|
400 |
-
{
|
401 |
-
if ($this->validatePassword($password) === false) {
|
402 |
-
require_once 'Microsoft/Uri/Exception.php';
|
403 |
-
throw new Microsoft_Uri_Exception("Password \"$password\" is not a valid HTTP password.");
|
404 |
-
}
|
405 |
-
|
406 |
-
$oldPassword = $this->_password;
|
407 |
-
$this->_password = $password;
|
408 |
-
|
409 |
-
return $oldPassword;
|
410 |
-
}
|
411 |
-
|
412 |
-
/**
|
413 |
-
* Returns the domain or host IP portion of the URL, or FALSE if none.
|
414 |
-
*
|
415 |
-
* @return string
|
416 |
-
*/
|
417 |
-
public function getHost()
|
418 |
-
{
|
419 |
-
return strlen($this->_host) > 0 ? $this->_host : false;
|
420 |
-
}
|
421 |
-
|
422 |
-
/**
|
423 |
-
* Returns true if and only if the host string passes validation. If no host is passed,
|
424 |
-
* then the host contained in the instance variable is used.
|
425 |
-
*
|
426 |
-
* @param string $host The HTTP host
|
427 |
-
* @return boolean
|
428 |
-
* @uses Microsoft_Filter
|
429 |
-
*/
|
430 |
-
public function validateHost($host = null)
|
431 |
-
{
|
432 |
-
if ($host === null) {
|
433 |
-
$host = $this->_host;
|
434 |
-
}
|
435 |
-
|
436 |
-
// If the host is empty, then it is considered invalid
|
437 |
-
if (strlen($host) === 0) {
|
438 |
-
return false;
|
439 |
-
}
|
440 |
-
|
441 |
-
return true;
|
442 |
-
}
|
443 |
-
|
444 |
-
/**
|
445 |
-
* Sets the host for the current URI, and returns the old host
|
446 |
-
*
|
447 |
-
* @param string $host The HTTP host
|
448 |
-
* @throws Microsoft_Uri_Exception When $host is nota valid HTTP host
|
449 |
-
* @return string
|
450 |
-
*/
|
451 |
-
public function setHost($host)
|
452 |
-
{
|
453 |
-
if ($this->validateHost($host) === false) {
|
454 |
-
require_once 'Microsoft/Uri/Exception.php';
|
455 |
-
throw new Microsoft_Uri_Exception("Host \"$host\" is not a valid HTTP host");
|
456 |
-
}
|
457 |
-
|
458 |
-
$oldHost = $this->_host;
|
459 |
-
$this->_host = $host;
|
460 |
-
|
461 |
-
return $oldHost;
|
462 |
-
}
|
463 |
-
|
464 |
-
/**
|
465 |
-
* Returns the TCP port, or FALSE if none.
|
466 |
-
*
|
467 |
-
* @return string
|
468 |
-
*/
|
469 |
-
public function getPort()
|
470 |
-
{
|
471 |
-
return strlen($this->_port) > 0 ? $this->_port : false;
|
472 |
-
}
|
473 |
-
|
474 |
-
/**
|
475 |
-
* Returns true if and only if the TCP port string passes validation. If no port is passed,
|
476 |
-
* then the port contained in the instance variable is used.
|
477 |
-
*
|
478 |
-
* @param string $port The HTTP port
|
479 |
-
* @return boolean
|
480 |
-
*/
|
481 |
-
public function validatePort($port = null)
|
482 |
-
{
|
483 |
-
if ($port === null) {
|
484 |
-
$port = $this->_port;
|
485 |
-
}
|
486 |
-
|
487 |
-
// If the port is empty, then it is considered valid
|
488 |
-
if (strlen($port) === 0) {
|
489 |
-
return true;
|
490 |
-
}
|
491 |
-
|
492 |
-
// Check the port against the allowed values
|
493 |
-
return ctype_digit((string) $port) and 1 <= $port and $port <= 65535;
|
494 |
-
}
|
495 |
-
|
496 |
-
/**
|
497 |
-
* Sets the port for the current URI, and returns the old port
|
498 |
-
*
|
499 |
-
* @param string $port The HTTP port
|
500 |
-
* @throws Microsoft_Uri_Exception When $port is not a valid HTTP port
|
501 |
-
* @return string
|
502 |
-
*/
|
503 |
-
public function setPort($port)
|
504 |
-
{
|
505 |
-
if ($this->validatePort($port) === false) {
|
506 |
-
require_once 'Microsoft/Uri/Exception.php';
|
507 |
-
throw new Microsoft_Uri_Exception("Port \"$port\" is not a valid HTTP port.");
|
508 |
-
}
|
509 |
-
|
510 |
-
$oldPort = $this->_port;
|
511 |
-
$this->_port = $port;
|
512 |
-
|
513 |
-
return $oldPort;
|
514 |
-
}
|
515 |
-
|
516 |
-
/**
|
517 |
-
* Returns the path and filename portion of the URL, or FALSE if none.
|
518 |
-
*
|
519 |
-
* @return string
|
520 |
-
*/
|
521 |
-
public function getPath()
|
522 |
-
{
|
523 |
-
return strlen($this->_path) > 0 ? $this->_path : '/';
|
524 |
-
}
|
525 |
-
|
526 |
-
/**
|
527 |
-
* Returns true if and only if the path string passes validation. If no path is passed,
|
528 |
-
* then the path contained in the instance variable is used.
|
529 |
-
*
|
530 |
-
* @param string $path The HTTP path
|
531 |
-
* @throws Microsoft_Uri_Exception When path validation fails
|
532 |
-
* @return boolean
|
533 |
-
*/
|
534 |
-
public function validatePath($path = null)
|
535 |
-
{
|
536 |
-
if ($path === null) {
|
537 |
-
$path = $this->_path;
|
538 |
-
}
|
539 |
-
|
540 |
-
// If the path is empty, then it is considered valid
|
541 |
-
if (strlen($path) === 0) {
|
542 |
-
return true;
|
543 |
-
}
|
544 |
-
|
545 |
-
// Determine whether the path is well-formed
|
546 |
-
$pattern = '/^' . $this->_regex['path'] . '$/';
|
547 |
-
$status = @preg_match($pattern, $path);
|
548 |
-
if ($status === false) {
|
549 |
-
require_once 'Microsoft/Uri/Exception.php';
|
550 |
-
throw new Microsoft_Uri_Exception('Internal error: path validation failed');
|
551 |
-
}
|
552 |
-
|
553 |
-
return (boolean) $status;
|
554 |
-
}
|
555 |
-
|
556 |
-
/**
|
557 |
-
* Sets the path for the current URI, and returns the old path
|
558 |
-
*
|
559 |
-
* @param string $path The HTTP path
|
560 |
-
* @throws Microsoft_Uri_Exception When $path is not a valid HTTP path
|
561 |
-
* @return string
|
562 |
-
*/
|
563 |
-
public function setPath($path)
|
564 |
-
{
|
565 |
-
if ($this->validatePath($path) === false) {
|
566 |
-
require_once 'Microsoft/Uri/Exception.php';
|
567 |
-
throw new Microsoft_Uri_Exception("Path \"$path\" is not a valid HTTP path");
|
568 |
-
}
|
569 |
-
|
570 |
-
$oldPath = $this->_path;
|
571 |
-
$this->_path = $path;
|
572 |
-
|
573 |
-
return $oldPath;
|
574 |
-
}
|
575 |
-
|
576 |
-
/**
|
577 |
-
* Returns the query portion of the URL (after ?), or FALSE if none.
|
578 |
-
*
|
579 |
-
* @return string
|
580 |
-
*/
|
581 |
-
public function getQuery()
|
582 |
-
{
|
583 |
-
return strlen($this->_query) > 0 ? $this->_query : false;
|
584 |
-
}
|
585 |
-
|
586 |
-
/**
|
587 |
-
* Returns the query portion of the URL (after ?) as a
|
588 |
-
* key-value-array. If the query is empty an empty array
|
589 |
-
* is returned
|
590 |
-
*
|
591 |
-
* @return array
|
592 |
-
*/
|
593 |
-
public function getQueryAsArray()
|
594 |
-
{
|
595 |
-
$query = $this->getQuery();
|
596 |
-
$querryArray = array();
|
597 |
-
if ($query !== false) {
|
598 |
-
parse_str($query, $querryArray);
|
599 |
-
}
|
600 |
-
return $querryArray;
|
601 |
-
}
|
602 |
-
|
603 |
-
/**
|
604 |
-
* Returns true if and only if the query string passes validation. If no query is passed,
|
605 |
-
* then the query string contained in the instance variable is used.
|
606 |
-
*
|
607 |
-
* @param string $query The query to validate
|
608 |
-
* @throws Microsoft_Uri_Exception When query validation fails
|
609 |
-
* @return boolean
|
610 |
-
* @link http://www.faqs.org/rfcs/rfc2396.html
|
611 |
-
*/
|
612 |
-
public function validateQuery($query = null)
|
613 |
-
{
|
614 |
-
if ($query === null) {
|
615 |
-
$query = $this->_query;
|
616 |
-
}
|
617 |
-
|
618 |
-
// If query is empty, it is considered to be valid
|
619 |
-
if (strlen($query) === 0) {
|
620 |
-
return true;
|
621 |
-
}
|
622 |
-
|
623 |
-
// Determine whether the query is well-formed
|
624 |
-
$pattern = '/^' . $this->_regex['uric'] . '*$/';
|
625 |
-
$status = @preg_match($pattern, $query);
|
626 |
-
if ($status === false) {
|
627 |
-
require_once 'Microsoft/Uri/Exception.php';
|
628 |
-
throw new Microsoft_Uri_Exception('Internal error: query validation failed');
|
629 |
-
}
|
630 |
-
|
631 |
-
return $status == 1;
|
632 |
-
}
|
633 |
-
|
634 |
-
/**
|
635 |
-
* Add or replace params in the query string for the current URI, and
|
636 |
-
* return the old query.
|
637 |
-
*
|
638 |
-
* @param array $queryParams
|
639 |
-
* @return string Old query string
|
640 |
-
*/
|
641 |
-
public function addReplaceQueryParameters(array $queryParams)
|
642 |
-
{
|
643 |
-
$queryParams = array_merge($this->getQueryAsArray(), $queryParams);
|
644 |
-
return $this->setQuery($queryParams);
|
645 |
-
}
|
646 |
-
|
647 |
-
/**
|
648 |
-
* Remove params in the query string for the current URI, and
|
649 |
-
* return the old query.
|
650 |
-
*
|
651 |
-
* @param array $queryParamKeys
|
652 |
-
* @return string Old query string
|
653 |
-
*/
|
654 |
-
public function removeQueryParameters(array $queryParamKeys)
|
655 |
-
{
|
656 |
-
$queryParams = array_diff_key($this->getQueryAsArray(), array_fill_keys($queryParamKeys, 0));
|
657 |
-
return $this->setQuery($queryParams);
|
658 |
-
}
|
659 |
-
|
660 |
-
/**
|
661 |
-
* Set the query string for the current URI, and return the old query
|
662 |
-
* string This method accepts both strings and arrays.
|
663 |
-
*
|
664 |
-
* @param string|array $query The query string or array
|
665 |
-
* @throws Microsoft_Uri_Exception When $query is not a valid query string
|
666 |
-
* @return string Old query string
|
667 |
-
*/
|
668 |
-
public function setQuery($query)
|
669 |
-
{
|
670 |
-
$oldQuery = $this->_query;
|
671 |
-
|
672 |
-
// If query is empty, set an empty string
|
673 |
-
if (empty($query) === true) {
|
674 |
-
$this->_query = '';
|
675 |
-
return $oldQuery;
|
676 |
-
}
|
677 |
-
|
678 |
-
// If query is an array, make a string out of it
|
679 |
-
if (is_array($query) === true) {
|
680 |
-
$query = http_build_query($query, '', '&');
|
681 |
-
} else {
|
682 |
-
// If it is a string, make sure it is valid. If not parse and encode it
|
683 |
-
$query = (string) $query;
|
684 |
-
if ($this->validateQuery($query) === false) {
|
685 |
-
parse_str($query, $queryArray);
|
686 |
-
$query = http_build_query($queryArray, '', '&');
|
687 |
-
}
|
688 |
-
}
|
689 |
-
|
690 |
-
// Make sure the query is valid, and set it
|
691 |
-
if ($this->validateQuery($query) === false) {
|
692 |
-
require_once 'Microsoft/Uri/Exception.php';
|
693 |
-
throw new Microsoft_Uri_Exception("'$query' is not a valid query string");
|
694 |
-
}
|
695 |
-
|
696 |
-
$this->_query = $query;
|
697 |
-
|
698 |
-
return $oldQuery;
|
699 |
-
}
|
700 |
-
|
701 |
-
/**
|
702 |
-
* Returns the fragment portion of the URL (after #), or FALSE if none.
|
703 |
-
*
|
704 |
-
* @return string|false
|
705 |
-
*/
|
706 |
-
public function getFragment()
|
707 |
-
{
|
708 |
-
return strlen($this->_fragment) > 0 ? $this->_fragment : false;
|
709 |
-
}
|
710 |
-
|
711 |
-
/**
|
712 |
-
* Returns true if and only if the fragment passes validation. If no fragment is passed,
|
713 |
-
* then the fragment contained in the instance variable is used.
|
714 |
-
*
|
715 |
-
* @param string $fragment Fragment of an URI
|
716 |
-
* @throws Microsoft_Uri_Exception When fragment validation fails
|
717 |
-
* @return boolean
|
718 |
-
* @link http://www.faqs.org/rfcs/rfc2396.html
|
719 |
-
*/
|
720 |
-
public function validateFragment($fragment = null)
|
721 |
-
{
|
722 |
-
if ($fragment === null) {
|
723 |
-
$fragment = $this->_fragment;
|
724 |
-
}
|
725 |
-
|
726 |
-
// If fragment is empty, it is considered to be valid
|
727 |
-
if (strlen($fragment) === 0) {
|
728 |
-
return true;
|
729 |
-
}
|
730 |
-
|
731 |
-
// Determine whether the fragment is well-formed
|
732 |
-
$pattern = '/^' . $this->_regex['uric'] . '*$/';
|
733 |
-
$status = @preg_match($pattern, $fragment);
|
734 |
-
if ($status === false) {
|
735 |
-
require_once 'Microsoft/Uri/Exception.php';
|
736 |
-
throw new Microsoft_Uri_Exception('Internal error: fragment validation failed');
|
737 |
-
}
|
738 |
-
|
739 |
-
return (boolean) $status;
|
740 |
-
}
|
741 |
-
|
742 |
-
/**
|
743 |
-
* Sets the fragment for the current URI, and returns the old fragment
|
744 |
-
*
|
745 |
-
* @param string $fragment Fragment of the current URI
|
746 |
-
* @throws Microsoft_Uri_Exception When $fragment is not a valid HTTP fragment
|
747 |
-
* @return string
|
748 |
-
*/
|
749 |
-
public function setFragment($fragment)
|
750 |
-
{
|
751 |
-
if ($this->validateFragment($fragment) === false) {
|
752 |
-
require_once 'Microsoft/Uri/Exception.php';
|
753 |
-
throw new Microsoft_Uri_Exception("Fragment \"$fragment\" is not a valid HTTP fragment");
|
754 |
-
}
|
755 |
-
|
756 |
-
$oldFragment = $this->_fragment;
|
757 |
-
$this->_fragment = $fragment;
|
758 |
-
|
759 |
-
return $oldFragment;
|
760 |
-
}
|
761 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Zend Framework
|
4 |
+
*
|
5 |
+
* LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the new BSD license that is bundled
|
8 |
+
* with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://framework.zend.com/license/new-bsd
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@zend.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* @category Microsoft
|
16 |
+
* @package Microsoft_Uri
|
17 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
18 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
19 |
+
* @version $Id: Http.php 19041 2009-11-19 15:19:07Z sgehrig $
|
20 |
+
*/
|
21 |
+
|
22 |
+
/**
|
23 |
+
* @see Microsoft_AutoLoader
|
24 |
+
*/
|
25 |
+
require_once dirname(__FILE__) . '/../AutoLoader.php';
|
26 |
+
|
27 |
+
/**
|
28 |
+
* HTTP(S) URI handler
|
29 |
+
*
|
30 |
+
* @category Microsoft
|
31 |
+
* @package Microsoft_Uri
|
32 |
+
* @uses Microsoft_Uri
|
33 |
+
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
34 |
+
* @license http://framework.zend.com/license/new-bsd New BSD License
|
35 |
+
*/
|
36 |
+
class Microsoft_Uri_Http extends Microsoft_Uri
|
37 |
+
{
|
38 |
+
/**
|
39 |
+
* Character classes for validation regular expressions
|
40 |
+
*/
|
41 |
+
const CHAR_ALNUM = 'A-Za-z0-9';
|
42 |
+
const CHAR_MARK = '-_.!~*\'()\[\]';
|
43 |
+
const CHAR_RESERVED = ';\/?:@&=+$,';
|
44 |
+
const CHAR_SEGMENT = ':@&=+$,;';
|
45 |
+
const CHAR_UNWISE = '{}|\\\\^`';
|
46 |
+
|
47 |
+
/**
|
48 |
+
* HTTP username
|
49 |
+
*
|
50 |
+
* @var string
|
51 |
+
*/
|
52 |
+
protected $_username = '';
|
53 |
+
|
54 |
+
/**
|
55 |
+
* HTTP password
|
56 |
+
*
|
57 |
+
* @var string
|
58 |
+
*/
|
59 |
+
protected $_password = '';
|
60 |
+
|
61 |
+
/**
|
62 |
+
* HTTP host
|
63 |
+
*
|
64 |
+
* @var string
|
65 |
+
*/
|
66 |
+
protected $_host = '';
|
67 |
+
|
68 |
+
/**
|
69 |
+
* HTTP post
|
70 |
+
*
|
71 |
+
* @var string
|
72 |
+
*/
|
73 |
+
protected $_port = '';
|
74 |
+
|
75 |
+
/**
|
76 |
+
* HTTP part
|
77 |
+
*
|
78 |
+
* @var string
|
79 |
+
*/
|
80 |
+
protected $_path = '';
|
81 |
+
|
82 |
+
/**
|
83 |
+
* HTTP query
|
84 |
+
*
|
85 |
+
* @var string
|
86 |
+
*/
|
87 |
+
protected $_query = '';
|
88 |
+
|
89 |
+
/**
|
90 |
+
* HTTP fragment
|
91 |
+
*
|
92 |
+
* @var string
|
93 |
+
*/
|
94 |
+
protected $_fragment = '';
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Regular expression grammar rules for validation; values added by constructor
|
98 |
+
*
|
99 |
+
* @var array
|
100 |
+
*/
|
101 |
+
protected $_regex = array();
|
102 |
+
|
103 |
+
/**
|
104 |
+
* Constructor accepts a string $scheme (e.g., http, https) and a scheme-specific part of the URI
|
105 |
+
* (e.g., example.com/path/to/resource?query=param#fragment)
|
106 |
+
*
|
107 |
+
* @param string $scheme The scheme of the URI
|
108 |
+
* @param string $schemeSpecific The scheme-specific part of the URI
|
109 |
+
* @throws Microsoft_Uri_Exception When the URI is not valid
|
110 |
+
*/
|
111 |
+
protected function __construct($scheme, $schemeSpecific = '')
|
112 |
+
{
|
113 |
+
// Set the scheme
|
114 |
+
$this->_scheme = $scheme;
|
115 |
+
|
116 |
+
// Set up grammar rules for validation via regular expressions. These
|
117 |
+
// are to be used with slash-delimited regular expression strings.
|
118 |
+
|
119 |
+
// Escaped special characters (eg. '%25' for '%')
|
120 |
+
$this->_regex['escaped'] = '%[[:xdigit:]]{2}';
|
121 |
+
|
122 |
+
// Unreserved characters
|
123 |
+
$this->_regex['unreserved'] = '[' . self::CHAR_ALNUM . self::CHAR_MARK . ']';
|
124 |
+
|
125 |
+
// Segment can use escaped, unreserved or a set of additional chars
|
126 |
+
$this->_regex['segment'] = '(?:' . $this->_regex['escaped'] . '|[' .
|
127 |
+
self::CHAR_ALNUM . self::CHAR_MARK . self::CHAR_SEGMENT . '])*';
|
128 |
+
|
129 |
+
// Path can be a series of segmets char strings seperated by '/'
|
130 |
+
$this->_regex['path'] = '(?:\/(?:' . $this->_regex['segment'] . ')?)+';
|
131 |
+
|
132 |
+
// URI characters can be escaped, alphanumeric, mark or reserved chars
|
133 |
+
$this->_regex['uric'] = '(?:' . $this->_regex['escaped'] . '|[' .
|
134 |
+
self::CHAR_ALNUM . self::CHAR_MARK . self::CHAR_RESERVED .
|
135 |
+
|
136 |
+
// If unwise chars are allowed, add them to the URI chars class
|
137 |
+
(self::$_config['allow_unwise'] ? self::CHAR_UNWISE : '') . '])';
|
138 |
+
|
139 |
+
// If no scheme-specific part was supplied, the user intends to create
|
140 |
+
// a new URI with this object. No further parsing is required.
|
141 |
+
if (strlen($schemeSpecific) === 0) {
|
142 |
+
return;
|
143 |
+
}
|
144 |
+
|
145 |
+
// Parse the scheme-specific URI parts into the instance variables.
|
146 |
+
$this->_parseUri($schemeSpecific);
|
147 |
+
|
148 |
+
// Validate the URI
|
149 |
+
if ($this->valid() === false) {
|
150 |
+
//require_once 'Microsoft/Uri/Exception.php';
|
151 |
+
throw new Microsoft_Uri_Exception('Invalid URI supplied');
|
152 |
+
}
|
153 |
+
}
|
154 |
+
|
155 |
+
/**
|
156 |
+
* Creates a Microsoft_Uri_Http from the given string
|
157 |
+
*
|
158 |
+
* @param string $uri String to create URI from, must start with
|
159 |
+
* 'http://' or 'https://'
|
160 |
+
* @throws InvalidArgumentException When the given $uri is not a string or
|
161 |
+
* does not start with http:// or https://
|
162 |
+
* @throws Microsoft_Uri_Exception When the given $uri is invalid
|
163 |
+
* @return Microsoft_Uri_Http
|
164 |
+
*/
|
165 |
+
public static function fromString($uri)
|
166 |
+
{
|
167 |
+
if (is_string($uri) === false) {
|
168 |
+
//require_once 'Microsoft/Uri/Exception.php';
|
169 |
+
throw new Microsoft_Uri_Exception('$uri is not a string');
|
170 |
+
}
|
171 |
+
|
172 |
+
$uri = explode(':', $uri, 2);
|
173 |
+
$scheme = strtolower($uri[0]);
|
174 |
+
$schemeSpecific = isset($uri[1]) === true ? $uri[1] : '';
|
175 |
+
|
176 |
+
if (in_array($scheme, array('http', 'https')) === false) {
|
177 |
+
//require_once 'Microsoft/Uri/Exception.php';
|
178 |
+
throw new Microsoft_Uri_Exception("Invalid scheme: '$scheme'");
|
179 |
+
}
|
180 |
+
|
181 |
+
$schemeHandler = new Microsoft_Uri_Http($scheme, $schemeSpecific);
|
182 |
+
return $schemeHandler;
|
183 |
+
}
|
184 |
+
|
185 |
+
/**
|
186 |
+
* Parse the scheme-specific portion of the URI and place its parts into instance variables.
|
187 |
+
*
|
188 |
+
* @param string $schemeSpecific The scheme-specific portion to parse
|
189 |
+
* @throws Microsoft_Uri_Exception When scheme-specific decoposition fails
|
190 |
+
* @throws Microsoft_Uri_Exception When authority decomposition fails
|
191 |
+
* @return void
|
192 |
+
*/
|
193 |
+
protected function _parseUri($schemeSpecific)
|
194 |
+
{
|
195 |
+
// High-level decomposition parser
|
196 |
+
$pattern = '~^((//)([^/?#]*))([^?#]*)(\?([^#]*))?(#(.*))?$~';
|
197 |
+
$status = @preg_match($pattern, $schemeSpecific, $matches);
|
198 |
+
if ($status === false) {
|
199 |
+
//require_once 'Microsoft/Uri/Exception.php';
|
200 |
+
throw new Microsoft_Uri_Exception('Internal error: scheme-specific decomposition failed');
|
201 |
+
}
|
202 |
+
|
203 |
+
// Failed decomposition; no further processing needed
|
204 |
+
if ($status === false) {
|
205 |
+
return;
|
206 |
+
}
|
207 |
+
|
208 |
+
// Save URI components that need no further decomposition
|
209 |
+
$this->_path = isset($matches[4]) === true ? $matches[4] : '';
|
210 |
+
$this->_query = isset($matches[6]) === true ? $matches[6] : '';
|
211 |
+
$this->_fragment = isset($matches[8]) === true ? $matches[8] : '';
|
212 |
+
|
213 |
+
// Additional decomposition to get username, password, host, and port
|
214 |
+
$combo = isset($matches[3]) === true ? $matches[3] : '';
|
215 |
+
$pattern = '~^(([^:@]*)(:([^@]*))?@)?([^:]+)(:(.*))?$~';
|
216 |
+
$status = @preg_match($pattern, $combo, $matches);
|
217 |
+
if ($status === false) {
|
218 |
+
//require_once 'Microsoft/Uri/Exception.php';
|
219 |
+
throw new Microsoft_Uri_Exception('Internal error: authority decomposition failed');
|
220 |
+
}
|
221 |
+
|
222 |
+
// Failed decomposition; no further processing needed
|
223 |
+
if ($status === false) {
|
224 |
+
return;
|
225 |
+
}
|
226 |
+
|
227 |
+
// Save remaining URI components
|
228 |
+
$this->_username = isset($matches[2]) === true ? $matches[2] : '';
|
229 |
+
$this->_password = isset($matches[4]) === true ? $matches[4] : '';
|
230 |
+
$this->_host = isset($matches[5]) === true ? $matches[5] : '';
|
231 |
+
$this->_port = isset($matches[7]) === true ? $matches[7] : '';
|
232 |
+
|
233 |
+
}
|
234 |
+
|
235 |
+
/**
|
236 |
+
* Returns a URI based on current values of the instance variables. If any
|
237 |
+
* part of the URI does not pass validation, then an exception is thrown.
|
238 |
+
*
|
239 |
+
* @throws Microsoft_Uri_Exception When one or more parts of the URI are invalid
|
240 |
+
* @return string
|
241 |
+
*/
|
242 |
+
public function getUri()
|
243 |
+
{
|
244 |
+
if ($this->valid() === false) {
|
245 |
+
//require_once 'Microsoft/Uri/Exception.php';
|
246 |
+
throw new Microsoft_Uri_Exception('One or more parts of the URI are invalid');
|
247 |
+
}
|
248 |
+
|
249 |
+
$password = strlen($this->_password) > 0 ? ":$this->_password" : '';
|
250 |
+
$auth = strlen($this->_username) > 0 ? "$this->_username$password@" : '';
|
251 |
+
$port = strlen($this->_port) > 0 ? ":$this->_port" : '';
|
252 |
+
$query = strlen($this->_query) > 0 ? "?$this->_query" : '';
|
253 |
+
$fragment = strlen($this->_fragment) > 0 ? "#$this->_fragment" : '';
|
254 |
+
|
255 |
+
return $this->_scheme
|
256 |
+
. '://'
|
257 |
+
. $auth
|
258 |
+
. $this->_host
|
259 |
+
. $port
|
260 |
+
. $this->_path
|
261 |
+
. $query
|
262 |
+
. $fragment;
|
263 |
+
}
|
264 |
+
|
265 |
+
/**
|
266 |
+
* Validate the current URI from the instance variables. Returns true if and only if all
|
267 |
+
* parts pass validation.
|
268 |
+
*
|
269 |
+
* @return boolean
|
270 |
+
*/
|
271 |
+
public function valid()
|
272 |
+
{
|
273 |
+
// Return true if and only if all parts of the URI have passed validation
|
274 |
+
return $this->validateUsername()
|
275 |
+
and $this->validatePassword()
|
276 |
+
and $this->validateHost()
|
277 |
+
and $this->validatePort()
|
278 |
+
and $this->validatePath()
|
279 |
+
and $this->validateQuery()
|
280 |
+
and $this->validateFragment();
|
281 |
+
}
|
282 |
+
|
283 |
+
/**
|
284 |
+
* Returns the username portion of the URL, or FALSE if none.
|
285 |
+
*
|
286 |
+
* @return string
|
287 |
+
*/
|
288 |
+
public function getUsername()
|
289 |
+
{
|
290 |
+
return strlen($this->_username) > 0 ? $this->_username : false;
|
291 |
+
}
|
292 |
+
|
293 |
+
/**
|
294 |
+
* Returns true if and only if the username passes validation. If no username is passed,
|
295 |
+
* then the username contained in the instance variable is used.
|
296 |
+
*
|
297 |
+
* @param string $username The HTTP username
|
298 |
+
* @throws Microsoft_Uri_Exception When username validation fails
|
299 |
+
* @return boolean
|
300 |
+
* @link http://www.faqs.org/rfcs/rfc2396.html
|
301 |
+
*/
|
302 |
+
public function validateUsername($username = null)
|
303 |
+
{
|
304 |
+
if ($username === null) {
|
305 |
+
$username = $this->_username;
|
306 |
+
}
|
307 |
+
|
308 |
+
// If the username is empty, then it is considered valid
|
309 |
+
if (strlen($username) === 0) {
|
310 |
+
return true;
|
311 |
+
}
|
312 |
+
|
313 |
+
// Check the username against the allowed values
|
314 |
+
$status = @preg_match('/^(?:' . $this->_regex['escaped'] . '|[' .
|
315 |
+
self::CHAR_ALNUM . self::CHAR_MARK . ';:&=+$,' . '])+$/', $username);
|
316 |
+
|
317 |
+
if ($status === false) {
|
318 |
+
//require_once 'Microsoft/Uri/Exception.php';
|
319 |
+
throw new Microsoft_Uri_Exception('Internal error: username validation failed');
|
320 |
+
}
|
321 |
+
|
322 |
+
return $status === 1;
|
323 |
+
}
|
324 |
+
|
325 |
+
/**
|
326 |
+
* Sets the username for the current URI, and returns the old username
|
327 |
+
*
|
328 |
+
* @param string $username The HTTP username
|
329 |
+
* @throws Microsoft_Uri_Exception When $username is not a valid HTTP username
|
330 |
+
* @return string
|
331 |
+
*/
|
332 |
+
public function setUsername($username)
|
333 |
+
{
|
334 |
+
if ($this->validateUsername($username) === false) {
|
335 |
+
//require_once 'Microsoft/Uri/Exception.php';
|
336 |
+
throw new Microsoft_Uri_Exception("Username \"$username\" is not a valid HTTP username");
|
337 |
+
}
|
338 |
+
|
339 |
+
$oldUsername = $this->_username;
|
340 |
+
$this->_username = $username;
|
341 |
+
|
342 |
+
return $oldUsername;
|
343 |
+
}
|
344 |
+
|
345 |
+
/**
|
346 |
+
* Returns the password portion of the URL, or FALSE if none.
|
347 |
+
*
|
348 |
+
* @return string
|
349 |
+
*/
|
350 |
+
public function getPassword()
|
351 |
+
{
|
352 |
+
return strlen($this->_password) > 0 ? $this->_password : false;
|
353 |
+
}
|
354 |
+
|
355 |
+
/**
|
356 |
+
* Returns true if and only if the password passes validation. If no password is passed,
|
357 |
+
* then the password contained in the instance variable is used.
|
358 |
+
*
|
359 |
+
* @param string $password The HTTP password
|
360 |
+
* @throws Microsoft_Uri_Exception When password validation fails
|
361 |
+
* @return boolean
|
362 |
+
* @link http://www.faqs.org/rfcs/rfc2396.html
|
363 |
+
*/
|
364 |
+
public function validatePassword($password = null)
|
365 |
+
{
|
366 |
+
if ($password === null) {
|
367 |
+
$password = $this->_password;
|
368 |
+
}
|
369 |
+
|
370 |
+
// If the password is empty, then it is considered valid
|
371 |
+
if (strlen($password) === 0) {
|
372 |
+
return true;
|
373 |
+
}
|
374 |
+
|
375 |
+
// If the password is nonempty, but there is no username, then it is considered invalid
|
376 |
+
if (strlen($password) > 0 and strlen($this->_username) === 0) {
|
377 |
+
return false;
|
378 |
+
}
|
379 |
+
|
380 |
+
// Check the password against the allowed values
|
381 |
+
$status = @preg_match('/^(?:' . $this->_regex['escaped'] . '|[' .
|
382 |
+
self::CHAR_ALNUM . self::CHAR_MARK . ';:&=+$,' . '])+$/', $password);
|
383 |
+
|
384 |
+
if ($status === false) {
|
385 |
+
//require_once 'Microsoft/Uri/Exception.php';
|
386 |
+
throw new Microsoft_Uri_Exception('Internal error: password validation failed.');
|
387 |
+
}
|
388 |
+
|
389 |
+
return $status == 1;
|
390 |
+
}
|
391 |
+
|
392 |
+
/**
|
393 |
+
* Sets the password for the current URI, and returns the old password
|
394 |
+
*
|
395 |
+
* @param string $password The HTTP password
|
396 |
+
* @throws Microsoft_Uri_Exception When $password is not a valid HTTP password
|
397 |
+
* @return string
|
398 |
+
*/
|
399 |
+
public function setPassword($password)
|
400 |
+
{
|
401 |
+
if ($this->validatePassword($password) === false) {
|
402 |
+
//require_once 'Microsoft/Uri/Exception.php';
|
403 |
+
throw new Microsoft_Uri_Exception("Password \"$password\" is not a valid HTTP password.");
|
404 |
+
}
|
405 |
+
|
406 |
+
$oldPassword = $this->_password;
|
407 |
+
$this->_password = $password;
|
408 |
+
|
409 |
+
return $oldPassword;
|
410 |
+
}
|
411 |
+
|
412 |
+
/**
|
413 |
+
* Returns the domain or host IP portion of the URL, or FALSE if none.
|
414 |
+
*
|
415 |
+
* @return string
|
416 |
+
*/
|
417 |
+
public function getHost()
|
418 |
+
{
|
419 |
+
return strlen($this->_host) > 0 ? $this->_host : false;
|
420 |
+
}
|
421 |
+
|
422 |
+
/**
|
423 |
+
* Returns true if and only if the host string passes validation. If no host is passed,
|
424 |
+
* then the host contained in the instance variable is used.
|
425 |
+
*
|
426 |
+
* @param string $host The HTTP host
|
427 |
+
* @return boolean
|
428 |
+
* @uses Microsoft_Filter
|
429 |
+
*/
|
430 |
+
public function validateHost($host = null)
|
431 |
+
{
|
432 |
+
if ($host === null) {
|
433 |
+
$host = $this->_host;
|
434 |
+
}
|
435 |
+
|
436 |
+
// If the host is empty, then it is considered invalid
|
437 |
+
if (strlen($host) === 0) {
|
438 |
+
return false;
|
439 |
+
}
|
440 |
+
|
441 |
+
return true;
|
442 |
+
}
|
443 |
+
|
444 |
+
/**
|
445 |
+
* Sets the host for the current URI, and returns the old host
|
446 |
+
*
|
447 |
+
* @param string $host The HTTP host
|
448 |
+
* @throws Microsoft_Uri_Exception When $host is nota valid HTTP host
|
449 |
+
* @return string
|
450 |
+
*/
|
451 |
+
public function setHost($host)
|
452 |
+
{
|
453 |
+
if ($this->validateHost($host) === false) {
|
454 |
+
//require_once 'Microsoft/Uri/Exception.php';
|
455 |
+
throw new Microsoft_Uri_Exception("Host \"$host\" is not a valid HTTP host");
|
456 |
+
}
|
457 |
+
|
458 |
+
$oldHost = $this->_host;
|
459 |
+
$this->_host = $host;
|
460 |
+
|
461 |
+
return $oldHost;
|
462 |
+
}
|
463 |
+
|
464 |
+
/**
|
465 |
+
* Returns the TCP port, or FALSE if none.
|
466 |
+
*
|
467 |
+
* @return string
|
468 |
+
*/
|
469 |
+
public function getPort()
|
470 |
+
{
|
471 |
+
return strlen($this->_port) > 0 ? $this->_port : false;
|
472 |
+
}
|
473 |
+
|
474 |
+
/**
|
475 |
+
* Returns true if and only if the TCP port string passes validation. If no port is passed,
|
476 |
+
* then the port contained in the instance variable is used.
|
477 |
+
*
|
478 |
+
* @param string $port The HTTP port
|
479 |
+
* @return boolean
|
480 |
+
*/
|
481 |
+
public function validatePort($port = null)
|
482 |
+
{
|
483 |
+
if ($port === null) {
|
484 |
+
$port = $this->_port;
|
485 |
+
}
|
486 |
+
|
487 |
+
// If the port is empty, then it is considered valid
|
488 |
+
if (strlen($port) === 0) {
|
489 |
+
return true;
|
490 |
+
}
|
491 |
+
|
492 |
+
// Check the port against the allowed values
|
493 |
+
return ctype_digit((string) $port) and 1 <= $port and $port <= 65535;
|
494 |
+
}
|
495 |
+
|
496 |
+
/**
|
497 |
+
* Sets the port for the current URI, and returns the old port
|
498 |
+
*
|
499 |
+
* @param string $port The HTTP port
|
500 |
+
* @throws Microsoft_Uri_Exception When $port is not a valid HTTP port
|
501 |
+
* @return string
|
502 |
+
*/
|
503 |
+
public function setPort($port)
|
504 |
+
{
|
505 |
+
if ($this->validatePort($port) === false) {
|
506 |
+
//require_once 'Microsoft/Uri/Exception.php';
|
507 |
+
throw new Microsoft_Uri_Exception("Port \"$port\" is not a valid HTTP port.");
|
508 |
+
}
|
509 |
+
|
510 |
+
$oldPort = $this->_port;
|
511 |
+
$this->_port = $port;
|
512 |
+
|
513 |
+
return $oldPort;
|
514 |
+
}
|
515 |
+
|
516 |
+
/**
|
517 |
+
* Returns the path and filename portion of the URL, or FALSE if none.
|
518 |
+
*
|
519 |
+
* @return string
|
520 |
+
*/
|
521 |
+
public function getPath()
|
522 |
+
{
|
523 |
+
return strlen($this->_path) > 0 ? $this->_path : '/';
|
524 |
+
}
|
525 |
+
|
526 |
+
/**
|
527 |
+
* Returns true if and only if the path string passes validation. If no path is passed,
|
528 |
+
* then the path contained in the instance variable is used.
|
529 |
+
*
|
530 |
+
* @param string $path The HTTP path
|
531 |
+
* @throws Microsoft_Uri_Exception When path validation fails
|
532 |
+
* @return boolean
|
533 |
+
*/
|
534 |
+
public function validatePath($path = null)
|
535 |
+
{
|
536 |
+
if ($path === null) {
|
537 |
+
$path = $this->_path;
|
538 |
+
}
|
539 |
+
|
540 |
+
// If the path is empty, then it is considered valid
|
541 |
+
if (strlen($path) === 0) {
|
542 |
+
return true;
|
543 |
+
}
|
544 |
+
|
545 |
+
// Determine whether the path is well-formed
|
546 |
+
$pattern = '/^' . $this->_regex['path'] . '$/';
|
547 |
+
$status = @preg_match($pattern, $path);
|
548 |
+
if ($status === false) {
|
549 |
+
//require_once 'Microsoft/Uri/Exception.php';
|
550 |
+
throw new Microsoft_Uri_Exception('Internal error: path validation failed');
|
551 |
+
}
|
552 |
+
|
553 |
+
return (boolean) $status;
|
554 |
+
}
|
555 |
+
|
556 |
+
/**
|
557 |
+
* Sets the path for the current URI, and returns the old path
|
558 |
+
*
|
559 |
+
* @param string $path The HTTP path
|
560 |
+
* @throws Microsoft_Uri_Exception When $path is not a valid HTTP path
|
561 |
+
* @return string
|
562 |
+
*/
|
563 |
+
public function setPath($path)
|
564 |
+
{
|
565 |
+
if ($this->validatePath($path) === false) {
|
566 |
+
//require_once 'Microsoft/Uri/Exception.php';
|
567 |
+
throw new Microsoft_Uri_Exception("Path \"$path\" is not a valid HTTP path");
|
568 |
+
}
|
569 |
+
|
570 |
+
$oldPath = $this->_path;
|
571 |
+
$this->_path = $path;
|
572 |
+
|
573 |
+
return $oldPath;
|
574 |
+
}
|
575 |
+
|
576 |
+
/**
|
577 |
+
* Returns the query portion of the URL (after ?), or FALSE if none.
|
578 |
+
*
|
579 |
+
* @return string
|
580 |
+
*/
|
581 |
+
public function getQuery()
|
582 |
+
{
|
583 |
+
return strlen($this->_query) > 0 ? $this->_query : false;
|
584 |
+
}
|
585 |
+
|
586 |
+
/**
|
587 |
+
* Returns the query portion of the URL (after ?) as a
|
588 |
+
* key-value-array. If the query is empty an empty array
|
589 |
+
* is returned
|
590 |
+
*
|
591 |
+
* @return array
|
592 |
+
*/
|
593 |
+
public function getQueryAsArray()
|
594 |
+
{
|
595 |
+
$query = $this->getQuery();
|
596 |
+
$querryArray = array();
|
597 |
+
if ($query !== false) {
|
598 |
+
parse_str($query, $querryArray);
|
599 |
+
}
|
600 |
+
return $querryArray;
|
601 |
+
}
|
602 |
+
|
603 |
+
/**
|
604 |
+
* Returns true if and only if the query string passes validation. If no query is passed,
|
605 |
+
* then the query string contained in the instance variable is used.
|
606 |
+
*
|
607 |
+
* @param string $query The query to validate
|
608 |
+
* @throws Microsoft_Uri_Exception When query validation fails
|
609 |
+
* @return boolean
|
610 |
+
* @link http://www.faqs.org/rfcs/rfc2396.html
|
611 |
+
*/
|
612 |
+
public function validateQuery($query = null)
|
613 |
+
{
|
614 |
+
if ($query === null) {
|
615 |
+
$query = $this->_query;
|
616 |
+
}
|
617 |
+
|
618 |
+
// If query is empty, it is considered to be valid
|
619 |
+
if (strlen($query) === 0) {
|
620 |
+
return true;
|
621 |
+
}
|
622 |
+
|
623 |
+
// Determine whether the query is well-formed
|
624 |
+
$pattern = '/^' . $this->_regex['uric'] . '*$/';
|
625 |
+
$status = @preg_match($pattern, $query);
|
626 |
+
if ($status === false) {
|
627 |
+
//require_once 'Microsoft/Uri/Exception.php';
|
628 |
+
throw new Microsoft_Uri_Exception('Internal error: query validation failed');
|
629 |
+
}
|
630 |
+
|
631 |
+
return $status == 1;
|
632 |
+
}
|
633 |
+
|
634 |
+
/**
|
635 |
+
* Add or replace params in the query string for the current URI, and
|
636 |
+
* return the old query.
|
637 |
+
*
|
638 |
+
* @param array $queryParams
|
639 |
+
* @return string Old query string
|
640 |
+
*/
|
641 |
+
public function addReplaceQueryParameters(array $queryParams)
|
642 |
+
{
|
643 |
+
$queryParams = array_merge($this->getQueryAsArray(), $queryParams);
|
644 |
+
return $this->setQuery($queryParams);
|
645 |
+
}
|
646 |
+
|
647 |
+
/**
|
648 |
+
* Remove params in the query string for the current URI, and
|
649 |
+
* return the old query.
|
650 |
+
*
|
651 |
+
* @param array $queryParamKeys
|
652 |
+
* @return string Old query string
|
653 |
+
*/
|
654 |
+
public function removeQueryParameters(array $queryParamKeys)
|
655 |
+
{
|
656 |
+
$queryParams = array_diff_key($this->getQueryAsArray(), array_fill_keys($queryParamKeys, 0));
|
657 |
+
return $this->setQuery($queryParams);
|
658 |
+
}
|
659 |
+
|
660 |
+
/**
|
661 |
+
* Set the query string for the current URI, and return the old query
|
662 |
+
* string This method accepts both strings and arrays.
|
663 |
+
*
|
664 |
+
* @param string|array $query The query string or array
|
665 |
+
* @throws Microsoft_Uri_Exception When $query is not a valid query string
|
666 |
+
* @return string Old query string
|
667 |
+
*/
|
668 |
+
public function setQuery($query)
|
669 |
+
{
|
670 |
+
$oldQuery = $this->_query;
|
671 |
+
|
672 |
+
// If query is empty, set an empty string
|
673 |
+
if (empty($query) === true) {
|
674 |
+
$this->_query = '';
|
675 |
+
return $oldQuery;
|
676 |
+
}
|
677 |
+
|
678 |
+
// If query is an array, make a string out of it
|
679 |
+
if (is_array($query) === true) {
|
680 |
+
$query = http_build_query($query, '', '&');
|
681 |
+
} else {
|
682 |
+
// If it is a string, make sure it is valid. If not parse and encode it
|
683 |
+
$query = (string) $query;
|
684 |
+
if ($this->validateQuery($query) === false) {
|
685 |
+
parse_str($query, $queryArray);
|
686 |
+
$query = http_build_query($queryArray, '', '&');
|
687 |
+
}
|
688 |
+
}
|
689 |
+
|
690 |
+
// Make sure the query is valid, and set it
|
691 |
+
if ($this->validateQuery($query) === false) {
|
692 |
+
//require_once 'Microsoft/Uri/Exception.php';
|
693 |
+
throw new Microsoft_Uri_Exception("'$query' is not a valid query string");
|
694 |
+
}
|
695 |
+
|
696 |
+
$this->_query = $query;
|
697 |
+
|
698 |
+
return $oldQuery;
|
699 |
+
}
|
700 |
+
|
701 |
+
/**
|
702 |
+
* Returns the fragment portion of the URL (after #), or FALSE if none.
|
703 |
+
*
|
704 |
+
* @return string|false
|
705 |
+
*/
|
706 |
+
public function getFragment()
|
707 |
+
{
|
708 |
+
return strlen($this->_fragment) > 0 ? $this->_fragment : false;
|
709 |
+
}
|
710 |
+
|
711 |
+
/**
|
712 |
+
* Returns true if and only if the fragment passes validation. If no fragment is passed,
|
713 |
+
* then the fragment contained in the instance variable is used.
|
714 |
+
*
|
715 |
+
* @param string $fragment Fragment of an URI
|
716 |
+
* @throws Microsoft_Uri_Exception When fragment validation fails
|
717 |
+
* @return boolean
|
718 |
+
* @link http://www.faqs.org/rfcs/rfc2396.html
|
719 |
+
*/
|
720 |
+
public function validateFragment($fragment = null)
|
721 |
+
{
|
722 |
+
if ($fragment === null) {
|
723 |
+
$fragment = $this->_fragment;
|
724 |
+
}
|
725 |
+
|
726 |
+
// If fragment is empty, it is considered to be valid
|
727 |
+
if (strlen($fragment) === 0) {
|
728 |
+
return true;
|
729 |
+
}
|
730 |
+
|
731 |
+
// Determine whether the fragment is well-formed
|
732 |
+
$pattern = '/^' . $this->_regex['uric'] . '*$/';
|
733 |
+
$status = @preg_match($pattern, $fragment);
|
734 |
+
if ($status === false) {
|
735 |
+
//require_once 'Microsoft/Uri/Exception.php';
|
736 |
+
throw new Microsoft_Uri_Exception('Internal error: fragment validation failed');
|
737 |
+
}
|
738 |
+
|
739 |
+
return (boolean) $status;
|
740 |
+
}
|
741 |
+
|
742 |
+
/**
|
743 |
+
* Sets the fragment for the current URI, and returns the old fragment
|
744 |
+
*
|
745 |
+
* @param string $fragment Fragment of the current URI
|
746 |
+
* @throws Microsoft_Uri_Exception When $fragment is not a valid HTTP fragment
|
747 |
+
* @return string
|
748 |
+
*/
|
749 |
+
public function setFragment($fragment)
|
750 |
+
{
|
751 |
+
if ($this->validateFragment($fragment) === false) {
|
752 |
+
//require_once 'Microsoft/Uri/Exception.php';
|
753 |
+
throw new Microsoft_Uri_Exception("Fragment \"$fragment\" is not a valid HTTP fragment");
|
754 |
+
}
|
755 |
+
|
756 |
+
$oldFragment = $this->_fragment;
|
757 |
+
$this->_fragment = $fragment;
|
758 |
+
|
759 |
+
return $oldFragment;
|
760 |
+
}
|
761 |
+
}
|
libs/Microsoft/WindowsAzure/CommandLine/Certificate.php
ADDED
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_Console
|
30 |
+
* @subpackage Exception
|
31 |
+
* @version $Id: Exception.php 55733 2011-01-03 09:17:16Z unknown $
|
32 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
33 |
+
* @license http://phpazure.codeplex.com/license
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @see Microsoft_AutoLoader
|
38 |
+
*/
|
39 |
+
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Certificate commands
|
43 |
+
*
|
44 |
+
* @category Microsoft
|
45 |
+
* @package Microsoft_WindowsAzure_CommandLine
|
46 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
47 |
+
* @license http://phpazure.codeplex.com/license
|
48 |
+
*
|
49 |
+
* @command-handler certificate
|
50 |
+
* @command-handler-description Windows Azure Certificate commands
|
51 |
+
* @command-handler-header Windows Azure SDK for PHP
|
52 |
+
* @command-handler-header Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
53 |
+
* @command-handler-footer Note: Parameters that are common across all commands can be stored
|
54 |
+
* @command-handler-footer in two dedicated environment variables.
|
55 |
+
* @command-handler-footer - SubscriptionId: The Windows Azure Subscription Id to operate on.
|
56 |
+
* @command-handler-footer - Certificate The Windows Azure .cer Management Certificate.
|
57 |
+
* @command-handler-footer
|
58 |
+
* @command-handler-footer All commands support the --ConfigurationFile or -F parameter.
|
59 |
+
* @command-handler-footer The parameter file is a simple INI file carrying one parameter
|
60 |
+
* @command-handler-footer value per line. It accepts the same parameters as one can
|
61 |
+
* @command-handler-footer use from the command line command.
|
62 |
+
*/
|
63 |
+
class Microsoft_WindowsAzure_CommandLine_Certificate
|
64 |
+
extends Microsoft_Console_Command
|
65 |
+
{
|
66 |
+
/**
|
67 |
+
* List certificates for a specified hosted service in a specified subscription.
|
68 |
+
*
|
69 |
+
* @command-name List
|
70 |
+
* @command-description List certificates for a specified hosted service in a specified subscription.
|
71 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
72 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
73 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
74 |
+
* @command-parameter-for $serviceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env|Microsoft_Console_Command_ParameterSource_StdIn --ServiceName|-sn Required. The name of the hosted service.
|
75 |
+
* @command-example List certificates for service name "phptest":
|
76 |
+
* @command-example List -sid="<your_subscription_id>" -cert="mycert.pem" -sn="phptest"
|
77 |
+
*/
|
78 |
+
public function listCertificatesCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName)
|
79 |
+
{
|
80 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
81 |
+
$result = $client->listCertificates($serviceName);
|
82 |
+
|
83 |
+
if (count($result) == 0) {
|
84 |
+
echo 'No data to display.';
|
85 |
+
}
|
86 |
+
foreach ($result as $object) {
|
87 |
+
$this->_displayObjectInformation($object, array('Thumbprint', 'CertificateUrl', 'ThumbprintAlgorithm'));
|
88 |
+
}
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Add a certificate for a specified hosted service in a specified subscription.
|
93 |
+
*
|
94 |
+
* @command-name Add
|
95 |
+
* @command-description Add a certificate for a specified hosted service in a specified subscription.
|
96 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
97 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
98 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
99 |
+
* @command-parameter-for $serviceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env|Microsoft_Console_Command_ParameterSource_StdIn --ServiceName|-sn Required. The name of the hosted service.
|
100 |
+
* @command-parameter-for $certificateLocation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --CertificateLocation Required. Path to the .pfx certificate to be added.
|
101 |
+
* @command-parameter-for $certificatePassword Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Prompt --CertificatePassword Required. The password for the certificate that will be added.
|
102 |
+
* @command-parameter-for $waitForOperation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete?
|
103 |
+
* @command-example Add certificates for service name "phptest":
|
104 |
+
* @command-example Add -sid="<your_subscription_id>" -cert="mycert.pem" -sn="phptest" --CertificateLocation="cert.pfx" --CertificatePassword="certpassword"
|
105 |
+
*/
|
106 |
+
public function addCertificateCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $certificateLocation, $certificatePassword, $waitForOperation = false)
|
107 |
+
{
|
108 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
109 |
+
$client->addCertificate($serviceName, $certificateLocation, $certificatePassword, 'pfx');
|
110 |
+
if ($waitForOperation) {
|
111 |
+
$client->waitForOperation();
|
112 |
+
}
|
113 |
+
echo $serviceName;
|
114 |
+
}
|
115 |
+
|
116 |
+
/**
|
117 |
+
* Gets a certificate from a specified hosted service in a specified subscription.
|
118 |
+
*
|
119 |
+
* @command-name Get
|
120 |
+
* @command-description Gets a certificate from a specified hosted service in a specified subscription.
|
121 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
122 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
123 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
124 |
+
* @command-parameter-for $serviceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env|Microsoft_Console_Command_ParameterSource_StdIn --ServiceName|-sn Required. The name of the hosted service.
|
125 |
+
* @command-parameter-for $thumbprint Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --CertificateThumbprint Required. The certificate thumbprint for which to retrieve the certificate.
|
126 |
+
* @command-parameter-for $algorithm Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --ThumbprintAlgorithm Required. The certificate's algorithm.
|
127 |
+
* @command-example Get certificate for service name "phptest":
|
128 |
+
* @command-example Get -sid="<your_subscription_id>" -cert="mycert.pem" -sn="phptest" --CertificateThumbprint="<thumbprint>" --ThumbprintAlgorithm="sha1"
|
129 |
+
*/
|
130 |
+
public function getCertificateCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $thumbprint, $algorithm = "sha1")
|
131 |
+
{
|
132 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
133 |
+
$result = $client->getCertificate($serviceName, $algorithm, $thumbprint);
|
134 |
+
|
135 |
+
$this->_displayObjectInformation($result, array('Thumbprint', 'CertificateUrl', 'ThumbprintAlgorithm'));
|
136 |
+
}
|
137 |
+
|
138 |
+
/**
|
139 |
+
* Gets a certificate property from a specified hosted service in a specified subscription.
|
140 |
+
*
|
141 |
+
* @command-name GetProperty
|
142 |
+
* @command-description Gets a certificate property from a specified hosted service in a specified subscription.
|
143 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
144 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
145 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
146 |
+
* @command-parameter-for $serviceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env|Microsoft_Console_Command_ParameterSource_StdIn --ServiceName|-sn Required. The name of the hosted service.
|
147 |
+
* @command-parameter-for $thumbprint Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --CertificateThumbprint Required. The certificate thumbprint for which to retrieve the certificate.
|
148 |
+
* @command-parameter-for $algorithm Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --ThumbprintAlgorithm Required. The certificate's algorithm.
|
149 |
+
* @command-parameter-for $property Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Property|-prop Required. The property to retrieve for the certificate.
|
150 |
+
* @command-example Get certificate for service name "phptest":
|
151 |
+
* @command-example Get -sid="<your_subscription_id>" -cert="mycert.pem" -sn="phptest" --CertificateThumbprint="<thumbprint>" --ThumbprintAlgorithm="sha1"
|
152 |
+
*/
|
153 |
+
public function getCertificatePropertyCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $thumbprint, $algorithm = "sha1", $property)
|
154 |
+
{
|
155 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
156 |
+
$result = $client->getCertificate($serviceName, $algorithm, $thumbprint);
|
157 |
+
|
158 |
+
printf("%s\r\n", $result->$property);
|
159 |
+
}
|
160 |
+
|
161 |
+
/**
|
162 |
+
* Deletes a certificate from a specified hosted service in a specified subscription.
|
163 |
+
*
|
164 |
+
* @command-name Delete
|
165 |
+
* @command-description Deletes a certificate from a specified hosted service in a specified subscription.
|
166 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
167 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
168 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
169 |
+
* @command-parameter-for $serviceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env|Microsoft_Console_Command_ParameterSource_StdIn --ServiceName|-sn Required. The name of the hosted service.
|
170 |
+
* @command-parameter-for $thumbprint Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --CertificateThumbprint Required. The certificate thumbprint for which to retrieve the certificate.
|
171 |
+
* @command-parameter-for $algorithm Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --ThumbprintAlgorithm Required. The certificate's algorithm.
|
172 |
+
* @command-parameter-for $waitForOperation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete?
|
173 |
+
* @command-example Get certificate for service name "phptest":
|
174 |
+
* @command-example Get -sid="<your_subscription_id>" -cert="mycert.pem" -sn="phptest" --CertificateThumbprint="<thumbprint>" --ThumbprintAlgorithm="sha1"
|
175 |
+
*/
|
176 |
+
public function deleteCertificateCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $thumbprint, $algorithm = "sha1", $waitForOperation = false)
|
177 |
+
{
|
178 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
179 |
+
$client->deleteCertificate($serviceName, $algorithm, $thumbprint);
|
180 |
+
if ($waitForOperation) {
|
181 |
+
$client->waitForOperation();
|
182 |
+
}
|
183 |
+
echo $serviceName;
|
184 |
+
}
|
185 |
+
}
|
186 |
+
|
187 |
+
Microsoft_Console_Command::bootstrap($_SERVER['argv']);
|
libs/Microsoft/WindowsAzure/CommandLine/Deployment.php
ADDED
@@ -0,0 +1,745 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_Console
|
30 |
+
* @subpackage Exception
|
31 |
+
* @version $Id: Exception.php 55733 2011-01-03 09:17:16Z unknown $
|
32 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
33 |
+
* @license http://phpazure.codeplex.com/license
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @see Microsoft_AutoLoader
|
38 |
+
*/
|
39 |
+
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Deployment commands
|
43 |
+
*
|
44 |
+
* @category Microsoft
|
45 |
+
* @package Microsoft_WindowsAzure_CommandLine
|
46 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
47 |
+
* @license http://phpazure.codeplex.com/license
|
48 |
+
*
|
49 |
+
* @command-handler deployment
|
50 |
+
* @command-handler-description Windows Azure Deployment commands
|
51 |
+
* @command-handler-header Windows Azure SDK for PHP
|
52 |
+
* @command-handler-header Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
53 |
+
* @command-handler-footer Note: Parameters that are common across all commands can be stored
|
54 |
+
* @command-handler-footer in two dedicated environment variables.
|
55 |
+
* @command-handler-footer - SubscriptionId: The Windows Azure Subscription Id to operate on.
|
56 |
+
* @command-handler-footer - Certificate The Windows Azure .cer Management Certificate.
|
57 |
+
* @command-handler-footer
|
58 |
+
* @command-handler-footer All commands support the --ConfigurationFile or -F parameter.
|
59 |
+
* @command-handler-footer The parameter file is a simple INI file carrying one parameter
|
60 |
+
* @command-handler-footer value per line. It accepts the same parameters as one can
|
61 |
+
* @command-handler-footer use from the command line command.
|
62 |
+
*/
|
63 |
+
class Microsoft_WindowsAzure_CommandLine_Deployment
|
64 |
+
extends Microsoft_Console_Command
|
65 |
+
{
|
66 |
+
/**
|
67 |
+
* Creates a deployment from a remote package file and service configuration.
|
68 |
+
*
|
69 |
+
* @command-name CreateFromStorage
|
70 |
+
* @command-description Creates a deployment from a remote package file and service configuration.
|
71 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
72 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
73 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
74 |
+
* @command-parameter-for $serviceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Name Required. The hosted service DNS name to operate on.
|
75 |
+
* @command-parameter-for $deploymentName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --DeploymentName Required. The name for the deployment.
|
76 |
+
* @command-parameter-for $label Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Label Required. The label for the deployment.
|
77 |
+
* @command-parameter-for $deploymentSlot Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --BySlot Required. The slot to deploy to.
|
78 |
+
* @command-parameter-for $packageUrl Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --PackageUrl Required. The remote location of the .cspkg file.
|
79 |
+
* @command-parameter-for $serviceConfigurationLocation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --ServiceConfigLocation Required. The location of the .cspkg file.
|
80 |
+
* @command-parameter-for $startImmediately Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --StartImmediately Optional. Start the deployment after creation.
|
81 |
+
* @command-parameter-for $warningsAsErrors Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --WarningsAsErrors Optional. Treat warnings as errors.
|
82 |
+
* @command-parameter-for $waitForOperation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete?
|
83 |
+
* @command-example Create a deployment from a remote .cspkg:
|
84 |
+
* @command-example CreateFromStorage -sid="<your_subscription_id>" -cert="mycert.pem" --Name="hostedservicename" --DeploymentName="deploymentname"
|
85 |
+
* @command-example --Label="deploymentlabel" --BySlot="production"
|
86 |
+
* @command-example --PackageUrl="http://acct.blob.core.windows.net/pkgs/service.cspkg"
|
87 |
+
* @command-example --ServiceConfigLocation=".\ServiceConfiguration.cscfg" --StartImmediately --WaitFor
|
88 |
+
*/
|
89 |
+
public function createFromStorageCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $deploymentName, $label, $deploymentSlot, $packageUrl, $serviceConfigurationLocation, $startImmediately = true, $warningsAsErrors = false, $waitForOperation = false)
|
90 |
+
{
|
91 |
+
if (!is_null($deploymentSlot) && $deploymentSlot != '') {
|
92 |
+
$deploymentSlot = strtolower($deploymentSlot);
|
93 |
+
}
|
94 |
+
if ($deploymentSlot != 'staging' && $deploymentSlot != 'production') {
|
95 |
+
throw new Microsoft_Console_Exception('The deployment slot specified should be either staging|production.');
|
96 |
+
}
|
97 |
+
|
98 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
99 |
+
$client->createDeployment($serviceName, $deploymentSlot, $deploymentName, $label, $packageUrl, $serviceConfigurationLocation, $startImmediately, $warningsAsErrors);
|
100 |
+
|
101 |
+
if ($waitForOperation) {
|
102 |
+
$client->waitForOperation();
|
103 |
+
}
|
104 |
+
echo $client->getLastRequestId();
|
105 |
+
}
|
106 |
+
|
107 |
+
/**
|
108 |
+
* Creates a deployment from a local package file and service configuration.
|
109 |
+
*
|
110 |
+
* @command-name CreateFromLocal
|
111 |
+
* @command-description Creates a deployment from a local package file and service configuration.
|
112 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
113 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
114 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
115 |
+
* @command-parameter-for $serviceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Name Required. The hosted service DNS name to operate on.
|
116 |
+
* @command-parameter-for $deploymentName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --DeploymentName Required. The name for the deployment.
|
117 |
+
* @command-parameter-for $label Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Label Required. The label for the deployment.
|
118 |
+
* @command-parameter-for $deploymentSlot Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --BySlot Required. The slot to deploy to.
|
119 |
+
* @command-parameter-for $packageLocation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_StdIn --PackageLocation Required. The location of the .cspkg file.
|
120 |
+
* @command-parameter-for $serviceConfigurationLocation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --ServiceConfigLocation Required. The location of the .cspkg file.
|
121 |
+
* @command-parameter-for $storageAccount Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --StorageAccount Required. Storage account to use when creating the deployment.
|
122 |
+
* @command-parameter-for $startImmediately Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --StartImmediately Optional. Start the deployment after creation.
|
123 |
+
* @command-parameter-for $warningsAsErrors Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --WarningsAsErrors Optional. Treat warnings as errors.
|
124 |
+
* @command-parameter-for $waitForOperation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete?
|
125 |
+
* @command-example Create a deployment from a local .cspkg:
|
126 |
+
* @command-example CreateFromLocal -sid="<your_subscription_id>" -cert="mycert.pem" --Name="hostedservicename" --DeploymentName="deploymentname"
|
127 |
+
* @command-example --Label="deploymentlabel" --BySlot="production" --PackageLocation=".\service.cspkg"
|
128 |
+
* @command-example --ServiceConfigLocation=".\ServiceConfiguration.cscfg" --StorageAccount="mystorage"
|
129 |
+
* @command-example --StartImmediately --WaitFor
|
130 |
+
*/
|
131 |
+
public function createFromLocalCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $deploymentName, $label, $deploymentSlot, $packageLocation, $serviceConfigurationLocation, $storageAccount, $startImmediately = true, $warningsAsErrors = false, $waitForOperation = false)
|
132 |
+
{
|
133 |
+
if (!is_null($deploymentSlot) && $deploymentSlot != '') {
|
134 |
+
$deploymentSlot = strtolower($deploymentSlot);
|
135 |
+
}
|
136 |
+
if ($deploymentSlot != 'staging' && $deploymentSlot != 'production') {
|
137 |
+
throw new Microsoft_Console_Exception('The deployment slot specified should be either staging|production.');
|
138 |
+
}
|
139 |
+
|
140 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
141 |
+
$blobClient = $client->createBlobClientForService($storageAccount);
|
142 |
+
$blobClient->createContainerIfNotExists('phpazuredeployments');
|
143 |
+
$blobClient->putBlob('phpazuredeployments', basename($packageLocation), $packageLocation);
|
144 |
+
$package = $blobClient->getBlobInstance('phpazuredeployments', basename($packageLocation));
|
145 |
+
|
146 |
+
$client->createDeployment($serviceName, $deploymentSlot, $deploymentName, $label, $package->Url, $serviceConfigurationLocation, $startImmediately, $warningsAsErrors);
|
147 |
+
|
148 |
+
$client->waitForOperation();
|
149 |
+
$blobClient->deleteBlob('phpazuredeployments', basename($packageLocation));
|
150 |
+
|
151 |
+
if ($waitForOperation) {
|
152 |
+
$client->waitForOperation();
|
153 |
+
}
|
154 |
+
echo $client->getLastRequestId();
|
155 |
+
}
|
156 |
+
|
157 |
+
/**
|
158 |
+
* Get deployment properties.
|
159 |
+
*
|
160 |
+
* @command-name GetProperties
|
161 |
+
* @command-description Get deployment properties.
|
162 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
163 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
164 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
165 |
+
* @command-parameter-for $serviceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env|Microsoft_Console_Command_ParameterSource_StdIn --Name Required. The hosted service DNS name to operate on.
|
166 |
+
* @command-parameter-for $deploymentSlot Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --BySlot Required if deployment name is omitted. The slot to retrieve property information for.
|
167 |
+
* @command-parameter-for $deploymentName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --ByName Required if deployment slot is omitted. The deployment name to retrieve property information for.
|
168 |
+
* @command-example Get deployment properties for service "phptest" (production slot):
|
169 |
+
* @command-example GetProperties -sid="<your_subscription_id>" -cert="mycert.pem" --Name="servicename" --BySlot="production"
|
170 |
+
*/
|
171 |
+
public function getPropertiesCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $deploymentSlot, $deploymentName)
|
172 |
+
{
|
173 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
174 |
+
|
175 |
+
$result = null;
|
176 |
+
|
177 |
+
if (!is_null($deploymentSlot) && $deploymentSlot != '') {
|
178 |
+
$deploymentSlot = strtolower($deploymentSlot);
|
179 |
+
|
180 |
+
$result = $client->getDeploymentBySlot($serviceName, $deploymentSlot);
|
181 |
+
} else {
|
182 |
+
$result = $client->getDeploymentByDeploymentId($serviceName, $deploymentName);
|
183 |
+
}
|
184 |
+
|
185 |
+
$this->_displayObjectInformation($result, array('Name', 'DeploymentSlot', 'Label', 'Url', 'Status'));
|
186 |
+
}
|
187 |
+
|
188 |
+
/**
|
189 |
+
* Get hosted service account property.
|
190 |
+
*
|
191 |
+
* @command-name GetProperty
|
192 |
+
* @command-description Get deployment property.
|
193 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
194 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
195 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
196 |
+
* @command-parameter-for $serviceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env|Microsoft_Console_Command_ParameterSource_StdIn --Name Required. The hosted service DNS name to operate on.
|
197 |
+
* @command-parameter-for $deploymentSlot Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --BySlot Required if deployment name is omitted. The slot to retrieve property information for.
|
198 |
+
* @command-parameter-for $deploymentName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --ByName Required if deployment slot is omitted. The deployment name to retrieve property information for.
|
199 |
+
* @command-parameter-for $property Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Property|-prop Required. The property to retrieve for the hosted service account.
|
200 |
+
* @command-example Get deployment property "Name" for service "phptest" (production slot):
|
201 |
+
* @command-example GetProperties -sid="<your_subscription_id>" -cert="mycert.pem"
|
202 |
+
* @command-example --Name="servicename" --BySlot="production" --Property="Name"
|
203 |
+
*/
|
204 |
+
public function getPropertyCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $deploymentSlot, $deploymentName, $property)
|
205 |
+
{
|
206 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
207 |
+
|
208 |
+
$result = null;
|
209 |
+
|
210 |
+
if (!is_null($deploymentSlot) && $deploymentSlot != '') {
|
211 |
+
$deploymentSlot = strtolower($deploymentSlot);
|
212 |
+
|
213 |
+
$result = $client->getDeploymentBySlot($serviceName, $deploymentSlot);
|
214 |
+
} else {
|
215 |
+
$result = $client->getDeploymentByDeploymentId($serviceName, $deploymentName);
|
216 |
+
}
|
217 |
+
|
218 |
+
printf("%s\r\n", $result->$property);
|
219 |
+
}
|
220 |
+
|
221 |
+
/**
|
222 |
+
* Get role instances.
|
223 |
+
*
|
224 |
+
* @command-name GetRoleInstances
|
225 |
+
* @command-description Get role instance information (instance count, instance names, and instance statuses for a specified deployment.
|
226 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
227 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
228 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
229 |
+
* @command-parameter-for $serviceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env|Microsoft_Console_Command_ParameterSource_StdIn --Name Required. The hosted service DNS name to operate on.
|
230 |
+
* @command-parameter-for $deploymentSlot Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --BySlot Required if deployment name is omitted. The slot to retrieve property information for.
|
231 |
+
* @command-parameter-for $deploymentName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --ByName Required if deployment slot is omitted. The deployment name to retrieve property information for.
|
232 |
+
* @command-example Get role instances for production-slot deployment of the hosted service "phptest":
|
233 |
+
* @command-example GetRoleInstances -sid="<your_subscription_id>" -cert="mycert.pem"
|
234 |
+
* @command-example --Name="servicename" --BySlot="production"
|
235 |
+
*/
|
236 |
+
public function getRoleInstances($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $deploymentSlot, $deploymentName)
|
237 |
+
{
|
238 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
239 |
+
|
240 |
+
$result = null;
|
241 |
+
|
242 |
+
if (!is_null($deploymentSlot) && $deploymentSlot != '') {
|
243 |
+
$deploymentSlot = strtolower($deploymentSlot);
|
244 |
+
|
245 |
+
$result = $client->getRoleInstancesByDeploymentSlot($serviceName, $deploymentSlot);
|
246 |
+
} else {
|
247 |
+
$result = $client->getRoleInstancesByDeploymentId($serviceName, $deploymentName);
|
248 |
+
}
|
249 |
+
|
250 |
+
printf("InstanceCount:%s\n\n", count($result));
|
251 |
+
$instance_index = 0;
|
252 |
+
foreach($result as $instance) {
|
253 |
+
printf("Instance%s\n", $instance_index );
|
254 |
+
printf("Name:%s\n", $instance['instancename']);
|
255 |
+
printf("Status:%s\n", $instance['instancestatus']);
|
256 |
+
printf("\n");
|
257 |
+
$instance_index++;
|
258 |
+
}
|
259 |
+
}
|
260 |
+
|
261 |
+
/**
|
262 |
+
* Get role instance properties.
|
263 |
+
*
|
264 |
+
* @command-name GetRoleInstanceProperties
|
265 |
+
* @command-description Get role instance information for a specified role instance.
|
266 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
267 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
268 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
269 |
+
* @command-parameter-for $serviceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env|Microsoft_Console_Command_ParameterSource_StdIn --Name Required. The hosted service DNS name to operate on.
|
270 |
+
* @command-parameter-for $deploymentSlot Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --BySlot Required if deployment name is omitted. The slot to retrieve property information for.
|
271 |
+
* @command-parameter-for $deploymentName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --ByName Required if deployment slot is omitted. The deployment name to retrieve property information for.
|
272 |
+
* @command-parameter-for $instanceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --InstanceName Required. The role instance name to retrieve properties for.
|
273 |
+
* @command-example Get role instance properties for role "role_0" for production-slot deployment of the hosted service "phptest":
|
274 |
+
* @command-example GetRoleInstances -sid="<your_subscription_id>" -cert="mycert.pem"
|
275 |
+
* @command-example --Name="servicename" --BySlot="production" --InstanceName="role_0"
|
276 |
+
*/
|
277 |
+
public function getRoleInstanceProperties($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $deploymentSlot, $deploymentName, $instanceName)
|
278 |
+
{
|
279 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
280 |
+
|
281 |
+
$result = null;
|
282 |
+
|
283 |
+
if (!is_null($deploymentSlot) && $deploymentSlot != '') {
|
284 |
+
$deploymentSlot = strtolower($deploymentSlot);
|
285 |
+
|
286 |
+
$result = $client->getRoleInstancesByDeploymentSlot($serviceName, $deploymentSlot);
|
287 |
+
} else {
|
288 |
+
$result = $client->getRoleInstancesByDeploymentId($serviceName, $deploymentName);
|
289 |
+
}
|
290 |
+
|
291 |
+
$instance_found = false;
|
292 |
+
|
293 |
+
foreach($result as $instance) {
|
294 |
+
if($instance['instancename'] == $instanceName) {
|
295 |
+
printf("Status: \t%s\n", $instance['instancestatus']);
|
296 |
+
printf("Upgrade domain: %s\n", $instance['instanceupgradedomain']);
|
297 |
+
printf("Fault domain: \t%s\n", $instance['instancefaultdomain']);
|
298 |
+
printf("Size: \t\t%s\n", $instance['instancesize']);
|
299 |
+
printf("\n");
|
300 |
+
$instance_found = true;
|
301 |
+
continue;
|
302 |
+
}
|
303 |
+
}
|
304 |
+
|
305 |
+
if(!$instance_found) {
|
306 |
+
printf("No instance with name %s was found.", $instanceName);
|
307 |
+
}
|
308 |
+
}
|
309 |
+
|
310 |
+
/**
|
311 |
+
* Get a role instance property.
|
312 |
+
*
|
313 |
+
* @command-name GetRoleInstanceProperty
|
314 |
+
* @command-description Get a specified role instance property for a specified role instance.
|
315 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
316 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
317 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
318 |
+
* @command-parameter-for $serviceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env|Microsoft_Console_Command_ParameterSource_StdIn --Name Required. The hosted service DNS name to operate on.
|
319 |
+
* @command-parameter-for $deploymentSlot Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --BySlot Required if deployment name is omitted. The slot to retrieve property information for.
|
320 |
+
* @command-parameter-for $deploymentName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --ByName Required if deployment slot is omitted. The deployment name to retrieve property information for.
|
321 |
+
* @command-parameter-for $instanceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --InstanceName Required. The role instance name to retrieve properties for.
|
322 |
+
* @command-parameter-for $propertyName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --PropertyName Required. The role instance property to retrieve.
|
323 |
+
* @command-example Get role instance property "Status" for role "role_0" for production-slot deployment of the hosted service "phptest":
|
324 |
+
* @command-example GetRoleInstances -sid="<your_subscription_id>" -cert="mycert.pem"
|
325 |
+
* @command-example --Name="servicename" --BySlot="production" --InstanceName="role_0" --PropertyName="Status"
|
326 |
+
* @command-example Possible values for PropertyName are "Role Name", "Status", "Upgrade Domain", "Fault Domain", "Size"
|
327 |
+
*/
|
328 |
+
public function getRoleInstanceProperty($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $deploymentSlot, $deploymentName, $instanceName, $propertyName)
|
329 |
+
{
|
330 |
+
if (!in_array($propertyName, array("Role Name", "Status", "Upgrade Domain", "Fault Domain", "Size"))) {
|
331 |
+
printf("%s is not a valid property name. Valid property names are 'Role Name', 'Status', 'Upgrade Domain', 'Fault Domain', 'Size'", $propertyName);
|
332 |
+
return;
|
333 |
+
}
|
334 |
+
|
335 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
336 |
+
|
337 |
+
$result = null;
|
338 |
+
|
339 |
+
if (!is_null($deploymentSlot) && $deploymentSlot != '') {
|
340 |
+
$deploymentSlot = strtolower($deploymentSlot);
|
341 |
+
|
342 |
+
$result = $client->getRoleInstancesByDeploymentSlot($serviceName, $deploymentSlot);
|
343 |
+
} else {
|
344 |
+
$result = $client->getRoleInstancesByDeploymentId($serviceName, $deploymentName);
|
345 |
+
}
|
346 |
+
|
347 |
+
$instance_found = false;
|
348 |
+
|
349 |
+
foreach($result as $instance) {
|
350 |
+
if($instance['instancename'] == $instanceName) {
|
351 |
+
switch($propertyName) {
|
352 |
+
case "Role Name":
|
353 |
+
printf($instance['rolename']);
|
354 |
+
break;
|
355 |
+
case "Status":
|
356 |
+
printf($instance['instancestatus']);
|
357 |
+
break;
|
358 |
+
case "Upgrade Domain":
|
359 |
+
printf($instance['instanceupgradedomain']);
|
360 |
+
break;
|
361 |
+
case "Fault Domain":
|
362 |
+
printf($instance['instancefaultdomain']);
|
363 |
+
break;
|
364 |
+
case "Size":
|
365 |
+
printf($instance['instancesize']);
|
366 |
+
break;
|
367 |
+
}
|
368 |
+
|
369 |
+
$instance_found = true;
|
370 |
+
continue;
|
371 |
+
}
|
372 |
+
}
|
373 |
+
|
374 |
+
if(!$instance_found) {
|
375 |
+
printf("No instance with name %s was found.", $instanceName);
|
376 |
+
}
|
377 |
+
}
|
378 |
+
|
379 |
+
/**
|
380 |
+
* Swap deployment slots (perform VIP swap).
|
381 |
+
*
|
382 |
+
* @command-name Swap
|
383 |
+
* @command-description Swap deployment slots (perform VIP swap).
|
384 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
385 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
386 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
387 |
+
* @command-parameter-for $serviceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env|Microsoft_Console_Command_ParameterSource_StdIn --Name Required. The hosted service DNS name to operate on.
|
388 |
+
* @command-parameter-for $waitForOperation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete?
|
389 |
+
* @command-example Swap deployment slots:
|
390 |
+
* @command-example Swap -sid="<your_subscription_id>" -cert="mycert.pem" --Name="servicename"
|
391 |
+
*/
|
392 |
+
public function swapCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $waitForOperation = false)
|
393 |
+
{
|
394 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
395 |
+
|
396 |
+
$productionDeploymentName = null;
|
397 |
+
try { $productionDeploymentName = $client->getDeploymentBySlot($serviceName, 'production')->Name; } catch (Exception $ex) {}
|
398 |
+
|
399 |
+
$stagingDeploymentName = null;
|
400 |
+
try { $stagingDeploymentName = $client->getDeploymentBySlot($serviceName, 'staging')->Name; } catch (Exception $ex) {}
|
401 |
+
|
402 |
+
if (is_null($productionDeploymentName)) {
|
403 |
+
$productionDeploymentName = $stagingDeploymentName;
|
404 |
+
}
|
405 |
+
if (is_null($stagingDeploymentName)) {
|
406 |
+
throw new Microsoft_Console_Exception('Swapping deployment slots is only possible when both slots have an active deployment or when production slot is empty.');
|
407 |
+
}
|
408 |
+
|
409 |
+
$client->swapDeployment($serviceName, $productionDeploymentName, $stagingDeploymentName);
|
410 |
+
|
411 |
+
if ($waitForOperation) {
|
412 |
+
$client->waitForOperation();
|
413 |
+
}
|
414 |
+
echo $client->getLastRequestId();
|
415 |
+
}
|
416 |
+
|
417 |
+
/**
|
418 |
+
* Deletes a deployment.
|
419 |
+
*
|
420 |
+
* @command-name Delete
|
421 |
+
* @command-description Deletes a deployment.
|
422 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
423 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
424 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
425 |
+
* @command-parameter-for $serviceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env|Microsoft_Console_Command_ParameterSource_StdIn --Name Required. The hosted service DNS name to operate on.
|
426 |
+
* @command-parameter-for $deploymentSlot Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --BySlot Required if deployment name is omitted. The slot to retrieve property information for.
|
427 |
+
* @command-parameter-for $deploymentName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --ByName Required if deployment slot is omitted. The deployment name to retrieve property information for.
|
428 |
+
* @command-parameter-for $waitForOperation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete?
|
429 |
+
* @command-example Delete a deployment:
|
430 |
+
* @command-example Delete -sid="<your_subscription_id>" -cert="mycert.pem" --Name="hostedservicename" --DeploymentName="deploymentname"
|
431 |
+
*/
|
432 |
+
public function deleteCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $deploymentSlot, $deploymentName, $waitForOperation = false)
|
433 |
+
{
|
434 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
435 |
+
|
436 |
+
if (!is_null($deploymentSlot) && $deploymentSlot != '') {
|
437 |
+
$deploymentSlot = strtolower($deploymentSlot);
|
438 |
+
|
439 |
+
$client->deleteDeploymentBySlot($serviceName, $deploymentSlot);
|
440 |
+
} else {
|
441 |
+
$client->deleteDeploymentByDeploymentId($serviceName, $deploymentName);
|
442 |
+
}
|
443 |
+
|
444 |
+
if ($waitForOperation) {
|
445 |
+
$client->waitForOperation();
|
446 |
+
}
|
447 |
+
echo $client->getLastRequestId();
|
448 |
+
}
|
449 |
+
|
450 |
+
/**
|
451 |
+
* Updates a deployment's configuration.
|
452 |
+
*
|
453 |
+
* @command-name UpdateConfig
|
454 |
+
* @command-description Updates a deployment's configuration.
|
455 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
456 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
457 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
458 |
+
* @command-parameter-for $serviceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env|Microsoft_Console_Command_ParameterSource_StdIn --Name Required. The hosted service DNS name to operate on.
|
459 |
+
* @command-parameter-for $deploymentSlot Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --BySlot Required if deployment name is omitted. The slot to retrieve property information for.
|
460 |
+
* @command-parameter-for $deploymentName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --ByName Required if deployment slot is omitted. The deployment name to retrieve property information for.
|
461 |
+
* @command-parameter-for $serviceConfigurationLocation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --ServiceConfigLocation Required. The location of the .cspkg file.
|
462 |
+
* @command-parameter-for $waitForOperation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete?
|
463 |
+
* @command-example Update configuration:
|
464 |
+
* @command-example UpdateConfig -sid="<your_subscription_id>" -cert="mycert.pem"
|
465 |
+
* @command-example --Name="hostedservicename" --ByName="deploymentname"
|
466 |
+
* @command-example --ServiceConfigLocation=".\ServiceConfiguration.cscfg"
|
467 |
+
*/
|
468 |
+
public function updateConfigurationCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $deploymentSlot, $deploymentName, $serviceConfigurationLocation, $waitForOperation = false)
|
469 |
+
{
|
470 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
471 |
+
|
472 |
+
if (!is_null($deploymentSlot) && $deploymentSlot != '') {
|
473 |
+
$deploymentSlot = strtolower($deploymentSlot);
|
474 |
+
|
475 |
+
$client->configureDeploymentBySlot($serviceName, $deploymentSlot, $serviceConfigurationLocation);
|
476 |
+
} else {
|
477 |
+
$client->configureDeploymentByDeploymentId($serviceName, $deploymentName, $serviceConfigurationLocation);
|
478 |
+
}
|
479 |
+
|
480 |
+
if ($waitForOperation) {
|
481 |
+
$client->waitForOperation();
|
482 |
+
}
|
483 |
+
echo $client->getLastRequestId();
|
484 |
+
}
|
485 |
+
|
486 |
+
/**
|
487 |
+
* Updates a deployment's status.
|
488 |
+
*
|
489 |
+
* @command-name UpdateStatus
|
490 |
+
* @command-description Updates a deployment's status.
|
491 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
492 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
493 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
494 |
+
* @command-parameter-for $serviceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env|Microsoft_Console_Command_ParameterSource_StdIn --Name Required. The hosted service DNS name to operate on.
|
495 |
+
* @command-parameter-for $deploymentSlot Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --BySlot Required if deployment name is omitted. The slot to retrieve property information for.
|
496 |
+
* @command-parameter-for $deploymentName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --ByName Required if deployment slot is omitted. The deployment name to retrieve property information for.
|
497 |
+
* @command-parameter-for $newStatus Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Status Required. New status (Suspended|Running)
|
498 |
+
* @command-parameter-for $waitForOperation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete?
|
499 |
+
* @command-example Suspend a deployment:
|
500 |
+
* @command-example UpdateStatus -sid="<your_subscription_id>" -cert="mycert.pem"
|
501 |
+
* @command-example --Name="hostedservicename" --ByName="deploymentname"
|
502 |
+
* @command-example --Status="Suspended"
|
503 |
+
*/
|
504 |
+
public function updateStatusCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $deploymentSlot, $deploymentName, $newStatus, $waitForOperation = false)
|
505 |
+
{
|
506 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
507 |
+
|
508 |
+
if (!is_null($deploymentSlot) && $deploymentSlot != '') {
|
509 |
+
$deploymentSlot = strtolower($deploymentSlot);
|
510 |
+
|
511 |
+
$client->updateDeploymentStatusBySlot($serviceName, $deploymentSlot, $newStatus);
|
512 |
+
} else {
|
513 |
+
$client->updateDeploymentStatusByDeploymentId($serviceName, $deploymentName, $newStatus);
|
514 |
+
}
|
515 |
+
|
516 |
+
if ($waitForOperation) {
|
517 |
+
$client->waitForOperation();
|
518 |
+
}
|
519 |
+
echo $client->getLastRequestId();
|
520 |
+
}
|
521 |
+
|
522 |
+
/**
|
523 |
+
* Updates the number of instances.
|
524 |
+
*
|
525 |
+
* @command-name EditInstanceNumber
|
526 |
+
* @command-description Updates the number of instances.
|
527 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
528 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
529 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
530 |
+
* @command-parameter-for $serviceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env|Microsoft_Console_Command_ParameterSource_StdIn --Name Required. The hosted service DNS name to operate on.
|
531 |
+
* @command-parameter-for $deploymentSlot Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --BySlot Required if deployment name is omitted. The slot to retrieve property information for.
|
532 |
+
* @command-parameter-for $deploymentName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --ByName Required if deployment slot is omitted. The deployment name to retrieve property information for.
|
533 |
+
* @command-parameter-for $roleName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --RoleName|-r Required. Role name to update the number of instances for.
|
534 |
+
* @command-parameter-for $newInstanceNumber Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --NewInstanceNumber|-i Required. New number of instances.
|
535 |
+
* @command-parameter-for $waitForOperation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete?
|
536 |
+
* @command-example Suspend a deployment:
|
537 |
+
* @command-example EditInstanceNumber -sid="<your_subscription_id>" -cert="mycert.pem"
|
538 |
+
* @command-example --Name="hostedservicename" --ByName="deploymentname"
|
539 |
+
* @command-example --NewInstanceNumber="4"
|
540 |
+
*/
|
541 |
+
public function editInstanceNumberCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $deploymentSlot, $deploymentName, $roleName, $newInstanceNumber = 1, $waitForOperation = false)
|
542 |
+
{
|
543 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
544 |
+
|
545 |
+
if (!is_null($deploymentSlot) && $deploymentSlot != '') {
|
546 |
+
$deploymentSlot = strtolower($deploymentSlot);
|
547 |
+
|
548 |
+
$client->setInstanceCountBySlot($serviceName, $deploymentSlot, $roleName, $newInstanceNumber);
|
549 |
+
} else {
|
550 |
+
$client->setInstanceCountByDeploymentId($serviceName, $deploymentName, $roleName, $newInstanceNumber);
|
551 |
+
}
|
552 |
+
|
553 |
+
if ($waitForOperation) {
|
554 |
+
$client->waitForOperation();
|
555 |
+
}
|
556 |
+
echo $client->getLastRequestId();
|
557 |
+
}
|
558 |
+
|
559 |
+
/**
|
560 |
+
* Reboots a role instance.
|
561 |
+
*
|
562 |
+
* @command-name RebootInstance
|
563 |
+
* @command-description Reboots a role instance.
|
564 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
565 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
566 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
567 |
+
* @command-parameter-for $serviceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env|Microsoft_Console_Command_ParameterSource_StdIn --Name Required. The hosted service DNS name to operate on.
|
568 |
+
* @command-parameter-for $deploymentSlot Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --BySlot Required if deployment name is omitted. The slot to retrieve property information for.
|
569 |
+
* @command-parameter-for $deploymentName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --ByName Required if deployment slot is omitted. The deployment name to retrieve property information for.
|
570 |
+
* @command-parameter-for $instanceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --RoleInstanceName Required. The name of the role instance to work with.
|
571 |
+
* @command-parameter-for $waitForOperation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete?
|
572 |
+
* @command-example Reboot a role instance:
|
573 |
+
* @command-example RebootInstance -sid="<your_subscription_id>" -cert="mycert.pem"
|
574 |
+
* @command-example --Name="hostedservicename" --ByName="deploymentname"
|
575 |
+
* @command-example --RoleInstanceName="PhpOnAzure.Web_IN_0"
|
576 |
+
*/
|
577 |
+
public function rebootInstanceCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $deploymentSlot, $deploymentName, $instanceName, $waitForOperation = false)
|
578 |
+
{
|
579 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
580 |
+
|
581 |
+
if (!is_null($deploymentSlot) && $deploymentSlot != '') {
|
582 |
+
$deploymentSlot = strtolower($deploymentSlot);
|
583 |
+
|
584 |
+
$client->rebootRoleInstanceBySlot($serviceName, $deploymentSlot, $instanceName);
|
585 |
+
} else {
|
586 |
+
$client->rebootRoleInstanceByDeploymentId($serviceName, $deploymentName, $instanceName);
|
587 |
+
}
|
588 |
+
|
589 |
+
if ($waitForOperation) {
|
590 |
+
$client->waitForOperation();
|
591 |
+
}
|
592 |
+
echo $client->getLastRequestId();
|
593 |
+
}
|
594 |
+
|
595 |
+
/**
|
596 |
+
* Reimages a role instance.
|
597 |
+
*
|
598 |
+
* @command-name ReimageInstance
|
599 |
+
* @command-description Reimages a role instance.
|
600 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
601 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
602 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
603 |
+
* @command-parameter-for $serviceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env|Microsoft_Console_Command_ParameterSource_StdIn --Name Required. The hosted service DNS name to operate on.
|
604 |
+
* @command-parameter-for $deploymentSlot Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --BySlot Required if deployment name is omitted. The slot to retrieve property information for.
|
605 |
+
* @command-parameter-for $deploymentName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --ByName Required if deployment slot is omitted. The deployment name to retrieve property information for.
|
606 |
+
* @command-parameter-for $instanceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --RoleInstanceName Required. The name of the role instance to work with.
|
607 |
+
* @command-parameter-for $waitForOperation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete?
|
608 |
+
* @command-example Reimage a role instance:
|
609 |
+
* @command-example ReimageInstance -sid="<your_subscription_id>" -cert="mycert.pem"
|
610 |
+
* @command-example --Name="hostedservicename" --ByName="deploymentname"
|
611 |
+
* @command-example --RoleInstanceName="PhpOnAzure.Web_IN_0"
|
612 |
+
*/
|
613 |
+
public function reimageInstanceCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $deploymentSlot, $deploymentName, $instanceName, $waitForOperation = false)
|
614 |
+
{
|
615 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
616 |
+
|
617 |
+
if (!is_null($deploymentSlot) && $deploymentSlot != '') {
|
618 |
+
$deploymentSlot = strtolower($deploymentSlot);
|
619 |
+
|
620 |
+
$client->reimageRoleInstanceBySlot($serviceName, $deploymentSlot, $instanceName);
|
621 |
+
} else {
|
622 |
+
$client->reimageRoleInstanceByDeploymentId($serviceName, $deploymentName, $instanceName);
|
623 |
+
}
|
624 |
+
|
625 |
+
if ($waitForOperation) {
|
626 |
+
$client->waitForOperation();
|
627 |
+
}
|
628 |
+
echo $client->getLastRequestId();
|
629 |
+
}
|
630 |
+
|
631 |
+
/**
|
632 |
+
* Upgrades a deployment from a remote package file and service configuration.
|
633 |
+
*
|
634 |
+
* @command-name UpgradeFromStorage
|
635 |
+
* @command-description Upgrades a deployment from a remote package file and service configuration.
|
636 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
637 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
638 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
639 |
+
* @command-parameter-for $serviceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Name Required. The hosted service DNS name to operate on.
|
640 |
+
* @command-parameter-for $deploymentSlot Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --BySlot Required if deployment name is omitted. The slot to retrieve property information for.
|
641 |
+
* @command-parameter-for $deploymentName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --ByName Required if deployment slot is omitted. The deployment name to retrieve property information for.
|
642 |
+
* @command-parameter-for $label Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Label Required. The label for the deployment.
|
643 |
+
* @command-parameter-for $packageUrl Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --PackageUrl Required. The remote location of the .cspkg file.
|
644 |
+
* @command-parameter-for $serviceConfigurationLocation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --ServiceConfigLocation Required. The location of the .cspkg file.
|
645 |
+
* @command-parameter-for $mode Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Mode Required. Set to auto|manual.
|
646 |
+
* @command-parameter-for $roleName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --RoleName Optional. Role name to upgrade.
|
647 |
+
* @command-parameter-for $waitForOperation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete?
|
648 |
+
*/
|
649 |
+
public function upgradeFromStorageCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $deploymentSlot, $deploymentName, $label, $packageUrl, $serviceConfigurationLocation, $mode = 'auto', $roleName = null, $waitForOperation = false)
|
650 |
+
{
|
651 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
652 |
+
|
653 |
+
if (!is_null($deploymentSlot) && $deploymentSlot != '') {
|
654 |
+
$deploymentSlot = strtolower($deploymentSlot);
|
655 |
+
|
656 |
+
$client->upgradeDeploymentBySlot($serviceName, $deploymentSlot, $label, $packageUrl, $serviceConfigurationLocation, $mode, $roleName);
|
657 |
+
} else {
|
658 |
+
$client->upgradeDeploymentByDeploymentId($serviceName, $deploymentName, $label, $packageUrl, $serviceConfigurationLocation, $mode, $roleName);
|
659 |
+
}
|
660 |
+
|
661 |
+
if ($waitForOperation) {
|
662 |
+
$client->waitForOperation();
|
663 |
+
}
|
664 |
+
echo $client->getLastRequestId();
|
665 |
+
}
|
666 |
+
|
667 |
+
/**
|
668 |
+
* Upgrades a deployment from a local package file and service configuration.
|
669 |
+
*
|
670 |
+
* @command-name UpgradeFromLocal
|
671 |
+
* @command-description Upgrades a deployment from a local package file and service configuration.
|
672 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
673 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
674 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
675 |
+
* @command-parameter-for $serviceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Name Required. The hosted service DNS name to operate on.
|
676 |
+
* @command-parameter-for $deploymentSlot Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --BySlot Required if deployment name is omitted. The slot to retrieve property information for.
|
677 |
+
* @command-parameter-for $deploymentName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --ByName Required if deployment slot is omitted. The deployment name to retrieve property information for.
|
678 |
+
* @command-parameter-for $label Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Label Required. The label for the deployment.
|
679 |
+
* @command-parameter-for $packageLocation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_StdIn --PackageLocation Required. The location of the .cspkg file.
|
680 |
+
* @command-parameter-for $serviceConfigurationLocation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --ServiceConfigLocation Required. The location of the .cspkg file.
|
681 |
+
* @command-parameter-for $storageAccount Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --StorageAccount Required. Storage account to use when creating the deployment.
|
682 |
+
* @command-parameter-for $mode Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Mode Required. Set to auto|manual.
|
683 |
+
* @command-parameter-for $roleName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --RoleName Optional. Role name to upgrade.
|
684 |
+
* @command-parameter-for $waitForOperation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete?
|
685 |
+
*/
|
686 |
+
public function upgradeFromLocalCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $deploymentSlot, $deploymentName, $label, $packageLocation, $serviceConfigurationLocation, $storageAccount, $mode = 'auto', $roleName = null, $waitForOperation = false)
|
687 |
+
{
|
688 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
689 |
+
|
690 |
+
$blobClient = $client->createBlobClientForService($storageAccount);
|
691 |
+
$blobClient->createContainerIfNotExists('phpazuredeployments');
|
692 |
+
$blobClient->putBlob('phpazuredeployments', basename($packageLocation), $packageLocation);
|
693 |
+
$package = $blobClient->getBlobInstance('phpazuredeployments', basename($packageLocation));
|
694 |
+
|
695 |
+
if (!is_null($deploymentSlot) && $deploymentSlot != '') {
|
696 |
+
$deploymentSlot = strtolower($deploymentSlot);
|
697 |
+
|
698 |
+
$client->upgradeDeploymentBySlot($serviceName, $deploymentSlot, $label, $package->Url, $serviceConfigurationLocation, $mode, $roleName);
|
699 |
+
} else {
|
700 |
+
$client->upgradeDeploymentByDeploymentId($serviceName, $deploymentName, $label, $package->Url, $serviceConfigurationLocation, $mode, $roleName);
|
701 |
+
}
|
702 |
+
|
703 |
+
$client->waitForOperation();
|
704 |
+
$blobClient->deleteBlob('phpazuredeployments', basename($packageLocation));
|
705 |
+
|
706 |
+
if ($waitForOperation) {
|
707 |
+
$client->waitForOperation();
|
708 |
+
}
|
709 |
+
echo $client->getLastRequestId();
|
710 |
+
}
|
711 |
+
|
712 |
+
/**
|
713 |
+
* Walks upgrade domains.
|
714 |
+
*
|
715 |
+
* @command-name WalkUpgradeDomains
|
716 |
+
* @command-description Walks upgrade domains.
|
717 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
718 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
719 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
720 |
+
* @command-parameter-for $serviceName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env|Microsoft_Console_Command_ParameterSource_StdIn --Name Required. The hosted service DNS name to operate on.
|
721 |
+
* @command-parameter-for $deploymentSlot Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --BySlot Required if deployment name is omitted. The slot to retrieve property information for.
|
722 |
+
* @command-parameter-for $deploymentName Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --ByName Required if deployment slot is omitted. The deployment name to retrieve property information for.
|
723 |
+
* @command-parameter-for $upgradeDomain Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --UpgradeDomain Required. The upgrade domain index.
|
724 |
+
* @command-parameter-for $waitForOperation Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete?
|
725 |
+
*/
|
726 |
+
public function walkUpgradeDomainsCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $deploymentSlot, $deploymentName, $upgradeDomain, $waitForOperation = false)
|
727 |
+
{
|
728 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
729 |
+
|
730 |
+
if (!is_null($deploymentSlot) && $deploymentSlot != '') {
|
731 |
+
$deploymentSlot = strtolower($deploymentSlot);
|
732 |
+
|
733 |
+
$client->walkUpgradeDomainBySlot($serviceName, $deploymentSlot, $upgradeDomain);
|
734 |
+
} else {
|
735 |
+
$client->walkUpgradeDomainByDeploymentId($serviceName, $deploymentName, $upgradeDomain);
|
736 |
+
}
|
737 |
+
|
738 |
+
if ($waitForOperation) {
|
739 |
+
$client->waitForOperation();
|
740 |
+
}
|
741 |
+
echo $client->getLastRequestId();
|
742 |
+
}
|
743 |
+
}
|
744 |
+
|
745 |
+
Microsoft_Console_Command::bootstrap($_SERVER['argv']);
|
libs/Microsoft/WindowsAzure/CommandLine/GetAsynchronousOperation.php
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_Console
|
30 |
+
* @subpackage Exception
|
31 |
+
* @version $Id: Exception.php 55733 2011-01-03 09:17:16Z unknown $
|
32 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
33 |
+
* @license http://phpazure.codeplex.com/license
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @see Microsoft_AutoLoader
|
38 |
+
*/
|
39 |
+
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Asynchronous Operation commands
|
43 |
+
*
|
44 |
+
* @category Microsoft
|
45 |
+
* @package Microsoft_WindowsAzure_CommandLine
|
46 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
47 |
+
* @license http://phpazure.codeplex.com/license
|
48 |
+
*
|
49 |
+
* @command-handler getasynchronousoperation
|
50 |
+
* @command-handler-description Windows Azure Asynchronous Operation commands
|
51 |
+
* @command-handler-header Windows Azure SDK for PHP
|
52 |
+
* @command-handler-header Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
53 |
+
* @command-handler-footer Note: Parameters that are common across all commands can be stored
|
54 |
+
* @command-handler-footer in two dedicated environment variables.
|
55 |
+
* @command-handler-footer - SubscriptionId: The Windows Azure Subscription Id to operate on.
|
56 |
+
* @command-handler-footer - Certificate The Windows Azure .cer Management Certificate.
|
57 |
+
* @command-handler-footer
|
58 |
+
* @command-handler-footer All commands support the --ConfigurationFile or -F parameter.
|
59 |
+
* @command-handler-footer The parameter file is a simple INI file carrying one parameter
|
60 |
+
* @command-handler-footer value per line. It accepts the same parameters as one can
|
61 |
+
* @command-handler-footer use from the command line command.
|
62 |
+
*/
|
63 |
+
class Microsoft_WindowsAzure_CommandLine_GetAsynchronousOperation
|
64 |
+
extends Microsoft_Console_Command
|
65 |
+
{
|
66 |
+
/**
|
67 |
+
* Get information for a specific asynchronous request.
|
68 |
+
*
|
69 |
+
* @command-name GetInfo
|
70 |
+
* @command-description Get information for a specific asynchronous request.
|
71 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
72 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
73 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
74 |
+
* @command-parameter-for $requestId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_StdIn --RequestId|-r Required. The value returned by a call that starts an asynchronous operation to monitor.
|
75 |
+
* @command-example Get information for a specific asynchronous operation:
|
76 |
+
* @command-example GetInfo -sid="<your_subscription_id>" -cert="mycert.pem" -r="dab87a4b70e94a36805f5af2d20fc593"
|
77 |
+
*/
|
78 |
+
public function getInfoCommand($subscriptionId, $certificate, $certificatePassphrase, $requestId)
|
79 |
+
{
|
80 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
81 |
+
$result = $client->getOperationStatus($requestId);
|
82 |
+
|
83 |
+
$this->_displayObjectInformation($result, array('ID', 'Status', 'ErrorMessage'));
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Wait for a specific asynchronous request to complete.
|
88 |
+
*
|
89 |
+
* @command-name WaitFor
|
90 |
+
* @command-description Wait for a specific asynchronous request to complete.
|
91 |
+
* @command-parameter-for $subscriptionId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on.
|
92 |
+
* @command-parameter-for $certificate Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate.
|
93 |
+
* @command-parameter-for $certificatePassphrase Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Passphrase|-p The certificate passphrase. If not specified, a prompt will be displayed.
|
94 |
+
* @command-parameter-for $requestId Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_StdIn --RequestId|-r Required. The value returned by a call that starts an asynchronous operation to monitor.
|
95 |
+
* @command-parameter-for $interval Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --Interval|-i Optional. The interval between two status checks (in milliseconds).
|
96 |
+
* @command-example Wait for a specific asynchronous operation:
|
97 |
+
* @command-example WaitFor -sid="<your_subscription_id>" -cert="mycert.pem" -r="dab87a4b70e94a36805f5af2d20fc593"
|
98 |
+
*/
|
99 |
+
public function waitForCommand($subscriptionId, $certificate, $certificatePassphrase, $requestId, $interval = 250)
|
100 |
+
{
|
101 |
+
$client = new Microsoft_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase);
|
102 |
+
$client->waitForOperation($requestId, $interval);
|
103 |
+
}
|
104 |
+
}
|
105 |
+
|
106 |
+
Microsoft_Console_Command::bootstrap($_SERVER['argv']);
|
libs/Microsoft/WindowsAzure/CommandLine/Package.php
ADDED
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_Console
|
30 |
+
* @subpackage Exception
|
31 |
+
* @version $Id: Exception.php 55733 2011-01-03 09:17:16Z unknown $
|
32 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
33 |
+
* @license http://phpazure.codeplex.com/license
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @see Microsoft_AutoLoader
|
38 |
+
*/
|
39 |
+
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Package commands
|
43 |
+
*
|
44 |
+
* @category Microsoft
|
45 |
+
* @package Microsoft_WindowsAzure_CommandLine
|
46 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
47 |
+
* @license http://phpazure.codeplex.com/license
|
48 |
+
*
|
49 |
+
* @command-handler package
|
50 |
+
* @command-handler-description Windows Azure Package commands
|
51 |
+
* @command-handler-header Windows Azure SDK for PHP
|
52 |
+
* @command-handler-header Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
53 |
+
* @command-handler-footer
|
54 |
+
* @command-handler-footer All commands support the --ConfigurationFile or -F parameter.
|
55 |
+
* @command-handler-footer The parameter file is a simple INI file carrying one parameter
|
56 |
+
* @command-handler-footer value per line. It accepts the same parameters as one can
|
57 |
+
* @command-handler-footer use from the command line command.
|
58 |
+
*/
|
59 |
+
class Microsoft_WindowsAzure_CommandLine_Package
|
60 |
+
extends Microsoft_Console_Command
|
61 |
+
{
|
62 |
+
/**
|
63 |
+
* Packages a Windows Azure project structure.
|
64 |
+
*
|
65 |
+
* @command-name Create
|
66 |
+
* @command-description Packages a Windows Azure project structure.
|
67 |
+
*
|
68 |
+
* @command-parameter-for $path Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_StdIn --InputPath|-in Required. The path to package.
|
69 |
+
* @command-parameter-for $runDevFabric Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --RunDevFabric|-dev Required. Switch. Run and deploy to the Windows Azure development fabric.
|
70 |
+
* @command-parameter-for $outputPath Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --OutputPath|-out Optional. The output path for the resulting package.
|
71 |
+
*/
|
72 |
+
public function createPackageCommand($path, $runDevFabric, $outputPath)
|
73 |
+
{
|
74 |
+
// See if the $path variable requires some cleaning due to piping commands
|
75 |
+
if (strpos($path, 'finished at location: ') !== false) {
|
76 |
+
$path = explode('finished at location: ', $path);
|
77 |
+
$path = rtrim($path[1]);
|
78 |
+
}
|
79 |
+
|
80 |
+
// Create output paths
|
81 |
+
if (is_null($outputPath) || $outputPath == '') {
|
82 |
+
$outputPath = realpath($path . '/../');
|
83 |
+
}
|
84 |
+
$packageOut = $outputPath . '/' . basename($path) . '.cspkg';
|
85 |
+
if (!file_exists($outputPath)) {
|
86 |
+
if (@mkdir($outputPath) === false) {
|
87 |
+
throw new Microsoft_Console_Exception('The path ' . $outputPath . ' could not be created.');
|
88 |
+
}
|
89 |
+
}
|
90 |
+
|
91 |
+
// Find Windows Azure SDK bin folders
|
92 |
+
$csPackFolderCandidates = array_merge(
|
93 |
+
isset($_SERVER['ProgramFiles']) ? glob($_SERVER['ProgramFiles'] . '\Windows Azure SDK\*\bin', GLOB_NOSORT) : array(),
|
94 |
+
isset($_SERVER['ProgramFiles(x86)']) ? glob($_SERVER['ProgramFiles(x86)'] . '\Windows Azure SDK\*\bin', GLOB_NOSORT) : array(),
|
95 |
+
isset($_SERVER['ProgramW6432']) ? glob($_SERVER['ProgramW6432'] . '\Windows Azure SDK\*\bin', GLOB_NOSORT) : array()
|
96 |
+
);
|
97 |
+
if (count($csPackFolderCandidates) == 0) {
|
98 |
+
throw new Microsoft_Console_Exception('Could not locate the Windows Azure SDK. Download the tools from www.azure.com or using the Web Platform Installer.');
|
99 |
+
}
|
100 |
+
$cspack = '"' . $csPackFolderCandidates[count($csPackFolderCandidates) - 1] . '\cspack.exe' . '"';
|
101 |
+
|
102 |
+
$csRunFolderCandidates = array_merge(
|
103 |
+
isset($_SERVER['ProgramFiles']) ? glob($_SERVER['ProgramFiles'] . '\Windows Azure SDK\*\bin', GLOB_NOSORT) : array(),
|
104 |
+
isset($_SERVER['ProgramFiles(x86)']) ? glob($_SERVER['ProgramFiles(x86)'] . '\Windows Azure SDK\*\bin', GLOB_NOSORT) : array(),
|
105 |
+
isset($_SERVER['ProgramW6432']) ? glob($_SERVER['ProgramW6432'] . '\Windows Azure SDK\*\bin', GLOB_NOSORT) : array(),
|
106 |
+
isset($_SERVER['ProgramFiles']) ? glob($_SERVER['ProgramFiles'] . '\Windows Azure Emulator\emulator', GLOB_NOSORT) : array(),
|
107 |
+
isset($_SERVER['ProgramFiles(x86)']) ? glob($_SERVER['ProgramFiles(x86)'] . '\Windows Azure Emulator\emulator', GLOB_NOSORT) : array(),
|
108 |
+
isset($_SERVER['ProgramW6432']) ? glob($_SERVER['ProgramW6432'] . '\Windows Azure Emulator\emulator', GLOB_NOSORT) : array()
|
109 |
+
);
|
110 |
+
if (count($csRunFolderCandidates) == 0) {
|
111 |
+
throw new Microsoft_Console_Exception('Could not locate the Windows Azure SDK. Download the tools from www.azure.com or using the Web Platform Installer.');
|
112 |
+
}
|
113 |
+
$csrun = '"' . $csRunFolderCandidates[count($csRunFolderCandidates) - 1] . '\csrun.exe' . '"';
|
114 |
+
|
115 |
+
// Open the ServiceDefinition.csdef file and check for role paths
|
116 |
+
$serviceDefinitionFile = $path . '/ServiceDefinition.csdef';
|
117 |
+
if (!file_exists($serviceDefinitionFile)) {
|
118 |
+
throw new Microsoft_Console_Exception('Could not locate ServiceDefinition.csdef at ' . $serviceDefinitionFile . '.');
|
119 |
+
}
|
120 |
+
$serviceDefinition = simplexml_load_file($serviceDefinitionFile);
|
121 |
+
$xmlRoles = array();
|
122 |
+
|
123 |
+
if ($serviceDefinition->WebRole) {
|
124 |
+
if (count($serviceDefinition->WebRole) > 1) {
|
125 |
+
foreach ($serviceDefinition->WebRole as $role) {
|
126 |
+
$xmlRoles[] = $role;
|
127 |
+
}
|
128 |
+
} else {
|
129 |
+
$xmlRoles = array_merge($xmlRoles, array($serviceDefinition->WebRole));
|
130 |
+
}
|
131 |
+
}
|
132 |
+
if ($serviceDefinition->WorkerRole) {
|
133 |
+
if (count($serviceDefinition->WorkerRole) > 1) {
|
134 |
+
foreach ($serviceDefinition->WorkerRole as $role) {
|
135 |
+
$xmlRoles[] = $role;
|
136 |
+
}
|
137 |
+
} else {
|
138 |
+
$xmlRoles = array_merge($xmlRoles, array($serviceDefinition->WorkerRole));
|
139 |
+
}
|
140 |
+
}
|
141 |
+
|
142 |
+
// Build '/role:' command parameter
|
143 |
+
$roleArgs = array();
|
144 |
+
foreach ($xmlRoles as $xmlRole) {
|
145 |
+
if ($xmlRole["name"]) {
|
146 |
+
$roleArgs[] = '/role:' . $xmlRole["name"] . ';' . realpath($path . '/' . $xmlRole["name"]);
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
// Build command
|
151 |
+
$command = $cspack;
|
152 |
+
$args = array(
|
153 |
+
$path . '\ServiceDefinition.csdef',
|
154 |
+
implode(' ', $roleArgs),
|
155 |
+
'/out:' . $packageOut
|
156 |
+
);
|
157 |
+
if ($runDevFabric) {
|
158 |
+
$args[] = '/copyOnly';
|
159 |
+
}
|
160 |
+
passthru($command . ' ' . implode(' ', $args));
|
161 |
+
|
162 |
+
// Can we copy a configuration file?
|
163 |
+
$serviceConfigurationFile = $path . '/ServiceConfiguration.cscfg';
|
164 |
+
$serviceConfigurationFileOut = $outputPath . '/ServiceConfiguration.cscfg';
|
165 |
+
if (file_exists($serviceConfigurationFile) && !file_exists($serviceConfigurationFileOut)) {
|
166 |
+
copy($serviceConfigurationFile, $serviceConfigurationFileOut);
|
167 |
+
}
|
168 |
+
|
169 |
+
// Do we have to start the development fabric?
|
170 |
+
if ($runDevFabric) {
|
171 |
+
passthru($csrun . ' /devstore:start');
|
172 |
+
passthru($csrun . ' /devfabric:start');
|
173 |
+
passthru($csrun . ' /removeAll');
|
174 |
+
passthru($csrun . ' /run:"' . $packageOut . ';' . $serviceConfigurationFileOut . '" /launchBrowser');
|
175 |
+
}
|
176 |
+
|
177 |
+
// Echo package
|
178 |
+
echo $packageOut;
|
179 |
+
}
|
180 |
+
}
|
181 |
+
Microsoft_Console_Command::bootstrap($_SERVER['argv']);
|
libs/Microsoft/WindowsAzure/CommandLine/PackageScaffolder/PackageScaffolderAbstract.php
ADDED
@@ -0,0 +1,324 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_WindowsAzure
|
30 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
31 |
+
* @license http://phpazure.codeplex.com/license
|
32 |
+
* @version $Id: SharedKeyCredentials.php 14561 2009-05-07 08:05:12Z unknown $
|
33 |
+
*/
|
34 |
+
|
35 |
+
/**
|
36 |
+
* @see Microsoft_AutoLoader
|
37 |
+
*/
|
38 |
+
require_once dirname(__FILE__) . '/../../../AutoLoader.php';
|
39 |
+
|
40 |
+
/**
|
41 |
+
* @category Microsoft
|
42 |
+
* @package Microsoft_WindowsAzure_CommandLine
|
43 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
44 |
+
* @license http://phpazure.codeplex.com/license
|
45 |
+
*/
|
46 |
+
abstract class Microsoft_WindowsAzure_CommandLine_PackageScaffolder_PackageScaffolderAbstract
|
47 |
+
extends Microsoft_Console_Command
|
48 |
+
{
|
49 |
+
/**
|
50 |
+
* Displays the help information.
|
51 |
+
*
|
52 |
+
* @command-name <default>
|
53 |
+
* @command-name -h
|
54 |
+
* @command-name -help
|
55 |
+
* @command-description Displays the current help information.
|
56 |
+
*/
|
57 |
+
public function helpCommand() {
|
58 |
+
$handler = $this->getHandler();
|
59 |
+
$newline = "\r\n";
|
60 |
+
|
61 |
+
if (count($handler->headers) > 0) {
|
62 |
+
foreach ($handler->headers as $header) {
|
63 |
+
printf('%s%s', $header, $newline);
|
64 |
+
}
|
65 |
+
printf($newline);
|
66 |
+
}
|
67 |
+
printf('%s%s', $handler->description, $newline);
|
68 |
+
printf($newline);
|
69 |
+
printf('Available commands:%s', $newline);
|
70 |
+
foreach ($handler->commands as $command) {
|
71 |
+
if ($command->aliases[0] != '<default>') {
|
72 |
+
$description = str_split($command->description, 50);
|
73 |
+
printf(' %-25s %s%s', implode(', ', $command->aliases), $description[0], $newline);
|
74 |
+
for ($di = 1; $di < count($description); $di++) {
|
75 |
+
printf(' %-25s %s%s', '', $description[$di], $newline);
|
76 |
+
}
|
77 |
+
printf($newline);
|
78 |
+
|
79 |
+
if (count($command->parameters) > 0) {
|
80 |
+
foreach ($command->parameters as $parameter) {
|
81 |
+
if ($parameter->aliases[0] != '--Phar' && $parameter->aliases[0] != '--Path') {
|
82 |
+
$description = str_split($parameter->description, 50);
|
83 |
+
printf(' %-23s %s', implode(', ', $parameter->aliases), $newline);
|
84 |
+
for ($di = 0; $di < count($description); $di++) {
|
85 |
+
printf(' %-23s %s%s', '', $description[$di], $newline);
|
86 |
+
}
|
87 |
+
printf($newline);
|
88 |
+
}
|
89 |
+
}
|
90 |
+
}
|
91 |
+
printf($newline);
|
92 |
+
|
93 |
+
if (count($command->examples) > 0) {
|
94 |
+
printf(' Example usage:%s', $newline);
|
95 |
+
foreach ($command->examples as $example) {
|
96 |
+
printf(' %s%s', $example, $newline);
|
97 |
+
}
|
98 |
+
printf($newline);
|
99 |
+
}
|
100 |
+
}
|
101 |
+
}
|
102 |
+
|
103 |
+
if (count($handler->footers) > 0) {
|
104 |
+
printf($newline);
|
105 |
+
foreach ($handler->footers as $footer) {
|
106 |
+
printf('%s%s', $footer, $newline);
|
107 |
+
}
|
108 |
+
printf($newline);
|
109 |
+
}
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Writes output to STDERR, followed by a newline (optional)
|
114 |
+
*
|
115 |
+
* @param string $message
|
116 |
+
* @param string $newLine
|
117 |
+
*/
|
118 |
+
protected function log($message, $newLine = true)
|
119 |
+
{
|
120 |
+
if (error_reporting() === 0) {
|
121 |
+
return;
|
122 |
+
}
|
123 |
+
file_put_contents('php://stderr', $message . ($newLine ? "\r\n" : ''));
|
124 |
+
}
|
125 |
+
|
126 |
+
/**
|
127 |
+
* Extract resources to a file system path
|
128 |
+
*
|
129 |
+
* @param Phar $phar Phar archive.
|
130 |
+
* @param string $path Output path root.
|
131 |
+
*/
|
132 |
+
protected function extractResources(Phar $phar, $path)
|
133 |
+
{
|
134 |
+
$this->deleteDirectory($path);
|
135 |
+
$phar->extractTo($path);
|
136 |
+
@unlink($path . '/index.php');
|
137 |
+
@unlink($path . '/build.bat');
|
138 |
+
$this->copyDirectory($path . '/resources', $path . '/tmp', false);
|
139 |
+
$this->deleteDirectory($path . '/resources');
|
140 |
+
$this->copyDirectory($path . '/tmp', $path, false);
|
141 |
+
$this->deleteDirectory($path . '/tmp');
|
142 |
+
}
|
143 |
+
|
144 |
+
/**
|
145 |
+
* Apply file transforms.
|
146 |
+
*
|
147 |
+
* @param string $rootPath Root path.
|
148 |
+
* @param array $values Key/value array.
|
149 |
+
*/
|
150 |
+
protected function applyTransforms($rootPath, $values)
|
151 |
+
{
|
152 |
+
if (is_null($rootPath) || !is_string($rootPath) || empty($rootPath)) {
|
153 |
+
throw new InvalidArgumentException("Undefined \"rootPath\"");
|
154 |
+
}
|
155 |
+
|
156 |
+
if (is_dir($rootPath)) {
|
157 |
+
$d = dir($rootPath);
|
158 |
+
while ( false !== ( $entry = $d->read() ) ) {
|
159 |
+
if ( $entry == '.' || $entry == '..' ) {
|
160 |
+
continue;
|
161 |
+
}
|
162 |
+
$entry = $rootPath . '/' . $entry;
|
163 |
+
|
164 |
+
$this->applyTransforms($entry, $values);
|
165 |
+
}
|
166 |
+
$d->close();
|
167 |
+
} else {
|
168 |
+
$contents = file_get_contents($rootPath);
|
169 |
+
foreach ($values as $key => $value) {
|
170 |
+
$contents = str_replace('$' . $key . '$', $value, $contents);
|
171 |
+
}
|
172 |
+
file_put_contents($rootPath, $contents);
|
173 |
+
}
|
174 |
+
|
175 |
+
return true;
|
176 |
+
}
|
177 |
+
|
178 |
+
/**
|
179 |
+
* Create directory
|
180 |
+
*
|
181 |
+
* @param string $path Path of directory to create.
|
182 |
+
* @param boolean $abortIfExists Abort if directory exists.
|
183 |
+
* @param boolean $recursive Create parent directories if not exist.
|
184 |
+
*
|
185 |
+
* @return boolean
|
186 |
+
*/
|
187 |
+
protected function createDirectory($path, $abortIfExists = true, $recursive = true) {
|
188 |
+
if (is_null($path) || !is_string($path) || empty($path)) {
|
189 |
+
throw new InvalidArgumentException ("Undefined \"path\"" );
|
190 |
+
}
|
191 |
+
|
192 |
+
if (is_dir($path) && $abortIfExists) {
|
193 |
+
return false;
|
194 |
+
}
|
195 |
+
|
196 |
+
if (is_dir($path) ) {
|
197 |
+
@chmod($path, '0777');
|
198 |
+
if (!self::deleteDirectory($path) ) {
|
199 |
+
throw new RuntimeException("Failed to delete \"{$path}\".");
|
200 |
+
}
|
201 |
+
}
|
202 |
+
|
203 |
+
if (!mkdir($path, '0777', $recursive) || !is_dir($path)) {
|
204 |
+
throw new RuntimeException( "Failed to create directory \"{$path}\"." );
|
205 |
+
}
|
206 |
+
|
207 |
+
return true;
|
208 |
+
}
|
209 |
+
|
210 |
+
/**
|
211 |
+
* Fully copy a source directory to a target directory.
|
212 |
+
*
|
213 |
+
* @param string $sourcePath Source directory
|
214 |
+
* @param string $destinationPath Target directory
|
215 |
+
* @param boolean $abortIfExists Query re-creating target directory if exists
|
216 |
+
* @param octal $mode Changes access mode
|
217 |
+
*
|
218 |
+
* @return boolean
|
219 |
+
*/
|
220 |
+
protected function copyDirectory($sourcePath, $destinationPath, $abortIfExists = true, $mode = '0777') {
|
221 |
+
if (is_null($sourcePath) || !is_string($sourcePath) || empty($sourcePath)) {
|
222 |
+
throw new InvalidArgumentException("Undefined \"sourcePath\"");
|
223 |
+
}
|
224 |
+
|
225 |
+
if (is_null($destinationPath) || !is_string($destinationPath) || empty($destinationPath)) {
|
226 |
+
throw new InvalidArgumentException("Undefined \"destinationPath\"");
|
227 |
+
}
|
228 |
+
|
229 |
+
if (is_dir($destinationPath) && $abortIfExists) {
|
230 |
+
return false;
|
231 |
+
}
|
232 |
+
|
233 |
+
if (is_dir($sourcePath)) {
|
234 |
+
if (!is_dir($destinationPath) && !mkdir($destinationPath, $mode)) {
|
235 |
+
throw new RuntimeException("Failed to create target directory \"{$destinationPath}\"" );
|
236 |
+
}
|
237 |
+
$d = dir($sourcePath);
|
238 |
+
while ( false !== ( $entry = $d->read() ) ) {
|
239 |
+
if ( $entry == '.' || $entry == '..' ) {
|
240 |
+
continue;
|
241 |
+
}
|
242 |
+
$strSourceEntry = $sourcePath . '/' . $entry;
|
243 |
+
$strTargetEntry = $destinationPath . '/' . $entry;
|
244 |
+
if (is_dir($strSourceEntry) ) {
|
245 |
+
$this->copyDirectory(
|
246 |
+
$strSourceEntry,
|
247 |
+
$strTargetEntry,
|
248 |
+
false,
|
249 |
+
$mode
|
250 |
+
);
|
251 |
+
continue;
|
252 |
+
}
|
253 |
+
if (!copy($strSourceEntry, $strTargetEntry) ) {
|
254 |
+
throw new RuntimeException (
|
255 |
+
"Failed to copy"
|
256 |
+
. " file \"{$strSourceEntry}\""
|
257 |
+
. " to \"{$strTargetEntry}\""
|
258 |
+
);
|
259 |
+
}
|
260 |
+
}
|
261 |
+
$d->close();
|
262 |
+
} else {
|
263 |
+
if (!copy($sourcePath, $destinationPath)) {
|
264 |
+
throw new RuntimeException (
|
265 |
+
"Failed to copy"
|
266 |
+
. " file \"{$sourcePath}\""
|
267 |
+
. " to \"{$destinationPath}\""
|
268 |
+
|
269 |
+
);
|
270 |
+
}
|
271 |
+
}
|
272 |
+
|
273 |
+
return true;
|
274 |
+
}
|
275 |
+
|
276 |
+
/**
|
277 |
+
* Delete directory and all of its contents;
|
278 |
+
*
|
279 |
+
* @param string $path Directory path
|
280 |
+
* @return boolean
|
281 |
+
*/
|
282 |
+
protected function deleteDirectory($path)
|
283 |
+
{
|
284 |
+
if (is_null($path) || !is_string($path) || empty($path)) {
|
285 |
+
throw new InvalidArgumentException( "Undefined \"path\"" );
|
286 |
+
}
|
287 |
+
|
288 |
+
$handleDir = false;
|
289 |
+
if (is_dir($path) ) {
|
290 |
+
$handleDir = @opendir($path);
|
291 |
+
}
|
292 |
+
if (!$handleDir) {
|
293 |
+
return false;
|
294 |
+
}
|
295 |
+
@chmod($path, 0777);
|
296 |
+
while ($file = readdir($handleDir)) {
|
297 |
+
if ($file == '.' || $file == '..') {
|
298 |
+
continue;
|
299 |
+
}
|
300 |
+
|
301 |
+
$fsEntity = $path . "/" . $file;
|
302 |
+
|
303 |
+
if (is_dir($fsEntity)) {
|
304 |
+
$this->deleteDirectory($fsEntity);
|
305 |
+
continue;
|
306 |
+
}
|
307 |
+
|
308 |
+
if (is_file($fsEntity)) {
|
309 |
+
@unlink($fsEntity);
|
310 |
+
continue;
|
311 |
+
}
|
312 |
+
|
313 |
+
throw new LogicException (
|
314 |
+
"Unexpected file type: \"{$fsEntity}\""
|
315 |
+
);
|
316 |
+
}
|
317 |
+
|
318 |
+
@chmod($path, 0777);
|
319 |
+
closedir($handleDir);
|
320 |
+
@rmdir($path);
|
321 |
+
|
322 |
+
return true;
|
323 |
+
}
|
324 |
+
}
|
libs/Microsoft/WindowsAzure/CommandLine/Scaffolder.php
ADDED
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_Console
|
30 |
+
* @subpackage Exception
|
31 |
+
* @version $Id: Exception.php 55733 2011-01-03 09:17:16Z unknown $
|
32 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
33 |
+
* @license http://phpazure.codeplex.com/license
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @see Microsoft_AutoLoader
|
38 |
+
*/
|
39 |
+
require_once dirname(__FILE__) . '/../../AutoLoader.php';
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Scaffold commands
|
43 |
+
*
|
44 |
+
* @category Microsoft
|
45 |
+
* @package Microsoft_WindowsAzure_CommandLine
|
46 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
47 |
+
* @license http://phpazure.codeplex.com/license
|
48 |
+
*
|
49 |
+
* @command-handler scaffolder
|
50 |
+
* @command-handler-description Windows Azure Package commands
|
51 |
+
* @command-handler-header Windows Azure SDK for PHP
|
52 |
+
* @command-handler-header Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
53 |
+
* @command-handler-footer
|
54 |
+
* @command-handler-footer All commands support the --ConfigurationFile or -F parameter.
|
55 |
+
* @command-handler-footer The parameter file is a simple INI file carrying one parameter
|
56 |
+
* @command-handler-footer value per line. It accepts the same parameters as one can
|
57 |
+
* @command-handler-footer use from the command line command.
|
58 |
+
*/
|
59 |
+
class Microsoft_WindowsAzure_CommandLine_Scaffolder
|
60 |
+
extends Microsoft_Console_Command
|
61 |
+
{
|
62 |
+
/**
|
63 |
+
* Runs a scaffolder and creates a Windows Azure project structure which can be customized before packaging.
|
64 |
+
*
|
65 |
+
* @command-name Run
|
66 |
+
* @command-description Runs a scaffolder and creates a Windows Azure project structure which can be customized before packaging.
|
67 |
+
*
|
68 |
+
* @command-parameter-for $path Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --OutputPath|-out Required. The path to create the Windows Azure project structure.
|
69 |
+
* @command-parameter-for $scaffolder Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Scaffolder|-s Optional. The path to the scaffolder to use. Defaults to Scaffolders/DefaultScaffolder.phar
|
70 |
+
*/
|
71 |
+
public function runCommand($path, $scaffolder, $argv)
|
72 |
+
{
|
73 |
+
// Default parameter value
|
74 |
+
if (is_null($scaffolder) || $scaffolder == '') {
|
75 |
+
$scaffolder = 'DefaultScaffolder';
|
76 |
+
}
|
77 |
+
|
78 |
+
// Locate scaffolder
|
79 |
+
$scaffolderFile = realpath($scaffolder);
|
80 |
+
if (!is_file($scaffolderFile)) {
|
81 |
+
$scaffolderFile = realpath(dirname(__FILE__) . '/../../../../scaffolders/' . str_replace('.phar', '', $scaffolder) . '.phar');
|
82 |
+
}
|
83 |
+
|
84 |
+
// Verify scaffolder
|
85 |
+
if (!is_file($scaffolderFile)) {
|
86 |
+
throw new Microsoft_Console_Exception('Could not locate the given scaffolder: ' . $scaffolder);
|
87 |
+
}
|
88 |
+
|
89 |
+
// Include scaffolder
|
90 |
+
require_once $scaffolderFile;
|
91 |
+
$scaffolderClass = str_replace('.phar', '', basename($scaffolderFile));
|
92 |
+
if (!class_exists($scaffolderClass)) {
|
93 |
+
$scaffolderClass = str_replace('-', '_', str_replace('.', '_', $scaffolderClass));
|
94 |
+
if (!class_exists($scaffolderClass)) {
|
95 |
+
$scaffolderClass = substr($scaffolderClass, 0, strpos($scaffolderClass, '_'));
|
96 |
+
if (!class_exists($scaffolderClass)) {
|
97 |
+
throw new Microsoft_Console_Exception('Could not locate a class named ' . $scaffolderClass . ' in the given scaffolder: ' . $scaffolder . '. Make sure the scaffolder package contains a file named index.php and contains a class named Scaffolder.');
|
98 |
+
}
|
99 |
+
}
|
100 |
+
}
|
101 |
+
|
102 |
+
// Add command parameters
|
103 |
+
array_unshift($argv, '--OutputPath=' . $path);
|
104 |
+
array_unshift($argv, '--Phar=' . $scaffolderFile);
|
105 |
+
array_unshift($argv, 'Run');
|
106 |
+
array_unshift($argv, $scaffolderClass);
|
107 |
+
|
108 |
+
// Run scaffolder
|
109 |
+
Microsoft_Console_Command::bootstrap($argv);
|
110 |
+
|
111 |
+
// Echo output path
|
112 |
+
echo "$scaffolderClass finished at location: $path\r\n";
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Shows help information for a specific scaffolder.
|
117 |
+
*
|
118 |
+
* @command-name Help
|
119 |
+
* @command-description Shows help information for a specific scaffolder.
|
120 |
+
*
|
121 |
+
* @command-parameter-for $scaffolder Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile|Microsoft_Console_Command_ParameterSource_Env --Scaffolder|-s Optional. The path to the scaffolder to use. Defaults to Scaffolders/DefaultScaffolder.phar
|
122 |
+
*/
|
123 |
+
public function scaffolderhelpCommand($scaffolder, $argv)
|
124 |
+
{
|
125 |
+
// Default parameter value
|
126 |
+
if (is_null($scaffolder) || $scaffolder == '') {
|
127 |
+
$scaffolder = 'DefaultScaffolder';
|
128 |
+
}
|
129 |
+
|
130 |
+
// Locate scaffolder
|
131 |
+
$scaffolderFile = realpath($scaffolder);
|
132 |
+
if (!is_file($scaffolderFile)) {
|
133 |
+
$scaffolderFile = realpath(dirname(__FILE__) . '/../../../../scaffolders/' . str_replace('.phar', '', $scaffolder) . '.phar');
|
134 |
+
}
|
135 |
+
|
136 |
+
// Verify scaffolder
|
137 |
+
if (!is_file($scaffolderFile)) {
|
138 |
+
throw new Microsoft_Console_Exception('Could not locate the given scaffolder: ' . $scaffolder);
|
139 |
+
}
|
140 |
+
|
141 |
+
// Include scaffolder
|
142 |
+
require_once $scaffolderFile;
|
143 |
+
$scaffolderClass = str_replace('.phar', '', basename($scaffolderFile));
|
144 |
+
if (!class_exists($scaffolderClass)) {
|
145 |
+
$scaffolderClass = str_replace('-', '_', str_replace('.', '_', $scaffolderClass));
|
146 |
+
if (!class_exists($scaffolderClass)) {
|
147 |
+
$scaffolderClass = substr($scaffolderClass, 0, strpos($scaffolderClass, '_'));
|
148 |
+
if (!class_exists($scaffolderClass)) {
|
149 |
+
throw new Microsoft_Console_Exception('Could not locate a class named ' . $scaffolderClass . ' in the given scaffolder: ' . $scaffolder . '. Make sure the scaffolder package contains a file named index.php and contains a class named Scaffolder.');
|
150 |
+
}
|
151 |
+
}
|
152 |
+
}
|
153 |
+
|
154 |
+
// Add command parameters
|
155 |
+
array_unshift($argv, '-h');
|
156 |
+
array_unshift($argv, $scaffolderClass);
|
157 |
+
|
158 |
+
// Run scaffolder
|
159 |
+
Microsoft_Console_Command::bootstrap($argv);
|
160 |
+
}
|
161 |
+
|
162 |
+
/**
|
163 |
+
* Builds a scaffolder from a given path.
|
164 |
+
*
|
165 |
+
* @command-name Build
|
166 |
+
* @command-description Builds a scaffolder from a given path.
|
167 |
+
*
|
168 |
+
* @command-parameter-for $rootPath Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --InputPath|-in Required. The path to package into a scaffolder.
|
169 |
+
* @command-parameter-for $scaffolderFile Microsoft_Console_Command_ParameterSource_Argv|Microsoft_Console_Command_ParameterSource_ConfigFile --OutputFile|-out Required. The filename of the scaffolder.
|
170 |
+
*/
|
171 |
+
public function buildCommand($rootPath, $scaffolderFile)
|
172 |
+
{
|
173 |
+
$archive = new Phar($scaffolderFile);
|
174 |
+
$archive->buildFromIterator(
|
175 |
+
new RecursiveIteratorIterator(
|
176 |
+
new SourceControlFilteredRecursiveFilterIterator(
|
177 |
+
new RecursiveDirectoryIterator(realpath($rootPath)))),
|
178 |
+
realpath($rootPath));
|
179 |
+
|
180 |
+
echo $scaffolderFile;
|
181 |
+
}
|
182 |
+
}
|
183 |
+
Microsoft_Console_Command::bootstrap($_SERVER['argv']);
|
184 |
+
|
185 |
+
class SourceControlFilteredRecursiveFilterIterator
|
186 |
+
extends RecursiveFilterIterator {
|
187 |
+
public static $filters = array('.svn', '.git');
|
188 |
+
|
189 |
+
public function accept() {
|
190 |
+
return !in_array(
|
191 |
+
$this->current()->getFilename(), self::$filters, true);
|
192 |
+
}
|
193 |
+
}
|
libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/build.bat
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
php ..\..\Scaffolder.php Build -in="./" -out="..\..\..\..\..\..\scaffolders\DefaultScaffolder.phar"
|
libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/index.php
ADDED
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2009 - 2011, RealDolmen
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without
|
7 |
+
* modification, are permitted provided that the following conditions are met:
|
8 |
+
* * Redistributions of source code must retain the above copyright
|
9 |
+
* notice, this list of conditions and the following disclaimer.
|
10 |
+
* * Redistributions in binary form must reproduce the above copyright
|
11 |
+
* notice, this list of conditions and the following disclaimer in the
|
12 |
+
* documentation and/or other materials provided with the distribution.
|
13 |
+
* * Neither the name of RealDolmen nor the
|
14 |
+
* names of its contributors may be used to endorse or promote products
|
15 |
+
* derived from this software without specific prior written permission.
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
|
18 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20 |
+
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
|
21 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
+
*
|
28 |
+
* @category Microsoft
|
29 |
+
* @package Microsoft_WindowsAzure
|
30 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
31 |
+
* @license http://phpazure.codeplex.com/license
|
32 |
+
* @version $Id: SharedKeyCredentials.php 14561 2009-05-07 08:05:12Z unknown $
|
33 |
+
*/
|
34 |
+
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @category Microsoft
|
38 |
+
* @package Microsoft_WindowsAzure_CommandLine
|
39 |
+
* @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
40 |
+
* @license http://phpazure.codeplex.com/license
|
41 |
+
*
|
42 |
+
* @command-handler DefaultScaffolder
|
43 |
+
*
|
44 |
+
* @command-handler-description Windows Azure SDK for PHP default scaffolder.
|
45 |
+
* @command-handler-header Windows Azure SDK for PHP
|
46 |
+
* @command-handler-header Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
|
47 |
+
* @command-handler-footer
|
48 |
+
* @command-handler-footer The DefaultScaffolder automatically installs PHP
|
49 |
+
* @command-handler-footer to the Windows Azure virtual machine. If a customized
|
50 |
+
* @command-handler-footer php.ini is required, add it in the /php folder after
|
51 |
+
* @command-handler-footer running the scaffolder.
|
52 |
+
*/
|
53 |
+
class DefaultScaffolder
|
54 |
+
extends Microsoft_WindowsAzure_CommandLine_PackageScaffolder_PackageScaffolderAbstract
|
55 |
+
{
|
56 |
+
/**
|
57 |
+
* Runs a scaffolder and creates a Windows Azure project structure which can be customized before packaging.
|
58 |
+
*
|
59 |
+
* @command-name Run
|
60 |
+
* @command-description Runs the scaffolder.
|
61 |
+
*
|
62 |
+
* @command-parameter-for $scaffolderFile Argv --Phar Required. The scaffolder Phar file path. This is injected automatically.
|
63 |
+
* @command-parameter-for $rootPath Argv|ConfigFile --OutputPath|-out Required. The path to create the Windows Azure project structure. This is injected automatically.
|
64 |
+
* @command-parameter-for $diagnosticsConnectionString Argv|ConfigFile|Env --DiagnosticsConnectionString|-d Optional. The diagnostics connection string. This defaults to development storage.
|
65 |
+
* @command-parameter-for $webRoleNames Argv|ConfigFile|Env --WebRoles|-web Optional. A comma-separated list of names for web roles to create when scaffolding. Set this value to an empty parameter to skip creating a web role.
|
66 |
+
* @command-parameter-for $workerRoleNames Argv|ConfigFile|Env --WorkerRoles|-workers Optional. A comma-separated list of names for worker roles to create when scaffolding.
|
67 |
+
*/
|
68 |
+
public function runCommand($scaffolderFile, $rootPath, $webRoleNames = 'PhpOnAzure.Web', $workerRoleNames = '', $diagnosticsConnectionString = 'UseDevelopmentStorage=true')
|
69 |
+
{
|
70 |
+
// Load Phar
|
71 |
+
$phar = new Phar($scaffolderFile);
|
72 |
+
|
73 |
+
// Extract to disk
|
74 |
+
$this->log('Extracting resources...');
|
75 |
+
$this->createDirectory($rootPath);
|
76 |
+
$this->extractResources($phar, $rootPath);
|
77 |
+
$this->log('Extracted resources.');
|
78 |
+
|
79 |
+
// Configuration files
|
80 |
+
$serviceDefinitionIncludes = array();
|
81 |
+
$serviceConfigurationIncludes = array();
|
82 |
+
|
83 |
+
// Follow instructions listed in $webRoleNames and $workerRoleNames
|
84 |
+
$httpPort = 80;
|
85 |
+
$webRoles = explode(',', $webRoleNames);
|
86 |
+
foreach ($webRoles as $webRole) {
|
87 |
+
if ($webRole == '') continue;
|
88 |
+
|
89 |
+
$this->log('Creating web role "' . $webRole . '"...');
|
90 |
+
|
91 |
+
// Copy all files
|
92 |
+
$this->createDirectory($rootPath . '/' . $webRole);
|
93 |
+
$this->copyDirectory($rootPath . '/Common', $rootPath . '/' . $webRole, false);
|
94 |
+
$this->copyDirectory($rootPath . '/CommonWeb', $rootPath . '/' . $webRole, false);
|
95 |
+
|
96 |
+
// Configure role
|
97 |
+
$this->log(' Configuring web role "' . $webRole . '"...');
|
98 |
+
|
99 |
+
$serviceDefinitionFile = $rootPath . '/' . $webRole . '/ServiceDefinition.' . $webRole . '.csdef';
|
100 |
+
$serviceConfigurationFile = $rootPath . '/' . $webRole . '/ServiceConfiguration.' . $webRole . '.cscfg';
|
101 |
+
copy($rootPath . '/ServiceDefinition.Web.csdef', $serviceDefinitionFile);
|
102 |
+
copy($rootPath . '/ServiceConfiguration.Web.cscfg', $serviceConfigurationFile);
|
103 |
+
|
104 |
+
$this->applyTransforms($rootPath . '/' . $webRole, array(
|
105 |
+
'DiagnosticsConnectionString' => $diagnosticsConnectionString,
|
106 |
+
'RoleName' => $webRole,
|
107 |
+
'HttpPort' => $httpPort++
|
108 |
+
));
|
109 |
+
$serviceDefinitionIncludes[$webRole] = file_get_contents($serviceDefinitionFile);
|
110 |
+
$serviceConfigurationIncludes[$webRole] = file_get_contents($serviceConfigurationFile);
|
111 |
+
@unlink($serviceDefinitionFile);
|
112 |
+
@unlink($serviceConfigurationFile);
|
113 |
+
|
114 |
+
$this->log(' Configured web role "' . $webRole . '"...');
|
115 |
+
|
116 |
+
$this->log('Created web role "' . $webRole . '"...');
|
117 |
+
}
|
118 |
+
|
119 |
+
$workerRoles = explode(',', $workerRoleNames);
|
120 |
+
foreach ($workerRoles as $workerRole) {
|
121 |
+
if ($workerRole == '') continue;
|
122 |
+
|
123 |
+
$this->log('Creating worker role "' . $workerRole . '"...');
|
124 |
+
|
125 |
+
// Copy all files
|
126 |
+
$this->createDirectory($rootPath . '/' . $workerRole);
|
127 |
+
$this->copyDirectory($rootPath . '/Common', $rootPath . '/' . $workerRole, false);
|
128 |
+
$this->copyDirectory($rootPath . '/CommonWorker', $rootPath . '/' . $workerRole, false);
|
129 |
+
|
130 |
+
// Configure role
|
131 |
+
$this->log(' Configuring worker role "' . $workerRole . '"...');
|
132 |
+
|
133 |
+
$serviceDefinitionFile = $rootPath . '/' . $workerRole . '/ServiceDefinition.' . $workerRole . '.csdef';
|
134 |
+
$serviceConfigurationFile = $rootPath . '/' . $workerRole . '/ServiceConfiguration.' . $workerRole . '.cscfg';
|
135 |
+
copy($rootPath . '/ServiceDefinition.Worker.csdef', $serviceDefinitionFile);
|
136 |
+
copy($rootPath . '/ServiceConfiguration.Worker.cscfg', $serviceConfigurationFile);
|
137 |
+
|
138 |
+
$this->applyTransforms($rootPath . '/' . $workerRole, array(
|
139 |
+
'DiagnosticsConnectionString' => $diagnosticsConnectionString,
|
140 |
+
'RoleName' => $workerRole
|
141 |
+
));
|
142 |
+
$serviceDefinitionIncludes[$workerRole] = file_get_contents($serviceDefinitionFile);
|
143 |
+
$serviceConfigurationIncludes[$workerRole] = file_get_contents($serviceConfigurationFile);
|
144 |
+
@unlink($serviceDefinitionFile);
|
145 |
+
@unlink($serviceConfigurationFile);
|
146 |
+
|
147 |
+
$this->log(' Configured worker role "' . $workerRole . '"...');
|
148 |
+
|
149 |
+
$this->log('Created worker role "' . $workerRole . '"...');
|
150 |
+
}
|
151 |
+
|
152 |
+
// Apply transforms
|
153 |
+
$this->log('Applying transforms...');
|
154 |
+
$this->applyTransforms($rootPath, array(
|
155 |
+
'DiagnosticsConnectionString' => $diagnosticsConnectionString,
|
156 |
+
'ServiceDefinition' => implode("\r\n", $serviceDefinitionIncludes),
|
157 |
+
'ServiceConfiguration' => implode("\r\n", $serviceConfigurationIncludes)
|
158 |
+
));
|
159 |
+
$this->log('Applied transforms.');
|
160 |
+
|
161 |
+
// Delete unnecessary files and folders
|
162 |
+
$this->log('Cleanup starting...');
|
163 |
+
$this->deleteDirectory($rootPath . '/Common');
|
164 |
+
$this->deleteDirectory($rootPath . '/CommonWeb');
|
165 |
+
$this->deleteDirectory($rootPath . '/CommonWorker');
|
166 |
+
@unlink($rootPath . '/ServiceConfiguration.Web.cscfg');
|
167 |
+
@unlink($rootPath . '/ServiceConfiguration.Worker.cscfg');
|
168 |
+
@unlink($rootPath . '/ServiceDefinition.Web.csdef');
|
169 |
+
@unlink($rootPath . '/ServiceDefinition.Worker.csdef');
|
170 |
+
$this->log('Cleanup finished.');
|
171 |
+
|
172 |
+
// Show "to do" message
|
173 |
+
$this->log('');
|
174 |
+
$this->log('Your Windows Azure project has been scaffolded.');
|
175 |
+
}
|
176 |
+
}
|
libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/bin/add-environment-variables.cmd
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
@echo off
|
2 |
+
cd "%~dp0"
|
3 |
+
ECHO "Adding extra environment variables..." >> ..\startup-tasks-log.txt
|
4 |
+
|
5 |
+
powershell.exe Set-ExecutionPolicy Unrestricted
|
6 |
+
powershell.exe .\add-environment-variables.ps1 >> ..\startup-tasks-log.txt 2>>..\startup-tasks-error-log.txt
|
7 |
+
|
8 |
+
ECHO "Added extra environment variables." >> ..\startup-tasks-log.txt
|
libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/bin/add-environment-variables.ps1
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[Reflection.Assembly]::LoadWithPartialName("Microsoft.WindowsAzure.ServiceRuntime")
|
2 |
+
|
3 |
+
$rdRoleId = [Environment]::GetEnvironmentVariable("RdRoleId", "Machine")
|
4 |
+
|
5 |
+
[Environment]::SetEnvironmentVariable("RdRoleId", [Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::CurrentRoleInstance.Id, "Machine")
|
6 |
+
[Environment]::SetEnvironmentVariable("RoleName", [Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::CurrentRoleInstance.Role.Name, "Machine")
|
7 |
+
[Environment]::SetEnvironmentVariable("RoleInstanceID", [Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::CurrentRoleInstance.Id, "Machine")
|
8 |
+
[Environment]::SetEnvironmentVariable("RoleDeploymentID", [Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::DeploymentId, "Machine")
|
9 |
+
|
10 |
+
if (![Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::CurrentRoleInstance.Id.Contains("deployment")) {
|
11 |
+
if ($rdRoleId -ne [Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::CurrentRoleInstance.Id) {
|
12 |
+
Restart-Computer
|
13 |
+
}
|
14 |
+
}
|
libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/bin/install-php-impl.cmd
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
@echo off
|
2 |
+
cd "%~dp0"
|
3 |
+
ECHO Starting PHP installation... >> ..\startup-tasks-log.txt
|
4 |
+
|
5 |
+
md "%~dp0appdata"
|
6 |
+
cd "%~dp0appdata"
|
7 |
+
cd "%~dp0"
|
8 |
+
|
9 |
+
reg add "hku\.default\software\microsoft\windows\currentversion\explorer\user shell folders" /v "Local AppData" /t REG_EXPAND_SZ /d "%~dp0appdata" /f
|
10 |
+
"..\resources\WebPICmdLine\webpicmdline" /Products:PHP53,SQLDriverPHP53IIS,PHPManager /AcceptEula >> ..\startup-tasks-log.txt 2>>..\startup-tasks-error-log.txt
|
11 |
+
reg add "hku\.default\software\microsoft\windows\currentversion\explorer\user shell folders" /v "Local AppData" /t REG_EXPAND_SZ /d %%USERPROFILE%%\AppData\Local /f
|
12 |
+
|
13 |
+
ECHO Completed PHP installation. >> ..\startup-tasks-log.txt
|
libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/bin/install-php.cmd
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
@echo off
|
2 |
+
cd "%~dp0"
|
3 |
+
|
4 |
+
icacls %RoleRoot%\approot /grant "Everyone":F /T
|
5 |
+
%WINDIR%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /-"[fullPath='%ProgramFiles(x86)%\PHP\v5.3\php-cgi.exe'].environmentVariables.[name='RoleRoot']" /commit:apphost
|
6 |
+
%WINDIR%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='%ProgramFiles(x86)%\PHP\v5.3\php-cgi.exe'].environmentVariables.[name='RoleRoot',value='%RoleRoot%']" /commit:apphost
|
7 |
+
|
8 |
+
REM This script will only execute on production Windows Azure.
|
9 |
+
if "%EMULATED%"=="true" goto :EOF
|
10 |
+
|
11 |
+
ECHO Installing PHP runtime... >> ..\startup-tasks-log.txt
|
12 |
+
|
13 |
+
powershell.exe Set-ExecutionPolicy Unrestricted
|
14 |
+
powershell.exe .\install-php.ps1
|
15 |
+
|
16 |
+
icacls %RoleRoot%\approot /grant "Everyone":F /T
|
17 |
+
%WINDIR%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='%ProgramFiles(x86)%\PHP\v5.3\php-cgi.exe'].environmentVariables.[name='PATH',value='%PATH%;%RoleRoot%\base\x86']" /commit:apphost
|
18 |
+
|
19 |
+
ECHO Installed PHP runtime. >> ..\startup-tasks-log.txt
|
libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/bin/install-php.ps1
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[Reflection.Assembly]::LoadWithPartialName("Microsoft.WindowsAzure.ServiceRuntime")
|
2 |
+
|
3 |
+
.\install-php-impl.cmd
|
4 |
+
|
5 |
+
# Get PHP installation details
|
6 |
+
Add-PsSnapin PHPManagerSnapin
|
7 |
+
$phpConfiguration = Get-PHPConfiguration
|
8 |
+
$phpExecutable = Get-ChildItem $phpConfiguration.ScriptProcessor
|
9 |
+
$phpExtensionsPath = $phpExecutable.DirectoryName + "\ext"
|
10 |
+
$phpIniFile = $phpConfiguration.PHPIniFilePath
|
11 |
+
|
12 |
+
# Get PHP installation override details
|
13 |
+
$myExtensionsPath = "..\php\ext"
|
14 |
+
$myExtensions = Get-ChildItem $myExtensionsPath | where {$_.Name.ToLower().EndsWith(".dll")}
|
15 |
+
$myPhpIniFile = "..\php\php.ini"
|
16 |
+
|
17 |
+
# Append PHP.ini directives
|
18 |
+
if ((Test-Path $myPhpIniFile) -eq 'True') {
|
19 |
+
$additionalPhpIniDirectives = Get-Content $myPhpIniFile
|
20 |
+
$additionalPhpIniDirectives = $additionalPhpIniDirectives.Replace("%EXT%", $phpExtensionsPath)
|
21 |
+
|
22 |
+
Add-Content $phpIniFile "`r`n"
|
23 |
+
Add-Content $phpIniFile $additionalPhpIniDirectives
|
24 |
+
}
|
25 |
+
|
26 |
+
# Copy and register extensions
|
27 |
+
if ($myExtensions -ne $null) {
|
28 |
+
foreach ($myExtension in $myExtensions) {
|
29 |
+
Copy-Item $myExtension.FullName $phpExtensionsPath
|
30 |
+
Set-PHPExtension -Name $myExtension.Name -Status enabled
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
# Add PHP executable to PATH
|
35 |
+
if (![Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::CurrentRoleInstance.Id.Contains("deployment")) {
|
36 |
+
[Environment]::SetEnvironmentVariable('Path', [Environment]::GetEnvironmentVariable('Path', 'Machine') + ";" + $phpExecutable.DirectoryName, 'Machine')
|
37 |
+
}
|
libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/bin/monitor-environment.cmd
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
@echo off
|
2 |
+
cd "%~dp0"
|
3 |
+
|
4 |
+
icacls %RoleRoot%\approot /grant "Everyone":F /T
|
5 |
+
|
6 |
+
powershell.exe Set-ExecutionPolicy Unrestricted
|
7 |
+
powershell.exe .\monitor-environment.ps1
|
libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/bin/monitor-environment.ps1
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[Reflection.Assembly]::LoadWithPartialName("Microsoft.WindowsAzure.ServiceRuntime")
|
2 |
+
|
3 |
+
# To infinity and beyond!
|
4 |
+
|
5 |
+
while(1) {
|
6 |
+
|
7 |
+
##########################################################
|
8 |
+
# Monitor environment to XML file
|
9 |
+
##########################################################
|
10 |
+
|
11 |
+
# Build some XML that may be useful to non-Microsoft languages running on Windows Azure
|
12 |
+
$reXml = "<?xml version=`"1.0`" encoding=`"UTF-8`" ?>`r`n"
|
13 |
+
$reXml += [System.String]::Format("<RoleEnvironment deploymentId=`"{0}`" isAvailable=`"{1}`" isEmulated=`"{2}`">`r`n", [Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::DeploymentId, [Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::IsAvailable, [Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::IsEmulated)
|
14 |
+
|
15 |
+
$reXml += [System.String]::Format(" <CurrentRoleInstance id=`"{0}`" roleName=`"{1}`" updateDomain=`"{2}`" faultDomain=`"{2}`">`r`n", [Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::CurrentRoleInstance.Id, [Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::CurrentRoleInstance.Role.Name, [Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::CurrentRoleInstance.UpdateDomain, [Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::CurrentRoleInstance.FaultDomain)
|
16 |
+
$reXml += " <Endpoints>`r`n"
|
17 |
+
$endpoints = [Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::CurrentRoleInstance.InstanceEndpoints
|
18 |
+
foreach ($endpoint in $endpoints.Keys) {
|
19 |
+
$reXml += [System.String]::Format(" <Endpoint id=`"{0}`" protocol=`"{1}`" address=`"{2}`" port=`"{3}`" />`r`n", $endpoint, $endpoints[$endpoint].Protocol, $endpoints[$endpoint].IPEndpoint.Address, $endpoints[$endpoint].IPEndpoint.Port)
|
20 |
+
}
|
21 |
+
$reXml += " </Endpoints>`r`n"
|
22 |
+
$reXml += " </CurrentRoleInstance>`r`n"
|
23 |
+
|
24 |
+
$reXml += " <Roles>`r`n"
|
25 |
+
$roles = [Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::Roles
|
26 |
+
foreach ($role in $roles.Keys) {
|
27 |
+
$reXml += [System.String]::Format(" <Role name=`"{0}`">`r`n", $role)
|
28 |
+
$reXml += " <Instances>`r`n"
|
29 |
+
$instances = $roles[$role].Instances
|
30 |
+
for ($i = 0; $i -lt $instances.Count; $i++) {
|
31 |
+
$reXml += [System.String]::Format(" <RoleInstance id=`"{0}`" roleName=`"{1}`" updateDomain=`"{2}`" faultDomain=`"{2}`">`r`n", $instances[$i].Id, $instances[$i].Role.Name, $instances[$i].UpdateDomain, $instances[$i].FaultDomain)
|
32 |
+
$reXml += " <Endpoints>`r`n"
|
33 |
+
$endpoints = $instances[$i].InstanceEndpoints
|
34 |
+
foreach ($endpoint in $endpoints.Keys) {
|
35 |
+
$reXml += [System.String]::Format(" <Endpoint id=`"{0}`" protocol=`"{1}`" address=`"{2}`" port=`"{3}`" />`r`n", $endpoint, $endpoints[$endpoint].Protocol, $endpoints[$endpoint].IPEndpoint.Address, $endpoints[$endpoint].IPEndpoint.Port)
|
36 |
+
}
|
37 |
+
$reXml += " </Endpoints>`r`n"
|
38 |
+
$reXml += " </RoleInstance>`r`n"
|
39 |
+
}
|
40 |
+
$reXml += " </Instances>`r`n"
|
41 |
+
$reXml += " </Role>`r`n"
|
42 |
+
}
|
43 |
+
$reXml += " </Roles>`r`n"
|
44 |
+
|
45 |
+
$reXml += "</RoleEnvironment>`r`n"
|
46 |
+
|
47 |
+
|
48 |
+
Write-Output $reXml | Out-File -Encoding Ascii ../monitor-environment.xml
|
49 |
+
|
50 |
+
|
51 |
+
# Restart the loop in 30 seconds
|
52 |
+
Start-Sleep -Seconds 30
|
53 |
+
}
|
libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/diagnostics.wadcfg
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<DiagnosticMonitorConfiguration xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration" configurationChangePollInterval="PT1M" overallQuotaInMB="4096">
|
2 |
+
<DiagnosticInfrastructureLogs bufferQuotaInMB="10"
|
3 |
+
scheduledTransferLogLevelFilter="Error"
|
4 |
+
scheduledTransferPeriod="PT1M" />
|
5 |
+
|
6 |
+
<Logs bufferQuotaInMB="0"
|
7 |
+
scheduledTransferLogLevelFilter="Verbose"
|
8 |
+
scheduledTransferPeriod="PT1M" />
|
9 |
+
|
10 |
+
<Directories bufferQuotaInMB="0"
|
11 |
+
scheduledTransferPeriod="PT5M">
|
12 |
+
|
13 |
+
<!-- These three elements specify the special directories
|
14 |
+
that are set up for the log types -->
|
15 |
+
<CrashDumps container="wad-crash-dumps" directoryQuotaInMB="256" />
|
16 |
+
<FailedRequestLogs container="wad-frq" directoryQuotaInMB="256" />
|
17 |
+
<IISLogs container="wad-iis" directoryQuotaInMB="256" />
|
18 |
+
</Directories>
|
19 |
+
|
20 |
+
<PerformanceCounters bufferQuotaInMB="0" scheduledTransferPeriod="PT1M">
|
21 |
+
<!-- The counter specifier is in the same format as the imperative
|
22 |
+
diagnostics configuration API -->
|
23 |
+
<PerformanceCounterConfiguration
|
24 |
+
counterSpecifier="\Processor(_Total)\% Processor Time" sampleRate="PT5M" />
|
25 |
+
<PerformanceCounterConfiguration
|
26 |
+
counterSpecifier="\Memory\Available Mbytes" sampleRate="PT5M" />
|
27 |
+
</PerformanceCounters>
|
28 |
+
<WindowsEventLog bufferQuotaInMB="0"
|
29 |
+
scheduledTransferLogLevelFilter="Verbose"
|
30 |
+
scheduledTransferPeriod="PT5M">
|
31 |
+
<!-- The event log name is in the same format as the imperative
|
32 |
+
diagnostics configuration API -->
|
33 |
+
<DataSource name="System!*" />
|
34 |
+
</WindowsEventLog>
|
35 |
+
</DiagnosticMonitorConfiguration>
|
libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/php/ext/readme.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
Extensons in this folder will be enabled
|
2 |
+
on the Windows Azure role instance.
|
libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/php/php.ini
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[PhpAzureChanges]
|
2 |
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
3 |
+
; This file will be appended to the PHP.ini file located
|
4 |
+
; on the Windows Azure role instance.
|
5 |
+
;
|
6 |
+
; It can be used to:
|
7 |
+
; - Enable extensions (note that extensions copied to
|
8 |
+
; the ext folder are enabled automatically)
|
9 |
+
; - Override PHP settings
|
10 |
+
; - ...
|
11 |
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
12 |
+
|
13 |
+
; Change memory limit (example)
|
14 |
+
; memory_limit = 1024M
|
15 |
+
|
16 |
+
; Enable an extension (example)
|
17 |
+
; extension=php_curl.dll
|
18 |
+
|
19 |
+
; %EXT% will be replaced by the absolute path to PHP's
|
20 |
+
; extension folder.
|
21 |
+
; zend_extension=%EXT%
|
libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/resources/WebPICmdLine/Microsoft.Web.Deployment.dll
ADDED
Binary file
|
libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/resources/WebPICmdLine/Microsoft.Web.PlatformInstaller.UI.dll
ADDED
Binary file
|
libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/resources/WebPICmdLine/Microsoft.Web.PlatformInstaller.dll
ADDED
Binary file
|
libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/resources/WebPICmdLine/WebpiCmdLine.exe
ADDED
Binary file
|
libs/Microsoft/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/Common/resources/WebPICmdLine/license.rtf
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{\rtf1\ansi\ansicpg1252\deff0\deflang1033\deflangfe1033{\fonttbl{\f0\fswiss\fprq2\fcharset0 Tahoma;}{\f1\froman\fprq2\fcharset0 Times New Roman;}{\f2\froman\fprq2\fcharset2 Symbol;}}
|
2 |
+
{\colortbl ;\red0\green0\blue0;\red0\green0\blue255;}
|
3 |
+
{\stylesheet{ Normal;}{\s1 heading 1;}{\s2 heading 2;}}
|
4 |
+
{\*\generator Msftedit 5.41.21.2509;}\viewkind4\uc1\pard\nowidctlpar\sb120\sa120\b\f0\fs20 MICROSOFT SOFTWARE LICENSE TERMS\par
|
5 |
+
\pard\brdrb\brdrs\brdrw10\brsp20 \nowidctlpar\sb120\sa120 MICROSOFT WEB PLATFORM INSTALLER 3.0\f1\par
|
6 |
+
\pard\nowidctlpar\sb120\sa120\b0\f0 These license terms are an agreement between Microsoft Corporation (or based on where you live, one of its affiliates) and you. Please read them. They apply to the software named above, which includes the media on which you received it, if any. The terms also apply to any Microsoft\par
|
7 |
+
\pard\nowidctlpar\fi-360\li360\sb120\sa120\tx360\f2\'b7\tab\f0 updates,\par
|
8 |
+
\pard\nowidctlpar\fi-360\li360\sb120\sa120\f2\'b7\tab\f0 supplements,\par
|
9 |
+
\f2\'b7\tab\f0 Internet-based services, and\par
|
10 |
+
\f2\'b7\tab\f0 support services\par
|
11 |
+
\pard\nowidctlpar\sb120\sa120 for this software, unless other terms accompany those items. If so, those terms apply.\par
|
12 |
+
\b By using the software, you accept these terms. If you do not accept them, do not use the software.\par
|
13 |
+
\pard\brdrt\brdrs\brdrw10\brsp20 \nowidctlpar\sb120\sa120 If you comply with these license terms, you have the rights below.\par
|
14 |
+
\pard\nowidctlpar\s1\fi-357\li357\sb120\sa120\tx360 1.\tab INSTALLATION AND USE RIGHTS. \b0 You may install and use any number of copies of the software on your devices.\f1\par
|
15 |
+
\pard\s1\fi-357\li357\sb120\sa120\tx360\b\caps\f0 2.\tab\fs19 Third Party Programs\caps0\f1 .\b0\f0\fs20 T\kerning36 his software enables you to obtain software applications from other sources. Those applications are offered and distributed by third parties under their own license terms. Microsoft is not developing, distributing or licensing those applications to you, but instead, as a convenience, enables you to use this software to obtain those applications directly from the application providers. By using the software, you acknowledge and agree that you are obtaining the applications directly from the third party providers and under separate license terms, and that it is your responsibility to locate, understand and comply with those license terms.\fs19 Microsoft grants you no license rights for third-party software or applications that is obtained using this software. \kerning0 \b\f1\par
|
16 |
+
\pard\nowidctlpar\s1\fi-357\li357\sb120\sa120\tx360\f0\fs20 3.\tab INTERNET-BASED SERVICES. \b0 Microsoft provides Internet-based services with the software. It may change or cancel them at any time. \cf1 The software contains product information that is updated by means of a feed online from Microsoft.\cf0\f1\par
|
17 |
+
\pard\nowidctlpar\s1\fi-357\li357\sb120\sa120\b\f0 4.\tab SCOPE OF LICENSE.\b0 The software is licensed, not sold. This agreement only gives you some rights to use the software. Microsoft reserves all other rights. Unless applicable law gives you more rights despite this limitation, you may use the software only as expressly permitted in this agreement. In doing so, you must comply with any technical limitations in the software that only allow you to use it in certain ways. You may not\par
|
18 |
+
\pard\nowidctlpar\fi-363\li720\sb120\sa120\tx720\f2\'b7\tab\f0 work around any technical limitations in the software;\par
|
19 |
+
\pard\nowidctlpar\fi-363\li720\sb120\sa120\f2\'b7\tab\f0 reverse engineer, decompile or disassemble the software, except and only to the extent that applicable law expressly permits, despite this limitation;\par
|
20 |
+
\f2\'b7\tab\f0 make more copies of the software than specified in this agreement or allowed by applicable law, despite this limitation;\par
|
21 |
+
\f2\'b7\tab\f0 publish the software for others to copy;\par
|
22 |
+
\f2\'b7\tab\f0 rent, lease or lend the software; or\par
|
23 |
+
\f2\'b7\tab\f0 transfer the software or this agreement to any third party;\par
|
24 |
+
\pard\nowidctlpar\s1\fi-357\li357\sb120\sa120\tx360\b 5.\tab BACKUP COPY.\b0 You may make one backup copy of the software. You may use it only to reinstall the software.\par
|
25 |
+
\pard\nowidctlpar\s1\fi-357\li357\sb120\sa120\b 6.\tab DOCUMENTATION.\b0 Any person that has valid access to your computer or internal network may copy and use the documentation for your internal, reference purposes.\par
|
26 |
+
\b 7.\tab TRANSFER TO ANOTHER DEVICE.\b0 You may uninstall the software and install it on another device for your use. You may not do so to share this license between devices.\par
|
27 |
+
\b 8.\tab EXPORT RESTRICTIONS.\b0 The software is subject to United States export laws and regulations. You must comply with all domestic and international export laws and regulations that apply to the software. These laws include restrictions on destinations, end users and end use. For additional information, see {\field{\*\fldinst{HYPERLINK "www.microsoft.com/exporting"}}{\fldrslt{\ul\cf2 www.microsoft.com/exporting}}}\f1\fs20 .\ul\par
|
28 |
+
\ulnone\b\f0 9.\tab SUPPORT SERVICES. \b0 Because this software is \ldblquote as is,\rdblquote we may not provide support services for it.\par
|
29 |
+
\b 10.\tab ENTIRE AGREEMENT.\b0 This agreement, and the terms for supplements, updates, Internet-based services and support services that you use, are the entire agreement for the software and support services.\par
|
30 |
+
\pard\nowidctlpar\s1\fi-360\li360\sb120\sa120\tx360\b 11.\tab APPLICABLE LAW.\par
|
31 |
+
\pard\nowidctlpar\s2\fi-363\li720\sb120\sa120\tx720 a.\tab United States.\b0 If you acquired the software in the United States, Washington state law governs the interpretation of this agreement and applies to claims for breach of it, regardless of conflict of laws principles. The laws of the state where you live govern all other claims, including claims under state consumer protection laws, unfair competition laws, and in tort.\par
|
32 |
+
\pard\nowidctlpar\s2\fi-363\li720\sb120\sa120\b b.\tab Outside the United States.\b0 If you acquired the software in any other country, the laws of that country apply.\par
|
33 |
+
\pard\nowidctlpar\s1\fi-357\li357\sb120\sa120\tx360\b 12.\tab LEGAL EFFECT.\b0 This agreement describes certain legal rights. You may have other rights under the laws of your country. You may also have rights with respect to the party from whom you acquired the software. This agreement does not change your rights under the laws of your country if the laws of your country do not permit it to do so.\par
|
34 |
+
\pard\s1\fi-357\li357\sb120\sa120\tx360\b 13.\tab DISCLAIMER OF WARRANTY. The software is licensed \ldblquote as-is.\rdblquote You bear the risk of using it. Microsoft gives no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this agreement cannot change. To the extent permitted under your local laws, Microsoft excludes the implied warranties of merchantability, fitness for a particular purpose and non-infringement.\par
|
35 |
+
\pard\s1\fi-357\li357\sb120\sa120 14.\tab LIMITATION ON AND EXCLUSION OF REMEDIES AND DAMAGES. You can recover from Microsoft and its suppliers only direct damages up to U.S. $5.00. You cannot recover any other damages, including consequential, lost profits, special, indirect or incidental damages.\par
|
36 |
+
\pard\nowidctlpar\li357\sb120\sa120\b0 This limitation applies to\par
|
37 |
+
\pard\nowidctlpar\fi-363\li720\sb120\sa120\tx720\f2\'b7\tab\f0 anything related to the software, services, content (including code) on third party Internet sites, or third party programs; and\par
|
38 |
+
\pard\nowidctlpar\fi-363\li720\sb120\sa120\f2\'b7\tab\f0 claims for breach of contract, breach of warranty, guarantee or condition, strict liability, negligence, or other tort to the extent permitted by applicable law.\par
|
39 |
+
\pard\sb120\sa120 It also applies even if Microsoft knew or should have known about the possibility of the damages. The above limitation or exclusion may not apply to you because your country may not allow the exclusion or limitation of incidental, consequential or other damages\f1 .\fs19\par
|
40 |
+
}
|
41 |
+
|