-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
18 changed files
with
177 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
defaults: | ||
target: | ||
host: www.somehost.com | ||
scheme: https:// | ||
|
||
Sections: | ||
website: | ||
rules: | ||
- HttpHeaderXSSProtection | ||
- HttpHeaderXSSProtectionSecure | ||
- HttpHeaderExposePHP | ||
- HttpHeaderContentTypeNoSniffing | ||
- HttpHeaderCookieWithHttpOnlyFlag | ||
|
||
|
||
- HttpHeaderHSTSPresent | ||
- HttpHeaderHSTSWithSubdomains | ||
- HttpHeaderCookieWithHttpSecureFlag | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
namespace Frickelbruder\KickOff\Configuration; | ||
|
||
use Frickelbruder\KickOff\Rules\ConfigurableRuleInterface; | ||
use Frickelbruder\KickOff\Rules\Exceptions\RuleNotConfigurableException; | ||
|
||
class RuleBuilder { | ||
|
||
public function buildRules($config) { | ||
$rules = array(); | ||
foreach($config as $name => $values) { | ||
$className = $values['class']; | ||
$class = new $className(); | ||
$this->addMethodCalls( $values, $class ); | ||
$this->addConfiguration( $values, $class ); | ||
$rules[$name] = $class; | ||
} | ||
return $rules; | ||
} | ||
|
||
/** | ||
* @param $values | ||
* @param $class | ||
*/ | ||
private function addMethodCalls($config, $class) { | ||
if( isset( $config['calls'] ) && is_array( $config['calls'] ) ) { | ||
foreach( $config['calls'] as $calls ) { | ||
$method = $calls[0]; | ||
$params = $calls[1]; | ||
call_user_func_array( array( $class, $method ), $params ); | ||
} | ||
} | ||
|
||
} | ||
|
||
private function addConfiguration($config, $class) { | ||
if(empty($config['configuration'])) { | ||
return; | ||
} | ||
if(!(isset($config['configuration']) && $class instanceof ConfigurableRuleInterface)) { | ||
throw new RuleNotConfigurableException($config['class'] . ' is not configurable.'); | ||
} | ||
$this->addMethodCalls(array('calls' => $config['configuration']), $class); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
namespace Frickelbruder\KickOff\Rules; | ||
|
||
use Frickelbruder\KickOff\Rules\Exceptions\FieldNotConfigurableException; | ||
|
||
abstract class ConfigurableRuleBase extends RuleBase implements ConfigurableRuleInterface { | ||
|
||
protected $configurableField = array(); | ||
|
||
public function set($key, $value) { | ||
|
||
if(!in_array($key, $this->configurableField)) { | ||
throw new FieldNotConfigurableException("$key is not configurable"); | ||
} | ||
|
||
$this->$key = $value; | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
namespace Frickelbruder\KickOff\Rules; | ||
|
||
interface ConfigurableRuleInterface extends RuleInterface { | ||
|
||
public function set($key, $value); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
namespace Frickelbruder\KickOff\Rules\Exceptions; | ||
|
||
class FieldNotConfigurableException extends \Exception { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
namespace Frickelbruder\KickOff\Rules\Exceptions; | ||
|
||
class RuleNotConfigurableException extends \Exception { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.