repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
krizalys/onedrive-php-sdk
src/Client.php
Client.fetchProperties
public function fetchProperties($driveItemId = null) { $message = sprintf( '%s() is deprecated and will be removed in version 3;' . ' use Krizalys\Onedrive\Client::getDriveItemById() instead', __METHOD__ ); @trigger_error($message, E_USER_DEPRECATED); $drive = $this->getMyDrive(); $item = $driveItemId !== null ? $this->getDriveItemById($drive->id, $driveItemId) : $drive->getRoot(); $options = $this->buildOptions( $item, [ 'id' => $item->id, 'parent_id' => $driveItemId, ] ); return (object) $options; }
php
public function fetchProperties($driveItemId = null) { $message = sprintf( '%s() is deprecated and will be removed in version 3;' . ' use Krizalys\Onedrive\Client::getDriveItemById() instead', __METHOD__ ); @trigger_error($message, E_USER_DEPRECATED); $drive = $this->getMyDrive(); $item = $driveItemId !== null ? $this->getDriveItemById($drive->id, $driveItemId) : $drive->getRoot(); $options = $this->buildOptions( $item, [ 'id' => $item->id, 'parent_id' => $driveItemId, ] ); return (object) $options; }
[ "public", "function", "fetchProperties", "(", "$", "driveItemId", "=", "null", ")", "{", "$", "message", "=", "sprintf", "(", "'%s() is deprecated and will be removed in version 3;'", ".", "' use Krizalys\\Onedrive\\Client::getDriveItemById() instead'", ",", "__METHOD__", ")"...
Fetches the properties of a drive item in the current OneDrive account. @param null|string $driveItemId The drive item ID, or null to fetch the OneDrive root folder. Default: null. @return object The properties of the drive item fetched. @deprecated Use Krizalys\Onedrive\Client::getDriveItemById() instead.
[ "Fetches", "the", "properties", "of", "a", "drive", "item", "in", "the", "current", "OneDrive", "account", "." ]
80fd1be8e149190e44dd5a055bad09bafda2c330
https://github.com/krizalys/onedrive-php-sdk/blob/80fd1be8e149190e44dd5a055bad09bafda2c330/src/Client.php#L881-L905
train
krizalys/onedrive-php-sdk
src/Client.php
Client.fetchDriveItems
public function fetchDriveItems($driveItemId = null) { $message = sprintf( '%s() is deprecated and will be removed in version 3;' . ' use Krizalys\Onedrive\Proxy\DriveItemProxy::children' . ' instead.', __METHOD__ ); @trigger_error($message, E_USER_DEPRECATED); $drive = $this->getMyDrive(); $item = $driveItemId !== null ? $this->getDriveItemById($drive->id, $driveItemId) : $drive->getRoot(); return array_map(function (DriveItemProxy $item) use ($driveItemId) { $options = $this->buildOptions($item, ['parent_id' => $driveItemId]); return $this->isFolder($item) ? new Folder($this, $item->id, $options) : new File($this, $item->id, $options); }, $item->children); }
php
public function fetchDriveItems($driveItemId = null) { $message = sprintf( '%s() is deprecated and will be removed in version 3;' . ' use Krizalys\Onedrive\Proxy\DriveItemProxy::children' . ' instead.', __METHOD__ ); @trigger_error($message, E_USER_DEPRECATED); $drive = $this->getMyDrive(); $item = $driveItemId !== null ? $this->getDriveItemById($drive->id, $driveItemId) : $drive->getRoot(); return array_map(function (DriveItemProxy $item) use ($driveItemId) { $options = $this->buildOptions($item, ['parent_id' => $driveItemId]); return $this->isFolder($item) ? new Folder($this, $item->id, $options) : new File($this, $item->id, $options); }, $item->children); }
[ "public", "function", "fetchDriveItems", "(", "$", "driveItemId", "=", "null", ")", "{", "$", "message", "=", "sprintf", "(", "'%s() is deprecated and will be removed in version 3;'", ".", "' use Krizalys\\Onedrive\\Proxy\\DriveItemProxy::children'", ".", "' instead.'", ",", ...
Fetches the drive items in a folder in the current OneDrive account. @param null|string $driveItemId The drive item ID, or null to fetch the OneDrive root folder. Default: null. @return array The drive items in the folder fetched, as DriveItem instances referencing OneDrive drive items. @deprecated Use Krizalys\Onedrive\Proxy\DriveItemProxy::children instead.
[ "Fetches", "the", "drive", "items", "in", "a", "folder", "in", "the", "current", "OneDrive", "account", "." ]
80fd1be8e149190e44dd5a055bad09bafda2c330
https://github.com/krizalys/onedrive-php-sdk/blob/80fd1be8e149190e44dd5a055bad09bafda2c330/src/Client.php#L921-L944
train
krizalys/onedrive-php-sdk
src/Client.php
Client.updateDriveItem
public function updateDriveItem($driveItemId, $properties = [], $temp = false) { $message = sprintf( '%s() is deprecated and will be removed in version 3;' . ' use Krizalys\Onedrive\Proxy\DriveItemProxy::rename()' . ' instead', __METHOD__ ); @trigger_error($message, E_USER_DEPRECATED); $drive = $this->getMyDrive(); $item = $driveItemId !== null ? $this->getDriveItemById($drive->id, $driveItemId) : $drive->getRoot(); $options = (array) $properties; if (array_key_exists('name', $options)) { $name = $options['name']; unset($options['name']); } else { $name = $item->name; } $item = $item->rename($name, $options); $options = $this->buildOptions($item, ['parent_id' => $driveItemId]); return new Folder($this, $item->id, $options); }
php
public function updateDriveItem($driveItemId, $properties = [], $temp = false) { $message = sprintf( '%s() is deprecated and will be removed in version 3;' . ' use Krizalys\Onedrive\Proxy\DriveItemProxy::rename()' . ' instead', __METHOD__ ); @trigger_error($message, E_USER_DEPRECATED); $drive = $this->getMyDrive(); $item = $driveItemId !== null ? $this->getDriveItemById($drive->id, $driveItemId) : $drive->getRoot(); $options = (array) $properties; if (array_key_exists('name', $options)) { $name = $options['name']; unset($options['name']); } else { $name = $item->name; } $item = $item->rename($name, $options); $options = $this->buildOptions($item, ['parent_id' => $driveItemId]); return new Folder($this, $item->id, $options); }
[ "public", "function", "updateDriveItem", "(", "$", "driveItemId", ",", "$", "properties", "=", "[", "]", ",", "$", "temp", "=", "false", ")", "{", "$", "message", "=", "sprintf", "(", "'%s() is deprecated and will be removed in version 3;'", ".", "' use Krizalys\\...
Updates the properties of a drive item in the current OneDrive account. @param string $driveItemId The unique ID of the drive item to update. @param array|object $properties The properties to update. Default: []. @param bool $temp Option to allow save to a temporary file in case of large files. @throws Exception Thrown on I/O errors. @deprecated Use Krizalys\Onedrive\Proxy\DriveItemProxy::rename() instead.
[ "Updates", "the", "properties", "of", "a", "drive", "item", "in", "the", "current", "OneDrive", "account", "." ]
80fd1be8e149190e44dd5a055bad09bafda2c330
https://github.com/krizalys/onedrive-php-sdk/blob/80fd1be8e149190e44dd5a055bad09bafda2c330/src/Client.php#L961-L990
train
krizalys/onedrive-php-sdk
src/Client.php
Client.moveDriveItem
public function moveDriveItem($driveItemId, $destinationId = null) { $message = sprintf( '%s() is deprecated and will be removed in version 3;' . ' use Krizalys\Onedrive\Proxy\DriveItemProxy::move()' . ' instead.', __METHOD__ ); @trigger_error($message, E_USER_DEPRECATED); $drive = $this->getMyDrive(); $item = $this->getDriveItemById($drive->id, $driveItemId); $destination = $destinationId !== null ? $this->getDriveItemById($drive->id, $destinationId) : $drive->getRoot(); $item->move($destination); }
php
public function moveDriveItem($driveItemId, $destinationId = null) { $message = sprintf( '%s() is deprecated and will be removed in version 3;' . ' use Krizalys\Onedrive\Proxy\DriveItemProxy::move()' . ' instead.', __METHOD__ ); @trigger_error($message, E_USER_DEPRECATED); $drive = $this->getMyDrive(); $item = $this->getDriveItemById($drive->id, $driveItemId); $destination = $destinationId !== null ? $this->getDriveItemById($drive->id, $destinationId) : $drive->getRoot(); $item->move($destination); }
[ "public", "function", "moveDriveItem", "(", "$", "driveItemId", ",", "$", "destinationId", "=", "null", ")", "{", "$", "message", "=", "sprintf", "(", "'%s() is deprecated and will be removed in version 3;'", ".", "' use Krizalys\\Onedrive\\Proxy\\DriveItemProxy::move()'", ...
Moves a drive item into another folder. @param string $driveItemId The unique ID of the drive item to move. @param null|string $destinationId The unique ID of the folder into which to move the drive item, or null to move it to the OneDrive root folder. Default: null. @deprecated Use Krizalys\Onedrive\Proxy\DriveItemProxy::move() instead.
[ "Moves", "a", "drive", "item", "into", "another", "folder", "." ]
80fd1be8e149190e44dd5a055bad09bafda2c330
https://github.com/krizalys/onedrive-php-sdk/blob/80fd1be8e149190e44dd5a055bad09bafda2c330/src/Client.php#L1003-L1021
train
krizalys/onedrive-php-sdk
src/Client.php
Client.deleteDriveItem
public function deleteDriveItem($driveItemId) { $message = sprintf( '%s() is deprecated and will be removed in version 3;' . ' use Krizalys\Onedrive\Proxy\DriveItemProxy::delete()' . ' instead', __METHOD__ ); @trigger_error($message, E_USER_DEPRECATED); $drive = $this->getMyDrive(); $item = $this->getDriveItemById($drive->id, $driveItemId); $item->delete(); }
php
public function deleteDriveItem($driveItemId) { $message = sprintf( '%s() is deprecated and will be removed in version 3;' . ' use Krizalys\Onedrive\Proxy\DriveItemProxy::delete()' . ' instead', __METHOD__ ); @trigger_error($message, E_USER_DEPRECATED); $drive = $this->getMyDrive(); $item = $this->getDriveItemById($drive->id, $driveItemId); $item->delete(); }
[ "public", "function", "deleteDriveItem", "(", "$", "driveItemId", ")", "{", "$", "message", "=", "sprintf", "(", "'%s() is deprecated and will be removed in version 3;'", ".", "' use Krizalys\\Onedrive\\Proxy\\DriveItemProxy::delete()'", ".", "' instead'", ",", "__METHOD__", ...
Deletes a drive item in the current OneDrive account. @param string $driveItemId The unique ID of the drive item to delete. @deprecated Use Krizalys\Onedrive\Proxy\DriveItemProxy::delete() instead.
[ "Deletes", "a", "drive", "item", "in", "the", "current", "OneDrive", "account", "." ]
80fd1be8e149190e44dd5a055bad09bafda2c330
https://github.com/krizalys/onedrive-php-sdk/blob/80fd1be8e149190e44dd5a055bad09bafda2c330/src/Client.php#L1063-L1076
train
krizalys/onedrive-php-sdk
src/Client.php
Client.fetchQuota
public function fetchQuota() { $message = sprintf( '%s() is deprecated and will be removed in version 3;' . ' use Krizalys\Onedrive\Proxy\DriveProxy::quota instead', __METHOD__ ); @trigger_error($message, E_USER_DEPRECATED); $drive = $this->getMyDrive(); $quota = $drive->quota; return (object) [ 'quota' => $quota->total, 'available' => $quota->remaining, ]; }
php
public function fetchQuota() { $message = sprintf( '%s() is deprecated and will be removed in version 3;' . ' use Krizalys\Onedrive\Proxy\DriveProxy::quota instead', __METHOD__ ); @trigger_error($message, E_USER_DEPRECATED); $drive = $this->getMyDrive(); $quota = $drive->quota; return (object) [ 'quota' => $quota->total, 'available' => $quota->remaining, ]; }
[ "public", "function", "fetchQuota", "(", ")", "{", "$", "message", "=", "sprintf", "(", "'%s() is deprecated and will be removed in version 3;'", ".", "' use Krizalys\\Onedrive\\Proxy\\DriveProxy::quota instead'", ",", "__METHOD__", ")", ";", "@", "trigger_error", "(", "$",...
Fetches the quota of the current OneDrive account. @return object An object with the following properties: - 'quota' (int) The total space, in bytes. - 'available' (int) The available space, in bytes. @deprecated Use Krizalys\Onedrive\Proxy\DriveProxy::quota instead.
[ "Fetches", "the", "quota", "of", "the", "current", "OneDrive", "account", "." ]
80fd1be8e149190e44dd5a055bad09bafda2c330
https://github.com/krizalys/onedrive-php-sdk/blob/80fd1be8e149190e44dd5a055bad09bafda2c330/src/Client.php#L1088-L1104
train
krizalys/onedrive-php-sdk
src/Client.php
Client.fetchRecentDocs
public function fetchRecentDocs() { $message = sprintf( '%s() is deprecated and will be removed in version 3;' . ' use Krizalys\Onedrive\Client::getRecent() instead', __METHOD__ ); @trigger_error($message, E_USER_DEPRECATED); $items = $this->getRecent(); return (object) [ 'data' => array_map(function (DriveItemProxy $item) { return (object) $this->buildOptions($item); }, $items), ]; }
php
public function fetchRecentDocs() { $message = sprintf( '%s() is deprecated and will be removed in version 3;' . ' use Krizalys\Onedrive\Client::getRecent() instead', __METHOD__ ); @trigger_error($message, E_USER_DEPRECATED); $items = $this->getRecent(); return (object) [ 'data' => array_map(function (DriveItemProxy $item) { return (object) $this->buildOptions($item); }, $items), ]; }
[ "public", "function", "fetchRecentDocs", "(", ")", "{", "$", "message", "=", "sprintf", "(", "'%s() is deprecated and will be removed in version 3;'", ".", "' use Krizalys\\Onedrive\\Client::getRecent() instead'", ",", "__METHOD__", ")", ";", "@", "trigger_error", "(", "$",...
Fetches the recent documents uploaded to the current OneDrive account. @return object An object with the following properties: - 'data' (array) The list of the recent documents uploaded. @deprecated Use Krizalys\Onedrive\Client::getRecent() instead.
[ "Fetches", "the", "recent", "documents", "uploaded", "to", "the", "current", "OneDrive", "account", "." ]
80fd1be8e149190e44dd5a055bad09bafda2c330
https://github.com/krizalys/onedrive-php-sdk/blob/80fd1be8e149190e44dd5a055bad09bafda2c330/src/Client.php#L1115-L1131
train
krizalys/onedrive-php-sdk
src/Client.php
Client.fetchShared
public function fetchShared() { $message = sprintf( '%s() is deprecated and will be removed in version 3;' . ' use Krizalys\Onedrive\Client::getShared() instead', __METHOD__ ); @trigger_error($message, E_USER_DEPRECATED); $items = $this->getShared(); return (object) [ 'data' => array_map(function (DriveItemProxy $item) { return (object) $this->buildOptions($item); }, $items), ]; }
php
public function fetchShared() { $message = sprintf( '%s() is deprecated and will be removed in version 3;' . ' use Krizalys\Onedrive\Client::getShared() instead', __METHOD__ ); @trigger_error($message, E_USER_DEPRECATED); $items = $this->getShared(); return (object) [ 'data' => array_map(function (DriveItemProxy $item) { return (object) $this->buildOptions($item); }, $items), ]; }
[ "public", "function", "fetchShared", "(", ")", "{", "$", "message", "=", "sprintf", "(", "'%s() is deprecated and will be removed in version 3;'", ".", "' use Krizalys\\Onedrive\\Client::getShared() instead'", ",", "__METHOD__", ")", ";", "@", "trigger_error", "(", "$", "...
Fetches the drive items shared with the current OneDrive account. @return object An object with the following properties: - 'data' (array) The list of the shared drive items. @deprecated Use Krizalys\Onedrive\Client::getShared() instead.
[ "Fetches", "the", "drive", "items", "shared", "with", "the", "current", "OneDrive", "account", "." ]
80fd1be8e149190e44dd5a055bad09bafda2c330
https://github.com/krizalys/onedrive-php-sdk/blob/80fd1be8e149190e44dd5a055bad09bafda2c330/src/Client.php#L1142-L1158
train
krizalys/onedrive-php-sdk
src/File.php
File.fetchContent
public function fetchContent(array $options = []) { $client = $this->_client; $message = sprintf( '%s() is deprecated and will be removed in version 3;' . ' use Krizalys\Onedrive\Proxy\DriveItemProxy::content' . ' instead.', __METHOD__ ); @trigger_error($message, E_USER_DEPRECATED); $drive = $client->getMyDrive(); $item = $client->getDriveItemById($drive->id, $this->_id); return (string) $item->content; }
php
public function fetchContent(array $options = []) { $client = $this->_client; $message = sprintf( '%s() is deprecated and will be removed in version 3;' . ' use Krizalys\Onedrive\Proxy\DriveItemProxy::content' . ' instead.', __METHOD__ ); @trigger_error($message, E_USER_DEPRECATED); $drive = $client->getMyDrive(); $item = $client->getDriveItemById($drive->id, $this->_id); return (string) $item->content; }
[ "public", "function", "fetchContent", "(", "array", "$", "options", "=", "[", "]", ")", "{", "$", "client", "=", "$", "this", "->", "_client", ";", "$", "message", "=", "sprintf", "(", "'%s() is deprecated and will be removed in version 3;'", ".", "' use Krizaly...
Fetches the content of the OneDrive file referenced by this File instance. @param array $options Extra cURL options to apply. @return string The content of the OneDrive file referenced by this File instance. @todo Should somewhat return the content-type as well; this information is not disclosed by OneDrive. @deprecated Use Krizalys\Onedrive\Proxy\DriveItemProxy::content instead.
[ "Fetches", "the", "content", "of", "the", "OneDrive", "file", "referenced", "by", "this", "File", "instance", "." ]
80fd1be8e149190e44dd5a055bad09bafda2c330
https://github.com/krizalys/onedrive-php-sdk/blob/80fd1be8e149190e44dd5a055bad09bafda2c330/src/File.php#L48-L64
train
duncan3dc/speaker
src/Providers/AcapelaProvider.php
AcapelaProvider.getVoice
private function getVoice(string $voice): string { $voice = trim($voice); if (strlen($voice) < 3) { throw new InvalidArgumentException("Unexpected voice name ({$voice}), names should be at least 3 characters long"); } return strtolower($voice); }
php
private function getVoice(string $voice): string { $voice = trim($voice); if (strlen($voice) < 3) { throw new InvalidArgumentException("Unexpected voice name ({$voice}), names should be at least 3 characters long"); } return strtolower($voice); }
[ "private", "function", "getVoice", "(", "string", "$", "voice", ")", ":", "string", "{", "$", "voice", "=", "trim", "(", "$", "voice", ")", ";", "if", "(", "strlen", "(", "$", "voice", ")", "<", "3", ")", "{", "throw", "new", "InvalidArgumentExceptio...
Check if the voce is valid, and convert it to the required format. @param string $voice The voice to use @return string
[ "Check", "if", "the", "voce", "is", "valid", "and", "convert", "it", "to", "the", "required", "format", "." ]
17c2f8cba5c702b7495e76aa80a18250b1ce895c
https://github.com/duncan3dc/speaker/blob/17c2f8cba5c702b7495e76aa80a18250b1ce895c/src/Providers/AcapelaProvider.php#L73-L81
train
duncan3dc/speaker
src/Providers/AcapelaProvider.php
AcapelaProvider.withVoice
public function withVoice(string $voice): self { $provider = clone $this; $provider->voice = $this->getVoice($voice); return $provider; }
php
public function withVoice(string $voice): self { $provider = clone $this; $provider->voice = $this->getVoice($voice); return $provider; }
[ "public", "function", "withVoice", "(", "string", "$", "voice", ")", ":", "self", "{", "$", "provider", "=", "clone", "$", "this", ";", "$", "provider", "->", "voice", "=", "$", "this", "->", "getVoice", "(", "$", "voice", ")", ";", "return", "$", ...
Set the voice to use. Visit http://www.acapela-vaas.com/ReleasedDocumentation/voices_list.php for available voices @param string $voice The voice to use (eg 'Graham') @return self
[ "Set", "the", "voice", "to", "use", "." ]
17c2f8cba5c702b7495e76aa80a18250b1ce895c
https://github.com/duncan3dc/speaker/blob/17c2f8cba5c702b7495e76aa80a18250b1ce895c/src/Providers/AcapelaProvider.php#L93-L100
train
duncan3dc/speaker
src/Providers/AcapelaProvider.php
AcapelaProvider.withSpeed
public function withSpeed(int $speed): self { $provider = clone $this; $provider->speed = $this->getSpeed($speed); return $provider; }
php
public function withSpeed(int $speed): self { $provider = clone $this; $provider->speed = $this->getSpeed($speed); return $provider; }
[ "public", "function", "withSpeed", "(", "int", "$", "speed", ")", ":", "self", "{", "$", "provider", "=", "clone", "$", "this", ";", "$", "provider", "->", "speed", "=", "$", "this", "->", "getSpeed", "(", "$", "speed", ")", ";", "return", "$", "pr...
Set the speech rate to use. @param int $speed The speech rate to use (between 60 and 360) @return self
[ "Set", "the", "speech", "rate", "to", "use", "." ]
17c2f8cba5c702b7495e76aa80a18250b1ce895c
https://github.com/duncan3dc/speaker/blob/17c2f8cba5c702b7495e76aa80a18250b1ce895c/src/Providers/AcapelaProvider.php#L127-L134
train
duncan3dc/speaker
src/Providers/ResponsiveVoiceProvider.php
ResponsiveVoiceProvider.withLanguage
public function withLanguage(string $language): self { $provider = clone $this; $provider->language = $this->getLanguage($language); return $provider; }
php
public function withLanguage(string $language): self { $provider = clone $this; $provider->language = $this->getLanguage($language); return $provider; }
[ "public", "function", "withLanguage", "(", "string", "$", "language", ")", ":", "self", "{", "$", "provider", "=", "clone", "$", "this", ";", "$", "provider", "->", "language", "=", "$", "this", "->", "getLanguage", "(", "$", "language", ")", ";", "ret...
Set the language to use. @param string $language The language to use (eg 'en') @return self
[ "Set", "the", "language", "to", "use", "." ]
17c2f8cba5c702b7495e76aa80a18250b1ce895c
https://github.com/duncan3dc/speaker/blob/17c2f8cba5c702b7495e76aa80a18250b1ce895c/src/Providers/ResponsiveVoiceProvider.php#L69-L76
train
duncan3dc/speaker
src/Providers/AbstractProvider.php
AbstractProvider.getClient
public function getClient(): ClientInterface { if ($this->client === null) { $this->client = new Client(); } return $this->client; }
php
public function getClient(): ClientInterface { if ($this->client === null) { $this->client = new Client(); } return $this->client; }
[ "public", "function", "getClient", "(", ")", ":", "ClientInterface", "{", "if", "(", "$", "this", "->", "client", "===", "null", ")", "{", "$", "this", "->", "client", "=", "new", "Client", "(", ")", ";", "}", "return", "$", "this", "->", "client", ...
Get the guzzle client. @return ClientInterface
[ "Get", "the", "guzzle", "client", "." ]
17c2f8cba5c702b7495e76aa80a18250b1ce895c
https://github.com/duncan3dc/speaker/blob/17c2f8cba5c702b7495e76aa80a18250b1ce895c/src/Providers/AbstractProvider.php#L40-L47
train
duncan3dc/speaker
src/Providers/AbstractProvider.php
AbstractProvider.sendRequest
protected function sendRequest(string $hostname, array $params): string { $url = $hostname . "?" . http_build_query($params); $response = $this->getClient()->request("GET", $url); if ($response->getStatusCode() != "200") { throw new ProviderException("Failed to call the external text-to-speech service"); } return $response->getBody(); }
php
protected function sendRequest(string $hostname, array $params): string { $url = $hostname . "?" . http_build_query($params); $response = $this->getClient()->request("GET", $url); if ($response->getStatusCode() != "200") { throw new ProviderException("Failed to call the external text-to-speech service"); } return $response->getBody(); }
[ "protected", "function", "sendRequest", "(", "string", "$", "hostname", ",", "array", "$", "params", ")", ":", "string", "{", "$", "url", "=", "$", "hostname", ".", "\"?\"", ".", "http_build_query", "(", "$", "params", ")", ";", "$", "response", "=", "...
Send a http request. @param string $hostname The hostname to send the request to @param string[] $params The parameters of the request @return string The response body
[ "Send", "a", "http", "request", "." ]
17c2f8cba5c702b7495e76aa80a18250b1ce895c
https://github.com/duncan3dc/speaker/blob/17c2f8cba5c702b7495e76aa80a18250b1ce895c/src/Providers/AbstractProvider.php#L83-L94
train
duncan3dc/speaker
src/TextToSpeech.php
TextToSpeech.getAudioData
public function getAudioData(): string { if ($this->data === null) { $this->data = $this->provider->textToSpeech($this->text); } return $this->data; }
php
public function getAudioData(): string { if ($this->data === null) { $this->data = $this->provider->textToSpeech($this->text); } return $this->data; }
[ "public", "function", "getAudioData", "(", ")", ":", "string", "{", "if", "(", "$", "this", "->", "data", "===", "null", ")", "{", "$", "this", "->", "data", "=", "$", "this", "->", "provider", "->", "textToSpeech", "(", "$", "this", "->", "text", ...
Get the audio for this text. @return string The audio data
[ "Get", "the", "audio", "for", "this", "text", "." ]
17c2f8cba5c702b7495e76aa80a18250b1ce895c
https://github.com/duncan3dc/speaker/blob/17c2f8cba5c702b7495e76aa80a18250b1ce895c/src/TextToSpeech.php#L51-L58
train
duncan3dc/speaker
src/TextToSpeech.php
TextToSpeech.generateFilename
public function generateFilename(): string { $options = $this->provider->getOptions(); $options["text"] = $this->text; $data = serialize($options); return md5($data) . "." . $this->provider->getFormat(); }
php
public function generateFilename(): string { $options = $this->provider->getOptions(); $options["text"] = $this->text; $data = serialize($options); return md5($data) . "." . $this->provider->getFormat(); }
[ "public", "function", "generateFilename", "(", ")", ":", "string", "{", "$", "options", "=", "$", "this", "->", "provider", "->", "getOptions", "(", ")", ";", "$", "options", "[", "\"text\"", "]", "=", "$", "this", "->", "text", ";", "$", "data", "="...
Generate the filename to be used for this text. @return string
[ "Generate", "the", "filename", "to", "be", "used", "for", "this", "text", "." ]
17c2f8cba5c702b7495e76aa80a18250b1ce895c
https://github.com/duncan3dc/speaker/blob/17c2f8cba5c702b7495e76aa80a18250b1ce895c/src/TextToSpeech.php#L66-L75
train
duncan3dc/speaker
src/TextToSpeech.php
TextToSpeech.save
public function save(string $filename): TextToSpeechInterface { $result = file_put_contents($filename, $this->getAudioData()); if ($result === false) { throw new RuntimeException("Unable to save the file ({$filename})"); } return $this; }
php
public function save(string $filename): TextToSpeechInterface { $result = file_put_contents($filename, $this->getAudioData()); if ($result === false) { throw new RuntimeException("Unable to save the file ({$filename})"); } return $this; }
[ "public", "function", "save", "(", "string", "$", "filename", ")", ":", "TextToSpeechInterface", "{", "$", "result", "=", "file_put_contents", "(", "$", "filename", ",", "$", "this", "->", "getAudioData", "(", ")", ")", ";", "if", "(", "$", "result", "==...
Create an audio file on the filesystem. @param string $filename The filename to write to @return $this
[ "Create", "an", "audio", "file", "on", "the", "filesystem", "." ]
17c2f8cba5c702b7495e76aa80a18250b1ce895c
https://github.com/duncan3dc/speaker/blob/17c2f8cba5c702b7495e76aa80a18250b1ce895c/src/TextToSpeech.php#L85-L94
train
duncan3dc/speaker
src/TextToSpeech.php
TextToSpeech.getFile
public function getFile(string $path = null): string { if ($path === null) { $path = sys_get_temp_dir(); } $filename = $path . "/" . $this->generateFilename(); if (!is_file($filename)) { $this->save($filename); } return $filename; }
php
public function getFile(string $path = null): string { if ($path === null) { $path = sys_get_temp_dir(); } $filename = $path . "/" . $this->generateFilename(); if (!is_file($filename)) { $this->save($filename); } return $filename; }
[ "public", "function", "getFile", "(", "string", "$", "path", "=", "null", ")", ":", "string", "{", "if", "(", "$", "path", "===", "null", ")", "{", "$", "path", "=", "sys_get_temp_dir", "(", ")", ";", "}", "$", "filename", "=", "$", "path", ".", ...
Store the audio file on the filesystem. This function uses caching so if the file already exists a call to the text-to-speech service is not made. @param string $path The path to the directory to store the file in @return string The full path and filename
[ "Store", "the", "audio", "file", "on", "the", "filesystem", "." ]
17c2f8cba5c702b7495e76aa80a18250b1ce895c
https://github.com/duncan3dc/speaker/blob/17c2f8cba5c702b7495e76aa80a18250b1ce895c/src/TextToSpeech.php#L107-L120
train
Modelizer/Laravel-Selenium
src/Services/WaitForElement.php
WaitForElement.waitForElement
protected function waitForElement($type, $value, $timeout) { if (!in_array($type, $this->waitForTypes)) { throw new \Exception('Invalid wait for element type to wait for on the page'); } $webdriver = $this; $this->waitUntil(function () use ($type, $value, $webdriver) { $function = 'by'.$type; try { $webdriver->$function($value); return true; } catch (\Exception $e) { return; // haven't found the element yet } }, $timeout); }
php
protected function waitForElement($type, $value, $timeout) { if (!in_array($type, $this->waitForTypes)) { throw new \Exception('Invalid wait for element type to wait for on the page'); } $webdriver = $this; $this->waitUntil(function () use ($type, $value, $webdriver) { $function = 'by'.$type; try { $webdriver->$function($value); return true; } catch (\Exception $e) { return; // haven't found the element yet } }, $timeout); }
[ "protected", "function", "waitForElement", "(", "$", "type", ",", "$", "value", ",", "$", "timeout", ")", "{", "if", "(", "!", "in_array", "(", "$", "type", ",", "$", "this", "->", "waitForTypes", ")", ")", "{", "throw", "new", "\\", "Exception", "("...
Generalized WaitsFor function to wait for a specific element with value by the type passed. @param $type The type of selector we are using to wait for @param $value The value of the selector we are using @param $timeout @throws \Exception
[ "Generalized", "WaitsFor", "function", "to", "wait", "for", "a", "specific", "element", "with", "value", "by", "the", "type", "passed", "." ]
bbbcf802467cc10af17ff6edffb31440bab8ce11
https://github.com/Modelizer/Laravel-Selenium/blob/bbbcf802467cc10af17ff6edffb31440bab8ce11/src/Services/WaitForElement.php#L21-L39
train
Modelizer/Laravel-Selenium
src/Services/WaitForElement.php
WaitForElement.waitForElementsWithClass
protected function waitForElementsWithClass($class, $timeout = 2000) { try { $this->waitForElement('ClassName', $class, $timeout); } catch (\Exception $e) { throw new CannotFindElement("Can't find an element with the class name of " .$class.' within the time period of '.$timeout.' miliseconds'); } return $this; }
php
protected function waitForElementsWithClass($class, $timeout = 2000) { try { $this->waitForElement('ClassName', $class, $timeout); } catch (\Exception $e) { throw new CannotFindElement("Can't find an element with the class name of " .$class.' within the time period of '.$timeout.' miliseconds'); } return $this; }
[ "protected", "function", "waitForElementsWithClass", "(", "$", "class", ",", "$", "timeout", "=", "2000", ")", "{", "try", "{", "$", "this", "->", "waitForElement", "(", "'ClassName'", ",", "$", "class", ",", "$", "timeout", ")", ";", "}", "catch", "(", ...
Helper method to wait for an element with the specified class. @param $class @param int $timeout @throws CannotFindElement @return $this
[ "Helper", "method", "to", "wait", "for", "an", "element", "with", "the", "specified", "class", "." ]
bbbcf802467cc10af17ff6edffb31440bab8ce11
https://github.com/Modelizer/Laravel-Selenium/blob/bbbcf802467cc10af17ff6edffb31440bab8ce11/src/Services/WaitForElement.php#L51-L61
train
Modelizer/Laravel-Selenium
src/Services/WaitForElement.php
WaitForElement.waitForElementWithId
protected function waitForElementWithId($id, $timeout = 2000) { try { $this->waitForElement('Id', $id, $timeout); } catch (\Exception $e) { throw new CannotFindElement("Can't find an element with an ID of " .$id.' within the time period of '.$timeout.' miliseconds'); } return $this; }
php
protected function waitForElementWithId($id, $timeout = 2000) { try { $this->waitForElement('Id', $id, $timeout); } catch (\Exception $e) { throw new CannotFindElement("Can't find an element with an ID of " .$id.' within the time period of '.$timeout.' miliseconds'); } return $this; }
[ "protected", "function", "waitForElementWithId", "(", "$", "id", ",", "$", "timeout", "=", "2000", ")", "{", "try", "{", "$", "this", "->", "waitForElement", "(", "'Id'", ",", "$", "id", ",", "$", "timeout", ")", ";", "}", "catch", "(", "\\", "Except...
Helper method to wait for an element with the specified id. @param $id @param int $timeout @throws CannotFindElement @return $this
[ "Helper", "method", "to", "wait", "for", "an", "element", "with", "the", "specified", "id", "." ]
bbbcf802467cc10af17ff6edffb31440bab8ce11
https://github.com/Modelizer/Laravel-Selenium/blob/bbbcf802467cc10af17ff6edffb31440bab8ce11/src/Services/WaitForElement.php#L73-L83
train
Modelizer/Laravel-Selenium
src/Services/WaitForElement.php
WaitForElement.waitForElementWithXPath
protected function waitForElementWithXPath($xpath, $timeout = 2000) { try { $this->waitForElement('XPath', $xpath, $timeout); } catch (\Exception $e) { throw new CannotFindElement("Can't find an element with an XPath of " .$xpath.' within the time period of '.$timeout.' miliseconds'); } return $this; }
php
protected function waitForElementWithXPath($xpath, $timeout = 2000) { try { $this->waitForElement('XPath', $xpath, $timeout); } catch (\Exception $e) { throw new CannotFindElement("Can't find an element with an XPath of " .$xpath.' within the time period of '.$timeout.' miliseconds'); } return $this; }
[ "protected", "function", "waitForElementWithXPath", "(", "$", "xpath", ",", "$", "timeout", "=", "2000", ")", "{", "try", "{", "$", "this", "->", "waitForElement", "(", "'XPath'", ",", "$", "xpath", ",", "$", "timeout", ")", ";", "}", "catch", "(", "\\...
Helper method to wait for an element with the specified xpath. @param $xpath @param int $timeout @throws CannotFindElement @return $this
[ "Helper", "method", "to", "wait", "for", "an", "element", "with", "the", "specified", "xpath", "." ]
bbbcf802467cc10af17ff6edffb31440bab8ce11
https://github.com/Modelizer/Laravel-Selenium/blob/bbbcf802467cc10af17ff6edffb31440bab8ce11/src/Services/WaitForElement.php#L95-L105
train
Modelizer/Laravel-Selenium
src/Services/InteractWithPage.php
InteractWithPage.select
protected function select($value, $element) { $this->wd->findElement(WebDriverBy::cssSelector($element))->sendKeys($value); return $this; }
php
protected function select($value, $element) { $this->wd->findElement(WebDriverBy::cssSelector($element))->sendKeys($value); return $this; }
[ "protected", "function", "select", "(", "$", "value", ",", "$", "element", ")", "{", "$", "this", "->", "wd", "->", "findElement", "(", "WebDriverBy", "::", "cssSelector", "(", "$", "element", ")", ")", "->", "sendKeys", "(", "$", "value", ")", ";", ...
"Select" a drop-down field. @param $value @param $element @return $this
[ "Select", "a", "drop", "-", "down", "field", "." ]
bbbcf802467cc10af17ff6edffb31440bab8ce11
https://github.com/Modelizer/Laravel-Selenium/blob/bbbcf802467cc10af17ff6edffb31440bab8ce11/src/Services/InteractWithPage.php#L53-L58
train
Modelizer/Laravel-Selenium
src/Services/InteractWithPage.php
InteractWithPage.see
protected function see($text, $tag = 'body') { $this->assertContains($text, $this->getTextByTag($tag)); return $this; }
php
protected function see($text, $tag = 'body') { $this->assertContains($text, $this->getTextByTag($tag)); return $this; }
[ "protected", "function", "see", "(", "$", "text", ",", "$", "tag", "=", "'body'", ")", "{", "$", "this", "->", "assertContains", "(", "$", "text", ",", "$", "this", "->", "getTextByTag", "(", "$", "tag", ")", ")", ";", "return", "$", "this", ";", ...
Assert that we see text within the specified tag Defaults to the body tag. @param $text @param string $tag @return $this
[ "Assert", "that", "we", "see", "text", "within", "the", "specified", "tag", "Defaults", "to", "the", "body", "tag", "." ]
bbbcf802467cc10af17ff6edffb31440bab8ce11
https://github.com/Modelizer/Laravel-Selenium/blob/bbbcf802467cc10af17ff6edffb31440bab8ce11/src/Services/InteractWithPage.php#L69-L74
train
Modelizer/Laravel-Selenium
src/Services/InteractWithPage.php
InteractWithPage.seePageIs
protected function seePageIs($path) { $this->assertEquals($this->wd->getCurrentURL(), $this->baseUrl.$path); return $this; }
php
protected function seePageIs($path) { $this->assertEquals($this->wd->getCurrentURL(), $this->baseUrl.$path); return $this; }
[ "protected", "function", "seePageIs", "(", "$", "path", ")", "{", "$", "this", "->", "assertEquals", "(", "$", "this", "->", "wd", "->", "getCurrentURL", "(", ")", ",", "$", "this", "->", "baseUrl", ".", "$", "path", ")", ";", "return", "$", "this", ...
Assert the page is at the path that you specified. @param $path @return $this
[ "Assert", "the", "page", "is", "at", "the", "path", "that", "you", "specified", "." ]
bbbcf802467cc10af17ff6edffb31440bab8ce11
https://github.com/Modelizer/Laravel-Selenium/blob/bbbcf802467cc10af17ff6edffb31440bab8ce11/src/Services/InteractWithPage.php#L105-L110
train
Modelizer/Laravel-Selenium
src/Services/InteractWithPage.php
InteractWithPage.typeBySelectorType
private function typeBySelectorType($type, $value, $name, $clear = false) { $element = $this->wd->findElement(WebDriverBy::{$type}($name)); if ($clear) { $element->clear(); } $element->sendKeys($value); return $this; }
php
private function typeBySelectorType($type, $value, $name, $clear = false) { $element = $this->wd->findElement(WebDriverBy::{$type}($name)); if ($clear) { $element->clear(); } $element->sendKeys($value); return $this; }
[ "private", "function", "typeBySelectorType", "(", "$", "type", ",", "$", "value", ",", "$", "name", ",", "$", "clear", "=", "false", ")", "{", "$", "element", "=", "$", "this", "->", "wd", "->", "findElement", "(", "WebDriverBy", "::", "{", "$", "typ...
Abstraction for typing into a field with a specific selector type. @param $type - one of 'Name', 'Id', 'CssSelector' @param $value - value to enter into form element @param $name - value to use for the selector $type @param bool $clear - Whether or not to clear the input first on say an edit form @throws CannotFindElement @return $this
[ "Abstraction", "for", "typing", "into", "a", "field", "with", "a", "specific", "selector", "type", "." ]
bbbcf802467cc10af17ff6edffb31440bab8ce11
https://github.com/Modelizer/Laravel-Selenium/blob/bbbcf802467cc10af17ff6edffb31440bab8ce11/src/Services/InteractWithPage.php#L152-L163
train
Modelizer/Laravel-Selenium
src/Services/InteractWithPage.php
InteractWithPage.typeByName
protected function typeByName($name, $value, $clear = false) { return $this->typeBySelectorType('name', $value, $name, $clear); }
php
protected function typeByName($name, $value, $clear = false) { return $this->typeBySelectorType('name', $value, $name, $clear); }
[ "protected", "function", "typeByName", "(", "$", "name", ",", "$", "value", ",", "$", "clear", "=", "false", ")", "{", "return", "$", "this", "->", "typeBySelectorType", "(", "'name'", ",", "$", "value", ",", "$", "name", ",", "$", "clear", ")", ";",...
Type a value into a form input by that inputs name. @param $name @param $value @param bool $clear Whether or not to clear the input first on say an edit form @return $this
[ "Type", "a", "value", "into", "a", "form", "input", "by", "that", "inputs", "name", "." ]
bbbcf802467cc10af17ff6edffb31440bab8ce11
https://github.com/Modelizer/Laravel-Selenium/blob/bbbcf802467cc10af17ff6edffb31440bab8ce11/src/Services/InteractWithPage.php#L174-L177
train
Modelizer/Laravel-Selenium
src/Services/InteractWithPage.php
InteractWithPage.typeInformation
protected function typeInformation($information, $clear = false) { foreach ($information as $element => $item) { $this->type($item, $element, $clear); } return $this; }
php
protected function typeInformation($information, $clear = false) { foreach ($information as $element => $item) { $this->type($item, $element, $clear); } return $this; }
[ "protected", "function", "typeInformation", "(", "$", "information", ",", "$", "clear", "=", "false", ")", "{", "foreach", "(", "$", "information", "as", "$", "element", "=>", "$", "item", ")", "{", "$", "this", "->", "type", "(", "$", "item", ",", "...
Function to type information as an array The key of the array specifies the input name. @param $information @param $clear @return $this
[ "Function", "to", "type", "information", "as", "an", "array", "The", "key", "of", "the", "array", "specifies", "the", "input", "name", "." ]
bbbcf802467cc10af17ff6edffb31440bab8ce11
https://github.com/Modelizer/Laravel-Selenium/blob/bbbcf802467cc10af17ff6edffb31440bab8ce11/src/Services/InteractWithPage.php#L216-L223
train
Modelizer/Laravel-Selenium
src/Services/InteractWithPage.php
InteractWithPage.click
protected function click($textOrId) { $element = $this->wd->findElement(WebDriverBy::xpath("//a[contains(., '{$textOrId}')]")); try { $element->click(); } catch (\Exception $e) { throw new CannotClickElement('Cannot click the element with the text: '.$textOrId); } return $this; }
php
protected function click($textOrId) { $element = $this->wd->findElement(WebDriverBy::xpath("//a[contains(., '{$textOrId}')]")); try { $element->click(); } catch (\Exception $e) { throw new CannotClickElement('Cannot click the element with the text: '.$textOrId); } return $this; }
[ "protected", "function", "click", "(", "$", "textOrId", ")", "{", "$", "element", "=", "$", "this", "->", "wd", "->", "findElement", "(", "WebDriverBy", "::", "xpath", "(", "\"//a[contains(., '{$textOrId}')]\"", ")", ")", ";", "try", "{", "$", "element", "...
Click an element based on text passed in, or pass an Id or Name to find the element by. @param $textOrId @throws CannotClickElement Throws when the element cannot be clicked @return $this
[ "Click", "an", "element", "based", "on", "text", "passed", "in", "or", "pass", "an", "Id", "or", "Name", "to", "find", "the", "element", "by", "." ]
bbbcf802467cc10af17ff6edffb31440bab8ce11
https://github.com/Modelizer/Laravel-Selenium/blob/bbbcf802467cc10af17ff6edffb31440bab8ce11/src/Services/InteractWithPage.php#L257-L268
train
Modelizer/Laravel-Selenium
src/Services/InteractWithPage.php
InteractWithPage.findElement
protected function findElement($name) { try { return $this->wd->findElement(WebDriverBy::id($name)); } catch (\Exception $e) { } try { return $this->wd->findElement(WebDriverBy::name($name)); } catch (\Exception $e) { } try { return $this->wd->findElement(WebDriverBy::cssSelector($name)); } catch (\Exception $e) { } try { return $this->wd->findElement(WebDriverBy::xpath($name)); } catch (\Exception $e) { } throw new CannotFindElement('Cannot find element: '.$value.' isn\'t visible on the page'); }
php
protected function findElement($name) { try { return $this->wd->findElement(WebDriverBy::id($name)); } catch (\Exception $e) { } try { return $this->wd->findElement(WebDriverBy::name($name)); } catch (\Exception $e) { } try { return $this->wd->findElement(WebDriverBy::cssSelector($name)); } catch (\Exception $e) { } try { return $this->wd->findElement(WebDriverBy::xpath($name)); } catch (\Exception $e) { } throw new CannotFindElement('Cannot find element: '.$value.' isn\'t visible on the page'); }
[ "protected", "function", "findElement", "(", "$", "name", ")", "{", "try", "{", "return", "$", "this", "->", "wd", "->", "findElement", "(", "WebDriverBy", "::", "id", "(", "$", "name", ")", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ...
Will attempt to find an element by different patterns If xpath is provided, will attempt to find by that first. @param null $name @throws CannotFindElement @return \Facebook\WebDriver\Remote\RemoteWebElement
[ "Will", "attempt", "to", "find", "an", "element", "by", "different", "patterns", "If", "xpath", "is", "provided", "will", "attempt", "to", "find", "by", "that", "first", "." ]
bbbcf802467cc10af17ff6edffb31440bab8ce11
https://github.com/Modelizer/Laravel-Selenium/blob/bbbcf802467cc10af17ff6edffb31440bab8ce11/src/Services/InteractWithPage.php#L280-L303
train
Modelizer/Laravel-Selenium
src/Console/BootSelenium.php
BootSelenium.getSeleniumServerQualifiedName
public function getSeleniumServerQualifiedName() { $files = opendir($binDirectory = base_path('vendor/bin')); while (false !== ($file = readdir($files))) { if (str_contains($file, 'selenium') && str_contains($file, $this->argument('serverVersion'))) { return $binDirectory.DIRECTORY_SEPARATOR.$file; } } return $this->downloadSelenium(); }
php
public function getSeleniumServerQualifiedName() { $files = opendir($binDirectory = base_path('vendor/bin')); while (false !== ($file = readdir($files))) { if (str_contains($file, 'selenium') && str_contains($file, $this->argument('serverVersion'))) { return $binDirectory.DIRECTORY_SEPARATOR.$file; } } return $this->downloadSelenium(); }
[ "public", "function", "getSeleniumServerQualifiedName", "(", ")", "{", "$", "files", "=", "opendir", "(", "$", "binDirectory", "=", "base_path", "(", "'vendor/bin'", ")", ")", ";", "while", "(", "false", "!==", "(", "$", "file", "=", "readdir", "(", "$", ...
Get selenium server qualified location. @throws FileNotFoundException @return string
[ "Get", "selenium", "server", "qualified", "location", "." ]
bbbcf802467cc10af17ff6edffb31440bab8ce11
https://github.com/Modelizer/Laravel-Selenium/blob/bbbcf802467cc10af17ff6edffb31440bab8ce11/src/Console/BootSelenium.php#L76-L87
train
Modelizer/Laravel-Selenium
src/Console/BootSelenium.php
BootSelenium.downloadSelenium
public function downloadSelenium() { $this->info('Downloading Selenium server file. Please wait...'); $process = new Process(base_path('vendor/bin/steward install '.$this->argument('serverVersion'))); $process->setTimeout(0); $process->run(); return $process->getOutput(); }
php
public function downloadSelenium() { $this->info('Downloading Selenium server file. Please wait...'); $process = new Process(base_path('vendor/bin/steward install '.$this->argument('serverVersion'))); $process->setTimeout(0); $process->run(); return $process->getOutput(); }
[ "public", "function", "downloadSelenium", "(", ")", "{", "$", "this", "->", "info", "(", "'Downloading Selenium server file. Please wait...'", ")", ";", "$", "process", "=", "new", "Process", "(", "base_path", "(", "'vendor/bin/steward install '", ".", "$", "this", ...
Download and get the file name of selenium server. @return string selenium server file directory
[ "Download", "and", "get", "the", "file", "name", "of", "selenium", "server", "." ]
bbbcf802467cc10af17ff6edffb31440bab8ce11
https://github.com/Modelizer/Laravel-Selenium/blob/bbbcf802467cc10af17ff6edffb31440bab8ce11/src/Console/BootSelenium.php#L94-L104
train
Modelizer/Laravel-Selenium
src/Console/BootSelenium.php
BootSelenium.getWebDriver
protected function getWebDriver($driverName) { $config = $this->getConfig(); if (empty($config)) { $this->warn('No web driver loaded.'); return ''; } $driver = base_path("vendor/bin/{$this->getFileName()}"); if (!is_file($driver)) { $this->call('selenium:web-driver:download', [ 'driver' => $driverName, ]); } return "-Dwebdriver.{$this->dWebDriver[$driverName]}.driver={$driver}"; }
php
protected function getWebDriver($driverName) { $config = $this->getConfig(); if (empty($config)) { $this->warn('No web driver loaded.'); return ''; } $driver = base_path("vendor/bin/{$this->getFileName()}"); if (!is_file($driver)) { $this->call('selenium:web-driver:download', [ 'driver' => $driverName, ]); } return "-Dwebdriver.{$this->dWebDriver[$driverName]}.driver={$driver}"; }
[ "protected", "function", "getWebDriver", "(", "$", "driverName", ")", "{", "$", "config", "=", "$", "this", "->", "getConfig", "(", ")", ";", "if", "(", "empty", "(", "$", "config", ")", ")", "{", "$", "this", "->", "warn", "(", "'No web driver loaded....
Get web driver full qualified location. @param $driverName @return string
[ "Get", "web", "driver", "full", "qualified", "location", "." ]
bbbcf802467cc10af17ff6edffb31440bab8ce11
https://github.com/Modelizer/Laravel-Selenium/blob/bbbcf802467cc10af17ff6edffb31440bab8ce11/src/Console/BootSelenium.php#L113-L132
train
Modelizer/Laravel-Selenium
src/Services/ManageWindow.php
ManageWindow.changeWindowSize
public function changeWindowSize(int $width = 1024, int $height = 768) { $this->wd->manage()->window()->setPosition(new WebDriverPoint($width, $height)); return $this; }
php
public function changeWindowSize(int $width = 1024, int $height = 768) { $this->wd->manage()->window()->setPosition(new WebDriverPoint($width, $height)); return $this; }
[ "public", "function", "changeWindowSize", "(", "int", "$", "width", "=", "1024", ",", "int", "$", "height", "=", "768", ")", "{", "$", "this", "->", "wd", "->", "manage", "(", ")", "->", "window", "(", ")", "->", "setPosition", "(", "new", "WebDriver...
Change the current window's width and height. @param int $width @param int $height @return $this
[ "Change", "the", "current", "window", "s", "width", "and", "height", "." ]
bbbcf802467cc10af17ff6edffb31440bab8ce11
https://github.com/Modelizer/Laravel-Selenium/blob/bbbcf802467cc10af17ff6edffb31440bab8ce11/src/Services/ManageWindow.php#L23-L28
train
Modelizer/Laravel-Selenium
src/Services/ManageWindow.php
ManageWindow.setWidth
public function setWidth($width) { return $this->wd->manage() ->window() ->setPosition(new WebDriverPoint($width, self::BROWSER_HEIGHT)); }
php
public function setWidth($width) { return $this->wd->manage() ->window() ->setPosition(new WebDriverPoint($width, self::BROWSER_HEIGHT)); }
[ "public", "function", "setWidth", "(", "$", "width", ")", "{", "return", "$", "this", "->", "wd", "->", "manage", "(", ")", "->", "window", "(", ")", "->", "setPosition", "(", "new", "WebDriverPoint", "(", "$", "width", ",", "self", "::", "BROWSER_HEIG...
Set the current window's width. @param $width @return \Facebook\WebDriver\WebDriverWindow
[ "Set", "the", "current", "window", "s", "width", "." ]
bbbcf802467cc10af17ff6edffb31440bab8ce11
https://github.com/Modelizer/Laravel-Selenium/blob/bbbcf802467cc10af17ff6edffb31440bab8ce11/src/Services/ManageWindow.php#L37-L42
train
Modelizer/Laravel-Selenium
src/Console/GetWebDriver.php
GetWebDriver.download
protected function download($client) { $resource = base_path('vendor/bin/driver-file'); if (is_file(base_path("vendor/bin/{$this->getFileName()}"))) { if (!$this->confirm(ucfirst($this->argument('driver')).' web driver file already exists. Would you still like to download it?')) { return false; } } $this->info("Downloading {$this->driver} web driver for {$this->userOS}..."); $resource .= $this->getExtension(); // Downloading Driver $client->request('get', $this->getConfig()['url'], [ 'save_to' => \GuzzleHttp\Psr7\stream_for(fopen($resource, 'w')), ]); return $resource; }
php
protected function download($client) { $resource = base_path('vendor/bin/driver-file'); if (is_file(base_path("vendor/bin/{$this->getFileName()}"))) { if (!$this->confirm(ucfirst($this->argument('driver')).' web driver file already exists. Would you still like to download it?')) { return false; } } $this->info("Downloading {$this->driver} web driver for {$this->userOS}..."); $resource .= $this->getExtension(); // Downloading Driver $client->request('get', $this->getConfig()['url'], [ 'save_to' => \GuzzleHttp\Psr7\stream_for(fopen($resource, 'w')), ]); return $resource; }
[ "protected", "function", "download", "(", "$", "client", ")", "{", "$", "resource", "=", "base_path", "(", "'vendor/bin/driver-file'", ")", ";", "if", "(", "is_file", "(", "base_path", "(", "\"vendor/bin/{$this->getFileName()}\"", ")", ")", ")", "{", "if", "("...
Downloading driver. @param $client @return bool|string
[ "Downloading", "driver", "." ]
bbbcf802467cc10af17ff6edffb31440bab8ce11
https://github.com/Modelizer/Laravel-Selenium/blob/bbbcf802467cc10af17ff6edffb31440bab8ce11/src/Console/GetWebDriver.php#L78-L98
train
Modelizer/Laravel-Selenium
src/Console/GetWebDriver.php
GetWebDriver.unZip
public function unZip(&$resource) { $this->info("Unzipping $resource file..."); $zip = new ZipArchive(); if (!$zip->open($resource)) { throw new \ErrorException("Unable to unzip downloaded file $resource."); } // Renaming chrome driver $zip->extractTo(dirname($resource)); $zip->close(); return $this->cleanUp($resource); }
php
public function unZip(&$resource) { $this->info("Unzipping $resource file..."); $zip = new ZipArchive(); if (!$zip->open($resource)) { throw new \ErrorException("Unable to unzip downloaded file $resource."); } // Renaming chrome driver $zip->extractTo(dirname($resource)); $zip->close(); return $this->cleanUp($resource); }
[ "public", "function", "unZip", "(", "&", "$", "resource", ")", "{", "$", "this", "->", "info", "(", "\"Unzipping $resource file...\"", ")", ";", "$", "zip", "=", "new", "ZipArchive", "(", ")", ";", "if", "(", "!", "$", "zip", "->", "open", "(", "$", ...
Unzip the web driver raw file. @param $resource @throws \ErrorException @return $this
[ "Unzip", "the", "web", "driver", "raw", "file", "." ]
bbbcf802467cc10af17ff6edffb31440bab8ce11
https://github.com/Modelizer/Laravel-Selenium/blob/bbbcf802467cc10af17ff6edffb31440bab8ce11/src/Console/GetWebDriver.php#L109-L123
train
Modelizer/Laravel-Selenium
src/Traits/WebDriverUtilsTrait.php
WebDriverUtilsTrait.setConfig
public function setConfig() { $this->config = (require static::prependPackagePath('bootstrap/config.php'))['web-drivers']; $this->config = @$this->config[$this->getDriver()][$this->getUserOS()]; if (!$this->config) { throw new \ErrorException("Currently {$this->getDriver()} not supported."); } return $this; }
php
public function setConfig() { $this->config = (require static::prependPackagePath('bootstrap/config.php'))['web-drivers']; $this->config = @$this->config[$this->getDriver()][$this->getUserOS()]; if (!$this->config) { throw new \ErrorException("Currently {$this->getDriver()} not supported."); } return $this; }
[ "public", "function", "setConfig", "(", ")", "{", "$", "this", "->", "config", "=", "(", "require", "static", "::", "prependPackagePath", "(", "'bootstrap/config.php'", ")", ")", "[", "'web-drivers'", "]", ";", "$", "this", "->", "config", "=", "@", "$", ...
Set the configuration for web drivers. @throws \ErrorException @return $this
[ "Set", "the", "configuration", "for", "web", "drivers", "." ]
bbbcf802467cc10af17ff6edffb31440bab8ce11
https://github.com/Modelizer/Laravel-Selenium/blob/bbbcf802467cc10af17ff6edffb31440bab8ce11/src/Traits/WebDriverUtilsTrait.php#L92-L103
train
Modelizer/Laravel-Selenium
src/Traits/WebDriverUtilsTrait.php
WebDriverUtilsTrait.prependPackagePath
public static function prependPackagePath($suffix, $assume = false) { $path = __DIR__."/../../$suffix"; if (!$assume and !$path) { throw new \Exception("$path path does not exists."); } return $assume ? $path : realpath($path); }
php
public static function prependPackagePath($suffix, $assume = false) { $path = __DIR__."/../../$suffix"; if (!$assume and !$path) { throw new \Exception("$path path does not exists."); } return $assume ? $path : realpath($path); }
[ "public", "static", "function", "prependPackagePath", "(", "$", "suffix", ",", "$", "assume", "=", "false", ")", "{", "$", "path", "=", "__DIR__", ".", "\"/../../$suffix\"", ";", "if", "(", "!", "$", "assume", "and", "!", "$", "path", ")", "{", "throw"...
Get the real path with package path prepended. @param string $suffix suffix the file needed @param bool $assume Possible directory can be created. @throws \Exception @return mixed
[ "Get", "the", "real", "path", "with", "package", "path", "prepended", "." ]
bbbcf802467cc10af17ff6edffb31440bab8ce11
https://github.com/Modelizer/Laravel-Selenium/blob/bbbcf802467cc10af17ff6edffb31440bab8ce11/src/Traits/WebDriverUtilsTrait.php#L135-L144
train
Maatwebsite/Laravel-Sidebar
src/Traits/CallableTrait.php
CallableTrait.call
public function call(Closure $callback = null, $caller = null) { if ($callback instanceof Closure) { // Make dependency injection possible $parameters = $this->resolveMethodDependencies( [$caller], new ReflectionFunction($callback) ); call_user_func_array($callback, $parameters); } return $caller; }
php
public function call(Closure $callback = null, $caller = null) { if ($callback instanceof Closure) { // Make dependency injection possible $parameters = $this->resolveMethodDependencies( [$caller], new ReflectionFunction($callback) ); call_user_func_array($callback, $parameters); } return $caller; }
[ "public", "function", "call", "(", "Closure", "$", "callback", "=", "null", ",", "$", "caller", "=", "null", ")", "{", "if", "(", "$", "callback", "instanceof", "Closure", ")", "{", "// Make dependency injection possible", "$", "parameters", "=", "$", "this"...
Preform a callback on this workbook instance. @param callable $callback @param null $caller @return $this
[ "Preform", "a", "callback", "on", "this", "workbook", "instance", "." ]
77b14cb48ac9fce45fffd6825c999fe154e70137
https://github.com/Maatwebsite/Laravel-Sidebar/blob/77b14cb48ac9fce45fffd6825c999fe154e70137/src/Traits/CallableTrait.php#L21-L32
train
Maatwebsite/Laravel-Sidebar
src/Domain/DefaultMenu.php
DefaultMenu.group
public function group($name, Closure $callback = null) { if ($this->groups->has($name)) { $group = $this->groups->get($name); } else { $group = $this->container->make('Maatwebsite\Sidebar\Group'); $group->name($name); } $this->call($callback, $group); $this->addGroup($group); return $group; }
php
public function group($name, Closure $callback = null) { if ($this->groups->has($name)) { $group = $this->groups->get($name); } else { $group = $this->container->make('Maatwebsite\Sidebar\Group'); $group->name($name); } $this->call($callback, $group); $this->addGroup($group); return $group; }
[ "public", "function", "group", "(", "$", "name", ",", "Closure", "$", "callback", "=", "null", ")", "{", "if", "(", "$", "this", "->", "groups", "->", "has", "(", "$", "name", ")", ")", "{", "$", "group", "=", "$", "this", "->", "groups", "->", ...
Init a new group or call an existing group and add it to the menu @param $name @param callable $callback @return Group
[ "Init", "a", "new", "group", "or", "call", "an", "existing", "group", "and", "add", "it", "to", "the", "menu" ]
77b14cb48ac9fce45fffd6825c999fe154e70137
https://github.com/Maatwebsite/Laravel-Sidebar/blob/77b14cb48ac9fce45fffd6825c999fe154e70137/src/Domain/DefaultMenu.php#L54-L68
train
Maatwebsite/Laravel-Sidebar
src/Domain/DefaultMenu.php
DefaultMenu.addGroup
public function addGroup(Group $group) { $this->groups->put($group->getName(), $group); return $this; }
php
public function addGroup(Group $group) { $this->groups->put($group->getName(), $group); return $this; }
[ "public", "function", "addGroup", "(", "Group", "$", "group", ")", "{", "$", "this", "->", "groups", "->", "put", "(", "$", "group", "->", "getName", "(", ")", ",", "$", "group", ")", ";", "return", "$", "this", ";", "}" ]
Add a Group instance to the Menu @param Group $group @return $this
[ "Add", "a", "Group", "instance", "to", "the", "Menu" ]
77b14cb48ac9fce45fffd6825c999fe154e70137
https://github.com/Maatwebsite/Laravel-Sidebar/blob/77b14cb48ac9fce45fffd6825c999fe154e70137/src/Domain/DefaultMenu.php#L77-L82
train
Maatwebsite/Laravel-Sidebar
src/Domain/DefaultMenu.php
DefaultMenu.add
public function add(Menu $menu) { foreach ($menu->getGroups() as $group) { if ($this->groups->has($group->getName())) { $existingGroup = $this->groups->get($group->getName()); $group->hideHeading(!$group->shouldShowHeading()); foreach ($group->getItems() as $item) { $existingGroup->addItem($item); } } else { $this->addGroup($group); } } return $this; }
php
public function add(Menu $menu) { foreach ($menu->getGroups() as $group) { if ($this->groups->has($group->getName())) { $existingGroup = $this->groups->get($group->getName()); $group->hideHeading(!$group->shouldShowHeading()); foreach ($group->getItems() as $item) { $existingGroup->addItem($item); } } else { $this->addGroup($group); } } return $this; }
[ "public", "function", "add", "(", "Menu", "$", "menu", ")", "{", "foreach", "(", "$", "menu", "->", "getGroups", "(", ")", "as", "$", "group", ")", "{", "if", "(", "$", "this", "->", "groups", "->", "has", "(", "$", "group", "->", "getName", "(",...
Add another Menu instance and combined the two Groups with the same name get combined, but inherit each other's items @param Menu $menu @return Menu $menu
[ "Add", "another", "Menu", "instance", "and", "combined", "the", "two", "Groups", "with", "the", "same", "name", "get", "combined", "but", "inherit", "each", "other", "s", "items" ]
77b14cb48ac9fce45fffd6825c999fe154e70137
https://github.com/Maatwebsite/Laravel-Sidebar/blob/77b14cb48ac9fce45fffd6825c999fe154e70137/src/Domain/DefaultMenu.php#L104-L121
train
Maatwebsite/Laravel-Sidebar
src/SidebarManager.php
SidebarManager.register
public function register($name) { if (class_exists($name)) { $this->sidebars[] = $name; } else { throw new LogicException('Sidebar [' . $name . '] does not exist'); } return $this; }
php
public function register($name) { if (class_exists($name)) { $this->sidebars[] = $name; } else { throw new LogicException('Sidebar [' . $name . '] does not exist'); } return $this; }
[ "public", "function", "register", "(", "$", "name", ")", "{", "if", "(", "class_exists", "(", "$", "name", ")", ")", "{", "$", "this", "->", "sidebars", "[", "]", "=", "$", "name", ";", "}", "else", "{", "throw", "new", "LogicException", "(", "'Sid...
Register the sidebar @param $name @throws LogicException @return $this
[ "Register", "the", "sidebar" ]
77b14cb48ac9fce45fffd6825c999fe154e70137
https://github.com/Maatwebsite/Laravel-Sidebar/blob/77b14cb48ac9fce45fffd6825c999fe154e70137/src/SidebarManager.php#L45-L54
train
Maatwebsite/Laravel-Sidebar
src/SidebarManager.php
SidebarManager.resolve
public function resolve() { foreach ($this->sidebars as $name) { $sidebar = $this->resolver->resolve($name); $this->container->singleton($name, function () use ($sidebar) { return $sidebar; }); } }
php
public function resolve() { foreach ($this->sidebars as $name) { $sidebar = $this->resolver->resolve($name); $this->container->singleton($name, function () use ($sidebar) { return $sidebar; }); } }
[ "public", "function", "resolve", "(", ")", "{", "foreach", "(", "$", "this", "->", "sidebars", "as", "$", "name", ")", "{", "$", "sidebar", "=", "$", "this", "->", "resolver", "->", "resolve", "(", "$", "name", ")", ";", "$", "this", "->", "contain...
Bind sidebar instances to the ioC
[ "Bind", "sidebar", "instances", "to", "the", "ioC" ]
77b14cb48ac9fce45fffd6825c999fe154e70137
https://github.com/Maatwebsite/Laravel-Sidebar/blob/77b14cb48ac9fce45fffd6825c999fe154e70137/src/SidebarManager.php#L59-L68
train
Maatwebsite/Laravel-Sidebar
src/Traits/ItemableTrait.php
ItemableTrait.addItem
public function addItem(Item $item) { $this->items->put($item->getName(), $item); return $this; }
php
public function addItem(Item $item) { $this->items->put($item->getName(), $item); return $this; }
[ "public", "function", "addItem", "(", "Item", "$", "item", ")", "{", "$", "this", "->", "items", "->", "put", "(", "$", "item", "->", "getName", "(", ")", ",", "$", "item", ")", ";", "return", "$", "this", ";", "}" ]
Add Item instance to Group @param Item $item @return Item
[ "Add", "Item", "instance", "to", "Group" ]
77b14cb48ac9fce45fffd6825c999fe154e70137
https://github.com/Maatwebsite/Laravel-Sidebar/blob/77b14cb48ac9fce45fffd6825c999fe154e70137/src/Traits/ItemableTrait.php#L47-L52
train
Eden-PHP/Core
src/Exception.php
Exception.trigger
public function trigger() { $this->trace = debug_backtrace(); $this->reporter = get_class($this); if (isset($this->trace[$this->offset]['class'])) { $this->reporter = $this->trace[$this->offset]['class']; } if (isset($this->trace[$this->offset]['file'])) { $this->file = $this->trace[$this->offset]['file']; } if (isset($this->trace[$this->offset]['line'])) { $this->line = $this->trace[$this->offset]['line']; } if (!empty($this->variables)) { $this->message = vsprintf($this->message, $this->variables); $this->variables = array(); } throw $this; }
php
public function trigger() { $this->trace = debug_backtrace(); $this->reporter = get_class($this); if (isset($this->trace[$this->offset]['class'])) { $this->reporter = $this->trace[$this->offset]['class']; } if (isset($this->trace[$this->offset]['file'])) { $this->file = $this->trace[$this->offset]['file']; } if (isset($this->trace[$this->offset]['line'])) { $this->line = $this->trace[$this->offset]['line']; } if (!empty($this->variables)) { $this->message = vsprintf($this->message, $this->variables); $this->variables = array(); } throw $this; }
[ "public", "function", "trigger", "(", ")", "{", "$", "this", "->", "trace", "=", "debug_backtrace", "(", ")", ";", "$", "this", "->", "reporter", "=", "get_class", "(", "$", "this", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "trace", "["...
Combines parameters with message and throws it
[ "Combines", "parameters", "with", "message", "and", "throws", "it" ]
2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72
https://github.com/Eden-PHP/Core/blob/2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72/src/Exception.php#L326-L349
train
Eden-PHP/Core
src/Route.php
Route.get
public function get($route = null) { //argument 1 must be a string or null Argument::i()->test(1, 'string', 'null'); //if route is null if (is_null($route)) { //return all routes return $this->route; } //if valid route if ($this->valid($route)) { //return route return $this->route[strtolower($route)]; } //at this point it is not a route //return the same thing return $route; }
php
public function get($route = null) { //argument 1 must be a string or null Argument::i()->test(1, 'string', 'null'); //if route is null if (is_null($route)) { //return all routes return $this->route; } //if valid route if ($this->valid($route)) { //return route return $this->route[strtolower($route)]; } //at this point it is not a route //return the same thing return $route; }
[ "public", "function", "get", "(", "$", "route", "=", "null", ")", "{", "//argument 1 must be a string or null", "Argument", "::", "i", "(", ")", "->", "test", "(", "1", ",", "'string'", ",", "'null'", ")", ";", "//if route is null", "if", "(", "is_null", "...
Returns the class that will be routed to given the route. @param string|null $route the class route name @return string|object|array
[ "Returns", "the", "class", "that", "will", "be", "routed", "to", "given", "the", "route", "." ]
2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72
https://github.com/Eden-PHP/Core/blob/2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72/src/Route.php#L116-L136
train
Eden-PHP/Core
src/Route.php
Route.valid
public function valid($route) { //argument 1 must be a string Argument::i()->test(1, 'string'); return isset($this->route[strtolower($route)]); }
php
public function valid($route) { //argument 1 must be a string Argument::i()->test(1, 'string'); return isset($this->route[strtolower($route)]); }
[ "public", "function", "valid", "(", "$", "route", ")", "{", "//argument 1 must be a string", "Argument", "::", "i", "(", ")", "->", "test", "(", "1", ",", "'string'", ")", ";", "return", "isset", "(", "$", "this", "->", "route", "[", "strtolower", "(", ...
Checks to see if a name is a route @param *string $route the class route name @return bool
[ "Checks", "to", "see", "if", "a", "name", "is", "a", "route" ]
2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72
https://github.com/Eden-PHP/Core/blob/2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72/src/Route.php#L145-L151
train
Eden-PHP/Core
src/Route.php
Route.release
public function release($route) { //argument 1 must be a string Argument::i()->test(1, 'string'); if ($this->valid($route)) { unset($this->route[strtolower($route)]); } return $this; }
php
public function release($route) { //argument 1 must be a string Argument::i()->test(1, 'string'); if ($this->valid($route)) { unset($this->route[strtolower($route)]); } return $this; }
[ "public", "function", "release", "(", "$", "route", ")", "{", "//argument 1 must be a string", "Argument", "::", "i", "(", ")", "->", "test", "(", "1", ",", "'string'", ")", ";", "if", "(", "$", "this", "->", "valid", "(", "$", "route", ")", ")", "{"...
Unsets the route @param *string $route the class route name @return Eden\Core\Route
[ "Unsets", "the", "route" ]
2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72
https://github.com/Eden-PHP/Core/blob/2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72/src/Route.php#L160-L170
train
Eden-PHP/Core
src/Route.php
Route.set
public function set($source, $destination) { //argument test Argument::i() //argument 1 must be a string or object ->test(1, 'string', 'object') //argument 2 must be a string or object ->test(2, 'string', 'object'); //if source is an object if (is_object($source)) { //transform it into string class $source = get_class($source); } //if it is a string if (is_string($destination)) { //we need to consider if this is a vitual class $destination = $this->get($destination); } //now let's route it $this->route[strtolower($source)] = $destination; return $this; }
php
public function set($source, $destination) { //argument test Argument::i() //argument 1 must be a string or object ->test(1, 'string', 'object') //argument 2 must be a string or object ->test(2, 'string', 'object'); //if source is an object if (is_object($source)) { //transform it into string class $source = get_class($source); } //if it is a string if (is_string($destination)) { //we need to consider if this is a vitual class $destination = $this->get($destination); } //now let's route it $this->route[strtolower($source)] = $destination; return $this; }
[ "public", "function", "set", "(", "$", "source", ",", "$", "destination", ")", "{", "//argument test", "Argument", "::", "i", "(", ")", "//argument 1 must be a string or object", "->", "test", "(", "1", ",", "'string'", ",", "'object'", ")", "//argument 2 must b...
Routes a class @param *string $source the class route name @param *string $destination the name of the class to route to @return Eden\Core\Route
[ "Routes", "a", "class" ]
2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72
https://github.com/Eden-PHP/Core/blob/2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72/src/Route.php#L180-L205
train
Eden-PHP/Core
src/Argument.php
Argument.virtual
public function virtual($method, array $args, $index, $types) { //if no test if (static::$stop) { return $this; } $offset = 1; //if the trace came from Argument->test() if (isset($trace['class'], $trace['function']) && $trace['class'] == __CLASS__ && $trace['function'] == 'test' ) { //go back one more $offset = 2; } $trace = debug_backtrace(); $trace = $trace[$offset]; $types = func_get_args(); $method = array_shift($types); $args = array_shift($types); $index = array_shift($types) - 1; if ($index < 0) { $index = 0; } //if it's not set then it's good because the default value //set in the method will be it. if ($index >= count($args)) { return $this; } $argument = $args[$index]; foreach ($types as $i => $type) { if ($this->isValid($type, $argument)) { return $this; } } if (strpos($method, '->') === false && isset($trace['class'])) { $method = $trace['class'].'->'.$method; } $type = $this->getDataType($argument); Exception::i() ->setMessage(self::INVALID_ARGUMENT) ->addVariable($index + 1) ->addVariable($method) ->addVariable(implode(' or ', $types)) ->addVariable($type) ->setTypeLogic() ->setTraceOffset($offset) ->trigger(); }
php
public function virtual($method, array $args, $index, $types) { //if no test if (static::$stop) { return $this; } $offset = 1; //if the trace came from Argument->test() if (isset($trace['class'], $trace['function']) && $trace['class'] == __CLASS__ && $trace['function'] == 'test' ) { //go back one more $offset = 2; } $trace = debug_backtrace(); $trace = $trace[$offset]; $types = func_get_args(); $method = array_shift($types); $args = array_shift($types); $index = array_shift($types) - 1; if ($index < 0) { $index = 0; } //if it's not set then it's good because the default value //set in the method will be it. if ($index >= count($args)) { return $this; } $argument = $args[$index]; foreach ($types as $i => $type) { if ($this->isValid($type, $argument)) { return $this; } } if (strpos($method, '->') === false && isset($trace['class'])) { $method = $trace['class'].'->'.$method; } $type = $this->getDataType($argument); Exception::i() ->setMessage(self::INVALID_ARGUMENT) ->addVariable($index + 1) ->addVariable($method) ->addVariable(implode(' or ', $types)) ->addVariable($type) ->setTypeLogic() ->setTraceOffset($offset) ->trigger(); }
[ "public", "function", "virtual", "(", "$", "method", ",", "array", "$", "args", ",", "$", "index", ",", "$", "types", ")", "{", "//if no test", "if", "(", "static", "::", "$", "stop", ")", "{", "return", "$", "this", ";", "}", "$", "offset", "=", ...
Tests virtual arguments for valid data types @param *string $method method name @param *array $args arguments @param *int $index the argument index to test for @param *mixed[,mixed..] $types the types to test for @return Eden\Core\Argument
[ "Tests", "virtual", "arguments", "for", "valid", "data", "types" ]
2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72
https://github.com/Eden-PHP/Core/blob/2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72/src/Argument.php#L122-L181
train
Eden-PHP/Core
src/Argument.php
Argument.getDataType
private function getDataType($data) { if (is_string($data)) { return "'".$data."'"; } if (is_numeric($data)) { return $data; } if (is_array($data)) { return 'Array'; } if (is_bool($data)) { return $data ? 'true' : 'false'; } if (is_object($data)) { return get_class($data); } if (is_null($data)) { return 'null'; } return 'unknown'; }
php
private function getDataType($data) { if (is_string($data)) { return "'".$data."'"; } if (is_numeric($data)) { return $data; } if (is_array($data)) { return 'Array'; } if (is_bool($data)) { return $data ? 'true' : 'false'; } if (is_object($data)) { return get_class($data); } if (is_null($data)) { return 'null'; } return 'unknown'; }
[ "private", "function", "getDataType", "(", "$", "data", ")", "{", "if", "(", "is_string", "(", "$", "data", ")", ")", "{", "return", "\"'\"", ".", "$", "data", ".", "\"'\"", ";", "}", "if", "(", "is_numeric", "(", "$", "data", ")", ")", "{", "ret...
Returns the data type of the argument @param *mixed $data the value being tested @return string
[ "Returns", "the", "data", "type", "of", "the", "argument" ]
2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72
https://github.com/Eden-PHP/Core/blob/2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72/src/Argument.php#L378-L405
train
Eden-PHP/Core
src/Base.php
Base.addMethod
public function addMethod($source, $destination = null) { //argument test Argument::i() //argument 1 must be a string ->test(1, 'string') //argument 2 must be callable or null ->test(2, 'callable', 'null'); if (is_null($destination)) { //when someone calls a class call this instead Route::i()->set($source, $this); return $this; } //if it's an array they meant to bind the callback if (!is_array($destination)) { //so there's no scope $destination = $destination->bindTo($this, get_class($this)); } //store it self::$invokables[$source] = $destination; return $this; }
php
public function addMethod($source, $destination = null) { //argument test Argument::i() //argument 1 must be a string ->test(1, 'string') //argument 2 must be callable or null ->test(2, 'callable', 'null'); if (is_null($destination)) { //when someone calls a class call this instead Route::i()->set($source, $this); return $this; } //if it's an array they meant to bind the callback if (!is_array($destination)) { //so there's no scope $destination = $destination->bindTo($this, get_class($this)); } //store it self::$invokables[$source] = $destination; return $this; }
[ "public", "function", "addMethod", "(", "$", "source", ",", "$", "destination", "=", "null", ")", "{", "//argument test", "Argument", "::", "i", "(", ")", "//argument 1 must be a string", "->", "test", "(", "1", ",", "'string'", ")", "//argument 2 must be callab...
Creates a class route for this class. @param *string $source the class route name @param callable|null $desination callback handler @return Eden\Core\Base
[ "Creates", "a", "class", "route", "for", "this", "class", "." ]
2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72
https://github.com/Eden-PHP/Core/blob/2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72/src/Base.php#L268-L293
train
Eden-PHP/Core
src/Base.php
Base.callArray
public function callArray($method, array $args = array()) { //argument 1 must be a string Argument::i()->test(1, 'string'); return call_user_func_array(array($this, $method), $args); }
php
public function callArray($method, array $args = array()) { //argument 1 must be a string Argument::i()->test(1, 'string'); return call_user_func_array(array($this, $method), $args); }
[ "public", "function", "callArray", "(", "$", "method", ",", "array", "$", "args", "=", "array", "(", ")", ")", "{", "//argument 1 must be a string", "Argument", "::", "i", "(", ")", "->", "test", "(", "1", ",", "'string'", ")", ";", "return", "call_user_...
Calls a method in this class and allows arguments to be passed as an array @param *string $method method name @param array $args arguments @return mixed
[ "Calls", "a", "method", "in", "this", "class", "and", "allows", "arguments", "to", "be", "passed", "as", "an", "array" ]
2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72
https://github.com/Eden-PHP/Core/blob/2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72/src/Base.php#L304-L310
train
Eden-PHP/Core
src/Base.php
Base.getMultiple
protected static function getMultiple($class = null) { //super magic sauce getting the callers class if (is_null($class) && function_exists('get_called_class')) { $class = get_called_class(); } //get routed class, if any $class = Route::i()->get($class); return self::getInstance($class); }
php
protected static function getMultiple($class = null) { //super magic sauce getting the callers class if (is_null($class) && function_exists('get_called_class')) { $class = get_called_class(); } //get routed class, if any $class = Route::i()->get($class); return self::getInstance($class); }
[ "protected", "static", "function", "getMultiple", "(", "$", "class", "=", "null", ")", "{", "//super magic sauce getting the callers class", "if", "(", "is_null", "(", "$", "class", ")", "&&", "function_exists", "(", "'get_called_class'", ")", ")", "{", "$", "cl...
Returns a non-singleton class, while considering routes @param string|null $class name of the class @return object
[ "Returns", "a", "non", "-", "singleton", "class", "while", "considering", "routes" ]
2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72
https://github.com/Eden-PHP/Core/blob/2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72/src/Base.php#L570-L580
train
Eden-PHP/Core
src/Base.php
Base.getSingleton
protected static function getSingleton($class = null) { //super magic sauce getting the callers class if (is_null($class) && function_exists('get_called_class')) { $class = get_called_class(); } //get routed class, if any $class = Route::i()->get($class); //if it's not set if (!isset(self::$instances[$class])) { //set it self::$instances[$class] = self::getInstance($class); } //return the cached version return self::$instances[$class]; }
php
protected static function getSingleton($class = null) { //super magic sauce getting the callers class if (is_null($class) && function_exists('get_called_class')) { $class = get_called_class(); } //get routed class, if any $class = Route::i()->get($class); //if it's not set if (!isset(self::$instances[$class])) { //set it self::$instances[$class] = self::getInstance($class); } //return the cached version return self::$instances[$class]; }
[ "protected", "static", "function", "getSingleton", "(", "$", "class", "=", "null", ")", "{", "//super magic sauce getting the callers class", "if", "(", "is_null", "(", "$", "class", ")", "&&", "function_exists", "(", "'get_called_class'", ")", ")", "{", "$", "c...
Returns the same instance if instantiated already while considering routes. @param string|null $class name of the class @return object
[ "Returns", "the", "same", "instance", "if", "instantiated", "already", "while", "considering", "routes", "." ]
2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72
https://github.com/Eden-PHP/Core/blob/2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72/src/Base.php#L590-L608
train
Eden-PHP/Core
src/Base.php
Base.getInstance
private static function getInstance($class) { //get the backtrace $trace = debug_backtrace(); $args = array(); //the 2nd line is the caller method if (isset($trace[1]['args']) && count($trace[1]['args']) > 1) { //get the args $args = $trace[1]['args']; //shift out the class name array_shift($args); //then maybe it's the 3rd line? } else if (isset($trace[2]['args']) && count($trace[2]['args']) > 0) { //get the args $args = $trace[2]['args']; } //if there's no args or there's no construct to accept the args if (count($args) === 0 || !method_exists($class, '__construct')) { //just return the instantiation return new $class; } //at this point, we need to vitually call the class $reflect = new \ReflectionClass($class); try { //to return the instantiation return $reflect->newInstanceArgs($args); } catch (\ReflectionException $e) { //trigger error Exception::i() ->setMessage(self::ERROR_REFLECTION) ->addVariable($class) ->addVariable('new') ->trigger(); } }
php
private static function getInstance($class) { //get the backtrace $trace = debug_backtrace(); $args = array(); //the 2nd line is the caller method if (isset($trace[1]['args']) && count($trace[1]['args']) > 1) { //get the args $args = $trace[1]['args']; //shift out the class name array_shift($args); //then maybe it's the 3rd line? } else if (isset($trace[2]['args']) && count($trace[2]['args']) > 0) { //get the args $args = $trace[2]['args']; } //if there's no args or there's no construct to accept the args if (count($args) === 0 || !method_exists($class, '__construct')) { //just return the instantiation return new $class; } //at this point, we need to vitually call the class $reflect = new \ReflectionClass($class); try { //to return the instantiation return $reflect->newInstanceArgs($args); } catch (\ReflectionException $e) { //trigger error Exception::i() ->setMessage(self::ERROR_REFLECTION) ->addVariable($class) ->addVariable('new') ->trigger(); } }
[ "private", "static", "function", "getInstance", "(", "$", "class", ")", "{", "//get the backtrace", "$", "trace", "=", "debug_backtrace", "(", ")", ";", "$", "args", "=", "array", "(", ")", ";", "//the 2nd line is the caller method", "if", "(", "isset", "(", ...
Returns an instance considering routes. With this method we can instantiate while passing construct arguments as arrays @param *string $class name of the class @return object
[ "Returns", "an", "instance", "considering", "routes", ".", "With", "this", "method", "we", "can", "instantiate", "while", "passing", "construct", "arguments", "as", "arrays" ]
2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72
https://github.com/Eden-PHP/Core/blob/2dbd1f3e83ca0dd2d787d31f1654335fba6b6f72/src/Base.php#L619-L656
train
dapphp/radius
src/EAPPacket.php
EAPPacket.identity
public static function identity($identity, $id = null) { $packet = new self(); $packet->setId($id); $packet->code = self::CODE_RESPONSE; $packet->type = self::TYPE_IDENTITY; $packet->data = $identity; return $packet->__toString(); }
php
public static function identity($identity, $id = null) { $packet = new self(); $packet->setId($id); $packet->code = self::CODE_RESPONSE; $packet->type = self::TYPE_IDENTITY; $packet->data = $identity; return $packet->__toString(); }
[ "public", "static", "function", "identity", "(", "$", "identity", ",", "$", "id", "=", "null", ")", "{", "$", "packet", "=", "new", "self", "(", ")", ";", "$", "packet", "->", "setId", "(", "$", "id", ")", ";", "$", "packet", "->", "code", "=", ...
Helper function to generate an EAP Identity packet @param string $identity The identity (username) to send in the packet @param int $id The packet ID (random if omitted) @return string An EAP identity packet
[ "Helper", "function", "to", "generate", "an", "EAP", "Identity", "packet" ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/EAPPacket.php#L36-L45
train
dapphp/radius
src/EAPPacket.php
EAPPacket.mschapv2
public static function mschapv2(\Dapphp\Radius\MsChapV2Packet $chapPacket, $id = null) { $packet = new self(); $packet->setId($id); $packet->code = self::CODE_RESPONSE; $packet->type = self::TYPE_EAP_MS_AUTH; $packet->data = $chapPacket->__toString(); return $packet->__toString(); }
php
public static function mschapv2(\Dapphp\Radius\MsChapV2Packet $chapPacket, $id = null) { $packet = new self(); $packet->setId($id); $packet->code = self::CODE_RESPONSE; $packet->type = self::TYPE_EAP_MS_AUTH; $packet->data = $chapPacket->__toString(); return $packet->__toString(); }
[ "public", "static", "function", "mschapv2", "(", "\\", "Dapphp", "\\", "Radius", "\\", "MsChapV2Packet", "$", "chapPacket", ",", "$", "id", "=", "null", ")", "{", "$", "packet", "=", "new", "self", "(", ")", ";", "$", "packet", "->", "setId", "(", "$...
Helper function for sending an MSCHAP v2 packet encapsulated in an EAP packet @param \Dapphp\Radius\MsChapV2Packet $chapPacket The MSCHAP v2 packet to send @param int $id The CHAP packet identifier (random if omitted) @return string An EAP-MSCHAPv2 packet
[ "Helper", "function", "for", "sending", "an", "MSCHAP", "v2", "packet", "encapsulated", "in", "an", "EAP", "packet" ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/EAPPacket.php#L54-L63
train
dapphp/radius
src/EAPPacket.php
EAPPacket.fromString
public static function fromString($packet) { // TODO: validate incoming packet better $p = new self(); $p->code = ord($packet[0]); $p->id = ord($packet[1]); $temp = unpack('n', substr($packet, 2, 2)); $length = array_shift($temp); if (strlen($packet) != $length) { return false; } $p->type = ord(substr($packet, 4, 1)); $p->data = substr($packet, 5); return $p; }
php
public static function fromString($packet) { // TODO: validate incoming packet better $p = new self(); $p->code = ord($packet[0]); $p->id = ord($packet[1]); $temp = unpack('n', substr($packet, 2, 2)); $length = array_shift($temp); if (strlen($packet) != $length) { return false; } $p->type = ord(substr($packet, 4, 1)); $p->data = substr($packet, 5); return $p; }
[ "public", "static", "function", "fromString", "(", "$", "packet", ")", "{", "// TODO: validate incoming packet better", "$", "p", "=", "new", "self", "(", ")", ";", "$", "p", "->", "code", "=", "ord", "(", "$", "packet", "[", "0", "]", ")", ";", "$", ...
Convert a raw EAP packet into a structure @param string $packet The EAP packet @return \Dapphp\Radius\EAPPacket The parsed packet structure
[ "Convert", "a", "raw", "EAP", "packet", "into", "a", "structure" ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/EAPPacket.php#L71-L89
train
dapphp/radius
src/EAPPacket.php
EAPPacket.setId
public function setId($id = null) { if ($id == null) { $this->id = mt_rand(0, 255); } else { $this->id = (int)$id; } return $this; }
php
public function setId($id = null) { if ($id == null) { $this->id = mt_rand(0, 255); } else { $this->id = (int)$id; } return $this; }
[ "public", "function", "setId", "(", "$", "id", "=", "null", ")", "{", "if", "(", "$", "id", "==", "null", ")", "{", "$", "this", "->", "id", "=", "mt_rand", "(", "0", ",", "255", ")", ";", "}", "else", "{", "$", "this", "->", "id", "=", "("...
Set the ID of the EAP packet @param int $id The EAP packet ID @return \Dapphp\Radius\EAPPacket Fluent interface
[ "Set", "the", "ID", "of", "the", "EAP", "packet" ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/EAPPacket.php#L96-L105
train
dapphp/radius
src/Radius.php
Radius.setPassword
public function setPassword($password) { $this->password = $password; $encryptedPassword = $this->getEncryptedPassword($password, $this->getSecret(), $this->getRequestAuthenticator()); $this->setAttribute(2, $encryptedPassword); return $this; }
php
public function setPassword($password) { $this->password = $password; $encryptedPassword = $this->getEncryptedPassword($password, $this->getSecret(), $this->getRequestAuthenticator()); $this->setAttribute(2, $encryptedPassword); return $this; }
[ "public", "function", "setPassword", "(", "$", "password", ")", "{", "$", "this", "->", "password", "=", "$", "password", ";", "$", "encryptedPassword", "=", "$", "this", "->", "getEncryptedPassword", "(", "$", "password", ",", "$", "this", "->", "getSecre...
Set the User-Password for PAP authentication. Do not use this if you will be using CHAP-MD5, MS-CHAP v1 or MS-CHAP v2 passwords. @param string $password The plain text password for authentication @return \Dapphp\Radius\Radius
[ "Set", "the", "User", "-", "Password", "for", "PAP", "authentication", ".", "Do", "not", "use", "this", "if", "you", "will", "be", "using", "CHAP", "-", "MD5", "MS", "-", "CHAP", "v1", "or", "MS", "-", "CHAP", "v2", "passwords", "." ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L397-L405
train
dapphp/radius
src/Radius.php
Radius.getEncryptedPassword
public function getEncryptedPassword($password, $secret, $requestAuthenticator) { $encryptedPassword = ''; $paddedPassword = $password; if (0 != (strlen($password) % 16)) { $paddedPassword .= str_repeat(chr(0), (16 - strlen($password) % 16)); } $previous = $requestAuthenticator; for ($i = 0; $i < (strlen($paddedPassword) / 16); ++$i) { $temp = md5($secret . $previous); $previous = ''; for ($j = 0; $j <= 15; ++$j) { $value1 = ord(substr($paddedPassword, ($i * 16) + $j, 1)); $value2 = hexdec(substr($temp, 2 * $j, 2)); $xor_result = $value1 ^ $value2; $previous .= chr($xor_result); } $encryptedPassword .= $previous; } return $encryptedPassword; }
php
public function getEncryptedPassword($password, $secret, $requestAuthenticator) { $encryptedPassword = ''; $paddedPassword = $password; if (0 != (strlen($password) % 16)) { $paddedPassword .= str_repeat(chr(0), (16 - strlen($password) % 16)); } $previous = $requestAuthenticator; for ($i = 0; $i < (strlen($paddedPassword) / 16); ++$i) { $temp = md5($secret . $previous); $previous = ''; for ($j = 0; $j <= 15; ++$j) { $value1 = ord(substr($paddedPassword, ($i * 16) + $j, 1)); $value2 = hexdec(substr($temp, 2 * $j, 2)); $xor_result = $value1 ^ $value2; $previous .= chr($xor_result); } $encryptedPassword .= $previous; } return $encryptedPassword; }
[ "public", "function", "getEncryptedPassword", "(", "$", "password", ",", "$", "secret", ",", "$", "requestAuthenticator", ")", "{", "$", "encryptedPassword", "=", "''", ";", "$", "paddedPassword", "=", "$", "password", ";", "if", "(", "0", "!=", "(", "strl...
Get a RADIUS encrypted password from a plaintext password, shared secret, and request authenticator. This method should generally not need to be called directly. @param string $password The plain text password @param string $secret The RADIUS shared secret @param string $requestAuthenticator 16 byte request authenticator @return string The encrypted password
[ "Get", "a", "RADIUS", "encrypted", "password", "from", "a", "plaintext", "password", "shared", "secret", "and", "request", "authenticator", ".", "This", "method", "should", "generally", "not", "need", "to", "be", "called", "directly", "." ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L426-L451
train
dapphp/radius
src/Radius.php
Radius.getChapPassword
public function getChapPassword($password, $chapId, $requestAuthenticator) { return md5(pack('C', $chapId) . $password . $requestAuthenticator, true); }
php
public function getChapPassword($password, $chapId, $requestAuthenticator) { return md5(pack('C', $chapId) . $password . $requestAuthenticator, true); }
[ "public", "function", "getChapPassword", "(", "$", "password", ",", "$", "chapId", ",", "$", "requestAuthenticator", ")", "{", "return", "md5", "(", "pack", "(", "'C'", ",", "$", "chapId", ")", ".", "$", "password", ".", "$", "requestAuthenticator", ",", ...
Generate a CHAP password. There is generally no need to call this method directly. @param string $password The password to hash using CHAP @param int $chapId The CHAP packet ID @param string $requestAuthenticator The request authenticator value @return string The hashed CHAP password
[ "Generate", "a", "CHAP", "password", ".", "There", "is", "generally", "no", "need", "to", "call", "this", "method", "directly", "." ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L522-L525
train
dapphp/radius
src/Radius.php
Radius.setNasPort
public function setNasPort($port = 0) { $this->nasPort = intval($port); $this->setAttribute(5, $this->nasPort); return $this; }
php
public function setNasPort($port = 0) { $this->nasPort = intval($port); $this->setAttribute(5, $this->nasPort); return $this; }
[ "public", "function", "setNasPort", "(", "$", "port", "=", "0", ")", "{", "$", "this", "->", "nasPort", "=", "intval", "(", "$", "port", ")", ";", "$", "this", "->", "setAttribute", "(", "5", ",", "$", "this", "->", "nasPort", ")", ";", "return", ...
Set the physical port number of the NAS which is authenticating the user. @param number $port The NAS port @return \Dapphp\Radius\Radius
[ "Set", "the", "physical", "port", "number", "of", "the", "NAS", "which", "is", "authenticating", "the", "user", "." ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L597-L603
train
dapphp/radius
src/Radius.php
Radius.getReadableReceivedAttributes
public function getReadableReceivedAttributes() { $attributes = ''; if (isset($this->attributesReceived)) { foreach($this->attributesReceived as $receivedAttr) { $info = $this->getAttributesInfo($receivedAttr[0]); $attributes .= sprintf('%s: ', $info[0]); if (26 == $receivedAttr[0]) { $vendorArr = $this->decodeVendorSpecificContent($receivedAttr[1]); foreach($vendorArr as $vendor) { $attributes .= sprintf('Vendor-Id: %s, Vendor-type: %s, Attribute-specific: %s', $vendor[0], $vendor[1], $vendor[2]); } } else { $attribues = $receivedAttr[1]; } $attributes .= "<br>\n"; } } return $attributes; }
php
public function getReadableReceivedAttributes() { $attributes = ''; if (isset($this->attributesReceived)) { foreach($this->attributesReceived as $receivedAttr) { $info = $this->getAttributesInfo($receivedAttr[0]); $attributes .= sprintf('%s: ', $info[0]); if (26 == $receivedAttr[0]) { $vendorArr = $this->decodeVendorSpecificContent($receivedAttr[1]); foreach($vendorArr as $vendor) { $attributes .= sprintf('Vendor-Id: %s, Vendor-type: %s, Attribute-specific: %s', $vendor[0], $vendor[1], $vendor[2]); } } else { $attribues = $receivedAttr[1]; } $attributes .= "<br>\n"; } } return $attributes; }
[ "public", "function", "getReadableReceivedAttributes", "(", ")", "{", "$", "attributes", "=", "''", ";", "if", "(", "isset", "(", "$", "this", "->", "attributesReceived", ")", ")", "{", "foreach", "(", "$", "this", "->", "attributesReceived", "as", "$", "r...
For debugging purposes. Print the attributes from the last received packet as a readble string @return string The RADIUS packet attributes in human readable format
[ "For", "debugging", "purposes", ".", "Print", "the", "attributes", "from", "the", "last", "received", "packet", "as", "a", "readble", "string" ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L717-L741
train
dapphp/radius
src/Radius.php
Radius.getAttribute
public function getAttribute($type) { $value = null; if (is_array($this->attributesReceived)) { foreach($this->attributesReceived as $attr) { if (intval($type) == $attr[0]) { $value = $attr[1]; break; } } } return $value; }
php
public function getAttribute($type) { $value = null; if (is_array($this->attributesReceived)) { foreach($this->attributesReceived as $attr) { if (intval($type) == $attr[0]) { $value = $attr[1]; break; } } } return $value; }
[ "public", "function", "getAttribute", "(", "$", "type", ")", "{", "$", "value", "=", "null", ";", "if", "(", "is_array", "(", "$", "this", "->", "attributesReceived", ")", ")", "{", "foreach", "(", "$", "this", "->", "attributesReceived", "as", "$", "a...
Get the value of an attribute from the last received RADIUS response packet. @param int $type The attribute ID to get @return NULL|string NULL if no such attribute was set in the response packet, or the data of that attribute
[ "Get", "the", "value", "of", "an", "attribute", "from", "the", "last", "received", "RADIUS", "response", "packet", "." ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L749-L763
train
dapphp/radius
src/Radius.php
Radius.getRadiusPacketInfo
public function getRadiusPacketInfo($info_index) { if (isset($this->radiusPackets[intval($info_index)])) { return $this->radiusPackets[intval($info_index)]; } else { return ''; } }
php
public function getRadiusPacketInfo($info_index) { if (isset($this->radiusPackets[intval($info_index)])) { return $this->radiusPackets[intval($info_index)]; } else { return ''; } }
[ "public", "function", "getRadiusPacketInfo", "(", "$", "info_index", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "radiusPackets", "[", "intval", "(", "$", "info_index", ")", "]", ")", ")", "{", "return", "$", "this", "->", "radiusPackets", "[",...
Gets the name of a RADIUS packet from the numeric value. This is only used for debugging functions @param number $info_index The packet type number @return mixed|string
[ "Gets", "the", "name", "of", "a", "RADIUS", "packet", "from", "the", "numeric", "value", ".", "This", "is", "only", "used", "for", "debugging", "functions" ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L772-L779
train
dapphp/radius
src/Radius.php
Radius.getAttributesInfo
public function getAttributesInfo($info_index) { if (isset($this->attributesInfo[intval($info_index)])) { return $this->attributesInfo[intval($info_index)]; } else { return array('', ''); } }
php
public function getAttributesInfo($info_index) { if (isset($this->attributesInfo[intval($info_index)])) { return $this->attributesInfo[intval($info_index)]; } else { return array('', ''); } }
[ "public", "function", "getAttributesInfo", "(", "$", "info_index", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "attributesInfo", "[", "intval", "(", "$", "info_index", ")", "]", ")", ")", "{", "return", "$", "this", "->", "attributesInfo", "[",...
Gets the info about a RADIUS attribute identifier such as the attribute name and data type. This is used internally for encoding packets and debug output. @param number $info_index The RADIUS packet attribute number @return array 2 element array with Attibute-Name and Data Type
[ "Gets", "the", "info", "about", "a", "RADIUS", "attribute", "identifier", "such", "as", "the", "attribute", "name", "and", "data", "type", ".", "This", "is", "used", "internally", "for", "encoding", "packets", "and", "debug", "output", "." ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L788-L795
train
dapphp/radius
src/Radius.php
Radius.setAttribute
public function setAttribute($type, $value) { $index = -1; if (is_array($this->attributesToSend)) { foreach($this->attributesToSend as $i => $attr) { if (is_array($attr)) { $tmp = $attr[0]; } else { $tmp = $attr; } if ($type == ord(substr($tmp, 0, 1))) { $index = $i; break; } } } $temp = null; if (isset($this->attributesInfo[$type])) { switch ($this->attributesInfo[$type][1]) { case 'T': // Text, 1-253 octets containing UTF-8 encoded ISO 10646 characters (RFC 2279). $temp = chr($type) . chr(2 + strlen($value)) . $value; break; case 'S': // String, 1-253 octets containing binary data (values 0 through 255 decimal, inclusive). $temp = chr($type) . chr(2 + strlen($value)) . $value; break; case 'A': // Address, 32 bit value, most significant octet first. $ip = explode('.', $value); $temp = chr($type) . chr(6) . chr($ip[0]) . chr($ip[1]) . chr($ip[2]) . chr($ip[3]); break; case 'I': // Integer, 32 bit unsigned value, most significant octet first. $temp = chr($type) . chr(6) . chr(($value / (256 * 256 * 256)) % 256) . chr(($value / (256 * 256)) % 256) . chr(($value / (256)) % 256) . chr($value % 256); break; case 'D': // Time, 32 bit unsigned value, most significant octet first -- seconds since 00:00:00 UTC, January 1, 1970. (not used in this RFC) $temp = null; break; default: $temp = null; } } if ($index > -1) { if ($type == 26) { // vendor specific $this->attributesToSend[$index][] = $temp; $action = 'Added'; } else { $this->attributesToSend[$index] = $temp; $action = 'Modified'; } } else { $this->attributesToSend[] = ($type == 26 /* vendor specific */) ? array($temp) : $temp; $action = 'Added'; } $info = $this->getAttributesInfo($type); $this->debugInfo("{$action} Attribute {$type} ({$info[0]}), format {$info[1]}, value <em>{$value}</em>"); return $this; }
php
public function setAttribute($type, $value) { $index = -1; if (is_array($this->attributesToSend)) { foreach($this->attributesToSend as $i => $attr) { if (is_array($attr)) { $tmp = $attr[0]; } else { $tmp = $attr; } if ($type == ord(substr($tmp, 0, 1))) { $index = $i; break; } } } $temp = null; if (isset($this->attributesInfo[$type])) { switch ($this->attributesInfo[$type][1]) { case 'T': // Text, 1-253 octets containing UTF-8 encoded ISO 10646 characters (RFC 2279). $temp = chr($type) . chr(2 + strlen($value)) . $value; break; case 'S': // String, 1-253 octets containing binary data (values 0 through 255 decimal, inclusive). $temp = chr($type) . chr(2 + strlen($value)) . $value; break; case 'A': // Address, 32 bit value, most significant octet first. $ip = explode('.', $value); $temp = chr($type) . chr(6) . chr($ip[0]) . chr($ip[1]) . chr($ip[2]) . chr($ip[3]); break; case 'I': // Integer, 32 bit unsigned value, most significant octet first. $temp = chr($type) . chr(6) . chr(($value / (256 * 256 * 256)) % 256) . chr(($value / (256 * 256)) % 256) . chr(($value / (256)) % 256) . chr($value % 256); break; case 'D': // Time, 32 bit unsigned value, most significant octet first -- seconds since 00:00:00 UTC, January 1, 1970. (not used in this RFC) $temp = null; break; default: $temp = null; } } if ($index > -1) { if ($type == 26) { // vendor specific $this->attributesToSend[$index][] = $temp; $action = 'Added'; } else { $this->attributesToSend[$index] = $temp; $action = 'Modified'; } } else { $this->attributesToSend[] = ($type == 26 /* vendor specific */) ? array($temp) : $temp; $action = 'Added'; } $info = $this->getAttributesInfo($type); $this->debugInfo("{$action} Attribute {$type} ({$info[0]}), format {$info[1]}, value <em>{$value}</em>"); return $this; }
[ "public", "function", "setAttribute", "(", "$", "type", ",", "$", "value", ")", "{", "$", "index", "=", "-", "1", ";", "if", "(", "is_array", "(", "$", "this", "->", "attributesToSend", ")", ")", "{", "foreach", "(", "$", "this", "->", "attributesToS...
Set an arbitrary RADIUS attribute to be sent in the next packet. @param number $type The number of the RADIUS attribute @param mixed $value The value of the attribute @return \Dapphp\Radius\Radius
[ "Set", "an", "arbitrary", "RADIUS", "attribute", "to", "be", "sent", "in", "the", "next", "packet", "." ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L804-L872
train
dapphp/radius
src/Radius.php
Radius.getAttributesToSend
public function getAttributesToSend($type = null) { if (is_array($this->attributesToSend)) { if ($type == null) { return $this->attributesToSend; } else { foreach($this->attributesToSend as $i => $attr) { if (is_array($attr)) { $tmp = $attr[0]; } else { $tmp = $attr; } if ($type == ord(substr($tmp, 0, 1))) { return $this->decodeAttribute(substr($tmp, 2), $type); } } return null; } } return array(); }
php
public function getAttributesToSend($type = null) { if (is_array($this->attributesToSend)) { if ($type == null) { return $this->attributesToSend; } else { foreach($this->attributesToSend as $i => $attr) { if (is_array($attr)) { $tmp = $attr[0]; } else { $tmp = $attr; } if ($type == ord(substr($tmp, 0, 1))) { return $this->decodeAttribute(substr($tmp, 2), $type); } } return null; } } return array(); }
[ "public", "function", "getAttributesToSend", "(", "$", "type", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "attributesToSend", ")", ")", "{", "if", "(", "$", "type", "==", "null", ")", "{", "return", "$", "this", "->", "attr...
Get one or all set attributes to send @param int|null $type RADIUS attribute type, or null for all @return mixed array of attributes to send, or null if specific attribute not found, or
[ "Get", "one", "or", "all", "set", "attributes", "to", "send" ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L880-L901
train
dapphp/radius
src/Radius.php
Radius.setVendorSpecificAttribute
public function setVendorSpecificAttribute($vendorId, $attributeType, $attributeValue) { $data = pack('N', $vendorId); $data .= chr($attributeType); $data .= chr(2 + strlen($attributeValue)); $data .= $attributeValue; $this->setAttribute(26, $data); return $this; }
php
public function setVendorSpecificAttribute($vendorId, $attributeType, $attributeValue) { $data = pack('N', $vendorId); $data .= chr($attributeType); $data .= chr(2 + strlen($attributeValue)); $data .= $attributeValue; $this->setAttribute(26, $data); return $this; }
[ "public", "function", "setVendorSpecificAttribute", "(", "$", "vendorId", ",", "$", "attributeType", ",", "$", "attributeValue", ")", "{", "$", "data", "=", "pack", "(", "'N'", ",", "$", "vendorId", ")", ";", "$", "data", ".=", "chr", "(", "$", "attribut...
Adds a vendor specific attribute to the RADIUS packet @param number $vendorId The RADIUS vendor ID @param number $attributeType The attribute number of the vendor specific attribute @param mixed $attributeValue The data for the attribute @return \Dapphp\Radius\Radius
[ "Adds", "a", "vendor", "specific", "attribute", "to", "the", "RADIUS", "packet" ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L911-L921
train
dapphp/radius
src/Radius.php
Radius.removeAttribute
public function removeAttribute($type) { $index = -1; if (is_array($this->attributesToSend)) { foreach($this->attributesToSend as $i => $attr) { if (is_array($attr)) { $tmp = $attr[0]; } else { $tmp = $attr; } if ($type == ord(substr($tmp, 0, 1))) { unset($this->attributesToSend[$i]); break; } } } return $this; }
php
public function removeAttribute($type) { $index = -1; if (is_array($this->attributesToSend)) { foreach($this->attributesToSend as $i => $attr) { if (is_array($attr)) { $tmp = $attr[0]; } else { $tmp = $attr; } if ($type == ord(substr($tmp, 0, 1))) { unset($this->attributesToSend[$i]); break; } } } return $this; }
[ "public", "function", "removeAttribute", "(", "$", "type", ")", "{", "$", "index", "=", "-", "1", ";", "if", "(", "is_array", "(", "$", "this", "->", "attributesToSend", ")", ")", "{", "foreach", "(", "$", "this", "->", "attributesToSend", "as", "$", ...
Remove an attribute from a RADIUS packet @param number $type The attribute number to remove @return \Dapphp\Radius\Radius
[ "Remove", "an", "attribute", "from", "a", "RADIUS", "packet" ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L929-L947
train
dapphp/radius
src/Radius.php
Radius.decodeVendorSpecificContent
public function decodeVendorSpecificContent($rawValue) { $result = array(); $offset = 0; $vendorId = (ord(substr($rawValue, 0, 1)) * 256 * 256 * 256) + (ord(substr($rawValue, 1, 1)) * 256 * 256) + (ord(substr($rawValue, 2, 1)) * 256) + ord(substr($rawValue, 3, 1)); $offset += 4; while ($offset < strlen($rawValue)) { $vendorType = (ord(substr($rawValue, 0 + $offset, 1))); $vendorLength = (ord(substr($rawValue, 1 + $offset, 1))); $attributeSpecific = substr($rawValue, 2 + $offset, $vendorLength); $result[] = array($vendorId, $vendorType, $attributeSpecific); $offset += $vendorLength; } return $result; }
php
public function decodeVendorSpecificContent($rawValue) { $result = array(); $offset = 0; $vendorId = (ord(substr($rawValue, 0, 1)) * 256 * 256 * 256) + (ord(substr($rawValue, 1, 1)) * 256 * 256) + (ord(substr($rawValue, 2, 1)) * 256) + ord(substr($rawValue, 3, 1)); $offset += 4; while ($offset < strlen($rawValue)) { $vendorType = (ord(substr($rawValue, 0 + $offset, 1))); $vendorLength = (ord(substr($rawValue, 1 + $offset, 1))); $attributeSpecific = substr($rawValue, 2 + $offset, $vendorLength); $result[] = array($vendorId, $vendorType, $attributeSpecific); $offset += $vendorLength; } return $result; }
[ "public", "function", "decodeVendorSpecificContent", "(", "$", "rawValue", ")", "{", "$", "result", "=", "array", "(", ")", ";", "$", "offset", "=", "0", ";", "$", "vendorId", "=", "(", "ord", "(", "substr", "(", "$", "rawValue", ",", "0", ",", "1", ...
Decodes a vendor specific attribute in a response packet @param string $rawValue The raw packet attribute data as seen on the wire @return array Array of vendor specific attributes in the response packet
[ "Decodes", "a", "vendor", "specific", "attribute", "in", "a", "response", "packet" ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L978-L997
train
dapphp/radius
src/Radius.php
Radius.accessRequest
public function accessRequest($username = '', $password = '', $timeout = 0, $state = null) { $this->clearDataReceived() ->clearError() ->setPacketType(self::TYPE_ACCESS_REQUEST); if (0 < strlen($username)) { $this->setUsername($username); } if (0 < strlen($password)) { $this->setPassword($password); } if ($state !== null) { $this->setAttribute(24, $state); } else { $this->setAttribute(6, 1); // 1=Login } if (intval($timeout) > 0) { $this->setTimeout($timeout); } $packetData = $this->generateRadiusPacket(); $conn = $this->sendRadiusRequest($packetData); if (!$conn) { $this->debugInfo(sprintf( 'Failed to send packet to %s; error: %s', $this->server, $this->getErrorMessage()) ); return false; } $receivedPacket = $this->readRadiusResponse($conn); @fclose($conn); if (!$receivedPacket) { $this->debugInfo(sprintf( 'Error receiving response packet from %s; error: %s', $this->server, $this->getErrorMessage()) ); return false; } if (!$this->parseRadiusResponsePacket($receivedPacket)) { $this->debugInfo(sprintf( 'Bad RADIUS response from %s; error: %s', $this->server, $this->getErrorMessage()) ); return false; } if ($this->radiusPacketReceived == self::TYPE_ACCESS_REJECT) { $this->errorCode = 3; $this->errorMessage = 'Access rejected'; } return (self::TYPE_ACCESS_ACCEPT == ($this->radiusPacketReceived)); }
php
public function accessRequest($username = '', $password = '', $timeout = 0, $state = null) { $this->clearDataReceived() ->clearError() ->setPacketType(self::TYPE_ACCESS_REQUEST); if (0 < strlen($username)) { $this->setUsername($username); } if (0 < strlen($password)) { $this->setPassword($password); } if ($state !== null) { $this->setAttribute(24, $state); } else { $this->setAttribute(6, 1); // 1=Login } if (intval($timeout) > 0) { $this->setTimeout($timeout); } $packetData = $this->generateRadiusPacket(); $conn = $this->sendRadiusRequest($packetData); if (!$conn) { $this->debugInfo(sprintf( 'Failed to send packet to %s; error: %s', $this->server, $this->getErrorMessage()) ); return false; } $receivedPacket = $this->readRadiusResponse($conn); @fclose($conn); if (!$receivedPacket) { $this->debugInfo(sprintf( 'Error receiving response packet from %s; error: %s', $this->server, $this->getErrorMessage()) ); return false; } if (!$this->parseRadiusResponsePacket($receivedPacket)) { $this->debugInfo(sprintf( 'Bad RADIUS response from %s; error: %s', $this->server, $this->getErrorMessage()) ); return false; } if ($this->radiusPacketReceived == self::TYPE_ACCESS_REJECT) { $this->errorCode = 3; $this->errorMessage = 'Access rejected'; } return (self::TYPE_ACCESS_ACCEPT == ($this->radiusPacketReceived)); }
[ "public", "function", "accessRequest", "(", "$", "username", "=", "''", ",", "$", "password", "=", "''", ",", "$", "timeout", "=", "0", ",", "$", "state", "=", "null", ")", "{", "$", "this", "->", "clearDataReceived", "(", ")", "->", "clearError", "(...
Issue an Access-Request packet to the RADIUS server. @param string $username Username to authenticate as @param string $password Password to authenticate with using PAP @param number $timeout The timeout (in seconds) to wait for a response packet @param string $state The state of the request (default is Service-Type=1) @return boolean true if the server sent an Access-Accept packet, false otherwise
[ "Issue", "an", "Access", "-", "Request", "packet", "to", "the", "RADIUS", "server", "." ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L1008-L1074
train
dapphp/radius
src/Radius.php
Radius.accessRequestList
public function accessRequestList($serverList, $username = '', $password = '', $timeout = 0, $state = null) { if (!is_array($serverList)) { $this->errorCode = 127; $this->errorMessage = sprintf( 'server list passed to accessRequestl must be array; %s given', gettype($serverList) ); return false; } foreach($serverList as $server) { $this->setServer($server); $result = $this->accessRequest($username, $password, $timeout, $state); if ($result === true) { break; // success } elseif ($this->getErrorCode() === self::TYPE_ACCESS_REJECT) { break; // access rejected } else { /* timeout or other possible transient error; try next host */ } } return $result; }
php
public function accessRequestList($serverList, $username = '', $password = '', $timeout = 0, $state = null) { if (!is_array($serverList)) { $this->errorCode = 127; $this->errorMessage = sprintf( 'server list passed to accessRequestl must be array; %s given', gettype($serverList) ); return false; } foreach($serverList as $server) { $this->setServer($server); $result = $this->accessRequest($username, $password, $timeout, $state); if ($result === true) { break; // success } elseif ($this->getErrorCode() === self::TYPE_ACCESS_REJECT) { break; // access rejected } else { /* timeout or other possible transient error; try next host */ } } return $result; }
[ "public", "function", "accessRequestList", "(", "$", "serverList", ",", "$", "username", "=", "''", ",", "$", "password", "=", "''", ",", "$", "timeout", "=", "0", ",", "$", "state", "=", "null", ")", "{", "if", "(", "!", "is_array", "(", "$", "ser...
Perform an accessRequest against a list of servers. Each server must share the same RADIUS secret. This is useful if you have more than one RADIUS server. This function tries each server until it receives an Access-Accept or Access-Reject response. That is, it will try more than one server in the event of a timeout or other failure. @see \Dapphp\Radius\Radius::accessRequest() @param array $serverList Array of servers to authenticate against @param string $username Username to authenticate as @param string $password Password to authenticate with using PAP @param number $timeout The timeout (in seconds) to wait for a response packet @param string $state The state of the request (default is Service-Type=1) @return boolean true if the server sent an Access-Accept packet, false otherwise
[ "Perform", "an", "accessRequest", "against", "a", "list", "of", "servers", ".", "Each", "server", "must", "share", "the", "same", "RADIUS", "secret", ".", "This", "is", "useful", "if", "you", "have", "more", "than", "one", "RADIUS", "server", ".", "This", ...
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L1093-L1119
train
dapphp/radius
src/Radius.php
Radius.accessRequestEapMsChapV2List
public function accessRequestEapMsChapV2List($serverList, $username, $password) { if (!is_array($serverList)) { $this->errorCode = 127; $this->errorMessage = sprintf( 'server list passed to accessRequestl must be array; %s given', gettype($serverList) ); return false; } foreach($serverList as $server) { $this->setServer($server); $result = $this->accessRequestEapMsChapV2($username, $password); if ($result === true) { break; // success } elseif ($this->getErrorCode() === self::TYPE_ACCESS_REJECT) { break; // access rejected } else { /* timeout or other possible transient error; try next host */ } } return $result; }
php
public function accessRequestEapMsChapV2List($serverList, $username, $password) { if (!is_array($serverList)) { $this->errorCode = 127; $this->errorMessage = sprintf( 'server list passed to accessRequestl must be array; %s given', gettype($serverList) ); return false; } foreach($serverList as $server) { $this->setServer($server); $result = $this->accessRequestEapMsChapV2($username, $password); if ($result === true) { break; // success } elseif ($this->getErrorCode() === self::TYPE_ACCESS_REJECT) { break; // access rejected } else { /* timeout or other possible transient error; try next host */ } } return $result; }
[ "public", "function", "accessRequestEapMsChapV2List", "(", "$", "serverList", ",", "$", "username", ",", "$", "password", ")", "{", "if", "(", "!", "is_array", "(", "$", "serverList", ")", ")", "{", "$", "this", "->", "errorCode", "=", "127", ";", "$", ...
Perform a EAP-MSCHAP v2 4-way authentication against a list of servers. Each server must share the same RADIUS secret. @see \Dapphp\Radius\Radius::accessRequestEapMsChapV2() @see \Dapphp\Radius\Radius::accessRequestList() @param array $serverList Array of servers to authenticate against @param string $username The username to authenticate as @param string $password The plain text password that will be hashed using MS-CHAPv2 @return boolean true if negotiation resulted in an Access-Accept packet, false otherwise
[ "Perform", "a", "EAP", "-", "MSCHAP", "v2", "4", "-", "way", "authentication", "against", "a", "list", "of", "servers", ".", "Each", "server", "must", "share", "the", "same", "RADIUS", "secret", "." ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L1312-L1338
train
dapphp/radius
src/Radius.php
Radius.sendRadiusRequest
private function sendRadiusRequest($packetData) { $packetLen = strlen($packetData); $conn = @fsockopen('udp://' . $this->server, $this->authenticationPort, $errno, $errstr); if (!$conn) { $this->errorCode = $errno; $this->errorMessage = $errstr; return false; } $sent = fwrite($conn, $packetData); if (!$sent || $packetLen != $sent) { $this->errorCode = 55; // CURLE_SEND_ERROR $this->errorMessage = 'Failed to send UDP packet'; return false; } if ($this->debug) { $this->debugInfo( sprintf( '<b>Packet type %d (%s) sent to %s</b>', $this->radiusPacket, $this->getRadiusPacketInfo($this->radiusPacket), $this->server ) ); foreach($this->attributesToSend as $attrs) { if (!is_array($attrs)) { $attrs = array($attrs); } foreach($attrs as $attr) { $attrInfo = $this->getAttributesInfo(ord(substr($attr, 0, 1))); $this->debugInfo( sprintf( 'Attribute %d (%s), length (%d), format %s, value <em>%s</em>', ord(substr($attr, 0, 1)), $attrInfo[0], ord(substr($attr, 1, 1)) - 2, $attrInfo[1], $this->decodeAttribute(substr($attr, 2), ord(substr($attr, 0, 1))) ) ); } } } return $conn; }
php
private function sendRadiusRequest($packetData) { $packetLen = strlen($packetData); $conn = @fsockopen('udp://' . $this->server, $this->authenticationPort, $errno, $errstr); if (!$conn) { $this->errorCode = $errno; $this->errorMessage = $errstr; return false; } $sent = fwrite($conn, $packetData); if (!$sent || $packetLen != $sent) { $this->errorCode = 55; // CURLE_SEND_ERROR $this->errorMessage = 'Failed to send UDP packet'; return false; } if ($this->debug) { $this->debugInfo( sprintf( '<b>Packet type %d (%s) sent to %s</b>', $this->radiusPacket, $this->getRadiusPacketInfo($this->radiusPacket), $this->server ) ); foreach($this->attributesToSend as $attrs) { if (!is_array($attrs)) { $attrs = array($attrs); } foreach($attrs as $attr) { $attrInfo = $this->getAttributesInfo(ord(substr($attr, 0, 1))); $this->debugInfo( sprintf( 'Attribute %d (%s), length (%d), format %s, value <em>%s</em>', ord(substr($attr, 0, 1)), $attrInfo[0], ord(substr($attr, 1, 1)) - 2, $attrInfo[1], $this->decodeAttribute(substr($attr, 2), ord(substr($attr, 0, 1))) ) ); } } } return $conn; }
[ "private", "function", "sendRadiusRequest", "(", "$", "packetData", ")", "{", "$", "packetLen", "=", "strlen", "(", "$", "packetData", ")", ";", "$", "conn", "=", "@", "fsockopen", "(", "'udp://'", ".", "$", "this", "->", "server", ",", "$", "this", "-...
Send a RADIUS packet over the wire using UDP. @param string $packetData The raw, complete, RADIUS packet to send @return boolean|resource false if the packet failed to send, or a socket resource on success
[ "Send", "a", "RADIUS", "packet", "over", "the", "wire", "using", "UDP", "." ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L1346-L1395
train
dapphp/radius
src/Radius.php
Radius.readRadiusResponse
private function readRadiusResponse($conn) { stream_set_blocking($conn, false); $read = array($conn); $write = null; $except = null; $receivedPacket = ''; $packetLen = null; $elapsed = 0; do { // Loop until the entire packet is read. Even with small packets, // not all data might get returned in one read on a non-blocking stream. $t0 = microtime(true); $changed = stream_select($read, $write, $except, $this->timeout); $t1 = microtime(true); if ($changed > 0) { $data = fgets($conn, 1024); // Try to read as much data from the stream in one pass until 4 // bytes are read. Once we have 4 bytes, we can determine the // length of the RADIUS response to know when to stop reading. if ($data === false) { // recv could fail due to ICMP destination unreachable $this->errorCode = 56; // CURLE_RECV_ERROR $this->errorMessage = 'Failure with receiving network data'; return false; } $receivedPacket .= $data; if (strlen($receivedPacket) < 4) { // not enough data to get the size // this will probably never happen continue; } if ($packetLen == null) { // first pass - decode the packet size from response $packetLen = unpack('n', substr($receivedPacket, 2, 2)); $packetLen = (int)array_shift($packetLen); if ($packetLen < 4 || $packetLen > 65507) { $this->errorCode = 102; $this->errorMessage = "Bad packet size in RADIUS response. Got {$packetLen}"; return false; } } } elseif ($changed === false) { $this->errorCode = 2; $this->errorMessage = 'stream_select returned false'; return false; } else { $this->errorCode = 28; // CURLE_OPERATION_TIMEDOUT $this->errorMessage = 'Timed out while waiting for RADIUS response'; return false; } $elapsed += ($t1 - $t0); } while ($elapsed < $this->timeout && strlen($receivedPacket) < $packetLen); return $receivedPacket; }
php
private function readRadiusResponse($conn) { stream_set_blocking($conn, false); $read = array($conn); $write = null; $except = null; $receivedPacket = ''; $packetLen = null; $elapsed = 0; do { // Loop until the entire packet is read. Even with small packets, // not all data might get returned in one read on a non-blocking stream. $t0 = microtime(true); $changed = stream_select($read, $write, $except, $this->timeout); $t1 = microtime(true); if ($changed > 0) { $data = fgets($conn, 1024); // Try to read as much data from the stream in one pass until 4 // bytes are read. Once we have 4 bytes, we can determine the // length of the RADIUS response to know when to stop reading. if ($data === false) { // recv could fail due to ICMP destination unreachable $this->errorCode = 56; // CURLE_RECV_ERROR $this->errorMessage = 'Failure with receiving network data'; return false; } $receivedPacket .= $data; if (strlen($receivedPacket) < 4) { // not enough data to get the size // this will probably never happen continue; } if ($packetLen == null) { // first pass - decode the packet size from response $packetLen = unpack('n', substr($receivedPacket, 2, 2)); $packetLen = (int)array_shift($packetLen); if ($packetLen < 4 || $packetLen > 65507) { $this->errorCode = 102; $this->errorMessage = "Bad packet size in RADIUS response. Got {$packetLen}"; return false; } } } elseif ($changed === false) { $this->errorCode = 2; $this->errorMessage = 'stream_select returned false'; return false; } else { $this->errorCode = 28; // CURLE_OPERATION_TIMEDOUT $this->errorMessage = 'Timed out while waiting for RADIUS response'; return false; } $elapsed += ($t1 - $t0); } while ($elapsed < $this->timeout && strlen($receivedPacket) < $packetLen); return $receivedPacket; }
[ "private", "function", "readRadiusResponse", "(", "$", "conn", ")", "{", "stream_set_blocking", "(", "$", "conn", ",", "false", ")", ";", "$", "read", "=", "array", "(", "$", "conn", ")", ";", "$", "write", "=", "null", ";", "$", "except", "=", "null...
Wait for a UDP response packet and read using a timeout. @param resource $conn The connection resource returned by fsockopen @return boolean|string false on failure, or the RADIUS response packet
[ "Wait", "for", "a", "UDP", "response", "packet", "and", "read", "using", "a", "timeout", "." ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L1403-L1469
train
dapphp/radius
src/MsChapV2Packet.php
MsChapV2Packet.fromString
public static function fromString($packet) { if (strlen($packet) < 5) { return false; } $p = new self(); $p->opcode = ord($packet[0]); $p->msChapId = ord($packet[1]); $temp = unpack('n', substr($packet, 2, 2)); $p->msLength = array_shift($temp); $p->valueSize = ord($packet[4]); switch($p->opcode) { case 1: // challenge $p->challenge = substr($packet, 5, 16); $p->name = substr($packet, -($p->msLength + 5 - $p->valueSize - 10)); break; case 2: // response break; case 3: // success break; case 4: // failure $p->response = substr($packet, 4); break; } return $p; }
php
public static function fromString($packet) { if (strlen($packet) < 5) { return false; } $p = new self(); $p->opcode = ord($packet[0]); $p->msChapId = ord($packet[1]); $temp = unpack('n', substr($packet, 2, 2)); $p->msLength = array_shift($temp); $p->valueSize = ord($packet[4]); switch($p->opcode) { case 1: // challenge $p->challenge = substr($packet, 5, 16); $p->name = substr($packet, -($p->msLength + 5 - $p->valueSize - 10)); break; case 2: // response break; case 3: // success break; case 4: // failure $p->response = substr($packet, 4); break; } return $p; }
[ "public", "static", "function", "fromString", "(", "$", "packet", ")", "{", "if", "(", "strlen", "(", "$", "packet", ")", "<", "5", ")", "{", "return", "false", ";", "}", "$", "p", "=", "new", "self", "(", ")", ";", "$", "p", "->", "opcode", "=...
Parse an MSCHAP v2 packet into a structure @param string $packet Raw MSCHAP v2 packet string @return \Dapphp\Radius\MsChapV2Packet The parsed packet structure
[ "Parse", "an", "MSCHAP", "v2", "packet", "into", "a", "structure" ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/MsChapV2Packet.php#L32-L63
train
wapmorgan/Mp3Info
src/Mp3Info.php
Mp3Info.readId3v1Body
private function readId3v1Body($fp) { $this->tags1['song'] = trim(fread($fp, 30)); $this->tags1['artist'] = trim(fread($fp, 30)); $this->tags1['album'] = trim(fread($fp, 30)); $this->tags1['year'] = trim(fread($fp, 4)); $this->tags1['comment'] = trim(fread($fp, 28)); fseek($fp, 1, SEEK_CUR); $this->tags1['track'] = ord(fread($fp, 1)); $this->tags1['genre'] = ord(fread($fp, 1)); return 128; }
php
private function readId3v1Body($fp) { $this->tags1['song'] = trim(fread($fp, 30)); $this->tags1['artist'] = trim(fread($fp, 30)); $this->tags1['album'] = trim(fread($fp, 30)); $this->tags1['year'] = trim(fread($fp, 4)); $this->tags1['comment'] = trim(fread($fp, 28)); fseek($fp, 1, SEEK_CUR); $this->tags1['track'] = ord(fread($fp, 1)); $this->tags1['genre'] = ord(fread($fp, 1)); return 128; }
[ "private", "function", "readId3v1Body", "(", "$", "fp", ")", "{", "$", "this", "->", "tags1", "[", "'song'", "]", "=", "trim", "(", "fread", "(", "$", "fp", ",", "30", ")", ")", ";", "$", "this", "->", "tags1", "[", "'artist'", "]", "=", "trim", ...
Reads id3v1 tag. @return int Returns length of id3v1 tag.
[ "Reads", "id3v1", "tag", "." ]
491bee5706683193b8965122755bd12c47f90560
https://github.com/wapmorgan/Mp3Info/blob/491bee5706683193b8965122755bd12c47f90560/src/Mp3Info.php#L353-L363
train
wapmorgan/Mp3Info
src/Mp3Info.php
Mp3Info.isValidAudio
static public function isValidAudio($filename) { if (!file_exists($filename)) throw new Exception('File '.$filename.' is not present!'); $raw = file_get_contents($filename, false, null, 0, 3); return ($raw == self::TAG2_SYNC || (self::FRAME_SYNC == (unpack('n*', $raw)[1] & self::FRAME_SYNC))); }
php
static public function isValidAudio($filename) { if (!file_exists($filename)) throw new Exception('File '.$filename.' is not present!'); $raw = file_get_contents($filename, false, null, 0, 3); return ($raw == self::TAG2_SYNC || (self::FRAME_SYNC == (unpack('n*', $raw)[1] & self::FRAME_SYNC))); }
[ "static", "public", "function", "isValidAudio", "(", "$", "filename", ")", "{", "if", "(", "!", "file_exists", "(", "$", "filename", ")", ")", "throw", "new", "Exception", "(", "'File '", ".", "$", "filename", ".", "' is not present!'", ")", ";", "$", "r...
Simple function that checks mpeg-audio correctness of given file. Actually it checks that first 3 bytes of file is a id3v2 tag mark or that first 11 bits of file is a frame header sync mark. To perform full test create an instance of Mp3Info with given file. @param string $filename File to be tested. @return boolean True if file is looks correct, False otherwise. @throws \Exception
[ "Simple", "function", "that", "checks", "mpeg", "-", "audio", "correctness", "of", "given", "file", ".", "Actually", "it", "checks", "that", "first", "3", "bytes", "of", "file", "is", "a", "id3v2", "tag", "mark", "or", "that", "first", "11", "bits", "of"...
491bee5706683193b8965122755bd12c47f90560
https://github.com/wapmorgan/Mp3Info/blob/491bee5706683193b8965122755bd12c47f90560/src/Mp3Info.php#L656-L661
train
mosbth/cimage
CAsciiArt.php
CAsciiArt.setOptions
public function setOptions($options = array()) { $default = array( "characterSet" => 'two', "scale" => 14, "luminanceStrategy" => 3, "customCharacterSet" => null, ); $default = array_merge($default, $options); if (!is_null($default['customCharacterSet'])) { $this->addCharacterSet('custom', $default['customCharacterSet']); $default['characterSet'] = 'custom'; } $this->scale = $default['scale']; $this->characters = $this->characterSet[$default['characterSet']]; $this->charCount = strlen($this->characters); $this->luminanceStrategy = $default['luminanceStrategy']; return $this; }
php
public function setOptions($options = array()) { $default = array( "characterSet" => 'two', "scale" => 14, "luminanceStrategy" => 3, "customCharacterSet" => null, ); $default = array_merge($default, $options); if (!is_null($default['customCharacterSet'])) { $this->addCharacterSet('custom', $default['customCharacterSet']); $default['characterSet'] = 'custom'; } $this->scale = $default['scale']; $this->characters = $this->characterSet[$default['characterSet']]; $this->charCount = strlen($this->characters); $this->luminanceStrategy = $default['luminanceStrategy']; return $this; }
[ "public", "function", "setOptions", "(", "$", "options", "=", "array", "(", ")", ")", "{", "$", "default", "=", "array", "(", "\"characterSet\"", "=>", "'two'", ",", "\"scale\"", "=>", "14", ",", "\"luminanceStrategy\"", "=>", "3", ",", "\"customCharacterSet...
Set options for processing, defaults are available. @param array $options to use as default settings. @return $this
[ "Set", "options", "for", "processing", "defaults", "are", "available", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CAsciiArt.php#L80-L101
train
mosbth/cimage
CAsciiArt.php
CAsciiArt.createFromFile
public function createFromFile($filename) { $img = imagecreatefromstring(file_get_contents($filename)); list($width, $height) = getimagesize($filename); $ascii = null; $incY = $this->scale; $incX = $this->scale / 2; for ($y = 0; $y < $height - 1; $y += $incY) { for ($x = 0; $x < $width - 1; $x += $incX) { $toX = min($x + $this->scale / 2, $width - 1); $toY = min($y + $this->scale, $height - 1); $luminance = $this->luminanceAreaAverage($img, $x, $y, $toX, $toY); $ascii .= $this->luminance2character($luminance); } $ascii .= PHP_EOL; } return $ascii; }
php
public function createFromFile($filename) { $img = imagecreatefromstring(file_get_contents($filename)); list($width, $height) = getimagesize($filename); $ascii = null; $incY = $this->scale; $incX = $this->scale / 2; for ($y = 0; $y < $height - 1; $y += $incY) { for ($x = 0; $x < $width - 1; $x += $incX) { $toX = min($x + $this->scale / 2, $width - 1); $toY = min($y + $this->scale, $height - 1); $luminance = $this->luminanceAreaAverage($img, $x, $y, $toX, $toY); $ascii .= $this->luminance2character($luminance); } $ascii .= PHP_EOL; } return $ascii; }
[ "public", "function", "createFromFile", "(", "$", "filename", ")", "{", "$", "img", "=", "imagecreatefromstring", "(", "file_get_contents", "(", "$", "filename", ")", ")", ";", "list", "(", "$", "width", ",", "$", "height", ")", "=", "getimagesize", "(", ...
Create an Ascii image from an image file. @param string $filename of the image to use. @return string $ascii with the ASCII image.
[ "Create", "an", "Ascii", "image", "from", "an", "image", "file", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CAsciiArt.php#L112-L132
train
mosbth/cimage
CAsciiArt.php
CAsciiArt.luminanceAreaAverage
public function luminanceAreaAverage($img, $x1, $y1, $x2, $y2) { $numPixels = ($x2 - $x1 + 1) * ($y2 - $y1 + 1); $luminance = 0; for ($x = $x1; $x <= $x2; $x++) { for ($y = $y1; $y <= $y2; $y++) { $rgb = imagecolorat($img, $x, $y); $red = (($rgb >> 16) & 0xFF); $green = (($rgb >> 8) & 0xFF); $blue = ($rgb & 0xFF); $luminance += $this->getLuminance($red, $green, $blue); } } return $luminance / $numPixels; }
php
public function luminanceAreaAverage($img, $x1, $y1, $x2, $y2) { $numPixels = ($x2 - $x1 + 1) * ($y2 - $y1 + 1); $luminance = 0; for ($x = $x1; $x <= $x2; $x++) { for ($y = $y1; $y <= $y2; $y++) { $rgb = imagecolorat($img, $x, $y); $red = (($rgb >> 16) & 0xFF); $green = (($rgb >> 8) & 0xFF); $blue = ($rgb & 0xFF); $luminance += $this->getLuminance($red, $green, $blue); } } return $luminance / $numPixels; }
[ "public", "function", "luminanceAreaAverage", "(", "$", "img", ",", "$", "x1", ",", "$", "y1", ",", "$", "x2", ",", "$", "y2", ")", "{", "$", "numPixels", "=", "(", "$", "x2", "-", "$", "x1", "+", "1", ")", "*", "(", "$", "y2", "-", "$", "y...
Get the luminance from a region of an image using average color value. @param string $img the image. @param integer $x1 the area to get pixels from. @param integer $y1 the area to get pixels from. @param integer $x2 the area to get pixels from. @param integer $y2 the area to get pixels from. @return integer $luminance with a value between 0 and 100.
[ "Get", "the", "luminance", "from", "a", "region", "of", "an", "image", "using", "average", "color", "value", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CAsciiArt.php#L147-L163
train
mosbth/cimage
CAsciiArt.php
CAsciiArt.getLuminance
public function getLuminance($red, $green, $blue) { switch ($this->luminanceStrategy) { case 1: $luminance = ($red * 0.2126 + $green * 0.7152 + $blue * 0.0722) / 255; break; case 2: $luminance = ($red * 0.299 + $green * 0.587 + $blue * 0.114) / 255; break; case 3: $luminance = sqrt(0.299 * pow($red, 2) + 0.587 * pow($green, 2) + 0.114 * pow($blue, 2)) / 255; break; case 0: default: $luminance = ($red + $green + $blue) / (255 * 3); } return $luminance; }
php
public function getLuminance($red, $green, $blue) { switch ($this->luminanceStrategy) { case 1: $luminance = ($red * 0.2126 + $green * 0.7152 + $blue * 0.0722) / 255; break; case 2: $luminance = ($red * 0.299 + $green * 0.587 + $blue * 0.114) / 255; break; case 3: $luminance = sqrt(0.299 * pow($red, 2) + 0.587 * pow($green, 2) + 0.114 * pow($blue, 2)) / 255; break; case 0: default: $luminance = ($red + $green + $blue) / (255 * 3); } return $luminance; }
[ "public", "function", "getLuminance", "(", "$", "red", ",", "$", "green", ",", "$", "blue", ")", "{", "switch", "(", "$", "this", "->", "luminanceStrategy", ")", "{", "case", "1", ":", "$", "luminance", "=", "(", "$", "red", "*", "0.2126", "+", "$"...
Calculate luminance value with different strategies. @param integer $red The color red. @param integer $green The color green. @param integer $blue The color blue. @return float $luminance with a value between 0 and 1.
[ "Calculate", "luminance", "value", "with", "different", "strategies", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CAsciiArt.php#L176-L194
train
mosbth/cimage
CAsciiArt.php
CAsciiArt.luminance2character
public function luminance2character($luminance) { $position = (int) round($luminance * ($this->charCount - 1)); $char = $this->characters[$position]; return $char; }
php
public function luminance2character($luminance) { $position = (int) round($luminance * ($this->charCount - 1)); $char = $this->characters[$position]; return $char; }
[ "public", "function", "luminance2character", "(", "$", "luminance", ")", "{", "$", "position", "=", "(", "int", ")", "round", "(", "$", "luminance", "*", "(", "$", "this", "->", "charCount", "-", "1", ")", ")", ";", "$", "char", "=", "$", "this", "...
Translate the luminance value to a character. @param string $position a value between 0-100 representing the luminance. @return string with the ascii character.
[ "Translate", "the", "luminance", "value", "to", "a", "character", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CAsciiArt.php#L206-L211
train
mosbth/cimage
CImage.php
CImage.injectDependency
public function injectDependency($property, $object) { if (!property_exists($this, $property)) { $this->raiseError("Injecting unknown property."); } $this->$property = $object; return $this; }
php
public function injectDependency($property, $object) { if (!property_exists($this, $property)) { $this->raiseError("Injecting unknown property."); } $this->$property = $object; return $this; }
[ "public", "function", "injectDependency", "(", "$", "property", ",", "$", "object", ")", "{", "if", "(", "!", "property_exists", "(", "$", "this", ",", "$", "property", ")", ")", "{", "$", "this", "->", "raiseError", "(", "\"Injecting unknown property.\"", ...
Inject object and use it, must be available as member. @param string $property to set as object. @param object $object to set to property. @return $this
[ "Inject", "object", "and", "use", "it", "must", "be", "available", "as", "member", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L478-L485
train
mosbth/cimage
CImage.php
CImage.setRemoteDownload
public function setRemoteDownload($allow, $cache, $pattern = null) { $this->allowRemote = $allow; $this->remoteCache = $cache; $this->remotePattern = is_null($pattern) ? $this->remotePattern : $pattern; $this->log( "Set remote download to: " . ($this->allowRemote ? "true" : "false") . " using pattern " . $this->remotePattern ); return $this; }
php
public function setRemoteDownload($allow, $cache, $pattern = null) { $this->allowRemote = $allow; $this->remoteCache = $cache; $this->remotePattern = is_null($pattern) ? $this->remotePattern : $pattern; $this->log( "Set remote download to: " . ($this->allowRemote ? "true" : "false") . " using pattern " . $this->remotePattern ); return $this; }
[ "public", "function", "setRemoteDownload", "(", "$", "allow", ",", "$", "cache", ",", "$", "pattern", "=", "null", ")", "{", "$", "this", "->", "allowRemote", "=", "$", "allow", ";", "$", "this", "->", "remoteCache", "=", "$", "cache", ";", "$", "thi...
Allow or disallow remote image download. @param boolean $allow true or false to enable and disable. @param string $cache path to cache dir. @param string $pattern to use to detect if its a remote file. @return $this
[ "Allow", "or", "disallow", "remote", "image", "download", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L567-L581
train
mosbth/cimage
CImage.php
CImage.isRemoteSource
public function isRemoteSource($src) { $remote = preg_match($this->remotePattern, $src); $this->log("Detected remote image: " . ($remote ? "true" : "false")); return !!$remote; }
php
public function isRemoteSource($src) { $remote = preg_match($this->remotePattern, $src); $this->log("Detected remote image: " . ($remote ? "true" : "false")); return !!$remote; }
[ "public", "function", "isRemoteSource", "(", "$", "src", ")", "{", "$", "remote", "=", "preg_match", "(", "$", "this", "->", "remotePattern", ",", "$", "src", ")", ";", "$", "this", "->", "log", "(", "\"Detected remote image: \"", ".", "(", "$", "remote"...
Check if the image resource is a remote file or not. @param string $src check if src is remote. @return boolean true if $src is a remote file, else false.
[ "Check", "if", "the", "image", "resource", "is", "a", "remote", "file", "or", "not", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L592-L597
train
mosbth/cimage
CImage.php
CImage.setRemoteHostWhitelist
public function setRemoteHostWhitelist($whitelist = null) { $this->remoteHostWhitelist = $whitelist; $this->log( "Setting remote host whitelist to: " . (is_null($whitelist) ? "null" : print_r($whitelist, 1)) ); return $this; }
php
public function setRemoteHostWhitelist($whitelist = null) { $this->remoteHostWhitelist = $whitelist; $this->log( "Setting remote host whitelist to: " . (is_null($whitelist) ? "null" : print_r($whitelist, 1)) ); return $this; }
[ "public", "function", "setRemoteHostWhitelist", "(", "$", "whitelist", "=", "null", ")", "{", "$", "this", "->", "remoteHostWhitelist", "=", "$", "whitelist", ";", "$", "this", "->", "log", "(", "\"Setting remote host whitelist to: \"", ".", "(", "is_null", "(",...
Set whitelist for valid hostnames from where remote source can be downloaded. @param array $whitelist with regexp hostnames to allow download from. @return $this
[ "Set", "whitelist", "for", "valid", "hostnames", "from", "where", "remote", "source", "can", "be", "downloaded", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L609-L617
train
mosbth/cimage
CImage.php
CImage.isRemoteSourceOnWhitelist
public function isRemoteSourceOnWhitelist($src) { if (is_null($this->remoteHostWhitelist)) { $this->log("Remote host on whitelist not configured - allowing."); return true; } $whitelist = new CWhitelist(); $hostname = parse_url($src, PHP_URL_HOST); $allow = $whitelist->check($hostname, $this->remoteHostWhitelist); $this->log( "Remote host is on whitelist: " . ($allow ? "true" : "false") ); return $allow; }
php
public function isRemoteSourceOnWhitelist($src) { if (is_null($this->remoteHostWhitelist)) { $this->log("Remote host on whitelist not configured - allowing."); return true; } $whitelist = new CWhitelist(); $hostname = parse_url($src, PHP_URL_HOST); $allow = $whitelist->check($hostname, $this->remoteHostWhitelist); $this->log( "Remote host is on whitelist: " . ($allow ? "true" : "false") ); return $allow; }
[ "public", "function", "isRemoteSourceOnWhitelist", "(", "$", "src", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "remoteHostWhitelist", ")", ")", "{", "$", "this", "->", "log", "(", "\"Remote host on whitelist not configured - allowing.\"", ")", ";", ...
Check if the hostname for the remote image, is on a whitelist, if the whitelist is defined. @param string $src the remote source. @return boolean true if hostname on $src is in the whitelist, else false.
[ "Check", "if", "the", "hostname", "for", "the", "remote", "image", "is", "on", "a", "whitelist", "if", "the", "whitelist", "is", "defined", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L629-L645
train
mosbth/cimage
CImage.php
CImage.checkFileExtension
private function checkFileExtension($extension) { $valid = array('jpg', 'jpeg', 'png', 'gif', 'webp'); in_array(strtolower($extension), $valid) or $this->raiseError('Not a valid file extension.'); return $this; }
php
private function checkFileExtension($extension) { $valid = array('jpg', 'jpeg', 'png', 'gif', 'webp'); in_array(strtolower($extension), $valid) or $this->raiseError('Not a valid file extension.'); return $this; }
[ "private", "function", "checkFileExtension", "(", "$", "extension", ")", "{", "$", "valid", "=", "array", "(", "'jpg'", ",", "'jpeg'", ",", "'png'", ",", "'gif'", ",", "'webp'", ")", ";", "in_array", "(", "strtolower", "(", "$", "extension", ")", ",", ...
Check if file extension is valid as a file extension. @param string $extension of image file. @return $this
[ "Check", "if", "file", "extension", "is", "valid", "as", "a", "file", "extension", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L656-L664
train
mosbth/cimage
CImage.php
CImage.normalizeFileExtension
private function normalizeFileExtension($extension = null) { $extension = strtolower($extension ? $extension : $this->extension); if ($extension == 'jpeg') { $extension = 'jpg'; } return $extension; }
php
private function normalizeFileExtension($extension = null) { $extension = strtolower($extension ? $extension : $this->extension); if ($extension == 'jpeg') { $extension = 'jpg'; } return $extension; }
[ "private", "function", "normalizeFileExtension", "(", "$", "extension", "=", "null", ")", "{", "$", "extension", "=", "strtolower", "(", "$", "extension", "?", "$", "extension", ":", "$", "this", "->", "extension", ")", ";", "if", "(", "$", "extension", ...
Normalize the file extension. @param string $extension of image file or skip to use internal. @return string $extension as a normalized file extension.
[ "Normalize", "the", "file", "extension", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L675-L684
train
mosbth/cimage
CImage.php
CImage.downloadRemoteSource
public function downloadRemoteSource($src) { if (!$this->isRemoteSourceOnWhitelist($src)) { throw new Exception("Hostname is not on whitelist for remote sources."); } $remote = new CRemoteImage(); if (!is_writable($this->remoteCache)) { $this->log("The remote cache is not writable."); } $remote->setCache($this->remoteCache); $remote->useCache($this->useCache); $src = $remote->download($src); $this->log("Remote HTTP status: " . $remote->getStatus()); $this->log("Remote item is in local cache: $src"); $this->log("Remote details on cache:" . print_r($remote->getDetails(), true)); return $src; }
php
public function downloadRemoteSource($src) { if (!$this->isRemoteSourceOnWhitelist($src)) { throw new Exception("Hostname is not on whitelist for remote sources."); } $remote = new CRemoteImage(); if (!is_writable($this->remoteCache)) { $this->log("The remote cache is not writable."); } $remote->setCache($this->remoteCache); $remote->useCache($this->useCache); $src = $remote->download($src); $this->log("Remote HTTP status: " . $remote->getStatus()); $this->log("Remote item is in local cache: $src"); $this->log("Remote details on cache:" . print_r($remote->getDetails(), true)); return $src; }
[ "public", "function", "downloadRemoteSource", "(", "$", "src", ")", "{", "if", "(", "!", "$", "this", "->", "isRemoteSourceOnWhitelist", "(", "$", "src", ")", ")", "{", "throw", "new", "Exception", "(", "\"Hostname is not on whitelist for remote sources.\"", ")", ...
Download a remote image and return path to its local copy. @param string $src remote path to image. @return string as path to downloaded remote source.
[ "Download", "a", "remote", "image", "and", "return", "path", "to", "its", "local", "copy", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L695-L716
train
mosbth/cimage
CImage.php
CImage.setSource
public function setSource($src, $dir = null) { if (!isset($src)) { $this->imageSrc = null; $this->pathToImage = null; return $this; } if ($this->allowRemote && $this->isRemoteSource($src)) { $src = $this->downloadRemoteSource($src); $dir = null; } if (!isset($dir)) { $dir = dirname($src); $src = basename($src); } $this->imageSrc = ltrim($src, '/'); $imageFolder = rtrim($dir, '/'); $this->pathToImage = $imageFolder . '/' . $this->imageSrc; return $this; }
php
public function setSource($src, $dir = null) { if (!isset($src)) { $this->imageSrc = null; $this->pathToImage = null; return $this; } if ($this->allowRemote && $this->isRemoteSource($src)) { $src = $this->downloadRemoteSource($src); $dir = null; } if (!isset($dir)) { $dir = dirname($src); $src = basename($src); } $this->imageSrc = ltrim($src, '/'); $imageFolder = rtrim($dir, '/'); $this->pathToImage = $imageFolder . '/' . $this->imageSrc; return $this; }
[ "public", "function", "setSource", "(", "$", "src", ",", "$", "dir", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "src", ")", ")", "{", "$", "this", "->", "imageSrc", "=", "null", ";", "$", "this", "->", "pathToImage", "=", "null", ...
Set source file to use as image source. @param string $src of image. @param string $dir as optional base directory where images are. @return $this
[ "Set", "source", "file", "to", "use", "as", "image", "source", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L728-L751
train
mosbth/cimage
CImage.php
CImage.mapFilter
private function mapFilter($name) { $map = array( 'negate' => array('id'=>0, 'argc'=>0, 'type'=>IMG_FILTER_NEGATE), 'grayscale' => array('id'=>1, 'argc'=>0, 'type'=>IMG_FILTER_GRAYSCALE), 'brightness' => array('id'=>2, 'argc'=>1, 'type'=>IMG_FILTER_BRIGHTNESS), 'contrast' => array('id'=>3, 'argc'=>1, 'type'=>IMG_FILTER_CONTRAST), 'colorize' => array('id'=>4, 'argc'=>4, 'type'=>IMG_FILTER_COLORIZE), 'edgedetect' => array('id'=>5, 'argc'=>0, 'type'=>IMG_FILTER_EDGEDETECT), 'emboss' => array('id'=>6, 'argc'=>0, 'type'=>IMG_FILTER_EMBOSS), 'gaussian_blur' => array('id'=>7, 'argc'=>0, 'type'=>IMG_FILTER_GAUSSIAN_BLUR), 'selective_blur' => array('id'=>8, 'argc'=>0, 'type'=>IMG_FILTER_SELECTIVE_BLUR), 'mean_removal' => array('id'=>9, 'argc'=>0, 'type'=>IMG_FILTER_MEAN_REMOVAL), 'smooth' => array('id'=>10, 'argc'=>1, 'type'=>IMG_FILTER_SMOOTH), 'pixelate' => array('id'=>11, 'argc'=>2, 'type'=>IMG_FILTER_PIXELATE), ); if (isset($map[$name])) { return $map[$name]; } else { throw new Exception('No such filter.'); } }
php
private function mapFilter($name) { $map = array( 'negate' => array('id'=>0, 'argc'=>0, 'type'=>IMG_FILTER_NEGATE), 'grayscale' => array('id'=>1, 'argc'=>0, 'type'=>IMG_FILTER_GRAYSCALE), 'brightness' => array('id'=>2, 'argc'=>1, 'type'=>IMG_FILTER_BRIGHTNESS), 'contrast' => array('id'=>3, 'argc'=>1, 'type'=>IMG_FILTER_CONTRAST), 'colorize' => array('id'=>4, 'argc'=>4, 'type'=>IMG_FILTER_COLORIZE), 'edgedetect' => array('id'=>5, 'argc'=>0, 'type'=>IMG_FILTER_EDGEDETECT), 'emboss' => array('id'=>6, 'argc'=>0, 'type'=>IMG_FILTER_EMBOSS), 'gaussian_blur' => array('id'=>7, 'argc'=>0, 'type'=>IMG_FILTER_GAUSSIAN_BLUR), 'selective_blur' => array('id'=>8, 'argc'=>0, 'type'=>IMG_FILTER_SELECTIVE_BLUR), 'mean_removal' => array('id'=>9, 'argc'=>0, 'type'=>IMG_FILTER_MEAN_REMOVAL), 'smooth' => array('id'=>10, 'argc'=>1, 'type'=>IMG_FILTER_SMOOTH), 'pixelate' => array('id'=>11, 'argc'=>2, 'type'=>IMG_FILTER_PIXELATE), ); if (isset($map[$name])) { return $map[$name]; } else { throw new Exception('No such filter.'); } }
[ "private", "function", "mapFilter", "(", "$", "name", ")", "{", "$", "map", "=", "array", "(", "'negate'", "=>", "array", "(", "'id'", "=>", "0", ",", "'argc'", "=>", "0", ",", "'type'", "=>", "IMG_FILTER_NEGATE", ")", ",", "'grayscale'", "=>", "array"...
Map filter name to PHP filter and id. @param string $name the name of the filter. @return array with filter settings @throws Exception
[ "Map", "filter", "name", "to", "PHP", "filter", "and", "id", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L921-L943
train
mosbth/cimage
CImage.php
CImage.loadImageDetails
public function loadImageDetails($file = null) { $file = $file ? $file : $this->pathToImage; is_readable($file) or $this->raiseError('Image file does not exist.'); $info = list($this->width, $this->height, $this->fileType) = getimagesize($file); if (empty($info)) { // To support webp $this->fileType = false; if (function_exists("exif_imagetype")) { $this->fileType = exif_imagetype($file); if ($this->fileType === false) { if (function_exists("imagecreatefromwebp")) { $webp = imagecreatefromwebp($file); if ($webp !== false) { $this->width = imagesx($webp); $this->height = imagesy($webp); $this->fileType = IMG_WEBP; } } } } } if (!$this->fileType) { throw new Exception("Loading image details, the file doesn't seem to be a valid image."); } if ($this->verbose) { $this->log("Loading image details for: {$file}"); $this->log(" Image width x height (type): {$this->width} x {$this->height} ({$this->fileType})."); $this->log(" Image filesize: " . filesize($file) . " bytes."); $this->log(" Image mimetype: " . $this->getMimeType()); } return $this; }
php
public function loadImageDetails($file = null) { $file = $file ? $file : $this->pathToImage; is_readable($file) or $this->raiseError('Image file does not exist.'); $info = list($this->width, $this->height, $this->fileType) = getimagesize($file); if (empty($info)) { // To support webp $this->fileType = false; if (function_exists("exif_imagetype")) { $this->fileType = exif_imagetype($file); if ($this->fileType === false) { if (function_exists("imagecreatefromwebp")) { $webp = imagecreatefromwebp($file); if ($webp !== false) { $this->width = imagesx($webp); $this->height = imagesy($webp); $this->fileType = IMG_WEBP; } } } } } if (!$this->fileType) { throw new Exception("Loading image details, the file doesn't seem to be a valid image."); } if ($this->verbose) { $this->log("Loading image details for: {$file}"); $this->log(" Image width x height (type): {$this->width} x {$this->height} ({$this->fileType})."); $this->log(" Image filesize: " . filesize($file) . " bytes."); $this->log(" Image mimetype: " . $this->getMimeType()); } return $this; }
[ "public", "function", "loadImageDetails", "(", "$", "file", "=", "null", ")", "{", "$", "file", "=", "$", "file", "?", "$", "file", ":", "$", "this", "->", "pathToImage", ";", "is_readable", "(", "$", "file", ")", "or", "$", "this", "->", "raiseError...
Load image details from original image file. @param string $file the file to load or null to use $this->pathToImage. @return $this @throws Exception
[ "Load", "image", "details", "from", "original", "image", "file", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L955-L993
train