| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 | <?phpnamespace 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;    }}   
 |