Example #1
0
 /**
  * App constructor.
  */
 public function __construct()
 {
     parent::__construct();
     $this->match('/', function () {
         return '/';
     });
     /**
      * process messages
      */
     $this->match('update', function () {
         $telegram = new Client(BOT_TOKEN);
         $handler = new Handler($telegram);
         return $handler->handle();
     });
     /**
      * update hook settings/api
      */
     $this->match('hook', function () {
         $telegram = new Api(BOT_TOKEN);
         $telegram->removeWebhook();
         if (USE_WEBHOOK) {
             $telegram->setWebhook(WEBHOOK, '../server-setup/files/cert/nginx.crt');
             return 'hook set';
         }
         return 'hook-removed';
     });
 }
Example #2
0
 /**
  * @param array       $basePath
  * @param Environment $environment
  */
 public function __construct($basePath, Environment $environment)
 {
     parent::__construct();
     $this['path'] = $basePath;
     $this['env'] = $environment;
     $this->bindPathsInApplicationContainer();
     $this->bindConfiguration();
     // Routes...
     $this->register(new RouteServiceProvider());
     // Services...
     $this->register(new SessionServiceProvider());
     $this->register(new FormServiceProvider());
     $this->register(new UrlGeneratorServiceProvider());
     $this->register(new ControllerResolverServiceProvider());
     $this->register(new ServiceControllerServiceProvider());
     $this->register(new DatabaseServiceProvider());
     $this->register(new ValidatorServiceProvider());
     $this->register(new TranslationServiceProvider());
     $this->register(new SwiftmailerServiceProvider(), ['swiftmailer.options' => ['host' => $this->config('mail.host'), 'port' => $this->config('mail.port'), 'username' => $this->config('mail.username'), 'password' => $this->config('mail.password'), 'encryption' => $this->config('mail.encryption'), 'auth_mode' => $this->config('mail.auth_mode')]]);
     $this->register(new SentryServiceProvider());
     $this->register(new TwigServiceProvider());
     $this->register(new HtmlPurifierServiceProvider());
     $this->register(new SpotServiceProvider());
     $this->register(new ImageProcessorProvider());
     // Application Services...
     $this->register(new ApplicationServiceProvider());
 }
