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
20,000
Chill-project/Main
Export/Formatter/CSVListFormatter.php
CSVListFormatter.buildForm
public function buildForm( FormBuilderInterface $builder, $exportAlias, array $aggregatorAliases ){ $builder->add('numerotation', ChoiceType::class, array( 'choices' => array( 'yes' => true, 'no' => false ), 'expanded' => true, 'multiple' => false, 'label' => "Add a number on first column", 'choices_as_values' => true, 'data' => true )); }
php
public function buildForm( FormBuilderInterface $builder, $exportAlias, array $aggregatorAliases ){ $builder->add('numerotation', ChoiceType::class, array( 'choices' => array( 'yes' => true, 'no' => false ), 'expanded' => true, 'multiple' => false, 'label' => "Add a number on first column", 'choices_as_values' => true, 'data' => true )); }
[ "public", "function", "buildForm", "(", "FormBuilderInterface", "$", "builder", ",", "$", "exportAlias", ",", "array", "$", "aggregatorAliases", ")", "{", "$", "builder", "->", "add", "(", "'numerotation'", ",", "ChoiceType", "::", "class", ",", "array", "(", "'choices'", "=>", "array", "(", "'yes'", "=>", "true", ",", "'no'", "=>", "false", ")", ",", "'expanded'", "=>", "true", ",", "'multiple'", "=>", "false", ",", "'label'", "=>", "\"Add a number on first column\"", ",", "'choices_as_values'", "=>", "true", ",", "'data'", "=>", "true", ")", ")", ";", "}" ]
build a form, which will be used to collect data required for the execution of this formatter. @uses appendAggregatorForm @param FormBuilderInterface $builder @param type $exportAlias @param array $aggregatorAliases
[ "build", "a", "form", "which", "will", "be", "used", "to", "collect", "data", "required", "for", "the", "execution", "of", "this", "formatter", "." ]
384cb6c793072a4f1047dc5cafc2157ee2419f60
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Export/Formatter/CSVListFormatter.php#L93-L109
20,001
Chill-project/Main
Export/Formatter/CSVListFormatter.php
CSVListFormatter.getResponse
public function getResponse( $result, $formatterData, $exportAlias, array $exportData, array $filtersData, array $aggregatorsData ) { $this->result = $result; $this->exportAlias = $exportAlias; $this->exportData = $exportData; $this->formatterData = $formatterData; $output = fopen('php://output', 'w'); $this->prepareHeaders($output); $i = 1; foreach ($result as $row) { $line = array(); if ($this->formatterData['numerotation'] === true) { $line[] = $i; } foreach ($row as $key => $value) { $line[] = $this->getLabel($key, $value); } fputcsv($output, $line); $i++; } $csvContent = stream_get_contents($output); fclose($output); $response = new Response(); $response->setStatusCode(200); $response->headers->set('Content-Type', 'text/csv; charset=utf-8'); //$response->headers->set('Content-Disposition','attachment; filename="export.csv"'); $response->setContent($csvContent); return $response; }
php
public function getResponse( $result, $formatterData, $exportAlias, array $exportData, array $filtersData, array $aggregatorsData ) { $this->result = $result; $this->exportAlias = $exportAlias; $this->exportData = $exportData; $this->formatterData = $formatterData; $output = fopen('php://output', 'w'); $this->prepareHeaders($output); $i = 1; foreach ($result as $row) { $line = array(); if ($this->formatterData['numerotation'] === true) { $line[] = $i; } foreach ($row as $key => $value) { $line[] = $this->getLabel($key, $value); } fputcsv($output, $line); $i++; } $csvContent = stream_get_contents($output); fclose($output); $response = new Response(); $response->setStatusCode(200); $response->headers->set('Content-Type', 'text/csv; charset=utf-8'); //$response->headers->set('Content-Disposition','attachment; filename="export.csv"'); $response->setContent($csvContent); return $response; }
[ "public", "function", "getResponse", "(", "$", "result", ",", "$", "formatterData", ",", "$", "exportAlias", ",", "array", "$", "exportData", ",", "array", "$", "filtersData", ",", "array", "$", "aggregatorsData", ")", "{", "$", "this", "->", "result", "=", "$", "result", ";", "$", "this", "->", "exportAlias", "=", "$", "exportAlias", ";", "$", "this", "->", "exportData", "=", "$", "exportData", ";", "$", "this", "->", "formatterData", "=", "$", "formatterData", ";", "$", "output", "=", "fopen", "(", "'php://output'", ",", "'w'", ")", ";", "$", "this", "->", "prepareHeaders", "(", "$", "output", ")", ";", "$", "i", "=", "1", ";", "foreach", "(", "$", "result", "as", "$", "row", ")", "{", "$", "line", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "formatterData", "[", "'numerotation'", "]", "===", "true", ")", "{", "$", "line", "[", "]", "=", "$", "i", ";", "}", "foreach", "(", "$", "row", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "line", "[", "]", "=", "$", "this", "->", "getLabel", "(", "$", "key", ",", "$", "value", ")", ";", "}", "fputcsv", "(", "$", "output", ",", "$", "line", ")", ";", "$", "i", "++", ";", "}", "$", "csvContent", "=", "stream_get_contents", "(", "$", "output", ")", ";", "fclose", "(", "$", "output", ")", ";", "$", "response", "=", "new", "Response", "(", ")", ";", "$", "response", "->", "setStatusCode", "(", "200", ")", ";", "$", "response", "->", "headers", "->", "set", "(", "'Content-Type'", ",", "'text/csv; charset=utf-8'", ")", ";", "//$response->headers->set('Content-Disposition','attachment; filename=\"export.csv\"');", "$", "response", "->", "setContent", "(", "$", "csvContent", ")", ";", "return", "$", "response", ";", "}" ]
Generate a response from the data collected on differents ExportElementInterface @param mixed[] $result The result, as given by the ExportInterface @param mixed[] $formatterData collected from the current form @param string $exportAlias the id of the current export @param array $filtersData an array containing the filters data. The key are the filters id, and the value are the data @param array $aggregatorsData an array containing the aggregators data. The key are the filters id, and the value are the data @return \Symfony\Component\HttpFoundation\Response The response to be shown
[ "Generate", "a", "response", "from", "the", "data", "collected", "on", "differents", "ExportElementInterface" ]
384cb6c793072a4f1047dc5cafc2157ee2419f60
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Export/Formatter/CSVListFormatter.php#L121-L166
20,002
Chill-project/Main
Export/Formatter/CSVListFormatter.php
CSVListFormatter.prepareHeaders
protected function prepareHeaders($output) { $keys = $this->exportManager->getExport($this->exportAlias)->getQueryKeys($this->exportData); // we want to keep the order of the first row. So we will iterate on the first row of the results $first_row = count($this->result) > 0 ? $this->result[0] : array(); $header_line = array(); if ($this->formatterData['numerotation'] === true) { $header_line[] = $this->translator->trans('Number'); } foreach ($first_row as $key => $value) { $header_line[] = $this->getLabel($key, '_header'); } if (count($header_line) > 0) { fputcsv($output, $header_line); } }
php
protected function prepareHeaders($output) { $keys = $this->exportManager->getExport($this->exportAlias)->getQueryKeys($this->exportData); // we want to keep the order of the first row. So we will iterate on the first row of the results $first_row = count($this->result) > 0 ? $this->result[0] : array(); $header_line = array(); if ($this->formatterData['numerotation'] === true) { $header_line[] = $this->translator->trans('Number'); } foreach ($first_row as $key => $value) { $header_line[] = $this->getLabel($key, '_header'); } if (count($header_line) > 0) { fputcsv($output, $header_line); } }
[ "protected", "function", "prepareHeaders", "(", "$", "output", ")", "{", "$", "keys", "=", "$", "this", "->", "exportManager", "->", "getExport", "(", "$", "this", "->", "exportAlias", ")", "->", "getQueryKeys", "(", "$", "this", "->", "exportData", ")", ";", "// we want to keep the order of the first row. So we will iterate on the first row of the results", "$", "first_row", "=", "count", "(", "$", "this", "->", "result", ")", ">", "0", "?", "$", "this", "->", "result", "[", "0", "]", ":", "array", "(", ")", ";", "$", "header_line", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "formatterData", "[", "'numerotation'", "]", "===", "true", ")", "{", "$", "header_line", "[", "]", "=", "$", "this", "->", "translator", "->", "trans", "(", "'Number'", ")", ";", "}", "foreach", "(", "$", "first_row", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "header_line", "[", "]", "=", "$", "this", "->", "getLabel", "(", "$", "key", ",", "'_header'", ")", ";", "}", "if", "(", "count", "(", "$", "header_line", ")", ">", "0", ")", "{", "fputcsv", "(", "$", "output", ",", "$", "header_line", ")", ";", "}", "}" ]
add the headers to the csv file @param resource $output
[ "add", "the", "headers", "to", "the", "csv", "file" ]
384cb6c793072a4f1047dc5cafc2157ee2419f60
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Export/Formatter/CSVListFormatter.php#L173-L191
20,003
Chill-project/Main
Export/Formatter/CSVListFormatter.php
CSVListFormatter.getLabel
protected function getLabel($key, $value) { if ($this->labelsCache === null) { $this->prepareCacheLabels(); } return $this->labelsCache[$key]($value); }
php
protected function getLabel($key, $value) { if ($this->labelsCache === null) { $this->prepareCacheLabels(); } return $this->labelsCache[$key]($value); }
[ "protected", "function", "getLabel", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "$", "this", "->", "labelsCache", "===", "null", ")", "{", "$", "this", "->", "prepareCacheLabels", "(", ")", ";", "}", "return", "$", "this", "->", "labelsCache", "[", "$", "key", "]", "(", "$", "value", ")", ";", "}" ]
Give the label corresponding to the given key and value. @param string $key @param string $value @return string @throws \LogicException if the label is not found
[ "Give", "the", "label", "corresponding", "to", "the", "given", "key", "and", "value", "." ]
384cb6c793072a4f1047dc5cafc2157ee2419f60
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Export/Formatter/CSVListFormatter.php#L201-L209
20,004
Chill-project/Main
Export/Formatter/CSVListFormatter.php
CSVListFormatter.prepareCacheLabels
protected function prepareCacheLabels() { $export = $this->exportManager->getExport($this->exportAlias); $keys = $export->getQueryKeys($this->exportData); foreach($keys as $key) { // get an array with all values for this key if possible $values = \array_map(function ($v) use ($key) { return $v[$key]; }, $this->result); // store the label in the labelsCache property $this->labelsCache[$key] = $export->getLabels($key, $values, $this->exportData); } }
php
protected function prepareCacheLabels() { $export = $this->exportManager->getExport($this->exportAlias); $keys = $export->getQueryKeys($this->exportData); foreach($keys as $key) { // get an array with all values for this key if possible $values = \array_map(function ($v) use ($key) { return $v[$key]; }, $this->result); // store the label in the labelsCache property $this->labelsCache[$key] = $export->getLabels($key, $values, $this->exportData); } }
[ "protected", "function", "prepareCacheLabels", "(", ")", "{", "$", "export", "=", "$", "this", "->", "exportManager", "->", "getExport", "(", "$", "this", "->", "exportAlias", ")", ";", "$", "keys", "=", "$", "export", "->", "getQueryKeys", "(", "$", "this", "->", "exportData", ")", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "// get an array with all values for this key if possible", "$", "values", "=", "\\", "array_map", "(", "function", "(", "$", "v", ")", "use", "(", "$", "key", ")", "{", "return", "$", "v", "[", "$", "key", "]", ";", "}", ",", "$", "this", "->", "result", ")", ";", "// store the label in the labelsCache property", "$", "this", "->", "labelsCache", "[", "$", "key", "]", "=", "$", "export", "->", "getLabels", "(", "$", "key", ",", "$", "values", ",", "$", "this", "->", "exportData", ")", ";", "}", "}" ]
Prepare the label cache which will be used by getLabel. This function should be called only once in the generation lifecycle.
[ "Prepare", "the", "label", "cache", "which", "will", "be", "used", "by", "getLabel", ".", "This", "function", "should", "be", "called", "only", "once", "in", "the", "generation", "lifecycle", "." ]
384cb6c793072a4f1047dc5cafc2157ee2419f60
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Export/Formatter/CSVListFormatter.php#L215-L226
20,005
hackzilla/ticket-message
Component/TicketFeatures.php
TicketFeatures.hasFeature
public function hasFeature($feature) { $feature = strtoupper($feature); if (!isset($this->features[$feature])) { return null; } return $this->features[$feature]; }
php
public function hasFeature($feature) { $feature = strtoupper($feature); if (!isset($this->features[$feature])) { return null; } return $this->features[$feature]; }
[ "public", "function", "hasFeature", "(", "$", "feature", ")", "{", "$", "feature", "=", "strtoupper", "(", "$", "feature", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "features", "[", "$", "feature", "]", ")", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "features", "[", "$", "feature", "]", ";", "}" ]
Check if feature exists and enabled. @param string $feature @return bool|null
[ "Check", "if", "feature", "exists", "and", "enabled", "." ]
043950aa95f322cfaae145ce3c7781a4b0618a18
https://github.com/hackzilla/ticket-message/blob/043950aa95f322cfaae145ce3c7781a4b0618a18/Component/TicketFeatures.php#L32-L41
20,006
redaigbaria/oauth2
src/AbstractServer.php
AbstractServer.setEventEmitter
public function setEventEmitter($emitter = null) { if ($emitter === null) { $this->eventEmitter = new Emitter(); } else { $this->eventEmitter = $emitter; } }
php
public function setEventEmitter($emitter = null) { if ($emitter === null) { $this->eventEmitter = new Emitter(); } else { $this->eventEmitter = $emitter; } }
[ "public", "function", "setEventEmitter", "(", "$", "emitter", "=", "null", ")", "{", "if", "(", "$", "emitter", "===", "null", ")", "{", "$", "this", "->", "eventEmitter", "=", "new", "Emitter", "(", ")", ";", "}", "else", "{", "$", "this", "->", "eventEmitter", "=", "$", "emitter", ";", "}", "}" ]
Set an event emitter @param object $emitter Event emitter object
[ "Set", "an", "event", "emitter" ]
54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/AbstractServer.php#L111-L118
20,007
redaigbaria/oauth2
src/AbstractServer.php
AbstractServer.addEventListener
public function addEventListener($eventName, callable $listener, $priority = Emitter::P_NORMAL) { $this->eventEmitter->addListener($eventName, $listener, $priority); }
php
public function addEventListener($eventName, callable $listener, $priority = Emitter::P_NORMAL) { $this->eventEmitter->addListener($eventName, $listener, $priority); }
[ "public", "function", "addEventListener", "(", "$", "eventName", ",", "callable", "$", "listener", ",", "$", "priority", "=", "Emitter", "::", "P_NORMAL", ")", "{", "$", "this", "->", "eventEmitter", "->", "addListener", "(", "$", "eventName", ",", "$", "listener", ",", "$", "priority", ")", ";", "}" ]
Add an event listener to the event emitter @param string $eventName Event name @param callable $listener Callable function or method @param int $priority Priority of event listener
[ "Add", "an", "event", "listener", "to", "the", "event", "emitter" ]
54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/AbstractServer.php#L127-L130
20,008
redaigbaria/oauth2
src/AbstractServer.php
AbstractServer.setClientStorage
public function setClientStorage(ClientInterface $storage) { $storage->setServer($this); $this->clientStorage = $storage; return $this; }
php
public function setClientStorage(ClientInterface $storage) { $storage->setServer($this); $this->clientStorage = $storage; return $this; }
[ "public", "function", "setClientStorage", "(", "ClientInterface", "$", "storage", ")", "{", "$", "storage", "->", "setServer", "(", "$", "this", ")", ";", "$", "this", "->", "clientStorage", "=", "$", "storage", ";", "return", "$", "this", ";", "}" ]
Set the client storage @param \League\OAuth2\Server\Storage\ClientInterface $storage @return self
[ "Set", "the", "client", "storage" ]
54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/AbstractServer.php#L177-L183
20,009
redaigbaria/oauth2
src/AbstractServer.php
AbstractServer.setSessionStorage
public function setSessionStorage(SessionInterface $storage) { $storage->setServer($this); $this->sessionStorage = $storage; return $this; }
php
public function setSessionStorage(SessionInterface $storage) { $storage->setServer($this); $this->sessionStorage = $storage; return $this; }
[ "public", "function", "setSessionStorage", "(", "SessionInterface", "$", "storage", ")", "{", "$", "storage", "->", "setServer", "(", "$", "this", ")", ";", "$", "this", "->", "sessionStorage", "=", "$", "storage", ";", "return", "$", "this", ";", "}" ]
Set the session storage @param \League\OAuth2\Server\Storage\SessionInterface $storage @return self
[ "Set", "the", "session", "storage" ]
54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/AbstractServer.php#L192-L198
20,010
redaigbaria/oauth2
src/AbstractServer.php
AbstractServer.setAccessTokenStorage
public function setAccessTokenStorage(AccessTokenInterface $storage) { $storage->setServer($this); $this->accessTokenStorage = $storage; return $this; }
php
public function setAccessTokenStorage(AccessTokenInterface $storage) { $storage->setServer($this); $this->accessTokenStorage = $storage; return $this; }
[ "public", "function", "setAccessTokenStorage", "(", "AccessTokenInterface", "$", "storage", ")", "{", "$", "storage", "->", "setServer", "(", "$", "this", ")", ";", "$", "this", "->", "accessTokenStorage", "=", "$", "storage", ";", "return", "$", "this", ";", "}" ]
Set the access token storage @param \League\OAuth2\Server\Storage\AccessTokenInterface $storage @return self
[ "Set", "the", "access", "token", "storage" ]
54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/AbstractServer.php#L207-L213
20,011
redaigbaria/oauth2
src/AbstractServer.php
AbstractServer.setRefreshTokenStorage
public function setRefreshTokenStorage(RefreshTokenInterface $storage) { $storage->setServer($this); $this->refreshTokenStorage = $storage; return $this; }
php
public function setRefreshTokenStorage(RefreshTokenInterface $storage) { $storage->setServer($this); $this->refreshTokenStorage = $storage; return $this; }
[ "public", "function", "setRefreshTokenStorage", "(", "RefreshTokenInterface", "$", "storage", ")", "{", "$", "storage", "->", "setServer", "(", "$", "this", ")", ";", "$", "this", "->", "refreshTokenStorage", "=", "$", "storage", ";", "return", "$", "this", ";", "}" ]
Set the refresh token storage @param \League\OAuth2\Server\Storage\RefreshTokenInterface $storage @return self
[ "Set", "the", "refresh", "token", "storage" ]
54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/AbstractServer.php#L222-L228
20,012
redaigbaria/oauth2
src/AbstractServer.php
AbstractServer.setAuthCodeStorage
public function setAuthCodeStorage(AuthCodeInterface $storage) { $storage->setServer($this); $this->authCodeStorage = $storage; return $this; }
php
public function setAuthCodeStorage(AuthCodeInterface $storage) { $storage->setServer($this); $this->authCodeStorage = $storage; return $this; }
[ "public", "function", "setAuthCodeStorage", "(", "AuthCodeInterface", "$", "storage", ")", "{", "$", "storage", "->", "setServer", "(", "$", "this", ")", ";", "$", "this", "->", "authCodeStorage", "=", "$", "storage", ";", "return", "$", "this", ";", "}" ]
Set the auth code storage @param \League\OAuth2\Server\Storage\AuthCodeInterface $storage @return self
[ "Set", "the", "auth", "code", "storage" ]
54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/AbstractServer.php#L237-L243
20,013
redaigbaria/oauth2
src/AbstractServer.php
AbstractServer.setScopeStorage
public function setScopeStorage(ScopeInterface $storage) { $storage->setServer($this); $this->scopeStorage = $storage; return $this; }
php
public function setScopeStorage(ScopeInterface $storage) { $storage->setServer($this); $this->scopeStorage = $storage; return $this; }
[ "public", "function", "setScopeStorage", "(", "ScopeInterface", "$", "storage", ")", "{", "$", "storage", "->", "setServer", "(", "$", "this", ")", ";", "$", "this", "->", "scopeStorage", "=", "$", "storage", ";", "return", "$", "this", ";", "}" ]
Set the scope storage @param \League\OAuth2\Server\Storage\ScopeInterface $storage @return self
[ "Set", "the", "scope", "storage" ]
54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/AbstractServer.php#L252-L258
20,014
yuncms/framework
src/admin/controllers/AdminController.php
AdminController.actionDelete
public function actionDelete($id) { if (Admin::find()->count() == 1) { Yii::$app->getSession()->setFlash('success', Yii::t('yuncms', 'This is the last administrator, delete can not manage the system, it can not be deleted!')); return $this->redirect(['index']); } $this->findModel($id)->delete(); Yii::$app->getSession()->setFlash('success', Yii::t('yuncms', 'Delete success.')); return $this->redirect(['index']); }
php
public function actionDelete($id) { if (Admin::find()->count() == 1) { Yii::$app->getSession()->setFlash('success', Yii::t('yuncms', 'This is the last administrator, delete can not manage the system, it can not be deleted!')); return $this->redirect(['index']); } $this->findModel($id)->delete(); Yii::$app->getSession()->setFlash('success', Yii::t('yuncms', 'Delete success.')); return $this->redirect(['index']); }
[ "public", "function", "actionDelete", "(", "$", "id", ")", "{", "if", "(", "Admin", "::", "find", "(", ")", "->", "count", "(", ")", "==", "1", ")", "{", "Yii", "::", "$", "app", "->", "getSession", "(", ")", "->", "setFlash", "(", "'success'", ",", "Yii", "::", "t", "(", "'yuncms'", ",", "'This is the last administrator, delete can not manage the system, it can not be deleted!'", ")", ")", ";", "return", "$", "this", "->", "redirect", "(", "[", "'index'", "]", ")", ";", "}", "$", "this", "->", "findModel", "(", "$", "id", ")", "->", "delete", "(", ")", ";", "Yii", "::", "$", "app", "->", "getSession", "(", ")", "->", "setFlash", "(", "'success'", ",", "Yii", "::", "t", "(", "'yuncms'", ",", "'Delete success.'", ")", ")", ";", "return", "$", "this", "->", "redirect", "(", "[", "'index'", "]", ")", ";", "}" ]
Deletes an existing Admin model. If deletion is successful, the browser will be redirected to the 'index' page. @param integer $id @return mixed @throws NotFoundHttpException @throws \Exception @throws \Throwable @throws \yii\db\StaleObjectException
[ "Deletes", "an", "existing", "Admin", "model", ".", "If", "deletion", "is", "successful", "the", "browser", "will", "be", "redirected", "to", "the", "index", "page", "." ]
af42e28ea4ae15ab8eead3f6d119f93863b94154
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/admin/controllers/AdminController.php#L102-L111
20,015
okitcom/ok-lib-php
src/Model/Attributes.php
Attributes.init
public static function init(array $attributes) { $obj = new Attributes; foreach ($attributes as $attribute) { $obj->{$attribute->key} = $attribute; } return $obj; }
php
public static function init(array $attributes) { $obj = new Attributes; foreach ($attributes as $attribute) { $obj->{$attribute->key} = $attribute; } return $obj; }
[ "public", "static", "function", "init", "(", "array", "$", "attributes", ")", "{", "$", "obj", "=", "new", "Attributes", ";", "foreach", "(", "$", "attributes", "as", "$", "attribute", ")", "{", "$", "obj", "->", "{", "$", "attribute", "->", "key", "}", "=", "$", "attribute", ";", "}", "return", "$", "obj", ";", "}" ]
Initialize from list of attributes. @param Attribute[] $attributes @return Attributes
[ "Initialize", "from", "list", "of", "attributes", "." ]
1f441f3d216af7c952788e864bfe66bc4f089467
https://github.com/okitcom/ok-lib-php/blob/1f441f3d216af7c952788e864bfe66bc4f089467/src/Model/Attributes.php#L62-L68
20,016
loadsys/CakePHP-CreatorModifier
src/Model/Behavior/CreatorModifierBehavior.php
CreatorModifierBehavior.sessionUserId
protected function sessionUserId() { $userId = null; $request = $this->newRequest(); if ($request->session()->started()) { $userId = $request->session()->read($this->_config['sessionUserIdKey']); } else { $this->log('The Session is not started. This typically means a User is not logged in. In this case there is no Session value for the currently active User and therefore we will set the `creator_id` and `modifier_id` to a null value. As a fallback, we are manually starting the session and reading the `$this->_config[sessionUserIdKey]` value, which is probably not correct.', 'debug'); try { $request->session()->start(); $userId = $request->session()->read($this->_config['sessionUserIdKey']); } catch (RuntimeException $e) { } } return $userId; }
php
protected function sessionUserId() { $userId = null; $request = $this->newRequest(); if ($request->session()->started()) { $userId = $request->session()->read($this->_config['sessionUserIdKey']); } else { $this->log('The Session is not started. This typically means a User is not logged in. In this case there is no Session value for the currently active User and therefore we will set the `creator_id` and `modifier_id` to a null value. As a fallback, we are manually starting the session and reading the `$this->_config[sessionUserIdKey]` value, which is probably not correct.', 'debug'); try { $request->session()->start(); $userId = $request->session()->read($this->_config['sessionUserIdKey']); } catch (RuntimeException $e) { } } return $userId; }
[ "protected", "function", "sessionUserId", "(", ")", "{", "$", "userId", "=", "null", ";", "$", "request", "=", "$", "this", "->", "newRequest", "(", ")", ";", "if", "(", "$", "request", "->", "session", "(", ")", "->", "started", "(", ")", ")", "{", "$", "userId", "=", "$", "request", "->", "session", "(", ")", "->", "read", "(", "$", "this", "->", "_config", "[", "'sessionUserIdKey'", "]", ")", ";", "}", "else", "{", "$", "this", "->", "log", "(", "'The Session is not started. This typically means a User is not logged in. In this case there is no Session value for the currently active User and therefore we will set the `creator_id` and `modifier_id` to a null value. As a fallback, we are manually starting the session and reading the `$this->_config[sessionUserIdKey]` value, which is probably not correct.'", ",", "'debug'", ")", ";", "try", "{", "$", "request", "->", "session", "(", ")", "->", "start", "(", ")", ";", "$", "userId", "=", "$", "request", "->", "session", "(", ")", "->", "read", "(", "$", "this", "->", "_config", "[", "'sessionUserIdKey'", "]", ")", ";", "}", "catch", "(", "RuntimeException", "$", "e", ")", "{", "}", "}", "return", "$", "userId", ";", "}" ]
Return the User.id grabbed from the Session information. @return string The string representing the current logged in user.
[ "Return", "the", "User", ".", "id", "grabbed", "from", "the", "Session", "information", "." ]
42a87eda9413beff82b4eb9cab77d2d5bd5536a0
https://github.com/loadsys/CakePHP-CreatorModifier/blob/42a87eda9413beff82b4eb9cab77d2d5bd5536a0/src/Model/Behavior/CreatorModifierBehavior.php#L169-L185
20,017
nyeholt/silverstripe-external-content
thirdparty/Zend/Feed.php
Zend_Feed.importArray
public static function importArray(array $data, $format = 'atom') { $obj = 'Zend_Feed_' . ucfirst(strtolower($format)); /** * @see Zend_Loader */ require_once 'Zend/Loader.php'; Zend_Loader::loadClass($obj); /** * @see Zend_Feed_Builder */ require_once 'Zend/Feed/Builder.php'; return new $obj(null, null, new Zend_Feed_Builder($data)); }
php
public static function importArray(array $data, $format = 'atom') { $obj = 'Zend_Feed_' . ucfirst(strtolower($format)); /** * @see Zend_Loader */ require_once 'Zend/Loader.php'; Zend_Loader::loadClass($obj); /** * @see Zend_Feed_Builder */ require_once 'Zend/Feed/Builder.php'; return new $obj(null, null, new Zend_Feed_Builder($data)); }
[ "public", "static", "function", "importArray", "(", "array", "$", "data", ",", "$", "format", "=", "'atom'", ")", "{", "$", "obj", "=", "'Zend_Feed_'", ".", "ucfirst", "(", "strtolower", "(", "$", "format", ")", ")", ";", "/**\n * @see Zend_Loader\n */", "require_once", "'Zend/Loader.php'", ";", "Zend_Loader", "::", "loadClass", "(", "$", "obj", ")", ";", "/**\n * @see Zend_Feed_Builder\n */", "require_once", "'Zend/Feed/Builder.php'", ";", "return", "new", "$", "obj", "(", "null", ",", "null", ",", "new", "Zend_Feed_Builder", "(", "$", "data", ")", ")", ";", "}" ]
Construct a new Zend_Feed_Abstract object from a custom array @param array $data @param string $format (rss|atom) the requested output format @return Zend_Feed_Abstract
[ "Construct", "a", "new", "Zend_Feed_Abstract", "object", "from", "a", "custom", "array" ]
1c6da8c56ef717225ff904e1522aff94ed051601
https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Feed.php#L373-L386
20,018
nyeholt/silverstripe-external-content
thirdparty/Zend/Feed.php
Zend_Feed.importBuilder
public static function importBuilder(Zend_Feed_Builder_Interface $builder, $format = 'atom') { $obj = 'Zend_Feed_' . ucfirst(strtolower($format)); /** * @see Zend_Loader */ require_once 'Zend/Loader.php'; Zend_Loader::loadClass($obj); return new $obj(null, null, $builder); }
php
public static function importBuilder(Zend_Feed_Builder_Interface $builder, $format = 'atom') { $obj = 'Zend_Feed_' . ucfirst(strtolower($format)); /** * @see Zend_Loader */ require_once 'Zend/Loader.php'; Zend_Loader::loadClass($obj); return new $obj(null, null, $builder); }
[ "public", "static", "function", "importBuilder", "(", "Zend_Feed_Builder_Interface", "$", "builder", ",", "$", "format", "=", "'atom'", ")", "{", "$", "obj", "=", "'Zend_Feed_'", ".", "ucfirst", "(", "strtolower", "(", "$", "format", ")", ")", ";", "/**\n * @see Zend_Loader\n */", "require_once", "'Zend/Loader.php'", ";", "Zend_Loader", "::", "loadClass", "(", "$", "obj", ")", ";", "return", "new", "$", "obj", "(", "null", ",", "null", ",", "$", "builder", ")", ";", "}" ]
Construct a new Zend_Feed_Abstract object from a Zend_Feed_Builder_Interface data source @param Zend_Feed_Builder_Interface $builder this object will be used to extract the data of the feed @param string $format (rss|atom) the requested output format @return Zend_Feed_Abstract
[ "Construct", "a", "new", "Zend_Feed_Abstract", "object", "from", "a", "Zend_Feed_Builder_Interface", "data", "source" ]
1c6da8c56ef717225ff904e1522aff94ed051601
https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Feed.php#L395-L405
20,019
yuncms/framework
src/web/Controller.php
Controller.asJsonP
public function asJsonP($data): YiiResponse { $response = Yii::$app->getResponse(); $response->data = $data; $response->format = YiiResponse::FORMAT_JSONP; return $response; }
php
public function asJsonP($data): YiiResponse { $response = Yii::$app->getResponse(); $response->data = $data; $response->format = YiiResponse::FORMAT_JSONP; return $response; }
[ "public", "function", "asJsonP", "(", "$", "data", ")", ":", "YiiResponse", "{", "$", "response", "=", "Yii", "::", "$", "app", "->", "getResponse", "(", ")", ";", "$", "response", "->", "data", "=", "$", "data", ";", "$", "response", "->", "format", "=", "YiiResponse", "::", "FORMAT_JSONP", ";", "return", "$", "response", ";", "}" ]
Sets the response format of the given data as JSONP. @param mixed $data The data that should be formatted. @return Response A response that is configured to send `$data` formatted as JSON. @see YiiResponse::$format @see YiiResponse::FORMAT_JSONP @see JsonResponseFormatter
[ "Sets", "the", "response", "format", "of", "the", "given", "data", "as", "JSONP", "." ]
af42e28ea4ae15ab8eead3f6d119f93863b94154
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/web/Controller.php#L33-L39
20,020
yuncms/framework
src/web/Controller.php
Controller.asRaw
public function asRaw($data): YiiResponse { $response = Yii::$app->getResponse(); $response->data = $data; $response->format = YiiResponse::FORMAT_RAW; return $response; }
php
public function asRaw($data): YiiResponse { $response = Yii::$app->getResponse(); $response->data = $data; $response->format = YiiResponse::FORMAT_RAW; return $response; }
[ "public", "function", "asRaw", "(", "$", "data", ")", ":", "YiiResponse", "{", "$", "response", "=", "Yii", "::", "$", "app", "->", "getResponse", "(", ")", ";", "$", "response", "->", "data", "=", "$", "data", ";", "$", "response", "->", "format", "=", "YiiResponse", "::", "FORMAT_RAW", ";", "return", "$", "response", ";", "}" ]
Sets the response format of the given data as RAW. @param mixed $data The data that should *not* be formatted. @return YiiResponse A response that is configured to send `$data` without formatting. @see YiiResponse::$format @see YiiResponse::FORMAT_RAW
[ "Sets", "the", "response", "format", "of", "the", "given", "data", "as", "RAW", "." ]
af42e28ea4ae15ab8eead3f6d119f93863b94154
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/web/Controller.php#L49-L55
20,021
magnus-eriksson/entity
src/Entity.php
Entity.setParam
protected function setParam($key, $value) { if (!array_key_exists($key, $this->_params)) { if ($this->_ignoreExisting || $this->arrayGet($this->_setup, 'suppress_errors') === true) { return; } throw new UnknownPropertyException("Unknown property: '{$key}'"); } switch ($this->_types[$key]) { case "boolean": $this->_params[$key] = (bool)$value; break; case "integer": $this->_params[$key] = (integer)$value; break; case "float": $this->_params[$key] = (float)$value; break; case "string": $this->_params[$key] = (string)$value; break; case "array": $this->_params[$key] = (array)$value; break; default: $this->_params[$key] = $value; break; } }
php
protected function setParam($key, $value) { if (!array_key_exists($key, $this->_params)) { if ($this->_ignoreExisting || $this->arrayGet($this->_setup, 'suppress_errors') === true) { return; } throw new UnknownPropertyException("Unknown property: '{$key}'"); } switch ($this->_types[$key]) { case "boolean": $this->_params[$key] = (bool)$value; break; case "integer": $this->_params[$key] = (integer)$value; break; case "float": $this->_params[$key] = (float)$value; break; case "string": $this->_params[$key] = (string)$value; break; case "array": $this->_params[$key] = (array)$value; break; default: $this->_params[$key] = $value; break; } }
[ "protected", "function", "setParam", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "_params", ")", ")", "{", "if", "(", "$", "this", "->", "_ignoreExisting", "||", "$", "this", "->", "arrayGet", "(", "$", "this", "->", "_setup", ",", "'suppress_errors'", ")", "===", "true", ")", "{", "return", ";", "}", "throw", "new", "UnknownPropertyException", "(", "\"Unknown property: '{$key}'\"", ")", ";", "}", "switch", "(", "$", "this", "->", "_types", "[", "$", "key", "]", ")", "{", "case", "\"boolean\"", ":", "$", "this", "->", "_params", "[", "$", "key", "]", "=", "(", "bool", ")", "$", "value", ";", "break", ";", "case", "\"integer\"", ":", "$", "this", "->", "_params", "[", "$", "key", "]", "=", "(", "integer", ")", "$", "value", ";", "break", ";", "case", "\"float\"", ":", "$", "this", "->", "_params", "[", "$", "key", "]", "=", "(", "float", ")", "$", "value", ";", "break", ";", "case", "\"string\"", ":", "$", "this", "->", "_params", "[", "$", "key", "]", "=", "(", "string", ")", "$", "value", ";", "break", ";", "case", "\"array\"", ":", "$", "this", "->", "_params", "[", "$", "key", "]", "=", "(", "array", ")", "$", "value", ";", "break", ";", "default", ":", "$", "this", "->", "_params", "[", "$", "key", "]", "=", "$", "value", ";", "break", ";", "}", "}" ]
Set a value in the parameter pool and cast it to the same type as the default value @param string $key @param mixed $value @throws UnknownPropertyException
[ "Set", "a", "value", "in", "the", "parameter", "pool", "and", "cast", "it", "to", "the", "same", "type", "as", "the", "default", "value" ]
e6b1df5bd7b65c0c2513895afa533d441fc6d43b
https://github.com/magnus-eriksson/entity/blob/e6b1df5bd7b65c0c2513895afa533d441fc6d43b/src/Entity.php#L159-L189
20,022
magnus-eriksson/entity
src/Entity.php
Entity.setDefaultDataTypes
protected function setDefaultDataTypes() { foreach ($this->_params as $key => $value) { switch (gettype($value)) { case "boolean": $this->_types[$key] = 'boolean'; break; case "integer": $this->_types[$key] = 'integer'; break; case "double": $this->_types[$key] = 'float'; break; case "string": $this->_types[$key] = 'string'; break; case "array": $this->_types[$key] = 'array'; break; default: $this->_types[$key] = null; break; } } }
php
protected function setDefaultDataTypes() { foreach ($this->_params as $key => $value) { switch (gettype($value)) { case "boolean": $this->_types[$key] = 'boolean'; break; case "integer": $this->_types[$key] = 'integer'; break; case "double": $this->_types[$key] = 'float'; break; case "string": $this->_types[$key] = 'string'; break; case "array": $this->_types[$key] = 'array'; break; default: $this->_types[$key] = null; break; } } }
[ "protected", "function", "setDefaultDataTypes", "(", ")", "{", "foreach", "(", "$", "this", "->", "_params", "as", "$", "key", "=>", "$", "value", ")", "{", "switch", "(", "gettype", "(", "$", "value", ")", ")", "{", "case", "\"boolean\"", ":", "$", "this", "->", "_types", "[", "$", "key", "]", "=", "'boolean'", ";", "break", ";", "case", "\"integer\"", ":", "$", "this", "->", "_types", "[", "$", "key", "]", "=", "'integer'", ";", "break", ";", "case", "\"double\"", ":", "$", "this", "->", "_types", "[", "$", "key", "]", "=", "'float'", ";", "break", ";", "case", "\"string\"", ":", "$", "this", "->", "_types", "[", "$", "key", "]", "=", "'string'", ";", "break", ";", "case", "\"array\"", ":", "$", "this", "->", "_types", "[", "$", "key", "]", "=", "'array'", ";", "break", ";", "default", ":", "$", "this", "->", "_types", "[", "$", "key", "]", "=", "null", ";", "break", ";", "}", "}", "}" ]
Get the default data types
[ "Get", "the", "default", "data", "types" ]
e6b1df5bd7b65c0c2513895afa533d441fc6d43b
https://github.com/magnus-eriksson/entity/blob/e6b1df5bd7b65c0c2513895afa533d441fc6d43b/src/Entity.php#L195-L219
20,023
magnus-eriksson/entity
src/Entity.php
Entity.toArray
public function toArray($protect = null) { $protect = is_array($protect) ? $protect : $this->_protect; if ($protect) { $new = $this->_params; foreach ($protect as $key) { unset($new[$key]); } // Do json encode and decode to convert all levels to arrays return json_decode(json_encode($new), true, 512); } // Do json encode and decode to convert all levels to arrays return json_decode(json_encode($this->_params), true, 512); }
php
public function toArray($protect = null) { $protect = is_array($protect) ? $protect : $this->_protect; if ($protect) { $new = $this->_params; foreach ($protect as $key) { unset($new[$key]); } // Do json encode and decode to convert all levels to arrays return json_decode(json_encode($new), true, 512); } // Do json encode and decode to convert all levels to arrays return json_decode(json_encode($this->_params), true, 512); }
[ "public", "function", "toArray", "(", "$", "protect", "=", "null", ")", "{", "$", "protect", "=", "is_array", "(", "$", "protect", ")", "?", "$", "protect", ":", "$", "this", "->", "_protect", ";", "if", "(", "$", "protect", ")", "{", "$", "new", "=", "$", "this", "->", "_params", ";", "foreach", "(", "$", "protect", "as", "$", "key", ")", "{", "unset", "(", "$", "new", "[", "$", "key", "]", ")", ";", "}", "// Do json encode and decode to convert all levels to arrays", "return", "json_decode", "(", "json_encode", "(", "$", "new", ")", ",", "true", ",", "512", ")", ";", "}", "// Do json encode and decode to convert all levels to arrays", "return", "json_decode", "(", "json_encode", "(", "$", "this", "->", "_params", ")", ",", "true", ",", "512", ")", ";", "}" ]
Return the params as array and remove the protected keys @param array|null $protect @return array
[ "Return", "the", "params", "as", "array", "and", "remove", "the", "protected", "keys" ]
e6b1df5bd7b65c0c2513895afa533d441fc6d43b
https://github.com/magnus-eriksson/entity/blob/e6b1df5bd7b65c0c2513895afa533d441fc6d43b/src/Entity.php#L258-L278
20,024
magnus-eriksson/entity
src/Entity.php
Entity.date
public function date($key, $format = "F j, Y") { if (is_numeric($this->_params[$key])) { return date($format, $this->_params[$key]); } return date($format, strtotime($this->_params[$key])); }
php
public function date($key, $format = "F j, Y") { if (is_numeric($this->_params[$key])) { return date($format, $this->_params[$key]); } return date($format, strtotime($this->_params[$key])); }
[ "public", "function", "date", "(", "$", "key", ",", "$", "format", "=", "\"F j, Y\"", ")", "{", "if", "(", "is_numeric", "(", "$", "this", "->", "_params", "[", "$", "key", "]", ")", ")", "{", "return", "date", "(", "$", "format", ",", "$", "this", "->", "_params", "[", "$", "key", "]", ")", ";", "}", "return", "date", "(", "$", "format", ",", "strtotime", "(", "$", "this", "->", "_params", "[", "$", "key", "]", ")", ")", ";", "}" ]
Return a parameter as a formatted date string @param string $key @param string $format @return string
[ "Return", "a", "parameter", "as", "a", "formatted", "date", "string" ]
e6b1df5bd7b65c0c2513895afa533d441fc6d43b
https://github.com/magnus-eriksson/entity/blob/e6b1df5bd7b65c0c2513895afa533d441fc6d43b/src/Entity.php#L300-L307
20,025
magnus-eriksson/entity
src/Entity.php
Entity.make
public static function make($data = null, $index = null, Closure $modifier = null) { if ($data instanceof Traversable) { $data = iterator_to_array($data); } if (!is_array($data)) { return null; } if (count($data) < 1) { return []; } // Check if it is a multi dimensional array $values = array_values($data); $multi = array_key_exists(0, $values) && is_array($values[0]); if ($multi) { $list = []; foreach ($data as $item) { if ($index && array_key_exists($index, $item)) { $key = $item[$index]; $list[$key] = static::populate($item, $modifier); continue; } $list[] = static::populate($item, $modifier); } return $list; } return static::populate($data, $modifier); }
php
public static function make($data = null, $index = null, Closure $modifier = null) { if ($data instanceof Traversable) { $data = iterator_to_array($data); } if (!is_array($data)) { return null; } if (count($data) < 1) { return []; } // Check if it is a multi dimensional array $values = array_values($data); $multi = array_key_exists(0, $values) && is_array($values[0]); if ($multi) { $list = []; foreach ($data as $item) { if ($index && array_key_exists($index, $item)) { $key = $item[$index]; $list[$key] = static::populate($item, $modifier); continue; } $list[] = static::populate($item, $modifier); } return $list; } return static::populate($data, $modifier); }
[ "public", "static", "function", "make", "(", "$", "data", "=", "null", ",", "$", "index", "=", "null", ",", "Closure", "$", "modifier", "=", "null", ")", "{", "if", "(", "$", "data", "instanceof", "Traversable", ")", "{", "$", "data", "=", "iterator_to_array", "(", "$", "data", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "data", ")", ")", "{", "return", "null", ";", "}", "if", "(", "count", "(", "$", "data", ")", "<", "1", ")", "{", "return", "[", "]", ";", "}", "// Check if it is a multi dimensional array", "$", "values", "=", "array_values", "(", "$", "data", ")", ";", "$", "multi", "=", "array_key_exists", "(", "0", ",", "$", "values", ")", "&&", "is_array", "(", "$", "values", "[", "0", "]", ")", ";", "if", "(", "$", "multi", ")", "{", "$", "list", "=", "[", "]", ";", "foreach", "(", "$", "data", "as", "$", "item", ")", "{", "if", "(", "$", "index", "&&", "array_key_exists", "(", "$", "index", ",", "$", "item", ")", ")", "{", "$", "key", "=", "$", "item", "[", "$", "index", "]", ";", "$", "list", "[", "$", "key", "]", "=", "static", "::", "populate", "(", "$", "item", ",", "$", "modifier", ")", ";", "continue", ";", "}", "$", "list", "[", "]", "=", "static", "::", "populate", "(", "$", "item", ",", "$", "modifier", ")", ";", "}", "return", "$", "list", ";", "}", "return", "static", "::", "populate", "(", "$", "data", ",", "$", "modifier", ")", ";", "}" ]
Convert array to entities @param array $data @param string $index Set the value in this key as index @param Closure $modifier Executed before the entity gets populated @return Entity|array
[ "Convert", "array", "to", "entities" ]
e6b1df5bd7b65c0c2513895afa533d441fc6d43b
https://github.com/magnus-eriksson/entity/blob/e6b1df5bd7b65c0c2513895afa533d441fc6d43b/src/Entity.php#L332-L366
20,026
magnus-eriksson/entity
src/Entity.php
Entity.arrayGet
protected function arrayGet(&$source, $key, $default = null) { if (!$key) { return $default; } if (array_key_exists($key, $source)) { return $source[$key]; } $current =& $source; foreach (explode('.', $key) as $segment) { if (!array_key_exists($segment, $current)) { return $default; } $current =& $current[$segment]; } return $current; }
php
protected function arrayGet(&$source, $key, $default = null) { if (!$key) { return $default; } if (array_key_exists($key, $source)) { return $source[$key]; } $current =& $source; foreach (explode('.', $key) as $segment) { if (!array_key_exists($segment, $current)) { return $default; } $current =& $current[$segment]; } return $current; }
[ "protected", "function", "arrayGet", "(", "&", "$", "source", ",", "$", "key", ",", "$", "default", "=", "null", ")", "{", "if", "(", "!", "$", "key", ")", "{", "return", "$", "default", ";", "}", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "source", ")", ")", "{", "return", "$", "source", "[", "$", "key", "]", ";", "}", "$", "current", "=", "&", "$", "source", ";", "foreach", "(", "explode", "(", "'.'", ",", "$", "key", ")", "as", "$", "segment", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "segment", ",", "$", "current", ")", ")", "{", "return", "$", "default", ";", "}", "$", "current", "=", "&", "$", "current", "[", "$", "segment", "]", ";", "}", "return", "$", "current", ";", "}" ]
Get a key value, using dot notation @param array &$source @param string $key @param mixed $default @return mixed
[ "Get", "a", "key", "value", "using", "dot", "notation" ]
e6b1df5bd7b65c0c2513895afa533d441fc6d43b
https://github.com/magnus-eriksson/entity/blob/e6b1df5bd7b65c0c2513895afa533d441fc6d43b/src/Entity.php#L392-L411
20,027
magnus-eriksson/entity
src/Entity.php
Entity.arrayHasKey
protected function arrayHasKey(&$source, $key) { if (!$key || !is_array($source)) { return false; } if (array_key_exists($key, $source)) { return true; } $current =& $source; foreach (explode('.', $key) as $segment) { if (!array_key_exists($segment, $current)) { return false; } $current =& $current[$segment]; } return true; }
php
protected function arrayHasKey(&$source, $key) { if (!$key || !is_array($source)) { return false; } if (array_key_exists($key, $source)) { return true; } $current =& $source; foreach (explode('.', $key) as $segment) { if (!array_key_exists($segment, $current)) { return false; } $current =& $current[$segment]; } return true; }
[ "protected", "function", "arrayHasKey", "(", "&", "$", "source", ",", "$", "key", ")", "{", "if", "(", "!", "$", "key", "||", "!", "is_array", "(", "$", "source", ")", ")", "{", "return", "false", ";", "}", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "source", ")", ")", "{", "return", "true", ";", "}", "$", "current", "=", "&", "$", "source", ";", "foreach", "(", "explode", "(", "'.'", ",", "$", "key", ")", "as", "$", "segment", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "segment", ",", "$", "current", ")", ")", "{", "return", "false", ";", "}", "$", "current", "=", "&", "$", "current", "[", "$", "segment", "]", ";", "}", "return", "true", ";", "}" ]
Check if a key exists, using dot notation @param array &$source @param string $key @return boolean
[ "Check", "if", "a", "key", "exists", "using", "dot", "notation" ]
e6b1df5bd7b65c0c2513895afa533d441fc6d43b
https://github.com/magnus-eriksson/entity/blob/e6b1df5bd7b65c0c2513895afa533d441fc6d43b/src/Entity.php#L422-L441
20,028
haldayne/boost
src/MapOfStrings.php
MapOfStrings.join
public function join($separator) { return $this->reduce( function ($joined, $string) use ($separator) { return ('' === $joined ? '' : $joined . $separator) . $string; }, '' ); }
php
public function join($separator) { return $this->reduce( function ($joined, $string) use ($separator) { return ('' === $joined ? '' : $joined . $separator) . $string; }, '' ); }
[ "public", "function", "join", "(", "$", "separator", ")", "{", "return", "$", "this", "->", "reduce", "(", "function", "(", "$", "joined", ",", "$", "string", ")", "use", "(", "$", "separator", ")", "{", "return", "(", "''", "===", "$", "joined", "?", "''", ":", "$", "joined", ".", "$", "separator", ")", ".", "$", "string", ";", "}", ",", "''", ")", ";", "}" ]
Join all the strings in this map with the separator between them. @param string $separator @return string @api
[ "Join", "all", "the", "strings", "in", "this", "map", "with", "the", "separator", "between", "them", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/MapOfStrings.php#L17-L25
20,029
haldayne/boost
src/MapOfStrings.php
MapOfStrings.letter_frequency
public function letter_frequency() { return $this->transform( function ($frequencies, $word) { foreach (count_chars($word, 1) as $byte => $frequency) { $letter = chr($byte); if ($frequencies->has($letter)) { $frequencies->set($letter, $frequencies->get($letter)+1); } else { $frequencies->set($letter, 1); } } }, function (Map $original) { return new MapOfInts(); } ); }
php
public function letter_frequency() { return $this->transform( function ($frequencies, $word) { foreach (count_chars($word, 1) as $byte => $frequency) { $letter = chr($byte); if ($frequencies->has($letter)) { $frequencies->set($letter, $frequencies->get($letter)+1); } else { $frequencies->set($letter, 1); } } }, function (Map $original) { return new MapOfInts(); } ); }
[ "public", "function", "letter_frequency", "(", ")", "{", "return", "$", "this", "->", "transform", "(", "function", "(", "$", "frequencies", ",", "$", "word", ")", "{", "foreach", "(", "count_chars", "(", "$", "word", ",", "1", ")", "as", "$", "byte", "=>", "$", "frequency", ")", "{", "$", "letter", "=", "chr", "(", "$", "byte", ")", ";", "if", "(", "$", "frequencies", "->", "has", "(", "$", "letter", ")", ")", "{", "$", "frequencies", "->", "set", "(", "$", "letter", ",", "$", "frequencies", "->", "get", "(", "$", "letter", ")", "+", "1", ")", ";", "}", "else", "{", "$", "frequencies", "->", "set", "(", "$", "letter", ",", "1", ")", ";", "}", "}", "}", ",", "function", "(", "Map", "$", "original", ")", "{", "return", "new", "MapOfInts", "(", ")", ";", "}", ")", ";", "}" ]
Calculate frequency of letters in all strings. Counts how many times each letter occurs within every string in this map. Returns a new Map of letter to number of occurrences. Only letters that appear will be in the resulting map. @return \Haldayne\Boost\MapOfIntegers @api
[ "Calculate", "frequency", "of", "letters", "in", "all", "strings", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/MapOfStrings.php#L37-L52
20,030
AymDev/PPRR
src/PPRR.php
PPRR.buildRegex
private static function buildRegex(string $expression, bool $is_prefix = false) : string { $regex = self::REGEX_DELIMITER . '^'; $regex .= preg_replace(array_keys(self::$datatypes), self::$datatypes, $expression); $regex .= $is_prefix ? '(.*)' : ''; $regex .= '$' . self::REGEX_DELIMITER; return $regex; }
php
private static function buildRegex(string $expression, bool $is_prefix = false) : string { $regex = self::REGEX_DELIMITER . '^'; $regex .= preg_replace(array_keys(self::$datatypes), self::$datatypes, $expression); $regex .= $is_prefix ? '(.*)' : ''; $regex .= '$' . self::REGEX_DELIMITER; return $regex; }
[ "private", "static", "function", "buildRegex", "(", "string", "$", "expression", ",", "bool", "$", "is_prefix", "=", "false", ")", ":", "string", "{", "$", "regex", "=", "self", "::", "REGEX_DELIMITER", ".", "'^'", ";", "$", "regex", ".=", "preg_replace", "(", "array_keys", "(", "self", "::", "$", "datatypes", ")", ",", "self", "::", "$", "datatypes", ",", "$", "expression", ")", ";", "$", "regex", ".=", "$", "is_prefix", "?", "'(.*)'", ":", "''", ";", "$", "regex", ".=", "'$'", ".", "self", "::", "REGEX_DELIMITER", ";", "return", "$", "regex", ";", "}" ]
Build a complete regular expression @param string $expression the route to evaluate @param bool $is_prefix is the route a route prefix @return string the complete regular expression
[ "Build", "a", "complete", "regular", "expression" ]
f14fc0a79c68a7f90891aa4a74986bdac1f59335
https://github.com/AymDev/PPRR/blob/f14fc0a79c68a7f90891aa4a74986bdac1f59335/src/PPRR.php#L63-L70
20,031
AymDev/PPRR
src/PPRR.php
PPRR.getParsingMode
private function getParsingMode(string &$route) : int { // Explicit regex mode if (strpos($route, 'R>') === 0) { $route = str_replace('R>', '', $route); return self::MODE_REGEX; } // Explicit string mode if (strpos($route, 'S>') === 0) { $route = str_replace('S>', '', $route); return self::MODE_STRING; } // Use default mode return self::$mode; }
php
private function getParsingMode(string &$route) : int { // Explicit regex mode if (strpos($route, 'R>') === 0) { $route = str_replace('R>', '', $route); return self::MODE_REGEX; } // Explicit string mode if (strpos($route, 'S>') === 0) { $route = str_replace('S>', '', $route); return self::MODE_STRING; } // Use default mode return self::$mode; }
[ "private", "function", "getParsingMode", "(", "string", "&", "$", "route", ")", ":", "int", "{", "// Explicit regex mode", "if", "(", "strpos", "(", "$", "route", ",", "'R>'", ")", "===", "0", ")", "{", "$", "route", "=", "str_replace", "(", "'R>'", ",", "''", ",", "$", "route", ")", ";", "return", "self", "::", "MODE_REGEX", ";", "}", "// Explicit string mode", "if", "(", "strpos", "(", "$", "route", ",", "'S>'", ")", "===", "0", ")", "{", "$", "route", "=", "str_replace", "(", "'S>'", ",", "''", ",", "$", "route", ")", ";", "return", "self", "::", "MODE_STRING", ";", "}", "// Use default mode", "return", "self", "::", "$", "mode", ";", "}" ]
Detect route parsing mode for specific route @param string &$route route to check @return int class constant mode
[ "Detect", "route", "parsing", "mode", "for", "specific", "route" ]
f14fc0a79c68a7f90891aa4a74986bdac1f59335
https://github.com/AymDev/PPRR/blob/f14fc0a79c68a7f90891aa4a74986bdac1f59335/src/PPRR.php#L83-L98
20,032
AymDev/PPRR
src/PPRR.php
PPRR.matchRoute
private function matchRoute(string $route, string $url, &$matches, $value = null) { switch ($this->getParsingMode($route)) { case self::MODE_REGEX: // Evaluate & remove first match (full route) $matched = preg_match(self::buildRegex($route, !is_null($value)), $url, $matches); array_shift($matches); break; case self::MODE_STRING: // final route if (is_null($value)) { $matched = $route === $url; $matches = []; // route prefix } else { $matched = empty($route) ? empty($url) : strpos($url, $route) === 0; $matches = [str_replace($route, '', $url)]; } break; } // Route matches if (is_null($value)) { return $matched; } // value is sub-routes array $sub_routes = !is_callable($value) && is_array($value); return $matched && $sub_routes; }
php
private function matchRoute(string $route, string $url, &$matches, $value = null) { switch ($this->getParsingMode($route)) { case self::MODE_REGEX: // Evaluate & remove first match (full route) $matched = preg_match(self::buildRegex($route, !is_null($value)), $url, $matches); array_shift($matches); break; case self::MODE_STRING: // final route if (is_null($value)) { $matched = $route === $url; $matches = []; // route prefix } else { $matched = empty($route) ? empty($url) : strpos($url, $route) === 0; $matches = [str_replace($route, '', $url)]; } break; } // Route matches if (is_null($value)) { return $matched; } // value is sub-routes array $sub_routes = !is_callable($value) && is_array($value); return $matched && $sub_routes; }
[ "private", "function", "matchRoute", "(", "string", "$", "route", ",", "string", "$", "url", ",", "&", "$", "matches", ",", "$", "value", "=", "null", ")", "{", "switch", "(", "$", "this", "->", "getParsingMode", "(", "$", "route", ")", ")", "{", "case", "self", "::", "MODE_REGEX", ":", "// Evaluate & remove first match (full route)", "$", "matched", "=", "preg_match", "(", "self", "::", "buildRegex", "(", "$", "route", ",", "!", "is_null", "(", "$", "value", ")", ")", ",", "$", "url", ",", "$", "matches", ")", ";", "array_shift", "(", "$", "matches", ")", ";", "break", ";", "case", "self", "::", "MODE_STRING", ":", "// final route", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "$", "matched", "=", "$", "route", "===", "$", "url", ";", "$", "matches", "=", "[", "]", ";", "// route prefix", "}", "else", "{", "$", "matched", "=", "empty", "(", "$", "route", ")", "?", "empty", "(", "$", "url", ")", ":", "strpos", "(", "$", "url", ",", "$", "route", ")", "===", "0", ";", "$", "matches", "=", "[", "str_replace", "(", "$", "route", ",", "''", ",", "$", "url", ")", "]", ";", "}", "break", ";", "}", "// Route matches", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "return", "$", "matched", ";", "}", "// value is sub-routes array", "$", "sub_routes", "=", "!", "is_callable", "(", "$", "value", ")", "&&", "is_array", "(", "$", "value", ")", ";", "return", "$", "matched", "&&", "$", "sub_routes", ";", "}" ]
Match url against route @param string $route route to match against @param string $url url to test @param mixed &$matches variable to fill with matches @param mixed $value route value (sub routes or callback)
[ "Match", "url", "against", "route" ]
f14fc0a79c68a7f90891aa4a74986bdac1f59335
https://github.com/AymDev/PPRR/blob/f14fc0a79c68a7f90891aa4a74986bdac1f59335/src/PPRR.php#L111-L142
20,033
AymDev/PPRR
src/PPRR.php
PPRR.route
private function route() : void { // Parse route $parsed = $this->parseRoute(); // Run error controller when no route matched if (!$parsed && isset($this->error_controller)) { call_user_func($this->error_controller); } }
php
private function route() : void { // Parse route $parsed = $this->parseRoute(); // Run error controller when no route matched if (!$parsed && isset($this->error_controller)) { call_user_func($this->error_controller); } }
[ "private", "function", "route", "(", ")", ":", "void", "{", "// Parse route", "$", "parsed", "=", "$", "this", "->", "parseRoute", "(", ")", ";", "// Run error controller when no route matched", "if", "(", "!", "$", "parsed", "&&", "isset", "(", "$", "this", "->", "error_controller", ")", ")", "{", "call_user_func", "(", "$", "this", "->", "error_controller", ")", ";", "}", "}" ]
Try to parse routes or call the error controller @return void
[ "Try", "to", "parse", "routes", "or", "call", "the", "error", "controller" ]
f14fc0a79c68a7f90891aa4a74986bdac1f59335
https://github.com/AymDev/PPRR/blob/f14fc0a79c68a7f90891aa4a74986bdac1f59335/src/PPRR.php#L153-L162
20,034
AymDev/PPRR
src/PPRR.php
PPRR.setDefaultMode
public static function setDefaultMode(int $mode) : void { if (in_array($mode, [self::MODE_REGEX, self::MODE_STRING])) { self::$mode = $mode; return; } // Unknown mode throw new \UnexpectedValueException('Invalid route mode'); }
php
public static function setDefaultMode(int $mode) : void { if (in_array($mode, [self::MODE_REGEX, self::MODE_STRING])) { self::$mode = $mode; return; } // Unknown mode throw new \UnexpectedValueException('Invalid route mode'); }
[ "public", "static", "function", "setDefaultMode", "(", "int", "$", "mode", ")", ":", "void", "{", "if", "(", "in_array", "(", "$", "mode", ",", "[", "self", "::", "MODE_REGEX", ",", "self", "::", "MODE_STRING", "]", ")", ")", "{", "self", "::", "$", "mode", "=", "$", "mode", ";", "return", ";", "}", "// Unknown mode", "throw", "new", "\\", "UnexpectedValueException", "(", "'Invalid route mode'", ")", ";", "}" ]
Set the route parsing mode @param int $mode a class MODE_* constant @return void @throws \UnexpectedValueException for unknown modes
[ "Set", "the", "route", "parsing", "mode" ]
f14fc0a79c68a7f90891aa4a74986bdac1f59335
https://github.com/AymDev/PPRR/blob/f14fc0a79c68a7f90891aa4a74986bdac1f59335/src/PPRR.php#L262-L271
20,035
cohesion/cohesion-core
src/Util/Autoloader.php
Autoloader.addClassPath
public function addClassPath($path) { if(!is_array($path)) { $path = array($path); } foreach($path as $item) { $this->classPaths[] = $item; } }
php
public function addClassPath($path) { if(!is_array($path)) { $path = array($path); } foreach($path as $item) { $this->classPaths[] = $item; } }
[ "public", "function", "addClassPath", "(", "$", "path", ")", "{", "if", "(", "!", "is_array", "(", "$", "path", ")", ")", "{", "$", "path", "=", "array", "(", "$", "path", ")", ";", "}", "foreach", "(", "$", "path", "as", "$", "item", ")", "{", "$", "this", "->", "classPaths", "[", "]", "=", "$", "item", ";", "}", "}" ]
Adds a path to search in when looking for a class. @param string $path @return void
[ "Adds", "a", "path", "to", "search", "in", "when", "looking", "for", "a", "class", "." ]
c6352aef7336e06285f0943da68235dc45523998
https://github.com/cohesion/cohesion-core/blob/c6352aef7336e06285f0943da68235dc45523998/src/Util/Autoloader.php#L96-L103
20,036
cohesion/cohesion-core
src/Util/Autoloader.php
Autoloader.loadClass
public function loadClass($className) { $cache = $this->getCache(); $entries = $cache->load($this->cacheKey); if($entries == false) { $entries = array(); } $status = $this->tryAndLoadClass($className, $entries); if($status) { // class loaded return true; } if(preg_match($this->ignoreClassNamesRegexp, $className)) { return false; } foreach($this->classPaths as $path) { // Scan for file $realPath = $this->searchForClassFile($className, $path); if($realPath !== false) { $entries[$className] = $realPath; break; } } $cache->save($entries, $this->cacheKey); $status = $this->tryAndLoadClass($className, $entries); return $status; }
php
public function loadClass($className) { $cache = $this->getCache(); $entries = $cache->load($this->cacheKey); if($entries == false) { $entries = array(); } $status = $this->tryAndLoadClass($className, $entries); if($status) { // class loaded return true; } if(preg_match($this->ignoreClassNamesRegexp, $className)) { return false; } foreach($this->classPaths as $path) { // Scan for file $realPath = $this->searchForClassFile($className, $path); if($realPath !== false) { $entries[$className] = $realPath; break; } } $cache->save($entries, $this->cacheKey); $status = $this->tryAndLoadClass($className, $entries); return $status; }
[ "public", "function", "loadClass", "(", "$", "className", ")", "{", "$", "cache", "=", "$", "this", "->", "getCache", "(", ")", ";", "$", "entries", "=", "$", "cache", "->", "load", "(", "$", "this", "->", "cacheKey", ")", ";", "if", "(", "$", "entries", "==", "false", ")", "{", "$", "entries", "=", "array", "(", ")", ";", "}", "$", "status", "=", "$", "this", "->", "tryAndLoadClass", "(", "$", "className", ",", "$", "entries", ")", ";", "if", "(", "$", "status", ")", "{", "// class loaded", "return", "true", ";", "}", "if", "(", "preg_match", "(", "$", "this", "->", "ignoreClassNamesRegexp", ",", "$", "className", ")", ")", "{", "return", "false", ";", "}", "foreach", "(", "$", "this", "->", "classPaths", "as", "$", "path", ")", "{", "// Scan for file", "$", "realPath", "=", "$", "this", "->", "searchForClassFile", "(", "$", "className", ",", "$", "path", ")", ";", "if", "(", "$", "realPath", "!==", "false", ")", "{", "$", "entries", "[", "$", "className", "]", "=", "$", "realPath", ";", "break", ";", "}", "}", "$", "cache", "->", "save", "(", "$", "entries", ",", "$", "this", "->", "cacheKey", ")", ";", "$", "status", "=", "$", "this", "->", "tryAndLoadClass", "(", "$", "className", ",", "$", "entries", ")", ";", "return", "$", "status", ";", "}" ]
Returns true if the class file was found and included, false if not. @return boolean
[ "Returns", "true", "if", "the", "class", "file", "was", "found", "and", "included", "false", "if", "not", "." ]
c6352aef7336e06285f0943da68235dc45523998
https://github.com/cohesion/cohesion-core/blob/c6352aef7336e06285f0943da68235dc45523998/src/Util/Autoloader.php#L179-L205
20,037
titon/db
src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php
AbstractPdoDialect.buildCreateIndex
public function buildCreateIndex(Query $query) { return $this->renderStatement(Query::CREATE_INDEX, [ 'index' => $this->formatTable($query->getAlias()), 'table' => $this->formatTable($query->getTable()), 'fields' => $this->formatFields($query) ] + $this->formatAttributes($query->getAttributes())); }
php
public function buildCreateIndex(Query $query) { return $this->renderStatement(Query::CREATE_INDEX, [ 'index' => $this->formatTable($query->getAlias()), 'table' => $this->formatTable($query->getTable()), 'fields' => $this->formatFields($query) ] + $this->formatAttributes($query->getAttributes())); }
[ "public", "function", "buildCreateIndex", "(", "Query", "$", "query", ")", "{", "return", "$", "this", "->", "renderStatement", "(", "Query", "::", "CREATE_INDEX", ",", "[", "'index'", "=>", "$", "this", "->", "formatTable", "(", "$", "query", "->", "getAlias", "(", ")", ")", ",", "'table'", "=>", "$", "this", "->", "formatTable", "(", "$", "query", "->", "getTable", "(", ")", ")", ",", "'fields'", "=>", "$", "this", "->", "formatFields", "(", "$", "query", ")", "]", "+", "$", "this", "->", "formatAttributes", "(", "$", "query", "->", "getAttributes", "(", ")", ")", ")", ";", "}" ]
Build the CREATE INDEX query. @param \Titon\Db\Query $query @return string
[ "Build", "the", "CREATE", "INDEX", "query", "." ]
fbc5159d1ce9d2139759c9367565986981485604
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php#L26-L32
20,038
titon/db
src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php
AbstractPdoDialect.buildCreateTable
public function buildCreateTable(Query $query) { $schema = $query->getSchema(); if (!$schema) { throw new InvalidSchemaException('Table creation requires a valid schema object'); } return $this->renderStatement(Query::CREATE_TABLE, [ 'table' => $this->formatTable($schema->getTable()), 'columns' => $this->formatColumns($schema), 'keys' => $this->formatTableKeys($schema), 'options' => $this->formatTableOptions($schema->getOptions()) ] + $this->formatAttributes($query->getAttributes())); }
php
public function buildCreateTable(Query $query) { $schema = $query->getSchema(); if (!$schema) { throw new InvalidSchemaException('Table creation requires a valid schema object'); } return $this->renderStatement(Query::CREATE_TABLE, [ 'table' => $this->formatTable($schema->getTable()), 'columns' => $this->formatColumns($schema), 'keys' => $this->formatTableKeys($schema), 'options' => $this->formatTableOptions($schema->getOptions()) ] + $this->formatAttributes($query->getAttributes())); }
[ "public", "function", "buildCreateTable", "(", "Query", "$", "query", ")", "{", "$", "schema", "=", "$", "query", "->", "getSchema", "(", ")", ";", "if", "(", "!", "$", "schema", ")", "{", "throw", "new", "InvalidSchemaException", "(", "'Table creation requires a valid schema object'", ")", ";", "}", "return", "$", "this", "->", "renderStatement", "(", "Query", "::", "CREATE_TABLE", ",", "[", "'table'", "=>", "$", "this", "->", "formatTable", "(", "$", "schema", "->", "getTable", "(", ")", ")", ",", "'columns'", "=>", "$", "this", "->", "formatColumns", "(", "$", "schema", ")", ",", "'keys'", "=>", "$", "this", "->", "formatTableKeys", "(", "$", "schema", ")", ",", "'options'", "=>", "$", "this", "->", "formatTableOptions", "(", "$", "schema", "->", "getOptions", "(", ")", ")", "]", "+", "$", "this", "->", "formatAttributes", "(", "$", "query", "->", "getAttributes", "(", ")", ")", ")", ";", "}" ]
Build the CREATE TABLE query. Requires a table schema object. @param \Titon\Db\Query $query @return string @throws \Titon\Db\Exception\InvalidSchemaException
[ "Build", "the", "CREATE", "TABLE", "query", ".", "Requires", "a", "table", "schema", "object", "." ]
fbc5159d1ce9d2139759c9367565986981485604
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php#L41-L54
20,039
titon/db
src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php
AbstractPdoDialect.buildDelete
public function buildDelete(Query $query) { return $this->renderStatement(Query::DELETE, [ 'table' => $this->formatTable($query->getTable(), $query->getAlias()), 'joins' => $this->formatJoins($query->getJoins()), 'where' => $this->formatWhere($query->getWhere()), 'orderBy' => $this->formatOrderBy($query->getOrderBy()), 'limit' => $this->formatLimit($query->getLimit()), ] + $this->formatAttributes($query->getAttributes())); }
php
public function buildDelete(Query $query) { return $this->renderStatement(Query::DELETE, [ 'table' => $this->formatTable($query->getTable(), $query->getAlias()), 'joins' => $this->formatJoins($query->getJoins()), 'where' => $this->formatWhere($query->getWhere()), 'orderBy' => $this->formatOrderBy($query->getOrderBy()), 'limit' => $this->formatLimit($query->getLimit()), ] + $this->formatAttributes($query->getAttributes())); }
[ "public", "function", "buildDelete", "(", "Query", "$", "query", ")", "{", "return", "$", "this", "->", "renderStatement", "(", "Query", "::", "DELETE", ",", "[", "'table'", "=>", "$", "this", "->", "formatTable", "(", "$", "query", "->", "getTable", "(", ")", ",", "$", "query", "->", "getAlias", "(", ")", ")", ",", "'joins'", "=>", "$", "this", "->", "formatJoins", "(", "$", "query", "->", "getJoins", "(", ")", ")", ",", "'where'", "=>", "$", "this", "->", "formatWhere", "(", "$", "query", "->", "getWhere", "(", ")", ")", ",", "'orderBy'", "=>", "$", "this", "->", "formatOrderBy", "(", "$", "query", "->", "getOrderBy", "(", ")", ")", ",", "'limit'", "=>", "$", "this", "->", "formatLimit", "(", "$", "query", "->", "getLimit", "(", ")", ")", ",", "]", "+", "$", "this", "->", "formatAttributes", "(", "$", "query", "->", "getAttributes", "(", ")", ")", ")", ";", "}" ]
Build the DELETE query. @param \Titon\Db\Query $query @return string
[ "Build", "the", "DELETE", "query", "." ]
fbc5159d1ce9d2139759c9367565986981485604
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php#L62-L70
20,040
titon/db
src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php
AbstractPdoDialect.buildDropIndex
public function buildDropIndex(Query $query) { return $this->renderStatement(Query::DROP_INDEX, [ 'index' => $this->formatTable($query->getAlias()), 'table' => $this->formatTable($query->getTable()) ] + $this->formatAttributes($query->getAttributes())); }
php
public function buildDropIndex(Query $query) { return $this->renderStatement(Query::DROP_INDEX, [ 'index' => $this->formatTable($query->getAlias()), 'table' => $this->formatTable($query->getTable()) ] + $this->formatAttributes($query->getAttributes())); }
[ "public", "function", "buildDropIndex", "(", "Query", "$", "query", ")", "{", "return", "$", "this", "->", "renderStatement", "(", "Query", "::", "DROP_INDEX", ",", "[", "'index'", "=>", "$", "this", "->", "formatTable", "(", "$", "query", "->", "getAlias", "(", ")", ")", ",", "'table'", "=>", "$", "this", "->", "formatTable", "(", "$", "query", "->", "getTable", "(", ")", ")", "]", "+", "$", "this", "->", "formatAttributes", "(", "$", "query", "->", "getAttributes", "(", ")", ")", ")", ";", "}" ]
Build the DROP INDEX query. @param \Titon\Db\Query $query @return string
[ "Build", "the", "DROP", "INDEX", "query", "." ]
fbc5159d1ce9d2139759c9367565986981485604
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php#L78-L83
20,041
titon/db
src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php
AbstractPdoDialect.buildDropTable
public function buildDropTable(Query $query) { return $this->renderStatement(Query::DROP_TABLE, [ 'table' => $this->formatTable($query->getTable()) ] + $this->formatAttributes($query->getAttributes())); }
php
public function buildDropTable(Query $query) { return $this->renderStatement(Query::DROP_TABLE, [ 'table' => $this->formatTable($query->getTable()) ] + $this->formatAttributes($query->getAttributes())); }
[ "public", "function", "buildDropTable", "(", "Query", "$", "query", ")", "{", "return", "$", "this", "->", "renderStatement", "(", "Query", "::", "DROP_TABLE", ",", "[", "'table'", "=>", "$", "this", "->", "formatTable", "(", "$", "query", "->", "getTable", "(", ")", ")", "]", "+", "$", "this", "->", "formatAttributes", "(", "$", "query", "->", "getAttributes", "(", ")", ")", ")", ";", "}" ]
Build the DROP TABLE query. @param \Titon\Db\Query $query @return string
[ "Build", "the", "DROP", "TABLE", "query", "." ]
fbc5159d1ce9d2139759c9367565986981485604
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php#L91-L95
20,042
titon/db
src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php
AbstractPdoDialect.buildMultiInsert
public function buildMultiInsert(Query $query) { return $this->renderStatement(Query::INSERT, [ 'table' => $this->formatTable($query->getTable()), 'fields' => $this->formatFields($query), 'values' => $this->formatValues($query) ] + $this->formatAttributes($query->getAttributes())); }
php
public function buildMultiInsert(Query $query) { return $this->renderStatement(Query::INSERT, [ 'table' => $this->formatTable($query->getTable()), 'fields' => $this->formatFields($query), 'values' => $this->formatValues($query) ] + $this->formatAttributes($query->getAttributes())); }
[ "public", "function", "buildMultiInsert", "(", "Query", "$", "query", ")", "{", "return", "$", "this", "->", "renderStatement", "(", "Query", "::", "INSERT", ",", "[", "'table'", "=>", "$", "this", "->", "formatTable", "(", "$", "query", "->", "getTable", "(", ")", ")", ",", "'fields'", "=>", "$", "this", "->", "formatFields", "(", "$", "query", ")", ",", "'values'", "=>", "$", "this", "->", "formatValues", "(", "$", "query", ")", "]", "+", "$", "this", "->", "formatAttributes", "(", "$", "query", "->", "getAttributes", "(", ")", ")", ")", ";", "}" ]
Build the INSERT query with multiple record support. @param \Titon\Db\Query $query @return string
[ "Build", "the", "INSERT", "query", "with", "multiple", "record", "support", "." ]
fbc5159d1ce9d2139759c9367565986981485604
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php#L117-L123
20,043
titon/db
src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php
AbstractPdoDialect.buildSelect
public function buildSelect(Query $query) { return $this->renderStatement(Query::SELECT, [ 'fields' => $this->formatFields($query), 'table' => $this->formatTable($query->getTable(), $query->getAlias()), 'joins' => $this->formatJoins($query->getJoins()), 'where' => $this->formatWhere($query->getWhere()), 'groupBy' => $this->formatGroupBy($query->getGroupBy()), 'having' => $this->formatHaving($query->getHaving()), 'compounds' => $this->formatCompounds($query->getCompounds()), 'orderBy' => $this->formatOrderBy($query->getOrderBy()), 'limit' => $this->formatLimitOffset($query->getLimit(), $query->getOffset()), ] + $this->formatAttributes($query->getAttributes())); }
php
public function buildSelect(Query $query) { return $this->renderStatement(Query::SELECT, [ 'fields' => $this->formatFields($query), 'table' => $this->formatTable($query->getTable(), $query->getAlias()), 'joins' => $this->formatJoins($query->getJoins()), 'where' => $this->formatWhere($query->getWhere()), 'groupBy' => $this->formatGroupBy($query->getGroupBy()), 'having' => $this->formatHaving($query->getHaving()), 'compounds' => $this->formatCompounds($query->getCompounds()), 'orderBy' => $this->formatOrderBy($query->getOrderBy()), 'limit' => $this->formatLimitOffset($query->getLimit(), $query->getOffset()), ] + $this->formatAttributes($query->getAttributes())); }
[ "public", "function", "buildSelect", "(", "Query", "$", "query", ")", "{", "return", "$", "this", "->", "renderStatement", "(", "Query", "::", "SELECT", ",", "[", "'fields'", "=>", "$", "this", "->", "formatFields", "(", "$", "query", ")", ",", "'table'", "=>", "$", "this", "->", "formatTable", "(", "$", "query", "->", "getTable", "(", ")", ",", "$", "query", "->", "getAlias", "(", ")", ")", ",", "'joins'", "=>", "$", "this", "->", "formatJoins", "(", "$", "query", "->", "getJoins", "(", ")", ")", ",", "'where'", "=>", "$", "this", "->", "formatWhere", "(", "$", "query", "->", "getWhere", "(", ")", ")", ",", "'groupBy'", "=>", "$", "this", "->", "formatGroupBy", "(", "$", "query", "->", "getGroupBy", "(", ")", ")", ",", "'having'", "=>", "$", "this", "->", "formatHaving", "(", "$", "query", "->", "getHaving", "(", ")", ")", ",", "'compounds'", "=>", "$", "this", "->", "formatCompounds", "(", "$", "query", "->", "getCompounds", "(", ")", ")", ",", "'orderBy'", "=>", "$", "this", "->", "formatOrderBy", "(", "$", "query", "->", "getOrderBy", "(", ")", ")", ",", "'limit'", "=>", "$", "this", "->", "formatLimitOffset", "(", "$", "query", "->", "getLimit", "(", ")", ",", "$", "query", "->", "getOffset", "(", ")", ")", ",", "]", "+", "$", "this", "->", "formatAttributes", "(", "$", "query", "->", "getAttributes", "(", ")", ")", ")", ";", "}" ]
Build the SELECT query. @param \Titon\Db\Query $query @return string
[ "Build", "the", "SELECT", "query", "." ]
fbc5159d1ce9d2139759c9367565986981485604
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php#L131-L143
20,044
titon/db
src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php
AbstractPdoDialect.buildTruncate
public function buildTruncate(Query $query) { return $this->renderStatement(Query::TRUNCATE, [ 'table' => $this->formatTable($query->getTable()) ] + $this->formatAttributes($query->getAttributes())); }
php
public function buildTruncate(Query $query) { return $this->renderStatement(Query::TRUNCATE, [ 'table' => $this->formatTable($query->getTable()) ] + $this->formatAttributes($query->getAttributes())); }
[ "public", "function", "buildTruncate", "(", "Query", "$", "query", ")", "{", "return", "$", "this", "->", "renderStatement", "(", "Query", "::", "TRUNCATE", ",", "[", "'table'", "=>", "$", "this", "->", "formatTable", "(", "$", "query", "->", "getTable", "(", ")", ")", "]", "+", "$", "this", "->", "formatAttributes", "(", "$", "query", "->", "getAttributes", "(", ")", ")", ")", ";", "}" ]
Build the TRUNCATE query. @param \Titon\Db\Query $query @return string
[ "Build", "the", "TRUNCATE", "query", "." ]
fbc5159d1ce9d2139759c9367565986981485604
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php#L151-L155
20,045
titon/db
src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php
AbstractPdoDialect.buildUpdate
public function buildUpdate(Query $query) { return $this->renderStatement(Query::UPDATE, [ 'fields' => $this->formatFields($query), 'table' => $this->formatTable($query->getTable(), $query->getAlias()), 'joins' => $this->formatJoins($query->getJoins()), 'where' => $this->formatWhere($query->getWhere()), 'orderBy' => $this->formatOrderBy($query->getOrderBy()), 'limit' => $this->formatLimit($query->getLimit()), ] + $this->formatAttributes($query->getAttributes())); }
php
public function buildUpdate(Query $query) { return $this->renderStatement(Query::UPDATE, [ 'fields' => $this->formatFields($query), 'table' => $this->formatTable($query->getTable(), $query->getAlias()), 'joins' => $this->formatJoins($query->getJoins()), 'where' => $this->formatWhere($query->getWhere()), 'orderBy' => $this->formatOrderBy($query->getOrderBy()), 'limit' => $this->formatLimit($query->getLimit()), ] + $this->formatAttributes($query->getAttributes())); }
[ "public", "function", "buildUpdate", "(", "Query", "$", "query", ")", "{", "return", "$", "this", "->", "renderStatement", "(", "Query", "::", "UPDATE", ",", "[", "'fields'", "=>", "$", "this", "->", "formatFields", "(", "$", "query", ")", ",", "'table'", "=>", "$", "this", "->", "formatTable", "(", "$", "query", "->", "getTable", "(", ")", ",", "$", "query", "->", "getAlias", "(", ")", ")", ",", "'joins'", "=>", "$", "this", "->", "formatJoins", "(", "$", "query", "->", "getJoins", "(", ")", ")", ",", "'where'", "=>", "$", "this", "->", "formatWhere", "(", "$", "query", "->", "getWhere", "(", ")", ")", ",", "'orderBy'", "=>", "$", "this", "->", "formatOrderBy", "(", "$", "query", "->", "getOrderBy", "(", ")", ")", ",", "'limit'", "=>", "$", "this", "->", "formatLimit", "(", "$", "query", "->", "getLimit", "(", ")", ")", ",", "]", "+", "$", "this", "->", "formatAttributes", "(", "$", "query", "->", "getAttributes", "(", ")", ")", ")", ";", "}" ]
Build the UPDATE query. @param \Titon\Db\Query $query @return string
[ "Build", "the", "UPDATE", "query", "." ]
fbc5159d1ce9d2139759c9367565986981485604
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractPdoDialect.php#L163-L172
20,046
php-rise/rise
src/Template/Blocks/Block.php
Block.extend
public function extend($template, $data = [], $paramName = 'body') { $this->extendedTemplate = $this->resolveTemplatePath($template); if (is_array($data)) { $this->extendedData = $data; } if (is_string($paramName) && $paramName) { $this->extendedParamName = $paramName; } }
php
public function extend($template, $data = [], $paramName = 'body') { $this->extendedTemplate = $this->resolveTemplatePath($template); if (is_array($data)) { $this->extendedData = $data; } if (is_string($paramName) && $paramName) { $this->extendedParamName = $paramName; } }
[ "public", "function", "extend", "(", "$", "template", ",", "$", "data", "=", "[", "]", ",", "$", "paramName", "=", "'body'", ")", "{", "$", "this", "->", "extendedTemplate", "=", "$", "this", "->", "resolveTemplatePath", "(", "$", "template", ")", ";", "if", "(", "is_array", "(", "$", "data", ")", ")", "{", "$", "this", "->", "extendedData", "=", "$", "data", ";", "}", "if", "(", "is_string", "(", "$", "paramName", ")", "&&", "$", "paramName", ")", "{", "$", "this", "->", "extendedParamName", "=", "$", "paramName", ";", "}", "}" ]
Set extended template and data. @param string $template @param array $data Optional. @param string $paramName Optional. Variable name of the variable storing the content of this block, default to "body".
[ "Set", "extended", "template", "and", "data", "." ]
cd14ef9956f1b6875b7bcd642545dcef6a9152b7
https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Template/Blocks/Block.php#L111-L119
20,047
php-rise/rise
src/Template/Blocks/Block.php
Block.translate
public function translate($key, $defaultValue = '', $locale = null) { return $this->translation->translate($key, $defaultValue, $locale); }
php
public function translate($key, $defaultValue = '', $locale = null) { return $this->translation->translate($key, $defaultValue, $locale); }
[ "public", "function", "translate", "(", "$", "key", ",", "$", "defaultValue", "=", "''", ",", "$", "locale", "=", "null", ")", "{", "return", "$", "this", "->", "translation", "->", "translate", "(", "$", "key", ",", "$", "defaultValue", ",", "$", "locale", ")", ";", "}" ]
Helper function for translation. @param string $key @param string $defaultValue @param string $locale @return string
[ "Helper", "function", "for", "translation", "." ]
cd14ef9956f1b6875b7bcd642545dcef6a9152b7
https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Template/Blocks/Block.php#L176-L178
20,048
php-rise/rise
src/Template/Blocks/Block.php
Block.resolveTemplatePath
protected function resolveTemplatePath($path) { switch ($path[0]) { case '/': break; case '.': $path = realpath(dirname($this->template) . '/' . $path . '.phtml'); break; default: $path = realpath($this->pathService->getTemplatesPath() . '/' . $path . '.phtml'); break; } if ($path === false) { throw new NotFoundException($this->template . ' file not found'); } return $path; }
php
protected function resolveTemplatePath($path) { switch ($path[0]) { case '/': break; case '.': $path = realpath(dirname($this->template) . '/' . $path . '.phtml'); break; default: $path = realpath($this->pathService->getTemplatesPath() . '/' . $path . '.phtml'); break; } if ($path === false) { throw new NotFoundException($this->template . ' file not found'); } return $path; }
[ "protected", "function", "resolveTemplatePath", "(", "$", "path", ")", "{", "switch", "(", "$", "path", "[", "0", "]", ")", "{", "case", "'/'", ":", "break", ";", "case", "'.'", ":", "$", "path", "=", "realpath", "(", "dirname", "(", "$", "this", "->", "template", ")", ".", "'/'", ".", "$", "path", ".", "'.phtml'", ")", ";", "break", ";", "default", ":", "$", "path", "=", "realpath", "(", "$", "this", "->", "pathService", "->", "getTemplatesPath", "(", ")", ".", "'/'", ".", "$", "path", ".", "'.phtml'", ")", ";", "break", ";", "}", "if", "(", "$", "path", "===", "false", ")", "{", "throw", "new", "NotFoundException", "(", "$", "this", "->", "template", ".", "' file not found'", ")", ";", "}", "return", "$", "path", ";", "}" ]
Resolve template path. @param string $path @return string
[ "Resolve", "template", "path", "." ]
cd14ef9956f1b6875b7bcd642545dcef6a9152b7
https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Template/Blocks/Block.php#L222-L239
20,049
php-rise/rise
src/Template/Blocks/Block.php
Block.renderToHtml
protected function renderToHtml() { extract($this->data, EXTR_SKIP); ob_start(); set_error_handler([$this, 'handleError']); include $this->template; restore_error_handler(); $html = ob_get_clean(); return $html; }
php
protected function renderToHtml() { extract($this->data, EXTR_SKIP); ob_start(); set_error_handler([$this, 'handleError']); include $this->template; restore_error_handler(); $html = ob_get_clean(); return $html; }
[ "protected", "function", "renderToHtml", "(", ")", "{", "extract", "(", "$", "this", "->", "data", ",", "EXTR_SKIP", ")", ";", "ob_start", "(", ")", ";", "set_error_handler", "(", "[", "$", "this", ",", "'handleError'", "]", ")", ";", "include", "$", "this", "->", "template", ";", "restore_error_handler", "(", ")", ";", "$", "html", "=", "ob_get_clean", "(", ")", ";", "return", "$", "html", ";", "}" ]
Render this block to HTML string. @return string
[ "Render", "this", "block", "to", "HTML", "string", "." ]
cd14ef9956f1b6875b7bcd642545dcef6a9152b7
https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Template/Blocks/Block.php#L246-L254
20,050
Ocramius/OcraDiCompiler
src/OcraDiCompiler/Generator/DiProxyGenerator.php
DiProxyGenerator.normalizeAlias
protected function normalizeAlias($alias) { $normalized = preg_replace('/[^a-zA-Z0-9]/', ' ', $alias); $normalized = 'new' . str_replace(' ', '', ucwords($normalized)); return $normalized; }
php
protected function normalizeAlias($alias) { $normalized = preg_replace('/[^a-zA-Z0-9]/', ' ', $alias); $normalized = 'new' . str_replace(' ', '', ucwords($normalized)); return $normalized; }
[ "protected", "function", "normalizeAlias", "(", "$", "alias", ")", "{", "$", "normalized", "=", "preg_replace", "(", "'/[^a-zA-Z0-9]/'", ",", "' '", ",", "$", "alias", ")", ";", "$", "normalized", "=", "'new'", ".", "str_replace", "(", "' '", ",", "''", ",", "ucwords", "(", "$", "normalized", ")", ")", ";", "return", "$", "normalized", ";", "}" ]
Normalize an alias to a new instance method name @param string $alias @return string
[ "Normalize", "an", "alias", "to", "a", "new", "instance", "method", "name" ]
667f4b24771f27fb9c8d6c38ffaf72d9cd55ca4a
https://github.com/Ocramius/OcraDiCompiler/blob/667f4b24771f27fb9c8d6c38ffaf72d9cd55ca4a/src/OcraDiCompiler/Generator/DiProxyGenerator.php#L375-L380
20,051
steeffeen/FancyManiaLinks
FML/Stylesheet/Style.php
Style.addStyleId
public function addStyleId($styleId) { $styleId = (string)$styleId; if (!in_array($styleId, $this->styleIds)) { array_push($this->styleIds, $styleId); } return $this; }
php
public function addStyleId($styleId) { $styleId = (string)$styleId; if (!in_array($styleId, $this->styleIds)) { array_push($this->styleIds, $styleId); } return $this; }
[ "public", "function", "addStyleId", "(", "$", "styleId", ")", "{", "$", "styleId", "=", "(", "string", ")", "$", "styleId", ";", "if", "(", "!", "in_array", "(", "$", "styleId", ",", "$", "this", "->", "styleIds", ")", ")", "{", "array_push", "(", "$", "this", "->", "styleIds", ",", "$", "styleId", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add style Id @api @param string $styleId Style Id @return static
[ "Add", "style", "Id" ]
227b0759306f0a3c75873ba50276e4163a93bfa6
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Stylesheet/Style.php#L114-L121
20,052
steeffeen/FancyManiaLinks
FML/Stylesheet/Style.php
Style.addStyleClass
public function addStyleClass($styleClass) { $styleClass = (string)$styleClass; if (!in_array($styleClass, $this->styleClasses)) { array_push($this->styleClasses, $styleClass); } return $this; }
php
public function addStyleClass($styleClass) { $styleClass = (string)$styleClass; if (!in_array($styleClass, $this->styleClasses)) { array_push($this->styleClasses, $styleClass); } return $this; }
[ "public", "function", "addStyleClass", "(", "$", "styleClass", ")", "{", "$", "styleClass", "=", "(", "string", ")", "$", "styleClass", ";", "if", "(", "!", "in_array", "(", "$", "styleClass", ",", "$", "this", "->", "styleClasses", ")", ")", "{", "array_push", "(", "$", "this", "->", "styleClasses", ",", "$", "styleClass", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add style class @api @param string $styleClass Style class @return static
[ "Add", "style", "class" ]
227b0759306f0a3c75873ba50276e4163a93bfa6
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Stylesheet/Style.php#L193-L200
20,053
webforge-labs/psc-cms
lib/Psc/Doctrine/CollectionSynchronizer.php
CollectionSynchronizer.init
public function init(Entity $entity, Closure $adder = NULL, Closure $remover = NULL) { parent::init($entity); list($add, $remove) = $this->getRelationInterface(); if (!$adder) { $adder = function ($entity, $toEntity, $repository) use ($add) { $repository->persist($toEntity); $entity->$add($toEntity); }; } if (!$remover) { $remover = function ($entity, $fromEntity, $repository) use ($remove) { $repository->persist($fromEntity); $entity->$remove($fromEntity); }; } $repository = $this->collectionRepository; // insert: in $toCollection gibt es ein $toEntity, welches noch nicht in $fromCollection war $this->innerSynchronizer->onInsert(function ($toEntity) use ($repository, $entity, $adder) { $adder($entity, $toEntity, $repository); }); // update bzw merge: das $toEntity war bereits in der $fromCollection und ist in der $toCollection $this->innerSynchronizer->onUpdate(function ($toEntity) use ($repository, $entity, $adder) { $adder($entity, $toEntity, $repository, $isUpdate = TRUE); }); // delete: das $fromEntity war vorher in der $fromCollection und ist nicht mehr in der $toCollection $this->innerSynchronizer->onDelete(function (Entity $fromEntity) use ($entity, $remover, $repository) { $remover($entity, $fromEntity, $repository); // wenn $fromEntity 0 verknüpfungen hat, könnte man es hier auch löschen, dies macht aber das relationinterface }); return $this; }
php
public function init(Entity $entity, Closure $adder = NULL, Closure $remover = NULL) { parent::init($entity); list($add, $remove) = $this->getRelationInterface(); if (!$adder) { $adder = function ($entity, $toEntity, $repository) use ($add) { $repository->persist($toEntity); $entity->$add($toEntity); }; } if (!$remover) { $remover = function ($entity, $fromEntity, $repository) use ($remove) { $repository->persist($fromEntity); $entity->$remove($fromEntity); }; } $repository = $this->collectionRepository; // insert: in $toCollection gibt es ein $toEntity, welches noch nicht in $fromCollection war $this->innerSynchronizer->onInsert(function ($toEntity) use ($repository, $entity, $adder) { $adder($entity, $toEntity, $repository); }); // update bzw merge: das $toEntity war bereits in der $fromCollection und ist in der $toCollection $this->innerSynchronizer->onUpdate(function ($toEntity) use ($repository, $entity, $adder) { $adder($entity, $toEntity, $repository, $isUpdate = TRUE); }); // delete: das $fromEntity war vorher in der $fromCollection und ist nicht mehr in der $toCollection $this->innerSynchronizer->onDelete(function (Entity $fromEntity) use ($entity, $remover, $repository) { $remover($entity, $fromEntity, $repository); // wenn $fromEntity 0 verknüpfungen hat, könnte man es hier auch löschen, dies macht aber das relationinterface }); return $this; }
[ "public", "function", "init", "(", "Entity", "$", "entity", ",", "Closure", "$", "adder", "=", "NULL", ",", "Closure", "$", "remover", "=", "NULL", ")", "{", "parent", "::", "init", "(", "$", "entity", ")", ";", "list", "(", "$", "add", ",", "$", "remove", ")", "=", "$", "this", "->", "getRelationInterface", "(", ")", ";", "if", "(", "!", "$", "adder", ")", "{", "$", "adder", "=", "function", "(", "$", "entity", ",", "$", "toEntity", ",", "$", "repository", ")", "use", "(", "$", "add", ")", "{", "$", "repository", "->", "persist", "(", "$", "toEntity", ")", ";", "$", "entity", "->", "$", "add", "(", "$", "toEntity", ")", ";", "}", ";", "}", "if", "(", "!", "$", "remover", ")", "{", "$", "remover", "=", "function", "(", "$", "entity", ",", "$", "fromEntity", ",", "$", "repository", ")", "use", "(", "$", "remove", ")", "{", "$", "repository", "->", "persist", "(", "$", "fromEntity", ")", ";", "$", "entity", "->", "$", "remove", "(", "$", "fromEntity", ")", ";", "}", ";", "}", "$", "repository", "=", "$", "this", "->", "collectionRepository", ";", "// insert: in $toCollection gibt es ein $toEntity, welches noch nicht in $fromCollection war", "$", "this", "->", "innerSynchronizer", "->", "onInsert", "(", "function", "(", "$", "toEntity", ")", "use", "(", "$", "repository", ",", "$", "entity", ",", "$", "adder", ")", "{", "$", "adder", "(", "$", "entity", ",", "$", "toEntity", ",", "$", "repository", ")", ";", "}", ")", ";", "// update bzw merge: das $toEntity war bereits in der $fromCollection und ist in der $toCollection", "$", "this", "->", "innerSynchronizer", "->", "onUpdate", "(", "function", "(", "$", "toEntity", ")", "use", "(", "$", "repository", ",", "$", "entity", ",", "$", "adder", ")", "{", "$", "adder", "(", "$", "entity", ",", "$", "toEntity", ",", "$", "repository", ",", "$", "isUpdate", "=", "TRUE", ")", ";", "}", ")", ";", "// delete: das $fromEntity war vorher in der $fromCollection und ist nicht mehr in der $toCollection", "$", "this", "->", "innerSynchronizer", "->", "onDelete", "(", "function", "(", "Entity", "$", "fromEntity", ")", "use", "(", "$", "entity", ",", "$", "remover", ",", "$", "repository", ")", "{", "$", "remover", "(", "$", "entity", ",", "$", "fromEntity", ",", "$", "repository", ")", ";", "// wenn $fromEntity 0 verknüpfungen hat, könnte man es hier auch löschen, dies macht aber das relationinterface", "}", ")", ";", "return", "$", "this", ";", "}" ]
Kompiliert den Synchronizer und initialisiert wenn angegeben $add angegben wird, wird diese Closure mit $entity (der Parameter der init() Funktion) und $otherEntity aufgerufen bei $add ist $otherEntity ein Entity aus der $toCollection welches nicht in der $fromColleciton ist bei $remove ist $otherEntity ein Entity aus der $fromCollection welches nicht in der $toCollection ist als dritter parameter wird das $repository des Entities in der Collection übergeben (also nicht das von $entity) die Standard-Adder sind nur für den Fall, dass diese Klasse auch die owning Side ist sie rufen also $entity->addXXX($toEntity) auf bzw $entity->removeXXX($fromEntity) @param Closure $adder function ($entity, $toEntity, $collectionRepository) persist nicht vergesen! @param Closure $remover function ($entity, $fromEntity, $collectionRepository)
[ "Kompiliert", "den", "Synchronizer", "und", "initialisiert" ]
467bfa2547e6b4fa487d2d7f35fa6cc618dbc763
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/CollectionSynchronizer.php#L51-L89
20,054
maniaplanet/maniaplanet-ws-sdk
libraries/Maniaplanet/WebServices/ManiaHome/ServerPublisher.php
ServerPublisher.postPublicNotification
function postPublicNotification($message, $link = null, $iconStyle = null, $iconSubstyle = null, $titleIdString = null, $mediaURL = null, $group = null) { $n = new Notification(); $n->senderName = (object) array('serverLogin' => $this->serverLogin); $n->message = $message; $n->link = $link; $n->iconStyle = $iconStyle; $n->iconSubStyle = $iconSubstyle; $n->titleId = $titleIdString; $n->mediaURL = $mediaURL; $n->group = $group; return $this->execute('POST', '/maniahome/notification/public/', array($n)); }
php
function postPublicNotification($message, $link = null, $iconStyle = null, $iconSubstyle = null, $titleIdString = null, $mediaURL = null, $group = null) { $n = new Notification(); $n->senderName = (object) array('serverLogin' => $this->serverLogin); $n->message = $message; $n->link = $link; $n->iconStyle = $iconStyle; $n->iconSubStyle = $iconSubstyle; $n->titleId = $titleIdString; $n->mediaURL = $mediaURL; $n->group = $group; return $this->execute('POST', '/maniahome/notification/public/', array($n)); }
[ "function", "postPublicNotification", "(", "$", "message", ",", "$", "link", "=", "null", ",", "$", "iconStyle", "=", "null", ",", "$", "iconSubstyle", "=", "null", ",", "$", "titleIdString", "=", "null", ",", "$", "mediaURL", "=", "null", ",", "$", "group", "=", "null", ")", "{", "$", "n", "=", "new", "Notification", "(", ")", ";", "$", "n", "->", "senderName", "=", "(", "object", ")", "array", "(", "'serverLogin'", "=>", "$", "this", "->", "serverLogin", ")", ";", "$", "n", "->", "message", "=", "$", "message", ";", "$", "n", "->", "link", "=", "$", "link", ";", "$", "n", "->", "iconStyle", "=", "$", "iconStyle", ";", "$", "n", "->", "iconSubStyle", "=", "$", "iconSubstyle", ";", "$", "n", "->", "titleId", "=", "$", "titleIdString", ";", "$", "n", "->", "mediaURL", "=", "$", "mediaURL", ";", "$", "n", "->", "group", "=", "$", "group", ";", "return", "$", "this", "->", "execute", "(", "'POST'", ",", "'/maniahome/notification/public/'", ",", "array", "(", "$", "n", ")", ")", ";", "}" ]
Send a public notification to every player that bookmarked your server. @param string $message The message itself. If you send a public notification to a player, the message will be prepended with its nickname. Max length is 255 chars, you can use Maniaplanet special chars. @param string $link Link when the player clicks on the notification @param string $iconStyle Icon style (from the Manialink styles) @param string $iconSubstyle Icon substyle (from the Manialink styles) @param string $titleIdString the titleIdString where the notification will be visible. Leave empty to post for ManiaPlanet @param string $mediaURL Link to a picture (jpg,png or dds) or a video (webm) @param string $group Group on the notification (http://maniapla.net/maniahome-group) @return int
[ "Send", "a", "public", "notification", "to", "every", "player", "that", "bookmarked", "your", "server", "." ]
027a458388035fe66f2f56ff3ea1f85eff2a5a4e
https://github.com/maniaplanet/maniaplanet-ws-sdk/blob/027a458388035fe66f2f56ff3ea1f85eff2a5a4e/libraries/Maniaplanet/WebServices/ManiaHome/ServerPublisher.php#L48-L60
20,055
maniaplanet/maniaplanet-ws-sdk
libraries/Maniaplanet/WebServices/ManiaHome/ServerPublisher.php
ServerPublisher.postPrivateEvent
function postPrivateEvent($message, $eventDate, $receiverName, $link = null, $titleIdString = null, $mediaURL = null) { $e = new Event(); $n->senderName = (object) array('serverLogin' => $this->serverLogin); $e->message = $message; $e->link = $link; $e->receiverName = $receiverName; $e->eventDate = $eventDate; $e->isPrivate = true; $n->titleId = $titleIdString; $n->mediaURL = $mediaURL; return $this->execute('POST', '/maniahome/event/private/', array($e)); }
php
function postPrivateEvent($message, $eventDate, $receiverName, $link = null, $titleIdString = null, $mediaURL = null) { $e = new Event(); $n->senderName = (object) array('serverLogin' => $this->serverLogin); $e->message = $message; $e->link = $link; $e->receiverName = $receiverName; $e->eventDate = $eventDate; $e->isPrivate = true; $n->titleId = $titleIdString; $n->mediaURL = $mediaURL; return $this->execute('POST', '/maniahome/event/private/', array($e)); }
[ "function", "postPrivateEvent", "(", "$", "message", ",", "$", "eventDate", ",", "$", "receiverName", ",", "$", "link", "=", "null", ",", "$", "titleIdString", "=", "null", ",", "$", "mediaURL", "=", "null", ")", "{", "$", "e", "=", "new", "Event", "(", ")", ";", "$", "n", "->", "senderName", "=", "(", "object", ")", "array", "(", "'serverLogin'", "=>", "$", "this", "->", "serverLogin", ")", ";", "$", "e", "->", "message", "=", "$", "message", ";", "$", "e", "->", "link", "=", "$", "link", ";", "$", "e", "->", "receiverName", "=", "$", "receiverName", ";", "$", "e", "->", "eventDate", "=", "$", "eventDate", ";", "$", "e", "->", "isPrivate", "=", "true", ";", "$", "n", "->", "titleId", "=", "$", "titleIdString", ";", "$", "n", "->", "mediaURL", "=", "$", "mediaURL", ";", "return", "$", "this", "->", "execute", "(", "'POST'", ",", "'/maniahome/event/private/'", ",", "array", "(", "$", "e", ")", ")", ";", "}" ]
Create an event visible only by the receivers. To create an event for many players just give an array of login as receiverName. @param string $message The message itself. If you send a public notification to a player, the message will be prepended with its nickname. Max length is 255 chars, you can use Maniaplanet special chars. @param string|string[] $receiverName The receiver(s) of the notification. @param int $eventDate The UNIX Timestamp of the date of the event @param string $link Link when the player clicks on the notification @return int
[ "Create", "an", "event", "visible", "only", "by", "the", "receivers", ".", "To", "create", "an", "event", "for", "many", "players", "just", "give", "an", "array", "of", "login", "as", "receiverName", "." ]
027a458388035fe66f2f56ff3ea1f85eff2a5a4e
https://github.com/maniaplanet/maniaplanet-ws-sdk/blob/027a458388035fe66f2f56ff3ea1f85eff2a5a4e/libraries/Maniaplanet/WebServices/ManiaHome/ServerPublisher.php#L127-L139
20,056
maniaplanet/maniaplanet-ws-sdk
libraries/Maniaplanet/WebServices/ManiaHome/ServerPublisher.php
ServerPublisher.postPublicEvent
function postPublicEvent($message, $eventDate, $link = null, $titleIdString = null, $mediaURL = null) { $e = new Event(); $n->senderName = (object) array('serverLogin' => $this->serverLogin); $e->message = $message; $e->link = $link; $e->eventDate = $eventDate; $n->titleId = $titleIdString; $n->mediaURL = $mediaURL; return $this->execute('POST', '/maniahome/event/public/', array($e)); }
php
function postPublicEvent($message, $eventDate, $link = null, $titleIdString = null, $mediaURL = null) { $e = new Event(); $n->senderName = (object) array('serverLogin' => $this->serverLogin); $e->message = $message; $e->link = $link; $e->eventDate = $eventDate; $n->titleId = $titleIdString; $n->mediaURL = $mediaURL; return $this->execute('POST', '/maniahome/event/public/', array($e)); }
[ "function", "postPublicEvent", "(", "$", "message", ",", "$", "eventDate", ",", "$", "link", "=", "null", ",", "$", "titleIdString", "=", "null", ",", "$", "mediaURL", "=", "null", ")", "{", "$", "e", "=", "new", "Event", "(", ")", ";", "$", "n", "->", "senderName", "=", "(", "object", ")", "array", "(", "'serverLogin'", "=>", "$", "this", "->", "serverLogin", ")", ";", "$", "e", "->", "message", "=", "$", "message", ";", "$", "e", "->", "link", "=", "$", "link", ";", "$", "e", "->", "eventDate", "=", "$", "eventDate", ";", "$", "n", "->", "titleId", "=", "$", "titleIdString", ";", "$", "n", "->", "mediaURL", "=", "$", "mediaURL", ";", "return", "$", "this", "->", "execute", "(", "'POST'", ",", "'/maniahome/event/public/'", ",", "array", "(", "$", "e", ")", ")", ";", "}" ]
Create an event visible by all players who bookmarked your server @param string $message The message itself. If you send a public notification to a player, the @param string message will be prepended with its nickname. Max length is 255 chars, you can use Maniaplanet special chars. @param int $eventDate The UNIX Timestamp of the date of the event @param string $link Link when the player clicks on the notification @return int
[ "Create", "an", "event", "visible", "by", "all", "players", "who", "bookmarked", "your", "server" ]
027a458388035fe66f2f56ff3ea1f85eff2a5a4e
https://github.com/maniaplanet/maniaplanet-ws-sdk/blob/027a458388035fe66f2f56ff3ea1f85eff2a5a4e/libraries/Maniaplanet/WebServices/ManiaHome/ServerPublisher.php#L150-L160
20,057
devmobgroup/postcodes
src/Util/Uri.php
Uri.create
public static function create(string $baseUri, array $query = []): string { if (count($query) === 0) { return $baseUri; } return sprintf('%s/?%s', $baseUri, http_build_query($query)); }
php
public static function create(string $baseUri, array $query = []): string { if (count($query) === 0) { return $baseUri; } return sprintf('%s/?%s', $baseUri, http_build_query($query)); }
[ "public", "static", "function", "create", "(", "string", "$", "baseUri", ",", "array", "$", "query", "=", "[", "]", ")", ":", "string", "{", "if", "(", "count", "(", "$", "query", ")", "===", "0", ")", "{", "return", "$", "baseUri", ";", "}", "return", "sprintf", "(", "'%s/?%s'", ",", "$", "baseUri", ",", "http_build_query", "(", "$", "query", ")", ")", ";", "}" ]
Create request url based on base uri and request parameters. @param string $baseUri @param array $query @return string
[ "Create", "request", "url", "based", "on", "base", "uri", "and", "request", "parameters", "." ]
1a8438fd960a8f50ec28d61af94560892b529f12
https://github.com/devmobgroup/postcodes/blob/1a8438fd960a8f50ec28d61af94560892b529f12/src/Util/Uri.php#L14-L21
20,058
CakeCMS/Core
src/View/Helper/FormHelper.php
FormHelper.switcher
public function switcher($fieldName, array $options = []) { $input = parent::checkbox($fieldName, $options); if ($this->getConfig('materializeCss', false) === false) { return $input; } $options += [ 'before' => __d('backend', 'Off'), 'after' => __d('backend', 'On') ]; $title = (Arr::key('title', $options)) ? $options['title'] : $fieldName; if (!empty($title)) { $title = $this->Html->div('switch-title', $title); } $content = $this->formatTemplate(__FUNCTION__, [ 'input' => $input, 'title' => $title, 'after' => $options['after'], 'before' => $options['before'], 'lever' => '<span class="lever"></span>' ]); return $content; }
php
public function switcher($fieldName, array $options = []) { $input = parent::checkbox($fieldName, $options); if ($this->getConfig('materializeCss', false) === false) { return $input; } $options += [ 'before' => __d('backend', 'Off'), 'after' => __d('backend', 'On') ]; $title = (Arr::key('title', $options)) ? $options['title'] : $fieldName; if (!empty($title)) { $title = $this->Html->div('switch-title', $title); } $content = $this->formatTemplate(__FUNCTION__, [ 'input' => $input, 'title' => $title, 'after' => $options['after'], 'before' => $options['before'], 'lever' => '<span class="lever"></span>' ]); return $content; }
[ "public", "function", "switcher", "(", "$", "fieldName", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "input", "=", "parent", "::", "checkbox", "(", "$", "fieldName", ",", "$", "options", ")", ";", "if", "(", "$", "this", "->", "getConfig", "(", "'materializeCss'", ",", "false", ")", "===", "false", ")", "{", "return", "$", "input", ";", "}", "$", "options", "+=", "[", "'before'", "=>", "__d", "(", "'backend'", ",", "'Off'", ")", ",", "'after'", "=>", "__d", "(", "'backend'", ",", "'On'", ")", "]", ";", "$", "title", "=", "(", "Arr", "::", "key", "(", "'title'", ",", "$", "options", ")", ")", "?", "$", "options", "[", "'title'", "]", ":", "$", "fieldName", ";", "if", "(", "!", "empty", "(", "$", "title", ")", ")", "{", "$", "title", "=", "$", "this", "->", "Html", "->", "div", "(", "'switch-title'", ",", "$", "title", ")", ";", "}", "$", "content", "=", "$", "this", "->", "formatTemplate", "(", "__FUNCTION__", ",", "[", "'input'", "=>", "$", "input", ",", "'title'", "=>", "$", "title", ",", "'after'", "=>", "$", "options", "[", "'after'", "]", ",", "'before'", "=>", "$", "options", "[", "'before'", "]", ",", "'lever'", "=>", "'<span class=\"lever\"></span>'", "]", ")", ";", "return", "$", "content", ";", "}" ]
Form switcher. @param string $fieldName @param array $options @return string
[ "Form", "switcher", "." ]
f9cba7aa0043a10e5c35bd45fbad158688a09a96
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/FormHelper.php#L147-L175
20,059
CakeCMS/Core
src/View/Helper/FormHelper.php
FormHelper.create
public function create($model = null, array $options = []) { $options += ['process' => false, 'jsForm' => false]; $options = $this->addClass($options, $this->_class('form')); $isProcess = $options['process']; if ($isProcess !== false) { $_options = [ 'url' => [ 'plugin' => $this->request->getParam('plugin'), 'controller' => $this->request->getParam('controller'), 'action' => 'process' ] ]; $options['jsForm'] = true; $options = Hash::merge($_options, $options); } $isJsForm = $options['jsForm']; if ($isJsForm) { $this->_isJsForm = true; $options = $this->addClass($options, 'jsForm'); } unset($options['process'], $options['jsForm']); return parent::create($model, $options); }
php
public function create($model = null, array $options = []) { $options += ['process' => false, 'jsForm' => false]; $options = $this->addClass($options, $this->_class('form')); $isProcess = $options['process']; if ($isProcess !== false) { $_options = [ 'url' => [ 'plugin' => $this->request->getParam('plugin'), 'controller' => $this->request->getParam('controller'), 'action' => 'process' ] ]; $options['jsForm'] = true; $options = Hash::merge($_options, $options); } $isJsForm = $options['jsForm']; if ($isJsForm) { $this->_isJsForm = true; $options = $this->addClass($options, 'jsForm'); } unset($options['process'], $options['jsForm']); return parent::create($model, $options); }
[ "public", "function", "create", "(", "$", "model", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "+=", "[", "'process'", "=>", "false", ",", "'jsForm'", "=>", "false", "]", ";", "$", "options", "=", "$", "this", "->", "addClass", "(", "$", "options", ",", "$", "this", "->", "_class", "(", "'form'", ")", ")", ";", "$", "isProcess", "=", "$", "options", "[", "'process'", "]", ";", "if", "(", "$", "isProcess", "!==", "false", ")", "{", "$", "_options", "=", "[", "'url'", "=>", "[", "'plugin'", "=>", "$", "this", "->", "request", "->", "getParam", "(", "'plugin'", ")", ",", "'controller'", "=>", "$", "this", "->", "request", "->", "getParam", "(", "'controller'", ")", ",", "'action'", "=>", "'process'", "]", "]", ";", "$", "options", "[", "'jsForm'", "]", "=", "true", ";", "$", "options", "=", "Hash", "::", "merge", "(", "$", "_options", ",", "$", "options", ")", ";", "}", "$", "isJsForm", "=", "$", "options", "[", "'jsForm'", "]", ";", "if", "(", "$", "isJsForm", ")", "{", "$", "this", "->", "_isJsForm", "=", "true", ";", "$", "options", "=", "$", "this", "->", "addClass", "(", "$", "options", ",", "'jsForm'", ")", ";", "}", "unset", "(", "$", "options", "[", "'process'", "]", ",", "$", "options", "[", "'jsForm'", "]", ")", ";", "return", "parent", "::", "create", "(", "$", "model", ",", "$", "options", ")", ";", "}" ]
Create html form. @param mixed $model @param array $options @return string
[ "Create", "html", "form", "." ]
f9cba7aa0043a10e5c35bd45fbad158688a09a96
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/FormHelper.php#L212-L241
20,060
CakeCMS/Core
src/View/Helper/FormHelper.php
FormHelper.end
public function end(array $secureAttributes = []) { if ($this->_isJsForm) { return implode('', [ $this->hidden('action', ['value' => '', 'class' => 'jsFormAction']), parent::end($secureAttributes) ]); } return parent::end($secureAttributes); }
php
public function end(array $secureAttributes = []) { if ($this->_isJsForm) { return implode('', [ $this->hidden('action', ['value' => '', 'class' => 'jsFormAction']), parent::end($secureAttributes) ]); } return parent::end($secureAttributes); }
[ "public", "function", "end", "(", "array", "$", "secureAttributes", "=", "[", "]", ")", "{", "if", "(", "$", "this", "->", "_isJsForm", ")", "{", "return", "implode", "(", "''", ",", "[", "$", "this", "->", "hidden", "(", "'action'", ",", "[", "'value'", "=>", "''", ",", "'class'", "=>", "'jsFormAction'", "]", ")", ",", "parent", "::", "end", "(", "$", "secureAttributes", ")", "]", ")", ";", "}", "return", "parent", "::", "end", "(", "$", "secureAttributes", ")", ";", "}" ]
End html form. @param array $secureAttributes @return string
[ "End", "html", "form", "." ]
f9cba7aa0043a10e5c35bd45fbad158688a09a96
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/FormHelper.php#L249-L259
20,061
CakeCMS/Core
src/View/Helper/FormHelper.php
FormHelper._addDefaultContextProviders
protected function _addDefaultContextProviders() { $this->addContextProvider('orm', function ($request, $data) { if (is_array($data['entity']) || $data['entity'] instanceof \Traversable) { $pass = (new Collection($data['entity']))->first() !== null; if ($pass) { return new EntityContext($request, $data); } } return $this->_addEntityContent($request, $data); }); $this->_addFormContextProvider(); $this->_addFormArrayProvider(); }
php
protected function _addDefaultContextProviders() { $this->addContextProvider('orm', function ($request, $data) { if (is_array($data['entity']) || $data['entity'] instanceof \Traversable) { $pass = (new Collection($data['entity']))->first() !== null; if ($pass) { return new EntityContext($request, $data); } } return $this->_addEntityContent($request, $data); }); $this->_addFormContextProvider(); $this->_addFormArrayProvider(); }
[ "protected", "function", "_addDefaultContextProviders", "(", ")", "{", "$", "this", "->", "addContextProvider", "(", "'orm'", ",", "function", "(", "$", "request", ",", "$", "data", ")", "{", "if", "(", "is_array", "(", "$", "data", "[", "'entity'", "]", ")", "||", "$", "data", "[", "'entity'", "]", "instanceof", "\\", "Traversable", ")", "{", "$", "pass", "=", "(", "new", "Collection", "(", "$", "data", "[", "'entity'", "]", ")", ")", "->", "first", "(", ")", "!==", "null", ";", "if", "(", "$", "pass", ")", "{", "return", "new", "EntityContext", "(", "$", "request", ",", "$", "data", ")", ";", "}", "}", "return", "$", "this", "->", "_addEntityContent", "(", "$", "request", ",", "$", "data", ")", ";", "}", ")", ";", "$", "this", "->", "_addFormContextProvider", "(", ")", ";", "$", "this", "->", "_addFormArrayProvider", "(", ")", ";", "}" ]
Add the default suite of context providers provided. @return void
[ "Add", "the", "default", "suite", "of", "context", "providers", "provided", "." ]
f9cba7aa0043a10e5c35bd45fbad158688a09a96
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/FormHelper.php#L278-L293
20,062
CakeCMS/Core
src/View/Helper/FormHelper.php
FormHelper._addEntityContent
protected function _addEntityContent($request, $data) { if ($data['entity'] instanceof EntityInterface) { return new EntityContext($request, $data); } if (is_array($data['entity']) && empty($data['entity']['schema'])) { return new EntityContext($request, $data); } }
php
protected function _addEntityContent($request, $data) { if ($data['entity'] instanceof EntityInterface) { return new EntityContext($request, $data); } if (is_array($data['entity']) && empty($data['entity']['schema'])) { return new EntityContext($request, $data); } }
[ "protected", "function", "_addEntityContent", "(", "$", "request", ",", "$", "data", ")", "{", "if", "(", "$", "data", "[", "'entity'", "]", "instanceof", "EntityInterface", ")", "{", "return", "new", "EntityContext", "(", "$", "request", ",", "$", "data", ")", ";", "}", "if", "(", "is_array", "(", "$", "data", "[", "'entity'", "]", ")", "&&", "empty", "(", "$", "data", "[", "'entity'", "]", "[", "'schema'", "]", ")", ")", "{", "return", "new", "EntityContext", "(", "$", "request", ",", "$", "data", ")", ";", "}", "}" ]
Add the entity suite of context providers provided. @param $request @param $data @return EntityContext
[ "Add", "the", "entity", "suite", "of", "context", "providers", "provided", "." ]
f9cba7aa0043a10e5c35bd45fbad158688a09a96
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/FormHelper.php#L330-L339
20,063
CakeCMS/Core
src/View/Helper/FormHelper.php
FormHelper._addFormArrayProvider
protected function _addFormArrayProvider() { $this->addContextProvider('array', function ($request, $data) { if (is_array($data['entity']) && isset($data['entity']['schema'])) { return new ArrayContext($request, $data['entity']); } }); }
php
protected function _addFormArrayProvider() { $this->addContextProvider('array', function ($request, $data) { if (is_array($data['entity']) && isset($data['entity']['schema'])) { return new ArrayContext($request, $data['entity']); } }); }
[ "protected", "function", "_addFormArrayProvider", "(", ")", "{", "$", "this", "->", "addContextProvider", "(", "'array'", ",", "function", "(", "$", "request", ",", "$", "data", ")", "{", "if", "(", "is_array", "(", "$", "data", "[", "'entity'", "]", ")", "&&", "isset", "(", "$", "data", "[", "'entity'", "]", "[", "'schema'", "]", ")", ")", "{", "return", "new", "ArrayContext", "(", "$", "request", ",", "$", "data", "[", "'entity'", "]", ")", ";", "}", "}", ")", ";", "}" ]
Add the array suite of context providers provided. @return void
[ "Add", "the", "array", "suite", "of", "context", "providers", "provided", "." ]
f9cba7aa0043a10e5c35bd45fbad158688a09a96
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/FormHelper.php#L346-L353
20,064
CakeCMS/Core
src/View/Helper/FormHelper.php
FormHelper._addFormContextProvider
protected function _addFormContextProvider() { $this->addContextProvider('form', function ($request, $data) { if ($data['entity'] instanceof Form) { return new FormContext($request, $data); } }); }
php
protected function _addFormContextProvider() { $this->addContextProvider('form', function ($request, $data) { if ($data['entity'] instanceof Form) { return new FormContext($request, $data); } }); }
[ "protected", "function", "_addFormContextProvider", "(", ")", "{", "$", "this", "->", "addContextProvider", "(", "'form'", ",", "function", "(", "$", "request", ",", "$", "data", ")", "{", "if", "(", "$", "data", "[", "'entity'", "]", "instanceof", "Form", ")", "{", "return", "new", "FormContext", "(", "$", "request", ",", "$", "data", ")", ";", "}", "}", ")", ";", "}" ]
Add the form suite of context providers provided. @return void
[ "Add", "the", "form", "suite", "of", "context", "providers", "provided", "." ]
f9cba7aa0043a10e5c35bd45fbad158688a09a96
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/FormHelper.php#L360-L367
20,065
basarevych/task-daemon
library/TaskDaemon/TaskDaemon.php
TaskDaemon.defineTask
public function defineTask($name, $object) { $options = static::getOptions(); $debug = @$options['debug'] === true; if ($this->started) throw new \Exception("Define tasks before start()ing the daemon not after"); if (! $object instanceof AbstractTask) throw new \Exception("Task must implement AbstractTask"); $object->setDaemon($this); $this->tasks[$name] = $object; if ($debug) echo "==> Task defined: $name" . PHP_EOL; return $this; }
php
public function defineTask($name, $object) { $options = static::getOptions(); $debug = @$options['debug'] === true; if ($this->started) throw new \Exception("Define tasks before start()ing the daemon not after"); if (! $object instanceof AbstractTask) throw new \Exception("Task must implement AbstractTask"); $object->setDaemon($this); $this->tasks[$name] = $object; if ($debug) echo "==> Task defined: $name" . PHP_EOL; return $this; }
[ "public", "function", "defineTask", "(", "$", "name", ",", "$", "object", ")", "{", "$", "options", "=", "static", "::", "getOptions", "(", ")", ";", "$", "debug", "=", "@", "$", "options", "[", "'debug'", "]", "===", "true", ";", "if", "(", "$", "this", "->", "started", ")", "throw", "new", "\\", "Exception", "(", "\"Define tasks before start()ing the daemon not after\"", ")", ";", "if", "(", "!", "$", "object", "instanceof", "AbstractTask", ")", "throw", "new", "\\", "Exception", "(", "\"Task must implement AbstractTask\"", ")", ";", "$", "object", "->", "setDaemon", "(", "$", "this", ")", ";", "$", "this", "->", "tasks", "[", "$", "name", "]", "=", "$", "object", ";", "if", "(", "$", "debug", ")", "echo", "\"==> Task defined: $name\"", ".", "PHP_EOL", ";", "return", "$", "this", ";", "}" ]
Add task to the list of known tasks @param string $name @param AbstractTask $object @return TaskDaemon
[ "Add", "task", "to", "the", "list", "of", "known", "tasks" ]
d8084e414d87cabe3c3066902da625c6f0ba770b
https://github.com/basarevych/task-daemon/blob/d8084e414d87cabe3c3066902da625c6f0ba770b/library/TaskDaemon/TaskDaemon.php#L94-L112
20,066
basarevych/task-daemon
library/TaskDaemon/TaskDaemon.php
TaskDaemon.runTask
public function runTask($name, $data = null, $allowDuplicates = false) { $options = static::getOptions(); $debug = @$options['debug'] === true; if ($debug) echo "==> Trying to run task: $name" . PHP_EOL; $function = $options['namespace'] . '-' . $name; $data = json_encode($data); if ($allowDuplicates) $unique = self::generateUnique(); else $unique = md5($function . '-' . $data); $gmClient = new GearmanClient(); $gmClient->addServer($options['gearman']['host'], $options['gearman']['port']); $gmClient->doBackground($function, $data, $unique); $code = $gmClient->returnCode(); if ($code != GEARMAN_SUCCESS) throw new \Exception("Could not run task: $name ($code)"); return $this; }
php
public function runTask($name, $data = null, $allowDuplicates = false) { $options = static::getOptions(); $debug = @$options['debug'] === true; if ($debug) echo "==> Trying to run task: $name" . PHP_EOL; $function = $options['namespace'] . '-' . $name; $data = json_encode($data); if ($allowDuplicates) $unique = self::generateUnique(); else $unique = md5($function . '-' . $data); $gmClient = new GearmanClient(); $gmClient->addServer($options['gearman']['host'], $options['gearman']['port']); $gmClient->doBackground($function, $data, $unique); $code = $gmClient->returnCode(); if ($code != GEARMAN_SUCCESS) throw new \Exception("Could not run task: $name ($code)"); return $this; }
[ "public", "function", "runTask", "(", "$", "name", ",", "$", "data", "=", "null", ",", "$", "allowDuplicates", "=", "false", ")", "{", "$", "options", "=", "static", "::", "getOptions", "(", ")", ";", "$", "debug", "=", "@", "$", "options", "[", "'debug'", "]", "===", "true", ";", "if", "(", "$", "debug", ")", "echo", "\"==> Trying to run task: $name\"", ".", "PHP_EOL", ";", "$", "function", "=", "$", "options", "[", "'namespace'", "]", ".", "'-'", ".", "$", "name", ";", "$", "data", "=", "json_encode", "(", "$", "data", ")", ";", "if", "(", "$", "allowDuplicates", ")", "$", "unique", "=", "self", "::", "generateUnique", "(", ")", ";", "else", "$", "unique", "=", "md5", "(", "$", "function", ".", "'-'", ".", "$", "data", ")", ";", "$", "gmClient", "=", "new", "GearmanClient", "(", ")", ";", "$", "gmClient", "->", "addServer", "(", "$", "options", "[", "'gearman'", "]", "[", "'host'", "]", ",", "$", "options", "[", "'gearman'", "]", "[", "'port'", "]", ")", ";", "$", "gmClient", "->", "doBackground", "(", "$", "function", ",", "$", "data", ",", "$", "unique", ")", ";", "$", "code", "=", "$", "gmClient", "->", "returnCode", "(", ")", ";", "if", "(", "$", "code", "!=", "GEARMAN_SUCCESS", ")", "throw", "new", "\\", "Exception", "(", "\"Could not run task: $name ($code)\"", ")", ";", "return", "$", "this", ";", "}" ]
Add known task to the run queue @param string $name @param mixed $data @param boolean $allowDuplicates @return TaskDaemon
[ "Add", "known", "task", "to", "the", "run", "queue" ]
d8084e414d87cabe3c3066902da625c6f0ba770b
https://github.com/basarevych/task-daemon/blob/d8084e414d87cabe3c3066902da625c6f0ba770b/library/TaskDaemon/TaskDaemon.php#L122-L146
20,067
basarevych/task-daemon
library/TaskDaemon/TaskDaemon.php
TaskDaemon.ping
public function ping() { $options = static::getOptions(); $debug = @$options['debug'] === true; $gmClient = new GearmanClient(); $gmClient->addServer($options['gearman']['host'], $options['gearman']['port']); $ping = $gmClient->ping(self::generateUnique()); if ($debug) echo "==> Pinging job server: " . ($ping ? 'Success' : 'Failure') . PHP_EOL; $code = $gmClient->returnCode(); if ($code != GEARMAN_SUCCESS) throw new \Exception("Ping failed ($code)"); return $ping; }
php
public function ping() { $options = static::getOptions(); $debug = @$options['debug'] === true; $gmClient = new GearmanClient(); $gmClient->addServer($options['gearman']['host'], $options['gearman']['port']); $ping = $gmClient->ping(self::generateUnique()); if ($debug) echo "==> Pinging job server: " . ($ping ? 'Success' : 'Failure') . PHP_EOL; $code = $gmClient->returnCode(); if ($code != GEARMAN_SUCCESS) throw new \Exception("Ping failed ($code)"); return $ping; }
[ "public", "function", "ping", "(", ")", "{", "$", "options", "=", "static", "::", "getOptions", "(", ")", ";", "$", "debug", "=", "@", "$", "options", "[", "'debug'", "]", "===", "true", ";", "$", "gmClient", "=", "new", "GearmanClient", "(", ")", ";", "$", "gmClient", "->", "addServer", "(", "$", "options", "[", "'gearman'", "]", "[", "'host'", "]", ",", "$", "options", "[", "'gearman'", "]", "[", "'port'", "]", ")", ";", "$", "ping", "=", "$", "gmClient", "->", "ping", "(", "self", "::", "generateUnique", "(", ")", ")", ";", "if", "(", "$", "debug", ")", "echo", "\"==> Pinging job server: \"", ".", "(", "$", "ping", "?", "'Success'", ":", "'Failure'", ")", ".", "PHP_EOL", ";", "$", "code", "=", "$", "gmClient", "->", "returnCode", "(", ")", ";", "if", "(", "$", "code", "!=", "GEARMAN_SUCCESS", ")", "throw", "new", "\\", "Exception", "(", "\"Ping failed ($code)\"", ")", ";", "return", "$", "ping", ";", "}" ]
Ping job servers @return TaskDaemon
[ "Ping", "job", "servers" ]
d8084e414d87cabe3c3066902da625c6f0ba770b
https://github.com/basarevych/task-daemon/blob/d8084e414d87cabe3c3066902da625c6f0ba770b/library/TaskDaemon/TaskDaemon.php#L153-L171
20,068
basarevych/task-daemon
library/TaskDaemon/TaskDaemon.php
TaskDaemon.getPid
public function getPid() { $options = static::getOptions(); $debug = @$options['debug'] === true; $pidFile = $options['pid_file']; if (!$pidFile) throw new \Exception("No pid_file in the config"); $fpPid = fopen($pidFile, "c"); if (!$fpPid) throw new \Exception("Could not open " . $pidFile); if (!flock($fpPid, LOCK_EX | LOCK_NB)) { fclose($fpPid); return (int)file_get_contents($pidFile); } flock($fpPid, LOCK_UN); fclose($fpPid); @unlink($pidFile); return false; }
php
public function getPid() { $options = static::getOptions(); $debug = @$options['debug'] === true; $pidFile = $options['pid_file']; if (!$pidFile) throw new \Exception("No pid_file in the config"); $fpPid = fopen($pidFile, "c"); if (!$fpPid) throw new \Exception("Could not open " . $pidFile); if (!flock($fpPid, LOCK_EX | LOCK_NB)) { fclose($fpPid); return (int)file_get_contents($pidFile); } flock($fpPid, LOCK_UN); fclose($fpPid); @unlink($pidFile); return false; }
[ "public", "function", "getPid", "(", ")", "{", "$", "options", "=", "static", "::", "getOptions", "(", ")", ";", "$", "debug", "=", "@", "$", "options", "[", "'debug'", "]", "===", "true", ";", "$", "pidFile", "=", "$", "options", "[", "'pid_file'", "]", ";", "if", "(", "!", "$", "pidFile", ")", "throw", "new", "\\", "Exception", "(", "\"No pid_file in the config\"", ")", ";", "$", "fpPid", "=", "fopen", "(", "$", "pidFile", ",", "\"c\"", ")", ";", "if", "(", "!", "$", "fpPid", ")", "throw", "new", "\\", "Exception", "(", "\"Could not open \"", ".", "$", "pidFile", ")", ";", "if", "(", "!", "flock", "(", "$", "fpPid", ",", "LOCK_EX", "|", "LOCK_NB", ")", ")", "{", "fclose", "(", "$", "fpPid", ")", ";", "return", "(", "int", ")", "file_get_contents", "(", "$", "pidFile", ")", ";", "}", "flock", "(", "$", "fpPid", ",", "LOCK_UN", ")", ";", "fclose", "(", "$", "fpPid", ")", ";", "@", "unlink", "(", "$", "pidFile", ")", ";", "return", "false", ";", "}" ]
Get daemon PID @return integer|false Returns false if there is no daemon running
[ "Get", "daemon", "PID" ]
d8084e414d87cabe3c3066902da625c6f0ba770b
https://github.com/basarevych/task-daemon/blob/d8084e414d87cabe3c3066902da625c6f0ba770b/library/TaskDaemon/TaskDaemon.php#L178-L200
20,069
basarevych/task-daemon
library/TaskDaemon/TaskDaemon.php
TaskDaemon.stop
public function stop() { $options = static::getOptions(); $debug = @$options['debug'] === true; $pidFile = $options['pid_file']; if (!$pidFile) throw new \Exception("No pid_file in the config"); $fpPid = fopen($pidFile, "c"); if (!$fpPid) throw new \Exception("Could not open " . $pidFile); if (flock($fpPid, LOCK_EX | LOCK_NB)) { flock($fpPid, LOCK_UN); fclose($fpPid); if ($debug) echo "==> Daemon not running" . PHP_EOL; return; } fclose($fpPid); $pid = (int)file_get_contents($pidFile); if ($debug) echo "==> Killing the daemon (PID $pid)..." . PHP_EOL; posix_kill($pid, SIGTERM); pcntl_waitpid($pid, $status); }
php
public function stop() { $options = static::getOptions(); $debug = @$options['debug'] === true; $pidFile = $options['pid_file']; if (!$pidFile) throw new \Exception("No pid_file in the config"); $fpPid = fopen($pidFile, "c"); if (!$fpPid) throw new \Exception("Could not open " . $pidFile); if (flock($fpPid, LOCK_EX | LOCK_NB)) { flock($fpPid, LOCK_UN); fclose($fpPid); if ($debug) echo "==> Daemon not running" . PHP_EOL; return; } fclose($fpPid); $pid = (int)file_get_contents($pidFile); if ($debug) echo "==> Killing the daemon (PID $pid)..." . PHP_EOL; posix_kill($pid, SIGTERM); pcntl_waitpid($pid, $status); }
[ "public", "function", "stop", "(", ")", "{", "$", "options", "=", "static", "::", "getOptions", "(", ")", ";", "$", "debug", "=", "@", "$", "options", "[", "'debug'", "]", "===", "true", ";", "$", "pidFile", "=", "$", "options", "[", "'pid_file'", "]", ";", "if", "(", "!", "$", "pidFile", ")", "throw", "new", "\\", "Exception", "(", "\"No pid_file in the config\"", ")", ";", "$", "fpPid", "=", "fopen", "(", "$", "pidFile", ",", "\"c\"", ")", ";", "if", "(", "!", "$", "fpPid", ")", "throw", "new", "\\", "Exception", "(", "\"Could not open \"", ".", "$", "pidFile", ")", ";", "if", "(", "flock", "(", "$", "fpPid", ",", "LOCK_EX", "|", "LOCK_NB", ")", ")", "{", "flock", "(", "$", "fpPid", ",", "LOCK_UN", ")", ";", "fclose", "(", "$", "fpPid", ")", ";", "if", "(", "$", "debug", ")", "echo", "\"==> Daemon not running\"", ".", "PHP_EOL", ";", "return", ";", "}", "fclose", "(", "$", "fpPid", ")", ";", "$", "pid", "=", "(", "int", ")", "file_get_contents", "(", "$", "pidFile", ")", ";", "if", "(", "$", "debug", ")", "echo", "\"==> Killing the daemon (PID $pid)...\"", ".", "PHP_EOL", ";", "posix_kill", "(", "$", "pid", ",", "SIGTERM", ")", ";", "pcntl_waitpid", "(", "$", "pid", ",", "$", "status", ")", ";", "}" ]
Stop the daemon @return TaskDaemon
[ "Stop", "the", "daemon" ]
d8084e414d87cabe3c3066902da625c6f0ba770b
https://github.com/basarevych/task-daemon/blob/d8084e414d87cabe3c3066902da625c6f0ba770b/library/TaskDaemon/TaskDaemon.php#L358-L386
20,070
basarevych/task-daemon
library/TaskDaemon/TaskDaemon.php
TaskDaemon.restart
public function restart() { if (count($this->tasks) == 0) throw new \Exception("There are no tasks defined - can not restart"); $this->stop(); do { sleep(1); } while ($this->getPid() !== false); $this->start(); }
php
public function restart() { if (count($this->tasks) == 0) throw new \Exception("There are no tasks defined - can not restart"); $this->stop(); do { sleep(1); } while ($this->getPid() !== false); $this->start(); }
[ "public", "function", "restart", "(", ")", "{", "if", "(", "count", "(", "$", "this", "->", "tasks", ")", "==", "0", ")", "throw", "new", "\\", "Exception", "(", "\"There are no tasks defined - can not restart\"", ")", ";", "$", "this", "->", "stop", "(", ")", ";", "do", "{", "sleep", "(", "1", ")", ";", "}", "while", "(", "$", "this", "->", "getPid", "(", ")", "!==", "false", ")", ";", "$", "this", "->", "start", "(", ")", ";", "}" ]
Restart the daemon @return TaskDaemon
[ "Restart", "the", "daemon" ]
d8084e414d87cabe3c3066902da625c6f0ba770b
https://github.com/basarevych/task-daemon/blob/d8084e414d87cabe3c3066902da625c6f0ba770b/library/TaskDaemon/TaskDaemon.php#L393-L405
20,071
PortaText/php-sdk
src/PortaText/Command/Api/Campaigns.php
Campaigns.setSetting
protected function setSetting($name, $value) { $args = $this->getArgument("settings"); if (is_null($args)) { $args = array(); } $args[$name] = $value; return $this->setArgument("settings", $args); }
php
protected function setSetting($name, $value) { $args = $this->getArgument("settings"); if (is_null($args)) { $args = array(); } $args[$name] = $value; return $this->setArgument("settings", $args); }
[ "protected", "function", "setSetting", "(", "$", "name", ",", "$", "value", ")", "{", "$", "args", "=", "$", "this", "->", "getArgument", "(", "\"settings\"", ")", ";", "if", "(", "is_null", "(", "$", "args", ")", ")", "{", "$", "args", "=", "array", "(", ")", ";", "}", "$", "args", "[", "$", "name", "]", "=", "$", "value", ";", "return", "$", "this", "->", "setArgument", "(", "\"settings\"", ",", "$", "args", ")", ";", "}" ]
Set a campaign setting. @param string $name Setting name. @param mixed $value Setting value. @return PortaText\Command\ICommand
[ "Set", "a", "campaign", "setting", "." ]
dbe04ef043db5b251953f9de57aa4d0f1785dfcc
https://github.com/PortaText/php-sdk/blob/dbe04ef043db5b251953f9de57aa4d0f1785dfcc/src/PortaText/Command/Api/Campaigns.php#L222-L230
20,072
benmanu/silverstripe-knowledgebase
code/controller/KnowledgebasePage_Controller.php
KnowledgebasePage_Controller.getSearchQuery
protected function getSearchQuery($keywords) { $query = parent::getSearchQuery($keywords); // add hook to modify search query $this->extend('updateSearchQuery', $query); return $query; }
php
protected function getSearchQuery($keywords) { $query = parent::getSearchQuery($keywords); // add hook to modify search query $this->extend('updateSearchQuery', $query); return $query; }
[ "protected", "function", "getSearchQuery", "(", "$", "keywords", ")", "{", "$", "query", "=", "parent", "::", "getSearchQuery", "(", "$", "keywords", ")", ";", "// add hook to modify search query", "$", "this", "->", "extend", "(", "'updateSearchQuery'", ",", "$", "query", ")", ";", "return", "$", "query", ";", "}" ]
Builds a search query from a given search term. Also has an extension hook which allows you to modify the parameters of the query. @param string $keywords @return SearchQuery
[ "Builds", "a", "search", "query", "from", "a", "given", "search", "term", "." ]
db19bfd4836f43da17ab52e8b53e72a11be64210
https://github.com/benmanu/silverstripe-knowledgebase/blob/db19bfd4836f43da17ab52e8b53e72a11be64210/code/controller/KnowledgebasePage_Controller.php#L34-L42
20,073
benmanu/silverstripe-knowledgebase
code/controller/KnowledgebasePage_Controller.php
KnowledgebasePage_Controller.parseSearchResults
protected function parseSearchResults($results, $suggestion, $keywords) { $renderData = parent::parseSearchResults($results, $suggestion, $keywords); // adding hook to allow checks or additional data to be passed to the Search Results $this->extend('updateParseSearchResults', $renderData); return $renderData; }
php
protected function parseSearchResults($results, $suggestion, $keywords) { $renderData = parent::parseSearchResults($results, $suggestion, $keywords); // adding hook to allow checks or additional data to be passed to the Search Results $this->extend('updateParseSearchResults', $renderData); return $renderData; }
[ "protected", "function", "parseSearchResults", "(", "$", "results", ",", "$", "suggestion", ",", "$", "keywords", ")", "{", "$", "renderData", "=", "parent", "::", "parseSearchResults", "(", "$", "results", ",", "$", "suggestion", ",", "$", "keywords", ")", ";", "// adding hook to allow checks or additional data to be passed to the Search Results", "$", "this", "->", "extend", "(", "'updateParseSearchResults'", ",", "$", "renderData", ")", ";", "return", "$", "renderData", ";", "}" ]
Overloading view method purely to provide a hook for others to add extra checks or pass additional data to the Search Results. @param array $results @param array $suggestion @param string $keywords @return array
[ "Overloading", "view", "method", "purely", "to", "provide", "a", "hook", "for", "others", "to", "add", "extra", "checks", "or", "pass", "additional", "data", "to", "the", "Search", "Results", "." ]
db19bfd4836f43da17ab52e8b53e72a11be64210
https://github.com/benmanu/silverstripe-knowledgebase/blob/db19bfd4836f43da17ab52e8b53e72a11be64210/code/controller/KnowledgebasePage_Controller.php#L70-L78
20,074
phrest/sdk
src/PhrestSDK.php
PhrestSDK.setApp
public function setApp(PhrestAPI $app) { $this->app = $app; $this->app->isInternalRequest = true; return $this; }
php
public function setApp(PhrestAPI $app) { $this->app = $app; $this->app->isInternalRequest = true; return $this; }
[ "public", "function", "setApp", "(", "PhrestAPI", "$", "app", ")", "{", "$", "this", "->", "app", "=", "$", "app", ";", "$", "this", "->", "app", "->", "isInternalRequest", "=", "true", ";", "return", "$", "this", ";", "}" ]
Set the API instance @param PhrestAPI $app @return $this
[ "Set", "the", "API", "instance" ]
e9f2812ad517b07ca4d284512b530f615305eb47
https://github.com/phrest/sdk/blob/e9f2812ad517b07ca4d284512b530f615305eb47/src/PhrestSDK.php#L87-L93
20,075
phrest/sdk
src/PhrestSDK.php
PhrestSDK.getHTTPResponse
private function getHTTPResponse( $method, $path, RequestOptions $options = null ) { $client = new Client(); // Build body $body = new PostBody(); if ($options) { foreach ($options->getPostParams() as $name => $value) { $body->setField($name, $value); } } // Prepare the request $request = new Request( $method, $this->url . $path, [], $body, [] ); // Get response $response = $client->send($request); $body = json_decode($response->getBody()); if (isset($body->data)) { return $body->data; } else { throw new \Exception('Error calling ' . $method . ' to: ' . $path); } }
php
private function getHTTPResponse( $method, $path, RequestOptions $options = null ) { $client = new Client(); // Build body $body = new PostBody(); if ($options) { foreach ($options->getPostParams() as $name => $value) { $body->setField($name, $value); } } // Prepare the request $request = new Request( $method, $this->url . $path, [], $body, [] ); // Get response $response = $client->send($request); $body = json_decode($response->getBody()); if (isset($body->data)) { return $body->data; } else { throw new \Exception('Error calling ' . $method . ' to: ' . $path); } }
[ "private", "function", "getHTTPResponse", "(", "$", "method", ",", "$", "path", ",", "RequestOptions", "$", "options", "=", "null", ")", "{", "$", "client", "=", "new", "Client", "(", ")", ";", "// Build body", "$", "body", "=", "new", "PostBody", "(", ")", ";", "if", "(", "$", "options", ")", "{", "foreach", "(", "$", "options", "->", "getPostParams", "(", ")", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "body", "->", "setField", "(", "$", "name", ",", "$", "value", ")", ";", "}", "}", "// Prepare the request", "$", "request", "=", "new", "Request", "(", "$", "method", ",", "$", "this", "->", "url", ".", "$", "path", ",", "[", "]", ",", "$", "body", ",", "[", "]", ")", ";", "// Get response", "$", "response", "=", "$", "client", "->", "send", "(", "$", "request", ")", ";", "$", "body", "=", "json_decode", "(", "$", "response", "->", "getBody", "(", ")", ")", ";", "if", "(", "isset", "(", "$", "body", "->", "data", ")", ")", "{", "return", "$", "body", "->", "data", ";", "}", "else", "{", "throw", "new", "\\", "Exception", "(", "'Error calling '", ".", "$", "method", ".", "' to: '", ".", "$", "path", ")", ";", "}", "}" ]
Makes a cURL HTTP request to the API and returns the response todo this needs to also handle PUT, POST, DELETE @param string $method @param $path @param RequestOptions $options @throws \Exception @return string
[ "Makes", "a", "cURL", "HTTP", "request", "to", "the", "API", "and", "returns", "the", "response", "todo", "this", "needs", "to", "also", "handle", "PUT", "POST", "DELETE" ]
e9f2812ad517b07ca4d284512b530f615305eb47
https://github.com/phrest/sdk/blob/e9f2812ad517b07ca4d284512b530f615305eb47/src/PhrestSDK.php#L314-L354
20,076
mle86/php-wq
src/WQ/WorkProcessor.php
WorkProcessor.processNextJob
public function processNextJob( $workQueue, callable $callback, int $timeout = WorkServerAdapter::DEFAULT_TIMEOUT ): void { $qe = $this->server->getNextQueueEntry($workQueue, $timeout); if (!$qe) { $this->onNoJobAvailable((array)$workQueue); return; } $job = $qe->getJob(); if ($job->jobIsExpired()) { $this->handleExpiredJob($qe); return; } $this->log(LogLevel::INFO, "got job", $qe); $this->onJobAvailable($qe); $ret = null; try { $ret = $callback($job); } catch (\Throwable $e) { // The job failed. $this->handleFailedJob($qe, $e); if ($this->options[self::WP_RETHROW_EXCEPTIONS]) { // pass exception to caller throw $e; } else { // drop it return; } } switch ($ret ?? JobResult::DEFAULT) { case JobResult::SUCCESS: // The job succeeded! $this->handleFinishedJob($qe); break; case JobResult::FAILED: // The job failed. $this->handleFailedJob($qe); break; default: // We'll assume the job went well. $this->handleFinishedJob($qe); throw new \UnexpectedValueException('unexpected job handler return value, should be JobResult::... or null or void'); } }
php
public function processNextJob( $workQueue, callable $callback, int $timeout = WorkServerAdapter::DEFAULT_TIMEOUT ): void { $qe = $this->server->getNextQueueEntry($workQueue, $timeout); if (!$qe) { $this->onNoJobAvailable((array)$workQueue); return; } $job = $qe->getJob(); if ($job->jobIsExpired()) { $this->handleExpiredJob($qe); return; } $this->log(LogLevel::INFO, "got job", $qe); $this->onJobAvailable($qe); $ret = null; try { $ret = $callback($job); } catch (\Throwable $e) { // The job failed. $this->handleFailedJob($qe, $e); if ($this->options[self::WP_RETHROW_EXCEPTIONS]) { // pass exception to caller throw $e; } else { // drop it return; } } switch ($ret ?? JobResult::DEFAULT) { case JobResult::SUCCESS: // The job succeeded! $this->handleFinishedJob($qe); break; case JobResult::FAILED: // The job failed. $this->handleFailedJob($qe); break; default: // We'll assume the job went well. $this->handleFinishedJob($qe); throw new \UnexpectedValueException('unexpected job handler return value, should be JobResult::... or null or void'); } }
[ "public", "function", "processNextJob", "(", "$", "workQueue", ",", "callable", "$", "callback", ",", "int", "$", "timeout", "=", "WorkServerAdapter", "::", "DEFAULT_TIMEOUT", ")", ":", "void", "{", "$", "qe", "=", "$", "this", "->", "server", "->", "getNextQueueEntry", "(", "$", "workQueue", ",", "$", "timeout", ")", ";", "if", "(", "!", "$", "qe", ")", "{", "$", "this", "->", "onNoJobAvailable", "(", "(", "array", ")", "$", "workQueue", ")", ";", "return", ";", "}", "$", "job", "=", "$", "qe", "->", "getJob", "(", ")", ";", "if", "(", "$", "job", "->", "jobIsExpired", "(", ")", ")", "{", "$", "this", "->", "handleExpiredJob", "(", "$", "qe", ")", ";", "return", ";", "}", "$", "this", "->", "log", "(", "LogLevel", "::", "INFO", ",", "\"got job\"", ",", "$", "qe", ")", ";", "$", "this", "->", "onJobAvailable", "(", "$", "qe", ")", ";", "$", "ret", "=", "null", ";", "try", "{", "$", "ret", "=", "$", "callback", "(", "$", "job", ")", ";", "}", "catch", "(", "\\", "Throwable", "$", "e", ")", "{", "// The job failed.", "$", "this", "->", "handleFailedJob", "(", "$", "qe", ",", "$", "e", ")", ";", "if", "(", "$", "this", "->", "options", "[", "self", "::", "WP_RETHROW_EXCEPTIONS", "]", ")", "{", "// pass exception to caller", "throw", "$", "e", ";", "}", "else", "{", "// drop it", "return", ";", "}", "}", "switch", "(", "$", "ret", "??", "JobResult", "::", "DEFAULT", ")", "{", "case", "JobResult", "::", "SUCCESS", ":", "// The job succeeded!", "$", "this", "->", "handleFinishedJob", "(", "$", "qe", ")", ";", "break", ";", "case", "JobResult", "::", "FAILED", ":", "// The job failed.", "$", "this", "->", "handleFailedJob", "(", "$", "qe", ")", ";", "break", ";", "default", ":", "// We'll assume the job went well.", "$", "this", "->", "handleFinishedJob", "(", "$", "qe", ")", ";", "throw", "new", "\\", "UnexpectedValueException", "(", "'unexpected job handler return value, should be JobResult::... or null or void'", ")", ";", "}", "}" ]
Executes the next job in the Work Queue by passing it to the callback function. If that results in a {@see \RuntimeException}, the method will try to re-queue the job and re-throw the exception. If the execution results in any other {@see \Throwable}, no re-queueing will be attempted; the job will be buried immediately. If the next job in the Work Queue is expired, it will be silently deleted. @param string|string[] $workQueue See {@see WorkServerAdapter::getNextJob()}. @param callable $callback The handler callback to execute each Job. Expected signature: <tt>function(Job): ?int|void</tt>. See {@see JobResult} for possible return values. @param int $timeout See {@see WorkServerAdapter::getNextJob()}. @throws \Throwable Will re-throw on any Exceptions/Throwables from the <tt>$callback</tt>. @throws \UnexpectedValueException in case of an unexpected callback return value (should be a {@see JobResult} constant or NULL or void).
[ "Executes", "the", "next", "job", "in", "the", "Work", "Queue", "by", "passing", "it", "to", "the", "callback", "function", "." ]
e1ca1dcfd3d40edb0085f6dfa83d90db74253de4
https://github.com/mle86/php-wq/blob/e1ca1dcfd3d40edb0085f6dfa83d90db74253de4/src/WQ/WorkProcessor.php#L78-L129
20,077
mle86/php-wq
src/WQ/WorkProcessor.php
WorkProcessor.setOption
public function setOption(int $option, $value): self { $this->options[$option] = $value; return $this; }
php
public function setOption(int $option, $value): self { $this->options[$option] = $value; return $this; }
[ "public", "function", "setOption", "(", "int", "$", "option", ",", "$", "value", ")", ":", "self", "{", "$", "this", "->", "options", "[", "$", "option", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
Sets one of the configuration options. @param int $option One of the <tt>WP_</tt> constants. @param mixed $value The option's new value. The required type depends on the option. @see setOptions() to change multiple options at once. @return self
[ "Sets", "one", "of", "the", "configuration", "options", "." ]
e1ca1dcfd3d40edb0085f6dfa83d90db74253de4
https://github.com/mle86/php-wq/blob/e1ca1dcfd3d40edb0085f6dfa83d90db74253de4/src/WQ/WorkProcessor.php#L286-L290
20,078
haldayne/boost
src/Map.php
Map.keys
public function keys() { $map = new Map; foreach (array_keys($this->array) as $hash) { $map[] = $this->hash_to_key($hash); } return $map; }
php
public function keys() { $map = new Map; foreach (array_keys($this->array) as $hash) { $map[] = $this->hash_to_key($hash); } return $map; }
[ "public", "function", "keys", "(", ")", "{", "$", "map", "=", "new", "Map", ";", "foreach", "(", "array_keys", "(", "$", "this", "->", "array", ")", "as", "$", "hash", ")", "{", "$", "map", "[", "]", "=", "$", "this", "->", "hash_to_key", "(", "$", "hash", ")", ";", "}", "return", "$", "map", ";", "}" ]
Get the keys of this map as a new map. @return new Map @api @since 1.0.5
[ "Get", "the", "keys", "of", "this", "map", "as", "a", "new", "map", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L85-L92
20,079
haldayne/boost
src/Map.php
Map.filter
public function filter($expression) { $new = new static; $this->walk(function ($v, $k) use ($expression, $new) { $result = $this->call($expression, $v, $k); if ($this->passes($result)) { $new[$k] = $v; } }); return $new; }
php
public function filter($expression) { $new = new static; $this->walk(function ($v, $k) use ($expression, $new) { $result = $this->call($expression, $v, $k); if ($this->passes($result)) { $new[$k] = $v; } }); return $new; }
[ "public", "function", "filter", "(", "$", "expression", ")", "{", "$", "new", "=", "new", "static", ";", "$", "this", "->", "walk", "(", "function", "(", "$", "v", ",", "$", "k", ")", "use", "(", "$", "expression", ",", "$", "new", ")", "{", "$", "result", "=", "$", "this", "->", "call", "(", "$", "expression", ",", "$", "v", ",", "$", "k", ")", ";", "if", "(", "$", "this", "->", "passes", "(", "$", "result", ")", ")", "{", "$", "new", "[", "$", "k", "]", "=", "$", "v", ";", "}", "}", ")", ";", "return", "$", "new", ";", "}" ]
Apply the filter to every element, creating a new map with only those elements from the original map that do not fail this filter. The filter expressions receives two arguments: - The current value - The current key If the filter returns exactly boolean false, the element is not copied into the new map. Otherwise, it is. Keys from the original map carry into the new map. @param callable|string $expression @return new static @api
[ "Apply", "the", "filter", "to", "every", "element", "creating", "a", "new", "map", "with", "only", "those", "elements", "from", "the", "original", "map", "that", "do", "not", "fail", "this", "filter", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L133-L145
20,080
haldayne/boost
src/Map.php
Map.first
public function first($expression, $n = 1) { if (is_numeric($n) && intval($n) <= 0) { throw new \InvalidArgumentException('Argument $n must be whole number'); } return $this->grep($expression, intval($n)); }
php
public function first($expression, $n = 1) { if (is_numeric($n) && intval($n) <= 0) { throw new \InvalidArgumentException('Argument $n must be whole number'); } return $this->grep($expression, intval($n)); }
[ "public", "function", "first", "(", "$", "expression", ",", "$", "n", "=", "1", ")", "{", "if", "(", "is_numeric", "(", "$", "n", ")", "&&", "intval", "(", "$", "n", ")", "<=", "0", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Argument $n must be whole number'", ")", ";", "}", "return", "$", "this", "->", "grep", "(", "$", "expression", ",", "intval", "(", "$", "n", ")", ")", ";", "}" ]
Return a new map containing the first N elements passing the expression. Like `find`, but stop after finding N elements from the front. Defaults to N = 1. ``` $nums = new Map(range(0, 9)); $odd3 = $nums->first('1 == ($_0 % 2)', 3); // first three odds ``` @param callable|string $expression @param int $n @return new static @api
[ "Return", "a", "new", "map", "containing", "the", "first", "N", "elements", "passing", "the", "expression", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L164-L170
20,081
haldayne/boost
src/Map.php
Map.last
public function last($expression, $n = 1) { if (is_numeric($n) && intval($n) <= 0) { throw new \InvalidArgumentException('Argument $n must be whole number'); } return $this->grep($expression, -intval($n)); }
php
public function last($expression, $n = 1) { if (is_numeric($n) && intval($n) <= 0) { throw new \InvalidArgumentException('Argument $n must be whole number'); } return $this->grep($expression, -intval($n)); }
[ "public", "function", "last", "(", "$", "expression", ",", "$", "n", "=", "1", ")", "{", "if", "(", "is_numeric", "(", "$", "n", ")", "&&", "intval", "(", "$", "n", ")", "<=", "0", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Argument $n must be whole number'", ")", ";", "}", "return", "$", "this", "->", "grep", "(", "$", "expression", ",", "-", "intval", "(", "$", "n", ")", ")", ";", "}" ]
Return a new map containing the last N elements passing the expression. Like `first`, but stop after finding N elements from the *end*. Defaults to N = 1. ``` $nums = new Map(range(0, 9)); $odds = $nums->last('1 == ($_0 % 2)', 2); // last two odd numbers ``` @param callable|string $expression @param int $n @return new static @api
[ "Return", "a", "new", "map", "containing", "the", "last", "N", "elements", "passing", "the", "expression", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L188-L194
20,082
haldayne/boost
src/Map.php
Map.get
public function get($key, $default = null) { $hash = $this->key_to_hash($key); if (array_key_exists($hash, $this->array)) { return $this->array[$hash]; } else { return $default; } }
php
public function get($key, $default = null) { $hash = $this->key_to_hash($key); if (array_key_exists($hash, $this->array)) { return $this->array[$hash]; } else { return $default; } }
[ "public", "function", "get", "(", "$", "key", ",", "$", "default", "=", "null", ")", "{", "$", "hash", "=", "$", "this", "->", "key_to_hash", "(", "$", "key", ")", ";", "if", "(", "array_key_exists", "(", "$", "hash", ",", "$", "this", "->", "array", ")", ")", "{", "return", "$", "this", "->", "array", "[", "$", "hash", "]", ";", "}", "else", "{", "return", "$", "default", ";", "}", "}" ]
Get the value corresponding to the given key. If the key does not exist in the map, return the default. This is the object method equivalent of the magic $map[$key]. @param mixed $key @param mixed $default @return mixed @api
[ "Get", "the", "value", "corresponding", "to", "the", "given", "key", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L259-L267
20,083
haldayne/boost
src/Map.php
Map.set
public function set($key, $value) { $hash = $this->key_to_hash($key); $this->array[$hash] = $value; return $this; }
php
public function set($key, $value) { $hash = $this->key_to_hash($key); $this->array[$hash] = $value; return $this; }
[ "public", "function", "set", "(", "$", "key", ",", "$", "value", ")", "{", "$", "hash", "=", "$", "this", "->", "key_to_hash", "(", "$", "key", ")", ";", "$", "this", "->", "array", "[", "$", "hash", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
Set a key and its corresponding value into the map. This is the object method equivalent of the magic $map[$key] = 'foo'. @param mixed $key @param mixed $value @return $this @api
[ "Set", "a", "key", "and", "its", "corresponding", "value", "into", "the", "map", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L279-L284
20,084
haldayne/boost
src/Map.php
Map.diff
public function diff($collection, $comparison = Map::LOOSE) { $func = ($comparison === Map::LOOSE ? 'array_diff' : 'array_diff_assoc'); return new static( $func($this->toArray(), $this->collection_to_array($collection)) ); }
php
public function diff($collection, $comparison = Map::LOOSE) { $func = ($comparison === Map::LOOSE ? 'array_diff' : 'array_diff_assoc'); return new static( $func($this->toArray(), $this->collection_to_array($collection)) ); }
[ "public", "function", "diff", "(", "$", "collection", ",", "$", "comparison", "=", "Map", "::", "LOOSE", ")", "{", "$", "func", "=", "(", "$", "comparison", "===", "Map", "::", "LOOSE", "?", "'array_diff'", ":", "'array_diff_assoc'", ")", ";", "return", "new", "static", "(", "$", "func", "(", "$", "this", "->", "toArray", "(", ")", ",", "$", "this", "->", "collection_to_array", "(", "$", "collection", ")", ")", ")", ";", "}" ]
Return a new map containing those keys and values that are not present in the given collection. If comparison is loose, then only those elements whose values match will be removed. Otherwise, comparison is strict, and elements whose keys and values match will be removed. @param Map|Arrayable|Jsonable|Traversable|object|array $collection @param enum $comparison @return new static @api
[ "Return", "a", "new", "map", "containing", "those", "keys", "and", "values", "that", "are", "not", "present", "in", "the", "given", "collection", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L325-L331
20,085
haldayne/boost
src/Map.php
Map.partition
public function partition($expression) { $outer = new MapOfCollections; $proto = new static; $this->walk(function ($v, $k) use ($expression, $outer, $proto) { $partition = $this->call($expression, $v, $k); $inner = $outer->has($partition) ? $outer->get($partition) : clone $proto; $inner->set($k, $v); $outer->set($partition, $inner); }); return $outer; }
php
public function partition($expression) { $outer = new MapOfCollections; $proto = new static; $this->walk(function ($v, $k) use ($expression, $outer, $proto) { $partition = $this->call($expression, $v, $k); $inner = $outer->has($partition) ? $outer->get($partition) : clone $proto; $inner->set($k, $v); $outer->set($partition, $inner); }); return $outer; }
[ "public", "function", "partition", "(", "$", "expression", ")", "{", "$", "outer", "=", "new", "MapOfCollections", ";", "$", "proto", "=", "new", "static", ";", "$", "this", "->", "walk", "(", "function", "(", "$", "v", ",", "$", "k", ")", "use", "(", "$", "expression", ",", "$", "outer", ",", "$", "proto", ")", "{", "$", "partition", "=", "$", "this", "->", "call", "(", "$", "expression", ",", "$", "v", ",", "$", "k", ")", ";", "$", "inner", "=", "$", "outer", "->", "has", "(", "$", "partition", ")", "?", "$", "outer", "->", "get", "(", "$", "partition", ")", ":", "clone", "$", "proto", ";", "$", "inner", "->", "set", "(", "$", "k", ",", "$", "v", ")", ";", "$", "outer", "->", "set", "(", "$", "partition", ",", "$", "inner", ")", ";", "}", ")", ";", "return", "$", "outer", ";", "}" ]
Groups elements of this map based on the result of an expression. Calls the expression for each element in this map. The expression receives the value and key, respectively. The expression may return any value: this value is the grouping key and the element is put into that group. ``` $nums = new Map(range(0, 9)); $part = $nums->partition(function ($value, $key) { return 0 == $value % 2 ? 'even' : 'odd'; }); var_dump( $part['odd']->count(), // 5 array_sum($part['even']->toArray()) // 20 ); ``` @param callable|string $expression @return MapOfCollections @api
[ "Groups", "elements", "of", "this", "map", "based", "on", "the", "result", "of", "an", "expression", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L377-L392
20,086
haldayne/boost
src/Map.php
Map.map
public function map($expression) { $new = new self; $this->walk(function ($v, $k) use ($expression, $new) { $new[$k] = $this->call($expression, $v, $k); }); return $new; }
php
public function map($expression) { $new = new self; $this->walk(function ($v, $k) use ($expression, $new) { $new[$k] = $this->call($expression, $v, $k); }); return $new; }
[ "public", "function", "map", "(", "$", "expression", ")", "{", "$", "new", "=", "new", "self", ";", "$", "this", "->", "walk", "(", "function", "(", "$", "v", ",", "$", "k", ")", "use", "(", "$", "expression", ",", "$", "new", ")", "{", "$", "new", "[", "$", "k", "]", "=", "$", "this", "->", "call", "(", "$", "expression", ",", "$", "v", ",", "$", "k", ")", ";", "}", ")", ";", "return", "$", "new", ";", "}" ]
Walk the map, applying the expression to every element, transforming them into a new map. ``` $nums = new Map(range(0, 9)); $doubled = $nums->map('$_0 * 2'); ``` The expression receives two arguments: - The current value in `$_0` - The current key in `$_1` The keys in the resulting map will be the same as the keys in the original map: only the values have (potentially) changed. Recommended to use this method when you are mapping from one type to the same type: int to int, string to string, etc. If you are changing types, use the more powerful `transform` method. @param callable|string $expression @return Map @api
[ "Walk", "the", "map", "applying", "the", "expression", "to", "every", "element", "transforming", "them", "into", "a", "new", "map", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L418-L427
20,087
haldayne/boost
src/Map.php
Map.reduce
public function reduce($reducer, $initial = null, $finisher = null) { $reduced = $initial; $this->walk(function ($value, $key) use ($reducer, &$reduced) { $reduced = $this->call($reducer, $reduced, $value, $key); }); if (null === $finisher) { return $reduced; } else { return $this->call($finisher, $reduced); } }
php
public function reduce($reducer, $initial = null, $finisher = null) { $reduced = $initial; $this->walk(function ($value, $key) use ($reducer, &$reduced) { $reduced = $this->call($reducer, $reduced, $value, $key); }); if (null === $finisher) { return $reduced; } else { return $this->call($finisher, $reduced); } }
[ "public", "function", "reduce", "(", "$", "reducer", ",", "$", "initial", "=", "null", ",", "$", "finisher", "=", "null", ")", "{", "$", "reduced", "=", "$", "initial", ";", "$", "this", "->", "walk", "(", "function", "(", "$", "value", ",", "$", "key", ")", "use", "(", "$", "reducer", ",", "&", "$", "reduced", ")", "{", "$", "reduced", "=", "$", "this", "->", "call", "(", "$", "reducer", ",", "$", "reduced", ",", "$", "value", ",", "$", "key", ")", ";", "}", ")", ";", "if", "(", "null", "===", "$", "finisher", ")", "{", "return", "$", "reduced", ";", "}", "else", "{", "return", "$", "this", "->", "call", "(", "$", "finisher", ",", "$", "reduced", ")", ";", "}", "}" ]
Walk the map, applying a reducing expression to every element, so as to reduce the map to a single value. The `$reducer` expression receives three arguments: - The current reduction (`$_0`) - The current value (`$_1`) - The current key (`$_2`) The initial value, if given or null if not, is passed as the current reduction on the first invocation of `$reducer`. The return value from `$reducer` then becomes the new, current reduced value. ``` $nums = new Map(range(0, 3)); $sum = $nums->reduce('$_0 + $_1'); // $sum == 6 ``` If `$finisher` is a callable or string expression, then it will be called last, after iterating over all elements. It will be passed reduced value. The `$finisher` must return the new final value. @param callable|string $reducer @param mixed $initial @param callable|string|null $finisher @return mixed @api @see http://php.net/manual/en/function.array-reduce.php
[ "Walk", "the", "map", "applying", "a", "reducing", "expression", "to", "every", "element", "so", "as", "to", "reduce", "the", "map", "to", "a", "single", "value", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L460-L472
20,088
haldayne/boost
src/Map.php
Map.rekey
public function rekey($expression) { $new = new static; $this->walk(function ($v, $k) use ($expression, $new) { $new_key = $this->call($expression, $v, $k); $new[$new_key] = $v; }); return $new; }
php
public function rekey($expression) { $new = new static; $this->walk(function ($v, $k) use ($expression, $new) { $new_key = $this->call($expression, $v, $k); $new[$new_key] = $v; }); return $new; }
[ "public", "function", "rekey", "(", "$", "expression", ")", "{", "$", "new", "=", "new", "static", ";", "$", "this", "->", "walk", "(", "function", "(", "$", "v", ",", "$", "k", ")", "use", "(", "$", "expression", ",", "$", "new", ")", "{", "$", "new_key", "=", "$", "this", "->", "call", "(", "$", "expression", ",", "$", "v", ",", "$", "k", ")", ";", "$", "new", "[", "$", "new_key", "]", "=", "$", "v", ";", "}", ")", ";", "return", "$", "new", ";", "}" ]
Change the key for every element in the map using an expression to calculate the new key. ``` $keyed_by_bytecode = new Map(count_chars('war of the worlds', 1)); $keyed_by_letter = $keyed_by_bytecode->rekey('chr($_1)'); ``` @param callable|string $expression @return new static @api
[ "Change", "the", "key", "for", "every", "element", "in", "the", "map", "using", "an", "expression", "to", "calculate", "the", "new", "key", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L487-L497
20,089
haldayne/boost
src/Map.php
Map.merge
public function merge($collection, callable $merger, $default = null) { $array = $this->collection_to_array($collection); foreach ($array as $key => $value) { $current = $this->get($key, $default); $this->set($key, $merger($current, $value)); } return $this; }
php
public function merge($collection, callable $merger, $default = null) { $array = $this->collection_to_array($collection); foreach ($array as $key => $value) { $current = $this->get($key, $default); $this->set($key, $merger($current, $value)); } return $this; }
[ "public", "function", "merge", "(", "$", "collection", ",", "callable", "$", "merger", ",", "$", "default", "=", "null", ")", "{", "$", "array", "=", "$", "this", "->", "collection_to_array", "(", "$", "collection", ")", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "current", "=", "$", "this", "->", "get", "(", "$", "key", ",", "$", "default", ")", ";", "$", "this", "->", "set", "(", "$", "key", ",", "$", "merger", "(", "$", "current", ",", "$", "value", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Merge the given collection into this map. The merger callable decides how to merge the current map's value with the given collection's value. The merger callable receives two arguments: - This map's value at the given key - The collection's value at the given key If the current map does not have a value for a key in the collection, then the default value is assumed. @param Map|Arrayable|Jsonable|Traversable|object|array $collection @param callable $merger @param mixed $default @return $this @api
[ "Merge", "the", "given", "collection", "into", "this", "map", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L517-L525
20,090
haldayne/boost
src/Map.php
Map.transform
public function transform(callable $transformer, callable $creator = null, callable $finisher = null) { // create the initial object, using as needed the default creator function if (null === $creator) { $creator = function (Map $original) { return new Map(); }; } $initial = $creator($this); // transform the initial value using the transformer $this->walk(function ($value, $key) use ($transformer, &$initial) { $transformer($initial, $value, $key); }); // finish up if (null === $finisher) { return $initial; } else { return $finisher($initial); } }
php
public function transform(callable $transformer, callable $creator = null, callable $finisher = null) { // create the initial object, using as needed the default creator function if (null === $creator) { $creator = function (Map $original) { return new Map(); }; } $initial = $creator($this); // transform the initial value using the transformer $this->walk(function ($value, $key) use ($transformer, &$initial) { $transformer($initial, $value, $key); }); // finish up if (null === $finisher) { return $initial; } else { return $finisher($initial); } }
[ "public", "function", "transform", "(", "callable", "$", "transformer", ",", "callable", "$", "creator", "=", "null", ",", "callable", "$", "finisher", "=", "null", ")", "{", "// create the initial object, using as needed the default creator function", "if", "(", "null", "===", "$", "creator", ")", "{", "$", "creator", "=", "function", "(", "Map", "$", "original", ")", "{", "return", "new", "Map", "(", ")", ";", "}", ";", "}", "$", "initial", "=", "$", "creator", "(", "$", "this", ")", ";", "// transform the initial value using the transformer", "$", "this", "->", "walk", "(", "function", "(", "$", "value", ",", "$", "key", ")", "use", "(", "$", "transformer", ",", "&", "$", "initial", ")", "{", "$", "transformer", "(", "$", "initial", ",", "$", "value", ",", "$", "key", ")", ";", "}", ")", ";", "// finish up", "if", "(", "null", "===", "$", "finisher", ")", "{", "return", "$", "initial", ";", "}", "else", "{", "return", "$", "finisher", "(", "$", "initial", ")", ";", "}", "}" ]
Flexibly and thoroughly change this map into another map. ``` // transform a word list into a map of word to frequency in the list use Haldayne\Boost\Map; $words = new Map([ 'bear', 'bee', 'goose', 'bee' ]); $lengths = $words->transform( function (Map $new, $word) { if ($new->has($word)) { $new->set($word, $new->get($word)+1); } else { $new->set($word, 1); } } ); ``` Sometimes you need to create one map from another using a strategy that isn't one-to-one. You may need to change keys. You may need to add multiple elements. You may need to delete elements. You may need to change from a map to a number. Whatever the case, the other simpler methods in Map don't quite fit the problem. What you need, and what this method provides, is a complete machine to transform this map into something else: ``` // convert a word list into a count of unique letters in those words use Haldayne\Boost\Map; $words = new Map([ 'bear', 'bee', 'goose', 'bee' ]); $letters = $words->transform( function ($frequencies, $word) { foreach (count_chars($word, 1) as $byte => $frequency) { $letter = chr($byte); if ($frequencies->has($letter)) { $new->set($letter, $frequencies->get($letter)+1); } else { $new->set($letter, 1); } } }, function (Map $original) { return new MapOfIntegers(); }, function (MapOfIntegers $new) { return $new->sum(); } ); ``` This method accepts three callables 1. `$creator`, which is called first with the current map, performs any initialization needed. The result of this callable will be passed to all the other callables. If no creator is given, then use a default one that returns an empty Map. 2. `$transformer`, which is called for every element in this map and receives the initialized value, the current value, and the current key in that order. The transformer should modify the initialized value appropriately. Often this means adding to a new map zero or more tranformed values. 3. `$finisher`, which is called last, receives the initialized value that was modified by the transformer calls. The finisher may transform that value once more as needed. If no finisher given, then no finishing step is made. @param callable $tranformer @param callable|null $creator @param callable|null $finisher @return mixed @api
[ "Flexibly", "and", "thoroughly", "change", "this", "map", "into", "another", "map", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L597-L616
20,091
haldayne/boost
src/Map.php
Map.into
public function into(Map $target) { $this->walk(function ($value, $key) use ($target) { $target->set($key, $value); }); return $target; }
php
public function into(Map $target) { $this->walk(function ($value, $key) use ($target) { $target->set($key, $value); }); return $target; }
[ "public", "function", "into", "(", "Map", "$", "target", ")", "{", "$", "this", "->", "walk", "(", "function", "(", "$", "value", ",", "$", "key", ")", "use", "(", "$", "target", ")", "{", "$", "target", "->", "set", "(", "$", "key", ",", "$", "value", ")", ";", "}", ")", ";", "return", "$", "target", ";", "}" ]
Put all of this map's elements into the target and return the target. ``` $words = new MapOfStrings([ 'foo', 'bar' ]); $words->map('strlen($_0)')->into(new MapOfInts)->sum(); // 6 ``` Use when you've mapped your elements into a different type, and you want to fluently perform operations on the new type. In the example, the sum of the words' lengths was calculated. @return $target @api
[ "Put", "all", "of", "this", "map", "s", "elements", "into", "the", "target", "and", "return", "the", "target", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L633-L639
20,092
haldayne/boost
src/Map.php
Map.push
public function push($element) { // ask PHP to give me the next index // http://stackoverflow.com/q/3698743/2908724 $this->array[] = 'probe'; end($this->array); $next = key($this->array); unset($this->array[$next]); // hash that and store $this->set($next, $element); return $this; }
php
public function push($element) { // ask PHP to give me the next index // http://stackoverflow.com/q/3698743/2908724 $this->array[] = 'probe'; end($this->array); $next = key($this->array); unset($this->array[$next]); // hash that and store $this->set($next, $element); return $this; }
[ "public", "function", "push", "(", "$", "element", ")", "{", "// ask PHP to give me the next index", "// http://stackoverflow.com/q/3698743/2908724", "$", "this", "->", "array", "[", "]", "=", "'probe'", ";", "end", "(", "$", "this", "->", "array", ")", ";", "$", "next", "=", "key", "(", "$", "this", "->", "array", ")", ";", "unset", "(", "$", "this", "->", "array", "[", "$", "next", "]", ")", ";", "// hash that and store", "$", "this", "->", "set", "(", "$", "next", ",", "$", "element", ")", ";", "return", "$", "this", ";", "}" ]
Treat the map as a stack and push an element onto its end. @return $this @api
[ "Treat", "the", "map", "as", "a", "stack", "and", "push", "an", "element", "onto", "its", "end", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L647-L660
20,093
haldayne/boost
src/Map.php
Map.pop
public function pop() { if (0 === count($this->array)) { return null; } // get the last hash of array end($this->array); $hash = key($this->array); // temporarily hold the element at that spot $element = $this->array[$hash]; // forget it in our map and return our temporary $this->forget($this->hash_to_key($hash)); return $element; }
php
public function pop() { if (0 === count($this->array)) { return null; } // get the last hash of array end($this->array); $hash = key($this->array); // temporarily hold the element at that spot $element = $this->array[$hash]; // forget it in our map and return our temporary $this->forget($this->hash_to_key($hash)); return $element; }
[ "public", "function", "pop", "(", ")", "{", "if", "(", "0", "===", "count", "(", "$", "this", "->", "array", ")", ")", "{", "return", "null", ";", "}", "// get the last hash of array", "end", "(", "$", "this", "->", "array", ")", ";", "$", "hash", "=", "key", "(", "$", "this", "->", "array", ")", ";", "// temporarily hold the element at that spot", "$", "element", "=", "$", "this", "->", "array", "[", "$", "hash", "]", ";", "// forget it in our map and return our temporary", "$", "this", "->", "forget", "(", "$", "this", "->", "hash_to_key", "(", "$", "hash", ")", ")", ";", "return", "$", "element", ";", "}" ]
Treat the map as a stack and pop an element off its end. @return mixed|null @api
[ "Treat", "the", "map", "as", "a", "stack", "and", "pop", "an", "element", "off", "its", "end", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L668-L685
20,094
haldayne/boost
src/Map.php
Map.toArray
public function toArray() { $array = []; foreach ($this->array as $hash => $value) { $key = $this->hash_to_key($hash); if ($this->is_collection_like($value)) { $array[$key] = $this->collection_to_array($value); } else { $array[$key] = $value; } } return $array; }
php
public function toArray() { $array = []; foreach ($this->array as $hash => $value) { $key = $this->hash_to_key($hash); if ($this->is_collection_like($value)) { $array[$key] = $this->collection_to_array($value); } else { $array[$key] = $value; } } return $array; }
[ "public", "function", "toArray", "(", ")", "{", "$", "array", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "array", "as", "$", "hash", "=>", "$", "value", ")", "{", "$", "key", "=", "$", "this", "->", "hash_to_key", "(", "$", "hash", ")", ";", "if", "(", "$", "this", "->", "is_collection_like", "(", "$", "value", ")", ")", "{", "$", "array", "[", "$", "key", "]", "=", "$", "this", "->", "collection_to_array", "(", "$", "value", ")", ";", "}", "else", "{", "$", "array", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "array", ";", "}" ]
Copy this map into an array, recursing as necessary to convert contained collections into arrays. @api
[ "Copy", "this", "map", "into", "an", "array", "recursing", "as", "necessary", "to", "convert", "contained", "collections", "into", "arrays", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L710-L722
20,095
haldayne/boost
src/Map.php
Map.offsetSet
public function offsetSet($key, $value) { if (null === $key) { $this->push($value); } else { $this->set($key, $value); } }
php
public function offsetSet($key, $value) { if (null === $key) { $this->push($value); } else { $this->set($key, $value); } }
[ "public", "function", "offsetSet", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "null", "===", "$", "key", ")", "{", "$", "this", "->", "push", "(", "$", "value", ")", ";", "}", "else", "{", "$", "this", "->", "set", "(", "$", "key", ",", "$", "value", ")", ";", "}", "}" ]
Set the value at a given key. If key is null, the value is appended to the array using numeric indexes, just like native PHP. Unlike native-PHP, $key can be of any type: boolean, int, float, string, array, object, closure, resource. @param mixed $key @param mixed $value @return void
[ "Set", "the", "value", "at", "a", "given", "key", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L773-L780
20,096
haldayne/boost
src/Map.php
Map.getIterator
public function getIterator() { $keys = $this->keys(); $count = count($keys); $index = 0; while ($index < $count) { $key = $keys[$index]; $value = $this->get($key); yield $key => $value; $index++; } }
php
public function getIterator() { $keys = $this->keys(); $count = count($keys); $index = 0; while ($index < $count) { $key = $keys[$index]; $value = $this->get($key); yield $key => $value; $index++; } }
[ "public", "function", "getIterator", "(", ")", "{", "$", "keys", "=", "$", "this", "->", "keys", "(", ")", ";", "$", "count", "=", "count", "(", "$", "keys", ")", ";", "$", "index", "=", "0", ";", "while", "(", "$", "index", "<", "$", "count", ")", "{", "$", "key", "=", "$", "keys", "[", "$", "index", "]", ";", "$", "value", "=", "$", "this", "->", "get", "(", "$", "key", ")", ";", "yield", "$", "key", "=>", "$", "value", ";", "$", "index", "++", ";", "}", "}" ]
Get an iterator for the map. @return \Generator @api
[ "Get", "an", "iterator", "for", "the", "map", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L802-L816
20,097
haldayne/boost
src/Map.php
Map.is_collection_like
protected function is_collection_like($value) { if ($value instanceof self) { return true; } else if ($value instanceof \Traversable) { return true; } else if ($value instanceof Arrayable) { return true; } else if ($value instanceof Jsonable) { return true; } else if (is_object($value) || is_array($value)) { return true; } else { return false; } }
php
protected function is_collection_like($value) { if ($value instanceof self) { return true; } else if ($value instanceof \Traversable) { return true; } else if ($value instanceof Arrayable) { return true; } else if ($value instanceof Jsonable) { return true; } else if (is_object($value) || is_array($value)) { return true; } else { return false; } }
[ "protected", "function", "is_collection_like", "(", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "self", ")", "{", "return", "true", ";", "}", "else", "if", "(", "$", "value", "instanceof", "\\", "Traversable", ")", "{", "return", "true", ";", "}", "else", "if", "(", "$", "value", "instanceof", "Arrayable", ")", "{", "return", "true", ";", "}", "else", "if", "(", "$", "value", "instanceof", "Jsonable", ")", "{", "return", "true", ";", "}", "else", "if", "(", "is_object", "(", "$", "value", ")", "||", "is_array", "(", "$", "value", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Decide if the given value is considered collection-like. @param mixed $value @return bool
[ "Decide", "if", "the", "given", "value", "is", "considered", "collection", "-", "like", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L844-L864
20,098
haldayne/boost
src/Map.php
Map.collection_to_array
protected function collection_to_array($collection) { if ($collection instanceof self) { return $collection->toArray(); } else if ($collection instanceof \Traversable) { return iterator_to_array($collection); } else if ($collection instanceof Arrayable) { return $collection->toArray(); } else if ($collection instanceof Jsonable) { return json_decode($collection->toJson(), true); } else if (is_object($collection) || is_array($collection)) { return (array)$collection; } else { throw new \InvalidArgumentException(sprintf( '$collection has type %s, which is not collection-like', gettype($collection) )); } }
php
protected function collection_to_array($collection) { if ($collection instanceof self) { return $collection->toArray(); } else if ($collection instanceof \Traversable) { return iterator_to_array($collection); } else if ($collection instanceof Arrayable) { return $collection->toArray(); } else if ($collection instanceof Jsonable) { return json_decode($collection->toJson(), true); } else if (is_object($collection) || is_array($collection)) { return (array)$collection; } else { throw new \InvalidArgumentException(sprintf( '$collection has type %s, which is not collection-like', gettype($collection) )); } }
[ "protected", "function", "collection_to_array", "(", "$", "collection", ")", "{", "if", "(", "$", "collection", "instanceof", "self", ")", "{", "return", "$", "collection", "->", "toArray", "(", ")", ";", "}", "else", "if", "(", "$", "collection", "instanceof", "\\", "Traversable", ")", "{", "return", "iterator_to_array", "(", "$", "collection", ")", ";", "}", "else", "if", "(", "$", "collection", "instanceof", "Arrayable", ")", "{", "return", "$", "collection", "->", "toArray", "(", ")", ";", "}", "else", "if", "(", "$", "collection", "instanceof", "Jsonable", ")", "{", "return", "json_decode", "(", "$", "collection", "->", "toJson", "(", ")", ",", "true", ")", ";", "}", "else", "if", "(", "is_object", "(", "$", "collection", ")", "||", "is_array", "(", "$", "collection", ")", ")", "{", "return", "(", "array", ")", "$", "collection", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'$collection has type %s, which is not collection-like'", ",", "gettype", "(", "$", "collection", ")", ")", ")", ";", "}", "}" ]
Give me a native PHP array, regardless of what kind of collection-like structure is given. @param Map|Traversable|Arrayable|Jsonable|object|array $items @return array|boolean @throws \InvalidArgumentException
[ "Give", "me", "a", "native", "PHP", "array", "regardless", "of", "what", "kind", "of", "collection", "-", "like", "structure", "is", "given", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L874-L897
20,099
haldayne/boost
src/Map.php
Map.grep
protected function grep($expression, $limit = null) { // initialize our return map and book-keeping values $map = new static; $bnd = empty($limit) ? null : abs($limit); $cnt = 0; // define a helper to add matching values to our new map, stopping when // any designated limit is reached $helper = function ($value, $key) use ($expression, $map, $bnd, &$cnt) { if ($this->passes($this->call($expression, $value, $key))) { $map->set($key, $value); if (null !== $bnd && $bnd <= ++$cnt) { return false; } } }; // walk the array in the right direction if (0 <= $limit) { $this->walk($helper); } else { $this->walk_backward($helper); } return $map; }
php
protected function grep($expression, $limit = null) { // initialize our return map and book-keeping values $map = new static; $bnd = empty($limit) ? null : abs($limit); $cnt = 0; // define a helper to add matching values to our new map, stopping when // any designated limit is reached $helper = function ($value, $key) use ($expression, $map, $bnd, &$cnt) { if ($this->passes($this->call($expression, $value, $key))) { $map->set($key, $value); if (null !== $bnd && $bnd <= ++$cnt) { return false; } } }; // walk the array in the right direction if (0 <= $limit) { $this->walk($helper); } else { $this->walk_backward($helper); } return $map; }
[ "protected", "function", "grep", "(", "$", "expression", ",", "$", "limit", "=", "null", ")", "{", "// initialize our return map and book-keeping values", "$", "map", "=", "new", "static", ";", "$", "bnd", "=", "empty", "(", "$", "limit", ")", "?", "null", ":", "abs", "(", "$", "limit", ")", ";", "$", "cnt", "=", "0", ";", "// define a helper to add matching values to our new map, stopping when", "// any designated limit is reached", "$", "helper", "=", "function", "(", "$", "value", ",", "$", "key", ")", "use", "(", "$", "expression", ",", "$", "map", ",", "$", "bnd", ",", "&", "$", "cnt", ")", "{", "if", "(", "$", "this", "->", "passes", "(", "$", "this", "->", "call", "(", "$", "expression", ",", "$", "value", ",", "$", "key", ")", ")", ")", "{", "$", "map", "->", "set", "(", "$", "key", ",", "$", "value", ")", ";", "if", "(", "null", "!==", "$", "bnd", "&&", "$", "bnd", "<=", "++", "$", "cnt", ")", "{", "return", "false", ";", "}", "}", "}", ";", "// walk the array in the right direction", "if", "(", "0", "<=", "$", "limit", ")", "{", "$", "this", "->", "walk", "(", "$", "helper", ")", ";", "}", "else", "{", "$", "this", "->", "walk_backward", "(", "$", "helper", ")", ";", "}", "return", "$", "map", ";", "}" ]
Finds elements for which the given code passes, optionally limited to a maximum count. If limit is null, no limit on number of matches. If limit is positive, return that many from the front of the array. If limit is negative, return that many from the end of the array. @param callable|string $expression @param int|null $limit @return new static
[ "Finds", "elements", "for", "which", "the", "given", "code", "passes", "optionally", "limited", "to", "a", "maximum", "count", "." ]
d18cc398557e23f9c316ea7fb40b90f84cc53650
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L911-L938