function normalize_driver_types()
 {
     // get the drivers configured
     \Config::load('auth', true);
     $drivers = \Config::get('auth.driver', array());
     is_array($drivers) or $drivers = array($drivers);
     $results = array();
     foreach ($drivers as $driver) {
         // determine the driver classname
         $class = \Inflector::get_namespace($driver) . 'Auth_Login_' . \Str::ucwords(\Inflector::denamespace($driver));
         // Auth's Simpleauth
         if ($class == 'Auth_Login_Simpleauth' or $class == 'Auth\\Auth_Login_Simpleauth') {
             $driver = 'Simpleauth';
         } elseif ($class == 'Auth_Login_Ormauth' or $class == 'Auth\\Auth_Login_Ormauth') {
             $driver = 'Ormauth';
         } elseif (class_exists($class)) {
             // Extended fromm Auth's Simpleauth
             if (get_parent_class($class) == 'Auth\\Auth_Login_Simpleauth') {
                 $driver = 'Simpleauth';
             } elseif (get_parent_class($class) == 'Auth\\Auth_Login_Ormauth') {
                 $driver = 'Ormauth';
             }
         }
         // store the normalized driver name
         in_array($driver, $results) or $results[] = $driver;
     }
     return $results;
 }
Exemplo n.º 2
0
 /**
  * This method gets called after the action is called.
  *
  * @param mixed $response Value returned from the action method.
  * 
  * @return Response $response
  */
 public function after($response)
 {
     // Return if passed a response.
     if ($response instanceof Response) {
         return parent::after($response);
     }
     if ($this->autorender) {
         try {
             $this->view->set_filename(Str::lower(str_replace('_', '/', Inflector::denamespace(str_replace('controller_', '', Str::lower($this->request->controller)))) . DS . str_replace('_', '/', $this->request->action)));
         } catch (FuelException $e) {
         }
     }
     // Inject view into the layout if the main request.
     if ($this->layout instanceof View) {
         if ($this->autorender) {
             try {
                 // Throws exception if there is no view template found.
                 $this->layout->content = $this->view->render();
             } catch (FuelException $e) {
             }
         }
         $this->layout->content_data = $this->view->get();
         $this->response->body($this->layout);
     } else {
         $this->response->body($this->view);
     }
     return parent::after($this->response);
 }
Exemplo n.º 3
0
 /**
  * Test for Inflector::denamespace()
  *
  * @test
  */
 public function test_denamespace()
 {
     $this->assertEquals(Inflector::denamespace('Fuel\\SomeClass'), 'SomeClass');
     $this->assertEquals(Inflector::denamespace('\\SomeClass'), 'SomeClass');
     $this->assertEquals(Inflector::denamespace('SomeClass'), 'SomeClass');
     $this->assertEquals(Inflector::denamespace('SomeClass\\'), 'SomeClass');
 }
Exemplo n.º 4
0
	/**
	 * Import config rules into $config property.
	 * Config file should be named as Class.
	 * 
	 * @access public
	 * @return void
	 */
	public static function _init()
	{
		self::$called_class = str_replace('Helper', '', \Inflector::denamespace(get_called_class()));
		
		if (self::$called_class != __CLASS__)
		{
			self::$called_classes[] = self::$called_class;
			static::$config = \Config::load(self::$called_class, true);
		}
	}
Exemplo n.º 5
0
 /**
  * Gets a new instance of gateway $class_name.
  *
  * @param Model_Gateway  $gateway    The gateway model to use for the driver.
  * @param Model_Customer $customer   The customer model to use for the driver.
  * @param string         $class_name The class name to call on the driver.
  *
  * @return Gateway_Model
  */
 public static function forge(Model_Gateway $gateway, Model_Customer $customer = null, $class_name)
 {
     $driver_name = str_replace('Gateway_', '', get_called_class());
     $driver_name = str_replace('_Driver', '', $driver_name);
     $class = 'Gateway_' . Str::ucwords(Inflector::denamespace($driver_name)) . '_' . Str::ucwords(Inflector::denamespace($class_name));
     if (!class_exists($class)) {
         throw new GatewayException('Call to undefined class ' . $class);
     }
     $driver = Gateway::instance($gateway, $customer);
     return new $class($driver);
 }
