/** * Return the Google API services class files * * @return array $services with the format apiAdsenseService.php, */ public static function services() { // Fetch all Google API services classes from Bundle folder. // scandir returns the files of a folder including '.' & '..' so we slice // the returned array to remove them. $classes = array_slice(scandir(Bundle::path('google-api-php-client') . 'google-api-php-client' . DS . 'src' . DS . 'contrib' . DS), 2); return self::$services = $classes; }
$google->setAccessToken(Session::get('token')); return View::make(Bundle::prefix(BUNDLE_NAME) . 'index')->with('services', Google::services()); } if ($google->getAccessToken()) { Session::put('token', $google->getAccessToken()); return View::make(Bundle::prefix(BUNDLE_NAME) . 'index')->with('services', Google::services()); } else { $data = array('google_auth_url' => $google->createAuthUrl()); return View::make(Bundle::prefix(BUNDLE_NAME) . 'index', $data); } }); Route::get('(:bundle)/(:any)', function ($service) { $google = IoC::resolve('google-api-php-client'); $class_name = 'Google_' . ucfirst($service) . 'Service'; $class_file = $class_name . ".php"; $classes = Google::services(); if (Session::has('token')) { $google->setAccessToken(Session::get('token')); try { if (in_array($class_file, $classes)) { $service = new $class_name($google); } else { throw new Exception('Google API Service not found'); } } catch (apiServiceException $e) { print 'There was an API service error ' . $e->getCode() . ':' . $e->getMessage(); } catch (apiException $e) { print 'There was a general API error ' . $e->getCode() . ':' . $e->getMessage(); } catch (Exception $e) { print 'There was a general error ' . $e->getCode() . ':' . $e->getMessage(); }