本文整理汇总了PHP中Error::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Error::create方法的具体用法?PHP Error::create怎么用?PHP Error::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Error
的用法示例。
在下文中一共展示了Error::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleError
/**
* PHP Errors (or warning/notices) will usually output something to the
* console and then return some unexpected value like false. Here we cause it
* to throw instead.
*/
static function handleError($level, $message, $file, $line, $context)
{
if ($level === E_NOTICE) {
return false;
}
$err = Error::create($message, 1);
$err->set('level', $level);
throw new Ex($err);
}
示例2: create
/**
* @desc Create a new cache file
* @param name, the name of the file
* @param data, and array of data to cache
* @return whether or not the file was created
*/
public static function create($name, $data)
{
if (is_array($data)) {
$data['modified'] = time();
File::write($name, json_encode($data), false, TEMP_BASE . 'cache/');
return true;
}
Error::create('The second parameter must be an array.
With keys : name, content and profile');
return false;
}
示例3: assert
static function assert($description, $condition = false)
{
if ($condition instanceof Closure) {
$condition = $condition();
}
if ($condition !== true) {
$stack = array_slice(self::$stack, 0);
array_push($stack, $description);
throw new Ex(Error::create('Test Failure: ' . join(': ', $stack)));
}
}
示例4: update
function update($setting, $value)
{
if (!Config::isValidSetting($setting)) {
return Error::create("Unrecognized setting: {$setting}");
}
$q = "delete from Config where name = '{$setting}'";
$r = @mysql_query($q);
if (!$r) {
return Error::MySQL();
}
$q = "insert into Config (name, value) values ('{$setting}', '" . db::sanitize_to_db($value) . "')";
$r = @mysql_query($q);
if (!$r) {
return Error::MySQL();
}
return true;
}
示例5: init
function init($args)
{
global $Buffer;
list($subject, $encoding, $offset) = array_pad($args, 3, null);
$type = gettype($subject);
if ($type === 'integer' || $type === 'double') {
$this->raw = str_repeat("", (int) $subject);
} else {
if ($type === 'string') {
$encoding = $encoding === null ? 'utf8' : to_string($encoding);
if ($encoding === 'hex') {
$this->raw = hex2bin($subject);
} else {
if ($encoding === 'base64') {
$this->raw = base64_decode($subject);
} else {
$this->raw = $subject;
}
}
} else {
if (_instanceof($subject, $Buffer)) {
$this->raw = $subject->raw;
} else {
if ($subject instanceof Arr) {
$this->raw = $util['arrToRaw']($subject);
} else {
throw new Ex(Error::create('Invalid parameters to construct Buffer'));
}
}
}
}
$len = strlen($this->raw);
//save an integer copy of length for performance
$this->length = $len;
$this->set('length', (double) $len);
}
示例6: array
$args = array();
foreach ($matches as $match) {
$args[] = $match[0];
}
$result[] = substr($str, $offset, $matchIndex - $offset);
//calculate multi-byte character index from match index
$mbIndex = mb_strlen(substr($str, 0, $matchIndex));
array_push($args, $mbIndex);
array_push($args, $str);
$result[] = to_string($replace->apply(null, $args));
$offset = $matchIndex + strlen($args[0]);
$count += 1;
}
if ($success === false) {
//this can happen in the case of invalid utf8 sequences
throw new Ex(Error::create('String.prototype.replace() failed'));
}
$result[] = substr($str, $offset);
return join('', $result);
} else {
$matchIndex = strpos($str, $search);
if ($matchIndex === false) {
return $str;
}
$before = substr($str, 0, $matchIndex);
$after = substr($str, $matchIndex + strlen($search));
//mb_strlen used to calculate multi-byte character index
$args = array($search, mb_strlen($before), $str);
return $before . to_string($replace->apply(null, $args)) . $after;
}
}
示例7: _store
private function _store()
{
$name = $this->name['filename'] . '_' . join('x', $this->dimensions) . '.' . $this->name['extension'];
if (!@file_put_contents(Config::get('image.cache') . $name, $this->_create())) {
return Config::get('image.cache') . $name;
} else {
Error::create('Could not save image file. Please check the cache folder exists and is writable.');
}
return false;
}
示例8: array
return $reg;
});
$RegExp->set('prototype', RegExp::$protoObject);
$RegExp->setMethods(RegExp::$classMethods, true, false, true);
return $RegExp;
}
}
RegExp::$classMethods = array();
RegExp::$protoMethods = array('exec' => function ($str) {
$self = Func::getContext();
$str = to_string($str);
//todo $offset
$offset = 0;
$result = preg_match($self->toString(true), $str, $matches, PREG_OFFSET_CAPTURE, $offset);
if ($result === false) {
throw new Ex(Error::create('Error executing Regular Expression: ' . $self->toString()));
}
if ($result === 0) {
return Object::$null;
}
$index = $matches[0][1];
$self->set('lastIndex', (double) ($index + strlen($matches[0][0])));
$arr = new Arr();
foreach ($matches as $match) {
$arr->push($match[0]);
}
$arr->set('index', (double) $index);
$arr->set('input', $str);
return $arr;
}, 'test' => function ($str) {
$self = Func::getContext();
示例9: getByUserID
function getByUserID($userID)
{
if (is_numeric($userID) && $userID > 0) {
$q = "select ID from Band_Members where user_id = {$userID}";
$r = mysql_query($q);
if ($r) {
$row = mysql_fetch_assoc($r);
return BandMember::get($row['ID']);
} else {
return Error::MySQL();
}
} else {
return Error::create("Invalid user ID.");
}
}
示例10: get
function get($userID)
{
if ($userID > 0 && is_numeric($userID)) {
$q = "select ID, firstname, lastname, birthdate, is_active, username, password, email, level from Users where ID = {$userID}";
$r = mysql_query($q);
$row = mysql_fetch_assoc($r);
if ($row['ID']) {
$uo = new User();
$uo->ID = $row['ID'];
$uo->username = $row['username'];
$uo->lastname = db::sanitize_from_db($row['lastname']);
$uo->password = $row['password'];
$uo->firstname = db::sanitize_from_db($row['firstname']);
$uo->birthdate = $row['birthdate'];
$uo->is_active = $row['is_active'];
$uo->email = $row['email'];
$uo->level = $row['level'];
return $uo;
}
}
return Error::create("Invalid user ID.");
}
示例11: set_length
function set_length($len)
{
$len = self::checkInt($len);
if ($len === null) {
throw new Ex(Error::create('Invalid array length'));
}
//when setting the length smaller than before, we need to delete elements
$oldLen = $this->length;
if ($oldLen > $len) {
for ($i = $len; $i < $oldLen; $i++) {
$this->remove($i);
}
}
$this->length = $len;
return (double) $len;
}
示例12: remove
function remove()
{
if ($this->canEdit()) {
$r = @mysql_query("delete from Band_News where ID = " . $this->ID);
if (!$r) {
return Error::MySQL();
}
} else {
return Error::create('You may not remove a post that is not yours.');
}
}
示例13: _in
/**
* @param string $key
* @param Object $obj
* @return bool
* @throws Exception
*/
function _in($key, $obj)
{
if (!$obj instanceof Object) {
throw new Ex(Error::create("Cannot use 'in' operator to search for '" . $key . "' in " . to_string($obj)));
}
return $obj->hasProperty($key);
}
示例14: __call
/**
* Similar to callMethod, we can call "internal" methods (dynamically-attached
* user functions) which are available in PHP land but not from JS
*
* @param string $name - method name
* @param array $args - arguments with which method was called
* @return mixed
* @throws Ex
*/
function __call($name, $args)
{
if (isset($this->{$name})) {
return call_user_func_array($this->{$name}, $args);
} else {
throw new Ex(Error::create('Internal method `' . $name . '` not found on ' . gettype($this)));
}
}
示例15: add
function add($postArray)
{
if (User::isAdmin()) {
$db = new db();
$name = $db->sanitize_to_db($postArray['name']);
$description = $db->sanitize_to_db($postArray['description']);
$url = $db->sanitize_to_db($postArray['url']);
$category_id = $postArray['category_id'];
if (!$name) {
$name = '(untitled link)';
}
if (strlen($url) < 6) {
return Error::create("Please enter a valid URL. A URL typically begins with \"http://\"");
}
$r = mysql_query("INSERT INTO Links (name, description, url, category_id, is_active) VALUES ('{$name}', '{$description}', '{$url}', '{$category_id}', " . DEFAULT_ACTIVE . ")");
if ($r) {
$nl = Link::get(mysql_insert_id());
return $nl;
} else {
return Error::MySQL();
}
} else {
return Error::create("Only an administrator may add links.");
}
}