@ 2013-12-30T19:23:24Z <?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->policy[self::DEFAULT_SRC] = array();
$this->policy[self::SCRIPT_SRC] = array();
$this->policy[self::OBJECT_SRC] = array();
$this->policy[self::STYLE_SRC] = array();
$this->policy[self::IMG_SRC] = array();
$this->policy[self::MEDIA_SRC] = array();
$this->policy[self::FRAME_SRC] = array();
$this->policy[self::FONT_SRC] = array();
$this->policy[self::CONNECT_SRC] = array();
}
private function setPolicySourceDirectives(){
$refl = new ReflectionClass(__CLASS__);
$srcPattern = '/.+_SRC$/';
foreach ($refl->getConstants() as $constant => $value){
if (pref_match($srcPattern, $constant){
print self::$constant . "\n";
}
}
exit;
}
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);
}
}
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->toString();
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.4.23 0.011 0.039 12.40 5.4.22 0.007 0.045 12.41 5.4.21 0.011 0.045 12.40 5.4.20 0.009 0.045 12.41 5.4.19 0.011 0.041 12.40 5.4.18 0.015 0.037 12.40 5.4.17 0.011 0.042 12.41 5.4.16 0.010 0.042 12.40 5.4.15 0.010 0.041 12.40 5.4.14 0.011 0.041 12.09 5.4.13 0.010 0.042 12.07 5.4.12 0.011 0.039 12.04 5.4.11 0.010 0.039 12.04 5.4.10 0.008 0.042 12.03 5.4.9 0.009 0.042 12.04 5.4.8 0.011 0.042 12.03 5.4.7 0.010 0.039 12.03 5.4.6 0.012 0.039 12.03 5.4.5 0.009 0.040 12.03 5.4.4 0.014 0.038 12.02 5.4.3 0.010 0.043 12.02 5.4.2 0.012 0.041 12.01 5.4.1 0.012 0.039 12.01 5.4.0 0.013 0.039 11.50 5.3.28 0.020 0.071 12.71 5.3.27 0.016 0.053 12.72 5.3.26 0.010 0.049 12.72 5.3.25 0.015 0.047 12.72 5.3.24 0.028 0.075 12.72 5.3.23 0.015 0.043 12.71 5.3.22 0.015 0.041 12.68 5.3.21 0.013 0.044 12.68 5.3.20 0.014 0.041 12.68 5.3.19 0.013 0.043 12.67 5.3.18 0.016 0.043 12.67 5.3.17 0.013 0.047 12.67 5.3.16 0.019 0.063 12.68 5.3.15 0.032 0.072 12.67 5.3.14 0.013 0.042 12.66 5.3.13 0.010 0.046 12.66 5.3.12 0.014 0.048 12.66 5.3.11 0.016 0.043 12.66 5.3.10 0.014 0.042 12.13 5.3.9 0.015 0.042 12.10 5.3.8 0.013 0.041 12.09 5.3.7 0.016 0.066 12.10 5.3.6 0.013 0.041 12.08 5.3.5 0.011 0.041 12.03 5.3.4 0.014 0.059 12.03 5.3.3 0.009 0.044 11.99 5.3.2 0.009 0.041 11.76 5.3.1 0.011 0.039 11.73 5.3.0 0.009 0.045 11.72
preferences:dark mode live preview
142.73 ms | 1394 KiB | 7 Q