Example #3
0
 /**
  * @param array $values
  */
 public function __construct(array $values = array())
 {
     $values['bolt_version'] = '2.2.10';
     $values['bolt_name'] = '';
     $values['bolt_released'] = true;
     // `true` for stable releases, `false` for alpha, beta and RC.
     /** @internal Parameter to track a deprecated PHP version */
     $values['deprecated.php'] = version_compare(PHP_VERSION, '5.4.0', '<');
     parent::__construct($values);
     $this->register(new PathServiceProvider());
     // Initialize the config. Note that we do this here, on 'construct'.
     // All other initialisation is triggered from bootstrap.php
     // Warning!
     // One of a valid ResourceManager ['resources'] or ClassLoader ['classloader']
     // must be defined for working properly
     if (!isset($this['resources'])) {
         $this['resources'] = new Configuration\ResourceManager($this);
         $this['resources']->compat();
     } else {
         $this['classloader'] = $this['resources']->getClassLoader();
     }
     $this['resources']->setApp($this);
     $this->initConfig();
     $this->initSession();
     $this['resources']->initialize();
     $this['debug'] = $this['config']->get('general/debug', false);
     $this['debugbar'] = false;
     // Initialize the 'editlink' and 'edittitle'.
     $this['editlink'] = '';
     $this['edittitle'] = '';
     // Initialise the JavaScipt data gateway
     $this['jsdata'] = array();
 }
 /**
  * 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($values);
     $this['debug'] = true;
     $this->get('/', function () {
         return 'Welcome at home';
     });
     $this->get('/welcome/{name}', function ($name) {
         return sprintf('Welcome %s at home', $name);
     });
     $this->get('/dirs', 'Cpyree\\Controller\\DirectoryController::getDirectories');
     $this->get('/dir-content', 'Cpyree\\Controller\\DirectoryController::getContentDir');
     $this->get('/dir-genre', 'Cpyree\\Controller\\DirectoryController::getGenreDir');
     $this->get('/set-matadata', 'Cpyree\\Controller\\DirectoryController::setMetadata');
     $this->get('/move', 'Cpyree\\Controller\\DirectoryController::move');
     $this->get('/delete', 'Cpyree\\Controller\\DirectoryController::delete');
     //Security issue, disalow stream on all
     $this->get('/stream', function (Request $request) {
         if ($request->query->has('file')) {
             $stream = new Streamer();
             return $stream->start($request->query->get('file'));
         }
         die;
     });
 }
Example #5
0
 public function __construct(array $values = array())
 {
     $values['bolt_version'] = '2.0.0';
     $values['bolt_name'] = 'almost beta';
     parent::__construct($values);
     // Initialize the config. Note that we do this here, on 'construct'.
     // All other initialisation is triggered from bootstrap.php
     // Warning!
     // One of a valid ResourceManager ['resources'] or ClassLoader ['classloader']
     // must be defined for working properly
     if (!isset($this['resources'])) {
         $this['resources'] = new Configuration\ResourceManager($this['classloader']);
         $this['resources']->compat();
     } else {
         $this['classloader'] = $this['resources']->getClassLoader();
     }
     $this['resources']->setApp($this);
     $this->initConfig();
     $this['resources']->initialize();
     $this['debug'] = $this['config']->get('general/debug', false);
     $this['debugbar'] = false;
     // Initialize the 'editlink' and 'edittitle'..
     $this['editlink'] = '';
     $this['edittitle'] = '';
 }
Example #6
0
 public function __construct($values = array())
 {
     parent::__construct();
     static::$app = $this;
     foreach ($values as $key => $value) {
         $this[$key] = $value;
     }
     Facade::setFacadeApplication($this);
     // register the configserviceprovider so we can access the config
     $this->register(new ConfigServiceProvider());
     // grab the providers from the config and load them
     $providers = $this['config']->get('app/providers');
     foreach ($providers as $provider) {
         $this->register(new $provider());
     }
     // set the locale (https://github.com/silexphp/Silex/issues/983)
     $locale = $values['locale'];
     if ($this['translator']) {
         $this['translator']->setlocale($locale);
     }
     // register fieldtypes from config
     $fieldTypesConfig = $this['config']->get('fieldtypes');
     if ($fieldTypesConfig) {
         $this['fieldtypes'] = $this['fieldtypes.factory']->fromConfig($fieldTypesConfig);
     }
     // register contenttypes from config
     $contentTypeConfig = $this['config']->get('contenttypes');
     if ($contentTypeConfig) {
         $this['contenttypes'] = $this['contenttypes.factory']->fromConfig($contentTypeConfig);
     }
 }
Example #7
0
 public function __construct(array $values = [])
 {
     parent::__construct($values);
     $this->registerProviders($this);
     $this->registerServices($this);
     $this->registerRoutes($this);
 }
 public function __construct(array $values = [])
 {
     parent::__construct($values);
     $this['serializer'] = SerializerBuilder::create()->build();
     BreweryBuilder::mountProviderIntoApplication($this->baseRouteApi, $this);
     BeerBuilder::mountProviderIntoApplication($this->baseRouteApi, $this);
 }
Example #9
0
 public function __construct($rootDir, $debug = true, array $values = [])
 {
     parent::__construct(['root_dir' => $rootDir, 'debug' => $debug] + $values);
     $this->register(new ExceptionServiceProvider());
     $this->register(new RoutingServiceProvider());
     $this->register(new TackerServiceProvider());
 }
 public function __construct(array $values = array())
 {
     parent::__construct($values);
     $this['config'] = $this->share(function ($this) {
         return new ConfigService($this);
     });
 }
Example #11
0
 public function __construct(array $values = [])
 {
     parent::__construct($values);
     $this->register(new Provider\ServiceControllerServiceProvider());
     $this->setupServices();
     $this->setupRouting();
 }
 public function __construct(array $config = array())
 {
     parent::__construct();
     $this->values = array_merge($this->values, $config);
     $this->register(new TwigServiceProvider(), array('twig.path' => __DIR__ . '/../../app/views'));
     $this->register(new ServiceControllerServiceProvider());
 }
Example #13
0
 /**
  * @constructor
  *
  * @param EnvironmentInterface $environment
  * @param Injector             $injector
  * @param array                $configuration
  */
 public function __construct(EnvironmentInterface $environment, Injector $injector, array $configuration)
 {
     $this->environment = $environment;
     $this->injector = $injector;
     $this->configuration = $configuration;
     parent::__construct([]);
 }
 public function __construct(array $values = [])
 {
     $this->defaultScope = self::SCOPE_PUBLIC;
     parent::__construct($values);
     $this->defaultScope = self::SCOPE_PRIVATE;
     $this->currentScope = self::SCOPE_PUBLIC;
 }
