static public function dir($directory, $date = false)
    {
        if ($date) {
            $directory = rtrim($directory, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . self::getDateDirectory();
        }

        if (!is_dir($directory)) {
            $umask = umask(0000);
            if (@mkdir($directory, 0777, true) === false) {
                throw new Exception(sprintf('Directory "%s" cannot be created.', $directory));
            }
            umask($umask);
        }

        return $directory;
    }