Skip to content
Snippets Groups Projects
Commit 1de5c6de authored by bertrandgauthier's avatar bertrandgauthier
Browse files

Commit initial

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 795 additions and 0 deletions
<?php
/**
* Configuration file generated by ZF Apigility Admin
*
* The previous config file has been stored in ./config/modules.config.old
*/
return [
'Zend\\Db',
'Zend\\Filter',
'Zend\\Hydrator',
'Zend\\InputFilter',
'Zend\\Paginator',
'Zend\\Router',
'Zend\\Validator',
'ZF\\Apigility',
'ZF\\Apigility\\Documentation',
'ZF\\ApiProblem',
'ZF\\Configuration',
'ZF\\OAuth2',
'ZF\\MvcAuth',
'ZF\\Hal',
'ZF\\ContentNegotiation',
'ZF\\ContentValidation',
'ZF\\Rest',
'ZF\\Rpc',
'ZF\\Versioning',
'Application',
'FirstRest',
];
version: "2"
services:
apigility:
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:80"
extra_hosts:
- "svn.unicaen.fr:10.14.129.44"
- "proxy.unicaen.fr:10.14.128.99"
volumes:
- .:/var/www
<?php
/**
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
* @copyright Copyright (c) 2014-2016 Zend Technologies USA Inc. (http://www.zend.com)
*/
namespace Application;
use Zend\ServiceManager\Factory\InvokableFactory;
return [
'router' => [
'routes' => [
'home' => [
'type' => 'Literal',
'options' => [
'route' => '/',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
],
],
'controllers' => [
'factories' => [
Controller\IndexController::class => InvokableFactory::class,
],
],
'view_manager' => [
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => [
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
],
'template_path_stack' => [
__DIR__ . '/../view',
],
],
];
<?php
/**
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
* @copyright Copyright (c) 2014-2016 Zend Technologies USA Inc. (http://www.zend.com)
*/
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use ZF\Apigility\Admin\Module as AdminModule;
class IndexController extends AbstractActionController
{
public function indexAction()
{
if (class_exists(AdminModule::class, false)) {
return $this->redirect()->toRoute('zf-apigility/ui');
}
return new ViewModel();
}
}
<?php
/**
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
* @copyright Copyright (c) 2014-2016 Zend Technologies USA Inc. (http://www.zend.com)
*/
namespace Application;
class Module
{
public function getConfig()
{
return include __DIR__ . '/../config/module.config.php';
}
}
<?php
/**
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com)
*/
namespace ApplicationTest\Controller;
use Application\Controller\IndexController;
use Zend\Stdlib\ArrayUtils;
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
class IndexControllerTest extends AbstractHttpControllerTestCase
{
public function setUp()
{
// The module configuration should still be applicable for tests.
// You can override configuration here with test case specific values,
// such as sample view templates, path stacks, module_listener_options,
// etc.
$configOverrides = [
'module_listener_options' => [
'config_cache_enabled' => false,
],
];
$this->setApplicationConfig(ArrayUtils::merge(
include __DIR__ . '/../../../../config/application.config.php',
$configOverrides
));
parent::setUp();
}
public function testIndexActionCanBeAccessed()
{
$this->dispatch('/', 'GET');
$this->assertResponseStatusCode(200);
$this->assertModuleName('application');
$this->assertControllerName(IndexController::class); // as specified in router's controller name alias
$this->assertControllerClass('IndexController');
$this->assertMatchedRouteName('home');
}
public function testIndexActionViewModelTemplateRenderedWithinLayout()
{
$this->dispatch('/', 'GET');
$this->assertQuery('.hero-unit');
}
public function testInvalidRouteDoesNotCrash()
{
$this->dispatch('/invalid/route', 'GET');
$this->assertResponseStatusCode(404);
}
}
<?php
/**
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com)
*/
namespace ApplicationTest\Controller;
use Application\Controller\IndexController;
use Zend\Stdlib\ArrayUtils;
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
/**
* Name is intentional, to force it to run last; this was necessary as,
* once the Admin module is loaded, the controller is able to find it and
* will attempt the redirect.
*/
class ZZIndexControllerDevModeTest extends AbstractHttpControllerTestCase
{
public function setUp()
{
// The module configuration should still be applicable for tests.
// You can override configuration here with test case specific values,
// such as sample view templates, path stacks, module_listener_options,
// etc.
$configOverrides = [
'modules' => [
'ZF\Apigility\Admin',
'ZF\Apigility\Admin\Ui',
],
'module_listener_options' => [
'config_cache_enabled' => false,
'config_glob_paths' => [
__DIR__ . '/../../../../config/autoload/{,*.}{global,local}.php',
__DIR__ . '/../../../../config/autoload/{,*.}{global,local}-development.php',
],
]
];
$this->setApplicationConfig(ArrayUtils::merge(
include __DIR__ . '/../../../../config/application.config.php',
$configOverrides
));
parent::setUp();
}
public function testIndexActionRedirectsToAdminUi()
{
$this->dispatch('/', 'GET');
$this->assertResponseStatusCode(302);
$this->assertRedirectRegex('#/ui$#');
}
}
<div class="hero-unit">
<p align="center"><img src="/img/ag-hero.png" alt="Apigility <?= \Apigility\VERSION ?>"></p>
</div>
<div class="row">
<div class="span8">
<p><br /><br />In order to use the <strong>Apigility Admin UI</strong> you need to enable the <strong>development</strong> mode. Currently your application is running in <strong>production</strong> mode.</p>
<p>To enable the development mode you can execute the following command from the terminal:</p>
<p><pre>$ composer development-enable</pre></p>
<p>Remember to set always the production mode if you want to deploy your API in a staging/production environment.</p>
</div>
</div>
<?php
use Zend\Mvc\Application;
?>
<h1>A 404 error occurred</h1>
<h2><?= $this->message ?></h2>
<?php
if (! empty($this->reason)) :
$reasonMessage = '';
switch ($this->reason) {
case Application::ERROR_CONTROLLER_CANNOT_DISPATCH:
$reasonMessage = 'The requested controller was unable to dispatch the request.';
break;
case Application::ERROR_MIDDLEWARE_CANNOT_DISPATCH:
$reasonMessage = 'The requested middleware was unable to dispatch the request.';
break;
case Application::ERROR_CONTROLLER_NOT_FOUND:
$reasonMessage = 'The requested controller could not be mapped to an existing controller class.';
break;
case Application::ERROR_CONTROLLER_INVALID:
$reasonMessage = 'The requested controller was not dispatchable.';
break;
case Application::ERROR_ROUTER_NO_MATCH:
$reasonMessage = 'The requested URL could not be matched by routing.';
break;
default:
$reasonMessage = 'We cannot determine at this time why a 404 was generated.';
break;
}
?>
<p><?= $reasonMessage ?></p>
<?php endif ?>
<?php if (! empty($this->controller)) : ?>
<dl>
<dt>Controller:</dt>
<dd><?= $this->escapeHtml($this->controller) ?>
<?php
if (! empty($this->controller_class)
&& $this->controller_class != $this->controller
) {
echo sprintf('(resolves to %s)', $this->escapeHtml($this->controller_class));
}
?>
</dd>
</dl>
<?php endif ?>
<?php if (! empty($this->display_exceptions)) : ?>
<?php if (isset($this->exception)
&& ($this->exception instanceof \Throwable || $this->exception instanceof \Exception)) : ?>
<hr/>
<h2>Additional information:</h2>
<h3><?= get_class($this->exception) ?></h3>
<dl>
<dt>File:</dt>
<dd>
<pre class="prettyprint linenums"><?= $this->exception->getFile() ?>:<?= $this->exception->getLine() ?></pre>
</dd>
<dt>Message:</dt>
<dd>
<pre class="prettyprint linenums"><?= $this->escapeHtml($this->exception->getMessage()) ?></pre>
</dd>
<dt>Stack trace:</dt>
<dd>
<pre class="prettyprint linenums"><?= $this->exception->getTraceAsString() ?></pre>
</dd>
</dl>
<?php $e = $this->exception->getPrevious() ?>
<?php if ($e) : ?>
<hr/>
<h2>Previous exceptions:</h2>
<ul class="unstyled">
<?php while ($e) : ?>
<li>
<h3><?= get_class($e) ?></h3>
<dl>
<dt>File:</dt>
<dd>
<pre class="prettyprint linenums"><?= $e->getFile() ?>:<?= $e->getLine() ?></pre>
</dd>
<dt>Message:</dt>
<dd>
<pre class="prettyprint linenums"><?= $this->escapeHtml($e->getMessage()) ?></pre>
</dd>
<dt>Stack trace:</dt>
<dd>
<pre class="prettyprint linenums"><?= $e->getTraceAsString() ?></pre>
</dd>
</dl>
</li>
<?php $e = $e->getPrevious() ?>
<?php endwhile ?>
</ul>
<?php endif ?>
<?php else : ?>
<h3>No Exception available</h3>
<?php endif ?>
<?php endif ?>
<h1>An error occurred</h1>
<h2><?= $this->message ?></h2>
<?php if (! empty($this->display_exceptions)) : ?>
<?php if (isset($this->exception)
&& ($this->exception instanceof \Throwable || $this->exception instanceof \Exception)) : ?>
<hr/>
<h2>Additional information:</h2>
<h3><?= get_class($this->exception) ?></h3>
<dl>
<dt>File:</dt>
<dd>
<pre class="prettyprint linenums"><?= $this->exception->getFile() ?>:<?= $this->exception->getLine() ?></pre>
</dd>
<dt>Message:</dt>
<dd>
<pre class="prettyprint linenums"><?= $this->escapeHtml($this->exception->getMessage()) ?></pre>
</dd>
<dt>Stack trace:</dt>
<dd>
<pre class="prettyprint linenums"><?= $this->exception->getTraceAsString() ?></pre>
</dd>
</dl>
<?php $e = $this->exception->getPrevious() ?>
<?php if ($e) : ?>
<hr/>
<h2>Previous exceptions:</h2>
<ul class="unstyled">
<?php while ($e) : ?>
<li>
<h3><?= get_class($e); ?></h3>
<dl>
<dt>File:</dt>
<dd>
<pre class="prettyprint linenums"><?= $e->getFile() ?>:<?= $e->getLine() ?></pre>
</dd>
<dt>Message:</dt>
<dd>
<pre class="prettyprint linenums"><?= $this->escapeHtml($e->getMessage()) ?></pre>
</dd>
<dt>Stack trace:</dt>
<dd>
<pre class="prettyprint linenums"><?= $e->getTraceAsString() ?></pre>
</dd>
</dl>
</li>
<?php $e = $e->getPrevious() ?>
<?php endwhile ?>
</ul>
<?php endif ?>
<?php else : ?>
<h3>No Exception available</h3>
<?php endif ?>
<?php endif ?>
<?= $this->doctype() ?>
<html lang="en">
<head>
<meta charset="utf-8">
<?php
echo $this->headTitle('Apigility');
echo $this->headMeta()->appendName('viewport', 'width=device-width, initial-scale=1.0');
echo $this->headLink(['rel' => 'icon', 'type' => 'image/png', 'href' => $this->basePath('/img/favicon.png')])
->prependStylesheet($this->basePath('/zf-apigility/css/main.min.css'))
->prependStylesheet($this->basePath('/zf-apigility/css/bootstrap.min.css'));
echo $this->headScript()
->prependFile($this->basePath('/zf-apigility/js/bootstrap.min.js'))
->prependFile($this->basePath('/zf-apigility/js/jquery.min.js'));
?>
</head>
<body>
<div class="container">
<?= $this->content ?>
</div>
<footer>
<hr>
<div class="container center-block"><div class="row">
<div class="col-sm-4">
&copy; Copyright 2013 - <?= date('Y') ?>
by <a href="http://www.zend.com">Zend Technologies</a> Ltd.
</div>
<div class="col-sm-4"><p class="center-block">
Apigility version <strong><?= \Apigility\VERSION ?></strong>
</p></div>
<div class="col-sm-4"><p class="pull-right">
For more information <a href="https://apigility.org">apigility.org</a>
</p></div>
</div></div>
</footer>
<?= $this->inlineScript() ?>
</body>
</html>
<?php
namespace FirstRest;
use ZF\Apigility\Provider\ApigilityProviderInterface;
class Module implements ApigilityProviderInterface
{
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getAutoloaderConfig()
{
return [
'ZF\Apigility\Autoloader' => [
'namespaces' => [
__NAMESPACE__ => __DIR__ . '/src',
],
],
];
}
}
<?php
return [
'service_manager' => [
'factories' => [
\FirstRest\V1\Rest\Ping\PingResource::class => \FirstRest\V1\Rest\Ping\PingResourceFactory::class,
],
],
'router' => [
'routes' => [
'first-rest.rest.ping' => [
'type' => 'Segment',
'options' => [
'route' => '/ping[/:ping_id]',
'defaults' => [
'controller' => 'FirstRest\\V1\\Rest\\Ping\\Controller',
],
],
],
],
],
'zf-versioning' => [
'uri' => [
0 => 'first-rest.rest.ping',
],
],
'zf-rest' => [
'FirstRest\\V1\\Rest\\Ping\\Controller' => [
'listener' => \FirstRest\V1\Rest\Ping\PingResource::class,
'route_name' => 'first-rest.rest.ping',
'route_identifier_name' => 'ping_id',
'collection_name' => 'ping',
'entity_http_methods' => [
0 => 'GET',
],
'collection_http_methods' => [
0 => 'GET',
],
'collection_query_whitelist' => [],
'page_size' => '25',
'page_size_param' => null,
'entity_class' => \FirstRest\V1\Rest\Ping\PingEntity::class,
'collection_class' => \FirstRest\V1\Rest\Ping\PingCollection::class,
'service_name' => 'Ping',
],
],
'zf-content-negotiation' => [
'controllers' => [
'FirstRest\\V1\\Rest\\Ping\\Controller' => 'HalJson',
],
'accept_whitelist' => [
'FirstRest\\V1\\Rest\\Ping\\Controller' => [
0 => 'application/vnd.first-rest.v1+json',
1 => 'application/hal+json',
2 => 'application/json',
],
],
'content_type_whitelist' => [
'FirstRest\\V1\\Rest\\Ping\\Controller' => [
0 => 'application/vnd.first-rest.v1+json',
1 => 'application/json',
],
],
],
'zf-hal' => [
'metadata_map' => [
\FirstRest\V1\Rest\Ping\PingEntity::class => [
'entity_identifier_name' => 'id',
'route_name' => 'first-rest.rest.ping',
'route_identifier_name' => 'ping_id',
'hydrator' => \Zend\Hydrator\ClassMethods::class,
],
\FirstRest\V1\Rest\Ping\PingCollection::class => [
'entity_identifier_name' => 'id',
'route_name' => 'first-rest.rest.ping',
'route_identifier_name' => 'ping_id',
'is_collection' => true,
],
],
],
];
<?php
namespace FirstRest\V1\Rest\Ping;
use Zend\Paginator\Paginator;
class PingCollection extends Paginator
{
}
<?php
namespace FirstRest\V1\Rest\Ping;
class PingEntity
{
protected $id;
protected $value;
/**
* PingEntity constructor.
*
* @param $id
* @param $value
*/
public function __construct($id, $value)
{
$this->id = $id;
$this->value = $value;
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param mixed $id
* @return PingEntity
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return mixed
*/
public function getValue()
{
return $this->value;
}
/**
* @param mixed $value
* @return PingEntity
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}
}
<?php
namespace FirstRest\V1\Rest\Ping;
use Zend\Paginator\Adapter\ArrayAdapter;
use ZF\ApiProblem\ApiProblem;
use ZF\Rest\AbstractResourceListener;
class PingResource extends AbstractResourceListener
{
/**
* Create a resource
*
* @param mixed $data
* @return ApiProblem|mixed
*/
public function create($data)
{
return new ApiProblem(405, 'The POST method has not been defined');
}
/**
* Delete a resource
*
* @param mixed $id
* @return ApiProblem|mixed
*/
public function delete($id)
{
return new ApiProblem(405, 'The DELETE method has not been defined for individual resources');
}
/**
* Delete a collection, or members of a collection
*
* @param mixed $data
* @return ApiProblem|mixed
*/
public function deleteList($data)
{
return new ApiProblem(405, 'The DELETE method has not been defined for collections');
}
/**
* Fetch a resource
*
* @param mixed $id
* @return ApiProblem|mixed
*/
public function fetch($id)
{
return new PingEntity(1, 1234);
}
/**
* Fetch all or a subset of resources
*
* @param array $params
* @return ApiProblem|mixed
*/
public function fetchAll($params = [])
{
return new PingCollection(new ArrayAdapter([
new PingEntity(1, 1234),
new PingEntity(2, 5678),
]));
}
/**
* Patch (partial in-place update) a resource
*
* @param mixed $id
* @param mixed $data
* @return ApiProblem|mixed
*/
public function patch($id, $data)
{
return new ApiProblem(405, 'The PATCH method has not been defined for individual resources');
}
/**
* Patch (partial in-place update) a collection or members of a collection
*
* @param mixed $data
* @return ApiProblem|mixed
*/
public function patchList($data)
{
return new ApiProblem(405, 'The PATCH method has not been defined for collections');
}
/**
* Replace a collection or members of a collection
*
* @param mixed $data
* @return ApiProblem|mixed
*/
public function replaceList($data)
{
return new ApiProblem(405, 'The PUT method has not been defined for collections');
}
/**
* Update a resource
*
* @param mixed $id
* @param mixed $data
* @return ApiProblem|mixed
*/
public function update($id, $data)
{
return new ApiProblem(405, 'The PUT method has not been defined for individual resources');
}
}
<?php
namespace FirstRest\V1\Rest\Ping;
class PingResourceFactory
{
public function __invoke($services)
{
return new PingResource();
}
}
<?xml version="1.0"?>
<ruleset name="Zend Framework coding standard">
<description>Zend Framework coding standard</description>
<!-- display progress -->
<arg value="p"/>
<arg name="colors"/>
<arg name="extensions" value="php,dist,phtml"/>
<!-- inherit rules from: -->
<rule ref="PSR2"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="Generic.Formatting.SpaceAfterNot"/>
<rule ref="Squiz.WhiteSpace.OperatorSpacing">
<properties>
<property name="ignoreNewlines" value="true"/>
</properties>
</rule>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
<properties>
<property name="ignoreBlankLines" value="false"/>
</properties>
</rule>
<rule ref="PSR1.Files.SideEffects">
<exclude-pattern>public/index.php</exclude-pattern>
</rule>
<!-- Paths to check -->
<file>config</file>
<file>module</file>
<file>public/index.php</file>
<file>src</file>
</ruleset>
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
bootstrap="./vendor/autoload.php">
<testsuites>
<testsuite name="zf-apigility-skeleton">
<directory>./module/Application/test</directory>
</testsuite>
</testsuites>
</phpunit>
apigility-ui/
zf-apigility/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment