/**
  * Constructs the container and set up default services and properties
  */
 public function __construct()
 {
     parent::__construct();
     //Shared services
     $this['twig'] = $this->share(function ($c) {
         $envOptions = array_merge(array('cache' => $c['twig.compilation_cache']), $c['twig.environment_options']);
         $twig = new Twig_Environment($c['twig.loader'], $envOptions);
         if (isset($envOptions['debug']) && $envOptions['debug']) {
             $twig->addExtension(new Twig_Extension_Debug());
         }
         return $twig;
     });
     $this['twig.loader'] = $this->share(function ($c) {
         return new $c['twig.loader_class']($c['twig.template_paths']);
     });
     //Dynamic props
     $this['twig.compilation_cache'] = BASE_PATH . '/twig-cache';
     $this['twig.template_paths'] = THEMES_PATH . '/' . SSViewer::current_theme() . '/twig';
     //Default config
     foreach (self::$config as $key => $value) {
         $this[$key] = $value;
     }
     //Extensions
     if (is_array(self::$extensions)) {
         foreach (self::$extensions as $value) {
             $this->extend($value[0], $value[1]);
         }
     }
     //Shared
     if (is_array(self::$shared)) {
         foreach (self::$shared as $value) {
             $this[$value[0]] = $this->share($value[1]);
         }
     }
 }
예제 #2
0
 /**
  * @param array         $config   The SlotMachine configuration data
  * @param Request|null  $request  The Request object
  */
 public function __construct(array $config = array(), Request $request = null)
 {
     parent::__construct();
     $this->config = $config;
     $this->request = !is_null($request) ? $request : Request::createFromGlobals();
     $this->initialize();
 }
예제 #3
0
 public function __construct(Application $app, array $values = array())
 {
     parent::__construct();
     $this->app = $app;
     $this['debug'] = false;
     $this['admin'] = false;
     $this['admin_content'] = '';
     $this['block_type_factory'] = $app->protect(function ($blockTypeData) {
         return BlockType::factory($blockTypeData);
     });
     $this['block_types'] = $this->share(function () {
         return array();
     });
     $this['twig_extensions'] = $this->share(function () {
         return array();
     });
     $this['snippet_queue'] = $this->share(function () {
         return new SnippetQueue();
     });
     $this['loader_class'] = 'NodePub\\Core\\Extension\\Loader';
     $app['loader'] = $app->share(function ($app) {
         return new $app['extension_loader_class']();
     });
     foreach ($values as $key => $value) {
         $this[$key] = $value;
     }
 }
예제 #4
0
 public function __construct()
 {
     parent::__construct();
     $this->initializeFilesystem();
     $this->initializeServices();
     $this->initializeSubscribers();
 }
예제 #5
0
 public function __construct($configDir)
 {
     parent::__construct();
     $this['configDir'] = $this->protect(function () use($configDir) {
         return $configDir;
     });
 }
예제 #6
0
 /**
  * Constructor.
  *
  * @param array $values
  */
 public function __construct(array $values = [])
 {
     parent::__construct($values);
     $this['app'] = $this;
     $this->register(new EventServiceProvider());
     $this->register(new RoutingServiceProvider());
     ApplicationTrait::setApplication($this);
 }
예제 #7
0
 /**
  * Instantiate the container.
  *
  * Objects and parameters can be passed as argument to the constructor.
  * 
  * @param ContainerInterface $container The root container of the application (if any)
  * @param array $values The parameters or objects.
  */
 public function __construct(ContainerInterface $container = null, array $values = array())
 {
     parent::__construct($values);
     if ($container) {
         $this->fallbackContainer = $container;
         $this->wrappedFallbackContainer = new FallbackContainerAdapter($container);
     }
 }
예제 #8
0
파일: Factory.php 프로젝트: cangit/beatrix
 public function __construct($blueprints = '')
 {
     parent::__construct();
     if (!is_array($blueprints)) {
         return;
     }
     $this->blueprints = array_merge_recursive($this->blueprints, $blueprints);
 }
예제 #9
0
 public function __construct()
 {
     parent::__construct();
     $this->initializeParameters();
     $this->initializeConfiguration();
     $this->initializeProfile();
     $this->initializeFinder();
     $this->initializeSourceFileSystem();
     $this->initializeVcs();
     $this->initializeServices();
 }
