Пример #1
0
        $filePath = $path . $fileName;
        $arr = explode(".", $fileName);
        $extension = array_pop($arr);
        $mime = "text/plain";
        if ($extension === "css") {
            $mime = "text/css";
        } else {
            if ($extension === "js") {
                $mime = "application/javascript";
            } else {
                if ($extension === "html") {
                    $mime = "text/html";
                }
            }
        }
        return $app->sendFile($filePath, 200, array('Content-Type' => $mime));
    })->assert('fileName', '.+');
}
// Development routes
$app->get('/devStatic/{lang}/{fileName}', 'DevStaticController::getDevFile')->assert('fileName', '.+');
$app->get('/dev/', 'DevDashboardController::devIndex');
$app->get('/dev/js/bench/{id}', 'DevDashboardController::devJSBench');
$app->get('/dev/js/{type}/{id}', 'DevDashboardController::devJSExample');
$app->match('/dev/php/{type}/{id}', 'DevDashboardController::devPHPExample');
$app->match('/dev/html/{type}/{id}', 'DevDashboardController::devHTMLExample');
$app->match('/dev/test/{id}', 'DevDashboardController::devTest');
$app->match('/docs/{fileName}', 'DevStaticController::devDocs')->assert('fileName', '.+');
// Production routes
$app->get('/', 'DevDashboardController::prodIndex');
$app->get('/dashboard/js/{type}/{id}', 'DevDashboardController::prodJSExample');
$app->match('/dashboard/php/{type}/{id}', 'DevDashboardController::prodPHPExample');
Пример #2
0
            $folder = 'img';
            $extension = 'jpg';
            break;
        case 'track':
            $folder = 'msc';
            $extension = 'mp3';
            break;
        default:
            return $app->abort(404, "La source demandée n'existe pas");
    }
    $file = project_path . "/{$folder}/{$type}/{$key}.{$extension}";
    if (!file_exists($file)) {
        $app->abort(404, "La ressource demandée n'existe pas");
    }
    if ($type != 'track') {
        return $app->sendFile($file, 200, ['Content-Type' => 'image/jpeg']);
    } else {
        return $app->sendFile($file, 200, ['Content-Type' => 'audio/mp3']);
    }
});
$app->get('/services/{type}/{key}', function ($type, $key) use($app) {
    $manager = ManagerFactory::getManager($type);
    if (is_null($manager)) {
        return null;
    }
    if ($key == 'all') {
        return json_encode($manager->all());
    }
    return json_encode($manager->get($key));
});
$app->get('/services/{type}/{key}/xml', function ($type, $key) use($app) {
Пример #3
0
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!
    }
    return $app->sendFile(__DIR__ . '/' . $path);
});
/** Use the image request endpoint to start the transaction.
 *
 * @return JsonResponse JSON, including a `token`.
 */
Пример #4
0
define('APP_DIR', __DIR__);
require_once APP_DIR . '/../vendor/autoload.php';
$app = new Silex\Application();
/**
 * Register database service
 */
$app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => array('dbname' => 'mydb', 'user' => 'user', 'password' => 'secret', 'host' => 'localhost', 'driver' => 'pdo_mysql')));
/**
 * router
 */
$app->post('/translate', '\\SlackBotService\\Controller\\Translate::translate');
$app->post('/zingmp3', '\\SlackBotService\\Controller\\ZingMp3::post');
$app->post('/meme/generate', '\\SlackBotService\\Controller\\Meme::generate');
$app->post('/meme/list', '\\SlackBotService\\Controller\\Meme::memoList');
$app->post('/quote', '\\SlackBotService\\Controller\\Quote::post');
$app->post('/horoscope', '\\SlackBotService\\Controller\\Horoscope::post');
$app->post('/funnyimage/random', '\\SlackBotService\\Controller\\FunnyImage::post');
$app->get('/public/meme/{filename}', function (Silex\Application $app, $filename) {
    $filePath = APP_DIR . '/public/meme/' . $filename;
    if (!file_exists($filePath)) {
        $app->abort(404, $filePath . ' not found.');
    }
    return $app->sendFile($filePath);
});
/**
 * Error handler
 */
$app->error(function (\Exception $e, $code) {
    return new JsonResponse(array('errorCode' => $code, 'message' => $e->getMessage()));
});
$app->run();
Пример #5
0
$app->get('/api/getnomola', function () use($fnomola) {
    $nomola = file_get_contents($fnomola);
    return $nomola;
});
$app->get('/api/getcuernos', function () use($fcuernos) {
    $cuernos = file_get_contents($fcuernos);
    return $cuernos;
});
$app->get('/api/getdj', function () use($fmola, $fnomola, $fcuernos, $faccion) {
    $mola = file_get_contents($fmola);
    $nomola = file_get_contents($fnomola);
    $cuernos = file_get_contents($fcuernos);
    $accion = file_get_contents($faccion);
    return '{ "mola": ' . $mola . ', "nomola": ' . $nomola . ', "cuernos": ' . $cuernos . ', "accion": ' . $accion . ' }';
});
$app->get('/', function () use($app, $findex) {
    return $app->sendFile($findex);
});
$app->get('/api/acciondj', function () use($faccion) {
    $accion = file_get_contents($faccion);
    return '{ "accion" : ' . $accion . ' }';
});
/*$app->get('/{fichero}', function($fichero) use($app, $findex) {
    return $app->sendFile(__DIR__."/".$fichero); 
});*/
$filename = __DIR__ . preg_replace('#(\\?.*)$#', '', $_SERVER['REQUEST_URI']);
if (php_sapi_name() === 'cli-server' && is_file($filename)) {
    return false;
}
//$app = require __DIR__.'/../src/app.php';
$app->run();
Пример #6
0
<?php

