Beispiel #1
0
            foreach ($project->fileList as &$fileObject) {
                $file = $dom->createElement('file');
                $files->appendChild($file);
                $path = $dom->createElement('path', $fileObject->path);
                $file->appendChild($path);
                $size = $dom->createElement('size', $fileObject->size);
                $file->appendChild($size);
            }
        }
        echo $dom->saveXML();
    }
}
//enable debugging
ini_set('display_errors', true);
ini_set('error_reporting', E_ALL);
//get list data
$list_fp = fopen("http://barril1.projects.cs.illinois.edu/svn_list.xml", "r") or die("Error reading XML data.");
$raw_list_data = "";
while ($data = fread($list_fp, 4096)) {
    $raw_list_data = $raw_list_data . $data;
}
// parse data into project data structure
$xml_parser = new Parser();
$parser = $xml_parser->xml();
$projects = $xml_parser->parse($raw_list_data);
// output XML file representing data structure
$output_engine = new OutputEngine();
$output_engine->outputXML($projects);
// free parser memory; close list file
xml_parser_free($parser);
fclose($list_fp);
 public function test()
 {
     $request = ['url' => 'http://thegamesdb.net/api/GetGame.php', 'params' => ['name' => 'harry potter']];
     $response = \HttpClient::get($request);
     dd(\Parser::xml($response->content()));
 }
 public function newGame(Request $request)
 {
     // Gets the game data from thegamesdb.net
     $data['games'] = [];
     if ($request->input('name')) {
         if ($request->input('platform')) {
             if ($request->input('exact')) {
                 $req = ['url' => 'http://thegamesdb.net/api/GetGame.php', 'params' => ['exactname' => $request->input('name'), 'platform' => $request->input('platform')]];
             } else {
                 $req = ['url' => 'http://thegamesdb.net/api/GetGame.php', 'params' => ['name' => $request->input('name'), 'platform' => $request->input('platform')]];
             }
         } else {
             if ($request->input('exact')) {
                 $req = ['url' => 'http://thegamesdb.net/api/GetGame.php', 'params' => ['exactname' => $request->input('name')]];
             } else {
                 $req = ['url' => 'http://thegamesdb.net/api/GetGame.php', 'params' => ['name' => $request->input('name')]];
             }
         }
         $response = \HttpClient::get($req);
         // Checks if only 1 game is produced
         if (isset(\Parser::xml($response->content())['Game'])) {
             $data['games'] = \Parser::xml($response->content())['Game'];
         } else {
             $data['games'] = [];
         }
         // Checks if the game returned is only 1
         if (isset($data['games']['id'])) {
             $valid_platforms = ["Sony Playstation 3", "Sony Playstation 4", "Sony Playstation Vita", "Nintendo 3DS", "PC", "Nintendo Wii U", "Nintendo Wii", "Microsoft Xbox 360", "Microsoft Xbox One"];
             $single_game = [];
             $single_game[0] = $data['games'];
             if (in_array($data['games']['Platform'], $valid_platforms)) {
                 $data['games'] = $single_game;
             } else {
                 $data['games'] = [];
             }
         } else {
             // FILTER ONLY VALID PLATFORMS
             $data['games'] = array_filter($data['games'], function ($var) {
                 $valid_platforms = ["Sony Playstation 3", "Sony Playstation 4", "Sony Playstation Vita", "Nintendo 3DS", "PC", "Nintendo Wii U", "Nintendo Wii", "Microsoft Xbox 360", "Microsoft Xbox One"];
                 return in_array($var['Platform'], $valid_platforms);
             });
             // SORT BY RELEASE DATE
             usort($data['games'], function ($a, $b) {
                 if (array_key_exists('ReleaseDate', $a) && array_key_exists('ReleaseDate', $b)) {
                     $format = "m/d/Y";
                     $date1 = \DateTime::createFromFormat($format, $b['ReleaseDate']);
                     $date2 = \DateTime::createFromFormat($format, $a['ReleaseDate']);
                     return $date1 > $date2;
                 }
                 return false;
             });
         }
     }
     $data['valid_platforms'] = ["Sony Playstation 3", "Sony Playstation 4", "Sony Playstation Vita", "Nintendo 3DS", "PC", "Nintendo Wii U", "Nintendo Wii", "Microsoft Xbox 360", "Microsoft Xbox One"];
     $perPage = 12;
     $currentPage = $request->input('page', 1) - 1;
     $pagedData = array_slice($data['games'], $currentPage * $perPage, $perPage);
     $page = $request->has('page') ? $request->get('page') : 1;
     $data['games'] = new LengthAwarePaginator($pagedData, count($data['games']), $perPage, $page, ['path' => $request->url(), 'query' => $request->query()]);
     $data['game_name'] = $request->input('name');
     return view('games.new', $data);
 }