forked from deblan/gist
Propel + console
This commit is contained in:
parent
b09a21761f
commit
6b31a2b2db
|
@ -5,3 +5,5 @@ use Gist\Application;
|
||||||
$app = Application::getInstance();
|
$app = Application::getInstance();
|
||||||
|
|
||||||
$app['root_path'] = __DIR__ . '/../..';
|
$app['root_path'] = __DIR__ . '/../..';
|
||||||
|
|
||||||
|
chdir($app['root_path']);
|
||||||
|
|
13
app/bootstrap.php.d/20-console.php
Normal file
13
app/bootstrap.php.d/20-console.php
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Knp\Provider\ConsoleServiceProvider;
|
||||||
|
|
||||||
|
$app->register(new ConsoleServiceProvider(), array(
|
||||||
|
'console.name' => 'GIST Console',
|
||||||
|
'console.version' => 'dev-master',
|
||||||
|
'console.project_directory' => $app['root_path'],
|
||||||
|
));
|
||||||
|
|
||||||
|
$app['console'] = $app->share($app->extend('console', function ($console) {
|
||||||
|
return $console;
|
||||||
|
}));
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
use Silex\Provider\UrlGeneratorServiceProvider;
|
use Silex\Provider\UrlGeneratorServiceProvider;
|
||||||
use Silex\Provider\SessionServiceProvider;
|
use Silex\Provider\SessionServiceProvider;
|
||||||
|
use Propel\Runtime\Propel;
|
||||||
|
|
||||||
$app->register(new UrlGeneratorServiceProvider());
|
$app->register(new UrlGeneratorServiceProvider());
|
||||||
$app->register(new SessionServiceProvider());
|
$app->register(new SessionServiceProvider());
|
||||||
|
|
||||||
|
Propel::init('app/config/propel/config.php');
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use GitWrapper\GitWrapper;
|
use GitWrapper\GitWrapper;
|
||||||
|
use Gist\Service\GistService;
|
||||||
|
|
||||||
|
$app['gist_path'] = $app['root_path'].'/data/git';
|
||||||
|
|
||||||
$app['git'] = function ($app) {
|
$app['git'] = function ($app) {
|
||||||
return new GitWrapper();
|
$wrapper = new GitWrapper('/usr/bin/git');
|
||||||
|
return $wrapper->init($app['gist_path']);
|
||||||
|
};
|
||||||
|
|
||||||
|
$app['gist'] = function ($app) {
|
||||||
|
return new GistService($app['gist_path'], $app['git']);
|
||||||
};
|
};
|
||||||
|
|
1
app/propel-console
Symbolic link
1
app/propel-console
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
/home/simon/www/repo/gist/vendor/propel/propel/bin/propel
|
|
@ -4,12 +4,12 @@
|
||||||
"silex/silex": "1.3.x-dev",
|
"silex/silex": "1.3.x-dev",
|
||||||
"symfony/yaml": "~2.6",
|
"symfony/yaml": "~2.6",
|
||||||
"symfony/twig-bridge": "~2.6",
|
"symfony/twig-bridge": "~2.6",
|
||||||
"symfony/translation": "dev-master",
|
|
||||||
"symfony/config": "2.8.x-dev",
|
"symfony/config": "2.8.x-dev",
|
||||||
"cpliakas/git-wrapper": "~1.4",
|
"cpliakas/git-wrapper": "~1.4",
|
||||||
"symfony/form": "~2.6",
|
"symfony/form": "~2.6",
|
||||||
"symfony/security-csrf": "~2.6",
|
"symfony/security-csrf": "~2.6",
|
||||||
"symfony/validator": "dev-master"
|
"knplabs/console-service-provider": "~1.0",
|
||||||
|
"propel/propel": "~2.0@dev"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": {
|
"psr-0": {
|
||||||
|
|
33
propel.yaml
Normal file
33
propel.yaml
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
propel:
|
||||||
|
database:
|
||||||
|
connections:
|
||||||
|
default:
|
||||||
|
adapter: mysql
|
||||||
|
classname: Propel\Runtime\Connection\ConnectionWrapper
|
||||||
|
dsn: "mysql:host=localhost;dbname=gist"
|
||||||
|
user: root
|
||||||
|
password: root
|
||||||
|
attributes:
|
||||||
|
settings:
|
||||||
|
charset: utf8
|
||||||
|
queries:
|
||||||
|
utf8: "SET NAMES utf8 COLLATE utf8_unicode_ci, COLLATION_CONNECTION = utf8_unicode_ci, COLLATION_DATABASE = utf8_unicode_ci, COLLATION_SERVER = utf8_unicode_ci"
|
||||||
|
|
||||||
|
paths:
|
||||||
|
projectDir: src/
|
||||||
|
schemaDir: src/
|
||||||
|
outputDir: src/
|
||||||
|
phpDir: src/
|
||||||
|
phpConfDir: app/config/propel
|
||||||
|
sqlDir: app/propel/sql
|
||||||
|
migrationDir: app/propel/migration
|
||||||
|
|
||||||
|
runtime:
|
||||||
|
defaultConnection: default
|
||||||
|
connections: [default]
|
||||||
|
|
||||||
|
generator:
|
||||||
|
defaultConnection: default
|
||||||
|
connections: [default]
|
||||||
|
objectModel:
|
||||||
|
addClassLevelComment: false
|
|
@ -5,6 +5,7 @@ namespace Gist\Controller;
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Gist\Form\CreateGistForm;
|
use Gist\Form\CreateGistForm;
|
||||||
|
use Gist\Model\Gist;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class HomeController
|
* Class HomeController
|
||||||
|
@ -26,7 +27,13 @@ class HomeController
|
||||||
$form->submit($request);
|
$form->submit($request);
|
||||||
|
|
||||||
if ($form->isValid()) {
|
if ($form->isValid()) {
|
||||||
|
$gist = $app['gist']->create(new Gist(), $form->getData());
|
||||||
|
|
||||||
|
if ($gist->getCipher()) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
30
src/Gist/Model/Gist.php
Normal file
30
src/Gist/Model/Gist.php
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Gist\Model;
|
||||||
|
|
||||||
|
use Gist\Model\Base\Gist as BaseGist;
|
||||||
|
|
||||||
|
class Gist extends BaseGist
|
||||||
|
{
|
||||||
|
public function hydrateWith(array $data)
|
||||||
|
{
|
||||||
|
if (isset($data['title'])) {
|
||||||
|
$this->setTitle(trim($data['title']));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($data['type'])) {
|
||||||
|
$this->setType($data['type']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($data['cipher'])) {
|
||||||
|
$this->setCipher(in_array($data['cipher'], [true, 'yes']));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function generateFilename()
|
||||||
|
{
|
||||||
|
$this->setFile(uniqid());
|
||||||
|
}
|
||||||
|
}
|
20
src/Gist/Model/GistQuery.php
Normal file
20
src/Gist/Model/GistQuery.php
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Gist\Model;
|
||||||
|
|
||||||
|
use Gist\Model\Base\GistQuery as BaseGistQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Skeleton subclass for performing query and update operations on the 'gist' table.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* You should add additional methods to this class to meet the
|
||||||
|
* application requirements. This class will only be generated as
|
||||||
|
* long as it does not already exist in the output directory.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class GistQuery extends BaseGistQuery
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
13
src/Gist/Resources/config/propel/schema.xml
Normal file
13
src/Gist/Resources/config/propel/schema.xml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<database defaultIdMethod="native" name="default" namespace="Gist\Model">
|
||||||
|
<table name="gist">
|
||||||
|
<column name="id" type="INTEGER" primaryKey="true" required="true" autoIncrement="true"/>
|
||||||
|
|
||||||
|
<column name="title" type="VARCHAR" size="255" required="false" />
|
||||||
|
<column name="cipher" type="BOOLEAN" required="true" defaultValue="false" />
|
||||||
|
<column name="type" type="VARCHAR" size="30" required="true" />
|
||||||
|
<column name="file" type="VARCHAR" size="30" required="true" />
|
||||||
|
|
||||||
|
<behavior name="timestampable"/>
|
||||||
|
</table>
|
||||||
|
</database>
|
|
@ -42,10 +42,10 @@
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p class="navbar-text navbar-right">
|
<p class="navbar-text navbar-right">
|
||||||
<a class="btn btn-xs" href="{{ path(app.request.get('_route'), {_locale: 'en'}) }}">
|
<a class="btn btn-xs" href="{{ path('home', {_locale: 'en'}) }}">
|
||||||
<span class="flag-icon flag-icon-gb"></span>
|
<span class="flag-icon flag-icon-gb"></span>
|
||||||
</a>
|
</a>
|
||||||
<a class="btn btn-xs" href="{{ path(app.request.get('_route'), {_locale: 'fr'}) }}">
|
<a class="btn btn-xs" href="{{ path('home', {_locale: 'fr'}) }}">
|
||||||
<span class="flag-icon flag-icon-fr"></span>
|
<span class="flag-icon flag-icon-fr"></span>
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
<p><em>In file "{{ exception.file }}" at line {{ exception.line }}</em></p>
|
<p><em>In file "{{ exception.file }}" at line {{ exception.line }}</em></p>
|
||||||
|
|
||||||
<h2>Stacktrace</h2>
|
<h2>Stacktrace</h2>
|
||||||
|
<p>{{ exception.message }}</p>
|
||||||
<pre>{{ exception.traceAsString }}</pre>
|
<pre>{{ exception.traceAsString }}</pre>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>{{ exception.message }}</p>
|
<p>{{ exception.message }}</p>
|
||||||
|
|
43
src/Gist/Service/GistService.php
Normal file
43
src/Gist/Service/GistService.php
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Gist\Service;
|
||||||
|
|
||||||
|
use Gist\Model\Gist;
|
||||||
|
use GitWrapper\GitWorkingCopy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class GistService
|
||||||
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
|
*/
|
||||||
|
class GistService
|
||||||
|
{
|
||||||
|
protected $gistPath;
|
||||||
|
|
||||||
|
protected $git;
|
||||||
|
|
||||||
|
public function __construct($gistPath, GitWorkingCopy $git)
|
||||||
|
{
|
||||||
|
$this->gistPath = $gistPath;
|
||||||
|
$this->git = $git;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(Gist $gist, array $data)
|
||||||
|
{
|
||||||
|
$gist->hydrateWith($data);
|
||||||
|
$gist->generateFilename();
|
||||||
|
$dir = getcwd();
|
||||||
|
|
||||||
|
chdir($this->gistPath);
|
||||||
|
file_put_contents($this->gistPath.'/'.$gist->getFile(), $data['content']);
|
||||||
|
|
||||||
|
$this->git
|
||||||
|
->add($gist->getFile())
|
||||||
|
->commit('Init');
|
||||||
|
|
||||||
|
chdir($dir);
|
||||||
|
|
||||||
|
$gist->save();
|
||||||
|
|
||||||
|
return $gist;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue