예제 #1
0
 public function testCreateSilexApplication()
 {
     $logger = new \Psr\Log\NullLogger();
     $silex = new Silex\Application(array('debug' => true, 'logger' => $logger));
     $silex->register(new \PHPExtra\Proxy\Provider\Silex\ProxyServiceProvider(), array('logger' => $logger, 'proxy.storage' => new \PHPExtra\Proxy\Storage\InMemoryStorage(), 'proxy.adapter.name' => 'dummy', 'proxy.adapter.dummy.handler' => $silex->protect(function (\PHPExtra\Proxy\Http\RequestInterface $request) {
         return new \PHPExtra\Proxy\Http\Response('I see ' . $request->getRequestUri());
     }), 'proxy.logger.access_log' => $logger));
     $silex->register(new \PHPExtra\EventManager\Silex\EventManagerServiceProvider());
     $silex->boot();
     $request = \Symfony\Component\HttpFoundation\Request::create('http://test.com/ping');
     $response = $silex->handle($request);
     $silex->terminate($request, $response);
     $this->assertEquals('I see /ping', $response->getContent());
     $this->assertEquals(200, $response->getStatusCode());
 }
 /**
  * @return Silex\Application
  */
 static function getApp()
 {
     $app = new \Silex\Application();
     $app['debug'] = TRUE;
     $app->register(new MonologServiceProvider(), array('monolog.logfile' => ROOT . '/log.txt'));
     $app->register(new UrlGeneratorServiceProvider());
     $app->register(new ConsoleServiceProvider());
     $app->register(new SessionServiceProvider(), array('session.test' => TRUE));
     $app->register(new TranslationServiceProvider());
     $app->register(new TwigServiceProvider(), array("twig.options" => array("path" => ROOT)));
     $app->register(new FormServiceProvider());
     $app->register(new DoctrineServiceProvider(), array("db.options" => array("driver" => "pdo_sqlite", "path" => 'url_shortener.sqlite')));
     $app->register(new DoctrineORMServiceProvider());
     $app->register(new UrlShortenerAppServiceProvider());
     $app->register(new ValidatorServiceProvider());
     /*$app->register(new ValidatorServiceProvider, array(
           "validator.mapping.chain_loader" => $app->share(function ($app) {
               return new CustomLoaderChain(
                   array(
                       new StaticMethodLoader,
                   )
               );
           }),
           "validator.mapping.class_metadata_factory" => $app->share(function ($app) {
               return new ClassMetadataFactory($app['validator.chain_loader']);
           })
       ));*/
     $app->mount("/", $app['url_shortener.controller']);
     $app->boot();
     /**
      * create the database
      */
     /* @var $em \Doctrine\ORM\EntityManager */
     $em = $app['orm.em'];
     $app['createDB'] = $app->protect(function () use($em) {
         $tool = new SchemaTool($em);
         $tool->dropDatabase();
         $tool->createSchema($em->getMetadataFactory()->getAllMetadata());
     });
     return $app;
 }
예제 #3
0
require_once __DIR__ . '/../vendor/autoload.php';
$debug = false;
$app = new Silex\Application();
$app->register(new Silex\Provider\SessionServiceProvider());
if ($debug) {
    $app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => __DIR__ . '/../development.log'));
}
/**
 * Using twig template engine
 */
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../src/Symstriker/TicTacToe/Resources/views'));
/**
 * Sharing game engine for all
 */
$app['game_engine'] = $app->protect(function (PlayerInterface $player1 = null, PlayerInterface $player2 = null, Board $board = null) use($app) {
    return \Symstriker\TicTacToe\Engine\GameEngine::start($app['request']->getSession(), $player1, $player2);
});
/******************
 * Controllers
 ******************/
/**
 * Welcome action
 */
