id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
6,700
n0m4dz/laracasa
Zend/Gdata/Spreadsheets/CellQuery.php
Zend_Gdata_Spreadsheets_CellQuery.setMaxCol
public function setMaxCol($value) { if ($value != null) { $this->_params['max-col'] = $value; } else { unset($this->_params['max-col']); } return $this; }
php
public function setMaxCol($value) { if ($value != null) { $this->_params['max-col'] = $value; } else { unset($this->_params['max-col']); } return $this; }
[ "public", "function", "setMaxCol", "(", "$", "value", ")", "{", "if", "(", "$", "value", "!=", "null", ")", "{", "$", "this", "->", "_params", "[", "'max-col'", "]", "=", "$", "value", ";", "}", "else", "{", "unset", "(", "$", "this", "->", "_params", "[", "'max-col'", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Sets the max-col attribute for this query. @param string $value @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
[ "Sets", "the", "max", "-", "col", "attribute", "for", "this", "query", "." ]
6141f0c16c7d4453275e3b74be5041f336085c91
https://github.com/n0m4dz/laracasa/blob/6141f0c16c7d4453275e3b74be5041f336085c91/Zend/Gdata/Spreadsheets/CellQuery.php#L272-L280
6,701
n0m4dz/laracasa
Zend/Gdata/Spreadsheets/CellQuery.php
Zend_Gdata_Spreadsheets_CellQuery.setRange
public function setRange($value) { if ($value != null) { $this->_params['range'] = $value; } else { unset($this->_params['range']); } return $this; }
php
public function setRange($value) { if ($value != null) { $this->_params['range'] = $value; } else { unset($this->_params['range']); } return $this; }
[ "public", "function", "setRange", "(", "$", "value", ")", "{", "if", "(", "$", "value", "!=", "null", ")", "{", "$", "this", "->", "_params", "[", "'range'", "]", "=", "$", "value", ";", "}", "else", "{", "unset", "(", "$", "this", "->", "_params", "[", "'range'", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Sets the range attribute for this query. @param string $value @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
[ "Sets", "the", "range", "attribute", "for", "this", "query", "." ]
6141f0c16c7d4453275e3b74be5041f336085c91
https://github.com/n0m4dz/laracasa/blob/6141f0c16c7d4453275e3b74be5041f336085c91/Zend/Gdata/Spreadsheets/CellQuery.php#L302-L310
6,702
n0m4dz/laracasa
Zend/Gdata/Spreadsheets/CellQuery.php
Zend_Gdata_Spreadsheets_CellQuery.setReturnEmpty
public function setReturnEmpty($value) { if (is_bool($value)) { $this->_params['return-empty'] = ($value?'true':'false'); } else if ($value != null) { $this->_params['return-empty'] = $value; } else { unset($this->_params['return-empty']); } return $this; }
php
public function setReturnEmpty($value) { if (is_bool($value)) { $this->_params['return-empty'] = ($value?'true':'false'); } else if ($value != null) { $this->_params['return-empty'] = $value; } else { unset($this->_params['return-empty']); } return $this; }
[ "public", "function", "setReturnEmpty", "(", "$", "value", ")", "{", "if", "(", "is_bool", "(", "$", "value", ")", ")", "{", "$", "this", "->", "_params", "[", "'return-empty'", "]", "=", "(", "$", "value", "?", "'true'", ":", "'false'", ")", ";", "}", "else", "if", "(", "$", "value", "!=", "null", ")", "{", "$", "this", "->", "_params", "[", "'return-empty'", "]", "=", "$", "value", ";", "}", "else", "{", "unset", "(", "$", "this", "->", "_params", "[", "'return-empty'", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Sets the return-empty attribute for this query. @param mixed $value String or bool value for whether to return empty cells @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
[ "Sets", "the", "return", "-", "empty", "attribute", "for", "this", "query", "." ]
6141f0c16c7d4453275e3b74be5041f336085c91
https://github.com/n0m4dz/laracasa/blob/6141f0c16c7d4453275e3b74be5041f336085c91/Zend/Gdata/Spreadsheets/CellQuery.php#L332-L342
6,703
apitude/apitude
src/Provider/AbstractServiceProvider.php
AbstractServiceProvider.addFirewall
protected function addFirewall(Application $app, $pattern, $authType) { $firewalls = $app['security.firewalls']; $key = is_object($pattern) ? spl_object_hash($pattern) : $pattern; $firewalls[$key] = [ 'pattern' => $pattern, $authType => true, ]; $app['security.firewalls'] = $firewalls; }
php
protected function addFirewall(Application $app, $pattern, $authType) { $firewalls = $app['security.firewalls']; $key = is_object($pattern) ? spl_object_hash($pattern) : $pattern; $firewalls[$key] = [ 'pattern' => $pattern, $authType => true, ]; $app['security.firewalls'] = $firewalls; }
[ "protected", "function", "addFirewall", "(", "Application", "$", "app", ",", "$", "pattern", ",", "$", "authType", ")", "{", "$", "firewalls", "=", "$", "app", "[", "'security.firewalls'", "]", ";", "$", "key", "=", "is_object", "(", "$", "pattern", ")", "?", "spl_object_hash", "(", "$", "pattern", ")", ":", "$", "pattern", ";", "$", "firewalls", "[", "$", "key", "]", "=", "[", "'pattern'", "=>", "$", "pattern", ",", "$", "authType", "=>", "true", ",", "]", ";", "$", "app", "[", "'security.firewalls'", "]", "=", "$", "firewalls", ";", "}" ]
Add a firewall record @param Application $app @param string|RequestMatcher $pattern @param string $authType (oauth, anonymous, oauth-optional, etc)
[ "Add", "a", "firewall", "record" ]
ccf503e42214184f96cd73b4e0fc5d06c377bce5
https://github.com/apitude/apitude/blob/ccf503e42214184f96cd73b4e0fc5d06c377bce5/src/Provider/AbstractServiceProvider.php#L85-L95
6,704
apitude/apitude
src/Provider/AbstractServiceProvider.php
AbstractServiceProvider.addAccessRule
protected function addAccessRule(Application $app, $pattern, $roles) { $security = $app['security.access_rules']; $key = is_object($pattern) ? spl_object_hash($pattern) : $pattern; $security[$key] = [ $pattern, $roles ]; $app['security.access_rules'] = $security; }
php
protected function addAccessRule(Application $app, $pattern, $roles) { $security = $app['security.access_rules']; $key = is_object($pattern) ? spl_object_hash($pattern) : $pattern; $security[$key] = [ $pattern, $roles ]; $app['security.access_rules'] = $security; }
[ "protected", "function", "addAccessRule", "(", "Application", "$", "app", ",", "$", "pattern", ",", "$", "roles", ")", "{", "$", "security", "=", "$", "app", "[", "'security.access_rules'", "]", ";", "$", "key", "=", "is_object", "(", "$", "pattern", ")", "?", "spl_object_hash", "(", "$", "pattern", ")", ":", "$", "pattern", ";", "$", "security", "[", "$", "key", "]", "=", "[", "$", "pattern", ",", "$", "roles", "]", ";", "$", "app", "[", "'security.access_rules'", "]", "=", "$", "security", ";", "}" ]
Add access rule to limit specific paths by role @param Application $app @param string $pattern @param string|array $roles
[ "Add", "access", "rule", "to", "limit", "specific", "paths", "by", "role" ]
ccf503e42214184f96cd73b4e0fc5d06c377bce5
https://github.com/apitude/apitude/blob/ccf503e42214184f96cd73b4e0fc5d06c377bce5/src/Provider/AbstractServiceProvider.php#L103-L112
6,705
rseyferth/activerecord
lib/DateTime.php
DateTime.getFormat
public static function getFormat($format=null) { // use default format if no format specified if (!$format) $format = self::$DEFAULT_FORMAT; // format is a friendly if (array_key_exists($format, self::$FORMATS)) return self::$FORMATS[$format]; // raw format return $format; }
php
public static function getFormat($format=null) { // use default format if no format specified if (!$format) $format = self::$DEFAULT_FORMAT; // format is a friendly if (array_key_exists($format, self::$FORMATS)) return self::$FORMATS[$format]; // raw format return $format; }
[ "public", "static", "function", "getFormat", "(", "$", "format", "=", "null", ")", "{", "// use default format if no format specified", "if", "(", "!", "$", "format", ")", "$", "format", "=", "self", "::", "$", "DEFAULT_FORMAT", ";", "// format is a friendly", "if", "(", "array_key_exists", "(", "$", "format", ",", "self", "::", "$", "FORMATS", ")", ")", "return", "self", "::", "$", "FORMATS", "[", "$", "format", "]", ";", "// raw format", "return", "$", "format", ";", "}" ]
Returns the format string. If $format is a pre-defined format in $FORMATS it will return that otherwise it will assume $format is a format string itself. @see FORMATS @param string $format A pre-defined string format or a raw format string @return string a format string
[ "Returns", "the", "format", "string", "." ]
0e7b1cbddd6f967c3a09adf38753babd5f698e39
https://github.com/rseyferth/activerecord/blob/0e7b1cbddd6f967c3a09adf38753babd5f698e39/lib/DateTime.php#L102-L114
6,706
bishopb/vanilla
applications/vanilla/models/class.draftmodel.php
DraftModel.Get
public function Get($UserID, $Offset = '0', $Limit = '', $DiscussionID = '') { if (!is_numeric($Offset) || $Offset < 0) $Offset = 0; if (!is_numeric($Limit) || $Limit < 1) $Limit = 100; $this->DraftQuery(); $this->SQL ->Select('d.Name, di.Name', 'coalesce', 'Name') ->Join('Discussion di', 'd.discussionID = di.DiscussionID', 'left') ->Where('d.InsertUserID', $UserID) ->OrderBy('d.DateInserted', 'desc') ->Limit($Limit, $Offset); if (is_numeric($DiscussionID) && $DiscussionID > 0) $this->SQL->Where('d.DiscussionID', $DiscussionID); return $this->SQL->Get(); }
php
public function Get($UserID, $Offset = '0', $Limit = '', $DiscussionID = '') { if (!is_numeric($Offset) || $Offset < 0) $Offset = 0; if (!is_numeric($Limit) || $Limit < 1) $Limit = 100; $this->DraftQuery(); $this->SQL ->Select('d.Name, di.Name', 'coalesce', 'Name') ->Join('Discussion di', 'd.discussionID = di.DiscussionID', 'left') ->Where('d.InsertUserID', $UserID) ->OrderBy('d.DateInserted', 'desc') ->Limit($Limit, $Offset); if (is_numeric($DiscussionID) && $DiscussionID > 0) $this->SQL->Where('d.DiscussionID', $DiscussionID); return $this->SQL->Get(); }
[ "public", "function", "Get", "(", "$", "UserID", ",", "$", "Offset", "=", "'0'", ",", "$", "Limit", "=", "''", ",", "$", "DiscussionID", "=", "''", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "Offset", ")", "||", "$", "Offset", "<", "0", ")", "$", "Offset", "=", "0", ";", "if", "(", "!", "is_numeric", "(", "$", "Limit", ")", "||", "$", "Limit", "<", "1", ")", "$", "Limit", "=", "100", ";", "$", "this", "->", "DraftQuery", "(", ")", ";", "$", "this", "->", "SQL", "->", "Select", "(", "'d.Name, di.Name'", ",", "'coalesce'", ",", "'Name'", ")", "->", "Join", "(", "'Discussion di'", ",", "'d.discussionID = di.DiscussionID'", ",", "'left'", ")", "->", "Where", "(", "'d.InsertUserID'", ",", "$", "UserID", ")", "->", "OrderBy", "(", "'d.DateInserted'", ",", "'desc'", ")", "->", "Limit", "(", "$", "Limit", ",", "$", "Offset", ")", ";", "if", "(", "is_numeric", "(", "$", "DiscussionID", ")", "&&", "$", "DiscussionID", ">", "0", ")", "$", "this", "->", "SQL", "->", "Where", "(", "'d.DiscussionID'", ",", "$", "DiscussionID", ")", ";", "return", "$", "this", "->", "SQL", "->", "Get", "(", ")", ";", "}" ]
Gets drafts matching the given criteria. @since 2.0.0 @access public @param int $UserID Unique ID of user that wrote the drafts. @param int $Offset Number of results to skip. @param int $Limit Max number of drafts to return. @param int $DiscussionID Limits drafts returned to a single discussion. @return object Gdn_DataSet SQL results.
[ "Gets", "drafts", "matching", "the", "given", "criteria", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/models/class.draftmodel.php#L57-L76
6,707
bishopb/vanilla
applications/vanilla/models/class.draftmodel.php
DraftModel.GetID
public function GetID($DraftID) { $this->DraftQuery(); return $this->SQL ->Where('d.DraftID', $DraftID) ->Get() ->FirstRow(); }
php
public function GetID($DraftID) { $this->DraftQuery(); return $this->SQL ->Where('d.DraftID', $DraftID) ->Get() ->FirstRow(); }
[ "public", "function", "GetID", "(", "$", "DraftID", ")", "{", "$", "this", "->", "DraftQuery", "(", ")", ";", "return", "$", "this", "->", "SQL", "->", "Where", "(", "'d.DraftID'", ",", "$", "DraftID", ")", "->", "Get", "(", ")", "->", "FirstRow", "(", ")", ";", "}" ]
Gets data for a single draft. @since 2.0.0 @access public @param int $DraftID Unique ID of draft to get data for. @return object SQL results.
[ "Gets", "data", "for", "a", "single", "draft", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/models/class.draftmodel.php#L87-L93
6,708
bishopb/vanilla
applications/vanilla/models/class.draftmodel.php
DraftModel.GetCount
public function GetCount($UserID) { return $this->SQL ->Select('DraftID', 'count', 'CountDrafts') ->From('Draft') ->Where('InsertUserID', $UserID) ->Get() ->FirstRow() ->CountDrafts; }
php
public function GetCount($UserID) { return $this->SQL ->Select('DraftID', 'count', 'CountDrafts') ->From('Draft') ->Where('InsertUserID', $UserID) ->Get() ->FirstRow() ->CountDrafts; }
[ "public", "function", "GetCount", "(", "$", "UserID", ")", "{", "return", "$", "this", "->", "SQL", "->", "Select", "(", "'DraftID'", ",", "'count'", ",", "'CountDrafts'", ")", "->", "From", "(", "'Draft'", ")", "->", "Where", "(", "'InsertUserID'", ",", "$", "UserID", ")", "->", "Get", "(", ")", "->", "FirstRow", "(", ")", "->", "CountDrafts", ";", "}" ]
Gets number of drafts a user has. @since 2.0.0 @access public @param int $UserID Unique ID of user to count drafts for. @return int Total drafts.
[ "Gets", "number", "of", "drafts", "a", "user", "has", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/models/class.draftmodel.php#L104-L112
6,709
bishopb/vanilla
applications/vanilla/models/class.draftmodel.php
DraftModel.Save
public function Save($FormPostValues) { $Session = Gdn::Session(); // Define the primary key in this model's table. $this->DefineSchema(); // Add & apply any extra validation rules: $this->Validation->ApplyRule('Body', 'Required'); $MaxCommentLength = Gdn::Config('Vanilla.Comment.MaxLength'); if (is_numeric($MaxCommentLength) && $MaxCommentLength > 0) { $this->Validation->SetSchemaProperty('Body', 'Length', $MaxCommentLength); $this->Validation->ApplyRule('Body', 'Length'); } // Get the DraftID from the form so we know if we are inserting or updating. $DraftID = ArrayValue('DraftID', $FormPostValues, ''); $Insert = $DraftID == '' ? TRUE : FALSE; // Remove the discussionid from the form value collection if it's empty if (array_key_exists('DiscussionID', $FormPostValues) && $FormPostValues['DiscussionID'] == '') unset($FormPostValues['DiscussionID']); if ($Insert) { // If no categoryid is defined, grab the first available. if (ArrayValue('CategoryID', $FormPostValues) === FALSE) $FormPostValues['CategoryID'] = $this->SQL->Get('Category', '', '', 1)->FirstRow()->CategoryID; } // Add the update fields because this table's default sort is by DateUpdated (see $this->Get()). $this->AddInsertFields($FormPostValues); $this->AddUpdateFields($FormPostValues); // Remove checkboxes from the fields if they were unchecked if (ArrayValue('Announce', $FormPostValues, '') === FALSE) unset($FormPostValues['Announce']); if (ArrayValue('Closed', $FormPostValues, '') === FALSE) unset($FormPostValues['Closed']); if (ArrayValue('Sink', $FormPostValues, '') === FALSE) unset($FormPostValues['Sink']); // Validate the form posted values if ($this->Validate($FormPostValues, $Insert)) { $Fields = $this->Validation->SchemaValidationFields(); // All fields on the form that relate to the schema $DraftID = intval(ArrayValue('DraftID', $Fields, 0)); // If the post is new and it validates, make sure the user isn't spamming if ($DraftID > 0) { // Update the draft $Fields = RemoveKeyFromArray($Fields, 'DraftID'); // Remove the primary key from the fields for saving $this->SQL->Put($this->Name, $Fields, array($this->PrimaryKey => $DraftID)); } else { // Insert the draft unset($Fields['DraftID']); $DraftID = $this->SQL->Insert($this->Name, $Fields); $this->UpdateUser($Session->UserID); } } return $DraftID; }
php
public function Save($FormPostValues) { $Session = Gdn::Session(); // Define the primary key in this model's table. $this->DefineSchema(); // Add & apply any extra validation rules: $this->Validation->ApplyRule('Body', 'Required'); $MaxCommentLength = Gdn::Config('Vanilla.Comment.MaxLength'); if (is_numeric($MaxCommentLength) && $MaxCommentLength > 0) { $this->Validation->SetSchemaProperty('Body', 'Length', $MaxCommentLength); $this->Validation->ApplyRule('Body', 'Length'); } // Get the DraftID from the form so we know if we are inserting or updating. $DraftID = ArrayValue('DraftID', $FormPostValues, ''); $Insert = $DraftID == '' ? TRUE : FALSE; // Remove the discussionid from the form value collection if it's empty if (array_key_exists('DiscussionID', $FormPostValues) && $FormPostValues['DiscussionID'] == '') unset($FormPostValues['DiscussionID']); if ($Insert) { // If no categoryid is defined, grab the first available. if (ArrayValue('CategoryID', $FormPostValues) === FALSE) $FormPostValues['CategoryID'] = $this->SQL->Get('Category', '', '', 1)->FirstRow()->CategoryID; } // Add the update fields because this table's default sort is by DateUpdated (see $this->Get()). $this->AddInsertFields($FormPostValues); $this->AddUpdateFields($FormPostValues); // Remove checkboxes from the fields if they were unchecked if (ArrayValue('Announce', $FormPostValues, '') === FALSE) unset($FormPostValues['Announce']); if (ArrayValue('Closed', $FormPostValues, '') === FALSE) unset($FormPostValues['Closed']); if (ArrayValue('Sink', $FormPostValues, '') === FALSE) unset($FormPostValues['Sink']); // Validate the form posted values if ($this->Validate($FormPostValues, $Insert)) { $Fields = $this->Validation->SchemaValidationFields(); // All fields on the form that relate to the schema $DraftID = intval(ArrayValue('DraftID', $Fields, 0)); // If the post is new and it validates, make sure the user isn't spamming if ($DraftID > 0) { // Update the draft $Fields = RemoveKeyFromArray($Fields, 'DraftID'); // Remove the primary key from the fields for saving $this->SQL->Put($this->Name, $Fields, array($this->PrimaryKey => $DraftID)); } else { // Insert the draft unset($Fields['DraftID']); $DraftID = $this->SQL->Insert($this->Name, $Fields); $this->UpdateUser($Session->UserID); } } return $DraftID; }
[ "public", "function", "Save", "(", "$", "FormPostValues", ")", "{", "$", "Session", "=", "Gdn", "::", "Session", "(", ")", ";", "// Define the primary key in this model's table.", "$", "this", "->", "DefineSchema", "(", ")", ";", "// Add & apply any extra validation rules: ", "$", "this", "->", "Validation", "->", "ApplyRule", "(", "'Body'", ",", "'Required'", ")", ";", "$", "MaxCommentLength", "=", "Gdn", "::", "Config", "(", "'Vanilla.Comment.MaxLength'", ")", ";", "if", "(", "is_numeric", "(", "$", "MaxCommentLength", ")", "&&", "$", "MaxCommentLength", ">", "0", ")", "{", "$", "this", "->", "Validation", "->", "SetSchemaProperty", "(", "'Body'", ",", "'Length'", ",", "$", "MaxCommentLength", ")", ";", "$", "this", "->", "Validation", "->", "ApplyRule", "(", "'Body'", ",", "'Length'", ")", ";", "}", "// Get the DraftID from the form so we know if we are inserting or updating.", "$", "DraftID", "=", "ArrayValue", "(", "'DraftID'", ",", "$", "FormPostValues", ",", "''", ")", ";", "$", "Insert", "=", "$", "DraftID", "==", "''", "?", "TRUE", ":", "FALSE", ";", "// Remove the discussionid from the form value collection if it's empty", "if", "(", "array_key_exists", "(", "'DiscussionID'", ",", "$", "FormPostValues", ")", "&&", "$", "FormPostValues", "[", "'DiscussionID'", "]", "==", "''", ")", "unset", "(", "$", "FormPostValues", "[", "'DiscussionID'", "]", ")", ";", "if", "(", "$", "Insert", ")", "{", "// If no categoryid is defined, grab the first available.", "if", "(", "ArrayValue", "(", "'CategoryID'", ",", "$", "FormPostValues", ")", "===", "FALSE", ")", "$", "FormPostValues", "[", "'CategoryID'", "]", "=", "$", "this", "->", "SQL", "->", "Get", "(", "'Category'", ",", "''", ",", "''", ",", "1", ")", "->", "FirstRow", "(", ")", "->", "CategoryID", ";", "}", "// Add the update fields because this table's default sort is by DateUpdated (see $this->Get()).", "$", "this", "->", "AddInsertFields", "(", "$", "FormPostValues", ")", ";", "$", "this", "->", "AddUpdateFields", "(", "$", "FormPostValues", ")", ";", "// Remove checkboxes from the fields if they were unchecked", "if", "(", "ArrayValue", "(", "'Announce'", ",", "$", "FormPostValues", ",", "''", ")", "===", "FALSE", ")", "unset", "(", "$", "FormPostValues", "[", "'Announce'", "]", ")", ";", "if", "(", "ArrayValue", "(", "'Closed'", ",", "$", "FormPostValues", ",", "''", ")", "===", "FALSE", ")", "unset", "(", "$", "FormPostValues", "[", "'Closed'", "]", ")", ";", "if", "(", "ArrayValue", "(", "'Sink'", ",", "$", "FormPostValues", ",", "''", ")", "===", "FALSE", ")", "unset", "(", "$", "FormPostValues", "[", "'Sink'", "]", ")", ";", "// Validate the form posted values", "if", "(", "$", "this", "->", "Validate", "(", "$", "FormPostValues", ",", "$", "Insert", ")", ")", "{", "$", "Fields", "=", "$", "this", "->", "Validation", "->", "SchemaValidationFields", "(", ")", ";", "// All fields on the form that relate to the schema", "$", "DraftID", "=", "intval", "(", "ArrayValue", "(", "'DraftID'", ",", "$", "Fields", ",", "0", ")", ")", ";", "// If the post is new and it validates, make sure the user isn't spamming", "if", "(", "$", "DraftID", ">", "0", ")", "{", "// Update the draft", "$", "Fields", "=", "RemoveKeyFromArray", "(", "$", "Fields", ",", "'DraftID'", ")", ";", "// Remove the primary key from the fields for saving", "$", "this", "->", "SQL", "->", "Put", "(", "$", "this", "->", "Name", ",", "$", "Fields", ",", "array", "(", "$", "this", "->", "PrimaryKey", "=>", "$", "DraftID", ")", ")", ";", "}", "else", "{", "// Insert the draft", "unset", "(", "$", "Fields", "[", "'DraftID'", "]", ")", ";", "$", "DraftID", "=", "$", "this", "->", "SQL", "->", "Insert", "(", "$", "this", "->", "Name", ",", "$", "Fields", ")", ";", "$", "this", "->", "UpdateUser", "(", "$", "Session", "->", "UserID", ")", ";", "}", "}", "return", "$", "DraftID", ";", "}" ]
Insert or update a draft from form values. @since 2.0.0 @access public @param array $FormPostValues Form values sent from form model. @return int Unique ID of draft.
[ "Insert", "or", "update", "a", "draft", "from", "form", "values", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/models/class.draftmodel.php#L123-L184
6,710
bishopb/vanilla
applications/vanilla/models/class.draftmodel.php
DraftModel.Delete
public function Delete($DraftID) { // Get some information about this draft $DraftUser = $this->SQL ->Select('InsertUserID') ->From('Draft') ->Where('DraftID', $DraftID) ->Get() ->FirstRow(); $this->SQL->Delete('Draft', array('DraftID' => $DraftID)); if (is_object($DraftUser)) $this->UpdateUser($DraftUser->InsertUserID); return TRUE; }
php
public function Delete($DraftID) { // Get some information about this draft $DraftUser = $this->SQL ->Select('InsertUserID') ->From('Draft') ->Where('DraftID', $DraftID) ->Get() ->FirstRow(); $this->SQL->Delete('Draft', array('DraftID' => $DraftID)); if (is_object($DraftUser)) $this->UpdateUser($DraftUser->InsertUserID); return TRUE; }
[ "public", "function", "Delete", "(", "$", "DraftID", ")", "{", "// Get some information about this draft", "$", "DraftUser", "=", "$", "this", "->", "SQL", "->", "Select", "(", "'InsertUserID'", ")", "->", "From", "(", "'Draft'", ")", "->", "Where", "(", "'DraftID'", ",", "$", "DraftID", ")", "->", "Get", "(", ")", "->", "FirstRow", "(", ")", ";", "$", "this", "->", "SQL", "->", "Delete", "(", "'Draft'", ",", "array", "(", "'DraftID'", "=>", "$", "DraftID", ")", ")", ";", "if", "(", "is_object", "(", "$", "DraftUser", ")", ")", "$", "this", "->", "UpdateUser", "(", "$", "DraftUser", "->", "InsertUserID", ")", ";", "return", "TRUE", ";", "}" ]
Deletes a specified draft. This is a hard delete that completely removes it. @since 2.0.0 @access public @param int $DraftID Unique ID of the draft to be deleted. @return bool Always returns TRUE.
[ "Deletes", "a", "specified", "draft", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/models/class.draftmodel.php#L197-L211
6,711
bishopb/vanilla
applications/vanilla/models/class.draftmodel.php
DraftModel.UpdateUser
public function UpdateUser($UserID) { // Retrieve a draft count $CountDrafts = $this->GetCount($UserID); // Update CountDrafts column of user table fot this user Gdn::UserModel()->SetField($UserID, 'CountDrafts', $CountDrafts); }
php
public function UpdateUser($UserID) { // Retrieve a draft count $CountDrafts = $this->GetCount($UserID); // Update CountDrafts column of user table fot this user Gdn::UserModel()->SetField($UserID, 'CountDrafts', $CountDrafts); }
[ "public", "function", "UpdateUser", "(", "$", "UserID", ")", "{", "// Retrieve a draft count", "$", "CountDrafts", "=", "$", "this", "->", "GetCount", "(", "$", "UserID", ")", ";", "// Update CountDrafts column of user table fot this user", "Gdn", "::", "UserModel", "(", ")", "->", "SetField", "(", "$", "UserID", ",", "'CountDrafts'", ",", "$", "CountDrafts", ")", ";", "}" ]
Updates a user's draft count. @since 2.0.0 @access public @param int $UserID Unique ID of the user to be updated.
[ "Updates", "a", "user", "s", "draft", "count", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/vanilla/models/class.draftmodel.php#L221-L227
6,712
Hexmedia/Administrator-Bundle
Controller/EditModeController.php
EditModeController.jsonSaveAction
public function jsonSaveAction(Request $request) { //@FIXME: This code need to be moved to ContentController somehow. $this->save($request); $response = new Response(json_encode(['status' => 'ok'])); $response->headers->set("Content-Type", 'application/json'); return $response; }
php
public function jsonSaveAction(Request $request) { //@FIXME: This code need to be moved to ContentController somehow. $this->save($request); $response = new Response(json_encode(['status' => 'ok'])); $response->headers->set("Content-Type", 'application/json'); return $response; }
[ "public", "function", "jsonSaveAction", "(", "Request", "$", "request", ")", "{", "//@FIXME: This code need to be moved to ContentController somehow.", "$", "this", "->", "save", "(", "$", "request", ")", ";", "$", "response", "=", "new", "Response", "(", "json_encode", "(", "[", "'status'", "=>", "'ok'", "]", ")", ")", ";", "$", "response", "->", "headers", "->", "set", "(", "\"Content-Type\"", ",", "'application/json'", ")", ";", "return", "$", "response", ";", "}" ]
Save from Raptor @param string $type @param \Symfony\Component\HttpFoundation\Request $request @return \Symfony\Component\HttpFoundation\Response
[ "Save", "from", "Raptor" ]
ac76cf3d226cd645a0976cfb6f3e6b058fa89890
https://github.com/Hexmedia/Administrator-Bundle/blob/ac76cf3d226cd645a0976cfb6f3e6b058fa89890/Controller/EditModeController.php#L69-L78
6,713
mszewcz/php-json-schema-validator
src/Validators/MiscValidators/TypeValidator.php
TypeValidator.validate
public function validate($subject): bool { switch ($this->schema['type']) { case 'boolean': return $this->validateTypBoolean($subject); case 'number': case 'integer': case 'float': return $this->validateTypeNumeric($subject); case 'string': return $this->validateTypeString($subject); case 'array': return $this->validateTypeArray($subject); case 'object': return $this->validateTypeObject($subject); case 'null': return $this->validateTypeNull($subject); } return false; }
php
public function validate($subject): bool { switch ($this->schema['type']) { case 'boolean': return $this->validateTypBoolean($subject); case 'number': case 'integer': case 'float': return $this->validateTypeNumeric($subject); case 'string': return $this->validateTypeString($subject); case 'array': return $this->validateTypeArray($subject); case 'object': return $this->validateTypeObject($subject); case 'null': return $this->validateTypeNull($subject); } return false; }
[ "public", "function", "validate", "(", "$", "subject", ")", ":", "bool", "{", "switch", "(", "$", "this", "->", "schema", "[", "'type'", "]", ")", "{", "case", "'boolean'", ":", "return", "$", "this", "->", "validateTypBoolean", "(", "$", "subject", ")", ";", "case", "'number'", ":", "case", "'integer'", ":", "case", "'float'", ":", "return", "$", "this", "->", "validateTypeNumeric", "(", "$", "subject", ")", ";", "case", "'string'", ":", "return", "$", "this", "->", "validateTypeString", "(", "$", "subject", ")", ";", "case", "'array'", ":", "return", "$", "this", "->", "validateTypeArray", "(", "$", "subject", ")", ";", "case", "'object'", ":", "return", "$", "this", "->", "validateTypeObject", "(", "$", "subject", ")", ";", "case", "'null'", ":", "return", "$", "this", "->", "validateTypeNull", "(", "$", "subject", ")", ";", "}", "return", "false", ";", "}" ]
Validates subject against type @param $subject @return bool
[ "Validates", "subject", "against", "type" ]
f7768bfe07ce6508bb1ff36163560a5e5791de7d
https://github.com/mszewcz/php-json-schema-validator/blob/f7768bfe07ce6508bb1ff36163560a5e5791de7d/src/Validators/MiscValidators/TypeValidator.php#L47-L66
6,714
mszewcz/php-json-schema-validator
src/Validators/MiscValidators/TypeValidator.php
TypeValidator.validateTypeArray
private function validateTypeArray($subject): bool { if (!\is_array($subject)) { return false; } if (count($subject) > 0 && !\is_int(\array_keys($subject)[0])) { return false; } return true; }
php
private function validateTypeArray($subject): bool { if (!\is_array($subject)) { return false; } if (count($subject) > 0 && !\is_int(\array_keys($subject)[0])) { return false; } return true; }
[ "private", "function", "validateTypeArray", "(", "$", "subject", ")", ":", "bool", "{", "if", "(", "!", "\\", "is_array", "(", "$", "subject", ")", ")", "{", "return", "false", ";", "}", "if", "(", "count", "(", "$", "subject", ")", ">", "0", "&&", "!", "\\", "is_int", "(", "\\", "array_keys", "(", "$", "subject", ")", "[", "0", "]", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Validates subject against type = array @param $subject @return bool
[ "Validates", "subject", "against", "type", "=", "array" ]
f7768bfe07ce6508bb1ff36163560a5e5791de7d
https://github.com/mszewcz/php-json-schema-validator/blob/f7768bfe07ce6508bb1ff36163560a5e5791de7d/src/Validators/MiscValidators/TypeValidator.php#L122-L131
6,715
mszewcz/php-json-schema-validator
src/Validators/MiscValidators/TypeValidator.php
TypeValidator.validateTypeObject
private function validateTypeObject($subject): bool { if (!\is_array($subject)) { return false; } if (count($subject) > 0 && !\is_string(\array_keys($subject)[0])) { return false; } return true; }
php
private function validateTypeObject($subject): bool { if (!\is_array($subject)) { return false; } if (count($subject) > 0 && !\is_string(\array_keys($subject)[0])) { return false; } return true; }
[ "private", "function", "validateTypeObject", "(", "$", "subject", ")", ":", "bool", "{", "if", "(", "!", "\\", "is_array", "(", "$", "subject", ")", ")", "{", "return", "false", ";", "}", "if", "(", "count", "(", "$", "subject", ")", ">", "0", "&&", "!", "\\", "is_string", "(", "\\", "array_keys", "(", "$", "subject", ")", "[", "0", "]", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Validates subject against type = object @param $subject @return bool
[ "Validates", "subject", "against", "type", "=", "object" ]
f7768bfe07ce6508bb1ff36163560a5e5791de7d
https://github.com/mszewcz/php-json-schema-validator/blob/f7768bfe07ce6508bb1ff36163560a5e5791de7d/src/Validators/MiscValidators/TypeValidator.php#L139-L148
6,716
oasmobile/php-doctrine-addon
src/CascadeRemoveTrait.php
CascadeRemoveTrait.findCascadeDetachableEntities
private function findCascadeDetachableEntities(EntityManager $em, CascadeRemovableInterface $entity, &$visited = [], $depth = 0) { $id = $em->getUnitOfWork()->getEntityIdentifier($entity); $key = serialize([get_class($entity), $id]); $visited[$key] = $entity; $entities = $entity->getCascadeRemoveableEntities(); foreach ($entities as $subEntity) { $id = $em->getUnitOfWork()->getEntityIdentifier($subEntity); $key = serialize([get_class($subEntity), $id]); if (array_key_exists($key, $visited)) { //mdebug( // "%sSkipping %s %d when detaching %s %d", // str_repeat(' ', $depth * 4), // get_class($subEntity), // $subEntity->getId(), // get_class($entity), // $entity->getId() //); continue; } //mdebug( // "%sCascade removing %s %d when removing %s %d", // str_repeat(' ', $depth * 4), // get_class($subEntity), // $subEntity->getId(), // get_class($entity), // $entity->getId() //); if ($subEntity instanceof CascadeRemovableInterface) { $this->findCascadeDetachableEntities($em, $subEntity, $visited, $depth + 1); } else { $visited[$key] = $subEntity; } } }
php
private function findCascadeDetachableEntities(EntityManager $em, CascadeRemovableInterface $entity, &$visited = [], $depth = 0) { $id = $em->getUnitOfWork()->getEntityIdentifier($entity); $key = serialize([get_class($entity), $id]); $visited[$key] = $entity; $entities = $entity->getCascadeRemoveableEntities(); foreach ($entities as $subEntity) { $id = $em->getUnitOfWork()->getEntityIdentifier($subEntity); $key = serialize([get_class($subEntity), $id]); if (array_key_exists($key, $visited)) { //mdebug( // "%sSkipping %s %d when detaching %s %d", // str_repeat(' ', $depth * 4), // get_class($subEntity), // $subEntity->getId(), // get_class($entity), // $entity->getId() //); continue; } //mdebug( // "%sCascade removing %s %d when removing %s %d", // str_repeat(' ', $depth * 4), // get_class($subEntity), // $subEntity->getId(), // get_class($entity), // $entity->getId() //); if ($subEntity instanceof CascadeRemovableInterface) { $this->findCascadeDetachableEntities($em, $subEntity, $visited, $depth + 1); } else { $visited[$key] = $subEntity; } } }
[ "private", "function", "findCascadeDetachableEntities", "(", "EntityManager", "$", "em", ",", "CascadeRemovableInterface", "$", "entity", ",", "&", "$", "visited", "=", "[", "]", ",", "$", "depth", "=", "0", ")", "{", "$", "id", "=", "$", "em", "->", "getUnitOfWork", "(", ")", "->", "getEntityIdentifier", "(", "$", "entity", ")", ";", "$", "key", "=", "serialize", "(", "[", "get_class", "(", "$", "entity", ")", ",", "$", "id", "]", ")", ";", "$", "visited", "[", "$", "key", "]", "=", "$", "entity", ";", "$", "entities", "=", "$", "entity", "->", "getCascadeRemoveableEntities", "(", ")", ";", "foreach", "(", "$", "entities", "as", "$", "subEntity", ")", "{", "$", "id", "=", "$", "em", "->", "getUnitOfWork", "(", ")", "->", "getEntityIdentifier", "(", "$", "subEntity", ")", ";", "$", "key", "=", "serialize", "(", "[", "get_class", "(", "$", "subEntity", ")", ",", "$", "id", "]", ")", ";", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "visited", ")", ")", "{", "//mdebug(", "// \"%sSkipping %s %d when detaching %s %d\",", "// str_repeat(' ', $depth * 4),", "// get_class($subEntity),", "// $subEntity->getId(),", "// get_class($entity),", "// $entity->getId()", "//);", "continue", ";", "}", "//mdebug(", "// \"%sCascade removing %s %d when removing %s %d\",", "// str_repeat(' ', $depth * 4),", "// get_class($subEntity),", "// $subEntity->getId(),", "// get_class($entity),", "// $entity->getId()", "//);", "if", "(", "$", "subEntity", "instanceof", "CascadeRemovableInterface", ")", "{", "$", "this", "->", "findCascadeDetachableEntities", "(", "$", "em", ",", "$", "subEntity", ",", "$", "visited", ",", "$", "depth", "+", "1", ")", ";", "}", "else", "{", "$", "visited", "[", "$", "key", "]", "=", "$", "subEntity", ";", "}", "}", "}" ]
Detaches associated entities from EntityManager and Cache. Normally these entities should either be deleted or updated in database in post-remove phase. @param EntityManager $em @param CascadeRemovableInterface $entity @param array $visited visited entities @param int $depth
[ "Detaches", "associated", "entities", "from", "EntityManager", "and", "Cache", ".", "Normally", "these", "entities", "should", "either", "be", "deleted", "or", "updated", "in", "database", "in", "post", "-", "remove", "phase", "." ]
0bb561415a10e8cc1623b230feffa6ed9afd19e6
https://github.com/oasmobile/php-doctrine-addon/blob/0bb561415a10e8cc1623b230feffa6ed9afd19e6/src/CascadeRemoveTrait.php#L108-L148
6,717
mimmi20/ua-data-mapper
src/BrowserTypeMapper.php
BrowserTypeMapper.mapBrowserType
public function mapBrowserType(?string $browserType): TypeInterface { if (null === $browserType) { return (new TypeLoader())->load('unknown'); } switch (mb_strtolower($browserType)) { case 'browser': case 'mobile browser': $typeKey = 'browser'; break; case 'bot': case 'robot': case 'bot/crawler': case 'library': $typeKey = 'bot'; break; case 'emailclient': case 'email client': $typeKey = 'email-client'; break; case 'pim': $typeKey = 'pim'; break; case 'feedreader': case 'feed reader': $typeKey = 'feed-reader'; break; case 'multimediaplayer': case 'mediaplayer': case 'multimedia player': $typeKey = 'multimedia-player'; break; case 'offlinebrowser': case 'offline browser': $typeKey = 'offline-browser'; break; case 'useragentanonymizer': case 'useragent anonymizer': $typeKey = 'useragent-anonymizer'; break; case 'wapbrowser': case 'wap browser': $typeKey = 'wap-browser'; break; case 'application': case 'mobile app': $typeKey = 'application'; break; case 'tool': $typeKey = 'tool'; break; default: $typeKey = 'unknown'; break; } return (new TypeLoader())->load($typeKey); }
php
public function mapBrowserType(?string $browserType): TypeInterface { if (null === $browserType) { return (new TypeLoader())->load('unknown'); } switch (mb_strtolower($browserType)) { case 'browser': case 'mobile browser': $typeKey = 'browser'; break; case 'bot': case 'robot': case 'bot/crawler': case 'library': $typeKey = 'bot'; break; case 'emailclient': case 'email client': $typeKey = 'email-client'; break; case 'pim': $typeKey = 'pim'; break; case 'feedreader': case 'feed reader': $typeKey = 'feed-reader'; break; case 'multimediaplayer': case 'mediaplayer': case 'multimedia player': $typeKey = 'multimedia-player'; break; case 'offlinebrowser': case 'offline browser': $typeKey = 'offline-browser'; break; case 'useragentanonymizer': case 'useragent anonymizer': $typeKey = 'useragent-anonymizer'; break; case 'wapbrowser': case 'wap browser': $typeKey = 'wap-browser'; break; case 'application': case 'mobile app': $typeKey = 'application'; break; case 'tool': $typeKey = 'tool'; break; default: $typeKey = 'unknown'; break; } return (new TypeLoader())->load($typeKey); }
[ "public", "function", "mapBrowserType", "(", "?", "string", "$", "browserType", ")", ":", "TypeInterface", "{", "if", "(", "null", "===", "$", "browserType", ")", "{", "return", "(", "new", "TypeLoader", "(", ")", ")", "->", "load", "(", "'unknown'", ")", ";", "}", "switch", "(", "mb_strtolower", "(", "$", "browserType", ")", ")", "{", "case", "'browser'", ":", "case", "'mobile browser'", ":", "$", "typeKey", "=", "'browser'", ";", "break", ";", "case", "'bot'", ":", "case", "'robot'", ":", "case", "'bot/crawler'", ":", "case", "'library'", ":", "$", "typeKey", "=", "'bot'", ";", "break", ";", "case", "'emailclient'", ":", "case", "'email client'", ":", "$", "typeKey", "=", "'email-client'", ";", "break", ";", "case", "'pim'", ":", "$", "typeKey", "=", "'pim'", ";", "break", ";", "case", "'feedreader'", ":", "case", "'feed reader'", ":", "$", "typeKey", "=", "'feed-reader'", ";", "break", ";", "case", "'multimediaplayer'", ":", "case", "'mediaplayer'", ":", "case", "'multimedia player'", ":", "$", "typeKey", "=", "'multimedia-player'", ";", "break", ";", "case", "'offlinebrowser'", ":", "case", "'offline browser'", ":", "$", "typeKey", "=", "'offline-browser'", ";", "break", ";", "case", "'useragentanonymizer'", ":", "case", "'useragent anonymizer'", ":", "$", "typeKey", "=", "'useragent-anonymizer'", ";", "break", ";", "case", "'wapbrowser'", ":", "case", "'wap browser'", ":", "$", "typeKey", "=", "'wap-browser'", ";", "break", ";", "case", "'application'", ":", "case", "'mobile app'", ":", "$", "typeKey", "=", "'application'", ";", "break", ";", "case", "'tool'", ":", "$", "typeKey", "=", "'tool'", ";", "break", ";", "default", ":", "$", "typeKey", "=", "'unknown'", ";", "break", ";", "}", "return", "(", "new", "TypeLoader", "(", ")", ")", "->", "load", "(", "$", "typeKey", ")", ";", "}" ]
maps the browser type @param string|null $browserType @return \UaBrowserType\TypeInterface
[ "maps", "the", "browser", "type" ]
fdb249045066a4e793fb481c6304c736605996eb
https://github.com/mimmi20/ua-data-mapper/blob/fdb249045066a4e793fb481c6304c736605996eb/src/BrowserTypeMapper.php#L34-L92
6,718
uthando-cms/uthando-file-manager
src/UthandoFileManager/Hydrator/ImageHydrator.php
ImageHydrator.extract
public function extract($object) { return [ 'name' => $object->getFileName(), 'type' => $object->getType(), 'size' => $object->getSize(), 'tmp_name' => $object->getTempName(), 'error' => $object->getError(), 'size' => [ 0 => $object->getWidth(), 1 => $object->getHeight(), 2 => $object->getMimeType(), ], ]; }
php
public function extract($object) { return [ 'name' => $object->getFileName(), 'type' => $object->getType(), 'size' => $object->getSize(), 'tmp_name' => $object->getTempName(), 'error' => $object->getError(), 'size' => [ 0 => $object->getWidth(), 1 => $object->getHeight(), 2 => $object->getMimeType(), ], ]; }
[ "public", "function", "extract", "(", "$", "object", ")", "{", "return", "[", "'name'", "=>", "$", "object", "->", "getFileName", "(", ")", ",", "'type'", "=>", "$", "object", "->", "getType", "(", ")", ",", "'size'", "=>", "$", "object", "->", "getSize", "(", ")", ",", "'tmp_name'", "=>", "$", "object", "->", "getTempName", "(", ")", ",", "'error'", "=>", "$", "object", "->", "getError", "(", ")", ",", "'size'", "=>", "[", "0", "=>", "$", "object", "->", "getWidth", "(", ")", ",", "1", "=>", "$", "object", "->", "getHeight", "(", ")", ",", "2", "=>", "$", "object", "->", "getMimeType", "(", ")", ",", "]", ",", "]", ";", "}" ]
Extract values from model @param ImageModel $object @return array
[ "Extract", "values", "from", "model" ]
e0b562e9b79f93ffef33a1e4d5a8f400895e7588
https://github.com/uthando-cms/uthando-file-manager/blob/e0b562e9b79f93ffef33a1e4d5a8f400895e7588/src/UthandoFileManager/Hydrator/ImageHydrator.php#L29-L43
6,719
cityware/city-wmi
src/Models/Variants/LogicalDevice.php
LogicalDevice.getStatusInfo
public function getStatusInfo() { $int = $this->variant->statusInfo(); $possible = [ 1 => 'Other', 2 => 'Unknown', 3 => 'Enabled', 4 => 'Disabled', 5 => 'Not Applicable', ]; return $this->getFromPossibleValues($int, $possible); }
php
public function getStatusInfo() { $int = $this->variant->statusInfo(); $possible = [ 1 => 'Other', 2 => 'Unknown', 3 => 'Enabled', 4 => 'Disabled', 5 => 'Not Applicable', ]; return $this->getFromPossibleValues($int, $possible); }
[ "public", "function", "getStatusInfo", "(", ")", "{", "$", "int", "=", "$", "this", "->", "variant", "->", "statusInfo", "(", ")", ";", "$", "possible", "=", "[", "1", "=>", "'Other'", ",", "2", "=>", "'Unknown'", ",", "3", "=>", "'Enabled'", ",", "4", "=>", "'Disabled'", ",", "5", "=>", "'Not Applicable'", ",", "]", ";", "return", "$", "this", "->", "getFromPossibleValues", "(", "$", "int", ",", "$", "possible", ")", ";", "}" ]
Returns a string indicating the devices status. @return mixed|null
[ "Returns", "a", "string", "indicating", "the", "devices", "status", "." ]
c7296e6855b6719f537ff5c2dc19d521ce1415d8
https://github.com/cityware/city-wmi/blob/c7296e6855b6719f537ff5c2dc19d521ce1415d8/src/Models/Variants/LogicalDevice.php#L53-L66
6,720
phossa2/libs
src/Phossa2/Cache/Traits/CacheItemAwareTrait.php
CacheItemAwareTrait.getCacheItem
protected function getCacheItem(/*# string */ $key)/*# : CacheItemExtendedInterface */ { // validate key first $this->validateKey($key); // try local cache if ($this->use_item_cache) { if (!isset($this->item_cache[$key[0]][$key])) { $this->item_cache[$key[0]][$key] = $this->createCacheItem($key); } return $this->item_cache[$key[0]][$key]; } else { return $this->createCacheItem($key); } }
php
protected function getCacheItem(/*# string */ $key)/*# : CacheItemExtendedInterface */ { // validate key first $this->validateKey($key); // try local cache if ($this->use_item_cache) { if (!isset($this->item_cache[$key[0]][$key])) { $this->item_cache[$key[0]][$key] = $this->createCacheItem($key); } return $this->item_cache[$key[0]][$key]; } else { return $this->createCacheItem($key); } }
[ "protected", "function", "getCacheItem", "(", "/*# string */", "$", "key", ")", "/*# : CacheItemExtendedInterface */", "{", "// validate key first", "$", "this", "->", "validateKey", "(", "$", "key", ")", ";", "// try local cache", "if", "(", "$", "this", "->", "use_item_cache", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "item_cache", "[", "$", "key", "[", "0", "]", "]", "[", "$", "key", "]", ")", ")", "{", "$", "this", "->", "item_cache", "[", "$", "key", "[", "0", "]", "]", "[", "$", "key", "]", "=", "$", "this", "->", "createCacheItem", "(", "$", "key", ")", ";", "}", "return", "$", "this", "->", "item_cache", "[", "$", "key", "[", "0", "]", "]", "[", "$", "key", "]", ";", "}", "else", "{", "return", "$", "this", "->", "createCacheItem", "(", "$", "key", ")", ";", "}", "}" ]
Get a cache item @param string $key @return CacheItemExtendedInterface @throws InvalidArgumentException if $key is invalid @access protected
[ "Get", "a", "cache", "item" ]
921e485c8cc29067f279da2cdd06f47a9bddd115
https://github.com/phossa2/libs/blob/921e485c8cc29067f279da2cdd06f47a9bddd115/src/Phossa2/Cache/Traits/CacheItemAwareTrait.php#L84-L98
6,721
phossa2/libs
src/Phossa2/Cache/Traits/CacheItemAwareTrait.php
CacheItemAwareTrait.createCacheItem
protected function createCacheItem(/*# string */ $key)/*# : CacheItemExtendedInterface */ { if (is_callable($this->item_factory)) { $func = $this->item_factory; $item = $func($key, $this); } else { $item = new CacheItem($key, $this); } return $item; }
php
protected function createCacheItem(/*# string */ $key)/*# : CacheItemExtendedInterface */ { if (is_callable($this->item_factory)) { $func = $this->item_factory; $item = $func($key, $this); } else { $item = new CacheItem($key, $this); } return $item; }
[ "protected", "function", "createCacheItem", "(", "/*# string */", "$", "key", ")", "/*# : CacheItemExtendedInterface */", "{", "if", "(", "is_callable", "(", "$", "this", "->", "item_factory", ")", ")", "{", "$", "func", "=", "$", "this", "->", "item_factory", ";", "$", "item", "=", "$", "func", "(", "$", "key", ",", "$", "this", ")", ";", "}", "else", "{", "$", "item", "=", "new", "CacheItem", "(", "$", "key", ",", "$", "this", ")", ";", "}", "return", "$", "item", ";", "}" ]
Create a cache item on the fly @param string $key @return CacheItemExtendedInterface @access protected
[ "Create", "a", "cache", "item", "on", "the", "fly" ]
921e485c8cc29067f279da2cdd06f47a9bddd115
https://github.com/phossa2/libs/blob/921e485c8cc29067f279da2cdd06f47a9bddd115/src/Phossa2/Cache/Traits/CacheItemAwareTrait.php#L107-L117
6,722
phossa2/libs
src/Phossa2/Cache/Traits/CacheItemAwareTrait.php
CacheItemAwareTrait.validateKey
protected function validateKey(/*# string */ &$key) { // validate key if (is_string($key)) { $key = trim($key); return; } // throw exception throw new InvalidArgumentException( Message::get(Message::CACHE_INVALID_KEY, $key), Message::CACHE_INVALID_KEY ); }
php
protected function validateKey(/*# string */ &$key) { // validate key if (is_string($key)) { $key = trim($key); return; } // throw exception throw new InvalidArgumentException( Message::get(Message::CACHE_INVALID_KEY, $key), Message::CACHE_INVALID_KEY ); }
[ "protected", "function", "validateKey", "(", "/*# string */", "&", "$", "key", ")", "{", "// validate key", "if", "(", "is_string", "(", "$", "key", ")", ")", "{", "$", "key", "=", "trim", "(", "$", "key", ")", ";", "return", ";", "}", "// throw exception", "throw", "new", "InvalidArgumentException", "(", "Message", "::", "get", "(", "Message", "::", "CACHE_INVALID_KEY", ",", "$", "key", ")", ",", "Message", "::", "CACHE_INVALID_KEY", ")", ";", "}" ]
Validate key string @param string &$key key to check @return void @throws InvalidArgumentException @access protected
[ "Validate", "key", "string" ]
921e485c8cc29067f279da2cdd06f47a9bddd115
https://github.com/phossa2/libs/blob/921e485c8cc29067f279da2cdd06f47a9bddd115/src/Phossa2/Cache/Traits/CacheItemAwareTrait.php#L127-L140
6,723
ripaclub/zf-apigility-imgman
src/Model/ImgManConnectedResource.php
ImgManConnectedResource.fetch
public function fetch($id) { $rendition = CoreInterface::RENDITION_ORIGINAL; if ($this->getEvent()) { $rendition = $this->getEvent()->getQueryParam('rendition', CoreInterface::RENDITION_ORIGINAL); } $src = $this->imageManager->getSrc($id, $rendition); if ($src && !$this->isAccept('application/json')) { return $this->getRedirectResponse($src); } $hasImage = $this->imageManager->has($id, $rendition); if ($hasImage) { $image = $this->imageManager->get($id, $rendition); if ($this->isAccept($image->getMimeType()) || $this->isAccept('*/*', true)) { return $this->getHttpResponse($image); } else { return $this->getApigilityResponse($image, $id); } } return new ApiProblem(404, 'Image not found'); }
php
public function fetch($id) { $rendition = CoreInterface::RENDITION_ORIGINAL; if ($this->getEvent()) { $rendition = $this->getEvent()->getQueryParam('rendition', CoreInterface::RENDITION_ORIGINAL); } $src = $this->imageManager->getSrc($id, $rendition); if ($src && !$this->isAccept('application/json')) { return $this->getRedirectResponse($src); } $hasImage = $this->imageManager->has($id, $rendition); if ($hasImage) { $image = $this->imageManager->get($id, $rendition); if ($this->isAccept($image->getMimeType()) || $this->isAccept('*/*', true)) { return $this->getHttpResponse($image); } else { return $this->getApigilityResponse($image, $id); } } return new ApiProblem(404, 'Image not found'); }
[ "public", "function", "fetch", "(", "$", "id", ")", "{", "$", "rendition", "=", "CoreInterface", "::", "RENDITION_ORIGINAL", ";", "if", "(", "$", "this", "->", "getEvent", "(", ")", ")", "{", "$", "rendition", "=", "$", "this", "->", "getEvent", "(", ")", "->", "getQueryParam", "(", "'rendition'", ",", "CoreInterface", "::", "RENDITION_ORIGINAL", ")", ";", "}", "$", "src", "=", "$", "this", "->", "imageManager", "->", "getSrc", "(", "$", "id", ",", "$", "rendition", ")", ";", "if", "(", "$", "src", "&&", "!", "$", "this", "->", "isAccept", "(", "'application/json'", ")", ")", "{", "return", "$", "this", "->", "getRedirectResponse", "(", "$", "src", ")", ";", "}", "$", "hasImage", "=", "$", "this", "->", "imageManager", "->", "has", "(", "$", "id", ",", "$", "rendition", ")", ";", "if", "(", "$", "hasImage", ")", "{", "$", "image", "=", "$", "this", "->", "imageManager", "->", "get", "(", "$", "id", ",", "$", "rendition", ")", ";", "if", "(", "$", "this", "->", "isAccept", "(", "$", "image", "->", "getMimeType", "(", ")", ")", "||", "$", "this", "->", "isAccept", "(", "'*/*'", ",", "true", ")", ")", "{", "return", "$", "this", "->", "getHttpResponse", "(", "$", "image", ")", ";", "}", "else", "{", "return", "$", "this", "->", "getApigilityResponse", "(", "$", "image", ",", "$", "id", ")", ";", "}", "}", "return", "new", "ApiProblem", "(", "404", ",", "'Image not found'", ")", ";", "}" ]
Fetch a resource @param mixed $id @return ApiProblem|mixed
[ "Fetch", "a", "resource" ]
827a63273f14695b5126f0d85906c8bcf1b1c0ba
https://github.com/ripaclub/zf-apigility-imgman/blob/827a63273f14695b5126f0d85906c8bcf1b1c0ba/src/Model/ImgManConnectedResource.php#L76-L101
6,724
gregoriohc/argentum-common
src/Common/Document/Invoice.php
Invoice.setTo
public function setTo($value) { if (is_array($value)) { $value = new Person($value); } return $this->setParameter('to', $value); }
php
public function setTo($value) { if (is_array($value)) { $value = new Person($value); } return $this->setParameter('to', $value); }
[ "public", "function", "setTo", "(", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "value", "=", "new", "Person", "(", "$", "value", ")", ";", "}", "return", "$", "this", "->", "setParameter", "(", "'to'", ",", "$", "value", ")", ";", "}" ]
Set document 'to' @param array|Person $value Parameter value @return Invoice provides a fluent interface.
[ "Set", "document", "to" ]
9d914d19aa6ed25d33f00d603eff486484f0f3ba
https://github.com/gregoriohc/argentum-common/blob/9d914d19aa6ed25d33f00d603eff486484f0f3ba/src/Common/Document/Invoice.php#L89-L95
6,725
liip/LiipDrupalRegistryModule
src/Liip/Drupal/Modules/Registry/Drupal/D7Config.php
D7Config.load
private function load() { $this->registry[$this->section] = $this->getDrupalCommonConnector()->variable_get($this->section, array()); }
php
private function load() { $this->registry[$this->section] = $this->getDrupalCommonConnector()->variable_get($this->section, array()); }
[ "private", "function", "load", "(", ")", "{", "$", "this", "->", "registry", "[", "$", "this", "->", "section", "]", "=", "$", "this", "->", "getDrupalCommonConnector", "(", ")", "->", "variable_get", "(", "$", "this", "->", "section", ",", "array", "(", ")", ")", ";", "}" ]
Loads the current content of the registry.
[ "Loads", "the", "current", "content", "of", "the", "registry", "." ]
2d860c1f88ef91d9af91909d8711ffbb6e2a1eab
https://github.com/liip/LiipDrupalRegistryModule/blob/2d860c1f88ef91d9af91909d8711ffbb6e2a1eab/src/Liip/Drupal/Modules/Registry/Drupal/D7Config.php#L45-L48
6,726
liip/LiipDrupalRegistryModule
src/Liip/Drupal/Modules/Registry/Drupal/D7Config.php
D7Config.unregister
public function unregister($identifier) { $this->load(); parent::unregister($identifier); $this->getDrupalCommonConnector()->variable_set($this->section, $this->registry[$this->section]); }
php
public function unregister($identifier) { $this->load(); parent::unregister($identifier); $this->getDrupalCommonConnector()->variable_set($this->section, $this->registry[$this->section]); }
[ "public", "function", "unregister", "(", "$", "identifier", ")", "{", "$", "this", "->", "load", "(", ")", ";", "parent", "::", "unregister", "(", "$", "identifier", ")", ";", "$", "this", "->", "getDrupalCommonConnector", "(", ")", "->", "variable_set", "(", "$", "this", "->", "section", ",", "$", "this", "->", "registry", "[", "$", "this", "->", "section", "]", ")", ";", "}" ]
Removes an item from the regisrty. @param string $identifier
[ "Removes", "an", "item", "from", "the", "regisrty", "." ]
2d860c1f88ef91d9af91909d8711ffbb6e2a1eab
https://github.com/liip/LiipDrupalRegistryModule/blob/2d860c1f88ef91d9af91909d8711ffbb6e2a1eab/src/Liip/Drupal/Modules/Registry/Drupal/D7Config.php#L94-L100
6,727
liip/LiipDrupalRegistryModule
src/Liip/Drupal/Modules/Registry/Drupal/D7Config.php
D7Config.destroy
public function destroy() { $this->registry[$this->section] = array(); $dcc = $this->getDrupalCommonConnector(); $dcc->variable_del($this->section); $content = $dcc->variable_get($this->section, array()); if (!empty($content)) { throw new \InvalidArgumentException( "Section $this->section could not be destroyed from the registry." ); } }
php
public function destroy() { $this->registry[$this->section] = array(); $dcc = $this->getDrupalCommonConnector(); $dcc->variable_del($this->section); $content = $dcc->variable_get($this->section, array()); if (!empty($content)) { throw new \InvalidArgumentException( "Section $this->section could not be destroyed from the registry." ); } }
[ "public", "function", "destroy", "(", ")", "{", "$", "this", "->", "registry", "[", "$", "this", "->", "section", "]", "=", "array", "(", ")", ";", "$", "dcc", "=", "$", "this", "->", "getDrupalCommonConnector", "(", ")", ";", "$", "dcc", "->", "variable_del", "(", "$", "this", "->", "section", ")", ";", "$", "content", "=", "$", "dcc", "->", "variable_get", "(", "$", "this", "->", "section", ",", "array", "(", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "content", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Section $this->section could not be destroyed from the registry.\"", ")", ";", "}", "}" ]
Deletes the current registry from the database. !! Use with caution !! There is no rollback. @throws \Assert\InvalidArgumentException in case the operation failed.
[ "Deletes", "the", "current", "registry", "from", "the", "database", "." ]
2d860c1f88ef91d9af91909d8711ffbb6e2a1eab
https://github.com/liip/LiipDrupalRegistryModule/blob/2d860c1f88ef91d9af91909d8711ffbb6e2a1eab/src/Liip/Drupal/Modules/Registry/Drupal/D7Config.php#L110-L124
6,728
liip/LiipDrupalRegistryModule
src/Liip/Drupal/Modules/Registry/Drupal/D7Config.php
D7Config.init
public function init() { $this->load(); if (!empty($this->registry[$this->section])) { throw new RegistryException( RegistryException::DUPLICATE_INITIATION_ATTEMPT_TEXT . '(section: ' . $this->section . ')', RegistryException::DUPLICATE_INITIATION_ATTEMPT_CODE ); } $this->getDrupalCommonConnector()->variable_set($this->section, $this->registry[$this->section]); }
php
public function init() { $this->load(); if (!empty($this->registry[$this->section])) { throw new RegistryException( RegistryException::DUPLICATE_INITIATION_ATTEMPT_TEXT . '(section: ' . $this->section . ')', RegistryException::DUPLICATE_INITIATION_ATTEMPT_CODE ); } $this->getDrupalCommonConnector()->variable_set($this->section, $this->registry[$this->section]); }
[ "public", "function", "init", "(", ")", "{", "$", "this", "->", "load", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "registry", "[", "$", "this", "->", "section", "]", ")", ")", "{", "throw", "new", "RegistryException", "(", "RegistryException", "::", "DUPLICATE_INITIATION_ATTEMPT_TEXT", ".", "'(section: '", ".", "$", "this", "->", "section", ".", "')'", ",", "RegistryException", "::", "DUPLICATE_INITIATION_ATTEMPT_CODE", ")", ";", "}", "$", "this", "->", "getDrupalCommonConnector", "(", ")", "->", "variable_set", "(", "$", "this", "->", "section", ",", "$", "this", "->", "registry", "[", "$", "this", "->", "section", "]", ")", ";", "}" ]
Initiates a registry. @throws RegistryException
[ "Initiates", "a", "registry", "." ]
2d860c1f88ef91d9af91909d8711ffbb6e2a1eab
https://github.com/liip/LiipDrupalRegistryModule/blob/2d860c1f88ef91d9af91909d8711ffbb6e2a1eab/src/Liip/Drupal/Modules/Registry/Drupal/D7Config.php#L131-L143
6,729
liip/LiipDrupalRegistryModule
src/Liip/Drupal/Modules/Registry/Drupal/D7Config.php
D7Config.isRegistered
public function isRegistered($identifier) { if (!parent::isRegistered($identifier)) { $this->load(); return parent::isRegistered($identifier); } return true; }
php
public function isRegistered($identifier) { if (!parent::isRegistered($identifier)) { $this->load(); return parent::isRegistered($identifier); } return true; }
[ "public", "function", "isRegistered", "(", "$", "identifier", ")", "{", "if", "(", "!", "parent", "::", "isRegistered", "(", "$", "identifier", ")", ")", "{", "$", "this", "->", "load", "(", ")", ";", "return", "parent", "::", "isRegistered", "(", "$", "identifier", ")", ";", "}", "return", "true", ";", "}" ]
Determines if the given identifier refers to a registry item. @param string $identifier @return bool
[ "Determines", "if", "the", "given", "identifier", "refers", "to", "a", "registry", "item", "." ]
2d860c1f88ef91d9af91909d8711ffbb6e2a1eab
https://github.com/liip/LiipDrupalRegistryModule/blob/2d860c1f88ef91d9af91909d8711ffbb6e2a1eab/src/Liip/Drupal/Modules/Registry/Drupal/D7Config.php#L201-L211
6,730
lucifurious/kisma
src/Kisma/Core/Utility/Curl.php
Curl.buildUrl
public static function buildUrl( $url, $payload = array(), $numericPrefix = null, $argSeparator = '&', $encodingType = PHP_QUERY_RFC1738 ) { $_query = \http_build_query( $payload, $numericPrefix, $argSeparator, $encodingType ); return $url . static::urlSeparator( $url, $argSeparator ) . $_query; }
php
public static function buildUrl( $url, $payload = array(), $numericPrefix = null, $argSeparator = '&', $encodingType = PHP_QUERY_RFC1738 ) { $_query = \http_build_query( $payload, $numericPrefix, $argSeparator, $encodingType ); return $url . static::urlSeparator( $url, $argSeparator ) . $_query; }
[ "public", "static", "function", "buildUrl", "(", "$", "url", ",", "$", "payload", "=", "array", "(", ")", ",", "$", "numericPrefix", "=", "null", ",", "$", "argSeparator", "=", "'&'", ",", "$", "encodingType", "=", "PHP_QUERY_RFC1738", ")", "{", "$", "_query", "=", "\\", "http_build_query", "(", "$", "payload", ",", "$", "numericPrefix", ",", "$", "argSeparator", ",", "$", "encodingType", ")", ";", "return", "$", "url", ".", "static", "::", "urlSeparator", "(", "$", "url", ",", "$", "argSeparator", ")", ".", "$", "_query", ";", "}" ]
Builds an URL, properly appending the payload as the query string. @param string $url The target URL @param array $payload The query string data. May be an array or object containing properties. The array form may be a simple one-dimensional structure, or an array of arrays (who in turn may contain other arrays). @param string $numericPrefix If numeric indices are used in the base array and this parameter is provided, it will be prepended to the numeric index for elements in the base array only. This is meant to allow for legal variable names when the data is decoded by PHP or another CGI application later on. @param string $argSeparator Character to use to separate arguments. Defaults to '&' @param int $encodingType If encodingType is PHP_QUERY_RFC1738 (the default), then encoding is as application/x-www-form-urlencoded, spaces will be encoded with plus (+) signs If encodingType is PHP_QUERY_RFC3986, spaces will be encoded with %20 @return string an URL-encoded string
[ "Builds", "an", "URL", "properly", "appending", "the", "payload", "as", "the", "query", "string", "." ]
4cc9954249da4e535b52f154e728935f07e648ae
https://github.com/lucifurious/kisma/blob/4cc9954249da4e535b52f154e728935f07e648ae/src/Kisma/Core/Utility/Curl.php#L704-L709
6,731
frizinak/ZipStreamer
src/ZipStreamer.php
ZipStreamer.send
public function send() { if (!isset($this->files[$this->sent])) { return FALSE; } $file = $this->files[$this->sent]; // Local header $local = $file->genLocal(self::ZIP_VERSION, $this->dosStamp); $this->output($local); // Body $file->hasDeflation() ? $this->outputDeflated($file) : $this->outputRaw($file); // Data descriptor $dataDescriptor = $file->isSmooth() ? $file->genDataDescriptor() : ''; $this->output($dataDescriptor); $file->setLocalOffset($this->localOffset); $this->localOffset += strlen($local) + $file->getDeflatedSize() + strlen($dataDescriptor); // Central header (not output, see flush) $file->genCentral(self::ZIP_VERSION, $this->dosStamp); $this->centralLength += strlen($file->getCentral()); $this->sent++; return TRUE; }
php
public function send() { if (!isset($this->files[$this->sent])) { return FALSE; } $file = $this->files[$this->sent]; // Local header $local = $file->genLocal(self::ZIP_VERSION, $this->dosStamp); $this->output($local); // Body $file->hasDeflation() ? $this->outputDeflated($file) : $this->outputRaw($file); // Data descriptor $dataDescriptor = $file->isSmooth() ? $file->genDataDescriptor() : ''; $this->output($dataDescriptor); $file->setLocalOffset($this->localOffset); $this->localOffset += strlen($local) + $file->getDeflatedSize() + strlen($dataDescriptor); // Central header (not output, see flush) $file->genCentral(self::ZIP_VERSION, $this->dosStamp); $this->centralLength += strlen($file->getCentral()); $this->sent++; return TRUE; }
[ "public", "function", "send", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "files", "[", "$", "this", "->", "sent", "]", ")", ")", "{", "return", "FALSE", ";", "}", "$", "file", "=", "$", "this", "->", "files", "[", "$", "this", "->", "sent", "]", ";", "// Local header", "$", "local", "=", "$", "file", "->", "genLocal", "(", "self", "::", "ZIP_VERSION", ",", "$", "this", "->", "dosStamp", ")", ";", "$", "this", "->", "output", "(", "$", "local", ")", ";", "// Body", "$", "file", "->", "hasDeflation", "(", ")", "?", "$", "this", "->", "outputDeflated", "(", "$", "file", ")", ":", "$", "this", "->", "outputRaw", "(", "$", "file", ")", ";", "// Data descriptor", "$", "dataDescriptor", "=", "$", "file", "->", "isSmooth", "(", ")", "?", "$", "file", "->", "genDataDescriptor", "(", ")", ":", "''", ";", "$", "this", "->", "output", "(", "$", "dataDescriptor", ")", ";", "$", "file", "->", "setLocalOffset", "(", "$", "this", "->", "localOffset", ")", ";", "$", "this", "->", "localOffset", "+=", "strlen", "(", "$", "local", ")", "+", "$", "file", "->", "getDeflatedSize", "(", ")", "+", "strlen", "(", "$", "dataDescriptor", ")", ";", "// Central header (not output, see flush)", "$", "file", "->", "genCentral", "(", "self", "::", "ZIP_VERSION", ",", "$", "this", "->", "dosStamp", ")", ";", "$", "this", "->", "centralLength", "+=", "strlen", "(", "$", "file", "->", "getCentral", "(", ")", ")", ";", "$", "this", "->", "sent", "++", ";", "return", "TRUE", ";", "}" ]
Sends the next file in the queue to the output interface. @returns TRUE if the file was sent, FALSE if the queue was empty.
[ "Sends", "the", "next", "file", "in", "the", "queue", "to", "the", "output", "interface", "." ]
64097363a52a4cb4f9d8cdfc6671ca3e83487dec
https://github.com/frizinak/ZipStreamer/blob/64097363a52a4cb4f9d8cdfc6671ca3e83487dec/src/ZipStreamer.php#L99-L126
6,732
frizinak/ZipStreamer
src/ZipStreamer.php
ZipStreamer.flush
public function flush() { if ($this->locked) return; while ($this->send()) { } foreach ($this->files as $file) { $this->output($file->getCentral()); } $this->output($this->getEOF()); $this->locked = TRUE; $this->outputter->flush(); }
php
public function flush() { if ($this->locked) return; while ($this->send()) { } foreach ($this->files as $file) { $this->output($file->getCentral()); } $this->output($this->getEOF()); $this->locked = TRUE; $this->outputter->flush(); }
[ "public", "function", "flush", "(", ")", "{", "if", "(", "$", "this", "->", "locked", ")", "return", ";", "while", "(", "$", "this", "->", "send", "(", ")", ")", "{", "}", "foreach", "(", "$", "this", "->", "files", "as", "$", "file", ")", "{", "$", "this", "->", "output", "(", "$", "file", "->", "getCentral", "(", ")", ")", ";", "}", "$", "this", "->", "output", "(", "$", "this", "->", "getEOF", "(", ")", ")", ";", "$", "this", "->", "locked", "=", "TRUE", ";", "$", "this", "->", "outputter", "->", "flush", "(", ")", ";", "}" ]
Send any remaining files in the queue (@see send()) and output the central directory records (footer).
[ "Send", "any", "remaining", "files", "in", "the", "queue", "(" ]
64097363a52a4cb4f9d8cdfc6671ca3e83487dec
https://github.com/frizinak/ZipStreamer/blob/64097363a52a4cb4f9d8cdfc6671ca3e83487dec/src/ZipStreamer.php#L132-L142
6,733
iRAP-software/package-core-libs
src/Filesystem.php
Filesystem.mkdir
public static function mkdir($dirPath, $perms=0755, $recursive=true) { $result = true; if (!is_dir($dirPath)) { $result = mkdir($dirPath, $perms, $recursive); } return $result; }
php
public static function mkdir($dirPath, $perms=0755, $recursive=true) { $result = true; if (!is_dir($dirPath)) { $result = mkdir($dirPath, $perms, $recursive); } return $result; }
[ "public", "static", "function", "mkdir", "(", "$", "dirPath", ",", "$", "perms", "=", "0755", ",", "$", "recursive", "=", "true", ")", "{", "$", "result", "=", "true", ";", "if", "(", "!", "is_dir", "(", "$", "dirPath", ")", ")", "{", "$", "result", "=", "mkdir", "(", "$", "dirPath", ",", "$", "perms", ",", "$", "recursive", ")", ";", "}", "return", "$", "result", ";", "}" ]
Wrapper around the mkdir that will only execute it if the directory doesn't already exist. Also, this defaults to being recursive so that it will create all relevant parent directories @param string $dirPath - the path to the directory we wish to create @param int $perms - optionally set the permissions to set for the directory @param bool $recursive - override to false if you want to fail if parent dirs dont exist. @return boolean - true if the directory now exists, false otherwise
[ "Wrapper", "around", "the", "mkdir", "that", "will", "only", "execute", "it", "if", "the", "directory", "doesn", "t", "already", "exist", ".", "Also", "this", "defaults", "to", "being", "recursive", "so", "that", "it", "will", "create", "all", "relevant", "parent", "directories" ]
244871d2fbc2f3fac26ff4b98715224953d9befb
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/Filesystem.php#L159-L169
6,734
iRAP-software/package-core-libs
src/Filesystem.php
Filesystem.lockFile
public static function lockFile($filePath, $is_write_lock, $is_blocking) { global $globals; # This creates the file if it doesnt exist. # we have to assign the file to a global variable, otherwise the file lock will be released # as soon as we exit this function. # This MUST be a+ instead of w or w+ as using w will result in the file being wiped. $globals['file_locks'][$filePath] = fopen($filePath, 'a+'); $lock_params = 0; if ($is_write_lock) { $lock_params = $lock_params | LOCK_EX; } else { # read lock = shared lock $lock_params = $lock_params | LOCK_SH; } if (!$is_blocking) { $lock_params = $lock_params | LOCK_NB; } $result = flock($globals['file_locks'][$filePath], $lock_params); return $result; }
php
public static function lockFile($filePath, $is_write_lock, $is_blocking) { global $globals; # This creates the file if it doesnt exist. # we have to assign the file to a global variable, otherwise the file lock will be released # as soon as we exit this function. # This MUST be a+ instead of w or w+ as using w will result in the file being wiped. $globals['file_locks'][$filePath] = fopen($filePath, 'a+'); $lock_params = 0; if ($is_write_lock) { $lock_params = $lock_params | LOCK_EX; } else { # read lock = shared lock $lock_params = $lock_params | LOCK_SH; } if (!$is_blocking) { $lock_params = $lock_params | LOCK_NB; } $result = flock($globals['file_locks'][$filePath], $lock_params); return $result; }
[ "public", "static", "function", "lockFile", "(", "$", "filePath", ",", "$", "is_write_lock", ",", "$", "is_blocking", ")", "{", "global", "$", "globals", ";", "# This creates the file if it doesnt exist.", "# we have to assign the file to a global variable, otherwise the file lock will be released", "# as soon as we exit this function.", "# This MUST be a+ instead of w or w+ as using w will result in the file being wiped.", "$", "globals", "[", "'file_locks'", "]", "[", "$", "filePath", "]", "=", "fopen", "(", "$", "filePath", ",", "'a+'", ")", ";", "$", "lock_params", "=", "0", ";", "if", "(", "$", "is_write_lock", ")", "{", "$", "lock_params", "=", "$", "lock_params", "|", "LOCK_EX", ";", "}", "else", "{", "# read lock = shared lock", "$", "lock_params", "=", "$", "lock_params", "|", "LOCK_SH", ";", "}", "if", "(", "!", "$", "is_blocking", ")", "{", "$", "lock_params", "=", "$", "lock_params", "|", "LOCK_NB", ";", "}", "$", "result", "=", "flock", "(", "$", "globals", "[", "'file_locks'", "]", "[", "$", "filePath", "]", ",", "$", "lock_params", ")", ";", "return", "$", "result", ";", "}" ]
Lock a file so that only we can use it. This will NOT block untill the file can be locked, but would return false immediately if cannot grab the lock. Note that this only allows other processes to see that you have locked it and does not actually guarantee that it cannot be edited at the same time on Linux. @param String $filePath - the full path to the file that we wish to lock @param boolean $is_write_lock - if false this will get a shared read lock, if true this will get an exclusive write lock. @param boolean $is_blocking - if true will wait to get lock. @return boolean - true if we managed to lock the file, false otherwise.
[ "Lock", "a", "file", "so", "that", "only", "we", "can", "use", "it", ".", "This", "will", "NOT", "block", "untill", "the", "file", "can", "be", "locked", "but", "would", "return", "false", "immediately", "if", "cannot", "grab", "the", "lock", ".", "Note", "that", "this", "only", "allows", "other", "processes", "to", "see", "that", "you", "have", "locked", "it", "and", "does", "not", "actually", "guarantee", "that", "it", "cannot", "be", "edited", "at", "the", "same", "time", "on", "Linux", "." ]
244871d2fbc2f3fac26ff4b98715224953d9befb
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/Filesystem.php#L217-L247
6,735
iRAP-software/package-core-libs
src/Filesystem.php
Filesystem.unlockFile
public static function unlockFile($filePath) { global $globals; if (isset($globals['file_locks'][$filePath])) { # This creates the file if it doesnt exist. fclose($globals['file_locks'][$filePath]); unset($globals['file_locks'][$filePath]); } }
php
public static function unlockFile($filePath) { global $globals; if (isset($globals['file_locks'][$filePath])) { # This creates the file if it doesnt exist. fclose($globals['file_locks'][$filePath]); unset($globals['file_locks'][$filePath]); } }
[ "public", "static", "function", "unlockFile", "(", "$", "filePath", ")", "{", "global", "$", "globals", ";", "if", "(", "isset", "(", "$", "globals", "[", "'file_locks'", "]", "[", "$", "filePath", "]", ")", ")", "{", "# This creates the file if it doesnt exist.", "fclose", "(", "$", "globals", "[", "'file_locks'", "]", "[", "$", "filePath", "]", ")", ";", "unset", "(", "$", "globals", "[", "'file_locks'", "]", "[", "$", "filePath", "]", ")", ";", "}", "}" ]
Unlock a file so that others may use it. @param String $filePath - the full path to the file that we wish to lock @return void.
[ "Unlock", "a", "file", "so", "that", "others", "may", "use", "it", "." ]
244871d2fbc2f3fac26ff4b98715224953d9befb
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/Filesystem.php#L255-L265
6,736
iRAP-software/package-core-libs
src/Filesystem.php
Filesystem.createFileIndex
function createFileIndex($dirToIndex, $indexLocation) { # Don't let the user place the index in the same folder being indexed, # otherwise the directory cannot be re-indexed later, otherwise we will # be indexing the index. if ($dirToIndex == $indexLocation) { $errMsg = 'Cannot place index in same folder being indexed!'; throw new \Exception($errMsg); } # delete the old index if one already exists. if (file_exists($indexLocation)) { self::deleteDir($indexLocation); } if (!mkdir($indexLocation)) { $err = 'Failed to create index directory, check write permissions'; throw new \Exception($err); } $files = scandir($dirToIndex); foreach ($files as $filename) { $first_letter = $filename[0]; $placement_dir = $indexLocation . "/" . strtoupper($first_letter); if (ctype_alpha($first_letter)) { # create the placement directory if it doesn't exist already mkdir($placement_dir); $newPath = $placement_dir . "/" . $filename; if (!is_link($newPath)) { symlink($dirToIndex . '/' . $filename, $newPath); } } } }
php
function createFileIndex($dirToIndex, $indexLocation) { # Don't let the user place the index in the same folder being indexed, # otherwise the directory cannot be re-indexed later, otherwise we will # be indexing the index. if ($dirToIndex == $indexLocation) { $errMsg = 'Cannot place index in same folder being indexed!'; throw new \Exception($errMsg); } # delete the old index if one already exists. if (file_exists($indexLocation)) { self::deleteDir($indexLocation); } if (!mkdir($indexLocation)) { $err = 'Failed to create index directory, check write permissions'; throw new \Exception($err); } $files = scandir($dirToIndex); foreach ($files as $filename) { $first_letter = $filename[0]; $placement_dir = $indexLocation . "/" . strtoupper($first_letter); if (ctype_alpha($first_letter)) { # create the placement directory if it doesn't exist already mkdir($placement_dir); $newPath = $placement_dir . "/" . $filename; if (!is_link($newPath)) { symlink($dirToIndex . '/' . $filename, $newPath); } } } }
[ "function", "createFileIndex", "(", "$", "dirToIndex", ",", "$", "indexLocation", ")", "{", "# Don't let the user place the index in the same folder being indexed, ", "# otherwise the directory cannot be re-indexed later, otherwise we will ", "# be indexing the index.", "if", "(", "$", "dirToIndex", "==", "$", "indexLocation", ")", "{", "$", "errMsg", "=", "'Cannot place index in same folder being indexed!'", ";", "throw", "new", "\\", "Exception", "(", "$", "errMsg", ")", ";", "}", "# delete the old index if one already exists.", "if", "(", "file_exists", "(", "$", "indexLocation", ")", ")", "{", "self", "::", "deleteDir", "(", "$", "indexLocation", ")", ";", "}", "if", "(", "!", "mkdir", "(", "$", "indexLocation", ")", ")", "{", "$", "err", "=", "'Failed to create index directory, check write permissions'", ";", "throw", "new", "\\", "Exception", "(", "$", "err", ")", ";", "}", "$", "files", "=", "scandir", "(", "$", "dirToIndex", ")", ";", "foreach", "(", "$", "files", "as", "$", "filename", ")", "{", "$", "first_letter", "=", "$", "filename", "[", "0", "]", ";", "$", "placement_dir", "=", "$", "indexLocation", ".", "\"/\"", ".", "strtoupper", "(", "$", "first_letter", ")", ";", "if", "(", "ctype_alpha", "(", "$", "first_letter", ")", ")", "{", "# create the placement directory if it doesn't exist already", "mkdir", "(", "$", "placement_dir", ")", ";", "$", "newPath", "=", "$", "placement_dir", ".", "\"/\"", ".", "$", "filename", ";", "if", "(", "!", "is_link", "(", "$", "newPath", ")", ")", "{", "symlink", "(", "$", "dirToIndex", ".", "'/'", ".", "$", "filename", ",", "$", "newPath", ")", ";", "}", "}", "}", "}" ]
Creates an index of the files in the specified directory, by creating symlinks to them, which are separated into folders having the first letter. WARNING - this will only index files that start with alphabetical characters. @param string $dirToIndex - the directory we wish to index. @param string $indexLocation - where to stick the index. @return void
[ "Creates", "an", "index", "of", "the", "files", "in", "the", "specified", "directory", "by", "creating", "symlinks", "to", "them", "which", "are", "separated", "into", "folders", "having", "the", "first", "letter", ".", "WARNING", "-", "this", "will", "only", "index", "files", "that", "start", "with", "alphabetical", "characters", "." ]
244871d2fbc2f3fac26ff4b98715224953d9befb
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/Filesystem.php#L298-L341
6,737
iRAP-software/package-core-libs
src/Filesystem.php
Filesystem.zipDir
public static function zipDir($sourceFolder, $dest, $deleteOnComplete=true) { if (!extension_loaded('zip') ) { throw new \Exception("Your PHP does not have the zip extesion."); } if (!file_exists($sourceFolder)) { throw new \Exception("Cannot zip non-existent folder"); } $rootPath = realpath($sourceFolder); $zip = new \ZipArchive(); $zip->open($dest, \ZipArchive::CREATE); $files = self::getDirContents($sourceFolder, true, true, true); $baseDir = basename($sourceFolder); $zip->addEmptyDir($baseDir); foreach ($files as $name => $filepath) { #$filePath = $file->getRealPath(); $relativePath = str_replace($sourceFolder, $baseDir, $filepath); $zip->addFile($filepath, $relativePath); } $zip->close(); # Delete all files from "delete list" if ($deleteOnComplete) { self::deleteDir($sourceFolder); } }
php
public static function zipDir($sourceFolder, $dest, $deleteOnComplete=true) { if (!extension_loaded('zip') ) { throw new \Exception("Your PHP does not have the zip extesion."); } if (!file_exists($sourceFolder)) { throw new \Exception("Cannot zip non-existent folder"); } $rootPath = realpath($sourceFolder); $zip = new \ZipArchive(); $zip->open($dest, \ZipArchive::CREATE); $files = self::getDirContents($sourceFolder, true, true, true); $baseDir = basename($sourceFolder); $zip->addEmptyDir($baseDir); foreach ($files as $name => $filepath) { #$filePath = $file->getRealPath(); $relativePath = str_replace($sourceFolder, $baseDir, $filepath); $zip->addFile($filepath, $relativePath); } $zip->close(); # Delete all files from "delete list" if ($deleteOnComplete) { self::deleteDir($sourceFolder); } }
[ "public", "static", "function", "zipDir", "(", "$", "sourceFolder", ",", "$", "dest", ",", "$", "deleteOnComplete", "=", "true", ")", "{", "if", "(", "!", "extension_loaded", "(", "'zip'", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Your PHP does not have the zip extesion.\"", ")", ";", "}", "if", "(", "!", "file_exists", "(", "$", "sourceFolder", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Cannot zip non-existent folder\"", ")", ";", "}", "$", "rootPath", "=", "realpath", "(", "$", "sourceFolder", ")", ";", "$", "zip", "=", "new", "\\", "ZipArchive", "(", ")", ";", "$", "zip", "->", "open", "(", "$", "dest", ",", "\\", "ZipArchive", "::", "CREATE", ")", ";", "$", "files", "=", "self", "::", "getDirContents", "(", "$", "sourceFolder", ",", "true", ",", "true", ",", "true", ")", ";", "$", "baseDir", "=", "basename", "(", "$", "sourceFolder", ")", ";", "$", "zip", "->", "addEmptyDir", "(", "$", "baseDir", ")", ";", "foreach", "(", "$", "files", "as", "$", "name", "=>", "$", "filepath", ")", "{", "#$filePath = $file->getRealPath();", "$", "relativePath", "=", "str_replace", "(", "$", "sourceFolder", ",", "$", "baseDir", ",", "$", "filepath", ")", ";", "$", "zip", "->", "addFile", "(", "$", "filepath", ",", "$", "relativePath", ")", ";", "}", "$", "zip", "->", "close", "(", ")", ";", "# Delete all files from \"delete list\"", "if", "(", "$", "deleteOnComplete", ")", "{", "self", "::", "deleteDir", "(", "$", "sourceFolder", ")", ";", "}", "}" ]
Zip a directory and all of its contents into a zip file. @param string $sourceFolder - path to the folder we wish to zip up. @param string $dest - path and name to give the zipfile e.g. (/tmp/my_zip.zip) @param bool $deleteOnComplete - specify false if you want to keep the original uncompressed files after they have been zipped.
[ "Zip", "a", "directory", "and", "all", "of", "its", "contents", "into", "a", "zip", "file", "." ]
244871d2fbc2f3fac26ff4b98715224953d9befb
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/Filesystem.php#L353-L389
6,738
iRAP-software/package-core-libs
src/Filesystem.php
Filesystem.unzip
public static function unzip($sourceZip, $destinationFolder, $deleteOnComplete=true) { if (!extension_loaded('zip') ) { throw new \Exception("Your PHP does not have the zip extesion."); } if (!file_exists($destinationFolder)) { mkdir($destinationFolder); } $zip = new \ZipArchive(); $open = $zip->open($sourceZip); if (!$open) { throw new \Exception('Unable to open zip file: ' . $sourceZip); } $unzip = $zip->extractTo($destinationFolder); if (!$unzip) { throw new \Exception('Unable to unzip file: ' . $sourceZip . ' to destination: ' . $destinationFolder); } $zip->close(); if ($deleteOnComplete) { self::deleteDir($sourceZip); } }
php
public static function unzip($sourceZip, $destinationFolder, $deleteOnComplete=true) { if (!extension_loaded('zip') ) { throw new \Exception("Your PHP does not have the zip extesion."); } if (!file_exists($destinationFolder)) { mkdir($destinationFolder); } $zip = new \ZipArchive(); $open = $zip->open($sourceZip); if (!$open) { throw new \Exception('Unable to open zip file: ' . $sourceZip); } $unzip = $zip->extractTo($destinationFolder); if (!$unzip) { throw new \Exception('Unable to unzip file: ' . $sourceZip . ' to destination: ' . $destinationFolder); } $zip->close(); if ($deleteOnComplete) { self::deleteDir($sourceZip); } }
[ "public", "static", "function", "unzip", "(", "$", "sourceZip", ",", "$", "destinationFolder", ",", "$", "deleteOnComplete", "=", "true", ")", "{", "if", "(", "!", "extension_loaded", "(", "'zip'", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Your PHP does not have the zip extesion.\"", ")", ";", "}", "if", "(", "!", "file_exists", "(", "$", "destinationFolder", ")", ")", "{", "mkdir", "(", "$", "destinationFolder", ")", ";", "}", "$", "zip", "=", "new", "\\", "ZipArchive", "(", ")", ";", "$", "open", "=", "$", "zip", "->", "open", "(", "$", "sourceZip", ")", ";", "if", "(", "!", "$", "open", ")", "{", "throw", "new", "\\", "Exception", "(", "'Unable to open zip file: '", ".", "$", "sourceZip", ")", ";", "}", "$", "unzip", "=", "$", "zip", "->", "extractTo", "(", "$", "destinationFolder", ")", ";", "if", "(", "!", "$", "unzip", ")", "{", "throw", "new", "\\", "Exception", "(", "'Unable to unzip file: '", ".", "$", "sourceZip", ".", "' to destination: '", ".", "$", "destinationFolder", ")", ";", "}", "$", "zip", "->", "close", "(", ")", ";", "if", "(", "$", "deleteOnComplete", ")", "{", "self", "::", "deleteDir", "(", "$", "sourceZip", ")", ";", "}", "}" ]
Unzip a zip file and all of its contents into a directory. @param string $sourceZip - zip file to unzip. @param string $destinationFolder - path to the folder we wish to unzip into. @param bool $deleteOnComplete - specify false if you want to keep the original uncompressed files after they have been zipped.
[ "Unzip", "a", "zip", "file", "and", "all", "of", "its", "contents", "into", "a", "directory", "." ]
244871d2fbc2f3fac26ff4b98715224953d9befb
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/Filesystem.php#L400-L433
6,739
iRAP-software/package-core-libs
src/Filesystem.php
Filesystem.downloadFile
public static function downloadFile(string $url) : string { $downloadedFilepath = tempnam(sys_get_temp_dir(), ""); // use curl if installed. Faster and probably more memory efficient. if (function_exists('curl_version')) { $fp = fopen($downloadedFilepath, 'w+'); $ch = curl_init(str_replace(" ", "%20", $url)); curl_setopt($ch, CURLOPT_TIMEOUT, 50); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_exec($ch); curl_close($ch); fclose($fp); } else { $content = file_get_contents($url); file_put_contents($downloadedFilepath, $content); } return $downloadedFilepath; }
php
public static function downloadFile(string $url) : string { $downloadedFilepath = tempnam(sys_get_temp_dir(), ""); // use curl if installed. Faster and probably more memory efficient. if (function_exists('curl_version')) { $fp = fopen($downloadedFilepath, 'w+'); $ch = curl_init(str_replace(" ", "%20", $url)); curl_setopt($ch, CURLOPT_TIMEOUT, 50); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_exec($ch); curl_close($ch); fclose($fp); } else { $content = file_get_contents($url); file_put_contents($downloadedFilepath, $content); } return $downloadedFilepath; }
[ "public", "static", "function", "downloadFile", "(", "string", "$", "url", ")", ":", "string", "{", "$", "downloadedFilepath", "=", "tempnam", "(", "sys_get_temp_dir", "(", ")", ",", "\"\"", ")", ";", "// use curl if installed. Faster and probably more memory efficient.", "if", "(", "function_exists", "(", "'curl_version'", ")", ")", "{", "$", "fp", "=", "fopen", "(", "$", "downloadedFilepath", ",", "'w+'", ")", ";", "$", "ch", "=", "curl_init", "(", "str_replace", "(", "\" \"", ",", "\"%20\"", ",", "$", "url", ")", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_TIMEOUT", ",", "50", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_FILE", ",", "$", "fp", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_FOLLOWLOCATION", ",", "true", ")", ";", "curl_exec", "(", "$", "ch", ")", ";", "curl_close", "(", "$", "ch", ")", ";", "fclose", "(", "$", "fp", ")", ";", "}", "else", "{", "$", "content", "=", "file_get_contents", "(", "$", "url", ")", ";", "file_put_contents", "(", "$", "downloadedFilepath", ",", "$", "content", ")", ";", "}", "return", "$", "downloadedFilepath", ";", "}" ]
Download a file from the provided URL This will use curl if it is available, if not it will fallback to using file_get_contents. @param string $url @return string - the full filepath to the downloaded file on the server.
[ "Download", "a", "file", "from", "the", "provided", "URL", "This", "will", "use", "curl", "if", "it", "is", "available", "if", "not", "it", "will", "fallback", "to", "using", "file_get_contents", "." ]
244871d2fbc2f3fac26ff4b98715224953d9befb
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/Filesystem.php#L493-L516
6,740
aloframework/handlers
src/class/Error.php
Error.shouldBeReported
public static function shouldBeReported($errcode, $reportingSettings = null) { if (!$reportingSettings || !is_numeric($reportingSettings)) { $reportingSettings = (int)((new ErrorConfig())->get(ErrorConfig::CFG_ERROR_LEVEL)); } $reportingSettings = (int)$reportingSettings; return $errcode && $reportingSettings & ((int)$errcode) ? true : false; }
php
public static function shouldBeReported($errcode, $reportingSettings = null) { if (!$reportingSettings || !is_numeric($reportingSettings)) { $reportingSettings = (int)((new ErrorConfig())->get(ErrorConfig::CFG_ERROR_LEVEL)); } $reportingSettings = (int)$reportingSettings; return $errcode && $reportingSettings & ((int)$errcode) ? true : false; }
[ "public", "static", "function", "shouldBeReported", "(", "$", "errcode", ",", "$", "reportingSettings", "=", "null", ")", "{", "if", "(", "!", "$", "reportingSettings", "||", "!", "is_numeric", "(", "$", "reportingSettings", ")", ")", "{", "$", "reportingSettings", "=", "(", "int", ")", "(", "(", "new", "ErrorConfig", "(", ")", ")", "->", "get", "(", "ErrorConfig", "::", "CFG_ERROR_LEVEL", ")", ")", ";", "}", "$", "reportingSettings", "=", "(", "int", ")", "$", "reportingSettings", ";", "return", "$", "errcode", "&&", "$", "reportingSettings", "&", "(", "(", "int", ")", "$", "errcode", ")", "?", "true", ":", "false", ";", "}" ]
Checks if an error should be reported @author Art <[email protected]> @param int $errcode The error code @param int $reportingSettings You can provide your own reporting settings. If omitted, ALO_HANDLERS_ERROR_LEVEL will be used. @return bool @since 1.3
[ "Checks", "if", "an", "error", "should", "be", "reported" ]
3f17510c5e9221855d39c332710d0e512ec8b42d
https://github.com/aloframework/handlers/blob/3f17510c5e9221855d39c332710d0e512ec8b42d/src/class/Error.php#L106-L114
6,741
MLukman/Securilex
src/Authentication/User/UserProviderSegmentalizer.php
UserProviderSegmentalizer.loadUserByUsername
public function loadUserByUsername($username) { if (!isset($this->cachedUsers[$username])) { $this->cachedUsers[$username] = $this->userProvider->loadUserByUsername($username); } return $this->cachedUsers[$username]; }
php
public function loadUserByUsername($username) { if (!isset($this->cachedUsers[$username])) { $this->cachedUsers[$username] = $this->userProvider->loadUserByUsername($username); } return $this->cachedUsers[$username]; }
[ "public", "function", "loadUserByUsername", "(", "$", "username", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "cachedUsers", "[", "$", "username", "]", ")", ")", "{", "$", "this", "->", "cachedUsers", "[", "$", "username", "]", "=", "$", "this", "->", "userProvider", "->", "loadUserByUsername", "(", "$", "username", ")", ";", "}", "return", "$", "this", "->", "cachedUsers", "[", "$", "username", "]", ";", "}" ]
Get user from cached, otherwise get it from the source User Provider. @param string $username @return type
[ "Get", "user", "from", "cached", "otherwise", "get", "it", "from", "the", "source", "User", "Provider", "." ]
d86ccae6df2ff9029a6d033b20e15f7f48fab79d
https://github.com/MLukman/Securilex/blob/d86ccae6df2ff9029a6d033b20e15f7f48fab79d/src/Authentication/User/UserProviderSegmentalizer.php#L64-L70
6,742
MLukman/Securilex
src/Authentication/User/UserProviderSegmentalizer.php
UserProviderSegmentalizer.refreshUser
public function refreshUser(UserInterface $user) { $username = $user->getUsername(); $this->cachedUsers[$username] = $this->userProvider->refreshUser($user); return $this->cachedUsers[$username]; }
php
public function refreshUser(UserInterface $user) { $username = $user->getUsername(); $this->cachedUsers[$username] = $this->userProvider->refreshUser($user); return $this->cachedUsers[$username]; }
[ "public", "function", "refreshUser", "(", "UserInterface", "$", "user", ")", "{", "$", "username", "=", "$", "user", "->", "getUsername", "(", ")", ";", "$", "this", "->", "cachedUsers", "[", "$", "username", "]", "=", "$", "this", "->", "userProvider", "->", "refreshUser", "(", "$", "user", ")", ";", "return", "$", "this", "->", "cachedUsers", "[", "$", "username", "]", ";", "}" ]
Refresh user using source User Provider. @param UserInterface $user @return UserInterface
[ "Refresh", "user", "using", "source", "User", "Provider", "." ]
d86ccae6df2ff9029a6d033b20e15f7f48fab79d
https://github.com/MLukman/Securilex/blob/d86ccae6df2ff9029a6d033b20e15f7f48fab79d/src/Authentication/User/UserProviderSegmentalizer.php#L77-L82
6,743
calgamo/collection
src/HashMap.php
HashMap.set
public function set($key, $value) : HashMap { $values = $this->_set($key, $value, false); $this->setValues($values); return $this; }
php
public function set($key, $value) : HashMap { $values = $this->_set($key, $value, false); $this->setValues($values); return $this; }
[ "public", "function", "set", "(", "$", "key", ",", "$", "value", ")", ":", "HashMap", "{", "$", "values", "=", "$", "this", "->", "_set", "(", "$", "key", ",", "$", "value", ",", "false", ")", ";", "$", "this", "->", "setValues", "(", "$", "values", ")", ";", "return", "$", "this", ";", "}" ]
update an element value @param mixed $key @param mixed $value @return HashMap
[ "update", "an", "element", "value" ]
65b2efa612bc8250cbe0e1749c7d77176bd0c3c5
https://github.com/calgamo/collection/blob/65b2efa612bc8250cbe0e1749c7d77176bd0c3c5/src/HashMap.php#L69-L74
6,744
agalbourdin/agl-core
src/Mysql/Query/Insert.php
Insert._setId
private function _setId($pId) { $idField = ItemInterface::IDFIELD; if (! isset($this->_fields[$idField]) or ! $this->_fields[$idField]) { $this->_fields[$idField] = $pId; } return $this; }
php
private function _setId($pId) { $idField = ItemInterface::IDFIELD; if (! isset($this->_fields[$idField]) or ! $this->_fields[$idField]) { $this->_fields[$idField] = $pId; } return $this; }
[ "private", "function", "_setId", "(", "$", "pId", ")", "{", "$", "idField", "=", "ItemInterface", "::", "IDFIELD", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "_fields", "[", "$", "idField", "]", ")", "or", "!", "$", "this", "->", "_fields", "[", "$", "idField", "]", ")", "{", "$", "this", "->", "_fields", "[", "$", "idField", "]", "=", "$", "pId", ";", "}", "return", "$", "this", ";", "}" ]
Set the insertion ID. @param string $pId @return Insert
[ "Set", "the", "insertion", "ID", "." ]
1db556f9a49488aa9fab6887fefb7141a79ad97d
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Mysql/Query/Insert.php#L49-L59
6,745
agalbourdin/agl-core
src/Mysql/Query/Insert.php
Insert.commit
public function commit() { try { $prepared = Agl::app()->getDb()->getConnection()->prepare(" INSERT INTO `" . $this->getDbPrefix() . $this->_dbContainer . "` (" . $this->_getFields() . ") VALUES (" . $this->_getPreparedFields() . ") "); if (! $prepared->execute($this->_fields)) { $error = $prepared->errorInfo(); throw new Exception("The insert query failed (table '" . $this->getDbPrefix() . $this->_dbContainer . "') with message '" . $error[2] . "'"); } if (Agl::app()->isDebugMode()) { Agl::app()->getDb()->incrementCounter(); } $this->_setId(Agl::app()->getDb()->getConnection()->lastInsertId()); return $prepared->rowCount(); } catch (Exception $e) { throw new Exception($e); } return true; }
php
public function commit() { try { $prepared = Agl::app()->getDb()->getConnection()->prepare(" INSERT INTO `" . $this->getDbPrefix() . $this->_dbContainer . "` (" . $this->_getFields() . ") VALUES (" . $this->_getPreparedFields() . ") "); if (! $prepared->execute($this->_fields)) { $error = $prepared->errorInfo(); throw new Exception("The insert query failed (table '" . $this->getDbPrefix() . $this->_dbContainer . "') with message '" . $error[2] . "'"); } if (Agl::app()->isDebugMode()) { Agl::app()->getDb()->incrementCounter(); } $this->_setId(Agl::app()->getDb()->getConnection()->lastInsertId()); return $prepared->rowCount(); } catch (Exception $e) { throw new Exception($e); } return true; }
[ "public", "function", "commit", "(", ")", "{", "try", "{", "$", "prepared", "=", "Agl", "::", "app", "(", ")", "->", "getDb", "(", ")", "->", "getConnection", "(", ")", "->", "prepare", "(", "\"\n INSERT INTO\n `\"", ".", "$", "this", "->", "getDbPrefix", "(", ")", ".", "$", "this", "->", "_dbContainer", ".", "\"`\n (\"", ".", "$", "this", "->", "_getFields", "(", ")", ".", "\")\n VALUES\n (\"", ".", "$", "this", "->", "_getPreparedFields", "(", ")", ".", "\")\n \"", ")", ";", "if", "(", "!", "$", "prepared", "->", "execute", "(", "$", "this", "->", "_fields", ")", ")", "{", "$", "error", "=", "$", "prepared", "->", "errorInfo", "(", ")", ";", "throw", "new", "Exception", "(", "\"The insert query failed (table '\"", ".", "$", "this", "->", "getDbPrefix", "(", ")", ".", "$", "this", "->", "_dbContainer", ".", "\"') with message '\"", ".", "$", "error", "[", "2", "]", ".", "\"'\"", ")", ";", "}", "if", "(", "Agl", "::", "app", "(", ")", "->", "isDebugMode", "(", ")", ")", "{", "Agl", "::", "app", "(", ")", "->", "getDb", "(", ")", "->", "incrementCounter", "(", ")", ";", "}", "$", "this", "->", "_setId", "(", "Agl", "::", "app", "(", ")", "->", "getDb", "(", ")", "->", "getConnection", "(", ")", "->", "lastInsertId", "(", ")", ")", ";", "return", "$", "prepared", "->", "rowCount", "(", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "throw", "new", "Exception", "(", "$", "e", ")", ";", "}", "return", "true", ";", "}" ]
Commit the insertion to MySQL and check the query result. @return int Number of affected rows
[ "Commit", "the", "insertion", "to", "MySQL", "and", "check", "the", "query", "result", "." ]
1db556f9a49488aa9fab6887fefb7141a79ad97d
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Mysql/Query/Insert.php#L66-L94
6,746
harvestcloud/CoreBundle
Entity/Category.php
Category.generateSlugAndPath
public function generateSlugAndPath() { // Set slug for this Category $this->slug = \Gedmo\Sluggable\Util\Urlizer::urlize($this->title); $category = $this; $pathSegments = array($category->getSlug()); while ($category->getParent()) { $category = $category->getParent(); $pathSegments[] = $category->getSlug(); } $this->setPath(implode('/', array_reverse($pathSegments))); }
php
public function generateSlugAndPath() { // Set slug for this Category $this->slug = \Gedmo\Sluggable\Util\Urlizer::urlize($this->title); $category = $this; $pathSegments = array($category->getSlug()); while ($category->getParent()) { $category = $category->getParent(); $pathSegments[] = $category->getSlug(); } $this->setPath(implode('/', array_reverse($pathSegments))); }
[ "public", "function", "generateSlugAndPath", "(", ")", "{", "// Set slug for this Category", "$", "this", "->", "slug", "=", "\\", "Gedmo", "\\", "Sluggable", "\\", "Util", "\\", "Urlizer", "::", "urlize", "(", "$", "this", "->", "title", ")", ";", "$", "category", "=", "$", "this", ";", "$", "pathSegments", "=", "array", "(", "$", "category", "->", "getSlug", "(", ")", ")", ";", "while", "(", "$", "category", "->", "getParent", "(", ")", ")", "{", "$", "category", "=", "$", "category", "->", "getParent", "(", ")", ";", "$", "pathSegments", "[", "]", "=", "$", "category", "->", "getSlug", "(", ")", ";", "}", "$", "this", "->", "setPath", "(", "implode", "(", "'/'", ",", "array_reverse", "(", "$", "pathSegments", ")", ")", ")", ";", "}" ]
Generate slug and path @author Tom Haskins-Vaughan <[email protected]> @since 2012-04-18 @ORM\PrePersist @ORM\PreUpdate
[ "Generate", "slug", "and", "path" ]
f33e079c4a6191cf674aa2678f2fb2e6f0dd89cc
https://github.com/harvestcloud/CoreBundle/blob/f33e079c4a6191cf674aa2678f2fb2e6f0dd89cc/Entity/Category.php#L395-L411
6,747
joegreen88/zf1-component-locale
src/Zend/Locale/Format.php
Zend_Locale_Format.isNumber
public static function isNumber($input, array $options = array()) { if (!self::_getUniCodeSupport()) { trigger_error("Sorry, your PCRE extension does not support UTF8 which is needed for the I18N core", E_USER_NOTICE); } $options = self::_checkOptions($options) + self::$_options; // Get correct signs for this locale $symbols = Zend_Locale_Data::getList($options['locale'],'symbols'); $regexs = Zend_Locale_Format::_getRegexForType('decimalnumber', $options); $regexs = array_merge($regexs, Zend_Locale_Format::_getRegexForType('scientificnumber', $options)); if (!empty($input) && ($input[0] == $symbols['decimal'])) { $input = 0 . $input; } foreach ($regexs as $regex) { preg_match($regex, $input, $found); if (isset($found[0])) { return true; } } return false; }
php
public static function isNumber($input, array $options = array()) { if (!self::_getUniCodeSupport()) { trigger_error("Sorry, your PCRE extension does not support UTF8 which is needed for the I18N core", E_USER_NOTICE); } $options = self::_checkOptions($options) + self::$_options; // Get correct signs for this locale $symbols = Zend_Locale_Data::getList($options['locale'],'symbols'); $regexs = Zend_Locale_Format::_getRegexForType('decimalnumber', $options); $regexs = array_merge($regexs, Zend_Locale_Format::_getRegexForType('scientificnumber', $options)); if (!empty($input) && ($input[0] == $symbols['decimal'])) { $input = 0 . $input; } foreach ($regexs as $regex) { preg_match($regex, $input, $found); if (isset($found[0])) { return true; } } return false; }
[ "public", "static", "function", "isNumber", "(", "$", "input", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "if", "(", "!", "self", "::", "_getUniCodeSupport", "(", ")", ")", "{", "trigger_error", "(", "\"Sorry, your PCRE extension does not support UTF8 which is needed for the I18N core\"", ",", "E_USER_NOTICE", ")", ";", "}", "$", "options", "=", "self", "::", "_checkOptions", "(", "$", "options", ")", "+", "self", "::", "$", "_options", ";", "// Get correct signs for this locale", "$", "symbols", "=", "Zend_Locale_Data", "::", "getList", "(", "$", "options", "[", "'locale'", "]", ",", "'symbols'", ")", ";", "$", "regexs", "=", "Zend_Locale_Format", "::", "_getRegexForType", "(", "'decimalnumber'", ",", "$", "options", ")", ";", "$", "regexs", "=", "array_merge", "(", "$", "regexs", ",", "Zend_Locale_Format", "::", "_getRegexForType", "(", "'scientificnumber'", ",", "$", "options", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "input", ")", "&&", "(", "$", "input", "[", "0", "]", "==", "$", "symbols", "[", "'decimal'", "]", ")", ")", "{", "$", "input", "=", "0", ".", "$", "input", ";", "}", "foreach", "(", "$", "regexs", "as", "$", "regex", ")", "{", "preg_match", "(", "$", "regex", ",", "$", "input", ",", "$", "found", ")", ";", "if", "(", "isset", "(", "$", "found", "[", "0", "]", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks if the input contains a normalized or localized number @param string $input Localized number string @param array $options Options: locale. See {@link setOptions()} for details. @return boolean Returns true if a number was found
[ "Checks", "if", "the", "input", "contains", "a", "normalized", "or", "localized", "number" ]
2e8dab3c9a1878f91ff2b934716638f4eb2e7f94
https://github.com/joegreen88/zf1-component-locale/blob/2e8dab3c9a1878f91ff2b934716638f4eb2e7f94/src/Zend/Locale/Format.php#L502-L526
6,748
joegreen88/zf1-component-locale
src/Zend/Locale/Format.php
Zend_Locale_Format.toInteger
public static function toInteger($value, array $options = array()) { $options['precision'] = 0; $options['number_format'] = Zend_Locale_Format::STANDARD; return self::toNumber($value, $options); }
php
public static function toInteger($value, array $options = array()) { $options['precision'] = 0; $options['number_format'] = Zend_Locale_Format::STANDARD; return self::toNumber($value, $options); }
[ "public", "static", "function", "toInteger", "(", "$", "value", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "options", "[", "'precision'", "]", "=", "0", ";", "$", "options", "[", "'number_format'", "]", "=", "Zend_Locale_Format", "::", "STANDARD", ";", "return", "self", "::", "toNumber", "(", "$", "value", ",", "$", "options", ")", ";", "}" ]
Returns a localized number @param string $value Number to normalize @param array $options Options: locale. See {@link setOptions()} for details. @return string Locale formatted number
[ "Returns", "a", "localized", "number" ]
2e8dab3c9a1878f91ff2b934716638f4eb2e7f94
https://github.com/joegreen88/zf1-component-locale/blob/2e8dab3c9a1878f91ff2b934716638f4eb2e7f94/src/Zend/Locale/Format.php#L697-L702
6,749
joegreen88/zf1-component-locale
src/Zend/Locale/Format.php
Zend_Locale_Format.isInteger
public static function isInteger($value, array $options = array()) { if (!self::isNumber($value, $options)) { return false; } if (self::getInteger($value, $options) == self::getFloat($value, $options)) { return true; } return false; }
php
public static function isInteger($value, array $options = array()) { if (!self::isNumber($value, $options)) { return false; } if (self::getInteger($value, $options) == self::getFloat($value, $options)) { return true; } return false; }
[ "public", "static", "function", "isInteger", "(", "$", "value", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "if", "(", "!", "self", "::", "isNumber", "(", "$", "value", ",", "$", "options", ")", ")", "{", "return", "false", ";", "}", "if", "(", "self", "::", "getInteger", "(", "$", "value", ",", "$", "options", ")", "==", "self", "::", "getFloat", "(", "$", "value", ",", "$", "options", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Returns if a integer was found @param string $input Localized number string @param array $options Options: locale. See {@link setOptions()} for details. @return boolean Returns true if a integer was found
[ "Returns", "if", "a", "integer", "was", "found" ]
2e8dab3c9a1878f91ff2b934716638f4eb2e7f94
https://github.com/joegreen88/zf1-component-locale/blob/2e8dab3c9a1878f91ff2b934716638f4eb2e7f94/src/Zend/Locale/Format.php#L711-L722
6,750
eFrane/Transfugio
src/Query/ValueExpression.php
ValueExpression.parseExpression
protected function parseExpression($valueExpression) { // expressions are not longer than 2 characters $checkForExpression = substr($valueExpression, 0, 2); if (str_contains($checkForExpression, static::$validExpressions)) { foreach (static::$validExpressions as $expression) { if (substr($valueExpression, 0, strlen($expression)) === $expression) { $this->expression = $expression; $this->value = $this->transformValue(substr($valueExpression, strlen($expression))); return; } } } // default to "equal to" $this->expression = '='; $this->value = $this->transformValue($valueExpression); }
php
protected function parseExpression($valueExpression) { // expressions are not longer than 2 characters $checkForExpression = substr($valueExpression, 0, 2); if (str_contains($checkForExpression, static::$validExpressions)) { foreach (static::$validExpressions as $expression) { if (substr($valueExpression, 0, strlen($expression)) === $expression) { $this->expression = $expression; $this->value = $this->transformValue(substr($valueExpression, strlen($expression))); return; } } } // default to "equal to" $this->expression = '='; $this->value = $this->transformValue($valueExpression); }
[ "protected", "function", "parseExpression", "(", "$", "valueExpression", ")", "{", "// expressions are not longer than 2 characters", "$", "checkForExpression", "=", "substr", "(", "$", "valueExpression", ",", "0", ",", "2", ")", ";", "if", "(", "str_contains", "(", "$", "checkForExpression", ",", "static", "::", "$", "validExpressions", ")", ")", "{", "foreach", "(", "static", "::", "$", "validExpressions", "as", "$", "expression", ")", "{", "if", "(", "substr", "(", "$", "valueExpression", ",", "0", ",", "strlen", "(", "$", "expression", ")", ")", "===", "$", "expression", ")", "{", "$", "this", "->", "expression", "=", "$", "expression", ";", "$", "this", "->", "value", "=", "$", "this", "->", "transformValue", "(", "substr", "(", "$", "valueExpression", ",", "strlen", "(", "$", "expression", ")", ")", ")", ";", "return", ";", "}", "}", "}", "// default to \"equal to\"", "$", "this", "->", "expression", "=", "'='", ";", "$", "this", "->", "value", "=", "$", "this", "->", "transformValue", "(", "$", "valueExpression", ")", ";", "}" ]
Split expressionValue into expression and type-checked value @param string $valueExpression
[ "Split", "expressionValue", "into", "expression", "and", "type", "-", "checked", "value" ]
c213b3c0e3649150d0c6675167e781930fda9125
https://github.com/eFrane/Transfugio/blob/c213b3c0e3649150d0c6675167e781930fda9125/src/Query/ValueExpression.php#L50-L69
6,751
native5/native5-sdk-common-php
src/Native5/Core/Configuration/ArrayConfigFactory.php
ArrayConfigFactory.override
public function override($config) { self::_checkArray($config); $this->_config = array_replace_recursive($this->_config, $config); }
php
public function override($config) { self::_checkArray($config); $this->_config = array_replace_recursive($this->_config, $config); }
[ "public", "function", "override", "(", "$", "config", ")", "{", "self", "::", "_checkArray", "(", "$", "config", ")", ";", "$", "this", "->", "_config", "=", "array_replace_recursive", "(", "$", "this", "->", "_config", ",", "$", "config", ")", ";", "}" ]
override Merge with configuration array, this array overrides the current values override Merges this configuration array with the base configuration, override values @param mixed $config Overriding configuration array @access public @return void @note needs to be called after setMasterConfig()
[ "override", "Merge", "with", "configuration", "array", "this", "array", "overrides", "the", "current", "values", "override", "Merges", "this", "configuration", "array", "with", "the", "base", "configuration", "override", "values" ]
c8bd5b219bd05ea4d317d21ae9c0c8dddcede7fe
https://github.com/native5/native5-sdk-common-php/blob/c8bd5b219bd05ea4d317d21ae9c0c8dddcede7fe/src/Native5/Core/Configuration/ArrayConfigFactory.php#L66-L69
6,752
ddehart/dilmun
src/LoggedClassTrait.php
LoggedClassTrait.updateLog
protected function updateLog($level, $message, array $context = array()) { if ($this->logger instanceof Logger) { $this->logger->$level($message, $context); $message_logged = true; } else { $message_logged = false; } return $message_logged; }
php
protected function updateLog($level, $message, array $context = array()) { if ($this->logger instanceof Logger) { $this->logger->$level($message, $context); $message_logged = true; } else { $message_logged = false; } return $message_logged; }
[ "protected", "function", "updateLog", "(", "$", "level", ",", "$", "message", ",", "array", "$", "context", "=", "array", "(", ")", ")", "{", "if", "(", "$", "this", "->", "logger", "instanceof", "Logger", ")", "{", "$", "this", "->", "logger", "->", "$", "level", "(", "$", "message", ",", "$", "context", ")", ";", "$", "message_logged", "=", "true", ";", "}", "else", "{", "$", "message_logged", "=", "false", ";", "}", "return", "$", "message_logged", ";", "}" ]
If it exists, logs the message at the supplied level using the set Logger @param string $level The log level for the message @param string $message The message to be logged @return bool Returns true if the message was logged returns false if the message was not logged
[ "If", "it", "exists", "logs", "the", "message", "at", "the", "supplied", "level", "using", "the", "set", "Logger" ]
e2a294dbcd4c6754063c247be64930c5ee91378f
https://github.com/ddehart/dilmun/blob/e2a294dbcd4c6754063c247be64930c5ee91378f/src/LoggedClassTrait.php#L45-L56
6,753
infinity-se/infinity-base
src/InfinityBase/Entity/EntityAwareTrait.php
EntityAwareTrait.getModuleNamespace
protected function getModuleNamespace() { if (null === $this->moduleNamespace) { $class = get_class($this); $this->moduleNamespace = substr($class, 0, strpos($class, '\\')); } return $this->moduleNamespace; }
php
protected function getModuleNamespace() { if (null === $this->moduleNamespace) { $class = get_class($this); $this->moduleNamespace = substr($class, 0, strpos($class, '\\')); } return $this->moduleNamespace; }
[ "protected", "function", "getModuleNamespace", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "moduleNamespace", ")", "{", "$", "class", "=", "get_class", "(", "$", "this", ")", ";", "$", "this", "->", "moduleNamespace", "=", "substr", "(", "$", "class", ",", "0", ",", "strpos", "(", "$", "class", ",", "'\\\\'", ")", ")", ";", "}", "return", "$", "this", "->", "moduleNamespace", ";", "}" ]
Retrieve the module namespace @return string
[ "Retrieve", "the", "module", "namespace" ]
4f869ae4b549e779560a83528d2ed2664f6deb5b
https://github.com/infinity-se/infinity-base/blob/4f869ae4b549e779560a83528d2ed2664f6deb5b/src/InfinityBase/Entity/EntityAwareTrait.php#L23-L30
6,754
infinity-se/infinity-base
src/InfinityBase/Entity/EntityAwareTrait.php
EntityAwareTrait.getEntityName
protected function getEntityName() { if (null === $this->entityName) { $name = get_class($this); $type = ucfirst($this->abstractType); $name = str_replace($this->getModuleNamespace() . '\\' . $type . '\\', '', $name); $name = str_replace($type, '', $name); $this->entityName = $name; } return $this->entityName; }
php
protected function getEntityName() { if (null === $this->entityName) { $name = get_class($this); $type = ucfirst($this->abstractType); $name = str_replace($this->getModuleNamespace() . '\\' . $type . '\\', '', $name); $name = str_replace($type, '', $name); $this->entityName = $name; } return $this->entityName; }
[ "protected", "function", "getEntityName", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "entityName", ")", "{", "$", "name", "=", "get_class", "(", "$", "this", ")", ";", "$", "type", "=", "ucfirst", "(", "$", "this", "->", "abstractType", ")", ";", "$", "name", "=", "str_replace", "(", "$", "this", "->", "getModuleNamespace", "(", ")", ".", "'\\\\'", ".", "$", "type", ".", "'\\\\'", ",", "''", ",", "$", "name", ")", ";", "$", "name", "=", "str_replace", "(", "$", "type", ",", "''", ",", "$", "name", ")", ";", "$", "this", "->", "entityName", "=", "$", "name", ";", "}", "return", "$", "this", "->", "entityName", ";", "}" ]
Retrieve the entity name @return string
[ "Retrieve", "the", "entity", "name" ]
4f869ae4b549e779560a83528d2ed2664f6deb5b
https://github.com/infinity-se/infinity-base/blob/4f869ae4b549e779560a83528d2ed2664f6deb5b/src/InfinityBase/Entity/EntityAwareTrait.php#L37-L47
6,755
bishopb/vanilla
library/core/class.pluginmanager.php
Gdn_PluginManager.Start
public function Start($Force = FALSE) { if (function_exists('apc_fetch') && C('Garden.Apc', FALSE)) $this->Apc = TRUE; // Build list of all available plugins $this->AvailablePlugins($Force); // Build list of all enabled plugins $this->EnabledPlugins($Force); // Include enabled plugin source files $this->IncludePlugins(); // Register hooked methods $this->RegisterPlugins(); $this->Started = TRUE; $this->FireEvent('AfterStart'); }
php
public function Start($Force = FALSE) { if (function_exists('apc_fetch') && C('Garden.Apc', FALSE)) $this->Apc = TRUE; // Build list of all available plugins $this->AvailablePlugins($Force); // Build list of all enabled plugins $this->EnabledPlugins($Force); // Include enabled plugin source files $this->IncludePlugins(); // Register hooked methods $this->RegisterPlugins(); $this->Started = TRUE; $this->FireEvent('AfterStart'); }
[ "public", "function", "Start", "(", "$", "Force", "=", "FALSE", ")", "{", "if", "(", "function_exists", "(", "'apc_fetch'", ")", "&&", "C", "(", "'Garden.Apc'", ",", "FALSE", ")", ")", "$", "this", "->", "Apc", "=", "TRUE", ";", "// Build list of all available plugins", "$", "this", "->", "AvailablePlugins", "(", "$", "Force", ")", ";", "// Build list of all enabled plugins", "$", "this", "->", "EnabledPlugins", "(", "$", "Force", ")", ";", "// Include enabled plugin source files", "$", "this", "->", "IncludePlugins", "(", ")", ";", "// Register hooked methods", "$", "this", "->", "RegisterPlugins", "(", ")", ";", "$", "this", "->", "Started", "=", "TRUE", ";", "$", "this", "->", "FireEvent", "(", "'AfterStart'", ")", ";", "}" ]
Sets up the plugin framework This method indexes all available plugins and extracts their information. It then determines which plugins have been enabled, and includes them. Finally, it parses all plugin files and extracts their events and plugged methods.
[ "Sets", "up", "the", "plugin", "framework" ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.pluginmanager.php#L99-L118
6,756
bishopb/vanilla
library/core/class.pluginmanager.php
Gdn_PluginManager.IncludePlugins
public function IncludePlugins($EnabledPlugins = NULL) { // Include all of the plugins. if (is_null($EnabledPlugins)) $EnabledPlugins = $this->EnabledPlugins(); $PluginManager = &$this; // Get a list of files to include. foreach ($EnabledPlugins as $PluginName => $Trash) { $PluginInfo = $this->GetPluginInfo($PluginName); $ClassName = GetValue('ClassName', $PluginInfo, FALSE); $ClassFile = GetValue('RealFile', $PluginInfo, FALSE); if ($ClassName !== FALSE && !class_exists($ClassName, FALSE)) if (file_exists($ClassFile)) include_once($ClassFile); } }
php
public function IncludePlugins($EnabledPlugins = NULL) { // Include all of the plugins. if (is_null($EnabledPlugins)) $EnabledPlugins = $this->EnabledPlugins(); $PluginManager = &$this; // Get a list of files to include. foreach ($EnabledPlugins as $PluginName => $Trash) { $PluginInfo = $this->GetPluginInfo($PluginName); $ClassName = GetValue('ClassName', $PluginInfo, FALSE); $ClassFile = GetValue('RealFile', $PluginInfo, FALSE); if ($ClassName !== FALSE && !class_exists($ClassName, FALSE)) if (file_exists($ClassFile)) include_once($ClassFile); } }
[ "public", "function", "IncludePlugins", "(", "$", "EnabledPlugins", "=", "NULL", ")", "{", "// Include all of the plugins.", "if", "(", "is_null", "(", "$", "EnabledPlugins", ")", ")", "$", "EnabledPlugins", "=", "$", "this", "->", "EnabledPlugins", "(", ")", ";", "$", "PluginManager", "=", "&", "$", "this", ";", "// Get a list of files to include.", "foreach", "(", "$", "EnabledPlugins", "as", "$", "PluginName", "=>", "$", "Trash", ")", "{", "$", "PluginInfo", "=", "$", "this", "->", "GetPluginInfo", "(", "$", "PluginName", ")", ";", "$", "ClassName", "=", "GetValue", "(", "'ClassName'", ",", "$", "PluginInfo", ",", "FALSE", ")", ";", "$", "ClassFile", "=", "GetValue", "(", "'RealFile'", ",", "$", "PluginInfo", ",", "FALSE", ")", ";", "if", "(", "$", "ClassName", "!==", "FALSE", "&&", "!", "class_exists", "(", "$", "ClassName", ",", "FALSE", ")", ")", "if", "(", "file_exists", "(", "$", "ClassFile", ")", ")", "include_once", "(", "$", "ClassFile", ")", ";", "}", "}" ]
Includes all of the plugin files for enabled plugins. Files are included in from the roots of each plugin directory if they have the following names. - default.php - *plugin.php @param array $EnabledPlugins An array of plugins that should be included. If this argument is null then all enabled plugins will be included. @return array The plugin info array for all included plugins.
[ "Includes", "all", "of", "the", "plugin", "files", "for", "enabled", "plugins", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.pluginmanager.php#L270-L289
6,757
bishopb/vanilla
library/core/class.pluginmanager.php
Gdn_PluginManager.RegisterPlugins
public function RegisterPlugins() { // Loop through all declared classes looking for ones that implement Gdn_iPlugin. foreach (get_declared_classes() as $ClassName) { if ($ClassName == 'Gdn_Plugin') continue; // Only register the plugin if it implements the Gdn_IPlugin interface if (in_array('Gdn_IPlugin', class_implements($ClassName))) { // If this plugin was already indexed, skip it. if (array_key_exists($ClassName, $this->RegisteredPlugins)) continue; // Register this plugin's methods $this->RegisterPlugin($ClassName); } } }
php
public function RegisterPlugins() { // Loop through all declared classes looking for ones that implement Gdn_iPlugin. foreach (get_declared_classes() as $ClassName) { if ($ClassName == 'Gdn_Plugin') continue; // Only register the plugin if it implements the Gdn_IPlugin interface if (in_array('Gdn_IPlugin', class_implements($ClassName))) { // If this plugin was already indexed, skip it. if (array_key_exists($ClassName, $this->RegisteredPlugins)) continue; // Register this plugin's methods $this->RegisterPlugin($ClassName); } } }
[ "public", "function", "RegisterPlugins", "(", ")", "{", "// Loop through all declared classes looking for ones that implement Gdn_iPlugin.", "foreach", "(", "get_declared_classes", "(", ")", "as", "$", "ClassName", ")", "{", "if", "(", "$", "ClassName", "==", "'Gdn_Plugin'", ")", "continue", ";", "// Only register the plugin if it implements the Gdn_IPlugin interface", "if", "(", "in_array", "(", "'Gdn_IPlugin'", ",", "class_implements", "(", "$", "ClassName", ")", ")", ")", "{", "// If this plugin was already indexed, skip it.", "if", "(", "array_key_exists", "(", "$", "ClassName", ",", "$", "this", "->", "RegisteredPlugins", ")", ")", "continue", ";", "// Register this plugin's methods", "$", "this", "->", "RegisterPlugin", "(", "$", "ClassName", ")", ";", "}", "}", "}" ]
Register all enabled plugins' event handlers and overrides Examines all declared classes, identifying which ones implement Gdn_IPlugin and registers all of their event handlers and method overrides. It recognizes them because Handlers end with _Handler, _Before, and _After and overrides end with "_Override". They are prefixed with the name of the class and method (or event) to be handled or overridden. For example: class MyPlugin implements Gdn_IPlugin { public function MyController_SignIn_After($Sender) { // Do something neato } public function Url_AppRoot_Override($WithDomain) { return "MyCustomAppRoot!"; } }
[ "Register", "all", "enabled", "plugins", "event", "handlers", "and", "overrides" ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.pluginmanager.php#L383-L402
6,758
bishopb/vanilla
library/core/class.pluginmanager.php
Gdn_PluginManager.GetPluginInstance
public function GetPluginInstance($AccessName, $AccessType = self::ACCESS_CLASSNAME, $Sender = NULL) { $ClassName = NULL; switch ($AccessType) { case self::ACCESS_PLUGINNAME: $ClassName = GetValue('ClassName', $this->GetPluginInfo($AccessName), FALSE); break; case self::ACCESS_CLASSNAME: default: $ClassName = $AccessName; break; } if (!class_exists($ClassName)) throw new Exception("Tried to load plugin '{$ClassName}' from access name '{$AccessName}:{$AccessType}', but it doesn't exist."); if (!array_key_exists($ClassName, $this->Instances)) { $this->Instances[$ClassName] = (is_null($Sender)) ? new $ClassName() : new $ClassName($Sender); $this->Instances[$ClassName]->PluginInfo = $this->GetPluginInfo($AccessName, $AccessType); } return $this->Instances[$ClassName]; }
php
public function GetPluginInstance($AccessName, $AccessType = self::ACCESS_CLASSNAME, $Sender = NULL) { $ClassName = NULL; switch ($AccessType) { case self::ACCESS_PLUGINNAME: $ClassName = GetValue('ClassName', $this->GetPluginInfo($AccessName), FALSE); break; case self::ACCESS_CLASSNAME: default: $ClassName = $AccessName; break; } if (!class_exists($ClassName)) throw new Exception("Tried to load plugin '{$ClassName}' from access name '{$AccessName}:{$AccessType}', but it doesn't exist."); if (!array_key_exists($ClassName, $this->Instances)) { $this->Instances[$ClassName] = (is_null($Sender)) ? new $ClassName() : new $ClassName($Sender); $this->Instances[$ClassName]->PluginInfo = $this->GetPluginInfo($AccessName, $AccessType); } return $this->Instances[$ClassName]; }
[ "public", "function", "GetPluginInstance", "(", "$", "AccessName", ",", "$", "AccessType", "=", "self", "::", "ACCESS_CLASSNAME", ",", "$", "Sender", "=", "NULL", ")", "{", "$", "ClassName", "=", "NULL", ";", "switch", "(", "$", "AccessType", ")", "{", "case", "self", "::", "ACCESS_PLUGINNAME", ":", "$", "ClassName", "=", "GetValue", "(", "'ClassName'", ",", "$", "this", "->", "GetPluginInfo", "(", "$", "AccessName", ")", ",", "FALSE", ")", ";", "break", ";", "case", "self", "::", "ACCESS_CLASSNAME", ":", "default", ":", "$", "ClassName", "=", "$", "AccessName", ";", "break", ";", "}", "if", "(", "!", "class_exists", "(", "$", "ClassName", ")", ")", "throw", "new", "Exception", "(", "\"Tried to load plugin '{$ClassName}' from access name '{$AccessName}:{$AccessType}', but it doesn't exist.\"", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "ClassName", ",", "$", "this", "->", "Instances", ")", ")", "{", "$", "this", "->", "Instances", "[", "$", "ClassName", "]", "=", "(", "is_null", "(", "$", "Sender", ")", ")", "?", "new", "$", "ClassName", "(", ")", ":", "new", "$", "ClassName", "(", "$", "Sender", ")", ";", "$", "this", "->", "Instances", "[", "$", "ClassName", "]", "->", "PluginInfo", "=", "$", "this", "->", "GetPluginInfo", "(", "$", "AccessName", ",", "$", "AccessType", ")", ";", "}", "return", "$", "this", "->", "Instances", "[", "$", "ClassName", "]", ";", "}" ]
Gets an instance of a given plugin. @param string $AccessName The key of the plugin. @param string $AccessType The type of key for the plugin which must be one of the following: - Gdn_PluginManager::ACCESS_PLUGINNAME - Gdn_PluginManager::ACCESS_CLASSNAME @param mixed $Sender An object to pass to a new plugin instantiation. @return Gdn_IPlugin The plugin instance.
[ "Gets", "an", "instance", "of", "a", "given", "plugin", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.pluginmanager.php#L541-L563
6,759
bishopb/vanilla
library/core/class.pluginmanager.php
Gdn_PluginManager.IsEnabled
public function IsEnabled($Name) { $Enabled = $this->EnabledPlugins; return isset($Enabled[$Name]) && $Enabled[$Name]; }
php
public function IsEnabled($Name) { $Enabled = $this->EnabledPlugins; return isset($Enabled[$Name]) && $Enabled[$Name]; }
[ "public", "function", "IsEnabled", "(", "$", "Name", ")", "{", "$", "Enabled", "=", "$", "this", "->", "EnabledPlugins", ";", "return", "isset", "(", "$", "Enabled", "[", "$", "Name", "]", ")", "&&", "$", "Enabled", "[", "$", "Name", "]", ";", "}" ]
Returns whether or not a plugin is enabled. @param string $Name The name of the plugin. @return bool Whether or not the plugin is enabled. @since 2.2
[ "Returns", "whether", "or", "not", "a", "plugin", "is", "enabled", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.pluginmanager.php#L572-L575
6,760
bishopb/vanilla
library/core/class.pluginmanager.php
Gdn_PluginManager.RegisterHandler
public function RegisterHandler($HandlerClassName, $HandlerMethodName, $EventClassName = '', $EventName = '', $EventHandlerType = '') { $HandlerKey = $HandlerClassName.'.'.$HandlerMethodName; $EventKey = strtolower($EventClassName == '' ? $HandlerMethodName : $EventClassName.'_'.$EventName.'_'.$EventHandlerType); // Create a new array of handler class names if it doesn't exist yet. if (array_key_exists($EventKey, $this->_EventHandlerCollection) === FALSE) $this->_EventHandlerCollection[$EventKey] = array(); // Specify this class as a handler for this method if it hasn't been done yet. if (in_array($HandlerKey, $this->_EventHandlerCollection[$EventKey]) === FALSE) $this->_EventHandlerCollection[$EventKey][] = $HandlerKey; }
php
public function RegisterHandler($HandlerClassName, $HandlerMethodName, $EventClassName = '', $EventName = '', $EventHandlerType = '') { $HandlerKey = $HandlerClassName.'.'.$HandlerMethodName; $EventKey = strtolower($EventClassName == '' ? $HandlerMethodName : $EventClassName.'_'.$EventName.'_'.$EventHandlerType); // Create a new array of handler class names if it doesn't exist yet. if (array_key_exists($EventKey, $this->_EventHandlerCollection) === FALSE) $this->_EventHandlerCollection[$EventKey] = array(); // Specify this class as a handler for this method if it hasn't been done yet. if (in_array($HandlerKey, $this->_EventHandlerCollection[$EventKey]) === FALSE) $this->_EventHandlerCollection[$EventKey][] = $HandlerKey; }
[ "public", "function", "RegisterHandler", "(", "$", "HandlerClassName", ",", "$", "HandlerMethodName", ",", "$", "EventClassName", "=", "''", ",", "$", "EventName", "=", "''", ",", "$", "EventHandlerType", "=", "''", ")", "{", "$", "HandlerKey", "=", "$", "HandlerClassName", ".", "'.'", ".", "$", "HandlerMethodName", ";", "$", "EventKey", "=", "strtolower", "(", "$", "EventClassName", "==", "''", "?", "$", "HandlerMethodName", ":", "$", "EventClassName", ".", "'_'", ".", "$", "EventName", ".", "'_'", ".", "$", "EventHandlerType", ")", ";", "// Create a new array of handler class names if it doesn't exist yet.", "if", "(", "array_key_exists", "(", "$", "EventKey", ",", "$", "this", "->", "_EventHandlerCollection", ")", "===", "FALSE", ")", "$", "this", "->", "_EventHandlerCollection", "[", "$", "EventKey", "]", "=", "array", "(", ")", ";", "// Specify this class as a handler for this method if it hasn't been done yet.", "if", "(", "in_array", "(", "$", "HandlerKey", ",", "$", "this", "->", "_EventHandlerCollection", "[", "$", "EventKey", "]", ")", "===", "FALSE", ")", "$", "this", "->", "_EventHandlerCollection", "[", "$", "EventKey", "]", "[", "]", "=", "$", "HandlerKey", ";", "}" ]
Registers a plugin method name as a handler. @param string $HandlerClassName The name of the plugin class that will handle the event. @param string $HandlerMethodName The name of the plugin method being registered to handle the event. @param string $EventClassName The name of the class that will fire the event. @param string $EventName The name of the event that will fire. @param string $EventHandlerType The type of event handler.
[ "Registers", "a", "plugin", "method", "name", "as", "a", "handler", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.pluginmanager.php#L585-L596
6,761
bishopb/vanilla
library/core/class.pluginmanager.php
Gdn_PluginManager.RegisterOverride
public function RegisterOverride($OverrideClassName, $OverrideMethodName, $EventClassName = '', $EventName = '') { $OverrideKey = $OverrideClassName.'.'.$OverrideMethodName; $EventKey = strtolower($EventClassName == '' ? $OverrideMethodName : $EventClassName.'_'.$EventName.'_Override'); // Throw an error if this method has already been overridden. if (array_key_exists($EventKey, $this->_MethodOverrideCollection) === TRUE) trigger_error(ErrorMessage('Any object method can only be overridden by a single plugin. The "'.$EventKey.'" override has already been assigned by the "'.$this->_MethodOverrideCollection[$EventKey].'" plugin. It cannot also be overridden by the "'.$OverrideClassName.'" plugin.', 'PluginManager', 'RegisterOverride'), E_USER_ERROR); // Otherwise, specify this class as the source for the override. $this->_MethodOverrideCollection[$EventKey] = $OverrideKey; }
php
public function RegisterOverride($OverrideClassName, $OverrideMethodName, $EventClassName = '', $EventName = '') { $OverrideKey = $OverrideClassName.'.'.$OverrideMethodName; $EventKey = strtolower($EventClassName == '' ? $OverrideMethodName : $EventClassName.'_'.$EventName.'_Override'); // Throw an error if this method has already been overridden. if (array_key_exists($EventKey, $this->_MethodOverrideCollection) === TRUE) trigger_error(ErrorMessage('Any object method can only be overridden by a single plugin. The "'.$EventKey.'" override has already been assigned by the "'.$this->_MethodOverrideCollection[$EventKey].'" plugin. It cannot also be overridden by the "'.$OverrideClassName.'" plugin.', 'PluginManager', 'RegisterOverride'), E_USER_ERROR); // Otherwise, specify this class as the source for the override. $this->_MethodOverrideCollection[$EventKey] = $OverrideKey; }
[ "public", "function", "RegisterOverride", "(", "$", "OverrideClassName", ",", "$", "OverrideMethodName", ",", "$", "EventClassName", "=", "''", ",", "$", "EventName", "=", "''", ")", "{", "$", "OverrideKey", "=", "$", "OverrideClassName", ".", "'.'", ".", "$", "OverrideMethodName", ";", "$", "EventKey", "=", "strtolower", "(", "$", "EventClassName", "==", "''", "?", "$", "OverrideMethodName", ":", "$", "EventClassName", ".", "'_'", ".", "$", "EventName", ".", "'_Override'", ")", ";", "// Throw an error if this method has already been overridden.", "if", "(", "array_key_exists", "(", "$", "EventKey", ",", "$", "this", "->", "_MethodOverrideCollection", ")", "===", "TRUE", ")", "trigger_error", "(", "ErrorMessage", "(", "'Any object method can only be overridden by a single plugin. The \"'", ".", "$", "EventKey", ".", "'\" override has already been assigned by the \"'", ".", "$", "this", "->", "_MethodOverrideCollection", "[", "$", "EventKey", "]", ".", "'\" plugin. It cannot also be overridden by the \"'", ".", "$", "OverrideClassName", ".", "'\" plugin.'", ",", "'PluginManager'", ",", "'RegisterOverride'", ")", ",", "E_USER_ERROR", ")", ";", "// Otherwise, specify this class as the source for the override.", "$", "this", "->", "_MethodOverrideCollection", "[", "$", "EventKey", "]", "=", "$", "OverrideKey", ";", "}" ]
Registers a plugin override method. @param string $OverrideClassName The name of the plugin class that will override the existing method. @param string $OverrideMethodName The name of the plugin method being registered to override the existing method. @param string $EventClassName The name of the class that will fire the event. @param string $EventName The name of the event that will fire.
[ "Registers", "a", "plugin", "override", "method", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.pluginmanager.php#L605-L615
6,762
bishopb/vanilla
library/core/class.pluginmanager.php
Gdn_PluginManager.RegisterNewMethod
public function RegisterNewMethod($NewMethodClassName, $NewMethodName, $EventClassName = '', $EventName = '') { $NewMethodKey = $NewMethodClassName.'.'.$NewMethodName; $EventKey = strtolower($EventClassName == '' ? $NewMethodName : $EventClassName.'_'.$EventName.'_Create'); // Throw an error if this method has already been created. if (array_key_exists($EventKey, $this->_NewMethodCollection) === TRUE) { trigger_error('New object methods must be unique. The new "'.$EventKey.'" method has already been assigned by the "'.$this->_NewMethodCollection[$EventKey].'" plugin. It cannot also be assigned by the "'.$NewMethodClassName.'" plugin.', E_USER_NOTICE); return; } // Otherwise, specify this class as the source for the new method. $this->_NewMethodCollection[$EventKey] = $NewMethodKey; }
php
public function RegisterNewMethod($NewMethodClassName, $NewMethodName, $EventClassName = '', $EventName = '') { $NewMethodKey = $NewMethodClassName.'.'.$NewMethodName; $EventKey = strtolower($EventClassName == '' ? $NewMethodName : $EventClassName.'_'.$EventName.'_Create'); // Throw an error if this method has already been created. if (array_key_exists($EventKey, $this->_NewMethodCollection) === TRUE) { trigger_error('New object methods must be unique. The new "'.$EventKey.'" method has already been assigned by the "'.$this->_NewMethodCollection[$EventKey].'" plugin. It cannot also be assigned by the "'.$NewMethodClassName.'" plugin.', E_USER_NOTICE); return; } // Otherwise, specify this class as the source for the new method. $this->_NewMethodCollection[$EventKey] = $NewMethodKey; }
[ "public", "function", "RegisterNewMethod", "(", "$", "NewMethodClassName", ",", "$", "NewMethodName", ",", "$", "EventClassName", "=", "''", ",", "$", "EventName", "=", "''", ")", "{", "$", "NewMethodKey", "=", "$", "NewMethodClassName", ".", "'.'", ".", "$", "NewMethodName", ";", "$", "EventKey", "=", "strtolower", "(", "$", "EventClassName", "==", "''", "?", "$", "NewMethodName", ":", "$", "EventClassName", ".", "'_'", ".", "$", "EventName", ".", "'_Create'", ")", ";", "// Throw an error if this method has already been created.", "if", "(", "array_key_exists", "(", "$", "EventKey", ",", "$", "this", "->", "_NewMethodCollection", ")", "===", "TRUE", ")", "{", "trigger_error", "(", "'New object methods must be unique. The new \"'", ".", "$", "EventKey", ".", "'\" method has already been assigned by the \"'", ".", "$", "this", "->", "_NewMethodCollection", "[", "$", "EventKey", "]", ".", "'\" plugin. It cannot also be assigned by the \"'", ".", "$", "NewMethodClassName", ".", "'\" plugin.'", ",", "E_USER_NOTICE", ")", ";", "return", ";", "}", "// Otherwise, specify this class as the source for the new method.", "$", "this", "->", "_NewMethodCollection", "[", "$", "EventKey", "]", "=", "$", "NewMethodKey", ";", "}" ]
Registers a plugin new method. @param string $NewMethodClassName The name of the plugin class that will add a new method. @param string $NewMethodName The name of the plugin method being added. @param string $EventClassName The name of the class that will fire the event. @param string $EventName The name of the event that will fire.
[ "Registers", "a", "plugin", "new", "method", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.pluginmanager.php#L624-L636
6,763
bishopb/vanilla
library/core/class.pluginmanager.php
Gdn_PluginManager.CallEventHandlers
public function CallEventHandlers($Sender, $EventClassName, $EventName, $EventHandlerType = 'Handler', $Options = array()) { $Return = FALSE; // Look through $this->_EventHandlerCollection for relevant handlers if ($this->CallEventHandler($Sender, $EventClassName, $EventName, $EventHandlerType)) $Return = TRUE; // Look for "Base" (aka any class that has $EventName) if ($this->CallEventHandler($Sender, 'Base', $EventName, $EventHandlerType)) $Return = TRUE; // Look for Wildcard event handlers $WildEventKey = $EventClassName.'_'.$EventName.'_'.$EventHandlerType; if ($this->CallEventHandler($Sender, 'Base', 'All', $EventHandlerType, $WildEventKey)) $Return = TRUE; if ($this->CallEventHandler($Sender, $EventClassName, 'All', $EventHandlerType, $WildEventKey)) $Return = TRUE; return $Return; }
php
public function CallEventHandlers($Sender, $EventClassName, $EventName, $EventHandlerType = 'Handler', $Options = array()) { $Return = FALSE; // Look through $this->_EventHandlerCollection for relevant handlers if ($this->CallEventHandler($Sender, $EventClassName, $EventName, $EventHandlerType)) $Return = TRUE; // Look for "Base" (aka any class that has $EventName) if ($this->CallEventHandler($Sender, 'Base', $EventName, $EventHandlerType)) $Return = TRUE; // Look for Wildcard event handlers $WildEventKey = $EventClassName.'_'.$EventName.'_'.$EventHandlerType; if ($this->CallEventHandler($Sender, 'Base', 'All', $EventHandlerType, $WildEventKey)) $Return = TRUE; if ($this->CallEventHandler($Sender, $EventClassName, 'All', $EventHandlerType, $WildEventKey)) $Return = TRUE; return $Return; }
[ "public", "function", "CallEventHandlers", "(", "$", "Sender", ",", "$", "EventClassName", ",", "$", "EventName", ",", "$", "EventHandlerType", "=", "'Handler'", ",", "$", "Options", "=", "array", "(", ")", ")", "{", "$", "Return", "=", "FALSE", ";", "// Look through $this->_EventHandlerCollection for relevant handlers", "if", "(", "$", "this", "->", "CallEventHandler", "(", "$", "Sender", ",", "$", "EventClassName", ",", "$", "EventName", ",", "$", "EventHandlerType", ")", ")", "$", "Return", "=", "TRUE", ";", "// Look for \"Base\" (aka any class that has $EventName)", "if", "(", "$", "this", "->", "CallEventHandler", "(", "$", "Sender", ",", "'Base'", ",", "$", "EventName", ",", "$", "EventHandlerType", ")", ")", "$", "Return", "=", "TRUE", ";", "// Look for Wildcard event handlers", "$", "WildEventKey", "=", "$", "EventClassName", ".", "'_'", ".", "$", "EventName", ".", "'_'", ".", "$", "EventHandlerType", ";", "if", "(", "$", "this", "->", "CallEventHandler", "(", "$", "Sender", ",", "'Base'", ",", "'All'", ",", "$", "EventHandlerType", ",", "$", "WildEventKey", ")", ")", "$", "Return", "=", "TRUE", ";", "if", "(", "$", "this", "->", "CallEventHandler", "(", "$", "Sender", ",", "$", "EventClassName", ",", "'All'", ",", "$", "EventHandlerType", ",", "$", "WildEventKey", ")", ")", "$", "Return", "=", "TRUE", ";", "return", "$", "Return", ";", "}" ]
Transfer control to the plugins Looks through $this->_EventHandlerCollection for matching event signatures to handle. If it finds any, it executes them in the order it found them. It instantiates any plugins and adds them as properties to this class (unless they were previously instantiated), and then calls the handler in question. @param object The object that fired the event being handled. @param string The name of the class that fired the event being handled. @param string The name of the event being fired. @param string The type of handler being fired (Handler, Before, After). @return bool True if an event was executed.
[ "Transfer", "control", "to", "the", "plugins" ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.pluginmanager.php#L653-L672
6,764
bishopb/vanilla
library/core/class.pluginmanager.php
Gdn_PluginManager.HasMethodOverride
public function HasMethodOverride($ClassName, $MethodName) { return array_key_exists(strtolower($ClassName.'_'.$MethodName.'_Override'), $this->_MethodOverrideCollection) ? TRUE : FALSE; }
php
public function HasMethodOverride($ClassName, $MethodName) { return array_key_exists(strtolower($ClassName.'_'.$MethodName.'_Override'), $this->_MethodOverrideCollection) ? TRUE : FALSE; }
[ "public", "function", "HasMethodOverride", "(", "$", "ClassName", ",", "$", "MethodName", ")", "{", "return", "array_key_exists", "(", "strtolower", "(", "$", "ClassName", ".", "'_'", ".", "$", "MethodName", ".", "'_Override'", ")", ",", "$", "this", "->", "_MethodOverrideCollection", ")", "?", "TRUE", ":", "FALSE", ";", "}" ]
Checks to see if there are any plugins that override the method being executed. @param string The name of the class that called the method being overridden. @param string The name of the method that is being overridden. @return bool True if an override exists.
[ "Checks", "to", "see", "if", "there", "are", "any", "plugins", "that", "override", "the", "method", "being", "executed", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.pluginmanager.php#L770-L772
6,765
bishopb/vanilla
library/core/class.pluginmanager.php
Gdn_PluginManager.GetCallback
public function GetCallback($ClassName, $MethodName, $Type = 'Create') { $EventKey = strtolower("{$ClassName}_{$MethodName}_{$Type}"); switch ($Type) { case 'Create': $MethodKey = GetValue($EventKey, $this->_NewMethodCollection); break; case 'Override': $MethodKey = GetValue($EventKey, $this->_MethodOverrideCollection); break; } $Parts = explode('.', $MethodKey, 2); if (count($Parts) != 2) return FALSE; list($ClassName, $MethodName) = $Parts; $Instance = $this->GetPluginInstance($ClassName, self::ACCESS_CLASSNAME); return array($Instance, $MethodName); }
php
public function GetCallback($ClassName, $MethodName, $Type = 'Create') { $EventKey = strtolower("{$ClassName}_{$MethodName}_{$Type}"); switch ($Type) { case 'Create': $MethodKey = GetValue($EventKey, $this->_NewMethodCollection); break; case 'Override': $MethodKey = GetValue($EventKey, $this->_MethodOverrideCollection); break; } $Parts = explode('.', $MethodKey, 2); if (count($Parts) != 2) return FALSE; list($ClassName, $MethodName) = $Parts; $Instance = $this->GetPluginInstance($ClassName, self::ACCESS_CLASSNAME); return array($Instance, $MethodName); }
[ "public", "function", "GetCallback", "(", "$", "ClassName", ",", "$", "MethodName", ",", "$", "Type", "=", "'Create'", ")", "{", "$", "EventKey", "=", "strtolower", "(", "\"{$ClassName}_{$MethodName}_{$Type}\"", ")", ";", "switch", "(", "$", "Type", ")", "{", "case", "'Create'", ":", "$", "MethodKey", "=", "GetValue", "(", "$", "EventKey", ",", "$", "this", "->", "_NewMethodCollection", ")", ";", "break", ";", "case", "'Override'", ":", "$", "MethodKey", "=", "GetValue", "(", "$", "EventKey", ",", "$", "this", "->", "_MethodOverrideCollection", ")", ";", "break", ";", "}", "$", "Parts", "=", "explode", "(", "'.'", ",", "$", "MethodKey", ",", "2", ")", ";", "if", "(", "count", "(", "$", "Parts", ")", "!=", "2", ")", "return", "FALSE", ";", "list", "(", "$", "ClassName", ",", "$", "MethodName", ")", "=", "$", "Parts", ";", "$", "Instance", "=", "$", "this", "->", "GetPluginInstance", "(", "$", "ClassName", ",", "self", "::", "ACCESS_CLASSNAME", ")", ";", "return", "array", "(", "$", "Instance", ",", "$", "MethodName", ")", ";", "}" ]
Get the callback for an event handler. @param string $ClassName The name of the class throwing the event. @param string $MethodName The name of the event. @param string $Type The type of event handler. - Create: A new method creation. - Override: A method override. @return callback @since 2.1
[ "Get", "the", "callback", "for", "an", "event", "handler", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.pluginmanager.php#L807-L825
6,766
bishopb/vanilla
library/core/class.pluginmanager.php
Gdn_PluginManager.HasNewMethod
public function HasNewMethod($ClassName, $MethodName) { $Key = strtolower($ClassName.'_'.$MethodName.'_Create'); if (array_key_exists($Key, $this->_NewMethodCollection)) { $Result = explode('.', $this->_NewMethodCollection[$Key]); return $Result[0]; } else { return FALSE; } }
php
public function HasNewMethod($ClassName, $MethodName) { $Key = strtolower($ClassName.'_'.$MethodName.'_Create'); if (array_key_exists($Key, $this->_NewMethodCollection)) { $Result = explode('.', $this->_NewMethodCollection[$Key]); return $Result[0]; } else { return FALSE; } }
[ "public", "function", "HasNewMethod", "(", "$", "ClassName", ",", "$", "MethodName", ")", "{", "$", "Key", "=", "strtolower", "(", "$", "ClassName", ".", "'_'", ".", "$", "MethodName", ".", "'_Create'", ")", ";", "if", "(", "array_key_exists", "(", "$", "Key", ",", "$", "this", "->", "_NewMethodCollection", ")", ")", "{", "$", "Result", "=", "explode", "(", "'.'", ",", "$", "this", "->", "_NewMethodCollection", "[", "$", "Key", "]", ")", ";", "return", "$", "Result", "[", "0", "]", ";", "}", "else", "{", "return", "FALSE", ";", "}", "}" ]
Checks to see if there are any plugins that create the method being executed. @param string The name of the class that called the method being created. @param string The name of the method that is being created. @return True if method exists.
[ "Checks", "to", "see", "if", "there", "are", "any", "plugins", "that", "create", "the", "method", "being", "executed", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.pluginmanager.php#L835-L843
6,767
bishopb/vanilla
library/core/class.pluginmanager.php
Gdn_PluginManager._PluginHook
private function _PluginHook($PluginName, $ForAction, $Callback = FALSE) { switch ($ForAction) { case self::ACTION_ENABLE: $HookMethod = 'Setup'; break; case self::ACTION_DISABLE: $HookMethod = 'OnDisable'; break; case self::ACTION_REMOVE: $HookMethod = 'CleanUp'; break; case self::ACTION_ONLOAD: $HookMethod = 'OnLoad'; break; } $PluginInfo = ArrayValue($PluginName, $this->AvailablePlugins(), FALSE); $PluginFolder = ArrayValue('Folder', $PluginInfo, FALSE); $PluginClassName = ArrayValue('ClassName', $PluginInfo, FALSE); if ($ForAction === self::ACTION_REMOVE) { $this->_RemovePluginFolder($PluginFolder); } if ($PluginFolder !== FALSE && $PluginClassName !== FALSE && class_exists($PluginClassName) === FALSE) { if ($ForAction !== self::ACTION_DISABLE) { $this->IncludePlugins(array($PluginName => TRUE)); } $this->_PluginCallbackExecution($PluginClassName, $HookMethod); } elseif ($Callback === TRUE) { $this->_PluginCallbackExecution($PluginClassName, $HookMethod); } }
php
private function _PluginHook($PluginName, $ForAction, $Callback = FALSE) { switch ($ForAction) { case self::ACTION_ENABLE: $HookMethod = 'Setup'; break; case self::ACTION_DISABLE: $HookMethod = 'OnDisable'; break; case self::ACTION_REMOVE: $HookMethod = 'CleanUp'; break; case self::ACTION_ONLOAD: $HookMethod = 'OnLoad'; break; } $PluginInfo = ArrayValue($PluginName, $this->AvailablePlugins(), FALSE); $PluginFolder = ArrayValue('Folder', $PluginInfo, FALSE); $PluginClassName = ArrayValue('ClassName', $PluginInfo, FALSE); if ($ForAction === self::ACTION_REMOVE) { $this->_RemovePluginFolder($PluginFolder); } if ($PluginFolder !== FALSE && $PluginClassName !== FALSE && class_exists($PluginClassName) === FALSE) { if ($ForAction !== self::ACTION_DISABLE) { $this->IncludePlugins(array($PluginName => TRUE)); } $this->_PluginCallbackExecution($PluginClassName, $HookMethod); } elseif ($Callback === TRUE) { $this->_PluginCallbackExecution($PluginClassName, $HookMethod); } }
[ "private", "function", "_PluginHook", "(", "$", "PluginName", ",", "$", "ForAction", ",", "$", "Callback", "=", "FALSE", ")", "{", "switch", "(", "$", "ForAction", ")", "{", "case", "self", "::", "ACTION_ENABLE", ":", "$", "HookMethod", "=", "'Setup'", ";", "break", ";", "case", "self", "::", "ACTION_DISABLE", ":", "$", "HookMethod", "=", "'OnDisable'", ";", "break", ";", "case", "self", "::", "ACTION_REMOVE", ":", "$", "HookMethod", "=", "'CleanUp'", ";", "break", ";", "case", "self", "::", "ACTION_ONLOAD", ":", "$", "HookMethod", "=", "'OnLoad'", ";", "break", ";", "}", "$", "PluginInfo", "=", "ArrayValue", "(", "$", "PluginName", ",", "$", "this", "->", "AvailablePlugins", "(", ")", ",", "FALSE", ")", ";", "$", "PluginFolder", "=", "ArrayValue", "(", "'Folder'", ",", "$", "PluginInfo", ",", "FALSE", ")", ";", "$", "PluginClassName", "=", "ArrayValue", "(", "'ClassName'", ",", "$", "PluginInfo", ",", "FALSE", ")", ";", "if", "(", "$", "ForAction", "===", "self", "::", "ACTION_REMOVE", ")", "{", "$", "this", "->", "_RemovePluginFolder", "(", "$", "PluginFolder", ")", ";", "}", "if", "(", "$", "PluginFolder", "!==", "FALSE", "&&", "$", "PluginClassName", "!==", "FALSE", "&&", "class_exists", "(", "$", "PluginClassName", ")", "===", "FALSE", ")", "{", "if", "(", "$", "ForAction", "!==", "self", "::", "ACTION_DISABLE", ")", "{", "$", "this", "->", "IncludePlugins", "(", "array", "(", "$", "PluginName", "=>", "TRUE", ")", ")", ";", "}", "$", "this", "->", "_PluginCallbackExecution", "(", "$", "PluginClassName", ",", "$", "HookMethod", ")", ";", "}", "elseif", "(", "$", "Callback", "===", "TRUE", ")", "{", "$", "this", "->", "_PluginCallbackExecution", "(", "$", "PluginClassName", ",", "$", "HookMethod", ")", ";", "}", "}" ]
Hooks to the various actions, i.e. enable, disable and remove. @param string $PluginName @param string $ForAction which action to hook it to, i.e. enable, disable or remove @param boolean $Callback whether to perform the hook method @return void
[ "Hooks", "to", "the", "various", "actions", "i", ".", "e", ".", "enable", "disable", "and", "remove", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.pluginmanager.php#L1138-L1164
6,768
bishopb/vanilla
library/core/class.pluginmanager.php
Gdn_PluginManager._PluginCallbackExecution
private function _PluginCallbackExecution($PluginClassName, $HookMethod) { if (class_exists($PluginClassName)) { $Plugin = new $PluginClassName(); if (method_exists($PluginClassName, $HookMethod)) { $Plugin->$HookMethod(); } } }
php
private function _PluginCallbackExecution($PluginClassName, $HookMethod) { if (class_exists($PluginClassName)) { $Plugin = new $PluginClassName(); if (method_exists($PluginClassName, $HookMethod)) { $Plugin->$HookMethod(); } } }
[ "private", "function", "_PluginCallbackExecution", "(", "$", "PluginClassName", ",", "$", "HookMethod", ")", "{", "if", "(", "class_exists", "(", "$", "PluginClassName", ")", ")", "{", "$", "Plugin", "=", "new", "$", "PluginClassName", "(", ")", ";", "if", "(", "method_exists", "(", "$", "PluginClassName", ",", "$", "HookMethod", ")", ")", "{", "$", "Plugin", "->", "$", "HookMethod", "(", ")", ";", "}", "}", "}" ]
Executes the plugin hook action if it exists. @param string $PluginClassName @param string $HookMethod @return void
[ "Executes", "the", "plugin", "hook", "action", "if", "it", "exists", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.pluginmanager.php#L1173-L1180
6,769
sellerlabs/nucleus
src/SellerLabs/Nucleus/Meditation/Spec.php
Spec.check
public function check(array $input) { $missing = []; $invalid = []; $check = function ($constraint, $key, $value, $input) use ( &$missing, &$invalid ) { if ($constraint instanceof AbstractConstraint) { if (!$constraint->check($value, $input)) { $invalid[$key][] = $constraint; } } elseif ($constraint instanceof CheckableInterface) { $result = $constraint->check($value); $missing = Std::concat( $missing, array_map( function ($subKey) use ($key) { return vsprintf('%s.%s', [$key, $subKey]); }, $result->getMissing() ) ); foreach ($result->getFailed() as $failedField => $constraints) { $fullPath = vsprintf('%s.%s', [$key, $failedField]); if (array_key_exists($fullPath, $invalid)) { $invalid[$fullPath] = array_merge( $invalid[$fullPath], $constraints ); } else { $invalid[$fullPath] = $constraints; } } } else { throw new CoreException( vsprintf( 'Unexpected constraint type: %s.', [ TypeHound::fetch($constraint), ] ) ); } }; $inputMap = ArrayMap::of($input); $this->annotations->each( function ($value, $key) use ( $check, $input, $inputMap, &$missing ) { // If a field is required but not present, we should report it. if (Maybe::fromMaybe( false, $value->lookup(static::ANNOTATION_REQUIRED) ) && $inputMap->member($key) === false ) { $missing[] = $key; // There's no point on checking constraints on the field // since it is missing. return; } elseif ($inputMap->member($key) === false) { // There's no point on checking constraints on the field // since it is missing. return; } $fieldValue = Maybe::fromJust($inputMap->lookup($key)); $this ->getInternalFieldConstraints($key) ->each( function ($constraint) use ( $check, $key, $fieldValue, $input ) { $check($constraint, $key, $fieldValue, $input); } ); } ); if (count($missing) === 0 && count($invalid) === 0) { return new SpecResult($missing, $invalid, SpecResult::STATUS_PASS); } return new SpecResult($missing, $invalid, SpecResult::STATUS_FAIL); }
php
public function check(array $input) { $missing = []; $invalid = []; $check = function ($constraint, $key, $value, $input) use ( &$missing, &$invalid ) { if ($constraint instanceof AbstractConstraint) { if (!$constraint->check($value, $input)) { $invalid[$key][] = $constraint; } } elseif ($constraint instanceof CheckableInterface) { $result = $constraint->check($value); $missing = Std::concat( $missing, array_map( function ($subKey) use ($key) { return vsprintf('%s.%s', [$key, $subKey]); }, $result->getMissing() ) ); foreach ($result->getFailed() as $failedField => $constraints) { $fullPath = vsprintf('%s.%s', [$key, $failedField]); if (array_key_exists($fullPath, $invalid)) { $invalid[$fullPath] = array_merge( $invalid[$fullPath], $constraints ); } else { $invalid[$fullPath] = $constraints; } } } else { throw new CoreException( vsprintf( 'Unexpected constraint type: %s.', [ TypeHound::fetch($constraint), ] ) ); } }; $inputMap = ArrayMap::of($input); $this->annotations->each( function ($value, $key) use ( $check, $input, $inputMap, &$missing ) { // If a field is required but not present, we should report it. if (Maybe::fromMaybe( false, $value->lookup(static::ANNOTATION_REQUIRED) ) && $inputMap->member($key) === false ) { $missing[] = $key; // There's no point on checking constraints on the field // since it is missing. return; } elseif ($inputMap->member($key) === false) { // There's no point on checking constraints on the field // since it is missing. return; } $fieldValue = Maybe::fromJust($inputMap->lookup($key)); $this ->getInternalFieldConstraints($key) ->each( function ($constraint) use ( $check, $key, $fieldValue, $input ) { $check($constraint, $key, $fieldValue, $input); } ); } ); if (count($missing) === 0 && count($invalid) === 0) { return new SpecResult($missing, $invalid, SpecResult::STATUS_PASS); } return new SpecResult($missing, $invalid, SpecResult::STATUS_FAIL); }
[ "public", "function", "check", "(", "array", "$", "input", ")", "{", "$", "missing", "=", "[", "]", ";", "$", "invalid", "=", "[", "]", ";", "$", "check", "=", "function", "(", "$", "constraint", ",", "$", "key", ",", "$", "value", ",", "$", "input", ")", "use", "(", "&", "$", "missing", ",", "&", "$", "invalid", ")", "{", "if", "(", "$", "constraint", "instanceof", "AbstractConstraint", ")", "{", "if", "(", "!", "$", "constraint", "->", "check", "(", "$", "value", ",", "$", "input", ")", ")", "{", "$", "invalid", "[", "$", "key", "]", "[", "]", "=", "$", "constraint", ";", "}", "}", "elseif", "(", "$", "constraint", "instanceof", "CheckableInterface", ")", "{", "$", "result", "=", "$", "constraint", "->", "check", "(", "$", "value", ")", ";", "$", "missing", "=", "Std", "::", "concat", "(", "$", "missing", ",", "array_map", "(", "function", "(", "$", "subKey", ")", "use", "(", "$", "key", ")", "{", "return", "vsprintf", "(", "'%s.%s'", ",", "[", "$", "key", ",", "$", "subKey", "]", ")", ";", "}", ",", "$", "result", "->", "getMissing", "(", ")", ")", ")", ";", "foreach", "(", "$", "result", "->", "getFailed", "(", ")", "as", "$", "failedField", "=>", "$", "constraints", ")", "{", "$", "fullPath", "=", "vsprintf", "(", "'%s.%s'", ",", "[", "$", "key", ",", "$", "failedField", "]", ")", ";", "if", "(", "array_key_exists", "(", "$", "fullPath", ",", "$", "invalid", ")", ")", "{", "$", "invalid", "[", "$", "fullPath", "]", "=", "array_merge", "(", "$", "invalid", "[", "$", "fullPath", "]", ",", "$", "constraints", ")", ";", "}", "else", "{", "$", "invalid", "[", "$", "fullPath", "]", "=", "$", "constraints", ";", "}", "}", "}", "else", "{", "throw", "new", "CoreException", "(", "vsprintf", "(", "'Unexpected constraint type: %s.'", ",", "[", "TypeHound", "::", "fetch", "(", "$", "constraint", ")", ",", "]", ")", ")", ";", "}", "}", ";", "$", "inputMap", "=", "ArrayMap", "::", "of", "(", "$", "input", ")", ";", "$", "this", "->", "annotations", "->", "each", "(", "function", "(", "$", "value", ",", "$", "key", ")", "use", "(", "$", "check", ",", "$", "input", ",", "$", "inputMap", ",", "&", "$", "missing", ")", "{", "// If a field is required but not present, we should report it.", "if", "(", "Maybe", "::", "fromMaybe", "(", "false", ",", "$", "value", "->", "lookup", "(", "static", "::", "ANNOTATION_REQUIRED", ")", ")", "&&", "$", "inputMap", "->", "member", "(", "$", "key", ")", "===", "false", ")", "{", "$", "missing", "[", "]", "=", "$", "key", ";", "// There's no point on checking constraints on the field", "// since it is missing.", "return", ";", "}", "elseif", "(", "$", "inputMap", "->", "member", "(", "$", "key", ")", "===", "false", ")", "{", "// There's no point on checking constraints on the field", "// since it is missing.", "return", ";", "}", "$", "fieldValue", "=", "Maybe", "::", "fromJust", "(", "$", "inputMap", "->", "lookup", "(", "$", "key", ")", ")", ";", "$", "this", "->", "getInternalFieldConstraints", "(", "$", "key", ")", "->", "each", "(", "function", "(", "$", "constraint", ")", "use", "(", "$", "check", ",", "$", "key", ",", "$", "fieldValue", ",", "$", "input", ")", "{", "$", "check", "(", "$", "constraint", ",", "$", "key", ",", "$", "fieldValue", ",", "$", "input", ")", ";", "}", ")", ";", "}", ")", ";", "if", "(", "count", "(", "$", "missing", ")", "===", "0", "&&", "count", "(", "$", "invalid", ")", "===", "0", ")", "{", "return", "new", "SpecResult", "(", "$", "missing", ",", "$", "invalid", ",", "SpecResult", "::", "STATUS_PASS", ")", ";", "}", "return", "new", "SpecResult", "(", "$", "missing", ",", "$", "invalid", ",", "SpecResult", "::", "STATUS_FAIL", ")", ";", "}" ]
Check that a certain input passes the spec. @param mixed $input @return SpecResult
[ "Check", "that", "a", "certain", "input", "passes", "the", "spec", "." ]
c05d9c23d424a6bd5ab2e29140805cc6e37e4623
https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Meditation/Spec.php#L136-L235
6,770
sellerlabs/nucleus
src/SellerLabs/Nucleus/Meditation/Spec.php
Spec.getFieldConstraints
public function getFieldConstraints($fieldName) { $maybeConstraints = $this->annotations->lookupIn( [$fieldName, static::ANNOTATION_CONSTRAINTS] ); if ($maybeConstraints->isNothing()) { return ArrayList::zero(); } $constraints = Maybe::fromJust($maybeConstraints); if (is_array($constraints)) { return ArrayList::of($constraints); } elseif ($constraints instanceof IterableType) { return $constraints; } return ArrayList::of([$constraints]); }
php
public function getFieldConstraints($fieldName) { $maybeConstraints = $this->annotations->lookupIn( [$fieldName, static::ANNOTATION_CONSTRAINTS] ); if ($maybeConstraints->isNothing()) { return ArrayList::zero(); } $constraints = Maybe::fromJust($maybeConstraints); if (is_array($constraints)) { return ArrayList::of($constraints); } elseif ($constraints instanceof IterableType) { return $constraints; } return ArrayList::of([$constraints]); }
[ "public", "function", "getFieldConstraints", "(", "$", "fieldName", ")", "{", "$", "maybeConstraints", "=", "$", "this", "->", "annotations", "->", "lookupIn", "(", "[", "$", "fieldName", ",", "static", "::", "ANNOTATION_CONSTRAINTS", "]", ")", ";", "if", "(", "$", "maybeConstraints", "->", "isNothing", "(", ")", ")", "{", "return", "ArrayList", "::", "zero", "(", ")", ";", "}", "$", "constraints", "=", "Maybe", "::", "fromJust", "(", "$", "maybeConstraints", ")", ";", "if", "(", "is_array", "(", "$", "constraints", ")", ")", "{", "return", "ArrayList", "::", "of", "(", "$", "constraints", ")", ";", "}", "elseif", "(", "$", "constraints", "instanceof", "IterableType", ")", "{", "return", "$", "constraints", ";", "}", "return", "ArrayList", "::", "of", "(", "[", "$", "constraints", "]", ")", ";", "}" ]
Get all the constraints for a single field. @param string $fieldName @return IterableType
[ "Get", "all", "the", "constraints", "for", "a", "single", "field", "." ]
c05d9c23d424a6bd5ab2e29140805cc6e37e4623
https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Meditation/Spec.php#L257-L276
6,771
sellerlabs/nucleus
src/SellerLabs/Nucleus/Meditation/Spec.php
Spec.withFieldAnnotation
public function withFieldAnnotation($fieldName, $name, $value) { $copy = clone $this; $copy->annotations = $this->annotations->update( $fieldName, function (ArrayMap $fieldAnnotations) use ($name, $value) { return $fieldAnnotations->insert($name, $value); }, ArrayMap::zero() ); return $copy; }
php
public function withFieldAnnotation($fieldName, $name, $value) { $copy = clone $this; $copy->annotations = $this->annotations->update( $fieldName, function (ArrayMap $fieldAnnotations) use ($name, $value) { return $fieldAnnotations->insert($name, $value); }, ArrayMap::zero() ); return $copy; }
[ "public", "function", "withFieldAnnotation", "(", "$", "fieldName", ",", "$", "name", ",", "$", "value", ")", "{", "$", "copy", "=", "clone", "$", "this", ";", "$", "copy", "->", "annotations", "=", "$", "this", "->", "annotations", "->", "update", "(", "$", "fieldName", ",", "function", "(", "ArrayMap", "$", "fieldAnnotations", ")", "use", "(", "$", "name", ",", "$", "value", ")", "{", "return", "$", "fieldAnnotations", "->", "insert", "(", "$", "name", ",", "$", "value", ")", ";", "}", ",", "ArrayMap", "::", "zero", "(", ")", ")", ";", "return", "$", "copy", ";", "}" ]
Set the value of an annotation. @param string $fieldName @param string $name @param mixed $value @return static
[ "Set", "the", "value", "of", "an", "annotation", "." ]
c05d9c23d424a6bd5ab2e29140805cc6e37e4623
https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Meditation/Spec.php#L425-L438
6,772
sellerlabs/nucleus
src/SellerLabs/Nucleus/Meditation/Spec.php
Spec.withAnnotation
public function withAnnotation($name, LeftKeyFoldableInterface $map) { return $map->foldlWithKeys( function (self $acc, $value, $fieldName) use ($name) { return $acc->withFieldAnnotation($fieldName, $name, $value); }, $this ); }
php
public function withAnnotation($name, LeftKeyFoldableInterface $map) { return $map->foldlWithKeys( function (self $acc, $value, $fieldName) use ($name) { return $acc->withFieldAnnotation($fieldName, $name, $value); }, $this ); }
[ "public", "function", "withAnnotation", "(", "$", "name", ",", "LeftKeyFoldableInterface", "$", "map", ")", "{", "return", "$", "map", "->", "foldlWithKeys", "(", "function", "(", "self", "$", "acc", ",", "$", "value", ",", "$", "fieldName", ")", "use", "(", "$", "name", ")", "{", "return", "$", "acc", "->", "withFieldAnnotation", "(", "$", "fieldName", ",", "$", "name", ",", "$", "value", ")", ";", "}", ",", "$", "this", ")", ";", "}" ]
Get this spec with a map applied as an annotation. @param string $name @param LeftKeyFoldableInterface $map @return mixed
[ "Get", "this", "spec", "with", "a", "map", "applied", "as", "an", "annotation", "." ]
c05d9c23d424a6bd5ab2e29140805cc6e37e4623
https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Meditation/Spec.php#L482-L490
6,773
anekdotes/support
src/anekdotes/I18n.php
I18n.loadFolder
public function loadFolder($path, $namespace = '__main__') { if (is_dir($path)) { $files = glob($path.'*.php'); if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); } foreach ($files as $file) { $shell = explode(DS, $file); $fileName = end($shell); $fileName = explode('.', $fileName, -1); $prefix = ''; if (count($fileName) == 2) { $prefix = reset($fileName).'.'; $locale = end($fileName); } else { $locale = end($fileName); } $translations = require $file; $translations = array_dot($translations, $prefix); // merge $namespace arrays with prefixed arrays if exists if (isset($this->translations[$locale])) { if (isset($this->translations[$locale][$namespace])) { $translations = array_merge($this->translations[$locale][$namespace], $translations); } } // Save the values in our instance array $this->translations[$locale][$namespace] = $translations; } } }
php
public function loadFolder($path, $namespace = '__main__') { if (is_dir($path)) { $files = glob($path.'*.php'); if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); } foreach ($files as $file) { $shell = explode(DS, $file); $fileName = end($shell); $fileName = explode('.', $fileName, -1); $prefix = ''; if (count($fileName) == 2) { $prefix = reset($fileName).'.'; $locale = end($fileName); } else { $locale = end($fileName); } $translations = require $file; $translations = array_dot($translations, $prefix); // merge $namespace arrays with prefixed arrays if exists if (isset($this->translations[$locale])) { if (isset($this->translations[$locale][$namespace])) { $translations = array_merge($this->translations[$locale][$namespace], $translations); } } // Save the values in our instance array $this->translations[$locale][$namespace] = $translations; } } }
[ "public", "function", "loadFolder", "(", "$", "path", ",", "$", "namespace", "=", "'__main__'", ")", "{", "if", "(", "is_dir", "(", "$", "path", ")", ")", "{", "$", "files", "=", "glob", "(", "$", "path", ".", "'*.php'", ")", ";", "if", "(", "!", "defined", "(", "'DS'", ")", ")", "{", "define", "(", "'DS'", ",", "DIRECTORY_SEPARATOR", ")", ";", "}", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "shell", "=", "explode", "(", "DS", ",", "$", "file", ")", ";", "$", "fileName", "=", "end", "(", "$", "shell", ")", ";", "$", "fileName", "=", "explode", "(", "'.'", ",", "$", "fileName", ",", "-", "1", ")", ";", "$", "prefix", "=", "''", ";", "if", "(", "count", "(", "$", "fileName", ")", "==", "2", ")", "{", "$", "prefix", "=", "reset", "(", "$", "fileName", ")", ".", "'.'", ";", "$", "locale", "=", "end", "(", "$", "fileName", ")", ";", "}", "else", "{", "$", "locale", "=", "end", "(", "$", "fileName", ")", ";", "}", "$", "translations", "=", "require", "$", "file", ";", "$", "translations", "=", "array_dot", "(", "$", "translations", ",", "$", "prefix", ")", ";", "// merge $namespace arrays with prefixed arrays if exists", "if", "(", "isset", "(", "$", "this", "->", "translations", "[", "$", "locale", "]", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "translations", "[", "$", "locale", "]", "[", "$", "namespace", "]", ")", ")", "{", "$", "translations", "=", "array_merge", "(", "$", "this", "->", "translations", "[", "$", "locale", "]", "[", "$", "namespace", "]", ",", "$", "translations", ")", ";", "}", "}", "// Save the values in our instance array", "$", "this", "->", "translations", "[", "$", "locale", "]", "[", "$", "namespace", "]", "=", "$", "translations", ";", "}", "}", "}" ]
Load files in a folder to use as translations. @param string $path Path to the folder @param string $namespace Namespace the folder is in
[ "Load", "files", "in", "a", "folder", "to", "use", "as", "translations", "." ]
071befb735b6ec464be41dc9be7eeeb4b2a89467
https://github.com/anekdotes/support/blob/071befb735b6ec464be41dc9be7eeeb4b2a89467/src/anekdotes/I18n.php#L89-L121
6,774
anekdotes/support
src/anekdotes/I18n.php
I18n.t
public function t() { $args = func_get_args(); $locales = count($this->supportedLocales); if (empty($args)) { return ''; } if ($locales == 0) { return ''; } if ($locales != count($args)) { $args = array_slice($args, 0, $locales); } if ($locales - count($args) > 0) { $args = array_merge($args, array_fill(0, $locales - count($args), '')); } $translations = array_combine($this->supportedLocales, $args); return $translations[$this->currentLocale]; }
php
public function t() { $args = func_get_args(); $locales = count($this->supportedLocales); if (empty($args)) { return ''; } if ($locales == 0) { return ''; } if ($locales != count($args)) { $args = array_slice($args, 0, $locales); } if ($locales - count($args) > 0) { $args = array_merge($args, array_fill(0, $locales - count($args), '')); } $translations = array_combine($this->supportedLocales, $args); return $translations[$this->currentLocale]; }
[ "public", "function", "t", "(", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "locales", "=", "count", "(", "$", "this", "->", "supportedLocales", ")", ";", "if", "(", "empty", "(", "$", "args", ")", ")", "{", "return", "''", ";", "}", "if", "(", "$", "locales", "==", "0", ")", "{", "return", "''", ";", "}", "if", "(", "$", "locales", "!=", "count", "(", "$", "args", ")", ")", "{", "$", "args", "=", "array_slice", "(", "$", "args", ",", "0", ",", "$", "locales", ")", ";", "}", "if", "(", "$", "locales", "-", "count", "(", "$", "args", ")", ">", "0", ")", "{", "$", "args", "=", "array_merge", "(", "$", "args", ",", "array_fill", "(", "0", ",", "$", "locales", "-", "count", "(", "$", "args", ")", ",", "''", ")", ")", ";", "}", "$", "translations", "=", "array_combine", "(", "$", "this", "->", "supportedLocales", ",", "$", "args", ")", ";", "return", "$", "translations", "[", "$", "this", "->", "currentLocale", "]", ";", "}" ]
Give the proper translation based on the locale. @param string Here are a lot of parameters. Each parameter corresponds to a translation, in order in which they are in supported locales @return string The string corresponding to the current locale
[ "Give", "the", "proper", "translation", "based", "on", "the", "locale", "." ]
071befb735b6ec464be41dc9be7eeeb4b2a89467
https://github.com/anekdotes/support/blob/071befb735b6ec464be41dc9be7eeeb4b2a89467/src/anekdotes/I18n.php#L130-L154
6,775
anekdotes/support
src/anekdotes/I18n.php
I18n.dt
public function dt($key, $values = []) { $namespace = '__main__'; if (Str::contains($key, '::')) { list($namespace, $key) = explode('::', $key); } if (empty($this->translations)) { return ''; } $loc = $this->getLocale(); if (array_key_exists($namespace, $this->translations[$loc]) && array_key_exists($key, $this->translations[$loc][$namespace])) { $translation = $this->translations[$loc][$namespace][$key]; foreach ($values as $name => $value) { $translation = str_replace(':'.$name, $value, $translation); } return $translation; } else { return ''; } }
php
public function dt($key, $values = []) { $namespace = '__main__'; if (Str::contains($key, '::')) { list($namespace, $key) = explode('::', $key); } if (empty($this->translations)) { return ''; } $loc = $this->getLocale(); if (array_key_exists($namespace, $this->translations[$loc]) && array_key_exists($key, $this->translations[$loc][$namespace])) { $translation = $this->translations[$loc][$namespace][$key]; foreach ($values as $name => $value) { $translation = str_replace(':'.$name, $value, $translation); } return $translation; } else { return ''; } }
[ "public", "function", "dt", "(", "$", "key", ",", "$", "values", "=", "[", "]", ")", "{", "$", "namespace", "=", "'__main__'", ";", "if", "(", "Str", "::", "contains", "(", "$", "key", ",", "'::'", ")", ")", "{", "list", "(", "$", "namespace", ",", "$", "key", ")", "=", "explode", "(", "'::'", ",", "$", "key", ")", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "translations", ")", ")", "{", "return", "''", ";", "}", "$", "loc", "=", "$", "this", "->", "getLocale", "(", ")", ";", "if", "(", "array_key_exists", "(", "$", "namespace", ",", "$", "this", "->", "translations", "[", "$", "loc", "]", ")", "&&", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "translations", "[", "$", "loc", "]", "[", "$", "namespace", "]", ")", ")", "{", "$", "translation", "=", "$", "this", "->", "translations", "[", "$", "loc", "]", "[", "$", "namespace", "]", "[", "$", "key", "]", ";", "foreach", "(", "$", "values", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "translation", "=", "str_replace", "(", "':'", ".", "$", "name", ",", "$", "value", ",", "$", "translation", ")", ";", "}", "return", "$", "translation", ";", "}", "else", "{", "return", "''", ";", "}", "}" ]
Fetches the translation of the key based on the current locale. @param string $key translation to obtain @param array $values Values to be replaced in the translation string @return string Translated value
[ "Fetches", "the", "translation", "of", "the", "key", "based", "on", "the", "current", "locale", "." ]
071befb735b6ec464be41dc9be7eeeb4b2a89467
https://github.com/anekdotes/support/blob/071befb735b6ec464be41dc9be7eeeb4b2a89467/src/anekdotes/I18n.php#L164-L188
6,776
indigophp-archive/codeception-fuel-module
fuel/fuel/core/classes/event.php
Event.instance
public static function instance($name = 'fuelphp', array $events = array()) { if ( ! array_key_exists($name, static::$instances)) { $events = array_merge(\Config::get('event.'.$name, array()), $events); $instance = static::forge($events); static::$instances[$name] = &$instance; } return static::$instances[$name]; }
php
public static function instance($name = 'fuelphp', array $events = array()) { if ( ! array_key_exists($name, static::$instances)) { $events = array_merge(\Config::get('event.'.$name, array()), $events); $instance = static::forge($events); static::$instances[$name] = &$instance; } return static::$instances[$name]; }
[ "public", "static", "function", "instance", "(", "$", "name", "=", "'fuelphp'", ",", "array", "$", "events", "=", "array", "(", ")", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "name", ",", "static", "::", "$", "instances", ")", ")", "{", "$", "events", "=", "array_merge", "(", "\\", "Config", "::", "get", "(", "'event.'", ".", "$", "name", ",", "array", "(", ")", ")", ",", "$", "events", ")", ";", "$", "instance", "=", "static", "::", "forge", "(", "$", "events", ")", ";", "static", "::", "$", "instances", "[", "$", "name", "]", "=", "&", "$", "instance", ";", "}", "return", "static", "::", "$", "instances", "[", "$", "name", "]", ";", "}" ]
Multiton Event instance. @param string $name instance name @param array $events events array @return object Event_Instance object
[ "Multiton", "Event", "instance", "." ]
0973b7cbd540a0e89cc5bb7af94627f77f09bf49
https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/core/classes/event.php#L48-L58
6,777
indigophp-archive/queue
src/Connector/RabbitConnector.php
RabbitConnector.regenerateChannel
public function regenerateChannel() { $channel = $this->channel; $this->channel = $this->amqp->channel(); return $channel; }
php
public function regenerateChannel() { $channel = $this->channel; $this->channel = $this->amqp->channel(); return $channel; }
[ "public", "function", "regenerateChannel", "(", ")", "{", "$", "channel", "=", "$", "this", "->", "channel", ";", "$", "this", "->", "channel", "=", "$", "this", "->", "amqp", "->", "channel", "(", ")", ";", "return", "$", "channel", ";", "}" ]
Regenerates a channel @return AMQPChannel Old channel
[ "Regenerates", "a", "channel" ]
d364d5a1fc3b00d59846b19aa472d7f2aa130ff8
https://github.com/indigophp-archive/queue/blob/d364d5a1fc3b00d59846b19aa472d7f2aa130ff8/src/Connector/RabbitConnector.php#L122-L128
6,778
indigophp-archive/queue
src/Connector/RabbitConnector.php
RabbitConnector.prepareMessage
protected function prepareMessage($queue, Job $job) { $this->queueDeclare($queue); return new AMQPMessage(json_encode($job->createPayload()), $job->getOptions()); }
php
protected function prepareMessage($queue, Job $job) { $this->queueDeclare($queue); return new AMQPMessage(json_encode($job->createPayload()), $job->getOptions()); }
[ "protected", "function", "prepareMessage", "(", "$", "queue", ",", "Job", "$", "job", ")", "{", "$", "this", "->", "queueDeclare", "(", "$", "queue", ")", ";", "return", "new", "AMQPMessage", "(", "json_encode", "(", "$", "job", "->", "createPayload", "(", ")", ")", ",", "$", "job", "->", "getOptions", "(", ")", ")", ";", "}" ]
Prepares a message @param string $queue @param Job $job @return AMQPMessage @codeCoverageIgnore
[ "Prepares", "a", "message" ]
d364d5a1fc3b00d59846b19aa472d7f2aa130ff8
https://github.com/indigophp-archive/queue/blob/d364d5a1fc3b00d59846b19aa472d7f2aa130ff8/src/Connector/RabbitConnector.php#L176-L181
6,779
indigophp-archive/queue
src/Connector/RabbitConnector.php
RabbitConnector.queueDeclare
protected function queueDeclare($queue = '', array $arguments = []) { return $this->channel->queue_declare( $queue, false, $this->persistent, false, false, false, $arguments ); }
php
protected function queueDeclare($queue = '', array $arguments = []) { return $this->channel->queue_declare( $queue, false, $this->persistent, false, false, false, $arguments ); }
[ "protected", "function", "queueDeclare", "(", "$", "queue", "=", "''", ",", "array", "$", "arguments", "=", "[", "]", ")", "{", "return", "$", "this", "->", "channel", "->", "queue_declare", "(", "$", "queue", ",", "false", ",", "$", "this", "->", "persistent", ",", "false", ",", "false", ",", "false", ",", "$", "arguments", ")", ";", "}" ]
Declares a new queue @param string $queue @param [] $arguments @return mixed @codeCoverageIgnore
[ "Declares", "a", "new", "queue" ]
d364d5a1fc3b00d59846b19aa472d7f2aa130ff8
https://github.com/indigophp-archive/queue/blob/d364d5a1fc3b00d59846b19aa472d7f2aa130ff8/src/Connector/RabbitConnector.php#L193-L204
6,780
indigophp-archive/queue
src/Connector/RabbitConnector.php
RabbitConnector.exchangeDeclare
protected function exchangeDeclare($exchange, $type = 'direct') { return $this->channel->exchange_declare( $exchange, $type, false, $this->persistent, false ); }
php
protected function exchangeDeclare($exchange, $type = 'direct') { return $this->channel->exchange_declare( $exchange, $type, false, $this->persistent, false ); }
[ "protected", "function", "exchangeDeclare", "(", "$", "exchange", ",", "$", "type", "=", "'direct'", ")", "{", "return", "$", "this", "->", "channel", "->", "exchange_declare", "(", "$", "exchange", ",", "$", "type", ",", "false", ",", "$", "this", "->", "persistent", ",", "false", ")", ";", "}" ]
Declares a new exchange @param string $exchange @param string $type @codeCoverageIgnore
[ "Declares", "a", "new", "exchange" ]
d364d5a1fc3b00d59846b19aa472d7f2aa130ff8
https://github.com/indigophp-archive/queue/blob/d364d5a1fc3b00d59846b19aa472d7f2aa130ff8/src/Connector/RabbitConnector.php#L214-L223
6,781
strident/Trident
src/Trident/Component/Caching/CachingProxy.php
CachingProxy.proxy
public function proxy($key, \Closure $data, $expiration = 0) { if ($this->driver->has($key)) { return $this->driver->get($key); } // Resolve the 'real' data source $data = $data(); // Value wasn't cached, so cache it for next time $this->driver->set($key, $data, $expiration); return $data; }
php
public function proxy($key, \Closure $data, $expiration = 0) { if ($this->driver->has($key)) { return $this->driver->get($key); } // Resolve the 'real' data source $data = $data(); // Value wasn't cached, so cache it for next time $this->driver->set($key, $data, $expiration); return $data; }
[ "public", "function", "proxy", "(", "$", "key", ",", "\\", "Closure", "$", "data", ",", "$", "expiration", "=", "0", ")", "{", "if", "(", "$", "this", "->", "driver", "->", "has", "(", "$", "key", ")", ")", "{", "return", "$", "this", "->", "driver", "->", "get", "(", "$", "key", ")", ";", "}", "// Resolve the 'real' data source", "$", "data", "=", "$", "data", "(", ")", ";", "// Value wasn't cached, so cache it for next time", "$", "this", "->", "driver", "->", "set", "(", "$", "key", ",", "$", "data", ",", "$", "expiration", ")", ";", "return", "$", "data", ";", "}" ]
Get a value, potentially from cache. @param string $key @param Closure $data @return mixed
[ "Get", "a", "value", "potentially", "from", "cache", "." ]
a112f0b75601b897c470a49d85791dc386c29952
https://github.com/strident/Trident/blob/a112f0b75601b897c470a49d85791dc386c29952/src/Trident/Component/Caching/CachingProxy.php#L62-L75
6,782
poliander/rio
src/Rio/Driver/Pdo/Mysql.php
Mysql.getLastErrorMessage
public function getLastErrorMessage() { $message = null; $error = $this->getConnection()->errorInfo(); if (is_array($error) && isset($error[2])) { $message = $error[2]; } return $message; }
php
public function getLastErrorMessage() { $message = null; $error = $this->getConnection()->errorInfo(); if (is_array($error) && isset($error[2])) { $message = $error[2]; } return $message; }
[ "public", "function", "getLastErrorMessage", "(", ")", "{", "$", "message", "=", "null", ";", "$", "error", "=", "$", "this", "->", "getConnection", "(", ")", "->", "errorInfo", "(", ")", ";", "if", "(", "is_array", "(", "$", "error", ")", "&&", "isset", "(", "$", "error", "[", "2", "]", ")", ")", "{", "$", "message", "=", "$", "error", "[", "2", "]", ";", "}", "return", "$", "message", ";", "}" ]
Get last SQL error message @return string|null
[ "Get", "last", "SQL", "error", "message" ]
d760ea6f0b93b88d5ca0b004a800d22359653321
https://github.com/poliander/rio/blob/d760ea6f0b93b88d5ca0b004a800d22359653321/src/Rio/Driver/Pdo/Mysql.php#L138-L148
6,783
etcinit/tutum-php
src/Chromabits/TutumClient/Modules/ContainerModule.php
ContainerModule.show
public function show($uuid) { $response = $this->httpClient->get($this->getResourceUrl($uuid)); return ContainerResponse::createFromHttpResponse($response); }
php
public function show($uuid) { $response = $this->httpClient->get($this->getResourceUrl($uuid)); return ContainerResponse::createFromHttpResponse($response); }
[ "public", "function", "show", "(", "$", "uuid", ")", "{", "$", "response", "=", "$", "this", "->", "httpClient", "->", "get", "(", "$", "this", "->", "getResourceUrl", "(", "$", "uuid", ")", ")", ";", "return", "ContainerResponse", "::", "createFromHttpResponse", "(", "$", "response", ")", ";", "}" ]
Fetch information about a container @param $uuid @return ContainerResponse
[ "Fetch", "information", "about", "a", "container" ]
39fb3375e0d47109a5da70a0e441efb8fd4f4008
https://github.com/etcinit/tutum-php/blob/39fb3375e0d47109a5da70a0e441efb8fd4f4008/src/Chromabits/TutumClient/Modules/ContainerModule.php#L27-L32
6,784
DesignPond/config-registry
src/DesignPond/Registry/RegistryServiceProvider.php
RegistryServiceProvider.registerRegistry
protected function registerRegistry() { $app = app(); $this->app->singleton('registry', function ($app) { $config = $app->config->get('registry', array()); return new Registry($app['db'], $app['registry.cache'], $config); }); }
php
protected function registerRegistry() { $app = app(); $this->app->singleton('registry', function ($app) { $config = $app->config->get('registry', array()); return new Registry($app['db'], $app['registry.cache'], $config); }); }
[ "protected", "function", "registerRegistry", "(", ")", "{", "$", "app", "=", "app", "(", ")", ";", "$", "this", "->", "app", "->", "singleton", "(", "'registry'", ",", "function", "(", "$", "app", ")", "{", "$", "config", "=", "$", "app", "->", "config", "->", "get", "(", "'registry'", ",", "array", "(", ")", ")", ";", "return", "new", "Registry", "(", "$", "app", "[", "'db'", "]", ",", "$", "app", "[", "'registry.cache'", "]", ",", "$", "config", ")", ";", "}", ")", ";", "}" ]
Register the repository. @return void
[ "Register", "the", "repository", "." ]
751247bb6440eef32e35498cae9042067186627c
https://github.com/DesignPond/config-registry/blob/751247bb6440eef32e35498cae9042067186627c/src/DesignPond/Registry/RegistryServiceProvider.php#L41-L53
6,785
DesignPond/config-registry
src/DesignPond/Registry/RegistryServiceProvider.php
RegistryServiceProvider.registerCache
protected function registerCache() { $app = app(); $this->app->singleton('registry.cache', function ($app) { $meta = $app->config->get('registry.cache_path'); $timestampManager = $app->config->get('registry.timestamp_manager'); return new Cache($meta, $timestampManager); }); }
php
protected function registerCache() { $app = app(); $this->app->singleton('registry.cache', function ($app) { $meta = $app->config->get('registry.cache_path'); $timestampManager = $app->config->get('registry.timestamp_manager'); return new Cache($meta, $timestampManager); }); }
[ "protected", "function", "registerCache", "(", ")", "{", "$", "app", "=", "app", "(", ")", ";", "$", "this", "->", "app", "->", "singleton", "(", "'registry.cache'", ",", "function", "(", "$", "app", ")", "{", "$", "meta", "=", "$", "app", "->", "config", "->", "get", "(", "'registry.cache_path'", ")", ";", "$", "timestampManager", "=", "$", "app", "->", "config", "->", "get", "(", "'registry.timestamp_manager'", ")", ";", "return", "new", "Cache", "(", "$", "meta", ",", "$", "timestampManager", ")", ";", "}", ")", ";", "}" ]
Register the cache repository. @return void
[ "Register", "the", "cache", "repository", "." ]
751247bb6440eef32e35498cae9042067186627c
https://github.com/DesignPond/config-registry/blob/751247bb6440eef32e35498cae9042067186627c/src/DesignPond/Registry/RegistryServiceProvider.php#L60-L70
6,786
setrun/setrun-component-sys
src/over/widgets/TimeAgo.php
TimeAgo.registerLocale
protected function registerLocale() { $lang = $this->prepareLang(); if (file_exists(Yii::getAlias($this->getAssetBundle()->sourcePath) . DIRECTORY_SEPARATOR . "locales" . DIRECTORY_SEPARATOR . "jquery.timeago.{$lang}.js")) { $this->getAssetBundle()->js[] = "locales/jquery.timeago.{$lang}.js"; } else { throw new InvalidConfigException("Language '{$lang}' do not exist."); } }
php
protected function registerLocale() { $lang = $this->prepareLang(); if (file_exists(Yii::getAlias($this->getAssetBundle()->sourcePath) . DIRECTORY_SEPARATOR . "locales" . DIRECTORY_SEPARATOR . "jquery.timeago.{$lang}.js")) { $this->getAssetBundle()->js[] = "locales/jquery.timeago.{$lang}.js"; } else { throw new InvalidConfigException("Language '{$lang}' do not exist."); } }
[ "protected", "function", "registerLocale", "(", ")", "{", "$", "lang", "=", "$", "this", "->", "prepareLang", "(", ")", ";", "if", "(", "file_exists", "(", "Yii", "::", "getAlias", "(", "$", "this", "->", "getAssetBundle", "(", ")", "->", "sourcePath", ")", ".", "DIRECTORY_SEPARATOR", ".", "\"locales\"", ".", "DIRECTORY_SEPARATOR", ".", "\"jquery.timeago.{$lang}.js\"", ")", ")", "{", "$", "this", "->", "getAssetBundle", "(", ")", "->", "js", "[", "]", "=", "\"locales/jquery.timeago.{$lang}.js\"", ";", "}", "else", "{", "throw", "new", "InvalidConfigException", "(", "\"Language '{$lang}' do not exist.\"", ")", ";", "}", "}" ]
Registred locale js file.
[ "Registred", "locale", "js", "file", "." ]
ad9a6442a2921e0f061ed4e455b050c56029d565
https://github.com/setrun/setrun-component-sys/blob/ad9a6442a2921e0f061ed4e455b050c56029d565/src/over/widgets/TimeAgo.php#L21-L29
6,787
setrun/setrun-component-sys
src/over/widgets/TimeAgo.php
TimeAgo.prepareLang
protected function prepareLang() { $lang = $this->language; if (strpos($lang, '-') !== false) { $lang = strtolower(explode('-', $lang)[0]); } return $lang; }
php
protected function prepareLang() { $lang = $this->language; if (strpos($lang, '-') !== false) { $lang = strtolower(explode('-', $lang)[0]); } return $lang; }
[ "protected", "function", "prepareLang", "(", ")", "{", "$", "lang", "=", "$", "this", "->", "language", ";", "if", "(", "strpos", "(", "$", "lang", ",", "'-'", ")", "!==", "false", ")", "{", "$", "lang", "=", "strtolower", "(", "explode", "(", "'-'", ",", "$", "lang", ")", "[", "0", "]", ")", ";", "}", "return", "$", "lang", ";", "}" ]
Prepare name of language. @return string
[ "Prepare", "name", "of", "language", "." ]
ad9a6442a2921e0f061ed4e455b050c56029d565
https://github.com/setrun/setrun-component-sys/blob/ad9a6442a2921e0f061ed4e455b050c56029d565/src/over/widgets/TimeAgo.php#L35-L42
6,788
canis-io/yii2-key-provider
lib/KeyPairReference.php
KeyPairReference.getKeyPair
public function getKeyPair() { if (!isset($this->keyPair)) { $keyProviderCollection = KeyProviderCollector::getInstance(); $keyProvider = $keyProviderCollection->getProvider($this->providerId); if (!$keyProvider) { throw new InaccessibleKeyPairException("Key pair provider ({$this->providerId}) has not been loaded in this instance"); } $this->keyPair = $keyProvider->get($this->keyPairId); } return $this->keyPair; }
php
public function getKeyPair() { if (!isset($this->keyPair)) { $keyProviderCollection = KeyProviderCollector::getInstance(); $keyProvider = $keyProviderCollection->getProvider($this->providerId); if (!$keyProvider) { throw new InaccessibleKeyPairException("Key pair provider ({$this->providerId}) has not been loaded in this instance"); } $this->keyPair = $keyProvider->get($this->keyPairId); } return $this->keyPair; }
[ "public", "function", "getKeyPair", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "keyPair", ")", ")", "{", "$", "keyProviderCollection", "=", "KeyProviderCollector", "::", "getInstance", "(", ")", ";", "$", "keyProvider", "=", "$", "keyProviderCollection", "->", "getProvider", "(", "$", "this", "->", "providerId", ")", ";", "if", "(", "!", "$", "keyProvider", ")", "{", "throw", "new", "InaccessibleKeyPairException", "(", "\"Key pair provider ({$this->providerId}) has not been loaded in this instance\"", ")", ";", "}", "$", "this", "->", "keyPair", "=", "$", "keyProvider", "->", "get", "(", "$", "this", "->", "keyPairId", ")", ";", "}", "return", "$", "this", "->", "keyPair", ";", "}" ]
Retrieves the referenced KeyPair from the provider @return \canis\keyProvider\encryption\KeyPairInterface the KeyPair object referenced
[ "Retrieves", "the", "referenced", "KeyPair", "from", "the", "provider" ]
c54f1c8af812bddf48872a05bc1d1e02112decc9
https://github.com/canis-io/yii2-key-provider/blob/c54f1c8af812bddf48872a05bc1d1e02112decc9/lib/KeyPairReference.php#L116-L127
6,789
dazarobbo/Cola
src/Set.php
Set.unique
public function unique(\Closure $compare = null) { if(\is_callable($compare)){ return parent::unique($compare); } return new static(\array_unique($this->_Arr, \SORT_REGULAR)); }
php
public function unique(\Closure $compare = null) { if(\is_callable($compare)){ return parent::unique($compare); } return new static(\array_unique($this->_Arr, \SORT_REGULAR)); }
[ "public", "function", "unique", "(", "\\", "Closure", "$", "compare", "=", "null", ")", "{", "if", "(", "\\", "is_callable", "(", "$", "compare", ")", ")", "{", "return", "parent", "::", "unique", "(", "$", "compare", ")", ";", "}", "return", "new", "static", "(", "\\", "array_unique", "(", "$", "this", "->", "_Arr", ",", "\\", "SORT_REGULAR", ")", ")", ";", "}" ]
Returns a new Set with duplicates removed @param \Closure $compare optional compare function @return \static
[ "Returns", "a", "new", "Set", "with", "duplicates", "removed" ]
b101b73ebeb8a571345a303cbc75168f60d0e64f
https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/Set.php#L62-L70
6,790
subjective-php/util-exceptions
src/Exception.php
Exception.raise
final public static function raise(int $level, string $message, string $file = null, int $line = null) { if (error_reporting() === 0) { return false; } throw new ErrorException($message, 0, $level, $file, $line); }
php
final public static function raise(int $level, string $message, string $file = null, int $line = null) { if (error_reporting() === 0) { return false; } throw new ErrorException($message, 0, $level, $file, $line); }
[ "final", "public", "static", "function", "raise", "(", "int", "$", "level", ",", "string", "$", "message", ",", "string", "$", "file", "=", "null", ",", "int", "$", "line", "=", "null", ")", "{", "if", "(", "error_reporting", "(", ")", "===", "0", ")", "{", "return", "false", ";", "}", "throw", "new", "ErrorException", "(", "$", "message", ",", "0", ",", "$", "level", ",", "$", "file", ",", "$", "line", ")", ";", "}" ]
Throws a new \ErrorException based on the error information provided. @param integer $level The level of the error raised. @param string $message The error message. @param string $file The filename from which the error was raised. @param integer $line The line number at which the error was raised. @return bool false @throws ErrorException Thrown based on information given in parameters.
[ "Throws", "a", "new", "\\", "ErrorException", "based", "on", "the", "error", "information", "provided", "." ]
387139ef7d5facbb4f59cb06156456e3688d6bb4
https://github.com/subjective-php/util-exceptions/blob/387139ef7d5facbb4f59cb06156456e3688d6bb4/src/Exception.php#L41-L48
6,791
subjective-php/util-exceptions
src/Exception.php
Exception.toArray
final public static function toArray(Throwable $throwable, bool $traceAsString = false, int $depth = 512) : array { $result = [ 'type' => get_class($throwable), 'message' => $throwable->getMessage(), 'code' => $throwable->getCode(), 'file' => $throwable->getFile(), 'line' => $throwable->getLine(), 'trace' => $traceAsString ? $throwable->getTraceAsString() : $throwable->getTrace(), 'previous' => null, ]; if ($throwable->getPrevious() !== null && --$depth) { $result['previous'] = self::toArray($throwable->getPrevious(), $traceAsString, $depth); } return $result; }
php
final public static function toArray(Throwable $throwable, bool $traceAsString = false, int $depth = 512) : array { $result = [ 'type' => get_class($throwable), 'message' => $throwable->getMessage(), 'code' => $throwable->getCode(), 'file' => $throwable->getFile(), 'line' => $throwable->getLine(), 'trace' => $traceAsString ? $throwable->getTraceAsString() : $throwable->getTrace(), 'previous' => null, ]; if ($throwable->getPrevious() !== null && --$depth) { $result['previous'] = self::toArray($throwable->getPrevious(), $traceAsString, $depth); } return $result; }
[ "final", "public", "static", "function", "toArray", "(", "Throwable", "$", "throwable", ",", "bool", "$", "traceAsString", "=", "false", ",", "int", "$", "depth", "=", "512", ")", ":", "array", "{", "$", "result", "=", "[", "'type'", "=>", "get_class", "(", "$", "throwable", ")", ",", "'message'", "=>", "$", "throwable", "->", "getMessage", "(", ")", ",", "'code'", "=>", "$", "throwable", "->", "getCode", "(", ")", ",", "'file'", "=>", "$", "throwable", "->", "getFile", "(", ")", ",", "'line'", "=>", "$", "throwable", "->", "getLine", "(", ")", ",", "'trace'", "=>", "$", "traceAsString", "?", "$", "throwable", "->", "getTraceAsString", "(", ")", ":", "$", "throwable", "->", "getTrace", "(", ")", ",", "'previous'", "=>", "null", ",", "]", ";", "if", "(", "$", "throwable", "->", "getPrevious", "(", ")", "!==", "null", "&&", "--", "$", "depth", ")", "{", "$", "result", "[", "'previous'", "]", "=", "self", "::", "toArray", "(", "$", "throwable", "->", "getPrevious", "(", ")", ",", "$", "traceAsString", ",", "$", "depth", ")", ";", "}", "return", "$", "result", ";", "}" ]
Converts the given Exception to an array. @param Throwable $throwable The exception to convert. @param boolean $traceAsString Flag to return the exception trace as a string or array. @param integer $depth User specified recursion depth. @return array
[ "Converts", "the", "given", "Exception", "to", "an", "array", "." ]
387139ef7d5facbb4f59cb06156456e3688d6bb4
https://github.com/subjective-php/util-exceptions/blob/387139ef7d5facbb4f59cb06156456e3688d6bb4/src/Exception.php#L59-L76
6,792
mlocati/composer-patcher
src/PatchCollector.php
PatchCollector.collectPatches
public function collectPatches(RootPackageInterface $rootPackage, array $subPackages) { $collectedPatches = $this->collectPatchesFromPackage($rootPackage); $extra = $rootPackage->getExtra(); if (isset($extra['allow-subpatches'])) { $allowedSubpatches = $extra['allow-subpatches']; if (!is_bool($allowedSubpatches) && !is_array($allowedSubpatches)) { $this->handleException(new Exception\InvalidPackageConfigurationValue($rootPackage, 'extra.allow-subpatches', $allowedSubpatches, 'The extra.allow-subpatches must be a boolean or an array of strings.')); } $collectedPatches->merge($this->collectSubpackagePatches($subPackages, $allowedSubpatches)); } return $collectedPatches; }
php
public function collectPatches(RootPackageInterface $rootPackage, array $subPackages) { $collectedPatches = $this->collectPatchesFromPackage($rootPackage); $extra = $rootPackage->getExtra(); if (isset($extra['allow-subpatches'])) { $allowedSubpatches = $extra['allow-subpatches']; if (!is_bool($allowedSubpatches) && !is_array($allowedSubpatches)) { $this->handleException(new Exception\InvalidPackageConfigurationValue($rootPackage, 'extra.allow-subpatches', $allowedSubpatches, 'The extra.allow-subpatches must be a boolean or an array of strings.')); } $collectedPatches->merge($this->collectSubpackagePatches($subPackages, $allowedSubpatches)); } return $collectedPatches; }
[ "public", "function", "collectPatches", "(", "RootPackageInterface", "$", "rootPackage", ",", "array", "$", "subPackages", ")", "{", "$", "collectedPatches", "=", "$", "this", "->", "collectPatchesFromPackage", "(", "$", "rootPackage", ")", ";", "$", "extra", "=", "$", "rootPackage", "->", "getExtra", "(", ")", ";", "if", "(", "isset", "(", "$", "extra", "[", "'allow-subpatches'", "]", ")", ")", "{", "$", "allowedSubpatches", "=", "$", "extra", "[", "'allow-subpatches'", "]", ";", "if", "(", "!", "is_bool", "(", "$", "allowedSubpatches", ")", "&&", "!", "is_array", "(", "$", "allowedSubpatches", ")", ")", "{", "$", "this", "->", "handleException", "(", "new", "Exception", "\\", "InvalidPackageConfigurationValue", "(", "$", "rootPackage", ",", "'extra.allow-subpatches'", ",", "$", "allowedSubpatches", ",", "'The extra.allow-subpatches must be a boolean or an array of strings.'", ")", ")", ";", "}", "$", "collectedPatches", "->", "merge", "(", "$", "this", "->", "collectSubpackagePatches", "(", "$", "subPackages", ",", "$", "allowedSubpatches", ")", ")", ";", "}", "return", "$", "collectedPatches", ";", "}" ]
Collect the patches. @param \Composer\Package\RootPackageInterface $rootPackage the root composer package @param \Composer\Package\PackageInterface[] $subPackages the dependency packages @return \ComposerPatcher\PatchCollection
[ "Collect", "the", "patches", "." ]
d8ba45c10b5cf8ac8da3591e09b6afd47fc10667
https://github.com/mlocati/composer-patcher/blob/d8ba45c10b5cf8ac8da3591e09b6afd47fc10667/src/PatchCollector.php#L70-L83
6,793
mlocati/composer-patcher
src/PatchCollector.php
PatchCollector.collectSubpackagePatches
protected function collectSubpackagePatches(array $subPackages, $allowedSubpatches) { $collectedPatches = new PatchCollection(); if ($allowedSubpatches !== false && $allowedSubpatches !== array()) { foreach ($subPackages as $subPackage) { if ($allowedSubpatches === true || in_array($subPackage->getName(), $allowedSubpatches, true)) { $collectedPatches->merge($this->collectPatchesFromPackage($subPackage)); } } } return $collectedPatches; }
php
protected function collectSubpackagePatches(array $subPackages, $allowedSubpatches) { $collectedPatches = new PatchCollection(); if ($allowedSubpatches !== false && $allowedSubpatches !== array()) { foreach ($subPackages as $subPackage) { if ($allowedSubpatches === true || in_array($subPackage->getName(), $allowedSubpatches, true)) { $collectedPatches->merge($this->collectPatchesFromPackage($subPackage)); } } } return $collectedPatches; }
[ "protected", "function", "collectSubpackagePatches", "(", "array", "$", "subPackages", ",", "$", "allowedSubpatches", ")", "{", "$", "collectedPatches", "=", "new", "PatchCollection", "(", ")", ";", "if", "(", "$", "allowedSubpatches", "!==", "false", "&&", "$", "allowedSubpatches", "!==", "array", "(", ")", ")", "{", "foreach", "(", "$", "subPackages", "as", "$", "subPackage", ")", "{", "if", "(", "$", "allowedSubpatches", "===", "true", "||", "in_array", "(", "$", "subPackage", "->", "getName", "(", ")", ",", "$", "allowedSubpatches", ",", "true", ")", ")", "{", "$", "collectedPatches", "->", "merge", "(", "$", "this", "->", "collectPatchesFromPackage", "(", "$", "subPackage", ")", ")", ";", "}", "}", "}", "return", "$", "collectedPatches", ";", "}" ]
Collect the patches from the sub-packages. @param \Composer\Package\PackageInterface[] $subPackages the dependency packages @param string[]|bool $allowedSubpatches TRUE to allow any sub-package; FALSE to allow no sub-packages; an array with allowed package names @return \ComposerPatcher\PatchCollection
[ "Collect", "the", "patches", "from", "the", "sub", "-", "packages", "." ]
d8ba45c10b5cf8ac8da3591e09b6afd47fc10667
https://github.com/mlocati/composer-patcher/blob/d8ba45c10b5cf8ac8da3591e09b6afd47fc10667/src/PatchCollector.php#L93-L105
6,794
mlocati/composer-patcher
src/PatchCollector.php
PatchCollector.collectPatchesFromPackage
protected function collectPatchesFromPackage(PackageInterface $package) { $collectedPatches = new PatchCollection(); $extra = $package->getExtra(); if (isset($extra['patches'])) { $this->io->write('<info>Gathering patches from '.$package->getName().' (extra.patches).</info>'); $collectedPatches->merge($this->resolveExplicitList($package, $extra['patches'])); } if (isset($extra['patches-file'])) { $this->io->write('<info>Gathering patches from '.$package->getName().' (extra.patches-file).</info>'); $collectedPatches->merge($this->resolveJsonFile($package, $extra['patches-file'])); } return $collectedPatches; }
php
protected function collectPatchesFromPackage(PackageInterface $package) { $collectedPatches = new PatchCollection(); $extra = $package->getExtra(); if (isset($extra['patches'])) { $this->io->write('<info>Gathering patches from '.$package->getName().' (extra.patches).</info>'); $collectedPatches->merge($this->resolveExplicitList($package, $extra['patches'])); } if (isset($extra['patches-file'])) { $this->io->write('<info>Gathering patches from '.$package->getName().' (extra.patches-file).</info>'); $collectedPatches->merge($this->resolveJsonFile($package, $extra['patches-file'])); } return $collectedPatches; }
[ "protected", "function", "collectPatchesFromPackage", "(", "PackageInterface", "$", "package", ")", "{", "$", "collectedPatches", "=", "new", "PatchCollection", "(", ")", ";", "$", "extra", "=", "$", "package", "->", "getExtra", "(", ")", ";", "if", "(", "isset", "(", "$", "extra", "[", "'patches'", "]", ")", ")", "{", "$", "this", "->", "io", "->", "write", "(", "'<info>Gathering patches from '", ".", "$", "package", "->", "getName", "(", ")", ".", "' (extra.patches).</info>'", ")", ";", "$", "collectedPatches", "->", "merge", "(", "$", "this", "->", "resolveExplicitList", "(", "$", "package", ",", "$", "extra", "[", "'patches'", "]", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "extra", "[", "'patches-file'", "]", ")", ")", "{", "$", "this", "->", "io", "->", "write", "(", "'<info>Gathering patches from '", ".", "$", "package", "->", "getName", "(", ")", ".", "' (extra.patches-file).</info>'", ")", ";", "$", "collectedPatches", "->", "merge", "(", "$", "this", "->", "resolveJsonFile", "(", "$", "package", ",", "$", "extra", "[", "'patches-file'", "]", ")", ")", ";", "}", "return", "$", "collectedPatches", ";", "}" ]
Collect the patches from a package. @param \Composer\Package\PackageInterface $package the package to be inspected @return \ComposerPatcher\PatchCollection
[ "Collect", "the", "patches", "from", "a", "package", "." ]
d8ba45c10b5cf8ac8da3591e09b6afd47fc10667
https://github.com/mlocati/composer-patcher/blob/d8ba45c10b5cf8ac8da3591e09b6afd47fc10667/src/PatchCollector.php#L114-L128
6,795
mlocati/composer-patcher
src/PatchCollector.php
PatchCollector.resolveExplicitList
protected function resolveExplicitList(PackageInterface $package, $patches) { $collectedPatches = new PatchCollection(); if (!is_array($patches)) { $this->handleException(Exception\InvalidPackageConfigurationValue($package, 'extra.patches', $patches, 'The extra.patches configuration must be an array.')); } else { $packageDirectory = $this->installationManager->getInstallPath($package); foreach ($patches as $forPackageHandle => $patchList) { if (!is_array($patchList)) { $this->handleException(Exception\InvalidPackageConfigurationValue($package, 'extra.patches', $package, "The \"{$forPackageHandle}\" value must be an array.")); continue; } foreach ($patchList as $patchDescription => $patchData) { try { list($path, $levels) = $this->extractPatchData($package, $patchData); $localFile = $this->pathResolver->resolve($path, $packageDirectory); if ($localFile === '') { $this->handleException(Exception\InvalidPackageConfigurationValue($package, 'extra.patches', $package, "The path of the \"{$patchDescription}\" patch is empty or is not a string.")); } $collectedPatches->addPatch( new Patch($package, $forPackageHandle, $path, $localFile, $patchDescription, $levels) ); } catch (BaseException $x) { $this->handleException($x); } } } } return $collectedPatches; }
php
protected function resolveExplicitList(PackageInterface $package, $patches) { $collectedPatches = new PatchCollection(); if (!is_array($patches)) { $this->handleException(Exception\InvalidPackageConfigurationValue($package, 'extra.patches', $patches, 'The extra.patches configuration must be an array.')); } else { $packageDirectory = $this->installationManager->getInstallPath($package); foreach ($patches as $forPackageHandle => $patchList) { if (!is_array($patchList)) { $this->handleException(Exception\InvalidPackageConfigurationValue($package, 'extra.patches', $package, "The \"{$forPackageHandle}\" value must be an array.")); continue; } foreach ($patchList as $patchDescription => $patchData) { try { list($path, $levels) = $this->extractPatchData($package, $patchData); $localFile = $this->pathResolver->resolve($path, $packageDirectory); if ($localFile === '') { $this->handleException(Exception\InvalidPackageConfigurationValue($package, 'extra.patches', $package, "The path of the \"{$patchDescription}\" patch is empty or is not a string.")); } $collectedPatches->addPatch( new Patch($package, $forPackageHandle, $path, $localFile, $patchDescription, $levels) ); } catch (BaseException $x) { $this->handleException($x); } } } } return $collectedPatches; }
[ "protected", "function", "resolveExplicitList", "(", "PackageInterface", "$", "package", ",", "$", "patches", ")", "{", "$", "collectedPatches", "=", "new", "PatchCollection", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "patches", ")", ")", "{", "$", "this", "->", "handleException", "(", "Exception", "\\", "InvalidPackageConfigurationValue", "(", "$", "package", ",", "'extra.patches'", ",", "$", "patches", ",", "'The extra.patches configuration must be an array.'", ")", ")", ";", "}", "else", "{", "$", "packageDirectory", "=", "$", "this", "->", "installationManager", "->", "getInstallPath", "(", "$", "package", ")", ";", "foreach", "(", "$", "patches", "as", "$", "forPackageHandle", "=>", "$", "patchList", ")", "{", "if", "(", "!", "is_array", "(", "$", "patchList", ")", ")", "{", "$", "this", "->", "handleException", "(", "Exception", "\\", "InvalidPackageConfigurationValue", "(", "$", "package", ",", "'extra.patches'", ",", "$", "package", ",", "\"The \\\"{$forPackageHandle}\\\" value must be an array.\"", ")", ")", ";", "continue", ";", "}", "foreach", "(", "$", "patchList", "as", "$", "patchDescription", "=>", "$", "patchData", ")", "{", "try", "{", "list", "(", "$", "path", ",", "$", "levels", ")", "=", "$", "this", "->", "extractPatchData", "(", "$", "package", ",", "$", "patchData", ")", ";", "$", "localFile", "=", "$", "this", "->", "pathResolver", "->", "resolve", "(", "$", "path", ",", "$", "packageDirectory", ")", ";", "if", "(", "$", "localFile", "===", "''", ")", "{", "$", "this", "->", "handleException", "(", "Exception", "\\", "InvalidPackageConfigurationValue", "(", "$", "package", ",", "'extra.patches'", ",", "$", "package", ",", "\"The path of the \\\"{$patchDescription}\\\" patch is empty or is not a string.\"", ")", ")", ";", "}", "$", "collectedPatches", "->", "addPatch", "(", "new", "Patch", "(", "$", "package", ",", "$", "forPackageHandle", ",", "$", "path", ",", "$", "localFile", ",", "$", "patchDescription", ",", "$", "levels", ")", ")", ";", "}", "catch", "(", "BaseException", "$", "x", ")", "{", "$", "this", "->", "handleException", "(", "$", "x", ")", ";", "}", "}", "}", "}", "return", "$", "collectedPatches", ";", "}" ]
Collect the patches from the "patches" configuration key. @param \Composer\Package\PackageInterface $package the package being inspected @param array|mixed $patches the extra.patches configuration provided by the package @throws \ComposerPatcher\Exception\InvalidPackageConfigurationValue when $patches is not valid @return \ComposerPatcher\PatchCollection
[ "Collect", "the", "patches", "from", "the", "patches", "configuration", "key", "." ]
d8ba45c10b5cf8ac8da3591e09b6afd47fc10667
https://github.com/mlocati/composer-patcher/blob/d8ba45c10b5cf8ac8da3591e09b6afd47fc10667/src/PatchCollector.php#L140-L170
6,796
mlocati/composer-patcher
src/PatchCollector.php
PatchCollector.extractPatchData
protected function extractPatchData(PackageInterface $package, $patchData) { $levels = null; if (is_string($patchData)) { $path = $patchData; } else { if (!is_array($patchData) || !isset($patchData['path']) || is_string($patchData['path'])) { throw new Exception\InvalidPackageConfigurationValue($package, 'extra.patches.[...]', $package, "The value of a patch must be a string or an array with a 'path' node value."); } $path = $patchData['path']; if (isset($patchData['levels'])) { $levels = $patchData['levels']; if (!is_array($levels) || empty($levels)) { throw new Exception\InvalidPackageConfigurationValue($package, 'extra.patches.[...].levels', $package, 'The patch levels must be an array of strings.'); } } } if ($levels === null) { $levels = $this->getDefaultPatchLevels(); } return array($path, $levels); }
php
protected function extractPatchData(PackageInterface $package, $patchData) { $levels = null; if (is_string($patchData)) { $path = $patchData; } else { if (!is_array($patchData) || !isset($patchData['path']) || is_string($patchData['path'])) { throw new Exception\InvalidPackageConfigurationValue($package, 'extra.patches.[...]', $package, "The value of a patch must be a string or an array with a 'path' node value."); } $path = $patchData['path']; if (isset($patchData['levels'])) { $levels = $patchData['levels']; if (!is_array($levels) || empty($levels)) { throw new Exception\InvalidPackageConfigurationValue($package, 'extra.patches.[...].levels', $package, 'The patch levels must be an array of strings.'); } } } if ($levels === null) { $levels = $this->getDefaultPatchLevels(); } return array($path, $levels); }
[ "protected", "function", "extractPatchData", "(", "PackageInterface", "$", "package", ",", "$", "patchData", ")", "{", "$", "levels", "=", "null", ";", "if", "(", "is_string", "(", "$", "patchData", ")", ")", "{", "$", "path", "=", "$", "patchData", ";", "}", "else", "{", "if", "(", "!", "is_array", "(", "$", "patchData", ")", "||", "!", "isset", "(", "$", "patchData", "[", "'path'", "]", ")", "||", "is_string", "(", "$", "patchData", "[", "'path'", "]", ")", ")", "{", "throw", "new", "Exception", "\\", "InvalidPackageConfigurationValue", "(", "$", "package", ",", "'extra.patches.[...]'", ",", "$", "package", ",", "\"The value of a patch must be a string or an array with a 'path' node value.\"", ")", ";", "}", "$", "path", "=", "$", "patchData", "[", "'path'", "]", ";", "if", "(", "isset", "(", "$", "patchData", "[", "'levels'", "]", ")", ")", "{", "$", "levels", "=", "$", "patchData", "[", "'levels'", "]", ";", "if", "(", "!", "is_array", "(", "$", "levels", ")", "||", "empty", "(", "$", "levels", ")", ")", "{", "throw", "new", "Exception", "\\", "InvalidPackageConfigurationValue", "(", "$", "package", ",", "'extra.patches.[...].levels'", ",", "$", "package", ",", "'The patch levels must be an array of strings.'", ")", ";", "}", "}", "}", "if", "(", "$", "levels", "===", "null", ")", "{", "$", "levels", "=", "$", "this", "->", "getDefaultPatchLevels", "(", ")", ";", "}", "return", "array", "(", "$", "path", ",", "$", "levels", ")", ";", "}" ]
Extract the data of a single patch. @param \Composer\Package\PackageInterface $package the package being inspected @param array|string|mixed $patchData The single patch data @throws \Exception in case of errors @return array
[ "Extract", "the", "data", "of", "a", "single", "patch", "." ]
d8ba45c10b5cf8ac8da3591e09b6afd47fc10667
https://github.com/mlocati/composer-patcher/blob/d8ba45c10b5cf8ac8da3591e09b6afd47fc10667/src/PatchCollector.php#L182-L204
6,797
mlocati/composer-patcher
src/PatchCollector.php
PatchCollector.resolveJsonFile
protected function resolveJsonFile(PackageInterface $package, $jsonPath) { $collectedPatches = new PatchCollection(); if (!is_string($jsonPath) || $jsonPath === '') { $this->handleException(Exception\InvalidPackageConfigurationValue($package(), 'extra.patches-file', $jsonPath, 'The extra.patches-file configuration must be a non empty string.')); } else { $packageDirectory = $this->installationManager->getInstallPath($package); $fullJsonPath = $this->pathResolver->resolve($jsonPath, $packageDirectory); $jsonReader = new JsonFile($fullJsonPath, null, $this->io); $data = $jsonReader->read(); if (!is_array($data)) { $this->handleException(Exception\InvalidPackageConfigurationValue($package, 'extra.patches-file', $jsonPath, "The JSON file at \"{$jsonPath}\" must contain an array.")); } elseif (!isset($data['patches'])) { $this->handleException(Exception\InvalidPackageConfigurationValue($package, 'extra.patches-file', $jsonPath, "The JSON file at \"{$jsonPath}\" must contain an array with a \"patches\" key.")); } else { $collectedPatches->merge($this->resolveExplicitList($package, $data['patches'])); } } return $collectedPatches; }
php
protected function resolveJsonFile(PackageInterface $package, $jsonPath) { $collectedPatches = new PatchCollection(); if (!is_string($jsonPath) || $jsonPath === '') { $this->handleException(Exception\InvalidPackageConfigurationValue($package(), 'extra.patches-file', $jsonPath, 'The extra.patches-file configuration must be a non empty string.')); } else { $packageDirectory = $this->installationManager->getInstallPath($package); $fullJsonPath = $this->pathResolver->resolve($jsonPath, $packageDirectory); $jsonReader = new JsonFile($fullJsonPath, null, $this->io); $data = $jsonReader->read(); if (!is_array($data)) { $this->handleException(Exception\InvalidPackageConfigurationValue($package, 'extra.patches-file', $jsonPath, "The JSON file at \"{$jsonPath}\" must contain an array.")); } elseif (!isset($data['patches'])) { $this->handleException(Exception\InvalidPackageConfigurationValue($package, 'extra.patches-file', $jsonPath, "The JSON file at \"{$jsonPath}\" must contain an array with a \"patches\" key.")); } else { $collectedPatches->merge($this->resolveExplicitList($package, $data['patches'])); } } return $collectedPatches; }
[ "protected", "function", "resolveJsonFile", "(", "PackageInterface", "$", "package", ",", "$", "jsonPath", ")", "{", "$", "collectedPatches", "=", "new", "PatchCollection", "(", ")", ";", "if", "(", "!", "is_string", "(", "$", "jsonPath", ")", "||", "$", "jsonPath", "===", "''", ")", "{", "$", "this", "->", "handleException", "(", "Exception", "\\", "InvalidPackageConfigurationValue", "(", "$", "package", "(", ")", ",", "'extra.patches-file'", ",", "$", "jsonPath", ",", "'The extra.patches-file configuration must be a non empty string.'", ")", ")", ";", "}", "else", "{", "$", "packageDirectory", "=", "$", "this", "->", "installationManager", "->", "getInstallPath", "(", "$", "package", ")", ";", "$", "fullJsonPath", "=", "$", "this", "->", "pathResolver", "->", "resolve", "(", "$", "jsonPath", ",", "$", "packageDirectory", ")", ";", "$", "jsonReader", "=", "new", "JsonFile", "(", "$", "fullJsonPath", ",", "null", ",", "$", "this", "->", "io", ")", ";", "$", "data", "=", "$", "jsonReader", "->", "read", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "data", ")", ")", "{", "$", "this", "->", "handleException", "(", "Exception", "\\", "InvalidPackageConfigurationValue", "(", "$", "package", ",", "'extra.patches-file'", ",", "$", "jsonPath", ",", "\"The JSON file at \\\"{$jsonPath}\\\" must contain an array.\"", ")", ")", ";", "}", "elseif", "(", "!", "isset", "(", "$", "data", "[", "'patches'", "]", ")", ")", "{", "$", "this", "->", "handleException", "(", "Exception", "\\", "InvalidPackageConfigurationValue", "(", "$", "package", ",", "'extra.patches-file'", ",", "$", "jsonPath", ",", "\"The JSON file at \\\"{$jsonPath}\\\" must contain an array with a \\\"patches\\\" key.\"", ")", ")", ";", "}", "else", "{", "$", "collectedPatches", "->", "merge", "(", "$", "this", "->", "resolveExplicitList", "(", "$", "package", ",", "$", "data", "[", "'patches'", "]", ")", ")", ";", "}", "}", "return", "$", "collectedPatches", ";", "}" ]
Collect the patches from the "patches-file" configuration key. @param \Composer\Package\PackageInterface $package the package being inspected @param string|mixed $jsonPath the extra.patches-file configuration provided by the package @throws \ComposerPatcher\Exception\InvalidPackageConfigurationValue when $jsonPath is not valid @return \ComposerPatcher\PatchCollection
[ "Collect", "the", "patches", "from", "the", "patches", "-", "file", "configuration", "key", "." ]
d8ba45c10b5cf8ac8da3591e09b6afd47fc10667
https://github.com/mlocati/composer-patcher/blob/d8ba45c10b5cf8ac8da3591e09b6afd47fc10667/src/PatchCollector.php#L216-L236
6,798
silverorange/Net_Notifier
Net/Notifier/WebSocket/Handshake.php
Net_Notifier_WebSocket_Handshake.start
public function start( $host, $port, $nonce, $resource = '/', array $protocols = array() ) { $version = Net_Notifier_WebSocket_Handshake::VERSION; $request = "GET " . $resource . " HTTP/1.1\r\n" . "Host: " . $host . "\r\n" . "Connection: Upgrade\r\n" . "Upgrade: websocket\r\n" . "Sec-WebSocket-Key: " . $nonce . "\r\n" . "Sec-WebSocket-Version: " . $version . "\r\n"; if (count($protocols) > 0) { $protocols = implode(',', $protocols); $request .= "Sec-WebSocket-Protocol: " . $protocols . "\r\n"; } $request .= "\r\n"; return $request; }
php
public function start( $host, $port, $nonce, $resource = '/', array $protocols = array() ) { $version = Net_Notifier_WebSocket_Handshake::VERSION; $request = "GET " . $resource . " HTTP/1.1\r\n" . "Host: " . $host . "\r\n" . "Connection: Upgrade\r\n" . "Upgrade: websocket\r\n" . "Sec-WebSocket-Key: " . $nonce . "\r\n" . "Sec-WebSocket-Version: " . $version . "\r\n"; if (count($protocols) > 0) { $protocols = implode(',', $protocols); $request .= "Sec-WebSocket-Protocol: " . $protocols . "\r\n"; } $request .= "\r\n"; return $request; }
[ "public", "function", "start", "(", "$", "host", ",", "$", "port", ",", "$", "nonce", ",", "$", "resource", "=", "'/'", ",", "array", "$", "protocols", "=", "array", "(", ")", ")", "{", "$", "version", "=", "Net_Notifier_WebSocket_Handshake", "::", "VERSION", ";", "$", "request", "=", "\"GET \"", ".", "$", "resource", ".", "\" HTTP/1.1\\r\\n\"", ".", "\"Host: \"", ".", "$", "host", ".", "\"\\r\\n\"", ".", "\"Connection: Upgrade\\r\\n\"", ".", "\"Upgrade: websocket\\r\\n\"", ".", "\"Sec-WebSocket-Key: \"", ".", "$", "nonce", ".", "\"\\r\\n\"", ".", "\"Sec-WebSocket-Version: \"", ".", "$", "version", ".", "\"\\r\\n\"", ";", "if", "(", "count", "(", "$", "protocols", ")", ">", "0", ")", "{", "$", "protocols", "=", "implode", "(", "','", ",", "$", "protocols", ")", ";", "$", "request", ".=", "\"Sec-WebSocket-Protocol: \"", ".", "$", "protocols", ".", "\"\\r\\n\"", ";", "}", "$", "request", ".=", "\"\\r\\n\"", ";", "return", "$", "request", ";", "}" ]
Initiates a WebSocket handshake @param string $host the server host name or IP address. @param integer $port the server connection port. @param string $nonce the nonce value used to validate this handshake. @param string $resource optional. The WebSocket resource name. @param array $protocols optional. A list of requested application- specific sub-protocols. If this array is specified, only handshake requests for the specified protocols will succeed. @return string the HTTP GET request data for initiating a WebSocket handshake for a WebSocket client.
[ "Initiates", "a", "WebSocket", "handshake" ]
b446e27cd1bebd58ba89243cde1272c5d281d3fb
https://github.com/silverorange/Net_Notifier/blob/b446e27cd1bebd58ba89243cde1272c5d281d3fb/Net/Notifier/WebSocket/Handshake.php#L86-L111
6,799
silverorange/Net_Notifier
Net/Notifier/WebSocket/Handshake.php
Net_Notifier_WebSocket_Handshake.receive
public function receive($data, $nonce, array $protocols = array()) { $handshake = $this->parseHeaders($data); $headers = $handshake['headers']; // get status code from status line $status_parts = explode(' ', $handshake['status']); if (count($status_parts) > 1) { $status = (integer)$status_parts[1]; } else { $status = 400; } // get method from status line $method = $status_parts[0]; if ($status == '101') { $response = $this->receiveServerHandshake( $headers, $nonce, $protocols ); } elseif ($method === 'GET') { $response = $this->receiveClientHandshake($headers, $protocols); } else { $response = "HTTP/1.1 400 Bad Request\r\n\r\n"; } return $response; }
php
public function receive($data, $nonce, array $protocols = array()) { $handshake = $this->parseHeaders($data); $headers = $handshake['headers']; // get status code from status line $status_parts = explode(' ', $handshake['status']); if (count($status_parts) > 1) { $status = (integer)$status_parts[1]; } else { $status = 400; } // get method from status line $method = $status_parts[0]; if ($status == '101') { $response = $this->receiveServerHandshake( $headers, $nonce, $protocols ); } elseif ($method === 'GET') { $response = $this->receiveClientHandshake($headers, $protocols); } else { $response = "HTTP/1.1 400 Bad Request\r\n\r\n"; } return $response; }
[ "public", "function", "receive", "(", "$", "data", ",", "$", "nonce", ",", "array", "$", "protocols", "=", "array", "(", ")", ")", "{", "$", "handshake", "=", "$", "this", "->", "parseHeaders", "(", "$", "data", ")", ";", "$", "headers", "=", "$", "handshake", "[", "'headers'", "]", ";", "// get status code from status line", "$", "status_parts", "=", "explode", "(", "' '", ",", "$", "handshake", "[", "'status'", "]", ")", ";", "if", "(", "count", "(", "$", "status_parts", ")", ">", "1", ")", "{", "$", "status", "=", "(", "integer", ")", "$", "status_parts", "[", "1", "]", ";", "}", "else", "{", "$", "status", "=", "400", ";", "}", "// get method from status line", "$", "method", "=", "$", "status_parts", "[", "0", "]", ";", "if", "(", "$", "status", "==", "'101'", ")", "{", "$", "response", "=", "$", "this", "->", "receiveServerHandshake", "(", "$", "headers", ",", "$", "nonce", ",", "$", "protocols", ")", ";", "}", "elseif", "(", "$", "method", "===", "'GET'", ")", "{", "$", "response", "=", "$", "this", "->", "receiveClientHandshake", "(", "$", "headers", ",", "$", "protocols", ")", ";", "}", "else", "{", "$", "response", "=", "\"HTTP/1.1 400 Bad Request\\r\\n\\r\\n\"", ";", "}", "return", "$", "response", ";", "}" ]
Does the actual WebSocket handshake See section 4.2.2 of {@link http://datatracker.ietf.org/doc/rfc6455/ IETF RFC 6455} for further details. @param string $data the handshake request/response data. @param string $nonce the nonce value used to validate this handshake. Not set for receiving client handshake requests. @param array $protocols optional. A list of supported or requested application-specific sub-protocols. If specified, only handshake requests for the specified protocols will succeed. @return string|null the handshake response or null if there is no response. @throws Net_Notifier_WebSocket_HandshakeFailureException if the handshake fails. @todo Handle 4XX responses from server properly on client.
[ "Does", "the", "actual", "WebSocket", "handshake" ]
b446e27cd1bebd58ba89243cde1272c5d281d3fb
https://github.com/silverorange/Net_Notifier/blob/b446e27cd1bebd58ba89243cde1272c5d281d3fb/Net/Notifier/WebSocket/Handshake.php#L139-L168