Ejemplo n.º 1
0
 /**
  * Registers services on the given app.
  *
  * @param Application $app An Application instance
  */
 public function register(Application $app)
 {
     $app['video'] = $app->share(function () use($app) {
         return new VideoWrapper($app['monolog'], $app['db']);
     });
     $app['option'] = $app->share(function () use($app) {
         return new OptionWrapper($app['monolog'], $app['db']);
     });
 }
Ejemplo n.º 2
0
 /**
  * Cli constructor.
  *
  * @param array $config
  */
 public function __construct(array $config = [])
 {
     $this->config = ['name' => '', 'namespace' => ''];
     $this->config = array_replace_recursive($this->config, $config);
     $this->_isConfigValid();
     $this->app = new Application($this->config['name']);
     $this->app['config'] = $this->app->share(function () {
         return new Config();
     });
     $this->_initialize();
 }
 /**
  * Registers services on the given app.
  *
  * @param Application $app An Application instance
  */
 public function register(Application $app)
 {
     $app['validator'] = $app->share(function ($app) {
         return new Validator($app['validator.mapping.class_metadata_factory'], $app['validator.validator_factory'], isset($app['translator']) ? $app['translator'] : new DefaultTranslator());
     });
     $app['validator.mapping.class_metadata_factory'] = $app->share(function () {
         return new ClassMetadataFactory(new StaticMethodLoader());
     });
     $app['validator.validator_factory'] = $app->share(function () use($app) {
         $validators = isset($app['validator.validator_service_ids']) ? $app['validator.validator_service_ids'] : array();
         return new ConstraintValidatorFactory($app, $validators);
     });
 }
 public function register(Application $app)
 {
     $app['validator'] = $app->share(function () use($app) {
         return new Validator($app['validator.mapping.class_metadata_factory'], $app['validator.validator_factory']);
     });
     $app['validator.mapping.class_metadata_factory'] = $app->share(function () use($app) {
         return new ClassMetadataFactory(new StaticMethodLoader());
     });
     $app['validator.validator_factory'] = $app->share(function () {
         return new ConstraintValidatorFactory();
     });
     if (isset($app['validator.class_path'])) {
         $app['autoloader']->registerNamespace('Symfony\\Component\\Validator', $app['validator.class_path']);
     }
 }
 /**
  * Registers services on the given app.
  *
  * @param Application $app An Application instance
  */
 public function register(Application $app)
 {
     $app['hipchat'] = $app->share(function () use($app) {
         if (empty($app['hipchat.rooms'])) {
             return new NullLogger();
         }
         $log = new TargetMappingLogger();
         $app['hipchat.configure']($log);
         return $log;
     });
     $app['hipchat.configure'] = $app->protect(function (TargetMappingLogger $log) use($app) {
         $roomConfigs = $app['hipchat.rooms'];
         $defaults = ['targets' => [], 'name' => 'HipChat', 'notify' => false, 'level' => Logger::INFO, 'bubble' => true, 'useSSL' => true, 'format' => 'text', 'host' => 'api.hipchat.com', 'version' => HipChatHandler::API_V2, 'guzzle' => false];
         if (isset($roomConfigs['_default'])) {
             $defaults = $roomConfigs['_default'] + $defaults;
             unset($roomConfigs['_default']);
         }
         foreach ($roomConfigs as $roomConfig) {
             $roomConfig += $defaults;
             $logger = new Logger('hcm');
             if (!isset($roomConfig['room']) || !isset($roomConfig['token'])) {
                 throw new InvalidArgumentException('missing room/token configuration');
             }
             if (isset($roomConfig['guzzle']) && is_array($roomConfig['guzzle'])) {
                 $logger->pushHandler(new GuzzleHipChatHandler(new Client('', $this->prepareGuzzleOptions($roomConfig['guzzle'])), $roomConfig['token'], $roomConfig['room'], $roomConfig['name'], $roomConfig['notify'], $roomConfig['level'], $roomConfig['bubble'], $roomConfig['useSSL'], $roomConfig['format'], $roomConfig['host'], $roomConfig['version']));
             } else {
                 $logger->pushHandler(new HipChatHandler($roomConfig['token'], $roomConfig['room'], $roomConfig['name'], $roomConfig['notify'], $roomConfig['level'], $roomConfig['bubble'], $roomConfig['useSSL'], $roomConfig['format'], $roomConfig['host'], $roomConfig['version']));
             }
             $log->addLogger($logger, $roomConfig['targets']);
         }
     });
 }
Ejemplo n.º 6
0
 public function register(Application $app)
 {
     $app['twig.options'] = array();
     $app['twig.form.templates'] = array('form_div_layout.html.twig');
     $app['twig.path'] = array();
     $app['twig.templates'] = array();
     $app['twig'] = $app->share(function ($app) {
         $app['twig.options'] = array_replace(array('charset' => "UTF-8", 'debug' => isset($app['debug']) ? $app['debug'] : false, 'strict_variables' => isset($app['debug']) ? $app['debug'] : false), $app['twig.options']);
         $twig = new \Twig_Environment($app['twig.loader'], $app['twig.options']);
         $twig->addGlobal('app', $app);
         $twig->addExtension(new TwigCoreExtension());
         if (isset($app['debug']) && $app['debug']) {
             $twig->addExtension(new \Twig_Extension_Debug());
         }
         return $twig;
     });
     $app['twig.loader.filesystem'] = $app->share(function ($app) {
         return new \Twig_Loader_Filesystem($app['twig.path']);
     });
     $app['twig.loader.array'] = $app->share(function ($app) {
         return new \Twig_Loader_Array($app['twig.templates']);
     });
     $app['twig.loader.string'] = $app->share(function ($app) {
         return new \Twig_Loader_String();
     });
     $app['twig.loader'] = $app->share(function ($app) {
         return new \Twig_Loader_Chain(array($app['twig.loader.filesystem'], $app['twig.loader.array'], $app['twig.loader.string']));
     });
 }
Ejemplo n.º 7
0
 /**
  * Registers services on the given app.
  *
  * @param Application $app An Application instance.
  */
 public function register(Application $app)
 {
     $app[self::TEMPLATE_FOLDER] = realpath(__DIR__ . '/data/templates/');
     $app[self::CONVERTERS] = array('\\phpDocumentor\\Plugin\\Scrybe\\Converter\\RestructuredText\\ToHtml' => array(Format::RST, Format::HTML));
     $app[self::FORMATS] = $app->share(function () {
         return new Converter\Format\Collection();
     });
     $app[self::CONVERTER_DEFINITION_FACTORY] = $app->share(function ($container) {
         return new Factory($container[ServiceProvider::FORMATS]);
     });
     $app[self::CONVERTER_FACTORY] = $app->share(function ($container) {
         return new Converter\Factory($container['converters'], $container['converter_definition_factory'], $container['monolog']);
     });
     $app[self::TEMPLATE_FACTORY] = $app->share(function ($app) {
         return new Template\Factory(array('twig' => new Template\Twig($app[ServiceProvider::TEMPLATE_FOLDER])));
     });
     $this->addCommands($app);
 }
 public function register(Application $app)
 {
     $app['bugsnag'] = $app->share(function () use($app) {
         $client = new \Bugsnag_Client($app['bugsnag.options']['apiKey']);
         set_error_handler(array($client, 'errorhandler'));
         set_exception_handler(array($client, 'exceptionhandler'));
         return $client;
     });
 }
Ejemplo n.º 9
0
 /**
  * {@inheritDoc}
  */
 public function register(Application $app)
 {
     $prefix = $this->prefix;
     if (!isset($app["{$prefix}.client_options"])) {
         $app["{$prefix}.client_options"] = [];
     }
     $app["{$prefix}"] = $app->share(function () use($app, $prefix) {
         return new Client($app["{$prefix}.client_options"]);
     });
 }
