/**
     * Initialize filerev catalogue from cache
     * or generate cache if not already available
     */
    private function initializeCacheCatalogue()
    {
        if (isset($this->catalogue)) {
            return;
        }
        $debug = $this->container->getParameter('grunt.debug');
        $cache = new ConfigCache($this->getCatalogueCachePath(), $debug);
        if (!$cache->isFresh()) {
            $this->initializeCatalogue();
            $content = sprintf(<<<EOF
<?php

use Symfony\\Component\\Translation\\MessageCatalogue;

\$catalogue = new MessageCatalogue(null, %s);

return \$catalogue;

EOF
, var_export($this->catalogue->all(), true));
            $cache->write($content, $this->catalogue->getResources());
            return;
        }
        $this->catalogue = (include $cache);
    }
コード例 #2
0
    /**
     * Initialize filerev catalogue from cache
     * or generate cache if not already available
     */
    protected function initializeCacheCatalogue()
    {
        if (isset($this->summary)) {
            return;
        }
        $cache = new ConfigCache($this->getCatalogueCachePath($this->cacheDir), $this->debug);
        if (!$cache->isFresh()) {
            $this->initializeCatalogue($this->summaryFile);
            $content = sprintf(<<<EOF
<?php

use Symfony\\Component\\Translation\\MessageCatalogue;

\$catalogue = new MessageCatalogue(null, %s);

return \$catalogue;

EOF
, var_export($this->summary->all(), true));
            $cache->write($content, $this->summary->getResources());
            return;
        }
        $this->summary = (include $cache);
    }
コード例 #3
0
 public function testGetAddResource()
 {
     $catalogue = new MessageCatalogue('en');
     $r = $this->getMock('Symfony\\Component\\Config\\Resource\\ResourceInterface');
     $r->expects($this->any())->method('__toString')->will($this->returnValue('r'));
     $catalogue->addResource($r);
     $catalogue->addResource($r);
     $r1 = $this->getMock('Symfony\\Component\\Config\\Resource\\ResourceInterface');
     $r1->expects($this->any())->method('__toString')->will($this->returnValue('r1'));
     $catalogue->addResource($r1);
     $this->assertEquals(array($r, $r1), $catalogue->getResources());
 }
コード例 #4
0
 private function filterCatalogue(MessageCatalogue $catalogue, $domain)
 {
     $filteredCatalogue = new MessageCatalogue($catalogue->getLocale());
     if ($messages = $catalogue->all($domain)) {
         $filteredCatalogue->add($messages, $domain);
     }
     foreach ($catalogue->getResources() as $resource) {
         $filteredCatalogue->addResource($resource);
     }
     if ($metadata = $catalogue->getMetadata('', $domain)) {
         foreach ($metadata as $k => $v) {
             $filteredCatalogue->setMetadata($k, $v, $domain);
         }
     }
     return $filteredCatalogue;
 }
コード例 #5
0
    /**
     * Gets the resources that matches a domain and a locale on a particular catalog
     *
     * @param MessageCatalogue $catalog the catalog
     * @param string $domain the domain name (default is 'messages')
     * @param string $locae the locale, to filter fallbackLocale
     * @return array of FileResource objects
     */
    private function getMatchedResources(MessageCatalogue $catalog, $domain, $locale)
    {
        $matched = array();
        foreach ($catalog->getResources() as $resource) {

            // @see Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
            // filename is domain.locale.format
            $basename = \basename($resource->getResource());
            list($resourceDomain, $resourceLocale, $format) = explode('.', $basename);

            if ($domain === $resourceDomain && $locale === $resourceLocale) {
                $matched[] = $resource;
            }
        }

        return $matched;
    }
コード例 #6
0
 public function testGetAddResource()
 {
     if (!class_exists('Symfony\\Component\\Config\\Loader\\Loader')) {
         $this->markTestSkipped('The "Config" component is not available');
     }
     $catalogue = new MessageCatalogue('en');
     $r = $this->getMock('Symfony\\Component\\Config\\Resource\\ResourceInterface');
     $r->expects($this->any())->method('__toString')->will($this->returnValue('r'));
     $catalogue->addResource($r);
     $catalogue->addResource($r);
     $r1 = $this->getMock('Symfony\\Component\\Config\\Resource\\ResourceInterface');
     $r1->expects($this->any())->method('__toString')->will($this->returnValue('r1'));
     $catalogue->addResource($r1);
     $this->assertEquals(array($r, $r1), $catalogue->getResources());
 }