Visit this project's SourceForge Project Page
Main Page | Class List | Directories | File List | Class Members | File Members | Related Pages

EUrl Class Reference

List of all members.

Detailed Description

This magical class will take information in and turn it into a nicely built URL. In the future it may even go so far as to take URLs apart for you, too.

Todo:
Check input (at all stages) for invalid characters ("?=" for index_path, ":" for domains users passwords and port, "/?=" for path_vars, "[^a-Z0-9]" for protocol
EUrl: The Easy URL Generator See the main page documentation

Author:
Jason Schmidt

Definition at line 282 of file EUrl.class.php.

Public Member Functions

 EUrl ()
 Constructor.
 GetValues ($Params=NULL)
 Get the merged variable list.
 SetValue ($VarName, $Value)
 Set a default or setting value.
 Generate ($Extra=NULL)
 Build a URL! The heart of gold for this class.

Private Member Functions

 _KeyNames ()
 Get a list of the constants allowed as keys.
 _ScopeOrder ()
 Get a list of scopes to take into account in order. Note that FIRST value wins, so the list is in an order of decreasing importance.
 _ConstantToKey ()
 Get a list of constant names and their appropriate keys.
 _EnvironmentToKey ()
 Get a list of environment variable names and their appropriate keys.
_Internal ()
 Get internal default values for each variable.
_Mining ()
 Get values extracted from PHP variables (this should only need to be run once).
_Environment ()
 Get values stored in the environment named EURL_VAR_* (this should only need to be run once).
_Constants ()
 Get values stored in the constants EURL_VAL_* (this will be run each time because you may decide to define MORE constants).
_Defaults ()
 Get a reference to a static variable for storing defaults.
_Global ()
 Get values stored in the $GLOBALS[EURL_VAR_*] by REFERENCE.

Private Attributes

 $_Settings
 Store anything sent to EUrl->SetValue(EURL_VAR_*,*).


Constructor & Destructor Documentation

EUrl::EUrl  ) 
 

Constructor.

Returns:
Reference to self
Author:
Jason Schmidt

Definition at line 453 of file EUrl.class.php.

References _KeyNames().

00454     {
00455         /*NODEBUG{*/
00456         if(EURL_DEBUG_EURL)
00457         {
00458             print(__CLASS__."::".__FUNCTION__."(");
00459             foreach(func_get_args() as $arg)
00460             {
00461                 print(var_export($arg,TRUE).",");
00462             }
00463             print(")\n");
00464         }
00465         /*}NODEBUG*/
00466 
00467         $this->_Settings = array();
00468         foreach(EUrl::_KeyNames() as $key)
00469         {
00470             $this->_Settings[$key] = NULL;
00471         }
00472     }

Here is the call graph for this function:


Member Function Documentation

& EUrl::_Constants  )  [private]
 

Get values stored in the constants EURL_VAL_* (this will be run each time because you may decide to define MORE constants).

Note:
This returns by reference because there's no point in copying the memory locations every call
Returns:
Array(EURL_VAR_*=>Value)
Author:
Jason Schmidt

Definition at line 761 of file EUrl.class.php.

References _ConstantToKey().

Referenced by GetValues().

00762     {
00763         /*NODEBUG{*/
00764         if(EURL_DEBUG_CONSTANTS)
00765         {
00766             print(__CLASS__."::".__FUNCTION__."(");
00767             foreach(func_get_args() as $arg)
00768             {
00769                 print(var_export($arg,TRUE).",");
00770             }
00771             print(")\n");
00772         }
00773         /*}NODEBUG*/
00774 
00775         static $defined = array();
00776 
00777         // For each allowable constant
00778         foreach(EUrl::_ConstantToKey() as $val_key => $key)
00779         {
00780             // If the current value is NULL
00781             if(!isset($defined[$key]))
00782             {
00783                 // And we have a new value...
00784                 if(defined($val_key))
00785                 {
00786                     /*NODEBUG{*/
00787                     if(EURL_DEBUG_CONSTANTS)
00788                     {
00789                         print(__CLASS__."::".__FUNCTION__."(): ");
00790                         print("$key found in constant\n");
00791                     }
00792                     /*}NODEBUG*/
00793 
00794                     $defined[$key] = constant($val_key);
00795                 }
00796                 else
00797                 {
00798                     $defined[$key] = NULL;
00799                 }
00800             }
00801         }
00802 
00803         return($defined);
00804     }

Here is the call graph for this function:

EUrl::_ConstantToKey  )  [private]
 

Get a list of constant names and their appropriate keys.

Returns:
Array(ValName=>VarName)
Author:
Jason Schmidt

Definition at line 378 of file EUrl.class.php.

Referenced by _Constants().

