_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q253000
Comment.deleteReply
validation
public function deleteReply($msgId, $index, $commentId) { $params = [ 'msg_data_id' => $msgId, 'index' => $index, 'user_comment_id' => $commentId, ]; return $this->parseJSON('json', [self::API_DELETE_REPLY, $params]); }
php
{ "resource": "" }
q253001
Collection.getArray
validation
public static function getArray() { $object = new \ReflectionClass( Collection::class ); $properties = $object->getProperties(\ReflectionProperty::IS_PUBLIC); $array = array(); foreach ($properties as $property) { $value = $property->getValue(); if (!empty($value)) { $array[$property->getName()] = $value; } } return $array; }
php
{ "resource": "" }
q253002
Collection.set
validation
public static function set($property, $value = NULL) { $object = new \ReflectionClass( Collection::class ); $object->setStaticPropertyValue($property, $value); return true; }
php
{ "resource": "" }
q253003
Collection.get
validation
public static function get($property, $default = NULL) { $object = new \ReflectionClass( Collection::class ); $value = $object->getStaticPropertyValue($property); //If there is no value return the default return (empty($value)) ? $default : $value; }
php
{ "resource": "" }
q253004
IsPipeline.replace
validation
public function replace($needle, $replacement): Pipeline { $stages = []; $found = false; foreach ($this->stages as $stage) { if ($this->matches($stage, $needle)) { $stages[] = $replacement; $found = true; continue; } $stages[] = $stage; } if ($found) { $pipeline = clone $this; $pipeline->stages = $stages; return $pipeline; } unset($stages); return $this; }
php
{ "resource": "" }
q253005
IsPipeline.handleStage
validation
protected function handleStage(&$stages, $stage) { if ($stage instanceof Pipeline) { $stages = array_merge($stages, $stage->stages()); } elseif ($stage instanceof MiddlewareInterface) { $stages[] = $stage; } elseif ($stage instanceof RequestHandlerInterface) { $stages[] = new RequestHandler($stage); } elseif (is_callable($stage)) { $stages[] = new Lambda($stage); } else { throw new InvalidMiddlewareArgument(is_string($stage) ? $stage : get_class($stage)); } }
php
{ "resource": "" }
q253006
Filter.remove
validation
public function remove(ExpressionContract $e) { unset($this->expressions[$this->indexOf($e)]); $this->expressions = array_values($this->expressions); return $this; }
php
{ "resource": "" }
q253007
Filter.indexOf
validation
public function indexOf($expressionOrColumn) { if ($expressionOrColumn instanceof ExpressionContract) { return $this->indexOfExpression($expressionOrColumn); } return $this->indexOfColumn($expressionOrColumn); }
php
{ "resource": "" }
q253008
SentinelReplication.wipeServerList
validation
protected function wipeServerList() { $this->reset(); $this->master = null; $this->slaves = array(); $this->pool = array(); }
php
{ "resource": "" }
q253009
SentinelReplication.updateSentinels
validation
public function updateSentinels() { SENTINEL_QUERY: { $sentinel = $this->getSentinelConnection(); try { $payload = $sentinel->executeCommand( RawCommand::create('SENTINEL', 'sentinels', $this->service) ); $this->sentinels = array(); // NOTE: sentinel server does not return itself, so we add it back. $this->sentinels[] = $sentinel->getParameters()->toArray(); foreach ($payload as $sentinel) { $this->sentinels[] = array( 'host' => $sentinel[3], 'port' => $sentinel[5], 'role' => 'sentinel', ); } } catch (ConnectionException $exception) { $this->sentinelConnection = null; goto SENTINEL_QUERY; } } }
php
{ "resource": "" }
q253010
SentinelReplication.getConnectionByRole
validation
public function getConnectionByRole($role) { if ($role === 'master') { return $this->getMaster(); } elseif ($role === 'slave') { return $this->pickSlave(); } elseif ($role === 'sentinel') { return $this->getSentinelConnection(); } }
php
{ "resource": "" }
q253011
SentinelReplication.switchTo
validation
public function switchTo(NodeConnectionInterface $connection) { if ($connection && $connection === $this->current) { return; } if ($connection !== $this->master && !in_array($connection, $this->slaves, true)) { throw new \InvalidArgumentException('Invalid connection or connection not found.'); } $connection->connect(); if ($this->current) { $this->current->disconnect(); } $this->current = $connection; }
php
{ "resource": "" }
q253012
SentinelReplication.retryCommandOnFailure
validation
private function retryCommandOnFailure(CommandInterface $command, $method) { $retries = 0; SENTINEL_RETRY: { try { $response = $this->getConnectionByCommand($command)->$method($command); } catch (CommunicationException $exception) { $this->wipeServerList(); $exception->getConnection()->disconnect(); if ($retries == $this->retryLimit) { throw $exception; } usleep($this->retryWait * 1000); ++$retries; goto SENTINEL_RETRY; } } return $response; }
php
{ "resource": "" }
q253013
ModuleDependencyResolver.resolve
validation
public function resolve() : array { try{ $app_required_modules = array_unique($this->required_modules); // get component dependency map $component_dependency_map = $this->getComponentDependencyMap($app_required_modules); // resolve component dependency $component_type_list = $this->resolveComponentDependencyMap($component_dependency_map); // add component modules to resolved list $component_module_list = []; foreach($component_type_list as $component_type){ $component_module = $this->findComponentModuleByType($app_required_modules, $component_type); if (!$component_module){ throw new ModuleDependencyResolverException( 'Could not find component module: ' . $component_type ); } if (!in_array($component_module, $component_module_list)){ $component_module_list[] = $component_module; } } // merge module lists $module_list = array_merge($component_module_list, $app_required_modules); // get module dependency map $module_dependency_map = self::getModuleDependencyMap($module_list); // resolve module dependency $resolved_list = $this->resolveModuleDependencyMap($module_dependency_map); return $resolved_list; } catch(\Throwable $e) { throw new ModuleDependencyResolverException(__METHOD__ . ' failed: ' . $e->getMessage(), $e); } }
php
{ "resource": "" }
q253014
ModuleDependencyResolver.findComponentModuleByType
validation
private function findComponentModuleByType(array $module_list, string $find_component_type) { foreach($module_list as $m) { $component_type = call_user_func([$m, 'declareComponentType']); if ($component_type == $find_component_type){ return $m; } } return null; }
php
{ "resource": "" }
q253015
CalcDef.getMaxPercentForPersonalBonus
validation
private function getMaxPercentForPersonalBonus($levels) { $result = 0; foreach ($levels as $percent) { if ($percent > $result) { $result = $percent; } } return $result; }
php
{ "resource": "" }
q253016
Site.getIsEnabled
validation
protected function getIsEnabled(): \Illuminate\Database\Eloquent\Model { $result = Model\Setting::find(1); $result->value = (bool) $result->value; return $result; }
php
{ "resource": "" }
q253017
CliQuestion.getHelper
validation
public function getHelper() { if ($this->helper === null) { $this->helper = $this->command->getHelper('question'); } return $this->helper; }
php
{ "resource": "" }
q253018
LinkedCustomFieldsType.appendChoice
validation
public function appendChoice(FormEvent $event) { $rootForm = $this->getRootForm($event->getForm()); $group = $rootForm->getData(); if ($group === NULL) { return; } $choices = array(); foreach($group->getCustomFields() as $customFields) { $choices[$customFields->getSlug()] = $this->translatableStringHelper ->localize($customFields->getName()); } $options = array_merge($this->options, array( 'choice_list' => new SimpleChoiceList($choices), )); $event->getForm()->getParent()->add($this->choiceName, 'choice', $options); }
php
{ "resource": "" }
q253019
StartFromThemeController.startAction
validation
public function startAction(Request $request, Application $app) { $options = array( "request" => $request, "configuration_handler" => $app["red_kite_cms.configuration_handler"], ); return parent::start($options); }
php
{ "resource": "" }
q253020
HelperMakeCommand.buildClass
validation
protected function buildClass($name) { $stub = $this->files->get($this->getStub()); return str_replace('DummyHelper', $this->getNameInput(), $stub); }
php
{ "resource": "" }
q253021
EntityDbMapper.fromDbToEntity
validation
public function fromDbToEntity(array $data) { $hydratorFactory = $this->documentManager->getHydratorFactory(); $documentClass = $this->documentClass; $document = new $documentClass(); $hydratorFactory->hydrate($document, $data); return $document; }
php
{ "resource": "" }
q253022
EntityDbMapper.fromEntityToDb
validation
public function fromEntityToDb($document) { $unitOfWork = $this->documentManager->getUnitOfWork(); $persistenceBuilder = new PersistenceBuilder($this->documentManager, $unitOfWork); $mapping = array ( 'targetDocument' => $this->documentClass, ); return $persistenceBuilder->prepareEmbeddedDocumentValue($mapping, $document, true); }
php
{ "resource": "" }
q253023
ExtendableCollectionBlock.generateSourceFromChildren
validation
protected function generateSourceFromChildren() { $i = 1; $children = array(); foreach ($this->children as $child) { $childValue = Yaml::parse($child->getSource()); if (is_array($childValue) && array_key_exists("type", $childValue)) { $childValue["type"] = $child->getType(); } $children['item' . $i] = $childValue; $i++; } $source = array( "children" => $children, ); if (!empty($this->tags)) { $source["tags"] = $this->tags; } $source["type"] = $this->type; return $source; }
php
{ "resource": "" }
q253024
Page.add
validation
public function add($title, $description, $pageUrl, $iconUrl, $comment = '') { $params = [ 'title' => $title, 'description' => $description, 'page_url' => $pageUrl, 'icon_url' => $iconUrl, ]; if ($comment !== '') { $params['comment'] = $comment; } return $this->parseJSON('json', [self::API_ADD, $params]); }
php
{ "resource": "" }
q253025
Page.update
validation
public function update($pageId, $title, $description, $pageUrl, $iconUrl, $comment = '') { $params = [ 'page_id' => intval($pageId), 'title' => $title, 'description' => $description, 'page_url' => $pageUrl, 'icon_url' => $iconUrl, ]; if ($comment !== '') { $params['comment'] = $comment; } return $this->parseJSON('json', [self::API_UPDATE, $params]); }
php
{ "resource": "" }
q253026
Page.pagination
validation
public function pagination($begin, $count) { $params = [ 'type' => 2, 'begin' => intval($begin), 'count' => intval($count), ]; return $this->parseJSON('json', [self::API_SEARCH, $params]); }
php
{ "resource": "" }
q253027
Page.delete
validation
public function delete($pageId) { $params = [ 'page_id' => intval($pageId), ]; return $this->parseJSON('json', [self::API_DELETE, $params]); }
php
{ "resource": "" }
q253028
Date.getAgeByDate
validation
public static function getAgeByDate(string $sBirthday) : int { list($iYear, $iMonth, $iDay) = preg_split('/[-.]/', $sBirthday); $aToday = array(); $aToday['mois'] = date('n'); $aToday['jour'] = date('j'); $aToday['annee'] = date('Y'); $iYears = $aToday['annee'] - $iYear; if ($aToday['mois'] <= $iMonth) { if ($iMonth == $aToday['mois']) { if ($iDay > $aToday['jour']) { $iYears--; } } else { $iYears--; } } return $iYears; }
php
{ "resource": "" }
q253029
Tv.updateTv
validation
private function updateTv($dwnl) { $entity = new EBonDwnl(); /** @var EBonDwnl $one */ foreach ($dwnl as $one) { $tv = $one->getTv(); $calcId = $one->getCalculationRef(); $custId = $one->getCustomerRef(); $entity->setTv($tv); $id = [ EBonDwnl::A_CALC_REF => $calcId, EBonDwnl::A_CUST_REF => $custId ]; $this->daoBonDwnl->updateById($id, $entity); } }
php
{ "resource": "" }
q253030
ElFinderFilesController.filesAction
validation
public function filesAction(Request $request, Application $app) { $options = array( "connector" => $app["red_kite_cms.elfinder_files_connector"], ); return parent::show($options); }
php
{ "resource": "" }
q253031
MimeMessage.clear
validation
public function clear($name = null) { if (!is_null($name)) { $name = strtolower($name); if (array_key_exists($name, self::$clearings)) { $this->{$name} = self::$clearings[$self::$clearings]; } } else { foreach (self::$clearings as $n=>$v) { $this->{$n} = $v; } } return $this; }
php
{ "resource": "" }
q253032
MimeMessage.setFrom
validation
public function setFrom($mail = '', $name = null, $reply = true) { $mail = trim($mail); if (strlen($mail) && Helper::isEmail($mail)) { $this->from = !empty($name) ? array($name=>$mail) : array($mail); $this->getMailer()->setRegistry('Return-Path', '<'.$mail.'>', 'headers'); $this->getMailer()->setRegistry('X-Sender', $mail, 'headers'); if ($reply) { $this->setReplyTo($mail, $name); } } return $this; }
php
{ "resource": "" }
q253033
MimeMessage.setTo
validation
public function setTo($mail = '', $name = null) { $this->to = Helper::deduplicate( array_merge($this->to, call_user_func_array(array('\MimeMailer\Helper', 'checkPeopleArgs'), func_get_args())) ); return $this; }
php
{ "resource": "" }
q253034
MimeMessage.setCc
validation
public function setCc($mail = '', $name = null) { $this->cc = Helper::deduplicate( array_merge($this->cc, call_user_func_array(array('\MimeMailer\Helper', 'checkPeopleArgs'), func_get_args())) ); return $this; }
php
{ "resource": "" }
q253035
MimeMessage.setBcc
validation
public function setBcc($mail = '', $name = null) { $this->bcc = Helper::deduplicate( array_merge($this->bcc, call_user_func_array(array('\MimeMailer\Helper', 'checkPeopleArgs'), func_get_args())) ); return $this; }
php
{ "resource": "" }
q253036
MimeMessage.setAttachment
validation
public function setAttachment($file = '', $clear = false) { if (true===$clear) { $this->clear('text'); } if (is_array($file)) { foreach ($file as $_f) { if (file_exists($_f)) { $this->attachment[] = $_f; } } } else { if (file_exists($file)) { $this->attachment[] = $file; } } return $this; }
php
{ "resource": "" }
q253037
MimeMessage.setSubject
validation
public function setSubject($subject = '', $clear = false) { if (true===$clear) { $this->clear('subject'); } $this->subject = $subject; return $this; }
php
{ "resource": "" }
q253038
MimeMessage.setText
validation
public function setText($text = '', $clear = false) { if (true===$clear) { $this->clear('text'); } if ('auto'==$text) { if (!empty($this->html)) { $html_content = preg_replace("/.*<body[^>]*>|<\/body>.*/si", "", $this->html); $this->text .= Helper::formatText(Helper::html2text($html_content)); } } else { $this->text .= Helper::formatText($text); } return $this; }
php
{ "resource": "" }
q253039
MimeMessage.setHtml
validation
public function setHtml($html = '', $clear = false) { if (true===$clear) { $this->clear('text'); } $this->html .= Helper::formatText($html, 'ascii'); return $this; }
php
{ "resource": "" }
q253040
MimeMessage.setReplyTo
validation
public function setReplyTo($mail = '', $name = null) { if (strlen($mail) && Helper::isEmail($mail)) { if (!empty($name)) { $_m = Helper::mailTagger($mail, $name); } else { $_m = $mail; } $this->getMailer()->setRegistry('Reply-To', $_m, 'headers'); } return $this; }
php
{ "resource": "" }
q253041
MimeMessage.substitution
validation
public function substitution($search, $replace) { $this->body = str_replace($search, $replace, $this->body); return $this->body; }
php
{ "resource": "" }
q253042
Main.hookTemplateRender
validation
public function hookTemplateRender($templates, $data, $rendered, $controller) { $template = reset($templates); if (strpos($template, '/modules/ga_report/templates/panels/') !== false && isset($data['content']['data']['report']['data']) && isset($data['content']['data']['handler']['id'])) { $handler_id = $data['content']['data']['handler']['id']; $controller->setJsSettings("ga_chart_$handler_id", $data['content']['data']['report']['data']); $controller->setJs(__DIR__ . "/js/handlers/$handler_id.js"); $controller->setJs(__DIR__ . "/js/common.js"); } }
php
{ "resource": "" }
q253043
Setup.import
validation
public static function import($name) { $importPath = FOREVERPHP_ROOT . DS . $name . '.php'; if (file_exists($importPath)) { include_once $importPath; } else { throw new SetupException("The object to import ($name) not exists."); } }
php
{ "resource": "" }
q253044
Setup.importFromApp
validation
public static function importFromApp($path) { $importPath = APPS_ROOT . DS . $path . '.php'; if (file_exists($importPath)) { include_once $importPath; } else { throw new SetupException("The object to import ($path) not exists."); } }
php
{ "resource": "" }
q253045
Builder.isRelation
validation
public function isRelation($key) { if(!method_exists($this->model, $key)) { return false; } $relation = $this->model->{$key}(); return ($relation instanceof Relation); }
php
{ "resource": "" }
q253046
Builder.get
validation
public function get($columns = array('*')) { $columnsPassed = (func_num_args() > 1); $columns = $columnsPassed ? $columns : $this->getQueryColumns(); $query = $this->buildQuery($columns); if (!$columnsPassed) { // addJoinOnce adds queryColumns again... return $query->get($this->getQueryColumns()); } if (!$columns) { return $query->get(); } return $query->get($columns); }
php
{ "resource": "" }
q253047
Builder.chunk
validation
public function chunk($count, callable $callback){ return $this->buildQuery($this->getQueryColumns())->chunk($count, $callback); }
php
{ "resource": "" }
q253048
Builder.lists
validation
public function lists($column, $key = null){ return $this->buildQuery([$column])->lists($column, $key); }
php
{ "resource": "" }
q253049
Builder.paginate
validation
public function paginate($perPage = null, $columns = array('*')) { $columnsPassed = (func_num_args() > 1) && ($columns !== null); $columns = $columnsPassed ? $columns : $this->getQueryColumns(); $query = $this->buildQuery($columns); if ($columnsPassed) { return $query->paginate($perPage, $columns); } // addJoinOnce adds queryColumns again... return $query->paginate($perPage, $this->getQueryColumns()); }
php
{ "resource": "" }
q253050
DataItem.fillRelationConfig
validation
protected function fillRelationConfig(&$config, $otherObject) { if (isset($config['parent_object_id'])) { $config['child_object_id'] = $otherObject; } elseif (isset($config['child_object_id'])) { $config['parent_object_id'] = $otherObject; } }
php
{ "resource": "" }
q253051
DataItem.loadForeignObject
validation
protected function loadForeignObject() { if ($this->_isLoadingForeignObject) { throw new RecursionException('Ran into recursion while loading foreign object'); } $this->_isLoadingForeignObject = true; if (isset($this->deferredModel) && ($attributes = $this->deferredModel->attributes)) { $this->foreignObject = $this->dataSource->createModel($this->deferredModel->id, $this->deferredModel->attributes); } $this->_isLoadingForeignObject = false; }
php
{ "resource": "" }
q253052
DataItem.loadLocalObject
validation
protected function loadLocalObject() { if ($this->_isLoadingLocalObject) { throw new RecursionException('Ran into recursion while loading local object'); } $this->_isLoadingLocalObject = true; if (isset($this->foreignObject) && !isset($this->_localObject)) { $keyTranslation = $this->dataSource->getKeyTranslation($this->foreignObject); if (!empty($keyTranslation) && ($localObject = $keyTranslation->object)) { $this->localObject = $localObject; } } $this->_isLoadingLocalObject = false; }
php
{ "resource": "" }
q253053
Benchmark.setPointInLog
validation
public static function setPointInLog(string $sName = 'default') { $oLogger = Debug::getInstance(); $oLogger->info('BENCHMARK: Time at this point '.(microtime(true) - self::$_fStart).' - '.$sName); }
php
{ "resource": "" }
q253054
Material.lists
validation
public function lists($type, $offset = 0, $count = 20) { $params = [ 'type' => $type, 'offset' => intval($offset), 'count' => min(20, $count), ]; return $this->parseJSON('json', [self::API_LISTS, $params]); }
php
{ "resource": "" }
q253055
Install.step1
validation
protected function step1(){ //this is step 1; $this->view->addToBlock("form", "import://admin/setup/license"); $this->view->setData("step", "1"); $this->view->setData("title", t("Installation | EULA")); return; }
php
{ "resource": "" }
q253056
Install.step2
validation
protected function step2(){ $this->view->addToBlock("form", "import://admin/setup/requirements"); $this->view->setData("step", "2"); $this->view->setData("title", t("Installation | Requirements")); $systemcheck = new Helpers\Requirements(); $requirements = []; $directives = require_once( PATH_CONFIG.'/requirements.inc' ); //Check Modules $server = ["title"=>"Required Server Software", "tests"=>[]]; foreach( $directives["server"] as $name=>$directive ){ $server["tests"][] = $systemcheck->testServerVersions($name, $directive); } $requirements[] = $server; //Check Modules $modules = ["title"=>"Required Modules", "tests"=>[]]; foreach( $directives["modules"] as $name=>$directive ){ $modules["tests"][] = $systemcheck->testModule($name, $directive); } $requirements[] = $modules; //Check Modules $limits = ["title"=>"Required Resource Limits", "tests"=>[]]; foreach( $directives["limits"] as $name=>$directive ){ $limits["tests"][] = $systemcheck->testLimit($name, $directive); } $requirements[] = $limits; //Check Modules $directories = ["title"=>"Required Folder Permissions", "tests"=>[]]; foreach( $directives["directories"] as $name=>$directive ){ $directories["tests"][] = $systemcheck->testFolderPermissions($directive["path"], $directive); } $requirements[] = $directories; $this->view->setDataArray( ["requirements"=> $requirements ]); return; }
php
{ "resource": "" }
q253057
Install.step3
validation
protected function step3(){ $this->view->addToBlock("form", "import://admin/setup/database"); $this->view->setData("step", "3"); $this->view->setData("randomstring", getRandomString('5')."_"); $this->view->setData("title", t("Installation | Database Settings")); return; }
php
{ "resource": "" }
q253058
Install.step4
validation
protected function step4(){ //this is step 1; $this->view->addToBlock("form", "import://admin/setup/user"); $this->view->setData("step", "4"); $this->view->setData("title", t("Installation | Install SuperUser")); if ($this->application->input->methodIs("post")) { // $this->view->setData("alerts", [ ["message"=>t('Success. The database was successfully configured'),"type"=>'success'] ] ); $install = new Helpers\Install($this->application->config, $this->application->encrypt ); //preform the installation; if(!$install->database( $this->application )){ $this->application->dispatcher->redirect("/admin/setup/install/3"); } $this->response->addAlert("Wohooo! The database was successfully configure. Now please create a super user.", "info"); } return; }
php
{ "resource": "" }
q253059
IncludeComponentTrait.setServiceLocator
validation
public function setServiceLocator(ServiceLocatorInterface $serviceLocator) { $this->serviceLocator = $serviceLocator; $config = $serviceLocator->getServiceLocator()->get('config'); if (isset($config['rznviewcomponent'])) { $this->config = $config['rznviewcomponent']; } return $this; }
php
{ "resource": "" }
q253060
SampleBootstrap.addAppDependencies
validation
public function addAppDependencies() { /** * @var \Pimple\Container $container */ $container = $this->getContainer(); $container['person'] = $container->protect(function ($name) { return 'Person name: ' . $name; }); return $this; }
php
{ "resource": "" }
q253061
ListTable.cell_default
validation
public function cell_default($item, $column) { $ret = $this->val($item, $column); return is_null($ret) ? '' : $ret; }
php
{ "resource": "" }
q253062
ListTable.prepare_items
validation
function prepare_items() { $this->columns = array( $this->get_columns(), $this->get_hidden_columns(), $this->get_sortable_columns() ); $this->items = $this->get_items(); usort($this->example_data, array($this, 'usort_reorder')); //paging //$per_page = $this->get_items_per_page('books_per_page', 5); //$current_page = $this->get_pagenum(); }
php
{ "resource": "" }
q253063
ListTable.render_admin_header
validation
public function render_admin_header() { //$page = (isset($_GET['page'])) ? esc_attr($_GET['page']) : false; $page = filter_input(INPUT_GET, 'page'); if ($this->page != $page) { return; } echo '<style type="text/css">'; echo $this->twig->render('list_table.css.twig', array()); echo '</style>'; }
php
{ "resource": "" }
q253064
Stack.replace
validation
public function replace($middleware, $with) { $this->pipeline = $this->pipeline->replace($middleware, $with); return $this; }
php
{ "resource": "" }
q253065
Bomifier.detect
validation
public function detect() { $str = file_get_contents($this->uri); foreach ($this->getBom('all') as $encoding => $bom) { if (0 === strncmp($str, $bom, strlen($bom))) { return $encoding; } } }
php
{ "resource": "" }
q253066
Bomifier.add
validation
public function add($encoding = 'UTF-8') { $str = file_get_contents($this->uri); return file_put_contents($this->uri, $this->getBom($encoding) . $str); }
php
{ "resource": "" }
q253067
Bomifier.remove
validation
public function remove($encoding) { $str = file_get_contents($this->uri); return file_put_contents($this->uri, substr($str, (strlen($this->getBom($encoding))))); }
php
{ "resource": "" }
q253068
Bomifier.getBom
validation
public function getBom($encoding = 'UTF-8') { $boms = array( 'UTF-8' => pack('CCC', 0xef, 0xbb, 0xbf), 'UTF-16 Big Endian' => pack('CC', 0xfe, 0xff), 'UTF-16 Little Endian' => pack('CC', 0xff, 0xfe), 'UTF-32 Big Endian' => pack('CCCC', 0x00, 0x00, 0xfe, 0xff), 'UTF-32 Little Endian' => pack('CCCC', 0xff, 0xfe, 0x00, 0x00), 'SCSU' => pack('CCC', 0x0e, 0xfe, 0xff), 'UTF-7 (1)' => pack('CCCC', 0x2b, 0x2f, 0x76, 0x38), 'UTF-7 (2)' => pack('CCCC', 0x2b, 0x2f, 0x76, 0x39), 'UTF-7 (3)' => pack('CCCC', 0x2b, 0x2f, 0x76, 0x2b), 'UTF-7 (4)' => pack('CCCC', 0x2b, 0x2f, 0x76, 0x2f), 'UTF-7 (5)' => pack('CCCCC', 0x2b, 0x2f, 0x76, 0x38, 0x2d), 'UTF-1' => pack('CCC', 0xF7, 0x64, 0x4c), 'UTF-EBCDIC' => pack('CCCC', 0xdd, 0x73, 0x66, 0x73), 'BOCU-1' => pack('CCC', 0xfb, 0xee, 0x28), 'GB-18030' => pack('CCCC', 0x84, 0x31, 0x95, 0x33), ); if ('all' == $encoding) { return $boms; } return $boms[$encoding]; }
php
{ "resource": "" }
q253069
Bomifier.setUri
validation
public function setUri($uri) { if (!empty($uri) && !is_file($uri)) { throw new \Exception(sprintf('File %s not found.', $uri)); } $this->uri = $uri; return $this; }
php
{ "resource": "" }
q253070
TaggedCollection.getByTag
validation
public function getByTag($tag) { $taggings = $this->getTaggings(); if (array_key_exists($tag, $taggings)) { return $taggings[$tag]; } return array(); }
php
{ "resource": "" }
q253071
TaggedCollection.expand
validation
protected function expand() { foreach ($this as $key => $item) { $item['slug'] = $key; if (isset($item['date'])) { $item['formatted_date'] = date(self::DATE_FORMAT, $item['date']); } $this->set($key, $item); } }
php
{ "resource": "" }
q253072
Container.create
validation
public static function create($command, $app) { static $cache = []; $cacheKey = $command; if (isset($cache[$cacheKey])) { $class = $cache[$cacheKey]['class']; $command = $cache[$cacheKey]['command']; } else { if (false === strpos($command, '.')) { // Not FQCN $class = __NAMESPACE__ . '\\' . String::convertToCamelCase($command); } else { // FQCN $class = explode('.', $command); $class = array_map(array('In2pire\\Component\\Utility\\Text', 'convertToCamelCase'), $class); $class = implode('\\', $class); $command = substr($command, strrpos($command, '.') + 1); } $cache[$cacheKey] = [ 'class' => $class, 'command' => $command ]; } if (!class_exists($class)) { throw new \RuntimeException('Unknow command ' . $cacheKey); } return new $class($app); }
php
{ "resource": "" }
q253073
CacheConfigListener.getCache
validation
public function getCache() { if (! $this->cache) { $services = $this->getServices(); $cache = $services->get('Cache'); $this->setCache($cache); } return $this->cache; }
php
{ "resource": "" }
q253074
CacheConfigListener.doRestore
validation
public function doRestore(ModulesEvent $event) { $cache = $this->getCache(); $data = $cache->get('config'); if ($data) { $services = $this->getServices(); $services->set('Config', $data); $event->stopPropagation(true); } }
php
{ "resource": "" }
q253075
CacheConfigListener.doStore
validation
public function doStore(ModulesEvent $event) { $cache = $this->getCache(); $config = $this->getConfig(); $cache->set('config', $config); }
php
{ "resource": "" }
q253076
UserRepository.save
validation
public function save(IUser $user): bool { if (!$user instanceof Entity) { return false; } return entityManager()->save($user); }
php
{ "resource": "" }
q253077
Group.addAction
validation
public function addAction(AbstractAction $action) { $action->setGroup($this); $this->actions[$action->getName()] = $action; return $this; }
php
{ "resource": "" }
q253078
IdentityAsset.getLogo
validation
public function getLogo($size = null) { if (!$this->logoPath || !file_exists($this->logoPath)) { return; } $cacheLogo = $this->sizeImageCache($this->logoPath, $size); if ($cacheLogo) { return $this->getCacheAssetUrl($cacheLogo); } return false; }
php
{ "resource": "" }
q253079
Cache.set
validation
public function set($key, $value) { if ($this->cacheEnabled) { $this->cacheEngine->set($key, $value); } }
php
{ "resource": "" }
q253080
ImageTool.convert2Jpeg
validation
public static function convert2Jpeg($inputImg, $savePath = null, $quality = null, array $exifData = null) { $retval = false; $img = self::imgCreate($inputImg); $imgSize = self::size($img); $jpegImg = imagecreatetruecolor($imgSize[0], $imgSize[1]); imagecopy($jpegImg, $img, 0, 0, 0, 0, $imgSize[0], $imgSize[1]); if (null === $quality) $quality = self::IMG_QUALITY; if (null !== $exifData && array_key_exists('Orientation', $exifData)) { $ort = $exifData['Orientation']; switch ($ort) { default: case 1: // nothing break; case 2: // horizontal flip $jpegImg = self::flipImage($jpegImg, 1); break; case 3: // 180 rotate left $jpegImg = self::rotateImage($jpegImg, 180); break; case 4: // vertical flip $jpegImg = self::flipImage($jpegImg, 2); break; case 5: // vertical flip + 90 rotate right $jpegImg = self::flipImage($jpegImg, 2); $jpegImg = self::rotateImage($jpegImg, 90); break; case 6: // 90 rotate right $jpegImg = self::rotateImage($jpegImg, 90); break; case 7: // horizontal flip + 90 rotate right $jpegImg = self::flipImage($jpegImg, 1); $jpegImg = self::rotateImage($jpegImg, 90); break; case 8: // 90 rotate left $jpegImg = self::rotateImage($jpegImg, 270); break; } } if (null === $savePath) $retval = $jpegImg; else $retval = imagejpeg($jpegImg, $savePath, $quality); return $retval; }
php
{ "resource": "" }
q253081
ImageTool.size
validation
public static function size($inputImg) { if (is_string($inputImg)) $img = self::imgCreate($inputImg); else $img = $inputImg; $imgW = imagesx($img); $imgH = imagesy($img); if (is_string($inputImg)) imagedestroy($img); return array($imgW, $imgH); }
php
{ "resource": "" }
q253082
Grid.extractInput
validation
private function extractInput() { $params = $this->request->getParams(); $period = $params[self::REQ_PERIOD] ?? ''; if (empty($period)) { $period = $this->hlpPeriod->getPeriodCurrent(null, 0, HPeriod::TYPE_MONTH); } else { $period = $this->hlpPeriod->normalizePeriod($period, HPeriod::TYPE_MONTH); } $dsBegin = $this->hlpPeriod->getPeriodFirstDate($period); $treeType = $params[self::REQ_TREE_TYPE] ?? ''; if ($treeType != OptionTreeType::VAL_PLAIN) { $treeType = OptionTreeType::VAL_COMPRESS; // 'compressed' by default } return [$dsBegin, $treeType]; }
php
{ "resource": "" }
q253083
Grid.getBind
validation
private function getBind() { [$dsBegin, $treeType] = $this->extractInput(); $calcId = $this->getCalcId($dsBegin, $treeType); $bind = [ QGrid::BND_CALC_ID => $calcId ]; return $bind; }
php
{ "resource": "" }
q253084
Grid.getCalcId
validation
private function getCalcId($dsBegin, $treeType) { $codeRegular = $codeForecast = ''; if ($treeType == OptionTreeType::VAL_PLAIN) { $codeRegular = Cfg::CODE_TYPE_CALC_PV_WRITE_OFF; $codeForecast = Cfg::CODE_TYPE_CALC_FORECAST_PLAIN; } elseif ($treeType == OptionTreeType::VAL_COMPRESS) { $codeRegular = Cfg::CODE_TYPE_CALC_COMPRESS_PHASE1; $codeForecast = Cfg::CODE_TYPE_CALC_FORECAST_PHASE1; } $query = $this->qGetId->build(); $conn = $query->getConnection(); $bind = [ QGetId::BND_DS_BEGIN => $dsBegin, QGetId::BND_TYPE_CODE_REGULAR => $codeRegular, QGetId::BND_TYPE_CODE_FORECAST => $codeForecast ]; $result = $conn->fetchOne($query, $bind); return $result; }
php
{ "resource": "" }
q253085
LoadPeople.addAPerson
validation
private function addAPerson(array $person, ObjectManager $manager) { $p = new Person(); foreach ($person as $key => $value) { switch ($key) { case 'CountryOfBirth': case 'Nationality': $value = $this->getCountry($value); break; case 'Birthdate': $value = new \DateTime($value); break; case 'center': case 'maritalStatus': $value = $this->getReference($value); break; } //try to add the data using the setSomething function, // if not possible, fallback to addSomething function if (method_exists($p, 'set'.$key)) { call_user_func(array($p, 'set'.$key), $value); } elseif (method_exists($p, 'add'.$key)) { // if we have a "addSomething", we may have multiple items to add // so, we set the value in an array if it is not an array, and // will call the function addSomething multiple times if (!is_array($value)) { $value = array($value); } foreach($value as $v) { if ($v !== NULL) { call_user_func(array($p, 'add'.$key), $v); } } } } $manager->persist($p); echo "add person'".$p->__toString()."'\n"; }
php
{ "resource": "" }
q253086
LoadPeople.getRandomAddress
validation
private function getRandomAddress() { return (new Address()) ->setStreetAddress1($this->faker->streetAddress) ->setStreetAddress2( rand(0,9) > 5 ? $this->faker->streetAddress : '' ) ->setPostcode($this->getReference( LoadPostalCodes::$refs[array_rand(LoadPostalCodes::$refs)] )) ->setValidFrom($this->faker->dateTimeBetween('-5 years')) ; }
php
{ "resource": "" }
q253087
Benri_Db_Table_Row.reset
validation
final public function reset($column) { if ($this->isDirty($column)) { $this->_data[$column] = $this->_cleanData[$column]; unset($this->_modifiedFields[$column]); } }
php
{ "resource": "" }
q253088
Benri_Db_Table_Row.save
validation
final public function save() { $this->checkReadOnly(); /* * Allows pre-save logic to be applied to any row. * * Zend_Db_Table_Row only uses to do it on _insert OR _update, * here we can use the very same rules to be applied in both methods. */ $this->_save(); if (count($this->_errors)) { throw new Zend_Db_Table_Row_Exception('This row contain errors.'); } foreach ($this->_data as $column => &$value) { if ($value instanceof DateTime) { // Should replace with Benri_Util_DateTime. if (!($value instanceof Benri_Util_DateTime)) { $value = new Benri_Util_DateTime($value->format('U')); } $value->setFormat('Y-m-d H:i:s'); } } if ($this->isNewRecord()) { if ($this->offsetExists('created_at')) { $this->created_at = new Benri_Util_DateTime(); $this->created_at->setFormat('Y-m-d H:i:s'); } } if ($this->offsetExists('updated_at')) { $this->updated_at = new Benri_Util_DateTime(); $this->updated_at->setFormat('Y-m-d H:i:s'); } /// Saves the properties to the database parent::save(); /// Run post-SAVE logic $this->_postSave(); /// chain return $this; }
php
{ "resource": "" }
q253089
Benri_Db_Table_Row.checkReadOnly
validation
private function checkReadOnly() { if (true === $this->_readOnly) { $this->_pushError( '', self::ERR_READ_ONLY, 'This row has been marked read-only' ); return false; } return true; }
php
{ "resource": "" }
q253090
SettingsProvider.getSettingsFromRealSource
validation
protected function getSettingsFromRealSource($namespace) { $arraySettings = $this->getSettingsArray($namespace); $namespaceOptions = $this->options->getNamespaceOptions($namespace); $entity = clone($namespaceOptions->getEntityPrototype()); if (!empty($arraySettings)) { $hydrator = $this->namespaceHydratorProvider->getHydrator($namespace); $entity = $hydrator->hydrate($arraySettings, $entity); } return $entity; }
php
{ "resource": "" }
q253091
XmlRpcBuilder.createFault
validation
public static function createFault($code, $message) { $response = new \SimpleXMLElement("<methodResponse></methodResponse>"); $struct = $response->addChild("fault")->addChild("value")->addChild("struct"); $member = $struct->addChild("member"); $member->addChild("name", "faultCode"); $member->addChild("value")->addChild("int", $code); $member = $struct->addChild("member"); $member->addChild("name", "faultString"); $member->addChild("value", $message); return $response->asXML(); }
php
{ "resource": "" }
q253092
Home.show
validation
public function show() { $response = new \Venus\lib\Response(); $response->setContent('<html><body><h1>Hello world!</h1></body></html>'); $response->setStatusCode(\Venus\lib\Response::HTTP_OK); $response->headers->set('Content-Type', 'text/html'); $response->send(); }
php
{ "resource": "" }
q253093
AbstractWebCtrl.setLayout
validation
protected function setLayout(string $layoutName): void { if (is_null($this->view)) { throw new Exception("It's unable to set Layout without View."); } $this->layout = ViewFactory::createLayout($layoutName, $this->view); }
php
{ "resource": "" }
q253094
AbstractWebCtrl.redirect
validation
protected function redirect(string $uri, bool $isPermanent = false): void { $nCode = $isPermanent ? 301 : 302; Headers::getInstance() ->addByHttpCode($nCode) ->add('Location: '.$uri) ->run(); exit; }
php
{ "resource": "" }
q253095
Request.getHeader
validation
public function getHeader(string $name): ?string { $name = strtolower($name); foreach ($this->getAllHeaders() as $key => $value) { if (strtolower($key) === $name) { return $value; } } return null; }
php
{ "resource": "" }
q253096
Request.getUrlPath
validation
public function getUrlPath(): ?string { $uri = $this->getServerParam('REQUEST_URI', \FILTER_SANITIZE_URL); if (!is_null($uri)) { return parse_url($uri, \PHP_URL_PATH); } return null; }
php
{ "resource": "" }
q253097
Request.isAjax
validation
public function isAjax(): bool { $param = $this->getServerParam('HTTP_X_REQUESTED_WITH', \FILTER_SANITIZE_STRING); return !is_null($param) && strtolower($param) === 'xmlhttprequest'; }
php
{ "resource": "" }
q253098
ControllerCookiesTrait.removeCookie
validation
private function removeCookie( $cookie, \Psr\Http\Message\ResponseInterface $response ) { return \Dflydev\FigCookies\FigResponseCookies::remove( $response, $cookie ); }
php
{ "resource": "" }
q253099
DataItem.getHandler
validation
public function getHandler() { if ($this->pairedDataItem) { if (!isset($this->primaryObject)) { return $this->pairedDataItem; } elseif (isset($this->companionObject)) { return static::getHandlingObject($this, $this->pairedDataItem); } } return $this; }
php
{ "resource": "" }