Page MenuHomeDevCentral

D4186.diff
No OneTemporary

D4186.diff

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

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)

Event Timeline