diff --git a/CHANGELOG b/CHANGELOG index 42f21b3..31688f0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,12 @@ Grammatista Changelog ===================== +0.1.2 (October ?, 2012) +------------------------ + +ADD: Support for PHPTal (Hash) +ADD: Support for MySQL storage (Hash) + 0.1.1 (February ?, 2009) ------------------------ diff --git a/examples/test1.php b/examples/test1.php index 8afa7b8..388ba18 100644 --- a/examples/test1.php +++ b/examples/test1.php @@ -29,8 +29,14 @@ ), ), )); +Grammatista::registerParser('agphptal', array( + 'class' => 'GrammatistaParserPcrePhptal', + 'options' => array( + 'pcre.transform' => array("' . dquote . '" => '"') + ) +)); -Grammatista::setStorage(new GrammatistaStoragePdo(array('pdo.dsn' => 'sqlite:' . dirname(__FILE__) . '/' . $_SERVER['REQUEST_TIME'] . '.sqlite'))); +Grammatista::setStorage(new GrammatistaStorageSQLite(array('pdo.dsn' => 'sqlite:' . dirname(__FILE__) . '/' . $_SERVER['REQUEST_TIME'] . '.sqlite'))); $logger = new GrammatistaLoggerShell(); Grammatista::registerEventResponder('grammatista.parser.parsed', array($logger, 'log')); diff --git a/examples/test1/wow.tal b/examples/test1/wow.tal new file mode 100644 index 0000000..feda818 --- /dev/null +++ b/examples/test1/wow.tal @@ -0,0 +1,12 @@ +
+ +

+ +

There is ${php:count(foo) . ' ' . tm.__('lol', 'lolz', 1, 'tal.baz')} in here

+ + + +

