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_documentation_string
stringlengths 1
47.2k
| func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|
PHPColibri/framework | Database/Concrete/MySQL/Connection.php | Connection.close | public function close()
{
if ( ! $this->link->close()) {
throw new DbException('can\'t close database connection: ' . $this->link->error, $this->link->errno);
}
return true;
} | php | public function close()
{
if ( ! $this->link->close()) {
throw new DbException('can\'t close database connection: ' . $this->link->error, $this->link->errno);
}
return true;
} | Closes the connection.
@return bool
@throws \Colibri\Database\DbException | https://github.com/PHPColibri/framework/blob/7e5b77141da5e5e7c63afc83592671321ac52f36/Database/Concrete/MySQL/Connection.php#L54-L61 |
PHPColibri/framework | Database/Concrete/MySQL/Connection.php | Connection.sendQuery | protected function sendQuery(string $query)
{
if (self::$monitorQueries) {
self::$queriesCount++;
}
$result = $this->link->query($query);
if ($result === false) {
throw new SqlException(
'SQL-error [' . $this->link->errno . ']: ' . $this->link->error . "\nSQL-query: $query",
$this->link->errno
);
}
return $result === true ? $result : new Query\Result($result);
} | php | protected function sendQuery(string $query)
{
if (self::$monitorQueries) {
self::$queriesCount++;
}
$result = $this->link->query($query);
if ($result === false) {
throw new SqlException(
'SQL-error [' . $this->link->errno . ']: ' . $this->link->error . "\nSQL-query: $query",
$this->link->errno
);
}
return $result === true ? $result : new Query\Result($result);
} | Выполняет переданный запрос.
Executes given query.
@param string $query
@return bool|Driver\Query\ResultInterface
@throws \Colibri\Database\Exception\SqlException | https://github.com/PHPColibri/framework/blob/7e5b77141da5e5e7c63afc83592671321ac52f36/Database/Concrete/MySQL/Connection.php#L105-L119 |
jtallant/skimpy-engine | src/Http/Renderer/NegotiatingRenderer.php | NegotiatingRenderer.render | public function render(
Entity $entity,
Request $request,
array $params = []
) {
$mimeType = $this->getMimeType($request);
return $this->getRendererByMimeType($mimeType)->render($entity, $request, $params);
} | php | public function render(
Entity $entity,
Request $request,
array $params = []
) {
$mimeType = $this->getMimeType($request);
return $this->getRendererByMimeType($mimeType)->render($entity, $request, $params);
} | {@inheritdoc} | https://github.com/jtallant/skimpy-engine/blob/2fce5bc16f8745e54fd66a1c291fcea47fc1b4b2/src/Http/Renderer/NegotiatingRenderer.php#L49-L57 |
jtallant/skimpy-engine | src/Http/Renderer/NegotiatingRenderer.php | NegotiatingRenderer.getMimeType | protected function getMimeType(Request $request)
{
$acceptHeader = $this->negotiator->getBest(
$request->headers->get('Accept'),
$this->getMimeTypes()
);
if ($acceptHeader && $this->isAcceptableMimeType($acceptHeader->getType())) {
return $acceptHeader->getType();
}
return $this->defaultMimeType;
} | php | protected function getMimeType(Request $request)
{
$acceptHeader = $this->negotiator->getBest(
$request->headers->get('Accept'),
$this->getMimeTypes()
);
if ($acceptHeader && $this->isAcceptableMimeType($acceptHeader->getType())) {
return $acceptHeader->getType();
}
return $this->defaultMimeType;
} | @param Request $request
@return string | https://github.com/jtallant/skimpy-engine/blob/2fce5bc16f8745e54fd66a1c291fcea47fc1b4b2/src/Http/Renderer/NegotiatingRenderer.php#L78-L90 |
jtallant/skimpy-engine | src/Http/Renderer/NegotiatingRenderer.php | NegotiatingRenderer.getRendererByMimeType | protected function getRendererByMimeType($type)
{
foreach ($this->renderers as $renderer) {
if (in_array($type, $renderer->getMimeTypes())) {
return $renderer;
}
}
throw new \LogicException("Could not find a renderer for mime type: $type");
} | php | protected function getRendererByMimeType($type)
{
foreach ($this->renderers as $renderer) {
if (in_array($type, $renderer->getMimeTypes())) {
return $renderer;
}
}
throw new \LogicException("Could not find a renderer for mime type: $type");
} | @param string $type
@return Renderer
@throws \LogicException | https://github.com/jtallant/skimpy-engine/blob/2fce5bc16f8745e54fd66a1c291fcea47fc1b4b2/src/Http/Renderer/NegotiatingRenderer.php#L99-L108 |
Synapse-Cmf/synapse-cmf | src/Synapse/Cmf/Bundle/Form/Type/Media/ImageChoiceType.php | ImageChoiceType.configureOptions | public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefined('image_formats');
$resolver->setDefaults(array(
'choices' => $this->imageCollection
->map(function (Image $image) {
return $image->getId();
})
->toArray(),
'choice_label' => function ($value, $key, $index) {
return $this->imageCollection->get($value)->getName();
},
));
} | php | public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefined('image_formats');
$resolver->setDefaults(array(
'choices' => $this->imageCollection
->map(function (Image $image) {
return $image->getId();
})
->toArray(),
'choice_label' => function ($value, $key, $index) {
return $this->imageCollection->get($value)->getName();
},
));
} | {@inheritdoc} | https://github.com/Synapse-Cmf/synapse-cmf/blob/d8122a4150a83d5607289724425cf35c56a5e880/src/Synapse/Cmf/Bundle/Form/Type/Media/ImageChoiceType.php#L45-L59 |
SpoonX/SxBootstrap | src/SxBootstrap/View/Helper/Bootstrap/FormColorPicker.php | FormColorPicker.assembleComponent | protected function assembleComponent($element)
{
$options = $this->getOptions();
$element = parent::__invoke($element);
$component = sprintf(
'<div style="padding: 0;" class="input-append color %s" data-color="%s" data-color-format="%s">%s',
$options['class'],
$options['color'],
$options['format'],
$element
) . sprintf(
'<span class="add-on"><i style="background-color: %s;"></i></span></div>',
$options['color']
);
return $component;
} | php | protected function assembleComponent($element)
{
$options = $this->getOptions();
$element = parent::__invoke($element);
$component = sprintf(
'<div style="padding: 0;" class="input-append color %s" data-color="%s" data-color-format="%s">%s',
$options['class'],
$options['color'],
$options['format'],
$element
) . sprintf(
'<span class="add-on"><i style="background-color: %s;"></i></span></div>',
$options['color']
);
return $component;
} | Put together the colorpicker component.
@param Zend\Form\Element $element | https://github.com/SpoonX/SxBootstrap/blob/768b02e3b65f7dfe560e821cb0ff41ad3f86b3b6/src/SxBootstrap/View/Helper/Bootstrap/FormColorPicker.php#L72-L88 |
SpoonX/SxBootstrap | src/SxBootstrap/View/Helper/Bootstrap/FormColorPicker.php | FormColorPicker.prepareElement | protected function prepareElement($element)
{
$options = $this->getOptions();
$currClass = $element->getAttribute('class');
$class = $currClass . (null !== $currClass ? ' ' : '') . $options['class'];
$element->setAttributes(array(
'class' => $class,
'data-color' => $options['color'],
'data-color-format' => $options['format'],
));
return $element;
} | php | protected function prepareElement($element)
{
$options = $this->getOptions();
$currClass = $element->getAttribute('class');
$class = $currClass . (null !== $currClass ? ' ' : '') . $options['class'];
$element->setAttributes(array(
'class' => $class,
'data-color' => $options['color'],
'data-color-format' => $options['format'],
));
return $element;
} | Prepare the element by applying all changes to it required for the colorpicker.
@param Zend\Form\Element\Element $element
@return Zend\Form\View\Helper\FormInput | https://github.com/SpoonX/SxBootstrap/blob/768b02e3b65f7dfe560e821cb0ff41ad3f86b3b6/src/SxBootstrap/View/Helper/Bootstrap/FormColorPicker.php#L97-L110 |
SpoonX/SxBootstrap | src/SxBootstrap/View/Helper/Bootstrap/FormColorPicker.php | FormColorPicker.handleDependencies | protected function handleDependencies()
{
$options = $this->getOptions();
if ($options['invoke_inline']) {
$this->invokeInline();
}
if ($options['include_dependencies']) {
$this->includeDependencies();
}
} | php | protected function handleDependencies()
{
$options = $this->getOptions();
if ($options['invoke_inline']) {
$this->invokeInline();
}
if ($options['include_dependencies']) {
$this->includeDependencies();
}
} | Handle the dependencies (inline, head and / or leave alone) | https://github.com/SpoonX/SxBootstrap/blob/768b02e3b65f7dfe560e821cb0ff41ad3f86b3b6/src/SxBootstrap/View/Helper/Bootstrap/FormColorPicker.php#L115-L126 |
SpoonX/SxBootstrap | src/SxBootstrap/View/Helper/Bootstrap/FormColorPicker.php | FormColorPicker.setOptions | protected function setOptions($options)
{
$options = array_merge(array(
'format' => 'hex',
'invoke_inline' => false,
'include_dependencies' => false,
'as_component' => false,
'class' => 'colorpicker',
), $options);
if (!in_array($options['format'], array('hex', 'rgb', 'rgba'))) {
throw new Exception\InvalidArgumentException(
'Invalid format supplied. Allowed formats are "hex", "rgb" and "rgba".'
);
}
$defaultColors = array(
'hex' => '#fff',
'rgb' => 'rgb(255,255,255)',
'rgba' => 'rgba(255,255,255,1)',
);
if (empty($options['color'])) {
$options['color'] = $defaultColors[$options['format']];
}
return $this->options = $options;
} | php | protected function setOptions($options)
{
$options = array_merge(array(
'format' => 'hex',
'invoke_inline' => false,
'include_dependencies' => false,
'as_component' => false,
'class' => 'colorpicker',
), $options);
if (!in_array($options['format'], array('hex', 'rgb', 'rgba'))) {
throw new Exception\InvalidArgumentException(
'Invalid format supplied. Allowed formats are "hex", "rgb" and "rgba".'
);
}
$defaultColors = array(
'hex' => '#fff',
'rgb' => 'rgb(255,255,255)',
'rgba' => 'rgba(255,255,255,1)',
);
if (empty($options['color'])) {
$options['color'] = $defaultColors[$options['format']];
}
return $this->options = $options;
} | Set the options for the colorpicker.
@param array $options
@return array The options.
@throws Exception\InvalidArgumentException | https://github.com/SpoonX/SxBootstrap/blob/768b02e3b65f7dfe560e821cb0ff41ad3f86b3b6/src/SxBootstrap/View/Helper/Bootstrap/FormColorPicker.php#L145-L172 |
SpoonX/SxBootstrap | src/SxBootstrap/View/Helper/Bootstrap/FormColorPicker.php | FormColorPicker.includeDependencies | protected function includeDependencies()
{
$view = $this->getView();
$view->headScript()->appendFile($view->basePath() . '/js/bootstrap-colorpicker.js');
$view->headLink()->prependStylesheet($view->basePath() . '/css/colorpicker.css');
} | php | protected function includeDependencies()
{
$view = $this->getView();
$view->headScript()->appendFile($view->basePath() . '/js/bootstrap-colorpicker.js');
$view->headLink()->prependStylesheet($view->basePath() . '/css/colorpicker.css');
} | Include the colorpicker dependencies. | https://github.com/SpoonX/SxBootstrap/blob/768b02e3b65f7dfe560e821cb0ff41ad3f86b3b6/src/SxBootstrap/View/Helper/Bootstrap/FormColorPicker.php#L190-L195 |
stratedge/wye | src/PDO/PDO.php | PDO.exec | public function exec($query)
{
$stmt = $this->getWye()->makeStatement($query, []);
$stmt->execute();
return $stmt->rowCount() !== null ? $stmt->rowCount() : 0;
} | php | public function exec($query)
{
$stmt = $this->getWye()->makeStatement($query, []);
$stmt->execute();
return $stmt->rowCount() !== null ? $stmt->rowCount() : 0;
} | Mimic for PDO::exec(). Executes the provided query.
@param string $query
@return int | https://github.com/stratedge/wye/blob/9d3d32b4ea56c711d67b8498ab1a05d0aded40ea/src/PDO/PDO.php#L77-L84 |
stratedge/wye | src/PDO/PDO.php | PDO.quote | public function quote($string, $paramtype = null)
{
if (!is_string($string)) {
throw new InvalidArgumentException(
sprintf(
"PDO:quote() expects parameter 1 to be a string, %s given.",
gettype($string)
)
);
}
return $this->getWye()->quote($string);
} | php | public function quote($string, $paramtype = null)
{
if (!is_string($string)) {
throw new InvalidArgumentException(
sprintf(
"PDO:quote() expects parameter 1 to be a string, %s given.",
gettype($string)
)
);
}
return $this->getWye()->quote($string);
} | Mimic for PDO::quote(). Stores the string and given option(s) on the Wye
and returns the given string wrapped in quote tags with a reference to
which number call to quote the current call is (<quote:0></quote:0>)
@param stromg $string
@param integer $paramtype
@return string | https://github.com/stratedge/wye/blob/9d3d32b4ea56c711d67b8498ab1a05d0aded40ea/src/PDO/PDO.php#L128-L140 |
ddvphp/wechat | org/old_version/Thinkphp/Wechatext.class.php | Wechatext.send | public function send($id,$content)
{
$send_snoopy = new Snoopy;
$post = array();
$post['tofakeid'] = $id;
$post['type'] = 1;
$post['token'] = $this->_token;
$post['content'] = $content;
$post['ajax'] = 1;
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/singlesendpage?t=message/send&action=index&tofakeid=$id&token={$this->_token}&lang=zh_CN";
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$submit = "https://mp.weixin.qq.com/cgi-bin/singlesend?t=ajax-response";
$send_snoopy->submit($submit,$post);
$this->log($send_snoopy->results);
return $send_snoopy->results;
} | php | public function send($id,$content)
{
$send_snoopy = new Snoopy;
$post = array();
$post['tofakeid'] = $id;
$post['type'] = 1;
$post['token'] = $this->_token;
$post['content'] = $content;
$post['ajax'] = 1;
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/singlesendpage?t=message/send&action=index&tofakeid=$id&token={$this->_token}&lang=zh_CN";
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$submit = "https://mp.weixin.qq.com/cgi-bin/singlesend?t=ajax-response";
$send_snoopy->submit($submit,$post);
$this->log($send_snoopy->results);
return $send_snoopy->results;
} | 主动发消息
@param string $id 用户的uid(即FakeId)
@param string $content 发送的内容 | https://github.com/ddvphp/wechat/blob/b5991526e7220c2bdc6b9e7a35651c11299aa69d/org/old_version/Thinkphp/Wechatext.class.php#L61-L76 |
ddvphp/wechat | org/old_version/Thinkphp/Wechatext.class.php | Wechatext.mass | public function mass($content) {
$send_snoopy = new Snoopy;
$post = array();
$post['type'] = 1;
$post['token'] = $this->_token;
$post['content'] = $content;
$post['ajax'] = 1;
$post['city']='';
$post['country']='';
$post['f']='json';
$post['groupid']='-1';
$post['imgcode']='';
$post['lang']='zh_CN';
$post['province']='';
$post['random']= rand(0, 1);
$post['sex']=0;
$post['synctxnews']=0;
$post['synctxweibo']=0;
$post['t']='ajax-response';
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/masssendpage?t=mass/send&token={$this->_token}&lang=zh_CN";
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$submit = "https://mp.weixin.qq.com/cgi-bin/masssend";
$send_snoopy->submit($submit,$post);
$this->log($send_snoopy->results);
return $send_snoopy->results;
} | php | public function mass($content) {
$send_snoopy = new Snoopy;
$post = array();
$post['type'] = 1;
$post['token'] = $this->_token;
$post['content'] = $content;
$post['ajax'] = 1;
$post['city']='';
$post['country']='';
$post['f']='json';
$post['groupid']='-1';
$post['imgcode']='';
$post['lang']='zh_CN';
$post['province']='';
$post['random']= rand(0, 1);
$post['sex']=0;
$post['synctxnews']=0;
$post['synctxweibo']=0;
$post['t']='ajax-response';
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/masssendpage?t=mass/send&token={$this->_token}&lang=zh_CN";
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$submit = "https://mp.weixin.qq.com/cgi-bin/masssend";
$send_snoopy->submit($submit,$post);
$this->log($send_snoopy->results);
return $send_snoopy->results;
} | 群发功能 纯文本
@param string $content
@return string | https://github.com/ddvphp/wechat/blob/b5991526e7220c2bdc6b9e7a35651c11299aa69d/org/old_version/Thinkphp/Wechatext.class.php#L83-L108 |
ddvphp/wechat | org/old_version/Thinkphp/Wechatext.class.php | Wechatext.massNews | function massNews($appmsgid){
$send_snoopy = new Snoopy;
$post = array();
$post['type'] = 10;
$post['token'] = $this->_token;
$post['appmsgid'] = $appmsgid;
$post['ajax'] = 1;
$post['city']='';
$post['country']='';
$post['f']='json';
$post['groupid']='-1';
$post['imgcode']='';
$post['lang']='zh_CN';
$post['province']='';
$post['random']= rand(0, 1);
$post['sex']=0;
$post['synctxnews']=0;
$post['synctxweibo']=0;
$post['t']='ajax-response';
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/masssendpage?t=mass/send&token={$this->_token}&lang=zh_CN";
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$submit = "https://mp.weixin.qq.com/cgi-bin/masssend";
$send_snoopy->submit($submit,$post);
$this->log($send_snoopy->results);
return $send_snoopy->results;
} | php | function massNews($appmsgid){
$send_snoopy = new Snoopy;
$post = array();
$post['type'] = 10;
$post['token'] = $this->_token;
$post['appmsgid'] = $appmsgid;
$post['ajax'] = 1;
$post['city']='';
$post['country']='';
$post['f']='json';
$post['groupid']='-1';
$post['imgcode']='';
$post['lang']='zh_CN';
$post['province']='';
$post['random']= rand(0, 1);
$post['sex']=0;
$post['synctxnews']=0;
$post['synctxweibo']=0;
$post['t']='ajax-response';
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/masssendpage?t=mass/send&token={$this->_token}&lang=zh_CN";
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$submit = "https://mp.weixin.qq.com/cgi-bin/masssend";
$send_snoopy->submit($submit,$post);
$this->log($send_snoopy->results);
return $send_snoopy->results;
} | 群发功能 图文素材
@param int $appmsgid 图文素材ID
@return string | https://github.com/ddvphp/wechat/blob/b5991526e7220c2bdc6b9e7a35651c11299aa69d/org/old_version/Thinkphp/Wechatext.class.php#L115-L140 |
ddvphp/wechat | org/old_version/Thinkphp/Wechatext.class.php | Wechatext.getUserList | function getUserList($page=0,$pagesize=10,$groupid=0){
$send_snoopy = new Snoopy;
$t = time().strval(mt_rand(100,999));
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/contactmanage?t=user/index&pagesize=".$pagesize."&pageidx=".$page."&type=0&groupid=0&lang=zh_CN&token=".$this->_token;
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$submit = "https://mp.weixin.qq.com/cgi-bin/contactmanage?t=user/index&pagesize=".$pagesize."&pageidx=".$page."&type=0&groupid=$groupid&lang=zh_CN&f=json&token=".$this->_token;
$send_snoopy->fetch($submit);
$result = $send_snoopy->results;
$this->log('userlist:'.$result);
$json = json_decode($result,true);
if (isset($json['contact_list'])) {
$json = json_decode($json['contact_list'],true);
if (isset($json['contacts']))
return $json['contacts'];
}
return false;
} | php | function getUserList($page=0,$pagesize=10,$groupid=0){
$send_snoopy = new Snoopy;
$t = time().strval(mt_rand(100,999));
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/contactmanage?t=user/index&pagesize=".$pagesize."&pageidx=".$page."&type=0&groupid=0&lang=zh_CN&token=".$this->_token;
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$submit = "https://mp.weixin.qq.com/cgi-bin/contactmanage?t=user/index&pagesize=".$pagesize."&pageidx=".$page."&type=0&groupid=$groupid&lang=zh_CN&f=json&token=".$this->_token;
$send_snoopy->fetch($submit);
$result = $send_snoopy->results;
$this->log('userlist:'.$result);
$json = json_decode($result,true);
if (isset($json['contact_list'])) {
$json = json_decode($json['contact_list'],true);
if (isset($json['contacts']))
return $json['contacts'];
}
return false;
} | 获取用户列表列表
@param $page 页码(从0开始)
@param $pagesize 每页大小
@param $groupid 分组id
@return array ({contacts:[{id:12345667,nick_name:"昵称",remark_name:"备注名",group_id:0},{}....]}) | https://github.com/ddvphp/wechat/blob/b5991526e7220c2bdc6b9e7a35651c11299aa69d/org/old_version/Thinkphp/Wechatext.class.php#L149-L165 |
ddvphp/wechat | org/old_version/Thinkphp/Wechatext.class.php | Wechatext.sendNews | public function sendNews($id,$msgid)
{
$send_snoopy = new Snoopy;
$post = array();
$post['tofakeid'] = $id;
$post['type'] = 10;
$post['token'] = $this->_token;
$post['fid'] = $msgid;
$post['appmsgid'] = $msgid;
$post['error'] = 'false';
$post['ajax'] = 1;
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/singlemsgpage?fromfakeid={$id}&msgid=&source=&count=20&t=wxm-singlechat&lang=zh_CN";
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$submit = "https://mp.weixin.qq.com/cgi-bin/singlesend?t=ajax-response";
$send_snoopy->submit($submit,$post);
$this->log($send_snoopy->results);
return $send_snoopy->results;
} | php | public function sendNews($id,$msgid)
{
$send_snoopy = new Snoopy;
$post = array();
$post['tofakeid'] = $id;
$post['type'] = 10;
$post['token'] = $this->_token;
$post['fid'] = $msgid;
$post['appmsgid'] = $msgid;
$post['error'] = 'false';
$post['ajax'] = 1;
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/singlemsgpage?fromfakeid={$id}&msgid=&source=&count=20&t=wxm-singlechat&lang=zh_CN";
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$submit = "https://mp.weixin.qq.com/cgi-bin/singlesend?t=ajax-response";
$send_snoopy->submit($submit,$post);
$this->log($send_snoopy->results);
return $send_snoopy->results;
} | 发送图文信息,必须从图文库里选取消息ID发送
@param string $id 用户的uid(即FakeId)
@param string $msgid 图文消息id | https://github.com/ddvphp/wechat/blob/b5991526e7220c2bdc6b9e7a35651c11299aa69d/org/old_version/Thinkphp/Wechatext.class.php#L239-L256 |
ddvphp/wechat | org/old_version/Thinkphp/Wechatext.class.php | Wechatext.uploadFile | public function uploadFile($filepath,$type=2) {
$send_snoopy = new Snoopy;
$send_snoopy->referer = "http://mp.weixin.qq.com/cgi-bin/indexpage?t=wxm-upload&lang=zh_CN&type=2&formId=1";
$t = time().strval(mt_rand(100,999));
$post = array('formId'=>'');
$postfile = array('uploadfile'=>$filepath);
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$send_snoopy->set_submit_multipart();
$submit = "http://mp.weixin.qq.com/cgi-bin/uploadmaterial?cgi=uploadmaterial&type=$type&token=".$this->_token."&t=iframe-uploadfile&lang=zh_CN&formId= file_from_".$t;
$send_snoopy->submit($submit,$post,$postfile);
$tmp = $send_snoopy->results;
$this->log('upload:'.$tmp);
preg_match("/formId,.*?\'(\d+)\'/",$tmp,$matches);
if (isset($matches[1])) {
return $matches[1];
}
return false;
} | php | public function uploadFile($filepath,$type=2) {
$send_snoopy = new Snoopy;
$send_snoopy->referer = "http://mp.weixin.qq.com/cgi-bin/indexpage?t=wxm-upload&lang=zh_CN&type=2&formId=1";
$t = time().strval(mt_rand(100,999));
$post = array('formId'=>'');
$postfile = array('uploadfile'=>$filepath);
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$send_snoopy->set_submit_multipart();
$submit = "http://mp.weixin.qq.com/cgi-bin/uploadmaterial?cgi=uploadmaterial&type=$type&token=".$this->_token."&t=iframe-uploadfile&lang=zh_CN&formId= file_from_".$t;
$send_snoopy->submit($submit,$post,$postfile);
$tmp = $send_snoopy->results;
$this->log('upload:'.$tmp);
preg_match("/formId,.*?\'(\d+)\'/",$tmp,$matches);
if (isset($matches[1])) {
return $matches[1];
}
return false;
} | 上传附件(图片/音频/视频)
@param string $filepath 本地文件地址
@param int $type 文件类型: 2:图片 3:音频 4:视频 | https://github.com/ddvphp/wechat/blob/b5991526e7220c2bdc6b9e7a35651c11299aa69d/org/old_version/Thinkphp/Wechatext.class.php#L263-L280 |
ddvphp/wechat | org/old_version/Thinkphp/Wechatext.class.php | Wechatext.addPreview | public function addPreview($title,$author,$summary,$content,$photoid,$srcurl='') {
$send_snoopy = new Snoopy;
$send_snoopy->referer = 'https://mp.weixin.qq.com/cgi-bin/operate_appmsg?lang=zh_CN&sub=edit&t=wxm-appmsgs-edit-new&type=10&subtype=3&token='.$this->_token;
$submit = "https://mp.weixin.qq.com/cgi-bin/operate_appmsg?lang=zh_CN&t=ajax-response&sub=create&token=".$this->_token;
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$send_snoopy->set_submit_normal();
$post = array(
'token'=>$this->_token,
'type'=>10,
'lang'=>'zh_CN',
'sub'=>'create',
'ajax'=>1,
'AppMsgId'=>'',
'error'=>'false',
);
if (count($title)==count($author)&&count($title)==count($summary)&&count($title)==count($content)&&count($title)==count($photoid))
{
$i = 0;
foreach($title as $v) {
$post['title'.$i] = $title[$i];
$post['author'.$i] = $author[$i];
$post['digest'.$i] = $summary[$i];
$post['content'.$i] = $content[$i];
$post['fileid'.$i] = $photoid[$i];
if ($srcurl[$i]) $post['sourceurl'.$i] = $srcurl[$i];
$i++;
}
}
$post['count'] = $i;
$post['token'] = $this->_token;
$send_snoopy->submit($submit,$post);
$tmp = $send_snoopy->results;
$this->log('step2:'.$tmp);
$json = json_decode($tmp,true);
return $json;
} | php | public function addPreview($title,$author,$summary,$content,$photoid,$srcurl='') {
$send_snoopy = new Snoopy;
$send_snoopy->referer = 'https://mp.weixin.qq.com/cgi-bin/operate_appmsg?lang=zh_CN&sub=edit&t=wxm-appmsgs-edit-new&type=10&subtype=3&token='.$this->_token;
$submit = "https://mp.weixin.qq.com/cgi-bin/operate_appmsg?lang=zh_CN&t=ajax-response&sub=create&token=".$this->_token;
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$send_snoopy->set_submit_normal();
$post = array(
'token'=>$this->_token,
'type'=>10,
'lang'=>'zh_CN',
'sub'=>'create',
'ajax'=>1,
'AppMsgId'=>'',
'error'=>'false',
);
if (count($title)==count($author)&&count($title)==count($summary)&&count($title)==count($content)&&count($title)==count($photoid))
{
$i = 0;
foreach($title as $v) {
$post['title'.$i] = $title[$i];
$post['author'.$i] = $author[$i];
$post['digest'.$i] = $summary[$i];
$post['content'.$i] = $content[$i];
$post['fileid'.$i] = $photoid[$i];
if ($srcurl[$i]) $post['sourceurl'.$i] = $srcurl[$i];
$i++;
}
}
$post['count'] = $i;
$post['token'] = $this->_token;
$send_snoopy->submit($submit,$post);
$tmp = $send_snoopy->results;
$this->log('step2:'.$tmp);
$json = json_decode($tmp,true);
return $json;
} | 创建图文消息
@param array $title 标题
@param array $summary 摘要
@param array $content 内容
@param array $photoid 素材库里的图片id(可通过uploadFile上传后获取)
@param array $srcurl 原文链接
@return json | https://github.com/ddvphp/wechat/blob/b5991526e7220c2bdc6b9e7a35651c11299aa69d/org/old_version/Thinkphp/Wechatext.class.php#L291-L329 |
ddvphp/wechat | org/old_version/Thinkphp/Wechatext.class.php | Wechatext.sendFile | public function sendFile($id,$fid,$type) {
$send_snoopy = new Snoopy;
$post = array();
$post['tofakeid'] = $id;
$post['type'] = $type;
$post['token'] = $this->_token;
$post['fid'] = $fid;
$post['fileid'] = $fid;
$post['error'] = 'false';
$post['ajax'] = 1;
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/singlemsgpage?fromfakeid={$id}&msgid=&source=&count=20&t=wxm-singlechat&lang=zh_CN";
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$submit = "https://mp.weixin.qq.com/cgi-bin/singlesend?t=ajax-response";
$send_snoopy->submit($submit,$post);
$result = $send_snoopy->results;
$this->log('sendfile:'.$result);
$json = json_decode($result,true);
if ($json && $json['ret']==0)
return true;
else
return false;
} | php | public function sendFile($id,$fid,$type) {
$send_snoopy = new Snoopy;
$post = array();
$post['tofakeid'] = $id;
$post['type'] = $type;
$post['token'] = $this->_token;
$post['fid'] = $fid;
$post['fileid'] = $fid;
$post['error'] = 'false';
$post['ajax'] = 1;
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/singlemsgpage?fromfakeid={$id}&msgid=&source=&count=20&t=wxm-singlechat&lang=zh_CN";
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$submit = "https://mp.weixin.qq.com/cgi-bin/singlesend?t=ajax-response";
$send_snoopy->submit($submit,$post);
$result = $send_snoopy->results;
$this->log('sendfile:'.$result);
$json = json_decode($result,true);
if ($json && $json['ret']==0)
return true;
else
return false;
} | 发送媒体文件
@param $id 用户的uid(即FakeId)
@param $fid 文件id
@param $type 文件类型 | https://github.com/ddvphp/wechat/blob/b5991526e7220c2bdc6b9e7a35651c11299aa69d/org/old_version/Thinkphp/Wechatext.class.php#L337-L358 |
ddvphp/wechat | org/old_version/Thinkphp/Wechatext.class.php | Wechatext.sendPreview | public function sendPreview($account,$title,$summary,$content,$photoid,$srcurl='') {
$send_snoopy = new Snoopy;
$submit = "https://mp.weixin.qq.com/cgi-bin/operate_appmsg?sub=preview&t=ajax-appmsg-preview";
$send_snoopy->set_submit_normal();
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$send_snoopy->referer = 'https://mp.weixin.qq.com/cgi-bin/operate_appmsg?sub=edit&t=wxm-appmsgs-edit-new&type=10&subtype=3&lang=zh_CN';
$post = array(
'AppMsgId'=>'',
'ajax'=>1,
'content0'=>$content,
'count'=>1,
'digest0'=>$summary,
'error'=>'false',
'fileid0'=>$photoid,
'preusername'=>$account,
'sourceurl0'=>$srcurl,
'title0'=>$title,
);
$post['token'] = $this->_token;
$send_snoopy->submit($submit,$post);
$tmp = $send_snoopy->results;
$this->log('sendpreview:'.$tmp);
$json = json_decode($tmp,true);
return $json;
} | php | public function sendPreview($account,$title,$summary,$content,$photoid,$srcurl='') {
$send_snoopy = new Snoopy;
$submit = "https://mp.weixin.qq.com/cgi-bin/operate_appmsg?sub=preview&t=ajax-appmsg-preview";
$send_snoopy->set_submit_normal();
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$send_snoopy->referer = 'https://mp.weixin.qq.com/cgi-bin/operate_appmsg?sub=edit&t=wxm-appmsgs-edit-new&type=10&subtype=3&lang=zh_CN';
$post = array(
'AppMsgId'=>'',
'ajax'=>1,
'content0'=>$content,
'count'=>1,
'digest0'=>$summary,
'error'=>'false',
'fileid0'=>$photoid,
'preusername'=>$account,
'sourceurl0'=>$srcurl,
'title0'=>$title,
);
$post['token'] = $this->_token;
$send_snoopy->submit($submit,$post);
$tmp = $send_snoopy->results;
$this->log('sendpreview:'.$tmp);
$json = json_decode($tmp,true);
return $json;
} | 发送预览图文消息
@param string $account 账户名称(user_name)
@param string $title 标题
@param string $summary 摘要
@param string $content 内容
@param string $photoid 素材库里的图片id(可通过uploadFile上传后获取)
@param string $srcurl 原文链接
@return json | https://github.com/ddvphp/wechat/blob/b5991526e7220c2bdc6b9e7a35651c11299aa69d/org/old_version/Thinkphp/Wechatext.class.php#L424-L448 |
ddvphp/wechat | org/old_version/Thinkphp/Wechatext.class.php | Wechatext.getInfo | public function getInfo($id)
{
$send_snoopy = new Snoopy;
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$t = time().strval(mt_rand(100,999));
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/getmessage?t=wxm-message&lang=zh_CN&count=50&token=".$this->_token;
$submit = "https://mp.weixin.qq.com/cgi-bin/getcontactinfo";
$post = array('ajax'=>1,'lang'=>'zh_CN','random'=>'0.'.$t,'token'=>$this->_token,'t'=>'ajax-getcontactinfo','fakeid'=>$id);
$send_snoopy->submit($submit,$post);
$this->log($send_snoopy->results);
$result = json_decode($send_snoopy->results,true);
if(isset($result['contact_info'])){
return $result['contact_info'];
}
return false;
} | php | public function getInfo($id)
{
$send_snoopy = new Snoopy;
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$t = time().strval(mt_rand(100,999));
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/getmessage?t=wxm-message&lang=zh_CN&count=50&token=".$this->_token;
$submit = "https://mp.weixin.qq.com/cgi-bin/getcontactinfo";
$post = array('ajax'=>1,'lang'=>'zh_CN','random'=>'0.'.$t,'token'=>$this->_token,'t'=>'ajax-getcontactinfo','fakeid'=>$id);
$send_snoopy->submit($submit,$post);
$this->log($send_snoopy->results);
$result = json_decode($send_snoopy->results,true);
if(isset($result['contact_info'])){
return $result['contact_info'];
}
return false;
} | 获取用户的信息
@param string $id 用户的uid(即FakeId)
@return array {fake_id:100001,nick_name:'昵称',user_name:'用户名',signature:'签名档',country:'中国',province:'广东',city:'广州',gender:'1',group_id:'0'},groups:{[id:0,name:'未分组',cnt:20]} | https://github.com/ddvphp/wechat/blob/b5991526e7220c2bdc6b9e7a35651c11299aa69d/org/old_version/Thinkphp/Wechatext.class.php#L455-L470 |
ddvphp/wechat | org/old_version/Thinkphp/Wechatext.class.php | Wechatext.getHeadImg | public function getHeadImg($fakeid){
$send_snoopy = new Snoopy;
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/getmessage?t=wxm-message&lang=zh_CN&count=50&token=".$this->_token;
$url = "https://mp.weixin.qq.com/misc/getheadimg?fakeid=$fakeid&token=".$this->_token."&lang=zh_CN";
$send_snoopy->fetch($url);
$result = $send_snoopy->results;
$this->log('Head image:'.$fakeid.'; length:'.strlen($result));
if(!$result){
return false;
}
return $result;
} | php | public function getHeadImg($fakeid){
$send_snoopy = new Snoopy;
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/getmessage?t=wxm-message&lang=zh_CN&count=50&token=".$this->_token;
$url = "https://mp.weixin.qq.com/misc/getheadimg?fakeid=$fakeid&token=".$this->_token."&lang=zh_CN";
$send_snoopy->fetch($url);
$result = $send_snoopy->results;
$this->log('Head image:'.$fakeid.'; length:'.strlen($result));
if(!$result){
return false;
}
return $result;
} | 获得头像数据
@param FakeId $fakeid
@return JPG二进制数据 | https://github.com/ddvphp/wechat/blob/b5991526e7220c2bdc6b9e7a35651c11299aa69d/org/old_version/Thinkphp/Wechatext.class.php#L478-L490 |
ddvphp/wechat | org/old_version/Thinkphp/Wechatext.class.php | Wechatext.getNewMsgNum | public function getNewMsgNum($lastid=0){
$send_snoopy = new Snoopy;
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/getmessage?t=wxm-message&lang=zh_CN&count=50&token=".$this->_token;
$submit = "https://mp.weixin.qq.com/cgi-bin/getnewmsgnum?t=ajax-getmsgnum&lastmsgid=".$lastid;
$post = array('ajax'=>1,'token'=>$this->_token);
$send_snoopy->submit($submit,$post);
$this->log($send_snoopy->results);
$result = json_decode($send_snoopy->results,1);
if(!$result){
return false;
}
return intval($result['newTotalMsgCount']);
} | php | public function getNewMsgNum($lastid=0){
$send_snoopy = new Snoopy;
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/getmessage?t=wxm-message&lang=zh_CN&count=50&token=".$this->_token;
$submit = "https://mp.weixin.qq.com/cgi-bin/getnewmsgnum?t=ajax-getmsgnum&lastmsgid=".$lastid;
$post = array('ajax'=>1,'token'=>$this->_token);
$send_snoopy->submit($submit,$post);
$this->log($send_snoopy->results);
$result = json_decode($send_snoopy->results,1);
if(!$result){
return false;
}
return intval($result['newTotalMsgCount']);
} | 获取消息更新数目
@param int $lastid 最近获取的消息ID,为0时获取总消息数目
@return int 数目 | https://github.com/ddvphp/wechat/blob/b5991526e7220c2bdc6b9e7a35651c11299aa69d/org/old_version/Thinkphp/Wechatext.class.php#L497-L510 |
ddvphp/wechat | org/old_version/Thinkphp/Wechatext.class.php | Wechatext.getTopMsg | public function getTopMsg(){
$send_snoopy = new Snoopy;
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/message?t=message/list&count=20&day=7&lang=zh_CN&token=".$this->_token;
$submit = "https://mp.weixin.qq.com/cgi-bin/message?t=message/list&f=json&count=20&day=7&lang=zh_CN&token=".$this->_token;
$send_snoopy->fetch($submit);
$this->log($send_snoopy->results);
$result = $send_snoopy->results;
$json = json_decode($result,true);
if (isset($json['msg_items'])) {
$json = json_decode($json['msg_items'],true);
if(isset($json['msg_item']))
return array_shift($json['msg_item']);
}
return false;
} | php | public function getTopMsg(){
$send_snoopy = new Snoopy;
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/message?t=message/list&count=20&day=7&lang=zh_CN&token=".$this->_token;
$submit = "https://mp.weixin.qq.com/cgi-bin/message?t=message/list&f=json&count=20&day=7&lang=zh_CN&token=".$this->_token;
$send_snoopy->fetch($submit);
$this->log($send_snoopy->results);
$result = $send_snoopy->results;
$json = json_decode($result,true);
if (isset($json['msg_items'])) {
$json = json_decode($json['msg_items'],true);
if(isset($json['msg_item']))
return array_shift($json['msg_item']);
}
return false;
} | 获取最新一条消息
@return array {"id":"最新一条id","type":"类型号(1为文字,2为图片,3为语音)","fileId":"0","hasReply":"0","fakeId":"用户uid","nickName":"昵称","dateTime":"时间戳","content":"文字内容","playLength":"0","length":"0","source":"","starred":"0","status":"4"} | https://github.com/ddvphp/wechat/blob/b5991526e7220c2bdc6b9e7a35651c11299aa69d/org/old_version/Thinkphp/Wechatext.class.php#L516-L531 |
ddvphp/wechat | org/old_version/Thinkphp/Wechatext.class.php | Wechatext.getMsg | public function getMsg($lastid=0,$offset=0,$perpage=20,$day=7,$today=0,$star=0){
$send_snoopy = new Snoopy;
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/message?t=message/list&lang=zh_CN&count=50&token=".$this->_token;
$lastid = $lastid===0 ? '':$lastid;
$addstar = $star?'&action=star':'';
$submit = "https://mp.weixin.qq.com/cgi-bin/message?t=message/list&f=json&lang=zh_CN{$addstar}&count=$perpage&timeline=$today&day=$day&frommsgid=$lastid&offset=$offset&token=".$this->_token;
$send_snoopy->fetch($submit);
$this->log($send_snoopy->results);
$result = $send_snoopy->results;
$json = json_decode($result,true);
if (isset($json['msg_items'])) {
$json = json_decode($json['msg_items'],true);
if(isset($json['msg_item']))
return $json['msg_item'];
}
return false;
} | php | public function getMsg($lastid=0,$offset=0,$perpage=20,$day=7,$today=0,$star=0){
$send_snoopy = new Snoopy;
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/message?t=message/list&lang=zh_CN&count=50&token=".$this->_token;
$lastid = $lastid===0 ? '':$lastid;
$addstar = $star?'&action=star':'';
$submit = "https://mp.weixin.qq.com/cgi-bin/message?t=message/list&f=json&lang=zh_CN{$addstar}&count=$perpage&timeline=$today&day=$day&frommsgid=$lastid&offset=$offset&token=".$this->_token;
$send_snoopy->fetch($submit);
$this->log($send_snoopy->results);
$result = $send_snoopy->results;
$json = json_decode($result,true);
if (isset($json['msg_items'])) {
$json = json_decode($json['msg_items'],true);
if(isset($json['msg_item']))
return $json['msg_item'];
}
return false;
} | 获取新消息
@param $lastid 传入最后的消息id编号,为0则从最新一条起倒序获取
@param $offset lastid起算第一条的偏移量
@param $perpage 每页获取多少条
@param $day 最近几天消息(0:今天,1:昨天,2:前天,3:更早,7:五天内)
@param $today 是否只显示今天的消息, 与$day参数不能同时大于0
@param $star 是否星标组信息
@return array[] 同getTopMsg()返回的字段结构相同 | https://github.com/ddvphp/wechat/blob/b5991526e7220c2bdc6b9e7a35651c11299aa69d/org/old_version/Thinkphp/Wechatext.class.php#L543-L560 |
ddvphp/wechat | org/old_version/Thinkphp/Wechatext.class.php | Wechatext.getMsgImage | public function getMsgImage($msgid,$mode='large'){
$send_snoopy = new Snoopy;
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/getmessage?t=wxm-message&lang=zh_CN&count=50&token=".$this->_token;
$url = "https://mp.weixin.qq.com/cgi-bin/getimgdata?token=".$this->_token."&msgid=$msgid&mode=$mode&source=&fileId=0";
$send_snoopy->fetch($url);
$result = $send_snoopy->results;
$this->log('msg image:'.$msgid.';length:'.strlen($result));
if(!$result){
return false;
}
return $result;
} | php | public function getMsgImage($msgid,$mode='large'){
$send_snoopy = new Snoopy;
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/getmessage?t=wxm-message&lang=zh_CN&count=50&token=".$this->_token;
$url = "https://mp.weixin.qq.com/cgi-bin/getimgdata?token=".$this->_token."&msgid=$msgid&mode=$mode&source=&fileId=0";
$send_snoopy->fetch($url);
$result = $send_snoopy->results;
$this->log('msg image:'.$msgid.';length:'.strlen($result));
if(!$result){
return false;
}
return $result;
} | 获取图片消息
@param int $msgid 消息id
@param string $mode 图片尺寸(large/small)
@return jpg二进制文件 | https://github.com/ddvphp/wechat/blob/b5991526e7220c2bdc6b9e7a35651c11299aa69d/org/old_version/Thinkphp/Wechatext.class.php#L568-L580 |
ddvphp/wechat | org/old_version/Thinkphp/Wechatext.class.php | Wechatext.openDevModel | public function openDevModel()
{
$send_snoopy = new Snoopy;
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$send_snoopy->referer = "https://mp.weixin.qq.com/advanced/advanced?action=dev&t=advanced/dev&lang=zh_CN&token=".$this->_token;
$submit = "https://mp.weixin.qq.com/misc/skeyform?form=advancedswitchform&lang=zh_CN";
$post['flag']=1;
$post['type']=2;
$post['token']=$this->_token;
$send_snoopy->submit($submit,$post);
$result = $send_snoopy->results;
$this->log($send_snoopy->results);
$json = json_decode($result,true);
if(!$result){
return false;
}
return true;
} | php | public function openDevModel()
{
$send_snoopy = new Snoopy;
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$send_snoopy->referer = "https://mp.weixin.qq.com/advanced/advanced?action=dev&t=advanced/dev&lang=zh_CN&token=".$this->_token;
$submit = "https://mp.weixin.qq.com/misc/skeyform?form=advancedswitchform&lang=zh_CN";
$post['flag']=1;
$post['type']=2;
$post['token']=$this->_token;
$send_snoopy->submit($submit,$post);
$result = $send_snoopy->results;
$this->log($send_snoopy->results);
$json = json_decode($result,true);
if(!$result){
return false;
}
return true;
} | 开启开发者模式 | https://github.com/ddvphp/wechat/blob/b5991526e7220c2bdc6b9e7a35651c11299aa69d/org/old_version/Thinkphp/Wechatext.class.php#L604-L621 |
ddvphp/wechat | org/old_version/Thinkphp/Wechatext.class.php | Wechatext.quickSetInterface | public function quickSetInterface($url, $token)
{
if ($this->closeEditModel() && $this->openDevModel() && $this->setUrlToken($url, $token))
return true;
return false;
} | php | public function quickSetInterface($url, $token)
{
if ($this->closeEditModel() && $this->openDevModel() && $this->setUrlToken($url, $token))
return true;
return false;
} | 快速设置接口
@param string $url 接口回调URL
@param string $token 接口Token | https://github.com/ddvphp/wechat/blob/b5991526e7220c2bdc6b9e7a35651c11299aa69d/org/old_version/Thinkphp/Wechatext.class.php#L672-L677 |
ddvphp/wechat | org/old_version/Thinkphp/Wechatext.class.php | Wechatext.login | public function login(){
$snoopy = new Snoopy;
$submit = "https://mp.weixin.qq.com/cgi-bin/login?lang=zh_CN";
$post["username"] = $this->_account;
$post["pwd"] = md5($this->_password);
$post["f"] = "json";
$post["imgcode"] = "";
$snoopy->referer = "https://mp.weixin.qq.com/";
$snoopy->submit($submit,$post);
$cookie = '';
$this->log($snoopy->results);
$result = json_decode($snoopy->results,true);
if (!isset($result['base_resp']) || $result['base_resp']['ret'] != 0) {
return false;
}
foreach ($snoopy->headers as $key => $value) {
$value = trim($value);
if(preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $value,$match))
$cookie .=$match[1].'='.$match[2].'; ';
}
preg_match("/token=(\d+)/i",$result['redirect_url'],$matches);
if($matches){
$this->_token = $matches[1];
$this->log('token:'.$this->_token);
}
$cookies='{"cookie":"'.$cookie.'","token":"'.$this->_token.'"}';
$this->saveCookie($this->_cookiename,$cookies);
return $cookie;
} | php | public function login(){
$snoopy = new Snoopy;
$submit = "https://mp.weixin.qq.com/cgi-bin/login?lang=zh_CN";
$post["username"] = $this->_account;
$post["pwd"] = md5($this->_password);
$post["f"] = "json";
$post["imgcode"] = "";
$snoopy->referer = "https://mp.weixin.qq.com/";
$snoopy->submit($submit,$post);
$cookie = '';
$this->log($snoopy->results);
$result = json_decode($snoopy->results,true);
if (!isset($result['base_resp']) || $result['base_resp']['ret'] != 0) {
return false;
}
foreach ($snoopy->headers as $key => $value) {
$value = trim($value);
if(preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $value,$match))
$cookie .=$match[1].'='.$match[2].'; ';
}
preg_match("/token=(\d+)/i",$result['redirect_url'],$matches);
if($matches){
$this->_token = $matches[1];
$this->log('token:'.$this->_token);
}
$cookies='{"cookie":"'.$cookie.'","token":"'.$this->_token.'"}';
$this->saveCookie($this->_cookiename,$cookies);
return $cookie;
} | 模拟登录获取cookie
@return [type] [description] | https://github.com/ddvphp/wechat/blob/b5991526e7220c2bdc6b9e7a35651c11299aa69d/org/old_version/Thinkphp/Wechatext.class.php#L683-L714 |
ddvphp/wechat | org/old_version/Thinkphp/Wechatext.class.php | Wechatext.getCookie | public function getCookie($filename){
$data = S($filename);
if($data){
$login=json_decode($data,true);
$send_snoopy = new Snoopy;
$send_snoopy->rawheaders['Cookie']= $login['cookie'];
$send_snoopy->maxredirs = 0;
$url = "https://mp.weixin.qq.com/cgi-bin/home?t=home/index&lang=zh_CN&token=".$login['token'];
$send_snoopy->fetch($url);
$header = $send_snoopy->headers;
$this->log('header:'.print_r($send_snoopy->headers,true));
if( strstr($header[3], 'EXPIRED')){
return $this->login();
}else{
$this->_token =$login['token'];
return $login['cookie'];
}
}else{
return $this->login();
}
} | php | public function getCookie($filename){
$data = S($filename);
if($data){
$login=json_decode($data,true);
$send_snoopy = new Snoopy;
$send_snoopy->rawheaders['Cookie']= $login['cookie'];
$send_snoopy->maxredirs = 0;
$url = "https://mp.weixin.qq.com/cgi-bin/home?t=home/index&lang=zh_CN&token=".$login['token'];
$send_snoopy->fetch($url);
$header = $send_snoopy->headers;
$this->log('header:'.print_r($send_snoopy->headers,true));
if( strstr($header[3], 'EXPIRED')){
return $this->login();
}else{
$this->_token =$login['token'];
return $login['cookie'];
}
}else{
return $this->login();
}
} | 读取cookie缓存内容
@param string $filename 缓存文件名
@return string cookie | https://github.com/ddvphp/wechat/blob/b5991526e7220c2bdc6b9e7a35651c11299aa69d/org/old_version/Thinkphp/Wechatext.class.php#L731-L751 |
ddvphp/wechat | org/old_version/Thinkphp/Wechatext.class.php | Wechatext.checkValid | public function checkValid()
{
if (!$this->cookie || !$this->_token) return false;
$send_snoopy = new Snoopy;
$post = array('ajax'=>1,'token'=>$this->_token);
$submit = "https://mp.weixin.qq.com/cgi-bin/getregions?id=1017&t=ajax-getregions&lang=zh_CN";
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$send_snoopy->submit($submit,$post);
$result = $send_snoopy->results;
if(json_decode($result,1)){
return true;
}else{
return false;
}
} | php | public function checkValid()
{
if (!$this->cookie || !$this->_token) return false;
$send_snoopy = new Snoopy;
$post = array('ajax'=>1,'token'=>$this->_token);
$submit = "https://mp.weixin.qq.com/cgi-bin/getregions?id=1017&t=ajax-getregions&lang=zh_CN";
$send_snoopy->rawheaders['Cookie']= $this->cookie;
$send_snoopy->submit($submit,$post);
$result = $send_snoopy->results;
if(json_decode($result,1)){
return true;
}else{
return false;
}
} | 验证cookie的有效性
@return bool | https://github.com/ddvphp/wechat/blob/b5991526e7220c2bdc6b9e7a35651c11299aa69d/org/old_version/Thinkphp/Wechatext.class.php#L757-L771 |
PlatoCreative/silverstripe-better-meta | code/models/SchemaObject.php | SchemaObject.getTitle | public function getTitle()
{
$title = parent::getTitle();
if ($this->Config()->title_pattern) {
$title = $this->Config()->title_pattern;
}
return $title;
} | php | public function getTitle()
{
$title = parent::getTitle();
if ($this->Config()->title_pattern) {
$title = $this->Config()->title_pattern;
}
return $title;
} | CMS Title
@return string | https://github.com/PlatoCreative/silverstripe-better-meta/blob/48f8afc6d5c9a86a135b86249ffbe038060e9e26/code/models/SchemaObject.php#L38-L45 |
antaresproject/translations | src/Processor/Publisher.php | Publisher.publish | public function publish($language)
{
$translations = $this->getTranslationGroups($language->translations);
foreach ($translations as $area => $groups) {
foreach ($groups as $group => $items) {
if (!isset($this->hints[$group])) {
continue;
}
$path = $this->getResourcePath($language->code, $area, $group);
$this->publishTranslations($path, $items);
}
$this->putGitignore($area);
}
return true;
} | php | public function publish($language)
{
$translations = $this->getTranslationGroups($language->translations);
foreach ($translations as $area => $groups) {
foreach ($groups as $group => $items) {
if (!isset($this->hints[$group])) {
continue;
}
$path = $this->getResourcePath($language->code, $area, $group);
$this->publishTranslations($path, $items);
}
$this->putGitignore($area);
}
return true;
} | publish translations from database
@param \Illuminate\Database\Eloquent\Model $language
@return boolean | https://github.com/antaresproject/translations/blob/63097aeb97f18c5aeeef7dcf15f0c67959951685/src/Processor/Publisher.php#L65-L79 |
antaresproject/translations | src/Processor/Publisher.php | Publisher.putGitignore | protected function putGitignore($area)
{
$target = resource_path(implode(DIRECTORY_SEPARATOR, ['lang', $area, '.gitignore']));
if (!file_exists($target)) {
return $this->filesystem->put($target, "*\n!.gitignore");
}
return true;
} | php | protected function putGitignore($area)
{
$target = resource_path(implode(DIRECTORY_SEPARATOR, ['lang', $area, '.gitignore']));
if (!file_exists($target)) {
return $this->filesystem->put($target, "*\n!.gitignore");
}
return true;
} | Puts gitignore file in lang directory
@param String $area
@return boolean | https://github.com/antaresproject/translations/blob/63097aeb97f18c5aeeef7dcf15f0c67959951685/src/Processor/Publisher.php#L87-L94 |
antaresproject/translations | src/Processor/Publisher.php | Publisher.getResourcePath | protected function getResourcePath($locale, $area, $group)
{
$path = resource_path(implode(DIRECTORY_SEPARATOR, ['lang', $area, $group, $locale]));
if ($this->filesystem->exists($path)) {
$this->filesystem->cleanDirectory($path);
} else {
$this->filesystem->makeDirectory($path, 0755, true);
}
return $path;
} | php | protected function getResourcePath($locale, $area, $group)
{
$path = resource_path(implode(DIRECTORY_SEPARATOR, ['lang', $area, $group, $locale]));
if ($this->filesystem->exists($path)) {
$this->filesystem->cleanDirectory($path);
} else {
$this->filesystem->makeDirectory($path, 0755, true);
}
return $path;
} | Gets resource path
@param String $locale
@param String $area
@param String $group
@return String | https://github.com/antaresproject/translations/blob/63097aeb97f18c5aeeef7dcf15f0c67959951685/src/Processor/Publisher.php#L104-L113 |
antaresproject/translations | src/Processor/Publisher.php | Publisher.publishTranslations | protected function publishTranslations($path, array $items)
{
foreach ($items as $filename => $translations) {
$content = "<?php
/**
* Part of the Antares package.
*
* NOTICE OF LICENSE
*
* Licensed under the 3-clause BSD License.
*
* This source file is subject to the 3-clause BSD License that is
* bundled with this package in the LICENSE file.
*
* @package Translations
* @version 0.9.0
* @author Antares Team
* @license BSD License (3-clause)
* @copyright (c) 2017, Antares
* @link http://antaresproject.io
*/
\n return\n\n " . var_export($translations, true) . ";\n";
file_put_contents($path . DIRECTORY_SEPARATOR . $filename . '.php', $content);
}
return true;
} | php | protected function publishTranslations($path, array $items)
{
foreach ($items as $filename => $translations) {
$content = "<?php
/**
* Part of the Antares package.
*
* NOTICE OF LICENSE
*
* Licensed under the 3-clause BSD License.
*
* This source file is subject to the 3-clause BSD License that is
* bundled with this package in the LICENSE file.
*
* @package Translations
* @version 0.9.0
* @author Antares Team
* @license BSD License (3-clause)
* @copyright (c) 2017, Antares
* @link http://antaresproject.io
*/
\n return\n\n " . var_export($translations, true) . ";\n";
file_put_contents($path . DIRECTORY_SEPARATOR . $filename . '.php', $content);
}
return true;
} | writing translations to files
@param String $path
@param array $items
@return boolean | https://github.com/antaresproject/translations/blob/63097aeb97f18c5aeeef7dcf15f0c67959951685/src/Processor/Publisher.php#L122-L150 |
antaresproject/translations | src/Processor/Publisher.php | Publisher.getTranslationGroups | protected function getTranslationGroups(Collection $list)
{
$groups = [];
foreach ($list as $model) {
if (!isset($groups[$model->area][$model->group])) {
$groups[$model->area][$model->group] = [];
}
$groups[$model->area][$model->group] = Arr::add($groups[$model->area][$model->group], $model->key, $model->value);
}
return $groups;
} | php | protected function getTranslationGroups(Collection $list)
{
$groups = [];
foreach ($list as $model) {
if (!isset($groups[$model->area][$model->group])) {
$groups[$model->area][$model->group] = [];
}
$groups[$model->area][$model->group] = Arr::add($groups[$model->area][$model->group], $model->key, $model->value);
}
return $groups;
} | grouping translations by component name
@param Collection $list
@return array | https://github.com/antaresproject/translations/blob/63097aeb97f18c5aeeef7dcf15f0c67959951685/src/Processor/Publisher.php#L158-L168 |
bennybi/yii2-cza-base | components/actions/common/OptionsListAction.php | OptionsListAction.prepareDataProvider | protected function prepareDataProvider($params = []) {
if (!isset($params['q'])) {
throw new Exception('Require parameter "q"!');
}
$data = [];
$modelClass = $this->modelClass;
$listMethod = $this->listMethod;
if (!is_null($params['q'])) {
$data['results'] = $modelClass::$listMethod($this->keyAttribute, $this->valueAttribute, "{$this->queryAttribute} like '%{$params['q']}%'", $params);
} else {
$data['results'] = $modelClass::$listMethod($this->keyAttribute, $this->valueAttribute, '', $params);
}
return $data;
} | php | protected function prepareDataProvider($params = []) {
if (!isset($params['q'])) {
throw new Exception('Require parameter "q"!');
}
$data = [];
$modelClass = $this->modelClass;
$listMethod = $this->listMethod;
if (!is_null($params['q'])) {
$data['results'] = $modelClass::$listMethod($this->keyAttribute, $this->valueAttribute, "{$this->queryAttribute} like '%{$params['q']}%'", $params);
} else {
$data['results'] = $modelClass::$listMethod($this->keyAttribute, $this->valueAttribute, '', $params);
}
return $data;
} | Prepares the data provider that should return the requested collection of the models.
@return array | https://github.com/bennybi/yii2-cza-base/blob/8257db8034bd948712fa469062921f210f0ba8da/components/actions/common/OptionsListAction.php#L56-L69 |
factorio-item-browser/api-client | src/Service/EndpointService.php | EndpointService.getEndpointForRequest | public function getEndpointForRequest(RequestInterface $request): EndpointInterface
{
$requestClass = get_class($request);
if (!isset($this->endpointsByRequestClass[$requestClass])) {
throw new UnsupportedRequestException($requestClass);
}
return $this->endpointsByRequestClass[$requestClass];
} | php | public function getEndpointForRequest(RequestInterface $request): EndpointInterface
{
$requestClass = get_class($request);
if (!isset($this->endpointsByRequestClass[$requestClass])) {
throw new UnsupportedRequestException($requestClass);
}
return $this->endpointsByRequestClass[$requestClass];
} | Returns the endpoint for the request.
@param RequestInterface $request
@return EndpointInterface
@throws UnsupportedRequestException | https://github.com/factorio-item-browser/api-client/blob/ebda897483bd537c310a17ff868ca40c0568f728/src/Service/EndpointService.php#L42-L50 |
fxpio/fxp-gluon | Block/Extension/AbstractRaisedExtension.php | AbstractRaisedExtension.configureOptions | public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'raised' => false,
]);
$resolver->addAllowedTypes('raised', ['bool', 'string']);
$resolver->addAllowedValues('raised', [true, false, 'flat']);
} | php | public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'raised' => false,
]);
$resolver->addAllowedTypes('raised', ['bool', 'string']);
$resolver->addAllowedValues('raised', [true, false, 'flat']);
} | {@inheritdoc} | https://github.com/fxpio/fxp-gluon/blob/0548b7d598ef4b0785b5df3b849a10f439b2dc65/Block/Extension/AbstractRaisedExtension.php#L39-L47 |
matryoshka-model/matryoshka | library/Object/PrototypeStrategy/Service/ServiceLocatorStrategyFactory.php | ServiceLocatorStrategyFactory.createService | public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $this->getConfig($serviceLocator);
if (isset($config['service_locator'])) {
$objectServiceLocator = $serviceLocator->get($config['service_locator']);
} else {
$objectServiceLocator = $serviceLocator->has('Matryoshka\Model\Object\ObjectManager') ?
$serviceLocator->get('Matryoshka\Model\Object\ObjectManager')
: $serviceLocator;
}
$strategy = new ServiceLocatorStrategy($objectServiceLocator);
if (isset($config['type_field'])) {
$strategy->setTypeField($config['type_field']);
}
if (isset($config['validate_object'])) {
$strategy->setValidateObject($config['validate_object']);
}
if (isset($config['clone_object'])) {
$strategy->setCloneObject($config['clone_object']);
}
return $strategy;
} | php | public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $this->getConfig($serviceLocator);
if (isset($config['service_locator'])) {
$objectServiceLocator = $serviceLocator->get($config['service_locator']);
} else {
$objectServiceLocator = $serviceLocator->has('Matryoshka\Model\Object\ObjectManager') ?
$serviceLocator->get('Matryoshka\Model\Object\ObjectManager')
: $serviceLocator;
}
$strategy = new ServiceLocatorStrategy($objectServiceLocator);
if (isset($config['type_field'])) {
$strategy->setTypeField($config['type_field']);
}
if (isset($config['validate_object'])) {
$strategy->setValidateObject($config['validate_object']);
}
if (isset($config['clone_object'])) {
$strategy->setCloneObject($config['clone_object']);
}
return $strategy;
} | Create service
@param ServiceLocatorInterface $serviceLocator
@return mixed | https://github.com/matryoshka-model/matryoshka/blob/51792df00d9897f556d5a3c53193eed0974ff09d/library/Object/PrototypeStrategy/Service/ServiceLocatorStrategyFactory.php#L37-L64 |
anklimsk/cakephp-console-installer | Console/Helper/WaitingShellHelper.php | WaitingShellHelper._getAnimateChar | protected function _getAnimateChar() {
if ($this->_animateCharNum >= count($this->_animateChars)) {
$this->_animateCharNum = 0;
}
return $this->_animateChars[$this->_animateCharNum++];
} | php | protected function _getAnimateChar() {
if ($this->_animateCharNum >= count($this->_animateChars)) {
$this->_animateCharNum = 0;
}
return $this->_animateChars[$this->_animateCharNum++];
} | Get char for animate
@return string | https://github.com/anklimsk/cakephp-console-installer/blob/76136550e856ff4f8fd3634b77633f86510f63e9/Console/Helper/WaitingShellHelper.php#L58-L64 |
anklimsk/cakephp-console-installer | Console/Helper/WaitingShellHelper.php | WaitingShellHelper.animateMessage | public function animateMessage() {
if (!$this->_showMessage) {
$this->_showMessage = true;
$this->_animateCharNum = 0;
$msg = $this->_getWaitMsg();
$msg .= ' ' . $this->_getAnimateChar();
$this->_consoleOutput->write($msg, 0);
} else {
$msg = $this->_getAnimateChar();
$this->_consoleOutput->overwrite($msg, 0, mb_strlen($msg));
}
} | php | public function animateMessage() {
if (!$this->_showMessage) {
$this->_showMessage = true;
$this->_animateCharNum = 0;
$msg = $this->_getWaitMsg();
$msg .= ' ' . $this->_getAnimateChar();
$this->_consoleOutput->write($msg, 0);
} else {
$msg = $this->_getAnimateChar();
$this->_consoleOutput->overwrite($msg, 0, mb_strlen($msg));
}
} | Print message 'Please wait...' and animate char on console
@return void | https://github.com/anklimsk/cakephp-console-installer/blob/76136550e856ff4f8fd3634b77633f86510f63e9/Console/Helper/WaitingShellHelper.php#L82-L93 |
anklimsk/cakephp-console-installer | Console/Helper/WaitingShellHelper.php | WaitingShellHelper.hideMessage | public function hideMessage() {
if (!$this->_showMessage) {
return;
}
$msg = $this->_getWaitMsg();
$msg .= ' x';
$this->_consoleOutput->write(str_repeat("\x08", mb_strlen($msg)), 0);
$this->_showMessage = false;
} | php | public function hideMessage() {
if (!$this->_showMessage) {
return;
}
$msg = $this->_getWaitMsg();
$msg .= ' x';
$this->_consoleOutput->write(str_repeat("\x08", mb_strlen($msg)), 0);
$this->_showMessage = false;
} | Hide message 'Please wait...' on console
@return void | https://github.com/anklimsk/cakephp-console-installer/blob/76136550e856ff4f8fd3634b77633f86510f63e9/Console/Helper/WaitingShellHelper.php#L100-L109 |
schpill/thin | src/Controller/Uri.php | Uri.factory | public static function factory($uri = 'http', $className = null)
{
// Separate the scheme from the scheme-specific parts
$uri = explode(':', $uri, 2);
$scheme = strtolower($uri[0]);
$schemeSpecific = isset($uri[1]) === true ? $uri[1] : '';
if (strlen($scheme) === 0) {
throw new Exception('An empty string was supplied for the scheme');
}
// Security check: $scheme is used to load a class file, so only alphanumerics are allowed.
if (ctype_alnum($scheme) === false) {
throw new Exception('Illegal scheme supplied, only alphanumeric characters are permitted');
}
if ($className === null) {
/**
* Create a new Uri object for the $uri. If a subclass of Uri exists for the
* scheme, return an instance of that class. Otherwise, a Exception is thrown.
*/
switch ($scheme) {
case 'http':
// Break intentionally omitted
case 'https':
$className = '\\Thin\\Controller\\Uri\\Http';
break;
case 'mailto':
// TODO
default:
throw new Exception("Scheme $scheme is not supported");
break;
}
}
$schemeHandler = new $className($scheme, $schemeSpecific);
if (! $schemeHandler instanceof Uri) {
throw new Exception('"' . $className . '" is not an instance of Uri');
}
return $schemeHandler;
} | php | public static function factory($uri = 'http', $className = null)
{
// Separate the scheme from the scheme-specific parts
$uri = explode(':', $uri, 2);
$scheme = strtolower($uri[0]);
$schemeSpecific = isset($uri[1]) === true ? $uri[1] : '';
if (strlen($scheme) === 0) {
throw new Exception('An empty string was supplied for the scheme');
}
// Security check: $scheme is used to load a class file, so only alphanumerics are allowed.
if (ctype_alnum($scheme) === false) {
throw new Exception('Illegal scheme supplied, only alphanumeric characters are permitted');
}
if ($className === null) {
/**
* Create a new Uri object for the $uri. If a subclass of Uri exists for the
* scheme, return an instance of that class. Otherwise, a Exception is thrown.
*/
switch ($scheme) {
case 'http':
// Break intentionally omitted
case 'https':
$className = '\\Thin\\Controller\\Uri\\Http';
break;
case 'mailto':
// TODO
default:
throw new Exception("Scheme $scheme is not supported");
break;
}
}
$schemeHandler = new $className($scheme, $schemeSpecific);
if (! $schemeHandler instanceof Uri) {
throw new Exception('"' . $className . '" is not an instance of Uri');
}
return $schemeHandler;
} | Create a new Uri object for a URI. If building a new URI, then $uri should contain
only the scheme (http, ftp, etc). Otherwise, supply $uri with the complete URI.
@param string $uri The URI form which a Uri instance is created
@param string $className The name of the class to use in order to manipulate URI
@throws Exception When an empty string was supplied for the scheme
@throws Exception When an illegal scheme is supplied
@throws Exception When the scheme is not supported
@throws Exception When $className doesn't exist or doesn't implements Uri
@return Uri
@link http://www.faqs.org/rfcs/rfc2396.html | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Controller/Uri.php#L72-L115 |
schpill/thin | src/Controller/Uri.php | Uri.setConfig | static public function setConfig($config)
{
if (!is_array($config)) {
throw new Exception("Config must be an array.");
}
foreach ($config as $k => $v) {
self::$_config[$k] = $v;
}
} | php | static public function setConfig($config)
{
if (!is_array($config)) {
throw new Exception("Config must be an array.");
}
foreach ($config as $k => $v) {
self::$_config[$k] = $v;
}
} | Set global configuration options
@param array $config | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Controller/Uri.php#L136-L145 |
as3io/modlr | src/Models/Embeds/HasMany.php | HasMany.areDirty | public function areDirty()
{
if (true === parent::areDirty()) {
return true;
}
foreach ($this->getOriginalAll() as $collection) {
if (true === $collection->isDirty()) {
return true;
}
}
return false;
} | php | public function areDirty()
{
if (true === parent::areDirty()) {
return true;
}
foreach ($this->getOriginalAll() as $collection) {
if (true === $collection->isDirty()) {
return true;
}
}
return false;
} | Extended to also check for dirty states of has-many Collections.
{@inheritDoc} | https://github.com/as3io/modlr/blob/7e684b88bb22a2e18397df9402075c6533084b16/src/Models/Embeds/HasMany.php#L20-L31 |
as3io/modlr | src/Models/Embeds/HasMany.php | HasMany.rollback | public function rollback()
{
parent::rollback();
foreach ($this->getOriginalAll() as $collection) {
if ($collection instanceof EmbedCollection) {
$collection->rollback();
}
}
return $this;
} | php | public function rollback()
{
parent::rollback();
foreach ($this->getOriginalAll() as $collection) {
if ($collection instanceof EmbedCollection) {
$collection->rollback();
}
}
return $this;
} | Extended to also rollback changes of has-many collections.
{@inheritDoc} | https://github.com/as3io/modlr/blob/7e684b88bb22a2e18397df9402075c6533084b16/src/Models/Embeds/HasMany.php#L38-L47 |
as3io/modlr | src/Models/Embeds/HasMany.php | HasMany.calculateChangeSet | public function calculateChangeSet()
{
$set = [];
foreach ($this->getOriginalAll() as $key => $collection) {
if (false === $collection->isDirty()) {
continue;
}
$set[$key] = $collection->calculateChangeSet();
}
return $set;
} | php | public function calculateChangeSet()
{
$set = [];
foreach ($this->getOriginalAll() as $key => $collection) {
if (false === $collection->isDirty()) {
continue;
}
$set[$key] = $collection->calculateChangeSet();
}
return $set;
} | Overwritten to account for collection change sets.
{@inheritDoc} | https://github.com/as3io/modlr/blob/7e684b88bb22a2e18397df9402075c6533084b16/src/Models/Embeds/HasMany.php#L54-L64 |
brainexe/core | src/Middleware/Locale.php | Locale.processRequest | public function processRequest(Request $request, Route $route)
{
if ($request->attributes->has('locale')) {
return;
}
$session = $request->getSession();
if ($request->query->has('locale')) {
$availableLocales = $this->locale->getLocales();
$locale = $request->query->get('locale');
if (!in_array($locale, $availableLocales, true)) {
// invalid locale -> use first defined locale as fallback
$locale = $availableLocales[0];
}
$session->set('locale', $locale);
} else {
$locale = $session->get('locale');
}
if ($locale) {
$this->locale->setLocale($locale);
$request->attributes->set('locale', $locale);
}
} | php | public function processRequest(Request $request, Route $route)
{
if ($request->attributes->has('locale')) {
return;
}
$session = $request->getSession();
if ($request->query->has('locale')) {
$availableLocales = $this->locale->getLocales();
$locale = $request->query->get('locale');
if (!in_array($locale, $availableLocales, true)) {
// invalid locale -> use first defined locale as fallback
$locale = $availableLocales[0];
}
$session->set('locale', $locale);
} else {
$locale = $session->get('locale');
}
if ($locale) {
$this->locale->setLocale($locale);
$request->attributes->set('locale', $locale);
}
} | {@inheritdoc} | https://github.com/brainexe/core/blob/9ef69c6f045306abd20e271572386970db9b3e54/src/Middleware/Locale.php#L32-L58 |
apishka/easy-extend | source/Command/Collect.php | Collect.execute | protected function execute(InputInterface $input, OutputInterface $output): void
{
$output->writeln('Apishka Easy Extend config generation');
$builder = new Builder();
$builder->buildFromCache();
$output->writeln('Done');
} | php | protected function execute(InputInterface $input, OutputInterface $output): void
{
$output->writeln('Apishka Easy Extend config generation');
$builder = new Builder();
$builder->buildFromCache();
$output->writeln('Done');
} | Execute
@param InputInterface $input
@param OutputInterface $output | https://github.com/apishka/easy-extend/blob/5e5c63c2509377abc3db6956e353623683703e09/source/Command/Collect.php#L32-L40 |
gregorybesson/PlaygroundFlow | src/Service/Story.php | Story.getStoryMapper | public function getStoryMapper()
{
if (null === $this->storyMapper) {
$this->storyMapper = $this->serviceLocator->get('playgroundflow_story_mapper');
}
return $this->storyMapper;
} | php | public function getStoryMapper()
{
if (null === $this->storyMapper) {
$this->storyMapper = $this->serviceLocator->get('playgroundflow_story_mapper');
}
return $this->storyMapper;
} | getStoryMapper
@return StoryMapperInterface | https://github.com/gregorybesson/PlaygroundFlow/blob/f97493f8527e425d46223ac7b5c41331ab8b3022/src/Service/Story.php#L78-L85 |
YiMAproject/yimaWidgetator | src/yimaWidgetator/AbstractWidgetHelper.php | AbstractWidgetHelper.addWidget | function addWidget($region, $widget, $priority = 0)
{
if (!$this->rBoxContainer) {
$sm = $this->getServiceLocator()->getServiceLocator();
$rBoxContainer = $sm->get('yimaWidgetator.Widgetizer.Container');
$this->rBoxContainer = $rBoxContainer;
}
$this->rBoxContainer->addWidget($region, $widget, $priority);
return $this;
} | php | function addWidget($region, $widget, $priority = 0)
{
if (!$this->rBoxContainer) {
$sm = $this->getServiceLocator()->getServiceLocator();
$rBoxContainer = $sm->get('yimaWidgetator.Widgetizer.Container');
$this->rBoxContainer = $rBoxContainer;
}
$this->rBoxContainer->addWidget($region, $widget, $priority);
return $this;
} | Add Widget To Region Box Container
@param $region
@param $widget
@param int $priority
@return $this | https://github.com/YiMAproject/yimaWidgetator/blob/332bc9318e6ceaec918147b30317da2f5b3d2636/src/yimaWidgetator/AbstractWidgetHelper.php#L59-L71 |
YiMAproject/yimaWidgetator | src/yimaWidgetator/AbstractWidgetHelper.php | AbstractWidgetHelper.getWidgetManager | function getWidgetManager()
{
if (! $this->widgetManager) {
$sm = $this->getServiceLocator()->getServiceLocator();
$widgetManager = $sm->get('yimaWidgetator.WidgetManager');
if (!($widgetManager instanceof WidgetManager)
|| !($widgetManager instanceof AbstractPluginManager)
)
throw new \Exception(sprintf(
'WidgetManager must instance of WidgetManager or AbstractPluginManager, but "%s" given from \'yimaWidgetator.WidgetManager\'',
is_object($widgetManager) ? get_class($widgetManager) : gettype($widgetManager)
));
$this->widgetManager = $widgetManager;
}
return $this->widgetManager;
} | php | function getWidgetManager()
{
if (! $this->widgetManager) {
$sm = $this->getServiceLocator()->getServiceLocator();
$widgetManager = $sm->get('yimaWidgetator.WidgetManager');
if (!($widgetManager instanceof WidgetManager)
|| !($widgetManager instanceof AbstractPluginManager)
)
throw new \Exception(sprintf(
'WidgetManager must instance of WidgetManager or AbstractPluginManager, but "%s" given from \'yimaWidgetator.WidgetManager\'',
is_object($widgetManager) ? get_class($widgetManager) : gettype($widgetManager)
));
$this->widgetManager = $widgetManager;
}
return $this->widgetManager;
} | Get Widget Manager
@throws \Exception
@return WidgetManager | https://github.com/YiMAproject/yimaWidgetator/blob/332bc9318e6ceaec918147b30317da2f5b3d2636/src/yimaWidgetator/AbstractWidgetHelper.php#L79-L97 |
znframework/package-hypertext | Table.php | Table.attr | public function attr(Array $attributes) : Table
{
foreach( $attributes as $att => $val )
{
$this->attr[$att] = $val;
}
return $this;
} | php | public function attr(Array $attributes) : Table
{
foreach( $attributes as $att => $val )
{
$this->attr[$att] = $val;
}
return $this;
} | Sets attributes
@param array $attributes
@return Table | https://github.com/znframework/package-hypertext/blob/12bbc3bd47a2fae735f638a3e01cc82c1b9c9005/Table.php#L56-L64 |
znframework/package-hypertext | Table.php | Table.cell | public function cell(Int $spacing, Int $padding) : Table
{
$this->attr['cellspacing'] = $spacing;
$this->attr['cellpadding'] = $padding;
return $this;
} | php | public function cell(Int $spacing, Int $padding) : Table
{
$this->attr['cellspacing'] = $spacing;
$this->attr['cellpadding'] = $padding;
return $this;
} | Sets table cell
@param int $spacing
@param int $padding
@return Table | https://github.com/znframework/package-hypertext/blob/12bbc3bd47a2fae735f638a3e01cc82c1b9c9005/Table.php#L74-L80 |
znframework/package-hypertext | Table.php | Table.border | public function border(Int $border, String $color = NULL) : Table
{
$this->attr['border'] = $border;
if( ! empty($color) )
{
$this->attr['bordercolor'] = $color;
}
return $this;
} | php | public function border(Int $border, String $color = NULL) : Table
{
$this->attr['border'] = $border;
if( ! empty($color) )
{
$this->attr['bordercolor'] = $color;
}
return $this;
} | Sets table border
@param int $border
@param string $color = NULL
@return Table | https://github.com/znframework/package-hypertext/blob/12bbc3bd47a2fae735f638a3e01cc82c1b9c9005/Table.php#L90-L100 |
znframework/package-hypertext | Table.php | Table.size | public function size(Int $width, Int $height) : Table
{
$this->attr['width'] = $width;
$this->attr['height'] = $height;
return $this;
} | php | public function size(Int $width, Int $height) : Table
{
$this->attr['width'] = $width;
$this->attr['height'] = $height;
return $this;
} | Sets table size
@param int $width
@param int $height
@return Table | https://github.com/znframework/package-hypertext/blob/12bbc3bd47a2fae735f638a3e01cc82c1b9c9005/Table.php#L110-L116 |
znframework/package-hypertext | Table.php | Table.style | public function style(Array $attributes) : Table
{
$attribute = '';
foreach( $attributes as $key => $values )
{
if( is_numeric($key) )
{
$key = $values;
}
$attribute .= ' '.$key.':'.$values.';';
}
$this->attr['style'] = $attribute;
return $this;
} | php | public function style(Array $attributes) : Table
{
$attribute = '';
foreach( $attributes as $key => $values )
{
if( is_numeric($key) )
{
$key = $values;
}
$attribute .= ' '.$key.':'.$values.';';
}
$this->attr['style'] = $attribute;
return $this;
} | Sets table style attribute
@param array $attributes
@return Table | https://github.com/znframework/package-hypertext/blob/12bbc3bd47a2fae735f638a3e01cc82c1b9c9005/Table.php#L125-L142 |
znframework/package-hypertext | Table.php | Table.create | public function create(...$elements) : String
{
$table = '<table'.$this->html->attributes($this->attr).'>';
$table .= $this->_content(...$elements);
$table .= '</table>';
if( ! empty($this->table)) $this->table = NULL;
if( ! empty($this->attr)) $this->attr = [];
return $table;
} | php | public function create(...$elements) : String
{
$table = '<table'.$this->html->attributes($this->attr).'>';
$table .= $this->_content(...$elements);
$table .= '</table>';
if( ! empty($this->table)) $this->table = NULL;
if( ! empty($this->attr)) $this->attr = [];
return $table;
} | Creates table
@param string ...$elements
@return string | https://github.com/znframework/package-hypertext/blob/12bbc3bd47a2fae735f638a3e01cc82c1b9c9005/Table.php#L151-L161 |
znframework/package-hypertext | Table.php | Table._content | protected function _content(...$elements)
{
$colNo = 1;
$rowNo = 1;
$table = '';
$eol = EOL;
if( isset($elements[0][0]) && is_array($elements[0][0]))
{
$elements = $elements[0];
}
foreach( $elements as $key => $element )
{
$table .= $eol."\t".'<tr>'.$eol;
if(is_array($element))foreach($element as $k => $v)
{
$val = $v;
$attr = "";
if(is_array($v))
{
$attr = $this->html->attributes($v);
$val = $k;
}
if( strpos($val, 'th:') === 0 )
{
$rowType = 'th';
$val = substr($val, 3);
}
else
{
$rowType = 'td';
}
$table .= "\t\t".'<'.$rowType.$attr.'>'.$val.'</'.$rowType.'>'.$eol;
$colNo++;
}
$table .= "\t".'</tr>'.$eol;
$rowNo++;
}
return $table;
} | php | protected function _content(...$elements)
{
$colNo = 1;
$rowNo = 1;
$table = '';
$eol = EOL;
if( isset($elements[0][0]) && is_array($elements[0][0]))
{
$elements = $elements[0];
}
foreach( $elements as $key => $element )
{
$table .= $eol."\t".'<tr>'.$eol;
if(is_array($element))foreach($element as $k => $v)
{
$val = $v;
$attr = "";
if(is_array($v))
{
$attr = $this->html->attributes($v);
$val = $k;
}
if( strpos($val, 'th:') === 0 )
{
$rowType = 'th';
$val = substr($val, 3);
}
else
{
$rowType = 'td';
}
$table .= "\t\t".'<'.$rowType.$attr.'>'.$val.'</'.$rowType.'>'.$eol;
$colNo++;
}
$table .= "\t".'</tr>'.$eol;
$rowNo++;
}
return $table;
} | Protected Content | https://github.com/znframework/package-hypertext/blob/12bbc3bd47a2fae735f638a3e01cc82c1b9c9005/Table.php#L166-L212 |
schpill/thin | src/Form.php | Form.buildLabel | public static function buildLabel($name, $label = '', $required = false)
{
$out = '';
if (!empty($label)) {
$class = 'control-label';
$requiredLabel = '.req';
$requiredSuffix = '<span class="required"><i class="icon-asterisk"></i></span>';
$requiredPrefix = '';
$requiredClass = 'labelrequired';
if (false !== $required) {
$label = $requiredPrefix . $label . $requiredSuffix;
$class .= ' ' . $requiredClass;
}
$out .= static::label($name, $label, array('class' => $class));
}
return $out;
} | php | public static function buildLabel($name, $label = '', $required = false)
{
$out = '';
if (!empty($label)) {
$class = 'control-label';
$requiredLabel = '.req';
$requiredSuffix = '<span class="required"><i class="icon-asterisk"></i></span>';
$requiredPrefix = '';
$requiredClass = 'labelrequired';
if (false !== $required) {
$label = $requiredPrefix . $label . $requiredSuffix;
$class .= ' ' . $requiredClass;
}
$out .= static::label($name, $label, array('class' => $class));
}
return $out;
} | Builds the label html
@param string $name The name of the html field
@param string $label The label name
@param boolean $required
@return string | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Form.php#L122-L142 |
schpill/thin | src/Form.php | Form.buildWrapper | private static function buildWrapper($field, $name, $label = '', $checkbox = false, $required)
{
$getter = 'get' . Inflector::camelize($name);
$error = null;
$actual = Session::instance('ThinForm')->getActual();
if (null !== $actual) {
$error = $actual->getErrors()->$getter();
}
$class = 'control-group';
if (!empty(static::$controlGroupError) && !empty($error)) {
$class .= ' ' . static::$controlGroupError;
}
$id = ' id="control-group-' . $name . '"';
$out = '<div class="' . $class . '"' . $id . '>';
$out .= static::buildLabel($name, $label, $required);
$out .= '<div class="controls">' . PHP_EOL;
$out .= ($checkbox === true) ? '<label class="checkbox">' : '';
$out .= $field;
if (!empty($error)) {
$out .= '<span class="help-inline">' . $error . '</span>';
}
$out .= ($checkbox === true) ? '</label>' : '';
$out .= '</div>';
$out .= '</div>' . PHP_EOL;
return $out;
} | php | private static function buildWrapper($field, $name, $label = '', $checkbox = false, $required)
{
$getter = 'get' . Inflector::camelize($name);
$error = null;
$actual = Session::instance('ThinForm')->getActual();
if (null !== $actual) {
$error = $actual->getErrors()->$getter();
}
$class = 'control-group';
if (!empty(static::$controlGroupError) && !empty($error)) {
$class .= ' ' . static::$controlGroupError;
}
$id = ' id="control-group-' . $name . '"';
$out = '<div class="' . $class . '"' . $id . '>';
$out .= static::buildLabel($name, $label, $required);
$out .= '<div class="controls">' . PHP_EOL;
$out .= ($checkbox === true) ? '<label class="checkbox">' : '';
$out .= $field;
if (!empty($error)) {
$out .= '<span class="help-inline">' . $error . '</span>';
}
$out .= ($checkbox === true) ? '</label>' : '';
$out .= '</div>';
$out .= '</div>' . PHP_EOL;
return $out;
} | Builds the Twitter Bootstrap control wrapper
@param string $field The html for the field
@param string $name The name of the field
@param string $label The label name
@param boolean $checkbox
@return string | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Form.php#L153-L185 |
Phpillip/phpillip | src/Config/Loader/YamlConfigLoader.php | YamlConfigLoader.load | public function load($resource, $type = null)
{
$config = Yaml::parse(file_get_contents($resource));
if (isset($config['imports'])) {
foreach ($config['imports'] as $resource) {
$config = array_merge($config, $this->import($resource));
}
}
return $config;
} | php | public function load($resource, $type = null)
{
$config = Yaml::parse(file_get_contents($resource));
if (isset($config['imports'])) {
foreach ($config['imports'] as $resource) {
$config = array_merge($config, $this->import($resource));
}
}
return $config;
} | {@inheritdoc} | https://github.com/Phpillip/phpillip/blob/c37afaafb536361e7e0b564659f1cd5b80b98be9/src/Config/Loader/YamlConfigLoader.php#L16-L27 |
jtallant/skimpy-engine | src/File/ContentFile.php | ContentFile.getDate | public function getDate()
{
if (false === $this->frontMatter->has('date')) {
# Defaults to last modified
return (new DateTime)->setTimestamp($this->file->getMTime());
}
$date = $this->frontMatter->getDate();
if ($date instanceof DateTime) {
return $date;
}
return (new DateTime)->setTimestamp($date);
} | php | public function getDate()
{
if (false === $this->frontMatter->has('date')) {
# Defaults to last modified
return (new DateTime)->setTimestamp($this->file->getMTime());
}
$date = $this->frontMatter->getDate();
if ($date instanceof DateTime) {
return $date;
}
return (new DateTime)->setTimestamp($date);
} | Front matter date or filemtime
@return DateTime | https://github.com/jtallant/skimpy-engine/blob/2fce5bc16f8745e54fd66a1c291fcea47fc1b4b2/src/File/ContentFile.php#L108-L122 |
jtallant/skimpy-engine | src/File/ContentFile.php | ContentFile.getUri | public function getUri()
{
if ($this->isIndex()) {
return $this->getUriPath();
}
$path = $this->getUriPath().DIRECTORY_SEPARATOR.$this->getFilename();
return trim($path, DIRECTORY_SEPARATOR);
} | php | public function getUri()
{
if ($this->isIndex()) {
return $this->getUriPath();
}
$path = $this->getUriPath().DIRECTORY_SEPARATOR.$this->getFilename();
return trim($path, DIRECTORY_SEPARATOR);
} | URI to the content based on directory path
# Directory | URI
------------------------------------
foo/bar/baz.md | foo/bar/baz
Files named index.md do not use the filename in the URI:
index.md => /
foo/index.md => foo/
foo/bar/index.md => foo/bar/index
@return string | https://github.com/jtallant/skimpy-engine/blob/2fce5bc16f8745e54fd66a1c291fcea47fc1b4b2/src/File/ContentFile.php#L188-L197 |
jtallant/skimpy-engine | src/File/ContentFile.php | ContentFile.getUriPath | protected function getUriPath()
{
$path = dirname($this->getPathFromContent());
$parts = explode(DIRECTORY_SEPARATOR, $path);
$uriParts = array_filter($parts, function ($dirname) {
return false === $this->isTopLevel();
});
return trim(implode(DIRECTORY_SEPARATOR, $uriParts), DIRECTORY_SEPARATOR);
} | php | protected function getUriPath()
{
$path = dirname($this->getPathFromContent());
$parts = explode(DIRECTORY_SEPARATOR, $path);
$uriParts = array_filter($parts, function ($dirname) {
return false === $this->isTopLevel();
});
return trim(implode(DIRECTORY_SEPARATOR, $uriParts), DIRECTORY_SEPARATOR);
} | Returns the URI parts to the Entry up to but not including
the slug, based on the file location.
@return string | https://github.com/jtallant/skimpy-engine/blob/2fce5bc16f8745e54fd66a1c291fcea47fc1b4b2/src/File/ContentFile.php#L257-L267 |
issei-m/spike-php | src/Converter/RecursiveObjectFactoryConverter.php | RecursiveObjectFactoryConverter.convert | public function convert(array $data)
{
foreach ($data as $key => $value) {
if (is_array($value)) {
$data[$key] = $this->convert($value);
}
}
if (isset($data['object'])) {
$data = $this->createObject($data);
}
return $data;
} | php | public function convert(array $data)
{
foreach ($data as $key => $value) {
if (is_array($value)) {
$data[$key] = $this->convert($value);
}
}
if (isset($data['object'])) {
$data = $this->createObject($data);
}
return $data;
} | {@inheritdoc} | https://github.com/issei-m/spike-php/blob/9205b5047a1132bcdca6731feac02fe3d5dc1023/src/Converter/RecursiveObjectFactoryConverter.php#L37-L50 |
crisu83/yii-consoletools | commands/EnvironmentCommand.php | EnvironmentCommand.run | public function run($args)
{
if (!isset($args[0])) {
$this->usageError('The environment id is not specified.');
}
$id = $args[0];
$this->flush();
echo "\nCopying environment files... \n";
$environmentPath = $this->basePath . '/' . $this->environmentsDir . '/' . $id;
if (!file_exists($environmentPath)) {
throw new CException(sprintf("Failed to change environment. Unknown environment '%s'!", $id));
}
$fileList = $this->buildFileList($environmentPath, $this->basePath);
$this->copyFiles($fileList);
echo "\nEnvironment successfully changed to '{$id}'.\n";
} | php | public function run($args)
{
if (!isset($args[0])) {
$this->usageError('The environment id is not specified.');
}
$id = $args[0];
$this->flush();
echo "\nCopying environment files... \n";
$environmentPath = $this->basePath . '/' . $this->environmentsDir . '/' . $id;
if (!file_exists($environmentPath)) {
throw new CException(sprintf("Failed to change environment. Unknown environment '%s'!", $id));
}
$fileList = $this->buildFileList($environmentPath, $this->basePath);
$this->copyFiles($fileList);
echo "\nEnvironment successfully changed to '{$id}'.\n";
} | Changes the current environment.
@param array $args the command-line arguments.
@throws CException if the environment path does not exist. | https://github.com/crisu83/yii-consoletools/blob/53bcb1bcdd33b9ef79034ff9c0d5bbfb3f971afc/commands/EnvironmentCommand.php#L44-L62 |
MovingImage24/VM6ApiClient | lib/ApiClient/AbstractApiClient.php | AbstractApiClient.getVideos | public function getVideos(VideoQueryCriteria $criteria)
{
if ($criteria->isIncludeSubChannels()) {
$criteria->setChannelIds($this->getChannelIdsInclusiveSubChannels($criteria->getChannelIds()));
}
$videoListResponse = $this->deserialize($this->makeRequest('GET', 'get_video_object_list.json', [
'query' => $criteria->getCriteriaData(),
])->getBody(), VideoListResponse::class);
return $videoListResponse->getVideos();
} | php | public function getVideos(VideoQueryCriteria $criteria)
{
if ($criteria->isIncludeSubChannels()) {
$criteria->setChannelIds($this->getChannelIdsInclusiveSubChannels($criteria->getChannelIds()));
}
$videoListResponse = $this->deserialize($this->makeRequest('GET', 'get_video_object_list.json', [
'query' => $criteria->getCriteriaData(),
])->getBody(), VideoListResponse::class);
return $videoListResponse->getVideos();
} | {@inheritdoc} | https://github.com/MovingImage24/VM6ApiClient/blob/84e6510fa0fb71cfbb42ea9f23775f681c266fac/lib/ApiClient/AbstractApiClient.php#L32-L42 |
MovingImage24/VM6ApiClient | lib/ApiClient/AbstractApiClient.php | AbstractApiClient.getChannelList | private function getChannelList()
{
if (empty($this->channelList)) {
$response = $this->makeRequest('GET', 'get_rubric_object_list.json', []);
$this->channelList = $this->deserialize($response->getBody()->getContents(), ChannelList::class);
}
return $this->channelList;
} | php | private function getChannelList()
{
if (empty($this->channelList)) {
$response = $this->makeRequest('GET', 'get_rubric_object_list.json', []);
$this->channelList = $this->deserialize($response->getBody()->getContents(), ChannelList::class);
}
return $this->channelList;
} | Returns ChannelList containing all channels belonging to the video manager.
@return ChannelList | https://github.com/MovingImage24/VM6ApiClient/blob/84e6510fa0fb71cfbb42ea9f23775f681c266fac/lib/ApiClient/AbstractApiClient.php#L49-L57 |
MovingImage24/VM6ApiClient | lib/ApiClient/AbstractApiClient.php | AbstractApiClient.getChannelIdsInclusiveSubChannels | private function getChannelIdsInclusiveSubChannels($channelIds)
{
$subChannelIds = [];
foreach ($channelIds as $channelId) {
$subChannels = $this->getChannelList()->getChildren($channelId);
$subChannelIds = array_merge($subChannelIds, $subChannels->map(function (Channel $channel) {
return $channel->getId();
})->toArray());
}
return empty($subChannelIds)
? $channelIds
: array_merge($channelIds, $this->getChannelIdsInclusiveSubChannels($subChannelIds));
} | php | private function getChannelIdsInclusiveSubChannels($channelIds)
{
$subChannelIds = [];
foreach ($channelIds as $channelId) {
$subChannels = $this->getChannelList()->getChildren($channelId);
$subChannelIds = array_merge($subChannelIds, $subChannels->map(function (Channel $channel) {
return $channel->getId();
})->toArray());
}
return empty($subChannelIds)
? $channelIds
: array_merge($channelIds, $this->getChannelIdsInclusiveSubChannels($subChannelIds));
} | Returns an array containing all channel IDs inclusive sub channels.
@param $channelIds
@return array | https://github.com/MovingImage24/VM6ApiClient/blob/84e6510fa0fb71cfbb42ea9f23775f681c266fac/lib/ApiClient/AbstractApiClient.php#L74-L88 |
MovingImage24/VM6ApiClient | lib/ApiClient/AbstractApiClient.php | AbstractApiClient.getVideoCount | public function getVideoCount(VideoQueryCriteria $criteria)
{
if ($criteria->isIncludeSubChannels()) {
$criteria->setChannelIds($this->getChannelIdsInclusiveSubChannels($criteria->getChannelIds()));
}
$videoListCountResponse = $this->deserialize($this->makeRequest('GET', 'get_video_list_count.json', [
'query' => $criteria->getCriteriaData(),
])->getBody(), VideoListCountResponse::class);
return $videoListCountResponse->getVideoCount();
} | php | public function getVideoCount(VideoQueryCriteria $criteria)
{
if ($criteria->isIncludeSubChannels()) {
$criteria->setChannelIds($this->getChannelIdsInclusiveSubChannels($criteria->getChannelIds()));
}
$videoListCountResponse = $this->deserialize($this->makeRequest('GET', 'get_video_list_count.json', [
'query' => $criteria->getCriteriaData(),
])->getBody(), VideoListCountResponse::class);
return $videoListCountResponse->getVideoCount();
} | {@inheritdoc} | https://github.com/MovingImage24/VM6ApiClient/blob/84e6510fa0fb71cfbb42ea9f23775f681c266fac/lib/ApiClient/AbstractApiClient.php#L93-L103 |
MovingImage24/VM6ApiClient | lib/ApiClient/AbstractApiClient.php | AbstractApiClient.getEmbedCode | public function getEmbedCode(Video $video, $skinId, $type = EmbedCode::TYPE_JAVASCRIPT, $tokenProtected = false)
{
$embedCode = $this->deserialize($this->makeRequest('GET', 'get_https_player_code_for_video.json', [
'query' => [
'videoid' => $video->getId(),
'skinid' => $skinId,
'type' => $type,
],
])->getBody(), EmbedCode::class);
if ($tokenProtected !== false) {
if (is_null($this->unlockTokenGenerator)) {
throw new \Exception('Attempting to append unlock token to embed code, but no unlock code
generator was instantiated.');
}
$token = $this->unlockTokenGenerator->generate($video->getId());
$embedCode->setUnlockToken($token);
}
return $embedCode;
} | php | public function getEmbedCode(Video $video, $skinId, $type = EmbedCode::TYPE_JAVASCRIPT, $tokenProtected = false)
{
$embedCode = $this->deserialize($this->makeRequest('GET', 'get_https_player_code_for_video.json', [
'query' => [
'videoid' => $video->getId(),
'skinid' => $skinId,
'type' => $type,
],
])->getBody(), EmbedCode::class);
if ($tokenProtected !== false) {
if (is_null($this->unlockTokenGenerator)) {
throw new \Exception('Attempting to append unlock token to embed code, but no unlock code
generator was instantiated.');
}
$token = $this->unlockTokenGenerator->generate($video->getId());
$embedCode->setUnlockToken($token);
}
return $embedCode;
} | {@inheritdoc} | https://github.com/MovingImage24/VM6ApiClient/blob/84e6510fa0fb71cfbb42ea9f23775f681c266fac/lib/ApiClient/AbstractApiClient.php#L120-L141 |
Boolive/Core | config/Config.php | Config.read | static function read($name)
{
if (!isset(self::$loaded[$name])) {
self::$loaded[$name] = [];
foreach (self::$dirs as $dir) {
try {
$c = include $dir . $name . '.php';
self::$loaded[$name] = array_merge_recursive(self::$loaded[$name], $c);
} catch (\Exception $e) {
}
}
}
return self::$loaded[$name];
} | php | static function read($name)
{
if (!isset(self::$loaded[$name])) {
self::$loaded[$name] = [];
foreach (self::$dirs as $dir) {
try {
$c = include $dir . $name . '.php';
self::$loaded[$name] = array_merge_recursive(self::$loaded[$name], $c);
} catch (\Exception $e) {
}
}
}
return self::$loaded[$name];
} | Получение конфигурации по названию
По имени находится файл конфиграции в директрии DIR_CONFIG
@param $name string Название конфигурации
@return mixed | https://github.com/Boolive/Core/blob/ead9668f1a6adf41656131eb608a99db6855138d/config/Config.php#L44-L57 |
Boolive/Core | config/Config.php | Config.write | static function write($name, $config, $comment = null, $pretty = true)
{
$fp = fopen(DIR_CONFIG.$name.'.php', 'w');
fwrite($fp, self::generate($config, $comment, $pretty));
fclose($fp);
} | php | static function write($name, $config, $comment = null, $pretty = true)
{
$fp = fopen(DIR_CONFIG.$name.'.php', 'w');
fwrite($fp, self::generate($config, $comment, $pretty));
fclose($fp);
} | Запись кофигруации в файл
@param $name string Название конфигурации
@param $config mixed
@param null $comment
@param bool $pretty | https://github.com/Boolive/Core/blob/ead9668f1a6adf41656131eb608a99db6855138d/config/Config.php#L66-L71 |
Boolive/Core | config/Config.php | Config.is_writable | static function is_writable($name)
{
if (file_exists(DIR_CONFIG.$name.'.php')){
return is_writable(DIR_CONFIG.$name.'.php');
}
return is_writable(DIR_CONFIG);
} | php | static function is_writable($name)
{
if (file_exists(DIR_CONFIG.$name.'.php')){
return is_writable(DIR_CONFIG.$name.'.php');
}
return is_writable(DIR_CONFIG);
} | Проверка возможности записать файл конфигураци
@param $name string Название конфигурации
@return bool | https://github.com/Boolive/Core/blob/ead9668f1a6adf41656131eb608a99db6855138d/config/Config.php#L78-L84 |
Boolive/Core | config/Config.php | Config.generate | static function generate(array $config, $comment = '', $pretty = true)
{
$arraySyntax = [
'open' => self::$bracket_syntax ? '[' : 'array(',
'close' => self::$bracket_syntax ? ']' : ')'
];
$code = "<?php\n";
if ($comment){
$comment = explode("\n",$comment);
$code.="/**\n";
foreach ($comment as $line) $code.=' * '.$line."\n";
$code.=" */\n";
}
return $code.
"return " . $arraySyntax['open'] . "\n" .
($pretty ? F::arrayToCode($config, $arraySyntax) : var_export($config, true) ).
$arraySyntax['close'] . ";\n";
} | php | static function generate(array $config, $comment = '', $pretty = true)
{
$arraySyntax = [
'open' => self::$bracket_syntax ? '[' : 'array(',
'close' => self::$bracket_syntax ? ']' : ')'
];
$code = "<?php\n";
if ($comment){
$comment = explode("\n",$comment);
$code.="/**\n";
foreach ($comment as $line) $code.=' * '.$line."\n";
$code.=" */\n";
}
return $code.
"return " . $arraySyntax['open'] . "\n" .
($pretty ? F::arrayToCode($config, $arraySyntax) : var_export($config, true) ).
$arraySyntax['close'] . ";\n";
} | Генератор содержимого файла конфигурации
@param array $config
@param string $comment
@param bool $pretty
@return string | https://github.com/Boolive/Core/blob/ead9668f1a6adf41656131eb608a99db6855138d/config/Config.php#L98-L115 |
subjective-php/psr-cache-helper | src/InMemoryCache.php | InMemoryCache.get | public function get($key, $default = null)//@codingStandardsIgnoreLine Interface does not define type-hints or return
{
$this->validateKey($key);
$cache = $this->cache[$key] ?? null;
if ($cache === null) {
return $default;
}
if ($cache['expires'] >= time()) {
return $cache['data'];
}
unset($this->cache[$key]);
return $default;
} | php | public function get($key, $default = null)//@codingStandardsIgnoreLine Interface does not define type-hints or return
{
$this->validateKey($key);
$cache = $this->cache[$key] ?? null;
if ($cache === null) {
return $default;
}
if ($cache['expires'] >= time()) {
return $cache['data'];
}
unset($this->cache[$key]);
return $default;
} | Fetches a value from the cache.
@param string $key The unique key of this item in the cache.
@param mixed $default Default value to return if the key does not exist.
@return mixed The value of the item from the cache, or $default in case of cache miss.
@throws InvalidArgumentException Thrown if the $key string is not a legal value. | https://github.com/subjective-php/psr-cache-helper/blob/9468360b643bb251501af61d788dfeb082e693d5/src/InMemoryCache.php#L43-L57 |
subjective-php/psr-cache-helper | src/InMemoryCache.php | InMemoryCache.deleteMultiple | public function deleteMultiple($keys)//@codingStandardsIgnoreLine Interface does not define type-hints
{
$this->validateKeys($keys);
foreach ($keys as $key) {
unset($this->cache[$key]);
}
return true;
} | php | public function deleteMultiple($keys)//@codingStandardsIgnoreLine Interface does not define type-hints
{
$this->validateKeys($keys);
foreach ($keys as $key) {
unset($this->cache[$key]);
}
return true;
} | Deletes multiple cache items in a single operation.
@param iterable $keys A list of string-based keys to be deleted.
@return boolean True if the items were successfully removed. False if there was an error.
@throws InvalidArgumentException Thrown if $keys is neither an array nor a Traversable,
or if any of the $keys are not a legal value. | https://github.com/subjective-php/psr-cache-helper/blob/9468360b643bb251501af61d788dfeb082e693d5/src/InMemoryCache.php#L152-L160 |
andrelohmann/silverstripe-geoform | code/forms/GeoLocationField.php | GeoLocationField.saveInto | function saveInto(DataObjectInterface $dataObject) {
$fieldName = $this->name;
if($dataObject->hasMethod("set$fieldName")) {
$dataObject->$fieldName = DBField::create('GeoLocation', array(
"Address" => $this->fieldAddress->Value(),
"Latitude" => $this->fieldLatitude->Value(),
"Longditude" => $this->fieldLongditude->Value()
));
} else {
$dataObject->$fieldName->setAddress($this->fieldAddress->Value());
$dataObject->$fieldName->setLatitude($this->fieldLatitude->Value());
$dataObject->$fieldName->setLongditude($this->fieldLongditude->Value());
}
} | php | function saveInto(DataObjectInterface $dataObject) {
$fieldName = $this->name;
if($dataObject->hasMethod("set$fieldName")) {
$dataObject->$fieldName = DBField::create('GeoLocation', array(
"Address" => $this->fieldAddress->Value(),
"Latitude" => $this->fieldLatitude->Value(),
"Longditude" => $this->fieldLongditude->Value()
));
} else {
$dataObject->$fieldName->setAddress($this->fieldAddress->Value());
$dataObject->$fieldName->setLatitude($this->fieldLatitude->Value());
$dataObject->$fieldName->setLongditude($this->fieldLongditude->Value());
}
} | 30/06/2009 - Enhancement:
SaveInto checks if set-methods are available and use them
instead of setting the values in the money class directly. saveInto
initiates a new Money class object to pass through the values to the setter
method.
(see @link MoneyFieldTest_CustomSetter_Object for more information) | https://github.com/andrelohmann/silverstripe-geoform/blob/4b8ca69d094dca985c059fb35a159673c39af8d3/code/forms/GeoLocationField.php#L142-L155 |
wigedev/farm | src/Utility/CollectionIterator.php | CollectionIterator.valid | public function valid() : bool
{
if ($this->pointer >= 0 && $this->pointer < $this->collection->length()) {
return true;
} else {
return false;
}
} | php | public function valid() : bool
{
if ($this->pointer >= 0 && $this->pointer < $this->collection->length()) {
return true;
} else {
return false;
}
} | (PHP 5 >= 5.0.0)<br/>
Checks if current position is valid
@link http://php.net/manual/en/iterator.valid.php
@return boolean The return value will be casted to boolean and then evaluated.
Returns true on success or false on failure. | https://github.com/wigedev/farm/blob/7a1729ec78628b7e5435e4a42e42d547a07af851/src/Utility/CollectionIterator.php#L90-L97 |
chilimatic/chilimatic-framework | lib/http/Request.php | Request.init | public function init($param)
{
if (empty($param)) return false;
$this->header = '';
$param_list = new ParamList();
foreach ($param as $key => $value) {
if (property_exists($this, $key)) $this->$key = $value;
elseif (property_exists($param_list, strtolower(str_replace('-', '_', $key)))) {
if (is_string($value)) {
$this->header[] = new SingleParam($key, $value);
} elseif (is_array($value)) {
$this->header[] = new MultiParam($key, $value);
}
}
}
return true;
} | php | public function init($param)
{
if (empty($param)) return false;
$this->header = '';
$param_list = new ParamList();
foreach ($param as $key => $value) {
if (property_exists($this, $key)) $this->$key = $value;
elseif (property_exists($param_list, strtolower(str_replace('-', '_', $key)))) {
if (is_string($value)) {
$this->header[] = new SingleParam($key, $value);
} elseif (is_array($value)) {
$this->header[] = new MultiParam($key, $value);
}
}
}
return true;
} | set the parameters
@param $param
@return bool | https://github.com/chilimatic/chilimatic-framework/blob/8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12/lib/http/Request.php#L124-L146 |
acacha/forge-publish | src/Console/Commands/Traits/ItFetchesSites.php | ItFetchesSites.getSiteByName | protected function getSiteByName($sites, $site_name)
{
$site_found = collect($sites)->filter(function ($site) use ($site_name) {
return $site->name === $site_name;
})->first();
if ($site_found) {
return $site_found;
}
return null;
} | php | protected function getSiteByName($sites, $site_name)
{
$site_found = collect($sites)->filter(function ($site) use ($site_name) {
return $site->name === $site_name;
})->first();
if ($site_found) {
return $site_found;
}
return null;
} | Get forge site from sites by name.
@param $sites
@param $site_id
@return mixed | https://github.com/acacha/forge-publish/blob/010779e3d2297c763b82dc3fbde992edffb3a6c6/src/Console/Commands/Traits/ItFetchesSites.php#L40-L50 |
acacha/forge-publish | src/Console/Commands/Traits/ItFetchesSites.php | ItFetchesSites.getSite | protected function getSite($sites, $site_id)
{
$site_found = collect($sites)->filter(function ($site) use ($site_id) {
return $site->id === $site_id;
})->first();
if ($site_found) {
return $site_found;
}
return null;
} | php | protected function getSite($sites, $site_id)
{
$site_found = collect($sites)->filter(function ($site) use ($site_id) {
return $site->id === $site_id;
})->first();
if ($site_found) {
return $site_found;
}
return null;
} | Get forge site from sites.
@param $sites
@param $site_id
@return mixed | https://github.com/acacha/forge-publish/blob/010779e3d2297c763b82dc3fbde992edffb3a6c6/src/Console/Commands/Traits/ItFetchesSites.php#L59-L69 |
acacha/forge-publish | src/Console/Commands/Traits/ItFetchesSites.php | ItFetchesSites.getSiteName | protected function getSiteName($sites, $site_id)
{
if ($site = $this->getSite($sites, $site_id)) {
return $site->name;
}
return null;
} | php | protected function getSiteName($sites, $site_id)
{
if ($site = $this->getSite($sites, $site_id)) {
return $site->name;
}
return null;
} | Get forge site name from site id.
@param $sites
@param $site_id
@return mixed | https://github.com/acacha/forge-publish/blob/010779e3d2297c763b82dc3fbde992edffb3a6c6/src/Console/Commands/Traits/ItFetchesSites.php#L78-L84 |
acacha/forge-publish | src/Console/Commands/Traits/ItFetchesSites.php | ItFetchesSites.getSiteId | protected function getSiteId($sites, $site_name)
{
if ($site = $this->getSiteByName($sites, $site_name)) {
return $site->id;
}
return null;
} | php | protected function getSiteId($sites, $site_name)
{
if ($site = $this->getSiteByName($sites, $site_name)) {
return $site->id;
}
return null;
} | Get forge site id from site name.
@param $sites
@param $site_name
@return mixed | https://github.com/acacha/forge-publish/blob/010779e3d2297c763b82dc3fbde992edffb3a6c6/src/Console/Commands/Traits/ItFetchesSites.php#L93-L99 |
RadialCorp/magento-core | src/app/code/community/Radial/Core/Helper/Quote/Item.php | Radial_Core_Helper_Quote_Item.isItemInventoried | public function isItemInventoried(Mage_Sales_Model_Quote_Item $item)
{
// never consider a child product as inventoried, allow the parent deal
// with inventory and let the child not need to worry about it as the parent
// will be the item to keep track of qty being ordered.
// Both checks needed as child items will not have a parent item id prior
// to being saved and a parent item prior to being added to the parent (e.g.
// immediately after being loaded from the DB).
if ($item->getParentItemId() || $item->getParentItem()) {
return false;
}
// when dealing with parent items, if any child of the product is managed
// stock, consider the entire item as managed stock - allows for the parent
// config product in the quote to deal with inventory while allowing child
// products to not care individually
if ($item->getHasChildren()) {
foreach ($item->getChildren() as $childItem) {
$childStock = $childItem->getProduct()->getStockItem();
if ($this->isManagedStock($childStock)) {
// This Parent is inventoried. Child's ROM setting is 'No backorders', and Manage Stock check hasn't been manually overridden
return true;
}
}
// if none of the children were managed stock, the parent is not inventoried
return false;
}
return $this->isManagedStock($item->getProduct()->getStockItem());
} | php | public function isItemInventoried(Mage_Sales_Model_Quote_Item $item)
{
// never consider a child product as inventoried, allow the parent deal
// with inventory and let the child not need to worry about it as the parent
// will be the item to keep track of qty being ordered.
// Both checks needed as child items will not have a parent item id prior
// to being saved and a parent item prior to being added to the parent (e.g.
// immediately after being loaded from the DB).
if ($item->getParentItemId() || $item->getParentItem()) {
return false;
}
// when dealing with parent items, if any child of the product is managed
// stock, consider the entire item as managed stock - allows for the parent
// config product in the quote to deal with inventory while allowing child
// products to not care individually
if ($item->getHasChildren()) {
foreach ($item->getChildren() as $childItem) {
$childStock = $childItem->getProduct()->getStockItem();
if ($this->isManagedStock($childStock)) {
// This Parent is inventoried. Child's ROM setting is 'No backorders', and Manage Stock check hasn't been manually overridden
return true;
}
}
// if none of the children were managed stock, the parent is not inventoried
return false;
}
return $this->isManagedStock($item->getProduct()->getStockItem());
} | Test if the item needs to have its quantity checked for available
inventory.
@param Mage_Sales_Model_Quote_Item $item The item to check
@return bool True if inventory is managed, false if not | https://github.com/RadialCorp/magento-core/blob/9bb5f218d9caf79eab8598f4f8447037a0cc6355/src/app/code/community/Radial/Core/Helper/Quote/Item.php#L32-L59 |
RadialCorp/magento-core | src/app/code/community/Radial/Core/Helper/Quote/Item.php | Radial_Core_Helper_Quote_Item.isManagedStock | protected function isManagedStock(Mage_CatalogInventory_Model_Stock_Item $stock)
{
return (
($this->_config->isBackorderable || (int) $stock->getBackorders() === Mage_CatalogInventory_Model_Stock::BACKORDERS_NO)
&& $stock->getManageStock() > 0
);
} | php | protected function isManagedStock(Mage_CatalogInventory_Model_Stock_Item $stock)
{
return (
($this->_config->isBackorderable || (int) $stock->getBackorders() === Mage_CatalogInventory_Model_Stock::BACKORDERS_NO)
&& $stock->getManageStock() > 0
);
} | If the inventory configuration allow order item to be backorderable simply check if the
Manage stock for the item is greater than zero. Otherwise, if the inventory configuration
do not allow order items to be backorderable, then ensure the item is not backorder and has
manage stock.
@param Mage_CatalogInventory_Model_Stock_Item
@return bool | https://github.com/RadialCorp/magento-core/blob/9bb5f218d9caf79eab8598f4f8447037a0cc6355/src/app/code/community/Radial/Core/Helper/Quote/Item.php#L70-L76 |
davin-bao/php-git | src/Git.php | GitRepo.run_command | public function run_command($command) {
\Log::debug($command);
$descriptorspec = array(
1 => array('pipe', 'w'),
2 => array('pipe', 'w'),
);
$pipes = array();
/* Depending on the value of variables_order, $_ENV may be empty.
* In that case, we have to explicitly set the new variables with
* putenv, and call proc_open with env=null to inherit the reset
* of the system.
*
* This is kind of crappy because we cannot easily restore just those
* variables afterwards.
*
* If $_ENV is not empty, then we can just copy it and be done with it.
*/
if(count($_ENV) === 0) {
$env = NULL;
foreach($this->envopts as $k => $v) {
putenv(sprintf("%s=%s",$k,$v));
}
} else {
$env = array_merge($_ENV, $this->envopts);
}
$cwd = $this->repo_path;
$resource = proc_open($command, $descriptorspec, $pipes, $cwd, $env);
$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
foreach ($pipes as $pipe) {
fclose($pipe);
}
$status = trim(proc_close($resource));
if ($status) throw new Exception($stderr);
return $stdout;
} | php | public function run_command($command) {
\Log::debug($command);
$descriptorspec = array(
1 => array('pipe', 'w'),
2 => array('pipe', 'w'),
);
$pipes = array();
/* Depending on the value of variables_order, $_ENV may be empty.
* In that case, we have to explicitly set the new variables with
* putenv, and call proc_open with env=null to inherit the reset
* of the system.
*
* This is kind of crappy because we cannot easily restore just those
* variables afterwards.
*
* If $_ENV is not empty, then we can just copy it and be done with it.
*/
if(count($_ENV) === 0) {
$env = NULL;
foreach($this->envopts as $k => $v) {
putenv(sprintf("%s=%s",$k,$v));
}
} else {
$env = array_merge($_ENV, $this->envopts);
}
$cwd = $this->repo_path;
$resource = proc_open($command, $descriptorspec, $pipes, $cwd, $env);
$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
foreach ($pipes as $pipe) {
fclose($pipe);
}
$status = trim(proc_close($resource));
if ($status) throw new Exception($stderr);
return $stdout;
} | Run a command in the git repository
Accepts a shell command to run
@access protected
@param string command to run
@return string | https://github.com/davin-bao/php-git/blob/9ae1997dc07978a3e647d44cba433d6638474c5c/src/Git.php#L287-L326 |
ajaxtown/eaglehorn_framework | src/Eaglehorn/View.php | View.render | public function render()
{
foreach ($this->base->load->viewset as $key => $view) {
$viewdir = configItem('site')['viewdir'];
if (file_exists($viewdir . $view[0])) {
if (isset($view[1]) && is_array($view[1])) {
$this->_view_data = $view[1];
extract($view[1]);
}
include_once $viewdir . $view[0];
$this->base->logger->info("View loaded - $view[0]", $this->_view_data);
} else {
$this->base->logger->error("404 View - $view[0]");
}
}
} | php | public function render()
{
foreach ($this->base->load->viewset as $key => $view) {
$viewdir = configItem('site')['viewdir'];
if (file_exists($viewdir . $view[0])) {
if (isset($view[1]) && is_array($view[1])) {
$this->_view_data = $view[1];
extract($view[1]);
}
include_once $viewdir . $view[0];
$this->base->logger->info("View loaded - $view[0]", $this->_view_data);
} else {
$this->base->logger->error("404 View - $view[0]");
}
}
} | While _loading views, every view and its data gets stored in viewset.
This method loops through the viewset and checks if the view exist. If so, then
include the view and convert the data(array),if exists, into independent variables.
As views are different from templates, special variables wrapped with {} cannot be used.
Instead, the data(array) which is passed to the view can be echoed directly using
the key.
For eg,
$data = array('title','My first page');
$this->load->view('myview.php',$data);
$this->render();
In myview.php, you can directly echo $title as it automatically gets converted into a variable. | https://github.com/ajaxtown/eaglehorn_framework/blob/5e2a1456ff6c65b3925f1219f115d8a919930f52/src/Eaglehorn/View.php#L48-L66 |
silvercommerce/contact-admin | src/model/Contact.php | Contact.DefaultLocation | public function DefaultLocation()
{
$location = $this
->Locations()
->sort("Default", "DESC")
->first();
$this->extend("updateDefaultLocation", $location);
return $location;
} | php | public function DefaultLocation()
{
$location = $this
->Locations()
->sort("Default", "DESC")
->first();
$this->extend("updateDefaultLocation", $location);
return $location;
} | Find from our locations one marked as default (of if not the
first in the list).
@return ContactLocation | https://github.com/silvercommerce/contact-admin/blob/32cbc2ef2589f93f9dd1796e5db2f11ad15d888c/src/model/Contact.php#L195-L205 |
silvercommerce/contact-admin | src/model/Contact.php | Contact.getName | public function getName()
{
$name = ($this->Surname) ? trim($this->FirstName . ' ' . $this->Surname) : $this->FirstName;
$this->extend("updateName", $name);
return $name;
} | php | public function getName()
{
$name = ($this->Surname) ? trim($this->FirstName . ' ' . $this->Surname) : $this->FirstName;
$this->extend("updateName", $name);
return $name;
} | Get the complete name of the member
@return string Returns the first- and surname of the member. | https://github.com/silvercommerce/contact-admin/blob/32cbc2ef2589f93f9dd1796e5db2f11ad15d888c/src/model/Contact.php#L229-L236 |
silvercommerce/contact-admin | src/model/Contact.php | Contact.getTagsList | public function getTagsList()
{
$return = "";
$tags = $this->Tags()->column("Title");
$this->extend("updateTagsList", $tags);
return implode(
$this->config()->list_seperator,
$tags
);
} | php | public function getTagsList()
{
$return = "";
$tags = $this->Tags()->column("Title");
$this->extend("updateTagsList", $tags);
return implode(
$this->config()->list_seperator,
$tags
);
} | Generate as string of tag titles seperated by a comma
@return string | https://github.com/silvercommerce/contact-admin/blob/32cbc2ef2589f93f9dd1796e5db2f11ad15d888c/src/model/Contact.php#L243-L254 |
silvercommerce/contact-admin | src/model/Contact.php | Contact.getListsList | public function getListsList()
{
$return = "";
$list = $this->Lists()->column("Title");
$this->extend("updateListsList", $tags);
return implode(
$this->config()->list_seperator,
$list
);
} | php | public function getListsList()
{
$return = "";
$list = $this->Lists()->column("Title");
$this->extend("updateListsList", $tags);
return implode(
$this->config()->list_seperator,
$list
);
} | Generate as string of list titles seperated by a comma
@return string | https://github.com/silvercommerce/contact-admin/blob/32cbc2ef2589f93f9dd1796e5db2f11ad15d888c/src/model/Contact.php#L261-L272 |
silvercommerce/contact-admin | src/model/Contact.php | Contact.syncToMember | public function syncToMember()
{
$member = $this->Member();
$sync = $this->config()->sync_fields;
$write = false;
if (!$member->exists()) {
return;
}
foreach ($this->getChangedFields() as $field => $change) {
// If this field is a field to sync, and it is different
// then update member
if (in_array($field, $sync) && $member->$field != $this->$field) {
$member->$field = $this->$field;
$write = true;
}
}
if ($write) {
$member->write();
}
} | php | public function syncToMember()
{
$member = $this->Member();
$sync = $this->config()->sync_fields;
$write = false;
if (!$member->exists()) {
return;
}
foreach ($this->getChangedFields() as $field => $change) {
// If this field is a field to sync, and it is different
// then update member
if (in_array($field, $sync) && $member->$field != $this->$field) {
$member->$field = $this->$field;
$write = true;
}
}
if ($write) {
$member->write();
}
} | Update an associated member with the data from this contact
@return void | https://github.com/silvercommerce/contact-admin/blob/32cbc2ef2589f93f9dd1796e5db2f11ad15d888c/src/model/Contact.php#L294-L316 |
silvercommerce/contact-admin | src/model/Contact.php | Contact.onBeforeDelete | public function onBeforeDelete()
{
parent::onBeforeDelete();
// Delete all locations attached to this order
foreach ($this->Locations() as $item) {
$item->delete();
}
// Delete all notes attached to this order
foreach ($this->Notes() as $item) {
$item->delete();
}
} | php | public function onBeforeDelete()
{
parent::onBeforeDelete();
// Delete all locations attached to this order
foreach ($this->Locations() as $item) {
$item->delete();
}
// Delete all notes attached to this order
foreach ($this->Notes() as $item) {
$item->delete();
}
} | Cleanup DB on removal | https://github.com/silvercommerce/contact-admin/blob/32cbc2ef2589f93f9dd1796e5db2f11ad15d888c/src/model/Contact.php#L513-L526 |
nyeholt/silverstripe-performant | code/services/SiteDataService.php | SiteDataService.getPrivateNodes | protected function getPrivateNodes() {
if (!Member::currentUserID()) {
return array();
}
$groups = Member::currentUser()->Groups()->column();
if (!count($groups)) {
return $groups;
}
$fields = $this->queryFields();
$query = new SQLQuery($fields, '"'.$this->baseClass.'"');
$query = $query->setOrderBy($this->itemSort);
$query->addWhere('"CanViewType" IN (\'OnlyTheseUsers\')');
if (Permission::check('ADMIN')) {
// don't need to restrict the canView by anything
} else {
$query->addInnerJoin('SiteTree_ViewerGroups', '"SiteTree_ViewerGroups"."SiteTreeID" = "SiteTree"."ID"');
$query->addWhere('"SiteTree_ViewerGroups"."GroupID" IN (' . implode(',', $groups) . ')');
}
$this->adjustPrivateNodeQuery($query);
$this->adjustForVersioned($query);
$sql = $query->sql();
$results = $query->execute();
return $results;
} | php | protected function getPrivateNodes() {
if (!Member::currentUserID()) {
return array();
}
$groups = Member::currentUser()->Groups()->column();
if (!count($groups)) {
return $groups;
}
$fields = $this->queryFields();
$query = new SQLQuery($fields, '"'.$this->baseClass.'"');
$query = $query->setOrderBy($this->itemSort);
$query->addWhere('"CanViewType" IN (\'OnlyTheseUsers\')');
if (Permission::check('ADMIN')) {
// don't need to restrict the canView by anything
} else {
$query->addInnerJoin('SiteTree_ViewerGroups', '"SiteTree_ViewerGroups"."SiteTreeID" = "SiteTree"."ID"');
$query->addWhere('"SiteTree_ViewerGroups"."GroupID" IN (' . implode(',', $groups) . ')');
}
$this->adjustPrivateNodeQuery($query);
$this->adjustForVersioned($query);
$sql = $query->sql();
$results = $query->execute();
return $results;
} | Get private nodes, assuming SilverStripe's default perm structure
@return SS_Query | https://github.com/nyeholt/silverstripe-performant/blob/2c9d2570ddf4a43ced38487184da4de453a4863c/code/services/SiteDataService.php#L158-L185 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.