Skip to content
Closed
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
6 changes: 3 additions & 3 deletions app/controllers/ErrorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public function errorAction($request)
// get the Exception from the Response
$exception = $response->getException();
switch ($exception->getCode()) {
case Response::NOT_FOUND:
case Apify_Response::NOT_FOUND:
// 404 error - controller or action not found
$viewScript = 'pagenotfound';
break;
case Response::NOT_ACCEPTABLE:
case Apify_Response::NOT_ACCEPTABLE:
// 406 error - content type missing or invalid
break;
default:
Expand All @@ -28,7 +28,7 @@ public function errorAction($request)
}

if ('html' === $request->getContentType()) {
$view = new View();
$view = new Apify_View();
$view->setScript($viewScript);
$view->setLayout('error');
$response->setView($view);
Expand Down
28 changes: 14 additions & 14 deletions app/controllers/IndexController.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
<?php
class IndexController extends Controller
class IndexController extends Apify_Controller
{
/**
* The init() method is called by the request object after the controller
* is instantiated.
*
* @param Request $request
* @param Apify_Request $request
* @return void
* @throws Exception
*/
public function init($request)
{
if (! method_exists($this, $request->getAction().'Action')) {
$message = sprintf('%s(): Intercepted call to "%s" action', __METHOD__, $request->getAction());
throw new Exception($message, Response::NOT_FOUND);
throw new Exception($message, Apify_Response::NOT_FOUND);
}
}

/**
* @route GET /
*
* @param Request $request
* @param Apify_Request $request
* @return View
*/
public function indexAction($request)
{
$view = new View();
$view = new Apify_View();
$view->setLayout('main');

return $view;
Expand All @@ -37,12 +37,12 @@ public function indexAction($request)
* @route GET /?method=example.request
* @route GET /example/request
*
* @param Request $request
* @param Apify_Request $request
* @return View
*/
public function requestAction($request)
{
$view = new View();
$view = new Apify_View();
$view->setLayout('main');

$view->method = $request->getMethod();
Expand All @@ -63,15 +63,15 @@ public function requestAction($request)
* @route GET /example/response.json
* @route GET /example/response.xml
*
* @param Request $request
* @return Response
* @param Apify_Request $request
* @return Apify_Response
*/
public function responseAction($request)
{
// accept JSON and XML
$request->acceptContentTypes(array('json', 'xml'));

$response = new Response();
$response = new Apify_Response();
$response->statusCode = $response->getCode();
$response->contentType = $request->getContentType();
$response->key = 'value';
Expand All @@ -85,19 +85,19 @@ public function responseAction($request)
* @route GET /?method=example.mixed
* @route GET /example/mixed
*
* @param Request $request
* @return View|Response
* @param Apify_Request $request
* @return Apify_View|Apify_Response
*/
public function mixedAction($request)
{
// accept HTML, JSON and XML
$request->acceptContentTypes(array('html', 'json', 'xml'));

if ('html' === $request->getContentType()) {
$response = new View();
$response = new Apify_View();
$response->setLayout('main');
} else {
$response = new Response();
$response = new Apify_Response();
}

$response->method = $request->getMethod();
Expand Down
54 changes: 27 additions & 27 deletions app/controllers/UsersController.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<?php
class UsersController extends Controller
class UsersController extends Apify_Controller
{
/**
* @route GET /?method=users
* @route GET /users
*
* @param Request $request
* @return Response|View
* @param Apify_Request $request
* @return Apify_Response|View
*/
public function indexAction($request)
{
// serve HTML, JSON and XML
$request->acceptContentTypes(array('html', 'json', 'xml'));

if ('html' == $request->getContentType()) {
$response = new View();
$response = new Apify_View();
$response->setLayout('main');
} else {
$response = new Response();
$response = new Apify_Response();
}

$response->users = $this->getModel('User')->findAll();
Expand All @@ -43,14 +43,14 @@ public function showAction($request)
$id = $request->getParam('id');
$user = is_numeric($id) ? $model->find($id) : $model->findBy(array('username'=>$id));
if (! $user) {
throw new Exception('User not found', Response::NOT_FOUND);
throw new Exception('User not found', Apify_Response::NOT_FOUND);
}

if ('html' == $request->getContentType()) {
$response = new View();
$response = new Apify_View();
$response->setLayout('main');
} else {
$response = new Response();
$response = new Apify_Response();
$response->setEtagHeader(md5('/users/' . $user->id));
}

Expand All @@ -62,15 +62,15 @@ public function showAction($request)
* @route POST /?method=users.create&format=json
* @route POST /users/create.json
*
* @param Request $request
* @return Response
* @param Apify_Request $request
* @return Apify_Response
* @throws Exception
*/
public function createAction($request)
{
$request->acceptContentTypes(array('json'));
if ('POST' != $request->getMethod()) {
throw new Exception('HTTP method not allowed', Response::NOT_ALLOWED);
throw new Exception('HTTP method not allowed', Apify_Response::NOT_ALLOWED);
}

try {
Expand All @@ -80,17 +80,17 @@ public function createAction($request)
'email' => $request->getPost('email'),
'gender' => $request->getPost('gender')
));
} catch (ValidationException $e) {
throw new Exception($e->getMessage(), Response::OK);
} catch (Apify_ValidationException $e) {
throw new Exception($e->getMessage(), Apify_Response::OK);
}

$id = $this->getModel('User')->save($user);
if (! is_numeric($id)) {
throw new Exception('An error occurred while creating user', Response::OK);
throw new Exception('An error occurred while creating user', Apify_Response::OK);
}

$response = new Response();
$response->setCode(Response::CREATED);
$response = new Apify_Response();
$response->setCode(Apify_Response::CREATED);
$response->setEtagHeader(md5('/users/' . $id));

return $response;
Expand All @@ -100,42 +100,42 @@ public function createAction($request)
* @route POST /?method=users.update&id=1&format=json
* @route POST /users/1/update.json
*
* @param Request $request
* @return Response
* @param Apify_Request $request
* @return Apify_Response
* @throws Exception
*/
public function updateAction($request)
{
$request->acceptContentTypes(array('json'));
if ('POST' != $request->getMethod()) {
throw new Exception('HTTP method not supported', Response::NOT_ALLOWED);
throw new Exception('HTTP method not supported', Apify_Response::NOT_ALLOWED);
}

$id = $request->getParam('id');

$model = $this->getModel('User');
$user = $model->find($id);
if (! $user) {
throw new Exception('User not found', Response::NOT_FOUND);
throw new Exception('User not found', Apify_Response::NOT_FOUND);
}

try {
$user->username = $request->getPost('username');
} catch (ValidationException $e) {
throw new Exception($e->getMessage(), Response::OK);
} catch (Apify_ValidationException $e) {
throw new Exception($e->getMessage(), Apify_Response::OK);
}
$model->save($user);

// return 200 OK
return new Response();
return new Apify_Response();
}

/**
* @route GET /?method=users.destroy&id=1&format=json
* @route GET /users/1/destroy.json
*
* @param Request $request
* @return Response
* @param Apify_Request $request
* @return Apify_Response
* @throws Exception
*/
public function destroyAction($request)
Expand All @@ -146,11 +146,11 @@ public function destroyAction($request)
$model = $this->getModel('User');
$user = $model->find($id);
if (! $user) {
throw new Exception('User not found', Response::NOT_FOUND);
throw new Exception('User not found', Apify_Response::NOT_FOUND);
}
$model->delete($user->id);

// return 200 OK
return new Response();
return new Apify_Response();
}
}
8 changes: 4 additions & 4 deletions app/models/Post.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
class Post extends Entity
class Post extends Apify_Entity
{
protected $id;
protected $category_id;
Expand All @@ -11,7 +11,7 @@ class Post extends Entity
public function setCategoryId($value)
{
if (! is_numeric($value)) {
throw new ValidationException('The category you have selected is invalid');
throw new Apify_ValidationException('The category you have selected is invalid');
}
$this->category_id = (int) $value;
}
Expand All @@ -20,7 +20,7 @@ public function setTitle($value)
{
$value = htmlspecialchars(strip_tags($value), ENT_QUOTES);
if (empty($value) || strlen($value) < 5) {
throw new ValidationException('The title is shorter than 5 characters');
throw new Apify_ValidationException('The title is shorter than 5 characters');
}
$this->title = $value;
}
Expand All @@ -29,7 +29,7 @@ public function setText($value)
{
$value = htmlspecialchars(strip_tags($value), ENT_QUOTES);
if (empty($value) || strlen($value) < 5) {
throw new ValidationException('The text is shorter than 5 characters');
throw new Apify_ValidationException('The text is shorter than 5 characters');
}
$this->text = $value;
}
Expand Down
10 changes: 5 additions & 5 deletions app/models/PostModel.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
class PostModel extends Model
class PostModel extends Apify_Model
{
/**
* By default, the entity will be persisted to a table with the same name
Expand All @@ -18,7 +18,7 @@ class PostModel extends Model
* @param string $foo
* @param string $bar
* @returns false|obj
* @throws ModelException
* @throws Apify_ModelException
*/
public function findByFooOrBar($foo, $bar)
{
Expand All @@ -29,7 +29,7 @@ public function findByFooOrBar($foo, $bar)
$stmt = $this->execute($sql, array($foo, $bar));
return $stmt->fetch();
} catch (Exception $e) {
throw new ModelException($e->getMessage());
throw new Apify_ModelException($e->getMessage());
}
}

Expand All @@ -40,7 +40,7 @@ public function findByFooOrBar($foo, $bar)
* @param int $categoryId
* @param array $options sort, order, page and count
* @returns false|array
* @throws ModelException
* @throws Apify_ModelException
*/
public function findAllByCategoryId($categoryId, $options)
{
Expand All @@ -66,7 +66,7 @@ public function findAllByCategoryId($categoryId, $options)
$stmt = $this->execute($sql, array($categoryId));
return $stmt->fetchAll();
} catch (Exception $e) {
throw new ModelException($e->getMessage());
throw new Apify_ModelException($e->getMessage());
}
}
}
8 changes: 4 additions & 4 deletions app/models/User.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
class User extends Entity
class User extends Apify_Entity
{
protected $id;
protected $email;
Expand All @@ -14,7 +14,7 @@ class User extends Entity
public function setUsername($value)
{
if (preg_match('/[^a-z0-9\-_.]/i', $value)) { // Undefined variable error fixed
throw new ValidationException('Invalid username');
throw new Apify_ValidationException('Invalid username');
}
$this->username = $value;
}
Expand All @@ -24,7 +24,7 @@ public function setName($value)
{
$value = htmlspecialchars(trim($value), ENT_QUOTES);
if (empty($value) || strlen($value) < 3) {
throw new ValidationException('Invalid name');
throw new Apify_ValidationException('Invalid name');
}
$this->name = $value;
}
Expand All @@ -33,7 +33,7 @@ public function setName($value)
public function setEmail($value)
{
if (! filter_var($value, FILTER_VALIDATE_EMAIL)) {
throw new ValidationException('Invalid email address');
throw new Apify_ValidationException('Invalid email address');
}
$this->email = $value;
}
Expand Down
2 changes: 1 addition & 1 deletion app/views/error/development.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<h3>Queries</h3>
<div class="info">
<pre><?php try { var_dump(Loader::getInstance()->getDatabase()->getQueries()); } catch (Exception $e) { echo 'Not connected'; } ?></pre>
<pre><?php try { var_dump(Apify_Loader::getInstance()->getDatabase()->getQueries()); } catch (Exception $e) { echo 'Not connected'; } ?></pre>
</div>

<br/>
Expand Down
Loading