diff --git a/app/bootstrap.php.d/00-main.php b/app/bootstrap.php.d/00-main.php index 86d5573..918614b 100644 --- a/app/bootstrap.php.d/00-main.php +++ b/app/bootstrap.php.d/00-main.php @@ -5,3 +5,5 @@ use Gist\Application; $app = Application::getInstance(); $app['root_path'] = __DIR__ . '/../..'; + +chdir($app['root_path']); diff --git a/app/bootstrap.php.d/20-console.php b/app/bootstrap.php.d/20-console.php new file mode 100644 index 0000000..b5820c2 --- /dev/null +++ b/app/bootstrap.php.d/20-console.php @@ -0,0 +1,13 @@ +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; +})); diff --git a/app/bootstrap.php.d/20-misc.php b/app/bootstrap.php.d/20-misc.php index 1e69986..0b67df2 100644 --- a/app/bootstrap.php.d/20-misc.php +++ b/app/bootstrap.php.d/20-misc.php @@ -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'); diff --git a/app/bootstrap.php.d/50-git.php b/app/bootstrap.php.d/50-git.php index 80bb64d..d9a6414 100644 --- a/app/bootstrap.php.d/50-git.php +++ b/app/bootstrap.php.d/50-git.php @@ -1,7 +1,15 @@ init($app['gist_path']); +}; + +$app['gist'] = function ($app) { + return new GistService($app['gist_path'], $app['git']); }; diff --git a/app/propel-console b/app/propel-console new file mode 120000 index 0000000..e76c4f9 --- /dev/null +++ b/app/propel-console @@ -0,0 +1 @@ +/home/simon/www/repo/gist/vendor/propel/propel/bin/propel \ No newline at end of file diff --git a/composer.json b/composer.json index c63fe54..77ef9d4 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/propel.yaml b/propel.yaml new file mode 100644 index 0000000..6af6edd --- /dev/null +++ b/propel.yaml @@ -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 diff --git a/src/Gist/Controller/HomeController.php b/src/Gist/Controller/HomeController.php index 0ec2735..4deff5e 100644 --- a/src/Gist/Controller/HomeController.php +++ b/src/Gist/Controller/HomeController.php @@ -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 { + + } } } diff --git a/src/Gist/Model/Gist.php b/src/Gist/Model/Gist.php new file mode 100644 index 0000000..9ae15fe --- /dev/null +++ b/src/Gist/Model/Gist.php @@ -0,0 +1,30 @@ +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()); + } +} diff --git a/src/Gist/Model/GistQuery.php b/src/Gist/Model/GistQuery.php new file mode 100644 index 0000000..a2adcca --- /dev/null +++ b/src/Gist/Model/GistQuery.php @@ -0,0 +1,20 @@ + + + + + + + + + + + +
+
diff --git a/src/Gist/Resources/views/base.html.twig b/src/Gist/Resources/views/base.html.twig index 0452b51..c008c2c 100644 --- a/src/Gist/Resources/views/base.html.twig +++ b/src/Gist/Resources/views/base.html.twig @@ -42,10 +42,10 @@ diff --git a/src/Gist/Resources/views/error.html.twig b/src/Gist/Resources/views/error.html.twig index 49dc2ae..9a2e90a 100644 --- a/src/Gist/Resources/views/error.html.twig +++ b/src/Gist/Resources/views/error.html.twig @@ -16,6 +16,7 @@

In file "{{ exception.file }}" at line {{ exception.line }}

Stacktrace

+

{{ exception.message }}

{{ exception.traceAsString }}
{% else %}

{{ exception.message }}

diff --git a/src/Gist/Service/GistService.php b/src/Gist/Service/GistService.php new file mode 100644 index 0000000..6a8b327 --- /dev/null +++ b/src/Gist/Service/GistService.php @@ -0,0 +1,43 @@ + + */ +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; + } +}