本文整理汇总了PHP中Filter::with方法的典型用法代码示例。如果您正苦于以下问题:PHP Filter::with方法的具体用法?PHP Filter::with怎么用?PHP Filter::with使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Filter
的用法示例。
在下文中一共展示了Filter::with方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: method
public static function method($name, $definition = null)
{
if (is_array($name)) {
foreach ($name as $method_name => $method_definition) {
if (is_callable($method_definition)) {
$method_definition = ['validate' => $method_definition];
}
if (empty($method_definition['validate']) || !is_callable($method_definition['validate'])) {
continue;
}
$method_definition['key'] = "core.check.error.{$method_name}";
$method_definition['message'] = Filter::with("core.check.message.{$method_definition['key']}", @$method_definition['message'] ?: 'Field not valid.');
static::$methods[$method_name] = (object) $method_definition;
}
} else {
if (is_callable($definition)) {
$definition = ['validate' => $definition];
}
if (empty($definition['validate']) || !is_callable($definition['validate'])) {
return;
}
$methods['key'] = "core.check.error.{$name}";
$methods['message'] = Filter::with("core.check.message.{$methods['key']}", @$methods['message'] ?: 'Field not valid.');
static::$methods[$name] = (object) $definition;
}
}
示例2: exec
public static function exec($query, $params = [])
{
$query = Filter::with('core.sql.query', $query);
$statement = static::prepare($query);
Event::trigger('core.sql.query', $query, $params, !!$statement);
static::$last_exec_success = $statement && $statement->execute($params);
return $statement;
}
示例3: buildProjector
public static function buildProjector()
{
// Build Projector
if ($projection_fields = Filter::with(["api." . get_called_class() . ".getProjectionFields", "api.resource.getProjectionFields"], Request::get('fields'))) {
$projection_fields = preg_split('~\\s*,\\s*~', $projection_fields);
// Ensure primary key presence
array_unshift($projection_fields, static::$PKEY);
// Remove duplicate entries
$projection_fields = array_unique($projection_fields);
$projector = function ($element) use($projection_fields) {
// An unique placehodler to handle `field_get` errors.
$unique_placeholder = '§@°§___CO(' . time() . ')RE___§°@§';
// Get an array field by dot.notation
$field_get = function ($x, $path, $default = null) {
$current = (array) $x;
$p = strtok($path, '.');
while (isset($current[$p])) {
if (!($p = strtok('.'))) {
return $current;
}
$current = (array) $current[$p];
}
return $default;
};
// Set an array field pointed by dot.notation
$field_set = function (&$x, $path, $value) {
$current = $x;
$p = strtok($path, '.');
while ($p !== false) {
$p = strtok('.');
if (!isset($current[$p])) {
$current[$p] = [];
}
$current = (array) $current[$p];
}
return $current;
};
$element = (object) $element;
$obj = [];
foreach ($projection_fields as $field_path) {
if (isset($element->{$field_path})) {
$obj[$field_path] = $element->{$field_path};
} else {
if (($value = $field_get($element, $field_path, $unique_placeholder)) !== $unique_placeholder) {
var_dump($value, $element, $field_path, $unique_placeholder);
$field_set($obj, $field_path, $value);
}
}
}
return (object) $obj;
};
} else {
$projector = function ($x) {
return $x;
};
}
return $projector;
}
示例4: viaJavaScript
public static function viaJavaScript($url, $parent = false)
{
if ($link = Filter::with('core.redirect', $url)) {
Response::type('text/html');
Response::add('<script>' . ($parent ? 'parent.' : '') . 'location.href="', addslashes($link), '"</script>');
Response::send();
exit;
}
}
示例5: fromSQL
public static function fromSQL($resource, $sql, $params = [])
{
$count = SQL::value(preg_replace(['(SELECT(.+)FROM)i', '(LIMIT\\s+\\d+\\s+)i', '(OFFSET\\s+\\d+\\s+)i'], ['SELECT COUNT(1) FROM', '', ''], $sql . ' '), $params, 0);
$page = Filter::with(["api.{$resource}.page", "api.page"], max(1, Request::get('page', 1)));
$limit = Filter::with(["api.{$resource}.limit", "api.limit"], max(1, Request::get('limit', 10)));
$page = min($page, ceil($count / $limit));
$offset = max(0, $page - 1);
$sql = "{$sql} LIMIT {$limit} OFFSET {$offset}";
return static::wrap($resource, SQL::each($sql, $params), $page, $limit, $count);
}
示例6: UA
/**
* Returns the remote UserAgent
*
* @return string
*/
public static function UA()
{
return Filter::with('core.request.UA', strtolower(empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT']));
}
示例7: URI
/**
* Returns the current request URI.
*
* @param boolean $relative If true, trim the URI relative to the application index.php script.
*
* @return string
*/
public static function URI($relative = true)
{
// On some web server configurations PHP_SELF is not populated.
$self = filter_input(INPUT_SERVER, 'SCRIPT_NAME') ?: filter_input(INPUT_SERVER, 'PHP_SELF');
// Search REQUEST_URI in $_SERVER
$serv_uri = filter_input(INPUT_SERVER, 'PATH_INFO') ?: (filter_input(INPUT_SERVER, 'ORIG_PATH_INFO') ?: filter_input(INPUT_SERVER, 'REQUEST_URI'));
$uri = strtok($serv_uri, '?');
$uri = $uri == $self ? '/' : $uri;
// Add a filter here, for URL rewriting
$uri = Filter::with('core.request.URI', $uri);
$uri = rtrim($uri, '/');
if ($relative) {
$base = rtrim(dirname($self), '/');
$uri = str_replace($base, '', $uri);
}
return $uri ?: '/';
}
示例8: __toString
/**
* Render view when casted to a string
* @return string The rendered view
*/
public function __toString()
{
return Filter::with('core.view', static::$handler->render($this->options['template'], $this->options['data']));
}
示例9: run
/**
* Run one of the mapped callbacks to a passed HTTP Method.
* @param array $args The arguments to be passed to the callback
* @param string $method The HTTP Method requested.
* @return array The callback response.
*/
public function run(array $args, $method = 'get')
{
$method = strtolower($method);
$append_echoed_text = Options::get('core.route.append_echoed_text', true);
static::trigger('start', $this, $args, $method);
// Call direct befores
if ($this->befores) {
// Reverse befores order
foreach (array_reverse($this->befores) as $mw) {
static::trigger('before', $this, $mw);
Event::trigger('core.route.before', $this, $mw);
ob_start();
$mw_result = call_user_func($mw);
$raw_echoed = ob_get_clean();
if ($append_echoed_text) {
Response::add($raw_echoed);
}
if (false === $mw_result) {
return [''];
} else {
Response::add($mw_result);
}
}
}
$callback = is_array($this->callback) && isset($this->callback[$method]) ? $this->callback[$method] : $this->callback;
if (is_callable($callback) || is_a($callback, "View")) {
Response::type(Options::get('core.route.response_default_type', Response::TYPE_HTML));
ob_start();
if (is_a($callback, "View")) {
// Get the rendered view
$view_results = (string) $callback;
} else {
$view_results = call_user_func_array($callback, $args);
}
$raw_echoed = ob_get_clean();
if ($append_echoed_text) {
Response::add($raw_echoed);
}
Response::add($view_results);
}
// Apply afters
if ($this->afters) {
foreach ($this->afters as $mw) {
static::trigger('after', $this, $mw);
Event::trigger('core.route.after', $this, $mw);
ob_start();
$mw_result = call_user_func($mw);
$raw_echoed = ob_get_clean();
if ($append_echoed_text) {
Response::add($raw_echoed);
}
if (false === $mw_result) {
return [''];
} else {
Response::add($mw_result);
}
}
}
static::trigger('end', $this, $args, $method);
Event::trigger('core.route.end', $this);
return [Filter::with('core.route.response', Response::body())];
}
示例10: body
public static function body($setBody = null)
{
if ($setBody) {
static::$payload = [$setBody];
}
return Filter::with('core.response.body', is_array(static::$payload) ? implode('', static::$payload) : static::$payload);
}
示例11: build
public function build()
{
return \Filter::with('core.email.source', $this->head() . "\r\n" . $this->body());
}
示例12: exec
public function exec($query, $params = [], $pdo_params = [])
{
if (!$this->connection()) {
return false;
}
if (false == is_array($params)) {
$params = (array) $params;
}
$query = Filter::with('core.sql.query', $query);
if ($statement = $this->prepare($query, $pdo_params)) {
SQL::trigger('query', $query, $params, (bool) $statement);
Event::trigger('core.sql.query', $query, $params, (bool) $statement);
foreach ($params as $key => $val) {
$type = PDO::PARAM_STR;
if (is_bool($val)) {
$type = PDO::PARAM_BOOL;
} elseif (is_null($val)) {
$type = PDO::PARAM_NULL;
} elseif (is_int($val)) {
$type = PDO::PARAM_INT;
}
// bindValue need a 1-based numeric parameter
$statement->bindValue(is_numeric($key) ? $key + 1 : ':' . $key, $val, $type);
}
} else {
$error = $this->connection['pdo']->errorInfo();
SQL::trigger('error', $error[2], $query, $params, $error);
Event::trigger('core.sql.error', $error[2], $query, $params, $error);
return false;
}
$this->last_exec_success = $statement && $statement->execute();
return $statement;
}