本文整理汇总了PHP中def函数的典型用法代码示例。如果您正苦于以下问题:PHP def函数的具体用法?PHP def怎么用?PHP def使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了def函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_function
/**
* Implements functionThatShouldNotShowUp();
*/
function test_function()
{
// Test a normal function should work properly.
normalFunction('test data');
// Test exceptions: start simple - call a function that doesn't exist with a space in between the function name
// and "(".
functionThatDoesNotExist('param1', 'param2');
functionThatDoesNotExist2('param1', 'param2');
// Call a function within a function.
abc(def('abc'));
// Use a constant, that can be misconstrued as a function potentially.
$test_result = 3 - TEST_CONST;
// Test referring to an object.
$testJsonResponse = (object) array('data' => 'abc');
$testJsonResponse->data = 'abc';
$result = drupal_json_decode($json->data);
// Create a reference to returned value
$a =& reference_returner_function();
// Static method call
StaticTestClass::staticFunctionCall();
// Method call
$someInstance->someMetod();
// Creating a class
$a = new stdClass();
}
示例2: create
/**
* function create()
*
* @param $back_url the url where the function retutn at the end of the operation
* @return nothing
*/
function create($idTest, $back_test)
{
if (!sql_query("\r\n\t\tINSERT INTO " . $GLOBALS['prefix_lms'] . "_testquest \r\n\t\t( idTest, type_quest, title_quest, sequence, page, difficult ) VALUES \r\n\t\t( \t'" . $idTest . "', \r\n\t\t\t'" . $this->getQuestionType() . "', \r\n\t\t\t'<span class=\"text_bold\">" . Lang::t('_QUEST_BREAK_PAGE') . "</span>',\r\n\t\t\t'" . $this->_getNextSequence($idTest) . "', \r\n\t\t\t'" . $this->_getPageNumber($idTest) . "',\r\n\t\t\t'0') ")) {
errorCommunication(def('_OPERATION_FAILURE') . getBackUi(Util::str_replace_once('&', '&', $back_test), Lang::t('_BACK')));
}
Util::jump_to('' . $back_test);
}
示例3: run
public function run()
{
try {
$this->req('ident');
} catch (\System\Error\Argument $e) {
$this->req('id');
}
def($this->template, 'system/text/show');
def($this->show_heading, true);
$conds = array();
if (isset($ident)) {
$conds['ident'] = $ident;
} else {
$conds['id_system_text'] = $id;
}
if ($text = \System\Text::get_first($conds)->fetch()) {
$this->partial($template, array("text" => $text, "show_heading" => $show_heading));
} else {
if (cfg('dev', 'debug', 'backend')) {
throw new \System\Error\Config('Text was not found', isset($ident) ? $ident : $id);
} else {
throw new \System\Error\NotFound();
}
}
}
示例4: __construct
function __construct ($name) {
$apps = Frix::config('APPS');
// Check if app is installed or throw an exception
if (!array_key_exists($name, $apps)) {
throw new AppException(sprintf('Application "%s" not installed!', $name));
}
// Set name
$this->name = $name;
// Use the class-name to create verbose_name if it's not set
$v_name = preg_replace('/App$/', '', get_class($this));
def($this->verbose_name, $v_name);
// Configure the application path
// $this->path = join_path(array(Frix::config('ROOT'), $apps[$name]));
$this->path = $apps[$name];
// Setup models and views path
def($this->views_path, join_path(array($this->path, 'views.php')));
def($this->models_path, join_path(array($this->path, 'models')));
}
示例5: __new__
protected function __new__($email = null, $password = null)
{
$this->email = def("arbo.service.GoogleAPI@email", $email);
$password = def("arbo.service.GoogleAPI@password", $password);
$this->vars("Email", $this->email);
$this->vars("Passwd", $password);
$this->vars("accountType", "GOOGLE");
$this->vars("source", "Google-Contact-Lister");
$this->vars("service", "cl");
$this->do_post("https://www.google.com/accounts/ClientLogin");
foreach (explode("\n", $this->body()) as $line) {
if (strpos($line, "SID=") === 0) {
$this->sid = trim(substr($line, 4));
} else {
if (strpos($line, "LSID=") === 0) {
$this->lsid = trim(substr($line, 5));
} else {
if (strpos($line, "Auth=") === 0) {
$this->auth = trim(substr($line, 5));
}
}
}
}
if (empty($this->auth)) {
throw new Exception("auth");
}
}
示例6: exec
/**
* Execute this module
*
* @return void
*/
public function exec()
{
if (!$this->accessible()) {
throw new \System\Error\Permissions(sprintf('Cannot access module "%s". Permission denied.', $this->get_path()));
}
$locals =& $this->opts;
def($locals['per_page'], 20);
def($locals['page'], intval($this->request->get('page')));
$locals['per_page'] = intval($locals['per_page']);
$propagated = array();
if (count($this->parents)) {
$propagated = $this->dbus->get_data($this->parents);
$locals = array_merge($locals, $propagated);
}
foreach (self::$array_forced_locals as $var) {
if (isset($locals[$var]) && !is_array($locals[$var])) {
throw new \System\Error\Argument(sprintf('Local variable "$%s" must be an array for module "%s"', $var, $this->get_path()));
}
}
foreach ($locals as $key => &$val) {
if (is_string($val) && preg_match("/^\\#\\{[0-9]{1,3}\\}\$/", $val)) {
$temp = $this->response->request->args;
$temp_key = intval(substr($val, 2));
if (isset($temp[$temp_key])) {
$locals[$key] = $temp[$temp_key];
} else {
throw new \System\Error\Argument(sprintf('Path variable #{%s} was not found.', $temp_key));
}
}
}
$this->opts = $locals;
$this->run();
return $this;
}
示例7: __new__
protected function __new__($user = null, $password = null)
{
$this->id = isset($user) ? $user : def("arbo.service.WassrAPI@user");
$password = isset($password) ? $password : def("arbo.service.WassrAPI@password");
if (isset($this->id)) {
$this->auth($this->id, $password);
}
}
示例8: from_def
public static function from_def($parent, $name, array $def)
{
$def['parent'] = $parent;
$def['name'] = $name;
def($def['is_master'], false);
if (strpos($def['model'], '\\') === 0) {
$def['model'] = substr($def['model'], 1);
}
return new self($def);
}
示例9: __new__
protected function __new__($login = null, $password = null)
{
$this->login = isset($login) ? $login : def("arbo.net.mail.Gmail@login");
$this->password = isset($password) ? $password : def("arbo.net.mail.Gmail@password");
parent::__new__($login);
$this->resource = fsockopen("tls://smtp.gmail.com", 465, $errno, $errstr, 30);
if ($this->resource === false) {
throw new Exception("connect fail");
}
}
示例10: load_config
/** Get domain init data
* @return mixed
*/
public function load_config()
{
$cfg = cfg('domains', \System\Router::get_domain($this->host));
$this->rules = def($cfg['rules'], null);
$this->layout = (array) def($cfg['layout'], array());
$this->policies = (array) def($cfg['policies'], array());
$this->context = (array) def($cfg['context'], array());
$this->init = (array) def($cfg['init'], array());
return $this;
}
示例11: editSite
/**
* 그룹 수정
* @class admin.site
* @param
$data: 자료
$no: 대상번호
-is_check: 입력변수 체크 여부
* @return
*/
function editSite($data, $no, $param = '')
{
global $mini;
$param = param($param);
def($param['is_check'], 1);
//// 변수 체크
if ($param['is_check']) {
checkFieldSite($data);
}
//// 번호 넣기
if (is_array($no) && isset($data['id'])) {
__error('그룹 다중 수정에 아이디 수정이 포함되어 있습니다');
}
if (!is_array($no)) {
$tmp = $no;
$no = array();
$no[0] = $tmp;
}
//// 수정할 수 없는 정보 제거
unset($data['no']);
unset($data['date']);
unset($data['mode']);
unset($data['script']);
//// 넘어오지 않은 변수 처리
if (empty($data['site_link'])) {
$data['site_link'] = '';
}
foreach ($no as $key => $val) {
//// 번호 체크
check($val, 'type:num, name:그룹번호');
//// 데이터 로드
$data_ex = sql("SELECT * FROM {$mini['name']['site']} WHERE no={$val}");
if (!is_array($data_ex)) {
__error('해당 그룹이 존재하지 않습니다');
}
//// 권한체크
checkAdmin("\n\t\t\t\tsite: {$data_ex['no']}\n\t\t\t\ttype: ajax\n\t\t\t");
//// 기본변수 여부 체크
if (isset($data['name']) && !$data['name']) {
__error('그룹 이름을 입력해 주세요');
}
//// 이름 중복 체크
if (isset($data['name'])) {
if (sql("SELECT COUNT(*) FROM {$mini['name']['site']} WHERE no!={$val} and name='{$data['name']}'")) {
__error('중복된 그룹이름 입니다.');
}
}
//// 쿼리
sql("UPDATE {$mini['name']['site']} SET " . query($data, 'update') . " WHERE no={$val}");
//// 번호 재입력
$data['no'] = $val;
//// 로그 기록
addLog(array('mode' => 'site_edit', 'field1' => $data['no'], 'ment' => arr_diff($data_ex, $data)));
}
}
示例12: __new__
protected function __new__($user = null, $password = null)
{
if (empty($user)) {
$this->user = def("arbo.service.TwitterAPI@user");
$this->password = def("arbo.service.TwitterAPI@password");
} else {
$this->user = $user;
$this->password = $password;
}
$this->auth($this->user, $this->password);
}
示例13: __call
/** Alias to create simple input type
* @param string $name Name of called method
* @param array $args Arguments to the function
*/
public function __call($name, $args)
{
if (strpos($name, self::SEPARATOR_INPUT_METHOD) === 0) {
$type = substr($name, strlen(self::SEPARATOR_INPUT_METHOD));
if (!isset($args[0])) {
throw new \System\Error\Argument(sprintf('You must enter input name as first argument for System\\Form::%s method', $name));
}
return $this->input(array("type" => $type, "name" => $args[0], "label" => def($args[1], ''), "required" => def($args[2], false), "info" => def($args[3], '')));
} else {
throw new \System\Error\Wtf(sprintf('There is no form method "%s".', $name));
}
}
示例14: run
public function run()
{
$res = $this->response;
$status = 400;
$message = 'fill-all-fields';
$data = null;
$icons = \Car\Offer::get_attr_options('icon');
$opts = array();
foreach ($icons as $icon) {
$opts[] = array('value' => $icon, 'name' => $icon);
}
$ident = $this->ident;
def($ident, null);
$f = $res->form(array('use_comm' => true));
$f->input(array('type' => 'text', 'name' => 'driver', 'required' => true));
$f->input(array('type' => 'text', 'name' => 'from', 'required' => true));
$f->input(array('type' => 'number', 'name' => 'seats', 'min' => 1, 'required' => true));
$f->input(array('type' => 'datetime', 'name' => 'departure', 'required' => true));
$f->input(array('type' => 'select', 'name' => 'icon', 'required' => true, 'options' => $opts));
$f->input(array('name' => 'phone', 'type' => 'phone', 'required' => true));
$f->input(array('type' => 'email', 'name' => 'email', 'required' => true));
$f->input(array('type' => 'textarea', 'name' => 'desc', 'required' => false));
if ($f->submited()) {
if ($f->passed()) {
$attrs = $f->get_data();
$status = 200;
$message = 'saved';
if ($ident) {
$item = \Car\Offer::get_first()->where(array('ident' => $ident))->fetch();
if (!$item) {
throw new \System\Error\NotFound();
}
} else {
$item = new \Car\Offer();
}
$item->update_attrs($attrs);
$item->visible = true;
$item->save();
if (!$item->sent_notif) {
$item->send_notif($res);
}
$data = $item->get_data();
} else {
$data = $f->get_errors();
}
$res->mime = 'text/html';
if (!isset($ident) || $f->submited()) {
$this->json_response($status, $message, $data);
}
}
}
示例15: __callStatic
public static function __callStatic($method, $args)
{
if (self::is_enabled()) {
if (self::is_ready()) {
if (method_exists(self::get_driver(), $method)) {
return self::get_driver()->{$method}(def($args[0], null), def($args[1], null), def($args[2], null));
} else {
throw new \System\Error\Wtf(sprintf('Cache driver method does not exist: %s', $method));
}
}
} else {
return null;
}
}