PathNavigator
[ class tree: PathNavigator ] [ index: PathNavigator ] [ all elements ]

Class: Text_PathNavigator

Source Location: /Text_PathNavigator-0.1.0dev1/PathNavigator.php

Class Overview


The Text_PathNavigator class provides convenient access to "/path/sub/strings".


Author(s):

Copyright:

  • 2006 Denny Shimkoski

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 48]
The Text_PathNavigator class provides convenient access to "/path/sub/strings".

These strings can be accessed in various ways:

  1. by numeric index (e.g., index 1 of /pages/staff.html returns "staff.html")
  2. by variable name (e.g., index "id" of /pages/id/1 returns 1)
  3. using the slice() method
  4. using the toArray() method
  5. in PHP 5, using the getIterator() method
When retrieving values by variable name, it is assumed that the entry following the first occurence of the given string is the value to be assigned.

Example 1.

  1.  require_once 'Text/PathNavigator.php';
  2.  $p = new Text_PathNavigator('/the/golden/path''/');
  3.  echo $p->get(2);          // prints 'path'
  4.  echo $p->get('golden');   // prints 'path'
  5.  echo $p->slice(1);        // prints 'golden/path'
  6.  echo $p->slice(-21);    // prints 'golden'
  7.  echo $p->slice(-1);       // prints 'path'



[ Top ]


Class Variables

$path =

[line 53]


Type:   string


[ Top ]

$slash =

[line 57]


Type:   string


[ Top ]

$vars =

[line 63]

Path after explode()

Type:   array


[ Top ]



Method Detail

Text_PathNavigator (Constructor)   [line 72]

Text_PathNavigator Text_PathNavigator( $path $path, [$slash $slash = DIRECTORY_SEPARATOR])

Constructor

Parameters:

$path   $path   —  array (e.g., array('test'=>'ok', 2, 3)) or string (e.g., '/test/ok/2/3')
$slash   $slash   — 

[ Top ]

get   [line 117]

null|false|string get( string $key)

Returns substrings by index or variable name

If $key appears to be a numeric index, attempts to return the corresponding substring (i.e., get(1) returns "val" from "/key/val"). Otherwise, searches path for a substring that matches $key and attempts to return the following entry. If the following entry is non-existent, null is returned. Returns false as a last resort.

  • Access: public

Parameters:

string   $key   —  the numeric index or variable name

[ Top ]

getIterator   [line 136]

null|object getIterator( [int $offset = 0])

Returns an ArrayIterator, starting at offset (PHP 5 only)
  • Access: public

Parameters:

int   $offset   —  the starting position

[ Top ]

load   [line 83]

false|array load( $path)

Loads a new path into the object
  • Access: public

Parameters:

   $path   — 

[ Top ]

slice   [line 176]

false|string slice( integer $offset, [integer $length = null])

Returns a slice from the path (see PHP's slice function for details)
  • Access: public

Parameters:

integer   $offset   — 
integer   $length   — 

[ Top ]

toArray   [line 155]

false|array toArray( [int $offset = 0])

Returns path as an associative array, starting at offset

Maps '/a/hello/b/world' to array('a' => 'hello', 'b' => 'world').

  • Access: public

Parameters:

int   $offset   —  the starting position

[ Top ]


Documentation generated on Mon, 11 Mar 2019 14:41:17 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.