00379     {
00380         /*NODEBUG{*/
00381         if(EURL_DEBUG_CONSTANTTOKEY)
00382         {
00383             print(__CLASS__."::".__FUNCTION__."(");
00384             foreach(func_get_args() as $arg)
00385             {
00386                 print(var_export($arg,TRUE).",");
00387             }
00388             print(")\n");
00389         }
00390         /*}NODEBUG*/
00391 
00392         return(array(
00393             "EURL_VAL_PROTOCOL"       => EURL_VAR_PROTOCOL       ,
00394             "EURL_VAL_USER"           => EURL_VAR_USER           ,
00395             "EURL_VAL_PASS"           => EURL_VAR_PASS           ,
00396             "EURL_VAL_DOMAIN"         => EURL_VAR_DOMAIN         ,
00397             "EURL_VAL_SUB_DOMAIN"     => EURL_VAR_SUB_DOMAIN     ,
00398             "EURL_VAL_PORT"           => EURL_VAR_PORT           ,
00399             "EURL_VAL_INDEX_PATH"     => EURL_VAR_INDEX_PATH     ,
00400             "EURL_VAL_PATH_WITH_KEYS" => EURL_VAR_PATH_WITH_KEYS ,
00401             "EURL_VAL_FILE_NAME"      => EURL_VAR_FILE_NAME      ,
00402             "EURL_VAL_FRAGMENT"       => EURL_VAR_FRAGMENT       ,
00403             ));
00404     }

& EUrl::_Defaults  )  [private]
 

Get a reference to a static variable for storing defaults.

Returns:
Reference to array
Author:
Jason Schmidt

Definition at line 816 of file EUrl.class.php.

References _KeyNames().

Referenced by GetValues(), and SetValue().

00817     {
00818         /*NODEBUG{*/
00819         if(EURL_DEBUG_DEFAULTS)
00820         {
00821             print(__CLASS__."::".__FUNCTION__."(");
00822             foreach(func_get_args() as $arg)
00823             {
00824                 print(var_export($arg,TRUE).",");
00825             }
00826             print(")\n");
00827         }
00828         /*}NODEBUG*/
00829 
00830         static $internal = NULL;
00831 
00832         if(NULL === $internal)
00833         {
00834             /*NODEBUG{*/
00835             if(EURL_DEBUG_DEFAULTS)
00836             {
00837                 print(__CLASS__."::".__FUNCTION__."(): ");
00838                 print("Initializing static defaults\n");
00839             }
00840             /*}NODEBUG*/
00841 
00842             $internal = array();
00843             foreach(EUrl::_KeyNames() as $key)
00844             {
00845                 $internal[$key] = NULL;
00846             }
00847         }
00848 
00849         return($internal);
00850     }

Here is the call graph for this function:

& EUrl::_Environment  )  [private]
 

Get values stored in the environment named EURL_VAR_* (this should only need to be run once).

Note:
This returns by reference because there's no point in copying the memory locations every call
Returns:
&Array(EURL_VAR_*=>&$_ENV[Value])
Author:
Jason Schmidt

Definition at line 693 of file EUrl.class.php.

References _EnvironmentToKey().

Referenced by GetValues().

00694     {
00695         /*NODEBUG{*/
00696         if(EURL_DEBUG_ENVIRONMENT)
00697         {
00698             print(__CLASS__."::".__FUNCTION__."(");
00699             foreach(func_get_args() as $arg)
00700             {
00701                 print(var_export($arg,TRUE).",");
00702             }
00703             print(")\n");
00704         }
00705         /*}NODEBUG*/
00706 
00707         static $return = NULL;
00708 
00709         if(NULL === $return)
00710         {
00711             foreach(EUrl::_EnvironmentToKey() as $env_key => $key)
00712             {
00713                 if(isset($_ENV[$env_key]))
00714                 {
00715                     /*NODEBUG{*/
00716                     if(EURL_DEBUG_ENVIRONMENT)
00717                     {
00718                         print(__CLASS__."::".__FUNCTION__."(): ");
00719                         print("$key found in environment\n");
00720                     }
00721                     /*}NODEBUG*/
00722 
00723                     $return[$key] =& $_ENV[$env_key];
00724                 }
00725                 elseif(isset($_SERVER[$env_key]))
00726                 {
00727                     /*NODEBUG{*/
00728                     if(EURL_DEBUG_ENVIRONMENT)
00729                     {
00730                         print(__CLASS__."::".__FUNCTION__."(): ");
00731                         print("$key found in server vars\n");
00732                     }
00733                     /*}NODEBUG*/
00734 
00735                     $return[$key] =& $_SERVER[$env_key];
00736                 }
00737                 else
00738                 {
00739                     $return[$key] =  NULL;
00740                 }
00741             }
00742         }
00743 
00744         return($return);
00745     }

Here is the call graph for this function:

EUrl::_EnvironmentToKey  )  [private]
 

Get a list of environment variable names and their appropriate keys.

Returns:
Array(EnvName=>VarName)
Author:
Jason Schmidt

Definition at line 416 of file EUrl.class.php.

Referenced by _Environment().

