SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2009
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    gException -What does it do in this code?

    Howdy again!
    Will someone explain what this line of code does?
    Code:
    if(strstr($class, 'Controller')):
       throw new gException('Class \''.$class.'\' could not be loaded by the          autoloader');
    endif;
    It's pulled from this block of code which I understand for the most part.
    Code:
    <?php
    
    class autoload
    {
    	public function __construct($class)
    	{
                /*The next line is also in the utility.php file. Each occurance is to set up
                 * 
                 */
    		$paths = parse_ini_file('../application/config/paths.ini.php', true);
    
    		foreach($paths['include_paths'] as $path):
    			$class = str_replace('_', '/', $class);
    			$file = $path.$class.'.php';
    			if(file_exists($file)):
    				include $file;
    				return;
    			endif;
    		endforeach;
    
    		if(strstr($class, 'Controller')):
    			throw new gException('Class \''.$class.'\' could not be loaded by the autoloader');
    		endif;
    	}
    }
    Thanks much.

  2. #2
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,396
    Mentioned
    61 Post(s)
    Tagged
    0 Thread(s)
    Which line in particular?
    Salathe
    Software Developer and PHP Manual Author.

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2009
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm sorry. The I meant to say block. The first block of code with the gException in it.

    Thanks

  4. #4
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    firstly it checks if the value of $class contains the word Controller, which by the looks of it the application disallows access to (after including it) by throwing an exception and possibly halting execution of the application (cant be sure of this without looking at the code within the gException class).

  5. #5
    SitePoint Zealot
    Join Date
    Sep 2009
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the gException code. Can you tell me what purpose would including access and then disallowing it would serve?
    Code:
    <?php
    
    class gException extends Exception
    {
    	public function __construct($message)
    	{
    		printr('', 'MVC APP');
    
    		printr($message, 'Message');
    
    		printr($this->file.'<br />Line: '.$this->getLine(), 'File');
    
    		printr($this->getTraceAsString(), 'Stack Trace');
    
    		printr(get_included_files(), 'Included Files');
    
    		die();
    	}
    }
    Thanks

  6. #6
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,396
    Mentioned
    61 Post(s)
    Tagged
    0 Thread(s)
    The exception is only thrown if the class's file could not be found in one of the defined paths and if the class name contains Controller. If the file could be found, or does not contain Controller then the gException is not thrown.
    Salathe
    Software Developer and PHP Manual Author.

  7. #7
    SitePoint Zealot
    Join Date
    Sep 2009
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the clarification.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •