public function load($helperName, $directory = null): bool
    {
        // First determine the name of the helper
        $helperName = strtolower(str_replace(array('_helper', '.php'), '', $helperName).'_helper');
        
        // Determine what directories should be checked
        $directories = (is_null($directory) ? $this->helperPaths : array($directory));

        // Check it is already loaded
        if (isset($this->helpers[$helperName]))
        {
            Logger::log("Helper '".$helperName."' is already loaded. Skipping");
            return false;
        }

        // First check if there is an 'extension' class
        $extendedHelper = Factory::getInstance()->config->get('main')->application_prefix . $helperName;
        $extendedHelperLoaded = false;
        foreach ($directories as $helperPath) 
        {
            $file = $helperPath . DS . $extendedHelper . '.php';
            if (file_exists($file))
            {
                $extendedHelperLoaded = true;
                $extendedHelperFile = $file;
            }
        }

        // If an extension is loaded there needs to be a base helper
        if ($extendedHelperLoaded)
        {
            $baseHelper = Core::$coreDir . DS . 'Helpers' . DS . $helperName.'.php';
            if (!file_exists($baseHelper))
            {
                throw new HelperException("Could not load helper. Base Helper not found while Extension loaded", 1);
            }

            // Fire the associated event
            $event = Events::fireEvent('helperLoadEvent', $helperName, $baseHelper, $extendedHelper, $extendedHelperFile);
            if ($event->isCancelled()) 
            {
                Logger::log("Not loading helper. Aborted by event");
                return false;
            }

            include_once($event->extendedHelperFile);
            include_once($event->helperFile);
            $this->helpers[$event->helperName] = true;
            Logger::log("Loading base helper '".$event->helperName."' and extended helper '".$event->extendedHelperName."'");
            return true;
        }

        // If no extension exists, try loading a regular helper
        foreach ($directories as $helperPath) 
        {
            $file = $helperPath . DS . $helperName . '.php';
            if (file_exists($file))
            {

                // Fire the associated event
                $event = Events::fireEvent('helperLoadEvent', $helperName, $file);
                if ($event->isCancelled()) 
                {
                    Logger::log("Not loading helper. Aborted by event");
                    return false;
                }

                include_once($event->helperFile);
                $this->helpers[$event->helperName] = true;
                Logger::log("Loading helper '".$event->helperName."'");
                return true;
            }
        }

        throw new HelperException("Could not load helper. Helper not found.", 1);
    }
public function load($helperName, $directory = null): bool
    {
        // First determine the name of the helper
        $helperName = strtolower(str_replace(array('_helper', '.php'), '', $helperName).'_helper');
        
        // Determine what directories should be checked
        $directories = (is_null($directory) ? $this->helperPaths : array($directory));

        // Check it is already loaded
        if (isset($this->helpers[$helperName]))
        {
            Logger::log("Helper '".$helperName."' is already loaded. Skipping");
            return false;
        }

        // First check if there is an 'extension' class
        $extendedHelper = Factory::getInstance()->config->get('main')->application_prefix . $helperName;
        $extendedHelperLoaded = false;
        foreach ($directories as $helperPath) 
        {
            $file = $helperPath . DS . $extendedHelper . '.php';
            if (file_exists($file))
            {
                $extendedHelperLoaded = true;
                $extendedHelperFile = $file;
            }
        }

        // If an extension is loaded there needs to be a base helper
        if ($extendedHelperLoaded)
        {
            $baseHelper = Core::$coreDir . DS . 'Helpers' . DS . $helperName.'.php';
            if (!file_exists($baseHelper))
            {
                throw new HelperException("Could not load helper. Base Helper not found while Extension loaded", 1);
            }

            // Fire the associated event
            $event = Events::fireEvent('helperLoadEvent', $helperName, $baseHelper, $extendedHelper, $extendedHelperFile);
            if ($event->isCancelled()) 
            {
                Logger::log("Not loading helper. Aborted by event");
                return false;
            }

            include_once($event->extendedHelperFile);
            include_once($event->helperFile);
            $this->helpers[$event->helperName] = true;
            Logger::log("Loading base helper '".$event->helperName."' and extended helper '".$event->extendedHelperName."'");
            return true;
        }

        // If no extension exists, try loading a regular helper
        foreach ($directories as $helperPath) 
        {
            $file = $helperPath . DS . $helperName . '.php';
            if (file_exists($file))
            {

                // Fire the associated event
                $event = Events::fireEvent('helperLoadEvent', $helperName, $file);
                if ($event->isCancelled()) 
                {
                    Logger::log("Not loading helper. Aborted by event");
                    return false;
                }

                include_once($event->helperFile);
                $this->helpers[$event->helperName] = true;
                Logger::log("Loading helper '".$event->helperName."'");
                return true;
            }
        }

        throw new HelperException("Could not load helper. Helper not found.", 1);
    }
