public function setUp()
 {
     $this->controller = $controller = new ResourceController();
     $this->router = $router = new SimpleRouteStack();
     $route = new Segment('/resource[/[:id]]');
     $router->addRoute('resource', $route);
     $this->event = $event = new MvcEvent();
     $event->setRouter($router);
     $event->setRouteMatch(new RouteMatch(array()));
     $controller->setEvent($event);
     $controller->setRoute('resource');
     $pluginManager = new PluginManager();
     $controller->setPluginManager($pluginManager);
     $urlHelper = new UrlHelper();
     $urlHelper->setRouter($this->router);
     $serverUrlHelper = new ServerUrlHelper();
     $serverUrlHelper->setScheme('http');
     $serverUrlHelper->setHost('localhost.localdomain');
     $linksHelper = new Plugin\HalLinks();
     $linksHelper->setUrlHelper($urlHelper);
     $linksHelper->setServerUrlHelper($serverUrlHelper);
     $pluginManager->setService('HalLinks', $linksHelper);
     $linksHelper->setController($controller);
     $this->resource = $resource = new Resource();
     $controller->setResource($resource);
 }
 public function setUpHelpers()
 {
     if (isset($this->helpers)) {
         return;
     }
     $this->setupRouter();
     $urlHelper = new UrlHelper();
     $urlHelper->setRouter($this->router);
     $serverUrlHelper = new ServerUrlHelper();
     $serverUrlHelper->setScheme('http');
     $serverUrlHelper->setHost('localhost.localdomain');
     $this->linksHelper = $linksHelper = new HalLinks();
     $linksHelper->setUrlHelper($urlHelper);
     $linksHelper->setServerUrlHelper($serverUrlHelper);
     $this->helpers = $helpers = new HelperPluginManager();
     $helpers->setService('url', $urlHelper);
     $helpers->setService('serverUrl', $serverUrlHelper);
     $helpers->setService('halLinks', $linksHelper);
 }
 public function setupHelpers()
 {
     if (!$this->router) {
         $this->setupRouter();
     }
     $urlHelper = new UrlHelper();
     $urlHelper->setRouter($this->router);
     $serverUrlHelper = new ServerUrlHelper();
     $serverUrlHelper->setScheme('http');
     $serverUrlHelper->setHost('localhost.localdomain');
     $linksHelper = new HalLinks();
     $linksHelper->setUrlHelper($urlHelper);
     $linksHelper->setServerUrlHelper($serverUrlHelper);
     $this->helpers = $helpers = new HelperPluginManager();
     $helpers->setService('url', $urlHelper);
     $helpers->setService('serverUrl', $serverUrlHelper);
     $helpers->setService('halLinks', $linksHelper);
     $this->plugins = $plugins = new ControllerPluginManager();
     $plugins->setService('halLinks', $linksHelper);
 }
 public function setUp()
 {
     $this->router = $router = new TreeRouteStack();
     $route = new Segment('/resource[/[:id]]');
     $router->addRoute('resource', $route);
     $route2 = new Segment('/help');
     $router->addRoute('docs', $route2);
     $router->addRoute('hostname', array('type' => 'hostname', 'options' => array('route' => 'localhost.localdomain'), 'child_routes' => array('resource' => array('type' => 'segment', 'options' => array('route' => '/resource[/:id]'), 'may_terminate' => true, 'child_routes' => array('children' => array('type' => 'literal', 'options' => array('route' => '/children')))), 'users' => array('type' => 'segment', 'options' => array('route' => '/users[/:id]')), 'contacts' => array('type' => 'segment', 'options' => array('route' => '/contacts[/:id]')), 'embedded' => array('type' => 'segment', 'options' => array('route' => '/embedded[/:id]')), 'embedded_custom' => array('type' => 'segment', 'options' => array('route' => '/embedded_custom[/:custom_id]')))));
     $this->event = $event = new MvcEvent();
     $event->setRouter($router);
     $router->setRequestUri(new Http('http://localhost.localdomain/resource'));
     $controller = $this->controller = $this->getMock('PhlyRestfully\\ResourceController');
     $controller->expects($this->any())->method('getEvent')->will($this->returnValue($event));
     $this->urlHelper = $urlHelper = new UrlHelper();
     $urlHelper->setRouter($router);
     $this->serverUrlHelper = $serverUrlHelper = new ServerUrlHelper();
     $serverUrlHelper->setScheme('http');
     $serverUrlHelper->setHost('localhost.localdomain');
     $this->plugin = $plugin = new HalLinks();
     $plugin->setController($controller);
     $plugin->setUrlHelper($urlHelper);
     $plugin->setServerUrlHelper($serverUrlHelper);
 }
 /**
  * Inject the helper manager with the HalLinks helper
  *
  * @param  HelperPluginManager $helpers
  */
 protected function injectHalLinksHelper(HelperPluginManager $helpers)
 {
     $helper = new HalLinks();
     $helper->setView($this);
     $helper->setServerUrlHelper($helpers->get('ServerUrl'));
     $helper->setUrlHelper($helpers->get('Url'));
     $helpers->setService('HalLinks', $helper);
 }
 public function setUpHelpers()
 {
     // need to setup routes
     // need to get a url and serverurl helper that have appropriate injections
     $this->router = $router = new TreeRouteStack();
     $this->resourceRoute = new Segment('/resource[/[:id]]');
     $this->router->addRoute('resource', $this->resourceRoute);
     $this->helpers = $helpers = new HelperPluginManager();
     $serverUrl = $helpers->get('ServerUrl');
     $url = $helpers->get('url');
     $url->setRouter($router);
     $serverUrl->setScheme('http');
     $serverUrl->setHost('localhost.localdomain');
     $halLinks = new HalLinks();
     $halLinks->setServerUrlHelper($serverUrl);
     $halLinks->setUrlHelper($url);
     $helpers->setService('HalLinks', $halLinks);
     $this->renderer->setHelperPluginManager($helpers);
 }
Esempio n. 7
0
 /**
  * Defines the "HalLinks" view helper
  *
  * @return array
  */
 public function getViewHelperConfig()
 {
     return array('factories' => array('HalLinks' => function ($helpers) {
         $serverUrlHelper = $helpers->get('ServerUrl');
         $urlHelper = $helpers->get('Url');
         $services = $helpers->getServiceLocator();
         $config = $services->get('Config');
         $metadataMap = $services->get('PhlyRestfully\\MetadataMap');
         $hydrators = $metadataMap->getHydratorManager();
         $helper = new Plugin\HalLinks($hydrators);
         $helper->setMetadataMap($metadataMap);
         $helper->setServerUrlHelper($serverUrlHelper);
         $helper->setUrlHelper($urlHelper);
         if (isset($config['phlyrestfully']) && isset($config['phlyrestfully']['renderer'])) {
             $config = $config['phlyrestfully']['renderer'];
             if (isset($config['default_hydrator'])) {
                 $hydratorServiceName = $config['default_hydrator'];
                 if (!$hydrators->has($hydratorServiceName)) {
                     throw new Exception\DomainException(sprintf('Cannot locate default hydrator by name "%s" via the HydratorManager', $hydratorServiceName));
                 }
                 $hydrator = $hydrators->get($hydratorServiceName);
                 $helper->setDefaultHydrator($hydrator);
             }
             if (isset($config['hydrators']) && is_array($config['hydrators'])) {
                 $hydratorMap = $config['hydrators'];
                 foreach ($hydratorMap as $class => $hydratorServiceName) {
                     $helper->addHydrator($class, $hydratorServiceName);
                 }
             }
         }
         return $helper;
     }));
 }