예제 #10
0
 public function __construct(array $values = array())
 {
     parent::__construct($values);
     $this['Request'] = $this->share(function () {
         return \Symfony\Component\HttpFoundation\Request::createFromGlobals();
     });
     $this['Response'] = function () {
         $response = new \Symfony\Component\HttpFoundation\Response();
         return $response;
     };
 }
예제 #11
0
 /**
  * Registers the autoloader and necessary components.
  *
  * @param string      $name    Name for this application.
  * @param string|null $version Version number for this application.
  */
 public function __construct($name, $version = null, array $values = array())
 {
     parent::__construct();
     $consoleConfig = array('console.name' => $name);
     if (null !== $version) {
         $consoleConfig['console.version'] = $version;
     }
     $this->register(new ConsoleServiceProvider(), $consoleConfig);
     foreach ($values as $key => $value) {
         $this[$key] = $value;
     }
 }
예제 #12
0
 /**
  * Constructs the object. You can inject a logger instance here, for
  * the lib to use.
  *
  * Also registers shutdown function and an exception handler to make sure
  * all errors that could occur are provided to the client in JSON format
  * with varying debug information.
  *
  * @param bool $debug
  */
 function __construct($debug = false)
 {
     parent::__construct();
     ob_start();
     self::$debug = $debug;
     $this['logger'] = function ($c) {
         $logger = new Logger('jsonrpc');
         $logger->pushHandler(new NullHandler());
         return $logger;
     };
     // register shutdown function so that we can report parse errors and such to the client.
     register_shutdown_function(array($this, 'handleShutdown'));
     set_error_handler(array($this, 'handleError'));
     set_exception_handler(array($this, 'handleException'));
 }
예제 #13
0
 function __construct()
 {
     parent::__construct();
     $this['config'] = function ($c) {
         return new Config(__DIR__ . "/../config.ini");
     };
     $this['db'] = function ($c) {
         $db = new \Services\MySQL\MySqlConnection($c->config->mysql->host, $c->config->mysql->username, $c->config->mysql->password, $c->config->mysql->db_name);
         $db->setTimeZone("+00:00");
         return $db;
     };
     $this['eb'] = function ($c) {
         return new \Services\Eventbrite\Eventbrite(array('app_key' => $c->config->eventbrite->appkey, 'user_key' => $c->config->eventbrite->userkey));
     };
     $this['mailchimp'] = function ($c) {
         return new \Services\Mailchimp\MCAPI($c->config->mailchimp->api_key);
     };
     $this['view'] = function ($c) {
         $loader = new Twig_Loader_Filesystem(realpath(__DIR__ . '/../../app/views'));
         $twig = new Twig_Environment($loader, array('cache' => realpath(__DIR__ . '/../../' . $c->config->view->cache_path), 'debug' => true));
         $twig->addFilter(new Twig_SimpleFilter('slugify', function ($string) {
             return strtolower(str_replace(' ', '-', $string));
         }));
         $twig->addFilter(new Twig_SimpleFilter('tourl', function ($string) {
             return rawurlencode(str_replace('\\n', ',', $string));
         }));
         $twig->addFilter(new Twig_SimpleFilter('timeago', function ($date) {
             return Carbon::instance($date)->diffForHumans();
         }));
         $twig->addGlobal('server', array('request_uri' => $_SERVER['REQUEST_URI']));
         $twig->addGlobal('layout', array('allevents' => $c->db->queryAllRows('(SELECT * FROM events WHERE end_time < NOW()) UNION (SELECT * FROM events WHERE end_time > NOW() ORDER BY end_time LIMIT 1) ORDER BY start_time DESC')));
         $twig->addExtension(new Twig_Extension_Debug());
         return $twig;
     };
     $this['auth'] = function ($c) {
         if (!session_id()) {
             session_start();
         }
         $host = $_SERVER['HTTP_HOST'];
         return new \Services\GoogleAuth\GoogleAuth($_SESSION, $c->config->google->client_id, $c->config->google->secret, array('canceldest' => 'http://edgeconf.com/', 'callback' => $c->config->google->callback));
     };
     $this['sentry'] = function ($c) {
         return new Raven_Client($c->config->sentry->dsn, array('tags' => array('php_version' => phpversion())));
     };
 }
