public function testSuccessResolve() { $callbackInvocationCount = 0; $callback = function () use(&$callbackInvocationCount) { $asset1 = new Asset\StringAsset('bacon'); $asset2 = new Asset\StringAsset('eggs'); $asset3 = new Asset\StringAsset('Mud'); $asset1->mimetype = 'text/plain'; $asset2->mimetype = 'text/plain'; $asset3->mimetype = 'text/plain'; $callbackInvocationCount += 1; $assetName = "asset{$callbackInvocationCount}"; return ${$assetName}; }; $aggregateResolver = $this->getMock('AssetManager\\Resolver\\ResolverInterface'); $aggregateResolver->expects($this->exactly(3))->method('resolve')->will($this->returnCallback($callback)); $resolver = new CollectionResolver(array('myCollection' => array('bacon', 'eggs', 'mud'))); $mimeResolver = new MimeResolver(); $assetFilterManager = new AssetFilterManager(); $assetFilterManager->setMimeResolver($mimeResolver); $resolver->setAggregateResolver($aggregateResolver); $resolver->setAssetFilterManager($assetFilterManager); $collectionResolved = $resolver->resolve('myCollection'); $this->assertEquals($collectionResolved->mimetype, 'text/plain'); $this->assertTrue($collectionResolved instanceof Asset\AssetCollection); }
/** * {@inheritDoc} */ public function resolve($name) { // Check if we are resolving an asset defined with an absolute path if ($name === realpath($name)) { return $this->resolveAbsolutePath($name); } elseif ($this->isGlobalAsset($name)) { $this->loadGlobalCollection($name); } elseif ($this->isTemplateAsset($name)) { $this->loadTemplateCollection($name); } $resolve = parent::resolve($name); if ($resolve instanceof AssetCollection) { $resolve->setTargetPath($this->getPublicPath() . $resolve->getTargetPath()); if (empty($resolve->mimetype)) { $resolve->mimetype = $this->getMimeResolver()->getMimeType($name); } } return $resolve; }