Skip to content
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
composer.phar
composer.lock
bin
vendor
apidocs
12 changes: 9 additions & 3 deletions src/Base.php → src/ExampleResources/Base.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?php
namespace ExampleResources;

class Base extends Tonic\Resource
use Exception;
use PDO;
use Tonic\NotFoundException;
use Tonic\Resource;

class Base extends Resource
{

protected function getRel($name)
Expand All @@ -14,8 +20,8 @@ protected function getDB($database)
try {
return new PDO($dsn, $this->container['db_config']['username'], $this->container['db_config']['password']);
} catch (Exception $e) {
throw new Tonic\NotFoundException;
throw new NotFoundException;
}
}

}
}
6 changes: 5 additions & 1 deletion src/Databases.php → src/ExampleResources/Databases.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php
namespace ExampleResources;

use PDO;
use Nocarrier\Hal;

/**
* @uri /
Expand Down Expand Up @@ -36,7 +40,7 @@ function html()
*/
function hal()
{
$hal = new Nocarrier\Hal('/');
$hal = new Hal('/');

$rel = $this->getRel('database');

Expand Down
9 changes: 7 additions & 2 deletions src/Rel.php → src/ExampleResources/Rel.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<?php
namespace ExampleResources;

use Exception;
use Tonic\NotFoundException;
use Tonic\Resource;

/**
* @uri /rel/:name
*/
class Rel extends Tonic\Resource
class Rel extends Resource
{

/**
Expand All @@ -16,7 +21,7 @@ function html($name)
try {
return $smarty->fetch('rel-'.$name.'.html');
} catch (Exception $e) {
throw new Tonic\NotFoundException;
throw new NotFoundException;
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/Table.php → src/ExampleResources/Table.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
namespace ExampleResources;

use PDO;
use Nocarrier\Hal;
use Tonic\NotFoundException;

/**
* @uri /:database/:table
Expand All @@ -12,7 +17,7 @@ private function fetchTableData($database, $table, $page)

$statement = $db->query('SELECT * FROM '.$table.' LIMIT '.$page.',10;');
if (!$statement) {
throw new Tonic\NotFoundException;
throw new NotFoundException;
}

$data = array();
Expand Down Expand Up @@ -56,7 +61,7 @@ function hal($database, $table)
$page = $this->getPage();
$data = $this->fetchTableData($database, $table, $page);

$hal = new Nocarrier\Hal('/tables/'.$table, $data);
$hal = new Hal('/tables/'.$table, $data);

if ($page > 1) $hal->addLink('prev', '/'.$database.'/'.$table.'.hal?page='.($page - 1), 'Previous page');
$hal->addLink('next', '/'.$database.'/'.$table.'.hal?page='.($page + 1), 'Next page');
Expand Down
6 changes: 5 additions & 1 deletion src/Tables.php → src/ExampleResources/Tables.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php
namespace ExampleResources;

use PDO;
use Nocarrier\Hal;

/**
* @uri /:database
Expand Down Expand Up @@ -37,7 +41,7 @@ function html($database)
*/
function hal($database)
{
$hal = new Nocarrier\Hal('/'.$database);
$hal = new Hal('/'.$database);

$rel = $this->getRel('table');

Expand Down
8 changes: 4 additions & 4 deletions web/dispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require_once '../vendor/autoload.php';

$config = array(
'load' => array('../src/*.php') // load resources
'load' => array('../src/ExampleResources/*.php') // load resources
);

$app = new Tonic\Application($config);
Expand Down Expand Up @@ -38,14 +38,14 @@
$response = $resource->exec();

} catch (Tonic\NotFoundException $e) {
$response = new Tonic\Response(404, 'Not found');
$response = new Tonic\Response(404, $e->getMessage());

} catch (Tonic\UnauthorizedException $e) {
$response = new Tonic\Response(401, 'Unauthorized');
$response = new Tonic\Response(401, $e->getMessage());
$response->wwwAuthenticate = 'Basic realm="My Realm"';

} catch (Tonic\Exception $e) {
$response = new Tonic\Response(500, 'Server error');
$response = new Tonic\Response($e->getCode(), $e->getMessage());
}

#$response->contentType = 'text/plain';
Expand Down