public function setUp()
 {
     vfsStreamWrapper::register();
     vfsStreamWrapper::setRoot(new vfsStreamDirectory('cacheDir'));
     $application = new \Silex\Application();
     $application[\Phruts\Util\Globals::DIGESTER] = $application->share(function () {
         $digester = new Digester();
         $digester->addRuleSet(new ConfigRuleSet('phruts-config'));
         return $digester;
     });
     $this->fileCache = new FileCacheModuleProvider($application);
     $this->fileCache->setCachePath(vfsStream::url('cacheDir'));
 }
Example #2
0
 public function createApplication()
 {
     // Silex
     $app = new Silex\Application();
     require __DIR__ . '/../../resources/config/test.php';
     require __DIR__ . '/../../src/app.php';
     // Use FilesystemSessionStorage to store session
     $app['session.storage'] = $app->share(function () {
         return new MockFileSessionStorage(sys_get_temp_dir());
     });
     // Controllers
     require __DIR__ . '/../../src/controllers.php';
     return $this->app = $app;
 }
 public function setUp()
 {
     parent::setUp();
     $app = new \Silex\Application();
     $app->register(new \Silex\Provider\FormServiceProvider());
     $app->register(new \Eccube\ServiceProvider\ValidatorServiceProvider());
     $app['form.types'] = $app->share($app->extend('form.types', function ($types) use($app) {
         $config['config']['name_len'] = 50;
         $types[] = new \Eccube\Form\Type\NameType($config['config']);
         // Nameに依存する
         return $types;
     }));
     // CSRF tokenを無効にしてFormを作成
     $this->form = $app['form.factory']->createBuilder('form', null, array('csrf_protection' => false))->add('name', 'name')->getForm();
 }
 public function setUp()
 {
     parent::setUp();
     // \Eccube\Applicationは重いから呼ばない
     $app = new \Silex\Application();
     $app->register(new \Silex\Provider\FormServiceProvider());
     $app->register(new \Eccube\ServiceProvider\ValidatorServiceProvider());
     $self = $this;
     $app['form.types'] = $app->share($app->extend('form.types', function ($types) use($app, $self) {
         $types[] = new \Eccube\Form\Type\PriceType($self->config);
         return $types;
     }));
     // CSRF tokenを無効にしてFormを作成
     $this->form = $app['form.factory']->createBuilder('price', null, array('csrf_protection' => false))->getForm();
 }
 public function createApplication()
 {
     $app = new \Silex\Application();
     $app->register(new \Silex\Provider\FormServiceProvider());
     $app->register(new \Eccube\ServiceProvider\ValidatorServiceProvider());
     $app['eccube.service.plugin'] = $app->share(function () use($app) {
         return new \Eccube\Service\PluginService($app);
     });
     // fix php5.3
     $self = $this;
     $app['form.types'] = $app->share($app->extend('form.types', function ($types) use($app, $self) {
         $types[] = new \Eccube\Form\Type\RepeatedEmailType();
         return $types;
     }));
     return $app;
 }
 public function createApplication()
 {
     // Silex
     $app = new Silex\Application();
     require __DIR__ . '/../../src/app.php';
     require __DIR__ . '/../../resources/config/dev.php';
     // Tests mode
     unset($app['exception_handler']);
     $app['translator.messages'] = array();
     // Use FilesystemSessionStorage to store session
     $app['session.storage'] = $app->share(function () {
         return new MockFileSessionStorage(sys_get_temp_dir());
     });
     // Controllers
     require __DIR__ . '/../../src/controllers.php';
     return $this->app = $app;
 }
