Ejemplo n.º 1
0
    public function testfunctionsDefinitionSpecificFunction()
    {
        $content = <<<'EOT'
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud {hook   name="hello world"  } exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore {function name={intl l="test"}} eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
EOT;
        $functions = SmartyHelper::getFunctionsDefinition($content, array("hook"));
        $this->assertCount(1, $functions);
        $this->assertArrayHasKey("name", $functions[0]);
        $this->assertEquals("hook", $functions[0]["name"]);
        $this->assertArrayHasKey("attributes", $functions[0]);
        $this->assertArrayHasKey("name", $functions[0]["attributes"]);
        $this->assertEquals("hello world", $functions[0]["attributes"]["name"]);
    }
Ejemplo n.º 2
0
 /**
  * Recursively examine files in a directory tree, and extract translatable strings.
  *
  * Returns an array of translatable strings, each item having with the following structure:
  * 'files' an array of file names in which the string appears,
  * 'text' the translatable text
  * 'translation' => the text translation, or an empty string if none available.
  * 'dollar'  => true if the translatable text contains a $
  *
  * @param string $directory the path to the directory to examine
  * @param        $hooks
  *
  * @internal param string $walkMode type of file scanning: WALK_MODE_PHP or WALK_MODE_TEMPLATE
  * @internal param \Thelia\Core\Translation\Translator $translator the current translator
  * @internal param string $currentLocale the current locale
  * @internal param string $domain the translation domain (fontoffice, backoffice, module, etc...)
  * @internal param array $strings the list of strings
  * @return number the total number of translatable texts
  */
 public function walkDir($directory, &$hooks)
 {
     $allowed_exts = array('html', 'tpl', 'xml');
     try {
         /** @var \DirectoryIterator $fileInfo */
         foreach (new \DirectoryIterator($directory) as $fileInfo) {
             if ($fileInfo->isDot()) {
                 continue;
             }
             if ($fileInfo->isDir()) {
                 $this->walkDir($fileInfo->getPathName(), $hooks);
             }
             if ($fileInfo->isFile()) {
                 $ext = $fileInfo->getExtension();
                 if (in_array($ext, $allowed_exts)) {
                     if ($content = file_get_contents($fileInfo->getPathName())) {
                         foreach (SmartyHelper::getFunctionsDefinition($content, array("hook", "hookblock")) as $hook) {
                             $hooks[] = $hook;
                         }
                     }
                 }
             }
         }
     } catch (\UnexpectedValueException $ex) {
         // Directory does not exists => ignore/
     }
 }