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

Fix psr voilations #23

Open
wants to merge 1 commit into
base: master
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.lock
*.phar
.idea
vendor
*.DS_Store
includes/shapefiles
35 changes: 23 additions & 12 deletions src/tdt/formatters/AStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
* @author Jan Vansteenlandt <[email protected]>
*/
namespace tdt\formatters;

use tdt\exceptions\TDTException;
use tdt\pages\Generator;
abstract class AStrategy {

abstract class AStrategy
{
protected $rootname;
protected $objectToPrint;
protected $format;
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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 ="";
Expand All @@ -84,7 +94,7 @@ public function printGraph(){
$rn = $this->rootname;
$body .= "<table border=3>";
$body .= "<tr><td>subject</td><td>predicate</td><td>object</td></tr>";
foreach($this->objectToPrint->$rn->triples as $triple){
foreach ($this->objectToPrint->$rn->triples as $triple) {
$body .= "<tr><td>". $triple["s"] ."</td>";
$body .= "<td>". $triple["p"] ."</td>";
$body .= "<td>". $triple["o"] ."</td>";
Expand All @@ -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 .= "<p class='nextpage'><a href='". $matches[1] ."'>Next page</a></p>";
}
$generator->generate($body);
Expand Down
22 changes: 15 additions & 7 deletions src/tdt/formatters/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

use tdt\exceptions\TDTException;

class Formatter {
class Formatter
{

private $format;

Expand All @@ -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
Expand Down Expand Up @@ -64,22 +68,24 @@ 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");
}

/*
* 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);

Expand All @@ -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')) {
Expand Down