Exemplo n.º 6
0
 /**
  * Gets a new instance of gateway driver class.
  *
  * @param Model_Gateway  $gateway  The gateway model to use (for gateway auth and such).
  * @param Model_Customer $customer The customer model to use.
  *
  * @return Gateway_Driver|bool
  */
 public static function forge(Model_Gateway $gateway, Model_Customer $customer = null)
 {
     $driver_name = $gateway->processor;
     $class = 'Gateway_' . Str::ucwords(Inflector::denamespace($driver_name)) . '_Driver';
     if (!class_exists($class)) {
         return false;
     }
     $driver = new $class($gateway, $customer);
     static::$_instances[$driver_name] = $driver;
     is_null(static::$_instance) and static::$_instance = $driver;
     return $driver;
 }
Exemplo n.º 7
0
 public static function _init()
 {
     \Config::load('parser', true);
     // Get class name
     $class = \Inflector::denamespace(get_called_class());
     if ($class !== __CLASS__) {
         // Include necessary files
         foreach ((array) \Config::get('parser.' . $class . '.include', array()) as $include) {
             if (!array_key_exists($include, static::$loaded_files)) {
                 require $include;
                 static::$loaded_files[$include] = true;
             }
         }
     }
 }
Exemplo n.º 8
0
 public static function factory(array $config = array())
 {
     // default driver id to driver name when not given
     !array_key_exists('id', $config) && ($config['id'] = $config['driver']);
     $class = \Inflector::get_namespace($config['driver']) . 'Auth_Login_' . ucfirst(\Inflector::denamespace($config['driver']));
     $driver = new $class($config);
     static::$_instances[$driver->get_id()] = $driver;
     foreach ($driver->get_config('drivers', array()) as $type => $drivers) {
         foreach ($drivers as $d => $custom) {
             $custom = is_int($d) ? array('driver' => $custom) : array_merge($custom, array('driver' => $d));
             $class = 'Auth_' . ucfirst($type) . '_Driver';
             $class::factory($custom);
         }
     }
     return $driver;
 }
Exemplo n.º 9
0
 /**
  * Calls all observers for the current event
  *
  * @param  string
  */
 public function observe($event)
 {
     foreach ($this->observers() as $observer => $events) {
         if (empty($events) or in_array($event, $events)) {
             if (!class_exists($observer)) {
                 $observer_class = \Inflector::get_namespace($observer) . 'Observer_' . \Inflector::denamespace($observer);
                 if (!class_exists($observer_class)) {
                     throw new \UnexpectedValueException($observer);
                 }
                 // Add the observer with the full classname for next usage
                 unset(static::$_observers_cached[$observer]);
                 static::$_observers_cached[$observer_class] = $events;
                 $observer = $observer_class;
             }
             try {
                 call_user_func(array($observer, 'orm_notify'), $this, $event);
             } catch (\Exception $e) {
                 // Unfreeze before failing
                 $this->unfreeze();
                 throw $e;
             }
         }
     }
 }
Exemplo n.º 10
0
 /**
  * Sets relations of FuelPHP Models
  *
  * @param  $table array \Doctrine\DBAL\Schema\Table
  */
 private function set_fuel_relations(\Doctrine\DBAL\Schema\Table $table)
 {
     $table_name = $table->getName();
     $fuel_model_name = $this->get_fuel_model_name($table_name);
     if ($fuel_model_name === false) {
         return;
     }
     foreach ($fuel_model_name::relations() as $relation) {
         switch (\Inflector::denamespace(get_class($relation))) {
             case 'BelongsTo':
                 $model_from = $relation->model_from;
                 $model_to = $relation->model_to;
                 $this->fuel_relations[$table_name]['belongs_to'][] = array('key_from' => $relation->key_from[0], 'table_to' => $model_to::table(), 'key_to' => $relation->key_to[0]);
                 break;
             case 'HasOne':
                 $model_from = $relation->model_from;
                 $model_to = $relation->model_to;
                 $this->fuel_relations[$table_name]['has_one'][] = array('key_from' => $relation->key_from[0], 'table_to' => $model_to::table(), 'key_to' => $relation->key_to[0]);
                 break;
             case 'HasMany':
                 $model_from = $relation->model_from;
                 $model_to = $relation->model_to;
                 $this->fuel_relations[$table_name]['has_many'][] = array('is_many_many' => false, 'key_from' => $relation->key_from[0], 'table_to' => $model_to::table(), 'key_to' => $relation->key_to[0]);
                 break;
             case 'ManyMany':
                 $this->fuel_relations[$table_name]['has_many'][] = array('is_many_many' => true, 'key_from' => $relation->key_from[0], 'table_to' => $relation->table_through, 'key_to' => $relation->key_through_from[0]);
                 break;
             default:
                 break;
         }
     }
 }