Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
161cc66
commit 96df73c
Showing
23 changed files
with
494 additions
and
1 deletion.
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
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,19 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Listen for XDebug", | ||
"type": "php", | ||
"request": "launch", | ||
"port": 9000 | ||
}, | ||
{ | ||
"name": "Launch currently open script", | ||
"type": "php", | ||
"request": "launch", | ||
"program": "${file}", | ||
"cwd": "${fileDirname}", | ||
"port": 9000 | ||
} | ||
] | ||
} |
File renamed without changes.
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 @@ | ||
MIT License | ||
|
||
Copyright (c) 2016 Stephen Rushing | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,28 @@ | ||
{ | ||
"name": "kentico/delivery-sdk-php", | ||
"type": "library", | ||
"license": "MIT", | ||
"version": "0.0.1", | ||
"description": "Kentico Cloud Delivery SDK for PHP", | ||
"authors": [ | ||
{ | ||
"name": "Kentico", | ||
"email": "developerscommunity@kentico.com" | ||
}, | ||
{ | ||
"name": "Stephen Rushing", | ||
"email": "stephen.rushing@esiteful.com" | ||
} | ||
], | ||
"require": { | ||
"nategood/httpful": "^0.2.20" | ||
}, | ||
"require-dev": { | ||
"phpdocumentor/phpdocumentor": "2.*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"KenticoCloud\\": "src/KenticoCloud" | ||
} | ||
} | ||
} |
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,3 @@ | ||
<?php | ||
|
||
header('Location: http://'.$_SERVER['HTTP_HOST'].'/site'); |
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,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="tests/bootstrap.php"> | ||
<testsuites> | ||
<testsuite name="unit"> | ||
<directory>tests/Unit</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist addUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
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,88 @@ | ||
<?php | ||
|
||
namespace KenticoCloud\Delivery; | ||
|
||
class Client { | ||
|
||
const MODE_PREVIEW = 1; | ||
const MODE_PUBLISHED = 2; | ||
|
||
public $projectID = null; | ||
public $apiKey = null; | ||
public $uri = 'https://deliver.kenticocloud.com/'; | ||
public $_debug = true; | ||
public $lastRequest = null; | ||
public $mode = null; | ||
|
||
public function __construct($projectID, $apiKey = null){ | ||
$this->projectID = $projectID; | ||
$this->apiKey = $apiKey; | ||
$self = get_class($this); | ||
$this->mode = $self::MODE_PUBLISHED; | ||
} | ||
|
||
public function buildURL($endpoint, $query = NULL){ | ||
$segments = array( | ||
trim($this->uri, '/'), | ||
trim($this->projectID, '/'), | ||
trim($endpoint, '/') | ||
); | ||
$url = implode('/', $segments); | ||
if(is_array($query)) $query = http_build_query($query); | ||
if(is_string($query)) $url = rtrim($url, '?') . '?' . ltrim($query, '?'); | ||
|
||
return $url; | ||
} | ||
|
||
public function setRequestAuthorization($request){ | ||
$request->addHeader('Authorization', 'Bearer ' . $this->apiKey); | ||
return $request; | ||
} | ||
|
||
public function prepRequest($request){ | ||
$request->_debug = $this->_debug; | ||
$request->mime('json'); | ||
$request = $this->setRequestAuthorization($request); | ||
$this->lastRequest = $request; | ||
return $request; | ||
} | ||
|
||
public function getRequest($endpoint, $params = null){ | ||
$uri = $this->buildURL($endpoint, $params); | ||
|
||
$request = \Httpful\Request::get($uri); | ||
$request = $this->prepRequest($request); | ||
return $request; | ||
} | ||
|
||
public function send($request = null){ | ||
if(!$request) $request = $this->lastRequest; | ||
else $this->lastRequest = $request; | ||
$response = $request->send(); | ||
$this->lastResponse = $response; | ||
return $response; | ||
} | ||
|
||
public function getItems($params){ | ||
$request = $this->getRequest('items', $params); | ||
$response = $this->send(); | ||
|
||
$items = Models\ContentItems::create($response->body); | ||
|
||
return $items; | ||
} | ||
|
||
public function getItem($params){ | ||
$params['limit'] = 1; | ||
$results = $this->getItems($params); | ||
|
||
if(!isset($results->items) || !count($results->items)) return null; | ||
|
||
$item = reset($results->items); | ||
return $item; | ||
} | ||
|
||
|
||
|
||
|
||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace KenticoCloud\Delivery; | ||
|
||
class ContentElementTypesMap extends TypesMap { | ||
|
||
public static $types = array( | ||
'asset' => '\KenticoCloud\Delivery\Models\Asset' | ||
); | ||
|
||
public static $defaultTypeClass = '\KenticoCloud\Delivery\Models\ContentItemElement'; | ||
|
||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace KenticoCloud\Delivery; | ||
|
||
class ContentTypesMap extends TypesMap { | ||
|
||
public static $types = array( | ||
|
||
); | ||
|
||
public static $defaultTypeClass = '\KenticoCloud\Delivery\Models\ContentItem'; | ||
|
||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace KenticoCloud\Delivery\Helpers; | ||
|
||
class Helper { | ||
|
||
static protected $instance = null; | ||
static public function getInstance(){ | ||
$class = get_called_class(); | ||
if(!$class::$instance){ | ||
$class::$instance = new $class; | ||
} | ||
return $class::$instance; | ||
} | ||
|
||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace KenticoCloud\Delivery\Helpers; | ||
|
||
class TextHelper extends Helper { | ||
|
||
//http://syframework.alwaysdata.net/decamelize | ||
function decamelize($input, $separator = '_') { | ||
return strtolower(preg_replace(array('/([a-z\d])([A-Z])/', '/([^_])([A-Z][a-z])/'), '$1'. $separator .'$2', $input)); | ||
} | ||
|
||
//http://stackoverflow.com/a/33122760/3363709 | ||
function camelize($input, $separator = '_') | ||
{ | ||
return str_replace($separator, '', ucwords($input, $separator)); | ||
} | ||
|
||
} |
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,50 @@ | ||
<?php | ||
|
||
namespace KenticoCloud\Delivery\Models; | ||
|
||
|
||
class ContentItem extends Model { | ||
|
||
public $system = null; | ||
public $elements = null; | ||
|
||
public function setSystem($system){ | ||
$this->system = ContentItemSystem::create($system); | ||
return $this; | ||
} | ||
|
||
public function getModularContent($huh){ | ||
|
||
} | ||
|
||
public function getElementValue($name){ | ||
if(!$this->elements) return null; | ||
foreach($this->elements as $element){ | ||
|
||
} | ||
return null; | ||
} | ||
|
||
public function getString($name){ | ||
$value = $this->getElementValue($name); | ||
return (string)$value; | ||
} | ||
|
||
public function getNumber($name){ | ||
$value = $this->getElementValue($name); | ||
return floatval($value) !== intval($value) ? floatval($value) : intval($value); | ||
} | ||
|
||
public function getDateTime($name, $format = NULL){ | ||
$value = $this->getElementValue($name); | ||
if(is_string($value)){ | ||
$value = strtotime($value); | ||
} | ||
if($format){ | ||
$value = date($format, $value); | ||
} | ||
return $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,11 @@ | ||
<?php | ||
|
||
namespace KenticoCloud\Delivery\Models; | ||
|
||
|
||
class ContentItemElement extends Model { | ||
|
||
public $type = null; | ||
public $value = null; | ||
|
||
} |
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,28 @@ | ||
<?php | ||
|
||
namespace KenticoCloud\Delivery\Models; | ||
|
||
|
||
class ContentItemSystem extends Model { | ||
|
||
public $id = null; | ||
public $name = null; | ||
public $codename = null; | ||
public $type = null; | ||
public $sitemap_locations = null; | ||
public $last_modified = null; | ||
|
||
public function getLastModified($format = null){ | ||
if(!$format) return $this->last_modified; | ||
return date($format, $this->last_modified); | ||
} | ||
|
||
public function setLastModified($value){ | ||
if(is_string($value)){ | ||
$value = strtotime($value); | ||
} | ||
$this->last_modified = $value; | ||
return $this; | ||
} | ||
|
||
} |
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,30 @@ | ||
<?php | ||
|
||
namespace KenticoCloud\Delivery\Models; | ||
|
||
use \KenticoCloud\Delivery\ContentTypesMap; | ||
|
||
class ContentItems extends Model { | ||
|
||
public $items = null; | ||
public $pagination = null; | ||
|
||
public function setItems($value){ | ||
$this->items = array(); | ||
foreach($value as $item){ | ||
if(isset($item->system->type)){ | ||
$class = ContentTypesMap::getTypeClass($item->system->type); | ||
}else{ | ||
$class = ContentTypesMap::$defaultTypeClass; | ||
} | ||
$this->items[] = $class::create($item); | ||
} | ||
return $this; | ||
} | ||
|
||
public function setPagination($value){ | ||
$this->pagination = Pagination::create($value); | ||
return $this; | ||
} | ||
|
||
} |
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,12 @@ | ||
<?php | ||
|
||
namespace KenticoCloud\Delivery\Models\Elements; | ||
|
||
|
||
class Asset extends ContentItemElement { | ||
|
||
public $name = null; | ||
public $size = null; | ||
public $url = null; | ||
|
||
} |
Oops, something went wrong.