code
stringlengths 15
9.96M
| docstring
stringlengths 1
10.1k
| func_name
stringlengths 1
124
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 6
186
| url
stringlengths 50
236
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
public function sync($arr)
{
$originUrlKey = 'catalog/category/index';
$origin_mysql_parent_id = $arr['parent_id'];
$origin_mysql_id = $arr['id'];
unset($arr['parent_id']);
unset($arr['id']);
$model = $this->_categoryModel->findOne([
'origin_mysql_id' => $origin_mysql_id
]);
if (!$model['origin_mysql_id']) {
$model = new $this->_categoryModelName;
$model->created_at = time();
}
$model->origin_mysql_id = $origin_mysql_id;
$model->origin_mysql_parent_id = $origin_mysql_parent_id;
//$arr = $this->serializeSaveData($arr);
$saveStatus = Yii::$service->helper->ar->save($model, $arr);
$originUrl = $originUrlKey.'?'.$this->getPrimaryKey() .'='. $model->_id;
$originUrlKey = isset($model['url_key']) ? $model['url_key'] : '';
$defaultLangTitle = Yii::$service->fecshoplang->getDefaultLangAttrVal($arr['name'], 'name');
$urlKey = Yii::$service->url->saveRewriteUrlKeyByStr($defaultLangTitle, $originUrl, $originUrlKey);
$model->url_key = $urlKey;
$model->save();
} | @param $arr | array
用于同步mysql数据库到mongodb数据库中 | sync | php | fecshop/yii2_fecshop | services/category/CategoryMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMongodb.php | BSD-3-Clause |
public function getAllParentInfo($parent_id)
{
if ($parent_id) {
$parentModel = $this->_categoryModel->findOne($parent_id);
$parent_parent_id = $parentModel['parent_id'];
$parent_category = [];
if ($parent_parent_id !== '0') {
$parent_category[] = [
'name' => $parentModel['name'],
'url_key'=>$parentModel['url_key'],
];
$parent_category = array_merge($this->getAllParentInfo($parent_parent_id), $parent_category);
} else {
$parent_category[] = [
'name' => $parentModel['name'],
'url_key'=>$parentModel['url_key'],
];
}
return $parent_category;
}
} | @param $parent_id|string
通过当前分类的parent_id字段(当前分类的上级分类id),得到所有的上级信息数组。
里面包含的信息为:name,url_key。
譬如一个分类为三级分类,将他的parent_id传递给这个函数,那么,他返回的数组信息为[一级分类的信息(name,url_key),二级分类的信息(name,url_key)].
目前这个功能用于前端分类页面的面包屑导航。 | getAllParentInfo | php | fecshop/yii2_fecshop | services/category/CategoryMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMongodb.php | BSD-3-Clause |
public function getFilterCategory($category_id, $parent_id)
{
$returnData = [];
$primaryKey = $this->getPrimaryKey();
$currentCategory = $this->_categoryModel->findOne($category_id);
$currentUrlKey = $currentCategory['url_key'];
$currentName = $currentCategory['name'];
$currentId = (string) $currentCategory['_id'];
$returnData['current'] = [
'_id' => $currentId,
'name' => $currentName,
'url_key' => $currentUrlKey,
'parent_id' => $currentCategory['parent_id'],
];
if ($currentCategory['parent_id']) {
$allParent = $this->getParentCategory($currentCategory['parent_id']);
$allParent[] = $returnData['current'];
$data = $this->getAllParentCate($allParent);
} else {
$data = $this->getOneLevelCateChild($returnData['current']);
}
return $data;
} | @param $category_id|string 当前的分类_id
@param $parent_id|string 当前的分类上级id parent_id
这个功能是点击分类后,在产品分类页面侧栏的子分类菜单导航,详细的逻辑如下:
1.如果level为一级,那么title部分为当前的分类,子分类为一级分类下的二级分类
2.如果level为二级,那么将所有的二级分类列出,当前的二级分类,会列出来当前二级分类对应的子分类
3.如果level为三级,那么将所有的二级分类列出。当前三级分类的所有姊妹分类(同一个父类)列出,当前三级分类如果有子分类,则列出
4.依次递归。
具体的显示效果,请查看appfront 对应的分类页面。 | getFilterCategory | php | fecshop/yii2_fecshop | services/category/CategoryMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMongodb.php | BSD-3-Clause |
public function excelSave($one, $originUrlKey = 'catalog/category/index')
{
$one['parent_id'] = (string)$one['parent_id'];
$one[$this->getPrimaryKey()] = (string)$one[$this->getPrimaryKey()];
$parent_id = $one['parent_id'];
$currentDateTime = \fec\helpers\CDate::getCurrentDateTime();
$primaryVal = isset($one[$this->getPrimaryKey()]) ? $one[$this->getPrimaryKey()] : '';
if (!$primaryVal) {
Yii::$service->helper->errors->add('category id can not empty');
return false;
}
$model = $this->_categoryModel->findOne($primaryVal);
if (!isset($model[$this->getPrimaryKey()]) || !$model[$this->getPrimaryKey()]) {
$model = new $this->_categoryModelName;
$idV = $one[$this->getPrimaryKey()];
//echo $this->getPrimaryKey();
//echo $idV;exit;
$model[$this->getPrimaryKey()] = $idV ;
$model->created_at = time();
$model->created_user_id = \fec\helpers\CUser::getCurrentUserId();
} else {
$name =$model['name'];
$title = $model['title'];
$meta_keywords = $model['meta_keywords'];
$meta_description = $model['meta_description'];
$description = $model['description'];
//var_dump($title);var_dump($one['title']);
if (is_array($one['name']) && !empty($one['name'])) {
$one['name'] = array_merge((is_array($name) ? $name : []), $one['name']);
}
if (is_array($one['title']) && !empty($one['title'])) {
$one['title'] = array_merge((is_array($title) ? $title : []), $one['title']);
}
if (is_array($one['meta_keywords']) && !empty($one['meta_keywords'])) {
$one['meta_keywords'] = array_merge((is_array($meta_keywords) ? $meta_keywords : []), $one['meta_keywords']);
}
if (is_array($one['meta_description']) && !empty($one['meta_description'])) {
$one['meta_description'] = array_merge((is_array($meta_description) ? $meta_description : []), $one['meta_description']);
}
if (is_array($one['description']) && !empty($one['description'])) {
$one['description'] = array_merge((is_array($description) ? $description : []), $one['description']);
}
}
// 增加分类的级别字段level,从1级级别开始依次类推。
if ($parent_id === '0') {
$model['level'] = 1;
} else {
$parent_model = $this->_categoryModel->findOne($parent_id);
if ($parent_level = $parent_model['level']) {
$model['level'] = $parent_level + 1;
}
}
$model->updated_at = time();
unset($one['_id']);
$one['status'] = (int)$one['status'];
$one['menu_show'] = (int)$one['menu_show'];
$allowMenuShowArr = [ $model::MENU_SHOW, $model::MENU_NOT_SHOW];
if (!in_array($one['menu_show'], $allowMenuShowArr)) {
$one['menu_show'] = $model::MENU_SHOW;
}
$allowStatusArr = [ $model::STATUS_ENABLE, $model::STATUS_DISABLE];
if (!in_array($one['status'], $allowStatusArr)) {
$one['status'] = $model::STATUS_ENABLE;
}
$saveStatus = Yii::$service->helper->ar->save($model, $one);
$originUrl = $originUrlKey.'?'.$this->getPrimaryKey() .'='. $primaryVal;
$originUrlKey = isset($one['url_key']) ? $one['url_key'] : '';
$defaultLangTitle = Yii::$service->fecshoplang->getDefaultLangAttrVal($one['name'], 'name');
$urlKey = Yii::$service->url->saveRewriteUrlKeyByStr($defaultLangTitle, $originUrl, $originUrlKey);
$model->url_key = $urlKey;
$model->save();
return $model;
} | @param $one|array , save one data . 分类数组
@param $originUrlKey|string , 分类的在修改之前的url key.(在数据库中保存的url_key字段,如果没有则为空)
保存分类,同时生成分类的伪静态url(自定义url),如果按照name生成的url或者自定义的urlkey存在,系统则会增加几个随机数字字符串,来增加唯一性。
和save方法不同的是,如果excel 中的category_id,查询不到,那么插入数据,将新插入数据的id = excel category id | excelSave | php | fecshop/yii2_fecshop | services/category/CategoryMongodb.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMongodb.php | BSD-3-Clause |
protected function hasChild($categoryId)
{
return Yii::$service->category->hasChildCategory($categoryId);
} | @param $categoryId|array
check if cateogry has child . | hasChild | php | fecshop/yii2_fecshop | services/category/Menu.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/category/Menu.php | BSD-3-Clause |
public function getBaseUrl()
{
return Yii::$service->image->GetImgUrl($this->imageFloder, 'common');
} | 得到保存分类图片所在相对根目录的url路径. | getBaseUrl | php | fecshop/yii2_fecshop | services/category/Image.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/category/Image.php | BSD-3-Clause |
public function getBaseDir()
{
return Yii::$service->image->GetImgDir($this->imageFloder, 'common');
} | 得到保存分类图片所在相对根目录的文件夹路径. | getBaseDir | php | fecshop/yii2_fecshop | services/category/Image.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/category/Image.php | BSD-3-Clause |
public function getUrl($str)
{
return Yii::$service->image->GetImgUrl($this->imageFloder.$str, 'common');
} | 通过分类图片的相对路径得到产品图片的url. | getUrl | php | fecshop/yii2_fecshop | services/category/Image.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/category/Image.php | BSD-3-Clause |
public function getDir($str)
{
return Yii::$service->image->GetImgDir($this->imageFloder.$str, 'common');
} | 通过分类图片的相对路径得到分类图片的绝对路径. | getDir | php | fecshop/yii2_fecshop | services/category/Image.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/category/Image.php | BSD-3-Clause |
public function saveCategoryStreamImg($fileName, $fileStream, $imgSavedRelativePath='')
{
Yii::$service->image->imageFloder = $this->imageFloder;
Yii::$service->image->allowImgType = $this->allowImgType;
if ($this->maxUploadMSize) {
Yii::$service->image->setMaxUploadSize($this->maxUploadMSize);
}
return Yii::$service->image->saveStreamImg($fileName, $fileStream, $imgSavedRelativePath);
} | @param $fileName | string, 文件名称
@param $fileStream |string, 图片文件的二进制字符。
@param $imgSavedRelativePath | string, 图片存放的相对路径,设置该值后,图片将保存到这个相对路径,如果该路径下已经存在文件,则将会覆盖。 | saveCategoryStreamImg | php | fecshop/yii2_fecshop | services/category/Image.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/category/Image.php | BSD-3-Clause |
public static function mapGet($absoluteClassName, $arguments = []){
$absoluteClassName = self::mapGetName($absoluteClassName);
if (!empty($arguments) && is_array($arguments)) {
$class = new ReflectionClass($absoluteClassName);
$absoluteOb = $class->newInstanceArgs($arguments);
/**
* 下面的 ...,是php的语法糖(只能php5.6以上,放弃),也就是把$paramArray数组里面的各个子项参数,
* 作为对象生成的参数,详细可以参看:https://segmentfault.com/q/1010000006789348
*/
//$absoluteOb = new $absoluteClassName(...$arguments);
} else {
$absoluteOb = new $absoluteClassName;
}
return [$absoluteClassName, $absoluteOb];
} | @param $absoluteClassName | String , like: '\fecshop\app\appfront\modules\Cms\block\home\Index'
@param $arguments | Array ,数组,里面的每一个子项就是用于实例化的一个参数,多少个子项,就代表有多个参数,用于对象的实例化。
通过$rewriteMap,查找是否存在重写,如果存在,则得到重写的className
然后返回 类名 和 对象 | mapGet | php | fecshop/yii2_fecshop | yii/Yii.php | https://github.com/fecshop/yii2_fecshop/blob/master/yii/Yii.php | BSD-3-Clause |
public static function mapGetName($absoluteClassName){
if(isset(self::$rewriteMap[$absoluteClassName]) && self::$rewriteMap[$absoluteClassName]){
$absoluteClassName = self::$rewriteMap[$absoluteClassName];
}
return $absoluteClassName;
} | @param $absoluteClassName | String , like: '\fecshop\app\appfront\modules\Cms\block\home\Index'
通过$rewriteMap,查找是否存在重写,如果存在,则返回重写的className | mapGetName | php | fecshop/yii2_fecshop | yii/Yii.php | https://github.com/fecshop/yii2_fecshop/blob/master/yii/Yii.php | BSD-3-Clause |
public static function mapGetClassName($className){
$absoluteClassName = '\\'.$className;
if(isset(self::$rewriteMap[$absoluteClassName]) && self::$rewriteMap[$absoluteClassName]){
$absoluteClassName = self::$rewriteMap[$absoluteClassName];
return substr($absoluteClassName,1);
}
return $className;
} | @param $className | String , block等className,前面没有`\`, like: 'fecshop\app\appfront\modules\Catalog\block\product\CustomOption'
通过$rewriteMap,查找是否存在重写,如果存在,则返回重写的className | mapGetClassName | php | fecshop/yii2_fecshop | yii/Yii.php | https://github.com/fecshop/yii2_fecshop/blob/master/yii/Yii.php | BSD-3-Clause |
protected function renderHeadHtml()
{
$lines = [];
if (!empty($this->metaTags)) {
$lines[] = implode("\n", $this->metaTags);
}
if (!empty($this->linkTags)) {
$lines[] = implode("\n", $this->linkTags);
}
if (!empty($this->cssFiles)) {
$lines[] = implode("\n", $this->cssFiles);
}
if (!empty($this->css)) {
$lines[] = implode("\n", $this->css);
}
if (!empty($this->externalJs[self::POS_HEAD])) {
$lines[] = implode("\n", $this->externalJs[self::POS_HEAD]);
}
if (!empty($this->jsFiles[self::POS_HEAD])) {
$lines[] = implode("\n", $this->jsFiles[self::POS_HEAD]);
}
if (!empty($this->js[self::POS_HEAD])) {
$lines[] = Html::script(implode("\n", $this->js[self::POS_HEAD]));
}
return empty($lines) ? '' : implode("\n", $lines);
} | Renders the content to be inserted in the head section.
The content is rendered using the registered meta tags, link tags, CSS/JS code blocks and files.
@return string the rendered content | renderHeadHtml | php | fecshop/yii2_fecshop | yii/web/View.php | https://github.com/fecshop/yii2_fecshop/blob/master/yii/web/View.php | BSD-3-Clause |
protected function renderBodyBeginHtml()
{
$lines = [];
if (!empty($this->externalJs[self::POS_BEGIN])) {
$lines[] = implode("\n", $this->externalJs[self::POS_BEGIN]);
}
if (!empty($this->jsFiles[self::POS_BEGIN])) {
$lines[] = implode("\n", $this->jsFiles[self::POS_BEGIN]);
}
if (!empty($this->js[self::POS_BEGIN])) {
$lines[] = Html::script(implode("\n", $this->js[self::POS_BEGIN]));
}
return empty($lines) ? '' : implode("\n", $lines);
} | Renders the content to be inserted at the beginning of the body section.
The content is rendered using the registered JS code blocks and files.
@return string the rendered content | renderBodyBeginHtml | php | fecshop/yii2_fecshop | yii/web/View.php | https://github.com/fecshop/yii2_fecshop/blob/master/yii/web/View.php | BSD-3-Clause |
protected function resolveRequestUri()
{
if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // IIS
$requestUri = $_SERVER['HTTP_X_REWRITE_URL'];
} elseif (isset($_SERVER['REQUEST_URI'])) {
$requestUri = $_SERVER['REQUEST_URI'];
if ($requestUri !== '' && $requestUri[0] !== '/') {
$requestUri = preg_replace('/^(http|https):\/\/[^\/]+/i', '', $requestUri);
}
} elseif (isset($_SERVER['ORIG_PATH_INFO'])) { // IIS 5.0 CGI
$requestUri = $_SERVER['ORIG_PATH_INFO'];
if (!empty($_SERVER['QUERY_STRING'])) {
$requestUri .= '?' . $_SERVER['QUERY_STRING'];
}
} else {
throw new InvalidConfigException('Unable to determine the request URI.');
}
/*
* Replace Code
* //return $requestUri;
* To:
*/
return $this->getRewriteUri($requestUri);
} | rewrite yii\web\Request resolveRequestUri(). | resolveRequestUri | php | fecshop/yii2_fecshop | yii/web/Request.php | https://github.com/fecshop/yii2_fecshop/blob/master/yii/web/Request.php | BSD-3-Clause |
protected function loginByCookie()
{
$data = $this->getIdentityAndDurationFromCookie();
if (isset($data['identity'], $data['duration'])) {
$identity = $data['identity'];
$duration = $data['duration'];
if ($this->beforeLogin($identity, true, $duration)) {
$this->switchIdentity($identity, $this->autoRenewCookie ? $duration : 0);
$id = $identity->getId();
$ip = Yii::$app->getRequest()->getUserIP();
Yii::info("User '$id' logged in from $ip via cookie.", __METHOD__);
$this->afterLogin($identity, true, $duration);
/**
* 如果user组件配置enableAutoLogin = true
* 当session失效后,就会调用当前方法,cookie获取信息后,重新使用session登录
* 因此,在账号重新恢复登录状态后,当前账户的购物车也要恢复。
* 下面的代码就是在cookie恢复登录状态后,通过当前账户的id,搜索出来购物车信息
* 然后把对应的购物车的cart_id,保存到cookie中。
*/
$customer_cart = Yii::$service->cart->quote->getCartByCustomerId($id);
$cart_id = isset($customer_cart['cart_id']) ? $customer_cart['cart_id'] : '';
//echo $cart_id;
if ($cart_id) {
Yii::$service->cart->quote->setCartId($cart_id);
}
//Yii::$service->cart->mergeCartAfterUserLogin();
}
}
} | 重写该方法的作用为:当用户登录账户设置为cookie的时候
购物车信息,通过cookie获取的用户id,在session中设置cart_id. | loginByCookie | php | fecshop/yii2_fecshop | yii/web/User.php | https://github.com/fecshop/yii2_fecshop/blob/master/yii/web/User.php | BSD-3-Clause |
public function __construct(array $server = [], ?History $history = null, ?CookieJar $cookieJar = null)
{
$this->setServerParameters($server);
$this->history = $history ?? new History();
$this->cookieJar = $cookieJar ?? new CookieJar();
} | @param array $server The server parameters (equivalent of $_SERVER) | __construct | php | symfony/browser-kit | AbstractBrowser.php | https://github.com/symfony/browser-kit/blob/master/AbstractBrowser.php | MIT |
protected function doRequestInProcess(object $request)
{
$deprecationsFile = tempnam(sys_get_temp_dir(), 'deprec');
putenv('SYMFONY_DEPRECATIONS_SERIALIZE='.$deprecationsFile);
$_ENV['SYMFONY_DEPRECATIONS_SERIALIZE'] = $deprecationsFile;
$process = new PhpProcess($this->getScript($request), null, null);
$process->run();
if (file_exists($deprecationsFile)) {
$deprecations = file_get_contents($deprecationsFile);
unlink($deprecationsFile);
foreach ($deprecations ? unserialize($deprecations) : [] as $deprecation) {
if ($deprecation[0]) {
// unsilenced on purpose
trigger_error($deprecation[1], \E_USER_DEPRECATED);
} else {
@trigger_error($deprecation[1], \E_USER_DEPRECATED);
}
}
}
if (!$process->isSuccessful() || !preg_match('/^O\:\d+\:/', $process->getOutput())) {
throw new RuntimeException(\sprintf('OUTPUT: %s ERROR OUTPUT: %s.', $process->getOutput(), $process->getErrorOutput()));
}
return unserialize($process->getOutput());
} | Makes a request in another process.
@psalm-param TRequest $request
@return object
@psalm-return TResponse
@throws \RuntimeException When processing returns exit code | doRequestInProcess | php | symfony/browser-kit | AbstractBrowser.php | https://github.com/symfony/browser-kit/blob/master/AbstractBrowser.php | MIT |
protected function getScript(object $request)
{
throw new LogicException('To insulate requests, you need to override the getScript() method.');
} | Returns the script to execute when the request must be insulated.
@psalm-param TRequest $request
@param object $request An origin request instance
@return string
@throws LogicException When this abstract class is not implemented | getScript | php | symfony/browser-kit | AbstractBrowser.php | https://github.com/symfony/browser-kit/blob/master/AbstractBrowser.php | MIT |
protected function filterRequest(Request $request)
{
return $request;
} | Filters the BrowserKit request to the origin one.
@return object
@psalm-return TRequest | filterRequest | php | symfony/browser-kit | AbstractBrowser.php | https://github.com/symfony/browser-kit/blob/master/AbstractBrowser.php | MIT |
protected function filterResponse(object $response)
{
return $response;
} | Filters the origin response to the BrowserKit one.
@psalm-param TResponse $response
@return Response | filterResponse | php | symfony/browser-kit | AbstractBrowser.php | https://github.com/symfony/browser-kit/blob/master/AbstractBrowser.php | MIT |
public function __construct(
private string $content = '',
private int $status = 200,
private array $headers = [],
) {
} | The headers array is a set of key/value pairs. If a header is present multiple times
then the value is an array of all the values.
@param string $content The content of the response
@param int $status The response status code (302 "Found" by default)
@param array $headers An array of headers | __construct | php | symfony/browser-kit | Response.php | https://github.com/symfony/browser-kit/blob/master/Response.php | MIT |
public function __construct(
private string $name,
?string $value,
?string $expires = null,
?string $path = null,
private string $domain = '',
private bool $secure = false,
private bool $httponly = true,
bool $encodedValue = false,
private ?string $samesite = null,
) {
if ($encodedValue) {
$this->rawValue = $value ?? '';
$this->value = urldecode($this->rawValue);
} else {
$this->value = $value ?? '';
$this->rawValue = rawurlencode($this->value);
}
$this->path = $path ?: '/';
if (null !== $expires) {
$timestampAsDateTime = \DateTimeImmutable::createFromFormat('U', $expires);
if (false === $timestampAsDateTime) {
throw new UnexpectedValueException(\sprintf('The cookie expiration time "%s" is not valid.', $expires));
}
$this->expires = $timestampAsDateTime->format('U');
}
} | Sets a cookie.
@param string $name The cookie name
@param string|null $value The value of the cookie
@param string|null $expires The time the cookie expires
@param string|null $path The path on the server in which the cookie will be available on
@param string $domain The domain that the cookie is available
@param bool $secure Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client
@param bool $httponly The cookie httponly flag
@param bool $encodedValue Whether the value is encoded or not
@param string|null $samesite The cookie samesite attribute | __construct | php | symfony/browser-kit | Cookie.php | https://github.com/symfony/browser-kit/blob/master/Cookie.php | MIT |
public function __construct(
protected string $uri,
protected string $method,
protected array $parameters = [],
protected array $files = [],
protected array $cookies = [],
protected array $server = [],
protected ?string $content = null,
) {
array_walk_recursive($parameters, static function (&$value) {
$value = (string) $value;
});
$this->parameters = $parameters;
} | @param string $uri The request URI
@param string $method The HTTP method request
@param array $parameters The request parameters
@param array $files An array of uploaded files
@param array $cookies An array of cookies
@param array $server An array of server parameters
@param string|null $content The raw body data | __construct | php | symfony/browser-kit | Request.php | https://github.com/symfony/browser-kit/blob/master/Request.php | MIT |
public function __construct(public $context = [], $prePrompt = "", $functions = [], protected $model = 'claude-3-opus-20240229', protected $claudeOptions = [])
{
parent::__construct($context, $prePrompt, $functions);
$this->client = new AnthropicClient(config('anthropic.api_key'), $claudeOptions['anthropic-version'] ?? "2023-06-01");
} | @param string $model
@param array $context
@param array $claudeOptions | __construct | php | adrenallen/ai-agents-laravel | src/ChatModels/AnthropicClaude.php | https://github.com/adrenallen/ai-agents-laravel/blob/master/src/ChatModels/AnthropicClaude.php | MIT |
public function recordContext($message) {
if (count($this->context) > 0) {
$lastIdx = count($this->context) - 1;
$lastMessage = $this->context[$lastIdx];
if ($lastMessage['role'] == $message['role']) {
$this->context[$lastIdx]['content'] = $this->mergeAndOrderSameContents($message['content'], $this->context[$lastIdx]['content']);
return;
}
}
parent::recordContext($message);
} | Override, we must combine all contexts that are the same "role" in a row into a single message | recordContext | php | adrenallen/ai-agents-laravel | src/ChatModels/AnthropicClaude.php | https://github.com/adrenallen/ai-agents-laravel/blob/master/src/ChatModels/AnthropicClaude.php | MIT |
private function getContextForNewMessage($message) {
$newContext = [...$this->context];
if ($message) {
// if the last message in the context is the same role, combine them
if (count($newContext) > 0) {
$lastIdx = count($newContext) - 1;
$lastMessage = $newContext[$lastIdx];
if ($lastMessage['role'] == $message['role']) {
$newContext[$lastIdx]['content'] = $this->mergeAndOrderSameContents($message['content'], $newContext[$lastIdx]['content']);
return $newContext;
}
}
$newContext[] = $message;
}
return $newContext;
} | Gets a new context based on the current context and the new message
does not update this models context though! We record it after we get the response and it's successful | getContextForNewMessage | php | adrenallen/ai-agents-laravel | src/ChatModels/AnthropicClaude.php | https://github.com/adrenallen/ai-agents-laravel/blob/master/src/ChatModels/AnthropicClaude.php | MIT |
protected function convertFunctionsForModel(AgentFunction $function)
{
$parameters = [];
foreach ($function->parameters as $parameter) {
$parameters[$parameter["name"]] = [
'type' => $parameter["type"],
'description' => $parameter["description"],
];
}
return [
"name" => $function->name,
"description" => $function->description,
'input_schema' => [
'type' => 'object',
//convert to object so json_encode works as expected
// and converts [] to {}
'properties' => (object)$parameters,
'required' => $function->requiredParameters,
]
];
} | Based on https://docs.anthropic.com/claude/docs/functions-external-tools | convertFunctionsForModel | php | adrenallen/ai-agents-laravel | src/ChatModels/AnthropicClaude.php | https://github.com/adrenallen/ai-agents-laravel/blob/master/src/ChatModels/AnthropicClaude.php | MIT |
public function __construct(public $apiKey, private $anthropicVersion = "2023-06-01")
{} | constructor | __construct | php | adrenallen/ai-agents-laravel | src/ChatModels/AnthropicClaude.php | https://github.com/adrenallen/ai-agents-laravel/blob/master/src/ChatModels/AnthropicClaude.php | MIT |
public function __construct($context = [], $prePrompt = "", $functions = [], $model = 'gpt-3.5-turbo', $openAiOptions = [])
{
parent::__construct($context, $prePrompt, $functions);
$this->model = $model;
$this->client = OpenAI::client(config('openai.api_key'));
$this->context = $context;
$this->openAiOptions = $openAiOptions;
} | @param string $model
@param array $context
@param array $openAiOptions | __construct | php | adrenallen/ai-agents-laravel | src/ChatModels/ChatGPT.php | https://github.com/adrenallen/ai-agents-laravel/blob/master/src/ChatModels/ChatGPT.php | MIT |
public function recordContext($message) {
$this->context[] = $message;
} | Add a new message to the context history
The input SHOULD BE FORMATTED PROPERTLY
USE `recordUserMessage` IF YOU ARE UNSURE
@param [type] $message
@return void | recordContext | php | adrenallen/ai-agents-laravel | src/ChatModels/AbstractChatModel.php | https://github.com/adrenallen/ai-agents-laravel/blob/master/src/ChatModels/AbstractChatModel.php | MIT |
public function recordThought(string $thought) {
return "recorded";
} | @aiagent-description Record a thought based on the last message
@param string $thought
@return mixed | recordThought | php | adrenallen/ai-agents-laravel | src/Agents/ReactAgent.php | https://github.com/adrenallen/ai-agents-laravel/blob/master/src/Agents/ReactAgent.php | MIT |
public function recordObservation(string $observation) {
return "recorded";
} | @aiagent-description Record an observation based on the last message
@param string $observation
@return mixed | recordObservation | php | adrenallen/ai-agents-laravel | src/Agents/ReactAgent.php | https://github.com/adrenallen/ai-agents-laravel/blob/master/src/Agents/ReactAgent.php | MIT |
public function handle()
{
if (class_exists($this->argument('agent'))) {
$agentClass = $this->argument('agent');
} else {
$agentClass = "\Adrenallen\AiAgentsLaravel\Agents\\" . $this->argument('agent');
}
$agent = new $agentClass(new \Adrenallen\AiAgentsLaravel\ChatModels\ChatGPT());
$this->info($agentClass . " is now chatting with you.");
$this->info("Send the message 'exit' to exit the chat.");
$userMsg = $this->ask("You");
while($userMsg != "exit") {
$agentMsg = $agent->ask($userMsg);
$this->info("Agent: " . $agentMsg);
$userMsg = $this->ask("You");
}
$this->info("Agent: Thanks for chatting!");
} | Execute the console command. | handle | php | adrenallen/ai-agents-laravel | src/Console/Commands/ChatWithAgent.php | https://github.com/adrenallen/ai-agents-laravel/blob/master/src/Console/Commands/ChatWithAgent.php | MIT |
public function partName()
{
return 'INSERT';
} | @return string | partName | php | nilportugues/php-sql-query-builder | src/Manipulation/Insert.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Insert.php | MIT |
public function getColumns()
{
$columns = \array_keys($this->values);
return SyntaxFactory::createColumns($columns, $this->getTable());
} | @return array | getColumns | php | nilportugues/php-sql-query-builder | src/Manipulation/Insert.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Insert.php | MIT |
public static function createSelect($table = null, array $columns = null)
{
return new Select($table, $columns);
} | @param string $table
@param array $columns
@return Select | createSelect | php | nilportugues/php-sql-query-builder | src/Manipulation/QueryFactory.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/QueryFactory.php | MIT |
public static function createInsert($table = null, array $values = null)
{
return new Insert($table, $values);
} | @param string $table
@param array $values
@return Insert | createInsert | php | nilportugues/php-sql-query-builder | src/Manipulation/QueryFactory.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/QueryFactory.php | MIT |
public static function createUpdate($table = null, array $values = null)
{
return new Update($table, $values);
} | @param string $table
@param array $values
@return Update | createUpdate | php | nilportugues/php-sql-query-builder | src/Manipulation/QueryFactory.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/QueryFactory.php | MIT |
public static function createDelete($table = null)
{
return new Delete($table);
} | @param string $table
@return Delete | createDelete | php | nilportugues/php-sql-query-builder | src/Manipulation/QueryFactory.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/QueryFactory.php | MIT |
public static function createWhere(QueryInterface $query)
{
return new Where($query);
} | @param QueryInterface $query
@return Where | createWhere | php | nilportugues/php-sql-query-builder | src/Manipulation/QueryFactory.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/QueryFactory.php | MIT |
public static function createIntersect()
{
return new Intersect();
} | @return Intersect | createIntersect | php | nilportugues/php-sql-query-builder | src/Manipulation/QueryFactory.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/QueryFactory.php | MIT |
public static function createMinus(Select $first, Select $second)
{
return new Minus($first, $second);
} | @param Select $first
@param Select $second
@return Minus | createMinus | php | nilportugues/php-sql-query-builder | src/Manipulation/QueryFactory.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/QueryFactory.php | MIT |
public static function createUnion()
{
return new Union();
} | @return Union | createUnion | php | nilportugues/php-sql-query-builder | src/Manipulation/QueryFactory.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/QueryFactory.php | MIT |
public static function createUnionAll()
{
return new UnionAll();
} | @return UnionAll | createUnionAll | php | nilportugues/php-sql-query-builder | src/Manipulation/QueryFactory.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/QueryFactory.php | MIT |
public function __construct($table = null, array $columns = null)
{
if (isset($table)) {
$this->setTable($table);
}
$this->joinQuery = new JoinQuery($this);
$this->columnQuery = new ColumnQuery($this, $this->joinQuery, $columns);
} | @param string $table
@param array $columns | __construct | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function __clone()
{
return \unserialize(\serialize($this));
} | This __clone method will create an exact clone but without the object references due to the fact these
are lost in the process of serialization and un-serialization.
@return Select | __clone | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function partName()
{
return 'SELECT';
} | @return string | partName | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function leftJoin($table, $selfColumn = null, $refColumn = null, $columns = [])
{
return $this->joinQuery->leftJoin($table, $selfColumn, $refColumn, $columns);
} | @param string $table
@param string $selfColumn
@param string $refColumn
@param string[] $columns
@return Select | leftJoin | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function join(
$table,
$selfColumn = null,
$refColumn = null,
$columns = [],
$joinType = null
) {
return $this->joinQuery->join($table, $selfColumn, $refColumn, $columns, $joinType);
} | @param string $table
@param string $selfColumn
@param string $refColumn
@param string[] $columns
@param string $joinType
@return Select | join | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function joinCondition()
{
return $this->joinQuery->joinCondition();
} | WHERE constrains used for the ON clause of a (LEFT/RIGHT/INNER/CROSS) JOIN.
@return Where | joinCondition | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function addJoin(Select $select, $selfColumn, $refColumn)
{
return $this->joinQuery->addJoin($select, $selfColumn, $refColumn);
} | @param Select $select
@param string $selfColumn
@param string $refColumn
@return Select | addJoin | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function isJoin($isJoin = true)
{
return $this->joinQuery->setJoin($isJoin);
} | Transforms Select in a joint.
@param bool $isJoin
@return JoinQuery | isJoin | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function rightJoin($table, $selfColumn = null, $refColumn = null, $columns = [])
{
return $this->joinQuery->rightJoin($table, $selfColumn, $refColumn, $columns);
} | @param string $table
@param string $selfColumn
@param string $refColumn
@param string[] $columns
@internal param null $selectClass
@return Select | rightJoin | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function crossJoin($table, $selfColumn = null, $refColumn = null, $columns = [])
{
return $this->joinQuery->crossJoin($table, $selfColumn, $refColumn, $columns);
} | @param string $table
@param string $selfColumn
@param string $refColumn
@param string[] $columns
@return Select | crossJoin | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function innerJoin($table, $selfColumn = null, $refColumn = null, $columns = [])
{
return $this->joinQuery->innerJoin($table, $selfColumn, $refColumn, $columns);
} | @param string $table
@param string $selfColumn
@param string $refColumn
@param string[] $columns
@return Select | innerJoin | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function on()
{
return $this->joinQuery->joinCondition();
} | Alias to joinCondition.
@return Where | on | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function isJoinSelect()
{
return $this->joinQuery->isJoin();
} | @return bool | isJoinSelect | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function getAllColumns()
{
return $this->columnQuery->getAllColumns();
} | @return array | getAllColumns | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function getColumns()
{
return $this->columnQuery->getColumns();
} | @return \NilPortugues\Sql\QueryBuilder\Syntax\Column
@throws QueryException | getColumns | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function setColumns(array $columns)
{
return $this->columnQuery->setColumns($columns);
} | Sets the column names used to write the SELECT statement.
If key is set, key is the column's alias. Value is always the column names.
@param string[] $columns
@return ColumnQuery | setColumns | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function setSelectAsColumn(array $column)
{
return $this->columnQuery->setSelectAsColumn($column);
} | Allows setting a Select query as a column value.
@param array $column
@return ColumnQuery | setSelectAsColumn | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function getColumnSelects()
{
return $this->columnQuery->getColumnSelects();
} | @return array | getColumnSelects | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function setValueAsColumn($value, $alias)
{
return $this->columnQuery->setValueAsColumn($value, $alias);
} | Allows setting a value to the select statement.
@param string $value
@param string $alias
@return ColumnQuery | setValueAsColumn | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function getColumnValues()
{
return $this->columnQuery->getColumnValues();
} | @return array | getColumnValues | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function setFunctionAsColumn($funcName, array $arguments, $alias)
{
return $this->columnQuery->setFunctionAsColumn($funcName, $arguments, $alias);
} | Allows calculation on columns using predefined SQL functions.
@param string $funcName
@param string[] $arguments
@param string $alias
@return ColumnQuery | setFunctionAsColumn | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function getColumnFuncs()
{
return $this->columnQuery->getColumnFuncs();
} | @return array | getColumnFuncs | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function getAllWheres()
{
return $this->getAllOperation($this->where, 'getAllWheres');
} | Returns all the Where conditions to the BuilderInterface class in order to write the SQL WHERE statement.
@return array | getAllWheres | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function getAllHavings()
{
return $this->getAllOperation($this->having, 'getAllHavings');
} | @return array | getAllHavings | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function count($columnName = '*', $alias = '')
{
return $this->columnQuery->count($columnName, $alias);
} | @param string $columnName
@param string $alias
@return ColumnQuery | count | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function isCount()
{
return $this->columnQuery->isCount();
} | @return bool | isCount | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function limit($start, $count = 0)
{
$this->limitStart = $start;
$this->limitCount = $count;
return $this;
} | @param int $start
@param $count
@return $this | limit | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function getAllJoins()
{
return $this->joinQuery->getAllJoins();
} | @return array | getAllJoins | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function getGroupBy()
{
return SyntaxFactory::createColumns($this->groupBy, $this->getTable());
} | @return array | getGroupBy | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function groupBy(array $columns)
{
$this->groupBy = $columns;
return $this;
} | @param string[] $columns
@return $this | groupBy | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function getJoinCondition()
{
return $this->joinQuery->getJoinCondition();
} | @return Where | getJoinCondition | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function getJoinType()
{
return $this->joinQuery->getJoinType();
} | @return string | getJoinType | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function setJoinType($joinType)
{
$this->joinQuery->setJoinType($joinType);
return $this;
} | @param string|null $joinType
@return $this | setJoinType | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function having($havingOperator = 'AND')
{
if (!isset($this->having)) {
$this->having = QueryFactory::createWhere($this);
}
if (!in_array($havingOperator, array(Where::CONJUNCTION_AND, Where::CONJUNCTION_OR))) {
throw new QueryException(
"Invalid conjunction specified, must be one of AND or OR, but '".$havingOperator."' was found."
);
}
$this->havingOperator = $havingOperator;
return $this->having;
} | @param $havingOperator
@throws QueryException
@return Where | having | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function getHavingOperator()
{
return $this->havingOperator;
} | @return string | getHavingOperator | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function distinct()
{
$this->isDistinct = true;
return $this;
} | @return $this | distinct | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function isDistinct()
{
return $this->isDistinct;
} | @return bool | isDistinct | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function getAllOrderBy()
{
return $this->orderBy;
} | @return array | getAllOrderBy | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function getParentQuery()
{
return $this->parentQuery;
} | @return ParentQuery | getParentQuery | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function setParentQuery(Select $parentQuery)
{
$this->parentQuery = $parentQuery;
return $this;
} | @param Select $parentQuery
@return $this | setParentQuery | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
public function orderBy($column, $direction = OrderBy::ASC, $table = null)
{
$current = parent::orderBy($column, $direction, $table);
if ($this->getParentQuery() != null) {
$this->getParentQuery()->orderBy($column, $direction, \is_null($table) ? $this->getTable() : $table);
}
return $current;
} | @param string $column
@param string $direction
@param null $table
@return $this | orderBy | php | nilportugues/php-sql-query-builder | src/Manipulation/Select.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/Select.php | MIT |
protected function filter()
{
if (!isset($this->where)) {
$this->where = QueryFactory::createWhere($this);
}
return $this->where;
} | @return Where | filter | php | nilportugues/php-sql-query-builder | src/Manipulation/AbstractBaseQuery.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/AbstractBaseQuery.php | MIT |
final public function setBuilder(BuilderInterface $builder)
{
$this->builder = $builder;
return $this;
} | Stores the builder that created this query.
@param BuilderInterface $builder
@return $this | setBuilder | php | nilportugues/php-sql-query-builder | src/Manipulation/AbstractBaseQuery.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/AbstractBaseQuery.php | MIT |
final public function getBuilder()
{
if (!$this->builder) {
throw new \RuntimeException('Query builder has not been injected with setBuilder');
}
return $this->builder;
} | @return BuilderInterface
@throws \RuntimeException when builder has not been injected | getBuilder | php | nilportugues/php-sql-query-builder | src/Manipulation/AbstractBaseQuery.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/AbstractBaseQuery.php | MIT |
public function __toString()
{
try {
return $this->getSql();
} catch (\Exception $e) {
return \sprintf('[%s] %s', \get_class($e), $e->getMessage());
}
} | Converts this query into an SQL string by using the injected builder.
@return string | __toString | php | nilportugues/php-sql-query-builder | src/Manipulation/AbstractBaseQuery.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/AbstractBaseQuery.php | MIT |
public function getSql($formatted = false)
{
if ($formatted) {
return $this->getBuilder()->writeFormatted($this);
}
return $this->getBuilder()->write($this);
} | Converts this query into an SQL string by using the injected builder.
Optionally can return the SQL with formatted structure.
@param bool $formatted
@return string | getSql | php | nilportugues/php-sql-query-builder | src/Manipulation/AbstractBaseQuery.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/AbstractBaseQuery.php | MIT |
public function getWhere()
{
return $this->where;
} | @return Where | getWhere | php | nilportugues/php-sql-query-builder | src/Manipulation/AbstractBaseQuery.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/AbstractBaseQuery.php | MIT |
public function setWhere(Where $where)
{
$this->where = $where;
return $this;
} | @param Where $where
@return $this | setWhere | php | nilportugues/php-sql-query-builder | src/Manipulation/AbstractBaseQuery.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/AbstractBaseQuery.php | MIT |
public function getTable()
{
$newTable = array($this->table);
return \is_null($this->table) ? null : SyntaxFactory::createTable($newTable);
} | @return Table | getTable | php | nilportugues/php-sql-query-builder | src/Manipulation/AbstractBaseQuery.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/AbstractBaseQuery.php | MIT |
public function setTable($table)
{
$this->table = (string) $table;
return $this;
} | @param string $table
@return $this | setTable | php | nilportugues/php-sql-query-builder | src/Manipulation/AbstractBaseQuery.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/AbstractBaseQuery.php | MIT |
public function where($whereOperator = 'AND')
{
if (!isset($this->where)) {
$this->where = $this->filter();
}
$this->where->conjunction($whereOperator);
return $this->where;
} | @param string $whereOperator
@return Where | where | php | nilportugues/php-sql-query-builder | src/Manipulation/AbstractBaseQuery.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/AbstractBaseQuery.php | MIT |
public function getWhereOperator()
{
if (!isset($this->where)) {
$this->where = $this->filter();
}
return $this->where->getConjunction();
} | @return string | getWhereOperator | php | nilportugues/php-sql-query-builder | src/Manipulation/AbstractBaseQuery.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/AbstractBaseQuery.php | MIT |
public function orderBy($column, $direction = OrderBy::ASC, $table = null)
{
$newColumn = array($column);
$column = SyntaxFactory::createColumn($newColumn, \is_null($table) ? $this->getTable() : $table);
$this->orderBy[] = new OrderBy($column, $direction);
return $this;
} | @param string $column
@param string $direction
@param null $table
@return $this | orderBy | php | nilportugues/php-sql-query-builder | src/Manipulation/AbstractBaseQuery.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/AbstractBaseQuery.php | MIT |
public function getLimitCount()
{
return $this->limitCount;
} | @return int | getLimitCount | php | nilportugues/php-sql-query-builder | src/Manipulation/AbstractBaseQuery.php | https://github.com/nilportugues/php-sql-query-builder/blob/master/src/Manipulation/AbstractBaseQuery.php | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.