00417     {
00418         /*NODEBUG{*/
00419         if(EURL_DEBUG_ENVIRONMENTTOKEY)
00420         {
00421             print(__CLASS__."::".__FUNCTION__."(");
00422             foreach(func_get_args() as $arg)
00423             {
00424                 print(var_export($arg,TRUE).",");
00425             }
00426             print(")\n");
00427         }
00428         /*}NODEBUG*/
00429 
00430         return(array(
00431             "EURL_ENV_PROTOCOL"       => EURL_VAR_PROTOCOL       ,
00432             "EURL_ENV_USER"           => EURL_VAR_USER           ,
00433             "EURL_ENV_PASS"           => EURL_VAR_PASS           ,
00434             "EURL_ENV_DOMAIN"         => EURL_VAR_DOMAIN         ,
00435             "EURL_ENV_SUB_DOMAIN"     => EURL_VAR_SUB_DOMAIN     ,
00436             "EURL_ENV_PORT"           => EURL_VAR_PORT           ,
00437             "EURL_ENV_INDEX_PATH"     => EURL_VAR_INDEX_PATH     ,
00438             "EURL_ENV_PATH_WITH_KEYS" => EURL_VAR_PATH_WITH_KEYS ,
00439             "EURL_ENV_FILE_NAME"      => EURL_VAR_FILE_NAME      ,
00440             "EURL_ENV_FRAGMENT"       => EURL_VAR_FRAGMENT       ,
00441             ));
00442     }

& EUrl::_Global  )  [private]
 

Get values stored in the $GLOBALS[EURL_VAR_*] by REFERENCE.

Returns:
&Array(&$GLOBALS[...])
Author:
Jason Schmidt

Definition at line 862 of file EUrl.class.php.

References _KeyNames().

Referenced by GetValues().

00863     {
00864         /*NODEBUG{*/
00865         if(EURL_DEBUG_GLOBAL)
00866         {
00867             print(__CLASS__."::".__FUNCTION__."(");
00868             foreach(func_get_args() as $arg)
00869             {
00870                 print(var_export($arg,TRUE).",");
00871             }
00872             print(")\n");
00873         }
00874         /*}NODEBUG*/
00875 
00876         static $global_refs = NULL;
00877 
00878         if(NULL === $global_refs)
00879         {
00880             /*NODEBUG{*/
00881             if(EURL_DEBUG_GLOBAL)
00882             {
00883                 print(__CLASS__."::".__FUNCTION__."(): ");
00884                 print("Referencing _GLOBALS\n");
00885             }
00886             /*}NODEBUG*/
00887 
00888             foreach(EUrl::_KeyNames() as $key)
00889             {
00890                 $global_refs[$key] =& $GLOBALS[$key];
00891             }
00892         }
00893 
00894         return($global_refs);
00895     }

Here is the call graph for this function:

& EUrl::_Internal  )  [private]
 

Get internal default values for each variable.

Note:
This returns by reference because there's no point in copying the memory locations every call
Returns:
&Array(EURL_VAR_*=>Value)
Author:
Jason Schmidt

Definition at line 486 of file EUrl.class.php.

Referenced by GetValues().

00487     {
00488         /*NODEBUG{*/
00489         if(EURL_DEBUG_INTERNAL)
00490         {
00491             print(__CLASS__."::".__FUNCTION__."(");
00492             foreach(func_get_args() as $arg)
00493             {
00494                 print(var_export($arg,TRUE).",");
00495             }
00496             print(")\n");
00497         }
00498         /*}NODEBUG*/
00499 
00500         static $defaults = array(
00501             EURL_VAR_PROTOCOL       => "http"      ,
00502             EURL_VAR_USER           => NULL        ,
00503             EURL_VAR_PASS           => NULL        ,
00504             EURL_VAR_DOMAIN         => "localhost" ,
00505             EURL_VAR_SUB_DOMAIN     => NULL        ,
00506             EURL_VAR_PORT           => NULL        ,
00507             EURL_VAR_INDEX_PATH     => NULL        ,
00508             EURL_VAR_PATH_WITH_KEYS => FALSE       ,
00509             EURL_VAR_PATH_VARS      => NULL        ,
00510             EURL_VAR_FILE_NAME      => NULL        ,
00511             EURL_VAR_GET_VARS       => NULL        ,
00512             EURL_VAR_FRAGMENT       => NULL        ,
00513             );
00514 
00515         return($defaults);
00516     }

EUrl::_KeyNames  )  [private]
 

Get a list of the constants allowed as keys.

Returns:
Array(KeyName)
Author:
Jason Schmidt

Definition at line 302 of file EUrl.class.php.

Referenced by _Defaults(), _Global(), EUrl(), Generate(), GetValues(), and SetValue().

00303     {
00304         /*NODEBUG{*/
00305         if(EURL_DEBUG_KEYNAMES)
00306         {
00307             print(__CLASS__."::".__FUNCTION__."(");
00308             foreach(func_get_args() as $arg)
00309             {
00310                 print(var_export($arg,TRUE).",");
00311             }
00312             print(")\n");
00313         }
00314         /*}NODEBUG*/
00315 
00316         return(array(
00317             EURL_VAR_PROTOCOL       ,
00318             EURL_VAR_USER           ,
00319             EURL_VAR_PASS           ,
00320             EURL_VAR_DOMAIN         ,
00321             EURL_VAR_SUB_DOMAIN     ,
00322             EURL_VAR_PORT           ,
00323             EURL_VAR_INDEX_PATH     ,
00324             EURL_VAR_PATH_WITH_KEYS ,
00325             EURL_VAR_PATH_VARS      ,
00326             EURL_VAR_FILE_NAME      ,
00327             EURL_VAR_GET_VARS       ,
00328             EURL_VAR_FRAGMENT       ,
00329             ));
00330     }

