Exemplo n.º 1
0
 /**
  * Bootstrap the Silex application by registering all providers and
  * services and returning a pre-configured Silex Application object.
  *
  */
 public static function bootstrap()
 {
     // front controller
     $app = new \Silex\Application();
     //$app['debug'] = true;
     //declare app globals
     $app['userName'] = null;
     $app['posterID'] = null;
     $app['sqlInsertMessage'] = "INSERT INTO messageboard (posterID, content) VALUES (?, ?)";
     $app['sqlInsertUser'] = "******";
     $app['sqlListMessageBoard'] = "Select mbID, userName, Content, postTS from messageboard mb\n\t\t\t\t\t\t\t\t\t\tjoin users u on mb.posterID = u.UserID order by mbID desc";
     $app['sqlGetMaxID'] = "Select Max(userID) as uid from users where userName = ?";
     $app['sqlCreateDB'] = "CREATE DATABASE IF NOT EXISTS sqlando;";
     $app['sqlCreateTableMessageBoard'] = "use sqlando;\n\t\t\tCREATE TABLE IF NOT EXISTS `messageboard` (\n\t\t\t`mbID` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t`posterID` int(11) NOT NULL,\n\t\t\t`Content` varchar(140) NOT NULL,\n\t\t\t`postTS` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n\t\t\tPRIMARY KEY (`mbID`),\n\t\t\tUNIQUE KEY `mbID` (`mbID`)\n\t\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
     $app['sqlCreateTableUsers'] = "use sqlando;\n\t\t\tCREATE TABLE IF NOT EXISTS `users` (\n\t\t\t`userID` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t`userName` varchar(250) NOT NULL,\n\t\t\t`loginTS` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n\t\t\tPRIMARY KEY (`userID`),\n\t\t\tUNIQUE KEY `userID` (`userID`)\n\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
     // set up the db provider
     $app->register(new \Silex\Provider\DoctrineServiceProvider(), array('dbs.options' => array('mysql_dts' => array('dbhost' => 'localhost', 'dbname' => 'sqlando', 'user' => 'localUser'), 'mysql_createDB' => array('dbhost' => 'localhost', 'user' => 'localUser'))));
     // ## Register Official Silex Providers ##
     // Twig provider for templating
     // twig.path is /views and autoescape ought to be on
     $app->register(new \Silex\Provider\TwigServiceProvider(), array('twig.path' => 'views', 'twig.autoescape' => true));
     // session provider to handle user sessions
     $app->register(new \Silex\Provider\SessionServiceProvider());
     return $app;
 }
Exemplo n.º 2
0
 public static function bootstrap()
 {
     $app = new \Silex\Application();
     $app['debug'] = true;
     $app['em'] = $app->share(function () {
         return (new EntityManagerFactory())->build();
     });
     $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 AMQPConnection('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['update_wish_application_service'] = $app->share(function ($app) {
         return new TransactionalApplicationService(new UpdateWishService($app['user_repository'], $app['wish_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['sign_in_user_application_service'] = $app->share(function ($app) {
         return new TransactionalApplicationService(new SignInUserService($app['user_repository']), $app['tx_session']);
     });
     $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 \Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../../Twig/Views'));
     $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();
     });
     $app['log_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' => 'Log in'])->getForm();
     });
     return $app;
 }
function getApp()
{
    $app = new \Silex\Application();
    $app["debug"] = TRUE;
    $app->register(new ConsoleServiceProvider());
    $app->register(new DoctrineORMServiceProvider(), array("orm.connection" => array('driver' => "pdo_sqlite", 'path' => ROOT_TEST_DIR . '/database.sqlite'), "orm.driver.configs" => array("default" => array("namespace" => "Entity", "type" => "yaml", "paths" => array(ROOT_TEST_DIR . '/doctrine')))));
    return $app;
}
 static function getApp()
 {
     $app = new \Silex\Application();
     $app["debug"] = TRUE;
     $app["session.test"] = 1;
     $app->register(new ConsoleServiceProvider());
     $app->register(new DoctrineODMMongoDBServiceProvider(), array("odm.connection.server" => getenv('ODM_MONGODB_TEST_CONNECTION_STRING'), "odm.connection.dbname" => getenv('ODM_MONGODB_TEST_DATABASE_NAME'), "odm.connection.options" => array('connect' => TRUE), "odm.proxy_dir" => __DIR__ . "/Proxy", "odm.driver.configs" => array("default" => array("namespace" => "Entity", "path" => __DIR__ . "/Entity", "type" => "annotations"))));
     return $app;
 }
 public function createApplication()
 {
     $app = new \Silex\Application(['debug' => true]);
     $app->register(new ParamConverterProvider());
     $app->register(new SessionServiceProvider(), ['session.test' => true]);
     $app->register(new SecurityServiceProvider(), ['security.firewalls' => ['unsecured' => ['anonymous' => true]]]);
     $app->register(new FormServiceProvider());
     return $app;
 }
