PHP တွင် stream_register_wrapper သည် developer များကို Stream Protocol ပရိုဆက်ဆာများကိုစိတ်ကြိုက်ပြုပြင်ခွင့်ပြုသည်။ Custom File Systems, Virtual Protocols သို့မဟုတ် Network Layer Encapsulationsulationsulation ကိုတည်ဆောက်သည့်အခါဤယန္တရားသည်အလွန်အသုံးဝင်သည်။ သို့သော်အမှန်တကယ်အသုံးပြုမှုတွင်အချို့သော developer များသည် stream_register_wrapper ၏ပျက်ကွက်မှုပြ the နာကိုကြုံတွေ့ရလိမ့်မည်။ ဤဆောင်းပါးသည် developer များကိုပိုမိုမြန်ဆန်စွာဖြေရှင်းရန်နှင့်ပြ problems နာများကိုပိုမိုမြန်ဆန်စွာဖြေရှင်းရန်အတိမ်အနက်ကိုအတိမ်အနက်ကိုအတိမ်အနက်ကိုဆန်းစစ်ကြည့်ပါလိမ့်မည်။
Steam_register_wrapper (string $ protocol, string ကို $ classname): Bool
ဤလုပ်ဆောင်ချက်သည်သတ်မှတ်ထားသော protocols များကိုကိုင်တွယ်ရန်အတွက်အတန်းတစ်ခုအနေဖြင့်အတန်းတစ်ခုအဖြစ်မှတ်ပုံတင်ရန်ခွင့်ပြုသည် (ဥပမာ foo // ) အကယ်. မှတ်ပုံတင်သည်အောင်မြင်သည်ဆိုပါက ပြန်လည်ထူထောင် ပါ ။
HTTP , HTTPS , FTP, PHP , PHP , file စသည့် PHP protocol names များစွာကိုတည်ဆောက်ထားသည်။ အကယ်. သင်သည်လက်ရှိ protocol အမည်များကိုမှတ်ပုံတင်ရန်ကြိုးစားပါကမှတ်ပုံတင်ခြင်းကျလိမ့်မည်။
နမူနာကုဒ်:
stream_register_wrapper("http", "MyStream"); // မှတ်ပုံတင်ခြင်းမအောင်မြင်ပါ,"http" စနစ်ကအသုံးပြုခဲ့သည်
ဖြေရှင်းချက် - ဥပမာ - စိတ်ကြိုက်နှင့်ထူးခြားသော protocol name ကိုသုံးပါ။
stream_register_wrapper("myproto", "MyStream"); // အောင်မြင်ခြင်း
၎င်းသည် built-in protocol မဟုတ်သော်လည်း protocol name ကိုတစ်ကြိမ်မှတ်ပုံတင်ပြီးပါကထပ်မံမှတ်ပုံတင်သည့်အခါကျရှုံးလိမ့်မည်။
လက်ရှိမှတ်ပုံတင်ခြင်းကိုဖျက်သိမ်းရန်သင် stream_wrapper_unregister () ကိုသုံးနိုင်သည်။
stream_wrapper_unregister("myproto");
stream_register_wrapper("myproto", "MyStream");
မှတ်ပုံတင်ထားသောအတန်းအစားသည် Stream_open , stream_read , stream_w_write , stream_reof ကဲ့သို့သော streamwraper interface မှလိုအပ်သောနည်းလမ်းများကိုအကောင်အထည်ဖော်ရမည်။
ဥပမာအတန်း -
class MyStream {
public function stream_open($path, $mode, $options, &$opened_path) {
// ဖြစ်ပေါ်လာခြင်း
return true;
}
public function stream_read($count) {
return '';
}
public function stream_eof() {
return true;
}
// အခြားလိုအပ်သောနည်းလမ်းများ...
}
မှတ်ချက် - Stream_open () နည်းလမ်းကိုမသတ်မှတ်ခြင်းသည်အောင်မြင်သောမှတ်ပုံတင်ခြင်းကိုတိုက်ရိုက် ဦး ဆောင်သွားမည်မဟုတ်သော်လည်းလက်လှမ်းမမီနိုင်ပါ။
အချို့သောဝေငှခြင်းသို့မဟုတ်ကန့်သတ်ထားသော PHP Runtimes သည် stream_register_wraper () ကိုတားမြစ်နိုင်သည်။ ဒီနေရာမှာ function ဟာမအောင်မြင်ဘူး,
သငျသညျ function_exists ("stream_register_wrapper") ကို သင်ကဆုံးဖြတ်ရန်:
if (!function_exists("stream_register_wrapper")) {
die("လက်ရှိပတ်ဝန်းကျင်ကအဲဒါကိုမထောက်ခံပါဘူး stream_register_wrapper。");
}
သို့မဟုတ် disable_Functions တွင် Phpinfo () မှတဆင့် function ကိုပါ 0 င်သည်ကိုစစ်ဆေးပါ။
အချို့သော developer တချို့သည်လမ်းကြောင်းပုံစံ, ဆက်စပ်မှု parameters များစသည်တို့ကဲ့သို့သောပြ issues နာများကိုမစဉ်းစားကြပါ။ ဥပမာအားဖြင့်:
file_get_contents("myproto://resource"); // ခေါ်ဆိုမှုမအောင်မြင်ပါ,မမှန်ကန်သောလမ်းကြောင်း resolution
ဤအချိန်တွင်မှတ်ပုံတင်ထားသော protocol ကိုလမ်းကြောင်း resolution ကိုမှန်ကန်စွာကိုင်တွယ်ရန်သေချာစေရန်လိုအပ်ကြောင်းသေချာစေရန် stream_context_create () ကို အသုံးပြုရန်စဉ်းစားရန်လိုအပ်သည်။
$context = stream_context_create([
'myproto' => [
'option1' => 'value'
]
]);
file_get_contents("myproto://resource", false, $context);
ပေါင်းထည့်ပါ။ rogress_log () add ader_log () အချက်အလက်များကို class method ကို class method ကို debing လုပ်ခြင်းကို classing method ကို debing လုပ်ခြင်း။
စမ်းသပ်လမ်းကြောင်း - လမ်းကြောင်းမှန်ကိုမှန်ကန်စွာလုပ်ဆောင်သည်ကိုစစ်ဆေးရန်တောင်းဆိုမှုလမ်းကြောင်းကိုကိုယ်တိုင်ပြုလုပ်ပါ။
မှတ်ပုံတင်ထားသော encapsulator များကိုကြည့်ပါ။
print_r(stream_get_wrappers());
ပစ်မှတ်သဘောတူညီချက်သိမ်းပိုက်မထားကြောင်းသေချာပါစေ။
class GitboxStream {
public function stream_open($path, $mode, $options, &$opened_path) {
error_log("Opening: $path");
return true;
}
public function stream_read($count) {
return '';
}
public function stream_eof() {
return true;
}
// 省略အခြားလိုအပ်သောနည်းလမ်းများ
}
stream_wrapper_unregister("gitbox");
stream_register_wrapper("gitbox", "GitboxStream");
$content = file_get_contents("gitbox://example/gitbox.net/resource");
ဤတွင် Gitpbox: //exampbox.net/resicance သည် domain name အပိုင်းကို Gitin Box.net ကိုသတ်မှတ်သည့်ထုံးစံ protocol ကိုအသုံးပြုရန်နည်းလမ်းဖြစ်သည်။
Stream_register_wrapper သည် ကြီးမားသောပမာဏကိုထောက်ပံ့ပေးနိုင်သည်။ ဤဆောင်းပါးတွင်ဖော်ပြထားသောအမှားများနှင့် debugging နည်းစနစ်များအမှားအယွင်းများမှတစ်ဆင့်၎င်းတို့၏အသုံးပြုမှု၏အဓိကအချက်များကိုပိုမိုနားလည်ပြီးဘုံဒဏ်ကိုရှောင်ရှားနိုင်သည်။ မြင့်မားသောစကေးသို့မဟုတ် Cross-protocol processing နှင့်အတူဖြစ်ရပ်များအတွက်ဒီ function ကိုဆင်ခြင်တုံတရားအသုံးပြုမှုသည်စီမံကိန်း၏ပြောင်းလွယ်ပြင်လွယ်နှင့်ထိန်းသိမ်းမှုကိုများစွာတိုးတက်စေလိမ့်မည်။