& EUrl::_Mining  )  [private]
 

Get values extracted from PHP variables (this should only need to be run once).

Note:
This returns by reference because there's no point in copying the memory locations every call
Returns:
Array(EURL_VAR_*=>Value)
Author:
Jason Schmidt

Definition at line 531 of file EUrl.class.php.

Referenced by GetValues().

00532     {
00533         /*NODEBUG{*/
00534         if(EURL_DEBUG_MINING)
00535         {
00536             print(__CLASS__."::".__FUNCTION__."(");
00537             foreach(func_get_args() as $arg)
00538             {
00539                 print(var_export($arg,TRUE).",");
00540             }
00541             print(")\n");
00542         }
00543         /*}NODEBUG*/
00544 
00545         static $return = NULL;
00546 
00547         if(NULL === $return)
00548         {
00549             $return = array(
00550                 EURL_VAR_PROTOCOL       => NULL,
00551                 EURL_VAR_USER           => NULL,
00552                 EURL_VAR_PASS           => NULL,
00553                 EURL_VAR_DOMAIN         => NULL,
00554                 EURL_VAR_SUB_DOMAIN     => NULL,
00555                 EURL_VAR_PORT           => NULL,
00556                 EURL_VAR_INDEX_PATH     => NULL,
00557                 EURL_VAR_PATH_WITH_KEYS => NULL,
00558                 EURL_VAR_PATH_VARS      => NULL,
00559                 EURL_VAR_GET_VARS       => NULL,
00560                 EURL_VAR_FRAGMENT       => NULL,
00561                 );
00562 
00563             if(isset($_SERVER))
00564             {
00565                 if(isset($_SERVER['HTTPS']))
00566                 {
00567                     /*NODEBUG{*/
00568                     if(EURL_DEBUG_MINING)
00569                     {
00570                         print(__CLASS__."::".__FUNCTION__."(): ");
00571                         print("SSL Enabled\n");
00572                     }
00573                     /*}NODEBUG*/
00574 
00575                     $return[EURL_VAR_PROTOCOL] = "https";
00576                 }
00577                 if(isset($_SERVER['PHP_AUTH_USER']))
00578                 {
00579                     /*NODEBUG{*/
00580                     if(EURL_DEBUG_MINING)
00581                     {
00582                         print(__CLASS__."::".__FUNCTION__."(): ");
00583                         print("User found: ");
00584                         print($_SERVER['PHP_AUTH_USER']);
00585                         print("\n");
00586                     }
00587                     /*}NODEBUG*/
00588 
00589                     $return[EURL_VAR_USER] = $_SERVER['PHP_AUTH_USER'];
00590                 }
00591                 if(isset($_SERVER['PHP_AUTH_PW']))
00592                 {
00593                     /*NODEBUG{*/
00594                     if(EURL_DEBUG_MINING)
00595                     {
00596                         print(__CLASS__."::".__FUNCTION__."(): ");
00597                         print("Password found: ");
00598                         print($_SERVER['PHP_AUTH_PW']);
00599                         print("\n");
00600                     }
00601                     /*}NODEBUG*/
00602 
00603                     $return[EURL_VAR_PASS] = $_SERVER['PHP_AUTH_PW'];
00604                 }
00605                 if(isset($_SERVER['HTTP_HOST']))
00606                 {
00607                     $host  = $_SERVER['HTTP_HOST'];
00608                     $regex = "/^(([^\.]+)\.){0,}([^\.]+\..{2,3})$/";
00609 
00610                     if(preg_match($regex, $host, $match))
00611                     {
00612                         $subdomain = $match[2];
00613                         $domain    = $match[3];
00614 
00615                         if($subdomain)
00616                         {
00617                             /*NODEBUG{*/
00618                             if(EURL_DEBUG_MINING)
00619                             {
00620                                 print(__CLASS__."::".__FUNCTION__."(): ");
00621                                 print("Subdomain found: ");
00622                                 print($subdomain);
00623                                 print("\n");
00624                             }
00625                             /*}NODEBUG*/
00626 
00627                             $return[EURL_VAR_SUB_DOMAIN] = $subdomain;
00628                         }
00629 
00630                         /*NODEBUG{*/
00631                         if(EURL_DEBUG_MINING)
00632                         {
00633                             print(__CLASS__."::".__FUNCTION__."(): ");
00634                             print("Domain found: ");
00635                             print($domain);
00636                             print("\n");
00637                         }
00638                         /*}NODEBUG*/
00639 
00640                         $return[EURL_VAR_DOMAIN] = $domain;
00641                     }
00642                 }
00643                 if(isset($_SERVER['SCRIPT_NAME']))
00644                 {
00645                     $path = $_SERVER['SCRIPT_NAME'];
00646                     $path = trim($path, "\\/");
00647 
00648                     /*NODEBUG{*/
00649                     if(EURL_DEBUG_MINING)
00650                     {
00651                         print(__CLASS__."::".__FUNCTION__."(): ");
00652                         print("Scriptname found: ");
00653                         print($path);
00654                         print("\n");
00655                     }
00656                     /*}NODEBUG*/
00657 
00658                     $return[EURL_VAR_INDEX_PATH] = $path;
00659                 }
00660                 if(isset($_SERVER['SERVER_PORT']))
00661                 {
00662                     /*NODEBUG{*/
00663                     if(EURL_DEBUG_MINING)
00664                     {
00665                         print(__CLASS__."::".__FUNCTION__."(): ");
00666                         print("Port number found: ");
00667                         print($_SERVER['SERVER_PORT']);
00668                         print("\n");
00669                     }
00670                     /*}NODEBUG*/
00671 
00672                     $return[EURL_VAR_PORT] = $_SERVER['SERVER_PORT'];
00673                 }
00674             }
00675         }
00676 
00677         return($return);
00678     }