Ejemplo n.º 10
0
 /**
  * Registers services on the given app.
  *
  * @param Application $app An Application instance
  *
  * @throws Exception\MissingDependencyException if the Descriptor Builder is not present.
  *
  * @return void
  */
 public function register(Application $app)
 {
     if (!isset($app['descriptor.builder'])) {
         throw new Exception\MissingDependencyException('The builder object that is used to construct the ProjectDescriptor is missing');
     }
     $app['parser'] = $app->share(function ($app) {
         $parser = new Parser();
         $parser->setStopwatch($app['kernel.stopwatch']);
         $parser->setLogger($app['monolog']);
         return $parser;
     });
     $app['markdown'] = $app->share(function () {
         return \Parsedown::instance();
     });
     /** @var Translator $translator  */
     $translator = $app['translator'];
     $translator->addTranslationFolder(__DIR__ . DIRECTORY_SEPARATOR . 'Messages');
     $app['parser.files'] = new Collection();
     $app->command(new ParseCommand($app['descriptor.builder'], $app['parser'], $translator, $app['parser.files']));
 }
Ejemplo n.º 11
0
 /**
  * Registers the translator using the currently active locale.
  *
  * @param Application $app
  */
 public function register(Application $app)
 {
     /** @var ApplicationConfiguration $config */
     $config = $app['config'];
     $app['translator.locale'] = $config->getTranslator()->getLocale();
     $app['translator'] = $app->share(function ($app) {
         $translator = new Translator();
         $translator->setLocale($app['translator.locale']);
         return $translator;
     });
 }
Ejemplo n.º 12
0
 /**
  * Registers services on the given app.
  *
  * @param Application $app An Application instance
  */
 public function register(Application $app)
 {
     if (!isset($app['descriptor.builder'])) {
         throw new Exception\MissingDependencyException('The builder object that is used to construct the ProjectDescriptor is missing');
     }
     if (!isset($app['serializer'])) {
         throw new Exception\MissingDependencyException('The serializer object that is used to read the template configuration with is missing');
     }
     $templateDir = __DIR__ . '/../../../data/templates';
     // vendored installation
     if (file_exists(__DIR__ . '/../../../../templates')) {
         $templateDir = __DIR__ . '/../../../../templates';
     }
     // parameters
     $app['transformer.template.location'] = $templateDir;
     $app['linker.substitutions'] = array('phpDocumentor\\Descriptor\\ProjectDescriptor' => array('files'), 'phpDocumentor\\Descriptor\\FileDescriptor' => array('tags', 'classes', 'interfaces', 'traits'), 'phpDocumentor\\Descriptor\\ClassDescriptor' => array('tags', 'parent', 'interfaces', 'constants', 'properties', 'methods'), 'phpDocumentor\\Descriptor\\InterfaceDescriptor' => array('tags', 'parent', 'constants', 'methods'), 'phpDocumentor\\Descriptor\\TraitDescriptor' => array('tags', 'properties', 'methods'), 'phpDocumentor\\Descriptor\\MethodDescriptor' => array('tags', 'arguments'), 'phpDocumentor\\Descriptor\\ArgumentDescriptor' => array('types'), 'phpDocumentor\\Descriptor\\PropertyDescriptor' => array('tags', 'types'), 'phpDocumentor\\Descriptor\\ConstantDescriptor' => array('tags', 'types'), 'phpDocumentor\\Descriptor\\Tag\\ParamDescriptor' => array('types'), 'phpDocumentor\\Descriptor\\Tag\\ReturnDescriptor' => array('types'), 'phpDocumentor\\Descriptor\\Tag\\SeeDescriptor' => array('reference'));
     // services
     $app['compiler'] = $app->share(function ($container) {
         $compiler = new Compiler();
         $compiler->insert(new ElementsIndexBuilder(), ElementsIndexBuilder::COMPILER_PRIORITY);
         $compiler->insert(new PackageTreeBuilder(), PackageTreeBuilder::COMPILER_PRIORITY);
         $compiler->insert(new NamespaceTreeBuilder(), NamespaceTreeBuilder::COMPILER_PRIORITY);
         $compiler->insert($container['linker'], Linker::COMPILER_PRIORITY);
         $compiler->insert($container['transformer'], Transformer::COMPILER_PRIORITY);
         $compiler->insert(new Debug($container['monolog'], $container['descriptor.analyzer']), Debug::COMPILER_PRIORITY);
         return $compiler;
     });
     $app['linker'] = $app->share(function ($app) {
         return new Linker($app['linker.substitutions']);
     });
     $app['transformer.behaviour.collection'] = $app->share(function () {
         return new Behaviour\Collection();
     });
     $app['transformer.routing.queue'] = $app->share(function () {
         $queue = new Router\Queue();
         // TODO: load from app configuration instead of hardcoded
         $queue->insert(new Router\StandardRouter(), 10000);
         return $queue;
     });
     $app['transformer.writer.collection'] = $app->share(function ($container) {
         return new Writer\Collection($container['transformer.routing.queue']);
     });
     $app['transformer.template.collection'] = $app->share(function ($container) {
         return new Template\Collection($container['transformer.template.location'], $container['serializer']);
     });
     $app['transformer'] = $app->share(function ($container) {
         $transformer = new Transformer($container['transformer.template.collection'], $container['transformer.writer.collection']);
         $transformer->setBehaviours($container['transformer.behaviour.collection']);
         return $transformer;
     });
     $app->command(new TransformCommand($app['descriptor.builder'], $app['transformer'], $app['compiler']));
     $app->command(new ListCommand());
 }
 public function register(Application $app)
 {
     $app['translator'] = $app->share(function ($app) {
         $translator = new Translator('en', $app['translator.message_selector']);
         // Handle deprecated 'locale_fallback'
         if (isset($app['locale_fallback'])) {
             $app['locale_fallbacks'] = (array) $app['locale_fallback'];
         }
         $translator->setFallbackLocales($app['locale_fallbacks']);
         $translator->addLoader('array', new ArrayLoader());
         $translator->addLoader('xliff', new XliffFileLoader());
         foreach ($app['translator.domains'] as $domain => $data) {
             foreach ($data as $locale => $messages) {
                 $translator->addResource('array', $messages, $locale, $domain);
             }
         }
         return $translator;
     });
     $app['translator.message_selector'] = $app->share(function () {
         return new MessageSelector();
     });
     $app['translator.domains'] = array();
     $app['locale_fallbacks'] = array('en');
 }
