diff --git a/.gitignore b/.gitignore index 67a3f1c..340243c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.lock *.phar +.idea vendor *.DS_Store includes/shapefiles diff --git a/src/tdt/formatters/AStrategy.php b/src/tdt/formatters/AStrategy.php index 18007e6..ae3daa7 100644 --- a/src/tdt/formatters/AStrategy.php +++ b/src/tdt/formatters/AStrategy.php @@ -9,9 +9,12 @@ * @author Jan Vansteenlandt */ namespace tdt\formatters; + use tdt\exceptions\TDTException; use tdt\pages\Generator; -abstract class AStrategy { + +abstract class AStrategy +{ protected $rootname; protected $objectToPrint; protected $format; @@ -24,7 +27,8 @@ abstract class AStrategy { * @param string $rootname Name of the rootobject, if used in the print format (i.e. xml) * @param Mixed $objectToPrint Object that needs printing. */ - public function __construct($rootname, &$objectToPrint,$version = "1.0") { + public function __construct($rootname, &$objectToPrint, $version = "1.0") + { $this->version = $version; $this->rootname = $rootname; $this->objectToPrint = &$objectToPrint; @@ -33,29 +37,34 @@ public function __construct($rootname, &$objectToPrint,$version = "1.0") { /** * This function prints the object. uses {@link printHeader()} and {@link printBody()}. */ - public function execute() { + public function execute() + { header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Methods: GET"); header("Expires: Sun, 19 Nov 1978 04:59:59 GMT"); $this->printHeader(); - if (!$this->isObjectAGraph()) + if (!$this->isObjectAGraph()) { $this->printBody(); - else + } else { $this->printGraph(); + } } /* * This function checks wether the object to print is an RDF graph or not */ - protected function isObjectAGraph() { + protected function isObjectAGraph() + { - if($this->objectToPrint instanceof \ARC2_RDFXMLParser) + if ($this->objectToPrint instanceof \ARC2_RDFXMLParser) { return true; + } - foreach ($this->objectToPrint as $prop) + foreach ($this->objectToPrint as $prop) { return ($prop instanceof \ARC2_RDFParser); + } return false; } @@ -73,7 +82,8 @@ abstract public function printBody(); /** * This function will print the body of the responsemessage when the object is a graph. */ - public function printGraph(){ + public function printGraph() + { set_error_header(453, "RDF not supported"); $generator = new Generator($this->rootname . " - formatter cannot process RDF"); $body =""; @@ -84,7 +94,7 @@ public function printGraph(){ $rn = $this->rootname; $body .= ""; $body .= ""; - foreach($this->objectToPrint->$rn->triples as $triple){ + foreach ($this->objectToPrint->$rn->triples as $triple) { $body .= ""; $body .= ""; $body .= ""; @@ -95,10 +105,11 @@ public function printGraph(){ $h = headers_list(); $i = 0; $matches = array(); - while($i < sizeof($h) && !preg_match( "/Link: (.+);rel=next.*/" , $h[$i], $matches)){ + while ($i < sizeof($h) && !preg_match( "/Link: (.+);rel=next.*/", $h[$i], $matches)){ $i++; } - if($i < sizeof($h)){ + + if ($i < sizeof($h)) { $body .= "

Next page

"; } $generator->generate($body); diff --git a/src/tdt/formatters/Formatter.php b/src/tdt/formatters/Formatter.php index ae245f8..e1db3c5 100644 --- a/src/tdt/formatters/Formatter.php +++ b/src/tdt/formatters/Formatter.php @@ -13,7 +13,8 @@ use tdt\exceptions\TDTException; -class Formatter { +class Formatter +{ private $format; @@ -23,9 +24,12 @@ public function __construct($format = "") { /** * sets the requested format in the factory from the request URL + * * @param string $urlformat The format of the request i.e. json,xml,.... + * @throws TDTException */ - public function setFormat($urlformat) { + public function setFormat($urlformat) + { //We define the format like this: // * Check if $urlformat has been set // - if not: probably something fishy happened, set format as error for logging purpose @@ -64,14 +68,15 @@ public function setFormat($urlformat) { } $contentlocation = str_ireplace(".about", "." . $format, $pageURL); header("Content-Location:" . $contentlocation); - } else if ($this->formatExists($urlformat)) { + } elseif ($this->formatExists($urlformat)) { $this->format = $urlformat; } else { throw new TDTException(451, array($urlformat)); } } - private function formatExists($format) { + private function formatExists($format) + { return class_exists("\\tdt\\formatters\\strategies\\$format"); } @@ -79,7 +84,8 @@ private function formatExists($format) { * This function has to create a strategy and print everything using this strategy. */ - public function execute($rootname, $thing) { + public function execute($rootname, $thing) + { $format = "\\tdt\\formatters\\strategies\\" . $this->format; $strategy = new $format($rootname, $thing); @@ -93,11 +99,13 @@ public function execute($rootname, $thing) { * Returns the format that has been set by the request * @return A format object */ - public function getFormat() { + public function getFormat() + { return $this->format; } - public function getFormatterDocumentation() { + public function getFormatterDocumentation() + { $doc = array(); //open the custom directory and loop through it if ($handle = opendir(__DIR__ . '/strategies')) {
subjectpredicateobject
". $triple["s"] ."". $triple["p"] ."". $triple["o"] ."