_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
33
8k
language
stringclasses
1 value
meta_information
dict
q6600
Model.validates
train
public function validates($options = []) { $this->sync(); $exists = $this->exists(); $defaults = [ 'events' => $exists ? 'update' : 'create', 'required' => $exists ? false : true, 'entity' => $this,
php
{ "resource": "" }
q6601
Model._validates
train
protected function _validates($options) { $defaults = ['embed' => true]; $options += $defaults; if ($options['embed'] === true) { $options['embed'] = $this->hierarchy(); } $schema = $this->schema();
php
{ "resource": "" }
q6602
Model.invalidate
train
public function invalidate($field, $errors = []) { $schema = $this->schema(); if (func_num_args() === 1) { foreach ($field as $key => $value) { if ($schema->hasRelation($key) && $this->has($key)) { $this->{$key}->invalidate($value); } else { $this->invalidate($key, $value);
php
{ "resource": "" }
q6603
Model.error
train
public function error($field, $all = false) { if (!empty($this->_errors[$field])) { return $all ? $this->_errors[$field] :
php
{ "resource": "" }
q6604
Model.errored
train
public function errored($field = null) { if (!func_num_args()) { return !!$this->_errors;
php
{ "resource": "" }
q6605
OciPdoStatementAdapter.bindColumn
train
public function bindColumn($column, &$param, $type = PDO::PARAM_STR, $maxlen = -1, $driverdata = null) { $type = $this->removeBitFlag($$type, PDO::PARAM_INPUT_OUTPUT); $ociParamType = $this->pdo2OciParamConst($type); // LOBs if ($lob_desc = $this->oci_lob_desc($ociParamType)) { $this->_lobs[$this->_lobsCount]['type'] = $ociParamType; $this->_lobs[$this->_lobsCount]['lob'] = @oci_new_descriptor($this->ociPdoAdapter->getOciConnection(), $lob_desc); $res = $this->_lobs[$this->_lobsCount]['lob']; $this->checkError($res); $res =
php
{ "resource": "" }
q6606
OciPdoStatementAdapter.fetchObject
train
public function fetchObject($class_name = 'stdClass', array $ctor_args = array()) { $obj = $this->fetch(PDO::FETCH_OBJ); if($class_name == 'stdClass') { $res = $obj; } else
php
{ "resource": "" }
q6607
OciPdoStatementAdapter.getError
train
protected function getError() { if ($this->_error === false) { if (is_resource($this->stmt)) { $this->_error = @oci_error($this->stmt); } else {
php
{ "resource": "" }
q6608
OciPdoStatementAdapter.oci_lob_desc
train
public function oci_lob_desc($type) { switch ($type) { case OCI_B_BFILE: $result = OCI_D_FILE; break; case OCI_B_CFILEE: $result = OCI_D_FILE; break; case OCI_B_CLOB: case SQLT_CLOB: case OCI_B_BLOB:
php
{ "resource": "" }
q6609
OciPdoStatementAdapter.lobToStream
train
protected function lobToStream(&$lob) { if (is_null($lob)) { return null; } if (is_object($lob) && get_class($lob) == 'OCI-Lob') { return fopen('ocipdolob://', 'r',
php
{ "resource": "" }
q6610
Annotation.parse
train
public static function parse($doc) { $block = new DocBlock(); $lines = explode("\n", $doc); // remove first line unset($lines[0]); foreach ($lines as $line) { $line = trim($line); $line = substr($line, 2); if (isset($line[0]) && $line[0] == '@') { $line = substr($line, 1); $sp = strpos($line, ' '); $bp = strpos($line, '('); if ($sp !== false || $bp !== false) { if ($sp !== false && $bp === false) { $pos = $sp; } elseif ($sp === false && $bp !== false) { $pos = $bp; } else { $pos = $sp < $bp ? $sp : $bp; } $key = substr($line, 0, $pos); $value = substr($line, $pos); } else { $key = $line; $value = null; } $key = trim($key);
php
{ "resource": "" }
q6611
Annotation.parseAttributes
train
public static function parseAttributes($values) { $result = array(); $values = trim($values, " \t\n\r\0\x0B()"); $parts = explode(',', $values); foreach ($parts as $part) {
php
{ "resource": "" }
q6612
SurvStatsCore.loadMapRow
train
protected function loadMapRow() { $ret = [ "cnt" => 0, "rec" => [], "dat" => [] ]; if (sizeof($this->datMap) > 0) {
php
{ "resource": "" }
q6613
Through._merge
train
protected function _merge($data, $exists) { if (!$data) { $this->_parent->get($this->_through)->clear(); return; } $pivot = $this->_parent->{$this->_through}; $relThrough = $this->_parent->schema()->relation($this->_through); $through = $relThrough->to(); $schema = $through::definition(); $rel = $schema->relation($this->_using); $fromKey = $rel->keys('from'); $toKey = $rel->keys('to'); $i = 0; while ($i < $pivot->count()) { $found = false; $entity = $pivot->get($i); $id1 = $entity->get($fromKey); if ($id1 === null) { $pivot->splice($i, 1); continue; } foreach ($data as $key => $item) { $isDocument = $item instanceof Document; $id2 = $isDocument ? $item->get($toKey) : (isset($item[$toKey]) ?$item[$toKey] : null);
php
{ "resource": "" }
q6614
Through.set
train
public function set($offset = null, $data = []) { $name = $this->_through;
php
{ "resource": "" }
q6615
Through.push
train
public function push($data = []) { $name = $this->_through;
php
{ "resource": "" }
q6616
Through._item
train
protected function _item($data, $options = []) { $name = $this->_through; $parent = $this->_parent; $relThrough = $parent->schema()->relation($name); $through = $relThrough->to(); $id = $this->_parent->id(); $item = $through::create($id !== null ?
php
{ "resource": "" }
q6617
Through.prev
train
public function prev() { $entity = $this->_parent->{$this->_through}->prev(); if ($entity) {
php
{ "resource": "" }
q6618
Through.map
train
public function map($closure) { $data = []; foreach ($this as $val) { $data[] = $closure($val);
php
{ "resource": "" }
q6619
Through.reduce
train
public function reduce($closure, $initial = false) { $result = $initial; foreach ($this as $val) {
php
{ "resource": "" }
q6620
Through.validates
train
public function validates($options = []) { $success = true; foreach ($this as $entity) {
php
{ "resource": "" }
q6621
Console_Color2.color
train
public function color($color = null, $style = null, $background = null) // {{{ { $colors = $this->getColorCodes(); if (is_array($color)) { $style = isset($color['style']) ? $color['style'] : null; $background = isset($color['background']) ? $color['background'] : null; $color = isset($color['color']) ? $color['color'] : null; } if ($color == 'reset') { return "\033[0m"; } $code = array(); if (isset($style)) {
php
{ "resource": "" }
q6622
Printer.formatExceptionMsg
train
protected function formatExceptionMsg($exceptionMessage) { $exceptionMessage = str_replace("+++ Actual\n", '', $exceptionMessage); $exceptionMessage = str_replace("--- Expected\n", '', $exceptionMessage); $exceptionMessage = str_replace("@@ @@\n", '', $exceptionMessage); $exceptionMessage = preg_replace("/(Failed.*)$/m", " \033[01;31m$1\033[0m",
php
{ "resource": "" }
q6623
CheckRoles.attachRoles
train
public function attachRoles($roles) { if ($roles instanceof Role) { $roles = [$roles->getKey()]; }
php
{ "resource": "" }
q6624
CheckRoles.detachRoles
train
public function detachRoles($roles) { if ($roles instanceof Role) { $roles = [$roles->getKey()]; }
php
{ "resource": "" }
q6625
Hashids.make
train
public static function make(?string $salt, ?int $length, ?string $alphabet) { $salt = is_null($salt) ? config('hashids.salt') : config('hashids.salt') . $salt; $length = $length ?? config('hashids.length');
php
{ "resource": "" }
q6626
Installer.configureAsRoot
train
public static function configureAsRoot(): void { $filesystem = new Filesystem(); $vendor_dir = Path::VENDOR_DIR . '/hostnet/phpcs-tool/src'; if ($filesystem->exists($vendor_dir)) { return; } self::configure(); $filesystem->mkdir($vendor_dir . '/Hostnet'); $filesystem->symlink(__DIR__ . '/../../Sniffs', $vendor_dir . '/Hostnet/Sniffs');
php
{ "resource": "" }
q6627
Installer.execute
train
public function execute(): void { self::configure(); if (false === $this->io->isVerbose()) {
php
{ "resource": "" }
q6628
Installer.configure
train
public static function configure(): void { $filesystem = new Filesystem(); $config = [ 'colors' => '1', 'installed_paths' => implode(',', [ Path::VENDOR_DIR . '/hostnet/phpcs-tool/src/', Path::VENDOR_DIR . '/slevomat/coding-standard/SlevomatCodingStandard', ]), ]; if (!$filesystem->exists(['phpcs.xml', 'phpcs.xml.dist'])) { $config['default_standard'] = 'Hostnet'; } $filesystem->dumpFile(
php
{ "resource": "" }
q6629
VerifyCode.configure
train
public function configure($_array = NULL) { if ( $_array != NULL ) { if ( isset( $_array['x'] ) ) $this->_config['x'] = $_array['x']; if ( isset( $_array['y'] ) ) $this->_config['y'] = $_array['y']; if ( isset( $_array['w'] ) ) $this->_config['w'] = $_array['w']; if
php
{ "resource": "" }
q6630
MergeCommand.execute
train
protected function execute(InputInterface $input, OutputInterface $output) { // Welcome $output->writeln( '<info>Welcome to the Cypress GitElephantBundle merge command.</info>' ); if ($input->getOption('no-push')) { $output->writeln( '<comment>--no-push option enabled (this option disable push destination branch to remotes)</comment>' ); } /** @var GitElephantRepositoryCollection $rc */ $rc = $this->getContainer()->get('git_repositories'); if ($rc->count() == 0) { throw new \Exception('Must have at least one Git repository. See https://github.com/matteosister/GitElephantBundle#how-to-use'); } /** @var Repository $repository */ foreach ($rc as $key => $repository) { if ($key == 0 || $key > 0 && $input->getOption('all')) { /** @var Branch $source */ $source = $repository->getBranch($input->getArgument('source')); if (is_null($source)) { throw new \Exception('Source branch ' . $input->getArgument('source') . ' doesn\'t exists'); } /** @var Branch $destination */ $destination = $repository->getBranch($input->getArgument('destination')); if (is_null($destination)) {
php
{ "resource": "" }
q6631
User.getSearchableRules
train
public function getSearchableRules(): array { return [ 'roles:[]' => function (Builder $query, array $roles) { return $query->whereHas('roles', function (Builder $query) use ($roles) {
php
{ "resource": "" }
q6632
User.scopeHasRoles
train
public function scopeHasRoles(Builder $query, array $roles = []): Builder { $query->with('roles')->whereNotNull('users.id');
php
{ "resource": "" }
q6633
User.scopeHasRolesId
train
public function scopeHasRolesId(Builder $query, array $rolesId = []): Builder { $query->with('roles')->whereNotNull('users.id');
php
{ "resource": "" }
q6634
User.setPasswordAttribute
train
public function setPasswordAttribute(string $value): void { if (Hash::needsRehash($value)) { $value = Hash::make($value);
php
{ "resource": "" }
q6635
OwnedBy.scopeOwnedBy
train
public function scopeOwnedBy(Builder $query, Model $related, ?string $key = null): Builder { if (\is_null($key)) {
php
{ "resource": "" }
q6636
Handler.getEncoding
train
private function getEncoding(string &$string): string { # Check for the UTF-8 byte order mark if (substr($string, 0, 3) === self::UTF8) { $string = substr($string, 3); return self::UTF8; } # Check for the UTF-16 big endian byte order mark if (substr($string, 0, 2) === self::UTF16BE) { $string = substr($string, 2); return self::UTF16BE; } # Check for the UTF-16
php
{ "resource": "" }
q6637
Handler.convert
train
public function convert(string $string): string { if ($this->encoding === null) { $this->encoding = $this->getEncoding($string); } if ($this->encoding === self::UTF16BE) { $string = mb_convert_encoding($string, "UTF-8", "UTF-16BE"); }
php
{ "resource": "" }
q6638
Map.set
train
public function set($value, $data) { $id = is_object($value) ? spl_object_hash($value) : $value;
php
{ "resource": "" }
q6639
Map.get
train
public function get($value) { $id = is_object($value) ? spl_object_hash($value) : $value; if (isset($this->_data[$id])) { return $this->_data[$id];
php
{ "resource": "" }
q6640
Map.delete
train
public function delete($value) { $id = is_object($value) ? spl_object_hash($value) : $value;
php
{ "resource": "" }
q6641
Map.has
train
public function has($value) { $id = is_object($value) ? spl_object_hash($value) : $value;
php
{ "resource": "" }
q6642
Bootstrap.setupEnvironment
train
public static function setupEnvironment(Config $config) { if (!defined('PSX')) { // define paths define('PSX_PATH_CACHE', $config->get('psx_path_cache')); define('PSX_PATH_PUBLIC', $config->get('psx_path_public')); define('PSX_PATH_SRC', $config->get('psx_path_src') ?: $config->get('psx_path_library')); /** @deprecated */ define('PSX_PATH_LIBRARY', $config->get('psx_path_library')); // error handling if ($config['psx_debug'] === true) {
php
{ "resource": "" }
q6643
MenuHelper.setFullBaseUrl
train
public function setFullBaseUrl(array $menu = []): array { $menu = array_map( function ($v) { $url = Hash::get($v, 'url'); $children = Hash::get($v, 'children'); if ($url) { $v['url'] = Router::url($url, true); } if
php
{ "resource": "" }
q6644
DynamicEntry.getFields
train
public function getFields() { $coercedFields = []; foreach (array_keys($this->entry->getFields()) as
php
{ "resource": "" }
q6645
AttributeType.getValue
train
public static function getValue($slug, $attributeAvId, $locale = 'en_US')
php
{ "resource": "" }
q6646
AttributeType.getFirstValues
train
public static function getFirstValues(array $slugs, array $attributeAvIds, $locale = 'en_US') { $results = self::getValues($slugs, $attributeAvIds, $locale); $return = array(); foreach ($slugs as $slug) { if (!isset($return[$slug])) { $return[$slug] = null; } foreach ($results[$slug] as $value) {
php
{ "resource": "" }
q6647
AttributeType.getAttributeAv
train
public static function getAttributeAv($slugs = null, $attributeIds = null, $values = null, $locale
php
{ "resource": "" }
q6648
AttributeType.getAttributeAvs
train
public static function getAttributeAvs($slugs = null, $attributeIds = null, $values = null, $locale = 'en_US') { return
php
{ "resource": "" }
q6649
SurvData.printAllTableIdFlds
train
public function printAllTableIdFlds($tbl, $flds = []) { $ret = ''; $arr = $this->getAllTableIdFlds($tbl, $flds); if (sizeof($arr) > 0) { foreach ($arr as $i => $row) { $ret .= ' (( '; if (sizeof($row) > 0) { foreach ($row as $fld => $val) {
php
{ "resource": "" }
q6650
MenuFactory.getMenu
train
public static function getMenu(string $name, array $user, bool $fullBaseUrl = false, $context = null): MenuInterface { $instance = new
php
{ "resource": "" }
q6651
MenuFactory.addToMenu
train
public static function addToMenu(MenuInterface $menu, array $items): void { $normalisedItems = self::normaliseItems($items); foreach ($normalisedItems as $item) {
php
{ "resource": "" }
q6652
MenuFactory.createMenu
train
public static function createMenu(array $menu): MenuInterface { $menuInstance = new Menu();
php
{ "resource": "" }
q6653
MenuFactory.getMenuByName
train
protected function getMenuByName(string $name, $context = null): MenuInterface { // validate menu name $this->validateName($name); // get menu $menuEntity = null; try { $menuEntity = $this->Menus ->find('all') ->where(['name' => $name]) ->firstOrFail(); if (!($menuEntity instanceof EntityInterface)) { throw new RuntimeException(sprintf( 'Expected value of type "Cake\Datasource\EntityInterface", got "%s" instead', gettype($menuEntity) )); } $menuInstance = $menuEntity->get('default') ? $this->getMenuItemsFromEvent($name, [], $context) : $this->getMenuItemsFromTable($menuEntity); } catch (RecordNotFoundException $e) { $menuInstance = static::getMenuItemsFromEvent($name, [], $context); }
php
{ "resource": "" }
q6654
MenuFactory.getMenuItemsFromEvent
train
protected function getMenuItemsFromEvent(string $menuName, array $modules = [], $subject = null): MenuInterface { if (empty($subject)) { $subject = $this; } $event = new Event((string)EventName::GET_MENU_ITEMS(), $subject, [ 'name' => $menuName, 'user' => $this->user,
php
{ "resource": "" }
q6655
MenuFactory.getMenuItemsFromTable
train
protected function getMenuItemsFromTable(EntityInterface $menu): array { $query = $this->MenuItems->find('threaded', [ 'conditions' => ['MenuItems.menu_id' => $menu->id], 'order' => ['MenuItems.lft'] ]); if ($query->isEmpty()) { return []; } $result = []; $count = 0; foreach ($query->all() as $entity) {
php
{ "resource": "" }
q6656
MenuFactory.getMenuItem
train
protected function getMenuItem(EntityInterface $menu, array $item, int $order = 0): array { if (empty($item)) { return []; } $label = $item['label']; $icon = $item['icon']; $type = $item['type']; $children = !empty($item['children']) ? $item['children'] : []; if (!empty($children)) { $count = 0; foreach ($children as $key => $child) { $children[$key] = $this->getMenuItem($menu, $child, ++$count); } } if (static::TYPE_MODULE === $type) { $item = $this->getMenuItemsFromEvent($menu->get('name'),
php
{ "resource": "" }
q6657
MenuFactory.applyDefaults
train
public static function applyDefaults(array $items, array $defaults = null): array { $defaults = empty($defaults) ? Configure::readOrFail('Menu.defaults') : $defaults; // merge item properties with defaults $func = function (&$item, $k) use (&$func, $defaults) { if (!empty($item['children'])) {
php
{ "resource": "" }
q6658
MenuFactory.normaliseItems
train
public static function normaliseItems(array $items): array { // merge item properties with defaults $items = self::applyDefaults($items); // merge duplicated labels recursively $result = []; foreach ($items as $item) { if (!array_key_exists($item['label'], $result)) { $result[$item['label']] = $item; continue; }
php
{ "resource": "" }
q6659
MenuFactory.sortItems
train
protected function sortItems(array $items, string $key = 'order'): array { $cmp = function (&$a, &$b) use (&$cmp, $key) { if (!empty($a['children'])) { usort($a['children'], $cmp); }
php
{ "resource": "" }
q6660
ClassBasedNameTrait.getName
train
public function getName() { //generate snake case name based on class name preg_match('/\\\?(\w+)Filter$/', get_class($this), $matches);
php
{ "resource": "" }
q6661
RabbitMQWorkerTask.consume
train
public function consume($config, callable $callable) { $this->ProcessManager->handleKillSignals(); $this->eventManager()->attach([$this, 'signalHandler'],
php
{ "resource": "" }
q6662
RabbitMQWorkerTask._callback
train
protected function _callback(callable $callable, AMQPEnvelope $envelope, AMQPQueue $queue) { if ($this->stop) { return false; } if ($envelope === false) { return false; } if ($this->stop) { $this->log('-> Putting job back into the queue', 'warning'); $queue->nack($envelope->getDeliveryTag(), AMQP_REQUEUE); return false; } $result = false; try { $this->_working = true; $body = $envelope->getBody(); $compressed = $envelope->getContentEncoding() === 'gzip'; if ($compressed) { $body = gzuncompress($body); } switch ($envelope->getContentType()) { case 'application/json': $result = $callable(json_decode($body, true), $envelope, $queue); break; case 'application/text':
php
{ "resource": "" }
q6663
RabbitMQWorkerTask.signalHandler
train
public function signalHandler() { if (!$this->_working) { $this->log('Not doing any jobs, going to die now...', 'warning');
php
{ "resource": "" }
q6664
Kernel.observes
train
public function observes() { foreach (config('observers') as $observer => $models) { foreach ($models as $model) {
php
{ "resource": "" }
q6665
UploadService.validatesUploadedFile
train
public function validatesUploadedFile($validate = null) { if (func_num_args() === 0)
php
{ "resource": "" }
q6666
UploadService.prepareUploadData
train
protected function prepareUploadData(UploadedFile $uploadedFile) { return [ 'extension' => $uploadedFile->getClientOriginalExtension(),
php
{ "resource": "" }
q6667
UploadService.getUploadPath
train
public function getUploadPath() { $relativePath = date('Y/m'); $fullPath = upload_path($relativePath);
php
{ "resource": "" }
q6668
UploadService.getNewUploadModel
train
protected function getNewUploadModel($id = null) { $uploadModel = $this->modelName(); $upload = new $uploadModel; if ( ! $upload instanceof Uploadable) {
php
{ "resource": "" }
q6669
TreeSurvFormVarieties.widgetCust
train
public function widgetCust(Request $request, $nID = -3) { $this->survLoopInit($request, ''); $this->loadAllSessData(); //$this->loadTree(); $txt = (($request->has('txt')) ? trim($request->get('txt')) : ''); $nIDtxt = $nID . $txt;
php
{ "resource": "" }
q6670
AttributeAttributeTypeQuery.filterByAttributeId
train
public function filterByAttributeId($attributeId = null, $comparison = null) { if (is_array($attributeId)) { $useMinMax = false; if (isset($attributeId['min'])) { $this->addUsingAlias(AttributeAttributeTypeTableMap::ATTRIBUTE_ID, $attributeId['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } if (isset($attributeId['max'])) { $this->addUsingAlias(AttributeAttributeTypeTableMap::ATTRIBUTE_ID, $attributeId['max'], Criteria::LESS_EQUAL); $useMinMax = true;
php
{ "resource": "" }
q6671
AttributeAttributeTypeQuery.filterByAttributeTypeId
train
public function filterByAttributeTypeId($attributeTypeId = null, $comparison = null) { if (is_array($attributeTypeId)) { $useMinMax = false; if (isset($attributeTypeId['min'])) { $this->addUsingAlias(AttributeAttributeTypeTableMap::ATTRIBUTE_TYPE_ID, $attributeTypeId['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } if (isset($attributeTypeId['max'])) { $this->addUsingAlias(AttributeAttributeTypeTableMap::ATTRIBUTE_TYPE_ID, $attributeTypeId['max'], Criteria::LESS_EQUAL); $useMinMax = true;
php
{ "resource": "" }
q6672
AttributeAttributeTypeQuery.filterByAttribute
train
public function filterByAttribute($attribute, $comparison = null) { if ($attribute instanceof \Thelia\Model\Attribute) { return $this ->addUsingAlias(AttributeAttributeTypeTableMap::ATTRIBUTE_ID, $attribute->getId(), $comparison); } elseif ($attribute instanceof ObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this
php
{ "resource": "" }
q6673
AttributeAttributeTypeQuery.useAttributeQuery
train
public function useAttributeQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) { return $this ->joinAttribute($relationAlias, $joinType)
php
{ "resource": "" }
q6674
AttributeAttributeTypeQuery.joinAttributeType
train
public function joinAttributeType($relationAlias = null, $joinType = Criteria::INNER_JOIN) { $tableMap = $this->getTableMap(); $relationMap = $tableMap->getRelation('AttributeType'); // create a ModelJoin object for this join $join = new ModelJoin(); $join->setJoinType($joinType); $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() :
php
{ "resource": "" }
q6675
AttributeAttributeTypeQuery.filterByAttributeTypeAvMeta
train
public function filterByAttributeTypeAvMeta($attributeTypeAvMeta, $comparison = null) { if ($attributeTypeAvMeta instanceof \AttributeType\Model\AttributeTypeAvMeta) { return $this ->addUsingAlias(AttributeAttributeTypeTableMap::ID, $attributeTypeAvMeta->getAttributeAttributeTypeId(), $comparison); } elseif ($attributeTypeAvMeta instanceof ObjectCollection) { return $this
php
{ "resource": "" }
q6676
AttributeAttributeTypeQuery.useAttributeTypeAvMetaQuery
train
public function useAttributeTypeAvMetaQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) { return $this ->joinAttributeTypeAvMeta($relationAlias, $joinType)
php
{ "resource": "" }
q6677
Image.show
train
public function show() { switch ( $this->extension ) { case 'jpg': case 'jpeg': header("Content-type: image/jpeg"); imagejpeg($this->imgDst); break; case 'gif': header("Content-type: image/gif"); imagegif($this->imgDst); break; case 'png':
php
{ "resource": "" }
q6678
GitElephantRepositoryCollection.get
train
public function get($name) { /** @var Repository $repository */ foreach ($this->repositories as $repository) { if ($repository->getName() ==
php
{ "resource": "" }
q6679
RestFormAction.cleanForm
train
private function cleanForm($requestData, Form $form) { $allowedField = array_keys($requestData); /** @var FormInterface[] $formFields */ $formFields = $form->all();
php
{ "resource": "" }
q6680
DefaultContainer.newLoggerHandlerImpl
train
protected function newLoggerHandlerImpl() { $config = $this->get('config'); $factory = $config->get('psx_logger_factory'); if ($factory instanceof \Closure) { return $factory($config); } else { $level = $config->get('psx_log_level');
php
{ "resource": "" }
q6681
DefaultContainer.newDoctrineCacheImpl
train
protected function newDoctrineCacheImpl($namespace) { $config = $this->get('config'); $factory = $config->get('psx_cache_factory'); if ($factory instanceof \Closure) { return $factory($config, $namespace); } else {
php
{ "resource": "" }
q6682
AddTaggedCompilerPass.getServiceArgument
train
private function getServiceArgument(ContainerBuilder $container, string $id) { if ($this->callMode === self::CALL_MODE_ID) { $container->getDefinition($id)->setPublic(true); return $id; } if ($this->callMode ===
php
{ "resource": "" }
q6683
Script.getRequestData
train
protected function getRequestData() { return [ 'request' => $this->request->toArray(), 'response' => [ 'content' => null, 'content_type' => null,
php
{ "resource": "" }
q6684
ConfigProvider.getFilterConfig
train
public function getFilterConfig(): array { return [ 'aliases' => [ 'singlespaces' => Filter\SingleSpaces::class, 'singleSpaces' => Filter\SingleSpaces::class, 'SingleSpaces' => Filter\SingleSpaces::class, 'transliteration' => Filter\Transliteration::class, 'Transliteration' => Filter\Transliteration::class, 'filenamesafe' => Filter\FilenameSafe::class, 'filenameSafe' => Filter\FilenameSafe::class, 'FilenameSafe' => Filter\FilenameSafe::class,
php
{ "resource": "" }
q6685
TypeFactory.create
train
public static function create(string $type): \Menu\Type\TypeInterface { if (empty($type)) { throw new InvalidArgumentException('Type must be a non-empty string.'); } $className = __NAMESPACE__ . '\\Types\\' . Inflector::camelize($type); if (!class_exists($className)) { throw new RuntimeException('Class [' . $className . '] does not exist.'); }
php
{ "resource": "" }
q6686
TypeFactory.getList
train
public static function getList(): array { $result = []; $path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Types'; $dir = new Folder($path); $files = $dir->find('.*\.php');
php
{ "resource": "" }
q6687
ResponseWriter.setBody
train
public function setBody(ResponseInterface $response, $data, $writerType = null) { if ($data instanceof HttpResponseInterface) { $statusCode = $data->getStatusCode(); if (!empty($statusCode)) { $response->setStatus($statusCode); } $headers = $data->getHeaders(); if (!empty($headers)) { $response->setHeaders($headers); } $body = $data->getBody(); } else { $body = $data; } if (!GraphTraverser::isEmpty($body)) { if ($writerType instanceof WriterOptions) { $options = $writerType; } elseif ($writerType instanceof RequestInterface) { $options = $this->getWriterOptions($writerType); } elseif (is_string($writerType)) { $options = new WriterOptions();
php
{ "resource": "" }
q6688
ResponseWriter.getWriterOptions
train
protected function getWriterOptions(RequestInterface $request) { $options = new WriterOptions(); $options->setContentType($request->getHeader('Accept')); $options->setFormat($request->getUri()->getParameter('format')); $options->setSupportedWriter($this->supportedWriter); $options->setWriterCallback(function(WriterInterface $writer) use ($request){ if ($writer instanceof Writer\Jsonp) {
php
{ "resource": "" }
q6689
Relationship.counterpart
train
public function counterpart() { if ($this->_counterpart) { return $this->_counterpart; } $to = $this->to(); $from = $this->from(); $relations = $to::definition()->relations(); $result = []; foreach ($relations as $relation) { $rel = $to::definition()->relation($relation); if ($rel->to() === $this->from()) { $result[] = $rel; } } if (count($result) === 1) {
php
{ "resource": "" }
q6690
Relationship._find
train
protected function _find($id, $options = []) { $defaults = [ 'query' => [], 'fetchOptions' => [] ]; $options += $defaults; $fetchOptions = $options['fetchOptions']; unset($options['fetchOptions']); if ($this->link() !== static::LINK_KEY) { throw new ORMException("This relation is not based on a foreign key."); } $to = $this->to(); $schema = $to::definition(); if (!$id) { return $to::create([], ['type' => 'set']);
php
{ "resource": "" }
q6691
Relationship._index
train
protected function _index($collection, $name) { $indexes = []; foreach ($collection as $key => $entity) { if (is_object($entity)) { if ($entity->{$name}) { $indexes[(string) $entity->{$name}] = $key; } } else {
php
{ "resource": "" }
q6692
Relationship._cleanup
train
public function _cleanup(&$collection) { $name = $this->name(); if ($this->isMany()) { foreach ($collection as $index => $entity) { if (is_object($entity)) { $entity->{$name} = []; } else { $collection[$index][$name] = []; } }
php
{ "resource": "" }
q6693
Relationship.validates
train
public function validates($entity, $options = []) { $fieldname = $this->name(); if (!isset($entity->{$fieldname})) {
php
{ "resource": "" }
q6694
Authenticate.redirectTo
train
protected function redirectTo($request) { session()->put('loginRedir', $_SERVER["REQUEST_URI"]); session()->put('loginRedirTime', time());
php
{ "resource": "" }
q6695
CreateModelCommand.promptMigration
train
protected function promptMigration($name) { $this->line(''); if ($this->confirm('Would you like to create the migration for the model? [Yes|no]')) {
php
{ "resource": "" }
q6696
CompositeAssetDecorator.decorate
train
public function decorate(AssetInterface $asset) { foreach ($this->decorators as $decorator) { /** * @var AssetDecoratorInterface $decorator */
php
{ "resource": "" }
q6697
HttpRequest.getParameter
train
public function getParameter( $name, $func_str=null, $setParam=true ) { if ( !$func_str ) return urldecode($this->parameters[$name]) ? urldecode($this->parameters[$name]) : $this->parameters[$name]; $funcs = explode("|", $func_str); $args = urldecode($this->parameters[$name]); foreach ( $funcs as $func
php
{ "resource": "" }
q6698
FileUpload.upload
train
public function upload($_field, $_base64 = false) { if ( !$this->checkUploadDir() ) { $this->errNum = 6; return false; } if ( $_base64 ) { $_data = $_POST[$_field]; return $this->makeBase64Image( $_data ); } $_localFile = $_FILES[$_field]['name']; if ( !$_localFile ) { $this->errNum = 10; return false; } $_tempFile = $_FILES[$_field]['tmp_name'];//原来是这样 //$_tempFile = str_replace('\\\\', '\\', $_FILES[$_field]['tmp_name']);//MAGIC_QUOTES_GPC=OFF时,做了这样处理:$_FILES = daddslashes($_FILES);图片上传后tmp_name值变成 X:\\Temp\\php668E.tmp,结果move_uploaded_file() 函数判断为不合法的文件而返回FALSE。 $_error_no = $_FILES[$_field]['error']; $this->fileInfo['file_type'] = $_FILES[$_field]['type']; $this->fileInfo['local_name'] = $_localFile; $this->fileInfo['file_size'] = $_FILES[$_field]['size']; $this->errNum = $_error_no; if ( $this->errNum == 0 ) { $this->checkFileType($_localFile); if ( $this->errNum == 0 ) { $this->checkFileSize($_tempFile); if ( $this->errNum == 0 ) { if ( is_uploaded_file($_tempFile) ) {
php
{ "resource": "" }
q6699
AttributeTypeAvMeta.setAttributeAv
train
public function setAttributeAv(ChildAttributeAv $v = null) { if ($v === null) { $this->setAttributeAvId(NULL); } else { $this->setAttributeAvId($v->getId()); } $this->aAttributeAv = $v; // Add binding for other direction of this n:n relationship.
php
{ "resource": "" }