_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q12800
CApacheHTTPServerInterface.locateApacheServer
train
public function locateApacheServer() : bool { if ($this->getApacheCtl()) { $this->getApacheInfo(); $this->getApacheInstancesPath(); $this->getPHPModule(); } return $this->apachectl !== false && $this->apache_config_path !== false; }
php
{ "resource": "" }
q12801
CApacheHTTPServerInterface.getApacheCtl
train
public function getApacheCtl() { if ($this->apachectl === false) { $shell = new CNabuShell(); $response = array(); if ($shell->exec('whereis apachectl', null, $response) && count($response) === 1) { $parts = preg_split('/\\s/', preg_replace('/^apachectl: /', '', $response[0])); $this->apachectl = $parts[0]; } } return $this->apachectl; }
php
{ "resource": "" }
q12802
CApacheHTTPServerInterface.getApacheInfo
train
public function getApacheInfo() { if ($this->apachectl !== false) { $shell = new CNabuShell(); $response = array(); if ($shell->exec($this->apachectl, array('-V' => ''), $response)) { $this->parseApacheInfo($response); } } }
php
{ "resource": "" }
q12803
CApacheHTTPServerInterface.parseApacheInfo
train
private function parseApacheInfo(array $data = null) { $this->apache_info = null; if (is_array($data) && count($data) > 0) { foreach ($data as $line) { $this->interpretApacheInfoData($line) || $this->interpretApacheInfoVariable($line); } } }
php
{ "resource": "" }
q12804
CApacheHTTPServerInterface.getApacheInstancesPath
train
public function getApacheInstancesPath() { if ($this->apache_config_path === false && is_array($this->apache_compiles) && array_key_exists('SERVER_CONFIG_FILE', $this->apache_compiles) ) { $config_file = $this->apache_compiles['SERVER_CONFIG_FILE']; if (is_file($config_file)) { $base_path = dirname($config_file); if (is_dir($base_path . DIRECTORY_SEPARATOR . 'other')) { $this->apache_config_path = $base_path . DIRECTORY_SEPARATOR . 'other'; } elseif (is_dir($base_path . DIRECTORY_SEPARATOR . 'conf.d')) { $this->apache_config_path = $base_path . DIRECTORY_SEPARATOR . 'conf.d'; } } elseif (array_key_exists('HTTPD_ROOT', $this->apache_compiles)) { $base_path = preg_replace('/"$/', '', preg_replace('/^"/', '', $this->apache_compiles['HTTPD_ROOT'])); if (is_dir($base_path . DIRECTORY_SEPARATOR . 'conf.d')) { $this->apache_config_path = $base_path . DIRECTORY_SEPARATOR . 'conf.d'; } elseif (is_dir($base_path . DIRECTORY_SEPARATOR . 'other')) { $this->apache_config_path = $base_path . DIRECTORY_SEPARATOR . 'other'; } } } return $this->apache_config_path; }
php
{ "resource": "" }
q12805
CApacheHTTPServerInterface.interpretApacheInfoVariable
train
private function interpretApacheInfoVariable(string $line) { $content = preg_split('/^\\s+-D\\s+/', $line, 2); if (count($content) === 2) { $parts = preg_split('/=/', $content[1], 2); if (count($parts) === 2) { $this->apache_compiles[$parts[0]] = str_replace('"', '', $parts[1]); } elseif (count($parts) === 1) { $this->apache_compiles[$content[1]] = true; } } }
php
{ "resource": "" }
q12806
CApacheHTTPServerInterface.getServerVersion
train
public function getServerVersion() : string { return (is_array($this->apache_info) && array_key_exists('server-version', $this->apache_info)) ? $this->apache_info['server-version'] : 'Unknown' ; }
php
{ "resource": "" }
q12807
CApacheHTTPServerInterface.createStandaloneConfiguration
train
public function createStandaloneConfiguration() : bool { $retval = false; if ($this->apache_config_path) { $file = new CApacheStandaloneFile($this, $this->nb_server, $this->nb_site); $file->create(); $file->exportToFile($this->apache_config_path . DIRECTORY_SEPARATOR . self::APACHE_CONFIG_FILENAME); $retval = true; } return $retval; }
php
{ "resource": "" }
q12808
CApacheHTTPServerInterface.createHostedConfiguration
train
public function createHostedConfiguration() : bool { $retval = false; if ($this->apache_config_path) { $index_list = $this->nb_server->getSitesIndex(); $index_list->iterate( function ($site_key, $nb_site) { $this->createHostedFile($nb_site); return true; } ); $this->createHostedIndex($index_list); $retval = true; } return $retval; }
php
{ "resource": "" }
q12809
CApacheHTTPServerInterface.createClusteredConfiguration
train
public function createClusteredConfiguration() { $retval = false; if ($this->apache_config_path) { $index_list = $this->nb_server->getSitesIndex(); $index_list->iterate( function ($site_key, $nb_site) { $this->createSiteFolders($nb_site); $this->createClusteredFile($nb_site); return true; } ); $this->createClusteredIndex($index_list); $retval = true; } return $retval; }
php
{ "resource": "" }
q12810
CApacheHTTPServerInterface.createHostedIndex
train
private function createHostedIndex(CNabuSiteList $index_list) { $index = new CApacheHostedIndex($this, $index_list); $index->create(); $index->exportToFile($this->apache_config_path . DIRECTORY_SEPARATOR . self::APACHE_CONFIG_FILENAME); }
php
{ "resource": "" }
q12811
CApacheHTTPServerInterface.createClusteredIndex
train
private function createClusteredIndex(CNabuSiteList $index_list) { $index = new CApacheClusteredIndex($this, $index_list); $index->create(); $index->exportToFile($this->apache_config_path . DIRECTORY_SEPARATOR . self::APACHE_CONFIG_FILENAME); }
php
{ "resource": "" }
q12812
CApacheHTTPServerInterface.createHostedFile
train
private function createHostedFile(CNabuSite $nb_site) { $file = new CApacheHostedFile($this, $this->nb_server, $nb_site); $file->create(); $path = $this->nb_server->getVirtualHostsPath() . DIRECTORY_SEPARATOR . $nb_site->getBasePath() . NABU_VHOST_CONFIG_FOLDER . DIRECTORY_SEPARATOR . $this->nb_server->getKey() ; if (!is_dir($path)) { mkdir($path, 0755, true); } if (!is_dir($path)) { throw new ENabuCoreException(ENabuCoreException::ERROR_FOLDER_NOT_FOUND, array($path)); } $filename = $path . DIRECTORY_SEPARATOR . NABU_VHOST_CONFIG_FILENAME; $file->exportToFile($filename); }
php
{ "resource": "" }
q12813
CApacheHTTPServerInterface.createClusteredFile
train
private function createClusteredFile(CNabuSite $nb_site) { $file = new CApacheClusteredFile($this, $this->nb_server, $nb_site); $file->create(); $path = self::NABU_APACHE_ETC_PATH . DIRECTORY_SEPARATOR . $nb_site->getBasePath(); if (!is_dir($path)) { mkdir($path, 0755, true); } if (!is_dir($path)) { throw new ENabuCoreException(ENabuCoreException::ERROR_FOLDER_NOT_FOUND, array($path)); } $filename = $path . DIRECTORY_SEPARATOR . NABU_VHOST_CONFIG_FILENAME; $file->exportToFile($filename); }
php
{ "resource": "" }
q12814
CApacheHTTPServerInterface.validatePath
train
private function validatePath(string $path) : string { if (!is_dir($path) && !mkdir($path, 0755, true)) { throw new ENabuCoreException(ENabuCoreException::ERROR_HOST_PATH_NOT_FOUND, array($path)); } return $path; }
php
{ "resource": "" }
q12815
CApacheHTTPServerInterface.createSiteFolders
train
public function createSiteFolders(CNabuSite $nb_site) : bool { $vhosts_path = $this->validatePath($this->nb_server->getVirtualHostsPath()); $vlib_path = $this->validatePath($this->nb_server->getVirtualLibrariesPath()); $vcache_path = $this->validatePath($this->nb_server->getVirtualCachePath()); $nb_cluster_user = $nb_site->getClusterUser(); if ($nb_cluster_user === null) { throw new ENabuCoreException(ENabuCoreException::ERROR_OBJECT_EXPECTED); } $nb_cluster_user_group = $nb_cluster_user->getGroup(); if ($nb_cluster_user_group === null) { throw new ENabuCoreException(ENabuCoreException::ERROR_OBJECT_EXPECTED); } $owner_name = $nb_cluster_user->getOSNick(); $owner_group = $nb_cluster_user_group->getOSNick(); $vhosts_path = $nb_site->getVirtualHostPath($this->nb_server); if (!is_dir($vhosts_path)) { if (!mkdir($vhosts_path, 0755, true)) { throw new ENabuCoreException(ENabuCoreException::ERROR_HOST_PATH_NOT_FOUND, array($vhosts_path)); } else { chown($vhosts_path, $owner_name); chgrp($vhosts_path, $owner_group); } } $vlib_path = $nb_site->getVirtualLibrariesPath($this->nb_server); if (!is_dir($vlib_path)) { if (!mkdir($vlib_path, 0755, true)) { throw new ENabuCoreException(ENabuCoreException::ERROR_HOST_PATH_NOT_FOUND, array($vlib_path)); } else { chown($vlib_path, APACHE_HTTPD_SYS_USER); chgrp($vlib_path, $owner_group); } } $vcache_path = $nb_site->getVirtualCachePath($this->nb_server); if (!is_dir($vcache_path)) { if (!mkdir($vcache_path, 0755, true)) { throw new ENabuCoreException(ENabuCoreException::ERROR_HOST_PATH_NOT_FOUND, array($vcache_path)); } else { chown($vcache_path, APACHE_HTTPD_SYS_USER); chgrp($vcache_path, $owner_group); } } return true; }
php
{ "resource": "" }
q12816
Checkout_Controller.index
train
public function index() { // If we are using simple checkout, skip if (Checkout::config()->simple_checkout) { return $this->redirect($this->Link('finish')); } // If we have turned off login, or member logged in if (!(Checkout::config()->login_form) || Member::currentUserID()) { return $this->redirect($this->Link('billing')); } $this->customise(array( 'Title' => _t('Checkout.SignIn', "Sign in"), "Login" => true, 'LoginForm' => $this->LoginForm() )); $this->extend("onBeforeIndex"); return $this->renderWith(array( 'Checkout', 'Page' )); }
php
{ "resource": "" }
q12817
Checkout_Controller.billing
train
public function billing() { $form = $this->BillingForm(); // If we are using simple checkout, skip if (Checkout::config()->simple_checkout) { return $this->redirect($this->Link('finish')); } // Check permissions for guest checkout if (!Member::currentUserID() && !Checkout::config()->guest_checkout) { return $this->redirect($this->Link('index')); } // Pre populate form with member info if (Member::currentUserID()) { $form->loadDataFrom(Member::currentUser()); } $this->customise(array( 'Title' => _t('Checkout.BillingDetails', "Billing Details"), 'Form' => $form )); $this->extend("onBeforeBilling"); return $this->renderWith(array( 'Checkout_billing', 'Checkout', 'Page' )); }
php
{ "resource": "" }
q12818
Checkout_Controller.delivery
train
public function delivery() { $cart = ShoppingCart::get(); // If we are using simple checkout, skip if (Checkout::config()->simple_checkout) { return $this->redirect($this->Link('finish')); } // If customer is collecting, skip if ($cart->isCollection()) { return $this->redirect($this->Link('finish')); } // If cart is not deliverable, also skip if (!$cart->isDeliverable()) { return $this->redirect($this->Link('finish')); } // Check permissions for guest checkout if (!Member::currentUserID() && !Checkout::config()->guest_checkout) { return $this->redirect($this->Link('index')); } $this->customise(array( 'Title' => _t('Checkout.DeliveryDetails', "Delivery Details"), 'Form' => $this->DeliveryForm() )); $this->extend("onBeforeDelivery"); return $this->renderWith(array( 'Checkout_delivery', 'Checkout', 'Page' )); }
php
{ "resource": "" }
q12819
Checkout_Controller.finish
train
public function finish() { // Check the users details are set, if not, send them to the cart $billing_data = Session::get("Checkout.BillingDetailsForm.data"); $delivery_data = Session::get("Checkout.DeliveryDetailsForm.data"); if (!Checkout::config()->simple_checkout && !is_array($billing_data) && !is_array($delivery_data)) { return $this->redirect($this->Link('index')); } // Check permissions for guest checkout if (!Member::currentUserID() && !Checkout::config()->guest_checkout) { return $this->redirect($this->Link('index')); } if (Checkout::config()->simple_checkout) { $title = _t('Checkout.SelectPaymentMethod', "Select Payment Method"); } else { $title = _t('Checkout.SeelctPostagePayment', "Select Postage and Payment Method"); } $this->customise(array( 'Title' => $title, 'Form' => $this->PostagePaymentForm() )); $this->extend("onBeforeFinish"); return $this->renderWith(array( 'Checkout_finish', 'Checkout', 'Page' )); }
php
{ "resource": "" }
q12820
Checkout_Controller.LoginForm
train
public function LoginForm() { $form = CheckoutLoginForm::create($this, 'LoginForm'); $form->setAttribute("action", $this->Link("LoginForm")); $form ->Fields() ->add(HiddenField::create("BackURL")->setValue($this->Link())); $form ->Actions() ->dataFieldByName('action_dologin') ->addExtraClass("btn btn-primary"); $this->extend("updateLoginForm", $form); return $form; }
php
{ "resource": "" }
q12821
Checkout_Controller.BillingForm
train
public function BillingForm() { $form = BillingDetailsForm::create($this, 'BillingForm'); $data = Session::get("Checkout.BillingDetailsForm.data"); if (is_array($data)) { $form->loadDataFrom($data); } elseif($member = Member::currentUser()) { // Fill email, phone, etc $form->loadDataFrom($member); // Then fill with Address info if($member->DefaultAddress()) { $form->loadDataFrom($member->DefaultAddress()); } } $this->extend("updateBillingForm", $form); return $form; }
php
{ "resource": "" }
q12822
Checkout_Controller.DeliveryForm
train
public function DeliveryForm() { $form = DeliveryDetailsForm::create($this, 'DeliveryForm'); $data = Session::get("Checkout.DeliveryDetailsForm.data"); if (is_array($data)) { $form->loadDataFrom($data); } $this->extend("updateDeliveryForm", $form); return $form; }
php
{ "resource": "" }
q12823
AbstractMapper.getFullColumnName
train
public static function getFullColumnName($column, $table = null) { // Get target table name if ($table === null) { // Make sure, the getTableName() is defined in calling class if (method_exists(get_called_class(), 'getTableName')) { $table = static::getTableName(); } else { throw new LogicException( sprintf('The method getTableName() is not declared in %s, therefore a full column name cannot be generated', get_called_class()) ); } } return sprintf('%s.%s', $table, $column); }
php
{ "resource": "" }
q12824
AbstractMapper.getWithPrefix
train
protected static function getWithPrefix($table) { $prefix = static::$prefix; if (is_null($prefix) || empty($prefix)) { // If prefix is null, then no need to prepend a redundant _ return $table; } return sprintf('%s_%s', $prefix, $table); }
php
{ "resource": "" }
q12825
AbstractMapper.executeSqlFromFile
train
final protected function executeSqlFromFile($file) { if (is_file($file)) { return $this->executeSqlFromString(file_get_contents($file)); } else { throw new RuntimeException(sprintf('Can not read file at "%s"', $file)); } }
php
{ "resource": "" }
q12826
AbstractMapper.valueExists
train
final protected function valueExists($column, $value) { $this->validateShortcutData(); return (bool) $this->db->select() ->count($column) ->from(static::getTableName()) ->whereEquals($column, $value) ->queryScalar(); }
php
{ "resource": "" }
q12827
AbstractMapper.deleteByPks
train
final public function deleteByPks(array $ids) { foreach ($ids as $id) { if (!$this->deleteByPk($id)) { return false; } } return true; }
php
{ "resource": "" }
q12828
AbstractMapper.findColumnByPk
train
final public function findColumnByPk($id, $column) { $this->validateShortcutData(); return $this->fetchOneColumn($column, $this->getPk(), $id); }
php
{ "resource": "" }
q12829
AbstractMapper.getLastPk
train
final public function getLastPk($table = null) { if ($table === null) { $this->validateShortcutData(); $table = static::getTableName(); } return $this->db->select() ->max($this->getPk()) ->from($table) ->queryScalar(); }
php
{ "resource": "" }
q12830
AbstractMapper.syncWithJunction
train
final public function syncWithJunction($table, $masterValue, array $slaves, $masterColumn = self::PARAM_JUNCTION_MASTER_COLUMN, $slaveColumn = self::PARAM_JUNCTION_SLAVE_COLUMN) { // Remove previous ones $this->removeFromJunction($table, $masterValue, $masterColumn); // And insert new ones $this->insertIntoJunction($table, $masterValue, $slaves, $masterColumn, $slaveColumn); return true; }
php
{ "resource": "" }
q12831
AbstractMapper.removeFromJunction
train
final public function removeFromJunction($table, $masterValue, $masterColumn = self::PARAM_JUNCTION_MASTER_COLUMN) { // Support for multiple removal if (!is_array($masterValue)) { $masterValue = array($masterValue); } return $this->db->delete() ->from($table) ->whereIn($masterColumn, $masterValue) ->execute(); }
php
{ "resource": "" }
q12832
AbstractMapper.insertIntoJunction
train
final public function insertIntoJunction($table, $masterValue, array $slaves, $masterColumn = self::PARAM_JUNCTION_MASTER_COLUMN, $slaveColumn = self::PARAM_JUNCTION_SLAVE_COLUMN) { // Avoid executing empty query if (!empty($slaves)) { return $this->db->insertIntoJunction($table, array($masterColumn, $slaveColumn), $masterValue, $slaves) ->execute(); } else { return false; } }
php
{ "resource": "" }
q12833
AbstractMapper.getMasterIdsFromJunction
train
final public function getMasterIdsFromJunction($table, $value, $masterColumn = self::PARAM_JUNCTION_MASTER_COLUMN, $slaveColumn = self::PARAM_JUNCTION_SLAVE_COLUMN) { return $this->getIdsFromJunction($table, $masterColumn, $slaveColumn, $value); }
php
{ "resource": "" }
q12834
AbstractMapper.getIdsFromJunction
train
private function getIdsFromJunction($table, $column, $key, $value) { return $this->db->select($column) ->from($table) ->whereEquals($key, $value) ->queryAll($column); }
php
{ "resource": "" }
q12835
AbstractMapper.getColumnSumWithAverages
train
final protected function getColumnSumWithAverages(array $columns, array $averages, array $constraints, $precision = 2) { $db = $this->db->select(); foreach ($columns as $column) { $db->sum($column, $column); } foreach ($averages as $average) { $db->avg($average, $average); } $db->from(static::getTableName()); if (!empty($constraints)) { // Iteration counter $iteration = 0; foreach ($constraints as $key => $value) { if ($iteration === 0) { $db->whereEquals($key, $value); } else { $db->andWhereEquals($key, $value); } $iteration++; } } $data = $db->queryAll(); if (isset($data[0])) { return Math::roundCollection($data[0], $precision); } else { // No results return array(); } }
php
{ "resource": "" }
q12836
AbstractMapper.persistRecord
train
private function persistRecord(array $data, array $fillable = array(), $set) { if (!empty($fillable) && !ArrayUtils::keysExist($data, $fillable)) { throw new LogicException('Can not persist the entity due to fillable protection. Make sure all fillable keys exist in the entity'); } $this->validateShortcutData(); if (isset($data[$this->getPk()]) && $data[$this->getPk()]) { $result = $this->db->update(static::getTableName(), $data) ->whereEquals($this->getPk(), $data[$this->getPk()]) ->execute(); return $set === true ? $data : $result; } else { // Do not insert primary key if present if (array_key_exists($this->getPk(), $data)) { unset($data[$this->getPk()]); } // Insert a new row without PK $result = $this->db->insert(static::getTableName(), $data) ->execute(); if ($set === true) { // Append a PK in result-set now $data[$this->getPk()] = $this->getMaxId(); return $data; } else { return $result; } } }
php
{ "resource": "" }
q12837
AbstractMapper.persistMany
train
final public function persistMany(array $collection, array $fillable = array()) { foreach ($collection as $item) { $this->persist($item, $fillable); } return true; }
php
{ "resource": "" }
q12838
AbstractMapper.updateColumns
train
final public function updateColumns(array $data, array $allowedColumns = array()) { foreach ($data as $column => $values) { foreach ($values as $id => $value) { // Protection. Update only defined columns if (!empty($allowedColumns) && !in_array($column, $allowedColumns)) { continue; } $this->updateColumnByPk($id, $column, $value); } } return true; }
php
{ "resource": "" }
q12839
AbstractMapper.updateColumnsByPk
train
final public function updateColumnsByPk($pk, $data) { $this->validateShortcutData(); return $this->db->update(static::getTableName(), $data) ->whereEquals($this->getPk(), $pk) ->execute(); }
php
{ "resource": "" }
q12840
AbstractMapper.isPrimaryKeyValue
train
final public function isPrimaryKeyValue($value) { $column = $this->getPk(); return (bool) $this->db->select($column) ->from(static::getTableName()) ->whereEquals($column, $value) ->query($column); }
php
{ "resource": "" }
q12841
AbstractMapper.fetchOneColumn
train
final public function fetchOneColumn($column, $key, $value) { $this->validateShortcutData(); return $this->db->select($column) ->from(static::getTableName()) ->whereEquals($key, $value) ->query($column); }
php
{ "resource": "" }
q12842
AbstractMapper.fetchAllByColumn
train
final public function fetchAllByColumn($column, $value, $select = '*') { $this->validateShortcutData(); return $this->db->select($select) ->from(static::getTableName()) ->whereEquals($column, $value) ->queryAll(); }
php
{ "resource": "" }
q12843
AbstractMapper.fetchByColumn
train
final public function fetchByColumn($column, $value, $select = '*') { $this->validateShortcutData(); return $this->db->select($select) ->from(static::getTableName()) ->whereEquals($column, $value) ->query(); }
php
{ "resource": "" }
q12844
AbstractMapper.deleteByColumn
train
final public function deleteByColumn($column, $value) { $this->validateShortcutData(); return $this->db->delete() ->from(static::getTableName()) ->whereEquals($column, $value) ->execute(); }
php
{ "resource": "" }
q12845
AbstractMapper.countByColumn
train
final public function countByColumn($column, $value, $field = null) { $this->validateShortcutData(); $alias = 'count'; if ($field === null) { $field = $this->getPk(); } return (int) $this->db->select() ->count($field, $alias) ->from(static::getTableName()) ->whereEquals($column, $value) ->query($alias); }
php
{ "resource": "" }
q12846
AbstractMapper.incrementColumnByPk
train
final public function incrementColumnByPk($pk, $column, $step = 1, $table = null) { return $this->db->increment($this->getTable($table), $column, $step) ->whereEquals($this->getPk(), $pk) ->execute(); }
php
{ "resource": "" }
q12847
AbstractMapper.decrementColumnByPk
train
final public function decrementColumnByPk($pk, $column, $step = 1, $table = null) { return $this->db->decrement($this->getTable($table), $column, $step) ->whereEquals($this->getPk(), $pk) ->execute(); }
php
{ "resource": "" }
q12848
AbstractMapper.dropTables
train
final public function dropTables(array $tables, $fkChecks = false) { // Whether FK checks are enabled if ($fkChecks == false) { $this->db->raw('SET FOREIGN_KEY_CHECKS=0') ->execute(); } foreach ($tables as $table) { if (!$this->dropTable($table)) { return false; } } // Whether FK checks are enabled if ($fkChecks == false) { $this->db->raw('SET FOREIGN_KEY_CHECKS=1') ->execute(); } return true; }
php
{ "resource": "" }
q12849
AbstractMapper.dropColumn
train
public function dropColumn($column, $table = null) { return $this->db->alterTable($this->getTable($table)) ->dropColumn($column) ->execute(); }
php
{ "resource": "" }
q12850
AbstractMapper.renameColumn
train
public function renameColumn($old, $new, $table = null) { return $this->db->alterTable($this->getTable($table)) ->renameColumn($old, $new) ->execute(); }
php
{ "resource": "" }
q12851
AbstractMapper.createIndex
train
public function createIndex($name, $target, $unique = false, $table = null) { return $this->db->createIndex($table, $name, $target, $unique) ->execute(); }
php
{ "resource": "" }
q12852
AbstractMapper.dropIndex
train
public function dropIndex($name, $table = null) { return $this->db->dropIndex($table, $name) ->execute(); }
php
{ "resource": "" }
q12853
AbstractMapper.addPrimaryKey
train
public function addPrimaryKey($name, $target, $table = null) { return $this->db->alterTable($this->getTable($table)) ->addConstraint($name) ->primaryKey($target) ->execute(); }
php
{ "resource": "" }
q12854
AbstractMapper.dropPrimaryKey
train
public function dropPrimaryKey($name, $table = null) { return $this->db->alterTable($this->getTable($table)) ->dropConstraint($name) ->execute(); }
php
{ "resource": "" }
q12855
AbstractMapper.getMaxId
train
public function getMaxId() { $column = $this->getPk(); return $this->db->select($column) ->from(static::getTableName()) ->orderBy($column) ->desc() ->limit(1) ->query($column); }
php
{ "resource": "" }
q12856
ProjectType.installRoot
train
public static function installRoot() { $install_root = ProjectX::getProjectConfig() ->getRoot(); // Ensure a forward slash has been added to the install root. $install_root = substr($install_root, 0, 1) != '/' ? "/{$install_root}" : $install_root; if (isset($install_root) && !empty($install_root)) { return $install_root; } return static::INSTALL_ROOT; }
php
{ "resource": "" }
q12857
ProjectType.getInstallRoot
train
public function getInstallRoot($strip_slash = false) { $install_root = static::installRoot(); return $strip_slash === false ? $install_root : substr($install_root, 1); }
php
{ "resource": "" }
q12858
ProjectType.onDeployBuild
train
public function onDeployBuild($build_root) { $install_root = $build_root . static::installRoot(); if (!file_exists($install_root)) { $this->_mkdir($install_root); } }
php
{ "resource": "" }
q12859
ProjectType.setupProjectFilesystem
train
public function setupProjectFilesystem() { $this->taskFilesystemStack() ->chmod(ProjectX::projectRoot(), 0775) ->mkdir($this->getInstallPath(), 0775) ->run(); return $this; }
php
{ "resource": "" }
q12860
ProjectType.getProjectOptionByKey
train
public function getProjectOptionByKey($key) { $options = $this->getProjectOptions(); if (!isset($options[$key])) { return false; } return $options[$key]; }
php
{ "resource": "" }
q12861
ProjectType.createSymbolicLinksOnProject
train
public function createSymbolicLinksOnProject(array $options) { $project_root = ProjectX::projectRoot(); $excludes = isset($options['excludes']) ? $options['excludes'] : []; $includes = isset($options['includes']) ? $options['includes'] : []; $target_dir = isset($options['target_dir']) ? $options['target_dir'] : null; $source_dir = isset($options['source_dir']) ? $options['source_dir'] : $project_root; $symlink_command = new SymlinkCommand(); /** @var SplFileInfo $file_info */ foreach (new \FilesystemIterator($project_root, \FilesystemIterator::SKIP_DOTS) as $file_info) { $filename = $file_info->getFilename(); if (strpos($filename, '.') === 0 || in_array($filename, $excludes)) { continue; } if (!empty($includes) && !in_array($filename, $includes)) { continue; } $symlink_command->link("{$source_dir}/{$filename}", "{$target_dir}/{$filename}"); } return $symlink_command; }
php
{ "resource": "" }
q12862
ProjectType.canBuild
train
protected function canBuild() { $rebuild = false; if ($this->isBuilt()) { $rebuild = $this->askConfirmQuestion( 'Project has already been built, do you want to rebuild?', false ); if (!$rebuild) { return static::BUILD_ABORT; } } return !$rebuild ? static::BUILD_FRESH : static::BUILD_DIRTY; }
php
{ "resource": "" }
q12863
ProjectType.getProjectOptions
train
protected function getProjectOptions() { $config = ProjectX::getProjectConfig(); $type = $config->getType(); $options = $config->getOptions(); return isset($options[$type]) ? $options[$type] : []; }
php
{ "resource": "" }
q12864
PaginationMaker.render
train
public function render() { // Run only in case paginator has at least one page if ($this->paginator->hasPages()) { $ulClass = $this->getOption('ulClass', 'pagination'); return $this->renderList($ulClass, $this->createPaginationItems()); } }
php
{ "resource": "" }
q12865
PaginationMaker.createPaginationItems
train
private function createPaginationItems() { // Grab overrides if present $linkClass = $this->getOption('linkClass', 'page-link'); $itemClass = $this->getOption('itemClass', 'page-item'); $itemActiveClass = $this->getOption('itemActiveClass', 'page-item active'); $previousCaption = ' « ' . $this->getOption('previousCaption', ''); $nextCaption = $this->getOption('nextCaption', '') . ' » '; // To be returned $items = array(); // First - check if first previous page available if ($this->paginator->hasPreviousPage()) { $items[] = $this->createListItem($itemClass, $this->renderLink($previousCaption, $this->paginator->getPreviousPageUrl(), $linkClass)); } foreach ($this->paginator->getPageNumbers() as $page) { if (is_numeric($page)) { $currentClass = $this->paginator->isCurrentPage($page) ? $itemActiveClass : $itemClass; $items[] = $this->createListItem($currentClass, $this->renderLink($page, $this->paginator->getUrl($page), $linkClass)); } else { $items[] = $this->createListItem($itemClass, $this->renderLink($page, '#', $linkClass)); } } // Last - check if next page available if ($this->paginator->hasNextPage()) { $items[] = $this->createListItem($itemClass, $this->renderLink($nextCaption, $this->paginator->getNextPageUrl(), $linkClass)); } return $items; }
php
{ "resource": "" }
q12866
Payment_Controller.callback
train
public function callback($request) { // If post data exists, process. Otherwise provide error if ($this->payment_handler === null) { // Redirect to error page return $this->redirect(Controller::join_links( Director::BaseURL(), $this->config()->url_segment, 'complete', 'error' )); } // Hand the request over to the payment handler return $this ->payment_handler ->handleRequest($request, $this->model); }
php
{ "resource": "" }
q12867
DataSourceConfig.addColumn
train
public function addColumn(BlockInterface $column, $index = null) { $this->mappingColumns = null; if (null !== $index) { array_splice($this->columns, $index, 0, $column); } else { array_push($this->columns, $column); } return $this; }
php
{ "resource": "" }
q12868
DataSourceConfig.removeColumn
train
public function removeColumn($index) { $this->mappingColumns = null; array_splice($this->columns, $index, 1); return $this; }
php
{ "resource": "" }
q12869
DataSourceConfig.setSortColumns
train
public function setSortColumns(array $columns) { $this->sortColumns = []; $this->mappingSortColumns = []; foreach ($columns as $i => $column) { if (!isset($column['name'])) { throw new InvalidArgumentException('The "name" property of sort column must be present ("sort" property is optional)'); } if (isset($column['sort']) && 'asc' !== $column['sort'] && 'desc' !== $column['sort']) { throw new InvalidArgumentException('The "sort" property of sort column must have "asc" or "desc" value'); } if ($this->isSorted($column['name'])) { throw new InvalidArgumentException(sprintf('The "%s" column is already sorted', $column['name'])); } $this->sortColumns[] = $column; $this->mappingSortColumns[$column['name']] = $i; } return $this; }
php
{ "resource": "" }
q12870
DataSourceConfig.getSortColumn
train
public function getSortColumn($column) { $val = null; if ($this->isSorted($column)) { $def = $this->sortColumns[$this->mappingSortColumns[$column]]; if (isset($def['sort'])) { $val = $def['sort']; } } return $val; }
php
{ "resource": "" }
q12871
DataSourceConfig.getColumnIndex
train
public function getColumnIndex($name) { if (!\is_array($this->mappingColumns)) { $this->mappingColumns = []; /* @var BlockInterface $column */ foreach ($this->getColumns() as $i => $column) { $this->mappingColumns[$column->getName()] = $i; } } if (isset($this->mappingColumns[$name])) { $column = $this->columns[$this->mappingColumns[$name]]; return $column->getOption('index'); } throw new InvalidArgumentException(sprintf('The column name "%s" does not exist', $name)); }
php
{ "resource": "" }
q12872
TrainersClub.fetchExecutionToken
train
protected function fetchExecutionToken() { try { $response = $this->client->get(static::LOGIN_URL, [ 'headers' => [ 'User-Agent' => 'niantic' ] ]); } catch(ServerException $e) { sleep(1); return $this->fetchExecutionToken(); } if ($response->getStatusCode() !== 200) { throw new AuthenticationException("Could not retrieve execution token. Got status code " . $response->getStatusCode()); } $jsonData = json_decode($response->getBody()->getContents()); if (!$jsonData || !isset($jsonData->execution)) { throw new AuthenticationException("Could not retrieve execution token. Invalid JSON. TrainersClub could be offline or unstable."); } return $jsonData; }
php
{ "resource": "" }
q12873
MakeObserverCommand.registerObserverServiceProvider
train
public function registerObserverServiceProvider() { if (! $this->files->exists(app_path('Providers/ObserverServiceProvider.php'))) { $this->call('make:provider', [ 'name' => 'ObserverServiceProvider', ]); $this->info('Please register your ObserverServiceProvider in config/app.php.'); $this->info('Do run php artisan config:cache to make sure ObserverServiceProvider is loaded.'); } else { $this->info(app_path('Providers/ObserverServiceProvider.php') . ' already exist.'); } }
php
{ "resource": "" }
q12874
FilterArray.addElementToFilteredArray
train
protected static function addElementToFilteredArray($key, $value) { if (is_null(self::$filteringCallback)) { return ($value); } if (is_string(self::$filteringCallback) && function_exists(self::$filteringCallback)) { $callback = self::$filteringCallback; return $callback($key, $value); } return call_user_func(self::$filteringCallback, $key, $value); }
php
{ "resource": "" }
q12875
FilterArray.filterStrings
train
protected static function filterStrings(array &$subjectArray, $goDeep = null, $filterFunction = null) { $arrayWalkFunction = self::getArrayWalkFunction($goDeep); $arrayWalkFunction($subjectArray, function (&$item) use ($filterFunction) { if (!is_string($item)) { return; } if (is_callable($filterFunction)) { $item = $filterFunction($item); } $item = trim($item); }); return $subjectArray; }
php
{ "resource": "" }
q12876
ReadonlyOptions.init
train
static function init() { // This can be overridden if something else feels better self::$hover_text = 'This option is set readonly in ' . basename(__DIR__).'/'.basename(__FILE__); // Use javascript hack in admin option pages if ( is_admin() && ! defined('WP_READONLY_OPTIONS_NO_JS') ) { add_action('admin_enqueue_scripts', [ __CLASS__, 'set_admin_readonly_js' ] ); } }
php
{ "resource": "" }
q12877
ReadonlyOptions.set
train
static function set( array $options ) { if ( is_array( $options ) ) { // Force mentioned options with filters foreach ( $options as $must_use_option => $must_use_value ) { // Always return this value for the option add_filter( "pre_option_{$must_use_option}", function() use ( $must_use_value ) { return $must_use_value; }); // Always deny saving this value to the DB // wp-includes/option.php:280-291 stops updating this option if it's same add_filter( "pre_update_option_{$must_use_option}", function() use ( $must_use_value ) { return $must_use_value; }); } // Add to all options which can be used later on in admin_footer hook self::add_options( $options ); } }
php
{ "resource": "" }
q12878
AuthTicket.fromProto
train
public static function fromProto(ProtoAuthTicket $ticket) : self { return new self($ticket->getStart()->getContents(), $ticket->getEnd()->getContents(), $ticket->getExpireTimestampMs()); }
php
{ "resource": "" }
q12879
FlashBag.prepare
train
private function prepare() { if (!$this->storage->has(self::FLASH_KEY)) { $this->storage->set(self::FLASH_KEY, array()); } }
php
{ "resource": "" }
q12880
FlashBag.has
train
public function has($key) { $flashMessages = $this->storage->get(self::FLASH_KEY); return isset($flashMessages[$key]); }
php
{ "resource": "" }
q12881
FlashBag.set
train
public function set($key, $message) { $this->storage->set(self::FLASH_KEY, array($key => $message)); return $this; }
php
{ "resource": "" }
q12882
FlashBag.get
train
public function get($key) { if ($this->has($key)) { $flashMessages = $this->storage->get(self::FLASH_KEY); $message = $flashMessages[$key]; $this->remove($key); if ($this->translator instanceof TranslatorInterface) { $message = $this->translator->translate($message); } return $message; } else { throw new RuntimeException(sprintf( 'Attempted to read non-existing key %s', $key )); } }
php
{ "resource": "" }
q12883
Factory.buildClassNameByFileName
train
final protected function buildClassNameByFileName($filename) { $className = sprintf('%s/%s', $this->getNamespace(), $filename); // Normalize it $className = str_replace(array('//', '/', '\\'), '\\', $className); return $className; }
php
{ "resource": "" }
q12884
Factory.build
train
final public function build() { $arguments = func_get_args(); $filename = array_shift($arguments); $className = $this->buildClassNameByFileName($filename); $ib = new InstanceBuilder(); return $ib->build($className, $arguments); }
php
{ "resource": "" }
q12885
AbstractRenderer.hasParent
train
protected function hasParent($id, array $relationships) { foreach ($relationships as $parentId => $children) { // 0 is reserved, therefore must be ignored if ($parentId == 0) { continue; } if (in_array($id, $children)) { return true; } } // By default return false; }
php
{ "resource": "" }
q12886
QueryContainer.getParam
train
private function getParam($param, $default = null) { if (isset($this->query[$param])) { return $this->query[$param]; } else { return $default; } }
php
{ "resource": "" }
q12887
QueryContainer.isSortedByMethod
train
private function isSortedByMethod($column, $value) { return $this->isSortedBy($column) && $this->getParam(FilterInvoker::FILTER_PARAM_DESC) == $value; }
php
{ "resource": "" }
q12888
QueryContainer.getColumnSortingUrl
train
public function getColumnSortingUrl($column) { $data = array( FilterInvoker::FILTER_PARAM_PAGE => $this->getCurrentPageNumber(), FilterInvoker::FILTER_PARAM_DESC => !$this->isSortedByDesc($column), FilterInvoker::FILTER_PARAM_SORT => $column ); return FilterInvoker::createUrl(array_merge($this->query, $data), $this->route); }
php
{ "resource": "" }
q12889
CreditCard.withToken
train
public function withToken(Token $token) { $card = $this->with('token', $token); if (null !== $card->number) { $lastDigits = strlen($card->number) <= 4 ? $card->number : substr($card->number, -4); $card->number = "XXXX-XXXX-XXXX-" . $lastDigits; } $card->cvv = null; return $card; }
php
{ "resource": "" }
q12890
Database.asArray
train
public function asArray() { $array = []; $properties = (new \ReflectionClass($this)) ->getProperties(ReflectionProperty::IS_PUBLIC); foreach ($properties as $object) { $value = $object->getValue($this); if (!isset($value)) { continue; } $property = $object->getName(); if (!empty($this->mappings) && isset($this->mappings[$property])) { $property = $this->mappings[$property]; } $array[$property] = $value; } return new \ArrayIterator($array); }
php
{ "resource": "" }
q12891
PhpProjectType.importDatabaseToService
train
public function importDatabaseToService($service = null, $import_path = null, $copy_to_service = false, $localhost = false) { $destination = $this->resolveDatabaseImportDestination( $import_path, $service, $copy_to_service, $localhost ); /** @var CommandBuilder $command */ $command = $this->resolveDatabaseImportCommand()->command("< {$destination}"); $this->executeEngineCommand($command, $service, [], false, $localhost); return $this; }
php
{ "resource": "" }
q12892
PhpProjectType.getDatabaseInfo
train
public function getDatabaseInfo(ServiceDbInterface $instance = null, $allow_override = true) { if (!isset($instance)) { /** @var EngineType $engine */ $engine = $this->getEngineInstance(); $instance = $engine->getServiceInstanceByInterface( ServiceDbInterface::class ); if ($instance === false) { throw new \RuntimeException( 'Unable to find a service for the database instance.' ); } } $database = $this->getServiceInstanceDatabase($instance); if (!$allow_override || !isset($this->databaseOverride)) { return $database; } // Process database overrides on the current db object. foreach (get_object_vars($this->databaseOverride) as $property => $value) { if (empty($value)) { continue; } $method = 'set' . ucwords($property); if (!method_exists($database, $method)) { continue; } $database = call_user_func_array( [$database, $method], [$value] ); } return $database; }
php
{ "resource": "" }
q12893
PhpProjectType.getEnvPhpVersion
train
public function getEnvPhpVersion() { /** @var EngineType $engine */ $engine = $this->getEngineInstance(); $instance = $engine->getServiceInstanceByType('php'); if (empty($instance)) { throw new \RuntimeException( 'No php service has been found.' ); } $service = $instance[0]; return $service->getVersion(); }
php
{ "resource": "" }
q12894
PhpProjectType.initBehat
train
public function initBehat() { $root_path = ProjectX::projectRoot(); if ($this->hasBehat() && !file_exists("$root_path/tests/Behat/features")) { $this->taskBehat() ->option('init') ->option('config', "{$root_path}/tests/Behat/behat.yml") ->run(); } return $this; }
php
{ "resource": "" }
q12895
PhpProjectType.setupPhpCodeSniffer
train
public function setupPhpCodeSniffer() { $root_path = ProjectX::projectRoot(); $this->taskWriteToFile("{$root_path}/phpcs.xml.dist") ->text($this->loadTemplateContents('phpcs.xml.dist')) ->place('PROJECT_ROOT', $this->getInstallRoot()) ->run(); $this->composer->addRequires([ 'squizlabs/php_codesniffer' => static::PHPCS_VERSION, ], true); return $this; }
php
{ "resource": "" }
q12896
PhpProjectType.packagePhpBuild
train
public function packagePhpBuild($build_root) { $project_root = ProjectX::projectRoot(); $stack = $this->taskFilesystemStack(); if (file_exists("{$project_root}/patches")) { $stack->mirror("{$project_root}/patches", "{$build_root}/patches"); } $stack->copy("{$project_root}/composer.json", "{$build_root}/composer.json"); $stack->copy("{$project_root}/composer.lock", "{$build_root}/composer.lock"); $stack->run(); return $this; }
php
{ "resource": "" }
q12897
PhpProjectType.updateComposer
train
public function updateComposer($lock = false) { $update = $this->taskComposerUpdate(); if ($lock) { $update->option('lock'); } $update->run(); return $this; }
php
{ "resource": "" }
q12898
PhpProjectType.hasComposerPackage
train
public function hasComposerPackage($vendor, $dev = false) { $packages = !$dev ? $this->composer->getRequire() : $this->composer->getRequireDev(); return isset($packages[$vendor]); }
php
{ "resource": "" }
q12899
PhpProjectType.extractArchive
train
protected function extractArchive($filename, $destination, $service = null, $localhost = false) { $mime_type = null; if (file_exists($filename) && $localhost) { $mime_type = mime_content_type($filename); } else { $engine = $this->getEngineInstance(); if ($engine instanceof DockerEngineType) { $mime_type = $engine->getFileMimeType($filename, $service); } } $command = null; switch ($mime_type) { case 'application/gzip': case 'application/x-gzip': $command = (new CommandBuilder('gunzip', $localhost)) ->command("-c {$filename} > {$destination}"); break; } if (!isset($command)) { return $filename; } // Remove destination file if on localhost. if (file_exists($destination) && $localhost) { $this->_remove($destination); } $this->executeEngineCommand($command, $service, [], false, $localhost); return $destination; }
php
{ "resource": "" }