Exemplo n.º 6
0
 public function createApplication()
 {
     $app = new \Silex\Application();
     $app->register(new \Silex\Provider\FormServiceProvider());
     $app->register(new \Eccube\ServiceProvider\ValidatorServiceProvider());
     // 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 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();
 }
Exemplo n.º 8
0
 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();
 }
Exemplo n.º 9
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());
 }
 /**
  * Test Register Finder
  *
  * @param integer $n Umpteenth Number
  *
  * @return void
  *
  * @dataProvider providerTestUmpteenth
  */
 public function testIntegratorSuccess($n)
 {
     $path = realpath(__DIR__ . "/../resources/") . "/";
     $oldFinder = new Symfony\Component\Finder\Finder();
     $app = new Silex\Application();
     $app->register(new \NachoNerd\Silex\Finder\Provider());
     $app->boot();
     $app['nn.finder']->sortByModifiedTimeDesc()->in($path);
     $newFinder = $app['nn.finder']->getNFirst($n);
     $filesNewWay = array();
     foreach ($newFinder as $files) {
         $filesNewWay[] = $files;
     }
     $oldFinder->sort(function ($a, $b) {
         return $b->getMTime() - $a->getMTime();
     })->in($path);
     $filesOldWay = array();
     $j = 0;
     foreach ($oldFinder as $files) {
         if ($j == $n) {
             break;
         }
         $j++;
         $filesOldWay[] = $files;
     }
     $this->assertEquals($filesOldWay, $filesNewWay);
 }
 /**
  * Test Boot Finder
  *
  * @return void
  */
 public function testBootFinder()
 {
     $app = new Silex\Application();
     $app->register(new \NachoNerd\Silex\Finder\Provider());
     $app->boot();
     $this->assertInstanceOf('NachoNerd\\Silex\\Finder\\Extensions\\Finder', $app['nn.finder']);
 }
Exemplo n.º 12
0
 public function createApplication()
 {
     $app = new \Silex\Application();
     $app['debug'] = true;
     unset($app['exception_handler']);
     $app->register(new \Silex\Provider\TwigServiceProvider());
     return $app;
 }
