<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
69328 Lyon, FRANCE.

See Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notices for more information.
=========================================================================*/

/** Component for api methods */
class Slicerappstore_ApiComponent extends AppComponent
{

  /**
   * Helper function for verifying keys in an input array
   */
  private function _checkKeys($keys, $values)
    {
    foreach($keys as $key)
      {
      if(!array_key_exists($key, $values))
        {
        throw new Exception('Parameter '.$key.' must be set.', -1);
        }
      }
    }

  /**
   * Helper function to get the user from token or session authentication
   */
  private function _getUser($args)
    {
    $componentLoader = new MIDAS_ComponentLoader();
    $authComponent = $componentLoader->loadComponent('Authentication', 'api');
    return $authComponent->getUser($args, null);
    }

  /**
   * Test the web api from this plugin
   * @param foo (Optional) not used
   * @return a json object defining a foo --> bar relationship
   */
  public function test($args)
    {
      $ret = array();
      $ret['foo'] = 'bar';
      return $ret;
    } // end function test

} // end class

<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
69328 Lyon, FRANCE.

See Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notices for more information.
=========================================================================*/

/** Component for api methods */
class Slicerappstore_ApiComponent extends AppComponent
{

  /**
   * Helper function for verifying keys in an input array
   */
  private function _checkKeys($keys, $values)
    {
    foreach($keys as $key)
      {
      if(!array_key_exists($key, $values))
        {
        throw new Exception('Parameter '.$key.' must be set.', -1);
        }
      }
    }

  /**
   * Helper function to get the user from token or session authentication
   */
  private function _getUser($args)
    {
    try
      {
      $componentLoader = new MIDAS_ComponentLoader();
      $authComponent = $componentLoader->loadComponent('Authentication', 'api');
      }
    catch (Zend_Exception $e)
      {
      $authComponent = MidasLoader::loadComponent('Authentication');
      }
    return $authComponent->getUser($args, null);
    }

  /**
   * Test the web api from this plugin
   * @param foo (Optional) not used
   * @return a json object defining a foo --> bar relationship
   */
  public function test($args)
    {
      $ret = array();
      $ret['foo'] = 'bar';
      return $ret;
    } // end function test

} // end class

Support new location of Authentication component.
Support new location of Authentication component.

Following Midas commit d65efd4f9, authentication component has been
moved to core. This commit ensure that the module remains compatible with
Midas independently of that backward incompatible change.
