Developed with love by KnpLabs Hire us for your project!
394

LadybugBundle

by raulfraile

Symfony2 bundle for Ladybug library, the Simple and Extensible PHP Dumper

LadybugBundle

Build Status
Latest Stable Version
Total Downloads
Latest Unstable Version

This bundle provides an easy and extensible var_dump/print_r replacement for
Symfony2 projects, both in controllers or Twig templates. For example, with this
bundle, the following is possible:

<?php
    class UserController extends Controller
    {
        public function userAction($username) {
            ladybug_dump($username); // or just ld($username)
        }
    }
{{ user.username|ladybug_dump }}

Getting as a result:

Installation

Step 1: Composer

Add the following line to the composer.json file:

{
    "require": {
        "raulfraile/ladybug-bundle": "~1.0"
    }
}

To actually install Ladybug in your project, download the composer binary and run it:

wget http://getcomposer.org/composer.phar
# or
curl -O http://getcomposer.org/composer.phar

php composer.phar install

Step 2: Enable the bundle

Finally, enable the bundle in the kernel:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new RaulFraile\Bundle\LadybugBundle\RaulFraileLadybugBundle(),
    );
}

Examples

It is possible to dump any variable, including arrays, objects and resources:

Dumping an array

<?php
    $var = array(1, 2, 3);
    ladybug_dump($var)

Dumping an object

<?php
    ladybug_dump($this->getRequest())

The same can be accomplished using the Twig filter ladybug_dump.

Helpers

The are 5 helpers that can be used in any controller:

ladybug_dump($var1[, $var2[, ...]]): Dumps one or more variables

ladybug_dump_die($var1[, $var2[, ...]]): Dumps one or more variables and
terminates the current script

ladybug_dump_return($format, $var1[, $var2[, ...]]): Dumps one or more variables and
returns the dump in any of the following formats:

  • yml: Returns the dump in YAML
  • json: Returns the dump in JSON
  • xml: Returns the dump in XML
  • php: Returns the dump in PHP arrays

ladybug_dump_ini([$extension]): Dumps all configuration options

ladybug_dump_ext(): Dumps loaded extensions

There are also some shortcuts in case you are not using this function names:

ld($var1[, $var2[, ...]]): shortcut for ladybug_dump

ldd($var1[, $var2[, ...]]): shortcut for ladybug_dump_die

ldr($format, $var1[, $var2[, ...]]): shortcut for ladybug_return

Only ladybug_dump can be used inside Twig templates.

Symfony profiler integration

Instead of printing out the dump tree inside the HTML document, you can use the Ladybug logger and
see the results in a tab of the Symfony profiler:

To make use of the Ladybug logger, grab the ladybug service from the DIC, and call the log
method:

<?php
class TestController
{
    public function testAction()
    {
        $var = 1;
        $this->get('ladybug')->log($var);
    }

API reference

Ladybug automatically detects Symfony, Doctrine, Twig, Silex and other classes, and link them to the
official documentation.

Configuration

You can configure ladybug library directly in your config.yml file. Here are the defaults:

raul_fraile_ladybug:
    theme: modern # select the theme: base, modern or custom themes
    expanded: false # true to expand all the variables tree by default
    silenced: false # true to ignore all ladybug calls

Credits

License

LadybugBundle is released under the MIT License. See the bundled LICENSE file for details.

Copyright (c) 2011 Raúl Fraile

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
raul_fraile_ladybug:
theme: modern
expanded: false
silenced: false
array_max_nesting_level: 9
object_max_nesting_level: 3
  • Merge pull request #61 from Survos/master
    By raulfraile, 2 years ago
  • fixing "Undefined index: vars" in symfony 2.6 debug toolbar
    By piogrek, 2 years ago
  • Merge pull request #60 from ricardclau/add_tests
    By raulfraile, 2 years ago
  • add tests and removed someuseless use and bundle construct
    By ricardclau, 2 years ago
  • Merge pull request #51 from boteeka/master
    By raulfraile, 2 years ago
  • Ensure Ladybug service always uses the HTML format
    By , 2 years ago
  • Merge pull request #47 from mmoreram/feature/remove-dic-dependency
    By raulfraile, 2 years ago
  • Merge pull request #48 from mmoreram/feature/updated-gitignore
    By raulfraile, 2 years ago
  • Updated gitignore to ignore these files/folders
    By mmoreram, 2 years ago
  • Removed all DIC dependency in twig extension and DataCollector
    By mmoreram, 2 years ago
  • Merge pull request #43 from h4cc/master
    By raulfraile, 2 years ago
  • Added PHP 5.6 and HHVM to travis.
    By h4cc, 2 years ago
  • [composer] Removed version
    By raulfraile, 3 years ago
  • [travis] Added PHP 5.5
    By raulfraile, 3 years ago
  • [readme] Fixed version
    By raulfraile, 3 years ago
  • [readme] Added config explanations
    By raulfraile, 3 years ago
  • [readme] API docs example
    By raulfraile, 3 years ago
  • [readme] Updated profiler image
    By raulfraile, 3 years ago
  • [readme] Profiler example
    By raulfraile, 3 years ago
  • [readme] Updated examples
    By raulfraile, 3 years ago
  • [readme] Added example
    By raulfraile, 3 years ago
  • [readme] Added credits and contributors
    By raulfraile, 3 years ago
  • [readme] Fixed links
    By raulfraile, 3 years ago
  • [readme] Added links for current version and downloads
    By raulfraile, 3 years ago
  • [readme] Fixed version
    By raulfraile, 3 years ago
  • #18 Remove symfony 2.0 installation instructions
    By raulfraile, 3 years ago
  • Merge pull request #32 from tacman/patch-1
    By raulfraile, 3 years ago
  • Fixed link to Ladybug library.
    By tacman, 3 years ago
  • Updated version
    By raulfraile, 3 years ago
  • Require stable version of plugin-symfony2
    By raulfraile, 3 years ago