\ No newline at end of file diff --git a/lib/Grammatista.class.php b/lib/Grammatista.class.php index d839aeb..57db6d4 100644 --- a/lib/Grammatista.class.php +++ b/lib/Grammatista.class.php @@ -14,7 +14,7 @@ */ class Grammatista { - const VERSION_NUMBER = '0.1.1'; + const VERSION_NUMBER = '0.1.2'; const VERSION_STATUS = 'dev'; /** @@ -29,6 +29,7 @@ class Grammatista 'GrammatistaParserDwoo' => 'Grammatista/Parser/Dwoo.class.php', 'GrammatistaParserPcre' => 'Grammatista/Parser/Pcre.class.php', 'GrammatistaParserPcreSmarty' => 'Grammatista/Parser/Pcre/Smarty.class.php', + 'GrammatistaParserPcrePhptal' => 'Grammatista/Parser/Pcre/Phptal.class.php', 'GrammatistaParserPcreSmartySlv3' => 'Grammatista/Parser/Pcre/Smarty/Slv3.class.php', 'GrammatistaParserPhp' => 'Grammatista/Parser/Php.class.php', 'GrammatistaParserPhpAgavi' => 'Grammatista/Parser/Php/Agavi.class.php', @@ -39,6 +40,8 @@ class Grammatista 'GrammatistaScannerFilesystemRecursivedirectoryiterator' => 'Grammatista/Scanner/Filesystem/Recursivedirectoryiterator.class.php', 'GrammatistaStorage' => 'Grammatista/Storage.class.php', 'GrammatistaStoragePdo' => 'Grammatista/Storage/Pdo.class.php', + 'GrammatistaStorageSQLite' => 'Grammatista/Storage/SQLite.class.php', + 'GrammatistaStorageMySQL' => 'Grammatista/Storage/MySQL.class.php', 'GrammatistaTranslatable' => 'Grammatista/Translatable.class.php', 'GrammatistaTranslatablePdo' => 'Grammatista/Translatable/Pdo.class.php', 'GrammatistaValueholder' => 'Grammatista/Valueholder.class.php', diff --git a/lib/Grammatista/Parser/Pcre.class.php b/lib/Grammatista/Parser/Pcre.class.php index 2a14a59..8c3a823 100644 --- a/lib/Grammatista/Parser/Pcre.class.php +++ b/lib/Grammatista/Parser/Pcre.class.php @@ -68,6 +68,8 @@ public function parse(GrammatistaEntity $entity) if(!$this->validate($key, $value)) { $problem = true; // var_dump('problem!'); + } else { + $info[$key] = $this->transform($value); } } @@ -106,6 +108,18 @@ protected function findLine($content, $offset) return preg_match_all('/$/m', substr($content, 0, $offset), $matches); } + protected function transform($value) + { + if(isset($this->options['pcre.transform'])) { + foreach((array)$this->options['pcre.transform'] as $search => $replace) + { + $value = str_replace($search, $replace, $value); + } + } + + return $value; + } + abstract protected function validate($name, $value); } diff --git a/lib/Grammatista/Parser/Pcre/Phptal.class.php b/lib/Grammatista/Parser/Pcre/Phptal.class.php new file mode 100644 index 0000000..6b91754 --- /dev/null +++ b/lib/Grammatista/Parser/Pcre/Phptal.class.php @@ -0,0 +1,46 @@ +options['pcre.comment_pattern'])) { + $this->options['pcre.comment_pattern'] = '/\)]+?)\s*-->(?!.*?php:.*?tm\._)/s'; + } + + if(!isset($this->options['pcre.patterns'])) { + $this->options['pcre.patterns'] = array( + '/php:.*?tm\._\((["\'](?P.+?)["\'])([,\s]+["\'](?P.+?)["\'])/ms' => true, + '/php:.*?tm\.__\((["\'](?P.+?)["\'])([,\s]+["\'](?P.+?)["\'])([,\s]+.+?)([,\s]+["\'](?P.+?)["\'])/ms' => true, + ); + } + } + + public function handles(GrammatistaEntity $entity) + { + $retval = $entity->type == 'tal'; + + if($retval) { + Grammatista::dispatchEvent('grammatista.parser.handles', array('entity' => $entity)); + } + + return $retval; + } + + protected function validate($name, $value) + { + switch($name) { + case 'singular_message': + case 'plural_message': + return preg_match('/[\{\}]/', $value) == 0; + case 'domain': + return preg_match('/\$/', $value) == 0; + case 'comment': + return true; + } + } +} + +?> \ No newline at end of file diff --git a/lib/Grammatista/Storage/MySQL.class.php b/lib/Grammatista/Storage/MySQL.class.php new file mode 100644 index 0000000..a3f02f2 --- /dev/null +++ b/lib/Grammatista/Storage/MySQL.class.php @@ -0,0 +1,38 @@ +connection->exec(' + DROP TABLE IF EXISTS translatables; + CREATE TABLE translatables( + item_name TEXT, + line INTEGER, + domain TEXT, + singular_message TEXT, + plural_message TEXT, + comment TEXT, + parser_name TEXT + ) COLLATE utf8_unicode_ci + '); + + $this->connection->exec(' + DROP TABLE IF EXISTS warnings; + CREATE TABLE warnings( + item_name TEXT, + line INTEGER, + domain TEXT, + singular_message TEXT, + plural_message TEXT, + comment TEXT, + parser_name TEXT + ) COLLATE utf8_unicode_ci + '); + } +} + +?> \ No newline at end of file diff --git a/lib/Grammatista/Storage/Pdo.class.php b/lib/Grammatista/Storage/Pdo.class.php index 8f3837c..f66e5f8 100644 --- a/lib/Grammatista/Storage/Pdo.class.php +++ b/lib/Grammatista/Storage/Pdo.class.php @@ -1,60 +1,36 @@ options['pdo.dsn'] = null; - $this->options['pdo.username'] = null; - $this->options['pdo.password'] = null; - $this->options['pdo.driver_options'] = array(); - $this->options['pdo.attributes'] = array(); - $this->options['pdo.init_queries'] = array(); - $this->options['pdo.translatable_class_name'] = 'GrammatistaTranslatablePdo'; - $this->options['pdo.translatable_class_ctorargs'] = array(); - - parent::__construct($options); - - // TODO: checks <: - if(!isset($this->options['pdo.attributes'][PDO::ATTR_ERRMODE])) { - $this->options['pdo.attributes'][PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; - } - - $this->connection = new PDO($this->options['pdo.dsn'], $this->options['pdo.username'], $this->options['pdo.password'], $this->options['pdo.driver_options']); - foreach((array)$this->options['pdo.attributes'] as $attribute => $value) { - $this->connection->setAttribute($attribute, $value); - } - foreach((array)$this->options['pdo.init_queries'] as $query) { - $this->connection->executeQuery($query); + public function __construct(array $options = array()) + { + $this->options['pdo.dsn'] = null; + $this->options['pdo.username'] = null; + $this->options['pdo.password'] = null; + $this->options['pdo.driver_options'] = array(); + $this->options['pdo.attributes'] = array(); + $this->options['pdo.init_queries'] = array(); + $this->options['pdo.translatable_class_name'] = 'GrammatistaTranslatablePdo'; + $this->options['pdo.translatable_class_ctorargs'] = array(); + + parent::__construct($options); + + // TODO: checks <: + if(!isset($this->options['pdo.attributes'][PDO::ATTR_ERRMODE])) { + $this->options['pdo.attributes'][PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; + } + + $this->connection = new PDO($this->options['pdo.dsn'], $this->options['pdo.username'], $this->options['pdo.password'], $this->options['pdo.driver_options']); + foreach((array)$this->options['pdo.attributes'] as $attribute => $value) { + $this->connection->setAttribute($attribute, $value); } - // TODO: make configurable - $this->connection->exec(' - CREATE TABLE translatables( - item_name TEXT, - line INTEGER, - domain TEXT, - singular_message TEXT, - plural_message TEXT, - comment TEXT, - parser_name TEXT - ) - '); - - $this->connection->exec(' - CREATE TABLE warnings( - item_name TEXT, - line INTEGER, - domain TEXT, - singular_message TEXT, - plural_message TEXT, - comment TEXT, - parser_name TEXT - ) - '); - } + foreach((array)$this->options['pdo.init_queries'] as $query) { + $this->connection->query($query); + } + } public function readTranslatables($unique = true, $order = 'domain') { diff --git a/lib/Grammatista/Storage/SQLite.class.php b/lib/Grammatista/Storage/SQLite.class.php new file mode 100644 index 0000000..81377a5 --- /dev/null +++ b/lib/Grammatista/Storage/SQLite.class.php @@ -0,0 +1,36 @@ +connection->exec(' + CREATE TABLE translatables( + item_name TEXT, + line INTEGER, + domain TEXT, + singular_message TEXT, + plural_message TEXT, + comment TEXT, + parser_name TEXT + ) + '); + + $this->connection->exec(' + CREATE TABLE warnings( + item_name TEXT, + line INTEGER, + domain TEXT, + singular_message TEXT, + plural_message TEXT, + comment TEXT, + parser_name TEXT + ) + '); + } +} + +?> \ No newline at end of file