1
0
mirror of https://gitnet.fr/deblan/gist.git synced 2021-08-14 08:30:49 +02:00

Propel + console

This commit is contained in:
Simon Vieille 2015-05-06 14:11:00 +02:00
parent b09a21761f
commit 6b31a2b2db
14 changed files with 179 additions and 5 deletions

View File

@ -5,3 +5,5 @@ use Gist\Application;
$app = Application::getInstance();
$app['root_path'] = __DIR__ . '/../..';
chdir($app['root_path']);

View 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;
}));

View File

@ -2,6 +2,9 @@
use Silex\Provider\UrlGeneratorServiceProvider;
use Silex\Provider\SessionServiceProvider;
use Propel\Runtime\Propel;
$app->register(new UrlGeneratorServiceProvider());
$app->register(new SessionServiceProvider());
Propel::init('app/config/propel/config.php');

View File

@ -1,7 +1,15 @@
<?php
use GitWrapper\GitWrapper;
use Gist\Service\GistService;
$app['gist_path'] = $app['root_path'].'/data/git';
$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
View File

@ -0,0 +1 @@
/home/simon/www/repo/gist/vendor/propel/propel/bin/propel

View File

@ -4,12 +4,12 @@
"silex/silex": "1.3.x-dev",
"symfony/yaml": "~2.6",
"symfony/twig-bridge": "~2.6",
"symfony/translation": "dev-master",
"symfony/config": "2.8.x-dev",
"cpliakas/git-wrapper": "~1.4",
"symfony/form": "~2.6",
"symfony/security-csrf": "~2.6",
"symfony/validator": "dev-master"
"knplabs/console-service-provider": "~1.0",
"propel/propel": "~2.0@dev"
},
"autoload": {
"psr-0": {

33
propel.yaml Normal file
View 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

View File

@ -5,6 +5,7 @@ namespace Gist\Controller;
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use Gist\Form\CreateGistForm;
use Gist\Model\Gist;
/**
* Class HomeController
@ -26,7 +27,13 @@ class HomeController
$form->submit($request);
if ($form->isValid()) {
$gist = $app['gist']->create(new Gist(), $form->getData());
if ($gist->getCipher()) {
} else {
}
}
}

30
src/Gist/Model/Gist.php Normal file
View 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());
}
}

View 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
{
}

View 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>

View File

@ -42,10 +42,10 @@
</li>
</ul>
<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>
</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>
</a>
</p>

View File

@ -16,6 +16,7 @@
<p><em>In file "{{ exception.file }}" at line {{ exception.line }}</em></p>
<h2>Stacktrace</h2>
<p>{{ exception.message }}</p>
<pre>{{ exception.traceAsString }}</pre>
{% else %}
<p>{{ exception.message }}</p>

View 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;
}
}