parent
b09a21761f
commit
6b31a2b2db
@ -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;
|
||||
}));
|
@ -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']);
|
||||
};
|
||||
|
@ -0,0 +1 @@
|
||||
/home/simon/www/repo/gist/vendor/propel/propel/bin/propel
|
@ -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
|
@ -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());
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
||||
|
||||
}
|
@ -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>
|
@ -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 new issue