Ejemplo n.º 14
0
 /**
  * Registers services on the given app.
  *
  * @param Application $app An Application instance
  *
  * @throws Exception\MissingDependencyException if the Descriptor Builder is not present.
  *
  * @return void
  */
 public function register(Application $app)
 {
     if (!isset($app['descriptor.builder'])) {
         throw new Exception\MissingDependencyException('The builder object that is used to construct the ProjectDescriptor is missing');
     }
     $app['parser'] = $app->share(function () {
         return new Parser();
     });
     /** @var Translator $translator  */
     $translator = $app['translator'];
     $translator->addTranslationFolder(__DIR__ . DIRECTORY_SEPARATOR . 'Messages');
     $app->command(new ParseCommand($app['descriptor.builder'], $app['parser'], $translator));
     /** @var Dispatcher $dispatcher  */
     $dispatcher = $app['event_dispatcher'];
     $dispatcher->addListener('reflection.docblock-extraction.post', array($this, 'validateDocBlocks'));
 }
 public function register(Application $app)
 {
     $this->app = $app;
     $app['config'] = $app->share(function () use($app) {
         $config = array();
         foreach ($app['config.paths'] as $path) {
             if (!file_exists($path)) {
                 continue;
             }
             $parser = new Yaml\Parser();
             $result = @file_get_contents($path);
             if ($result === FALSE) {
                 $result = $app['process']->executeSudoCommand("cat " . $path, true);
             }
             $config = array_replace_recursive($config, $parser->parse($result));
         }
         return $config;
     });
 }
