repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
paulgibbs/behat-wordpress-extension
src/Driver/Element/Wpcli/CommentElement.php
CommentElement.create
public function create($args) { $wpcli_args = buildCLIArgs( array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_date', 'comment_date_gmt', 'comment_parent', 'comment_post_ID', 'user_id', 'comment_agent', 'comment_author_IP', 'comment_approved', 'comment_karma', 'comment_type', ), $args ); array_unshift($wpcli_args, '--porcelain'); $comment_id = (int) $this->drivers->getDriver()->wpcli('comment', 'create', $wpcli_args)['stdout']; return $this->get($comment_id); }
php
public function create($args) { $wpcli_args = buildCLIArgs( array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_date', 'comment_date_gmt', 'comment_parent', 'comment_post_ID', 'user_id', 'comment_agent', 'comment_author_IP', 'comment_approved', 'comment_karma', 'comment_type', ), $args ); array_unshift($wpcli_args, '--porcelain'); $comment_id = (int) $this->drivers->getDriver()->wpcli('comment', 'create', $wpcli_args)['stdout']; return $this->get($comment_id); }
[ "public", "function", "create", "(", "$", "args", ")", "{", "$", "wpcli_args", "=", "buildCLIArgs", "(", "array", "(", "'comment_author'", ",", "'comment_author_email'", ",", "'comment_author_url'", ",", "'comment_content'", ",", "'comment_date'", ",", "'comment_date_gmt'", ",", "'comment_parent'", ",", "'comment_post_ID'", ",", "'user_id'", ",", "'comment_agent'", ",", "'comment_author_IP'", ",", "'comment_approved'", ",", "'comment_karma'", ",", "'comment_type'", ",", ")", ",", "$", "args", ")", ";", "array_unshift", "(", "$", "wpcli_args", ",", "'--porcelain'", ")", ";", "$", "comment_id", "=", "(", "int", ")", "$", "this", "->", "drivers", "->", "getDriver", "(", ")", "->", "wpcli", "(", "'comment'", ",", "'create'", ",", "$", "wpcli_args", ")", "[", "'stdout'", "]", ";", "return", "$", "this", "->", "get", "(", "$", "comment_id", ")", ";", "}" ]
Create an item for this element. @param array $args Data used to create an object. @return mixed The new item.
[ "Create", "an", "item", "for", "this", "element", "." ]
train
https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpcli/CommentElement.php#L21-L36
paulgibbs/behat-wordpress-extension
src/Driver/Element/Wpcli/CommentElement.php
CommentElement.get
public function get($id, $args = []) { $wpcli_args = buildCLIArgs( array( 'field', 'fields', ), $args ); array_unshift($wpcli_args, $id, '--format=json'); $comment = $this->drivers->getDriver()->wpcli('comment', 'get', $wpcli_args)['stdout']; $comment = json_decode($comment); if (! $comment) { throw new UnexpectedValueException(sprintf('[W500] Could not find comment with ID %d', $id)); } return $comment; }
php
public function get($id, $args = []) { $wpcli_args = buildCLIArgs( array( 'field', 'fields', ), $args ); array_unshift($wpcli_args, $id, '--format=json'); $comment = $this->drivers->getDriver()->wpcli('comment', 'get', $wpcli_args)['stdout']; $comment = json_decode($comment); if (! $comment) { throw new UnexpectedValueException(sprintf('[W500] Could not find comment with ID %d', $id)); } return $comment; }
[ "public", "function", "get", "(", "$", "id", ",", "$", "args", "=", "[", "]", ")", "{", "$", "wpcli_args", "=", "buildCLIArgs", "(", "array", "(", "'field'", ",", "'fields'", ",", ")", ",", "$", "args", ")", ";", "array_unshift", "(", "$", "wpcli_args", ",", "$", "id", ",", "'--format=json'", ")", ";", "$", "comment", "=", "$", "this", "->", "drivers", "->", "getDriver", "(", ")", "->", "wpcli", "(", "'comment'", ",", "'get'", ",", "$", "wpcli_args", ")", "[", "'stdout'", "]", ";", "$", "comment", "=", "json_decode", "(", "$", "comment", ")", ";", "if", "(", "!", "$", "comment", ")", "{", "throw", "new", "UnexpectedValueException", "(", "sprintf", "(", "'[W500] Could not find comment with ID %d'", ",", "$", "id", ")", ")", ";", "}", "return", "$", "comment", ";", "}" ]
Retrieve an item for this element. @param int|string $id Object ID. @param array $args Optional data used to fetch an object. @throws \UnexpectedValueException @return mixed The item.
[ "Retrieve", "an", "item", "for", "this", "element", "." ]
train
https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpcli/CommentElement.php#L48-L67
paulgibbs/behat-wordpress-extension
src/Driver/Element/Wpcli/CommentElement.php
CommentElement.delete
public function delete($id, $args = []) { $wpcli_args = buildCLIArgs( ['force'], $args ); array_unshift($wpcli_args, $id); $this->drivers->getDriver()->wpcli('comment', 'delete', $wpcli_args); }
php
public function delete($id, $args = []) { $wpcli_args = buildCLIArgs( ['force'], $args ); array_unshift($wpcli_args, $id); $this->drivers->getDriver()->wpcli('comment', 'delete', $wpcli_args); }
[ "public", "function", "delete", "(", "$", "id", ",", "$", "args", "=", "[", "]", ")", "{", "$", "wpcli_args", "=", "buildCLIArgs", "(", "[", "'force'", "]", ",", "$", "args", ")", ";", "array_unshift", "(", "$", "wpcli_args", ",", "$", "id", ")", ";", "$", "this", "->", "drivers", "->", "getDriver", "(", ")", "->", "wpcli", "(", "'comment'", ",", "'delete'", ",", "$", "wpcli_args", ")", ";", "}" ]
Delete an item for this element. @param int|string $id Object ID. @param array $args Optional data used to delete an object.
[ "Delete", "an", "item", "for", "this", "element", "." ]
train
https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpcli/CommentElement.php#L75-L85
paulgibbs/behat-wordpress-extension
src/Listener/DriverListener.php
DriverListener.prepareWordpressDriver
public function prepareWordpressDriver($event) { $drivers = array_keys($this->wordpress->getDrivers()); $driver = $this->parameters['default_driver']; $tags = array_merge($event->getFeature()->getTags(), $event->getScenario()->getTags()); // If the scenario or outline is tagged with a specific driver, switch to it. foreach ($tags as $tag) { if (! in_array($tag, $drivers, true)) { continue; } $driver = $tag; break; } $this->wordpress->setDefaultDriverName($driver); }
php
public function prepareWordpressDriver($event) { $drivers = array_keys($this->wordpress->getDrivers()); $driver = $this->parameters['default_driver']; $tags = array_merge($event->getFeature()->getTags(), $event->getScenario()->getTags()); // If the scenario or outline is tagged with a specific driver, switch to it. foreach ($tags as $tag) { if (! in_array($tag, $drivers, true)) { continue; } $driver = $tag; break; } $this->wordpress->setDefaultDriverName($driver); }
[ "public", "function", "prepareWordpressDriver", "(", "$", "event", ")", "{", "$", "drivers", "=", "array_keys", "(", "$", "this", "->", "wordpress", "->", "getDrivers", "(", ")", ")", ";", "$", "driver", "=", "$", "this", "->", "parameters", "[", "'default_driver'", "]", ";", "$", "tags", "=", "array_merge", "(", "$", "event", "->", "getFeature", "(", ")", "->", "getTags", "(", ")", ",", "$", "event", "->", "getScenario", "(", ")", "->", "getTags", "(", ")", ")", ";", "// If the scenario or outline is tagged with a specific driver, switch to it.", "foreach", "(", "$", "tags", "as", "$", "tag", ")", "{", "if", "(", "!", "in_array", "(", "$", "tag", ",", "$", "drivers", ",", "true", ")", ")", "{", "continue", ";", "}", "$", "driver", "=", "$", "tag", ";", "break", ";", "}", "$", "this", "->", "wordpress", "->", "setDefaultDriverName", "(", "$", "driver", ")", ";", "}" ]
Configures the driver to use before each scenario or outline. @param ScenarioLikeTested $event
[ "Configures", "the", "driver", "to", "use", "before", "each", "scenario", "or", "outline", "." ]
train
https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Listener/DriverListener.php#L62-L79
paulgibbs/behat-wordpress-extension
src/Context/UserContext.php
UserContext.getUserByName
protected function getUserByName(string $username) { $found_user = null; $users = $this->getWordpressParameter('users'); foreach ($users as $user) { if ($username === $user['username']) { $found_user = $user; break; } } if ($found_user === null) { throw new RuntimeException("[W801] User not found for name \"{$username}\""); } return $found_user; }
php
protected function getUserByName(string $username) { $found_user = null; $users = $this->getWordpressParameter('users'); foreach ($users as $user) { if ($username === $user['username']) { $found_user = $user; break; } } if ($found_user === null) { throw new RuntimeException("[W801] User not found for name \"{$username}\""); } return $found_user; }
[ "protected", "function", "getUserByName", "(", "string", "$", "username", ")", "{", "$", "found_user", "=", "null", ";", "$", "users", "=", "$", "this", "->", "getWordpressParameter", "(", "'users'", ")", ";", "foreach", "(", "$", "users", "as", "$", "user", ")", "{", "if", "(", "$", "username", "===", "$", "user", "[", "'username'", "]", ")", "{", "$", "found_user", "=", "$", "user", ";", "break", ";", "}", "}", "if", "(", "$", "found_user", "===", "null", ")", "{", "throw", "new", "RuntimeException", "(", "\"[W801] User not found for name \\\"{$username}\\\"\"", ")", ";", "}", "return", "$", "found_user", ";", "}" ]
Verify a username is valid and get the matching user information. @param string $username @throws \RuntimeException @return array The WordPress user details matching the given username.
[ "Verify", "a", "username", "is", "valid", "and", "get", "the", "matching", "user", "information", "." ]
train
https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/UserContext.php#L25-L42
paulgibbs/behat-wordpress-extension
src/Context/UserContext.php
UserContext.thereAreUsers
public function thereAreUsers(TableNode $users) { $params = $this->getWordpressParameters(); foreach ($users->getHash() as $user) { if (! isset($user['user_pass'])) { $user['user_pass'] = $this->getRandomString(); } $this->createUser($user['user_login'], $user['user_email'], $user); $params['users'][] = array( 'roles' => $this->getUserDataFromUsername('roles', $user['user_login']), 'username' => $user['user_login'], 'password' => $user['user_pass'], ); } $this->setWordpressParameters($params); }
php
public function thereAreUsers(TableNode $users) { $params = $this->getWordpressParameters(); foreach ($users->getHash() as $user) { if (! isset($user['user_pass'])) { $user['user_pass'] = $this->getRandomString(); } $this->createUser($user['user_login'], $user['user_email'], $user); $params['users'][] = array( 'roles' => $this->getUserDataFromUsername('roles', $user['user_login']), 'username' => $user['user_login'], 'password' => $user['user_pass'], ); } $this->setWordpressParameters($params); }
[ "public", "function", "thereAreUsers", "(", "TableNode", "$", "users", ")", "{", "$", "params", "=", "$", "this", "->", "getWordpressParameters", "(", ")", ";", "foreach", "(", "$", "users", "->", "getHash", "(", ")", "as", "$", "user", ")", "{", "if", "(", "!", "isset", "(", "$", "user", "[", "'user_pass'", "]", ")", ")", "{", "$", "user", "[", "'user_pass'", "]", "=", "$", "this", "->", "getRandomString", "(", ")", ";", "}", "$", "this", "->", "createUser", "(", "$", "user", "[", "'user_login'", "]", ",", "$", "user", "[", "'user_email'", "]", ",", "$", "user", ")", ";", "$", "params", "[", "'users'", "]", "[", "]", "=", "array", "(", "'roles'", "=>", "$", "this", "->", "getUserDataFromUsername", "(", "'roles'", ",", "$", "user", "[", "'user_login'", "]", ")", ",", "'username'", "=>", "$", "user", "[", "'user_login'", "]", ",", "'password'", "=>", "$", "user", "[", "'user_pass'", "]", ",", ")", ";", "}", "$", "this", "->", "setWordpressParameters", "(", "$", "params", ")", ";", "}" ]
Add specified user accounts. Example: Given there are users: | user_login | user_email | role | | admin | admin@example.com | administrator | @Given /^(?:there are|there is a) users?:/ @param TableNode $users
[ "Add", "specified", "user", "accounts", "." ]
train
https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/UserContext.php#L55-L74
paulgibbs/behat-wordpress-extension
src/Context/UserContext.php
UserContext.iAmViewingAuthorArchive
public function iAmViewingAuthorArchive(string $username) { $found_user = $this->getUserByName($username); $this->visitPath(sprintf( $this->getWordpressParameters()['permalinks']['author_archive'], $this->getUserDataFromUsername('user_nicename', $found_user['username']) )); }
php
public function iAmViewingAuthorArchive(string $username) { $found_user = $this->getUserByName($username); $this->visitPath(sprintf( $this->getWordpressParameters()['permalinks']['author_archive'], $this->getUserDataFromUsername('user_nicename', $found_user['username']) )); }
[ "public", "function", "iAmViewingAuthorArchive", "(", "string", "$", "username", ")", "{", "$", "found_user", "=", "$", "this", "->", "getUserByName", "(", "$", "username", ")", ";", "$", "this", "->", "visitPath", "(", "sprintf", "(", "$", "this", "->", "getWordpressParameters", "(", ")", "[", "'permalinks'", "]", "[", "'author_archive'", "]", ",", "$", "this", "->", "getUserDataFromUsername", "(", "'user_nicename'", ",", "$", "found_user", "[", "'username'", "]", ")", ")", ")", ";", "}" ]
Go to a user's author archive page. Example: When I am viewing posts published by Paul @When /^(?:I am|they are) viewing posts published by (.+)$/ @param string $username
[ "Go", "to", "a", "user", "s", "author", "archive", "page", "." ]
train
https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/UserContext.php#L99-L107
paulgibbs/behat-wordpress-extension
src/Context/UserContext.php
UserContext.iAmLoggedInAsRole
public function iAmLoggedInAsRole(string $role) { $found_user = null; $users = $this->getWordpressParameter('users'); foreach ($users as $user) { if (in_array($role, $user['roles'], true)) { $found_user = $user; break; } } if ($found_user === null) { throw new RuntimeException("[W801] User not found for role \"{$role}\""); } $this->logIn($found_user['username'], $found_user['password']); }
php
public function iAmLoggedInAsRole(string $role) { $found_user = null; $users = $this->getWordpressParameter('users'); foreach ($users as $user) { if (in_array($role, $user['roles'], true)) { $found_user = $user; break; } } if ($found_user === null) { throw new RuntimeException("[W801] User not found for role \"{$role}\""); } $this->logIn($found_user['username'], $found_user['password']); }
[ "public", "function", "iAmLoggedInAsRole", "(", "string", "$", "role", ")", "{", "$", "found_user", "=", "null", ";", "$", "users", "=", "$", "this", "->", "getWordpressParameter", "(", "'users'", ")", ";", "foreach", "(", "$", "users", "as", "$", "user", ")", "{", "if", "(", "in_array", "(", "$", "role", ",", "$", "user", "[", "'roles'", "]", ",", "true", ")", ")", "{", "$", "found_user", "=", "$", "user", ";", "break", ";", "}", "}", "if", "(", "$", "found_user", "===", "null", ")", "{", "throw", "new", "RuntimeException", "(", "\"[W801] User not found for role \\\"{$role}\\\"\"", ")", ";", "}", "$", "this", "->", "logIn", "(", "$", "found_user", "[", "'username'", "]", ",", "$", "found_user", "[", "'password'", "]", ")", ";", "}" ]
Log user in (with role name). Example: Given I am logged in as an contributor @Given /^(?:I am|they are) logged in as an? (.+)$/ @param string $role @throws \RuntimeException
[ "Log", "user", "in", "(", "with", "role", "name", ")", "." ]
train
https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/UserContext.php#L134-L151
paulgibbs/behat-wordpress-extension
src/Context/UserContext.php
UserContext.iAmLoggedInAsUser
public function iAmLoggedInAsUser(string $username) { $found_user = $this->getUserByName($username); $this->logIn($found_user['username'], $found_user['password']); }
php
public function iAmLoggedInAsUser(string $username) { $found_user = $this->getUserByName($username); $this->logIn($found_user['username'], $found_user['password']); }
[ "public", "function", "iAmLoggedInAsUser", "(", "string", "$", "username", ")", "{", "$", "found_user", "=", "$", "this", "->", "getUserByName", "(", "$", "username", ")", ";", "$", "this", "->", "logIn", "(", "$", "found_user", "[", "'username'", "]", ",", "$", "found_user", "[", "'password'", "]", ")", ";", "}" ]
Log user in (with user name). Example: Given I am logged in as Mince @Given /^(?:I am|they are) logged in as (?!an? )(.+)$/ @param string $username @throws \RuntimeException
[ "Log", "user", "in", "(", "with", "user", "name", ")", "." ]
train
https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/UserContext.php#L164-L169
paulgibbs/behat-wordpress-extension
src/Context/UserContext.php
UserContext.iShouldNotBeAbleToLogInAsRole
public function iShouldNotBeAbleToLogInAsRole(string $role) { try { $this->iAmLoggedInAsRole($role); } catch (ExpectationException $e) { // Expectation fulfilled. return; } catch (RuntimeException $e) { // Expectation fulfilled. return; } throw new ExpectationException( sprintf( '[W802] A user with role "%s" was logged-in succesfully. This should not have happened.', $role ), $this->getSession()->getDriver() ); }
php
public function iShouldNotBeAbleToLogInAsRole(string $role) { try { $this->iAmLoggedInAsRole($role); } catch (ExpectationException $e) { // Expectation fulfilled. return; } catch (RuntimeException $e) { // Expectation fulfilled. return; } throw new ExpectationException( sprintf( '[W802] A user with role "%s" was logged-in succesfully. This should not have happened.', $role ), $this->getSession()->getDriver() ); }
[ "public", "function", "iShouldNotBeAbleToLogInAsRole", "(", "string", "$", "role", ")", "{", "try", "{", "$", "this", "->", "iAmLoggedInAsRole", "(", "$", "role", ")", ";", "}", "catch", "(", "ExpectationException", "$", "e", ")", "{", "// Expectation fulfilled.", "return", ";", "}", "catch", "(", "RuntimeException", "$", "e", ")", "{", "// Expectation fulfilled.", "return", ";", "}", "throw", "new", "ExpectationException", "(", "sprintf", "(", "'[W802] A user with role \"%s\" was logged-in succesfully. This should not have happened.'", ",", "$", "role", ")", ",", "$", "this", "->", "getSession", "(", ")", "->", "getDriver", "(", ")", ")", ";", "}" ]
Try to log user in (with role name), but expect failure. Example: Then I should not be able to log in as an editor @Then /^(?:I|they) should not be able to log in as an? (.+)$/ @param string $role @throws ExpectationException
[ "Try", "to", "log", "user", "in", "(", "with", "role", "name", ")", "but", "expect", "failure", "." ]
train
https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/UserContext.php#L182-L201
paulgibbs/behat-wordpress-extension
src/Context/UserContext.php
UserContext.iShouldNotBeAbleToLogInAsUser
public function iShouldNotBeAbleToLogInAsUser(string $username) { try { $this->iAmLoggedInAsUser($username); } catch (ExpectationException $e) { // Expectation fulfilled. return; } catch (RuntimeException $e) { // Expectation fulfilled. return; } throw new ExpectationException( sprintf( '[W802] The user "%s" was logged-in succesfully. This should not have happened.', $username ), $this->getSession()->getDriver() ); }
php
public function iShouldNotBeAbleToLogInAsUser(string $username) { try { $this->iAmLoggedInAsUser($username); } catch (ExpectationException $e) { // Expectation fulfilled. return; } catch (RuntimeException $e) { // Expectation fulfilled. return; } throw new ExpectationException( sprintf( '[W802] The user "%s" was logged-in succesfully. This should not have happened.', $username ), $this->getSession()->getDriver() ); }
[ "public", "function", "iShouldNotBeAbleToLogInAsUser", "(", "string", "$", "username", ")", "{", "try", "{", "$", "this", "->", "iAmLoggedInAsUser", "(", "$", "username", ")", ";", "}", "catch", "(", "ExpectationException", "$", "e", ")", "{", "// Expectation fulfilled.", "return", ";", "}", "catch", "(", "RuntimeException", "$", "e", ")", "{", "// Expectation fulfilled.", "return", ";", "}", "throw", "new", "ExpectationException", "(", "sprintf", "(", "'[W802] The user \"%s\" was logged-in succesfully. This should not have happened.'", ",", "$", "username", ")", ",", "$", "this", "->", "getSession", "(", ")", "->", "getDriver", "(", ")", ")", ";", "}" ]
Try to log user in (with username), but expect failure. Example: Then I should not be able to log in as Scotty @Then /^(?:I|they) should not be able to log in as (.+)$/ @param string $username @throws ExpectationException
[ "Try", "to", "log", "user", "in", "(", "with", "username", ")", "but", "expect", "failure", "." ]
train
https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/UserContext.php#L214-L233
paulgibbs/behat-wordpress-extension
src/Driver/Element/Wpphp/UserElement.php
UserElement.create
public function create($args) { $extra_roles = []; // Store multiple roles; WP can only assign one on user creation. if (! empty($args['role'])) { if (! is_array($args['role'])) { $args['role'] = array_map('trim', explode(',', $args['role'])); } $extra_roles = $args['role']; $args['role'] = array_shift($extra_roles); } $args = wp_slash($args); $user_id = wp_insert_user($args); if (is_wp_error($user_id)) { throw new UnexpectedValueException(sprintf('[W615] Failed creating new user: %s', $user_id->get_error_message())); } $wp_user = get_user_by('ID', $user_id); // Assign any extra roles. foreach ($extra_roles as $role) { $wp_user->add_role($role); } return $this->get($user); }
php
public function create($args) { $extra_roles = []; // Store multiple roles; WP can only assign one on user creation. if (! empty($args['role'])) { if (! is_array($args['role'])) { $args['role'] = array_map('trim', explode(',', $args['role'])); } $extra_roles = $args['role']; $args['role'] = array_shift($extra_roles); } $args = wp_slash($args); $user_id = wp_insert_user($args); if (is_wp_error($user_id)) { throw new UnexpectedValueException(sprintf('[W615] Failed creating new user: %s', $user_id->get_error_message())); } $wp_user = get_user_by('ID', $user_id); // Assign any extra roles. foreach ($extra_roles as $role) { $wp_user->add_role($role); } return $this->get($user); }
[ "public", "function", "create", "(", "$", "args", ")", "{", "$", "extra_roles", "=", "[", "]", ";", "// Store multiple roles; WP can only assign one on user creation.", "if", "(", "!", "empty", "(", "$", "args", "[", "'role'", "]", ")", ")", "{", "if", "(", "!", "is_array", "(", "$", "args", "[", "'role'", "]", ")", ")", "{", "$", "args", "[", "'role'", "]", "=", "array_map", "(", "'trim'", ",", "explode", "(", "','", ",", "$", "args", "[", "'role'", "]", ")", ")", ";", "}", "$", "extra_roles", "=", "$", "args", "[", "'role'", "]", ";", "$", "args", "[", "'role'", "]", "=", "array_shift", "(", "$", "extra_roles", ")", ";", "}", "$", "args", "=", "wp_slash", "(", "$", "args", ")", ";", "$", "user_id", "=", "wp_insert_user", "(", "$", "args", ")", ";", "if", "(", "is_wp_error", "(", "$", "user_id", ")", ")", "{", "throw", "new", "UnexpectedValueException", "(", "sprintf", "(", "'[W615] Failed creating new user: %s'", ",", "$", "user_id", "->", "get_error_message", "(", ")", ")", ")", ";", "}", "$", "wp_user", "=", "get_user_by", "(", "'ID'", ",", "$", "user_id", ")", ";", "// Assign any extra roles.", "foreach", "(", "$", "extra_roles", "as", "$", "role", ")", "{", "$", "wp_user", "->", "add_role", "(", "$", "role", ")", ";", "}", "return", "$", "this", "->", "get", "(", "$", "user", ")", ";", "}" ]
Create an item for this element. @param array $args Data used to create an object. @throws \UnexpectedValueException @return \WP_User The new item.
[ "Create", "an", "item", "for", "this", "element", "." ]
train
https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpphp/UserElement.php#L22-L51
paulgibbs/behat-wordpress-extension
src/Driver/Element/Wpphp/UserElement.php
UserElement.get
public function get($id, $args = []) { if (is_numeric($id) || ! isset($args['by'])) { $type = 'ID'; } else { $type = $args['by']; } $user = get_user_by($type, $id); if (! $user) { throw new UnexpectedValueException(sprintf('[W616] Could not find user with ID %d', $id)); } return $user; }
php
public function get($id, $args = []) { if (is_numeric($id) || ! isset($args['by'])) { $type = 'ID'; } else { $type = $args['by']; } $user = get_user_by($type, $id); if (! $user) { throw new UnexpectedValueException(sprintf('[W616] Could not find user with ID %d', $id)); } return $user; }
[ "public", "function", "get", "(", "$", "id", ",", "$", "args", "=", "[", "]", ")", "{", "if", "(", "is_numeric", "(", "$", "id", ")", "||", "!", "isset", "(", "$", "args", "[", "'by'", "]", ")", ")", "{", "$", "type", "=", "'ID'", ";", "}", "else", "{", "$", "type", "=", "$", "args", "[", "'by'", "]", ";", "}", "$", "user", "=", "get_user_by", "(", "$", "type", ",", "$", "id", ")", ";", "if", "(", "!", "$", "user", ")", "{", "throw", "new", "UnexpectedValueException", "(", "sprintf", "(", "'[W616] Could not find user with ID %d'", ",", "$", "id", ")", ")", ";", "}", "return", "$", "user", ";", "}" ]
Retrieve an item for this element. @param int|string $id Object ID. @param array $args Optional data used to fetch an object. @throws \UnexpectedValueException @return \WP_User The item.
[ "Retrieve", "an", "item", "for", "this", "element", "." ]
train
https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpphp/UserElement.php#L63-L78
paulgibbs/behat-wordpress-extension
src/Driver/Element/Wpphp/UserElement.php
UserElement.delete
public function delete($id, $args = []) { if (! function_exists('\wp_delete_user')) { require_once ABSPATH . 'wp-admin/includes/user.php'; } $result = wp_delete_user($id, $args); if (! $result) { throw new UnexpectedValueException('[W617] Failed deleting user'); } }
php
public function delete($id, $args = []) { if (! function_exists('\wp_delete_user')) { require_once ABSPATH . 'wp-admin/includes/user.php'; } $result = wp_delete_user($id, $args); if (! $result) { throw new UnexpectedValueException('[W617] Failed deleting user'); } }
[ "public", "function", "delete", "(", "$", "id", ",", "$", "args", "=", "[", "]", ")", "{", "if", "(", "!", "function_exists", "(", "'\\wp_delete_user'", ")", ")", "{", "require_once", "ABSPATH", ".", "'wp-admin/includes/user.php'", ";", "}", "$", "result", "=", "wp_delete_user", "(", "$", "id", ",", "$", "args", ")", ";", "if", "(", "!", "$", "result", ")", "{", "throw", "new", "UnexpectedValueException", "(", "'[W617] Failed deleting user'", ")", ";", "}", "}" ]
Delete an item for this element. @param int $id Object ID. @param array $args Optional data used to delete an object. @throws \UnexpectedValueException
[ "Delete", "an", "item", "for", "this", "element", "." ]
train
https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpphp/UserElement.php#L104-L115
paulgibbs/behat-wordpress-extension
src/Driver/Element/Wpphp/CommentElement.php
CommentElement.create
public function create($args) { $comment_id = wp_new_comment($args); if (! $comment_id) { throw new UnexpectedValueException('[W600] Failed creating a new comment'); } elseif (is_wp_error($comment_id)) { throw new UnexpectedValueException( sprintf('[W600] Failed creating a new comment: %s', $comment_id->get_error_message()) ); } return $this->get($comment_id); }
php
public function create($args) { $comment_id = wp_new_comment($args); if (! $comment_id) { throw new UnexpectedValueException('[W600] Failed creating a new comment'); } elseif (is_wp_error($comment_id)) { throw new UnexpectedValueException( sprintf('[W600] Failed creating a new comment: %s', $comment_id->get_error_message()) ); } return $this->get($comment_id); }
[ "public", "function", "create", "(", "$", "args", ")", "{", "$", "comment_id", "=", "wp_new_comment", "(", "$", "args", ")", ";", "if", "(", "!", "$", "comment_id", ")", "{", "throw", "new", "UnexpectedValueException", "(", "'[W600] Failed creating a new comment'", ")", ";", "}", "elseif", "(", "is_wp_error", "(", "$", "comment_id", ")", ")", "{", "throw", "new", "UnexpectedValueException", "(", "sprintf", "(", "'[W600] Failed creating a new comment: %s'", ",", "$", "comment_id", "->", "get_error_message", "(", ")", ")", ")", ";", "}", "return", "$", "this", "->", "get", "(", "$", "comment_id", ")", ";", "}" ]
Create an item for this element. @param array $args Data used to create an object. @throws \UnexpectedValueException @return \WP_Comment The new item.
[ "Create", "an", "item", "for", "this", "element", "." ]
train
https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpphp/CommentElement.php#L22-L35
paulgibbs/behat-wordpress-extension
src/Driver/Element/Wpphp/CommentElement.php
CommentElement.get
public function get($id, $args = []) { $comment = get_comment($id); if (! $comment) { throw new UnexpectedValueException(sprintf('[W601] Could not find comment with ID %d', $id)); } return $comment; }
php
public function get($id, $args = []) { $comment = get_comment($id); if (! $comment) { throw new UnexpectedValueException(sprintf('[W601] Could not find comment with ID %d', $id)); } return $comment; }
[ "public", "function", "get", "(", "$", "id", ",", "$", "args", "=", "[", "]", ")", "{", "$", "comment", "=", "get_comment", "(", "$", "id", ")", ";", "if", "(", "!", "$", "comment", ")", "{", "throw", "new", "UnexpectedValueException", "(", "sprintf", "(", "'[W601] Could not find comment with ID %d'", ",", "$", "id", ")", ")", ";", "}", "return", "$", "comment", ";", "}" ]
Retrieve an item for this element. @param int|string $id Object ID. @param array $args Not used. @throws \UnexpectedValueException @return \WP_Comment The item.
[ "Retrieve", "an", "item", "for", "this", "element", "." ]
train
https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpphp/CommentElement.php#L47-L56
paulgibbs/behat-wordpress-extension
src/Driver/Element/Wpphp/CommentElement.php
CommentElement.delete
public function delete($id, $args = []) { $result = wp_delete_comment($id, isset($args['force'])); if (! $result) { throw new UnexpectedValueException('[W602] Failed deleting a comment'); } }
php
public function delete($id, $args = []) { $result = wp_delete_comment($id, isset($args['force'])); if (! $result) { throw new UnexpectedValueException('[W602] Failed deleting a comment'); } }
[ "public", "function", "delete", "(", "$", "id", ",", "$", "args", "=", "[", "]", ")", "{", "$", "result", "=", "wp_delete_comment", "(", "$", "id", ",", "isset", "(", "$", "args", "[", "'force'", "]", ")", ")", ";", "if", "(", "!", "$", "result", ")", "{", "throw", "new", "UnexpectedValueException", "(", "'[W602] Failed deleting a comment'", ")", ";", "}", "}" ]
Delete an item for this element. @param int|string $id Object ID. @param array $args Optional data used to delete an object. @throws \UnexpectedValueException
[ "Delete", "an", "item", "for", "this", "element", "." ]
train
https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpphp/CommentElement.php#L66-L73
paulgibbs/behat-wordpress-extension
src/Driver/Element/Wpphp/WidgetElement.php
WidgetElement.addToSidebar
public function addToSidebar($widget_name, $sidebar_id, $args) { global $wp_widget_factory; $widget_name = strtolower($widget_name); $widget = wp_filter_object_list($wp_widget_factory->widgets, array('id_base' => $widget_name)); if (! $widget) { throw new UnexpectedValueException(sprintf('[W613] Widget "%s" does not exist', $widget_name)); } $widget = array_pop($widget); $widget_options = get_option('widget_' . $widget_name, []); if (! isset($widget_options['_multiwidget'])) { $widget_options['_multiwidget'] = 1; } $option_keys = $widget_options; unset($option_keys['_multiwidget']); $option_keys = array_keys($option_keys); // Get the widgets 'counter' $last_key = array_pop($option_keys); $counter = $last_key + 1; // Create widget instance $widget_options[$counter] = $widget->update($args, array()); update_option('widget_' . $widget_name, $widget_options); $widget_id = $widget_name . '-' . $counter; // Add widget to sidebar $active_widgets = get_option('sidebars_widgets', array()); array_unshift($active_widgets[$sidebar_id], $widget_id); update_option('sidebars_widgets', $active_widgets); }
php
public function addToSidebar($widget_name, $sidebar_id, $args) { global $wp_widget_factory; $widget_name = strtolower($widget_name); $widget = wp_filter_object_list($wp_widget_factory->widgets, array('id_base' => $widget_name)); if (! $widget) { throw new UnexpectedValueException(sprintf('[W613] Widget "%s" does not exist', $widget_name)); } $widget = array_pop($widget); $widget_options = get_option('widget_' . $widget_name, []); if (! isset($widget_options['_multiwidget'])) { $widget_options['_multiwidget'] = 1; } $option_keys = $widget_options; unset($option_keys['_multiwidget']); $option_keys = array_keys($option_keys); // Get the widgets 'counter' $last_key = array_pop($option_keys); $counter = $last_key + 1; // Create widget instance $widget_options[$counter] = $widget->update($args, array()); update_option('widget_' . $widget_name, $widget_options); $widget_id = $widget_name . '-' . $counter; // Add widget to sidebar $active_widgets = get_option('sidebars_widgets', array()); array_unshift($active_widgets[$sidebar_id], $widget_id); update_option('sidebars_widgets', $active_widgets); }
[ "public", "function", "addToSidebar", "(", "$", "widget_name", ",", "$", "sidebar_id", ",", "$", "args", ")", "{", "global", "$", "wp_widget_factory", ";", "$", "widget_name", "=", "strtolower", "(", "$", "widget_name", ")", ";", "$", "widget", "=", "wp_filter_object_list", "(", "$", "wp_widget_factory", "->", "widgets", ",", "array", "(", "'id_base'", "=>", "$", "widget_name", ")", ")", ";", "if", "(", "!", "$", "widget", ")", "{", "throw", "new", "UnexpectedValueException", "(", "sprintf", "(", "'[W613] Widget \"%s\" does not exist'", ",", "$", "widget_name", ")", ")", ";", "}", "$", "widget", "=", "array_pop", "(", "$", "widget", ")", ";", "$", "widget_options", "=", "get_option", "(", "'widget_'", ".", "$", "widget_name", ",", "[", "]", ")", ";", "if", "(", "!", "isset", "(", "$", "widget_options", "[", "'_multiwidget'", "]", ")", ")", "{", "$", "widget_options", "[", "'_multiwidget'", "]", "=", "1", ";", "}", "$", "option_keys", "=", "$", "widget_options", ";", "unset", "(", "$", "option_keys", "[", "'_multiwidget'", "]", ")", ";", "$", "option_keys", "=", "array_keys", "(", "$", "option_keys", ")", ";", "// Get the widgets 'counter'", "$", "last_key", "=", "array_pop", "(", "$", "option_keys", ")", ";", "$", "counter", "=", "$", "last_key", "+", "1", ";", "// Create widget instance", "$", "widget_options", "[", "$", "counter", "]", "=", "$", "widget", "->", "update", "(", "$", "args", ",", "array", "(", ")", ")", ";", "update_option", "(", "'widget_'", ".", "$", "widget_name", ",", "$", "widget_options", ")", ";", "$", "widget_id", "=", "$", "widget_name", ".", "'-'", ".", "$", "counter", ";", "// Add widget to sidebar", "$", "active_widgets", "=", "get_option", "(", "'sidebars_widgets'", ",", "array", "(", ")", ")", ";", "array_unshift", "(", "$", "active_widgets", "[", "$", "sidebar_id", "]", ",", "$", "widget_id", ")", ";", "update_option", "(", "'sidebars_widgets'", ",", "$", "active_widgets", ")", ";", "}" ]
Adds a widget to the sidebar with the specified arguments @param string $widget_name The ID base of the widget (e.g. 'meta', 'calendar'). Case insensitive. @param string $sidebar_id The ID of the sidebar to the add the widget to @param array $args Associative array of widget settings for this widget @throws UnexpectedValueException If the widget is not registered.
[ "Adds", "a", "widget", "to", "the", "sidebar", "with", "the", "specified", "arguments" ]
train
https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpphp/WidgetElement.php#L23-L57
paulgibbs/behat-wordpress-extension
src/Driver/Element/Wpphp/WidgetElement.php
WidgetElement.getSidebar
public function getSidebar($sidebar_name) { global $wp_registered_sidebars; $sidebar_id = null; foreach ($wp_registered_sidebars as $registered_sidebar_id => $registered_sidebar) { if ($sidebar_name === $registered_sidebar['name']) { $sidebar_id = $registered_sidebar_id; break; } } if ($sidebar_id === null) { throw new UnexpectedValueException(sprintf('[W614] Sidebar "%s" does not exist', $sidebar_name)); } return $sidebar_id; }
php
public function getSidebar($sidebar_name) { global $wp_registered_sidebars; $sidebar_id = null; foreach ($wp_registered_sidebars as $registered_sidebar_id => $registered_sidebar) { if ($sidebar_name === $registered_sidebar['name']) { $sidebar_id = $registered_sidebar_id; break; } } if ($sidebar_id === null) { throw new UnexpectedValueException(sprintf('[W614] Sidebar "%s" does not exist', $sidebar_name)); } return $sidebar_id; }
[ "public", "function", "getSidebar", "(", "$", "sidebar_name", ")", "{", "global", "$", "wp_registered_sidebars", ";", "$", "sidebar_id", "=", "null", ";", "foreach", "(", "$", "wp_registered_sidebars", "as", "$", "registered_sidebar_id", "=>", "$", "registered_sidebar", ")", "{", "if", "(", "$", "sidebar_name", "===", "$", "registered_sidebar", "[", "'name'", "]", ")", "{", "$", "sidebar_id", "=", "$", "registered_sidebar_id", ";", "break", ";", "}", "}", "if", "(", "$", "sidebar_id", "===", "null", ")", "{", "throw", "new", "UnexpectedValueException", "(", "sprintf", "(", "'[W614] Sidebar \"%s\" does not exist'", ",", "$", "sidebar_name", ")", ")", ";", "}", "return", "$", "sidebar_id", ";", "}" ]
Gets a sidebar ID from its human-readable name. @param string $sidebar_name The name of the sidebar (e.g. 'Footer', 'Widget Area', 'Right Sidebar'). @return string The sidebar ID. @throws UnexpectedValueException If the sidebar is not registered.
[ "Gets", "a", "sidebar", "ID", "from", "its", "human", "-", "readable", "name", "." ]
train
https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpphp/WidgetElement.php#L68-L86
paulgibbs/behat-wordpress-extension
src/Driver/Element/Wpcli/DatabaseElement.php
DatabaseElement.get
public function get($id, $args = []) { $wpcli_args = ['--porcelain', '--add-drop-table']; if (! empty($args['path'])) { $file = tempnam($args['path'], 'wordhat'); if ($file) { array_unshift($wpcli_args, $file); } }; // Protect against WP-CLI changing the filename. $path = $this->drivers->getDriver()->wpcli('db', 'export', $wpcli_args)['stdout']; if (! $path) { throw new RuntimeException('[W502] Could not export database'); } return $path; }
php
public function get($id, $args = []) { $wpcli_args = ['--porcelain', '--add-drop-table']; if (! empty($args['path'])) { $file = tempnam($args['path'], 'wordhat'); if ($file) { array_unshift($wpcli_args, $file); } }; // Protect against WP-CLI changing the filename. $path = $this->drivers->getDriver()->wpcli('db', 'export', $wpcli_args)['stdout']; if (! $path) { throw new RuntimeException('[W502] Could not export database'); } return $path; }
[ "public", "function", "get", "(", "$", "id", ",", "$", "args", "=", "[", "]", ")", "{", "$", "wpcli_args", "=", "[", "'--porcelain'", ",", "'--add-drop-table'", "]", ";", "if", "(", "!", "empty", "(", "$", "args", "[", "'path'", "]", ")", ")", "{", "$", "file", "=", "tempnam", "(", "$", "args", "[", "'path'", "]", ",", "'wordhat'", ")", ";", "if", "(", "$", "file", ")", "{", "array_unshift", "(", "$", "wpcli_args", ",", "$", "file", ")", ";", "}", "}", ";", "// Protect against WP-CLI changing the filename.", "$", "path", "=", "$", "this", "->", "drivers", "->", "getDriver", "(", ")", "->", "wpcli", "(", "'db'", ",", "'export'", ",", "$", "wpcli_args", ")", "[", "'stdout'", "]", ";", "if", "(", "!", "$", "path", ")", "{", "throw", "new", "RuntimeException", "(", "'[W502] Could not export database'", ")", ";", "}", "return", "$", "path", ";", "}" ]
Export site database. @param int $id Not used. @param array $args @return string Path to the database dump.
[ "Export", "site", "database", "." ]
train
https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpcli/DatabaseElement.php#L21-L39
paulgibbs/behat-wordpress-extension
src/PageObject/PostsEditPage.php
PostsEditPage.getMetaBox
public function getMetaBox(string $title): NodeElement { $metaboxes = $this->findAll('css', '.postbox'); if ($metaboxes) { foreach ($metaboxes as $metabox) { if ($metabox->find('css', 'h2')->getText() === $title) { return $metabox; } } } throw new ExpectationException( sprintf( '[W400] Metabox "%s" not found on the screen.', $title ), $this->getDriver() ); }
php
public function getMetaBox(string $title): NodeElement { $metaboxes = $this->findAll('css', '.postbox'); if ($metaboxes) { foreach ($metaboxes as $metabox) { if ($metabox->find('css', 'h2')->getText() === $title) { return $metabox; } } } throw new ExpectationException( sprintf( '[W400] Metabox "%s" not found on the screen.', $title ), $this->getDriver() ); }
[ "public", "function", "getMetaBox", "(", "string", "$", "title", ")", ":", "NodeElement", "{", "$", "metaboxes", "=", "$", "this", "->", "findAll", "(", "'css'", ",", "'.postbox'", ")", ";", "if", "(", "$", "metaboxes", ")", "{", "foreach", "(", "$", "metaboxes", "as", "$", "metabox", ")", "{", "if", "(", "$", "metabox", "->", "find", "(", "'css'", ",", "'h2'", ")", "->", "getText", "(", ")", "===", "$", "title", ")", "{", "return", "$", "metabox", ";", "}", "}", "}", "throw", "new", "ExpectationException", "(", "sprintf", "(", "'[W400] Metabox \"%s\" not found on the screen.'", ",", "$", "title", ")", ",", "$", "this", "->", "getDriver", "(", ")", ")", ";", "}" ]
Get the node element for the specified metabox. @param string $title The title of the metabox to get @return \Behat\Mink\Element\NodeElement @throws \Behat\Mink\Exception\ExpectationException If the metabox cannot be found
[ "Get", "the", "node", "element", "for", "the", "specified", "metabox", "." ]
train
https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/PageObject/PostsEditPage.php#L58-L76
PingPlusPlus/pingpp-php
lib/RoyaltySettlement.php
RoyaltySettlement.update
public static function update($royalty_settlement_id, $params, $options = null) { $url = static::instanceUrlWithId($royalty_settlement_id); return static::_directRequest('put', $url, $params, $options); }
php
public static function update($royalty_settlement_id, $params, $options = null) { $url = static::instanceUrlWithId($royalty_settlement_id); return static::_directRequest('put', $url, $params, $options); }
[ "public", "static", "function", "update", "(", "$", "royalty_settlement_id", ",", "$", "params", ",", "$", "options", "=", "null", ")", "{", "$", "url", "=", "static", "::", "instanceUrlWithId", "(", "$", "royalty_settlement_id", ")", ";", "return", "static", "::", "_directRequest", "(", "'put'", ",", "$", "url", ",", "$", "params", ",", "$", "options", ")", ";", "}" ]
更新分润结算对象 @param $royalty_settlement_id @param $params @return array|PingppObject
[ "更新分润结算对象" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/RoyaltySettlement.php#L45-L49
PingPlusPlus/pingpp-php
lib/Util/Util.php
Util.convertPingppObjectToArray
public static function convertPingppObjectToArray($values, $keep_object = false) { $results = array(); foreach ($values as $k => $v) { // FIXME: this is an encapsulation violation if ($k[0] == '_') { continue; } if ($v instanceof PingppObject) { $results[$k] = $keep_object ? $v->__toStdObject(true) : $v->__toArray(true); } else if (is_array($v)) { $results[$k] = self::convertPingppObjectToArray($v, $keep_object); } else { $results[$k] = $v; } } return $results; }
php
public static function convertPingppObjectToArray($values, $keep_object = false) { $results = array(); foreach ($values as $k => $v) { // FIXME: this is an encapsulation violation if ($k[0] == '_') { continue; } if ($v instanceof PingppObject) { $results[$k] = $keep_object ? $v->__toStdObject(true) : $v->__toArray(true); } else if (is_array($v)) { $results[$k] = self::convertPingppObjectToArray($v, $keep_object); } else { $results[$k] = $v; } } return $results; }
[ "public", "static", "function", "convertPingppObjectToArray", "(", "$", "values", ",", "$", "keep_object", "=", "false", ")", "{", "$", "results", "=", "array", "(", ")", ";", "foreach", "(", "$", "values", "as", "$", "k", "=>", "$", "v", ")", "{", "// FIXME: this is an encapsulation violation", "if", "(", "$", "k", "[", "0", "]", "==", "'_'", ")", "{", "continue", ";", "}", "if", "(", "$", "v", "instanceof", "PingppObject", ")", "{", "$", "results", "[", "$", "k", "]", "=", "$", "keep_object", "?", "$", "v", "->", "__toStdObject", "(", "true", ")", ":", "$", "v", "->", "__toArray", "(", "true", ")", ";", "}", "else", "if", "(", "is_array", "(", "$", "v", ")", ")", "{", "$", "results", "[", "$", "k", "]", "=", "self", "::", "convertPingppObjectToArray", "(", "$", "v", ",", "$", "keep_object", ")", ";", "}", "else", "{", "$", "results", "[", "$", "k", "]", "=", "$", "v", ";", "}", "}", "return", "$", "results", ";", "}" ]
Recursively converts the PHP Pingpp object to an array. @param array $values The PHP Pingpp object to convert. @param bool @return array
[ "Recursively", "converts", "the", "PHP", "Pingpp", "object", "to", "an", "array", "." ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/Util/Util.php#L36-L53
PingPlusPlus/pingpp-php
lib/Util/Util.php
Util.convertPingppObjectToStdObject
public static function convertPingppObjectToStdObject($values) { $results = new stdClass; foreach ($values as $k => $v) { // FIXME: this is an encapsulation violation if ($k[0] == '_') { continue; } if ($v instanceof PingppObject) { $results->$k = $v->__toStdObject(true); } else if (is_array($v)) { $results->$k = self::convertPingppObjectToArray($v, true); } else { $results->$k = $v; } } return $results; }
php
public static function convertPingppObjectToStdObject($values) { $results = new stdClass; foreach ($values as $k => $v) { // FIXME: this is an encapsulation violation if ($k[0] == '_') { continue; } if ($v instanceof PingppObject) { $results->$k = $v->__toStdObject(true); } else if (is_array($v)) { $results->$k = self::convertPingppObjectToArray($v, true); } else { $results->$k = $v; } } return $results; }
[ "public", "static", "function", "convertPingppObjectToStdObject", "(", "$", "values", ")", "{", "$", "results", "=", "new", "stdClass", ";", "foreach", "(", "$", "values", "as", "$", "k", "=>", "$", "v", ")", "{", "// FIXME: this is an encapsulation violation", "if", "(", "$", "k", "[", "0", "]", "==", "'_'", ")", "{", "continue", ";", "}", "if", "(", "$", "v", "instanceof", "PingppObject", ")", "{", "$", "results", "->", "$", "k", "=", "$", "v", "->", "__toStdObject", "(", "true", ")", ";", "}", "else", "if", "(", "is_array", "(", "$", "v", ")", ")", "{", "$", "results", "->", "$", "k", "=", "self", "::", "convertPingppObjectToArray", "(", "$", "v", ",", "true", ")", ";", "}", "else", "{", "$", "results", "->", "$", "k", "=", "$", "v", ";", "}", "}", "return", "$", "results", ";", "}" ]
Recursively converts the PHP Pingpp object to an stdObject. @param array $values The PHP Pingpp object to convert. @return array
[ "Recursively", "converts", "the", "PHP", "Pingpp", "object", "to", "an", "stdObject", "." ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/Util/Util.php#L61-L78
PingPlusPlus/pingpp-php
lib/Util/Util.php
Util.convertToPingppObject
public static function convertToPingppObject($resp, $opts) { $types = array( 'red_envelope'=>'Pingpp\\RedEnvelope', 'charge' => 'Pingpp\\Charge', 'list' => 'Pingpp\\Collection', 'refund' => 'Pingpp\\Refund', 'event' => 'Pingpp\\Event', 'transfer' => 'Pingpp\\Transfer', 'customs' => 'Pingpp\\Customs', 'order' => 'Pingpp\\Order', 'batch_refund' => 'Pingpp\\BatchRefund', 'batch_transfer' => 'Pingpp\\BatchTransfer', 'user' => 'Pingpp\\User', 'balance_transaction' => 'Pingpp\\BalanceTransaction', 'withdrawal' => 'Pingpp\\Withdrawal', 'batch_withdrawal' => 'Pingpp\\BatchWithdrawal', 'coupon_template' => 'Pingpp\\CouponTemplate', 'coupon' => 'Pingpp\\Coupon', 'sub_app' => 'Pingpp\\SubApp', 'channel' => 'Pingpp\\Channel', 'royalty' => 'Pingpp\\Royalty', 'royalty_settlement' => 'Pingpp\\RoyaltySettlement', 'royalty_transaction' => 'Pingpp\\RoyaltyTransaction', 'settle_account' => 'Pingpp\\SettleAccount', 'royalty_template' => 'Pingpp\\RoyaltyTemplate', 'recharge' => 'Pingpp\\Recharge', 'balance_bonus' => 'Pingpp\\BalanceBonus', 'balance_settlements' => 'Pingpp\\BalanceSettlements', 'balance_transfer' => 'Pingpp\\BalanceTransfer', ); if (self::isList($resp)) { $mapped = array(); foreach ($resp as $i) array_push($mapped, self::convertToPingppObject($i, $opts)); return $mapped; } else if (is_object($resp)) { if (isset($resp->object) && is_string($resp->object) && isset($types[$resp->object])) { $class = $types[$resp->object]; } else { $class = 'Pingpp\\PingppObject'; } return $class::constructFrom($resp, $opts); } else { return $resp; } }
php
public static function convertToPingppObject($resp, $opts) { $types = array( 'red_envelope'=>'Pingpp\\RedEnvelope', 'charge' => 'Pingpp\\Charge', 'list' => 'Pingpp\\Collection', 'refund' => 'Pingpp\\Refund', 'event' => 'Pingpp\\Event', 'transfer' => 'Pingpp\\Transfer', 'customs' => 'Pingpp\\Customs', 'order' => 'Pingpp\\Order', 'batch_refund' => 'Pingpp\\BatchRefund', 'batch_transfer' => 'Pingpp\\BatchTransfer', 'user' => 'Pingpp\\User', 'balance_transaction' => 'Pingpp\\BalanceTransaction', 'withdrawal' => 'Pingpp\\Withdrawal', 'batch_withdrawal' => 'Pingpp\\BatchWithdrawal', 'coupon_template' => 'Pingpp\\CouponTemplate', 'coupon' => 'Pingpp\\Coupon', 'sub_app' => 'Pingpp\\SubApp', 'channel' => 'Pingpp\\Channel', 'royalty' => 'Pingpp\\Royalty', 'royalty_settlement' => 'Pingpp\\RoyaltySettlement', 'royalty_transaction' => 'Pingpp\\RoyaltyTransaction', 'settle_account' => 'Pingpp\\SettleAccount', 'royalty_template' => 'Pingpp\\RoyaltyTemplate', 'recharge' => 'Pingpp\\Recharge', 'balance_bonus' => 'Pingpp\\BalanceBonus', 'balance_settlements' => 'Pingpp\\BalanceSettlements', 'balance_transfer' => 'Pingpp\\BalanceTransfer', ); if (self::isList($resp)) { $mapped = array(); foreach ($resp as $i) array_push($mapped, self::convertToPingppObject($i, $opts)); return $mapped; } else if (is_object($resp)) { if (isset($resp->object) && is_string($resp->object) && isset($types[$resp->object])) { $class = $types[$resp->object]; } else { $class = 'Pingpp\\PingppObject'; } return $class::constructFrom($resp, $opts); } else { return $resp; } }
[ "public", "static", "function", "convertToPingppObject", "(", "$", "resp", ",", "$", "opts", ")", "{", "$", "types", "=", "array", "(", "'red_envelope'", "=>", "'Pingpp\\\\RedEnvelope'", ",", "'charge'", "=>", "'Pingpp\\\\Charge'", ",", "'list'", "=>", "'Pingpp\\\\Collection'", ",", "'refund'", "=>", "'Pingpp\\\\Refund'", ",", "'event'", "=>", "'Pingpp\\\\Event'", ",", "'transfer'", "=>", "'Pingpp\\\\Transfer'", ",", "'customs'", "=>", "'Pingpp\\\\Customs'", ",", "'order'", "=>", "'Pingpp\\\\Order'", ",", "'batch_refund'", "=>", "'Pingpp\\\\BatchRefund'", ",", "'batch_transfer'", "=>", "'Pingpp\\\\BatchTransfer'", ",", "'user'", "=>", "'Pingpp\\\\User'", ",", "'balance_transaction'", "=>", "'Pingpp\\\\BalanceTransaction'", ",", "'withdrawal'", "=>", "'Pingpp\\\\Withdrawal'", ",", "'batch_withdrawal'", "=>", "'Pingpp\\\\BatchWithdrawal'", ",", "'coupon_template'", "=>", "'Pingpp\\\\CouponTemplate'", ",", "'coupon'", "=>", "'Pingpp\\\\Coupon'", ",", "'sub_app'", "=>", "'Pingpp\\\\SubApp'", ",", "'channel'", "=>", "'Pingpp\\\\Channel'", ",", "'royalty'", "=>", "'Pingpp\\\\Royalty'", ",", "'royalty_settlement'", "=>", "'Pingpp\\\\RoyaltySettlement'", ",", "'royalty_transaction'", "=>", "'Pingpp\\\\RoyaltyTransaction'", ",", "'settle_account'", "=>", "'Pingpp\\\\SettleAccount'", ",", "'royalty_template'", "=>", "'Pingpp\\\\RoyaltyTemplate'", ",", "'recharge'", "=>", "'Pingpp\\\\Recharge'", ",", "'balance_bonus'", "=>", "'Pingpp\\\\BalanceBonus'", ",", "'balance_settlements'", "=>", "'Pingpp\\\\BalanceSettlements'", ",", "'balance_transfer'", "=>", "'Pingpp\\\\BalanceTransfer'", ",", ")", ";", "if", "(", "self", "::", "isList", "(", "$", "resp", ")", ")", "{", "$", "mapped", "=", "array", "(", ")", ";", "foreach", "(", "$", "resp", "as", "$", "i", ")", "array_push", "(", "$", "mapped", ",", "self", "::", "convertToPingppObject", "(", "$", "i", ",", "$", "opts", ")", ")", ";", "return", "$", "mapped", ";", "}", "else", "if", "(", "is_object", "(", "$", "resp", ")", ")", "{", "if", "(", "isset", "(", "$", "resp", "->", "object", ")", "&&", "is_string", "(", "$", "resp", "->", "object", ")", "&&", "isset", "(", "$", "types", "[", "$", "resp", "->", "object", "]", ")", ")", "{", "$", "class", "=", "$", "types", "[", "$", "resp", "->", "object", "]", ";", "}", "else", "{", "$", "class", "=", "'Pingpp\\\\PingppObject'", ";", "}", "return", "$", "class", "::", "constructFrom", "(", "$", "resp", ",", "$", "opts", ")", ";", "}", "else", "{", "return", "$", "resp", ";", "}", "}" ]
Converts a response from the Pingpp API to the corresponding PHP object. @param stdObject $resp The response from the Pingpp API. @param array $opts @return PingppObject|array
[ "Converts", "a", "response", "from", "the", "Pingpp", "API", "to", "the", "corresponding", "PHP", "object", "." ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/Util/Util.php#L87-L135
PingPlusPlus/pingpp-php
lib/Util/Util.php
Util.getRequestHeaders
public static function getRequestHeaders() { if (function_exists('getallheaders')) { $headers = array(); foreach (getallheaders() as $name => $value) { $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('-', ' ', $name))))] = $value; } return $headers; } $headers = array(); foreach ($_SERVER as $name => $value) { if (substr($name, 0, 5) == 'HTTP_') { $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; } } return $headers; }
php
public static function getRequestHeaders() { if (function_exists('getallheaders')) { $headers = array(); foreach (getallheaders() as $name => $value) { $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('-', ' ', $name))))] = $value; } return $headers; } $headers = array(); foreach ($_SERVER as $name => $value) { if (substr($name, 0, 5) == 'HTTP_') { $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; } } return $headers; }
[ "public", "static", "function", "getRequestHeaders", "(", ")", "{", "if", "(", "function_exists", "(", "'getallheaders'", ")", ")", "{", "$", "headers", "=", "array", "(", ")", ";", "foreach", "(", "getallheaders", "(", ")", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "headers", "[", "str_replace", "(", "' '", ",", "'-'", ",", "ucwords", "(", "strtolower", "(", "str_replace", "(", "'-'", ",", "' '", ",", "$", "name", ")", ")", ")", ")", "]", "=", "$", "value", ";", "}", "return", "$", "headers", ";", "}", "$", "headers", "=", "array", "(", ")", ";", "foreach", "(", "$", "_SERVER", "as", "$", "name", "=>", "$", "value", ")", "{", "if", "(", "substr", "(", "$", "name", ",", "0", ",", "5", ")", "==", "'HTTP_'", ")", "{", "$", "headers", "[", "str_replace", "(", "' '", ",", "'-'", ",", "ucwords", "(", "strtolower", "(", "str_replace", "(", "'_'", ",", "' '", ",", "substr", "(", "$", "name", ",", "5", ")", ")", ")", ")", ")", "]", "=", "$", "value", ";", "}", "}", "return", "$", "headers", ";", "}" ]
Get the request headers @return array An hash map of request headers.
[ "Get", "the", "request", "headers" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/Util/Util.php#L141-L157
PingPlusPlus/pingpp-php
lib/User.php
User.retrieve
public static function retrieve($id, $options = null) { $url = static::classUrl().'/'.$id; return static::_directRequest('get', $url, null, $options); }
php
public static function retrieve($id, $options = null) { $url = static::classUrl().'/'.$id; return static::_directRequest('get', $url, null, $options); }
[ "public", "static", "function", "retrieve", "(", "$", "id", ",", "$", "options", "=", "null", ")", "{", "$", "url", "=", "static", "::", "classUrl", "(", ")", ".", "'/'", ".", "$", "id", ";", "return", "static", "::", "_directRequest", "(", "'get'", ",", "$", "url", ",", "null", ",", "$", "options", ")", ";", "}" ]
@param string $id The ID of the user to retrieve. @param array|string|null $options @return User
[ "@param", "string", "$id", "The", "ID", "of", "the", "user", "to", "retrieve", ".", "@param", "array|string|null", "$options" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/User.php#L13-L17
PingPlusPlus/pingpp-php
lib/WxpubOAuth.php
WxpubOAuth.getOpenid
public static function getOpenid($app_id, $app_secret, $code) { $url = WxpubOAuth::_createOauthUrlForOpenid($app_id, $app_secret, $code); $res = self::_getRequest($url); $data = json_decode($res, true); return $data['openid']; }
php
public static function getOpenid($app_id, $app_secret, $code) { $url = WxpubOAuth::_createOauthUrlForOpenid($app_id, $app_secret, $code); $res = self::_getRequest($url); $data = json_decode($res, true); return $data['openid']; }
[ "public", "static", "function", "getOpenid", "(", "$", "app_id", ",", "$", "app_secret", ",", "$", "code", ")", "{", "$", "url", "=", "WxpubOAuth", "::", "_createOauthUrlForOpenid", "(", "$", "app_id", ",", "$", "app_secret", ",", "$", "code", ")", ";", "$", "res", "=", "self", "::", "_getRequest", "(", "$", "url", ")", ";", "$", "data", "=", "json_decode", "(", "$", "res", ",", "true", ")", ";", "return", "$", "data", "[", "'openid'", "]", ";", "}" ]
获取微信公众号授权用户唯一标识 @param $app_id 微信公众号应用唯一标识 @param $app_secret 微信公众号应用密钥(注意保密) @param $code 授权code, 通过调用WxpubOAuth::createOauthUrlForCode来获取 @return openid 微信公众号授权用户唯一标识, 可用于微信网页内支付
[ "获取微信公众号授权用户唯一标识" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/WxpubOAuth.php#L19-L26
PingPlusPlus/pingpp-php
lib/WxpubOAuth.php
WxpubOAuth.createOauthUrlForCode
public static function createOauthUrlForCode($app_id, $redirect_url, $more_info = false) { $urlObj = array(); $urlObj['appid'] = $app_id; $urlObj['redirect_uri'] = $redirect_url; $urlObj['response_type'] = 'code'; $urlObj['scope'] = $more_info ? 'snsapi_userinfo' : 'snsapi_base'; $urlObj['state'] = 'STATE' . '#wechat_redirect'; $queryStr = http_build_query($urlObj); return 'https://open.weixin.qq.com/connect/oauth2/authorize?' . $queryStr; }
php
public static function createOauthUrlForCode($app_id, $redirect_url, $more_info = false) { $urlObj = array(); $urlObj['appid'] = $app_id; $urlObj['redirect_uri'] = $redirect_url; $urlObj['response_type'] = 'code'; $urlObj['scope'] = $more_info ? 'snsapi_userinfo' : 'snsapi_base'; $urlObj['state'] = 'STATE' . '#wechat_redirect'; $queryStr = http_build_query($urlObj); return 'https://open.weixin.qq.com/connect/oauth2/authorize?' . $queryStr; }
[ "public", "static", "function", "createOauthUrlForCode", "(", "$", "app_id", ",", "$", "redirect_url", ",", "$", "more_info", "=", "false", ")", "{", "$", "urlObj", "=", "array", "(", ")", ";", "$", "urlObj", "[", "'appid'", "]", "=", "$", "app_id", ";", "$", "urlObj", "[", "'redirect_uri'", "]", "=", "$", "redirect_url", ";", "$", "urlObj", "[", "'response_type'", "]", "=", "'code'", ";", "$", "urlObj", "[", "'scope'", "]", "=", "$", "more_info", "?", "'snsapi_userinfo'", ":", "'snsapi_base'", ";", "$", "urlObj", "[", "'state'", "]", "=", "'STATE'", ".", "'#wechat_redirect'", ";", "$", "queryStr", "=", "http_build_query", "(", "$", "urlObj", ")", ";", "return", "'https://open.weixin.qq.com/connect/oauth2/authorize?'", ".", "$", "queryStr", ";", "}" ]
用于获取授权code的URL地址,此地址用于用户身份鉴权,获取用户身份信息,同时重定向到$redirect_url @param $app_id 微信公众号应用唯一标识 @param $redirect_url 授权后重定向的回调链接地址,重定向后此地址将带有授权code参数, 该地址的域名需在微信公众号平台上进行设置, 步骤为:登陆微信公众号平台 => 开发者中心 => 网页授权获取用户基本信息 => 修改 @param bool $more_info FALSE 不弹出授权页面,直接跳转,这个只能拿到用户openid TRUE 弹出授权页面,这个可以通过 openid 拿到昵称、性别、所在地, @return string 用于获取授权code的URL地址
[ "用于获取授权code的URL地址,此地址用于用户身份鉴权,获取用户身份信息,同时重定向到$redirect_url" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/WxpubOAuth.php#L38-L49
PingPlusPlus/pingpp-php
lib/WxpubOAuth.php
WxpubOAuth._createOauthUrlForOpenid
private static function _createOauthUrlForOpenid($app_id, $app_secret, $code) { $urlObj = array(); $urlObj['appid'] = $app_id; $urlObj['secret'] = $app_secret; $urlObj['code'] = $code; $urlObj['grant_type'] = 'authorization_code'; $queryStr = http_build_query($urlObj); return 'https://api.weixin.qq.com/sns/oauth2/access_token?' . $queryStr; }
php
private static function _createOauthUrlForOpenid($app_id, $app_secret, $code) { $urlObj = array(); $urlObj['appid'] = $app_id; $urlObj['secret'] = $app_secret; $urlObj['code'] = $code; $urlObj['grant_type'] = 'authorization_code'; $queryStr = http_build_query($urlObj); return 'https://api.weixin.qq.com/sns/oauth2/access_token?' . $queryStr; }
[ "private", "static", "function", "_createOauthUrlForOpenid", "(", "$", "app_id", ",", "$", "app_secret", ",", "$", "code", ")", "{", "$", "urlObj", "=", "array", "(", ")", ";", "$", "urlObj", "[", "'appid'", "]", "=", "$", "app_id", ";", "$", "urlObj", "[", "'secret'", "]", "=", "$", "app_secret", ";", "$", "urlObj", "[", "'code'", "]", "=", "$", "code", ";", "$", "urlObj", "[", "'grant_type'", "]", "=", "'authorization_code'", ";", "$", "queryStr", "=", "http_build_query", "(", "$", "urlObj", ")", ";", "return", "'https://api.weixin.qq.com/sns/oauth2/access_token?'", ".", "$", "queryStr", ";", "}" ]
获取openid的URL地址 @param $app_id 微信公众号应用唯一标识 @param $app_secret 微信公众号应用密钥(注意保密) @param $code 授权code, 通过调用WxpubOAuth::createOauthUrlForCode来获取 @return string 获取openid的URL地址
[ "获取openid的URL地址" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/WxpubOAuth.php#L58-L68
PingPlusPlus/pingpp-php
lib/WxpubOAuth.php
WxpubOAuth.getJsapiTicket
public static function getJsapiTicket($app_id, $app_secret) { $urlObj = array(); $urlObj['appid'] = $app_id; $urlObj['secret'] = $app_secret; $urlObj['grant_type'] = 'client_credential'; $queryStr = http_build_query($urlObj); $accessTokenUrl = 'https://api.weixin.qq.com/cgi-bin/token?' . $queryStr; $resp = self::_getRequest($accessTokenUrl); $resp = json_decode($resp, true); if (!is_array($resp) || isset($resp['errcode'])) { return $resp; } $urlObj = array(); $urlObj['access_token'] = $resp['access_token']; $urlObj['type'] = 'jsapi'; $queryStr = http_build_query($urlObj); $jsapiTicketUrl = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?' . $queryStr; $resp = self::_getRequest($jsapiTicketUrl); return json_decode($resp, true); }
php
public static function getJsapiTicket($app_id, $app_secret) { $urlObj = array(); $urlObj['appid'] = $app_id; $urlObj['secret'] = $app_secret; $urlObj['grant_type'] = 'client_credential'; $queryStr = http_build_query($urlObj); $accessTokenUrl = 'https://api.weixin.qq.com/cgi-bin/token?' . $queryStr; $resp = self::_getRequest($accessTokenUrl); $resp = json_decode($resp, true); if (!is_array($resp) || isset($resp['errcode'])) { return $resp; } $urlObj = array(); $urlObj['access_token'] = $resp['access_token']; $urlObj['type'] = 'jsapi'; $queryStr = http_build_query($urlObj); $jsapiTicketUrl = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?' . $queryStr; $resp = self::_getRequest($jsapiTicketUrl); return json_decode($resp, true); }
[ "public", "static", "function", "getJsapiTicket", "(", "$", "app_id", ",", "$", "app_secret", ")", "{", "$", "urlObj", "=", "array", "(", ")", ";", "$", "urlObj", "[", "'appid'", "]", "=", "$", "app_id", ";", "$", "urlObj", "[", "'secret'", "]", "=", "$", "app_secret", ";", "$", "urlObj", "[", "'grant_type'", "]", "=", "'client_credential'", ";", "$", "queryStr", "=", "http_build_query", "(", "$", "urlObj", ")", ";", "$", "accessTokenUrl", "=", "'https://api.weixin.qq.com/cgi-bin/token?'", ".", "$", "queryStr", ";", "$", "resp", "=", "self", "::", "_getRequest", "(", "$", "accessTokenUrl", ")", ";", "$", "resp", "=", "json_decode", "(", "$", "resp", ",", "true", ")", ";", "if", "(", "!", "is_array", "(", "$", "resp", ")", "||", "isset", "(", "$", "resp", "[", "'errcode'", "]", ")", ")", "{", "return", "$", "resp", ";", "}", "$", "urlObj", "=", "array", "(", ")", ";", "$", "urlObj", "[", "'access_token'", "]", "=", "$", "resp", "[", "'access_token'", "]", ";", "$", "urlObj", "[", "'type'", "]", "=", "'jsapi'", ";", "$", "queryStr", "=", "http_build_query", "(", "$", "urlObj", ")", ";", "$", "jsapiTicketUrl", "=", "'https://api.weixin.qq.com/cgi-bin/ticket/getticket?'", ".", "$", "queryStr", ";", "$", "resp", "=", "self", "::", "_getRequest", "(", "$", "jsapiTicketUrl", ")", ";", "return", "json_decode", "(", "$", "resp", ",", "true", ")", ";", "}" ]
获取微信公众号 jsapi_ticket @param $app_id 微信公众号应用唯一标识 @param $app_secret 微信公众号应用密钥(注意保密) @return array 包含 jsapi_ticket 的数组或者错误信息
[ "获取微信公众号", "jsapi_ticket" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/WxpubOAuth.php#L93-L114
PingPlusPlus/pingpp-php
lib/WxpubOAuth.php
WxpubOAuth.getSignature
public static function getSignature($charge, $jsapi_ticket, $url = NULL) { if (!isset($charge['credential']) || !isset($charge['credential']['wx_pub'])) { return null; } $credential = $charge['credential']['wx_pub']; $arrayToSign = array(); $arrayToSign[] = 'jsapi_ticket=' . $jsapi_ticket; $arrayToSign[] = 'noncestr=' . $credential['nonceStr']; $arrayToSign[] = 'timestamp=' . $credential['timeStamp']; if (!$url) { $requestUri = explode('#', $_SERVER['REQUEST_URI']); $scheme = isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http'); $url = $scheme . '://' . $_SERVER['HTTP_HOST'] . $requestUri[0]; } $arrayToSign[] = 'url=' . $url; return sha1(implode('&', $arrayToSign)); }
php
public static function getSignature($charge, $jsapi_ticket, $url = NULL) { if (!isset($charge['credential']) || !isset($charge['credential']['wx_pub'])) { return null; } $credential = $charge['credential']['wx_pub']; $arrayToSign = array(); $arrayToSign[] = 'jsapi_ticket=' . $jsapi_ticket; $arrayToSign[] = 'noncestr=' . $credential['nonceStr']; $arrayToSign[] = 'timestamp=' . $credential['timeStamp']; if (!$url) { $requestUri = explode('#', $_SERVER['REQUEST_URI']); $scheme = isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http'); $url = $scheme . '://' . $_SERVER['HTTP_HOST'] . $requestUri[0]; } $arrayToSign[] = 'url=' . $url; return sha1(implode('&', $arrayToSign)); }
[ "public", "static", "function", "getSignature", "(", "$", "charge", ",", "$", "jsapi_ticket", ",", "$", "url", "=", "NULL", ")", "{", "if", "(", "!", "isset", "(", "$", "charge", "[", "'credential'", "]", ")", "||", "!", "isset", "(", "$", "charge", "[", "'credential'", "]", "[", "'wx_pub'", "]", ")", ")", "{", "return", "null", ";", "}", "$", "credential", "=", "$", "charge", "[", "'credential'", "]", "[", "'wx_pub'", "]", ";", "$", "arrayToSign", "=", "array", "(", ")", ";", "$", "arrayToSign", "[", "]", "=", "'jsapi_ticket='", ".", "$", "jsapi_ticket", ";", "$", "arrayToSign", "[", "]", "=", "'noncestr='", ".", "$", "credential", "[", "'nonceStr'", "]", ";", "$", "arrayToSign", "[", "]", "=", "'timestamp='", ".", "$", "credential", "[", "'timeStamp'", "]", ";", "if", "(", "!", "$", "url", ")", "{", "$", "requestUri", "=", "explode", "(", "'#'", ",", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ")", ";", "$", "scheme", "=", "isset", "(", "$", "_SERVER", "[", "'REQUEST_SCHEME'", "]", ")", "?", "$", "_SERVER", "[", "'REQUEST_SCHEME'", "]", ":", "(", "isset", "(", "$", "_SERVER", "[", "'HTTPS'", "]", ")", "&&", "strtolower", "(", "$", "_SERVER", "[", "'HTTPS'", "]", ")", "!==", "'off'", "?", "'https'", ":", "'http'", ")", ";", "$", "url", "=", "$", "scheme", ".", "'://'", ".", "$", "_SERVER", "[", "'HTTP_HOST'", "]", ".", "$", "requestUri", "[", "0", "]", ";", "}", "$", "arrayToSign", "[", "]", "=", "'url='", ".", "$", "url", ";", "return", "sha1", "(", "implode", "(", "'&'", ",", "$", "arrayToSign", ")", ")", ";", "}" ]
生成微信公众号 js sdk signature @param $charge charge @param $jsapi_ticket @param $url 是当前网页的 URL,不包含 # 及其后面部分 @return string signature 字符串
[ "生成微信公众号", "js", "sdk", "signature" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/WxpubOAuth.php#L123-L142
PingPlusPlus/pingpp-php
lib/Agreement.php
Agreement.cancel
public static function cancel($id, $params = null, $options = null) { $url = static::classUrl().'/'.$id; if (empty($params)) { $params = ['status' => 'canceled']; } else { $params = array_merge($params, ['status' => 'canceled']); } return static::_directRequest('put', $url, $params, $options); }
php
public static function cancel($id, $params = null, $options = null) { $url = static::classUrl().'/'.$id; if (empty($params)) { $params = ['status' => 'canceled']; } else { $params = array_merge($params, ['status' => 'canceled']); } return static::_directRequest('put', $url, $params, $options); }
[ "public", "static", "function", "cancel", "(", "$", "id", ",", "$", "params", "=", "null", ",", "$", "options", "=", "null", ")", "{", "$", "url", "=", "static", "::", "classUrl", "(", ")", ".", "'/'", ".", "$", "id", ";", "if", "(", "empty", "(", "$", "params", ")", ")", "{", "$", "params", "=", "[", "'status'", "=>", "'canceled'", "]", ";", "}", "else", "{", "$", "params", "=", "array_merge", "(", "$", "params", ",", "[", "'status'", "=>", "'canceled'", "]", ")", ";", "}", "return", "static", "::", "_directRequest", "(", "'put'", ",", "$", "url", ",", "$", "params", ",", "$", "options", ")", ";", "}" ]
@param string $id API resource ID @param array|string|null $options @return Agreement The canceled agreement.
[ "@param", "string", "$id", "API", "resource", "ID", "@param", "array|string|null", "$options" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/Agreement.php#L46-L55
PingPlusPlus/pingpp-php
lib/ApiRequestor.php
ApiRequestor.handleApiError
public function handleApiError($rbody, $rcode, $resp) { if (!is_object($resp) || !isset($resp->error)) { $msg = "Invalid response object from API: $rbody " ."(HTTP response code was $rcode)"; throw new Error\Api($msg, $rcode, $rbody, $resp); } $error = $resp->error; $msg = isset($error->message) ? $error->message : null; $param = isset($error->param) ? $error->param : null; $code = isset($error->code) ? $error->code : null; switch ($rcode) { case 400: if ($code == 'rate_limit') { throw new Error\RateLimit( $msg, $param, $rcode, $rbody, $resp ); } case 404: throw new Error\InvalidRequest( $msg, $param, $rcode, $rbody, $resp ); case 401: throw new Error\Authentication($msg, $rcode, $rbody, $resp); case 402: throw new Error\Channel( $msg, $code, $param, $rcode, $rbody, $resp ); default: throw new Error\Api($msg, $rcode, $rbody, $resp); } }
php
public function handleApiError($rbody, $rcode, $resp) { if (!is_object($resp) || !isset($resp->error)) { $msg = "Invalid response object from API: $rbody " ."(HTTP response code was $rcode)"; throw new Error\Api($msg, $rcode, $rbody, $resp); } $error = $resp->error; $msg = isset($error->message) ? $error->message : null; $param = isset($error->param) ? $error->param : null; $code = isset($error->code) ? $error->code : null; switch ($rcode) { case 400: if ($code == 'rate_limit') { throw new Error\RateLimit( $msg, $param, $rcode, $rbody, $resp ); } case 404: throw new Error\InvalidRequest( $msg, $param, $rcode, $rbody, $resp ); case 401: throw new Error\Authentication($msg, $rcode, $rbody, $resp); case 402: throw new Error\Channel( $msg, $code, $param, $rcode, $rbody, $resp ); default: throw new Error\Api($msg, $rcode, $rbody, $resp); } }
[ "public", "function", "handleApiError", "(", "$", "rbody", ",", "$", "rcode", ",", "$", "resp", ")", "{", "if", "(", "!", "is_object", "(", "$", "resp", ")", "||", "!", "isset", "(", "$", "resp", "->", "error", ")", ")", "{", "$", "msg", "=", "\"Invalid response object from API: $rbody \"", ".", "\"(HTTP response code was $rcode)\"", ";", "throw", "new", "Error", "\\", "Api", "(", "$", "msg", ",", "$", "rcode", ",", "$", "rbody", ",", "$", "resp", ")", ";", "}", "$", "error", "=", "$", "resp", "->", "error", ";", "$", "msg", "=", "isset", "(", "$", "error", "->", "message", ")", "?", "$", "error", "->", "message", ":", "null", ";", "$", "param", "=", "isset", "(", "$", "error", "->", "param", ")", "?", "$", "error", "->", "param", ":", "null", ";", "$", "code", "=", "isset", "(", "$", "error", "->", "code", ")", "?", "$", "error", "->", "code", ":", "null", ";", "switch", "(", "$", "rcode", ")", "{", "case", "400", ":", "if", "(", "$", "code", "==", "'rate_limit'", ")", "{", "throw", "new", "Error", "\\", "RateLimit", "(", "$", "msg", ",", "$", "param", ",", "$", "rcode", ",", "$", "rbody", ",", "$", "resp", ")", ";", "}", "case", "404", ":", "throw", "new", "Error", "\\", "InvalidRequest", "(", "$", "msg", ",", "$", "param", ",", "$", "rcode", ",", "$", "rbody", ",", "$", "resp", ")", ";", "case", "401", ":", "throw", "new", "Error", "\\", "Authentication", "(", "$", "msg", ",", "$", "rcode", ",", "$", "rbody", ",", "$", "resp", ")", ";", "case", "402", ":", "throw", "new", "Error", "\\", "Channel", "(", "$", "msg", ",", "$", "code", ",", "$", "param", ",", "$", "rcode", ",", "$", "rbody", ",", "$", "resp", ")", ";", "default", ":", "throw", "new", "Error", "\\", "Api", "(", "$", "msg", ",", "$", "rcode", ",", "$", "rbody", ",", "$", "resp", ")", ";", "}", "}" ]
@param string $rbody A JSON string. @param int $rcode @param array $resp @throws InvalidRequestError if the error is caused by the user. @throws AuthenticationError if the error is caused by a lack of permissions. @throws ApiError otherwise.
[ "@param", "string", "$rbody", "A", "JSON", "string", ".", "@param", "int", "$rcode", "@param", "array", "$resp" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/ApiRequestor.php#L115-L148
PingPlusPlus/pingpp-php
lib/RoyaltyTemplate.php
RoyaltyTemplate.update
public static function update($id, $params = [], $options = []) { $url = static::classUrl() . '/' . $id; return static::_directRequest('put', $url, $params, $options); }
php
public static function update($id, $params = [], $options = []) { $url = static::classUrl() . '/' . $id; return static::_directRequest('put', $url, $params, $options); }
[ "public", "static", "function", "update", "(", "$", "id", ",", "$", "params", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "$", "url", "=", "static", "::", "classUrl", "(", ")", ".", "'/'", ".", "$", "id", ";", "return", "static", "::", "_directRequest", "(", "'put'", ",", "$", "url", ",", "$", "params", ",", "$", "options", ")", ";", "}" ]
Update RoyaltyTemplate @param $id @param array $params @param array $options @return RoyaltyTemplate
[ "Update", "RoyaltyTemplate" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/RoyaltyTemplate.php#L40-L44
PingPlusPlus/pingpp-php
lib/RoyaltyTemplate.php
RoyaltyTemplate.delete
public static function delete($id, $options = []) { $url = static::classUrl() . '/' . $id; return static::_directRequest('delete', $url, null, $options); }
php
public static function delete($id, $options = []) { $url = static::classUrl() . '/' . $id; return static::_directRequest('delete', $url, null, $options); }
[ "public", "static", "function", "delete", "(", "$", "id", ",", "$", "options", "=", "[", "]", ")", "{", "$", "url", "=", "static", "::", "classUrl", "(", ")", ".", "'/'", ".", "$", "id", ";", "return", "static", "::", "_directRequest", "(", "'delete'", ",", "$", "url", ",", "null", ",", "$", "options", ")", ";", "}" ]
Delete RoyaltyTemplate @param $id @param array $options @return RoyaltyTemplate
[ "Delete", "RoyaltyTemplate" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/RoyaltyTemplate.php#L52-L56
PingPlusPlus/pingpp-php
lib/Charge.php
Charge.reverse
public static function reverse($id, $options = null) { $url = static::classUrl().'/'.$id.'/reverse'; $params = []; return static::_directRequest('post', $url, $params, $options); }
php
public static function reverse($id, $options = null) { $url = static::classUrl().'/'.$id.'/reverse'; $params = []; return static::_directRequest('post', $url, $params, $options); }
[ "public", "static", "function", "reverse", "(", "$", "id", ",", "$", "options", "=", "null", ")", "{", "$", "url", "=", "static", "::", "classUrl", "(", ")", ".", "'/'", ".", "$", "id", ".", "'/reverse'", ";", "$", "params", "=", "[", "]", ";", "return", "static", "::", "_directRequest", "(", "'post'", ",", "$", "url", ",", "$", "params", ",", "$", "options", ")", ";", "}" ]
@param string $id The ID of the charge. @param array|string|null $options @return Charge The reversed charge.
[ "@param", "string", "$id", "The", "ID", "of", "the", "charge", ".", "@param", "array|string|null", "$options" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/Charge.php#L46-L51
PingPlusPlus/pingpp-php
lib/BatchWithdrawal.php
BatchWithdrawal.confirm
public static function confirm($params = null, $options = null) { $params['status'] = 'pending'; return self::_create($params, $options); }
php
public static function confirm($params = null, $options = null) { $params['status'] = 'pending'; return self::_create($params, $options); }
[ "public", "static", "function", "confirm", "(", "$", "params", "=", "null", ",", "$", "options", "=", "null", ")", "{", "$", "params", "[", "'status'", "]", "=", "'pending'", ";", "return", "self", "::", "_create", "(", "$", "params", ",", "$", "options", ")", ";", "}" ]
批量提现确认 @param array|null $params @param array|string|null $options @return BatchWithdrawal The created withdrawal.
[ "批量提现确认", "@param", "array|null", "$params", "@param", "array|string|null", "$options" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/BatchWithdrawal.php#L30-L34
PingPlusPlus/pingpp-php
lib/BatchWithdrawal.php
BatchWithdrawal.cancel
public static function cancel($params = null, $options = null) { $params['status'] = 'canceled'; return self::_create($params, $options); }
php
public static function cancel($params = null, $options = null) { $params['status'] = 'canceled'; return self::_create($params, $options); }
[ "public", "static", "function", "cancel", "(", "$", "params", "=", "null", ",", "$", "options", "=", "null", ")", "{", "$", "params", "[", "'status'", "]", "=", "'canceled'", ";", "return", "self", "::", "_create", "(", "$", "params", ",", "$", "options", ")", ";", "}" ]
批量提现撤销 @param null $params @param null $options @return array|PingppObject
[ "批量提现撤销" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/BatchWithdrawal.php#L42-L46
PingPlusPlus/pingpp-php
lib/Royalty.php
Royalty.update
public static function update($params, $options = null) { $url = static::classUrl(); return static::_directRequest('put', $url, $params, $options); }
php
public static function update($params, $options = null) { $url = static::classUrl(); return static::_directRequest('put', $url, $params, $options); }
[ "public", "static", "function", "update", "(", "$", "params", ",", "$", "options", "=", "null", ")", "{", "$", "url", "=", "static", "::", "classUrl", "(", ")", ";", "return", "static", "::", "_directRequest", "(", "'put'", ",", "$", "url", ",", "$", "params", ",", "$", "options", ")", ";", "}" ]
批量更新分润对象 @param $params @param $options @return Royalty
[ "批量更新分润对象" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/Royalty.php#L23-L27
PingPlusPlus/pingpp-php
lib/Withdrawal.php
Withdrawal.confirm
public static function confirm($id, $options = null) { $url = static::classUrl().'/'.$id; $params = array('status' => 'pending'); return static::_directRequest('put', $url, $params, $options); }
php
public static function confirm($id, $options = null) { $url = static::classUrl().'/'.$id; $params = array('status' => 'pending'); return static::_directRequest('put', $url, $params, $options); }
[ "public", "static", "function", "confirm", "(", "$", "id", ",", "$", "options", "=", "null", ")", "{", "$", "url", "=", "static", "::", "classUrl", "(", ")", ".", "'/'", ".", "$", "id", ";", "$", "params", "=", "array", "(", "'status'", "=>", "'pending'", ")", ";", "return", "static", "::", "_directRequest", "(", "'put'", ",", "$", "url", ",", "$", "params", ",", "$", "options", ")", ";", "}" ]
@param string $id API resource ID @param array|string|null $options @return Withdrawal The confirmed withdrawal.
[ "@param", "string", "$id", "API", "resource", "ID", "@param", "array|string|null", "$options" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/Withdrawal.php#L35-L40
PingPlusPlus/pingpp-php
lib/Withdrawal.php
Withdrawal.cancel
public static function cancel($id, $options = null) { $url = static::classUrl().'/'.$id; $params = array('status' => 'canceled'); return static::_directRequest('put', $url, $params, $options); }
php
public static function cancel($id, $options = null) { $url = static::classUrl().'/'.$id; $params = array('status' => 'canceled'); return static::_directRequest('put', $url, $params, $options); }
[ "public", "static", "function", "cancel", "(", "$", "id", ",", "$", "options", "=", "null", ")", "{", "$", "url", "=", "static", "::", "classUrl", "(", ")", ".", "'/'", ".", "$", "id", ";", "$", "params", "=", "array", "(", "'status'", "=>", "'canceled'", ")", ";", "return", "static", "::", "_directRequest", "(", "'put'", ",", "$", "url", ",", "$", "params", ",", "$", "options", ")", ";", "}" ]
@param string $id API resource ID @param array|string|null $options @return Withdrawal The canceled withdrawal.
[ "@param", "string", "$id", "API", "resource", "ID", "@param", "array|string|null", "$options" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/Withdrawal.php#L48-L53
PingPlusPlus/pingpp-php
lib/Withdrawal.php
Withdrawal.batchConfirm
public static function batchConfirm($params = null, $options = null) { $url = static::appBaseUrl().'/batch_withdrawals'; return static::_directRequest('post', $url, $params, $options); }
php
public static function batchConfirm($params = null, $options = null) { $url = static::appBaseUrl().'/batch_withdrawals'; return static::_directRequest('post', $url, $params, $options); }
[ "public", "static", "function", "batchConfirm", "(", "$", "params", "=", "null", ",", "$", "options", "=", "null", ")", "{", "$", "url", "=", "static", "::", "appBaseUrl", "(", ")", ".", "'/batch_withdrawals'", ";", "return", "static", "::", "_directRequest", "(", "'post'", ",", "$", "url", ",", "$", "params", ",", "$", "options", ")", ";", "}" ]
@param array|null $params @param array|string|null $options @return array An array of batch withdrawals.
[ "@param", "array|null", "$params", "@param", "array|string|null", "$options" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/Withdrawal.php#L72-L76
PingPlusPlus/pingpp-php
lib/WxLiteOAuth.php
WxLiteOAuth.getSession
public static function getSession($app_id, $app_secret, $code) { $url_params = [ 'appid' => $app_id, 'secret' => $app_secret, 'js_code' => $code, 'grant_type'=> 'authorization_code', ]; $query_str = http_build_query($url_params); $url = 'https://api.weixin.qq.com/sns/jscode2session?' . $query_str; $res = self::getRequest($url); if (empty($res)) { throw new Error\Api("connect error"); } $data = json_decode($res, true); if (!isset($data['openid']) || isset($data['errcode'])) { throw new Error\Api($res); } return $data; }
php
public static function getSession($app_id, $app_secret, $code) { $url_params = [ 'appid' => $app_id, 'secret' => $app_secret, 'js_code' => $code, 'grant_type'=> 'authorization_code', ]; $query_str = http_build_query($url_params); $url = 'https://api.weixin.qq.com/sns/jscode2session?' . $query_str; $res = self::getRequest($url); if (empty($res)) { throw new Error\Api("connect error"); } $data = json_decode($res, true); if (!isset($data['openid']) || isset($data['errcode'])) { throw new Error\Api($res); } return $data; }
[ "public", "static", "function", "getSession", "(", "$", "app_id", ",", "$", "app_secret", ",", "$", "code", ")", "{", "$", "url_params", "=", "[", "'appid'", "=>", "$", "app_id", ",", "'secret'", "=>", "$", "app_secret", ",", "'js_code'", "=>", "$", "code", ",", "'grant_type'", "=>", "'authorization_code'", ",", "]", ";", "$", "query_str", "=", "http_build_query", "(", "$", "url_params", ")", ";", "$", "url", "=", "'https://api.weixin.qq.com/sns/jscode2session?'", ".", "$", "query_str", ";", "$", "res", "=", "self", "::", "getRequest", "(", "$", "url", ")", ";", "if", "(", "empty", "(", "$", "res", ")", ")", "{", "throw", "new", "Error", "\\", "Api", "(", "\"connect error\"", ")", ";", "}", "$", "data", "=", "json_decode", "(", "$", "res", ",", "true", ")", ";", "if", "(", "!", "isset", "(", "$", "data", "[", "'openid'", "]", ")", "||", "isset", "(", "$", "data", "[", "'errcode'", "]", ")", ")", "{", "throw", "new", "Error", "\\", "Api", "(", "$", "res", ")", ";", "}", "return", "$", "data", ";", "}" ]
获取 session_key 和 openid 等 @param string $app_id 微信小程序应用唯一标识 @param string $app_secret 微信小程序应用密钥(注意保密) @param string $code 授权code, 登录时获取的 code @return array 正常返回数组 [ 'openid' => 'OPENID', 'session_key' => 'SESSIONKEY' ] 满足 UnionID 返回条件时返回数组 [ 'openid' => 'OPENID', 'session_key' => 'SESSIONKEY', 'unionid' => 'UNIONID' ]
[ "获取", "session_key", "和", "openid", "等", "@param", "string", "$app_id", "微信小程序应用唯一标识", "@param", "string", "$app_secret", "微信小程序应用密钥(注意保密)", "@param", "string", "$code", "授权code", "登录时获取的", "code", "@return", "array", "正常返回数组", "[", "openid", "=", ">", "OPENID", "session_key", "=", ">", "SESSIONKEY", "]" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/WxLiteOAuth.php#L45-L65
PingPlusPlus/pingpp-php
lib/WxLiteOAuth.php
WxLiteOAuth.getRequest
private static function getRequest($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $res = curl_exec($ch); curl_close($ch); return $res; }
php
private static function getRequest($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $res = curl_exec($ch); curl_close($ch); return $res; }
[ "private", "static", "function", "getRequest", "(", "$", "url", ")", "{", "$", "ch", "=", "curl_init", "(", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_TIMEOUT", ",", "30", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_URL", ",", "$", "url", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_SSL_VERIFYPEER", ",", "FALSE", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_SSL_VERIFYHOST", ",", "FALSE", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_HEADER", ",", "FALSE", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_RETURNTRANSFER", ",", "TRUE", ")", ";", "$", "res", "=", "curl_exec", "(", "$", "ch", ")", ";", "curl_close", "(", "$", "ch", ")", ";", "return", "$", "res", ";", "}" ]
GET 请求
[ "GET", "请求" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/WxLiteOAuth.php#L71-L84
PingPlusPlus/pingpp-php
lib/AttachedObject.php
AttachedObject.replaceWith
public function replaceWith($properties) { $removed = array_diff(array_keys($this->_values), array_keys($properties)); foreach ($removed as $k) { unset($this->$k); } foreach ($properties as $k => $v) { $this->$k = $v; } }
php
public function replaceWith($properties) { $removed = array_diff(array_keys($this->_values), array_keys($properties)); foreach ($removed as $k) { unset($this->$k); } foreach ($properties as $k => $v) { $this->$k = $v; } }
[ "public", "function", "replaceWith", "(", "$", "properties", ")", "{", "$", "removed", "=", "array_diff", "(", "array_keys", "(", "$", "this", "->", "_values", ")", ",", "array_keys", "(", "$", "properties", ")", ")", ";", "foreach", "(", "$", "removed", "as", "$", "k", ")", "{", "unset", "(", "$", "this", "->", "$", "k", ")", ";", "}", "foreach", "(", "$", "properties", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "this", "->", "$", "k", "=", "$", "v", ";", "}", "}" ]
Updates this object. @param array $properties A mapping of properties to update on this object.
[ "Updates", "this", "object", "." ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/AttachedObject.php#L13-L23
PingPlusPlus/pingpp-php
lib/Util/RequestOptions.php
RequestOptions.merge
public function merge($options) { $other_options = self::parse($options); if ($other_options->apiKey === null) { $other_options->apiKey = $this->apiKey; } $other_options->headers = array_merge($this->headers, $other_options->headers); return $other_options; }
php
public function merge($options) { $other_options = self::parse($options); if ($other_options->apiKey === null) { $other_options->apiKey = $this->apiKey; } $other_options->headers = array_merge($this->headers, $other_options->headers); return $other_options; }
[ "public", "function", "merge", "(", "$", "options", ")", "{", "$", "other_options", "=", "self", "::", "parse", "(", "$", "options", ")", ";", "if", "(", "$", "other_options", "->", "apiKey", "===", "null", ")", "{", "$", "other_options", "->", "apiKey", "=", "$", "this", "->", "apiKey", ";", "}", "$", "other_options", "->", "headers", "=", "array_merge", "(", "$", "this", "->", "headers", ",", "$", "other_options", "->", "headers", ")", ";", "return", "$", "other_options", ";", "}" ]
Unpacks an options array and merges it into the existing RequestOptions object. @param array|string|null $options a key => value array @return RequestOptions
[ "Unpacks", "an", "options", "array", "and", "merges", "it", "into", "the", "existing", "RequestOptions", "object", ".", "@param", "array|string|null", "$options", "a", "key", "=", ">", "value", "array" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/Util/RequestOptions.php#L27-L35
PingPlusPlus/pingpp-php
lib/Util/RequestOptions.php
RequestOptions.parse
public static function parse($options) { if ($options instanceof self) { return $options; } if (is_null($options)) { return new RequestOptions(null, array()); } if (is_string($options)) { return new RequestOptions($options, array()); } if (is_array($options)) { $headers = array(); $key = null; $signOpts = array(); if (array_key_exists('api_key', $options)) { $key = $options['api_key']; } if (array_key_exists('pingpp_version', $options)) { $headers['Pingpp-Version'] = $options['pingpp_version']; } if (array_key_exists('sign_opts', $options)) { $signOpts = $options['sign_opts']; } return new RequestOptions($key, $headers, $signOpts); } $message = 'The second argument to Pingpp API method calls is an ' . 'optional per-request apiKey, which must be a string, or ' . 'per-request options, which must be an array. (HINT: you can set ' . 'a global apiKey by "Pingpp::setApiKey(<apiKey>)")'; throw new Error\Api($message); }
php
public static function parse($options) { if ($options instanceof self) { return $options; } if (is_null($options)) { return new RequestOptions(null, array()); } if (is_string($options)) { return new RequestOptions($options, array()); } if (is_array($options)) { $headers = array(); $key = null; $signOpts = array(); if (array_key_exists('api_key', $options)) { $key = $options['api_key']; } if (array_key_exists('pingpp_version', $options)) { $headers['Pingpp-Version'] = $options['pingpp_version']; } if (array_key_exists('sign_opts', $options)) { $signOpts = $options['sign_opts']; } return new RequestOptions($key, $headers, $signOpts); } $message = 'The second argument to Pingpp API method calls is an ' . 'optional per-request apiKey, which must be a string, or ' . 'per-request options, which must be an array. (HINT: you can set ' . 'a global apiKey by "Pingpp::setApiKey(<apiKey>)")'; throw new Error\Api($message); }
[ "public", "static", "function", "parse", "(", "$", "options", ")", "{", "if", "(", "$", "options", "instanceof", "self", ")", "{", "return", "$", "options", ";", "}", "if", "(", "is_null", "(", "$", "options", ")", ")", "{", "return", "new", "RequestOptions", "(", "null", ",", "array", "(", ")", ")", ";", "}", "if", "(", "is_string", "(", "$", "options", ")", ")", "{", "return", "new", "RequestOptions", "(", "$", "options", ",", "array", "(", ")", ")", ";", "}", "if", "(", "is_array", "(", "$", "options", ")", ")", "{", "$", "headers", "=", "array", "(", ")", ";", "$", "key", "=", "null", ";", "$", "signOpts", "=", "array", "(", ")", ";", "if", "(", "array_key_exists", "(", "'api_key'", ",", "$", "options", ")", ")", "{", "$", "key", "=", "$", "options", "[", "'api_key'", "]", ";", "}", "if", "(", "array_key_exists", "(", "'pingpp_version'", ",", "$", "options", ")", ")", "{", "$", "headers", "[", "'Pingpp-Version'", "]", "=", "$", "options", "[", "'pingpp_version'", "]", ";", "}", "if", "(", "array_key_exists", "(", "'sign_opts'", ",", "$", "options", ")", ")", "{", "$", "signOpts", "=", "$", "options", "[", "'sign_opts'", "]", ";", "}", "return", "new", "RequestOptions", "(", "$", "key", ",", "$", "headers", ",", "$", "signOpts", ")", ";", "}", "$", "message", "=", "'The second argument to Pingpp API method calls is an '", ".", "'optional per-request apiKey, which must be a string, or '", ".", "'per-request options, which must be an array. (HINT: you can set '", ".", "'a global apiKey by \"Pingpp::setApiKey(<apiKey>)\")'", ";", "throw", "new", "Error", "\\", "Api", "(", "$", "message", ")", ";", "}" ]
Unpacks an options array into an RequestOptions object @param array|string|null $options a key => value array @return RequestOptions
[ "Unpacks", "an", "options", "array", "into", "an", "RequestOptions", "object", "@param", "array|string|null", "$options", "a", "key", "=", ">", "value", "array" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/Util/RequestOptions.php#L43-L78
PingPlusPlus/pingpp-php
lib/SubApp.php
SubApp.delete
public static function delete($sub_app_id, $options = null) { $url = static::instanceUrlWithId($sub_app_id); return static::_directRequest('delete', $url, null, $options); }
php
public static function delete($sub_app_id, $options = null) { $url = static::instanceUrlWithId($sub_app_id); return static::_directRequest('delete', $url, null, $options); }
[ "public", "static", "function", "delete", "(", "$", "sub_app_id", ",", "$", "options", "=", "null", ")", "{", "$", "url", "=", "static", "::", "instanceUrlWithId", "(", "$", "sub_app_id", ")", ";", "return", "static", "::", "_directRequest", "(", "'delete'", ",", "$", "url", ",", "null", ",", "$", "options", ")", ";", "}" ]
删除子商户对象 @param $sub_app_id @param $options @return $this
[ "删除子商户对象" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/SubApp.php#L55-L59
PingPlusPlus/pingpp-php
lib/SubApp.php
SubApp.update
public static function update($sub_app_id, $params, $options = null) { $url = static::instanceUrlWithId($sub_app_id); return static::_directRequest('put', $url, $params, $options); }
php
public static function update($sub_app_id, $params, $options = null) { $url = static::instanceUrlWithId($sub_app_id); return static::_directRequest('put', $url, $params, $options); }
[ "public", "static", "function", "update", "(", "$", "sub_app_id", ",", "$", "params", ",", "$", "options", "=", "null", ")", "{", "$", "url", "=", "static", "::", "instanceUrlWithId", "(", "$", "sub_app_id", ")", ";", "return", "static", "::", "_directRequest", "(", "'put'", ",", "$", "url", ",", "$", "params", ",", "$", "options", ")", ";", "}" ]
更新子商户对象 @param $sub_app_id @param $params @param $options @return array|PingppObject
[ "更新子商户对象" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/SubApp.php#L68-L72
PingPlusPlus/pingpp-php
lib/Order.php
Order.pay
public static function pay($order_id, $params = null, $opts = null) { $url = static::instanceUrlWithId($order_id) . '/pay'; return static::_directRequest('post', $url, $params, $opts); }
php
public static function pay($order_id, $params = null, $opts = null) { $url = static::instanceUrlWithId($order_id) . '/pay'; return static::_directRequest('post', $url, $params, $opts); }
[ "public", "static", "function", "pay", "(", "$", "order_id", ",", "$", "params", "=", "null", ",", "$", "opts", "=", "null", ")", "{", "$", "url", "=", "static", "::", "instanceUrlWithId", "(", "$", "order_id", ")", ".", "'/pay'", ";", "return", "static", "::", "_directRequest", "(", "'post'", ",", "$", "url", ",", "$", "params", ",", "$", "opts", ")", ";", "}" ]
@param array|null $params @param array|string|null $opts @return Order
[ "@param", "array|null", "$params", "@param", "array|string|null", "$opts" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/Order.php#L57-L61
PingPlusPlus/pingpp-php
lib/Order.php
Order.cancel
public static function cancel($order_id, $params = null, $opts = null) { $url = static::instanceUrlWithId($order_id); if (empty($params)) { $params = ['status' => 'canceled']; } else { $params = array_merge($params, ['status' => 'canceled']); } return static::_directRequest('put', $url, $params, $opts); }
php
public static function cancel($order_id, $params = null, $opts = null) { $url = static::instanceUrlWithId($order_id); if (empty($params)) { $params = ['status' => 'canceled']; } else { $params = array_merge($params, ['status' => 'canceled']); } return static::_directRequest('put', $url, $params, $opts); }
[ "public", "static", "function", "cancel", "(", "$", "order_id", ",", "$", "params", "=", "null", ",", "$", "opts", "=", "null", ")", "{", "$", "url", "=", "static", "::", "instanceUrlWithId", "(", "$", "order_id", ")", ";", "if", "(", "empty", "(", "$", "params", ")", ")", "{", "$", "params", "=", "[", "'status'", "=>", "'canceled'", "]", ";", "}", "else", "{", "$", "params", "=", "array_merge", "(", "$", "params", ",", "[", "'status'", "=>", "'canceled'", "]", ")", ";", "}", "return", "static", "::", "_directRequest", "(", "'put'", ",", "$", "url", ",", "$", "params", ",", "$", "opts", ")", ";", "}" ]
@param array|null $params @param array|string|null $opts @return Order the canceled order
[ "@param", "array|null", "$params", "@param", "array|string|null", "$opts" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/Order.php#L69-L78
PingPlusPlus/pingpp-php
lib/Coupon.php
Coupon.retrieve
public static function retrieve($userId, $id, $options = null) { return self::_userBasedRetrieve($userId, $id, $options); }
php
public static function retrieve($userId, $id, $options = null) { return self::_userBasedRetrieve($userId, $id, $options); }
[ "public", "static", "function", "retrieve", "(", "$", "userId", ",", "$", "id", ",", "$", "options", "=", "null", ")", "{", "return", "self", "::", "_userBasedRetrieve", "(", "$", "userId", ",", "$", "id", ",", "$", "options", ")", ";", "}" ]
@param string $id The ID of the coupon to retrieve. @param array|string|null $options @return Coupon
[ "@param", "string", "$id", "The", "ID", "of", "the", "coupon", "to", "retrieve", ".", "@param", "array|string|null", "$options" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/Coupon.php#L13-L16
PingPlusPlus/pingpp-php
lib/Coupon.php
Coupon.create
public static function create($userId, $params = null, $options = null) { return self::_userBasedCreate($userId, $params, $options); }
php
public static function create($userId, $params = null, $options = null) { return self::_userBasedCreate($userId, $params, $options); }
[ "public", "static", "function", "create", "(", "$", "userId", ",", "$", "params", "=", "null", ",", "$", "options", "=", "null", ")", "{", "return", "self", "::", "_userBasedCreate", "(", "$", "userId", ",", "$", "params", ",", "$", "options", ")", ";", "}" ]
@param string $userId @param array|null $params @param array|string|null $options @return Coupon The created coupon.
[ "@param", "string", "$userId", "@param", "array|null", "$params", "@param", "array|string|null", "$options" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/Coupon.php#L25-L28
PingPlusPlus/pingpp-php
lib/Coupon.php
Coupon.update
public static function update($userId, $id, $params = null, $options = null) { return self::_userBasedUpdate($userId, $id, $params, $options); }
php
public static function update($userId, $id, $params = null, $options = null) { return self::_userBasedUpdate($userId, $id, $params, $options); }
[ "public", "static", "function", "update", "(", "$", "userId", ",", "$", "id", ",", "$", "params", "=", "null", ",", "$", "options", "=", "null", ")", "{", "return", "self", "::", "_userBasedUpdate", "(", "$", "userId", ",", "$", "id", ",", "$", "params", ",", "$", "options", ")", ";", "}" ]
@param string $userId @param string $id API resource ID @param array|null $params @param array|string|null $options @return Coupon The updated coupon.
[ "@param", "string", "$userId", "@param", "string", "$id", "API", "resource", "ID", "@param", "array|null", "$params", "@param", "array|string|null", "$options" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/Coupon.php#L38-L41
PingPlusPlus/pingpp-php
lib/Coupon.php
Coupon.all
public static function all($userId, $params = null, $options = null) { return self::_userBasedList($userId, $params, $options); }
php
public static function all($userId, $params = null, $options = null) { return self::_userBasedList($userId, $params, $options); }
[ "public", "static", "function", "all", "(", "$", "userId", ",", "$", "params", "=", "null", ",", "$", "options", "=", "null", ")", "{", "return", "self", "::", "_userBasedList", "(", "$", "userId", ",", "$", "params", ",", "$", "options", ")", ";", "}" ]
@param string $userId @param array|null $params @param array|string|null $options @return array An array of coupon.
[ "@param", "string", "$userId", "@param", "array|null", "$params", "@param", "array|string|null", "$options" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/Coupon.php#L50-L53
PingPlusPlus/pingpp-php
lib/SettleAccount.php
SettleAccount.create
public static function create($user_id, $params, $options = null) { $url = static::classUrlWithUserId($user_id); return static::_directRequest('post', $url, $params, $options); }
php
public static function create($user_id, $params, $options = null) { $url = static::classUrlWithUserId($user_id); return static::_directRequest('post', $url, $params, $options); }
[ "public", "static", "function", "create", "(", "$", "user_id", ",", "$", "params", ",", "$", "options", "=", "null", ")", "{", "$", "url", "=", "static", "::", "classUrlWithUserId", "(", "$", "user_id", ")", ";", "return", "static", "::", "_directRequest", "(", "'post'", ",", "$", "url", ",", "$", "params", ",", "$", "options", ")", ";", "}" ]
创建结算账户对象 @param $user_id @param $params @param $options @return SettleAccount
[ "创建结算账户对象" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/SettleAccount.php#L32-L36
PingPlusPlus/pingpp-php
lib/SettleAccount.php
SettleAccount.retrieve
public static function retrieve($user_id, $settle_account_id, $params = null, $options = null) { $url = static::instanceUrlWithSettleAccountId($user_id, $settle_account_id); return static::_directRequest('get', $url, $params, $options); }
php
public static function retrieve($user_id, $settle_account_id, $params = null, $options = null) { $url = static::instanceUrlWithSettleAccountId($user_id, $settle_account_id); return static::_directRequest('get', $url, $params, $options); }
[ "public", "static", "function", "retrieve", "(", "$", "user_id", ",", "$", "settle_account_id", ",", "$", "params", "=", "null", ",", "$", "options", "=", "null", ")", "{", "$", "url", "=", "static", "::", "instanceUrlWithSettleAccountId", "(", "$", "user_id", ",", "$", "settle_account_id", ")", ";", "return", "static", "::", "_directRequest", "(", "'get'", ",", "$", "url", ",", "$", "params", ",", "$", "options", ")", ";", "}" ]
查询结算账户对象 @param $user_id @param $settle_account_id @param null $params @return SettleAccount
[ "查询结算账户对象" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/SettleAccount.php#L45-L49
PingPlusPlus/pingpp-php
lib/SettleAccount.php
SettleAccount.all
public static function all($user_id, $params = null) { $url = static::classUrlWithUserId($user_id); return static::_directRequest('get', $url, $params); }
php
public static function all($user_id, $params = null) { $url = static::classUrlWithUserId($user_id); return static::_directRequest('get', $url, $params); }
[ "public", "static", "function", "all", "(", "$", "user_id", ",", "$", "params", "=", "null", ")", "{", "$", "url", "=", "static", "::", "classUrlWithUserId", "(", "$", "user_id", ")", ";", "return", "static", "::", "_directRequest", "(", "'get'", ",", "$", "url", ",", "$", "params", ")", ";", "}" ]
查询结算账户对象列表 @param $user_id @param null $params @return SettleAccount
[ "查询结算账户对象列表" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/SettleAccount.php#L70-L74
PingPlusPlus/pingpp-php
lib/Channel.php
Channel.create
public static function create($sub_app_id, $params, $options = null) { $url = static::classUrlWithSubAppId($sub_app_id); return static::_directRequest('post', $url, $params, $options); }
php
public static function create($sub_app_id, $params, $options = null) { $url = static::classUrlWithSubAppId($sub_app_id); return static::_directRequest('post', $url, $params, $options); }
[ "public", "static", "function", "create", "(", "$", "sub_app_id", ",", "$", "params", ",", "$", "options", "=", "null", ")", "{", "$", "url", "=", "static", "::", "classUrlWithSubAppId", "(", "$", "sub_app_id", ")", ";", "return", "static", "::", "_directRequest", "(", "'post'", ",", "$", "url", ",", "$", "params", ",", "$", "options", ")", ";", "}" ]
创建子商户应用支付渠道 @param $sub_app_id @param $params @param $options @return array|PingppObject
[ "创建子商户应用支付渠道" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/Channel.php#L32-L36
PingPlusPlus/pingpp-php
lib/Channel.php
Channel.retrieve
public static function retrieve($sub_app_id, $channel, $options = null) { $url = static::instanceUrlWithChannel($sub_app_id, $channel); return static::_directRequest('get', $url, array(), $options); }
php
public static function retrieve($sub_app_id, $channel, $options = null) { $url = static::instanceUrlWithChannel($sub_app_id, $channel); return static::_directRequest('get', $url, array(), $options); }
[ "public", "static", "function", "retrieve", "(", "$", "sub_app_id", ",", "$", "channel", ",", "$", "options", "=", "null", ")", "{", "$", "url", "=", "static", "::", "instanceUrlWithChannel", "(", "$", "sub_app_id", ",", "$", "channel", ")", ";", "return", "static", "::", "_directRequest", "(", "'get'", ",", "$", "url", ",", "array", "(", ")", ",", "$", "options", ")", ";", "}" ]
查询子商户应用支付渠道 @param $sub_app_id @param $channel @param $options @return array|PingppObject
[ "查询子商户应用支付渠道" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/Channel.php#L45-L49
PingPlusPlus/pingpp-php
lib/Channel.php
Channel.update
public static function update($sub_app_id, $channel, $params = null, $options = null) { $url = static::instanceUrlWithChannel($sub_app_id, $channel); return static::_directRequest('put', $url, $params, $options); }
php
public static function update($sub_app_id, $channel, $params = null, $options = null) { $url = static::instanceUrlWithChannel($sub_app_id, $channel); return static::_directRequest('put', $url, $params, $options); }
[ "public", "static", "function", "update", "(", "$", "sub_app_id", ",", "$", "channel", ",", "$", "params", "=", "null", ",", "$", "options", "=", "null", ")", "{", "$", "url", "=", "static", "::", "instanceUrlWithChannel", "(", "$", "sub_app_id", ",", "$", "channel", ")", ";", "return", "static", "::", "_directRequest", "(", "'put'", ",", "$", "url", ",", "$", "params", ",", "$", "options", ")", ";", "}" ]
更新子商户应用支付渠道 @param $sub_app_id @param $channel @param null $params @param $options @return array|PingppObject
[ "更新子商户应用支付渠道" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/Channel.php#L59-L63
PingPlusPlus/pingpp-php
lib/CouponTemplate.php
CouponTemplate.batchCreateCoupons
public static function batchCreateCoupons($id, $params = null, $options = null) { $url = static::classUrl() . '/' . $id . '/coupons'; return static::_directRequest('post', $url, $params, $options); }
php
public static function batchCreateCoupons($id, $params = null, $options = null) { $url = static::classUrl() . '/' . $id . '/coupons'; return static::_directRequest('post', $url, $params, $options); }
[ "public", "static", "function", "batchCreateCoupons", "(", "$", "id", ",", "$", "params", "=", "null", ",", "$", "options", "=", "null", ")", "{", "$", "url", "=", "static", "::", "classUrl", "(", ")", ".", "'/'", ".", "$", "id", ".", "'/coupons'", ";", "return", "static", "::", "_directRequest", "(", "'post'", ",", "$", "url", ",", "$", "params", ",", "$", "options", ")", ";", "}" ]
@param $id @param array|null $params @param array|string|null $options @return coupon
[ "@param", "$id", "@param", "array|null", "$params", "@param", "array|string|null", "$options" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/CouponTemplate.php#L63-L67
PingPlusPlus/pingpp-php
lib/CouponTemplate.php
CouponTemplate.couponsList
public static function couponsList($id, $params = null, $options = null) { $url = static::classUrl() . '/' . $id . '/coupons'; return static::_directRequest('get', $url, $params, $options); }
php
public static function couponsList($id, $params = null, $options = null) { $url = static::classUrl() . '/' . $id . '/coupons'; return static::_directRequest('get', $url, $params, $options); }
[ "public", "static", "function", "couponsList", "(", "$", "id", ",", "$", "params", "=", "null", ",", "$", "options", "=", "null", ")", "{", "$", "url", "=", "static", "::", "classUrl", "(", ")", ".", "'/'", ".", "$", "id", ".", "'/coupons'", ";", "return", "static", "::", "_directRequest", "(", "'get'", ",", "$", "url", ",", "$", "params", ",", "$", "options", ")", ";", "}" ]
@param $id @param array|null $params @param array|string|null $options @return coupon
[ "@param", "$id", "@param", "array|null", "$params", "@param", "array|string|null", "$options" ]
train
https://github.com/PingPlusPlus/pingpp-php/blob/ce11a340abea605d76114f0d1587b54cf5ad85bf/lib/CouponTemplate.php#L76-L80
mailin-api/mailin-api-php
src/Sendinblue/Mailin.php
Mailin.campaign_recipients_export
public function campaign_recipients_export($data) { $id = $data['id']; unset($data['id']); return $this->post("campaign/".$id."/recipients", json_encode($data)); }
php
public function campaign_recipients_export($data) { $id = $data['id']; unset($data['id']); return $this->post("campaign/".$id."/recipients", json_encode($data)); }
[ "public", "function", "campaign_recipients_export", "(", "$", "data", ")", "{", "$", "id", "=", "$", "data", "[", "'id'", "]", ";", "unset", "(", "$", "data", "[", "'id'", "]", ")", ";", "return", "$", "this", "->", "post", "(", "\"campaign/\"", ".", "$", "id", ".", "\"/recipients\"", ",", "json_encode", "(", "$", "data", ")", ")", ";", "}" ]
/* Export the recipients of a specified campaign. @param {Array} data contains php array with key value pair. @options data {Integer} id: Id of campaign to export its recipients [Mandatory] @options data {String} notify_url: URL that will be called once the export process is finished [Mandatory] @options data {String} type: Type of recipients. Possible values – all, non_clicker, non_opener, clicker, opener, soft_bounces, hard_bounces & unsubscribes [Mandatory]
[ "/", "*", "Export", "the", "recipients", "of", "a", "specified", "campaign", "." ]
train
https://github.com/mailin-api/mailin-api-php/blob/a0a521a88ea41cee821f5d30215a1c19efe540df/src/Sendinblue/Mailin.php#L277-L282
mailin-api/mailin-api-php
src/Sendinblue/Mailin.php
Mailin.send_bat_email
public function send_bat_email($data) { $id = $data['id']; unset($data['id']); return $this->post("campaign/".$id."/test", json_encode($data)); }
php
public function send_bat_email($data) { $id = $data['id']; unset($data['id']); return $this->post("campaign/".$id."/test", json_encode($data)); }
[ "public", "function", "send_bat_email", "(", "$", "data", ")", "{", "$", "id", "=", "$", "data", "[", "'id'", "]", ";", "unset", "(", "$", "data", "[", "'id'", "]", ")", ";", "return", "$", "this", "->", "post", "(", "\"campaign/\"", ".", "$", "id", ".", "\"/test\"", ",", "json_encode", "(", "$", "data", ")", ")", ";", "}" ]
/* Send a Test Campaign. @param {Array} data contains php array with key value pair. @options data {Integer} id: Id of the campaign [Mandatory] @options data {Array} emails: Email address of recipient(s) existing in the one of the lists & should not be blacklisted. Example: "test@example.net". You can use commas to separate multiple recipients [Mandatory]
[ "/", "*", "Send", "a", "Test", "Campaign", "." ]
train
https://github.com/mailin-api/mailin-api-php/blob/a0a521a88ea41cee821f5d30215a1c19efe540df/src/Sendinblue/Mailin.php#L301-L306
mailin-api/mailin-api-php
src/Sendinblue/Mailin.php
Mailin.update_campaign_status
public function update_campaign_status($data) { $id = $data['id']; unset($data['id']); return $this->put("campaign/".$id."/updatecampstatus", json_encode($data)); }
php
public function update_campaign_status($data) { $id = $data['id']; unset($data['id']); return $this->put("campaign/".$id."/updatecampstatus", json_encode($data)); }
[ "public", "function", "update_campaign_status", "(", "$", "data", ")", "{", "$", "id", "=", "$", "data", "[", "'id'", "]", ";", "unset", "(", "$", "data", "[", "'id'", "]", ")", ";", "return", "$", "this", "->", "put", "(", "\"campaign/\"", ".", "$", "id", ".", "\"/updatecampstatus\"", ",", "json_encode", "(", "$", "data", ")", ")", ";", "}" ]
/* Update the Campaign status. @param {Array} data contains php array with key value pair. @options data {Integer} id: Id of campaign to update its status [Mandatory] @options data {String} status: Types of status. Possible values – suspended, archive, darchive, sent, queued, replicate and replicate_template ( case sensitive ) [Mandatory]
[ "/", "*", "Update", "the", "Campaign", "status", "." ]
train
https://github.com/mailin-api/mailin-api-php/blob/a0a521a88ea41cee821f5d30215a1c19efe540df/src/Sendinblue/Mailin.php#L314-L319
mailin-api/mailin-api-php
src/Sendinblue/Mailin.php
Mailin.update_folder
public function update_folder($data) { $id = $data['id']; unset($data['id']); return $this->put("folder/".$id, json_encode($data)); }
php
public function update_folder($data) { $id = $data['id']; unset($data['id']); return $this->put("folder/".$id, json_encode($data)); }
[ "public", "function", "update_folder", "(", "$", "data", ")", "{", "$", "id", "=", "$", "data", "[", "'id'", "]", ";", "unset", "(", "$", "data", "[", "'id'", "]", ")", ";", "return", "$", "this", "->", "put", "(", "\"folder/\"", ".", "$", "id", ",", "json_encode", "(", "$", "data", ")", ")", ";", "}" ]
/* Update an existing folder. @param {Array} data contains php array with key value pair. @options data {Integer} id: Id of folder to be modified [Mandatory] @options data {String} name: Desired name of the folder to be modified [Mandatory]
[ "/", "*", "Update", "an", "existing", "folder", "." ]
train
https://github.com/mailin-api/mailin-api-php/blob/a0a521a88ea41cee821f5d30215a1c19efe540df/src/Sendinblue/Mailin.php#L425-L430
mailin-api/mailin-api-php
src/Sendinblue/Mailin.php
Mailin.add_users_list
public function add_users_list($data) { $id = $data['id']; unset($data['id']); return $this->post("list/".$id."/users", json_encode($data)); }
php
public function add_users_list($data) { $id = $data['id']; unset($data['id']); return $this->post("list/".$id."/users", json_encode($data)); }
[ "public", "function", "add_users_list", "(", "$", "data", ")", "{", "$", "id", "=", "$", "data", "[", "'id'", "]", ";", "unset", "(", "$", "data", "[", "'id'", "]", ")", ";", "return", "$", "this", "->", "post", "(", "\"list/\"", ".", "$", "id", ".", "\"/users\"", ",", "json_encode", "(", "$", "data", ")", ")", ";", "}" ]
/* Add already existing users in the SendinBlue contacts to the list. @param {Array} data contains php array with key value pair. @options data {Integer} id: Id of list to link users in it [Mandatory] @options data {Array} users: Email address of the already existing user(s) in the SendinBlue contacts. Example: "test@example.net". You can use commas to separate multiple users [Mandatory]
[ "/", "*", "Add", "already", "existing", "users", "in", "the", "SendinBlue", "contacts", "to", "the", "list", "." ]
train
https://github.com/mailin-api/mailin-api-php/blob/a0a521a88ea41cee821f5d30215a1c19efe540df/src/Sendinblue/Mailin.php#L509-L514
mailin-api/mailin-api-php
src/Sendinblue/Mailin.php
Mailin.delete_users_list
public function delete_users_list($data) { $id = $data['id']; unset($data['id']); return $this->delete("list/".$id."/delusers", json_encode($data)); }
php
public function delete_users_list($data) { $id = $data['id']; unset($data['id']); return $this->delete("list/".$id."/delusers", json_encode($data)); }
[ "public", "function", "delete_users_list", "(", "$", "data", ")", "{", "$", "id", "=", "$", "data", "[", "'id'", "]", ";", "unset", "(", "$", "data", "[", "'id'", "]", ")", ";", "return", "$", "this", "->", "delete", "(", "\"list/\"", ".", "$", "id", ".", "\"/delusers\"", ",", "json_encode", "(", "$", "data", ")", ")", ";", "}" ]
/* Delete already existing users in the SendinBlue contacts from the list. @param {Array} data contains php array with key value pair. @options data {Integer} id: Id of list to unlink users from it [Mandatory] @options data {Array} users: Email address of the already existing user(s) in the SendinBlue contacts to be modified. Example: "test@example.net". You can use commas to separate multiple users [Mandatory]
[ "/", "*", "Delete", "already", "existing", "users", "in", "the", "SendinBlue", "contacts", "from", "the", "list", "." ]
train
https://github.com/mailin-api/mailin-api-php/blob/a0a521a88ea41cee821f5d30215a1c19efe540df/src/Sendinblue/Mailin.php#L522-L527
mailin-api/mailin-api-php
src/Sendinblue/Mailin.php
Mailin.update_webhook
public function update_webhook($data) { $id = $data['id']; unset($data['id']); return $this->put("webhook/".$id, json_encode($data)); }
php
public function update_webhook($data) { $id = $data['id']; unset($data['id']); return $this->put("webhook/".$id, json_encode($data)); }
[ "public", "function", "update_webhook", "(", "$", "data", ")", "{", "$", "id", "=", "$", "data", "[", "'id'", "]", ";", "unset", "(", "$", "data", "[", "'id'", "]", ")", ";", "return", "$", "this", "->", "put", "(", "\"webhook/\"", ".", "$", "id", ",", "json_encode", "(", "$", "data", ")", ")", ";", "}" ]
/* Update a webhook. @param {Array} data contains php array with key value pair. @options data {Integer} id: Id of webhook to be modified [Mandatory] @options data {String} url: URL that will be triggered by a webhook [Mandatory] @options data {String} description: Webook description [Optional] @options data {Array} events: Set of events. You can use commas to separate multiple events. Possible values for Transcational webhook – request, delivered, hard_bounce, soft_bounce, blocked, spam, invalid_email, deferred, click, & opened and Possible Values for Marketing webhook – spam, opened, click, hard_bounce, unsubscribe, soft_bounce & list_addition ( case sensitive ) [Mandatory]
[ "/", "*", "Update", "a", "webhook", "." ]
train
https://github.com/mailin-api/mailin-api-php/blob/a0a521a88ea41cee821f5d30215a1c19efe540df/src/Sendinblue/Mailin.php#L706-L711
mailin-api/mailin-api-php
src/Sendinblue/Mailin.php
Mailin.send_transactional_template
public function send_transactional_template($data) { $id = $data['id']; unset($data['id']); return $this->put("template/".$id, json_encode($data)); }
php
public function send_transactional_template($data) { $id = $data['id']; unset($data['id']); return $this->put("template/".$id, json_encode($data)); }
[ "public", "function", "send_transactional_template", "(", "$", "data", ")", "{", "$", "id", "=", "$", "data", "[", "'id'", "]", ";", "unset", "(", "$", "data", "[", "'id'", "]", ")", ";", "return", "$", "this", "->", "put", "(", "\"template/\"", ".", "$", "id", ",", "json_encode", "(", "$", "data", ")", ")", ";", "}" ]
/* Send templates created on SendinBlue, through SendinBlue SMTP (transactional mails). @param {Array} data contains php array with key value pair. @options data {Integer} id: Id of the template created on SendinBlue account [Mandatory] @options data {String} to: Email address of the recipient(s). You can use pipe ( | ) to separate multiple recipients. Example: "to-example@example.net|to2-example@example.net" [Mandatory] @options data {String} cc: Same as to but for Cc [Optional] @options data {String} bcc: Same as to but for Bcc [Optional] @options data {Array} attrv The name of attribute present in your SendinBlue account. It should be sent as an associative array. Example: array("NAME"=>"name"). You can use commas to separate multiple attributes [Optional] @options data {String} attachment_url: Provide the absolute url of the attachment. Url not allowed from local machine. File must be hosted somewhere [Optional] @options data {Array} attachment: To send attachment/s generated on the fly you have to pass your attachment/s filename & its base64 encoded chunk data as an associative array [Optional]
[ "/", "*", "Send", "templates", "created", "on", "SendinBlue", "through", "SendinBlue", "SMTP", "(", "transactional", "mails", ")", "." ]
train
https://github.com/mailin-api/mailin-api-php/blob/a0a521a88ea41cee821f5d30215a1c19efe540df/src/Sendinblue/Mailin.php#L832-L837
mailin-api/mailin-api-php
src/Sendinblue/Mailin.php
Mailin.update_sms_campaign
public function update_sms_campaign($data) { $id = $data['id']; unset($data['id']); return $this->put("sms/".$id, json_encode($data)); }
php
public function update_sms_campaign($data) { $id = $data['id']; unset($data['id']); return $this->put("sms/".$id, json_encode($data)); }
[ "public", "function", "update_sms_campaign", "(", "$", "data", ")", "{", "$", "id", "=", "$", "data", "[", "'id'", "]", ";", "unset", "(", "$", "data", "[", "'id'", "]", ")", ";", "return", "$", "this", "->", "put", "(", "\"sms/\"", ".", "$", "id", ",", "json_encode", "(", "$", "data", ")", ")", ";", "}" ]
/* Update your SMS campaigns. @param {Array} data contains php array with key value pair. @options data {Integer} id: Id of the SMS campaign [Mandatory] @options data {String} name: Name of the SMS campaign [Optional] @options data {String} sender: This allows you to customize the SMS sender. The number of characters is limited to 11 ( alphanumeric format ) [Optional] @options data {String} content: Content of the message. The maximum characters used per SMS is 160, if used more than that, it will be counted as more than one SMS [Optional] @options data {String} bat: Mobile number with the country code to send test SMS. The mobile number defined here should belong to one of your contacts in SendinBlue account and should not be blacklisted [Optional] @options data {Array} listid: hese are the list ids to which the SMS campaign is sent [Mandatory: if scheduled_date is not empty] @options data {Array} exclude_list: These are the list ids which will be excluded from the SMS campaign [Optional] @options data {String} scheduled_date: The day on which the SMS campaign is supposed to run [Optional] @options data {Integer} send_now: Flag to send campaign now. Possible values = 0 (default) & 1. send_now = 0 means campaign can’t be send now, & send_now = 1 means campaign ready to send now [Optional]
[ "/", "*", "Update", "your", "SMS", "campaigns", "." ]
train
https://github.com/mailin-api/mailin-api-php/blob/a0a521a88ea41cee821f5d30215a1c19efe540df/src/Sendinblue/Mailin.php#L927-L932
mailin-api/mailin-api-php
src/Sendinblue/Mailin.php
Mailin.send_bat_sms
public function send_bat_sms($data) { $id = $data['id']; unset($data['id']); return $this->get("sms/".$id, json_encode($data)); }
php
public function send_bat_sms($data) { $id = $data['id']; unset($data['id']); return $this->get("sms/".$id, json_encode($data)); }
[ "public", "function", "send_bat_sms", "(", "$", "data", ")", "{", "$", "id", "=", "$", "data", "[", "'id'", "]", ";", "unset", "(", "$", "data", "[", "'id'", "]", ")", ";", "return", "$", "this", "->", "get", "(", "\"sms/\"", ".", "$", "id", ",", "json_encode", "(", "$", "data", ")", ")", ";", "}" ]
/* Send a Test SMS. @param {Array} data contains php array with key value pair. @options data {Integer} id: Id of the SMS campaign [Mandatory] @options data {String} to: Mobile number with the country code to send test SMS. The mobile number defined here should belong to one of your contacts in SendinBlue account and should not be blacklisted [Mandatory]
[ "/", "*", "Send", "a", "Test", "SMS", "." ]
train
https://github.com/mailin-api/mailin-api-php/blob/a0a521a88ea41cee821f5d30215a1c19efe540df/src/Sendinblue/Mailin.php#L940-L945
mailin-api/mailin-api-php
V1.0/mailin.php
Mailin.do_request
private function do_request($resource,$method,$input) { $called_url = $this->base_url."/".$resource; $ch = curl_init($called_url); $c_date_time = date("r"); $md5_content = ""; if($input!="") { $md5_content = md5($input); } $content_type = "application/json"; $sign_string = $method."\n".$md5_content."\n".$content_type."\n".$c_date_time."\n".$called_url; $time_header = 'X-mailin-date:'.$c_date_time; $auth_header = 'Authorization:'.$this->access_key.":".base64_encode(hash_hmac('sha1' , utf8_encode($sign_string) ,$this->secret_key)); $content_header = "Content-Type:application/json"; if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { // Windows only over-ride curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); } curl_setopt($ch, CURLOPT_HTTPHEADER, array($time_header,$auth_header,$content_header)); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, $input); $data = curl_exec($ch); if(curl_errno($ch)) { echo 'Curl error: ' . curl_error($ch). '\n'; } curl_close($ch); return json_decode($data,true); }
php
private function do_request($resource,$method,$input) { $called_url = $this->base_url."/".$resource; $ch = curl_init($called_url); $c_date_time = date("r"); $md5_content = ""; if($input!="") { $md5_content = md5($input); } $content_type = "application/json"; $sign_string = $method."\n".$md5_content."\n".$content_type."\n".$c_date_time."\n".$called_url; $time_header = 'X-mailin-date:'.$c_date_time; $auth_header = 'Authorization:'.$this->access_key.":".base64_encode(hash_hmac('sha1' , utf8_encode($sign_string) ,$this->secret_key)); $content_header = "Content-Type:application/json"; if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { // Windows only over-ride curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); } curl_setopt($ch, CURLOPT_HTTPHEADER, array($time_header,$auth_header,$content_header)); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, $input); $data = curl_exec($ch); if(curl_errno($ch)) { echo 'Curl error: ' . curl_error($ch). '\n'; } curl_close($ch); return json_decode($data,true); }
[ "private", "function", "do_request", "(", "$", "resource", ",", "$", "method", ",", "$", "input", ")", "{", "$", "called_url", "=", "$", "this", "->", "base_url", ".", "\"/\"", ".", "$", "resource", ";", "$", "ch", "=", "curl_init", "(", "$", "called_url", ")", ";", "$", "c_date_time", "=", "date", "(", "\"r\"", ")", ";", "$", "md5_content", "=", "\"\"", ";", "if", "(", "$", "input", "!=", "\"\"", ")", "{", "$", "md5_content", "=", "md5", "(", "$", "input", ")", ";", "}", "$", "content_type", "=", "\"application/json\"", ";", "$", "sign_string", "=", "$", "method", ".", "\"\\n\"", ".", "$", "md5_content", ".", "\"\\n\"", ".", "$", "content_type", ".", "\"\\n\"", ".", "$", "c_date_time", ".", "\"\\n\"", ".", "$", "called_url", ";", "$", "time_header", "=", "'X-mailin-date:'", ".", "$", "c_date_time", ";", "$", "auth_header", "=", "'Authorization:'", ".", "$", "this", "->", "access_key", ".", "\":\"", ".", "base64_encode", "(", "hash_hmac", "(", "'sha1'", ",", "utf8_encode", "(", "$", "sign_string", ")", ",", "$", "this", "->", "secret_key", ")", ")", ";", "$", "content_header", "=", "\"Content-Type:application/json\"", ";", "if", "(", "strtoupper", "(", "substr", "(", "PHP_OS", ",", "0", ",", "3", ")", ")", "===", "'WIN'", ")", "{", "// Windows only over-ride", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_SSL_VERIFYPEER", ",", "false", ")", ";", "}", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_HTTPHEADER", ",", "array", "(", "$", "time_header", ",", "$", "auth_header", ",", "$", "content_header", ")", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_FOLLOWLOCATION", ",", "1", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_CUSTOMREQUEST", ",", "$", "method", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_RETURNTRANSFER", ",", "1", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_HEADER", ",", "0", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_POSTFIELDS", ",", "$", "input", ")", ";", "$", "data", "=", "curl_exec", "(", "$", "ch", ")", ";", "if", "(", "curl_errno", "(", "$", "ch", ")", ")", "{", "echo", "'Curl error: '", ".", "curl_error", "(", "$", "ch", ")", ".", "'\\n'", ";", "}", "curl_close", "(", "$", "ch", ")", ";", "return", "json_decode", "(", "$", "data", ",", "true", ")", ";", "}" ]
Do CURL request with authorization
[ "Do", "CURL", "request", "with", "authorization" ]
train
https://github.com/mailin-api/mailin-api-php/blob/a0a521a88ea41cee821f5d30215a1c19efe540df/V1.0/mailin.php#L24-L55
ellipsesynergie/api-response
src/Laravel/ResponseServiceProvider.php
ResponseServiceProvider.bootResponse
protected function bootResponse() { $manager = new Manager; // Custom serializer because DataArraySerializer doesn't provide the opportunity to change the resource key $manager->setSerializer($this->getSerializer()); // Are we going to try and include embedded data? $manager->parseIncludes(explode(',', $this->app['Illuminate\Http\Request']->get('include'))); // Return the Response object $response = new Response($manager); //Set the response instance properly $this->app->instance('EllipseSynergie\ApiResponse\Contracts\Response', $response); return $response; }
php
protected function bootResponse() { $manager = new Manager; // Custom serializer because DataArraySerializer doesn't provide the opportunity to change the resource key $manager->setSerializer($this->getSerializer()); // Are we going to try and include embedded data? $manager->parseIncludes(explode(',', $this->app['Illuminate\Http\Request']->get('include'))); // Return the Response object $response = new Response($manager); //Set the response instance properly $this->app->instance('EllipseSynergie\ApiResponse\Contracts\Response', $response); return $response; }
[ "protected", "function", "bootResponse", "(", ")", "{", "$", "manager", "=", "new", "Manager", ";", "// Custom serializer because DataArraySerializer doesn't provide the opportunity to change the resource key", "$", "manager", "->", "setSerializer", "(", "$", "this", "->", "getSerializer", "(", ")", ")", ";", "// Are we going to try and include embedded data?", "$", "manager", "->", "parseIncludes", "(", "explode", "(", "','", ",", "$", "this", "->", "app", "[", "'Illuminate\\Http\\Request'", "]", "->", "get", "(", "'include'", ")", ")", ")", ";", "// Return the Response object", "$", "response", "=", "new", "Response", "(", "$", "manager", ")", ";", "//Set the response instance properly", "$", "this", "->", "app", "->", "instance", "(", "'EllipseSynergie\\ApiResponse\\Contracts\\Response'", ",", "$", "response", ")", ";", "return", "$", "response", ";", "}" ]
Boot response @return Response
[ "Boot", "response" ]
train
https://github.com/ellipsesynergie/api-response/blob/a0a803a01b04becfb3c681a8eab8ab06edaa3529/src/Laravel/ResponseServiceProvider.php#L46-L63
ellipsesynergie/api-response
src/Serializer/Serializer.php
Serializer.collection
public function collection($resourceKey, array $data) { if (is_null($resourceKey)) $resourceKey = static::RESOURCE_KEY; return $resourceKey ? [$resourceKey => $data]: $data; }
php
public function collection($resourceKey, array $data) { if (is_null($resourceKey)) $resourceKey = static::RESOURCE_KEY; return $resourceKey ? [$resourceKey => $data]: $data; }
[ "public", "function", "collection", "(", "$", "resourceKey", ",", "array", "$", "data", ")", "{", "if", "(", "is_null", "(", "$", "resourceKey", ")", ")", "$", "resourceKey", "=", "static", "::", "RESOURCE_KEY", ";", "return", "$", "resourceKey", "?", "[", "$", "resourceKey", "=>", "$", "data", "]", ":", "$", "data", ";", "}" ]
Serialize a collection. @param string $resourceKey @param array $data @return array
[ "Serialize", "a", "collection", "." ]
train
https://github.com/ellipsesynergie/api-response/blob/a0a803a01b04becfb3c681a8eab8ab06edaa3529/src/Serializer/Serializer.php#L24-L28
ellipsesynergie/api-response
src/Serializer/Serializer.php
Serializer.item
public function item($resourceKey, array $data) { if (is_null($resourceKey)) $resourceKey = static::RESOURCE_KEY; return $resourceKey ? [$resourceKey => $data]: $data; }
php
public function item($resourceKey, array $data) { if (is_null($resourceKey)) $resourceKey = static::RESOURCE_KEY; return $resourceKey ? [$resourceKey => $data]: $data; }
[ "public", "function", "item", "(", "$", "resourceKey", ",", "array", "$", "data", ")", "{", "if", "(", "is_null", "(", "$", "resourceKey", ")", ")", "$", "resourceKey", "=", "static", "::", "RESOURCE_KEY", ";", "return", "$", "resourceKey", "?", "[", "$", "resourceKey", "=>", "$", "data", "]", ":", "$", "data", ";", "}" ]
Serialize an item. @param string $resourceKey @param array $data @return array
[ "Serialize", "an", "item", "." ]
train
https://github.com/ellipsesynergie/api-response/blob/a0a803a01b04becfb3c681a8eab8ab06edaa3529/src/Serializer/Serializer.php#L38-L42
ellipsesynergie/api-response
src/Laravel/Middleware/ParseInclude.php
ParseInclude.handle
public function handle(Request $request, Closure $next) { // Are we going to try and include embedded data? $this->response->getManager()->parseIncludes(explode(',', $request->get('include'))); return $next($request); }
php
public function handle(Request $request, Closure $next) { // Are we going to try and include embedded data? $this->response->getManager()->parseIncludes(explode(',', $request->get('include'))); return $next($request); }
[ "public", "function", "handle", "(", "Request", "$", "request", ",", "Closure", "$", "next", ")", "{", "// Are we going to try and include embedded data?", "$", "this", "->", "response", "->", "getManager", "(", ")", "->", "parseIncludes", "(", "explode", "(", "','", ",", "$", "request", "->", "get", "(", "'include'", ")", ")", ")", ";", "return", "$", "next", "(", "$", "request", ")", ";", "}" ]
Handle middleware @param Request $request @param Closure $next @return mixed
[ "Handle", "middleware" ]
train
https://github.com/ellipsesynergie/api-response/blob/a0a803a01b04becfb3c681a8eab8ab06edaa3529/src/Laravel/Middleware/ParseInclude.php#L36-L42
ellipsesynergie/api-response
src/Laravel/LumenServiceProvider.php
LumenServiceProvider.boot
public function boot() { $manager = new Manager; // If you have to customize the manager instance, like setting a custom serializer, // I strongly suggest you to create your own service provider and add you manager configuration action here // Here some example if you want to set a custom serializer : // $manager->setSerializer(\League\Fractal\Serializer\JsonApiSerializer); // Are we going to try and include embedded data? $manager->parseIncludes(explode(',', $this->app['Illuminate\Http\Request']->get('include'))); //Set the response instance properly $this->app->instance('EllipseSynergie\ApiResponse\Contracts\Response', new Response($manager)); }
php
public function boot() { $manager = new Manager; // If you have to customize the manager instance, like setting a custom serializer, // I strongly suggest you to create your own service provider and add you manager configuration action here // Here some example if you want to set a custom serializer : // $manager->setSerializer(\League\Fractal\Serializer\JsonApiSerializer); // Are we going to try and include embedded data? $manager->parseIncludes(explode(',', $this->app['Illuminate\Http\Request']->get('include'))); //Set the response instance properly $this->app->instance('EllipseSynergie\ApiResponse\Contracts\Response', new Response($manager)); }
[ "public", "function", "boot", "(", ")", "{", "$", "manager", "=", "new", "Manager", ";", "// If you have to customize the manager instance, like setting a custom serializer,", "// I strongly suggest you to create your own service provider and add you manager configuration action here", "// Here some example if you want to set a custom serializer :", "// $manager->setSerializer(\\League\\Fractal\\Serializer\\JsonApiSerializer);", "// Are we going to try and include embedded data?", "$", "manager", "->", "parseIncludes", "(", "explode", "(", "','", ",", "$", "this", "->", "app", "[", "'Illuminate\\Http\\Request'", "]", "->", "get", "(", "'include'", ")", ")", ")", ";", "//Set the response instance properly", "$", "this", "->", "app", "->", "instance", "(", "'EllipseSynergie\\ApiResponse\\Contracts\\Response'", ",", "new", "Response", "(", "$", "manager", ")", ")", ";", "}" ]
Register the service provider. @return void
[ "Register", "the", "service", "provider", "." ]
train
https://github.com/ellipsesynergie/api-response/blob/a0a803a01b04becfb3c681a8eab8ab06edaa3529/src/Laravel/LumenServiceProvider.php#L24-L38
ellipsesynergie/api-response
src/AbstractResponse.php
AbstractResponse.withItem
public function withItem($data, $transformer, $resourceKey = null, $meta = [], array $headers = []) { $resource = new Item($data, $transformer, $resourceKey); foreach ($meta as $metaKey => $metaValue) { $resource->setMetaValue($metaKey, $metaValue); } $rootScope = $this->manager->createData($resource); return $this->withArray($rootScope->toArray(), $headers); }
php
public function withItem($data, $transformer, $resourceKey = null, $meta = [], array $headers = []) { $resource = new Item($data, $transformer, $resourceKey); foreach ($meta as $metaKey => $metaValue) { $resource->setMetaValue($metaKey, $metaValue); } $rootScope = $this->manager->createData($resource); return $this->withArray($rootScope->toArray(), $headers); }
[ "public", "function", "withItem", "(", "$", "data", ",", "$", "transformer", ",", "$", "resourceKey", "=", "null", ",", "$", "meta", "=", "[", "]", ",", "array", "$", "headers", "=", "[", "]", ")", "{", "$", "resource", "=", "new", "Item", "(", "$", "data", ",", "$", "transformer", ",", "$", "resourceKey", ")", ";", "foreach", "(", "$", "meta", "as", "$", "metaKey", "=>", "$", "metaValue", ")", "{", "$", "resource", "->", "setMetaValue", "(", "$", "metaKey", ",", "$", "metaValue", ")", ";", "}", "$", "rootScope", "=", "$", "this", "->", "manager", "->", "createData", "(", "$", "resource", ")", ";", "return", "$", "this", "->", "withArray", "(", "$", "rootScope", "->", "toArray", "(", ")", ",", "$", "headers", ")", ";", "}" ]
Response for one item @param $data @param callable|\League\Fractal\TransformerAbstract $transformer @param string $resourceKey @param array $meta @param array $headers @return mixed
[ "Response", "for", "one", "item" ]
train
https://github.com/ellipsesynergie/api-response/blob/a0a803a01b04becfb3c681a8eab8ab06edaa3529/src/AbstractResponse.php#L116-L127
ellipsesynergie/api-response
src/AbstractResponse.php
AbstractResponse.withCollection
public function withCollection($data, $transformer, $resourceKey = null, Cursor $cursor = null, $meta = [], array $headers = []) { $resource = new Collection($data, $transformer, $resourceKey); foreach ($meta as $metaKey => $metaValue) { $resource->setMetaValue($metaKey, $metaValue); } if (!is_null($cursor)) { $resource->setCursor($cursor); } $rootScope = $this->manager->createData($resource); return $this->withArray($rootScope->toArray(), $headers); }
php
public function withCollection($data, $transformer, $resourceKey = null, Cursor $cursor = null, $meta = [], array $headers = []) { $resource = new Collection($data, $transformer, $resourceKey); foreach ($meta as $metaKey => $metaValue) { $resource->setMetaValue($metaKey, $metaValue); } if (!is_null($cursor)) { $resource->setCursor($cursor); } $rootScope = $this->manager->createData($resource); return $this->withArray($rootScope->toArray(), $headers); }
[ "public", "function", "withCollection", "(", "$", "data", ",", "$", "transformer", ",", "$", "resourceKey", "=", "null", ",", "Cursor", "$", "cursor", "=", "null", ",", "$", "meta", "=", "[", "]", ",", "array", "$", "headers", "=", "[", "]", ")", "{", "$", "resource", "=", "new", "Collection", "(", "$", "data", ",", "$", "transformer", ",", "$", "resourceKey", ")", ";", "foreach", "(", "$", "meta", "as", "$", "metaKey", "=>", "$", "metaValue", ")", "{", "$", "resource", "->", "setMetaValue", "(", "$", "metaKey", ",", "$", "metaValue", ")", ";", "}", "if", "(", "!", "is_null", "(", "$", "cursor", ")", ")", "{", "$", "resource", "->", "setCursor", "(", "$", "cursor", ")", ";", "}", "$", "rootScope", "=", "$", "this", "->", "manager", "->", "createData", "(", "$", "resource", ")", ";", "return", "$", "this", "->", "withArray", "(", "$", "rootScope", "->", "toArray", "(", ")", ",", "$", "headers", ")", ";", "}" ]
Response for collection of items @param $data @param callable|\League\Fractal\TransformerAbstract $transformer @param string $resourceKey @param Cursor $cursor @param array $meta @param array $headers @return mixed
[ "Response", "for", "collection", "of", "items" ]
train
https://github.com/ellipsesynergie/api-response/blob/a0a803a01b04becfb3c681a8eab8ab06edaa3529/src/AbstractResponse.php#L140-L155
ellipsesynergie/api-response
src/AbstractResponse.php
AbstractResponse.withError
public function withError($message, $errorCode, array $headers = []) { return $this->withArray([ 'error' => [ 'code' => $errorCode, 'http_code' => $this->statusCode, 'message' => $message ] ], $headers ); }
php
public function withError($message, $errorCode, array $headers = []) { return $this->withArray([ 'error' => [ 'code' => $errorCode, 'http_code' => $this->statusCode, 'message' => $message ] ], $headers ); }
[ "public", "function", "withError", "(", "$", "message", ",", "$", "errorCode", ",", "array", "$", "headers", "=", "[", "]", ")", "{", "return", "$", "this", "->", "withArray", "(", "[", "'error'", "=>", "[", "'code'", "=>", "$", "errorCode", ",", "'http_code'", "=>", "$", "this", "->", "statusCode", ",", "'message'", "=>", "$", "message", "]", "]", ",", "$", "headers", ")", ";", "}" ]
Response for errors @param string $message @param string $errorCode @param array $headers @return mixed
[ "Response", "for", "errors" ]
train
https://github.com/ellipsesynergie/api-response/blob/a0a803a01b04becfb3c681a8eab8ab06edaa3529/src/AbstractResponse.php#L165-L176
ellipsesynergie/api-response
src/Laravel/Response.php
Response.withPaginator
public function withPaginator(LengthAwarePaginator $paginator, $transformer, $resourceKey = null, $meta = []) { $queryParams = array_diff_key($_GET, array_flip(['page'])); $paginator->appends($queryParams); $resource = new Collection($paginator->items(), $transformer, $resourceKey); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); foreach ($meta as $metaKey => $metaValue) { $resource->setMetaValue($metaKey, $metaValue); } $rootScope = $this->manager->createData($resource); return $this->withArray($rootScope->toArray()); }
php
public function withPaginator(LengthAwarePaginator $paginator, $transformer, $resourceKey = null, $meta = []) { $queryParams = array_diff_key($_GET, array_flip(['page'])); $paginator->appends($queryParams); $resource = new Collection($paginator->items(), $transformer, $resourceKey); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); foreach ($meta as $metaKey => $metaValue) { $resource->setMetaValue($metaKey, $metaValue); } $rootScope = $this->manager->createData($resource); return $this->withArray($rootScope->toArray()); }
[ "public", "function", "withPaginator", "(", "LengthAwarePaginator", "$", "paginator", ",", "$", "transformer", ",", "$", "resourceKey", "=", "null", ",", "$", "meta", "=", "[", "]", ")", "{", "$", "queryParams", "=", "array_diff_key", "(", "$", "_GET", ",", "array_flip", "(", "[", "'page'", "]", ")", ")", ";", "$", "paginator", "->", "appends", "(", "$", "queryParams", ")", ";", "$", "resource", "=", "new", "Collection", "(", "$", "paginator", "->", "items", "(", ")", ",", "$", "transformer", ",", "$", "resourceKey", ")", ";", "$", "resource", "->", "setPaginator", "(", "new", "IlluminatePaginatorAdapter", "(", "$", "paginator", ")", ")", ";", "foreach", "(", "$", "meta", "as", "$", "metaKey", "=>", "$", "metaValue", ")", "{", "$", "resource", "->", "setMetaValue", "(", "$", "metaKey", ",", "$", "metaValue", ")", ";", "}", "$", "rootScope", "=", "$", "this", "->", "manager", "->", "createData", "(", "$", "resource", ")", ";", "return", "$", "this", "->", "withArray", "(", "$", "rootScope", "->", "toArray", "(", ")", ")", ";", "}" ]
Respond with a paginator, and a transformer. @param LengthAwarePaginator $paginator @param callable|\League\Fractal\TransformerAbstract $transformer @param string $resourceKey @param array $meta @return ResponseFactory
[ "Respond", "with", "a", "paginator", "and", "a", "transformer", "." ]
train
https://github.com/ellipsesynergie/api-response/blob/a0a803a01b04becfb3c681a8eab8ab06edaa3529/src/Laravel/Response.php#L43-L58
optimizely/php-sdk
src/Optimizely/UserProfile/UserProfile.php
UserProfile.getVariationForExperiment
public function getVariationForExperiment($experimentId) { $decision = $this->getDecisionForExperiment($experimentId); if (!is_null($decision)) { return $decision->getVariationId(); } return null; }
php
public function getVariationForExperiment($experimentId) { $decision = $this->getDecisionForExperiment($experimentId); if (!is_null($decision)) { return $decision->getVariationId(); } return null; }
[ "public", "function", "getVariationForExperiment", "(", "$", "experimentId", ")", "{", "$", "decision", "=", "$", "this", "->", "getDecisionForExperiment", "(", "$", "experimentId", ")", ";", "if", "(", "!", "is_null", "(", "$", "decision", ")", ")", "{", "return", "$", "decision", "->", "getVariationId", "(", ")", ";", "}", "return", "null", ";", "}" ]
Get the variation ID for the given experiment from the experiment bucket map. @param $experimentId string The ID of the experiment. @return null|string The variation ID.
[ "Get", "the", "variation", "ID", "for", "the", "given", "experiment", "from", "the", "experiment", "bucket", "map", "." ]
train
https://github.com/optimizely/php-sdk/blob/6bc0c7b1372e22926f5d7c1a439fe334c1c6e1db/src/Optimizely/UserProfile/UserProfile.php#L67-L75
optimizely/php-sdk
src/Optimizely/UserProfile/UserProfile.php
UserProfile.getDecisionForExperiment
public function getDecisionForExperiment($experimentId) { if (isset($this->_experiment_bucket_map[$experimentId])) { return $this->_experiment_bucket_map[$experimentId]; } return null; }
php
public function getDecisionForExperiment($experimentId) { if (isset($this->_experiment_bucket_map[$experimentId])) { return $this->_experiment_bucket_map[$experimentId]; } return null; }
[ "public", "function", "getDecisionForExperiment", "(", "$", "experimentId", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_experiment_bucket_map", "[", "$", "experimentId", "]", ")", ")", "{", "return", "$", "this", "->", "_experiment_bucket_map", "[", "$", "experimentId", "]", ";", "}", "return", "null", ";", "}" ]
Get the decision for the given experiment from the experiment bucket map. @param $experimentId string The ID of the experiment. @return null|Decision The decision for the given experiment.
[ "Get", "the", "decision", "for", "the", "given", "experiment", "from", "the", "experiment", "bucket", "map", "." ]
train
https://github.com/optimizely/php-sdk/blob/6bc0c7b1372e22926f5d7c1a439fe334c1c6e1db/src/Optimizely/UserProfile/UserProfile.php#L84-L91
optimizely/php-sdk
src/Optimizely/Utils/Validator.php
Validator.validateJsonSchema
public static function validateJsonSchema($datafile, LoggerInterface $logger = null) { $data = json_decode($datafile); // Validate $validator = new JsonSchema\Validator; $validator->check($data, (object)['$ref' => 'file://' . __DIR__.'/schema.json']); if ($validator->isValid()) { return true; } else { if ($logger) { $logger->log(Logger::DEBUG, "JSON does not validate. Violations:\n"); ; foreach ($validator->getErrors() as $error) { $logger->log(Logger::DEBUG, "[%s] %s\n", $error['property'], $error['message']); } } return false; } }
php
public static function validateJsonSchema($datafile, LoggerInterface $logger = null) { $data = json_decode($datafile); // Validate $validator = new JsonSchema\Validator; $validator->check($data, (object)['$ref' => 'file://' . __DIR__.'/schema.json']); if ($validator->isValid()) { return true; } else { if ($logger) { $logger->log(Logger::DEBUG, "JSON does not validate. Violations:\n"); ; foreach ($validator->getErrors() as $error) { $logger->log(Logger::DEBUG, "[%s] %s\n", $error['property'], $error['message']); } } return false; } }
[ "public", "static", "function", "validateJsonSchema", "(", "$", "datafile", ",", "LoggerInterface", "$", "logger", "=", "null", ")", "{", "$", "data", "=", "json_decode", "(", "$", "datafile", ")", ";", "// Validate", "$", "validator", "=", "new", "JsonSchema", "\\", "Validator", ";", "$", "validator", "->", "check", "(", "$", "data", ",", "(", "object", ")", "[", "'$ref'", "=>", "'file://'", ".", "__DIR__", ".", "'/schema.json'", "]", ")", ";", "if", "(", "$", "validator", "->", "isValid", "(", ")", ")", "{", "return", "true", ";", "}", "else", "{", "if", "(", "$", "logger", ")", "{", "$", "logger", "->", "log", "(", "Logger", "::", "DEBUG", ",", "\"JSON does not validate. Violations:\\n\"", ")", ";", ";", "foreach", "(", "$", "validator", "->", "getErrors", "(", ")", "as", "$", "error", ")", "{", "$", "logger", "->", "log", "(", "Logger", "::", "DEBUG", ",", "\"[%s] %s\\n\"", ",", "$", "error", "[", "'property'", "]", ",", "$", "error", "[", "'message'", "]", ")", ";", "}", "}", "return", "false", ";", "}", "}" ]
@param $datafile string JSON string representing the project. @return boolean Representing whether schema is valid or not.
[ "@param", "$datafile", "string", "JSON", "string", "representing", "the", "project", "." ]
train
https://github.com/optimizely/php-sdk/blob/6bc0c7b1372e22926f5d7c1a439fe334c1c6e1db/src/Optimizely/Utils/Validator.php#L35-L56
optimizely/php-sdk
src/Optimizely/Utils/Validator.php
Validator.areAttributesValid
public static function areAttributesValid($attributes) { if (!is_array($attributes)) { return false; } if (empty($attributes)) { return true; } // At least one key string to be an associative array. return count(array_filter(array_keys($attributes), 'is_string')) > 0; }
php
public static function areAttributesValid($attributes) { if (!is_array($attributes)) { return false; } if (empty($attributes)) { return true; } // At least one key string to be an associative array. return count(array_filter(array_keys($attributes), 'is_string')) > 0; }
[ "public", "static", "function", "areAttributesValid", "(", "$", "attributes", ")", "{", "if", "(", "!", "is_array", "(", "$", "attributes", ")", ")", "{", "return", "false", ";", "}", "if", "(", "empty", "(", "$", "attributes", ")", ")", "{", "return", "true", ";", "}", "// At least one key string to be an associative array.", "return", "count", "(", "array_filter", "(", "array_keys", "(", "$", "attributes", ")", ",", "'is_string'", ")", ")", ">", "0", ";", "}" ]
@param $attributes mixed Attributes of the user. @return boolean Representing whether attributes are valid or not.
[ "@param", "$attributes", "mixed", "Attributes", "of", "the", "user", "." ]
train
https://github.com/optimizely/php-sdk/blob/6bc0c7b1372e22926f5d7c1a439fe334c1c6e1db/src/Optimizely/Utils/Validator.php#L63-L74
optimizely/php-sdk
src/Optimizely/Utils/Validator.php
Validator.isFiniteNumber
public static function isFiniteNumber($value) { if (!(is_int($value) || is_float($value))) { return false; } if (is_nan($value) || is_infinite($value)) { return false; } if (abs($value) > pow(2, 53)) { return false; } return true; }
php
public static function isFiniteNumber($value) { if (!(is_int($value) || is_float($value))) { return false; } if (is_nan($value) || is_infinite($value)) { return false; } if (abs($value) > pow(2, 53)) { return false; } return true; }
[ "public", "static", "function", "isFiniteNumber", "(", "$", "value", ")", "{", "if", "(", "!", "(", "is_int", "(", "$", "value", ")", "||", "is_float", "(", "$", "value", ")", ")", ")", "{", "return", "false", ";", "}", "if", "(", "is_nan", "(", "$", "value", ")", "||", "is_infinite", "(", "$", "value", ")", ")", "{", "return", "false", ";", "}", "if", "(", "abs", "(", "$", "value", ")", ">", "pow", "(", "2", ",", "53", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
@param $value The value to validate. @return boolean Representing whether attribute's value is a number and not NAN, INF, -INF or greater than absolute limit of 2^53.
[ "@param", "$value", "The", "value", "to", "validate", "." ]
train
https://github.com/optimizely/php-sdk/blob/6bc0c7b1372e22926f5d7c1a439fe334c1c6e1db/src/Optimizely/Utils/Validator.php#L82-L97
optimizely/php-sdk
src/Optimizely/Utils/Validator.php
Validator.isAttributeValid
public static function isAttributeValid($attributeKey, $attributeValue) { if (!is_string($attributeKey)) { return false; } if (is_string($attributeValue) || is_bool($attributeValue)) { return true; } if (is_int($attributeValue) || is_float($attributeValue)) { return Validator::isFiniteNumber($attributeValue); } return false; }
php
public static function isAttributeValid($attributeKey, $attributeValue) { if (!is_string($attributeKey)) { return false; } if (is_string($attributeValue) || is_bool($attributeValue)) { return true; } if (is_int($attributeValue) || is_float($attributeValue)) { return Validator::isFiniteNumber($attributeValue); } return false; }
[ "public", "static", "function", "isAttributeValid", "(", "$", "attributeKey", ",", "$", "attributeValue", ")", "{", "if", "(", "!", "is_string", "(", "$", "attributeKey", ")", ")", "{", "return", "false", ";", "}", "if", "(", "is_string", "(", "$", "attributeValue", ")", "||", "is_bool", "(", "$", "attributeValue", ")", ")", "{", "return", "true", ";", "}", "if", "(", "is_int", "(", "$", "attributeValue", ")", "||", "is_float", "(", "$", "attributeValue", ")", ")", "{", "return", "Validator", "::", "isFiniteNumber", "(", "$", "attributeValue", ")", ";", "}", "return", "false", ";", "}" ]
@param $attributeKey The key to validate. @param $attributeValue The value to validate. @return boolean Representing whether attribute's key and value are valid for event payload or not. Valid attribute key must be a string. Valid attribute value can be a string, bool, or a finite number.
[ "@param", "$attributeKey", "The", "key", "to", "validate", ".", "@param", "$attributeValue", "The", "value", "to", "validate", "." ]
train
https://github.com/optimizely/php-sdk/blob/6bc0c7b1372e22926f5d7c1a439fe334c1c6e1db/src/Optimizely/Utils/Validator.php#L107-L122
optimizely/php-sdk
src/Optimizely/Utils/Validator.php
Validator.isUserInExperiment
public static function isUserInExperiment($config, $experiment, $userAttributes, $logger) { $audienceConditions = $experiment->getAudienceConditions(); if ($audienceConditions === null) { $audienceConditions = $experiment->getAudienceIds(); } $logger->log(Logger::DEBUG, sprintf( AudienceEvaluationLogs::EVALUATING_AUDIENCES_COMBINED, $experiment->getKey(), json_encode($audienceConditions) )); // Return true if experiment is not targeted to any audience. if (empty($audienceConditions)) { $logger->log(Logger::INFO, sprintf( AudienceEvaluationLogs::AUDIENCE_EVALUATION_RESULT_COMBINED, $experiment->getKey(), 'TRUE' )); return true; } if ($userAttributes === null) { $userAttributes = []; } $customAttrCondEval = new CustomAttributeConditionEvaluator($userAttributes, $logger); $evaluateCustomAttr = function ($leafCondition) use ($customAttrCondEval) { return $customAttrCondEval->evaluate($leafCondition); }; $evaluateAudience = function ($audienceId) use ($config, $evaluateCustomAttr, $logger) { $audience = $config->getAudience($audienceId); if ($audience === null) { return null; } $logger->log(Logger::DEBUG, sprintf( AudienceEvaluationLogs::EVALUATING_AUDIENCE, $audienceId, json_encode($audience->getConditionsList()) )); $conditionTreeEvaluator = new ConditionTreeEvaluator(); $result = $conditionTreeEvaluator->evaluate($audience->getConditionsList(), $evaluateCustomAttr); $resultStr = $result === null ? 'UNKNOWN' : strtoupper(var_export($result, true)); $logger->log(Logger::INFO, sprintf( AudienceEvaluationLogs::AUDIENCE_EVALUATION_RESULT, $audienceId, $resultStr )); return $result; }; $conditionTreeEvaluator = new ConditionTreeEvaluator(); $evalResult = $conditionTreeEvaluator->evaluate($audienceConditions, $evaluateAudience); $evalResult = $evalResult || false; $logger->log(Logger::INFO, sprintf( AudienceEvaluationLogs::AUDIENCE_EVALUATION_RESULT_COMBINED, $experiment->getKey(), strtoupper(var_export($evalResult, true)) )); return $evalResult; }
php
public static function isUserInExperiment($config, $experiment, $userAttributes, $logger) { $audienceConditions = $experiment->getAudienceConditions(); if ($audienceConditions === null) { $audienceConditions = $experiment->getAudienceIds(); } $logger->log(Logger::DEBUG, sprintf( AudienceEvaluationLogs::EVALUATING_AUDIENCES_COMBINED, $experiment->getKey(), json_encode($audienceConditions) )); // Return true if experiment is not targeted to any audience. if (empty($audienceConditions)) { $logger->log(Logger::INFO, sprintf( AudienceEvaluationLogs::AUDIENCE_EVALUATION_RESULT_COMBINED, $experiment->getKey(), 'TRUE' )); return true; } if ($userAttributes === null) { $userAttributes = []; } $customAttrCondEval = new CustomAttributeConditionEvaluator($userAttributes, $logger); $evaluateCustomAttr = function ($leafCondition) use ($customAttrCondEval) { return $customAttrCondEval->evaluate($leafCondition); }; $evaluateAudience = function ($audienceId) use ($config, $evaluateCustomAttr, $logger) { $audience = $config->getAudience($audienceId); if ($audience === null) { return null; } $logger->log(Logger::DEBUG, sprintf( AudienceEvaluationLogs::EVALUATING_AUDIENCE, $audienceId, json_encode($audience->getConditionsList()) )); $conditionTreeEvaluator = new ConditionTreeEvaluator(); $result = $conditionTreeEvaluator->evaluate($audience->getConditionsList(), $evaluateCustomAttr); $resultStr = $result === null ? 'UNKNOWN' : strtoupper(var_export($result, true)); $logger->log(Logger::INFO, sprintf( AudienceEvaluationLogs::AUDIENCE_EVALUATION_RESULT, $audienceId, $resultStr )); return $result; }; $conditionTreeEvaluator = new ConditionTreeEvaluator(); $evalResult = $conditionTreeEvaluator->evaluate($audienceConditions, $evaluateAudience); $evalResult = $evalResult || false; $logger->log(Logger::INFO, sprintf( AudienceEvaluationLogs::AUDIENCE_EVALUATION_RESULT_COMBINED, $experiment->getKey(), strtoupper(var_export($evalResult, true)) )); return $evalResult; }
[ "public", "static", "function", "isUserInExperiment", "(", "$", "config", ",", "$", "experiment", ",", "$", "userAttributes", ",", "$", "logger", ")", "{", "$", "audienceConditions", "=", "$", "experiment", "->", "getAudienceConditions", "(", ")", ";", "if", "(", "$", "audienceConditions", "===", "null", ")", "{", "$", "audienceConditions", "=", "$", "experiment", "->", "getAudienceIds", "(", ")", ";", "}", "$", "logger", "->", "log", "(", "Logger", "::", "DEBUG", ",", "sprintf", "(", "AudienceEvaluationLogs", "::", "EVALUATING_AUDIENCES_COMBINED", ",", "$", "experiment", "->", "getKey", "(", ")", ",", "json_encode", "(", "$", "audienceConditions", ")", ")", ")", ";", "// Return true if experiment is not targeted to any audience.", "if", "(", "empty", "(", "$", "audienceConditions", ")", ")", "{", "$", "logger", "->", "log", "(", "Logger", "::", "INFO", ",", "sprintf", "(", "AudienceEvaluationLogs", "::", "AUDIENCE_EVALUATION_RESULT_COMBINED", ",", "$", "experiment", "->", "getKey", "(", ")", ",", "'TRUE'", ")", ")", ";", "return", "true", ";", "}", "if", "(", "$", "userAttributes", "===", "null", ")", "{", "$", "userAttributes", "=", "[", "]", ";", "}", "$", "customAttrCondEval", "=", "new", "CustomAttributeConditionEvaluator", "(", "$", "userAttributes", ",", "$", "logger", ")", ";", "$", "evaluateCustomAttr", "=", "function", "(", "$", "leafCondition", ")", "use", "(", "$", "customAttrCondEval", ")", "{", "return", "$", "customAttrCondEval", "->", "evaluate", "(", "$", "leafCondition", ")", ";", "}", ";", "$", "evaluateAudience", "=", "function", "(", "$", "audienceId", ")", "use", "(", "$", "config", ",", "$", "evaluateCustomAttr", ",", "$", "logger", ")", "{", "$", "audience", "=", "$", "config", "->", "getAudience", "(", "$", "audienceId", ")", ";", "if", "(", "$", "audience", "===", "null", ")", "{", "return", "null", ";", "}", "$", "logger", "->", "log", "(", "Logger", "::", "DEBUG", ",", "sprintf", "(", "AudienceEvaluationLogs", "::", "EVALUATING_AUDIENCE", ",", "$", "audienceId", ",", "json_encode", "(", "$", "audience", "->", "getConditionsList", "(", ")", ")", ")", ")", ";", "$", "conditionTreeEvaluator", "=", "new", "ConditionTreeEvaluator", "(", ")", ";", "$", "result", "=", "$", "conditionTreeEvaluator", "->", "evaluate", "(", "$", "audience", "->", "getConditionsList", "(", ")", ",", "$", "evaluateCustomAttr", ")", ";", "$", "resultStr", "=", "$", "result", "===", "null", "?", "'UNKNOWN'", ":", "strtoupper", "(", "var_export", "(", "$", "result", ",", "true", ")", ")", ";", "$", "logger", "->", "log", "(", "Logger", "::", "INFO", ",", "sprintf", "(", "AudienceEvaluationLogs", "::", "AUDIENCE_EVALUATION_RESULT", ",", "$", "audienceId", ",", "$", "resultStr", ")", ")", ";", "return", "$", "result", ";", "}", ";", "$", "conditionTreeEvaluator", "=", "new", "ConditionTreeEvaluator", "(", ")", ";", "$", "evalResult", "=", "$", "conditionTreeEvaluator", "->", "evaluate", "(", "$", "audienceConditions", ",", "$", "evaluateAudience", ")", ";", "$", "evalResult", "=", "$", "evalResult", "||", "false", ";", "$", "logger", "->", "log", "(", "Logger", "::", "INFO", ",", "sprintf", "(", "AudienceEvaluationLogs", "::", "AUDIENCE_EVALUATION_RESULT_COMBINED", ",", "$", "experiment", "->", "getKey", "(", ")", ",", "strtoupper", "(", "var_export", "(", "$", "evalResult", ",", "true", ")", ")", ")", ")", ";", "return", "$", "evalResult", ";", "}" ]
@param $config ProjectConfig Configuration for the project. @param $experiment Experiment Entity representing the experiment. @param $userAttributes array Attributes of the user. @param $logger LoggerInterface. @return boolean Representing whether user meets audience conditions to be in experiment or not.
[ "@param", "$config", "ProjectConfig", "Configuration", "for", "the", "project", ".", "@param", "$experiment", "Experiment", "Entity", "representing", "the", "experiment", ".", "@param", "$userAttributes", "array", "Attributes", "of", "the", "user", ".", "@param", "$logger", "LoggerInterface", "." ]
train
https://github.com/optimizely/php-sdk/blob/6bc0c7b1372e22926f5d7c1a439fe334c1c6e1db/src/Optimizely/Utils/Validator.php#L142-L210
optimizely/php-sdk
src/Optimizely/Utils/Validator.php
Validator.isFeatureFlagValid
public static function isFeatureFlagValid($config, $featureFlag) { $experimentIds = $featureFlag->getExperimentIds(); if (empty($experimentIds)) { return true; } if (sizeof($experimentIds) == 1) { return true; } $groupId = $config->getExperimentFromId($experimentIds[0])->getGroupId(); foreach ($experimentIds as $id) { $experiment = $config->getExperimentFromId($id); $grpId = $experiment->getGroupId(); if ($groupId != $grpId) { return false; } } return true; }
php
public static function isFeatureFlagValid($config, $featureFlag) { $experimentIds = $featureFlag->getExperimentIds(); if (empty($experimentIds)) { return true; } if (sizeof($experimentIds) == 1) { return true; } $groupId = $config->getExperimentFromId($experimentIds[0])->getGroupId(); foreach ($experimentIds as $id) { $experiment = $config->getExperimentFromId($id); $grpId = $experiment->getGroupId(); if ($groupId != $grpId) { return false; } } return true; }
[ "public", "static", "function", "isFeatureFlagValid", "(", "$", "config", ",", "$", "featureFlag", ")", "{", "$", "experimentIds", "=", "$", "featureFlag", "->", "getExperimentIds", "(", ")", ";", "if", "(", "empty", "(", "$", "experimentIds", ")", ")", "{", "return", "true", ";", "}", "if", "(", "sizeof", "(", "$", "experimentIds", ")", "==", "1", ")", "{", "return", "true", ";", "}", "$", "groupId", "=", "$", "config", "->", "getExperimentFromId", "(", "$", "experimentIds", "[", "0", "]", ")", "->", "getGroupId", "(", ")", ";", "foreach", "(", "$", "experimentIds", "as", "$", "id", ")", "{", "$", "experiment", "=", "$", "config", "->", "getExperimentFromId", "(", "$", "id", ")", ";", "$", "grpId", "=", "$", "experiment", "->", "getGroupId", "(", ")", ";", "if", "(", "$", "groupId", "!=", "$", "grpId", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Checks that if there are more than one experiment IDs in the feature flag, they must belong to the same mutex group @param ProjectConfig $config The project config to verify against @param FeatureFlag $featureFlag The feature to validate @return boolean True if feature flag is valid
[ "Checks", "that", "if", "there", "are", "more", "than", "one", "experiment", "IDs", "in", "the", "feature", "flag", "they", "must", "belong", "to", "the", "same", "mutex", "group" ]
train
https://github.com/optimizely/php-sdk/blob/6bc0c7b1372e22926f5d7c1a439fe334c1c6e1db/src/Optimizely/Utils/Validator.php#L221-L242
optimizely/php-sdk
src/Optimizely/Utils/Validator.php
Validator.areValuesSameType
public static function areValuesSameType($firstVal, $secondVal) { $firstValType = gettype($firstVal); $secondValType = gettype($secondVal); $numberTypes = array('double', 'integer'); if (in_array($firstValType, $numberTypes) && in_array($secondValType, $numberTypes)) { return true; } return $firstValType == $secondValType; }
php
public static function areValuesSameType($firstVal, $secondVal) { $firstValType = gettype($firstVal); $secondValType = gettype($secondVal); $numberTypes = array('double', 'integer'); if (in_array($firstValType, $numberTypes) && in_array($secondValType, $numberTypes)) { return true; } return $firstValType == $secondValType; }
[ "public", "static", "function", "areValuesSameType", "(", "$", "firstVal", ",", "$", "secondVal", ")", "{", "$", "firstValType", "=", "gettype", "(", "$", "firstVal", ")", ";", "$", "secondValType", "=", "gettype", "(", "$", "secondVal", ")", ";", "$", "numberTypes", "=", "array", "(", "'double'", ",", "'integer'", ")", ";", "if", "(", "in_array", "(", "$", "firstValType", ",", "$", "numberTypes", ")", "&&", "in_array", "(", "$", "secondValType", ",", "$", "numberTypes", ")", ")", "{", "return", "true", ";", "}", "return", "$", "firstValType", "==", "$", "secondValType", ";", "}" ]
Method to verify that both values belong to same type. Float/Double and Integer are considered similar. @param mixed $firstVal @param mixed $secondVal @return bool True if values belong to similar types. Otherwise, False.
[ "Method", "to", "verify", "that", "both", "values", "belong", "to", "same", "type", ".", "Float", "/", "Double", "and", "Integer", "are", "considered", "similar", "." ]
train
https://github.com/optimizely/php-sdk/blob/6bc0c7b1372e22926f5d7c1a439fe334c1c6e1db/src/Optimizely/Utils/Validator.php#L269-L280
optimizely/php-sdk
src/Optimizely/Utils/Validator.php
Validator.doesArrayContainOnlyStringKeys
public static function doesArrayContainOnlyStringKeys($arr) { if (!is_array($arr) || empty($arr)) { return false; } return count(array_filter(array_keys($arr), 'is_string')) == count(array_keys($arr)); }
php
public static function doesArrayContainOnlyStringKeys($arr) { if (!is_array($arr) || empty($arr)) { return false; } return count(array_filter(array_keys($arr), 'is_string')) == count(array_keys($arr)); }
[ "public", "static", "function", "doesArrayContainOnlyStringKeys", "(", "$", "arr", ")", "{", "if", "(", "!", "is_array", "(", "$", "arr", ")", "||", "empty", "(", "$", "arr", ")", ")", "{", "return", "false", ";", "}", "return", "count", "(", "array_filter", "(", "array_keys", "(", "$", "arr", ")", ",", "'is_string'", ")", ")", "==", "count", "(", "array_keys", "(", "$", "arr", ")", ")", ";", "}" ]
Returns true only if given input is an array with all of it's keys of type string. @param mixed $arr @return bool True if array contains all string keys. Otherwise, false.
[ "Returns", "true", "only", "if", "given", "input", "is", "an", "array", "with", "all", "of", "it", "s", "keys", "of", "type", "string", "." ]
train
https://github.com/optimizely/php-sdk/blob/6bc0c7b1372e22926f5d7c1a439fe334c1c6e1db/src/Optimizely/Utils/Validator.php#L287-L294
optimizely/php-sdk
src/Optimizely/ProjectConfig.php
ProjectConfig.getGroup
public function getGroup($groupId) { if (isset($this->_groupIdMap[$groupId])) { return $this->_groupIdMap[$groupId]; } $this->_logger->log(Logger::ERROR, sprintf('Group ID "%s" is not in datafile.', $groupId)); $this->_errorHandler->handleError(new InvalidGroupException('Provided group is not in datafile.')); return new Group(); }
php
public function getGroup($groupId) { if (isset($this->_groupIdMap[$groupId])) { return $this->_groupIdMap[$groupId]; } $this->_logger->log(Logger::ERROR, sprintf('Group ID "%s" is not in datafile.', $groupId)); $this->_errorHandler->handleError(new InvalidGroupException('Provided group is not in datafile.')); return new Group(); }
[ "public", "function", "getGroup", "(", "$", "groupId", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_groupIdMap", "[", "$", "groupId", "]", ")", ")", "{", "return", "$", "this", "->", "_groupIdMap", "[", "$", "groupId", "]", ";", "}", "$", "this", "->", "_logger", "->", "log", "(", "Logger", "::", "ERROR", ",", "sprintf", "(", "'Group ID \"%s\" is not in datafile.'", ",", "$", "groupId", ")", ")", ";", "$", "this", "->", "_errorHandler", "->", "handleError", "(", "new", "InvalidGroupException", "(", "'Provided group is not in datafile.'", ")", ")", ";", "return", "new", "Group", "(", ")", ";", "}" ]
@param $groupId string ID of the group. @return Group Entity corresponding to the ID. Dummy entity is returned if ID is invalid.
[ "@param", "$groupId", "string", "ID", "of", "the", "group", "." ]
train
https://github.com/optimizely/php-sdk/blob/6bc0c7b1372e22926f5d7c1a439fe334c1c6e1db/src/Optimizely/ProjectConfig.php#L372-L381
optimizely/php-sdk
src/Optimizely/ProjectConfig.php
ProjectConfig.getExperimentFromKey
public function getExperimentFromKey($experimentKey) { if (isset($this->_experimentKeyMap[$experimentKey])) { return $this->_experimentKeyMap[$experimentKey]; } $this->_logger->log(Logger::ERROR, sprintf('Experiment key "%s" is not in datafile.', $experimentKey)); $this->_errorHandler->handleError(new InvalidExperimentException('Provided experiment is not in datafile.')); return new Experiment(); }
php
public function getExperimentFromKey($experimentKey) { if (isset($this->_experimentKeyMap[$experimentKey])) { return $this->_experimentKeyMap[$experimentKey]; } $this->_logger->log(Logger::ERROR, sprintf('Experiment key "%s" is not in datafile.', $experimentKey)); $this->_errorHandler->handleError(new InvalidExperimentException('Provided experiment is not in datafile.')); return new Experiment(); }
[ "public", "function", "getExperimentFromKey", "(", "$", "experimentKey", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_experimentKeyMap", "[", "$", "experimentKey", "]", ")", ")", "{", "return", "$", "this", "->", "_experimentKeyMap", "[", "$", "experimentKey", "]", ";", "}", "$", "this", "->", "_logger", "->", "log", "(", "Logger", "::", "ERROR", ",", "sprintf", "(", "'Experiment key \"%s\" is not in datafile.'", ",", "$", "experimentKey", ")", ")", ";", "$", "this", "->", "_errorHandler", "->", "handleError", "(", "new", "InvalidExperimentException", "(", "'Provided experiment is not in datafile.'", ")", ")", ";", "return", "new", "Experiment", "(", ")", ";", "}" ]
@param $experimentKey string Key of the experiment. @return Experiment Entity corresponding to the key. Dummy entity is returned if key is invalid.
[ "@param", "$experimentKey", "string", "Key", "of", "the", "experiment", "." ]
train
https://github.com/optimizely/php-sdk/blob/6bc0c7b1372e22926f5d7c1a439fe334c1c6e1db/src/Optimizely/ProjectConfig.php#L389-L398
optimizely/php-sdk
src/Optimizely/ProjectConfig.php
ProjectConfig.getExperimentFromId
public function getExperimentFromId($experimentId) { if (isset($this->_experimentIdMap[$experimentId])) { return $this->_experimentIdMap[$experimentId]; } $this->_logger->log(Logger::ERROR, sprintf('Experiment ID "%s" is not in datafile.', $experimentId)); $this->_errorHandler->handleError(new InvalidExperimentException('Provided experiment is not in datafile.')); return new Experiment(); }
php
public function getExperimentFromId($experimentId) { if (isset($this->_experimentIdMap[$experimentId])) { return $this->_experimentIdMap[$experimentId]; } $this->_logger->log(Logger::ERROR, sprintf('Experiment ID "%s" is not in datafile.', $experimentId)); $this->_errorHandler->handleError(new InvalidExperimentException('Provided experiment is not in datafile.')); return new Experiment(); }
[ "public", "function", "getExperimentFromId", "(", "$", "experimentId", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_experimentIdMap", "[", "$", "experimentId", "]", ")", ")", "{", "return", "$", "this", "->", "_experimentIdMap", "[", "$", "experimentId", "]", ";", "}", "$", "this", "->", "_logger", "->", "log", "(", "Logger", "::", "ERROR", ",", "sprintf", "(", "'Experiment ID \"%s\" is not in datafile.'", ",", "$", "experimentId", ")", ")", ";", "$", "this", "->", "_errorHandler", "->", "handleError", "(", "new", "InvalidExperimentException", "(", "'Provided experiment is not in datafile.'", ")", ")", ";", "return", "new", "Experiment", "(", ")", ";", "}" ]
@param $experimentId string ID of the experiment. @return Experiment Entity corresponding to the key. Dummy entity is returned if ID is invalid.
[ "@param", "$experimentId", "string", "ID", "of", "the", "experiment", "." ]
train
https://github.com/optimizely/php-sdk/blob/6bc0c7b1372e22926f5d7c1a439fe334c1c6e1db/src/Optimizely/ProjectConfig.php#L406-L415
optimizely/php-sdk
src/Optimizely/ProjectConfig.php
ProjectConfig.getFeatureFlagFromKey
public function getFeatureFlagFromKey($featureKey) { if (isset($this->_featureKeyMap[$featureKey])) { return $this->_featureKeyMap[$featureKey]; } $this->_logger->log(Logger::ERROR, sprintf('FeatureFlag Key "%s" is not in datafile.', $featureKey)); $this->_errorHandler->handleError(new InvalidFeatureFlagException('Provided feature flag is not in datafile.')); return new FeatureFlag(); }
php
public function getFeatureFlagFromKey($featureKey) { if (isset($this->_featureKeyMap[$featureKey])) { return $this->_featureKeyMap[$featureKey]; } $this->_logger->log(Logger::ERROR, sprintf('FeatureFlag Key "%s" is not in datafile.', $featureKey)); $this->_errorHandler->handleError(new InvalidFeatureFlagException('Provided feature flag is not in datafile.')); return new FeatureFlag(); }
[ "public", "function", "getFeatureFlagFromKey", "(", "$", "featureKey", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_featureKeyMap", "[", "$", "featureKey", "]", ")", ")", "{", "return", "$", "this", "->", "_featureKeyMap", "[", "$", "featureKey", "]", ";", "}", "$", "this", "->", "_logger", "->", "log", "(", "Logger", "::", "ERROR", ",", "sprintf", "(", "'FeatureFlag Key \"%s\" is not in datafile.'", ",", "$", "featureKey", ")", ")", ";", "$", "this", "->", "_errorHandler", "->", "handleError", "(", "new", "InvalidFeatureFlagException", "(", "'Provided feature flag is not in datafile.'", ")", ")", ";", "return", "new", "FeatureFlag", "(", ")", ";", "}" ]
@param String $featureKey Key of the feature flag @return FeatureFlag Entity corresponding to the key.
[ "@param", "String", "$featureKey", "Key", "of", "the", "feature", "flag" ]
train
https://github.com/optimizely/php-sdk/blob/6bc0c7b1372e22926f5d7c1a439fe334c1c6e1db/src/Optimizely/ProjectConfig.php#L422-L431
optimizely/php-sdk
src/Optimizely/ProjectConfig.php
ProjectConfig.getRolloutFromId
public function getRolloutFromId($rolloutId) { if (isset($this->_rolloutIdMap[$rolloutId])) { return $this->_rolloutIdMap[$rolloutId]; } $this->_logger->log(Logger::ERROR, sprintf('Rollout with ID "%s" is not in the datafile.', $rolloutId)); $this->_errorHandler->handleError(new InvalidRolloutException('Provided rollout is not in datafile.')); return new Rollout(); }
php
public function getRolloutFromId($rolloutId) { if (isset($this->_rolloutIdMap[$rolloutId])) { return $this->_rolloutIdMap[$rolloutId]; } $this->_logger->log(Logger::ERROR, sprintf('Rollout with ID "%s" is not in the datafile.', $rolloutId)); $this->_errorHandler->handleError(new InvalidRolloutException('Provided rollout is not in datafile.')); return new Rollout(); }
[ "public", "function", "getRolloutFromId", "(", "$", "rolloutId", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_rolloutIdMap", "[", "$", "rolloutId", "]", ")", ")", "{", "return", "$", "this", "->", "_rolloutIdMap", "[", "$", "rolloutId", "]", ";", "}", "$", "this", "->", "_logger", "->", "log", "(", "Logger", "::", "ERROR", ",", "sprintf", "(", "'Rollout with ID \"%s\" is not in the datafile.'", ",", "$", "rolloutId", ")", ")", ";", "$", "this", "->", "_errorHandler", "->", "handleError", "(", "new", "InvalidRolloutException", "(", "'Provided rollout is not in datafile.'", ")", ")", ";", "return", "new", "Rollout", "(", ")", ";", "}" ]
@param String $rolloutId @return Rollout
[ "@param", "String", "$rolloutId" ]
train
https://github.com/optimizely/php-sdk/blob/6bc0c7b1372e22926f5d7c1a439fe334c1c6e1db/src/Optimizely/ProjectConfig.php#L438-L448
optimizely/php-sdk
src/Optimizely/ProjectConfig.php
ProjectConfig.getEvent
public function getEvent($eventKey) { if (isset($this->_eventKeyMap[$eventKey])) { return $this->_eventKeyMap[$eventKey]; } $this->_logger->log(Logger::ERROR, sprintf('Event key "%s" is not in datafile.', $eventKey)); $this->_errorHandler->handleError(new InvalidEventException('Provided event is not in datafile.')); return new Event(); }
php
public function getEvent($eventKey) { if (isset($this->_eventKeyMap[$eventKey])) { return $this->_eventKeyMap[$eventKey]; } $this->_logger->log(Logger::ERROR, sprintf('Event key "%s" is not in datafile.', $eventKey)); $this->_errorHandler->handleError(new InvalidEventException('Provided event is not in datafile.')); return new Event(); }
[ "public", "function", "getEvent", "(", "$", "eventKey", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_eventKeyMap", "[", "$", "eventKey", "]", ")", ")", "{", "return", "$", "this", "->", "_eventKeyMap", "[", "$", "eventKey", "]", ";", "}", "$", "this", "->", "_logger", "->", "log", "(", "Logger", "::", "ERROR", ",", "sprintf", "(", "'Event key \"%s\" is not in datafile.'", ",", "$", "eventKey", ")", ")", ";", "$", "this", "->", "_errorHandler", "->", "handleError", "(", "new", "InvalidEventException", "(", "'Provided event is not in datafile.'", ")", ")", ";", "return", "new", "Event", "(", ")", ";", "}" ]
@param $eventKey string Key of the event. @return Event Entity corresponding to the key. Dummy entity is returned if key is invalid.
[ "@param", "$eventKey", "string", "Key", "of", "the", "event", "." ]
train
https://github.com/optimizely/php-sdk/blob/6bc0c7b1372e22926f5d7c1a439fe334c1c6e1db/src/Optimizely/ProjectConfig.php#L456-L465