sentence1 stringlengths 52 3.87M | sentence2 stringlengths 1 47.2k | label stringclasses 1
value |
|---|---|---|
protected function normalizeAbsoluteWindowsPath(
AbsoluteWindowsPathInterface $path
) {
return $this->factory()->createFromDriveAndAtoms(
$this->normalizeAbsolutePathAtoms($path->atoms()),
$this->normalizeDriveSpecifier($path->drive()),
true,
false,
... | Normalize an absolute Windows path.
@param AbsoluteWindowsPathInterface $path The path to normalize.
@return AbsoluteWindowsPathInterface The normalized path. | entailment |
protected function normalizeRelativeWindowsPath(
RelativeWindowsPathInterface $path
) {
if ($path->isAnchored()) {
$atoms = $this->normalizeAbsolutePathAtoms($path->atoms());
} else {
$atoms = $this->normalizeRelativePathAtoms($path->atoms());
}
retur... | Normalize a relative Windows path.
@param RelativeWindowsPathInterface $path The path to normalize.
@return RelativeWindowsPathInterface The normalized path. | entailment |
public function execute(array $args, array $options = [])
{
$this->bootstrap($args, $options);
$seedSet = isset($options['seed']) ? $options['seed'] : $options['s'];
$start = microtime(true);
if (empty($seedSet)) {
// run all the seed(ers)
$this->getManager... | 执行 seeders.
@param array $args 参数
@param array $options 选项 | entailment |
public static function fromDriveAndAtoms(
$drive,
$atoms,
$hasTrailingSeparator = null
) {
return static::factory()->createFromDriveAndAtoms(
$atoms,
$drive,
true,
false,
$hasTrailingSeparator
);
} | Creates a new absolute Windows path from a set of path atoms and a drive
specifier.
@param string $drive The drive specifier.
@param mixed<string> $atoms The path atoms.
@param boolean|null $hasTrailingSeparator True if the path has a trailing separator.
@return AbsoluteWindowsPa... | entailment |
public function joinDrive($drive)
{
if (null === $drive) {
return $this->createPathFromDriveAndAtoms(
$this->atoms(),
null,
false,
true,
false
);
}
return $this->createPathFromDriveAndAto... | Joins the supplied drive specifier to this path.
@return string|null $drive The drive specifier to use, or null to remove the drive specifier.
@return WindowsPathInterface A new path instance with the supplied drive specifier joined to this path. | entailment |
public function isParentOf(AbsolutePathInterface $path)
{
if (!$this->matchesDriveOrNull($this->pathDriveSpecifier($path))) {
return false;
}
return parent::isParentOf($path);
} | Determine if this path is the direct parent of the supplied path.
@param AbsolutePathInterface $path The child path.
@return boolean True if this path is the direct parent of the supplied path. | entailment |
public function isAncestorOf(AbsolutePathInterface $path)
{
if (!$this->matchesDriveOrNull($this->pathDriveSpecifier($path))) {
return false;
}
return parent::isAncestorOf($path);
} | Determine if this path is an ancestor of the supplied path.
@param AbsolutePathInterface $path The child path.
@return boolean True if this path is an ancestor of the supplied path. | entailment |
public function relativeTo(AbsolutePathInterface $path)
{
if (!$this->matchesDriveOrNull($this->pathDriveSpecifier($path))) {
return $this->toRelative();
}
return parent::relativeTo($path);
} | Determine the shortest path from the supplied path to this path.
For example, given path A equal to '/foo/bar', and path B equal to
'/foo/baz', A relative to B would be '../bar'.
@param AbsolutePathInterface $path The path that the generated path will be relative to.
@return RelativePathInterface A relative path fro... | entailment |
public function string()
{
return
$this->drive() .
':' .
static::ATOM_SEPARATOR .
implode(static::ATOM_SEPARATOR, $this->atoms()) .
($this->hasTrailingSeparator() ? static::ATOM_SEPARATOR : '');
} | Generate a string representation of this path.
@return string A string representation of this path. | entailment |
public function toRelative()
{
return $this->createPathFromDriveAndAtoms(
$this->atoms(),
$this->drive(),
false,
false,
false
);
} | Get a relative version of this path.
If this path is absolute, a new relative path with equivalent atoms will
be returned. Otherwise, this path will be retured unaltered.
@return RelativePathInterface A relative version of this path.
@throws EmptyPathException If this path has no atoms. | entailment |
protected function createPath(
$atoms,
$isAbsolute,
$hasTrailingSeparator = null
) {
if ($isAbsolute) {
return $this->createPathFromDriveAndAtoms(
$atoms,
$this->drive(),
true,
false,
$hasTrai... | Creates a new path instance of the most appropriate type.
This method is called internally every time a new path instance is
created as part of another method call. It can be overridden in child
classes to change which classes are used when creating new path
instances.
@param mixed<string> $atoms The p... | entailment |
public static function levenshteinDistance($string1, $string2, $costReplace = 1, $encoding = 'UTF-8')
{
$mbStringToArrayFunc = function ($string) use ($encoding)
{
$arrayResult = [];
while ($iLen = mb_strlen($string, $encoding)) {
array_push($arrayResult, mb_... | 计算两个字符串间的levenshteinDistance
@param string $string1
@param string $string2
@param int $costReplace 定义替换次数
@param string $encoding
@return mixed | entailment |
public static function substrCn($string, $start = 0, $length, $charset = "utf-8", $suffix = '')
{
if (function_exists("mb_substr")){
return mb_substr($string, $start, $length, $charset).$suffix;
} elseif (function_exists('iconv_substr')) {
return iconv_substr($string, $start,... | 字符串截取,支持中文和其他编码
@param string $string 需要转换的字符串
@param int $start 开始位置
@param int $length 截取长度
@param string $charset 编码格式
@param string $suffix 截断字符串后缀
@return string | entailment |
public static function randString($len = 6, $type = 0, $addChars = '')
{
$string = '';
switch ($type) {
case 0:
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.$addChars;
break;
case 1:
$chars = str_repeat('01234... | 产生随机字串 //中文 需要php_mbstring扩展支持
默认长度6位 字母和数字混合 支持中文
@param int $len 长度
@param int $type 字串类型 0 字母 1 数字 其它 混合
@param string $addChars 自定义一部分字符
@return string | entailment |
public function set($key, $value, $expire = 0)
{
($expire == 0) && $expire = null;
return apc_store($this->conf['prefix'] . $key, $value, $expire);
} | 存储对象
@param mixed $key 要缓存的数据的key
@param mixed $value 要缓存的值,除resource类型外的数据类型
@param int $expire 缓存的有效时间 0为不过期
@return bool | entailment |
public function update($key, $value, $expire = 0)
{
$arr = $this->get($key);
if (!empty($arr)) {
$arr = array_merge($arr, $value);
return $this->set($key, $arr, $expire);
}
return 0;
} | 更新对象
@param mixed $key 要更新的缓存的数据的key
@param mixed $value 要更新的要缓存的值,除resource类型外的数据类型
@param int $expire 缓存的有效时间 0为不过期
@return bool|int | entailment |
public function increment($key, $val = 1)
{
return apc_inc($this->conf['prefix'] . $key, abs(intval($val)));
} | 自增
@param mixed $key 要自增的缓存的数据的key
@param int $val 自增的进步值,默认为1
@return bool | entailment |
public function decrement($key, $val = 1)
{
return apc_dec($this->conf['prefix'] . $key, abs(intval($val)));
} | 自减
@param mixed $key 要自减的缓存的数据的key
@param int $val 自减的进步值,默认为1
@return bool | entailment |
public function showFeedbackFormAction(Request $request, ContentView $view)
{
// Creating a form using Symfony's form component
$feedback = new Feedback();
$form = $this->createForm($this->get('ezdemo.form.type.feedback'), $feedback);
if ($request->isMethod('POST')) {
$f... | Displays the feedback form, and processes posted data.
The signature of this method follows the one from the default view controller, and adds the Request, since
we use to handle form data.
@param \Symfony\Component\HttpFoundation\Request $request
@param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view
@return Vie... | entailment |
private static function parseInputToString($params)
{
return is_array($params) ? array_map(function ($item) {
return trim(htmlspecialchars($item, ENT_QUOTES, 'UTF-8'));
}, $params) : trim(htmlspecialchars($params, ENT_QUOTES, 'UTF-8'));
} | 统一的处理输入-输出为字符串
@param array|string $params
@return array|string | entailment |
private static function parseInputToInt($params)
{
return is_array($params) ? array_map(function ($item) {
return intval($item);
}, $params) : intval($params);
} | 统一的处理输入-输出为整型
@param array|string $params
@return array|int | entailment |
private static function parseInputToBool($params)
{
return is_array($params) ? array_map(function ($item) {
return ((bool)$item);
}, $params) : ((bool)$params);
} | 统一的处理输入-输出为布尔型
@param array|string $params
@return array|bool | entailment |
private static function getReferParams($name)
{
static $params = null;
if (is_null($params)) {
if (isset($_SERVER['HTTP_REFERER'])) {
$args = parse_url($_SERVER['HTTP_REFERER']);
parse_str($args['query'], $params);
}
}
return i... | 获取解析后的Refer的参数
@param string $name 参数的key
@return mixed | entailment |
public static function getString($name, $default = null)
{
if (isset($_GET[$name]) && $_GET[$name] !== '') return self::parseInputToString($_GET[$name]);
return $default;
} | 获取get string数据
@param string $name 要获取的变量
@param null $default 未获取到$_GET值时返回的默认值
@return string|null|array | entailment |
public static function postString($name, $default = null)
{
if (isset($_POST[$name]) && $_POST[$name] !== '') return self::parseInputToString($_POST[$name]);
return $default;
} | 获取post string数据
@param string $name 要获取的变量
@param null $default 未获取到$_POST值时返回的默认值
@return string|null|array | entailment |
public static function requestString($name, $default = null)
{
if (isset($_REQUEST[$name]) && $_REQUEST[$name] !== '') return self::parseInputToString($_REQUEST[$name]);
return $default;
} | 获取$_REQUEST string数据
@param string $name 要获取的变量
@param null $default 未获取到$_REQUEST值时返回的默认值
@return null|string|array | entailment |
public static function referString($name, $default = null)
{
$res = self::getReferParams($name);
if (!is_null($res)) return self::parseInputToString($res);
return $default;
} | 获取Refer string数据
@param string $name 要获取的变量
@param null $default 未获取到Refer值时返回的默认值
@return null|string|array | entailment |
public static function getInt($name, $default = null)
{
if (isset($_GET[$name]) && $_GET[$name] !== '') return self::parseInputToInt($_GET[$name]);
return (is_null($default) ? null : intval($default));
} | 获取get int数据
@param string $name 要获取的变量
@param null $default 未获取到$_GET值时返回的默认值
@return int|null|array | entailment |
public static function postInt($name, $default = null)
{
if (isset($_POST[$name]) && $_POST[$name] !== '') return self::parseInputToInt($_POST[$name]);
return (is_null($default) ? null : intval($default));
} | 获取post int数据
@param string $name 要获取的变量
@param null $default 未获取到$_POST值时返回的默认值
@return int|null|array | entailment |
public static function requestInt($name, $default = null)
{
if (isset($_REQUEST[$name]) && $_REQUEST[$name] !== '') return self::parseInputToInt($_REQUEST[$name]);
return (is_null($default) ? null : intval($default));
} | 获取$_REQUEST int数据
@param string $name 要获取的变量
@param null $default 未获取到$_REQUEST值时返回的默认值
@return null|int|array | entailment |
public static function referInt($name, $default = null)
{
$res = self::getReferParams($name);
if (!is_null($res)) return self::parseInputToInt($res);
return (is_null($default) ? null : intval($default));
} | 获取Refer int数据
@param string $name 要获取的变量
@param null $default 未获取到Refer值时返回的默认值
@return null|string|array | entailment |
public static function getBool($name, $default = null)
{
if (isset($_GET[$name]) && $_GET[$name] !== '') return self::parseInputToBool($_GET[$name]);
return (is_null($default) ? null : ((bool)$default));
} | 获取get bool数据
@param string $name 要获取的变量
@param null $default 未获取到$_GET值时返回的默认值
@return bool|null|array | entailment |
public static function postBool($name, $default = null)
{
if (isset($_POST[$name]) && $_POST[$name] !== '') return self::parseInputToBool($_POST[$name]);
return (is_null($default) ? null : ((bool)$default));
} | 获取post bool数据
@param string $name 要获取的变量
@param null $default 未获取到$_POST值时返回的默认值
@return bool|null|array | entailment |
public static function requestBool($name, $default = null)
{
if (isset($_REQUEST[$name]) && $_REQUEST[$name] !== '') return self::parseInputToBool($_REQUEST[$name]);
return (is_null($default) ? null : ((bool)$default));
} | 获取$_REQUEST bool数据
@param string $name 要获取的变量
@param null $default 未获取到$_REQUEST值时返回的默认值
@return null|bool|array | entailment |
public static function referBool($name, $default = null)
{
$res = self::getReferParams($name);
if (!is_null($res)) return self::parseInputToBool($res);
return (is_null($default) ? null : ((bool)$default));
} | 获取Refer bool数据
@param string $name 要获取的变量
@param null $default 未获取到Refer值时返回的默认值
@return null|string|array | entailment |
public static function get($name)
{
if (!self::isExist($name)) return false;
$value = $_COOKIE[Config::get('cookie_prefix') . $name];
return Encry::decrypt($value);
} | 获取某个Cookie值
@param string $name 要获取的cookie名称
@return bool|mixed | entailment |
public static function set($name, $value, $expire = 0, $path = '', $domain = '')
{
empty($expire) && $expire = Config::get('cookie_expire');
empty($path) && $path = Config::get('cookie_path');
empty($domain) && $domain = Config::get('cookie_domain');
$expire = empty($expire) ? 0 : C... | 设置某个Cookie值
@param string $name 要设置的cookie的名称
@param mixed $value 要设置的值
@param int $expire 过期时间
@param string $path path
@param string $domain domain
@return void | entailment |
public static function delete($name, $path = '', $domain = '')
{
self::set($name, '', -3600, $path, $domain);
unset($_COOKIE[Config::get('cookie_prefix') . $name]);
} | 删除某个Cookie值
@param string $name 要删除的cookie的名称
@param string $path path
@param string $domain domain
@return void | entailment |
public function itHasATextSpanLinkedTo($text, $link)
{
$this->assertSession()->pageTextContains($text);
Assertion::assertCount(
1,
$this->getXpath()->findXpath(sprintf('//a[@href="%s"]/span[text()="%s"]', $link, $text))
);
} | Tests that the page contains a specific link with a specific text (the text must be within a span).
@Then It has the text :text in a span linked to :link
@Then I see the text :text in a span linked to :link | entailment |
public function breadcrumbHasTheFollowingLinks(TableNode $table)
{
foreach ($table->getTable() as $breadcrumbItem) {
$text = $breadcrumbItem[0];
$url = $breadcrumbItem[1];
// this is not a link (the current page)
if ($url === 'null') {
$query ... | Tests if a link is present in the breadcrumbs.
@Then the breadcrumb has the following links: | entailment |
public function iShouldSeeAVailidThumbnailForImageWithAlternativeText($imageAlternativeText)
{
$image = $this->getXpath()->findXpath("//img[contains(@alt, '" . $imageAlternativeText . "')]");
if (count($image) == 0) {
throw new \Exception(sprintf('Image with an alternative text `%s` was... | Test if image is present on page and is downloadable (`img` tag must contain `alt` attribute).
@Then I (should) see a valid thumbnail for image with alternative text :imageAlternativeText | entailment |
public function bootstrap(array $args, array $options = [])
{
if (false === class_exists('\Phinx\Config\Config')) {
throw new \RuntimeException('please use `composer require linhecheng/cmlphp-ext-phinx` cmd to install phinx.');
}
if (!$this->getConfig()) {
$this->loa... | Bootstrap Phinx.
@param array $args
@param array $options | entailment |
protected function loadConfig($options)
{
if (isset($options['env']) && !in_array($options['env'], ['cli', 'product', 'development'])) {
throw new \InvalidArgumentException('option --env\'s value must be [cli, product, development]');
}
$env = 'development';
isset($option... | Parse the config file and load it into the config object
@param array $options 选项
@throws \InvalidArgumentException
@return void | entailment |
protected function loadManager($args, $options)
{
if (null === $this->getManager()) {
$manager = new Manager($this->getConfig(), $args, $options);
$this->setManager($manager);
}
} | Load the migrations manager and inject the config
@param array $args
@param array $options | entailment |
public function getTables()
{
$this->currentQueryIsMaster = false;
$stmt = $this->prepare('SHOW TABLES;', $this->rlink);
$this->execute($stmt);
$tables = [];
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$tables[] = $row['Tables_in_' . $this->conf['master']['d... | 获取当前db所有表名
@return array | entailment |
public function getAllTableStatus()
{
$this->currentQueryIsMaster = false;
$stmt = $this->prepare('SHOW TABLE STATUS FROM ' . $this->conf['master']['dbname'], $this->rlink);
$this->execute($stmt);
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$return = [];
foreach ($res ... | 获取当前数据库中所有表的信息
@return array | entailment |
public function getDbFields($table, $tablePrefix = null, $filter = 0)
{
static $dbFieldCache = [];
is_null($tablePrefix) && $tablePrefix = $this->tablePrefix;
if ($filter == 1 && Cml::$debug) return '*'; //debug模式时直接返回*
$table = strtolower($tablePrefix . $table);
$info = fa... | 获取表字段
@param string $table 表名
@param mixed $tablePrefix 表前缀,不传则获取配置中配置的前缀
@param int $filter 0 获取表字段详细信息数组 1获取字段以,号相隔组成的字符串
@return mixed | entailment |
public function get($key, $and = true, $useMaster = false, $tablePrefix = null)
{
if (is_string($useMaster) && is_null($tablePrefix)) {
$tablePrefix = $useMaster;
$useMaster = false;
}
is_null($tablePrefix) && $tablePrefix = $this->tablePrefix;
list($tableNam... | 根据key取出数据
@param string $key get('user-uid-123');
@param bool $and 多个条件之间是否为and true为and false为or
@param bool|string $useMaster 是否使用主库 默认读取从库 此选项为字符串时为表前缀$tablePrefix
@param null|string $tablePrefix 表前缀
@return array | entailment |
public function set($table, $data, $tablePrefix = null)
{
is_null($tablePrefix) && $tablePrefix = $this->tablePrefix;
$tableName = $tablePrefix . $table;
if (is_array($data)) {
$s = $this->arrToCondition($data);
$this->currentQueryIsMaster = true;
$stmt = ... | 新增 一条数据
@param string $table 表名
@param array $data eg: ['username'=>'admin', 'email'=>'linhechengbush@live.com']
@param mixed $tablePrefix 表前缀 不传则获取配置中配置的前缀
@return bool|int | entailment |
public function setMulti($table, $field, $data, $tablePrefix = null, $openTransAction = true)
{
is_null($tablePrefix) && $tablePrefix = $this->tablePrefix;
$tableName = $tablePrefix . $table;
if (is_array($data) && is_array($field)) {
$field = array_flip(array_values($field));
... | 新增多条数据
@param string $table 表名
@param array $field 字段 eg: ['title', 'msg', 'status', 'ctime‘]
@param array $data eg: 多条数据的值 [['标题1', '内容1', 1, '2017'], ['标题2', '内容2', 1, '2017']]
@param mixed $tablePrefix 表前缀 不传则获取配置中配置的前缀
@param bool $openTransAction 是否开启事务 默认开启
@throws \InvalidArgumentException
@return bool|array | entailment |
public function update($key, $data = null, $and = true, $tablePrefix = null)
{
is_null($tablePrefix) && $tablePrefix = $this->tablePrefix;
$tableName = $condition = '';
if (is_array($data)) {
list($tableName, $condition) = $this->parseKey($key, $and, true, true);
} else ... | 根据key更新一条数据
@param string|array $key eg: 'user'(表名)、'user-uid-$uid'(表名+条件) 、['xx'=>'xx' ...](即:$data数组如果条件是通用whereXX()、表名是通过table()设定。这边可以直接传$data的数组)
@param array | null $data eg: ['username'=>'admin', 'email'=>'linhechengbush@live.com'] 可以直接通过$key参数传递
@param bool $and 多个条件之间是否为and true为and false为or
@param mixed $ta... | entailment |
public function delete($key = '', $and = true, $tablePrefix = null)
{
is_null($tablePrefix) && $tablePrefix = $this->tablePrefix;
$tableName = $condition = '';
empty($key) || list($tableName, $condition) = $this->parseKey($key, $and, true, true);
if (empty($tableName)) {
... | 根据key值删除数据
@param string|int $key eg: 'user'(表名,即条件通过where()传递)、'user-uid-$uid'(表名+条件)、啥也不传(即通过table传表名)
@param bool $and 多个条件之间是否为and true为and false为or
@param mixed $tablePrefix 表前缀 不传则获取配置中配置的前缀
@return boolean | entailment |
public function truncate($tableName)
{
$tableName = $this->tablePrefix . $tableName;
$this->currentQueryIsMaster = true;
$stmt = $this->prepare("TRUNCATE {$tableName}");
$this->setCacheVer($tableName);
return $stmt->execute();//不存在会报错,但无关紧要
} | 根据表名删除数据 这个操作太危险慎用。不过一般情况程序也没这个权限
@param string $tableName 要清空的表名
@return bool | entailment |
public function count($field = '*', $isMulti = false, $useMaster = false)
{
return $this->aggregation($field, $isMulti, $useMaster, 'COUNT');
} | 获取 COUNT(字段名或*) 的结果
@param string $field 要统计的字段名
@param bool|string $isMulti 结果集是否为多条 默认只有一条。传字符串时相当于执行了 groupBy($isMulti)
@param bool|string $useMaster 是否使用主库 默认读取从库
@return mixed | entailment |
public function max($field = 'id', $isMulti = false, $useMaster = false)
{
return $this->aggregation($field, $isMulti, $useMaster, 'MAX');
} | 获取 MAX(字段名) 的结果
@param string $field 要统计的字段名
@param bool|string $isMulti 结果集是否为多条 默认只有一条。传字符串时相当于执行了 groupBy($isMulti)
@param bool|string $useMaster 是否使用主库 默认读取从库
@return mixed | entailment |
private function aggregation($field, $isMulti = false, $useMaster = false, $operation = 'COUNT')
{
is_string($isMulti) && $this->groupBy($isMulti)->columns($isMulti);
$count = $this->columns(["{$operation}({$field})" => '__res__'])->select(null, null, $useMaster);
if ($isMulti) {
... | 获取max(字段名)的结果
@param string $field 要统计的字段名
@param bool|string $isMulti 结果集是否为多条 默认只有一条。传字符串时相当于执行了 groupBy($isMulti)
@param bool|string $useMaster 是否使用主库 默认读取从库
@param string $operation 聚合操作
@return mixed | entailment |
private function tableFactory($isRead = true)
{
$table = $operator = '';
$cacheKey = [];
foreach ($this->table as $key => $val) {
$realTable = $this->getRealTableName($key);
$cacheKey[] = $isRead ? $this->getCacheVer($realTable) : $realTable;
$on = null;
... | table组装工厂
@param bool $isRead 是否为读操作
@return array | entailment |
public function forceIndex($table, $index, $tablePrefix = null)
{
is_null($tablePrefix) && $tablePrefix = $this->tablePrefix;
$this->forceIndex[$tablePrefix . $table] = $index;
return $this;
} | 强制使用索引
@param string $table 要强制索引的表名(不带前缀)
@param string $index 要强制使用的索引
@param string $tablePrefix 表前缀 不传则获取配置中配置的前缀
@return $this | entailment |
public function buildSql($offset = null, $limit = null, $isSelect = false)
{
is_null($offset) || $this->limit($offset, $limit);
$this->sql['columns'] == '' && ($this->sql['columns'] = '*');
$columns = $this->sql['columns'];
$tableAndCacheKey = $this->tableFactory();
empty... | 构建sql
@param null $offset 偏移量
@param null $limit 返回的条数
@param bool $isSelect 是否为select调用, 是则不重置查询参数并返回cacheKey/否则直接返回sql并重置查询参数
@return string|array | entailment |
public function select($offset = null, $limit = null, $useMaster = false)
{
list($sql, $cacheKey) = $this->buildSql($offset, $limit, true);
if ($this->openCache && $this->currentQueryUseCache) {
$cacheKey = md5($sql . json_encode($this->bindParams)) . implode('', $cacheKey);
... | 获取多条数据
@param int $offset 偏移量
@param int $limit 返回的条数
@param bool $useMaster 是否使用主库 默认读取从库
@return array | entailment |
public function insertId($link = null)
{
is_null($link) && $link = $this->wlink;
return $link->lastInsertId();
} | 获取上一INSERT的主键值
@param \PDO $link
@return int | entailment |
public function connect($host, $username, $password, $dbName, $charset = 'utf8', $engine = '', $pConnect = false)
{
$link = '';
try {
$host = explode(':', $host);
if (substr($host[0], 0, 11) === 'unix_socket') {
$dsn = "mysql:dbname={$dbName};unix_socket=" . s... | Db连接
@param string $host 数据库host
@param string $username 数据库用户名
@param string $password 数据库密码
@param string $dbName 数据库名
@param string $charset 字符集
@param string $engine 引擎
@param bool $pConnect 是否为长连接
@return mixed | entailment |
public function increment($key, $val = 1, $field = null, $tablePrefix = null)
{
list($tableName, $condition) = $this->parseKey($key, true);
if (is_null($field) || empty($tableName) || empty($condition)) {
$this->clearBindParams();
return false;
}
$val = abs(in... | 指定字段的值+1
@param string $key 操作的key user-id-1
@param int $val
@param string $field 要改变的字段
@param mixed $tablePrefix 表前缀 不传则获取配置中配置的前缀
@return bool | entailment |
public function prepare($sql, $link = null, $resetParams = true)
{
$resetParams && $this->reset();
is_null($link) && $link = $this->currentQueryIsMaster ? $this->wlink : $this->rlink;
$sqlParams = [];
foreach ($this->bindParams as $key => $val) {
$sqlParams[] = ':param' ... | 预处理语句
@param string $sql 要预处理的sql语句
@param \PDO $link
@param bool $resetParams
@return \PDOStatement | entailment |
public function execute($stmt, $clearBindParams = true)
{
foreach ($this->bindParams as $key => $val) {
is_int($val) ? $stmt->bindValue(':param' . $key, $val, \PDO::PARAM_INT) : $stmt->bindValue(':param' . $key, $val, \PDO::PARAM_STR);
}
//empty($param) && $param = $this->bindPa... | 执行预处理语句
@param object $stmt PDOStatement
@param bool $clearBindParams
@return bool | entailment |
private function debugLogSql($type = Debug::SQL_TYPE_NORMAL, $other = 0)
{
Debug::addSqlInfo($this->buildDebugSql(), $type, $other);
} | Debug模式记录查询语句显示到控制台
@param int $type
@param int $other $other type = SQL_TYPE_SLOW时带上执行时间 | entailment |
private function buildDebugSql()
{
$bindParams = $this->bindParams;
foreach ($bindParams as $key => $val) {
$bindParams[$key] = str_replace('\\\\', '\\', addslashes($val));
}
return vsprintf(str_replace('%s', "'%s'", $this->currentSql), $bindParams);
} | 组装sql用于DEBUG
@return string | entailment |
public function close()
{
if (!Config::get('session_user')) {
//开启会话自定义保存时,不关闭防止会话保存失败
$this->wlink = null;
unset($this->wlink);
}
$this->rlink = null;
unset($this->rlink);
} | 关闭连接 | entailment |
public function version($link = null)
{
is_null($link) && $link = $this->wlink;
return $link->getAttribute(\PDO::ATTR_SERVER_VERSION);
} | 获取mysql 版本
@param \PDO $link
@return string | entailment |
public function rollBack($rollBackTo = false)
{
if ($rollBackTo === false) {
return $this->wlink->rollBack();
} else {
return $this->wlink->exec("ROLLBACK TO {$rollBackTo}");
}
} | 回滚事务
@param bool $rollBackTo 是否为还原到某个保存点
@return bool | entailment |
public function callProcedure($procedureName = '', $bindParams = [], $isSelect = true)
{
$this->bindParams = $bindParams;
$this->currentQueryIsMaster = true;
$stmt = $this->prepare("exec {$procedureName}", $this->wlink);
$this->execute($stmt);
if ($isSelect) {
ret... | 调用存储过程
@param string $procedureName 要调用的存储过程名称
@param array $bindParams 绑定的参数
@param bool|true $isSelect 是否为返回数据集的语句
@return array|int | entailment |
public function handle()
{
// This is the model that all your others will extend
$baseModel = '\Illuminate\Database\Eloquent\Model'; // default laravel 5
// This is the path where we will store your new models
$path = storage_path('models');
if ($this->option('output')) {
... | Execute the console command.
@return mixed | entailment |
public function lPush($name, $data)
{
return $this->getDriver()->lPush($name, $this->encodeDate($data));
} | 从列表头入队
@param string $name 要从列表头入队的队列的名称
@param mixed $data 要入队的数据
@return mixed | entailment |
public function lPop($name)
{
$data = $this->getDriver()->lPop($name);
$data && $data = $this->decodeDate($data);
return $data;
} | 从列表头出队
@param string $name 要从列表头出队的队列的名称
@return mixed | entailment |
public function rPush($name, $data)
{
return $this->getDriver()->rPush($name, $this->encodeDate($data));
} | 从列表尾入队
@param string $name 要从列表尾入队的队列的名称
@param mixed $data 要入队的数据
@return mixed | entailment |
public function rPop($name)
{
$data = $this->getDriver()->rPop($name);
$data && $data = $this->decodeDate($data);
return $data;
} | 从列表尾出队
@param string $name 要从列表尾出队的队列的名称
@return mixed | entailment |
public function fromArray($data)
{
foreach ($data as $param => $value) {
if (!method_exists($this, 'set' . ucfirst($param))) {
continue;
}
$this->{'set' . ucfirst($param)}($value);
}
return $this;
} | Converts array to response model
@param array $data
@return $this | entailment |
public function toArray($method)
{
$vars = get_object_vars($this);
$className = explode('\\', get_called_class());
return $vars + array('model' => end($className));
} | Convert object to an associative array
@param string $method The API method called
@return array | entailment |
private function initBaseDir($templateFile)
{
$baseDir = Cml::getContainer()->make('cml_route')->getAppName();
$baseDir && $baseDir .= '/';
$baseDir .= Cml::getApplicationDir('app_view_path_name') . (Config::get('html_theme') != '' ? DIRECTORY_SEPARATOR . Config::get('html_theme') : '');
... | 初始化目录
@param string $templateFile 模板文件名
@return string | entailment |
public function display($templateFile = '')
{
$options = $this->initBaseDir($templateFile);
$compiler = new BladeCompiler($options['cacheDir'], $options['layoutCacheRootPath']);
$compiler->directive('datetime', function ($timestamp) {
return preg_replace('/\(\s*?(\S+?)\s*?\|(.*?... | 抽象display
@param string $templateFile 模板文件
@return mixed | entailment |
public function execute(array $args, array $options = [])
{
if (!isset($args[0])) {
throw new \InvalidArgumentException('arg action must be input');
}
$action = explode('::', $args[0]);
if (!class_exists($action[0])) {
throw new \InvalidArgumentException('acti... | 添加一个后台任务
@param array $args 传递给命令的参数
@param array $options 传递给命令的选项
@throws \InvalidArgumentException | entailment |
public static function fromString($path)
{
$pathObject = static::factory()->create($path);
if (!$pathObject instanceof AbsolutePathInterface) {
throw new Exception\NonAbsolutePathException($pathObject);
}
return $pathObject;
} | Creates a new absolute path from its string representation.
@param string $path The string representation of the absolute path.
@return AbsolutePathInterface The newly created absolute path.
@throws Exception\NonAbsolutePathException If the supplied string represents a non-absolute path. | entailment |
public function isParentOf(AbsolutePathInterface $path)
{
return $path->hasAtoms() &&
$this->normalize()->atoms() ===
$path->parent()->normalize()->atoms();
} | Determine if this path is the direct parent of the supplied path.
@param AbsolutePathInterface $path The child path.
@return boolean True if this path is the direct parent of the supplied path. | entailment |
public function isAncestorOf(AbsolutePathInterface $path)
{
$parentAtoms = $this->normalize()->atoms();
return $parentAtoms === array_slice(
$path->normalize()->atoms(),
0,
count($parentAtoms)
);
} | Determine if this path is an ancestor of the supplied path.
@param AbsolutePathInterface $path The child path.
@return boolean True if this path is an ancestor of the supplied path. | entailment |
public function relativeTo(AbsolutePathInterface $path)
{
$parentAtoms = $path->normalize()->atoms();
$childAtoms = $this->normalize()->atoms();
if ($childAtoms === $parentAtoms) {
$diffAtoms = array(static::SELF_ATOM);
} else {
$diffAtoms = array_diff_assoc(... | Determine the shortest path from the supplied path to this path.
For example, given path A equal to '/foo/bar', and path B equal to
'/foo/baz', A relative to B would be '../bar'.
@param AbsolutePathInterface $path The path that the generated path will be relative to.
@return RelativePathInterface A relative path fro... | entailment |
public function searchForPaginatedContent($searchText, $currentPage, $languages)
{
// Generating query
$query = new Query();
$query->query = new Criterion\FullText($searchText);
$query->filter = new Criterion\LogicalAnd(
array(
new Criterion\Visibility(Cri... | Search for content for a given $searchText and returns a pager.
@param string $searchText to be looked up
@param int $currentPage to be displayed
@param array $languages to include in the search
@return \Pagerfanta\Pagerfanta | entailment |
public function buildListFromSearchResult(SearchResult $searchResult)
{
$list = array();
foreach ($searchResult->searchHits as $searchHit) {
$list[$searchHit->valueObject->id] = $searchHit->valueObject;
}
return $list;
} | Builds a list from $searchResult.
Returned array consists of a hash of objects, indexed by their ID.
@param \eZ\Publish\API\Repository\Values\Content\Search\SearchResult $searchResult
@return array | entailment |
public static function parsePathInfo()
{
$urlModel = Config::get('url_model');
$pathInfo = self::$pathInfo;
if (empty($pathInfo)) {
$isCli = Request::isCli(); //是否为命令行访问
if ($isCli) {
isset($_SERVER['argv'][1]) && $pathInfo = explode('/', $_SERVER['ar... | 解析url获取pathinfo
@return void | entailment |
public static function loadAppRoute($app = 'web', $inConfigDir = true)
{
static $loaded = [];
if (isset($loaded[$app])) {
return;
}
$path = $app . DIRECTORY_SEPARATOR . ($inConfigDir ? Cml::getApplicationDir('app_config_path_name') . DIRECTORY_SEPARATOR : '') . 'route.php... | 载入应用单独的路由
@param string $app 应用名称
@param string $inConfigDir 配置文件是否在Config目录中 | entailment |
public static function executeCallableRoute(callable $call, $route = '')
{
call_user_func($call);
Cml::$debug && Debug::addTipInfo(Lang::get('_CML_EXECUTION_ROUTE_IS_', "callable route:{{$route}}", Config::get('url_model')));
Cml::cmlStop();
} | 执行闭包路由
@param callable $call 闭包
@param string $route 路由string | entailment |
public function getAppName()
{
if (!self::$urlParams['path']) {
$pathInfo = \Cml\Route::getPathInfo();
self::$urlParams['path'] = $pathInfo[0];//用于绑定系统命令
}
return trim(self::$urlParams['path'], '\\/');
} | 获取应用目录可以是多层目录。如web、admin等.404的时候也必须有值用于绑定系统命令
@return string | entailment |
public function parseUrl()
{
\Cml\Route::parsePathInfo();
$dispatcher = \FastRoute\simpleDispatcher(function (RouteCollector $r) {
foreach ($this->routes as $route) {
$r->addRoute($route['method'], $route['uri'], $route['action']);
}
});
$htt... | 解析url
@return mixed | entailment |
private function parseUrlParams($uri)
{
//is_array($action) ? $action['__rest'] = 1 : ['__rest' => 0, '__action' => $action];
if (is_array($uri) && !isset($uri['__action'])) {
self::$urlParams['path'] = $uri[0];
self::$urlParams['controller'] = $uri[1];
if (isset... | 解析uri参数
@param $uri | entailment |
public function any($pattern, $action)
{
$this->addRoute($this->httpMethod, $pattern, $action);
return $this;
} | 增加任意访问方式路由
@param string $pattern 路由规则
@param string|array $action 执行的操作
@return $this | entailment |
public function rest($pattern, $action)
{
is_array($action) ? $action['__rest'] = 1 : $action = ['__rest' => 0, '__action' => $action];
$this->addRoute($this->httpMethod, $pattern, $action);
return $this;
} | 增加REST方式路由
@param string $pattern 路由规则
@param string|array $action 执行的操作
@return $this | entailment |
private function addRoute($method, $pattern, $action)
{
if (is_array($method)) {
foreach ($method as $verb) {
$this->routes[$verb . $pattern] = ['method' => $verb, 'uri' => self::patternFactory($pattern), 'action' => $action];
}
} else {
$this->ro... | 添加一个路由
@param array|string $method
@param string $pattern
@param mixed $action
@return void | entailment |
public function normalize(PathInterface $path)
{
if ($path instanceof WindowsPathInterface) {
return $this->windowsNormalizer()->normalize($path);
}
return $this->unixNormalizer()->normalize($path);
} | Normalize the supplied path to its most canonical form.
@param PathInterface $path The path to normalize.
@return PathInterface The normalized path. | entailment |
public static function redirect($url, $time = 0)
{
strpos($url, 'http') === false && $url = self::url($url, 0);
if (!headers_sent()) {
($time === 0) && header("Location: {$url}");
header("refresh:{$time};url={$url}");
exit();
} else {
exit("<me... | 重定向
@param string $url 重写向的目标地址
@param int $time 等待时间
@return void | entailment |
public static function show404Page($tpl = null)
{
self::sendHttpStatus(404);
is_null($tpl) && $tpl = Config::get('404_page');
is_file($tpl) && Cml::requireFile($tpl);
exit();
} | 显示404页面
@param string $tpl 模板路径
@return void | entailment |
public static function fullUrl($url = '', $echo = true)
{
$url = Request::baseUrl() . self::url($url, false);
if ($echo) {
echo $url;
return '';
} else {
return $url;
}
} | URL组装(带域名端口) 支持不同URL模式
eg: \Cml\Http\Response::fullUrl('Home/Blog/cate/id/1')
@param string $url URL表达式 路径/控制器/操作/参数1/参数1值/.....
@param bool $echo 是否输出 true输出 false return
@return string | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.