Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F45512518
D4186.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D4186.diff
View Options
diff --git a/omnitools/src/IO/Directory.php b/omnitools/src/IO/Directory.php
--- a/omnitools/src/IO/Directory.php
+++ b/omnitools/src/IO/Directory.php
@@ -2,6 +2,8 @@
namespace Keruald\OmniTools\IO;
+use Keruald\OmniTools\Collections\Vector;
+
class Directory {
///
@@ -12,6 +14,14 @@
private string $path,
) {}
+ public static function fromPathFragments (iterable $fragments) : self {
+ $path = Vector::from($fragments)
+ ->implode(DIRECTORY_SEPARATOR)
+ ->getValue();
+
+ return new self($path);
+ }
+
///
/// Getters and setters
///
@@ -75,6 +85,17 @@
);
}
+ /**
+ * Count files in the directory matching a specific pattern.
+ * Non-recursive.
+ *
+ * @param string $pattern Glob pattern to match files, defaults to "*"
+ * @return int
+ */
+ public function countFiles (string $pattern = "*") : int {
+ return count($this->glob($pattern));
+ }
+
/**
* @return Directory[]
*/
@@ -86,4 +107,12 @@
);
}
+ ///
+ /// Generate File from path
+ ///
+
+ public function getFile (string $filename) : File {
+ return new File($this->path . DIRECTORY_SEPARATOR . $filename);
+ }
+
}
diff --git a/omnitools/src/IO/File.php b/omnitools/src/IO/File.php
--- a/omnitools/src/IO/File.php
+++ b/omnitools/src/IO/File.php
@@ -71,4 +71,12 @@
return pathinfo($this->path, PATHINFO_EXTENSION);
}
+ ///
+ /// IO helper methods
+ ///
+
+ public function read () : string {
+ return file_get_contents($this->path);
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Aug 23, 12:11 (18 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4028108
Default Alt Text
D4186.diff (1 KB)
Attached To
Mode
D4186: Solve basic CMS interaction needs with files and directories
Attached
Detach File
Event Timeline
Log In to Comment