Advertisement
shelob9

Untitled

Jul 24th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. use \josh\api\boot;
  2. add_action( 'rest_api_init', function(){
  3. //http://www.php-fig.org/psr/psr-4/examples/
  4. spl_autoload_register(function ($class) {
  5.  
  6. // project-specific namespace prefix
  7. $prefix = 'josh\\api\\';
  8. $base_dir = __DIR__ . '/api/';
  9. $len = strlen( $prefix );
  10. if ( strncmp( $prefix, $class, $len ) !== 0 ) {
  11. return;
  12. }
  13.  
  14. $relative_class = substr( $class, $len );
  15.  
  16. $file = $base_dir . str_replace( '\\', '/', $relative_class ) . '.php';
  17.  
  18. if ( file_exists( $file ) ) {
  19. require $file;
  20. }
  21. });
  22.  
  23. //make product route
  24. $product = new \josh\api\routes\product();
  25.  
  26. //OMG(s) shoes! Shoes!
  27. $shoes = new \josh\api\routes\shoes();
  28.  
  29. //make API go
  30. $api = new boot( 'store\v1' );
  31. $api->add_route( $product );
  32. $api->add_route( $shoes );
  33. $api->add_routes();
  34.  
  35. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement