diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5fe36f4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +composer.phar +composer.lock +bin +vendor +apidocs \ No newline at end of file diff --git a/src/Base.php b/src/ExampleResources/Base.php similarity index 72% rename from src/Base.php rename to src/ExampleResources/Base.php index 41134e3..64c3c30 100644 --- a/src/Base.php +++ b/src/ExampleResources/Base.php @@ -1,6 +1,12 @@ container['db_config']['username'], $this->container['db_config']['password']); } catch (Exception $e) { - throw new Tonic\NotFoundException; + throw new NotFoundException; } } -} \ No newline at end of file +} diff --git a/src/Databases.php b/src/ExampleResources/Databases.php similarity index 91% rename from src/Databases.php rename to src/ExampleResources/Databases.php index f9f9153..05ef0ca 100644 --- a/src/Databases.php +++ b/src/ExampleResources/Databases.php @@ -1,4 +1,8 @@ getRel('database'); diff --git a/src/Rel.php b/src/ExampleResources/Rel.php similarity index 65% rename from src/Rel.php rename to src/ExampleResources/Rel.php index 74ec26c..d7bf04e 100644 --- a/src/Rel.php +++ b/src/ExampleResources/Rel.php @@ -1,9 +1,14 @@ fetch('rel-'.$name.'.html'); } catch (Exception $e) { - throw new Tonic\NotFoundException; + throw new NotFoundException; } } diff --git a/src/Table.php b/src/ExampleResources/Table.php similarity index 89% rename from src/Table.php rename to src/ExampleResources/Table.php index 9c0cf56..b18a11a 100644 --- a/src/Table.php +++ b/src/ExampleResources/Table.php @@ -1,4 +1,9 @@ query('SELECT * FROM '.$table.' LIMIT '.$page.',10;'); if (!$statement) { - throw new Tonic\NotFoundException; + throw new NotFoundException; } $data = array(); @@ -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'); diff --git a/src/Tables.php b/src/ExampleResources/Tables.php similarity index 91% rename from src/Tables.php rename to src/ExampleResources/Tables.php index c52cec2..3971559 100644 --- a/src/Tables.php +++ b/src/ExampleResources/Tables.php @@ -1,4 +1,8 @@ getRel('table'); diff --git a/web/dispatch.php b/web/dispatch.php index 13560eb..c6bb190 100644 --- a/web/dispatch.php +++ b/web/dispatch.php @@ -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); @@ -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';