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

RESTful help #2165

Merged
merged 23 commits into from
Sep 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9ec3ab4
First pass at resource controller
jim-parry Feb 21, 2019
172d75b
Flesh out resource controllers
jim-parry Feb 22, 2019
f7552ca
Resource tests completed; not working yet
jim-parry Feb 26, 2019
b0b242a
Merge branch 'develop' into feature/resource
jim-parry Mar 20, 2019
dbc9573
Merge branch 'develop' into feature/resource
jim-parry May 2, 2019
9f3f1dc
Fix docblocks, rename module
jim-parry May 4, 2019
8d6110c
Merge branch 'develop' into feature/resource
jim-parry Jul 3, 2019
cc10452
Drop presenter for now
jim-parry Jul 25, 2019
29e4e88
Drop presenter for now
jim-parry Jul 25, 2019
0711bf2
Merge branch 'develop' into feature/resource
jim-parry Aug 13, 2019
ce10a0b
ResourceController testing
jim-parry Aug 20, 2019
18e7a05
Add back ResourcePresenter
jim-parry Aug 20, 2019
d93248e
Still trying to get the tests working
jim-parry Aug 27, 2019
7a5d2b9
Merge branch 'develop' into feature/resource
jim-parry Aug 27, 2019
0513dbe
Fix use stmts & embrace language message
jim-parry Aug 28, 2019
53918b3
Merge branch 'develop' into feature/resource
jim-parry Aug 28, 2019
172a403
Restore FeatureTestCase
jim-parry Aug 29, 2019
de993d4
Simplify & fix RESTful unit tests
jim-parry Aug 30, 2019
1ede3b3
Fiddling with the ResourcePresenterTest
jim-parry Aug 30, 2019
47d955c
Merge branch 'develop' into feature/resource
jim-parry Aug 30, 2019
3005744
Fix RouteCollection::presenter() and test
jim-parry Aug 31, 2019
0ec655d
Finish the ResourcePresenter testing
jim-parry Aug 31, 2019
139fdd4
Tweak phpunit annotations
jim-parry Aug 31, 2019
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
12 changes: 6 additions & 6 deletions app/Controllers/BaseController.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?php

namespace App\Controllers;

use CodeIgniter\Controller;

/**
* Class BaseController
*
Expand All @@ -16,6 +13,9 @@
*
* @package CodeIgniter
*/

use CodeIgniter\Controller;

class BaseController extends Controller
{

Expand All @@ -26,21 +26,21 @@ class BaseController extends Controller
*
* @var array
*/
protected $helpers = [ ];
protected $helpers = [];

/**
* Constructor.
*
*/
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
// Do Not Edit This Line
parent::initController($request, $response, $logger);

//--------------------------------------------------------------------
// Preload any models, libraries, etc, here.
//--------------------------------------------------------------------
// E.g.:
// $this->session = \Config\Services::session();

}

}
5 changes: 3 additions & 2 deletions system/Cache/Handlers/MemcachedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function initialize()

// $stats should be an associate array with a key in the format of host:port.
// If it doesn't have the key, we know the server is not working as expected.
if( !isset($stats[$this->config['host']. ':' .$this->config['port']]) )
if (! isset($stats[$this->config['host'] . ':' . $this->config['port']]))
{
throw new CriticalError('Cache: Memcached connection failed.');
}
Expand All @@ -154,7 +154,8 @@ public function initialize()
);

// If we can't connect, throw a CriticalError exception
if($can_connect == false){
if ($can_connect === false)
{
throw new CriticalError('Cache: Memcache connection failed.');
}

Expand Down
2 changes: 1 addition & 1 deletion system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ function force_https(int $duration = 31536000, RequestInterface $request = null,
$response->setHeader('Strict-Transport-Security', 'max-age=' . $duration);
$response->redirect($uri);
$response->sendHeaders();

exit();
}
}
Expand Down
8 changes: 4 additions & 4 deletions system/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ private static function createClass(string $name)
{
return new $name();
}

$locator = Services::locator();
$file = $locator->locateFile($name, 'Config');

if (empty($file))
{
// No file found - check if the class was namespaced
Expand All @@ -134,14 +134,14 @@ private static function createClass(string $name)
// Class was namespaced and locateFile couldn't find it
return null;
}

// Check all namespaces
$files = $locator->search('Config/' . $name);
if (empty($files))
{
return null;
}

// Get the first match (prioritizes user and framework)
$file = reset($files);
}
Expand Down
4 changes: 2 additions & 2 deletions system/Debug/Toolbar/Views/toolbarloader.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ function loadDoc(time) {

// Track all AJAX requests
if (window.ActiveXObject) {
var oldXHR = new ActiveXObject('Microsoft.XMLHTTP');
var oldXHR = new ActiveXObject('Microsoft.XMLHTTP');
} else {
var oldXHR = window.XMLHttpRequest;
var oldXHR = window.XMLHttpRequest;
}

function newXHR() {
Expand Down
2 changes: 1 addition & 1 deletion system/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ private function castAsJson($value, bool $asArray = false)
$tmp = ! is_null($value) ? ($asArray ? [] : new \stdClass) : null;
if (function_exists('json_decode'))
{
if ((is_string($value) && strlen($value) > 1 && in_array($value{0}, ['[','{','"'])) || is_numeric($value))
if ((is_string($value) && strlen($value) > 1 && in_array($value{0}, ['[', '{', '"'])) || is_numeric($value))
{
$tmp = json_decode($value, $asArray);

Expand Down
2 changes: 1 addition & 1 deletion system/Exceptions/ModelException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static function forNoPrimaryKey(string $modelName)
{
return new static(lang('Database.noPrimaryKey', [$modelName]));
}

public static function forNoDateFormat(string $modelName)
{
return new static(lang('Database.noDateFormat', [$modelName]));
Expand Down
4 changes: 2 additions & 2 deletions system/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function getMimeType(): string
public function getRandomName(): string
{
$extension = $this->getExtension();
$extension = empty($extension) ? '' : '.' . $extension;
$extension = empty($extension) ? '' : '.' . $extension;
return time() . '_' . bin2hex(random_bytes(10)) . $extension;
}

Expand Down Expand Up @@ -204,7 +204,7 @@ public function getDestination(string $destination, string $delimiter = '_', int
{
while (is_file($destination))
{
$info = pathinfo($destination);
$info = pathinfo($destination);
$extension = isset($info['extension']) ? '.' . $info['extension'] : '';
if (strpos($info['filename'], $delimiter) !== false)
{
Expand Down
18 changes: 9 additions & 9 deletions system/Helpers/date_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,26 @@ function now(string $timezone = null): int
*
* Returns a string with the formatted HTML
*
* @param string $class Optional class to apply to the select field
* @param string $default Default value for initial selection
* @param int $what One of the DateTimeZone class constants (for listIdentifiers)
* @param string $country A two-letter ISO 3166-1 compatible country code (for listIdentifiers)
* @param string $class Optional class to apply to the select field
* @param string $default Default value for initial selection
* @param integer $what One of the DateTimeZone class constants (for listIdentifiers)
* @param string $country A two-letter ISO 3166-1 compatible country code (for listIdentifiers)
*
* @return string
* @throws \Exception
*/
function timezone_select(string $class = '', string $default = '', int $what = \DateTimeZone::ALL, string $country = null): string
{
$timezones = \DateTimeZone::listIdentifiers($what, $country);

$buffer = "<select name='timezone' class='{$class}'>" . PHP_EOL;
foreach ($timezones as $timezone)
{
$selected = ($timezone == $default) ? 'selected' : '';
$buffer .= "<option value='{$timezone}' {$selected}>{$timezone}</option>" . PHP_EOL;
$selected = ($timezone === $default) ? 'selected' : '';
$buffer .= "<option value='{$timezone}' {$selected}>{$timezone}</option>" . PHP_EOL;
}
$buffer .= "</select>" . PHP_EOL;
$buffer .= '</select>' . PHP_EOL;

return $buffer;
}
}
2 changes: 1 addition & 1 deletion system/Language/en/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@

return
[
'tryingToAccessNonExistentProperty' => 'Trying to access non existent property {0} of {1}'
'tryingToAccessNonExistentProperty' => 'Trying to access non existent property {0} of {1}',
];
18 changes: 18 additions & 0 deletions system/Language/en/RESTful.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* RESTful language strings.
*
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/)
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 3.0.0
* @filesource
*
* @codeCoverageIgnore
*/

return [
'notImplemented' => "'{0}' action not implemented.",
];
13 changes: 6 additions & 7 deletions system/Pager/Pager.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ public function simpleLinks(string $group = 'default', string $template = 'defau
* Allows for a simple, manual, form of pagination where all of the data
* is provided by the user. The URL is the current URI.
*
* @param integer $page
* @param integer $perPage
* @param integer $total
* @param string $template The output template alias to render.
* @param integer $segment (if page number is provided by URI segment)
* @param integer $page
* @param integer $perPage
* @param integer $total
* @param string $template The output template alias to render.
* @param integer $segment (if page number is provided by URI segment)
*
* @param string|null $group optional group (i.e. if we'd like to define custom path)
* @param string|null $group optional group (i.e. if we'd like to define custom path)
* @return string
*/
public function makeLinks(int $page, int $perPage, int $total, string $template = 'default_full', int $segment = 0, ?string $group = null): string
Expand All @@ -162,7 +162,6 @@ public function makeLinks(int $page, int $perPage, int $total, string $template
return $this->displayLinks($group ?? $name, $template);
}


//--------------------------------------------------------------------

/**
Expand Down
Loading