本文整理汇总了PHP中API::AddHandler方法的典型用法代码示例。如果您正苦于以下问题:PHP API::AddHandler方法的具体用法?PHP API::AddHandler怎么用?PHP API::AddHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类API
的用法示例。
在下文中一共展示了API::AddHandler方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: curl_setopt
}
}
}
if ($ch = curl_init()) {
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($timeout) {
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
}
if ($data) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($binary && $response) {
$response = "data:{$mime};base64," . base64_encode($response);
}
$result = array("httpCode" => $httpcode, "body" => $response);
curl_close($ch);
} else {
$error = "Failed to initialize cURL";
}
}
return array($error, $result);
}
}
API::AddHandler('application', array('CoreAPIHandler', 'application'));
API::AddHandler('fs', array('CoreAPIHandler', 'fs'));
API::AddHandler('curl', array('CoreAPIHandler', 'curl'));
示例2: login
* @licence Simplified BSD License
*/
/**
* This is your handler class
*
* Out-of-the-box support for permissions! You just have to make sure your
* login method returns the right groups.
*
* @link http://os.js.org/doc/tutorials/create-handler.html
*/
class EXAMPLEAPIHandler extends APIHandler
{
public static function login(array $arguments)
{
$user = APIUser::login(array("id" => 0, "username" => "test", "name" => "EXAMPLE handler user", "groups" => array("admin")));
return array(false, $user->getData());
}
public static function logout(array $arguments)
{
APIUser::logout();
return array(false, true);
}
public static function settings(array $arguments)
{
return array(false, true);
}
}
API::AddHandler('login', array('EXAMPLEAPIHandler', 'login'));
API::AddHandler('logout', array('EXAMPLEAPIHandler', 'logout'));
API::AddHandler('settings', array('EXAMPLEAPIHandler', 'settings'));
API::SetHandler('EXAMPLEAPIHandler');
示例3: login
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Anders Evenrud <andersevenrud@gmail.com>
* @licence Simplified BSD License
*/
/**
* DemoAPIHandler for demoing
*/
class DemoAPIHandler extends APIHandler
{
public static function login(array $arguments)
{
$user = APIUser::login(array("id" => 0, "username" => "demo", "name" => "Demo User", "groups" => array("admin")));
return array(false, $user->getData());
}
public static function logout(array $arguments)
{
APIUser::logout();
return array(false, true);
}
/**
* Demo handler allows EVERYTHING
*/
public static function checkPrivilege($requires = null)
{
APIHandler::checkPrivilege(true);
}
}
API::AddHandler('login', array('DemoAPIHandler', 'login'));
API::AddHandler('logout', array('DemoAPIHandler', 'logout'));
API::SetHandler('DemoAPIHandler');
示例4: array
$db = self::_initDB();
APIUser::logout();
return array(false, true);
}
public static function settings(array $arguments)
{
$db = self::_initDB();
$result = false;
if (!isset($_SESSION['user'])) {
throw new Exception("Cannot set settings without user session");
}
$q = "UPDATE `users` SET `settings` = ? WHERE `id` = ?;";
$a = array(json_encode($arguments['settings']), $_SESSION['user']['id']);
if ($stmt = $db->prepare($q)) {
$result = $stmt->execute($a);
}
return array(false, $result);
}
/**
* This enables full privileges for all users. Simply remove to make use of the groups
* @see APIUser
*/
public static function checkPrivilege($requires = null)
{
APIHandler::checkPrivilege(true);
}
}
API::AddHandler('login', array('ExampleAPIHandler', 'login'));
API::AddHandler('logout', array('ExampleAPIHandler', 'logout'));
API::AddHandler('settings', array('ExampleAPIHandler', 'settings'));
API::SetHandler('ExampleAPIHandler');
示例5: broadway
<?php
class BroadwayAPIHandler
{
public static function broadway(array $arguments)
{
return array(false, false);
}
}
API::AddHandler('broadway', array('BroadwayAPIHandler', 'broadway'));