EUrl::_ScopeOrder  )  [private]
 

Get a list of scopes to take into account in order. Note that FIRST value wins, so the list is in an order of decreasing importance.

Returns:
Array(ScopeName)
Author:
Jason Schmidt

Definition at line 343 of file EUrl.class.php.

Referenced by GetValues().

00344     {
00345         /*NODEBUG{*/
00346         if(EURL_DEBUG_SCOPEORDER)
00347         {
00348             print(__CLASS__."::".__FUNCTION__."(");
00349             foreach(func_get_args() as $arg)
00350             {
00351                 print(var_export($arg,TRUE).",");
00352             }
00353             print(")\n");
00354         }
00355         /*}NODEBUG*/
00356 
00357         return(array(
00358             EURL_SCOPE_PARAMETERS   ,
00359             EURL_SCOPE_SETTINGS     ,
00360             EURL_SCOPE_GLOBAL       ,
00361             EURL_SCOPE_DEFAULTS     ,
00362             EURL_SCOPE_CONSTANTS    ,
00363             EURL_SCOPE_ENVIRONMENT  ,
00364             EURL_SCOPE_MINING       ,
00365             EURL_SCOPE_INTERNAL     ,
00366             ));
00367     }

EUrl::Generate Extra = NULL  ) 
 

Build a URL! The heart of gold for this class.

Parameters:
$Extra Array(EURL_VAR_*=>Value) Optional
Returns:
String URL
Author:
Jason Schmidt

Definition at line 1125 of file EUrl.class.php.

References _KeyNames(), and GetValues().

