[Solar-svn] Revision 2611
pmjones at solarphp.com
pmjones at solarphp.com
Sat Jul 21 18:31:10 CDT 2007
Solar_Request
-------------
* [ADD] Property $argv for command-line arguments
* [ADD] Method argv() for command-line arguments
* [ADD] Method isCli() to see if we're in a command-line environment
Modified: trunk/Solar/Request.php
===================================================================
--- trunk/Solar/Request.php 2007-07-21 21:43:46 UTC (rev 2610)
+++ trunk/Solar/Request.php 2007-07-21 23:31:09 UTC (rev 2611)
@@ -124,6 +124,15 @@
public $http;
/**
+ *
+ * Imported $_SERVER['argv'] values.
+ *
+ * @var array
+ *
+ */
+ public $argv;
+
+ /**
*
* Constructor.
*
@@ -246,6 +255,24 @@
/**
*
+ * Retrieves a value by key from the [[$argv]] property, or an alternate
+ * default value if that key does not exist.
+ *
+ * @param string $key The $argv key to retrieve the value of.
+ *
+ * @param string $alt The value to return if the key does not exist.
+ *
+ * @return mixed The value of $argv[$key], or the alternate default
+ * value.
+ *
+ */
+ public function argv($key = null, $alt = null)
+ {
+ return $this->_getValue('argv', $key, $alt);
+ }
+
+ /**
+ *
* Retrieves a value by key from the [[$http]] property, or an alternate
* default value if that key does not exist.
*
@@ -264,6 +291,18 @@
/**
*
+ * Is this a command-line request?
+ *
+ * @return bool
+ *
+ */
+ public function isCli()
+ {
+ return PHP_SAPI == 'cli';
+ }
+
+ /**
+ *
* Is this a 'GET' request?
*
* @return bool
@@ -364,6 +403,9 @@
unset($in);
}
+ // load the "fake" argv request var
+ $this->argv = (array) $this->server('argv');
+
// load the "fake" http request var
$this->http = array();
foreach ($this->server as $key => $val) {
@@ -375,14 +417,14 @@
$nicekey = strtolower(
str_replace('_', '-', substr($key, 5))
);
-
+
// strip control characters from keys and values
$nicekey = preg_replace('/[\x00-\x1F]/', '', $nicekey);
$this->http[$nicekey] = preg_replace('/[\x00-\x1F]/', '', $val);
-
+
// no control characters wanted in $this->server for these
$this->server[$key] = $this->http[$nicekey];
-
+
// disallow external setting of X-JSON headers.
if ($nicekey == 'x-json') {
unset($this->http[$nicekey]);
More information about the Solar-svn
mailing list