コード例 #1
0
ファイル: index.php プロジェクト: madflow/cheesecake
<?php

require_once __DIR__ . '/../vendor/autoload.php';
$app = new Silex\Application();
$app->get('/', function () use($app) {
    return 'Home';
});
$app->get('/hello/{name}', function ($name) use($app) {
    return 'Hello ' . $app->escape($name);
});
$app->run();
コード例 #2
0
 * @link  https://gist.github.com/nfreear/ac98e809b574948a47ab
 * @link  https://twitter.com/alt_text_bot/status/594605860388757504
 * @link  https://twitter.com/dartshipping/status/594605713298620416
 *
 *  ~/.bashrc
 *  export COMPOSER_PROCESS_TIMEOUT=600
 */
require_once __DIR__ . '/env.php';
use Nfreear\Cloudsight\Cloudsight_Http_Client;
use Symfony\Component\HttpFoundation\Request;
$app = new Silex\Application();
$app['debug'] = getenv('CS_DEBUG');
/** Sanity check.
 */
$app->get('/hello/{name}', function ($name) use($app) {
    return 'Hello ' . $app->escape($name) . ' - ' . date('H:m:i');
});
/** HTML test page 'cs.html'
 *
 * @return object HTML response.
 */
$app->get('/cs{any}', function () use($app) {
    return $app->sendFile(__DIR__ . '/app-cs.html');
});
$app->get('/files/{path}', function ($path) use($app) {
    if (!file_exists(__DIR__ . '/' . $path)) {
        $app->abort(404);
    }
    if (!preg_match('/^[\\w\\-]+\\.(html|js|css|png)$/', $path)) {
        $app->abort(403);
        // Security!
コード例 #3
0
ファイル: index.php プロジェクト: ArchSirius/log2420-project
})->bind('admin_journals');
// Author dashboard
$app->get('/author', function () use($app) {
    return $app['twig']->render('author/dashboard.twig', array('role' => 'author'));
})->bind('author_dashboard');
// Author submissions
$app->get('/author/submissions', function () use($app) {
    return $app['twig']->render('author/submissions.twig', array('role' => 'author'));
})->bind('author_submissions');
// Author add new submissions
$app->get('/author/submissions/new', function () use($app) {
    return $app['twig']->render('author/newSubmission.twig', array('role' => 'author'));
})->bind('author_new_submission');
// Author submissions detail
$app->get('/author/submissions/{id}', function ($id) use($app) {
    return $app['twig']->render('submissionDetail.twig', array('role' => 'author', 'id' => $app->escape($id)));
})->bind('author_submission_detail');
// Editor home page
$app->get('/editor', function () use($app) {
    return $app['twig']->render('editor/dashboard.twig', array('role' => 'editor'));
})->bind('editor_dashboard');
// Editor unassigned submissions
$app->get('/editor/unassigned', function () use($app) {
    return $app['twig']->render('editor/unassigned.twig', array('role' => 'editor'));
})->bind('editor_unassigned');
// Editor submissions in review
$app->get('/editor/inreview', function () use($app) {
    return $app['twig']->render('editor/inreview.twig', array('role' => 'editor'));
})->bind('editor_inreview');
// Editor submissions in editing
$app->get('/editor/inediting', function () use($app) {
コード例 #4
0
ファイル: index.php プロジェクト: goshshitmailme/php
    throw new RuntimeException('Parameters file not found');
    die('Parameters file not fount');
}
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\ServiceControllerServiceProvider());
$app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => $parameters['db']));
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => $parameters['twig']['path']));
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app['post.controller'] = $app->share(function () use($app) {
    return new \Controller\PostController($app);
});
$app['admin.post.controller'] = $app->share(function () use($app) {
    return new \Controller\Admin\PostController($app);
});
$app->get('/', function () use($app) {
    return 'Welcome!';
});
$app->get('/hello/{username}', function ($username) use($app) {
    return 'Hello ' . $app->escape($username);
});
$app->get('/blog', 'post.controller:indexAction')->bind('post_index');
$app->get('/blog/{id}', 'post.controller:showAction')->assert('id', '[0-9]+')->bind('post_show');
//    ->method('GET');
$app->get('/admin/blog', 'admin.post.controller:indexAction')->bind('admin_post_index');
$app->get('/admin/edit/{id}', 'admin.post.controller:editAction')->assert('id', '[0-9]+')->bind('admin_post_edit')->method('GET|POST');
$app->post('/admin/blog/new/', 'admin.post.controller:newAction')->bind('admin_post_new')->method('GET|POST');
$app->run();
//Dependency injection and the art of services
コード例 #5
0
ファイル: main.php プロジェクト: pombredanne/oss-license-gen
<?php