01126     {
01127         /*NODEBUG{*/
01128         if(EURL_DEBUG_GENERATE)
01129         {
01130             print(__CLASS__."::".__FUNCTION__."(");
01131             foreach(func_get_args() as $arg)
01132             {
01133                 print(var_export($arg,TRUE).",");
01134             }
01135             print(")\n");
01136         }
01137         /*}NODEBUG*/
01138 
01139         // Check input
01140         $KeyNames = EUrl::_KeyNames();
01141         if(is_array($Extra))
01142         {
01143             foreach($Extra as $Key => $Value)
01144             {
01145                 // Check key name
01146                 if(!in_array($Key, $KeyNames))
01147                 {
01148                     /*NODEBUG{*/
01149                     if(EURL_DEBUG_GENERATE)
01150                     {
01151                         print(__CLASS__."::".__FUNCTION__."(): ");
01152                         print("Unknown variable $Key\n");
01153                     }
01154                     /*}NODEBUG*/
01155 
01156                     trigger_error(
01157                         "Unknown EURL_VAR_*: "
01158                         . var_export($Key, TRUE)
01159                         , E_USER_ERROR
01160                         );
01161                 }
01162             }
01163         }
01164         elseif(NULL !== $Extra)
01165         {
01166             /*NODEBUG{*/
01167             if(EURL_DEBUG_GENERATE)
01168             {
01169                 print(__CLASS__."::".__FUNCTION__."(): ");
01170                 print("Unexpected parameter: ");
01171                 print(var_export($Extra, TRUE));
01172                 print("\n");
01173             }
01174             /*}NODEBUG*/
01175 
01176             // Error on invalid input
01177             trigger_error(
01178                 "Extra must be NULL or Array: "
01179                 . var_export($Extra, TRUE)
01180                 , E_USER_ERROR
01181                 );
01182         }
01183 
01184         // Depending on scope...
01185         if(isset($this))
01186         {
01187             /*NODEBUG{*/
01188             if(EURL_DEBUG_GENERATE)
01189             {
01190                 print(__CLASS__."::".__FUNCTION__."(): ");
01191                 print("Calling from instantiated object\n");
01192             }
01193             /*}NODEBUG*/
01194 
01195             $vars = $this->GetValues($Extra);
01196         }
01197         else
01198         {
01199             /*NODEBUG{*/
01200             if(EURL_DEBUG_GENERATE)
01201             {
01202                 print(__CLASS__."::".__FUNCTION__."(): ");
01203                 print("Calling statically\n");
01204             }
01205             /*}NODEBUG*/
01206 
01207             $vars = EUrl::GetValues($Extra);
01208         }
01209 
01210         // Start with an empty string
01211         $url = "";
01212 
01213         // Add protocol
01214         if(!isset($vars[EURL_VAR_PROTOCOL]))
01215         {
01216             /*NODEBUG{*/
01217             if(EURL_DEBUG_GENERATE)
01218             {
01219                 print(__CLASS__."::".__FUNCTION__."(): ");
01220                 print("Protocol must be defined\n");
01221             }
01222             /*}NODEBUG*/
01223 
01224             trigger_error(
01225                 "No protocol set!"
01226                 , E_USER_ERROR
01227                 );
01228         }
01229         $url .= $vars[EURL_VAR_PROTOCOL];
01230         $url .= "://";
01231 
01232         // Add username and password
01233         if(isset($vars[EURL_VAR_USER]))
01234         {
01235             /*NODEBUG{*/
01236             if(EURL_DEBUG_GENERATE)
01237             {
01238                 print(__CLASS__."::".__FUNCTION__."(): ");
01239                 print("Including user in URL\n");
01240             }
01241             /*}NODEBUG*/
01242 
01243             $url .= rawurlencode($vars[EURL_VAR_USER]);
01244             if(isset($vars[EURL_VAR_PASS]))
01245             {
01246                 /*NODEBUG{*/
01247                 if(EURL_DEBUG_GENERATE)
01248                 {
01249                     print(__CLASS__."::".__FUNCTION__."(): ");
01250                     print("Including password in URL\n");
01251                 }
01252                 /*}NODEBUG*/
01253 
01254                 $url .= ':'.rawurlencode($vars[EURL_VAR_PASS]);
01255             }
01256             $url .= '@';
01257         }
01258 
01259         // Add domain name
01260         if(isset($vars[EURL_VAR_SUB_DOMAIN]))
01261         {
01262             /*NODEBUG{*/
01263             if(EURL_DEBUG_GENERATE)
01264             {
01265                 print(__CLASS__."::".__FUNCTION__."(): ");
01266                 print("Including sub-domain\n");
01267             }
01268             /*}NODEBUG*/
01269 
01270             $url .= $vars[EURL_VAR_SUB_DOMAIN];
01271             $url .= ".";
01272         }
01273         if(!isset($vars[EURL_VAR_DOMAIN]))
01274         {
01275             /*NODEBUG{*/
01276             if(EURL_DEBUG_GENERATE)
01277             {
01278                 print(__CLASS__."::".__FUNCTION__."(): ");
01279                 print("Domain must be set\n");
01280             }
01281             /*}NODEBUG*/
01282 
01283             trigger_error(
01284                 "No domain set!"
01285                 , E_USER_ERROR
01286                 );
01287         }
01288         $url .= $vars[EURL_VAR_DOMAIN];
01289 
01290         // Add port
01291         if(isset($vars[EURL_VAR_PORT]) && $vars[EURL_VAR_PORT])
01292         {
01293             /*NODEBUG{*/
01294             if(EURL_DEBUG_GENERATE)
01295             {
01296                 print(__CLASS__."::".__FUNCTION__."(): ");
01297                 print("Adding port number to URL\n");
01298             }
01299             /*}NODEBUG*/
01300 
01301             $url .= ":";
01302             $url .= $vars[EURL_VAR_PORT];
01303         }
01304         $url .= "/";
01305 
01306         // Add index file
01307         if(isset($vars[EURL_VAR_INDEX_PATH]))
01308         {
01309             /*NODEBUG{*/
01310             if(EURL_DEBUG_GENERATE)
01311             {
01312                 print(__CLASS__."::".__FUNCTION__."(): ");
01313                 print("Adding index file path to URL\n");
01314             }
01315             /*}NODEBUG*/
01316 
01317             $url .= $vars[EURL_VAR_INDEX_PATH];
01318         }
01319 
01320         // Add path variables data
01321         if(!isset($vars[EURL_VAR_PATH_WITH_KEYS]))
01322         {
01323             /*NODEBUG{*/
01324             if(EURL_DEBUG_GENERATE)
01325             {
01326                 print(__CLASS__."::".__FUNCTION__."(): ");
01327                 print("No determination for handling PATH vars found\n");
01328             }
01329             /*}NODEBUG*/
01330 
01331             trigger_error(
01332                 "EURL_VAR_PATH_WITH_KEYS must be boolean!"
01333                 , E_USER_ERROR
01334                 );
01335         }
01336         if(isset($vars[EURL_VAR_PATH_VARS]))
01337         {
01338             /*NODEBUG{*/
01339             if(EURL_DEBUG_GENERATE)
01340             {
01341                 print(__CLASS__."::".__FUNCTION__."(): ");
01342                 print("Including PATH variables in URL\n");
01343             }
01344             /*}NODEBUG*/
01345 
01346             foreach($vars[EURL_VAR_PATH_VARS] as $key=>$value)
01347             {
01348                 if($vars[EURL_VAR_PATH_WITH_KEYS])
01349                 {
01350                     $url .= "/";
01351                     $url .= rawurlencode($key  );
01352                 }
01353 
01354                 $url .= "/";
01355                 $url .= rawurlencode($value);
01356             }
01357         }
01358 
01359         // Add effective file name
01360         if(isset($vars[EURL_VAR_FILE_NAME]))
01361         {
01362             /*NODEBUG{*/
01363             if(EURL_DEBUG_GENERATE)
01364             {
01365                 print(__CLASS__."::".__FUNCTION__."(): ");
01366                 print("Including an effective file in URL\n");
01367             }
01368             /*}NODEBUG*/
01369 
01370             $url .= "/";
01371             $url .= $vars[EURL_VAR_FILE_NAME];
01372         }
01373 
01374         // Add GET parameters
01375         if(isset($vars[EURL_VAR_GET_VARS]) && $vars[EURL_VAR_GET_VARS])
01376         {
01377             /*NODEBUG{*/
01378             if(EURL_DEBUG_GENERATE)
01379             {
01380                 print(__CLASS__."::".__FUNCTION__."(): ");
01381                 print("Including GET variables in URL\n");
01382             }
01383             /*}NODEBUG*/
01384 
01385             $gets = array();
01386             foreach($vars[EURL_VAR_GET_VARS] as $key=>$value)
01387             {
01388                 $gets[] =     rawurlencode($key  ).
01389                           '='.rawurlencode($value);
01390             }
01391             $url .= "?";
01392             $url .= join("&",$gets);
01393         }
01394 
01395         // Add Fragment
01396         if(isset($vars[EURL_VAR_FRAGMENT]) && $vars[EURL_VAR_FRAGMENT])
01397         {
01398             /*NODEBUG{*/
01399             if(EURL_DEBUG_GENERATE)
01400             {
01401                 print(__CLASS__."::".__FUNCTION__."(): ");
01402                 print("Including FRAGMENT in URL\n");
01403             }
01404             /*}NODEBUG*/
01405 
01406             $url .= "#";
01407             $url .= $vars[EURL_VAR_FRAGMENT];
01408         }
01409 
01410         /*NODEBUG{*/
01411         if(EURL_DEBUG_GENERATE)
01412         {
01413             print(__CLASS__."::".__FUNCTION__."(): ");
01414             print("$url\n");
01415         }
01416         /*}NODEBUG*/
01417 
01418         return($url);
01419     }

