Implement stream_context_{get,set}_default

Implement stream_context_{get,set}_default

Closes #1642

Reviewed By: @ptarjan

Differential Revision: D1145658

Pulled By: @scannell
Esse commit está contido em:
Jim Radford
2014-01-28 06:52:39 -08:00
commit de Sara Golemon
commit c052283289
8 arquivos alterados com 100 adições e 1 exclusões
+4
Ver Arquivo
@@ -329,6 +329,9 @@ public:
void setExitCallback(Variant f) { m_exitCallback = f; }
Variant getExitCallback() { return m_exitCallback; }
void setStreamContext(Resource &context) { m_streamContext = context; }
Resource &getStreamContext() { return m_streamContext; }
void restoreIncludePath();
void setIncludePath(const String& path);
String getIncludePath() const;
@@ -387,6 +390,7 @@ private:
String m_timezoneDefault;
String m_argSeparatorOutput;
bool m_throwAllErrors;
Resource m_streamContext;
// session backup/restore for RPCRequestHandler
Array m_shutdownsBackup;
+3 -1
Ver Arquivo
@@ -137,7 +137,9 @@ Variant File::Open(const String& filename, const String& mode,
int options /* = 0 */,
CVarRef context /* = null */) {
Stream::Wrapper *wrapper = Stream::getWrapperFromURI(filename);
File *file = wrapper->open(filename, mode, options, context);
File *file =
wrapper->open(filename, mode, options,
context.isNull() ? g_context->getStreamContext() : context);
if (file != nullptr) {
file->m_name = filename.data();
file->m_mode = mode.data();
+18
Ver Arquivo
@@ -111,6 +111,24 @@ bool f_stream_context_set_option(CVarRef stream_or_context,
}
}
Variant f_stream_context_get_default(CArrRef options /* = null_array */) {
Resource &resource = g_context->getStreamContext();
if (resource.isNull()) {
resource = Resource(NEWOBJ(StreamContext)(Array::Create(),
Array::Create()));
g_context->setStreamContext(resource);
}
StreamContext *context = resource.getTyped<StreamContext>();
if (!options.isNull() && !f_stream_context_set_option0(context, options)) {
return false;
}
return resource;
}
Variant f_stream_context_set_default(CArrRef options) {
return f_stream_context_get_default(options);
}
Variant f_stream_context_get_params(CResRef stream_or_context) {
StreamContext* context = get_stream_context(stream_or_context);
if (!context) {
+33
Ver Arquivo
@@ -27,6 +27,39 @@
}
]
},
{
"name": "stream_context_set_default",
"flags": [
],
"return": {
"type": "Variant",
"desc": "Returns the default stream context."
},
"args": [
{
"name": "options",
"type": "VariantMap",
"desc": "The options to set for the default context.\n\noptions must be an associative array of associative arrays in the format $arr['wrapper']['option'] = $value.\n\nRefer to context options and parameters for a listing of stream options."
}
]
},
{
"name": "stream_context_get_default",
"flags": [
],
"return": {
"type": "Variant",
"desc": "Returns the default stream context."
},
"args": [
{
"name": "options",
"type": "VariantMap",
"value": "null_array",
"desc": "The options to set for the default context.\n\noptions must be an associative array of associative arrays in the format $arr['wrapper']['option'] = $value.\n\nRefer to context options and parameters for a listing of stream options."
}
]
},
{
"name": "stream_context_get_options",
"flags": [
@@ -0,0 +1,8 @@
<?php
var_dump(stream_context_get_options(stream_context_get_default()));
var_dump(stream_context_get_options(stream_context_get_default(
array("http" => array("header" => "X-Hello: world")))));
var_dump(stream_context_get_options(stream_context_get_default()));
var_dump(stream_context_get_options(stream_context_set_default(
array("http" => array("method" => "POST")))));
var_dump(stream_context_get_options(stream_context_get_default()));
@@ -0,0 +1,34 @@
array(0) {
}
array(1) {
["http"]=>
array(1) {
["header"]=>
string(14) "X-Hello: world"
}
}
array(1) {
["http"]=>
array(1) {
["header"]=>
string(14) "X-Hello: world"
}
}
array(1) {
["http"]=>
array(2) {
["header"]=>
string(14) "X-Hello: world"
["method"]=>
string(4) "POST"
}
}
array(1) {
["http"]=>
array(2) {
["header"]=>
string(14) "X-Hello: world"
["method"]=>
string(4) "POST"
}
}