Ejemplo n.º 16
0
 public function register(Application $app)
 {
     $app['monolog'] = $app->share(function () use($app) {
         $log = new Logger(isset($app['monolog.name']) ? $app['monolog.name'] : 'myapp');
         $app['monolog.configure']($log);
         return $log;
     });
     $app['monolog.configure'] = $app->protect(function ($log) use($app) {
         $log->pushHandler($app['monolog.handler']);
     });
     $app['monolog.handler'] = function () use($app) {
         return new StreamHandler($app['monolog.logfile'], $app['monolog.level']);
     };
     if (!isset($app['monolog.level'])) {
         $app['monolog.level'] = function () {
             return Logger::DEBUG;
         };
     }
     if (isset($app['monolog.class_path'])) {
         $app['autoloader']->registerNamespace('Monolog', $app['monolog.class_path']);
     }
 }
 /**
  * Registers services on the given app.
  *
  * @param Application $app An Application instance
  */
 public function register(Application $app)
 {
     $vendorPath = isset($app['composer.vendor_path']) ? $app['composer.vendor_path'] : __DIR__ . '/../../../vendor';
     $serializerPath = $vendorPath . '/jms/serializer/src';
     if (!file_exists($serializerPath)) {
         $serializerPath = __DIR__ . '/../../../../../jms/serializer/src';
     }
     $app['serializer.annotations'] = array(array('namespace' => 'JMS\\Serializer\\Annotation', 'path' => $serializerPath));
     $app['serializer'] = $app->share(function ($container) {
         if (!isset($container['serializer.annotations']) || !is_array($container['serializer.annotations'])) {
             throw new \RuntimeException('Expected the container to have an array called "serializer.annotations" that describes which ' . 'annotations are supported by the Serializer and where it can find them');
         }
         foreach ($container['serializer.annotations'] as $annotationsDefinition) {
             if (!isset($annotationsDefinition['namespace'])) {
                 throw new \UnexpectedValueException('The annotation definition for the Serializer should have a key "namespace" that tells the ' . 'serializer what the namespace for the provided annotations are.');
             }
             if (!isset($annotationsDefinition['path'])) {
                 throw new \UnexpectedValueException('The annotation definition for the Serializer should have a key "path" that tells the ' . 'serializer where it can find the provided annotations.');
             }
             AnnotationRegistry::registerAutoloadNamespace($annotationsDefinition['namespace'], $annotationsDefinition['path']);
         }
         return SerializerBuilder::create()->build();
     });
 }
Ejemplo n.º 18
0
 public function register(Application $app)
 {
     $app['config'] = $app->share(function () use($app) {
         if (!file_exists($app['config.path'])) {
             throw new \InvalidArgumentException($app['config.path'] . ' is not a valid path to the ' . 'configuration');
         }
         $fullpath = explode('.', $app['config.path']);
         switch (strtolower(end($fullpath))) {
             case 'yml':
                 $parser = new Yaml\Parser();
                 $result = new \ArrayObject($parser->parse(file_get_contents($app['config.path'])));
                 break;
             case 'xml':
                 $result = simplexml_load_file($app['config.path']);
                 break;
             case 'json':
                 $result = json_decode(file_get_contents($app['config.path']));
                 break;
             default:
                 throw new \InvalidArgumentException('Unable to load configuration; the provided file ' . 'extension was not recognized. Only yml or xml allowed');
         }
         return $result;
     });
 }