Example #15
0
 /**
  * @param array       $basePath
  * @param Environment $environment
  */
 public function __construct($basePath, Environment $environment)
 {
     parent::__construct();
     $this['path'] = $basePath;
     $this['env'] = $environment;
     $this->bindPathsInApplicationContainer();
     $this->bindConfiguration();
     // Register Gateways...
     $this->register(new WebGatewayProvider());
     $this->register(new ApiGatewayProvider());
     $this->register(new OAuthGatewayProvider());
     // Services...
     $this->register(new SessionServiceProvider());
     $this->register(new FormServiceProvider());
     $this->register(new UrlGeneratorServiceProvider());
     $this->register(new ControllerResolverServiceProvider());
     $this->register(new DatabaseServiceProvider());
     $this->register(new ValidatorServiceProvider());
     $this->register(new TranslationServiceProvider());
     $this->register(new MonologServiceProvider(), ['monolog.logfile' => $this->config('log.path') ?: "{$basePath}/log/app.log", 'monolog.name' => 'opencfp', 'monlog.level' => strtoupper($this->config('log.level') ?: 'debug')]);
     $this->register(new SwiftmailerServiceProvider(), ['swiftmailer.options' => ['host' => $this->config('mail.host'), 'port' => $this->config('mail.port'), 'username' => $this->config('mail.username'), 'password' => $this->config('mail.password'), 'encryption' => $this->config('mail.encryption'), 'auth_mode' => $this->config('mail.auth_mode')]]);
     $this->register(new SentryServiceProvider());
     $this->register(new TwigServiceProvider());
     $this->register(new HtmlPurifierServiceProvider());
     $this->register(new SpotServiceProvider());
     $this->register(new ImageProcessorProvider());
     $this->register(new ResetEmailerServiceProvider());
     // Application Services...
     $this->register(new ApplicationServiceProvider());
     $this->registerGlobalErrorHandler($this);
     if ($timezone = $this->config('application.date_timezone')) {
         date_default_timezone_set($timezone);
     }
 }
Example #16
0
 /**
  * Instantiate a new MainApp, calls parent Silex\Application constructor and passes array of Objects or Parameters
  * @param array $values objects and parameters to pass
  */
 function __construct(array $values = array())
 {
     parent::__construct($values);
     $this->registerProviders();
     $this->loadConfig();
     $this->mountControllers();
 }
Example #17
0
 public function __construct()
 {
     parent::__construct();
     $this['controllers'] = $this->share(function () {
         return new ControllerCollection();
     });
 }
Example #18
0
 public function __construct($values = array())
 {
     parent::__construct();
     // paths relative to index.php
     $this['theme'] = 'theme';
     $this['content'] = 'content';
     $this['template.index'] = 'index.twig';
     $this['template.pjax'] = null;
     $this['markdown.class'] = 'Michelf\\MarkdownExtra';
     $this->register(new TwigServiceProvider(), array('twig.path' => $this['theme']));
     $this->register(new CacheServiceProvider());
     $this['page'] = function ($app) {
         return new Page($app);
     };
     $pageConverter = function ($urlPath) {
         /** @var Page $page */
         $page = $this['page'];
         $page->setPath($urlPath);
         return $page;
     };
     $this->get('{page}', array($this, 'getResponse'))->assert('page', '.*')->convert('page', $pageConverter);
     $this->error(array($this, 'handleError'));
     foreach ($values as $key => $value) {
         $this[$key] = $value;
     }
 }
Example #19
0
 /**
  * @param array $values
  */
 public function __construct(array $values = array())
 {
     $app = parent::__construct($values);
     $this->loadProviders();
     $this->loadRoutes();
     return $app;
 }
Example #20
0
 public function __construct(array $values = array())
 {
     parent::__construct($values);
     $this->register(new ConfigurationServiceProvider());
     $this->register(new ServiceControllerServiceProvider());
     $this->register(new PropelServiceProvider());
 }
 public function __construct(array $values = array())
 {
     parent::__construct($values);
     $this->registerProviders();
     $this->registerServices();
     $this->registerControllers();
 }
