-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! Added loaders and dumpers for nette database and Doctrine DBAL.
- Loading branch information
1 parent
8094b40
commit bc671b6
Showing
25 changed files
with
1,061 additions
and
511 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,69 +14,43 @@ | |
use Doctrine\DBAL\Schema\AbstractSchemaManager; | ||
use Doctrine\DBAL\Types\Type; | ||
use Kdyby; | ||
use Kdyby\Console\ContainerHelper; | ||
use Nette; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Helper\Helper; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
|
||
|
||
/** | ||
* @author Filip Procházka <[email protected]> | ||
* @author Azathoth <[email protected]> | ||
* | ||
* @method ContainerHelper|Helper getHelper(string $name) | ||
*/ | ||
class CreateTableCommand extends Command | ||
{ | ||
|
||
/** @var Nette\DI\Container */ | ||
private $serviceLocator; | ||
|
||
/** @var Connection */ | ||
private $connection; | ||
|
||
/** @var AbstractSchemaManager */ | ||
private $schemaManager; | ||
|
||
/** @var string */ | ||
public $table; | ||
|
||
/** @var string */ | ||
public $key; | ||
|
||
/** @var string */ | ||
public $locale; | ||
|
||
/** @var string */ | ||
public $message; | ||
|
||
/** @var string */ | ||
public $updatedAt; | ||
|
||
protected function configure() | ||
{ | ||
$this->setName('kdyby:translation-create-table') | ||
$this->setName('kdyby:translation:create-table') | ||
->setDescription('Builds query for creating of database table.') | ||
->setDefinition(array( | ||
new InputOption( | ||
'dump-sql', NULL, InputOption::VALUE_NONE, | ||
'Dumps the generated SQL statement to the screen (does not execute it).' | ||
), | ||
new InputOption( | ||
'force', NULL, InputOption::VALUE_NONE, | ||
'Causes the generated SQL statement to be physically executed against your database.' | ||
) | ||
)); | ||
->addOption('dump-sql', NULL, InputOption::VALUE_NONE, 'Dumps the generated SQL statement to the screen (does not execute it).') | ||
->addOption('force', NULL, InputOption::VALUE_NONE, 'Causes the generated SQL statement to be physically executed against your database.'); | ||
} | ||
|
||
|
||
|
||
protected function initialize(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->serviceLocator = $this->getHelper('container')->getContainer(); | ||
$this->connection = $this->serviceLocator->getByType('Doctrine\DBAL\Connection'); | ||
$this->schemaManager = $this->serviceLocator->getByType('Doctrine\DBAL\Schema\AbstractSchemaManager'); | ||
$serviceLocator = $this->getHelper('container')->getContainer(); | ||
$this->connection = $serviceLocator->getByType('Doctrine\DBAL\Connection'); | ||
$this->schemaManager = $serviceLocator->getByType('Doctrine\DBAL\Schema\AbstractSchemaManager'); | ||
} | ||
|
||
|
||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
if (!$input->getOption('dump-sql') && !$input->getOption('force')) { | ||
|
@@ -89,8 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
return; | ||
} | ||
|
||
$table = $this->schemaManager->createSchema() | ||
->createTable($this->table); | ||
$table = $this->schemaManager->createSchema()->createTable($this->table); | ||
$table->addColumn($this->key, Type::STRING); | ||
$table->addColumn($this->locale, Type::STRING); | ||
$table->addColumn($this->message, Type::TEXT); | ||
|
@@ -100,7 +73,6 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
|
||
if ($input->getOption('dump-sql')) { | ||
list($sql) = $this->connection->getDatabasePlatform()->getCreateTableSQL($table); | ||
$output->writeln('Create table SQL:'); | ||
$output->writeln($sql); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Kdyby (http://www.kdyby.org) | ||
* | ||
* Copyright (c) 2008 Filip Procházka ([email protected]) | ||
* | ||
* For the full copyright and license information, please view the file license.txt that was distributed with this source code. | ||
*/ | ||
|
||
namespace Kdyby\Translation\DI; | ||
|
||
use Kdyby; | ||
use Nette; | ||
|
||
|
||
|
||
/** | ||
* @author Filip Procházka <[email protected]> | ||
*/ | ||
class Configuration | ||
{ | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $table = 'translations'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $key = 'key'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $locale = 'locale'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $message = 'message'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $updatedAt = 'updated_at'; | ||
|
||
|
||
|
||
/** | ||
* @param string $table | ||
*/ | ||
public function setTableName($table) | ||
{ | ||
$this->table = $table; | ||
} | ||
|
||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getTableName() | ||
{ | ||
return $this->table; | ||
} | ||
|
||
|
||
|
||
/** | ||
* @param string $key | ||
* @param string $locale | ||
* @param string $message | ||
* @param string $updatedAt | ||
*/ | ||
public function setColumnNames($key, $locale, $message, $updatedAt) | ||
{ | ||
$this->key = $key; | ||
$this->locale = $locale; | ||
$this->message = $message; | ||
$this->updatedAt = $updatedAt; | ||
} | ||
|
||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getKeyColumn() | ||
{ | ||
return $this->key; | ||
} | ||
|
||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getLocaleColumn() | ||
{ | ||
return $this->locale; | ||
} | ||
|
||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getMessageColumn() | ||
{ | ||
return $this->message; | ||
} | ||
|
||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getUpdatedAtColumn() | ||
{ | ||
return $this->updatedAt; | ||
} | ||
|
||
} |
Oops, something went wrong.