_id
stringlengths 2
7
| title
stringlengths 3
151
| partition
stringclasses 3
values | text
stringlengths 83
13k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q253800 | ToolsController.fixFile | validation | public function fixFile($file)
{
$contents = preg_split("/\\r\\n|\\r|\\n/", file_get_contents($file));
$changed = false;
if ($this->fixFileSlashes($file, $contents)) {
$changed = true;
}
// if ($this->fixDocBlockPlaceholder($file, $contents)) {
// $changed = true;
// }
if ($changed) {
file_put_contents($file, implode("\n", $contents));
}
return $changed;
} | php | {
"resource": ""
} |
q253801 | ToolsController.fixFileSlashes | validation | public function fixFileSlashes($file, &$contents)
{
$changed = false;
foreach ($contents as $lineNumber => $line) {
if (preg_match('/(psesd|canis|cascade)\\\\\\\/', $line) === 1) {
$fixedLine = preg_replace('/\\\\\\\/', '\\', $line);
if ($fixedLine !== $line) {
$contents[$lineNumber] = $fixedLine;
$changed = true;
}
}
}
return $changed;
} | php | {
"resource": ""
} |
q253802 | Broadcast.send | validation | public function send($msgType, $message, $to = null)
{
$message = (new MessageBuilder())->msgType($msgType)->message($message)->to($to)->build();
$api = is_array($to) ? self::API_SEND_BY_OPENID : self::API_SEND_BY_GROUP;
return $this->post($api, $message);
} | php | {
"resource": ""
} |
q253803 | Broadcast.sendText | validation | public function sendText($message, $to = null)
{
return $this->send(self::MSG_TYPE_TEXT, $message, $to);
} | php | {
"resource": ""
} |
q253804 | Broadcast.sendNews | validation | public function sendNews($message, $to = null)
{
return $this->send(self::MSG_TYPE_NEWS, $message, $to);
} | php | {
"resource": ""
} |
q253805 | Broadcast.sendVoice | validation | public function sendVoice($message, $to = null)
{
return $this->send(self::MSG_TYPE_VOICE, $message, $to);
} | php | {
"resource": ""
} |
q253806 | Broadcast.sendImage | validation | public function sendImage($message, $to = null)
{
return $this->send(self::MSG_TYPE_IMAGE, $message, $to);
} | php | {
"resource": ""
} |
q253807 | Broadcast.sendVideo | validation | public function sendVideo($message, $to = null)
{
return $this->send(self::MSG_TYPE_VIDEO, $message, $to);
} | php | {
"resource": ""
} |
q253808 | Broadcast.sendCard | validation | public function sendCard($message, $to = null)
{
return $this->send(self::MSG_TYPE_CARD, $message, $to);
} | php | {
"resource": ""
} |
q253809 | Broadcast.preview | validation | public function preview($msgType, $message, $to, $by = self::PREVIEW_BY_OPENID)
{
$message = (new MessageBuilder())->msgType($msgType)->message($message)->to($to)->buildPreview($by);
return $this->post(self::API_PREVIEW, $message);
} | php | {
"resource": ""
} |
q253810 | Broadcast.previewText | validation | public function previewText($message, $to, $by = self::PREVIEW_BY_OPENID)
{
return $this->preview(self::MSG_TYPE_TEXT, $message, $to, $by);
} | php | {
"resource": ""
} |
q253811 | Broadcast.previewNews | validation | public function previewNews($message, $to, $by = self::PREVIEW_BY_OPENID)
{
return $this->preview(self::MSG_TYPE_NEWS, $message, $to, $by);
} | php | {
"resource": ""
} |
q253812 | Broadcast.previewVoice | validation | public function previewVoice($message, $to, $by = self::PREVIEW_BY_OPENID)
{
return $this->preview(self::MSG_TYPE_VOICE, $message, $to, $by);
} | php | {
"resource": ""
} |
q253813 | Broadcast.previewImage | validation | public function previewImage($message, $to, $by = self::PREVIEW_BY_OPENID)
{
return $this->preview(self::MSG_TYPE_IMAGE, $message, $to, $by);
} | php | {
"resource": ""
} |
q253814 | Broadcast.previewVideo | validation | public function previewVideo($message, $to, $by = self::PREVIEW_BY_OPENID)
{
return $this->preview(self::MSG_TYPE_VIDEO, $message, $to, $by);
} | php | {
"resource": ""
} |
q253815 | Broadcast.previewCard | validation | public function previewCard($message, $to, $by = self::PREVIEW_BY_OPENID)
{
return $this->preview(self::MSG_TYPE_CARD, $message, $to, $by);
} | php | {
"resource": ""
} |
q253816 | Broadcast.previewByName | validation | public function previewByName($msgType, $message, $to)
{
return $this->preview($msgType, $message, $to, self::PREVIEW_BY_NAME);
} | php | {
"resource": ""
} |
q253817 | Broadcast.previewTextByName | validation | public function previewTextByName($message, $to)
{
return $this->preview(self::MSG_TYPE_TEXT, $message, $to, self::PREVIEW_BY_NAME);
} | php | {
"resource": ""
} |
q253818 | Broadcast.previewNewsByName | validation | public function previewNewsByName($message, $to)
{
return $this->preview(self::MSG_TYPE_NEWS, $message, $to, self::PREVIEW_BY_NAME);
} | php | {
"resource": ""
} |
q253819 | Broadcast.previewVoiceByName | validation | public function previewVoiceByName($message, $to)
{
return $this->preview(self::MSG_TYPE_VOICE, $message, $to, self::PREVIEW_BY_NAME);
} | php | {
"resource": ""
} |
q253820 | Broadcast.previewImageByName | validation | public function previewImageByName($message, $to)
{
return $this->preview(self::MSG_TYPE_IMAGE, $message, $to, self::PREVIEW_BY_NAME);
} | php | {
"resource": ""
} |
q253821 | Broadcast.previewVideoByName | validation | public function previewVideoByName($message, $to)
{
return $this->preview(self::MSG_TYPE_VIDEO, $message, $to, self::PREVIEW_BY_NAME);
} | php | {
"resource": ""
} |
q253822 | Broadcast.previewCardByName | validation | public function previewCardByName($message, $to)
{
return $this->preview(self::MSG_TYPE_CARD, $message, $to, self::PREVIEW_BY_NAME);
} | php | {
"resource": ""
} |
q253823 | Grid.setTranslator | validation | public function setTranslator($translator, $translatorDomain = null, $translatorLocale = null) {
$this->translator = $translator;
$this->setTranslatorDomain($translatorDomain);
$this->setTranslatorLocale($translatorLocale);
$this->setCaption($this->translate($this->getCaption()));
} | php | {
"resource": ""
} |
q253824 | GenericTasks.run_tool_version | validation | static function run_tool_version( $task=null, $args=array(), $cliopts=array() )
{
pake_echo( "eZ Extension Builder ver." . self::VERSION . "\nRunning on pake " . pakeApp::VERSION );
} | php | {
"resource": ""
} |
q253825 | GenericTasks.run_generate_extension_config | validation | static function run_generate_extension_config( $task=null, $args=array(), $cliopts=array() )
{
self::setConfigDir( $cliopts );
$overwrite = @$cliopts['overwrite-existing'];
if ( count( $args ) == 0 )
{
throw new pakeException( "Missing extension name" );
}
$extname = $args[0];
$configfile = self::getOptionsDir() . "/options-$extname.yaml";
if ( file_exists( $configfile ) && ! $overwrite )
{
pake_echo( "File $configfile already exists. Must overwrite it to continue" );
$ok = pake_input( "Do you want to overwrite it? [y/n]", 'n' );
if ( $ok != 'y' )
{
return;
}
}
pake_mkdirs( self::getOptionsDir() );
pake_copy( self::getResourceDir() . '/options-sample.yaml', $configfile, array( 'override' => true ) );
pake_echo( "Created file $configfile, now go and edit it" );
} | php | {
"resource": ""
} |
q253826 | GenericTasks.run_convert_configuration | validation | static function run_convert_configuration( $task=null, $args=array(), $cliopts=array() )
{
self::setConfigDir( $cliopts );
$extname = @$args[0];
if ( $extname == '' )
{
$extname = dirname( __FILE__ );
}
while ( !is_file( "ant/$extname.properties" ) )
{
$extname = pake_input( 'What is the name of the current extension?' );
if ( !is_file( "ant/$extname.properties" ) )
{
pake_echo( "File ant/$extname.properties not found" );
}
}
self::convertPropertyFileToYamlFile(
"ant/$extname.properties",
self::getConfigDir() . "/options-$extname.yaml",
array( $extname => '', 'external' => 'dependencies', 'dependency' => 'extensions', 'repository' => array( 'svn', 'url' ) ),
"extension:\n name: $extname\n\n" );
foreach( array( 'files.to.parse.txt' => 'to_parse', 'files.to.exclude.txt' => 'to_exclude' ) as $file => $option )
{
$src = "ant/$file";
if ( file_exists( $src ) )
{
//$ok = !file_exists( $dst ) || ( pake_input( "Destionation file $dst exists. Overwrite? [y/n]", 'n' ) == 'y' );
//$ok && pake_copy( $src, $dst, array( 'override' => true ) );
if ( count( $in = file( $src, FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES ) ) )
{
$in = "\n\nfiles:\n $option: [" . implode( ', ', $in ) . "]\n";
file_put_contents( self::getConfigDir() . "options-$extname.yaml", $in, FILE_APPEND );
}
}
}
} | php | {
"resource": ""
} |
q253827 | WebCtrlResolver.createCtrl | validation | protected function createCtrl(): AbstractCtrl
{
$view = ViewFactory::createView(
str_replace('action', '', $this->actionName),
$this->ctrlName
);
$componentsRootMap = AppHelper::getInstance()->getConfig('componentsRootMap');
if (!isset($componentsRootMap['controllers'])) {
throw new Exception("The field 'componentsRootMap.controllers' must be "
.'presented in the main configuration file.');
}
$ctrlNamespace = str_replace(
\DIRECTORY_SEPARATOR,
'\\',
$componentsRootMap['controllers']
);
$ctrlFullName = $ctrlNamespace.'\\'.$this->ctrlName;
if (!is_null($view)) {
$layoutName = AppHelper::getInstance()->getConfig('defaultLayout');
if (!is_null($layoutName)) {
$layout = ViewFactory::createLayout($layoutName, $view);
$ctrl = new $ctrlFullName($this->request, $layout);
} else {
$ctrl = new $ctrlFullName($this->request, $view);
}
} else {
$ctrl = new $ctrlFullName($this->request);
}
return $ctrl;
} | php | {
"resource": ""
} |
q253828 | ETokenManager.init | validation | public function init()
{
parent::init();
$db = $this->getDbConnection();
$db->setActive(true);
if ($this->autoCreateTokenTable) {
$sql = "DELETE FROM {$this->tokenTableName} WHERE (expires>0 AND expires<" . time() . ") OR (uses_allowed>0 AND uses_remaining<1)";
try {
$db->createCommand($sql)->execute();
} catch (Exception $e) {
$this->createTokenTable($db, $this->tokenTableName);
}
}
} | php | {
"resource": ""
} |
q253829 | ETokenManager.createTokenTable | validation | protected function createTokenTable($db, $tableName)
{
$driver = $db->getDriverName();
$file = dirname(__DIR__) . '/migrations/' . $this->tokenTableName . '.' . $db->getDriverName();
$pdo = $this->getDbConnection()->pdoInstance;
$sql = file_get_contents($file);
$sql = rtrim($sql);
$sqls = preg_replace_callback("/\((.*)\)/", create_function('$matches', 'return str_replace(";"," $$$ ",$matches[0]);'), $sql);
$sqls = explode(";", $sqls);
foreach ($sqls as $sql) {
if (!empty($sql)) {
$sql = str_replace(" $$$ ", ";", $sql) . ";";
$pdo->exec($sql);
}
}
} | php | {
"resource": ""
} |
q253830 | ContactFormController.sendEmails | validation | protected function sendEmails(ContactInquiry $inquiry)
{
$recipients = $this->container->getParameter('c33s_contact_form.email.recipients');
if ($this->container->getParameter('c33s_contact_form.email.send_copy_to_user') && $inquiry->hasSenderEmail()) {
$recipients[] = $inquiry->getSenderEmail();
}
if (empty($recipients)) {
return;
}
$translator = $this->get('translator');
$subject = $this->container->getParameter('c33s_contact_form.email.subject');
$message = \Swift_Message::newInstance()
->setSubject($translator->trans($subject, array(), 'C33sContactForm'))
->setFrom($this->container->getParameter('c33s_contact_form.email.sender_email'))
->setTo($recipients)
->setBody(
$this->renderView(
'C33sContactFormBundle:ContactForm:email.txt.twig',
array('inquiry' => $inquiry)
)
)
;
$this->get('mailer')->send($message);
} | php | {
"resource": ""
} |
q253831 | DefaultController.getDataTablesI18nAction | validation | public function getDataTablesI18nAction()
{
$locale = $this->get('request_stack')->getCurrentRequest()->getLocale();
$format = $this->get('request_stack')->getCurrentRequest()->getRequestFormat();
return $this->render(
'AdminBundle:Default/DataTables_i18n:'.$locale.'.txt.'.$format
);
} | php | {
"resource": ""
} |
q253832 | Web2All_Table_MultiValueOperator.checkParams | validation | protected function checkParams($params,$operator)
{
if (!is_array($params)) {
throw new Exception('Web2All_Table_MultiValueOperator: first param must be an array');
}
if ($operator=='IN') {
if (count($params)<1) {
throw new Exception('Web2All_Table_MultiValueOperator: IN operator requires at least one param');
}
} elseif ($operator=='BETWEEN') {
if (count($params)!=2) {
throw new Exception('Web2All_Table_MultiValueOperator: BETWEEN operator requires exactly two params');
}
}else{
throw new Exception('Web2All_Table_MultiValueOperator: unsupported operator "'.$operator.'"');
}
} | php | {
"resource": ""
} |
q253833 | Web2All_Table_MultiValueOperator.toSQLString | validation | public function toSQLString() {
if ($this->operator=='IN') {
$sql = '(';
$komma = '';
for ($i=0;$i<count($this->operation);$i++)
{
$sql.= $komma.'?';
$komma = ',';
}
$sql.= ')';
return $sql;
} elseif ($this->operator=='BETWEEN') {
return '? AND ?';
}
} | php | {
"resource": ""
} |
q253834 | Web2All_Table_MultiValueOperator.setOperator | validation | public function setOperator($operator)
{
$this->checkParams($this->operation,$operator);
$this->operator=$operator;
} | php | {
"resource": ""
} |
q253835 | CreateDirectoriesCompiler.makeDir | validation | protected function makeDir($dirName, LoggerInterface $logger) {
$dn = explode(getcwd(), $dirName)[1] ?? $dirName;
if(@mkdir($dirName)) {
$logger->logText("Created directory <fg=green>%s</>", LoggerInterface::VERBOSITY_NORMAL, NULL, $dn);
} else {
$logger->logWarning("Creating directory $dn failed");
}
} | php | {
"resource": ""
} |
q253836 | Base.getMinifier | validation | protected function getMinifier(SplFileInfo $file, string $source): Minifier
{
$minifier = '\Gears\Asset\Minifiers\\';
$minifier .= ucfirst($this->destination->getExtension());
if (!class_exists($minifier))
{
throw new RuntimeException
(
'Minification is not supported for type: '.
$this->destination->getExtension()
);
}
return new $minifier($file, $source);
} | php | {
"resource": ""
} |
q253837 | Base.doWeNeedToMinify | validation | protected function doWeNeedToMinify(SplFileInfo $file): bool
{
return
(
!$this->debug &&
!Str::s($file->getFilename())->contains('.min.')
);
} | php | {
"resource": ""
} |
q253838 | CacheManager.getCacheAdapter | validation | public function getCacheAdapter($namespace)
{
// caching is not enabled for a namespace
if (!$this->isCacheable($namespace)) {
return null;
}
// user wants to implements different adapter for different namespaces
if (is_array($this->cacheOptions->getAdapter())) {
// checks if adapter of a namespace exists
if (!isset($this->cacheOptions->getAdapter()[$namespace])) {
return null;
}
$adapter = $this->cacheOptions->getAdapter()[$namespace];
} else {
// user want to implements one adapter for all namespaces
$adapter = $this->cacheOptions->getAdapter();
}
if (is_object($adapter)) {
return $adapter;
}
if ($this->getServiceLocator()->has($adapter)) {
return $this->getServiceLocator()->get($adapter);
}
return new $adapter;
} | php | {
"resource": ""
} |
q253839 | CacheManager.isCacheable | validation | public function isCacheable($namespace)
{
if (!$this->cacheOptions->isEnabled()) {
return false;
}
$namespaces = $this->cacheOptions->getNamespaces();
// user has enabled caching but has not specified namespaces to cache,
// so we cache all the namespaces
if (empty($namespaces)) {
return true;
}
// user has enabled caching but has specified certain namespaces to cache,
// so we cache only the specified namespaces
return in_array($namespace, $namespaces);
} | php | {
"resource": ""
} |
q253840 | Config.get | validation | public function get($key, $default = null)
{
return array_key_exists($key, $this->configs) ? $this->configs[$key] : $default;
} | php | {
"resource": ""
} |
q253841 | File.copy | validation | public static function copy($src, $dest, $force=true)
{
$src = Path::clean($src);
$dest = Path::clean($dest);
if ( !Folder::exists(dirname($dest)) ){
Folder::create(dirname($dest));
}
$fs = new Filesystem();
try {
$fs->copy($src, $dest, $force);
} catch(IOExceptionInterface $e){
throw new Exception(Helper::getTranslation('CANNOT_FIND_SOURCE').' '.$e->getPath());
}
return true;
} | php | {
"resource": ""
} |
q253842 | File.write | validation | public static function write($filename, $buffer)
{
$fs = new Filesystem();
try {
$fs->dumpFile($filename, $buffer);
}
catch(IOExceptionInterface $e){
throw new Exception($e->getMessage());
}
return true;
} | php | {
"resource": ""
} |
q253843 | File.delete | validation | public static function delete($path)
{
$path = Path::clean($path);
$fs = new Filesystem();
try {
$fs->remove($path);
}
catch(IOExceptionInterface $e){
throw new Exception(Helper::getTranslation('FAILED_DELETING').' - ('.$e->getMessage().')');
}
return true;
} | php | {
"resource": ""
} |
q253844 | File.read | validation | public static function read($path)
{
$path = Path::clean($path);
if ( !File::exists($path) ){
return '';
}
return file_get_contents($path);
} | php | {
"resource": ""
} |
q253845 | File.upload | validation | public static function upload($src, $dest)
{
$dest = Path::clean($dest);
$baseDir = dirname($dest);
try {
if ( !Folder::exists($baseDir) ){
Folder::create($baseDir);
}
}
catch(Exception $e){
throw $e;
}
if ( is_writeable($baseDir) && move_uploaded_file($src, $dest) ){
if ( Path::setPermissions($dest) ){
return true;
}
throw new Exception(Helper::getTranslation('FAILED_CHMOD'));
}
throw new Exception(Helper::getTranslation('FAILED_MOVE_UPLOAD'));
} | php | {
"resource": ""
} |
q253846 | File.getName | validation | public static function getName($file)
{
$file = str_replace('\\', '/', $file);
$slash = strrpos($file, '/');
if ( $slash !== false ){
return substr($file, $slash + 1);
}
return $file;
} | php | {
"resource": ""
} |
q253847 | File.getPath | validation | public static function getPath(string $file)
{
$parts = explode('/', $file);
array_pop($parts);
return implode('/', $parts);
} | php | {
"resource": ""
} |
q253848 | File.makeSafe | validation | public static function makeSafe($file)
{
$regex = [
'#(\.){2,}#',
'#[^A-Za-z0-9\.\_\- ]#', '#^\.#',
];
$file = rtrim($file, '.');
$clean = preg_replace($regex, ' ', $file);
$clean = preg_replace("/[ \_]/", '-', $clean);
$clean = preg_replace("/[\-]+/", '-', $clean);
return $clean;
} | php | {
"resource": ""
} |
q253849 | Item.getChild | validation | public function getChild($type)
{
if (isset($this->_children[$type])) {
return $this->_children[$type];
}
return false;
} | php | {
"resource": ""
} |
q253850 | Item.getParent | validation | public function getParent($type)
{
if (isset($this->_parents[$type])) {
return $this->_parents[$type];
}
return false;
} | php | {
"resource": ""
} |
q253851 | Item.getParents | validation | public function getParents()
{
$parents = [];
foreach ($this->_parents as $key => $parent) {
if (!$parent->active) {
continue;
}
$parents[$key] = $parent;
}
return $parents;
} | php | {
"resource": ""
} |
q253852 | Item.getChecked | validation | public function getChecked()
{
if (is_null($this->object) || !$this->object) {
return false;
}
if (is_null($this->_checked)) {
$this->_checked = true;
foreach ($this->object->dependencies() as $dep) {
if (!$this->collector->has($dep, false)) {
$this->_checked = false;
}
}
}
return $this->_checked;
} | php | {
"resource": ""
} |
q253853 | Host.getIP | validation | public function getIP() {
$ip = "UNKNOWN";
if (getenv("HTTP_CLIENT_IP")) {
$ip = getenv("HTTP_CLIENT_IP");
} else if(getenv("HTTP_X_FORWARDED_FOR")) {
$ip = getenv("HTTP_X_FORWARDED_FOR");
} else if(getenv("REMOTE_ADDR")) {
$ip = getenv("REMOTE_ADDR");
}
return $ip;
} | php | {
"resource": ""
} |
q253854 | App.checkOptions | validation | private function checkOptions($options)
{
foreach ($this->required as $req) {
if (!array_key_exists($req, $options)) {
throw new \Exception('"' . $req . '" option has not been defined');
}
}
} | php | {
"resource": ""
} |
q253855 | WP_Enqueue_Options.have_required_properties | validation | public function have_required_properties() {
return (
! empty( $this->handle )
&& ! empty( $this->relative_path )
&& ! empty( $this->filename )
);
} | php | {
"resource": ""
} |
q253856 | AttributeCollection.addAttribute | validation | public function addAttribute(AttributeInterface $attribute) {
if(isset($this->attributes[$attribute->getName()]))
trigger_error("Attribute " . $attribute->getName() . " already exists", E_USER_NOTICE);
$this->attributes[ $attribute->getName() ] = $attribute;
} | php | {
"resource": ""
} |
q253857 | AttributeCollection.setAttributes | validation | public function setAttributes(array $attributes) {
foreach($attributes as $key => $attribute) {
if(!($attribute instanceof AttributeInterface)) {
if(is_array($attribute)) {
$attr = new AttributeCollection($key);
$attr->setAttributes($attribute);
$attribute = $attr;
} else {
$attribute = new Attribute($key, $attribute);
}
}
$this->attributes[ $attribute->getName() ] = $attribute;
}
} | php | {
"resource": ""
} |
q253858 | AttributeCollection.removeAttribute | validation | public function removeAttribute(string $attributeName) {
if(isset($this->attributes[$attributeName]))
unset($this->attributes[$attributeName]);
} | php | {
"resource": ""
} |
q253859 | DataSource.setFileSource | validation | public function setFileSource($value)
{
if (isset($this->module->sourceFiles[$value])) {
$this->_fileSource = $this->module->sourceFiles[$value];
} else {
$this->_fileSource = false;
}
} | php | {
"resource": ""
} |
q253860 | DataSource.loadForeignDataItems | validation | protected function loadForeignDataItems()
{
if (!$this->fileSource) {
\d("boom");
return false;
}
$foreignModelClass = $this->foreignModelClass;
$lines = $this->fileSource->getLines($this->lazyForeign);
$lineCount = 0;
foreach ($lines as $id => $line) {
if ($this->lazyForeign) {
$this->createForeignDataItem(null, ['deferredModel' => $line]);
} else {
$model = $this->createModel($line->id, $line->attributes);
$this->createForeignDataItem($model, ['deferredModel' => $line]);
}
$lineCount++;
}
$this->task->addInfo("Processed {$lineCount} lines from {$this->fileSource->id}");
} | php | {
"resource": ""
} |
q253861 | DataSource.createModel | validation | public function createModel($id, $attributes)
{
return Yii::createObject(['class' => $this->foreignModelClass, 'tableName' => $this->fileSource->id, 'interface' => $this->module, 'id' => $id, 'attributes' => $attributes]);
} | php | {
"resource": ""
} |
q253862 | Repository.set | validation | public function set($key, $value)
{
ArrayDot::set($_SESSION[$this->root], $key, $value);
} | php | {
"resource": ""
} |
q253863 | EventManager.register | validation | public function register($event,$obj,$methodName){
$this->events+=[
$event=>[
]
];
$this->events[$event][]=[
'object'=>$obj,
'methodName'=>$methodName,
];
} | php | {
"resource": ""
} |
q253864 | EventManager.fire | validation | public function fire($eventName,$infoClass=null){
if(isset($this->events[$eventName])){
foreach($this->events[$eventName] as $bind=>$data){
call_user_func_array([$data['object'], $data['methodName']], [$infoClass]);
}
}
//FIXME throw exception?
} | php | {
"resource": ""
} |
q253865 | GuzzleHelper.useHeaders | validation | public function useHeaders($name)
{
$headers = $this->httpHeaders->getHeaders($name);
$this->mergeOptions(array('headers' => $headers));
} | php | {
"resource": ""
} |
q253866 | GuzzleHelper.get | validation | public function get($url, $data = array())
{
$client = $this->getClient();
return $client->request('GET', $url, array('query' => $data));
} | php | {
"resource": ""
} |
q253867 | GuzzleHelper.post | validation | public function post($url, $data = array())
{
$client = $this->getClient();
return $client->request('POST', $url, array('form_params' => $data));
} | php | {
"resource": ""
} |
q253868 | Benri_Util_DateTime.format | validation | public function format($format = null)
{
if (null === $format) {
$format = $this->_format;
}
return parent::format($format);
} | php | {
"resource": ""
} |
q253869 | YamlConfigServiceProvider.register | validation | public function register(Application $app)
{
if (is_null($this->filename)) {
throw new \RuntimeException('You must provide a valid config filename');
}
if (!file_exists($this->filename)) {
throw new \RuntimeException(sprintf('Config path \'%s\' is not valid', $this->filename));
}
if (!is_readable($this->filename)) {
throw new \RuntimeException(sprintf('Config path \'%s\' is not readable', $this->filename));
}
$parser = new YamlParser();
$config = $parser->parse(file_get_contents($this->filename));
if (is_array($config) && !empty($config)) {
if (isset($app['config']) && is_array($app['config'])) {
$config = array_replace_recursive($app['config'], $config);
}
$app['config'] = $config;
}
} | php | {
"resource": ""
} |
q253870 | Device.sendToDevice | validation | public function sendToDevice($deviceId, $openId, $content)
{
$params = [
'device_type' => $this->deviceType,
'device_id' => $deviceId,
'open_id' => $openId,
'content' => base64_encode($content),
];
return $this->parseJSON('json', [self::API_TRANS_MSG, $params]);
} | php | {
"resource": ""
} |
q253871 | API.pay | validation | public function pay(Order $order)
{
return $this->request($this->wrapApi(self::API_PAY_ORDER), $order->all());
} | php | {
"resource": ""
} |
q253872 | API.prepare | validation | public function prepare(Order $order)
{
$order->notify_url = $order->get('notify_url', $this->merchant->notify_url);
if (is_null($order->spbill_create_ip)) {
$order->spbill_create_ip = ($order->trade_type === Order::NATIVE) ? get_server_ip() : get_client_ip();
}
return $this->request($this->wrapApi(self::API_PREPARE_ORDER), $order->all());
} | php | {
"resource": ""
} |
q253873 | API.query | validation | public function query($orderNo, $type = self::OUT_TRADE_NO)
{
$params = [
$type => $orderNo,
];
return $this->request($this->wrapApi(self::API_QUERY), $params);
} | php | {
"resource": ""
} |
q253874 | API.close | validation | public function close($tradeNo)
{
$params = [
'out_trade_no' => $tradeNo,
];
return $this->request($this->wrapApi(self::API_CLOSE), $params);
} | php | {
"resource": ""
} |
q253875 | API.reverse | validation | public function reverse($orderNo, $type = self::OUT_TRADE_NO)
{
$params = [
$type => $orderNo,
];
return $this->safeRequest($this->wrapApi(self::API_REVERSE), $params);
} | php | {
"resource": ""
} |
q253876 | API.getSignkey | validation | protected function getSignkey($api)
{
return $this->sandboxEnabled && $api !== self::API_SANDBOX_SIGN_KEY ? $this->getSandboxSignKey() : $this->merchant->key;
} | php | {
"resource": ""
} |
q253877 | API.getSandboxSignKey | validation | protected function getSandboxSignKey()
{
if ($this->sandboxSignKey) {
return $this->sandboxSignKey;
}
// Try to get sandbox_signkey from cache
$cacheKey = 'sandbox_signkey.'.$this->merchant->merchant_id.$this->merchant->sub_merchant_id;
/** @var \Doctrine\Common\Cache\Cache $cache */
$cache = $this->getCache();
$this->sandboxSignKey = $cache->fetch($cacheKey);
if (!$this->sandboxSignKey) {
// Try to acquire a new sandbox_signkey from WeChat
$result = $this->request(self::API_SANDBOX_SIGN_KEY, []);
if ($result->return_code === 'SUCCESS') {
$cache->save($cacheKey, $result->sandbox_signkey, 24 * 3600);
return $this->sandboxSignKey = $result->sandbox_signkey;
}
throw new Exception($result->return_msg);
}
return $this->sandboxSignKey;
} | php | {
"resource": ""
} |
q253878 | Database.connect | validation | public static function connect(string $host = "", int $port = 0, string $dbname = "", string $user = "",
string $pass = "", bool $reconnect = false): ?\PDO
{
// IF the connection already exists AND a reconnect was not requested...
if(self::$pdo !== null && !$reconnect)
// THEN return the current database object!
return self::$pdo;
// IF no hostname was provided AND hostname was not previously set, THEN throw an Exception!
if($host === "" && (self::$databaseHost === null || self::$databaseHost === ""))
throw new Exceptions\DatabaseConnectionException("A valid host name was not provided!");
// OTHERWISE, set the hostname to the one provided or the previous one if none was provided.
$host = $host ?: self::$databaseHost;
// IF no port number was provided AND port number was not previously set, THEN throw an Exception!
if($port === 0 && (self::$databasePort === null || self::$databasePort === 0))
throw new Exceptions\DatabaseConnectionException("A valid port number was not provided!");
// OTHERWISE, set the port number to the one provided or the previous one if none was provided.
$port = $port ?: self::$databasePort;
// IF no database name was provided AND database name was not previously set, THEN throw an Exception!
if($dbname === "" && (self::$databaseName === null || self::$databaseName === ""))
throw new Exceptions\DatabaseConnectionException("A valid database name was not provided!");
// OTHERWISE, set the database name to the one provided or the previous one if none was provided.
$dbname = $dbname ?: self::$databaseName;
// IF no username was provided AND username was not previously set, THEN throw an Exception!
if($user === "" && (self::$databaseUser === null || self::$databaseUser === ""))
throw new Exceptions\DatabaseConnectionException("A valid username was not provided!");
// OTHERWISE, set the username to the one provided or the previous one if none was provided.
$user = $user ?: self::$databaseUser;
// IF no password was provided AND password was not previously set, THEN throw an Exception!
if($pass === "" && (self::$databasePass === null || self::$databasePass === ""))
throw new Exceptions\DatabaseConnectionException("A valid password was not provided!");
// OTHERWISE, set the password to the one provided or the previous one if none was provided.
$pass = $pass ?: self::$databasePass;
// All pre-checks should have ensured a valid state for connection!
try
{
// Attempt to create a new database connection using the provided information.
self::$pdo = new \PDO("pgsql:host=$host;port=$port;dbname=$dbname", $user, $pass, [
// Setting some default options.
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
]);
// IF the connection is valid, return the new database object!
if(self::$pdo)
return self::$pdo;
}
catch(\PDOException $e)
{
// OTHERWISE, throw an Exception!
throw new Exceptions\DatabaseConnectionException($e->getMessage());
}
// We should NEVER reach this line of code, but if we somehow do, return NULL!
return null;
} | php | {
"resource": ""
} |
q253879 | Database.select | validation | public static function select(string $table, array $columns = [], string $orderBy = ""): array
{
// Get a connection to the database.
$pdo = self::connect();
// Generate a SQL statement, given the provided parameters.
$sql =
"SELECT ".($columns === [] ? "*" : "\"".implode("\", \"", $columns)."\"")." FROM \"$table\"".
($orderBy !== "" ? " ORDER BY $orderBy" : "");
// Execute the query.
$results = $pdo->query($sql)->fetchAll();
// Return the results!
return $results;
} | php | {
"resource": ""
} |
q253880 | Container.rethrowExceptions | validation | protected function rethrowExceptions(callable $callable) {
try {
return $callable();
} catch (ImplementationNotFoundException $ex) {
throw new ImplementationNotFoundException($ex->getMessage());
} catch (TypeMismatchException $ex) {
throw new TypeMismatchException($ex->getMessage());
} catch (UnresolveableArgumentException $ex) {
throw new UnresolveableArgumentException($ex->getMessage());
} catch (ValueNotFoundException $ex) {
throw new ValueNotFoundException($ex->getMessage());
} catch (InvalidCallableFormatException $ex) {
throw new InvalidCallableFormatException($ex->getMessage());
} catch (MissingDefinitionIdentifierException $ex) {
throw new MissingDefinitionIdentifierException($ex->getMessage());
} catch (MissingDefinitionValueException $ex) {
throw new MissingDefinitionValueException($ex->getMessage());
} catch (ClassNotFoundException $ex) {
throw new ClassNotFoundException($ex->getMessage());
}
} | php | {
"resource": ""
} |
q253881 | Factory.init | validation | public function init($adapter, $client = null)
{
// set the server adapter
$this->adapter = $adapter;
// for ease of use we can fallback to a default http client
if (!$client) {
$client = new \PeterColes\Cluster\HttpClients\GuzzleHttp;
}
// initialise the http client with the authentication header options
$client->initClient($this->adapter->getHeaders());
// make the initialised http client available to the adapter
$this->adapter->setClient($client);
} | php | {
"resource": ""
} |
q253882 | Container.add | validation | public function add($key, $value)
{
try
{
$this->getRecursive($key, $this->data);
}
catch (ElementNotFoundException $e)
{
$this->set($key, $value);
}
} | php | {
"resource": ""
} |
q253883 | Container.set | validation | public function set($key, $value)
{
if (!is_string($key))
throw new InvalidArgumentException('First parameter has to be a string');
if (!$this->isTypeSupported(gettype($value)))
throw new UnsupportedException('First parameter has to be an int, a double, a bool or a string');
try
{
// try to find the key, and set the value if this succeeds
$this->getRecursive($key, $this->data);
$this->data = $this->setRecursive($key, $value);
}
catch (ElementNotFoundException $e)
{
$this->data = array_merge_recursive($this->data, $this->setRecursive($key, $value));
}
} | php | {
"resource": ""
} |
q253884 | BaseWidget.getWidgetId | validation | public function getWidgetId()
{
if (!is_null($this->_widgetId)) {
return $this->_widgetId;
}
return $this->_widgetId = 'ic-widget-' . md5(microtime() . mt_rand());
} | php | {
"resource": ""
} |
q253885 | BaseWidget.getSystemId | validation | public function getSystemId()
{
if (!isset($this->_systemId)) {
if (isset($this->collectorItem) && isset($this->collectorItem->systemId)) {
$this->_systemId = $this->collectorItem->systemId;
}
}
return $this->_systemId;
} | php | {
"resource": ""
} |
q253886 | FormRow.render | validation | public function render(ElementInterface $element)
{
$label = $element->getLabel();
if (isset($label) && '' !== $label) {
// Translate the label
if (null !== ($translator = $this->getTranslator())) {
$label = $translator->translate(
$label, $this->getTranslatorTextDomain()
);
$element->setLabel($label);
}
}
return parent::render($element);
} | php | {
"resource": ""
} |
q253887 | ResultStore.setTrue | validation | public function setTrue($obData = null)
{
$this->bStatus = true;
$this->obData = $obData;
return $this;
} | php | {
"resource": ""
} |
q253888 | ResultStore.setFalse | validation | public function setFalse($obData = null)
{
$this->bStatus = false;
$this->obData = $obData;
return $this;
} | php | {
"resource": ""
} |
q253889 | ResultStore.get | validation | public function get()
{
$arResult = [
'status' => $this->status(),
'data' => $this->data(),
'message' => $this->message(),
'code' => $this->code(),
];
return $arResult;
} | php | {
"resource": ""
} |
q253890 | AsseticFactoryBuilder.build | validation | public function build()
{
$assetManager = new AssetManager();
$filterManager = new FilterManager();
foreach ($this->filters as $filterName => $filter) {
$filterManager->set($filterName, $filter);
}
$assetsFactory = new AssetFactory($this->configurationHandler->webDir());
$assetsFactory->setAssetManager($assetManager);
$assetsFactory->setFilterManager($filterManager);
return $assetsFactory;
} | php | {
"resource": ""
} |
q253891 | Text.readFileContents | validation | protected function readFileContents($language)
{
$fileName = $this->getFileName($language);
$fs = $this->env->getFileSystem();
if (!$fs->fileExists($fileName)) {
return array();
}
$content = json_decode(preg_replace('/^.*?define\((.*)\);\s*/s', '$1', $fs->getFile($fileName)), true);
if ($language === $this->baseLang) {
$content = $content['root'];
}
$outdateInfo = [];
$fileName = $this->getOutdateInfoFileName($language);
if ($fs->fileExists($fileName)) {
$outdateInfo = json_decode($fs->getFile($fileName), true);
}
foreach ($content as $id => $text) {
$outdated = isset($outdateInfo[$id]) ? $outdateInfo[$id] : true;
$content[$id] = array('id' => $id, 'name' => $id, 'content' => $text, 'outdated' => $outdated);
}
return $content;
} | php | {
"resource": ""
} |
q253892 | Text.writeTextsToFile | validation | private function writeTextsToFile($language)
{
$textInfo = array();
$outdateInfo = array();
foreach ($this->contents[$language] as $id => $info) {
$textInfo[$id] = $info['content'];
$outdateInfo[$id] = $info['outdated'];
}
if ($language === $this->baseLang) {
$content = array('root' => $textInfo) + array_fill_keys($this->extraLangs, true);
} else {
$content = $textInfo;
}
$encodeFlags = JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES;
$content = "'use strict';\n/*global define*/\ndefine(" . json_encode($content, $encodeFlags) . ");\n";
$fs = $this->env->getFileSystem();
$fs->putFile($this->getFileName($language), $content);
$fs->putFile($this->getOutdateInfoFileName($language), json_encode($outdateInfo, $encodeFlags));
} | php | {
"resource": ""
} |
q253893 | Text.getPageTexts | validation | public function getPageTexts($language)
{
if (!isset($this->contents[$language])) {
$this->contents[$language] = $this->readFileContents($language);
}
return $this->contents[$language];
} | php | {
"resource": ""
} |
q253894 | Text.getTextsWithBaseTexts | validation | public function getTextsWithBaseTexts($language)
{
$texts = $this->getPageTexts($language);
if ($language !== $this->baseLang) {
$baseTexts = $this->getPageTexts($this->baseLang);
$texts = array_map(
function ($text, $baseText) {
return $text + array("basecontent" => $baseText['content']);
},
$texts,
$baseTexts
);
}
return $texts;
} | php | {
"resource": ""
} |
q253895 | Text.getText | validation | public function getText($name, $language)
{
$allTexts = $this->getPageTexts($language);
if (isset($allTexts[$name])) {
return $allTexts[$name];
} else {
return null;
}
} | php | {
"resource": ""
} |
q253896 | Text.addTextContainer | validation | public function addTextContainer($name, $content, $language)
{
$allTexts = $this->getPageTexts($language);
if (isset($allTexts[$name])) {
throw new \Exception("Text container name already used.");
}
$this->contents[$language][$name] = array(
'id' => $name,
'name' => $name,
'content' => $content,
'outdated' => false
);
$this->writeTextsToFile($language);
if ($language === $this->baseLang) {
$this->setExtraLanguagesOutdated($name, $content);
}
return $this->contents[$language][$name];
} | php | {
"resource": ""
} |
q253897 | Text.modifyTextContainer | validation | public function modifyTextContainer($oldName, $newName, $content, $language)
{
foreach ($this->languages as $lang) {
$modified = false;
$allTexts = $this->getPageTexts($lang);
if (!isset($allTexts[$oldName])) {
throw new \Exception("Text container unknown.");
}
if ($oldName !== $newName) {
if (isset($allTexts[$newName])) {
throw new \Exception("Text container already exists");
}
$this->contents[$lang][$newName] = $this->contents[$lang][$oldName];
$this->contents[$lang][$newName]['id'] = $newName;
$this->contents[$lang][$newName]['name'] = $newName;
unset($this->contents[$lang][$oldName]);
$modified = true;
}
if ($language === $lang) {
$this->contents[$lang][$newName]['content'] = $content;
$this->contents[$lang][$newName]['outdated'] = false;
$modified = true;
} elseif ($language === $this->baseLang) {
$this->contents[$lang][$newName]['outdated'] = true;
$modified = true;
}
if ($modified) {
$this->writeTextsToFile($lang);
}
}
return $this->contents[$language][$newName];
} | php | {
"resource": ""
} |
q253898 | Text.deleteTextContainer | validation | public function deleteTextContainer($name)
{
foreach ($this->languages as $lang) {
$this->getPageTexts($lang);
unset($this->contents[$lang][$name]);
$this->writeTextsToFile($lang);
}
} | php | {
"resource": ""
} |
q253899 | Text.getFileName | validation | private function getFileName($language)
{
if ($language === $this->baseLang) {
return $this->baseDir . $this->pageName . '.js';
} else {
return $this->baseDir . $language . '/' . $this->pageName . '.js';
}
} | php | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.