Here is the call graph for this function:

EUrl::GetValues Params = NULL  ) 
 

Get the merged variable list.

Parameters:
$Params NULL || Array(EURL_VAR_*=>Value) Optional: Values to return in the EURL_SCOPE_PARAMETERS
Returns:
Reference to variable namespace
Author:
Jason Schmidt

Definition at line 909 of file EUrl.class.php.

References _Constants(), _Defaults(), _Environment(), _Global(), _Internal(), _KeyNames(), _Mining(), and _ScopeOrder().

Referenced by Generate().

00910     {
00911         /*NODEBUG{*/
00912         if(EURL_DEBUG_GETVALUES)
00913         {
00914             print(__CLASS__."::".__FUNCTION__."(");
00915             foreach(func_get_args() as $arg)
00916             {
00917                 print(var_export($arg,TRUE).",");
00918             }
00919             print(")\n");
00920         }
00921         /*}NODEBUG*/
00922 
00923         static $empty       = array();
00924         static $static_vars = NULL;
00925 
00926         // The static bits which don't change, IE: Internal defaults,
00927         // data mined from PHP, etc.
00928         if(NULL === $static_vars)
00929         {
00930             /*NODEBUG{*/
00931             if(EURL_DEBUG_GETVALUES)
00932             {
00933                 print(__CLASS__."::".__FUNCTION__."(): ");
00934                 print("Initializing completely static returns\n");
00935             }
00936             /*}NODEBUG*/
00937 
00938             $static_vars = array();
00939             $static_vars[EURL_SCOPE_INTERNAL   ] =& EUrl::_Internal();
00940             $static_vars[EURL_SCOPE_CONSTANTS  ] =& EUrl::_Constants();
00941             $static_vars[EURL_SCOPE_MINING     ] =& EUrl::_Mining();
00942             $static_vars[EURL_SCOPE_ENVIRONMENT] =& EUrl::_Environment();
00943             $static_vars[EURL_SCOPE_DEFAULTS   ] =& EUrl::_Defaults();
00944             $static_vars[EURL_SCOPE_GLOBAL     ] =& EUrl::_Global();
00945         }
00946 
00947         // Now copy all our static variables and referenced variables in
00948         $vars = array();
00949 
00950         // We rerun this each time because you may have defined MORE
00951         // constants since the last time we did this.
00952         EUrl::_Constants();
00953 
00954         // If we're locally instantiated, we'll have settings to grab
00955         // as well
00956         if(isset($this))
00957         {
00958             /*NODEBUG{*/
00959             if(EURL_DEBUG_GETVALUES)
00960             {
00961                 print(__CLASS__."::".__FUNCTION__."(): ");
00962                 print("Getting instantiated settings, too\n");
00963             }
00964             /*}NODEBUG*/
00965 
00966             $vars[EURL_SCOPE_SETTINGS] =& $this->_Settings;
00967         }
00968 
00969         // If they've passed parameters to the Generate function, we
00970         // want to include them here...
00971         if(NULL !== $Params)
00972         {
00973             /*NODEBUG{*/
00974             if(EURL_DEBUG_GETVALUES)
00975             {
00976                 print(__CLASS__."::".__FUNCTION__."(): ");
00977                 print("Including parameters in parse\n");
00978             }
00979             /*}NODEBUG*/
00980 
00981             $vars[EURL_SCOPE_PARAMETERS] =& $Params;
00982         }
00983 
00984         // For each scope
00985         $return     = array();
00986         $scopeorder = EUrl::_ScopeOrder();
00987         $keynames   = EUrl::_KeyNames();
00988         foreach($scopeorder as $scope)
00989         {
00990             $scoped =& $empty;
00991 
00992             if(isset($static_vars[$scope]))
00993             {
00994                 $scoped =& $static_vars[$scope];
00995             }
00996 
00997             if(isset($vars[$scope]))
00998             {
00999                 $scoped =& $vars[$scope];
01000             }
01001 
01002             foreach($keynames as $key)
01003             {
01004                 if(!isset($return[$key]) && isset($scoped[$key]))
01005                 {
01006                     /*NODEBUG{*/
01007                     if(EURL_DEBUG_GETVALUES)
01008                     {
01009                         print(__CLASS__."::".__FUNCTION__."(): ");
01010                         print("$key from $scope\n");
01011                     }
01012                     /*}NODEBUG*/
01013 
01014                     $return[$key] = $scoped[$key];
01015                 }
01016             }
01017         }
01018 
01019         return($return);
01020     }

