Esempio n. 1
0
 /**
  * @test
  */
 public function testParse()
 {
     $result = PhpTemplate::load($this->getFixturePath('tpl.php'), array('verb' => 'do', 'b' => 'better'));
     $this->assertEquals('John do this better', $result);
 }
Esempio n. 2
0
 /**
  * Sends a email message from specified templated.
  *
  * This method uses translate array to parse template before sending.
  *
  * @param   string     $template      Path to template file.
  * @param   array      $translate     optional Transtation array looks like array(key => value)
  * @param   string     $to            optional "To" email address
  * @param   string     $toName        ]optional "To" email name.
  * @return  boolean    Returns true on succes
  * @throws  \Exception
  */
 public function sendTemplate($template, array $translate = array(), $to = null, $toName = null)
 {
     if (!is_file($template) || !is_readable($template)) {
         throw new \Exception(sprintf('Could not open the template "%s"', (string) $template));
     }
     //Loads template
     if (strtolower(substr($template, -4)) == '.php') {
         $body = PhpTemplate::load($template, $translate);
     } else {
         $body = file_get_contents($template);
         if (!empty($translate)) {
             $body = str_replace(array_keys($translate), array_values($translate), $body);
         }
     }
     //Extracts subject from the template
     if (preg_match('~\\[subject\\](.+?)\\[/subject\\]~U', $body, $matches)) {
         $subject = $matches[1];
         $body = preg_replace('~\\[subject\\].+?\\[/subject\\]~U', '', $body);
     }
     //Transforms according to MIME standards
     if (!empty($toName) && !empty($to)) {
         $to = self::addr($to, $toName, $this->charset);
     }
     return $this->send($to, isset($subject) ? $subject : null, $body);
 }
Esempio n. 3
0
    $options->uuid = strtolower(str_replace('-', '', $opt['r']));
}
$options->verbosity = isset($opt['v']);
$options->interactive = isset($opt['i']);
if (isset($opt['help']) || isset($opt['h'])) {
    $showusage();
}
if (isset($opt['n']) || isset($opt['new'])) {
    $template = UpgradeHandler::getPathToUpdates() . '/Template.php';
    if (!is_readable($template)) {
        $console->error('Could not open template file for reading ' . $template);
        exit;
    }
    $released = gmdate('YmdHis');
    $pathname = UpgradeHandler::getPathToUpdates() . '/Update' . $released . '.php';
    $tpl = PhpTemplate::load($template, array('upd_released' => $released, 'upd_uuid' => \Scalr::GenerateUID()));
    if ($console->confirm("Are you sure you want to create a new upgrade class?")) {
        if (file_put_contents($pathname, $tpl) === false) {
            $console->error('Could not write to file "%s"', $pathname);
            exit;
        }
        $console->success('Upgrade class "%s" has been successfully created.', realpath($pathname));
    }
    exit;
}
if (isset($opt['force'])) {
    UpgradeHandler::removePid();
}
$upgrade = new UpgradeHandler($options);
if (!$upgrade->run()) {
    exit(1);
Esempio n. 4
0
        $report = \Scalr_Util_Arrays::percentile($report, 90, true);
        if ($format == 'csv' && !array_key_exists($platform, $csvRowTemplate)) {
            $csvRowTemplate[$platform] = 0;
        }
    }
}
foreach ($data as $quarter => &$set) {
    $uniqueDates = count($set["days"]);
    $partial = $quarterDays[$set["quarter"]] + ($set["quarter"] === 0 && ($set["year"] % 4 === 0 && $set["year"] % 100 !== 0 || $set["year"] % 400 === 0) ? 1 : 0) === $uniqueDates ? false : $uniqueDates;
    if ($format == 'csv') {
        $csvData[] = array_merge($csvRowTemplate, ['year' => $set["year"], 'quarter' => $set["quarter"] + 1, 'partial' => empty($partial) ? '' : $partial], $set["dataByPlatform"]);
    } else {
        foreach ($set["dataByPlatform"] as $platform => &$report) {
            $platformName = array_key_exists($platform, $allPlatforms) ? $allPlatforms[$platform] : $platform;
            if (empty($report)) {
                $report = str_pad($platformName . ":", 32) . "0";
            } else {
                $report = str_pad($platformName . ":", 34) . str_replace("0", " ", sprintf("%05d", $report));
            }
        }
        $set["header"] = str_pad("===== " . $quarter . ($partial !== false ? " (Partial: " . $partial . " day" . ($partial > 1 ? "s" : "") . ")" : "") . " =====", 39, "=", STR_PAD_BOTH);
    }
}
if ($format == 'csv') {
    fputcsv(STDOUT, array_keys($csvRowTemplate));
    foreach ($csvData as $csvRow) {
        fputcsv(STDOUT, $csvRow);
    }
} else {
    echo PhpTemplate::load(APPPATH . "/templates/reports/usage_report.txt.php", ["data" => $data]);
}