2017 © Pedro Peláez
 

library console

php burnners console package

image

jbt/console

php burnners console package

  • Thursday, February 22, 2018
  • by JoueBien
  • Repository
  • 1 Watchers
  • 0 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

php Burner Console (jbt/console)

A small console for php5/7 for logging and dumping into a browsers js console. This package has been designed to work with php Burner 5 however it can also be used as a standalone library for native PHP or your favourite php framework., (*1)

Note that this is beta software and is not considered 100% production ready. Previous versions of the console have been used in php Burner 4, however, all these systems have been decommissioned. This iteration of the console is still being tested in php Burner 5 (in active development) and has yet to be tested in Laravel 5_6/5_5/5_4., (*2)

Installation

php Burner 5

  1. Add the package to your package.json composer require jbt/console:0.1.1, (*3)

  2. In the www/index.php file add the following, (*4)

use jbt\Console\Console as Console;

$app->use('console',Console::start());

standard php

  1. Add the package to your package.json composer require jbt/console:0.1.1, (*5)

  2. include the composer autoloader by adding, (*6)

require_once ( './../vendor/autoload.php'); //include composer libs

to the top of you page, (*7)

  1. then import the namespace using
use jbt\Console\Console as Console;
  1. and finally, init the console Class
$console = Console::start());

inti options

Development and Production Modes

The development mode is turned on by default when you call, (*8)

Console::start();

to visually specify the development mode is on it is recommended that you init the console using, (*9)

Console::start('dev');

Alternatively, if you want to disable the console for production than you can init the console using, (*10)

Console::start('live');

This returns an empty class with empty members and thus will not log anything into the js console, (*11)

Use

dumping vars to the js console

You can dump variables (arrays and objects) into the js console so that they are rendered as JSON object in the js console. To do this you use the ->dump(varToDump) member function., (*12)

//php burner 5
$console = $app->getLib('console'); // get console var
$TestVar = array(); 
$console->dump($TestVar); //add a var to dump
$console->show(); //echo to page - should be the last thing you call in your php
//native & other
$console = Console::start();
$TestVar = array();
$console->dump($TestVar);
$console->show(); //echo to page - should be the last thing you call in your php



### logging a string or number You can log strings or numbers to the js console by using the `->log(varToDump)` member function. Do not pass objects or arrays into the log funciton unless they have a toString meathod.
//php burner 5 $console = $app->getLib('console'); // get console var $testStr = "testStr"; $testNum = "testNum"; //add a vars to log $console->log($testStr); $console->log($testNum); $console->log("passing a string"."concat"); $console->log(10); $console->show(); //echo to page - should be the last thing you call in your php
//native & other
$console = Console::start();
$testStr = "testStr"; 
$testNum = "testNum";
//add a vars to log
$console->log($testStr); 
$console->log($testNum); 
$console->log("passing a string"."concat"); 
$console->log(10); 
$console->show(); //echo to page - should be the last thing you call in your php

logging warnings

Sometimes you might need to log warnings - this is particularly true if your writing db or file managment code using native php. The member function ->warning ("message as a string", "function name", "class name", "the php warning and stack trace string"); is used to log warnings to the browsers js console., (*13)

public function db_MYSQL ($console,$host,$username,$password,$dbname){
    try {
    $database = new PDO("mysql:host=$host;dbname=$dbname", $username, $password, array( PDO::ATTR_PERSISTENT => false));
    $database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $this->db=$database;
    return true;
    }catch (PDOException $e){
      $console->warning(
         " MySQL databse could not conected to $dbname.",
            "db_MYSQL('$host','$username','$password','$dbname')",
            "DatabaseConection",
            $e
       );
       return false;
    }
  }

The Versions

22/02 2018

dev-master

9999999-dev

php burnners console package

  Sources   Download

MIT

by Zach Radloff

22/02 2018

v0.1.1

0.1.1.0

php burnners console package

  Sources   Download

MIT

by Zach Radloff

22/02 2018

v0.1.0

0.1.0.0

php burnners console package

  Sources   Download

MIT

by Zach Radloff