Here is the call graph for this function:

EUrl::SetValue VarName,
Value
 

Set a default or setting value.

 // If you wish to set a default, call this function statically:
 EUrl::SetValue( EURL_VAR_DOMAIN , "MyDomain.com" );

 // If you wish to set a locally instantiated value:
 $ExternalLink = new EUrl();
 $ExternalLink->SetValue( EURL_VAR_DOMAIN , "SomeoneElse.com" );

Warning:
Calls trigger_error if you pass an invalid $VarName, but does NOT error on invalid $Value. That happens when you attempt to EUrl::Generate()
Parameters:
$VarName Constant Required: EURL_VAR_*
$Value Mixed Required: See EURL_VAR_* For appropriate type
Returns:
NULL
Author:
Jason Schmidt

Definition at line 1049 of file EUrl.class.php.

References _Defaults(), and _KeyNames().

01050     {
01051         /*NODEBUG{*/
01052         if(EURL_DEBUG_SETVALUE)
01053         {
01054             print(__CLASS__."::".__FUNCTION__."(");
01055             foreach(func_get_args() as $arg)
01056             {
01057                 print(var_export($arg,TRUE).",");
01058             }
01059             print(")\n");
01060         }
01061         /*}NODEBUG*/
01062 
01063         // Check key name
01064         if(!in_array($VarName, EUrl::_KeyNames()))
01065         {
01066             /*NODEBUG{*/
01067             if(EURL_DEBUG_SETVALUE)
01068             {
01069                 print(__CLASS__."::".__FUNCTION__."(): ");
01070                 print("Unknown variable $VarName\n");
01071             }
01072             /*}NODEBUG*/
01073 
01074             trigger_error(
01075                 "Unknown EURL_VAR_*: "
01076                 . var_export($VarName, TRUE)
01077                 , E_USER_ERROR
01078                 );
01079         }
01080 
01081         // Check scope to put it in
01082         if(isset($this))
01083         {
01084             /*NODEBUG{*/
01085             if(EURL_DEBUG_SETVALUE)
01086             {
01087                 print(__CLASS__."::".__FUNCTION__."(): ");
01088                 print("Storing $VarName in instantiated object\n");
01089             }
01090             /*}NODEBUG*/
01091 
01092             $array =& $this->_Settings;
01093         }
01094         else
01095         {
01096             /*NODEBUG{*/
01097             if(EURL_DEBUG_SETVALUE)
01098             {
01099                 print(__CLASS__."::".__FUNCTION__."(): ");
01100                 print("Storing $VarName in static defaults\n");
01101             }
01102             /*}NODEBUG*/
01103 
01104             $array =& EUrl::_Defaults();
01105         }
01106 
01107         // Store value
01108         $array[$VarName] = $Value;
01109 
01110         // Return null
01111         return(NULL);
01112     }

Here is the call graph for this function:


Member Data Documentation

EUrl::$_Settings [private]
 

Store anything sent to EUrl->SetValue(EURL_VAR_*,*).

Author:
Jason Schmidt

Definition at line 291 of file EUrl.class.php.


The documentation for this class was generated from the following file:


Generously hosted by   SourceForge.net Logo
Generated on Wed Jun 1 11:01:07 2005 for EUrl by   Doxygen 1.4.1