_id stringlengths 2 7 | title stringlengths 3 151 | partition stringclasses 3
values | text stringlengths 83 13k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q12900 | PhpProjectType.resolveDatabaseImportPath | train | protected function resolveDatabaseImportPath($import_path = null)
{
if (!isset($import_path)) {
$import_path = $this->doAsk(
new Question(
'Input the path to the database file: '
)
);
if (!file_exists($import_path)) {
throw new \Exception(
'The path to the database file does not exist.'
);
}
}
return new \SplFileInfo($import_path);
} | php | {
"resource": ""
} |
q12901 | PhpProjectType.resolveDatabaseImportDestination | train | protected function resolveDatabaseImportDestination($import_path, $service, $copy_to_service = false, $localhost = false)
{
/** @var \SplFileInfo $import_path */
$path = $this->resolveDatabaseImportPath($import_path);
$filename = $path->getFilename();
$extract_filename = substr($filename, 0, strrpos($filename, '.'));
if (!$localhost) {
// Copy file to service if uploaded from localhost.
if ($copy_to_service) {
/** @var DockerEngineType $engine */
$engine = $this->getEngineInstance();
if ($engine instanceof DockerEngineType) {
$engine->copyFileToService($path->getRealPath(), '/tmp', $service);
}
}
return $this->extractArchive(
"/tmp/{$filename}",
"/tmp/{$extract_filename}",
$service,
$localhost
);
}
return $this->extractArchive(
$path->getRealPath(),
"/tmp/{$extract_filename}",
null,
$localhost
);
} | php | {
"resource": ""
} |
q12902 | PhpProjectType.resolveDatabaseServiceInstance | train | protected function resolveDatabaseServiceInstance($service = null)
{
/** @var EngineType $engine */
$engine = $this->getEngineInstance();
$services = $engine->getServiceInstanceByGroup('database');
if (!isset($service) || !isset($services[$service])) {
if (count($services) > 1) {
$options = array_keys($services);
$service = $this->doAsk(
new ChoiceQuestion(
'Select the database service to use for import: ',
$options
)
);
} else {
$options = array_keys($services);
$service = reset($options);
}
}
if (!isset($services[$service])) {
throw new \RuntimeException(
'Unable to resolve database service.'
);
}
return $services[$service];
} | php | {
"resource": ""
} |
q12903 | PhpProjectType.resolveDatabaseImportCommand | train | protected function resolveDatabaseImportCommand($service = null)
{
/** @var ServiceDbInterface $instance */
$instance = $this->resolveDatabaseServiceInstance($service);
/** @var DatabaseInterface $database */
$database = $this->getDatabaseInfo($instance);
switch ($database->getProtocol()) {
case 'mysql':
return (new MysqlCommand())
->host($database->getHostname())
->username($database->getUser())
->password($database->getPassword())
->database($database->getDatabase());
case 'pgsql':
return (new PgsqlCommand())
->host($database->getHostname())
->username($database->getUser())
->password($database->getPassword())
->database($database->getDatabase());
}
} | php | {
"resource": ""
} |
q12904 | PhpProjectType.hasDatabaseConnection | train | protected function hasDatabaseConnection($host, $port = 3306, $seconds = 30)
{
$hostChecker = $this->getHostChecker();
$hostChecker
->setHost($host)
->setPort($port);
return $hostChecker->isPortOpenRepeater($seconds);
} | php | {
"resource": ""
} |
q12905 | PhpProjectType.getServiceInstanceDatabase | train | protected function getServiceInstanceDatabase(ServiceDbInterface $instance)
{
$port = current($instance->getHostPorts());
return (new Database($this->databaseInfoMapping()))
->setPort($port)
->setUser($instance->username())
->setPassword($instance->password())
->setProtocol($instance->protocol())
->setHostname($instance->getName())
->setDatabase($instance->database());
} | php | {
"resource": ""
} |
q12906 | PhpProjectType.mergeProjectComposerTemplate | train | protected function mergeProjectComposerTemplate()
{
if ($contents = $this->loadTemplateContents('composer.json', 'json')) {
$this->composer = $this->composer->update($contents);
}
return $this;
} | php | {
"resource": ""
} |
q12907 | PhpProjectType.setupComposerPackages | train | protected function setupComposerPackages()
{
$platform = $this->getPlatformInstance();
if ($platform instanceof ComposerPackageInterface) {
$platform->alterComposer($this->composer);
}
$this->saveComposer();
return $this;
} | php | {
"resource": ""
} |
q12908 | PhpProjectType.composer | train | private function composer()
{
$composer_file = $this->composerFile();
return file_exists($composer_file)
? ComposerConfig::createFromFile($composer_file)
: new ComposerConfig();
} | php | {
"resource": ""
} |
q12909 | ShoppingCart.setAvailablePostage | train | public function setAvailablePostage($country, $code)
{
$postage_areas = new ShippingCalculator($code, $country);
$postage_areas
->setCost($this->SubTotalCost)
->setWeight($this->TotalWeight)
->setItems($this->TotalItems);
$postage_areas = $postage_areas->getPostageAreas();
Session::set("Checkout.AvailablePostage", $postage_areas);
return $this;
} | php | {
"resource": ""
} |
q12910 | ShoppingCart.isCollection | train | public function isCollection()
{
if (Checkout::config()->click_and_collect) {
$type = Session::get("Checkout.Delivery");
return ($type == "collect") ? true : false;
} else {
return false;
}
} | php | {
"resource": ""
} |
q12911 | ShoppingCart.isDeliverable | train | public function isDeliverable()
{
$deliverable = false;
foreach ($this->getItems() as $item) {
if ($item->Deliverable) {
$deliverable = true;
}
}
return $deliverable;
} | php | {
"resource": ""
} |
q12912 | ShoppingCart.emptycart | train | public function emptycart()
{
$this->extend("onBeforeEmpty");
$this->removeAll();
$this->save();
$this->setSessionMessage(
"bad",
_t("Checkout.EmptiedCart", "Shopping cart emptied")
);
return $this->redirectBack();
} | php | {
"resource": ""
} |
q12913 | ShoppingCart.save | train | public function save()
{
Session::clear("Checkout.PostageID");
// Extend our save operation
$this->extend("onBeforeSave");
// Save cart items
Session::set(
"Checkout.ShoppingCart.Items",
serialize($this->items)
);
// Save cart discounts
Session::set(
"Checkout.ShoppingCart.Discount",
serialize($this->discount)
);
// Update available postage
if ($data = Session::get("Form.Form_PostageForm.data")) {
$country = $data["Country"];
$code = $data["ZipCode"];
$this->setAvailablePostage($country, $code);
}
} | php | {
"resource": ""
} |
q12914 | ShoppingCart.getSubTotalCost | train | public function getSubTotalCost()
{
$total = 0;
foreach ($this->items as $item) {
if ($item->SubTotal) {
$total += $item->SubTotal;
}
}
return $total;
} | php | {
"resource": ""
} |
q12915 | ShoppingCart.getDiscountAmount | train | public function getDiscountAmount()
{
$total = 0;
$discount = 0;
foreach ($this->items as $item) {
if ($item->Price) {
$total += ($item->Price * $item->Quantity);
}
if ($item->Discount) {
$discount += ($item->TotalDiscount);
}
}
if ($discount > $total) {
$discount = $total;
}
return $discount;
} | php | {
"resource": ""
} |
q12916 | ShoppingCart.doAddDiscount | train | public function doAddDiscount($data, $form)
{
$code_to_search = $data['DiscountCode'];
// First check if the discount is already added (so we don't
// query the DB if we don't have to).
if (!$this->discount || ($this->discount && $this->discount->Code != $code_to_search)) {
$code = Discount::get()
->filter("Code", $code_to_search)
->exclude("Expires:LessThan", date("Y-m-d"))
->first();
if ($code) {
$this->discount = $code;
}
}
$this->save();
return $this->redirectBack();
} | php | {
"resource": ""
} |
q12917 | ShoppingCart.doSetPostage | train | public function doSetPostage($data, $form)
{
$country = $data["Country"];
$code = $data["ZipCode"];
$this->setAvailablePostage($country, $code);
$postage = Session::get("Checkout.AvailablePostage");
// Check that postage is set, if not, see if we can set a default
if (array_key_exists("PostageID", $data) && $data["PostageID"]) {
// First is the current postage ID in the list of postage
// areas
if ($postage && $postage->exists() && $postage->find("ID", $data["PostageID"])) {
$id = $data["PostageID"];
} else {
$id = $postage->first()->ID;
}
$data["PostageID"] = $id;
Session::set("Checkout.PostageID", $id);
} else {
// Finally set the default postage
if ($postage && $postage->exists()) {
$data["PostageID"] = $postage->first()->ID;
Session::set("Checkout.PostageID", $postage->first()->ID);
}
}
// Set the form pre-populate data before redirecting
Session::set("Form.{$form->FormName()}.data", $data);
$url = Controller::join_links($this->Link(), "#{$form->FormName()}");
return $this->redirect($url);
} | php | {
"resource": ""
} |
q12918 | BaseWebUserContext.iFillTheUiSelectWithAndSelectElement2 | train | public function iFillTheUiSelectWithAndSelectElement2($id, $item)
{
$items = explode("-", $item);
if(count($items) > 0){
$item = $items[0].'-'.((int)$items[1] - 1);
}else {
$item = "0-".((int)$item - 1);
}
$idItem = sprintf("#ui-select-choices-row-%s",$item);
$this->iClickTheElement(sprintf("#%s > div.ui-select-match.ng-scope > span",$id));
$this->spin(function($context) use ($idItem){
$element = $context->findElement($idItem);
return $element != null;
},20);
$element = $this->findElement($idItem);
$element->click();
} | php | {
"resource": ""
} |
q12919 | BaseWebUserContext.generatePageUrl | train | protected function generatePageUrl($route, array $parameters = array())
{
// $parts = explode(' ', trim($page), 2);
// $route = implode('_', $parts);
// $route = str_replace(' ', '_', $route);
$path = $this->generateUrl($route, $parameters);
// var_dump($this->getMinkParameter('base_url'));
// var_dump($path);
// die;
if ('Selenium2Driver' === strstr(get_class($this->getSession()->getDriver()), 'Selenium2Driver')) {
return sprintf('%s%s', $this->getMinkParameter('base_url'), $path);
}
return $path;
} | php | {
"resource": ""
} |
q12920 | BaseWebUserContext.iWaitForTextToDisappear | train | public function iWaitForTextToDisappear($text)
{
$this->spin(function(FeatureContext $context) use ($text) {
try {
$context->assertPageContainsText($text);
}
catch(\Behat\Mink\Exception\ResponseTextException $e) {
return true;
}
return false;
});
} | php | {
"resource": ""
} |
q12921 | BaseWebUserContext.spin | train | public function spin($lambda, $wait = 15,$errorCallback = null)
{
$time = time();
$stopTime = $time + $wait;
while (time() < $stopTime)
{
try {
if ($lambda($this)) {
return;
}
} catch (\Exception $e) {
// do nothing
}
usleep(250000);
}
if($errorCallback !== null){
$errorCallback($this);
}
throw new \Exception("Spin function timed out after {$wait} seconds");
} | php | {
"resource": ""
} |
q12922 | ComposerConfig.addRequires | train | public function addRequires(array $requires, $dev = false)
{
foreach ($requires as $vendor => $version) {
if (!isset($vendor) || !isset($version)) {
continue;
}
if (!$dev) {
$this->addRequire($vendor, $version);
} else {
$this->addDevRequire($vendor, $version);
}
}
return $this;
} | php | {
"resource": ""
} |
q12923 | ComposerConfig.addRequire | train | public function addRequire($vendor, $version)
{
if (!isset($this->require[$vendor])) {
$this->require[$vendor] = $version;
}
return $this;
} | php | {
"resource": ""
} |
q12924 | ComposerConfig.addDevRequire | train | public function addDevRequire($vendor, $version)
{
if (!isset($this->require_dev[$vendor])) {
$this->require_dev[$vendor] = $version;
}
return $this;
} | php | {
"resource": ""
} |
q12925 | ComposerConfig.addExtra | train | public function addExtra($key, array $options)
{
if (!isset($this->extra[$key])) {
$this->extra[$key] = $options;
}
return $this;
} | php | {
"resource": ""
} |
q12926 | Stats.getStat | train | public function getStat($stat)
{
if (isset($this->stats[$stat])) {
return $this->stats[$stat];
}
return false;
} | php | {
"resource": ""
} |
q12927 | CheckoutMemberExtension.getDefaultAddress | train | public function getDefaultAddress()
{
if ($this->cached_address) {
return $this->cached_address;
} else {
$address = $this
->owner
->Addresses()
->sort("Default", "DESC")
->first();
$this->cached_address = $address;
return $address;
}
} | php | {
"resource": ""
} |
q12928 | CheckoutMemberExtension.getDiscount | train | public function getDiscount()
{
$discounts = ArrayList::create();
foreach ($this->owner->Groups() as $group) {
foreach ($group->Discounts() as $discount) {
$discounts->add($discount);
}
}
$discounts->sort("Amount", "DESC");
return $discounts->first();
} | php | {
"resource": ""
} |
q12929 | SequenceGeneratorBase.buildRef | train | public function buildRef(ItemReferenceInterface $item,array $config) {
$mask = $config['mask'];
$className = $config['className'];
$field = $config['field'];
$qb = $this->sequenceGenerator->createQueryBuilder();
$qb->from($className,'p');
return $this->sequenceGenerator->generateNext($qb, $mask,$field,[],$config);
} | php | {
"resource": ""
} |
q12930 | SequenceGeneratorBase.setRef | train | public function setRef(ItemReferenceInterface $item)
{
$className = ClassUtils::getRealClass(get_class($item));
$classMap = $this->getClassMap();
if(!isset($classMap[$className])){
throw new LogicException(sprintf("No ha definido la configuracion de '%s' para generar su referencia",$className));
}
$resolver = new \Symfony\Component\OptionsResolver\OptionsResolver();
$resolver->setDefined([
"method","field","options","mask"
]);
$resolver->setDefaults([
'method' => 'buildRef',
'field' => 'ref',
'use_cache' => false,
// 'options' => array()
]);
$config = $resolver->resolve($classMap[$className]);
$config['className'] = $className;
$method = $config['method'];
$ref = $this->$method($item,$config);
$item->setRef($ref);
return $ref;
} | php | {
"resource": ""
} |
q12931 | SequenceGeneratorBase.setSequenceGenerator | train | function setSequenceGenerator(\Tecnocreaciones\Bundle\ToolsBundle\Service\SequenceGenerator $sequenceGenerator) {
$this->sequenceGenerator = $sequenceGenerator;
} | php | {
"resource": ""
} |
q12932 | UtilsExtension.renderTabs | train | public function renderTabs(\Tecnoready\Common\Model\Tab\Tab $tab,array $parameters = [])
{
$parameters["tab"] = $tab;
return $this->container->get('templating')->render($this->config["tabs"]["template"],
$parameters
);
} | php | {
"resource": ""
} |
q12933 | HtmlMessageContent.asPlainText | train | public function asPlainText(): string
{
return $this->text ?? $this->text = (new Html2Text($this->html))->getText();
} | php | {
"resource": ""
} |
q12934 | SchemaBuilder.packSchema | train | public function packSchema(): array
{
$result = [];
foreach ($this->schemas as $class => $schema) {
$item = [
//Instantiator class
ODMInterface::D_INSTANTIATOR => $schema->getInstantiator(),
//Primary collection class
ODMInterface::D_PRIMARY_CLASS => $schema->resolvePrimary($this),
//Instantiator and entity specific schema
ODMInterface::D_SCHEMA => $schema->packSchema($this),
];
if (!$schema->isEmbedded()) {
$item[ODMInterface::D_SOURCE_CLASS] = $this->getSource($class);
$item[ODMInterface::D_DATABASE] = $schema->getDatabase();
$item[ODMInterface::D_COLLECTION] = $schema->getCollection();
}
$result[$class] = $item;
}
return $result;
} | php | {
"resource": ""
} |
q12935 | SchemaBuilder.createIndexes | train | public function createIndexes()
{
foreach ($this->schemas as $class => $schema) {
if ($schema->isEmbedded()) {
continue;
}
$collection = $this->manager->database(
$schema->getDatabase()
)->selectCollection(
$schema->getCollection()
);
//Declaring needed indexes
foreach ($schema->getIndexes() as $index) {
$collection->createIndex($index->getIndex(), $index->getOptions());
}
}
} | php | {
"resource": ""
} |
q12936 | FileDownloader.prepare | train | private function prepare($mimeType, $baseName)
{
// Ensure that output buffering is turned off. @ - intentionally
@ob_end_clean();
// Special hack for legacy IE version
if (ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');
}
// Prepare required headers
$headers = array(
'Content-Type' => $mimeType,
'Content-Disposition' => sprintf('attachment; filename="%s"', rawurldecode($baseName)),
'Content-Transfer-Encoding' => 'binary',
'Accept-Ranges' => 'bytes',
'Cache-control' => 'private',
'Pragma' => 'private',
'Expires' => 'Thu, 21 Jul 1999 05:00:00 GMT'
);
$this->headerBag->appendPairs($headers)
->send()
->clear();
} | php | {
"resource": ""
} |
q12937 | FileDownloader.preload | train | private function preload($target, $alias)
{
if (!is_file($target) || !is_readable($target)) {
throw new RuntimeException('Either invalid file supplied or its not readable');
}
// Prepare base name
if ($alias === null) {
$baseName = FileManager::getBaseName($target);
} else {
$baseName = $alias;
}
// Grab the Mime-Type
$mime = FileManager::getMimeType($target);
$this->prepare($mime, $baseName);
} | php | {
"resource": ""
} |
q12938 | FileDownloader.download | train | public function download($target, $alias = null)
{
$this->preload($target, $alias);
// Count file size in bytes
$size = filesize($target);
// multipart-download and download resuming support
if (isset($_SERVER['HTTP_RANGE'])) {
list($a, $range) = explode("=", $_SERVER['HTTP_RANGE'], 2);
list($range) = explode(",", $range, 2);
list($range, $range_end) = explode("-", $range);
$range = intval($range);
if (!$range_end) {
$range_end = $size - 1;
} else {
$range_end = intval($range_end);
}
$new_length = $range_end - $range + 1;
$headers = array(
'Content-Length' => $new_length,
'Content-Range' => sprintf('bytes %s', $range - $range_end / $size)
);
$this->headerBag->setStatusCode(206)
->setPairs($headers)
->send();
} else {
$new_length = $size;
$this->headerBag->appendPair('Content-Length', $size)
->send()
->clear();
}
$chunksize = 1024 * 1024;
$bytes_send = 0;
$target = fopen($target, 'r');
if (isset($_SERVER['HTTP_RANGE'])) {
fseek($target, $range);
}
while (!feof($target) && (!connection_aborted()) && ($bytes_send < $new_length)) {
$buffer = fread($target, $chunksize);
print($buffer);
flush();
$bytes_send += strlen($buffer);
}
fclose($target);
} | php | {
"resource": ""
} |
q12939 | AbstractController.redirectToRoute | train | final protected function redirectToRoute($route)
{
$url = $this->urlBuilder->build($route);
if ($url !== null) {
$this->response->redirect($url);
} else {
throw new RuntimeException(sprintf('Unknown route supplied for redirection "%s"', $route));
}
} | php | {
"resource": ""
} |
q12940 | AbstractController.getQueryFilter | train | final protected function getQueryFilter(FilterableServiceInterface $service, $perPageCount, $route)
{
$invoker = new FilterInvoker($this->request->getQuery(), $route);
return $invoker->invoke($service, $perPageCount);
} | php | {
"resource": ""
} |
q12941 | AbstractController.getOptions | train | public function getOptions($key = null)
{
if ($key == null) {
return $this->options;
} else {
return $this->options[$key];
}
} | php | {
"resource": ""
} |
q12942 | AbstractController.haltOnDemand | train | final protected function haltOnDemand()
{
switch (true) {
// If at least one of below conditions is true, then $this->halt() is called
case $this->hasOption('secure') && $this->getOptions('secure') == true && !$this->request->isSecure():
case $this->hasOption('ajax') && $this->getOptions('ajax') == true && !$this->request->isAjax():
case $this->hasOption('method') && (strtoupper($this->getOptions('method')) != $this->request->getMethod()):
$this->halt();
}
} | php | {
"resource": ""
} |
q12943 | AbstractController.loadTranslationMessages | train | private function loadTranslationMessages($language)
{
// Reset any previous translations if any
$this->moduleManager->clearTranslations();
$this->translator->reset();
// Now load new ones
$this->moduleManager->loadAllTranslations($language);
$this->translator->extend($this->moduleManager->getTranslations());
} | php | {
"resource": ""
} |
q12944 | AbstractController.loadDefaultTranslations | train | private function loadDefaultTranslations()
{
$language = $this->appConfig->getLanguage();
if ($language !== null) {
$this->loadTranslationMessages($language);
}
} | php | {
"resource": ""
} |
q12945 | AbstractController.loadTranslations | train | final protected function loadTranslations($language)
{
// Don't load the same language twice, if that's the case
if ($this->appConfig->getLanguage() !== $language) {
$this->appConfig->setLanguage($language);
$this->loadTranslationMessages($language);
return true;
} else {
return false;
}
} | php | {
"resource": ""
} |
q12946 | AbstractController.initialize | train | final public function initialize($action)
{
$this->haltOnDemand();
// Configure view with defaults
$this->view->setModule($this->getModule())
->setTheme($this->appConfig->getTheme());
if (method_exists($this, 'bootstrap')) {
$this->bootstrap($action);
}
if (method_exists($this, 'onAuth')) {
$this->onAuth();
}
$this->loadDefaultTranslations();
} | php | {
"resource": ""
} |
q12947 | Controllers.get | train | public static function get($controllerClass) {
if (!isset(self::$controllers[$controllerClass])) {
if (class_exists($controllerClass)) {
$reflectionClass = new ReflectionClass($controllerClass);
self::$controllers[$controllerClass] = $reflectionClass->isAbstract()? $controllerClass : (new $controllerClass);
}
else {
self::$controllers[$controllerClass] = null;
}
}
return self::$controllers[$controllerClass];
} | php | {
"resource": ""
} |
q12948 | Manager.createLaravelDriver | train | protected function createLaravelDriver(): Sdk\Client
{
return \tap($this->createHttpClient(), function ($client) {
if (isset($this->config['client_id']) || isset($this->config['client_secret'])) {
$client->setClientId($this->config['client_id'])
->setClientSecret($this->config['client_secret']);
}
if (isset($this->config['access_token'])) {
$client->setAccessToken($this->config['access_token']);
}
});
} | php | {
"resource": ""
} |
q12949 | MemcachedEngine.set | train | public function set($key, $value, $ttl)
{
if (!$this->memcached->set($key, $value, $ttl)) {
// If set() returns false, that means the key already exists,
return $this->memcached->replace($key, $value, $ttl);
} else {
// set() returned true, so the key has been set successfully
return true;
}
} | php | {
"resource": ""
} |
q12950 | MemcachedEngine.get | train | public function get($key, $default = false)
{
$value = $this->memcached->get($key);
if ($this->memcached->getResultCode() == 0) {
return $value;
} else {
return $default;
}
} | php | {
"resource": ""
} |
q12951 | ViewManager.setLayout | train | public function setLayout($layout, $layoutModule = null)
{
$this->layout = $layout;
$this->layoutModule = $layoutModule;
return $this;
} | php | {
"resource": ""
} |
q12952 | ViewManager.addVariables | train | public function addVariables(array $variables)
{
foreach ($variables as $name => $value) {
$this->addVariable($name, $value);
}
return $this;
} | php | {
"resource": ""
} |
q12953 | ViewManager.url | train | public function url()
{
$args = func_get_args();
$controller = array_shift($args);
$url = $this->urlBuilder->createUrl($controller, $args);
if ($url === false) {
return $controller;
} else {
return $url;
}
} | php | {
"resource": ""
} |
q12954 | ViewManager.mapUrl | train | public function mapUrl($controller, array $args = array(), $index = 0)
{
return $this->urlBuilder->createUrl($controller, $args, $index);
} | php | {
"resource": ""
} |
q12955 | ViewManager.show | train | public function show($message, $translate = true)
{
if ($translate === true) {
$message = $this->translate($message);
}
echo $message;
} | php | {
"resource": ""
} |
q12956 | ViewManager.createPath | train | private function createPath($dir, $path, $module, $theme = null)
{
if ($theme !== null) {
return sprintf('%s/%s/%s/%s/%s', $path, self::TEMPLATE_PARAM_MODULES_DIR, $module, $dir, $theme);
} else {
return sprintf('%s/%s/%s/%s', $path, self::TEMPLATE_PARAM_MODULES_DIR, $module, $dir);
}
} | php | {
"resource": ""
} |
q12957 | ViewManager.createSharedThemePath | train | private function createSharedThemePath($module, $theme, $base)
{
if (is_null($theme)) {
$theme = $this->theme;
}
if (is_null($module)) {
$module = $this->module;
}
return sprintf('%s/%s/%s/%s', $base, $module, self::TEMPLATE_PARAM_BASE_DIR, $theme);
} | php | {
"resource": ""
} |
q12958 | ViewManager.createThemeUrl | train | public function createThemeUrl($module = null, $theme = null)
{
return $this->createSharedThemePath($module, $theme, '/'.self::TEMPLATE_PARAM_MODULES_DIR);
} | php | {
"resource": ""
} |
q12959 | ViewManager.createThemePath | train | public function createThemePath($module = null, $theme = null)
{
return $this->createSharedThemePath($module, $theme, $this->moduleDir);
} | php | {
"resource": ""
} |
q12960 | ViewManager.createAssetUrl | train | public function createAssetUrl($module = null, $path = null)
{
if (is_null($module)) {
$module = $this->module;
}
return sprintf('/%s/%s/%s', self::TEMPLATE_PARAM_MODULES_DIR, $module, self::TEMPLATE_PARAM_ASSETS_DIR) . $path;
} | php | {
"resource": ""
} |
q12961 | ViewManager.createAssetPath | train | private function createAssetPath($path, $module, $absolute, $fromAssets)
{
$baseUrl = '';
if ($absolute === true) {
$url = $baseUrl;
} else {
$url = null;
}
// If module isn't provided, then current one used by default
if (is_null($module)) {
$module = $this->module;
}
if ($fromAssets !== false) {
$dir = self::TEMPLATE_PARAM_ASSETS_DIR;
$theme = null;
} else {
$dir = self::TEMPLATE_PARAM_BASE_DIR;
$theme = $this->theme;
}
return $url.sprintf('%s/%s', $this->createPath($dir, $baseUrl, $module, $theme), $path);
} | php | {
"resource": ""
} |
q12962 | ViewManager.createInclusionPath | train | private function createInclusionPath($name, $module = null)
{
if (is_null($module)) {
$module = $this->module;
}
$base = $this->createPath(self::TEMPLATE_PARAM_BASE_DIR, dirname($this->moduleDir), $module, $this->theme);
$path = sprintf('%s.%s', $base . \DIRECTORY_SEPARATOR . $name, self::TEMPLATE_PARAM_EXTENSION);
return $path;
} | php | {
"resource": ""
} |
q12963 | ViewManager.moduleAsset | train | public function moduleAsset($asset, $module = null, $absolute = false)
{
return $this->createAssetPath($asset, $module, $absolute, true);
} | php | {
"resource": ""
} |
q12964 | ViewManager.asset | train | public function asset($asset, $module = null, $absolute = false)
{
return $this->createAssetPath($asset, $module, $absolute, false);
} | php | {
"resource": ""
} |
q12965 | ViewManager.createContentWithLayout | train | private function createContentWithLayout($layout, $fragment)
{
// Create and append $fragment variable to the shared view stack
$this->variables[self::TEMPLATE_PARAM_FRAGMENT_VAR_NAME] = $this->createFileContent($fragment);
return $this->createFileContent($layout);
} | php | {
"resource": ""
} |
q12966 | ViewManager.render | train | public function render($template, array $vars = array())
{
// Make sure template file isn't empty string
if (empty($template)) {
throw new LogicException('Empty template name provided');
}
if (!$this->templateExists($template)) {
$base = $this->createPath(self::TEMPLATE_PARAM_BASE_DIR, dirname($this->moduleDir), $this->module, $this->theme);
throw new RuntimeException(sprintf('Cannot find "%s.%s" in %s', $template, self::TEMPLATE_PARAM_EXTENSION, $base));
}
// Template file
$file = $this->createInclusionPath($template);
$this->addVariables($vars);
if ($this->hasLayout()) {
$layout = $this->createInclusionPath($this->layout, $this->layoutModule);
$content = $this->createContentWithLayout($layout, $file);
} else {
$content = $this->createFileContent($file);
}
// Compress if needed
if ($this->compress === true) {
$compressor = new HtmlCompressor();
$content = $compressor->compress($content);
}
return $content;
} | php | {
"resource": ""
} |
q12967 | ViewManager.renderRaw | train | public function renderRaw($module, $theme, $template, array $vars = array())
{
// Save initial values before overriding theme
$initialLayout = $this->layout;
$initialModule = $this->module;
$initialTheme = $this->theme;
// Configure view with new values
$this->setModule($module)
->setTheme($theme)
->disableLayout();
$response = $this->render($template, $vars);
// Restore initial values now
$this->layout = $initialLayout;
$this->module = $initialModule;
$this->theme = $initialTheme;
return $response;
} | php | {
"resource": ""
} |
q12968 | ViewManager.loadPartial | train | public function loadPartial($name, array $vars = array())
{
$partialTemplateFile = $this->getPartialBag()->getPartialFile($name);
if (is_file($partialTemplateFile)) {
extract(array_replace_recursive($vars, $this->variables));
include($partialTemplateFile);
} else {
return false;
}
} | php | {
"resource": ""
} |
q12969 | HtmlHelper.wrapOnDemand | train | public static function wrapOnDemand($condition, $tag, $content)
{
if ($condition) {
echo sprintf('<%s>%s</%s>', $tag, $content, $tag);
} else {
echo $content;
}
} | php | {
"resource": ""
} |
q12970 | Request.baseContext | train | public function baseContext() {
$baseContext = get_property("web.base_context", "");
if (empty($baseContext)) {
$baseContext = !empty($_SERVER["CONTEXT_PREFIX"])? $_SERVER["CONTEXT_PREFIX"] : "";
}
return $baseContext;
} | php | {
"resource": ""
} |
q12971 | Request.setData | train | public function setData(array $request = []) {
unset($this->parameters);
unset($this->path);
unset($this->pathParts);
$_REQUEST = $request;
} | php | {
"resource": ""
} |
q12972 | LayoutProcessor.beforeProcess | train | public function beforeProcess(
\Magento\Checkout\Block\Checkout\LayoutProcessor $subject,
$jsLayout
) {
if (!$this->enhancementHelper->isActiveGoogleAddress()) {
if (isset($jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
['children']['shippingAddress']['children']['shipping-address-fieldset']
)) {
// Revert changes
$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
['children']['shippingAddress']['children']['shipping-address-fieldset']['component'] = 'uiComponent';
unset($jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
['children']['shippingAddress']['children']['shipping-address-fieldset']['config']['template']);
}
}
return [$jsLayout];
} | php | {
"resource": ""
} |
q12973 | ValidatorBuilderTrait.hasMandatoryItem | train | protected function hasMandatoryItem(array $definition)
{
foreach ($definition as $key => $node) {
if (isset($node['required'])) {
if ($node['required']) {
return true;
}
} else {
if ($this->hasMandatoryItem($node)) {
return true;
}
}
}
return false;
} | php | {
"resource": ""
} |
q12974 | MapManager.getDataByUriTemplate | train | public function getDataByUriTemplate($uriTemplate, $option = null)
{
if (isset($this->map[$uriTemplate])) {
$target = $this->map[$uriTemplate];
if ($option !== null) {
// The option might not be set, so ensure
if (!isset($target[$option])) {
throw new RuntimeException(sprintf('Can not read non-existing option %s for "%s"', $option, $uriTemplate));
} else {
return $target[$option];
}
} else {
return $target;
}
} else {
throw new RuntimeException(sprintf(
'URI "%s" does not belong to route map. Cannot get a controller in %s', $uriTemplate, __METHOD__
));
}
} | php | {
"resource": ""
} |
q12975 | MapManager.getControllers | train | public function getControllers()
{
$map = $this->map;
$result = array();
foreach ($map as $template => $options) {
if (isset($options['controller'])) {
$result[] = $options['controller'];
}
}
return $result;
} | php | {
"resource": ""
} |
q12976 | MapManager.findUriTemplatesByController | train | public function findUriTemplatesByController($controller)
{
$result = array();
foreach ($this->map as $uriTemplate => $options) {
if (isset($options['controller']) && $options['controller'] == $controller) {
array_push($result, $uriTemplate);
}
}
return $result;
} | php | {
"resource": ""
} |
q12977 | MapManager.getUrlTemplateByController | train | public function getUrlTemplateByController($controller)
{
$result = $this->findUriTemplatesByController($controller);
// Now check the results of search
if (isset($result[0])) {
return $result[0];
} else {
return false;
}
} | php | {
"resource": ""
} |
q12978 | MapManager.getControllerByURITemplate | train | public function getControllerByURITemplate($uriTemplate)
{
$controller = $this->getDataByUriTemplate($uriTemplate, 'controller');
$separatorPosition = strpos($controller, '@');
if ($separatorPosition !== false) {
$controller = substr($controller, 0, $separatorPosition);
return $this->notation->toClassPath($controller);
} else {
// No separator
return false;
}
} | php | {
"resource": ""
} |
q12979 | MapManager.getActionByURITemplate | train | public function getActionByURITemplate($uriTemplate)
{
$controller = $this->getDataByUriTemplate($uriTemplate, 'controller');
$separatorPosition = strpos($controller, '@');
if ($separatorPosition !== false) {
$action = substr($controller, $separatorPosition + 1);
return $action;
} else {
// No separator
return false;
}
} | php | {
"resource": ""
} |
q12980 | Socket.open | train | public function open($host, $port, $timeout)
{
if (($this->socket = @fsockopen($host, $port, $errno, $errstr, ($timeout / 1000))) === false) {
return false;
}
return true;
} | php | {
"resource": ""
} |
q12981 | Socket.isTimedOut | train | public function isTimedOut()
{
if (is_resource($this->socket)) {
$info = stream_get_meta_data($this->socket);
}
return $this->socket === null || $this->socket === false || $info['timed_out'] || feof($this->socket);
} | php | {
"resource": ""
} |
q12982 | Socket.readLine | train | public function readLine()
{
do {
$line = rtrim(fgets($this->socket));
// server must have dropped the connection
if ($line === '' && feof($this->socket)) {
$this->close();
return false;
}
} while ($line === '');
return $line;
} | php | {
"resource": ""
} |
q12983 | EngineType.getServiceNamesByType | train | public function getServiceNamesByType($type)
{
if (!$this->hasServices()) {
return [];
}
$types = [];
$services = $this->getServices();
foreach ($services as $name => $service) {
if ($service['type'] !== $type) {
continue;
}
$types[] = $name;
}
return $types;
} | php | {
"resource": ""
} |
q12984 | EngineType.getServiceInstances | train | public function getServiceInstances()
{
$instances = [];
foreach ($this->getServices() as $name => $info) {
if (!isset($info['type'])) {
continue;
}
$type = $info['type'];
unset($info['type']);
$instances[$name] = [
'type' => $type,
'options' => $info,
'instance' => static::loadService($this, $type, $name),
];
}
return $instances;
} | php | {
"resource": ""
} |
q12985 | EngineType.getServiceInstanceByGroup | train | public function getServiceInstanceByGroup($group)
{
$services = [];
$services_map = static::services();
foreach ($this->getServiceInstances() as $name => $info) {
if (!isset($info['type']) || !isset($info['instance'])) {
continue;
}
$type = $info['type'];
if (!isset($services_map[$type])) {
continue;
}
$classname = $services_map[$type];
if ($group !== $classname::group()) {
continue;
}
$services[$name] = $info['instance'];
}
return $services;
} | php | {
"resource": ""
} |
q12986 | EngineType.getServiceInstanceByType | train | public function getServiceInstanceByType($type)
{
$services = [];
$instances = $this->getServiceInstances();
foreach ($this->getServiceNamesByType($type) as $name) {
if (!isset($instances[$name]['instance'])) {
continue;
}
$services[] = $instances[$name]['instance'];
}
return $services;
} | php | {
"resource": ""
} |
q12987 | EngineType.getServiceInstanceByInterface | train | public function getServiceInstanceByInterface($interface)
{
foreach ($this->getServiceInstances() as $info) {
if (!isset($info['instance'])) {
continue;
}
$instance = $info['instance'];
if ($instance instanceof $interface) {
return $instance;
}
}
return false;
} | php | {
"resource": ""
} |
q12988 | EngineType.loadService | train | public static function loadService(
EngineTypeInterface $engine,
$type,
$name = null
) {
$classname = static::serviceClassname($type);
if (!class_exists($classname)) {
throw new \RuntimeException(
sprintf("Service class %s doesn't exist.", $classname)
);
}
return new $classname($engine, $name);
} | php | {
"resource": ""
} |
q12989 | EngineType.serviceClassname | train | public static function serviceClassname($name)
{
$services = static::services();
if (!isset($services[$name])) {
throw new \InvalidArgumentException(
sprintf('The provided service %s does not exist.', $name)
);
}
return $services[$name];
} | php | {
"resource": ""
} |
q12990 | EngineType.getOptions | train | protected function getOptions()
{
$engine = $this->getConfigs()->getEngine();
$options = $this->getConfigs()->getOptions();
return isset($options[$engine])
? $options[$engine]
: [];
} | php | {
"resource": ""
} |
q12991 | ModelDocument.getFilePathContent | train | public function getFilePathContent() {
if($this->filePathContent === null){
throw new InvalidArgumentException(sprintf("The filePathContent must be setter."));
}
$path = $this->filePathContent;
if($this->container){
$path = $this->container->get("kernel")->locateResource($this->filePathContent);
}
if(!$this->chainModel->getExporterManager()->getFs()->exists($path)){
throw new InvalidArgumentException(sprintf("The filePathContent '%s' does not exist.",$path));
}
return $path;
} | php | {
"resource": ""
} |
q12992 | ModelDocument.getFilePathHeader | train | public function getFilePathHeader() {
if($this->filePathHeader === null){
throw new InvalidArgumentException(sprintf("The filePathContent must be setter."));
}
$path = $this->filePathHeader;
if($this->container){
$path = $this->container->get("kernel")->locateResource($path);
}
if(!$this->chainModel->getExporterManager()->getFs()->exists($path)){
throw new InvalidArgumentException(sprintf("The filePathHeader '%s' does not exist.",$path));
}
return $path;
} | php | {
"resource": ""
} |
q12993 | ModelDocument.getDocumentPath | train | protected function getDocumentPath(array $parameters = []) {
$dirOut = $this->getDirOutput();
$dirOut = $dirOut.DIRECTORY_SEPARATOR.$this->getFileNameTranslate($parameters).'.'.$this->getFormat();
return $dirOut;
} | php | {
"resource": ""
} |
q12994 | ConstraintException.getTargetNode | train | protected function getTargetNode()
{
if (null === $target = $this->getTarget()) {
$segments = explode('/', $this->getPath());
$target = '';
while (count($segments) > 0) {
$segment = array_pop($segments);
$target = $segment.'/'.$target;
if (!is_numeric($segment)) {
break;
}
}
return rtrim($target, '/');
}
return $target;
} | php | {
"resource": ""
} |
q12995 | ObjectValidator.isValid | train | public function isValid($item)
{
if (!$item) {
$item = new \stdClass();
}
$validator = $this->getValidator();
return $validator->validate($item);
} | php | {
"resource": ""
} |
q12996 | Purifier.GetHTMLPurifierConfig | train | private static function GetHTMLPurifierConfig() {
$defaultConfig = \HTMLPurifier_Config::createDefault();
$customConfig = Config::inst()->get('g4b0\HtmlPurifier\Purifier', 'html_purifier_config');
if(is_array($customConfig)) {
foreach ($customConfig as $key => $value) {
$defaultConfig->set($key, $value);
}
}
return $defaultConfig;
} | php | {
"resource": ""
} |
q12997 | Purifier.Purify | train | public static function Purify($html = null, $encoding = 'UTF-8') {
$config = self::GetHTMLPurifierConfig();
$config->set('Core.Encoding', $encoding);
$config->set('HTML.Allowed', 'span,p,br,a,h1,h2,h3,h4,h5,strong,em,u,ul,li,ol,hr,blockquote,sub,sup,p[class],img');
$config->set('HTML.AllowedElements', array('span', 'p', 'br', 'a', 'h1', 'h2', 'h3', 'h4', 'h5', 'strong', 'em', 'u', 'ul', 'li', 'ol', 'hr', 'blockquote', 'sub', 'sup', 'img'));
$config->set('HTML.AllowedAttributes', 'style,target,title,href,class,src,border,alt,width,height,title,name,id');
$config->set('CSS.AllowedProperties', 'text-align,font-weight,text-decoration');
$config->set('AutoFormat.RemoveEmpty', true);
$config->set('Attr.ForbiddenClasses', array('MsoNormal'));
$purifier = new \HTMLPurifier($config);
return $cleanCode = $purifier->purify($html);
} | php | {
"resource": ""
} |
q12998 | Purifier.PurifyXHTML | train | public static function PurifyXHTML($html = null, $encoding = 'UTF-8') {
$config = self::GetHTMLPurifierConfig();
$config->set('Core.Encoding', $encoding);
$config->set('HTML.Doctype', 'XHTML 1.0 Strict');
$config->set('HTML.TidyLevel', 'heavy'); // all changes, minus...
$config->set('CSS.AllowedProperties', array());
$config->set('Attr.AllowedClasses', array());
$config->set('HTML.Allowed', null);
$config->set('AutoFormat.RemoveEmpty', true); // Remove empty tags
$config->set('AutoFormat.Linkify', true); // add <A> to links
$config->set('AutoFormat.AutoParagraph', true);
$config->set('HTML.ForbiddenElements', array('span', 'center'));
$config->set('Core.EscapeNonASCIICharacters', true);
$config->set('Output.TidyFormat', true);
$purifier = new \HTMLPurifier($config);
$html = $purifier->purify($html);
// Rimpiazzo le parentesi quadre
$html = str_ireplace("%5B", "[", $html);
$html = str_ireplace("%5D", "]", $html);
return $html;
} | php | {
"resource": ""
} |
q12999 | Purifier.PurifyTXT | train | public static function PurifyTXT($html = null, $encoding = 'UTF-8') {
$config = self::GetHTMLPurifierConfig();
$config->set('Core.Encoding', $encoding);
$config->set('HTML.Allowed', null); // Allow Nothing
$config->set('HTML.AllowedElements', array());
$purifier = new \HTMLPurifier($config);
return $purifier->purify($html);
} | php | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.