require_once __DIR__ . '/vendor/autoload.php';
use Keep\OssGen\Generator\Generator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
function get_generator()
{
    return new Generator(realpath(dirname(__FILE__) . '/oss-sources'));
}
$app = new Silex\Application();
$app->get('/generate/{source}/{licenser}/{year}', function ($source, $licenser, $year) use($app) {
    return get_generator()->generate($app->escape($source), $app->escape($licenser), $app->escape($year));
});
$app->post('/generate/{source}', function (Request $request) use($app) {
    return get_generator()->generate($request->get('source'), $request->get('licenser'), $request->get('year'));
});
$app->run();
コード例 #6
0
<?php

//Allow PHP's built-in server to serve our static content in local dev:
if (php_sapi_name() === 'cli-server' && is_file(__DIR__ . '/static' . preg_replace('#(\\?.*)$#', '', $_SERVER['REQUEST_URI']))) {
    return false;
}
require 'vendor/autoload.php';
use Symfony\Component\HttpFoundation\Response;
$app = new \Silex\Application();
$app->get('/', function () use($app) {
    return $app->sendFile('static/index.html');
});
$app->get('/hello/{name}', function ($name) use($app) {
    return new Response("Hello, {$app->escape($name)}!");
});
// the .htaccess file should handle our static content in Production.
// PHP-5.4's local server can handle static content as well (see README)
// This alternate method for serving static files should not be needed:
//$app->get('/css/{filename}', function ($filename) use ($app){
//  if (!file_exists('static/css/' . $filename)) {
//    $app->abort(404);
//  }
//  return $app->sendFile('static/css/' . $filename, 200, array('Content-Type' => 'text/css'));
//});
$app->get('/parks', function () use($app) {
    $db_connection = getenv('OPENSHIFT_MONGODB_DB_URL') ? getenv('OPENSHIFT_MONGODB_DB_URL') . getenv('OPENSHIFT_APP_NAME') : "mongodb://localhost:27017/";
    $client = new MongoClient($db_connection);
    $db = $client->selectDB(getenv('OPENSHIFT_APP_NAME'));
    $parks = new MongoCollection($db, 'parks');
    $result = $parks->find();
    $response = "[";
コード例 #7
0
use Symfony\Component\Validator\Constraints as Assert;
$app = new Silex\Application();
$app->register(new FormServiceProvider());
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/views'));
$app->register(new Silex\Provider\ValidatorServiceProvider());
$app->register(new Silex\Provider\TranslationServiceProvider(), array('locale' => 'es', 'locale_fallbacks' => array('es')));
$app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => array('driver' => 'pdo_mysql', 'host' => 'localhost', 'dbname' => '', 'charset' => 'utf8', 'password' => '')));
$app->before(function () use($app) {
    $app['twig']->addGlobal('layout', $app['twig']->loadTemplate('layout.twig'));
});
$app->match('/', function (Request $request) use($app) {
    $form = $app['form.factory']->createBuilder('form')->add('nombre', 'text', array('constraints' => array(new Assert\NotBlank(), new Assert\Length(array('min' => 5))), 'attr' => array('class' => 'form-control')))->add('apellido', 'text', array('constraints' => array(new Assert\NotBlank(), new Assert\Length(array('min' => 5))), 'attr' => array('class' => 'form-control')))->add('fecha_nacimiento', 'text', array('constraints' => array(new Assert\NotBlank(), new Assert\Length(array('min' => 5))), 'attr' => array('class' => 'form-control date-picker')))->add('rut', 'text', array('constraints' => array(new Assert\NotBlank(), new Assert\Length(array('min' => 5))), 'attr' => array('class' => 'form-control')))->add('comuna', 'text', array('constraints' => array(new Assert\NotBlank(), new Assert\Length(array('min' => 5))), 'attr' => array('class' => 'form-control')))->add('telefono', 'text', array('constraints' => array(new Assert\NotBlank(), new Assert\Length(array('min' => 5))), 'attr' => array('class' => 'form-control')))->add('celular', 'text', array('constraints' => array(new Assert\NotBlank(), new Assert\Length(array('min' => 5))), 'attr' => array('class' => 'form-control')))->add('email', 'text', array('constraints' => new Assert\Email(), 'attr' => array('class' => 'form-control', 'placeholder' => '*****@*****.**')))->add('codigo', 'text', array('constraints' => array(new Assert\NotBlank(), new Assert\Length(array('min' => 5))), 'attr' => array('class' => 'form-control')))->add('tiempo_exp', 'text', array('constraints' => array(new Assert\NotBlank(), new Assert\Length(array('min' => 1))), 'attr' => array('class' => 'form-control numero')))->add('formacion_academica', 'text', array('constraints' => array(new Assert\NotBlank(), new Assert\Length(array('min' => 5))), 'attr' => array('class' => 'form-control')))->add('pretension_renta', 'text', array('constraints' => array(new Assert\NotBlank(), new Assert\Length(array('min' => 5))), 'attr' => array('class' => 'form-control numero')))->getForm();
    $form->handleRequest($request);
    if ($form->isValid()) {
        $data = $form->getData();
        $app['db']->insert('profesionales', array('nombre' => $app->escape($data['nombre']), 'apellido' => $app->escape($data['apellido']), 'fecha_nacimiento' => $app->escape($data['fecha_nacimiento']), 'rut' => $data['rut'], 'comuna' => $app->escape($data['comuna']), 'telefono' => $app->escape($data['telefono']), 'celular' => $app->escape($data['celular']), 'email' => $data['email'], 'codigo' => $app->escape($data['codigo']), 'tiempo_exp' => $app->escape($data['tiempo_exp']), 'formacion_academica' => $app->escape($data['formacion_academica']), 'pretension_renta' => $app->escape($data['pretension_renta']), 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")));
        return $app->redirect('success');
    }
    // display the form
    return $app['twig']->render('index.twig', array('form' => $form->createView()));
});
$app->get('/success', function () use($app) {
    $objPHPExcel = new PHPExcel();
    $estiloTituloReporte = array('font' => array('name' => 'Verdana', 'bold' => true, 'italic' => false, 'strike' => false, 'size' => 16, 'color' => array('rgb' => 'FFFFFF')), 'fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('argb' => 'FF220835')), 'borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_NONE)), 'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER, 'rotation' => 0, 'wrap' => TRUE));
    $estiloTituloColumnas = array('font' => array('name' => 'Arial', 'bold' => true, 'color' => array('rgb' => '000000')), 'fill' => array('type' => PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR, 'rotation' => 90, 'startcolor' => array('rgb' => 'c47cf2'), 'endcolor' => array('argb' => 'FF431a5d')), 'borders' => array('top' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM, 'color' => array('rgb' => '143860')), 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM, 'color' => array('rgb' => '143860'))), 'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER, 'wrap' => TRUE));
    $estiloInformacion = new PHPExcel_Style();
    $estiloInformacion->applyFromArray(array('font' => array('name' => 'Arial', 'color' => array('rgb' => '000000')), 'fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('argb' => 'FFd9b7f4')), 'borders' => array('left' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('rgb' => '3a2a47')))));
    $sql = "SELECT * FROM profesionales";
    $post = $app['db']->fetchAll($sql);
    $objPHPExcel->setActiveSheetIndex(0);
    $objPHPExcel->getActiveSheet()->setTitle("profesionales");
コード例 #8
0
ファイル: index.php プロジェクト: monz111/impvsys_blog
<?php

require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../vendor/j4mie/idiorm/idiorm.php';
require_once __DIR__ . '/../vendor/j4mie/paris/paris.php';
$app = new Silex\Application();
$app->get('/', function () {
    return "Hello World!";
});
//名前を表示させるテスト
$app->get('/hello/{name}', function ($name) use($app) {
    return $app->escape($name);
});
$app->run();
$loader = new Twig_Loader_String();
$twig = new Twig_Environment($loader);
echo $twig->render('Hello {{ name }}!', array('name' => 'Fabien'));
コード例 #9
0
ファイル: main.php プロジェクト: SlimBN/UploadIt
 * Prihlasovanie
 */
$app->get('/login', function () use($app) {
    $user = new User();
    $form = $app['form.factory']->create(new LoginForm(), $user);
    return $app['twig']->render('login.twig', array('form' => $form->createView()));
})->bind('login');
$app->post('/login', function (Symfony\Component\HttpFoundation\Request $request) use($app) {
    $user = new User();
    $form = $app['form.factory']->create(new LoginForm(), $user);
    $form->bind($request);
    if ($form->isValid()) {
        $loggedUser = $app['login_service']->auth($user);
        if ($loggedUser !== FALSE) {
            $app['session']->set('user', $loggedUser);
            $app['session']->getFlashBag()->add('success', 'Vitaj späť ' . $app->escape($loggedUser['meno']) . '.');
            return new RedirectResponse($app['url_generator']->generate('home'));
        } else {
            // Prihlasenie zlyhalo
            $app['session']->getFlashBag()->add('error', 'Zadal si nespravne meno alebo heslo.');
        }
    }
    return $app['twig']->render('login.twig', array('form' => $form->createView()));
})->bind('login.process');
/**
 * Sekcia pre ucitelov
 */
$app->post('/zadanie/new', function (Symfony\Component\HttpFoundation\Request $request) use($app) {
    $user = $app['session']->get('user');
    if ($user['role'] != 2) {
        throw new Exception('Permission denied');
コード例 #10
0
ファイル: index.php プロジェクト: nacmartin/gozame
<?php

error_reporting(E_ALL);
require __DIR__ . '/silex.phar';
$app = new Silex\Application();
$app['db'] = $app->share(function () {
    $dbh = new PDO('sqlite:' . __DIR__ . '/db/bookmarks.db3', null, null, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
    $dbh->exec("CREATE TABLE IF NOT EXISTS bookmarks (id INTEGER PRIMARY KEY, bookmark VARCHAR(255), created_at TIMESTAMP)");
    return $dbh;
});
$app->get('/new', function () use($app) {
    $request = $app['request'];
    $url = $request->get('url');
    $url = urldecode($url);
    $app['db']->prepare("INSERT INTO bookmarks (bookmark, created_at) VALUES (?, DATETIME('NOW'))")->execute(array($url));
    return $app->escape($url) . " Bookmarked";
});
$app->get('/', function () use($app) {
    $request = $app['request'];
    $num = $request->get('num');
    $rcount = $app['db']->query('SELECT COUNT (*) as num FROM bookmarks');
    $count = $rcount->fetch();
    $num = $num && $num <= $count['num'] ? $num : 0;
    $res = $app['db']->query('SELECT * FROM bookmarks ORDER BY created_at DESC LIMIT 1 OFFSET ' . $num);
    $row = $res->fetch();
    return '<!DOCTYPE html>
        <html><head>  
        <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />

        <style type="text/css" media="all">
    html, body {
コード例 #11
0
ファイル: index.php プロジェクト: yenteck/premier-silex
<?php

require_once __DIR__ . '/../vendor/autoload.php';
$app = new Silex\Application();
$app->get('/', function () {
    return " bonjour voici ma premiere appli base sur le framework silex de php";
});
$app->get("/hello/{name}", function ($name) use($app) {
    return "Hello <b>" . $app->escape($name) . "</b> comment tu va ?";
});
$app->run();
コード例 #12
0
ファイル: index.php プロジェクト: elisherer/slack-rage
    // 		'verify' => false,
    // 		debug => true
    // 	]
    // 	);
    $res = \Requests::get('http://alltheragefaces.com/api/search/' . $search);
    $json = json_decode($res->body);
    // $json   = json_decode( $res->getBody() );
    if ($json && is_array($json)) {
        $img = $json[array_rand($json)];
        return $img;
    }
    $app->abort(200, 'Failed to fetch anything from the API :(');
};
$app->get('/', function (\Silex\Application $app) {
    $img = $app['fetch_rage'];
    return sprintf('<img src="%s" alt="%s" />', $app->escape($img->png), $app->escape($img->title));
});
$app->post('/', function (\Silex\Application $app) {
    $img = $app['fetch_rage'];
    // check for slack data
    $token = $app['request']->get('token');
    if ($token && isset($app['webhooks'][$token])) {
        // check if user chat or channel
        $channel = $app['request']->get('channel_name') === 'directmessage' ? $app['request']->get('channel_id') : '#' . $app['request']->get('channel_name');
        $payload = json_encode(['text' => '/rage ' . $app['request']->get('text'), 'channel' => $channel, 'username' => $app['request']->get('user_name'), 'icon_url' => 'http://cdn.alltheragefaces.com/img/faces/png/troll-troll-face.png', 'attachments' => [['title' => $img->title, 'fallback' => $img->title, 'image_url' => $img->png]]]);
        // $client  = new \GuzzleHttp\Client();
        // $promise = $client->postAsync( $app['webhooks'][ $token ], [ 'body' => $payload ] );
        // $promise->wait();
        // $res = \Requests::post($app['webhooks'][ $token ], [ 'body' => $payload ]);
        $ch = curl_init($app['webhooks'][$token]);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");