Exemplo n.º 13
0
 protected function createApplication($noTwig = false, $noSm = false)
 {
     $app = new \Silex\Application();
     $this->mockGenerator->orphanize('__construct');
     $sm = new \mock\Swift_Mailer();
     $this->calling($sm)->send = function ($message = null) {
         return $message;
     };
     $app->register(new \Rad\Silex\MailerServiceProvider(), array('rad_mailer.from' => '*****@*****.**'));
     if (!$noTwig) {
         $app->register(new \Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../../template'));
     }
     if (!$noSm) {
         $app['mailer'] = $sm;
     }
     $app->boot();
     return $app;
 }
Exemplo n.º 14
0
 /**
  * @return \Silex\Application
  */
 public static function bootstrap(array $config = array())
 {
     $config += array('root_dir' => __DIR__ . '/..');
     $config += array('conf_file' => $config['root_dir'] . '/conf/config.yml');
     $app = new \Silex\Application();
     // Registers the configuration service provider so that developers can
     // configure the app through a config file.
     $app->register(new \Igorw\Silex\ConfigServiceProvider($config['conf_file'], array('root_dir' => $config['root_dir'])));
     // Optionally add the monolog service provider if the "monolog.logfile"
     // configuration option is set.
     if (isset($app['monolog.logfile'])) {
         $app->register(new \Silex\Provider\MonologServiceProvider());
     }
     // Register the index and service manager as a service so we can query
     // our Acquia Search indexes.
     $app->register(new \Acquia\Search\Proxy\Silex\AcquiaSearchIndexProvider());
     // Dispatch the "acquia.search.proxy.bootstrap" event so that developers
     // can hook into the bootstrap process and add their providers.
     $event = new Event\AppEvent($app);
     $app['dispatcher']->dispatch(AppEvents::BOOTSTRAP, $event);
     return $app;
 }
Exemplo n.º 15
0
<?php

define('DB_HOST', 'localhost');
define('DB_NAME', 'exercice-silex-zrihen-petit');
define('DB_USER', 'root');
define('DB_PASS', 'root');
try {
    $pdo = new PDO('mysql:dbname=' . DB_NAME . ';host=' . DB_HOST, DB_USER, DB_PASS);
    $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_NAMED);
} catch (PDOException $e) {
    die('error');
}
require_once __DIR__ . '/../vendor/autoload.php';
$app = new Silex\Application();
$app['debug'] = true;
// Twig
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/views'));
// Url Generator
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
include 'models/snippets.class.php';
$snippets_model = new Snippets_Model($pdo);
Exemplo n.º 16
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Task.php";
require_once __DIR__ . "/../src/Category.php";
//session_start();
//if (empty($_SESSION['list_of_tasks'])) {
//    $_SESSION['list_of_tasks'] = array();
//}
$app = new Silex\Application();
$server = 'mysql:host=localhost;dbname=to_do';
$username = '******';
$password = '******';
$DB = new PDO($server, $username, $password);
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get("/", function () use($app) {
    return $app['twig']->render('index.html.twig');
});
$app->get("/tasks", function () use($app) {
    return $app['twig']->render('tasks.html.twig', array('tasks' => Task::getAll()));
});
$app->get("/categories", function () use($app) {
    return $app['twig']->render('categories.html.twig', array('categories' => Category::getAll()));
});
$app->post("/tasks", function () use($app) {
    $task = new task($_POST['description']);
    $task->save();
    return $app['twig']->render('tasks.html.twig', array('tasks' => Task::getAll()));
});
$app->post("/delete_tasks", function () use($app) {
    Task::deleteAll();
Exemplo n.º 17
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => array('driver' => 'pdo_sqlite', 'path' => __DIR__ . '/../db/worldcup.db')));
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => array(__DIR__ . '/View')));
$app->get('/', function () use($app) {
    $eventDao = new \Mila\DAO\eventDAO($app['db']);
    return $app['twig']->render('index.twig', array('events' => $eventDao->fetchAll()));
});
$app->get('/event/{id}', function ($id) use($app) {
    $eventDao = new \Mila\DAO\eventDAO($app['db']);
    return $app['twig']->render('event.twig', array('event' => $eventDao->fetchById($id)));
});
$app->get('/hello/{name}', function ($name) use($app) {
    return $app['twig']->render('hello.twig', array('name' => $name));
});
$app->get('/teams', function () use($app) {
    $dao = new \Mila\DAO\teamDAO($app['db']);
    return $app['twig']->render('teams.twig', array('teams' => $dao->fetchAll()));
});
return $app;
Exemplo n.º 18
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\MarkdownExtension(), array('markdown.class_path' => __DIR__ . '/../vendor/knplabs-markdown', 'markdown.features' => array('header' => true, 'list' => true, 'horizontal_rule' => true, 'table' => true, 'foot_note' => true, 'fenced_code_block' => true, 'abbreviation' => true, 'definition_list' => true, 'inline_link' => true, 'reference_link' => true, 'shortcut_link' => true, 'block_quote' => true, 'code_block' => true, 'html_block' => true, 'auto_link' => true, 'auto_mailto' => true, 'entities' => false)));
$app->get('/', function () use($app) {
    return $app['twig']->render('markdown.twig');
});
$app->run();
Exemplo n.º 19
0
<?php

require_once 'bootstrap.php';
define('APP_ROOT', __DIR__);
define('APP_PATH', __DIR__ . '/app/');
define('CONFIG_FILE', APP_PATH . 'config/config.yml');
define('PASSWD_DIR', APP_PATH . 'config/secure');
define('PASSWD_FILE', PASSWD_DIR . '/passwd');
define('VENDOR_PATH', __DIR__ . '/vendor');
define('BASE_URL', (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['BASE']);
define('WEB_URL', BASE_URL . '/web');
$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 = "";
Exemplo n.º 20
0
<?php

require_once __DIR__ . '../../vendor/autoload.php';
require_once '../src/Guestbook/Helpers/Form.php';
require_once '../src/Guestbook/Helpers/ModelFactory.php';
require_once '../src/Guestbook/Models/GuestBookFileModel.php';
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), ['twig.path' => '../src/views']);
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app->register(new \Silex\Provider\FormServiceProvider());
$app->register(new Silex\Provider\TranslationServiceProvider(), ['translator.domains' => []]);
$app['debug'] = true;
/**
 * index Action
 */
