/** * Applies version to the supplied path. * * @param string $path A path * @param string|bool|null $version A specific version * * @return string The versionized path */ protected function applyVersion($path, $version = null) { $file = $path; // apply the base path if ('/' !== substr($path, 0, 1)) { $file = $this->basePath . $path; } $reved = $this->summary->get($file); $fullpath = $this->getRoot() . $file; $fullreved = $this->getRoot() . $reved; // $reved or unversioned if (file_exists($fullreved)) { return $reved; // fallback } else { $pattern = preg_replace('/\\.([^\\.]+$)/', '.*.$1', $fullpath); $regex = preg_replace('/\\.([^\\.]+$)/', '\\.[\\d\\w]{8}\\.$1', $fullpath); $base = str_replace($path, '', $fullpath); foreach (glob($pattern) as $filepath) { if (preg_match('#' . $regex . '#', $filepath)) { $result = str_replace($base, '', $filepath); $this->summary->set($file, $result); return $result; } } } return $path; }
/** * {@inheritdoc} */ public function get($id, $domain = 'messages') { if ($this->defines($id, $domain)) { return parent::get($id, $domain); } if ($this->getFallbackCatalogue() !== NULL) { return $this->getFallbackCatalogue()->get($id, $domain); } return ""; }
public function testAddFallbackCatalogue() { $r = $this->getMock('Symfony\\Component\\Config\\Resource\\ResourceInterface'); $r->expects($this->any())->method('__toString')->will($this->returnValue('r')); $r1 = $this->getMock('Symfony\\Component\\Config\\Resource\\ResourceInterface'); $r1->expects($this->any())->method('__toString')->will($this->returnValue('r1')); $catalogue = new MessageCatalogue('en_US', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar'))); $catalogue->addResource($r); $catalogue1 = new MessageCatalogue('en', array('domain1' => array('foo' => 'bar', 'foo1' => 'foo1'))); $catalogue1->addResource($r1); $catalogue->addFallbackCatalogue($catalogue1); $this->assertEquals('foo', $catalogue->get('foo', 'domain1')); $this->assertEquals('foo1', $catalogue->get('foo1', 'domain1')); $this->assertEquals(array($r, $r1), $catalogue->getResources()); }
/** * Get reved filename from summary * * @param $file * * @return string */ protected function getRevedFilename($file) { $this->initializeCacheCatalogue(); return $this->summary->get($file); }