Permalink
Browse files

update to use composer, latest silex

  • Loading branch information...
1 parent f491340 commit 33234cd00196b969b4e6afc43317b1cf40cab0b0 @igorw committed Dec 16, 2011
View
3 .gitignore
@@ -1,4 +1,3 @@
-silex.phar
cache
-.DS_Store
+vendor
.htaccess
View
12 .gitmodules
@@ -1,12 +0,0 @@
-[submodule "vendor/twig"]
- path = vendor/twig
- url = http://github.com/fabpot/Twig.git
-[submodule "vendor/doctrine"]
- path = vendor/doctrine
- url = git://github.com/doctrine/doctrine2.git
-[submodule "vendor/sfYaml"]
- path = vendor/sfYaml
- url = http://github.com/fabpot/yaml.git
-[submodule "vendor/symfony/src/Symfony/Component/Finder"]
- path = vendor/symfony/src/Symfony/Component/Finder
- url = https://github.com/symfony/Finder.git
View
16 README.md
@@ -4,14 +4,10 @@ simple pastebin written in PHP
## setup
-set up [silex](https://github.com/fabpot/Silex) dependency:
+set up dependencies:
- git clone git://github.com/igorw/Silex.git
- cd Silex
- ./compile
- cp silex.phar ..
- cd ..
- rm -rf Silex
+ wget http://getcomposer.org/composer.phar
+ php composer.phar install
install and start [mongodb](http://www.mongodb.org):
@@ -24,14 +20,14 @@ install the mongodb driver for php:
vi /path/to/php.ini
# extension=mongo.so
-set up [twig](http://www.twig-project.org) dependency:
+set up [twig](http://twig.sensiolabs.org) dependency:
git submodule update --init
configure
- cp example.htaccess .htaccess
- # adjust .htaccess
+ cp web/example.htaccess web/.htaccess
+ # adjust web/.htaccess
create a cron job to run garbage_collector.php every now and then.
View
0 cache/twig/.gitkeep
No changes.
View
7 composer.json
@@ -0,0 +1,7 @@
+{
+ "require": {
+ "silex/silex": ">=1.0.0-dev",
+ "symfony/finder": ">=2.1-dev",
+ "twig/twig": ">=1.4"
+ }
+}
View
1 composer.lock
@@ -0,0 +1 @@
+[{"package":"twig\/twig","version":"1.5.0-dev"},{"package":"symfony\/css-selector","version":"2.1.0-dev"},{"package":"symfony\/event-dispatcher","version":"2.1.0-dev"},{"package":"symfony\/http-foundation","version":"2.1.0-dev"},{"package":"symfony\/http-kernel","version":"2.1.0-dev"},{"package":"symfony\/routing","version":"2.1.0-dev"},{"package":"symfony\/finder","version":"2.1.0-dev"},{"package":"symfony\/dom-crawler","version":"2.1.0-dev"},{"package":"symfony\/browser-kit","version":"2.1.0-dev"},{"package":"pimple\/pimple","version":"1.0.0-dev"},{"package":"silex\/silex","version":"1.0.0-dev"}]
View
16 app.php → src/app.php
@@ -8,7 +8,7 @@
* with this source code in the file LICENSE.
*/
-require_once __DIR__.'/silex.phar';
+require_once __DIR__.'/../vendor/.composer/autoload.php';
use Silex\Application;
use Silex\Extension\TwigExtension;
@@ -22,15 +22,15 @@
require __DIR__.'/bootstrap.php';
-$app->before(function() use ($app) {
+$app->before(function () use ($app) {
// set up some template globals
$app['twig']->addGlobal('base_path', $app['request']->getBasePath());
$app['twig']->addGlobal('index_url', $app['url_generator']->generate('homepage'));
$app['twig']->addGlobal('create_url', $app['url_generator']->generate('create'));
$app['twig']->addGlobal('languages', $app['app.languages']);
});
-$app->get('/', function() use ($app) {
+$app->get('/', function () use ($app) {
$parentId = $app['request']->get('parent', false);
$parent = false;
if ($parentId) {
@@ -44,11 +44,11 @@
})
->bind('homepage');
-$app->get('/create', function() use ($app) {
+$app->get('/create', function () use ($app) {
return $app->redirect($app['url_generator']->generate('homepage'));
});
-$app->post('/create', function() use ($app) {
+$app->post('/create', function () use ($app) {
$content = preg_replace('#\r?\n#', "\n", $app['request']->get('content', ''));
$paste = array(
@@ -75,11 +75,11 @@
})
->bind('create');
-$app->get('/about', function() use ($app) {
+$app->get('/about', function () use ($app) {
return $app['twig']->render('about.html');
});
-$app->get('/{id}', function($id) use ($app) {
+$app->get('/{id}', function ($id) use ($app) {
$paste = $app['mongo.pastes']->findOne(array("_id" => $id));
if (!$paste) {
@@ -94,7 +94,7 @@
->bind('view')
->assert('id', '[0-9a-f]{8}');
-$app->error(function(Exception $e) use ($app) {
+$app->error(function (Exception $e) use ($app) {
$code = ($e instanceof BaseHttpException) ? $e->getStatusCode() : 500;
return new Response($app['twig']->render('error.html', array(
View
25 bootstrap.php → src/bootstrap.php
@@ -8,8 +8,8 @@
* with this source code in the file LICENSE.
*/
-use Silex\Extension\TwigExtension;
-use Silex\Extension\UrlGeneratorExtension;
+use Silex\Provider\TwigServiceProvider;
+use Silex\Provider\UrlGeneratorServiceProvider;
use Symfony\Component\Finder\Finder;
@@ -18,20 +18,17 @@
exit;
}
-$app->register(new TwigExtension(), array(
- 'twig.path' => __DIR__.'/views',
- 'twig.class_path' => __DIR__.'/vendor/twig/lib',
- 'twig.options' => array('cache' => __DIR__.'/cache/twig', 'debug' => true),
+$app->register(new TwigServiceProvider(), array(
+ 'twig.path' => __DIR__.'/../views',
+ 'twig.options' => array('cache' => __DIR__.'/../cache/twig', 'debug' => true),
));
-$app->register(new UrlGeneratorExtension());
+$app->register(new UrlGeneratorServiceProvider());
-$app['autoloader']->registerNamespace('Symfony', __DIR__.'/vendor/symfony/src');
-
-$app['app.languages'] = function() {
+$app['app.languages'] = function () {
$languages = array();
$finder = new Finder();
- foreach ($finder->name('*.min.js')->in(__DIR__.'/vendor/shjs/lang') as $file) {
+ foreach ($finder->name('*.min.js')->in(__DIR__.'/../vendor/shjs/lang') as $file) {
if (preg_match('#sh_(.+).min.js#', basename($file), $matches)) {
$languages[] = $matches[1];
}
@@ -42,7 +39,7 @@
$app['app.gc_interval'] = strtotime('24 hours ago');
$app['footer'] = 'Hosted by <a href="https://affiliates.nexcess.net/idevaffiliate.php?id=1184">Nexcess.net</a>';
-$app['app.garbage_collect'] = $app->protect(function() use ($app) {
+$app['app.garbage_collect'] = $app->protect(function () use ($app) {
$result = $app['mongo.pastes']->remove(
array('createdAt' => array(
'$lt' => new MongoDate($app['app.gc_interval']))
@@ -53,11 +50,11 @@
return $result['n'];
});
-$app['mongo.pastes'] = function($app) {
+$app['mongo.pastes'] = function ($app) {
return $app['mongo.db']->paste;
};
-$app['mongo.db'] = $app->share(function($app) {
+$app['mongo.db'] = $app->share(function ($app) {
$mongo = new Mongo();
return $mongo->trashbin;
});
1 vendor/symfony/src/Symfony/Component/Finder
@@ -1 +0,0 @@
-Subproject commit 707b2fc9b2bb7ccf631f2bfe7d650fd8f0707942
View
2 views/layout.html
@@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>{% block title %}trashbin{% endblock %}</title>
- <link rel="stylesheet" href="{{ base_path }}/views/stylesheet.css" />
+ <link rel="stylesheet" href="{{ base_path }}/style.css" />
{% block scripts %}{% endblock %}
</head>
<body>
View
0 example.htaccess → web/example.htaccess
File renamed without changes.
View
2 index.php → web/index.php
@@ -8,5 +8,5 @@
* with this source code in the file LICENSE.
*/
-$app = require __DIR__.'/app.php';
+$app = require __DIR__.'/../src/app.php';
$app->run();
View
0 views/stylesheet.css → web/style.css
File renamed without changes.

0 comments on commit 33234cd

Please sign in to comment.