repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
zofe/rapyd-laravel
src/DataForm/DataForm.php
DataForm.set
public function set($field, $value = null , $insert = true, $update = true) { if (is_array($field)) { foreach ($field as $key=>$val) { $this->set($key, $val, $insert, $update); } } $this->add($field, '', 'auto'); if ($insert) $this->field($field)->insertValue($value); if ($update) $this->field($field)->updateValue($value); }
php
public function set($field, $value = null , $insert = true, $update = true) { if (is_array($field)) { foreach ($field as $key=>$val) { $this->set($key, $val, $insert, $update); } } $this->add($field, '', 'auto'); if ($insert) $this->field($field)->insertValue($value); if ($update) $this->field($field)->updateValue($value); }
[ "public", "function", "set", "(", "$", "field", ",", "$", "value", "=", "null", ",", "$", "insert", "=", "true", ",", "$", "update", "=", "true", ")", "{", "if", "(", "is_array", "(", "$", "field", ")", ")", "{", "foreach", "(", "$", "field", "...
Set a value to model without show anything (it appends an auto-field) It set value on insert and update (but is configurable) @param $field @param $value @param bool $insert @param bool $update
[ "Set", "a", "value", "to", "model", "without", "show", "anything", "(", "it", "appends", "an", "auto", "-", "field", ")", "It", "set", "value", "on", "insert", "and", "update", "(", "but", "is", "configurable", ")" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/DataForm.php#L639-L655
zofe/rapyd-laravel
src/DataSet.php
DataSet.source
public static function source($source) { $ins = new static(); $ins->source = $source; //inherit cid from datafilter if ($ins->source instanceof \Zofe\Rapyd\DataFilter\DataFilter) { $ins->cid = $ins->source->cid; } //generate new component id else { $ins->cid = $ins->getIdentifier(); } return $ins; }
php
public static function source($source) { $ins = new static(); $ins->source = $source; //inherit cid from datafilter if ($ins->source instanceof \Zofe\Rapyd\DataFilter\DataFilter) { $ins->cid = $ins->source->cid; } //generate new component id else { $ins->cid = $ins->getIdentifier(); } return $ins; }
[ "public", "static", "function", "source", "(", "$", "source", ")", "{", "$", "ins", "=", "new", "static", "(", ")", ";", "$", "ins", "->", "source", "=", "$", "source", ";", "//inherit cid from datafilter", "if", "(", "$", "ins", "->", "source", "insta...
@param $source @return static
[ "@param", "$source" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataSet.php#L48-L63
zofe/rapyd-laravel
src/DataSet.php
DataSet.links
public function links($view = null) { if ($this->limit) { if ($this->hash != '') $links = $this->paginator->appends($this->url->remove('page'.$this->cid)->getArray())->fragment($this->hash)->render($view); else $links = $this->paginator->appends($this->url->remove('page'.$this->cid)->getArray())->render($view); $links = str_replace('#pjax','%23pajax',$links); return str_replace('/?', '?', $links); } }
php
public function links($view = null) { if ($this->limit) { if ($this->hash != '') $links = $this->paginator->appends($this->url->remove('page'.$this->cid)->getArray())->fragment($this->hash)->render($view); else $links = $this->paginator->appends($this->url->remove('page'.$this->cid)->getArray())->render($view); $links = str_replace('#pjax','%23pajax',$links); return str_replace('/?', '?', $links); } }
[ "public", "function", "links", "(", "$", "view", "=", "null", ")", "{", "if", "(", "$", "this", "->", "limit", ")", "{", "if", "(", "$", "this", "->", "hash", "!=", "''", ")", "$", "links", "=", "$", "this", "->", "paginator", "->", "appends", ...
@param string $view @return mixed
[ "@param", "string", "$view" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataSet.php#L324-L335
zofe/rapyd-laravel
src/DataSet.php
DataSet.addOrderBy
public function addOrderBy($fieldname) { $this->orderby_check = true; $this->orderby_fields = array_merge($this->orderby_fields, (array)$fieldname); return $this; }
php
public function addOrderBy($fieldname) { $this->orderby_check = true; $this->orderby_fields = array_merge($this->orderby_fields, (array)$fieldname); return $this; }
[ "public", "function", "addOrderBy", "(", "$", "fieldname", ")", "{", "$", "this", "->", "orderby_check", "=", "true", ";", "$", "this", "->", "orderby_fields", "=", "array_merge", "(", "$", "this", "->", "orderby_fields", ",", "(", "array", ")", "$", "fi...
add the ability to check & enable "order by" of given field/s by default you can order by @param mixed $fieldname
[ "add", "the", "ability", "to", "check", "&", "enable", "order", "by", "of", "given", "field", "/", "s", "by", "default", "you", "can", "order", "by" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataSet.php#L348-L354
zofe/rapyd-laravel
src/DataForm/Field/Image.php
Image.resize
public function resize($width, $height, $filename = null) { $this->resize[] = array('width'=>$width, 'height'=>$height, 'filename'=>$filename); return $this; }
php
public function resize($width, $height, $filename = null) { $this->resize[] = array('width'=>$width, 'height'=>$height, 'filename'=>$filename); return $this; }
[ "public", "function", "resize", "(", "$", "width", ",", "$", "height", ",", "$", "filename", "=", "null", ")", "{", "$", "this", "->", "resize", "[", "]", "=", "array", "(", "'width'", "=>", "$", "width", ",", "'height'", "=>", "$", "height", ",", ...
shortcut to ImageManager resize @param $width @param $height @param $filename @return $this
[ "shortcut", "to", "ImageManager", "resize" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/Field/Image.php#L48-L53
zofe/rapyd-laravel
src/DataForm/Field/Image.php
Image.fit
public function fit($width, $height, $filename = null) { $this->fit[] = array('width'=>$width, 'height'=>$height, 'filename'=>$filename); return $this; }
php
public function fit($width, $height, $filename = null) { $this->fit[] = array('width'=>$width, 'height'=>$height, 'filename'=>$filename); return $this; }
[ "public", "function", "fit", "(", "$", "width", ",", "$", "height", ",", "$", "filename", "=", "null", ")", "{", "$", "this", "->", "fit", "[", "]", "=", "array", "(", "'width'", "=>", "$", "width", ",", "'height'", "=>", "$", "height", ",", "'fi...
shortcut to ImageManager fit @param $width @param $height @param $filename @return $this
[ "shortcut", "to", "ImageManager", "fit" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/Field/Image.php#L62-L67
zofe/rapyd-laravel
src/DataForm/Field/Image.php
Image.imageProcess
protected function imageProcess() { if ($this->saved) { if (!$this->image) $this->image = ImageManager::make($this->saved); if ($this->image_callable) { $callable = $this->image_callable; $callable($this->image); } if (count($this->resize)) { foreach ($this->resize as $resize) { $this->image->resize($resize["width"], $resize["height"]); $this->image->save($this->parseString($resize["filename"])); } } if (count($this->fit)) { foreach ($this->fit as $fit) { $this->image->fit($fit["width"], $fit["height"]); $this->image->save($this->parseString($fit["filename"])); } } } }
php
protected function imageProcess() { if ($this->saved) { if (!$this->image) $this->image = ImageManager::make($this->saved); if ($this->image_callable) { $callable = $this->image_callable; $callable($this->image); } if (count($this->resize)) { foreach ($this->resize as $resize) { $this->image->resize($resize["width"], $resize["height"]); $this->image->save($this->parseString($resize["filename"])); } } if (count($this->fit)) { foreach ($this->fit as $fit) { $this->image->fit($fit["width"], $fit["height"]); $this->image->save($this->parseString($fit["filename"])); } } } }
[ "protected", "function", "imageProcess", "(", ")", "{", "if", "(", "$", "this", "->", "saved", ")", "{", "if", "(", "!", "$", "this", "->", "image", ")", "$", "this", "->", "image", "=", "ImageManager", "::", "make", "(", "$", "this", "->", "saved"...
postprocess image if needed
[ "postprocess", "image", "if", "needed" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/Field/Image.php#L85-L110
zofe/rapyd-laravel
src/Widget.php
Widget.button
public function button($name, $position="BL", $attributes=array()) { $attributes = array_merge(array("class"=>"btn btn-default"), $attributes); $this->button_container[$position][] = Form::button($name, $attributes); return $this; }
php
public function button($name, $position="BL", $attributes=array()) { $attributes = array_merge(array("class"=>"btn btn-default"), $attributes); $this->button_container[$position][] = Form::button($name, $attributes); return $this; }
[ "public", "function", "button", "(", "$", "name", ",", "$", "position", "=", "\"BL\"", ",", "$", "attributes", "=", "array", "(", ")", ")", "{", "$", "attributes", "=", "array_merge", "(", "array", "(", "\"class\"", "=>", "\"btn btn-default\"", ")", ",",...
@param string $name @param string $position @param array $attributes @return $this
[ "@param", "string", "$name", "@param", "string", "$position", "@param", "array", "$attributes" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/Widget.php#L58-L65
zofe/rapyd-laravel
src/Widget.php
Widget.link
public function link($url, $name, $position="BL", $attributes=array()) { $base = str_replace(Request::path(),'',strtok(Request::fullUrl(),'?')); $match_url = str_replace($base, '/', strtok($url,'?')); if (Request::path()!= $match_url) { $url = Persistence::get($match_url, parse_url($url, PHP_URL_QUERY)); } $attributes = array_merge(array("class"=>"btn btn-default"), $attributes); $this->button_container[$position][] = HTML::link($url, $name, $attributes); $this->links[] = $url; return $this; }
php
public function link($url, $name, $position="BL", $attributes=array()) { $base = str_replace(Request::path(),'',strtok(Request::fullUrl(),'?')); $match_url = str_replace($base, '/', strtok($url,'?')); if (Request::path()!= $match_url) { $url = Persistence::get($match_url, parse_url($url, PHP_URL_QUERY)); } $attributes = array_merge(array("class"=>"btn btn-default"), $attributes); $this->button_container[$position][] = HTML::link($url, $name, $attributes); $this->links[] = $url; return $this; }
[ "public", "function", "link", "(", "$", "url", ",", "$", "name", ",", "$", "position", "=", "\"BL\"", ",", "$", "attributes", "=", "array", "(", ")", ")", "{", "$", "base", "=", "str_replace", "(", "Request", "::", "path", "(", ")", ",", "''", ",...
@param string $url @param string $name @param string $position @param array $attributes @return $this
[ "@param", "string", "$url", "@param", "string", "$name", "@param", "string", "$position", "@param", "array", "$attributes" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/Widget.php#L75-L89
zofe/rapyd-laravel
src/Widget.php
Widget.linkRoute
public function linkRoute($route, $name, $parameters=array(), $position="BL", $attributes=array()) { return $this->link(route($route, $parameters), $name, $position, $attributes); }
php
public function linkRoute($route, $name, $parameters=array(), $position="BL", $attributes=array()) { return $this->link(route($route, $parameters), $name, $position, $attributes); }
[ "public", "function", "linkRoute", "(", "$", "route", ",", "$", "name", ",", "$", "parameters", "=", "array", "(", ")", ",", "$", "position", "=", "\"BL\"", ",", "$", "attributes", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "lin...
@param string $route @param string $name @param array $parameters @param string $position @param array $attributes @return $this
[ "@param", "string", "$route", "@param", "string", "$name", "@param", "array", "$parameters", "@param", "string", "$position", "@param", "array", "$attributes" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/Widget.php#L100-L103
zofe/rapyd-laravel
src/Widget.php
Widget.linkAction
public function linkAction($action, $name, $parameters=array(), $position="BL", $attributes=array()) { return $this->link(action($action, $parameters), $name, $position, $attributes); }
php
public function linkAction($action, $name, $parameters=array(), $position="BL", $attributes=array()) { return $this->link(action($action, $parameters), $name, $position, $attributes); }
[ "public", "function", "linkAction", "(", "$", "action", ",", "$", "name", ",", "$", "parameters", "=", "array", "(", ")", ",", "$", "position", "=", "\"BL\"", ",", "$", "attributes", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "l...
@param string $action @param string $name @param array $parameters @param string $position @param array $attributes @return $this
[ "@param", "string", "$action", "@param", "string", "$name", "@param", "array", "$parameters", "@param", "string", "$position", "@param", "array", "$attributes" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/Widget.php#L114-L117
zofe/rapyd-laravel
src/Widget.php
Widget.attributes
public function attributes($attributes) { if (is_array($this->attributes) and is_array($attributes)) { $attributes = array_merge($this->attributes, $attributes); } $this->attributes = $attributes; return $this; }
php
public function attributes($attributes) { if (is_array($this->attributes) and is_array($attributes)) { $attributes = array_merge($this->attributes, $attributes); } $this->attributes = $attributes; return $this; }
[ "public", "function", "attributes", "(", "$", "attributes", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "attributes", ")", "and", "is_array", "(", "$", "attributes", ")", ")", "{", "$", "attributes", "=", "array_merge", "(", "$", "this", "...
set attributes for widget @param $attributes @return $this
[ "set", "attributes", "for", "widget" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/Widget.php#L165-L173
zofe/rapyd-laravel
src/Widget.php
Widget.attr
public function attr($attribute, $value = null) { if (is_array($attribute)) return $this->attributes($attribute); if ($value) return $this->attributes(array($attribute => $value)); }
php
public function attr($attribute, $value = null) { if (is_array($attribute)) return $this->attributes($attribute); if ($value) return $this->attributes(array($attribute => $value)); }
[ "public", "function", "attr", "(", "$", "attribute", ",", "$", "value", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "attribute", ")", ")", "return", "$", "this", "->", "attributes", "(", "$", "attribute", ")", ";", "if", "(", "$", "valu...
add an attribute, or shortcut for attributes() @param $attributes @return $this
[ "add", "an", "attribute", "or", "shortcut", "for", "attributes", "()" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/Widget.php#L180-L184
zofe/rapyd-laravel
src/Widget.php
Widget.buildAttributes
public function buildAttributes() { if (is_string($this->attributes)) return $this->attributes; if (count($this->attributes)<1) return ""; $compiled = ''; foreach ($this->attributes as $key => $val) { $compiled .= ' '.$key.'="'.$val.'"'; } return $compiled; }
php
public function buildAttributes() { if (is_string($this->attributes)) return $this->attributes; if (count($this->attributes)<1) return ""; $compiled = ''; foreach ($this->attributes as $key => $val) { $compiled .= ' '.$key.'="'.$val.'"'; } return $compiled; }
[ "public", "function", "buildAttributes", "(", ")", "{", "if", "(", "is_string", "(", "$", "this", "->", "attributes", ")", ")", "return", "$", "this", "->", "attributes", ";", "if", "(", "count", "(", "$", "this", "->", "attributes", ")", "<", "1", "...
return a attributes in string format @return string
[ "return", "a", "attributes", "in", "string", "format" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/Widget.php#L190-L204
zofe/rapyd-laravel
src/Widget.php
Widget.formButton
public function formButton($url, $method, $name, $position="BL", $attributes=array()) { $attributes = array_merge(array("class"=>"btn btn-default"), $attributes); $this->button_container[$position][] = Form::open(array('url' => $url, 'method' => $method)).Form::submit($name, $attributes).Form::close(); return $this; }
php
public function formButton($url, $method, $name, $position="BL", $attributes=array()) { $attributes = array_merge(array("class"=>"btn btn-default"), $attributes); $this->button_container[$position][] = Form::open(array('url' => $url, 'method' => $method)).Form::submit($name, $attributes).Form::close(); return $this; }
[ "public", "function", "formButton", "(", "$", "url", ",", "$", "method", ",", "$", "name", ",", "$", "position", "=", "\"BL\"", ",", "$", "attributes", "=", "array", "(", ")", ")", "{", "$", "attributes", "=", "array_merge", "(", "array", "(", "\"cla...
return a form with a nested action button @param $url @param $method @param $name @param string $position @param array $attributes @return $this
[ "return", "a", "form", "with", "a", "nested", "action", "button" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/Widget.php#L215-L221
zofe/rapyd-laravel
src/DataForm/Field/Date.php
Date.format
public function format($format, $language = 'en') { $this->format = $format; $this->language = $language; return $this; }
php
public function format($format, $language = 'en') { $this->format = $format; $this->language = $language; return $this; }
[ "public", "function", "format", "(", "$", "format", ",", "$", "language", "=", "'en'", ")", "{", "$", "this", "->", "format", "=", "$", "format", ";", "$", "this", "->", "language", "=", "$", "language", ";", "return", "$", "this", ";", "}" ]
set instarnal preview date format @param $format valid php date format @param string $language valid DatePicker language string http://bootstrap-datepicker.readthedocs.org/en/release/options.html#language
[ "set", "instarnal", "preview", "date", "format" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/Field/Date.php#L28-L34
zofe/rapyd-laravel
src/DataForm/Field/Date.php
Date.isoDateToHuman
protected function isoDateToHuman($isodate) { $isodate = str_replace(" 00:00:00", "", $isodate); $datetime = \DateTime::createFromFormat( 'Y-m-d', $isodate); if (!$datetime || $isodate == '0000-00-00') return ''; $isodate = $datetime->format($this->format); return $isodate; }
php
protected function isoDateToHuman($isodate) { $isodate = str_replace(" 00:00:00", "", $isodate); $datetime = \DateTime::createFromFormat( 'Y-m-d', $isodate); if (!$datetime || $isodate == '0000-00-00') return ''; $isodate = $datetime->format($this->format); return $isodate; }
[ "protected", "function", "isoDateToHuman", "(", "$", "isodate", ")", "{", "$", "isodate", "=", "str_replace", "(", "\" 00:00:00\"", ",", "\"\"", ",", "$", "isodate", ")", ";", "$", "datetime", "=", "\\", "DateTime", "::", "createFromFormat", "(", "'Y-m-d'", ...
convert from iso date to user format fix empty value and remove H:i:s
[ "convert", "from", "iso", "date", "to", "user", "format", "fix", "empty", "value", "and", "remove", "H", ":", "i", ":", "s" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/Field/Date.php#L40-L48
zofe/rapyd-laravel
src/DataForm/Field/Date.php
Date.humanDateToIso
protected function humanDateToIso($humandate) { $datetime = \DateTime::createFromFormat( $this->format, $humandate); if (!$datetime) return null; $humandate = $datetime->format('Y-m-d'); return $humandate; }
php
protected function humanDateToIso($humandate) { $datetime = \DateTime::createFromFormat( $this->format, $humandate); if (!$datetime) return null; $humandate = $datetime->format('Y-m-d'); return $humandate; }
[ "protected", "function", "humanDateToIso", "(", "$", "humandate", ")", "{", "$", "datetime", "=", "\\", "DateTime", "::", "createFromFormat", "(", "$", "this", "->", "format", ",", "$", "humandate", ")", ";", "if", "(", "!", "$", "datetime", ")", "return...
convert from current user format to iso date
[ "convert", "from", "current", "user", "format", "to", "iso", "date" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/Field/Date.php#L53-L60
zofe/rapyd-laravel
src/DataEdit/DataEdit.php
DataEdit.sniffStatus
protected function sniffStatus() { $this->status = "idle"; ///// show ///// if ($this->url->value('show' . $this->cid)) { $this->status = "show"; $this->process_url = ""; if (!$this->find($this->url->value('show' . $this->cid))) { $this->status = "unknow_record"; } ///// modify ///// } elseif ($this->url->value('modify' . $this->cid.'|update' . $this->cid)) { $this->status = "modify"; $this->method = "patch"; $this->process_url = $this->url->replace('modify' . $this->cid, 'update' . $this->cid)->get(); if (!$this->find($this->url->value('modify' . $this->cid.'|update'. $this->cid))) { $this->status = "unknow_record"; } ///// create ///// } elseif ($this->url->value('show' . $this->cid . "|modify" . $this->cid . "|create" . $this->cid . "|delete" . $this->cid) === false) { $this->status = "create"; $this->method = "post"; $this->process_url = $this->url->append('insert' . $this->cid, 1)->get(); } elseif ($this->url->value('create' . $this->cid)) { $this->status = "create"; $this->method = "post"; $this->process_url = $this->url->replace('create' . $this->cid, 'insert' . $this->cid)->get(); ///// delete ///// } elseif ($this->url->value('delete' . $this->cid)) { $this->status = "delete"; $this->method = "delete"; $this->process_url = $this->url->replace('delete' . $this->cid, 'do_delete' . $this->cid)->get(); $this->undo_url = $this->url->replace('delete' . $this->cid, 'show' . $this->cid)->get(); if (!$this->find($this->url->value('delete' . $this->cid))) { $this->status = "unknow_record"; } } else { $this->status = "unknow_record"; } }
php
protected function sniffStatus() { $this->status = "idle"; ///// show ///// if ($this->url->value('show' . $this->cid)) { $this->status = "show"; $this->process_url = ""; if (!$this->find($this->url->value('show' . $this->cid))) { $this->status = "unknow_record"; } ///// modify ///// } elseif ($this->url->value('modify' . $this->cid.'|update' . $this->cid)) { $this->status = "modify"; $this->method = "patch"; $this->process_url = $this->url->replace('modify' . $this->cid, 'update' . $this->cid)->get(); if (!$this->find($this->url->value('modify' . $this->cid.'|update'. $this->cid))) { $this->status = "unknow_record"; } ///// create ///// } elseif ($this->url->value('show' . $this->cid . "|modify" . $this->cid . "|create" . $this->cid . "|delete" . $this->cid) === false) { $this->status = "create"; $this->method = "post"; $this->process_url = $this->url->append('insert' . $this->cid, 1)->get(); } elseif ($this->url->value('create' . $this->cid)) { $this->status = "create"; $this->method = "post"; $this->process_url = $this->url->replace('create' . $this->cid, 'insert' . $this->cid)->get(); ///// delete ///// } elseif ($this->url->value('delete' . $this->cid)) { $this->status = "delete"; $this->method = "delete"; $this->process_url = $this->url->replace('delete' . $this->cid, 'do_delete' . $this->cid)->get(); $this->undo_url = $this->url->replace('delete' . $this->cid, 'show' . $this->cid)->get(); if (!$this->find($this->url->value('delete' . $this->cid))) { $this->status = "unknow_record"; } } else { $this->status = "unknow_record"; } }
[ "protected", "function", "sniffStatus", "(", ")", "{", "$", "this", "->", "status", "=", "\"idle\"", ";", "///// show /////", "if", "(", "$", "this", "->", "url", "->", "value", "(", "'show'", ".", "$", "this", "->", "cid", ")", ")", "{", "$", "this"...
detect dataedit status by qs, if needed it find the record for show/modify/delete "status"
[ "detect", "dataedit", "status", "by", "qs", "if", "needed", "it", "find", "the", "record", "for", "show", "/", "modify", "/", "delete", "status" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataEdit/DataEdit.php#L32-L71
zofe/rapyd-laravel
src/DataEdit/DataEdit.php
DataEdit.find
protected function find($id) { $model = $this->model; $this->model = $model::find($id); if (!$this->model) { // belts and braces check - no model = doesn't exist (without being masked missing object property) // potential candidate for custom exception handling return false; } return $this->model->exists; }
php
protected function find($id) { $model = $this->model; $this->model = $model::find($id); if (!$this->model) { // belts and braces check - no model = doesn't exist (without being masked missing object property) // potential candidate for custom exception handling return false; } return $this->model->exists; }
[ "protected", "function", "find", "(", "$", "id", ")", "{", "$", "model", "=", "$", "this", "->", "model", ";", "$", "this", "->", "model", "=", "$", "model", "::", "find", "(", "$", "id", ")", ";", "if", "(", "!", "$", "this", "->", "model", ...
find a record on current model, and return bool @param $id @return bool
[ "find", "a", "record", "on", "current", "model", "and", "return", "bool" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataEdit/DataEdit.php#L78-L88
zofe/rapyd-laravel
src/DataEdit/DataEdit.php
DataEdit.sniffAction
protected function sniffAction() { ///// insert ///// if (Request::isMethod('post') && $this->url->value('insert' . $this->cid)) { $this->action = "insert"; ///// update ///// } elseif (Request::isMethod('patch') && $this->url->value('update' . $this->cid)) { $this->action = "update"; $this->process_url = $this->url->append('update', $this->url->value('update' . $this->cid))->get(); if (!$this->find($this->url->value('update' . $this->cid))) { $this->status = "unknow_record"; } ///// delete ///// } elseif (Request::isMethod('delete') && $this->url->value("do_delete" . $this->cid)) { $this->action = "delete"; if (!$this->find($this->url->value("do_delete" . $this->cid))) { $this->status = "unknow_record"; } } }
php
protected function sniffAction() { ///// insert ///// if (Request::isMethod('post') && $this->url->value('insert' . $this->cid)) { $this->action = "insert"; ///// update ///// } elseif (Request::isMethod('patch') && $this->url->value('update' . $this->cid)) { $this->action = "update"; $this->process_url = $this->url->append('update', $this->url->value('update' . $this->cid))->get(); if (!$this->find($this->url->value('update' . $this->cid))) { $this->status = "unknow_record"; } ///// delete ///// } elseif (Request::isMethod('delete') && $this->url->value("do_delete" . $this->cid)) { $this->action = "delete"; if (!$this->find($this->url->value("do_delete" . $this->cid))) { $this->status = "unknow_record"; } } }
[ "protected", "function", "sniffAction", "(", ")", "{", "///// insert /////", "if", "(", "Request", "::", "isMethod", "(", "'post'", ")", "&&", "$", "this", "->", "url", "->", "value", "(", "'insert'", ".", "$", "this", "->", "cid", ")", ")", "{", "$", ...
detect current action to execute by request method and qs if needed it find the record for update/do_delete "action"
[ "detect", "current", "action", "to", "execute", "by", "request", "method", "and", "qs", "if", "needed", "it", "find", "the", "record", "for", "update", "/", "do_delete", "action" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataEdit/DataEdit.php#L94-L114
zofe/rapyd-laravel
src/DataEdit/DataEdit.php
DataEdit.process
protected function process() { $result = parent::process(); switch ($this->action) { case "update": if ($this->on("error")) { $this->status = "modify"; } if ($this->on("success")) { $this->status = "modify"; if (in_array('update',$this->back_on)) { $this->redirect = $this->back_url; } else { $this->redirect = $this->url->replace('update' . $this->cid, 'show' . $this->cid)->get(); } } break; case "insert": if ($this->on("error")) { $this->status = "create"; } if ($this->on("success")) { $this->status = "show"; if (in_array('insert',$this->back_on)) { $this->redirect = $this->back_url; } else { $this->redirect = $this->url->remove('insert' . $this->cid)->append('show' . $this->cid, $this->model->getKey())->get(); } } break; case "delete": if ($this->on("error")) { $this->message(trans('rapyd::rapyd.err')); } if ($this->on("success")) { if (in_array('do_delete',$this->back_on)) { $this->redirect = $this->back_url; } else { $this->message(trans('rapyd::rapyd.deleted')); } } break; } switch ($this->status) { case "delete": $this->message(trans('rapyd::rapyd.conf_delete')); break; case "unknow_record": $this->message(trans('rapyd::rapyd.err_unknown')); break; } }
php
protected function process() { $result = parent::process(); switch ($this->action) { case "update": if ($this->on("error")) { $this->status = "modify"; } if ($this->on("success")) { $this->status = "modify"; if (in_array('update',$this->back_on)) { $this->redirect = $this->back_url; } else { $this->redirect = $this->url->replace('update' . $this->cid, 'show' . $this->cid)->get(); } } break; case "insert": if ($this->on("error")) { $this->status = "create"; } if ($this->on("success")) { $this->status = "show"; if (in_array('insert',$this->back_on)) { $this->redirect = $this->back_url; } else { $this->redirect = $this->url->remove('insert' . $this->cid)->append('show' . $this->cid, $this->model->getKey())->get(); } } break; case "delete": if ($this->on("error")) { $this->message(trans('rapyd::rapyd.err')); } if ($this->on("success")) { if (in_array('do_delete',$this->back_on)) { $this->redirect = $this->back_url; } else { $this->message(trans('rapyd::rapyd.deleted')); } } break; } switch ($this->status) { case "delete": $this->message(trans('rapyd::rapyd.conf_delete')); break; case "unknow_record": $this->message(trans('rapyd::rapyd.err_unknown')); break; } }
[ "protected", "function", "process", "(", ")", "{", "$", "result", "=", "parent", "::", "process", "(", ")", ";", "switch", "(", "$", "this", "->", "action", ")", "{", "case", "\"update\"", ":", "if", "(", "$", "this", "->", "on", "(", "\"error\"", ...
process works with current action/status, appended fields and model it do field validation, field auto-update, then model operations in can change current status and setup an output message @return bool|void
[ "process", "works", "with", "current", "action", "/", "status", "appended", "fields", "and", "model", "it", "do", "field", "validation", "field", "auto", "-", "update", "then", "model", "operations", "in", "can", "change", "current", "status", "and", "setup", ...
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataEdit/DataEdit.php#L122-L180
zofe/rapyd-laravel
src/DataEdit/DataEdit.php
DataEdit.back
public function back($actions='insert|update|do_delete', $url="") { if ($url == "") { if (count($this->links)) { $url = array_pop($this->links); } else { return $this; } } else { $base = str_replace(Request::path(),'',strtok(Request::fullUrl(),'?')); $match_url = str_replace($base, '/', strtok($url,'?')); if (Request::path()!= $match_url) { $url = Persistence::get($match_url); } } $this->back_on = explode("|", $actions); $this->back_url = $url; return $this; }
php
public function back($actions='insert|update|do_delete', $url="") { if ($url == "") { if (count($this->links)) { $url = array_pop($this->links); } else { return $this; } } else { $base = str_replace(Request::path(),'',strtok(Request::fullUrl(),'?')); $match_url = str_replace($base, '/', strtok($url,'?')); if (Request::path()!= $match_url) { $url = Persistence::get($match_url); } } $this->back_on = explode("|", $actions); $this->back_url = $url; return $this; }
[ "public", "function", "back", "(", "$", "actions", "=", "'insert|update|do_delete'", ",", "$", "url", "=", "\"\"", ")", "{", "if", "(", "$", "url", "==", "\"\"", ")", "{", "if", "(", "count", "(", "$", "this", "->", "links", ")", ")", "{", "$", "...
enable auto-back feature on given actions @param string $actions @param string $uri @return $this
[ "enable", "auto", "-", "back", "feature", "on", "given", "actions" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataEdit/DataEdit.php#L188-L209
zofe/rapyd-laravel
src/DataEdit/DataEdit.php
DataEdit.buildButtons
protected function buildButtons() { // load button position defaults. We could load these into an array however we would still need to provide // a failsafe check for each setting so long hand here reduces processing overall $saveButtonPosition = Config::get('rapyd.data_edit.button_position.save') != '' ? Config::get('rapyd.data_edit.button_position.save') : 'BL'; $showButtonPosition = Config::get('rapyd.data_edit.button_position.show') != '' ? Config::get('rapyd.data_edit.button_position.show') : 'TR'; $modifyButtonPosition = Config::get('rapyd.data_edit.button_position.modify') != '' ? Config::get('rapyd.data_edit.button_position.modify') : 'TR'; $undoButtonPosition = Config::get('rapyd.data_edit.button_position.undo') != '' ? Config::get('rapyd.data_edit.button_position.undo') : 'TR'; $deleteButtonPosition = Config::get('rapyd.data_edit.button_position.delete') != '' ? Config::get('rapyd.data_edit.button_position.delete') : 'BL'; //show if ($this->status == "show") { $this->link($this->url->replace('show' . $this->cid, 'modify' . $this->cid)->get(), trans('rapyd::rapyd.modify'), $showButtonPosition); } //modify if ($this->status == "modify") { if (in_array('update',$this->back_on)) { $this->link($this->back_url, trans('rapyd::rapyd.undo'), $undoButtonPosition); } else { $this->link($this->url->replace('modify' . $this->cid, 'show' . $this->cid)->replace('update' . $this->cid, 'show' . $this->cid)->get(), trans('rapyd::rapyd.undo'), $modifyButtonPosition); } $this->submit(trans('rapyd::rapyd.save'), $saveButtonPosition); } //crete if ($this->status == "create" && $this->action!= 'delete') { $this->submit(trans('rapyd::rapyd.save'), $saveButtonPosition); } //delete if ($this->status == "delete") { if (in_array('do_delete',$this->back_on)) { $this->link($this->back_url, trans('rapyd::rapyd.undo'), $undoButtonPosition); } else { $this->link($this->url->replace('delete' . $this->cid, 'show' . $this->cid)->replace('do_delete' . $this->cid, 'show' . $this->cid)->get(), trans('rapyd::rapyd.undo'), $deleteButtonPosition); } $do_delete_url = $this->url->replace('delete' . $this->cid, 'do_delete' . $this->cid)->get(); $this->formButton($do_delete_url, 'delete', trans('rapyd::rapyd.delete'), $deleteButtonPosition); } }
php
protected function buildButtons() { // load button position defaults. We could load these into an array however we would still need to provide // a failsafe check for each setting so long hand here reduces processing overall $saveButtonPosition = Config::get('rapyd.data_edit.button_position.save') != '' ? Config::get('rapyd.data_edit.button_position.save') : 'BL'; $showButtonPosition = Config::get('rapyd.data_edit.button_position.show') != '' ? Config::get('rapyd.data_edit.button_position.show') : 'TR'; $modifyButtonPosition = Config::get('rapyd.data_edit.button_position.modify') != '' ? Config::get('rapyd.data_edit.button_position.modify') : 'TR'; $undoButtonPosition = Config::get('rapyd.data_edit.button_position.undo') != '' ? Config::get('rapyd.data_edit.button_position.undo') : 'TR'; $deleteButtonPosition = Config::get('rapyd.data_edit.button_position.delete') != '' ? Config::get('rapyd.data_edit.button_position.delete') : 'BL'; //show if ($this->status == "show") { $this->link($this->url->replace('show' . $this->cid, 'modify' . $this->cid)->get(), trans('rapyd::rapyd.modify'), $showButtonPosition); } //modify if ($this->status == "modify") { if (in_array('update',$this->back_on)) { $this->link($this->back_url, trans('rapyd::rapyd.undo'), $undoButtonPosition); } else { $this->link($this->url->replace('modify' . $this->cid, 'show' . $this->cid)->replace('update' . $this->cid, 'show' . $this->cid)->get(), trans('rapyd::rapyd.undo'), $modifyButtonPosition); } $this->submit(trans('rapyd::rapyd.save'), $saveButtonPosition); } //crete if ($this->status == "create" && $this->action!= 'delete') { $this->submit(trans('rapyd::rapyd.save'), $saveButtonPosition); } //delete if ($this->status == "delete") { if (in_array('do_delete',$this->back_on)) { $this->link($this->back_url, trans('rapyd::rapyd.undo'), $undoButtonPosition); } else { $this->link($this->url->replace('delete' . $this->cid, 'show' . $this->cid)->replace('do_delete' . $this->cid, 'show' . $this->cid)->get(), trans('rapyd::rapyd.undo'), $deleteButtonPosition); } $do_delete_url = $this->url->replace('delete' . $this->cid, 'do_delete' . $this->cid)->get(); $this->formButton($do_delete_url, 'delete', trans('rapyd::rapyd.delete'), $deleteButtonPosition); } }
[ "protected", "function", "buildButtons", "(", ")", "{", "// load button position defaults. We could load these into an array however we would still need to provide", "// a failsafe check for each setting so long hand here reduces processing overall", "$", "saveButtonPosition", "=", "Config", ...
it build standard buttons depending on current status
[ "it", "build", "standard", "buttons", "depending", "on", "current", "status" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataEdit/DataEdit.php#L214-L256
zofe/rapyd-laravel
src/RapydServiceProvider.php
RapydServiceProvider.register
public function register() { $this->app->register('Collective\Html\HtmlServiceProvider'); $this->app->register('Zofe\Burp\BurpServiceProvider'); Rapyd::setContainer($this->app); $this->app->booting(function () { $loader = \Illuminate\Foundation\AliasLoader::getInstance(); $loader->alias('Input', 'Illuminate\Support\Facades\Input'); $loader->alias('Rapyd' , 'Zofe\Rapyd\Facades\Rapyd' ); //deprecated .. and more facade are really needed ? $loader->alias('DataSet' , 'Zofe\Rapyd\Facades\DataSet' ); $loader->alias('DataGrid' , 'Zofe\Rapyd\Facades\DataGrid' ); $loader->alias('DataForm' , 'Zofe\Rapyd\Facades\DataForm' ); $loader->alias('DataEdit' , 'Zofe\Rapyd\Facades\DataEdit' ); $loader->alias('DataFilter', 'Zofe\Rapyd\Facades\DataFilter'); $loader->alias('DataEmbed' , 'Zofe\Rapyd\Facades\DataEmbed'); $loader->alias('DataTree' , 'Zofe\Rapyd\Facades\DataTree'); $loader->alias('Documenter', 'Zofe\Rapyd\Facades\Documenter'); }); }
php
public function register() { $this->app->register('Collective\Html\HtmlServiceProvider'); $this->app->register('Zofe\Burp\BurpServiceProvider'); Rapyd::setContainer($this->app); $this->app->booting(function () { $loader = \Illuminate\Foundation\AliasLoader::getInstance(); $loader->alias('Input', 'Illuminate\Support\Facades\Input'); $loader->alias('Rapyd' , 'Zofe\Rapyd\Facades\Rapyd' ); //deprecated .. and more facade are really needed ? $loader->alias('DataSet' , 'Zofe\Rapyd\Facades\DataSet' ); $loader->alias('DataGrid' , 'Zofe\Rapyd\Facades\DataGrid' ); $loader->alias('DataForm' , 'Zofe\Rapyd\Facades\DataForm' ); $loader->alias('DataEdit' , 'Zofe\Rapyd\Facades\DataEdit' ); $loader->alias('DataFilter', 'Zofe\Rapyd\Facades\DataFilter'); $loader->alias('DataEmbed' , 'Zofe\Rapyd\Facades\DataEmbed'); $loader->alias('DataTree' , 'Zofe\Rapyd\Facades\DataTree'); $loader->alias('Documenter', 'Zofe\Rapyd\Facades\Documenter'); }); }
[ "public", "function", "register", "(", ")", "{", "$", "this", "->", "app", "->", "register", "(", "'Collective\\Html\\HtmlServiceProvider'", ")", ";", "$", "this", "->", "app", "->", "register", "(", "'Zofe\\Burp\\BurpServiceProvider'", ")", ";", "Rapyd", "::", ...
Register the service provider. @return void
[ "Register", "the", "service", "provider", "." ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/RapydServiceProvider.php#L47-L73
zofe/rapyd-laravel
src/DataTree/DataTree.php
DataTree.maxDepth
public function maxDepth($value = null) { if (func_num_args()) { $this->maxDepth = $value; return $this; } return $this->maxDepth; }
php
public function maxDepth($value = null) { if (func_num_args()) { $this->maxDepth = $value; return $this; } return $this->maxDepth; }
[ "public", "function", "maxDepth", "(", "$", "value", "=", "null", ")", "{", "if", "(", "func_num_args", "(", ")", ")", "{", "$", "this", "->", "maxDepth", "=", "$", "value", ";", "return", "$", "this", ";", "}", "return", "$", "this", "->", "maxDep...
Get/Set maximum depth of the tree. Nesting beyond this limit will not be allowed. Defaults to 5. @param integer $value @return $this|int
[ "Get", "/", "Set", "maximum", "depth", "of", "the", "tree", ".", "Nesting", "beyond", "this", "limit", "will", "not", "be", "allowed", "." ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataTree/DataTree.php#L343-L350
zofe/rapyd-laravel
src/DataTree/DataTree.php
DataTree.onChange
public function onChange($value = null) { if (func_num_args()) { $this->onChange = $value; return $this; } return $this->onChange; }
php
public function onChange($value = null) { if (func_num_args()) { $this->onChange = $value; return $this; } return $this->onChange; }
[ "public", "function", "onChange", "(", "$", "value", "=", "null", ")", "{", "if", "(", "func_num_args", "(", ")", ")", "{", "$", "this", "->", "onChange", "=", "$", "value", ";", "return", "$", "this", ";", "}", "return", "$", "this", "->", "onChan...
Get/Set a custom javascript string to be executed at each order change. @param string $value @return $this|string
[ "Get", "/", "Set", "a", "custom", "javascript", "string", "to", "be", "executed", "at", "each", "order", "change", "." ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataTree/DataTree.php#L358-L365
zofe/rapyd-laravel
src/DataTree/DataTree.php
DataTree.autoSave
public function autoSave($value = null) { if (func_num_args()) { $this->autoSave = $value; return $this; } return $this->autoSave; }
php
public function autoSave($value = null) { if (func_num_args()) { $this->autoSave = $value; return $this; } return $this->autoSave; }
[ "public", "function", "autoSave", "(", "$", "value", "=", "null", ")", "{", "if", "(", "func_num_args", "(", ")", ")", "{", "$", "this", "->", "autoSave", "=", "$", "value", ";", "return", "$", "this", ";", "}", "return", "$", "this", "->", "autoSa...
Enable/Disable automatic ajax-saving at each change @param null $value @return $this
[ "Enable", "/", "Disable", "automatic", "ajax", "-", "saving", "at", "each", "change" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataTree/DataTree.php#L373-L380
zofe/rapyd-laravel
src/DataTree/DataTree.php
DataTree.group
public function group($value = null) { if (func_num_args()) { $this->group = $value; return $this; } return $this->group; }
php
public function group($value = null) { if (func_num_args()) { $this->group = $value; return $this; } return $this->group; }
[ "public", "function", "group", "(", "$", "value", "=", "null", ")", "{", "if", "(", "func_num_args", "(", ")", ")", "{", "$", "this", "->", "group", "=", "$", "value", ";", "return", "$", "this", ";", "}", "return", "$", "this", "->", "group", ";...
Set the group of the DataTree. Multiple DataTrees of the same group will be able to exchange items. @param null $value @return $this|int
[ "Set", "the", "group", "of", "the", "DataTree", ".", "Multiple", "DataTrees", "of", "the", "same", "group", "will", "be", "able", "to", "exchange", "items", "." ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataTree/DataTree.php#L390-L397
zofe/rapyd-laravel
src/DataTree/DataTree.php
DataTree.name
public function name($value = null) { if (func_num_args()) { $this->name = $value; return $this; } return $this->name; }
php
public function name($value = null) { if (func_num_args()) { $this->name = $value; return $this; } return $this->name; }
[ "public", "function", "name", "(", "$", "value", "=", "null", ")", "{", "if", "(", "func_num_args", "(", ")", ")", "{", "$", "this", "->", "name", "=", "$", "value", ";", "return", "$", "this", ";", "}", "return", "$", "this", "->", "name", ";", ...
Get/Set the input name of the DataTree data. You have to change this if you display multiple datatrees in the same page. @param null $value @return $this|string
[ "Get", "/", "Set", "the", "input", "name", "of", "the", "DataTree", "data", ".", "You", "have", "to", "change", "this", "if", "you", "display", "multiple", "datatrees", "in", "the", "same", "page", "." ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataTree/DataTree.php#L406-L413
zofe/rapyd-laravel
src/DataTree/DataTree.php
DataTree.initJsWidget
public function initJsWidget() { $onChange = $this->onChange ?: ''; $ajax = $this->autoSave ? '$.post("", {"'.$this->name().'": $(this).nestable("serialize")});' : ''; $script = ' $("[data-instance-id=\\"' . $this->attributes['data-instance-id'] . '\\"]").each(function(){ var root = $(this); var form = root.find(".datatree-values"); root.find(".datatree-inner-wrapper").nestable({ listNodeName: "ol", itemNodeName: "li", rootClass: "datatree-inner-wrapper", listClass: "datatree-list", itemClass: "datatree-item", dragClass: "datatree-dragel", handleClass: "datatree-handle", collapsedClass: "datatree-collapsed", placeClass: "datatree-placeholder", noDragClass: "datatree-nodrag", emptyClass: "datatree-empty", expandBtnHTML: "<button data-action=\"expand\" type=\"button\">Expand</button>", collapseBtnHTML: "<button data-action=\"collapse\" type=\"button\">Collapse</button>", group: ' . $this->group . ', maxDepth: ' . $this->maxDepth . ', threshold: 20 }).on("mousedown", "a", function (e) { e.stopImmediatePropagation(); }).each(function () { var ol = $(this).children(".datatree-list"); if (ol.length) rapyd.datatree.updateDepth(ol); rapyd.datatree.updateForm($(this), form, "' . $this->name . '"); }).on("change", function () { var ol = $(this).children(".datatree-list"); if (ol.length) rapyd.datatree.updateDepth(ol); var updated = rapyd.datatree.updateForm($(this), form, "' . $this->name . '"); '.$ajax.' '.$onChange.' }); $(".datatree").submit(function () { var action = $(this).attr("action") || document.location.href; //return false; }); }); '; \Rapyd::script($script); }
php
public function initJsWidget() { $onChange = $this->onChange ?: ''; $ajax = $this->autoSave ? '$.post("", {"'.$this->name().'": $(this).nestable("serialize")});' : ''; $script = ' $("[data-instance-id=\\"' . $this->attributes['data-instance-id'] . '\\"]").each(function(){ var root = $(this); var form = root.find(".datatree-values"); root.find(".datatree-inner-wrapper").nestable({ listNodeName: "ol", itemNodeName: "li", rootClass: "datatree-inner-wrapper", listClass: "datatree-list", itemClass: "datatree-item", dragClass: "datatree-dragel", handleClass: "datatree-handle", collapsedClass: "datatree-collapsed", placeClass: "datatree-placeholder", noDragClass: "datatree-nodrag", emptyClass: "datatree-empty", expandBtnHTML: "<button data-action=\"expand\" type=\"button\">Expand</button>", collapseBtnHTML: "<button data-action=\"collapse\" type=\"button\">Collapse</button>", group: ' . $this->group . ', maxDepth: ' . $this->maxDepth . ', threshold: 20 }).on("mousedown", "a", function (e) { e.stopImmediatePropagation(); }).each(function () { var ol = $(this).children(".datatree-list"); if (ol.length) rapyd.datatree.updateDepth(ol); rapyd.datatree.updateForm($(this), form, "' . $this->name . '"); }).on("change", function () { var ol = $(this).children(".datatree-list"); if (ol.length) rapyd.datatree.updateDepth(ol); var updated = rapyd.datatree.updateForm($(this), form, "' . $this->name . '"); '.$ajax.' '.$onChange.' }); $(".datatree").submit(function () { var action = $(this).attr("action") || document.location.href; //return false; }); }); '; \Rapyd::script($script); }
[ "public", "function", "initJsWidget", "(", ")", "{", "$", "onChange", "=", "$", "this", "->", "onChange", "?", ":", "''", ";", "$", "ajax", "=", "$", "this", "->", "autoSave", "?", "'$.post(\"\", {\"'", ".", "$", "this", "->", "name", "(", ")", ".", ...
inline script
[ "inline", "script" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataTree/DataTree.php#L417-L465
zofe/rapyd-laravel
src/DataGrid/DataGrid.php
DataGrid.add
public function add($name, $label = null, $orderby = false) { $column = new Column($name, $label, $orderby); $this->columns[$column->name] = $column; if (!in_array($name,array("_edit"))) { $this->headers[] = $label; } if ($orderby) { $this->addOrderBy($column->orderby_field); } return $column; }
php
public function add($name, $label = null, $orderby = false) { $column = new Column($name, $label, $orderby); $this->columns[$column->name] = $column; if (!in_array($name,array("_edit"))) { $this->headers[] = $label; } if ($orderby) { $this->addOrderBy($column->orderby_field); } return $column; }
[ "public", "function", "add", "(", "$", "name", ",", "$", "label", "=", "null", ",", "$", "orderby", "=", "false", ")", "{", "$", "column", "=", "new", "Column", "(", "$", "name", ",", "$", "label", ",", "$", "orderby", ")", ";", "$", "this", "-...
@param string $name @param string $label @param bool $orderby @return Column
[ "@param", "string", "$name", "@param", "string", "$label", "@param", "bool", "$orderby" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataGrid/DataGrid.php#L29-L40
zofe/rapyd-laravel
src/DataGrid/DataGrid.php
DataGrid.build
public function build($view = '') { if ($this->output != '') return; ($view == '') and $view = 'rapyd::datagrid'; parent::build(); Persistence::save(); foreach ($this->data as $tablerow) { $row = new Row($tablerow); foreach ($this->columns as $column) { $cell = new Cell($column->name); $sanitize = (count($column->filters) || $column->cell_callable) ? false : true; $value = $this->getCellValue($column, $tablerow, $sanitize); $cell->value($value); $cell->parseFilters($column->filters); if ($column->cell_callable) { $callable = $column->cell_callable; $cell->value($callable($cell->value, $tablerow)); } $row->add($cell); } if (count($this->row_callable)) { foreach ($this->row_callable as $callable) { $callable($row); } } $this->rows[] = $row; } $this->output = \View::make($view, array('dg' => $this, 'buttons'=>$this->button_container, 'label'=>$this->label))->render(); return $this->output; }
php
public function build($view = '') { if ($this->output != '') return; ($view == '') and $view = 'rapyd::datagrid'; parent::build(); Persistence::save(); foreach ($this->data as $tablerow) { $row = new Row($tablerow); foreach ($this->columns as $column) { $cell = new Cell($column->name); $sanitize = (count($column->filters) || $column->cell_callable) ? false : true; $value = $this->getCellValue($column, $tablerow, $sanitize); $cell->value($value); $cell->parseFilters($column->filters); if ($column->cell_callable) { $callable = $column->cell_callable; $cell->value($callable($cell->value, $tablerow)); } $row->add($cell); } if (count($this->row_callable)) { foreach ($this->row_callable as $callable) { $callable($row); } } $this->rows[] = $row; } $this->output = \View::make($view, array('dg' => $this, 'buttons'=>$this->button_container, 'label'=>$this->label))->render(); return $this->output; }
[ "public", "function", "build", "(", "$", "view", "=", "''", ")", "{", "if", "(", "$", "this", "->", "output", "!=", "''", ")", "return", ";", "(", "$", "view", "==", "''", ")", "and", "$", "view", "=", "'rapyd::datagrid'", ";", "parent", "::", "b...
todo: like "field" for DataForm, should be nice to work with "cell" as instance and "row" as collection of cells
[ "todo", ":", "like", "field", "for", "DataForm", "should", "be", "nice", "to", "work", "with", "cell", "as", "instance", "and", "row", "as", "collection", "of", "cells" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataGrid/DataGrid.php#L43-L78
zofe/rapyd-laravel
src/DataForm/Field/Datetime.php
Datetime.format
public function format($format, $language = 'en', $store_as =null) { $this->format = $format; $this->language = $language; if ($store_as) { $this->store_as = $store_as; } return $this; }
php
public function format($format, $language = 'en', $store_as =null) { $this->format = $format; $this->language = $language; if ($store_as) { $this->store_as = $store_as; } return $this; }
[ "public", "function", "format", "(", "$", "format", ",", "$", "language", "=", "'en'", ",", "$", "store_as", "=", "null", ")", "{", "$", "this", "->", "format", "=", "$", "format", ";", "$", "this", "->", "language", "=", "$", "language", ";", "if"...
set instarnal preview datetime format @param $format valid php datetime format @param string $language valid datetimePicker language string http://www.malot.fr/bootstrap-datetimepicker/
[ "set", "instarnal", "preview", "datetime", "format" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/Field/Datetime.php#L30-L38
zofe/rapyd-laravel
src/DataForm/Field/Datetime.php
Datetime.isodatetimeToHuman
protected function isodatetimeToHuman($isodatetime) { $datetime = \DateTime::createFromFormat( $this->store_as, $isodatetime); if (!$datetime) return ''; $timestamp = $datetime->getTimestamp(); if ($timestamp < 1) { return ""; } $isodatetime = date($this->format, $timestamp); return $isodatetime; }
php
protected function isodatetimeToHuman($isodatetime) { $datetime = \DateTime::createFromFormat( $this->store_as, $isodatetime); if (!$datetime) return ''; $timestamp = $datetime->getTimestamp(); if ($timestamp < 1) { return ""; } $isodatetime = date($this->format, $timestamp); return $isodatetime; }
[ "protected", "function", "isodatetimeToHuman", "(", "$", "isodatetime", ")", "{", "$", "datetime", "=", "\\", "DateTime", "::", "createFromFormat", "(", "$", "this", "->", "store_as", ",", "$", "isodatetime", ")", ";", "if", "(", "!", "$", "datetime", ")",...
convert from iso datetime to user format
[ "convert", "from", "iso", "datetime", "to", "user", "format" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/Field/Datetime.php#L43-L54
zofe/rapyd-laravel
src/DataForm/Field/Datetime.php
Datetime.humandatetimeToIso
protected function humandatetimeToIso($humandatetime) { $datetime = \DateTime::createFromFormat( $this->format, $humandatetime); if (!$datetime) return ''; $timestamp = $datetime->getTimestamp(); if ($timestamp < 1) { return ""; } $humandatetime = date($this->store_as, $timestamp); return $humandatetime; }
php
protected function humandatetimeToIso($humandatetime) { $datetime = \DateTime::createFromFormat( $this->format, $humandatetime); if (!$datetime) return ''; $timestamp = $datetime->getTimestamp(); if ($timestamp < 1) { return ""; } $humandatetime = date($this->store_as, $timestamp); return $humandatetime; }
[ "protected", "function", "humandatetimeToIso", "(", "$", "humandatetime", ")", "{", "$", "datetime", "=", "\\", "DateTime", "::", "createFromFormat", "(", "$", "this", "->", "format", ",", "$", "humandatetime", ")", ";", "if", "(", "!", "$", "datetime", ")...
convert from current user format to iso datetime
[ "convert", "from", "current", "user", "format", "to", "iso", "datetime" ]
train
https://github.com/zofe/rapyd-laravel/blob/a34f02b2899092f3b0975354987d4e2a254d62d7/src/DataForm/Field/Datetime.php#L59-L70
gmars/tp5-rbac
src/model/Role.php
Role.saveRole
public function saveRole($permissionIds = '', $data = []) { if (!empty($data)) { $this->data($data); } $validate = new \gmars\rbac\validate\Role(); if (!$validate->check($this)) { throw new Exception($validate->getError()); } $data = $this->getData(); if (isset($data['id']) && !empty($data['id'])) { $this->isUpdate(true); } $this->startTrans(); $this->save(); //如果有权限的情况下 if (empty($permissionIds)) { return $this; } $permissionIdsArr = array_filter(explode(',', $permissionIds)); if (empty($permissionIdsArr)) { return $this; } //删除原有权限 $rolePermission = new RolePermission($this->connection); if ($rolePermission->where('role_id', $this->id)->delete() === false) { $this->rollback(); throw new Exception('删除原有权限时出错'); } $writeData = []; foreach ($permissionIdsArr as $v) { $writeData[] = [ 'role_id' => $this->id, 'permission_id' => $v ]; } if ($rolePermission->saveAll($writeData) === false) { $this->rollback(); throw new Exception('写入角色权限时出错'); } $this->commit(); return $this; }
php
public function saveRole($permissionIds = '', $data = []) { if (!empty($data)) { $this->data($data); } $validate = new \gmars\rbac\validate\Role(); if (!$validate->check($this)) { throw new Exception($validate->getError()); } $data = $this->getData(); if (isset($data['id']) && !empty($data['id'])) { $this->isUpdate(true); } $this->startTrans(); $this->save(); //如果有权限的情况下 if (empty($permissionIds)) { return $this; } $permissionIdsArr = array_filter(explode(',', $permissionIds)); if (empty($permissionIdsArr)) { return $this; } //删除原有权限 $rolePermission = new RolePermission($this->connection); if ($rolePermission->where('role_id', $this->id)->delete() === false) { $this->rollback(); throw new Exception('删除原有权限时出错'); } $writeData = []; foreach ($permissionIdsArr as $v) { $writeData[] = [ 'role_id' => $this->id, 'permission_id' => $v ]; } if ($rolePermission->saveAll($writeData) === false) { $this->rollback(); throw new Exception('写入角色权限时出错'); } $this->commit(); return $this; }
[ "public", "function", "saveRole", "(", "$", "permissionIds", "=", "''", ",", "$", "data", "=", "[", "]", ")", "{", "if", "(", "!", "empty", "(", "$", "data", ")", ")", "{", "$", "this", "->", "data", "(", "$", "data", ")", ";", "}", "$", "val...
编辑角色 @param string $permissionIds @param array $data @return $this @throws Exception @throws \think\exception\PDOException
[ "编辑角色" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/model/Role.php#L25-L68
gmars/tp5-rbac
src/model/Role.php
Role.delRole
public function delRole($condition) { $where = []; $relationWhere = []; if (is_array($condition)) { $where[] = ['id', 'IN', $condition]; $relationWhere[] = ['role_id', 'IN', $condition]; } else { $id = (int)$condition; if (is_numeric($id) && $id > 0) { $where[] = ['id', '=', $id]; $relationWhere[] = ['role_id', '=', $condition]; } else { throw new Exception('删除条件错误'); } } $this->startTrans(); if ($this->where($where)->delete() === false) { $this->rollback(); throw new Exception('删除角色出错'); } $rolePermission = new RolePermission($this->connection); if ($rolePermission->where($relationWhere)->delete() === false) { $this->rollback(); throw new Exception('删除角色关联权限出错'); } $this->commit(); return true; }
php
public function delRole($condition) { $where = []; $relationWhere = []; if (is_array($condition)) { $where[] = ['id', 'IN', $condition]; $relationWhere[] = ['role_id', 'IN', $condition]; } else { $id = (int)$condition; if (is_numeric($id) && $id > 0) { $where[] = ['id', '=', $id]; $relationWhere[] = ['role_id', '=', $condition]; } else { throw new Exception('删除条件错误'); } } $this->startTrans(); if ($this->where($where)->delete() === false) { $this->rollback(); throw new Exception('删除角色出错'); } $rolePermission = new RolePermission($this->connection); if ($rolePermission->where($relationWhere)->delete() === false) { $this->rollback(); throw new Exception('删除角色关联权限出错'); } $this->commit(); return true; }
[ "public", "function", "delRole", "(", "$", "condition", ")", "{", "$", "where", "=", "[", "]", ";", "$", "relationWhere", "=", "[", "]", ";", "if", "(", "is_array", "(", "$", "condition", ")", ")", "{", "$", "where", "[", "]", "=", "[", "'id'", ...
删除角色 @param $condition @return bool @throws Exception @throws \think\exception\PDOException
[ "删除角色" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/model/Role.php#L77-L105
gmars/tp5-rbac
src/model/Role.php
Role.getRole
public function getRole($condition, $withPermissionId = false) { $model = Db::name('role')->setConnection($this->getConnection()); $where = []; if (is_array($condition)) { $where = $condition; } else { $condition = (int)$condition; if (is_numeric($condition) && $condition > 0) { $role = $model->where('id', $condition)->find(); if (!empty($role) && $withPermissionId) { $role['permission_ids'] = Db::name('role_permission')->setConnection($this->getConnection()) ->where('role_id', $condition)->column('permission_id'); } return $role; } } $role = Db::name('role')->setConnection($this->getConnection()) ->where($where)->select(); if (!empty($role) && $withPermissionId) { $permission = Db::name('role_permission')->setConnection($this->getConnection()) ->where('role_id', 'IN', array_column($role, 'id'))->select(); $roleIdIndexer = []; if (!empty($permission)) { foreach ($permission as $v) { $roleIdIndexer[$v['role_id']][] = $v['permission_id']; } } foreach ($role as &$v) { $v['permission_ids'] = isset($roleIdIndexer[$v['id']])? $roleIdIndexer[$v['id']] : []; unset($v); } } return $role; }
php
public function getRole($condition, $withPermissionId = false) { $model = Db::name('role')->setConnection($this->getConnection()); $where = []; if (is_array($condition)) { $where = $condition; } else { $condition = (int)$condition; if (is_numeric($condition) && $condition > 0) { $role = $model->where('id', $condition)->find(); if (!empty($role) && $withPermissionId) { $role['permission_ids'] = Db::name('role_permission')->setConnection($this->getConnection()) ->where('role_id', $condition)->column('permission_id'); } return $role; } } $role = Db::name('role')->setConnection($this->getConnection()) ->where($where)->select(); if (!empty($role) && $withPermissionId) { $permission = Db::name('role_permission')->setConnection($this->getConnection()) ->where('role_id', 'IN', array_column($role, 'id'))->select(); $roleIdIndexer = []; if (!empty($permission)) { foreach ($permission as $v) { $roleIdIndexer[$v['role_id']][] = $v['permission_id']; } } foreach ($role as &$v) { $v['permission_ids'] = isset($roleIdIndexer[$v['id']])? $roleIdIndexer[$v['id']] : []; unset($v); } } return $role; }
[ "public", "function", "getRole", "(", "$", "condition", ",", "$", "withPermissionId", "=", "false", ")", "{", "$", "model", "=", "Db", "::", "name", "(", "'role'", ")", "->", "setConnection", "(", "$", "this", "->", "getConnection", "(", ")", ")", ";",...
获取角色列表 @param $condition @param bool $withPermissionId @return array|\PDOStatement|string|\think\Collection|\think\Model|null @throws \think\db\exception\DataNotFoundException @throws \think\db\exception\ModelNotFoundException @throws \think\exception\DbException
[ "获取角色列表" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/model/Role.php#L116-L152
gmars/tp5-rbac
src/CreateTable.php
CreateTable.create
public function create($db = '') { $dbConfig = Db::getConfig(); $prefix = $db == ''? $dbConfig['prefix'] : $dbConfig[$db]['prefix']; if (file_exists($this->_lockFile)) { echo "<b style='color:red'>数据库创建操作被锁定,请删除[{$this->_lockFile}]文件后重试</b>"; exit; } if ($this->_generateSql($prefix) === false) { echo '执行sql语句出错,请检查配置'; exit; } echo '执行成功,如非必要请不要解锁后再次执行,重复执行会清空原有rbac表中的数据'; $this->_writeLock(); exit; }
php
public function create($db = '') { $dbConfig = Db::getConfig(); $prefix = $db == ''? $dbConfig['prefix'] : $dbConfig[$db]['prefix']; if (file_exists($this->_lockFile)) { echo "<b style='color:red'>数据库创建操作被锁定,请删除[{$this->_lockFile}]文件后重试</b>"; exit; } if ($this->_generateSql($prefix) === false) { echo '执行sql语句出错,请检查配置'; exit; } echo '执行成功,如非必要请不要解锁后再次执行,重复执行会清空原有rbac表中的数据'; $this->_writeLock(); exit; }
[ "public", "function", "create", "(", "$", "db", "=", "''", ")", "{", "$", "dbConfig", "=", "Db", "::", "getConfig", "(", ")", ";", "$", "prefix", "=", "$", "db", "==", "''", "?", "$", "dbConfig", "[", "'prefix'", "]", ":", "$", "dbConfig", "[", ...
创建数据表 @param string $db
[ "创建数据表" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/CreateTable.php#L30-L47
gmars/tp5-rbac
src/CreateTable.php
CreateTable._generateSql
private function _generateSql($prefix = '') { $sql = $this->_loadSqlFile(); $prefix = empty($prefix)? '' : $prefix . '_'; $sql = str_replace('###', $prefix, $sql); $sqlArr = explode(';', $sql); if (Db::batchQuery($sqlArr) === false) { return false; } return true; }
php
private function _generateSql($prefix = '') { $sql = $this->_loadSqlFile(); $prefix = empty($prefix)? '' : $prefix . '_'; $sql = str_replace('###', $prefix, $sql); $sqlArr = explode(';', $sql); if (Db::batchQuery($sqlArr) === false) { return false; } return true; }
[ "private", "function", "_generateSql", "(", "$", "prefix", "=", "''", ")", "{", "$", "sql", "=", "$", "this", "->", "_loadSqlFile", "(", ")", ";", "$", "prefix", "=", "empty", "(", "$", "prefix", ")", "?", "''", ":", "$", "prefix", ".", "'_'", ";...
执行sql语句 @param string $prefix @return bool
[ "执行sql语句" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/CreateTable.php#L54-L64
gmars/tp5-rbac
src/CreateTable.php
CreateTable._loadSqlFile
private function _loadSqlFile() { $fileObj = fopen($this->_sqlFile, 'r'); $sql = fread($fileObj, filesize($this->_sqlFile)); fclose($fileObj); return $sql; }
php
private function _loadSqlFile() { $fileObj = fopen($this->_sqlFile, 'r'); $sql = fread($fileObj, filesize($this->_sqlFile)); fclose($fileObj); return $sql; }
[ "private", "function", "_loadSqlFile", "(", ")", "{", "$", "fileObj", "=", "fopen", "(", "$", "this", "->", "_sqlFile", ",", "'r'", ")", ";", "$", "sql", "=", "fread", "(", "$", "fileObj", ",", "filesize", "(", "$", "this", "->", "_sqlFile", ")", "...
加载sql文件 @return bool|string
[ "加载sql文件" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/CreateTable.php#L70-L76
gmars/tp5-rbac
src/CreateTable.php
CreateTable._writeLock
private function _writeLock() { $fileObj = fopen($this->_lockFile, 'w'); fwrite($fileObj, date("Y-m-d H:i:s") . '执行成功!'); fclose($fileObj); }
php
private function _writeLock() { $fileObj = fopen($this->_lockFile, 'w'); fwrite($fileObj, date("Y-m-d H:i:s") . '执行成功!'); fclose($fileObj); }
[ "private", "function", "_writeLock", "(", ")", "{", "$", "fileObj", "=", "fopen", "(", "$", "this", "->", "_lockFile", ",", "'w'", ")", ";", "fwrite", "(", "$", "fileObj", ",", "date", "(", "\"Y-m-d H:i:s\"", ")", ".", "'执行成功!');", "", "", "fclose", ...
创建数据库操作锁
[ "创建数据库操作锁" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/CreateTable.php#L81-L86
gmars/tp5-rbac
src/Rbac.php
Rbac.createPermission
public function createPermission(array $data = []) { $model = new Permission($this->db); $model->data($data); try{ $res = $model->savePermission(); return $res; } catch (Exception $e) { throw new Exception($e->getMessage()); } }
php
public function createPermission(array $data = []) { $model = new Permission($this->db); $model->data($data); try{ $res = $model->savePermission(); return $res; } catch (Exception $e) { throw new Exception($e->getMessage()); } }
[ "public", "function", "createPermission", "(", "array", "$", "data", "=", "[", "]", ")", "{", "$", "model", "=", "new", "Permission", "(", "$", "this", "->", "db", ")", ";", "$", "model", "->", "data", "(", "$", "data", ")", ";", "try", "{", "$",...
创建权限 @param array $data @return Permission @throws Exception
[ "创建权限" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/Rbac.php#L93-L103
gmars/tp5-rbac
src/Rbac.php
Rbac.editPermission
public function editPermission(array $data = [], $id = null) { if (!empty($id)) { $data['id'] = $id; } try{ return $this->createPermission($data); } catch (Exception $e) { throw new Exception($e->getMessage()); } }
php
public function editPermission(array $data = [], $id = null) { if (!empty($id)) { $data['id'] = $id; } try{ return $this->createPermission($data); } catch (Exception $e) { throw new Exception($e->getMessage()); } }
[ "public", "function", "editPermission", "(", "array", "$", "data", "=", "[", "]", ",", "$", "id", "=", "null", ")", "{", "if", "(", "!", "empty", "(", "$", "id", ")", ")", "{", "$", "data", "[", "'id'", "]", "=", "$", "id", ";", "}", "try", ...
修改权限数据(版本兼容暂时保留建议使用createPermission方法) @param array $data @param null $id @return Permission @throws Exception
[ "修改权限数据", "(", "版本兼容暂时保留建议使用createPermission方法", ")" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/Rbac.php#L112-L122
gmars/tp5-rbac
src/Rbac.php
Rbac.delPermission
public function delPermission($id = 0) { $model = new Permission($this->db); try { return $model->delPermission($id); } catch (Exception $e) { throw new Exception($e->getMessage()); } }
php
public function delPermission($id = 0) { $model = new Permission($this->db); try { return $model->delPermission($id); } catch (Exception $e) { throw new Exception($e->getMessage()); } }
[ "public", "function", "delPermission", "(", "$", "id", "=", "0", ")", "{", "$", "model", "=", "new", "Permission", "(", "$", "this", "->", "db", ")", ";", "try", "{", "return", "$", "model", "->", "delPermission", "(", "$", "id", ")", ";", "}", "...
根据主键删除权限(支持多主键用数组的方式传入) @param int $id @return bool @throws Exception
[ "根据主键删除权限", "(", "支持多主键用数组的方式传入", ")" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/Rbac.php#L130-L138
gmars/tp5-rbac
src/Rbac.php
Rbac.delPermissionBatch
public function delPermissionBatch($condition) { $model = new Permission($this->db); if ($model->where($condition)->delete() === false) { throw new Exception('批量删除数据出错'); } return true; }
php
public function delPermissionBatch($condition) { $model = new Permission($this->db); if ($model->where($condition)->delete() === false) { throw new Exception('批量删除数据出错'); } return true; }
[ "public", "function", "delPermissionBatch", "(", "$", "condition", ")", "{", "$", "model", "=", "new", "Permission", "(", "$", "this", "->", "db", ")", ";", "if", "(", "$", "model", "->", "where", "(", "$", "condition", ")", "->", "delete", "(", ")",...
根据条件删除权限条件请参考tp5 where条件的写法 @param $condition @return bool @throws Exception @throws \think\exception\PDOException
[ "根据条件删除权限条件请参考tp5", "where条件的写法" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/Rbac.php#L147-L154
gmars/tp5-rbac
src/Rbac.php
Rbac.savePermissionCategory
public function savePermissionCategory(array $data = []) { $model = new PermissionCategory($this->db); $model->data($data); try{ $res = $model->saveCategory(); return $res; } catch (Exception $e) { throw new Exception($e->getMessage()); } }
php
public function savePermissionCategory(array $data = []) { $model = new PermissionCategory($this->db); $model->data($data); try{ $res = $model->saveCategory(); return $res; } catch (Exception $e) { throw new Exception($e->getMessage()); } }
[ "public", "function", "savePermissionCategory", "(", "array", "$", "data", "=", "[", "]", ")", "{", "$", "model", "=", "new", "PermissionCategory", "(", "$", "this", "->", "db", ")", ";", "$", "model", "->", "data", "(", "$", "data", ")", ";", "try",...
编辑权限分组 @param array $data @return PermissionCategory @throws Exception
[ "编辑权限分组" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/Rbac.php#L176-L186
gmars/tp5-rbac
src/Rbac.php
Rbac.delPermissionCategory
public function delPermissionCategory($id = 0) { $model = new PermissionCategory($this->db); try { $res = $model->delCategory($id); return $res; } catch (Exception $e) { throw new Exception($e->getMessage()); } }
php
public function delPermissionCategory($id = 0) { $model = new PermissionCategory($this->db); try { $res = $model->delCategory($id); return $res; } catch (Exception $e) { throw new Exception($e->getMessage()); } }
[ "public", "function", "delPermissionCategory", "(", "$", "id", "=", "0", ")", "{", "$", "model", "=", "new", "PermissionCategory", "(", "$", "this", "->", "db", ")", ";", "try", "{", "$", "res", "=", "$", "model", "->", "delCategory", "(", "$", "id",...
根据主键删除权限分组(支持多主键用数组的方式传入) @param int $id @return bool @throws Exception
[ "根据主键删除权限分组", "(", "支持多主键用数组的方式传入", ")" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/Rbac.php#L194-L203
gmars/tp5-rbac
src/Rbac.php
Rbac.createRole
public function createRole(array $data = [], $permissionIds = '') { $model = new Role($this->db); $model->data($data); try{ $res = $model->saveRole($permissionIds); return $res; } catch (Exception $e) { throw new Exception($e->getMessage()); } }
php
public function createRole(array $data = [], $permissionIds = '') { $model = new Role($this->db); $model->data($data); try{ $res = $model->saveRole($permissionIds); return $res; } catch (Exception $e) { throw new Exception($e->getMessage()); } }
[ "public", "function", "createRole", "(", "array", "$", "data", "=", "[", "]", ",", "$", "permissionIds", "=", "''", ")", "{", "$", "model", "=", "new", "Role", "(", "$", "this", "->", "db", ")", ";", "$", "model", "->", "data", "(", "$", "data", ...
编辑角色 @param array $data @param string $permissionIds @return Role @throws Exception
[ "编辑角色" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/Rbac.php#L226-L237
gmars/tp5-rbac
src/Rbac.php
Rbac.getRole
public function getRole($condition, $withPermissionId = true) { $model = new Role($this->db); return $model->getRole($condition, $withPermissionId); }
php
public function getRole($condition, $withPermissionId = true) { $model = new Role($this->db); return $model->getRole($condition, $withPermissionId); }
[ "public", "function", "getRole", "(", "$", "condition", ",", "$", "withPermissionId", "=", "true", ")", "{", "$", "model", "=", "new", "Role", "(", "$", "this", "->", "db", ")", ";", "return", "$", "model", "->", "getRole", "(", "$", "condition", ","...
根据id或标准条件获取角色 @param $condition @param bool $withPermissionId @return array|\PDOStatement|string|\think\Collection|\think\Model|null @throws \think\db\exception\DataNotFoundException @throws \think\db\exception\ModelNotFoundException @throws \think\exception\DbException
[ "根据id或标准条件获取角色" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/Rbac.php#L248-L252
gmars/tp5-rbac
src/Rbac.php
Rbac.delUserRole
public function delUserRole($id) { if (empty($id)) { throw new Exception('参数错误'); } $model = new UserRole($this->db); if ($model->where('user_id', $id)->delete() === false) { throw new Exception('删除用户角色出错'); } return true; }
php
public function delUserRole($id) { if (empty($id)) { throw new Exception('参数错误'); } $model = new UserRole($this->db); if ($model->where('user_id', $id)->delete() === false) { throw new Exception('删除用户角色出错'); } return true; }
[ "public", "function", "delUserRole", "(", "$", "id", ")", "{", "if", "(", "empty", "(", "$", "id", ")", ")", "{", "throw", "new", "Exception", "(", "'参数错误');", "", "", "}", "$", "model", "=", "new", "UserRole", "(", "$", "this", "->", "db", ")", ...
删除用户角色 @param $id @return bool @throws Exception @throws \think\exception\PDOException
[ "删除用户角色" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/Rbac.php#L310-L320
gmars/tp5-rbac
src/Rbac.php
Rbac.cachePermission
public function cachePermission($id, $timeOut = 3600) { if (empty($id)) { throw new Exception('参数错误'); } $model = new Permission($this->db); $permission = $model->userPermission($id, $timeOut); return $permission; }
php
public function cachePermission($id, $timeOut = 3600) { if (empty($id)) { throw new Exception('参数错误'); } $model = new Permission($this->db); $permission = $model->userPermission($id, $timeOut); return $permission; }
[ "public", "function", "cachePermission", "(", "$", "id", ",", "$", "timeOut", "=", "3600", ")", "{", "if", "(", "empty", "(", "$", "id", ")", ")", "{", "throw", "new", "Exception", "(", "'参数错误');", "", "", "}", "$", "model", "=", "new", "Permission...
获取用户权限并缓存 @param $id @param int $timeOut @return array|bool|mixed|\PDOStatement|string|\think\Collection @throws Exception @throws \think\db\exception\DataNotFoundException @throws \think\db\exception\ModelNotFoundException @throws \think\exception\DbException
[ "获取用户权限并缓存" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/Rbac.php#L332-L340
gmars/tp5-rbac
src/Rbac.php
Rbac.generateToken
public function generateToken($userId, $timeOut = 7200, $prefix = '') { $token = md5($prefix . $this->randCode(32) . $this->saltToken . time()); $freshTOken = md5($prefix . $this->randCode(32) . $this->saltToken . time()); $permissionModel = new Permission($this->db); $permission = $permissionModel->getPermissionByUserId($userId); //无权限时为登录验证用 if (!empty($permission)) { $newPermission = []; if (!empty($permission)) { foreach ($permission as $k=>$v) { $newPermission[$v['path']] = $v; } } Cache::set($token, $newPermission, $timeOut); } else { //权限为空时token仅仅用作登录身份验证 Cache::set($token, '', $timeOut); } Cache::set($freshTOken, $token, $timeOut); return [ 'token' => $token, 'refresh_token' => $freshTOken, 'expire' => $timeOut ]; }
php
public function generateToken($userId, $timeOut = 7200, $prefix = '') { $token = md5($prefix . $this->randCode(32) . $this->saltToken . time()); $freshTOken = md5($prefix . $this->randCode(32) . $this->saltToken . time()); $permissionModel = new Permission($this->db); $permission = $permissionModel->getPermissionByUserId($userId); //无权限时为登录验证用 if (!empty($permission)) { $newPermission = []; if (!empty($permission)) { foreach ($permission as $k=>$v) { $newPermission[$v['path']] = $v; } } Cache::set($token, $newPermission, $timeOut); } else { //权限为空时token仅仅用作登录身份验证 Cache::set($token, '', $timeOut); } Cache::set($freshTOken, $token, $timeOut); return [ 'token' => $token, 'refresh_token' => $freshTOken, 'expire' => $timeOut ]; }
[ "public", "function", "generateToken", "(", "$", "userId", ",", "$", "timeOut", "=", "7200", ",", "$", "prefix", "=", "''", ")", "{", "$", "token", "=", "md5", "(", "$", "prefix", ".", "$", "this", "->", "randCode", "(", "32", ")", ".", "$", "thi...
生成jwt的token @param $userId @param int $timeOut @param string $prefix @return array @throws \think\db\exception\DataNotFoundException @throws \think\db\exception\ModelNotFoundException @throws \think\exception\DbException
[ "生成jwt的token" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/Rbac.php#L385-L411
gmars/tp5-rbac
src/Rbac.php
Rbac.refreshToken
public function refreshToken($refreshToken, $timeOut = 7200, $prefix = '') { $token = Cache::get($refreshToken); if (empty($token)) { throw new Exception('refresh_token已经过期'); } $permission = Cache::get($token); if (empty($permission)) { throw new Exception('token已经过期'); } $token = md5($prefix . $this->randCode(32) . $this->saltToken . time()); $freshTOken = md5($prefix . $this->randCode(32) . $this->saltToken . time()); Cache::set($token, $permission, $timeOut); Cache::set($freshTOken, $token); return [ 'token' => $token, 'refresh_token' => $freshTOken, 'expire' => $timeOut ]; }
php
public function refreshToken($refreshToken, $timeOut = 7200, $prefix = '') { $token = Cache::get($refreshToken); if (empty($token)) { throw new Exception('refresh_token已经过期'); } $permission = Cache::get($token); if (empty($permission)) { throw new Exception('token已经过期'); } $token = md5($prefix . $this->randCode(32) . $this->saltToken . time()); $freshTOken = md5($prefix . $this->randCode(32) . $this->saltToken . time()); Cache::set($token, $permission, $timeOut); Cache::set($freshTOken, $token); return [ 'token' => $token, 'refresh_token' => $freshTOken, 'expire' => $timeOut ]; }
[ "public", "function", "refreshToken", "(", "$", "refreshToken", ",", "$", "timeOut", "=", "7200", ",", "$", "prefix", "=", "''", ")", "{", "$", "token", "=", "Cache", "::", "get", "(", "$", "refreshToken", ")", ";", "if", "(", "empty", "(", "$", "t...
刷新token @param $refreshToken @param int $timeOut @param string $prefix @return array @throws Exception
[ "刷新token" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/Rbac.php#L421-L441
gmars/tp5-rbac
src/Rbac.php
Rbac.randCode
private function randCode($length = 6, $type = 'mix') { $number = '0123456789'; $seed = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $specialChar = '!@#$%^&*()_+[]|'; $randRes = ""; switch ($type) { case 'string': for ($i = 0; $i < $length; $i++) { $randomInt = rand(0, strlen($seed) - 1); $randRes .= $seed{$randomInt}; } break; case 'number': for ($i = 0; $i < $length; $i++) { $randomInt = rand(0, strlen($number) - 1); $randRes .= $number{$randomInt}; } break; case 'mix': $mix = $number . $seed; for ($i = 0; $i < $length; $i++) { $randomInt = rand(0, strlen($mix) - 1); $randRes .= $mix{$randomInt}; } break; case 'special': $special = $number . $seed . $specialChar; for ($i = 0; $i < $length; $i++) { $randomInt = rand(0, strlen($special) - 1); $randRes .= $special{$randomInt}; } break; } return $randRes; }
php
private function randCode($length = 6, $type = 'mix') { $number = '0123456789'; $seed = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $specialChar = '!@#$%^&*()_+[]|'; $randRes = ""; switch ($type) { case 'string': for ($i = 0; $i < $length; $i++) { $randomInt = rand(0, strlen($seed) - 1); $randRes .= $seed{$randomInt}; } break; case 'number': for ($i = 0; $i < $length; $i++) { $randomInt = rand(0, strlen($number) - 1); $randRes .= $number{$randomInt}; } break; case 'mix': $mix = $number . $seed; for ($i = 0; $i < $length; $i++) { $randomInt = rand(0, strlen($mix) - 1); $randRes .= $mix{$randomInt}; } break; case 'special': $special = $number . $seed . $specialChar; for ($i = 0; $i < $length; $i++) { $randomInt = rand(0, strlen($special) - 1); $randRes .= $special{$randomInt}; } break; } return $randRes; }
[ "private", "function", "randCode", "(", "$", "length", "=", "6", ",", "$", "type", "=", "'mix'", ")", "{", "$", "number", "=", "'0123456789'", ";", "$", "seed", "=", "'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'", ";", "$", "specialChar", "=", "'!@#$...
生成随机码 @param int $length @param string $type string|mix|number|special @return string
[ "生成随机码" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/Rbac.php#L449-L488
gmars/tp5-rbac
src/model/Permission.php
Permission.savePermission
public function savePermission($data = []) { if (!empty($data)) { $this->data($data); } $validate = new \gmars\rbac\validate\Permission(); if (!$validate->check($this)) { throw new Exception($validate->getError()); } $data = $this->getData(); if (isset($data['id']) && !empty($data['id'])) { $this->isUpdate(true); } $this->save(); return $this; }
php
public function savePermission($data = []) { if (!empty($data)) { $this->data($data); } $validate = new \gmars\rbac\validate\Permission(); if (!$validate->check($this)) { throw new Exception($validate->getError()); } $data = $this->getData(); if (isset($data['id']) && !empty($data['id'])) { $this->isUpdate(true); } $this->save(); return $this; }
[ "public", "function", "savePermission", "(", "$", "data", "=", "[", "]", ")", "{", "if", "(", "!", "empty", "(", "$", "data", ")", ")", "{", "$", "this", "->", "data", "(", "$", "data", ")", ";", "}", "$", "validate", "=", "new", "\\", "gmars",...
编辑权限数据 @param array $data @return $this @throws Exception
[ "编辑权限数据" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/model/Permission.php#L38-L53
gmars/tp5-rbac
src/model/Permission.php
Permission.userPermission
public function userPermission($userId, $timeOut = 3600) { if (empty($userId)) { throw new Exception('参数错误'); } $permission = Cache::get($this->_permissionCachePrefix . $userId); if (!empty($permission)) { return $permission; } $permission = $this->getPermissionByUserId($userId); if (empty($permission)) { throw new Exception('未查询到该用户的任何权限'); } $newPermission = []; if (!empty($permission)) { foreach ($permission as $k=>$v) { $newPermission[$v['path']] = $v; } } Cache::set($this->_permissionCachePrefix . $userId, $newPermission, $timeOut); Session::set('gmars_rbac_permission_name', $this->_permissionCachePrefix . $userId); return $newPermission; }
php
public function userPermission($userId, $timeOut = 3600) { if (empty($userId)) { throw new Exception('参数错误'); } $permission = Cache::get($this->_permissionCachePrefix . $userId); if (!empty($permission)) { return $permission; } $permission = $this->getPermissionByUserId($userId); if (empty($permission)) { throw new Exception('未查询到该用户的任何权限'); } $newPermission = []; if (!empty($permission)) { foreach ($permission as $k=>$v) { $newPermission[$v['path']] = $v; } } Cache::set($this->_permissionCachePrefix . $userId, $newPermission, $timeOut); Session::set('gmars_rbac_permission_name', $this->_permissionCachePrefix . $userId); return $newPermission; }
[ "public", "function", "userPermission", "(", "$", "userId", ",", "$", "timeOut", "=", "3600", ")", "{", "if", "(", "empty", "(", "$", "userId", ")", ")", "{", "throw", "new", "Exception", "(", "'参数错误');", "", "", "}", "$", "permission", "=", "Cache",...
获取用户权限 @param $userId @param int $timeOut @return array|mixed|\PDOStatement|string|\think\Collection @throws Exception @throws \think\db\exception\DataNotFoundException @throws \think\db\exception\ModelNotFoundException @throws \think\exception\DbException
[ "获取用户权限" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/model/Permission.php#L91-L114
gmars/tp5-rbac
src/model/Permission.php
Permission.getPermissionByUserId
public function getPermissionByUserId($userId) { $prefix = $this->getConfig('prefix'); $permission = Db::name('permission')->setConnection($this->getConnection())->alias('p') ->join(["{$prefix}role_permission" => 'rp'], 'p.id = rp.permission_id') ->join(["{$prefix}user_role" => 'ur'], 'rp.role_id = ur.role_id') ->where('ur.user_id', $userId)->select(); return $permission; }
php
public function getPermissionByUserId($userId) { $prefix = $this->getConfig('prefix'); $permission = Db::name('permission')->setConnection($this->getConnection())->alias('p') ->join(["{$prefix}role_permission" => 'rp'], 'p.id = rp.permission_id') ->join(["{$prefix}user_role" => 'ur'], 'rp.role_id = ur.role_id') ->where('ur.user_id', $userId)->select(); return $permission; }
[ "public", "function", "getPermissionByUserId", "(", "$", "userId", ")", "{", "$", "prefix", "=", "$", "this", "->", "getConfig", "(", "'prefix'", ")", ";", "$", "permission", "=", "Db", "::", "name", "(", "'permission'", ")", "->", "setConnection", "(", ...
根据userid获取权限 @param $userId @return array|\PDOStatement|string|\think\Collection @throws \think\db\exception\DataNotFoundException @throws \think\db\exception\ModelNotFoundException @throws \think\exception\DbException
[ "根据userid获取权限" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/model/Permission.php#L124-L132
gmars/tp5-rbac
src/model/Permission.php
Permission.getPermission
public function getPermission($condition) { $model = Db::name('permission')->setConnection($this->getConnection()); if (is_numeric($condition)) { return $model->where('id', $condition)->find(); } else { return $model->where($condition)->select(); } }
php
public function getPermission($condition) { $model = Db::name('permission')->setConnection($this->getConnection()); if (is_numeric($condition)) { return $model->where('id', $condition)->find(); } else { return $model->where($condition)->select(); } }
[ "public", "function", "getPermission", "(", "$", "condition", ")", "{", "$", "model", "=", "Db", "::", "name", "(", "'permission'", ")", "->", "setConnection", "(", "$", "this", "->", "getConnection", "(", ")", ")", ";", "if", "(", "is_numeric", "(", "...
获取权限节点 @param $condition @return array|\PDOStatement|string|\think\Collection|\think\Model|null @throws \think\db\exception\DataNotFoundException @throws \think\db\exception\ModelNotFoundException @throws \think\exception\DbException
[ "获取权限节点" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/model/Permission.php#L142-L150
gmars/tp5-rbac
src/model/PermissionCategory.php
PermissionCategory.saveCategory
public function saveCategory($data = []) { if (!empty($data)) { $this->data($data); } $validate = new \gmars\rbac\validate\PermissionCategory(); if (!$validate->check($this)) { throw new Exception($validate->getError()); } $data = $this->getData(); if (isset($data['id']) && !empty($data['id'])) { $this->isUpdate(true); } $this->save(); return $this; }
php
public function saveCategory($data = []) { if (!empty($data)) { $this->data($data); } $validate = new \gmars\rbac\validate\PermissionCategory(); if (!$validate->check($this)) { throw new Exception($validate->getError()); } $data = $this->getData(); if (isset($data['id']) && !empty($data['id'])) { $this->isUpdate(true); } $this->save(); return $this; }
[ "public", "function", "saveCategory", "(", "$", "data", "=", "[", "]", ")", "{", "if", "(", "!", "empty", "(", "$", "data", ")", ")", "{", "$", "this", "->", "data", "(", "$", "data", ")", ";", "}", "$", "validate", "=", "new", "\\", "gmars", ...
编辑权限分组 @param $data @return $this @throws Exception
[ "编辑权限分组" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/model/PermissionCategory.php#L24-L39
gmars/tp5-rbac
src/model/PermissionCategory.php
PermissionCategory.delCategory
public function delCategory($id) { $where = []; if (is_array($id)) { $where[] = ['id', 'IN', $id]; } else { $id = (int)$id; if (is_numeric($id) && $id > 0) { $where[] = ['id', '=', $id]; } else { throw new Exception('删除条件错误'); } } if ($this->where($where)->delete() === false) { throw new Exception('删除权限分组出错'); } return true; }
php
public function delCategory($id) { $where = []; if (is_array($id)) { $where[] = ['id', 'IN', $id]; } else { $id = (int)$id; if (is_numeric($id) && $id > 0) { $where[] = ['id', '=', $id]; } else { throw new Exception('删除条件错误'); } } if ($this->where($where)->delete() === false) { throw new Exception('删除权限分组出错'); } return true; }
[ "public", "function", "delCategory", "(", "$", "id", ")", "{", "$", "where", "=", "[", "]", ";", "if", "(", "is_array", "(", "$", "id", ")", ")", "{", "$", "where", "[", "]", "=", "[", "'id'", ",", "'IN'", ",", "$", "id", "]", ";", "}", "el...
删除权限分组 @param $id @return bool @throws Exception
[ "删除权限分组" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/model/PermissionCategory.php#L47-L65
gmars/tp5-rbac
src/model/PermissionCategory.php
PermissionCategory.getCategory
public function getCategory($where) { $model = Db::name('permission_category')->setConnection($this->getConnection()); if (is_numeric($where)) { return $model->where('id', $where)->find(); } else { return $model->where($where)->select(); } }
php
public function getCategory($where) { $model = Db::name('permission_category')->setConnection($this->getConnection()); if (is_numeric($where)) { return $model->where('id', $where)->find(); } else { return $model->where($where)->select(); } }
[ "public", "function", "getCategory", "(", "$", "where", ")", "{", "$", "model", "=", "Db", "::", "name", "(", "'permission_category'", ")", "->", "setConnection", "(", "$", "this", "->", "getConnection", "(", ")", ")", ";", "if", "(", "is_numeric", "(", ...
获取权限分组 @param $where @return array|\PDOStatement|string|\think\Collection|\think\Model|null @throws \think\db\exception\DataNotFoundException @throws \think\db\exception\ModelNotFoundException @throws \think\exception\DbException
[ "获取权限分组" ]
train
https://github.com/gmars/tp5-rbac/blob/907584a06d5ef62376a3cf11047030b542721258/src/model/PermissionCategory.php#L75-L83
akaunting/setting
src/Provider.php
Provider.boot
public function boot() { $this->publishes([ __DIR__ . '/Config/setting.php' => config_path('setting.php'), __DIR__ . '/Migrations/2017_08_24_000000_create_settings_table.php' => database_path('migrations/2017_08_24_000000_create_settings_table.php'), ], 'setting'); $this->app->singleton('setting.manager', function ($app) { return new Manager($app); }); $this->app->singleton('setting', function ($app) { return $app['setting.manager']->driver(); }); // Auto save setting if (config('setting.auto_save')) { $kernel = $this->app['Illuminate\Contracts\Http\Kernel']; $kernel->pushMiddleware(AutoSaveSetting::class); } // Override config if (config('setting.override')) { foreach (config('setting.override') as $config_key => $setting_key) { // handle non associative override declaration $config_key = $config_key ?: $setting_key; try { $value = setting($setting_key); if (is_null($value)) { continue; } } catch (\Exception $e) { continue; } config([$config_key => $value]); } unset($value); } // Register blade directive Blade::directive('setting', function ($expression) { return "<?php echo setting($expression); ?>"; }); }
php
public function boot() { $this->publishes([ __DIR__ . '/Config/setting.php' => config_path('setting.php'), __DIR__ . '/Migrations/2017_08_24_000000_create_settings_table.php' => database_path('migrations/2017_08_24_000000_create_settings_table.php'), ], 'setting'); $this->app->singleton('setting.manager', function ($app) { return new Manager($app); }); $this->app->singleton('setting', function ($app) { return $app['setting.manager']->driver(); }); // Auto save setting if (config('setting.auto_save')) { $kernel = $this->app['Illuminate\Contracts\Http\Kernel']; $kernel->pushMiddleware(AutoSaveSetting::class); } // Override config if (config('setting.override')) { foreach (config('setting.override') as $config_key => $setting_key) { // handle non associative override declaration $config_key = $config_key ?: $setting_key; try { $value = setting($setting_key); if (is_null($value)) { continue; } } catch (\Exception $e) { continue; } config([$config_key => $value]); } unset($value); } // Register blade directive Blade::directive('setting', function ($expression) { return "<?php echo setting($expression); ?>"; }); }
[ "public", "function", "boot", "(", ")", "{", "$", "this", "->", "publishes", "(", "[", "__DIR__", ".", "'/Config/setting.php'", "=>", "config_path", "(", "'setting.php'", ")", ",", "__DIR__", ".", "'/Migrations/2017_08_24_000000_create_settings_table.php'", "=>", "d...
Bootstrap the application services. @return void
[ "Bootstrap", "the", "application", "services", "." ]
train
https://github.com/akaunting/setting/blob/a4210fb6efb6a49f2ad8e0583ebabe8d3ee4076d/src/Provider.php#L16-L63
akaunting/setting
src/Contracts/Driver.php
Driver.get
public function get($key, $default = null) { if (!$this->checkExtraColumns()) { return false; } $this->load(); return Arr::get($this->data, $key, $default); }
php
public function get($key, $default = null) { if (!$this->checkExtraColumns()) { return false; } $this->load(); return Arr::get($this->data, $key, $default); }
[ "public", "function", "get", "(", "$", "key", ",", "$", "default", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "checkExtraColumns", "(", ")", ")", "{", "return", "false", ";", "}", "$", "this", "->", "load", "(", ")", ";", "return",...
Get a specific key from the settings data. @param string|array $key @param mixed $default Optional default value. @return mixed
[ "Get", "a", "specific", "key", "from", "the", "settings", "data", "." ]
train
https://github.com/akaunting/setting/blob/a4210fb6efb6a49f2ad8e0583ebabe8d3ee4076d/src/Contracts/Driver.php#L38-L47
akaunting/setting
src/Contracts/Driver.php
Driver.has
public function has($key) { if (!$this->checkExtraColumns()) { return false; } $this->load(); return Arr::has($this->data, $key); }
php
public function has($key) { if (!$this->checkExtraColumns()) { return false; } $this->load(); return Arr::has($this->data, $key); }
[ "public", "function", "has", "(", "$", "key", ")", "{", "if", "(", "!", "$", "this", "->", "checkExtraColumns", "(", ")", ")", "{", "return", "false", ";", "}", "$", "this", "->", "load", "(", ")", ";", "return", "Arr", "::", "has", "(", "$", "...
Determine if a key exists in the settings data. @param string $key @return bool
[ "Determine", "if", "a", "key", "exists", "in", "the", "settings", "data", "." ]
train
https://github.com/akaunting/setting/blob/a4210fb6efb6a49f2ad8e0583ebabe8d3ee4076d/src/Contracts/Driver.php#L56-L65
akaunting/setting
src/Contracts/Driver.php
Driver.set
public function set($key, $value = null) { if (!$this->checkExtraColumns()) { return; } $this->load(); $this->unsaved = true; if (is_array($key)) { foreach ($key as $k => $v) { Arr::set($this->data, $k, $v); } } else { Arr::set($this->data, $key, $value); } }
php
public function set($key, $value = null) { if (!$this->checkExtraColumns()) { return; } $this->load(); $this->unsaved = true; if (is_array($key)) { foreach ($key as $k => $v) { Arr::set($this->data, $k, $v); } } else { Arr::set($this->data, $key, $value); } }
[ "public", "function", "set", "(", "$", "key", ",", "$", "value", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "checkExtraColumns", "(", ")", ")", "{", "return", ";", "}", "$", "this", "->", "load", "(", ")", ";", "$", "this", "->",...
Set a specific key to a value in the settings data. @param string|array $key Key string or associative array of key => value @param mixed $value Optional only if the first argument is an array
[ "Set", "a", "specific", "key", "to", "a", "value", "in", "the", "settings", "data", "." ]
train
https://github.com/akaunting/setting/blob/a4210fb6efb6a49f2ad8e0583ebabe8d3ee4076d/src/Contracts/Driver.php#L73-L89
akaunting/setting
src/Contracts/Driver.php
Driver.forget
public function forget($key) { if (!$this->checkExtraColumns()) { return; } $this->unsaved = true; if ($this->has($key)) { Arr::forget($this->data, $key); } }
php
public function forget($key) { if (!$this->checkExtraColumns()) { return; } $this->unsaved = true; if ($this->has($key)) { Arr::forget($this->data, $key); } }
[ "public", "function", "forget", "(", "$", "key", ")", "{", "if", "(", "!", "$", "this", "->", "checkExtraColumns", "(", ")", ")", "{", "return", ";", "}", "$", "this", "->", "unsaved", "=", "true", ";", "if", "(", "$", "this", "->", "has", "(", ...
Unset a key in the settings data. @param string $key
[ "Unset", "a", "key", "in", "the", "settings", "data", "." ]
train
https://github.com/akaunting/setting/blob/a4210fb6efb6a49f2ad8e0583ebabe8d3ee4076d/src/Contracts/Driver.php#L96-L107
akaunting/setting
src/Contracts/Driver.php
Driver.load
public function load($force = false) { if (!$this->checkExtraColumns()) { return; } if ($this->loaded && !$force) { return; } $this->data = $this->read(); $this->loaded = true; }
php
public function load($force = false) { if (!$this->checkExtraColumns()) { return; } if ($this->loaded && !$force) { return; } $this->data = $this->read(); $this->loaded = true; }
[ "public", "function", "load", "(", "$", "force", "=", "false", ")", "{", "if", "(", "!", "$", "this", "->", "checkExtraColumns", "(", ")", ")", "{", "return", ";", "}", "if", "(", "$", "this", "->", "loaded", "&&", "!", "$", "force", ")", "{", ...
Make sure data is loaded. @param $force Force a reload of data. Default false.
[ "Make", "sure", "data", "is", "loaded", "." ]
train
https://github.com/akaunting/setting/blob/a4210fb6efb6a49f2ad8e0583ebabe8d3ee4076d/src/Contracts/Driver.php#L166-L178
akaunting/setting
src/Middleware/AutoSaveSetting.php
AutoSaveSetting.handle
public function handle($request, Closure $next) { $response = $next($request); $this->setting->save(); return $response; }
php
public function handle($request, Closure $next) { $response = $next($request); $this->setting->save(); return $response; }
[ "public", "function", "handle", "(", "$", "request", ",", "Closure", "$", "next", ")", "{", "$", "response", "=", "$", "next", "(", "$", "request", ")", ";", "$", "this", "->", "setting", "->", "save", "(", ")", ";", "return", "$", "response", ";",...
Handle an incoming request. @param \Illuminate\Http\Request $request @param \Closure $next @return mixed
[ "Handle", "an", "incoming", "request", "." ]
train
https://github.com/akaunting/setting/blob/a4210fb6efb6a49f2ad8e0583ebabe8d3ee4076d/src/Middleware/AutoSaveSetting.php#L25-L32
akaunting/setting
src/Support/Arr.php
Arr.set
public static function set(array &$data, $key, $value) { $segments = explode('.', $key); $key = array_pop($segments); // iterate through all of $segments except the last one foreach ($segments as $segment) { if (!array_key_exists($segment, $data)) { $data[$segment] = array(); } elseif (!is_array($data[$segment])) { throw new \UnexpectedValueException('Non-array segment encountered'); } $data = &$data[$segment]; } $data[$key] = $value; }
php
public static function set(array &$data, $key, $value) { $segments = explode('.', $key); $key = array_pop($segments); // iterate through all of $segments except the last one foreach ($segments as $segment) { if (!array_key_exists($segment, $data)) { $data[$segment] = array(); } elseif (!is_array($data[$segment])) { throw new \UnexpectedValueException('Non-array segment encountered'); } $data = &$data[$segment]; } $data[$key] = $value; }
[ "public", "static", "function", "set", "(", "array", "&", "$", "data", ",", "$", "key", ",", "$", "value", ")", "{", "$", "segments", "=", "explode", "(", "'.'", ",", "$", "key", ")", ";", "$", "key", "=", "array_pop", "(", "$", "segments", ")", ...
Set an element of an array. @param array $data @param string $key Specify a nested element by separating keys with full stops. @param mixed $value
[ "Set", "an", "element", "of", "an", "array", "." ]
train
https://github.com/akaunting/setting/blob/a4210fb6efb6a49f2ad8e0583ebabe8d3ee4076d/src/Support/Arr.php#L92-L110
akaunting/setting
src/Migrations/2017_08_24_000000_create_settings_table.php
CreateSettingsTable.up
public function up() { Schema::create($this->table, function (Blueprint $table) { $table->increments('id'); $table->string($this->key)->index(); $table->text($this->value); }); }
php
public function up() { Schema::create($this->table, function (Blueprint $table) { $table->increments('id'); $table->string($this->key)->index(); $table->text($this->value); }); }
[ "public", "function", "up", "(", ")", "{", "Schema", "::", "create", "(", "$", "this", "->", "table", ",", "function", "(", "Blueprint", "$", "table", ")", "{", "$", "table", "->", "increments", "(", "'id'", ")", ";", "$", "table", "->", "string", ...
Run the migrations. @return void
[ "Run", "the", "migrations", "." ]
train
https://github.com/akaunting/setting/blob/a4210fb6efb6a49f2ad8e0583ebabe8d3ee4076d/src/Migrations/2017_08_24_000000_create_settings_table.php#L23-L30
punkstar/mageconfigsync
src/MageConfigSync/Magento/ConfigurationAdapter.php
ConfigurationAdapter.deleteValue
public function deleteValue($path, $scope, $scope_id) { $write = $this->_magento->getDatabaseWriteConnection(); return $write->delete( $this->_table_name, array( 'scope = ?' => $scope, 'scope_id = ?' => $scope_id, 'path = ?' => $path ) ); }
php
public function deleteValue($path, $scope, $scope_id) { $write = $this->_magento->getDatabaseWriteConnection(); return $write->delete( $this->_table_name, array( 'scope = ?' => $scope, 'scope_id = ?' => $scope_id, 'path = ?' => $path ) ); }
[ "public", "function", "deleteValue", "(", "$", "path", ",", "$", "scope", ",", "$", "scope_id", ")", "{", "$", "write", "=", "$", "this", "->", "_magento", "->", "getDatabaseWriteConnection", "(", ")", ";", "return", "$", "write", "->", "delete", "(", ...
@param $path @param $scope @param $scope_id @return int Number of affected rows
[ "@param", "$path", "@param", "$scope", "@param", "$scope_id" ]
train
https://github.com/punkstar/mageconfigsync/blob/f1ef312c3c68d5bd4b4d8a30b895e9373a4138d2/src/MageConfigSync/Magento/ConfigurationAdapter.php#L53-L64
punkstar/mageconfigsync
src/MageConfigSync/Magento.php
Magento.findMagentoRootDir
public function findMagentoRootDir($start_directory) { $ds = DIRECTORY_SEPARATOR; $directory_tree = explode($ds, $start_directory); while (count($directory_tree) > 0) { $current_directory = join($ds, $directory_tree); $current_search_location = join($ds, array_merge($directory_tree, array('app', 'Mage.php'))); if (file_exists($current_search_location)) { return $current_directory; } array_pop($directory_tree); } throw new \Exception("Unable to locate Magento root"); }
php
public function findMagentoRootDir($start_directory) { $ds = DIRECTORY_SEPARATOR; $directory_tree = explode($ds, $start_directory); while (count($directory_tree) > 0) { $current_directory = join($ds, $directory_tree); $current_search_location = join($ds, array_merge($directory_tree, array('app', 'Mage.php'))); if (file_exists($current_search_location)) { return $current_directory; } array_pop($directory_tree); } throw new \Exception("Unable to locate Magento root"); }
[ "public", "function", "findMagentoRootDir", "(", "$", "start_directory", ")", "{", "$", "ds", "=", "DIRECTORY_SEPARATOR", ";", "$", "directory_tree", "=", "explode", "(", "$", "ds", ",", "$", "start_directory", ")", ";", "while", "(", "count", "(", "$", "d...
Given a start directory, work upwards and attempt to identify the Magento root directory. Throws an exception if it can't be found. @param string $start_directory @return string @throws \Exception
[ "Given", "a", "start", "directory", "work", "upwards", "and", "attempt", "to", "identify", "the", "Magento", "root", "directory", ".", "Throws", "an", "exception", "if", "it", "can", "t", "be", "found", "." ]
train
https://github.com/punkstar/mageconfigsync/blob/f1ef312c3c68d5bd4b4d8a30b895e9373a4138d2/src/MageConfigSync/Magento.php#L66-L83
punkstar/mageconfigsync
src/MageConfigSync/Util/ArrayUtil.php
ArrayUtil.diffAssocRecursive
public static function diffAssocRecursive($array1, $array2) { $difference = array(); foreach ($array1 as $key => $value) { if (is_array($value)) { if (!isset($array2[$key]) || !is_array($array2[$key])) { $difference[$key] = $value; } else { $new_diff = self::diffAssocRecursive($value, $array2[$key]); if (!empty($new_diff)) { $difference[$key] = $new_diff; } } } elseif (!array_key_exists($key, $array2) || $array2[$key] !== $value) { $difference[$key] = $value; } } return $difference; }
php
public static function diffAssocRecursive($array1, $array2) { $difference = array(); foreach ($array1 as $key => $value) { if (is_array($value)) { if (!isset($array2[$key]) || !is_array($array2[$key])) { $difference[$key] = $value; } else { $new_diff = self::diffAssocRecursive($value, $array2[$key]); if (!empty($new_diff)) { $difference[$key] = $new_diff; } } } elseif (!array_key_exists($key, $array2) || $array2[$key] !== $value) { $difference[$key] = $value; } } return $difference; }
[ "public", "static", "function", "diffAssocRecursive", "(", "$", "array1", ",", "$", "array2", ")", "{", "$", "difference", "=", "array", "(", ")", ";", "foreach", "(", "$", "array1", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_arra...
http://www.php.net/manual/en/function.array-diff-assoc.php#111675 @param $array1 @param $array2 @return array
[ "http", ":", "//", "www", ".", "php", ".", "net", "/", "manual", "/", "en", "/", "function", ".", "array", "-", "diff", "-", "assoc", ".", "php#111675" ]
train
https://github.com/punkstar/mageconfigsync/blob/f1ef312c3c68d5bd4b4d8a30b895e9373a4138d2/src/MageConfigSync/Util/ArrayUtil.php#L13-L33
graphp/graphviz
src/GraphViz.php
GraphViz.display
public function display(Graph $graph) { // echo "Generate picture ..."; $tmp = $this->createImageFile($graph); static $next = 0; if ($next > microtime(true)) { // wait some time between calling xdg-open because earlier calls will be ignored otherwise //echo '[delay flooding xdg-open]' . PHP_EOL; sleep(self::DELAY_OPEN); } if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { // open image in untitled, temporary background shell exec('start "" ' . escapeshellarg($tmp) . ' >NUL'); } elseif (strtoupper(PHP_OS) === 'DARWIN') { // open image in background (redirect stdout to /dev/null, sterr to stdout and run in background) exec('open ' . escapeshellarg($tmp) . ' > /dev/null 2>&1 &'); } else { // open image in background (redirect stdout to /dev/null, sterr to stdout and run in background) exec('xdg-open ' . escapeshellarg($tmp) . ' > /dev/null 2>&1 &'); } $next = microtime(true) + self::DELAY_OPEN; // echo "... done\n"; }
php
public function display(Graph $graph) { // echo "Generate picture ..."; $tmp = $this->createImageFile($graph); static $next = 0; if ($next > microtime(true)) { // wait some time between calling xdg-open because earlier calls will be ignored otherwise //echo '[delay flooding xdg-open]' . PHP_EOL; sleep(self::DELAY_OPEN); } if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { // open image in untitled, temporary background shell exec('start "" ' . escapeshellarg($tmp) . ' >NUL'); } elseif (strtoupper(PHP_OS) === 'DARWIN') { // open image in background (redirect stdout to /dev/null, sterr to stdout and run in background) exec('open ' . escapeshellarg($tmp) . ' > /dev/null 2>&1 &'); } else { // open image in background (redirect stdout to /dev/null, sterr to stdout and run in background) exec('xdg-open ' . escapeshellarg($tmp) . ' > /dev/null 2>&1 &'); } $next = microtime(true) + self::DELAY_OPEN; // echo "... done\n"; }
[ "public", "function", "display", "(", "Graph", "$", "graph", ")", "{", "// echo \"Generate picture ...\";", "$", "tmp", "=", "$", "this", "->", "createImageFile", "(", "$", "graph", ")", ";", "static", "$", "next", "=", "0", ";", "if", "(", "$", "next", ...
create and display image for this graph @param Graph $graph graph to display @return void @uses GraphViz::createImageFile()
[ "create", "and", "display", "image", "for", "this", "graph" ]
train
https://github.com/graphp/graphviz/blob/80e5b2639411b8a709c8eebf294eec0c495a01bb/src/GraphViz.php#L105-L130
graphp/graphviz
src/GraphViz.php
GraphViz.createImageData
public function createImageData(Graph $graph) { $file = $this->createImageFile($graph); $data = file_get_contents($file); unlink($file); return $data; }
php
public function createImageData(Graph $graph) { $file = $this->createImageFile($graph); $data = file_get_contents($file); unlink($file); return $data; }
[ "public", "function", "createImageData", "(", "Graph", "$", "graph", ")", "{", "$", "file", "=", "$", "this", "->", "createImageFile", "(", "$", "graph", ")", ";", "$", "data", "=", "file_get_contents", "(", "$", "file", ")", ";", "unlink", "(", "$", ...
create image file data contents for this graph @param Graph $graph graph to display @return string @uses GraphViz::createImageFile()
[ "create", "image", "file", "data", "contents", "for", "this", "graph" ]
train
https://github.com/graphp/graphviz/blob/80e5b2639411b8a709c8eebf294eec0c495a01bb/src/GraphViz.php#L139-L146
graphp/graphviz
src/GraphViz.php
GraphViz.createImageSrc
public function createImageSrc(Graph $graph) { $format = $this->format; if ($this->format === 'svg' || $this->format === 'svgz') { $format = 'svg+xml;charset=' . $graph->getAttribute('graphviz.graph.charset', 'UTF-8'); } return 'data:image/' . $format . ';base64,' . base64_encode($this->createImageData($graph)); }
php
public function createImageSrc(Graph $graph) { $format = $this->format; if ($this->format === 'svg' || $this->format === 'svgz') { $format = 'svg+xml;charset=' . $graph->getAttribute('graphviz.graph.charset', 'UTF-8'); } return 'data:image/' . $format . ';base64,' . base64_encode($this->createImageData($graph)); }
[ "public", "function", "createImageSrc", "(", "Graph", "$", "graph", ")", "{", "$", "format", "=", "$", "this", "->", "format", ";", "if", "(", "$", "this", "->", "format", "===", "'svg'", "||", "$", "this", "->", "format", "===", "'svgz'", ")", "{", ...
create base64-encoded image src target data to be used for html images @param Graph $graph graph to display @return string @uses GraphViz::createImageData()
[ "create", "base64", "-", "encoded", "image", "src", "target", "data", "to", "be", "used", "for", "html", "images" ]
train
https://github.com/graphp/graphviz/blob/80e5b2639411b8a709c8eebf294eec0c495a01bb/src/GraphViz.php#L155-L163
graphp/graphviz
src/GraphViz.php
GraphViz.createImageHtml
public function createImageHtml(Graph $graph) { if ($this->format === 'svg' || $this->format === 'svgz') { return '<object type="image/svg+xml" data="' . $this->createImageSrc($graph) . '"></object>'; } return '<img src="' . $this->createImageSrc($graph) . '" />'; }
php
public function createImageHtml(Graph $graph) { if ($this->format === 'svg' || $this->format === 'svgz') { return '<object type="image/svg+xml" data="' . $this->createImageSrc($graph) . '"></object>'; } return '<img src="' . $this->createImageSrc($graph) . '" />'; }
[ "public", "function", "createImageHtml", "(", "Graph", "$", "graph", ")", "{", "if", "(", "$", "this", "->", "format", "===", "'svg'", "||", "$", "this", "->", "format", "===", "'svgz'", ")", "{", "return", "'<object type=\"image/svg+xml\" data=\"'", ".", "$...
create image html code for this graph @param Graph $graph graph to display @return string @uses GraphViz::createImageSrc()
[ "create", "image", "html", "code", "for", "this", "graph" ]
train
https://github.com/graphp/graphviz/blob/80e5b2639411b8a709c8eebf294eec0c495a01bb/src/GraphViz.php#L172-L179
graphp/graphviz
src/GraphViz.php
GraphViz.createImageFile
public function createImageFile(Graph $graph) { $script = $this->createScript($graph); // var_dump($script); $tmp = tempnam(sys_get_temp_dir(), 'graphviz'); if ($tmp === false) { throw new UnexpectedValueException('Unable to get temporary file name for graphviz script'); } $ret = file_put_contents($tmp, $script, LOCK_EX); if ($ret === false) { throw new UnexpectedValueException('Unable to write graphviz script to temporary file'); } $ret = 0; $executable = $this->getExecutable(); system(escapeshellarg($executable) . ' -T ' . escapeshellarg($this->format) . ' ' . escapeshellarg($tmp) . ' -o ' . escapeshellarg($tmp . '.' . $this->format), $ret); if ($ret !== 0) { throw new UnexpectedValueException('Unable to invoke "' . $executable .'" to create image file (code ' . $ret . ')'); } unlink($tmp); return $tmp . '.' . $this->format; }
php
public function createImageFile(Graph $graph) { $script = $this->createScript($graph); // var_dump($script); $tmp = tempnam(sys_get_temp_dir(), 'graphviz'); if ($tmp === false) { throw new UnexpectedValueException('Unable to get temporary file name for graphviz script'); } $ret = file_put_contents($tmp, $script, LOCK_EX); if ($ret === false) { throw new UnexpectedValueException('Unable to write graphviz script to temporary file'); } $ret = 0; $executable = $this->getExecutable(); system(escapeshellarg($executable) . ' -T ' . escapeshellarg($this->format) . ' ' . escapeshellarg($tmp) . ' -o ' . escapeshellarg($tmp . '.' . $this->format), $ret); if ($ret !== 0) { throw new UnexpectedValueException('Unable to invoke "' . $executable .'" to create image file (code ' . $ret . ')'); } unlink($tmp); return $tmp . '.' . $this->format; }
[ "public", "function", "createImageFile", "(", "Graph", "$", "graph", ")", "{", "$", "script", "=", "$", "this", "->", "createScript", "(", "$", "graph", ")", ";", "// var_dump($script);", "$", "tmp", "=", "tempnam", "(", "sys_get_temp_dir", "(", ")", ",", ...
create image file for this graph @param Graph $graph graph to display @return string filename @throws UnexpectedValueException on error @uses GraphViz::createScript()
[ "create", "image", "file", "for", "this", "graph" ]
train
https://github.com/graphp/graphviz/blob/80e5b2639411b8a709c8eebf294eec0c495a01bb/src/GraphViz.php#L189-L215
graphp/graphviz
src/GraphViz.php
GraphViz.createScript
public function createScript(Graph $graph) { $alg = new Directed($graph); $directed = $alg->hasDirected(); /* * The website [http://www.graphviz.org/content/dot-language] uses the term `ID` when displaying * the abstract grammar for the DOT language. * But the man pages for dot use the term `name` when describing the graph file language. */ $name = $graph->getAttribute('graphviz.name'); if ($name !== null) { $name = $this->escapeId($name) . ' '; } $script = ($directed ? 'di':'') . 'graph ' . $name . '{' . self::EOL; // add global attributes $globals = array( 'graph' => 'graphviz.graph.', 'node' => 'graphviz.node.', 'edge' => 'graphviz.edge.', ); foreach ($globals as $key => $prefix) { $bag = new AttributeBagNamespaced($graph, $prefix); if ($layout = $bag->getAttributes()) { $script .= $this->formatIndent . $key . ' ' . $this->escapeAttributes($layout) . self::EOL; } } $alg = new Groups($graph); // only append group number to vertex label if there are at least 2 different groups $showGroups = ($alg->getNumberOfGroups() > 1); if ($showGroups) { $gid = 0; $indent = str_repeat($this->formatIndent, 2); // put each group of vertices in a separate subgraph cluster foreach ($alg->getGroups() as $group) { $script .= $this->formatIndent . 'subgraph cluster_' . $gid++ . ' {' . self::EOL . $indent . 'label = ' . $this->escape($group) . self::EOL; foreach($alg->getVerticesGroup($group)->getMap() as $vid => $vertex) { $layout = $this->getLayoutVertex($vertex); $script .= $indent . $this->escapeId($vid); if($layout){ $script .= ' ' . $this->escapeAttributes($layout); } $script .= self::EOL; } $script .= ' }' . self::EOL; } } else { $alg = new Degree($graph); // explicitly add all isolated vertices (vertices with no edges) and vertices with special layout set // other vertices wil be added automatically due to below edge definitions foreach ($graph->getVertices()->getMap() as $vid => $vertex){ $layout = $this->getLayoutVertex($vertex); if($layout || $alg->isVertexIsolated($vertex)){ $script .= $this->formatIndent . $this->escapeId($vid); if($layout){ $script .= ' ' . $this->escapeAttributes($layout); } $script .= self::EOL; } } } $edgeop = $directed ? ' -> ' : ' -- '; // add all edges as directed edges foreach ($graph->getEdges() as $currentEdge) { $both = $currentEdge->getVertices()->getVector(); $currentStartVertex = $both[0]; $currentTargetVertex = $both[1]; $script .= $this->formatIndent . $this->escapeId($currentStartVertex->getId()) . $edgeop . $this->escapeId($currentTargetVertex->getId()); $layout = $this->getLayoutEdge($currentEdge); // this edge also points to the opposite direction => this is actually an undirected edge if ($directed && $currentEdge->isConnection($currentTargetVertex, $currentStartVertex)) { $layout['dir'] = 'none'; } if ($layout) { $script .= ' ' . $this->escapeAttributes($layout); } $script .= self::EOL; } $script .= '}' . self::EOL; return $script; }
php
public function createScript(Graph $graph) { $alg = new Directed($graph); $directed = $alg->hasDirected(); /* * The website [http://www.graphviz.org/content/dot-language] uses the term `ID` when displaying * the abstract grammar for the DOT language. * But the man pages for dot use the term `name` when describing the graph file language. */ $name = $graph->getAttribute('graphviz.name'); if ($name !== null) { $name = $this->escapeId($name) . ' '; } $script = ($directed ? 'di':'') . 'graph ' . $name . '{' . self::EOL; // add global attributes $globals = array( 'graph' => 'graphviz.graph.', 'node' => 'graphviz.node.', 'edge' => 'graphviz.edge.', ); foreach ($globals as $key => $prefix) { $bag = new AttributeBagNamespaced($graph, $prefix); if ($layout = $bag->getAttributes()) { $script .= $this->formatIndent . $key . ' ' . $this->escapeAttributes($layout) . self::EOL; } } $alg = new Groups($graph); // only append group number to vertex label if there are at least 2 different groups $showGroups = ($alg->getNumberOfGroups() > 1); if ($showGroups) { $gid = 0; $indent = str_repeat($this->formatIndent, 2); // put each group of vertices in a separate subgraph cluster foreach ($alg->getGroups() as $group) { $script .= $this->formatIndent . 'subgraph cluster_' . $gid++ . ' {' . self::EOL . $indent . 'label = ' . $this->escape($group) . self::EOL; foreach($alg->getVerticesGroup($group)->getMap() as $vid => $vertex) { $layout = $this->getLayoutVertex($vertex); $script .= $indent . $this->escapeId($vid); if($layout){ $script .= ' ' . $this->escapeAttributes($layout); } $script .= self::EOL; } $script .= ' }' . self::EOL; } } else { $alg = new Degree($graph); // explicitly add all isolated vertices (vertices with no edges) and vertices with special layout set // other vertices wil be added automatically due to below edge definitions foreach ($graph->getVertices()->getMap() as $vid => $vertex){ $layout = $this->getLayoutVertex($vertex); if($layout || $alg->isVertexIsolated($vertex)){ $script .= $this->formatIndent . $this->escapeId($vid); if($layout){ $script .= ' ' . $this->escapeAttributes($layout); } $script .= self::EOL; } } } $edgeop = $directed ? ' -> ' : ' -- '; // add all edges as directed edges foreach ($graph->getEdges() as $currentEdge) { $both = $currentEdge->getVertices()->getVector(); $currentStartVertex = $both[0]; $currentTargetVertex = $both[1]; $script .= $this->formatIndent . $this->escapeId($currentStartVertex->getId()) . $edgeop . $this->escapeId($currentTargetVertex->getId()); $layout = $this->getLayoutEdge($currentEdge); // this edge also points to the opposite direction => this is actually an undirected edge if ($directed && $currentEdge->isConnection($currentTargetVertex, $currentStartVertex)) { $layout['dir'] = 'none'; } if ($layout) { $script .= ' ' . $this->escapeAttributes($layout); } $script .= self::EOL; } $script .= '}' . self::EOL; return $script; }
[ "public", "function", "createScript", "(", "Graph", "$", "graph", ")", "{", "$", "alg", "=", "new", "Directed", "(", "$", "graph", ")", ";", "$", "directed", "=", "$", "alg", "->", "hasDirected", "(", ")", ";", "/*\n * The website [http://www.graphvi...
create graphviz script representing this graph @param Graph $graph graph to display @return string @uses Directed::hasDirected() @uses Graph::getVertices() @uses Graph::getEdges()
[ "create", "graphviz", "script", "representing", "this", "graph" ]
train
https://github.com/graphp/graphviz/blob/80e5b2639411b8a709c8eebf294eec0c495a01bb/src/GraphViz.php#L226-L323
graphp/graphviz
src/GraphViz.php
GraphViz.escapeAttributes
private function escapeAttributes($attrs) { $script = '['; $first = true; foreach ($attrs as $name => $value) { if ($first) { $first = false; } else { $script .= ' '; } $script .= $name . '=' . self::escape($value); } $script .= ']'; return $script; }
php
private function escapeAttributes($attrs) { $script = '['; $first = true; foreach ($attrs as $name => $value) { if ($first) { $first = false; } else { $script .= ' '; } $script .= $name . '=' . self::escape($value); } $script .= ']'; return $script; }
[ "private", "function", "escapeAttributes", "(", "$", "attrs", ")", "{", "$", "script", "=", "'['", ";", "$", "first", "=", "true", ";", "foreach", "(", "$", "attrs", "as", "$", "name", "=>", "$", "value", ")", "{", "if", "(", "$", "first", ")", "...
get escaped attribute string for given array of (unescaped) attributes @param array $attrs @return string @uses GraphViz::escapeId()
[ "get", "escaped", "attribute", "string", "for", "given", "array", "of", "(", "unescaped", ")", "attributes" ]
train
https://github.com/graphp/graphviz/blob/80e5b2639411b8a709c8eebf294eec0c495a01bb/src/GraphViz.php#L359-L374
llaville/php-reflect
src/Bartlett/Reflect/Analyser/AnalyserManager.php
AnalyserManager.registerAnalysers
public function registerAnalysers() { $jsonFile = Environment::getJsonConfigFilename(); if (!$jsonFile) { return; } $config = new Config; $var = $config->validate($jsonFile); foreach ($var['analysers'] as $analyser) { if (class_exists($analyser['class'])) { $analyser = new $analyser['class']; if ($analyser instanceof AnalyserInterface) { $this->addAnalyser($analyser); } } } }
php
public function registerAnalysers() { $jsonFile = Environment::getJsonConfigFilename(); if (!$jsonFile) { return; } $config = new Config; $var = $config->validate($jsonFile); foreach ($var['analysers'] as $analyser) { if (class_exists($analyser['class'])) { $analyser = new $analyser['class']; if ($analyser instanceof AnalyserInterface) { $this->addAnalyser($analyser); } } } }
[ "public", "function", "registerAnalysers", "(", ")", "{", "$", "jsonFile", "=", "Environment", "::", "getJsonConfigFilename", "(", ")", ";", "if", "(", "!", "$", "jsonFile", ")", "{", "return", ";", "}", "$", "config", "=", "new", "Config", ";", "$", "...
Loads all analysers declared in the JSON config file. @return void
[ "Loads", "all", "analysers", "declared", "in", "the", "JSON", "config", "file", "." ]
train
https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Analyser/AnalyserManager.php#L77-L96
llaville/php-reflect
src/Bartlett/Reflect/Api/BaseApi.php
BaseApi.request
protected function request($url, $method = 'GET', array $params = array()) { $this->client->setEventDispatcher($this->getEventDispatcher()); $this->client->activatePlugins($this->registerPlugins); $response = $this->client->request($method, $url, $params); return $response; }
php
protected function request($url, $method = 'GET', array $params = array()) { $this->client->setEventDispatcher($this->getEventDispatcher()); $this->client->activatePlugins($this->registerPlugins); $response = $this->client->request($method, $url, $params); return $response; }
[ "protected", "function", "request", "(", "$", "url", ",", "$", "method", "=", "'GET'", ",", "array", "$", "params", "=", "array", "(", ")", ")", "{", "$", "this", "->", "client", "->", "setEventDispatcher", "(", "$", "this", "->", "getEventDispatcher", ...
Performs the request @param string $url @param string $method @param array $params
[ "Performs", "the", "request" ]
train
https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Api/BaseApi.php#L69-L76
llaville/php-reflect
src/Bartlett/Reflect.php
Reflect.addAnalyser
public function addAnalyser(NodeVisitor $analyser) { $analyser->setSubject($this); $this->analysers[] = $analyser; return $this; }
php
public function addAnalyser(NodeVisitor $analyser) { $analyser->setSubject($this); $this->analysers[] = $analyser; return $this; }
[ "public", "function", "addAnalyser", "(", "NodeVisitor", "$", "analyser", ")", "{", "$", "analyser", "->", "setSubject", "(", "$", "this", ")", ";", "$", "this", "->", "analysers", "[", "]", "=", "$", "analyser", ";", "return", "$", "this", ";", "}" ]
Adds a new analyser to get specific metrics @param NodeVisitor $analyser Analyser instance @return self for fluent interface
[ "Adds", "a", "new", "analyser", "to", "get", "specific", "metrics" ]
train
https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect.php#L65-L70
llaville/php-reflect
src/Bartlett/Reflect.php
Reflect.parse
public function parse(Finder $finder) { $metrics = array(); if (empty($this->analysers)) { return false; } $lexer = new Emulative(array( 'usedAttributes' => array( 'comments', 'startLine', 'endLine', 'startTokenPos', 'endTokenPos' ) )); $parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7, $lexer); $traverser = new NodeTraverser(false); $traverser->addVisitor(new NameResolver); $conditionalCode = false; // attach all analysers selected foreach ($this->analysers as $analyser) { if ('compatibility' == $analyser->getShortName()) { $conditionalCode = true; } $traverser->addVisitor($analyser); if ($analyser instanceof VisitorInterface) { $analyser->setUpBeforeVisitor(); } } $queue = new \SplQueue(); $priority = array(); if ($conditionalCode) { // files to process with highest priority $filter = new CustomFilterIterator( $finder->getIterator(), array( function (\SplFileInfo $fileinfo) { $content = php_strip_whitespace($fileinfo->getPathname()); if (preg_match('/define\s*\(/i', $content) > 0) { // must be confirmed to avoid false positive with string content $tokens = token_get_all($content); for ($i = 0, $max = count($tokens); $i < $max; $i++) { if (is_array($tokens[$i]) && $tokens[$i][0] == T_STRING && strcasecmp($tokens[$i][1], 'define') == 0 ) { // confirmed by token strategy return true; } } } return false; } ) ); foreach ($filter as $file) { $path = $file->getPathname(); $priority[] = $path; $queue->enqueue($file); } // just followed by this other highest priority $filter = new CustomFilterIterator( $finder->getIterator(), array( function (\SplFileInfo $fileinfo) { $content = php_strip_whitespace($fileinfo->getPathname()); if (preg_match('/defined\s*\(/i', $content) > 0) { // must be confirmed to avoid false positive with string content $tokens = token_get_all($content); for ($i = 0, $max = count($tokens); $i < $max; $i++) { if (is_array($tokens[$i]) && $tokens[$i][0] == T_STRING && strcasecmp($tokens[$i][1], 'defined') == 0 ) { // confirmed by token strategy return true; } } } return false; } ) ); foreach ($filter as $file) { $path = $file->getPathname(); if (!in_array($path, $priority)) { $priority[] = $path; $queue->enqueue($file); } } $filter = new CustomFilterIterator( $finder->getIterator(), array( function (\SplFileInfo $fileinfo) { $content = php_strip_whitespace($fileinfo->getPathname()); $checks = array( 'extension_loaded', 'function_exists', 'method_exists', 'class_exists', 'interface_exists', 'trait_exists', ); $patterns = array_map( function ($a) { return "/$a\s*\(/i"; }, $checks ); foreach ($patterns as $regexp) { if (preg_match($regexp, $content) > 0) { // must be confirmed to avoid false positive with string content $tokens = token_get_all($content); for ($i = 0, $max = count($tokens); $i < $max; $i++) { if (is_array($tokens[$i]) && $tokens[$i][0] == T_STRING && in_array(strtolower($tokens[$i][1]), $checks) ) { // confirmed by token strategy return true; } } } } return false; } ) ); foreach ($filter as $file) { $path = $file->getPathname(); if (!in_array($path, $priority)) { $priority[] = $path; $queue->enqueue($file); } } unset($filter); } // all other files with lowest priority foreach ($finder as $file) { if (!in_array($file->getPathname(), $priority)) { $queue->enqueue($file); } } $files = $parserErrors = array(); // generate a data source identifier if not provided if (!isset($this->dataSourceId)) { $this->dataSourceId = sha1(serialize($finder->getIterator())); } // analyse each file of the data source while (!$queue->isEmpty()) { $file = $queue->dequeue(); $event = $this->dispatch( Events::PROGRESS, array( 'source' => $this->dataSourceId, 'file' => $file, ) ); $files[] = $file->getPathname(); if (isset($event['notModified'])) { $tokens = @token_get_all( file_get_contents($file->getPathname()) ); // uses cached response (AST built by PHP-Parser) $stmts = $event['notModified']; } else { // live request $errorHandler = new Collecting(); $stmts = $parser->parse( file_get_contents($file->getPathname()), $errorHandler ); if ($errorHandler->hasErrors()) { foreach ($errorHandler->getErrors() as $e) { $this->dispatch( Events::ERROR, array( 'source' => $this->dataSourceId, 'file' => $file, 'error' => $e->getMessage() ) ); $parserErrors[$file->getPathname()] = $e->getMessage(); } continue; // skip to next file of the data source } $tokens = $lexer->getTokens(); } // update context for each analyser selected foreach ($this->analysers as $analyser) { $analyser->setTokens($tokens); $analyser->setCurrentFile($file->getPathname()); } $stmts = $traverser->traverse($stmts); $this->dispatch( Events::SUCCESS, array( 'source' => $this->dataSourceId, 'file' => $file, 'ast' => $stmts, ) ); } // end of parsing the data source $event = $this->dispatch(Events::COMPLETE, array('source' => $this->dataSourceId)); if (isset($event['extra'])) { $metrics['extra'] = $event['extra']; } // list of files parsed $metrics['files'] = $files; // list of PHP-Parser errors $metrics['errors'] = $parserErrors; // collect metrics of each analyser selected foreach ($this->analysers as $analyser) { if ($analyser instanceof VisitorInterface) { $analyser->tearDownAfterVisitor(); } $metrics = array_merge($metrics, (array)$analyser->getMetrics()); } return $metrics; }
php
public function parse(Finder $finder) { $metrics = array(); if (empty($this->analysers)) { return false; } $lexer = new Emulative(array( 'usedAttributes' => array( 'comments', 'startLine', 'endLine', 'startTokenPos', 'endTokenPos' ) )); $parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7, $lexer); $traverser = new NodeTraverser(false); $traverser->addVisitor(new NameResolver); $conditionalCode = false; // attach all analysers selected foreach ($this->analysers as $analyser) { if ('compatibility' == $analyser->getShortName()) { $conditionalCode = true; } $traverser->addVisitor($analyser); if ($analyser instanceof VisitorInterface) { $analyser->setUpBeforeVisitor(); } } $queue = new \SplQueue(); $priority = array(); if ($conditionalCode) { // files to process with highest priority $filter = new CustomFilterIterator( $finder->getIterator(), array( function (\SplFileInfo $fileinfo) { $content = php_strip_whitespace($fileinfo->getPathname()); if (preg_match('/define\s*\(/i', $content) > 0) { // must be confirmed to avoid false positive with string content $tokens = token_get_all($content); for ($i = 0, $max = count($tokens); $i < $max; $i++) { if (is_array($tokens[$i]) && $tokens[$i][0] == T_STRING && strcasecmp($tokens[$i][1], 'define') == 0 ) { // confirmed by token strategy return true; } } } return false; } ) ); foreach ($filter as $file) { $path = $file->getPathname(); $priority[] = $path; $queue->enqueue($file); } // just followed by this other highest priority $filter = new CustomFilterIterator( $finder->getIterator(), array( function (\SplFileInfo $fileinfo) { $content = php_strip_whitespace($fileinfo->getPathname()); if (preg_match('/defined\s*\(/i', $content) > 0) { // must be confirmed to avoid false positive with string content $tokens = token_get_all($content); for ($i = 0, $max = count($tokens); $i < $max; $i++) { if (is_array($tokens[$i]) && $tokens[$i][0] == T_STRING && strcasecmp($tokens[$i][1], 'defined') == 0 ) { // confirmed by token strategy return true; } } } return false; } ) ); foreach ($filter as $file) { $path = $file->getPathname(); if (!in_array($path, $priority)) { $priority[] = $path; $queue->enqueue($file); } } $filter = new CustomFilterIterator( $finder->getIterator(), array( function (\SplFileInfo $fileinfo) { $content = php_strip_whitespace($fileinfo->getPathname()); $checks = array( 'extension_loaded', 'function_exists', 'method_exists', 'class_exists', 'interface_exists', 'trait_exists', ); $patterns = array_map( function ($a) { return "/$a\s*\(/i"; }, $checks ); foreach ($patterns as $regexp) { if (preg_match($regexp, $content) > 0) { // must be confirmed to avoid false positive with string content $tokens = token_get_all($content); for ($i = 0, $max = count($tokens); $i < $max; $i++) { if (is_array($tokens[$i]) && $tokens[$i][0] == T_STRING && in_array(strtolower($tokens[$i][1]), $checks) ) { // confirmed by token strategy return true; } } } } return false; } ) ); foreach ($filter as $file) { $path = $file->getPathname(); if (!in_array($path, $priority)) { $priority[] = $path; $queue->enqueue($file); } } unset($filter); } // all other files with lowest priority foreach ($finder as $file) { if (!in_array($file->getPathname(), $priority)) { $queue->enqueue($file); } } $files = $parserErrors = array(); // generate a data source identifier if not provided if (!isset($this->dataSourceId)) { $this->dataSourceId = sha1(serialize($finder->getIterator())); } // analyse each file of the data source while (!$queue->isEmpty()) { $file = $queue->dequeue(); $event = $this->dispatch( Events::PROGRESS, array( 'source' => $this->dataSourceId, 'file' => $file, ) ); $files[] = $file->getPathname(); if (isset($event['notModified'])) { $tokens = @token_get_all( file_get_contents($file->getPathname()) ); // uses cached response (AST built by PHP-Parser) $stmts = $event['notModified']; } else { // live request $errorHandler = new Collecting(); $stmts = $parser->parse( file_get_contents($file->getPathname()), $errorHandler ); if ($errorHandler->hasErrors()) { foreach ($errorHandler->getErrors() as $e) { $this->dispatch( Events::ERROR, array( 'source' => $this->dataSourceId, 'file' => $file, 'error' => $e->getMessage() ) ); $parserErrors[$file->getPathname()] = $e->getMessage(); } continue; // skip to next file of the data source } $tokens = $lexer->getTokens(); } // update context for each analyser selected foreach ($this->analysers as $analyser) { $analyser->setTokens($tokens); $analyser->setCurrentFile($file->getPathname()); } $stmts = $traverser->traverse($stmts); $this->dispatch( Events::SUCCESS, array( 'source' => $this->dataSourceId, 'file' => $file, 'ast' => $stmts, ) ); } // end of parsing the data source $event = $this->dispatch(Events::COMPLETE, array('source' => $this->dataSourceId)); if (isset($event['extra'])) { $metrics['extra'] = $event['extra']; } // list of files parsed $metrics['files'] = $files; // list of PHP-Parser errors $metrics['errors'] = $parserErrors; // collect metrics of each analyser selected foreach ($this->analysers as $analyser) { if ($analyser instanceof VisitorInterface) { $analyser->tearDownAfterVisitor(); } $metrics = array_merge($metrics, (array)$analyser->getMetrics()); } return $metrics; }
[ "public", "function", "parse", "(", "Finder", "$", "finder", ")", "{", "$", "metrics", "=", "array", "(", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "analysers", ")", ")", "{", "return", "false", ";", "}", "$", "lexer", "=", "new", "Em...
Analyse a data source and return all analyser metrics. @param Finder $finder A data source finder @return array|boolean array of all analysers metrics, or FALSE if no parse occured
[ "Analyse", "a", "data", "source", "and", "return", "all", "analyser", "metrics", "." ]
train
https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect.php#L112-L359
llaville/php-reflect
src/Bartlett/Reflect/Console/Application.php
Application.getVersion
public function getVersion() { $version = parent::getVersion(); if ('UNKNOWN' == $version) { $version = new \SebastianBergmann\Version( $this->release, dirname(dirname(dirname(dirname(__DIR__)))) ); $version = $version->getVersion(); } return $version; }
php
public function getVersion() { $version = parent::getVersion(); if ('UNKNOWN' == $version) { $version = new \SebastianBergmann\Version( $this->release, dirname(dirname(dirname(dirname(__DIR__)))) ); $version = $version->getVersion(); } return $version; }
[ "public", "function", "getVersion", "(", ")", "{", "$", "version", "=", "parent", "::", "getVersion", "(", ")", ";", "if", "(", "'UNKNOWN'", "==", "$", "version", ")", "{", "$", "version", "=", "new", "\\", "SebastianBergmann", "\\", "Version", "(", "$...
{@inheritDoc}
[ "{" ]
train
https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Console/Application.php#L178-L190
llaville/php-reflect
src/Bartlett/Reflect/Console/Application.php
Application.run
public function run(InputInterface $input = null, OutputInterface $output = null) { if (null === $input) { $input = new ArgvInput(); } if (null === $output) { $target = $input->getParameterOption('--output'); if ($target === false) { $output = new ConsoleOutput(); } else { $url = parse_url($target); $mode = 'w'; if (isset($url['scheme']) && $url['scheme'] == 'ftp') { $options = array($url['scheme'] => array('overwrite' => true)); $context = stream_context_create($options); $output = new StreamOutput(fopen($target, $mode, false, $context), null, false); } else { $output = new StreamOutput(fopen($target, $mode), null, false); } } $output->getFormatter()->setStyle('diagpass', new OutputFormatterStyle('green', null, ['reverse'])); $output->getFormatter()->setStyle('warning', new OutputFormatterStyle('black', 'yellow')); $output->getFormatter()->setStyle('debug', new OutputFormatterStyle('black', 'cyan')); $output->getFormatter()->setStyle('php', new OutputFormatterStyle('white', 'magenta')); $output->getFormatter()->setStyle('ext', new OutputFormatterStyle('white', 'blue')); } $this->getDispatcher(); parent::run($input, $output); }
php
public function run(InputInterface $input = null, OutputInterface $output = null) { if (null === $input) { $input = new ArgvInput(); } if (null === $output) { $target = $input->getParameterOption('--output'); if ($target === false) { $output = new ConsoleOutput(); } else { $url = parse_url($target); $mode = 'w'; if (isset($url['scheme']) && $url['scheme'] == 'ftp') { $options = array($url['scheme'] => array('overwrite' => true)); $context = stream_context_create($options); $output = new StreamOutput(fopen($target, $mode, false, $context), null, false); } else { $output = new StreamOutput(fopen($target, $mode), null, false); } } $output->getFormatter()->setStyle('diagpass', new OutputFormatterStyle('green', null, ['reverse'])); $output->getFormatter()->setStyle('warning', new OutputFormatterStyle('black', 'yellow')); $output->getFormatter()->setStyle('debug', new OutputFormatterStyle('black', 'cyan')); $output->getFormatter()->setStyle('php', new OutputFormatterStyle('white', 'magenta')); $output->getFormatter()->setStyle('ext', new OutputFormatterStyle('white', 'blue')); } $this->getDispatcher(); parent::run($input, $output); }
[ "public", "function", "run", "(", "InputInterface", "$", "input", "=", "null", ",", "OutputInterface", "$", "output", "=", "null", ")", "{", "if", "(", "null", "===", "$", "input", ")", "{", "$", "input", "=", "new", "ArgvInput", "(", ")", ";", "}", ...
{@inheritDoc}
[ "{" ]
train
https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Console/Application.php#L209-L241
llaville/php-reflect
src/Bartlett/Reflect/Console/Application.php
Application.doRun
public function doRun(InputInterface $input, OutputInterface $output) { if (\Phar::running() && true === $input->hasParameterOption('--manifest') ) { $manifest = 'phar://' . strtolower($this->getName()) . '.phar/manifest.txt'; if (file_exists($manifest)) { $out = file_get_contents($manifest); $exitCode = 0; } else { $fmt = $this->getHelperSet()->get('formatter'); $out = $fmt->formatBlock('No manifest defined', 'error'); $exitCode = 1; } $output->writeln($out); return $exitCode; } $exitCode = parent::doRun($input, $output); return $exitCode; }
php
public function doRun(InputInterface $input, OutputInterface $output) { if (\Phar::running() && true === $input->hasParameterOption('--manifest') ) { $manifest = 'phar://' . strtolower($this->getName()) . '.phar/manifest.txt'; if (file_exists($manifest)) { $out = file_get_contents($manifest); $exitCode = 0; } else { $fmt = $this->getHelperSet()->get('formatter'); $out = $fmt->formatBlock('No manifest defined', 'error'); $exitCode = 1; } $output->writeln($out); return $exitCode; } $exitCode = parent::doRun($input, $output); return $exitCode; }
[ "public", "function", "doRun", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "if", "(", "\\", "Phar", "::", "running", "(", ")", "&&", "true", "===", "$", "input", "->", "hasParameterOption", "(", "'--manifest'", ")"...
{@inheritDoc}
[ "{" ]
train
https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Console/Application.php#L246-L268
llaville/php-reflect
src/Bartlett/Reflect/Plugin/Notifier/GrowlNotifier.php
GrowlNotifier.setMessageFormat
public function setMessageFormat($format) { if (is_string($format) && !empty($format)) { $this->format = $format; } return $this; }
php
public function setMessageFormat($format) { if (is_string($format) && !empty($format)) { $this->format = $format; } return $this; }
[ "public", "function", "setMessageFormat", "(", "$", "format", ")", "{", "if", "(", "is_string", "(", "$", "format", ")", "&&", "!", "empty", "(", "$", "format", ")", ")", "{", "$", "this", "->", "format", "=", "$", "format", ";", "}", "return", "$"...
{@inheritDoc}
[ "{" ]
train
https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/Notifier/GrowlNotifier.php#L85-L92
llaville/php-reflect
src/Bartlett/Reflect/Plugin/Notifier/GrowlNotifier.php
GrowlNotifier.notify
public function notify(GenericEvent $event) { try { $this->growl->register(); $name = $event['eventname']; $notifications = $this->growl->getApplication()->getGrowlNotifications(); $this->growl->publish( $name, $this->growl->getApplication()->getGrowlName(), $event['formatted'], $notifications[$name] ); // } catch (\Net_Growl_Exception $e) { return false; } return true; }
php
public function notify(GenericEvent $event) { try { $this->growl->register(); $name = $event['eventname']; $notifications = $this->growl->getApplication()->getGrowlNotifications(); $this->growl->publish( $name, $this->growl->getApplication()->getGrowlName(), $event['formatted'], $notifications[$name] ); // } catch (\Net_Growl_Exception $e) { return false; } return true; }
[ "public", "function", "notify", "(", "GenericEvent", "$", "event", ")", "{", "try", "{", "$", "this", "->", "growl", "->", "register", "(", ")", ";", "$", "name", "=", "$", "event", "[", "'eventname'", "]", ";", "$", "notifications", "=", "$", "this"...
{@inheritDoc}
[ "{" ]
train
https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/Notifier/GrowlNotifier.php#L105-L126
llaville/php-reflect
src/Bartlett/Reflect/Api/V3/Plugin.php
Plugin.dir
public function dir() { $pm = new PluginManager(new EventDispatcher()); if ($this->registerPlugins) { $pm->registerPlugins(); } $plugins = $pm->getPlugins(); $rows = array(); foreach ($plugins as $plugin) { if (!$plugin instanceof EventSubscriberInterface) { $events = array(); } else { $events = $plugin::getSubscribedEvents(); } $rows[get_class($plugin)] = array_keys($events); } return $rows; }
php
public function dir() { $pm = new PluginManager(new EventDispatcher()); if ($this->registerPlugins) { $pm->registerPlugins(); } $plugins = $pm->getPlugins(); $rows = array(); foreach ($plugins as $plugin) { if (!$plugin instanceof EventSubscriberInterface) { $events = array(); } else { $events = $plugin::getSubscribedEvents(); } $rows[get_class($plugin)] = array_keys($events); } return $rows; }
[ "public", "function", "dir", "(", ")", "{", "$", "pm", "=", "new", "PluginManager", "(", "new", "EventDispatcher", "(", ")", ")", ";", "if", "(", "$", "this", "->", "registerPlugins", ")", "{", "$", "pm", "->", "registerPlugins", "(", ")", ";", "}", ...
List all plugins installed. @return array
[ "List", "all", "plugins", "installed", "." ]
train
https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Api/V3/Plugin.php#L45-L65
llaville/php-reflect
src/Bartlett/Reflect/Model/ConstantModel.php
ConstantModel.getNamespaceName
public function getNamespaceName() { $parts = $this->node->consts[0]->namespacedName->parts; array_pop($parts); return implode('\\', $parts); }
php
public function getNamespaceName() { $parts = $this->node->consts[0]->namespacedName->parts; array_pop($parts); return implode('\\', $parts); }
[ "public", "function", "getNamespaceName", "(", ")", "{", "$", "parts", "=", "$", "this", "->", "node", "->", "consts", "[", "0", "]", "->", "namespacedName", "->", "parts", ";", "array_pop", "(", "$", "parts", ")", ";", "return", "implode", "(", "'\\\\...
Get the namespace name where the constant is defined. @return string
[ "Get", "the", "namespace", "name", "where", "the", "constant", "is", "defined", "." ]
train
https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/ConstantModel.php#L36-L41
llaville/php-reflect
src/Bartlett/Reflect/Model/ConstantModel.php
ConstantModel.getValue
public function getValue() { $prettyPrinter = new PrettyPrinter\Standard; return trim( $prettyPrinter->prettyPrintExpr($this->node->consts[0]->value), '"\'' ); }
php
public function getValue() { $prettyPrinter = new PrettyPrinter\Standard; return trim( $prettyPrinter->prettyPrintExpr($this->node->consts[0]->value), '"\'' ); }
[ "public", "function", "getValue", "(", ")", "{", "$", "prettyPrinter", "=", "new", "PrettyPrinter", "\\", "Standard", ";", "return", "trim", "(", "$", "prettyPrinter", "->", "prettyPrintExpr", "(", "$", "this", "->", "node", "->", "consts", "[", "0", "]", ...
Gets the constant value. @return mixed
[ "Gets", "the", "constant", "value", "." ]
train
https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/ConstantModel.php#L68-L75
llaville/php-reflect
src/Bartlett/Reflect/Model/ClassModel.php
ClassModel.getInterfaceNames
public function getInterfaceNames() { $interfaces = array(); if ($this->node instanceof Node\Stmt\Class_) { foreach ($this->node->implements as $interface) { $interfaces[] = (string) $interface; } } return $interfaces; }
php
public function getInterfaceNames() { $interfaces = array(); if ($this->node instanceof Node\Stmt\Class_) { foreach ($this->node->implements as $interface) { $interfaces[] = (string) $interface; } } return $interfaces; }
[ "public", "function", "getInterfaceNames", "(", ")", "{", "$", "interfaces", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "node", "instanceof", "Node", "\\", "Stmt", "\\", "Class_", ")", "{", "foreach", "(", "$", "this", "->", "node", "...
Gets the interface names. @return array A numerical array with interface names as the values.
[ "Gets", "the", "interface", "names", "." ]
train
https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/ClassModel.php#L60-L71
llaville/php-reflect
src/Bartlett/Reflect/Model/ClassModel.php
ClassModel.getParentClassName
public function getParentClassName() { if ($this->isTrait()) { return false; } $parent = $this->node->extends; if (!empty($parent)) { if ($this->isInterface()) { $parent = array_pop($parent); } return (string) $parent; } return false; }
php
public function getParentClassName() { if ($this->isTrait()) { return false; } $parent = $this->node->extends; if (!empty($parent)) { if ($this->isInterface()) { $parent = array_pop($parent); } return (string) $parent; } return false; }
[ "public", "function", "getParentClassName", "(", ")", "{", "if", "(", "$", "this", "->", "isTrait", "(", ")", ")", "{", "return", "false", ";", "}", "$", "parent", "=", "$", "this", "->", "node", "->", "extends", ";", "if", "(", "!", "empty", "(", ...
Gets the parent class. @return mixed string if parent exists, false otherwise
[ "Gets", "the", "parent", "class", "." ]
train
https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/ClassModel.php#L100-L114
llaville/php-reflect
src/Bartlett/Reflect/Model/ClassModel.php
ClassModel.getConstants
public function getConstants() { if ($this->constants === null) { $prettyPrinter = new PrettyPrinter\Standard; // lazy load class constants list $this->constants = array(); foreach ($this->node->stmts as $stmt) { if ($stmt instanceof Node\Stmt\ClassConst) { foreach ($stmt->consts as $const) { $this->constants[$const->name] = trim( $prettyPrinter->prettyPrintExpr($const->value), '"\'' ); } } } } return $this->constants; }
php
public function getConstants() { if ($this->constants === null) { $prettyPrinter = new PrettyPrinter\Standard; // lazy load class constants list $this->constants = array(); foreach ($this->node->stmts as $stmt) { if ($stmt instanceof Node\Stmt\ClassConst) { foreach ($stmt->consts as $const) { $this->constants[$const->name] = trim( $prettyPrinter->prettyPrintExpr($const->value), '"\'' ); } } } } return $this->constants; }
[ "public", "function", "getConstants", "(", ")", "{", "if", "(", "$", "this", "->", "constants", "===", "null", ")", "{", "$", "prettyPrinter", "=", "new", "PrettyPrinter", "\\", "Standard", ";", "// lazy load class constants list", "$", "this", "->", "constant...
Gets the constants. @return array An array of constants. Constant name in key, constant value in value.
[ "Gets", "the", "constants", "." ]
train
https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/ClassModel.php#L142-L160
llaville/php-reflect
src/Bartlett/Reflect/Model/ClassModel.php
ClassModel.getConstant
public function getConstant($name) { $constants = $this->getConstants(); $value = array_key_exists($name, $constants); if ($value) { $value = $constants[$name]; } return $value; }
php
public function getConstant($name) { $constants = $this->getConstants(); $value = array_key_exists($name, $constants); if ($value) { $value = $constants[$name]; } return $value; }
[ "public", "function", "getConstant", "(", "$", "name", ")", "{", "$", "constants", "=", "$", "this", "->", "getConstants", "(", ")", ";", "$", "value", "=", "array_key_exists", "(", "$", "name", ",", "$", "constants", ")", ";", "if", "(", "$", "value...
Gets defined constant. @param string $name Name of the constant @return mixed constant value or FALSE if constant does not exist
[ "Gets", "defined", "constant", "." ]
train
https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/ClassModel.php#L169-L177
llaville/php-reflect
src/Bartlett/Reflect/Model/ClassModel.php
ClassModel.getMethods
public function getMethods($filter = null) { if ($this->methods === null) { // lazy load class methods list $this->methods = array(); foreach ($this->node->stmts as $stmt) { if ($stmt instanceof Node\Stmt\ClassMethod) { $stmt->setAttribute('fileName', $this->getFileName()); $this->methods[$stmt->name] = new MethodModel($this, $stmt); } } } if (isset($filter)) { // @TODO must implement the filter feature $methods =& $this->methods; } else { $methods =& $this->methods; } return array_values($methods); }
php
public function getMethods($filter = null) { if ($this->methods === null) { // lazy load class methods list $this->methods = array(); foreach ($this->node->stmts as $stmt) { if ($stmt instanceof Node\Stmt\ClassMethod) { $stmt->setAttribute('fileName', $this->getFileName()); $this->methods[$stmt->name] = new MethodModel($this, $stmt); } } } if (isset($filter)) { // @TODO must implement the filter feature $methods =& $this->methods; } else { $methods =& $this->methods; } return array_values($methods); }
[ "public", "function", "getMethods", "(", "$", "filter", "=", "null", ")", "{", "if", "(", "$", "this", "->", "methods", "===", "null", ")", "{", "// lazy load class methods list", "$", "this", "->", "methods", "=", "array", "(", ")", ";", "foreach", "(",...
Gets an array of methods. @param int $filter Filter the results to include only methods with certain attributes. Defaults to no filtering. @return array An array of MethodModel objects reflecting each method.
[ "Gets", "an", "array", "of", "methods", "." ]
train
https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/ClassModel.php#L200-L221
llaville/php-reflect
src/Bartlett/Reflect/Model/ClassModel.php
ClassModel.getMethod
public function getMethod($name) { if ($this->hasMethod($name)) { return $this->methods[$name]; } throw new ModelException( 'Method ' . $name . ' does not exist.' ); }
php
public function getMethod($name) { if ($this->hasMethod($name)) { return $this->methods[$name]; } throw new ModelException( 'Method ' . $name . ' does not exist.' ); }
[ "public", "function", "getMethod", "(", "$", "name", ")", "{", "if", "(", "$", "this", "->", "hasMethod", "(", "$", "name", ")", ")", "{", "return", "$", "this", "->", "methods", "[", "$", "name", "]", ";", "}", "throw", "new", "ModelException", "(...
Gets a MethodModel for a class method. @param string $name The method name to reflect. @return MethodModel @throws ModelException if the method does not exist.
[ "Gets", "a", "MethodModel", "for", "a", "class", "method", "." ]
train
https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/ClassModel.php#L231-L239