Exercise\HTMLPurifierBundle\CacheWarmer\SerializerCacheWarmer::warmUp PHP Метод

warmUp() публичный Метод

См. также: Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface::warmUp()
public warmUp ( $cacheDir )
    public function warmUp($cacheDir)
    {
        foreach ($this->paths as $path) {
            if (!is_dir($path)) {
                if (false === @mkdir($path, 0777, true)) {
                    throw new \RuntimeException(sprintf('Unable to create the HTMLPurifier Serializer cache directory "%s".', $path));
                }
            } elseif (!is_writable($path)) {
                throw new \RuntimeException(sprintf('The HTMLPurifier Serializer cache directory "%s" is not writeable for the current system user.', $path));
            }
        }
        // build htmlPurifier cache for HTML/CSS & URIs with the other Symfony cache warmups. Fixes issue #22
        $this->htmlPurifier->purify('<div style="border: thick">-2</div>');
        $this->htmlPurifier->purify('<div style="background:url(\'http://www.example.com/x.gif\');">');
    }

Usage Example

 public function testShouldCreatePaths()
 {
     if (!is_writable(sys_get_temp_dir())) {
         $this->markTestSkipped(sprintf('The system temp directory "%s" is not writeable for the current system user.', sys_get_temp_dir()));
     }
     $path = sys_get_temp_dir() . '/' . uniqid('htmlpurifierbundle');
     $cacheWarmer = new SerializerCacheWarmer(array($path), new \HTMLPurifier());
     $cacheWarmer->warmUp(null);
     $this->assertTrue(is_dir($path));
     $this->assertTrue(is_writeable($path));
     rmdir($path);
 }