Ejemplo n.º 19
0
 public function register(Application $app)
 {
     $app['db.default_options'] = array('driver' => 'pdo_mysql', 'dbname' => null, 'host' => 'localhost', 'user' => 'root', 'password' => null);
     $app['dbs.options.initializer'] = $app->protect(function () use($app) {
         static $initialized = false;
         if ($initialized) {
             return;
         }
         $initialized = true;
         if (!isset($app['dbs.options'])) {
             $app['dbs.options'] = array('default' => isset($app['db.options']) ? $app['db.options'] : array());
         }
         $tmp = $app['dbs.options'];
         foreach ($tmp as $name => &$options) {
             $options = array_replace($app['db.default_options'], $options);
             if (!isset($app['dbs.default'])) {
                 $app['dbs.default'] = $name;
             }
         }
         $app['dbs.options'] = $tmp;
     });
     $app['dbs'] = $app->share(function () use($app) {
         $app['dbs.options.initializer']();
         $dbs = new \Pimple();
         foreach ($app['dbs.options'] as $name => $options) {
             if ($app['dbs.default'] === $name) {
                 // we use shortcuts here in case the default has been overriden
                 $config = $app['db.config'];
                 $manager = $app['db.event_manager'];
             } else {
                 $config = $app['dbs.config'][$name];
                 $manager = $app['dbs.event_manager'][$name];
             }
             $dbs[$name] = DriverManager::getConnection($options, $config, $manager);
         }
         return $dbs;
     });
     $app['dbs.config'] = $app->share(function () use($app) {
         $app['dbs.options.initializer']();
         $configs = new \Pimple();
         foreach ($app['dbs.options'] as $name => $options) {
             $configs[$name] = new Configuration();
         }
         return $configs;
     });
     $app['dbs.event_manager'] = $app->share(function () use($app) {
         $app['dbs.options.initializer']();
         $managers = new \Pimple();
         foreach ($app['dbs.options'] as $name => $options) {
             $managers[$name] = new EventManager();
         }
         return $managers;
     });
     // shortcuts for the "first" DB
     $app['db'] = $app->share(function () use($app) {
         $dbs = $app['dbs'];
         return $dbs[$app['dbs.default']];
     });
     $app['db.config'] = $app->share(function () use($app) {
         $dbs = $app['dbs.config'];
         return $dbs[$app['dbs.default']];
     });
     $app['db.event_manager'] = $app->share(function () use($app) {
         $dbs = $app['dbs.event_manager'];
         return $dbs[$app['dbs.default']];
     });
     if (isset($app['db.dbal.class_path'])) {
         $app['autoloader']->registerNamespace('Doctrine\\DBAL', $app['db.dbal.class_path']);
     }
     if (isset($app['db.common.class_path'])) {
         $app['autoloader']->registerNamespace('Doctrine\\Common', $app['db.common.class_path']);
     }
 }
Ejemplo n.º 20
0
 /**
  * Initializes the templating system in the container.
  *
  * @param Application $app
  *
  * @return void
  */
 protected function provideTemplatingSystem(Application $app)
 {
     $templateDir = __DIR__ . '/../../../data/templates';
     // when installed using composer the templates are in a different folder
     $composerTemplatePath = __DIR__ . '/../../../../templates';
     if (file_exists($composerTemplatePath)) {
         $templateDir = $composerTemplatePath;
     }
     // parameters
     $app['transformer.template.location'] = $templateDir;
     // services
     $app['transformer.template.path_resolver'] = $app->share(function ($container) {
         return new PathResolver($container['transformer.template.location']);
     });
     $app['transformer.template.factory'] = $app->share(function ($container) {
         return new Factory($container['transformer.template.path_resolver'], $container['serializer']);
     });
     $app['transformer.template.collection'] = $app->share(function ($container) {
         return new Template\Collection($container['transformer.template.factory'], $container['transformer.writer.collection']);
     });
 }
Ejemplo n.º 21
0
 /**
  * Adds validators for the descriptors to the validator manager.
  *
  * @param Application $app
  *
  * @throws Exception\MissingDependencyException if the validator could not be found.
  *
  * @return void
  */
 protected function addValidators(Application $app)
 {
     if (!isset($app['validator'])) {
         throw new Exception\MissingDependencyException('The validator manager is missing');
     }
     $provider = $this;
     $app['validator'] = $app->share($app->extend('validator', function ($validatorManager) use($provider) {
         return $provider->attachValidators($validatorManager);
     }));
 }
Ejemplo n.º 22
0
 /**
  * @param Application $app
  */
 public function register(Application $app)
 {
     $app['vandpibe.generator.heroku'] = $app->share(function () use($app) {
         return new HerokuGenerator();
     });
 }