$app->get('/symfony/', function () use($app) {
    $objModel = GuestBook\Helpers\ModelFactory::getGuestBookModel();
    return $app['twig']->render('index.html.twig', ['entries' => (array) $objModel->getAllEntries()]);
})->bind('home');
/**
 * add action
 */
$app->get('/symfony/add', function () use($app) {
    return $app['twig']->render('add.html.twig', ['form' => GuestBook\Helpers\Form::getGuestBookForm($app)->createView()]);
})->bind('add');
/**
* Save Action
*/
$app->post('/symfony/save', function () use($app) {
    $objModel = GuestBook\Helpers\ModelFactory::getGuestBookModel();
    $objFormBuilder = GuestBook\Helpers\Form::getGuestBookForm($app);
Exemplo n.º 21
0
<?php

require_once '../bootstrap.php';
define('APP_ROOT', realpath(__DIR__ . '/../'));
define('APP_PATH', APP_ROOT . '/app');
define('CONFIG_FILE', APP_PATH . '/config/config.yml');
define('PASSWD_DIR', APP_PATH . '/config/secure');
define('PASSWD_FILE', PASSWD_DIR . '/passwd');
define('VENDOR_PATH', APP_ROOT . '/vendor');
define('BASE_URL', (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http') . '://' . $_SERVER['SERVER_NAME'] . str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']));
$app = new Silex\Application();
$app['template_url'] = BASE_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(), ['twig.path' => APP_ROOT . '/views', 'twig.options' => ['debug' => $app['debug']]]);
$app->register(new Silex\Provider\SessionServiceProvider());
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app->register(new Silex\Provider\SecurityServiceProvider(), ['security.firewalls' => ['admin' => ['pattern' => '^/(logs|api)', 'form' => ['login_path' => '/login', 'check_path' => '/logs/login_check'], 'users' => ['user' => ['ROLE_USER', is_file(PASSWD_FILE) ? file_get_contents(PASSWD_FILE) : null]], 'logout' => ['logout_path' => '/logs/logout', 'invalidate_session' => true]]]]);
$app['security.encoder.digest'] = $app->share(function ($app) {
    return new \Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder(10);
});
if (!is_file(PASSWD_FILE)) {
    $app->mount('/', include 'guest.php');
} else {
    $app->mount('/api', include 'api.php');
Exemplo n.º 22
0
<?php

$app = new Silex\Application();
$app['debug'] = DEBUG;
Symfony\Component\Debug\ErrorHandler::register();
if ('cli' !== php_sapi_name()) {
    Symfony\Component\Debug\ExceptionHandler::register();
}
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => APP_DIR . '/../logs/app.error.log', 'monolog.level' => Monolog\Logger::ERROR));
$templateDir = APP_DIR . VIEWS_LOCATION;
$templatePaths = array($templateDir, $templateDir . '/templates', $templateDir . '/pages', $templateDir . '/error-pages');
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => $templatePaths, 'twig.options' => array('cache' => APP_DIR . 'cache')));
$app->register(new Silex\Provider\FormServiceProvider());
$app->register(new Silex\Provider\TranslationServiceProvider(), array('locale_fallbacks' => array('en')));
$app->register(new Silex\Provider\ValidatorServiceProvider());
$app->register(new Aws\Silex\AwsServiceProvider(), array('aws.config' => array('key' => AWS_USER_ACCESS_KEY, 'secret' => AWS_USER_SECRET_KEY, 'region' => 'eu-west-1')));
$app['twig']->addGlobal('publicAssetsLocation', PUBLIC_ASSETS_LOCATION);
Exemplo n.º 23
0
require_once __DIR__ . "/../vendor/autoload.php";
$app = new Silex\Application();
require_once __DIR__ . "/../resources/config.php";
// 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');
Exemplo n.º 24
0
<?php

