Skip to content

Commit 53e25fb

Browse files
author
Marc J. Schmidt
committed
Added examples, html5 history browsing and 'my-fiddles' section. Fixed timezone php bug
1 parent 28f037c commit 53e25fb

File tree

16 files changed

+622
-154
lines changed

16 files changed

+622
-154
lines changed

.bowerrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"directory": "Resources/public/libs"
3+
}

Controller/MainController.php

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
namespace PropelSandbox\Controller;
44

55
use FOS\RestBundle\Request\ParamFetcher;
6+
use Propel\Runtime\ActiveQuery\Criteria;
67
use Propel\Runtime\Map\TableMap;
78
use PropelSandbox\Model\Fiddle;
89
use PropelSandbox\Model\FiddleQuery;
910
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
1011
use Symfony\Component\HttpFoundation\Request;
11-
use FOS\RestBundle\Controller\Annotations\View;
12+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
13+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
1214
use FOS\RestBundle\Controller\Annotations\Get;
1315
use FOS\RestBundle\Controller\Annotations\Post;
1416
use FOS\RestBundle\Controller\Annotations\Put;
@@ -19,42 +21,59 @@ class MainController extends Controller
1921
{
2022

2123
/**
22-
*
23-
* @QueryParam(name="fiddle", requirements="[a-zA-Z0-9]{7}")
24-
*
25-
* @Get("/")
26-
* @Get("/{fiddle}")
24+
* @Route("/")
25+
* @Route("/{fiddle}",requirements={"fiddle" = "[a-zA-Z0-9]{7}"})
26+
* @Route("/example/{exampleId}",requirements={"exampleId" = "[a-zA-Z0-9]+"})
27+
* @Method("GET")
2728
*/
28-
public function indexAction(Request $request, $fiddle = '')
29+
public function appAction(Request $request, $fiddle = '')
2930
{
30-
$editable = $fiddle ? $this->isEditable($fiddle, $request) : true;
31-
32-
$model = false;
33-
$fiddleId = $fiddle;
34-
3531
if ($fiddle) {
3632
$fiddle = FiddleQuery::create()->findPk($fiddle);
3733
if (!$fiddle) {
38-
throw $this->createNotFoundException('The fiddle does not exist');
34+
throw $this->createNotFoundException('The fiddle does not exist.');
3935
}
40-
41-
$model = $fiddle->exportModel();
4236
}
4337

44-
$config = array(
45-
'fiddleId' => $fiddleId,
46-
'editable' => $editable
47-
);
48-
4938
return $this->render(
50-
'PropelSandboxBundle::app.twig.html',
51-
array(
52-
'config' => $config,
53-
'model' => $model
54-
)
39+
'PropelSandboxBundle::app.twig.html'
5540
);
5641
}
5742

43+
/**
44+
* @Route("/{fiddle}.json", requirements={"fiddle" = "[a-zA-Z0-9]{7}"})
45+
* @Method("GET")
46+
*/
47+
public function fiddleAsJsonAction($fiddle, Request $request)
48+
{
49+
$fiddle = FiddleQuery::create()->findPk($fiddle);
50+
if (!$fiddle) {
51+
throw $this->createNotFoundException('The fiddle does not exist. [json]');
52+
}
53+
54+
$result = $fiddle->exportModel();
55+
$result['editable'] = $this->isEditable($fiddle->getId(), $request);
56+
57+
return $result;
58+
}
59+
60+
/**
61+
* @Route("/my-fiddles")
62+
* @Method("GET")
63+
*/
64+
public function myFiddles(Request $request)
65+
{
66+
$request->getSession()->start();
67+
$sessionId = $request->getSession()->getId();
68+
69+
return FiddleQuery::create()
70+
->select(['id', 'title', 'created_at'])
71+
->filterBySessionOwner($sessionId)
72+
->orderByCreatedAt(Criteria::DESC)
73+
->find()
74+
->toArray();
75+
}
76+
5877
/**
5978
* @param string $fiddle
6079
* @param Request $request

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
```
99
useradd sandbox --home /home/sandbox
1010
echo 'www-data ALL= NOPASSWD: /var/www/propelsandbox/src/PropelSandbox/Resources/meta/jail.sh' >> /etc/sudoers // or sudo visudo
11-
iptables -I OUTPUT -j REJECT -m owner --gid-owner sandbox #dont forget to do this on server boot, use iptables-persistent
11+
12+
#dont forget to do this on server boot, use iptables-persistent
13+
iptables -I OUTPUT -j REJECT -m owner --gid-owner sandbox
14+
iptables -I OUTPUT -j ACCEPT -p tcp -d 127.0.0.1 -m owner --gid-owner sandbox
1215
```
1316
4. make sure `/var/www/propelsandbox/src/PropelSandbox/Resources/meta/jail.sh` is only writeable by root!
1417
5. fire `bower install` in `src/PropelSandbox`
1518
6. make sure /tmp/propelsandbox is writeable by your web server
19+
7. user `sandbox` needs access to `/tmp/propelsandbox/`, `/tmp/propelsandbox/chroots/` rx.
1620
7. Make sure all dependencies are set up. See @propelorm/sandbox-vagrant/bootstrap.sh for more information.

Resources/config/config.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ framework:
1414

1515
fos_rest:
1616
param_fetcher_listener: true
17-
body_listener: true
17+
body_listener: true
18+
routing_loader:
19+
include_format: false

Resources/meta/jail-php.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[PHP]
22

3-
zend_extension=xdebug.so
3+
;zend_extension=xdebug.so
44
extension=pdo.so
55
extension=pdo_mysql.so
66
extension=json.so
@@ -871,7 +871,7 @@ cli_server.color = On
871871
[Date]
872872
; Defines the default timezone used by the date functions
873873
; http://php.net/date.timezone
874-
;date.timezone =
874+
date.timezone = "Europe/Berlin"
875875

876876
; http://php.net/date.default-latitude
877877
;date.default_latitude = 31.7667

Resources/meta/setup_jail_base.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ chmod 644 $BASE/etc/passwd $BASE/etc/shadow $BASE/etc/group
7575
mkdir -p $BASE/etc/php5/cli
7676
cp $metaDir/jail-php.ini $BASE/etc/php5/cli/php.ini
7777

78+
mkdir -p $BASE/usr/share/
79+
cp -r /usr/share/zoneinfo $BASE/usr/share/
7880

7981
cp $metaDir/start.sh $BASE/bin/
8082
cp $metaDir/model-build.sh $BASE/bin/

Resources/public/.bowerrc

Whitespace-only changes.

Resources/public/app.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
import angular from './angular';
22

3-
var app = angular.module('propelFiddle', ['ui.codemirror', 'ui.bootstrap']);
3+
var app = angular.module('propelFiddle', ['ngRoute', 'ui.codemirror', 'ui.bootstrap']);
44

55
import MainController from './controller/MainController';
66
import toArray from './filters/toArray';
77

8+
import examples from './examples';
9+
810
app.controller('MainController', MainController);
911
app.filter('toArray', () => toArray);
12+
app.constant('EXAMPLES', examples);
13+
app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
14+
// use the HTML5 History API
15+
$locationProvider.html5Mode(true);
16+
17+
$routeProvider
18+
.when(window._baseUrl + '/', {})
19+
.when(window._baseUrl + '/:fiddleId', {})
20+
.when(window._baseUrl + '/example/:exampleId', {});
21+
}]);
22+
23+
app.run(function($route) {});

0 commit comments

Comments
 (0)