That looks right!

If there are particular points you find confusing about the configs, let me know. I think most of the file is fairly self-explanatory once you understand how the service managers work, but the problem is that the file is so huge that it's hard to figure out your context when looking at any particular part of it. Hopefully by factoring out the closures it will become a bit more readable and thus more comprehensible.

The routes are definitely confusing, though -- that's a separate issue to continue pondering.

- Demian

From: anna headley [anna3lc@gmail.com]
Sent: Friday, January 31, 2014 11:10 AM
To: Demian Katz
Cc: vufind-tech@lists.sourceforge.net
Subject: Re: [VuFind-Tech] config for new non-tab record action

Good point! Okay so now I have this [1]; is there anything else I can delete??

Honestly, a config file refactor that would go a long way for me would be the addition of a bunch of comments. I have tried to read zend docs on module configuration but it always seems very simple and straightforward in the docs, as compared with our vufind configs.

Thanks!
Anna

[1]
  $config['router']['routes']['record-booking'] = array(
      'type'    => 'Zend\Mvc\Router\Http\Segment',
      'options' => array(
          'route'    => '/' . $controller . '/[:id]/' . $action,
          'constraints' => array(
              'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
              'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
          ),
          'defaults' => array(
              'controller' => $controller,
              'action'     => $action,
          )
      )
  );


On Fri, Jan 31, 2014 at 7:39 AM, Demian Katz <demian.katz@villanova.edu> wrote:
What you did should work... but you could probably simplify it significantly by simply manually adding the $config['router']['routes']['record-booking'] settings to the config array created in your module.config.php (I assume that booking doesn't really apply to any of the non-Solr modules, so it's likely unnecessary to replicate the route configuration across all of them).

I'm not expecting this stuff to change during the first round of config refactoring (which will just involve eliminating closures to improve caching potential). However, I would eventually like to make this more comprehensible. I can think of a few possible approaches:

1.) Get rid of the config-generation code and manually enter all of the routes into the configuration. This will make the configuration file huge but will at least be more explicit.

2.) Create some new elements in the config array for short-hand routes, record routes and non-tab actions. Set up an event listener that triggers prior to routing and generates all the routes on the fly at that point. This has the advantage of offering a mechanism which easily allows short-hand routes to be set up in local modules without having to copy and paste logic... but it's somewhat complicated (event listeners are cool, but they make program flow harder to understand; also, this moves us further away from standard ZF2 configuration) and it may have performance implications (once again, it works against caching the configuration and instead forces processing to happen on every page load).

3.) Build a custom router that allows us to use a shorthand in the configuration. This might be the most elegant approach, but again it involves using non-standard components within the framework, and it may also be complex -- I'm not sure how hard it is to implement the router interface since I haven't looked at it yet.

Thoughts/preferences are welcome!

- Demian

From: anna headley [anna3lc@gmail.com]
Sent: Thursday, January 30, 2014 4:14 PM
To: vufind-tech@lists.sourceforge.net
Subject: [VuFind-Tech] config for new non-tab record action

I'm adding my bookings functionality just pretty much alongside the holds stuff.

I just copied all this [1] to my module config. The only thing I changed was where it says 'Booking'. I really don't understand this config stuff so I probably should work on that although it sounds like it's all about to change. Is there anything simpler I could have done? Is there a way to address this problem in the upcoming config refactor?

Thanks,
Anna

$recordRoutes = array(
      'record' => 'Record',
      'collection' => 'Collection',
      'missingrecord' => 'MissingRecord',
      'solrauthrecord' => 'Authority',
      'summonrecord' => 'SummonRecord',
      'worldcatrecord' => 'WorldcatRecord'
  );
  $nonTabRecordActions = array(
      'Booking',
  );
  // Build record routes
  foreach ($recordRoutes as $routeBase => $controller) {
      // catch-all "tab" route:
      $config['router']['routes'][$routeBase] = array(
          'type'    => 'Zend\Mvc\Router\Http\Segment',
          'options' => array(
              'route'    => '/' . $controller . '/[:id[/:tab]]',
              'constraints' => array(
                  'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                  'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
              ),
              'defaults' => array(
                  'controller' => $controller,
                  'action'     => 'Home',
              )
          )
      );
      // special non-tab actions that each need their own route:
      foreach ($nonTabRecordActions as $action) {
          $config['router']['routes'][$routeBase . '-' . strtolower($action)] = array(
              'type'    => 'Zend\Mvc\Router\Http\Segment',
              'options' => array(
                  'route'    => '/' . $controller . '/[:id]/' . $action,
                  'constraints' => array(
                      'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                      'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                  ),
                  'defaults' => array(
                      'controller' => $controller,
                      'action'     => $action,
                  )
              )
          );
      }
  }