Exemplo n.º 1
0
 /**
  * Start an HTML form by returning an opening form tag
  *
  * @param String $id the form's id (required)
  * @param String $action the form's action (optional)
  * @param Array $attrs the form tag's attributes (optional)
  * @return String the opening HTML form tag
  */
 public static function form_open($id, $action = NULL, $attrs = array())
 {
     if (is_null($action) && ($app = YAWF::prop(Symbol::APP))) {
         $action = $app->get_path();
     }
     $attrs['id'] = $id;
     $attrs['action'] = AppView::uri($action, array_key($attrs, 'prefix'));
     $attrs['method'] = array_key($attrs, 'method', 'post');
     // by default
     return '<form ' . self::attrs($attrs) . ">\n";
 }
Exemplo n.º 2
0
 /**
  * Get the basic auth password
  *
  * @return String the basic auth password
  */
 public static function password()
 {
     $server = YAWF::prop(Symbol::SERVER);
     return $server->php_auth_pw;
 }
Exemplo n.º 3
0
 /**
  * Return a request session object
  *
  * @return Request_session a request session object holding session values
  */
 protected function session_object()
 {
     if ($session = YAWF::prop(Symbol::SESSION)) {
         return $session;
     } else {
         return YAWF::prop(Symbol::SESSION, new Request_session());
     }
 }
Exemplo n.º 4
0
 /**
  * Create a new controller flash object
  *
  * @param Array $array an optional array of flash messages to display now
  */
 public function __construct($array = NULL)
 {
     $this->session = YAWF::prop(Symbol::SESSION);
     $var = self::SESSION_VAR;
     if (!is_object($this->session->{$var})) {
         $this->session->{$var} = new Object();
     }
     $this->flash_now = is_null($array) ? $this->session->{$var} : new Object($array);
     $this->session->{$var} = $this->flash_next = new Object();
 }
Exemplo n.º 5
0
 /**
  * Create a new service and return it
  *
  * @param String $class an optional class name
  * @param Integer $version the service version
  * @return Service the new service
  */
 public function new_service($class = NULL, $version = NULL)
 {
     // Require the Web_service base class
     // ...and the Application web service
     require_once 'lib/Web_service.php';
     load_service('App');
     // Require the service's subclass
     if (!$class) {
         $class = Text::camelize(Text::singularize($this->file));
     }
     if (!$version) {
         $version = $this->folder + 0;
     }
     try {
         load_service($class, $version);
     } catch (Exception $e) {
         $render = new Object();
         $render->data = array('error' => "Cannot load \"{$class}\" service version {$version}");
         echo $this->render_type($this->content_type, $render);
         exit;
     }
     // Create and return a new Service object
     $class .= '_service';
     // mandatory suffix
     $this->service = new $class();
     $this->service->setup_for_app($this);
     return YAWF::prop(Symbol::SERVICE, $this->service);
 }
Exemplo n.º 6
0
/**
 * 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;
}