ドキュメントの例に基づいて Phlyrestfully を実行するのに問題があります。 http://phlyrestfully.readthedocs.org/en/latest/basics/example.html これを新しい zend スケルトンとして開始し、ルートとリスナーを作成しました。常に 404 エラーが発生します。その他のエラーはありません。
return array(
'phlyrestfully' => array(
'resources' => array(
'Paste\ApiController' => array(
'identifier' => 'Pastes',
'listener' => 'Paste\PasteResourceListener',
'resource_identifiers' => array('PasteResource'),
'collection_http_options' => array('get', 'post'),
'collection_name' => 'pastes',
'page_size' => 10,
'resource_http_options' => array('get'),
'route_name' => 'paste/api',
),
),
),
'router' => array(
'routes' => array(
'paste' => array(
'type' => 'Literal',
'options' => array(
'route' => '/paste',
'controller' => 'Paste\PasteController', // for the web UI
),
'may_terminate' => true,
'child_routes' => array(
'api' => array(
'type' => 'Segment',
'options' => array(
'route' => '/api/pastes[/:id]',
'controller' => 'Paste\ApiController',
),
),
),
),
)),
'view_manager' => array(
'strategies' => array(
'ViewJsonStrategy'
))
);
リスナー ファイル:
namespace Paste;
use PhlyRestfully\Exception\CreationException;
use PhlyRestfully\Exception\DomainException;
use PhlyRestfully\ResourceEvent;
use Zend\EventManager\AbstractListenerAggregate;
use Zend\EventManager\EventManagerInterface;
class PasteResourceListener extends AbstractListenerAggregate
{
protected $persistence;
public function __construct(PersistenceInterface $persistence)
{
$this->persistence = $persistence;
}
public function attach(EventManagerInterface $events)
{
$this->listeners[] = $events->attach('create', array($this, 'onCreate'));
$this->listeners[] = $events->attach('fetch', array($this, 'onFetch'));
$this->listeners[] = $events->attach('fetchAll', array($this, 'onFetchAll'));
}
public function onCreate(ResourceEvent $e)
{
$data = $e->getParam('data');
$paste = $this->persistence->save($data);
if (!$paste) {
throw new CreationException();
}
return $paste;
}
public function onFetch(ResourceEvent $e)
{
$id = $e->getParam('id');
$paste = $this->persistence->fetch($id);
if (!$paste) {
throw new DomainException('Paste not found', 404);
}
return $paste;
}
public function onFetchAll(ResourceEvent $e)
{
return $this->persistence->fetchAll();
}
}
インターフェイス ファイル:
namespace Paste;
interface PersistenceInterface
{
public function save(array $data);
public function fetch($id);
public function fetchAll();
}
モデルファイル:
namespace Paste;
class Module
{
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
public function getServiceConfig()
{
return array('factories' => array(
'Paste\PasteResourceListener' => function ($services) {
$persistence = $services->get('Paste\PersistenceInterface');
return new PasteResourceListener($persistence);
},
));
}
}