Example #22
0
 /**
  *   mixed $options either an array or yaml valid ressource
  */
 public function __construct($options)
 {
     parent::__construct();
     $this->options = $options;
     // if options is a yaml file, read it
     if (!is_array($options) && false !== strpos($options, '.yml')) {
         $this->readYamlConfig($options);
     }
     // tweak $options and register SilexCMS twig path
     $this->registerTwigService();
     $this->register(new DoctrineServiceProvider(), $this->options);
     $this->register(new TranslationServiceProvider(), $this->options);
     $this->register(new SessionServiceProvider(), $this->options);
     $this->register(new FormServiceProvider(), $this->options);
     $this->register(new ValidatorServiceProvider(), $this->options);
     $this->register(new UrlGeneratorServiceProvider(), $this->options);
     $this->register(new TemplateLoader('silexcms.template.loader'));
     // security
     if (isset($options['silexcms.security'])) {
         $this->registerSecurityService();
     }
     // caching strategy
     if (isset($this->options['silexcms.cache'])) {
         $this->registerCacheService();
     }
     // handle errors and exceptions in debug mode
     $this->registerErrorHandlers();
     // registering console and console commands
     $this->registerConsoleService();
     // registered sets container
     $this['silexcms.sets'] = array();
 }
 /**
  * @param array $values
  */
 public function __construct(array $values = [])
 {
     parent::__construct($values);
     $this->register(new DoctrineServiceProvider(), ['db.options' => ['dbname' => 'events', 'driver' => 'pdo_sqlite', 'path' => getenv('HOME') . '/.events.db']]);
     $eventTable = new EventTable($this['db']);
     $eventTable->create();
 }
Example #24
0
 public function __construct()
 {
     // super()
     parent::__construct();
     // Load configuration
     try {
         $this->register(new ConfigServiceProvider(__DIR__ . '/../app/settings.yml', array('base_dir' => realpath(__DIR__ . '/../')), new YamlConfigDriver(), 'config'));
     } catch (\InvalidArgumentException $e) {
         throw new \Exception("Configuration file app/settings.yml is not available and/or readable.");
     }
     $this['debug'] = $this['config']['debug'];
     $this->initProviders();
     // Debug providers
     if ($this['debug'] === true) {
         $this->register(new WhoopsServiceProvider());
         $this->register(new \Sorien\Provider\PimpleDumpProvider());
     }
     // Controllers
     $this->mount("/", new Provider\ControllerProvider());
     $this->mount("/v1", new Provider\ApiProvider());
     // Error handler
     $this->error(function (\Exception $e, $code) {
         switch ($code) {
             case 404:
                 $message = 'The requested page could not be found.';
                 break;
             default:
                 $message = $e->getMessage();
         }
         return $this['twig']->render('error.twig', array('message' => $message));
     });
 }
Example #25
0
 function __construct()
 {
     parent::__construct();
     $this['debug'] = true;
     $this->registerProviders();
     $this->mountControllers();
 }
Example #26
0
 public function __construct(array $values = array())
 {
     parent::__construct($values);
     $app = $this;
     $app->register(new UrlGeneratorServiceProvider());
     $app->register(new SessionServiceProvider());
     if (true === $app['debug']) {
         $app->register(new WhoopsServiceProvider());
     }
     $app['session.storage.handler'] = $app->share(function ($app) {
         $memcache = new \Memcache();
         $memcache->connect('localhost', 11211);
         return new MemcacheSessionHandler($memcache);
     });
     $app['facebook'] = $app->share(function () use($app, $values) {
         return new \Facebook(['appId' => $values['facebook.app_id'], 'secret' => $values['facebook.secret'], 'allowSignedRequest' => false]);
     });
     $app['user'] = function () use($app) {
         return $app['session']->get('user');
     };
     $app->before(function ($request) use($app) {
         $user = $app['user'];
         if (null === $user) {
             $facebook = $app['facebook'];
             $result = $facebook->api(array('method' => 'fql.query', 'query' => 'SELECT uid, name, pic_square, profile_url FROM user WHERE uid = me()'));
             if (!empty($result)) {
                 $app['session']->set('user', $result[0]);
                 return;
             }
             return $app->render('login.phtml', ['loginUrl' => $facebook->getLoginUrl()]);
         }
     });
 }
 public function __construct()
 {
     parent::__construct();
     $app = $this;
     $this->register(new TwigServiceProvider());
     $this['puli.factory'] = $this->share(function () {
         $factoryClass = PULI_FACTORY_CLASS;
         return new $factoryClass();
     });
     $this['puli.repository'] = $this->share(function (Application $app) {
         return $app['puli.factory']->createRepository();
     });
     $this['puli.discovery'] = $this->share(function (Application $app) {
         return $app['puli.factory']->createDiscovery($app['puli.repository']);
     });
     $this['puli.asset_url_generator'] = $this->share(function (Application $app) {
         return $app['puli.factory']->createUrlGenerator($app['puli.discovery']);
     });
     /** @var Closure $twig */
     $twig = $this->raw('twig');
     $this['twig.options'] = array('cache' => realpath(__DIR__ . '/..') . '/var/cache/twig');
     $this['twig.loader'] = $this->share(function (Application $app) {
         return new PuliTemplateLoader($app['puli.repository']);
     });
     $this['twig'] = $this->share(function (Application $app) use($twig) {
         $twig = $twig($app);
         /** @var Twig_Environment $twig */
         $twig->addExtension(new PuliExtension($app['puli.repository'], $app['puli.asset_url_generator']));
         return $twig;
     });
     $this->get('/', function () use($app) {
         return $app['twig']->render('/app/views/index.html.twig');
     });
 }
Example #28
0
 public function __construct()
 {
     parent::__construct();
     $this->registerBundles();
     $this->configure();
     $this->mountRoutes();
 }
Example #29
0
 /**
  * Constructor initialize services.
  *
  * @param Config $config
  * @param string $root   Base path of the application files (views, cache)
  */
 public function __construct(Config $config, $root = null)
 {
     parent::__construct();
     $app = $this;
     $root = realpath($root);
     $this['debug'] = $config->get('app', 'debug');
     $this['filetypes'] = $config->getSection('filetypes');
     $this['cache.archives'] = $root . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'archives';
     // Register services
     $this->register(new TwigServiceProvider(), array('twig.path' => $root . DIRECTORY_SEPARATOR . 'views', 'twig.options' => array('cache' => $root . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'views')));
     $this->register(new GitServiceProvider(), array('git.client' => $config->get('git', 'client'), 'git.repos' => $config->get('git', 'repositories'), 'git.hidden' => $config->get('git', 'hidden') ? $config->get('git', 'hidden') : array()));
     $this->register(new ViewUtilServiceProvider());
     $this->register(new RepositoryUtilServiceProvider());
     $this->register(new UrlGeneratorServiceProvider());
     $this['twig'] = $this->share($this->extend('twig', function ($twig, $app) {
         $twig->addFilter('md5', new \Twig_Filter_Function('md5'));
         return $twig;
     }));
     // Handle errors
     $this->error(function (\Exception $e, $code) use($app) {
         if ($app['debug']) {
             return;
         }
         return $app['twig']->render('error.twig', array('message' => $e->getMessage()));
     });
 }
Example #30
0
 /**
  * Constructor initialize services.
  *
  * @param Config $config
  * @param string $root   Base path of the application files (views, cache)
  */
 public function __construct(Config $config, $root = null)
 {
     parent::__construct();
     $app = $this;
     $this->path = realpath($root);
     $this['debug'] = $config->get('app', 'debug');
     $this['filetypes'] = $config->getSection('filetypes');
     $this['cache.archives'] = $this->getCachePath() . 'archives';
     $this['path_prefix'] = $config->get('app', 'path_prefix');
     $this['clone_url'] = $config->get('app', 'clone_url');
     // Register services
     $this->register(new TwigServiceProvider(), array('twig.path' => $this->getViewPath(), 'twig.options' => $config->get('app', 'cache') ? array('cache' => $this->getCachePath() . 'views') : array()));
     $repositories = $config->get('git', 'repositories');
     $this->register(new GitServiceProvider(), array('git.client' => $config->get('git', 'client'), 'git.repos' => $repositories, 'ini.file' => "config.ini", 'git.hidden' => $config->get('git', 'hidden') ? $config->get('git', 'hidden') : array(), 'git.default_branch' => $config->get('git', 'default_branch') ? $config->get('git', 'default_branch') : 'master'));
     $this->register(new ViewUtilServiceProvider());
     $this->register(new RepositoryUtilServiceProvider());
     $this->register(new UrlGeneratorServiceProvider());
     $this->register(new RoutingUtilServiceProvider());
     $this['twig'] = $this->share($this->extend('twig', function ($twig, $app) {
         $twig->addFilter('htmlentities', new \Twig_Filter_Function('htmlentities'));
         $twig->addFilter('md5', new \Twig_Filter_Function('md5'));
         return $twig;
     }));
     // Handle errors
     $this->error(function (\Exception $e, $code) use($app) {
         if ($app['debug']) {
             return;
         }
         return $app['twig']->render('error.twig', array('message' => $e->getMessage()));
     });
 }