Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Page Rules Implementation #35

Open
wants to merge 1 commit into
base: 2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions code/Rules/Items/Actions/RuleAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
namespace Steadlane\CloudFlare\Rules;

use SilverStripe\Core\Object;

class RuleAction extends Object
{
/**
* This represents the action that the inheriting page rule should trigger, ie: cache_level, browser_cache_ttl,
* rocket_loader etc
*
* @var string
*/
protected $actionId;

/**
* @var int|string This value is dependent on the action
*/
protected $value;

/**
* Sets the action id, ie: cache_level, browser_cache_ttl, rocket_loader etc
*
* @param string $actionId
*
* @return $this
*/
public function setActionId($actionId)
{
$this->actionId = $actionId;

return $this;
}

/**
* Gets the action id
*
* @return string
*/
public function getActionId()
{
return $this->actionId;
}

/**
* Set the value for this objects action id
*
* @param int|string $value
*
* @return $this
*/
public function setValue($value)
{
$this->value = $value;

return $this;
}

/**
* Get the value of this objects action id
*
* @return int|string
*/
public function getValue()
{
return $this->value;
}

/**
* Converts this object to an array in the format expected by CloudFlare
*
* @return array
*/
public function toArray()
{
return array(
'id' => $this->getActionId(),
'value' => $this->getValue()
);
}

/**
* Converts this object to a JSON string in the format expected by CloudFlare
*
* @return array
*/
public function toJson() {
return json_encode($this->toArray());
}
}
52 changes: 52 additions & 0 deletions code/Rules/Items/Actions/RuleActionList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
namespace Steadlane\CloudFlare\Rules;

use SilverStripe\Core\Object;

class RuleActionList extends Object
{
/**
* @var array An array of RuleAction's
*/
protected $items = array();

/**
* Pushes a RuleAction object into this object
*
* @param \Steadlane\CloudFlare\Rules\RuleAction $item
*/
public function push(RuleAction $item)
{
if (in_array($item, $this->items)) {
return;
}

$this->items[] = $item;
}

/**
* Converts all children of this object into an array
*
* @return array
*/
public function toArray()
{
$stack = array();

foreach ($this->items as $item) {
$stack[] = $item->toArray();
}

return $stack;
}

/**
* Converts all children of this object into an array and outputs it as JSON
*
* @return string
*/
public function toJson()
{
return json_encode($this->toArray());
}
}
Loading