/** * Provoquer une ErrorException et/ou retourne la dernière provoquée. * * @param string $message=null Le message de l'erreur * @param int $code=0 Le code de l'erreur * @return ErrorException|null */ public function error($message = null, $code = 0) { if ($message !== null) { $error = new ErrorException($message, $code); self::$_lastError = $error; if ($this->throwExceptions) { throw $error; } } return self::$_lastError; }
<?php // Load the file. require_once "../api-allocine-helper.php"; // Construct the object. $allohelper = new AlloHelper(); // Define parameters. $keywords = "The Dark Knight"; $page = 1; // It's important to catch Exceptions. try { // Request data with parameters, and save the response in $data. $data = $allohelper->search($keywords, $page); // No result ? if (count($data->movie) < 1) { // Print a error message. echo '<p>No result for "' . $keywords . '"</p>'; } else { // For each movie result. foreach ($data['movie'] as $movie) { // Print the title. echo "<h2>" . $movie['title'] . "</h2>"; } } } catch (ErrorException $e) { // Print a error message. echo "Error " . $e->getCode() . ": " . $e->getMessage(); }
<?php // Charger le fichier. require_once "../api-allocine-helper.php"; // Créer un objet AlloHelper. $allohelper = new AlloHelper(); // Définir les paramètres $motsCles = "The Dark Knight"; $page = 1; // Il est important d'utiliser le bloc try-catch pour gérer les erreurs. try { // Envoi de la requête avec les paramètres, et enregistrement des résultats dans $donnees. $donnees = $allohelper->search($motsCles, $page); // Affichage des informations sur la requête echo "<pre>", print_r($allohelper->getRequestInfos(), 1), "</pre>"; // Pas de résultat ? if (count($donnees['movie']) < 1) { // Afficher un message d'erreur. echo '<p>Pas de résultat pour "' . $motsCles . '"</p>'; } else { // Pour chaque résultat de film. foreach ($donnees['movie'] as $film) { // Afficher le titre. echo "<h2>" . $film['title'] . "</h2>"; } } } catch (ErrorException $e) { // Affichage des informations sur la requête echo "<pre>", print_r($allohelper->getRequestInfos(), 1), "</pre>"; // Afficher un message d'erreur. echo "Erreur " . $e->getCode() . ": " . $e->getMessage();
<?php require_once "../api-allocine-helper.php"; // Construct the object $allohelper = new AlloHelper(); // Get keywords echo "Keywords: "; // Trim the input text. $search = trim(substr(fgets(STDIN), 0, -1)); // Parameters $page = 1; $count = 16; try { // Request $data = $allohelper->search($search, $page, $count); // No result ? if (!$data or count($data->movie) < 1) { throw new ErrorException('No result for "' . $search . '"'); } // View number of results. echo "// " . $data->results->movie . ' results for "' . $search . '":' . PHP_EOL; // For each movie result. foreach ($data->movie as $i => $movie) { // i | code | title echo $i . "\t" . $movie->code . "\t" . $movie->title . PHP_EOL; } } catch (ErrorException $e) { echo "Error " . $e->getCode() . ": " . $e->getMessage() . PHP_EOL; }
<?php require_once "../api-allocine-helper.php"; // Construct the object $allohelper = new AlloHelper(); // Get the movie code echo "Movie code: "; // Get the code $code = (int) fgets(STDIN); try { // Request $movie = $allohelper->movie($code); echo 'Title : ' . $movie->title . PHP_EOL; echo 'Synopsis : ' . $movie->synopsis . PHP_EOL; echo 'Poster URL : ' . $movie->poster . PHP_EOL; } catch (ErrorException $e) { echo "Error " . $e->getCode() . ": " . $e->getMessage() . PHP_EOL; }
return count($this->_data); } /** * Si l'on essaie d'accéder à l'objet comme à un tableau. * * @param string|int $offset * @return mixed */ public function offsetGet($offset) { $data = $this->_getProperty($offset); if (is_array($data)) { return new AlloData($data, $this->utf8Decode);