Pubwich::loadService PHP Method

loadService() public static method

Load a service file
public static loadService ( string $service, array $config ) : Service
$service string The service name
$config array The parameters
return Service
    public static function loadService($service, $config)
    {
        PubwichLog::log(1, sprintf(Pubwich::_('Loading %s service'), $service));
        $file_included = self::requireServiceFile($service);
        if (!$file_included) {
            throw new PubwichError(sprintf(Pubwich::_('You told Pubwich to use the %s service, but the file <code>%s</code> couldn’t be found.'), $service, $service . '.php'));
        }
        $classname = $config['method'] ? $config['method'] : $service;
        if (!class_exists($classname)) {
            throw new PubwichError(sprintf(Pubwich::_('The class %s doesn\'t exist. Check your configuration file for inexistent services or methods.'), $classname));
        }
        return new $classname($config);
    }

Usage Example

Example #1
0
 /**
  * Set the $classes array
  *
  * @return void
  */
 public static function setClasses()
 {
     require 'Services/Service.php';
     $columnCounter = 0;
     foreach (self::getServices() as $column) {
         $columnCounter++;
         self::$columns[$columnCounter] = array();
         foreach ($column as $service) {
             list($name, $variable, $config) = $service;
             $service_instance = strtolower($name . '_' . $variable);
             ${$service_instance} = Pubwich::loadService($name, $config);
             ${$service_instance}->setVariable($variable);
             self::$classes[] = ${$service_instance};
             self::$columns[$columnCounter][] =& ${$service_instance};
         }
     }
 }
All Usage Examples Of Pubwich::loadService