Nelmio\SecurityBundle\ContentSecurityPolicy\ShaComputer::computeForStyle PHP Method

computeForStyle() public method

public computeForStyle ( $html )
    public function computeForStyle($html)
    {
        if (1 !== preg_match_all('/<style[^>]*>/i', $html, $m)) {
            throw new \InvalidArgumentException('Invalid script, you should use a single <style> tag.');
        }
        preg_match('/^\\s*<style[^>]*>((?s).*)<\\/style>\\s*$/i', $html, $matches);
        if (!isset($matches[1])) {
            throw new \InvalidArgumentException('Invalid script, no <style> tag found.');
        }
        return $this->compute($matches[1]);
    }

Usage Example

 /**
  * @dataProvider provideValidStyleCode
  */
 public function testComputeStyle($expected, $code)
 {
     $shaComputer = new ShaComputer('sha256');
     $this->assertSame($expected, $shaComputer->computeForStyle($code));
 }