repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
sequencelengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
antaresproject/notifications
src/Repository/StackRepository.php
StackRepository.findAllNew
public function findAllNew($ids = []) { $query = $model = $this->makeModel()->where('broadcasted', 0); if (!empty($ids)) { $values = array_values($ids); $query->whereNotIn('id', $values); } return $query->get(); }
php
public function findAllNew($ids = []) { $query = $model = $this->makeModel()->where('broadcasted', 0); if (!empty($ids)) { $values = array_values($ids); $query->whereNotIn('id', $values); } return $query->get(); }
[ "public", "function", "findAllNew", "(", "$", "ids", "=", "[", "]", ")", "{", "$", "query", "=", "$", "model", "=", "$", "this", "->", "makeModel", "(", ")", "->", "where", "(", "'broadcasted'", ",", "0", ")", ";", "if", "(", "!", "empty", "(", "$", "ids", ")", ")", "{", "$", "values", "=", "array_values", "(", "$", "ids", ")", ";", "$", "query", "->", "whereNotIn", "(", "'id'", ",", "$", "values", ")", ";", "}", "return", "$", "query", "->", "get", "(", ")", ";", "}" ]
finds all new notification messages @param array $ids @return \Illuminate\Database\Query\Builder
[ "finds", "all", "new", "notification", "messages" ]
train
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/StackRepository.php#L80-L88
antaresproject/notifications
src/Repository/StackRepository.php
StackRepository.query
public function query() { $read = NotificationsStackRead::select(['stack_id']) ->withTrashed() ->where('user_id', user()->id) ->whereNotNull('deleted_at') ->pluck('stack_id'); return $this->makeModel()->newQuery() ->distinct() ->select(['tbl_notifications_stack.*']) ->whereHas('content', function($query) { $query->where([ 'lang_id' => lang_id() ]); }) ->whereHas('notification', function($query) { $query->whereHas('type', function($subquery) { $subquery->where('name', area()); }); }) ->where(function ($query) { $query ->whereNull('author_id') ->orWhere('author_id', user()->id) ->orWhereHas('author', function($subquery) { $subquery->whereHas('roles', function($rolesQuery) { $rolesQuery->whereIn('tbl_roles.id', user()->roles->first()->getChilds()); }); }) ->orWhereHas('params', function($subquery) { $subquery->where('model_id', user()->id); }); }) ->whereNotIn('id', $read) ->with('author') ->with('content')->with('notification.severity') ->orderBy('tbl_notifications_stack.created_at', 'desc'); }
php
public function query() { $read = NotificationsStackRead::select(['stack_id']) ->withTrashed() ->where('user_id', user()->id) ->whereNotNull('deleted_at') ->pluck('stack_id'); return $this->makeModel()->newQuery() ->distinct() ->select(['tbl_notifications_stack.*']) ->whereHas('content', function($query) { $query->where([ 'lang_id' => lang_id() ]); }) ->whereHas('notification', function($query) { $query->whereHas('type', function($subquery) { $subquery->where('name', area()); }); }) ->where(function ($query) { $query ->whereNull('author_id') ->orWhere('author_id', user()->id) ->orWhereHas('author', function($subquery) { $subquery->whereHas('roles', function($rolesQuery) { $rolesQuery->whereIn('tbl_roles.id', user()->roles->first()->getChilds()); }); }) ->orWhereHas('params', function($subquery) { $subquery->where('model_id', user()->id); }); }) ->whereNotIn('id', $read) ->with('author') ->with('content')->with('notification.severity') ->orderBy('tbl_notifications_stack.created_at', 'desc'); }
[ "public", "function", "query", "(", ")", "{", "$", "read", "=", "NotificationsStackRead", "::", "select", "(", "[", "'stack_id'", "]", ")", "->", "withTrashed", "(", ")", "->", "where", "(", "'user_id'", ",", "user", "(", ")", "->", "id", ")", "->", "whereNotNull", "(", "'deleted_at'", ")", "->", "pluck", "(", "'stack_id'", ")", ";", "return", "$", "this", "->", "makeModel", "(", ")", "->", "newQuery", "(", ")", "->", "distinct", "(", ")", "->", "select", "(", "[", "'tbl_notifications_stack.*'", "]", ")", "->", "whereHas", "(", "'content'", ",", "function", "(", "$", "query", ")", "{", "$", "query", "->", "where", "(", "[", "'lang_id'", "=>", "lang_id", "(", ")", "]", ")", ";", "}", ")", "->", "whereHas", "(", "'notification'", ",", "function", "(", "$", "query", ")", "{", "$", "query", "->", "whereHas", "(", "'type'", ",", "function", "(", "$", "subquery", ")", "{", "$", "subquery", "->", "where", "(", "'name'", ",", "area", "(", ")", ")", ";", "}", ")", ";", "}", ")", "->", "where", "(", "function", "(", "$", "query", ")", "{", "$", "query", "->", "whereNull", "(", "'author_id'", ")", "->", "orWhere", "(", "'author_id'", ",", "user", "(", ")", "->", "id", ")", "->", "orWhereHas", "(", "'author'", ",", "function", "(", "$", "subquery", ")", "{", "$", "subquery", "->", "whereHas", "(", "'roles'", ",", "function", "(", "$", "rolesQuery", ")", "{", "$", "rolesQuery", "->", "whereIn", "(", "'tbl_roles.id'", ",", "user", "(", ")", "->", "roles", "->", "first", "(", ")", "->", "getChilds", "(", ")", ")", ";", "}", ")", ";", "}", ")", "->", "orWhereHas", "(", "'params'", ",", "function", "(", "$", "subquery", ")", "{", "$", "subquery", "->", "where", "(", "'model_id'", ",", "user", "(", ")", "->", "id", ")", ";", "}", ")", ";", "}", ")", "->", "whereNotIn", "(", "'id'", ",", "$", "read", ")", "->", "with", "(", "'author'", ")", "->", "with", "(", "'content'", ")", "->", "with", "(", "'notification.severity'", ")", "->", "orderBy", "(", "'tbl_notifications_stack.created_at'", ",", "'desc'", ")", ";", "}" ]
Gets base query builder for notifications and alerts @return \Illuminate\Database\Query\Builder
[ "Gets", "base", "query", "builder", "for", "notifications", "and", "alerts" ]
train
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/StackRepository.php#L115-L152
antaresproject/notifications
src/Repository/StackRepository.php
StackRepository.count
protected function count($builder) { $read = NotificationsStackRead::select(['stack_id'])->withTrashed()->where('user_id', user()->id)->pluck('stack_id'); return $builder->whereNotIn('id', $read)->count(); }
php
protected function count($builder) { $read = NotificationsStackRead::select(['stack_id'])->withTrashed()->where('user_id', user()->id)->pluck('stack_id'); return $builder->whereNotIn('id', $read)->count(); }
[ "protected", "function", "count", "(", "$", "builder", ")", "{", "$", "read", "=", "NotificationsStackRead", "::", "select", "(", "[", "'stack_id'", "]", ")", "->", "withTrashed", "(", ")", "->", "where", "(", "'user_id'", ",", "user", "(", ")", "->", "id", ")", "->", "pluck", "(", "'stack_id'", ")", ";", "return", "$", "builder", "->", "whereNotIn", "(", "'id'", ",", "$", "read", ")", "->", "count", "(", ")", ";", "}" ]
Assign counter query @param \Illuminate\Database\Query\Builder $builder @return \Illuminate\Database\Eloquent\Model
[ "Assign", "counter", "query" ]
train
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/StackRepository.php#L184-L188
antaresproject/notifications
src/Repository/StackRepository.php
StackRepository.clear
public function clear($type = 'notifications') { $builder = ($type === 'alerts') ? $this->getAlerts() : $this->getNotifications(); return $this->makeModel() ->getModel() ->read() ->getModel() ->newQuery() ->whereIn('stack_id', $builder->pluck('id'))->delete(); }
php
public function clear($type = 'notifications') { $builder = ($type === 'alerts') ? $this->getAlerts() : $this->getNotifications(); return $this->makeModel() ->getModel() ->read() ->getModel() ->newQuery() ->whereIn('stack_id', $builder->pluck('id'))->delete(); }
[ "public", "function", "clear", "(", "$", "type", "=", "'notifications'", ")", "{", "$", "builder", "=", "(", "$", "type", "===", "'alerts'", ")", "?", "$", "this", "->", "getAlerts", "(", ")", ":", "$", "this", "->", "getNotifications", "(", ")", ";", "return", "$", "this", "->", "makeModel", "(", ")", "->", "getModel", "(", ")", "->", "read", "(", ")", "->", "getModel", "(", ")", "->", "newQuery", "(", ")", "->", "whereIn", "(", "'stack_id'", ",", "$", "builder", "->", "pluck", "(", "'id'", ")", ")", "->", "delete", "(", ")", ";", "}" ]
Deletes all messages @param String $type @return boolean
[ "Deletes", "all", "messages" ]
train
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/StackRepository.php#L209-L219
antaresproject/notifications
src/Repository/StackRepository.php
StackRepository.markAsRead
public function markAsRead($type = 'notifications') { DB::beginTransaction(); try { $builder = ($type === 'alerts') ? $this->getAlerts() : $this->getNotifications(); $read = NotificationsStackRead::select(['stack_id'])->withTrashed()->where('user_id', user()->id)->pluck('stack_id'); $items = $builder->whereNotIn('id', $read)->get(); foreach ($items as $item) { $item->read()->save(new NotificationsStackRead([ 'user_id' => user()->id ])); $item->save(); } } catch (Exception $ex) { DB::rollback(); return false; } return DB::commit(); }
php
public function markAsRead($type = 'notifications') { DB::beginTransaction(); try { $builder = ($type === 'alerts') ? $this->getAlerts() : $this->getNotifications(); $read = NotificationsStackRead::select(['stack_id'])->withTrashed()->where('user_id', user()->id)->pluck('stack_id'); $items = $builder->whereNotIn('id', $read)->get(); foreach ($items as $item) { $item->read()->save(new NotificationsStackRead([ 'user_id' => user()->id ])); $item->save(); } } catch (Exception $ex) { DB::rollback(); return false; } return DB::commit(); }
[ "public", "function", "markAsRead", "(", "$", "type", "=", "'notifications'", ")", "{", "DB", "::", "beginTransaction", "(", ")", ";", "try", "{", "$", "builder", "=", "(", "$", "type", "===", "'alerts'", ")", "?", "$", "this", "->", "getAlerts", "(", ")", ":", "$", "this", "->", "getNotifications", "(", ")", ";", "$", "read", "=", "NotificationsStackRead", "::", "select", "(", "[", "'stack_id'", "]", ")", "->", "withTrashed", "(", ")", "->", "where", "(", "'user_id'", ",", "user", "(", ")", "->", "id", ")", "->", "pluck", "(", "'stack_id'", ")", ";", "$", "items", "=", "$", "builder", "->", "whereNotIn", "(", "'id'", ",", "$", "read", ")", "->", "get", "(", ")", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "$", "item", "->", "read", "(", ")", "->", "save", "(", "new", "NotificationsStackRead", "(", "[", "'user_id'", "=>", "user", "(", ")", "->", "id", "]", ")", ")", ";", "$", "item", "->", "save", "(", ")", ";", "}", "}", "catch", "(", "Exception", "$", "ex", ")", "{", "DB", "::", "rollback", "(", ")", ";", "return", "false", ";", "}", "return", "DB", "::", "commit", "(", ")", ";", "}" ]
Mark notifications or alerts as read @param String $type @return boolean
[ "Mark", "notifications", "or", "alerts", "as", "read" ]
train
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/StackRepository.php#L227-L246
antaresproject/notifications
src/Repository/StackRepository.php
StackRepository.deleteById
public function deleteById($id) { $read = NotificationsStackRead::where([ 'stack_id' => $id, 'user_id' => user()->id ])->first(); if (!is_null($read)) { return $read->delete(); } return false; }
php
public function deleteById($id) { $read = NotificationsStackRead::where([ 'stack_id' => $id, 'user_id' => user()->id ])->first(); if (!is_null($read)) { return $read->delete(); } return false; }
[ "public", "function", "deleteById", "(", "$", "id", ")", "{", "$", "read", "=", "NotificationsStackRead", "::", "where", "(", "[", "'stack_id'", "=>", "$", "id", ",", "'user_id'", "=>", "user", "(", ")", "->", "id", "]", ")", "->", "first", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "read", ")", ")", "{", "return", "$", "read", "->", "delete", "(", ")", ";", "}", "return", "false", ";", "}" ]
Deletes item by id @param mixed $id @return boolean
[ "Deletes", "item", "by", "id" ]
train
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/StackRepository.php#L254-L264
antaresproject/notifications
src/Repository/StackRepository.php
StackRepository.save
public function save(array $log, $message = null) { DB::beginTransaction(); try { $this->resolveJsonCastableColumns($log); $inserted = Logs::insert($log); if (!$inserted) { throw new Exception('Unable to save log'); } $lid = DB::getPdo()->lastInsertId(); $notification = Notifications::query()->firstOrNew([ 'brand_id' => brand_id(), 'category_id' => NotificationCategory::where('name', 'default')->first()->id, 'type_id' => NotificationTypes::where('name', 'admin')->first()->id, 'name' => $log['name'], ]); if (!$notification->exists) { $notification->active = 1; $notification->save(); $notification->contents()->save(new NotificationContents([ 'lang_id' => lang_id(), 'title' => $log['name'], 'content' => $message ])); } } catch (Exception $ex) { DB::rollback(); return false; } DB::commit(); return true; }
php
public function save(array $log, $message = null) { DB::beginTransaction(); try { $this->resolveJsonCastableColumns($log); $inserted = Logs::insert($log); if (!$inserted) { throw new Exception('Unable to save log'); } $lid = DB::getPdo()->lastInsertId(); $notification = Notifications::query()->firstOrNew([ 'brand_id' => brand_id(), 'category_id' => NotificationCategory::where('name', 'default')->first()->id, 'type_id' => NotificationTypes::where('name', 'admin')->first()->id, 'name' => $log['name'], ]); if (!$notification->exists) { $notification->active = 1; $notification->save(); $notification->contents()->save(new NotificationContents([ 'lang_id' => lang_id(), 'title' => $log['name'], 'content' => $message ])); } } catch (Exception $ex) { DB::rollback(); return false; } DB::commit(); return true; }
[ "public", "function", "save", "(", "array", "$", "log", ",", "$", "message", "=", "null", ")", "{", "DB", "::", "beginTransaction", "(", ")", ";", "try", "{", "$", "this", "->", "resolveJsonCastableColumns", "(", "$", "log", ")", ";", "$", "inserted", "=", "Logs", "::", "insert", "(", "$", "log", ")", ";", "if", "(", "!", "$", "inserted", ")", "{", "throw", "new", "Exception", "(", "'Unable to save log'", ")", ";", "}", "$", "lid", "=", "DB", "::", "getPdo", "(", ")", "->", "lastInsertId", "(", ")", ";", "$", "notification", "=", "Notifications", "::", "query", "(", ")", "->", "firstOrNew", "(", "[", "'brand_id'", "=>", "brand_id", "(", ")", ",", "'category_id'", "=>", "NotificationCategory", "::", "where", "(", "'name'", ",", "'default'", ")", "->", "first", "(", ")", "->", "id", ",", "'type_id'", "=>", "NotificationTypes", "::", "where", "(", "'name'", ",", "'admin'", ")", "->", "first", "(", ")", "->", "id", ",", "'name'", "=>", "$", "log", "[", "'name'", "]", ",", "]", ")", ";", "if", "(", "!", "$", "notification", "->", "exists", ")", "{", "$", "notification", "->", "active", "=", "1", ";", "$", "notification", "->", "save", "(", ")", ";", "$", "notification", "->", "contents", "(", ")", "->", "save", "(", "new", "NotificationContents", "(", "[", "'lang_id'", "=>", "lang_id", "(", ")", ",", "'title'", "=>", "$", "log", "[", "'name'", "]", ",", "'content'", "=>", "$", "message", "]", ")", ")", ";", "}", "}", "catch", "(", "Exception", "$", "ex", ")", "{", "DB", "::", "rollback", "(", ")", ";", "return", "false", ";", "}", "DB", "::", "commit", "(", ")", ";", "return", "true", ";", "}" ]
Saves notification @param array $log @param String $message @return boolean @throws Exception
[ "Saves", "notification" ]
train
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/StackRepository.php#L274-L305
antaresproject/notifications
src/Repository/StackRepository.php
StackRepository.resolveJsonCastableColumns
protected function resolveJsonCastableColumns(&$log) { foreach ($log as $name => $value) { if (!is_array($value)) { continue; } $log[$name] = json_encode($value); } return $log; }
php
protected function resolveJsonCastableColumns(&$log) { foreach ($log as $name => $value) { if (!is_array($value)) { continue; } $log[$name] = json_encode($value); } return $log; }
[ "protected", "function", "resolveJsonCastableColumns", "(", "&", "$", "log", ")", "{", "foreach", "(", "$", "log", "as", "$", "name", "=>", "$", "value", ")", "{", "if", "(", "!", "is_array", "(", "$", "value", ")", ")", "{", "continue", ";", "}", "$", "log", "[", "$", "name", "]", "=", "json_encode", "(", "$", "value", ")", ";", "}", "return", "$", "log", ";", "}" ]
Resolves json castable columns @return array
[ "Resolves", "json", "castable", "columns" ]
train
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/StackRepository.php#L312-L321
antaresproject/notifications
src/Repository/StackRepository.php
StackRepository.fetchAll
public function fetchAll(array $columns = []): Builder { return $this->makeModel() ->newQuery() ->select([ 'tbl_notifications_stack.id', 'tbl_notifications_stack.variables as variables', 'tbl_notifications_stack.created_at as created_at', 'tbl_notifications_stack.author_id as author_id', 'tbl_notifications.event as name', 'tbl_notification_contents.title as title', 'tbl_notification_types.title as type', 'tbl_languages.code as lang_code', 'tbl_languages.name as lang_name', 'tbl_roles.area as area', DB::raw('CONCAT_WS(" ",tbl_users.firstname,tbl_users.lastname) AS fullname') ]) ->leftJoin('tbl_notification_contents', 'tbl_notifications_stack.notification_id', '=', 'tbl_notification_contents.notification_id') ->leftJoin('tbl_notifications', 'tbl_notifications_stack.notification_id', '=', 'tbl_notifications.id') ->leftJoin('tbl_notification_types', 'tbl_notifications.type_id', '=', 'tbl_notification_types.id') ->leftJoin('tbl_languages', 'tbl_notification_contents.lang_id', '=', 'tbl_languages.id') ->leftJoin('tbl_users', 'tbl_notifications_stack.author_id', '=', 'tbl_users.id') ->leftJoin('tbl_user_role', 'tbl_users.id', '=', 'tbl_user_role.user_id') ->leftJoin('tbl_roles', 'tbl_user_role.role_id', '=', 'tbl_roles.id') ->where(function($query) { $query->whereNull('author_id') ->orWhere('author_id', user()->id) ->orWhereIn('tbl_roles.id', user()->roles->first()->getChilds()); }); }
php
public function fetchAll(array $columns = []): Builder { return $this->makeModel() ->newQuery() ->select([ 'tbl_notifications_stack.id', 'tbl_notifications_stack.variables as variables', 'tbl_notifications_stack.created_at as created_at', 'tbl_notifications_stack.author_id as author_id', 'tbl_notifications.event as name', 'tbl_notification_contents.title as title', 'tbl_notification_types.title as type', 'tbl_languages.code as lang_code', 'tbl_languages.name as lang_name', 'tbl_roles.area as area', DB::raw('CONCAT_WS(" ",tbl_users.firstname,tbl_users.lastname) AS fullname') ]) ->leftJoin('tbl_notification_contents', 'tbl_notifications_stack.notification_id', '=', 'tbl_notification_contents.notification_id') ->leftJoin('tbl_notifications', 'tbl_notifications_stack.notification_id', '=', 'tbl_notifications.id') ->leftJoin('tbl_notification_types', 'tbl_notifications.type_id', '=', 'tbl_notification_types.id') ->leftJoin('tbl_languages', 'tbl_notification_contents.lang_id', '=', 'tbl_languages.id') ->leftJoin('tbl_users', 'tbl_notifications_stack.author_id', '=', 'tbl_users.id') ->leftJoin('tbl_user_role', 'tbl_users.id', '=', 'tbl_user_role.user_id') ->leftJoin('tbl_roles', 'tbl_user_role.role_id', '=', 'tbl_roles.id') ->where(function($query) { $query->whereNull('author_id') ->orWhere('author_id', user()->id) ->orWhereIn('tbl_roles.id', user()->roles->first()->getChilds()); }); }
[ "public", "function", "fetchAll", "(", "array", "$", "columns", "=", "[", "]", ")", ":", "Builder", "{", "return", "$", "this", "->", "makeModel", "(", ")", "->", "newQuery", "(", ")", "->", "select", "(", "[", "'tbl_notifications_stack.id'", ",", "'tbl_notifications_stack.variables as variables'", ",", "'tbl_notifications_stack.created_at as created_at'", ",", "'tbl_notifications_stack.author_id as author_id'", ",", "'tbl_notifications.event as name'", ",", "'tbl_notification_contents.title as title'", ",", "'tbl_notification_types.title as type'", ",", "'tbl_languages.code as lang_code'", ",", "'tbl_languages.name as lang_name'", ",", "'tbl_roles.area as area'", ",", "DB", "::", "raw", "(", "'CONCAT_WS(\" \",tbl_users.firstname,tbl_users.lastname) AS fullname'", ")", "]", ")", "->", "leftJoin", "(", "'tbl_notification_contents'", ",", "'tbl_notifications_stack.notification_id'", ",", "'='", ",", "'tbl_notification_contents.notification_id'", ")", "->", "leftJoin", "(", "'tbl_notifications'", ",", "'tbl_notifications_stack.notification_id'", ",", "'='", ",", "'tbl_notifications.id'", ")", "->", "leftJoin", "(", "'tbl_notification_types'", ",", "'tbl_notifications.type_id'", ",", "'='", ",", "'tbl_notification_types.id'", ")", "->", "leftJoin", "(", "'tbl_languages'", ",", "'tbl_notification_contents.lang_id'", ",", "'='", ",", "'tbl_languages.id'", ")", "->", "leftJoin", "(", "'tbl_users'", ",", "'tbl_notifications_stack.author_id'", ",", "'='", ",", "'tbl_users.id'", ")", "->", "leftJoin", "(", "'tbl_user_role'", ",", "'tbl_users.id'", ",", "'='", ",", "'tbl_user_role.user_id'", ")", "->", "leftJoin", "(", "'tbl_roles'", ",", "'tbl_user_role.role_id'", ",", "'='", ",", "'tbl_roles.id'", ")", "->", "where", "(", "function", "(", "$", "query", ")", "{", "$", "query", "->", "whereNull", "(", "'author_id'", ")", "->", "orWhere", "(", "'author_id'", ",", "user", "(", ")", "->", "id", ")", "->", "orWhereIn", "(", "'tbl_roles.id'", ",", "user", "(", ")", "->", "roles", "->", "first", "(", ")", "->", "getChilds", "(", ")", ")", ";", "}", ")", ";", "}" ]
Fetch stacks @param array $columns @return Builder
[ "Fetch", "stacks" ]
train
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/StackRepository.php#L329-L358
antaresproject/notifications
src/Repository/StackRepository.php
StackRepository.fetchOne
public function fetchOne(int $id): Builder { return $this->makeModel()->newQuery()->withoutGlobalScopes()->distinct() ->select(['tbl_notifications_stack.*'])->with('content')->with('content.lang')->with('notification.type') ->where(function ($query) { $query->whereNull('author_id')->orWhere('author_id', user()->id)->orWhereHas('author', function($subquery) { $subquery->whereHas('roles', function($rolesQuery) { $rolesQuery->whereIn('tbl_roles.id', user()->roles->first()->getChilds()); }); }); }) ->with('author')->with('author.roles')->with('content') ->whereId($id); }
php
public function fetchOne(int $id): Builder { return $this->makeModel()->newQuery()->withoutGlobalScopes()->distinct() ->select(['tbl_notifications_stack.*'])->with('content')->with('content.lang')->with('notification.type') ->where(function ($query) { $query->whereNull('author_id')->orWhere('author_id', user()->id)->orWhereHas('author', function($subquery) { $subquery->whereHas('roles', function($rolesQuery) { $rolesQuery->whereIn('tbl_roles.id', user()->roles->first()->getChilds()); }); }); }) ->with('author')->with('author.roles')->with('content') ->whereId($id); }
[ "public", "function", "fetchOne", "(", "int", "$", "id", ")", ":", "Builder", "{", "return", "$", "this", "->", "makeModel", "(", ")", "->", "newQuery", "(", ")", "->", "withoutGlobalScopes", "(", ")", "->", "distinct", "(", ")", "->", "select", "(", "[", "'tbl_notifications_stack.*'", "]", ")", "->", "with", "(", "'content'", ")", "->", "with", "(", "'content.lang'", ")", "->", "with", "(", "'notification.type'", ")", "->", "where", "(", "function", "(", "$", "query", ")", "{", "$", "query", "->", "whereNull", "(", "'author_id'", ")", "->", "orWhere", "(", "'author_id'", ",", "user", "(", ")", "->", "id", ")", "->", "orWhereHas", "(", "'author'", ",", "function", "(", "$", "subquery", ")", "{", "$", "subquery", "->", "whereHas", "(", "'roles'", ",", "function", "(", "$", "rolesQuery", ")", "{", "$", "rolesQuery", "->", "whereIn", "(", "'tbl_roles.id'", ",", "user", "(", ")", "->", "roles", "->", "first", "(", ")", "->", "getChilds", "(", ")", ")", ";", "}", ")", ";", "}", ")", ";", "}", ")", "->", "with", "(", "'author'", ")", "->", "with", "(", "'author.roles'", ")", "->", "with", "(", "'content'", ")", "->", "whereId", "(", "$", "id", ")", ";", "}" ]
Fetch one stack item @param int $id @return Builder
[ "Fetch", "one", "stack", "item" ]
train
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/StackRepository.php#L366-L379
Danzabar/config-builder
src/Data/Extracter.php
Extracter.load
public function load($file, $extension = 'json') { $this->file = $file; $this->extension = $extension; return $this; }
php
public function load($file, $extension = 'json') { $this->file = $file; $this->extension = $extension; return $this; }
[ "public", "function", "load", "(", "$", "file", ",", "$", "extension", "=", "'json'", ")", "{", "$", "this", "->", "file", "=", "$", "file", ";", "$", "this", "->", "extension", "=", "$", "extension", ";", "return", "$", "this", ";", "}" ]
Load the file details @param String $file @param String $extension @return Extracter @author Dan Cox
[ "Load", "the", "file", "details" ]
train
https://github.com/Danzabar/config-builder/blob/3b237be578172c32498bbcdfb360e69a6243739d/src/Data/Extracter.php#L65-L71
Danzabar/config-builder
src/Data/Extracter.php
Extracter.extract
public function extract() { $this->reader->read($this->file); $this->converter ->setExtension($this->extension) ->process($this->reader->getData()); }
php
public function extract() { $this->reader->read($this->file); $this->converter ->setExtension($this->extension) ->process($this->reader->getData()); }
[ "public", "function", "extract", "(", ")", "{", "$", "this", "->", "reader", "->", "read", "(", "$", "this", "->", "file", ")", ";", "$", "this", "->", "converter", "->", "setExtension", "(", "$", "this", "->", "extension", ")", "->", "process", "(", "$", "this", "->", "reader", "->", "getData", "(", ")", ")", ";", "}" ]
Extracts the raw data from the file for conversion @return Extracter @author Dan Cox
[ "Extracts", "the", "raw", "data", "from", "the", "file", "for", "conversion" ]
train
https://github.com/Danzabar/config-builder/blob/3b237be578172c32498bbcdfb360e69a6243739d/src/Data/Extracter.php#L79-L86
kouks/laravel-filters
src/Filters/Behavior/Orderable.php
Orderable.resolveOrder
protected function resolveOrder($column, $key) { $this->resolve($column, $key, $this->getTableName(), function ($query, $pattern) { $this->builder->orderBy($query, $pattern); }); }
php
protected function resolveOrder($column, $key) { $this->resolve($column, $key, $this->getTableName(), function ($query, $pattern) { $this->builder->orderBy($query, $pattern); }); }
[ "protected", "function", "resolveOrder", "(", "$", "column", ",", "$", "key", ")", "{", "$", "this", "->", "resolve", "(", "$", "column", ",", "$", "key", ",", "$", "this", "->", "getTableName", "(", ")", ",", "function", "(", "$", "query", ",", "$", "pattern", ")", "{", "$", "this", "->", "builder", "->", "orderBy", "(", "$", "query", ",", "$", "pattern", ")", ";", "}", ")", ";", "}" ]
Recursively build up the order query. @param string $column @param string $key @return void
[ "Recursively", "build", "up", "the", "order", "query", "." ]
train
https://github.com/kouks/laravel-filters/blob/c1a594fd40173dcbb454ea7ec59818a919fff6bd/src/Filters/Behavior/Orderable.php#L30-L35
flextype-components/assets
Assets.php
Assets.add
public static function add(string $asset_type, string $asset, string $namespace, int $priority = 1) : void { Assets::$assets[$namespace][$asset_type][$priority][] = [ 'asset' => $asset ]; }
php
public static function add(string $asset_type, string $asset, string $namespace, int $priority = 1) : void { Assets::$assets[$namespace][$asset_type][$priority][] = [ 'asset' => $asset ]; }
[ "public", "static", "function", "add", "(", "string", "$", "asset_type", ",", "string", "$", "asset", ",", "string", "$", "namespace", ",", "int", "$", "priority", "=", "1", ")", ":", "void", "{", "Assets", "::", "$", "assets", "[", "$", "namespace", "]", "[", "$", "asset_type", "]", "[", "$", "priority", "]", "[", "]", "=", "[", "'asset'", "=>", "$", "asset", "]", ";", "}" ]
Add new asset Assets::add('js', 'jquery.js', 'site', 1); Assets::add('js', 'site.js', 'site', 2); Assets::add('css', 'site.css', 'site', 1); Assets::add('css', 'theme.css', 'site', 2); @param string $asset_type @param string $asset @param string $namespace @param int $priority @return void
[ "Add", "new", "asset" ]
train
https://github.com/flextype-components/assets/blob/fd30d051ceff7491d1fd6dd67913e58c451df2f8/Assets.php#L38-L43
flextype-components/assets
Assets.php
Assets.get
public static function get(string $asset_type, string $namespace) : array { $assets = []; // is there some registered $assets for current $namespace ? if (isset(Assets::$assets[$namespace]) && isset(Assets::$assets[$namespace][$asset_type]) && count(Assets::$assets[$namespace][$asset_type]) > 0) { // Get all $assets for given $namespace and $asset_type. $assets = Assets::$assets[$namespace][$asset_type]; // Sort $assets by priority from low to high ksort($assets); } // Return $assets return $assets; }
php
public static function get(string $asset_type, string $namespace) : array { $assets = []; // is there some registered $assets for current $namespace ? if (isset(Assets::$assets[$namespace]) && isset(Assets::$assets[$namespace][$asset_type]) && count(Assets::$assets[$namespace][$asset_type]) > 0) { // Get all $assets for given $namespace and $asset_type. $assets = Assets::$assets[$namespace][$asset_type]; // Sort $assets by priority from low to high ksort($assets); } // Return $assets return $assets; }
[ "public", "static", "function", "get", "(", "string", "$", "asset_type", ",", "string", "$", "namespace", ")", ":", "array", "{", "$", "assets", "=", "[", "]", ";", "// is there some registered $assets for current $namespace ?", "if", "(", "isset", "(", "Assets", "::", "$", "assets", "[", "$", "namespace", "]", ")", "&&", "isset", "(", "Assets", "::", "$", "assets", "[", "$", "namespace", "]", "[", "$", "asset_type", "]", ")", "&&", "count", "(", "Assets", "::", "$", "assets", "[", "$", "namespace", "]", "[", "$", "asset_type", "]", ")", ">", "0", ")", "{", "// Get all $assets for given $namespace and $asset_type.", "$", "assets", "=", "Assets", "::", "$", "assets", "[", "$", "namespace", "]", "[", "$", "asset_type", "]", ";", "// Sort $assets by priority from low to high", "ksort", "(", "$", "assets", ")", ";", "}", "// Return $assets", "return", "$", "assets", ";", "}" ]
Get assets for current namespace and asset type $css = Assets::get('css', 'site'); $js = Assets::get('js', 'site'); @param string $asset_type @param string $namespace @return array
[ "Get", "assets", "for", "current", "namespace", "and", "asset", "type" ]
train
https://github.com/flextype-components/assets/blob/fd30d051ceff7491d1fd6dd67913e58c451df2f8/Assets.php#L55-L73
ShaoZeMing/laravel-merchant
src/Widgets/Form.php
Form.findFieldClass
public static function findFieldClass($method) { $class = array_get(\ShaoZeMing\Merchant\Form::$availableFields, $method); if (class_exists($class)) { return $class; } return false; }
php
public static function findFieldClass($method) { $class = array_get(\ShaoZeMing\Merchant\Form::$availableFields, $method); if (class_exists($class)) { return $class; } return false; }
[ "public", "static", "function", "findFieldClass", "(", "$", "method", ")", "{", "$", "class", "=", "array_get", "(", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Form", "::", "$", "availableFields", ",", "$", "method", ")", ";", "if", "(", "class_exists", "(", "$", "class", ")", ")", "{", "return", "$", "class", ";", "}", "return", "false", ";", "}" ]
Find field class with given name. @param string $method @return bool|string
[ "Find", "field", "class", "with", "given", "name", "." ]
train
https://github.com/ShaoZeMing/laravel-merchant/blob/20801b1735e7832a6e58b37c2c391328f8d626fa/src/Widgets/Form.php#L180-L189
ekuiter/feature-php
FeaturePhp/Generator/TemplateGenerator.php
TemplateGenerator.getSpecification
protected function getSpecification($file, $settings, $artifact) { return fphp\Specification\TemplateSpecification::fromArrayAndSettings($file, $settings, $artifact); }
php
protected function getSpecification($file, $settings, $artifact) { return fphp\Specification\TemplateSpecification::fromArrayAndSettings($file, $settings, $artifact); }
[ "protected", "function", "getSpecification", "(", "$", "file", ",", "$", "settings", ",", "$", "artifact", ")", "{", "return", "fphp", "\\", "Specification", "\\", "TemplateSpecification", "::", "fromArrayAndSettings", "(", "$", "file", ",", "$", "settings", ",", "$", "artifact", ")", ";", "}" ]
Returns a template specification from a plain settings array. @param array $file a plain settings array @param Settings $settings the generator's settings @param \FeaturePhp\Artifact\Artifact $artifact the currently processed artifact @return \FeaturePhp\Specification\TemplateSpecification
[ "Returns", "a", "template", "specification", "from", "a", "plain", "settings", "array", "." ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Generator/TemplateGenerator.php#L34-L36
Humanized/yii2-lookup
controllers/DefaultController.php
DefaultController.actionIndex
public function actionIndex($caller) { $model = new $this->modelClass(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $model = new $this->modelClass(); } if (Yii::$app->request->post('hasEditable')) { $this->_update(); return; } $searchModel = new $this->modelClass(['scenario' => \humanized\lookup\models\LookupTable::SCENARIO_SEARCH]); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ 'caller' => $caller, 'model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); }
php
public function actionIndex($caller) { $model = new $this->modelClass(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $model = new $this->modelClass(); } if (Yii::$app->request->post('hasEditable')) { $this->_update(); return; } $searchModel = new $this->modelClass(['scenario' => \humanized\lookup\models\LookupTable::SCENARIO_SEARCH]); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ 'caller' => $caller, 'model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); }
[ "public", "function", "actionIndex", "(", "$", "caller", ")", "{", "$", "model", "=", "new", "$", "this", "->", "modelClass", "(", ")", ";", "if", "(", "$", "model", "->", "load", "(", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", ")", ")", "&&", "$", "model", "->", "save", "(", ")", ")", "{", "$", "model", "=", "new", "$", "this", "->", "modelClass", "(", ")", ";", "}", "if", "(", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", "'hasEditable'", ")", ")", "{", "$", "this", "->", "_update", "(", ")", ";", "return", ";", "}", "$", "searchModel", "=", "new", "$", "this", "->", "modelClass", "(", "[", "'scenario'", "=>", "\\", "humanized", "\\", "lookup", "\\", "models", "\\", "LookupTable", "::", "SCENARIO_SEARCH", "]", ")", ";", "$", "dataProvider", "=", "$", "searchModel", "->", "search", "(", "Yii", "::", "$", "app", "->", "request", "->", "queryParams", ")", ";", "return", "$", "this", "->", "render", "(", "'index'", ",", "[", "'caller'", "=>", "$", "caller", ",", "'model'", "=>", "$", "model", ",", "'searchModel'", "=>", "$", "searchModel", ",", "'dataProvider'", "=>", "$", "dataProvider", ",", "]", ")", ";", "}" ]
Single interface for all CRUD Operations. @return mixed
[ "Single", "interface", "for", "all", "CRUD", "Operations", "." ]
train
https://github.com/Humanized/yii2-lookup/blob/80982195cca9eb6f502e26fa1a27f72ed28ae25d/controllers/DefaultController.php#L50-L70
Humanized/yii2-lookup
controllers/DefaultController.php
DefaultController.actionDelete
public function actionDelete($caller, $id) { $this->findModel($id)->delete(); return $this->redirect(['index', 'caller' => $caller]); }
php
public function actionDelete($caller, $id) { $this->findModel($id)->delete(); return $this->redirect(['index', 'caller' => $caller]); }
[ "public", "function", "actionDelete", "(", "$", "caller", ",", "$", "id", ")", "{", "$", "this", "->", "findModel", "(", "$", "id", ")", "->", "delete", "(", ")", ";", "return", "$", "this", "->", "redirect", "(", "[", "'index'", ",", "'caller'", "=>", "$", "caller", "]", ")", ";", "}" ]
Deletes an existing ArtifactType model. If deletion is successful, the browser will be redirected to the 'index' page. @param integer $id @return mixed
[ "Deletes", "an", "existing", "ArtifactType", "model", ".", "If", "deletion", "is", "successful", "the", "browser", "will", "be", "redirected", "to", "the", "index", "page", "." ]
train
https://github.com/Humanized/yii2-lookup/blob/80982195cca9eb6f502e26fa1a27f72ed28ae25d/controllers/DefaultController.php#L110-L114
Humanized/yii2-lookup
controllers/DefaultController.php
DefaultController.findModel
protected function findModel($id) { $class = $this->modelClass; if (($model = $class::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
php
protected function findModel($id) { $class = $this->modelClass; if (($model = $class::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
[ "protected", "function", "findModel", "(", "$", "id", ")", "{", "$", "class", "=", "$", "this", "->", "modelClass", ";", "if", "(", "(", "$", "model", "=", "$", "class", "::", "findOne", "(", "$", "id", ")", ")", "!==", "null", ")", "{", "return", "$", "model", ";", "}", "else", "{", "throw", "new", "NotFoundHttpException", "(", "'The requested page does not exist.'", ")", ";", "}", "}" ]
Finds the ArtifactType model based on its primary key value. If the model is not found, a 404 HTTP exception will be thrown. @param integer $id @return ArtifactType the loaded model @throws NotFoundHttpException if the model cannot be found
[ "Finds", "the", "ArtifactType", "model", "based", "on", "its", "primary", "key", "value", ".", "If", "the", "model", "is", "not", "found", "a", "404", "HTTP", "exception", "will", "be", "thrown", "." ]
train
https://github.com/Humanized/yii2-lookup/blob/80982195cca9eb6f502e26fa1a27f72ed28ae25d/controllers/DefaultController.php#L123-L131
wenbinye/PhalconX
src/Db/Dialect/Mysql.php
Mysql.getColumnDefinition
public function getColumnDefinition(ColumnInterface $column) { $sql = parent::getColumnDefinition($column); if ($column instanceof Column && $column->getComment()) { $sql .= " COMMENT \"" . addcslashes($column->getComment(), '"') . "\""; } $def = $column->getDefault(); // empty value will ignore when create table if (isset($def) && in_array($def, [0, '', '0'])) { $sql .= ' DEFAULT "' . $def . '"'; } if ($column->getType() == Column::TYPE_INTEGER && $column->getSize() == 4) { $sql = preg_replace('/^INT/', 'TINYINT', $sql); } return $sql; }
php
public function getColumnDefinition(ColumnInterface $column) { $sql = parent::getColumnDefinition($column); if ($column instanceof Column && $column->getComment()) { $sql .= " COMMENT \"" . addcslashes($column->getComment(), '"') . "\""; } $def = $column->getDefault(); // empty value will ignore when create table if (isset($def) && in_array($def, [0, '', '0'])) { $sql .= ' DEFAULT "' . $def . '"'; } if ($column->getType() == Column::TYPE_INTEGER && $column->getSize() == 4) { $sql = preg_replace('/^INT/', 'TINYINT', $sql); } return $sql; }
[ "public", "function", "getColumnDefinition", "(", "ColumnInterface", "$", "column", ")", "{", "$", "sql", "=", "parent", "::", "getColumnDefinition", "(", "$", "column", ")", ";", "if", "(", "$", "column", "instanceof", "Column", "&&", "$", "column", "->", "getComment", "(", ")", ")", "{", "$", "sql", ".=", "\" COMMENT \\\"\"", ".", "addcslashes", "(", "$", "column", "->", "getComment", "(", ")", ",", "'\"'", ")", ".", "\"\\\"\"", ";", "}", "$", "def", "=", "$", "column", "->", "getDefault", "(", ")", ";", "// empty value will ignore when create table", "if", "(", "isset", "(", "$", "def", ")", "&&", "in_array", "(", "$", "def", ",", "[", "0", ",", "''", ",", "'0'", "]", ")", ")", "{", "$", "sql", ".=", "' DEFAULT \"'", ".", "$", "def", ".", "'\"'", ";", "}", "if", "(", "$", "column", "->", "getType", "(", ")", "==", "Column", "::", "TYPE_INTEGER", "&&", "$", "column", "->", "getSize", "(", ")", "==", "4", ")", "{", "$", "sql", "=", "preg_replace", "(", "'/^INT/'", ",", "'TINYINT'", ",", "$", "sql", ")", ";", "}", "return", "$", "sql", ";", "}" ]
supports comment and tinyint
[ "supports", "comment", "and", "tinyint" ]
train
https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Db/Dialect/Mysql.php#L24-L40
Xety/Breadcrumbs
src/Breadcrumbs.php
Breadcrumbs.addBreadcrumbs
public function addBreadcrumbs(array $breadcrumbs = []) { foreach ($breadcrumbs as $breadcrumb) { $this->addCrumb( isset($breadcrumb['name']) ? $breadcrumb['name'] : '', isset($breadcrumb['href']) ? $breadcrumb['href'] : '' ); } return $this; }
php
public function addBreadcrumbs(array $breadcrumbs = []) { foreach ($breadcrumbs as $breadcrumb) { $this->addCrumb( isset($breadcrumb['name']) ? $breadcrumb['name'] : '', isset($breadcrumb['href']) ? $breadcrumb['href'] : '' ); } return $this; }
[ "public", "function", "addBreadcrumbs", "(", "array", "$", "breadcrumbs", "=", "[", "]", ")", "{", "foreach", "(", "$", "breadcrumbs", "as", "$", "breadcrumb", ")", "{", "$", "this", "->", "addCrumb", "(", "isset", "(", "$", "breadcrumb", "[", "'name'", "]", ")", "?", "$", "breadcrumb", "[", "'name'", "]", ":", "''", ",", "isset", "(", "$", "breadcrumb", "[", "'href'", "]", ")", "?", "$", "breadcrumb", "[", "'href'", "]", ":", "''", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add the breadcrumbs to the current list. @param array $breadcrumbs The breadcrumbs to add to the list. @throws \InvalidArgumentException When the breadcrumb is not well formated. @return \Xety\Breadcrumbs\Breadcrumbs
[ "Add", "the", "breadcrumbs", "to", "the", "current", "list", "." ]
train
https://github.com/Xety/Breadcrumbs/blob/aded39bdbf4f6e857f0154a810339d71897a94b0/src/Breadcrumbs.php#L81-L91
Xety/Breadcrumbs
src/Breadcrumbs.php
Breadcrumbs.addCrumb
public function addCrumb(string $name = '', string $href = ''): Breadcrumbs { $breadcrumb = [ 'name' => $name, 'href' => $href ]; if (!$this->validateCrumb($breadcrumb)) { throw new InvalidArgumentException( 'Breadcrumbs::addCrumb() only accepts correctly formatted arrays.' ); } $crumb = [ 'name' => $name, 'href' => $href ]; $this->breadcrumbs[] = $crumb; return $this; }
php
public function addCrumb(string $name = '', string $href = ''): Breadcrumbs { $breadcrumb = [ 'name' => $name, 'href' => $href ]; if (!$this->validateCrumb($breadcrumb)) { throw new InvalidArgumentException( 'Breadcrumbs::addCrumb() only accepts correctly formatted arrays.' ); } $crumb = [ 'name' => $name, 'href' => $href ]; $this->breadcrumbs[] = $crumb; return $this; }
[ "public", "function", "addCrumb", "(", "string", "$", "name", "=", "''", ",", "string", "$", "href", "=", "''", ")", ":", "Breadcrumbs", "{", "$", "breadcrumb", "=", "[", "'name'", "=>", "$", "name", ",", "'href'", "=>", "$", "href", "]", ";", "if", "(", "!", "$", "this", "->", "validateCrumb", "(", "$", "breadcrumb", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Breadcrumbs::addCrumb() only accepts correctly formatted arrays.'", ")", ";", "}", "$", "crumb", "=", "[", "'name'", "=>", "$", "name", ",", "'href'", "=>", "$", "href", "]", ";", "$", "this", "->", "breadcrumbs", "[", "]", "=", "$", "crumb", ";", "return", "$", "this", ";", "}" ]
Add a crumb to the internal array. @param string $name The name of the crumb. @param string $href The link of the crumb. @return \Xety\Breadcrumbs\Breadcrumbs
[ "Add", "a", "crumb", "to", "the", "internal", "array", "." ]
train
https://github.com/Xety/Breadcrumbs/blob/aded39bdbf4f6e857f0154a810339d71897a94b0/src/Breadcrumbs.php#L101-L121
Xety/Breadcrumbs
src/Breadcrumbs.php
Breadcrumbs.firstFormated
public function firstFormated(): string { if ($this->isEmpty()) { return ''; } $crumb = reset($this->breadcrumbs); return $this->renderCrumb($crumb['name'], $crumb['href'], false, 1); }
php
public function firstFormated(): string { if ($this->isEmpty()) { return ''; } $crumb = reset($this->breadcrumbs); return $this->renderCrumb($crumb['name'], $crumb['href'], false, 1); }
[ "public", "function", "firstFormated", "(", ")", ":", "string", "{", "if", "(", "$", "this", "->", "isEmpty", "(", ")", ")", "{", "return", "''", ";", "}", "$", "crumb", "=", "reset", "(", "$", "this", "->", "breadcrumbs", ")", ";", "return", "$", "this", "->", "renderCrumb", "(", "$", "crumb", "[", "'name'", "]", ",", "$", "crumb", "[", "'href'", "]", ",", "false", ",", "1", ")", ";", "}" ]
Get the first crumb formated as HTML. @return string
[ "Get", "the", "first", "crumb", "formated", "as", "HTML", "." ]
train
https://github.com/Xety/Breadcrumbs/blob/aded39bdbf4f6e857f0154a810339d71897a94b0/src/Breadcrumbs.php#L195-L204
Xety/Breadcrumbs
src/Breadcrumbs.php
Breadcrumbs.lastFormated
public function lastFormated(): string { if ($this->isEmpty()) { return ''; } $crumb = end($this->breadcrumbs); return $this->renderCrumb($crumb['name'], $crumb['href'], false, 1); }
php
public function lastFormated(): string { if ($this->isEmpty()) { return ''; } $crumb = end($this->breadcrumbs); return $this->renderCrumb($crumb['name'], $crumb['href'], false, 1); }
[ "public", "function", "lastFormated", "(", ")", ":", "string", "{", "if", "(", "$", "this", "->", "isEmpty", "(", ")", ")", "{", "return", "''", ";", "}", "$", "crumb", "=", "end", "(", "$", "this", "->", "breadcrumbs", ")", ";", "return", "$", "this", "->", "renderCrumb", "(", "$", "crumb", "[", "'name'", "]", ",", "$", "crumb", "[", "'href'", "]", ",", "false", ",", "1", ")", ";", "}" ]
Get the last crumb formated as HTML. @return string
[ "Get", "the", "last", "crumb", "formated", "as", "HTML", "." ]
train
https://github.com/Xety/Breadcrumbs/blob/aded39bdbf4f6e857f0154a810339d71897a94b0/src/Breadcrumbs.php#L225-L234
Xety/Breadcrumbs
src/Breadcrumbs.php
Breadcrumbs.renderCrumb
protected function renderCrumb($name, $href, $isLast = false, $position = null): string { $positionAttribute = ''; if ($this->getOption('position')) { $positionAttribute = "data-position=\"{$position}\""; } if ($isLast) { $element = $this->getOption('listActiveElement'); $classes = $this->getClasses('listActiveElementClasses'); return "<{$element} {$positionAttribute} class=\"{$classes}\">{$name}</{$element}>"; } $element = $this->getOption('listItemElement'); $classes = $this->getClasses('listItemElementClasses'); $divider = ''; if ($this->getDivider() !== null) { $divider = $this->getDivider(); $dividerElement = $this->getOption('dividerElement'); $dividerClasses = $this->getClasses('dividerElementClasses'); $divider = "<{$dividerElement} class=\"{$dividerClasses}\">{$divider}</{$dividerElement}>"; } return "<{$element} {$positionAttribute} class=\"{$classes}\" href=\"{$href}\">{$name}</{$element}>{$divider}"; }
php
protected function renderCrumb($name, $href, $isLast = false, $position = null): string { $positionAttribute = ''; if ($this->getOption('position')) { $positionAttribute = "data-position=\"{$position}\""; } if ($isLast) { $element = $this->getOption('listActiveElement'); $classes = $this->getClasses('listActiveElementClasses'); return "<{$element} {$positionAttribute} class=\"{$classes}\">{$name}</{$element}>"; } $element = $this->getOption('listItemElement'); $classes = $this->getClasses('listItemElementClasses'); $divider = ''; if ($this->getDivider() !== null) { $divider = $this->getDivider(); $dividerElement = $this->getOption('dividerElement'); $dividerClasses = $this->getClasses('dividerElementClasses'); $divider = "<{$dividerElement} class=\"{$dividerClasses}\">{$divider}</{$dividerElement}>"; } return "<{$element} {$positionAttribute} class=\"{$classes}\" href=\"{$href}\">{$name}</{$element}>{$divider}"; }
[ "protected", "function", "renderCrumb", "(", "$", "name", ",", "$", "href", ",", "$", "isLast", "=", "false", ",", "$", "position", "=", "null", ")", ":", "string", "{", "$", "positionAttribute", "=", "''", ";", "if", "(", "$", "this", "->", "getOption", "(", "'position'", ")", ")", "{", "$", "positionAttribute", "=", "\"data-position=\\\"{$position}\\\"\"", ";", "}", "if", "(", "$", "isLast", ")", "{", "$", "element", "=", "$", "this", "->", "getOption", "(", "'listActiveElement'", ")", ";", "$", "classes", "=", "$", "this", "->", "getClasses", "(", "'listActiveElementClasses'", ")", ";", "return", "\"<{$element} {$positionAttribute} class=\\\"{$classes}\\\">{$name}</{$element}>\"", ";", "}", "$", "element", "=", "$", "this", "->", "getOption", "(", "'listItemElement'", ")", ";", "$", "classes", "=", "$", "this", "->", "getClasses", "(", "'listItemElementClasses'", ")", ";", "$", "divider", "=", "''", ";", "if", "(", "$", "this", "->", "getDivider", "(", ")", "!==", "null", ")", "{", "$", "divider", "=", "$", "this", "->", "getDivider", "(", ")", ";", "$", "dividerElement", "=", "$", "this", "->", "getOption", "(", "'dividerElement'", ")", ";", "$", "dividerClasses", "=", "$", "this", "->", "getClasses", "(", "'dividerElementClasses'", ")", ";", "$", "divider", "=", "\"<{$dividerElement} class=\\\"{$dividerClasses}\\\">{$divider}</{$dividerElement}>\"", ";", "}", "return", "\"<{$element} {$positionAttribute} class=\\\"{$classes}\\\" href=\\\"{$href}\\\">{$name}</{$element}>{$divider}\"", ";", "}" ]
Render a crumb. @param string $name The text/HTML to render within the element. @param string $href The link of the crumb. @param bool $isLast Whether the crumb is the last item. @param number $position The current position of the crumb. @return string
[ "Render", "a", "crumb", "." ]
train
https://github.com/Xety/Breadcrumbs/blob/aded39bdbf4f6e857f0154a810339d71897a94b0/src/Breadcrumbs.php#L268-L295
Xety/Breadcrumbs
src/Breadcrumbs.php
Breadcrumbs.getClasses
protected function getClasses(string $option, string $separator = ' '): string { return implode($separator, $this->getOption($option)); }
php
protected function getClasses(string $option, string $separator = ' '): string { return implode($separator, $this->getOption($option)); }
[ "protected", "function", "getClasses", "(", "string", "$", "option", ",", "string", "$", "separator", "=", "' '", ")", ":", "string", "{", "return", "implode", "(", "$", "separator", ",", "$", "this", "->", "getOption", "(", "$", "option", ")", ")", ";", "}" ]
Get the imploded classes for the given option. @param string $option The option where to get the classes from. @param string $separator The separator used by the implode function. @return string
[ "Get", "the", "imploded", "classes", "for", "the", "given", "option", "." ]
train
https://github.com/Xety/Breadcrumbs/blob/aded39bdbf4f6e857f0154a810339d71897a94b0/src/Breadcrumbs.php#L305-L308
Xety/Breadcrumbs
src/Breadcrumbs.php
Breadcrumbs.renderCrumbs
protected function renderCrumbs(): string { end($this->breadcrumbs); $lastKey = key($this->breadcrumbs); $output = ''; $position = 1; foreach ($this->breadcrumbs as $key => $crumb) { $isLast = ($lastKey === $key); $href = $crumb['href']; // Add a slash when the URL is relative and does not contain a slash at the start. if (!preg_match('#^https?://.*#', $href) && mb_substr($href, 0, 1) !== '/') { $href = "/{$href}"; } $output .= $this->renderCrumb($crumb['name'], $href, $isLast, $position); $position++; } return $output; }
php
protected function renderCrumbs(): string { end($this->breadcrumbs); $lastKey = key($this->breadcrumbs); $output = ''; $position = 1; foreach ($this->breadcrumbs as $key => $crumb) { $isLast = ($lastKey === $key); $href = $crumb['href']; // Add a slash when the URL is relative and does not contain a slash at the start. if (!preg_match('#^https?://.*#', $href) && mb_substr($href, 0, 1) !== '/') { $href = "/{$href}"; } $output .= $this->renderCrumb($crumb['name'], $href, $isLast, $position); $position++; } return $output; }
[ "protected", "function", "renderCrumbs", "(", ")", ":", "string", "{", "end", "(", "$", "this", "->", "breadcrumbs", ")", ";", "$", "lastKey", "=", "key", "(", "$", "this", "->", "breadcrumbs", ")", ";", "$", "output", "=", "''", ";", "$", "position", "=", "1", ";", "foreach", "(", "$", "this", "->", "breadcrumbs", "as", "$", "key", "=>", "$", "crumb", ")", "{", "$", "isLast", "=", "(", "$", "lastKey", "===", "$", "key", ")", ";", "$", "href", "=", "$", "crumb", "[", "'href'", "]", ";", "// Add a slash when the URL is relative and does not contain a slash at the start.", "if", "(", "!", "preg_match", "(", "'#^https?://.*#'", ",", "$", "href", ")", "&&", "mb_substr", "(", "$", "href", ",", "0", ",", "1", ")", "!==", "'/'", ")", "{", "$", "href", "=", "\"/{$href}\"", ";", "}", "$", "output", ".=", "$", "this", "->", "renderCrumb", "(", "$", "crumb", "[", "'name'", "]", ",", "$", "href", ",", "$", "isLast", ",", "$", "position", ")", ";", "$", "position", "++", ";", "}", "return", "$", "output", ";", "}" ]
Renders the crumbs. @return string
[ "Renders", "the", "crumbs", "." ]
train
https://github.com/Xety/Breadcrumbs/blob/aded39bdbf4f6e857f0154a810339d71897a94b0/src/Breadcrumbs.php#L315-L339
Xety/Breadcrumbs
src/Breadcrumbs.php
Breadcrumbs.render
public function render(): string { if (empty($this->breadcrumbs)) { return ''; } $classes = $this->getClasses('listElementClasses'); $element = $this->getOption('listElement'); return "<{$element} class=\"{$classes}\">" . $this->renderCrumbs() . "</{$element}>"; }
php
public function render(): string { if (empty($this->breadcrumbs)) { return ''; } $classes = $this->getClasses('listElementClasses'); $element = $this->getOption('listElement'); return "<{$element} class=\"{$classes}\">" . $this->renderCrumbs() . "</{$element}>"; }
[ "public", "function", "render", "(", ")", ":", "string", "{", "if", "(", "empty", "(", "$", "this", "->", "breadcrumbs", ")", ")", "{", "return", "''", ";", "}", "$", "classes", "=", "$", "this", "->", "getClasses", "(", "'listElementClasses'", ")", ";", "$", "element", "=", "$", "this", "->", "getOption", "(", "'listElement'", ")", ";", "return", "\"<{$element} class=\\\"{$classes}\\\">\"", ".", "$", "this", "->", "renderCrumbs", "(", ")", ".", "\"</{$element}>\"", ";", "}" ]
Renders the complete breadcrumbs into HTML. @return string
[ "Renders", "the", "complete", "breadcrumbs", "into", "HTML", "." ]
train
https://github.com/Xety/Breadcrumbs/blob/aded39bdbf4f6e857f0154a810339d71897a94b0/src/Breadcrumbs.php#L346-L356
qlake/framework
src/Qlake/Http/Header.php
Header.set
public function set($name, $value) { $this->data[$this->normalizeKey($name)] = $value; return $this; }
php
public function set($name, $value) { $this->data[$this->normalizeKey($name)] = $value; return $this; }
[ "public", "function", "set", "(", "$", "name", ",", "$", "value", ")", "{", "$", "this", "->", "data", "[", "$", "this", "->", "normalizeKey", "(", "$", "name", ")", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
Set a HTTP header. @param string $name @param string $value @return Qlake\Http\Header
[ "Set", "a", "HTTP", "header", "." ]
train
https://github.com/qlake/framework/blob/0b7bad459ae0721bc5cdd141344f9dfc1acee28a/src/Qlake/Http/Header.php#L48-L53
qlake/framework
src/Qlake/Http/Header.php
Header.normalizeKey
protected function normalizeKey($name) { $name = strtolower($name); $name = str_replace(array('-', '_'), ' ', $name); $name = preg_replace('#^http #', '', $name); $name = ucwords($name); $name = str_replace(' ', '-', $name); return $name; }
php
protected function normalizeKey($name) { $name = strtolower($name); $name = str_replace(array('-', '_'), ' ', $name); $name = preg_replace('#^http #', '', $name); $name = ucwords($name); $name = str_replace(' ', '-', $name); return $name; }
[ "protected", "function", "normalizeKey", "(", "$", "name", ")", "{", "$", "name", "=", "strtolower", "(", "$", "name", ")", ";", "$", "name", "=", "str_replace", "(", "array", "(", "'-'", ",", "'_'", ")", ",", "' '", ",", "$", "name", ")", ";", "$", "name", "=", "preg_replace", "(", "'#^http #'", ",", "''", ",", "$", "name", ")", ";", "$", "name", "=", "ucwords", "(", "$", "name", ")", ";", "$", "name", "=", "str_replace", "(", "' '", ",", "'-'", ",", "$", "name", ")", ";", "return", "$", "name", ";", "}" ]
Normalize HTTP header name. @param string $name @return string
[ "Normalize", "HTTP", "header", "name", "." ]
train
https://github.com/qlake/framework/blob/0b7bad459ae0721bc5cdd141344f9dfc1acee28a/src/Qlake/Http/Header.php#L137-L146
dcsg/EventbriteApiConnector
lib/EventbriteApiConnector/HttpAdapter/BuzzHttpAdapter.php
BuzzHttpAdapter.postContent
public function postContent($url, $headers = array(), $content = '') { try { $response = $this->browser->post($url, $headers, $content); $content = $response->getContent(); } catch (\Exception $e) { $content = null; } return $content; }
php
public function postContent($url, $headers = array(), $content = '') { try { $response = $this->browser->post($url, $headers, $content); $content = $response->getContent(); } catch (\Exception $e) { $content = null; } return $content; }
[ "public", "function", "postContent", "(", "$", "url", ",", "$", "headers", "=", "array", "(", ")", ",", "$", "content", "=", "''", ")", "{", "try", "{", "$", "response", "=", "$", "this", "->", "browser", "->", "post", "(", "$", "url", ",", "$", "headers", ",", "$", "content", ")", ";", "$", "content", "=", "$", "response", "->", "getContent", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "content", "=", "null", ";", "}", "return", "$", "content", ";", "}" ]
@param string $url @param array $headers HTTP headers @param string $content Content to be sent @return string
[ "@param", "string", "$url", "@param", "array", "$headers", "HTTP", "headers", "@param", "string", "$content", "Content", "to", "be", "sent" ]
train
https://github.com/dcsg/EventbriteApiConnector/blob/3926f6dee8d824601cad7155bc2b5f9748218236/lib/EventbriteApiConnector/HttpAdapter/BuzzHttpAdapter.php#L59-L69
expectation-php/expect
src/matcher/strategy/ArrayInclusionStrategy.php
ArrayInclusionStrategy.match
public function match(array $expectValues) { $matchResults = []; $unmatchResults = []; foreach ($expectValues as $expectValue) { if (in_array($expectValue, $this->actualValues)) { $matchResults[] = $expectValue; } else { $unmatchResults[] = $expectValue; } } return new InclusionResult($expectValues, $matchResults, $unmatchResults); }
php
public function match(array $expectValues) { $matchResults = []; $unmatchResults = []; foreach ($expectValues as $expectValue) { if (in_array($expectValue, $this->actualValues)) { $matchResults[] = $expectValue; } else { $unmatchResults[] = $expectValue; } } return new InclusionResult($expectValues, $matchResults, $unmatchResults); }
[ "public", "function", "match", "(", "array", "$", "expectValues", ")", "{", "$", "matchResults", "=", "[", "]", ";", "$", "unmatchResults", "=", "[", "]", ";", "foreach", "(", "$", "expectValues", "as", "$", "expectValue", ")", "{", "if", "(", "in_array", "(", "$", "expectValue", ",", "$", "this", "->", "actualValues", ")", ")", "{", "$", "matchResults", "[", "]", "=", "$", "expectValue", ";", "}", "else", "{", "$", "unmatchResults", "[", "]", "=", "$", "expectValue", ";", "}", "}", "return", "new", "InclusionResult", "(", "$", "expectValues", ",", "$", "matchResults", ",", "$", "unmatchResults", ")", ";", "}" ]
<code> <?php $strategy = new ArrayInclusionStrategy([ 1, 2 ]); $result = $strategy->match([ 1, 2, 3 ]);. var_dump($result->isMatched()) // true var_dump($result->getMatchResults()); // [ 1, 2 ] var_dump($result->getUnmatchResults()); // [ 3 ] ?> </code> @param array expectValues
[ "<code", ">", "<?php", "$strategy", "=", "new", "ArrayInclusionStrategy", "(", "[", "1", "2", "]", ")", ";", "$result", "=", "$strategy", "-", ">", "match", "(", "[", "1", "2", "3", "]", ")", ";", "." ]
train
https://github.com/expectation-php/expect/blob/1a32c5af37f3dc8dabe4e8eedeeb21aea16ce139/src/matcher/strategy/ArrayInclusionStrategy.php#L42-L56
webandco/neos-wireframe
Classes/Fusion/WireframeContentImplementation.php
WireframeContentImplementation.evaluate
public function evaluate() { $httpRequest = Request::createFromEnvironment(); /** @var UserInterfaceMode $mode */ $mode = $this->interfaceRenderModeService->findModeByCurrentUser(); /** @var integer $renderMode */ $renderMode = 0; switch (true) { case $mode->getName() === 'wireframe' || $httpRequest->getArgument('wireframeMode') == '1' : $renderMode = 1; break; case $httpRequest->getArgument('wireframeMode') == '2' : $renderMode = 2; break; } return $renderMode; }
php
public function evaluate() { $httpRequest = Request::createFromEnvironment(); /** @var UserInterfaceMode $mode */ $mode = $this->interfaceRenderModeService->findModeByCurrentUser(); /** @var integer $renderMode */ $renderMode = 0; switch (true) { case $mode->getName() === 'wireframe' || $httpRequest->getArgument('wireframeMode') == '1' : $renderMode = 1; break; case $httpRequest->getArgument('wireframeMode') == '2' : $renderMode = 2; break; } return $renderMode; }
[ "public", "function", "evaluate", "(", ")", "{", "$", "httpRequest", "=", "Request", "::", "createFromEnvironment", "(", ")", ";", "/** @var UserInterfaceMode $mode */", "$", "mode", "=", "$", "this", "->", "interfaceRenderModeService", "->", "findModeByCurrentUser", "(", ")", ";", "/** @var integer $renderMode */", "$", "renderMode", "=", "0", ";", "switch", "(", "true", ")", "{", "case", "$", "mode", "->", "getName", "(", ")", "===", "'wireframe'", "||", "$", "httpRequest", "->", "getArgument", "(", "'wireframeMode'", ")", "==", "'1'", ":", "$", "renderMode", "=", "1", ";", "break", ";", "case", "$", "httpRequest", "->", "getArgument", "(", "'wireframeMode'", ")", "==", "'2'", ":", "$", "renderMode", "=", "2", ";", "break", ";", "}", "return", "$", "renderMode", ";", "}" ]
Evaluate wireframe rendering mode @return integer
[ "Evaluate", "wireframe", "rendering", "mode" ]
train
https://github.com/webandco/neos-wireframe/blob/b1dfd9bedee80001a9a0cf0f483d0261633d12cb/Classes/Fusion/WireframeContentImplementation.php#L30-L51
technote-space/wordpress-plugin-base
src/traits/helper/data_helper.php
Data_Helper.convert_to_bool
protected function convert_to_bool( $data, $key ) { return ! empty( $data[ $key ] ) && $data[ $key ] !== '0' && $data[ $key ] !== 'false'; }
php
protected function convert_to_bool( $data, $key ) { return ! empty( $data[ $key ] ) && $data[ $key ] !== '0' && $data[ $key ] !== 'false'; }
[ "protected", "function", "convert_to_bool", "(", "$", "data", ",", "$", "key", ")", "{", "return", "!", "empty", "(", "$", "data", "[", "$", "key", "]", ")", "&&", "$", "data", "[", "$", "key", "]", "!==", "'0'", "&&", "$", "data", "[", "$", "key", "]", "!==", "'false'", ";", "}" ]
@param array $data @param string $key @return bool
[ "@param", "array", "$data", "@param", "string", "$key" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/data_helper.php#L36-L38
technote-space/wordpress-plugin-base
src/traits/helper/data_helper.php
Data_Helper.sanitize_input
protected function sanitize_input( $param, $type ) { switch ( $type ) { case 'int': if ( ! is_int( $param ) && ! ctype_digit( ltrim( $param, '-' ) ) ) { return null; } $param -= 0; $param = (int) $param; break; case 'float': case 'number': if ( ! is_numeric( $param ) && ! ctype_alpha( $param ) ) { return null; } $param -= 0; break; case 'bool': // bool 以外は $param = null は null // bool は !nullable (checkboxにチェックを入れたか入れてないかの二値しか取れない想定のため) // したがって is_null のチェックはしない(null は false) if ( is_string( $param ) ) { $param = strtolower( trim( $param ) ); if ( $param === 'true' ) { $param = 1; } elseif ( $param === 'false' ) { $param = 0; } elseif ( $param === '0' ) { $param = 0; } else { $param = ! empty( $param ); } } else { $param = ! empty( $param ); } break; default: if ( is_null( $param ) ) { return null; } break; } return $param; }
php
protected function sanitize_input( $param, $type ) { switch ( $type ) { case 'int': if ( ! is_int( $param ) && ! ctype_digit( ltrim( $param, '-' ) ) ) { return null; } $param -= 0; $param = (int) $param; break; case 'float': case 'number': if ( ! is_numeric( $param ) && ! ctype_alpha( $param ) ) { return null; } $param -= 0; break; case 'bool': // bool 以外は $param = null は null // bool は !nullable (checkboxにチェックを入れたか入れてないかの二値しか取れない想定のため) // したがって is_null のチェックはしない(null は false) if ( is_string( $param ) ) { $param = strtolower( trim( $param ) ); if ( $param === 'true' ) { $param = 1; } elseif ( $param === 'false' ) { $param = 0; } elseif ( $param === '0' ) { $param = 0; } else { $param = ! empty( $param ); } } else { $param = ! empty( $param ); } break; default: if ( is_null( $param ) ) { return null; } break; } return $param; }
[ "protected", "function", "sanitize_input", "(", "$", "param", ",", "$", "type", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "'int'", ":", "if", "(", "!", "is_int", "(", "$", "param", ")", "&&", "!", "ctype_digit", "(", "ltrim", "(", "$", "param", ",", "'-'", ")", ")", ")", "{", "return", "null", ";", "}", "$", "param", "-=", "0", ";", "$", "param", "=", "(", "int", ")", "$", "param", ";", "break", ";", "case", "'float'", ":", "case", "'number'", ":", "if", "(", "!", "is_numeric", "(", "$", "param", ")", "&&", "!", "ctype_alpha", "(", "$", "param", ")", ")", "{", "return", "null", ";", "}", "$", "param", "-=", "0", ";", "break", ";", "case", "'bool'", ":", "// bool 以外は $param = null は null", "// bool は !nullable (checkboxにチェックを入れたか入れてないかの二値しか取れない想定のため)", "// したがって is_null のチェックはしない(null は false)", "if", "(", "is_string", "(", "$", "param", ")", ")", "{", "$", "param", "=", "strtolower", "(", "trim", "(", "$", "param", ")", ")", ";", "if", "(", "$", "param", "===", "'true'", ")", "{", "$", "param", "=", "1", ";", "}", "elseif", "(", "$", "param", "===", "'false'", ")", "{", "$", "param", "=", "0", ";", "}", "elseif", "(", "$", "param", "===", "'0'", ")", "{", "$", "param", "=", "0", ";", "}", "else", "{", "$", "param", "=", "!", "empty", "(", "$", "param", ")", ";", "}", "}", "else", "{", "$", "param", "=", "!", "empty", "(", "$", "param", ")", ";", "}", "break", ";", "default", ":", "if", "(", "is_null", "(", "$", "param", ")", ")", "{", "return", "null", ";", "}", "break", ";", "}", "return", "$", "param", ";", "}" ]
@since 2.9.6 Fixed: return null if $param = null @param mixed $param @param string $type @return mixed
[ "@since", "2", ".", "9", ".", "6", "Fixed", ":", "return", "null", "if", "$param", "=", "null" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/data_helper.php#L57-L100
InactiveProjects/limoncello-illuminate
app/Database/Migrations/MigrateBoards.php
MigrateBoards.apply
public function apply() { Schema::create(Model::TABLE_NAME, function (Blueprint $table) { $table->increments(Model::FIELD_ID); $table->string(Model::FIELD_TITLE, Model::LENGTH_TITLE); $table->softDeletes(); $table->timestamps(); }); }
php
public function apply() { Schema::create(Model::TABLE_NAME, function (Blueprint $table) { $table->increments(Model::FIELD_ID); $table->string(Model::FIELD_TITLE, Model::LENGTH_TITLE); $table->softDeletes(); $table->timestamps(); }); }
[ "public", "function", "apply", "(", ")", "{", "Schema", "::", "create", "(", "Model", "::", "TABLE_NAME", ",", "function", "(", "Blueprint", "$", "table", ")", "{", "$", "table", "->", "increments", "(", "Model", "::", "FIELD_ID", ")", ";", "$", "table", "->", "string", "(", "Model", "::", "FIELD_TITLE", ",", "Model", "::", "LENGTH_TITLE", ")", ";", "$", "table", "->", "softDeletes", "(", ")", ";", "$", "table", "->", "timestamps", "(", ")", ";", "}", ")", ";", "}" ]
@inheritdoc @SuppressWarnings(PHPMD.StaticAccess)
[ "@inheritdoc" ]
train
https://github.com/InactiveProjects/limoncello-illuminate/blob/cae6fc26190efcf090495a5c3582c10fa2430897/app/Database/Migrations/MigrateBoards.php#L16-L24
canis-io/yii2-broadcaster
lib/models/BroadcastEvent.php
BroadcastEvent.getPayloadObject
public function getPayloadObject() { if (!isset($this->_dataObject) && !empty($this->payload)) { $this->_dataObject = unserialize($this->payload); $this->_dataObject->model = $this; } return $this->_dataObject; }
php
public function getPayloadObject() { if (!isset($this->_dataObject) && !empty($this->payload)) { $this->_dataObject = unserialize($this->payload); $this->_dataObject->model = $this; } return $this->_dataObject; }
[ "public", "function", "getPayloadObject", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_dataObject", ")", "&&", "!", "empty", "(", "$", "this", "->", "payload", ")", ")", "{", "$", "this", "->", "_dataObject", "=", "unserialize", "(", "$", "this", "->", "payload", ")", ";", "$", "this", "->", "_dataObject", "->", "model", "=", "$", "this", ";", "}", "return", "$", "this", "->", "_dataObject", ";", "}" ]
Get action object. @return [[@doctodo return_type:getActionObject]] [[@doctodo return_description:getActionObject]]
[ "Get", "action", "object", "." ]
train
https://github.com/canis-io/yii2-broadcaster/blob/b8d7b5b24f2d8f4fdb29132dd85df34602dcd6b1/lib/models/BroadcastEvent.php#L66-L74
SporkCode/Spork
src/Mvc/Listener/Limit/Storage/Db.php
Db.setServiceLocator
public function setServiceLocator(ServiceLocatorInterface $serviceManager) { if (!$this->dbAdapter instanceof DbAdapter) { $this->dbAdapter = $serviceManager->getServiceLocator()->get($this->dbAdapter); } }
php
public function setServiceLocator(ServiceLocatorInterface $serviceManager) { if (!$this->dbAdapter instanceof DbAdapter) { $this->dbAdapter = $serviceManager->getServiceLocator()->get($this->dbAdapter); } }
[ "public", "function", "setServiceLocator", "(", "ServiceLocatorInterface", "$", "serviceManager", ")", "{", "if", "(", "!", "$", "this", "->", "dbAdapter", "instanceof", "DbAdapter", ")", "{", "$", "this", "->", "dbAdapter", "=", "$", "serviceManager", "->", "getServiceLocator", "(", ")", "->", "get", "(", "$", "this", "->", "dbAdapter", ")", ";", "}", "}" ]
Use Service Manager to inject database adapter @see \Zend\ServiceManager\ServiceLocatorAwareInterface::setServiceLocator() @param ServiceLocatorInterface $serviceManager
[ "Use", "Service", "Manager", "to", "inject", "database", "adapter" ]
train
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/Storage/Db.php#L114-L119
SporkCode/Spork
src/Mvc/Listener/Limit/Storage/Db.php
Db.getCleanInterval
public function getCleanInterval() { if (!$this->cleanInterval instanceof DateInterval) { $this->cleanInterval = new DateInterval($this->cleanInterval); } return $this->cleanInterval; }
php
public function getCleanInterval() { if (!$this->cleanInterval instanceof DateInterval) { $this->cleanInterval = new DateInterval($this->cleanInterval); } return $this->cleanInterval; }
[ "public", "function", "getCleanInterval", "(", ")", "{", "if", "(", "!", "$", "this", "->", "cleanInterval", "instanceof", "DateInterval", ")", "{", "$", "this", "->", "cleanInterval", "=", "new", "DateInterval", "(", "$", "this", "->", "cleanInterval", ")", ";", "}", "return", "$", "this", "->", "cleanInterval", ";", "}" ]
Get clean interval @return \Spork\DateTime\DateInterval
[ "Get", "clean", "interval" ]
train
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/Storage/Db.php#L157-L163
SporkCode/Spork
src/Mvc/Listener/Limit/Storage/Db.php
Db.increment
public function increment($ip, $type) { $this->assertReady(); $sql = sprintf("INSERT INTO %s SET %s=:type, %s=:ip", $this->dbAdapter->platform->quoteIdentifier($this->table), $this->dbAdapter->platform->quoteIdentifier($this->typeColumn), $this->dbAdapter->platform->quoteIdentifier($this->ipColumn)); $parameters = array( 'type' => $type, 'ip' => $ip, ); $this->dbAdapter->query($sql, $parameters); }
php
public function increment($ip, $type) { $this->assertReady(); $sql = sprintf("INSERT INTO %s SET %s=:type, %s=:ip", $this->dbAdapter->platform->quoteIdentifier($this->table), $this->dbAdapter->platform->quoteIdentifier($this->typeColumn), $this->dbAdapter->platform->quoteIdentifier($this->ipColumn)); $parameters = array( 'type' => $type, 'ip' => $ip, ); $this->dbAdapter->query($sql, $parameters); }
[ "public", "function", "increment", "(", "$", "ip", ",", "$", "type", ")", "{", "$", "this", "->", "assertReady", "(", ")", ";", "$", "sql", "=", "sprintf", "(", "\"INSERT INTO %s SET %s=:type, %s=:ip\"", ",", "$", "this", "->", "dbAdapter", "->", "platform", "->", "quoteIdentifier", "(", "$", "this", "->", "table", ")", ",", "$", "this", "->", "dbAdapter", "->", "platform", "->", "quoteIdentifier", "(", "$", "this", "->", "typeColumn", ")", ",", "$", "this", "->", "dbAdapter", "->", "platform", "->", "quoteIdentifier", "(", "$", "this", "->", "ipColumn", ")", ")", ";", "$", "parameters", "=", "array", "(", "'type'", "=>", "$", "type", ",", "'ip'", "=>", "$", "ip", ",", ")", ";", "$", "this", "->", "dbAdapter", "->", "query", "(", "$", "sql", ",", "$", "parameters", ")", ";", "}" ]
Add record to database @see \Spork\Mvc\Listener\Limit\Storage\StorageInterface::increment() @param unknown $ip @param unknown $type
[ "Add", "record", "to", "database" ]
train
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/Storage/Db.php#L292-L307
SporkCode/Spork
src/Mvc/Listener/Limit/Storage/Db.php
Db.check
public function check($ip, Limit $limit) { $this->assertReady(); if ($this->cleanOnCheck) { $this->clean(); } $sql = sprintf("SELECT count(*) as count FROM %s WHERE %s=:ip AND %s=:type AND %s >= NOW() - INTERVAL %d SECOND", $this->dbAdapter->platform->quoteIdentifier($this->table), $this->dbAdapter->platform->quoteIdentifier($this->ipColumn), $this->dbAdapter->platform->quoteIdentifier($this->typeColumn), $this->dbAdapter->platform->quoteIdentifier($this->timestampColumn), $limit->getInterval()->toSeconds()); $parameters = array( 'ip' => $ip, 'type' => $limit->getName(), ); $result = $this->dbAdapter->query($sql, $parameters); $count = $result->current()->count; return $count >= $limit->getLimit(); }
php
public function check($ip, Limit $limit) { $this->assertReady(); if ($this->cleanOnCheck) { $this->clean(); } $sql = sprintf("SELECT count(*) as count FROM %s WHERE %s=:ip AND %s=:type AND %s >= NOW() - INTERVAL %d SECOND", $this->dbAdapter->platform->quoteIdentifier($this->table), $this->dbAdapter->platform->quoteIdentifier($this->ipColumn), $this->dbAdapter->platform->quoteIdentifier($this->typeColumn), $this->dbAdapter->platform->quoteIdentifier($this->timestampColumn), $limit->getInterval()->toSeconds()); $parameters = array( 'ip' => $ip, 'type' => $limit->getName(), ); $result = $this->dbAdapter->query($sql, $parameters); $count = $result->current()->count; return $count >= $limit->getLimit(); }
[ "public", "function", "check", "(", "$", "ip", ",", "Limit", "$", "limit", ")", "{", "$", "this", "->", "assertReady", "(", ")", ";", "if", "(", "$", "this", "->", "cleanOnCheck", ")", "{", "$", "this", "->", "clean", "(", ")", ";", "}", "$", "sql", "=", "sprintf", "(", "\"SELECT count(*) as count FROM %s WHERE %s=:ip AND %s=:type AND %s >= NOW() - INTERVAL %d SECOND\"", ",", "$", "this", "->", "dbAdapter", "->", "platform", "->", "quoteIdentifier", "(", "$", "this", "->", "table", ")", ",", "$", "this", "->", "dbAdapter", "->", "platform", "->", "quoteIdentifier", "(", "$", "this", "->", "ipColumn", ")", ",", "$", "this", "->", "dbAdapter", "->", "platform", "->", "quoteIdentifier", "(", "$", "this", "->", "typeColumn", ")", ",", "$", "this", "->", "dbAdapter", "->", "platform", "->", "quoteIdentifier", "(", "$", "this", "->", "timestampColumn", ")", ",", "$", "limit", "->", "getInterval", "(", ")", "->", "toSeconds", "(", ")", ")", ";", "$", "parameters", "=", "array", "(", "'ip'", "=>", "$", "ip", ",", "'type'", "=>", "$", "limit", "->", "getName", "(", ")", ",", ")", ";", "$", "result", "=", "$", "this", "->", "dbAdapter", "->", "query", "(", "$", "sql", ",", "$", "parameters", ")", ";", "$", "count", "=", "$", "result", "->", "current", "(", ")", "->", "count", ";", "return", "$", "count", ">=", "$", "limit", "->", "getLimit", "(", ")", ";", "}" ]
Check if the number or records in the database exceeds the set limit @see \Spork\Mvc\Listener\Limit\Storage\StorageInterface::check() @param string $ip @param Limit $limit @return boolean
[ "Check", "if", "the", "number", "or", "records", "in", "the", "database", "exceeds", "the", "set", "limit" ]
train
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/Storage/Db.php#L317-L340
SporkCode/Spork
src/Mvc/Listener/Limit/Storage/Db.php
Db.clean
public function clean() { $this->assertReady(); $sql = sprintf("DELETE FROM %s WHERE %s < NOW() - INTERVAL %d SECOND", $this->dbAdapter->platform->quoteIdentifier($this->table), $this->dbAdapter->platform->quoteIdentifier($this->timestampColumn), $this->getCleanInterval()->toSeconds()); $this->dbAdapter->query($sql, DbAdapter::QUERY_MODE_EXECUTE); }
php
public function clean() { $this->assertReady(); $sql = sprintf("DELETE FROM %s WHERE %s < NOW() - INTERVAL %d SECOND", $this->dbAdapter->platform->quoteIdentifier($this->table), $this->dbAdapter->platform->quoteIdentifier($this->timestampColumn), $this->getCleanInterval()->toSeconds()); $this->dbAdapter->query($sql, DbAdapter::QUERY_MODE_EXECUTE); }
[ "public", "function", "clean", "(", ")", "{", "$", "this", "->", "assertReady", "(", ")", ";", "$", "sql", "=", "sprintf", "(", "\"DELETE FROM %s WHERE %s < NOW() - INTERVAL %d SECOND\"", ",", "$", "this", "->", "dbAdapter", "->", "platform", "->", "quoteIdentifier", "(", "$", "this", "->", "table", ")", ",", "$", "this", "->", "dbAdapter", "->", "platform", "->", "quoteIdentifier", "(", "$", "this", "->", "timestampColumn", ")", ",", "$", "this", "->", "getCleanInterval", "(", ")", "->", "toSeconds", "(", ")", ")", ";", "$", "this", "->", "dbAdapter", "->", "query", "(", "$", "sql", ",", "DbAdapter", "::", "QUERY_MODE_EXECUTE", ")", ";", "}" ]
Remove expired records from database @see \Spork\Mvc\Listener\Limit\Storage\StorageInterface::clean()
[ "Remove", "expired", "records", "from", "database" ]
train
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/Storage/Db.php#L347-L357
Isset/pushnotification
src/PushNotification/Type/Windows/WindowsNotifier.php
WindowsNotifier.sendMessageEnvelope
private function sendMessageEnvelope(WindowsConnection $connection, WindowsMessageEnvelope $messageEnvelope) { $response = $connection->sendAndReceive($messageEnvelope->getMessage()); $messageEnvelope->setResponse($response); if ($response->isSuccess()) { $messageEnvelope->setState(MessageEnvelope::SUCCESS); } else { $messageEnvelope->setState(MessageEnvelope::FAILED); } }
php
private function sendMessageEnvelope(WindowsConnection $connection, WindowsMessageEnvelope $messageEnvelope) { $response = $connection->sendAndReceive($messageEnvelope->getMessage()); $messageEnvelope->setResponse($response); if ($response->isSuccess()) { $messageEnvelope->setState(MessageEnvelope::SUCCESS); } else { $messageEnvelope->setState(MessageEnvelope::FAILED); } }
[ "private", "function", "sendMessageEnvelope", "(", "WindowsConnection", "$", "connection", ",", "WindowsMessageEnvelope", "$", "messageEnvelope", ")", "{", "$", "response", "=", "$", "connection", "->", "sendAndReceive", "(", "$", "messageEnvelope", "->", "getMessage", "(", ")", ")", ";", "$", "messageEnvelope", "->", "setResponse", "(", "$", "response", ")", ";", "if", "(", "$", "response", "->", "isSuccess", "(", ")", ")", "{", "$", "messageEnvelope", "->", "setState", "(", "MessageEnvelope", "::", "SUCCESS", ")", ";", "}", "else", "{", "$", "messageEnvelope", "->", "setState", "(", "MessageEnvelope", "::", "FAILED", ")", ";", "}", "}" ]
@param $connection @param $messageEnvelope @throws ConnectionException @throws ConnectionHandlerException
[ "@param", "$connection", "@param", "$messageEnvelope" ]
train
https://github.com/Isset/pushnotification/blob/5e7634dc6b1cf4f7c371d1890243a25252db0d85/src/PushNotification/Type/Windows/WindowsNotifier.php#L90-L99
ShaoZeMing/laravel-merchant
src/Controllers/LogController.php
LogController.index
public function index() { return Merchant::content(function (Content $content) { $content->header(trans('merchant.operation_log')); $content->description(trans('merchant.list')); $grid = Merchant::grid(OperationLog::class, function (Grid $grid) { $grid->model()->orderBy('id', 'DESC'); $grid->id('ID')->sortable(); $grid->user()->name(trans('merchant.user')); $grid->method()->display(function ($method) { $color = array_get(OperationLog::$methodColors, $method, 'grey'); return "<span class=\"badge bg-$color\">$method</span>"; }); $grid->path()->label('info'); $grid->ip()->label('primary'); $grid->input()->display(function ($input) { $input = json_decode($input, true); $input = array_except($input, ['_pjax', '_token', '_method', '_previous_']); if (empty($input)) { return '<code>{}</code>'; } return '<pre>'.json_encode($input, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE).'</pre>'; }); $grid->created_at(trans('merchant.created_at')); $grid->actions(function (Grid\Displayers\Actions $actions) { $actions->disableEdit(); }); $grid->disableCreation(); $grid->filter(function ($filter) { $filter->equal('user_id', 'User')->select(Administrator::all()->pluck('name', 'id')); $filter->equal('method')->select(array_combine(OperationLog::$methods, OperationLog::$methods)); $filter->like('path'); $filter->equal('ip'); }); }); $content->body($grid); }); }
php
public function index() { return Merchant::content(function (Content $content) { $content->header(trans('merchant.operation_log')); $content->description(trans('merchant.list')); $grid = Merchant::grid(OperationLog::class, function (Grid $grid) { $grid->model()->orderBy('id', 'DESC'); $grid->id('ID')->sortable(); $grid->user()->name(trans('merchant.user')); $grid->method()->display(function ($method) { $color = array_get(OperationLog::$methodColors, $method, 'grey'); return "<span class=\"badge bg-$color\">$method</span>"; }); $grid->path()->label('info'); $grid->ip()->label('primary'); $grid->input()->display(function ($input) { $input = json_decode($input, true); $input = array_except($input, ['_pjax', '_token', '_method', '_previous_']); if (empty($input)) { return '<code>{}</code>'; } return '<pre>'.json_encode($input, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE).'</pre>'; }); $grid->created_at(trans('merchant.created_at')); $grid->actions(function (Grid\Displayers\Actions $actions) { $actions->disableEdit(); }); $grid->disableCreation(); $grid->filter(function ($filter) { $filter->equal('user_id', 'User')->select(Administrator::all()->pluck('name', 'id')); $filter->equal('method')->select(array_combine(OperationLog::$methods, OperationLog::$methods)); $filter->like('path'); $filter->equal('ip'); }); }); $content->body($grid); }); }
[ "public", "function", "index", "(", ")", "{", "return", "Merchant", "::", "content", "(", "function", "(", "Content", "$", "content", ")", "{", "$", "content", "->", "header", "(", "trans", "(", "'merchant.operation_log'", ")", ")", ";", "$", "content", "->", "description", "(", "trans", "(", "'merchant.list'", ")", ")", ";", "$", "grid", "=", "Merchant", "::", "grid", "(", "OperationLog", "::", "class", ",", "function", "(", "Grid", "$", "grid", ")", "{", "$", "grid", "->", "model", "(", ")", "->", "orderBy", "(", "'id'", ",", "'DESC'", ")", ";", "$", "grid", "->", "id", "(", "'ID'", ")", "->", "sortable", "(", ")", ";", "$", "grid", "->", "user", "(", ")", "->", "name", "(", "trans", "(", "'merchant.user'", ")", ")", ";", "$", "grid", "->", "method", "(", ")", "->", "display", "(", "function", "(", "$", "method", ")", "{", "$", "color", "=", "array_get", "(", "OperationLog", "::", "$", "methodColors", ",", "$", "method", ",", "'grey'", ")", ";", "return", "\"<span class=\\\"badge bg-$color\\\">$method</span>\"", ";", "}", ")", ";", "$", "grid", "->", "path", "(", ")", "->", "label", "(", "'info'", ")", ";", "$", "grid", "->", "ip", "(", ")", "->", "label", "(", "'primary'", ")", ";", "$", "grid", "->", "input", "(", ")", "->", "display", "(", "function", "(", "$", "input", ")", "{", "$", "input", "=", "json_decode", "(", "$", "input", ",", "true", ")", ";", "$", "input", "=", "array_except", "(", "$", "input", ",", "[", "'_pjax'", ",", "'_token'", ",", "'_method'", ",", "'_previous_'", "]", ")", ";", "if", "(", "empty", "(", "$", "input", ")", ")", "{", "return", "'<code>{}</code>'", ";", "}", "return", "'<pre>'", ".", "json_encode", "(", "$", "input", ",", "JSON_PRETTY_PRINT", "|", "JSON_UNESCAPED_UNICODE", ")", ".", "'</pre>'", ";", "}", ")", ";", "$", "grid", "->", "created_at", "(", "trans", "(", "'merchant.created_at'", ")", ")", ";", "$", "grid", "->", "actions", "(", "function", "(", "Grid", "\\", "Displayers", "\\", "Actions", "$", "actions", ")", "{", "$", "actions", "->", "disableEdit", "(", ")", ";", "}", ")", ";", "$", "grid", "->", "disableCreation", "(", ")", ";", "$", "grid", "->", "filter", "(", "function", "(", "$", "filter", ")", "{", "$", "filter", "->", "equal", "(", "'user_id'", ",", "'User'", ")", "->", "select", "(", "Administrator", "::", "all", "(", ")", "->", "pluck", "(", "'name'", ",", "'id'", ")", ")", ";", "$", "filter", "->", "equal", "(", "'method'", ")", "->", "select", "(", "array_combine", "(", "OperationLog", "::", "$", "methods", ",", "OperationLog", "::", "$", "methods", ")", ")", ";", "$", "filter", "->", "like", "(", "'path'", ")", ";", "$", "filter", "->", "equal", "(", "'ip'", ")", ";", "}", ")", ";", "}", ")", ";", "$", "content", "->", "body", "(", "$", "grid", ")", ";", "}", ")", ";", "}" ]
Index interface. @return Content
[ "Index", "interface", "." ]
train
https://github.com/ShaoZeMing/laravel-merchant/blob/20801b1735e7832a6e58b37c2c391328f8d626fa/src/Controllers/LogController.php#L19-L65
newmythmedia/di
src/DI.php
DI.register
public function register($alias, $class) { $alias = strtolower($alias); if (array_key_exists($alias, $this->instances)) { throw new \RuntimeException('You cannot register a provider when an instance of that class has already been created.'); } $this->services[$alias] = $class; return $this; }
php
public function register($alias, $class) { $alias = strtolower($alias); if (array_key_exists($alias, $this->instances)) { throw new \RuntimeException('You cannot register a provider when an instance of that class has already been created.'); } $this->services[$alias] = $class; return $this; }
[ "public", "function", "register", "(", "$", "alias", ",", "$", "class", ")", "{", "$", "alias", "=", "strtolower", "(", "$", "alias", ")", ";", "if", "(", "array_key_exists", "(", "$", "alias", ",", "$", "this", "->", "instances", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'You cannot register a provider when an instance of that class has already been created.'", ")", ";", "}", "$", "this", "->", "services", "[", "$", "alias", "]", "=", "$", "class", ";", "return", "$", "this", ";", "}" ]
Registers a specific class name with the corresponding alias for the dependency inversion. @param $name @param $class @return $this
[ "Registers", "a", "specific", "class", "name", "with", "the", "corresponding", "alias", "for", "the", "dependency", "inversion", "." ]
train
https://github.com/newmythmedia/di/blob/bc7397ea447de6a2d7564d7c95abf03f15e7756a/src/DI.php#L125-L137
newmythmedia/di
src/DI.php
DI.unregister
public function unregister($alias, $remove_instances=false) { $alias = strtolower($alias); if ($remove_instances && array_key_exists($alias, $this->instances)) { $this->instances[$alias] = null; unset($this->instances[$alias]); } unset($this->services[$alias]); return $this; }
php
public function unregister($alias, $remove_instances=false) { $alias = strtolower($alias); if ($remove_instances && array_key_exists($alias, $this->instances)) { $this->instances[$alias] = null; unset($this->instances[$alias]); } unset($this->services[$alias]); return $this; }
[ "public", "function", "unregister", "(", "$", "alias", ",", "$", "remove_instances", "=", "false", ")", "{", "$", "alias", "=", "strtolower", "(", "$", "alias", ")", ";", "if", "(", "$", "remove_instances", "&&", "array_key_exists", "(", "$", "alias", ",", "$", "this", "->", "instances", ")", ")", "{", "$", "this", "->", "instances", "[", "$", "alias", "]", "=", "null", ";", "unset", "(", "$", "this", "->", "instances", "[", "$", "alias", "]", ")", ";", "}", "unset", "(", "$", "this", "->", "services", "[", "$", "alias", "]", ")", ";", "return", "$", "this", ";", "}" ]
Unregisters a single service provider. If an instance of that provider has already been created, it will be destroyed. @param $alias @return $this
[ "Unregisters", "a", "single", "service", "provider", ".", "If", "an", "instance", "of", "that", "provider", "has", "already", "been", "created", "it", "will", "be", "destroyed", "." ]
train
https://github.com/newmythmedia/di/blob/bc7397ea447de6a2d7564d7c95abf03f15e7756a/src/DI.php#L149-L162
newmythmedia/di
src/DI.php
DI.saveInstance
public function saveInstance($alias, &$class) { $alias = strtolower($alias); if (array_key_exists($alias, $this->instances)) { unset($this->instances[$alias]); } $this->instances[$alias] = $class; return $this; }
php
public function saveInstance($alias, &$class) { $alias = strtolower($alias); if (array_key_exists($alias, $this->instances)) { unset($this->instances[$alias]); } $this->instances[$alias] = $class; return $this; }
[ "public", "function", "saveInstance", "(", "$", "alias", ",", "&", "$", "class", ")", "{", "$", "alias", "=", "strtolower", "(", "$", "alias", ")", ";", "if", "(", "array_key_exists", "(", "$", "alias", ",", "$", "this", "->", "instances", ")", ")", "{", "unset", "(", "$", "this", "->", "instances", "[", "$", "alias", "]", ")", ";", "}", "$", "this", "->", "instances", "[", "$", "alias", "]", "=", "$", "class", ";", "return", "$", "this", ";", "}" ]
Registers an instantiated class as a Service Provider. todo Register savedInstance class with the services array. @param $alias @param $class @return $this
[ "Registers", "an", "instantiated", "class", "as", "a", "Service", "Provider", "." ]
train
https://github.com/newmythmedia/di/blob/bc7397ea447de6a2d7564d7c95abf03f15e7756a/src/DI.php#L176-L188
newmythmedia/di
src/DI.php
DI.make
public function make($alias, $use_singletons=false) { $alias = strtolower($alias); if (! array_key_exists($alias, $this->services)) { throw new \InvalidArgumentException('No Service is registered for alias: '. $alias); } // The provider could be either a string (namespaced class) // or a Closure that returns an instance of the desired class. $service = $this->services[$alias]; if (is_string($service)) { if (! class_exists($service, true)) { throw new \RuntimeException('Unable to locate the Service Provider: '. $this->services[$alias] ); } return $this->inject($service, $use_singletons); } else if (is_callable($service)) { return $service( $this ); } return null; }
php
public function make($alias, $use_singletons=false) { $alias = strtolower($alias); if (! array_key_exists($alias, $this->services)) { throw new \InvalidArgumentException('No Service is registered for alias: '. $alias); } // The provider could be either a string (namespaced class) // or a Closure that returns an instance of the desired class. $service = $this->services[$alias]; if (is_string($service)) { if (! class_exists($service, true)) { throw new \RuntimeException('Unable to locate the Service Provider: '. $this->services[$alias] ); } return $this->inject($service, $use_singletons); } else if (is_callable($service)) { return $service( $this ); } return null; }
[ "public", "function", "make", "(", "$", "alias", ",", "$", "use_singletons", "=", "false", ")", "{", "$", "alias", "=", "strtolower", "(", "$", "alias", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "alias", ",", "$", "this", "->", "services", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'No Service is registered for alias: '", ".", "$", "alias", ")", ";", "}", "// The provider could be either a string (namespaced class)", "// or a Closure that returns an instance of the desired class.", "$", "service", "=", "$", "this", "->", "services", "[", "$", "alias", "]", ";", "if", "(", "is_string", "(", "$", "service", ")", ")", "{", "if", "(", "!", "class_exists", "(", "$", "service", ",", "true", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Unable to locate the Service Provider: '", ".", "$", "this", "->", "services", "[", "$", "alias", "]", ")", ";", "}", "return", "$", "this", "->", "inject", "(", "$", "service", ",", "$", "use_singletons", ")", ";", "}", "else", "if", "(", "is_callable", "(", "$", "service", ")", ")", "{", "return", "$", "service", "(", "$", "this", ")", ";", "}", "return", "null", ";", "}" ]
Creates a new instance of the service provider with $alias, and return it. Does not check for an existing instance but always returns a new one. @param $alias @param bool $use_singletons @return null
[ "Creates", "a", "new", "instance", "of", "the", "service", "provider", "with", "$alias", "and", "return", "it", ".", "Does", "not", "check", "for", "an", "existing", "instance", "but", "always", "returns", "a", "new", "one", "." ]
train
https://github.com/newmythmedia/di/blob/bc7397ea447de6a2d7564d7c95abf03f15e7756a/src/DI.php#L202-L231
newmythmedia/di
src/DI.php
DI.single
public function single($alias) { $alias = strtolower($alias); // Return the existing object if it exists. if (! empty($this->instances[$alias]) && is_object($this->instances[$alias])) { return $this->instances[$alias]; } // Die if we don't know what class to use. if (empty($this->services[$alias])) { throw new \InvalidArgumentException('Unable to find class with alias: '. $alias); } $instance = $this->make($alias, true); $this->instances[$alias] =& $instance; return $this->instances[$alias]; }
php
public function single($alias) { $alias = strtolower($alias); // Return the existing object if it exists. if (! empty($this->instances[$alias]) && is_object($this->instances[$alias])) { return $this->instances[$alias]; } // Die if we don't know what class to use. if (empty($this->services[$alias])) { throw new \InvalidArgumentException('Unable to find class with alias: '. $alias); } $instance = $this->make($alias, true); $this->instances[$alias] =& $instance; return $this->instances[$alias]; }
[ "public", "function", "single", "(", "$", "alias", ")", "{", "$", "alias", "=", "strtolower", "(", "$", "alias", ")", ";", "// Return the existing object if it exists.", "if", "(", "!", "empty", "(", "$", "this", "->", "instances", "[", "$", "alias", "]", ")", "&&", "is_object", "(", "$", "this", "->", "instances", "[", "$", "alias", "]", ")", ")", "{", "return", "$", "this", "->", "instances", "[", "$", "alias", "]", ";", "}", "// Die if we don't know what class to use.", "if", "(", "empty", "(", "$", "this", "->", "services", "[", "$", "alias", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Unable to find class with alias: '", ".", "$", "alias", ")", ";", "}", "$", "instance", "=", "$", "this", "->", "make", "(", "$", "alias", ",", "true", ")", ";", "$", "this", "->", "instances", "[", "$", "alias", "]", "=", "&", "$", "instance", ";", "return", "$", "this", "->", "instances", "[", "$", "alias", "]", ";", "}" ]
Allows you to create a new instance of an object as a singleton, passing in arguments. @param $alias @return mixed
[ "Allows", "you", "to", "create", "a", "new", "instance", "of", "an", "object", "as", "a", "singleton", "passing", "in", "arguments", "." ]
train
https://github.com/newmythmedia/di/blob/bc7397ea447de6a2d7564d7c95abf03f15e7756a/src/DI.php#L242-L263
newmythmedia/di
src/DI.php
DI.inject
protected function inject($service, $single=false) { $mirror = new \ReflectionClass($service); $constructor = $mirror->getConstructor(); $params = null; if (empty($constructor)) { return new $service(); } $params = $this->getParams($constructor, $single); // No params means we simply create a new // instance of the class and return it... if (is_null($params)) { return new $service(); } // Still here - then return an instance // with those params as arguments return $mirror->newInstanceArgs($params); }
php
protected function inject($service, $single=false) { $mirror = new \ReflectionClass($service); $constructor = $mirror->getConstructor(); $params = null; if (empty($constructor)) { return new $service(); } $params = $this->getParams($constructor, $single); // No params means we simply create a new // instance of the class and return it... if (is_null($params)) { return new $service(); } // Still here - then return an instance // with those params as arguments return $mirror->newInstanceArgs($params); }
[ "protected", "function", "inject", "(", "$", "service", ",", "$", "single", "=", "false", ")", "{", "$", "mirror", "=", "new", "\\", "ReflectionClass", "(", "$", "service", ")", ";", "$", "constructor", "=", "$", "mirror", "->", "getConstructor", "(", ")", ";", "$", "params", "=", "null", ";", "if", "(", "empty", "(", "$", "constructor", ")", ")", "{", "return", "new", "$", "service", "(", ")", ";", "}", "$", "params", "=", "$", "this", "->", "getParams", "(", "$", "constructor", ",", "$", "single", ")", ";", "// No params means we simply create a new", "// instance of the class and return it...", "if", "(", "is_null", "(", "$", "params", ")", ")", "{", "return", "new", "$", "service", "(", ")", ";", "}", "// Still here - then return an instance", "// with those params as arguments", "return", "$", "mirror", "->", "newInstanceArgs", "(", "$", "params", ")", ";", "}" ]
Determines the classes needed, creates instances (or uses existing instances, if exists) to pass in constructor and returns a new instance of the desired service. @param $service @return null|object
[ "Determines", "the", "classes", "needed", "creates", "instances", "(", "or", "uses", "existing", "instances", "if", "exists", ")", "to", "pass", "in", "constructor", "and", "returns", "a", "new", "instance", "of", "the", "desired", "service", "." ]
train
https://github.com/newmythmedia/di/blob/bc7397ea447de6a2d7564d7c95abf03f15e7756a/src/DI.php#L366-L390
newmythmedia/di
src/DI.php
DI.getParams
protected function getParams(\ReflectionMethod $mirror, $single=false) { $params = []; foreach ($mirror->getParameters() as $param) { $alias = strtolower($param->name); // Is this a mapped alias? if (! empty($this->services[$alias])) { $params[] = $single ? $this->single($alias) : $this->make($alias); continue; } // Is this a normal class we can give them? $class = $param->getClass()->name; if (class_exists($class)) { $params[] = new $class(); } $params[] = null; } return $params; }
php
protected function getParams(\ReflectionMethod $mirror, $single=false) { $params = []; foreach ($mirror->getParameters() as $param) { $alias = strtolower($param->name); // Is this a mapped alias? if (! empty($this->services[$alias])) { $params[] = $single ? $this->single($alias) : $this->make($alias); continue; } // Is this a normal class we can give them? $class = $param->getClass()->name; if (class_exists($class)) { $params[] = new $class(); } $params[] = null; } return $params; }
[ "protected", "function", "getParams", "(", "\\", "ReflectionMethod", "$", "mirror", ",", "$", "single", "=", "false", ")", "{", "$", "params", "=", "[", "]", ";", "foreach", "(", "$", "mirror", "->", "getParameters", "(", ")", "as", "$", "param", ")", "{", "$", "alias", "=", "strtolower", "(", "$", "param", "->", "name", ")", ";", "// Is this a mapped alias?", "if", "(", "!", "empty", "(", "$", "this", "->", "services", "[", "$", "alias", "]", ")", ")", "{", "$", "params", "[", "]", "=", "$", "single", "?", "$", "this", "->", "single", "(", "$", "alias", ")", ":", "$", "this", "->", "make", "(", "$", "alias", ")", ";", "continue", ";", "}", "// Is this a normal class we can give them?", "$", "class", "=", "$", "param", "->", "getClass", "(", ")", "->", "name", ";", "if", "(", "class_exists", "(", "$", "class", ")", ")", "{", "$", "params", "[", "]", "=", "new", "$", "class", "(", ")", ";", "}", "$", "params", "[", "]", "=", "null", ";", "}", "return", "$", "params", ";", "}" ]
Given a reflection method, will get or create an array of objects ready to be inserted into the class' constructor. If $single is true, will return a singleton version of dependencies else will create a new class. @param \ReflectionMethod $mirror @param bool $single @return array
[ "Given", "a", "reflection", "method", "will", "get", "or", "create", "an", "array", "of", "objects", "ready", "to", "be", "inserted", "into", "the", "class", "constructor", "." ]
train
https://github.com/newmythmedia/di/blob/bc7397ea447de6a2d7564d7c95abf03f15e7756a/src/DI.php#L406-L433
newmythmedia/di
src/DI.php
DI.reset
protected function reset() { $this->parameters = []; $this->instances = []; $this->services = []; static::$instance = null; unset(static::$instance); }
php
protected function reset() { $this->parameters = []; $this->instances = []; $this->services = []; static::$instance = null; unset(static::$instance); }
[ "protected", "function", "reset", "(", ")", "{", "$", "this", "->", "parameters", "=", "[", "]", ";", "$", "this", "->", "instances", "=", "[", "]", ";", "$", "this", "->", "services", "=", "[", "]", ";", "static", "::", "$", "instance", "=", "null", ";", "unset", "(", "static", "::", "$", "instance", ")", ";", "}" ]
--------------------------------------------------------------------
[ "--------------------------------------------------------------------" ]
train
https://github.com/newmythmedia/di/blob/bc7397ea447de6a2d7564d7c95abf03f15e7756a/src/DI.php#L437-L445
gregorybesson/PlaygroundCms
src/Entity/Page.php
Page.populate
public function populate($data = array()) { foreach (array('title', 'meta_keywords', 'meta_description', 'content', 'heading', 'category') as $attr) { if (isset($data[$attr]) && $data[$attr]!= null) { $this->$attr = $data[$attr]; } } foreach (array('active', 'sort_order', 'pushHome', 'displayHome') as $attr) { if (isset($data[$attr])) { $this->$attr = (bool) $data[$attr]; } } if (isset($data['category']) && $data['category']!= null) { $this->category = (int) $data['category']; } }
php
public function populate($data = array()) { foreach (array('title', 'meta_keywords', 'meta_description', 'content', 'heading', 'category') as $attr) { if (isset($data[$attr]) && $data[$attr]!= null) { $this->$attr = $data[$attr]; } } foreach (array('active', 'sort_order', 'pushHome', 'displayHome') as $attr) { if (isset($data[$attr])) { $this->$attr = (bool) $data[$attr]; } } if (isset($data['category']) && $data['category']!= null) { $this->category = (int) $data['category']; } }
[ "public", "function", "populate", "(", "$", "data", "=", "array", "(", ")", ")", "{", "foreach", "(", "array", "(", "'title'", ",", "'meta_keywords'", ",", "'meta_description'", ",", "'content'", ",", "'heading'", ",", "'category'", ")", "as", "$", "attr", ")", "{", "if", "(", "isset", "(", "$", "data", "[", "$", "attr", "]", ")", "&&", "$", "data", "[", "$", "attr", "]", "!=", "null", ")", "{", "$", "this", "->", "$", "attr", "=", "$", "data", "[", "$", "attr", "]", ";", "}", "}", "foreach", "(", "array", "(", "'active'", ",", "'sort_order'", ",", "'pushHome'", ",", "'displayHome'", ")", "as", "$", "attr", ")", "{", "if", "(", "isset", "(", "$", "data", "[", "$", "attr", "]", ")", ")", "{", "$", "this", "->", "$", "attr", "=", "(", "bool", ")", "$", "data", "[", "$", "attr", "]", ";", "}", "}", "if", "(", "isset", "(", "$", "data", "[", "'category'", "]", ")", "&&", "$", "data", "[", "'category'", "]", "!=", "null", ")", "{", "$", "this", "->", "category", "=", "(", "int", ")", "$", "data", "[", "'category'", "]", ";", "}", "}" ]
Populate from an array. @param array $data
[ "Populate", "from", "an", "array", "." ]
train
https://github.com/gregorybesson/PlaygroundCms/blob/e929a283f2a6e82d4f248c930f7aa454ce20cbc3/src/Entity/Page.php#L509-L524
raideer/twitch-api
src/Resources/Videos.php
Videos.getTopVideos
public function getTopVideos($params = []) { $defaults = [ 'limit' => 10, 'offset' => 0, 'game' => null, 'period' => 'week', ]; $values = [ 'period' => ['week', 'month', 'all'], ]; return $this->wrapper->request('GET', 'videos/top', ['query' => $this->resolveOptions($params, $defaults, [], $values)]); }
php
public function getTopVideos($params = []) { $defaults = [ 'limit' => 10, 'offset' => 0, 'game' => null, 'period' => 'week', ]; $values = [ 'period' => ['week', 'month', 'all'], ]; return $this->wrapper->request('GET', 'videos/top', ['query' => $this->resolveOptions($params, $defaults, [], $values)]); }
[ "public", "function", "getTopVideos", "(", "$", "params", "=", "[", "]", ")", "{", "$", "defaults", "=", "[", "'limit'", "=>", "10", ",", "'offset'", "=>", "0", ",", "'game'", "=>", "null", ",", "'period'", "=>", "'week'", ",", "]", ";", "$", "values", "=", "[", "'period'", "=>", "[", "'week'", ",", "'month'", ",", "'all'", "]", ",", "]", ";", "return", "$", "this", "->", "wrapper", "->", "request", "(", "'GET'", ",", "'videos/top'", ",", "[", "'query'", "=>", "$", "this", "->", "resolveOptions", "(", "$", "params", ",", "$", "defaults", ",", "[", "]", ",", "$", "values", ")", "]", ")", ";", "}" ]
Returns a list of videos created in a given time period sorted by number of views, most popular first. Learn more: https://github.com/justintv/Twitch-API/blob/master/v3_resources/videos.md#get-videostop @param array $params Optional params @return array
[ "Returns", "a", "list", "of", "videos", "created", "in", "a", "given", "time", "period", "sorted", "by", "number", "of", "views", "most", "popular", "first", "." ]
train
https://github.com/raideer/twitch-api/blob/27ebf1dcb0315206300d507600b6a82ebe33d57e/src/Resources/Videos.php#L45-L59
raideer/twitch-api
src/Resources/Videos.php
Videos.getChannelVideos
public function getChannelVideos($channel, $params = []) { $defaults = [ 'limit' => 10, 'offset' => 0, 'broadcasts' => false, 'hls' => false, ]; $values = [ 'hls' => [true, false], 'broadcasts' => [true, false], ]; return $this->wrapper->request('GET', "channels/$channel/videos", ['query' => $this->resolveOptions($params, $defaults, [], $values)]); }
php
public function getChannelVideos($channel, $params = []) { $defaults = [ 'limit' => 10, 'offset' => 0, 'broadcasts' => false, 'hls' => false, ]; $values = [ 'hls' => [true, false], 'broadcasts' => [true, false], ]; return $this->wrapper->request('GET', "channels/$channel/videos", ['query' => $this->resolveOptions($params, $defaults, [], $values)]); }
[ "public", "function", "getChannelVideos", "(", "$", "channel", ",", "$", "params", "=", "[", "]", ")", "{", "$", "defaults", "=", "[", "'limit'", "=>", "10", ",", "'offset'", "=>", "0", ",", "'broadcasts'", "=>", "false", ",", "'hls'", "=>", "false", ",", "]", ";", "$", "values", "=", "[", "'hls'", "=>", "[", "true", ",", "false", "]", ",", "'broadcasts'", "=>", "[", "true", ",", "false", "]", ",", "]", ";", "return", "$", "this", "->", "wrapper", "->", "request", "(", "'GET'", ",", "\"channels/$channel/videos\"", ",", "[", "'query'", "=>", "$", "this", "->", "resolveOptions", "(", "$", "params", ",", "$", "defaults", ",", "[", "]", ",", "$", "values", ")", "]", ")", ";", "}" ]
Returns a list of videos ordered by time of creation, starting with the most recent from $channel. Learn more: https://github.com/justintv/Twitch-API/blob/master/v3_resources/videos.md#get-channelschannelvideos @param string $channel Target channel @param array $params Optional params @return array
[ "Returns", "a", "list", "of", "videos", "ordered", "by", "time", "of", "creation", "starting", "with", "the", "most", "recent", "from", "$channel", "." ]
train
https://github.com/raideer/twitch-api/blob/27ebf1dcb0315206300d507600b6a82ebe33d57e/src/Resources/Videos.php#L73-L88
SporkCode/Spork
src/CSS/AbstractCompiler.php
AbstractCompiler.compile
public function compile($source, $destination = null, $include = null) { $include = array_merge($this->includes, (array) $include); $useCache = null == $destination && null !== $this->cache; if ($useCache) { if ($this->cache->hasItem($source)) { return $this->cache->getItem($source); } } $arguments = implode(' ', array_map('escapeshellarg', $this->arguments)); $arguments .= ' ' . $this->getCommandArguments($source, $destination, $include); $command = "{$this->compiler} $arguments" . ' 2>&1'; $result = exec($command, $output, $exitCode); if ($exitCode != 0) { throw new \Exception(sprintf('Error compiling CSS "%s": %s', $source, implode(PHP_EOL, $output))); } $css = implode(PHP_EOL, $output); if ($useCache) { $this->cache->setItem($source, $css); } return $css; }
php
public function compile($source, $destination = null, $include = null) { $include = array_merge($this->includes, (array) $include); $useCache = null == $destination && null !== $this->cache; if ($useCache) { if ($this->cache->hasItem($source)) { return $this->cache->getItem($source); } } $arguments = implode(' ', array_map('escapeshellarg', $this->arguments)); $arguments .= ' ' . $this->getCommandArguments($source, $destination, $include); $command = "{$this->compiler} $arguments" . ' 2>&1'; $result = exec($command, $output, $exitCode); if ($exitCode != 0) { throw new \Exception(sprintf('Error compiling CSS "%s": %s', $source, implode(PHP_EOL, $output))); } $css = implode(PHP_EOL, $output); if ($useCache) { $this->cache->setItem($source, $css); } return $css; }
[ "public", "function", "compile", "(", "$", "source", ",", "$", "destination", "=", "null", ",", "$", "include", "=", "null", ")", "{", "$", "include", "=", "array_merge", "(", "$", "this", "->", "includes", ",", "(", "array", ")", "$", "include", ")", ";", "$", "useCache", "=", "null", "==", "$", "destination", "&&", "null", "!==", "$", "this", "->", "cache", ";", "if", "(", "$", "useCache", ")", "{", "if", "(", "$", "this", "->", "cache", "->", "hasItem", "(", "$", "source", ")", ")", "{", "return", "$", "this", "->", "cache", "->", "getItem", "(", "$", "source", ")", ";", "}", "}", "$", "arguments", "=", "implode", "(", "' '", ",", "array_map", "(", "'escapeshellarg'", ",", "$", "this", "->", "arguments", ")", ")", ";", "$", "arguments", ".=", "' '", ".", "$", "this", "->", "getCommandArguments", "(", "$", "source", ",", "$", "destination", ",", "$", "include", ")", ";", "$", "command", "=", "\"{$this->compiler} $arguments\"", ".", "' 2>&1'", ";", "$", "result", "=", "exec", "(", "$", "command", ",", "$", "output", ",", "$", "exitCode", ")", ";", "if", "(", "$", "exitCode", "!=", "0", ")", "{", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "'Error compiling CSS \"%s\": %s'", ",", "$", "source", ",", "implode", "(", "PHP_EOL", ",", "$", "output", ")", ")", ")", ";", "}", "$", "css", "=", "implode", "(", "PHP_EOL", ",", "$", "output", ")", ";", "if", "(", "$", "useCache", ")", "{", "$", "this", "->", "cache", "->", "setItem", "(", "$", "source", ",", "$", "css", ")", ";", "}", "return", "$", "css", ";", "}" ]
Compile to file. If destination is not specified return CSS. @param string $source @param string|null $destination @param array|string|null $include Include path(s) to use @throws \Exception on compilation error @return string Compiled CSS
[ "Compile", "to", "file", ".", "If", "destination", "is", "not", "specified", "return", "CSS", "." ]
train
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/CSS/AbstractCompiler.php#L91-L122
SporkCode/Spork
src/CSS/AbstractCompiler.php
AbstractCompiler.setCache
public function setCache($cache) { if (is_string($cache) && class_exists($cache)) { $cache = new $cache(); } if (is_array($cache)) { $cache = StorageFactory::factory($cache); } if (!$cache instanceof AbstractCacheAdapter) { throw new \Exception('Invalid Cache'); } $this->cache = $cache; }
php
public function setCache($cache) { if (is_string($cache) && class_exists($cache)) { $cache = new $cache(); } if (is_array($cache)) { $cache = StorageFactory::factory($cache); } if (!$cache instanceof AbstractCacheAdapter) { throw new \Exception('Invalid Cache'); } $this->cache = $cache; }
[ "public", "function", "setCache", "(", "$", "cache", ")", "{", "if", "(", "is_string", "(", "$", "cache", ")", "&&", "class_exists", "(", "$", "cache", ")", ")", "{", "$", "cache", "=", "new", "$", "cache", "(", ")", ";", "}", "if", "(", "is_array", "(", "$", "cache", ")", ")", "{", "$", "cache", "=", "StorageFactory", "::", "factory", "(", "$", "cache", ")", ";", "}", "if", "(", "!", "$", "cache", "instanceof", "AbstractCacheAdapter", ")", "{", "throw", "new", "\\", "Exception", "(", "'Invalid Cache'", ")", ";", "}", "$", "this", "->", "cache", "=", "$", "cache", ";", "}" ]
Set cache for CSS Preprocessor Cache parameter can be an instance of \Zend\Cache\Storage\Adapter\AbstractAdapter, the name of a cache adapter class or an array of options to be passed to AbstractAdapter::factory() @param string|array|\Zend\Cache\Storage\Adapter\AbstractAdapter $cache @throws \Exception on invalid cache
[ "Set", "cache", "for", "CSS", "Preprocessor" ]
train
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/CSS/AbstractCompiler.php#L162-L177
SporkCode/Spork
src/CSS/AbstractCompiler.php
AbstractCompiler.createService
public function createService(ServiceLocatorInterface $services) { if (null !== $this->configurationKey) { $this->configure($this->getOptions($services, $this->configurationKey)); } return $this; }
php
public function createService(ServiceLocatorInterface $services) { if (null !== $this->configurationKey) { $this->configure($this->getOptions($services, $this->configurationKey)); } return $this; }
[ "public", "function", "createService", "(", "ServiceLocatorInterface", "$", "services", ")", "{", "if", "(", "null", "!==", "$", "this", "->", "configurationKey", ")", "{", "$", "this", "->", "configure", "(", "$", "this", "->", "getOptions", "(", "$", "services", ",", "$", "this", "->", "configurationKey", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Create Service @see \Zend\ServiceManager\FactoryInterface::createService() @param ServiceLocatorInterface $services @return \Spork\Style\AbstractStyle
[ "Create", "Service" ]
train
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/CSS/AbstractCompiler.php#L276-L283
SporkCode/Spork
src/CSS/AbstractCompiler.php
AbstractCompiler.configure
protected function configure(array $options) { foreach ($options as $key => $value) { switch (strtolower($key)) { case 'arguments': $this->setArguments($value); break; case 'cache': $this->setCache($value); break; case 'compiler': $this->setCompiler($value); break; case 'compress': $this->setCompress($value); break; case 'extension': $this->setExtension($value); break; case 'includes': $this->setIncludes($value); break; } } }
php
protected function configure(array $options) { foreach ($options as $key => $value) { switch (strtolower($key)) { case 'arguments': $this->setArguments($value); break; case 'cache': $this->setCache($value); break; case 'compiler': $this->setCompiler($value); break; case 'compress': $this->setCompress($value); break; case 'extension': $this->setExtension($value); break; case 'includes': $this->setIncludes($value); break; } } }
[ "protected", "function", "configure", "(", "array", "$", "options", ")", "{", "foreach", "(", "$", "options", "as", "$", "key", "=>", "$", "value", ")", "{", "switch", "(", "strtolower", "(", "$", "key", ")", ")", "{", "case", "'arguments'", ":", "$", "this", "->", "setArguments", "(", "$", "value", ")", ";", "break", ";", "case", "'cache'", ":", "$", "this", "->", "setCache", "(", "$", "value", ")", ";", "break", ";", "case", "'compiler'", ":", "$", "this", "->", "setCompiler", "(", "$", "value", ")", ";", "break", ";", "case", "'compress'", ":", "$", "this", "->", "setCompress", "(", "$", "value", ")", ";", "break", ";", "case", "'extension'", ":", "$", "this", "->", "setExtension", "(", "$", "value", ")", ";", "break", ";", "case", "'includes'", ":", "$", "this", "->", "setIncludes", "(", "$", "value", ")", ";", "break", ";", "}", "}", "}" ]
configure @param array $options
[ "configure" ]
train
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/CSS/AbstractCompiler.php#L289-L313
SporkCode/Spork
src/CSS/AbstractCompiler.php
AbstractCompiler.getOptions
protected function getOptions(ServiceLocatorInterface $services, $key) { $appConfig = $services->get('config'); $options = array_key_exists($key, $appConfig) ? $appConfig[$key] : array(); if (array_key_exists('cache', $options) && is_string($options['cache']) && $services->has($options['cache'])) { $options['cache'] = $services->get($options['cache']); } return $options; }
php
protected function getOptions(ServiceLocatorInterface $services, $key) { $appConfig = $services->get('config'); $options = array_key_exists($key, $appConfig) ? $appConfig[$key] : array(); if (array_key_exists('cache', $options) && is_string($options['cache']) && $services->has($options['cache'])) { $options['cache'] = $services->get($options['cache']); } return $options; }
[ "protected", "function", "getOptions", "(", "ServiceLocatorInterface", "$", "services", ",", "$", "key", ")", "{", "$", "appConfig", "=", "$", "services", "->", "get", "(", "'config'", ")", ";", "$", "options", "=", "array_key_exists", "(", "$", "key", ",", "$", "appConfig", ")", "?", "$", "appConfig", "[", "$", "key", "]", ":", "array", "(", ")", ";", "if", "(", "array_key_exists", "(", "'cache'", ",", "$", "options", ")", "&&", "is_string", "(", "$", "options", "[", "'cache'", "]", ")", "&&", "$", "services", "->", "has", "(", "$", "options", "[", "'cache'", "]", ")", ")", "{", "$", "options", "[", "'cache'", "]", "=", "$", "services", "->", "get", "(", "$", "options", "[", "'cache'", "]", ")", ";", "}", "return", "$", "options", ";", "}" ]
Get options from application configuration @param ServiceLocatorInterface $services @param string $key @return array
[ "Get", "options", "from", "application", "configuration" ]
train
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/CSS/AbstractCompiler.php#L322-L332
zhouyl/mellivora
Mellivora/Application/Dispatcher.php
Dispatcher.detectControllerClass
protected function detectControllerClass(array $args) { $class = str_replace('\\\\', '\\', sprintf( '\%s\%s\%sController', $args['namespace'], Str::studly($args['module']), Str::studly($args['controller']) )); if (!class_exists($class)) { throw new NotFoundException( $this->container['request'], $this->container['response'] ); } // controller 类型检测 if (!is_subclass_of($class, Controller::class)) { throw new UnexpectedValueException( $class . ' must return instance of ' . Controller::class ); } return $class; }
php
protected function detectControllerClass(array $args) { $class = str_replace('\\\\', '\\', sprintf( '\%s\%s\%sController', $args['namespace'], Str::studly($args['module']), Str::studly($args['controller']) )); if (!class_exists($class)) { throw new NotFoundException( $this->container['request'], $this->container['response'] ); } // controller 类型检测 if (!is_subclass_of($class, Controller::class)) { throw new UnexpectedValueException( $class . ' must return instance of ' . Controller::class ); } return $class; }
[ "protected", "function", "detectControllerClass", "(", "array", "$", "args", ")", "{", "$", "class", "=", "str_replace", "(", "'\\\\\\\\'", ",", "'\\\\'", ",", "sprintf", "(", "'\\%s\\%s\\%sController'", ",", "$", "args", "[", "'namespace'", "]", ",", "Str", "::", "studly", "(", "$", "args", "[", "'module'", "]", ")", ",", "Str", "::", "studly", "(", "$", "args", "[", "'controller'", "]", ")", ")", ")", ";", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "throw", "new", "NotFoundException", "(", "$", "this", "->", "container", "[", "'request'", "]", ",", "$", "this", "->", "container", "[", "'response'", "]", ")", ";", "}", "// controller 类型检测", "if", "(", "!", "is_subclass_of", "(", "$", "class", ",", "Controller", "::", "class", ")", ")", "{", "throw", "new", "UnexpectedValueException", "(", "$", "class", ".", "' must return instance of '", ".", "Controller", "::", "class", ")", ";", "}", "return", "$", "class", ";", "}" ]
检测 controller 的 class 类型 @param array $args @throws \Slim\Exception\NotFoundException|\UnexpectedValueException @return string
[ "检测", "controller", "的", "class", "类型" ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Application/Dispatcher.php#L39-L63
cartalyst/assetic-filters
src/UriRewriteFilter.php
UriRewriteFilter.realPath
protected function realPath($path) { if (php_sapi_name() == 'cli' && ! $path) { $path = $_SERVER['DOCUMENT_ROOT']; } if ($realPath = realpath($path)) { $path = $realPath; } return rtrim($path, '/\\'); }
php
protected function realPath($path) { if (php_sapi_name() == 'cli' && ! $path) { $path = $_SERVER['DOCUMENT_ROOT']; } if ($realPath = realpath($path)) { $path = $realPath; } return rtrim($path, '/\\'); }
[ "protected", "function", "realPath", "(", "$", "path", ")", "{", "if", "(", "php_sapi_name", "(", ")", "==", "'cli'", "&&", "!", "$", "path", ")", "{", "$", "path", "=", "$", "_SERVER", "[", "'DOCUMENT_ROOT'", "]", ";", "}", "if", "(", "$", "realPath", "=", "realpath", "(", "$", "path", ")", ")", "{", "$", "path", "=", "$", "realPath", ";", "}", "return", "rtrim", "(", "$", "path", ",", "'/\\\\'", ")", ";", "}" ]
Takes a path and transforms it to a real path. @param string $path @return string
[ "Takes", "a", "path", "and", "transforms", "it", "to", "a", "real", "path", "." ]
train
https://github.com/cartalyst/assetic-filters/blob/5e26328f7e46937bf1daa0bee2f744ab3493f471/src/UriRewriteFilter.php#L165-L176
cartalyst/assetic-filters
src/UriRewriteFilter.php
UriRewriteFilter.processUriCallback
protected function processUriCallback($matches) { $scriptName = basename($this->getRequest()->getScriptName()); $isImport = $matches[0][0] === '@'; // Determine what the quote character and the URI is, if there is one. $quoteCharacter = $uri = null; if ($isImport) { $quoteCharacter = $matches[1]; $uri = $matches[2]; } else { if ($matches[1][0] === "'" or $matches[1][0] === '"') { $quoteCharacter = $matches[1][0]; } if ( ! $quoteCharacter) { $uri = $matches[1]; } else { $uri = substr($matches[1], 1, strlen($matches[1]) - 2); } } // Strip off the scriptname $uri = str_replace($scriptName.'/', '', $uri); // Analyze the URI if ($uri[0] !== '/' and strpos($uri, '//') === false and strpos($uri, 'data') !== 0) { $uri = $this->rewriteAbsolute($uri); } if ($isImport) { return "@import {$quoteCharacter}{$uri}{$quoteCharacter}"; } return "url({$quoteCharacter}{$uri}{$quoteCharacter})"; }
php
protected function processUriCallback($matches) { $scriptName = basename($this->getRequest()->getScriptName()); $isImport = $matches[0][0] === '@'; // Determine what the quote character and the URI is, if there is one. $quoteCharacter = $uri = null; if ($isImport) { $quoteCharacter = $matches[1]; $uri = $matches[2]; } else { if ($matches[1][0] === "'" or $matches[1][0] === '"') { $quoteCharacter = $matches[1][0]; } if ( ! $quoteCharacter) { $uri = $matches[1]; } else { $uri = substr($matches[1], 1, strlen($matches[1]) - 2); } } // Strip off the scriptname $uri = str_replace($scriptName.'/', '', $uri); // Analyze the URI if ($uri[0] !== '/' and strpos($uri, '//') === false and strpos($uri, 'data') !== 0) { $uri = $this->rewriteAbsolute($uri); } if ($isImport) { return "@import {$quoteCharacter}{$uri}{$quoteCharacter}"; } return "url({$quoteCharacter}{$uri}{$quoteCharacter})"; }
[ "protected", "function", "processUriCallback", "(", "$", "matches", ")", "{", "$", "scriptName", "=", "basename", "(", "$", "this", "->", "getRequest", "(", ")", "->", "getScriptName", "(", ")", ")", ";", "$", "isImport", "=", "$", "matches", "[", "0", "]", "[", "0", "]", "===", "'@'", ";", "// Determine what the quote character and the URI is, if there is one.", "$", "quoteCharacter", "=", "$", "uri", "=", "null", ";", "if", "(", "$", "isImport", ")", "{", "$", "quoteCharacter", "=", "$", "matches", "[", "1", "]", ";", "$", "uri", "=", "$", "matches", "[", "2", "]", ";", "}", "else", "{", "if", "(", "$", "matches", "[", "1", "]", "[", "0", "]", "===", "\"'\"", "or", "$", "matches", "[", "1", "]", "[", "0", "]", "===", "'\"'", ")", "{", "$", "quoteCharacter", "=", "$", "matches", "[", "1", "]", "[", "0", "]", ";", "}", "if", "(", "!", "$", "quoteCharacter", ")", "{", "$", "uri", "=", "$", "matches", "[", "1", "]", ";", "}", "else", "{", "$", "uri", "=", "substr", "(", "$", "matches", "[", "1", "]", ",", "1", ",", "strlen", "(", "$", "matches", "[", "1", "]", ")", "-", "2", ")", ";", "}", "}", "// Strip off the scriptname", "$", "uri", "=", "str_replace", "(", "$", "scriptName", ".", "'/'", ",", "''", ",", "$", "uri", ")", ";", "// Analyze the URI", "if", "(", "$", "uri", "[", "0", "]", "!==", "'/'", "and", "strpos", "(", "$", "uri", ",", "'//'", ")", "===", "false", "and", "strpos", "(", "$", "uri", ",", "'data'", ")", "!==", "0", ")", "{", "$", "uri", "=", "$", "this", "->", "rewriteAbsolute", "(", "$", "uri", ")", ";", "}", "if", "(", "$", "isImport", ")", "{", "return", "\"@import {$quoteCharacter}{$uri}{$quoteCharacter}\"", ";", "}", "return", "\"url({$quoteCharacter}{$uri}{$quoteCharacter})\"", ";", "}" ]
Processes a regular expression callback, determines the URI and returns the rewritten URIs. @param array $matches @return string
[ "Processes", "a", "regular", "expression", "callback", "determines", "the", "URI", "and", "returns", "the", "rewritten", "URIs", "." ]
train
https://github.com/cartalyst/assetic-filters/blob/5e26328f7e46937bf1daa0bee2f744ab3493f471/src/UriRewriteFilter.php#L195-L233
cartalyst/assetic-filters
src/UriRewriteFilter.php
UriRewriteFilter.rewriteAbsolute
protected function rewriteAbsolute($uri) { $request = $this->getRequest(); $path = strtr($this->assetDirectory, '/', DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.strtr($uri, '/', DIRECTORY_SEPARATOR); foreach ($this->symlinks as $link => $target) { if (strpos($path, $target) === 0) { $path = $link.substr($path, strlen($target)); break; } } $base = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null; if ($request->getHost()) { $base = $request->getSchemeAndHttpHost().$request->getBaseUrl(); } // Strip the document root from the path. if (strpos($path, app('path.public')) !== false) { $path = str_replace(app('path.public'), '', $path); } elseif (strpos($path, app('path.resources')) !== false) { $path = str_replace(app('path.resources'), '', $path); } $uri = strtr($path, '/\\', '//'); $uri = $this->removeDots($uri); return $uri; }
php
protected function rewriteAbsolute($uri) { $request = $this->getRequest(); $path = strtr($this->assetDirectory, '/', DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.strtr($uri, '/', DIRECTORY_SEPARATOR); foreach ($this->symlinks as $link => $target) { if (strpos($path, $target) === 0) { $path = $link.substr($path, strlen($target)); break; } } $base = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null; if ($request->getHost()) { $base = $request->getSchemeAndHttpHost().$request->getBaseUrl(); } // Strip the document root from the path. if (strpos($path, app('path.public')) !== false) { $path = str_replace(app('path.public'), '', $path); } elseif (strpos($path, app('path.resources')) !== false) { $path = str_replace(app('path.resources'), '', $path); } $uri = strtr($path, '/\\', '//'); $uri = $this->removeDots($uri); return $uri; }
[ "protected", "function", "rewriteAbsolute", "(", "$", "uri", ")", "{", "$", "request", "=", "$", "this", "->", "getRequest", "(", ")", ";", "$", "path", "=", "strtr", "(", "$", "this", "->", "assetDirectory", ",", "'/'", ",", "DIRECTORY_SEPARATOR", ")", ".", "DIRECTORY_SEPARATOR", ".", "strtr", "(", "$", "uri", ",", "'/'", ",", "DIRECTORY_SEPARATOR", ")", ";", "foreach", "(", "$", "this", "->", "symlinks", "as", "$", "link", "=>", "$", "target", ")", "{", "if", "(", "strpos", "(", "$", "path", ",", "$", "target", ")", "===", "0", ")", "{", "$", "path", "=", "$", "link", ".", "substr", "(", "$", "path", ",", "strlen", "(", "$", "target", ")", ")", ";", "break", ";", "}", "}", "$", "base", "=", "isset", "(", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ")", "?", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ":", "null", ";", "if", "(", "$", "request", "->", "getHost", "(", ")", ")", "{", "$", "base", "=", "$", "request", "->", "getSchemeAndHttpHost", "(", ")", ".", "$", "request", "->", "getBaseUrl", "(", ")", ";", "}", "// Strip the document root from the path.", "if", "(", "strpos", "(", "$", "path", ",", "app", "(", "'path.public'", ")", ")", "!==", "false", ")", "{", "$", "path", "=", "str_replace", "(", "app", "(", "'path.public'", ")", ",", "''", ",", "$", "path", ")", ";", "}", "elseif", "(", "strpos", "(", "$", "path", ",", "app", "(", "'path.resources'", ")", ")", "!==", "false", ")", "{", "$", "path", "=", "str_replace", "(", "app", "(", "'path.resources'", ")", ",", "''", ",", "$", "path", ")", ";", "}", "$", "uri", "=", "strtr", "(", "$", "path", ",", "'/\\\\'", ",", "'//'", ")", ";", "$", "uri", "=", "$", "this", "->", "removeDots", "(", "$", "uri", ")", ";", "return", "$", "uri", ";", "}" ]
Rewrites a relative URI. @param string $uri @return string
[ "Rewrites", "a", "relative", "URI", "." ]
train
https://github.com/cartalyst/assetic-filters/blob/5e26328f7e46937bf1daa0bee2f744ab3493f471/src/UriRewriteFilter.php#L241-L272
kenphp/ken
src/Log/Logger.php
Logger.applyConfig
private function applyConfig($config) { try { if (isset($config['enabledLevels'])) { $this->setEnabledLevels($config['enabledLevels']); } else { $this->setEnabledLevels(['error', 'warning']); } if (isset($config['flushIntervals'])) { $this->setFlushIntervals($config['flushIntervals']); } else { $this->setFlushIntervals(100); } if (isset($config['targets'])) { foreach ($config['targets'] as $key => $value) { if (isset($value['class'])) { $className = $value['class']; $this->_targets[$key] = $className::build($value); } } } } catch (InvalidConfigurationException $e) { $configStr = print_r($config, true); error_log('Invalid Configuration for Logger Component. '.PHP_EOL.$configStr); } }
php
private function applyConfig($config) { try { if (isset($config['enabledLevels'])) { $this->setEnabledLevels($config['enabledLevels']); } else { $this->setEnabledLevels(['error', 'warning']); } if (isset($config['flushIntervals'])) { $this->setFlushIntervals($config['flushIntervals']); } else { $this->setFlushIntervals(100); } if (isset($config['targets'])) { foreach ($config['targets'] as $key => $value) { if (isset($value['class'])) { $className = $value['class']; $this->_targets[$key] = $className::build($value); } } } } catch (InvalidConfigurationException $e) { $configStr = print_r($config, true); error_log('Invalid Configuration for Logger Component. '.PHP_EOL.$configStr); } }
[ "private", "function", "applyConfig", "(", "$", "config", ")", "{", "try", "{", "if", "(", "isset", "(", "$", "config", "[", "'enabledLevels'", "]", ")", ")", "{", "$", "this", "->", "setEnabledLevels", "(", "$", "config", "[", "'enabledLevels'", "]", ")", ";", "}", "else", "{", "$", "this", "->", "setEnabledLevels", "(", "[", "'error'", ",", "'warning'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "config", "[", "'flushIntervals'", "]", ")", ")", "{", "$", "this", "->", "setFlushIntervals", "(", "$", "config", "[", "'flushIntervals'", "]", ")", ";", "}", "else", "{", "$", "this", "->", "setFlushIntervals", "(", "100", ")", ";", "}", "if", "(", "isset", "(", "$", "config", "[", "'targets'", "]", ")", ")", "{", "foreach", "(", "$", "config", "[", "'targets'", "]", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "isset", "(", "$", "value", "[", "'class'", "]", ")", ")", "{", "$", "className", "=", "$", "value", "[", "'class'", "]", ";", "$", "this", "->", "_targets", "[", "$", "key", "]", "=", "$", "className", "::", "build", "(", "$", "value", ")", ";", "}", "}", "}", "}", "catch", "(", "InvalidConfigurationException", "$", "e", ")", "{", "$", "configStr", "=", "print_r", "(", "$", "config", ",", "true", ")", ";", "error_log", "(", "'Invalid Configuration for Logger Component. '", ".", "PHP_EOL", ".", "$", "configStr", ")", ";", "}", "}" ]
Applies log configuration @param array $config
[ "Applies", "log", "configuration" ]
train
https://github.com/kenphp/ken/blob/c454a86f0ab55c52c88e9bff5bc6fb4e7bd9e0eb/src/Log/Logger.php#L51-L79
kenphp/ken
src/Log/Logger.php
Logger.setEnabledLevels
public function setEnabledLevels(array $levels) { $enabledLevels = array(); foreach ($levels as $value) { if ($this->validLevel($value)) { array_push($enabledLevels, $value); } } $this->_enabledLevels = $enabledLevels; }
php
public function setEnabledLevels(array $levels) { $enabledLevels = array(); foreach ($levels as $value) { if ($this->validLevel($value)) { array_push($enabledLevels, $value); } } $this->_enabledLevels = $enabledLevels; }
[ "public", "function", "setEnabledLevels", "(", "array", "$", "levels", ")", "{", "$", "enabledLevels", "=", "array", "(", ")", ";", "foreach", "(", "$", "levels", "as", "$", "value", ")", "{", "if", "(", "$", "this", "->", "validLevel", "(", "$", "value", ")", ")", "{", "array_push", "(", "$", "enabledLevels", ",", "$", "value", ")", ";", "}", "}", "$", "this", "->", "_enabledLevels", "=", "$", "enabledLevels", ";", "}" ]
Sets enabled logging levels. @param array $levels
[ "Sets", "enabled", "logging", "levels", "." ]
train
https://github.com/kenphp/ken/blob/c454a86f0ab55c52c88e9bff5bc6fb4e7bd9e0eb/src/Log/Logger.php#L173-L184
raideer/twitch-api
src/Resources/Subscriptions.php
Subscriptions.getSubscribtions
public function getSubscribtions($channel, $params = []) { $this->wrapper->checkScope('channel_subscriptions'); $defaults = [ 'limit' => 25, 'offset' => 0, 'direction' => 'asc', ]; $values = [ 'direction' => ['asc', 'desc'], ]; return $this->wrapper->request('GET', "channels/$channel/subscriptions", ['query' => $this->resolveOptions($params, $defaults, [], $values)], true); }
php
public function getSubscribtions($channel, $params = []) { $this->wrapper->checkScope('channel_subscriptions'); $defaults = [ 'limit' => 25, 'offset' => 0, 'direction' => 'asc', ]; $values = [ 'direction' => ['asc', 'desc'], ]; return $this->wrapper->request('GET', "channels/$channel/subscriptions", ['query' => $this->resolveOptions($params, $defaults, [], $values)], true); }
[ "public", "function", "getSubscribtions", "(", "$", "channel", ",", "$", "params", "=", "[", "]", ")", "{", "$", "this", "->", "wrapper", "->", "checkScope", "(", "'channel_subscriptions'", ")", ";", "$", "defaults", "=", "[", "'limit'", "=>", "25", ",", "'offset'", "=>", "0", ",", "'direction'", "=>", "'asc'", ",", "]", ";", "$", "values", "=", "[", "'direction'", "=>", "[", "'asc'", ",", "'desc'", "]", ",", "]", ";", "return", "$", "this", "->", "wrapper", "->", "request", "(", "'GET'", ",", "\"channels/$channel/subscriptions\"", ",", "[", "'query'", "=>", "$", "this", "->", "resolveOptions", "(", "$", "params", ",", "$", "defaults", ",", "[", "]", ",", "$", "values", ")", "]", ",", "true", ")", ";", "}" ]
Returns a list of subscribtion objects sorted by subscribtion relationship creation date which contain users subscribed to $channel. Learn more: https://github.com/justintv/Twitch-API/blob/master/v3_resources/subscriptions.md#get-channelschannelsubscriptions @param string $channel Target channel @param array $params Optional params @return array
[ "Returns", "a", "list", "of", "subscribtion", "objects", "sorted", "by", "subscribtion", "relationship", "creation", "date", "which", "contain", "users", "subscribed", "to", "$channel", "." ]
train
https://github.com/raideer/twitch-api/blob/27ebf1dcb0315206300d507600b6a82ebe33d57e/src/Resources/Subscriptions.php#L32-L47
raideer/twitch-api
src/Resources/Subscriptions.php
Subscriptions.getSubscribtion
public function getSubscribtion($channel, $user) { $this->wrapper->checkScope('channel_check_subscription'); return $this->wrapper->request('GET', "channels/$channel/subscriptions/$user", [], true); }
php
public function getSubscribtion($channel, $user) { $this->wrapper->checkScope('channel_check_subscription'); return $this->wrapper->request('GET', "channels/$channel/subscriptions/$user", [], true); }
[ "public", "function", "getSubscribtion", "(", "$", "channel", ",", "$", "user", ")", "{", "$", "this", "->", "wrapper", "->", "checkScope", "(", "'channel_check_subscription'", ")", ";", "return", "$", "this", "->", "wrapper", "->", "request", "(", "'GET'", ",", "\"channels/$channel/subscriptions/$user\"", ",", "[", "]", ",", "true", ")", ";", "}" ]
Returns a subscribtion object which includes the user is subscribed Requires authentication for $channel. Learn more: https://github.com/justintv/Twitch-API/blob/master/v3_resources/subscriptions.md#get-channelschannelsubscriptionsuser @param string $channel Target channel @param string $user Target user @return array
[ "Returns", "a", "subscribtion", "object", "which", "includes", "the", "user", "is", "subscribed", "Requires", "authentication", "for", "$channel", "." ]
train
https://github.com/raideer/twitch-api/blob/27ebf1dcb0315206300d507600b6a82ebe33d57e/src/Resources/Subscriptions.php#L61-L66
raideer/twitch-api
src/Resources/Subscriptions.php
Subscriptions.getUserSubscribtion
public function getUserSubscribtion($user, $channel) { $this->wrapper->checkScope('user_subscriptions'); return $this->wrapper->request('GET', "users/$user/subscriptions/$channel", [], true); }
php
public function getUserSubscribtion($user, $channel) { $this->wrapper->checkScope('user_subscriptions'); return $this->wrapper->request('GET', "users/$user/subscriptions/$channel", [], true); }
[ "public", "function", "getUserSubscribtion", "(", "$", "user", ",", "$", "channel", ")", "{", "$", "this", "->", "wrapper", "->", "checkScope", "(", "'user_subscriptions'", ")", ";", "return", "$", "this", "->", "wrapper", "->", "request", "(", "'GET'", ",", "\"users/$user/subscriptions/$channel\"", ",", "[", "]", ",", "true", ")", ";", "}" ]
Returns a channel object that user subscribes to Requires authentication for $user. Learn more: https://github.com/justintv/Twitch-API/blob/master/v3_resources/subscriptions.md#get-usersusersubscriptionschannel @param string $user Target user @param string $channel Target channel @return array
[ "Returns", "a", "channel", "object", "that", "user", "subscribes", "to", "Requires", "authentication", "for", "$user", "." ]
train
https://github.com/raideer/twitch-api/blob/27ebf1dcb0315206300d507600b6a82ebe33d57e/src/Resources/Subscriptions.php#L80-L85
netvlies/NetvliesFormBundle
Twig/Extension/FormExtension.php
FormExtension.showForm
public function showForm($id) { $form = $this->container->get('netvlies.form')->get($id); if ($form->getSuccess()) { return $this->container->get('templating')->render('NetvliesFormBundle:Twig:form_success.html.twig', array( 'successMessage' => $form->getSuccessMessage(), )); } else { $formView = $form->getSf2Form()->createView(); if ($this->container->getParameter('netvlies.form.templates.fields') != null) { $this->container->get('twig')->getExtension('form')->renderer->setTheme($formView, array($this->container->getParameter('netvlies.form.templates.fields'))); } return $this->container->get('templating')->render($this->container->getParameter('netvlies.form.templates.form'), array( 'id' => $form->getId(), 'form' => $formView, )); } }
php
public function showForm($id) { $form = $this->container->get('netvlies.form')->get($id); if ($form->getSuccess()) { return $this->container->get('templating')->render('NetvliesFormBundle:Twig:form_success.html.twig', array( 'successMessage' => $form->getSuccessMessage(), )); } else { $formView = $form->getSf2Form()->createView(); if ($this->container->getParameter('netvlies.form.templates.fields') != null) { $this->container->get('twig')->getExtension('form')->renderer->setTheme($formView, array($this->container->getParameter('netvlies.form.templates.fields'))); } return $this->container->get('templating')->render($this->container->getParameter('netvlies.form.templates.form'), array( 'id' => $form->getId(), 'form' => $formView, )); } }
[ "public", "function", "showForm", "(", "$", "id", ")", "{", "$", "form", "=", "$", "this", "->", "container", "->", "get", "(", "'netvlies.form'", ")", "->", "get", "(", "$", "id", ")", ";", "if", "(", "$", "form", "->", "getSuccess", "(", ")", ")", "{", "return", "$", "this", "->", "container", "->", "get", "(", "'templating'", ")", "->", "render", "(", "'NetvliesFormBundle:Twig:form_success.html.twig'", ",", "array", "(", "'successMessage'", "=>", "$", "form", "->", "getSuccessMessage", "(", ")", ",", ")", ")", ";", "}", "else", "{", "$", "formView", "=", "$", "form", "->", "getSf2Form", "(", ")", "->", "createView", "(", ")", ";", "if", "(", "$", "this", "->", "container", "->", "getParameter", "(", "'netvlies.form.templates.fields'", ")", "!=", "null", ")", "{", "$", "this", "->", "container", "->", "get", "(", "'twig'", ")", "->", "getExtension", "(", "'form'", ")", "->", "renderer", "->", "setTheme", "(", "$", "formView", ",", "array", "(", "$", "this", "->", "container", "->", "getParameter", "(", "'netvlies.form.templates.fields'", ")", ")", ")", ";", "}", "return", "$", "this", "->", "container", "->", "get", "(", "'templating'", ")", "->", "render", "(", "$", "this", "->", "container", "->", "getParameter", "(", "'netvlies.form.templates.form'", ")", ",", "array", "(", "'id'", "=>", "$", "form", "->", "getId", "(", ")", ",", "'form'", "=>", "$", "formView", ",", ")", ")", ";", "}", "}" ]
Twig function that displays the form with the requested ID. If the form post was successful, the success message is shown by the Twig renderer. @param $id @return mixed
[ "Twig", "function", "that", "displays", "the", "form", "with", "the", "requested", "ID", ".", "If", "the", "form", "post", "was", "successful", "the", "success", "message", "is", "shown", "by", "the", "Twig", "renderer", "." ]
train
https://github.com/netvlies/NetvliesFormBundle/blob/93f9a3321d9925040111374e7c1014a6400a2d08/Twig/Extension/FormExtension.php#L51-L70
Duffleman/json-client
src/Collections/Generic.php
Generic.all
public function all() { $attributes = $this->attributes; return array_map(function ($item) { if (is_object($item) && get_class($item) === Generic::class) { $item = $item->all(); } return $item; }, $attributes); }
php
public function all() { $attributes = $this->attributes; return array_map(function ($item) { if (is_object($item) && get_class($item) === Generic::class) { $item = $item->all(); } return $item; }, $attributes); }
[ "public", "function", "all", "(", ")", "{", "$", "attributes", "=", "$", "this", "->", "attributes", ";", "return", "array_map", "(", "function", "(", "$", "item", ")", "{", "if", "(", "is_object", "(", "$", "item", ")", "&&", "get_class", "(", "$", "item", ")", "===", "Generic", "::", "class", ")", "{", "$", "item", "=", "$", "item", "->", "all", "(", ")", ";", "}", "return", "$", "item", ";", "}", ",", "$", "attributes", ")", ";", "}" ]
Return the base attribute array. @return array
[ "Return", "the", "base", "attribute", "array", "." ]
train
https://github.com/Duffleman/json-client/blob/83432875a000e79243424a1e8676acb9969d0c18/src/Collections/Generic.php#L80-L91
wenbinye/PhalconX
src/Queue/Beanstalk.php
Beanstalk.ignore
public function ignore($tube) { $this->write('ignore ' . $tube); $response = $this->readStatus(); if ($response[0] != "WATCHING") { return false; } return $response[1]; }
php
public function ignore($tube) { $this->write('ignore ' . $tube); $response = $this->readStatus(); if ($response[0] != "WATCHING") { return false; } return $response[1]; }
[ "public", "function", "ignore", "(", "$", "tube", ")", "{", "$", "this", "->", "write", "(", "'ignore '", ".", "$", "tube", ")", ";", "$", "response", "=", "$", "this", "->", "readStatus", "(", ")", ";", "if", "(", "$", "response", "[", "0", "]", "!=", "\"WATCHING\"", ")", "{", "return", "false", ";", "}", "return", "$", "response", "[", "1", "]", ";", "}" ]
Ignores the tube
[ "Ignores", "the", "tube" ]
train
https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Queue/Beanstalk.php#L51-L59
wenbinye/PhalconX
src/Queue/Beanstalk.php
Beanstalk.put
public function put($job, $options = null) { if ($job instanceof JobInterface) { if ($job->isRunOnce()) { $cacheKey = self::CACHE_JOB . get_class($job); if ($this->getCache()->get($cacheKey) === null) { $expire = $job->getDelay() + $job->getTtr() + 60; $this->getCache()->save($cacheKey, 1, $expire); } else { return true; } } $options = [ 'delay' => $job->getDelay(), 'ttr' => $job->getTtr(), 'priority' => $job->getPriority() ]; } $this->getLogger()->info('Add job ' . json_encode($job)); return parent::put($job, $options); }
php
public function put($job, $options = null) { if ($job instanceof JobInterface) { if ($job->isRunOnce()) { $cacheKey = self::CACHE_JOB . get_class($job); if ($this->getCache()->get($cacheKey) === null) { $expire = $job->getDelay() + $job->getTtr() + 60; $this->getCache()->save($cacheKey, 1, $expire); } else { return true; } } $options = [ 'delay' => $job->getDelay(), 'ttr' => $job->getTtr(), 'priority' => $job->getPriority() ]; } $this->getLogger()->info('Add job ' . json_encode($job)); return parent::put($job, $options); }
[ "public", "function", "put", "(", "$", "job", ",", "$", "options", "=", "null", ")", "{", "if", "(", "$", "job", "instanceof", "JobInterface", ")", "{", "if", "(", "$", "job", "->", "isRunOnce", "(", ")", ")", "{", "$", "cacheKey", "=", "self", "::", "CACHE_JOB", ".", "get_class", "(", "$", "job", ")", ";", "if", "(", "$", "this", "->", "getCache", "(", ")", "->", "get", "(", "$", "cacheKey", ")", "===", "null", ")", "{", "$", "expire", "=", "$", "job", "->", "getDelay", "(", ")", "+", "$", "job", "->", "getTtr", "(", ")", "+", "60", ";", "$", "this", "->", "getCache", "(", ")", "->", "save", "(", "$", "cacheKey", ",", "1", ",", "$", "expire", ")", ";", "}", "else", "{", "return", "true", ";", "}", "}", "$", "options", "=", "[", "'delay'", "=>", "$", "job", "->", "getDelay", "(", ")", ",", "'ttr'", "=>", "$", "job", "->", "getTtr", "(", ")", ",", "'priority'", "=>", "$", "job", "->", "getPriority", "(", ")", "]", ";", "}", "$", "this", "->", "getLogger", "(", ")", "->", "info", "(", "'Add job '", ".", "json_encode", "(", "$", "job", ")", ")", ";", "return", "parent", "::", "put", "(", "$", "job", ",", "$", "options", ")", ";", "}" ]
Inserts jobs into the queue @param mixed $job JobInterface or any data @param array options
[ "Inserts", "jobs", "into", "the", "queue" ]
train
https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Queue/Beanstalk.php#L75-L95
wenbinye/PhalconX
src/Queue/Beanstalk.php
Beanstalk.delete
public function delete(JobInterface $job) { if ($job->isRunOnce()) { $this->getCache()->delete(self::CACHE_JOB.get_class($job)); } return $job->getBeanstalkJob()->delete(); }
php
public function delete(JobInterface $job) { if ($job->isRunOnce()) { $this->getCache()->delete(self::CACHE_JOB.get_class($job)); } return $job->getBeanstalkJob()->delete(); }
[ "public", "function", "delete", "(", "JobInterface", "$", "job", ")", "{", "if", "(", "$", "job", "->", "isRunOnce", "(", ")", ")", "{", "$", "this", "->", "getCache", "(", ")", "->", "delete", "(", "self", "::", "CACHE_JOB", ".", "get_class", "(", "$", "job", ")", ")", ";", "}", "return", "$", "job", "->", "getBeanstalkJob", "(", ")", "->", "delete", "(", ")", ";", "}" ]
deletes job from queue @var JobInterface $job
[ "deletes", "job", "from", "queue" ]
train
https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Queue/Beanstalk.php#L102-L108
phergie/phergie-irc-generator
src/Generator.php
Generator.getIrcMessage
protected function getIrcMessage($type, array $params = array()) { $message = ''; if ($this->prefix) { $message .= ':' . $this->prefix . ' '; } $message .= $type; $params = array_filter($params, function($param) { return $param !== null; }); if ($params) { $last = end($params); $params[key($params)] = ':' . $last; $message .= ' ' . implode(' ', $params); } $message .= "\r\n"; return $message; }
php
protected function getIrcMessage($type, array $params = array()) { $message = ''; if ($this->prefix) { $message .= ':' . $this->prefix . ' '; } $message .= $type; $params = array_filter($params, function($param) { return $param !== null; }); if ($params) { $last = end($params); $params[key($params)] = ':' . $last; $message .= ' ' . implode(' ', $params); } $message .= "\r\n"; return $message; }
[ "protected", "function", "getIrcMessage", "(", "$", "type", ",", "array", "$", "params", "=", "array", "(", ")", ")", "{", "$", "message", "=", "''", ";", "if", "(", "$", "this", "->", "prefix", ")", "{", "$", "message", ".=", "':'", ".", "$", "this", "->", "prefix", ".", "' '", ";", "}", "$", "message", ".=", "$", "type", ";", "$", "params", "=", "array_filter", "(", "$", "params", ",", "function", "(", "$", "param", ")", "{", "return", "$", "param", "!==", "null", ";", "}", ")", ";", "if", "(", "$", "params", ")", "{", "$", "last", "=", "end", "(", "$", "params", ")", ";", "$", "params", "[", "key", "(", "$", "params", ")", "]", "=", "':'", ".", "$", "last", ";", "$", "message", ".=", "' '", ".", "implode", "(", "' '", ",", "$", "params", ")", ";", "}", "$", "message", ".=", "\"\\r\\n\"", ";", "return", "$", "message", ";", "}" ]
Returns a formatted IRC message. @param string $type Command or response code @param array $params Optional message parameters @return string
[ "Returns", "a", "formatted", "IRC", "message", "." ]
train
https://github.com/phergie/phergie-irc-generator/blob/8e7871f6d4e6c0f409a7912fb967e6cf2ead4ed8/src/Generator.php#L45-L64
phergie/phergie-irc-generator
src/Generator.php
Generator.ircUser
public function ircUser($username, $hostname, $servername, $realname) { return $this->getIrcMessage('USER', array($username, $hostname, $servername, $realname)); }
php
public function ircUser($username, $hostname, $servername, $realname) { return $this->getIrcMessage('USER', array($username, $hostname, $servername, $realname)); }
[ "public", "function", "ircUser", "(", "$", "username", ",", "$", "hostname", ",", "$", "servername", ",", "$", "realname", ")", "{", "return", "$", "this", "->", "getIrcMessage", "(", "'USER'", ",", "array", "(", "$", "username", ",", "$", "hostname", ",", "$", "servername", ",", "$", "realname", ")", ")", ";", "}" ]
Returns a USER message. @param string $username @param string $hostname @param string $servername @param string $realname @return string
[ "Returns", "a", "USER", "message", "." ]
train
https://github.com/phergie/phergie-irc-generator/blob/8e7871f6d4e6c0f409a7912fb967e6cf2ead4ed8/src/Generator.php#L98-L101
phergie/phergie-irc-generator
src/Generator.php
Generator.ircMode
public function ircMode($target, $mode = null, $param = null) { return $this->getIrcMessage('MODE', array($target, $mode, $param)); }
php
public function ircMode($target, $mode = null, $param = null) { return $this->getIrcMessage('MODE', array($target, $mode, $param)); }
[ "public", "function", "ircMode", "(", "$", "target", ",", "$", "mode", "=", "null", ",", "$", "param", "=", "null", ")", "{", "return", "$", "this", "->", "getIrcMessage", "(", "'MODE'", ",", "array", "(", "$", "target", ",", "$", "mode", ",", "$", "param", ")", ")", ";", "}" ]
Returns a MODE message. @param string $target @param string|null $mode @param string|null $param @return string
[ "Returns", "a", "MODE", "message", "." ]
train
https://github.com/phergie/phergie-irc-generator/blob/8e7871f6d4e6c0f409a7912fb967e6cf2ead4ed8/src/Generator.php#L183-L186
phergie/phergie-irc-generator
src/Generator.php
Generator.ircKick
public function ircKick($channel, $user, $comment = null) { return $this->getIrcMessage('KICK', array($channel, $user, $comment)); }
php
public function ircKick($channel, $user, $comment = null) { return $this->getIrcMessage('KICK', array($channel, $user, $comment)); }
[ "public", "function", "ircKick", "(", "$", "channel", ",", "$", "user", ",", "$", "comment", "=", "null", ")", "{", "return", "$", "this", "->", "getIrcMessage", "(", "'KICK'", ",", "array", "(", "$", "channel", ",", "$", "user", ",", "$", "comment", ")", ")", ";", "}" ]
Returns a KICK message. @param string $channel @param string $user @param string $comment @return string
[ "Returns", "a", "KICK", "message", "." ]
train
https://github.com/phergie/phergie-irc-generator/blob/8e7871f6d4e6c0f409a7912fb967e6cf2ead4ed8/src/Generator.php#L243-L246
phergie/phergie-irc-generator
src/Generator.php
Generator.ircConnect
public function ircConnect($targetserver, $port = null, $remoteserver = null) { return $this->getIrcMessage('CONNECT', array($targetserver, $port, $remoteserver)); }
php
public function ircConnect($targetserver, $port = null, $remoteserver = null) { return $this->getIrcMessage('CONNECT', array($targetserver, $port, $remoteserver)); }
[ "public", "function", "ircConnect", "(", "$", "targetserver", ",", "$", "port", "=", "null", ",", "$", "remoteserver", "=", "null", ")", "{", "return", "$", "this", "->", "getIrcMessage", "(", "'CONNECT'", ",", "array", "(", "$", "targetserver", ",", "$", "port", ",", "$", "remoteserver", ")", ")", ";", "}" ]
Returns a CONNECT message. @param string $targetserver @param int $port @param string $remoteserver @return string
[ "Returns", "a", "CONNECT", "message", "." ]
train
https://github.com/phergie/phergie-irc-generator/blob/8e7871f6d4e6c0f409a7912fb967e6cf2ead4ed8/src/Generator.php#L306-L309
phergie/phergie-irc-generator
src/Generator.php
Generator.ircWhowas
public function ircWhowas($nickname, $count = null, $server = null) { return $this->getIrcMessage('WHOWAS', array($nickname, $count, $server)); }
php
public function ircWhowas($nickname, $count = null, $server = null) { return $this->getIrcMessage('WHOWAS', array($nickname, $count, $server)); }
[ "public", "function", "ircWhowas", "(", "$", "nickname", ",", "$", "count", "=", "null", ",", "$", "server", "=", "null", ")", "{", "return", "$", "this", "->", "getIrcMessage", "(", "'WHOWAS'", ",", "array", "(", "$", "nickname", ",", "$", "count", ",", "$", "server", ")", ")", ";", "}" ]
Returns a WHOWAS message. @param string $nickname @param int $count @param string $server @return string
[ "Returns", "a", "WHOWAS", "message", "." ]
train
https://github.com/phergie/phergie-irc-generator/blob/8e7871f6d4e6c0f409a7912fb967e6cf2ead4ed8/src/Generator.php#L400-L403
phergie/phergie-irc-generator
src/Generator.php
Generator.ctcpVersionResponse
public function ctcpVersionResponse($nickname, $name, $version, $environment) { return $this->getCtcpResponse($nickname, 'VERSION ' . $name . ':' . $version . ':' . $environment); }
php
public function ctcpVersionResponse($nickname, $name, $version, $environment) { return $this->getCtcpResponse($nickname, 'VERSION ' . $name . ':' . $version . ':' . $environment); }
[ "public", "function", "ctcpVersionResponse", "(", "$", "nickname", ",", "$", "name", ",", "$", "version", ",", "$", "environment", ")", "{", "return", "$", "this", "->", "getCtcpResponse", "(", "$", "nickname", ",", "'VERSION '", ".", "$", "name", ".", "':'", ".", "$", "version", ".", "':'", ".", "$", "environment", ")", ";", "}" ]
Returns a CTCP VERSION reply message. @param string $nickname @param string $name @param string $version @param string $environment @return string
[ "Returns", "a", "CTCP", "VERSION", "reply", "message", "." ]
train
https://github.com/phergie/phergie-irc-generator/blob/8e7871f6d4e6c0f409a7912fb967e6cf2ead4ed8/src/Generator.php#L621-L624
phergie/phergie-irc-generator
src/Generator.php
Generator.ctcpSourceResponse
public function ctcpSourceResponse($nickname, $host, $directories, $files) { return $this->getCtcpResponse($nickname, 'SOURCE ' . $host . ':' . $directories . ':' . $files); }
php
public function ctcpSourceResponse($nickname, $host, $directories, $files) { return $this->getCtcpResponse($nickname, 'SOURCE ' . $host . ':' . $directories . ':' . $files); }
[ "public", "function", "ctcpSourceResponse", "(", "$", "nickname", ",", "$", "host", ",", "$", "directories", ",", "$", "files", ")", "{", "return", "$", "this", "->", "getCtcpResponse", "(", "$", "nickname", ",", "'SOURCE '", ".", "$", "host", ".", "':'", ".", "$", "directories", ".", "':'", ".", "$", "files", ")", ";", "}" ]
Returns a CTCP SOURCE reply message. @param string $nickname @param string $host @param string $directories @param string $files @return string
[ "Returns", "a", "CTCP", "SOURCE", "reply", "message", "." ]
train
https://github.com/phergie/phergie-irc-generator/blob/8e7871f6d4e6c0f409a7912fb967e6cf2ead4ed8/src/Generator.php#L646-L649
inhere/php-librarys
src/Files/FileSystem.php
FileSystem.pathFormat
public static function pathFormat($dirName): string { $dirName = str_ireplace('\\', '/', trim($dirName)); return substr($dirName, -1) === '/' ? $dirName : $dirName . '/'; }
php
public static function pathFormat($dirName): string { $dirName = str_ireplace('\\', '/', trim($dirName)); return substr($dirName, -1) === '/' ? $dirName : $dirName . '/'; }
[ "public", "static", "function", "pathFormat", "(", "$", "dirName", ")", ":", "string", "{", "$", "dirName", "=", "str_ireplace", "(", "'\\\\'", ",", "'/'", ",", "trim", "(", "$", "dirName", ")", ")", ";", "return", "substr", "(", "$", "dirName", ",", "-", "1", ")", "===", "'/'", "?", "$", "dirName", ":", "$", "dirName", ".", "'/'", ";", "}" ]
转换为标准的路径结构 @param string $dirName @return string
[ "转换为标准的路径结构" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Files/FileSystem.php#L64-L69
inhere/php-librarys
src/Files/FileSystem.php
FileSystem.exists
public static function exists($file, $type = null) { if (!$type) { return file_exists($file); } $ret = false; if ($type === 'file') { $ret = is_file($file); } elseif ($type === 'dir') { $ret = is_dir($file); } elseif ($type === 'link') { $ret = is_link($file); } return $ret; }
php
public static function exists($file, $type = null) { if (!$type) { return file_exists($file); } $ret = false; if ($type === 'file') { $ret = is_file($file); } elseif ($type === 'dir') { $ret = is_dir($file); } elseif ($type === 'link') { $ret = is_link($file); } return $ret; }
[ "public", "static", "function", "exists", "(", "$", "file", ",", "$", "type", "=", "null", ")", "{", "if", "(", "!", "$", "type", ")", "{", "return", "file_exists", "(", "$", "file", ")", ";", "}", "$", "ret", "=", "false", ";", "if", "(", "$", "type", "===", "'file'", ")", "{", "$", "ret", "=", "is_file", "(", "$", "file", ")", ";", "}", "elseif", "(", "$", "type", "===", "'dir'", ")", "{", "$", "ret", "=", "is_dir", "(", "$", "file", ")", ";", "}", "elseif", "(", "$", "type", "===", "'link'", ")", "{", "$", "ret", "=", "is_link", "(", "$", "file", ")", ";", "}", "return", "$", "ret", ";", "}" ]
检查文件/夹/链接是否存在 @param string $file 要检查的目标 @param null|string $type @return array|string
[ "检查文件", "/", "夹", "/", "链接是否存在" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Files/FileSystem.php#L94-L111
inhere/php-librarys
src/Files/FileSystem.php
FileSystem.rename
public static function rename($origin, $target, $overwrite = false): void { // we check that target does not exist if (!$overwrite && static::isReadable($target)) { throw new IOException(sprintf('Cannot rename because the target "%s" already exists.', $target), 0, null, $target); } if (true !== rename($origin, $target)) { throw new IOException(sprintf('Cannot rename "%s" to "%s".', $origin, $target), 0, null, $target); } }
php
public static function rename($origin, $target, $overwrite = false): void { // we check that target does not exist if (!$overwrite && static::isReadable($target)) { throw new IOException(sprintf('Cannot rename because the target "%s" already exists.', $target), 0, null, $target); } if (true !== rename($origin, $target)) { throw new IOException(sprintf('Cannot rename "%s" to "%s".', $origin, $target), 0, null, $target); } }
[ "public", "static", "function", "rename", "(", "$", "origin", ",", "$", "target", ",", "$", "overwrite", "=", "false", ")", ":", "void", "{", "// we check that target does not exist", "if", "(", "!", "$", "overwrite", "&&", "static", "::", "isReadable", "(", "$", "target", ")", ")", "{", "throw", "new", "IOException", "(", "sprintf", "(", "'Cannot rename because the target \"%s\" already exists.'", ",", "$", "target", ")", ",", "0", ",", "null", ",", "$", "target", ")", ";", "}", "if", "(", "true", "!==", "rename", "(", "$", "origin", ",", "$", "target", ")", ")", "{", "throw", "new", "IOException", "(", "sprintf", "(", "'Cannot rename \"%s\" to \"%s\".'", ",", "$", "origin", ",", "$", "target", ")", ",", "0", ",", "null", ",", "$", "target", ")", ";", "}", "}" ]
Renames a file or a directory. @from Symfony-filesystem @param string $origin The origin filename or directory @param string $target The new filename or directory @param bool $overwrite Whether to overwrite the target if it already exists @throws IOException When target file or directory already exists @throws IOException When origin cannot be renamed
[ "Renames", "a", "file", "or", "a", "directory", "." ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Files/FileSystem.php#L145-L156
GrupaZero/api
src/Gzero/Api/ServiceProvider.php
ServiceProvider.boot
public function boot() { $this->registerRoutes(); // @TODO Probably we can move this to routes file Passport::routes(); Passport::tokensExpireIn(Carbon::now()->addDays(15)); Passport::refreshTokensExpireIn(Carbon::now()->addDays(30)); }
php
public function boot() { $this->registerRoutes(); // @TODO Probably we can move this to routes file Passport::routes(); Passport::tokensExpireIn(Carbon::now()->addDays(15)); Passport::refreshTokensExpireIn(Carbon::now()->addDays(30)); }
[ "public", "function", "boot", "(", ")", "{", "$", "this", "->", "registerRoutes", "(", ")", ";", "// @TODO Probably we can move this to routes file", "Passport", "::", "routes", "(", ")", ";", "Passport", "::", "tokensExpireIn", "(", "Carbon", "::", "now", "(", ")", "->", "addDays", "(", "15", ")", ")", ";", "Passport", "::", "refreshTokensExpireIn", "(", "Carbon", "::", "now", "(", ")", "->", "addDays", "(", "30", ")", ")", ";", "}" ]
Bootstrap the application events. @return void
[ "Bootstrap", "the", "application", "events", "." ]
train
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/ServiceProvider.php#L54-L64
GrupaZero/api
src/Gzero/Api/ServiceProvider.php
ServiceProvider.bind
private function bind() { $this->app->bind( 'League\Fractal\Manager', function () { $manager = new Manager(); $manager->setSerializer(new ArraySerializer()); return $manager; } ); }
php
private function bind() { $this->app->bind( 'League\Fractal\Manager', function () { $manager = new Manager(); $manager->setSerializer(new ArraySerializer()); return $manager; } ); }
[ "private", "function", "bind", "(", ")", "{", "$", "this", "->", "app", "->", "bind", "(", "'League\\Fractal\\Manager'", ",", "function", "(", ")", "{", "$", "manager", "=", "new", "Manager", "(", ")", ";", "$", "manager", "->", "setSerializer", "(", "new", "ArraySerializer", "(", ")", ")", ";", "return", "$", "manager", ";", "}", ")", ";", "}" ]
Bind additional classes @return void
[ "Bind", "additional", "classes" ]
train
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/ServiceProvider.php#L81-L91
bigfootcms/core
src/index.php
Bigfoot.MagicAssets
public function MagicAssets($fake=false, $real=false) { if ( $fake !== false && $real !== false ) { $_SESSION['MAGIC'][$fake] = $real; return true; } if ( !empty($_SESSION['MAGIC']) ) { foreach($_SESSION['MAGIC'] as $symbol=>$link) { Base::instance()->route('GET|POST '.$symbol, function($f3) use ($symbol, $link) { $ext = pathinfo($link, PATHINFO_EXTENSION); $filename = basename($link); $directory = $f3->get("ROOT").dirname($link)."/"; if ( $ext == "js" ) { $js = Web::instance()->minify($filename, null, true, $directory); $js = preg_replace('/(?:(?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:(?<!\:|\\\|\'|\")\/\/.*))/', '', $js); header("Content-type: application/x-javascript"); echo Template::instance()->resolve(Template::instance()->parse($js)); exit(); } elseif( $ext == "css" ) { header("Content-type: text/css"); } else { header("Content-type: text/css"); echo "/* SCSS currently disabled */"; exit; $css = file_get_contents($directory.$filename); $js = str_replace("{{uuid}}", $f3->get("SESSION.uuid"), $js); $scss = new Compiler(); echo $scss->compile($css); exit; } echo Template::instance()->resolve(Template::instance()->parse(file_get_contents($f3->get("ROOT").'/'.$link))); exit; }); } return true; } return false; }
php
public function MagicAssets($fake=false, $real=false) { if ( $fake !== false && $real !== false ) { $_SESSION['MAGIC'][$fake] = $real; return true; } if ( !empty($_SESSION['MAGIC']) ) { foreach($_SESSION['MAGIC'] as $symbol=>$link) { Base::instance()->route('GET|POST '.$symbol, function($f3) use ($symbol, $link) { $ext = pathinfo($link, PATHINFO_EXTENSION); $filename = basename($link); $directory = $f3->get("ROOT").dirname($link)."/"; if ( $ext == "js" ) { $js = Web::instance()->minify($filename, null, true, $directory); $js = preg_replace('/(?:(?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:(?<!\:|\\\|\'|\")\/\/.*))/', '', $js); header("Content-type: application/x-javascript"); echo Template::instance()->resolve(Template::instance()->parse($js)); exit(); } elseif( $ext == "css" ) { header("Content-type: text/css"); } else { header("Content-type: text/css"); echo "/* SCSS currently disabled */"; exit; $css = file_get_contents($directory.$filename); $js = str_replace("{{uuid}}", $f3->get("SESSION.uuid"), $js); $scss = new Compiler(); echo $scss->compile($css); exit; } echo Template::instance()->resolve(Template::instance()->parse(file_get_contents($f3->get("ROOT").'/'.$link))); exit; }); } return true; } return false; }
[ "public", "function", "MagicAssets", "(", "$", "fake", "=", "false", ",", "$", "real", "=", "false", ")", "{", "if", "(", "$", "fake", "!==", "false", "&&", "$", "real", "!==", "false", ")", "{", "$", "_SESSION", "[", "'MAGIC'", "]", "[", "$", "fake", "]", "=", "$", "real", ";", "return", "true", ";", "}", "if", "(", "!", "empty", "(", "$", "_SESSION", "[", "'MAGIC'", "]", ")", ")", "{", "foreach", "(", "$", "_SESSION", "[", "'MAGIC'", "]", "as", "$", "symbol", "=>", "$", "link", ")", "{", "Base", "::", "instance", "(", ")", "->", "route", "(", "'GET|POST '", ".", "$", "symbol", ",", "function", "(", "$", "f3", ")", "use", "(", "$", "symbol", ",", "$", "link", ")", "{", "$", "ext", "=", "pathinfo", "(", "$", "link", ",", "PATHINFO_EXTENSION", ")", ";", "$", "filename", "=", "basename", "(", "$", "link", ")", ";", "$", "directory", "=", "$", "f3", "->", "get", "(", "\"ROOT\"", ")", ".", "dirname", "(", "$", "link", ")", ".", "\"/\"", ";", "if", "(", "$", "ext", "==", "\"js\"", ")", "{", "$", "js", "=", "Web", "::", "instance", "(", ")", "->", "minify", "(", "$", "filename", ",", "null", ",", "true", ",", "$", "directory", ")", ";", "$", "js", "=", "preg_replace", "(", "'/(?:(?:\\/\\*(?:[^*]|(?:\\*+[^*\\/]))*\\*+\\/)|(?:(?<!\\:|\\\\\\|\\'|\\\")\\/\\/.*))/'", ",", "''", ",", "$", "js", ")", ";", "header", "(", "\"Content-type: application/x-javascript\"", ")", ";", "echo", "Template", "::", "instance", "(", ")", "->", "resolve", "(", "Template", "::", "instance", "(", ")", "->", "parse", "(", "$", "js", ")", ")", ";", "exit", "(", ")", ";", "}", "elseif", "(", "$", "ext", "==", "\"css\"", ")", "{", "header", "(", "\"Content-type: text/css\"", ")", ";", "}", "else", "{", "header", "(", "\"Content-type: text/css\"", ")", ";", "echo", "\"/* SCSS currently disabled */\"", ";", "exit", ";", "$", "css", "=", "file_get_contents", "(", "$", "directory", ".", "$", "filename", ")", ";", "$", "js", "=", "str_replace", "(", "\"{{uuid}}\"", ",", "$", "f3", "->", "get", "(", "\"SESSION.uuid\"", ")", ",", "$", "js", ")", ";", "$", "scss", "=", "new", "Compiler", "(", ")", ";", "echo", "$", "scss", "->", "compile", "(", "$", "css", ")", ";", "exit", ";", "}", "echo", "Template", "::", "instance", "(", ")", "->", "resolve", "(", "Template", "::", "instance", "(", ")", "->", "parse", "(", "file_get_contents", "(", "$", "f3", "->", "get", "(", "\"ROOT\"", ")", ".", "'/'", ".", "$", "link", ")", ")", ")", ";", "exit", ";", "}", ")", ";", "}", "return", "true", ";", "}", "return", "false", ";", "}" ]
/* Magic paths are convenient for hiding the real path of a file. Use only JS, CSS and SCSS assets.
[ "/", "*", "Magic", "paths", "are", "convenient", "for", "hiding", "the", "real", "path", "of", "a", "file", ".", "Use", "only", "JS", "CSS", "and", "SCSS", "assets", "." ]
train
https://github.com/bigfootcms/core/blob/65c720dd5e2c73a276476e56d9bf3b84da25ce4c/src/index.php#L348-L385
42mate/towel
src/Towel/Migration/BaseMigration.php
BaseMigration.setDone
public function setDone() { $migration = $this->getMigration(); if ($migration['state']) { return true; //alredy done } $this->db()->update($this->table, array('state' => true), array('id' => $migration['id'])); }
php
public function setDone() { $migration = $this->getMigration(); if ($migration['state']) { return true; //alredy done } $this->db()->update($this->table, array('state' => true), array('id' => $migration['id'])); }
[ "public", "function", "setDone", "(", ")", "{", "$", "migration", "=", "$", "this", "->", "getMigration", "(", ")", ";", "if", "(", "$", "migration", "[", "'state'", "]", ")", "{", "return", "true", ";", "//alredy done", "}", "$", "this", "->", "db", "(", ")", "->", "update", "(", "$", "this", "->", "table", ",", "array", "(", "'state'", "=>", "true", ")", ",", "array", "(", "'id'", "=>", "$", "migration", "[", "'id'", "]", ")", ")", ";", "}" ]
Sets that the migration was done. @return bool
[ "Sets", "that", "the", "migration", "was", "done", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Migration/BaseMigration.php#L79-L85
42mate/towel
src/Towel/Migration/BaseMigration.php
BaseMigration.unsetDone
public function unsetDone() { $migration = $this->getMigration(); if (!$migration['state']) { return true; //alredy undone } $this->db()->update($this->table, array('state' => false), array('id' => $migration['id'])); }
php
public function unsetDone() { $migration = $this->getMigration(); if (!$migration['state']) { return true; //alredy undone } $this->db()->update($this->table, array('state' => false), array('id' => $migration['id'])); }
[ "public", "function", "unsetDone", "(", ")", "{", "$", "migration", "=", "$", "this", "->", "getMigration", "(", ")", ";", "if", "(", "!", "$", "migration", "[", "'state'", "]", ")", "{", "return", "true", ";", "//alredy undone", "}", "$", "this", "->", "db", "(", ")", "->", "update", "(", "$", "this", "->", "table", ",", "array", "(", "'state'", "=>", "false", ")", ",", "array", "(", "'id'", "=>", "$", "migration", "[", "'id'", "]", ")", ")", ";", "}" ]
Sets that the migration was reverted. @return bool
[ "Sets", "that", "the", "migration", "was", "reverted", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Migration/BaseMigration.php#L92-L98
42mate/towel
src/Towel/Migration/BaseMigration.php
BaseMigration.create
public function create() { $migration = $this->getMessages(); if (!$migration) { $this->db()->insert($this->table, array('migration' => get_class($this), 'state' => false)); } else { throw new \Exception('Migration ' . get_class($this) . ' already created'); } }
php
public function create() { $migration = $this->getMessages(); if (!$migration) { $this->db()->insert($this->table, array('migration' => get_class($this), 'state' => false)); } else { throw new \Exception('Migration ' . get_class($this) . ' already created'); } }
[ "public", "function", "create", "(", ")", "{", "$", "migration", "=", "$", "this", "->", "getMessages", "(", ")", ";", "if", "(", "!", "$", "migration", ")", "{", "$", "this", "->", "db", "(", ")", "->", "insert", "(", "$", "this", "->", "table", ",", "array", "(", "'migration'", "=>", "get_class", "(", "$", "this", ")", ",", "'state'", "=>", "false", ")", ")", ";", "}", "else", "{", "throw", "new", "\\", "Exception", "(", "'Migration '", ".", "get_class", "(", "$", "this", ")", ".", "' already created'", ")", ";", "}", "}" ]
Creates the record in the database of the migration. @throws \Exception
[ "Creates", "the", "record", "in", "the", "database", "of", "the", "migration", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Migration/BaseMigration.php#L105-L112
42mate/towel
src/Towel/Migration/BaseMigration.php
BaseMigration.getMigration
public function getMigration() { $query = $this->db()->createQueryBuilder() ->select('m.*') ->from($this->table, 'm') ->where('migration = ?') ->setParameter(0, get_class($this)); $results = $query->execute(); $migration = $results->fetch(); if (!$migration) { $this->create(); return true; //Is not in the DB so is new and is pending } return $migration; }
php
public function getMigration() { $query = $this->db()->createQueryBuilder() ->select('m.*') ->from($this->table, 'm') ->where('migration = ?') ->setParameter(0, get_class($this)); $results = $query->execute(); $migration = $results->fetch(); if (!$migration) { $this->create(); return true; //Is not in the DB so is new and is pending } return $migration; }
[ "public", "function", "getMigration", "(", ")", "{", "$", "query", "=", "$", "this", "->", "db", "(", ")", "->", "createQueryBuilder", "(", ")", "->", "select", "(", "'m.*'", ")", "->", "from", "(", "$", "this", "->", "table", ",", "'m'", ")", "->", "where", "(", "'migration = ?'", ")", "->", "setParameter", "(", "0", ",", "get_class", "(", "$", "this", ")", ")", ";", "$", "results", "=", "$", "query", "->", "execute", "(", ")", ";", "$", "migration", "=", "$", "results", "->", "fetch", "(", ")", ";", "if", "(", "!", "$", "migration", ")", "{", "$", "this", "->", "create", "(", ")", ";", "return", "true", ";", "//Is not in the DB so is new and is pending", "}", "return", "$", "migration", ";", "}" ]
Gets the information in the DB of this migration. @return mixed
[ "Gets", "the", "information", "in", "the", "DB", "of", "this", "migration", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Migration/BaseMigration.php#L118-L133
42mate/towel
src/Towel/Migration/BaseMigration.php
BaseMigration.addMessage
public function addMessage($message) { $migrationName = get_class($this); $this->messages[] = sprintf("%s: %s\n", $migrationName, $message); }
php
public function addMessage($message) { $migrationName = get_class($this); $this->messages[] = sprintf("%s: %s\n", $migrationName, $message); }
[ "public", "function", "addMessage", "(", "$", "message", ")", "{", "$", "migrationName", "=", "get_class", "(", "$", "this", ")", ";", "$", "this", "->", "messages", "[", "]", "=", "sprintf", "(", "\"%s: %s\\n\"", ",", "$", "migrationName", ",", "$", "message", ")", ";", "}" ]
Adds messages in the migration for later use.
[ "Adds", "messages", "in", "the", "migration", "for", "later", "use", "." ]
train
https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Migration/BaseMigration.php#L138-L141
rhosocial/yii2-user
models/LoginMethod/ID.php
ID.validate
public static function validate($attribute) { $userClass = Yii::$app->user->identityClass; $regex = $userClass::$idRegex; $result = preg_match($regex, $attribute); return is_int($result) && $result > 0; }
php
public static function validate($attribute) { $userClass = Yii::$app->user->identityClass; $regex = $userClass::$idRegex; $result = preg_match($regex, $attribute); return is_int($result) && $result > 0; }
[ "public", "static", "function", "validate", "(", "$", "attribute", ")", "{", "$", "userClass", "=", "Yii", "::", "$", "app", "->", "user", "->", "identityClass", ";", "$", "regex", "=", "$", "userClass", "::", "$", "idRegex", ";", "$", "result", "=", "preg_match", "(", "$", "regex", ",", "$", "attribute", ")", ";", "return", "is_int", "(", "$", "result", ")", "&&", "$", "result", ">", "0", ";", "}" ]
Validate whether the attribute is valid. @param mixed $attribute @return bool
[ "Validate", "whether", "the", "attribute", "is", "valid", "." ]
train
https://github.com/rhosocial/yii2-user/blob/96737a9d8ca7e9c42cd2b7736d6c0a90ede6e5bc/models/LoginMethod/ID.php#L44-L50
arndtteunissen/column-layout
Classes/User/Tca.php
Tca.generateSelectItems
public function generateSelectItems(array &$params) { $pageUid = $params['flexParentDatabaseRow']['_tx_column_layout_orig_pid'] ?? $params['flexParentDatabaseRow']['pid']; $size = $params['config']['txColumnLayout']['size']; $type = $params['config']['txColumnLayout']['type']; $columnSizes = ColumnLayoutUtility::getSizesFor($size, $type, $pageUid); $settings = ColumnLayoutUtility::getColumnLayoutSettings($pageUid); $sizeSettings = $settings['sizes.'][$size . '.']; $typeSettings = $settings['types.'][$type . '.']; $itemLabel = $this->getLanguageService()->sL($typeSettings['itemLabel']); $items = array_map(function ($column) use ($size, $itemLabel) { return [ sprintf( $itemLabel, $column, $size ), $column ]; }, $columnSizes); if ($columnSizes[0] === 0 && ($typeSettings['itemLabelDisabled'] ?? false)) { $items[0][0] = sprintf($this->getLanguageService()->sL($typeSettings['itemLabelDisabled']), $type); } $typeOrdering = $typeSettings['ordering'] ?? null; $sizeTypeOverride = array_key_exists($type . '.', $sizeSettings) ? $sizeSettings[$type . '.']['ordering'] ?? false : false; $typeOrdering = $sizeTypeOverride ? $sizeTypeOverride : $typeOrdering; if ($typeOrdering === 'reverse') { $items = array_reverse($items); } $params['items'] = $items; }
php
public function generateSelectItems(array &$params) { $pageUid = $params['flexParentDatabaseRow']['_tx_column_layout_orig_pid'] ?? $params['flexParentDatabaseRow']['pid']; $size = $params['config']['txColumnLayout']['size']; $type = $params['config']['txColumnLayout']['type']; $columnSizes = ColumnLayoutUtility::getSizesFor($size, $type, $pageUid); $settings = ColumnLayoutUtility::getColumnLayoutSettings($pageUid); $sizeSettings = $settings['sizes.'][$size . '.']; $typeSettings = $settings['types.'][$type . '.']; $itemLabel = $this->getLanguageService()->sL($typeSettings['itemLabel']); $items = array_map(function ($column) use ($size, $itemLabel) { return [ sprintf( $itemLabel, $column, $size ), $column ]; }, $columnSizes); if ($columnSizes[0] === 0 && ($typeSettings['itemLabelDisabled'] ?? false)) { $items[0][0] = sprintf($this->getLanguageService()->sL($typeSettings['itemLabelDisabled']), $type); } $typeOrdering = $typeSettings['ordering'] ?? null; $sizeTypeOverride = array_key_exists($type . '.', $sizeSettings) ? $sizeSettings[$type . '.']['ordering'] ?? false : false; $typeOrdering = $sizeTypeOverride ? $sizeTypeOverride : $typeOrdering; if ($typeOrdering === 'reverse') { $items = array_reverse($items); } $params['items'] = $items; }
[ "public", "function", "generateSelectItems", "(", "array", "&", "$", "params", ")", "{", "$", "pageUid", "=", "$", "params", "[", "'flexParentDatabaseRow'", "]", "[", "'_tx_column_layout_orig_pid'", "]", "??", "$", "params", "[", "'flexParentDatabaseRow'", "]", "[", "'pid'", "]", ";", "$", "size", "=", "$", "params", "[", "'config'", "]", "[", "'txColumnLayout'", "]", "[", "'size'", "]", ";", "$", "type", "=", "$", "params", "[", "'config'", "]", "[", "'txColumnLayout'", "]", "[", "'type'", "]", ";", "$", "columnSizes", "=", "ColumnLayoutUtility", "::", "getSizesFor", "(", "$", "size", ",", "$", "type", ",", "$", "pageUid", ")", ";", "$", "settings", "=", "ColumnLayoutUtility", "::", "getColumnLayoutSettings", "(", "$", "pageUid", ")", ";", "$", "sizeSettings", "=", "$", "settings", "[", "'sizes.'", "]", "[", "$", "size", ".", "'.'", "]", ";", "$", "typeSettings", "=", "$", "settings", "[", "'types.'", "]", "[", "$", "type", ".", "'.'", "]", ";", "$", "itemLabel", "=", "$", "this", "->", "getLanguageService", "(", ")", "->", "sL", "(", "$", "typeSettings", "[", "'itemLabel'", "]", ")", ";", "$", "items", "=", "array_map", "(", "function", "(", "$", "column", ")", "use", "(", "$", "size", ",", "$", "itemLabel", ")", "{", "return", "[", "sprintf", "(", "$", "itemLabel", ",", "$", "column", ",", "$", "size", ")", ",", "$", "column", "]", ";", "}", ",", "$", "columnSizes", ")", ";", "if", "(", "$", "columnSizes", "[", "0", "]", "===", "0", "&&", "(", "$", "typeSettings", "[", "'itemLabelDisabled'", "]", "??", "false", ")", ")", "{", "$", "items", "[", "0", "]", "[", "0", "]", "=", "sprintf", "(", "$", "this", "->", "getLanguageService", "(", ")", "->", "sL", "(", "$", "typeSettings", "[", "'itemLabelDisabled'", "]", ")", ",", "$", "type", ")", ";", "}", "$", "typeOrdering", "=", "$", "typeSettings", "[", "'ordering'", "]", "??", "null", ";", "$", "sizeTypeOverride", "=", "array_key_exists", "(", "$", "type", ".", "'.'", ",", "$", "sizeSettings", ")", "?", "$", "sizeSettings", "[", "$", "type", ".", "'.'", "]", "[", "'ordering'", "]", "??", "false", ":", "false", ";", "$", "typeOrdering", "=", "$", "sizeTypeOverride", "?", "$", "sizeTypeOverride", ":", "$", "typeOrdering", ";", "if", "(", "$", "typeOrdering", "===", "'reverse'", ")", "{", "$", "items", "=", "array_reverse", "(", "$", "items", ")", ";", "}", "$", "params", "[", "'items'", "]", "=", "$", "items", ";", "}" ]
Generates select items for the gridsystem flexform @param array $params @throws Exception when size or type was not defined
[ "Generates", "select", "items", "for", "the", "gridsystem", "flexform" ]
train
https://github.com/arndtteunissen/column-layout/blob/ad737068eef3b084d4d0e3a48e6a3d8277af9560/Classes/User/Tca.php#L26-L62
yuncms/yii2-authentication
AuthenticationTrait.php
AuthenticationTrait.getIdCardPath
public function getIdCardPath($userId) { $avatarPath = $this->getSetting('idCardPath') . '/' . $this->getIdSavePath($userId); if (!is_dir($avatarPath)) { FileHelper::createDirectory($avatarPath); } return $avatarPath . substr($userId, -2); }
php
public function getIdCardPath($userId) { $avatarPath = $this->getSetting('idCardPath') . '/' . $this->getIdSavePath($userId); if (!is_dir($avatarPath)) { FileHelper::createDirectory($avatarPath); } return $avatarPath . substr($userId, -2); }
[ "public", "function", "getIdCardPath", "(", "$", "userId", ")", "{", "$", "avatarPath", "=", "$", "this", "->", "getSetting", "(", "'idCardPath'", ")", ".", "'/'", ".", "$", "this", "->", "getIdSavePath", "(", "$", "userId", ")", ";", "if", "(", "!", "is_dir", "(", "$", "avatarPath", ")", ")", "{", "FileHelper", "::", "createDirectory", "(", "$", "avatarPath", ")", ";", "}", "return", "$", "avatarPath", ".", "substr", "(", "$", "userId", ",", "-", "2", ")", ";", "}" ]
获取头像的存储路径 @param int $userId @return string
[ "获取头像的存储路径" ]
train
https://github.com/yuncms/yii2-authentication/blob/02b70f7d2587480edb6dcc18ce256db662f1ed0d/AuthenticationTrait.php#L39-L46
yuncms/yii2-authentication
AuthenticationTrait.php
AuthenticationTrait.getIdSavePath
public function getIdSavePath($userId) { $id = sprintf("%09d", $userId); $dir1 = substr($id, 0, 3); $dir2 = substr($id, 3, 2); $dir3 = substr($id, 5, 2); return $dir1 . '/' . $dir2 . '/' . $dir3 . '/'; }
php
public function getIdSavePath($userId) { $id = sprintf("%09d", $userId); $dir1 = substr($id, 0, 3); $dir2 = substr($id, 3, 2); $dir3 = substr($id, 5, 2); return $dir1 . '/' . $dir2 . '/' . $dir3 . '/'; }
[ "public", "function", "getIdSavePath", "(", "$", "userId", ")", "{", "$", "id", "=", "sprintf", "(", "\"%09d\"", ",", "$", "userId", ")", ";", "$", "dir1", "=", "substr", "(", "$", "id", ",", "0", ",", "3", ")", ";", "$", "dir2", "=", "substr", "(", "$", "id", ",", "3", ",", "2", ")", ";", "$", "dir3", "=", "substr", "(", "$", "id", ",", "5", ",", "2", ")", ";", "return", "$", "dir1", ".", "'/'", ".", "$", "dir2", ".", "'/'", ".", "$", "dir3", ".", "'/'", ";", "}" ]
计算用户头像子路径 @param int $userId 用户ID @return string
[ "计算用户头像子路径" ]
train
https://github.com/yuncms/yii2-authentication/blob/02b70f7d2587480edb6dcc18ce256db662f1ed0d/AuthenticationTrait.php#L64-L71
bit3archive/php-remote-objects
src/RemoteObjects/Encode/AesEncoder.php
AesEncoder.getCryptAes
protected function getCryptAes() { if ($this->aes === null) { $this->aes = new \Crypt_AES(); $this->aes->setKey($this->psk); } return $this->aes; }
php
protected function getCryptAes() { if ($this->aes === null) { $this->aes = new \Crypt_AES(); $this->aes->setKey($this->psk); } return $this->aes; }
[ "protected", "function", "getCryptAes", "(", ")", "{", "if", "(", "$", "this", "->", "aes", "===", "null", ")", "{", "$", "this", "->", "aes", "=", "new", "\\", "Crypt_AES", "(", ")", ";", "$", "this", "->", "aes", "->", "setKey", "(", "$", "this", "->", "psk", ")", ";", "}", "return", "$", "this", "->", "aes", ";", "}" ]
Get the crypt aes component. @return \Crypt_RSA
[ "Get", "the", "crypt", "aes", "component", "." ]
train
https://github.com/bit3archive/php-remote-objects/blob/0a917cdb261d83b1e89bdbdce3627584823bff5f/src/RemoteObjects/Encode/AesEncoder.php#L69-L77
colorium/web
src/Colorium/Web/App.php
App.before
protected function before(Context $context) { // kernel before handler $context = parent::before($context); // add templater to context $context->templater = $this->templater; // prepare templater helpers and globals vars $this->templater->vars['ctx'] = $context; $this->templater->helpers['url'] = [$context, 'url']; $this->templater->helpers['call'] = [$context, 'forward']; return $context; }
php
protected function before(Context $context) { // kernel before handler $context = parent::before($context); // add templater to context $context->templater = $this->templater; // prepare templater helpers and globals vars $this->templater->vars['ctx'] = $context; $this->templater->helpers['url'] = [$context, 'url']; $this->templater->helpers['call'] = [$context, 'forward']; return $context; }
[ "protected", "function", "before", "(", "Context", "$", "context", ")", "{", "// kernel before handler", "$", "context", "=", "parent", "::", "before", "(", "$", "context", ")", ";", "// add templater to context", "$", "context", "->", "templater", "=", "$", "this", "->", "templater", ";", "// prepare templater helpers and globals vars", "$", "this", "->", "templater", "->", "vars", "[", "'ctx'", "]", "=", "$", "context", ";", "$", "this", "->", "templater", "->", "helpers", "[", "'url'", "]", "=", "[", "$", "context", ",", "'url'", "]", ";", "$", "this", "->", "templater", "->", "helpers", "[", "'call'", "]", "=", "[", "$", "context", ",", "'forward'", "]", ";", "return", "$", "context", ";", "}" ]
Before handler @param Context $context @return Context
[ "Before", "handler" ]
train
https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/App.php#L35-L49