@ 2013-12-30T19:32:13Z <?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();
$this->setPolicySourceDirectives();
}
private function setPolicySourceDirectives(){
$refl = new ReflectionClass(__CLASS__);
$srcPattern = '/.+_SRC$/';
foreach ($refl->getConstants() as $constant => $value){
if (preg_match($srcPattern, $constant)){
print self::{$constant};
}
}
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.010 0.042 12.40 5.4.22 0.016 0.056 12.40 5.4.21 0.012 0.040 12.40 5.4.20 0.010 0.048 12.40 5.4.19 0.013 0.038 12.39 5.4.18 0.011 0.042 12.39 5.4.17 0.010 0.044 12.40 5.4.16 0.009 0.041 12.40 5.4.15 0.016 0.044 12.39 5.4.14 0.009 0.040 12.08 5.4.13 0.011 0.039 12.06 5.4.12 0.009 0.048 12.03 5.4.11 0.014 0.047 12.03 5.4.10 0.011 0.039 12.03 5.4.9 0.012 0.038 12.03 5.4.8 0.010 0.039 12.03 5.4.7 0.011 0.039 12.02 5.4.6 0.010 0.036 12.03 5.4.5 0.012 0.044 12.02 5.4.4 0.010 0.036 12.01 5.4.3 0.008 0.042 12.01 5.4.2 0.011 0.040 12.00 5.4.1 0.009 0.039 12.01 5.4.0 0.010 0.038 11.50 5.3.28 0.019 0.053 12.71 5.3.27 0.010 0.044 12.72 5.3.26 0.009 0.041 12.72 5.3.25 0.011 0.039 12.72 5.3.24 0.011 0.041 12.72 5.3.23 0.011 0.039 12.71 5.3.22 0.010 0.041 12.68 5.3.21 0.012 0.039 12.68 5.3.20 0.012 0.036 12.68 5.3.19 0.009 0.041 12.68 5.3.18 0.010 0.042 12.67 5.3.17 0.011 0.042 12.67 5.3.16 0.013 0.051 12.67 5.3.15 0.009 0.045 12.67 5.3.14 0.012 0.047 12.66 5.3.13 0.012 0.043 12.66 5.3.12 0.021 0.054 12.66 5.3.11 0.011 0.044 12.66 5.3.10 0.010 0.044 12.13 5.3.9 0.010 0.044 12.10 5.3.8 0.012 0.040 12.09 5.3.7 0.012 0.041 12.09 5.3.6 0.010 0.044 12.07 5.3.5 0.013 0.040 12.02 5.3.4 0.011 0.049 12.02 5.3.3 0.008 0.039 11.99 5.3.2 0.009 0.041 11.76 5.3.1 0.011 0.041 11.73 5.3.0 0.017 0.056 11.71
preferences:dark mode live preview
135.78 ms | 1394 KiB | 7 Q