Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
User Agents PHP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ad Aures
User Agents PHP
Commits
ce81b43c
Commit
ce81b43c
authored
Oct 5, 2020
by
Benjamin Bellamy
Browse files
Options
Downloads
Patches
Plain Diff
Convert class back to script
parent
e61c1246
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+54
-1
54 additions, 1 deletion
README.md
README.md.backup
+55
-0
55 additions, 0 deletions
README.md.backup
composer.json
+2
-2
2 additions, 2 deletions
composer.json
src/UserAgentsGenerate.php
+21
-19
21 additions, 19 deletions
src/UserAgentsGenerate.php
with
132 additions
and
22 deletions
README.md
+
54
−
1
View file @
ce81b43c
# user-agents-php
PHP implementation for
[
opawg / user-agents
](
https://github.com/opawg/user-agents
)
This is a dummy PHP implementation for
[
opawg / user-agents
](
https://github.com/opawg/user-agents
)
## Installation
### Via composer
-
Add
``podlibre/user-agents-php` to your `composer.json`.
- Add ``
post-install-cmd
` / `
post-update-cmd
` scripts to your `
composer.json
` so that the class is generated.
```
{
"require": {
"podlibre/user-agents-php": "*"
},
"scripts": {
"post-install-cmd": "@php vendor/podlibre/user-agents-php/src/UserAgentsGenerate.php > vendor/podlibre/user-agents-php/src/UserAgents.php",
"post-update-cmd": "@php vendor/podlibre/user-agents-php/src/UserAgentsGenerate.php > vendor/podlibre/user-agents-php/src/UserAgents.php"
}
}
```
### Manually
- Clone git repository where you need it:
```
$ git clone https://github.com/podlibre/user-agents-php.git
```
- Generate the class:
```
$ php src/UserAgentsGenerate.php > src/UserAgents.php
```
Or with composer:
```
$ composer run-script post-install-cmd
```
## Usage
When you need it, just call `
\P
odlibre
\U
serAgentsPhp
\U
serAgents::find()
`:
```
$player = \Podlibre\UserAgentsPhp\UserAgents::find($_SERVER['HTTP_USER_AGENT']);
if($player){
print player['app']."\n";
print player['device']."\n";
print player['os']."\n";
print player['bot']."\n";
} else {
print "This user-agent was not found\n";
}
``
`
\ No newline at end of file
This diff is collapsed.
Click to expand it.
README.md.backup
0 → 100644
+
55
−
0
View file @
ce81b43c
# user-agents-php
This is a dummy PHP implementation for [opawg / user-agents](https://github.com/opawg/user-agents)
## Installation
### Via composer
- Add ``podlibre/user-agents-php` to your `composer.json`.
- Add ``post-install-cmd` / `post-update-cmd` scripts to your `composer.json` so that the class is generated.
```
{
"require": {
"podlibre/user-agents-php": "*"
},
"scripts": {
"post-install-cmd": "@php vendor/podlibre/user-agents-php/src/UserAgentsGenerate.php > vendor/podlibre/user-agents-php/src/UserAgents.php",
"post-update-cmd": "@php vendor/podlibre/user-agents-php/src/UserAgentsGenerate.php > vendor/podlibre/user-agents-php/src/UserAgents.php"
}
}
```
### Manually
- Clone git repository where you need it:
```
$ git clone https://github.com/podlibre/user-agents-php.git
```
- Generate the class:
```
$ php src/UserAgentsGenerate.php > src/UserAgents.php
```
Or with composer:
```
$ composer run-script post-install-cmd
```
## Usage
When you need it, just call `\Podlibre\UserAgentsPhp\UserAgents::find()`:
```
$player = \Podlibre\UserAgentsPhp\UserAgents::find($_SERVER['HTTP_USER_AGENT']);
if($player){
print player['app']."\n";
print player['device']."\n";
print player['os']."\n";
print player['bot']."\n";
} else {
print "This user-agent was not found\n";
}
```
\ No newline at end of file
This diff is collapsed.
Click to expand it.
composer.json
+
2
−
2
View file @
ce81b43c
...
...
@@ -16,7 +16,7 @@
}
},
"scripts"
:
{
"post-install-cmd"
:
"
Podlibre
\\
UserAgentsPhp
\\
UserAgentsGenerate::generate
"
,
"post-update-cmd"
:
"
Podlibre
\\
UserAgentsPhp
\\
UserAgentsGenerate.php::generate
"
"post-install-cmd"
:
"
@php src/UserAgentsGenerate.php > src/UserAgents.php
"
,
"post-update-cmd"
:
"
@php src/UserAgentsGenerate.php > src/UserAgents.php
"
}
}
This diff is collapsed.
Click to expand it.
src/UserAgentsGenerate.php
+
21
−
19
View file @
ce81b43c
<?php
namespace
Podlibre\UserAgentsPhp
;
#!/usr/bin/php
class
UserAgentsGenerate
{
<?php
/*
* Load json and convert it to PHP object:
*/
public
static
function
generate
(
$userAgent
)
{
$rowstr
=
var_export
(
json_decode
(
file_get_contents
(
...
...
@@ -17,14 +15,15 @@ class UserAgentsGenerate {
);
// autogenerate database
$code
=
<<<EOT
print
<<<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:
...
...
@@ -48,7 +47,10 @@ class UserAgents {
return \$playerFound;
}
EOT;
file_put_contents
(
'UserAgents.php'
,
$code
.
" static public
\$
db = "
.
$rowstr
.
";
\n
}
\n
"
);
}
}
\ No newline at end of file
print
" static public
\$
db = "
;
print
$rowstr
;
print
";
\n
"
;
print
"}
\n
"
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment