Beispiel #1
0
<?php

/**
 * Example. Usage of Gelembjuk/Mail . Send simple contact email.
 * The example shows how to easy create wel formatted emails and send them to users
 * The package allows to change sending engine easy without many changes in your PHP code.
 * Different mail systems have same interface, change only mailer clas name.
 * 
 * This example is part of gelembjuk/templating package by Roman Gelembjuk (@gelembjuk)
 */
// ===================== INIT SECTION =================================
// path to your composer autoloader
require 'vendor/autoload.php';
$thisdir = dirname(__FILE__) . '/';
// create logger object
$logger1 = new Gelembjuk\Logger\FileLogger(array('logfile' => $thisdir . '/logs/log.txt', 'groupfilter' => 'all'));
if (!$logger1->logFileIsWritable()) {
    echo '<font color="red">No access to write to log file </font>';
    exit;
}
// choose what mailer type do you want to use (null,phpmailer,phpnative)
$mailertype = 'null';
// it is really used only if  $mailertype is 'phpmailer'
$maileroptions = array('logger' => $logger1, 'format' => array('locale' => '', 'deflocale' => 'en', 'templateprocessorclass' => null, 'templatecompiledir' => $thisdir . '/email_tmp/', 'templatespath' => $thisdir . '/email_intern_templates/'), 'mailsystem' => 'smtp', 'smtp_host' => 'smtp_host', 'smtp_port' => 25, 'smtp_secure' => false, 'smtp_auth' => true, 'smtp_user' => 'smtp user', 'smtp_password' => 'smtp password');
// make email sending object
switch ($mailertype) {
    case 'phpmailer':
        $mailer = new \Gelembjuk\Mail\PHPMailer();
        break;
    case 'phpnative':
        $mailer = new \Gelembjuk\Mail\PHPNative();
Beispiel #2
0
    }
    protected function C()
    {
        $this->logger->debug('Called C', array('group' => 'C'));
    }
    protected function D()
    {
        // this will log if groups D or A or B are in the filter
        $this->logger->debug('Called D', array('group' => 'D|A|B'));
    }
}
// NOTE. this file must be writable!
// The path to your log file
$logfile = dirname(__FILE__) . '/tmp/log.txt';
// create the logger object
$logger1 = new Gelembjuk\Logger\FileLogger(array('logfile' => $logfile, 'groupfilter' => 'all'));
if (!$logger1->logFileIsWritable()) {
    echo '<font color="red">No access to write to log file ' . $logfile . '</font>';
    exit;
}
// do test log write. at this time all logs will be written
$logger1->debug('Test log', array('group' => 'test'));
// create test class object
$worker = new Worker($logger1);
// call a method to log somethign to a file
$worker->doSomething();
$logger1->debug('Now disable logging', array('group' => 'test'));
// disable all loggin with empty filter
$logger1->setGroupFilter('');
// call the method and nothing will be logged
$worker->doSomething();