Пример #1
0
 public function execute($files)
 {
     printLn('=> CategoryWriter.');
     $this->make_categories_directory();
     $categories = Application::db()->retrieve('categories_list');
     $writer = new DataWriter();
     foreach ($categories as $cat => $posts) {
         $tmpl = $this->make_data($cat, $posts);
         $writer->write($tmpl['slug'], 'index.html', $tmpl['html']);
     }
 }
Пример #2
0
/**
 * echo recent entries in the error log
 * @param int $numberOfEntries
 */
function errorLogRecentEntries($numberOfEntries = 5)
{
    $errorLogFilename = 'error_log';
    if (!file_exists($errorLogFilename)) {
        println("Could not find filename: " . $errorLogFilename);
        return;
    }
    try {
        $errorMessages = file_get_contents('error_log');
    } catch (Exception $e) {
        println("Could not open log file. Possible reasons:");
        println("File size: " . fileGetSize($errorLogFilename));
        return;
    }
    $errorMessagesArray = explode("\n", $errorMessages);
    $i = 0;
    foreach ($errorMessagesArray as $line) {
        $i++;
        printLn($line);
        if ($i >= $numberOfEntries) {
            break;
        }
    }
}
Пример #3
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Retrinko\Ini\IniFile;
try {
    // Load contents from ini file
    $iniFile = IniFile::load(__DIR__ . '/sample.ini');
    // Read key1 value from default section
    $key1 = $iniFile->get('default', 'key1');
    printLn('default section, key1 value: %s', $key1);
    // Read key1 value from A section
    $key1 = $iniFile->get('A', 'key1');
    printLn('A section, key1 value: %s', $key1);
    // Read key1 value from B section
    $key1 = $iniFile->get('B', 'key1');
    printLn('B section, key1 value: %s', $key1);
    // Read boolYes value from B section
    $boolYes = $iniFile->get('B', 'boolYes');
    printLn('B section, boolYes value: %s', $boolYes);
    // Get ini file contents as array
    $array = $iniFile->toArray();
    printLn('Contents as array: %s', PHP_EOL . var_export($array, true));
} catch (\Exception $e) {
    printLn('Exception! %s', $e->getMessage());
}
function printLn($string)
{
    $vars = func_get_args();
    array_shift($vars);
    vprintf('>>> ' . $string . PHP_EOL, $vars);
}
Пример #4
0
 /**
  * Log current page.
  * @param $title string | The title of the page.
  * @param $slug string | The slug.
  * @return void
  */
 private function log_current_page($title, $slug)
 {
     printLn('==> Current page: ' . $title . ': /' . $slug);
 }
Пример #5
0
     * 
     * @var double $a The first operand
     * @var double $b The second operand
     * @return double The product
     */
    public function calculate($a, $b)
    {
        return pow($a, $b);
    }
}
$calc = new Calculator([new AbsoluteValue(), new NaturalLog(), new Exponent(), new Multiply(), new Divide(), new Modulus(), new Add(), new Subtract()]);
// printLn($calc->calculate('---2'), 'should be -2');
printLn($calc->calculate('|-2|'), 'should be 2');
printLn($calc->calculate('ln 2'), 'should be approximately 0.6931471805599453');
printLn($calc->calculate('4 ^ 2'), 'should be 16');
printLn($calc->calculate('4 + 1'), 'should be 5');
printLn($calc->calculate('4 - 3'), 'should be 1');
printLn($calc->calculate('3 * 2'), 'should be 6');
printLn($calc->calculate('5 / 2'), 'should be 2.5');
printLn($calc->calculate('5 % 2'), 'should be 1');
printLn($calc->calculate('4 + -1'), 'should be 3');
printLn($calc->calculate('4 - -3'), 'should be 7');
printLn($calc->calculate('-3 * 2'), 'should be -6');
printLn($calc->calculate('+5 / -2'), 'should be -2.5');
printLn($calc->calculate('5 % -2'), 'should be -1');
printLn($calc->calculate('4 + 5 / 2'), 'should be 6.5');
printLn($calc->calculate('4 - 5 * 2'), 'should be -6');
printLn($calc->calculate('1 + 11 - 2 * 3 / 4'), 'should be 10.5');
printLn($calc->calculate('1 + -11 - 2 * 3 / 4'), 'should be -11.5');
printLn($calc->calculate('1 + 11 - 2 * 3 / 2 % 2'), 'should be 11');