@ 2013-12-30T19:43:31Z <?php
class ContentSecurityPolicy {
const DEFAULT_SRC = 'default-src';
const SCRIPT_SRC = 'script-src';
const OBJECT_SRC = 'object-src';
const STYLE_SRC = 'style-src';
const IMG_SRC = 'img-src';
const MEDIA_SRC = 'media-src';
const FRAME_SRC = 'frame-src';
const FONT_SRC = 'font-src';
const CONNECT_SRC = 'connect-src';
const SOURCE_NONE = "'none'";
const SOURCE_SELF = "'self'";
const SOURCE_UNSAFE_INLINE = "'unsafe-inline'";
const SOURCE_UNSAFE_EVAL = "'unsafe-eval'";
private $policy;
public function __construct() {
$this->policy = array();
$this->setPolicySourceDirectives();
}
private function setPolicySourceDirectives(){
$refl = new ReflectionClass(__CLASS__);
$srcPattern = '/.+_SRC$/';
foreach ($refl->getConstants() as $constant => $value){
if (preg_match($srcPattern, $constant)){
$this->policy[constant(__CLASS__.'::'.$constant)] = array();
}
}
}
private function copy() {
$retval = new ContentSecurityPolicy();
foreach ($this->policy as $directive => $sources) {
foreach ($sources as $source) {
array_push($retval->policy[$directive], $source);
}
}
return $retval;
}
function addSource($directive, $source) {
if (!isset($this->policy[$directive])) {
throw new CSPException("Invalid directive");
}
$this->policy[$directive][] = $source;
return $this;
}
function toString() {
$retval = array();
foreach ($this->policy as $directive => $sources) {
if (sizeof($sources) > 0) {
$retval[] = join(' ', [$directive, join(' ', $sources)]);
}
}
return join('; ', $retval);
}
public function __toString(){
$retval = array();
foreach ($this->policy as $directive => $sources) {
if (sizeof($sources) > 0) {
$retval[] = $directive . ' ' . join(' ', $sources));
}
}
return join('; ', $retval);
}
}
class CSPException extends \Exception {}
$CSP = new ContentSecurityPolicy();
$CSP->addSource(ContentSecurityPolicy::DEFAULT_SRC, ContentSecurityPolicy::SOURCE_SELF) ->addSource(ContentSecurityPolicy::SCRIPT_SRC, ContentSecurityPolicy::SOURCE_SELF)
->addSource(ContentSecurityPolicy::SCRIPT_SRC, 'http://code.jquery.com')
->addSource(ContentSecurityPolicy::STYLE_SRC, ContentSecurityPolicy::SOURCE_SELF)
->addSource(ContentSecurityPolicy::STYLE_SRC, 'https://bootstrapcdn.com')
->addSource(ContentSecurityPolicy::FONT_SRC, 'https://fonts.googleapis.com');
echo $CSP;
exit("\nDone!\n");
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.5.7 0.013 0.073 19.54 5.5.6 0.010 0.033 19.21 5.5.5 0.013 0.070 19.21 5.5.4 0.000 0.087 19.43 5.5.3 0.003 0.040 19.52 5.5.2 0.010 0.063 19.62 5.5.1 0.010 0.073 19.32 5.5.0 0.007 0.083 19.60 5.4.23 0.007 0.067 19.14 5.4.22 0.007 0.083 18.84 5.4.21 0.003 0.083 19.15 5.4.20 0.010 0.073 19.20 5.4.19 0.003 0.060 18.96 5.4.18 0.007 0.043 18.91 5.4.17 0.003 0.053 19.14 5.4.16 0.000 0.050 19.18 5.4.15 0.003 0.040 19.13 5.4.14 0.000 0.063 16.27 5.4.13 0.000 0.043 16.29 5.4.12 0.010 0.070 16.34 5.4.11 0.003 0.077 16.41 5.4.10 0.007 0.073 16.48 5.4.9 0.007 0.077 16.45 5.4.8 0.000 0.073 16.41 5.4.7 0.003 0.053 16.37 5.4.6 0.010 0.067 16.38 5.4.5 0.013 0.053 16.27 5.4.4 0.007 0.073 16.27 5.4.3 0.010 0.070 16.38 5.4.2 0.007 0.067 16.42 5.4.1 0.013 0.057 16.38 5.4.0 0.000 0.047 15.80 5.3.28 0.007 0.080 14.77 5.3.27 0.003 0.057 14.52 5.3.26 0.003 0.047 14.70 5.3.25 0.010 0.070 14.68 5.3.24 0.007 0.040 14.61 5.3.23 0.003 0.080 14.51 5.3.22 0.013 0.060 14.66 5.3.21 0.010 0.033 14.59 5.3.20 0.013 0.073 14.61 5.3.19 0.003 0.057 14.59 5.3.18 0.010 0.047 14.54 5.3.17 0.007 0.073 14.58 5.3.16 0.007 0.043 14.60 5.3.15 0.003 0.080 14.63 5.3.14 0.000 0.040 14.62 5.3.13 0.007 0.077 14.63 5.3.12 0.003 0.040 14.60 5.3.11 0.017 0.063 14.49 5.3.10 0.003 0.037 13.98 5.3.9 0.000 0.070 14.20 5.3.8 0.000 0.053 14.18 5.3.7 0.007 0.060 14.09 5.3.6 0.013 0.030 14.19 5.3.5 0.007 0.033 13.90 5.3.4 0.007 0.073 13.98 5.3.3 0.003 0.050 13.87 5.3.2 0.010 0.073 13.86 5.3.1 0.010 0.067 13.67 5.3.0 0.003 0.070 13.73
preferences:dark mode live preview
141.46 ms | 1394 KiB | 7 Q