/**
 * simple web app that returns info on a subnet through a JSON api
 *
 * @licence GPLv3
 * @author Lucas Bickel <*****@*****.**>
 */
require_once __DIR__ . '/../vendor/autoload.php';
$app = new Silex\Application();
#$app['debug'] = true;
$app['cache_ttl'] = 86400;
$app->register(new Silex\Provider\RoutingServiceProvider());
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../app/views'));
$app->register(new Silex\Provider\HttpCacheServiceProvider(), array('http_cache.cache_dir' => __DIR__ . '/../app/cache/', 'http_cache.options' => ['default_ttl' => $app['cache_ttl']]));
$app->get('/', function () use($app) {
    return $app['twig']->render('index.html.twig');
})->bind('home');
$app->get('/swagger.json', function () use($app) {
    return new Symfony\Component\HttpFoundation\Response($app['twig']->render('swagger.json.twig'), 200, ['Content-Type' => 'application/json']);
})->bind('swagger');
$app->get('/apis.json', function () use($app) {
    return new Symfony\Component\HttpFoundation\Response($app['twig']->render('apis.json.twig'), 200, ['Content-Type' => 'application/json']);
})->bind('apisjson');
$app->get('/subnet/{ip}/{mask}', function ($ip, $mask) use($app) {
    $subnet = $ip . '/' . $mask;
    try {
        $subnet_info = IPTools\Network::parse($subnet)->info;
        unset($subnet_info['class']);
    } catch (Exception $e) {
        $app->abort(400, $e->getMessage());
Exemplo n.º 25
0
<?php

require '../vendor/autoload.php';
$app = new Silex\Application();
$app['debug'] = true;
// Register the monolog logging service
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => 'php://stderr'));
// Register view rendering
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/views'));
// Our web handlers
$app->get('/', function () use($app) {
    $app['monolog']->addDebug('logging output.');
    return $app['twig']->render('index.twig');
});
$app->get('/page2', function () use($app) {
    $app['monolog']->addDebug('logging output.');
    return $app['twig']->render('page2.twig');
});
$app->run();
Exemplo n.º 26
0
<?php

// web/index.php
use Freshdesk\Config\Connection, Freshdesk\Ticket, Freshdesk\Model\Ticket as TicketM;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
require_once __DIR__ . '/../vendor/autoload.php';
$app = new Silex\Application();
$app->register(new Igorw\Silex\ConfigServiceProvider(__DIR__ . '/../config/config.php'));
/**
 * Merge webhook data into templated messages
 * @param $message
 * @param $data
 * @return string
 */
function buildMessage($message, $data)
{
    $params = ['conversionMessages' => $data['conversionMessages'], 'visitor_fullName' => $data['visitor']['fullName'], 'visitor_city' => $data['visitor']['city'], 'visitor_region' => $data['visitor']['region'], 'visitor_countryCode' => $data['visitor']['countryCode'], 'visitor_conversationBeginPage' => isset($data['visitor']['conversationBeginPage']) ? $data['visitor']['conversationBeginPage'] : '', 'visitor_phoneNumber' => isset($data['visitor']['phoneNumber']) ? $data['visitor']['phoneNumber'] : '', 'visitor_shopDomain' => isset($data['visitor']['customFields']['shopDomain']) ? $data['visitor']['customFields']['shopDomain'] : ''];
    $search = [];
    $replace = [];
    foreach ($params as $key => $value) {
        $search[] = '{{' . $key . '}}';
        $replace[] = $value;
    }
    return str_replace($search, $replace, $message);
}
$app->get('/', function () use($app) {
    return 'Setup olark webhook to this url';
});
$app->post('/', function (Request $request) use($app) {
    // Handle Olark webhook
Exemplo n.º 27
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
define('GOOGLE_API_KEY', '389361308386-0lc02qa6gs3q0pf7j86hhj169to93jh9.apps.googleusercontent.com');
define('GOOGLE_API_SECRET', 'nijEu5O05kXBLQv9pawzrF9Z');
$app = new Silex\Application();
error_reporting(E_ALL);
ini_set('display_errors', 1);
$app['debug'] = true;
$app->register(new Gigablah\Silex\OAuth\OAuthServiceProvider(), array('oauth.services' => array('Google' => array('key' => GOOGLE_API_KEY, 'secret' => GOOGLE_API_SECRET, 'scope' => array('https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile'), 'user_endpoint' => 'https://www.googleapis.com/oauth2/v1/userinfo'))));
// Provides URL generation
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
// Provides CSRF token generation
$app->register(new Silex\Provider\FormServiceProvider());
// Provides session storage
$app->register(new Silex\Provider\SessionServiceProvider(), array('session.storage.save_path' => __DIR__ . '/../cache'));
// Provides Twig template engine
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__));
$app->register(new Silex\Provider\SecurityServiceProvider(), array('security.firewalls' => array('default' => array('pattern' => '^/', 'anonymous' => true, 'oauth' => array('failure_path' => '/', 'with_csrf' => true), 'logout' => array('logout_path' => '/logout', 'with_csrf' => true), 'users' => new Gigablah\Silex\OAuth\Security\User\Provider\OAuthInMemoryUserProvider())), 'security.access_rules' => array(array('^/auth', 'ROLE_USER'))));
$app->before(function (Symfony\Component\HttpFoundation\Request $request) use($app) {
    $token = $app['security']->getToken();
    $app['user'] = null;
    if ($token && !$app['security.trust_resolver']->isAnonymous($token)) {
        $app['user'] = $token->getUser();
    }
});
$app->get('/', function () use($app) {
    return $app['twig']->render('index.twig', array('login_paths' => $app['oauth.login_paths'], 'logout_path' => $app['url_generator']->generate('logout', array('_csrf_token' => $app['oauth.csrf_token']('logout')))));
});
$app->match('/logout', function () {
})->bind('logout');
Exemplo n.º 28
0
<?php

use Igorw\Middleware\Stack;
use Symfony\Component\HttpFoundation\Request;
// Default configuration
require_once 'config.init.php';
// Actual configuration
require_once '/var/baztille-data/config/config.php';
// Require Silex
require_once $g_config['silex_autoload_location'];
require_once 'version.php';
$app = new Silex\Application();
$app['debug'] = false;
///////////////// Service routing /////////////////////////////
$app->get('/', function () use($app) {
    return file_get_contents('landing/index.html');
});
$app->get('/confirm', function () use($app) {
    return file_get_contents('landing/confirm.html');
});
$app->get('/thankyou', function () use($app) {
    return file_get_contents('landing/thankyou.html');
});
$app->get('/faq', function () use($app) {
    return file_get_contents('landing/faq.html');
});
$app->get('/template', function () use($app) {
    return file_get_contents('landing/elements.html');
});
$app->register(new Silex\Provider\SessionServiceProvider(), array('session.storage.options' => array('cookie_domain' => $g_config['app_domain'])));
$app->run();
Exemplo n.º 29
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
function app_path($path = '/')
{
    $rootDir = realpath(__DIR__ . '/..') . '/';
    return preg_replace('/\\/+/', '/', $rootDir . $path);
}
$app = new Silex\Application();
$app['console'] = function () {
    return new \Symfony\Component\Console\Application();
};
if (file_exists(app_path('.env'))) {
    $dotenv = new \Dotenv\Dotenv(app_path());
    $dotenv->load();
}
$serviceProviderClasses = (require_once __DIR__ . '/providers.php');
foreach ($serviceProviderClasses as $serviceProviderClass) {
    $app->register(new $serviceProviderClass());
}
return $app;
Exemplo n.º 30
0
Arquivo: api.php Projeto: bazylu/web
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
$app = new Silex\Application();
$app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => array('driver' => 'pdo_mysql', 'dbname' => 'super-crm', 'user' => 'root', 'password' => '', 'charset' => 'UTF8')));
$app['debug'] = true;
class DataProvider
{
    private $db;
    public function __construct($db)
    {
        $this->db = $db;
    }
    public function getRequestData()
    {
        return json_decode(file_get_contents('php://input'), true);
    }
    /*==========  Clients  ==========*/
    public function getClients()
    {
        $sql = "SELECT c.*, cs.name as sector_name, u.name as account_manager_name FROM clients as c LEFT JOIN company_sectors as cs ON c.sector_id = cs.id LEFT JOIN users as u ON c.account_manager_id = u.id";
        return $this->db->fetchAll($sql);
    }
    public function getClient($clientId)
    {
        $sql = "SELECT * FROM clients WHERE id = ?";
        return $this->db->fetchAssoc($sql, array((int) $clientId));
    }
    public function updateClient($clientId, $data)