Example #7
0
$app = new Silex\Application();
$app['template_url'] = WEB_URL;
if (is_readable(CONFIG_FILE)) {
    $app->register(new DerAlex\Silex\YamlConfigServiceProvider(CONFIG_FILE));
    $app['debug'] = $app['config']['debug'];
    Symfony\Component\Debug\ExceptionHandler::register(!$app['debug']);
    if (in_array($app['config']['timezone'], DateTimeZone::listIdentifiers())) {
        date_default_timezone_set($app['config']['timezone']);
    }
}
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/views', 'twig.options' => array('debug' => $app['debug'])));
$app->register(new Silex\Provider\SessionServiceProvider());
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app->register(new Silex\Provider\SecurityServiceProvider(), array('security.firewalls' => array('admin' => array('pattern' => '^/logs', 'form' => array('login_path' => '/login', 'check_path' => '/logs/login_check'), 'users' => array('user' => array('ROLE_USER', is_file(PASSWD_FILE) ? file_get_contents(PASSWD_FILE) : null)), 'logout' => array('logout_path' => '/logs/logout')))));
$app['security.encoder.digest'] = $app->share(function ($app) {
    return new \Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder(10);
});
if (!is_file(PASSWD_FILE)) {
    $app->match('/', function (\Symfony\Component\HttpFoundation\Request $request) use($app) {
        $error = "";
        if ($request->getMethod() == "POST") {
            if ($request->get('password') == $request->get('password-repeat')) {
                if (is_writable(PASSWD_DIR)) {
                    $user = new \Symfony\Component\Security\Core\User\User('user', array());
                    $encoder = $app['security.encoder_factory']->getEncoder($user);
                    $password = $encoder->encodePassword($request->get('password'), '');
                    file_put_contents(PASSWD_FILE, $password);
                    return $app['twig']->render('login.html.twig', array('create_success' => true, 'error' => false));
                } else {
                    $error = 'Could not save the password. Please make sure your server can write the directory (<code>/app/config/secure/</code>).';
                }
Example #8
0
$app['debug'] = true;
//
// Twig
//
$app->register(new TwigServiceProvider(), array('twig.path' => __DIR__ . '/templates', 'twig.options' => array('cache' => __DIR__ . '/../cache/twig', 'debug' => $app['debug'], 'strict_variables' => true)));
//
// Translator
//
$app->register(new TranslationServiceProvider(), array('locale' => 'fr', 'locale_fallback' => 'fr'));
$app['translator'] = $app->share($app->extend('translator', function ($translator, $app) {
    $translator->addLoader('yaml', new YamlFileLoader());
    if (file_exists(__DIR__ . '/locales/messages.en.yml')) {
        $translator->addResource('yaml', __DIR__ . '/locales/messages.en.yml', 'en');
    }
    if (file_exists(__DIR__ . '/locales/messages.de.yml')) {
        $translator->addResource('yaml', __DIR__ . '/locales/messages.de.yml', 'de');
    }
    if (file_exists(__DIR__ . '/locales/messages.fr.yml')) {
        $translator->addResource('yaml', __DIR__ . '/locales/messages.fr.yml', 'fr');
    }
    return $translator;
}));
//
// Assetic
//
$app->register(new SilexAssetic\AsseticServiceProvider());
$app['assetic.path_to_web'] = __DIR__ . '/../web';
$app['assetic.options'] = array('auto_dump_assets' => true);
$app['assetic.filter_manager'] = $app->share($app->extend('assetic.filter_manager', function ($fm, $app) {
    $node = getenv('NODE_BIN_PATH') === false ? '/usr/bin/js' : getenv('NODE_BIN_PATH');
    $fm->set('less', new Assetic\Filter\LessFilter($node));
Example #9
0
$app->before(function (Symfony\Component\HttpFoundation\Request $request, $app) {
    if (!isset($app['base_url'])) {
        $app['base_url'] = rtrim($request->getSchemeAndHttpHost() . $request->getBaseUrl(), '/');
    }
    if (strpos($request->headers->get('Content-Type'), 'application/json') === 0) {
        $data = json_decode($request->getContent(), true);
        $request->request->replace(is_array($data) ? $data : array());
    }
});
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__));
$app->register(new Silex\Provider\ServiceControllerServiceProvider());
$app->register(new Shop\Database\DatabaseServiceProvider());
$app['illuminate.capsule']->bootEloquent();
$app['illuminate.capsule']->setAsGlobal();
$app['db.controller'] = $app->share(function () use($app) {
    return new Shop\Database\DBController($app, new \Shop\Database\Schema());
});
$app['db.controller']->createDB();
$app['home.controller'] = $app->share(function () use($app) {
    return new Shop\Home\HomeController($app);
});
$app['products.controller'] = $app->share(function () use($app) {
    return new Shop\Products\ProductsController($app, $app['request'], new Shop\Products\ProductModel());
});
$app->get('/', 'home.controller:index');
$app->get('/products', 'products.controller:index');
$app->put('/products/{id}', 'products.controller:update');
$app->post('/products', 'products.controller:insert');
$app->delete('/products/{id}', 'products.controller:delete');
$app->post('/admin', function () use($app) {
    $admin = (require_once $app['base_dir'] . '/backend/config/admin.php');
Example #10
0
define('ROOT', dirname(__DIR__));
#chamada do autoloader
$loader = (require ROOT . "/vendor/autoload.php");
#Cria instancia objeto app Silex
$app = new Silex\Application();
#Registra o objeto para criação de URL
$app->register(new UrlGeneratorServiceProvider());
#Configuração do dot env
$app['env'] = (new \Dotenv\Dotenv(dirname(__DIR__)))->load();
#ativa o debug
$app['debug'] = getenv('debug');
#cache
$app->register(new Silex\Provider\HttpCacheServiceProvider(), ['http_cache.cache_dir' => ROOT . '/storage/temp/http']);
# autoloader
$app['autoloader'] = $app->share(function () use($loader) {
    return $loader;
});
# Adiciona ao autoloader a chamada
$app['autoloader']->add("app", ROOT);
#Registra a pasta de layout do sistema
require_once ROOT . '/config/twig.php';
//Configuração da base de dados
require_once ROOT . '/config/monolog.php';
//Configuração da base de dados
require_once ROOT . '/config/database.php';
$app->register(new \Silex\Provider\ServiceControllerServiceProvider());
$app->register(new \Silex\Provider\UrlGeneratorServiceProvider());
$app->register(new Silex\Provider\SessionServiceProvider());
#Chamada de arquivos necessarios
require_once __DIR__ . '/services/services.php';
require_once 'routes.php';
Example #11
0
use Propilex\Hateoas\TransExpressionFunction;
use Propilex\Hateoas\VndErrorRepresentation;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Mapping\ClassMetadataFactory;
use Symfony\Component\Validator\Mapping\Loader\YamlFileLoader;
$app = new Silex\Application();
// Providers
$app->register(new Silex\Provider\ValidatorServiceProvider());
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app->register(new Propel\Silex\PropelServiceProvider(), array('propel.config_file' => __DIR__ . '/config/propel/propilex.php', 'propel.model_path' => __DIR__ . '/../src/Propilex/Model'));
// Configure the validator service
$app['validator.mapping.class_metadata_factory'] = new ClassMetadataFactory(new YamlFileLoader(__DIR__ . '/config/validation.yml'));
// Configure Hateoas serializer
$app['serializer'] = $app->share(function () use($app) {
    $jmsSerializerBuilder = JMS\Serializer\SerializerBuilder::create()->setMetadataDirs(array('' => __DIR__ . '/config/serializer', 'Propilex' => __DIR__ . '/config/serializer'))->setDebug($app['debug'])->setCacheDir(__DIR__ . '/cache/serializer');
    return Hateoas\HateoasBuilder::create($jmsSerializerBuilder)->setMetadataDirs(array('' => __DIR__ . '/config/serializer', 'Propilex' => __DIR__ . '/config/serializer'))->setDebug($app['debug'])->setCacheDir(__DIR__ . '/cache/hateoas')->setUrlGenerator(null, new SymfonyUrlGenerator($app['url_generator']))->setUrlGenerator('templated', new SymfonyUrlGenerator($app['templated_uri_generator']))->setXmlSerializer(new XmlHalSerializer())->addConfigurationExtension(new CuriesConfigurationExtension($app['curies_route_name'], 'templated'))->setExpressionContextVariable('curies_prefix', $app['curies_prefix'])->registerExpressionFunction(new TransExpressionFunction($app['translator']))->build();
});
$app['hateoas.pagerfanta_factory'] = $app->share(function () use($app) {
    return new PagerfantaFactory();
});
// Translation
$app->register(new Silex\Provider\TranslationServiceProvider());
$app->before(function (Request $request) use($app) {
    $validatorFile = __DIR__ . '/../vendor/symfony/validator/Symfony/Component/Validator/Resources/translations/validators.%s.xlf';
    $locale = $request->attributes->get('_language', 'en');
    $app['translator']->setLocale($locale);
    $app['translator']->addLoader('xlf', new Symfony\Component\Translation\Loader\XliffFileLoader());
    $app['translator']->addResource('xlf', sprintf($validatorFile, $locale), $locale, 'validators');
    $messagesLocale = $locale;
    if (!is_file($messagesFile = __DIR__ . '/config/messages.' . $messagesLocale . '.yml')) {
        $messagesFile = sprintf(__DIR__ . '/config/messages.%s.yml', $app['translation.fallback']);
Example #12
0
use TimeBoard\Controller\PlanningController;
use TimeBoard\Controller\SecurityController;
use TimeBoard\Fixtures;
use TimeBoard\Manager\TimeBoardManager;
use TimeBoard\Manager\UserManager;
use TimeBoard\Repository\TimeBoardRepository;
use TimeBoard\Repository\UserRepository;
require_once __DIR__ . '/../vendor/autoload.php';
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\ServiceControllerServiceProvider());
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app->register(new Silex\Provider\SessionServiceProvider());
$app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => array('driver' => 'pdo_sqlite', 'path' => __DIR__ . '/../data/app.db')));
$app->register(new Silex\Provider\SecurityServiceProvider(), array('security.firewalls' => array('login_path' => array('pattern' => '^/login$', 'anonymous' => true), 'default' => array('pattern' => '^/.*$', 'anonymous' => true, 'form' => array('login_path' => '/login', 'check_path' => '/login_check'), 'logout' => array('logout_path' => '/logout'), 'users' => $app->share(function ($app) {
    return $app['UserManager'];
}))), 'security.access_rules' => array(array('^/login', 'IS_AUTHENTICATED_ANONYMOUSLY'), array('^/register', 'IS_AUTHENTICATED_ANONYMOUSLY'), array('^/setup', 'IS_AUTHENTICATED_ANONYMOUSLY'), array('^/', 'ROLE_USER'))));
$app['UserManager'] = $app->share(function () use($app) {
    return new UserManager($app['UserRepository'], $app);
});
$app['TimeBoardManager'] = $app->share(function () use($app) {
    return new TimeBoardManager($app['TimeBoardRepository']);
});
$app['UserRepository'] = $app->share(function () use($app) {
    return new UserRepository($app['db']);
});
$app['TimeBoardRepository'] = $app->share(function () use($app) {
    return new TimeBoardRepository($app['db'], $app['UserManager']);
});
$app['BaseController'] = $app->share(function () use($app) {
    return new BaseController($app['twig']);
Example #13
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->register(new Silex\Provider\SessionServiceProvider());
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app['oauth'] = $app->share(function () use($app) {
    // Base url, during development use the sanbdo
    $baseUrl = 'https://sandbox.evernote.com/';
    //$baseUrl = 'https://evernote.com/';
    $oauth = new Lemon\OAuthWrapper($baseUrl);
    $oauth->setConsumerKey('')->setConsumerSecret('')->setCallbackUrl($app['url_generator']->generate('callback', array(), true));
    return $oauth;
});
$app['evernote'] = $app->share(function () use($app) {
    $oauth = $app['session']->get('oauth');
    $evernote = new Lemon\Evernote($oauth['oauth_token'], $oauth['edam_noteStoreUrl']);
    return $evernote;
});
$app->get('/', function () use($app) {
    $oauth = $app['session']->get('oauth');
    if (empty($oauth)) {
        $notebooks = null;
    } else {
        $notebooks = $app['evernote']->listNotebooks();
        foreach ($notebooks as $key => $notebook) {
            $notebooks[$key] = (array) $notebook;
            $notebooks[$key]['notes'] = $app['evernote']->listNotes($notebook->guid);
        }
Example #14
0
 public function createApplication()
 {
     // Create a silex application
     $app = new Silex\Application();
     // Configure test environments
     $app['debug'] = true;
     $app['exception_handler']->disable();
     $app['session.test'] = true;
     // Add in phruts to organise your controllers
     $app->register(new Phruts\Provider\PhrutsServiceProvider(), array(Phruts\Util\Globals::ACTION_KERNEL_CONFIG => array('config' => __DIR__ . '/Resources/module1-config.xml', 'config/moduleA' => __DIR__ . '/Resources/module2-config.xml', 'config/moduleB' => __DIR__ . '/Resources/module2-config.xml,' . __DIR__ . '/Resources/module1-config.xml')));
     // Setup the mock file system for caching
     vfsStreamWrapper::register();
     vfsStreamWrapper::setRoot(new vfsStreamDirectory('cacheDir'));
     $app[Phruts\Util\Globals::MODULE_CONFIG_PROVIDER] = $app->share(function () use($app) {
         $provider = new FileCacheModuleProvider($app);
         $provider->setCachePath(vfsStream::url('cacheDir'));
         return $provider;
     });
     // Add a relevant html
     $app->get('{path}', function ($path) use($app) {
         return new \Symfony\Component\HttpFoundation\Response(file_get_contents(__DIR__ . '/Resources/' . $path));
     })->assert('path', '.+\\.html');
     // Add routes to be matched by Phruts
     $app->get('/my/{path}.do', function (Request $request) use($app) {
         return $app[Phruts\Util\Globals::ACTION_KERNEL]->handle($request, HttpKernelInterface::SUB_REQUEST, false);
     })->assert('path', '.*')->before(function (Request $request) {
         // Match a ".do" as context path
         $path = $request->attributes->get('path');
         if (!empty($path)) {
             $request->attributes->set(\Phruts\Action\RequestProcessor::INCLUDE_PATH_INFO, $path);
         }
     });
     // Add routes to be matched by Phruts
     $app->get('{path}', function (Request $request) use($app) {
         return $app[Phruts\Util\Globals::ACTION_KERNEL]->handle($request, HttpKernelInterface::SUB_REQUEST, false);
     })->assert('path', '.*')->value('path', '/')->before(function (Request $request) {
         $do = $request->get('do');
         if (!empty($do)) {
             $rewritePath = $request->attributes->get('_rewrite_path');
             // tmp var as attributes
             if (empty($rewritePath)) {
                 $request->attributes->set(\Phruts\Action\RequestProcessor::INCLUDE_PATH_INFO, $do);
                 $request->attributes->set('_rewrite_path', 1);
             } else {
                 $request->attributes->set(\Phruts\Action\RequestProcessor::INCLUDE_PATH_INFO, null);
             }
         }
     });
     return $app;
 }
Example #15
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
$app = new Silex\Application();
$config = array();
if (file_exists(__DIR__ . '/../config/config.php')) {
    require_once __DIR__ . '/../config/config.php';
}
$app['config'] = $config;
$app['config.dir'] = __DIR__ . '/../config';
$app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => $config['db']));
$app->register(new Silex\Provider\ServiceControllerServiceProvider());
if (isset($config['http_cache']) && $config['http_cache'] !== false) {
    $app->register(new Silex\Provider\HttpCacheServiceProvider(), array('http_cache.cache_dir' => __DIR__ . '/../cache/http', 'http_cache.esi' => null, 'http_cache.options' => isset($config['http_cache']) && is_array($config['http_cache']) ? $config['http_cache'] : array()));
}
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../templates', 'twig.options' => isset($config['twig']) ? $config['twig'] : array()));
// Set config as a global variable for templates.
$app['twig'] = $app->share($app->extend('twig', function ($twig, $app) use($config) {
    $twig->addGlobal('config', $config);
    return $twig;
}));
return $app;
Example #16
0
 public static function bootstrap()
 {
     $app = new \Silex\Application();
     $app['debug'] = true;
     $app['gamify_host'] = '127.0.0.1';
     $app['gamify_port'] = '8000';
     $app['em'] = $app->share(function ($app) {
         return (new EntityManagerFactory())->build($app['db']);
     });
     $app->register(new DoctrineServiceProvider(), array('db.options' => array('driver' => 'pdo_sqlite', 'path' => __DIR__ . '/../../../../../../db.sqlite')));
     $app['exchange_name'] = 'last-will';
     $app['tx_session'] = $app->share(function ($app) {
         return new DoctrineSession($app['em']);
     });
     $app['user_repository'] = $app->share(function ($app) {
         return $app['em']->getRepository('Lw\\Domain\\Model\\User\\User');
     });
     $app['wish_repository'] = $app->share(function ($app) {
         return $app['em']->getRepository('Lw\\Domain\\Model\\Wish\\Wish');
     });
     $app['event_store'] = $app->share(function ($app) {
         return $app['em']->getRepository('Ddd\\Domain\\Event\\StoredEvent');
     });
     $app['message_tracker'] = $app->share(function ($app) {
         return $app['em']->getRepository('Ddd\\Domain\\Event\\PublishedMessage');
     });
     $app['message_producer'] = $app->share(function () {
         return new RabbitMqMessageProducer(new AMQPStreamConnection('localhost', 5672, 'guest', 'guest'));
     });
     $app['user_factory'] = $app->share(function () {
         return new DoctrineUserFactory();
     });
     $app['view_wishes_application_service'] = $app->share(function ($app) {
         return new ViewWishesService($app['wish_repository']);
     });
     $app['view_wish_application_service'] = $app->share(function ($app) {
         return new ViewWishService($app['user_repository'], $app['wish_repository']);
     });
     $app['add_wish_application_service'] = $app->share(function ($app) {
         return new TransactionalApplicationService(new AddWishService($app['user_repository'], $app['wish_repository']), $app['tx_session']);
     });
     $app['add_wish_application_service_aggregate_version'] = $app->share(function ($app) {
         return new TransactionalApplicationService(new AddWishServiceAggregateVersion($app['user_repository']), $app['tx_session']);
     });
     $app['update_wish_application_service'] = $app->share(function ($app) {
         return new TransactionalApplicationService(new UpdateWishService($app['user_repository'], $app['wish_repository']), $app['tx_session']);
     });
     $app['update_wish_application_service_aggregate_version'] = $app->share(function ($app) {
         return new TransactionalApplicationService(new UpdateWishServiceAggregateVersion($app['user_repository']), $app['tx_session']);
     });
     $app['delete_wish_application_service'] = $app->share(function ($app) {
         return new TransactionalApplicationService(new DeleteWishService($app['user_repository'], $app['wish_repository']), $app['tx_session']);
     });
     $app['delete_wish_application_service_aggregate_version'] = $app->share(function ($app) {
         return new TransactionalApplicationService(new DeleterWishServiceAggregateVersion($app['user_repository']), $app['tx_session']);
     });
     $app['sign_in_user_application_service'] = $app->share(function ($app) {
         return new TransactionalApplicationService(new SignUpUserService($app['user_repository'], new UserDtoDataTransformer()), $app['tx_session']);
     });
     $app['gamify_guzzle_client'] = $app->share(function ($app) {
         return new Client(['base_uri' => sprintf('http://%s:%d/api/', $app['gamify_host'], $app['gamify_port'])]);
     });
     $app['http_user_adapter'] = $app->share(function ($app) {
         return new HttpUserAdapter($app['gamify_guzzle_client']);
     });
     $app['user_adapter'] = $app->share(function ($app) {
         return $app['http_user_adapter'];
     });
     $app['translating_user_service'] = $app->share(function ($app) {
         return new TranslatingUserService($app['user_adapter']);
     });
     $app['view_badges_application_service'] = $app->share(function ($app) {
         return new ViewBadgesService($app['translating_user_service']);
     });
     $app->register(new \Silex\Provider\SessionServiceProvider());
     $app->register(new \Silex\Provider\UrlGeneratorServiceProvider());
     $app->register(new \Silex\Provider\FormServiceProvider());
     $app->register(new \Silex\Provider\TranslationServiceProvider());
     $app->register(new MonologServiceProvider(), ['monolog.logfile' => __DIR__ . '/var/logs/silex_' . ($app['debug'] ? 'dev' : 'prod') . '.log', 'monolog.name' => 'last_whises']);
     $app->register(new TwigServiceProvider(), array('twig.path' => __DIR__ . '/../../Twig/Views'));
     $app->register(new Provider\HttpFragmentServiceProvider());
     $app->register(new Provider\ServiceControllerServiceProvider());
     $app->register(new Provider\WebProfilerServiceProvider(), array('profiler.cache_dir' => __DIR__ . '/../cache/profiler', 'profiler.mount_prefix' => '/_profiler'));
     $app->register(new \Sorien\Provider\DoctrineProfilerServiceProvider());
     $app['sign_up_form'] = $app->share(function ($app) {
         return $app['form.factory']->createBuilder('form', null, ['attr' => ['autocomplete' => 'off']])->add('email', 'email', ['attr' => ['maxlength' => User::MAX_LENGTH_EMAIL, 'class' => 'form-control'], 'label' => 'Email'])->add('password', 'password', ['attr' => ['maxlength' => User::MAX_LENGTH_PASSWORD, 'class' => 'form-control'], 'label' => 'Password'])->add('submit', 'submit', ['attr' => ['class' => 'btn btn-primary btn-lg btn-block'], 'label' => 'Sign up'])->getForm();
     });
     $app['sign_in_form'] = $app->share(function ($app) {
         return $app['form.factory']->createBuilder('form', null, ['attr' => ['autocomplete' => 'off']])->add('email', 'email', ['attr' => ['maxlength' => User::MAX_LENGTH_EMAIL, 'class' => 'form-control'], 'label' => 'Email'])->add('password', 'password', ['attr' => ['maxlength' => User::MAX_LENGTH_PASSWORD, 'class' => 'form-control'], 'label' => 'Password'])->add('submit', 'submit', ['attr' => ['class' => 'btn btn-primary btn-lg btn-block'], 'label' => 'Sign in'])->getForm();
     });
     return $app;
 }
Example #17
0
$app = new Silex\Application();
/**
 * Services 
 */
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => __DIR__ . '/logs/application.log'));
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
//$app->register(new ImagineServiceProvider());
$app->register(new FilesystemServiceProvider());
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/views'));
// Configuration
$app->register(new Igorw\Silex\ConfigServiceProvider(__DIR__ . "/config/config.json"));
// FlySystem
$app->register(new WyriHaximus\SliFly\FlysystemServiceProvider(), ['flysystem.filesystems' => ['local' => ['adapter' => 'League\\Flysystem\\Adapter\\Local', 'args' => [$app['base_path']]], 'thumbs' => ['adapter' => 'League\\Flysystem\\Adapter\\Local', 'args' => [__DIR__ . '/web/thumbs']]]]);
// Command service
$app['system_service'] = $app->share(function ($app) {
    return new \piTitle\SystemService($app['flysystems']['local']);
});
// Command service
$app['command_service'] = $app->share(function ($app) {
    return new \piTitle\CommandService($app['framebuffer']);
});
$app['monolog']->addInfo("Services & providers loaded !");
// Actions
$app->get('/', 'piTitle\\Controller\\AppController::indexAction')->bind("homepage");
$app->get('/checkfbi', 'piTitle\\Controller\\AppController::checkAction')->bind('checkfbi');
$app->get('/thumbnail', 'piTitle\\Controller\\AppController::thumbAction')->bind('thumbnail');
$app->post('/publish', 'piTitle\\Controller\\AppController::publishAction')->bind("publish");
// Thumbnails
/*
$app->get('/thumb/{width}/{height}/{subfolder}/{filename}',
    function(Silex\Application $app, $width, $height, $subfolder, $filename) {
<?php

require_once __DIR__ . '/../vendor/autoload.php';
$app = new Silex\Application();
$app['guzzle'] = $app->share(function () {
    return new \GuzzleHttp\Client();
});
$app['my_client'] = $app->share(function () use($app) {
    return new \Devhelp\Piwik\Api\Guzzle\Client\PiwikGuzzleClient($app['guzzle']);
});
$app['my_piwik_method'] = $app->share(function () use($app) {
    return $app['devhelp_piwik.api']->getMethod('Actions.get');
});
$app->register(new \Devhelp\Silex\Piwik\PiwikApiServiceProvider(['client' => 'my_client', 'api' => ['reader' => ['url' => 'http://demo.piwik.org', 'default_params' => ['idSite' => 7, 'period' => 'day', 'date' => 'yesterday', 'format' => 'json', 'token_auth' => 'anonymous']]]]));
$app->get('/demo/method-call', function () use($app) {
    return $app['my_piwik_method']->call([])->getBody()->getContents();
});
Example #19
0
require_once __DIR__ . '/../vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Pinboard\Logger\DbalLogger;
use Pinboard\Stopwatch\Stopwatch;
$app = new Silex\Application();
$app['params'] = Symfony\Component\Yaml\Yaml::parse(file_get_contents(__DIR__ . '/../config/parameters.yml'));
$app->register(new Silex\Provider\SessionServiceProvider());
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
    if (!isset($app['params']['base_url']) || empty($app['params']['base_url'])) {
        $baseUrl = '/';
    } else {
        $baseUrl = $app['params']['base_url'];
    }
    if (substr($baseUrl, -1) != '/') {
        $baseUrl .= '/';
    }
    $twig->addGlobal('base_url', $baseUrl);
    return $twig;
}));
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$dbOptions = array('driver' => 'pdo_mysql', 'dbname' => $app['params']['db']['name'], 'host' => $app['params']['db']['host'], 'user' => $app['params']['db']['user'], 'password' => $app['params']['db']['pass']);
if (isset($app['params']['db']['port'])) {
    $dbOptions['port'] = $app['params']['db']['port'];
}
if (isset($app['params']['db']['unix_socket'])) {
    $dbOptions['unix_socket'] = $app['params']['db']['unix_socket'];
}
$app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => $dbOptions));
$app['dbs.config']['default']->setSQLLogger(new DbalLogger(new Stopwatch(), $app['params']['db']['host']));
Example #20
0
            echo "<h1>Error creating SQLite Database!</h1>";
            echo "Could not run 'php vendor/doctrine/orm/bin/doctrine.php orm:schema-tool:create'.<br><br>";
            echo "Please ensure that the php executable is in your PATH and refresh the page or run the command above manually!";
        } else {
            header('Refresh:0');
        }
        exit;
    }
}
/* i18n support */
$app->register(new Silex\Provider\TranslationServiceProvider());
$app['locales'] = $app->share(function () use($app) {
    // Read available locales
    $localeFiles = glob(__DIR__ . '/resources/i18n/*.php');
    $locales = array();
    foreach ($localeFiles as $file) {
        $locale = basename($file, ".php");
        $locales[$locale] = $file;
    }
    return $locales;
});
$app['translator'] = $app->share($app->extend('translator', function ($translator, $app) {
    foreach ($app['locales'] as $locale => $file) {
        $translator->addResource('array', require $file, $locale);
    }
    return $translator;
}));
$app['twig']->addExtension(new Symfony\Bridge\Twig\Extension\TranslationExtension($app['translator']));
/* Dependency Injection wiring */
$app['service.messages'] = $app->share(function () use($app) {
    return new Start\Service\Impl\MessageServiceImpl($app['orm.em']);
});
Example #21
0
use App\Controller\ArticlesController;
use App\Controller\ArticleAddController;
use Igorw\Silex\ConfigServiceProvider;
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../app/views', 'twig.class_path' => __DIR__ . '/../vendor/twig/lib'));
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app->register(new Silex\Provider\ServiceControllerServiceProvider());
$app->register(new Silex\Provider\FormServiceProvider());
$app->register(new Silex\Provider\TranslationServiceProvider());
$app->register(new Silex\Provider\SessionServiceProvider());
$app->register(new Silex\Provider\ValidatorServiceProvider());
$app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => $db_config));
$app->register(new ConfigServiceProvider(__DIR__ . "/../app/config/routes.yml"));
foreach ($app["config.routes"] as $name => $route) {
    $app->match($route["path"], $route["defaults"]["_controller"])->bind($name)->method(isset($route["methods"]) ? $route["methods"] : "GET");
}
$app['controller.home'] = $app->share(function () use($app) {
    return new HomeController($app);
});
$app['controller.categories'] = $app->share(function () use($app) {
    return new CategoriesController($app);
});
$app['controller.categoryAdd'] = $app->share(function () use($app) {
    return new CategoryAdd($app);
});
$app['controller.articles'] = $app->share(function () use($app) {
    return new ArticlesController($app);
});
$app['controller.articleAdd'] = $app->share(function () use($app) {
    return new ArticleAddController($app);
});
$app->run();
Example #22
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Symfony\Component\HttpFoundation\Response;
$app = new Silex\Application();
$app->register(new Silex\Provider\DoctrineServiceProvider());
$app->register(new Silex\Provider\FormServiceProvider());
$app->register(new Silex\Provider\TwigServiceProvider());
$app->register(new Silex\Provider\ValidatorServiceProvider());
$app->register(new Silex\Provider\TranslationServiceProvider());
$app->register(new Silex\Provider\MonologServiceProvider());
$app->register(new Silex\Provider\SessionServiceProvider());
$app['storage'] = $app->share(function () use($app) {
    return new Paste\Storage\Storage($app['db'], $app['monolog']);
});
$configReplacements = array('pwd' => __DIR__ . '/../');
$env = getenv('APP_ENV') ?: 'prod';
$app->register(new Igorw\Silex\ConfigServiceProvider(__DIR__ . "/../config/{$env}.json.dist", $configReplacements));
$app->register(new Igorw\Silex\ConfigServiceProvider(__DIR__ . "/../config/{$env}.json", $configReplacements));
$app['twig']->addGlobal('title', $app['pastebin.title']);
$app['twig']->addGlobal('theme', $app['pastebin.theme']);
$app->error(function (\Exception $ex, $code) use($app) {
    if ($code !== 404) {
        return;
    }
    $view = $app['twig']->render('error.html', array('error' => $ex->getMessage()));
    return new Response($view, $code);
});
return $app;
Example #23
0
<?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\ParameterBag;
$app = new Silex\Application();
// Create the Silex application, in which all configuration is going to go
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app['debug'] = true;
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../templates'));
$app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
    $twig->addFunction(new \Twig_SimpleFunction('asset', function ($asset) use($app) {
        return sprintf('%s/%s', trim($app['request']->getBasePath()), ltrim($asset, '/'));
        //return __DIR__.'/../assets';
    }));
    return $twig;
}));
$app->before(function (Request $request) {
    if (0 === strpos($request->headers->get('Content-Type'), 'application/json')) {
        $data = json_decode($request->getContent(), true);
        $request->request->replace(is_array($data) ? $data : array());
    }
});
return $app;
Example #24
0
$app->register(new FormExtension());
$app->register(new TranslationExtension(), array('translator.messages' => array()));
$app->register(new TwigExtension(), array('twig.path' => array(__DIR__ . '/templates', __DIR__ . '/../vendor/Symfony/Bridge/Twig/Resources/views/Form'), 'twig.class_path' => __DIR__ . '/../vendor/silex/vendor/twig/lib'));
$app->register(new DoctrineMongoDBExtension(), array('doctrine.odm.mongodb.connection_options' => array('database' => 'springbok-silex', 'host' => 'localhost'), 'doctrine.odm.mongodb.documents' => array(array('type' => 'annotation', 'path' => __DIR__ . '/Document', 'namespace' => 'Document')), 'doctrine.odm.mongodb.metadata_cache' => 'array', 'doctrine.common.class_path' => __DIR__ . '/../vendor/mongodb-odm/lib/vendor/doctrine-common/lib', 'doctrine.mongodb.class_path' => __DIR__ . '/../vendor/mongodb-odm/lib/vendor/doctrine-mongodb/lib', 'doctrine.odm.mongodb.class_path' => __DIR__ . '/../vendor/mongodb-odm/lib'));
$app['doctrine.odm.mongodb.hydrators_dir'] = __DIR__ . '/../cache/doctrine/hydrators';
Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver::registerAnnotationClasses();
require_once __DIR__ . '/config.php';
if (!is_dir($app['doctrine.odm.mongodb.hydrators_dir'])) {
    mkdir($app['doctrine.odm.mongodb.hydrators_dir'], 0777, true);
}
$app->before(function () use($app) {
    if (!isset($app['culin.entity'])) {
        throw new \RuntimeException('Configuration entry "culin.entity" is not set');
    }
    $app['repository'] = $app['doctrine.odm.mongodb.dm']->getRepository($app['culin.entity']);
    $app['query_builder'] = $app->share(function ($app) {
        return $app['doctrine.odm.mongodb.dm']->createQueryBuilder($app['culin.entity']);
    });
    $app['form'] = $app->share(function ($app) {
        return function ($entity = null) use($app) {
            return $app['form.factory']->create(new $app['culin.form'](), $entity);
        };
    });
    $app['twig']->addExtension(new CulinExtension($app));
    $app['twig']->addExtension(new \Twig_Extensions_Extension_Debug());
    $app['twig']->enableDebug();
});
$app->after(function () use($app) {
    $app['doctrine.odm.mongodb.dm']->flush();
});
return $app;
Example #25
0
<?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
define("APP_NAME", getenv('APP_NAME'));
define("APP_ENV", getenv('APP_ENV'));
define("BASE_DIR", __DIR__ . '/../');
\date_default_timezone_set('America/Los_Angeles');
include BASE_DIR . 'vendor/autoload.php';
$app = new Silex\Application();
if (in_array(APP_ENV, array('dev', 'staging'))) {
    $app['debug'] = true;
}
$app->register(new Silex\Provider\DoctrineServiceProvider(), ['db.options' => include sprintf('%s/src/Config/credentials.%s.php', BASE_DIR, APP_NAME)]);
$app['guzzle'] = $app->share(function () use($app) {
    return new Guzzle\Http\Client();
});
$app->register(new Silex\Provider\ServiceControllerServiceProvider());
$app->register(new Silex\Provider\ValidatorServiceProvider());
$app['home'] = $app->share(function () use($app) {
    return new Controllers\Home();
});
$app['versions'] = $app->share(function () use($app) {
    $versions = new Models\Versions($app['db']);
    return new Controllers\Versions($versions);
});
$app->before(function (Request $request, Silex\Application $app) {
    if (extension_loaded('newrelic')) {
        newrelic_name_transaction(current(explode('?', $_SERVER['REQUEST_URI'])));
    }
});
Example #26
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
$app = new Silex\Application();
$app['api-keys'] = $app->share(function () {
    $parser = new Symfony\Component\Yaml\Parser();
    return $parser->parse(file_get_contents(__DIR__ . '/../config/api-keys.yml'));
});
$app['config'] = $app->share(function () {
    $parser = new Symfony\Component\Yaml\Parser();
    return $parser->parse(file_get_contents(__DIR__ . '/../config/config.yml'));
});
return $app;
Example #27
0
<?php

require_once __DIR__ . '/vendor/autoload.php';
require_once 'CaptchaClass.php';
require_once 'CaptchaController.php';
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\ServiceControllerServiceProvider());
$app['captcha.controller'] = $app->share(function () use($app) {
    return new CaptchaController(new Randomizer());
});
$app->get('/', function () {
    return "";
});
$app->get('/captcha', 'captcha.controller:buildCaptcha');
$app->run();
Example #28
0
<?php

use Cocur\Slugify\Bridge\Twig\SlugifyExtension;
use Cocur\Slugify\Slugify;
require_once __DIR__ . '/../vendor/autoload.php';
$app = new Silex\Application();
// Data sources
$app['import_url'] = "http://www.letour.fr/le-tour/2015/fr/300/classement/bloc-classement-page/ITG.html";
// Locale
Locale::setDefault('fr-FR');
// Debug enabled
$app['debug'] = true;
// Url helpers
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
// Cache support
$app->register(new Silex\Provider\HttpCacheServiceProvider(), array('http_cache.cache_dir' => __DIR__ . '/../cache/'));
// Doctrine support
$app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => array('driver' => 'pdo_sqlite', 'path' => __DIR__ . '/../data/tdfbdc.db')));
// Twig support
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
    $twig->addExtension(new Twig_Extensions_Extension_Intl());
    $twig->addExtension(new SlugifyExtension(Slugify::create()));
    return $twig;
}));
// Controllers
require_once __DIR__ . "/controllers.php";
// Go !
$app->run();
Example #29
0
// Accept and decode JSON data before the call to controllers
$app->before(function (Request $request) {
    if (0 === strpos($request->headers->get('Content-Type'), 'application/json')) {
        $data = json_decode($request->getContent(), true);
        $request->request->replace(is_array($data) ? $data : array());
    }
});
// Add correct headers before it is sent to the client
$app->after(function (Request $request, Response $response) {
    $response->headers->set("Access-Control-Allow-Origin", "*");
    $response->headers->set("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
});
$app->register(new ServiceControllerServiceProvider());
$connection = new RestApp\Service\PDOConnection($app);
$app['todo.repo'] = $app->share(function () use($connection) {
    return new RestApp\Repository\TodoRepository($connection);
});
$app['todo.controller'] = $app->share(function () use($app) {
    return new RestApp\Controller\TodoController($app['todo.repo']);
});
$app['converter.user'] = $app->share(function () use($app) {
    return new RestApp\Service\UserAuthentication($app['api.validtoken']);
});
$api = $app["controllers_factory"];
$api->get('/todo/get', "todo.controller:getAllTodo")->convert('token', 'converter.user:authorize');
$api->post('/todo/save', "todo.controller:saveTodo")->convert('token', 'converter.user:authorize');
$api->put('/todo/update', "todo.controller:updateTodo")->convert('token', 'converter.user:authorize');
$api->delete('/todo/delete', "todo.controller:deleteTodo")->convert('token', 'converter.user:authorize');
$app->mount($app["api.endpoint"] . '/' . $app["api.version"] . '/{token}', $api);
// Proper way to handler error in app
$app->error(function (\Exception $e, $code) use($app) {
Example #30
0
<?php

$loader = (include 'vendor/autoload.php');
$loader->add('', 'src');
$app = new Silex\Application();
// App configuration
$app['config'] = (require 'config.php');
// Model
$app['model'] = $app->share(function () use($app) {
    return new Model($app['config']['database']);
});
// Enabling debug
$app['debug'] = true;
// TWIG services
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/views'));
// Sessions
$app->register(new Silex\Provider\SessionServiceProvider());
// Loading controllers
include 'controllers.php';
return $app;