/** * Write benchmarking performance in the log file, then exit * * @param String $log_info info written to the log (default is "Finished") */ public static function finish($log_info = 'Finished') { if (defined('BENCHMARKING_ON')) { load_tool('Log'); $msecs = (int) (1000 * (microtime(TRUE) - self::$start)); Log::info($log_info . " after {$msecs} ms"); } exit; }
/** * Encode data as YAML and return YAML text * * @param Array/Object $data the data to encode * @return String the encoded data as YAML text */ public static function to_yaml($data) { load_tool('YAML'); return YAML::dump(object_to_array($data)); }
<?php header('Content-Type: text/plain'); load_tool('YAML'); // Get the data to encode into YAML if (!isset($data)) { $data = array(); } // Now for our elegant YAML encoding echo YAML::dump($data);
<?php // Copyright (c) 2010 Guanoo, Inc. // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public License // as published by the Free Software Foundation; either version 3 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. load_tool('Data'); /** * Provide a simple helper to write objects to a queue and read * them from the queue (either by blocking - default behavior - * or non-blocking). * * The objects written and read from the queue retain their PHP * object classes (provided classes are already loaded into the * program). The objects are written as files in queue folders. * * @author Kevin Hutchinson <*****@*****.**> */ class Queue extends YAWF { const QUEUE_FOLDER = 'app/tmp/queue'; const QUEUE_PAUSE = 1; // second when blocking const QUEUE_NAME = Symbol::DEFAULT_WORD;
<?php // Copyright (c) 2010 Guanoo, Inc. // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public License // as published by the Free Software Foundation; either version 3 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. load_interfaces('Modelled', 'Persisted', 'Validated'); load_tool('REST'); /** * The Remote class provides remote data manipulation capabilities via REST * by providing a facade to a data model object via the Modelled, Persisted * and Validated interfaces. * * @author Kevin Hutchinson <*****@*****.**> */ class Remote extends Relating_model implements Modelled, Persisted, Validated { const DEFAULT_TYPE = Symbol::JSON; // (it's built into PHP) const DB = '__db'; private static $defaults = array(); private $username; // Do we need a username too? private $password;
/** * Send a mail message (this depends on the Mail tool) by reading an * HTML file and a text file from a "mail" folder in a views folder. * * @param String $file the file to send (e.g. "welcome") * @param Object $render optional data to render (can be an Array) * @return String the raw content of the message that was sent */ public function send_mail($file, $render = NULL) { $file = "mail/{$file}"; $render = new Object($render); load_tool('Mail'); $text = $this->render_view($file, $render, array('ext' => '.text.php', 'must_find' => TRUE)); $html = $this->render_view($file, $render, array('ext' => '.html.php', 'must_find' => TRUE)); $render->text = $text; $render->html = $html; return Mail::send($render, $this->is_testing); }
function validate_tool_info($tool_id, &$toolInfo) { $err_msg = array(); if (strlen($tool_id) > 0 && is_numeric($tool_id)) { $toolInfo = load_tool($tool_id); if ($toolInfo == false) { array_push($err_msg, "ツールID が不正です。"); } } else { array_push($err_msg, "ツールID が不正です。"); } return $err_msg; }
/** * Copy the Ruby on Rails "t()" translate function to translate some text * * @param String $lookup the lookup string (see "configs/translate.yaml" file) * @param Array $replacements an optional array of text replacements to make * @return String the translated text after any replacements have been made */ function t($lookup, $replacements = array()) { static $is_loaded = FALSE; // for speed if (!$is_loaded) { load_tool('Translate'); } $is_loaded = TRUE; $app = YAWF::prop(Symbol::APP); return $app ? Translate::into($app->get_lang(), $lookup, $replacements) : NULL; }
<?php header('Content-Type: text/xml'); load_tool('XML'); // Get the data to encode into XML if (!isset($data)) { $data = array(); } // Now for our elegant XML encoding echo XML::serialize($data);