예제 #14
0
 /**
  * @inheritDoc
  */
 public function __construct(array $values = array())
 {
     $this->defaultValues['params']['storage']['filesystem'] = __DIR__ . '/../../../var';
     $values['storage'] = $this->share(function ($c) {
         $factory = new Storage\Factory(array('filesystem' => function () use($c) {
             return new Storage\FileSystem($c['params']['storage']['filesystem'], new Finder());
         }, 'database' => function () use($c) {
             return new Storage\DoctrineDbal($c['params']['storage']['database']['dsn'], $c['params']['storage']['database']['table_prefix']);
         }));
         return $factory->create($c['params']['storage']['type']);
     });
     $values['rsa'] = function () {
         return new \phpseclib\Crypt\RSA();
     };
     $values['ssl'] = $this->share(function ($c) {
         return new Ssl\PhpSecLib($c->raw('rsa'));
     });
     $values['http-client'] = $this->share(function ($c) {
         return new Http\GuzzleClient(new \Guzzle\Http\Client(), $c->raw('rsa'), $c['storage']);
     });
     $values['certificate'] = $this->share(function ($c) {
         return new Certificate($c['storage'], $c['http-client'], $c['ssl']);
     });
     $values['account'] = $this->share(function ($c) {
         return new Account($c['storage'], $c['http-client'], $c['ssl']);
     });
     $values['ownership'] = function ($c) {
         return new Ownership($c['storage'], $c['http-client'], $c['ssl']);
     };
     $values['challenge-solver-http'] = $this->share(function ($c) {
         return new \Octopuce\Acme\ChallengeSolver\Http($c['params']['challenge']['config']);
     });
     /*
     $values['challenge-solver-dns'] = $this->share(function () {
         return new Octopuce\Acme\ChallengeSolver\Dns;
     });
     $values['challenge-solver-dvsni'] = $this->share(function () {
         return new Octopuce\Acme\ChallengeSolver\DvSni;
     });
     */
     // Override default values with provided config
     $values = array_replace_recursive($this->defaultValues, $values);
     parent::__construct($values);
 }
예제 #15
0
 /**
  * Constructor
  * @param array $config Configuration data
  */
 public function __construct(array $config = [])
 {
     parent::__construct();
     $this['config'] = $config;
     $this['request'] = function () {
         return Request::createFromGlobals();
     };
     $this['router'] = function () {
         return new \AltoRouter([], $this['request']->getBasePath());
     };
     $this['session'] = function () {
         $config = $this->config('session') ?: [];
         $storage = new NativeSessionStorage($config, new NativeSessionHandler());
         return new Session($storage);
     };
     $this['event'] = function () {
         return new EventEmitter();
     };
 }
예제 #16
0
 public function __construct()
 {
     parent::__construct();
     /* Symfony HttpFoundation Request object */
     // http://symfony.com/doc/current/components/http_foundation/introduction.html#accessing-request-data
     $this['request'] = $this->share(function () {
         Request::enableHttpMethodParameterOverride();
         return Request::createFromGlobals();
     });
     if (file_exists(APP_ROOT . '/app/config/beatrix/settings.php') === false) {
         exit("Application is not installed correctly. Error: Could not locate setting.php file.");
     }
     $defaultSettings = ['name' => 'Beatrix', 'cache.interface' => 'none', 'cache.routes' => false, 'cache' => false, 'env' => 'prod'];
     require APP_ROOT . '/app/config/beatrix/settings.php';
     $this->settings = array_merge($defaultSettings, $this->settings);
     $this->settings['factory'] = $this['cache']->file('BeatrixFactory', APP_ROOT . '/app/config/beatrix/factoryDefinitions.yml', 'yml', $this->settings['cache']);
     $this->settings['DIC'] = $this->settings['factory'];
     // BC, Old factory definitions used DIC.
     if (isset($this->settings['timezone'])) {
         date_default_timezone_set($this->settings['timezone']);
     }
     if ($this->setting('env') === 'prod') {
         if (file_exists(APP_ROOT . '/app/config/beatrix/prodAutoexecute.php')) {
             try {
                 require APP_ROOT . '/app/config/beatrix/prodAutoexecute.php';
             } catch (\Exception $e) {
                 $this['logger']->warning('Catchable error in /app/config/beatrix/prodAutoexecute.php');
             }
         }
     }
     if ($this->setting('env') === 'dev') {
         if (file_exists(APP_ROOT . '/app/config/beatrix/devAutoexecute.php')) {
             try {
                 require APP_ROOT . '/app/config/beatrix/devAutoexecute.php';
             } catch (\Exception $e) {
                 $this['logger']->warning('Catchable error in /app/config/beatrix/devAutoexecute.php');
             }
         }
     }
     error_reporting(E_ALL);
 }
