Exemplo n.º 1
0
 /**
  * Create the given shell name, and set the plugin property
  *
  * @param string $className The class name to instanciate
  * @param string $shortName The plugin-prefixed shell name
  * @return \Cake\Console\Shell A shell instance.
  */
 protected function _createShell($className, $shortName)
 {
     list($plugin) = pluginSplit($shortName);
     $instance = PipingBag::get($className);
     $instance->plugin = trim($plugin, '.');
     return $instance;
 }
 /**
  * Get controller to use, either plugin controller or application controller
  *
  * @param \Cake\Network\Request $request Request object
  * @param \Cake\Network\Response $response Response for the controller.
  * @return mixed name of controller if not loaded, or object if loaded
  */
 protected function _getController($request, $response)
 {
     $pluginPath = $controller = null;
     $namespace = 'Controller';
     if (!empty($request->params['plugin'])) {
         $pluginPath = $request->params['plugin'] . '.';
     }
     if ($pluginPath) {
         return parent::_getController($request, $response);
     }
     if (!empty($request->params['controller'])) {
         $controller = $request->params['controller'];
     }
     if (!empty($request->params['prefix'])) {
         $namespace .= '/' . Inflector::camelize($request->params['prefix']);
     }
     $className = false;
     if ($pluginPath . $controller) {
         $className = App::classname($pluginPath . $controller, $namespace, 'Controller');
     }
     if (!$className) {
         return false;
     }
     $instance = PipingBag::get($className);
     if (method_exists($instance, 'viewBuilder')) {
         $instance->viewBuilder();
     } else {
         $instance->viewPath = null;
     }
     $instance->name = $controller;
     $instance->setRequest($request);
     $instance->response = $response;
     return $instance;
 }
Exemplo n.º 3
0
/**
 * @return LoopInterface
 */
function loopResolver()
{
    if (Configure::check('WyriHaximus.Ratchet.loop') && Configure::read('WyriHaximus.Ratchet.loop') instanceof LoopInterface) {
        return Configure::read('WyriHaximus.Ratchet.loop');
    }
    if (class_exists('PipingBag\\Di\\PipingBag') && Configure::check('WyriHaximus.Ratchet.pipingbag.loop')) {
        return PipingBag::get(Configure::read('WyriHaximus.Ratchet.pipingbag.loop'));
    }
    return Factory::create();
}
Exemplo n.º 4
0
 /**
  * Intercepts any method and injects instances of the missing arguments
  * when they are type hinted
  */
 public function invoke(MethodInvocation $invocation)
 {
     $object = $invocation->getThis();
     $parameters = $invocation->getMethod()->getParameters();
     $arguments = $invocation->getArguments()->getArrayCopy();
     $assisted = [];
     foreach ($parameters as $k => $p) {
         $hint = $p->getClass();
         if ($hint) {
             $assisted[$k] = PipingBag::get($hint->getName());
             continue;
         }
         if (isset($arguments[$k])) {
             $assisted[$k] = array_shift($arguments);
             continue;
         }
         $assisted[$k] = $p->getDefaultValue();
     }
     $invocation->getArguments()->exchangeArray($assisted);
     return $invocation->proceed();
 }
Exemplo n.º 5
0
<?php

use Cake\Core\Configure;
use Cake\Cache\Cache;
use PipingBag\Di\PipingBag;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Annotations\AnnotationReader;
$config = Configure::consume('PipingBag');
$modules = !empty($config['modules']) ? $config['modules'] : [];
$cache = isset($config['cacheConfig']) ? $config['cacheConfig'] : 'default';
AnnotationReader::addGlobalIgnoredName('triggers');
AnnotationRegistry::registerFile(dirname(__DIR__) . '/src/Annotation/Assisted.php');
$instance = Cache::read('pipingbag.instance', $cache);
if (!$instance) {
    $instance = PipingBag::create($modules);
}
PipingBag::container($instance);
register_shutdown_function(function () use($instance, $cache) {
    Cache::write('pipingbag.instance', $instance, $cache);
});