From ea20683059b93a718b44894f0721892a9f436e0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20M=C3=AD=C5=A1ek?= Date: Sun, 31 Mar 2019 21:01:47 +0200 Subject: [PATCH] SplFileInfo::openFile() --- src/Peachpie.Library/Spl/SplFileInfo.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Peachpie.Library/Spl/SplFileInfo.cs b/src/Peachpie.Library/Spl/SplFileInfo.cs index 5a39c8a628..bfb197b052 100644 --- a/src/Peachpie.Library/Spl/SplFileInfo.cs +++ b/src/Peachpie.Library/Spl/SplFileInfo.cs @@ -115,9 +115,19 @@ public virtual string getExtension() public virtual bool isLink() { throw new NotImplementedException(); } public virtual bool isReadable() { throw new NotImplementedException(); } public virtual bool isWritable() { throw new NotImplementedException(); } - public virtual SplFileObject openFile(string open_mode = "r", bool use_include_path = false, PhpResource context = null) { throw new NotImplementedException(); /* NOTE: use _file_class */ } - public virtual void setFileClass(string class_name = "SplFileObject") => _file_class = class_name; - public virtual void setInfoClass(string class_name = "SplFileInfo") => _info_class = class_name; + public virtual SplFileObject openFile(Context ctx, string open_mode = "r", bool use_include_path = false, PhpResource context = null) + { + if (string.IsNullOrEmpty(_file_class) || string.Equals(_file_class, nameof(SplFileObject), StringComparison.OrdinalIgnoreCase)) + { + return new SplFileObject(ctx, _fullpath, open_mode, use_include_path, context); + } + else + { + return (SplFileObject)ctx.Create(_file_class, _fullpath, open_mode, use_include_path, PhpValue.FromClass(context)); + } + } + public virtual void setFileClass(string class_name = nameof(SplFileObject)) => _file_class = class_name; + public virtual void setInfoClass(string class_name = nameof(SplFileInfo)) => _info_class = class_name; public virtual string __toString() => _fullpath; public override string ToString() => _fullpath; }