예제 #17
0
 /**
  * Constructor.
  *
  * @param array $values Defaults to override
  */
 public function __construct(array $values = [])
 {
     parent::__construct();
     $this['debug'] = false;
     $this['app.catch_errors'] = true;
     $this['app.handler'] = $this->share(function ($app) {
         $handler = new Handler(null, null, ['iterate' => true]);
         $handler->handlers(array_map([$handler, 'handler'], $app['app.handlers']));
         return $handler;
     });
     $this['app.handlers'] = $this->share(function ($app) {
         return [new Middleware\ResponseMiddleware($app), new Middleware\RouterMiddleware($app)];
     });
     $this['app.context'] = $this->share(function ($app) {
         return new ContextProxy();
     });
     $this['app.routes'] = $this->share(function ($app) {
         return new Route();
     });
     foreach ($values as $key => $value) {
         $this[$key] = $value;
     }
 }
예제 #18
0
 public function __construct(array $values = array())
 {
     parent::__construct($values);
     $this->addRequestToContainer();
 }
예제 #19
0
 public function __construct(array $values = array())
 {
     parent::__construct(array_merge(array('debug' => false, 'charset' => 'UTF-8', 'locale' => 'en'), $values));
 }
예제 #20
0
 /**
  * Instantiate a new Application.
  *
  * Objects and parameters can be passed as argument to the constructor.
  *
  * @param array $values The parameters or objects.
  */
 public function __construct(array $values = array())
 {
     parent::__construct();
     $app = $this;
     $this['logger'] = null;
     $this['routes'] = $this->share(function () {
         return new RouteCollection();
     });
     $this['controllers'] = $this->share(function () use($app) {
         return $app['controllers_factory'];
     });
     $this['controllers_factory'] = function () use($app) {
         return new ControllerCollection($app['route_factory']);
     };
     $this['route_class'] = 'Silex\\Route';
     $this['route_factory'] = function () use($app) {
         return new $app['route_class']();
     };
     $this['exception_handler'] = $this->share(function () use($app) {
         return new ExceptionHandler($app['debug']);
     });
     $this['dispatcher_class'] = 'Symfony\\Component\\EventDispatcher\\EventDispatcher';
     $this['dispatcher'] = $this->share(function () use($app) {
         /*
          * @var EventDispatcherInterface
          */
         $dispatcher = new $app['dispatcher_class']();
         $urlMatcher = new LazyUrlMatcher(function () use($app) {
             return $app['url_matcher'];
         });
         $dispatcher->addSubscriber(new RouterListener($urlMatcher, $app['request_context'], $app['logger'], $app['request_stack']));
         $dispatcher->addSubscriber(new LocaleListener($app, $urlMatcher, $app['request_stack']));
         if (isset($app['exception_handler'])) {
             $dispatcher->addSubscriber($app['exception_handler']);
         }
         $dispatcher->addSubscriber(new ResponseListener($app['charset']));
         $dispatcher->addSubscriber(new MiddlewareListener($app));
         $dispatcher->addSubscriber(new ConverterListener($app['routes'], $app['callback_resolver']));
         $dispatcher->addSubscriber(new StringToResponseListener());
         return $dispatcher;
     });
     $this['callback_resolver'] = $this->share(function () use($app) {
         return new CallbackResolver($app);
     });
     $this['resolver'] = $this->share(function () use($app) {
         return new ControllerResolver($app, $app['logger']);
     });
     $this['kernel'] = $this->share(function () use($app) {
         return new HttpKernel($app['dispatcher'], $app['resolver'], $app['request_stack']);
     });
     $this['request_stack'] = $this->share(function () use($app) {
         if (class_exists('Symfony\\Component\\HttpFoundation\\RequestStack')) {
             return new RequestStack();
         }
     });
     $this['request_context'] = $this->share(function () use($app) {
         $context = new RequestContext();
         $context->setHttpPort($app['request.http_port']);
         $context->setHttpsPort($app['request.https_port']);
         return $context;
     });
     $this['url_matcher'] = $this->share(function () use($app) {
         return new RedirectableUrlMatcher($app['routes'], $app['request_context']);
     });
     $this['request_error'] = $this->protect(function () {
         throw new \RuntimeException('Accessed request service outside of request scope. Try moving that call to a before handler or controller.');
     });
     $this['request'] = $this['request_error'];
     $this['request.http_port'] = 80;
     $this['request.https_port'] = 443;
     $this['debug'] = false;
     $this['charset'] = 'UTF-8';
     $this['locale'] = 'en';
     foreach ($values as $key => $value) {
         $this[$key] = $value;
     }
 }
 public function __construct(array $values = array())
 {
     parent::__construct($values);
 }
