Giter Site home page Giter Site logo

slash's Introduction

PHP utility classes for URIs, paths, and files

API (3.0)

Classes

  • Uri methods aim to be more practical and reliable than parse_url.
  • Path contains reliable methods for working with server filesystem paths.
  • File contains reliable methods for reading and writing files.
  • Slash contains string utilities inherited by Path and Uri.

Uri Methods

foo://user:[email protected]:800/dir/file.php?s=10&e=23#jump
\_/   \_______/ \_________/ \_/              \_______/ \__/
 |        |          |       |                  |       |
 |     userinfo   hostname  port              query   fragment
 |    \_______________________/\___________/
 |            |                      |
scheme    authority                 path

Methods are based on the URI diagram or otherwise normalized between terms in PHP, JavaScript, jQuery Mobile, and node.

\slash\Uri::scheme($uri) // get scheme (excludes ':')
\slash\Uri::prorel($uri) // convert to protocol relative
\slash\Uri::prorel($uri, $scheme) // replace the scheme
\slash\Uri::bar($uri) // get "address bar" uri
\slash\Uri::authority($uri) // get authority
\slash\Uri::hostname($uri) // get hostname
\slash\Uri::prefetch($uri) // get uri for dns prefetch
\slash\Uri::userinfo($uri) // get userinfo
\slash\Uri::user($uri) // get username
\slash\Uri::pass($uri) // get password
\slash\Uri::port($uri) // get port number (string)
\slash\Uri::hier($uri) // get hierarchial part
\slash\Uri::path($uri) // get path part
\slash\Uri::query($uri) // get query str (excludes '?')
\slash\Uri::hash($uri) // get fragment  (includes '#')
\slash\Uri::fragment($uri) // get fragment  (excludes '#')
\slash\Uri::nohash($uri) // remove hash
\slash\Uri::novars($uri) // remove hash and query
\slash\Uri::parse($uri) // get object containing parts

Slash Methods

\slash\Slash::trim($path)
\slash\Slash::ltrim($path)
\slash\Slash::rtrim($path)
\slash\Slash::slash($path)
\slash\Slash::lslash($path)
\slash\Slash::rslash($path)
\slash\Slash::join(*$parts)
\slash\Slash::split($path)
\slash\Slash::normalize($path)

File Methods

\slash\File::exists($path)
\slash\File::get($path, $done?)
\slash\File::put($path, $data)
\slash\File::load($path, $done)
\slash\File::getJson($path, $done?)
\slash\File::putJson($path, $data)

Path Methods

\slash\Path::normalize($path)
\slash\Path::root($relative?)
\slash\Path::dir($relative?)
\slash\Path::ext($path, $add?)
\slash\Path::filename($file)
\slash\Path::inc($file)
\slash\Path::scan($path?)
\slash\Path::tree($path?)
\slash\Path::paths($path?)
\slash\Path::files($path?)
\slash\Path::dirs($path?)
\slash\Path::exists($item)
\slash\Path::isPath($item)
\slash\Path::isFile($item)
\slash\Path::isDir($item)
\slash\Path::isDot($item)
\slash\Path::isAbs($path) // test if path is absolute
\slash\Path::toAbs($path) // resolve relative path
\slash\Path::toUri($path, $scheme?) // defaults to protocol-relative
\slash\Path::toUrl($path, $scheme?) // defaults to http or https
\slash\Path::isHttps()
\slash\Path::mtime($path)
\slash\Path::ctime($path)
\slash\Path::atime($path)
\slash\Path::affix($list, $prefix, $suffix?)
\slash\Path::infix($list, $infix)
\slash\Path::depth($path)
\slash\Path::tier($array)
\slash\Path::sort($array)
\slash\Path::locate($needles)
\slash\Path::contains($haystack, $needle)
\slash\Path::search($paths, $needles?)
\slash\Path::find($list, $test)

Mixin Methods

Extend Any Class

::mixin($name, $fn) // mixin a single method
::mixin($array) // mixin methods from an associative array
::mixin($object) // mixin methods from an object or class
::method($name) // fully-qualify a method (returns callable)
::methods($object?) // get array of all methods incl. mixins

Fund

Fund development with tips to @ryanve =)

Copyright (C) 2013 by Ryan Van Etten

slash's People

Contributors

ryanve avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.