From 4f260cf8659f4f143e27f056b24ca389b8c54366 Mon Sep 17 00:00:00 2001 From: Alexander Kiryuhin Date: Fri, 14 Feb 2014 01:03:30 +0400 Subject: ~ Fix autoloader --- DependencyInjection/Configuration.php | 20 --- DependencyInjection/nxpRutilsExtension.php | 28 ---- Resources/config/services.yml | 5 - Resources/doc/index.rst | 41 ----- Twig/RutilsExtension.php | 170 --------------------- composer.json | 2 +- nxpRutilsBundle.php | 9 -- src/NXP/DependencyInjection/Configuration.php | 20 +++ src/NXP/DependencyInjection/nxpRutilsExtension.php | 28 ++++ src/NXP/Resources/config/services.yml | 5 + src/NXP/Resources/doc/index.rst | 41 +++++ src/NXP/Twig/RutilsExtension.php | 170 +++++++++++++++++++++ src/NXP/nxpRutilsBundle.php | 9 ++ 13 files changed, 274 insertions(+), 274 deletions(-) delete mode 100644 DependencyInjection/Configuration.php delete mode 100644 DependencyInjection/nxpRutilsExtension.php delete mode 100644 Resources/config/services.yml delete mode 100644 Resources/doc/index.rst delete mode 100644 Twig/RutilsExtension.php delete mode 100644 nxpRutilsBundle.php create mode 100644 src/NXP/DependencyInjection/Configuration.php create mode 100644 src/NXP/DependencyInjection/nxpRutilsExtension.php create mode 100644 src/NXP/Resources/config/services.yml create mode 100644 src/NXP/Resources/doc/index.rst create mode 100644 src/NXP/Twig/RutilsExtension.php create mode 100644 src/NXP/nxpRutilsBundle.php diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php deleted file mode 100644 index 45b3ca8..0000000 --- a/DependencyInjection/Configuration.php +++ /dev/null @@ -1,20 +0,0 @@ -root('rutils'); - - return $treeBuilder; - } -} diff --git a/DependencyInjection/nxpRutilsExtension.php b/DependencyInjection/nxpRutilsExtension.php deleted file mode 100644 index 2b2a39b..0000000 --- a/DependencyInjection/nxpRutilsExtension.php +++ /dev/null @@ -1,28 +0,0 @@ -processConfiguration($configuration, $configs); - - $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - $loader->load('services.yml'); - } -} diff --git a/Resources/config/services.yml b/Resources/config/services.yml deleted file mode 100644 index 431641b..0000000 --- a/Resources/config/services.yml +++ /dev/null @@ -1,5 +0,0 @@ -services: - nxp.twig.rutils_extension: - class: nxp\RutilsBundle\Twig\RutilsExtension - tags: - - { name: twig.extension } \ No newline at end of file diff --git a/Resources/doc/index.rst b/Resources/doc/index.rst deleted file mode 100644 index 4b94f4d..0000000 --- a/Resources/doc/index.rst +++ /dev/null @@ -1,41 +0,0 @@ -Rutils Symfony 2 Bundle -======================= - -Простой бандл для Symfony 2 содержащий в себе расширение для Twig, позволяющее использовать функции из библиотеки RUtils_ в шаблонах. - -Допускается как вызов в стиле функций:: - - {{ getPlural(10, ['гвоздь', 'гвоздя', 'гвоздей']) }} - -так и в стиле фильтров:: - - {{ 10 | getPlural(['гвоздь', 'гвоздя', 'гвоздей']) }} - -Поддерживаются все методы библиотеки: - -Числительные:: - getInWords\2 - вывод числа прописью - getInWordsInt\2 - вывод числа прописью - getInWordsFloat\2 - вывод числа прописью - getPlural\3 - выбор формы множественного числа и вывод вместе с числом - choosePlural\2 - выбор только формы множественного числа - sumString\3 - выбор формы и вывод прописью - getRubles\2 - вывод суммы денег в рублях - -Даты:: - ruStrFTime\6 - вывод даты строкой - distanceOfTimeInWords\3 - временной период - getAge\1 - возраст - -Транслитерация:: - translify\1 - транслитерация - detranslify\1 - обратное преобразование - slugify\1 - подготовка для использования в URL'ях или путях - -Типографика:: - typography\2 - -TODO:: - написать нормальную документацию - -.. _RUtils: https://github.com/Andre-487/php_rutils/ \ No newline at end of file diff --git a/Twig/RutilsExtension.php b/Twig/RutilsExtension.php deleted file mode 100644 index d4cf8c2..0000000 --- a/Twig/RutilsExtension.php +++ /dev/null @@ -1,170 +0,0 @@ - - */ - -namespace nxp\RutilsBundle\Twig; - -use php_rutils\RUtils; -use php_rutils\struct\TimeParams; - -class RutilsExtension extends \Twig_Extension -{ - public function getFilters() - { - $numeral = RUtils::numeral(); - $date = RUtils::dt(); - $translit = RUtils::translit(); - $typography = RUtils::typo(); - return [ - new \Twig_SimpleFilter('getInWords', function ($amount, $gender = RUtils::MALE) use ($numeral) { - return $numeral->getInWords($amount, $gender); - }), - new \Twig_SimpleFilter('getInWordsInt', function ($amount, $gender = RUtils::MALE) use ($numeral) { - return $numeral->getInWordsInt($amount, $gender); - }), - new \Twig_SimpleFilter('getInWordsFloat', function ($amount, $gender = RUtils::MALE) use ($numeral) { - return $numeral->getInWordsFloat($amount, $gender); - }), - new \Twig_SimpleFilter('getPlural', function ($amount, array $variants, $absence = null) use ($numeral) { - return $numeral->getPlural($amount, $variants, $absence); - }), - new \Twig_SimpleFilter('choosePlural', function ($amount, array $variants) use ($numeral) { - return $numeral->choosePlural($amount, $variants); - }), - new \Twig_SimpleFilter('sumString', function ($amount, $gender, array $variants = null) use ($numeral) { - return $numeral->sumString($amount, $gender, $variants); - }), - new \Twig_SimpleFilter('getRubles', function ($amount, $zeroForKopeck = false) use ($numeral) { - return $numeral->getRubles($amount, $zeroForKopeck); - }), - new \Twig_SimpleFilter('ruStrFTime', function ( - \DateTime $dateTime, - $format = 'd F Y', - $monthInflected = false, - $dayInflected = false, - $preposition = false, - $timezone = null - ) use ($date) { - $params = TimeParams::create( - [ - 'date' => $dateTime, - 'format' => $format, - 'monthInflected' => $monthInflected, - 'dayInflected' => $dayInflected, - 'preposition' => $preposition, - 'timezone' => $timezone - ] - ); - return $date->ruStrFTime($params); - }), - new \Twig_SimpleFilter('distanceOfTimeInWords', function ( - $toTime, - $fromTime = null, - $accuracy = RUtils::ACCURACY_YEAR - ) use ($date) { - return $date->distanceOfTimeInWords($toTime, $fromTime, $accuracy); - }), - new \Twig_SimpleFilter('getAge', function ($birthDate) use ($date) { - return $date->getAge($birthDate); - }), - new \Twig_SimpleFilter('translify', function ($inString) use ($translit) { - return $translit->translify($inString); - }), - new \Twig_SimpleFilter('detranslify', function ($inString) use ($translit) { - return $translit->detranslify($inString); - }), - new \Twig_SimpleFilter('slugify', function ($inString) use ($translit) { - return $translit->slugify($inString); - }), - new \Twig_SimpleFilter('typography', function ($text, array $rules = null) use ($typography) { - return $typography->typography($text, $rules); - }) - ]; - } - - - public function getFunctions() - { - $numeral = RUtils::numeral(); - $date = RUtils::dt(); - $translit = RUtils::translit(); - $typography = RUtils::typo(); - return [ - new \Twig_SimpleFunction('getInWords', function ($amount, $gender = RUtils::MALE) use ($numeral) { - return $numeral->getInWords($amount, $gender); - }), - new \Twig_SimpleFunction('getInWordsInt', function ($amount, $gender = RUtils::MALE) use ($numeral) { - return $numeral->getInWordsInt($amount, $gender); - }), - new \Twig_SimpleFunction('getInWordsFloat', function ($amount, $gender = RUtils::MALE) use ($numeral) { - return $numeral->getInWordsFloat($amount, $gender); - }), - new \Twig_SimpleFunction('getPlural', function ($amount, array $variants, $absence = null) use ($numeral) { - return $numeral->getPlural($amount, $variants, $absence); - }), - new \Twig_SimpleFunction('choosePlural', function ($amount, array $variants) use ($numeral) { - return $numeral->choosePlural($amount, $variants); - }), - new \Twig_SimpleFunction('sumString', function ($amount, $gender, array $variants = null) use ($numeral) { - return $numeral->sumString($amount, $gender, $variants); - }), - new \Twig_SimpleFunction('getRubles', function ($amount, $zeroForKopeck = false) use ($numeral) { - return $numeral->getRubles($amount, $zeroForKopeck); - }), - new \Twig_SimpleFunction('ruStrFTime', function ( - \DateTime $dateTime, - $format = 'd F Y', - $monthInflected = false, - $dayInflected = false, - $preposition = false, - $timezone = null - ) use ($date) { - $params = TimeParams::create( - [ - 'date' => $dateTime, - 'format' => $format, - 'monthInflected' => $monthInflected, - 'dayInflected' => $dayInflected, - 'preposition' => $preposition, - 'timezone' => $timezone - ] - ); - return $date->ruStrFTime($params); - }), - new \Twig_SimpleFunction('distanceOfTimeInWords', function ( - $toTime, - $fromTime = null, - $accuracy = RUtils::ACCURACY_YEAR - ) use ($date) { - return $date->distanceOfTimeInWords($toTime, $fromTime, $accuracy); - }), - new \Twig_SimpleFunction('getAge', function ($birthDate) use ($date) { - return $date->getAge($birthDate); - }), - new \Twig_SimpleFunction('translify', function ($inString) use ($translit) { - return $translit->translify($inString); - }), - new \Twig_SimpleFunction('detranslify', function ($inString) use ($translit) { - return $translit->detranslify($inString); - }), - new \Twig_SimpleFunction('slugify', function ($inString) use ($translit) { - return $translit->slugify($inString); - }), - new \Twig_SimpleFunction('typography', function ($text, array $rules = null) use ($typography) { - return $typography->typography($text, $rules); - }) - ]; - } - - /** - * Returns the name of the extension. - * - * @return string The extension name - */ - public function getName() - { - return 'rutils_extension'; - } - -} \ No newline at end of file diff --git a/composer.json b/composer.json index 5f13ed3..d0c26c4 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ } ], "autoload": { - "psr-0": {"NXP\\RutilsBundle": ""} + "psr-0": {"NXP": "src/"} }, "require": { "php": ">=5.4.0", diff --git a/nxpRutilsBundle.php b/nxpRutilsBundle.php deleted file mode 100644 index a46734f..0000000 --- a/nxpRutilsBundle.php +++ /dev/null @@ -1,9 +0,0 @@ -root('rutils'); + + return $treeBuilder; + } +} diff --git a/src/NXP/DependencyInjection/nxpRutilsExtension.php b/src/NXP/DependencyInjection/nxpRutilsExtension.php new file mode 100644 index 0000000..2b2a39b --- /dev/null +++ b/src/NXP/DependencyInjection/nxpRutilsExtension.php @@ -0,0 +1,28 @@ +processConfiguration($configuration, $configs); + + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader->load('services.yml'); + } +} diff --git a/src/NXP/Resources/config/services.yml b/src/NXP/Resources/config/services.yml new file mode 100644 index 0000000..431641b --- /dev/null +++ b/src/NXP/Resources/config/services.yml @@ -0,0 +1,5 @@ +services: + nxp.twig.rutils_extension: + class: nxp\RutilsBundle\Twig\RutilsExtension + tags: + - { name: twig.extension } \ No newline at end of file diff --git a/src/NXP/Resources/doc/index.rst b/src/NXP/Resources/doc/index.rst new file mode 100644 index 0000000..4b94f4d --- /dev/null +++ b/src/NXP/Resources/doc/index.rst @@ -0,0 +1,41 @@ +Rutils Symfony 2 Bundle +======================= + +Простой бандл для Symfony 2 содержащий в себе расширение для Twig, позволяющее использовать функции из библиотеки RUtils_ в шаблонах. + +Допускается как вызов в стиле функций:: + + {{ getPlural(10, ['гвоздь', 'гвоздя', 'гвоздей']) }} + +так и в стиле фильтров:: + + {{ 10 | getPlural(['гвоздь', 'гвоздя', 'гвоздей']) }} + +Поддерживаются все методы библиотеки: + +Числительные:: + getInWords\2 - вывод числа прописью + getInWordsInt\2 - вывод числа прописью + getInWordsFloat\2 - вывод числа прописью + getPlural\3 - выбор формы множественного числа и вывод вместе с числом + choosePlural\2 - выбор только формы множественного числа + sumString\3 - выбор формы и вывод прописью + getRubles\2 - вывод суммы денег в рублях + +Даты:: + ruStrFTime\6 - вывод даты строкой + distanceOfTimeInWords\3 - временной период + getAge\1 - возраст + +Транслитерация:: + translify\1 - транслитерация + detranslify\1 - обратное преобразование + slugify\1 - подготовка для использования в URL'ях или путях + +Типографика:: + typography\2 + +TODO:: + написать нормальную документацию + +.. _RUtils: https://github.com/Andre-487/php_rutils/ \ No newline at end of file diff --git a/src/NXP/Twig/RutilsExtension.php b/src/NXP/Twig/RutilsExtension.php new file mode 100644 index 0000000..d4cf8c2 --- /dev/null +++ b/src/NXP/Twig/RutilsExtension.php @@ -0,0 +1,170 @@ + + */ + +namespace nxp\RutilsBundle\Twig; + +use php_rutils\RUtils; +use php_rutils\struct\TimeParams; + +class RutilsExtension extends \Twig_Extension +{ + public function getFilters() + { + $numeral = RUtils::numeral(); + $date = RUtils::dt(); + $translit = RUtils::translit(); + $typography = RUtils::typo(); + return [ + new \Twig_SimpleFilter('getInWords', function ($amount, $gender = RUtils::MALE) use ($numeral) { + return $numeral->getInWords($amount, $gender); + }), + new \Twig_SimpleFilter('getInWordsInt', function ($amount, $gender = RUtils::MALE) use ($numeral) { + return $numeral->getInWordsInt($amount, $gender); + }), + new \Twig_SimpleFilter('getInWordsFloat', function ($amount, $gender = RUtils::MALE) use ($numeral) { + return $numeral->getInWordsFloat($amount, $gender); + }), + new \Twig_SimpleFilter('getPlural', function ($amount, array $variants, $absence = null) use ($numeral) { + return $numeral->getPlural($amount, $variants, $absence); + }), + new \Twig_SimpleFilter('choosePlural', function ($amount, array $variants) use ($numeral) { + return $numeral->choosePlural($amount, $variants); + }), + new \Twig_SimpleFilter('sumString', function ($amount, $gender, array $variants = null) use ($numeral) { + return $numeral->sumString($amount, $gender, $variants); + }), + new \Twig_SimpleFilter('getRubles', function ($amount, $zeroForKopeck = false) use ($numeral) { + return $numeral->getRubles($amount, $zeroForKopeck); + }), + new \Twig_SimpleFilter('ruStrFTime', function ( + \DateTime $dateTime, + $format = 'd F Y', + $monthInflected = false, + $dayInflected = false, + $preposition = false, + $timezone = null + ) use ($date) { + $params = TimeParams::create( + [ + 'date' => $dateTime, + 'format' => $format, + 'monthInflected' => $monthInflected, + 'dayInflected' => $dayInflected, + 'preposition' => $preposition, + 'timezone' => $timezone + ] + ); + return $date->ruStrFTime($params); + }), + new \Twig_SimpleFilter('distanceOfTimeInWords', function ( + $toTime, + $fromTime = null, + $accuracy = RUtils::ACCURACY_YEAR + ) use ($date) { + return $date->distanceOfTimeInWords($toTime, $fromTime, $accuracy); + }), + new \Twig_SimpleFilter('getAge', function ($birthDate) use ($date) { + return $date->getAge($birthDate); + }), + new \Twig_SimpleFilter('translify', function ($inString) use ($translit) { + return $translit->translify($inString); + }), + new \Twig_SimpleFilter('detranslify', function ($inString) use ($translit) { + return $translit->detranslify($inString); + }), + new \Twig_SimpleFilter('slugify', function ($inString) use ($translit) { + return $translit->slugify($inString); + }), + new \Twig_SimpleFilter('typography', function ($text, array $rules = null) use ($typography) { + return $typography->typography($text, $rules); + }) + ]; + } + + + public function getFunctions() + { + $numeral = RUtils::numeral(); + $date = RUtils::dt(); + $translit = RUtils::translit(); + $typography = RUtils::typo(); + return [ + new \Twig_SimpleFunction('getInWords', function ($amount, $gender = RUtils::MALE) use ($numeral) { + return $numeral->getInWords($amount, $gender); + }), + new \Twig_SimpleFunction('getInWordsInt', function ($amount, $gender = RUtils::MALE) use ($numeral) { + return $numeral->getInWordsInt($amount, $gender); + }), + new \Twig_SimpleFunction('getInWordsFloat', function ($amount, $gender = RUtils::MALE) use ($numeral) { + return $numeral->getInWordsFloat($amount, $gender); + }), + new \Twig_SimpleFunction('getPlural', function ($amount, array $variants, $absence = null) use ($numeral) { + return $numeral->getPlural($amount, $variants, $absence); + }), + new \Twig_SimpleFunction('choosePlural', function ($amount, array $variants) use ($numeral) { + return $numeral->choosePlural($amount, $variants); + }), + new \Twig_SimpleFunction('sumString', function ($amount, $gender, array $variants = null) use ($numeral) { + return $numeral->sumString($amount, $gender, $variants); + }), + new \Twig_SimpleFunction('getRubles', function ($amount, $zeroForKopeck = false) use ($numeral) { + return $numeral->getRubles($amount, $zeroForKopeck); + }), + new \Twig_SimpleFunction('ruStrFTime', function ( + \DateTime $dateTime, + $format = 'd F Y', + $monthInflected = false, + $dayInflected = false, + $preposition = false, + $timezone = null + ) use ($date) { + $params = TimeParams::create( + [ + 'date' => $dateTime, + 'format' => $format, + 'monthInflected' => $monthInflected, + 'dayInflected' => $dayInflected, + 'preposition' => $preposition, + 'timezone' => $timezone + ] + ); + return $date->ruStrFTime($params); + }), + new \Twig_SimpleFunction('distanceOfTimeInWords', function ( + $toTime, + $fromTime = null, + $accuracy = RUtils::ACCURACY_YEAR + ) use ($date) { + return $date->distanceOfTimeInWords($toTime, $fromTime, $accuracy); + }), + new \Twig_SimpleFunction('getAge', function ($birthDate) use ($date) { + return $date->getAge($birthDate); + }), + new \Twig_SimpleFunction('translify', function ($inString) use ($translit) { + return $translit->translify($inString); + }), + new \Twig_SimpleFunction('detranslify', function ($inString) use ($translit) { + return $translit->detranslify($inString); + }), + new \Twig_SimpleFunction('slugify', function ($inString) use ($translit) { + return $translit->slugify($inString); + }), + new \Twig_SimpleFunction('typography', function ($text, array $rules = null) use ($typography) { + return $typography->typography($text, $rules); + }) + ]; + } + + /** + * Returns the name of the extension. + * + * @return string The extension name + */ + public function getName() + { + return 'rutils_extension'; + } + +} \ No newline at end of file diff --git a/src/NXP/nxpRutilsBundle.php b/src/NXP/nxpRutilsBundle.php new file mode 100644 index 0000000..a46734f --- /dev/null +++ b/src/NXP/nxpRutilsBundle.php @@ -0,0 +1,9 @@ +