repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
sequencelengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_select.php
ezcQuerySelect.orderBy
public function orderBy( $column, $type = self::ASC ) { $string = $this->getIdentifier( $column ); if ( $type == self::DESC ) { $string .= ' DESC'; } if ( $this->orderString == '' ) { $this->orderString = "ORDER BY {$string}"; } else { $this->orderString .= ", {$string}"; } $this->lastInvokedMethod = 'order'; return $this; }
php
public function orderBy( $column, $type = self::ASC ) { $string = $this->getIdentifier( $column ); if ( $type == self::DESC ) { $string .= ' DESC'; } if ( $this->orderString == '' ) { $this->orderString = "ORDER BY {$string}"; } else { $this->orderString .= ", {$string}"; } $this->lastInvokedMethod = 'order'; return $this; }
[ "public", "function", "orderBy", "(", "$", "column", ",", "$", "type", "=", "self", "::", "ASC", ")", "{", "$", "string", "=", "$", "this", "->", "getIdentifier", "(", "$", "column", ")", ";", "if", "(", "$", "type", "==", "self", "::", "DESC", ")", "{", "$", "string", ".=", "' DESC'", ";", "}", "if", "(", "$", "this", "->", "orderString", "==", "''", ")", "{", "$", "this", "->", "orderString", "=", "\"ORDER BY {$string}\"", ";", "}", "else", "{", "$", "this", "->", "orderString", ".=", "\", {$string}\"", ";", "}", "$", "this", "->", "lastInvokedMethod", "=", "'order'", ";", "return", "$", "this", ";", "}" ]
Returns SQL that orders the result set by a given column. You can call orderBy multiple times. Each call will add a column to order by. Example: <code> $q->select( '*' )->from( 'table' ) ->orderBy( 'id' ); </code> @param string $column a column name in the result set @param string $type if the column should be sorted ascending or descending. you can specify this using ezcQuerySelect::ASC or ezcQuerySelect::DESC @return ezcQuery a pointer to $this
[ "Returns", "SQL", "that", "orders", "the", "result", "set", "by", "a", "given", "column", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_select.php#L723-L741
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_select.php
ezcQuerySelect.groupBy
public function groupBy() { $args = func_get_args(); $columns = self::arrayFlatten( $args ); if ( count( $columns ) < 1 ) { throw new ezcQueryVariableParameterException( 'groupBy', count( $args ), 1 ); } $columns = $this->getIdentifiers( $columns ); $string = join( ', ', $columns ); if ( $this->groupString == '' ) { $this->groupString = "GROUP BY {$string}" ; } else { $this->groupString .= ", {$string}"; } $this->lastInvokedMethod = 'group'; return $this; }
php
public function groupBy() { $args = func_get_args(); $columns = self::arrayFlatten( $args ); if ( count( $columns ) < 1 ) { throw new ezcQueryVariableParameterException( 'groupBy', count( $args ), 1 ); } $columns = $this->getIdentifiers( $columns ); $string = join( ', ', $columns ); if ( $this->groupString == '' ) { $this->groupString = "GROUP BY {$string}" ; } else { $this->groupString .= ", {$string}"; } $this->lastInvokedMethod = 'group'; return $this; }
[ "public", "function", "groupBy", "(", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "columns", "=", "self", "::", "arrayFlatten", "(", "$", "args", ")", ";", "if", "(", "count", "(", "$", "columns", ")", "<", "1", ")", "{", "throw", "new", "ezcQueryVariableParameterException", "(", "'groupBy'", ",", "count", "(", "$", "args", ")", ",", "1", ")", ";", "}", "$", "columns", "=", "$", "this", "->", "getIdentifiers", "(", "$", "columns", ")", ";", "$", "string", "=", "join", "(", "', '", ",", "$", "columns", ")", ";", "if", "(", "$", "this", "->", "groupString", "==", "''", ")", "{", "$", "this", "->", "groupString", "=", "\"GROUP BY {$string}\"", ";", "}", "else", "{", "$", "this", "->", "groupString", ".=", "\", {$string}\"", ";", "}", "$", "this", "->", "lastInvokedMethod", "=", "'group'", ";", "return", "$", "this", ";", "}" ]
Returns SQL that groups the result set by a given column. You can call groupBy multiple times. Each call will add a column to group by. Example: <code> $q->select( '*' )->from( 'table' ) ->groupBy( 'id' ); </code> @throws ezcQueryVariableParameterException if called with no parameters. @param string $column a column name in the result set @return ezcQuery a pointer to $this
[ "Returns", "SQL", "that", "groups", "the", "result", "set", "by", "a", "given", "column", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_select.php#L759-L782
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_select.php
ezcQuerySelect.having
public function having() { // using groupBy()->having() syntax assumed, so check if last call was to groupBy() if ( $this->lastInvokedMethod != 'group' && $this->lastInvokedMethod != 'having' ) { throw new ezcQueryInvalidException( 'SELECT', 'Invoking having() not immediately after groupBy().' ); } $args = func_get_args(); $expressions = self::arrayFlatten( $args ); if ( count( $expressions ) < 1 ) { throw new ezcQueryVariableParameterException( 'having', count( $args ), 1 ); } if ( $this->havingString == null ) { $this->havingString = 'HAVING '; } // will add "AND expression" in subsequent calls to having() if ( $this->havingString != 'HAVING ' ) { $this->havingString .= ' AND '; } $this->havingString .= join( ' AND ', $expressions ); $this->lastInvokedMethod = 'having'; return $this; }
php
public function having() { // using groupBy()->having() syntax assumed, so check if last call was to groupBy() if ( $this->lastInvokedMethod != 'group' && $this->lastInvokedMethod != 'having' ) { throw new ezcQueryInvalidException( 'SELECT', 'Invoking having() not immediately after groupBy().' ); } $args = func_get_args(); $expressions = self::arrayFlatten( $args ); if ( count( $expressions ) < 1 ) { throw new ezcQueryVariableParameterException( 'having', count( $args ), 1 ); } if ( $this->havingString == null ) { $this->havingString = 'HAVING '; } // will add "AND expression" in subsequent calls to having() if ( $this->havingString != 'HAVING ' ) { $this->havingString .= ' AND '; } $this->havingString .= join( ' AND ', $expressions ); $this->lastInvokedMethod = 'having'; return $this; }
[ "public", "function", "having", "(", ")", "{", "// using groupBy()->having() syntax assumed, so check if last call was to groupBy()", "if", "(", "$", "this", "->", "lastInvokedMethod", "!=", "'group'", "&&", "$", "this", "->", "lastInvokedMethod", "!=", "'having'", ")", "{", "throw", "new", "ezcQueryInvalidException", "(", "'SELECT'", ",", "'Invoking having() not immediately after groupBy().'", ")", ";", "}", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "expressions", "=", "self", "::", "arrayFlatten", "(", "$", "args", ")", ";", "if", "(", "count", "(", "$", "expressions", ")", "<", "1", ")", "{", "throw", "new", "ezcQueryVariableParameterException", "(", "'having'", ",", "count", "(", "$", "args", ")", ",", "1", ")", ";", "}", "if", "(", "$", "this", "->", "havingString", "==", "null", ")", "{", "$", "this", "->", "havingString", "=", "'HAVING '", ";", "}", "// will add \"AND expression\" in subsequent calls to having()", "if", "(", "$", "this", "->", "havingString", "!=", "'HAVING '", ")", "{", "$", "this", "->", "havingString", ".=", "' AND '", ";", "}", "$", "this", "->", "havingString", ".=", "join", "(", "' AND '", ",", "$", "expressions", ")", ";", "$", "this", "->", "lastInvokedMethod", "=", "'having'", ";", "return", "$", "this", ";", "}" ]
Returns SQL that set having by a given expression. You can call having multiple times. Each call will add an expression with a logical and. Example: <code> $q->select( '*' )->from( 'table' )->groupBy( 'id' ) ->having( $q->expr->eq('id',1) ); </code> @throws ezcQueryInvalidException if invoked without preceding call to groupBy(). @throws ezcQueryVariableParameterException if called with no parameters. @param string|array(string) $... Either a string with a logical expression name or an array with logical expressions. @return ezcQuery a pointer to $this
[ "Returns", "SQL", "that", "set", "having", "by", "a", "given", "expression", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_select.php#L804-L833
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_select.php
ezcQuerySelect.getQuery
public function getQuery() { if ( $this->selectString == null ) { throw new ezcQueryInvalidException( "SELECT", "select() was not called before getQuery()." ); } $query = "{$this->selectString}"; if ( $this->fromString != null ) { $query = "{$query} {$this->fromString}"; } if ( $this->whereString != null ) { $query = "{$query} {$this->whereString}"; } if ( $this->groupString != null ) { $query = "{$query} {$this->groupString}"; } if ( $this->havingString != null ) { $query = "{$query} {$this->havingString}"; } if ( $this->orderString != null ) { $query = "{$query} {$this->orderString}"; } if ( $this->limitString != null ) { $query = "{$query} {$this->limitString}"; } return $query; }
php
public function getQuery() { if ( $this->selectString == null ) { throw new ezcQueryInvalidException( "SELECT", "select() was not called before getQuery()." ); } $query = "{$this->selectString}"; if ( $this->fromString != null ) { $query = "{$query} {$this->fromString}"; } if ( $this->whereString != null ) { $query = "{$query} {$this->whereString}"; } if ( $this->groupString != null ) { $query = "{$query} {$this->groupString}"; } if ( $this->havingString != null ) { $query = "{$query} {$this->havingString}"; } if ( $this->orderString != null ) { $query = "{$query} {$this->orderString}"; } if ( $this->limitString != null ) { $query = "{$query} {$this->limitString}"; } return $query; }
[ "public", "function", "getQuery", "(", ")", "{", "if", "(", "$", "this", "->", "selectString", "==", "null", ")", "{", "throw", "new", "ezcQueryInvalidException", "(", "\"SELECT\"", ",", "\"select() was not called before getQuery().\"", ")", ";", "}", "$", "query", "=", "\"{$this->selectString}\"", ";", "if", "(", "$", "this", "->", "fromString", "!=", "null", ")", "{", "$", "query", "=", "\"{$query} {$this->fromString}\"", ";", "}", "if", "(", "$", "this", "->", "whereString", "!=", "null", ")", "{", "$", "query", "=", "\"{$query} {$this->whereString}\"", ";", "}", "if", "(", "$", "this", "->", "groupString", "!=", "null", ")", "{", "$", "query", "=", "\"{$query} {$this->groupString}\"", ";", "}", "if", "(", "$", "this", "->", "havingString", "!=", "null", ")", "{", "$", "query", "=", "\"{$query} {$this->havingString}\"", ";", "}", "if", "(", "$", "this", "->", "orderString", "!=", "null", ")", "{", "$", "query", "=", "\"{$query} {$this->orderString}\"", ";", "}", "if", "(", "$", "this", "->", "limitString", "!=", "null", ")", "{", "$", "query", "=", "\"{$query} {$this->limitString}\"", ";", "}", "return", "$", "query", ";", "}" ]
Returns the complete select query string. This method uses the build methods to build the various parts of the select query. @todo add newlines? easier for debugging @throws ezcQueryInvalidException if it was not possible to build a valid query. @return string
[ "Returns", "the", "complete", "select", "query", "string", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_select.php#L864-L897
SporkCode/Spork
src/Mvc/Listener/ViewModelIdentity.php
ViewModelIdentity.injectIdentityModel
public function injectIdentityModel(MvcEvent $event) { $viewModel = $event->getViewModel(); if ($viewModel->getTemplate() == 'layout/layout') { $servies = $event->getApplication()->getServiceManager(); $appConfig = $servies->get('config'); if (isset($appConfig['view_model_identity'])) { $config = $appConfig['view_model_identity']; } else { throw new \Exception('view_model_identity key not found in configuration'); } if (!$servies->has($config['authenticationService'])) { throw new \Exception('Auththentication service not found'); } if (!$servies->has($config['identity'])) { throw new \Exception('Identity not found'); } $childViewModel = new IdentityViewModel(array( 'auth' => $servies->get($config['authenticationService']), 'identity' => $servies->get($config['identity']), )); if (isset($config['template'])) { $childViewModel->setTemplate($config['template']); } if (isset($config['captureTo'])) { $childViewModel->setCaptureTo($config['captureTo']); } $viewModel->addChild($childViewModel); } }
php
public function injectIdentityModel(MvcEvent $event) { $viewModel = $event->getViewModel(); if ($viewModel->getTemplate() == 'layout/layout') { $servies = $event->getApplication()->getServiceManager(); $appConfig = $servies->get('config'); if (isset($appConfig['view_model_identity'])) { $config = $appConfig['view_model_identity']; } else { throw new \Exception('view_model_identity key not found in configuration'); } if (!$servies->has($config['authenticationService'])) { throw new \Exception('Auththentication service not found'); } if (!$servies->has($config['identity'])) { throw new \Exception('Identity not found'); } $childViewModel = new IdentityViewModel(array( 'auth' => $servies->get($config['authenticationService']), 'identity' => $servies->get($config['identity']), )); if (isset($config['template'])) { $childViewModel->setTemplate($config['template']); } if (isset($config['captureTo'])) { $childViewModel->setCaptureTo($config['captureTo']); } $viewModel->addChild($childViewModel); } }
[ "public", "function", "injectIdentityModel", "(", "MvcEvent", "$", "event", ")", "{", "$", "viewModel", "=", "$", "event", "->", "getViewModel", "(", ")", ";", "if", "(", "$", "viewModel", "->", "getTemplate", "(", ")", "==", "'layout/layout'", ")", "{", "$", "servies", "=", "$", "event", "->", "getApplication", "(", ")", "->", "getServiceManager", "(", ")", ";", "$", "appConfig", "=", "$", "servies", "->", "get", "(", "'config'", ")", ";", "if", "(", "isset", "(", "$", "appConfig", "[", "'view_model_identity'", "]", ")", ")", "{", "$", "config", "=", "$", "appConfig", "[", "'view_model_identity'", "]", ";", "}", "else", "{", "throw", "new", "\\", "Exception", "(", "'view_model_identity key not found in configuration'", ")", ";", "}", "if", "(", "!", "$", "servies", "->", "has", "(", "$", "config", "[", "'authenticationService'", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Auththentication service not found'", ")", ";", "}", "if", "(", "!", "$", "servies", "->", "has", "(", "$", "config", "[", "'identity'", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Identity not found'", ")", ";", "}", "$", "childViewModel", "=", "new", "IdentityViewModel", "(", "array", "(", "'auth'", "=>", "$", "servies", "->", "get", "(", "$", "config", "[", "'authenticationService'", "]", ")", ",", "'identity'", "=>", "$", "servies", "->", "get", "(", "$", "config", "[", "'identity'", "]", ")", ",", ")", ")", ";", "if", "(", "isset", "(", "$", "config", "[", "'template'", "]", ")", ")", "{", "$", "childViewModel", "->", "setTemplate", "(", "$", "config", "[", "'template'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "config", "[", "'captureTo'", "]", ")", ")", "{", "$", "childViewModel", "->", "setCaptureTo", "(", "$", "config", "[", "'captureTo'", "]", ")", ";", "}", "$", "viewModel", "->", "addChild", "(", "$", "childViewModel", ")", ";", "}", "}" ]
Inject identity view model into layout @param MvcEvent $event @throws \Exception
[ "Inject", "identity", "view", "model", "into", "layout" ]
train
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/ViewModelIdentity.php#L60-L89
FriendsOfApi/phraseapp
src/Api/Key.php
Key.create
public function create(string $projectKey, string $name, array $params = []) { $params['name'] = $name; $response = $this->httpPost(sprintf('/api/v2/projects/%s/keys', $projectKey), $params); if (!$this->hydrator) { return $response; } if ($response->getStatusCode() !== 200 && $response->getStatusCode() !== 201) { $this->handleErrors($response); } return $this->hydrator->hydrate($response, KeyCreated::class); }
php
public function create(string $projectKey, string $name, array $params = []) { $params['name'] = $name; $response = $this->httpPost(sprintf('/api/v2/projects/%s/keys', $projectKey), $params); if (!$this->hydrator) { return $response; } if ($response->getStatusCode() !== 200 && $response->getStatusCode() !== 201) { $this->handleErrors($response); } return $this->hydrator->hydrate($response, KeyCreated::class); }
[ "public", "function", "create", "(", "string", "$", "projectKey", ",", "string", "$", "name", ",", "array", "$", "params", "=", "[", "]", ")", "{", "$", "params", "[", "'name'", "]", "=", "$", "name", ";", "$", "response", "=", "$", "this", "->", "httpPost", "(", "sprintf", "(", "'/api/v2/projects/%s/keys'", ",", "$", "projectKey", ")", ",", "$", "params", ")", ";", "if", "(", "!", "$", "this", "->", "hydrator", ")", "{", "return", "$", "response", ";", "}", "if", "(", "$", "response", "->", "getStatusCode", "(", ")", "!==", "200", "&&", "$", "response", "->", "getStatusCode", "(", ")", "!==", "201", ")", "{", "$", "this", "->", "handleErrors", "(", "$", "response", ")", ";", "}", "return", "$", "this", "->", "hydrator", "->", "hydrate", "(", "$", "response", ",", "KeyCreated", "::", "class", ")", ";", "}" ]
Create a new key. @param string $projectKey @param string $localeId @param array $params @return KeyCreated|ResponseInterface
[ "Create", "a", "new", "key", "." ]
train
https://github.com/FriendsOfApi/phraseapp/blob/1553bf857eb0858f9a7eb905b085864d24f80886/src/Api/Key.php#L30-L45
FriendsOfApi/phraseapp
src/Api/Key.php
Key.search
public function search(string $projectKey, array $params = []) { $q = ''; if (isset($params['tags'])) { $q .= 'tags:'.$params['tags'].' '; } if (isset($params['name'])) { $q .= 'name:'.$params['name'].' '; } if (isset($params['ids'])) { $q .= 'ids:'.$params['ids'].' '; } if (!empty($q)) { $params['q'] = $q; } $response = $this->httpPost(sprintf('/api/v2/projects/%s/keys/search', $projectKey), $params); if (!$this->hydrator) { return $response; } if ($response->getStatusCode() !== 200 && $response->getStatusCode() !== 201) { $this->handleErrors($response); } return $this->hydrator->hydrate($response, KeySearchResults::class); }
php
public function search(string $projectKey, array $params = []) { $q = ''; if (isset($params['tags'])) { $q .= 'tags:'.$params['tags'].' '; } if (isset($params['name'])) { $q .= 'name:'.$params['name'].' '; } if (isset($params['ids'])) { $q .= 'ids:'.$params['ids'].' '; } if (!empty($q)) { $params['q'] = $q; } $response = $this->httpPost(sprintf('/api/v2/projects/%s/keys/search', $projectKey), $params); if (!$this->hydrator) { return $response; } if ($response->getStatusCode() !== 200 && $response->getStatusCode() !== 201) { $this->handleErrors($response); } return $this->hydrator->hydrate($response, KeySearchResults::class); }
[ "public", "function", "search", "(", "string", "$", "projectKey", ",", "array", "$", "params", "=", "[", "]", ")", "{", "$", "q", "=", "''", ";", "if", "(", "isset", "(", "$", "params", "[", "'tags'", "]", ")", ")", "{", "$", "q", ".=", "'tags:'", ".", "$", "params", "[", "'tags'", "]", ".", "' '", ";", "}", "if", "(", "isset", "(", "$", "params", "[", "'name'", "]", ")", ")", "{", "$", "q", ".=", "'name:'", ".", "$", "params", "[", "'name'", "]", ".", "' '", ";", "}", "if", "(", "isset", "(", "$", "params", "[", "'ids'", "]", ")", ")", "{", "$", "q", ".=", "'ids:'", ".", "$", "params", "[", "'ids'", "]", ".", "' '", ";", "}", "if", "(", "!", "empty", "(", "$", "q", ")", ")", "{", "$", "params", "[", "'q'", "]", "=", "$", "q", ";", "}", "$", "response", "=", "$", "this", "->", "httpPost", "(", "sprintf", "(", "'/api/v2/projects/%s/keys/search'", ",", "$", "projectKey", ")", ",", "$", "params", ")", ";", "if", "(", "!", "$", "this", "->", "hydrator", ")", "{", "return", "$", "response", ";", "}", "if", "(", "$", "response", "->", "getStatusCode", "(", ")", "!==", "200", "&&", "$", "response", "->", "getStatusCode", "(", ")", "!==", "201", ")", "{", "$", "this", "->", "handleErrors", "(", "$", "response", ")", ";", "}", "return", "$", "this", "->", "hydrator", "->", "hydrate", "(", "$", "response", ",", "KeySearchResults", "::", "class", ")", ";", "}" ]
Search keys. @param string $projectKey @param array $params @return KeySearchResults|ResponseInterface
[ "Search", "keys", "." ]
train
https://github.com/FriendsOfApi/phraseapp/blob/1553bf857eb0858f9a7eb905b085864d24f80886/src/Api/Key.php#L55-L86
FriendsOfApi/phraseapp
src/Api/Key.php
Key.delete
public function delete(string $projectKey, string $keyId) { $response = $this->httpDelete(sprintf('/api/v2/projects/%s/keys/%s', $projectKey, $keyId)); if (!$this->hydrator) { return $response; } if ($response->getStatusCode() !== 204) { $this->handleErrors($response); } return true; }
php
public function delete(string $projectKey, string $keyId) { $response = $this->httpDelete(sprintf('/api/v2/projects/%s/keys/%s', $projectKey, $keyId)); if (!$this->hydrator) { return $response; } if ($response->getStatusCode() !== 204) { $this->handleErrors($response); } return true; }
[ "public", "function", "delete", "(", "string", "$", "projectKey", ",", "string", "$", "keyId", ")", "{", "$", "response", "=", "$", "this", "->", "httpDelete", "(", "sprintf", "(", "'/api/v2/projects/%s/keys/%s'", ",", "$", "projectKey", ",", "$", "keyId", ")", ")", ";", "if", "(", "!", "$", "this", "->", "hydrator", ")", "{", "return", "$", "response", ";", "}", "if", "(", "$", "response", "->", "getStatusCode", "(", ")", "!==", "204", ")", "{", "$", "this", "->", "handleErrors", "(", "$", "response", ")", ";", "}", "return", "true", ";", "}" ]
Delete a key. @param string $projectKey @param string $keyId @return bool|ResponseInterface
[ "Delete", "a", "key", "." ]
train
https://github.com/FriendsOfApi/phraseapp/blob/1553bf857eb0858f9a7eb905b085864d24f80886/src/Api/Key.php#L96-L109
99designs/ergo-http
src/RequestFactory.php
RequestFactory._getUrl
private function _getUrl() { return new Url(sprintf( '%s://%s:%d%s', $this->_getScheme(), $this->_server['SERVER_NAME'], $this->_getPort(), $this->_uriRelativeToHost($this->_server['REQUEST_URI']) )); }
php
private function _getUrl() { return new Url(sprintf( '%s://%s:%d%s', $this->_getScheme(), $this->_server['SERVER_NAME'], $this->_getPort(), $this->_uriRelativeToHost($this->_server['REQUEST_URI']) )); }
[ "private", "function", "_getUrl", "(", ")", "{", "return", "new", "Url", "(", "sprintf", "(", "'%s://%s:%d%s'", ",", "$", "this", "->", "_getScheme", "(", ")", ",", "$", "this", "->", "_server", "[", "'SERVER_NAME'", "]", ",", "$", "this", "->", "_getPort", "(", ")", ",", "$", "this", "->", "_uriRelativeToHost", "(", "$", "this", "->", "_server", "[", "'REQUEST_URI'", "]", ")", ")", ")", ";", "}" ]
----------------------------------------
[ "----------------------------------------" ]
train
https://github.com/99designs/ergo-http/blob/979b789f2e011a1cb70a00161e6b7bcd0d2e9c71/src/RequestFactory.php#L66-L75
php-lug/lug
src/Bundle/GridBundle/DependencyInjection/Configuration.php
Configuration.getConfigTreeBuilder
public function getConfigTreeBuilder() { $builder = new TreeBuilder(); $root = $builder->root('lug_grid'); $root ->children() ->arrayNode('templates') ->prototype('scalar')->end() ->defaultValue([]) ->end() ->arrayNode('columns') ->addDefaultsIfNotSet() ->children() ->arrayNode('boolean') ->addDefaultsIfNotSet() ->children() ->scalarNode('template')->defaultValue('@LugGrid/Column/boolean.html.twig'); return $builder; }
php
public function getConfigTreeBuilder() { $builder = new TreeBuilder(); $root = $builder->root('lug_grid'); $root ->children() ->arrayNode('templates') ->prototype('scalar')->end() ->defaultValue([]) ->end() ->arrayNode('columns') ->addDefaultsIfNotSet() ->children() ->arrayNode('boolean') ->addDefaultsIfNotSet() ->children() ->scalarNode('template')->defaultValue('@LugGrid/Column/boolean.html.twig'); return $builder; }
[ "public", "function", "getConfigTreeBuilder", "(", ")", "{", "$", "builder", "=", "new", "TreeBuilder", "(", ")", ";", "$", "root", "=", "$", "builder", "->", "root", "(", "'lug_grid'", ")", ";", "$", "root", "->", "children", "(", ")", "->", "arrayNode", "(", "'templates'", ")", "->", "prototype", "(", "'scalar'", ")", "->", "end", "(", ")", "->", "defaultValue", "(", "[", "]", ")", "->", "end", "(", ")", "->", "arrayNode", "(", "'columns'", ")", "->", "addDefaultsIfNotSet", "(", ")", "->", "children", "(", ")", "->", "arrayNode", "(", "'boolean'", ")", "->", "addDefaultsIfNotSet", "(", ")", "->", "children", "(", ")", "->", "scalarNode", "(", "'template'", ")", "->", "defaultValue", "(", "'@LugGrid/Column/boolean.html.twig'", ")", ";", "return", "$", "builder", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/DependencyInjection/Configuration.php#L25-L45
vaibhavpandeyvpz/sandesh
src/Cookie.php
Cookie.withExpiry
public function withExpiry($expiry) { if (null !== $expiry) { MessageValidations::assertCookieExpiry($expiry); } $clone = clone $this; $clone->expiry = MessageValidations::normalizeCookieExpiry($expiry); return $clone; }
php
public function withExpiry($expiry) { if (null !== $expiry) { MessageValidations::assertCookieExpiry($expiry); } $clone = clone $this; $clone->expiry = MessageValidations::normalizeCookieExpiry($expiry); return $clone; }
[ "public", "function", "withExpiry", "(", "$", "expiry", ")", "{", "if", "(", "null", "!==", "$", "expiry", ")", "{", "MessageValidations", "::", "assertCookieExpiry", "(", "$", "expiry", ")", ";", "}", "$", "clone", "=", "clone", "$", "this", ";", "$", "clone", "->", "expiry", "=", "MessageValidations", "::", "normalizeCookieExpiry", "(", "$", "expiry", ")", ";", "return", "$", "clone", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/vaibhavpandeyvpz/sandesh/blob/bea2d06c7cac099ed82da973c922859de4158de0/src/Cookie.php#L148-L156
songshenzong/log
src/DataCollector/RequestCollector.php
RequestCollector.collect
public function collect() { $request = $this->request; $response = $this->response; $responseHeaders = $response->headers->all(); $cookies = []; foreach ($response->headers->getCookies() as $cookie) { $cookies[] = $this->getCookieHeader( $cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly() ); } if (count($cookies) > 0) { $responseHeaders['Set-Cookie'] = $cookies; } $statusCode = $response->getStatusCode(); $data = [ 'format' => $request->getRequestFormat(), 'content_type' => $response->headers->get('Content-Type') ? $response->headers->get( 'Content-Type' ) : 'text/html', 'status_text' => isset(Response::$statusTexts[$statusCode]) ? Response::$statusTexts[$statusCode] : '', 'status_code' => $statusCode, 'path_info' => $request->getPathInfo(), 'query' => $request->query->all(), 'request' => [ 'get' => $GLOBALS['_GET'], 'post' => $GLOBALS['_POST'], ], 'session' => isset($GLOBALS['_SESSION']) ? $GLOBALS['_SESSION'] : '', 'headers' => $request->headers->all(), 'server' => array_change_key_case($request->server->all(), CASE_LOWER), 'cookies' => $request->cookies->all(), 'response_headers' => $responseHeaders, ]; foreach ($data['server'] as $key => $value) { if (str_is('*_KEY', $key) || str_is('*_PASSWORD', $key) || str_is('*_SECRET', $key) || str_is('*_PW', $key) ) { $data['server'][$key] = '******'; } } if (isset($data['headers']['php-auth-pw'])) { $data['headers']['php-auth-pw'] = '******'; } return $data; }
php
public function collect() { $request = $this->request; $response = $this->response; $responseHeaders = $response->headers->all(); $cookies = []; foreach ($response->headers->getCookies() as $cookie) { $cookies[] = $this->getCookieHeader( $cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly() ); } if (count($cookies) > 0) { $responseHeaders['Set-Cookie'] = $cookies; } $statusCode = $response->getStatusCode(); $data = [ 'format' => $request->getRequestFormat(), 'content_type' => $response->headers->get('Content-Type') ? $response->headers->get( 'Content-Type' ) : 'text/html', 'status_text' => isset(Response::$statusTexts[$statusCode]) ? Response::$statusTexts[$statusCode] : '', 'status_code' => $statusCode, 'path_info' => $request->getPathInfo(), 'query' => $request->query->all(), 'request' => [ 'get' => $GLOBALS['_GET'], 'post' => $GLOBALS['_POST'], ], 'session' => isset($GLOBALS['_SESSION']) ? $GLOBALS['_SESSION'] : '', 'headers' => $request->headers->all(), 'server' => array_change_key_case($request->server->all(), CASE_LOWER), 'cookies' => $request->cookies->all(), 'response_headers' => $responseHeaders, ]; foreach ($data['server'] as $key => $value) { if (str_is('*_KEY', $key) || str_is('*_PASSWORD', $key) || str_is('*_SECRET', $key) || str_is('*_PW', $key) ) { $data['server'][$key] = '******'; } } if (isset($data['headers']['php-auth-pw'])) { $data['headers']['php-auth-pw'] = '******'; } return $data; }
[ "public", "function", "collect", "(", ")", "{", "$", "request", "=", "$", "this", "->", "request", ";", "$", "response", "=", "$", "this", "->", "response", ";", "$", "responseHeaders", "=", "$", "response", "->", "headers", "->", "all", "(", ")", ";", "$", "cookies", "=", "[", "]", ";", "foreach", "(", "$", "response", "->", "headers", "->", "getCookies", "(", ")", "as", "$", "cookie", ")", "{", "$", "cookies", "[", "]", "=", "$", "this", "->", "getCookieHeader", "(", "$", "cookie", "->", "getName", "(", ")", ",", "$", "cookie", "->", "getValue", "(", ")", ",", "$", "cookie", "->", "getExpiresTime", "(", ")", ",", "$", "cookie", "->", "getPath", "(", ")", ",", "$", "cookie", "->", "getDomain", "(", ")", ",", "$", "cookie", "->", "isSecure", "(", ")", ",", "$", "cookie", "->", "isHttpOnly", "(", ")", ")", ";", "}", "if", "(", "count", "(", "$", "cookies", ")", ">", "0", ")", "{", "$", "responseHeaders", "[", "'Set-Cookie'", "]", "=", "$", "cookies", ";", "}", "$", "statusCode", "=", "$", "response", "->", "getStatusCode", "(", ")", ";", "$", "data", "=", "[", "'format'", "=>", "$", "request", "->", "getRequestFormat", "(", ")", ",", "'content_type'", "=>", "$", "response", "->", "headers", "->", "get", "(", "'Content-Type'", ")", "?", "$", "response", "->", "headers", "->", "get", "(", "'Content-Type'", ")", ":", "'text/html'", ",", "'status_text'", "=>", "isset", "(", "Response", "::", "$", "statusTexts", "[", "$", "statusCode", "]", ")", "?", "Response", "::", "$", "statusTexts", "[", "$", "statusCode", "]", ":", "''", ",", "'status_code'", "=>", "$", "statusCode", ",", "'path_info'", "=>", "$", "request", "->", "getPathInfo", "(", ")", ",", "'query'", "=>", "$", "request", "->", "query", "->", "all", "(", ")", ",", "'request'", "=>", "[", "'get'", "=>", "$", "GLOBALS", "[", "'_GET'", "]", ",", "'post'", "=>", "$", "GLOBALS", "[", "'_POST'", "]", ",", "]", ",", "'session'", "=>", "isset", "(", "$", "GLOBALS", "[", "'_SESSION'", "]", ")", "?", "$", "GLOBALS", "[", "'_SESSION'", "]", ":", "''", ",", "'headers'", "=>", "$", "request", "->", "headers", "->", "all", "(", ")", ",", "'server'", "=>", "array_change_key_case", "(", "$", "request", "->", "server", "->", "all", "(", ")", ",", "CASE_LOWER", ")", ",", "'cookies'", "=>", "$", "request", "->", "cookies", "->", "all", "(", ")", ",", "'response_headers'", "=>", "$", "responseHeaders", ",", "]", ";", "foreach", "(", "$", "data", "[", "'server'", "]", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "str_is", "(", "'*_KEY'", ",", "$", "key", ")", "||", "str_is", "(", "'*_PASSWORD'", ",", "$", "key", ")", "||", "str_is", "(", "'*_SECRET'", ",", "$", "key", ")", "||", "str_is", "(", "'*_PW'", ",", "$", "key", ")", ")", "{", "$", "data", "[", "'server'", "]", "[", "$", "key", "]", "=", "'******'", ";", "}", "}", "if", "(", "isset", "(", "$", "data", "[", "'headers'", "]", "[", "'php-auth-pw'", "]", ")", ")", "{", "$", "data", "[", "'headers'", "]", "[", "'php-auth-pw'", "]", "=", "'******'", ";", "}", "return", "$", "data", ";", "}" ]
Called by the DebugBar when data needs to be collected @return array Collected data @throws \InvalidArgumentException
[ "Called", "by", "the", "DebugBar", "when", "data", "needs", "to", "be", "collected" ]
train
https://github.com/songshenzong/log/blob/b1e01f7994da47737866eabf82367490eab17c46/src/DataCollector/RequestCollector.php#L55-L115
stk2k/net-driver
src/NetDriver/Curl/CurlNetDriver.php
CurlNetDriver.sendRequest
public function sendRequest(NetDriverHandleInterface $handle, HttpRequest $request) { $url = $request->getUrl(); try{ $ch = $handle->reset(); // set default options curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $this->debug('Set URL: ' . $url); // follow redirection URL curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true); // set max redirection curl_setopt($ch,CURLOPT_MAXREDIRS, self::DEFAULT_MAX_REDIRECTION); // add referer in redirection curl_setopt($ch,CURLOPT_AUTOREFERER,true); // set total timeout curl_setopt($ch, CURLOPT_TIMEOUT_MS, $request->getTotalTimeoutMs()); // set connect timeout curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $request->getConnectTimeoutMs()); // fire event after received HTTP response $request = $this->fireOnSendingRequest($request); // set request header $headers = $request->getHttpHeaders(); $headers_curl = array(); foreach($headers as $key => $value){ $headers_curl[] = "$key: $value"; } curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_curl); $this->debug('HTTP request headers: ' . print_r($headers_curl, true)); // set extra options $extra_options = $request->getExtraOptions(); foreach($extra_options as $opt => $value){ curl_setopt($ch, $opt, $value); } // set proxy options if ($request instanceof HttpProxyRequestInterface){ curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE); curl_setopt($ch, CURLOPT_PROXYPORT, $request->getProxyPort()); $proxy_type = $request->getProxyType(); switch($proxy_type){ case 'http': curl_setopt($ch, CURLOPT_PROXY, 'http://' . $request->getProxyServer()); break; case 'https': curl_setopt($ch, CURLOPT_PROXY, 'https://' . $request->getProxyServer()); break; } $proxy_auth = $request->getProxyAuth(); if (!empty($proxy_auth)){ curl_setopt($ch, CURLOPT_PROXYAUTH, $proxy_auth); curl_setopt($ch, CURLOPT_PROXYUSERPWD, $request->getProxyUserPassword()); } else{ curl_setopt($ch, CURLOPT_PROXYUSERPWD, "anonymous:"); } } // set custome request if ($request instanceof HttpPostRequest){ //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, EnumHttpMethod::POST); $this->debug('Method: POST'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $request->getPostFields()); $this->debug('POST fields: ' . print_r($request->getPostFields(), true)); } else if ($request instanceof HttpPutRequest){ $this->debug('Method: PUT'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request->getMethod()); curl_setopt($ch, CURLOPT_POSTFIELDS, $request->getPutFields()); } else{ $method = $request->getMethod(); $this->debug('Method: ' . $method); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); } // verbose $verbose = $this->getVerbose() | $request->getVerbose(); curl_setopt($ch, CURLOPT_VERBOSE, $verbose ? 1 : 0); // verbose output $strerr_file = new CurlOutputFile(); curl_setopt($ch, CURLOPT_STDERR, $strerr_file->handle()); $header_file = new CurlOutputFile(); curl_setopt($ch, CURLOPT_WRITEHEADER, $header_file->handle()); $output_file = new CurlOutputFile(); curl_setopt($ch, CURLOPT_FILE, $output_file->handle()); // send request $result = curl_exec($ch); $this->debug('curl_exec result: ' . $result); // get verbose output $strerr = $strerr_file->readAll(); $header = $header_file->readAll(); $output = $output_file->readAll(); $this->debug('strerr: ' . $strerr); $this->debug('header: ' . $header); $this->debug('output: ' . $output); // fire event after received verbose $this->fireOnReceivedVerbose($strerr, $header, $output); if ($result === false) { switch(curl_errno($ch)) { case CURLE_OPERATION_TIMEDOUT: throw new TimeoutException($request); break; } throw new CurlException('curl_exec', $ch); } // get response $info = curl_getinfo ($ch); $response = new CurlResponse($info, $output); $this->debug('status code: ' . $response->getStatusCode()); $this->debug('response headers: ' . $response->getHeaders()); // fire event after received HTTP response $this->fireOnReceivedResponse($response); return $response; } catch (CurlException $e){ throw new NetDriverException($url, $e); } }
php
public function sendRequest(NetDriverHandleInterface $handle, HttpRequest $request) { $url = $request->getUrl(); try{ $ch = $handle->reset(); // set default options curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $this->debug('Set URL: ' . $url); // follow redirection URL curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true); // set max redirection curl_setopt($ch,CURLOPT_MAXREDIRS, self::DEFAULT_MAX_REDIRECTION); // add referer in redirection curl_setopt($ch,CURLOPT_AUTOREFERER,true); // set total timeout curl_setopt($ch, CURLOPT_TIMEOUT_MS, $request->getTotalTimeoutMs()); // set connect timeout curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $request->getConnectTimeoutMs()); // fire event after received HTTP response $request = $this->fireOnSendingRequest($request); // set request header $headers = $request->getHttpHeaders(); $headers_curl = array(); foreach($headers as $key => $value){ $headers_curl[] = "$key: $value"; } curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_curl); $this->debug('HTTP request headers: ' . print_r($headers_curl, true)); // set extra options $extra_options = $request->getExtraOptions(); foreach($extra_options as $opt => $value){ curl_setopt($ch, $opt, $value); } // set proxy options if ($request instanceof HttpProxyRequestInterface){ curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE); curl_setopt($ch, CURLOPT_PROXYPORT, $request->getProxyPort()); $proxy_type = $request->getProxyType(); switch($proxy_type){ case 'http': curl_setopt($ch, CURLOPT_PROXY, 'http://' . $request->getProxyServer()); break; case 'https': curl_setopt($ch, CURLOPT_PROXY, 'https://' . $request->getProxyServer()); break; } $proxy_auth = $request->getProxyAuth(); if (!empty($proxy_auth)){ curl_setopt($ch, CURLOPT_PROXYAUTH, $proxy_auth); curl_setopt($ch, CURLOPT_PROXYUSERPWD, $request->getProxyUserPassword()); } else{ curl_setopt($ch, CURLOPT_PROXYUSERPWD, "anonymous:"); } } // set custome request if ($request instanceof HttpPostRequest){ //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, EnumHttpMethod::POST); $this->debug('Method: POST'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $request->getPostFields()); $this->debug('POST fields: ' . print_r($request->getPostFields(), true)); } else if ($request instanceof HttpPutRequest){ $this->debug('Method: PUT'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request->getMethod()); curl_setopt($ch, CURLOPT_POSTFIELDS, $request->getPutFields()); } else{ $method = $request->getMethod(); $this->debug('Method: ' . $method); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); } // verbose $verbose = $this->getVerbose() | $request->getVerbose(); curl_setopt($ch, CURLOPT_VERBOSE, $verbose ? 1 : 0); // verbose output $strerr_file = new CurlOutputFile(); curl_setopt($ch, CURLOPT_STDERR, $strerr_file->handle()); $header_file = new CurlOutputFile(); curl_setopt($ch, CURLOPT_WRITEHEADER, $header_file->handle()); $output_file = new CurlOutputFile(); curl_setopt($ch, CURLOPT_FILE, $output_file->handle()); // send request $result = curl_exec($ch); $this->debug('curl_exec result: ' . $result); // get verbose output $strerr = $strerr_file->readAll(); $header = $header_file->readAll(); $output = $output_file->readAll(); $this->debug('strerr: ' . $strerr); $this->debug('header: ' . $header); $this->debug('output: ' . $output); // fire event after received verbose $this->fireOnReceivedVerbose($strerr, $header, $output); if ($result === false) { switch(curl_errno($ch)) { case CURLE_OPERATION_TIMEDOUT: throw new TimeoutException($request); break; } throw new CurlException('curl_exec', $ch); } // get response $info = curl_getinfo ($ch); $response = new CurlResponse($info, $output); $this->debug('status code: ' . $response->getStatusCode()); $this->debug('response headers: ' . $response->getHeaders()); // fire event after received HTTP response $this->fireOnReceivedResponse($response); return $response; } catch (CurlException $e){ throw new NetDriverException($url, $e); } }
[ "public", "function", "sendRequest", "(", "NetDriverHandleInterface", "$", "handle", ",", "HttpRequest", "$", "request", ")", "{", "$", "url", "=", "$", "request", "->", "getUrl", "(", ")", ";", "try", "{", "$", "ch", "=", "$", "handle", "->", "reset", "(", ")", ";", "// set default options", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_URL", ",", "$", "url", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_HEADER", ",", "true", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_RETURNTRANSFER", ",", "true", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_SSL_VERIFYPEER", ",", "false", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_SSL_VERIFYHOST", ",", "false", ")", ";", "$", "this", "->", "debug", "(", "'Set URL: '", ".", "$", "url", ")", ";", "// follow redirection URL", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_FOLLOWLOCATION", ",", "true", ")", ";", "// set max redirection", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_MAXREDIRS", ",", "self", "::", "DEFAULT_MAX_REDIRECTION", ")", ";", "// add referer in redirection", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_AUTOREFERER", ",", "true", ")", ";", "// set total timeout", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_TIMEOUT_MS", ",", "$", "request", "->", "getTotalTimeoutMs", "(", ")", ")", ";", "// set connect timeout", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_CONNECTTIMEOUT_MS", ",", "$", "request", "->", "getConnectTimeoutMs", "(", ")", ")", ";", "// fire event after received HTTP response", "$", "request", "=", "$", "this", "->", "fireOnSendingRequest", "(", "$", "request", ")", ";", "// set request header", "$", "headers", "=", "$", "request", "->", "getHttpHeaders", "(", ")", ";", "$", "headers_curl", "=", "array", "(", ")", ";", "foreach", "(", "$", "headers", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "headers_curl", "[", "]", "=", "\"$key: $value\"", ";", "}", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_HTTPHEADER", ",", "$", "headers_curl", ")", ";", "$", "this", "->", "debug", "(", "'HTTP request headers: '", ".", "print_r", "(", "$", "headers_curl", ",", "true", ")", ")", ";", "// set extra options", "$", "extra_options", "=", "$", "request", "->", "getExtraOptions", "(", ")", ";", "foreach", "(", "$", "extra_options", "as", "$", "opt", "=>", "$", "value", ")", "{", "curl_setopt", "(", "$", "ch", ",", "$", "opt", ",", "$", "value", ")", ";", "}", "// set proxy options", "if", "(", "$", "request", "instanceof", "HttpProxyRequestInterface", ")", "{", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_HTTPPROXYTUNNEL", ",", "TRUE", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_PROXYPORT", ",", "$", "request", "->", "getProxyPort", "(", ")", ")", ";", "$", "proxy_type", "=", "$", "request", "->", "getProxyType", "(", ")", ";", "switch", "(", "$", "proxy_type", ")", "{", "case", "'http'", ":", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_PROXY", ",", "'http://'", ".", "$", "request", "->", "getProxyServer", "(", ")", ")", ";", "break", ";", "case", "'https'", ":", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_PROXY", ",", "'https://'", ".", "$", "request", "->", "getProxyServer", "(", ")", ")", ";", "break", ";", "}", "$", "proxy_auth", "=", "$", "request", "->", "getProxyAuth", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "proxy_auth", ")", ")", "{", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_PROXYAUTH", ",", "$", "proxy_auth", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_PROXYUSERPWD", ",", "$", "request", "->", "getProxyUserPassword", "(", ")", ")", ";", "}", "else", "{", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_PROXYUSERPWD", ",", "\"anonymous:\"", ")", ";", "}", "}", "// set custome request", "if", "(", "$", "request", "instanceof", "HttpPostRequest", ")", "{", "//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, EnumHttpMethod::POST);", "$", "this", "->", "debug", "(", "'Method: POST'", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_POST", ",", "1", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_POSTFIELDS", ",", "$", "request", "->", "getPostFields", "(", ")", ")", ";", "$", "this", "->", "debug", "(", "'POST fields: '", ".", "print_r", "(", "$", "request", "->", "getPostFields", "(", ")", ",", "true", ")", ")", ";", "}", "else", "if", "(", "$", "request", "instanceof", "HttpPutRequest", ")", "{", "$", "this", "->", "debug", "(", "'Method: PUT'", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_CUSTOMREQUEST", ",", "$", "request", "->", "getMethod", "(", ")", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_POSTFIELDS", ",", "$", "request", "->", "getPutFields", "(", ")", ")", ";", "}", "else", "{", "$", "method", "=", "$", "request", "->", "getMethod", "(", ")", ";", "$", "this", "->", "debug", "(", "'Method: '", ".", "$", "method", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_CUSTOMREQUEST", ",", "$", "method", ")", ";", "}", "// verbose", "$", "verbose", "=", "$", "this", "->", "getVerbose", "(", ")", "|", "$", "request", "->", "getVerbose", "(", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_VERBOSE", ",", "$", "verbose", "?", "1", ":", "0", ")", ";", "// verbose output", "$", "strerr_file", "=", "new", "CurlOutputFile", "(", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_STDERR", ",", "$", "strerr_file", "->", "handle", "(", ")", ")", ";", "$", "header_file", "=", "new", "CurlOutputFile", "(", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_WRITEHEADER", ",", "$", "header_file", "->", "handle", "(", ")", ")", ";", "$", "output_file", "=", "new", "CurlOutputFile", "(", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_FILE", ",", "$", "output_file", "->", "handle", "(", ")", ")", ";", "// send request", "$", "result", "=", "curl_exec", "(", "$", "ch", ")", ";", "$", "this", "->", "debug", "(", "'curl_exec result: '", ".", "$", "result", ")", ";", "// get verbose output", "$", "strerr", "=", "$", "strerr_file", "->", "readAll", "(", ")", ";", "$", "header", "=", "$", "header_file", "->", "readAll", "(", ")", ";", "$", "output", "=", "$", "output_file", "->", "readAll", "(", ")", ";", "$", "this", "->", "debug", "(", "'strerr: '", ".", "$", "strerr", ")", ";", "$", "this", "->", "debug", "(", "'header: '", ".", "$", "header", ")", ";", "$", "this", "->", "debug", "(", "'output: '", ".", "$", "output", ")", ";", "// fire event after received verbose", "$", "this", "->", "fireOnReceivedVerbose", "(", "$", "strerr", ",", "$", "header", ",", "$", "output", ")", ";", "if", "(", "$", "result", "===", "false", ")", "{", "switch", "(", "curl_errno", "(", "$", "ch", ")", ")", "{", "case", "CURLE_OPERATION_TIMEDOUT", ":", "throw", "new", "TimeoutException", "(", "$", "request", ")", ";", "break", ";", "}", "throw", "new", "CurlException", "(", "'curl_exec'", ",", "$", "ch", ")", ";", "}", "// get response", "$", "info", "=", "curl_getinfo", "(", "$", "ch", ")", ";", "$", "response", "=", "new", "CurlResponse", "(", "$", "info", ",", "$", "output", ")", ";", "$", "this", "->", "debug", "(", "'status code: '", ".", "$", "response", "->", "getStatusCode", "(", ")", ")", ";", "$", "this", "->", "debug", "(", "'response headers: '", ".", "$", "response", "->", "getHeaders", "(", ")", ")", ";", "// fire event after received HTTP response", "$", "this", "->", "fireOnReceivedResponse", "(", "$", "response", ")", ";", "return", "$", "response", ";", "}", "catch", "(", "CurlException", "$", "e", ")", "{", "throw", "new", "NetDriverException", "(", "$", "url", ",", "$", "e", ")", ";", "}", "}" ]
Send HTTP request @param NetDriverHandleInterface $handle @param HttpRequest $request @return HttpResponse @throws NetDriverException @throws TimeoutException @throws DeflateException
[ "Send", "HTTP", "request" ]
train
https://github.com/stk2k/net-driver/blob/75e0bc1a95ba430dd9ed9e69f6a0a5dd8f2e7b1c/src/NetDriver/Curl/CurlNetDriver.php#L43-L192
phpgears/dto
src/ScalarPayloadBehaviour.php
ScalarPayloadBehaviour.setPayloadParameter
private function setPayloadParameter(string $parameter, $value): void { $this->checkParameterType($value); $this->defaultSetPayloadParameter($parameter, $value); }
php
private function setPayloadParameter(string $parameter, $value): void { $this->checkParameterType($value); $this->defaultSetPayloadParameter($parameter, $value); }
[ "private", "function", "setPayloadParameter", "(", "string", "$", "parameter", ",", "$", "value", ")", ":", "void", "{", "$", "this", "->", "checkParameterType", "(", "$", "value", ")", ";", "$", "this", "->", "defaultSetPayloadParameter", "(", "$", "parameter", ",", "$", "value", ")", ";", "}" ]
Set payload parameter. @param string $parameter @param mixed $value
[ "Set", "payload", "parameter", "." ]
train
https://github.com/phpgears/dto/blob/404b2cdea108538b55caa261c29280062dd0e3db/src/ScalarPayloadBehaviour.php#L33-L38
phpgears/dto
src/ScalarPayloadBehaviour.php
ScalarPayloadBehaviour.checkParameterType
final protected function checkParameterType($value): void { if (\is_array($value)) { foreach ($value as $val) { $this->checkParameterType($val); } } elseif ($value !== null && !\is_scalar($value)) { throw new InvalidScalarParameterException(\sprintf( 'Class %s can only accept scalar payload parameters, %s given', self::class, \is_object($value) ? \get_class($value) : \gettype($value) )); } }
php
final protected function checkParameterType($value): void { if (\is_array($value)) { foreach ($value as $val) { $this->checkParameterType($val); } } elseif ($value !== null && !\is_scalar($value)) { throw new InvalidScalarParameterException(\sprintf( 'Class %s can only accept scalar payload parameters, %s given', self::class, \is_object($value) ? \get_class($value) : \gettype($value) )); } }
[ "final", "protected", "function", "checkParameterType", "(", "$", "value", ")", ":", "void", "{", "if", "(", "\\", "is_array", "(", "$", "value", ")", ")", "{", "foreach", "(", "$", "value", "as", "$", "val", ")", "{", "$", "this", "->", "checkParameterType", "(", "$", "val", ")", ";", "}", "}", "elseif", "(", "$", "value", "!==", "null", "&&", "!", "\\", "is_scalar", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidScalarParameterException", "(", "\\", "sprintf", "(", "'Class %s can only accept scalar payload parameters, %s given'", ",", "self", "::", "class", ",", "\\", "is_object", "(", "$", "value", ")", "?", "\\", "get_class", "(", "$", "value", ")", ":", "\\", "gettype", "(", "$", "value", ")", ")", ")", ";", "}", "}" ]
Check only scalar types allowed. @param mixed $value @throws InvalidScalarParameterException
[ "Check", "only", "scalar", "types", "allowed", "." ]
train
https://github.com/phpgears/dto/blob/404b2cdea108538b55caa261c29280062dd0e3db/src/ScalarPayloadBehaviour.php#L47-L60
petrica/php-statsd-system
Model/Process/TopProcessParser.php
TopProcessParser.parse
public function parse() { $raw = $this->getRaw(); $count = count($raw); for ($i = 7; $i < $count; $i++) { $line = $raw[$i]; $process = new Process( $line[11], $line[0], floatval($line[8]), floatval($line[9]) ); $this->processes[] = $process; } }
php
public function parse() { $raw = $this->getRaw(); $count = count($raw); for ($i = 7; $i < $count; $i++) { $line = $raw[$i]; $process = new Process( $line[11], $line[0], floatval($line[8]), floatval($line[9]) ); $this->processes[] = $process; } }
[ "public", "function", "parse", "(", ")", "{", "$", "raw", "=", "$", "this", "->", "getRaw", "(", ")", ";", "$", "count", "=", "count", "(", "$", "raw", ")", ";", "for", "(", "$", "i", "=", "7", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "$", "line", "=", "$", "raw", "[", "$", "i", "]", ";", "$", "process", "=", "new", "Process", "(", "$", "line", "[", "11", "]", ",", "$", "line", "[", "0", "]", ",", "floatval", "(", "$", "line", "[", "8", "]", ")", ",", "floatval", "(", "$", "line", "[", "9", "]", ")", ")", ";", "$", "this", "->", "processes", "[", "]", "=", "$", "process", ";", "}", "}" ]
Run the parsing process
[ "Run", "the", "parsing", "process" ]
train
https://github.com/petrica/php-statsd-system/blob/c476be3514a631a605737888bb8f6eb096789c9d/Model/Process/TopProcessParser.php#L37-L53
nabab/bbn
src/bbn/file/system.php
system._connect_ftp
private function _connect_ftp(array $cfg): bool { if ( isset($cfg['host'], $cfg['user'], $cfg['pass']) ){ $args = [$cfg['host'], $cfg['port'] ?? 21, $cfg['timeout'] ?? 3]; try { $this->stream = ftp_ssl_connect(...$args); } catch ( \Exception $e ){ $this->error = _('Impossible to connect to the FTP host'); $this->error .= PHP_EOL.$e->getMessage(); } if ( $this->stream ){ if ( !@ftp_login($this->stream, $cfg['user'], $cfg['pass']) ){ try { $this->stream = ftp_connect(...$args); } catch ( \Exception $e ){ $this->error = _('Impossible to connect to the FTP host'); $this->error .= PHP_EOL.$e->getMessage(); } if ( !@ftp_login($this->stream, $cfg['user'], $cfg['pass']) ){ $this->error = _('Impossible to login to the FTP host'); $this->error .= PHP_EOL.error_get_last()['message']; } } if ( !$this->error ){ $this->current = ftp_pwd($this->stream); if ( !empty($cfg['passive']) || (defined('BBN_SERVER_NAME') && !@fsockopen(BBN_SERVER_NAME, $args[1])) ){ ftp_pasv($this->stream, true); } return true; } } } return false; }
php
private function _connect_ftp(array $cfg): bool { if ( isset($cfg['host'], $cfg['user'], $cfg['pass']) ){ $args = [$cfg['host'], $cfg['port'] ?? 21, $cfg['timeout'] ?? 3]; try { $this->stream = ftp_ssl_connect(...$args); } catch ( \Exception $e ){ $this->error = _('Impossible to connect to the FTP host'); $this->error .= PHP_EOL.$e->getMessage(); } if ( $this->stream ){ if ( !@ftp_login($this->stream, $cfg['user'], $cfg['pass']) ){ try { $this->stream = ftp_connect(...$args); } catch ( \Exception $e ){ $this->error = _('Impossible to connect to the FTP host'); $this->error .= PHP_EOL.$e->getMessage(); } if ( !@ftp_login($this->stream, $cfg['user'], $cfg['pass']) ){ $this->error = _('Impossible to login to the FTP host'); $this->error .= PHP_EOL.error_get_last()['message']; } } if ( !$this->error ){ $this->current = ftp_pwd($this->stream); if ( !empty($cfg['passive']) || (defined('BBN_SERVER_NAME') && !@fsockopen(BBN_SERVER_NAME, $args[1])) ){ ftp_pasv($this->stream, true); } return true; } } } return false; }
[ "private", "function", "_connect_ftp", "(", "array", "$", "cfg", ")", ":", "bool", "{", "if", "(", "isset", "(", "$", "cfg", "[", "'host'", "]", ",", "$", "cfg", "[", "'user'", "]", ",", "$", "cfg", "[", "'pass'", "]", ")", ")", "{", "$", "args", "=", "[", "$", "cfg", "[", "'host'", "]", ",", "$", "cfg", "[", "'port'", "]", "??", "21", ",", "$", "cfg", "[", "'timeout'", "]", "??", "3", "]", ";", "try", "{", "$", "this", "->", "stream", "=", "ftp_ssl_connect", "(", "...", "$", "args", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "error", "=", "_", "(", "'Impossible to connect to the FTP host'", ")", ";", "$", "this", "->", "error", ".=", "PHP_EOL", ".", "$", "e", "->", "getMessage", "(", ")", ";", "}", "if", "(", "$", "this", "->", "stream", ")", "{", "if", "(", "!", "@", "ftp_login", "(", "$", "this", "->", "stream", ",", "$", "cfg", "[", "'user'", "]", ",", "$", "cfg", "[", "'pass'", "]", ")", ")", "{", "try", "{", "$", "this", "->", "stream", "=", "ftp_connect", "(", "...", "$", "args", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "error", "=", "_", "(", "'Impossible to connect to the FTP host'", ")", ";", "$", "this", "->", "error", ".=", "PHP_EOL", ".", "$", "e", "->", "getMessage", "(", ")", ";", "}", "if", "(", "!", "@", "ftp_login", "(", "$", "this", "->", "stream", ",", "$", "cfg", "[", "'user'", "]", ",", "$", "cfg", "[", "'pass'", "]", ")", ")", "{", "$", "this", "->", "error", "=", "_", "(", "'Impossible to login to the FTP host'", ")", ";", "$", "this", "->", "error", ".=", "PHP_EOL", ".", "error_get_last", "(", ")", "[", "'message'", "]", ";", "}", "}", "if", "(", "!", "$", "this", "->", "error", ")", "{", "$", "this", "->", "current", "=", "ftp_pwd", "(", "$", "this", "->", "stream", ")", ";", "if", "(", "!", "empty", "(", "$", "cfg", "[", "'passive'", "]", ")", "||", "(", "defined", "(", "'BBN_SERVER_NAME'", ")", "&&", "!", "@", "fsockopen", "(", "BBN_SERVER_NAME", ",", "$", "args", "[", "1", "]", ")", ")", ")", "{", "ftp_pasv", "(", "$", "this", "->", "stream", ",", "true", ")", ";", "}", "return", "true", ";", "}", "}", "}", "return", "false", ";", "}" ]
Connect to FTP @param array $cfg @return bool
[ "Connect", "to", "FTP" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/system.php#L56-L94
nabab/bbn
src/bbn/file/system.php
system._connect_ssh
private function _connect_ssh(array $cfg): bool { if ( isset($cfg['host']) ){ $param = []; if ( isset($cfg['public'], $cfg['private']) ){ $param['hostkey'] = 'ssh-rsa'; } $this->cn = @ssh2_connect($cfg['host'], $cfg['port'] ?? 22, $param, [ 'debug' => function($message, $language, $always_display){ bbn\x::log([$message, $language, $always_display]); }, 'disconnect' => function($reason, $message, $language){ bbn\x::log([$reason, $message, $language]); } ]); if ( !$this->cn ){ $this->error = _("Could not connect through SSH."); } else if ( isset($cfg['user'], $cfg['public'], $cfg['private']) ){ /* $fingerprint = ssh2_fingerprint($this->cn, SSH2_FINGERPRINT_MD5 | SSH2_FINGERPRINT_HEX); if ( strcmp($this->ssh_server_fp, $fingerprint) !== 0 ){ $this->error = _('Unable to verify server identity!'); } */ if ( !ssh2_auth_pubkey_file($this->cn, $cfg['user'], $cfg['public'], $cfg['private'], $cfg['pass'] ?? null) ){ $this->error = _('Authentication rejected by server'); } else if ( $this->stream = @ssh2_sftp($this->cn) ){ $this->current = ssh2_sftp_realpath($this->stream, '.'); return true; } else{ $this->error = _("Could not connect through SFTP."); } } else if ( isset($cfg['user'], $cfg['pass']) && @ssh2_auth_password($this->cn, $cfg['user'], $cfg['pass']) ){ //die(_("Could not authenticate with username and password.")); $this->stream = @ssh2_sftp($this->cn); if ( $this->stream ){ $this->current = ssh2_sftp_realpath($this->stream, '.'); return true; } $this->error = _("Could not initialize SFTP subsystem."); } else{ $this->error = _("Could not authenticate with username and password."); } } return false; }
php
private function _connect_ssh(array $cfg): bool { if ( isset($cfg['host']) ){ $param = []; if ( isset($cfg['public'], $cfg['private']) ){ $param['hostkey'] = 'ssh-rsa'; } $this->cn = @ssh2_connect($cfg['host'], $cfg['port'] ?? 22, $param, [ 'debug' => function($message, $language, $always_display){ bbn\x::log([$message, $language, $always_display]); }, 'disconnect' => function($reason, $message, $language){ bbn\x::log([$reason, $message, $language]); } ]); if ( !$this->cn ){ $this->error = _("Could not connect through SSH."); } else if ( isset($cfg['user'], $cfg['public'], $cfg['private']) ){ /* $fingerprint = ssh2_fingerprint($this->cn, SSH2_FINGERPRINT_MD5 | SSH2_FINGERPRINT_HEX); if ( strcmp($this->ssh_server_fp, $fingerprint) !== 0 ){ $this->error = _('Unable to verify server identity!'); } */ if ( !ssh2_auth_pubkey_file($this->cn, $cfg['user'], $cfg['public'], $cfg['private'], $cfg['pass'] ?? null) ){ $this->error = _('Authentication rejected by server'); } else if ( $this->stream = @ssh2_sftp($this->cn) ){ $this->current = ssh2_sftp_realpath($this->stream, '.'); return true; } else{ $this->error = _("Could not connect through SFTP."); } } else if ( isset($cfg['user'], $cfg['pass']) && @ssh2_auth_password($this->cn, $cfg['user'], $cfg['pass']) ){ //die(_("Could not authenticate with username and password.")); $this->stream = @ssh2_sftp($this->cn); if ( $this->stream ){ $this->current = ssh2_sftp_realpath($this->stream, '.'); return true; } $this->error = _("Could not initialize SFTP subsystem."); } else{ $this->error = _("Could not authenticate with username and password."); } } return false; }
[ "private", "function", "_connect_ssh", "(", "array", "$", "cfg", ")", ":", "bool", "{", "if", "(", "isset", "(", "$", "cfg", "[", "'host'", "]", ")", ")", "{", "$", "param", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "cfg", "[", "'public'", "]", ",", "$", "cfg", "[", "'private'", "]", ")", ")", "{", "$", "param", "[", "'hostkey'", "]", "=", "'ssh-rsa'", ";", "}", "$", "this", "->", "cn", "=", "@", "ssh2_connect", "(", "$", "cfg", "[", "'host'", "]", ",", "$", "cfg", "[", "'port'", "]", "??", "22", ",", "$", "param", ",", "[", "'debug'", "=>", "function", "(", "$", "message", ",", "$", "language", ",", "$", "always_display", ")", "{", "bbn", "\\", "x", "::", "log", "(", "[", "$", "message", ",", "$", "language", ",", "$", "always_display", "]", ")", ";", "}", ",", "'disconnect'", "=>", "function", "(", "$", "reason", ",", "$", "message", ",", "$", "language", ")", "{", "bbn", "\\", "x", "::", "log", "(", "[", "$", "reason", ",", "$", "message", ",", "$", "language", "]", ")", ";", "}", "]", ")", ";", "if", "(", "!", "$", "this", "->", "cn", ")", "{", "$", "this", "->", "error", "=", "_", "(", "\"Could not connect through SSH.\"", ")", ";", "}", "else", "if", "(", "isset", "(", "$", "cfg", "[", "'user'", "]", ",", "$", "cfg", "[", "'public'", "]", ",", "$", "cfg", "[", "'private'", "]", ")", ")", "{", "/*\n $fingerprint = ssh2_fingerprint($this->cn, SSH2_FINGERPRINT_MD5 | SSH2_FINGERPRINT_HEX);\n if ( strcmp($this->ssh_server_fp, $fingerprint) !== 0 ){\n $this->error = _('Unable to verify server identity!');\n }\n */", "if", "(", "!", "ssh2_auth_pubkey_file", "(", "$", "this", "->", "cn", ",", "$", "cfg", "[", "'user'", "]", ",", "$", "cfg", "[", "'public'", "]", ",", "$", "cfg", "[", "'private'", "]", ",", "$", "cfg", "[", "'pass'", "]", "??", "null", ")", ")", "{", "$", "this", "->", "error", "=", "_", "(", "'Authentication rejected by server'", ")", ";", "}", "else", "if", "(", "$", "this", "->", "stream", "=", "@", "ssh2_sftp", "(", "$", "this", "->", "cn", ")", ")", "{", "$", "this", "->", "current", "=", "ssh2_sftp_realpath", "(", "$", "this", "->", "stream", ",", "'.'", ")", ";", "return", "true", ";", "}", "else", "{", "$", "this", "->", "error", "=", "_", "(", "\"Could not connect through SFTP.\"", ")", ";", "}", "}", "else", "if", "(", "isset", "(", "$", "cfg", "[", "'user'", "]", ",", "$", "cfg", "[", "'pass'", "]", ")", "&&", "@", "ssh2_auth_password", "(", "$", "this", "->", "cn", ",", "$", "cfg", "[", "'user'", "]", ",", "$", "cfg", "[", "'pass'", "]", ")", ")", "{", "//die(_(\"Could not authenticate with username and password.\"));", "$", "this", "->", "stream", "=", "@", "ssh2_sftp", "(", "$", "this", "->", "cn", ")", ";", "if", "(", "$", "this", "->", "stream", ")", "{", "$", "this", "->", "current", "=", "ssh2_sftp_realpath", "(", "$", "this", "->", "stream", ",", "'.'", ")", ";", "return", "true", ";", "}", "$", "this", "->", "error", "=", "_", "(", "\"Could not initialize SFTP subsystem.\"", ")", ";", "}", "else", "{", "$", "this", "->", "error", "=", "_", "(", "\"Could not authenticate with username and password.\"", ")", ";", "}", "}", "return", "false", ";", "}" ]
Connects to SSH @param array $cfg @return bool
[ "Connects", "to", "SSH" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/system.php#L101-L151
nabab/bbn
src/bbn/file/system.php
system._get_items
private function _get_items(string $path, $type = 'both', bool $hidden = false, string $detailed = ''): array { $files = []; if ( ($this->mode === 'ftp') && ($detailed || ($type !== 'both')) ){ if ( $fs = ftp_mlsd($this->stream, substr($path, strlen($this->prefix))) ){ foreach ( $fs as $f ){ if ( ($f['name'] !== '.') && ($f['name'] !== '..') && ($hidden || (strpos(basename($f['name']), '.') !== 0)) ){ $ok = 0; if ( $type === 'both' ){ $ok = 1; } else if ( $type === 'dir' ){ $ok = $f['type'] === 'dir'; } else if ( $type === 'file' ){ $ok = $f['type'] === 'file'; } else if ( !is_string($type) || is_file($path.'/'.$f['name']) ){ $ok = $this->_check_filter($f['name'], $type); } if ( $ok ){ if ( $detailed ){ if ( !isset($has_type, $has_mod) ){ $has_type = stripos($detailed, 't') !== false; $has_mod = stripos($detailed, 'm') !== false; } $tmp = [ 'path' => $path.'/'.$f['name'] ]; if ( $has_mod ){ $tmp['mtime'] = mktime( substr($f['modify'], 8, 2), substr($f['modify'], 10, 2), substr($f['modify'], 12, 2), substr($f['modify'], 4, 2), substr($f['modify'], 6, 2), substr($f['modify'], 0, 4) ); } if ( $has_type ){ $tmp['dir'] = $f['type'] === 'dir'; $tmp['file'] = $f['type'] !== 'dir'; } $files[] = $tmp; } else{ $files[] = $path.'/'.$f['name']; } } } } } else{ bbn\x::log(error_get_last(), 'filesystem'); } } else{ $fs = scandir($path, SCANDIR_SORT_ASCENDING); foreach ( $fs as $f ){ if ( ($f !== '.') && ($f !== '..') && ($hidden || (strpos(basename($f), '.') !== 0)) ){ $ok = 0; $is_dir = null; $is_file = null; if ( $type === 'both' ){ $ok = 1; } else if ( $type === 'dir' ){ if ( $ok = is_dir($path.'/'.$f) ){ $is_dir = $ok; $is_file = !$ok; } } else if ( $type === 'file' ){ if ( $ok = is_file($path.'/'.$f) ){ $is_file = $ok; $is_dir = !$ok; } } else if ( !is_string($type) || is_file($path.'/'.$f) ){ $ok = $this->_check_filter($f, $type); $is_file = true; $is_dir = false; } if ( $ok ){ if ( $detailed ){ if ( !isset($has_type, $has_mod) ){ $has_type = stripos($detailed, 't') !== false; $has_mod = stripos($detailed, 'm') !== false; } $tmp = [ 'path' => $path.'/'.$f ]; if ( $has_mod ){ $tmp['mtime'] = filemtime($path.'/'.$f); } if ( $has_type ){ $tmp['dir'] = $is_dir ?? is_dir($path.'/'.$f); $tmp['file'] = $is_file ?? is_file($path.'/'.$f); } $files[] = $tmp; } else { $files[] = $path.'/'.$f; } } } } } if ( \count($files) > 0 ){ //bbn\x::sort($files, 'real'); } return $files; }
php
private function _get_items(string $path, $type = 'both', bool $hidden = false, string $detailed = ''): array { $files = []; if ( ($this->mode === 'ftp') && ($detailed || ($type !== 'both')) ){ if ( $fs = ftp_mlsd($this->stream, substr($path, strlen($this->prefix))) ){ foreach ( $fs as $f ){ if ( ($f['name'] !== '.') && ($f['name'] !== '..') && ($hidden || (strpos(basename($f['name']), '.') !== 0)) ){ $ok = 0; if ( $type === 'both' ){ $ok = 1; } else if ( $type === 'dir' ){ $ok = $f['type'] === 'dir'; } else if ( $type === 'file' ){ $ok = $f['type'] === 'file'; } else if ( !is_string($type) || is_file($path.'/'.$f['name']) ){ $ok = $this->_check_filter($f['name'], $type); } if ( $ok ){ if ( $detailed ){ if ( !isset($has_type, $has_mod) ){ $has_type = stripos($detailed, 't') !== false; $has_mod = stripos($detailed, 'm') !== false; } $tmp = [ 'path' => $path.'/'.$f['name'] ]; if ( $has_mod ){ $tmp['mtime'] = mktime( substr($f['modify'], 8, 2), substr($f['modify'], 10, 2), substr($f['modify'], 12, 2), substr($f['modify'], 4, 2), substr($f['modify'], 6, 2), substr($f['modify'], 0, 4) ); } if ( $has_type ){ $tmp['dir'] = $f['type'] === 'dir'; $tmp['file'] = $f['type'] !== 'dir'; } $files[] = $tmp; } else{ $files[] = $path.'/'.$f['name']; } } } } } else{ bbn\x::log(error_get_last(), 'filesystem'); } } else{ $fs = scandir($path, SCANDIR_SORT_ASCENDING); foreach ( $fs as $f ){ if ( ($f !== '.') && ($f !== '..') && ($hidden || (strpos(basename($f), '.') !== 0)) ){ $ok = 0; $is_dir = null; $is_file = null; if ( $type === 'both' ){ $ok = 1; } else if ( $type === 'dir' ){ if ( $ok = is_dir($path.'/'.$f) ){ $is_dir = $ok; $is_file = !$ok; } } else if ( $type === 'file' ){ if ( $ok = is_file($path.'/'.$f) ){ $is_file = $ok; $is_dir = !$ok; } } else if ( !is_string($type) || is_file($path.'/'.$f) ){ $ok = $this->_check_filter($f, $type); $is_file = true; $is_dir = false; } if ( $ok ){ if ( $detailed ){ if ( !isset($has_type, $has_mod) ){ $has_type = stripos($detailed, 't') !== false; $has_mod = stripos($detailed, 'm') !== false; } $tmp = [ 'path' => $path.'/'.$f ]; if ( $has_mod ){ $tmp['mtime'] = filemtime($path.'/'.$f); } if ( $has_type ){ $tmp['dir'] = $is_dir ?? is_dir($path.'/'.$f); $tmp['file'] = $is_file ?? is_file($path.'/'.$f); } $files[] = $tmp; } else { $files[] = $path.'/'.$f; } } } } } if ( \count($files) > 0 ){ //bbn\x::sort($files, 'real'); } return $files; }
[ "private", "function", "_get_items", "(", "string", "$", "path", ",", "$", "type", "=", "'both'", ",", "bool", "$", "hidden", "=", "false", ",", "string", "$", "detailed", "=", "''", ")", ":", "array", "{", "$", "files", "=", "[", "]", ";", "if", "(", "(", "$", "this", "->", "mode", "===", "'ftp'", ")", "&&", "(", "$", "detailed", "||", "(", "$", "type", "!==", "'both'", ")", ")", ")", "{", "if", "(", "$", "fs", "=", "ftp_mlsd", "(", "$", "this", "->", "stream", ",", "substr", "(", "$", "path", ",", "strlen", "(", "$", "this", "->", "prefix", ")", ")", ")", ")", "{", "foreach", "(", "$", "fs", "as", "$", "f", ")", "{", "if", "(", "(", "$", "f", "[", "'name'", "]", "!==", "'.'", ")", "&&", "(", "$", "f", "[", "'name'", "]", "!==", "'..'", ")", "&&", "(", "$", "hidden", "||", "(", "strpos", "(", "basename", "(", "$", "f", "[", "'name'", "]", ")", ",", "'.'", ")", "!==", "0", ")", ")", ")", "{", "$", "ok", "=", "0", ";", "if", "(", "$", "type", "===", "'both'", ")", "{", "$", "ok", "=", "1", ";", "}", "else", "if", "(", "$", "type", "===", "'dir'", ")", "{", "$", "ok", "=", "$", "f", "[", "'type'", "]", "===", "'dir'", ";", "}", "else", "if", "(", "$", "type", "===", "'file'", ")", "{", "$", "ok", "=", "$", "f", "[", "'type'", "]", "===", "'file'", ";", "}", "else", "if", "(", "!", "is_string", "(", "$", "type", ")", "||", "is_file", "(", "$", "path", ".", "'/'", ".", "$", "f", "[", "'name'", "]", ")", ")", "{", "$", "ok", "=", "$", "this", "->", "_check_filter", "(", "$", "f", "[", "'name'", "]", ",", "$", "type", ")", ";", "}", "if", "(", "$", "ok", ")", "{", "if", "(", "$", "detailed", ")", "{", "if", "(", "!", "isset", "(", "$", "has_type", ",", "$", "has_mod", ")", ")", "{", "$", "has_type", "=", "stripos", "(", "$", "detailed", ",", "'t'", ")", "!==", "false", ";", "$", "has_mod", "=", "stripos", "(", "$", "detailed", ",", "'m'", ")", "!==", "false", ";", "}", "$", "tmp", "=", "[", "'path'", "=>", "$", "path", ".", "'/'", ".", "$", "f", "[", "'name'", "]", "]", ";", "if", "(", "$", "has_mod", ")", "{", "$", "tmp", "[", "'mtime'", "]", "=", "mktime", "(", "substr", "(", "$", "f", "[", "'modify'", "]", ",", "8", ",", "2", ")", ",", "substr", "(", "$", "f", "[", "'modify'", "]", ",", "10", ",", "2", ")", ",", "substr", "(", "$", "f", "[", "'modify'", "]", ",", "12", ",", "2", ")", ",", "substr", "(", "$", "f", "[", "'modify'", "]", ",", "4", ",", "2", ")", ",", "substr", "(", "$", "f", "[", "'modify'", "]", ",", "6", ",", "2", ")", ",", "substr", "(", "$", "f", "[", "'modify'", "]", ",", "0", ",", "4", ")", ")", ";", "}", "if", "(", "$", "has_type", ")", "{", "$", "tmp", "[", "'dir'", "]", "=", "$", "f", "[", "'type'", "]", "===", "'dir'", ";", "$", "tmp", "[", "'file'", "]", "=", "$", "f", "[", "'type'", "]", "!==", "'dir'", ";", "}", "$", "files", "[", "]", "=", "$", "tmp", ";", "}", "else", "{", "$", "files", "[", "]", "=", "$", "path", ".", "'/'", ".", "$", "f", "[", "'name'", "]", ";", "}", "}", "}", "}", "}", "else", "{", "bbn", "\\", "x", "::", "log", "(", "error_get_last", "(", ")", ",", "'filesystem'", ")", ";", "}", "}", "else", "{", "$", "fs", "=", "scandir", "(", "$", "path", ",", "SCANDIR_SORT_ASCENDING", ")", ";", "foreach", "(", "$", "fs", "as", "$", "f", ")", "{", "if", "(", "(", "$", "f", "!==", "'.'", ")", "&&", "(", "$", "f", "!==", "'..'", ")", "&&", "(", "$", "hidden", "||", "(", "strpos", "(", "basename", "(", "$", "f", ")", ",", "'.'", ")", "!==", "0", ")", ")", ")", "{", "$", "ok", "=", "0", ";", "$", "is_dir", "=", "null", ";", "$", "is_file", "=", "null", ";", "if", "(", "$", "type", "===", "'both'", ")", "{", "$", "ok", "=", "1", ";", "}", "else", "if", "(", "$", "type", "===", "'dir'", ")", "{", "if", "(", "$", "ok", "=", "is_dir", "(", "$", "path", ".", "'/'", ".", "$", "f", ")", ")", "{", "$", "is_dir", "=", "$", "ok", ";", "$", "is_file", "=", "!", "$", "ok", ";", "}", "}", "else", "if", "(", "$", "type", "===", "'file'", ")", "{", "if", "(", "$", "ok", "=", "is_file", "(", "$", "path", ".", "'/'", ".", "$", "f", ")", ")", "{", "$", "is_file", "=", "$", "ok", ";", "$", "is_dir", "=", "!", "$", "ok", ";", "}", "}", "else", "if", "(", "!", "is_string", "(", "$", "type", ")", "||", "is_file", "(", "$", "path", ".", "'/'", ".", "$", "f", ")", ")", "{", "$", "ok", "=", "$", "this", "->", "_check_filter", "(", "$", "f", ",", "$", "type", ")", ";", "$", "is_file", "=", "true", ";", "$", "is_dir", "=", "false", ";", "}", "if", "(", "$", "ok", ")", "{", "if", "(", "$", "detailed", ")", "{", "if", "(", "!", "isset", "(", "$", "has_type", ",", "$", "has_mod", ")", ")", "{", "$", "has_type", "=", "stripos", "(", "$", "detailed", ",", "'t'", ")", "!==", "false", ";", "$", "has_mod", "=", "stripos", "(", "$", "detailed", ",", "'m'", ")", "!==", "false", ";", "}", "$", "tmp", "=", "[", "'path'", "=>", "$", "path", ".", "'/'", ".", "$", "f", "]", ";", "if", "(", "$", "has_mod", ")", "{", "$", "tmp", "[", "'mtime'", "]", "=", "filemtime", "(", "$", "path", ".", "'/'", ".", "$", "f", ")", ";", "}", "if", "(", "$", "has_type", ")", "{", "$", "tmp", "[", "'dir'", "]", "=", "$", "is_dir", "??", "is_dir", "(", "$", "path", ".", "'/'", ".", "$", "f", ")", ";", "$", "tmp", "[", "'file'", "]", "=", "$", "is_file", "??", "is_file", "(", "$", "path", ".", "'/'", ".", "$", "f", ")", ";", "}", "$", "files", "[", "]", "=", "$", "tmp", ";", "}", "else", "{", "$", "files", "[", "]", "=", "$", "path", ".", "'/'", ".", "$", "f", ";", "}", "}", "}", "}", "}", "if", "(", "\\", "count", "(", "$", "files", ")", ">", "0", ")", "{", "//bbn\\x::sort($files, 'real');", "}", "return", "$", "files", ";", "}" ]
Raw function returning the elements contained in the given directory @param string $path @param string|callable $type @param bool $hidden @param string $detailed @return array
[ "Raw", "function", "returning", "the", "elements", "contained", "in", "the", "given", "directory" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/system.php#L180-L292
Daursu/xero
src/Daursu/Xero/models/Collection.php
Collection.setItems
public function setItems($items = array()) { $this->items = array(); foreach ($items as $key => $item) { if ( ! is_numeric($key) && is_array($item)) { // Check to see if the item contains many subitems if (array_key_exists('1', $item)) { $this->setItems($item); return false; } else { // This is a single item $this->push($item); } } elseif (is_array($item)) { $this->push($item); } } }
php
public function setItems($items = array()) { $this->items = array(); foreach ($items as $key => $item) { if ( ! is_numeric($key) && is_array($item)) { // Check to see if the item contains many subitems if (array_key_exists('1', $item)) { $this->setItems($item); return false; } else { // This is a single item $this->push($item); } } elseif (is_array($item)) { $this->push($item); } } }
[ "public", "function", "setItems", "(", "$", "items", "=", "array", "(", ")", ")", "{", "$", "this", "->", "items", "=", "array", "(", ")", ";", "foreach", "(", "$", "items", "as", "$", "key", "=>", "$", "item", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "key", ")", "&&", "is_array", "(", "$", "item", ")", ")", "{", "// Check to see if the item contains many subitems", "if", "(", "array_key_exists", "(", "'1'", ",", "$", "item", ")", ")", "{", "$", "this", "->", "setItems", "(", "$", "item", ")", ";", "return", "false", ";", "}", "else", "{", "// This is a single item", "$", "this", "->", "push", "(", "$", "item", ")", ";", "}", "}", "elseif", "(", "is_array", "(", "$", "item", ")", ")", "{", "$", "this", "->", "push", "(", "$", "item", ")", ";", "}", "}", "}" ]
Set all the items at once @param array $items
[ "Set", "all", "the", "items", "at", "once" ]
train
https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/models/Collection.php#L39-L61
Daursu/xero
src/Daursu/Xero/models/Collection.php
Collection.push
public function push($item) { $full_class_name = $this->getFullClassName(); if (is_array($item)) { array_push($this->items, new $full_class_name($item)); } elseif ($item instanceof $full_class_name) { array_push($this->items, $item); } }
php
public function push($item) { $full_class_name = $this->getFullClassName(); if (is_array($item)) { array_push($this->items, new $full_class_name($item)); } elseif ($item instanceof $full_class_name) { array_push($this->items, $item); } }
[ "public", "function", "push", "(", "$", "item", ")", "{", "$", "full_class_name", "=", "$", "this", "->", "getFullClassName", "(", ")", ";", "if", "(", "is_array", "(", "$", "item", ")", ")", "{", "array_push", "(", "$", "this", "->", "items", ",", "new", "$", "full_class_name", "(", "$", "item", ")", ")", ";", "}", "elseif", "(", "$", "item", "instanceof", "$", "full_class_name", ")", "{", "array_push", "(", "$", "this", "->", "items", ",", "$", "item", ")", ";", "}", "}" ]
Add a new item to the collection @param mixed $item @return void
[ "Add", "a", "new", "item", "to", "the", "collection" ]
train
https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/models/Collection.php#L69-L79
Daursu/xero
src/Daursu/Xero/models/Collection.php
Collection.toArray
public function toArray() { $output = array(); foreach ($this->items as $key => $value) { array_push($output, $value->toArray(true)); } return array( $this->getEntityName() => array( $this->getSingularEntityName() => $output ), ); }
php
public function toArray() { $output = array(); foreach ($this->items as $key => $value) { array_push($output, $value->toArray(true)); } return array( $this->getEntityName() => array( $this->getSingularEntityName() => $output ), ); }
[ "public", "function", "toArray", "(", ")", "{", "$", "output", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "items", "as", "$", "key", "=>", "$", "value", ")", "{", "array_push", "(", "$", "output", ",", "$", "value", "->", "toArray", "(", "true", ")", ")", ";", "}", "return", "array", "(", "$", "this", "->", "getEntityName", "(", ")", "=>", "array", "(", "$", "this", "->", "getSingularEntityName", "(", ")", "=>", "$", "output", ")", ",", ")", ";", "}" ]
Convert the model to an array @return array
[ "Convert", "the", "model", "to", "an", "array" ]
train
https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/models/Collection.php#L120-L133
Daursu/xero
src/Daursu/Xero/models/Collection.php
Collection.toXML
public function toXML($singular = false) { $output = new SimpleXMLElement( sprintf("<%s></%s>", $this->getEntityName(), $this->getEntityName()) ); BaseModel::array_to_xml($this->toArray(), $output); return $output->asXML(); }
php
public function toXML($singular = false) { $output = new SimpleXMLElement( sprintf("<%s></%s>", $this->getEntityName(), $this->getEntityName()) ); BaseModel::array_to_xml($this->toArray(), $output); return $output->asXML(); }
[ "public", "function", "toXML", "(", "$", "singular", "=", "false", ")", "{", "$", "output", "=", "new", "SimpleXMLElement", "(", "sprintf", "(", "\"<%s></%s>\"", ",", "$", "this", "->", "getEntityName", "(", ")", ",", "$", "this", "->", "getEntityName", "(", ")", ")", ")", ";", "BaseModel", "::", "array_to_xml", "(", "$", "this", "->", "toArray", "(", ")", ",", "$", "output", ")", ";", "return", "$", "output", "->", "asXML", "(", ")", ";", "}" ]
Converts the model to XML @return string
[ "Converts", "the", "model", "to", "XML" ]
train
https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/models/Collection.php#L140-L149
surebert/surebert-framework
src/sb/Validate/Numbers.php
Numbers.isInt
public static function isInt($int) { return (is_string($int) || is_int($int) || is_float($int)) && ctype_digit((string)$int); }
php
public static function isInt($int) { return (is_string($int) || is_int($int) || is_float($int)) && ctype_digit((string)$int); }
[ "public", "static", "function", "isInt", "(", "$", "int", ")", "{", "return", "(", "is_string", "(", "$", "int", ")", "||", "is_int", "(", "$", "int", ")", "||", "is_float", "(", "$", "int", ")", ")", "&&", "ctype_digit", "(", "(", "string", ")", "$", "int", ")", ";", "}" ]
Checks to see if str, float, or int type and represents whole number @param mixed $int @return boolean
[ "Checks", "to", "see", "if", "str", "float", "or", "int", "type", "and", "represents", "whole", "number" ]
train
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Validate/Numbers.php#L16-L20
actimeo/pgproc
src/PgSchema.class.php
PgSchema.traceCall
private function traceCall($method) { $tracepath = $this->base->trace; if (!file_exists($tracepath)) { mkdir($tracepath); } $path = $tracepath . DIRECTORY_SEPARATOR . $this->name; if (!file_exists($path)) { mkdir ($path); } $cmdpath = $path . DIRECTORY_SEPARATOR . $method; if (!file_exists($cmdpath)) { touch($cmdpath); } }
php
private function traceCall($method) { $tracepath = $this->base->trace; if (!file_exists($tracepath)) { mkdir($tracepath); } $path = $tracepath . DIRECTORY_SEPARATOR . $this->name; if (!file_exists($path)) { mkdir ($path); } $cmdpath = $path . DIRECTORY_SEPARATOR . $method; if (!file_exists($cmdpath)) { touch($cmdpath); } }
[ "private", "function", "traceCall", "(", "$", "method", ")", "{", "$", "tracepath", "=", "$", "this", "->", "base", "->", "trace", ";", "if", "(", "!", "file_exists", "(", "$", "tracepath", ")", ")", "{", "mkdir", "(", "$", "tracepath", ")", ";", "}", "$", "path", "=", "$", "tracepath", ".", "DIRECTORY_SEPARATOR", ".", "$", "this", "->", "name", ";", "if", "(", "!", "file_exists", "(", "$", "path", ")", ")", "{", "mkdir", "(", "$", "path", ")", ";", "}", "$", "cmdpath", "=", "$", "path", ".", "DIRECTORY_SEPARATOR", ".", "$", "method", ";", "if", "(", "!", "file_exists", "(", "$", "cmdpath", ")", ")", "{", "touch", "(", "$", "cmdpath", ")", ";", "}", "}" ]
/* PRIVATE
[ "/", "*", "PRIVATE" ]
train
https://github.com/actimeo/pgproc/blob/e251da8f27a560ccf82196ee946f73e0ed030108/src/PgSchema.class.php#L153-L166
actimeo/pgproc
src/PgSchema.class.php
PgSchema.search_pg_proc
private function search_pg_proc ($method, $args) { $argtypenames = array (); $argtypeschemas = array (); $nargs = count ($args); $query = "SELECT * FROM pgprocedures.search_function ('".$this->name."', '$method', $nargs)"; $rettypename = null; if ($res = $this->pgproc_query ($query)) { if ($row = pg_fetch_array ($res)) { $schema = $row['proc_nspname']; $argtypes = $row['proargtypes']; $rettype = $row['prorettype']; // Get the arguments types $argtypeslist = explode (' ', $argtypes); foreach ($argtypeslist as $argtype) { if (!strlen (trim ($argtype))) continue; list($argtypeschemas[], $argtypenames[]) = $this->get_pgtype_and_schema ($argtype); } if ((in_array($row['ret_typtype'], array('b', 'p', 'e')))) { // scalar type: (b)ase, (p)seudo-type, (e)num $rettypename = $row['ret_typname']; } else if ($row['ret_typtype'] == 'c') { // composite type $query3 = "select attname, typname FROM pg_attribute INNER JOIN pg_type ON pg_attribute.atttypid = pg_type.oid WHERE pg_attribute.attrelid = (select oid FROM pg_class where relname = '".$row['ret_typname']."') AND attnum > 0 ORDER BY attnum"; if ($res3 = $this->pgproc_query ($query3)) { $rettypename = array(); while ($row3 = pg_fetch_array ($res3)) { $rettypename[$row3['attname']] = $row3['typname']; } } } } } if (count ($argtypenames) == $nargs) return array ($schema, $argtypeschemas, $argtypenames, $row['ret_typtype'], $rettypename, ($row['proretset'] == 't')); else return NULL; }
php
private function search_pg_proc ($method, $args) { $argtypenames = array (); $argtypeschemas = array (); $nargs = count ($args); $query = "SELECT * FROM pgprocedures.search_function ('".$this->name."', '$method', $nargs)"; $rettypename = null; if ($res = $this->pgproc_query ($query)) { if ($row = pg_fetch_array ($res)) { $schema = $row['proc_nspname']; $argtypes = $row['proargtypes']; $rettype = $row['prorettype']; // Get the arguments types $argtypeslist = explode (' ', $argtypes); foreach ($argtypeslist as $argtype) { if (!strlen (trim ($argtype))) continue; list($argtypeschemas[], $argtypenames[]) = $this->get_pgtype_and_schema ($argtype); } if ((in_array($row['ret_typtype'], array('b', 'p', 'e')))) { // scalar type: (b)ase, (p)seudo-type, (e)num $rettypename = $row['ret_typname']; } else if ($row['ret_typtype'] == 'c') { // composite type $query3 = "select attname, typname FROM pg_attribute INNER JOIN pg_type ON pg_attribute.atttypid = pg_type.oid WHERE pg_attribute.attrelid = (select oid FROM pg_class where relname = '".$row['ret_typname']."') AND attnum > 0 ORDER BY attnum"; if ($res3 = $this->pgproc_query ($query3)) { $rettypename = array(); while ($row3 = pg_fetch_array ($res3)) { $rettypename[$row3['attname']] = $row3['typname']; } } } } } if (count ($argtypenames) == $nargs) return array ($schema, $argtypeschemas, $argtypenames, $row['ret_typtype'], $rettypename, ($row['proretset'] == 't')); else return NULL; }
[ "private", "function", "search_pg_proc", "(", "$", "method", ",", "$", "args", ")", "{", "$", "argtypenames", "=", "array", "(", ")", ";", "$", "argtypeschemas", "=", "array", "(", ")", ";", "$", "nargs", "=", "count", "(", "$", "args", ")", ";", "$", "query", "=", "\"SELECT * FROM pgprocedures.search_function ('\"", ".", "$", "this", "->", "name", ".", "\"', '$method', $nargs)\"", ";", "$", "rettypename", "=", "null", ";", "if", "(", "$", "res", "=", "$", "this", "->", "pgproc_query", "(", "$", "query", ")", ")", "{", "if", "(", "$", "row", "=", "pg_fetch_array", "(", "$", "res", ")", ")", "{", "$", "schema", "=", "$", "row", "[", "'proc_nspname'", "]", ";", "$", "argtypes", "=", "$", "row", "[", "'proargtypes'", "]", ";", "$", "rettype", "=", "$", "row", "[", "'prorettype'", "]", ";", "// Get the arguments types", "$", "argtypeslist", "=", "explode", "(", "' '", ",", "$", "argtypes", ")", ";", "foreach", "(", "$", "argtypeslist", "as", "$", "argtype", ")", "{", "if", "(", "!", "strlen", "(", "trim", "(", "$", "argtype", ")", ")", ")", "continue", ";", "list", "(", "$", "argtypeschemas", "[", "]", ",", "$", "argtypenames", "[", "]", ")", "=", "$", "this", "->", "get_pgtype_and_schema", "(", "$", "argtype", ")", ";", "}", "if", "(", "(", "in_array", "(", "$", "row", "[", "'ret_typtype'", "]", ",", "array", "(", "'b'", ",", "'p'", ",", "'e'", ")", ")", ")", ")", "{", "// scalar type: (b)ase, (p)seudo-type, (e)num", "$", "rettypename", "=", "$", "row", "[", "'ret_typname'", "]", ";", "}", "else", "if", "(", "$", "row", "[", "'ret_typtype'", "]", "==", "'c'", ")", "{", "// composite type", "$", "query3", "=", "\"select attname, typname FROM pg_attribute INNER JOIN pg_type ON pg_attribute.atttypid = pg_type.oid WHERE pg_attribute.attrelid = (select oid FROM pg_class where relname = '\"", ".", "$", "row", "[", "'ret_typname'", "]", ".", "\"') AND attnum > 0 ORDER BY attnum\"", ";", "if", "(", "$", "res3", "=", "$", "this", "->", "pgproc_query", "(", "$", "query3", ")", ")", "{", "$", "rettypename", "=", "array", "(", ")", ";", "while", "(", "$", "row3", "=", "pg_fetch_array", "(", "$", "res3", ")", ")", "{", "$", "rettypename", "[", "$", "row3", "[", "'attname'", "]", "]", "=", "$", "row3", "[", "'typname'", "]", ";", "}", "}", "}", "}", "}", "if", "(", "count", "(", "$", "argtypenames", ")", "==", "$", "nargs", ")", "return", "array", "(", "$", "schema", ",", "$", "argtypeschemas", ",", "$", "argtypenames", ",", "$", "row", "[", "'ret_typtype'", "]", ",", "$", "rettypename", ",", "(", "$", "row", "[", "'proretset'", "]", "==", "'t'", ")", ")", ";", "else", "return", "NULL", ";", "}" ]
Search method by name and number of args Returns: The types of the arguments
[ "Search", "method", "by", "name", "and", "number", "of", "args", "Returns", ":", "The", "types", "of", "the", "arguments" ]
train
https://github.com/actimeo/pgproc/blob/e251da8f27a560ccf82196ee946f73e0ed030108/src/PgSchema.class.php#L188-L231
spiderling-php/spiderling
src/Html.php
Html.resolveLinks
public function resolveLinks(UriInterface $base) { $this->resolveLinkAttribute('href', $base); $this->resolveLinkAttribute('src', $base); $this->resolveLinkAttribute('action', $base); return $this; }
php
public function resolveLinks(UriInterface $base) { $this->resolveLinkAttribute('href', $base); $this->resolveLinkAttribute('src', $base); $this->resolveLinkAttribute('action', $base); return $this; }
[ "public", "function", "resolveLinks", "(", "UriInterface", "$", "base", ")", "{", "$", "this", "->", "resolveLinkAttribute", "(", "'href'", ",", "$", "base", ")", ";", "$", "this", "->", "resolveLinkAttribute", "(", "'src'", ",", "$", "base", ")", ";", "$", "this", "->", "resolveLinkAttribute", "(", "'action'", ",", "$", "base", ")", ";", "return", "$", "this", ";", "}" ]
Add a prefix to all relative links (src, href and action) @param UriInterface $base
[ "Add", "a", "prefix", "to", "all", "relative", "links", "(", "src", "href", "and", "action", ")" ]
train
https://github.com/spiderling-php/spiderling/blob/030d70fb71c89256e3b256dda7fa4c47751d9c53/src/Html.php#L63-L70
weew/http
src/Weew/Http/BasicAuthParser.php
BasicAuthParser.getToken
public function getToken(IHttpHeaders $headers) { $header = $this->getHeader($headers); return $this->parseHeader($header); }
php
public function getToken(IHttpHeaders $headers) { $header = $this->getHeader($headers); return $this->parseHeader($header); }
[ "public", "function", "getToken", "(", "IHttpHeaders", "$", "headers", ")", "{", "$", "header", "=", "$", "this", "->", "getHeader", "(", "$", "headers", ")", ";", "return", "$", "this", "->", "parseHeader", "(", "$", "header", ")", ";", "}" ]
@param IHttpHeaders $headers @return null|string
[ "@param", "IHttpHeaders", "$headers" ]
train
https://github.com/weew/http/blob/fd34d3d5643ca01c8e0946e888224a8e8dcc3c0d/src/Weew/Http/BasicAuthParser.php#L33-L37
weew/http
src/Weew/Http/BasicAuthParser.php
BasicAuthParser.getCredentials
public function getCredentials(IHttpHeaders $headers) { $token = $this->getToken($headers); return $this->parseToken($token); }
php
public function getCredentials(IHttpHeaders $headers) { $token = $this->getToken($headers); return $this->parseToken($token); }
[ "public", "function", "getCredentials", "(", "IHttpHeaders", "$", "headers", ")", "{", "$", "token", "=", "$", "this", "->", "getToken", "(", "$", "headers", ")", ";", "return", "$", "this", "->", "parseToken", "(", "$", "token", ")", ";", "}" ]
@param IHttpHeaders $headers @return array
[ "@param", "IHttpHeaders", "$headers" ]
train
https://github.com/weew/http/blob/fd34d3d5643ca01c8e0946e888224a8e8dcc3c0d/src/Weew/Http/BasicAuthParser.php#L53-L57
weew/http
src/Weew/Http/BasicAuthParser.php
BasicAuthParser.parseToken
public function parseToken($token) { $token = base64_decode($token); $parts = explode(':', $token, 2); return [array_get($parts, 0), array_get($parts, 1)]; }
php
public function parseToken($token) { $token = base64_decode($token); $parts = explode(':', $token, 2); return [array_get($parts, 0), array_get($parts, 1)]; }
[ "public", "function", "parseToken", "(", "$", "token", ")", "{", "$", "token", "=", "base64_decode", "(", "$", "token", ")", ";", "$", "parts", "=", "explode", "(", "':'", ",", "$", "token", ",", "2", ")", ";", "return", "[", "array_get", "(", "$", "parts", ",", "0", ")", ",", "array_get", "(", "$", "parts", ",", "1", ")", "]", ";", "}" ]
@param $token @return array
[ "@param", "$token" ]
train
https://github.com/weew/http/blob/fd34d3d5643ca01c8e0946e888224a8e8dcc3c0d/src/Weew/Http/BasicAuthParser.php#L127-L132
contao-community-alliance/url-builder
src/UrlBuilder.php
UrlBuilder.setQueryParameter
public function setQueryParameter($name, $value) { $this->query[(string) $name] = (string) $value; return $this; }
php
public function setQueryParameter($name, $value) { $this->query[(string) $name] = (string) $value; return $this; }
[ "public", "function", "setQueryParameter", "(", "$", "name", ",", "$", "value", ")", "{", "$", "this", "->", "query", "[", "(", "string", ")", "$", "name", "]", "=", "(", "string", ")", "$", "value", ";", "return", "$", "this", ";", "}" ]
Set a query parameter. @param string $name The name of the query parameter. @param string $value The value of the query parameter. @return UrlBuilder
[ "Set", "a", "query", "parameter", "." ]
train
https://github.com/contao-community-alliance/url-builder/blob/2d730649058f3d3af41175358ee92f0659de08a1/src/UrlBuilder.php#L325-L330
contao-community-alliance/url-builder
src/UrlBuilder.php
UrlBuilder.insertQueryParameter
public function insertQueryParameter($name, $value, $position) { $this->query = array_merge( array_slice($this->query, 0, $position), array((string) $name => (string) $value), array_slice($this->query, $position) ); return $this; }
php
public function insertQueryParameter($name, $value, $position) { $this->query = array_merge( array_slice($this->query, 0, $position), array((string) $name => (string) $value), array_slice($this->query, $position) ); return $this; }
[ "public", "function", "insertQueryParameter", "(", "$", "name", ",", "$", "value", ",", "$", "position", ")", "{", "$", "this", "->", "query", "=", "array_merge", "(", "array_slice", "(", "$", "this", "->", "query", ",", "0", ",", "$", "position", ")", ",", "array", "(", "(", "string", ")", "$", "name", "=>", "(", "string", ")", "$", "value", ")", ",", "array_slice", "(", "$", "this", "->", "query", ",", "$", "position", ")", ")", ";", "return", "$", "this", ";", "}" ]
Insert a query parameter at the given position. @param string $name The name of the query parameter. @param string $value The value of the query parameter. @param int $position The desired position where the query parameter shall get inserted at. @return UrlBuilder
[ "Insert", "a", "query", "parameter", "at", "the", "given", "position", "." ]
train
https://github.com/contao-community-alliance/url-builder/blob/2d730649058f3d3af41175358ee92f0659de08a1/src/UrlBuilder.php#L343-L352
contao-community-alliance/url-builder
src/UrlBuilder.php
UrlBuilder.insertQueryParameterBefore
public function insertQueryParameterBefore($name, $value, $before) { $index = array_search($before, array_keys($this->query)); if ($index !== false) { $this->insertQueryParameter((string) $name, (string) $value, $index); } else { $this->setQueryParameter((string) $name, (string) $value); } return $this; }
php
public function insertQueryParameterBefore($name, $value, $before) { $index = array_search($before, array_keys($this->query)); if ($index !== false) { $this->insertQueryParameter((string) $name, (string) $value, $index); } else { $this->setQueryParameter((string) $name, (string) $value); } return $this; }
[ "public", "function", "insertQueryParameterBefore", "(", "$", "name", ",", "$", "value", ",", "$", "before", ")", "{", "$", "index", "=", "array_search", "(", "$", "before", ",", "array_keys", "(", "$", "this", "->", "query", ")", ")", ";", "if", "(", "$", "index", "!==", "false", ")", "{", "$", "this", "->", "insertQueryParameter", "(", "(", "string", ")", "$", "name", ",", "(", "string", ")", "$", "value", ",", "$", "index", ")", ";", "}", "else", "{", "$", "this", "->", "setQueryParameter", "(", "(", "string", ")", "$", "name", ",", "(", "string", ")", "$", "value", ")", ";", "}", "return", "$", "this", ";", "}" ]
Insert a query parameter at the given position. @param string $name The name of the query parameter. @param string $value The value of the query parameter. @param string $before The name of the desired parameter where the query parameter shall get inserted before. @return UrlBuilder
[ "Insert", "a", "query", "parameter", "at", "the", "given", "position", "." ]
train
https://github.com/contao-community-alliance/url-builder/blob/2d730649058f3d3af41175358ee92f0659de08a1/src/UrlBuilder.php#L365-L376
contao-community-alliance/url-builder
src/UrlBuilder.php
UrlBuilder.getQueryParameter
public function getQueryParameter($name) { return isset($this->query[$name]) ? $this->query[$name] : null; }
php
public function getQueryParameter($name) { return isset($this->query[$name]) ? $this->query[$name] : null; }
[ "public", "function", "getQueryParameter", "(", "$", "name", ")", "{", "return", "isset", "(", "$", "this", "->", "query", "[", "$", "name", "]", ")", "?", "$", "this", "->", "query", "[", "$", "name", "]", ":", "null", ";", "}" ]
Retrieve the value of a query parameter. @param string $name The name of the query parameter. @return string|null
[ "Retrieve", "the", "value", "of", "a", "query", "parameter", "." ]
train
https://github.com/contao-community-alliance/url-builder/blob/2d730649058f3d3af41175358ee92f0659de08a1/src/UrlBuilder.php#L411-L414
contao-community-alliance/url-builder
src/UrlBuilder.php
UrlBuilder.addQueryParameters
public function addQueryParameters($queryString) { $queries = preg_split('/&(amp;)?/i', $queryString); foreach ($queries as $v) { $explode = explode('=', $v); $name = $explode[0]; $value = isset($explode[1]) ? $explode[1] : ''; $rpos = strrpos($name, '?'); if ($rpos !== false) { $name = substr($name, ($rpos + 1)); } if (empty($name)) { continue; } $this->setQueryParameter($name, $value); } return $this; }
php
public function addQueryParameters($queryString) { $queries = preg_split('/&(amp;)?/i', $queryString); foreach ($queries as $v) { $explode = explode('=', $v); $name = $explode[0]; $value = isset($explode[1]) ? $explode[1] : ''; $rpos = strrpos($name, '?'); if ($rpos !== false) { $name = substr($name, ($rpos + 1)); } if (empty($name)) { continue; } $this->setQueryParameter($name, $value); } return $this; }
[ "public", "function", "addQueryParameters", "(", "$", "queryString", ")", "{", "$", "queries", "=", "preg_split", "(", "'/&(amp;)?/i'", ",", "$", "queryString", ")", ";", "foreach", "(", "$", "queries", "as", "$", "v", ")", "{", "$", "explode", "=", "explode", "(", "'='", ",", "$", "v", ")", ";", "$", "name", "=", "$", "explode", "[", "0", "]", ";", "$", "value", "=", "isset", "(", "$", "explode", "[", "1", "]", ")", "?", "$", "explode", "[", "1", "]", ":", "''", ";", "$", "rpos", "=", "strrpos", "(", "$", "name", ",", "'?'", ")", ";", "if", "(", "$", "rpos", "!==", "false", ")", "{", "$", "name", "=", "substr", "(", "$", "name", ",", "(", "$", "rpos", "+", "1", ")", ")", ";", "}", "if", "(", "empty", "(", "$", "name", ")", ")", "{", "continue", ";", "}", "$", "this", "->", "setQueryParameter", "(", "$", "name", ",", "$", "value", ")", ";", "}", "return", "$", "this", ";", "}" ]
Absorb the query parameters from a query string. @param string $queryString The query string. @return UrlBuilder
[ "Absorb", "the", "query", "parameters", "from", "a", "query", "string", "." ]
train
https://github.com/contao-community-alliance/url-builder/blob/2d730649058f3d3af41175358ee92f0659de08a1/src/UrlBuilder.php#L423-L446
contao-community-alliance/url-builder
src/UrlBuilder.php
UrlBuilder.getQueryString
public function getQueryString() { $query = ''; foreach ($this->query as $name => $value) { if ($query) { $query .= '&'; } $query .= $name; if ($value) { $query .= '=' . $value; } } if ('' === $query) { return null; } return $query; }
php
public function getQueryString() { $query = ''; foreach ($this->query as $name => $value) { if ($query) { $query .= '&'; } $query .= $name; if ($value) { $query .= '=' . $value; } } if ('' === $query) { return null; } return $query; }
[ "public", "function", "getQueryString", "(", ")", "{", "$", "query", "=", "''", ";", "foreach", "(", "$", "this", "->", "query", "as", "$", "name", "=>", "$", "value", ")", "{", "if", "(", "$", "query", ")", "{", "$", "query", ".=", "'&'", ";", "}", "$", "query", ".=", "$", "name", ";", "if", "(", "$", "value", ")", "{", "$", "query", ".=", "'='", ".", "$", "value", ";", "}", "}", "if", "(", "''", "===", "$", "query", ")", "{", "return", "null", ";", "}", "return", "$", "query", ";", "}" ]
Retrieve the serialized query string. @return string|null
[ "Retrieve", "the", "serialized", "query", "string", "." ]
train
https://github.com/contao-community-alliance/url-builder/blob/2d730649058f3d3af41175358ee92f0659de08a1/src/UrlBuilder.php#L467-L487
contao-community-alliance/url-builder
src/UrlBuilder.php
UrlBuilder.getBaseUrl
public function getBaseUrl() { $url = ''; if (isset($this->scheme)) { if ('' !== $this->scheme) { $url .= $this->scheme . ':'; } $url .= '//'; } if (isset($this->user)) { $url .= $this->user; if (isset($this->pass)) { $url .= ':' . $this->pass; } $url .= '@'; } $url .= $this->host; if (isset($this->port)) { $url .= ':' . $this->port; } if (isset($this->path)) { if ($url != '' && $this->path[0] !== '/') { $url .= '/'; } $url .= $this->path; } return $url; }
php
public function getBaseUrl() { $url = ''; if (isset($this->scheme)) { if ('' !== $this->scheme) { $url .= $this->scheme . ':'; } $url .= '//'; } if (isset($this->user)) { $url .= $this->user; if (isset($this->pass)) { $url .= ':' . $this->pass; } $url .= '@'; } $url .= $this->host; if (isset($this->port)) { $url .= ':' . $this->port; } if (isset($this->path)) { if ($url != '' && $this->path[0] !== '/') { $url .= '/'; } $url .= $this->path; } return $url; }
[ "public", "function", "getBaseUrl", "(", ")", "{", "$", "url", "=", "''", ";", "if", "(", "isset", "(", "$", "this", "->", "scheme", ")", ")", "{", "if", "(", "''", "!==", "$", "this", "->", "scheme", ")", "{", "$", "url", ".=", "$", "this", "->", "scheme", ".", "':'", ";", "}", "$", "url", ".=", "'//'", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "user", ")", ")", "{", "$", "url", ".=", "$", "this", "->", "user", ";", "if", "(", "isset", "(", "$", "this", "->", "pass", ")", ")", "{", "$", "url", ".=", "':'", ".", "$", "this", "->", "pass", ";", "}", "$", "url", ".=", "'@'", ";", "}", "$", "url", ".=", "$", "this", "->", "host", ";", "if", "(", "isset", "(", "$", "this", "->", "port", ")", ")", "{", "$", "url", ".=", "':'", ".", "$", "this", "->", "port", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "path", ")", ")", "{", "if", "(", "$", "url", "!=", "''", "&&", "$", "this", "->", "path", "[", "0", "]", "!==", "'/'", ")", "{", "$", "url", ".=", "'/'", ";", "}", "$", "url", ".=", "$", "this", "->", "path", ";", "}", "return", "$", "url", ";", "}" ]
Retrieve the base url. The base URL is the url without query part and fragment. @return string|null
[ "Retrieve", "the", "base", "url", "." ]
train
https://github.com/contao-community-alliance/url-builder/blob/2d730649058f3d3af41175358ee92f0659de08a1/src/UrlBuilder.php#L496-L531
contao-community-alliance/url-builder
src/UrlBuilder.php
UrlBuilder.getUrl
public function getUrl() { $url = $this->getBaseUrl(); if ($query = $this->getQueryString()) { if ($url) { if (!$this->path) { $url .= '/'; } $url .= '?'; } $url .= $query; } if (isset($this->fragment)) { $url .= '#' . $this->fragment; } return $url; }
php
public function getUrl() { $url = $this->getBaseUrl(); if ($query = $this->getQueryString()) { if ($url) { if (!$this->path) { $url .= '/'; } $url .= '?'; } $url .= $query; } if (isset($this->fragment)) { $url .= '#' . $this->fragment; } return $url; }
[ "public", "function", "getUrl", "(", ")", "{", "$", "url", "=", "$", "this", "->", "getBaseUrl", "(", ")", ";", "if", "(", "$", "query", "=", "$", "this", "->", "getQueryString", "(", ")", ")", "{", "if", "(", "$", "url", ")", "{", "if", "(", "!", "$", "this", "->", "path", ")", "{", "$", "url", ".=", "'/'", ";", "}", "$", "url", ".=", "'?'", ";", "}", "$", "url", ".=", "$", "query", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "fragment", ")", ")", "{", "$", "url", ".=", "'#'", ".", "$", "this", "->", "fragment", ";", "}", "return", "$", "url", ";", "}" ]
Retrieve the complete generated URL. @return string
[ "Retrieve", "the", "complete", "generated", "URL", "." ]
train
https://github.com/contao-community-alliance/url-builder/blob/2d730649058f3d3af41175358ee92f0659de08a1/src/UrlBuilder.php#L538-L558
contao-community-alliance/url-builder
src/UrlBuilder.php
UrlBuilder.parseUrl
private function parseUrl($url) { $parsed = parse_url($url); if ((count($parsed) === 1) && isset($parsed['path']) && (0 === strpos($parsed['path'], '?') || false !== strpos($parsed['path'], '&')) ) { $parsed = array( 'query' => $parsed['path'] ); return $parsed; } return $parsed; }
php
private function parseUrl($url) { $parsed = parse_url($url); if ((count($parsed) === 1) && isset($parsed['path']) && (0 === strpos($parsed['path'], '?') || false !== strpos($parsed['path'], '&')) ) { $parsed = array( 'query' => $parsed['path'] ); return $parsed; } return $parsed; }
[ "private", "function", "parseUrl", "(", "$", "url", ")", "{", "$", "parsed", "=", "parse_url", "(", "$", "url", ")", ";", "if", "(", "(", "count", "(", "$", "parsed", ")", "===", "1", ")", "&&", "isset", "(", "$", "parsed", "[", "'path'", "]", ")", "&&", "(", "0", "===", "strpos", "(", "$", "parsed", "[", "'path'", "]", ",", "'?'", ")", "||", "false", "!==", "strpos", "(", "$", "parsed", "[", "'path'", "]", ",", "'&'", ")", ")", ")", "{", "$", "parsed", "=", "array", "(", "'query'", "=>", "$", "parsed", "[", "'path'", "]", ")", ";", "return", "$", "parsed", ";", "}", "return", "$", "parsed", ";", "}" ]
Parse the URL and fix up if it only contains only one element to make it the query element. @param string $url The url to parse. @return array
[ "Parse", "the", "URL", "and", "fix", "up", "if", "it", "only", "contains", "only", "one", "element", "to", "make", "it", "the", "query", "element", "." ]
train
https://github.com/contao-community-alliance/url-builder/blob/2d730649058f3d3af41175358ee92f0659de08a1/src/UrlBuilder.php#L567-L583
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.GoogleMapAPI
function GoogleMapAPI($map_id = 'map', $app_id = 'MyMapApp') { $this->map_id = $map_id; $this->sidebar_id = 'sidebar_' . $map_id; $this->app_id = $app_id; }
php
function GoogleMapAPI($map_id = 'map', $app_id = 'MyMapApp') { $this->map_id = $map_id; $this->sidebar_id = 'sidebar_' . $map_id; $this->app_id = $app_id; }
[ "function", "GoogleMapAPI", "(", "$", "map_id", "=", "'map'", ",", "$", "app_id", "=", "'MyMapApp'", ")", "{", "$", "this", "->", "map_id", "=", "$", "map_id", ";", "$", "this", "->", "sidebar_id", "=", "'sidebar_'", ".", "$", "map_id", ";", "$", "this", "->", "app_id", "=", "$", "app_id", ";", "}" ]
class constructor @param string $map_id the DOM element ID for the map @param string $app_id YOUR Yahoo App ID
[ "class", "constructor" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L644-L648
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.setWidth
function setWidth($width) { if(!preg_match('!^(\d+)(.*)$!',$width,$_match)) return false; $_width = $_match[1]; $_type = $_match[2]; if($_type == '%') $this->width = $_width . '%'; else $this->width = $_width . 'px'; return true; }
php
function setWidth($width) { if(!preg_match('!^(\d+)(.*)$!',$width,$_match)) return false; $_width = $_match[1]; $_type = $_match[2]; if($_type == '%') $this->width = $_width . '%'; else $this->width = $_width . 'px'; return true; }
[ "function", "setWidth", "(", "$", "width", ")", "{", "if", "(", "!", "preg_match", "(", "'!^(\\d+)(.*)$!'", ",", "$", "width", ",", "$", "_match", ")", ")", "return", "false", ";", "$", "_width", "=", "$", "_match", "[", "1", "]", ";", "$", "_type", "=", "$", "_match", "[", "2", "]", ";", "if", "(", "$", "_type", "==", "'%'", ")", "$", "this", "->", "width", "=", "$", "_width", ".", "'%'", ";", "else", "$", "this", "->", "width", "=", "$", "_width", ".", "'px'", ";", "return", "true", ";", "}" ]
sets the width of the map @param string $width @return string|false Width or false if not a valid value
[ "sets", "the", "width", "of", "the", "map" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L679-L691
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.setHeight
function setHeight($height) { if(!preg_match('!^(\d+)(.*)$!',$height,$_match)) return false; $_height = $_match[1]; $_type = $_match[2]; if($_type == '%') $this->height = $_height . '%'; else $this->height = $_height . 'px'; return true; }
php
function setHeight($height) { if(!preg_match('!^(\d+)(.*)$!',$height,$_match)) return false; $_height = $_match[1]; $_type = $_match[2]; if($_type == '%') $this->height = $_height . '%'; else $this->height = $_height . 'px'; return true; }
[ "function", "setHeight", "(", "$", "height", ")", "{", "if", "(", "!", "preg_match", "(", "'!^(\\d+)(.*)$!'", ",", "$", "height", ",", "$", "_match", ")", ")", "return", "false", ";", "$", "_height", "=", "$", "_match", "[", "1", "]", ";", "$", "_type", "=", "$", "_match", "[", "2", "]", ";", "if", "(", "$", "_type", "==", "'%'", ")", "$", "this", "->", "height", "=", "$", "_height", ".", "'%'", ";", "else", "$", "this", "->", "height", "=", "$", "_height", ".", "'px'", ";", "return", "true", ";", "}" ]
sets the height of the map @param string $height @return string|false Height or false if not a valid value
[ "sets", "the", "height", "of", "the", "map" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L699-L711
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.addDirections
function addDirections($start_address='',$dest_address='',$dom_id='', $add_markers=true, $elevation_samples=256, $elevation_width="", $elevation_height="", $elevation_dom_id=''){ if($elevation_dom_id=="") $elevation_dom_id = "elevation".$dom_id; if($start_address != '' && $dest_address != '' && $dom_id != ''){ $this->_directions[$dom_id] = array( "dom_id"=>$dom_id, "start"=>$start_address, "dest"=>$dest_address, "markers"=>true, "elevation_samples"=>$elevation_samples, "width"=>($elevation_width!=""?$elevation_width:str_replace("px","",$this->width)), "height"=>($elevation_height!=""?$elevation_height:str_replace("px","",$this->height)/2), "elevation_dom_id"=>$elevation_dom_id ); if($add_markers==true){ $this->addMarkerByAddress($start_address,$start_address, $start_address); $this->addMarkerByAddress($dest_address,$dest_address, $dest_address); } } }
php
function addDirections($start_address='',$dest_address='',$dom_id='', $add_markers=true, $elevation_samples=256, $elevation_width="", $elevation_height="", $elevation_dom_id=''){ if($elevation_dom_id=="") $elevation_dom_id = "elevation".$dom_id; if($start_address != '' && $dest_address != '' && $dom_id != ''){ $this->_directions[$dom_id] = array( "dom_id"=>$dom_id, "start"=>$start_address, "dest"=>$dest_address, "markers"=>true, "elevation_samples"=>$elevation_samples, "width"=>($elevation_width!=""?$elevation_width:str_replace("px","",$this->width)), "height"=>($elevation_height!=""?$elevation_height:str_replace("px","",$this->height)/2), "elevation_dom_id"=>$elevation_dom_id ); if($add_markers==true){ $this->addMarkerByAddress($start_address,$start_address, $start_address); $this->addMarkerByAddress($dest_address,$dest_address, $dest_address); } } }
[ "function", "addDirections", "(", "$", "start_address", "=", "''", ",", "$", "dest_address", "=", "''", ",", "$", "dom_id", "=", "''", ",", "$", "add_markers", "=", "true", ",", "$", "elevation_samples", "=", "256", ",", "$", "elevation_width", "=", "\"\"", ",", "$", "elevation_height", "=", "\"\"", ",", "$", "elevation_dom_id", "=", "''", ")", "{", "if", "(", "$", "elevation_dom_id", "==", "\"\"", ")", "$", "elevation_dom_id", "=", "\"elevation\"", ".", "$", "dom_id", ";", "if", "(", "$", "start_address", "!=", "''", "&&", "$", "dest_address", "!=", "''", "&&", "$", "dom_id", "!=", "''", ")", "{", "$", "this", "->", "_directions", "[", "$", "dom_id", "]", "=", "array", "(", "\"dom_id\"", "=>", "$", "dom_id", ",", "\"start\"", "=>", "$", "start_address", ",", "\"dest\"", "=>", "$", "dest_address", ",", "\"markers\"", "=>", "true", ",", "\"elevation_samples\"", "=>", "$", "elevation_samples", ",", "\"width\"", "=>", "(", "$", "elevation_width", "!=", "\"\"", "?", "$", "elevation_width", ":", "str_replace", "(", "\"px\"", ",", "\"\"", ",", "$", "this", "->", "width", ")", ")", ",", "\"height\"", "=>", "(", "$", "elevation_height", "!=", "\"\"", "?", "$", "elevation_height", ":", "str_replace", "(", "\"px\"", ",", "\"\"", ",", "$", "this", "->", "height", ")", "/", "2", ")", ",", "\"elevation_dom_id\"", "=>", "$", "elevation_dom_id", ")", ";", "if", "(", "$", "add_markers", "==", "true", ")", "{", "$", "this", "->", "addMarkerByAddress", "(", "$", "start_address", ",", "$", "start_address", ",", "$", "start_address", ")", ";", "$", "this", "->", "addMarkerByAddress", "(", "$", "dest_address", ",", "$", "dest_address", ",", "$", "dest_address", ")", ";", "}", "}", "}" ]
Add directions route to the map and adds text directions container with id=$dom_id @param string $start_address @param string $dest_address @param string $dom_id DOM Element ID for directions container. @param bool $add_markers Add a marker at start and dest locations.
[ "Add", "directions", "route", "to", "the", "map", "and", "adds", "text", "directions", "container", "with", "id", "=", "$dom_id" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L894-L914
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.setMapType
function setMapType($type) { switch($type) { case 'hybrid': $this->map_type = 'HYBRID'; break; case 'satellite': $this->map_type = 'SATELLITE'; break; case 'terrain': $this->map_type = 'TERRAIN'; break; case 'map': default: $this->map_type = 'ROADMAP'; break; } }
php
function setMapType($type) { switch($type) { case 'hybrid': $this->map_type = 'HYBRID'; break; case 'satellite': $this->map_type = 'SATELLITE'; break; case 'terrain': $this->map_type = 'TERRAIN'; break; case 'map': default: $this->map_type = 'ROADMAP'; break; } }
[ "function", "setMapType", "(", "$", "type", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "'hybrid'", ":", "$", "this", "->", "map_type", "=", "'HYBRID'", ";", "break", ";", "case", "'satellite'", ":", "$", "this", "->", "map_type", "=", "'SATELLITE'", ";", "break", ";", "case", "'terrain'", ":", "$", "this", "->", "map_type", "=", "'TERRAIN'", ";", "break", ";", "case", "'map'", ":", "default", ":", "$", "this", "->", "map_type", "=", "'ROADMAP'", ";", "break", ";", "}", "}" ]
set default map type (map/satellite/hybrid) @param string $type New V3 Map Types, only include ending word (HYBRID,SATELLITE,TERRAIN,ROADMAP)
[ "set", "default", "map", "type", "(", "map", "/", "satellite", "/", "hybrid", ")" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L972-L988
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.setClusterOptions
function setClusterOptions($zoom="null", $gridsize="null", $styles="null"){ $this->marker_clusterer_options["maxZoom"]=$zoom; $this->marker_clusterer_options["gridSize"]=$gridsize; $this->marker_clusterer_options["styles"]=$styles; }
php
function setClusterOptions($zoom="null", $gridsize="null", $styles="null"){ $this->marker_clusterer_options["maxZoom"]=$zoom; $this->marker_clusterer_options["gridSize"]=$gridsize; $this->marker_clusterer_options["styles"]=$styles; }
[ "function", "setClusterOptions", "(", "$", "zoom", "=", "\"null\"", ",", "$", "gridsize", "=", "\"null\"", ",", "$", "styles", "=", "\"null\"", ")", "{", "$", "this", "->", "marker_clusterer_options", "[", "\"maxZoom\"", "]", "=", "$", "zoom", ";", "$", "this", "->", "marker_clusterer_options", "[", "\"gridSize\"", "]", "=", "$", "gridsize", ";", "$", "this", "->", "marker_clusterer_options", "[", "\"styles\"", "]", "=", "$", "styles", ";", "}" ]
set clustering options
[ "set", "clustering", "options" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L1180-L1184
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.addMarkerByAddress
function addMarkerByAddress($address,$title = '',$html = '',$tooltip = '', $icon_filename = '', $icon_shadow_filename='') { if(($_geocode = $this->getGeocode($address)) === false) return false; return $this->addMarkerByCoords($_geocode['lon'],$_geocode['lat'],$title,$html,$tooltip, $icon_filename, $icon_shadow_filename); }
php
function addMarkerByAddress($address,$title = '',$html = '',$tooltip = '', $icon_filename = '', $icon_shadow_filename='') { if(($_geocode = $this->getGeocode($address)) === false) return false; return $this->addMarkerByCoords($_geocode['lon'],$_geocode['lat'],$title,$html,$tooltip, $icon_filename, $icon_shadow_filename); }
[ "function", "addMarkerByAddress", "(", "$", "address", ",", "$", "title", "=", "''", ",", "$", "html", "=", "''", ",", "$", "tooltip", "=", "''", ",", "$", "icon_filename", "=", "''", ",", "$", "icon_shadow_filename", "=", "''", ")", "{", "if", "(", "(", "$", "_geocode", "=", "$", "this", "->", "getGeocode", "(", "$", "address", ")", ")", "===", "false", ")", "return", "false", ";", "return", "$", "this", "->", "addMarkerByCoords", "(", "$", "_geocode", "[", "'lon'", "]", ",", "$", "_geocode", "[", "'lat'", "]", ",", "$", "title", ",", "$", "html", ",", "$", "tooltip", ",", "$", "icon_filename", ",", "$", "icon_shadow_filename", ")", ";", "}" ]
adds a map marker by address - DEPRECATION WARNING: Tabs are no longer supported in V3, if this changes this can be easily updated. @param string $address the map address to mark (street/city/state/zip) @param string $title the title display in the sidebar @param string $html the HTML block to display in the info bubble (if empty, title is used) @param string $tooltip Tooltip to display (deprecated?) @param string $icon_filename Web file location (eg http://somesite/someicon.gif) to use for icon @param string $icon_shadow_filename Web file location (eg http://somesite/someicon.gif) to use for icon shadow @return int|bool
[ "adds", "a", "map", "marker", "by", "address", "-", "DEPRECATION", "WARNING", ":", "Tabs", "are", "no", "longer", "supported", "in", "V3", "if", "this", "changes", "this", "can", "be", "easily", "updated", "." ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L1297-L1301
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.addMarkerByCoords
function addMarkerByCoords($lon,$lat,$title = '',$html = '',$tooltip = '', $icon_filename = '', $icon_shadow_filename='') { $_marker['lon'] = $lon; $_marker['lat'] = $lat; $_marker['html'] = (is_array($html) || strlen($html) > 0) ? $html : $title; $_marker['title'] = $title; $_marker['tooltip'] = $tooltip; if($icon_filename!=""){ $_marker['icon_key'] = $this->setMarkerIconKey($icon_filename, $icon_shadow_filename); if($icon_shadow_filename!=""){ $_marker['shadow_icon']=1; } }else if( $this->default_icon != ''){ $_marker['icon_key'] = $this->setMarkerIconKey($this->default_icon, $this->default_icon_shadow); if($this->default_icon_shadow!=""){ $_marker['shadow_icon']=1; } } $this->_markers[] = $_marker; $this->adjustCenterCoords($_marker['lon'],$_marker['lat']); // return index of marker return count($this->_markers) - 1; }
php
function addMarkerByCoords($lon,$lat,$title = '',$html = '',$tooltip = '', $icon_filename = '', $icon_shadow_filename='') { $_marker['lon'] = $lon; $_marker['lat'] = $lat; $_marker['html'] = (is_array($html) || strlen($html) > 0) ? $html : $title; $_marker['title'] = $title; $_marker['tooltip'] = $tooltip; if($icon_filename!=""){ $_marker['icon_key'] = $this->setMarkerIconKey($icon_filename, $icon_shadow_filename); if($icon_shadow_filename!=""){ $_marker['shadow_icon']=1; } }else if( $this->default_icon != ''){ $_marker['icon_key'] = $this->setMarkerIconKey($this->default_icon, $this->default_icon_shadow); if($this->default_icon_shadow!=""){ $_marker['shadow_icon']=1; } } $this->_markers[] = $_marker; $this->adjustCenterCoords($_marker['lon'],$_marker['lat']); // return index of marker return count($this->_markers) - 1; }
[ "function", "addMarkerByCoords", "(", "$", "lon", ",", "$", "lat", ",", "$", "title", "=", "''", ",", "$", "html", "=", "''", ",", "$", "tooltip", "=", "''", ",", "$", "icon_filename", "=", "''", ",", "$", "icon_shadow_filename", "=", "''", ")", "{", "$", "_marker", "[", "'lon'", "]", "=", "$", "lon", ";", "$", "_marker", "[", "'lat'", "]", "=", "$", "lat", ";", "$", "_marker", "[", "'html'", "]", "=", "(", "is_array", "(", "$", "html", ")", "||", "strlen", "(", "$", "html", ")", ">", "0", ")", "?", "$", "html", ":", "$", "title", ";", "$", "_marker", "[", "'title'", "]", "=", "$", "title", ";", "$", "_marker", "[", "'tooltip'", "]", "=", "$", "tooltip", ";", "if", "(", "$", "icon_filename", "!=", "\"\"", ")", "{", "$", "_marker", "[", "'icon_key'", "]", "=", "$", "this", "->", "setMarkerIconKey", "(", "$", "icon_filename", ",", "$", "icon_shadow_filename", ")", ";", "if", "(", "$", "icon_shadow_filename", "!=", "\"\"", ")", "{", "$", "_marker", "[", "'shadow_icon'", "]", "=", "1", ";", "}", "}", "else", "if", "(", "$", "this", "->", "default_icon", "!=", "''", ")", "{", "$", "_marker", "[", "'icon_key'", "]", "=", "$", "this", "->", "setMarkerIconKey", "(", "$", "this", "->", "default_icon", ",", "$", "this", "->", "default_icon_shadow", ")", ";", "if", "(", "$", "this", "->", "default_icon_shadow", "!=", "\"\"", ")", "{", "$", "_marker", "[", "'shadow_icon'", "]", "=", "1", ";", "}", "}", "$", "this", "->", "_markers", "[", "]", "=", "$", "_marker", ";", "$", "this", "->", "adjustCenterCoords", "(", "$", "_marker", "[", "'lon'", "]", ",", "$", "_marker", "[", "'lat'", "]", ")", ";", "// return index of marker", "return", "count", "(", "$", "this", "->", "_markers", ")", "-", "1", ";", "}" ]
adds a map marker by lat/lng coordinates - DEPRECATION WARNING: Tabs are no longer supported in V3, if this changes this can be easily updated. @param string $lon the map longitude (horizontal) @param string $lat the map latitude (vertical) @param string $title the title display in the sidebar @param string $html the HTML block to display in the info bubble (if empty, title is used) @param string $tooltip Tooltip to display (deprecated?) @param string $icon_filename Web file location (eg http://somesite/someicon.gif) to use for icon @param string $icon_shadow_filename Web file location (eg http://somesite/someicon.gif) to use for icon shadow @return int|bool
[ "adds", "a", "map", "marker", "by", "lat", "/", "lng", "coordinates", "-", "DEPRECATION", "WARNING", ":", "Tabs", "are", "no", "longer", "supported", "in", "V3", "if", "this", "changes", "this", "can", "be", "easily", "updated", "." ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L1315-L1337
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.addMarkerOpener
function addMarkerOpener($marker_id, $dom_id){ if($this->info_window === false || !isset($this->_markers[$marker_id])) return false; if(!isset($this->_markers[$marker_id]["openers"])) $this->_markers[$marker_id]["openers"] = array(); $this->_markers[$marker_id]["openers"][] = $dom_id; }
php
function addMarkerOpener($marker_id, $dom_id){ if($this->info_window === false || !isset($this->_markers[$marker_id])) return false; if(!isset($this->_markers[$marker_id]["openers"])) $this->_markers[$marker_id]["openers"] = array(); $this->_markers[$marker_id]["openers"][] = $dom_id; }
[ "function", "addMarkerOpener", "(", "$", "marker_id", ",", "$", "dom_id", ")", "{", "if", "(", "$", "this", "->", "info_window", "===", "false", "||", "!", "isset", "(", "$", "this", "->", "_markers", "[", "$", "marker_id", "]", ")", ")", "return", "false", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "_markers", "[", "$", "marker_id", "]", "[", "\"openers\"", "]", ")", ")", "$", "this", "->", "_markers", "[", "$", "marker_id", "]", "[", "\"openers\"", "]", "=", "array", "(", ")", ";", "$", "this", "->", "_markers", "[", "$", "marker_id", "]", "[", "\"openers\"", "]", "[", "]", "=", "$", "dom_id", ";", "}" ]
adds a DOM object ID to specified marker to open the marker's info window. Does nothing if the info windows is disabled. @param string $marker_id ID of the marker to associate to @param string $dom_id ID of the DOM object to use to open marker info window @return bool true/false status
[ "adds", "a", "DOM", "object", "ID", "to", "specified", "marker", "to", "open", "the", "marker", "s", "info", "window", ".", "Does", "nothing", "if", "the", "info", "windows", "is", "disabled", "." ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L1346-L1352
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.addPolylineByCoordsArray
function addPolylineByCoordsArray($polyline_array,$id=false,$color='',$weight=0,$opacity=0){ if(!is_array($polyline_array) || sizeof($polyline_array) < 2) return false; $_prev_coords = ""; $_next_coords = ""; foreach($polyline_array as $_coords){ $_prev_coords = $_next_coords; $_next_coords = $_coords; if($_prev_coords !== ""){ $_lt1=$_prev_coords["lat"]; $_ln1=$_prev_coords["long"]; $_lt2=$_next_coords["lat"]; $_ln2=$_next_coords["long"]; $id = $this->addPolyLineByCoords($_ln1, $_lt1, $_ln2, $_lt2, $id, $color, $weight, $opacity); } } return $id; }
php
function addPolylineByCoordsArray($polyline_array,$id=false,$color='',$weight=0,$opacity=0){ if(!is_array($polyline_array) || sizeof($polyline_array) < 2) return false; $_prev_coords = ""; $_next_coords = ""; foreach($polyline_array as $_coords){ $_prev_coords = $_next_coords; $_next_coords = $_coords; if($_prev_coords !== ""){ $_lt1=$_prev_coords["lat"]; $_ln1=$_prev_coords["long"]; $_lt2=$_next_coords["lat"]; $_ln2=$_next_coords["long"]; $id = $this->addPolyLineByCoords($_ln1, $_lt1, $_ln2, $_lt2, $id, $color, $weight, $opacity); } } return $id; }
[ "function", "addPolylineByCoordsArray", "(", "$", "polyline_array", ",", "$", "id", "=", "false", ",", "$", "color", "=", "''", ",", "$", "weight", "=", "0", ",", "$", "opacity", "=", "0", ")", "{", "if", "(", "!", "is_array", "(", "$", "polyline_array", ")", "||", "sizeof", "(", "$", "polyline_array", ")", "<", "2", ")", "return", "false", ";", "$", "_prev_coords", "=", "\"\"", ";", "$", "_next_coords", "=", "\"\"", ";", "foreach", "(", "$", "polyline_array", "as", "$", "_coords", ")", "{", "$", "_prev_coords", "=", "$", "_next_coords", ";", "$", "_next_coords", "=", "$", "_coords", ";", "if", "(", "$", "_prev_coords", "!==", "\"\"", ")", "{", "$", "_lt1", "=", "$", "_prev_coords", "[", "\"lat\"", "]", ";", "$", "_ln1", "=", "$", "_prev_coords", "[", "\"long\"", "]", ";", "$", "_lt2", "=", "$", "_next_coords", "[", "\"lat\"", "]", ";", "$", "_ln2", "=", "$", "_next_coords", "[", "\"long\"", "]", ";", "$", "id", "=", "$", "this", "->", "addPolyLineByCoords", "(", "$", "_ln1", ",", "$", "_lt1", ",", "$", "_ln2", ",", "$", "_lt2", ",", "$", "id", ",", "$", "color", ",", "$", "weight", ",", "$", "opacity", ")", ";", "}", "}", "return", "$", "id", ";", "}" ]
adds polyline by passed array if color, weight and opacity are not defined, use the google maps defaults @param array $polyline_array array of lat/long coords @param string $id An array id to use to append coordinates to a line @param string $color the color of the line (format: #000000) @param string $weight the weight of the line in pixels @param string $opacity the line opacity (percentage) @return bool|int Array id of newly added point or false
[ "adds", "polyline", "by", "passed", "array", "if", "color", "weight", "and", "opacity", "are", "not", "defined", "use", "the", "google", "maps", "defaults" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L1364-L1383
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.addPolylineByAddressArray
function addPolylineByAddressArray($polyline_array,$id=false,$color='',$weight=0,$opacity=0){ if(!is_array($polyline_array) || sizeof($polyline_array) < 2) return false; $_prev_address = ""; $_next_address = ""; foreach($polyline_array as $_address){ $_prev_address = $_next_address; $_next_address = $_address; if($_prev_address !== ""){ $id = $this->addPolyLineByAddress($_prev_address, $_next_address, $id, $color, $weight, $opacity); } } return $id; }
php
function addPolylineByAddressArray($polyline_array,$id=false,$color='',$weight=0,$opacity=0){ if(!is_array($polyline_array) || sizeof($polyline_array) < 2) return false; $_prev_address = ""; $_next_address = ""; foreach($polyline_array as $_address){ $_prev_address = $_next_address; $_next_address = $_address; if($_prev_address !== ""){ $id = $this->addPolyLineByAddress($_prev_address, $_next_address, $id, $color, $weight, $opacity); } } return $id; }
[ "function", "addPolylineByAddressArray", "(", "$", "polyline_array", ",", "$", "id", "=", "false", ",", "$", "color", "=", "''", ",", "$", "weight", "=", "0", ",", "$", "opacity", "=", "0", ")", "{", "if", "(", "!", "is_array", "(", "$", "polyline_array", ")", "||", "sizeof", "(", "$", "polyline_array", ")", "<", "2", ")", "return", "false", ";", "$", "_prev_address", "=", "\"\"", ";", "$", "_next_address", "=", "\"\"", ";", "foreach", "(", "$", "polyline_array", "as", "$", "_address", ")", "{", "$", "_prev_address", "=", "$", "_next_address", ";", "$", "_next_address", "=", "$", "_address", ";", "if", "(", "$", "_prev_address", "!==", "\"\"", ")", "{", "$", "id", "=", "$", "this", "->", "addPolyLineByAddress", "(", "$", "_prev_address", ",", "$", "_next_address", ",", "$", "id", ",", "$", "color", ",", "$", "weight", ",", "$", "opacity", ")", ";", "}", "}", "return", "$", "id", ";", "}" ]
adds polyline by passed array if color, weight and opacity are not defined, use the google maps defaults @param array $polyline_array array of addresses @param string $id An array id to use to append coordinates to a line @param string $color the color of the line (format: #000000) @param string $weight the weight of the line in pixels @param string $opacity the line opacity (percentage) @return bool|int Array id of newly added point or false
[ "adds", "polyline", "by", "passed", "array", "if", "color", "weight", "and", "opacity", "are", "not", "defined", "use", "the", "google", "maps", "defaults" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L1395-L1410
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.addPolyLineByAddress
function addPolyLineByAddress($address1,$address2,$id=false,$color='',$weight=0,$opacity=0) { if(($_geocode1 = $this->getGeocode($address1)) === false) return false; if(($_geocode2 = $this->getGeocode($address2)) === false) return false; return $this->addPolyLineByCoords($_geocode1['lon'],$_geocode1['lat'],$_geocode2['lon'],$_geocode2['lat'],$id,$color,$weight,$opacity); }
php
function addPolyLineByAddress($address1,$address2,$id=false,$color='',$weight=0,$opacity=0) { if(($_geocode1 = $this->getGeocode($address1)) === false) return false; if(($_geocode2 = $this->getGeocode($address2)) === false) return false; return $this->addPolyLineByCoords($_geocode1['lon'],$_geocode1['lat'],$_geocode2['lon'],$_geocode2['lat'],$id,$color,$weight,$opacity); }
[ "function", "addPolyLineByAddress", "(", "$", "address1", ",", "$", "address2", ",", "$", "id", "=", "false", ",", "$", "color", "=", "''", ",", "$", "weight", "=", "0", ",", "$", "opacity", "=", "0", ")", "{", "if", "(", "(", "$", "_geocode1", "=", "$", "this", "->", "getGeocode", "(", "$", "address1", ")", ")", "===", "false", ")", "return", "false", ";", "if", "(", "(", "$", "_geocode2", "=", "$", "this", "->", "getGeocode", "(", "$", "address2", ")", ")", "===", "false", ")", "return", "false", ";", "return", "$", "this", "->", "addPolyLineByCoords", "(", "$", "_geocode1", "[", "'lon'", "]", ",", "$", "_geocode1", "[", "'lat'", "]", ",", "$", "_geocode2", "[", "'lon'", "]", ",", "$", "_geocode2", "[", "'lat'", "]", ",", "$", "id", ",", "$", "color", ",", "$", "weight", ",", "$", "opacity", ")", ";", "}" ]
adds a map polyline by address if color, weight and opacity are not defined, use the google maps defaults @param string $address1 the map address to draw from @param string $address2 the map address to draw to @param string $id An array id to use to append coordinates to a line @param string $color the color of the line (format: #000000) @param string $weight the weight of the line in pixels @param string $opacity the line opacity (percentage) @return bool|int Array id of newly added point or false
[ "adds", "a", "map", "polyline", "by", "address", "if", "color", "weight", "and", "opacity", "are", "not", "defined", "use", "the", "google", "maps", "defaults" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L1424-L1430
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.addPolyLineByCoords
function addPolyLineByCoords($lon1,$lat1,$lon2,$lat2,$id=false,$color='',$weight=0,$opacity=0) { if($id !== false && isset($this->_polylines[$id]) && is_array($this->_polylines[$id])){ $_polyline = $this->_polylines[$id]; }else{ //only set color,weight,and opacity if new polyline $_polyline = array( "color"=>$color, "weight"=>$weight, "opacity"=>$opacity ); } if(!isset($_polyline['coords']) || !is_array($_polyline['coords'])){ $_polyline['coords'] = array( "0"=> array("lat"=>$lat1, "long"=>$lon1), "1"=> array("lat"=>$lat2, "long"=>$lon2) ); }else{ $last_index = sizeof($_polyline['coords'])-1; //check if lat1/lon1 point is already on polyline if($_polyline['coords'][$last_index]["lat"] != $lat1 || $_polyline['coords'][$last_index]["long"] != $lon1){ $_polyline['coords'][] = array("lat"=>$lat1, "long"=>$lon1); } $_polyline['coords'][] = array("lat"=>$lat2, "long"=>$lon2); } if($id === false){ $this->_polylines[] = $_polyline; $id = count($this->_polylines) - 1; }else{ $this->_polylines[$id] = $_polyline; } $this->adjustCenterCoords($lon1,$lat1); $this->adjustCenterCoords($lon2,$lat2); // return index of polyline return $id; }
php
function addPolyLineByCoords($lon1,$lat1,$lon2,$lat2,$id=false,$color='',$weight=0,$opacity=0) { if($id !== false && isset($this->_polylines[$id]) && is_array($this->_polylines[$id])){ $_polyline = $this->_polylines[$id]; }else{ //only set color,weight,and opacity if new polyline $_polyline = array( "color"=>$color, "weight"=>$weight, "opacity"=>$opacity ); } if(!isset($_polyline['coords']) || !is_array($_polyline['coords'])){ $_polyline['coords'] = array( "0"=> array("lat"=>$lat1, "long"=>$lon1), "1"=> array("lat"=>$lat2, "long"=>$lon2) ); }else{ $last_index = sizeof($_polyline['coords'])-1; //check if lat1/lon1 point is already on polyline if($_polyline['coords'][$last_index]["lat"] != $lat1 || $_polyline['coords'][$last_index]["long"] != $lon1){ $_polyline['coords'][] = array("lat"=>$lat1, "long"=>$lon1); } $_polyline['coords'][] = array("lat"=>$lat2, "long"=>$lon2); } if($id === false){ $this->_polylines[] = $_polyline; $id = count($this->_polylines) - 1; }else{ $this->_polylines[$id] = $_polyline; } $this->adjustCenterCoords($lon1,$lat1); $this->adjustCenterCoords($lon2,$lat2); // return index of polyline return $id; }
[ "function", "addPolyLineByCoords", "(", "$", "lon1", ",", "$", "lat1", ",", "$", "lon2", ",", "$", "lat2", ",", "$", "id", "=", "false", ",", "$", "color", "=", "''", ",", "$", "weight", "=", "0", ",", "$", "opacity", "=", "0", ")", "{", "if", "(", "$", "id", "!==", "false", "&&", "isset", "(", "$", "this", "->", "_polylines", "[", "$", "id", "]", ")", "&&", "is_array", "(", "$", "this", "->", "_polylines", "[", "$", "id", "]", ")", ")", "{", "$", "_polyline", "=", "$", "this", "->", "_polylines", "[", "$", "id", "]", ";", "}", "else", "{", "//only set color,weight,and opacity if new polyline", "$", "_polyline", "=", "array", "(", "\"color\"", "=>", "$", "color", ",", "\"weight\"", "=>", "$", "weight", ",", "\"opacity\"", "=>", "$", "opacity", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "_polyline", "[", "'coords'", "]", ")", "||", "!", "is_array", "(", "$", "_polyline", "[", "'coords'", "]", ")", ")", "{", "$", "_polyline", "[", "'coords'", "]", "=", "array", "(", "\"0\"", "=>", "array", "(", "\"lat\"", "=>", "$", "lat1", ",", "\"long\"", "=>", "$", "lon1", ")", ",", "\"1\"", "=>", "array", "(", "\"lat\"", "=>", "$", "lat2", ",", "\"long\"", "=>", "$", "lon2", ")", ")", ";", "}", "else", "{", "$", "last_index", "=", "sizeof", "(", "$", "_polyline", "[", "'coords'", "]", ")", "-", "1", ";", "//check if lat1/lon1 point is already on polyline", "if", "(", "$", "_polyline", "[", "'coords'", "]", "[", "$", "last_index", "]", "[", "\"lat\"", "]", "!=", "$", "lat1", "||", "$", "_polyline", "[", "'coords'", "]", "[", "$", "last_index", "]", "[", "\"long\"", "]", "!=", "$", "lon1", ")", "{", "$", "_polyline", "[", "'coords'", "]", "[", "]", "=", "array", "(", "\"lat\"", "=>", "$", "lat1", ",", "\"long\"", "=>", "$", "lon1", ")", ";", "}", "$", "_polyline", "[", "'coords'", "]", "[", "]", "=", "array", "(", "\"lat\"", "=>", "$", "lat2", ",", "\"long\"", "=>", "$", "lon2", ")", ";", "}", "if", "(", "$", "id", "===", "false", ")", "{", "$", "this", "->", "_polylines", "[", "]", "=", "$", "_polyline", ";", "$", "id", "=", "count", "(", "$", "this", "->", "_polylines", ")", "-", "1", ";", "}", "else", "{", "$", "this", "->", "_polylines", "[", "$", "id", "]", "=", "$", "_polyline", ";", "}", "$", "this", "->", "adjustCenterCoords", "(", "$", "lon1", ",", "$", "lat1", ")", ";", "$", "this", "->", "adjustCenterCoords", "(", "$", "lon2", ",", "$", "lat2", ")", ";", "// return index of polyline", "return", "$", "id", ";", "}" ]
adds a map polyline by map coordinates if color, weight and opacity are not defined, use the google maps defaults @param string $lon1 the map longitude to draw from @param string $lat1 the map latitude to draw from @param string $lon2 the map longitude to draw to @param string $lat2 the map latitude to draw to @param string $id An array id to use to append coordinates to a line @param string $color the color of the line (format: #000000) @param string $weight the weight of the line in pixels @param string $opacity the line opacity (percentage) @return string $id id of the created/updated polyline array
[ "adds", "a", "map", "polyline", "by", "map", "coordinates", "if", "color", "weight", "and", "opacity", "are", "not", "defined", "use", "the", "google", "maps", "defaults" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L1446-L1480
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.addPolylineElevation
function addPolylineElevation($polyline_id, $elevation_dom_id, $samples=256, $width="", $height="", $focus_color="#00ff00"){ if(isset($this->_polylines[$polyline_id])){ $this->_elevation_polylines[$polyline_id] = array( "dom_id"=>$elevation_dom_id, "samples"=>$samples, "width"=>($width!=""?$width:str_replace("px","",$this->width)), "height"=>($height!=""?$height:str_replace("px","",$this->height)/2), "focus_color"=>$focus_color ); } }
php
function addPolylineElevation($polyline_id, $elevation_dom_id, $samples=256, $width="", $height="", $focus_color="#00ff00"){ if(isset($this->_polylines[$polyline_id])){ $this->_elevation_polylines[$polyline_id] = array( "dom_id"=>$elevation_dom_id, "samples"=>$samples, "width"=>($width!=""?$width:str_replace("px","",$this->width)), "height"=>($height!=""?$height:str_replace("px","",$this->height)/2), "focus_color"=>$focus_color ); } }
[ "function", "addPolylineElevation", "(", "$", "polyline_id", ",", "$", "elevation_dom_id", ",", "$", "samples", "=", "256", ",", "$", "width", "=", "\"\"", ",", "$", "height", "=", "\"\"", ",", "$", "focus_color", "=", "\"#00ff00\"", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_polylines", "[", "$", "polyline_id", "]", ")", ")", "{", "$", "this", "->", "_elevation_polylines", "[", "$", "polyline_id", "]", "=", "array", "(", "\"dom_id\"", "=>", "$", "elevation_dom_id", ",", "\"samples\"", "=>", "$", "samples", ",", "\"width\"", "=>", "(", "$", "width", "!=", "\"\"", "?", "$", "width", ":", "str_replace", "(", "\"px\"", ",", "\"\"", ",", "$", "this", "->", "width", ")", ")", ",", "\"height\"", "=>", "(", "$", "height", "!=", "\"\"", "?", "$", "height", ":", "str_replace", "(", "\"px\"", ",", "\"\"", ",", "$", "this", "->", "height", ")", "/", "2", ")", ",", "\"focus_color\"", "=>", "$", "focus_color", ")", ";", "}", "}" ]
function to add an elevation profile for a polyline to the page
[ "function", "to", "add", "an", "elevation", "profile", "for", "a", "polyline", "to", "the", "page" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L1485-L1495
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.addOverlay
function addOverlay($bds_lat1, $bds_lon1, $bds_lat2, $bds_lon2, $img_src, $opacity = 100){ $_overlay = array( "bounds" => array( "ne"=>array( "lat"=>$bds_lat1, "long"=>$bds_lon1 ), "sw"=>array( "lat"=>$bds_lat2, "long"=>$bds_lon2 ) ), "img" => $img_src, "opacity" => $opacity/10 ); $this->adjustCenterCoords($bds_lon1,$bds_lat1); $this->adjustCenterCoords($bds_lon2,$bds_lat2); $this->_overlays[] = $_overlay; return count($this->_overlays)-1; }
php
function addOverlay($bds_lat1, $bds_lon1, $bds_lat2, $bds_lon2, $img_src, $opacity = 100){ $_overlay = array( "bounds" => array( "ne"=>array( "lat"=>$bds_lat1, "long"=>$bds_lon1 ), "sw"=>array( "lat"=>$bds_lat2, "long"=>$bds_lon2 ) ), "img" => $img_src, "opacity" => $opacity/10 ); $this->adjustCenterCoords($bds_lon1,$bds_lat1); $this->adjustCenterCoords($bds_lon2,$bds_lat2); $this->_overlays[] = $_overlay; return count($this->_overlays)-1; }
[ "function", "addOverlay", "(", "$", "bds_lat1", ",", "$", "bds_lon1", ",", "$", "bds_lat2", ",", "$", "bds_lon2", ",", "$", "img_src", ",", "$", "opacity", "=", "100", ")", "{", "$", "_overlay", "=", "array", "(", "\"bounds\"", "=>", "array", "(", "\"ne\"", "=>", "array", "(", "\"lat\"", "=>", "$", "bds_lat1", ",", "\"long\"", "=>", "$", "bds_lon1", ")", ",", "\"sw\"", "=>", "array", "(", "\"lat\"", "=>", "$", "bds_lat2", ",", "\"long\"", "=>", "$", "bds_lon2", ")", ")", ",", "\"img\"", "=>", "$", "img_src", ",", "\"opacity\"", "=>", "$", "opacity", "/", "10", ")", ";", "$", "this", "->", "adjustCenterCoords", "(", "$", "bds_lon1", ",", "$", "bds_lat1", ")", ";", "$", "this", "->", "adjustCenterCoords", "(", "$", "bds_lon2", ",", "$", "bds_lat2", ")", ";", "$", "this", "->", "_overlays", "[", "]", "=", "$", "_overlay", ";", "return", "count", "(", "$", "this", "->", "_overlays", ")", "-", "1", ";", "}" ]
function to add an overlay to the map.
[ "function", "to", "add", "an", "overlay", "to", "the", "map", "." ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L1500-L1519
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.adjustCenterCoords
function adjustCenterCoords($lon,$lat) { if(strlen((string)$lon) == 0 || strlen((string)$lat) == 0) return false; $this->_max_lon = (float) max($lon, $this->_max_lon); $this->_min_lon = (float) min($lon, $this->_min_lon); $this->_max_lat = (float) max($lat, $this->_max_lat); $this->_min_lat = (float) min($lat, $this->_min_lat); $this->center_lon = (float) ($this->_min_lon + $this->_max_lon) / 2; $this->center_lat = (float) ($this->_min_lat + $this->_max_lat) / 2; return true; }
php
function adjustCenterCoords($lon,$lat) { if(strlen((string)$lon) == 0 || strlen((string)$lat) == 0) return false; $this->_max_lon = (float) max($lon, $this->_max_lon); $this->_min_lon = (float) min($lon, $this->_min_lon); $this->_max_lat = (float) max($lat, $this->_max_lat); $this->_min_lat = (float) min($lat, $this->_min_lat); $this->center_lon = (float) ($this->_min_lon + $this->_max_lon) / 2; $this->center_lat = (float) ($this->_min_lat + $this->_max_lat) / 2; return true; }
[ "function", "adjustCenterCoords", "(", "$", "lon", ",", "$", "lat", ")", "{", "if", "(", "strlen", "(", "(", "string", ")", "$", "lon", ")", "==", "0", "||", "strlen", "(", "(", "string", ")", "$", "lat", ")", "==", "0", ")", "return", "false", ";", "$", "this", "->", "_max_lon", "=", "(", "float", ")", "max", "(", "$", "lon", ",", "$", "this", "->", "_max_lon", ")", ";", "$", "this", "->", "_min_lon", "=", "(", "float", ")", "min", "(", "$", "lon", ",", "$", "this", "->", "_min_lon", ")", ";", "$", "this", "->", "_max_lat", "=", "(", "float", ")", "max", "(", "$", "lat", ",", "$", "this", "->", "_max_lat", ")", ";", "$", "this", "->", "_min_lat", "=", "(", "float", ")", "min", "(", "$", "lat", ",", "$", "this", "->", "_min_lat", ")", ";", "$", "this", "->", "center_lon", "=", "(", "float", ")", "(", "$", "this", "->", "_min_lon", "+", "$", "this", "->", "_max_lon", ")", "/", "2", ";", "$", "this", "->", "center_lat", "=", "(", "float", ")", "(", "$", "this", "->", "_min_lat", "+", "$", "this", "->", "_max_lat", ")", "/", "2", ";", "return", "true", ";", "}" ]
adjust map center coordinates by the given lat/lon point @param string $lon the map latitude (horizontal) @param string $lat the map latitude (vertical)
[ "adjust", "map", "center", "coordinates", "by", "the", "given", "lat", "/", "lon", "point" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L1537-L1547
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.setCenterCoords
function setCenterCoords($lon,$lat) { $this->center_lat = (float) $lat; $this->center_lon = (float) $lon; }
php
function setCenterCoords($lon,$lat) { $this->center_lat = (float) $lat; $this->center_lon = (float) $lon; }
[ "function", "setCenterCoords", "(", "$", "lon", ",", "$", "lat", ")", "{", "$", "this", "->", "center_lat", "=", "(", "float", ")", "$", "lat", ";", "$", "this", "->", "center_lon", "=", "(", "float", ")", "$", "lon", ";", "}" ]
set map center coordinates to lat/lon point @param string $lon the map latitude (horizontal) @param string $lat the map latitude (vertical)
[ "set", "map", "center", "coordinates", "to", "lat", "/", "lon", "point" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L1555-L1558
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.createMarkerIcon
function createMarkerIcon($iconImage,$iconShadowImage = '',$iconAnchorX = 'x',$iconAnchorY = 'x',$infoWindowAnchorX = 'x',$infoWindowAnchorY = 'x') { $_icon_image_path = strpos($iconImage,'http') === 0 ? $iconImage : $_SERVER['DOCUMENT_ROOT'] . $iconImage; if(!($_image_info = @getimagesize($_icon_image_path))) { die('GoogleMapAPI:createMarkerIcon: Error reading image: ' . $iconImage); } if($iconShadowImage) { $_shadow_image_path = strpos($iconShadowImage,'http') === 0 ? $iconShadowImage : $_SERVER['DOCUMENT_ROOT'] . $iconShadowImage; if(!($_shadow_info = @getimagesize($_shadow_image_path))) { die('GoogleMapAPI:createMarkerIcon: Error reading shadow image: ' . $iconShadowImage); } } if($iconAnchorX === 'x') { $iconAnchorX = (int) ($_image_info[0] / 2); } if($iconAnchorY === 'x') { $iconAnchorY = (int) ($_image_info[1] / 2); } if($infoWindowAnchorX === 'x') { $infoWindowAnchorX = (int) ($_image_info[0] / 2); } if($infoWindowAnchorY === 'x') { $infoWindowAnchorY = (int) ($_image_info[1] / 2); } $icon_info = array( 'image' => $iconImage, 'iconWidth' => $_image_info[0], 'iconHeight' => $_image_info[1], 'iconAnchorX' => $iconAnchorX, 'iconAnchorY' => $iconAnchorY, 'infoWindowAnchorX' => $infoWindowAnchorX, 'infoWindowAnchorY' => $infoWindowAnchorY ); if($iconShadowImage) { $icon_info = array_merge($icon_info, array('shadow' => $iconShadowImage, 'shadowWidth' => $_shadow_info[0], 'shadowHeight' => $_shadow_info[1])); } return $icon_info; }
php
function createMarkerIcon($iconImage,$iconShadowImage = '',$iconAnchorX = 'x',$iconAnchorY = 'x',$infoWindowAnchorX = 'x',$infoWindowAnchorY = 'x') { $_icon_image_path = strpos($iconImage,'http') === 0 ? $iconImage : $_SERVER['DOCUMENT_ROOT'] . $iconImage; if(!($_image_info = @getimagesize($_icon_image_path))) { die('GoogleMapAPI:createMarkerIcon: Error reading image: ' . $iconImage); } if($iconShadowImage) { $_shadow_image_path = strpos($iconShadowImage,'http') === 0 ? $iconShadowImage : $_SERVER['DOCUMENT_ROOT'] . $iconShadowImage; if(!($_shadow_info = @getimagesize($_shadow_image_path))) { die('GoogleMapAPI:createMarkerIcon: Error reading shadow image: ' . $iconShadowImage); } } if($iconAnchorX === 'x') { $iconAnchorX = (int) ($_image_info[0] / 2); } if($iconAnchorY === 'x') { $iconAnchorY = (int) ($_image_info[1] / 2); } if($infoWindowAnchorX === 'x') { $infoWindowAnchorX = (int) ($_image_info[0] / 2); } if($infoWindowAnchorY === 'x') { $infoWindowAnchorY = (int) ($_image_info[1] / 2); } $icon_info = array( 'image' => $iconImage, 'iconWidth' => $_image_info[0], 'iconHeight' => $_image_info[1], 'iconAnchorX' => $iconAnchorX, 'iconAnchorY' => $iconAnchorY, 'infoWindowAnchorX' => $infoWindowAnchorX, 'infoWindowAnchorY' => $infoWindowAnchorY ); if($iconShadowImage) { $icon_info = array_merge($icon_info, array('shadow' => $iconShadowImage, 'shadowWidth' => $_shadow_info[0], 'shadowHeight' => $_shadow_info[1])); } return $icon_info; }
[ "function", "createMarkerIcon", "(", "$", "iconImage", ",", "$", "iconShadowImage", "=", "''", ",", "$", "iconAnchorX", "=", "'x'", ",", "$", "iconAnchorY", "=", "'x'", ",", "$", "infoWindowAnchorX", "=", "'x'", ",", "$", "infoWindowAnchorY", "=", "'x'", ")", "{", "$", "_icon_image_path", "=", "strpos", "(", "$", "iconImage", ",", "'http'", ")", "===", "0", "?", "$", "iconImage", ":", "$", "_SERVER", "[", "'DOCUMENT_ROOT'", "]", ".", "$", "iconImage", ";", "if", "(", "!", "(", "$", "_image_info", "=", "@", "getimagesize", "(", "$", "_icon_image_path", ")", ")", ")", "{", "die", "(", "'GoogleMapAPI:createMarkerIcon: Error reading image: '", ".", "$", "iconImage", ")", ";", "}", "if", "(", "$", "iconShadowImage", ")", "{", "$", "_shadow_image_path", "=", "strpos", "(", "$", "iconShadowImage", ",", "'http'", ")", "===", "0", "?", "$", "iconShadowImage", ":", "$", "_SERVER", "[", "'DOCUMENT_ROOT'", "]", ".", "$", "iconShadowImage", ";", "if", "(", "!", "(", "$", "_shadow_info", "=", "@", "getimagesize", "(", "$", "_shadow_image_path", ")", ")", ")", "{", "die", "(", "'GoogleMapAPI:createMarkerIcon: Error reading shadow image: '", ".", "$", "iconShadowImage", ")", ";", "}", "}", "if", "(", "$", "iconAnchorX", "===", "'x'", ")", "{", "$", "iconAnchorX", "=", "(", "int", ")", "(", "$", "_image_info", "[", "0", "]", "/", "2", ")", ";", "}", "if", "(", "$", "iconAnchorY", "===", "'x'", ")", "{", "$", "iconAnchorY", "=", "(", "int", ")", "(", "$", "_image_info", "[", "1", "]", "/", "2", ")", ";", "}", "if", "(", "$", "infoWindowAnchorX", "===", "'x'", ")", "{", "$", "infoWindowAnchorX", "=", "(", "int", ")", "(", "$", "_image_info", "[", "0", "]", "/", "2", ")", ";", "}", "if", "(", "$", "infoWindowAnchorY", "===", "'x'", ")", "{", "$", "infoWindowAnchorY", "=", "(", "int", ")", "(", "$", "_image_info", "[", "1", "]", "/", "2", ")", ";", "}", "$", "icon_info", "=", "array", "(", "'image'", "=>", "$", "iconImage", ",", "'iconWidth'", "=>", "$", "_image_info", "[", "0", "]", ",", "'iconHeight'", "=>", "$", "_image_info", "[", "1", "]", ",", "'iconAnchorX'", "=>", "$", "iconAnchorX", ",", "'iconAnchorY'", "=>", "$", "iconAnchorY", ",", "'infoWindowAnchorX'", "=>", "$", "infoWindowAnchorX", ",", "'infoWindowAnchorY'", "=>", "$", "infoWindowAnchorY", ")", ";", "if", "(", "$", "iconShadowImage", ")", "{", "$", "icon_info", "=", "array_merge", "(", "$", "icon_info", ",", "array", "(", "'shadow'", "=>", "$", "iconShadowImage", ",", "'shadowWidth'", "=>", "$", "_shadow_info", "[", "0", "]", ",", "'shadowHeight'", "=>", "$", "_shadow_info", "[", "1", "]", ")", ")", ";", "}", "return", "$", "icon_info", ";", "}" ]
generate an array of params for a new marker icon image iconShadowImage is optional If anchor coords are not supplied, we use the center point of the image by default. Can be called statically. For private use by addMarkerIcon() and setMarkerIcon() and addIcon() @param string $iconImage URL to icon image @param string $iconShadowImage URL to shadow image @param string $iconAnchorX X coordinate for icon anchor point @param string $iconAnchorY Y coordinate for icon anchor point @param string $infoWindowAnchorX X coordinate for info window anchor point @param string $infoWindowAnchorY Y coordinate for info window anchor point @return array Array with information about newly /previously created icon.
[ "generate", "an", "array", "of", "params", "for", "a", "new", "marker", "icon", "image", "iconShadowImage", "is", "optional", "If", "anchor", "coords", "are", "not", "supplied", "we", "use", "the", "center", "point", "of", "the", "image", "by", "default", ".", "Can", "be", "called", "statically", ".", "For", "private", "use", "by", "addMarkerIcon", "()", "and", "setMarkerIcon", "()", "and", "addIcon", "()" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L1574-L1614
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.setMarkerIcon
function setMarkerIcon($iconImage,$iconShadowImage = '',$iconAnchorX = 'x',$iconAnchorY = 'x',$infoWindowAnchorX = 'x',$infoWindowAnchorY = 'x') { $this->default_icon = $iconImage; $this->default_icon_shadow = $iconShadowImage; return $this->setMarkerIconKey($iconImage,$iconShadowImage,$iconAnchorX,$iconAnchorY,$infoWindowAnchorX,$infoWindowAnchorY); }
php
function setMarkerIcon($iconImage,$iconShadowImage = '',$iconAnchorX = 'x',$iconAnchorY = 'x',$infoWindowAnchorX = 'x',$infoWindowAnchorY = 'x') { $this->default_icon = $iconImage; $this->default_icon_shadow = $iconShadowImage; return $this->setMarkerIconKey($iconImage,$iconShadowImage,$iconAnchorX,$iconAnchorY,$infoWindowAnchorX,$infoWindowAnchorY); }
[ "function", "setMarkerIcon", "(", "$", "iconImage", ",", "$", "iconShadowImage", "=", "''", ",", "$", "iconAnchorX", "=", "'x'", ",", "$", "iconAnchorY", "=", "'x'", ",", "$", "infoWindowAnchorX", "=", "'x'", ",", "$", "infoWindowAnchorY", "=", "'x'", ")", "{", "$", "this", "->", "default_icon", "=", "$", "iconImage", ";", "$", "this", "->", "default_icon_shadow", "=", "$", "iconShadowImage", ";", "return", "$", "this", "->", "setMarkerIconKey", "(", "$", "iconImage", ",", "$", "iconShadowImage", ",", "$", "iconAnchorX", ",", "$", "iconAnchorY", ",", "$", "infoWindowAnchorX", ",", "$", "infoWindowAnchorY", ")", ";", "}" ]
set the default marker icon for ALL markers on the map NOTE: This MUST be set prior to adding markers in order for the defaults to be set correctly. @param string $iconImage URL to icon image @param string $iconShadowImage URL to shadow image @param string $iconAnchorX X coordinate for icon anchor point @param string $iconAnchorY Y coordinate for icon anchor point @param string $infoWindowAnchorX X coordinate for info window anchor point @param string $infoWindowAnchorY Y coordinate for info window anchor point @return string A marker icon key.
[ "set", "the", "default", "marker", "icon", "for", "ALL", "markers", "on", "the", "map", "NOTE", ":", "This", "MUST", "be", "set", "prior", "to", "adding", "markers", "in", "order", "for", "the", "defaults", "to", "be", "set", "correctly", "." ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L1628-L1632
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.setMarkerIconKey
function setMarkerIconKey($iconImage,$iconShadow='',$iconAnchorX = 'x',$iconAnchorY = 'x',$infoWindowAnchorX = 'x',$infoWindowAnchorY = 'x'){ $_iconKey = $this->getIconKey($iconImage,$iconShadow); if(isset($this->_marker_icons[$_iconKey])){ return $_iconKey; }else{ return $this->addIcon($iconImage,$iconShadow,$iconAnchorX,$iconAnchorY,$infoWindowAnchorX,$infoWindowAnchorY); } }
php
function setMarkerIconKey($iconImage,$iconShadow='',$iconAnchorX = 'x',$iconAnchorY = 'x',$infoWindowAnchorX = 'x',$infoWindowAnchorY = 'x'){ $_iconKey = $this->getIconKey($iconImage,$iconShadow); if(isset($this->_marker_icons[$_iconKey])){ return $_iconKey; }else{ return $this->addIcon($iconImage,$iconShadow,$iconAnchorX,$iconAnchorY,$infoWindowAnchorX,$infoWindowAnchorY); } }
[ "function", "setMarkerIconKey", "(", "$", "iconImage", ",", "$", "iconShadow", "=", "''", ",", "$", "iconAnchorX", "=", "'x'", ",", "$", "iconAnchorY", "=", "'x'", ",", "$", "infoWindowAnchorX", "=", "'x'", ",", "$", "infoWindowAnchorY", "=", "'x'", ")", "{", "$", "_iconKey", "=", "$", "this", "->", "getIconKey", "(", "$", "iconImage", ",", "$", "iconShadow", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "_marker_icons", "[", "$", "_iconKey", "]", ")", ")", "{", "return", "$", "_iconKey", ";", "}", "else", "{", "return", "$", "this", "->", "addIcon", "(", "$", "iconImage", ",", "$", "iconShadow", ",", "$", "iconAnchorX", ",", "$", "iconAnchorY", ",", "$", "infoWindowAnchorX", ",", "$", "infoWindowAnchorY", ")", ";", "}", "}" ]
function to check if icon is in class "marker_iconset", if it is, returns the key, if not, creates a new array indice and returns the key @param string $iconImage URL to icon image @param string $iconShadowImage URL to shadow image @param string $iconAnchorX X coordinate for icon anchor point @param string $iconAnchorY Y coordinate for icon anchor point @param string $infoWindowAnchorX X coordinate for info window anchor point @param string $infoWindowAnchorY Y coordinate for info window anchor point @return string A marker icon key.
[ "function", "to", "check", "if", "icon", "is", "in", "class", "marker_iconset", "if", "it", "is", "returns", "the", "key", "if", "not", "creates", "a", "new", "array", "indice", "and", "returns", "the", "key" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L1645-L1652
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.addIcon
function addIcon($iconImage,$iconShadowImage = '',$iconAnchorX = 'x',$iconAnchorY = 'x',$infoWindowAnchorX = 'x',$infoWindowAnchorY = 'x') { $_iconKey = $this->getIconKey($iconImage, $iconShadowImage); $this->_marker_icons[$_iconKey] = $this->createMarkerIcon($iconImage,$iconShadowImage,$iconAnchorX,$iconAnchorY,$infoWindowAnchorX,$infoWindowAnchorY); return $_iconKey; }
php
function addIcon($iconImage,$iconShadowImage = '',$iconAnchorX = 'x',$iconAnchorY = 'x',$infoWindowAnchorX = 'x',$infoWindowAnchorY = 'x') { $_iconKey = $this->getIconKey($iconImage, $iconShadowImage); $this->_marker_icons[$_iconKey] = $this->createMarkerIcon($iconImage,$iconShadowImage,$iconAnchorX,$iconAnchorY,$infoWindowAnchorX,$infoWindowAnchorY); return $_iconKey; }
[ "function", "addIcon", "(", "$", "iconImage", ",", "$", "iconShadowImage", "=", "''", ",", "$", "iconAnchorX", "=", "'x'", ",", "$", "iconAnchorY", "=", "'x'", ",", "$", "infoWindowAnchorX", "=", "'x'", ",", "$", "infoWindowAnchorY", "=", "'x'", ")", "{", "$", "_iconKey", "=", "$", "this", "->", "getIconKey", "(", "$", "iconImage", ",", "$", "iconShadowImage", ")", ";", "$", "this", "->", "_marker_icons", "[", "$", "_iconKey", "]", "=", "$", "this", "->", "createMarkerIcon", "(", "$", "iconImage", ",", "$", "iconShadowImage", ",", "$", "iconAnchorX", ",", "$", "iconAnchorY", ",", "$", "infoWindowAnchorX", ",", "$", "infoWindowAnchorY", ")", ";", "return", "$", "_iconKey", ";", "}" ]
add an icon to "iconset" @param string $iconImage URL to marker icon image @param string $iconShadow URL to marker icon shadow image @param string $iconAnchorX X coordinate for icon anchor point @param string $iconAnchorY Y coordinate for icon anchor point @param string $infoWindowAnchorX X coordinate for info window anchor point @param string $infoWindowAnchorY Y coordinate for info window anchor point @return string Returns the icon's key.
[ "add", "an", "icon", "to", "iconset" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L1674-L1678
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.updateMarkerIconKey
function updateMarkerIconKey($markerKey, $iconKey){ if(isset($this->_markers[$markerKey])){ $this->_markers[$markerKey]['icon_key'] = $iconKey; } }
php
function updateMarkerIconKey($markerKey, $iconKey){ if(isset($this->_markers[$markerKey])){ $this->_markers[$markerKey]['icon_key'] = $iconKey; } }
[ "function", "updateMarkerIconKey", "(", "$", "markerKey", ",", "$", "iconKey", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_markers", "[", "$", "markerKey", "]", ")", ")", "{", "$", "this", "->", "_markers", "[", "$", "markerKey", "]", "[", "'icon_key'", "]", "=", "$", "iconKey", ";", "}", "}" ]
updates a marker's icon key. NOTE: To be used in lieu of addMarkerIcon, now use addIcon + updateMarkerIconKey for explicit icon association @param string $markerKey Marker key to define which marker's icon to update @param string $iconKey Icon key to define which icon to use.
[ "updates", "a", "marker", "s", "icon", "key", ".", "NOTE", ":", "To", "be", "used", "in", "lieu", "of", "addMarkerIcon", "now", "use", "addIcon", "+", "updateMarkerIconKey", "for", "explicit", "icon", "association" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L1686-L1690
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.getHeaderJS
function getHeaderJS() { $_headerJS = ""; if( $this->mobile == true){ $_headerJS .= " <meta name='viewport' content='".$this->meta_viewport."' /> "; } if(!empty($this->_elevation_polylines)||(!empty($this->_directions)&&$this->elevation_directions)){ $_headerJS .= "<script type='text/javascript' src='//www.google.com/jsapi'></script>"; $_headerJS .= " <script type='text/javascript'> // Load the Visualization API and the piechart package. google.load('visualization', '1', {packages: ['columnchart']}); </script>"; } $scriptUrl = "//maps.google.com/maps/api/js?sensor=".(($this->mobile==true)?"true":"false"); if( is_array( $this->api_options ) ) { foreach( $this->api_options as $key => $value ){ $scriptUrl .= '&'.$key.'='.$value; } } $_headerJS .= "<script type='text/javascript' src='".$scriptUrl."'></script>"; if($this->marker_clusterer){ $_headerJS .= "<script type='text/javascript' src='".$this->marker_clusterer_location."' ></script>"; } if($this->local_search){/*TODO: Load Local Search API V3 when available*/} return $_headerJS; }
php
function getHeaderJS() { $_headerJS = ""; if( $this->mobile == true){ $_headerJS .= " <meta name='viewport' content='".$this->meta_viewport."' /> "; } if(!empty($this->_elevation_polylines)||(!empty($this->_directions)&&$this->elevation_directions)){ $_headerJS .= "<script type='text/javascript' src='//www.google.com/jsapi'></script>"; $_headerJS .= " <script type='text/javascript'> // Load the Visualization API and the piechart package. google.load('visualization', '1', {packages: ['columnchart']}); </script>"; } $scriptUrl = "//maps.google.com/maps/api/js?sensor=".(($this->mobile==true)?"true":"false"); if( is_array( $this->api_options ) ) { foreach( $this->api_options as $key => $value ){ $scriptUrl .= '&'.$key.'='.$value; } } $_headerJS .= "<script type='text/javascript' src='".$scriptUrl."'></script>"; if($this->marker_clusterer){ $_headerJS .= "<script type='text/javascript' src='".$this->marker_clusterer_location."' ></script>"; } if($this->local_search){/*TODO: Load Local Search API V3 when available*/} return $_headerJS; }
[ "function", "getHeaderJS", "(", ")", "{", "$", "_headerJS", "=", "\"\"", ";", "if", "(", "$", "this", "->", "mobile", "==", "true", ")", "{", "$", "_headerJS", ".=", "\"\n \t <meta name='viewport' content='\"", ".", "$", "this", "->", "meta_viewport", ".", "\"' />\n \t\"", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "_elevation_polylines", ")", "||", "(", "!", "empty", "(", "$", "this", "->", "_directions", ")", "&&", "$", "this", "->", "elevation_directions", ")", ")", "{", "$", "_headerJS", ".=", "\"<script type='text/javascript' src='//www.google.com/jsapi'></script>\"", ";", "$", "_headerJS", ".=", "\"\n\t\t\t<script type='text/javascript'>\n\t\t\t\t// Load the Visualization API and the piechart package.\n\t\t\t\tgoogle.load('visualization', '1', {packages: ['columnchart']});\n\t\t\t</script>\"", ";", "}", "$", "scriptUrl", "=", "\"//maps.google.com/maps/api/js?sensor=\"", ".", "(", "(", "$", "this", "->", "mobile", "==", "true", ")", "?", "\"true\"", ":", "\"false\"", ")", ";", "if", "(", "is_array", "(", "$", "this", "->", "api_options", ")", ")", "{", "foreach", "(", "$", "this", "->", "api_options", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "scriptUrl", ".=", "'&'", ".", "$", "key", ".", "'='", ".", "$", "value", ";", "}", "}", "$", "_headerJS", ".=", "\"<script type='text/javascript' src='\"", ".", "$", "scriptUrl", ".", "\"'></script>\"", ";", "if", "(", "$", "this", "->", "marker_clusterer", ")", "{", "$", "_headerJS", ".=", "\"<script type='text/javascript' src='\"", ".", "$", "this", "->", "marker_clusterer_location", ".", "\"' ></script>\"", ";", "}", "if", "(", "$", "this", "->", "local_search", ")", "{", "/*TODO: Load Local Search API V3 when available*/", "}", "return", "$", "_headerJS", ";", "}" ]
return map header javascript (goes between <head></head>)
[ "return", "map", "header", "javascript", "(", "goes", "between", "<head", ">", "<", "/", "head", ">", ")" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L1704-L1731
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.getMapJS
function getMapJS() { $_script = ""; $_key = $this->map_id; $_output = '<script type="text/javascript" charset="utf-8">' . "\n"; $_output .= '//<![CDATA[' . "\n"; $_output .= "/*************************************************\n"; $_output .= " * Created with GoogleMapAPI" . $this->_version . "\n"; $_output .= " * Author: Brad Wedell <brad AT mycnl DOT com>\n"; $_output .= " * Link http://code.google.com/p/php-google-map-api/\n"; $_output .= " * Copyright 2010-2012 Brad Wedell\n"; $_output .= " * Original Author: Monte Ohrt <monte AT ohrt DOT com>\n"; $_output .= " * Original Copyright 2005-2006 New Digital Group\n"; $_output .= " * Originial Link http://www.phpinsider.com/php/code/GoogleMapAPI/\n"; $_output .= " *************************************************/\n"; // create global info window ( so we can auto close it ) $_script .= "var infowindow = new google.maps.InfoWindow();"; if($this->street_view_dom_id!=""){ $_script .= " var panorama".$this->street_view_dom_id."$_key = ''; "; if(!empty($this->_markers)){ $_script .= " var panorama".$this->street_view_dom_id."markers$_key = []; "; } } if(!empty($this->_markers)){ $_script .= " var markers$_key = []; "; if($this->sidebar) { $_script .= " var sidebar_html$_key = ''; var marker_html$_key = []; "; } } if($this->marker_clusterer){ $_script .= " var markerClusterer$_key = null; "; } if($this->directions) { $_script .= " var to_htmls$_key = []; var from_htmls$_key = []; "; } if(!empty($this->_directions)){ $_script .= " var directions$_key = []; "; } //Polylines if(!empty($this->_polylines)){ $_script .= " var polylines$_key = []; var polylineCoords$_key = []; "; if(!empty($this->_elevation_polylines)){ $_script .= " var elevationPolylines$_key = []; "; } } //Polygons if(!empty($this->_polygons)){ $_script .= " var polygon$_key = []; var polygonCoords$_key = []; "; } //Elevation stuff if(!empty($this->_elevation_polylines)||(!empty($this->_directions)&&$this->elevation_directions)){ $_script .= " var elevationCharts$_key = []; "; } //Overlays if(!empty($this->_overlays)){ $_script .= " var overlays$_key = []; "; } //KML Overlays if(!empty($this->_kml_overlays)){ $_script .= " var kml_overlays$_key = []; "; } //New Icons if(!empty($this->_marker_icons)){ $_script .= "var icon$_key = []; \n"; foreach($this->_marker_icons as $icon_key=>$icon_info){ //no need to check icon key here since that's already done with setters $_script .= " icon".$_key."['$icon_key'] = {}; icon".$_key."['$icon_key'].image = new google.maps.MarkerImage('".$icon_info["image"]."', // The size new google.maps.Size(".$icon_info['iconWidth'].", ".$icon_info['iconHeight']."), // The origin(sprite) new google.maps.Point(0,0), // The anchor new google.maps.Point(".$icon_info['iconAnchorX'].", ".$icon_info['iconAnchorY'].") ); "; if(isset($icon_info['shadow']) && $icon_info['shadow']!=""){ $_script .= " icon".$_key."['$icon_key'].shadow = new google.maps.MarkerImage('".$icon_info["shadow"]."', // The size new google.maps.Size(".$icon_info['shadowWidth'].", ".$icon_info['shadowHeight']."), // The origin(sprite) new google.maps.Point(0,0), // The anchor new google.maps.Point(".$icon_info['iconAnchorX'].", ".$icon_info['iconAnchorY'].") ); "; } } } $_script .= "var map$_key = null;\n"; //start setting script var if($this->onload) { $_script .= 'function onLoad'.$this->map_id.'() {' . "\n"; } if(!empty($this->browser_alert)) { //TODO:Update with new browser catch - GBrowserIsCompatible is deprecated //$_output .= 'if (GBrowserIsCompatible()) {' . "\n"; } /* *TODO:Update with local search bar once implemented in V3 api $strMapOptions = ""; if($this->local_search){ $_output .= " mapOptions.googleBarOptions= { style : 'new' ".(($this->local_search_ads)?", adsOptions: { client: '".$this->ads_pub_id."', channel: '".$this->ads_channel."', language: 'en' ":"")." }; "; $strMapOptions .= ", mapOptions"; } */ if($this->display_map){ $_script .= sprintf('var mapObj%s = document.getElementById("%s");', $_key, $this->map_id) . "\n"; $_script .= "if (mapObj$_key != 'undefined' && mapObj$_key != null) {\n"; $_script .= " var mapOptions$_key = { scrollwheel: ". ($this->scrollwheel?"true":"false") . ", zoom: ".$this->zoom.", draggable: ".$this->draggable.", maxZoom: ".$this->max_zoom.", minZoom: ".$this->min_zoom.", mapTypeId: google.maps.MapTypeId.".$this->map_type.", mapTypeControl: ".($this->type_controls?"true":"false").", mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.".$this->type_controls_style."} }; "; if(isset($this->center_lat) && isset($this->center_lon)) { // Special care for decimal point in lon and lat, would get lost if "wrong" locale is set; applies to (s)printf only $_script .= " mapOptions".$_key.".center = new google.maps.LatLng( ".number_format($this->center_lat, 6, ".", "").", ".number_format($this->center_lon, 6, ".", "")." ); "; } if($this->street_view_controls){ $_script .= " mapOptions".$_key.".streetViewControl= true; "; } // Add any map styles if they are present if( isset($this->map_styles) ) { $_script .= " var styles$_key = ".$this->map_styles."; "; } $_script .= " map$_key = new google.maps.Map(mapObj$_key,mapOptions$_key); "; $_script .= " map$_key.setOptions({styles: styles$_key}); "; if($this->street_view_dom_id!=""){ $_script .= " panorama".$this->street_view_dom_id."$_key = new google.maps.StreetViewPanorama(document.getElementById('".$this->street_view_dom_id."')); map$_key.setStreetView(panorama".$this->street_view_dom_id."$_key); "; if(!empty($this->_markers)){ //Add markers to the street view if($this->street_view_dom_id!=""){ $_script .= $this->getAddMarkersJS($this->map_id, $pano=true); } //set center to last marker $last_id = count($this->_markers)-1; $_script .= " panorama".$this->street_view_dom_id."$_key.setPosition(new google.maps.LatLng( ".$this->_markers[$last_id]["lat"].", ".$this->_markers[$last_id]["lon"]." )); panorama".$this->street_view_dom_id."$_key.setVisible(true); "; } } if(!empty($this->_directions)){ $_script .= $this->getAddDirectionsJS(); } //TODO:add support for Google Earth Overlay once integrated with V3 //$_output .= "map.addMapType(G_SATELLITE_3D_MAP);\n"; // zoom so that all markers are in the viewport if($this->zoom_encompass && (count($this->_markers) > 1 || count($this->_polylines) >= 1 || count($this->_overlays) >= 1)) { // increase bounds by fudge factor to keep // markers away from the edges $_len_lon = $this->_max_lon - $this->_min_lon; $_len_lat = $this->_max_lat - $this->_min_lat; $this->_min_lon -= $_len_lon * $this->bounds_fudge; $this->_max_lon += $_len_lon * $this->bounds_fudge; $this->_min_lat -= $_len_lat * $this->bounds_fudge; $this->_max_lat += $_len_lat * $this->bounds_fudge; $_script .= "var bds$_key = new google.maps.LatLngBounds(new google.maps.LatLng($this->_min_lat, $this->_min_lon), new google.maps.LatLng($this->_max_lat, $this->_max_lon));\n"; $_script .= 'map'.$_key.'.fitBounds(bds'.$_key.');' . "\n"; } /* * TODO: Update controls to use new API v3 methods.(Not a priority, see below) * default V3 functionality caters control display according to the * device that's accessing the page, as well as the specified width * and height of the map itself. if($this->map_controls) { if($this->control_size == 'large') $_output .= 'map.addControl(new GLargeMapControl(), new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10,10)));' . "\n"; else $_output .= 'map.addControl(new GSmallMapControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,60)));' . "\n"; } if($this->type_controls) { $_output .= 'map.addControl(new GMapTypeControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10)));' . "\n"; } if($this->scale_control) { if($this->control_size == 'large'){ $_output .= 'map.addControl(new GScaleControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(35,190)));' . "\n"; }else { $_output .= 'map.addControl(new GScaleControl(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(190,10)));' . "\n"; } } if($this->overview_control) { $_output .= 'map.addControl(new GOverviewMapControl());' . "\n"; } * TODO: Update with ads_manager stuff once integrated into V3 if($this->ads_manager){ $_output .= 'var adsManager = new GAdsManager(map, "'.$this->ads_pub_id.'",{channel:"'.$this->ads_channel.'",maxAdsOnMap:"'.$this->ads_max.'"}); adsManager.enable();'."\n"; } * TODO: Update with local search once integrated into V3 if($this->local_search){ $_output .= "\n map.enableGoogleBar(); "; } */ if($this->traffic_overlay){ $_script .= " var trafficLayer = new google.maps.TrafficLayer(); trafficLayer.setMap(map$_key); "; } if($this->biking_overlay){ $_script .= " var bikingLayer = new google.maps.BicyclingLayer(); bikingLayer.setMap(map$_key); "; } $_script .= $this->getAddMarkersJS(); $_script .= $this->getPolylineJS(); $_script .= $this->getPolygonJS(); $_script .= $this->getAddOverlayJS(); if($this->_kml_overlays!==""){ foreach($this->_kml_overlays as $_kml_key=>$_kml_file){ $_script .= " kml_overlays$_key[$_kml_key]= new google.maps.KmlLayer('$_kml_file'); kml_overlays$_key[$_kml_key].setMap(map$_key); "; } $_script .= " "; } //end JS if mapObj != "undefined" block $_script .= '}' . "\n"; }//end if $this->display_map==true if(!empty($this->browser_alert)) { //TODO:Update with new browser catch SEE ABOVE // $_output .= '} else {' . "\n"; // $_output .= 'alert("' . str_replace('"','\"',$this->browser_alert) . '");' . "\n"; // $_output .= '}' . "\n"; } if($this->onload) { $_script .= '}' . "\n"; } $_script .= $this->getMapFunctions(); if($this->_minify_js && class_exists("JSMin")){ $_script = JSMin::minify($_script); } //Append script to output $_output .= $_script; $_output .= '//]]>' . "\n"; $_output .= '</script>' . "\n"; return $_output; }
php
function getMapJS() { $_script = ""; $_key = $this->map_id; $_output = '<script type="text/javascript" charset="utf-8">' . "\n"; $_output .= '//<![CDATA[' . "\n"; $_output .= "/*************************************************\n"; $_output .= " * Created with GoogleMapAPI" . $this->_version . "\n"; $_output .= " * Author: Brad Wedell <brad AT mycnl DOT com>\n"; $_output .= " * Link http://code.google.com/p/php-google-map-api/\n"; $_output .= " * Copyright 2010-2012 Brad Wedell\n"; $_output .= " * Original Author: Monte Ohrt <monte AT ohrt DOT com>\n"; $_output .= " * Original Copyright 2005-2006 New Digital Group\n"; $_output .= " * Originial Link http://www.phpinsider.com/php/code/GoogleMapAPI/\n"; $_output .= " *************************************************/\n"; // create global info window ( so we can auto close it ) $_script .= "var infowindow = new google.maps.InfoWindow();"; if($this->street_view_dom_id!=""){ $_script .= " var panorama".$this->street_view_dom_id."$_key = ''; "; if(!empty($this->_markers)){ $_script .= " var panorama".$this->street_view_dom_id."markers$_key = []; "; } } if(!empty($this->_markers)){ $_script .= " var markers$_key = []; "; if($this->sidebar) { $_script .= " var sidebar_html$_key = ''; var marker_html$_key = []; "; } } if($this->marker_clusterer){ $_script .= " var markerClusterer$_key = null; "; } if($this->directions) { $_script .= " var to_htmls$_key = []; var from_htmls$_key = []; "; } if(!empty($this->_directions)){ $_script .= " var directions$_key = []; "; } //Polylines if(!empty($this->_polylines)){ $_script .= " var polylines$_key = []; var polylineCoords$_key = []; "; if(!empty($this->_elevation_polylines)){ $_script .= " var elevationPolylines$_key = []; "; } } //Polygons if(!empty($this->_polygons)){ $_script .= " var polygon$_key = []; var polygonCoords$_key = []; "; } //Elevation stuff if(!empty($this->_elevation_polylines)||(!empty($this->_directions)&&$this->elevation_directions)){ $_script .= " var elevationCharts$_key = []; "; } //Overlays if(!empty($this->_overlays)){ $_script .= " var overlays$_key = []; "; } //KML Overlays if(!empty($this->_kml_overlays)){ $_script .= " var kml_overlays$_key = []; "; } //New Icons if(!empty($this->_marker_icons)){ $_script .= "var icon$_key = []; \n"; foreach($this->_marker_icons as $icon_key=>$icon_info){ //no need to check icon key here since that's already done with setters $_script .= " icon".$_key."['$icon_key'] = {}; icon".$_key."['$icon_key'].image = new google.maps.MarkerImage('".$icon_info["image"]."', // The size new google.maps.Size(".$icon_info['iconWidth'].", ".$icon_info['iconHeight']."), // The origin(sprite) new google.maps.Point(0,0), // The anchor new google.maps.Point(".$icon_info['iconAnchorX'].", ".$icon_info['iconAnchorY'].") ); "; if(isset($icon_info['shadow']) && $icon_info['shadow']!=""){ $_script .= " icon".$_key."['$icon_key'].shadow = new google.maps.MarkerImage('".$icon_info["shadow"]."', // The size new google.maps.Size(".$icon_info['shadowWidth'].", ".$icon_info['shadowHeight']."), // The origin(sprite) new google.maps.Point(0,0), // The anchor new google.maps.Point(".$icon_info['iconAnchorX'].", ".$icon_info['iconAnchorY'].") ); "; } } } $_script .= "var map$_key = null;\n"; //start setting script var if($this->onload) { $_script .= 'function onLoad'.$this->map_id.'() {' . "\n"; } if(!empty($this->browser_alert)) { //TODO:Update with new browser catch - GBrowserIsCompatible is deprecated //$_output .= 'if (GBrowserIsCompatible()) {' . "\n"; } /* *TODO:Update with local search bar once implemented in V3 api $strMapOptions = ""; if($this->local_search){ $_output .= " mapOptions.googleBarOptions= { style : 'new' ".(($this->local_search_ads)?", adsOptions: { client: '".$this->ads_pub_id."', channel: '".$this->ads_channel."', language: 'en' ":"")." }; "; $strMapOptions .= ", mapOptions"; } */ if($this->display_map){ $_script .= sprintf('var mapObj%s = document.getElementById("%s");', $_key, $this->map_id) . "\n"; $_script .= "if (mapObj$_key != 'undefined' && mapObj$_key != null) {\n"; $_script .= " var mapOptions$_key = { scrollwheel: ". ($this->scrollwheel?"true":"false") . ", zoom: ".$this->zoom.", draggable: ".$this->draggable.", maxZoom: ".$this->max_zoom.", minZoom: ".$this->min_zoom.", mapTypeId: google.maps.MapTypeId.".$this->map_type.", mapTypeControl: ".($this->type_controls?"true":"false").", mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.".$this->type_controls_style."} }; "; if(isset($this->center_lat) && isset($this->center_lon)) { // Special care for decimal point in lon and lat, would get lost if "wrong" locale is set; applies to (s)printf only $_script .= " mapOptions".$_key.".center = new google.maps.LatLng( ".number_format($this->center_lat, 6, ".", "").", ".number_format($this->center_lon, 6, ".", "")." ); "; } if($this->street_view_controls){ $_script .= " mapOptions".$_key.".streetViewControl= true; "; } // Add any map styles if they are present if( isset($this->map_styles) ) { $_script .= " var styles$_key = ".$this->map_styles."; "; } $_script .= " map$_key = new google.maps.Map(mapObj$_key,mapOptions$_key); "; $_script .= " map$_key.setOptions({styles: styles$_key}); "; if($this->street_view_dom_id!=""){ $_script .= " panorama".$this->street_view_dom_id."$_key = new google.maps.StreetViewPanorama(document.getElementById('".$this->street_view_dom_id."')); map$_key.setStreetView(panorama".$this->street_view_dom_id."$_key); "; if(!empty($this->_markers)){ //Add markers to the street view if($this->street_view_dom_id!=""){ $_script .= $this->getAddMarkersJS($this->map_id, $pano=true); } //set center to last marker $last_id = count($this->_markers)-1; $_script .= " panorama".$this->street_view_dom_id."$_key.setPosition(new google.maps.LatLng( ".$this->_markers[$last_id]["lat"].", ".$this->_markers[$last_id]["lon"]." )); panorama".$this->street_view_dom_id."$_key.setVisible(true); "; } } if(!empty($this->_directions)){ $_script .= $this->getAddDirectionsJS(); } //TODO:add support for Google Earth Overlay once integrated with V3 //$_output .= "map.addMapType(G_SATELLITE_3D_MAP);\n"; // zoom so that all markers are in the viewport if($this->zoom_encompass && (count($this->_markers) > 1 || count($this->_polylines) >= 1 || count($this->_overlays) >= 1)) { // increase bounds by fudge factor to keep // markers away from the edges $_len_lon = $this->_max_lon - $this->_min_lon; $_len_lat = $this->_max_lat - $this->_min_lat; $this->_min_lon -= $_len_lon * $this->bounds_fudge; $this->_max_lon += $_len_lon * $this->bounds_fudge; $this->_min_lat -= $_len_lat * $this->bounds_fudge; $this->_max_lat += $_len_lat * $this->bounds_fudge; $_script .= "var bds$_key = new google.maps.LatLngBounds(new google.maps.LatLng($this->_min_lat, $this->_min_lon), new google.maps.LatLng($this->_max_lat, $this->_max_lon));\n"; $_script .= 'map'.$_key.'.fitBounds(bds'.$_key.');' . "\n"; } /* * TODO: Update controls to use new API v3 methods.(Not a priority, see below) * default V3 functionality caters control display according to the * device that's accessing the page, as well as the specified width * and height of the map itself. if($this->map_controls) { if($this->control_size == 'large') $_output .= 'map.addControl(new GLargeMapControl(), new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10,10)));' . "\n"; else $_output .= 'map.addControl(new GSmallMapControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,60)));' . "\n"; } if($this->type_controls) { $_output .= 'map.addControl(new GMapTypeControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10)));' . "\n"; } if($this->scale_control) { if($this->control_size == 'large'){ $_output .= 'map.addControl(new GScaleControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(35,190)));' . "\n"; }else { $_output .= 'map.addControl(new GScaleControl(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(190,10)));' . "\n"; } } if($this->overview_control) { $_output .= 'map.addControl(new GOverviewMapControl());' . "\n"; } * TODO: Update with ads_manager stuff once integrated into V3 if($this->ads_manager){ $_output .= 'var adsManager = new GAdsManager(map, "'.$this->ads_pub_id.'",{channel:"'.$this->ads_channel.'",maxAdsOnMap:"'.$this->ads_max.'"}); adsManager.enable();'."\n"; } * TODO: Update with local search once integrated into V3 if($this->local_search){ $_output .= "\n map.enableGoogleBar(); "; } */ if($this->traffic_overlay){ $_script .= " var trafficLayer = new google.maps.TrafficLayer(); trafficLayer.setMap(map$_key); "; } if($this->biking_overlay){ $_script .= " var bikingLayer = new google.maps.BicyclingLayer(); bikingLayer.setMap(map$_key); "; } $_script .= $this->getAddMarkersJS(); $_script .= $this->getPolylineJS(); $_script .= $this->getPolygonJS(); $_script .= $this->getAddOverlayJS(); if($this->_kml_overlays!==""){ foreach($this->_kml_overlays as $_kml_key=>$_kml_file){ $_script .= " kml_overlays$_key[$_kml_key]= new google.maps.KmlLayer('$_kml_file'); kml_overlays$_key[$_kml_key].setMap(map$_key); "; } $_script .= " "; } //end JS if mapObj != "undefined" block $_script .= '}' . "\n"; }//end if $this->display_map==true if(!empty($this->browser_alert)) { //TODO:Update with new browser catch SEE ABOVE // $_output .= '} else {' . "\n"; // $_output .= 'alert("' . str_replace('"','\"',$this->browser_alert) . '");' . "\n"; // $_output .= '}' . "\n"; } if($this->onload) { $_script .= '}' . "\n"; } $_script .= $this->getMapFunctions(); if($this->_minify_js && class_exists("JSMin")){ $_script = JSMin::minify($_script); } //Append script to output $_output .= $_script; $_output .= '//]]>' . "\n"; $_output .= '</script>' . "\n"; return $_output; }
[ "function", "getMapJS", "(", ")", "{", "$", "_script", "=", "\"\"", ";", "$", "_key", "=", "$", "this", "->", "map_id", ";", "$", "_output", "=", "'<script type=\"text/javascript\" charset=\"utf-8\">'", ".", "\"\\n\"", ";", "$", "_output", ".=", "'//<![CDATA['", ".", "\"\\n\"", ";", "$", "_output", ".=", "\"/*************************************************\\n\"", ";", "$", "_output", ".=", "\" * Created with GoogleMapAPI\"", ".", "$", "this", "->", "_version", ".", "\"\\n\"", ";", "$", "_output", ".=", "\" * Author: Brad Wedell <brad AT mycnl DOT com>\\n\"", ";", "$", "_output", ".=", "\" * Link http://code.google.com/p/php-google-map-api/\\n\"", ";", "$", "_output", ".=", "\" * Copyright 2010-2012 Brad Wedell\\n\"", ";", "$", "_output", ".=", "\" * Original Author: Monte Ohrt <monte AT ohrt DOT com>\\n\"", ";", "$", "_output", ".=", "\" * Original Copyright 2005-2006 New Digital Group\\n\"", ";", "$", "_output", ".=", "\" * Originial Link http://www.phpinsider.com/php/code/GoogleMapAPI/\\n\"", ";", "$", "_output", ".=", "\" *************************************************/\\n\"", ";", "// create global info window ( so we can auto close it )", "$", "_script", ".=", "\"var infowindow = new google.maps.InfoWindow();\"", ";", "if", "(", "$", "this", "->", "street_view_dom_id", "!=", "\"\"", ")", "{", "$", "_script", ".=", "\"\n\t\t\t\tvar panorama\"", ".", "$", "this", "->", "street_view_dom_id", ".", "\"$_key = '';\n\t\t\t\"", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "_markers", ")", ")", "{", "$", "_script", ".=", "\"\n\t\t\t\t\tvar panorama\"", ".", "$", "this", "->", "street_view_dom_id", ".", "\"markers$_key = [];\n\t\t\t\t\"", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "_markers", ")", ")", "{", "$", "_script", ".=", "\"\n\t\t\t\tvar markers$_key = [];\n\t\t\t\"", ";", "if", "(", "$", "this", "->", "sidebar", ")", "{", "$", "_script", ".=", "\"\n\t\t\t\t\tvar sidebar_html$_key = '';\n\t\t\t\t\tvar marker_html$_key = [];\n\t\t\t\t\"", ";", "}", "}", "if", "(", "$", "this", "->", "marker_clusterer", ")", "{", "$", "_script", ".=", "\"\n\t\t\t var markerClusterer$_key = null;\n\t\t\t\"", ";", "}", "if", "(", "$", "this", "->", "directions", ")", "{", "$", "_script", ".=", "\"\n var to_htmls$_key = [];\n var from_htmls$_key = [];\n \"", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "_directions", ")", ")", "{", "$", "_script", ".=", "\"\n\t\t\t var directions$_key = [];\n\t\t\t\"", ";", "}", "//Polylines", "if", "(", "!", "empty", "(", "$", "this", "->", "_polylines", ")", ")", "{", "$", "_script", ".=", "\"\n\t\t\t\tvar polylines$_key = [];\n\t\t\t\tvar polylineCoords$_key = [];\n\t\t\t\"", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "_elevation_polylines", ")", ")", "{", "$", "_script", ".=", "\"\n\t\t\t\t\tvar elevationPolylines$_key = [];\n\t\t\t\t\"", ";", "}", "}", "//Polygons", "if", "(", "!", "empty", "(", "$", "this", "->", "_polygons", ")", ")", "{", "$", "_script", ".=", "\"\n\t\t\t\tvar polygon$_key = [];\n\t\t\t\tvar polygonCoords$_key = [];\n\t\t\t\"", ";", "}", "//Elevation stuff", "if", "(", "!", "empty", "(", "$", "this", "->", "_elevation_polylines", ")", "||", "(", "!", "empty", "(", "$", "this", "->", "_directions", ")", "&&", "$", "this", "->", "elevation_directions", ")", ")", "{", "$", "_script", ".=", "\"\n\t\t\t\tvar elevationCharts$_key = [];\t\t\t\t\n\t\t\t\"", ";", "}", "//Overlays", "if", "(", "!", "empty", "(", "$", "this", "->", "_overlays", ")", ")", "{", "$", "_script", ".=", "\"\n\t\t\t\tvar overlays$_key = [];\n\t\t\t\"", ";", "}", "//KML Overlays", "if", "(", "!", "empty", "(", "$", "this", "->", "_kml_overlays", ")", ")", "{", "$", "_script", ".=", "\"\n var kml_overlays$_key = [];\n \"", ";", "}", "//New Icons", "if", "(", "!", "empty", "(", "$", "this", "->", "_marker_icons", ")", ")", "{", "$", "_script", ".=", "\"var icon$_key = []; \\n\"", ";", "foreach", "(", "$", "this", "->", "_marker_icons", "as", "$", "icon_key", "=>", "$", "icon_info", ")", "{", "//no need to check icon key here since that's already done with setters", "$", "_script", ".=", "\"\n \t\t icon\"", ".", "$", "_key", ".", "\"['$icon_key'] = {};\n \t\t icon\"", ".", "$", "_key", ".", "\"['$icon_key'].image = new google.maps.MarkerImage('\"", ".", "$", "icon_info", "[", "\"image\"", "]", ".", "\"',\n\t\t\t\t // The size\n\t\t\t\t new google.maps.Size(\"", ".", "$", "icon_info", "[", "'iconWidth'", "]", ".", "\", \"", ".", "$", "icon_info", "[", "'iconHeight'", "]", ".", "\"),\n\t\t\t\t // The origin(sprite)\n\t\t\t\t new google.maps.Point(0,0),\n\t\t\t\t // The anchor\n\t\t\t\t new google.maps.Point(\"", ".", "$", "icon_info", "[", "'iconAnchorX'", "]", ".", "\", \"", ".", "$", "icon_info", "[", "'iconAnchorY'", "]", ".", "\")\n );\n \t\t\"", ";", "if", "(", "isset", "(", "$", "icon_info", "[", "'shadow'", "]", ")", "&&", "$", "icon_info", "[", "'shadow'", "]", "!=", "\"\"", ")", "{", "$", "_script", ".=", "\"\n icon\"", ".", "$", "_key", ".", "\"['$icon_key'].shadow = new google.maps.MarkerImage('\"", ".", "$", "icon_info", "[", "\"shadow\"", "]", ".", "\"',\n // The size\n new google.maps.Size(\"", ".", "$", "icon_info", "[", "'shadowWidth'", "]", ".", "\", \"", ".", "$", "icon_info", "[", "'shadowHeight'", "]", ".", "\"),\n // The origin(sprite)\n new google.maps.Point(0,0),\n // The anchor\n new google.maps.Point(\"", ".", "$", "icon_info", "[", "'iconAnchorX'", "]", ".", "\", \"", ".", "$", "icon_info", "[", "'iconAnchorY'", "]", ".", "\")\n );\n \"", ";", "}", "}", "}", "$", "_script", ".=", "\"var map$_key = null;\\n\"", ";", "//start setting script var", "if", "(", "$", "this", "->", "onload", ")", "{", "$", "_script", ".=", "'function onLoad'", ".", "$", "this", "->", "map_id", ".", "'() {'", ".", "\"\\n\"", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "browser_alert", ")", ")", "{", "//TODO:Update with new browser catch - GBrowserIsCompatible is deprecated", "//$_output .= 'if (GBrowserIsCompatible()) {' . \"\\n\";", "}", "/*\n *TODO:Update with local search bar once implemented in V3 api \n\t\t$strMapOptions = \"\";\n\t\tif($this->local_search){\n\t\t\t$_output .= \"\n\t\t\t\tmapOptions.googleBarOptions= {\n\t\t\t\t\tstyle : 'new'\n\t\t\t\t\t\".(($this->local_search_ads)?\",\n\t\t\t\t\tadsOptions: {\n\t\t\t\t\t client: '\".$this->ads_pub_id.\"',\n\t\t\t\t\t channel: '\".$this->ads_channel.\"',\n\t\t\t\t\t language: 'en'\n\t\t\t\t\t\":\"\").\"\n\t\t\t\t};\n\t\t\t\"; \n\t\t\t$strMapOptions .= \", mapOptions\";\n\t\t}\n */", "if", "(", "$", "this", "->", "display_map", ")", "{", "$", "_script", ".=", "sprintf", "(", "'var mapObj%s = document.getElementById(\"%s\");'", ",", "$", "_key", ",", "$", "this", "->", "map_id", ")", ".", "\"\\n\"", ";", "$", "_script", ".=", "\"if (mapObj$_key != 'undefined' && mapObj$_key != null) {\\n\"", ";", "$", "_script", ".=", "\"\n\t\t\t\tvar mapOptions$_key = {\n\t\t\t\t\tscrollwheel: \"", ".", "(", "$", "this", "->", "scrollwheel", "?", "\"true\"", ":", "\"false\"", ")", ".", "\",\n\t\t\t\t\tzoom: \"", ".", "$", "this", "->", "zoom", ".", "\",\n\t\t\t\t\tdraggable: \"", ".", "$", "this", "->", "draggable", ".", "\",\n\t\t\t\t\tmaxZoom: \"", ".", "$", "this", "->", "max_zoom", ".", "\",\n\t\t\t\t\tminZoom: \"", ".", "$", "this", "->", "min_zoom", ".", "\",\n\t\t\t\t\tmapTypeId: google.maps.MapTypeId.\"", ".", "$", "this", "->", "map_type", ".", "\",\n\t\t\t\t\tmapTypeControl: \"", ".", "(", "$", "this", "->", "type_controls", "?", "\"true\"", ":", "\"false\"", ")", ".", "\",\n\t\t\t\t\tmapTypeControlOptions: {style: google.maps.MapTypeControlStyle.\"", ".", "$", "this", "->", "type_controls_style", ".", "\"}\n\t\t\t\t};\n\t\t\t\"", ";", "if", "(", "isset", "(", "$", "this", "->", "center_lat", ")", "&&", "isset", "(", "$", "this", "->", "center_lon", ")", ")", "{", "// Special care for decimal point in lon and lat, would get lost if \"wrong\" locale is set; applies to (s)printf only", "$", "_script", ".=", "\"\n\t\t\t\t\tmapOptions\"", ".", "$", "_key", ".", "\".center = new google.maps.LatLng(\n\t\t\t\t\t\t\"", ".", "number_format", "(", "$", "this", "->", "center_lat", ",", "6", ",", "\".\"", ",", "\"\"", ")", ".", "\",\n\t\t\t\t\t\t\"", ".", "number_format", "(", "$", "this", "->", "center_lon", ",", "6", ",", "\".\"", ",", "\"\"", ")", ".", "\"\n\t\t\t\t\t);\n\t\t\t\t\"", ";", "}", "if", "(", "$", "this", "->", "street_view_controls", ")", "{", "$", "_script", ".=", "\"\n\t\t\t\t\tmapOptions\"", ".", "$", "_key", ".", "\".streetViewControl= true;\n\t\n\t\t\t\t\"", ";", "}", "// Add any map styles if they are present", "if", "(", "isset", "(", "$", "this", "->", "map_styles", ")", ")", "{", "$", "_script", ".=", "\"\n\t\t\t\t\t\tvar styles$_key = \"", ".", "$", "this", "->", "map_styles", ".", "\";\t\t\n\t\t\t\t\"", ";", "}", "$", "_script", ".=", "\"\n\t\t\t\tmap$_key = new google.maps.Map(mapObj$_key,mapOptions$_key);\n\t\t\t\"", ";", "$", "_script", ".=", "\"\n\t\t\t\tmap$_key.setOptions({styles: styles$_key});\n\t\t\t\"", ";", "if", "(", "$", "this", "->", "street_view_dom_id", "!=", "\"\"", ")", "{", "$", "_script", ".=", "\"\n\t\t\t\t\tpanorama\"", ".", "$", "this", "->", "street_view_dom_id", ".", "\"$_key = new google.maps.StreetViewPanorama(document.getElementById('\"", ".", "$", "this", "->", "street_view_dom_id", ".", "\"'));\n\t\t\t\t\tmap$_key.setStreetView(panorama\"", ".", "$", "this", "->", "street_view_dom_id", ".", "\"$_key);\n\t\t\t\t\"", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "_markers", ")", ")", "{", "//Add markers to the street view", "if", "(", "$", "this", "->", "street_view_dom_id", "!=", "\"\"", ")", "{", "$", "_script", ".=", "$", "this", "->", "getAddMarkersJS", "(", "$", "this", "->", "map_id", ",", "$", "pano", "=", "true", ")", ";", "}", "//set center to last marker", "$", "last_id", "=", "count", "(", "$", "this", "->", "_markers", ")", "-", "1", ";", "$", "_script", ".=", "\"\n\t\t\t\t\t\tpanorama\"", ".", "$", "this", "->", "street_view_dom_id", ".", "\"$_key.setPosition(new google.maps.LatLng(\n\t\t\t\t\t\t\t\"", ".", "$", "this", "->", "_markers", "[", "$", "last_id", "]", "[", "\"lat\"", "]", ".", "\",\n\t\t\t\t\t\t\t\"", ".", "$", "this", "->", "_markers", "[", "$", "last_id", "]", "[", "\"lon\"", "]", ".", "\"\n\t\t\t\t\t\t));\n\t\t\t\t\t\tpanorama\"", ".", "$", "this", "->", "street_view_dom_id", ".", "\"$_key.setVisible(true);\n\t\t\t\t\t\"", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "_directions", ")", ")", "{", "$", "_script", ".=", "$", "this", "->", "getAddDirectionsJS", "(", ")", ";", "}", "//TODO:add support for Google Earth Overlay once integrated with V3", "//$_output .= \"map.addMapType(G_SATELLITE_3D_MAP);\\n\";", "// zoom so that all markers are in the viewport", "if", "(", "$", "this", "->", "zoom_encompass", "&&", "(", "count", "(", "$", "this", "->", "_markers", ")", ">", "1", "||", "count", "(", "$", "this", "->", "_polylines", ")", ">=", "1", "||", "count", "(", "$", "this", "->", "_overlays", ")", ">=", "1", ")", ")", "{", "// increase bounds by fudge factor to keep", "// markers away from the edges", "$", "_len_lon", "=", "$", "this", "->", "_max_lon", "-", "$", "this", "->", "_min_lon", ";", "$", "_len_lat", "=", "$", "this", "->", "_max_lat", "-", "$", "this", "->", "_min_lat", ";", "$", "this", "->", "_min_lon", "-=", "$", "_len_lon", "*", "$", "this", "->", "bounds_fudge", ";", "$", "this", "->", "_max_lon", "+=", "$", "_len_lon", "*", "$", "this", "->", "bounds_fudge", ";", "$", "this", "->", "_min_lat", "-=", "$", "_len_lat", "*", "$", "this", "->", "bounds_fudge", ";", "$", "this", "->", "_max_lat", "+=", "$", "_len_lat", "*", "$", "this", "->", "bounds_fudge", ";", "$", "_script", ".=", "\"var bds$_key = new google.maps.LatLngBounds(new google.maps.LatLng($this->_min_lat, $this->_min_lon), new google.maps.LatLng($this->_max_lat, $this->_max_lon));\\n\"", ";", "$", "_script", ".=", "'map'", ".", "$", "_key", ".", "'.fitBounds(bds'", ".", "$", "_key", ".", "');'", ".", "\"\\n\"", ";", "}", "/*\n\t\t\t * TODO: Update controls to use new API v3 methods.(Not a priority, see below)\n\t\t\t * default V3 functionality caters control display according to the \n\t\t\t * device that's accessing the page, as well as the specified width\n\t\t\t * and height of the map itself.\n\t\t\tif($this->map_controls) {\n\t\t\t if($this->control_size == 'large')\n\t\t\t\t $_output .= 'map.addControl(new GLargeMapControl(), new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10,10)));' . \"\\n\";\n\t\t\t else\n\t\t\t\t $_output .= 'map.addControl(new GSmallMapControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,60)));' . \"\\n\";\n\t\t\t}\n\t\t\tif($this->type_controls) {\n\t\t\t\t$_output .= 'map.addControl(new GMapTypeControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10)));' . \"\\n\";\n\t\t\t}\n\t\t\t\n\t\t\tif($this->scale_control) {\n\t\t\t\tif($this->control_size == 'large'){\n\t\t\t\t\t$_output .= 'map.addControl(new GScaleControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(35,190)));' . \"\\n\";\n\t\t\t\t}else {\n\t\t\t\t\t$_output .= 'map.addControl(new GScaleControl(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(190,10)));' . \"\\n\";\n\t\t\t\t}\n\t\t\t}\n\t\t\tif($this->overview_control) {\n\t\t\t\t$_output .= 'map.addControl(new GOverviewMapControl());' . \"\\n\";\n\t\t\t}\n\t\t\t\n\t\t\t * TODO: Update with ads_manager stuff once integrated into V3\n\t\t\tif($this->ads_manager){\n\t\t\t\t$_output .= 'var adsManager = new GAdsManager(map, \"'.$this->ads_pub_id.'\",{channel:\"'.$this->ads_channel.'\",maxAdsOnMap:\"'.$this->ads_max.'\"});\n\t\t adsManager.enable();'.\"\\n\";\n\t\t\t\n\t\t\t}\n\t\t\t * TODO: Update with local search once integrated into V3\n\t\t\tif($this->local_search){\n\t\t\t\t$_output .= \"\\n\n\t\t\t\t\tmap.enableGoogleBar();\n\t\t\t\t\";\n\t\t\t}\n\t\t\t*/", "if", "(", "$", "this", "->", "traffic_overlay", ")", "{", "$", "_script", ".=", "\"\n\t\t\t\t\tvar trafficLayer = new google.maps.TrafficLayer();\n\t\t\t\t\ttrafficLayer.setMap(map$_key);\n\t\t\t\t\"", ";", "}", "if", "(", "$", "this", "->", "biking_overlay", ")", "{", "$", "_script", ".=", "\"\n\t\t\t\t\tvar bikingLayer = new google.maps.BicyclingLayer();\n\t\t\t\t\tbikingLayer.setMap(map$_key);\n\t\t\t\t\"", ";", "}", "$", "_script", ".=", "$", "this", "->", "getAddMarkersJS", "(", ")", ";", "$", "_script", ".=", "$", "this", "->", "getPolylineJS", "(", ")", ";", "$", "_script", ".=", "$", "this", "->", "getPolygonJS", "(", ")", ";", "$", "_script", ".=", "$", "this", "->", "getAddOverlayJS", "(", ")", ";", "if", "(", "$", "this", "->", "_kml_overlays", "!==", "\"\"", ")", "{", "foreach", "(", "$", "this", "->", "_kml_overlays", "as", "$", "_kml_key", "=>", "$", "_kml_file", ")", "{", "$", "_script", ".=", "\"\n\t\t\t\t\t kml_overlays$_key[$_kml_key]= new google.maps.KmlLayer('$_kml_file');\n\t\t\t\t\t kml_overlays$_key[$_kml_key].setMap(map$_key);\n\t\t\t\t \"", ";", "}", "$", "_script", ".=", "\"\n\t\t\t\t \n\t\t\t \"", ";", "}", "//end JS if mapObj != \"undefined\" block", "$", "_script", ".=", "'}'", ".", "\"\\n\"", ";", "}", "//end if $this->display_map==true", "if", "(", "!", "empty", "(", "$", "this", "->", "browser_alert", ")", ")", "{", "//TODO:Update with new browser catch SEE ABOVE", "// $_output .= '} else {' . \"\\n\";", "// $_output .= 'alert(\"' . str_replace('\"','\\\"',$this->browser_alert) . '\");' . \"\\n\";", "// $_output .= '}' . \"\\n\";", "}", "if", "(", "$", "this", "->", "onload", ")", "{", "$", "_script", ".=", "'}'", ".", "\"\\n\"", ";", "}", "$", "_script", ".=", "$", "this", "->", "getMapFunctions", "(", ")", ";", "if", "(", "$", "this", "->", "_minify_js", "&&", "class_exists", "(", "\"JSMin\"", ")", ")", "{", "$", "_script", "=", "JSMin", "::", "minify", "(", "$", "_script", ")", ";", "}", "//Append script to output", "$", "_output", ".=", "$", "_script", ";", "$", "_output", ".=", "'//]]>'", ".", "\"\\n\"", ";", "$", "_output", ".=", "'</script>'", ".", "\"\\n\"", ";", "return", "$", "_output", ";", "}" ]
return map javascript
[ "return", "map", "javascript" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L1776-L2130
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.getAddMarkersJS
function getAddMarkersJS($map_id = "", $pano= false) { //defaults if($map_id == ""){ $map_id = $this->map_id; } if($pano==false){ $_prefix = "map"; }else{ $_prefix = "panorama".$this->street_view_dom_id; } $_output = ''; foreach($this->_markers as $_marker) { $iw_html = str_replace('"','\"',str_replace(array("\n", "\r"), "", $_marker['html'])); $_output .= "var point = new google.maps.LatLng(".$_marker['lat'].",".$_marker['lon'].");\n"; $_output .= sprintf('%s.push(createMarker(%s%s, point,"%s","%s", %s, %s, "%s", %s ));', (($pano==true)?$_prefix:"")."markers".$map_id, $_prefix, $map_id, str_replace('"','\"',$_marker['title']), str_replace('/','\/',$iw_html), (isset($_marker["icon_key"]))?"icon".$map_id."['".$_marker["icon_key"]."'].image":"''", (isset($_marker["icon_key"])&&isset($_marker["shadow_icon"]))?"icon".$map_id."['".$_marker["icon_key"]."'].shadow":"''", (($this->sidebar)?$this->sidebar_id:""), ((isset($_marker["openers"])&&count($_marker["openers"])>0)?json_encode($_marker["openers"]):"''") ) . "\n"; } if($this->marker_clusterer && $pano==false){//only do marker clusterer for map, not streetview $_output .= " markerClusterer".$map_id." = new MarkerClusterer(".$_prefix.$map_id.", markers".$map_id.", { maxZoom: ".$this->marker_clusterer_options["maxZoom"].", gridSize: ".$this->marker_clusterer_options["gridSize"].", styles: ".$this->marker_clusterer_options["styles"]." }); "; } return $_output; }
php
function getAddMarkersJS($map_id = "", $pano= false) { //defaults if($map_id == ""){ $map_id = $this->map_id; } if($pano==false){ $_prefix = "map"; }else{ $_prefix = "panorama".$this->street_view_dom_id; } $_output = ''; foreach($this->_markers as $_marker) { $iw_html = str_replace('"','\"',str_replace(array("\n", "\r"), "", $_marker['html'])); $_output .= "var point = new google.maps.LatLng(".$_marker['lat'].",".$_marker['lon'].");\n"; $_output .= sprintf('%s.push(createMarker(%s%s, point,"%s","%s", %s, %s, "%s", %s ));', (($pano==true)?$_prefix:"")."markers".$map_id, $_prefix, $map_id, str_replace('"','\"',$_marker['title']), str_replace('/','\/',$iw_html), (isset($_marker["icon_key"]))?"icon".$map_id."['".$_marker["icon_key"]."'].image":"''", (isset($_marker["icon_key"])&&isset($_marker["shadow_icon"]))?"icon".$map_id."['".$_marker["icon_key"]."'].shadow":"''", (($this->sidebar)?$this->sidebar_id:""), ((isset($_marker["openers"])&&count($_marker["openers"])>0)?json_encode($_marker["openers"]):"''") ) . "\n"; } if($this->marker_clusterer && $pano==false){//only do marker clusterer for map, not streetview $_output .= " markerClusterer".$map_id." = new MarkerClusterer(".$_prefix.$map_id.", markers".$map_id.", { maxZoom: ".$this->marker_clusterer_options["maxZoom"].", gridSize: ".$this->marker_clusterer_options["gridSize"].", styles: ".$this->marker_clusterer_options["styles"]." }); "; } return $_output; }
[ "function", "getAddMarkersJS", "(", "$", "map_id", "=", "\"\"", ",", "$", "pano", "=", "false", ")", "{", "//defaults", "if", "(", "$", "map_id", "==", "\"\"", ")", "{", "$", "map_id", "=", "$", "this", "->", "map_id", ";", "}", "if", "(", "$", "pano", "==", "false", ")", "{", "$", "_prefix", "=", "\"map\"", ";", "}", "else", "{", "$", "_prefix", "=", "\"panorama\"", ".", "$", "this", "->", "street_view_dom_id", ";", "}", "$", "_output", "=", "''", ";", "foreach", "(", "$", "this", "->", "_markers", "as", "$", "_marker", ")", "{", "$", "iw_html", "=", "str_replace", "(", "'\"'", ",", "'\\\"'", ",", "str_replace", "(", "array", "(", "\"\\n\"", ",", "\"\\r\"", ")", ",", "\"\"", ",", "$", "_marker", "[", "'html'", "]", ")", ")", ";", "$", "_output", ".=", "\"var point = new google.maps.LatLng(\"", ".", "$", "_marker", "[", "'lat'", "]", ".", "\",\"", ".", "$", "_marker", "[", "'lon'", "]", ".", "\");\\n\"", ";", "$", "_output", ".=", "sprintf", "(", "'%s.push(createMarker(%s%s, point,\"%s\",\"%s\", %s, %s, \"%s\", %s ));'", ",", "(", "(", "$", "pano", "==", "true", ")", "?", "$", "_prefix", ":", "\"\"", ")", ".", "\"markers\"", ".", "$", "map_id", ",", "$", "_prefix", ",", "$", "map_id", ",", "str_replace", "(", "'\"'", ",", "'\\\"'", ",", "$", "_marker", "[", "'title'", "]", ")", ",", "str_replace", "(", "'/'", ",", "'\\/'", ",", "$", "iw_html", ")", ",", "(", "isset", "(", "$", "_marker", "[", "\"icon_key\"", "]", ")", ")", "?", "\"icon\"", ".", "$", "map_id", ".", "\"['\"", ".", "$", "_marker", "[", "\"icon_key\"", "]", ".", "\"'].image\"", ":", "\"''\"", ",", "(", "isset", "(", "$", "_marker", "[", "\"icon_key\"", "]", ")", "&&", "isset", "(", "$", "_marker", "[", "\"shadow_icon\"", "]", ")", ")", "?", "\"icon\"", ".", "$", "map_id", ".", "\"['\"", ".", "$", "_marker", "[", "\"icon_key\"", "]", ".", "\"'].shadow\"", ":", "\"''\"", ",", "(", "(", "$", "this", "->", "sidebar", ")", "?", "$", "this", "->", "sidebar_id", ":", "\"\"", ")", ",", "(", "(", "isset", "(", "$", "_marker", "[", "\"openers\"", "]", ")", "&&", "count", "(", "$", "_marker", "[", "\"openers\"", "]", ")", ">", "0", ")", "?", "json_encode", "(", "$", "_marker", "[", "\"openers\"", "]", ")", ":", "\"''\"", ")", ")", ".", "\"\\n\"", ";", "}", "if", "(", "$", "this", "->", "marker_clusterer", "&&", "$", "pano", "==", "false", ")", "{", "//only do marker clusterer for map, not streetview", "$", "_output", ".=", "\"\n \t markerClusterer\"", ".", "$", "map_id", ".", "\" = new MarkerClusterer(\"", ".", "$", "_prefix", ".", "$", "map_id", ".", "\", markers\"", ".", "$", "map_id", ".", "\", {\n\t\t maxZoom: \"", ".", "$", "this", "->", "marker_clusterer_options", "[", "\"maxZoom\"", "]", ".", "\",\n\t\t gridSize: \"", ".", "$", "this", "->", "marker_clusterer_options", "[", "\"gridSize\"", "]", ".", "\",\n\t\t styles: \"", ".", "$", "this", "->", "marker_clusterer_options", "[", "\"styles\"", "]", ".", "\"\n\t\t });\n\t\t \t\n \t\"", ";", "}", "return", "$", "_output", ";", "}" ]
overridable function for generating js to add markers
[ "overridable", "function", "for", "generating", "js", "to", "add", "markers" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L2162-L2201
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.getPolylineJS
function getPolylineJS() { $_output = ''; foreach($this->_polylines as $polyline_id =>$_polyline) { $_coords_output = ""; foreach($_polyline["coords"] as $_coords){ if($_coords_output != ""){$_coords_output.=",";} $_coords_output .= " new google.maps.LatLng(".$_coords["lat"].", ".$_coords["long"].") "; } $_output .= " polylineCoords".$this->map_id."[$polyline_id] = [".$_coords_output."]; polylines".$this->map_id."[$polyline_id] = new google.maps.Polyline({ path: polylineCoords".$this->map_id."[$polyline_id] ".(($_polyline['color']!="")?", strokeColor: '".$_polyline['color']."'":"")." ".(($_polyline['opacity']!=0)?", strokeOpacity: ".$_polyline['opacity']."":"")." ".(($_polyline['weight']!=0)?", strokeWeight: ".$_polyline['weight']."":"")." }); polylines".$this->map_id."[$polyline_id].setMap(map".$this->map_id."); "; //Elevation profiles if(!empty($this->_elevation_polylines) && isset($this->_elevation_polylines[$polyline_id])){ $elevation_dom_id=$this->_elevation_polylines[$polyline_id]["dom_id"]; $width = $this->_elevation_polylines[$polyline_id]["width"]; $height = $this->_elevation_polylines[$polyline_id]["height"]; $samples = $this->_elevation_polylines[$polyline_id]["samples"]; $focus_color = $this->_elevation_polylines[$polyline_id]["focus_color"]; $_output .= " elevationPolylines".$this->map_id."[$polyline_id] = { 'selector':'$elevation_dom_id', 'chart': new google.visualization.ColumnChart(document.getElementById('$elevation_dom_id')), 'service': new google.maps.ElevationService(), 'width':$width, 'height':$height, 'focusColor':'$focus_color', 'marker':null }; elevationPolylines".$this->map_id."[$polyline_id]['service'].getElevationAlongPath({ path: polylineCoords".$this->map_id."[$polyline_id], samples: $samples }, function(results,status){plotElevation(results,status, elevationPolylines".$this->map_id."[$polyline_id], map".$this->map_id.", elevationCharts".$this->map_id.");}); "; } } return $_output; }
php
function getPolylineJS() { $_output = ''; foreach($this->_polylines as $polyline_id =>$_polyline) { $_coords_output = ""; foreach($_polyline["coords"] as $_coords){ if($_coords_output != ""){$_coords_output.=",";} $_coords_output .= " new google.maps.LatLng(".$_coords["lat"].", ".$_coords["long"].") "; } $_output .= " polylineCoords".$this->map_id."[$polyline_id] = [".$_coords_output."]; polylines".$this->map_id."[$polyline_id] = new google.maps.Polyline({ path: polylineCoords".$this->map_id."[$polyline_id] ".(($_polyline['color']!="")?", strokeColor: '".$_polyline['color']."'":"")." ".(($_polyline['opacity']!=0)?", strokeOpacity: ".$_polyline['opacity']."":"")." ".(($_polyline['weight']!=0)?", strokeWeight: ".$_polyline['weight']."":"")." }); polylines".$this->map_id."[$polyline_id].setMap(map".$this->map_id."); "; //Elevation profiles if(!empty($this->_elevation_polylines) && isset($this->_elevation_polylines[$polyline_id])){ $elevation_dom_id=$this->_elevation_polylines[$polyline_id]["dom_id"]; $width = $this->_elevation_polylines[$polyline_id]["width"]; $height = $this->_elevation_polylines[$polyline_id]["height"]; $samples = $this->_elevation_polylines[$polyline_id]["samples"]; $focus_color = $this->_elevation_polylines[$polyline_id]["focus_color"]; $_output .= " elevationPolylines".$this->map_id."[$polyline_id] = { 'selector':'$elevation_dom_id', 'chart': new google.visualization.ColumnChart(document.getElementById('$elevation_dom_id')), 'service': new google.maps.ElevationService(), 'width':$width, 'height':$height, 'focusColor':'$focus_color', 'marker':null }; elevationPolylines".$this->map_id."[$polyline_id]['service'].getElevationAlongPath({ path: polylineCoords".$this->map_id."[$polyline_id], samples: $samples }, function(results,status){plotElevation(results,status, elevationPolylines".$this->map_id."[$polyline_id], map".$this->map_id.", elevationCharts".$this->map_id.");}); "; } } return $_output; }
[ "function", "getPolylineJS", "(", ")", "{", "$", "_output", "=", "''", ";", "foreach", "(", "$", "this", "->", "_polylines", "as", "$", "polyline_id", "=>", "$", "_polyline", ")", "{", "$", "_coords_output", "=", "\"\"", ";", "foreach", "(", "$", "_polyline", "[", "\"coords\"", "]", "as", "$", "_coords", ")", "{", "if", "(", "$", "_coords_output", "!=", "\"\"", ")", "{", "$", "_coords_output", ".=", "\",\"", ";", "}", "$", "_coords_output", ".=", "\"\n \t\t new google.maps.LatLng(\"", ".", "$", "_coords", "[", "\"lat\"", "]", ".", "\", \"", ".", "$", "_coords", "[", "\"long\"", "]", ".", "\")\n \t\t\"", ";", "}", "$", "_output", ".=", "\"\n \t polylineCoords\"", ".", "$", "this", "->", "map_id", ".", "\"[$polyline_id] = [\"", ".", "$", "_coords_output", ".", "\"]; \t\n\t\t\t polylines\"", ".", "$", "this", "->", "map_id", ".", "\"[$polyline_id] = new google.maps.Polyline({\n\t\t\t\t path: polylineCoords\"", ".", "$", "this", "->", "map_id", ".", "\"[$polyline_id]\n\t\t\t\t \"", ".", "(", "(", "$", "_polyline", "[", "'color'", "]", "!=", "\"\"", ")", "?", "\", strokeColor: '\"", ".", "$", "_polyline", "[", "'color'", "]", ".", "\"'\"", ":", "\"\"", ")", ".", "\"\n\t\t\t\t \"", ".", "(", "(", "$", "_polyline", "[", "'opacity'", "]", "!=", "0", ")", "?", "\", strokeOpacity: \"", ".", "$", "_polyline", "[", "'opacity'", "]", ".", "\"\"", ":", "\"\"", ")", ".", "\"\n\t\t\t\t \"", ".", "(", "(", "$", "_polyline", "[", "'weight'", "]", "!=", "0", ")", "?", "\", strokeWeight: \"", ".", "$", "_polyline", "[", "'weight'", "]", ".", "\"\"", ":", "\"\"", ")", ".", "\"\n\t\t\t });\t\t\t\n\t\t\t polylines\"", ".", "$", "this", "->", "map_id", ".", "\"[$polyline_id].setMap(map\"", ".", "$", "this", "->", "map_id", ".", "\");\n \t\"", ";", "//Elevation profiles", "if", "(", "!", "empty", "(", "$", "this", "->", "_elevation_polylines", ")", "&&", "isset", "(", "$", "this", "->", "_elevation_polylines", "[", "$", "polyline_id", "]", ")", ")", "{", "$", "elevation_dom_id", "=", "$", "this", "->", "_elevation_polylines", "[", "$", "polyline_id", "]", "[", "\"dom_id\"", "]", ";", "$", "width", "=", "$", "this", "->", "_elevation_polylines", "[", "$", "polyline_id", "]", "[", "\"width\"", "]", ";", "$", "height", "=", "$", "this", "->", "_elevation_polylines", "[", "$", "polyline_id", "]", "[", "\"height\"", "]", ";", "$", "samples", "=", "$", "this", "->", "_elevation_polylines", "[", "$", "polyline_id", "]", "[", "\"samples\"", "]", ";", "$", "focus_color", "=", "$", "this", "->", "_elevation_polylines", "[", "$", "polyline_id", "]", "[", "\"focus_color\"", "]", ";", "$", "_output", ".=", "\"\n\t\t\t\t\televationPolylines\"", ".", "$", "this", "->", "map_id", ".", "\"[$polyline_id] = {\n\t\t\t\t\t\t'selector':'$elevation_dom_id',\n\t\t\t\t\t\t'chart': new google.visualization.ColumnChart(document.getElementById('$elevation_dom_id')),\n\t\t\t\t\t\t'service': new google.maps.ElevationService(),\n\t\t\t\t\t\t'width':$width,\n\t\t\t\t\t\t'height':$height,\n\t\t\t\t\t\t'focusColor':'$focus_color',\n\t\t\t\t\t\t'marker':null\n\t\t\t\t\t};\n\t\t\t\t\televationPolylines\"", ".", "$", "this", "->", "map_id", ".", "\"[$polyline_id]['service'].getElevationAlongPath({\n\t\t\t\t\t\tpath: polylineCoords\"", ".", "$", "this", "->", "map_id", ".", "\"[$polyline_id],\n\t\t\t\t\t\tsamples: $samples\n\t\t\t\t\t}, function(results,status){plotElevation(results,status, elevationPolylines\"", ".", "$", "this", "->", "map_id", ".", "\"[$polyline_id], map\"", ".", "$", "this", "->", "map_id", ".", "\", elevationCharts\"", ".", "$", "this", "->", "map_id", ".", "\");});\n\t\t\t\t\"", ";", "}", "}", "return", "$", "_output", ";", "}" ]
overridable function to generate polyline js - for now can only be used on a map, not a streetview
[ "overridable", "function", "to", "generate", "polyline", "js", "-", "for", "now", "can", "only", "be", "used", "on", "a", "map", "not", "a", "streetview" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L2206-L2252
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.getAddDirectionsJS
function getAddDirectionsJS(){ $_output = ""; foreach($this->_directions as $directions){ $dom_id = $directions["dom_id"]; $travelModeParams = array(); $directionsParams = ""; if($this->walking_directions==TRUE) $directionsParams .= ", \n travelMode:google.maps.DirectionsTravelMode.WALKING"; else if($this->biking_directions==TRUE) $directionsParams .= ", \n travelMode:google.maps.DirectionsTravelMode.BICYCLING"; else $directionsParams .= ", \n travelMode:google.maps.DirectionsTravelMode.DRIVING"; if($this->avoid_highways==TRUE) $directionsParams .= ", \n avoidHighways: true"; if($this->avoid_tollways==TRUE) $directionsParams .= ", \n avoidTolls: true"; if($this->directions_unit_system!=''){ if($this->directions_unit_system == 'METRIC'){ $directionsParams .= ", \n unitSystem: google.maps.DirectionsUnitSystem.METRIC"; }else{ $directionsParams .= ", \n unitSystem: google.maps.DirectionsUnitSystem.IMPERIAL"; } } $_output .= " directions".$this->map_id."['$dom_id'] = { displayRenderer:new google.maps.DirectionsRenderer(), directionService:new google.maps.DirectionsService(), request:{ waypoints: [{$this->_waypoints_string}], origin: '".$directions["start"]."', destination: '".$directions["dest"]."' $directionsParams } ".(($this->elevation_directions)?", selector: '".$directions["elevation_dom_id"]."', chart: new google.visualization.ColumnChart(document.getElementById('".$directions["elevation_dom_id"]."')), service: new google.maps.ElevationService(), width:".$directions["width"].", height:".$directions["height"].", focusColor:'#00FF00', marker:null ":"")." }; directions".$this->map_id."['$dom_id'].displayRenderer.setMap(map".$this->map_id."); directions".$this->map_id."['$dom_id'].displayRenderer.setPanel(document.getElementById('$dom_id')); directions".$this->map_id."['$dom_id'].directionService.route(directions".$this->map_id."['$dom_id'].request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directions".$this->map_id."['$dom_id'].displayRenderer.setDirections(response); ".(($this->elevation_directions)?" directions".$this->map_id."['$dom_id'].service.getElevationAlongPath({ path: response.routes[0].overview_path, samples: ".$directions["elevation_samples"]." }, function(results,status){plotElevation(results,status, directions".$this->map_id."['$dom_id'], map".$this->map_id.", elevationCharts".$this->map_id.");}); ":"")." } }); "; } return $_output; }
php
function getAddDirectionsJS(){ $_output = ""; foreach($this->_directions as $directions){ $dom_id = $directions["dom_id"]; $travelModeParams = array(); $directionsParams = ""; if($this->walking_directions==TRUE) $directionsParams .= ", \n travelMode:google.maps.DirectionsTravelMode.WALKING"; else if($this->biking_directions==TRUE) $directionsParams .= ", \n travelMode:google.maps.DirectionsTravelMode.BICYCLING"; else $directionsParams .= ", \n travelMode:google.maps.DirectionsTravelMode.DRIVING"; if($this->avoid_highways==TRUE) $directionsParams .= ", \n avoidHighways: true"; if($this->avoid_tollways==TRUE) $directionsParams .= ", \n avoidTolls: true"; if($this->directions_unit_system!=''){ if($this->directions_unit_system == 'METRIC'){ $directionsParams .= ", \n unitSystem: google.maps.DirectionsUnitSystem.METRIC"; }else{ $directionsParams .= ", \n unitSystem: google.maps.DirectionsUnitSystem.IMPERIAL"; } } $_output .= " directions".$this->map_id."['$dom_id'] = { displayRenderer:new google.maps.DirectionsRenderer(), directionService:new google.maps.DirectionsService(), request:{ waypoints: [{$this->_waypoints_string}], origin: '".$directions["start"]."', destination: '".$directions["dest"]."' $directionsParams } ".(($this->elevation_directions)?", selector: '".$directions["elevation_dom_id"]."', chart: new google.visualization.ColumnChart(document.getElementById('".$directions["elevation_dom_id"]."')), service: new google.maps.ElevationService(), width:".$directions["width"].", height:".$directions["height"].", focusColor:'#00FF00', marker:null ":"")." }; directions".$this->map_id."['$dom_id'].displayRenderer.setMap(map".$this->map_id."); directions".$this->map_id."['$dom_id'].displayRenderer.setPanel(document.getElementById('$dom_id')); directions".$this->map_id."['$dom_id'].directionService.route(directions".$this->map_id."['$dom_id'].request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directions".$this->map_id."['$dom_id'].displayRenderer.setDirections(response); ".(($this->elevation_directions)?" directions".$this->map_id."['$dom_id'].service.getElevationAlongPath({ path: response.routes[0].overview_path, samples: ".$directions["elevation_samples"]." }, function(results,status){plotElevation(results,status, directions".$this->map_id."['$dom_id'], map".$this->map_id.", elevationCharts".$this->map_id.");}); ":"")." } }); "; } return $_output; }
[ "function", "getAddDirectionsJS", "(", ")", "{", "$", "_output", "=", "\"\"", ";", "foreach", "(", "$", "this", "->", "_directions", "as", "$", "directions", ")", "{", "$", "dom_id", "=", "$", "directions", "[", "\"dom_id\"", "]", ";", "$", "travelModeParams", "=", "array", "(", ")", ";", "$", "directionsParams", "=", "\"\"", ";", "if", "(", "$", "this", "->", "walking_directions", "==", "TRUE", ")", "$", "directionsParams", ".=", "\", \\n travelMode:google.maps.DirectionsTravelMode.WALKING\"", ";", "else", "if", "(", "$", "this", "->", "biking_directions", "==", "TRUE", ")", "$", "directionsParams", ".=", "\", \\n travelMode:google.maps.DirectionsTravelMode.BICYCLING\"", ";", "else", "$", "directionsParams", ".=", "\", \\n travelMode:google.maps.DirectionsTravelMode.DRIVING\"", ";", "if", "(", "$", "this", "->", "avoid_highways", "==", "TRUE", ")", "$", "directionsParams", ".=", "\", \\n avoidHighways: true\"", ";", "if", "(", "$", "this", "->", "avoid_tollways", "==", "TRUE", ")", "$", "directionsParams", ".=", "\", \\n avoidTolls: true\"", ";", "if", "(", "$", "this", "->", "directions_unit_system", "!=", "''", ")", "{", "if", "(", "$", "this", "->", "directions_unit_system", "==", "'METRIC'", ")", "{", "$", "directionsParams", ".=", "\", \\n unitSystem: google.maps.DirectionsUnitSystem.METRIC\"", ";", "}", "else", "{", "$", "directionsParams", ".=", "\", \\n unitSystem: google.maps.DirectionsUnitSystem.IMPERIAL\"", ";", "}", "}", "$", "_output", ".=", "\"\n\t\t\t directions\"", ".", "$", "this", "->", "map_id", ".", "\"['$dom_id'] = {\n\t\t\t\t\tdisplayRenderer:new google.maps.DirectionsRenderer(),\n\t\t\t\t\tdirectionService:new google.maps.DirectionsService(),\n\t\t\t\t\trequest:{\n \t\t\t\t\twaypoints: [{$this->_waypoints_string}],\n\t\t\t\t\t\torigin: '\"", ".", "$", "directions", "[", "\"start\"", "]", ".", "\"',\n\t\t\t\t\t\tdestination: '\"", ".", "$", "directions", "[", "\"dest\"", "]", ".", "\"'\n\t\t\t\t\t\t$directionsParams\n\t\t\t\t\t}\n\t\t\t\t\t\"", ".", "(", "(", "$", "this", "->", "elevation_directions", ")", "?", "\",\t\t\n\t\t\t\t\t selector: '\"", ".", "$", "directions", "[", "\"elevation_dom_id\"", "]", ".", "\"',\n\t\t\t\t\t chart: new google.visualization.ColumnChart(document.getElementById('\"", ".", "$", "directions", "[", "\"elevation_dom_id\"", "]", ".", "\"')),\n\t\t\t\t\t service: new google.maps.ElevationService(),\n\t\t\t\t\t width:\"", ".", "$", "directions", "[", "\"width\"", "]", ".", "\",\n\t\t\t\t\t height:\"", ".", "$", "directions", "[", "\"height\"", "]", ".", "\",\n\t\t\t\t\t focusColor:'#00FF00',\n\t\t\t\t\t marker:null\n\t\t\t\t \"", ":", "\"\"", ")", ".", "\"\n\t\t\t\t};\n\t\t\t\tdirections\"", ".", "$", "this", "->", "map_id", ".", "\"['$dom_id'].displayRenderer.setMap(map\"", ".", "$", "this", "->", "map_id", ".", "\");\n\t\t\t\tdirections\"", ".", "$", "this", "->", "map_id", ".", "\"['$dom_id'].displayRenderer.setPanel(document.getElementById('$dom_id'));\n\t\t\t\tdirections\"", ".", "$", "this", "->", "map_id", ".", "\"['$dom_id'].directionService.route(directions\"", ".", "$", "this", "->", "map_id", ".", "\"['$dom_id'].request, function(response, status) {\n\t\t\t\t\tif (status == google.maps.DirectionsStatus.OK) {\n\t\t\t\t\t directions\"", ".", "$", "this", "->", "map_id", ".", "\"['$dom_id'].displayRenderer.setDirections(response);\n\t\t\t\t\t \"", ".", "(", "(", "$", "this", "->", "elevation_directions", ")", "?", "\"\n\t\t\t\t\t\t directions\"", ".", "$", "this", "->", "map_id", ".", "\"['$dom_id'].service.getElevationAlongPath({\n\t\t\t\t\t\t\t path: response.routes[0].overview_path,\n\t\t\t\t\t\t\t samples: \"", ".", "$", "directions", "[", "\"elevation_samples\"", "]", ".", "\"\n\t\t\t\t\t\t }, function(results,status){plotElevation(results,status, directions\"", ".", "$", "this", "->", "map_id", ".", "\"['$dom_id'], map\"", ".", "$", "this", "->", "map_id", ".", "\", elevationCharts\"", ".", "$", "this", "->", "map_id", ".", "\");});\n\t\t\t\t\t \"", ":", "\"\"", ")", ".", "\"\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t \"", ";", "}", "return", "$", "_output", ";", "}" ]
function to render proper calls for directions - for now can only be used on a map, not a streetview
[ "function", "to", "render", "proper", "calls", "for", "directions", "-", "for", "now", "can", "only", "be", "used", "on", "a", "map", "not", "a", "streetview" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L2257-L2321
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.getAddOverlayJS
function getAddOverlayJS(){ $_output = ""; foreach($this->_overlays as $_key=>$_overlay){ $_output .= " var bounds = new google.maps.LatLngBounds(new google.maps.LatLng(".$_overlay["bounds"]["ne"]["lat"].", ".$_overlay["bounds"]["ne"]["long"]."), new google.maps.LatLng(".$_overlay["bounds"]["sw"]["lat"].", ".$_overlay["bounds"]["sw"]["long"].")); var image = '".$_overlay["img"]."'; overlays".$this->map_id."[$_key] = new CustomOverlay(bounds, image, map".$this->map_id.", ".$_overlay["opacity"]."); "; } return $_output; }
php
function getAddOverlayJS(){ $_output = ""; foreach($this->_overlays as $_key=>$_overlay){ $_output .= " var bounds = new google.maps.LatLngBounds(new google.maps.LatLng(".$_overlay["bounds"]["ne"]["lat"].", ".$_overlay["bounds"]["ne"]["long"]."), new google.maps.LatLng(".$_overlay["bounds"]["sw"]["lat"].", ".$_overlay["bounds"]["sw"]["long"].")); var image = '".$_overlay["img"]."'; overlays".$this->map_id."[$_key] = new CustomOverlay(bounds, image, map".$this->map_id.", ".$_overlay["opacity"]."); "; } return $_output; }
[ "function", "getAddOverlayJS", "(", ")", "{", "$", "_output", "=", "\"\"", ";", "foreach", "(", "$", "this", "->", "_overlays", "as", "$", "_key", "=>", "$", "_overlay", ")", "{", "$", "_output", ".=", "\"\n\t\t\t \t var bounds = new google.maps.LatLngBounds(new google.maps.LatLng(\"", ".", "$", "_overlay", "[", "\"bounds\"", "]", "[", "\"ne\"", "]", "[", "\"lat\"", "]", ".", "\", \"", ".", "$", "_overlay", "[", "\"bounds\"", "]", "[", "\"ne\"", "]", "[", "\"long\"", "]", ".", "\"), new google.maps.LatLng(\"", ".", "$", "_overlay", "[", "\"bounds\"", "]", "[", "\"sw\"", "]", "[", "\"lat\"", "]", ".", "\", \"", ".", "$", "_overlay", "[", "\"bounds\"", "]", "[", "\"sw\"", "]", "[", "\"long\"", "]", ".", "\"));\n\t\t\t\t var image = '\"", ".", "$", "_overlay", "[", "\"img\"", "]", ".", "\"';\n\t\t\t overlays\"", ".", "$", "this", "->", "map_id", ".", "\"[$_key] = new CustomOverlay(bounds, image, map\"", ".", "$", "this", "->", "map_id", ".", "\", \"", ".", "$", "_overlay", "[", "\"opacity\"", "]", ".", "\");\n\t\t\t \"", ";", "}", "return", "$", "_output", ";", "}" ]
function to get overlay creation JS.
[ "function", "to", "get", "overlay", "creation", "JS", "." ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L2326-L2336
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.getCreateMarkerJS
function getCreateMarkerJS() { $_output = " function createMarker(map, point, title, html, icon, icon_shadow, sidebar_id, openers){ var marker_options = { position: point, map: map, title: title}; if(icon!=''){marker_options.icon = icon;} if(icon_shadow!=''){marker_options.shadow = icon_shadow;} //create marker var new_marker = new google.maps.Marker(marker_options); if(html!=''){ ".(($this->info_window)?" google.maps.event.addListener(new_marker, '".$this->window_trigger."', function() { infowindow.close(); infowindow.setContent(html); infowindow.open(map,new_marker); }); if(openers != ''&&!isEmpty(openers)){ for(var i in openers){ var opener = document.getElementById(openers[i]); opener.on".$this->window_trigger." = function() { infowindow.close(); infowindow.setContent(html); infowindow.open(map,new_marker); return false; }; } } ":"")." if(sidebar_id != ''){ var sidebar = document.getElementById(sidebar_id); if(sidebar!=null && sidebar!=undefined && title!=null && title!=''){ var newlink = document.createElement('a'); ".(($this->info_window)?" newlink.onclick=function(){infowindow.open(map,new_marker); return false}; ":" newlink.onclick=function(){map.setCenter(point); return false}; ")." newlink.innerHTML = title; sidebar.appendChild(newlink); } } } return new_marker; } "; return $_output; }
php
function getCreateMarkerJS() { $_output = " function createMarker(map, point, title, html, icon, icon_shadow, sidebar_id, openers){ var marker_options = { position: point, map: map, title: title}; if(icon!=''){marker_options.icon = icon;} if(icon_shadow!=''){marker_options.shadow = icon_shadow;} //create marker var new_marker = new google.maps.Marker(marker_options); if(html!=''){ ".(($this->info_window)?" google.maps.event.addListener(new_marker, '".$this->window_trigger."', function() { infowindow.close(); infowindow.setContent(html); infowindow.open(map,new_marker); }); if(openers != ''&&!isEmpty(openers)){ for(var i in openers){ var opener = document.getElementById(openers[i]); opener.on".$this->window_trigger." = function() { infowindow.close(); infowindow.setContent(html); infowindow.open(map,new_marker); return false; }; } } ":"")." if(sidebar_id != ''){ var sidebar = document.getElementById(sidebar_id); if(sidebar!=null && sidebar!=undefined && title!=null && title!=''){ var newlink = document.createElement('a'); ".(($this->info_window)?" newlink.onclick=function(){infowindow.open(map,new_marker); return false}; ":" newlink.onclick=function(){map.setCenter(point); return false}; ")." newlink.innerHTML = title; sidebar.appendChild(newlink); } } } return new_marker; } "; return $_output; }
[ "function", "getCreateMarkerJS", "(", ")", "{", "$", "_output", "=", "\"\n \t function createMarker(map, point, title, html, icon, icon_shadow, sidebar_id, openers){\n\t\t\t var marker_options = {\n\t\t\t position: point,\n\t\t\t map: map,\n\t\t\t title: title}; \n\t\t\t if(icon!=''){marker_options.icon = icon;}\n\t\t\t if(icon_shadow!=''){marker_options.shadow = icon_shadow;}\n\t\t\t \n\t\t\t //create marker\n\t\t\t var new_marker = new google.maps.Marker(marker_options);\n\t\t\t if(html!=''){\n\t\t\t\t\t\"", ".", "(", "(", "$", "this", "->", "info_window", ")", "?", "\"\n\t\t\t \n\t\t\t google.maps.event.addListener(new_marker, '\"", ".", "$", "this", "->", "window_trigger", ".", "\"', function() {\n\t\t\t \tinfowindow.close();\t\n\t\t\t \tinfowindow.setContent(html);\n\t\t\t \tinfowindow.open(map,new_marker);\n\t\t\t });\n\t\t\t \n\t\t\t\t\tif(openers != ''&&!isEmpty(openers)){\n\t\t\t for(var i in openers){\n\t\t\t var opener = document.getElementById(openers[i]);\n\t\t\t opener.on\"", ".", "$", "this", "->", "window_trigger", ".", "\" = function() { \n\t\t\t \n\t\t\t \tinfowindow.close();\n\t\t\t \tinfowindow.setContent(html);\n\t\t\t \tinfowindow.open(map,new_marker); \n\t\t\t \t\n\t\t\t \t\treturn false;\t\t\t \t\n\t\t\t };\n\t\t\t }\n\t\t\t }\n\t\t\t\t\t\"", ":", "\"\"", ")", ".", "\"\n\t\t\t if(sidebar_id != ''){\n\t\t\t var sidebar = document.getElementById(sidebar_id);\n\t\t\t\t\t\tif(sidebar!=null && sidebar!=undefined && title!=null && title!=''){\n\t\t\t\t\t\t\tvar newlink = document.createElement('a');\n\t\t\t\t\t\t\t\"", ".", "(", "(", "$", "this", "->", "info_window", ")", "?", "\"\n\t\t\t \t\tnewlink.onclick=function(){infowindow.open(map,new_marker); return false};\n\t\t\t\t\t\t\t\"", ":", "\"\n\t\t\t\t\t\t\tnewlink.onclick=function(){map.setCenter(point); return false};\n\t\t\t\t\t\t\t\"", ")", ".", "\"\n\t\t\t\t\t\t\tnewlink.innerHTML = title;\n\t\t\t\t\t\t\tsidebar.appendChild(newlink);\n\t\t\t\t\t\t}\n\t\t\t }\n }\n\t\t\t return new_marker; \n\t\t\t}\n \t\"", ";", "return", "$", "_output", ";", "}" ]
overridable function to generate the js for the js function for creating a marker.
[ "overridable", "function", "to", "generate", "the", "js", "for", "the", "js", "function", "for", "creating", "a", "marker", "." ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L2341-L2394
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.getMap
function getMap() { $_output = '<script type="text/javascript" charset="utf-8">' . "\n" . '//<![CDATA[' . "\n"; //$_output .= 'if (GBrowserIsCompatible()) {' . "\n"; if(strlen($this->width) > 0 && strlen($this->height) > 0) { $_output .= sprintf('document.write(\'<div id="%s" style="width: %s; height: %s; position:relative;"><\/div>\');',$this->map_id,$this->width,$this->height) . "\n"; } else { $_output .= sprintf('document.write(\'<div id="%s" style="position:relative;"><\/div>\');',$this->map_id) . "\n"; } //$_output .= '}'; //if(!empty($this->js_alert)) { // $_output .= ' else {' . "\n"; // $_output .= sprintf('document.write(\'%s\');', str_replace('/','\/',$this->js_alert)) . "\n"; // $_output .= '}' . "\n"; //} $_output .= '//]]>' . "\n" . '</script>' . "\n"; if(!empty($this->js_alert)) { $_output .= '<noscript>' . $this->js_alert . '</noscript>' . "\n"; } return $_output; }
php
function getMap() { $_output = '<script type="text/javascript" charset="utf-8">' . "\n" . '//<![CDATA[' . "\n"; //$_output .= 'if (GBrowserIsCompatible()) {' . "\n"; if(strlen($this->width) > 0 && strlen($this->height) > 0) { $_output .= sprintf('document.write(\'<div id="%s" style="width: %s; height: %s; position:relative;"><\/div>\');',$this->map_id,$this->width,$this->height) . "\n"; } else { $_output .= sprintf('document.write(\'<div id="%s" style="position:relative;"><\/div>\');',$this->map_id) . "\n"; } //$_output .= '}'; //if(!empty($this->js_alert)) { // $_output .= ' else {' . "\n"; // $_output .= sprintf('document.write(\'%s\');', str_replace('/','\/',$this->js_alert)) . "\n"; // $_output .= '}' . "\n"; //} $_output .= '//]]>' . "\n" . '</script>' . "\n"; if(!empty($this->js_alert)) { $_output .= '<noscript>' . $this->js_alert . '</noscript>' . "\n"; } return $_output; }
[ "function", "getMap", "(", ")", "{", "$", "_output", "=", "'<script type=\"text/javascript\" charset=\"utf-8\">'", ".", "\"\\n\"", ".", "'//<![CDATA['", ".", "\"\\n\"", ";", "//$_output .= 'if (GBrowserIsCompatible()) {' . \"\\n\";", "if", "(", "strlen", "(", "$", "this", "->", "width", ")", ">", "0", "&&", "strlen", "(", "$", "this", "->", "height", ")", ">", "0", ")", "{", "$", "_output", ".=", "sprintf", "(", "'document.write(\\'<div id=\"%s\" style=\"width: %s; height: %s; position:relative;\"><\\/div>\\');'", ",", "$", "this", "->", "map_id", ",", "$", "this", "->", "width", ",", "$", "this", "->", "height", ")", ".", "\"\\n\"", ";", "}", "else", "{", "$", "_output", ".=", "sprintf", "(", "'document.write(\\'<div id=\"%s\" style=\"position:relative;\"><\\/div>\\');'", ",", "$", "this", "->", "map_id", ")", ".", "\"\\n\"", ";", "}", "//$_output .= '}';", "//if(!empty($this->js_alert)) {", "// $_output .= ' else {' . \"\\n\";", "// $_output .= sprintf('document.write(\\'%s\\');', str_replace('/','\\/',$this->js_alert)) . \"\\n\";", "// $_output .= '}' . \"\\n\";", "//}", "$", "_output", ".=", "'//]]>'", ".", "\"\\n\"", ".", "'</script>'", ".", "\"\\n\"", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "js_alert", ")", ")", "{", "$", "_output", ".=", "'<noscript>'", ".", "$", "this", "->", "js_alert", ".", "'</noscript>'", ".", "\"\\n\"", ";", "}", "return", "$", "_output", ";", "}" ]
return map
[ "return", "map" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L2518-L2541
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.getGeocode
function getGeocode($address) { if(empty($address)) return false; $_geocode = false; if(($_geocode = $this->getCache($address)) === false) { if(($_geocode = $this->geoGetCoords($address)) !== false) { $this->putCache($address, $_geocode['lon'], $_geocode['lat']); } } return $_geocode; }
php
function getGeocode($address) { if(empty($address)) return false; $_geocode = false; if(($_geocode = $this->getCache($address)) === false) { if(($_geocode = $this->geoGetCoords($address)) !== false) { $this->putCache($address, $_geocode['lon'], $_geocode['lat']); } } return $_geocode; }
[ "function", "getGeocode", "(", "$", "address", ")", "{", "if", "(", "empty", "(", "$", "address", ")", ")", "return", "false", ";", "$", "_geocode", "=", "false", ";", "if", "(", "(", "$", "_geocode", "=", "$", "this", "->", "getCache", "(", "$", "address", ")", ")", "===", "false", ")", "{", "if", "(", "(", "$", "_geocode", "=", "$", "this", "->", "geoGetCoords", "(", "$", "address", ")", ")", "!==", "false", ")", "{", "$", "this", "->", "putCache", "(", "$", "address", ",", "$", "_geocode", "[", "'lon'", "]", ",", "$", "_geocode", "[", "'lat'", "]", ")", ";", "}", "}", "return", "$", "_geocode", ";", "}" ]
get the geocode lat/lon points from given address look in cache first, otherwise get from Yahoo @param string $address @return array GeoCode information
[ "get", "the", "geocode", "lat", "/", "lon", "points", "from", "given", "address", "look", "in", "cache", "first", "otherwise", "get", "from", "Yahoo" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L2567-L2577
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.getCache
function getCache($address) { if(!isset($this->dsn)) return false; $_ret = array(); // PEAR DB require_once('DB.php'); $_db =& DB::connect($this->dsn); if (PEAR::isError($_db)) { die($_db->getMessage()); } $_res =& $_db->query("SELECT lon,lat FROM {$this->_db_cache_table} where address = ?", $address); if (PEAR::isError($_res)) { die($_res->getMessage()); } if($_row = $_res->fetchRow()) { $_ret['lon'] = $_row[0]; $_ret['lat'] = $_row[1]; } $_db->disconnect(); return !empty($_ret) ? $_ret : false; }
php
function getCache($address) { if(!isset($this->dsn)) return false; $_ret = array(); // PEAR DB require_once('DB.php'); $_db =& DB::connect($this->dsn); if (PEAR::isError($_db)) { die($_db->getMessage()); } $_res =& $_db->query("SELECT lon,lat FROM {$this->_db_cache_table} where address = ?", $address); if (PEAR::isError($_res)) { die($_res->getMessage()); } if($_row = $_res->fetchRow()) { $_ret['lon'] = $_row[0]; $_ret['lat'] = $_row[1]; } $_db->disconnect(); return !empty($_ret) ? $_ret : false; }
[ "function", "getCache", "(", "$", "address", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "dsn", ")", ")", "return", "false", ";", "$", "_ret", "=", "array", "(", ")", ";", "// PEAR DB", "require_once", "(", "'DB.php'", ")", ";", "$", "_db", "=", "&", "DB", "::", "connect", "(", "$", "this", "->", "dsn", ")", ";", "if", "(", "PEAR", "::", "isError", "(", "$", "_db", ")", ")", "{", "die", "(", "$", "_db", "->", "getMessage", "(", ")", ")", ";", "}", "$", "_res", "=", "&", "$", "_db", "->", "query", "(", "\"SELECT lon,lat FROM {$this->_db_cache_table} where address = ?\"", ",", "$", "address", ")", ";", "if", "(", "PEAR", "::", "isError", "(", "$", "_res", ")", ")", "{", "die", "(", "$", "_res", "->", "getMessage", "(", ")", ")", ";", "}", "if", "(", "$", "_row", "=", "$", "_res", "->", "fetchRow", "(", ")", ")", "{", "$", "_ret", "[", "'lon'", "]", "=", "$", "_row", "[", "0", "]", ";", "$", "_ret", "[", "'lat'", "]", "=", "$", "_row", "[", "1", "]", ";", "}", "$", "_db", "->", "disconnect", "(", ")", ";", "return", "!", "empty", "(", "$", "_ret", ")", "?", "$", "_ret", ":", "false", ";", "}" ]
get the geocode lat/lon points from cache for given address @param string $address @return bool|array False if no cache, array of data if has cache
[ "get", "the", "geocode", "lat", "/", "lon", "points", "from", "cache", "for", "given", "address" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L2585-L2609
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.putCache
function putCache($address, $lon, $lat) { if(!isset($this->dsn) || (strlen($address) == 0 || strlen($lon) == 0 || strlen($lat) == 0)) return false; // PEAR DB require_once('DB.php'); $_db =& DB::connect($this->dsn); if (PEAR::isError($_db)) { die($_db->getMessage()); } $_res =& $_db->query('insert into '.$this->_db_cache_table.' values (?, ?, ?)', array($address, $lon, $lat)); if (PEAR::isError($_res)) { die($_res->getMessage()); } $_db->disconnect(); return true; }
php
function putCache($address, $lon, $lat) { if(!isset($this->dsn) || (strlen($address) == 0 || strlen($lon) == 0 || strlen($lat) == 0)) return false; // PEAR DB require_once('DB.php'); $_db =& DB::connect($this->dsn); if (PEAR::isError($_db)) { die($_db->getMessage()); } $_res =& $_db->query('insert into '.$this->_db_cache_table.' values (?, ?, ?)', array($address, $lon, $lat)); if (PEAR::isError($_res)) { die($_res->getMessage()); } $_db->disconnect(); return true; }
[ "function", "putCache", "(", "$", "address", ",", "$", "lon", ",", "$", "lat", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "dsn", ")", "||", "(", "strlen", "(", "$", "address", ")", "==", "0", "||", "strlen", "(", "$", "lon", ")", "==", "0", "||", "strlen", "(", "$", "lat", ")", "==", "0", ")", ")", "return", "false", ";", "// PEAR DB", "require_once", "(", "'DB.php'", ")", ";", "$", "_db", "=", "&", "DB", "::", "connect", "(", "$", "this", "->", "dsn", ")", ";", "if", "(", "PEAR", "::", "isError", "(", "$", "_db", ")", ")", "{", "die", "(", "$", "_db", "->", "getMessage", "(", ")", ")", ";", "}", "$", "_res", "=", "&", "$", "_db", "->", "query", "(", "'insert into '", ".", "$", "this", "->", "_db_cache_table", ".", "' values (?, ?, ?)'", ",", "array", "(", "$", "address", ",", "$", "lon", ",", "$", "lat", ")", ")", ";", "if", "(", "PEAR", "::", "isError", "(", "$", "_res", ")", ")", "{", "die", "(", "$", "_res", "->", "getMessage", "(", ")", ")", ";", "}", "$", "_db", "->", "disconnect", "(", ")", ";", "return", "true", ";", "}" ]
put the geocode lat/lon points into cache for given address @param string $address @param string $lon the map latitude (horizontal) @param string $lat the map latitude (vertical) @return bool Status of put cache request
[ "put", "the", "geocode", "lat", "/", "lon", "points", "into", "cache", "for", "given", "address" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L2619-L2634
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.geoGetCoords
function geoGetCoords($address,$depth=0) { $_coords = false; switch($this->lookup_service) { case 'GOOGLE': $_url = sprintf('http://%s/maps/api/geocode/json?sensor=%s&address=%s',$this->lookup_server['GOOGLE'], $this->mobile==true?"true":"false", rawurlencode($address)); if($_result = $this->fetchURL($_url)) { $_result_parts = json_decode($_result); if($_result_parts->status!="OK"){ return false; } $_coords['lat'] = $_result_parts->results[0]->geometry->location->lat; $_coords['lon'] = $_result_parts->results[0]->geometry->location->lng; } break; case 'YAHOO': default: $_url = sprintf('http://%s/MapsService/V1/geocode?appid=%s&location=%s',$this->lookup_server['YAHOO'],$this->app_id,rawurlencode($address)); if($_result = $this->fetchURL($_url)) { preg_match('!<Latitude>(.*)</Latitude><Longitude>(.*)</Longitude>!U', $_result, $_match); $_coords['lon'] = $_match[2]; $_coords['lat'] = $_match[1]; } break; } return $_coords; }
php
function geoGetCoords($address,$depth=0) { $_coords = false; switch($this->lookup_service) { case 'GOOGLE': $_url = sprintf('http://%s/maps/api/geocode/json?sensor=%s&address=%s',$this->lookup_server['GOOGLE'], $this->mobile==true?"true":"false", rawurlencode($address)); if($_result = $this->fetchURL($_url)) { $_result_parts = json_decode($_result); if($_result_parts->status!="OK"){ return false; } $_coords['lat'] = $_result_parts->results[0]->geometry->location->lat; $_coords['lon'] = $_result_parts->results[0]->geometry->location->lng; } break; case 'YAHOO': default: $_url = sprintf('http://%s/MapsService/V1/geocode?appid=%s&location=%s',$this->lookup_server['YAHOO'],$this->app_id,rawurlencode($address)); if($_result = $this->fetchURL($_url)) { preg_match('!<Latitude>(.*)</Latitude><Longitude>(.*)</Longitude>!U', $_result, $_match); $_coords['lon'] = $_match[2]; $_coords['lat'] = $_match[1]; } break; } return $_coords; }
[ "function", "geoGetCoords", "(", "$", "address", ",", "$", "depth", "=", "0", ")", "{", "$", "_coords", "=", "false", ";", "switch", "(", "$", "this", "->", "lookup_service", ")", "{", "case", "'GOOGLE'", ":", "$", "_url", "=", "sprintf", "(", "'http://%s/maps/api/geocode/json?sensor=%s&address=%s'", ",", "$", "this", "->", "lookup_server", "[", "'GOOGLE'", "]", ",", "$", "this", "->", "mobile", "==", "true", "?", "\"true\"", ":", "\"false\"", ",", "rawurlencode", "(", "$", "address", ")", ")", ";", "if", "(", "$", "_result", "=", "$", "this", "->", "fetchURL", "(", "$", "_url", ")", ")", "{", "$", "_result_parts", "=", "json_decode", "(", "$", "_result", ")", ";", "if", "(", "$", "_result_parts", "->", "status", "!=", "\"OK\"", ")", "{", "return", "false", ";", "}", "$", "_coords", "[", "'lat'", "]", "=", "$", "_result_parts", "->", "results", "[", "0", "]", "->", "geometry", "->", "location", "->", "lat", ";", "$", "_coords", "[", "'lon'", "]", "=", "$", "_result_parts", "->", "results", "[", "0", "]", "->", "geometry", "->", "location", "->", "lng", ";", "}", "break", ";", "case", "'YAHOO'", ":", "default", ":", "$", "_url", "=", "sprintf", "(", "'http://%s/MapsService/V1/geocode?appid=%s&location=%s'", ",", "$", "this", "->", "lookup_server", "[", "'YAHOO'", "]", ",", "$", "this", "->", "app_id", ",", "rawurlencode", "(", "$", "address", ")", ")", ";", "if", "(", "$", "_result", "=", "$", "this", "->", "fetchURL", "(", "$", "_url", ")", ")", "{", "preg_match", "(", "'!<Latitude>(.*)</Latitude><Longitude>(.*)</Longitude>!U'", ",", "$", "_result", ",", "$", "_match", ")", ";", "$", "_coords", "[", "'lon'", "]", "=", "$", "_match", "[", "2", "]", ";", "$", "_coords", "[", "'lat'", "]", "=", "$", "_match", "[", "1", "]", ";", "}", "break", ";", "}", "return", "$", "_coords", ";", "}" ]
get geocode lat/lon points for given address from Google/Yahoo @param string $address @return bool|array false if can't be geocoded, array or geocodess if successful
[ "get", "geocode", "lat", "/", "lon", "points", "for", "given", "address", "from", "Google", "/", "Yahoo" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L2642-L2667
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.geoGetCoordsFull
function geoGetCoordsFull($address,$depth=0) { $_result = false; switch($this->lookup_service) { case 'GOOGLE': $_url = sprintf('http://%s/maps/api/geocode/json?sensor=%s&address=%s',$this->lookup_server['GOOGLE'], $this->mobile==true?"true":"false", rawurlencode($address)); if($_result = $this->fetchURL($_url)) { return json_decode($_result); } break; case 'YAHOO': default: $_url = 'http://%s/MapsService/V1/geocode'; $_url .= sprintf('?appid=%s&location=%s',$this->lookup_server['YAHOO'],$this->app_id,rawurlencode($address)); if($_result = $this->fetchURL($_url)) { return $_result; } break; } }
php
function geoGetCoordsFull($address,$depth=0) { $_result = false; switch($this->lookup_service) { case 'GOOGLE': $_url = sprintf('http://%s/maps/api/geocode/json?sensor=%s&address=%s',$this->lookup_server['GOOGLE'], $this->mobile==true?"true":"false", rawurlencode($address)); if($_result = $this->fetchURL($_url)) { return json_decode($_result); } break; case 'YAHOO': default: $_url = 'http://%s/MapsService/V1/geocode'; $_url .= sprintf('?appid=%s&location=%s',$this->lookup_server['YAHOO'],$this->app_id,rawurlencode($address)); if($_result = $this->fetchURL($_url)) { return $_result; } break; } }
[ "function", "geoGetCoordsFull", "(", "$", "address", ",", "$", "depth", "=", "0", ")", "{", "$", "_result", "=", "false", ";", "switch", "(", "$", "this", "->", "lookup_service", ")", "{", "case", "'GOOGLE'", ":", "$", "_url", "=", "sprintf", "(", "'http://%s/maps/api/geocode/json?sensor=%s&address=%s'", ",", "$", "this", "->", "lookup_server", "[", "'GOOGLE'", "]", ",", "$", "this", "->", "mobile", "==", "true", "?", "\"true\"", ":", "\"false\"", ",", "rawurlencode", "(", "$", "address", ")", ")", ";", "if", "(", "$", "_result", "=", "$", "this", "->", "fetchURL", "(", "$", "_url", ")", ")", "{", "return", "json_decode", "(", "$", "_result", ")", ";", "}", "break", ";", "case", "'YAHOO'", ":", "default", ":", "$", "_url", "=", "'http://%s/MapsService/V1/geocode'", ";", "$", "_url", ".=", "sprintf", "(", "'?appid=%s&location=%s'", ",", "$", "this", "->", "lookup_server", "[", "'YAHOO'", "]", ",", "$", "this", "->", "app_id", ",", "rawurlencode", "(", "$", "address", ")", ")", ";", "if", "(", "$", "_result", "=", "$", "this", "->", "fetchURL", "(", "$", "_url", ")", ")", "{", "return", "$", "_result", ";", "}", "break", ";", "}", "}" ]
get full geocode information for given address from Google NOTE: This does not use the getCache function as there is a lot of data in a full geocode response to cache. @param string $address @return bool|array false if can't be geocoded, array or geocdoes if successful
[ "get", "full", "geocode", "information", "for", "given", "address", "from", "Google", "NOTE", ":", "This", "does", "not", "use", "the", "getCache", "function", "as", "there", "is", "a", "lot", "of", "data", "in", "a", "full", "geocode", "response", "to", "cache", "." ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L2677-L2695
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.geoGetDistance
function geoGetDistance($lat1,$lon1,$lat2,$lon2,$unit='M') { // calculate miles $M = 69.09 * rad2deg(acos(sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($lon1 - $lon2)))); switch(strtoupper($unit)) { case 'K': // kilometers return $M * 1.609344; break; case 'N': // nautical miles return $M * 0.868976242; break; case 'F': // feet return $M * 5280; break; case 'I': // inches return $M * 63360; break; case 'M': default: // miles return $M; break; } }
php
function geoGetDistance($lat1,$lon1,$lat2,$lon2,$unit='M') { // calculate miles $M = 69.09 * rad2deg(acos(sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($lon1 - $lon2)))); switch(strtoupper($unit)) { case 'K': // kilometers return $M * 1.609344; break; case 'N': // nautical miles return $M * 0.868976242; break; case 'F': // feet return $M * 5280; break; case 'I': // inches return $M * 63360; break; case 'M': default: // miles return $M; break; } }
[ "function", "geoGetDistance", "(", "$", "lat1", ",", "$", "lon1", ",", "$", "lat2", ",", "$", "lon2", ",", "$", "unit", "=", "'M'", ")", "{", "// calculate miles", "$", "M", "=", "69.09", "*", "rad2deg", "(", "acos", "(", "sin", "(", "deg2rad", "(", "$", "lat1", ")", ")", "*", "sin", "(", "deg2rad", "(", "$", "lat2", ")", ")", "+", "cos", "(", "deg2rad", "(", "$", "lat1", ")", ")", "*", "cos", "(", "deg2rad", "(", "$", "lat2", ")", ")", "*", "cos", "(", "deg2rad", "(", "$", "lon1", "-", "$", "lon2", ")", ")", ")", ")", ";", "switch", "(", "strtoupper", "(", "$", "unit", ")", ")", "{", "case", "'K'", ":", "// kilometers", "return", "$", "M", "*", "1.609344", ";", "break", ";", "case", "'N'", ":", "// nautical miles", "return", "$", "M", "*", "0.868976242", ";", "break", ";", "case", "'F'", ":", "// feet", "return", "$", "M", "*", "5280", ";", "break", ";", "case", "'I'", ":", "// inches", "return", "$", "M", "*", "63360", ";", "break", ";", "case", "'M'", ":", "default", ":", "// miles", "return", "$", "M", ";", "break", ";", "}", "}" ]
get distance between to geocoords using great circle distance formula @param float $lat1 @param float $lat2 @param float $lon1 @param float $lon2 @param float $unit M=miles, K=kilometers, N=nautical miles, I=inches, F=feet @return float
[ "get", "distance", "between", "to", "geocoords", "using", "great", "circle", "distance", "formula" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L2718-L2748
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.getPolygonJS
function getPolygonJS() { $_output = ''; foreach($this->_polygons as $polygon_id => $_polygon) { $_coords_output = ""; foreach($_polygon["coords"] as $_coords){ if($_coords_output != ""){$_coords_output.=",";} $_coords_output .= " new google.maps.LatLng(".$_coords["lat"].", ".$_coords["long"].") "; } $_output .= " polygonCoords".$this->map_id."[$polygon_id] = [".$_coords_output."]; polygon".$this->map_id."[$polygon_id] = new google.maps.Polygon({ paths: polygonCoords".$this->map_id."[$polygon_id] ".(($_polygon['color']!="")?", strokeColor: '".$_polygon['color']."'":"")." ".(($_polygon['opacity']!=0)?", strokeOpacity: ".$_polygon['opacity']."":"")." ".(($_polygon['weight']!=0)?", strokeWeight: ".$_polygon['weight']."":"")." ".(($_polygon['fill_color']!="")?", fillColor: '".$_polygon['fill_color']."'":"")." ".(($_polygon['fill_opacity']!=0)?", fillOpacity: ".$_polygon['fill_opacity']."":"")." }); polygon".$this->map_id."[$polygon_id].setMap(map".$this->map_id."); "; } return $_output; }
php
function getPolygonJS() { $_output = ''; foreach($this->_polygons as $polygon_id => $_polygon) { $_coords_output = ""; foreach($_polygon["coords"] as $_coords){ if($_coords_output != ""){$_coords_output.=",";} $_coords_output .= " new google.maps.LatLng(".$_coords["lat"].", ".$_coords["long"].") "; } $_output .= " polygonCoords".$this->map_id."[$polygon_id] = [".$_coords_output."]; polygon".$this->map_id."[$polygon_id] = new google.maps.Polygon({ paths: polygonCoords".$this->map_id."[$polygon_id] ".(($_polygon['color']!="")?", strokeColor: '".$_polygon['color']."'":"")." ".(($_polygon['opacity']!=0)?", strokeOpacity: ".$_polygon['opacity']."":"")." ".(($_polygon['weight']!=0)?", strokeWeight: ".$_polygon['weight']."":"")." ".(($_polygon['fill_color']!="")?", fillColor: '".$_polygon['fill_color']."'":"")." ".(($_polygon['fill_opacity']!=0)?", fillOpacity: ".$_polygon['fill_opacity']."":"")." }); polygon".$this->map_id."[$polygon_id].setMap(map".$this->map_id."); "; } return $_output; }
[ "function", "getPolygonJS", "(", ")", "{", "$", "_output", "=", "''", ";", "foreach", "(", "$", "this", "->", "_polygons", "as", "$", "polygon_id", "=>", "$", "_polygon", ")", "{", "$", "_coords_output", "=", "\"\"", ";", "foreach", "(", "$", "_polygon", "[", "\"coords\"", "]", "as", "$", "_coords", ")", "{", "if", "(", "$", "_coords_output", "!=", "\"\"", ")", "{", "$", "_coords_output", ".=", "\",\"", ";", "}", "$", "_coords_output", ".=", "\"\n \t\t new google.maps.LatLng(\"", ".", "$", "_coords", "[", "\"lat\"", "]", ".", "\", \"", ".", "$", "_coords", "[", "\"long\"", "]", ".", "\")\n \t\t\"", ";", "}", "$", "_output", ".=", "\"\n \t polygonCoords\"", ".", "$", "this", "->", "map_id", ".", "\"[$polygon_id] = [\"", ".", "$", "_coords_output", ".", "\"]; \t\n\t\t\t polygon\"", ".", "$", "this", "->", "map_id", ".", "\"[$polygon_id] = new google.maps.Polygon({\n\t\t\t\t paths: polygonCoords\"", ".", "$", "this", "->", "map_id", ".", "\"[$polygon_id]\n\t\t\t\t \"", ".", "(", "(", "$", "_polygon", "[", "'color'", "]", "!=", "\"\"", ")", "?", "\", strokeColor: '\"", ".", "$", "_polygon", "[", "'color'", "]", ".", "\"'\"", ":", "\"\"", ")", ".", "\"\n\t\t\t\t \"", ".", "(", "(", "$", "_polygon", "[", "'opacity'", "]", "!=", "0", ")", "?", "\", strokeOpacity: \"", ".", "$", "_polygon", "[", "'opacity'", "]", ".", "\"\"", ":", "\"\"", ")", ".", "\"\n\t\t\t\t \"", ".", "(", "(", "$", "_polygon", "[", "'weight'", "]", "!=", "0", ")", "?", "\", strokeWeight: \"", ".", "$", "_polygon", "[", "'weight'", "]", ".", "\"\"", ":", "\"\"", ")", ".", "\"\n\t\t\t\t \"", ".", "(", "(", "$", "_polygon", "[", "'fill_color'", "]", "!=", "\"\"", ")", "?", "\", fillColor: '\"", ".", "$", "_polygon", "[", "'fill_color'", "]", ".", "\"'\"", ":", "\"\"", ")", ".", "\"\n\t\t\t\t \"", ".", "(", "(", "$", "_polygon", "[", "'fill_opacity'", "]", "!=", "0", ")", "?", "\", fillOpacity: \"", ".", "$", "_polygon", "[", "'fill_opacity'", "]", ".", "\"\"", ":", "\"\"", ")", ".", "\"\n\t\t\t });\t\t\t\n\t\t\t polygon\"", ".", "$", "this", "->", "map_id", ".", "\"[$polygon_id].setMap(map\"", ".", "$", "this", "->", "map_id", ".", "\");\n \t\"", ";", "}", "return", "$", "_output", ";", "}" ]
#)MS overridable function to generate polyline js - for now can only be used on a map, not a streetview
[ "#", ")", "MS", "overridable", "function", "to", "generate", "polyline", "js", "-", "for", "now", "can", "only", "be", "used", "on", "a", "map", "not", "a", "streetview" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L2753-L2777
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.addPolygonByCoords
function addPolygonByCoords($lon1,$lat1,$lon2,$lat2,$id=false,$color='',$weight=0,$opacity=0,$fill_color='',$fill_opacity=0) { if($id !== false && isset($this->_polygons[$id]) && is_array($this->_polygons[$id])){ $_polygon = $this->_polygons[$id]; }else{ //only set color,weight,and opacity if new polyline $_polygon = array( "color"=>$color, "weight"=>$weight, "opacity"=>$opacity, "fill_color"=>$fill_color, "fill_opacity"=>$fill_opacity, ); } if(!isset($_polygon['coords']) || !is_array($_polygon['coords'])){ $_polygon['coords'] = array( "0"=> array("lat"=>$lat1, "long"=>$lon1), "1"=> array("lat"=>$lat2, "long"=>$lon2) ); }else{ $last_index = sizeof($_polygon['coords'])-1; //check if lat1/lon1 point is already on polyline if($_polygon['coords'][$last_index]["lat"] != $lat1 || $_polygon['coords'][$last_index]["long"] != $lon1){ $_polygon['coords'][] = array("lat"=>$lat1, "long"=>$lon1); } $_polygon['coords'][] = array("lat"=>$lat2, "long"=>$lon2); } if($id === false){ $this->_polygons[] = $_polygon; $id = count($this->_polygons) - 1; }else{ $this->_polygons[$id] = $_polygon; } $this->adjustCenterCoords($lon1,$lat1); $this->adjustCenterCoords($lon2,$lat2); // return index of polyline return $id; }
php
function addPolygonByCoords($lon1,$lat1,$lon2,$lat2,$id=false,$color='',$weight=0,$opacity=0,$fill_color='',$fill_opacity=0) { if($id !== false && isset($this->_polygons[$id]) && is_array($this->_polygons[$id])){ $_polygon = $this->_polygons[$id]; }else{ //only set color,weight,and opacity if new polyline $_polygon = array( "color"=>$color, "weight"=>$weight, "opacity"=>$opacity, "fill_color"=>$fill_color, "fill_opacity"=>$fill_opacity, ); } if(!isset($_polygon['coords']) || !is_array($_polygon['coords'])){ $_polygon['coords'] = array( "0"=> array("lat"=>$lat1, "long"=>$lon1), "1"=> array("lat"=>$lat2, "long"=>$lon2) ); }else{ $last_index = sizeof($_polygon['coords'])-1; //check if lat1/lon1 point is already on polyline if($_polygon['coords'][$last_index]["lat"] != $lat1 || $_polygon['coords'][$last_index]["long"] != $lon1){ $_polygon['coords'][] = array("lat"=>$lat1, "long"=>$lon1); } $_polygon['coords'][] = array("lat"=>$lat2, "long"=>$lon2); } if($id === false){ $this->_polygons[] = $_polygon; $id = count($this->_polygons) - 1; }else{ $this->_polygons[$id] = $_polygon; } $this->adjustCenterCoords($lon1,$lat1); $this->adjustCenterCoords($lon2,$lat2); // return index of polyline return $id; }
[ "function", "addPolygonByCoords", "(", "$", "lon1", ",", "$", "lat1", ",", "$", "lon2", ",", "$", "lat2", ",", "$", "id", "=", "false", ",", "$", "color", "=", "''", ",", "$", "weight", "=", "0", ",", "$", "opacity", "=", "0", ",", "$", "fill_color", "=", "''", ",", "$", "fill_opacity", "=", "0", ")", "{", "if", "(", "$", "id", "!==", "false", "&&", "isset", "(", "$", "this", "->", "_polygons", "[", "$", "id", "]", ")", "&&", "is_array", "(", "$", "this", "->", "_polygons", "[", "$", "id", "]", ")", ")", "{", "$", "_polygon", "=", "$", "this", "->", "_polygons", "[", "$", "id", "]", ";", "}", "else", "{", "//only set color,weight,and opacity if new polyline", "$", "_polygon", "=", "array", "(", "\"color\"", "=>", "$", "color", ",", "\"weight\"", "=>", "$", "weight", ",", "\"opacity\"", "=>", "$", "opacity", ",", "\"fill_color\"", "=>", "$", "fill_color", ",", "\"fill_opacity\"", "=>", "$", "fill_opacity", ",", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "_polygon", "[", "'coords'", "]", ")", "||", "!", "is_array", "(", "$", "_polygon", "[", "'coords'", "]", ")", ")", "{", "$", "_polygon", "[", "'coords'", "]", "=", "array", "(", "\"0\"", "=>", "array", "(", "\"lat\"", "=>", "$", "lat1", ",", "\"long\"", "=>", "$", "lon1", ")", ",", "\"1\"", "=>", "array", "(", "\"lat\"", "=>", "$", "lat2", ",", "\"long\"", "=>", "$", "lon2", ")", ")", ";", "}", "else", "{", "$", "last_index", "=", "sizeof", "(", "$", "_polygon", "[", "'coords'", "]", ")", "-", "1", ";", "//check if lat1/lon1 point is already on polyline", "if", "(", "$", "_polygon", "[", "'coords'", "]", "[", "$", "last_index", "]", "[", "\"lat\"", "]", "!=", "$", "lat1", "||", "$", "_polygon", "[", "'coords'", "]", "[", "$", "last_index", "]", "[", "\"long\"", "]", "!=", "$", "lon1", ")", "{", "$", "_polygon", "[", "'coords'", "]", "[", "]", "=", "array", "(", "\"lat\"", "=>", "$", "lat1", ",", "\"long\"", "=>", "$", "lon1", ")", ";", "}", "$", "_polygon", "[", "'coords'", "]", "[", "]", "=", "array", "(", "\"lat\"", "=>", "$", "lat2", ",", "\"long\"", "=>", "$", "lon2", ")", ";", "}", "if", "(", "$", "id", "===", "false", ")", "{", "$", "this", "->", "_polygons", "[", "]", "=", "$", "_polygon", ";", "$", "id", "=", "count", "(", "$", "this", "->", "_polygons", ")", "-", "1", ";", "}", "else", "{", "$", "this", "->", "_polygons", "[", "$", "id", "]", "=", "$", "_polygon", ";", "}", "$", "this", "->", "adjustCenterCoords", "(", "$", "lon1", ",", "$", "lat1", ")", ";", "$", "this", "->", "adjustCenterCoords", "(", "$", "lon2", ",", "$", "lat2", ")", ";", "// return index of polyline", "return", "$", "id", ";", "}" ]
#)MS adds a map polygon by map coordinates if color, weight and opacity are not defined, use the google maps defaults @param string $lon1 the map longitude to draw from @param string $lat1 the map latitude to draw from @param string $lon2 the map longitude to draw to @param string $lat2 the map latitude to draw to @param string $id An array id to use to append coordinates to a line @param string $color the color of the border line (format: #000000) @param string $weight the weight of the line in pixels @param string $opacity the border line opacity (percentage) @param string $fill_color the polygon color (format: #000000) @param string $fill_opacity the polygon opacity (percentage) @return string $id id of the created/updated polyline array
[ "#", ")", "MS", "adds", "a", "map", "polygon", "by", "map", "coordinates", "if", "color", "weight", "and", "opacity", "are", "not", "defined", "use", "the", "google", "maps", "defaults" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L2795-L2831
kossmoss/yii2-google-maps-api
src/GoogleMapAPI.php
GoogleMapAPI.addPolygonByCoordsArray
function addPolygonByCoordsArray($polygon_array,$id=false,$color='',$weight=0,$opacity=0,$fill_color='',$fill_opacity=0){ if(!is_array($polygon_array) || sizeof($polygon_array) < 3) return false; $_prev_coords = ""; $_next_coords = ""; foreach($polygon_array as $_coords){ $_prev_coords = $_next_coords; $_next_coords = $_coords; if($_prev_coords !== ""){ $_lt1=$_prev_coords["lat"]; $_ln1=$_prev_coords["long"]; $_lt2=$_next_coords["lat"]; $_ln2=$_next_coords["long"]; $id = $this->addPolygonByCoords($_ln1, $_lt1, $_ln2, $_lt2, $id, $color, $weight, $opacity, $fill_color, $fill_opacity); } } return $id; }
php
function addPolygonByCoordsArray($polygon_array,$id=false,$color='',$weight=0,$opacity=0,$fill_color='',$fill_opacity=0){ if(!is_array($polygon_array) || sizeof($polygon_array) < 3) return false; $_prev_coords = ""; $_next_coords = ""; foreach($polygon_array as $_coords){ $_prev_coords = $_next_coords; $_next_coords = $_coords; if($_prev_coords !== ""){ $_lt1=$_prev_coords["lat"]; $_ln1=$_prev_coords["long"]; $_lt2=$_next_coords["lat"]; $_ln2=$_next_coords["long"]; $id = $this->addPolygonByCoords($_ln1, $_lt1, $_ln2, $_lt2, $id, $color, $weight, $opacity, $fill_color, $fill_opacity); } } return $id; }
[ "function", "addPolygonByCoordsArray", "(", "$", "polygon_array", ",", "$", "id", "=", "false", ",", "$", "color", "=", "''", ",", "$", "weight", "=", "0", ",", "$", "opacity", "=", "0", ",", "$", "fill_color", "=", "''", ",", "$", "fill_opacity", "=", "0", ")", "{", "if", "(", "!", "is_array", "(", "$", "polygon_array", ")", "||", "sizeof", "(", "$", "polygon_array", ")", "<", "3", ")", "return", "false", ";", "$", "_prev_coords", "=", "\"\"", ";", "$", "_next_coords", "=", "\"\"", ";", "foreach", "(", "$", "polygon_array", "as", "$", "_coords", ")", "{", "$", "_prev_coords", "=", "$", "_next_coords", ";", "$", "_next_coords", "=", "$", "_coords", ";", "if", "(", "$", "_prev_coords", "!==", "\"\"", ")", "{", "$", "_lt1", "=", "$", "_prev_coords", "[", "\"lat\"", "]", ";", "$", "_ln1", "=", "$", "_prev_coords", "[", "\"long\"", "]", ";", "$", "_lt2", "=", "$", "_next_coords", "[", "\"lat\"", "]", ";", "$", "_ln2", "=", "$", "_next_coords", "[", "\"long\"", "]", ";", "$", "id", "=", "$", "this", "->", "addPolygonByCoords", "(", "$", "_ln1", ",", "$", "_lt1", ",", "$", "_ln2", ",", "$", "_lt2", ",", "$", "id", ",", "$", "color", ",", "$", "weight", ",", "$", "opacity", ",", "$", "fill_color", ",", "$", "fill_opacity", ")", ";", "}", "}", "return", "$", "id", ";", "}" ]
#)MS adds polyline by passed array if color, weight and opacity are not defined, use the google maps defaults @param array $polyline_array array of lat/long coords @param string $id An array id to use to append coordinates to a line @param string $color the color of the line (format: #000000) @param string $weight the weight of the line in pixels @param string $opacity the line opacity (percentage) @param string $fill_color the polygon color (format: #000000) @param string $fill_opacity the polygon opacity (percentage) @return bool|int Array id of newly added point or false
[ "#", ")", "MS", "adds", "polyline", "by", "passed", "array", "if", "color", "weight", "and", "opacity", "are", "not", "defined", "use", "the", "google", "maps", "defaults" ]
train
https://github.com/kossmoss/yii2-google-maps-api/blob/8a994c173031d7ece3cfedd30b971258616579d2/src/GoogleMapAPI.php#L2845-L2864
mothership-ec/composer
src/Composer/Downloader/HgDownloader.php
HgDownloader.doDownload
public function doDownload(PackageInterface $package, $path, $url) { $url = ProcessExecutor::escape($url); $ref = ProcessExecutor::escape($package->getSourceReference()); $this->io->writeError(" Cloning ".$package->getSourceReference()); $command = sprintf('hg clone %s %s', $url, ProcessExecutor::escape($path)); if (0 !== $this->process->execute($command, $ignoredOutput)) { throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); } $command = sprintf('hg up %s', $ref); if (0 !== $this->process->execute($command, $ignoredOutput, realpath($path))) { throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); } }
php
public function doDownload(PackageInterface $package, $path, $url) { $url = ProcessExecutor::escape($url); $ref = ProcessExecutor::escape($package->getSourceReference()); $this->io->writeError(" Cloning ".$package->getSourceReference()); $command = sprintf('hg clone %s %s', $url, ProcessExecutor::escape($path)); if (0 !== $this->process->execute($command, $ignoredOutput)) { throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); } $command = sprintf('hg up %s', $ref); if (0 !== $this->process->execute($command, $ignoredOutput, realpath($path))) { throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); } }
[ "public", "function", "doDownload", "(", "PackageInterface", "$", "package", ",", "$", "path", ",", "$", "url", ")", "{", "$", "url", "=", "ProcessExecutor", "::", "escape", "(", "$", "url", ")", ";", "$", "ref", "=", "ProcessExecutor", "::", "escape", "(", "$", "package", "->", "getSourceReference", "(", ")", ")", ";", "$", "this", "->", "io", "->", "writeError", "(", "\" Cloning \"", ".", "$", "package", "->", "getSourceReference", "(", ")", ")", ";", "$", "command", "=", "sprintf", "(", "'hg clone %s %s'", ",", "$", "url", ",", "ProcessExecutor", "::", "escape", "(", "$", "path", ")", ")", ";", "if", "(", "0", "!==", "$", "this", "->", "process", "->", "execute", "(", "$", "command", ",", "$", "ignoredOutput", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Failed to execute '", ".", "$", "command", ".", "\"\\n\\n\"", ".", "$", "this", "->", "process", "->", "getErrorOutput", "(", ")", ")", ";", "}", "$", "command", "=", "sprintf", "(", "'hg up %s'", ",", "$", "ref", ")", ";", "if", "(", "0", "!==", "$", "this", "->", "process", "->", "execute", "(", "$", "command", ",", "$", "ignoredOutput", ",", "realpath", "(", "$", "path", ")", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Failed to execute '", ".", "$", "command", ".", "\"\\n\\n\"", ".", "$", "this", "->", "process", "->", "getErrorOutput", "(", ")", ")", ";", "}", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Downloader/HgDownloader.php#L26-L39
mothership-ec/composer
src/Composer/Downloader/HgDownloader.php
HgDownloader.doUpdate
public function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url) { $url = ProcessExecutor::escape($url); $ref = ProcessExecutor::escape($target->getSourceReference()); $this->io->writeError(" Updating to ".$target->getSourceReference()); if (!is_dir($path.'/.hg')) { throw new \RuntimeException('The .hg directory is missing from '.$path.', see https://getcomposer.org/commit-deps for more information'); } $command = sprintf('hg pull %s && hg up %s', $url, $ref); if (0 !== $this->process->execute($command, $ignoredOutput, realpath($path))) { throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); } }
php
public function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url) { $url = ProcessExecutor::escape($url); $ref = ProcessExecutor::escape($target->getSourceReference()); $this->io->writeError(" Updating to ".$target->getSourceReference()); if (!is_dir($path.'/.hg')) { throw new \RuntimeException('The .hg directory is missing from '.$path.', see https://getcomposer.org/commit-deps for more information'); } $command = sprintf('hg pull %s && hg up %s', $url, $ref); if (0 !== $this->process->execute($command, $ignoredOutput, realpath($path))) { throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); } }
[ "public", "function", "doUpdate", "(", "PackageInterface", "$", "initial", ",", "PackageInterface", "$", "target", ",", "$", "path", ",", "$", "url", ")", "{", "$", "url", "=", "ProcessExecutor", "::", "escape", "(", "$", "url", ")", ";", "$", "ref", "=", "ProcessExecutor", "::", "escape", "(", "$", "target", "->", "getSourceReference", "(", ")", ")", ";", "$", "this", "->", "io", "->", "writeError", "(", "\" Updating to \"", ".", "$", "target", "->", "getSourceReference", "(", ")", ")", ";", "if", "(", "!", "is_dir", "(", "$", "path", ".", "'/.hg'", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'The .hg directory is missing from '", ".", "$", "path", ".", "', see https://getcomposer.org/commit-deps for more information'", ")", ";", "}", "$", "command", "=", "sprintf", "(", "'hg pull %s && hg up %s'", ",", "$", "url", ",", "$", "ref", ")", ";", "if", "(", "0", "!==", "$", "this", "->", "process", "->", "execute", "(", "$", "command", ",", "$", "ignoredOutput", ",", "realpath", "(", "$", "path", ")", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Failed to execute '", ".", "$", "command", ".", "\"\\n\\n\"", ".", "$", "this", "->", "process", "->", "getErrorOutput", "(", ")", ")", ";", "}", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Downloader/HgDownloader.php#L44-L58
NuclearCMS/Hierarchy
src/NodeRepository.php
NodeRepository.getHome
public function getHome($track = true) { $home = PublishedNode::whereHome(1) ->firstOrFail(); $this->track($track, $home); return $home; }
php
public function getHome($track = true) { $home = PublishedNode::whereHome(1) ->firstOrFail(); $this->track($track, $home); return $home; }
[ "public", "function", "getHome", "(", "$", "track", "=", "true", ")", "{", "$", "home", "=", "PublishedNode", "::", "whereHome", "(", "1", ")", "->", "firstOrFail", "(", ")", ";", "$", "this", "->", "track", "(", "$", "track", ",", "$", "home", ")", ";", "return", "$", "home", ";", "}" ]
Returns the home node @param bool $track @return Node
[ "Returns", "the", "home", "node" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/NodeRepository.php#L29-L37
NuclearCMS/Hierarchy
src/NodeRepository.php
NodeRepository.getNode
public function getNode($name, $track = true, $published = true) { if ($this->withPublishedOnly($published)) { $node = PublishedNode::withName($name); } else { $node = Node::withName($name); } $node = $node->firstOrFail(); $this->track($track, $node); return $node; }
php
public function getNode($name, $track = true, $published = true) { if ($this->withPublishedOnly($published)) { $node = PublishedNode::withName($name); } else { $node = Node::withName($name); } $node = $node->firstOrFail(); $this->track($track, $node); return $node; }
[ "public", "function", "getNode", "(", "$", "name", ",", "$", "track", "=", "true", ",", "$", "published", "=", "true", ")", "{", "if", "(", "$", "this", "->", "withPublishedOnly", "(", "$", "published", ")", ")", "{", "$", "node", "=", "PublishedNode", "::", "withName", "(", "$", "name", ")", ";", "}", "else", "{", "$", "node", "=", "Node", "::", "withName", "(", "$", "name", ")", ";", "}", "$", "node", "=", "$", "node", "->", "firstOrFail", "(", ")", ";", "$", "this", "->", "track", "(", "$", "track", ",", "$", "node", ")", ";", "return", "$", "node", ";", "}" ]
Returns a node by name @param string $name @param bool $track @param bool $published @return Node
[ "Returns", "a", "node", "by", "name" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/NodeRepository.php#L47-L62
NuclearCMS/Hierarchy
src/NodeRepository.php
NodeRepository.withPublishedOnly
protected function withPublishedOnly($published) { if ($published === false) { return false; } if ($this->tokenManager->requestHasToken('preview_nodes')) { return false; } return true; }
php
protected function withPublishedOnly($published) { if ($published === false) { return false; } if ($this->tokenManager->requestHasToken('preview_nodes')) { return false; } return true; }
[ "protected", "function", "withPublishedOnly", "(", "$", "published", ")", "{", "if", "(", "$", "published", "===", "false", ")", "{", "return", "false", ";", "}", "if", "(", "$", "this", "->", "tokenManager", "->", "requestHasToken", "(", "'preview_nodes'", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Checks if the request includes unpublished nodes as well @param bool $published @return bool
[ "Checks", "if", "the", "request", "includes", "unpublished", "nodes", "as", "well" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/NodeRepository.php#L70-L83
NuclearCMS/Hierarchy
src/NodeRepository.php
NodeRepository.getNodeAndSetLocale
public function getNodeAndSetLocale($name, $track = true, $published = true) { $node = $this->getNode($name, $track, $published); $locale = $node->getLocaleForNodeName($name); set_app_locale($locale); return $node; }
php
public function getNodeAndSetLocale($name, $track = true, $published = true) { $node = $this->getNode($name, $track, $published); $locale = $node->getLocaleForNodeName($name); set_app_locale($locale); return $node; }
[ "public", "function", "getNodeAndSetLocale", "(", "$", "name", ",", "$", "track", "=", "true", ",", "$", "published", "=", "true", ")", "{", "$", "node", "=", "$", "this", "->", "getNode", "(", "$", "name", ",", "$", "track", ",", "$", "published", ")", ";", "$", "locale", "=", "$", "node", "->", "getLocaleForNodeName", "(", "$", "name", ")", ";", "set_app_locale", "(", "$", "locale", ")", ";", "return", "$", "node", ";", "}" ]
Returns a node by name and sets the locale @param string $name @param bool $track @param bool $published @return Node
[ "Returns", "a", "node", "by", "name", "and", "sets", "the", "locale" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/NodeRepository.php#L93-L102
NuclearCMS/Hierarchy
src/NodeRepository.php
NodeRepository.getSearchNodeBuilder
public function getSearchNodeBuilder($keywords, $type = null, $limit = null, $locale = null) { // Because of the searchable trait we have to reset global scopes $builder = PublishedNode::withoutGlobalScopes() ->published() ->typeMailing() ->translatedIn($locale) ->groupBy('nodes.id'); if ($type) { $builder->withType($type); } if ($limit) { $builder->limit($limit); } $builder->search($keywords, 20, true); return $builder; }
php
public function getSearchNodeBuilder($keywords, $type = null, $limit = null, $locale = null) { // Because of the searchable trait we have to reset global scopes $builder = PublishedNode::withoutGlobalScopes() ->published() ->typeMailing() ->translatedIn($locale) ->groupBy('nodes.id'); if ($type) { $builder->withType($type); } if ($limit) { $builder->limit($limit); } $builder->search($keywords, 20, true); return $builder; }
[ "public", "function", "getSearchNodeBuilder", "(", "$", "keywords", ",", "$", "type", "=", "null", ",", "$", "limit", "=", "null", ",", "$", "locale", "=", "null", ")", "{", "// Because of the searchable trait we have to reset global scopes", "$", "builder", "=", "PublishedNode", "::", "withoutGlobalScopes", "(", ")", "->", "published", "(", ")", "->", "typeMailing", "(", ")", "->", "translatedIn", "(", "$", "locale", ")", "->", "groupBy", "(", "'nodes.id'", ")", ";", "if", "(", "$", "type", ")", "{", "$", "builder", "->", "withType", "(", "$", "type", ")", ";", "}", "if", "(", "$", "limit", ")", "{", "$", "builder", "->", "limit", "(", "$", "limit", ")", ";", "}", "$", "builder", "->", "search", "(", "$", "keywords", ",", "20", ",", "true", ")", ";", "return", "$", "builder", ";", "}" ]
Gets node searching builder @param string $keywords @param string $type @param int $limit @param string $locale @return Builder
[ "Gets", "node", "searching", "builder" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/NodeRepository.php#L113-L135
NuclearCMS/Hierarchy
src/NodeRepository.php
NodeRepository.searchNodes
public function searchNodes($keywords, $type = null, $limit = null, $locale = null) { return $this->getSearchNodeBuilder($keywords, $type, $limit, $locale)->get(); }
php
public function searchNodes($keywords, $type = null, $limit = null, $locale = null) { return $this->getSearchNodeBuilder($keywords, $type, $limit, $locale)->get(); }
[ "public", "function", "searchNodes", "(", "$", "keywords", ",", "$", "type", "=", "null", ",", "$", "limit", "=", "null", ",", "$", "locale", "=", "null", ")", "{", "return", "$", "this", "->", "getSearchNodeBuilder", "(", "$", "keywords", ",", "$", "type", ",", "$", "limit", ",", "$", "locale", ")", "->", "get", "(", ")", ";", "}" ]
Searches for nodes @param string $keywords @param string $type @param int $limit @param string $locale @return Collection
[ "Searches", "for", "nodes" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/NodeRepository.php#L146-L149
NuclearCMS/Hierarchy
src/NodeRepository.php
NodeRepository.getSortedNodesBuilder
public function getSortedNodesBuilder($key = null, $direction = null, $type = null, $limit = null, $locale = null) { $builder = PublishedNode::translatedIn($locale) ->groupBy('nodes.id'); if ($type) { $builder->withType($type); } if ($limit) { $builder->limit($limit); } return $builder->sortable($key, $direction); }
php
public function getSortedNodesBuilder($key = null, $direction = null, $type = null, $limit = null, $locale = null) { $builder = PublishedNode::translatedIn($locale) ->groupBy('nodes.id'); if ($type) { $builder->withType($type); } if ($limit) { $builder->limit($limit); } return $builder->sortable($key, $direction); }
[ "public", "function", "getSortedNodesBuilder", "(", "$", "key", "=", "null", ",", "$", "direction", "=", "null", ",", "$", "type", "=", "null", ",", "$", "limit", "=", "null", ",", "$", "locale", "=", "null", ")", "{", "$", "builder", "=", "PublishedNode", "::", "translatedIn", "(", "$", "locale", ")", "->", "groupBy", "(", "'nodes.id'", ")", ";", "if", "(", "$", "type", ")", "{", "$", "builder", "->", "withType", "(", "$", "type", ")", ";", "}", "if", "(", "$", "limit", ")", "{", "$", "builder", "->", "limit", "(", "$", "limit", ")", ";", "}", "return", "$", "builder", "->", "sortable", "(", "$", "key", ",", "$", "direction", ")", ";", "}" ]
Gets node sortable builder @param string $key @param string $direction @param string $type @param int $limit @param string $locale @return Builder
[ "Gets", "node", "sortable", "builder" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/NodeRepository.php#L161-L177
NuclearCMS/Hierarchy
src/NodeRepository.php
NodeRepository.getSortedNodes
public function getSortedNodes($key = null, $direction = null, $type = null, $limit = null, $locale = null) { return $this->getSortedNodesBuilder($key, $direction, $type, $limit, $locale)->paginate(); }
php
public function getSortedNodes($key = null, $direction = null, $type = null, $limit = null, $locale = null) { return $this->getSortedNodesBuilder($key, $direction, $type, $limit, $locale)->paginate(); }
[ "public", "function", "getSortedNodes", "(", "$", "key", "=", "null", ",", "$", "direction", "=", "null", ",", "$", "type", "=", "null", ",", "$", "limit", "=", "null", ",", "$", "locale", "=", "null", ")", "{", "return", "$", "this", "->", "getSortedNodesBuilder", "(", "$", "key", ",", "$", "direction", ",", "$", "type", ",", "$", "limit", ",", "$", "locale", ")", "->", "paginate", "(", ")", ";", "}" ]
Gets sorted nodes @param string $key @param string $direction @param string $type @param int $limit @param string $locale @return Collection
[ "Gets", "sorted", "nodes" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/NodeRepository.php#L189-L192
NuclearCMS/Hierarchy
src/NodeRepository.php
NodeRepository.getNodeById
public function getNodeById($id, $published) { return $published ? PublishedNode::find($id) : Node::find($id); }
php
public function getNodeById($id, $published) { return $published ? PublishedNode::find($id) : Node::find($id); }
[ "public", "function", "getNodeById", "(", "$", "id", ",", "$", "published", ")", "{", "return", "$", "published", "?", "PublishedNode", "::", "find", "(", "$", "id", ")", ":", "Node", "::", "find", "(", "$", "id", ")", ";", "}" ]
Returns a node by id @param int $id @param bool $published @return Node
[ "Returns", "a", "node", "by", "id" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/NodeRepository.php#L201-L204
NuclearCMS/Hierarchy
src/NodeRepository.php
NodeRepository.getNodesByIds
public function getNodesByIds($ids, $published = true) { if (empty($ids)) { return null; } if (is_string($ids)) { $ids = json_decode($ids, true); } if (is_array($ids) && ! empty($ids)) { $placeholders = implode(',', array_fill(0, count($ids), '?')); $nodes = Node::whereIn('id', $ids) ->orderByRaw('field(id,' . $placeholders . ')', $ids); if ($published) { $nodes->published(); } $nodes = $nodes->get(); return (count($nodes) > 0) ? $nodes : null; } return null; }
php
public function getNodesByIds($ids, $published = true) { if (empty($ids)) { return null; } if (is_string($ids)) { $ids = json_decode($ids, true); } if (is_array($ids) && ! empty($ids)) { $placeholders = implode(',', array_fill(0, count($ids), '?')); $nodes = Node::whereIn('id', $ids) ->orderByRaw('field(id,' . $placeholders . ')', $ids); if ($published) { $nodes->published(); } $nodes = $nodes->get(); return (count($nodes) > 0) ? $nodes : null; } return null; }
[ "public", "function", "getNodesByIds", "(", "$", "ids", ",", "$", "published", "=", "true", ")", "{", "if", "(", "empty", "(", "$", "ids", ")", ")", "{", "return", "null", ";", "}", "if", "(", "is_string", "(", "$", "ids", ")", ")", "{", "$", "ids", "=", "json_decode", "(", "$", "ids", ",", "true", ")", ";", "}", "if", "(", "is_array", "(", "$", "ids", ")", "&&", "!", "empty", "(", "$", "ids", ")", ")", "{", "$", "placeholders", "=", "implode", "(", "','", ",", "array_fill", "(", "0", ",", "count", "(", "$", "ids", ")", ",", "'?'", ")", ")", ";", "$", "nodes", "=", "Node", "::", "whereIn", "(", "'id'", ",", "$", "ids", ")", "->", "orderByRaw", "(", "'field(id,'", ".", "$", "placeholders", ".", "')'", ",", "$", "ids", ")", ";", "if", "(", "$", "published", ")", "{", "$", "nodes", "->", "published", "(", ")", ";", "}", "$", "nodes", "=", "$", "nodes", "->", "get", "(", ")", ";", "return", "(", "count", "(", "$", "nodes", ")", ">", "0", ")", "?", "$", "nodes", ":", "null", ";", "}", "return", "null", ";", "}" ]
Returns nodes by ids @param array|string $ids @param bool $published @return Collection
[ "Returns", "nodes", "by", "ids" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/NodeRepository.php#L213-L243
codezero-be/curl
src/Curl.php
Curl.initialize
public function initialize() { if ($this->isInitialized()) { $this->close(); } if ( ! ($this->curl = curl_init())) { throw new CurlException('Could not initialize a cURL resource'); } return true; }
php
public function initialize() { if ($this->isInitialized()) { $this->close(); } if ( ! ($this->curl = curl_init())) { throw new CurlException('Could not initialize a cURL resource'); } return true; }
[ "public", "function", "initialize", "(", ")", "{", "if", "(", "$", "this", "->", "isInitialized", "(", ")", ")", "{", "$", "this", "->", "close", "(", ")", ";", "}", "if", "(", "!", "(", "$", "this", "->", "curl", "=", "curl_init", "(", ")", ")", ")", "{", "throw", "new", "CurlException", "(", "'Could not initialize a cURL resource'", ")", ";", "}", "return", "true", ";", "}" ]
Initialize a new cURL resource @return bool @throws CurlException
[ "Initialize", "a", "new", "cURL", "resource" ]
train
https://github.com/codezero-be/curl/blob/c1385479886662b6276c18dd9140df529959d95c/src/Curl.php#L38-L51
codezero-be/curl
src/Curl.php
Curl.setOption
public function setOption($option, $value) { $this->autoInitialize(); return curl_setopt($this->curl, $option, $value); }
php
public function setOption($option, $value) { $this->autoInitialize(); return curl_setopt($this->curl, $option, $value); }
[ "public", "function", "setOption", "(", "$", "option", ",", "$", "value", ")", "{", "$", "this", "->", "autoInitialize", "(", ")", ";", "return", "curl_setopt", "(", "$", "this", "->", "curl", ",", "$", "option", ",", "$", "value", ")", ";", "}" ]
Set cURL option @param int $option @param mixed $value @return bool @throws CurlException
[ "Set", "cURL", "option" ]
train
https://github.com/codezero-be/curl/blob/c1385479886662b6276c18dd9140df529959d95c/src/Curl.php#L72-L77
codezero-be/curl
src/Curl.php
Curl.sendRequest
public function sendRequest(array $options = []) { $this->autoInitialize(); if ( ! empty($options)) { if ( ! $this->setOptions($options)) { return false; } } $this->response = curl_exec($this->curl); return $this->response; }
php
public function sendRequest(array $options = []) { $this->autoInitialize(); if ( ! empty($options)) { if ( ! $this->setOptions($options)) { return false; } } $this->response = curl_exec($this->curl); return $this->response; }
[ "public", "function", "sendRequest", "(", "array", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "autoInitialize", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "options", ")", ")", "{", "if", "(", "!", "$", "this", "->", "setOptions", "(", "$", "options", ")", ")", "{", "return", "false", ";", "}", "}", "$", "this", "->", "response", "=", "curl_exec", "(", "$", "this", "->", "curl", ")", ";", "return", "$", "this", "->", "response", ";", "}" ]
Send the cURL request (will initialize if needed and set options if provided) !!! Options that have already been set are not automatically reset !!! @param array $options @return bool|string @throws CurlException
[ "Send", "the", "cURL", "request", "(", "will", "initialize", "if", "needed", "and", "set", "options", "if", "provided", ")" ]
train
https://github.com/codezero-be/curl/blob/c1385479886662b6276c18dd9140df529959d95c/src/Curl.php#L104-L119
codezero-be/curl
src/Curl.php
Curl.getRequestInfo
public function getRequestInfo($key = null) { if ( ! $this->isInitialized()) { return $key ? '' : []; } return $key ? curl_getinfo($this->curl, $key) : curl_getinfo($this->curl); }
php
public function getRequestInfo($key = null) { if ( ! $this->isInitialized()) { return $key ? '' : []; } return $key ? curl_getinfo($this->curl, $key) : curl_getinfo($this->curl); }
[ "public", "function", "getRequestInfo", "(", "$", "key", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "isInitialized", "(", ")", ")", "{", "return", "$", "key", "?", "''", ":", "[", "]", ";", "}", "return", "$", "key", "?", "curl_getinfo", "(", "$", "this", "->", "curl", ",", "$", "key", ")", ":", "curl_getinfo", "(", "$", "this", "->", "curl", ")", ";", "}" ]
Get additional information about the last cURL request @param string $key @return string|array
[ "Get", "additional", "information", "about", "the", "last", "cURL", "request" ]
train
https://github.com/codezero-be/curl/blob/c1385479886662b6276c18dd9140df529959d95c/src/Curl.php#L138-L146
codezero-be/curl
src/Curl.php
Curl.reset
public function reset() { if ( ! $this->isInitialized() || ! function_exists('curl_reset')) { $this->initialize(); } else { // PHP >= 5.5.0 curl_reset($this->curl); $this->response = null; } }
php
public function reset() { if ( ! $this->isInitialized() || ! function_exists('curl_reset')) { $this->initialize(); } else { // PHP >= 5.5.0 curl_reset($this->curl); $this->response = null; } }
[ "public", "function", "reset", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isInitialized", "(", ")", "||", "!", "function_exists", "(", "'curl_reset'", ")", ")", "{", "$", "this", "->", "initialize", "(", ")", ";", "}", "else", "{", "// PHP >= 5.5.0", "curl_reset", "(", "$", "this", "->", "curl", ")", ";", "$", "this", "->", "response", "=", "null", ";", "}", "}" ]
Reset all cURL options @return void @throws CurlException
[ "Reset", "all", "cURL", "options" ]
train
https://github.com/codezero-be/curl/blob/c1385479886662b6276c18dd9140df529959d95c/src/Curl.php#L216-L229
codezero-be/curl
src/Curl.php
Curl.close
public function close() { if ($this->isInitialized()) { curl_close($this->curl); $this->curl = null; $this->response = null; } }
php
public function close() { if ($this->isInitialized()) { curl_close($this->curl); $this->curl = null; $this->response = null; } }
[ "public", "function", "close", "(", ")", "{", "if", "(", "$", "this", "->", "isInitialized", "(", ")", ")", "{", "curl_close", "(", "$", "this", "->", "curl", ")", ";", "$", "this", "->", "curl", "=", "null", ";", "$", "this", "->", "response", "=", "null", ";", "}", "}" ]
Close the cURL resource @return void
[ "Close", "the", "cURL", "resource" ]
train
https://github.com/codezero-be/curl/blob/c1385479886662b6276c18dd9140df529959d95c/src/Curl.php#L236-L245
codezero-be/curl
src/Curl.php
Curl.parseUrl
private function parseUrl($string, $decode) { $this->autoInitialize(); $function = $decode ? 'curl_unescape' : 'curl_escape'; if ( ! function_exists($function)) { return $decode ? rawurldecode($string) : rawurlencode($string); } // PHP >= 5.5.0 return call_user_func($function, $this->curl, $string); }
php
private function parseUrl($string, $decode) { $this->autoInitialize(); $function = $decode ? 'curl_unescape' : 'curl_escape'; if ( ! function_exists($function)) { return $decode ? rawurldecode($string) : rawurlencode($string); } // PHP >= 5.5.0 return call_user_func($function, $this->curl, $string); }
[ "private", "function", "parseUrl", "(", "$", "string", ",", "$", "decode", ")", "{", "$", "this", "->", "autoInitialize", "(", ")", ";", "$", "function", "=", "$", "decode", "?", "'curl_unescape'", ":", "'curl_escape'", ";", "if", "(", "!", "function_exists", "(", "$", "function", ")", ")", "{", "return", "$", "decode", "?", "rawurldecode", "(", "$", "string", ")", ":", "rawurlencode", "(", "$", "string", ")", ";", "}", "// PHP >= 5.5.0", "return", "call_user_func", "(", "$", "function", ",", "$", "this", "->", "curl", ",", "$", "string", ")", ";", "}" ]
Encode or decode a URL @param string $string @param bool $decode @return bool|string
[ "Encode", "or", "decode", "a", "URL" ]
train
https://github.com/codezero-be/curl/blob/c1385479886662b6276c18dd9140df529959d95c/src/Curl.php#L286-L299
josegonzalez/cakephp-sanction
Model/Behavior/PermitBehavior.php
PermitBehavior.setup
public function setup(Model $Model, $settings = array()) { if (!isset($this->settings[$Model->alias])) { $this->settings[$Model->alias] = array( 'message' => sprintf('You do not have permission to view this %s ', strtolower(Inflector::humanize($Model->alias)) ), 'check' => false, 'value' => true, 'field' => $Model->alias . '.user_id', 'skip' => true, 'rules' => array(), ); } $this->settings[$Model->alias] = array_merge($this->settings[$Model->alias], $settings); $this->modelDefaults[$Model->alias] = $this->settings[$Model->alias]; }
php
public function setup(Model $Model, $settings = array()) { if (!isset($this->settings[$Model->alias])) { $this->settings[$Model->alias] = array( 'message' => sprintf('You do not have permission to view this %s ', strtolower(Inflector::humanize($Model->alias)) ), 'check' => false, 'value' => true, 'field' => $Model->alias . '.user_id', 'skip' => true, 'rules' => array(), ); } $this->settings[$Model->alias] = array_merge($this->settings[$Model->alias], $settings); $this->modelDefaults[$Model->alias] = $this->settings[$Model->alias]; }
[ "public", "function", "setup", "(", "Model", "$", "Model", ",", "$", "settings", "=", "array", "(", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "settings", "[", "$", "Model", "->", "alias", "]", ")", ")", "{", "$", "this", "->", "settings", "[", "$", "Model", "->", "alias", "]", "=", "array", "(", "'message'", "=>", "sprintf", "(", "'You do not have permission to view this %s '", ",", "strtolower", "(", "Inflector", "::", "humanize", "(", "$", "Model", "->", "alias", ")", ")", ")", ",", "'check'", "=>", "false", ",", "'value'", "=>", "true", ",", "'field'", "=>", "$", "Model", "->", "alias", ".", "'.user_id'", ",", "'skip'", "=>", "true", ",", "'rules'", "=>", "array", "(", ")", ",", ")", ";", "}", "$", "this", "->", "settings", "[", "$", "Model", "->", "alias", "]", "=", "array_merge", "(", "$", "this", "->", "settings", "[", "$", "Model", "->", "alias", "]", ",", "$", "settings", ")", ";", "$", "this", "->", "modelDefaults", "[", "$", "Model", "->", "alias", "]", "=", "$", "this", "->", "settings", "[", "$", "Model", "->", "alias", "]", ";", "}" ]
Initiate behavior for the model using specified settings. Available settings: - message: (string, optional) A message to display to the user when they do not have access to the model record. DEFAULTS TO: "You do not have permission to view this %ModelAlias%" - check: (string, optional) optional admin override for returning the results when the user_id does not match the current user. DEFAULTS TO: false - value: (mixed, optional) The value the check should resolve to. DEFAULTS TO: true - field: (string, optional) A `Hash::get()`-compatible string for retrieving the from the current record user_id. DEFAULTS TO: %ModelAlias%.user_id - skip: (boolean, optional) Whether to skip rule checking. DEFAULTS TO: true - rules: (array, optional) If `permit` is set in a `Model::find()`, this key will be used to make an index lookup for rules to apply to this find. DEFAULTS TO: empty array @param Model $Model Model using the behavior @param array $settings Settings to override for model. @return void
[ "Initiate", "behavior", "for", "the", "model", "using", "specified", "settings", "." ]
train
https://github.com/josegonzalez/cakephp-sanction/blob/df2a8f0c0602c0ace802773db2c2ca6c89555c47/Model/Behavior/PermitBehavior.php#L38-L53
josegonzalez/cakephp-sanction
Model/Behavior/PermitBehavior.php
PermitBehavior.beforeFind
public function beforeFind(Model $Model, $query) { $this->settings[$Model->alias] = $this->modelDefaults[$Model->alias]; // check if $this->modelDefaultsPersist has been set if (isset($this->modelDefaultsPersist[$Model->alias])) { // if persist equals equals true if (!isset($this->modelDefaults[$Model->alias]['persist']) || $this->modelDefaults[$Model->alias]['persist'] == false) { $this->modelDefaults[$Model->alias] = $this->modelDefaultsPersist[$Model->alias]; } } if (isset($query['permit']) && isset($this->settings[$Model->alias]['rules'][$query['permit']])) { $rules = $this->settings[$Model->alias]['rules'][$query['permit']]; if (isset($rules['rules'])) { unset($rules['rules']); } $this->settings[$Model->alias] = array_merge($this->settings[$Model->alias], $rules); } foreach (array('message', 'check', 'value', 'field', 'skip', 'rules') as $key) { if (isset($query['permit_' . $key])) { $this->settings[$Model->alias][$key] = $query['permit_' . $key]; } } return $query; }
php
public function beforeFind(Model $Model, $query) { $this->settings[$Model->alias] = $this->modelDefaults[$Model->alias]; // check if $this->modelDefaultsPersist has been set if (isset($this->modelDefaultsPersist[$Model->alias])) { // if persist equals equals true if (!isset($this->modelDefaults[$Model->alias]['persist']) || $this->modelDefaults[$Model->alias]['persist'] == false) { $this->modelDefaults[$Model->alias] = $this->modelDefaultsPersist[$Model->alias]; } } if (isset($query['permit']) && isset($this->settings[$Model->alias]['rules'][$query['permit']])) { $rules = $this->settings[$Model->alias]['rules'][$query['permit']]; if (isset($rules['rules'])) { unset($rules['rules']); } $this->settings[$Model->alias] = array_merge($this->settings[$Model->alias], $rules); } foreach (array('message', 'check', 'value', 'field', 'skip', 'rules') as $key) { if (isset($query['permit_' . $key])) { $this->settings[$Model->alias][$key] = $query['permit_' . $key]; } } return $query; }
[ "public", "function", "beforeFind", "(", "Model", "$", "Model", ",", "$", "query", ")", "{", "$", "this", "->", "settings", "[", "$", "Model", "->", "alias", "]", "=", "$", "this", "->", "modelDefaults", "[", "$", "Model", "->", "alias", "]", ";", "// check if $this->modelDefaultsPersist has been set", "if", "(", "isset", "(", "$", "this", "->", "modelDefaultsPersist", "[", "$", "Model", "->", "alias", "]", ")", ")", "{", "// if persist equals equals true", "if", "(", "!", "isset", "(", "$", "this", "->", "modelDefaults", "[", "$", "Model", "->", "alias", "]", "[", "'persist'", "]", ")", "||", "$", "this", "->", "modelDefaults", "[", "$", "Model", "->", "alias", "]", "[", "'persist'", "]", "==", "false", ")", "{", "$", "this", "->", "modelDefaults", "[", "$", "Model", "->", "alias", "]", "=", "$", "this", "->", "modelDefaultsPersist", "[", "$", "Model", "->", "alias", "]", ";", "}", "}", "if", "(", "isset", "(", "$", "query", "[", "'permit'", "]", ")", "&&", "isset", "(", "$", "this", "->", "settings", "[", "$", "Model", "->", "alias", "]", "[", "'rules'", "]", "[", "$", "query", "[", "'permit'", "]", "]", ")", ")", "{", "$", "rules", "=", "$", "this", "->", "settings", "[", "$", "Model", "->", "alias", "]", "[", "'rules'", "]", "[", "$", "query", "[", "'permit'", "]", "]", ";", "if", "(", "isset", "(", "$", "rules", "[", "'rules'", "]", ")", ")", "{", "unset", "(", "$", "rules", "[", "'rules'", "]", ")", ";", "}", "$", "this", "->", "settings", "[", "$", "Model", "->", "alias", "]", "=", "array_merge", "(", "$", "this", "->", "settings", "[", "$", "Model", "->", "alias", "]", ",", "$", "rules", ")", ";", "}", "foreach", "(", "array", "(", "'message'", ",", "'check'", ",", "'value'", ",", "'field'", ",", "'skip'", ",", "'rules'", ")", "as", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "query", "[", "'permit_'", ".", "$", "key", "]", ")", ")", "{", "$", "this", "->", "settings", "[", "$", "Model", "->", "alias", "]", "[", "$", "key", "]", "=", "$", "query", "[", "'permit_'", ".", "$", "key", "]", ";", "}", "}", "return", "$", "query", ";", "}" ]
beforeFind Callback @param Model $Model Model find is being run on. @param array $query Array of Query parameters. @return array Modified query
[ "beforeFind", "Callback" ]
train
https://github.com/josegonzalez/cakephp-sanction/blob/df2a8f0c0602c0ace802773db2c2ca6c89555c47/Model/Behavior/PermitBehavior.php#L62-L89
josegonzalez/cakephp-sanction
Model/Behavior/PermitBehavior.php
PermitBehavior.afterFind
public function afterFind(Model $Model, $results, $primary) { if (!$primary) { return $results; } $settings = $this->settings[$Model->alias]; if ($settings['skip'] === true) { return $results; } // the permit behavour is a bit pointless if we're handing more than one result if (count($results) > 1) { return $results; } // HACK: Retrieve the zeroth index in the resultset $userId = Hash::get($results, "0.{$settings['field']}"); if ($userId === null) { return $results; } if ($userId == $this->user($Model, $results, 'id')) { return $results; } $adminCheck = $settings['check']; $adminValue = $settings['value']; if ($adminCheck && $this->user($Model, $results, $adminCheck) == $adminValue) { return $results; } throw new UnauthorizedException($settings['message']); }
php
public function afterFind(Model $Model, $results, $primary) { if (!$primary) { return $results; } $settings = $this->settings[$Model->alias]; if ($settings['skip'] === true) { return $results; } // the permit behavour is a bit pointless if we're handing more than one result if (count($results) > 1) { return $results; } // HACK: Retrieve the zeroth index in the resultset $userId = Hash::get($results, "0.{$settings['field']}"); if ($userId === null) { return $results; } if ($userId == $this->user($Model, $results, 'id')) { return $results; } $adminCheck = $settings['check']; $adminValue = $settings['value']; if ($adminCheck && $this->user($Model, $results, $adminCheck) == $adminValue) { return $results; } throw new UnauthorizedException($settings['message']); }
[ "public", "function", "afterFind", "(", "Model", "$", "Model", ",", "$", "results", ",", "$", "primary", ")", "{", "if", "(", "!", "$", "primary", ")", "{", "return", "$", "results", ";", "}", "$", "settings", "=", "$", "this", "->", "settings", "[", "$", "Model", "->", "alias", "]", ";", "if", "(", "$", "settings", "[", "'skip'", "]", "===", "true", ")", "{", "return", "$", "results", ";", "}", "// the permit behavour is a bit pointless if we're handing more than one result", "if", "(", "count", "(", "$", "results", ")", ">", "1", ")", "{", "return", "$", "results", ";", "}", "// HACK: Retrieve the zeroth index in the resultset", "$", "userId", "=", "Hash", "::", "get", "(", "$", "results", ",", "\"0.{$settings['field']}\"", ")", ";", "if", "(", "$", "userId", "===", "null", ")", "{", "return", "$", "results", ";", "}", "if", "(", "$", "userId", "==", "$", "this", "->", "user", "(", "$", "Model", ",", "$", "results", ",", "'id'", ")", ")", "{", "return", "$", "results", ";", "}", "$", "adminCheck", "=", "$", "settings", "[", "'check'", "]", ";", "$", "adminValue", "=", "$", "settings", "[", "'value'", "]", ";", "if", "(", "$", "adminCheck", "&&", "$", "this", "->", "user", "(", "$", "Model", ",", "$", "results", ",", "$", "adminCheck", ")", "==", "$", "adminValue", ")", "{", "return", "$", "results", ";", "}", "throw", "new", "UnauthorizedException", "(", "$", "settings", "[", "'message'", "]", ")", ";", "}" ]
afterFind Callback @param Model $Model Model find was run on @param array $results Array of model results. @param bool $primary Did the find originate on $model. @return array Modified results @throws UnauthorizedException
[ "afterFind", "Callback" ]
train
https://github.com/josegonzalez/cakephp-sanction/blob/df2a8f0c0602c0ace802773db2c2ca6c89555c47/Model/Behavior/PermitBehavior.php#L100-L133