stripPlugin() public static method

Removes the plugin name from the base URL.
public static stripPlugin ( string $base, string $plugin = null ) : string
$base string Base URL
$plugin string Plugin name
return string base URL with plugin name removed if present
 /**
  * Load components used by this component.
  *
  * @param array $loaded Components already loaded (indexed by component name)
  * @param array $components Components to load
  * @return array Components loaded
  * @access protected
  */
 function &_loadComponents(&$loaded, $components)
 {
     $components[] = 'Session';
     foreach ($components as $component) {
         $parts = preg_split('/\\/|\\./', $component);
         if (count($parts) === 1) {
             $plugin = $this->controller->plugin;
         } else {
             $plugin = Inflector::underscore($parts['0']);
             $component = $parts[count($parts) - 1];
         }
         $componentCn = $component . 'Component';
         if (in_array($component, array_keys($loaded)) !== true) {
             if (!class_exists($componentCn)) {
                 if (is_null($plugin) || !loadPluginComponent($plugin, $component)) {
                     if (!loadComponent($component)) {
                         $this->cakeError('missingComponentFile', array(array('className' => $this->controller->name, 'component' => $component, 'file' => Inflector::underscore($component) . '.php', 'base' => $this->controller->base)));
                         exit;
                     }
                 }
                 if (!class_exists($componentCn)) {
                     $this->cakeError('missingComponentClass', array(array('className' => $this->controller->name, 'component' => $component, 'file' => Inflector::underscore($component) . '.php', 'base' => $this->controller->base)));
                     exit;
                 }
             }
             if ($componentCn == 'SessionComponent') {
                 $param = Router::stripPlugin($this->controller->base, $this->controller->plugin) . '/';
             } else {
                 $param = null;
             }
             $this->controller->{$component} =& new $componentCn($param);
             $loaded[$component] =& $this->controller->{$component};
             if (isset($this->controller->{$component}->components) && is_array($this->controller->{$component}->components)) {
                 $loaded =& $this->_loadComponents($loaded, $this->controller->{$component}->components);
             }
         }
     }
     return $loaded;
 }
Beispiel #2
0
 /**
  * testStripPlugin
  *
  * @return void
  * @access public
  */
 function testStripPlugin()
 {
     $pluginName = 'forums';
     $url = 'example.com/' . $pluginName . '/';
     $expected = 'example.com';
     $this->assertEqual(Router::stripPlugin($url, $pluginName), $expected);
     $this->assertEqual(Router::stripPlugin($url), $url);
     $this->assertEqual(Router::stripPlugin($url, null), $url);
 }
Beispiel #3
0
 /**
  * testStripPlugin
  *
  * @return void
  */
 public function testStripPlugin()
 {
     $pluginName = 'forums';
     $url = 'example.com/' . $pluginName . '/';
     $expected = 'example.com';
     $this->assertEquals($expected, Router::stripPlugin($url, $pluginName));
     $this->assertEquals(Router::stripPlugin($url), $url);
     $this->assertEquals(Router::stripPlugin($url, NULL), $url);
 }