コード例 #1
0
ファイル: App.php プロジェクト: hutchike/YAWF
 /**
  * Construct a new App object
  *
  * @param String $uri an optional relative URI (e.g. "/folder/file")
  */
 public function __construct($uri = NULL)
 {
     if (is_null($uri)) {
         $uri = $_SERVER['REQUEST_URI'];
     }
     // Setup the config, prefix and assert checks
     $config = AppConfig::configure();
     load_helper('HTML', 'Text');
     load_tools('Log', 'Translate');
     $this->error_messages = array();
     $this->assert_checking($config);
     // Set the content type, folder and file
     $uri = preg_replace('/[\\?#].*/', '', $uri);
     $content_type = preg_match('/\\.(\\w+)$/', $uri, $matches) ? $matches[1] : DEFAULT_CONTENT_TYPE;
     if ($content_type === Symbol::TEST && !Config::get('TESTING_ENABLED')) {
         $content_type = DEFAULT_CONTENT_TYPE;
     }
     $uri = $this->set_lang_and_remove_prefix($uri);
     $this->parts = explode('/', $uri);
     $folder = $this->get_part(0, TRUE);
     // remove any extension
     $file = $this->get_part(1, TRUE);
     // remove any extension
     // Setup the application request environment
     $this->content_type = strtolower($content_type);
     // e.g. "html", "test"
     $this->folder = strlen($folder) > 0 ? $folder : DEFAULT_FOLDER;
     $this->file = strlen($file) > 0 ? $file : DEFAULT_FILE;
     $this->is_testing = $this->is_testing || array_key($_REQUEST, Symbol::TEST) || $content_type === Symbol::TEST;
     if ($this->is_testing) {
         Log::type(Symbol::TEST);
     }
     // If we're testing then use a test database
     require_once 'lib/Model.php';
     $model = new Model();
     $db_test = Config::get('DB_DATABASE_TEST', TRUE);
     $db_live = Config::get('DB_DATABASE_LIVE', TRUE);
     $database = $this->is_testing ? $db_test : $db_live;
     $model->set_database($database);
     // Setup the language translations
     Translate::add_translations(Config::load('validate'));
     Translate::add_translations(Config::load('translate'));
     // Register this app as a prop
     YAWF::prop(Symbol::APP, $this);
 }
コード例 #2
0
ファイル: utils.php プロジェクト: hutchike/YAWF
/**
 * Load a tool
 *
 * @param String $tool the tool to load
 */
function load_tool($tool)
{
    load_tools($tool);
}
コード例 #3
0
ファイル: REST.php プロジェクト: hutchike/YAWF
<?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_tools('CURL', 'Data');
/**
 * Provide REST methods to "get", "put", "post" and "delete" data,
 * and parse any received data so that it's available as an array.
 *
 * @author Kevin Hutchinson <*****@*****.**>
 */
class REST extends YAWF
{
    /**
     * By default, REST uses the JSON type for parsing speed
     * and because JSON retains string and number data types
     */
    private static $type = Symbol::JSON;
    /**
     * By default, REST uses the UTF8 encoding
     */
    private static $charset = Symbol::UTF8;