Giter VIP home page Giter VIP logo

cakephp-platform's Introduction

CakePHP Platform Component

PlatformComponent is a CakePHP component created to determine your browser name, browser version, operating system name and version based on your browser user agent.

Install Platform

  • Copy the src > Controller > Component > PlatformComponent.php to your Component folder.
  • Load the component in the controller with $this->loadComponent('Platform'); command.

Requirements

  • PHP >= 7.1.x
  • CakePHP >= 3.6.x

Browsers

  • IE / InternetExplorer
  • Edge
  • Firefox
  • Chrome
  • Safari
  • Opera
  • OperaMini
  • OperaMobile
  • Netscape
  • Maxthon
  • Konqueror
  • Camino
  • Fennec
  • SeaMonkey

isBrowser

function isBrowser(string $browser, string $version = null): bool

Usage of isBrowser function:

$result = $this->Platform->isBrowser('safari');
var_dump($result);

$result = $this->Platform->isBrowser('ie', '8');
var_dump($result);

Mobile devices, OS and Mobile OS

  • Windows
  • Mac / MacOS
  • Linux
  • Ubuntu
  • iOS
  • Android
  • iPod
  • iPad
  • iPhone
  • BlackBerry

isOS

function isOS(string $os): bool

Usage of isOS function:

$result = $this->Platform->isOS('macos');
var_dump($result);

Dynamic is methods

You can also check the operating system and browser using dynamically constructed is methods. The name of the operating system or browser name is in upper camel case, like OperatingSystemName or BrowserName. All methods return boolean values.

$result = $this->Platform->isMacOS();
var_dump($result);

$result = $this->Platform->isChrome();
var_dump($result);

$result = $this->Platform->isInternetExplorer('8.1');
var_dump($result);

Special names

  • isMacOS()
  • isiOS()
  • isiPod()
  • isiPad()
  • isiPhone()
  • isWebOS()
  • isIE($version = null)

Example

Load Platform component and get browser name and version.

namespace App\Controller;

use Cake\Controller\Controller;

/**
 * @package App\Controller
 * @property \App\Controller\Component\PlatformComponent $Platform
 */
class AppController extends Controller
{
    // Your code
    public function initialize()
    {
        $this->loadComponent('Platform');
    }

    public function index()
    {
        // Get browser User Agent
        $ua = $this->Platform->getUserAgent();
        echo $ua;

        // BROWSER
        $browser = $this->Platform->getBrowser();
        // Get browser name
        echo $browser->name;

        // Get browser version
        echo $browser->version;

        // OS
        $os = $this->Platform->getOS();
        // Get operating system name
        echo $os->name;

        // Get operating system version
        echo $os->version;

        // Check if is iPhone
        $result = $this->Platform->isiPhone();
        var_dump($result);

        // Check if is iOS device
        $result = $this->Platform->isiOS();
        var_dump($result);
    }
    // Your code
}

Enjoy ;)

cakephp-platform's People

Contributors

mrred85 avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

kamal-m

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.