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
10up/wp-codeception
classes/WPCC/Component/Console/Input/ArgvInput.php
ArgvInput.filter_arguments
public function filter_arguments( $arg ) { $patterns = array( 'url=', 'path=', 'user=', 'skip-plugins=?', 'skip-themes=?', 'require=', 'no-color', 'color', 'prompt', 'allow-root', ); foreach ( $patterns as $pattern ) { if ( preg_match( "~^--{$pattern}~i", $arg ) ) { return false; } } return true; }
php
public function filter_arguments( $arg ) { $patterns = array( 'url=', 'path=', 'user=', 'skip-plugins=?', 'skip-themes=?', 'require=', 'no-color', 'color', 'prompt', 'allow-root', ); foreach ( $patterns as $pattern ) { if ( preg_match( "~^--{$pattern}~i", $arg ) ) { return false; } } return true; }
[ "public", "function", "filter_arguments", "(", "$", "arg", ")", "{", "$", "patterns", "=", "array", "(", "'url='", ",", "'path='", ",", "'user='", ",", "'skip-plugins=?'", ",", "'skip-themes=?'", ",", "'require='", ",", "'no-color'", ",", "'color'", ",", "'p...
Removes WP_CLI related arguments from input for Codeception commands to escape conflicts. @since 1.0.0 @access public @param string $arg The argument. @return boolean TRUE if argument has to be left in the input array, otherwise FALSE.
[ "Removes", "WP_CLI", "related", "arguments", "from", "input", "for", "Codeception", "commands", "to", "escape", "conflicts", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Component/Console/Input/ArgvInput.php#L66-L79
10up/wp-codeception
classes/WPCC/Component/Factory/Comment.php
Comment._createObject
protected function _createObject( $args ) { $comment_id = wp_insert_comment( $this->_addSlashesDeep( $args ) ); if ( $comment_id && ! is_wp_error( $comment_id ) ) { $this->_debug( 'Generated comment ID: ' . $comment_id ); } elseif ( is_wp_error( $comment_id ) ) { $this->_debug( 'Comment generation failed with message [%s] %s', $comment_id->get_error_code(), $comment_id->get_error_messages() ); } else { $this->_debug( 'Comment generation failed' ); } return $comment_id; }
php
protected function _createObject( $args ) { $comment_id = wp_insert_comment( $this->_addSlashesDeep( $args ) ); if ( $comment_id && ! is_wp_error( $comment_id ) ) { $this->_debug( 'Generated comment ID: ' . $comment_id ); } elseif ( is_wp_error( $comment_id ) ) { $this->_debug( 'Comment generation failed with message [%s] %s', $comment_id->get_error_code(), $comment_id->get_error_messages() ); } else { $this->_debug( 'Comment generation failed' ); } return $comment_id; }
[ "protected", "function", "_createObject", "(", "$", "args", ")", "{", "$", "comment_id", "=", "wp_insert_comment", "(", "$", "this", "->", "_addSlashesDeep", "(", "$", "args", ")", ")", ";", "if", "(", "$", "comment_id", "&&", "!", "is_wp_error", "(", "$...
Generates a new comment. @since 1.0.0 @access protected @param array $args The array of arguments to use during a new comment creation. @return int|boolean The newly created comment's ID on success, otherwise FALSE.
[ "Generates", "a", "new", "comment", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Component/Factory/Comment.php#L60-L75
10up/wp-codeception
classes/WPCC/Component/Factory/Comment.php
Comment._updateObject
protected function _updateObject( $comment_id, $fields ) { $fields['comment_ID'] = $comment_id; $updated = (bool) wp_update_comment( $this->_addSlashesDeep( $fields ) ); if ( $updated ) { $this->_debug( 'Updated comment ' . $comment_id ); } else { $this->_debug( 'Update failed for comment ' . $comment_id ); } return $updated; }
php
protected function _updateObject( $comment_id, $fields ) { $fields['comment_ID'] = $comment_id; $updated = (bool) wp_update_comment( $this->_addSlashesDeep( $fields ) ); if ( $updated ) { $this->_debug( 'Updated comment ' . $comment_id ); } else { $this->_debug( 'Update failed for comment ' . $comment_id ); } return $updated; }
[ "protected", "function", "_updateObject", "(", "$", "comment_id", ",", "$", "fields", ")", "{", "$", "fields", "[", "'comment_ID'", "]", "=", "$", "comment_id", ";", "$", "updated", "=", "(", "bool", ")", "wp_update_comment", "(", "$", "this", "->", "_ad...
Updates generated comment. @since 1.0.0 @access protected @param mixed $comment_id The comment id. @param array $fields The array of fields to update. @return boolean TRUE on success, otherwise FALSE.
[ "Updates", "generated", "comment", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Component/Factory/Comment.php#L87-L97
10up/wp-codeception
classes/WPCC/Component/Factory/Comment.php
Comment._deleteObject
protected function _deleteObject( $comment_id ) { $comment = get_comment( $comment_id ); if ( ! $comment || is_wp_error( $comment ) ) { return false; } $deleted = wp_delete_comment( $comment_id, true ); if ( $deleted ) { $this->_debug( 'Deleted comment with ID: ' . $comment_id ); return true; } $this->_debug( 'Comment removal failed for ID: ' . $comment_id ); return false; }
php
protected function _deleteObject( $comment_id ) { $comment = get_comment( $comment_id ); if ( ! $comment || is_wp_error( $comment ) ) { return false; } $deleted = wp_delete_comment( $comment_id, true ); if ( $deleted ) { $this->_debug( 'Deleted comment with ID: ' . $comment_id ); return true; } $this->_debug( 'Comment removal failed for ID: ' . $comment_id ); return false; }
[ "protected", "function", "_deleteObject", "(", "$", "comment_id", ")", "{", "$", "comment", "=", "get_comment", "(", "$", "comment_id", ")", ";", "if", "(", "!", "$", "comment", "||", "is_wp_error", "(", "$", "comment", ")", ")", "{", "return", "false", ...
Deletes previously generated comment. @since 1.0.0 @access protected @param int $comment_id The comment id. @return boolean TRUE on success, otherwise FALSE.
[ "Deletes", "previously", "generated", "comment", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Component/Factory/Comment.php#L108-L122
10up/wp-codeception
classes/WPCC/Component/Factory/Comment.php
Comment.createPostComments
public function createPostComments( $post_id, $count = 1, $args = array(), $definitions = null ) { $args['comment_post_ID'] = $post_id; return $this->createMany( $count, $args, $definitions ); }
php
public function createPostComments( $post_id, $count = 1, $args = array(), $definitions = null ) { $args['comment_post_ID'] = $post_id; return $this->createMany( $count, $args, $definitions ); }
[ "public", "function", "createPostComments", "(", "$", "post_id", ",", "$", "count", "=", "1", ",", "$", "args", "=", "array", "(", ")", ",", "$", "definitions", "=", "null", ")", "{", "$", "args", "[", "'comment_post_ID'", "]", "=", "$", "post_id", "...
Creates comments for a post. @since 1.0.0 @access public @param int $post_id The post id to create comments for. @param int $count The number of comments to create. @param array $args The array of arguments to use during a new object creation. @param array $definitions Custom difinitions of default values for a new object properties. @return array The array of generated comment ids.
[ "Creates", "comments", "for", "a", "post", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Component/Factory/Comment.php#L136-L139
10up/wp-codeception
classes/WPCC/Subscriber/AutoRebuild.php
AutoRebuild.updateGuy
public function updateGuy( SuiteEvent $e ) { $settings = $e->getSettings(); $guyFile = $settings['path'] . $settings['class_name'] . '.php'; // load guy class to see hash $handle = fopen( $guyFile, "r" ); if ( $handle ) { $line = fgets( $handle ); if ( preg_match( '~\[STAMP\] ([a-f0-9]*)~', $line, $matches ) ) { $hash = $matches[1]; $currentHash = Actor::genHash( SuiteManager::$actions, $settings ); // regenerate guy class when hashes do not match if ( $hash != $currentHash ) { codecept_debug( "Rebuilding {$settings['class_name']}..." ); $guyGenerator = new Actor( $settings ); fclose( $handle ); $generated = $guyGenerator->produce(); file_put_contents( $guyFile, $generated ); return; } } fclose( $handle ); } }
php
public function updateGuy( SuiteEvent $e ) { $settings = $e->getSettings(); $guyFile = $settings['path'] . $settings['class_name'] . '.php'; // load guy class to see hash $handle = fopen( $guyFile, "r" ); if ( $handle ) { $line = fgets( $handle ); if ( preg_match( '~\[STAMP\] ([a-f0-9]*)~', $line, $matches ) ) { $hash = $matches[1]; $currentHash = Actor::genHash( SuiteManager::$actions, $settings ); // regenerate guy class when hashes do not match if ( $hash != $currentHash ) { codecept_debug( "Rebuilding {$settings['class_name']}..." ); $guyGenerator = new Actor( $settings ); fclose( $handle ); $generated = $guyGenerator->produce(); file_put_contents( $guyFile, $generated ); return; } } fclose( $handle ); } }
[ "public", "function", "updateGuy", "(", "SuiteEvent", "$", "e", ")", "{", "$", "settings", "=", "$", "e", "->", "getSettings", "(", ")", ";", "$", "guyFile", "=", "$", "settings", "[", "'path'", "]", ".", "$", "settings", "[", "'class_name'", "]", "....
Updates test guy class. @since 1.0.0 @access public @param SuiteEvent $e Event object.
[ "Updates", "test", "guy", "class", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Subscriber/AutoRebuild.php#L44-L69
10up/wp-codeception
classes/WPCC/Command/Build.php
Build.buildActorsForConfig
protected function buildActorsForConfig( $configFile ) { $config = $this->getGlobalConfig( $configFile ); $suites = $this->getSuites( $configFile ); $path = pathinfo( $configFile ); $dir = isset( $path['dirname'] ) ? $path['dirname'] : getcwd(); foreach ( $config['include'] as $subConfig ) { $this->output->writeln( "<comment>Included Configuration: $subConfig</comment>" ); $this->buildActorsForConfig( $dir . DIRECTORY_SEPARATOR . $subConfig ); } if ( !empty( $suites ) ) { $this->output->writeln( "<info>Building Actor classes for suites: " . implode( ', ', $suites ) . '</info>' ); } foreach ( $suites as $suite ) { $settings = $this->getSuiteConfig( $suite, $configFile ); $gen = new ActorGenerator( $settings ); $this->output->writeln( '<info>' . Configuration::config()['namespace'] . '\\' . $gen->getActorName() . "</info> includes modules: " . implode( ', ', $gen->getModules() ) ); $contents = $gen->produce(); @mkdir( $settings['path'], 0755, true ); $file = $settings['path'] . $this->getClassName( $settings['class_name'] ) . '.php'; $this->save( $file, $contents, true ); $this->output->writeln( "{$settings['class_name']}.php generated successfully. " . $gen->getNumMethods() . " methods added" ); } }
php
protected function buildActorsForConfig( $configFile ) { $config = $this->getGlobalConfig( $configFile ); $suites = $this->getSuites( $configFile ); $path = pathinfo( $configFile ); $dir = isset( $path['dirname'] ) ? $path['dirname'] : getcwd(); foreach ( $config['include'] as $subConfig ) { $this->output->writeln( "<comment>Included Configuration: $subConfig</comment>" ); $this->buildActorsForConfig( $dir . DIRECTORY_SEPARATOR . $subConfig ); } if ( !empty( $suites ) ) { $this->output->writeln( "<info>Building Actor classes for suites: " . implode( ', ', $suites ) . '</info>' ); } foreach ( $suites as $suite ) { $settings = $this->getSuiteConfig( $suite, $configFile ); $gen = new ActorGenerator( $settings ); $this->output->writeln( '<info>' . Configuration::config()['namespace'] . '\\' . $gen->getActorName() . "</info> includes modules: " . implode( ', ', $gen->getModules() ) ); $contents = $gen->produce(); @mkdir( $settings['path'], 0755, true ); $file = $settings['path'] . $this->getClassName( $settings['class_name'] ) . '.php'; $this->save( $file, $contents, true ); $this->output->writeln( "{$settings['class_name']}.php generated successfully. " . $gen->getNumMethods() . " methods added" ); } }
[ "protected", "function", "buildActorsForConfig", "(", "$", "configFile", ")", "{", "$", "config", "=", "$", "this", "->", "getGlobalConfig", "(", "$", "configFile", ")", ";", "$", "suites", "=", "$", "this", "->", "getSuites", "(", "$", "configFile", ")", ...
Builds actors for suites. @since 1.0.0 @access protected @param string $configFile Alternative config file name.
[ "Builds", "actors", "for", "suites", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Command/Build.php#L44-L70
10up/wp-codeception
classes/WPCC/Codecept.php
Codecept.registerSubscribers
public function registerSubscribers() { // required $this->dispatcher->addSubscriber( new \Codeception\Subscriber\ErrorHandler() ); $this->dispatcher->addSubscriber( new \WPCC\Subscriber\Bootstrap() ); $this->dispatcher->addSubscriber( new \Codeception\Subscriber\Module() ); $this->dispatcher->addSubscriber( new \Codeception\Subscriber\BeforeAfterTest() ); $this->dispatcher->addSubscriber( new \WPCC\Subscriber\AutoRebuild() ); // optional if ( !$this->options['silent'] ) { $this->dispatcher->addSubscriber( new \Codeception\Subscriber\Console( $this->options ) ); } if ( $this->options['fail-fast'] ) { $this->dispatcher->addSubscriber( new \Codeception\Subscriber\FailFast() ); } if ( $this->options['coverage'] ) { $this->dispatcher->addSubscriber( new \Codeception\Coverage\Subscriber\Local( $this->options ) ); $this->dispatcher->addSubscriber( new \Codeception\Coverage\Subscriber\LocalServer( $this->options ) ); $this->dispatcher->addSubscriber( new \Codeception\Coverage\Subscriber\RemoteServer( $this->options ) ); $this->dispatcher->addSubscriber( new \Codeception\Coverage\Subscriber\Printer( $this->options ) ); } // extensions foreach ( $this->extensions as $subscriber ) { $this->dispatcher->addSubscriber( $subscriber ); } }
php
public function registerSubscribers() { // required $this->dispatcher->addSubscriber( new \Codeception\Subscriber\ErrorHandler() ); $this->dispatcher->addSubscriber( new \WPCC\Subscriber\Bootstrap() ); $this->dispatcher->addSubscriber( new \Codeception\Subscriber\Module() ); $this->dispatcher->addSubscriber( new \Codeception\Subscriber\BeforeAfterTest() ); $this->dispatcher->addSubscriber( new \WPCC\Subscriber\AutoRebuild() ); // optional if ( !$this->options['silent'] ) { $this->dispatcher->addSubscriber( new \Codeception\Subscriber\Console( $this->options ) ); } if ( $this->options['fail-fast'] ) { $this->dispatcher->addSubscriber( new \Codeception\Subscriber\FailFast() ); } if ( $this->options['coverage'] ) { $this->dispatcher->addSubscriber( new \Codeception\Coverage\Subscriber\Local( $this->options ) ); $this->dispatcher->addSubscriber( new \Codeception\Coverage\Subscriber\LocalServer( $this->options ) ); $this->dispatcher->addSubscriber( new \Codeception\Coverage\Subscriber\RemoteServer( $this->options ) ); $this->dispatcher->addSubscriber( new \Codeception\Coverage\Subscriber\Printer( $this->options ) ); } // extensions foreach ( $this->extensions as $subscriber ) { $this->dispatcher->addSubscriber( $subscriber ); } }
[ "public", "function", "registerSubscribers", "(", ")", "{", "// required", "$", "this", "->", "dispatcher", "->", "addSubscriber", "(", "new", "\\", "Codeception", "\\", "Subscriber", "\\", "ErrorHandler", "(", ")", ")", ";", "$", "this", "->", "dispatcher", ...
Registers event listeners. @since 1.0.0 @access public
[ "Registers", "event", "listeners", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Codecept.php#L38-L66
10up/wp-codeception
classes/WPCC/Codecept.php
Codecept.runSuite
public function runSuite( $settings, $suite, $test = null ) { $suiteManager = new SuiteManager( $this->dispatcher, $suite, $settings ); $suiteManager->initialize(); $suiteManager->loadTests( $test ); $suiteManager->run( $this->runner, $this->result, $this->options ); return $this->result; }
php
public function runSuite( $settings, $suite, $test = null ) { $suiteManager = new SuiteManager( $this->dispatcher, $suite, $settings ); $suiteManager->initialize(); $suiteManager->loadTests( $test ); $suiteManager->run( $this->runner, $this->result, $this->options ); return $this->result; }
[ "public", "function", "runSuite", "(", "$", "settings", ",", "$", "suite", ",", "$", "test", "=", "null", ")", "{", "$", "suiteManager", "=", "new", "SuiteManager", "(", "$", "this", "->", "dispatcher", ",", "$", "suite", ",", "$", "settings", ")", "...
Runs suite tests. @since 1.0.0 @access public @param array $settings The array of suite settings. @param string $suite The suite name to run. @param string $test The test name to run. @return \PHPUnit_Framework_TestResult The suite execution results.
[ "Runs", "suite", "tests", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Codecept.php#L79-L86
10up/wp-codeception
classes/WPCC/Component/Factory/Network.php
Network._createObject
protected function _createObject( $args ) { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $faker = \Faker\Factory::create(); $test_email = defined( 'WP_TESTS_EMAIL' ) ? WP_TESTS_EMAIL : $faker->email; $email = isset( $args['user'] ) ? get_userdata( $args['user'] )->user_email : $test_email; $network = populate_network( $args['network_id'], $args['domain'], $email, $args['title'], $args['path'], $args['subdomain_install'] ); if ( $network && ! is_wp_error( $network ) ) { $this->_debug( 'Generated network ID: ' . $args['network_id'] ); } elseif ( is_wp_error( $network ) ) { $this->_debug( 'Network generation failed with message [%s] %s', $network->get_error_code(), $network->get_error_messages() ); } else { $this->_debug( 'Network generation failed' ); } return $args['network_id']; }
php
protected function _createObject( $args ) { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $faker = \Faker\Factory::create(); $test_email = defined( 'WP_TESTS_EMAIL' ) ? WP_TESTS_EMAIL : $faker->email; $email = isset( $args['user'] ) ? get_userdata( $args['user'] )->user_email : $test_email; $network = populate_network( $args['network_id'], $args['domain'], $email, $args['title'], $args['path'], $args['subdomain_install'] ); if ( $network && ! is_wp_error( $network ) ) { $this->_debug( 'Generated network ID: ' . $args['network_id'] ); } elseif ( is_wp_error( $network ) ) { $this->_debug( 'Network generation failed with message [%s] %s', $network->get_error_code(), $network->get_error_messages() ); } else { $this->_debug( 'Network generation failed' ); } return $args['network_id']; }
[ "protected", "function", "_createObject", "(", "$", "args", ")", "{", "require_once", "ABSPATH", ".", "'wp-admin/includes/upgrade.php'", ";", "$", "faker", "=", "\\", "Faker", "\\", "Factory", "::", "create", "(", ")", ";", "$", "test_email", "=", "defined", ...
Generates a new network. @since 1.0.0 @access protected @param array $args The array of arguments to use during a new object creation. @return int The newly created network's ID.
[ "Generates", "a", "new", "network", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Component/Factory/Network.php#L64-L89
10up/wp-codeception
classes/WPCC/Component/Factory/Network.php
Network._deleteObject
protected function _deleteObject( $network_id ) { global $wpdb; $network_blog = wp_get_sites( array( 'network_id' => $network_id ) ); if ( ! empty( $network_blog ) ) { $suppress = $wpdb->suppress_errors(); foreach ( $network_blog as $blog ) { wpmu_delete_blog( $blog->blog_id, true ); } $wpdb->suppress_errors( $suppress ); } $deleted = $wpdb->delete( $wpdb->site, array( 'id' => $network_id ), array( '%d' ) ); if ( $deleted ) { $wpdb->delete( $wpdb->sitemeta, array( 'site_id' => $network_id ), array( '%d' ) ); $this->_debug( 'Deleted network with ID: ' . $network_id ); return true; } $this->_debug( 'Failed to delet network with ID: ' . $network_id ); return false; }
php
protected function _deleteObject( $network_id ) { global $wpdb; $network_blog = wp_get_sites( array( 'network_id' => $network_id ) ); if ( ! empty( $network_blog ) ) { $suppress = $wpdb->suppress_errors(); foreach ( $network_blog as $blog ) { wpmu_delete_blog( $blog->blog_id, true ); } $wpdb->suppress_errors( $suppress ); } $deleted = $wpdb->delete( $wpdb->site, array( 'id' => $network_id ), array( '%d' ) ); if ( $deleted ) { $wpdb->delete( $wpdb->sitemeta, array( 'site_id' => $network_id ), array( '%d' ) ); $this->_debug( 'Deleted network with ID: ' . $network_id ); return true; } $this->_debug( 'Failed to delet network with ID: ' . $network_id ); return false; }
[ "protected", "function", "_deleteObject", "(", "$", "network_id", ")", "{", "global", "$", "wpdb", ";", "$", "network_blog", "=", "wp_get_sites", "(", "array", "(", "'network_id'", "=>", "$", "network_id", ")", ")", ";", "if", "(", "!", "empty", "(", "$"...
Deletes previously generated network. @since 1.0.0 @access protected @global \wpdb $wpdb The database connection. @param int $network_id The network id. @return boolean TRUE on success, otherwise FALSE.
[ "Deletes", "previously", "generated", "network", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Component/Factory/Network.php#L115-L140
10up/wp-codeception
classes/WPCC/Command/Bootstrap.php
Bootstrap.createAcceptanceSuite
protected function createAcceptanceSuite( $actor = 'Acceptance' ) { $suiteConfig = array( 'class_name' => $actor . $this->actorSuffix, 'modules' => array( 'enabled' => array( 'WebDriver', 'WordPress', "{$actor}Helper", ), 'config' => array( 'WebDriver' => array( 'browser' => 'phantomjs', ), ), ), ); $str = "# Codeception Test Suite Configuration\n\n"; $str .= "# suite for acceptance tests.\n"; $str .= "# perform tests in browser using the WebDriver or PhpBrowser.\n"; $str .= "# If you need both WebDriver and PHPBrowser tests - create a separate suite.\n\n"; $str .= Yaml::dump( $suiteConfig, 5 ); $this->createSuite( 'acceptance', $actor, $str ); }
php
protected function createAcceptanceSuite( $actor = 'Acceptance' ) { $suiteConfig = array( 'class_name' => $actor . $this->actorSuffix, 'modules' => array( 'enabled' => array( 'WebDriver', 'WordPress', "{$actor}Helper", ), 'config' => array( 'WebDriver' => array( 'browser' => 'phantomjs', ), ), ), ); $str = "# Codeception Test Suite Configuration\n\n"; $str .= "# suite for acceptance tests.\n"; $str .= "# perform tests in browser using the WebDriver or PhpBrowser.\n"; $str .= "# If you need both WebDriver and PHPBrowser tests - create a separate suite.\n\n"; $str .= Yaml::dump( $suiteConfig, 5 ); $this->createSuite( 'acceptance', $actor, $str ); }
[ "protected", "function", "createAcceptanceSuite", "(", "$", "actor", "=", "'Acceptance'", ")", "{", "$", "suiteConfig", "=", "array", "(", "'class_name'", "=>", "$", "actor", ".", "$", "this", "->", "actorSuffix", ",", "'modules'", "=>", "array", "(", "'enab...
Creates acceptance suite. @since 1.0.0 @access protected @param string $actor The actor name.
[ "Creates", "acceptance", "suite", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Command/Bootstrap.php#L43-L67
10up/wp-codeception
classes/WPCC/Command/Bootstrap.php
Bootstrap.createGlobalConfig
public function createGlobalConfig() { $basicConfig = array( 'actor' => $this->actorSuffix, 'paths' => array( 'tests' => 'tests', 'log' => $this->logDir, 'data' => $this->dataDir, 'helpers' => $this->helperDir ), 'settings' => array( 'bootstrap' => '_bootstrap.php', 'colors' => strtoupper( substr( PHP_OS, 0, 3 ) ) != 'WIN', 'memory_limit' => WP_MAX_MEMORY_LIMIT ), ); $str = Yaml::dump( $basicConfig, 4 ); if ( $this->namespace ) { $str = "namespace: {$this->namespace} \n" . $str; } file_put_contents( 'codeception.yml', $str ); }
php
public function createGlobalConfig() { $basicConfig = array( 'actor' => $this->actorSuffix, 'paths' => array( 'tests' => 'tests', 'log' => $this->logDir, 'data' => $this->dataDir, 'helpers' => $this->helperDir ), 'settings' => array( 'bootstrap' => '_bootstrap.php', 'colors' => strtoupper( substr( PHP_OS, 0, 3 ) ) != 'WIN', 'memory_limit' => WP_MAX_MEMORY_LIMIT ), ); $str = Yaml::dump( $basicConfig, 4 ); if ( $this->namespace ) { $str = "namespace: {$this->namespace} \n" . $str; } file_put_contents( 'codeception.yml', $str ); }
[ "public", "function", "createGlobalConfig", "(", ")", "{", "$", "basicConfig", "=", "array", "(", "'actor'", "=>", "$", "this", "->", "actorSuffix", ",", "'paths'", "=>", "array", "(", "'tests'", "=>", "'tests'", ",", "'log'", "=>", "$", "this", "->", "l...
Creates global config file. @since 1.0.0 @access public
[ "Creates", "global", "config", "file", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Command/Bootstrap.php#L100-L122
10up/wp-codeception
classes/WPCC/Command/Bootstrap.php
Bootstrap.createDirs
protected function createDirs() { @mkdir( 'tests' ); @mkdir( $this->logDir ); @mkdir( $this->dataDir ); @mkdir( $this->helperDir ); }
php
protected function createDirs() { @mkdir( 'tests' ); @mkdir( $this->logDir ); @mkdir( $this->dataDir ); @mkdir( $this->helperDir ); }
[ "protected", "function", "createDirs", "(", ")", "{", "@", "mkdir", "(", "'tests'", ")", ";", "@", "mkdir", "(", "$", "this", "->", "logDir", ")", ";", "@", "mkdir", "(", "$", "this", "->", "dataDir", ")", ";", "@", "mkdir", "(", "$", "this", "->...
Creates appropriate folders. @since 1.0.0 @access protected
[ "Creates", "appropriate", "folders", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Command/Bootstrap.php#L131-L136
10up/wp-codeception
classes/WPCC/Component/Factory/User.php
User._createObject
protected function _createObject( $args ) { $user_id = wp_insert_user( $args ); if ( $user_id && ! is_wp_error( $user_id ) ) { $this->_debug( 'Generated user with ID: ' . $user_id ); } elseif ( is_wp_error( $user_id ) ) { $this->_debug( 'User generation failed with message [%s] %s', $user_id->get_error_code(), $user_id->get_error_message() ); } else { $this->_debug( 'User generation failed' ); } return $user_id; }
php
protected function _createObject( $args ) { $user_id = wp_insert_user( $args ); if ( $user_id && ! is_wp_error( $user_id ) ) { $this->_debug( 'Generated user with ID: ' . $user_id ); } elseif ( is_wp_error( $user_id ) ) { $this->_debug( 'User generation failed with message [%s] %s', $user_id->get_error_code(), $user_id->get_error_message() ); } else { $this->_debug( 'User generation failed' ); } return $user_id; }
[ "protected", "function", "_createObject", "(", "$", "args", ")", "{", "$", "user_id", "=", "wp_insert_user", "(", "$", "args", ")", ";", "if", "(", "$", "user_id", "&&", "!", "is_wp_error", "(", "$", "user_id", ")", ")", "{", "$", "this", "->", "_deb...
Generates a new user. @since 1.0.0 @access protected @param array $args The array of arguments to use during a new user creation. @return int|\WP_Error The newly created user's ID on success, otherwise a WP_Error object.
[ "Generates", "a", "new", "user", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Component/Factory/User.php#L59-L75
10up/wp-codeception
classes/WPCC/Component/Factory/User.php
User._updateObject
protected function _updateObject( $user_id, $fields ) { $fields['ID'] = $user_id; $updated = wp_update_user( $fields ); if ( $updated && ! is_wp_error( $updated ) ) { $this->_debug( 'Updated user ' . $user_id ); } elseif ( is_wp_error( $updated ) ) { $this->_debug( 'Update failed for user %d with message [%s] %s', $user_id, $updated->get_error_code(), $updated->get_error_message() ); } else { $this->_debug( 'Update failed for user ' . $user_id ); } return $updated; }
php
protected function _updateObject( $user_id, $fields ) { $fields['ID'] = $user_id; $updated = wp_update_user( $fields ); if ( $updated && ! is_wp_error( $updated ) ) { $this->_debug( 'Updated user ' . $user_id ); } elseif ( is_wp_error( $updated ) ) { $this->_debug( 'Update failed for user %d with message [%s] %s', $user_id, $updated->get_error_code(), $updated->get_error_message() ); } else { $this->_debug( 'Update failed for user ' . $user_id ); } return $updated; }
[ "protected", "function", "_updateObject", "(", "$", "user_id", ",", "$", "fields", ")", "{", "$", "fields", "[", "'ID'", "]", "=", "$", "user_id", ";", "$", "updated", "=", "wp_update_user", "(", "$", "fields", ")", ";", "if", "(", "$", "updated", "&...
Updates generated user. @since 1.0.0 @access protected @param mixed $user_id The user id to update. @param array $fields The array of fields to update. @return mixed Updated user ID on success, otherwise a WP_Error object.
[ "Updates", "generated", "user", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Component/Factory/User.php#L87-L104
10up/wp-codeception
classes/WPCC/Component/Factory/User.php
User._deleteObject
protected function _deleteObject( $user_id ) { $user = get_user_by( 'id', $user_id ); if ( ! $user ) { return false; } $deleted = is_multisite() ? wpmu_delete_user( $user_id ) : wp_delete_user( $user_id ); if ( $deleted ) { $this->_debug( 'Deleted user with ID: ' . $user_id ); return true; } $this->_debug( 'User removal failed for ID: ' . $user_id ); return false; }
php
protected function _deleteObject( $user_id ) { $user = get_user_by( 'id', $user_id ); if ( ! $user ) { return false; } $deleted = is_multisite() ? wpmu_delete_user( $user_id ) : wp_delete_user( $user_id ); if ( $deleted ) { $this->_debug( 'Deleted user with ID: ' . $user_id ); return true; } $this->_debug( 'User removal failed for ID: ' . $user_id ); return false; }
[ "protected", "function", "_deleteObject", "(", "$", "user_id", ")", "{", "$", "user", "=", "get_user_by", "(", "'id'", ",", "$", "user_id", ")", ";", "if", "(", "!", "$", "user", ")", "{", "return", "false", ";", "}", "$", "deleted", "=", "is_multisi...
Deletes previously generated user. @since 1.0.0 @access protected @param int $user_id The user id to delete. @return boolean TRUEY on success, otherwise FALSE.
[ "Deletes", "previously", "generated", "user", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Component/Factory/User.php#L115-L132
10up/wp-codeception
classes/WPCC/Module/BrowserStack.php
BrowserStack._initialize
public function _initialize() { $this->wd_host = sprintf( 'http://%s:%s@hub.browserstack.com/wd/hub', $this->config['username'], $this->config['access_key'] ); $this->capabilities = $this->config['capabilities']; $this->capabilities[ \WebDriverCapabilityType::BROWSER_NAME ] = $this->config['browser']; if ( ! empty( $this->config['version'] ) ) { $this->capabilities[ \WebDriverCapabilityType::VERSION ] = $this->config['version']; } $this->webDriver = \RemoteWebDriver::create( $this->wd_host, $this->capabilities ); $this->webDriver->manage()->timeouts()->implicitlyWait( $this->config['wait'] ); $this->initialWindowSize(); }
php
public function _initialize() { $this->wd_host = sprintf( 'http://%s:%s@hub.browserstack.com/wd/hub', $this->config['username'], $this->config['access_key'] ); $this->capabilities = $this->config['capabilities']; $this->capabilities[ \WebDriverCapabilityType::BROWSER_NAME ] = $this->config['browser']; if ( ! empty( $this->config['version'] ) ) { $this->capabilities[ \WebDriverCapabilityType::VERSION ] = $this->config['version']; } $this->webDriver = \RemoteWebDriver::create( $this->wd_host, $this->capabilities ); $this->webDriver->manage()->timeouts()->implicitlyWait( $this->config['wait'] ); $this->initialWindowSize(); }
[ "public", "function", "_initialize", "(", ")", "{", "$", "this", "->", "wd_host", "=", "sprintf", "(", "'http://%s:%s@hub.browserstack.com/wd/hub'", ",", "$", "this", "->", "config", "[", "'username'", "]", ",", "$", "this", "->", "config", "[", "'access_key'"...
Initializes webdriver. @since 1.0.0 @access public
[ "Initializes", "webdriver", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Module/BrowserStack.php#L57-L70
10up/wp-codeception
classes/WPCC/Module/BrowserStack.php
BrowserStack.initialWindowSize
protected function initialWindowSize() { if ( isset( $this->config['resolution'] ) ) { if ( $this->config['resolution'] == 'maximize' ) { $this->maximizeWindow(); } else { $size = explode( 'x', $this->config['resolution'] ); if ( count( $size ) == 2 ) { $this->resizeWindow( intval( $size[0] ), intval( $size[1] ) ); } } } }
php
protected function initialWindowSize() { if ( isset( $this->config['resolution'] ) ) { if ( $this->config['resolution'] == 'maximize' ) { $this->maximizeWindow(); } else { $size = explode( 'x', $this->config['resolution'] ); if ( count( $size ) == 2 ) { $this->resizeWindow( intval( $size[0] ), intval( $size[1] ) ); } } } }
[ "protected", "function", "initialWindowSize", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "config", "[", "'resolution'", "]", ")", ")", "{", "if", "(", "$", "this", "->", "config", "[", "'resolution'", "]", "==", "'maximize'", ")", "{", ...
Setup initial window size. @since 1.0.0 @access protected
[ "Setup", "initial", "window", "size", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Module/BrowserStack.php#L79-L90
10up/wp-codeception
classes/WPCC/Module/MailtrapIO.php
MailtrapIO._setup_smtp_settings
public function _setup_smtp_settings( \PHPMailer $phpmailer ) { $phpmailer->Host = 'mailtrap.io'; $phpmailer->Port = $this->config['port']; $phpmailer->Username = $this->config['username']; $phpmailer->Password = $this->config['password']; $phpmailer->SMTPAuth = true; $phpmailer->SMTPDebug = 1; $phpmailer->IsSMTP(); }
php
public function _setup_smtp_settings( \PHPMailer $phpmailer ) { $phpmailer->Host = 'mailtrap.io'; $phpmailer->Port = $this->config['port']; $phpmailer->Username = $this->config['username']; $phpmailer->Password = $this->config['password']; $phpmailer->SMTPAuth = true; $phpmailer->SMTPDebug = 1; $phpmailer->IsSMTP(); }
[ "public", "function", "_setup_smtp_settings", "(", "\\", "PHPMailer", "$", "phpmailer", ")", "{", "$", "phpmailer", "->", "Host", "=", "'mailtrap.io'", ";", "$", "phpmailer", "->", "Port", "=", "$", "this", "->", "config", "[", "'port'", "]", ";", "$", "...
Setups SMPT settings for the mailer object. @since 1.0.0 @action phpmailer_init @access public @param \PHPMailer $phpmailer The mailer object.
[ "Setups", "SMPT", "settings", "for", "the", "mailer", "object", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Module/MailtrapIO.php#L91-L100
10up/wp-codeception
classes/WPCC/Module/MailtrapIO.php
MailtrapIO._send_request
protected function _send_request( $url, $args = array() ) { $url = 'https://mailtrap.io/api/v1/inboxes/' . $this->config['inbox_id'] . $url; $args = wp_parse_args( $args, array( 'method' => 'GET', 'headers' => array(), ) ); $args['headers'] = array_merge( $args['headers'], array( 'Api-Token' => $this->config['api_token'], 'Accept' => 'application/json', ) ); $response = wp_remote_request( $url, $args ); return $response; }
php
protected function _send_request( $url, $args = array() ) { $url = 'https://mailtrap.io/api/v1/inboxes/' . $this->config['inbox_id'] . $url; $args = wp_parse_args( $args, array( 'method' => 'GET', 'headers' => array(), ) ); $args['headers'] = array_merge( $args['headers'], array( 'Api-Token' => $this->config['api_token'], 'Accept' => 'application/json', ) ); $response = wp_remote_request( $url, $args ); return $response; }
[ "protected", "function", "_send_request", "(", "$", "url", ",", "$", "args", "=", "array", "(", ")", ")", "{", "$", "url", "=", "'https://mailtrap.io/api/v1/inboxes/'", ".", "$", "this", "->", "config", "[", "'inbox_id'", "]", ".", "$", "url", ";", "$", ...
Sends request to the Mailtrap.io API. @since 1.0.0 @access protected @param string $url The relative URL to a resource. @param array $args The array of arguments for a request. @return array The response array.
[ "Sends", "request", "to", "the", "Mailtrap", ".", "io", "API", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Module/MailtrapIO.php#L112-L128
10up/wp-codeception
classes/WPCC/Module/MailtrapIO.php
MailtrapIO._send_get_request
protected function _send_get_request( $url ) { $response = $this->_send_request( $url, array( 'method' => 'GET' ) ); $response_code = wp_remote_retrieve_response_code( $response ); $this->assertEquals( 200, $response_code, 'The Mailtrap.io API resonse code is not equals to 200.' ); return $response; }
php
protected function _send_get_request( $url ) { $response = $this->_send_request( $url, array( 'method' => 'GET' ) ); $response_code = wp_remote_retrieve_response_code( $response ); $this->assertEquals( 200, $response_code, 'The Mailtrap.io API resonse code is not equals to 200.' ); return $response; }
[ "protected", "function", "_send_get_request", "(", "$", "url", ")", "{", "$", "response", "=", "$", "this", "->", "_send_request", "(", "$", "url", ",", "array", "(", "'method'", "=>", "'GET'", ")", ")", ";", "$", "response_code", "=", "wp_remote_retrieve_...
Sends GET request to the Mailtrap.io API. @since 1.0.0 @access public @param string $url The relative URL to a resource. @return array The response array.
[ "Sends", "GET", "request", "to", "the", "Mailtrap", ".", "io", "API", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Module/MailtrapIO.php#L139-L146
10up/wp-codeception
classes/WPCC/Module/MailtrapIO.php
MailtrapIO._send_delete_request
protected function _send_delete_request( $url ) { $response = $this->_send_request( $url, array( 'method' => 'DELETE' ) ); $response_code = wp_remote_retrieve_response_code( $response ); $this->assertEquals( 200, $response_code, 'The Mailtrap.io API resonse code is not equals to 200.' ); return $response; }
php
protected function _send_delete_request( $url ) { $response = $this->_send_request( $url, array( 'method' => 'DELETE' ) ); $response_code = wp_remote_retrieve_response_code( $response ); $this->assertEquals( 200, $response_code, 'The Mailtrap.io API resonse code is not equals to 200.' ); return $response; }
[ "protected", "function", "_send_delete_request", "(", "$", "url", ")", "{", "$", "response", "=", "$", "this", "->", "_send_request", "(", "$", "url", ",", "array", "(", "'method'", "=>", "'DELETE'", ")", ")", ";", "$", "response_code", "=", "wp_remote_ret...
Sends DELETE request to the Mailtrap.io API. @since 1.0.0 @access protected @param string $url The relative URL to a resource. @return array The response array.
[ "Sends", "DELETE", "request", "to", "the", "Mailtrap", ".", "io", "API", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Module/MailtrapIO.php#L157-L164
10up/wp-codeception
classes/WPCC/Module/MailtrapIO.php
MailtrapIO._send_patch_request
protected function _send_patch_request( $url, $body ) { $response = $this->_send_request( $url, array( 'method' => 'PATCH', 'body' => $body, ) ); $response_code = wp_remote_retrieve_response_code( $response ); $this->assertEquals( 200, $response_code, 'The Mailtrap.io API resonse code is not equals to 200.' ); return $response; }
php
protected function _send_patch_request( $url, $body ) { $response = $this->_send_request( $url, array( 'method' => 'PATCH', 'body' => $body, ) ); $response_code = wp_remote_retrieve_response_code( $response ); $this->assertEquals( 200, $response_code, 'The Mailtrap.io API resonse code is not equals to 200.' ); return $response; }
[ "protected", "function", "_send_patch_request", "(", "$", "url", ",", "$", "body", ")", "{", "$", "response", "=", "$", "this", "->", "_send_request", "(", "$", "url", ",", "array", "(", "'method'", "=>", "'PATCH'", ",", "'body'", "=>", "$", "body", ",...
Sends PATCH request to the Mailtrap.io API. @since 1.0.0 @access protected @param string $url The relative URL to a resource. @param array $body The request body. @return array The response array.
[ "Sends", "PATCH", "request", "to", "the", "Mailtrap", ".", "io", "API", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Module/MailtrapIO.php#L176-L186
10up/wp-codeception
classes/WPCC/Module/MailtrapIO.php
MailtrapIO.seeNewEmailFor
public function seeNewEmailFor( $recipient ) { $email = $this->grabLatestEmailFor( $recipient ); $this->assertEquals( $recipient, $email['to_email'], 'The email recipient is wrong.' ); $this->assertFalse( $email['is_read'], 'The email is already read.' ); }
php
public function seeNewEmailFor( $recipient ) { $email = $this->grabLatestEmailFor( $recipient ); $this->assertEquals( $recipient, $email['to_email'], 'The email recipient is wrong.' ); $this->assertFalse( $email['is_read'], 'The email is already read.' ); }
[ "public", "function", "seeNewEmailFor", "(", "$", "recipient", ")", "{", "$", "email", "=", "$", "this", "->", "grabLatestEmailFor", "(", "$", "recipient", ")", ";", "$", "this", "->", "assertEquals", "(", "$", "recipient", ",", "$", "email", "[", "'to_e...
Checks whether a new email exists for a recipient or not. @since 1.0.0 @access public @param string $recipient The email address of a recipient.
[ "Checks", "whether", "a", "new", "email", "exists", "for", "a", "recipient", "or", "not", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Module/MailtrapIO.php#L196-L200
10up/wp-codeception
classes/WPCC/Module/MailtrapIO.php
MailtrapIO.deleteEmail
public function deleteEmail( $email_id = null ) { if ( ! $email_id ) { $this->assertNotEmpty( $this->_current_email, 'The current email is not selected' ); $email_id = $this->_current_email['id']; } $this->_send_delete_request( '/messages/' . $email_id ); }
php
public function deleteEmail( $email_id = null ) { if ( ! $email_id ) { $this->assertNotEmpty( $this->_current_email, 'The current email is not selected' ); $email_id = $this->_current_email['id']; } $this->_send_delete_request( '/messages/' . $email_id ); }
[ "public", "function", "deleteEmail", "(", "$", "email_id", "=", "null", ")", "{", "if", "(", "!", "$", "email_id", ")", "{", "$", "this", "->", "assertNotEmpty", "(", "$", "this", "->", "_current_email", ",", "'The current email is not selected'", ")", ";", ...
Deletes an email from the inbox. If no email id is provided, then email id will be taken from the current email. @since 1.0.0 @access public @param int $email_id The email id to delete.
[ "Deletes", "an", "email", "from", "the", "inbox", ".", "If", "no", "email", "id", "is", "provided", "then", "email", "id", "will", "be", "taken", "from", "the", "current", "email", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Module/MailtrapIO.php#L231-L238
10up/wp-codeception
classes/WPCC/Module/MailtrapIO.php
MailtrapIO.markEmailRead
public function markEmailRead( $email_id = null ) { if ( ! $email_id ) { $this->assertNotEmpty( $this->_current_email, 'The current email is not selected' ); $email_id = $this->_current_email['id']; } $this->_send_patch_request( '/messages/' . $email_id, array( 'message' => array( 'is_read' => true ) ) ); }
php
public function markEmailRead( $email_id = null ) { if ( ! $email_id ) { $this->assertNotEmpty( $this->_current_email, 'The current email is not selected' ); $email_id = $this->_current_email['id']; } $this->_send_patch_request( '/messages/' . $email_id, array( 'message' => array( 'is_read' => true ) ) ); }
[ "public", "function", "markEmailRead", "(", "$", "email_id", "=", "null", ")", "{", "if", "(", "!", "$", "email_id", ")", "{", "$", "this", "->", "assertNotEmpty", "(", "$", "this", "->", "_current_email", ",", "'The current email is not selected'", ")", ";"...
Marks email read. If no email id is provided, then email id will be taken from the current email. @since 1.0.0 @access public @param int $email_id The email id.
[ "Marks", "email", "read", ".", "If", "no", "email", "id", "is", "provided", "then", "email", "id", "will", "be", "taken", "from", "the", "current", "email", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Module/MailtrapIO.php#L249-L258
10up/wp-codeception
classes/WPCC/Component/Factory/Blog.php
Blog._createObject
protected function _createObject( $args ) { global $wpdb; $meta = isset( $args['meta'] ) ? $args['meta'] : array(); $user_id = isset( $args['user_id'] ) ? $args['user_id'] : get_current_user_id(); // temp tables will trigger db errors when we attempt to reference them as new temp tables $suppress = $wpdb->suppress_errors(); $blog = wpmu_create_blog( $args['domain'], $args['path'], $args['title'], $user_id, $meta, $args['site_id'] ); $wpdb->suppress_errors( $suppress ); if ( $blog && ! is_wp_error( $blog ) ) { $this->_debug( 'Generated blog ID: ' . $blog ); } elseif ( is_wp_error( $blog ) ) { $this->_debug( 'Blog generation failed with message [%s] %s', $blog->get_error_code(), $blog->get_error_messages() ); } else { $this->_debug( 'Blog generation failed' ); } return $blog; }
php
protected function _createObject( $args ) { global $wpdb; $meta = isset( $args['meta'] ) ? $args['meta'] : array(); $user_id = isset( $args['user_id'] ) ? $args['user_id'] : get_current_user_id(); // temp tables will trigger db errors when we attempt to reference them as new temp tables $suppress = $wpdb->suppress_errors(); $blog = wpmu_create_blog( $args['domain'], $args['path'], $args['title'], $user_id, $meta, $args['site_id'] ); $wpdb->suppress_errors( $suppress ); if ( $blog && ! is_wp_error( $blog ) ) { $this->_debug( 'Generated blog ID: ' . $blog ); } elseif ( is_wp_error( $blog ) ) { $this->_debug( 'Blog generation failed with message [%s] %s', $blog->get_error_code(), $blog->get_error_messages() ); } else { $this->_debug( 'Blog generation failed' ); } return $blog; }
[ "protected", "function", "_createObject", "(", "$", "args", ")", "{", "global", "$", "wpdb", ";", "$", "meta", "=", "isset", "(", "$", "args", "[", "'meta'", "]", ")", "?", "$", "args", "[", "'meta'", "]", ":", "array", "(", ")", ";", "$", "user_...
Generates a new blog. @since 1.0.0 @access protected @global \wpdb $wpdb The database connection. @param array $args The array of arguments to use during a new blog creation. @return int|\WP_Error The newly created blog's ID on success, otherwise a WP_Error object.
[ "Generates", "a", "new", "blog", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Component/Factory/Blog.php#L66-L90
10up/wp-codeception
classes/WPCC/Component/Factory/Blog.php
Blog._deleteObject
protected function _deleteObject( $blog_id ) { global $wpdb; $suppress = $wpdb->suppress_errors(); wpmu_delete_blog( $blog_id, true ); $wpdb->suppress_errors( $suppress ); $this->_debug( 'Deleted blog with ID: ' . $blog_id ); return true; }
php
protected function _deleteObject( $blog_id ) { global $wpdb; $suppress = $wpdb->suppress_errors(); wpmu_delete_blog( $blog_id, true ); $wpdb->suppress_errors( $suppress ); $this->_debug( 'Deleted blog with ID: ' . $blog_id ); return true; }
[ "protected", "function", "_deleteObject", "(", "$", "blog_id", ")", "{", "global", "$", "wpdb", ";", "$", "suppress", "=", "$", "wpdb", "->", "suppress_errors", "(", ")", ";", "wpmu_delete_blog", "(", "$", "blog_id", ",", "true", ")", ";", "$", "wpdb", ...
Deletes previously generated blog. @since 1.0.0 @access protected @global \wpdb $wpdb The database connection. @param int $blog_id The blog id. @return boolean Always returns TRUE.
[ "Deletes", "previously", "generated", "blog", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Component/Factory/Blog.php#L116-L126
10up/wp-codeception
classes/WPCC/CLI/Codeception.php
Codeception.run
public function run( $args, $assoc_args ) { $app = new Application( 'Codeception', \Codeception\Codecept::VERSION ); $app->add( new \WPCC\Command\Run( 'run' ) ); $app->run( new ArgvInput() ); }
php
public function run( $args, $assoc_args ) { $app = new Application( 'Codeception', \Codeception\Codecept::VERSION ); $app->add( new \WPCC\Command\Run( 'run' ) ); $app->run( new ArgvInput() ); }
[ "public", "function", "run", "(", "$", "args", ",", "$", "assoc_args", ")", "{", "$", "app", "=", "new", "Application", "(", "'Codeception'", ",", "\\", "Codeception", "\\", "Codecept", "::", "VERSION", ")", ";", "$", "app", "->", "add", "(", "new", ...
Runs Codeception tests. ### OPTIONS <suite> : The suite name to run. There are three types of suites available to use: unit, functional and acceptance, but currently only acceptance tests are supported. <test> : The test name to run. <config> : Path to the custom config file. <report> : Determines whether to show output in compact style or not. <html> : Tells to generate html with results (default: "report.html"). <xml> : Tells to generate JUnit XML Log (default: "report.xml"). <tap> : Tells to generate Tap Log (default: "report.tap.log"). <json> : Tells to generate Json Log (default: "report.json"). <colors> : Tells to use colors in output. <no-colors> : Forces no colors in output (useful to override config file). <silent> : Tells to output only suite names and final results. <steps> : Determines whether to show test steps in output or not. <debug> : Determines whether to show debug and scenario output or not. <coverage> : Determines whether to run with code coverage (default: "coverage.serialized") or not. <coverage-html> : Tells to generate CodeCoverage HTML report in path (default: "coverage"). <coverage-xml> : Tells to generate CodeCoverage XML report in file (default: "coverage.xml"). <coverage-text> : Tells to generate CodeCoverage text report in file (default: "coverage.txt"). <no-exit> : Tells to not finish with exit code. <env> : Environment to use during tests execution. <fail-fast> : Tells to stop after first failure. <quiet> : Tells to not output any message. <ansi> : Forces ANSI output. <no-ansi> : Tells to disable ANSI output. <no-interaction> : Tells to not ask any interactive question. ### EXAMPLE wp codeception run wp codeception run acceptance --steps --html wp codeception run acceptance MyAwesomeTest --debug wp codeception run functional --env=staging @synopsis [<suite>] [<test>] [--config=<config>] [--report] [--html=<html>] [--xml=<xml>] [--tap=<tap>] [--json=<json>] [--colors] [--no-colors] [--silent] [--steps] [--debug] [--coverage] [--coverage-html] [--coverage-xml] [--coverage-text] [--no-exit] [--env=<env>] [--fail-fast] [--quiet] [--ansi] [--no-ansi] [--no-interaction] @since 1.0.0 @todo Implement all arguments for run command (http://codeception.com/docs/reference/Commands). @access public @param array $args Unassociated array of arguments passed to this command. @param array $assoc_args Associated array of arguments passed to this command.
[ "Runs", "Codeception", "tests", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/CLI/Codeception.php#L136-L140
10up/wp-codeception
classes/WPCC/CLI/Codeception.php
Codeception._execute_command
private function _execute_command() { $app = new Application( 'Codeception', \Codeception\Codecept::VERSION ); $app->add( new \WPCC\Command\Build( 'build' ) ); $app->add( new \Codeception\Command\Console( 'console' ) ); $app->add( new \WPCC\Command\Bootstrap( 'bootstrap' ) ); $app->add( new \Codeception\Command\GenerateCept( 'generate-cept' ) ); $app->add( new \Codeception\Command\GenerateCest( 'generate-cest' ) ); $app->add( new \Codeception\Command\GenerateTest( 'generate-test' ) ); $app->add( new \Codeception\Command\GeneratePhpUnit( 'generate-phpunit' ) ); $app->add( new \Codeception\Command\GenerateSuite( 'generate-suite' ) ); $app->add( new \Codeception\Command\GenerateHelper( 'generate-helper' ) ); $app->add( new \Codeception\Command\GenerateScenarios( 'generate-scenarios' ) ); $app->add( new \Codeception\Command\Clean( 'clean' ) ); $app->add( new \Codeception\Command\GenerateGroup( 'generate-group' ) ); $app->add( new \Codeception\Command\GeneratePageObject( 'generate-pageobject' ) ); $app->add( new \Codeception\Command\GenerateStepObject( 'generate-stepobject' ) ); $app->run( new ArgvInput() ); }
php
private function _execute_command() { $app = new Application( 'Codeception', \Codeception\Codecept::VERSION ); $app->add( new \WPCC\Command\Build( 'build' ) ); $app->add( new \Codeception\Command\Console( 'console' ) ); $app->add( new \WPCC\Command\Bootstrap( 'bootstrap' ) ); $app->add( new \Codeception\Command\GenerateCept( 'generate-cept' ) ); $app->add( new \Codeception\Command\GenerateCest( 'generate-cest' ) ); $app->add( new \Codeception\Command\GenerateTest( 'generate-test' ) ); $app->add( new \Codeception\Command\GeneratePhpUnit( 'generate-phpunit' ) ); $app->add( new \Codeception\Command\GenerateSuite( 'generate-suite' ) ); $app->add( new \Codeception\Command\GenerateHelper( 'generate-helper' ) ); $app->add( new \Codeception\Command\GenerateScenarios( 'generate-scenarios' ) ); $app->add( new \Codeception\Command\Clean( 'clean' ) ); $app->add( new \Codeception\Command\GenerateGroup( 'generate-group' ) ); $app->add( new \Codeception\Command\GeneratePageObject( 'generate-pageobject' ) ); $app->add( new \Codeception\Command\GenerateStepObject( 'generate-stepobject' ) ); $app->run( new ArgvInput() ); }
[ "private", "function", "_execute_command", "(", ")", "{", "$", "app", "=", "new", "Application", "(", "'Codeception'", ",", "\\", "Codeception", "\\", "Codecept", "::", "VERSION", ")", ";", "$", "app", "->", "add", "(", "new", "\\", "WPCC", "\\", "Comman...
Executes command. @since 1.0.0 @access private
[ "Executes", "command", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/CLI/Codeception.php#L149-L166
10up/wp-codeception
classes/WPCC/Component/Factory/Term.php
Term._createObject
protected function _createObject( $args ) { $args = array_merge( array( 'taxonomy' => $this->_taxonomy ), $args ); $term_id_pair = wp_insert_term( $args['name'], $args['taxonomy'], $args ); if ( is_wp_error( $term_id_pair ) ) { $this->_debug( 'Term generation failed with message [%s] %s', $term_id_pair->get_error_code(), $term_id_pair->get_error_messages() ); return $term_id_pair; } $this->_debug( 'Generated term ID: ' . $term_id_pair['term_id'] ); return $term_id_pair['term_id']; }
php
protected function _createObject( $args ) { $args = array_merge( array( 'taxonomy' => $this->_taxonomy ), $args ); $term_id_pair = wp_insert_term( $args['name'], $args['taxonomy'], $args ); if ( is_wp_error( $term_id_pair ) ) { $this->_debug( 'Term generation failed with message [%s] %s', $term_id_pair->get_error_code(), $term_id_pair->get_error_messages() ); return $term_id_pair; } $this->_debug( 'Generated term ID: ' . $term_id_pair['term_id'] ); return $term_id_pair['term_id']; }
[ "protected", "function", "_createObject", "(", "$", "args", ")", "{", "$", "args", "=", "array_merge", "(", "array", "(", "'taxonomy'", "=>", "$", "this", "->", "_taxonomy", ")", ",", "$", "args", ")", ";", "$", "term_id_pair", "=", "wp_insert_term", "("...
Generates a new term. @since 1.0.0 @access protected @param array $args The array of arguments to use during a new term creation. @return int|\WP_Error The newly created term's ID on success, otherwise a WP_Error object.
[ "Generates", "a", "new", "term", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Component/Factory/Term.php#L75-L91
10up/wp-codeception
classes/WPCC/Component/Factory/Term.php
Term._updateObject
protected function _updateObject( $term, $fields ) { $fields = array_merge( array( 'taxonomy' => $this->_taxonomy ), $fields ); $taxonomy = is_object( $term ) ? $term->taxonomy : $this->_taxonomy; $term_id_pair = wp_update_term( $term, $taxonomy, $fields ); if ( is_wp_error( $term_id_pair ) ) { $this->_debug( 'Update failed for term %d with message [%s] %s', is_object( $term ) ? $term->term_id : $term, $term_id_pair->get_error_code(), $term_id_pair->get_error_message() ); return $term_id_pair; } $this->_debug( 'Updated term ' . $term_id_pair['term_id'] ); return $term_id_pair['term_id']; }
php
protected function _updateObject( $term, $fields ) { $fields = array_merge( array( 'taxonomy' => $this->_taxonomy ), $fields ); $taxonomy = is_object( $term ) ? $term->taxonomy : $this->_taxonomy; $term_id_pair = wp_update_term( $term, $taxonomy, $fields ); if ( is_wp_error( $term_id_pair ) ) { $this->_debug( 'Update failed for term %d with message [%s] %s', is_object( $term ) ? $term->term_id : $term, $term_id_pair->get_error_code(), $term_id_pair->get_error_message() ); return $term_id_pair; } $this->_debug( 'Updated term ' . $term_id_pair['term_id'] ); return $term_id_pair['term_id']; }
[ "protected", "function", "_updateObject", "(", "$", "term", ",", "$", "fields", ")", "{", "$", "fields", "=", "array_merge", "(", "array", "(", "'taxonomy'", "=>", "$", "this", "->", "_taxonomy", ")", ",", "$", "fields", ")", ";", "$", "taxonomy", "=",...
Updates generated term. @since 1.0.0 @access protected @param mixed $term The term id to update. @param array $fields The array of fields to update. @return mixed Updated term ID on success, otherwise a WP_Error object.
[ "Updates", "generated", "term", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Component/Factory/Term.php#L103-L122
10up/wp-codeception
classes/WPCC/Component/Factory/Term.php
Term._deleteObject
protected function _deleteObject( $term_id ) { $term = get_term_by( 'id', $term_id, $this->_taxonomy ); if ( ! $term || is_wp_error( $term ) ) { return false; } $deleted = wp_delete_term( $term_id, $this->_taxonomy ); if ( $deleted && ! is_wp_error( $deleted ) ) { $this->_debug( 'Deleted term with ID: ' . $term_id ); return true; } elseif ( is_wp_error( $deleted ) ) { $this->_debug( 'Removal failed for term %d with message [%s] %s', $term_id, $deleted->get_error_code(), $deleted->get_error_message() ); } else { $this->_debug( 'Term removal failed for ID: ' . $term_id ); } return false; }
php
protected function _deleteObject( $term_id ) { $term = get_term_by( 'id', $term_id, $this->_taxonomy ); if ( ! $term || is_wp_error( $term ) ) { return false; } $deleted = wp_delete_term( $term_id, $this->_taxonomy ); if ( $deleted && ! is_wp_error( $deleted ) ) { $this->_debug( 'Deleted term with ID: ' . $term_id ); return true; } elseif ( is_wp_error( $deleted ) ) { $this->_debug( 'Removal failed for term %d with message [%s] %s', $term_id, $deleted->get_error_code(), $deleted->get_error_message() ); } else { $this->_debug( 'Term removal failed for ID: ' . $term_id ); } return false; }
[ "protected", "function", "_deleteObject", "(", "$", "term_id", ")", "{", "$", "term", "=", "get_term_by", "(", "'id'", ",", "$", "term_id", ",", "$", "this", "->", "_taxonomy", ")", ";", "if", "(", "!", "$", "term", "||", "is_wp_error", "(", "$", "te...
Deletes previously generated term. @since 1.0.0 @access protected @param int $term_id The term id to delete. @return boolean TRUE on success, otherwise FALSE.
[ "Deletes", "previously", "generated", "term", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Component/Factory/Term.php#L133-L155
10up/wp-codeception
classes/WPCC/Component/Factory/Term.php
Term.addPostTerms
public function addPostTerms( $post_id, $terms, $taxonomy, $append = true ) { return wp_set_post_terms( $post_id, $terms, $taxonomy, $append ); }
php
public function addPostTerms( $post_id, $terms, $taxonomy, $append = true ) { return wp_set_post_terms( $post_id, $terms, $taxonomy, $append ); }
[ "public", "function", "addPostTerms", "(", "$", "post_id", ",", "$", "terms", ",", "$", "taxonomy", ",", "$", "append", "=", "true", ")", "{", "return", "wp_set_post_terms", "(", "$", "post_id", ",", "$", "terms", ",", "$", "taxonomy", ",", "$", "appen...
Adds terms to a post. @since 1.0.0 @access public @param int $post_id The post id to add terms to. @param array $terms The array of terms to add. @param string $taxonomy The taxonomy name of terms. @param boolean $append Determines whether to add or replace terms. @return array The array of affected term IDs.
[ "Adds", "terms", "to", "a", "post", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Component/Factory/Term.php#L169-L171
10up/wp-codeception
classes/WPCC/Util/Debug.php
Debug.debugf
public static function debugf( $message, $args ) { $args = array_slice( func_get_args(), 1 ); if ( count( $args ) == 1 && is_array( $args[0] ) ) { $args = $args[0]; } array_unshift( $args, $message ); $message = call_user_func_array( 'sprintf', $args ); self::debug( $message ); }
php
public static function debugf( $message, $args ) { $args = array_slice( func_get_args(), 1 ); if ( count( $args ) == 1 && is_array( $args[0] ) ) { $args = $args[0]; } array_unshift( $args, $message ); $message = call_user_func_array( 'sprintf', $args ); self::debug( $message ); }
[ "public", "static", "function", "debugf", "(", "$", "message", ",", "$", "args", ")", "{", "$", "args", "=", "array_slice", "(", "func_get_args", "(", ")", ",", "1", ")", ";", "if", "(", "count", "(", "$", "args", ")", "==", "1", "&&", "is_array", ...
Prints formatted data to screen. Example: <pre><code> <?php // using multiple arguments \WPCC\Util\Debug::debugf( 'Here are %s and %s parameters', $first, $second ); // or an array \WPCC\Util\Debug::debugf( 'Here are %s and %s parameters', array( $first, $second ) ); ?> </code></pre> @since 1.0.2 @uses sprintf() to build debug message. @uses \Codeception\Util\Debug::debug() to print data to screen. @static @access public @param string $message The message pattern. @param type $args
[ "Prints", "formatted", "data", "to", "screen", "." ]
train
https://github.com/10up/wp-codeception/blob/9eb60dc0fe2a1374cdf78f7308932f5212f85304/classes/WPCC/Util/Debug.php#L57-L66
florianv/laravel-swap
src/SwapServiceProvider.php
SwapServiceProvider.boot
public function boot() { $source = realpath(__DIR__.'/../config/swap.php'); $this->publishes([$source => $this->getConfigPath('swap.php')]); $this->mergeConfigFrom($source, 'swap'); }
php
public function boot() { $source = realpath(__DIR__.'/../config/swap.php'); $this->publishes([$source => $this->getConfigPath('swap.php')]); $this->mergeConfigFrom($source, 'swap'); }
[ "public", "function", "boot", "(", ")", "{", "$", "source", "=", "realpath", "(", "__DIR__", ".", "'/../config/swap.php'", ")", ";", "$", "this", "->", "publishes", "(", "[", "$", "source", "=>", "$", "this", "->", "getConfigPath", "(", "'swap.php'", ")"...
Bootstrap the application services.
[ "Bootstrap", "the", "application", "services", "." ]
train
https://github.com/florianv/laravel-swap/blob/7501fa7038011dc652cd7839088b5160c61e2694/src/SwapServiceProvider.php#L29-L34
florianv/laravel-swap
src/SwapServiceProvider.php
SwapServiceProvider.register
public function register() { $this->app->singleton('swap', function ($app) { $builder = new Builder($app->config->get('swap.options', [])); if (null !== $cache = $this->getSimpleCache()) { $builder->useSimpleCache($cache); } if (null !== $httpClient = $this->getHttpClient()) { $builder->useHttpClient($httpClient); } if (null !== $requestFactory = $this->getRequestFactory()) { $builder->useRequestFactory($requestFactory); } foreach ($app->config->get('swap.services', []) as $name => $config) { if (false === $config) { continue; } $builder->add($name, is_array($config) ? $config : []); } return $builder->build(); }); $this->app->bind('Swap\Swap', 'swap'); }
php
public function register() { $this->app->singleton('swap', function ($app) { $builder = new Builder($app->config->get('swap.options', [])); if (null !== $cache = $this->getSimpleCache()) { $builder->useSimpleCache($cache); } if (null !== $httpClient = $this->getHttpClient()) { $builder->useHttpClient($httpClient); } if (null !== $requestFactory = $this->getRequestFactory()) { $builder->useRequestFactory($requestFactory); } foreach ($app->config->get('swap.services', []) as $name => $config) { if (false === $config) { continue; } $builder->add($name, is_array($config) ? $config : []); } return $builder->build(); }); $this->app->bind('Swap\Swap', 'swap'); }
[ "public", "function", "register", "(", ")", "{", "$", "this", "->", "app", "->", "singleton", "(", "'swap'", ",", "function", "(", "$", "app", ")", "{", "$", "builder", "=", "new", "Builder", "(", "$", "app", "->", "config", "->", "get", "(", "'swa...
Register the application services.
[ "Register", "the", "application", "services", "." ]
train
https://github.com/florianv/laravel-swap/blob/7501fa7038011dc652cd7839088b5160c61e2694/src/SwapServiceProvider.php#L39-L68
florianv/laravel-swap
src/SwapServiceProvider.php
SwapServiceProvider.getSimpleCache
private function getSimpleCache() { if ($cache = $this->app->config->get('swap.cache')) { $store = $this->app['cache']->store($cache)->getStore(); return new SimpleCacheBridge(new IlluminateCachePool($store)); } return null; }
php
private function getSimpleCache() { if ($cache = $this->app->config->get('swap.cache')) { $store = $this->app['cache']->store($cache)->getStore(); return new SimpleCacheBridge(new IlluminateCachePool($store)); } return null; }
[ "private", "function", "getSimpleCache", "(", ")", "{", "if", "(", "$", "cache", "=", "$", "this", "->", "app", "->", "config", "->", "get", "(", "'swap.cache'", ")", ")", "{", "$", "store", "=", "$", "this", "->", "app", "[", "'cache'", "]", "->",...
Gets the simple cache. @return SimpleCacheBridge
[ "Gets", "the", "simple", "cache", "." ]
train
https://github.com/florianv/laravel-swap/blob/7501fa7038011dc652cd7839088b5160c61e2694/src/SwapServiceProvider.php#L99-L108
florianv/laravel-swap
src/SwapServiceProvider.php
SwapServiceProvider.getHttpClient
private function getHttpClient() { if ($httpClient = $this->app->config->get('swap.http_client')) { return $this->app[$httpClient]; } return null; }
php
private function getHttpClient() { if ($httpClient = $this->app->config->get('swap.http_client')) { return $this->app[$httpClient]; } return null; }
[ "private", "function", "getHttpClient", "(", ")", "{", "if", "(", "$", "httpClient", "=", "$", "this", "->", "app", "->", "config", "->", "get", "(", "'swap.http_client'", ")", ")", "{", "return", "$", "this", "->", "app", "[", "$", "httpClient", "]", ...
Gets the http client. @return \Psr\Http\Client\ClientInterface|null
[ "Gets", "the", "http", "client", "." ]
train
https://github.com/florianv/laravel-swap/blob/7501fa7038011dc652cd7839088b5160c61e2694/src/SwapServiceProvider.php#L115-L122
florianv/laravel-swap
src/SwapServiceProvider.php
SwapServiceProvider.getRequestFactory
private function getRequestFactory() { if ($requestFactory = $this->app->config->get('swap.request_factory')) { return $this->app[$requestFactory]; } return null; }
php
private function getRequestFactory() { if ($requestFactory = $this->app->config->get('swap.request_factory')) { return $this->app[$requestFactory]; } return null; }
[ "private", "function", "getRequestFactory", "(", ")", "{", "if", "(", "$", "requestFactory", "=", "$", "this", "->", "app", "->", "config", "->", "get", "(", "'swap.request_factory'", ")", ")", "{", "return", "$", "this", "->", "app", "[", "$", "requestF...
Gets the request factory. @return \Psr\Http\Message\RequestFactoryInterface|null
[ "Gets", "the", "request", "factory", "." ]
train
https://github.com/florianv/laravel-swap/blob/7501fa7038011dc652cd7839088b5160c61e2694/src/SwapServiceProvider.php#L129-L136
jsor/geokit
src/Utils.php
Utils.normalizeLat
public static function normalizeLat(float $lat): float { if ($lat > 360.0) { $lat = \fmod($lat, 360.0); } if ($lat < -360.0) { $lat = \fmod($lat, -360.0); } if ($lat > 180.0) { $lat = 180.0 - $lat; } if ($lat < -180.0) { $lat = -180.0 - $lat; } if ($lat > 90.0) { $lat = 180.0 - $lat; } if ($lat < -90.0) { $lat = -180.0 - $lat; } return $lat; }
php
public static function normalizeLat(float $lat): float { if ($lat > 360.0) { $lat = \fmod($lat, 360.0); } if ($lat < -360.0) { $lat = \fmod($lat, -360.0); } if ($lat > 180.0) { $lat = 180.0 - $lat; } if ($lat < -180.0) { $lat = -180.0 - $lat; } if ($lat > 90.0) { $lat = 180.0 - $lat; } if ($lat < -90.0) { $lat = -180.0 - $lat; } return $lat; }
[ "public", "static", "function", "normalizeLat", "(", "float", "$", "lat", ")", ":", "float", "{", "if", "(", "$", "lat", ">", "360.0", ")", "{", "$", "lat", "=", "\\", "fmod", "(", "$", "lat", ",", "360.0", ")", ";", "}", "if", "(", "$", "lat",...
Normalizes a latitude in degrees to the -90,90 range. @see https://github.com/postgis/postgis/blob/153cf2b8e346182e371d0fdec7f34baaf78c4334/liblwgeom/lwgeodetic.c#L133-L155
[ "Normalizes", "a", "latitude", "in", "degrees", "to", "the", "-", "90", "90", "range", "." ]
train
https://github.com/jsor/geokit/blob/52eb6d4f497c449e9f7c0fe0b6a0d5a35dec1c2e/src/Utils.php#L13-L40
jsor/geokit
src/Utils.php
Utils.normalizeLng
public static function normalizeLng(float $lng): float { if ($lng > 360.0) { $lng = \fmod($lng, 360.0); } if ($lng < -360.0) { $lng = \fmod($lng, -360.0); } if ($lng > 180.0) { $lng = -360.0 + $lng; } if ($lng < -180.0) { $lng = 360.0 + $lng; } if ($lng === -180.0) { return 180.0; } if ($lng === -360.0) { return 0.0; } return $lng; }
php
public static function normalizeLng(float $lng): float { if ($lng > 360.0) { $lng = \fmod($lng, 360.0); } if ($lng < -360.0) { $lng = \fmod($lng, -360.0); } if ($lng > 180.0) { $lng = -360.0 + $lng; } if ($lng < -180.0) { $lng = 360.0 + $lng; } if ($lng === -180.0) { return 180.0; } if ($lng === -360.0) { return 0.0; } return $lng; }
[ "public", "static", "function", "normalizeLng", "(", "float", "$", "lng", ")", ":", "float", "{", "if", "(", "$", "lng", ">", "360.0", ")", "{", "$", "lng", "=", "\\", "fmod", "(", "$", "lng", ",", "360.0", ")", ";", "}", "if", "(", "$", "lng",...
Normalizes a longitude in degrees to the -180,180 range. @see https://github.com/postgis/postgis/blob/153cf2b8e346182e371d0fdec7f34baaf78c4334/liblwgeom/lwgeodetic.c#L106-L127
[ "Normalizes", "a", "longitude", "in", "degrees", "to", "the", "-", "180", "180", "range", "." ]
train
https://github.com/jsor/geokit/blob/52eb6d4f497c449e9f7c0fe0b6a0d5a35dec1c2e/src/Utils.php#L46-L73
jsor/geokit
src/Math.php
Math.distanceHaversine
public function distanceHaversine(Position $from, Position $to): Distance { $lat1 = \deg2rad($from->latitude()); $lng1 = \deg2rad($from->longitude()); $lat2 = \deg2rad($to->latitude()); $lng2 = \deg2rad($to->longitude()); $dLat = $lat2 - $lat1; $dLon = $lng2 - $lng1; $a = \sin($dLat / 2) * \sin($dLat / 2) + \cos($lat1) * \cos($lat2) * \sin($dLon / 2) * \sin($dLon / 2); $c = 2 * \atan2(\sqrt($a), \sqrt(1 - $a)); return new Distance(Earth::RADIUS * $c); }
php
public function distanceHaversine(Position $from, Position $to): Distance { $lat1 = \deg2rad($from->latitude()); $lng1 = \deg2rad($from->longitude()); $lat2 = \deg2rad($to->latitude()); $lng2 = \deg2rad($to->longitude()); $dLat = $lat2 - $lat1; $dLon = $lng2 - $lng1; $a = \sin($dLat / 2) * \sin($dLat / 2) + \cos($lat1) * \cos($lat2) * \sin($dLon / 2) * \sin($dLon / 2); $c = 2 * \atan2(\sqrt($a), \sqrt(1 - $a)); return new Distance(Earth::RADIUS * $c); }
[ "public", "function", "distanceHaversine", "(", "Position", "$", "from", ",", "Position", "$", "to", ")", ":", "Distance", "{", "$", "lat1", "=", "\\", "deg2rad", "(", "$", "from", "->", "latitude", "(", ")", ")", ";", "$", "lng1", "=", "\\", "deg2ra...
Calculates the approximate sea level great circle (Earth) distance between two points using the Haversine formula. @see http://en.wikipedia.org/wiki/Haversine_formula @see http://www.movable-type.co.uk/scripts/latlong.html
[ "Calculates", "the", "approximate", "sea", "level", "great", "circle", "(", "Earth", ")", "distance", "between", "two", "points", "using", "the", "Haversine", "formula", "." ]
train
https://github.com/jsor/geokit/blob/52eb6d4f497c449e9f7c0fe0b6a0d5a35dec1c2e/src/Math.php#L16-L33
jsor/geokit
src/Math.php
Math.distanceVincenty
public function distanceVincenty(Position $from, Position $to): Distance { $lat1 = $from->latitude(); $lng1 = $from->longitude(); $lat2 = $to->latitude(); $lng2 = $to->longitude(); $a = Earth::SEMI_MAJOR_AXIS; $b = Earth::SEMI_MINOR_AXIS; $f = Earth::FLATTENING; $L = \deg2rad($lng2 - $lng1); $U1 = \atan((1 - $f) * \tan(\deg2rad($lat1))); $U2 = \atan((1 - $f) * \tan(\deg2rad($lat2))); $sinU1 = \sin($U1); $cosU1 = \cos($U1); $sinU2 = \sin($U2); $cosU2 = \cos($U2); $lambda = $L; $iterLimit = 100; do { $sinLambda = \sin($lambda); $cosLambda = \cos($lambda); $sinSigma = \sqrt(($cosU2 * $sinLambda) * ($cosU2 * $sinLambda) + ($cosU1 * $sinU2 - $sinU1 * $cosU2 * $cosLambda) * ($cosU1 * $sinU2 - $sinU1 * $cosU2 * $cosLambda)); if (0.0 === $sinSigma) { return new Distance(0); // co-incident points } $cosSigma = $sinU1 * $sinU2 + $cosU1 * $cosU2 * $cosLambda; $sigma = \atan2($sinSigma, $cosSigma); $sinAlpha = $cosU1 * $cosU2 * $sinLambda / $sinSigma; $cosSqAlpha = (float) 1 - $sinAlpha * $sinAlpha; if (0.0 !== $cosSqAlpha) { $cos2SigmaM = $cosSigma - 2 * $sinU1 * $sinU2 / $cosSqAlpha; } else { $cos2SigmaM = 0.0; // Equatorial line } $C = $f / 16 * $cosSqAlpha * (4 + $f * (4 - 3 * $cosSqAlpha)); $lambdaP = $lambda; $lambda = $L + (1 - $C) * $f * $sinAlpha * ($sigma + $C * $sinSigma * ($cos2SigmaM + $C * $cosSigma * (-1 + 2 * $cos2SigmaM * $cos2SigmaM))); } while (\abs($lambda - $lambdaP) > 1e-12 && --$iterLimit > 0); if ($iterLimit === 0) { throw new Exception\RuntimeException('Vincenty formula failed to converge.'); } $uSq = $cosSqAlpha * ($a * $a - $b * $b) / ($b * $b); $A = 1 + $uSq / 16384 * (4096 + $uSq * (-768 + $uSq * (320 - 175 * $uSq))); $B = $uSq / 1024 * (256 + $uSq * (-128 + $uSq * (74 - 47 * $uSq))); $deltaSigma = $B * $sinSigma * ($cos2SigmaM + $B / 4 * ($cosSigma * (-1 + 2 * $cos2SigmaM * $cos2SigmaM) - $B / 6 * $cos2SigmaM * (-3 + 4 * $sinSigma * $sinSigma) * (-3 + 4 * $cos2SigmaM * $cos2SigmaM))); $s = $b * $A * ($sigma - $deltaSigma); return new Distance($s); }
php
public function distanceVincenty(Position $from, Position $to): Distance { $lat1 = $from->latitude(); $lng1 = $from->longitude(); $lat2 = $to->latitude(); $lng2 = $to->longitude(); $a = Earth::SEMI_MAJOR_AXIS; $b = Earth::SEMI_MINOR_AXIS; $f = Earth::FLATTENING; $L = \deg2rad($lng2 - $lng1); $U1 = \atan((1 - $f) * \tan(\deg2rad($lat1))); $U2 = \atan((1 - $f) * \tan(\deg2rad($lat2))); $sinU1 = \sin($U1); $cosU1 = \cos($U1); $sinU2 = \sin($U2); $cosU2 = \cos($U2); $lambda = $L; $iterLimit = 100; do { $sinLambda = \sin($lambda); $cosLambda = \cos($lambda); $sinSigma = \sqrt(($cosU2 * $sinLambda) * ($cosU2 * $sinLambda) + ($cosU1 * $sinU2 - $sinU1 * $cosU2 * $cosLambda) * ($cosU1 * $sinU2 - $sinU1 * $cosU2 * $cosLambda)); if (0.0 === $sinSigma) { return new Distance(0); // co-incident points } $cosSigma = $sinU1 * $sinU2 + $cosU1 * $cosU2 * $cosLambda; $sigma = \atan2($sinSigma, $cosSigma); $sinAlpha = $cosU1 * $cosU2 * $sinLambda / $sinSigma; $cosSqAlpha = (float) 1 - $sinAlpha * $sinAlpha; if (0.0 !== $cosSqAlpha) { $cos2SigmaM = $cosSigma - 2 * $sinU1 * $sinU2 / $cosSqAlpha; } else { $cos2SigmaM = 0.0; // Equatorial line } $C = $f / 16 * $cosSqAlpha * (4 + $f * (4 - 3 * $cosSqAlpha)); $lambdaP = $lambda; $lambda = $L + (1 - $C) * $f * $sinAlpha * ($sigma + $C * $sinSigma * ($cos2SigmaM + $C * $cosSigma * (-1 + 2 * $cos2SigmaM * $cos2SigmaM))); } while (\abs($lambda - $lambdaP) > 1e-12 && --$iterLimit > 0); if ($iterLimit === 0) { throw new Exception\RuntimeException('Vincenty formula failed to converge.'); } $uSq = $cosSqAlpha * ($a * $a - $b * $b) / ($b * $b); $A = 1 + $uSq / 16384 * (4096 + $uSq * (-768 + $uSq * (320 - 175 * $uSq))); $B = $uSq / 1024 * (256 + $uSq * (-128 + $uSq * (74 - 47 * $uSq))); $deltaSigma = $B * $sinSigma * ($cos2SigmaM + $B / 4 * ($cosSigma * (-1 + 2 * $cos2SigmaM * $cos2SigmaM) - $B / 6 * $cos2SigmaM * (-3 + 4 * $sinSigma * $sinSigma) * (-3 + 4 * $cos2SigmaM * $cos2SigmaM))); $s = $b * $A * ($sigma - $deltaSigma); return new Distance($s); }
[ "public", "function", "distanceVincenty", "(", "Position", "$", "from", ",", "Position", "$", "to", ")", ":", "Distance", "{", "$", "lat1", "=", "$", "from", "->", "latitude", "(", ")", ";", "$", "lng1", "=", "$", "from", "->", "longitude", "(", ")",...
Calculates the geodetic distance between two points using the Vincenty inverse formula for ellipsoids. @see http://en.wikipedia.org/wiki/Vincenty%27s_formulae @see http://www.movable-type.co.uk/scripts/latlong-vincenty.html
[ "Calculates", "the", "geodetic", "distance", "between", "two", "points", "using", "the", "Vincenty", "inverse", "formula", "for", "ellipsoids", "." ]
train
https://github.com/jsor/geokit/blob/52eb6d4f497c449e9f7c0fe0b6a0d5a35dec1c2e/src/Math.php#L42-L105
jsor/geokit
src/Math.php
Math.heading
public function heading(Position $from, Position $to): float { $lat1 = $from->latitude(); $lng1 = $from->longitude(); $lat2 = $to->latitude(); $lng2 = $to->longitude(); $lat1 = \deg2rad($lat1); $lat2 = \deg2rad($lat2); $dLon = \deg2rad($lng2 - $lng1); $y = \sin($dLon) * \cos($lat2); $x = \cos($lat1) * \sin($lat2) - \sin($lat1) * \cos($lat2) * \cos($dLon); $heading = \atan2($y, $x); return \fmod(\rad2deg($heading) + 360, 360); }
php
public function heading(Position $from, Position $to): float { $lat1 = $from->latitude(); $lng1 = $from->longitude(); $lat2 = $to->latitude(); $lng2 = $to->longitude(); $lat1 = \deg2rad($lat1); $lat2 = \deg2rad($lat2); $dLon = \deg2rad($lng2 - $lng1); $y = \sin($dLon) * \cos($lat2); $x = \cos($lat1) * \sin($lat2) - \sin($lat1) * \cos($lat2) * \cos($dLon); $heading = \atan2($y, $x); return \fmod(\rad2deg($heading) + 360, 360); }
[ "public", "function", "heading", "(", "Position", "$", "from", ",", "Position", "$", "to", ")", ":", "float", "{", "$", "lat1", "=", "$", "from", "->", "latitude", "(", ")", ";", "$", "lng1", "=", "$", "from", "->", "longitude", "(", ")", ";", "$...
Calculates the (initial) heading from the first point to the second point in degrees.
[ "Calculates", "the", "(", "initial", ")", "heading", "from", "the", "first", "point", "to", "the", "second", "point", "in", "degrees", "." ]
train
https://github.com/jsor/geokit/blob/52eb6d4f497c449e9f7c0fe0b6a0d5a35dec1c2e/src/Math.php#L111-L129
jsor/geokit
src/Math.php
Math.midpoint
public function midpoint(Position $from, Position $to): Position { $lat1 = $from->latitude(); $lng1 = $from->longitude(); $lat2 = $to->latitude(); $lng2 = $to->longitude(); $lat1 = \deg2rad($lat1); $lat2 = \deg2rad($lat2); $dLon = \deg2rad($lng2 - $lng1); $Bx = \cos($lat2) * \cos($dLon); $By = \cos($lat2) * \sin($dLon); $lat3 = \atan2( \sin($lat1) + \sin($lat2), \sqrt((\cos($lat1) + $Bx) * (\cos($lat1) + $Bx) + $By * $By) ); $lon3 = \deg2rad($lng1) + \atan2($By, \cos($lat1) + $Bx); return new Position(\rad2deg($lon3), \rad2deg($lat3)); }
php
public function midpoint(Position $from, Position $to): Position { $lat1 = $from->latitude(); $lng1 = $from->longitude(); $lat2 = $to->latitude(); $lng2 = $to->longitude(); $lat1 = \deg2rad($lat1); $lat2 = \deg2rad($lat2); $dLon = \deg2rad($lng2 - $lng1); $Bx = \cos($lat2) * \cos($dLon); $By = \cos($lat2) * \sin($dLon); $lat3 = \atan2( \sin($lat1) + \sin($lat2), \sqrt((\cos($lat1) + $Bx) * (\cos($lat1) + $Bx) + $By * $By) ); $lon3 = \deg2rad($lng1) + \atan2($By, \cos($lat1) + $Bx); return new Position(\rad2deg($lon3), \rad2deg($lat3)); }
[ "public", "function", "midpoint", "(", "Position", "$", "from", ",", "Position", "$", "to", ")", ":", "Position", "{", "$", "lat1", "=", "$", "from", "->", "latitude", "(", ")", ";", "$", "lng1", "=", "$", "from", "->", "longitude", "(", ")", ";", ...
Calculates an intermediate point on the geodesic between the two given points. @see http://www.movable-type.co.uk/scripts/latlong.html
[ "Calculates", "an", "intermediate", "point", "on", "the", "geodesic", "between", "the", "two", "given", "points", "." ]
train
https://github.com/jsor/geokit/blob/52eb6d4f497c449e9f7c0fe0b6a0d5a35dec1c2e/src/Math.php#L137-L158
jsor/geokit
src/Math.php
Math.endpoint
public function endpoint(Position $start, float $heading, Distance $distance): Position { $lat = \deg2rad($start->latitude()); $lng = \deg2rad($start->longitude()); $angularDistance = $distance->meters() / Earth::RADIUS; $heading = \deg2rad($heading); $lat2 = \asin( \sin($lat) * \cos($angularDistance) + \cos($lat) * \sin($angularDistance) * \cos($heading) ); $lon2 = $lng + \atan2( \sin($heading) * \sin($angularDistance) * \cos($lat), \cos($angularDistance) - \sin($lat) * \sin($lat2) ); return new Position(\rad2deg($lon2), \rad2deg($lat2)); }
php
public function endpoint(Position $start, float $heading, Distance $distance): Position { $lat = \deg2rad($start->latitude()); $lng = \deg2rad($start->longitude()); $angularDistance = $distance->meters() / Earth::RADIUS; $heading = \deg2rad($heading); $lat2 = \asin( \sin($lat) * \cos($angularDistance) + \cos($lat) * \sin($angularDistance) * \cos($heading) ); $lon2 = $lng + \atan2( \sin($heading) * \sin($angularDistance) * \cos($lat), \cos($angularDistance) - \sin($lat) * \sin($lat2) ); return new Position(\rad2deg($lon2), \rad2deg($lat2)); }
[ "public", "function", "endpoint", "(", "Position", "$", "start", ",", "float", "$", "heading", ",", "Distance", "$", "distance", ")", ":", "Position", "{", "$", "lat", "=", "\\", "deg2rad", "(", "$", "start", "->", "latitude", "(", ")", ")", ";", "$"...
Calculates the destination point along a geodesic, given an initial heading and distance, from the given start point. @see http://www.movable-type.co.uk/scripts/latlong.html
[ "Calculates", "the", "destination", "point", "along", "a", "geodesic", "given", "an", "initial", "heading", "and", "distance", "from", "the", "given", "start", "point", "." ]
train
https://github.com/jsor/geokit/blob/52eb6d4f497c449e9f7c0fe0b6a0d5a35dec1c2e/src/Math.php#L166-L184
sebastian-lenz/craft-linkfield
src/models/Link.php
Link.getLink
public function getLink($attributesOrText = null) { $text = $this->getText(); $extraAttributes = null; if (is_string($attributesOrText)) { // If a string is passed, override the text component $text = $attributesOrText; } elseif (is_array($attributesOrText)) { // If an array is passed, use it as tag attributes $extraAttributes = $attributesOrText; if (array_key_exists('text', $extraAttributes)) { $text = $extraAttributes['text']; unset($extraAttributes['text']); } } $attributes = $this->getRawLinkAttributes($extraAttributes); if (is_null($attributes) || is_null($text)) { return null; } return Template::raw(Html::tag('a', $text, $attributes)); }
php
public function getLink($attributesOrText = null) { $text = $this->getText(); $extraAttributes = null; if (is_string($attributesOrText)) { // If a string is passed, override the text component $text = $attributesOrText; } elseif (is_array($attributesOrText)) { // If an array is passed, use it as tag attributes $extraAttributes = $attributesOrText; if (array_key_exists('text', $extraAttributes)) { $text = $extraAttributes['text']; unset($extraAttributes['text']); } } $attributes = $this->getRawLinkAttributes($extraAttributes); if (is_null($attributes) || is_null($text)) { return null; } return Template::raw(Html::tag('a', $text, $attributes)); }
[ "public", "function", "getLink", "(", "$", "attributesOrText", "=", "null", ")", "{", "$", "text", "=", "$", "this", "->", "getText", "(", ")", ";", "$", "extraAttributes", "=", "null", ";", "if", "(", "is_string", "(", "$", "attributesOrText", ")", ")...
Renders a complete link tag. You can either pass the desired content of the link as a string, e.g. ``` {{ entry.linkField.link('Imprint') }} ``` or you can pass an array of attributes which can contain the key `text` which will be used as the link text. When doing this you can also override the default attributes `href` and `target` if you want to. ``` {{ entry.linkField.link({ class: 'my-link-class', text: 'Imprint', }) }} ``` @param array|string|null $attributesOrText @return null|\Twig_Markup
[ "Renders", "a", "complete", "link", "tag", "." ]
train
https://github.com/sebastian-lenz/craft-linkfield/blob/136c7fcc221d8f53ef903be215f2929a19218a69/src/models/Link.php#L186-L209
sebastian-lenz/craft-linkfield
src/models/Link.php
Link.getLinkAttributes
public function getLinkAttributes($extraAttributes = null) { $attributes = $this->getRawLinkAttributes($extraAttributes); return Template::raw(is_null($attributes) ? '' : Html::renderTagAttributes($attributes) ); }
php
public function getLinkAttributes($extraAttributes = null) { $attributes = $this->getRawLinkAttributes($extraAttributes); return Template::raw(is_null($attributes) ? '' : Html::renderTagAttributes($attributes) ); }
[ "public", "function", "getLinkAttributes", "(", "$", "extraAttributes", "=", "null", ")", "{", "$", "attributes", "=", "$", "this", "->", "getRawLinkAttributes", "(", "$", "extraAttributes", ")", ";", "return", "Template", "::", "raw", "(", "is_null", "(", "...
Return the attributes of this link as a rendered html string. @param array|null $extraAttributes @return \Twig_Markup
[ "Return", "the", "attributes", "of", "this", "link", "as", "a", "rendered", "html", "string", "." ]
train
https://github.com/sebastian-lenz/craft-linkfield/blob/136c7fcc221d8f53ef903be215f2929a19218a69/src/models/Link.php#L217-L223
sebastian-lenz/craft-linkfield
src/models/Link.php
Link.getRawLinkAttributes
public function getRawLinkAttributes($extraAttributes = null) { $url = $this->getUrl(); if (is_null($url)) { return null; } $attributes = [ 'href' => $url ]; $ariaLabel = $this->getAriaLabel(); if (!empty($ariaLabel)) { $attributes['arial-label'] = $ariaLabel; } $target = $this->getTarget(); if (!empty($target)) { $attributes['target'] = $target; if ($target === '_blank' && $this->linkField->autoNoReferrer) { $attributes['rel'] = 'noopener noreferrer'; } } $title = $this->getTitle(); if (!empty($title)) { $attributes['title'] = $title; } if (is_array($extraAttributes)) { $attributes = $extraAttributes + $attributes; } return $attributes; }
php
public function getRawLinkAttributes($extraAttributes = null) { $url = $this->getUrl(); if (is_null($url)) { return null; } $attributes = [ 'href' => $url ]; $ariaLabel = $this->getAriaLabel(); if (!empty($ariaLabel)) { $attributes['arial-label'] = $ariaLabel; } $target = $this->getTarget(); if (!empty($target)) { $attributes['target'] = $target; if ($target === '_blank' && $this->linkField->autoNoReferrer) { $attributes['rel'] = 'noopener noreferrer'; } } $title = $this->getTitle(); if (!empty($title)) { $attributes['title'] = $title; } if (is_array($extraAttributes)) { $attributes = $extraAttributes + $attributes; } return $attributes; }
[ "public", "function", "getRawLinkAttributes", "(", "$", "extraAttributes", "=", "null", ")", "{", "$", "url", "=", "$", "this", "->", "getUrl", "(", ")", ";", "if", "(", "is_null", "(", "$", "url", ")", ")", "{", "return", "null", ";", "}", "$", "a...
Return an array defining the common link attributes (`href`, `target` `title` and `arial-label`) of this link. Returns NULL if this link has no target url. @param null|array $extraAttributes @return array|null
[ "Return", "an", "array", "defining", "the", "common", "link", "attributes", "(", "href", "target", "title", "and", "arial", "-", "label", ")", "of", "this", "link", ".", "Returns", "NULL", "if", "this", "link", "has", "no", "target", "url", "." ]
train
https://github.com/sebastian-lenz/craft-linkfield/blob/136c7fcc221d8f53ef903be215f2929a19218a69/src/models/Link.php#L270-L302
sebastian-lenz/craft-linkfield
src/models/Link.php
Link.getCustomText
public function getCustomText($fallbackText = "Learn More") { if ($this->getAllowCustomText() && !empty($this->customText)) { return $this->customText; } $defaultText = $this->getDefaultText(); return empty($defaultText) ? $fallbackText : $defaultText; }
php
public function getCustomText($fallbackText = "Learn More") { if ($this->getAllowCustomText() && !empty($this->customText)) { return $this->customText; } $defaultText = $this->getDefaultText(); return empty($defaultText) ? $fallbackText : $defaultText; }
[ "public", "function", "getCustomText", "(", "$", "fallbackText", "=", "\"Learn More\"", ")", "{", "if", "(", "$", "this", "->", "getAllowCustomText", "(", ")", "&&", "!", "empty", "(", "$", "this", "->", "customText", ")", ")", "{", "return", "$", "this"...
Try to use provided custom text or field default. Allows user to specify a fallback string if the custom text and default are not set. @param string $fallbackText @return string
[ "Try", "to", "use", "provided", "custom", "text", "or", "field", "default", ".", "Allows", "user", "to", "specify", "a", "fallback", "string", "if", "the", "custom", "text", "and", "default", "are", "not", "set", "." ]
train
https://github.com/sebastian-lenz/craft-linkfield/blob/136c7fcc221d8f53ef903be215f2929a19218a69/src/models/Link.php#L347-L356
spatie/laravel-slack-slash-command
src/AttachmentAction.php
AttachmentAction.setConfirmation
public function setConfirmation(array $confirmation) { if (! array_key_exists('text', $confirmation)) { throw InvalidConfirmationHash::missingTextField(); } $this->confirmation = $confirmation; return $this; }
php
public function setConfirmation(array $confirmation) { if (! array_key_exists('text', $confirmation)) { throw InvalidConfirmationHash::missingTextField(); } $this->confirmation = $confirmation; return $this; }
[ "public", "function", "setConfirmation", "(", "array", "$", "confirmation", ")", "{", "if", "(", "!", "array_key_exists", "(", "'text'", ",", "$", "confirmation", ")", ")", "{", "throw", "InvalidConfirmationHash", "::", "missingTextField", "(", ")", ";", "}", ...
Sets the confirmation hash for the action. @param array $confirmation @return \Spatie\SlashCommand\AttachmentAction @throws \Spatie\SlashCommand\Exceptions\InvalidConfirmationHash
[ "Sets", "the", "confirmation", "hash", "for", "the", "action", "." ]
train
https://github.com/spatie/laravel-slack-slash-command/blob/010aaa32c5cfe90bd01d06204f61473660160169/src/AttachmentAction.php#L146-L155
spatie/laravel-slack-slash-command
src/AttachmentAction.php
AttachmentAction.toArray
public function toArray(): array { return [ 'name' => $this->name, 'text' => $this->text, 'type' => $this->type, 'value' => $this->value, 'style' => $this->style, 'confirm' => $this->confirmation, ]; }
php
public function toArray(): array { return [ 'name' => $this->name, 'text' => $this->text, 'type' => $this->type, 'value' => $this->value, 'style' => $this->style, 'confirm' => $this->confirmation, ]; }
[ "public", "function", "toArray", "(", ")", ":", "array", "{", "return", "[", "'name'", "=>", "$", "this", "->", "name", ",", "'text'", "=>", "$", "this", "->", "text", ",", "'type'", "=>", "$", "this", "->", "type", ",", "'value'", "=>", "$", "this...
Convert this action to its array representation. @return array
[ "Convert", "this", "action", "to", "its", "array", "representation", "." ]
train
https://github.com/spatie/laravel-slack-slash-command/blob/010aaa32c5cfe90bd01d06204f61473660160169/src/AttachmentAction.php#L162-L172
spatie/laravel-slack-slash-command
src/Handlers/CatchAll.php
CatchAll.handle
public function handle(Request $request): Response { $response = $this->respondToSlack("I did not recognize this command: `/{$request->command} {$request->text}`"); list($command) = explode(' ', $this->request->text); $alternativeHandlers = $this->findAlternativeHandlers($command); if ($alternativeHandlers->count()) { $response->withAttachment($this->getCommandListAttachment($alternativeHandlers)); } if ($this->containsHelpHandler($alternativeHandlers)) { $response->withAttachment(Attachment::create() ->setText("For all available commands, try `/{$request->command} help`") ); } return $response; }
php
public function handle(Request $request): Response { $response = $this->respondToSlack("I did not recognize this command: `/{$request->command} {$request->text}`"); list($command) = explode(' ', $this->request->text); $alternativeHandlers = $this->findAlternativeHandlers($command); if ($alternativeHandlers->count()) { $response->withAttachment($this->getCommandListAttachment($alternativeHandlers)); } if ($this->containsHelpHandler($alternativeHandlers)) { $response->withAttachment(Attachment::create() ->setText("For all available commands, try `/{$request->command} help`") ); } return $response; }
[ "public", "function", "handle", "(", "Request", "$", "request", ")", ":", "Response", "{", "$", "response", "=", "$", "this", "->", "respondToSlack", "(", "\"I did not recognize this command: `/{$request->command} {$request->text}`\"", ")", ";", "list", "(", "$", "c...
Handle the given request. Remember that Slack expects a response within three seconds after the slash command was issued. If there is more time needed, dispatch a job. @param \Spatie\SlashCommand\Request $request @return \Spatie\SlashCommand\Response
[ "Handle", "the", "given", "request", ".", "Remember", "that", "Slack", "expects", "a", "response", "within", "three", "seconds", "after", "the", "slash", "command", "was", "issued", ".", "If", "there", "is", "more", "time", "needed", "dispatch", "a", "job", ...
train
https://github.com/spatie/laravel-slack-slash-command/blob/010aaa32c5cfe90bd01d06204f61473660160169/src/Handlers/CatchAll.php#L36-L55
spatie/laravel-slack-slash-command
src/SlashCommandServiceProvider.php
SlashCommandServiceProvider.boot
public function boot() { $this->publishes([ __DIR__.'/../config/laravel-slack-slash-command.php' => config_path('laravel-slack-slash-command.php'), ], 'config'); $this->app['router']->post(config('laravel-slack-slash-command')['url'], Controller::class.'@getResponse'); }
php
public function boot() { $this->publishes([ __DIR__.'/../config/laravel-slack-slash-command.php' => config_path('laravel-slack-slash-command.php'), ], 'config'); $this->app['router']->post(config('laravel-slack-slash-command')['url'], Controller::class.'@getResponse'); }
[ "public", "function", "boot", "(", ")", "{", "$", "this", "->", "publishes", "(", "[", "__DIR__", ".", "'/../config/laravel-slack-slash-command.php'", "=>", "config_path", "(", "'laravel-slack-slash-command.php'", ")", ",", "]", ",", "'config'", ")", ";", "$", "...
Bootstrap the application services.
[ "Bootstrap", "the", "application", "services", "." ]
train
https://github.com/spatie/laravel-slack-slash-command/blob/010aaa32c5cfe90bd01d06204f61473660160169/src/SlashCommandServiceProvider.php#L12-L19
spatie/laravel-slack-slash-command
src/Attachment.php
Attachment.addField
public function addField($field) { if (! is_array($field) && ! $field instanceof AttachmentField) { throw FieldCannotBeAdded::invalidType(); } if (is_array($field)) { $title = array_keys($field)[0]; $value = $field[$title]; $field = AttachmentField::create($title, $value); } $this->fields->push($field); return $this; }
php
public function addField($field) { if (! is_array($field) && ! $field instanceof AttachmentField) { throw FieldCannotBeAdded::invalidType(); } if (is_array($field)) { $title = array_keys($field)[0]; $value = $field[$title]; $field = AttachmentField::create($title, $value); } $this->fields->push($field); return $this; }
[ "public", "function", "addField", "(", "$", "field", ")", "{", "if", "(", "!", "is_array", "(", "$", "field", ")", "&&", "!", "$", "field", "instanceof", "AttachmentField", ")", "{", "throw", "FieldCannotBeAdded", "::", "invalidType", "(", ")", ";", "}",...
Add a field to the attachment. @param \Spatie\SlashCommand\AttachmentField|array $field @return $this @throws \Spatie\SlashCommand\Exceptions\FieldCannotBeAdded
[ "Add", "a", "field", "to", "the", "attachment", "." ]
train
https://github.com/spatie/laravel-slack-slash-command/blob/010aaa32c5cfe90bd01d06204f61473660160169/src/Attachment.php#L385-L401
spatie/laravel-slack-slash-command
src/Attachment.php
Attachment.addFields
public function addFields(array $fields) { collect($fields)->each(function ($field, $key) { if (! $field instanceof AttachmentField) { $field = [$key => $field]; } $this->addField($field); }); return $this; }
php
public function addFields(array $fields) { collect($fields)->each(function ($field, $key) { if (! $field instanceof AttachmentField) { $field = [$key => $field]; } $this->addField($field); }); return $this; }
[ "public", "function", "addFields", "(", "array", "$", "fields", ")", "{", "collect", "(", "$", "fields", ")", "->", "each", "(", "function", "(", "$", "field", ",", "$", "key", ")", "{", "if", "(", "!", "$", "field", "instanceof", "AttachmentField", ...
Add the fields for the attachment. @param array $fields @return $this
[ "Add", "the", "fields", "for", "the", "attachment", "." ]
train
https://github.com/spatie/laravel-slack-slash-command/blob/010aaa32c5cfe90bd01d06204f61473660160169/src/Attachment.php#L410-L421
spatie/laravel-slack-slash-command
src/Attachment.php
Attachment.addAction
public function addAction($action) { if (! is_array($action) && ! $action instanceof AttachmentAction) { throw ActionCannotBeAdded::invalidType(); } if (is_array($action)) { $name = $action['name']; $text = $action['text']; $type = $action['type']; $action = AttachmentAction::create($name, $text, $type); } $this->actions->push($action); return $this; }
php
public function addAction($action) { if (! is_array($action) && ! $action instanceof AttachmentAction) { throw ActionCannotBeAdded::invalidType(); } if (is_array($action)) { $name = $action['name']; $text = $action['text']; $type = $action['type']; $action = AttachmentAction::create($name, $text, $type); } $this->actions->push($action); return $this; }
[ "public", "function", "addAction", "(", "$", "action", ")", "{", "if", "(", "!", "is_array", "(", "$", "action", ")", "&&", "!", "$", "action", "instanceof", "AttachmentAction", ")", "{", "throw", "ActionCannotBeAdded", "::", "invalidType", "(", ")", ";", ...
@param \Spatie\SlashCommand\AttachmentAction|array $action @return $this @throws \Spatie\SlashCommand\Exceptions\ActionCannotBeAdded
[ "@param", "\\", "Spatie", "\\", "SlashCommand", "\\", "AttachmentAction|array", "$action" ]
train
https://github.com/spatie/laravel-slack-slash-command/blob/010aaa32c5cfe90bd01d06204f61473660160169/src/Attachment.php#L457-L474
spatie/laravel-slack-slash-command
src/Attachment.php
Attachment.addActions
public function addActions(array $actions) { collect($actions)->each(function ($action) { $this->addAction($action); }); return $this; }
php
public function addActions(array $actions) { collect($actions)->each(function ($action) { $this->addAction($action); }); return $this; }
[ "public", "function", "addActions", "(", "array", "$", "actions", ")", "{", "collect", "(", "$", "actions", ")", "->", "each", "(", "function", "(", "$", "action", ")", "{", "$", "this", "->", "addAction", "(", "$", "action", ")", ";", "}", ")", ";...
Add the actions for the attachment. @param array $actions @return $this
[ "Add", "the", "actions", "for", "the", "attachment", "." ]
train
https://github.com/spatie/laravel-slack-slash-command/blob/010aaa32c5cfe90bd01d06204f61473660160169/src/Attachment.php#L483-L490
spatie/laravel-slack-slash-command
src/Attachment.php
Attachment.toArray
public function toArray() { return [ 'fallback' => $this->fallback, 'text' => $this->text, 'pretext' => $this->preText, 'color' => $this->color, 'footer' => $this->footer, 'mrkdwn_in' => $this->useMarkdown ? ['text', 'pretext', 'footer'] : [], 'footer_icon' => $this->footerIcon, 'ts' => $this->timestamp ? $this->timestamp->getTimestamp() : null, 'image_url' => $this->imageUrl, 'thumb_url' => $this->thumbUrl, 'title' => $this->title, 'title_link' => $this->titleLink, 'author_name' => $this->authorName, 'author_link' => $this->authorLink, 'author_icon' => $this->authorIcon, 'callback_id' => $this->callbackId, 'fields' => $this->fields->map(function (AttachmentField $field) { return $field->toArray(); })->toArray(), 'actions' => $this->actions->map(function (AttachmentAction $action) { return $action->toArray(); })->toArray(), ]; }
php
public function toArray() { return [ 'fallback' => $this->fallback, 'text' => $this->text, 'pretext' => $this->preText, 'color' => $this->color, 'footer' => $this->footer, 'mrkdwn_in' => $this->useMarkdown ? ['text', 'pretext', 'footer'] : [], 'footer_icon' => $this->footerIcon, 'ts' => $this->timestamp ? $this->timestamp->getTimestamp() : null, 'image_url' => $this->imageUrl, 'thumb_url' => $this->thumbUrl, 'title' => $this->title, 'title_link' => $this->titleLink, 'author_name' => $this->authorName, 'author_link' => $this->authorLink, 'author_icon' => $this->authorIcon, 'callback_id' => $this->callbackId, 'fields' => $this->fields->map(function (AttachmentField $field) { return $field->toArray(); })->toArray(), 'actions' => $this->actions->map(function (AttachmentAction $action) { return $action->toArray(); })->toArray(), ]; }
[ "public", "function", "toArray", "(", ")", "{", "return", "[", "'fallback'", "=>", "$", "this", "->", "fallback", ",", "'text'", "=>", "$", "this", "->", "text", ",", "'pretext'", "=>", "$", "this", "->", "preText", ",", "'color'", "=>", "$", "this", ...
Convert this attachment to its array representation. @return array
[ "Convert", "this", "attachment", "to", "its", "array", "representation", "." ]
train
https://github.com/spatie/laravel-slack-slash-command/blob/010aaa32c5cfe90bd01d06204f61473660160169/src/Attachment.php#L525-L551
spatie/laravel-slack-slash-command
src/Handlers/Help.php
Help.handle
public function handle(Request $request): Response { $handlers = $this->findAvailableHandlers(); if ($command = $this->getArgument('command')) { return $this->displayHelpForCommand($handlers, $command); } return $this->displayListOfAllCommands($handlers); }
php
public function handle(Request $request): Response { $handlers = $this->findAvailableHandlers(); if ($command = $this->getArgument('command')) { return $this->displayHelpForCommand($handlers, $command); } return $this->displayListOfAllCommands($handlers); }
[ "public", "function", "handle", "(", "Request", "$", "request", ")", ":", "Response", "{", "$", "handlers", "=", "$", "this", "->", "findAvailableHandlers", "(", ")", ";", "if", "(", "$", "command", "=", "$", "this", "->", "getArgument", "(", "'command'"...
Handle the given request. @param \Spatie\SlashCommand\Request $request @return \Spatie\SlashCommand\Response
[ "Handle", "the", "given", "request", "." ]
train
https://github.com/spatie/laravel-slack-slash-command/blob/010aaa32c5cfe90bd01d06204f61473660160169/src/Handlers/Help.php#L26-L35
spatie/laravel-slack-slash-command
src/Handlers/Help.php
Help.findAvailableHandlers
protected function findAvailableHandlers(): Collection { return collect(config('laravel-slack-slash-command.handlers')) ->map(function (string $handlerClassName) { return new $handlerClassName($this->request); }) ->filter(function (HandlesSlashCommand $handler) { return $handler instanceof SignatureHandler; }) ->filter(function (SignatureHandler $handler) { $signatureParts = new SignatureParts($handler->getSignature()); return Str::is($signatureParts->getSlashCommandName(), $this->request->command); }); }
php
protected function findAvailableHandlers(): Collection { return collect(config('laravel-slack-slash-command.handlers')) ->map(function (string $handlerClassName) { return new $handlerClassName($this->request); }) ->filter(function (HandlesSlashCommand $handler) { return $handler instanceof SignatureHandler; }) ->filter(function (SignatureHandler $handler) { $signatureParts = new SignatureParts($handler->getSignature()); return Str::is($signatureParts->getSlashCommandName(), $this->request->command); }); }
[ "protected", "function", "findAvailableHandlers", "(", ")", ":", "Collection", "{", "return", "collect", "(", "config", "(", "'laravel-slack-slash-command.handlers'", ")", ")", "->", "map", "(", "function", "(", "string", "$", "handlerClassName", ")", "{", "return...
Find all handlers that are available for the current SlashCommand and have a signature. @return Collection|SignatureHandler[]
[ "Find", "all", "handlers", "that", "are", "available", "for", "the", "current", "SlashCommand", "and", "have", "a", "signature", "." ]
train
https://github.com/spatie/laravel-slack-slash-command/blob/010aaa32c5cfe90bd01d06204f61473660160169/src/Handlers/Help.php#L43-L57
spatie/laravel-slack-slash-command
src/Handlers/Help.php
Help.displayHelpForCommand
protected function displayHelpForCommand(Collection $handlers, string $command): Response { $helpRequest = clone $this->request; $helpRequest->text = $command; /** @var \Spatie\SlashCommand\Handlers $handler */ $handler = $handlers->filter(function (HandlesSlashCommand $handler) use ($helpRequest) { return $handler->canHandle($helpRequest); }) ->first(); $field = AttachmentField::create($handler->getFullCommand(), $handler->getHelpDescription()); return $this->respondToSlack('') ->withAttachment( Attachment::create()->addField($field) ); }
php
protected function displayHelpForCommand(Collection $handlers, string $command): Response { $helpRequest = clone $this->request; $helpRequest->text = $command; /** @var \Spatie\SlashCommand\Handlers $handler */ $handler = $handlers->filter(function (HandlesSlashCommand $handler) use ($helpRequest) { return $handler->canHandle($helpRequest); }) ->first(); $field = AttachmentField::create($handler->getFullCommand(), $handler->getHelpDescription()); return $this->respondToSlack('') ->withAttachment( Attachment::create()->addField($field) ); }
[ "protected", "function", "displayHelpForCommand", "(", "Collection", "$", "handlers", ",", "string", "$", "command", ")", ":", "Response", "{", "$", "helpRequest", "=", "clone", "$", "this", "->", "request", ";", "$", "helpRequest", "->", "text", "=", "$", ...
Show the help information for a single SignatureHandler. @param Collection $handlers @param string $command @return Response
[ "Show", "the", "help", "information", "for", "a", "single", "SignatureHandler", "." ]
train
https://github.com/spatie/laravel-slack-slash-command/blob/010aaa32c5cfe90bd01d06204f61473660160169/src/Handlers/Help.php#L66-L84
spatie/laravel-slack-slash-command
src/Handlers/Help.php
Help.displayListOfAllCommands
protected function displayListOfAllCommands(Collection $handlers): Response { $attachmentFields = $handlers ->sort(function (SignatureHandler $handlerA, SignatureHandler $handlerB) { return strcmp($handlerA->getFullCommand(), $handlerB->getFullCommand()); }) ->map(function (SignatureHandler $handler) { return AttachmentField::create($handler->getFullCommand(), $handler->getDescription()); }) ->all(); return $this->respondToSlack('Available commands:') ->withAttachment( Attachment::create() ->setColor('good') ->setFields($attachmentFields) ); }
php
protected function displayListOfAllCommands(Collection $handlers): Response { $attachmentFields = $handlers ->sort(function (SignatureHandler $handlerA, SignatureHandler $handlerB) { return strcmp($handlerA->getFullCommand(), $handlerB->getFullCommand()); }) ->map(function (SignatureHandler $handler) { return AttachmentField::create($handler->getFullCommand(), $handler->getDescription()); }) ->all(); return $this->respondToSlack('Available commands:') ->withAttachment( Attachment::create() ->setColor('good') ->setFields($attachmentFields) ); }
[ "protected", "function", "displayListOfAllCommands", "(", "Collection", "$", "handlers", ")", ":", "Response", "{", "$", "attachmentFields", "=", "$", "handlers", "->", "sort", "(", "function", "(", "SignatureHandler", "$", "handlerA", ",", "SignatureHandler", "$"...
Show a list of all available handlers. @param Collection $handlers @return Response
[ "Show", "a", "list", "of", "all", "available", "handlers", "." ]
train
https://github.com/spatie/laravel-slack-slash-command/blob/010aaa32c5cfe90bd01d06204f61473660160169/src/Handlers/Help.php#L92-L109
spatie/laravel-slack-slash-command
src/Response.php
Response.withAttachments
public function withAttachments($attachments) { if (! is_array($attachments)) { $attachments = [$attachments]; } foreach ($attachments as $attachment) { $this->withAttachment($attachment); } return $this; }
php
public function withAttachments($attachments) { if (! is_array($attachments)) { $attachments = [$attachments]; } foreach ($attachments as $attachment) { $this->withAttachment($attachment); } return $this; }
[ "public", "function", "withAttachments", "(", "$", "attachments", ")", "{", "if", "(", "!", "is_array", "(", "$", "attachments", ")", ")", "{", "$", "attachments", "=", "[", "$", "attachments", "]", ";", "}", "foreach", "(", "$", "attachments", "as", "...
@param array|\Spatie\SlashCommand\Attachment $attachments @return $this
[ "@param", "array|", "\\", "Spatie", "\\", "SlashCommand", "\\", "Attachment", "$attachments" ]
train
https://github.com/spatie/laravel-slack-slash-command/blob/010aaa32c5cfe90bd01d06204f61473660160169/src/Response.php#L98-L109
spatie/laravel-slack-slash-command
src/Response.php
Response.displayResponseToEveryoneOnChannel
public function displayResponseToEveryoneOnChannel(string $channelName = '') { $this->responseType = 'in_channel'; if ($channelName !== '') { $this->onChannel($channelName); } return $this; }
php
public function displayResponseToEveryoneOnChannel(string $channelName = '') { $this->responseType = 'in_channel'; if ($channelName !== '') { $this->onChannel($channelName); } return $this; }
[ "public", "function", "displayResponseToEveryoneOnChannel", "(", "string", "$", "channelName", "=", "''", ")", "{", "$", "this", "->", "responseType", "=", "'in_channel'", ";", "if", "(", "$", "channelName", "!==", "''", ")", "{", "$", "this", "->", "onChann...
@param string $channelName @return $this
[ "@param", "string", "$channelName" ]
train
https://github.com/spatie/laravel-slack-slash-command/blob/010aaa32c5cfe90bd01d06204f61473660160169/src/Response.php#L116-L125
spatie/laravel-slack-slash-command
src/Handlers/SignatureHandler.php
SignatureHandler.getHelpDescription
public function getHelpDescription(): string { $inputDefinition = $this->inputDefinition; $output = new BufferedOutput(); $name = $this->getFullCommand(); $command = (new Command($name)) ->setDefinition($inputDefinition) ->setDescription($this->getDescription()); $descriptor = new DescriptorHelper(); $descriptor->describe($output, $command); return $output->fetch(); }
php
public function getHelpDescription(): string { $inputDefinition = $this->inputDefinition; $output = new BufferedOutput(); $name = $this->getFullCommand(); $command = (new Command($name)) ->setDefinition($inputDefinition) ->setDescription($this->getDescription()); $descriptor = new DescriptorHelper(); $descriptor->describe($output, $command); return $output->fetch(); }
[ "public", "function", "getHelpDescription", "(", ")", ":", "string", "{", "$", "inputDefinition", "=", "$", "this", "->", "inputDefinition", ";", "$", "output", "=", "new", "BufferedOutput", "(", ")", ";", "$", "name", "=", "$", "this", "->", "getFullComma...
Get the usage description, including parameters and options. @return string
[ "Get", "the", "usage", "description", "including", "parameters", "and", "options", "." ]
train
https://github.com/spatie/laravel-slack-slash-command/blob/010aaa32c5cfe90bd01d06204f61473660160169/src/Handlers/SignatureHandler.php#L101-L116
spatie/laravel-slack-slash-command
src/Controller.php
Controller.determineHandler
protected function determineHandler() { $handler = collect($this->config->get('handlers')) ->map(function (string $handlerClassName) { if (! class_exists($handlerClassName)) { throw InvalidHandler::handlerDoesNotExist($handlerClassName); } return new $handlerClassName($this->request); }) ->filter(function (HandlesSlashCommand $handler) { return $handler->canHandle($this->request); }) ->first(); if (! $handler) { throw RequestCouldNotBeHandled::noHandlerFound($this->request); } return $handler; }
php
protected function determineHandler() { $handler = collect($this->config->get('handlers')) ->map(function (string $handlerClassName) { if (! class_exists($handlerClassName)) { throw InvalidHandler::handlerDoesNotExist($handlerClassName); } return new $handlerClassName($this->request); }) ->filter(function (HandlesSlashCommand $handler) { return $handler->canHandle($this->request); }) ->first(); if (! $handler) { throw RequestCouldNotBeHandled::noHandlerFound($this->request); } return $handler; }
[ "protected", "function", "determineHandler", "(", ")", "{", "$", "handler", "=", "collect", "(", "$", "this", "->", "config", "->", "get", "(", "'handlers'", ")", ")", "->", "map", "(", "function", "(", "string", "$", "handlerClassName", ")", "{", "if", ...
@return \Spatie\SlashCommand\Handlers\BaseHandler @throws \Spatie\SlashCommand\Exceptions\RequestCouldNotBeHandled
[ "@return", "\\", "Spatie", "\\", "SlashCommand", "\\", "Handlers", "\\", "BaseHandler" ]
train
https://github.com/spatie/laravel-slack-slash-command/blob/010aaa32c5cfe90bd01d06204f61473660160169/src/Controller.php#L91-L111
gilbitron/EasyCSRF
src/EasyCSRF.php
EasyCSRF.generate
public function generate($key) { $key = $result = preg_replace('/[^a-zA-Z0-9]+/', '', $key); $extra = sha1($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']); // time() is used for token expiration $token = base64_encode(time() . $extra . $this->randomString(32)); $this->session->set($this->session_prefix . $key, $token); return $token; }
php
public function generate($key) { $key = $result = preg_replace('/[^a-zA-Z0-9]+/', '', $key); $extra = sha1($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']); // time() is used for token expiration $token = base64_encode(time() . $extra . $this->randomString(32)); $this->session->set($this->session_prefix . $key, $token); return $token; }
[ "public", "function", "generate", "(", "$", "key", ")", "{", "$", "key", "=", "$", "result", "=", "preg_replace", "(", "'/[^a-zA-Z0-9]+/'", ",", "''", ",", "$", "key", ")", ";", "$", "extra", "=", "sha1", "(", "$", "_SERVER", "[", "'REMOTE_ADDR'", "]...
Generate a CSRF token @param string $key Key for this token @return string
[ "Generate", "a", "CSRF", "token" ]
train
https://github.com/gilbitron/EasyCSRF/blob/e60fd94256b82b6bd322ddd809cd06a85a3132a7/src/EasyCSRF.php#L21-L31
gilbitron/EasyCSRF
src/EasyCSRF.php
EasyCSRF.check
public function check($key, $token, $timespan = null, $multiple = false) { $key = $result = preg_replace('/[^a-zA-Z0-9]+/', '', $key); if (!$token) { throw new \Exception('Missing CSRF form token.'); } $session_token = $this->session->get($this->session_prefix . $key); if (!$session_token) { throw new \Exception('Missing CSRF session token.'); } if (!$multiple) { $this->session->set($this->session_prefix . $key, null); } if (sha1($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']) != substr(base64_decode($session_token), 10, 40)) { throw new \Exception('Form origin does not match token origin.'); } if ($token != $session_token) { throw new \Exception('Invalid CSRF token.'); } // Check for token expiration if ($timespan != null && is_int($timespan) && intval(substr(base64_decode($session_token), 0, 10)) + $timespan < time()) { throw new \Exception('CSRF token has expired.'); } }
php
public function check($key, $token, $timespan = null, $multiple = false) { $key = $result = preg_replace('/[^a-zA-Z0-9]+/', '', $key); if (!$token) { throw new \Exception('Missing CSRF form token.'); } $session_token = $this->session->get($this->session_prefix . $key); if (!$session_token) { throw new \Exception('Missing CSRF session token.'); } if (!$multiple) { $this->session->set($this->session_prefix . $key, null); } if (sha1($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']) != substr(base64_decode($session_token), 10, 40)) { throw new \Exception('Form origin does not match token origin.'); } if ($token != $session_token) { throw new \Exception('Invalid CSRF token.'); } // Check for token expiration if ($timespan != null && is_int($timespan) && intval(substr(base64_decode($session_token), 0, 10)) + $timespan < time()) { throw new \Exception('CSRF token has expired.'); } }
[ "public", "function", "check", "(", "$", "key", ",", "$", "token", ",", "$", "timespan", "=", "null", ",", "$", "multiple", "=", "false", ")", "{", "$", "key", "=", "$", "result", "=", "preg_replace", "(", "'/[^a-zA-Z0-9]+/'", ",", "''", ",", "$", ...
Check the CSRF token is valid @param string $key Key for this token @param string $token The token string (usually found in $_POST) @param int $timespan Makes the token expire after $timespan seconds (null = never) @param boolean $multiple Makes the token reusable and not one-time (Useful for ajax-heavy requests)
[ "Check", "the", "CSRF", "token", "is", "valid" ]
train
https://github.com/gilbitron/EasyCSRF/blob/e60fd94256b82b6bd322ddd809cd06a85a3132a7/src/EasyCSRF.php#L41-L70
gilbitron/EasyCSRF
src/EasyCSRF.php
EasyCSRF.randomString
protected function randomString($length) { $seed = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijqlmnopqrtsuvwxyz0123456789'; $max = strlen($seed) - 1; $string = ''; for ($i = 0; $i < $length; ++$i) { $string .= $seed{intval(mt_rand(0.0, $max))}; } return $string; }
php
protected function randomString($length) { $seed = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijqlmnopqrtsuvwxyz0123456789'; $max = strlen($seed) - 1; $string = ''; for ($i = 0; $i < $length; ++$i) { $string .= $seed{intval(mt_rand(0.0, $max))}; } return $string; }
[ "protected", "function", "randomString", "(", "$", "length", ")", "{", "$", "seed", "=", "'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijqlmnopqrtsuvwxyz0123456789'", ";", "$", "max", "=", "strlen", "(", "$", "seed", ")", "-", "1", ";", "$", "string", "=", "''", ";", ...
Generate a random string @param int $length @return string
[ "Generate", "a", "random", "string" ]
train
https://github.com/gilbitron/EasyCSRF/blob/e60fd94256b82b6bd322ddd809cd06a85a3132a7/src/EasyCSRF.php#L78-L88
toplan/phpsms
src/phpsms/Sms.php
Sms.bootTask
public static function bootTask() { if (!self::isTaskBooted()) { self::configure(); foreach (self::scheme() as $name => $scheme) { self::registerDriver($name, $scheme); } } }
php
public static function bootTask() { if (!self::isTaskBooted()) { self::configure(); foreach (self::scheme() as $name => $scheme) { self::registerDriver($name, $scheme); } } }
[ "public", "static", "function", "bootTask", "(", ")", "{", "if", "(", "!", "self", "::", "isTaskBooted", "(", ")", ")", "{", "self", "::", "configure", "(", ")", ";", "foreach", "(", "self", "::", "scheme", "(", ")", "as", "$", "name", "=>", "$", ...
Bootstrap the task.
[ "Bootstrap", "the", "task", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L124-L132
toplan/phpsms
src/phpsms/Sms.php
Sms.configure
protected static function configure() { $config = []; if (!count(self::scheme())) { self::initScheme($config); } $diff = array_diff_key(self::scheme(), self::$agentsConfig); self::initAgentsConfig(array_keys($diff), $config); if (!count(self::scheme())) { throw new PhpSmsException('Expected at least one agent in scheme.'); } }
php
protected static function configure() { $config = []; if (!count(self::scheme())) { self::initScheme($config); } $diff = array_diff_key(self::scheme(), self::$agentsConfig); self::initAgentsConfig(array_keys($diff), $config); if (!count(self::scheme())) { throw new PhpSmsException('Expected at least one agent in scheme.'); } }
[ "protected", "static", "function", "configure", "(", ")", "{", "$", "config", "=", "[", "]", ";", "if", "(", "!", "count", "(", "self", "::", "scheme", "(", ")", ")", ")", "{", "self", "::", "initScheme", "(", "$", "config", ")", ";", "}", "$", ...
Configure. @throws PhpSmsException
[ "Configure", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L163-L174
toplan/phpsms
src/phpsms/Sms.php
Sms.initScheme
protected static function initScheme(array &$config) { $config = empty($config) ? include __DIR__ . '/../config/phpsms.php' : $config; $scheme = isset($config['scheme']) ? $config['scheme'] : []; self::scheme($scheme); }
php
protected static function initScheme(array &$config) { $config = empty($config) ? include __DIR__ . '/../config/phpsms.php' : $config; $scheme = isset($config['scheme']) ? $config['scheme'] : []; self::scheme($scheme); }
[ "protected", "static", "function", "initScheme", "(", "array", "&", "$", "config", ")", "{", "$", "config", "=", "empty", "(", "$", "config", ")", "?", "include", "__DIR__", ".", "'/../config/phpsms.php'", ":", "$", "config", ";", "$", "scheme", "=", "is...
Initialize the dispatch scheme. @param array $config
[ "Initialize", "the", "dispatch", "scheme", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L181-L186
toplan/phpsms
src/phpsms/Sms.php
Sms.initAgentsConfig
protected static function initAgentsConfig(array $agents, array &$config) { if (empty($agents)) { return; } $config = empty($config) ? include __DIR__ . '/../config/phpsms.php' : $config; $agentsConfig = isset($config['agents']) ? $config['agents'] : []; foreach ($agents as $name) { $agentConfig = isset($agentsConfig[$name]) ? $agentsConfig[$name] : []; self::config($name, $agentConfig); } }
php
protected static function initAgentsConfig(array $agents, array &$config) { if (empty($agents)) { return; } $config = empty($config) ? include __DIR__ . '/../config/phpsms.php' : $config; $agentsConfig = isset($config['agents']) ? $config['agents'] : []; foreach ($agents as $name) { $agentConfig = isset($agentsConfig[$name]) ? $agentsConfig[$name] : []; self::config($name, $agentConfig); } }
[ "protected", "static", "function", "initAgentsConfig", "(", "array", "$", "agents", ",", "array", "&", "$", "config", ")", "{", "if", "(", "empty", "(", "$", "agents", ")", ")", "{", "return", ";", "}", "$", "config", "=", "empty", "(", "$", "config"...
Initialize the configuration information. @param array $agents @param array $config
[ "Initialize", "the", "configuration", "information", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L194-L205
toplan/phpsms
src/phpsms/Sms.php
Sms.registerDriver
protected static function registerDriver($name, $scheme) { // parse higher-order scheme $settings = []; if (is_array($scheme)) { $settings = self::parseScheme($scheme); $scheme = $settings['scheme']; } // register self::getTask()->driver("$name $scheme")->work(function (Driver $driver) use ($settings) { $agent = self::getAgent($driver->name, $settings); extract($driver->getTaskData()); $template = isset($templates[$driver->name]) ? $templates[$driver->name] : null; $file = isset($files[$driver->name]) ? $files[$driver->name] : null; $params = isset($params[$driver->name]) ? $params[$driver->name] : []; if ($type === self::TYPE_VOICE) { $agent->sendVoice($to, $content, $template, $data, $code, $file, $params); } elseif ($type === self::TYPE_SMS) { $agent->sendSms($to, $content, $template, $data, $params); } $result = $agent->result(); if ($result['success']) { $driver->success(); } unset($result['success']); return $result; }); }
php
protected static function registerDriver($name, $scheme) { // parse higher-order scheme $settings = []; if (is_array($scheme)) { $settings = self::parseScheme($scheme); $scheme = $settings['scheme']; } // register self::getTask()->driver("$name $scheme")->work(function (Driver $driver) use ($settings) { $agent = self::getAgent($driver->name, $settings); extract($driver->getTaskData()); $template = isset($templates[$driver->name]) ? $templates[$driver->name] : null; $file = isset($files[$driver->name]) ? $files[$driver->name] : null; $params = isset($params[$driver->name]) ? $params[$driver->name] : []; if ($type === self::TYPE_VOICE) { $agent->sendVoice($to, $content, $template, $data, $code, $file, $params); } elseif ($type === self::TYPE_SMS) { $agent->sendSms($to, $content, $template, $data, $params); } $result = $agent->result(); if ($result['success']) { $driver->success(); } unset($result['success']); return $result; }); }
[ "protected", "static", "function", "registerDriver", "(", "$", "name", ",", "$", "scheme", ")", "{", "// parse higher-order scheme", "$", "settings", "=", "[", "]", ";", "if", "(", "is_array", "(", "$", "scheme", ")", ")", "{", "$", "settings", "=", "sel...
register driver. @param string $name @param string|array $scheme
[ "register", "driver", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L213-L241
toplan/phpsms
src/phpsms/Sms.php
Sms.parseScheme
protected static function parseScheme(array $options) { $weight = Util::pullFromArray($options, 'weight'); $backup = Util::pullFromArray($options, 'backup') ? 'backup' : ''; $props = array_filter(array_values($options), function ($prop) { return is_numeric($prop) || is_string($prop); }); $options['scheme'] = implode(' ', $props) . " $weight $backup"; return $options; }
php
protected static function parseScheme(array $options) { $weight = Util::pullFromArray($options, 'weight'); $backup = Util::pullFromArray($options, 'backup') ? 'backup' : ''; $props = array_filter(array_values($options), function ($prop) { return is_numeric($prop) || is_string($prop); }); $options['scheme'] = implode(' ', $props) . " $weight $backup"; return $options; }
[ "protected", "static", "function", "parseScheme", "(", "array", "$", "options", ")", "{", "$", "weight", "=", "Util", "::", "pullFromArray", "(", "$", "options", ",", "'weight'", ")", ";", "$", "backup", "=", "Util", "::", "pullFromArray", "(", "$", "opt...
Parse the higher-order dispatch scheme. @param array $options @return array
[ "Parse", "the", "higher", "-", "order", "dispatch", "scheme", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L250-L261
toplan/phpsms
src/phpsms/Sms.php
Sms.getAgent
public static function getAgent($name, array $options = []) { if (!self::hasAgent($name)) { $scheme = self::scheme($name); $config = self::config($name); if (is_array($scheme) && empty($options)) { $options = self::parseScheme($scheme); } if (isset($options['scheme'])) { unset($options['scheme']); } $className = "Toplan\\PhpSms\\{$name}Agent"; if (isset($options['agentClass'])) { $className = $options['agentClass']; unset($options['agentClass']); } if (!empty($options)) { self::$agents[$name] = new ParasiticAgent($config, $options); } elseif (class_exists($className)) { self::$agents[$name] = new $className($config); } else { throw new PhpSmsException("Not support agent `$name`."); } } return self::$agents[$name]; }
php
public static function getAgent($name, array $options = []) { if (!self::hasAgent($name)) { $scheme = self::scheme($name); $config = self::config($name); if (is_array($scheme) && empty($options)) { $options = self::parseScheme($scheme); } if (isset($options['scheme'])) { unset($options['scheme']); } $className = "Toplan\\PhpSms\\{$name}Agent"; if (isset($options['agentClass'])) { $className = $options['agentClass']; unset($options['agentClass']); } if (!empty($options)) { self::$agents[$name] = new ParasiticAgent($config, $options); } elseif (class_exists($className)) { self::$agents[$name] = new $className($config); } else { throw new PhpSmsException("Not support agent `$name`."); } } return self::$agents[$name]; }
[ "public", "static", "function", "getAgent", "(", "$", "name", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "self", "::", "hasAgent", "(", "$", "name", ")", ")", "{", "$", "scheme", "=", "self", "::", "scheme", "(", "$", ...
Get the agent instance by name. @param string $name @param array $options @throws PhpSmsException @return Agent
[ "Get", "the", "agent", "instance", "by", "name", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L273-L299
toplan/phpsms
src/phpsms/Sms.php
Sms.scheme
public static function scheme($name = null, $scheme = null, $override = false) { if (is_array($name) && is_bool($scheme)) { $override = $scheme; } return Util::operateArray(self::$scheme, $name, $scheme, null, function ($key, $value) { if (is_string($key)) { self::modifyScheme($key, is_array($value) ? $value : "$value"); } elseif (is_int($key)) { self::modifyScheme($value, ''); } }, $override, function (array $origin) { if (self::isTaskBooted()) { foreach (array_keys($origin) as $name) { self::getTask()->removeDriver($name); } } }); }
php
public static function scheme($name = null, $scheme = null, $override = false) { if (is_array($name) && is_bool($scheme)) { $override = $scheme; } return Util::operateArray(self::$scheme, $name, $scheme, null, function ($key, $value) { if (is_string($key)) { self::modifyScheme($key, is_array($value) ? $value : "$value"); } elseif (is_int($key)) { self::modifyScheme($value, ''); } }, $override, function (array $origin) { if (self::isTaskBooted()) { foreach (array_keys($origin) as $name) { self::getTask()->removeDriver($name); } } }); }
[ "public", "static", "function", "scheme", "(", "$", "name", "=", "null", ",", "$", "scheme", "=", "null", ",", "$", "override", "=", "false", ")", "{", "if", "(", "is_array", "(", "$", "name", ")", "&&", "is_bool", "(", "$", "scheme", ")", ")", "...
Set or get the dispatch scheme. @param string|array|null $name @param string|array|bool|null $scheme @param bool $override @return mixed
[ "Set", "or", "get", "the", "dispatch", "scheme", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L322-L341
toplan/phpsms
src/phpsms/Sms.php
Sms.modifyScheme
protected static function modifyScheme($name, $scheme) { self::validateAgentName($name); self::$scheme[$name] = $scheme; if (self::isTaskBooted()) { $driver = self::getTask()->getDriver($name); if ($driver) { if (is_array($scheme)) { $higherOrderScheme = self::parseScheme($scheme); $scheme = $higherOrderScheme['scheme']; } $driver->reset($scheme); } else { self::registerDriver($name, $scheme); } } }
php
protected static function modifyScheme($name, $scheme) { self::validateAgentName($name); self::$scheme[$name] = $scheme; if (self::isTaskBooted()) { $driver = self::getTask()->getDriver($name); if ($driver) { if (is_array($scheme)) { $higherOrderScheme = self::parseScheme($scheme); $scheme = $higherOrderScheme['scheme']; } $driver->reset($scheme); } else { self::registerDriver($name, $scheme); } } }
[ "protected", "static", "function", "modifyScheme", "(", "$", "name", ",", "$", "scheme", ")", "{", "self", "::", "validateAgentName", "(", "$", "name", ")", ";", "self", "::", "$", "scheme", "[", "$", "name", "]", "=", "$", "scheme", ";", "if", "(", ...
Modify the dispatch scheme of agent. @param string $name @param string|array $scheme @throws PhpSmsException
[ "Modify", "the", "dispatch", "scheme", "of", "agent", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L351-L367
toplan/phpsms
src/phpsms/Sms.php
Sms.config
public static function config($name = null, $config = null, $override = false) { $overrideAll = (is_array($name) && is_bool($config)) ? $config : false; return Util::operateArray(self::$agentsConfig, $name, $config, [], function ($name, array $config) use ($override) { self::modifyConfig($name, $config, $override); }, $overrideAll, function (array $origin) { foreach (array_keys($origin) as $name) { if (self::hasAgent("$name")) { self::getAgent("$name")->config([], true); } } }); }
php
public static function config($name = null, $config = null, $override = false) { $overrideAll = (is_array($name) && is_bool($config)) ? $config : false; return Util::operateArray(self::$agentsConfig, $name, $config, [], function ($name, array $config) use ($override) { self::modifyConfig($name, $config, $override); }, $overrideAll, function (array $origin) { foreach (array_keys($origin) as $name) { if (self::hasAgent("$name")) { self::getAgent("$name")->config([], true); } } }); }
[ "public", "static", "function", "config", "(", "$", "name", "=", "null", ",", "$", "config", "=", "null", ",", "$", "override", "=", "false", ")", "{", "$", "overrideAll", "=", "(", "is_array", "(", "$", "name", ")", "&&", "is_bool", "(", "$", "con...
Set or get the configuration information. @param string|array|null $name @param array|bool|null $config @param bool $override @throws PhpSmsException @return array
[ "Set", "or", "get", "the", "configuration", "information", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L380-L393
toplan/phpsms
src/phpsms/Sms.php
Sms.modifyConfig
protected static function modifyConfig($name, array $config, $override = false) { self::validateAgentName($name); if (!isset(self::$agentsConfig[$name])) { self::$agentsConfig[$name] = []; } $target = &self::$agentsConfig[$name]; if ($override) { $target = $config; } else { $target = array_merge($target, $config); } if (self::hasAgent($name)) { self::getAgent($name)->config($target); } }
php
protected static function modifyConfig($name, array $config, $override = false) { self::validateAgentName($name); if (!isset(self::$agentsConfig[$name])) { self::$agentsConfig[$name] = []; } $target = &self::$agentsConfig[$name]; if ($override) { $target = $config; } else { $target = array_merge($target, $config); } if (self::hasAgent($name)) { self::getAgent($name)->config($target); } }
[ "protected", "static", "function", "modifyConfig", "(", "$", "name", ",", "array", "$", "config", ",", "$", "override", "=", "false", ")", "{", "self", "::", "validateAgentName", "(", "$", "name", ")", ";", "if", "(", "!", "isset", "(", "self", "::", ...
Modify the configuration information. @param string $name @param array $config @param bool $override @throws PhpSmsException
[ "Modify", "the", "configuration", "information", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L404-L419
toplan/phpsms
src/phpsms/Sms.php
Sms.make
public static function make($agentName = null, $tempId = null) { $sms = new self(); $sms->type(self::TYPE_SMS); if (is_array($agentName)) { $sms->template($agentName); } elseif ($agentName && is_string($agentName)) { if ($tempId === null) { $sms->content($agentName); } elseif (is_string($tempId) || is_int($tempId)) { $sms->template($agentName, "$tempId"); } } return $sms; }
php
public static function make($agentName = null, $tempId = null) { $sms = new self(); $sms->type(self::TYPE_SMS); if (is_array($agentName)) { $sms->template($agentName); } elseif ($agentName && is_string($agentName)) { if ($tempId === null) { $sms->content($agentName); } elseif (is_string($tempId) || is_int($tempId)) { $sms->template($agentName, "$tempId"); } } return $sms; }
[ "public", "static", "function", "make", "(", "$", "agentName", "=", "null", ",", "$", "tempId", "=", "null", ")", "{", "$", "sms", "=", "new", "self", "(", ")", ";", "$", "sms", "->", "type", "(", "self", "::", "TYPE_SMS", ")", ";", "if", "(", ...
Create a instance for send sms. @param mixed $agentName @param mixed $tempId @return Sms
[ "Create", "a", "instance", "for", "send", "sms", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L459-L474
toplan/phpsms
src/phpsms/Sms.php
Sms.voice
public static function voice($code = null) { $sms = new self(); $sms->type(self::TYPE_VOICE); $sms->code($code); return $sms; }
php
public static function voice($code = null) { $sms = new self(); $sms->type(self::TYPE_VOICE); $sms->code($code); return $sms; }
[ "public", "static", "function", "voice", "(", "$", "code", "=", "null", ")", "{", "$", "sms", "=", "new", "self", "(", ")", ";", "$", "sms", "->", "type", "(", "self", "::", "TYPE_VOICE", ")", ";", "$", "sms", "->", "code", "(", "$", "code", ")...
Create a instance for send voice. @param int|string|null $code @return Sms
[ "Create", "a", "instance", "for", "send", "voice", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L483-L490
toplan/phpsms
src/phpsms/Sms.php
Sms.queue
public static function queue($enable = null, $handler = null) { if ($enable === null && $handler === null) { return self::$enableQueue; } if (is_callable($enable)) { $handler = $enable; $enable = true; } self::$enableQueue = (bool) $enable; if (is_callable($handler)) { self::$howToUseQueue = $handler; } return self::$enableQueue; }
php
public static function queue($enable = null, $handler = null) { if ($enable === null && $handler === null) { return self::$enableQueue; } if (is_callable($enable)) { $handler = $enable; $enable = true; } self::$enableQueue = (bool) $enable; if (is_callable($handler)) { self::$howToUseQueue = $handler; } return self::$enableQueue; }
[ "public", "static", "function", "queue", "(", "$", "enable", "=", "null", ",", "$", "handler", "=", "null", ")", "{", "if", "(", "$", "enable", "===", "null", "&&", "$", "handler", "===", "null", ")", "{", "return", "self", "::", "$", "enableQueue", ...
Set whether to use the queue system, and define how to use it. @param bool|\Closure|null $enable @param \Closure|null $handler @return bool
[ "Set", "whether", "to", "use", "the", "queue", "system", "and", "define", "how", "to", "use", "it", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L501-L516
toplan/phpsms
src/phpsms/Sms.php
Sms.type
public function type($type) { if ($type !== self::TYPE_SMS && $type !== self::TYPE_VOICE) { throw new PhpSmsException('Expected the parameter equals to `Sms::TYPE_SMS` or `Sms::TYPE_VOICE`.'); } $this->smsData['type'] = $type; return $this; }
php
public function type($type) { if ($type !== self::TYPE_SMS && $type !== self::TYPE_VOICE) { throw new PhpSmsException('Expected the parameter equals to `Sms::TYPE_SMS` or `Sms::TYPE_VOICE`.'); } $this->smsData['type'] = $type; return $this; }
[ "public", "function", "type", "(", "$", "type", ")", "{", "if", "(", "$", "type", "!==", "self", "::", "TYPE_SMS", "&&", "$", "type", "!==", "self", "::", "TYPE_VOICE", ")", "{", "throw", "new", "PhpSmsException", "(", "'Expected the parameter equals to `Sms...
Set the type of Sms instance. @param $type @throws PhpSmsException @return $this
[ "Set", "the", "type", "of", "Sms", "instance", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L527-L535
toplan/phpsms
src/phpsms/Sms.php
Sms.to
public function to($mobile) { if (is_string($mobile)) { $mobile = trim($mobile); } $this->smsData['to'] = $mobile; return $this; }
php
public function to($mobile) { if (is_string($mobile)) { $mobile = trim($mobile); } $this->smsData['to'] = $mobile; return $this; }
[ "public", "function", "to", "(", "$", "mobile", ")", "{", "if", "(", "is_string", "(", "$", "mobile", ")", ")", "{", "$", "mobile", "=", "trim", "(", "$", "mobile", ")", ";", "}", "$", "this", "->", "smsData", "[", "'to'", "]", "=", "$", "mobil...
Set the recipient`s mobile number. @param string|array $mobile @return $this
[ "Set", "the", "recipient", "s", "mobile", "number", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L544-L552
toplan/phpsms
src/phpsms/Sms.php
Sms.template
public function template($name, $tempId = null) { Util::operateArray($this->smsData['templates'], $name, $tempId); return $this; }
php
public function template($name, $tempId = null) { Util::operateArray($this->smsData['templates'], $name, $tempId); return $this; }
[ "public", "function", "template", "(", "$", "name", ",", "$", "tempId", "=", "null", ")", "{", "Util", "::", "operateArray", "(", "$", "this", "->", "smsData", "[", "'templates'", "]", ",", "$", "name", ",", "$", "tempId", ")", ";", "return", "$", ...
Set the template ids. @param mixed $name @param mixed $tempId @return $this
[ "Set", "the", "template", "ids", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L576-L581
toplan/phpsms
src/phpsms/Sms.php
Sms.data
public function data($key, $value = null) { Util::operateArray($this->smsData['data'], $key, $value); return $this; }
php
public function data($key, $value = null) { Util::operateArray($this->smsData['data'], $key, $value); return $this; }
[ "public", "function", "data", "(", "$", "key", ",", "$", "value", "=", "null", ")", "{", "Util", "::", "operateArray", "(", "$", "this", "->", "smsData", "[", "'data'", "]", ",", "$", "key", ",", "$", "value", ")", ";", "return", "$", "this", ";"...
Set the template data. @param mixed $key @param mixed $value @return $this
[ "Set", "the", "template", "data", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L591-L596
toplan/phpsms
src/phpsms/Sms.php
Sms.file
public function file($name, $id = null) { Util::operateArray($this->smsData['files'], $name, $id); return $this; }
php
public function file($name, $id = null) { Util::operateArray($this->smsData['files'], $name, $id); return $this; }
[ "public", "function", "file", "(", "$", "name", ",", "$", "id", "=", "null", ")", "{", "Util", "::", "operateArray", "(", "$", "this", "->", "smsData", "[", "'files'", "]", ",", "$", "name", ",", "$", "id", ")", ";", "return", "$", "this", ";", ...
Set voice file. @param string|array $name @param string|int $id @return $this
[ "Set", "voice", "file", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L620-L625
toplan/phpsms
src/phpsms/Sms.php
Sms.params
public function params($name, $params = null, $override = false) { $overrideAll = (is_array($name) && is_bool($params)) ? $params : false; Util::operateArray($this->smsData['params'], $name, $params, [], function ($name, array $params) use ($override) { if (!isset($this->smsData['params'][$name])) { $this->smsData['params'][$name] = []; } $target = &$this->smsData['params'][$name]; if ($override) { $target = $params; } else { $target = array_merge($target, $params); } }, $overrideAll); return $this; }
php
public function params($name, $params = null, $override = false) { $overrideAll = (is_array($name) && is_bool($params)) ? $params : false; Util::operateArray($this->smsData['params'], $name, $params, [], function ($name, array $params) use ($override) { if (!isset($this->smsData['params'][$name])) { $this->smsData['params'][$name] = []; } $target = &$this->smsData['params'][$name]; if ($override) { $target = $params; } else { $target = array_merge($target, $params); } }, $overrideAll); return $this; }
[ "public", "function", "params", "(", "$", "name", ",", "$", "params", "=", "null", ",", "$", "override", "=", "false", ")", "{", "$", "overrideAll", "=", "(", "is_array", "(", "$", "name", ")", "&&", "is_bool", "(", "$", "params", ")", ")", "?", ...
Set params of agent. @param string|array $name @param array|bool|null $params @param bool $override @return $this
[ "Set", "params", "of", "agent", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L636-L652
toplan/phpsms
src/phpsms/Sms.php
Sms.agent
public function agent($name) { if (!is_string($name) || empty($name)) { throw new PhpSmsException('Expected the parameter to be non-empty string.'); } $this->firstAgent = $name; return $this; }
php
public function agent($name) { if (!is_string($name) || empty($name)) { throw new PhpSmsException('Expected the parameter to be non-empty string.'); } $this->firstAgent = $name; return $this; }
[ "public", "function", "agent", "(", "$", "name", ")", "{", "if", "(", "!", "is_string", "(", "$", "name", ")", "||", "empty", "(", "$", "name", ")", ")", "{", "throw", "new", "PhpSmsException", "(", "'Expected the parameter to be non-empty string.'", ")", ...
Set the first agent. @param string $name @throws PhpSmsException @return $this
[ "Set", "the", "first", "agent", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L663-L671
toplan/phpsms
src/phpsms/Sms.php
Sms.send
public function send($immediately = false) { if (!self::$enableQueue || $this->pushedToQueue) { $immediately = true; } if ($immediately) { return self::$task->data($this->all())->run($this->firstAgent); } return $this->push(); }
php
public function send($immediately = false) { if (!self::$enableQueue || $this->pushedToQueue) { $immediately = true; } if ($immediately) { return self::$task->data($this->all())->run($this->firstAgent); } return $this->push(); }
[ "public", "function", "send", "(", "$", "immediately", "=", "false", ")", "{", "if", "(", "!", "self", "::", "$", "enableQueue", "||", "$", "this", "->", "pushedToQueue", ")", "{", "$", "immediately", "=", "true", ";", "}", "if", "(", "$", "immediate...
Start send. If call with a `true` parameter, this system will immediately start request to send sms whatever whether to use the queue. if the current instance has pushed to the queue, you can recall this method in queue system without any parameter, so this mechanism in order to make you convenient to use this method in queue system. @param bool $immediately @return mixed
[ "Start", "send", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L684-L694
toplan/phpsms
src/phpsms/Sms.php
Sms.push
public function push() { if (!is_callable(self::$howToUseQueue)) { throw new PhpSmsException('Expected define how to use the queue system by methods `queue`.'); } try { $this->pushedToQueue = true; return call_user_func_array(self::$howToUseQueue, [$this, $this->all()]); } catch (\Exception $e) { $this->pushedToQueue = false; throw $e; } }
php
public function push() { if (!is_callable(self::$howToUseQueue)) { throw new PhpSmsException('Expected define how to use the queue system by methods `queue`.'); } try { $this->pushedToQueue = true; return call_user_func_array(self::$howToUseQueue, [$this, $this->all()]); } catch (\Exception $e) { $this->pushedToQueue = false; throw $e; } }
[ "public", "function", "push", "(", ")", "{", "if", "(", "!", "is_callable", "(", "self", "::", "$", "howToUseQueue", ")", ")", "{", "throw", "new", "PhpSmsException", "(", "'Expected define how to use the queue system by methods `queue`.'", ")", ";", "}", "try", ...
Push to the queue system. @throws \Exception | PhpSmsException @return mixed
[ "Push", "to", "the", "queue", "system", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L703-L716
toplan/phpsms
src/phpsms/Sms.php
Sms.all
public function all($key = null) { if ($key !== null) { return isset($this->smsData[$key]) ? $this->smsData[$key] : null; } return $this->smsData; }
php
public function all($key = null) { if ($key !== null) { return isset($this->smsData[$key]) ? $this->smsData[$key] : null; } return $this->smsData; }
[ "public", "function", "all", "(", "$", "key", "=", "null", ")", "{", "if", "(", "$", "key", "!==", "null", ")", "{", "return", "isset", "(", "$", "this", "->", "smsData", "[", "$", "key", "]", ")", "?", "$", "this", "->", "smsData", "[", "$", ...
Get all of the data. @param null|string $key @return mixed
[ "Get", "all", "of", "the", "data", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L725-L732
toplan/phpsms
src/phpsms/Sms.php
Sms.toggleSerializeScheme
protected static function toggleSerializeScheme(array $scheme) { foreach ($scheme as $name => &$options) { if (is_array($options)) { foreach (ParasiticAgent::methods() as $method) { self::toggleSerializeClosure($options, $method); } } } return $scheme; }
php
protected static function toggleSerializeScheme(array $scheme) { foreach ($scheme as $name => &$options) { if (is_array($options)) { foreach (ParasiticAgent::methods() as $method) { self::toggleSerializeClosure($options, $method); } } } return $scheme; }
[ "protected", "static", "function", "toggleSerializeScheme", "(", "array", "$", "scheme", ")", "{", "foreach", "(", "$", "scheme", "as", "$", "name", "=>", "&", "$", "options", ")", "{", "if", "(", "is_array", "(", "$", "options", ")", ")", "{", "foreac...
Serialize or deserialize the scheme. @param array $scheme @return array
[ "Serialize", "or", "deserialize", "the", "scheme", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L812-L823
toplan/phpsms
src/phpsms/Sms.php
Sms.serializeHandlers
protected static function serializeHandlers() { $hooks = (array) self::getTask()->handlers; foreach ($hooks as &$handlers) { foreach (array_keys($handlers) as $key) { self::toggleSerializeClosure($handlers, $key); } } return $hooks; }
php
protected static function serializeHandlers() { $hooks = (array) self::getTask()->handlers; foreach ($hooks as &$handlers) { foreach (array_keys($handlers) as $key) { self::toggleSerializeClosure($handlers, $key); } } return $hooks; }
[ "protected", "static", "function", "serializeHandlers", "(", ")", "{", "$", "hooks", "=", "(", "array", ")", "self", "::", "getTask", "(", ")", "->", "handlers", ";", "foreach", "(", "$", "hooks", "as", "&", "$", "handlers", ")", "{", "foreach", "(", ...
Serialize the hooks' handlers. @return array
[ "Serialize", "the", "hooks", "handlers", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L830-L840
toplan/phpsms
src/phpsms/Sms.php
Sms.reinstallHandlers
protected static function reinstallHandlers(array $handlers) { $serializer = Util::getClosureSerializer(); foreach ($handlers as $hookName => $serializedHandlers) { foreach ($serializedHandlers as $index => $handler) { if (is_string($handler)) { $handler = $serializer->unserialize($handler); } self::$hookName($handler, $index === 0); } } }
php
protected static function reinstallHandlers(array $handlers) { $serializer = Util::getClosureSerializer(); foreach ($handlers as $hookName => $serializedHandlers) { foreach ($serializedHandlers as $index => $handler) { if (is_string($handler)) { $handler = $serializer->unserialize($handler); } self::$hookName($handler, $index === 0); } } }
[ "protected", "static", "function", "reinstallHandlers", "(", "array", "$", "handlers", ")", "{", "$", "serializer", "=", "Util", "::", "getClosureSerializer", "(", ")", ";", "foreach", "(", "$", "handlers", "as", "$", "hookName", "=>", "$", "serializedHandlers...
Reinstall hooks' handlers. @param array $handlers
[ "Reinstall", "hooks", "handlers", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L847-L858
toplan/phpsms
src/phpsms/Sms.php
Sms.toggleSerializeClosure
protected static function toggleSerializeClosure(array &$options, $key) { if (!isset($options[$key])) { return; } $serializer = Util::getClosureSerializer(); if (is_callable($options[$key])) { $options[$key] = (string) $serializer->serialize($options[$key]); } elseif (is_string($options[$key])) { $options[$key] = $serializer->unserialize($options[$key]); } }
php
protected static function toggleSerializeClosure(array &$options, $key) { if (!isset($options[$key])) { return; } $serializer = Util::getClosureSerializer(); if (is_callable($options[$key])) { $options[$key] = (string) $serializer->serialize($options[$key]); } elseif (is_string($options[$key])) { $options[$key] = $serializer->unserialize($options[$key]); } }
[ "protected", "static", "function", "toggleSerializeClosure", "(", "array", "&", "$", "options", ",", "$", "key", ")", "{", "if", "(", "!", "isset", "(", "$", "options", "[", "$", "key", "]", ")", ")", "{", "return", ";", "}", "$", "serializer", "=", ...
Serialize or deserialize the specified closure and then replace the original value. @param array $options @param int|string $key
[ "Serialize", "or", "deserialize", "the", "specified", "closure", "and", "then", "replace", "the", "original", "value", "." ]
train
https://github.com/toplan/phpsms/blob/863918ed0970d335471fb48c09f9f446a4daddbd/src/phpsms/Sms.php#L866-L877