Url

The Url class is an helper class that is used for managing urls. The methods available are as follows:

  1. path
  2. follows
  3. isLike
  4. is
  5. in
  6. hash
  7. query
The following keywords should be noted:

keywords
    
  $test_url : supplied url to be processed

  $some_url : supplied url to be compared
    
                                

Initializing url class
The Url class can be easily initialized as shown below.

Sample: Initializing url
  $Url  = new Url;
                                

path
The path() method supplies a url to be tested.

Syntax
  $Url->path($test_url);
                                        

Example
  $Url->path('/user/profile/settings');
                                

follows
The follows() method checks if a path follows a particular url supplied. This returns a boolean value of true or false

Syntax
  $Url->follows($some_url); 
    
    where: $some_url is the parent url structure that must be matched
    
                                        
Examples
  $Url->path('index')->follows('index'); // true

  $Url->path('index/profile')->follows('index'); // true

  $Url->path('index/profile')->follows('index/profile/user'); // false

  $Url->path('index/profile')->follows('profile'); // false
                                        

isLike
This method returns true if the url supplied into it exists as a root structure of the test url without any observable change in form.

Syntax
  $Url->isLike($some_url); 
                                        
Examples
  $Url->path('index')->isLike('index'); // true

  $Url->path('index/profile')->isLike('index'); // true

  $Url->path('index/profile/user')->isLike('index/profile'); // true

  $Url->path('index/profile/me')->isLike('index/profile/you'); // false
                                        

is
This method is used to check if two url is equal to each other

Example
  $Url->path('index')->is('index');  // true

  $Url->path('index/user', 'index/person');  //false
                                        

in
This method defines a list of urls that a supplied url must be a member of. If the array list supplied does not contain the url, then a boolean of false is returned.

Examples: in
  $Url->path('index')->in(['index', 'profile']); // true

  $Url->path('index')->in(['home', 'profile']);   // false
                                        

hash
The hash() method returns the hash of a string.

Example
  $Url->path('index#user');

  var_dump( $Url->hash() ); //returns user
                                        

query
The query method returns the query of a url. If query string is found, an array is returned else, a null value is returned

Example: query
  $Url->path("http://site.com/user?name=foo&class=bar"); 
  
  var_dump( $Url->query() ); //['name'=>'foo', 'class' => 'bar']