Cixo Develop 6 zile în urmă
părinte
comite
467f8ba4e3
6 a modificat fișierele cu 158 adăugiri și 0 ștergeri
  1. 22 0
      phpath.php
  2. 25 0
      source/common_path.php
  3. 10 0
      source/path.php
  4. 0 0
      source/posix_path.php
  5. 101 0
      source/system_detector.php
  6. 0 0
      source/windows_path.php

+ 22 - 0
phpath.php

@@ -0,0 +1,22 @@
+<?php
+
+namespace phpath;
+
+function load(string $name): void {
+    $current = __DIR__;
+
+    if ($name[0] !== '/') {
+        $current .= '/';
+    }
+
+    require_once($current.$name);
+}
+
+load('source/system_detector.php');
+load('source/common_path.php');
+load('source/path.php');
+load('source/posix_path.php');
+load('source/windows_path.php');
+
+
+

+ 25 - 0
source/common_path.php

@@ -0,0 +1,25 @@
+<?php
+
+namespace phpath;
+
+use \resource as resource;
+
+abstract class common_path {
+    private string $path;
+
+    public function __construct(string $path) {
+        $this->path = trim($path);
+    }
+
+    public function get_path(): string {
+        return $this->path;
+    
+    abstract public function is_absolute(): bool;
+    abstract public function is_dir(): bool;
+    abstract public function is_file(): bool;
+    abstract public function exists(): bool;
+    abstract public function remove(): void;
+    abstract public function create(): void;
+    abstract public function open(string $mode): resource;
+
+} 

+ 10 - 0
source/path.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace phpath;
+
+class path extends common_path {
+    public function __construct(string $path) {
+                
+    }   
+}
+

+ 0 - 0
source/posix_path.php


+ 101 - 0
source/system_detector.php

@@ -0,0 +1,101 @@
+<?php
+
+namespace phpath;
+
+class system_detector {
+    /**
+     * That class could be used to detect, which standard of operating system
+     * code is running on. POSIX like operating systems, that mean Linux, BSD
+     * MacOS, Solaris, and other *nix use "/" as directory separator and uses
+     * root directory, when Windows and DOS use "\" and drives letters.
+     */
+
+    public static function is_posix(): bool {
+        /**
+         * This function check that system uses POSIX like standards.
+         * When system is POSIX like, that mean Linux, Unix, MacOS and much
+         * more return true. When run on not POSIX system return false.
+         * 
+         * @return bool True when system is POSIX like, false when not.
+         */
+        static $is_posix = null;
+
+        if ($is_posix !== null) {
+            return $is_posix;
+        }
+
+        $is_posix = false;
+        $is_posix = $is_posix or self::in_os_name('nix');
+        $is_posix = $is_posix or self::in_os_name('linux');
+        $is_posix = $is_posix or self::in_os_name('mac');
+        $is_posix = $is_posix or self::in_os_name('bsd');
+        $is_posix = $is_posix or self::in_os_name('solaris');
+    
+        return $is_posix;
+    }
+
+    public static function is_windows(): bool {
+        /**
+         * It check that code run on windows. 
+         * When code run on windows like os, which use "\" as directory 
+         * separator, return true. When not run on dos or windows return 
+         * false.
+         *
+         * @return bool True when run on windows, or false when on POSIX.
+         */
+
+        static $is_windows = null;
+
+        if ($is_windows !== null) {
+            return $is_windows;
+        }
+
+        $is_windows = false;
+        $is_windows = $is_windows or self::in_os_name('nt');
+        $is_windows = $is_windows or self::in_os_name('win');
+        $is_windows = $is_windows or self::in_os_name('dos');
+    
+        return $is_windows;
+    }
+
+    public static function get_os_name(): string {
+        /**
+         * It return simple name of family of system on which code run.
+         *
+         * @return string Name of system family.
+         */
+
+        return strtolower(php_uname('s'));
+    }
+
+    private static function in_os_name(string $part): bool {
+        /**
+         * This function check that given part of name is in the operating
+         * system name or given part is equal to system name.
+         *
+         * @return bool True when it is equal or false when not.
+         */
+
+        static $uname = self::get_os_name();
+    
+        if ($uname === $part) {
+            return true;
+        }
+
+        if (strpos($uname, $part) !== false) {
+            return true;
+        }
+
+        return false;
+    }       
+
+    public static function get_separator(): string {
+        /**
+         * That return directory separator.
+         * 
+         * @return string Directory separator.
+         */
+
+        return DIRECTORY_SEPARATOR;
+    }
+}   

+ 0 - 0
source/windows_path.php