public function setUp() { $this->css = new CSS(__DIR__, $this->createMock(ResourceMap::class), $this->createMock(Core::class)); $this->css->prepare(); ResourceValidator::$projectRoot = __DIR__ . '/'; ResourceValidator::$webRoot = __DIR__ . '/www/'; // Testing other deprecated functions here ResourceValidator::getWebRelativePath('test.jpg', __DIR__ . '/'); $resourcePath = __DIR__ . '/test.jpg'; file_put_contents($resourcePath, '/** TEST */'); }
/** * Static resource path builder. * * @deprecated Moving to use new samsonphp/view resource an $this->src() should be used * in view file for generating paths to static resources * * @param string $path Relative static resource resource path * @param null $module Entity for path building, if not passed current resource is used * * @return string Static resource path * @throws \samsonphp\resource\exception\ResourceNotFound */ function src($path, $module = null) { // Define resource switch (gettype($module)) { case 'string': // Find resource by identifier $module = m($module); break; case 'object': // Do nothing break; default: // Get current resource $module = m(); } echo '/' . STATIC_RESOURCE_HANDLER . '/?p=' . ResourceValidator::getRelativePath($path, $module->path(), dirname(getcwd())); }
/** * Callback for CSS url(...) rewriting. * * @param array $matches Regular expression matches collection * * @return string Rewritten url(..) with static resource handler url * @throws ResourceNotFound */ public function rewriteUrls($matches) { // Store static resource path $url = $matches[2]; // Validate url for restricted protocols and inline images $validation = array_filter(['data/', 'data:', 'http:', 'https:'], function ($item) use($url) { return strpos($url, $item) !== false; }); // Ignore inline resources if (!count($validation)) { // Remove possible GET, HASH parameters from resource path $url = $this->getOnlyUrl($this->getOnlyUrl($url, '#'), '?'); // Try to find resource and output full error try { $path = ResourceValidator::getProjectRelativePath($url, dirname($this->currentResource)); } catch (ResourceNotFound $e) { throw new ResourceNotFound('Cannot find resource "' . $url . '" in "' . $this->currentResource . '"'); } // Build path to static resource handler return 'url("/' . STATIC_RESOURCE_HANDLER . '/?p=' . $path . '")'; } return $matches[0]; }