require_once __DIR__ . '/vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Routing\Loader\YamlFileLoader;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Neutron\Silex\Provider\MongoDBODMServiceProvider;
$app = new Silex\Application();
//serve index as default
$app->get('/', function () use($app) {
    return $app->sendFile(dirname(__DIR__) . '/public/index.html');
});
//load routes from config/routes.yml
$app['routes'] = $app->extend('routes', function (RouteCollection $routes, Silex\Application $app) {
    $loader = new YamlFileLoader(new FileLocator(__DIR__ . '/config'));
    $collection = $loader->load('routes.yml');
    $routes->addCollection($collection);
    return $routes;
});
//register logger
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => __DIR__ . '/log/dev.log'));
if (!isset($dbName)) {
    $app['monolog']->addInfo("dbName is null!!!!!");
    exit;
}
//mongo connection & ODM
$app->register(new MongoDBODMServiceProvider(), array('doctrine.odm.mongodb.connection_options' => array('database' => $dbName, 'host' => 'localhost', 'options' => array('fsync' => false)), 'doctrine.odm.mongodb.documents' => array(0 => array('type' => 'annotation', 'path' => array('src/Timeshare/Entities'), 'namespace' => 'Timeshare\\Entities', 'alias' => 'ann')), 'doctrine.odm.mongodb.proxies_dir' => 'cache/doctrine/odm/mongodb/Proxy', 'doctrine.odm.mongodb.proxies_namespace' => 'DoctrineMongoDBProxy', 'doctrine.odm.mongodb.auto_generate_proxies' => true, 'doctrine.odm.mongodb.hydrators_dir' => 'cache/doctrine/odm/mongodb/Hydrator', 'doctrine.odm.mongodb.hydrators_namespace' => 'DoctrineMongoDBHydrator', 'doctrine.odm.mongodb.auto_generate_hydrators' => true, 'doctrine.odm.mongodb.metadata_cache' => new \Doctrine\Common\Cache\ArrayCache(), 'doctrine.odm.mongodb.logger_callable' => $app->protect(function ($query) {
    // log your query
Пример #7
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 = "[";
Пример #8
0
        }

        $manager = new ImageManager(array('driver' => 'gd'));

        $image = $manager->make($loadPath . $name . '.' . $extension);
        $image->resize($width, $height);

        $sizePath = $width . $sizedelimiter . $height . '/';
        if (! file_exists(($path . $sizePath ))) {
            mkdir($path . $sizePath, 0777, true);
        }

        $savedFile = $path . $sizePath . $name . '.' . $extension;
        $image->save($savedFile);

        return $app->sendFile($savedFile);
    }
)
    ->assert('sizedelimiter', 'x')
    ->assert('path', '([a-z0-9]{0,}[\/]{1}){1,}')
    ->assert('width', '[1-9]{1}[0-9]{1,3}')
    ->assert('height', '[1-9]{1}[0-9]{1,3}')
    ->assert('extension', 'png|jpg');

$app->error(function() {
    return new \Symfony\Component\HttpFoundation\Response('Not found', 404);
});

$app->run();

<?php

require_once __DIR__ . '/vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Routing\Loader\YamlFileLoader;
use Symfony\Component\Routing\RouteCollection;
use Neutron\Silex\Provider\MongoDBODMServiceProvider;
$app = new Silex\Application();
//serve index as default
$app->get('/', function () use($app) {
    return $app->sendFile(dirname(__DIR__) . '/index.html');
});
//load routes from config/routes.yml
$app['routes'] = $app->extend('routes', function (RouteCollection $routes, Silex\Application $app) {
    $loader = new YamlFileLoader(new FileLocator(__DIR__ . '/config'));
    $collection = $loader->load('routes.yml');
    $routes->addCollection($collection);
    return $routes;
});
//register logger
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => __DIR__ . '/log/dev.log'));
if (!isset($dbName)) {
    $app['monolog']->addInfo("dbName is null!!!!!");
    exit;
}
//mongo connection & ODM
$app->register(new MongoDBODMServiceProvider(), array('doctrine.odm.mongodb.connection_options' => array('database' => $dbName, 'host' => 'localhost', 'options' => array('fsync' => false)), 'doctrine.odm.mongodb.documents' => array(0 => array('type' => 'annotation', 'path' => array('src/Todos/Entities'), 'namespace' => 'Todos\\Entities', 'alias' => 'docs')), 'doctrine.odm.mongodb.proxies_dir' => 'cache/doctrine/odm/mongodb/Proxy', 'doctrine.odm.mongodb.proxies_namespace' => 'DoctrineMongoDBProxy', 'doctrine.odm.mongodb.auto_generate_proxies' => true, 'doctrine.odm.mongodb.hydrators_dir' => 'cache/doctrine/odm/mongodb/Hydrator', 'doctrine.odm.mongodb.hydrators_namespace' => 'DoctrineMongoDBHydrator', 'doctrine.odm.mongodb.auto_generate_hydrators' => true, 'doctrine.odm.mongodb.metadata_cache' => new \Doctrine\Common\Cache\ArrayCache(), 'doctrine.odm.mongodb.logger_callable' => $app->protect(function ($query) {
    // log your query
})));
//register all entities