Changeset 276

Show
Ignore:
Timestamp:
05/29/07 10:21:15
Author:
danfreak
Message:

adding "atomagic" for extending core classes: see ticket #67

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • FreakAuth/trunk/www/system/application/config/freakauth_light.php

    r274 r276  
    4747 */ 
    4848 $config['FAL'] = TRUE; 
     49  
     50 /* 
     51 |-------------------------------------------------------------------------- 
     52 | Enable/Disable FreakAuth light extensions 
     53 |-------------------------------------------------------------------------- 
     54 | 
     55 | If you need to extend the Core class (libraries/FreakAuth_light.php) or  
     56 | the FAL_validation.php class build your files according to the following 
     57 | specifications about file-names. You can place them either in  
     58 | system/libraries or in application/libraries 
     59 | 
     60 | - libraries/MyFAL.php 
     61 | - libraries/MyFALVal.php 
     62 |  
     63 | Following this convention, if $config['FAL_use_extensions'] = TRUE; 
     64 | the above files will be loaded in FAL_front.php, and also the 
     65 | freakauth_light_helper.php functions will be updated. 
     66 | ----------------- 
     67 | MyFAL.php EXAMPLE 
     68 | ----------------- 
     69 |<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); 
     70 | 
     71 |   class MyFAL extends Freakauth_light  
     72 |   { 
     73 |       // --------------------------------------------------------------------  
     74 |       // Class constructor 
     75 |       // not really needed but I wrote it anyway 
     76 |       function MyFAL() 
     77 |       { 
     78 |              parent::Freakauth_light(); 
     79 |       } 
     80 |        
     81 |       // --------------------------------------------------------------------  
     82 |       // Overwrites normal FAL logout 
     83 |       function logout() 
     84 |       { 
     85 |           log_message('debug', 'MyFAL logout working'); 
     86 |           
     87 |           exit('MyFAL logout working'); 
     88 |       } 
     89 |     } 
     90 | 
     91 */ 
     92 $config['FAL_use_extensions'] = FALSE; 
    4993  
    5094 /* 
  • FreakAuth/trunk/www/system/application/helpers/freakauth_light_helper.php

    r265 r276  
    1313 * @version     1.0.4 
    1414 */ 
    15   
     15// ------------------------------------------------------------------------ 
     16/** 
     17 * Cheks if we have extensions to the Freakauth_light class 
     18 * The class extending it should be called MyFAL and the file 
     19 * You can place them either in system/libraries or in application/libraries 
     20 *  
     21 * - libraries/MyFAL.php 
     22 */ 
     23function loadFalExtension() 
     24
     25    $obj =& get_instance(); 
     26    if ($obj->config->item('FAL_use_extensions')) 
     27    { 
     28        if (file_exists(APPPATH.'libraries/MyFAL'.EXT) OR file_exists(BASEPATH.'libraries/MyFAL'.EXT)) 
     29        { 
     30            //let's load the core library (i.e. FreakAuth_light.php) extension 
     31            $obj->load->library('MyFAL'); 
     32     
     33            $obj->freakauth_light = & new MyFAL(); 
     34            log_message('debug', 'MyFAL library loaded'); 
     35            log_message('debug', 'MyFAL class assigned to $this->CI->freakauth_light'); 
     36        } 
     37        else 
     38        { 
     39            log_message('debug', 'MyFAL class not found'); 
     40        } 
     41    } 
     42
    1643// ------------------------------------------------------------------------ 
    1744// 
     
    2249{ 
    2350    $obj =& get_instance(); 
     51    //loadFalExtension(); 
    2452    return $obj->freakauth_light->getUserName(); 
    2553} 
     
    4270{ 
    4371    $obj =& get_instance(); 
     72    loadFalExtension(); 
    4473    return $obj->freakauth_light->getUserProperty($prop); 
    4574} 
     
    6190{ 
    6291        $obj =& get_instance(); 
     92        loadFalExtension(); 
    6393    return $obj->freakauth_light->getUserPropertyFromId($id, $prop); 
    6494} 
     
    73103{ 
    74104    $obj =& get_instance(); 
     105    loadFalExtension(); 
    75106    return $obj->freakauth_light->isAdmin(); 
    76107} 
     
    85116{ 
    86117    $obj =& get_instance(); 
     118    loadFalExtension(); 
    87119    return $obj->freakauth_light->isValidUser(); 
    88120} 
     
    109141{ 
    110142    $obj =& get_instance(); 
     143    loadFalExtension(); 
    111144    return $obj->freakauth_light->belongsToGroup($group, $only); 
    112145} 
  • FreakAuth/trunk/www/system/application/libraries/FAL_front.php

    r266 r276  
    7575                } 
    7676        
     77                //let's check if we have core classes extensions, and if we have them 
     78                //let's load them 
     79        if ($this->CI->config->item('FAL_use_extensions')) 
     80        { 
     81            $this->_loadExtensions(); 
     82        } 
     83        else 
     84        { 
     85            log_message('debug', 'FAL not using extensions'); 
     86        } 
    7787        
    7888                $this->CI->fal_validation->set_error_delimiters($this->CI->config->item('FAL_error_delimiter_open'), $this->CI->config->item('FAL_error_delimiter_close')); 
    7989        
     90    } 
     91     
     92    // -------------------------------------------------------------------- 
     93    /** 
     94     * FAL extensions handler. 
     95     * It makes easier to load extensions to the classes in  
     96     * (libraries/FreakAuth_light.php) or the FAL_validation.php class build 
     97     *  your files according to the following specifications about file-names. 
     98     *  You can place them either in system/libraries or in application/libraries 
     99     *  
     100     * - libraries/MyFAL.php 
     101     * - libraries/MyFALVal.php 
     102     *  
     103     * Following this convention, if $config['FAL_use_extensions'] = TRUE; 
     104     * the above files will be loaded  
     105     */ 
     106    function _loadExtensions() 
     107    { 
     108   
     109        if (file_exists(APPPATH.'libraries/MyFAL'.EXT) OR file_exists(BASEPATH.'libraries/MyFAL'.EXT)) 
     110        { 
     111            //let's load the core library (i.e. FreakAuth_light.php) extension 
     112            $this->CI->load->library('MyFAL'); 
     113             
     114            $this->CI->freakauth_light = new MyFAL(); 
     115            log_message('debug', 'MyFAL library loaded'); 
     116            log_message('debug', 'MyFAL class assigned to $this->CI->freakauth_light'); 
     117        } 
     118        else 
     119        { 
     120            log_message('debug', 'MyFAL class not found'); 
     121        } 
     122 
     123        if (file_exists(APPPATH.'libraries/MyFALVal'.EXT) OR file_exists(BASEPATH.'libraries/MyFALVal'.EXT)) 
     124        { 
     125            //let's load the validation library (i.e. FAL_validation.php) extension 
     126            //and assign it to $this->CI->fal_validation 
     127            $this->CI->load->library('MyFALVal'); 
     128            $this->CI->fal_validation = new MyFALVal(); 
     129 
     130        } 
     131        else 
     132        { 
     133            log_message('debug', 'MyFALVal class not found'); 
     134        } 
    80135    } 
    81136