public function load ( $ helperName , $ directory = null ) : bool { // First determine the name of the helper $ helperName = strtolower ( str_replace ( array ( '_helper' , '.php' ) , '' , $ helperName ) . '_helper' ) ; // Determine what directories should be checked $ directories = ( is_null ( $ directory ) ? $ this -> helperPaths : array ( $ directory ) ) ; // Check it is already loaded if ( isset ( $ this -> helpers [ $ helperName ] ) ) { Logger :: log ( "Helper '" . $ helperName . "' is already loaded. Skipping" ) ; return false ; } // First check if there is an 'extension' class $ extendedHelper = Factory :: getInstance ( ) -> config -> get ( 'main' ) -> application_prefix . $ helperName ; $ extendedHelperLoaded = false ; foreach ( $ directories as $ helperPath ) { $ file = $ helperPath . DS . $ extendedHelper . '.php' ; if ( file_exists ( $ file ) ) { $ extendedHelperLoaded = true ; $ extendedHelperFile = $ file ; } } // If an extension is loaded there needs to be a base helper if ( $ extendedHelperLoaded ) { $ baseHelper = Core :: $ coreDir . DS . 'Helpers' . DS . $ helperName . '.php' ; if ( ! file_exists ( $ baseHelper ) ) { throw new HelperException ( "Could not load helper. Base Helper not found while Extension loaded" , 1 ) ; } // Fire the associated event $ event = Events :: fireEvent ( 'helperLoadEvent' , $ helperName , $ baseHelper , $ extendedHelper , $ extendedHelperFile ) ; if ( $ event -> isCancelled ( ) ) { Logger :: log ( "Not loading helper. Aborted by event" ) ; return false ; } include_once ( $ event -> extendedHelperFile ) ; include_once ( $ event -> helperFile ) ; $ this -> helpers [ $ event -> helperName ] = true ; Logger :: log ( "Loading base helper '" . $ event -> helperName . "' and extended helper '" . $ event -> extendedHelperName . "'" ) ; return true ; } // If no extension exists, try loading a regular helper foreach ( $ directories as $ helperPath ) { $ file = $ helperPath . DS . $ helperName . '.php' ; if ( file_exists ( $ file ) ) { // Fire the associated event $ event = Events :: fireEvent ( 'helperLoadEvent' , $ helperName , $ file ) ; if ( $ event -> isCancelled ( ) ) { Logger :: log ( "Not loading helper. Aborted by event" ) ; return false ; } include_once ( $ event -> helperFile ) ; $ this -> helpers [ $ event -> helperName ] = true ; Logger :: log ( "Loading helper '" . $ event -> helperName . "'" ) ; return true ; } } throw new HelperException ( "Could not load helper. Helper not found." , 1 ) ; }
Load a helper.

Supply the name and the helper will be loaded from the supplied directory,
or from one of the helperPaths (which you can add).

@param string        $helperName Name of the helper
@param string|null   $directory  Directory to load the helper from, will ignore $helperPaths
@return bool                     Whether the helper was succesfully loaded (true if yes)
Load a helper .