Download the PHP package zenstruck/mobile-bundle without Composer

On this page you can find all versions of the php package zenstruck/mobile-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mobile-bundle

ZenstruckMobileBundle

Adds various tools to help with mobile development in Symfony2.

Installation

  1. Add the following lines in your deps file:

    [ZenstruckMobileBundle]
        git=git://github.com/kbond/ZenstruckMobileBundle.git
        target=bundles/Zenstruck/Bundle/MobileBundle
  2. Add the Zenstruck namespace to your autoloader:

  3. Finally, enable the bundle in the kernel:

Mobile Manager

The zenstruck_mobile.manager service stores whether or not the current request is a mobile one.

Setup

In your config.yml:

zenstruck_mobile:
    full_host: example.com
    mobile_host: m.example.com

You can also set the mobile status of the current environment (ie config_mobile.yml):

zenstruck_mobile:
    mobile: true/false

This allows you to have a vhost point to index.php which enables the full environment and another vhost point to mobile.php which enables the mobile environment.

Examples

<?php

$this->container->get('zenstruck_mobile.manager')->isMobile(); // true or false
$this->container->get('zenstruck_mobile.manager')->getMobile(); // false or 'mobile'
$this->container->get('zenstruck_mobile.manager')->getMobileHost(); // your mobile_host set in config.yml
$this->container->get('zenstruck_mobile.manager')->getFullHost(); // your full_host set in config.yml

Listener

To have both your full and mobile site be in the same environment this bundle comes with an event listener. The listener compares the current request's host name to the mobile_host you set in your config.yml. If a match is found the manager's mobile flag is set to true.

Enable/Disable the listener in your config.yml:

zenstruck_mobile:
    use_listener: true/false

Twig Helper

There are twig functions that allow you to generate your full/mobile urls.

Enable/Disable them in your config.yml:

zenstruck_mobile:
    use_helper: true/false

Use them in your twig templates as follows:

{{ zenstruck_mobile_url() }} {# generates mobile url #}
{{ zenstruck_mobile_full_url() }} {# generates full url #}
{{ zenstruck_mobile_is_mobile() }} {# true if mobile #}

Optional Parameters

Examples

{# generate mobile url and set a ?mobile=true parameter #}
{{ zenstruck_mobile_url({'mobile': 1}) }}

{# generate full url, set a ?mobile=true parameter and set the prefix to https:// #}
{{ zenstruck_mobile_full_url({'mobile': 0, 'prefix': 'https://'}) }}

Suggested Usage

  1. Create 3 layouts: full.html.twig, mobile.html.twig layout.html.twig.
  2. Add the following to layout.html.twig:

    {% extends zenstruck_mobile_is_mobile() ? "MyBundle::mobile.html.twig" : "MyBundle::full.html.twig" %}
  3. Have all your templates extend layout.html.twig If the request is a mobile one your templates will be decorated with mobile.html.twig.

Custom TwigEngine

This bundle comes with a custom twig engine. It allows you to have mobile templates that are automatically rendered on a mobile request if they exist.

For example:

$this->container->get('templating')->render('MyBundle:Default:index.html.twig');

Will render the MyBundle:Default:index.html.twig template as normal on full site but on a mobile request it will look for MyBundle:Default:mobile/index.html.twig. If found it will render the mobile template, if not, it will render the default full one. Simply create a mobile folder in the same directoy as your full template and create a template with the same name in it.

Enable/Disable the custom twig engine in your config.yml:

zenstruck_mobile:
    use_twig_engine: true/false

Full Default Configuration

zenstruck_mobile:
    mobile: false
    use_listener: true
    use_helper: true
    use_twig_engine: false
    full_host: ~ # Required
    mobile_host: ~ # Required

Reference

Possible settings for .htaccess to handle mobile detection and redirect. This also allows a mobile device to override the redirect if a cookie is set. See the Twig Helper example above to see how to set the mobile parameter.

<IfModule mod_rewrite.c>
    RewriteBase /
    RewriteEngine On

    # Check if mobile=1 is set and set cookie 'mobile' equal to 1
    RewriteCond %{QUERY_STRING} (^|&)mobile=1(&|$)
    RewriteRule ^ - [CO=mobile:1:%{HTTP_HOST}]

    # Check if mobile=0 is set and set cookie 'mobile' equal to 0
    RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
    RewriteRule ^ - [CO=mobile:0:%{HTTP_HOST}]

    # cookie can't be set and read in the same request so check
    RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
    RewriteRule ^ - [S=1]

    # Check if this looks like a mobile device
    RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
    RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC,OR]
    RewriteCond %{HTTP:Profile}       !^$

    # Check if we're not already on the mobile site
    RewriteCond %{HTTP_HOST}          !^m\.
    # Check to make sure we haven't set the cookie before
    RewriteCond %{HTTP:Cookie}        !\mobile=0(;|$)
    # Now redirect to the mobile site
    RewriteRule ^ http://m.example.com%{REQUEST_URI} [R,L]

    # Symfony
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>

TODO


All versions of mobile-bundle with dependencies

PHP Build Version
Package Version
Requires symfony/framework-bundle Version ~2.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package zenstruck/mobile-bundle contains the following files

Loading the files please wait ....