Skip to content

Commit 18e7a05

Browse files
committed
Add back ResourcePresenter
1 parent ce10a0b commit 18e7a05

7 files changed

Lines changed: 880 additions & 1 deletion

File tree

system/RESTful/ResourceController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function initController(\CodeIgniter\HTTP\RequestInterface $request, \Cod
8383
}
8484
catch (\Exception $e)
8585
{
86-
// ignored. we just own't use a model for now
86+
// ignored. we just don't use a model for now
8787
}
8888
}
8989
}
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
<?php
2+
/**
3+
* CodeIgniter
4+
*
5+
* An open source application development framework for PHP
6+
*
7+
* This content is released under the MIT License (MIT)
8+
*
9+
* Copyright (c) 2014-2019 British Columbia Institute of Technology
10+
*
11+
* Permission is hereby granted, free of charge, to any person obtaining a copy
12+
* of this software and associated documentation files (the "Software"), to deal
13+
* in the Software without restriction, including without limitation the rights
14+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
* copies of the Software, and to permit persons to whom the Software is
16+
* furnished to do so, subject to the following conditions:
17+
*
18+
* The above copyright notice and this permission notice shall be included in
19+
* all copies or substantial portions of the Software.
20+
*
21+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27+
* THE SOFTWARE.
28+
*
29+
* @package CodeIgniter
30+
* @author CodeIgniter Dev Team
31+
* @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/)
32+
* @license https://opensource.org/licenses/MIT MIT License
33+
* @link https://codeigniter.com
34+
* @since Version 3.0.0
35+
* @filesource
36+
*/
37+
38+
namespace CodeIgniter\RESTful;
39+
40+
use CodeIgniter\API\ResponseTrait;
41+
use CodeIgniter\Controller;
42+
43+
/**
44+
* An extendable controller to help provide a UI for a resource.
45+
*
46+
* @package CodeIgniter\RESTful
47+
*/
48+
class ResourcePresenter extends Controller
49+
{
50+
51+
/**
52+
*
53+
* @var string Name of the model class managing this resource's data
54+
*/
55+
protected $modelName = null;
56+
57+
/**
58+
*
59+
* @var \CodeIgniter\Model the model holding this resource's data
60+
*/
61+
protected $model = null;
62+
63+
const NOT_THERE = 'Action not implemented yet';
64+
65+
//--------------------------------------------------------------------
66+
67+
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
68+
{
69+
parent::initController($request, $response, $logger);
70+
71+
// instantiate our model, if needed
72+
if (! empty($this->modelName))
73+
{
74+
try
75+
{
76+
$this->model = $this->modelName();
77+
}
78+
catch (\Exception $e)
79+
{
80+
// ignored. we just own't use a model for now
81+
}
82+
}
83+
}
84+
85+
//--------------------------------------------------------------------
86+
87+
/**
88+
* Present a view of resource objects
89+
*
90+
* @return string
91+
*/
92+
public function index()
93+
{
94+
return 'index: ' . NOT_THERE;
95+
}
96+
97+
/**
98+
* Present a view to present a specific resource object
99+
*
100+
* @param type $id
101+
* @return string
102+
*/
103+
public function show($id = null)
104+
{
105+
return 'show: ' . NOT_THERE;
106+
}
107+
108+
/**
109+
* Present a view to present a new single resource object
110+
*
111+
* @param type $id
112+
* @return string
113+
*/
114+
public function new()
115+
{
116+
return 'new: ' . NOT_THERE;
117+
}
118+
119+
/**
120+
* Process the creation/insertion of a new resource object
121+
*
122+
* @return string
123+
*/
124+
public function create()
125+
{
126+
return 'create: ' . NOT_THERE;
127+
}
128+
129+
/**
130+
* Present a view to confirm the deletion of a specific resource object
131+
*
132+
* @param type $id
133+
* @return string
134+
*/
135+
public function remove($id = null)
136+
{
137+
return 'remove: ' . NOT_THERE;
138+
}
139+
140+
/**
141+
* Process the deletion of a specific resource object
142+
*
143+
* @param type $id
144+
* @return string
145+
*/
146+
public function delete($id = null)
147+
{
148+
return 'delete: ' . NOT_THERE;
149+
}
150+
151+
/**
152+
* Present a view to edit the properties of a specific resource object
153+
*
154+
* @param type $id
155+
* @return string
156+
*/
157+
public function edit($id = null)
158+
{
159+
return 'edit: ' . NOT_THERE;
160+
}
161+
162+
/**
163+
* Process the updating, full or partial, of a specific resource object
164+
*
165+
* @param type $id
166+
* @return string
167+
*/
168+
public function update($id = null)
169+
{
170+
return 'update: ' . NOT_THERE;
171+
}
172+
173+
//--------------------------------------------------------------------
174+
175+
/**
176+
* Set/change the model that this controller is bound to
177+
*
178+
* @param type $which
179+
*/
180+
public function setModel($which = null)
181+
{
182+
$this->model = $model;
183+
}
184+
185+
}

tests/_support/RESTful/Worker2.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
namespace Tests\Support\RESTful;
3+
4+
use CodeIgniter\RESTful\ResourcePresenter;
5+
6+
/**
7+
* An extendable controller to provide a RESTful API for a resource.
8+
*/
9+
class Worker2 extends ResourcePresenter
10+
{
11+
12+
}

tests/system/RESTful/ResourceControllerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ public function testEdit()
219219
// $routes->resource('work', ['controller' => '\Tests\Support\RESTful\Worker']);
220220
// $router = Services::router($routes);
221221
// Services::injectMock('router', $router);
222+
$routes->resource('work/edit', ['controller' => '\Tests\Support\RESTful\Worker::edit']);
222223

223224
ob_start();
224225
$this->codeigniter->useSafeOutput(true)->run();

0 commit comments

Comments
 (0)