예제 #22
0
 /**
  * Constructor.
  *
  * @param Container $container        The real container.
  * @param string[]  $serviceWhiteList A list of services that can be invoked.
  */
 public function __construct(Container $container, array $serviceWhiteList = [])
 {
     parent::__construct([]);
     $this->container = $container;
     $this->serviceWhiteList = $serviceWhiteList;
 }
예제 #23
0
파일: App.php 프로젝트: fobiaweb/slim
 /**
  * Constructor
  * @param  array $userSettings Associative array of application settings
  * @api
  */
 public function __construct(array $userSettings = array())
 {
     parent::__construct();
     // Settings
     $this['settings'] = function ($c) use($userSettings) {
         $config = new \Slim\Configuration(new \Slim\ConfigurationHandler());
         $config->setArray($userSettings);
         return $config;
     };
     // Environment
     $this['environment'] = function ($c) {
         return new \Slim\Environment($_SERVER);
     };
     // Request
     $this['request'] = function ($c) {
         $environment = $c['environment'];
         $headers = new \Slim\Http\Headers($environment);
         $cookies = new \Slim\Http\Cookies($headers);
         if ($c['settings']['cookies.encrypt'] === true) {
             $cookies->decrypt($c['crypt']);
         }
         return new \Slim\Http\Request($environment, $headers, $cookies);
     };
     // Response
     $this['response'] = function ($c) {
         $headers = new \Slim\Http\Headers();
         $cookies = new \Slim\Http\Cookies();
         $response = new \Slim\Http\Response($headers, $cookies);
         $response->setProtocolVersion('HTTP/' . $c['settings']['http.version']);
         return $response;
     };
     // Router
     $this['router'] = function ($c) {
         return new \Slim\Router();
     };
     // View
     $this['view'] = function ($c) {
         $view = $c['settings']['view'];
         if ($view instanceof \Slim\Interfaces\ViewInterface === false) {
             throw new \Exception('View class must be instance of \\Slim\\View');
         }
         return $view;
     };
     // Crypt
     $this['crypt'] = function ($c) {
         return new \Slim\Crypt($c['settings']['crypt.key'], $c['settings']['crypt.cipher'], $c['settings']['crypt.mode']);
     };
     // Session
     $this['session'] = function ($c) {
         $session = new \Slim\Session($c['settings']['session.handler']);
         $session->start();
         if ($c['settings']['session.encrypt'] === true) {
             $session->decrypt($c['crypt']);
         }
         return $session;
     };
     // Flash
     $this['flash'] = function ($c) {
         $flash = new \Slim\Flash($c['session'], $c['settings']['session.flash_key']);
         if ($c['settings']['view'] instanceof \Slim\Interfaces\ViewInterface) {
             $c['view']->set('flash', $flash);
         }
         return $flash;
     };
     // Mode
     $this['mode'] = function ($c) {
         $mode = $c['settings']['mode'];
         if (isset($_ENV['SLIM_MODE'])) {
             $mode = $_ENV['SLIM_MODE'];
         } else {
             $envMode = getenv('SLIM_MODE');
             if ($envMode !== false) {
                 $mode = $envMode;
             }
         }
         return $mode;
     };
     // Middleware stack
     $this['middleware'] = array($this);
 }
예제 #24
0
 public function __construct($appPath, $libPath, $env = '', $user = '', $sapi = '', $cache = false)
 {
     parent::__construct();
     $this->config = self::configure($this, $appPath, $libPath, $env, $user, $sapi ? $sapi : 'generic', $cache);
 }