_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q29000
Debug.getCode
train
protected static function getCode($file, $offset, $limit, $pos) { ob_start(); highlight_string(file_get_contents($file)); $code = ob_get_contents(); ob_end_clean(); $code = explode('<br />', $code); $code = array_slice($code, $offset, $limit); if($code) { $r = '<div><span class="toggle"><span>+</span>...
php
{ "resource": "" }
q29001
Debug.getCLIBacktrace
train
public static function getCLIBacktrace($backtrace=null) { if(!$backtrace) $backtrace = debug_backtrace(); $r = ''; $c = count($backtrace); for($i=0; $i<$c; $i++) { $trace = $backtrace[$i]; if(isset($trace['file'])) $r .= $trace['file'].':'.$trace['line']."\n"; } return $r; }
php
{ "resource": "" }
q29002
Debug.getHTMLRequest
train
public static function getHTMLRequest(\Asgard\Http\Request $r) { $res = '<b>Request</b><br>'; $res .= '<div>'; $res .= static::inputs($r, 'get', 'GET'); $res .= static::inputs($r, 'post', 'POST'); $res .= static::inputs($r, 'file', 'FILES'); $res .= static::inputs($r, 'cookie', 'COOKIES'); // $res .= stat...
php
{ "resource": "" }
q29003
Debug.inputs
train
protected static function inputs(\Asgard\Http\Request $r, $input, $name) { if($r->$input->count()) { $res = '<div><span class="toggle"><span>+</span>'.$name.':</span>'; $res .= '<div style="display:none"><ul>'; foreach($r->get->all() as $k=>$v) { $res .= '<li>'.$k.': '; $str = static::var_dump_to_str...
php
{ "resource": "" }
q29004
Debug.var_dump_to_string
train
protected static function var_dump_to_string($var) { if(is_string($var)) return $var; ob_start(); var_dump($var); if(ob_get_length() > 1024) $str = '['.(is_object($var) ? get_class($var):gettype($var)).' - too big to display]'; else $str = ob_get_contents(); ob_end_clean(); return $str; }
php
{ "resource": "" }
q29005
PluginTrait.getData
train
public function getData($namespace = null) { if(!self::$pluginData) { // try to find the model via namespace if (!$namespace) { // if we are in a model if (property_exists($this, 'namespace')) { self::$pluginData = $this; ...
php
{ "resource": "" }
q29006
PluginTrait.config
train
public static function config($namespace) { $configPath = pluginsPath($namespace.'/config.json'); if(file_exists($configPath)) { return json_decode(File::get($configPath)); } throw new \Exception("No config.json file found for plugin ".$configPath); }
php
{ "resource": "" }
q29007
PluginTrait.fullBackendUrl
train
public function fullBackendUrl() { return url(Config::get('project')['adminPrefix'].'/'.App::getLocale()."/plugins/".str_replace("\\", "/", self::config($this->namespace)->baseURL)); }
php
{ "resource": "" }
q29008
PluginTrait.autoloadPlugins
train
public function autoloadPlugins() { foreach(self::activePlugins() as $plugin){ // plugin composer autoload if(File::exists($plugin->basePath().'/vendor/autoload.php')) { include $plugin->basePath() . '/vendor/autoload.php'; } // plugin helpers ...
php
{ "resource": "" }
q29009
PluginTrait.registerPlugins
train
public function registerPlugins() { foreach($this->activePlugins() as $plugin){ $className = $plugin->parseNamespace()."\\Plugin"; if(class_exists($className)) { $pluginInstance = new $className(); if ($plugin->isActive() && method_exists($pluginInstan...
php
{ "resource": "" }
q29010
PluginTrait.bootPlugins
train
public function bootPlugins() { foreach($this->activePlugins() as $plugin){ $className = $plugin->parseNamespace()."\\Plugin"; if(class_exists($className)) { $pluginInstance = new $className(); if ($plugin->isActive() && method_exists($pluginInstance, ...
php
{ "resource": "" }
q29011
PluginTrait.configs
train
public static function configs() { $files = File::allFiles(base_path().'/plugins'); $result = []; foreach ($files as $file){ if($file->getBasename() == "config.json") { $result[] = json_decode(File::get($file->getPathname())); } } retur...
php
{ "resource": "" }
q29012
PluginTrait.isActive
train
public function isActive() { // wee need a namespace first if(!isset($this->namespace)) { return false; } // Plugin is not active is it's not installed if(!self::isInstalled($this->namespace)) { return false; } if(!$this->isActive) { ...
php
{ "resource": "" }
q29013
Serializer.toArrayRaw
train
public function toArrayRaw(Entity $entity, $depth=0) { $res = []; foreach($entity->getDefinition()->properties() as $name=>$property) { if($entity->getDefinition()->property($name) instanceof Property\EntityProperty) { if($depth < 1) $res[$name] = $entity->get($name, null, false); else { if($e...
php
{ "resource": "" }
q29014
Serializer.toArray
train
public function toArray(Entity $entity, $depth=0) { $res = []; foreach($entity->getDefinition()->properties() as $name=>$property) { if($entity->getDefinition()->property($name) instanceof Property\EntityProperty) { if($depth < 1) continue; if($entity->getDefinition()->property($name)->get('many'))...
php
{ "resource": "" }
q29015
Serializer.propertyToArray
train
private function propertyToArray($v, $property) { if(is_null($v)) return null; if(is_string($v) || is_numeric($v) || is_array($v)) return $v; if(method_exists($property, 'toArray')) return $property->toArray($v); elseif(method_exists($property, 'toString')) return $property->toString($v); elseif(i...
php
{ "resource": "" }
q29016
Serializer.toArrayRawI18N
train
public function toArrayRawI18N(Entity $entity, array $locales=[], $depth=0) { if(!$locales) $locales = $entity->getLocales(); $res = []; foreach($entity->getDefinition()->properties() as $name=>$property) { if($property->get('i18n')) { foreach($locales as $locale) { if($entity->getDefinition()->pr...
php
{ "resource": "" }
q29017
Serializer.toArrayI18N
train
public function toArrayI18N(Entity $entity, array $locales=[], $depth=0) { if(!$locales) $locales = $entity->getLocales(); $res = []; foreach($entity->getDefinition()->properties() as $name=>$property) { if($property->get('i18n')) { foreach($locales as $locale) { if($entity->getDefinition()->prope...
php
{ "resource": "" }
q29018
Serializer.toJSONI18N
train
public function toJSONI18N(Entity $entity, array $locales=[], $depth=0) { if(!$locales) $locales = $entity->getLocales(); return json_encode($entity->toArrayI18N($locales, $depth)); }
php
{ "resource": "" }
q29019
Serializer.arrayToJSONI18N
train
public static function arrayToJSONI18N(array $entities, array $locales=[], $depth=0) { foreach($entities as $k=>$entity) $entities[$k] = $entity->toArrayI18N($locales, $depth); return json_encode($entities); }
php
{ "resource": "" }
q29020
Serializer.arrayToJSON
train
public static function arrayToJSON(array $entities, $depth=0) { foreach($entities as $k=>$entity) $entities[$k] = $entity->toArray($depth); return json_encode($entities); }
php
{ "resource": "" }
q29021
CurlProxy.get
train
public function get($url) { $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // grab URL and pass it to the browser ...
php
{ "resource": "" }
q29022
User.setLastLoginTime
train
public function setLastLoginTime(\DateTime $time = null) { if (is_null($time)) { $time = new \DateTime(); } $this->lastLoginTime = $time; }
php
{ "resource": "" }
q29023
DataSource.getDSN
train
public function getDSN () { $dsn = []; // Pick $data_source parameters that make up the DSN string. $map = [ 'host' => 'host', 'port' => 'port', 'dbname' => 'database', 'unix_socket' => 'unix_socket', 'charset' => 'charset' ]; ...
php
{ "resource": "" }
q29024
PostTypeTrait.hasPosts
train
public static function hasPosts($postTypeSlug) { $getPostType = self::findBySlug($postTypeSlug); if($getPostType) { if(DB::table($getPostType['slug'])->count() > 0) { return true; } } return false; }
php
{ "resource": "" }
q29025
PostTypeTrait.isInMenuLinks
train
public static function isInMenuLinks($postTypeID) { $menulinks = MenuLink::where('belongsToID', $postTypeID)->where('belongsTo', 'post_type')->count(); if($menulinks) { return true; } return false; }
php
{ "resource": "" }
q29026
PostTypeTrait.getSlug
train
public static function getSlug($removePrefix = false) { // get it from route $postTypeSlug = \Request::route('postTypeSlug'); if(!$postTypeSlug) { // get it from url $url = explode('/', Request::route()->uri()); if(isset($url[0]) && $url[0]) { ...
php
{ "resource": "" }
q29027
PostTypeTrait.getFields
train
public static function getFields($post_type) { $postType = PostType::all()->where('slug', $post_type)->first(); if($postType) { return $postType->fields; } return []; }
php
{ "resource": "" }
q29028
PostTypeTrait.hasCustomController
train
public function hasCustomController() { $controllerName = ucfirst(str_replace('post_', '', $this->slug)); if(File::exists(Theme::getPath().'/controllers/'.$controllerName.'Controller.php')) { return true; } return false; }
php
{ "resource": "" }
q29029
SyntaxHighlighterStringsProvider.getSyntaxHighlighterStrings
train
public function getSyntaxHighlighterStrings() { $strings = new SyntaxHighlighterStrings(); $strings->setAlert($this->getTranslator()->trans("strings.alert", [], "WBWSyntaxHighlighterBundle", $this->getTranslator()->getLocale())); $strings->setBrushNotHtmlScript($this->getTranslator()->trans("st...
php
{ "resource": "" }
q29030
ArraySearchCondition.getSearchClosure
train
public function getSearchClosure() { $conditions = $this->conditions; $filter = function (NodeInterface $node) use (&$conditions) { foreach ($conditions as $condition) { $field = $condition[SearchConditionInterface::FIELD_POS]; $testValue = null; switch ($field) { case SearchConditi...
php
{ "resource": "" }
q29031
PageAbstractRepository.getRootNodes
train
public function getRootNodes() { $filter = new DoctrineSearchCondition(); $filter->levelEqualsTo(0); $order = new DoctrineSelectOrder(); $order->byLeftAscending(); $rootNodes = $this->nestedSetRepository->search($filter, $order); return $rootNodes; }
php
{ "resource": "" }
q29032
Container.createFacade
train
protected function createFacade($name) { if(preg_match('/^[a-zA-Z_][a-zA-Z0-9_]+$/', $name) && !class_exists(ucfirst($name))) eval('class '.ucfirst($name).' extends \Asgard\Container\Facade {}'); }
php
{ "resource": "" }
q29033
Environment.setEnv
train
public function setEnv($properties) { $envPath = app()->environmentFilePath(); $contents = File::get($envPath); if(!$contents) { throw new \Exception('Could not read env file'); } foreach($properties as $key => $value){ // Env value must be set so th...
php
{ "resource": "" }
q29034
TagsSubjectTrait.addTag
train
public function addTag(TagInterface $tag) { if (!$this->tags->contains($tag)) { $this->tags->add($tag); } return $this; }
php
{ "resource": "" }
q29035
TagsSubjectTrait.removeTag
train
public function removeTag(TagInterface $tag) { if ($this->tags->contains($tag)) { $this->tags->removeElement($tag); } return $this; }
php
{ "resource": "" }
q29036
EntityForm.getPropertyField
train
protected function getPropertyField(\Asgard\Entity\Entity $entity, $name, \Asgard\Entity\Property $property, $locale=null) { $field = $this->getentityFieldSolver()->solve($property); if($field instanceof \Asgard\Form\DynamicGroup) { $field->setCallback(function() use($entity, $name, $property, $locale) { ...
php
{ "resource": "" }
q29037
EntityForm.getEntityFieldOptions
train
protected function getEntityFieldOptions(\Asgard\Entity\Property $property) { $options = $property->getFormParameters(); $options['form'] = $this; return $options; }
php
{ "resource": "" }
q29038
EntityForm.getDefaultValue
train
protected function getDefaultValue(\Asgard\Entity\Entity $entity, $name, $property, $locale) { if($entity->get($name, $locale) !== null) return $entity->get($name, $locale); }
php
{ "resource": "" }
q29039
EntityForm.myErrors
train
protected function myErrors($validationGroups=[]) { $data = $this->data(); $data = array_filter($data, function($v) { if($v instanceof \Asgard\Http\HttpFile && $v->error()) return false; return $v !== null; }); #callback to edit data before passing them to entity if($cb = $this->preEntityS...
php
{ "resource": "" }
q29040
GnAdminApi.DelSubCommunity
train
public function DelSubCommunity(string $tag = NULL) { if (GnUtil::IsNullOrEmpty($tag)) { throw new \InvalidArgumentException("tag required"); } $this->ExecuteCall("DelSubCommunity", (object)[ "tag" => $tag ], GnResponseType::Json, FALSE, PHP_INT_MAX); }
php
{ "resource": "" }
q29041
GnAdminApi.UpdateCommunityWeb
train
public function UpdateCommunityWeb(string $tag = NULL, array $hosts = [], string $mashupTokenCallbackUrl = NULL) { if (GnUtil::IsNullOrEmpty($tag)) { throw new \InvalidArgumentException("tag required"); } $this->ExecuteCall("UpdateCommunityWeb", (object)[ "tag" => $t...
php
{ "resource": "" }
q29042
MinistryPlatformBaseAPI.authenticate
train
public function authenticate($grantType = 'client_credentials') { if ($grantType == 'client_credentials') { $cc = new oAuthClientCredentials; $this->authorization = $cc->clientCredentials(); } elseif ($grantType = 'authorization_code') { // Authentication has alre...
php
{ "resource": "" }
q29043
MinistryPlatformBaseAPI.sendData
train
protected function sendData($verb, $parameters) { // Set the endpoint $endpoint = $this->buildEndpoint(); // Set the header $this->buildHttpHeader(); // Send the request $client = new Client(); //GuzzleHttp\Client $error = true; try { $...
php
{ "resource": "" }
q29044
MinistryPlatformBaseAPI.setGetCurlopts
train
protected function setGetCurlopts() { $curlopts = [ CURLOPT_HTTPHEADER => $this->headers, CURLOPT_POST => 0, CURLOPT_HEADER => 0, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_VERBOSE => false, CURLOPT_RETURNTRANSFER => true ]; ...
php
{ "resource": "" }
q29045
MinistryPlatformBaseAPI.setPostCurlopts
train
protected function setPostCurlopts() { $curlopts = [ CURLOPT_HTTPHEADER => $this->headers, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $this->postFields, CURLOPT_HEADER => 0, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_VERBOSE => false, ...
php
{ "resource": "" }
q29046
CUrl.createRelative
train
public function createRelative($uri = null) { if (empty($uri)) { // Empty uri means baseurl return $this->baseUrl; } elseif (substr($uri, 0, 7) == "http://" || substr($uri, 0, 8) == "https://" || substr($uri, 0, 2) == "//" ) { // Fu...
php
{ "resource": "" }
q29047
CUrl.asset
train
public function asset($uri = null) { if (empty($uri)) { // Allow empty } elseif (substr($uri, 0, 7) == "http://" || substr($uri, 0, 8) == "https://" || substr($uri, 0, 2) == "//" ) { // Fully qualified, just leave as is. return rtri...
php
{ "resource": "" }
q29048
CUrl.setUrlType
train
public function setUrlType($type) { if (!in_array($type, [self::URL_APPEND, self::URL_CLEAN])) { throw new \Exception("Unsupported Url type."); } $this->urlType = $type; return $this; }
php
{ "resource": "" }
q29049
Filter.validateNested
train
private function validateNested(array $errors): array { foreach ($this->getFields(false) as $index => $value) { if (isset($errors[$index])) { //Invalid on parent level continue; } if ($value instanceof FilterInterface && !$value->isValid()...
php
{ "resource": "" }
q29050
MediaLibraryController.moveAction
train
public function moveAction(Request $request) { $repository = $this->container->getDoctrine()->getManager()->getRepository(FileAbstraction::CN()); /* @var $repository FileNestedSetRepository */ $repository->getNestedSetRepository()->lock(); $file = $this->getEntity(); $parentId = $request->get('parent_id');...
php
{ "resource": "" }
q29051
MediaLibraryController.saveAction
train
public function saveAction(Request $request) { $file = $this->getEntity(); // set private if ($request->request->has('private')) { $private = $request->request->get('private'); if ($private == 0) { $this->getFileStorage()->setPublic($file); } if ($private == 1) { $this->getFileStorage()->s...
php
{ "resource": "" }
q29052
MediaLibraryController.viewAction
train
public function viewAction() { $node = $this->getFile(); $nodeOutput = $this->imageAndFileOutput($node); $output = array($nodeOutput); $return = array( 'totalRecords' => count($output), 'records' => $output, ); return new SupraJsonResponse($return); }
php
{ "resource": "" }
q29053
MediaLibraryController.insertAction
train
public function insertAction(Request $request) { $manager = $this->container->getDoctrine()->getManager(); $repository = $manager->getRepository(FileAbstraction::CN()); /* @var $repository FileNestedSetRepository */ $repository->getNestedSetRepository()->lock(); $manager->beginTransaction(); try { if (...
php
{ "resource": "" }
q29054
MediaLibraryController.deleteAction
train
public function deleteAction() { $repository = $this->container->getDoctrine()->getManager()->getRepository(FileAbstraction::CN()); /* @var $repository FileNestedSetRepository */ $repository->getNestedSetRepository()->lock(); $file = $this->getEntity(); $this->checkActionPermission($file, FileAbstraction::...
php
{ "resource": "" }
q29055
MediaLibraryController.listAction
train
public function listAction(Request $request) { $rootNodes = array(); $repo = $this->container->getDoctrine() ->getManager()->getRepository('Supra\Package\Cms\Entity\Abstraction\File'); $output = array(); // if parent dir is set then we set folder as rootNode if ($request->query->get('id')) { $node =...
php
{ "resource": "" }
q29056
MediaLibraryController.getEntityType
train
protected function getEntityType(FileAbstraction $entity) { $type = null; if ($entity instanceof Folder) { $type = self::TYPE_FOLDER; } elseif ($entity instanceof Image) { $type = self::TYPE_IMAGE; } elseif ($entity instanceof File) { $type = self::TYPE_FILE; } return $type; }
php
{ "resource": "" }
q29057
SolutionSchema.registerSchema
train
public static function registerSchema($schemaName, $schemaClass) { self::$schemaClasses[$schemaName] = $schemaClass; // Invalidate the caches self::$modelClassesCache = null; self::$modelNamesCache = null; self::$relationshipCache = null; }
php
{ "resource": "" }
q29058
SolutionSchema.getModel
train
public static function getModel($modelName, $uniqueIdentifier = null) { $class = self::getModelClass($modelName); $model = new $class($uniqueIdentifier); return $model; }
php
{ "resource": "" }
q29059
SolutionSchema.getAllSchemas
train
public static function getAllSchemas() { foreach (self::$schemaClasses as $schemaName => $schemaClass) { self::getSchema($schemaName); } return self::$schemas; }
php
{ "resource": "" }
q29060
SolutionSchema.getAllRelationshipsForModel
train
public static function getAllRelationshipsForModel($modelClassName) { $modelClassName = self::getModelClass($modelClassName); if (!isset(self::$relationshipCache[$modelClassName])) { $schemas = self::getAllSchemas(); $relationships = []; foreach ($schemas as $sc...
php
{ "resource": "" }
q29061
SolutionSchema.getAllOneToOneRelationshipsForModelBySourceColumnName
train
public static function getAllOneToOneRelationshipsForModelBySourceColumnName($modelClassName) { $relationships = self::getAllRelationshipsForModel($modelClassName); $columnRelationships = []; foreach ($relationships as $relationship) { if ($relationship instanceof OneToOne) { ...
php
{ "resource": "" }
q29062
SolutionSchema.getModelClass
train
public static function getModelClass($name) { // If the name contains a backslash it is already fully qualified. However in some cases // a model might be replaced by a new class and so we must first look to see if this model is // mapped and if so return it's replacement instead. if...
php
{ "resource": "" }
q29063
SolutionSchema.declareOneToManyRelationships
train
public function declareOneToManyRelationships($relationships) { if (!is_array($relationships)) { throw new RelationshipDefinitionException("DefineOneToManyRelationships must be passed an array"); } foreach ($relationships as $oneModel => $definitions) { $oneModelColu...
php
{ "resource": "" }
q29064
SolutionSchema.declareOneToOneRelationship
train
protected function declareOneToOneRelationship( $sourceModelName, $targetModelName, $sourceColumnName, $targetColumnName, $navigationPropertyName = "" ) { $oneToOne = new OneToOne( $navigationPropertyName, $sourceModelName, $source...
php
{ "resource": "" }
q29065
SolutionSchema.declareOneToManyRelationship
train
protected function declareOneToManyRelationship( $oneModelName, $oneColumnName, $oneNavigationName, $manyModelName, $manyColumnName = "", $manyNavigationName = "" ) { $oneToMany = new OneToMany($oneNavigationName, $oneModelName, $oneColumnName, $manyModelName...
php
{ "resource": "" }
q29066
SolutionSchema.getRelationship
train
public function getRelationship($modelName, $navigationName) { $modelName = $this->getModelClass($modelName); if (!isset($this->relationships[$modelName])) { return null; } if (!isset($this->relationships[$modelName][$navigationName])) { return null; ...
php
{ "resource": "" }
q29067
SolutionSchema.checkModelSchemas
train
public function checkModelSchemas($oldVersion = null) { Model::clearAllRepositories(); /** * @var Model $class */ /** * @var Model $object */ foreach ($this->models as $class) { $object = new $class(); $repository = $objec...
php
{ "resource": "" }
q29068
CmsExtension.renderTitle
train
public function renderTitle($tag = 'h1', $content = null) { if (null === $content && null !== $page = $this->getPage()) { $content = $page->getTitle(); // Tags the response as Page relative $this->tagManager->addTags($page->getEntityTag()); } if (0 == st...
php
{ "resource": "" }
q29069
CmsExtension.renderMenu
train
public function renderMenu($name, array $options = [], $renderer = null) { if (null === $menu = $this->menuProvider->findByName($name)) { throw new \InvalidArgumentException(sprintf('Menu named "%s" not found.', $name)); } // Tags the response as Menu relative $this->tag...
php
{ "resource": "" }
q29070
CmsExtension.renderLocaleSwitcher
train
public function renderLocaleSwitcher(\Twig_Environment $twig, array $options = []) { if (!$this->localeSwitcher->hasResource()) { $this->localeSwitcher->setResource($this->getPage()); } $options = array_replace([ 'dropdown' => true, 'tag' => 'div', ...
php
{ "resource": "" }
q29071
CmsExtension.getPageControllerTitle
train
public function getPageControllerTitle($name) { if (!array_key_exists($name, $this->config['page']['controllers'])) { throw new \InvalidArgumentException(sprintf('Undefined controller "%s".', $name)); } return $this->config['page']['controllers'][$name]['title']; }
php
{ "resource": "" }
q29072
CmsExtension.renderTag
train
private function renderTag($tag, $content = null, array $attributes = []) { $attr = []; foreach ($attributes as $key => $value) { $attr[] = sprintf(' %s="%s"', $key, $value); } if (0 < strlen($content)) { return sprintf('<%s%s>%s</%s>', $tag, implode('', $at...
php
{ "resource": "" }
q29073
MySqlCursor.filterModelsByIdentifier
train
public function filterModelsByIdentifier($uniqueIdentifiers) { $this->filteredIds = array_merge($this->filteredIds, $uniqueIdentifiers); $this->filteredCount = count($this->filteredIds); }
php
{ "resource": "" }
q29074
MySqlCursor.processHydration
train
private function processHydration(&$row) { if (!count($this->hydrationMappings)){ return; } $primaryFields = []; $rawData = []; foreach($row as $key => $value){ if (isset($this->hydrationMappings[$key])){ unset($row[$key]); ...
php
{ "resource": "" }
q29075
MediaExtension.renderImage
train
public function renderImage(MediaInterface $image, array $columns, array $attr = []) { if (!$image->getType() === MediaTypes::IMAGE) { throw new InvalidArgumentException("Expected 'image' media type."); } $map = []; $col = 12; foreach (array_reverse(Bootstrap3Ada...
php
{ "resource": "" }
q29076
Tabs.setsTabs
train
public function setsTabs($tabs) { if (is_array($tabs)) { $tabs = new ArrayCollection($tabs); } if (!$tabs instanceof ArrayCollection) { throw new \UnexpectedValueException("Expected array or instance of " . ArrayCollection::class); } $this->tabs = $ta...
php
{ "resource": "" }
q29077
Tabs.hasButton
train
public function hasButton() { if (!empty($this->getButtonLabel())) { return true; } foreach ($this->tabs as $tab) { if (!empty($tab->getButtonLabel())) { return true; } } return false; }
php
{ "resource": "" }
q29078
Tabs.isAnchorMode
train
public function isAnchorMode() { foreach ($this->tabs as $tab) { if (!empty($tab->getAnchor())) { return true; } } return false; }
php
{ "resource": "" }
q29079
type.toBoolean
train
static function toBoolean ($v) { return is_string ($v) ? get (self::$BOOLEAN_VALUES, $v, false) : boolval ($v); }
php
{ "resource": "" }
q29080
type.validate
train
static function validate ($type, $v) { if (is_null ($v) || $v === '') return true; switch ($type) { case type::binding: return is_string ($v); case type::any: case type::bool: // Any value can be typecast to boolean. return true; case type::data: retur...
php
{ "resource": "" }
q29081
PluginInstall.canInstall
train
private function canInstall() { $this->info("Validating"); // Exists as a directory if(!file_exists(pluginsPath($this->pluginNamespace))) { throw new \Exception("Plugin ".$this->pluginNamespace." not found in plugins directory!"); } // Remove composer autoloader...
php
{ "resource": "" }
q29082
PluginInstall.cleanTmp
train
private function cleanTmp() { $directories = File::directories(tmpPath()); foreach($directories as $directory){ File::deleteDirectory($directory); } return $this; }
php
{ "resource": "" }
q29083
PluginInstall.readConfigFile
train
private function readConfigFile() { // Check config.json exists $this->info("Reading config"); // look for config in main directory if(file_exists($this->tmpDirectory.'/config.json')) { $this->configContent = json_decode(File::get($this->tmpDirectory.'/config.json')); ...
php
{ "resource": "" }
q29084
PluginInstall.getZip
train
private function getZip() { $this->info("Downloading"); $sourceContent = file_get_contents($this->argument('source')); if(!$sourceContent) { throw new \Exception('Source could not be found!'); } $this->tmpRandomName = time(); $this->tmpZipFile = tmpPath(...
php
{ "resource": "" }
q29085
PluginInstall.extractZip
train
private function extractZip() { $this->info("Extracting"); $this->tmpDirectory = tmpPath($this->tmpRandomName); // extract Zipper::make($this->tmpZipFile)->extractTo($this->tmpDirectory); // delete zip file File::delete($this->tmpZipFile); // zip creates a ...
php
{ "resource": "" }
q29086
PluginInstall.addPluginInDB
train
private function addPluginInDB() { $configContent = Plugin::config($this->pluginNamespace); $plugin = new Plugin(); $plugin->title = $configContent->title; $plugin->namespace = $configContent->namespace; $plugin->organization = $configContent->organization; $plugin->...
php
{ "resource": "" }
q29087
MarkdownTwigExtension.markdownFilter
train
public function markdownFilter($input, $parserName = 'default') { $parser = $this->parserCollection->getParser($parserName); return $parser->parse($input); }
php
{ "resource": "" }
q29088
BaseMediaController.store
train
public function store(Request $request) { // check if user has permissions to access this link if(!User::hasAccess('Media', 'create')) { return $this->noPermission(); } return (new Media())->upload($request); }
php
{ "resource": "" }
q29089
BaseMediaController.getList
train
public function getList($lang, $pagination) { // check if user has permissions to access this link if(!User::hasAccess('Media', 'read')) { return $this->noPermission(); } $list = Pagination::infiniteScrollPagination('media', $pagination, Media::$infinitPaginationShow); ...
php
{ "resource": "" }
q29090
BaseMediaController.edit
train
public function edit(Request $request) { // check if user has permissions to access this link if(!User::hasAccess('Media', 'update')) { return $this->noPermission(); } $media = Media::find($request->mediaID); $media->title = $request->title; $media->descri...
php
{ "resource": "" }
q29091
BaseMediaController.delete
train
public function delete(Request $request) { $isOk = "OK"; // loop throw file array foreach ($request->all() as $key => $file){ if ($key === "postTypes") { continue; } // check if user has permissions to access this link if(!User...
php
{ "resource": "" }
q29092
BaseMediaController.getWatermak
train
private function getWatermak() { // Verify watermark $watermarkMediaID = settings("watermark"); if(!$watermarkMediaID) { return $this->response("No watermark is available. Go to settings and set a watermark", 500); } $watermarImage = Media::find($watermarkMediaID...
php
{ "resource": "" }
q29093
BaseMediaController.assignWatermark
train
public function assignWatermark(Request $request) { $getWatermak = $this->getWatermak(); if(!$getWatermak) { return $getWatermak; } // go through each select image foreach ($request->all() as $key => $file){ $image = new Media($file); //...
php
{ "resource": "" }
q29094
BaseMediaController.cropImage
train
public function cropImage(Request $request) { // check if user has permissions to access this link if(!User::hasAccess('Media', 'update')) { return $this->noPermission(); } // get all inputs $inputs = $request->all(); // Where is this file beeing croped ...
php
{ "resource": "" }
q29095
FluentFunction.method
train
public function method($methodName, $arg1/*, $arg2, $arg3, ...*/) { $args = array_slice(func_get_args(), 1); return $this->func(function($object) use ($methodName, $args) { return call_user_func_array([$object, $methodName], $args); }); }
php
{ "resource": "" }
q29096
GnUtility.GetQueryStringFromKeyVals
train
public static function GetQueryStringFromKeyVals(string $url, array $keyVals) { if ($url == NULL) { throw new \InvalidArgumentException('url'); } if ($keyVals == NULL) { throw new \InvalidArgumentException('keyVals'); } $anchorIndex = strpos($url, '#...
php
{ "resource": "" }
q29097
NodeConfigurator.afterNodeCreate
train
public function afterNodeCreate(NodeInterface $node) { if (!($nodeType = $node->getNodeType())) { return; } // array with [beforeNodes, childNodes, afterNodes] keys $config = $this->getAssistanceConfigForNodeType($nodeType->getName()); switch ($nodeType->getName(...
php
{ "resource": "" }
q29098
NodeConfigurator.setNodeProperties
train
protected function setNodeProperties(NodeInterface $node, array $properties, array $args = []) { foreach ($properties as $property => $value) { $value = count($args) && is_string($value) ? vsprintf($value, $args) : $value; $node->setProperty($property, $value); } }
php
{ "resource": "" }
q29099
NodeConfigurator.configureImage
train
protected function configureImage(NodeInterface $node, NodeType $nodeType, array $config = []) { $this->configureCreateAssistanceChildNodes($node, $nodeType, $config); switch ($node->getParent()->getNodeType()->getName()) { // Image slider: enable caption by default case 'M1...
php
{ "resource": "" }