$app->get('/', function () use($app) {
    return $app['twig']->render('welcome.html.twig');
})->bind('welcome');
$app->get('/aboutme', function () use($app) {
    return $app['twig']->render('aboutme.html.twig');
})->bind('aboutme');
/**
 * Welcome action
예제 #4
0
    }
    $app['translator']->addLoader('yml', new Symfony\Component\Translation\Loader\YamlFileLoader());
    $app['translator']->addResource('yml', $messagesFile, $messagesLocale);
});
$app['templated_uri_generator'] = $app->share(function () use($app) {
    return new Rfc6570Generator($app['routes'], $app['request_context']);
});
// Markdown
$app->register(new Nicl\Silex\MarkdownServiceProvider());
// Negotiation
$app->register(new KPhoen\Provider\NegotiationServiceProvider(['json' => ['application/hal+json', 'application/json'], 'xml' => ['application/hal+xml', 'application/xml']]));
// Document validator
$app['document_validator'] = $app->protect(function (Document $document) use($app) {
    $errors = $app['validator']->validate($document);
    if (0 < count($errors)) {
        return new FormErrors($errors);
    }
    return true;
});
// View
$app['view_handler'] = $app->share(function () use($app) {
    return new ViewHandler($app['serializer'], $app['request'], $app['acceptable_mime_types']);
});
// Error handler
$app->error(function (\Exception $e, $code) use($app) {
    if (405 === $code) {
        return new Response($e->getMessage(), 405, array_merge($e->getHeaders(), ['Content-Type' => 'text/plain']));
    }
    if (406 === $code) {
        return new Response($e->getMessage(), 406, ['Content-Type' => 'text/plain']);
    }
예제 #5
0
<?php

require __DIR__ . '/vendor/autoload.php';
$app = new \Silex\Application();
$app['conftool.passPhrase'] = 'cG9v3N38';
$app['conftool.baseUrl'] = 'https://www.conftool.pro/esa2015/rest.php';
$app['conftool.createUrl'] = $app->protect(function ($export = 'sessions', $query = []) use($app) {
    $nonce = time();
    $pass = $app['conftool.passPhrase'];
    $query = array_merge(['nonce' => $nonce, 'passhash' => hash('sha256', $nonce . $pass), 'page' => 'adminExport', 'export_select' => $export, 'form_export_format' => 'xml', 'cmd_create_export' => true, 'form_export_sessions_options' => ['presentations', 'presentations_abstracts', 'all']], $query);
    return $app['conftool.baseUrl'] . '?' . http_build_query($query);
});
$app['db.url'] = getenv('DATABASE_URL');
if (empty($app['db.url'])) {
    throw new RuntimeException('Set DATABASE_URL environment variable.');
}
$app['db'] = $app->factory(function () use($app) {
    $conn = \Doctrine\DBAL\DriverManager::getConnection(['url' => $app['db.url']]);
    $conn->executeQuery("SET client_encoding = 'UTF8'");
    return $conn;
});
return $app;
예제 #6
0
<?php

require_once 'vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/views'));
$app['skype'] = $app->share(function () {
    return Inviqa\SkypeEngine::getDbusProxy();
});
$app['bot'] = $app->protect(function ($dbus) {
    $bot = new Inviqa\SkypeEngine($dbus);
    return $bot;
});
$app->get('/', function () use($app) {
    return $app['twig']->render('index.twig', array());
});
$app->post('/', function (Request $request) use($app) {
    $username = $request->request->get('username');
    $app['skype']->Invoke("SET USER {$username} ISAUTHORIZED TRUE");
    $app['skype']->Invoke("SET USER {$username} ISBLOCKED FALSE");
    $app['bot']($app['skype'])->parse($app['skype']->Invoke("SET USER {$username} BUDDYSTATUS 2"));
    return $app['twig']->render('thanks.twig', array());
});
$app->run();
예제 #7
0
//load routes from config/routes.yml
$app['routes'] = $app->extend('routes', function (RouteCollection $routes, Silex\Application $app) {
    $loader = new YamlFileLoader(new FileLocator(__DIR__ . '/config'));
    $collection = $loader->load('routes.yml');
    $routes->addCollection($collection);
    return $routes;
});
//register logger
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => __DIR__ . '/log/dev.log'));
if (!isset($dbName)) {
    $app['monolog']->addInfo("dbName is null!!!!!");
    exit;
}
//mongo connection & ODM
$app->register(new MongoDBODMServiceProvider(), array('doctrine.odm.mongodb.connection_options' => array('database' => $dbName, 'host' => 'localhost', 'options' => array('fsync' => false)), 'doctrine.odm.mongodb.documents' => array(0 => array('type' => 'annotation', 'path' => array('src/Timeshare/Entities'), 'namespace' => 'Timeshare\\Entities', 'alias' => 'ann')), 'doctrine.odm.mongodb.proxies_dir' => 'cache/doctrine/odm/mongodb/Proxy', 'doctrine.odm.mongodb.proxies_namespace' => 'DoctrineMongoDBProxy', 'doctrine.odm.mongodb.auto_generate_proxies' => true, 'doctrine.odm.mongodb.hydrators_dir' => 'cache/doctrine/odm/mongodb/Hydrator', 'doctrine.odm.mongodb.hydrators_namespace' => 'DoctrineMongoDBHydrator', 'doctrine.odm.mongodb.auto_generate_hydrators' => true, 'doctrine.odm.mongodb.metadata_cache' => new \Doctrine\Common\Cache\ArrayCache(), 'doctrine.odm.mongodb.logger_callable' => $app->protect(function ($query) {
    // log your query
})));
//register all entities
// $app->register(new MongoDBODMServiceProvider(), array(
//     // ...
//     'doctrine.odm.mongodb.documents' => array(
//         0 => array(
//             'type' => 'annotation',
//             'path' => array(
//                  'src/Todos/Entities'
//             ),
//             'namespace' => 'Todos\Entities',
//             'alias'     => 'docs',
//         ),
//     ),
//     // ...
예제 #8
0
require __DIR__ . '/config.php';
$app->register(new HttpCacheServiceProvider());
$app->register(new SessionServiceProvider());
$app->register(new ValidatorServiceProvider());
$app->register(new FormServiceProvider());
$app->register(new UrlGeneratorServiceProvider());
$app->register(new TranslationServiceProvider(), array('locale' => $app['locale']));
$app['translator'] = $app->share($app->extend('translator', function ($translator, $app) {
    $translator->addLoader('yaml', new YamlFileLoader());
    $translator->addResource('yaml', __DIR__ . '/../resources/locales/fr.yml', 'fr');
    return $translator;
}));
// Temporarly hack
$app['translator.domains'] = array();
$app->register(new MonologServiceProvider(), array('monolog.logfile' => __DIR__ . '/../log/app.log', 'monolog.name' => 'app', 'monolog.level' => 300));
$app->register(new TwigServiceProvider(), array('twig.options' => array('cache' => false, 'strict_variables' => true), 'twig.form.templates' => array('form_div_layout.html.twig', 'common/form_div_layout.html.twig'), 'twig.path' => array(__DIR__ . '/../views')));
$app->register(new DoctrineServiceProvider(), array('db.options' => array('driver' => $app['db.config.driver'], 'dbname' => $app['db.config.dbname'], 'host' => $app['db.config.host'], 'user' => $app['db.config.user'], 'password' => $app['db.config.password'])));
$app->register(new AsseticExtension(), array('assetic.options' => array('debug' => $app['debug']), 'assetic.filters' => $app->protect(function ($fm) use($app) {
    $fm->set('yui_css', new Assetic\Filter\Yui\CssCompressorFilter($app['assetic.filter.yui_compressor.path']));
    $fm->set('yui_js', new Assetic\Filter\Yui\JsCompressorFilter($app['assetic.filter.yui_compressor.path']));
}), 'assetic.assets' => $app->protect(function ($am, $fm) use($app) {
    $am->set('styles', new Assetic\Asset\AssetCache(new Assetic\Asset\GlobAsset($app['assetic.input.path_to_css'], array()), new Assetic\Cache\FilesystemCache($app['assetic.path_to_cache'])));
    $am->get('styles')->setTargetPath($app['assetic.output.path_to_css']);
    $am->set('scripts', new Assetic\Asset\AssetCache(new Assetic\Asset\GlobAsset($app['assetic.input.path_to_js'], array()), new Assetic\Cache\FilesystemCache($app['assetic.path_to_cache'])));
    $am->get('scripts')->setTargetPath($app['assetic.output.path_to_js']);
})));
// Temporary hack. Silex should start session on demand.
$app->before(function () use($app) {
    $app['session']->start();
});
return $app;
예제 #9
0
$app['hc.pkg_dir'] = $app['hc.root_dir'] . '/pkg';
$app['hc.config'] = $app->share(function () use($app) {
    $configFile = $app['hc.root_dir'] . '/config/config.yml';
    if (!file_exists($configFile)) {
        throw new Exception('Missing config file!');
    }
    return Config::loadYaml(file_get_contents($configFile));
});
$app['hc.method_builder'] = $app->share(function () {
    return new Package\MethodGenerator();
});
$app['hc.package_loader'] = $app->share(function () use($app) {
    return new Package\Loader($app['hc.config']->getEnabledPackages());
});
$app['hc.cache_factory'] = $app->protect(function ($namespace) use($app) {
    return new FilesystemCache($app['hc.cache_dir'] . '/' . $namespace);
});
$app['hc.cache'] = $app->share(function () use($app) {
    return $app['hc.cache_factory']('__core__');
});
$app['hc.pkg_cache'] = $app->protect(function ($ns, $package = null) use($app) {
    $pkgDir = $package ? '/' . $package : null;
    return $app['hc.cache_factory']($ns . $pkgDir);
});
$app['hc.api_registry'] = $app->share(function () use($app) {
    return new Api\Client\Registry($app['hc.cache']);
});
$app['hc.api_client'] = $app->protect(function ($clientId) use($app) {
    return new Api\Client($clientId, $app['hc.config'], $app['hc.api_registry'], $app['hc.http_client'], $app['logger']);
});
$app['hc.api_request_validator'] = $app->share(function () use($app) {
예제 #10
0
<?php

require_once __DIR__ . '/../../vendor/autoload.php';
$app = new Silex\Application();
// Debug?
$app['debug'] = true;
// @see http://silex.sensiolabs.org/doc/providers/security.html
//$app->register(new Silex\Provider\SecurityServiceProvider() );
$app->register(new Propel\Silex\PropelServiceProvider(), array('propel.config_file' => __DIR__ . '/conf/Propilex-conf.php', 'propel.model_path' => __DIR__ . '/../../src/Propilex/Model'));
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../../views'));
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => __DIR__ . '/../../log/development.log', 'monolog.name' => 'birthday'));
$app->register(new SilexExtension\AsseticExtension(), array('assetic.class_path' => __DIR__ . '/../../vendor/assetic/src', 'assetic.path_to_web' => __DIR__ . '/../../web/assets', 'assetic.filter.yui_compressor.path' => __DIR__ . '/../../bin/yuicompressor/build/yuicompressor-2.4.7.jar', 'assetic.options' => array('debug' => $app['debug']), 'assetic.filters' => $app->protect(function ($fm) use($app) {
    $fm->set('less', new Assetic\Filter\LessphpFilter());
    $fm->set('yui_css', new Assetic\Filter\Yui\CssCompressorFilter($app['assetic.filter.yui_compressor.path']));
})));
// Parser that removes "root" on JSON objects
$app['json_parser'] = new Propilex\Parser\JsonParser();
return $app;
예제 #11
0
<?php

require_once __DIR__ . '/../functions.php';
require_once __DIR__ . '/../silex.phar';
$app = new Silex\Application();
$app->register(new Silex\Extension\TwigExtension(), array('twig.class_path' => __DIR__ . '/../vendor/twig/lib', 'twig.path' => __DIR__ . '/twig'));
$app['autoloader']->registerNamespace('SilexExtension', __DIR__ . '/../src');
$app->register(new SilexExtension\AsseticExtension(), array('assetic.class_path' => __DIR__ . '/../vendor/assetic/src', 'assetic.path_to_web' => __DIR__ . '/assetic/output', 'assetic.options' => array('formulae_cache_dir' => __DIR__ . '/assetic/cache', 'debug' => false), 'assetic.filters' => $app->protect(function ($fm) {
    $fm->set('yui_css', new Assetic\Filter\Yui\CssCompressorFilter('/usr/share/yui-compressor/yui-compressor.jar'));
    $fm->set('yui_js', new Assetic\Filter\Yui\JsCompressorFilter('/usr/share/yui-compressor/yui-compressor.jar'));
}), 'assetic.assets' => $app->protect(function ($am, $fm) {
    $am->set('styles', new Assetic\Asset\AssetCache(new Assetic\Asset\GlobAsset(__DIR__ . '/assetic/resources/css/*.css', array($fm->get('yui_css'))), new Assetic\Cache\FilesystemCache(__DIR__ . '/assetic/cache')));
    $am->get('styles')->setTargetPath('css/styles');
})));
$app->get('/', function () use($app) {
    return "Hello!";
});
$app->run();