id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
13,700
csun-metalab/laravel-directory-authentication
src/Authentication/MetaUser.php
MetaUser.stopMasquerading
public function stopMasquerading() { if($this->isMasquerading()) { // become the real user again Auth::logout(); Auth::login(session('masquerading_user')); session(['masquerading_user' => null]); // success! return true; } return false; }
php
public function stopMasquerading() { if($this->isMasquerading()) { // become the real user again Auth::logout(); Auth::login(session('masquerading_user')); session(['masquerading_user' => null]); // success! return true; } return false; }
[ "public", "function", "stopMasquerading", "(", ")", "{", "if", "(", "$", "this", "->", "isMasquerading", "(", ")", ")", "{", "// become the real user again", "Auth", "::", "logout", "(", ")", ";", "Auth", "::", "login", "(", "session", "(", "'masquerading_user'", ")", ")", ";", "session", "(", "[", "'masquerading_user'", "=>", "null", "]", ")", ";", "// success!", "return", "true", ";", "}", "return", "false", ";", "}" ]
Stops masquerading as another user if we are currently masquerading. Returns true on success or false otherwise. @return boolean
[ "Stops", "masquerading", "as", "another", "user", "if", "we", "are", "currently", "masquerading", ".", "Returns", "true", "on", "success", "or", "false", "otherwise", "." ]
b8d4fa64dd646566e508cdf838d6a3d03b1d53ea
https://github.com/csun-metalab/laravel-directory-authentication/blob/b8d4fa64dd646566e508cdf838d6a3d03b1d53ea/src/Authentication/MetaUser.php#L150-L162
13,701
cpliakas/search-framework
src/Search/Framework/Indexer.php
Indexer.newCollector
public function newCollector() { $collector = new Collector($this->getDispatcher()); // Pass services and settings to collector. $collector ->setCollections($this->_collections) ->setLogger($this->getLogger()) ->setQueue($this->getQueue()) ->setTimeout($this->_timeout) ->setLimit($this->_limit); return $collector; }
php
public function newCollector() { $collector = new Collector($this->getDispatcher()); // Pass services and settings to collector. $collector ->setCollections($this->_collections) ->setLogger($this->getLogger()) ->setQueue($this->getQueue()) ->setTimeout($this->_timeout) ->setLimit($this->_limit); return $collector; }
[ "public", "function", "newCollector", "(", ")", "{", "$", "collector", "=", "new", "Collector", "(", "$", "this", "->", "getDispatcher", "(", ")", ")", ";", "// Pass services and settings to collector.", "$", "collector", "->", "setCollections", "(", "$", "this", "->", "_collections", ")", "->", "setLogger", "(", "$", "this", "->", "getLogger", "(", ")", ")", "->", "setQueue", "(", "$", "this", "->", "getQueue", "(", ")", ")", "->", "setTimeout", "(", "$", "this", "->", "_timeout", ")", "->", "setLimit", "(", "$", "this", "->", "_limit", ")", ";", "return", "$", "collector", ";", "}" ]
Returns a Collector object that the Indexer class injects itself as a service into. @return Collector
[ "Returns", "a", "Collector", "object", "that", "the", "Indexer", "class", "injects", "itself", "as", "a", "service", "into", "." ]
7c5832d38ed998e04837c26e0daef59115563b98
https://github.com/cpliakas/search-framework/blob/7c5832d38ed998e04837c26e0daef59115563b98/src/Search/Framework/Indexer.php#L87-L100
13,702
cpliakas/search-framework
src/Search/Framework/Indexer.php
Indexer.normalizeField
public function normalizeField(IndexField $field) { $id = $field->getId(); $value = $field->getValue(); $log = $this->getLogger(); $context = array('field' => $id); if (isset($this->_fieldTypes[$id])) { if ($this->_searchEngine->hasNormalizer($this->_fieldTypes[$id])) { $normalizer = $this->_searchEngine->getNormalizer($this->_fieldTypes[$id]); $context['normalizer'] = get_class($normalizer); $value = $normalizer->normalize($value); $log->debug('Normalizer applied to field', $context); } } else { $log->debug('Data type could not be determined for field', $context); } return $value; }
php
public function normalizeField(IndexField $field) { $id = $field->getId(); $value = $field->getValue(); $log = $this->getLogger(); $context = array('field' => $id); if (isset($this->_fieldTypes[$id])) { if ($this->_searchEngine->hasNormalizer($this->_fieldTypes[$id])) { $normalizer = $this->_searchEngine->getNormalizer($this->_fieldTypes[$id]); $context['normalizer'] = get_class($normalizer); $value = $normalizer->normalize($value); $log->debug('Normalizer applied to field', $context); } } else { $log->debug('Data type could not be determined for field', $context); } return $value; }
[ "public", "function", "normalizeField", "(", "IndexField", "$", "field", ")", "{", "$", "id", "=", "$", "field", "->", "getId", "(", ")", ";", "$", "value", "=", "$", "field", "->", "getValue", "(", ")", ";", "$", "log", "=", "$", "this", "->", "getLogger", "(", ")", ";", "$", "context", "=", "array", "(", "'field'", "=>", "$", "id", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "_fieldTypes", "[", "$", "id", "]", ")", ")", "{", "if", "(", "$", "this", "->", "_searchEngine", "->", "hasNormalizer", "(", "$", "this", "->", "_fieldTypes", "[", "$", "id", "]", ")", ")", "{", "$", "normalizer", "=", "$", "this", "->", "_searchEngine", "->", "getNormalizer", "(", "$", "this", "->", "_fieldTypes", "[", "$", "id", "]", ")", ";", "$", "context", "[", "'normalizer'", "]", "=", "get_class", "(", "$", "normalizer", ")", ";", "$", "value", "=", "$", "normalizer", "->", "normalize", "(", "$", "value", ")", ";", "$", "log", "->", "debug", "(", "'Normalizer applied to field'", ",", "$", "context", ")", ";", "}", "}", "else", "{", "$", "log", "->", "debug", "(", "'Data type could not be determined for field'", ",", "$", "context", ")", ";", "}", "return", "$", "value", ";", "}" ]
Apply the serivce specific normalizers to a field's value. @param IndexField $field The field being normalized. @return string|array
[ "Apply", "the", "serivce", "specific", "normalizers", "to", "a", "field", "s", "value", "." ]
7c5832d38ed998e04837c26e0daef59115563b98
https://github.com/cpliakas/search-framework/blob/7c5832d38ed998e04837c26e0daef59115563b98/src/Search/Framework/Indexer.php#L110-L130
13,703
cpliakas/search-framework
src/Search/Framework/Indexer.php
Indexer.indexQueuedItems
public function indexQueuedItems() { $dispatcher = $this->getDispatcher(); $log = $this->getLogger(); $context = array('engine' => get_class($this->_searchEngine)); $log->info('Indexing operation started', $context); try { // Ensure the schema object is populated. This routine will also // throw the SearchEvents::SCHEMA_ALTER event as well as detect // incompatible schemata. $this->getSchema(); // Adds the search engine instance as a subscriber only for the // duration of this indexing process. $dispatcher->addSubscriber($this->_searchEngine); $event = new SearchEngineEvent($this); $this->dispatchEvent(SearchEvents::SEARCH_ENGINE_PRE_INDEX, $event); // Consume messages from the queue that correspond with items that // are scheduled for indexing. $consumer = new QueueConsumer($this); foreach ($consumer as $message) { $context['item'] = $message->getBody(); $log->debug('Consumed item scheduled for indexing from queue', $context); $this->indexQueuedItem($message); } unset($context['item']); // The item is no longer in context. $this->dispatchEvent(SearchEvents::SEARCH_ENGINE_POST_INDEX, $event); // The search engine should only listen to events throws during it's // own indexing operation. $dispatcher->removeSubscriber($this->_searchEngine); } catch (Exception $e) { // Make sure this service is removed as a subscriber. See above. $dispatcher->removeSubscriber($this->_searchEngine); throw $e; } $context['indexed'] = count($consumer); $log->info('Indexing operation completed', $context); }
php
public function indexQueuedItems() { $dispatcher = $this->getDispatcher(); $log = $this->getLogger(); $context = array('engine' => get_class($this->_searchEngine)); $log->info('Indexing operation started', $context); try { // Ensure the schema object is populated. This routine will also // throw the SearchEvents::SCHEMA_ALTER event as well as detect // incompatible schemata. $this->getSchema(); // Adds the search engine instance as a subscriber only for the // duration of this indexing process. $dispatcher->addSubscriber($this->_searchEngine); $event = new SearchEngineEvent($this); $this->dispatchEvent(SearchEvents::SEARCH_ENGINE_PRE_INDEX, $event); // Consume messages from the queue that correspond with items that // are scheduled for indexing. $consumer = new QueueConsumer($this); foreach ($consumer as $message) { $context['item'] = $message->getBody(); $log->debug('Consumed item scheduled for indexing from queue', $context); $this->indexQueuedItem($message); } unset($context['item']); // The item is no longer in context. $this->dispatchEvent(SearchEvents::SEARCH_ENGINE_POST_INDEX, $event); // The search engine should only listen to events throws during it's // own indexing operation. $dispatcher->removeSubscriber($this->_searchEngine); } catch (Exception $e) { // Make sure this service is removed as a subscriber. See above. $dispatcher->removeSubscriber($this->_searchEngine); throw $e; } $context['indexed'] = count($consumer); $log->info('Indexing operation completed', $context); }
[ "public", "function", "indexQueuedItems", "(", ")", "{", "$", "dispatcher", "=", "$", "this", "->", "getDispatcher", "(", ")", ";", "$", "log", "=", "$", "this", "->", "getLogger", "(", ")", ";", "$", "context", "=", "array", "(", "'engine'", "=>", "get_class", "(", "$", "this", "->", "_searchEngine", ")", ")", ";", "$", "log", "->", "info", "(", "'Indexing operation started'", ",", "$", "context", ")", ";", "try", "{", "// Ensure the schema object is populated. This routine will also", "// throw the SearchEvents::SCHEMA_ALTER event as well as detect", "// incompatible schemata.", "$", "this", "->", "getSchema", "(", ")", ";", "// Adds the search engine instance as a subscriber only for the", "// duration of this indexing process.", "$", "dispatcher", "->", "addSubscriber", "(", "$", "this", "->", "_searchEngine", ")", ";", "$", "event", "=", "new", "SearchEngineEvent", "(", "$", "this", ")", ";", "$", "this", "->", "dispatchEvent", "(", "SearchEvents", "::", "SEARCH_ENGINE_PRE_INDEX", ",", "$", "event", ")", ";", "// Consume messages from the queue that correspond with items that", "// are scheduled for indexing.", "$", "consumer", "=", "new", "QueueConsumer", "(", "$", "this", ")", ";", "foreach", "(", "$", "consumer", "as", "$", "message", ")", "{", "$", "context", "[", "'item'", "]", "=", "$", "message", "->", "getBody", "(", ")", ";", "$", "log", "->", "debug", "(", "'Consumed item scheduled for indexing from queue'", ",", "$", "context", ")", ";", "$", "this", "->", "indexQueuedItem", "(", "$", "message", ")", ";", "}", "unset", "(", "$", "context", "[", "'item'", "]", ")", ";", "// The item is no longer in context.", "$", "this", "->", "dispatchEvent", "(", "SearchEvents", "::", "SEARCH_ENGINE_POST_INDEX", ",", "$", "event", ")", ";", "// The search engine should only listen to events throws during it's", "// own indexing operation.", "$", "dispatcher", "->", "removeSubscriber", "(", "$", "this", "->", "_searchEngine", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "// Make sure this service is removed as a subscriber. See above.", "$", "dispatcher", "->", "removeSubscriber", "(", "$", "this", "->", "_searchEngine", ")", ";", "throw", "$", "e", ";", "}", "$", "context", "[", "'indexed'", "]", "=", "count", "(", "$", "consumer", ")", ";", "$", "log", "->", "info", "(", "'Indexing operation completed'", ",", "$", "context", ")", ";", "}" ]
Indexes the items that are queued for indexing into the search engine.
[ "Indexes", "the", "items", "that", "are", "queued", "for", "indexing", "into", "the", "search", "engine", "." ]
7c5832d38ed998e04837c26e0daef59115563b98
https://github.com/cpliakas/search-framework/blob/7c5832d38ed998e04837c26e0daef59115563b98/src/Search/Framework/Indexer.php#L156-L202
13,704
cpliakas/search-framework
src/Search/Framework/Indexer.php
Indexer.indexQueuedItem
public function indexQueuedItem(QueueMessage $message) { $log = $this->getLogger(); $context = array( 'engine' => get_class($this->_searchEngine), 'item' => $message->getBody(), ); // Load the source data form the message. The message usually contains a // unique identifier in the body. Skip processing if false is returned // as the source data. $collection = $message->getCollection(); $data = $collection->loadSourceData($message); if ($data) { $context['collection'] = $collection->getId(); $log->debug('Data fetched from source', $context); // Build an index document from the source data. $document = $this->_searchEngine->newDocument($this); $collection->buildDocument($document, $data); $log->debug('Document prepared for indexing', $context); // Index the document, sandwich indexing with events. $event = new IndexDocumentEvent($this, $document, $data); $this->dispatchEvent(SearchEvents::DOCUMENT_PRE_INDEX, $event); $this->_searchEngine->indexDocument($collection, $document); $this->dispatchEvent(SearchEvents::DOCUMENT_POST_INDEX, $event); $log->debug('Document processed for indexing', $context); } else { $log->critical('Data could not be loaded from source', $context); } }
php
public function indexQueuedItem(QueueMessage $message) { $log = $this->getLogger(); $context = array( 'engine' => get_class($this->_searchEngine), 'item' => $message->getBody(), ); // Load the source data form the message. The message usually contains a // unique identifier in the body. Skip processing if false is returned // as the source data. $collection = $message->getCollection(); $data = $collection->loadSourceData($message); if ($data) { $context['collection'] = $collection->getId(); $log->debug('Data fetched from source', $context); // Build an index document from the source data. $document = $this->_searchEngine->newDocument($this); $collection->buildDocument($document, $data); $log->debug('Document prepared for indexing', $context); // Index the document, sandwich indexing with events. $event = new IndexDocumentEvent($this, $document, $data); $this->dispatchEvent(SearchEvents::DOCUMENT_PRE_INDEX, $event); $this->_searchEngine->indexDocument($collection, $document); $this->dispatchEvent(SearchEvents::DOCUMENT_POST_INDEX, $event); $log->debug('Document processed for indexing', $context); } else { $log->critical('Data could not be loaded from source', $context); } }
[ "public", "function", "indexQueuedItem", "(", "QueueMessage", "$", "message", ")", "{", "$", "log", "=", "$", "this", "->", "getLogger", "(", ")", ";", "$", "context", "=", "array", "(", "'engine'", "=>", "get_class", "(", "$", "this", "->", "_searchEngine", ")", ",", "'item'", "=>", "$", "message", "->", "getBody", "(", ")", ",", ")", ";", "// Load the source data form the message. The message usually contains a", "// unique identifier in the body. Skip processing if false is returned", "// as the source data.", "$", "collection", "=", "$", "message", "->", "getCollection", "(", ")", ";", "$", "data", "=", "$", "collection", "->", "loadSourceData", "(", "$", "message", ")", ";", "if", "(", "$", "data", ")", "{", "$", "context", "[", "'collection'", "]", "=", "$", "collection", "->", "getId", "(", ")", ";", "$", "log", "->", "debug", "(", "'Data fetched from source'", ",", "$", "context", ")", ";", "// Build an index document from the source data.", "$", "document", "=", "$", "this", "->", "_searchEngine", "->", "newDocument", "(", "$", "this", ")", ";", "$", "collection", "->", "buildDocument", "(", "$", "document", ",", "$", "data", ")", ";", "$", "log", "->", "debug", "(", "'Document prepared for indexing'", ",", "$", "context", ")", ";", "// Index the document, sandwich indexing with events.", "$", "event", "=", "new", "IndexDocumentEvent", "(", "$", "this", ",", "$", "document", ",", "$", "data", ")", ";", "$", "this", "->", "dispatchEvent", "(", "SearchEvents", "::", "DOCUMENT_PRE_INDEX", ",", "$", "event", ")", ";", "$", "this", "->", "_searchEngine", "->", "indexDocument", "(", "$", "collection", ",", "$", "document", ")", ";", "$", "this", "->", "dispatchEvent", "(", "SearchEvents", "::", "DOCUMENT_POST_INDEX", ",", "$", "event", ")", ";", "$", "log", "->", "debug", "(", "'Document processed for indexing'", ",", "$", "context", ")", ";", "}", "else", "{", "$", "log", "->", "critical", "(", "'Data could not be loaded from source'", ",", "$", "context", ")", ";", "}", "}" ]
Indexes an item that is queued for indexing into the search engine.
[ "Indexes", "an", "item", "that", "is", "queued", "for", "indexing", "into", "the", "search", "engine", "." ]
7c5832d38ed998e04837c26e0daef59115563b98
https://github.com/cpliakas/search-framework/blob/7c5832d38ed998e04837c26e0daef59115563b98/src/Search/Framework/Indexer.php#L207-L241
13,705
todstoychev/icr
src/Manager/FileManager.php
FileManager.generate
public function generate(FilesystemAdapter $filesystemAdapter, $extension, $path = null) { $hash = sha1(time() + microtime()); $exists = $filesystemAdapter->exists($path . '/' . $hash . '.' . $extension); if ($exists) { $this->generate($filesystemAdapter, $extension, $path); } return $hash; }
php
public function generate(FilesystemAdapter $filesystemAdapter, $extension, $path = null) { $hash = sha1(time() + microtime()); $exists = $filesystemAdapter->exists($path . '/' . $hash . '.' . $extension); if ($exists) { $this->generate($filesystemAdapter, $extension, $path); } return $hash; }
[ "public", "function", "generate", "(", "FilesystemAdapter", "$", "filesystemAdapter", ",", "$", "extension", ",", "$", "path", "=", "null", ")", "{", "$", "hash", "=", "sha1", "(", "time", "(", ")", "+", "microtime", "(", ")", ")", ";", "$", "exists", "=", "$", "filesystemAdapter", "->", "exists", "(", "$", "path", ".", "'/'", ".", "$", "hash", ".", "'.'", ".", "$", "extension", ")", ";", "if", "(", "$", "exists", ")", "{", "$", "this", "->", "generate", "(", "$", "filesystemAdapter", ",", "$", "extension", ",", "$", "path", ")", ";", "}", "return", "$", "hash", ";", "}" ]
Generates unique filename @param FilesystemAdapter $filesystemAdapter @param string $extension File extension @param null|string $path Directory path @return string
[ "Generates", "unique", "filename" ]
0214c7bc76e44488e98758d55deb707b72e24000
https://github.com/todstoychev/icr/blob/0214c7bc76e44488e98758d55deb707b72e24000/src/Manager/FileManager.php#L99-L110
13,706
dphn/ScContent
src/ScContent/Listener/Theme/AbstractThemeStrategy.php
AbstractThemeStrategy.injectContentTemplate
protected function injectContentTemplate(MvcEvent $event) { $model = $event->getResult(); if (! $model instanceof ViewModel) { return $this; } if ($model->getTemplate()) { return $this; } $routeMatch = $event->getRouteMatch(); $themeName = $this->getThemeName(); $themeOptions = $this->getThemeOptions(); $options = []; if (isset($themeOptions[static::$side])) { $options = $themeOptions[static::$side]; } if (isset($options['templates'])) { $templatesPath = rtrim($options['templates'], '/') . '/'; } else { $templatesPath = str_replace( ['{theme}', '{side}'], [$themeName, static::$side], self::DefaultTemplatesPath ); } $controller = $event->getTarget(); if ($controller) { $controller = get_class($controller); } else { $controller = $routeMatch->getParam('controller', ''); } $controller = $this->deriveControllerClass($controller); $template = $templatesPath . $this->inflectName($controller); $action = $routeMatch->getParam('action'); if (null !== $action) { $template .= '/' . $this->inflectName($action); } $model->setTemplate($template); return $this; }
php
protected function injectContentTemplate(MvcEvent $event) { $model = $event->getResult(); if (! $model instanceof ViewModel) { return $this; } if ($model->getTemplate()) { return $this; } $routeMatch = $event->getRouteMatch(); $themeName = $this->getThemeName(); $themeOptions = $this->getThemeOptions(); $options = []; if (isset($themeOptions[static::$side])) { $options = $themeOptions[static::$side]; } if (isset($options['templates'])) { $templatesPath = rtrim($options['templates'], '/') . '/'; } else { $templatesPath = str_replace( ['{theme}', '{side}'], [$themeName, static::$side], self::DefaultTemplatesPath ); } $controller = $event->getTarget(); if ($controller) { $controller = get_class($controller); } else { $controller = $routeMatch->getParam('controller', ''); } $controller = $this->deriveControllerClass($controller); $template = $templatesPath . $this->inflectName($controller); $action = $routeMatch->getParam('action'); if (null !== $action) { $template .= '/' . $this->inflectName($action); } $model->setTemplate($template); return $this; }
[ "protected", "function", "injectContentTemplate", "(", "MvcEvent", "$", "event", ")", "{", "$", "model", "=", "$", "event", "->", "getResult", "(", ")", ";", "if", "(", "!", "$", "model", "instanceof", "ViewModel", ")", "{", "return", "$", "this", ";", "}", "if", "(", "$", "model", "->", "getTemplate", "(", ")", ")", "{", "return", "$", "this", ";", "}", "$", "routeMatch", "=", "$", "event", "->", "getRouteMatch", "(", ")", ";", "$", "themeName", "=", "$", "this", "->", "getThemeName", "(", ")", ";", "$", "themeOptions", "=", "$", "this", "->", "getThemeOptions", "(", ")", ";", "$", "options", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "themeOptions", "[", "static", "::", "$", "side", "]", ")", ")", "{", "$", "options", "=", "$", "themeOptions", "[", "static", "::", "$", "side", "]", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'templates'", "]", ")", ")", "{", "$", "templatesPath", "=", "rtrim", "(", "$", "options", "[", "'templates'", "]", ",", "'/'", ")", ".", "'/'", ";", "}", "else", "{", "$", "templatesPath", "=", "str_replace", "(", "[", "'{theme}'", ",", "'{side}'", "]", ",", "[", "$", "themeName", ",", "static", "::", "$", "side", "]", ",", "self", "::", "DefaultTemplatesPath", ")", ";", "}", "$", "controller", "=", "$", "event", "->", "getTarget", "(", ")", ";", "if", "(", "$", "controller", ")", "{", "$", "controller", "=", "get_class", "(", "$", "controller", ")", ";", "}", "else", "{", "$", "controller", "=", "$", "routeMatch", "->", "getParam", "(", "'controller'", ",", "''", ")", ";", "}", "$", "controller", "=", "$", "this", "->", "deriveControllerClass", "(", "$", "controller", ")", ";", "$", "template", "=", "$", "templatesPath", ".", "$", "this", "->", "inflectName", "(", "$", "controller", ")", ";", "$", "action", "=", "$", "routeMatch", "->", "getParam", "(", "'action'", ")", ";", "if", "(", "null", "!==", "$", "action", ")", "{", "$", "template", ".=", "'/'", ".", "$", "this", "->", "inflectName", "(", "$", "action", ")", ";", "}", "$", "model", "->", "setTemplate", "(", "$", "template", ")", ";", "return", "$", "this", ";", "}" ]
Inject a template into the content view model, if none present @param \Zend\Mvc\MvcEvent @return AbstractThemeStrategy
[ "Inject", "a", "template", "into", "the", "content", "view", "model", "if", "none", "present" ]
9dd5732490c45fd788b96cedf7b3c7adfacb30d2
https://github.com/dphn/ScContent/blob/9dd5732490c45fd788b96cedf7b3c7adfacb30d2/src/ScContent/Listener/Theme/AbstractThemeStrategy.php#L119-L166
13,707
dphn/ScContent
src/ScContent/Listener/Theme/AbstractThemeStrategy.php
AbstractThemeStrategy.injectLayoutTemplate
protected function injectLayoutTemplate(MvcEvent $event) { $model = $event->getResult(); if (! $model instanceof ViewModel) { return $this; } if ($model->terminate()) { return $this; } $viewManager = $this->getViewManager(); $renderer = $viewManager->getRenderer(); $themeName = $this->getThemeName(); $themeOptions = $this->getThemeOptions(); $options = []; if (isset($themeOptions[static::$side])) { $options = $themeOptions[static::$side]; } if (isset($options['layouts'])) { $layoutsPath = rtrim($options['layouts'], '/') . '/'; } else { $layoutsPath = str_replace( ['{theme}', '{side}'], [$themeName, static::$side], self::DefaultLayoutsPath ); } $layout = $event->getViewModel(); if ($layout && 'layout/layout' !== $layout->getTemplate()) { $layout->setTemplate( str_replace('{layouts}', $layoutsPath, $layout->getTemplate()) ); return $this; } $defaultLayout = self::DefaultLayout; if(isset($options['default_layout'])) { $defaultLayout = $options['default_layout']; } $renderer->layout()->setTemplate($layoutsPath . $defaultLayout); return $this; }
php
protected function injectLayoutTemplate(MvcEvent $event) { $model = $event->getResult(); if (! $model instanceof ViewModel) { return $this; } if ($model->terminate()) { return $this; } $viewManager = $this->getViewManager(); $renderer = $viewManager->getRenderer(); $themeName = $this->getThemeName(); $themeOptions = $this->getThemeOptions(); $options = []; if (isset($themeOptions[static::$side])) { $options = $themeOptions[static::$side]; } if (isset($options['layouts'])) { $layoutsPath = rtrim($options['layouts'], '/') . '/'; } else { $layoutsPath = str_replace( ['{theme}', '{side}'], [$themeName, static::$side], self::DefaultLayoutsPath ); } $layout = $event->getViewModel(); if ($layout && 'layout/layout' !== $layout->getTemplate()) { $layout->setTemplate( str_replace('{layouts}', $layoutsPath, $layout->getTemplate()) ); return $this; } $defaultLayout = self::DefaultLayout; if(isset($options['default_layout'])) { $defaultLayout = $options['default_layout']; } $renderer->layout()->setTemplate($layoutsPath . $defaultLayout); return $this; }
[ "protected", "function", "injectLayoutTemplate", "(", "MvcEvent", "$", "event", ")", "{", "$", "model", "=", "$", "event", "->", "getResult", "(", ")", ";", "if", "(", "!", "$", "model", "instanceof", "ViewModel", ")", "{", "return", "$", "this", ";", "}", "if", "(", "$", "model", "->", "terminate", "(", ")", ")", "{", "return", "$", "this", ";", "}", "$", "viewManager", "=", "$", "this", "->", "getViewManager", "(", ")", ";", "$", "renderer", "=", "$", "viewManager", "->", "getRenderer", "(", ")", ";", "$", "themeName", "=", "$", "this", "->", "getThemeName", "(", ")", ";", "$", "themeOptions", "=", "$", "this", "->", "getThemeOptions", "(", ")", ";", "$", "options", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "themeOptions", "[", "static", "::", "$", "side", "]", ")", ")", "{", "$", "options", "=", "$", "themeOptions", "[", "static", "::", "$", "side", "]", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'layouts'", "]", ")", ")", "{", "$", "layoutsPath", "=", "rtrim", "(", "$", "options", "[", "'layouts'", "]", ",", "'/'", ")", ".", "'/'", ";", "}", "else", "{", "$", "layoutsPath", "=", "str_replace", "(", "[", "'{theme}'", ",", "'{side}'", "]", ",", "[", "$", "themeName", ",", "static", "::", "$", "side", "]", ",", "self", "::", "DefaultLayoutsPath", ")", ";", "}", "$", "layout", "=", "$", "event", "->", "getViewModel", "(", ")", ";", "if", "(", "$", "layout", "&&", "'layout/layout'", "!==", "$", "layout", "->", "getTemplate", "(", ")", ")", "{", "$", "layout", "->", "setTemplate", "(", "str_replace", "(", "'{layouts}'", ",", "$", "layoutsPath", ",", "$", "layout", "->", "getTemplate", "(", ")", ")", ")", ";", "return", "$", "this", ";", "}", "$", "defaultLayout", "=", "self", "::", "DefaultLayout", ";", "if", "(", "isset", "(", "$", "options", "[", "'default_layout'", "]", ")", ")", "{", "$", "defaultLayout", "=", "$", "options", "[", "'default_layout'", "]", ";", "}", "$", "renderer", "->", "layout", "(", ")", "->", "setTemplate", "(", "$", "layoutsPath", ".", "$", "defaultLayout", ")", ";", "return", "$", "this", ";", "}" ]
Inject a template into the layout view model, if none present @param \Zend\Mvc\MvcEvent @return AbstractThemeStrategy
[ "Inject", "a", "template", "into", "the", "layout", "view", "model", "if", "none", "present" ]
9dd5732490c45fd788b96cedf7b3c7adfacb30d2
https://github.com/dphn/ScContent/blob/9dd5732490c45fd788b96cedf7b3c7adfacb30d2/src/ScContent/Listener/Theme/AbstractThemeStrategy.php#L174-L221
13,708
kriskbx/mikado
src/Formatters/Formatter.php
Formatter.formatAble
protected function formatAble(&$object) { if (!is_object($object) || is_array($object)) { throw new InvalidArgumentException('The given argument is not an object/array.'); } if (!is_object($object) && $object instanceof FormatAble) { return; } $object = new FormatAbleObject(clone($object)); }
php
protected function formatAble(&$object) { if (!is_object($object) || is_array($object)) { throw new InvalidArgumentException('The given argument is not an object/array.'); } if (!is_object($object) && $object instanceof FormatAble) { return; } $object = new FormatAbleObject(clone($object)); }
[ "protected", "function", "formatAble", "(", "&", "$", "object", ")", "{", "if", "(", "!", "is_object", "(", "$", "object", ")", "||", "is_array", "(", "$", "object", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'The given argument is not an object/array.'", ")", ";", "}", "if", "(", "!", "is_object", "(", "$", "object", ")", "&&", "$", "object", "instanceof", "FormatAble", ")", "{", "return", ";", "}", "$", "object", "=", "new", "FormatAbleObject", "(", "clone", "(", "$", "object", ")", ")", ";", "}" ]
Make an object formatAble. @param object|array $object @return object
[ "Make", "an", "object", "formatAble", "." ]
f00e566d682a66796f3f8a68b348920fadd9ee87
https://github.com/kriskbx/mikado/blob/f00e566d682a66796f3f8a68b348920fadd9ee87/src/Formatters/Formatter.php#L22-L33
13,709
kriskbx/mikado
src/Formatters/Formatter.php
Formatter.regex
public function regex($array = []) { $filtered = []; foreach ($array as $key => $value) { if ($this->isRegex($key)) { $filtered[$key] = $value; } } return $filtered; }
php
public function regex($array = []) { $filtered = []; foreach ($array as $key => $value) { if ($this->isRegex($key)) { $filtered[$key] = $value; } } return $filtered; }
[ "public", "function", "regex", "(", "$", "array", "=", "[", "]", ")", "{", "$", "filtered", "=", "[", "]", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "this", "->", "isRegex", "(", "$", "key", ")", ")", "{", "$", "filtered", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "filtered", ";", "}" ]
Filter an array where the key is a regex string. @param array $array @return array
[ "Filter", "an", "array", "where", "the", "key", "is", "a", "regex", "string", "." ]
f00e566d682a66796f3f8a68b348920fadd9ee87
https://github.com/kriskbx/mikado/blob/f00e566d682a66796f3f8a68b348920fadd9ee87/src/Formatters/Formatter.php#L42-L52
13,710
kriskbx/mikado
src/Formatters/Formatter.php
Formatter.getRegexProperty
protected function getRegexProperty($matches, $value) { foreach ($matches as $index => $match) { if (is_numeric($index) && $index != 0) { $value = str_replace('$'.$index, $match, $value); } } return $value; }
php
protected function getRegexProperty($matches, $value) { foreach ($matches as $index => $match) { if (is_numeric($index) && $index != 0) { $value = str_replace('$'.$index, $match, $value); } } return $value; }
[ "protected", "function", "getRegexProperty", "(", "$", "matches", ",", "$", "value", ")", "{", "foreach", "(", "$", "matches", "as", "$", "index", "=>", "$", "match", ")", "{", "if", "(", "is_numeric", "(", "$", "index", ")", "&&", "$", "index", "!=", "0", ")", "{", "$", "value", "=", "str_replace", "(", "'$'", ".", "$", "index", ",", "$", "match", ",", "$", "value", ")", ";", "}", "}", "return", "$", "value", ";", "}" ]
Get regex property. @param array $matches @param string $value @return string
[ "Get", "regex", "property", "." ]
f00e566d682a66796f3f8a68b348920fadd9ee87
https://github.com/kriskbx/mikado/blob/f00e566d682a66796f3f8a68b348920fadd9ee87/src/Formatters/Formatter.php#L80-L89
13,711
kriskbx/mikado
src/Formatters/Formatter.php
Formatter.pregMatchArray
protected function pregMatchArray($input, $rules, $flags = 0) { if (!is_array($rules)) { return false; } foreach ($rules as $rule => $value) { if (preg_match($rule, $input, $matches, $flags)) { return array_merge($matches, ['value' => $value]); } } return false; }
php
protected function pregMatchArray($input, $rules, $flags = 0) { if (!is_array($rules)) { return false; } foreach ($rules as $rule => $value) { if (preg_match($rule, $input, $matches, $flags)) { return array_merge($matches, ['value' => $value]); } } return false; }
[ "protected", "function", "pregMatchArray", "(", "$", "input", ",", "$", "rules", ",", "$", "flags", "=", "0", ")", "{", "if", "(", "!", "is_array", "(", "$", "rules", ")", ")", "{", "return", "false", ";", "}", "foreach", "(", "$", "rules", "as", "$", "rule", "=>", "$", "value", ")", "{", "if", "(", "preg_match", "(", "$", "rule", ",", "$", "input", ",", "$", "matches", ",", "$", "flags", ")", ")", "{", "return", "array_merge", "(", "$", "matches", ",", "[", "'value'", "=>", "$", "value", "]", ")", ";", "}", "}", "return", "false", ";", "}" ]
Applies the regular expressions stored in the keys of the given array to the given input string. Returns the first match including the matching value. @param string $input @param array $rules @param int $flags @return array|bool
[ "Applies", "the", "regular", "expressions", "stored", "in", "the", "keys", "of", "the", "given", "array", "to", "the", "given", "input", "string", ".", "Returns", "the", "first", "match", "including", "the", "matching", "value", "." ]
f00e566d682a66796f3f8a68b348920fadd9ee87
https://github.com/kriskbx/mikado/blob/f00e566d682a66796f3f8a68b348920fadd9ee87/src/Formatters/Formatter.php#L101-L114
13,712
cpliakas/search-framework
src/Search/Framework/IndexDocument.php
IndexDocument.addField
public function addField($id, $value, $name = null) { $field = $this->_service->newField($id, $value, $name); return $this->attachField($field); }
php
public function addField($id, $value, $name = null) { $field = $this->_service->newField($id, $value, $name); return $this->attachField($field); }
[ "public", "function", "addField", "(", "$", "id", ",", "$", "value", ",", "$", "name", "=", "null", ")", "{", "$", "field", "=", "$", "this", "->", "_service", "->", "newField", "(", "$", "id", ",", "$", "value", ",", "$", "name", ")", ";", "return", "$", "this", "->", "attachField", "(", "$", "field", ")", ";", "}" ]
Instantiates and attaches a field to this document. @return IndexField @see SearchServiceAbstract::newField()
[ "Instantiates", "and", "attaches", "a", "field", "to", "this", "document", "." ]
7c5832d38ed998e04837c26e0daef59115563b98
https://github.com/cpliakas/search-framework/blob/7c5832d38ed998e04837c26e0daef59115563b98/src/Search/Framework/IndexDocument.php#L80-L84
13,713
cpliakas/search-framework
src/Search/Framework/IndexDocument.php
IndexDocument.attachField
public function attachField(IndexField $field) { // Enrich the field here, agent will probably do this. // Throw the SearchEvents::FIELD_ENRICH event, reset the field's value // with the enriched value. // $event = new SearchFieldEvent($this->_service, $this, $field); // $this->_dispatcher->dispatch(SearchEvents::FIELD_ENRICH, $event); // $field->setValue($event->getValue()); $id = $field->getId(); $this->_fields[$id] = $field; return $this; }
php
public function attachField(IndexField $field) { // Enrich the field here, agent will probably do this. // Throw the SearchEvents::FIELD_ENRICH event, reset the field's value // with the enriched value. // $event = new SearchFieldEvent($this->_service, $this, $field); // $this->_dispatcher->dispatch(SearchEvents::FIELD_ENRICH, $event); // $field->setValue($event->getValue()); $id = $field->getId(); $this->_fields[$id] = $field; return $this; }
[ "public", "function", "attachField", "(", "IndexField", "$", "field", ")", "{", "// Enrich the field here, agent will probably do this.", "// Throw the SearchEvents::FIELD_ENRICH event, reset the field's value", "// with the enriched value.", "// $event = new SearchFieldEvent($this->_service, $this, $field);", "// $this->_dispatcher->dispatch(SearchEvents::FIELD_ENRICH, $event);", "// $field->setValue($event->getValue());", "$", "id", "=", "$", "field", "->", "getId", "(", ")", ";", "$", "this", "->", "_fields", "[", "$", "id", "]", "=", "$", "field", ";", "return", "$", "this", ";", "}" ]
Adds a field to the document. This method throws the SearchEvents::FIELD_ENRICH event and stores the enriched value as the field's value. @param IndexField $field The field being added to this document. @return SearchIndexDocument
[ "Adds", "a", "field", "to", "the", "document", "." ]
7c5832d38ed998e04837c26e0daef59115563b98
https://github.com/cpliakas/search-framework/blob/7c5832d38ed998e04837c26e0daef59115563b98/src/Search/Framework/IndexDocument.php#L97-L111
13,714
cpliakas/search-framework
src/Search/Framework/IndexDocument.php
IndexDocument.getField
public function getField($id) { if (!isset($this->_fields[$id])) { $this->$id = ''; // @see SearchIndexDocument::__set() } return $this->_fields[$id]; }
php
public function getField($id) { if (!isset($this->_fields[$id])) { $this->$id = ''; // @see SearchIndexDocument::__set() } return $this->_fields[$id]; }
[ "public", "function", "getField", "(", "$", "id", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_fields", "[", "$", "id", "]", ")", ")", "{", "$", "this", "->", "$", "id", "=", "''", ";", "// @see SearchIndexDocument::__set()", "}", "return", "$", "this", "->", "_fields", "[", "$", "id", "]", ";", "}" ]
Returns a field that is attached to this document. If the field is not attached to this document, a field is attached with an empty string as it's value. @param string $id The unique identifier of the field. @return IndexField
[ "Returns", "a", "field", "that", "is", "attached", "to", "this", "document", "." ]
7c5832d38ed998e04837c26e0daef59115563b98
https://github.com/cpliakas/search-framework/blob/7c5832d38ed998e04837c26e0daef59115563b98/src/Search/Framework/IndexDocument.php#L124-L130
13,715
fuelphp/filesystem
src/Handler.php
Handler.setPermissions
public function setPermissions($permissions) { if (is_string($permissions)) { $permissions = '0'.ltrim($permissions, '0'); $permissions = octdec($permissions); } return chmod($this->path, $permissions); }
php
public function setPermissions($permissions) { if (is_string($permissions)) { $permissions = '0'.ltrim($permissions, '0'); $permissions = octdec($permissions); } return chmod($this->path, $permissions); }
[ "public", "function", "setPermissions", "(", "$", "permissions", ")", "{", "if", "(", "is_string", "(", "$", "permissions", ")", ")", "{", "$", "permissions", "=", "'0'", ".", "ltrim", "(", "$", "permissions", ",", "'0'", ")", ";", "$", "permissions", "=", "octdec", "(", "$", "permissions", ")", ";", "}", "return", "chmod", "(", "$", "this", "->", "path", ",", "$", "permissions", ")", ";", "}" ]
Sets the permissions @return boolean
[ "Sets", "the", "permissions" ]
770a8cb04caca920af8029d7aad7208bc0592743
https://github.com/fuelphp/filesystem/blob/770a8cb04caca920af8029d7aad7208bc0592743/src/Handler.php#L168-L177
13,716
chadicus/test-helpers
src/FunctionRegistry.php
FunctionRegistry.reset
public static function reset($namespace = null, array $extensions = array()) { self::$functions = array(); foreach ($extensions as $extension) { foreach (\get_extension_funcs($extension) as $name) { self::evaluate($namespace, $name); } } }
php
public static function reset($namespace = null, array $extensions = array()) { self::$functions = array(); foreach ($extensions as $extension) { foreach (\get_extension_funcs($extension) as $name) { self::evaluate($namespace, $name); } } }
[ "public", "static", "function", "reset", "(", "$", "namespace", "=", "null", ",", "array", "$", "extensions", "=", "array", "(", ")", ")", "{", "self", "::", "$", "functions", "=", "array", "(", ")", ";", "foreach", "(", "$", "extensions", "as", "$", "extension", ")", "{", "foreach", "(", "\\", "get_extension_funcs", "(", "$", "extension", ")", "as", "$", "name", ")", "{", "self", "::", "evaluate", "(", "$", "namespace", ",", "$", "name", ")", ";", "}", "}", "}" ]
Sets all custom function properties to null. @param string $namespace The namespace from which the global function will be called. @param array $extensions Array of PHP extensions whose functions will be mocked. @return void
[ "Sets", "all", "custom", "function", "properties", "to", "null", "." ]
e6718f5b62e0f1e0851ad2cd344e44a1fdb0b9bf
https://github.com/chadicus/test-helpers/blob/e6718f5b62e0f1e0851ad2cd344e44a1fdb0b9bf/src/FunctionRegistry.php#L56-L64
13,717
CloudObjects/RDFUtilities
Parser.php
Parser.parseToIndex
public static function parseToIndex($input) { if (($input[0] == '{' || $input[0] == '[')) { return Arc2JsonLdConverter::jsonLdToIndex($input); } else { $parser = \ARC2::getRDFParser(); $parser->parse('', $input); return $parser->getSimpleIndex(false); } }
php
public static function parseToIndex($input) { if (($input[0] == '{' || $input[0] == '[')) { return Arc2JsonLdConverter::jsonLdToIndex($input); } else { $parser = \ARC2::getRDFParser(); $parser->parse('', $input); return $parser->getSimpleIndex(false); } }
[ "public", "static", "function", "parseToIndex", "(", "$", "input", ")", "{", "if", "(", "(", "$", "input", "[", "0", "]", "==", "'{'", "||", "$", "input", "[", "0", "]", "==", "'['", ")", ")", "{", "return", "Arc2JsonLdConverter", "::", "jsonLdToIndex", "(", "$", "input", ")", ";", "}", "else", "{", "$", "parser", "=", "\\", "ARC2", "::", "getRDFParser", "(", ")", ";", "$", "parser", "->", "parse", "(", "''", ",", "$", "input", ")", ";", "return", "$", "parser", "->", "getSimpleIndex", "(", "false", ")", ";", "}", "}" ]
Parses the given input and returns an ARC2 index. If the input is JsonLD the JsonLD parser is used, otherwise ARC2 is used. @param string $input
[ "Parses", "the", "given", "input", "and", "returns", "an", "ARC2", "index", ".", "If", "the", "input", "is", "JsonLD", "the", "JsonLD", "parser", "is", "used", "otherwise", "ARC2", "is", "used", "." ]
cd086981557352073b18b9e2fec1d99cfaacd285
https://github.com/CloudObjects/RDFUtilities/blob/cd086981557352073b18b9e2fec1d99cfaacd285/Parser.php#L17-L25
13,718
terdia/legato-framework
src/View/Twig.php
Twig.getExtensions
protected function getExtensions() { if (file_exists(realpath(__DIR__.'/../../../../../config/twig.php'))) { $this->config = require realpath(__DIR__.'/../../../../../config/twig.php'); } else { $this->config = require realpath(__DIR__.'/../../config/twig.php'); } return isset($this->config['extensions']) ? $this->config['extensions'] : []; }
php
protected function getExtensions() { if (file_exists(realpath(__DIR__.'/../../../../../config/twig.php'))) { $this->config = require realpath(__DIR__.'/../../../../../config/twig.php'); } else { $this->config = require realpath(__DIR__.'/../../config/twig.php'); } return isset($this->config['extensions']) ? $this->config['extensions'] : []; }
[ "protected", "function", "getExtensions", "(", ")", "{", "if", "(", "file_exists", "(", "realpath", "(", "__DIR__", ".", "'/../../../../../config/twig.php'", ")", ")", ")", "{", "$", "this", "->", "config", "=", "require", "realpath", "(", "__DIR__", ".", "'/../../../../../config/twig.php'", ")", ";", "}", "else", "{", "$", "this", "->", "config", "=", "require", "realpath", "(", "__DIR__", ".", "'/../../config/twig.php'", ")", ";", "}", "return", "isset", "(", "$", "this", "->", "config", "[", "'extensions'", "]", ")", "?", "$", "this", "->", "config", "[", "'extensions'", "]", ":", "[", "]", ";", "}" ]
Get extensions defined by application developer. @return array
[ "Get", "extensions", "defined", "by", "application", "developer", "." ]
44057c1c3c6f3e9643e9fade51bd417860fafda8
https://github.com/terdia/legato-framework/blob/44057c1c3c6f3e9643e9fade51bd417860fafda8/src/View/Twig.php#L54-L63
13,719
terdia/legato-framework
src/View/Twig.php
Twig.registerExtension
private function registerExtension(\Twig_Environment $twig) { $extensions = $this->getExtensions(); if (count($extensions)) { foreach ($extensions as $key => $extension) { $this->load($twig, $key, $extension); } } }
php
private function registerExtension(\Twig_Environment $twig) { $extensions = $this->getExtensions(); if (count($extensions)) { foreach ($extensions as $key => $extension) { $this->load($twig, $key, $extension); } } }
[ "private", "function", "registerExtension", "(", "\\", "Twig_Environment", "$", "twig", ")", "{", "$", "extensions", "=", "$", "this", "->", "getExtensions", "(", ")", ";", "if", "(", "count", "(", "$", "extensions", ")", ")", "{", "foreach", "(", "$", "extensions", "as", "$", "key", "=>", "$", "extension", ")", "{", "$", "this", "->", "load", "(", "$", "twig", ",", "$", "key", ",", "$", "extension", ")", ";", "}", "}", "}" ]
Register twig extensions. @param \Twig_Environment $twig
[ "Register", "twig", "extensions", "." ]
44057c1c3c6f3e9643e9fade51bd417860fafda8
https://github.com/terdia/legato-framework/blob/44057c1c3c6f3e9643e9fade51bd417860fafda8/src/View/Twig.php#L70-L78
13,720
Im0rtality/Underscore
src/Functions.php
Functions.once
public static function once($function) { $called = false; $value = null; return function () use ($function, &$called, &$value) { if (!$called) { $args = func_get_args(); $value = call_user_func_array($function, $args); $called = true; } return $value; }; }
php
public static function once($function) { $called = false; $value = null; return function () use ($function, &$called, &$value) { if (!$called) { $args = func_get_args(); $value = call_user_func_array($function, $args); $called = true; } return $value; }; }
[ "public", "static", "function", "once", "(", "$", "function", ")", "{", "$", "called", "=", "false", ";", "$", "value", "=", "null", ";", "return", "function", "(", ")", "use", "(", "$", "function", ",", "&", "$", "called", ",", "&", "$", "value", ")", "{", "if", "(", "!", "$", "called", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "value", "=", "call_user_func_array", "(", "$", "function", ",", "$", "args", ")", ";", "$", "called", "=", "true", ";", "}", "return", "$", "value", ";", "}", ";", "}" ]
Creates a version of the function that can only be called one time. Repeated calls to the modified function will have no effect, returning the value from the original call. Useful for initialization functions, instead of having to set a boolean flag and then check it later. @param callable $function @return \Closure
[ "Creates", "a", "version", "of", "the", "function", "that", "can", "only", "be", "called", "one", "time", "." ]
2deb95cfd340761d00ecd0f033e67ce600f2b535
https://github.com/Im0rtality/Underscore/blob/2deb95cfd340761d00ecd0f033e67ce600f2b535/src/Functions.php#L53-L67
13,721
Im0rtality/Underscore
src/Functions.php
Functions.partial
public static function partial($function, $arg) { $bound = func_get_args(); array_shift($bound); // remove $function $placeholder = static::p(); return function () use ($function, $bound, $placeholder) { $inject = func_get_args(); $args = []; foreach ($bound as $value) { if ($value === $placeholder) { $args[] = array_shift($inject); } else { $args[] = $value; } } // Append any remaining arguments $args = array_merge($args, $inject); return call_user_func_array($function, $args); }; }
php
public static function partial($function, $arg) { $bound = func_get_args(); array_shift($bound); // remove $function $placeholder = static::p(); return function () use ($function, $bound, $placeholder) { $inject = func_get_args(); $args = []; foreach ($bound as $value) { if ($value === $placeholder) { $args[] = array_shift($inject); } else { $args[] = $value; } } // Append any remaining arguments $args = array_merge($args, $inject); return call_user_func_array($function, $args); }; }
[ "public", "static", "function", "partial", "(", "$", "function", ",", "$", "arg", ")", "{", "$", "bound", "=", "func_get_args", "(", ")", ";", "array_shift", "(", "$", "bound", ")", ";", "// remove $function", "$", "placeholder", "=", "static", "::", "p", "(", ")", ";", "return", "function", "(", ")", "use", "(", "$", "function", ",", "$", "bound", ",", "$", "placeholder", ")", "{", "$", "inject", "=", "func_get_args", "(", ")", ";", "$", "args", "=", "[", "]", ";", "foreach", "(", "$", "bound", "as", "$", "value", ")", "{", "if", "(", "$", "value", "===", "$", "placeholder", ")", "{", "$", "args", "[", "]", "=", "array_shift", "(", "$", "inject", ")", ";", "}", "else", "{", "$", "args", "[", "]", "=", "$", "value", ";", "}", "}", "// Append any remaining arguments", "$", "args", "=", "array_merge", "(", "$", "args", ",", "$", "inject", ")", ";", "return", "call_user_func_array", "(", "$", "function", ",", "$", "args", ")", ";", "}", ";", "}" ]
Partially apply a function by filling in any number of its arguments. You may pass p() in your list of arguments to specify an argument that should not be pre-filled, but left open to supply at call-time. @param callable $function @param mixed $arg @param mixed ... @return \Closure
[ "Partially", "apply", "a", "function", "by", "filling", "in", "any", "number", "of", "its", "arguments", "." ]
2deb95cfd340761d00ecd0f033e67ce600f2b535
https://github.com/Im0rtality/Underscore/blob/2deb95cfd340761d00ecd0f033e67ce600f2b535/src/Functions.php#L97-L121
13,722
Im0rtality/Underscore
src/Functions.php
Functions.wrap
public static function wrap($function, $wrapper) { return function () use ($function, $wrapper) { $args = func_get_args(); array_unshift($args, $function); // make $function the first argument return call_user_func_array($wrapper, $args); }; }
php
public static function wrap($function, $wrapper) { return function () use ($function, $wrapper) { $args = func_get_args(); array_unshift($args, $function); // make $function the first argument return call_user_func_array($wrapper, $args); }; }
[ "public", "static", "function", "wrap", "(", "$", "function", ",", "$", "wrapper", ")", "{", "return", "function", "(", ")", "use", "(", "$", "function", ",", "$", "wrapper", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "array_unshift", "(", "$", "args", ",", "$", "function", ")", ";", "// make $function the first argument", "return", "call_user_func_array", "(", "$", "wrapper", ",", "$", "args", ")", ";", "}", ";", "}" ]
Wraps the first function inside of the wrapper function, passing it as the first argument. This allows the wrapper to execute code before and after the function runs, adjust the arguments, and execute it conditionally. @param callable $function @param callable $wrapper @return \Closure
[ "Wraps", "the", "first", "function", "inside", "of", "the", "wrapper", "function", "passing", "it", "as", "the", "first", "argument", "." ]
2deb95cfd340761d00ecd0f033e67ce600f2b535
https://github.com/Im0rtality/Underscore/blob/2deb95cfd340761d00ecd0f033e67ce600f2b535/src/Functions.php#L156-L163
13,723
Im0rtality/Underscore
src/Functions.php
Functions.throttle
public static function throttle($function, $wait, array $options = []) { $options += [ 'leading' => true, ]; // @codeCoverageIgnore $previous = 0; $callback = function () use ($function, $wait, &$previous) { $now = floor(microtime(true) * 1000); // convert float to integer if (($wait - ($now - $previous)) <= 0) { $args = func_get_args(); call_user_func_array($function, $args); $previous = $now; } }; if ($options['leading'] !== false) { $callback(); } return $callback; }
php
public static function throttle($function, $wait, array $options = []) { $options += [ 'leading' => true, ]; // @codeCoverageIgnore $previous = 0; $callback = function () use ($function, $wait, &$previous) { $now = floor(microtime(true) * 1000); // convert float to integer if (($wait - ($now - $previous)) <= 0) { $args = func_get_args(); call_user_func_array($function, $args); $previous = $now; } }; if ($options['leading'] !== false) { $callback(); } return $callback; }
[ "public", "static", "function", "throttle", "(", "$", "function", ",", "$", "wait", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "+=", "[", "'leading'", "=>", "true", ",", "]", ";", "// @codeCoverageIgnore", "$", "previous", "=", "0", ";", "$", "callback", "=", "function", "(", ")", "use", "(", "$", "function", ",", "$", "wait", ",", "&", "$", "previous", ")", "{", "$", "now", "=", "floor", "(", "microtime", "(", "true", ")", "*", "1000", ")", ";", "// convert float to integer", "if", "(", "(", "$", "wait", "-", "(", "$", "now", "-", "$", "previous", ")", ")", "<=", "0", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "call_user_func_array", "(", "$", "function", ",", "$", "args", ")", ";", "$", "previous", "=", "$", "now", ";", "}", "}", ";", "if", "(", "$", "options", "[", "'leading'", "]", "!==", "false", ")", "{", "$", "callback", "(", ")", ";", "}", "return", "$", "callback", ";", "}" ]
Creates and returns a new, throttled version of the passed function. When invoked repeatedly, will only actually call the original function at most once per every wait milliseconds. Useful for rate-limiting events that occur faster than you can keep up with. By default, throttle will execute the function as soon as you call it for the first time, and, if you call it again any number of times during the wait period, as soon as that period is over. If you'd like to disable the leading-edge call, pass `leading => false`. NOTE: Does not support the `trailing` option because there is no timeout functionality in PHP (without using threads). NOTE: No arguments are passed to the function on the leading edge call! @param callable $function @param integer $wait @param array $options @return \Closure
[ "Creates", "and", "returns", "a", "new", "throttled", "version", "of", "the", "passed", "function", "." ]
2deb95cfd340761d00ecd0f033e67ce600f2b535
https://github.com/Im0rtality/Underscore/blob/2deb95cfd340761d00ecd0f033e67ce600f2b535/src/Functions.php#L187-L210
13,724
Im0rtality/Underscore
src/Functions.php
Functions.before
public static function before($count, $function) { $memo = null; return function () use ($function, &$count, &$memo) { if (--$count > 0) { $args = func_get_args(); $memo = call_user_func_array($function, $args); } return $memo; }; }
php
public static function before($count, $function) { $memo = null; return function () use ($function, &$count, &$memo) { if (--$count > 0) { $args = func_get_args(); $memo = call_user_func_array($function, $args); } return $memo; }; }
[ "public", "static", "function", "before", "(", "$", "count", ",", "$", "function", ")", "{", "$", "memo", "=", "null", ";", "return", "function", "(", ")", "use", "(", "$", "function", ",", "&", "$", "count", ",", "&", "$", "memo", ")", "{", "if", "(", "--", "$", "count", ">", "0", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "memo", "=", "call_user_func_array", "(", "$", "function", ",", "$", "args", ")", ";", "}", "return", "$", "memo", ";", "}", ";", "}" ]
Creates a version of the function that can be called no more than count times. The result of the last function call is memoized and returned when count has been reached. @param integer $count @param callable $function @return \Closure
[ "Creates", "a", "version", "of", "the", "function", "that", "can", "be", "called", "no", "more", "than", "count", "times", "." ]
2deb95cfd340761d00ecd0f033e67ce600f2b535
https://github.com/Im0rtality/Underscore/blob/2deb95cfd340761d00ecd0f033e67ce600f2b535/src/Functions.php#L242-L254
13,725
todstoychev/icr
src/Handler/OpenImageHandler.php
OpenImageHandler.loadImage
public function loadImage($image) { $imageLibrary = ucfirst($this->imageLibrary); $functionName = 'loadWith' . $imageLibrary; $this->image = $image; if (!method_exists($this, $functionName)) { throw new IcrRuntimeException('Wrong image library name provided!'); } return call_user_func([$this, $functionName]); }
php
public function loadImage($image) { $imageLibrary = ucfirst($this->imageLibrary); $functionName = 'loadWith' . $imageLibrary; $this->image = $image; if (!method_exists($this, $functionName)) { throw new IcrRuntimeException('Wrong image library name provided!'); } return call_user_func([$this, $functionName]); }
[ "public", "function", "loadImage", "(", "$", "image", ")", "{", "$", "imageLibrary", "=", "ucfirst", "(", "$", "this", "->", "imageLibrary", ")", ";", "$", "functionName", "=", "'loadWith'", ".", "$", "imageLibrary", ";", "$", "this", "->", "image", "=", "$", "image", ";", "if", "(", "!", "method_exists", "(", "$", "this", ",", "$", "functionName", ")", ")", "{", "throw", "new", "IcrRuntimeException", "(", "'Wrong image library name provided!'", ")", ";", "}", "return", "call_user_func", "(", "[", "$", "this", ",", "$", "functionName", "]", ")", ";", "}" ]
Loads image from data string with imagine based on the driver name @param string $image Image as string @return AbstractImage
[ "Loads", "image", "from", "data", "string", "with", "imagine", "based", "on", "the", "driver", "name" ]
0214c7bc76e44488e98758d55deb707b72e24000
https://github.com/todstoychev/icr/blob/0214c7bc76e44488e98758d55deb707b72e24000/src/Handler/OpenImageHandler.php#L61-L72
13,726
todstoychev/icr
src/Handler/OpenImageHandler.php
OpenImageHandler.openImage
public function openImage($path) { $imageLibrary = ucfirst($this->imageLibrary); $functionName = 'openWith' . $imageLibrary; $this->path = $path; if (!method_exists($this, $functionName)) { throw new IcrRuntimeException('Wrong image library name provided!'); } return call_user_func([$this, $functionName]); }
php
public function openImage($path) { $imageLibrary = ucfirst($this->imageLibrary); $functionName = 'openWith' . $imageLibrary; $this->path = $path; if (!method_exists($this, $functionName)) { throw new IcrRuntimeException('Wrong image library name provided!'); } return call_user_func([$this, $functionName]); }
[ "public", "function", "openImage", "(", "$", "path", ")", "{", "$", "imageLibrary", "=", "ucfirst", "(", "$", "this", "->", "imageLibrary", ")", ";", "$", "functionName", "=", "'openWith'", ".", "$", "imageLibrary", ";", "$", "this", "->", "path", "=", "$", "path", ";", "if", "(", "!", "method_exists", "(", "$", "this", ",", "$", "functionName", ")", ")", "{", "throw", "new", "IcrRuntimeException", "(", "'Wrong image library name provided!'", ")", ";", "}", "return", "call_user_func", "(", "[", "$", "this", ",", "$", "functionName", "]", ")", ";", "}" ]
Open image from path with imagine library @param string $path @return AbstractImage
[ "Open", "image", "from", "path", "with", "imagine", "library" ]
0214c7bc76e44488e98758d55deb707b72e24000
https://github.com/todstoychev/icr/blob/0214c7bc76e44488e98758d55deb707b72e24000/src/Handler/OpenImageHandler.php#L81-L92
13,727
mamuz/MamuzBlog
src/MamuzBlog/Controller/Plugin/ViewModelFactory.php
ViewModelFactory.create
public function create($variables = null, $options = null) { $viewModel = new ViewModel($variables, $options); $viewModel->setTerminal($this->isTerminal()); $viewModel->setVariable('isTerminal', $viewModel->terminate()); return $viewModel; }
php
public function create($variables = null, $options = null) { $viewModel = new ViewModel($variables, $options); $viewModel->setTerminal($this->isTerminal()); $viewModel->setVariable('isTerminal', $viewModel->terminate()); return $viewModel; }
[ "public", "function", "create", "(", "$", "variables", "=", "null", ",", "$", "options", "=", "null", ")", "{", "$", "viewModel", "=", "new", "ViewModel", "(", "$", "variables", ",", "$", "options", ")", ";", "$", "viewModel", "->", "setTerminal", "(", "$", "this", "->", "isTerminal", "(", ")", ")", ";", "$", "viewModel", "->", "setVariable", "(", "'isTerminal'", ",", "$", "viewModel", "->", "terminate", "(", ")", ")", ";", "return", "$", "viewModel", ";", "}" ]
Create ViewModel instance and set terminal mode by HttpRequest @param null|array|\Traversable $variables @param null|array|\Traversable $options @return ModelInterface
[ "Create", "ViewModel", "instance", "and", "set", "terminal", "mode", "by", "HttpRequest" ]
cb43be5c39031e3dcc939283e284824c4d07da38
https://github.com/mamuz/MamuzBlog/blob/cb43be5c39031e3dcc939283e284824c4d07da38/src/MamuzBlog/Controller/Plugin/ViewModelFactory.php#L19-L26
13,728
joomla-projects/jorobo
src/Tasks/Build/Library.php
Library.run
public function run() { $this->say("Building library folder " . $this->libName); if (!file_exists($this->source)) { $this->say("Folder " . $this->source . " does not exist!"); return true; } $this->prepareDirectory(); // Libaries are problematic.. we have libraries/name/libraries/name in the end for the build script $tar = $this->target; if (!$this->hasComponent) { $tar = $this->target . "/libraries/" . $this->libName; } $files = $this->copyTarget($this->source, $tar); $lib = $this->libName; // Workaround for libraries without lib_ if (substr($this->libName, 0, 3) != "lib") { $lib = 'lib_' . $this->libName; } // Build media (relative path) $media = $this->buildMedia("media/" . $lib, $lib); $media->run(); $this->addFiles('media', $media->getResultFiles()); // Build language files for the component $language = $this->buildLanguage($lib); $language->run(); // Copy XML $this->createInstaller($files); return true; }
php
public function run() { $this->say("Building library folder " . $this->libName); if (!file_exists($this->source)) { $this->say("Folder " . $this->source . " does not exist!"); return true; } $this->prepareDirectory(); // Libaries are problematic.. we have libraries/name/libraries/name in the end for the build script $tar = $this->target; if (!$this->hasComponent) { $tar = $this->target . "/libraries/" . $this->libName; } $files = $this->copyTarget($this->source, $tar); $lib = $this->libName; // Workaround for libraries without lib_ if (substr($this->libName, 0, 3) != "lib") { $lib = 'lib_' . $this->libName; } // Build media (relative path) $media = $this->buildMedia("media/" . $lib, $lib); $media->run(); $this->addFiles('media', $media->getResultFiles()); // Build language files for the component $language = $this->buildLanguage($lib); $language->run(); // Copy XML $this->createInstaller($files); return true; }
[ "public", "function", "run", "(", ")", "{", "$", "this", "->", "say", "(", "\"Building library folder \"", ".", "$", "this", "->", "libName", ")", ";", "if", "(", "!", "file_exists", "(", "$", "this", "->", "source", ")", ")", "{", "$", "this", "->", "say", "(", "\"Folder \"", ".", "$", "this", "->", "source", ".", "\" does not exist!\"", ")", ";", "return", "true", ";", "}", "$", "this", "->", "prepareDirectory", "(", ")", ";", "// Libaries are problematic.. we have libraries/name/libraries/name in the end for the build script", "$", "tar", "=", "$", "this", "->", "target", ";", "if", "(", "!", "$", "this", "->", "hasComponent", ")", "{", "$", "tar", "=", "$", "this", "->", "target", ".", "\"/libraries/\"", ".", "$", "this", "->", "libName", ";", "}", "$", "files", "=", "$", "this", "->", "copyTarget", "(", "$", "this", "->", "source", ",", "$", "tar", ")", ";", "$", "lib", "=", "$", "this", "->", "libName", ";", "// Workaround for libraries without lib_", "if", "(", "substr", "(", "$", "this", "->", "libName", ",", "0", ",", "3", ")", "!=", "\"lib\"", ")", "{", "$", "lib", "=", "'lib_'", ".", "$", "this", "->", "libName", ";", "}", "// Build media (relative path)", "$", "media", "=", "$", "this", "->", "buildMedia", "(", "\"media/\"", ".", "$", "lib", ",", "$", "lib", ")", ";", "$", "media", "->", "run", "(", ")", ";", "$", "this", "->", "addFiles", "(", "'media'", ",", "$", "media", "->", "getResultFiles", "(", ")", ")", ";", "// Build language files for the component", "$", "language", "=", "$", "this", "->", "buildLanguage", "(", "$", "lib", ")", ";", "$", "language", "->", "run", "(", ")", ";", "// Copy XML", "$", "this", "->", "createInstaller", "(", "$", "files", ")", ";", "return", "true", ";", "}" ]
Runs the library build tasks, just copying files currently @return bool @since 1.0
[ "Runs", "the", "library", "build", "tasks", "just", "copying", "files", "currently" ]
e72dd0ed15f387739f67cacdbc2c0bd1b427f317
https://github.com/joomla-projects/jorobo/blob/e72dd0ed15f387739f67cacdbc2c0bd1b427f317/src/Tasks/Build/Library.php#L67-L112
13,729
joomla-projects/jorobo
src/Tasks/Build/Library.php
Library.createInstaller
private function createInstaller($files) { $this->say("Creating library installer"); $xmlFile = $this->target . "/" . $this->libName . ".xml"; // Version & Date Replace $this->replaceInFile($xmlFile); // Files and folders $f = $this->generateFileList($files); $this->taskReplaceInFile($xmlFile) ->from('##LIBRARYFILES##') ->to($f) ->run(); // Language backend files $f = $this->generateLanguageFileList($this->getFiles('backendLanguage')); $this->taskReplaceInFile($xmlFile) ->from('##BACKEND_LANGUAGE_FILES##') ->to($f) ->run(); // Language frontend files $f = $this->generateLanguageFileList($this->getFiles('frontendLanguage')); $this->taskReplaceInFile($xmlFile) ->from('##FRONTEND_LANGUAGE_FILES##') ->to($f) ->run(); // Media files $f = $this->generateFileList($this->getFiles('media')); $this->taskReplaceInFile($xmlFile) ->from('##MEDIA_FILES##') ->to($f) ->run(); }
php
private function createInstaller($files) { $this->say("Creating library installer"); $xmlFile = $this->target . "/" . $this->libName . ".xml"; // Version & Date Replace $this->replaceInFile($xmlFile); // Files and folders $f = $this->generateFileList($files); $this->taskReplaceInFile($xmlFile) ->from('##LIBRARYFILES##') ->to($f) ->run(); // Language backend files $f = $this->generateLanguageFileList($this->getFiles('backendLanguage')); $this->taskReplaceInFile($xmlFile) ->from('##BACKEND_LANGUAGE_FILES##') ->to($f) ->run(); // Language frontend files $f = $this->generateLanguageFileList($this->getFiles('frontendLanguage')); $this->taskReplaceInFile($xmlFile) ->from('##FRONTEND_LANGUAGE_FILES##') ->to($f) ->run(); // Media files $f = $this->generateFileList($this->getFiles('media')); $this->taskReplaceInFile($xmlFile) ->from('##MEDIA_FILES##') ->to($f) ->run(); }
[ "private", "function", "createInstaller", "(", "$", "files", ")", "{", "$", "this", "->", "say", "(", "\"Creating library installer\"", ")", ";", "$", "xmlFile", "=", "$", "this", "->", "target", ".", "\"/\"", ".", "$", "this", "->", "libName", ".", "\".xml\"", ";", "// Version & Date Replace", "$", "this", "->", "replaceInFile", "(", "$", "xmlFile", ")", ";", "// Files and folders", "$", "f", "=", "$", "this", "->", "generateFileList", "(", "$", "files", ")", ";", "$", "this", "->", "taskReplaceInFile", "(", "$", "xmlFile", ")", "->", "from", "(", "'##LIBRARYFILES##'", ")", "->", "to", "(", "$", "f", ")", "->", "run", "(", ")", ";", "// Language backend files", "$", "f", "=", "$", "this", "->", "generateLanguageFileList", "(", "$", "this", "->", "getFiles", "(", "'backendLanguage'", ")", ")", ";", "$", "this", "->", "taskReplaceInFile", "(", "$", "xmlFile", ")", "->", "from", "(", "'##BACKEND_LANGUAGE_FILES##'", ")", "->", "to", "(", "$", "f", ")", "->", "run", "(", ")", ";", "// Language frontend files", "$", "f", "=", "$", "this", "->", "generateLanguageFileList", "(", "$", "this", "->", "getFiles", "(", "'frontendLanguage'", ")", ")", ";", "$", "this", "->", "taskReplaceInFile", "(", "$", "xmlFile", ")", "->", "from", "(", "'##FRONTEND_LANGUAGE_FILES##'", ")", "->", "to", "(", "$", "f", ")", "->", "run", "(", ")", ";", "// Media files", "$", "f", "=", "$", "this", "->", "generateFileList", "(", "$", "this", "->", "getFiles", "(", "'media'", ")", ")", ";", "$", "this", "->", "taskReplaceInFile", "(", "$", "xmlFile", ")", "->", "from", "(", "'##MEDIA_FILES##'", ")", "->", "to", "(", "$", "f", ")", "->", "run", "(", ")", ";", "}" ]
Generate the installer xml file for the library @param array $files The library files @return void @since 1.0
[ "Generate", "the", "installer", "xml", "file", "for", "the", "library" ]
e72dd0ed15f387739f67cacdbc2c0bd1b427f317
https://github.com/joomla-projects/jorobo/blob/e72dd0ed15f387739f67cacdbc2c0bd1b427f317/src/Tasks/Build/Library.php#L135-L175
13,730
iP1SMS/ip1-php-sdk
src/Core/Communicator.php
Communicator.add
public function add(ProcessableComponentInterface $component) { switch (get_class($component)) { case "IP1\RESTClient\Recipient\Contact": $response = $this->sendRequest("api/contacts", "POST", json_encode($component)); return RecipientFactory::createProcessedContactFromJSON($response); case "IP1\RESTClient\Recipient\Group": $response = $this->sendRequest("api/groups", "POST", json_encode($component)); return RecipientFactory::createProcessedGroupFromJSON($response); case "IP1\RESTClient\Recipient\Membership": $response = $this->sendRequest("api/memberships", "POST", json_encode($component)); return RecipientFactory::createProcessedMembershipFromJSON($response); case "IP1\RESTClient\SMS\OutGoingSMS": $response = $this->sendRequest("api/sms/send", "POST", json_encode($component)); return RecipientFactory::createProcessedOutGoingSMSFromJSONArray($response); case "IP1\RESTClient\Recipient\BlacklistEntry": $response = $this->sendRequest("api/blacklist", "POST", json_encode($component)); $stdResponse = json_decode($response); $created = new \DateTime($stdResponse->Created); return new ProcessedBlacklistEntry($stdResponse->Phone, $stdResponse->ID, $created); default: throw new \InvalidArgumentException("Given JsonSerializable not supported."); } }
php
public function add(ProcessableComponentInterface $component) { switch (get_class($component)) { case "IP1\RESTClient\Recipient\Contact": $response = $this->sendRequest("api/contacts", "POST", json_encode($component)); return RecipientFactory::createProcessedContactFromJSON($response); case "IP1\RESTClient\Recipient\Group": $response = $this->sendRequest("api/groups", "POST", json_encode($component)); return RecipientFactory::createProcessedGroupFromJSON($response); case "IP1\RESTClient\Recipient\Membership": $response = $this->sendRequest("api/memberships", "POST", json_encode($component)); return RecipientFactory::createProcessedMembershipFromJSON($response); case "IP1\RESTClient\SMS\OutGoingSMS": $response = $this->sendRequest("api/sms/send", "POST", json_encode($component)); return RecipientFactory::createProcessedOutGoingSMSFromJSONArray($response); case "IP1\RESTClient\Recipient\BlacklistEntry": $response = $this->sendRequest("api/blacklist", "POST", json_encode($component)); $stdResponse = json_decode($response); $created = new \DateTime($stdResponse->Created); return new ProcessedBlacklistEntry($stdResponse->Phone, $stdResponse->ID, $created); default: throw new \InvalidArgumentException("Given JsonSerializable not supported."); } }
[ "public", "function", "add", "(", "ProcessableComponentInterface", "$", "component", ")", "{", "switch", "(", "get_class", "(", "$", "component", ")", ")", "{", "case", "\"IP1\\RESTClient\\Recipient\\Contact\"", ":", "$", "response", "=", "$", "this", "->", "sendRequest", "(", "\"api/contacts\"", ",", "\"POST\"", ",", "json_encode", "(", "$", "component", ")", ")", ";", "return", "RecipientFactory", "::", "createProcessedContactFromJSON", "(", "$", "response", ")", ";", "case", "\"IP1\\RESTClient\\Recipient\\Group\"", ":", "$", "response", "=", "$", "this", "->", "sendRequest", "(", "\"api/groups\"", ",", "\"POST\"", ",", "json_encode", "(", "$", "component", ")", ")", ";", "return", "RecipientFactory", "::", "createProcessedGroupFromJSON", "(", "$", "response", ")", ";", "case", "\"IP1\\RESTClient\\Recipient\\Membership\"", ":", "$", "response", "=", "$", "this", "->", "sendRequest", "(", "\"api/memberships\"", ",", "\"POST\"", ",", "json_encode", "(", "$", "component", ")", ")", ";", "return", "RecipientFactory", "::", "createProcessedMembershipFromJSON", "(", "$", "response", ")", ";", "case", "\"IP1\\RESTClient\\SMS\\OutGoingSMS\"", ":", "$", "response", "=", "$", "this", "->", "sendRequest", "(", "\"api/sms/send\"", ",", "\"POST\"", ",", "json_encode", "(", "$", "component", ")", ")", ";", "return", "RecipientFactory", "::", "createProcessedOutGoingSMSFromJSONArray", "(", "$", "response", ")", ";", "case", "\"IP1\\RESTClient\\Recipient\\BlacklistEntry\"", ":", "$", "response", "=", "$", "this", "->", "sendRequest", "(", "\"api/blacklist\"", ",", "\"POST\"", ",", "json_encode", "(", "$", "component", ")", ")", ";", "$", "stdResponse", "=", "json_decode", "(", "$", "response", ")", ";", "$", "created", "=", "new", "\\", "DateTime", "(", "$", "stdResponse", "->", "Created", ")", ";", "return", "new", "ProcessedBlacklistEntry", "(", "$", "stdResponse", "->", "Phone", ",", "$", "stdResponse", "->", "ID", ",", "$", "created", ")", ";", "default", ":", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Given JsonSerializable not supported.\"", ")", ";", "}", "}" ]
Adds the param to the API and returns the response as the corresponding object. @param ProcessableComponentInterface $component A Contact, Group, Membership or OutGoingSMS. @return ProcessedComponentInterface ProcessedContact, ProcessedGroup, PrcessedMembership or a ClassValidatinArray filled with ProcessedOutGoingSMS. @throws \InvalidArgumentException When param isn't any of the classes listed in param args.
[ "Adds", "the", "param", "to", "the", "API", "and", "returns", "the", "response", "as", "the", "corresponding", "object", "." ]
348e6572a279363ba689c9e0f5689b83a25930f5
https://github.com/iP1SMS/ip1-php-sdk/blob/348e6572a279363ba689c9e0f5689b83a25930f5/src/Core/Communicator.php#L60-L86
13,731
iP1SMS/ip1-php-sdk
src/Core/Communicator.php
Communicator.remove
public function remove(ProcessedComponentInterface $component): ProcessedComponentInterface { switch (get_class($component)) { case "IP1\RESTClient\Recipient\ProcessedContact": $response = $this->sendRequest("api/contacts/".$component->getID(), "DELETE"); return RecipientFactory::createProcessedContactFromJSON($response); case "IP1\RESTClient\Recipient\ProcessedGroup": $response = $this->sendRequest("api/groups/".$component->getID(), "DELETE"); return RecipientFactory::createProcessedGroupFromJSON($response); case "IP1\RESTClient\Recipient\ProcessedMembership": $response = $this->sendRequest("api/memberships/".$component->getID(), "DELETE"); return RecipientFactory::createProcessedMembershipFromJSON($response); case "IP1\RESTClient\Recipient\ProcessedBlacklistEntry": $response = $this->sendRequest("api/blacklist/".$component->getID(), "DELETE"); $stdResponse = json_decode($response); $created = new \DateTime($stdResponse->Created); return new ProcessedBlacklistEntry($stdResponse->Phone, $stdResponse->ID, $created); default: throw new \InvalidArgumentException("Given JsonSerializable not supported."); } }
php
public function remove(ProcessedComponentInterface $component): ProcessedComponentInterface { switch (get_class($component)) { case "IP1\RESTClient\Recipient\ProcessedContact": $response = $this->sendRequest("api/contacts/".$component->getID(), "DELETE"); return RecipientFactory::createProcessedContactFromJSON($response); case "IP1\RESTClient\Recipient\ProcessedGroup": $response = $this->sendRequest("api/groups/".$component->getID(), "DELETE"); return RecipientFactory::createProcessedGroupFromJSON($response); case "IP1\RESTClient\Recipient\ProcessedMembership": $response = $this->sendRequest("api/memberships/".$component->getID(), "DELETE"); return RecipientFactory::createProcessedMembershipFromJSON($response); case "IP1\RESTClient\Recipient\ProcessedBlacklistEntry": $response = $this->sendRequest("api/blacklist/".$component->getID(), "DELETE"); $stdResponse = json_decode($response); $created = new \DateTime($stdResponse->Created); return new ProcessedBlacklistEntry($stdResponse->Phone, $stdResponse->ID, $created); default: throw new \InvalidArgumentException("Given JsonSerializable not supported."); } }
[ "public", "function", "remove", "(", "ProcessedComponentInterface", "$", "component", ")", ":", "ProcessedComponentInterface", "{", "switch", "(", "get_class", "(", "$", "component", ")", ")", "{", "case", "\"IP1\\RESTClient\\Recipient\\ProcessedContact\"", ":", "$", "response", "=", "$", "this", "->", "sendRequest", "(", "\"api/contacts/\"", ".", "$", "component", "->", "getID", "(", ")", ",", "\"DELETE\"", ")", ";", "return", "RecipientFactory", "::", "createProcessedContactFromJSON", "(", "$", "response", ")", ";", "case", "\"IP1\\RESTClient\\Recipient\\ProcessedGroup\"", ":", "$", "response", "=", "$", "this", "->", "sendRequest", "(", "\"api/groups/\"", ".", "$", "component", "->", "getID", "(", ")", ",", "\"DELETE\"", ")", ";", "return", "RecipientFactory", "::", "createProcessedGroupFromJSON", "(", "$", "response", ")", ";", "case", "\"IP1\\RESTClient\\Recipient\\ProcessedMembership\"", ":", "$", "response", "=", "$", "this", "->", "sendRequest", "(", "\"api/memberships/\"", ".", "$", "component", "->", "getID", "(", ")", ",", "\"DELETE\"", ")", ";", "return", "RecipientFactory", "::", "createProcessedMembershipFromJSON", "(", "$", "response", ")", ";", "case", "\"IP1\\RESTClient\\Recipient\\ProcessedBlacklistEntry\"", ":", "$", "response", "=", "$", "this", "->", "sendRequest", "(", "\"api/blacklist/\"", ".", "$", "component", "->", "getID", "(", ")", ",", "\"DELETE\"", ")", ";", "$", "stdResponse", "=", "json_decode", "(", "$", "response", ")", ";", "$", "created", "=", "new", "\\", "DateTime", "(", "$", "stdResponse", "->", "Created", ")", ";", "return", "new", "ProcessedBlacklistEntry", "(", "$", "stdResponse", "->", "Phone", ",", "$", "stdResponse", "->", "ID", ",", "$", "created", ")", ";", "default", ":", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Given JsonSerializable not supported.\"", ")", ";", "}", "}" ]
Removes the param to the API and returns the response as the corresponding object. @param ProcessedComponentInterface $component A Contact, Group, Membership. @return ProcessedComponentInterface ProcessedContact, ProcessedGroup, PrcessedMembership or a ClassValidatinArray filled with ProcessedOutGoingSMS. @throws \InvalidArgumentException When param isn't any of the classes listed in param args.
[ "Removes", "the", "param", "to", "the", "API", "and", "returns", "the", "response", "as", "the", "corresponding", "object", "." ]
348e6572a279363ba689c9e0f5689b83a25930f5
https://github.com/iP1SMS/ip1-php-sdk/blob/348e6572a279363ba689c9e0f5689b83a25930f5/src/Core/Communicator.php#L94-L118
13,732
iP1SMS/ip1-php-sdk
src/Core/Communicator.php
Communicator.edit
public function edit(UpdatableComponentInterface $component): UpdatableComponentInterface { switch (get_class($component)) { case "IP1\RESTClient\Recipient\ProcessedContact": $response = $this->sendRequest( "api/contacts/".$component->getID(), "PUT", json_encode($component) ); return RecipientFactory::createProcessedContactFromJSON($response); case "IP1\RESTClient\Recipient\ProcessedGroup": $response = $this->sendRequest( "api/groups/".$component->getID(), "PUT", json_encode($component) ); return RecipientFactory::createProcessedGroupFromJSON($response); default: throw new \InvalidArgumentException("Given JsonSerializable not supported."); } }
php
public function edit(UpdatableComponentInterface $component): UpdatableComponentInterface { switch (get_class($component)) { case "IP1\RESTClient\Recipient\ProcessedContact": $response = $this->sendRequest( "api/contacts/".$component->getID(), "PUT", json_encode($component) ); return RecipientFactory::createProcessedContactFromJSON($response); case "IP1\RESTClient\Recipient\ProcessedGroup": $response = $this->sendRequest( "api/groups/".$component->getID(), "PUT", json_encode($component) ); return RecipientFactory::createProcessedGroupFromJSON($response); default: throw new \InvalidArgumentException("Given JsonSerializable not supported."); } }
[ "public", "function", "edit", "(", "UpdatableComponentInterface", "$", "component", ")", ":", "UpdatableComponentInterface", "{", "switch", "(", "get_class", "(", "$", "component", ")", ")", "{", "case", "\"IP1\\RESTClient\\Recipient\\ProcessedContact\"", ":", "$", "response", "=", "$", "this", "->", "sendRequest", "(", "\"api/contacts/\"", ".", "$", "component", "->", "getID", "(", ")", ",", "\"PUT\"", ",", "json_encode", "(", "$", "component", ")", ")", ";", "return", "RecipientFactory", "::", "createProcessedContactFromJSON", "(", "$", "response", ")", ";", "case", "\"IP1\\RESTClient\\Recipient\\ProcessedGroup\"", ":", "$", "response", "=", "$", "this", "->", "sendRequest", "(", "\"api/groups/\"", ".", "$", "component", "->", "getID", "(", ")", ",", "\"PUT\"", ",", "json_encode", "(", "$", "component", ")", ")", ";", "return", "RecipientFactory", "::", "createProcessedGroupFromJSON", "(", "$", "response", ")", ";", "default", ":", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Given JsonSerializable not supported.\"", ")", ";", "}", "}" ]
Edits the param to the API and returns the response as the corresponding object. @param UpdatableComponentInterface $component A Contact, Group, Membership. @return UpdatableComponentInterface ProcessedContact, ProcessedGroup or PrcessedMembership. @throws \InvalidArgumentException When param isn't any of the classes listed in param args.
[ "Edits", "the", "param", "to", "the", "API", "and", "returns", "the", "response", "as", "the", "corresponding", "object", "." ]
348e6572a279363ba689c9e0f5689b83a25930f5
https://github.com/iP1SMS/ip1-php-sdk/blob/348e6572a279363ba689c9e0f5689b83a25930f5/src/Core/Communicator.php#L125-L146
13,733
iP1SMS/ip1-php-sdk
src/Core/Communicator.php
Communicator.post
public function post(string $endPoint, \JsonSerializable $content): string { $parsedEndPoint = self::parseEndPoint($endPoint); return $this->sendRequest($parsedEndPoint, "POST", json_encode($content)); }
php
public function post(string $endPoint, \JsonSerializable $content): string { $parsedEndPoint = self::parseEndPoint($endPoint); return $this->sendRequest($parsedEndPoint, "POST", json_encode($content)); }
[ "public", "function", "post", "(", "string", "$", "endPoint", ",", "\\", "JsonSerializable", "$", "content", ")", ":", "string", "{", "$", "parsedEndPoint", "=", "self", "::", "parseEndPoint", "(", "$", "endPoint", ")", ";", "return", "$", "this", "->", "sendRequest", "(", "$", "parsedEndPoint", ",", "\"POST\"", ",", "json_encode", "(", "$", "content", ")", ")", ";", "}" ]
Adds the content object to the endpoint and returns a processed version of given object. @param string $endPoint API URI. @param \JsonSerializable $content The ProcessableComponentInterface that is to be posted to the API. @return string JSON API Response.
[ "Adds", "the", "content", "object", "to", "the", "endpoint", "and", "returns", "a", "processed", "version", "of", "given", "object", "." ]
348e6572a279363ba689c9e0f5689b83a25930f5
https://github.com/iP1SMS/ip1-php-sdk/blob/348e6572a279363ba689c9e0f5689b83a25930f5/src/Core/Communicator.php#L164-L168
13,734
iP1SMS/ip1-php-sdk
src/Core/Communicator.php
Communicator.delete
public function delete(string $endPoint): string { $parsedEndPoint = self::parseEndPoint($endPoint); return $this->sendRequest($parsedEndPoint, "DELETE"); }
php
public function delete(string $endPoint): string { $parsedEndPoint = self::parseEndPoint($endPoint); return $this->sendRequest($parsedEndPoint, "DELETE"); }
[ "public", "function", "delete", "(", "string", "$", "endPoint", ")", ":", "string", "{", "$", "parsedEndPoint", "=", "self", "::", "parseEndPoint", "(", "$", "endPoint", ")", ";", "return", "$", "this", "->", "sendRequest", "(", "$", "parsedEndPoint", ",", "\"DELETE\"", ")", ";", "}" ]
Deletes the object at the given endpoint @param string $endPoint API URI. @return string JSON string of what got deleted.
[ "Deletes", "the", "object", "at", "the", "given", "endpoint" ]
348e6572a279363ba689c9e0f5689b83a25930f5
https://github.com/iP1SMS/ip1-php-sdk/blob/348e6572a279363ba689c9e0f5689b83a25930f5/src/Core/Communicator.php#L174-L178
13,735
iP1SMS/ip1-php-sdk
src/Core/Communicator.php
Communicator.parseEndPoint
private static function parseEndPoint(string $endPoint) { $endPoint = trim($endPoint, '/'); $endPointArray = explode('/', $endPoint); if ($endPointArray[0] == "api") { return $endPoint; } array_unshift($endPointArray, "api"); return implode('/', array_filter($endPointArray)); }
php
private static function parseEndPoint(string $endPoint) { $endPoint = trim($endPoint, '/'); $endPointArray = explode('/', $endPoint); if ($endPointArray[0] == "api") { return $endPoint; } array_unshift($endPointArray, "api"); return implode('/', array_filter($endPointArray)); }
[ "private", "static", "function", "parseEndPoint", "(", "string", "$", "endPoint", ")", "{", "$", "endPoint", "=", "trim", "(", "$", "endPoint", ",", "'/'", ")", ";", "$", "endPointArray", "=", "explode", "(", "'/'", ",", "$", "endPoint", ")", ";", "if", "(", "$", "endPointArray", "[", "0", "]", "==", "\"api\"", ")", "{", "return", "$", "endPoint", ";", "}", "array_unshift", "(", "$", "endPointArray", ",", "\"api\"", ")", ";", "return", "implode", "(", "'/'", ",", "array_filter", "(", "$", "endPointArray", ")", ")", ";", "}" ]
Turns the given endPoint string into a usable. @param string $endPoint API URI. @return string Fixed endpoint string.
[ "Turns", "the", "given", "endPoint", "string", "into", "a", "usable", "." ]
348e6572a279363ba689c9e0f5689b83a25930f5
https://github.com/iP1SMS/ip1-php-sdk/blob/348e6572a279363ba689c9e0f5689b83a25930f5/src/Core/Communicator.php#L195-L205
13,736
iP1SMS/ip1-php-sdk
src/Core/Communicator.php
Communicator.sendRequest
private function sendRequest(string $endPoint, string $method, string $content = "", bool $https = true): Response { $url = ($https ? "https://" : "http://") . self::DOMAIN . "/" .$endPoint; $request = \Httpful\Request::init($method, 'application/json'); $request->basicAuth($this->accountToken, $this->apiToken) ->addHeader('User-Agent', 'iP1sms/indev') ->expectsJson() ->Uri($url) ->body($content, 'application/json') ->neverSerialize(); $response = $request->send(); if ($response->hasErrors()) { $this->errorResponses[] = $response; } return $response; }
php
private function sendRequest(string $endPoint, string $method, string $content = "", bool $https = true): Response { $url = ($https ? "https://" : "http://") . self::DOMAIN . "/" .$endPoint; $request = \Httpful\Request::init($method, 'application/json'); $request->basicAuth($this->accountToken, $this->apiToken) ->addHeader('User-Agent', 'iP1sms/indev') ->expectsJson() ->Uri($url) ->body($content, 'application/json') ->neverSerialize(); $response = $request->send(); if ($response->hasErrors()) { $this->errorResponses[] = $response; } return $response; }
[ "private", "function", "sendRequest", "(", "string", "$", "endPoint", ",", "string", "$", "method", ",", "string", "$", "content", "=", "\"\"", ",", "bool", "$", "https", "=", "true", ")", ":", "Response", "{", "$", "url", "=", "(", "$", "https", "?", "\"https://\"", ":", "\"http://\"", ")", ".", "self", "::", "DOMAIN", ".", "\"/\"", ".", "$", "endPoint", ";", "$", "request", "=", "\\", "Httpful", "\\", "Request", "::", "init", "(", "$", "method", ",", "'application/json'", ")", ";", "$", "request", "->", "basicAuth", "(", "$", "this", "->", "accountToken", ",", "$", "this", "->", "apiToken", ")", "->", "addHeader", "(", "'User-Agent'", ",", "'iP1sms/indev'", ")", "->", "expectsJson", "(", ")", "->", "Uri", "(", "$", "url", ")", "->", "body", "(", "$", "content", ",", "'application/json'", ")", "->", "neverSerialize", "(", ")", ";", "$", "response", "=", "$", "request", "->", "send", "(", ")", ";", "if", "(", "$", "response", "->", "hasErrors", "(", ")", ")", "{", "$", "this", "->", "errorResponses", "[", "]", "=", "$", "response", ";", "}", "return", "$", "response", ";", "}" ]
Sends a HTTP request to the RESTful API and returns the result as a JSON string. @param string $endPoint The URI that the function should use. @param string $method The HTTP method that should be used, valid ones are: METH_POST, METH_GET, METH_DELETE and METH_PUT. @param string $content A JSON string containing all additional data that can not be provided by $endPoint. @param boolean $https Whether the the API call should use HTTPS or not(HTTP). @return string The response from the API.
[ "Sends", "a", "HTTP", "request", "to", "the", "RESTful", "API", "and", "returns", "the", "result", "as", "a", "JSON", "string", "." ]
348e6572a279363ba689c9e0f5689b83a25930f5
https://github.com/iP1SMS/ip1-php-sdk/blob/348e6572a279363ba689c9e0f5689b83a25930f5/src/Core/Communicator.php#L216-L233
13,737
mimmi20/Wurfl
src/CustomDevice.php
CustomDevice.isSpecific
public function isSpecific() { foreach ($this->modelDevices as $modelDevice) { if ($modelDevice->specific === true || $modelDevice->actualDeviceRoot === true) { return true; } } return false; }
php
public function isSpecific() { foreach ($this->modelDevices as $modelDevice) { if ($modelDevice->specific === true || $modelDevice->actualDeviceRoot === true) { return true; } } return false; }
[ "public", "function", "isSpecific", "(", ")", "{", "foreach", "(", "$", "this", "->", "modelDevices", "as", "$", "modelDevice", ")", "{", "if", "(", "$", "modelDevice", "->", "specific", "===", "true", "||", "$", "modelDevice", "->", "actualDeviceRoot", "===", "true", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Device is a specific or actual WURFL device as defined by its capabilities @return bool
[ "Device", "is", "a", "specific", "or", "actual", "WURFL", "device", "as", "defined", "by", "its", "capabilities" ]
443ed0d73a0b9a21ebd0d6ddf1e32669b9de44ec
https://github.com/mimmi20/Wurfl/blob/443ed0d73a0b9a21ebd0d6ddf1e32669b9de44ec/src/CustomDevice.php#L148-L157
13,738
mimmi20/Wurfl
src/CustomDevice.php
CustomDevice.getCapability
public function getCapability($capabilityName) { if (empty($capabilityName)) { throw new \InvalidArgumentException('capability name must not be empty'); } if (!$this->getRootDevice()->isCapabilityDefined($capabilityName)) { throw new \InvalidArgumentException('no capability named [' . $capabilityName . '] is present in wurfl.'); } foreach ($this->modelDevices as $modelDevice) { /* @var Device\ModelDeviceInterface $modelDevice */ $capabilityValue = $modelDevice->getCapability($capabilityName); if ($capabilityValue !== null) { return $capabilityValue; } } return null; }
php
public function getCapability($capabilityName) { if (empty($capabilityName)) { throw new \InvalidArgumentException('capability name must not be empty'); } if (!$this->getRootDevice()->isCapabilityDefined($capabilityName)) { throw new \InvalidArgumentException('no capability named [' . $capabilityName . '] is present in wurfl.'); } foreach ($this->modelDevices as $modelDevice) { /* @var Device\ModelDeviceInterface $modelDevice */ $capabilityValue = $modelDevice->getCapability($capabilityName); if ($capabilityValue !== null) { return $capabilityValue; } } return null; }
[ "public", "function", "getCapability", "(", "$", "capabilityName", ")", "{", "if", "(", "empty", "(", "$", "capabilityName", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'capability name must not be empty'", ")", ";", "}", "if", "(", "!", "$", "this", "->", "getRootDevice", "(", ")", "->", "isCapabilityDefined", "(", "$", "capabilityName", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'no capability named ['", ".", "$", "capabilityName", ".", "'] is present in wurfl.'", ")", ";", "}", "foreach", "(", "$", "this", "->", "modelDevices", "as", "$", "modelDevice", ")", "{", "/* @var Device\\ModelDeviceInterface $modelDevice */", "$", "capabilityValue", "=", "$", "modelDevice", "->", "getCapability", "(", "$", "capabilityName", ")", ";", "if", "(", "$", "capabilityValue", "!==", "null", ")", "{", "return", "$", "capabilityValue", ";", "}", "}", "return", "null", ";", "}" ]
Returns the value of a given capability name for the current device @param string $capabilityName must be a valid capability name @throws \InvalidArgumentException The $capabilityName is is not defined in the loaded WURFL. @return string|null Capability value @see \Wurfl\Device\ModelDeviceInterface::getCapability()
[ "Returns", "the", "value", "of", "a", "given", "capability", "name", "for", "the", "current", "device" ]
443ed0d73a0b9a21ebd0d6ddf1e32669b9de44ec
https://github.com/mimmi20/Wurfl/blob/443ed0d73a0b9a21ebd0d6ddf1e32669b9de44ec/src/CustomDevice.php#L171-L190
13,739
christophe-brachet/aspi-framework
src/Framework/Form/Element/Input/Datalist.php
Datalist.render
public function render($depth = 0, $indent = null, $inner = false) { return parent::render($depth, $indent, $inner) . $this->datalist->render($depth, $indent, $inner); }
php
public function render($depth = 0, $indent = null, $inner = false) { return parent::render($depth, $indent, $inner) . $this->datalist->render($depth, $indent, $inner); }
[ "public", "function", "render", "(", "$", "depth", "=", "0", ",", "$", "indent", "=", "null", ",", "$", "inner", "=", "false", ")", "{", "return", "parent", "::", "render", "(", "$", "depth", ",", "$", "indent", ",", "$", "inner", ")", ".", "$", "this", "->", "datalist", "->", "render", "(", "$", "depth", ",", "$", "indent", ",", "$", "inner", ")", ";", "}" ]
Render the datalist element @param int $depth @param string $indent @param boolean $inner @return mixed
[ "Render", "the", "datalist", "element" ]
17a36c8a8582e0b8d8bff7087590c09a9bd4af1e
https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Element/Input/Datalist.php#L61-L64
13,740
incraigulous/contentful-sdk
src/ManagementResources/Assets.php
Assets.process
function process($id, $language = null) { if (!$language && defined('CONTENTFUL_DEFAULT_LANGUAGE')) { $language = CONTENTFUL_DEFAULT_LANGUAGE; } else { $language = 'en-US'; } $this->requestDecorator->setId($id . '/files/' . $language . '/process'); $result = $this->client->put($this->requestDecorator->makeResource(), $this->requestDecorator->makePayload(), $this->requestDecorator->makeHeaders()); $this->refresh(); return $result; }
php
function process($id, $language = null) { if (!$language && defined('CONTENTFUL_DEFAULT_LANGUAGE')) { $language = CONTENTFUL_DEFAULT_LANGUAGE; } else { $language = 'en-US'; } $this->requestDecorator->setId($id . '/files/' . $language . '/process'); $result = $this->client->put($this->requestDecorator->makeResource(), $this->requestDecorator->makePayload(), $this->requestDecorator->makeHeaders()); $this->refresh(); return $result; }
[ "function", "process", "(", "$", "id", ",", "$", "language", "=", "null", ")", "{", "if", "(", "!", "$", "language", "&&", "defined", "(", "'CONTENTFUL_DEFAULT_LANGUAGE'", ")", ")", "{", "$", "language", "=", "CONTENTFUL_DEFAULT_LANGUAGE", ";", "}", "else", "{", "$", "language", "=", "'en-US'", ";", "}", "$", "this", "->", "requestDecorator", "->", "setId", "(", "$", "id", ".", "'/files/'", ".", "$", "language", ".", "'/process'", ")", ";", "$", "result", "=", "$", "this", "->", "client", "->", "put", "(", "$", "this", "->", "requestDecorator", "->", "makeResource", "(", ")", ",", "$", "this", "->", "requestDecorator", "->", "makePayload", "(", ")", ",", "$", "this", "->", "requestDecorator", "->", "makeHeaders", "(", ")", ")", ";", "$", "this", "->", "refresh", "(", ")", ";", "return", "$", "result", ";", "}" ]
Process an asset. @param $id @param string $language @return mixed
[ "Process", "an", "asset", "." ]
29399b11b0e085a06ea5976661378c379fe5a731
https://github.com/incraigulous/contentful-sdk/blob/29399b11b0e085a06ea5976661378c379fe5a731/src/ManagementResources/Assets.php#L18-L29
13,741
PandaPlatform/framework
src/Panda/Http/Request.php
Request.getInputValue
public function getInputValue($key = null, $default = null) { $input = $this->getInputSource()->all() + $this->query->all(); return ArrayHelper::get($input, $key, $default); }
php
public function getInputValue($key = null, $default = null) { $input = $this->getInputSource()->all() + $this->query->all(); return ArrayHelper::get($input, $key, $default); }
[ "public", "function", "getInputValue", "(", "$", "key", "=", "null", ",", "$", "default", "=", "null", ")", "{", "$", "input", "=", "$", "this", "->", "getInputSource", "(", ")", "->", "all", "(", ")", "+", "$", "this", "->", "query", "->", "all", "(", ")", ";", "return", "ArrayHelper", "::", "get", "(", "$", "input", ",", "$", "key", ",", "$", "default", ")", ";", "}" ]
Get an input item from the request. @param string $key @param string|array|null $default @return array|string @throws \LogicException
[ "Get", "an", "input", "item", "from", "the", "request", "." ]
a78cf051b379896b5a4d5df620988e37a0e632f5
https://github.com/PandaPlatform/framework/blob/a78cf051b379896b5a4d5df620988e37a0e632f5/src/Panda/Http/Request.php#L97-L102
13,742
PandaPlatform/framework
src/Panda/Http/Request.php
Request.get
public function get($key, $default = null, $includeCookies = true) { if ($includeCookies) { if ($this !== $result = $this->cookies->get($key, $this)) { return $result; } } return parent::get($key, $default); }
php
public function get($key, $default = null, $includeCookies = true) { if ($includeCookies) { if ($this !== $result = $this->cookies->get($key, $this)) { return $result; } } return parent::get($key, $default); }
[ "public", "function", "get", "(", "$", "key", ",", "$", "default", "=", "null", ",", "$", "includeCookies", "=", "true", ")", "{", "if", "(", "$", "includeCookies", ")", "{", "if", "(", "$", "this", "!==", "$", "result", "=", "$", "this", "->", "cookies", "->", "get", "(", "$", "key", ",", "$", "this", ")", ")", "{", "return", "$", "result", ";", "}", "}", "return", "parent", "::", "get", "(", "$", "key", ",", "$", "default", ")", ";", "}" ]
Gets a "parameter" value from any bag. You can include the cookies bag. It is included by default. @param string $key @param null $default @param bool $includeCookies @return mixed
[ "Gets", "a", "parameter", "value", "from", "any", "bag", ".", "You", "can", "include", "the", "cookies", "bag", ".", "It", "is", "included", "by", "default", "." ]
a78cf051b379896b5a4d5df620988e37a0e632f5
https://github.com/PandaPlatform/framework/blob/a78cf051b379896b5a4d5df620988e37a0e632f5/src/Panda/Http/Request.php#L209-L218
13,743
venta/framework
src/Routing/src/UrlGenerator.php
UrlGenerator.addPortToUri
private function addPortToUri(UriInterface $uri): UriInterface { $requestPort = $this->request->getUri()->getPort(); if (!in_array($requestPort, [80, 443])) { $uri = $uri->withPort($requestPort); } return $uri; }
php
private function addPortToUri(UriInterface $uri): UriInterface { $requestPort = $this->request->getUri()->getPort(); if (!in_array($requestPort, [80, 443])) { $uri = $uri->withPort($requestPort); } return $uri; }
[ "private", "function", "addPortToUri", "(", "UriInterface", "$", "uri", ")", ":", "UriInterface", "{", "$", "requestPort", "=", "$", "this", "->", "request", "->", "getUri", "(", ")", "->", "getPort", "(", ")", ";", "if", "(", "!", "in_array", "(", "$", "requestPort", ",", "[", "80", ",", "443", "]", ")", ")", "{", "$", "uri", "=", "$", "uri", "->", "withPort", "(", "$", "requestPort", ")", ";", "}", "return", "$", "uri", ";", "}" ]
Adds port to URI if it is needed. @param UriInterface $uri @return UriInterface
[ "Adds", "port", "to", "URI", "if", "it", "is", "needed", "." ]
514a7854cc69f84f47e62a58cc55efd68b7c9f83
https://github.com/venta/framework/blob/514a7854cc69f84f47e62a58cc55efd68b7c9f83/src/Routing/src/UrlGenerator.php#L99-L108
13,744
venta/framework
src/Routing/src/UrlGenerator.php
UrlGenerator.buildRouteUri
private function buildRouteUri(RouteContract $route, array $variables = [], array $query = []): UriInterface { $uri = $this->uri ->withScheme($route->scheme() ?: $this->request->getUri()->getScheme()) ->withHost($route->host() ?: $this->request->getUri()->getHost()) ->withPath($route->compilePath($variables)); if ($query) { $uri = $uri->withQuery(http_build_query($query)); } return $this->addPortToUri($uri); }
php
private function buildRouteUri(RouteContract $route, array $variables = [], array $query = []): UriInterface { $uri = $this->uri ->withScheme($route->scheme() ?: $this->request->getUri()->getScheme()) ->withHost($route->host() ?: $this->request->getUri()->getHost()) ->withPath($route->compilePath($variables)); if ($query) { $uri = $uri->withQuery(http_build_query($query)); } return $this->addPortToUri($uri); }
[ "private", "function", "buildRouteUri", "(", "RouteContract", "$", "route", ",", "array", "$", "variables", "=", "[", "]", ",", "array", "$", "query", "=", "[", "]", ")", ":", "UriInterface", "{", "$", "uri", "=", "$", "this", "->", "uri", "->", "withScheme", "(", "$", "route", "->", "scheme", "(", ")", "?", ":", "$", "this", "->", "request", "->", "getUri", "(", ")", "->", "getScheme", "(", ")", ")", "->", "withHost", "(", "$", "route", "->", "host", "(", ")", "?", ":", "$", "this", "->", "request", "->", "getUri", "(", ")", "->", "getHost", "(", ")", ")", "->", "withPath", "(", "$", "route", "->", "compilePath", "(", "$", "variables", ")", ")", ";", "if", "(", "$", "query", ")", "{", "$", "uri", "=", "$", "uri", "->", "withQuery", "(", "http_build_query", "(", "$", "query", ")", ")", ";", "}", "return", "$", "this", "->", "addPortToUri", "(", "$", "uri", ")", ";", "}" ]
Builds URI for provided route instance. @param RouteContract $route @param array $variables @param array $query @return UriInterface
[ "Builds", "URI", "for", "provided", "route", "instance", "." ]
514a7854cc69f84f47e62a58cc55efd68b7c9f83
https://github.com/venta/framework/blob/514a7854cc69f84f47e62a58cc55efd68b7c9f83/src/Routing/src/UrlGenerator.php#L118-L130
13,745
raphaelstolt/composer-travis-lint
src/Travis.php
Travis.hasStaleCacheFile
protected static function hasStaleCacheFile() { $composerTravisLintCache = getcwd() . DIRECTORY_SEPARATOR . self::CTL_CACHE; $travisConfiguration = getcwd() . DIRECTORY_SEPARATOR . self::TRAVIS_CONFIGURATION; if (file_exists($composerTravisLintCache) && file_exists($travisConfiguration)) { $travisConfigurationContent = trim(file_get_contents($travisConfiguration)); $composerTravisLintCacheContent = trim(file_get_contents($composerTravisLintCache)); if (md5($travisConfigurationContent) === $composerTravisLintCacheContent) { return false; } } return true; }
php
protected static function hasStaleCacheFile() { $composerTravisLintCache = getcwd() . DIRECTORY_SEPARATOR . self::CTL_CACHE; $travisConfiguration = getcwd() . DIRECTORY_SEPARATOR . self::TRAVIS_CONFIGURATION; if (file_exists($composerTravisLintCache) && file_exists($travisConfiguration)) { $travisConfigurationContent = trim(file_get_contents($travisConfiguration)); $composerTravisLintCacheContent = trim(file_get_contents($composerTravisLintCache)); if (md5($travisConfigurationContent) === $composerTravisLintCacheContent) { return false; } } return true; }
[ "protected", "static", "function", "hasStaleCacheFile", "(", ")", "{", "$", "composerTravisLintCache", "=", "getcwd", "(", ")", ".", "DIRECTORY_SEPARATOR", ".", "self", "::", "CTL_CACHE", ";", "$", "travisConfiguration", "=", "getcwd", "(", ")", ".", "DIRECTORY_SEPARATOR", ".", "self", "::", "TRAVIS_CONFIGURATION", ";", "if", "(", "file_exists", "(", "$", "composerTravisLintCache", ")", "&&", "file_exists", "(", "$", "travisConfiguration", ")", ")", "{", "$", "travisConfigurationContent", "=", "trim", "(", "file_get_contents", "(", "$", "travisConfiguration", ")", ")", ";", "$", "composerTravisLintCacheContent", "=", "trim", "(", "file_get_contents", "(", "$", "composerTravisLintCache", ")", ")", ";", "if", "(", "md5", "(", "$", "travisConfigurationContent", ")", "===", "$", "composerTravisLintCacheContent", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Check if composer travis lint cache is stale. @return boolean
[ "Check", "if", "composer", "travis", "lint", "cache", "is", "stale", "." ]
e6e005350b3c8981826aa718bc2282ddfd03caef
https://github.com/raphaelstolt/composer-travis-lint/blob/e6e005350b3c8981826aa718bc2282ddfd03caef/src/Travis.php#L20-L40
13,746
raphaelstolt/composer-travis-lint
src/Travis.php
Travis.lint
public static function lint(Event $event, Api $api = null) { $composerTravisLintCache = getcwd() . DIRECTORY_SEPARATOR . self::CTL_CACHE; $io = $event->getIO(); if (!file_exists(self::TRAVIS_CONFIGURATION)) { $io->writeError("Travis CI configuration doesn't exist."); return false; } if (self::hasStaleCacheFile() === false) { $message = 'Travis CI configuration has not ' . 'changed since the last lint run and is therefore valid.'; $io->write($message); return true; } $travisConfigContent = trim( file_get_contents(realpath(self::TRAVIS_CONFIGURATION)) ); if ($api === null) { $api = new Api(); } try { $result = $api->post($travisConfigContent); if ($result->isSuccessful()) { $message = 'Travis CI configuration is valid.'; $bytesWritten = file_put_contents( $composerTravisLintCache, md5($travisConfigContent) . "\n" ); if ($bytesWritten > 0) { $message .= PHP_EOL . "Created '" . self::CTL_CACHE . "' file."; } $io->write($message); return true; } $errorMessage = $result->getFailure(); if (file_exists($composerTravisLintCache)) { unlink($composerTravisLintCache); $errorMessage .= PHP_EOL . "Deleted '" . self::CTL_CACHE . "' file."; } $io->writeError($errorMessage); return false; } catch (ConnectivityFailure $f) { $io->writeError($f->getMessage()); return false; } catch (NonExpectedReponseStructure $n) { $io->writeError($n->getMessage()); return false; } }
php
public static function lint(Event $event, Api $api = null) { $composerTravisLintCache = getcwd() . DIRECTORY_SEPARATOR . self::CTL_CACHE; $io = $event->getIO(); if (!file_exists(self::TRAVIS_CONFIGURATION)) { $io->writeError("Travis CI configuration doesn't exist."); return false; } if (self::hasStaleCacheFile() === false) { $message = 'Travis CI configuration has not ' . 'changed since the last lint run and is therefore valid.'; $io->write($message); return true; } $travisConfigContent = trim( file_get_contents(realpath(self::TRAVIS_CONFIGURATION)) ); if ($api === null) { $api = new Api(); } try { $result = $api->post($travisConfigContent); if ($result->isSuccessful()) { $message = 'Travis CI configuration is valid.'; $bytesWritten = file_put_contents( $composerTravisLintCache, md5($travisConfigContent) . "\n" ); if ($bytesWritten > 0) { $message .= PHP_EOL . "Created '" . self::CTL_CACHE . "' file."; } $io->write($message); return true; } $errorMessage = $result->getFailure(); if (file_exists($composerTravisLintCache)) { unlink($composerTravisLintCache); $errorMessage .= PHP_EOL . "Deleted '" . self::CTL_CACHE . "' file."; } $io->writeError($errorMessage); return false; } catch (ConnectivityFailure $f) { $io->writeError($f->getMessage()); return false; } catch (NonExpectedReponseStructure $n) { $io->writeError($n->getMessage()); return false; } }
[ "public", "static", "function", "lint", "(", "Event", "$", "event", ",", "Api", "$", "api", "=", "null", ")", "{", "$", "composerTravisLintCache", "=", "getcwd", "(", ")", ".", "DIRECTORY_SEPARATOR", ".", "self", "::", "CTL_CACHE", ";", "$", "io", "=", "$", "event", "->", "getIO", "(", ")", ";", "if", "(", "!", "file_exists", "(", "self", "::", "TRAVIS_CONFIGURATION", ")", ")", "{", "$", "io", "->", "writeError", "(", "\"Travis CI configuration doesn't exist.\"", ")", ";", "return", "false", ";", "}", "if", "(", "self", "::", "hasStaleCacheFile", "(", ")", "===", "false", ")", "{", "$", "message", "=", "'Travis CI configuration has not '", ".", "'changed since the last lint run and is therefore valid.'", ";", "$", "io", "->", "write", "(", "$", "message", ")", ";", "return", "true", ";", "}", "$", "travisConfigContent", "=", "trim", "(", "file_get_contents", "(", "realpath", "(", "self", "::", "TRAVIS_CONFIGURATION", ")", ")", ")", ";", "if", "(", "$", "api", "===", "null", ")", "{", "$", "api", "=", "new", "Api", "(", ")", ";", "}", "try", "{", "$", "result", "=", "$", "api", "->", "post", "(", "$", "travisConfigContent", ")", ";", "if", "(", "$", "result", "->", "isSuccessful", "(", ")", ")", "{", "$", "message", "=", "'Travis CI configuration is valid.'", ";", "$", "bytesWritten", "=", "file_put_contents", "(", "$", "composerTravisLintCache", ",", "md5", "(", "$", "travisConfigContent", ")", ".", "\"\\n\"", ")", ";", "if", "(", "$", "bytesWritten", ">", "0", ")", "{", "$", "message", ".=", "PHP_EOL", ".", "\"Created '\"", ".", "self", "::", "CTL_CACHE", ".", "\"' file.\"", ";", "}", "$", "io", "->", "write", "(", "$", "message", ")", ";", "return", "true", ";", "}", "$", "errorMessage", "=", "$", "result", "->", "getFailure", "(", ")", ";", "if", "(", "file_exists", "(", "$", "composerTravisLintCache", ")", ")", "{", "unlink", "(", "$", "composerTravisLintCache", ")", ";", "$", "errorMessage", ".=", "PHP_EOL", ".", "\"Deleted '\"", ".", "self", "::", "CTL_CACHE", ".", "\"' file.\"", ";", "}", "$", "io", "->", "writeError", "(", "$", "errorMessage", ")", ";", "return", "false", ";", "}", "catch", "(", "ConnectivityFailure", "$", "f", ")", "{", "$", "io", "->", "writeError", "(", "$", "f", "->", "getMessage", "(", ")", ")", ";", "return", "false", ";", "}", "catch", "(", "NonExpectedReponseStructure", "$", "n", ")", "{", "$", "io", "->", "writeError", "(", "$", "n", "->", "getMessage", "(", ")", ")", ";", "return", "false", ";", "}", "}" ]
The Composer script to lint a Travis CI configuration file. @param Event $event @param Api|null $api @return boolean
[ "The", "Composer", "script", "to", "lint", "a", "Travis", "CI", "configuration", "file", "." ]
e6e005350b3c8981826aa718bc2282ddfd03caef
https://github.com/raphaelstolt/composer-travis-lint/blob/e6e005350b3c8981826aa718bc2282ddfd03caef/src/Travis.php#L49-L118
13,747
crysalead/net
src/Http/Auth.php
Auth.header
public static function header($data) { if (empty($data['response'])) { throw new NetException("Can't create Authorization headers from an empty response."); } if (!isset($data['nonce'])) { return "Basic " . $data['response']; } $defaults = [ 'realm' => 'app', 'method' => 'GET', 'uri' => '/', 'username' => null, 'qop' => 'auth', 'nonce' => null, 'opaque' => null, 'cnonce' => md5(time()), 'nc' => static::$nc ]; $data += $defaults; $auth = "username=\"{$data['username']}\", response=\"{$data['response']}\", "; $auth .= "uri=\"{$data['uri']}\", realm=\"{$data['realm']}\", "; $auth .= "qop=\"{$data['qop']}\", nc={$data['nc']}, cnonce=\"{$data['cnonce']}\", "; $auth .= "nonce=\"{$data['nonce']}\", opaque=\"{$data['opaque']}\""; return "Digest " . $auth; }
php
public static function header($data) { if (empty($data['response'])) { throw new NetException("Can't create Authorization headers from an empty response."); } if (!isset($data['nonce'])) { return "Basic " . $data['response']; } $defaults = [ 'realm' => 'app', 'method' => 'GET', 'uri' => '/', 'username' => null, 'qop' => 'auth', 'nonce' => null, 'opaque' => null, 'cnonce' => md5(time()), 'nc' => static::$nc ]; $data += $defaults; $auth = "username=\"{$data['username']}\", response=\"{$data['response']}\", "; $auth .= "uri=\"{$data['uri']}\", realm=\"{$data['realm']}\", "; $auth .= "qop=\"{$data['qop']}\", nc={$data['nc']}, cnonce=\"{$data['cnonce']}\", "; $auth .= "nonce=\"{$data['nonce']}\", opaque=\"{$data['opaque']}\""; return "Digest " . $auth; }
[ "public", "static", "function", "header", "(", "$", "data", ")", "{", "if", "(", "empty", "(", "$", "data", "[", "'response'", "]", ")", ")", "{", "throw", "new", "NetException", "(", "\"Can't create Authorization headers from an empty response.\"", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "data", "[", "'nonce'", "]", ")", ")", "{", "return", "\"Basic \"", ".", "$", "data", "[", "'response'", "]", ";", "}", "$", "defaults", "=", "[", "'realm'", "=>", "'app'", ",", "'method'", "=>", "'GET'", ",", "'uri'", "=>", "'/'", ",", "'username'", "=>", "null", ",", "'qop'", "=>", "'auth'", ",", "'nonce'", "=>", "null", ",", "'opaque'", "=>", "null", ",", "'cnonce'", "=>", "md5", "(", "time", "(", ")", ")", ",", "'nc'", "=>", "static", "::", "$", "nc", "]", ";", "$", "data", "+=", "$", "defaults", ";", "$", "auth", "=", "\"username=\\\"{$data['username']}\\\", response=\\\"{$data['response']}\\\", \"", ";", "$", "auth", ".=", "\"uri=\\\"{$data['uri']}\\\", realm=\\\"{$data['realm']}\\\", \"", ";", "$", "auth", ".=", "\"qop=\\\"{$data['qop']}\\\", nc={$data['nc']}, cnonce=\\\"{$data['cnonce']}\\\", \"", ";", "$", "auth", ".=", "\"nonce=\\\"{$data['nonce']}\\\", opaque=\\\"{$data['opaque']}\\\"\"", ";", "return", "\"Digest \"", ".", "$", "auth", ";", "}" ]
Returns the proper header string. Accepts the data from the `encode` method. @param array $data @return string
[ "Returns", "the", "proper", "header", "string", ".", "Accepts", "the", "data", "from", "the", "encode", "method", "." ]
4d75abead39e954529b56cbffa3841a9cd3044bb
https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Auth.php#L24-L44
13,748
crysalead/net
src/Http/Auth.php
Auth.encode
public static function encode($username, $password, $data = []) { if (!isset($data['nonce'])) { $response = base64_encode("{$username}:{$password}"); return compact('username', 'response'); } $defaults = [ 'realm' => 'app', 'method' => 'GET', 'uri' => '/', 'qop' => null, 'cnonce' => md5(time()), 'nc' => static::$nc ]; $data = array_filter($data) + $defaults; $part1 = md5("{$username}:{$data['realm']}:{$password}"); $part2 = "{$data['nonce']}:{$data['nc']}:{$data['cnonce']}:{$data['qop']}"; $part3 = md5($data['method'] . ':' . $data['uri']); $response = md5("{$part1}:{$part2}:{$part3}"); return compact('username', 'response') + $data; }
php
public static function encode($username, $password, $data = []) { if (!isset($data['nonce'])) { $response = base64_encode("{$username}:{$password}"); return compact('username', 'response'); } $defaults = [ 'realm' => 'app', 'method' => 'GET', 'uri' => '/', 'qop' => null, 'cnonce' => md5(time()), 'nc' => static::$nc ]; $data = array_filter($data) + $defaults; $part1 = md5("{$username}:{$data['realm']}:{$password}"); $part2 = "{$data['nonce']}:{$data['nc']}:{$data['cnonce']}:{$data['qop']}"; $part3 = md5($data['method'] . ':' . $data['uri']); $response = md5("{$part1}:{$part2}:{$part3}"); return compact('username', 'response') + $data; }
[ "public", "static", "function", "encode", "(", "$", "username", ",", "$", "password", ",", "$", "data", "=", "[", "]", ")", "{", "if", "(", "!", "isset", "(", "$", "data", "[", "'nonce'", "]", ")", ")", "{", "$", "response", "=", "base64_encode", "(", "\"{$username}:{$password}\"", ")", ";", "return", "compact", "(", "'username'", ",", "'response'", ")", ";", "}", "$", "defaults", "=", "[", "'realm'", "=>", "'app'", ",", "'method'", "=>", "'GET'", ",", "'uri'", "=>", "'/'", ",", "'qop'", "=>", "null", ",", "'cnonce'", "=>", "md5", "(", "time", "(", ")", ")", ",", "'nc'", "=>", "static", "::", "$", "nc", "]", ";", "$", "data", "=", "array_filter", "(", "$", "data", ")", "+", "$", "defaults", ";", "$", "part1", "=", "md5", "(", "\"{$username}:{$data['realm']}:{$password}\"", ")", ";", "$", "part2", "=", "\"{$data['nonce']}:{$data['nc']}:{$data['cnonce']}:{$data['qop']}\"", ";", "$", "part3", "=", "md5", "(", "$", "data", "[", "'method'", "]", ".", "':'", ".", "$", "data", "[", "'uri'", "]", ")", ";", "$", "response", "=", "md5", "(", "\"{$part1}:{$part2}:{$part3}\"", ")", ";", "return", "compact", "(", "'username'", ",", "'response'", ")", "+", "$", "data", ";", "}" ]
Encodes the data with username and password to create the proper response. Returns an array containing the username and encoded response. @param string $username Username to authenticate with @param string $password Password to authenticate with @param array $data Params needed to hash the response @return array
[ "Encodes", "the", "data", "with", "username", "and", "password", "to", "create", "the", "proper", "response", ".", "Returns", "an", "array", "containing", "the", "username", "and", "encoded", "response", "." ]
4d75abead39e954529b56cbffa3841a9cd3044bb
https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Auth.php#L55-L71
13,749
crysalead/net
src/Http/Auth.php
Auth.decode
public static function decode($header) { $data = [ 'realm' => null, 'username' => null, 'uri' => null, 'nonce' => null, 'opaque' => null, 'qop' => null, 'cnonce' => null, 'nc' => null, 'response' => null ]; $keys = implode('|', array_keys($data)); $regex = '~(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))~'; preg_match_all($regex, $header, $matches, PREG_SET_ORDER); foreach ($matches as $m) { $data[$m[1]] = $m[3] ? $m[3] : $m[4]; } return $data; }
php
public static function decode($header) { $data = [ 'realm' => null, 'username' => null, 'uri' => null, 'nonce' => null, 'opaque' => null, 'qop' => null, 'cnonce' => null, 'nc' => null, 'response' => null ]; $keys = implode('|', array_keys($data)); $regex = '~(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))~'; preg_match_all($regex, $header, $matches, PREG_SET_ORDER); foreach ($matches as $m) { $data[$m[1]] = $m[3] ? $m[3] : $m[4]; } return $data; }
[ "public", "static", "function", "decode", "(", "$", "header", ")", "{", "$", "data", "=", "[", "'realm'", "=>", "null", ",", "'username'", "=>", "null", ",", "'uri'", "=>", "null", ",", "'nonce'", "=>", "null", ",", "'opaque'", "=>", "null", ",", "'qop'", "=>", "null", ",", "'cnonce'", "=>", "null", ",", "'nc'", "=>", "null", ",", "'response'", "=>", "null", "]", ";", "$", "keys", "=", "implode", "(", "'|'", ",", "array_keys", "(", "$", "data", ")", ")", ";", "$", "regex", "=", "'~('", ".", "$", "keys", ".", "')=(?:([\\'\"])([^\\2]+?)\\2|([^\\s,]+))~'", ";", "preg_match_all", "(", "$", "regex", ",", "$", "header", ",", "$", "matches", ",", "PREG_SET_ORDER", ")", ";", "foreach", "(", "$", "matches", "as", "$", "m", ")", "{", "$", "data", "[", "$", "m", "[", "1", "]", "]", "=", "$", "m", "[", "3", "]", "?", "$", "m", "[", "3", "]", ":", "$", "m", "[", "4", "]", ";", "}", "return", "$", "data", ";", "}" ]
Takes the header string and parses out the params needed for a digest authentication. @param string $header @return array
[ "Takes", "the", "header", "string", "and", "parses", "out", "the", "params", "needed", "for", "a", "digest", "authentication", "." ]
4d75abead39e954529b56cbffa3841a9cd3044bb
https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Auth.php#L79-L100
13,750
fuelphp/filesystem
src/Finder.php
Finder.setRoot
public function setRoot($root) { if ( ! $path = realpath($root)) { throw new \Exception('Location does not exist: '.$root); } $this->root = $path; }
php
public function setRoot($root) { if ( ! $path = realpath($root)) { throw new \Exception('Location does not exist: '.$root); } $this->root = $path; }
[ "public", "function", "setRoot", "(", "$", "root", ")", "{", "if", "(", "!", "$", "path", "=", "realpath", "(", "$", "root", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Location does not exist: '", ".", "$", "root", ")", ";", "}", "$", "this", "->", "root", "=", "$", "path", ";", "}" ]
Sets a root restriction @param string $root
[ "Sets", "a", "root", "restriction" ]
770a8cb04caca920af8029d7aad7208bc0592743
https://github.com/fuelphp/filesystem/blob/770a8cb04caca920af8029d7aad7208bc0592743/src/Finder.php#L107-L115
13,751
fuelphp/filesystem
src/Finder.php
Finder.addPaths
public function addPaths(array $paths, $clearCache = true, $group = '__DEFAULT__') { array_map([$this, 'addPath'], $paths, [[$clearCache, $group]]); }
php
public function addPaths(array $paths, $clearCache = true, $group = '__DEFAULT__') { array_map([$this, 'addPath'], $paths, [[$clearCache, $group]]); }
[ "public", "function", "addPaths", "(", "array", "$", "paths", ",", "$", "clearCache", "=", "true", ",", "$", "group", "=", "'__DEFAULT__'", ")", "{", "array_map", "(", "[", "$", "this", ",", "'addPath'", "]", ",", "$", "paths", ",", "[", "[", "$", "clearCache", ",", "$", "group", "]", "]", ")", ";", "}" ]
Adds paths to look in @param array $paths @param boolean $clearCache
[ "Adds", "paths", "to", "look", "in" ]
770a8cb04caca920af8029d7aad7208bc0592743
https://github.com/fuelphp/filesystem/blob/770a8cb04caca920af8029d7aad7208bc0592743/src/Finder.php#L123-L126
13,752
fuelphp/filesystem
src/Finder.php
Finder.removePaths
public function removePaths(array $paths, $clearCache = true, $group = '__DEFAULT__') { array_map([$this, 'removePath'], $paths, [[$clearCache, $group]]); }
php
public function removePaths(array $paths, $clearCache = true, $group = '__DEFAULT__') { array_map([$this, 'removePath'], $paths, [[$clearCache, $group]]); }
[ "public", "function", "removePaths", "(", "array", "$", "paths", ",", "$", "clearCache", "=", "true", ",", "$", "group", "=", "'__DEFAULT__'", ")", "{", "array_map", "(", "[", "$", "this", ",", "'removePath'", "]", ",", "$", "paths", ",", "[", "[", "$", "clearCache", ",", "$", "group", "]", "]", ")", ";", "}" ]
Removes paths to look in @param array $paths
[ "Removes", "paths", "to", "look", "in" ]
770a8cb04caca920af8029d7aad7208bc0592743
https://github.com/fuelphp/filesystem/blob/770a8cb04caca920af8029d7aad7208bc0592743/src/Finder.php#L154-L157
13,753
fuelphp/filesystem
src/Finder.php
Finder.removePathCache
public function removePathCache($path) { foreach ($this->cache as $key => $cache) { if (in_array($path, $cache['used'])) { unset($this->cache[$key]); } } }
php
public function removePathCache($path) { foreach ($this->cache as $key => $cache) { if (in_array($path, $cache['used'])) { unset($this->cache[$key]); } } }
[ "public", "function", "removePathCache", "(", "$", "path", ")", "{", "foreach", "(", "$", "this", "->", "cache", "as", "$", "key", "=>", "$", "cache", ")", "{", "if", "(", "in_array", "(", "$", "path", ",", "$", "cache", "[", "'used'", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "cache", "[", "$", "key", "]", ")", ";", "}", "}", "}" ]
Removes path cache @param string $path
[ "Removes", "path", "cache" ]
770a8cb04caca920af8029d7aad7208bc0592743
https://github.com/fuelphp/filesystem/blob/770a8cb04caca920af8029d7aad7208bc0592743/src/Finder.php#L181-L190
13,754
fuelphp/filesystem
src/Finder.php
Finder.normalizePath
public function normalizePath($path) { $path = rtrim($path, '/\\').DIRECTORY_SEPARATOR; $path = realpath($path).DIRECTORY_SEPARATOR; if ($this->root and strpos($path, $this->root) !== 0) { throw new \Exception('Cannot access path outside: '.$this->root.'. Trying to access: '.$path); } return $path; }
php
public function normalizePath($path) { $path = rtrim($path, '/\\').DIRECTORY_SEPARATOR; $path = realpath($path).DIRECTORY_SEPARATOR; if ($this->root and strpos($path, $this->root) !== 0) { throw new \Exception('Cannot access path outside: '.$this->root.'. Trying to access: '.$path); } return $path; }
[ "public", "function", "normalizePath", "(", "$", "path", ")", "{", "$", "path", "=", "rtrim", "(", "$", "path", ",", "'/\\\\'", ")", ".", "DIRECTORY_SEPARATOR", ";", "$", "path", "=", "realpath", "(", "$", "path", ")", ".", "DIRECTORY_SEPARATOR", ";", "if", "(", "$", "this", "->", "root", "and", "strpos", "(", "$", "path", ",", "$", "this", "->", "root", ")", "!==", "0", ")", "{", "throw", "new", "\\", "Exception", "(", "'Cannot access path outside: '", ".", "$", "this", "->", "root", ".", "'. Trying to access: '", ".", "$", "path", ")", ";", "}", "return", "$", "path", ";", "}" ]
Normalizes a path @param string $path @return string @throws \Exception
[ "Normalizes", "a", "path" ]
770a8cb04caca920af8029d7aad7208bc0592743
https://github.com/fuelphp/filesystem/blob/770a8cb04caca920af8029d7aad7208bc0592743/src/Finder.php#L201-L212
13,755
fuelphp/filesystem
src/Finder.php
Finder.getPaths
public function getPaths($group = '__DEFAULT__') { if ( ! isset($this->paths[$group])) { return []; } return array_values($this->paths[$group]); }
php
public function getPaths($group = '__DEFAULT__') { if ( ! isset($this->paths[$group])) { return []; } return array_values($this->paths[$group]); }
[ "public", "function", "getPaths", "(", "$", "group", "=", "'__DEFAULT__'", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "paths", "[", "$", "group", "]", ")", ")", "{", "return", "[", "]", ";", "}", "return", "array_values", "(", "$", "this", "->", "paths", "[", "$", "group", "]", ")", ";", "}" ]
Returns the paths set up to look in @return array
[ "Returns", "the", "paths", "set", "up", "to", "look", "in" ]
770a8cb04caca920af8029d7aad7208bc0592743
https://github.com/fuelphp/filesystem/blob/770a8cb04caca920af8029d7aad7208bc0592743/src/Finder.php#L219-L227
13,756
fuelphp/filesystem
src/Finder.php
Finder.setPaths
public function setPaths(array $paths, $clearCache = true, $group = '__DEFAULT__') { $this->paths[$group] = []; $this->addPaths($paths, false, $group); if ($clearCache) { $this->cache = []; } }
php
public function setPaths(array $paths, $clearCache = true, $group = '__DEFAULT__') { $this->paths[$group] = []; $this->addPaths($paths, false, $group); if ($clearCache) { $this->cache = []; } }
[ "public", "function", "setPaths", "(", "array", "$", "paths", ",", "$", "clearCache", "=", "true", ",", "$", "group", "=", "'__DEFAULT__'", ")", "{", "$", "this", "->", "paths", "[", "$", "group", "]", "=", "[", "]", ";", "$", "this", "->", "addPaths", "(", "$", "paths", ",", "false", ",", "$", "group", ")", ";", "if", "(", "$", "clearCache", ")", "{", "$", "this", "->", "cache", "=", "[", "]", ";", "}", "}" ]
Replaces all the paths @param array $paths
[ "Replaces", "all", "the", "paths" ]
770a8cb04caca920af8029d7aad7208bc0592743
https://github.com/fuelphp/filesystem/blob/770a8cb04caca920af8029d7aad7208bc0592743/src/Finder.php#L244-L253
13,757
fuelphp/filesystem
src/Finder.php
Finder.findCached
public function findCached($scope, $name, $reversed) { $cacheKey = $this->makeCacheKey($scope, $name, $reversed); if (isset($this->cache[$cacheKey])) { return $this->cache[$cacheKey]['result']; } }
php
public function findCached($scope, $name, $reversed) { $cacheKey = $this->makeCacheKey($scope, $name, $reversed); if (isset($this->cache[$cacheKey])) { return $this->cache[$cacheKey]['result']; } }
[ "public", "function", "findCached", "(", "$", "scope", ",", "$", "name", ",", "$", "reversed", ")", "{", "$", "cacheKey", "=", "$", "this", "->", "makeCacheKey", "(", "$", "scope", ",", "$", "name", ",", "$", "reversed", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "cache", "[", "$", "cacheKey", "]", ")", ")", "{", "return", "$", "this", "->", "cache", "[", "$", "cacheKey", "]", "[", "'result'", "]", ";", "}", "}" ]
Retrieves a location from cache @param string $scope @param string $name @param boolean $reversed @return string|array
[ "Retrieves", "a", "location", "from", "cache" ]
770a8cb04caca920af8029d7aad7208bc0592743
https://github.com/fuelphp/filesystem/blob/770a8cb04caca920af8029d7aad7208bc0592743/src/Finder.php#L533-L541
13,758
fuelphp/filesystem
src/Finder.php
Finder.cache
public function cache($scope, $name, $reversed, $result, $pathsUsed = []) { $cacheKey = $this->makeCacheKey($scope, $name, $reversed); $this->cache[$cacheKey] = [ 'result' => $result, 'used' => $pathsUsed, ]; }
php
public function cache($scope, $name, $reversed, $result, $pathsUsed = []) { $cacheKey = $this->makeCacheKey($scope, $name, $reversed); $this->cache[$cacheKey] = [ 'result' => $result, 'used' => $pathsUsed, ]; }
[ "public", "function", "cache", "(", "$", "scope", ",", "$", "name", ",", "$", "reversed", ",", "$", "result", ",", "$", "pathsUsed", "=", "[", "]", ")", "{", "$", "cacheKey", "=", "$", "this", "->", "makeCacheKey", "(", "$", "scope", ",", "$", "name", ",", "$", "reversed", ")", ";", "$", "this", "->", "cache", "[", "$", "cacheKey", "]", "=", "[", "'result'", "=>", "$", "result", ",", "'used'", "=>", "$", "pathsUsed", ",", "]", ";", "}" ]
Caches a find result @param string $scope @param string $name @param boolean $reversed @param array $pathsUsed
[ "Caches", "a", "find", "result" ]
770a8cb04caca920af8029d7aad7208bc0592743
https://github.com/fuelphp/filesystem/blob/770a8cb04caca920af8029d7aad7208bc0592743/src/Finder.php#L559-L566
13,759
fuelphp/filesystem
src/Finder.php
Finder.makeCacheKey
public function makeCacheKey($scope, $name, $reversed) { $cacheKey = $scope.'::'.$name; if ($reversed) { $cacheKey .= '::reversed'; } return $cacheKey; }
php
public function makeCacheKey($scope, $name, $reversed) { $cacheKey = $scope.'::'.$name; if ($reversed) { $cacheKey .= '::reversed'; } return $cacheKey; }
[ "public", "function", "makeCacheKey", "(", "$", "scope", ",", "$", "name", ",", "$", "reversed", ")", "{", "$", "cacheKey", "=", "$", "scope", ".", "'::'", ".", "$", "name", ";", "if", "(", "$", "reversed", ")", "{", "$", "cacheKey", ".=", "'::reversed'", ";", "}", "return", "$", "cacheKey", ";", "}" ]
Generates a cache key @param string $scope @param string $name @param boolean $reversed @return string
[ "Generates", "a", "cache", "key" ]
770a8cb04caca920af8029d7aad7208bc0592743
https://github.com/fuelphp/filesystem/blob/770a8cb04caca920af8029d7aad7208bc0592743/src/Finder.php#L577-L587
13,760
crysalead/net
src/Http/Response.php
Response.negotiate
public function negotiate($request) { $media = $this->_classes['media']; foreach ($request->accepts() as $mime => $value) { if ($format = $media::suitable($request, $mime)) { $this->format($format); return; } } $mimes = join('", "', array_keys($request->accepts())); throw new NetException("Unsupported Media Type: [\"{$mimes}\"].", 415); }
php
public function negotiate($request) { $media = $this->_classes['media']; foreach ($request->accepts() as $mime => $value) { if ($format = $media::suitable($request, $mime)) { $this->format($format); return; } } $mimes = join('", "', array_keys($request->accepts())); throw new NetException("Unsupported Media Type: [\"{$mimes}\"].", 415); }
[ "public", "function", "negotiate", "(", "$", "request", ")", "{", "$", "media", "=", "$", "this", "->", "_classes", "[", "'media'", "]", ";", "foreach", "(", "$", "request", "->", "accepts", "(", ")", "as", "$", "mime", "=>", "$", "value", ")", "{", "if", "(", "$", "format", "=", "$", "media", "::", "suitable", "(", "$", "request", ",", "$", "mime", ")", ")", "{", "$", "this", "->", "format", "(", "$", "format", ")", ";", "return", ";", "}", "}", "$", "mimes", "=", "join", "(", "'\", \"'", ",", "array_keys", "(", "$", "request", "->", "accepts", "(", ")", ")", ")", ";", "throw", "new", "NetException", "(", "\"Unsupported Media Type: [\\\"{$mimes}\\\"].\"", ",", "415", ")", ";", "}" ]
Performs a format negotiation from a `Request` object, by iterating over the accepted content types in sequence, from most preferred to least. @param object $request A request instance .
[ "Performs", "a", "format", "negotiation", "from", "a", "Request", "object", "by", "iterating", "over", "the", "accepted", "content", "types", "in", "sequence", "from", "most", "preferred", "to", "least", "." ]
4d75abead39e954529b56cbffa3841a9cd3044bb
https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Response.php#L110-L121
13,761
crysalead/net
src/Http/Response.php
Response.dump
public function dump() { $this->_setContentLength(); header($this->line()); $headers = $this->headers(); foreach ($headers as $header) { header($header->to('header')); } if ($headers['Transfer-Encoding']->value() === 'chunked') { return; } if ($this->_stream->isSeekable()) { $this->_stream->rewind(); } while (!$this->_stream->eof()) { echo $this->_stream->read(); if (connection_status() !== CONNECTION_NORMAL) { break; } } }
php
public function dump() { $this->_setContentLength(); header($this->line()); $headers = $this->headers(); foreach ($headers as $header) { header($header->to('header')); } if ($headers['Transfer-Encoding']->value() === 'chunked') { return; } if ($this->_stream->isSeekable()) { $this->_stream->rewind(); } while (!$this->_stream->eof()) { echo $this->_stream->read(); if (connection_status() !== CONNECTION_NORMAL) { break; } } }
[ "public", "function", "dump", "(", ")", "{", "$", "this", "->", "_setContentLength", "(", ")", ";", "header", "(", "$", "this", "->", "line", "(", ")", ")", ";", "$", "headers", "=", "$", "this", "->", "headers", "(", ")", ";", "foreach", "(", "$", "headers", "as", "$", "header", ")", "{", "header", "(", "$", "header", "->", "to", "(", "'header'", ")", ")", ";", "}", "if", "(", "$", "headers", "[", "'Transfer-Encoding'", "]", "->", "value", "(", ")", "===", "'chunked'", ")", "{", "return", ";", "}", "if", "(", "$", "this", "->", "_stream", "->", "isSeekable", "(", ")", ")", "{", "$", "this", "->", "_stream", "->", "rewind", "(", ")", ";", "}", "while", "(", "!", "$", "this", "->", "_stream", "->", "eof", "(", ")", ")", "{", "echo", "$", "this", "->", "_stream", "->", "read", "(", ")", ";", "if", "(", "connection_status", "(", ")", "!==", "CONNECTION_NORMAL", ")", "{", "break", ";", "}", "}", "}" ]
Renders a response by writing headers and output. @see https://bugs.php.net/bug.php?id=18029
[ "Renders", "a", "response", "by", "writing", "headers", "and", "output", "." ]
4d75abead39e954529b56cbffa3841a9cd3044bb
https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Response.php#L243-L263
13,762
crysalead/net
src/Http/Response.php
Response.push
public function push($data, $atomic = true, $options = []) { $headers = $this->headers(); if ($headers['Transfer-Encoding']->value() !== 'chunked') { throw new NetException("Pushing is only supported in chunked transfer."); } $defaults = [ 'cast' => true, 'atomic' => true, 'stream' => [], 'encode' => [] ]; $options += $defaults; if ($data instanceof StreamInterface) { $stream = $data; } else { if ($options['cast']) { $media = $this->_classes['media']; $format = $this->format(); if (!$format && !is_string($data)) { throw new NetException("The data must be a string when no format is defined."); } $data = $media::encode($format, $data, $options['encode'], $this); } $stream = new Part(['data' => $data] + $options['stream']); } $length = $options['atomic'] && $stream->isSeekable() ? $stream->length() : $this->chunkSize(); if ($stream->isSeekable()) { $stream->rewind(); } while (!$stream->eof()) { $chunk = $stream->read($length); $readed = strlen($chunk); if (!$readed) { break; } echo dechex($readed) . "\r\n" . $chunk . "\r\n"; if (connection_status() !== CONNECTION_NORMAL) { break; } } $stream->close(); }
php
public function push($data, $atomic = true, $options = []) { $headers = $this->headers(); if ($headers['Transfer-Encoding']->value() !== 'chunked') { throw new NetException("Pushing is only supported in chunked transfer."); } $defaults = [ 'cast' => true, 'atomic' => true, 'stream' => [], 'encode' => [] ]; $options += $defaults; if ($data instanceof StreamInterface) { $stream = $data; } else { if ($options['cast']) { $media = $this->_classes['media']; $format = $this->format(); if (!$format && !is_string($data)) { throw new NetException("The data must be a string when no format is defined."); } $data = $media::encode($format, $data, $options['encode'], $this); } $stream = new Part(['data' => $data] + $options['stream']); } $length = $options['atomic'] && $stream->isSeekable() ? $stream->length() : $this->chunkSize(); if ($stream->isSeekable()) { $stream->rewind(); } while (!$stream->eof()) { $chunk = $stream->read($length); $readed = strlen($chunk); if (!$readed) { break; } echo dechex($readed) . "\r\n" . $chunk . "\r\n"; if (connection_status() !== CONNECTION_NORMAL) { break; } } $stream->close(); }
[ "public", "function", "push", "(", "$", "data", ",", "$", "atomic", "=", "true", ",", "$", "options", "=", "[", "]", ")", "{", "$", "headers", "=", "$", "this", "->", "headers", "(", ")", ";", "if", "(", "$", "headers", "[", "'Transfer-Encoding'", "]", "->", "value", "(", ")", "!==", "'chunked'", ")", "{", "throw", "new", "NetException", "(", "\"Pushing is only supported in chunked transfer.\"", ")", ";", "}", "$", "defaults", "=", "[", "'cast'", "=>", "true", ",", "'atomic'", "=>", "true", ",", "'stream'", "=>", "[", "]", ",", "'encode'", "=>", "[", "]", "]", ";", "$", "options", "+=", "$", "defaults", ";", "if", "(", "$", "data", "instanceof", "StreamInterface", ")", "{", "$", "stream", "=", "$", "data", ";", "}", "else", "{", "if", "(", "$", "options", "[", "'cast'", "]", ")", "{", "$", "media", "=", "$", "this", "->", "_classes", "[", "'media'", "]", ";", "$", "format", "=", "$", "this", "->", "format", "(", ")", ";", "if", "(", "!", "$", "format", "&&", "!", "is_string", "(", "$", "data", ")", ")", "{", "throw", "new", "NetException", "(", "\"The data must be a string when no format is defined.\"", ")", ";", "}", "$", "data", "=", "$", "media", "::", "encode", "(", "$", "format", ",", "$", "data", ",", "$", "options", "[", "'encode'", "]", ",", "$", "this", ")", ";", "}", "$", "stream", "=", "new", "Part", "(", "[", "'data'", "=>", "$", "data", "]", "+", "$", "options", "[", "'stream'", "]", ")", ";", "}", "$", "length", "=", "$", "options", "[", "'atomic'", "]", "&&", "$", "stream", "->", "isSeekable", "(", ")", "?", "$", "stream", "->", "length", "(", ")", ":", "$", "this", "->", "chunkSize", "(", ")", ";", "if", "(", "$", "stream", "->", "isSeekable", "(", ")", ")", "{", "$", "stream", "->", "rewind", "(", ")", ";", "}", "while", "(", "!", "$", "stream", "->", "eof", "(", ")", ")", "{", "$", "chunk", "=", "$", "stream", "->", "read", "(", "$", "length", ")", ";", "$", "readed", "=", "strlen", "(", "$", "chunk", ")", ";", "if", "(", "!", "$", "readed", ")", "{", "break", ";", "}", "echo", "dechex", "(", "$", "readed", ")", ".", "\"\\r\\n\"", ".", "$", "chunk", ".", "\"\\r\\n\"", ";", "if", "(", "connection_status", "(", ")", "!==", "CONNECTION_NORMAL", ")", "{", "break", ";", "}", "}", "$", "stream", "->", "close", "(", ")", ";", "}" ]
Push additionnal data to a chunked response. @param mixed $data The formated data. If the passed data is a stream it'll be closed. @param boolean $atomic Indicates if the $data can be chunked or must be send as a whole chunk.
[ "Push", "additionnal", "data", "to", "a", "chunked", "response", "." ]
4d75abead39e954529b56cbffa3841a9cd3044bb
https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Response.php#L271-L320
13,763
crysalead/net
src/Http/Response.php
Response.applyCookies
public function applyCookies($cookies) { $headers = $this->headers(); foreach ($cookies as $cookie) { $headers['Set-Cookie'][] = $cookie->toString(); } return $this; }
php
public function applyCookies($cookies) { $headers = $this->headers(); foreach ($cookies as $cookie) { $headers['Set-Cookie'][] = $cookie->toString(); } return $this; }
[ "public", "function", "applyCookies", "(", "$", "cookies", ")", "{", "$", "headers", "=", "$", "this", "->", "headers", "(", ")", ";", "foreach", "(", "$", "cookies", "as", "$", "cookie", ")", "{", "$", "headers", "[", "'Set-Cookie'", "]", "[", "]", "=", "$", "cookie", "->", "toString", "(", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the Set-Cookie header @param array $cookies The cookies. @return self
[ "Set", "the", "Set", "-", "Cookie", "header" ]
4d75abead39e954529b56cbffa3841a9cd3044bb
https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Response.php#L340-L348
13,764
crysalead/net
src/Http/Response.php
Response.cookies
public function cookies($request) { $headers = $response->headers(); if (!isset($headers['Set-Cookie'])) { return []; } $setCookies = []; foreach ($headers['Set-Cookie'] as $setCookieHeader) { $setCookie = Cookie::fromString($setCookieHeader); if (!$setCookie->domain()) { $setCookie->domain($request->hostname()); } if (strpos($setCookie->path(), '/') !== 0) { $setCookie->path($this->_pathFrom($request)); } $setCookies[] = $setCookie; } return $setCookies; }
php
public function cookies($request) { $headers = $response->headers(); if (!isset($headers['Set-Cookie'])) { return []; } $setCookies = []; foreach ($headers['Set-Cookie'] as $setCookieHeader) { $setCookie = Cookie::fromString($setCookieHeader); if (!$setCookie->domain()) { $setCookie->domain($request->hostname()); } if (strpos($setCookie->path(), '/') !== 0) { $setCookie->path($this->_pathFrom($request)); } $setCookies[] = $setCookie; } return $setCookies; }
[ "public", "function", "cookies", "(", "$", "request", ")", "{", "$", "headers", "=", "$", "response", "->", "headers", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "headers", "[", "'Set-Cookie'", "]", ")", ")", "{", "return", "[", "]", ";", "}", "$", "setCookies", "=", "[", "]", ";", "foreach", "(", "$", "headers", "[", "'Set-Cookie'", "]", "as", "$", "setCookieHeader", ")", "{", "$", "setCookie", "=", "Cookie", "::", "fromString", "(", "$", "setCookieHeader", ")", ";", "if", "(", "!", "$", "setCookie", "->", "domain", "(", ")", ")", "{", "$", "setCookie", "->", "domain", "(", "$", "request", "->", "hostname", "(", ")", ")", ";", "}", "if", "(", "strpos", "(", "$", "setCookie", "->", "path", "(", ")", ",", "'/'", ")", "!==", "0", ")", "{", "$", "setCookie", "->", "path", "(", "$", "this", "->", "_pathFrom", "(", "$", "request", ")", ")", ";", "}", "$", "setCookies", "[", "]", "=", "$", "setCookie", ";", "}", "return", "$", "setCookies", ";", "}" ]
Extract cookies. @return array The cookies array.
[ "Extract", "cookies", "." ]
4d75abead39e954529b56cbffa3841a9cd3044bb
https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Response.php#L355-L373
13,765
crysalead/net
src/Http/Response.php
Response.redirect
public function redirect($location, $status = 302) { if (!$location) { return; } $this->status($status); $headers = $this->headers(); $headers['Location'] = $location; return $this; }
php
public function redirect($location, $status = 302) { if (!$location) { return; } $this->status($status); $headers = $this->headers(); $headers['Location'] = $location; return $this; }
[ "public", "function", "redirect", "(", "$", "location", ",", "$", "status", "=", "302", ")", "{", "if", "(", "!", "$", "location", ")", "{", "return", ";", "}", "$", "this", "->", "status", "(", "$", "status", ")", ";", "$", "headers", "=", "$", "this", "->", "headers", "(", ")", ";", "$", "headers", "[", "'Location'", "]", "=", "$", "location", ";", "return", "$", "this", ";", "}" ]
Set a redirect location. @param string $location The redirect location. @param integer $status The redirect HTTP status.
[ "Set", "a", "redirect", "location", "." ]
4d75abead39e954529b56cbffa3841a9cd3044bb
https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Response.php#L381-L390
13,766
crysalead/net
src/Http/Response.php
Response.export
public function export($options = []) { $this->_setContentLength(); return [ 'status' => $this->status(), 'version' => $this->version(), 'headers' => $this->headers(), 'body' => $this->stream() ]; }
php
public function export($options = []) { $this->_setContentLength(); return [ 'status' => $this->status(), 'version' => $this->version(), 'headers' => $this->headers(), 'body' => $this->stream() ]; }
[ "public", "function", "export", "(", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "_setContentLength", "(", ")", ";", "return", "[", "'status'", "=>", "$", "this", "->", "status", "(", ")", ",", "'version'", "=>", "$", "this", "->", "version", "(", ")", ",", "'headers'", "=>", "$", "this", "->", "headers", "(", ")", ",", "'body'", "=>", "$", "this", "->", "stream", "(", ")", "]", ";", "}" ]
Exports a `Response` instance to an array. @param array $options Options. @return array The export array.
[ "Exports", "a", "Response", "instance", "to", "an", "array", "." ]
4d75abead39e954529b56cbffa3841a9cd3044bb
https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Response.php#L398-L407
13,767
crysalead/net
src/Http/Response.php
Response.parse
public static function parse($message, $options = []) { $parts = explode("\r\n\r\n", $message, 2); if (count($parts) < 2) { throw new NetException("The CRLFCRLF separator between headers and body is missing."); } $response = new static($options + ['format' => null]); list($header, $body) = $parts; $data = str_replace("\r", '', explode("\n", $header)); $data = array_filter($data); preg_match('/HTTP\/(\d+\.\d+)\s+(\d+)(?:\s+(.*))?/i', array_shift($data), $matches); $headers = $response->headers(); $headers->push($data); if ($matches) { $response->version($matches[1]); $response->status([$matches[2], isset($matches[3]) ? $matches[3] : '']); } if ($headers['Transfer-Encoding']->value() === 'chunked') { $decoded = ''; while (!empty($body)) { $pos = strpos($body, "\r\n"); $len = hexdec(substr($body, 0, $pos)); $decoded .= substr($body, $pos + 2, $len); $body = substr($body, $pos + 2 + $len); } $body = $decoded; } $response->body($body); return $response; }
php
public static function parse($message, $options = []) { $parts = explode("\r\n\r\n", $message, 2); if (count($parts) < 2) { throw new NetException("The CRLFCRLF separator between headers and body is missing."); } $response = new static($options + ['format' => null]); list($header, $body) = $parts; $data = str_replace("\r", '', explode("\n", $header)); $data = array_filter($data); preg_match('/HTTP\/(\d+\.\d+)\s+(\d+)(?:\s+(.*))?/i', array_shift($data), $matches); $headers = $response->headers(); $headers->push($data); if ($matches) { $response->version($matches[1]); $response->status([$matches[2], isset($matches[3]) ? $matches[3] : '']); } if ($headers['Transfer-Encoding']->value() === 'chunked') { $decoded = ''; while (!empty($body)) { $pos = strpos($body, "\r\n"); $len = hexdec(substr($body, 0, $pos)); $decoded .= substr($body, $pos + 2, $len); $body = substr($body, $pos + 2 + $len); } $body = $decoded; } $response->body($body); return $response; }
[ "public", "static", "function", "parse", "(", "$", "message", ",", "$", "options", "=", "[", "]", ")", "{", "$", "parts", "=", "explode", "(", "\"\\r\\n\\r\\n\"", ",", "$", "message", ",", "2", ")", ";", "if", "(", "count", "(", "$", "parts", ")", "<", "2", ")", "{", "throw", "new", "NetException", "(", "\"The CRLFCRLF separator between headers and body is missing.\"", ")", ";", "}", "$", "response", "=", "new", "static", "(", "$", "options", "+", "[", "'format'", "=>", "null", "]", ")", ";", "list", "(", "$", "header", ",", "$", "body", ")", "=", "$", "parts", ";", "$", "data", "=", "str_replace", "(", "\"\\r\"", ",", "''", ",", "explode", "(", "\"\\n\"", ",", "$", "header", ")", ")", ";", "$", "data", "=", "array_filter", "(", "$", "data", ")", ";", "preg_match", "(", "'/HTTP\\/(\\d+\\.\\d+)\\s+(\\d+)(?:\\s+(.*))?/i'", ",", "array_shift", "(", "$", "data", ")", ",", "$", "matches", ")", ";", "$", "headers", "=", "$", "response", "->", "headers", "(", ")", ";", "$", "headers", "->", "push", "(", "$", "data", ")", ";", "if", "(", "$", "matches", ")", "{", "$", "response", "->", "version", "(", "$", "matches", "[", "1", "]", ")", ";", "$", "response", "->", "status", "(", "[", "$", "matches", "[", "2", "]", ",", "isset", "(", "$", "matches", "[", "3", "]", ")", "?", "$", "matches", "[", "3", "]", ":", "''", "]", ")", ";", "}", "if", "(", "$", "headers", "[", "'Transfer-Encoding'", "]", "->", "value", "(", ")", "===", "'chunked'", ")", "{", "$", "decoded", "=", "''", ";", "while", "(", "!", "empty", "(", "$", "body", ")", ")", "{", "$", "pos", "=", "strpos", "(", "$", "body", ",", "\"\\r\\n\"", ")", ";", "$", "len", "=", "hexdec", "(", "substr", "(", "$", "body", ",", "0", ",", "$", "pos", ")", ")", ";", "$", "decoded", ".=", "substr", "(", "$", "body", ",", "$", "pos", "+", "2", ",", "$", "len", ")", ";", "$", "body", "=", "substr", "(", "$", "body", ",", "$", "pos", "+", "2", "+", "$", "len", ")", ";", "}", "$", "body", "=", "$", "decoded", ";", "}", "$", "response", "->", "body", "(", "$", "body", ")", ";", "return", "$", "response", ";", "}" ]
Creates a response instance from an entire HTTP message including HTTP status headers and body. @param string $message The full HTTP message. @param string $options Additionnal options. @return object Returns a request instance.
[ "Creates", "a", "response", "instance", "from", "an", "entire", "HTTP", "message", "including", "HTTP", "status", "headers", "and", "body", "." ]
4d75abead39e954529b56cbffa3841a9cd3044bb
https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Http/Response.php#L416-L452
13,768
crysalead/net
src/Mime/Mime.php
Mime.encode
public static function encode($body, $encoding, $wrapWidth = 76, $le = "\r\n", $cut = false) { $encoding = strtolower($encoding); switch ($encoding) { case 'quoted-printable': $body = quoted_printable_encode($body); return $wrapWidth ? rtrim(chunk_split($body, $wrapWidth, $le)) : $body; break; case 'base64': $body = base64_encode($body); return $wrapWidth ? rtrim(chunk_split($body, $wrapWidth, $le)) : $body; break; case '7bit': if (preg_match('~[^\x00-\x7F]~', $body)) { throw new RuntimeException("Can't use `'{$encoding}'` encoding, non 7 bit characters detected."); } case '8bit': case 'binary': $body = ltrim(str_replace("\r", '', $body), "\n"); return $wrapWidth ? wordwrap($body, $wrapWidth, "\n", $cut) : $body; break; default: throw new InvalidArgumentException("Unsupported encoding `'{$encoding}'`."); break; } }
php
public static function encode($body, $encoding, $wrapWidth = 76, $le = "\r\n", $cut = false) { $encoding = strtolower($encoding); switch ($encoding) { case 'quoted-printable': $body = quoted_printable_encode($body); return $wrapWidth ? rtrim(chunk_split($body, $wrapWidth, $le)) : $body; break; case 'base64': $body = base64_encode($body); return $wrapWidth ? rtrim(chunk_split($body, $wrapWidth, $le)) : $body; break; case '7bit': if (preg_match('~[^\x00-\x7F]~', $body)) { throw new RuntimeException("Can't use `'{$encoding}'` encoding, non 7 bit characters detected."); } case '8bit': case 'binary': $body = ltrim(str_replace("\r", '', $body), "\n"); return $wrapWidth ? wordwrap($body, $wrapWidth, "\n", $cut) : $body; break; default: throw new InvalidArgumentException("Unsupported encoding `'{$encoding}'`."); break; } }
[ "public", "static", "function", "encode", "(", "$", "body", ",", "$", "encoding", ",", "$", "wrapWidth", "=", "76", ",", "$", "le", "=", "\"\\r\\n\"", ",", "$", "cut", "=", "false", ")", "{", "$", "encoding", "=", "strtolower", "(", "$", "encoding", ")", ";", "switch", "(", "$", "encoding", ")", "{", "case", "'quoted-printable'", ":", "$", "body", "=", "quoted_printable_encode", "(", "$", "body", ")", ";", "return", "$", "wrapWidth", "?", "rtrim", "(", "chunk_split", "(", "$", "body", ",", "$", "wrapWidth", ",", "$", "le", ")", ")", ":", "$", "body", ";", "break", ";", "case", "'base64'", ":", "$", "body", "=", "base64_encode", "(", "$", "body", ")", ";", "return", "$", "wrapWidth", "?", "rtrim", "(", "chunk_split", "(", "$", "body", ",", "$", "wrapWidth", ",", "$", "le", ")", ")", ":", "$", "body", ";", "break", ";", "case", "'7bit'", ":", "if", "(", "preg_match", "(", "'~[^\\x00-\\x7F]~'", ",", "$", "body", ")", ")", "{", "throw", "new", "RuntimeException", "(", "\"Can't use `'{$encoding}'` encoding, non 7 bit characters detected.\"", ")", ";", "}", "case", "'8bit'", ":", "case", "'binary'", ":", "$", "body", "=", "ltrim", "(", "str_replace", "(", "\"\\r\"", ",", "''", ",", "$", "body", ")", ",", "\"\\n\"", ")", ";", "return", "$", "wrapWidth", "?", "wordwrap", "(", "$", "body", ",", "$", "wrapWidth", ",", "\"\\n\"", ",", "$", "cut", ")", ":", "$", "body", ";", "break", ";", "default", ":", "throw", "new", "InvalidArgumentException", "(", "\"Unsupported encoding `'{$encoding}'`.\"", ")", ";", "break", ";", "}", "}" ]
Encoding method. Note: Not relying on `stream_filter_append()` since not stable. @param string $body The message to encode. @param string $encoding The encoding. @param string $wrapWidth The wrap width. @param string $le The wrap width line ending. @return string
[ "Encoding", "method", "." ]
4d75abead39e954529b56cbffa3841a9cd3044bb
https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Mime/Mime.php#L54-L79
13,769
crysalead/net
src/Mime/Mime.php
Mime.encodeEmail
public static function encodeEmail($email) { if (($pos = strpos($email, '@')) === false) { return; } if (!preg_match('~[\x80-\xFF]~', $email)) { return $email; } $domain = substr($email, ++$pos); return substr($email, 0, $pos) . idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46); }
php
public static function encodeEmail($email) { if (($pos = strpos($email, '@')) === false) { return; } if (!preg_match('~[\x80-\xFF]~', $email)) { return $email; } $domain = substr($email, ++$pos); return substr($email, 0, $pos) . idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46); }
[ "public", "static", "function", "encodeEmail", "(", "$", "email", ")", "{", "if", "(", "(", "$", "pos", "=", "strpos", "(", "$", "email", ",", "'@'", ")", ")", "===", "false", ")", "{", "return", ";", "}", "if", "(", "!", "preg_match", "(", "'~[\\x80-\\xFF]~'", ",", "$", "email", ")", ")", "{", "return", "$", "email", ";", "}", "$", "domain", "=", "substr", "(", "$", "email", ",", "++", "$", "pos", ")", ";", "return", "substr", "(", "$", "email", ",", "0", ",", "$", "pos", ")", ".", "idn_to_ascii", "(", "$", "domain", ",", "0", ",", "INTL_IDNA_VARIANT_UTS46", ")", ";", "}" ]
Punycode email address to its ASCII form, also known as punycode. @param string $email The email address to encode @return string|null The encoded address in ASCII form or `null` on error.
[ "Punycode", "email", "address", "to", "its", "ASCII", "form", "also", "known", "as", "punycode", "." ]
4d75abead39e954529b56cbffa3841a9cd3044bb
https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Mime/Mime.php#L87-L97
13,770
crysalead/net
src/Mime/Mime.php
Mime.encodeValue
public static function encodeValue($value, $wrapWidth = 998, $folding = "\r\n ") { if (!preg_match('~[^\x00-\x7F]~', $value)) { $encoding = '7bit'; } elseif (preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $value) > (strlen($value) / 3)) { $encoding = 'base64'; } else { $encoding = 'quoted-printable'; } $encodedName = Mime::encode($value, $encoding, $wrapWidth, $folding, true); $value = trim(str_replace(["\r", "\n"], '', $value)); if ($encoding === 'base64') { $encodedName = "=?UTF-8?B?{$encodedName}?="; } elseif ($encoding === 'quoted-printable') { $encodedName = "=?UTF-8?Q?{$encodedName}?="; } else { $encodedName = addcslashes($encodedName, "\0..\37\177\\\""); if ($encodedName !== $value || preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $value) === 1) { $encodedName = sprintf('"%s"', $encodedName); } } return $encodedName; }
php
public static function encodeValue($value, $wrapWidth = 998, $folding = "\r\n ") { if (!preg_match('~[^\x00-\x7F]~', $value)) { $encoding = '7bit'; } elseif (preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $value) > (strlen($value) / 3)) { $encoding = 'base64'; } else { $encoding = 'quoted-printable'; } $encodedName = Mime::encode($value, $encoding, $wrapWidth, $folding, true); $value = trim(str_replace(["\r", "\n"], '', $value)); if ($encoding === 'base64') { $encodedName = "=?UTF-8?B?{$encodedName}?="; } elseif ($encoding === 'quoted-printable') { $encodedName = "=?UTF-8?Q?{$encodedName}?="; } else { $encodedName = addcslashes($encodedName, "\0..\37\177\\\""); if ($encodedName !== $value || preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $value) === 1) { $encodedName = sprintf('"%s"', $encodedName); } } return $encodedName; }
[ "public", "static", "function", "encodeValue", "(", "$", "value", ",", "$", "wrapWidth", "=", "998", ",", "$", "folding", "=", "\"\\r\\n \"", ")", "{", "if", "(", "!", "preg_match", "(", "'~[^\\x00-\\x7F]~'", ",", "$", "value", ")", ")", "{", "$", "encoding", "=", "'7bit'", ";", "}", "elseif", "(", "preg_match_all", "(", "'/[\\000-\\010\\013\\014\\016-\\037\\177-\\377]/'", ",", "$", "value", ")", ">", "(", "strlen", "(", "$", "value", ")", "/", "3", ")", ")", "{", "$", "encoding", "=", "'base64'", ";", "}", "else", "{", "$", "encoding", "=", "'quoted-printable'", ";", "}", "$", "encodedName", "=", "Mime", "::", "encode", "(", "$", "value", ",", "$", "encoding", ",", "$", "wrapWidth", ",", "$", "folding", ",", "true", ")", ";", "$", "value", "=", "trim", "(", "str_replace", "(", "[", "\"\\r\"", ",", "\"\\n\"", "]", ",", "''", ",", "$", "value", ")", ")", ";", "if", "(", "$", "encoding", "===", "'base64'", ")", "{", "$", "encodedName", "=", "\"=?UTF-8?B?{$encodedName}?=\"", ";", "}", "elseif", "(", "$", "encoding", "===", "'quoted-printable'", ")", "{", "$", "encodedName", "=", "\"=?UTF-8?Q?{$encodedName}?=\"", ";", "}", "else", "{", "$", "encodedName", "=", "addcslashes", "(", "$", "encodedName", ",", "\"\\0..\\37\\177\\\\\\\"\"", ")", ";", "if", "(", "$", "encodedName", "!==", "$", "value", "||", "preg_match", "(", "'/[^A-Za-z0-9!#$%&\\'*+\\/=?^_`{|}~ -]/'", ",", "$", "value", ")", "===", "1", ")", "{", "$", "encodedName", "=", "sprintf", "(", "'\"%s\"'", ",", "$", "encodedName", ")", ";", "}", "}", "return", "$", "encodedName", ";", "}" ]
MIME-encode a value to its mots suitable format @param string $value The value to encode. @return string Returns the encoded value.
[ "MIME", "-", "encode", "a", "value", "to", "its", "mots", "suitable", "format" ]
4d75abead39e954529b56cbffa3841a9cd3044bb
https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Mime/Mime.php#L105-L130
13,771
incraigulous/contentful-sdk
src/ClientBase.php
ClientBase.getEndpoint
function getEndpoint() { $endpoint = $this->endpointBase; if ($this->spaceId) { $endpoint .= '/' . $this->spaceId; } return $endpoint; }
php
function getEndpoint() { $endpoint = $this->endpointBase; if ($this->spaceId) { $endpoint .= '/' . $this->spaceId; } return $endpoint; }
[ "function", "getEndpoint", "(", ")", "{", "$", "endpoint", "=", "$", "this", "->", "endpointBase", ";", "if", "(", "$", "this", "->", "spaceId", ")", "{", "$", "endpoint", ".=", "'/'", ".", "$", "this", "->", "spaceId", ";", "}", "return", "$", "endpoint", ";", "}" ]
Get the endpoint. @return string
[ "Get", "the", "endpoint", "." ]
29399b11b0e085a06ea5976661378c379fe5a731
https://github.com/incraigulous/contentful-sdk/blob/29399b11b0e085a06ea5976661378c379fe5a731/src/ClientBase.php#L48-L54
13,772
incraigulous/contentful-sdk
src/ClientBase.php
ClientBase.build_url
function build_url($resource, array $query = array()) { $url = $this->getEndpoint(); if ($resource && $this->spaceId) $url .= '/'; if ($resource) $url .= $resource; if (!empty($query)) $url .= '?' . http_build_query($query); return $url; }
php
function build_url($resource, array $query = array()) { $url = $this->getEndpoint(); if ($resource && $this->spaceId) $url .= '/'; if ($resource) $url .= $resource; if (!empty($query)) $url .= '?' . http_build_query($query); return $url; }
[ "function", "build_url", "(", "$", "resource", ",", "array", "$", "query", "=", "array", "(", ")", ")", "{", "$", "url", "=", "$", "this", "->", "getEndpoint", "(", ")", ";", "if", "(", "$", "resource", "&&", "$", "this", "->", "spaceId", ")", "$", "url", ".=", "'/'", ";", "if", "(", "$", "resource", ")", "$", "url", ".=", "$", "resource", ";", "if", "(", "!", "empty", "(", "$", "query", ")", ")", "$", "url", ".=", "'?'", ".", "http_build_query", "(", "$", "query", ")", ";", "return", "$", "url", ";", "}" ]
Build the query URL. @param $resource @param $query @return string
[ "Build", "the", "query", "URL", "." ]
29399b11b0e085a06ea5976661378c379fe5a731
https://github.com/incraigulous/contentful-sdk/blob/29399b11b0e085a06ea5976661378c379fe5a731/src/ClientBase.php#L82-L88
13,773
incraigulous/contentful-sdk
src/ClientBase.php
ClientBase.buildCacheKey
function buildCacheKey($method, $resource, $url, $headers = array(), $query = array()) { return md5($method . $resource . $url . json_encode($query) . json_encode($headers)); }
php
function buildCacheKey($method, $resource, $url, $headers = array(), $query = array()) { return md5($method . $resource . $url . json_encode($query) . json_encode($headers)); }
[ "function", "buildCacheKey", "(", "$", "method", ",", "$", "resource", ",", "$", "url", ",", "$", "headers", "=", "array", "(", ")", ",", "$", "query", "=", "array", "(", ")", ")", "{", "return", "md5", "(", "$", "method", ".", "$", "resource", ".", "$", "url", ".", "json_encode", "(", "$", "query", ")", ".", "json_encode", "(", "$", "headers", ")", ")", ";", "}" ]
Return a unique key for the query. @param $method @param $resource @param $url @param array $query @param array $headers @return string
[ "Return", "a", "unique", "key", "for", "the", "query", "." ]
29399b11b0e085a06ea5976661378c379fe5a731
https://github.com/incraigulous/contentful-sdk/blob/29399b11b0e085a06ea5976661378c379fe5a731/src/ClientBase.php#L99-L101
13,774
DevGroup-ru/yii2-data-structure-tools
src/models/PropertyGroup.php
PropertyGroup.autoAddToObjects
public function autoAddToObjects() { /** @var \yii\db\ActiveRecord|\DevGroup\DataStructure\traits\PropertiesTrait $modelClassName */ $modelClassName = PropertiesHelper::classNameForApplicablePropertyModelId($this->applicable_property_model_id); $modelIdsWithoutGroup = $modelClassName::find() ->leftJoin( $modelClassName::bindedPropertyGroupsTable() . ' bpg', 'bpg.model_id = id' ) ->where('bpg.model_id IS NULL') ->select('id') ->column($modelClassName::getDb()); $insertRows = array_map( function ($item) { return [ $item, $this->id ]; }, $modelIdsWithoutGroup ); if (count($insertRows) > 0) { $modelClassName::getDb()->createCommand()->batchInsert( $modelClassName::bindedPropertyGroupsTable(), [ 'model_id', 'property_group_id', ], $insertRows )->execute(); } }
php
public function autoAddToObjects() { /** @var \yii\db\ActiveRecord|\DevGroup\DataStructure\traits\PropertiesTrait $modelClassName */ $modelClassName = PropertiesHelper::classNameForApplicablePropertyModelId($this->applicable_property_model_id); $modelIdsWithoutGroup = $modelClassName::find() ->leftJoin( $modelClassName::bindedPropertyGroupsTable() . ' bpg', 'bpg.model_id = id' ) ->where('bpg.model_id IS NULL') ->select('id') ->column($modelClassName::getDb()); $insertRows = array_map( function ($item) { return [ $item, $this->id ]; }, $modelIdsWithoutGroup ); if (count($insertRows) > 0) { $modelClassName::getDb()->createCommand()->batchInsert( $modelClassName::bindedPropertyGroupsTable(), [ 'model_id', 'property_group_id', ], $insertRows )->execute(); } }
[ "public", "function", "autoAddToObjects", "(", ")", "{", "/** @var \\yii\\db\\ActiveRecord|\\DevGroup\\DataStructure\\traits\\PropertiesTrait $modelClassName */", "$", "modelClassName", "=", "PropertiesHelper", "::", "classNameForApplicablePropertyModelId", "(", "$", "this", "->", "applicable_property_model_id", ")", ";", "$", "modelIdsWithoutGroup", "=", "$", "modelClassName", "::", "find", "(", ")", "->", "leftJoin", "(", "$", "modelClassName", "::", "bindedPropertyGroupsTable", "(", ")", ".", "' bpg'", ",", "'bpg.model_id = id'", ")", "->", "where", "(", "'bpg.model_id IS NULL'", ")", "->", "select", "(", "'id'", ")", "->", "column", "(", "$", "modelClassName", "::", "getDb", "(", ")", ")", ";", "$", "insertRows", "=", "array_map", "(", "function", "(", "$", "item", ")", "{", "return", "[", "$", "item", ",", "$", "this", "->", "id", "]", ";", "}", ",", "$", "modelIdsWithoutGroup", ")", ";", "if", "(", "count", "(", "$", "insertRows", ")", ">", "0", ")", "{", "$", "modelClassName", "::", "getDb", "(", ")", "->", "createCommand", "(", ")", "->", "batchInsert", "(", "$", "modelClassName", "::", "bindedPropertyGroupsTable", "(", ")", ",", "[", "'model_id'", ",", "'property_group_id'", ",", "]", ",", "$", "insertRows", ")", "->", "execute", "(", ")", ";", "}", "}" ]
Finds new applicable models and binds this group to them @throws \yii\db\Exception Database exception is thrown on error
[ "Finds", "new", "applicable", "models", "and", "binds", "this", "group", "to", "them" ]
a5b24d7c0b24d4b0d58cacd91ec7fd876e979097
https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/models/PropertyGroup.php#L185-L217
13,775
DevGroup-ru/yii2-data-structure-tools
src/models/PropertyGroup.php
PropertyGroup.search
public function search($applicablePropertyModelId, $params, $showHidden = false) { $query = self::find() ->where([ 'applicable_property_model_id' => $applicablePropertyModelId, ]); $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ 'pageSize' => 10, ], ]); $dataProvider->sort->attributes['name'] = [ 'asc' => ['property_group_translation.name' => SORT_ASC], 'desc' => ['property_group_translation.name' => SORT_DESC], ]; if (!($this->load($params))) { if ($showHidden === false) { $this->is_deleted = 0; $query->andWhere(['is_deleted' => $this->is_deleted]); } return $dataProvider; } // perform filtering $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'internal_name', $this->internal_name]); $query->andFilterWhere(['is_auto_added' => $this->is_auto_added]); $query->andFilterWhere(['is_deleted' => $this->is_deleted]); // filter by multilingual field $query->andFilterWhere(['like', 'property_group_translation.name', $this->name]); return $dataProvider; }
php
public function search($applicablePropertyModelId, $params, $showHidden = false) { $query = self::find() ->where([ 'applicable_property_model_id' => $applicablePropertyModelId, ]); $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ 'pageSize' => 10, ], ]); $dataProvider->sort->attributes['name'] = [ 'asc' => ['property_group_translation.name' => SORT_ASC], 'desc' => ['property_group_translation.name' => SORT_DESC], ]; if (!($this->load($params))) { if ($showHidden === false) { $this->is_deleted = 0; $query->andWhere(['is_deleted' => $this->is_deleted]); } return $dataProvider; } // perform filtering $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'internal_name', $this->internal_name]); $query->andFilterWhere(['is_auto_added' => $this->is_auto_added]); $query->andFilterWhere(['is_deleted' => $this->is_deleted]); // filter by multilingual field $query->andFilterWhere(['like', 'property_group_translation.name', $this->name]); return $dataProvider; }
[ "public", "function", "search", "(", "$", "applicablePropertyModelId", ",", "$", "params", ",", "$", "showHidden", "=", "false", ")", "{", "$", "query", "=", "self", "::", "find", "(", ")", "->", "where", "(", "[", "'applicable_property_model_id'", "=>", "$", "applicablePropertyModelId", ",", "]", ")", ";", "$", "dataProvider", "=", "new", "ActiveDataProvider", "(", "[", "'query'", "=>", "$", "query", ",", "'pagination'", "=>", "[", "'pageSize'", "=>", "10", ",", "]", ",", "]", ")", ";", "$", "dataProvider", "->", "sort", "->", "attributes", "[", "'name'", "]", "=", "[", "'asc'", "=>", "[", "'property_group_translation.name'", "=>", "SORT_ASC", "]", ",", "'desc'", "=>", "[", "'property_group_translation.name'", "=>", "SORT_DESC", "]", ",", "]", ";", "if", "(", "!", "(", "$", "this", "->", "load", "(", "$", "params", ")", ")", ")", "{", "if", "(", "$", "showHidden", "===", "false", ")", "{", "$", "this", "->", "is_deleted", "=", "0", ";", "$", "query", "->", "andWhere", "(", "[", "'is_deleted'", "=>", "$", "this", "->", "is_deleted", "]", ")", ";", "}", "return", "$", "dataProvider", ";", "}", "// perform filtering", "$", "query", "->", "andFilterWhere", "(", "[", "'id'", "=>", "$", "this", "->", "id", "]", ")", ";", "$", "query", "->", "andFilterWhere", "(", "[", "'like'", ",", "'internal_name'", ",", "$", "this", "->", "internal_name", "]", ")", ";", "$", "query", "->", "andFilterWhere", "(", "[", "'is_auto_added'", "=>", "$", "this", "->", "is_auto_added", "]", ")", ";", "$", "query", "->", "andFilterWhere", "(", "[", "'is_deleted'", "=>", "$", "this", "->", "is_deleted", "]", ")", ";", "// filter by multilingual field", "$", "query", "->", "andFilterWhere", "(", "[", "'like'", ",", "'property_group_translation.name'", ",", "$", "this", "->", "name", "]", ")", ";", "return", "$", "dataProvider", ";", "}" ]
Returns ActiveDataProvider for searching PropertyGroup models @param integer $applicablePropertyModelId Applicable property model id @param array $params Array of filter params @return \yii\data\ActiveDataProvider @codeCoverageIgnore
[ "Returns", "ActiveDataProvider", "for", "searching", "PropertyGroup", "models" ]
a5b24d7c0b24d4b0d58cacd91ec7fd876e979097
https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/models/PropertyGroup.php#L294-L329
13,776
markwatkinson/luminous
src/Luminous/Core/Scanners/EmbeddedWebScriptScanner.php
EmbeddedWebScriptScanner.string
public function string($str = null) { if ($str !== null) { foreach ($this->childScanners as $s) { $s->string($str); } } return parent::string($str); }
php
public function string($str = null) { if ($str !== null) { foreach ($this->childScanners as $s) { $s->string($str); } } return parent::string($str); }
[ "public", "function", "string", "(", "$", "str", "=", "null", ")", "{", "if", "(", "$", "str", "!==", "null", ")", "{", "foreach", "(", "$", "this", "->", "childScanners", "as", "$", "s", ")", "{", "$", "s", "->", "string", "(", "$", "str", ")", ";", "}", "}", "return", "parent", "::", "string", "(", "$", "str", ")", ";", "}" ]
override string to hit the child scanners as well
[ "override", "string", "to", "hit", "the", "child", "scanners", "as", "well" ]
4adc18f414534abe986133d6d38e8e9787d32e69
https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Core/Scanners/EmbeddedWebScriptScanner.php#L115-L123
13,777
dphn/ScContent
src/ScContent/Controller/Installation/RequirementsController.php
RequirementsController.configurationAction
public function configurationAction() { $redirect = $this->getRedirect(); $installation = $this->getInstallation(); $step = $installation->getCurrentStep(); $member = $step->getCurrentMember(); $validator = $this->getValidator(); if (! $validator instanceof PhpIni) { throw new DomainException(sprintf( $this->scTranslate( "An error occurred while installing the module '%s', step '%s', member '%s'. " . "Validator must be an instance of class '%s', '%s' instead." ), $installation->getModuleName(), $step->getName(), $member->getName(), 'ScContent\Validator\Installation\PhpIni', is_object($validator) ? get_class($validator) : gettype($validator) )); } $failures = []; foreach ($member as $requirement) { if (! $validator->isValid($requirement)) { if (! isset($requirement['failure_message'])) { throw new InvalidArgumentException(sprintf( $this->scTranslate( "An error occurred while installing the module '%s', step '%s', member '%s'. " . "Missing option 'failure_message' for '%s' param." ), $installation->getModuleName(), $step->getName(), $member->getName(), $requirement['name'] )); } $failures[] = [ $requirement['name'], (false === $validator->getValueFromCallback($requirement['name'])) ? 'false' : $validator->getValueFromCallback($requirement['name']), $requirement['failure_message'] ]; } } if (! empty($failures)) { return new ViewModel([ 'errors' => ['table' => [ 'head' => ['Php.ini option', 'Value', 'Requirement'], 'body' => $failures ]] ]); } return $this->redirect()->toUrl($redirect); }
php
public function configurationAction() { $redirect = $this->getRedirect(); $installation = $this->getInstallation(); $step = $installation->getCurrentStep(); $member = $step->getCurrentMember(); $validator = $this->getValidator(); if (! $validator instanceof PhpIni) { throw new DomainException(sprintf( $this->scTranslate( "An error occurred while installing the module '%s', step '%s', member '%s'. " . "Validator must be an instance of class '%s', '%s' instead." ), $installation->getModuleName(), $step->getName(), $member->getName(), 'ScContent\Validator\Installation\PhpIni', is_object($validator) ? get_class($validator) : gettype($validator) )); } $failures = []; foreach ($member as $requirement) { if (! $validator->isValid($requirement)) { if (! isset($requirement['failure_message'])) { throw new InvalidArgumentException(sprintf( $this->scTranslate( "An error occurred while installing the module '%s', step '%s', member '%s'. " . "Missing option 'failure_message' for '%s' param." ), $installation->getModuleName(), $step->getName(), $member->getName(), $requirement['name'] )); } $failures[] = [ $requirement['name'], (false === $validator->getValueFromCallback($requirement['name'])) ? 'false' : $validator->getValueFromCallback($requirement['name']), $requirement['failure_message'] ]; } } if (! empty($failures)) { return new ViewModel([ 'errors' => ['table' => [ 'head' => ['Php.ini option', 'Value', 'Requirement'], 'body' => $failures ]] ]); } return $this->redirect()->toUrl($redirect); }
[ "public", "function", "configurationAction", "(", ")", "{", "$", "redirect", "=", "$", "this", "->", "getRedirect", "(", ")", ";", "$", "installation", "=", "$", "this", "->", "getInstallation", "(", ")", ";", "$", "step", "=", "$", "installation", "->", "getCurrentStep", "(", ")", ";", "$", "member", "=", "$", "step", "->", "getCurrentMember", "(", ")", ";", "$", "validator", "=", "$", "this", "->", "getValidator", "(", ")", ";", "if", "(", "!", "$", "validator", "instanceof", "PhpIni", ")", "{", "throw", "new", "DomainException", "(", "sprintf", "(", "$", "this", "->", "scTranslate", "(", "\"An error occurred while installing the module '%s', step '%s', member '%s'. \"", ".", "\"Validator must be an instance of class '%s', '%s' instead.\"", ")", ",", "$", "installation", "->", "getModuleName", "(", ")", ",", "$", "step", "->", "getName", "(", ")", ",", "$", "member", "->", "getName", "(", ")", ",", "'ScContent\\Validator\\Installation\\PhpIni'", ",", "is_object", "(", "$", "validator", ")", "?", "get_class", "(", "$", "validator", ")", ":", "gettype", "(", "$", "validator", ")", ")", ")", ";", "}", "$", "failures", "=", "[", "]", ";", "foreach", "(", "$", "member", "as", "$", "requirement", ")", "{", "if", "(", "!", "$", "validator", "->", "isValid", "(", "$", "requirement", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "requirement", "[", "'failure_message'", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "$", "this", "->", "scTranslate", "(", "\"An error occurred while installing the module '%s', step '%s', member '%s'. \"", ".", "\"Missing option 'failure_message' for '%s' param.\"", ")", ",", "$", "installation", "->", "getModuleName", "(", ")", ",", "$", "step", "->", "getName", "(", ")", ",", "$", "member", "->", "getName", "(", ")", ",", "$", "requirement", "[", "'name'", "]", ")", ")", ";", "}", "$", "failures", "[", "]", "=", "[", "$", "requirement", "[", "'name'", "]", ",", "(", "false", "===", "$", "validator", "->", "getValueFromCallback", "(", "$", "requirement", "[", "'name'", "]", ")", ")", "?", "'false'", ":", "$", "validator", "->", "getValueFromCallback", "(", "$", "requirement", "[", "'name'", "]", ")", ",", "$", "requirement", "[", "'failure_message'", "]", "]", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "failures", ")", ")", "{", "return", "new", "ViewModel", "(", "[", "'errors'", "=>", "[", "'table'", "=>", "[", "'head'", "=>", "[", "'Php.ini option'", ",", "'Value'", ",", "'Requirement'", "]", ",", "'body'", "=>", "$", "failures", "]", "]", "]", ")", ";", "}", "return", "$", "this", "->", "redirect", "(", ")", "->", "toUrl", "(", "$", "redirect", ")", ";", "}" ]
Checks the settings in the php.ini file in accordance with the configuration of the module. If the settings are not compatible, the installation process stops and displays the information message. @return \Zend\Stdlib\ResponseInterface|\Zend\View\Model\ViewModel
[ "Checks", "the", "settings", "in", "the", "php", ".", "ini", "file", "in", "accordance", "with", "the", "configuration", "of", "the", "module", ".", "If", "the", "settings", "are", "not", "compatible", "the", "installation", "process", "stops", "and", "displays", "the", "information", "message", "." ]
9dd5732490c45fd788b96cedf7b3c7adfacb30d2
https://github.com/dphn/ScContent/blob/9dd5732490c45fd788b96cedf7b3c7adfacb30d2/src/ScContent/Controller/Installation/RequirementsController.php#L33-L89
13,778
terdia/legato-framework
src/Mail/Transport/MailGunClient.php
MailGunClient.combineTo
protected function combineTo(Swift_Mime_SimpleMessage $message) { return array_merge( (array) $message->getTo(), (array) $message->getCc(), (array) $message->getBcc() ); }
php
protected function combineTo(Swift_Mime_SimpleMessage $message) { return array_merge( (array) $message->getTo(), (array) $message->getCc(), (array) $message->getBcc() ); }
[ "protected", "function", "combineTo", "(", "Swift_Mime_SimpleMessage", "$", "message", ")", "{", "return", "array_merge", "(", "(", "array", ")", "$", "message", "->", "getTo", "(", ")", ",", "(", "array", ")", "$", "message", "->", "getCc", "(", ")", ",", "(", "array", ")", "$", "message", "->", "getBcc", "(", ")", ")", ";", "}" ]
Combine all contacts for the message. @param \Swift_Mime_SimpleMessage $message @return array
[ "Combine", "all", "contacts", "for", "the", "message", "." ]
44057c1c3c6f3e9643e9fade51bd417860fafda8
https://github.com/terdia/legato-framework/blob/44057c1c3c6f3e9643e9fade51bd417860fafda8/src/Mail/Transport/MailGunClient.php#L84-L89
13,779
terdia/legato-framework
src/Mail/Transport/MailGunClient.php
MailGunClient.prepareTo
protected function prepareTo(Swift_Mime_SimpleMessage $message) { $to = array_map(function ($name, $address) { return $name ? $name." <{$address}>" : $address; }, $this->combineTo($message), array_keys($this->combineTo($message))); return implode(',', $to); }
php
protected function prepareTo(Swift_Mime_SimpleMessage $message) { $to = array_map(function ($name, $address) { return $name ? $name." <{$address}>" : $address; }, $this->combineTo($message), array_keys($this->combineTo($message))); return implode(',', $to); }
[ "protected", "function", "prepareTo", "(", "Swift_Mime_SimpleMessage", "$", "message", ")", "{", "$", "to", "=", "array_map", "(", "function", "(", "$", "name", ",", "$", "address", ")", "{", "return", "$", "name", "?", "$", "name", ".", "\" <{$address}>\"", ":", "$", "address", ";", "}", ",", "$", "this", "->", "combineTo", "(", "$", "message", ")", ",", "array_keys", "(", "$", "this", "->", "combineTo", "(", "$", "message", ")", ")", ")", ";", "return", "implode", "(", "','", ",", "$", "to", ")", ";", "}" ]
Format the to addresses to match Mailgun message.mime format. @param Swift_Mime_SimpleMessage $message @return string
[ "Format", "the", "to", "addresses", "to", "match", "Mailgun", "message", ".", "mime", "format", "." ]
44057c1c3c6f3e9643e9fade51bd417860fafda8
https://github.com/terdia/legato-framework/blob/44057c1c3c6f3e9643e9fade51bd417860fafda8/src/Mail/Transport/MailGunClient.php#L98-L105
13,780
terdia/legato-framework
src/Security/CSRFProtection.php
CSRFProtection.extractToken
protected function extractToken() { if ($this->request->input('token') === false) { if (!$this->request->getHeader('X-JS-CLIENTS-TOKEN')) { return 'token'; } return $this->request->getHeader('X-JS-CLIENTS-TOKEN'); } return $this->request->input('token'); }
php
protected function extractToken() { if ($this->request->input('token') === false) { if (!$this->request->getHeader('X-JS-CLIENTS-TOKEN')) { return 'token'; } return $this->request->getHeader('X-JS-CLIENTS-TOKEN'); } return $this->request->input('token'); }
[ "protected", "function", "extractToken", "(", ")", "{", "if", "(", "$", "this", "->", "request", "->", "input", "(", "'token'", ")", "===", "false", ")", "{", "if", "(", "!", "$", "this", "->", "request", "->", "getHeader", "(", "'X-JS-CLIENTS-TOKEN'", ")", ")", "{", "return", "'token'", ";", "}", "return", "$", "this", "->", "request", "->", "getHeader", "(", "'X-JS-CLIENTS-TOKEN'", ")", ";", "}", "return", "$", "this", "->", "request", "->", "input", "(", "'token'", ")", ";", "}" ]
extract token from form or JavaScript Clients like Axios, Ajax, JQuery. @return bool|string|string[]
[ "extract", "token", "from", "form", "or", "JavaScript", "Clients", "like", "Axios", "Ajax", "JQuery", "." ]
44057c1c3c6f3e9643e9fade51bd417860fafda8
https://github.com/terdia/legato-framework/blob/44057c1c3c6f3e9643e9fade51bd417860fafda8/src/Security/CSRFProtection.php#L77-L88
13,781
terdia/legato-framework
src/Session/Session.php
Session.getInstance
public static function getInstance() { if (!static::$instance instanceof self) { static::$instance = $session = new self(); if (!$session->isStarted()) { $session->start(); } } return static::$instance; }
php
public static function getInstance() { if (!static::$instance instanceof self) { static::$instance = $session = new self(); if (!$session->isStarted()) { $session->start(); } } return static::$instance; }
[ "public", "static", "function", "getInstance", "(", ")", "{", "if", "(", "!", "static", "::", "$", "instance", "instanceof", "self", ")", "{", "static", "::", "$", "instance", "=", "$", "session", "=", "new", "self", "(", ")", ";", "if", "(", "!", "$", "session", "->", "isStarted", "(", ")", ")", "{", "$", "session", "->", "start", "(", ")", ";", "}", "}", "return", "static", "::", "$", "instance", ";", "}" ]
Session singleton. @return mixed
[ "Session", "singleton", "." ]
44057c1c3c6f3e9643e9fade51bd417860fafda8
https://github.com/terdia/legato-framework/blob/44057c1c3c6f3e9643e9fade51bd417860fafda8/src/Session/Session.php#L26-L36
13,782
terdia/legato-framework
src/Session/Session.php
Session.createFlashMessage
public function createFlashMessage($key, $value) { $session = static::getInstance(); $session->getFlashBag()->add($key, $value); }
php
public function createFlashMessage($key, $value) { $session = static::getInstance(); $session->getFlashBag()->add($key, $value); }
[ "public", "function", "createFlashMessage", "(", "$", "key", ",", "$", "value", ")", "{", "$", "session", "=", "static", "::", "getInstance", "(", ")", ";", "$", "session", "->", "getFlashBag", "(", ")", "->", "add", "(", "$", "key", ",", "$", "value", ")", ";", "}" ]
Add flash message. @param $key @param $value
[ "Add", "flash", "message", "." ]
44057c1c3c6f3e9643e9fade51bd417860fafda8
https://github.com/terdia/legato-framework/blob/44057c1c3c6f3e9643e9fade51bd417860fafda8/src/Session/Session.php#L44-L48
13,783
terdia/legato-framework
src/Session/Session.php
Session.getFlashMessage
public function getFlashMessage($key) { $session = static::getInstance(); foreach ($session->getFlashBag()->get($key, []) as $message) { return $message ?: null; } return ''; }
php
public function getFlashMessage($key) { $session = static::getInstance(); foreach ($session->getFlashBag()->get($key, []) as $message) { return $message ?: null; } return ''; }
[ "public", "function", "getFlashMessage", "(", "$", "key", ")", "{", "$", "session", "=", "static", "::", "getInstance", "(", ")", ";", "foreach", "(", "$", "session", "->", "getFlashBag", "(", ")", "->", "get", "(", "$", "key", ",", "[", "]", ")", "as", "$", "message", ")", "{", "return", "$", "message", "?", ":", "null", ";", "}", "return", "''", ";", "}" ]
Get message from flash bag. @param $key @return null|string
[ "Get", "message", "from", "flash", "bag", "." ]
44057c1c3c6f3e9643e9fade51bd417860fafda8
https://github.com/terdia/legato-framework/blob/44057c1c3c6f3e9643e9fade51bd417860fafda8/src/Session/Session.php#L57-L65
13,784
arckinteractive/events_api
classes/Events/API/Event.php
Event.getURL
public function getURL($start_timestamp = 0, $calendar_guid = 0) { if (!$start_timestamp) { $start_timestamp = $this->getNextOccurrence(); } $url = parent::getURL(); return elgg_http_add_url_query_elements($url, array_filter(array( 'ts' => $start_timestamp, 'calendar' => $calendar_guid, ))); }
php
public function getURL($start_timestamp = 0, $calendar_guid = 0) { if (!$start_timestamp) { $start_timestamp = $this->getNextOccurrence(); } $url = parent::getURL(); return elgg_http_add_url_query_elements($url, array_filter(array( 'ts' => $start_timestamp, 'calendar' => $calendar_guid, ))); }
[ "public", "function", "getURL", "(", "$", "start_timestamp", "=", "0", ",", "$", "calendar_guid", "=", "0", ")", "{", "if", "(", "!", "$", "start_timestamp", ")", "{", "$", "start_timestamp", "=", "$", "this", "->", "getNextOccurrence", "(", ")", ";", "}", "$", "url", "=", "parent", "::", "getURL", "(", ")", ";", "return", "elgg_http_add_url_query_elements", "(", "$", "url", ",", "array_filter", "(", "array", "(", "'ts'", "=>", "$", "start_timestamp", ",", "'calendar'", "=>", "$", "calendar_guid", ",", ")", ")", ")", ";", "}" ]
Returns canonical URL with instance start time added as query element @param int $start_timestamp Start time of the instance @param int $calendar_guid GUID of the calendar in context @return string
[ "Returns", "canonical", "URL", "with", "instance", "start", "time", "added", "as", "query", "element" ]
56c0f0ae403af1672a913db5dc259db9cb712491
https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Event.php#L61-L70
13,785
arckinteractive/events_api
classes/Events/API/Event.php
Event.getCalendars
public function getCalendars($params = array(), $public = false) { $defaults = array( 'type' => 'object', 'subtype' => 'calendar', 'relationship' => Calendar::EVENT_CALENDAR_RELATIONSHIP, 'relationship_guid' => $this->guid, 'limit' => false ); $options = array_merge($defaults, $params); if ($public) { $options['metadata_name_value_pairs'][] = array( 'name' => '__public_calendar', 'value' => true ); } if ($options['count']) { return elgg_get_entities_from_relationship($options); } return new ElggBatch('elgg_get_entities_from_relationship', $options); }
php
public function getCalendars($params = array(), $public = false) { $defaults = array( 'type' => 'object', 'subtype' => 'calendar', 'relationship' => Calendar::EVENT_CALENDAR_RELATIONSHIP, 'relationship_guid' => $this->guid, 'limit' => false ); $options = array_merge($defaults, $params); if ($public) { $options['metadata_name_value_pairs'][] = array( 'name' => '__public_calendar', 'value' => true ); } if ($options['count']) { return elgg_get_entities_from_relationship($options); } return new ElggBatch('elgg_get_entities_from_relationship', $options); }
[ "public", "function", "getCalendars", "(", "$", "params", "=", "array", "(", ")", ",", "$", "public", "=", "false", ")", "{", "$", "defaults", "=", "array", "(", "'type'", "=>", "'object'", ",", "'subtype'", "=>", "'calendar'", ",", "'relationship'", "=>", "Calendar", "::", "EVENT_CALENDAR_RELATIONSHIP", ",", "'relationship_guid'", "=>", "$", "this", "->", "guid", ",", "'limit'", "=>", "false", ")", ";", "$", "options", "=", "array_merge", "(", "$", "defaults", ",", "$", "params", ")", ";", "if", "(", "$", "public", ")", "{", "$", "options", "[", "'metadata_name_value_pairs'", "]", "[", "]", "=", "array", "(", "'name'", "=>", "'__public_calendar'", ",", "'value'", "=>", "true", ")", ";", "}", "if", "(", "$", "options", "[", "'count'", "]", ")", "{", "return", "elgg_get_entities_from_relationship", "(", "$", "options", ")", ";", "}", "return", "new", "ElggBatch", "(", "'elgg_get_entities_from_relationship'", ",", "$", "options", ")", ";", "}" ]
Get all calendars this event is on @param array custom parameters to override the default egef @param bool $public - limit to only personal public calendars?
[ "Get", "all", "calendars", "this", "event", "is", "on" ]
56c0f0ae403af1672a913db5dc259db9cb712491
https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Event.php#L78-L101
13,786
arckinteractive/events_api
classes/Events/API/Event.php
Event.move
public function move($params) { //update the event $this->all_day = elgg_extract('all_day', $params, false); $this->start_timestamp = $params['new_start_timestamp']; $this->end_timestamp = $params['new_end_timestamp']; $this->start_date = $params['new_start_date']; $this->end_date = $params['new_end_date']; $this->start_time = $params['new_start_time']; $this->end_time = $params['new_end_time']; $this->end_delta = $params['new_end_timestamp'] - $params['new_start_timestamp']; // how long this is in seconds $this->repeat_end_timestamp = $this->calculateRepeatEndTimestamp(); // rebuild reminders for the next 2 days $time = time(); $this->removeReminders(null, null, true); // remove all reminders $this->buildReminders($time, $time + (Util::SECONDS_IN_A_DAY * 2)); return true; }
php
public function move($params) { //update the event $this->all_day = elgg_extract('all_day', $params, false); $this->start_timestamp = $params['new_start_timestamp']; $this->end_timestamp = $params['new_end_timestamp']; $this->start_date = $params['new_start_date']; $this->end_date = $params['new_end_date']; $this->start_time = $params['new_start_time']; $this->end_time = $params['new_end_time']; $this->end_delta = $params['new_end_timestamp'] - $params['new_start_timestamp']; // how long this is in seconds $this->repeat_end_timestamp = $this->calculateRepeatEndTimestamp(); // rebuild reminders for the next 2 days $time = time(); $this->removeReminders(null, null, true); // remove all reminders $this->buildReminders($time, $time + (Util::SECONDS_IN_A_DAY * 2)); return true; }
[ "public", "function", "move", "(", "$", "params", ")", "{", "//update the event", "$", "this", "->", "all_day", "=", "elgg_extract", "(", "'all_day'", ",", "$", "params", ",", "false", ")", ";", "$", "this", "->", "start_timestamp", "=", "$", "params", "[", "'new_start_timestamp'", "]", ";", "$", "this", "->", "end_timestamp", "=", "$", "params", "[", "'new_end_timestamp'", "]", ";", "$", "this", "->", "start_date", "=", "$", "params", "[", "'new_start_date'", "]", ";", "$", "this", "->", "end_date", "=", "$", "params", "[", "'new_end_date'", "]", ";", "$", "this", "->", "start_time", "=", "$", "params", "[", "'new_start_time'", "]", ";", "$", "this", "->", "end_time", "=", "$", "params", "[", "'new_end_time'", "]", ";", "$", "this", "->", "end_delta", "=", "$", "params", "[", "'new_end_timestamp'", "]", "-", "$", "params", "[", "'new_start_timestamp'", "]", ";", "// how long this is in seconds", "$", "this", "->", "repeat_end_timestamp", "=", "$", "this", "->", "calculateRepeatEndTimestamp", "(", ")", ";", "// rebuild reminders for the next 2 days", "$", "time", "=", "time", "(", ")", ";", "$", "this", "->", "removeReminders", "(", "null", ",", "null", ",", "true", ")", ";", "// remove all reminders", "$", "this", "->", "buildReminders", "(", "$", "time", ",", "$", "time", "+", "(", "Util", "::", "SECONDS_IN_A_DAY", "*", "2", ")", ")", ";", "return", "true", ";", "}" ]
Perform a move action with calculated parameters @param array $params New event parameters @return boolean
[ "Perform", "a", "move", "action", "with", "calculated", "parameters" ]
56c0f0ae403af1672a913db5dc259db9cb712491
https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Event.php#L109-L128
13,787
arckinteractive/events_api
classes/Events/API/Event.php
Event.resize
public function resize($params) { //update the event $this->end_timestamp = $params['new_end_timestamp']; $this->end_date = $params['new_end_date']; $this->end_time = $params['new_end_time']; $this->end_delta = $params['new_end_timestamp'] - $this->getStartTimestamp(); // how long this is in seconds $this->repeat_end_timestamp = $this->calculateRepeatEndTimestamp(); return true; }
php
public function resize($params) { //update the event $this->end_timestamp = $params['new_end_timestamp']; $this->end_date = $params['new_end_date']; $this->end_time = $params['new_end_time']; $this->end_delta = $params['new_end_timestamp'] - $this->getStartTimestamp(); // how long this is in seconds $this->repeat_end_timestamp = $this->calculateRepeatEndTimestamp(); return true; }
[ "public", "function", "resize", "(", "$", "params", ")", "{", "//update the event", "$", "this", "->", "end_timestamp", "=", "$", "params", "[", "'new_end_timestamp'", "]", ";", "$", "this", "->", "end_date", "=", "$", "params", "[", "'new_end_date'", "]", ";", "$", "this", "->", "end_time", "=", "$", "params", "[", "'new_end_time'", "]", ";", "$", "this", "->", "end_delta", "=", "$", "params", "[", "'new_end_timestamp'", "]", "-", "$", "this", "->", "getStartTimestamp", "(", ")", ";", "// how long this is in seconds", "$", "this", "->", "repeat_end_timestamp", "=", "$", "this", "->", "calculateRepeatEndTimestamp", "(", ")", ";", "return", "true", ";", "}" ]
Extends event duration @param array $params New end parameters @return boolean
[ "Extends", "event", "duration" ]
56c0f0ae403af1672a913db5dc259db9cb712491
https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Event.php#L136-L145
13,788
arckinteractive/events_api
classes/Events/API/Event.php
Event.getMoveParams
public function getMoveParams($day_delta, $minute_delta, $all_day = false) { // calculate new dates $start_timestamp = $this->getStartTimestamp(); $end_timestamp = $this->getEndTimestamp(); $time_diff = $end_timestamp - $start_timestamp; $new_start_timestamp = $start_timestamp + ($day_delta * Util::SECONDS_IN_A_DAY) + ($minute_delta * Util::SECONDS_IN_A_MINUTE); $new_end_timestamp = $new_start_timestamp + $time_diff; $params = array( 'entity' => $this, 'new_start_timestamp' => $new_start_timestamp, 'new_end_timestamp' => $new_end_timestamp, 'new_start_date' => date('Y-m-d', $new_start_timestamp), 'new_end_date' => date('Y-m-d', $new_end_timestamp), 'new_start_time' => date('g:ia', $new_start_timestamp), 'new_end_time' => date('g:ia', $new_end_timestamp), 'all_day' => $all_day ); return $params; }
php
public function getMoveParams($day_delta, $minute_delta, $all_day = false) { // calculate new dates $start_timestamp = $this->getStartTimestamp(); $end_timestamp = $this->getEndTimestamp(); $time_diff = $end_timestamp - $start_timestamp; $new_start_timestamp = $start_timestamp + ($day_delta * Util::SECONDS_IN_A_DAY) + ($minute_delta * Util::SECONDS_IN_A_MINUTE); $new_end_timestamp = $new_start_timestamp + $time_diff; $params = array( 'entity' => $this, 'new_start_timestamp' => $new_start_timestamp, 'new_end_timestamp' => $new_end_timestamp, 'new_start_date' => date('Y-m-d', $new_start_timestamp), 'new_end_date' => date('Y-m-d', $new_end_timestamp), 'new_start_time' => date('g:ia', $new_start_timestamp), 'new_end_time' => date('g:ia', $new_end_timestamp), 'all_day' => $all_day ); return $params; }
[ "public", "function", "getMoveParams", "(", "$", "day_delta", ",", "$", "minute_delta", ",", "$", "all_day", "=", "false", ")", "{", "// calculate new dates", "$", "start_timestamp", "=", "$", "this", "->", "getStartTimestamp", "(", ")", ";", "$", "end_timestamp", "=", "$", "this", "->", "getEndTimestamp", "(", ")", ";", "$", "time_diff", "=", "$", "end_timestamp", "-", "$", "start_timestamp", ";", "$", "new_start_timestamp", "=", "$", "start_timestamp", "+", "(", "$", "day_delta", "*", "Util", "::", "SECONDS_IN_A_DAY", ")", "+", "(", "$", "minute_delta", "*", "Util", "::", "SECONDS_IN_A_MINUTE", ")", ";", "$", "new_end_timestamp", "=", "$", "new_start_timestamp", "+", "$", "time_diff", ";", "$", "params", "=", "array", "(", "'entity'", "=>", "$", "this", ",", "'new_start_timestamp'", "=>", "$", "new_start_timestamp", ",", "'new_end_timestamp'", "=>", "$", "new_end_timestamp", ",", "'new_start_date'", "=>", "date", "(", "'Y-m-d'", ",", "$", "new_start_timestamp", ")", ",", "'new_end_date'", "=>", "date", "(", "'Y-m-d'", ",", "$", "new_end_timestamp", ")", ",", "'new_start_time'", "=>", "date", "(", "'g:ia'", ",", "$", "new_start_timestamp", ")", ",", "'new_end_time'", "=>", "date", "(", "'g:ia'", ",", "$", "new_end_timestamp", ")", ",", "'all_day'", "=>", "$", "all_day", ")", ";", "return", "$", "params", ";", "}" ]
Calculates parameters for a move action @param int $day_delta Positive or negative number of days from the original event day @param int $minute_delta Position or negative number of minutes from the origin event time @param bool $all_day All day event? @return array
[ "Calculates", "parameters", "for", "a", "move", "action" ]
56c0f0ae403af1672a913db5dc259db9cb712491
https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Event.php#L235-L256
13,789
arckinteractive/events_api
classes/Events/API/Event.php
Event.getResizeParams
public function getResizeParams($day_delta = 0, $minute_delta = 0) { // calculate new dates $end_timestamp = $this->getEndTimestamp(); $new_end_timestamp = $end_timestamp + ($day_delta * Util::SECONDS_IN_A_DAY) + ($minute_delta * Util::SECONDS_IN_A_MINUTE); $params = array( 'entity' => $this, 'new_end_timestamp' => $new_end_timestamp, 'new_end_date' => date('Y-m-d', $new_end_timestamp), 'new_end_time' => date('g:ia', $new_end_timestamp) ); return $params; }
php
public function getResizeParams($day_delta = 0, $minute_delta = 0) { // calculate new dates $end_timestamp = $this->getEndTimestamp(); $new_end_timestamp = $end_timestamp + ($day_delta * Util::SECONDS_IN_A_DAY) + ($minute_delta * Util::SECONDS_IN_A_MINUTE); $params = array( 'entity' => $this, 'new_end_timestamp' => $new_end_timestamp, 'new_end_date' => date('Y-m-d', $new_end_timestamp), 'new_end_time' => date('g:ia', $new_end_timestamp) ); return $params; }
[ "public", "function", "getResizeParams", "(", "$", "day_delta", "=", "0", ",", "$", "minute_delta", "=", "0", ")", "{", "// calculate new dates", "$", "end_timestamp", "=", "$", "this", "->", "getEndTimestamp", "(", ")", ";", "$", "new_end_timestamp", "=", "$", "end_timestamp", "+", "(", "$", "day_delta", "*", "Util", "::", "SECONDS_IN_A_DAY", ")", "+", "(", "$", "minute_delta", "*", "Util", "::", "SECONDS_IN_A_MINUTE", ")", ";", "$", "params", "=", "array", "(", "'entity'", "=>", "$", "this", ",", "'new_end_timestamp'", "=>", "$", "new_end_timestamp", ",", "'new_end_date'", "=>", "date", "(", "'Y-m-d'", ",", "$", "new_end_timestamp", ")", ",", "'new_end_time'", "=>", "date", "(", "'g:ia'", ",", "$", "new_end_timestamp", ")", ")", ";", "return", "$", "params", ";", "}" ]
Calculates parameters for the resize action @param int $day_delta Positive or negative number of days from the original event end @param int $minute_delta Positive or negative number of minutes from the original event end @return array
[ "Calculates", "parameters", "for", "the", "resize", "action" ]
56c0f0ae403af1672a913db5dc259db9cb712491
https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Event.php#L265-L279
13,790
arckinteractive/events_api
classes/Events/API/Event.php
Event.calculateRepeatEndTimestamp
public function calculateRepeatEndTimestamp() { // determine when it actually stops repeating in terms of timestamp switch ($this->repeat_end_type) { case Util::REPEAT_END_ON: $repeat_end_timestamp = strtotime($this->repeat_end_on); if ($repeat_end_timestamp === false) { $repeat_end_timestamp = 0; //@TODO - what else could we do here? } $return = $repeat_end_timestamp; break; case Util::REPEAT_END_AFTER: $return = $this->calculateEndAfterTimestamp($this->repeat_end_after); break; case Util::REPEAT_END_NEVER : $return = 0; break; default : if ($this->repeat) { $return = 0; } else { $return = $this->getStartTimestamp(); } break; } if ($return && $return < $this->getEndTimestamp()) { $return = $this->getEndTimestamp(); } return $return; }
php
public function calculateRepeatEndTimestamp() { // determine when it actually stops repeating in terms of timestamp switch ($this->repeat_end_type) { case Util::REPEAT_END_ON: $repeat_end_timestamp = strtotime($this->repeat_end_on); if ($repeat_end_timestamp === false) { $repeat_end_timestamp = 0; //@TODO - what else could we do here? } $return = $repeat_end_timestamp; break; case Util::REPEAT_END_AFTER: $return = $this->calculateEndAfterTimestamp($this->repeat_end_after); break; case Util::REPEAT_END_NEVER : $return = 0; break; default : if ($this->repeat) { $return = 0; } else { $return = $this->getStartTimestamp(); } break; } if ($return && $return < $this->getEndTimestamp()) { $return = $this->getEndTimestamp(); } return $return; }
[ "public", "function", "calculateRepeatEndTimestamp", "(", ")", "{", "// determine when it actually stops repeating in terms of timestamp", "switch", "(", "$", "this", "->", "repeat_end_type", ")", "{", "case", "Util", "::", "REPEAT_END_ON", ":", "$", "repeat_end_timestamp", "=", "strtotime", "(", "$", "this", "->", "repeat_end_on", ")", ";", "if", "(", "$", "repeat_end_timestamp", "===", "false", ")", "{", "$", "repeat_end_timestamp", "=", "0", ";", "//@TODO - what else could we do here?", "}", "$", "return", "=", "$", "repeat_end_timestamp", ";", "break", ";", "case", "Util", "::", "REPEAT_END_AFTER", ":", "$", "return", "=", "$", "this", "->", "calculateEndAfterTimestamp", "(", "$", "this", "->", "repeat_end_after", ")", ";", "break", ";", "case", "Util", "::", "REPEAT_END_NEVER", ":", "$", "return", "=", "0", ";", "break", ";", "default", ":", "if", "(", "$", "this", "->", "repeat", ")", "{", "$", "return", "=", "0", ";", "}", "else", "{", "$", "return", "=", "$", "this", "->", "getStartTimestamp", "(", ")", ";", "}", "break", ";", "}", "if", "(", "$", "return", "&&", "$", "return", "<", "$", "this", "->", "getEndTimestamp", "(", ")", ")", "{", "$", "return", "=", "$", "this", "->", "getEndTimestamp", "(", ")", ";", "}", "return", "$", "return", ";", "}" ]
Calculates and returns the last timestamp for event recurrences @return int
[ "Calculates", "and", "returns", "the", "last", "timestamp", "for", "event", "recurrences" ]
56c0f0ae403af1672a913db5dc259db9cb712491
https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Event.php#L416-L449
13,791
arckinteractive/events_api
classes/Events/API/Event.php
Event.getNextOccurrence
public function getNextOccurrence($after_timestamp = null) { if ($after_timestamp === null) { $after_timestamp = time(); } $after_timestamp = (int) $after_timestamp; $next = false; if ($this->isRecurring()) { $next = $this->calculateEndAfterTimestamp(1, $after_timestamp, false); } else if ($after_timestamp < $this->getStartTimestamp()) { $next = $this->getStartTimestamp(); } if ($this->repeat_end_timestamp && $this->repeat_end_timestamp < $next) { return false; } return $next; }
php
public function getNextOccurrence($after_timestamp = null) { if ($after_timestamp === null) { $after_timestamp = time(); } $after_timestamp = (int) $after_timestamp; $next = false; if ($this->isRecurring()) { $next = $this->calculateEndAfterTimestamp(1, $after_timestamp, false); } else if ($after_timestamp < $this->getStartTimestamp()) { $next = $this->getStartTimestamp(); } if ($this->repeat_end_timestamp && $this->repeat_end_timestamp < $next) { return false; } return $next; }
[ "public", "function", "getNextOccurrence", "(", "$", "after_timestamp", "=", "null", ")", "{", "if", "(", "$", "after_timestamp", "===", "null", ")", "{", "$", "after_timestamp", "=", "time", "(", ")", ";", "}", "$", "after_timestamp", "=", "(", "int", ")", "$", "after_timestamp", ";", "$", "next", "=", "false", ";", "if", "(", "$", "this", "->", "isRecurring", "(", ")", ")", "{", "$", "next", "=", "$", "this", "->", "calculateEndAfterTimestamp", "(", "1", ",", "$", "after_timestamp", ",", "false", ")", ";", "}", "else", "if", "(", "$", "after_timestamp", "<", "$", "this", "->", "getStartTimestamp", "(", ")", ")", "{", "$", "next", "=", "$", "this", "->", "getStartTimestamp", "(", ")", ";", "}", "if", "(", "$", "this", "->", "repeat_end_timestamp", "&&", "$", "this", "->", "repeat_end_timestamp", "<", "$", "next", ")", "{", "return", "false", ";", "}", "return", "$", "next", ";", "}" ]
Returns the start timestamp of the next event occurence Returns false if there are no future occurrences @param int $after_timestamp Find next occurrence @return int|false
[ "Returns", "the", "start", "timestamp", "of", "the", "next", "event", "occurence", "Returns", "false", "if", "there", "are", "no", "future", "occurrences" ]
56c0f0ae403af1672a913db5dc259db9cb712491
https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Event.php#L572-L591
13,792
arckinteractive/events_api
classes/Events/API/Event.php
Event.getLastOccurrence
public function getLastOccurrence($before_timestamp = null) { if ($before_timestamp === null) { $before_timestamp = time(); } $before_timestamp = (int) $before_timestamp; $prev = false; if ($this->isRecurring()) { $starttimes = $this->getStartTimes($this->getStartTimestamp(), $before_timestamp); if ($starttimes) { $prev = end($starttimes); } } else { $prev = $this->getStartTimestamp(); if ($prev > $before_timestamp) { $prev = false; // there is no occurrence before the timestamp } } return $prev; }
php
public function getLastOccurrence($before_timestamp = null) { if ($before_timestamp === null) { $before_timestamp = time(); } $before_timestamp = (int) $before_timestamp; $prev = false; if ($this->isRecurring()) { $starttimes = $this->getStartTimes($this->getStartTimestamp(), $before_timestamp); if ($starttimes) { $prev = end($starttimes); } } else { $prev = $this->getStartTimestamp(); if ($prev > $before_timestamp) { $prev = false; // there is no occurrence before the timestamp } } return $prev; }
[ "public", "function", "getLastOccurrence", "(", "$", "before_timestamp", "=", "null", ")", "{", "if", "(", "$", "before_timestamp", "===", "null", ")", "{", "$", "before_timestamp", "=", "time", "(", ")", ";", "}", "$", "before_timestamp", "=", "(", "int", ")", "$", "before_timestamp", ";", "$", "prev", "=", "false", ";", "if", "(", "$", "this", "->", "isRecurring", "(", ")", ")", "{", "$", "starttimes", "=", "$", "this", "->", "getStartTimes", "(", "$", "this", "->", "getStartTimestamp", "(", ")", ",", "$", "before_timestamp", ")", ";", "if", "(", "$", "starttimes", ")", "{", "$", "prev", "=", "end", "(", "$", "starttimes", ")", ";", "}", "}", "else", "{", "$", "prev", "=", "$", "this", "->", "getStartTimestamp", "(", ")", ";", "if", "(", "$", "prev", ">", "$", "before_timestamp", ")", "{", "$", "prev", "=", "false", ";", "// there is no occurrence before the timestamp", "}", "}", "return", "$", "prev", ";", "}" ]
Returns the timestamp of the previous event occurence Returns false if there are no past occurrences @param int $before_timestamp Find previous occurrence @return int|false
[ "Returns", "the", "timestamp", "of", "the", "previous", "event", "occurence", "Returns", "false", "if", "there", "are", "no", "past", "occurrences" ]
56c0f0ae403af1672a913db5dc259db9cb712491
https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Event.php#L601-L625
13,793
arckinteractive/events_api
classes/Events/API/Event.php
Event.buildReminders
public function buildReminders($starttime, $endtime) { if (!$this->hasReminders()) { return true; } $starttime = sanitize_int($starttime); $endtime = sanitize_int($endtime); // first delete any existing reminders for this time period $this->removeReminders($starttime, $endtime); $reminders = elgg_get_metadata(array( 'guid' => $this->guid, 'metadata_name' => 'reminder', 'limit' => false )); // create reminders in this time period $starttimes = $this->getStartTimes($starttime, $endtime); foreach ($starttimes as $s) { foreach ($reminders as $r) { $reminder = $s - $r->value; if ($reminder < time()) { continue; // already passed } $this->annotate('reminder', $s - $r->value, ACCESS_PUBLIC); } } return true; }
php
public function buildReminders($starttime, $endtime) { if (!$this->hasReminders()) { return true; } $starttime = sanitize_int($starttime); $endtime = sanitize_int($endtime); // first delete any existing reminders for this time period $this->removeReminders($starttime, $endtime); $reminders = elgg_get_metadata(array( 'guid' => $this->guid, 'metadata_name' => 'reminder', 'limit' => false )); // create reminders in this time period $starttimes = $this->getStartTimes($starttime, $endtime); foreach ($starttimes as $s) { foreach ($reminders as $r) { $reminder = $s - $r->value; if ($reminder < time()) { continue; // already passed } $this->annotate('reminder', $s - $r->value, ACCESS_PUBLIC); } } return true; }
[ "public", "function", "buildReminders", "(", "$", "starttime", ",", "$", "endtime", ")", "{", "if", "(", "!", "$", "this", "->", "hasReminders", "(", ")", ")", "{", "return", "true", ";", "}", "$", "starttime", "=", "sanitize_int", "(", "$", "starttime", ")", ";", "$", "endtime", "=", "sanitize_int", "(", "$", "endtime", ")", ";", "// first delete any existing reminders for this time period", "$", "this", "->", "removeReminders", "(", "$", "starttime", ",", "$", "endtime", ")", ";", "$", "reminders", "=", "elgg_get_metadata", "(", "array", "(", "'guid'", "=>", "$", "this", "->", "guid", ",", "'metadata_name'", "=>", "'reminder'", ",", "'limit'", "=>", "false", ")", ")", ";", "// create reminders in this time period", "$", "starttimes", "=", "$", "this", "->", "getStartTimes", "(", "$", "starttime", ",", "$", "endtime", ")", ";", "foreach", "(", "$", "starttimes", "as", "$", "s", ")", "{", "foreach", "(", "$", "reminders", "as", "$", "r", ")", "{", "$", "reminder", "=", "$", "s", "-", "$", "r", "->", "value", ";", "if", "(", "$", "reminder", "<", "time", "(", ")", ")", "{", "continue", ";", "// already passed", "}", "$", "this", "->", "annotate", "(", "'reminder'", ",", "$", "s", "-", "$", "r", "->", "value", ",", "ACCESS_PUBLIC", ")", ";", "}", "}", "return", "true", ";", "}" ]
Creates reminder annotations for this event @param type $starttime @param type $endtime @return boolean
[ "Creates", "reminder", "annotations", "for", "this", "event" ]
56c0f0ae403af1672a913db5dc259db9cb712491
https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Event.php#L652-L682
13,794
dphn/ScContent
src/ScContent/Controller/Installation/InstallationController.php
InstallationController.indexAction
public function indexAction() { // To begin the step of installation, the user must click "continue". if (! $this->params()->fromRoute('process')) { return new ViewModel(); } $installation = $this->getInstallation(); $redirect = $this->getRedirect(); $step = $installation->getCurrentStep(); $member = $step->getCurrentMember(); $service = $this->getService(); $validator = $this->getValidator(); foreach ($member as $item) { if (! $validator->isValid($item)) { if (! $service->process($item)) { return new ViewModel([ 'errors' => $service->getMessages() ]); } } } return $this->redirect()->toUrl($redirect); }
php
public function indexAction() { // To begin the step of installation, the user must click "continue". if (! $this->params()->fromRoute('process')) { return new ViewModel(); } $installation = $this->getInstallation(); $redirect = $this->getRedirect(); $step = $installation->getCurrentStep(); $member = $step->getCurrentMember(); $service = $this->getService(); $validator = $this->getValidator(); foreach ($member as $item) { if (! $validator->isValid($item)) { if (! $service->process($item)) { return new ViewModel([ 'errors' => $service->getMessages() ]); } } } return $this->redirect()->toUrl($redirect); }
[ "public", "function", "indexAction", "(", ")", "{", "// To begin the step of installation, the user must click \"continue\".", "if", "(", "!", "$", "this", "->", "params", "(", ")", "->", "fromRoute", "(", "'process'", ")", ")", "{", "return", "new", "ViewModel", "(", ")", ";", "}", "$", "installation", "=", "$", "this", "->", "getInstallation", "(", ")", ";", "$", "redirect", "=", "$", "this", "->", "getRedirect", "(", ")", ";", "$", "step", "=", "$", "installation", "->", "getCurrentStep", "(", ")", ";", "$", "member", "=", "$", "step", "->", "getCurrentMember", "(", ")", ";", "$", "service", "=", "$", "this", "->", "getService", "(", ")", ";", "$", "validator", "=", "$", "this", "->", "getValidator", "(", ")", ";", "foreach", "(", "$", "member", "as", "$", "item", ")", "{", "if", "(", "!", "$", "validator", "->", "isValid", "(", "$", "item", ")", ")", "{", "if", "(", "!", "$", "service", "->", "process", "(", "$", "item", ")", ")", "{", "return", "new", "ViewModel", "(", "[", "'errors'", "=>", "$", "service", "->", "getMessages", "(", ")", "]", ")", ";", "}", "}", "}", "return", "$", "this", "->", "redirect", "(", ")", "->", "toUrl", "(", "$", "redirect", ")", ";", "}" ]
Runs services specified in the configuration. @throws \ScContent\Exception\DomainException @return \Zend\Stdlib\ResponseInterface|\Zend\View\Model\ViewModel
[ "Runs", "services", "specified", "in", "the", "configuration", "." ]
9dd5732490c45fd788b96cedf7b3c7adfacb30d2
https://github.com/dphn/ScContent/blob/9dd5732490c45fd788b96cedf7b3c7adfacb30d2/src/ScContent/Controller/Installation/InstallationController.php#L35-L59
13,795
arckinteractive/events_api
classes/Events/API/Calendar.php
Calendar.getAllEvents
public function getAllEvents($starttime = null, $endtime = null) { if (is_null($starttime)) { $starttime = time(); } if (is_null($endtime)) { $endtime = strtotime('+1 year', $starttime); } $starttime = sanitize_int($starttime); $endtime = sanitize_int($endtime); $relationship_name = sanitize_string(self::EVENT_CALENDAR_RELATIONSHIP); $dbprefix = elgg_get_config('dbprefix'); $mds_name = elgg_get_metastring_id('start_timestamp'); $mdre_name = elgg_get_metastring_id('repeat_end_timestamp'); $options = array( 'type' => 'object', 'subtype' => Event::SUBTYPE, 'joins' => array( "JOIN {$dbprefix}entity_relationships er ON er.guid_one = e.guid", // calendar relationship "JOIN {$dbprefix}metadata mds ON mds.entity_guid = e.guid", // start time metadata "JOIN {$dbprefix}metastrings mss ON mss.id = mds.value_id", // start time metastring "JOIN {$dbprefix}metadata mdre ON mdre.entity_guid = e.guid", // repeat end time metadata "JOIN {$dbprefix}metastrings msre ON msre.id = mdre.value_id" // repeat end time metastring ), 'wheres' => array( "er.guid_two = {$this->guid} AND er.relationship = '{$relationship_name}'", "mds.name_id = {$mds_name}", "mdre.name_id = {$mdre_name}", // event start is before our endtime AND (repeat end is after starttime, or there is no repeat end) "((CAST(mss.string AS SIGNED) < {$endtime}) AND (CAST(msre.string AS SIGNED) > {$starttime} OR CAST(msre.string AS SIGNED) = 0))" ), 'limit' => false ); return new ElggBatch('elgg_get_entities', $options); }
php
public function getAllEvents($starttime = null, $endtime = null) { if (is_null($starttime)) { $starttime = time(); } if (is_null($endtime)) { $endtime = strtotime('+1 year', $starttime); } $starttime = sanitize_int($starttime); $endtime = sanitize_int($endtime); $relationship_name = sanitize_string(self::EVENT_CALENDAR_RELATIONSHIP); $dbprefix = elgg_get_config('dbprefix'); $mds_name = elgg_get_metastring_id('start_timestamp'); $mdre_name = elgg_get_metastring_id('repeat_end_timestamp'); $options = array( 'type' => 'object', 'subtype' => Event::SUBTYPE, 'joins' => array( "JOIN {$dbprefix}entity_relationships er ON er.guid_one = e.guid", // calendar relationship "JOIN {$dbprefix}metadata mds ON mds.entity_guid = e.guid", // start time metadata "JOIN {$dbprefix}metastrings mss ON mss.id = mds.value_id", // start time metastring "JOIN {$dbprefix}metadata mdre ON mdre.entity_guid = e.guid", // repeat end time metadata "JOIN {$dbprefix}metastrings msre ON msre.id = mdre.value_id" // repeat end time metastring ), 'wheres' => array( "er.guid_two = {$this->guid} AND er.relationship = '{$relationship_name}'", "mds.name_id = {$mds_name}", "mdre.name_id = {$mdre_name}", // event start is before our endtime AND (repeat end is after starttime, or there is no repeat end) "((CAST(mss.string AS SIGNED) < {$endtime}) AND (CAST(msre.string AS SIGNED) > {$starttime} OR CAST(msre.string AS SIGNED) = 0))" ), 'limit' => false ); return new ElggBatch('elgg_get_entities', $options); }
[ "public", "function", "getAllEvents", "(", "$", "starttime", "=", "null", ",", "$", "endtime", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "starttime", ")", ")", "{", "$", "starttime", "=", "time", "(", ")", ";", "}", "if", "(", "is_null", "(", "$", "endtime", ")", ")", "{", "$", "endtime", "=", "strtotime", "(", "'+1 year'", ",", "$", "starttime", ")", ";", "}", "$", "starttime", "=", "sanitize_int", "(", "$", "starttime", ")", ";", "$", "endtime", "=", "sanitize_int", "(", "$", "endtime", ")", ";", "$", "relationship_name", "=", "sanitize_string", "(", "self", "::", "EVENT_CALENDAR_RELATIONSHIP", ")", ";", "$", "dbprefix", "=", "elgg_get_config", "(", "'dbprefix'", ")", ";", "$", "mds_name", "=", "elgg_get_metastring_id", "(", "'start_timestamp'", ")", ";", "$", "mdre_name", "=", "elgg_get_metastring_id", "(", "'repeat_end_timestamp'", ")", ";", "$", "options", "=", "array", "(", "'type'", "=>", "'object'", ",", "'subtype'", "=>", "Event", "::", "SUBTYPE", ",", "'joins'", "=>", "array", "(", "\"JOIN {$dbprefix}entity_relationships er ON er.guid_one = e.guid\"", ",", "// calendar relationship", "\"JOIN {$dbprefix}metadata mds ON mds.entity_guid = e.guid\"", ",", "// start time metadata", "\"JOIN {$dbprefix}metastrings mss ON mss.id = mds.value_id\"", ",", "// start time metastring", "\"JOIN {$dbprefix}metadata mdre ON mdre.entity_guid = e.guid\"", ",", "// repeat end time metadata", "\"JOIN {$dbprefix}metastrings msre ON msre.id = mdre.value_id\"", "// repeat end time metastring", ")", ",", "'wheres'", "=>", "array", "(", "\"er.guid_two = {$this->guid} AND er.relationship = '{$relationship_name}'\"", ",", "\"mds.name_id = {$mds_name}\"", ",", "\"mdre.name_id = {$mdre_name}\"", ",", "// event start is before our endtime AND (repeat end is after starttime, or there is no repeat end)", "\"((CAST(mss.string AS SIGNED) < {$endtime}) AND (CAST(msre.string AS SIGNED) > {$starttime} OR CAST(msre.string AS SIGNED) = 0))\"", ")", ",", "'limit'", "=>", "false", ")", ";", "return", "new", "ElggBatch", "(", "'elgg_get_entities'", ",", "$", "options", ")", ";", "}" ]
Returns all event objects @param int $starttime Time range start, default: now @param int $endtime Time range end, default: 1 year from start time @return ElggBatch
[ "Returns", "all", "event", "objects" ]
56c0f0ae403af1672a913db5dc259db9cb712491
https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Calendar.php#L64-L103
13,796
arckinteractive/events_api
classes/Events/API/Calendar.php
Calendar.compareInstancesByStartTime
public static function compareInstancesByStartTime($a, $b) { $start_a = $a->getStartTimestamp(); $start_b = $b->getStartTimestamp(); if ($start_a == $start_b) { return 0; } return ($start_a < $start_b) ? -1 : 1; }
php
public static function compareInstancesByStartTime($a, $b) { $start_a = $a->getStartTimestamp(); $start_b = $b->getStartTimestamp(); if ($start_a == $start_b) { return 0; } return ($start_a < $start_b) ? -1 : 1; }
[ "public", "static", "function", "compareInstancesByStartTime", "(", "$", "a", ",", "$", "b", ")", "{", "$", "start_a", "=", "$", "a", "->", "getStartTimestamp", "(", ")", ";", "$", "start_b", "=", "$", "b", "->", "getStartTimestamp", "(", ")", ";", "if", "(", "$", "start_a", "==", "$", "start_b", ")", "{", "return", "0", ";", "}", "return", "(", "$", "start_a", "<", "$", "start_b", ")", "?", "-", "1", ":", "1", ";", "}" ]
Compares two event instances by start time @param EventInstance $a Instance @param EventInstance $b Instance @return int
[ "Compares", "two", "event", "instances", "by", "start", "time" ]
56c0f0ae403af1672a913db5dc259db9cb712491
https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Calendar.php#L174-L181
13,797
arckinteractive/events_api
classes/Events/API/Calendar.php
Calendar.getRecurringEvents
public function getRecurringEvents($starttime = null, $endtime = null) { if (is_null($starttime)) { $starttime = time(); } if (is_null($endtime)) { $endtime = strtotime('+1 year', $starttime); } $starttime = sanitize_int($starttime); $endtime = sanitize_int($endtime); $relationship_name = sanitize_string(self::EVENT_CALENDAR_RELATIONSHIP); $dbprefix = elgg_get_config('dbprefix'); // for performance we'll denormalize metastrings first $mdr_name = elgg_get_metastring_id('repeat'); $mdr_val = elgg_get_metastring_id(1); $mds_name = elgg_get_metastring_id('start_timestamp'); $mdre_name = elgg_get_metastring_id('repeat_end_timestamp'); $options = array( 'type' => 'object', 'subtype' => Event::SUBTYPE, 'joins' => array( "JOIN {$dbprefix}entity_relationships er ON er.guid_one = e.guid", // calendar relationship "JOIN {$dbprefix}metadata mdr ON mdr.entity_guid = e.guid", // repeating metadata "JOIN {$dbprefix}metadata mds ON mds.entity_guid = e.guid", // start time metadata "JOIN {$dbprefix}metastrings mss ON mss.id = mds.value_id", // start time metastring "JOIN {$dbprefix}metadata mdre ON mdre.entity_guid = e.guid", // repeat end time metadata "JOIN {$dbprefix}metastrings msre ON msre.id = mdre.value_id" // repeat end time metastring ), 'wheres' => array( "er.guid_two = {$this->guid} AND er.relationship = '{$relationship_name}'", "mdr.name_id = {$mdr_name} AND mdr.value_id = {$mdr_val}", "mds.name_id = {$mds_name}", "mdre.name_id = {$mdre_name}", // event start is before our endtime AND (repeat end is after starttime, or there is no repeat end) "((CAST(mss.string AS SIGNED) < {$endtime}) AND (CAST(msre.string AS SIGNED) > {$starttime} OR CAST(msre.string AS SIGNED) = 0))" ), 'limit' => false ); $events = new ElggBatch('elgg_get_entities', $options); // these entities may not actually show up in our range yet, need to filter $recurring_events = array(); foreach ($events as $event) { /* @var Event $event */ if ($event->getStartTimes($starttime, $endtime)) { // hey, we have a hit! $recurring_events[] = $event; } } return $recurring_events; }
php
public function getRecurringEvents($starttime = null, $endtime = null) { if (is_null($starttime)) { $starttime = time(); } if (is_null($endtime)) { $endtime = strtotime('+1 year', $starttime); } $starttime = sanitize_int($starttime); $endtime = sanitize_int($endtime); $relationship_name = sanitize_string(self::EVENT_CALENDAR_RELATIONSHIP); $dbprefix = elgg_get_config('dbprefix'); // for performance we'll denormalize metastrings first $mdr_name = elgg_get_metastring_id('repeat'); $mdr_val = elgg_get_metastring_id(1); $mds_name = elgg_get_metastring_id('start_timestamp'); $mdre_name = elgg_get_metastring_id('repeat_end_timestamp'); $options = array( 'type' => 'object', 'subtype' => Event::SUBTYPE, 'joins' => array( "JOIN {$dbprefix}entity_relationships er ON er.guid_one = e.guid", // calendar relationship "JOIN {$dbprefix}metadata mdr ON mdr.entity_guid = e.guid", // repeating metadata "JOIN {$dbprefix}metadata mds ON mds.entity_guid = e.guid", // start time metadata "JOIN {$dbprefix}metastrings mss ON mss.id = mds.value_id", // start time metastring "JOIN {$dbprefix}metadata mdre ON mdre.entity_guid = e.guid", // repeat end time metadata "JOIN {$dbprefix}metastrings msre ON msre.id = mdre.value_id" // repeat end time metastring ), 'wheres' => array( "er.guid_two = {$this->guid} AND er.relationship = '{$relationship_name}'", "mdr.name_id = {$mdr_name} AND mdr.value_id = {$mdr_val}", "mds.name_id = {$mds_name}", "mdre.name_id = {$mdre_name}", // event start is before our endtime AND (repeat end is after starttime, or there is no repeat end) "((CAST(mss.string AS SIGNED) < {$endtime}) AND (CAST(msre.string AS SIGNED) > {$starttime} OR CAST(msre.string AS SIGNED) = 0))" ), 'limit' => false ); $events = new ElggBatch('elgg_get_entities', $options); // these entities may not actually show up in our range yet, need to filter $recurring_events = array(); foreach ($events as $event) { /* @var Event $event */ if ($event->getStartTimes($starttime, $endtime)) { // hey, we have a hit! $recurring_events[] = $event; } } return $recurring_events; }
[ "public", "function", "getRecurringEvents", "(", "$", "starttime", "=", "null", ",", "$", "endtime", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "starttime", ")", ")", "{", "$", "starttime", "=", "time", "(", ")", ";", "}", "if", "(", "is_null", "(", "$", "endtime", ")", ")", "{", "$", "endtime", "=", "strtotime", "(", "'+1 year'", ",", "$", "starttime", ")", ";", "}", "$", "starttime", "=", "sanitize_int", "(", "$", "starttime", ")", ";", "$", "endtime", "=", "sanitize_int", "(", "$", "endtime", ")", ";", "$", "relationship_name", "=", "sanitize_string", "(", "self", "::", "EVENT_CALENDAR_RELATIONSHIP", ")", ";", "$", "dbprefix", "=", "elgg_get_config", "(", "'dbprefix'", ")", ";", "// for performance we'll denormalize metastrings first", "$", "mdr_name", "=", "elgg_get_metastring_id", "(", "'repeat'", ")", ";", "$", "mdr_val", "=", "elgg_get_metastring_id", "(", "1", ")", ";", "$", "mds_name", "=", "elgg_get_metastring_id", "(", "'start_timestamp'", ")", ";", "$", "mdre_name", "=", "elgg_get_metastring_id", "(", "'repeat_end_timestamp'", ")", ";", "$", "options", "=", "array", "(", "'type'", "=>", "'object'", ",", "'subtype'", "=>", "Event", "::", "SUBTYPE", ",", "'joins'", "=>", "array", "(", "\"JOIN {$dbprefix}entity_relationships er ON er.guid_one = e.guid\"", ",", "// calendar relationship", "\"JOIN {$dbprefix}metadata mdr ON mdr.entity_guid = e.guid\"", ",", "// repeating metadata", "\"JOIN {$dbprefix}metadata mds ON mds.entity_guid = e.guid\"", ",", "// start time metadata", "\"JOIN {$dbprefix}metastrings mss ON mss.id = mds.value_id\"", ",", "// start time metastring", "\"JOIN {$dbprefix}metadata mdre ON mdre.entity_guid = e.guid\"", ",", "// repeat end time metadata", "\"JOIN {$dbprefix}metastrings msre ON msre.id = mdre.value_id\"", "// repeat end time metastring", ")", ",", "'wheres'", "=>", "array", "(", "\"er.guid_two = {$this->guid} AND er.relationship = '{$relationship_name}'\"", ",", "\"mdr.name_id = {$mdr_name} AND mdr.value_id = {$mdr_val}\"", ",", "\"mds.name_id = {$mds_name}\"", ",", "\"mdre.name_id = {$mdre_name}\"", ",", "// event start is before our endtime AND (repeat end is after starttime, or there is no repeat end)", "\"((CAST(mss.string AS SIGNED) < {$endtime}) AND (CAST(msre.string AS SIGNED) > {$starttime} OR CAST(msre.string AS SIGNED) = 0))\"", ")", ",", "'limit'", "=>", "false", ")", ";", "$", "events", "=", "new", "ElggBatch", "(", "'elgg_get_entities'", ",", "$", "options", ")", ";", "// these entities may not actually show up in our range yet, need to filter", "$", "recurring_events", "=", "array", "(", ")", ";", "foreach", "(", "$", "events", "as", "$", "event", ")", "{", "/* @var Event $event */", "if", "(", "$", "event", "->", "getStartTimes", "(", "$", "starttime", ",", "$", "endtime", ")", ")", "{", "// hey, we have a hit!", "$", "recurring_events", "[", "]", "=", "$", "event", ";", "}", "}", "return", "$", "recurring_events", ";", "}" ]
Returns a batch of recurring events in a given time range @param int $starttime Time range start, default: now @param int $endtime Time range end, default: 1 year from start time @return array
[ "Returns", "a", "batch", "of", "recurring", "events", "in", "a", "given", "time", "range" ]
56c0f0ae403af1672a913db5dc259db9cb712491
https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Calendar.php#L190-L245
13,798
arckinteractive/events_api
classes/Events/API/Calendar.php
Calendar.getOneTimeEvents
public function getOneTimeEvents($starttime = null, $endtime = null) { if (is_null($starttime)) { $starttime = time(); } if (is_null($endtime)) { $endtime = strtotime('+1 year', $starttime); } $starttime = sanitize_int($starttime); $endtime = sanitize_int($endtime); $relationship_name = sanitize_string(self::EVENT_CALENDAR_RELATIONSHIP); $dbprefix = elgg_get_config('dbprefix'); // for performance we'll denormalize metastrings first $mdr_name = elgg_get_metastring_id('repeat'); $mdr_val = elgg_get_metastring_id(0); $mds_name = elgg_get_metastring_id('start_timestamp'); $mde_name = elgg_get_metastring_id('end_timestamp'); $options = array( 'type' => 'object', 'subtype' => Event::SUBTYPE, 'joins' => array( "JOIN {$dbprefix}entity_relationships er ON er.guid_one = e.guid", // calendar relationship "JOIN {$dbprefix}metadata mdr ON mdr.entity_guid = e.guid", // repeating metadata "JOIN {$dbprefix}metadata mds ON mds.entity_guid = e.guid", // start time metadata "JOIN {$dbprefix}metastrings mss ON mss.id = mds.value_id", // start time metastring "JOIN {$dbprefix}metadata mde ON mde.entity_guid = e.guid", // end time metadata "JOIN {$dbprefix}metastrings mse ON mse.id = mde.value_id" // end time metastring ), 'wheres' => array( "er.guid_two = {$this->guid} AND er.relationship = '{$relationship_name}'", "mdr.name_id = {$mdr_name} AND mdr.value_id = {$mdr_val}", "mds.name_id = {$mds_name}", "mde.name_id = {$mde_name}", "((CAST(mss.string AS SIGNED) BETWEEN {$starttime} AND {$endtime}) OR (CAST(mse.string AS SIGNED) BETWEEN {$starttime} AND {$endtime}))" ), 'limit' => false ); return new ElggBatch('elgg_get_entities', $options); }
php
public function getOneTimeEvents($starttime = null, $endtime = null) { if (is_null($starttime)) { $starttime = time(); } if (is_null($endtime)) { $endtime = strtotime('+1 year', $starttime); } $starttime = sanitize_int($starttime); $endtime = sanitize_int($endtime); $relationship_name = sanitize_string(self::EVENT_CALENDAR_RELATIONSHIP); $dbprefix = elgg_get_config('dbprefix'); // for performance we'll denormalize metastrings first $mdr_name = elgg_get_metastring_id('repeat'); $mdr_val = elgg_get_metastring_id(0); $mds_name = elgg_get_metastring_id('start_timestamp'); $mde_name = elgg_get_metastring_id('end_timestamp'); $options = array( 'type' => 'object', 'subtype' => Event::SUBTYPE, 'joins' => array( "JOIN {$dbprefix}entity_relationships er ON er.guid_one = e.guid", // calendar relationship "JOIN {$dbprefix}metadata mdr ON mdr.entity_guid = e.guid", // repeating metadata "JOIN {$dbprefix}metadata mds ON mds.entity_guid = e.guid", // start time metadata "JOIN {$dbprefix}metastrings mss ON mss.id = mds.value_id", // start time metastring "JOIN {$dbprefix}metadata mde ON mde.entity_guid = e.guid", // end time metadata "JOIN {$dbprefix}metastrings mse ON mse.id = mde.value_id" // end time metastring ), 'wheres' => array( "er.guid_two = {$this->guid} AND er.relationship = '{$relationship_name}'", "mdr.name_id = {$mdr_name} AND mdr.value_id = {$mdr_val}", "mds.name_id = {$mds_name}", "mde.name_id = {$mde_name}", "((CAST(mss.string AS SIGNED) BETWEEN {$starttime} AND {$endtime}) OR (CAST(mse.string AS SIGNED) BETWEEN {$starttime} AND {$endtime}))" ), 'limit' => false ); return new ElggBatch('elgg_get_entities', $options); }
[ "public", "function", "getOneTimeEvents", "(", "$", "starttime", "=", "null", ",", "$", "endtime", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "starttime", ")", ")", "{", "$", "starttime", "=", "time", "(", ")", ";", "}", "if", "(", "is_null", "(", "$", "endtime", ")", ")", "{", "$", "endtime", "=", "strtotime", "(", "'+1 year'", ",", "$", "starttime", ")", ";", "}", "$", "starttime", "=", "sanitize_int", "(", "$", "starttime", ")", ";", "$", "endtime", "=", "sanitize_int", "(", "$", "endtime", ")", ";", "$", "relationship_name", "=", "sanitize_string", "(", "self", "::", "EVENT_CALENDAR_RELATIONSHIP", ")", ";", "$", "dbprefix", "=", "elgg_get_config", "(", "'dbprefix'", ")", ";", "// for performance we'll denormalize metastrings first", "$", "mdr_name", "=", "elgg_get_metastring_id", "(", "'repeat'", ")", ";", "$", "mdr_val", "=", "elgg_get_metastring_id", "(", "0", ")", ";", "$", "mds_name", "=", "elgg_get_metastring_id", "(", "'start_timestamp'", ")", ";", "$", "mde_name", "=", "elgg_get_metastring_id", "(", "'end_timestamp'", ")", ";", "$", "options", "=", "array", "(", "'type'", "=>", "'object'", ",", "'subtype'", "=>", "Event", "::", "SUBTYPE", ",", "'joins'", "=>", "array", "(", "\"JOIN {$dbprefix}entity_relationships er ON er.guid_one = e.guid\"", ",", "// calendar relationship", "\"JOIN {$dbprefix}metadata mdr ON mdr.entity_guid = e.guid\"", ",", "// repeating metadata", "\"JOIN {$dbprefix}metadata mds ON mds.entity_guid = e.guid\"", ",", "// start time metadata", "\"JOIN {$dbprefix}metastrings mss ON mss.id = mds.value_id\"", ",", "// start time metastring", "\"JOIN {$dbprefix}metadata mde ON mde.entity_guid = e.guid\"", ",", "// end time metadata", "\"JOIN {$dbprefix}metastrings mse ON mse.id = mde.value_id\"", "// end time metastring", ")", ",", "'wheres'", "=>", "array", "(", "\"er.guid_two = {$this->guid} AND er.relationship = '{$relationship_name}'\"", ",", "\"mdr.name_id = {$mdr_name} AND mdr.value_id = {$mdr_val}\"", ",", "\"mds.name_id = {$mds_name}\"", ",", "\"mde.name_id = {$mde_name}\"", ",", "\"((CAST(mss.string AS SIGNED) BETWEEN {$starttime} AND {$endtime})\n\t\t\t\t\tOR (CAST(mse.string AS SIGNED) BETWEEN {$starttime} AND {$endtime}))\"", ")", ",", "'limit'", "=>", "false", ")", ";", "return", "new", "ElggBatch", "(", "'elgg_get_entities'", ",", "$", "options", ")", ";", "}" ]
Returns one-time events @param int $starttime Time range start, default: now @param int $endtime Time range end, default: 1 year from start time @return ElggBatch
[ "Returns", "one", "-", "time", "events" ]
56c0f0ae403af1672a913db5dc259db9cb712491
https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Calendar.php#L254-L297
13,799
arckinteractive/events_api
classes/Events/API/Calendar.php
Calendar.hasEvent
public function hasEvent($event) { return (bool) check_entity_relationship($event->guid, self::EVENT_CALENDAR_RELATIONSHIP, $this->guid); }
php
public function hasEvent($event) { return (bool) check_entity_relationship($event->guid, self::EVENT_CALENDAR_RELATIONSHIP, $this->guid); }
[ "public", "function", "hasEvent", "(", "$", "event", ")", "{", "return", "(", "bool", ")", "check_entity_relationship", "(", "$", "event", "->", "guid", ",", "self", "::", "EVENT_CALENDAR_RELATIONSHIP", ",", "$", "this", "->", "guid", ")", ";", "}" ]
Checks if the event is on calendar @param Event $event Event @return bool
[ "Checks", "if", "the", "event", "is", "on", "calendar" ]
56c0f0ae403af1672a913db5dc259db9cb712491
https://github.com/arckinteractive/events_api/blob/56c0f0ae403af1672a913db5dc259db9cb712491/classes/Events/API/Calendar.php#L316-L318