Skip to content
Snippets Groups Projects
Commit e61c1246 authored by Benjamin Bellamy's avatar Benjamin Bellamy :speech_balloon:
Browse files

Convert script to class

parent 6dd081df
Branches
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@
}
},
"scripts": {
"post-install-cmd": "@php src/UserAgentsGenerate.php > src/UserAgents.php",
"post-update-cmd": "@php src/UserAgentsGenerate.php > src/UserAgents.php"
"post-install-cmd": "Podlibre\\UserAgentsPhp\\UserAgentsGenerate::generate",
"post-update-cmd": "Podlibre\\UserAgentsPhp\\UserAgentsGenerate.php::generate"
}
}
#!/usr/bin/php
<?php
namespace Podlibre\UserAgentsPhp;
class UserAgentsGenerate {
/*
* Load json and convert it to PHP object:
*/
public static function generate($userAgent) {
$rowstr = var_export(
json_decode(
file_get_contents(
......@@ -15,15 +17,14 @@ $rowstr = var_export(
);
// autogenerate database
print <<<EOT
$code = <<<EOT
<?php
namespace Podlibre\UserAgentsPhp;
/* Autogenerated. Do not edit */
class UserAgents {
public static function find(\$userAgent)
{
public static function find(\$userAgent) {
\$playerFound = null;
//Search for current HTTP_USER_AGENT:
......@@ -47,9 +48,7 @@ class UserAgents {
return \$playerFound;
}
EOT;
print " static public \$db = ";
print $rowstr;
print ";\n";
print "}\n";
file_put_contents('UserAgents.php', $code." static public \$db = ".$rowstr.";\n}\n");
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment