repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
thephpleague/oauth2-client
src/Tool/ProviderRedirectTrait.php
ProviderRedirectTrait.followRequestRedirects
protected function followRequestRedirects(RequestInterface $request) { $response = null; $attempts = 0; while ($attempts < $this->redirectLimit) { $attempts++; $response = $this->getHttpClient()->send($request, [ 'allow_redirects' => false ]); if ($this->isRedirect($response)) { $redirectUrl = new Uri($response->getHeader('Location')[0]); $request = $request->withUri($redirectUrl); } else { break; } } return $response; }
php
protected function followRequestRedirects(RequestInterface $request) { $response = null; $attempts = 0; while ($attempts < $this->redirectLimit) { $attempts++; $response = $this->getHttpClient()->send($request, [ 'allow_redirects' => false ]); if ($this->isRedirect($response)) { $redirectUrl = new Uri($response->getHeader('Location')[0]); $request = $request->withUri($redirectUrl); } else { break; } } return $response; }
[ "protected", "function", "followRequestRedirects", "(", "RequestInterface", "$", "request", ")", "{", "$", "response", "=", "null", ";", "$", "attempts", "=", "0", ";", "while", "(", "$", "attempts", "<", "$", "this", "->", "redirectLimit", ")", "{", "$", "attempts", "++", ";", "$", "response", "=", "$", "this", "->", "getHttpClient", "(", ")", "->", "send", "(", "$", "request", ",", "[", "'allow_redirects'", "=>", "false", "]", ")", ";", "if", "(", "$", "this", "->", "isRedirect", "(", "$", "response", ")", ")", "{", "$", "redirectUrl", "=", "new", "Uri", "(", "$", "response", "->", "getHeader", "(", "'Location'", ")", "[", "0", "]", ")", ";", "$", "request", "=", "$", "request", "->", "withUri", "(", "$", "redirectUrl", ")", ";", "}", "else", "{", "break", ";", "}", "}", "return", "$", "response", ";", "}" ]
Retrieves a response for a given request and retrieves subsequent responses, with authorization headers, if a redirect is detected. @param RequestInterface $request @return ResponseInterface @throws BadResponseException
[ "Retrieves", "a", "response", "for", "a", "given", "request", "and", "retrieves", "subsequent", "responses", "with", "authorization", "headers", "if", "a", "redirect", "is", "detected", "." ]
552c940c65b2310615b3cc4c0328798011a7e268
https://github.com/thephpleague/oauth2-client/blob/552c940c65b2310615b3cc4c0328798011a7e268/src/Tool/ProviderRedirectTrait.php#L28-L48
train
thephpleague/oauth2-client
src/Tool/ProviderRedirectTrait.php
ProviderRedirectTrait.isRedirect
protected function isRedirect(ResponseInterface $response) { $statusCode = $response->getStatusCode(); return $statusCode > 300 && $statusCode < 400 && $response->hasHeader('Location'); }
php
protected function isRedirect(ResponseInterface $response) { $statusCode = $response->getStatusCode(); return $statusCode > 300 && $statusCode < 400 && $response->hasHeader('Location'); }
[ "protected", "function", "isRedirect", "(", "ResponseInterface", "$", "response", ")", "{", "$", "statusCode", "=", "$", "response", "->", "getStatusCode", "(", ")", ";", "return", "$", "statusCode", ">", "300", "&&", "$", "statusCode", "<", "400", "&&", "$", "response", "->", "hasHeader", "(", "'Location'", ")", ";", "}" ]
Determines if a given response is a redirect. @param ResponseInterface $response @return boolean
[ "Determines", "if", "a", "given", "response", "is", "a", "redirect", "." ]
552c940c65b2310615b3cc4c0328798011a7e268
https://github.com/thephpleague/oauth2-client/blob/552c940c65b2310615b3cc4c0328798011a7e268/src/Tool/ProviderRedirectTrait.php#L74-L79
train
thephpleague/oauth2-client
src/Tool/ProviderRedirectTrait.php
ProviderRedirectTrait.setRedirectLimit
public function setRedirectLimit($limit) { if (!is_int($limit)) { throw new InvalidArgumentException('redirectLimit must be an integer.'); } if ($limit < 1) { throw new InvalidArgumentException('redirectLimit must be greater than or equal to one.'); } $this->redirectLimit = $limit; return $this; }
php
public function setRedirectLimit($limit) { if (!is_int($limit)) { throw new InvalidArgumentException('redirectLimit must be an integer.'); } if ($limit < 1) { throw new InvalidArgumentException('redirectLimit must be greater than or equal to one.'); } $this->redirectLimit = $limit; return $this; }
[ "public", "function", "setRedirectLimit", "(", "$", "limit", ")", "{", "if", "(", "!", "is_int", "(", "$", "limit", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'redirectLimit must be an integer.'", ")", ";", "}", "if", "(", "$", "limit", "<", "1", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'redirectLimit must be greater than or equal to one.'", ")", ";", "}", "$", "this", "->", "redirectLimit", "=", "$", "limit", ";", "return", "$", "this", ";", "}" ]
Updates the redirect limit. @param integer $limit @return League\OAuth2\Client\Provider\AbstractProvider @throws InvalidArgumentException
[ "Updates", "the", "redirect", "limit", "." ]
552c940c65b2310615b3cc4c0328798011a7e268
https://github.com/thephpleague/oauth2-client/blob/552c940c65b2310615b3cc4c0328798011a7e268/src/Tool/ProviderRedirectTrait.php#L108-L121
train
thephpleague/oauth2-client
src/Tool/ArrayAccessorTrait.php
ArrayAccessorTrait.getValueByKey
private function getValueByKey(array $data, $key, $default = null) { if (!is_string($key) || empty($key) || !count($data)) { return $default; } if (strpos($key, '.') !== false) { $keys = explode('.', $key); foreach ($keys as $innerKey) { if (!is_array($data) || !array_key_exists($innerKey, $data)) { return $default; } $data = $data[$innerKey]; } return $data; } return array_key_exists($key, $data) ? $data[$key] : $default; }
php
private function getValueByKey(array $data, $key, $default = null) { if (!is_string($key) || empty($key) || !count($data)) { return $default; } if (strpos($key, '.') !== false) { $keys = explode('.', $key); foreach ($keys as $innerKey) { if (!is_array($data) || !array_key_exists($innerKey, $data)) { return $default; } $data = $data[$innerKey]; } return $data; } return array_key_exists($key, $data) ? $data[$key] : $default; }
[ "private", "function", "getValueByKey", "(", "array", "$", "data", ",", "$", "key", ",", "$", "default", "=", "null", ")", "{", "if", "(", "!", "is_string", "(", "$", "key", ")", "||", "empty", "(", "$", "key", ")", "||", "!", "count", "(", "$", "data", ")", ")", "{", "return", "$", "default", ";", "}", "if", "(", "strpos", "(", "$", "key", ",", "'.'", ")", "!==", "false", ")", "{", "$", "keys", "=", "explode", "(", "'.'", ",", "$", "key", ")", ";", "foreach", "(", "$", "keys", "as", "$", "innerKey", ")", "{", "if", "(", "!", "is_array", "(", "$", "data", ")", "||", "!", "array_key_exists", "(", "$", "innerKey", ",", "$", "data", ")", ")", "{", "return", "$", "default", ";", "}", "$", "data", "=", "$", "data", "[", "$", "innerKey", "]", ";", "}", "return", "$", "data", ";", "}", "return", "array_key_exists", "(", "$", "key", ",", "$", "data", ")", "?", "$", "data", "[", "$", "key", "]", ":", "$", "default", ";", "}" ]
Returns a value by key using dot notation. @param array $data @param string $key @param mixed|null $default @return mixed
[ "Returns", "a", "value", "by", "key", "using", "dot", "notation", "." ]
552c940c65b2310615b3cc4c0328798011a7e268
https://github.com/thephpleague/oauth2-client/blob/552c940c65b2310615b3cc4c0328798011a7e268/src/Tool/ArrayAccessorTrait.php#L30-L51
train
thephpleague/oauth2-client
src/Tool/MacAuthorizationTrait.php
MacAuthorizationTrait.getAuthorizationHeaders
protected function getAuthorizationHeaders($token = null) { if ($token === null) { return []; } $ts = time(); $id = $this->getTokenId($token); $nonce = $this->getRandomState(16); $mac = $this->getMacSignature($id, $ts, $nonce); $parts = []; foreach (compact('id', 'ts', 'nonce', 'mac') as $key => $value) { $parts[] = sprintf('%s="%s"', $key, $value); } return ['Authorization' => 'MAC ' . implode(', ', $parts)]; }
php
protected function getAuthorizationHeaders($token = null) { if ($token === null) { return []; } $ts = time(); $id = $this->getTokenId($token); $nonce = $this->getRandomState(16); $mac = $this->getMacSignature($id, $ts, $nonce); $parts = []; foreach (compact('id', 'ts', 'nonce', 'mac') as $key => $value) { $parts[] = sprintf('%s="%s"', $key, $value); } return ['Authorization' => 'MAC ' . implode(', ', $parts)]; }
[ "protected", "function", "getAuthorizationHeaders", "(", "$", "token", "=", "null", ")", "{", "if", "(", "$", "token", "===", "null", ")", "{", "return", "[", "]", ";", "}", "$", "ts", "=", "time", "(", ")", ";", "$", "id", "=", "$", "this", "->", "getTokenId", "(", "$", "token", ")", ";", "$", "nonce", "=", "$", "this", "->", "getRandomState", "(", "16", ")", ";", "$", "mac", "=", "$", "this", "->", "getMacSignature", "(", "$", "id", ",", "$", "ts", ",", "$", "nonce", ")", ";", "$", "parts", "=", "[", "]", ";", "foreach", "(", "compact", "(", "'id'", ",", "'ts'", ",", "'nonce'", ",", "'mac'", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "parts", "[", "]", "=", "sprintf", "(", "'%s=\"%s\"'", ",", "$", "key", ",", "$", "value", ")", ";", "}", "return", "[", "'Authorization'", "=>", "'MAC '", ".", "implode", "(", "', '", ",", "$", "parts", ")", "]", ";", "}" ]
Returns the authorization headers for the 'mac' grant. @param AccessTokenInterface|string|null $token Either a string or an access token instance @return array @codeCoverageIgnore @todo This is currently untested and provided only as an example. If you complete the implementation, please create a pull request for https://github.com/thephpleague/oauth2-client
[ "Returns", "the", "authorization", "headers", "for", "the", "mac", "grant", "." ]
552c940c65b2310615b3cc4c0328798011a7e268
https://github.com/thephpleague/oauth2-client/blob/552c940c65b2310615b3cc4c0328798011a7e268/src/Tool/MacAuthorizationTrait.php#L65-L82
train
thephpleague/oauth2-client
src/Tool/RequestFactory.php
RequestFactory.getRequestWithOptions
public function getRequestWithOptions($method, $uri, array $options = []) { $options = $this->parseOptions($options); return $this->getRequest( $method, $uri, $options['headers'], $options['body'], $options['version'] ); }
php
public function getRequestWithOptions($method, $uri, array $options = []) { $options = $this->parseOptions($options); return $this->getRequest( $method, $uri, $options['headers'], $options['body'], $options['version'] ); }
[ "public", "function", "getRequestWithOptions", "(", "$", "method", ",", "$", "uri", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "=", "$", "this", "->", "parseOptions", "(", "$", "options", ")", ";", "return", "$", "this", "->", "getRequest", "(", "$", "method", ",", "$", "uri", ",", "$", "options", "[", "'headers'", "]", ",", "$", "options", "[", "'body'", "]", ",", "$", "options", "[", "'version'", "]", ")", ";", "}" ]
Creates a request using a simplified array of options. @param null|string $method @param null|string $uri @param array $options @return Request
[ "Creates", "a", "request", "using", "a", "simplified", "array", "of", "options", "." ]
552c940c65b2310615b3cc4c0328798011a7e268
https://github.com/thephpleague/oauth2-client/blob/552c940c65b2310615b3cc4c0328798011a7e268/src/Tool/RequestFactory.php#L75-L86
train
thephpleague/oauth2-client
src/Grant/AbstractGrant.php
AbstractGrant.prepareRequestParameters
public function prepareRequestParameters(array $defaults, array $options) { $defaults['grant_type'] = $this->getName(); $required = $this->getRequiredRequestParameters(); $provided = array_merge($defaults, $options); $this->checkRequiredParameters($required, $provided); return $provided; }
php
public function prepareRequestParameters(array $defaults, array $options) { $defaults['grant_type'] = $this->getName(); $required = $this->getRequiredRequestParameters(); $provided = array_merge($defaults, $options); $this->checkRequiredParameters($required, $provided); return $provided; }
[ "public", "function", "prepareRequestParameters", "(", "array", "$", "defaults", ",", "array", "$", "options", ")", "{", "$", "defaults", "[", "'grant_type'", "]", "=", "$", "this", "->", "getName", "(", ")", ";", "$", "required", "=", "$", "this", "->", "getRequiredRequestParameters", "(", ")", ";", "$", "provided", "=", "array_merge", "(", "$", "defaults", ",", "$", "options", ")", ";", "$", "this", "->", "checkRequiredParameters", "(", "$", "required", ",", "$", "provided", ")", ";", "return", "$", "provided", ";", "}" ]
Prepares an access token request's parameters by checking that all required parameters are set, then merging with any given defaults. @param array $defaults @param array $options @return array
[ "Prepares", "an", "access", "token", "request", "s", "parameters", "by", "checking", "that", "all", "required", "parameters", "are", "set", "then", "merging", "with", "any", "given", "defaults", "." ]
552c940c65b2310615b3cc4c0328798011a7e268
https://github.com/thephpleague/oauth2-client/blob/552c940c65b2310615b3cc4c0328798011a7e268/src/Grant/AbstractGrant.php#L69-L79
train
thephpleague/oauth2-client
src/Provider/AbstractProvider.php
AbstractProvider.getAuthorizationUrl
public function getAuthorizationUrl(array $options = []) { $base = $this->getBaseAuthorizationUrl(); $params = $this->getAuthorizationParameters($options); $query = $this->getAuthorizationQuery($params); return $this->appendQuery($base, $query); }
php
public function getAuthorizationUrl(array $options = []) { $base = $this->getBaseAuthorizationUrl(); $params = $this->getAuthorizationParameters($options); $query = $this->getAuthorizationQuery($params); return $this->appendQuery($base, $query); }
[ "public", "function", "getAuthorizationUrl", "(", "array", "$", "options", "=", "[", "]", ")", "{", "$", "base", "=", "$", "this", "->", "getBaseAuthorizationUrl", "(", ")", ";", "$", "params", "=", "$", "this", "->", "getAuthorizationParameters", "(", "$", "options", ")", ";", "$", "query", "=", "$", "this", "->", "getAuthorizationQuery", "(", "$", "params", ")", ";", "return", "$", "this", "->", "appendQuery", "(", "$", "base", ",", "$", "query", ")", ";", "}" ]
Builds the authorization URL. @param array $options @return string Authorization URL
[ "Builds", "the", "authorization", "URL", "." ]
552c940c65b2310615b3cc4c0328798011a7e268
https://github.com/thephpleague/oauth2-client/blob/552c940c65b2310615b3cc4c0328798011a7e268/src/Provider/AbstractProvider.php#L386-L393
train
thephpleague/oauth2-client
src/Provider/AbstractProvider.php
AbstractProvider.authorize
public function authorize( array $options = [], callable $redirectHandler = null ) { $url = $this->getAuthorizationUrl($options); if ($redirectHandler) { return $redirectHandler($url, $this); } // @codeCoverageIgnoreStart header('Location: ' . $url); exit; // @codeCoverageIgnoreEnd }
php
public function authorize( array $options = [], callable $redirectHandler = null ) { $url = $this->getAuthorizationUrl($options); if ($redirectHandler) { return $redirectHandler($url, $this); } // @codeCoverageIgnoreStart header('Location: ' . $url); exit; // @codeCoverageIgnoreEnd }
[ "public", "function", "authorize", "(", "array", "$", "options", "=", "[", "]", ",", "callable", "$", "redirectHandler", "=", "null", ")", "{", "$", "url", "=", "$", "this", "->", "getAuthorizationUrl", "(", "$", "options", ")", ";", "if", "(", "$", "redirectHandler", ")", "{", "return", "$", "redirectHandler", "(", "$", "url", ",", "$", "this", ")", ";", "}", "// @codeCoverageIgnoreStart", "header", "(", "'Location: '", ".", "$", "url", ")", ";", "exit", ";", "// @codeCoverageIgnoreEnd", "}" ]
Redirects the client for authorization. @param array $options @param callable|null $redirectHandler @return mixed
[ "Redirects", "the", "client", "for", "authorization", "." ]
552c940c65b2310615b3cc4c0328798011a7e268
https://github.com/thephpleague/oauth2-client/blob/552c940c65b2310615b3cc4c0328798011a7e268/src/Provider/AbstractProvider.php#L402-L415
train
thephpleague/oauth2-client
src/Provider/AbstractProvider.php
AbstractProvider.appendQuery
protected function appendQuery($url, $query) { $query = trim($query, '?&'); if ($query) { $glue = strstr($url, '?') === false ? '?' : '&'; return $url . $glue . $query; } return $url; }
php
protected function appendQuery($url, $query) { $query = trim($query, '?&'); if ($query) { $glue = strstr($url, '?') === false ? '?' : '&'; return $url . $glue . $query; } return $url; }
[ "protected", "function", "appendQuery", "(", "$", "url", ",", "$", "query", ")", "{", "$", "query", "=", "trim", "(", "$", "query", ",", "'?&'", ")", ";", "if", "(", "$", "query", ")", "{", "$", "glue", "=", "strstr", "(", "$", "url", ",", "'?'", ")", "===", "false", "?", "'?'", ":", "'&'", ";", "return", "$", "url", ".", "$", "glue", ".", "$", "query", ";", "}", "return", "$", "url", ";", "}" ]
Appends a query string to a URL. @param string $url The URL to append the query to @param string $query The HTTP query string @return string The resulting URL
[ "Appends", "a", "query", "string", "to", "a", "URL", "." ]
552c940c65b2310615b3cc4c0328798011a7e268
https://github.com/thephpleague/oauth2-client/blob/552c940c65b2310615b3cc4c0328798011a7e268/src/Provider/AbstractProvider.php#L424-L434
train
thephpleague/oauth2-client
src/Provider/AbstractProvider.php
AbstractProvider.verifyGrant
protected function verifyGrant($grant) { if (is_string($grant)) { return $this->grantFactory->getGrant($grant); } $this->grantFactory->checkGrant($grant); return $grant; }
php
protected function verifyGrant($grant) { if (is_string($grant)) { return $this->grantFactory->getGrant($grant); } $this->grantFactory->checkGrant($grant); return $grant; }
[ "protected", "function", "verifyGrant", "(", "$", "grant", ")", "{", "if", "(", "is_string", "(", "$", "grant", ")", ")", "{", "return", "$", "this", "->", "grantFactory", "->", "getGrant", "(", "$", "grant", ")", ";", "}", "$", "this", "->", "grantFactory", "->", "checkGrant", "(", "$", "grant", ")", ";", "return", "$", "grant", ";", "}" ]
Checks that a provided grant is valid, or attempts to produce one if the provided grant is a string. @param AbstractGrant|string $grant @return AbstractGrant
[ "Checks", "that", "a", "provided", "grant", "is", "valid", "or", "attempts", "to", "produce", "one", "if", "the", "provided", "grant", "is", "a", "string", "." ]
552c940c65b2310615b3cc4c0328798011a7e268
https://github.com/thephpleague/oauth2-client/blob/552c940c65b2310615b3cc4c0328798011a7e268/src/Provider/AbstractProvider.php#L474-L482
train
thephpleague/oauth2-client
src/Provider/AbstractProvider.php
AbstractProvider.getAccessTokenUrl
protected function getAccessTokenUrl(array $params) { $url = $this->getBaseAccessTokenUrl($params); if ($this->getAccessTokenMethod() === self::METHOD_GET) { $query = $this->getAccessTokenQuery($params); return $this->appendQuery($url, $query); } return $url; }
php
protected function getAccessTokenUrl(array $params) { $url = $this->getBaseAccessTokenUrl($params); if ($this->getAccessTokenMethod() === self::METHOD_GET) { $query = $this->getAccessTokenQuery($params); return $this->appendQuery($url, $query); } return $url; }
[ "protected", "function", "getAccessTokenUrl", "(", "array", "$", "params", ")", "{", "$", "url", "=", "$", "this", "->", "getBaseAccessTokenUrl", "(", "$", "params", ")", ";", "if", "(", "$", "this", "->", "getAccessTokenMethod", "(", ")", "===", "self", "::", "METHOD_GET", ")", "{", "$", "query", "=", "$", "this", "->", "getAccessTokenQuery", "(", "$", "params", ")", ";", "return", "$", "this", "->", "appendQuery", "(", "$", "url", ",", "$", "query", ")", ";", "}", "return", "$", "url", ";", "}" ]
Returns the full URL to use when requesting an access token. @param array $params Query parameters @return string
[ "Returns", "the", "full", "URL", "to", "use", "when", "requesting", "an", "access", "token", "." ]
552c940c65b2310615b3cc4c0328798011a7e268
https://github.com/thephpleague/oauth2-client/blob/552c940c65b2310615b3cc4c0328798011a7e268/src/Provider/AbstractProvider.php#L490-L500
train
thephpleague/oauth2-client
src/Provider/AbstractProvider.php
AbstractProvider.getRequest
public function getRequest($method, $url, array $options = []) { return $this->createRequest($method, $url, null, $options); }
php
public function getRequest($method, $url, array $options = []) { return $this->createRequest($method, $url, null, $options); }
[ "public", "function", "getRequest", "(", "$", "method", ",", "$", "url", ",", "array", "$", "options", "=", "[", "]", ")", "{", "return", "$", "this", "->", "createRequest", "(", "$", "method", ",", "$", "url", ",", "null", ",", "$", "options", ")", ";", "}" ]
Returns a PSR-7 request instance that is not authenticated. @param string $method @param string $url @param array $options @return RequestInterface
[ "Returns", "a", "PSR", "-", "7", "request", "instance", "that", "is", "not", "authenticated", "." ]
552c940c65b2310615b3cc4c0328798011a7e268
https://github.com/thephpleague/oauth2-client/blob/552c940c65b2310615b3cc4c0328798011a7e268/src/Provider/AbstractProvider.php#L557-L560
train
thephpleague/oauth2-client
src/Provider/AbstractProvider.php
AbstractProvider.getHeaders
public function getHeaders($token = null) { if ($token) { return array_merge( $this->getDefaultHeaders(), $this->getAuthorizationHeaders($token) ); } return $this->getDefaultHeaders(); }
php
public function getHeaders($token = null) { if ($token) { return array_merge( $this->getDefaultHeaders(), $this->getAuthorizationHeaders($token) ); } return $this->getDefaultHeaders(); }
[ "public", "function", "getHeaders", "(", "$", "token", "=", "null", ")", "{", "if", "(", "$", "token", ")", "{", "return", "array_merge", "(", "$", "this", "->", "getDefaultHeaders", "(", ")", ",", "$", "this", "->", "getAuthorizationHeaders", "(", "$", "token", ")", ")", ";", "}", "return", "$", "this", "->", "getDefaultHeaders", "(", ")", ";", "}" ]
Returns all headers used by this provider for a request. The request will be authenticated if an access token is provided. @param mixed|null $token object or string @return array
[ "Returns", "all", "headers", "used", "by", "this", "provider", "for", "a", "request", "." ]
552c940c65b2310615b3cc4c0328798011a7e268
https://github.com/thephpleague/oauth2-client/blob/552c940c65b2310615b3cc4c0328798011a7e268/src/Provider/AbstractProvider.php#L832-L842
train
thephpleague/oauth2-client
src/Tool/RequiredParameterTrait.php
RequiredParameterTrait.checkRequiredParameters
private function checkRequiredParameters(array $names, array $params) { foreach ($names as $name) { $this->checkRequiredParameter($name, $params); } }
php
private function checkRequiredParameters(array $names, array $params) { foreach ($names as $name) { $this->checkRequiredParameter($name, $params); } }
[ "private", "function", "checkRequiredParameters", "(", "array", "$", "names", ",", "array", "$", "params", ")", "{", "foreach", "(", "$", "names", "as", "$", "name", ")", "{", "$", "this", "->", "checkRequiredParameter", "(", "$", "name", ",", "$", "params", ")", ";", "}", "}" ]
Checks for multiple required parameters in a hash. @throws InvalidArgumentException @param array $names @param array $params @return void
[ "Checks", "for", "multiple", "required", "parameters", "in", "a", "hash", "." ]
552c940c65b2310615b3cc4c0328798011a7e268
https://github.com/thephpleague/oauth2-client/blob/552c940c65b2310615b3cc4c0328798011a7e268/src/Tool/RequiredParameterTrait.php#L50-L55
train
thephpleague/oauth2-client
src/Tool/GuardedPropertyTrait.php
GuardedPropertyTrait.fillProperties
protected function fillProperties(array $options = []) { if (isset($options['guarded'])) { unset($options['guarded']); } foreach ($options as $option => $value) { if (property_exists($this, $option) && !$this->isGuarded($option)) { $this->{$option} = $value; } } }
php
protected function fillProperties(array $options = []) { if (isset($options['guarded'])) { unset($options['guarded']); } foreach ($options as $option => $value) { if (property_exists($this, $option) && !$this->isGuarded($option)) { $this->{$option} = $value; } } }
[ "protected", "function", "fillProperties", "(", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "isset", "(", "$", "options", "[", "'guarded'", "]", ")", ")", "{", "unset", "(", "$", "options", "[", "'guarded'", "]", ")", ";", "}", "foreach", "(", "$", "options", "as", "$", "option", "=>", "$", "value", ")", "{", "if", "(", "property_exists", "(", "$", "this", ",", "$", "option", ")", "&&", "!", "$", "this", "->", "isGuarded", "(", "$", "option", ")", ")", "{", "$", "this", "->", "{", "$", "option", "}", "=", "$", "value", ";", "}", "}", "}" ]
Attempts to mass assign the given options to explicitly defined properties, skipping over any properties that are defined in the guarded array. @param array $options @return mixed
[ "Attempts", "to", "mass", "assign", "the", "given", "options", "to", "explicitly", "defined", "properties", "skipping", "over", "any", "properties", "that", "are", "defined", "in", "the", "guarded", "array", "." ]
552c940c65b2310615b3cc4c0328798011a7e268
https://github.com/thephpleague/oauth2-client/blob/552c940c65b2310615b3cc4c0328798011a7e268/src/Tool/GuardedPropertyTrait.php#L37-L48
train
caouecs/Laravel-lang
script/todo.php
TodoGenerator.load
private function load() { // Get English version $english = $this->getTranslations(__DIR__, 'en'); $languages = $this->getLanguages(); $this->compareTranslations($english, $languages); }
php
private function load() { // Get English version $english = $this->getTranslations(__DIR__, 'en'); $languages = $this->getLanguages(); $this->compareTranslations($english, $languages); }
[ "private", "function", "load", "(", ")", "{", "// Get English version", "$", "english", "=", "$", "this", "->", "getTranslations", "(", "__DIR__", ",", "'en'", ")", ";", "$", "languages", "=", "$", "this", "->", "getLanguages", "(", ")", ";", "$", "this", "->", "compareTranslations", "(", "$", "english", ",", "$", "languages", ")", ";", "}" ]
Compare translations and generate file.
[ "Compare", "translations", "and", "generate", "file", "." ]
5a2b4fa71c29aea236ced9af9359686b0927ac5e
https://github.com/caouecs/Laravel-lang/blob/5a2b4fa71c29aea236ced9af9359686b0927ac5e/script/todo.php#L69-L76
train
caouecs/Laravel-lang
script/todo.php
TodoGenerator.getTranslations
private function getTranslations($directory, $language) { $contentJson = ''; $directoryJson = ($language == 'en') ? '/en/' : '/../json/'; $fileJson = $directory.$directoryJson.$language.'.json'; if (file_exists($fileJson)) { $contentJson = json_decode(file_get_contents($fileJson), true); } return [ 'json' => $contentJson, 'auth' => include($directory.'/'.$language.'/auth.php'), 'pagination' => include($directory.'/'.$language.'/pagination.php'), 'passwords' => include($directory.'/'.$language.'/passwords.php'), 'validation' => include($directory.'/'.$language.'/validation.php'), ]; }
php
private function getTranslations($directory, $language) { $contentJson = ''; $directoryJson = ($language == 'en') ? '/en/' : '/../json/'; $fileJson = $directory.$directoryJson.$language.'.json'; if (file_exists($fileJson)) { $contentJson = json_decode(file_get_contents($fileJson), true); } return [ 'json' => $contentJson, 'auth' => include($directory.'/'.$language.'/auth.php'), 'pagination' => include($directory.'/'.$language.'/pagination.php'), 'passwords' => include($directory.'/'.$language.'/passwords.php'), 'validation' => include($directory.'/'.$language.'/validation.php'), ]; }
[ "private", "function", "getTranslations", "(", "$", "directory", ",", "$", "language", ")", "{", "$", "contentJson", "=", "''", ";", "$", "directoryJson", "=", "(", "$", "language", "==", "'en'", ")", "?", "'/en/'", ":", "'/../json/'", ";", "$", "fileJson", "=", "$", "directory", ".", "$", "directoryJson", ".", "$", "language", ".", "'.json'", ";", "if", "(", "file_exists", "(", "$", "fileJson", ")", ")", "{", "$", "contentJson", "=", "json_decode", "(", "file_get_contents", "(", "$", "fileJson", ")", ",", "true", ")", ";", "}", "return", "[", "'json'", "=>", "$", "contentJson", ",", "'auth'", "=>", "include", "(", "$", "directory", ".", "'/'", ".", "$", "language", ".", "'/auth.php'", ")", ",", "'pagination'", "=>", "include", "(", "$", "directory", ".", "'/'", ".", "$", "language", ".", "'/pagination.php'", ")", ",", "'passwords'", "=>", "include", "(", "$", "directory", ".", "'/'", ".", "$", "language", ".", "'/passwords.php'", ")", ",", "'validation'", "=>", "include", "(", "$", "directory", ".", "'/'", ".", "$", "language", ".", "'/validation.php'", ")", ",", "]", ";", "}" ]
Returns array of translations by language. @param string $directory directory @param string $language language code @return array
[ "Returns", "array", "of", "translations", "by", "language", "." ]
5a2b4fa71c29aea236ced9af9359686b0927ac5e
https://github.com/caouecs/Laravel-lang/blob/5a2b4fa71c29aea236ced9af9359686b0927ac5e/script/todo.php#L86-L105
train
caouecs/Laravel-lang
script/todo.php
TodoGenerator.getLanguages
private function getLanguages() { $directories = glob($this->basePath.'/*', GLOB_ONLYDIR); $languages = array_map(function ($dir) { $name = basename($dir); return in_array($name, $this->excluded, true) ? null : $name; }, $directories); return array_filter($languages); }
php
private function getLanguages() { $directories = glob($this->basePath.'/*', GLOB_ONLYDIR); $languages = array_map(function ($dir) { $name = basename($dir); return in_array($name, $this->excluded, true) ? null : $name; }, $directories); return array_filter($languages); }
[ "private", "function", "getLanguages", "(", ")", "{", "$", "directories", "=", "glob", "(", "$", "this", "->", "basePath", ".", "'/*'", ",", "GLOB_ONLYDIR", ")", ";", "$", "languages", "=", "array_map", "(", "function", "(", "$", "dir", ")", "{", "$", "name", "=", "basename", "(", "$", "dir", ")", ";", "return", "in_array", "(", "$", "name", ",", "$", "this", "->", "excluded", ",", "true", ")", "?", "null", ":", "$", "name", ";", "}", ",", "$", "directories", ")", ";", "return", "array_filter", "(", "$", "languages", ")", ";", "}" ]
Returns list of languages. @return array
[ "Returns", "list", "of", "languages", "." ]
5a2b4fa71c29aea236ced9af9359686b0927ac5e
https://github.com/caouecs/Laravel-lang/blob/5a2b4fa71c29aea236ced9af9359686b0927ac5e/script/todo.php#L112-L123
train
caouecs/Laravel-lang
script/todo.php
TodoGenerator.compareTranslations
private function compareTranslations(array $default, array $languages) { // Return diff language by language foreach ($languages as $language) { $this->addOutput($language); $current = $this->getTranslations($this->basePath, $language); foreach ($default as $key => $values) { $valuesKeys = array_keys($values); foreach ($valuesKeys as $key2) { if (in_array($key2, ['custom', 'attributes'], true)) { continue; } if (!isset($current[$key][$key2])) { $this->addOutput($language, " * {$key} : {$key2} : not present"); } elseif ($current[$key][$key2] === $default[$key][$key2]) { $this->addOutput($language, " * {$key} : {$key2}"); } } } } }
php
private function compareTranslations(array $default, array $languages) { // Return diff language by language foreach ($languages as $language) { $this->addOutput($language); $current = $this->getTranslations($this->basePath, $language); foreach ($default as $key => $values) { $valuesKeys = array_keys($values); foreach ($valuesKeys as $key2) { if (in_array($key2, ['custom', 'attributes'], true)) { continue; } if (!isset($current[$key][$key2])) { $this->addOutput($language, " * {$key} : {$key2} : not present"); } elseif ($current[$key][$key2] === $default[$key][$key2]) { $this->addOutput($language, " * {$key} : {$key2}"); } } } } }
[ "private", "function", "compareTranslations", "(", "array", "$", "default", ",", "array", "$", "languages", ")", "{", "// Return diff language by language", "foreach", "(", "$", "languages", "as", "$", "language", ")", "{", "$", "this", "->", "addOutput", "(", "$", "language", ")", ";", "$", "current", "=", "$", "this", "->", "getTranslations", "(", "$", "this", "->", "basePath", ",", "$", "language", ")", ";", "foreach", "(", "$", "default", "as", "$", "key", "=>", "$", "values", ")", "{", "$", "valuesKeys", "=", "array_keys", "(", "$", "values", ")", ";", "foreach", "(", "$", "valuesKeys", "as", "$", "key2", ")", "{", "if", "(", "in_array", "(", "$", "key2", ",", "[", "'custom'", ",", "'attributes'", "]", ",", "true", ")", ")", "{", "continue", ";", "}", "if", "(", "!", "isset", "(", "$", "current", "[", "$", "key", "]", "[", "$", "key2", "]", ")", ")", "{", "$", "this", "->", "addOutput", "(", "$", "language", ",", "\" * {$key} : {$key2} : not present\"", ")", ";", "}", "elseif", "(", "$", "current", "[", "$", "key", "]", "[", "$", "key2", "]", "===", "$", "default", "[", "$", "key", "]", "[", "$", "key2", "]", ")", "{", "$", "this", "->", "addOutput", "(", "$", "language", ",", "\" * {$key} : {$key2}\"", ")", ";", "}", "}", "}", "}", "}" ]
Compare translations. @param array $default language by default @param array $languages others languages
[ "Compare", "translations", "." ]
5a2b4fa71c29aea236ced9af9359686b0927ac5e
https://github.com/caouecs/Laravel-lang/blob/5a2b4fa71c29aea236ced9af9359686b0927ac5e/script/todo.php#L131-L154
train
caouecs/Laravel-lang
script/todo.php
TodoGenerator.addOutput
private function addOutput(string $key, string $value = null) { if (!array_key_exists($key, $this->output)) { $this->output[$key] = []; } $this->output[$key][] = $value; }
php
private function addOutput(string $key, string $value = null) { if (!array_key_exists($key, $this->output)) { $this->output[$key] = []; } $this->output[$key][] = $value; }
[ "private", "function", "addOutput", "(", "string", "$", "key", ",", "string", "$", "value", "=", "null", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "output", ")", ")", "{", "$", "this", "->", "output", "[", "$", "key", "]", "=", "[", "]", ";", "}", "$", "this", "->", "output", "[", "$", "key", "]", "[", "]", "=", "$", "value", ";", "}" ]
Adding elements to the resulting array. @param string $key @param string|null $value
[ "Adding", "elements", "to", "the", "resulting", "array", "." ]
5a2b4fa71c29aea236ced9af9359686b0927ac5e
https://github.com/caouecs/Laravel-lang/blob/5a2b4fa71c29aea236ced9af9359686b0927ac5e/script/todo.php#L162-L169
train
caouecs/Laravel-lang
script/todo.php
TodoGenerator.getOutput
private function getOutput() { $output = "# Todo list\n\n"; // Make menu $columns = 12; $captions = implode('|', array_fill(0, $columns, ' ')); $subcaptions = implode('|', array_fill(0, $columns, ':---:')); $output .= "|$captions|\n"; $output .= "|$subcaptions|\n"; $menu = []; foreach (array_keys($this->output) as $language) { $menu[] = "[$language](#$language)"; } $rows = array_chunk($menu, $columns); array_map(function ($row) use (&$output) { $row = implode(' | ', $row); $output .= $row."\n"; }, $rows); $output .= "\n\n"; // Make items foreach ($this->output as $language => $values) { $output .= "#### {$language}:\n"; $output .= implode(PHP_EOL, $values); $output .= "\n\n[ [to top](#todo-list) ]\n\n"; } return $output; }
php
private function getOutput() { $output = "# Todo list\n\n"; // Make menu $columns = 12; $captions = implode('|', array_fill(0, $columns, ' ')); $subcaptions = implode('|', array_fill(0, $columns, ':---:')); $output .= "|$captions|\n"; $output .= "|$subcaptions|\n"; $menu = []; foreach (array_keys($this->output) as $language) { $menu[] = "[$language](#$language)"; } $rows = array_chunk($menu, $columns); array_map(function ($row) use (&$output) { $row = implode(' | ', $row); $output .= $row."\n"; }, $rows); $output .= "\n\n"; // Make items foreach ($this->output as $language => $values) { $output .= "#### {$language}:\n"; $output .= implode(PHP_EOL, $values); $output .= "\n\n[ [to top](#todo-list) ]\n\n"; } return $output; }
[ "private", "function", "getOutput", "(", ")", "{", "$", "output", "=", "\"# Todo list\\n\\n\"", ";", "// Make menu", "$", "columns", "=", "12", ";", "$", "captions", "=", "implode", "(", "'|'", ",", "array_fill", "(", "0", ",", "$", "columns", ",", "' '", ")", ")", ";", "$", "subcaptions", "=", "implode", "(", "'|'", ",", "array_fill", "(", "0", ",", "$", "columns", ",", "':---:'", ")", ")", ";", "$", "output", ".=", "\"|$captions|\\n\"", ";", "$", "output", ".=", "\"|$subcaptions|\\n\"", ";", "$", "menu", "=", "[", "]", ";", "foreach", "(", "array_keys", "(", "$", "this", "->", "output", ")", "as", "$", "language", ")", "{", "$", "menu", "[", "]", "=", "\"[$language](#$language)\"", ";", "}", "$", "rows", "=", "array_chunk", "(", "$", "menu", ",", "$", "columns", ")", ";", "array_map", "(", "function", "(", "$", "row", ")", "use", "(", "&", "$", "output", ")", "{", "$", "row", "=", "implode", "(", "' | '", ",", "$", "row", ")", ";", "$", "output", ".=", "$", "row", ".", "\"\\n\"", ";", "}", ",", "$", "rows", ")", ";", "$", "output", ".=", "\"\\n\\n\"", ";", "// Make items", "foreach", "(", "$", "this", "->", "output", "as", "$", "language", "=>", "$", "values", ")", "{", "$", "output", ".=", "\"#### {$language}:\\n\"", ";", "$", "output", ".=", "implode", "(", "PHP_EOL", ",", "$", "values", ")", ";", "$", "output", ".=", "\"\\n\\n[ [to top](#todo-list) ]\\n\\n\"", ";", "}", "return", "$", "output", ";", "}" ]
Forming the page content for output. @return string
[ "Forming", "the", "page", "content", "for", "output", "." ]
5a2b4fa71c29aea236ced9af9359686b0927ac5e
https://github.com/caouecs/Laravel-lang/blob/5a2b4fa71c29aea236ced9af9359686b0927ac5e/script/todo.php#L176-L210
train
cakephp/phinx
src/Phinx/Migration/Manager/Environment.php
Environment.executeMigration
public function executeMigration(MigrationInterface $migration, $direction = MigrationInterface::UP, $fake = false) { $direction = ($direction === MigrationInterface::UP) ? MigrationInterface::UP : MigrationInterface::DOWN; $migration->setMigratingUp($direction === MigrationInterface::UP); $startTime = time(); $migration->setAdapter($this->getAdapter()); if (!$fake) { // begin the transaction if the adapter supports it if ($this->getAdapter()->hasTransactions()) { $this->getAdapter()->beginTransaction(); } // Run the migration if (method_exists($migration, MigrationInterface::CHANGE)) { if ($direction === MigrationInterface::DOWN) { // Create an instance of the ProxyAdapter so we can record all // of the migration commands for reverse playback /** @var \Phinx\Db\Adapter\ProxyAdapter $proxyAdapter */ $proxyAdapter = AdapterFactory::instance() ->getWrapper('proxy', $this->getAdapter()); $migration->setAdapter($proxyAdapter); /** @noinspection PhpUndefinedMethodInspection */ $migration->change(); $proxyAdapter->executeInvertedCommands(); $migration->setAdapter($this->getAdapter()); } else { /** @noinspection PhpUndefinedMethodInspection */ $migration->change(); } } else { $migration->{$direction}(); } // commit the transaction if the adapter supports it if ($this->getAdapter()->hasTransactions()) { $this->getAdapter()->commitTransaction(); } } // Record it in the database $this->getAdapter()->migrated($migration, $direction, date('Y-m-d H:i:s', $startTime), date('Y-m-d H:i:s', time())); }
php
public function executeMigration(MigrationInterface $migration, $direction = MigrationInterface::UP, $fake = false) { $direction = ($direction === MigrationInterface::UP) ? MigrationInterface::UP : MigrationInterface::DOWN; $migration->setMigratingUp($direction === MigrationInterface::UP); $startTime = time(); $migration->setAdapter($this->getAdapter()); if (!$fake) { // begin the transaction if the adapter supports it if ($this->getAdapter()->hasTransactions()) { $this->getAdapter()->beginTransaction(); } // Run the migration if (method_exists($migration, MigrationInterface::CHANGE)) { if ($direction === MigrationInterface::DOWN) { // Create an instance of the ProxyAdapter so we can record all // of the migration commands for reverse playback /** @var \Phinx\Db\Adapter\ProxyAdapter $proxyAdapter */ $proxyAdapter = AdapterFactory::instance() ->getWrapper('proxy', $this->getAdapter()); $migration->setAdapter($proxyAdapter); /** @noinspection PhpUndefinedMethodInspection */ $migration->change(); $proxyAdapter->executeInvertedCommands(); $migration->setAdapter($this->getAdapter()); } else { /** @noinspection PhpUndefinedMethodInspection */ $migration->change(); } } else { $migration->{$direction}(); } // commit the transaction if the adapter supports it if ($this->getAdapter()->hasTransactions()) { $this->getAdapter()->commitTransaction(); } } // Record it in the database $this->getAdapter()->migrated($migration, $direction, date('Y-m-d H:i:s', $startTime), date('Y-m-d H:i:s', time())); }
[ "public", "function", "executeMigration", "(", "MigrationInterface", "$", "migration", ",", "$", "direction", "=", "MigrationInterface", "::", "UP", ",", "$", "fake", "=", "false", ")", "{", "$", "direction", "=", "(", "$", "direction", "===", "MigrationInterface", "::", "UP", ")", "?", "MigrationInterface", "::", "UP", ":", "MigrationInterface", "::", "DOWN", ";", "$", "migration", "->", "setMigratingUp", "(", "$", "direction", "===", "MigrationInterface", "::", "UP", ")", ";", "$", "startTime", "=", "time", "(", ")", ";", "$", "migration", "->", "setAdapter", "(", "$", "this", "->", "getAdapter", "(", ")", ")", ";", "if", "(", "!", "$", "fake", ")", "{", "// begin the transaction if the adapter supports it", "if", "(", "$", "this", "->", "getAdapter", "(", ")", "->", "hasTransactions", "(", ")", ")", "{", "$", "this", "->", "getAdapter", "(", ")", "->", "beginTransaction", "(", ")", ";", "}", "// Run the migration", "if", "(", "method_exists", "(", "$", "migration", ",", "MigrationInterface", "::", "CHANGE", ")", ")", "{", "if", "(", "$", "direction", "===", "MigrationInterface", "::", "DOWN", ")", "{", "// Create an instance of the ProxyAdapter so we can record all", "// of the migration commands for reverse playback", "/** @var \\Phinx\\Db\\Adapter\\ProxyAdapter $proxyAdapter */", "$", "proxyAdapter", "=", "AdapterFactory", "::", "instance", "(", ")", "->", "getWrapper", "(", "'proxy'", ",", "$", "this", "->", "getAdapter", "(", ")", ")", ";", "$", "migration", "->", "setAdapter", "(", "$", "proxyAdapter", ")", ";", "/** @noinspection PhpUndefinedMethodInspection */", "$", "migration", "->", "change", "(", ")", ";", "$", "proxyAdapter", "->", "executeInvertedCommands", "(", ")", ";", "$", "migration", "->", "setAdapter", "(", "$", "this", "->", "getAdapter", "(", ")", ")", ";", "}", "else", "{", "/** @noinspection PhpUndefinedMethodInspection */", "$", "migration", "->", "change", "(", ")", ";", "}", "}", "else", "{", "$", "migration", "->", "{", "$", "direction", "}", "(", ")", ";", "}", "// commit the transaction if the adapter supports it", "if", "(", "$", "this", "->", "getAdapter", "(", ")", "->", "hasTransactions", "(", ")", ")", "{", "$", "this", "->", "getAdapter", "(", ")", "->", "commitTransaction", "(", ")", ";", "}", "}", "// Record it in the database", "$", "this", "->", "getAdapter", "(", ")", "->", "migrated", "(", "$", "migration", ",", "$", "direction", ",", "date", "(", "'Y-m-d H:i:s'", ",", "$", "startTime", ")", ",", "date", "(", "'Y-m-d H:i:s'", ",", "time", "(", ")", ")", ")", ";", "}" ]
Executes the specified migration on this environment. @param \Phinx\Migration\MigrationInterface $migration Migration @param string $direction Direction @param bool $fake flag that if true, we just record running the migration, but not actually do the migration @return void
[ "Executes", "the", "specified", "migration", "on", "this", "environment", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Migration/Manager/Environment.php#L95-L139
train
cakephp/phinx
src/Phinx/Migration/Manager/Environment.php
Environment.executeSeed
public function executeSeed(SeedInterface $seed) { $seed->setAdapter($this->getAdapter()); // begin the transaction if the adapter supports it if ($this->getAdapter()->hasTransactions()) { $this->getAdapter()->beginTransaction(); } // Run the seeder if (method_exists($seed, SeedInterface::RUN)) { $seed->run(); } // commit the transaction if the adapter supports it if ($this->getAdapter()->hasTransactions()) { $this->getAdapter()->commitTransaction(); } }
php
public function executeSeed(SeedInterface $seed) { $seed->setAdapter($this->getAdapter()); // begin the transaction if the adapter supports it if ($this->getAdapter()->hasTransactions()) { $this->getAdapter()->beginTransaction(); } // Run the seeder if (method_exists($seed, SeedInterface::RUN)) { $seed->run(); } // commit the transaction if the adapter supports it if ($this->getAdapter()->hasTransactions()) { $this->getAdapter()->commitTransaction(); } }
[ "public", "function", "executeSeed", "(", "SeedInterface", "$", "seed", ")", "{", "$", "seed", "->", "setAdapter", "(", "$", "this", "->", "getAdapter", "(", ")", ")", ";", "// begin the transaction if the adapter supports it", "if", "(", "$", "this", "->", "getAdapter", "(", ")", "->", "hasTransactions", "(", ")", ")", "{", "$", "this", "->", "getAdapter", "(", ")", "->", "beginTransaction", "(", ")", ";", "}", "// Run the seeder", "if", "(", "method_exists", "(", "$", "seed", ",", "SeedInterface", "::", "RUN", ")", ")", "{", "$", "seed", "->", "run", "(", ")", ";", "}", "// commit the transaction if the adapter supports it", "if", "(", "$", "this", "->", "getAdapter", "(", ")", "->", "hasTransactions", "(", ")", ")", "{", "$", "this", "->", "getAdapter", "(", ")", "->", "commitTransaction", "(", ")", ";", "}", "}" ]
Executes the specified seeder on this environment. @param \Phinx\Seed\SeedInterface $seed @return void
[ "Executes", "the", "specified", "seeder", "on", "this", "environment", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Migration/Manager/Environment.php#L147-L165
train
cakephp/phinx
src/Phinx/Migration/Manager/Environment.php
Environment.parseAgnosticDsn
protected function parseAgnosticDsn(array $options) { if (isset($options['dsn']) && is_string($options['dsn'])) { $regex = '#^(?P<adapter>[^\\:]+)\\://(?:(?P<user>[^\\:@]+)(?:\\:(?P<pass>[^@]*))?@)?' . '(?P<host>[^\\:@/]+)(?:\\:(?P<port>[1-9]\\d*))?/(?P<name>[^\?]+)(?:\?(?P<query>.*))?$#'; if (preg_match($regex, trim($options['dsn']), $parsedOptions)) { $additionalOpts = []; if (isset($parsedOptions['query'])) { parse_str($parsedOptions['query'], $additionalOpts); } $validOptions = ['adapter', 'user', 'pass', 'host', 'port', 'name']; $parsedOptions = array_filter(array_intersect_key($parsedOptions, array_flip($validOptions))); $options = array_merge($additionalOpts, $parsedOptions, $options); unset($options['dsn']); } } return $options; }
php
protected function parseAgnosticDsn(array $options) { if (isset($options['dsn']) && is_string($options['dsn'])) { $regex = '#^(?P<adapter>[^\\:]+)\\://(?:(?P<user>[^\\:@]+)(?:\\:(?P<pass>[^@]*))?@)?' . '(?P<host>[^\\:@/]+)(?:\\:(?P<port>[1-9]\\d*))?/(?P<name>[^\?]+)(?:\?(?P<query>.*))?$#'; if (preg_match($regex, trim($options['dsn']), $parsedOptions)) { $additionalOpts = []; if (isset($parsedOptions['query'])) { parse_str($parsedOptions['query'], $additionalOpts); } $validOptions = ['adapter', 'user', 'pass', 'host', 'port', 'name']; $parsedOptions = array_filter(array_intersect_key($parsedOptions, array_flip($validOptions))); $options = array_merge($additionalOpts, $parsedOptions, $options); unset($options['dsn']); } } return $options; }
[ "protected", "function", "parseAgnosticDsn", "(", "array", "$", "options", ")", "{", "if", "(", "isset", "(", "$", "options", "[", "'dsn'", "]", ")", "&&", "is_string", "(", "$", "options", "[", "'dsn'", "]", ")", ")", "{", "$", "regex", "=", "'#^(?P<adapter>[^\\\\:]+)\\\\://(?:(?P<user>[^\\\\:@]+)(?:\\\\:(?P<pass>[^@]*))?@)?'", ".", "'(?P<host>[^\\\\:@/]+)(?:\\\\:(?P<port>[1-9]\\\\d*))?/(?P<name>[^\\?]+)(?:\\?(?P<query>.*))?$#'", ";", "if", "(", "preg_match", "(", "$", "regex", ",", "trim", "(", "$", "options", "[", "'dsn'", "]", ")", ",", "$", "parsedOptions", ")", ")", "{", "$", "additionalOpts", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "parsedOptions", "[", "'query'", "]", ")", ")", "{", "parse_str", "(", "$", "parsedOptions", "[", "'query'", "]", ",", "$", "additionalOpts", ")", ";", "}", "$", "validOptions", "=", "[", "'adapter'", ",", "'user'", ",", "'pass'", ",", "'host'", ",", "'port'", ",", "'name'", "]", ";", "$", "parsedOptions", "=", "array_filter", "(", "array_intersect_key", "(", "$", "parsedOptions", ",", "array_flip", "(", "$", "validOptions", ")", ")", ")", ";", "$", "options", "=", "array_merge", "(", "$", "additionalOpts", ",", "$", "parsedOptions", ",", "$", "options", ")", ";", "unset", "(", "$", "options", "[", "'dsn'", "]", ")", ";", "}", "}", "return", "$", "options", ";", "}" ]
Parse a database-agnostic DSN into individual options. @param array $options Options @return array
[ "Parse", "a", "database", "-", "agnostic", "DSN", "into", "individual", "options", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Migration/Manager/Environment.php#L219-L237
train
cakephp/phinx
src/Phinx/Migration/Manager/Environment.php
Environment.getCurrentVersion
public function getCurrentVersion() { // We don't cache this code as the current version is pretty volatile. // TODO - that means they're no point in a setter then? // maybe we should cache and call a reset() method every time a migration is run $versions = $this->getVersions(); $version = 0; if (!empty($versions)) { $version = end($versions); } $this->setCurrentVersion($version); return $this->currentVersion; }
php
public function getCurrentVersion() { // We don't cache this code as the current version is pretty volatile. // TODO - that means they're no point in a setter then? // maybe we should cache and call a reset() method every time a migration is run $versions = $this->getVersions(); $version = 0; if (!empty($versions)) { $version = end($versions); } $this->setCurrentVersion($version); return $this->currentVersion; }
[ "public", "function", "getCurrentVersion", "(", ")", "{", "// We don't cache this code as the current version is pretty volatile.", "// TODO - that means they're no point in a setter then?", "// maybe we should cache and call a reset() method every time a migration is run", "$", "versions", "=", "$", "this", "->", "getVersions", "(", ")", ";", "$", "version", "=", "0", ";", "if", "(", "!", "empty", "(", "$", "versions", ")", ")", "{", "$", "version", "=", "end", "(", "$", "versions", ")", ";", "}", "$", "this", "->", "setCurrentVersion", "(", "$", "version", ")", ";", "return", "$", "this", "->", "currentVersion", ";", "}" ]
Gets the current version of the environment. @return int
[ "Gets", "the", "current", "version", "of", "the", "environment", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Migration/Manager/Environment.php#L324-L339
train
cakephp/phinx
src/Phinx/Db/Action/AddIndex.php
AddIndex.build
public static function build(Table $table, $columns, array $options = []) { // create a new index object if strings or an array of strings were supplied $index = $columns; if (!$columns instanceof Index) { $index = new Index(); if (is_string($columns)) { $columns = [$columns]; // str to array } $index->setColumns($columns); $index->setOptions($options); } return new static($table, $index); }
php
public static function build(Table $table, $columns, array $options = []) { // create a new index object if strings or an array of strings were supplied $index = $columns; if (!$columns instanceof Index) { $index = new Index(); if (is_string($columns)) { $columns = [$columns]; // str to array } $index->setColumns($columns); $index->setOptions($options); } return new static($table, $index); }
[ "public", "static", "function", "build", "(", "Table", "$", "table", ",", "$", "columns", ",", "array", "$", "options", "=", "[", "]", ")", "{", "// create a new index object if strings or an array of strings were supplied", "$", "index", "=", "$", "columns", ";", "if", "(", "!", "$", "columns", "instanceof", "Index", ")", "{", "$", "index", "=", "new", "Index", "(", ")", ";", "if", "(", "is_string", "(", "$", "columns", ")", ")", "{", "$", "columns", "=", "[", "$", "columns", "]", ";", "// str to array", "}", "$", "index", "->", "setColumns", "(", "$", "columns", ")", ";", "$", "index", "->", "setOptions", "(", "$", "options", ")", ";", "}", "return", "new", "static", "(", "$", "table", ",", "$", "index", ")", ";", "}" ]
Creates a new AddIndex object after building the index object with the provided arguments @param Table $table The table to add the index to @param mixed $columns The columns to index @param array $options Additional options for the index creation @return AddIndex
[ "Creates", "a", "new", "AddIndex", "object", "after", "building", "the", "index", "object", "with", "the", "provided", "arguments" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Action/AddIndex.php#L60-L77
train
cakephp/phinx
src/Phinx/Db/Adapter/PostgresAdapter.php
PostgresAdapter.getDefaultValueDefinition
protected function getDefaultValueDefinition($default, $columnType = null) { if (is_string($default) && 'CURRENT_TIMESTAMP' !== $default) { $default = $this->getConnection()->quote($default); } elseif (is_bool($default)) { $default = $this->castToBool($default); } elseif ($columnType === static::PHINX_TYPE_BOOLEAN) { $default = $this->castToBool((bool)$default); } return isset($default) ? 'DEFAULT ' . $default : ''; }
php
protected function getDefaultValueDefinition($default, $columnType = null) { if (is_string($default) && 'CURRENT_TIMESTAMP' !== $default) { $default = $this->getConnection()->quote($default); } elseif (is_bool($default)) { $default = $this->castToBool($default); } elseif ($columnType === static::PHINX_TYPE_BOOLEAN) { $default = $this->castToBool((bool)$default); } return isset($default) ? 'DEFAULT ' . $default : ''; }
[ "protected", "function", "getDefaultValueDefinition", "(", "$", "default", ",", "$", "columnType", "=", "null", ")", "{", "if", "(", "is_string", "(", "$", "default", ")", "&&", "'CURRENT_TIMESTAMP'", "!==", "$", "default", ")", "{", "$", "default", "=", "$", "this", "->", "getConnection", "(", ")", "->", "quote", "(", "$", "default", ")", ";", "}", "elseif", "(", "is_bool", "(", "$", "default", ")", ")", "{", "$", "default", "=", "$", "this", "->", "castToBool", "(", "$", "default", ")", ";", "}", "elseif", "(", "$", "columnType", "===", "static", "::", "PHINX_TYPE_BOOLEAN", ")", "{", "$", "default", "=", "$", "this", "->", "castToBool", "(", "(", "bool", ")", "$", "default", ")", ";", "}", "return", "isset", "(", "$", "default", ")", "?", "'DEFAULT '", ".", "$", "default", ":", "''", ";", "}" ]
Get the defintion for a `DEFAULT` statement. @param mixed $default default value @param string $columnType column type added @return string
[ "Get", "the", "defintion", "for", "a", "DEFAULT", "statement", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Adapter/PostgresAdapter.php#L1080-L1091
train
cakephp/phinx
src/Phinx/Db/Adapter/PostgresAdapter.php
PostgresAdapter.getColumnCommentSqlDefinition
protected function getColumnCommentSqlDefinition(Column $column, $tableName) { // passing 'null' is to remove column comment $comment = (strcasecmp($column->getComment(), 'NULL') !== 0) ? $this->getConnection()->quote($column->getComment()) : 'NULL'; return sprintf( 'COMMENT ON COLUMN %s.%s IS %s;', $this->quoteTableName($tableName), $this->quoteColumnName($column->getName()), $comment ); }
php
protected function getColumnCommentSqlDefinition(Column $column, $tableName) { // passing 'null' is to remove column comment $comment = (strcasecmp($column->getComment(), 'NULL') !== 0) ? $this->getConnection()->quote($column->getComment()) : 'NULL'; return sprintf( 'COMMENT ON COLUMN %s.%s IS %s;', $this->quoteTableName($tableName), $this->quoteColumnName($column->getName()), $comment ); }
[ "protected", "function", "getColumnCommentSqlDefinition", "(", "Column", "$", "column", ",", "$", "tableName", ")", "{", "// passing 'null' is to remove column comment", "$", "comment", "=", "(", "strcasecmp", "(", "$", "column", "->", "getComment", "(", ")", ",", "'NULL'", ")", "!==", "0", ")", "?", "$", "this", "->", "getConnection", "(", ")", "->", "quote", "(", "$", "column", "->", "getComment", "(", ")", ")", ":", "'NULL'", ";", "return", "sprintf", "(", "'COMMENT ON COLUMN %s.%s IS %s;'", ",", "$", "this", "->", "quoteTableName", "(", "$", "tableName", ")", ",", "$", "this", "->", "quoteColumnName", "(", "$", "column", "->", "getName", "(", ")", ")", ",", "$", "comment", ")", ";", "}" ]
Gets the PostgreSQL Column Comment Definition for a column object. @param \Phinx\Db\Table\Column $column Column @param string $tableName Table name @return string
[ "Gets", "the", "PostgreSQL", "Column", "Comment", "Definition", "for", "a", "column", "object", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Adapter/PostgresAdapter.php#L1155-L1168
train
cakephp/phinx
src/Phinx/Db/Adapter/PostgresAdapter.php
PostgresAdapter.dropSchema
public function dropSchema($schemaName) { $sql = sprintf("DROP SCHEMA IF EXISTS %s CASCADE;", $this->quoteSchemaName($schemaName)); $this->execute($sql); }
php
public function dropSchema($schemaName) { $sql = sprintf("DROP SCHEMA IF EXISTS %s CASCADE;", $this->quoteSchemaName($schemaName)); $this->execute($sql); }
[ "public", "function", "dropSchema", "(", "$", "schemaName", ")", "{", "$", "sql", "=", "sprintf", "(", "\"DROP SCHEMA IF EXISTS %s CASCADE;\"", ",", "$", "this", "->", "quoteSchemaName", "(", "$", "schemaName", ")", ")", ";", "$", "this", "->", "execute", "(", "$", "sql", ")", ";", "}" ]
Drops the specified schema table. @param string $schemaName Schema name @return void
[ "Drops", "the", "specified", "schema", "table", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Adapter/PostgresAdapter.php#L1277-L1281
train
cakephp/phinx
src/Phinx/Db/Adapter/PostgresAdapter.php
PostgresAdapter.getAllSchemas
public function getAllSchemas() { $sql = "SELECT schema_name FROM information_schema.schemata WHERE schema_name <> 'information_schema' AND schema_name !~ '^pg_'"; $items = $this->fetchAll($sql); $schemaNames = []; foreach ($items as $item) { $schemaNames[] = $item['schema_name']; } return $schemaNames; }
php
public function getAllSchemas() { $sql = "SELECT schema_name FROM information_schema.schemata WHERE schema_name <> 'information_schema' AND schema_name !~ '^pg_'"; $items = $this->fetchAll($sql); $schemaNames = []; foreach ($items as $item) { $schemaNames[] = $item['schema_name']; } return $schemaNames; }
[ "public", "function", "getAllSchemas", "(", ")", "{", "$", "sql", "=", "\"SELECT schema_name\n FROM information_schema.schemata\n WHERE schema_name <> 'information_schema' AND schema_name !~ '^pg_'\"", ";", "$", "items", "=", "$", "this", "->", "fetchAll", "(", "$", "sql", ")", ";", "$", "schemaNames", "=", "[", "]", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "$", "schemaNames", "[", "]", "=", "$", "item", "[", "'schema_name'", "]", ";", "}", "return", "$", "schemaNames", ";", "}" ]
Returns schemas. @return array
[ "Returns", "schemas", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Adapter/PostgresAdapter.php#L1300-L1312
train
cakephp/phinx
src/Phinx/Db/Adapter/MysqlAdapter.php
MysqlAdapter.getColumnSqlDefinition
protected function getColumnSqlDefinition(Column $column) { if ($column->getType() instanceof Literal) { $def = (string)$column->getType(); } else { $sqlType = $this->getSqlType($column->getType(), $column->getLimit()); $def = strtoupper($sqlType['name']); } if ($column->getPrecision() && $column->getScale()) { $def .= '(' . $column->getPrecision() . ',' . $column->getScale() . ')'; } elseif (isset($sqlType['limit'])) { $def .= '(' . $sqlType['limit'] . ')'; } if (($values = $column->getValues()) && is_array($values)) { $def .= "('" . implode("', '", $values) . "')"; } $def .= $column->getEncoding() ? ' CHARACTER SET ' . $column->getEncoding() : ''; $def .= $column->getCollation() ? ' COLLATE ' . $column->getCollation() : ''; $def .= (!$column->isSigned() && isset($this->signedColumnTypes[$column->getType()])) ? ' unsigned' : ''; $def .= ($column->isNull() == false) ? ' NOT NULL' : ' NULL'; $def .= $column->isIdentity() ? ' AUTO_INCREMENT' : ''; $def .= $this->getDefaultValueDefinition($column->getDefault(), $column->getType()); if ($column->getComment()) { $def .= ' COMMENT ' . $this->getConnection()->quote($column->getComment()); } if ($column->getUpdate()) { $def .= ' ON UPDATE ' . $column->getUpdate(); } return $def; }
php
protected function getColumnSqlDefinition(Column $column) { if ($column->getType() instanceof Literal) { $def = (string)$column->getType(); } else { $sqlType = $this->getSqlType($column->getType(), $column->getLimit()); $def = strtoupper($sqlType['name']); } if ($column->getPrecision() && $column->getScale()) { $def .= '(' . $column->getPrecision() . ',' . $column->getScale() . ')'; } elseif (isset($sqlType['limit'])) { $def .= '(' . $sqlType['limit'] . ')'; } if (($values = $column->getValues()) && is_array($values)) { $def .= "('" . implode("', '", $values) . "')"; } $def .= $column->getEncoding() ? ' CHARACTER SET ' . $column->getEncoding() : ''; $def .= $column->getCollation() ? ' COLLATE ' . $column->getCollation() : ''; $def .= (!$column->isSigned() && isset($this->signedColumnTypes[$column->getType()])) ? ' unsigned' : ''; $def .= ($column->isNull() == false) ? ' NOT NULL' : ' NULL'; $def .= $column->isIdentity() ? ' AUTO_INCREMENT' : ''; $def .= $this->getDefaultValueDefinition($column->getDefault(), $column->getType()); if ($column->getComment()) { $def .= ' COMMENT ' . $this->getConnection()->quote($column->getComment()); } if ($column->getUpdate()) { $def .= ' ON UPDATE ' . $column->getUpdate(); } return $def; }
[ "protected", "function", "getColumnSqlDefinition", "(", "Column", "$", "column", ")", "{", "if", "(", "$", "column", "->", "getType", "(", ")", "instanceof", "Literal", ")", "{", "$", "def", "=", "(", "string", ")", "$", "column", "->", "getType", "(", ")", ";", "}", "else", "{", "$", "sqlType", "=", "$", "this", "->", "getSqlType", "(", "$", "column", "->", "getType", "(", ")", ",", "$", "column", "->", "getLimit", "(", ")", ")", ";", "$", "def", "=", "strtoupper", "(", "$", "sqlType", "[", "'name'", "]", ")", ";", "}", "if", "(", "$", "column", "->", "getPrecision", "(", ")", "&&", "$", "column", "->", "getScale", "(", ")", ")", "{", "$", "def", ".=", "'('", ".", "$", "column", "->", "getPrecision", "(", ")", ".", "','", ".", "$", "column", "->", "getScale", "(", ")", ".", "')'", ";", "}", "elseif", "(", "isset", "(", "$", "sqlType", "[", "'limit'", "]", ")", ")", "{", "$", "def", ".=", "'('", ".", "$", "sqlType", "[", "'limit'", "]", ".", "')'", ";", "}", "if", "(", "(", "$", "values", "=", "$", "column", "->", "getValues", "(", ")", ")", "&&", "is_array", "(", "$", "values", ")", ")", "{", "$", "def", ".=", "\"('\"", ".", "implode", "(", "\"', '\"", ",", "$", "values", ")", ".", "\"')\"", ";", "}", "$", "def", ".=", "$", "column", "->", "getEncoding", "(", ")", "?", "' CHARACTER SET '", ".", "$", "column", "->", "getEncoding", "(", ")", ":", "''", ";", "$", "def", ".=", "$", "column", "->", "getCollation", "(", ")", "?", "' COLLATE '", ".", "$", "column", "->", "getCollation", "(", ")", ":", "''", ";", "$", "def", ".=", "(", "!", "$", "column", "->", "isSigned", "(", ")", "&&", "isset", "(", "$", "this", "->", "signedColumnTypes", "[", "$", "column", "->", "getType", "(", ")", "]", ")", ")", "?", "' unsigned'", ":", "''", ";", "$", "def", ".=", "(", "$", "column", "->", "isNull", "(", ")", "==", "false", ")", "?", "' NOT NULL'", ":", "' NULL'", ";", "$", "def", ".=", "$", "column", "->", "isIdentity", "(", ")", "?", "' AUTO_INCREMENT'", ":", "''", ";", "$", "def", ".=", "$", "this", "->", "getDefaultValueDefinition", "(", "$", "column", "->", "getDefault", "(", ")", ",", "$", "column", "->", "getType", "(", ")", ")", ";", "if", "(", "$", "column", "->", "getComment", "(", ")", ")", "{", "$", "def", ".=", "' COMMENT '", ".", "$", "this", "->", "getConnection", "(", ")", "->", "quote", "(", "$", "column", "->", "getComment", "(", ")", ")", ";", "}", "if", "(", "$", "column", "->", "getUpdate", "(", ")", ")", "{", "$", "def", ".=", "' ON UPDATE '", ".", "$", "column", "->", "getUpdate", "(", ")", ";", "}", "return", "$", "def", ";", "}" ]
Gets the MySQL Column Definition for a Column object. @param \Phinx\Db\Table\Column $column Column @return string
[ "Gets", "the", "MySQL", "Column", "Definition", "for", "a", "Column", "object", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Adapter/MysqlAdapter.php#L1115-L1147
train
cakephp/phinx
src/Phinx/Db/Adapter/MysqlAdapter.php
MysqlAdapter.describeTable
public function describeTable($tableName) { $options = $this->getOptions(); // mysql specific $sql = sprintf( "SELECT * FROM information_schema.tables WHERE table_schema = '%s' AND table_name = '%s'", $options['name'], $tableName ); return $this->fetchRow($sql); }
php
public function describeTable($tableName) { $options = $this->getOptions(); // mysql specific $sql = sprintf( "SELECT * FROM information_schema.tables WHERE table_schema = '%s' AND table_name = '%s'", $options['name'], $tableName ); return $this->fetchRow($sql); }
[ "public", "function", "describeTable", "(", "$", "tableName", ")", "{", "$", "options", "=", "$", "this", "->", "getOptions", "(", ")", ";", "// mysql specific", "$", "sql", "=", "sprintf", "(", "\"SELECT *\n FROM information_schema.tables\n WHERE table_schema = '%s'\n AND table_name = '%s'\"", ",", "$", "options", "[", "'name'", "]", ",", "$", "tableName", ")", ";", "return", "$", "this", "->", "fetchRow", "(", "$", "sql", ")", ";", "}" ]
Describes a database table. This is a MySQL adapter specific method. @param string $tableName Table name @return array
[ "Describes", "a", "database", "table", ".", "This", "is", "a", "MySQL", "adapter", "specific", "method", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Adapter/MysqlAdapter.php#L1232-L1247
train
cakephp/phinx
src/Phinx/Migration/Manager.php
Manager.printMissingVersion
private function printMissingVersion($version, $maxNameLength) { $this->getOutput()->writeln(sprintf( ' <error>up</error> %14.0f %19s %19s <comment>%s</comment> <error>** MISSING **</error>', $version['version'], $version['start_time'], $version['end_time'], str_pad($version['migration_name'], $maxNameLength, ' ') )); if ($version && $version['breakpoint']) { $this->getOutput()->writeln(' <error>BREAKPOINT SET</error>'); } }
php
private function printMissingVersion($version, $maxNameLength) { $this->getOutput()->writeln(sprintf( ' <error>up</error> %14.0f %19s %19s <comment>%s</comment> <error>** MISSING **</error>', $version['version'], $version['start_time'], $version['end_time'], str_pad($version['migration_name'], $maxNameLength, ' ') )); if ($version && $version['breakpoint']) { $this->getOutput()->writeln(' <error>BREAKPOINT SET</error>'); } }
[ "private", "function", "printMissingVersion", "(", "$", "version", ",", "$", "maxNameLength", ")", "{", "$", "this", "->", "getOutput", "(", ")", "->", "writeln", "(", "sprintf", "(", "' <error>up</error> %14.0f %19s %19s <comment>%s</comment> <error>** MISSING **</error>'", ",", "$", "version", "[", "'version'", "]", ",", "$", "version", "[", "'start_time'", "]", ",", "$", "version", "[", "'end_time'", "]", ",", "str_pad", "(", "$", "version", "[", "'migration_name'", "]", ",", "$", "maxNameLength", ",", "' '", ")", ")", ")", ";", "if", "(", "$", "version", "&&", "$", "version", "[", "'breakpoint'", "]", ")", "{", "$", "this", "->", "getOutput", "(", ")", "->", "writeln", "(", "' <error>BREAKPOINT SET</error>'", ")", ";", "}", "}" ]
Print Missing Version @param array $version The missing version to print (in the format returned by Environment.getVersionLog). @param int $maxNameLength The maximum migration name length.
[ "Print", "Missing", "Version" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Migration/Manager.php#L264-L277
train
cakephp/phinx
src/Phinx/Migration/Manager.php
Manager.migrateToDateTime
public function migrateToDateTime($environment, \DateTime $dateTime, $fake = false) { $versions = array_keys($this->getMigrations($environment)); $dateString = $dateTime->format('YmdHis'); $outstandingMigrations = array_filter($versions, function ($version) use ($dateString) { return $version <= $dateString; }); if (count($outstandingMigrations) > 0) { $migration = max($outstandingMigrations); $this->getOutput()->writeln('Migrating to version ' . $migration); $this->migrate($environment, $migration, $fake); } }
php
public function migrateToDateTime($environment, \DateTime $dateTime, $fake = false) { $versions = array_keys($this->getMigrations($environment)); $dateString = $dateTime->format('YmdHis'); $outstandingMigrations = array_filter($versions, function ($version) use ($dateString) { return $version <= $dateString; }); if (count($outstandingMigrations) > 0) { $migration = max($outstandingMigrations); $this->getOutput()->writeln('Migrating to version ' . $migration); $this->migrate($environment, $migration, $fake); } }
[ "public", "function", "migrateToDateTime", "(", "$", "environment", ",", "\\", "DateTime", "$", "dateTime", ",", "$", "fake", "=", "false", ")", "{", "$", "versions", "=", "array_keys", "(", "$", "this", "->", "getMigrations", "(", "$", "environment", ")", ")", ";", "$", "dateString", "=", "$", "dateTime", "->", "format", "(", "'YmdHis'", ")", ";", "$", "outstandingMigrations", "=", "array_filter", "(", "$", "versions", ",", "function", "(", "$", "version", ")", "use", "(", "$", "dateString", ")", "{", "return", "$", "version", "<=", "$", "dateString", ";", "}", ")", ";", "if", "(", "count", "(", "$", "outstandingMigrations", ")", ">", "0", ")", "{", "$", "migration", "=", "max", "(", "$", "outstandingMigrations", ")", ";", "$", "this", "->", "getOutput", "(", ")", "->", "writeln", "(", "'Migrating to version '", ".", "$", "migration", ")", ";", "$", "this", "->", "migrate", "(", "$", "environment", ",", "$", "migration", ",", "$", "fake", ")", ";", "}", "}" ]
Migrate to the version of the database on a given date. @param string $environment Environment @param \DateTime $dateTime Date to migrate to @param bool $fake flag that if true, we just record running the migration, but not actually do the migration @return void
[ "Migrate", "to", "the", "version", "of", "the", "database", "on", "a", "given", "date", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Migration/Manager.php#L289-L303
train
cakephp/phinx
src/Phinx/Migration/Manager.php
Manager.executeMigration
public function executeMigration($name, MigrationInterface $migration, $direction = MigrationInterface::UP, $fake = false) { $this->getOutput()->writeln(''); $this->getOutput()->writeln( ' ==' . ' <info>' . $migration->getVersion() . ' ' . $migration->getName() . ':</info>' . ' <comment>' . ($direction === MigrationInterface::UP ? 'migrating' : 'reverting') . '</comment>' ); $migration->preFlightCheck($direction); // Execute the migration and log the time elapsed. $start = microtime(true); $this->getEnvironment($name)->executeMigration($migration, $direction, $fake); $end = microtime(true); $migration->postFlightCheck($direction); $this->getOutput()->writeln( ' ==' . ' <info>' . $migration->getVersion() . ' ' . $migration->getName() . ':</info>' . ' <comment>' . ($direction === MigrationInterface::UP ? 'migrated' : 'reverted') . ' ' . sprintf('%.4fs', $end - $start) . '</comment>' ); }
php
public function executeMigration($name, MigrationInterface $migration, $direction = MigrationInterface::UP, $fake = false) { $this->getOutput()->writeln(''); $this->getOutput()->writeln( ' ==' . ' <info>' . $migration->getVersion() . ' ' . $migration->getName() . ':</info>' . ' <comment>' . ($direction === MigrationInterface::UP ? 'migrating' : 'reverting') . '</comment>' ); $migration->preFlightCheck($direction); // Execute the migration and log the time elapsed. $start = microtime(true); $this->getEnvironment($name)->executeMigration($migration, $direction, $fake); $end = microtime(true); $migration->postFlightCheck($direction); $this->getOutput()->writeln( ' ==' . ' <info>' . $migration->getVersion() . ' ' . $migration->getName() . ':</info>' . ' <comment>' . ($direction === MigrationInterface::UP ? 'migrated' : 'reverted') . ' ' . sprintf('%.4fs', $end - $start) . '</comment>' ); }
[ "public", "function", "executeMigration", "(", "$", "name", ",", "MigrationInterface", "$", "migration", ",", "$", "direction", "=", "MigrationInterface", "::", "UP", ",", "$", "fake", "=", "false", ")", "{", "$", "this", "->", "getOutput", "(", ")", "->", "writeln", "(", "''", ")", ";", "$", "this", "->", "getOutput", "(", ")", "->", "writeln", "(", "' =='", ".", "' <info>'", ".", "$", "migration", "->", "getVersion", "(", ")", ".", "' '", ".", "$", "migration", "->", "getName", "(", ")", ".", "':</info>'", ".", "' <comment>'", ".", "(", "$", "direction", "===", "MigrationInterface", "::", "UP", "?", "'migrating'", ":", "'reverting'", ")", ".", "'</comment>'", ")", ";", "$", "migration", "->", "preFlightCheck", "(", "$", "direction", ")", ";", "// Execute the migration and log the time elapsed.", "$", "start", "=", "microtime", "(", "true", ")", ";", "$", "this", "->", "getEnvironment", "(", "$", "name", ")", "->", "executeMigration", "(", "$", "migration", ",", "$", "direction", ",", "$", "fake", ")", ";", "$", "end", "=", "microtime", "(", "true", ")", ";", "$", "migration", "->", "postFlightCheck", "(", "$", "direction", ")", ";", "$", "this", "->", "getOutput", "(", ")", "->", "writeln", "(", "' =='", ".", "' <info>'", ".", "$", "migration", "->", "getVersion", "(", ")", ".", "' '", ".", "$", "migration", "->", "getName", "(", ")", ".", "':</info>'", ".", "' <comment>'", ".", "(", "$", "direction", "===", "MigrationInterface", "::", "UP", "?", "'migrated'", ":", "'reverted'", ")", ".", "' '", ".", "sprintf", "(", "'%.4fs'", ",", "$", "end", "-", "$", "start", ")", ".", "'</comment>'", ")", ";", "}" ]
Execute a migration against the specified environment. @param string $name Environment Name @param \Phinx\Migration\MigrationInterface $migration Migration @param string $direction Direction @param bool $fake flag that if true, we just record running the migration, but not actually do the migration @return void
[ "Execute", "a", "migration", "against", "the", "specified", "environment", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Migration/Manager.php#L375-L397
train
cakephp/phinx
src/Phinx/Migration/Manager.php
Manager.executeSeed
public function executeSeed($name, SeedInterface $seed) { $this->getOutput()->writeln(''); $this->getOutput()->writeln( ' ==' . ' <info>' . $seed->getName() . ':</info>' . ' <comment>seeding</comment>' ); // Execute the seeder and log the time elapsed. $start = microtime(true); $this->getEnvironment($name)->executeSeed($seed); $end = microtime(true); $this->getOutput()->writeln( ' ==' . ' <info>' . $seed->getName() . ':</info>' . ' <comment>seeded' . ' ' . sprintf('%.4fs', $end - $start) . '</comment>' ); }
php
public function executeSeed($name, SeedInterface $seed) { $this->getOutput()->writeln(''); $this->getOutput()->writeln( ' ==' . ' <info>' . $seed->getName() . ':</info>' . ' <comment>seeding</comment>' ); // Execute the seeder and log the time elapsed. $start = microtime(true); $this->getEnvironment($name)->executeSeed($seed); $end = microtime(true); $this->getOutput()->writeln( ' ==' . ' <info>' . $seed->getName() . ':</info>' . ' <comment>seeded' . ' ' . sprintf('%.4fs', $end - $start) . '</comment>' ); }
[ "public", "function", "executeSeed", "(", "$", "name", ",", "SeedInterface", "$", "seed", ")", "{", "$", "this", "->", "getOutput", "(", ")", "->", "writeln", "(", "''", ")", ";", "$", "this", "->", "getOutput", "(", ")", "->", "writeln", "(", "' =='", ".", "' <info>'", ".", "$", "seed", "->", "getName", "(", ")", ".", "':</info>'", ".", "' <comment>seeding</comment>'", ")", ";", "// Execute the seeder and log the time elapsed.", "$", "start", "=", "microtime", "(", "true", ")", ";", "$", "this", "->", "getEnvironment", "(", "$", "name", ")", "->", "executeSeed", "(", "$", "seed", ")", ";", "$", "end", "=", "microtime", "(", "true", ")", ";", "$", "this", "->", "getOutput", "(", ")", "->", "writeln", "(", "' =='", ".", "' <info>'", ".", "$", "seed", "->", "getName", "(", ")", ".", "':</info>'", ".", "' <comment>seeded'", ".", "' '", ".", "sprintf", "(", "'%.4fs'", ",", "$", "end", "-", "$", "start", ")", ".", "'</comment>'", ")", ";", "}" ]
Execute a seeder against the specified environment. @param string $name Environment Name @param \Phinx\Seed\SeedInterface $seed Seed @return void
[ "Execute", "a", "seeder", "against", "the", "specified", "environment", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Migration/Manager.php#L406-L426
train
cakephp/phinx
src/Phinx/Migration/Manager.php
Manager.seed
public function seed($environment, $seed = null) { $seeds = $this->getSeeds(); if ($seed === null) { // run all seeders foreach ($seeds as $seeder) { if (array_key_exists($seeder->getName(), $seeds)) { $this->executeSeed($environment, $seeder); } } } else { // run only one seeder if (array_key_exists($seed, $seeds)) { $this->executeSeed($environment, $seeds[$seed]); } else { throw new \InvalidArgumentException(sprintf('The seed class "%s" does not exist', $seed)); } } }
php
public function seed($environment, $seed = null) { $seeds = $this->getSeeds(); if ($seed === null) { // run all seeders foreach ($seeds as $seeder) { if (array_key_exists($seeder->getName(), $seeds)) { $this->executeSeed($environment, $seeder); } } } else { // run only one seeder if (array_key_exists($seed, $seeds)) { $this->executeSeed($environment, $seeds[$seed]); } else { throw new \InvalidArgumentException(sprintf('The seed class "%s" does not exist', $seed)); } } }
[ "public", "function", "seed", "(", "$", "environment", ",", "$", "seed", "=", "null", ")", "{", "$", "seeds", "=", "$", "this", "->", "getSeeds", "(", ")", ";", "if", "(", "$", "seed", "===", "null", ")", "{", "// run all seeders", "foreach", "(", "$", "seeds", "as", "$", "seeder", ")", "{", "if", "(", "array_key_exists", "(", "$", "seeder", "->", "getName", "(", ")", ",", "$", "seeds", ")", ")", "{", "$", "this", "->", "executeSeed", "(", "$", "environment", ",", "$", "seeder", ")", ";", "}", "}", "}", "else", "{", "// run only one seeder", "if", "(", "array_key_exists", "(", "$", "seed", ",", "$", "seeds", ")", ")", "{", "$", "this", "->", "executeSeed", "(", "$", "environment", ",", "$", "seeds", "[", "$", "seed", "]", ")", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'The seed class \"%s\" does not exist'", ",", "$", "seed", ")", ")", ";", "}", "}", "}" ]
Run database seeders against an environment. @param string $environment Environment @param string $seed Seeder @return void
[ "Run", "database", "seeders", "against", "an", "environment", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Migration/Manager.php#L546-L565
train
cakephp/phinx
src/Phinx/Migration/Manager.php
Manager.getSeedFiles
protected function getSeedFiles() { $config = $this->getConfig(); $paths = $config->getSeedPaths(); $files = []; foreach ($paths as $path) { $files = array_merge( $files, Util::glob($path . DIRECTORY_SEPARATOR . '*.php') ); } // glob() can return the same file multiple times // This will cause the migration to fail with a // false assumption of duplicate migrations // http://php.net/manual/en/function.glob.php#110340 $files = array_unique($files); return $files; }
php
protected function getSeedFiles() { $config = $this->getConfig(); $paths = $config->getSeedPaths(); $files = []; foreach ($paths as $path) { $files = array_merge( $files, Util::glob($path . DIRECTORY_SEPARATOR . '*.php') ); } // glob() can return the same file multiple times // This will cause the migration to fail with a // false assumption of duplicate migrations // http://php.net/manual/en/function.glob.php#110340 $files = array_unique($files); return $files; }
[ "protected", "function", "getSeedFiles", "(", ")", "{", "$", "config", "=", "$", "this", "->", "getConfig", "(", ")", ";", "$", "paths", "=", "$", "config", "->", "getSeedPaths", "(", ")", ";", "$", "files", "=", "[", "]", ";", "foreach", "(", "$", "paths", "as", "$", "path", ")", "{", "$", "files", "=", "array_merge", "(", "$", "files", ",", "Util", "::", "glob", "(", "$", "path", ".", "DIRECTORY_SEPARATOR", ".", "'*.php'", ")", ")", ";", "}", "// glob() can return the same file multiple times", "// This will cause the migration to fail with a", "// false assumption of duplicate migrations", "// http://php.net/manual/en/function.glob.php#110340", "$", "files", "=", "array_unique", "(", "$", "files", ")", ";", "return", "$", "files", ";", "}" ]
Returns a list of seed files found in the provided seed paths. @return string[]
[ "Returns", "a", "list", "of", "seed", "files", "found", "in", "the", "provided", "seed", "paths", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Migration/Manager.php#L930-L949
train
cakephp/phinx
src/Phinx/Migration/Manager.php
Manager.toggleBreakpoint
public function toggleBreakpoint($environment, $version) { $migrations = $this->getMigrations($environment); $this->getMigrations($environment); $env = $this->getEnvironment($environment); $versions = $env->getVersionLog(); if (empty($versions) || empty($migrations)) { return; } if ($version === null) { $lastVersion = end($versions); $version = $lastVersion['version']; } if (0 != $version && !isset($migrations[$version])) { $this->output->writeln(sprintf( '<comment>warning</comment> %s is not a valid version', $version )); return; } $env->getAdapter()->toggleBreakpoint($migrations[$version]); $versions = $env->getVersionLog(); $this->getOutput()->writeln( ' Breakpoint ' . ($versions[$version]['breakpoint'] ? 'set' : 'cleared') . ' for <info>' . $version . '</info>' . ' <comment>' . $migrations[$version]->getName() . '</comment>' ); }
php
public function toggleBreakpoint($environment, $version) { $migrations = $this->getMigrations($environment); $this->getMigrations($environment); $env = $this->getEnvironment($environment); $versions = $env->getVersionLog(); if (empty($versions) || empty($migrations)) { return; } if ($version === null) { $lastVersion = end($versions); $version = $lastVersion['version']; } if (0 != $version && !isset($migrations[$version])) { $this->output->writeln(sprintf( '<comment>warning</comment> %s is not a valid version', $version )); return; } $env->getAdapter()->toggleBreakpoint($migrations[$version]); $versions = $env->getVersionLog(); $this->getOutput()->writeln( ' Breakpoint ' . ($versions[$version]['breakpoint'] ? 'set' : 'cleared') . ' for <info>' . $version . '</info>' . ' <comment>' . $migrations[$version]->getName() . '</comment>' ); }
[ "public", "function", "toggleBreakpoint", "(", "$", "environment", ",", "$", "version", ")", "{", "$", "migrations", "=", "$", "this", "->", "getMigrations", "(", "$", "environment", ")", ";", "$", "this", "->", "getMigrations", "(", "$", "environment", ")", ";", "$", "env", "=", "$", "this", "->", "getEnvironment", "(", "$", "environment", ")", ";", "$", "versions", "=", "$", "env", "->", "getVersionLog", "(", ")", ";", "if", "(", "empty", "(", "$", "versions", ")", "||", "empty", "(", "$", "migrations", ")", ")", "{", "return", ";", "}", "if", "(", "$", "version", "===", "null", ")", "{", "$", "lastVersion", "=", "end", "(", "$", "versions", ")", ";", "$", "version", "=", "$", "lastVersion", "[", "'version'", "]", ";", "}", "if", "(", "0", "!=", "$", "version", "&&", "!", "isset", "(", "$", "migrations", "[", "$", "version", "]", ")", ")", "{", "$", "this", "->", "output", "->", "writeln", "(", "sprintf", "(", "'<comment>warning</comment> %s is not a valid version'", ",", "$", "version", ")", ")", ";", "return", ";", "}", "$", "env", "->", "getAdapter", "(", ")", "->", "toggleBreakpoint", "(", "$", "migrations", "[", "$", "version", "]", ")", ";", "$", "versions", "=", "$", "env", "->", "getVersionLog", "(", ")", ";", "$", "this", "->", "getOutput", "(", ")", "->", "writeln", "(", "' Breakpoint '", ".", "(", "$", "versions", "[", "$", "version", "]", "[", "'breakpoint'", "]", "?", "'set'", ":", "'cleared'", ")", ".", "' for <info>'", ".", "$", "version", ".", "'</info>'", ".", "' <comment>'", ".", "$", "migrations", "[", "$", "version", "]", "->", "getName", "(", ")", ".", "'</comment>'", ")", ";", "}" ]
Toggles the breakpoint for a specific version. @param string $environment @param int|null $version @return void
[ "Toggles", "the", "breakpoint", "for", "a", "specific", "version", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Migration/Manager.php#L981-L1015
train
cakephp/phinx
src/Phinx/Migration/Manager.php
Manager.removeBreakpoints
public function removeBreakpoints($environment) { $this->getOutput()->writeln(sprintf( ' %d breakpoints cleared.', $this->getEnvironment($environment)->getAdapter()->resetAllBreakpoints() )); }
php
public function removeBreakpoints($environment) { $this->getOutput()->writeln(sprintf( ' %d breakpoints cleared.', $this->getEnvironment($environment)->getAdapter()->resetAllBreakpoints() )); }
[ "public", "function", "removeBreakpoints", "(", "$", "environment", ")", "{", "$", "this", "->", "getOutput", "(", ")", "->", "writeln", "(", "sprintf", "(", "' %d breakpoints cleared.'", ",", "$", "this", "->", "getEnvironment", "(", "$", "environment", ")", "->", "getAdapter", "(", ")", "->", "resetAllBreakpoints", "(", ")", ")", ")", ";", "}" ]
Remove all breakpoints @param string $environment @return void
[ "Remove", "all", "breakpoints" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Migration/Manager.php#L1023-L1029
train
cakephp/phinx
src/Phinx/Db/Table/ForeignKey.php
ForeignKey.normalizeAction
protected function normalizeAction($action) { $constantName = 'static::' . str_replace(' ', '_', strtoupper(trim($action))); if (!defined($constantName)) { throw new \InvalidArgumentException('Unknown action passed: ' . $action); } return constant($constantName); }
php
protected function normalizeAction($action) { $constantName = 'static::' . str_replace(' ', '_', strtoupper(trim($action))); if (!defined($constantName)) { throw new \InvalidArgumentException('Unknown action passed: ' . $action); } return constant($constantName); }
[ "protected", "function", "normalizeAction", "(", "$", "action", ")", "{", "$", "constantName", "=", "'static::'", ".", "str_replace", "(", "' '", ",", "'_'", ",", "strtoupper", "(", "trim", "(", "$", "action", ")", ")", ")", ";", "if", "(", "!", "defined", "(", "$", "constantName", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Unknown action passed: '", ".", "$", "action", ")", ";", "}", "return", "constant", "(", "$", "constantName", ")", ";", "}" ]
From passed value checks if it's correct and fixes if needed @param string $action @throws \InvalidArgumentException @return string
[ "From", "passed", "value", "checks", "if", "it", "s", "correct", "and", "fixes", "if", "needed" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Table/ForeignKey.php#L246-L254
train
cakephp/phinx
src/Phinx/Db/Adapter/SqlServerAdapter.php
SqlServerAdapter.getColumnCommentSqlDefinition
protected function getColumnCommentSqlDefinition(Column $column, $tableName) { // passing 'null' is to remove column comment $currentComment = $this->getColumnComment($tableName, $column->getName()); $comment = (strcasecmp($column->getComment(), 'NULL') !== 0) ? $this->getConnection()->quote($column->getComment()) : '\'\''; $command = $currentComment === false ? 'sp_addextendedproperty' : 'sp_updateextendedproperty'; return sprintf( "EXECUTE %s N'MS_Description', N%s, N'SCHEMA', N'%s', N'TABLE', N'%s', N'COLUMN', N'%s';", $command, $comment, $this->schema, $tableName, $column->getName() ); }
php
protected function getColumnCommentSqlDefinition(Column $column, $tableName) { // passing 'null' is to remove column comment $currentComment = $this->getColumnComment($tableName, $column->getName()); $comment = (strcasecmp($column->getComment(), 'NULL') !== 0) ? $this->getConnection()->quote($column->getComment()) : '\'\''; $command = $currentComment === false ? 'sp_addextendedproperty' : 'sp_updateextendedproperty'; return sprintf( "EXECUTE %s N'MS_Description', N%s, N'SCHEMA', N'%s', N'TABLE', N'%s', N'COLUMN', N'%s';", $command, $comment, $this->schema, $tableName, $column->getName() ); }
[ "protected", "function", "getColumnCommentSqlDefinition", "(", "Column", "$", "column", ",", "$", "tableName", ")", "{", "// passing 'null' is to remove column comment", "$", "currentComment", "=", "$", "this", "->", "getColumnComment", "(", "$", "tableName", ",", "$", "column", "->", "getName", "(", ")", ")", ";", "$", "comment", "=", "(", "strcasecmp", "(", "$", "column", "->", "getComment", "(", ")", ",", "'NULL'", ")", "!==", "0", ")", "?", "$", "this", "->", "getConnection", "(", ")", "->", "quote", "(", "$", "column", "->", "getComment", "(", ")", ")", ":", "'\\'\\''", ";", "$", "command", "=", "$", "currentComment", "===", "false", "?", "'sp_addextendedproperty'", ":", "'sp_updateextendedproperty'", ";", "return", "sprintf", "(", "\"EXECUTE %s N'MS_Description', N%s, N'SCHEMA', N'%s', N'TABLE', N'%s', N'COLUMN', N'%s';\"", ",", "$", "command", ",", "$", "comment", ",", "$", "this", "->", "schema", ",", "$", "tableName", ",", "$", "column", "->", "getName", "(", ")", ")", ";", "}" ]
Gets the SqlServer Column Comment Defininition for a column object. @param \Phinx\Db\Table\Column $column Column @param string $tableName Table name @return string
[ "Gets", "the", "SqlServer", "Column", "Comment", "Defininition", "for", "a", "column", "object", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Adapter/SqlServerAdapter.php#L329-L345
train
cakephp/phinx
src/Phinx/Db/Adapter/SqlServerAdapter.php
SqlServerAdapter.getChangeDefault
protected function getChangeDefault($tableName, Column $newColumn) { $constraintName = "DF_{$tableName}_{$newColumn->getName()}"; $default = $newColumn->getDefault(); $instructions = new AlterInstructions(); if ($default === null) { $default = 'DEFAULT NULL'; } else { $default = ltrim($this->getDefaultValueDefinition($default)); } if (empty($default)) { return $instructions; } $instructions->addPostStep(sprintf( 'ALTER TABLE %s ADD CONSTRAINT %s %s FOR %s', $this->quoteTableName($tableName), $constraintName, $default, $this->quoteColumnName($newColumn->getName()) )); return $instructions; }
php
protected function getChangeDefault($tableName, Column $newColumn) { $constraintName = "DF_{$tableName}_{$newColumn->getName()}"; $default = $newColumn->getDefault(); $instructions = new AlterInstructions(); if ($default === null) { $default = 'DEFAULT NULL'; } else { $default = ltrim($this->getDefaultValueDefinition($default)); } if (empty($default)) { return $instructions; } $instructions->addPostStep(sprintf( 'ALTER TABLE %s ADD CONSTRAINT %s %s FOR %s', $this->quoteTableName($tableName), $constraintName, $default, $this->quoteColumnName($newColumn->getName()) )); return $instructions; }
[ "protected", "function", "getChangeDefault", "(", "$", "tableName", ",", "Column", "$", "newColumn", ")", "{", "$", "constraintName", "=", "\"DF_{$tableName}_{$newColumn->getName()}\"", ";", "$", "default", "=", "$", "newColumn", "->", "getDefault", "(", ")", ";", "$", "instructions", "=", "new", "AlterInstructions", "(", ")", ";", "if", "(", "$", "default", "===", "null", ")", "{", "$", "default", "=", "'DEFAULT NULL'", ";", "}", "else", "{", "$", "default", "=", "ltrim", "(", "$", "this", "->", "getDefaultValueDefinition", "(", "$", "default", ")", ")", ";", "}", "if", "(", "empty", "(", "$", "default", ")", ")", "{", "return", "$", "instructions", ";", "}", "$", "instructions", "->", "addPostStep", "(", "sprintf", "(", "'ALTER TABLE %s ADD CONSTRAINT %s %s FOR %s'", ",", "$", "this", "->", "quoteTableName", "(", "$", "tableName", ")", ",", "$", "constraintName", ",", "$", "default", ",", "$", "this", "->", "quoteColumnName", "(", "$", "newColumn", "->", "getName", "(", ")", ")", ")", ")", ";", "return", "$", "instructions", ";", "}" ]
Returns the instructions to change a column default value @param string $tableName The table where the column is @param Column $newColumn The column to alter @return AlterInstructions
[ "Returns", "the", "instructions", "to", "change", "a", "column", "default", "value" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Adapter/SqlServerAdapter.php#L537-L562
train
cakephp/phinx
src/Phinx/Db/Adapter/SqlServerAdapter.php
SqlServerAdapter.getColumnSqlDefinition
protected function getColumnSqlDefinition(Column $column, $create = true) { $buffer = []; if ($column->getType() instanceof Literal) { $buffer[] = (string)$column->getType(); } else { $sqlType = $this->getSqlType($column->getType()); $buffer[] = strtoupper($sqlType['name']); // integers cant have limits in SQlServer $noLimits = [ 'bigint', 'int', 'tinyint' ]; if (!in_array($sqlType['name'], $noLimits) && ($column->getLimit() || isset($sqlType['limit']))) { $buffer[] = sprintf('(%s)', $column->getLimit() ? $column->getLimit() : $sqlType['limit']); } } if ($column->getPrecision() && $column->getScale()) { $buffer[] = '(' . $column->getPrecision() . ',' . $column->getScale() . ')'; } $properties = $column->getProperties(); $buffer[] = $column->getType() === 'filestream' ? 'FILESTREAM' : ''; $buffer[] = isset($properties['rowguidcol']) ? 'ROWGUIDCOL' : ''; $buffer[] = $column->isNull() ? 'NULL' : 'NOT NULL'; if ($create === true) { if ($column->getDefault() === null && $column->isNull()) { $buffer[] = ' DEFAULT NULL'; } else { $buffer[] = $this->getDefaultValueDefinition($column->getDefault()); } } if ($column->isIdentity()) { $buffer[] = 'IDENTITY(1, 1)'; } return implode(' ', $buffer); }
php
protected function getColumnSqlDefinition(Column $column, $create = true) { $buffer = []; if ($column->getType() instanceof Literal) { $buffer[] = (string)$column->getType(); } else { $sqlType = $this->getSqlType($column->getType()); $buffer[] = strtoupper($sqlType['name']); // integers cant have limits in SQlServer $noLimits = [ 'bigint', 'int', 'tinyint' ]; if (!in_array($sqlType['name'], $noLimits) && ($column->getLimit() || isset($sqlType['limit']))) { $buffer[] = sprintf('(%s)', $column->getLimit() ? $column->getLimit() : $sqlType['limit']); } } if ($column->getPrecision() && $column->getScale()) { $buffer[] = '(' . $column->getPrecision() . ',' . $column->getScale() . ')'; } $properties = $column->getProperties(); $buffer[] = $column->getType() === 'filestream' ? 'FILESTREAM' : ''; $buffer[] = isset($properties['rowguidcol']) ? 'ROWGUIDCOL' : ''; $buffer[] = $column->isNull() ? 'NULL' : 'NOT NULL'; if ($create === true) { if ($column->getDefault() === null && $column->isNull()) { $buffer[] = ' DEFAULT NULL'; } else { $buffer[] = $this->getDefaultValueDefinition($column->getDefault()); } } if ($column->isIdentity()) { $buffer[] = 'IDENTITY(1, 1)'; } return implode(' ', $buffer); }
[ "protected", "function", "getColumnSqlDefinition", "(", "Column", "$", "column", ",", "$", "create", "=", "true", ")", "{", "$", "buffer", "=", "[", "]", ";", "if", "(", "$", "column", "->", "getType", "(", ")", "instanceof", "Literal", ")", "{", "$", "buffer", "[", "]", "=", "(", "string", ")", "$", "column", "->", "getType", "(", ")", ";", "}", "else", "{", "$", "sqlType", "=", "$", "this", "->", "getSqlType", "(", "$", "column", "->", "getType", "(", ")", ")", ";", "$", "buffer", "[", "]", "=", "strtoupper", "(", "$", "sqlType", "[", "'name'", "]", ")", ";", "// integers cant have limits in SQlServer", "$", "noLimits", "=", "[", "'bigint'", ",", "'int'", ",", "'tinyint'", "]", ";", "if", "(", "!", "in_array", "(", "$", "sqlType", "[", "'name'", "]", ",", "$", "noLimits", ")", "&&", "(", "$", "column", "->", "getLimit", "(", ")", "||", "isset", "(", "$", "sqlType", "[", "'limit'", "]", ")", ")", ")", "{", "$", "buffer", "[", "]", "=", "sprintf", "(", "'(%s)'", ",", "$", "column", "->", "getLimit", "(", ")", "?", "$", "column", "->", "getLimit", "(", ")", ":", "$", "sqlType", "[", "'limit'", "]", ")", ";", "}", "}", "if", "(", "$", "column", "->", "getPrecision", "(", ")", "&&", "$", "column", "->", "getScale", "(", ")", ")", "{", "$", "buffer", "[", "]", "=", "'('", ".", "$", "column", "->", "getPrecision", "(", ")", ".", "','", ".", "$", "column", "->", "getScale", "(", ")", ".", "')'", ";", "}", "$", "properties", "=", "$", "column", "->", "getProperties", "(", ")", ";", "$", "buffer", "[", "]", "=", "$", "column", "->", "getType", "(", ")", "===", "'filestream'", "?", "'FILESTREAM'", ":", "''", ";", "$", "buffer", "[", "]", "=", "isset", "(", "$", "properties", "[", "'rowguidcol'", "]", ")", "?", "'ROWGUIDCOL'", ":", "''", ";", "$", "buffer", "[", "]", "=", "$", "column", "->", "isNull", "(", ")", "?", "'NULL'", ":", "'NOT NULL'", ";", "if", "(", "$", "create", "===", "true", ")", "{", "if", "(", "$", "column", "->", "getDefault", "(", ")", "===", "null", "&&", "$", "column", "->", "isNull", "(", ")", ")", "{", "$", "buffer", "[", "]", "=", "' DEFAULT NULL'", ";", "}", "else", "{", "$", "buffer", "[", "]", "=", "$", "this", "->", "getDefaultValueDefinition", "(", "$", "column", "->", "getDefault", "(", ")", ")", ";", "}", "}", "if", "(", "$", "column", "->", "isIdentity", "(", ")", ")", "{", "$", "buffer", "[", "]", "=", "'IDENTITY(1, 1)'", ";", "}", "return", "implode", "(", "' '", ",", "$", "buffer", ")", ";", "}" ]
Gets the SqlServer Column Definition for a Column object. @param \Phinx\Db\Table\Column $column Column @return string
[ "Gets", "the", "SqlServer", "Column", "Definition", "for", "a", "Column", "object", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Adapter/SqlServerAdapter.php#L1141-L1182
train
cakephp/phinx
src/Phinx/Db/Adapter/SqlServerAdapter.php
SqlServerAdapter.getIndexSqlDefinition
protected function getIndexSqlDefinition(Index $index, $tableName) { if (is_string($index->getName())) { $indexName = $index->getName(); } else { $columnNames = $index->getColumns(); $indexName = sprintf('%s_%s', $tableName, implode('_', $columnNames)); } $def = sprintf( "CREATE %s INDEX %s ON %s (%s);", ($index->getType() === Index::UNIQUE ? 'UNIQUE' : ''), $indexName, $this->quoteTableName($tableName), '[' . implode('],[', $index->getColumns()) . ']' ); return $def; }
php
protected function getIndexSqlDefinition(Index $index, $tableName) { if (is_string($index->getName())) { $indexName = $index->getName(); } else { $columnNames = $index->getColumns(); $indexName = sprintf('%s_%s', $tableName, implode('_', $columnNames)); } $def = sprintf( "CREATE %s INDEX %s ON %s (%s);", ($index->getType() === Index::UNIQUE ? 'UNIQUE' : ''), $indexName, $this->quoteTableName($tableName), '[' . implode('],[', $index->getColumns()) . ']' ); return $def; }
[ "protected", "function", "getIndexSqlDefinition", "(", "Index", "$", "index", ",", "$", "tableName", ")", "{", "if", "(", "is_string", "(", "$", "index", "->", "getName", "(", ")", ")", ")", "{", "$", "indexName", "=", "$", "index", "->", "getName", "(", ")", ";", "}", "else", "{", "$", "columnNames", "=", "$", "index", "->", "getColumns", "(", ")", ";", "$", "indexName", "=", "sprintf", "(", "'%s_%s'", ",", "$", "tableName", ",", "implode", "(", "'_'", ",", "$", "columnNames", ")", ")", ";", "}", "$", "def", "=", "sprintf", "(", "\"CREATE %s INDEX %s ON %s (%s);\"", ",", "(", "$", "index", "->", "getType", "(", ")", "===", "Index", "::", "UNIQUE", "?", "'UNIQUE'", ":", "''", ")", ",", "$", "indexName", ",", "$", "this", "->", "quoteTableName", "(", "$", "tableName", ")", ",", "'['", ".", "implode", "(", "'],['", ",", "$", "index", "->", "getColumns", "(", ")", ")", ".", "']'", ")", ";", "return", "$", "def", ";", "}" ]
Gets the SqlServer Index Definition for an Index object. @param \Phinx\Db\Table\Index $index Index @return string
[ "Gets", "the", "SqlServer", "Index", "Definition", "for", "an", "Index", "object", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Adapter/SqlServerAdapter.php#L1190-L1207
train
cakephp/phinx
src/Phinx/Db/Adapter/SqlServerAdapter.php
SqlServerAdapter.getForeignKeySqlDefinition
protected function getForeignKeySqlDefinition(ForeignKey $foreignKey, $tableName) { $constraintName = $foreignKey->getConstraint() ?: $tableName . '_' . implode('_', $foreignKey->getColumns()); $def = ' CONSTRAINT ' . $this->quoteColumnName($constraintName); $def .= ' FOREIGN KEY ("' . implode('", "', $foreignKey->getColumns()) . '")'; $def .= " REFERENCES {$this->quoteTableName($foreignKey->getReferencedTable()->getName())} (\"" . implode('", "', $foreignKey->getReferencedColumns()) . '")'; if ($foreignKey->getOnDelete()) { $def .= " ON DELETE {$foreignKey->getOnDelete()}"; } if ($foreignKey->getOnUpdate()) { $def .= " ON UPDATE {$foreignKey->getOnUpdate()}"; } return $def; }
php
protected function getForeignKeySqlDefinition(ForeignKey $foreignKey, $tableName) { $constraintName = $foreignKey->getConstraint() ?: $tableName . '_' . implode('_', $foreignKey->getColumns()); $def = ' CONSTRAINT ' . $this->quoteColumnName($constraintName); $def .= ' FOREIGN KEY ("' . implode('", "', $foreignKey->getColumns()) . '")'; $def .= " REFERENCES {$this->quoteTableName($foreignKey->getReferencedTable()->getName())} (\"" . implode('", "', $foreignKey->getReferencedColumns()) . '")'; if ($foreignKey->getOnDelete()) { $def .= " ON DELETE {$foreignKey->getOnDelete()}"; } if ($foreignKey->getOnUpdate()) { $def .= " ON UPDATE {$foreignKey->getOnUpdate()}"; } return $def; }
[ "protected", "function", "getForeignKeySqlDefinition", "(", "ForeignKey", "$", "foreignKey", ",", "$", "tableName", ")", "{", "$", "constraintName", "=", "$", "foreignKey", "->", "getConstraint", "(", ")", "?", ":", "$", "tableName", ".", "'_'", ".", "implode", "(", "'_'", ",", "$", "foreignKey", "->", "getColumns", "(", ")", ")", ";", "$", "def", "=", "' CONSTRAINT '", ".", "$", "this", "->", "quoteColumnName", "(", "$", "constraintName", ")", ";", "$", "def", ".=", "' FOREIGN KEY (\"'", ".", "implode", "(", "'\", \"'", ",", "$", "foreignKey", "->", "getColumns", "(", ")", ")", ".", "'\")'", ";", "$", "def", ".=", "\" REFERENCES {$this->quoteTableName($foreignKey->getReferencedTable()->getName())} (\\\"\"", ".", "implode", "(", "'\", \"'", ",", "$", "foreignKey", "->", "getReferencedColumns", "(", ")", ")", ".", "'\")'", ";", "if", "(", "$", "foreignKey", "->", "getOnDelete", "(", ")", ")", "{", "$", "def", ".=", "\" ON DELETE {$foreignKey->getOnDelete()}\"", ";", "}", "if", "(", "$", "foreignKey", "->", "getOnUpdate", "(", ")", ")", "{", "$", "def", ".=", "\" ON UPDATE {$foreignKey->getOnUpdate()}\"", ";", "}", "return", "$", "def", ";", "}" ]
Gets the SqlServer Foreign Key Definition for an ForeignKey object. @param \Phinx\Db\Table\ForeignKey $foreignKey @return string
[ "Gets", "the", "SqlServer", "Foreign", "Key", "Definition", "for", "an", "ForeignKey", "object", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Adapter/SqlServerAdapter.php#L1215-L1229
train
cakephp/phinx
src/Phinx/Db/Adapter/AbstractAdapter.php
AbstractAdapter.isDryRunEnabled
public function isDryRunEnabled() { $input = $this->getInput(); return ($input && $input->hasOption('dry-run')) ? (bool)$input->getOption('dry-run') : false; }
php
public function isDryRunEnabled() { $input = $this->getInput(); return ($input && $input->hasOption('dry-run')) ? (bool)$input->getOption('dry-run') : false; }
[ "public", "function", "isDryRunEnabled", "(", ")", "{", "$", "input", "=", "$", "this", "->", "getInput", "(", ")", ";", "return", "(", "$", "input", "&&", "$", "input", "->", "hasOption", "(", "'dry-run'", ")", ")", "?", "(", "bool", ")", "$", "input", "->", "getOption", "(", "'dry-run'", ")", ":", "false", ";", "}" ]
Determines if instead of executing queries a dump to standard output is needed @return bool
[ "Determines", "if", "instead", "of", "executing", "queries", "a", "dump", "to", "standard", "output", "is", "needed" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Adapter/AbstractAdapter.php#L255-L260
train
cakephp/phinx
src/Phinx/Db/Util/AlterInstructions.php
AlterInstructions.merge
public function merge(AlterInstructions $other) { $this->alterParts = array_merge($this->alterParts, $other->getAlterParts()); $this->postSteps = array_merge($this->postSteps, $other->getPostSteps()); }
php
public function merge(AlterInstructions $other) { $this->alterParts = array_merge($this->alterParts, $other->getAlterParts()); $this->postSteps = array_merge($this->postSteps, $other->getPostSteps()); }
[ "public", "function", "merge", "(", "AlterInstructions", "$", "other", ")", "{", "$", "this", "->", "alterParts", "=", "array_merge", "(", "$", "this", "->", "alterParts", ",", "$", "other", "->", "getAlterParts", "(", ")", ")", ";", "$", "this", "->", "postSteps", "=", "array_merge", "(", "$", "this", "->", "postSteps", ",", "$", "other", "->", "getPostSteps", "(", ")", ")", ";", "}" ]
Merges another AlterInstructions object to this one @param AlterInstructions $other The other collection of instructions to merge in @return void
[ "Merges", "another", "AlterInstructions", "object", "to", "this", "one" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Util/AlterInstructions.php#L109-L113
train
cakephp/phinx
src/Phinx/Db/Util/AlterInstructions.php
AlterInstructions.execute
public function execute($alterTemplate, callable $executor) { if ($this->alterParts) { $alter = sprintf($alterTemplate, implode(', ', $this->alterParts)); $executor($alter); } $state = []; foreach ($this->postSteps as $instruction) { if (is_callable($instruction)) { $state = $instruction($state); continue; } $executor($instruction); } }
php
public function execute($alterTemplate, callable $executor) { if ($this->alterParts) { $alter = sprintf($alterTemplate, implode(', ', $this->alterParts)); $executor($alter); } $state = []; foreach ($this->postSteps as $instruction) { if (is_callable($instruction)) { $state = $instruction($state); continue; } $executor($instruction); } }
[ "public", "function", "execute", "(", "$", "alterTemplate", ",", "callable", "$", "executor", ")", "{", "if", "(", "$", "this", "->", "alterParts", ")", "{", "$", "alter", "=", "sprintf", "(", "$", "alterTemplate", ",", "implode", "(", "', '", ",", "$", "this", "->", "alterParts", ")", ")", ";", "$", "executor", "(", "$", "alter", ")", ";", "}", "$", "state", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "postSteps", "as", "$", "instruction", ")", "{", "if", "(", "is_callable", "(", "$", "instruction", ")", ")", "{", "$", "state", "=", "$", "instruction", "(", "$", "state", ")", ";", "continue", ";", "}", "$", "executor", "(", "$", "instruction", ")", ";", "}", "}" ]
Executes the ALTER instruction and all of the post steps. @param string $alterTemplate The template for the alter instruction @param callable $executor The function to be used to execute all instructions @return void
[ "Executes", "the", "ALTER", "instruction", "and", "all", "of", "the", "post", "steps", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Util/AlterInstructions.php#L122-L139
train
cakephp/phinx
src/Phinx/Db/Action/AddForeignKey.php
AddForeignKey.build
public static function build(Table $table, $columns, $referencedTable, $referencedColumns = ['id'], array $options = [], $name = null) { if (is_string($referencedColumns)) { $referencedColumns = [$referencedColumns]; // str to array } if (is_string($referencedTable)) { $referencedTable = new Table($referencedTable); } $fk = new ForeignKey(); $fk->setReferencedTable($referencedTable) ->setColumns($columns) ->setReferencedColumns($referencedColumns) ->setOptions($options); if ($name !== null) { $fk->setConstraint($name); } return new static($table, $fk); }
php
public static function build(Table $table, $columns, $referencedTable, $referencedColumns = ['id'], array $options = [], $name = null) { if (is_string($referencedColumns)) { $referencedColumns = [$referencedColumns]; // str to array } if (is_string($referencedTable)) { $referencedTable = new Table($referencedTable); } $fk = new ForeignKey(); $fk->setReferencedTable($referencedTable) ->setColumns($columns) ->setReferencedColumns($referencedColumns) ->setOptions($options); if ($name !== null) { $fk->setConstraint($name); } return new static($table, $fk); }
[ "public", "static", "function", "build", "(", "Table", "$", "table", ",", "$", "columns", ",", "$", "referencedTable", ",", "$", "referencedColumns", "=", "[", "'id'", "]", ",", "array", "$", "options", "=", "[", "]", ",", "$", "name", "=", "null", ")", "{", "if", "(", "is_string", "(", "$", "referencedColumns", ")", ")", "{", "$", "referencedColumns", "=", "[", "$", "referencedColumns", "]", ";", "// str to array", "}", "if", "(", "is_string", "(", "$", "referencedTable", ")", ")", "{", "$", "referencedTable", "=", "new", "Table", "(", "$", "referencedTable", ")", ";", "}", "$", "fk", "=", "new", "ForeignKey", "(", ")", ";", "$", "fk", "->", "setReferencedTable", "(", "$", "referencedTable", ")", "->", "setColumns", "(", "$", "columns", ")", "->", "setReferencedColumns", "(", "$", "referencedColumns", ")", "->", "setOptions", "(", "$", "options", ")", ";", "if", "(", "$", "name", "!==", "null", ")", "{", "$", "fk", "->", "setConstraint", "(", "$", "name", ")", ";", "}", "return", "new", "static", "(", "$", "table", ",", "$", "fk", ")", ";", "}" ]
Creates a new AddForeignKey object after building the foreign key with the passed attributes @param Table $table The table object to add the foreign key to @param string|string[] $columns The columns for the foreign key @param Table|string $referencedTable The table the foreign key references @param string|array $referencedColumns The columns in the referenced table @param array $options Extra options for the foreign key @param string|null $name The name of the foreign key @return AddForeignKey
[ "Creates", "a", "new", "AddForeignKey", "object", "after", "building", "the", "foreign", "key", "with", "the", "passed", "attributes" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Action/AddForeignKey.php#L64-L85
train
cakephp/phinx
src/Phinx/Util/Util.php
Util.getExistingMigrationClassNames
public static function getExistingMigrationClassNames($path) { $classNames = []; if (!is_dir($path)) { return $classNames; } // filter the files to only get the ones that match our naming scheme $phpFiles = glob($path . DIRECTORY_SEPARATOR . '*.php'); foreach ($phpFiles as $filePath) { if (preg_match('/([0-9]+)_([_a-z0-9]*).php/', basename($filePath))) { $classNames[] = static::mapFileNameToClassName(basename($filePath)); } } return $classNames; }
php
public static function getExistingMigrationClassNames($path) { $classNames = []; if (!is_dir($path)) { return $classNames; } // filter the files to only get the ones that match our naming scheme $phpFiles = glob($path . DIRECTORY_SEPARATOR . '*.php'); foreach ($phpFiles as $filePath) { if (preg_match('/([0-9]+)_([_a-z0-9]*).php/', basename($filePath))) { $classNames[] = static::mapFileNameToClassName(basename($filePath)); } } return $classNames; }
[ "public", "static", "function", "getExistingMigrationClassNames", "(", "$", "path", ")", "{", "$", "classNames", "=", "[", "]", ";", "if", "(", "!", "is_dir", "(", "$", "path", ")", ")", "{", "return", "$", "classNames", ";", "}", "// filter the files to only get the ones that match our naming scheme", "$", "phpFiles", "=", "glob", "(", "$", "path", ".", "DIRECTORY_SEPARATOR", ".", "'*.php'", ")", ";", "foreach", "(", "$", "phpFiles", "as", "$", "filePath", ")", "{", "if", "(", "preg_match", "(", "'/([0-9]+)_([_a-z0-9]*).php/'", ",", "basename", "(", "$", "filePath", ")", ")", ")", "{", "$", "classNames", "[", "]", "=", "static", "::", "mapFileNameToClassName", "(", "basename", "(", "$", "filePath", ")", ")", ";", "}", "}", "return", "$", "classNames", ";", "}" ]
Gets an array of all the existing migration class names. @return string[]
[ "Gets", "an", "array", "of", "all", "the", "existing", "migration", "class", "names", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Util/Util.php#L65-L83
train
cakephp/phinx
src/Phinx/Util/Util.php
Util.mapClassNameToFileName
public static function mapClassNameToFileName($className) { $arr = preg_split('/(?=[A-Z])/', $className); unset($arr[0]); // remove the first element ('') $fileName = static::getCurrentTimestamp() . '_' . strtolower(implode($arr, '_')) . '.php'; return $fileName; }
php
public static function mapClassNameToFileName($className) { $arr = preg_split('/(?=[A-Z])/', $className); unset($arr[0]); // remove the first element ('') $fileName = static::getCurrentTimestamp() . '_' . strtolower(implode($arr, '_')) . '.php'; return $fileName; }
[ "public", "static", "function", "mapClassNameToFileName", "(", "$", "className", ")", "{", "$", "arr", "=", "preg_split", "(", "'/(?=[A-Z])/'", ",", "$", "className", ")", ";", "unset", "(", "$", "arr", "[", "0", "]", ")", ";", "// remove the first element ('')", "$", "fileName", "=", "static", "::", "getCurrentTimestamp", "(", ")", ".", "'_'", ".", "strtolower", "(", "implode", "(", "$", "arr", ",", "'_'", ")", ")", ".", "'.php'", ";", "return", "$", "fileName", ";", "}" ]
Turn migration names like 'CreateUserTable' into file names like '12345678901234_create_user_table.php' or 'LimitResourceNamesTo30Chars' into '12345678901234_limit_resource_names_to_30_chars.php'. @param string $className Class Name @return string
[ "Turn", "migration", "names", "like", "CreateUserTable", "into", "file", "names", "like", "12345678901234_create_user_table", ".", "php", "or", "LimitResourceNamesTo30Chars", "into", "12345678901234_limit_resource_names_to_30_chars", ".", "php", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Util/Util.php#L107-L114
train
cakephp/phinx
src/Phinx/Util/Util.php
Util.mapFileNameToClassName
public static function mapFileNameToClassName($fileName) { $matches = []; if (preg_match(static::MIGRATION_FILE_NAME_PATTERN, $fileName, $matches)) { $fileName = $matches[1]; } return str_replace(' ', '', ucwords(str_replace('_', ' ', $fileName))); }
php
public static function mapFileNameToClassName($fileName) { $matches = []; if (preg_match(static::MIGRATION_FILE_NAME_PATTERN, $fileName, $matches)) { $fileName = $matches[1]; } return str_replace(' ', '', ucwords(str_replace('_', ' ', $fileName))); }
[ "public", "static", "function", "mapFileNameToClassName", "(", "$", "fileName", ")", "{", "$", "matches", "=", "[", "]", ";", "if", "(", "preg_match", "(", "static", "::", "MIGRATION_FILE_NAME_PATTERN", ",", "$", "fileName", ",", "$", "matches", ")", ")", "{", "$", "fileName", "=", "$", "matches", "[", "1", "]", ";", "}", "return", "str_replace", "(", "' '", ",", "''", ",", "ucwords", "(", "str_replace", "(", "'_'", ",", "' '", ",", "$", "fileName", ")", ")", ")", ";", "}" ]
Turn file names like '12345678901234_create_user_table.php' into class names like 'CreateUserTable'. @param string $fileName File Name @return string
[ "Turn", "file", "names", "like", "12345678901234_create_user_table", ".", "php", "into", "class", "names", "like", "CreateUserTable", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Util/Util.php#L123-L131
train
cakephp/phinx
src/Phinx/Util/Util.php
Util.loadPhpFile
public static function loadPhpFile($filename) { $filePath = realpath($filename); /** * I lifed this from phpunits FileLoader class * * @see https://github.com/sebastianbergmann/phpunit/pull/2751 */ $isReadable = @\fopen($filePath, 'r') !== false; if (!$filePath || !$isReadable) { throw new \Exception(sprintf("Cannot open file %s \n", $filename)); } include_once $filePath; return $filePath; }
php
public static function loadPhpFile($filename) { $filePath = realpath($filename); /** * I lifed this from phpunits FileLoader class * * @see https://github.com/sebastianbergmann/phpunit/pull/2751 */ $isReadable = @\fopen($filePath, 'r') !== false; if (!$filePath || !$isReadable) { throw new \Exception(sprintf("Cannot open file %s \n", $filename)); } include_once $filePath; return $filePath; }
[ "public", "static", "function", "loadPhpFile", "(", "$", "filename", ")", "{", "$", "filePath", "=", "realpath", "(", "$", "filename", ")", ";", "/**\n * I lifed this from phpunits FileLoader class\n *\n * @see https://github.com/sebastianbergmann/phpunit/pull/2751\n */", "$", "isReadable", "=", "@", "\\", "fopen", "(", "$", "filePath", ",", "'r'", ")", "!==", "false", ";", "if", "(", "!", "$", "filePath", "||", "!", "$", "isReadable", ")", "{", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "\"Cannot open file %s \\n\"", ",", "$", "filename", ")", ")", ";", "}", "include_once", "$", "filePath", ";", "return", "$", "filePath", ";", "}" ]
Takes the path to a php file and attempts to include it if readable @return string
[ "Takes", "the", "path", "to", "a", "php", "file", "and", "attempts", "to", "include", "it", "if", "readable" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Util/Util.php#L230-L248
train
cakephp/phinx
src/Phinx/Db/Action/RenameColumn.php
RenameColumn.build
public static function build(Table $table, $columnName, $newName) { $column = new Column(); $column->setName($columnName); return new static($table, $column, $newName); }
php
public static function build(Table $table, $columnName, $newName) { $column = new Column(); $column->setName($columnName); return new static($table, $column, $newName); }
[ "public", "static", "function", "build", "(", "Table", "$", "table", ",", "$", "columnName", ",", "$", "newName", ")", "{", "$", "column", "=", "new", "Column", "(", ")", ";", "$", "column", "->", "setName", "(", "$", "columnName", ")", ";", "return", "new", "static", "(", "$", "table", ",", "$", "column", ",", "$", "newName", ")", ";", "}" ]
Creates a new RenameColumn object after building the passed arguments @param Table $table The table where the column is @param mixed $columnName The name of the column to be changed @param mixed $newName The new name for the column @return RenameColumn
[ "Creates", "a", "new", "RenameColumn", "object", "after", "building", "the", "passed", "arguments" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Action/RenameColumn.php#L70-L76
train
cakephp/phinx
src/Phinx/Db/Plan/Plan.php
Plan.createPlan
protected function createPlan($actions) { $this->gatherCreates($actions); $this->gatherUpdates($actions); $this->gatherTableMoves($actions); $this->gatherIndexes($actions); $this->gatherConstraints($actions); $this->resolveConflicts(); }
php
protected function createPlan($actions) { $this->gatherCreates($actions); $this->gatherUpdates($actions); $this->gatherTableMoves($actions); $this->gatherIndexes($actions); $this->gatherConstraints($actions); $this->resolveConflicts(); }
[ "protected", "function", "createPlan", "(", "$", "actions", ")", "{", "$", "this", "->", "gatherCreates", "(", "$", "actions", ")", ";", "$", "this", "->", "gatherUpdates", "(", "$", "actions", ")", ";", "$", "this", "->", "gatherTableMoves", "(", "$", "actions", ")", ";", "$", "this", "->", "gatherIndexes", "(", "$", "actions", ")", ";", "$", "this", "->", "gatherConstraints", "(", "$", "actions", ")", ";", "$", "this", "->", "resolveConflicts", "(", ")", ";", "}" ]
Parses the given Intent and creates the separate steps to execute @param Intent $actions The actions to use for the plan @return void
[ "Parses", "the", "given", "Intent", "and", "creates", "the", "separate", "steps", "to", "execute" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Plan/Plan.php#L106-L114
train
cakephp/phinx
src/Phinx/Db/Plan/Plan.php
Plan.execute
public function execute(AdapterInterface $executor) { foreach ($this->tableCreates as $newTable) { $executor->createTable($newTable->getTable(), $newTable->getColumns(), $newTable->getIndexes()); } collection($this->updatesSequence()) ->unfold() ->each(function ($updates) use ($executor) { $executor->executeActions($updates->getTable(), $updates->getActions()); }); }
php
public function execute(AdapterInterface $executor) { foreach ($this->tableCreates as $newTable) { $executor->createTable($newTable->getTable(), $newTable->getColumns(), $newTable->getIndexes()); } collection($this->updatesSequence()) ->unfold() ->each(function ($updates) use ($executor) { $executor->executeActions($updates->getTable(), $updates->getActions()); }); }
[ "public", "function", "execute", "(", "AdapterInterface", "$", "executor", ")", "{", "foreach", "(", "$", "this", "->", "tableCreates", "as", "$", "newTable", ")", "{", "$", "executor", "->", "createTable", "(", "$", "newTable", "->", "getTable", "(", ")", ",", "$", "newTable", "->", "getColumns", "(", ")", ",", "$", "newTable", "->", "getIndexes", "(", ")", ")", ";", "}", "collection", "(", "$", "this", "->", "updatesSequence", "(", ")", ")", "->", "unfold", "(", ")", "->", "each", "(", "function", "(", "$", "updates", ")", "use", "(", "$", "executor", ")", "{", "$", "executor", "->", "executeActions", "(", "$", "updates", "->", "getTable", "(", ")", ",", "$", "updates", "->", "getActions", "(", ")", ")", ";", "}", ")", ";", "}" ]
Executes this plan using the given AdapterInterface @param AdapterInterface $executor The executor object for the plan @return void
[ "Executes", "this", "plan", "using", "the", "given", "AdapterInterface" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Plan/Plan.php#L137-L148
train
cakephp/phinx
src/Phinx/Db/Plan/Plan.php
Plan.resolveConflicts
protected function resolveConflicts() { $moveActions = collection($this->tableMoves) ->unfold(function ($move) { return $move->getActions(); }); foreach ($moveActions as $action) { if ($action instanceof DropTable) { $this->tableUpdates = $this->forgetTable($action->getTable(), $this->tableUpdates); $this->constraints = $this->forgetTable($action->getTable(), $this->constraints); $this->indexes = $this->forgetTable($action->getTable(), $this->indexes); } } $this->tableUpdates = collection($this->tableUpdates) // Renaming a column and then changing the renamed column is something people do, // but it is a conflicting action. Luckily solving the conflict can be done by moving // the ChangeColumn action to another AlterTable ->unfold(new ActionSplitter(RenameColumn::class, ChangeColumn::class, function (RenameColumn $a, ChangeColumn $b) { return $a->getNewName() == $b->getColumnName(); })) ->toList(); $this->constraints = collection($this->constraints) ->map(function (AlterTable $alter) { // Dropping indexes used by foreign keys is a conflict, but one we can resolve // if the foreign key is also scheduled to be dropped. If we can find sucha a case, // we force the execution of the index drop after the foreign key is dropped. return $this->remapContraintAndIndexConflicts($alter); }) // Changing constraint properties sometimes require dropping it and then // creating it again with the new stuff. Unfortunately, we have already bundled // everything together in as few AlterTable statements as we could, so we need to // resolve this conflict manually ->unfold(new ActionSplitter(DropForeignKey::class, AddForeignKey::class, function (DropForeignKey $a, AddForeignKey $b) { return $a->getForeignKey()->getColumns() === $b->getForeignKey()->getColumns(); })) ->toList(); }
php
protected function resolveConflicts() { $moveActions = collection($this->tableMoves) ->unfold(function ($move) { return $move->getActions(); }); foreach ($moveActions as $action) { if ($action instanceof DropTable) { $this->tableUpdates = $this->forgetTable($action->getTable(), $this->tableUpdates); $this->constraints = $this->forgetTable($action->getTable(), $this->constraints); $this->indexes = $this->forgetTable($action->getTable(), $this->indexes); } } $this->tableUpdates = collection($this->tableUpdates) // Renaming a column and then changing the renamed column is something people do, // but it is a conflicting action. Luckily solving the conflict can be done by moving // the ChangeColumn action to another AlterTable ->unfold(new ActionSplitter(RenameColumn::class, ChangeColumn::class, function (RenameColumn $a, ChangeColumn $b) { return $a->getNewName() == $b->getColumnName(); })) ->toList(); $this->constraints = collection($this->constraints) ->map(function (AlterTable $alter) { // Dropping indexes used by foreign keys is a conflict, but one we can resolve // if the foreign key is also scheduled to be dropped. If we can find sucha a case, // we force the execution of the index drop after the foreign key is dropped. return $this->remapContraintAndIndexConflicts($alter); }) // Changing constraint properties sometimes require dropping it and then // creating it again with the new stuff. Unfortunately, we have already bundled // everything together in as few AlterTable statements as we could, so we need to // resolve this conflict manually ->unfold(new ActionSplitter(DropForeignKey::class, AddForeignKey::class, function (DropForeignKey $a, AddForeignKey $b) { return $a->getForeignKey()->getColumns() === $b->getForeignKey()->getColumns(); })) ->toList(); }
[ "protected", "function", "resolveConflicts", "(", ")", "{", "$", "moveActions", "=", "collection", "(", "$", "this", "->", "tableMoves", ")", "->", "unfold", "(", "function", "(", "$", "move", ")", "{", "return", "$", "move", "->", "getActions", "(", ")", ";", "}", ")", ";", "foreach", "(", "$", "moveActions", "as", "$", "action", ")", "{", "if", "(", "$", "action", "instanceof", "DropTable", ")", "{", "$", "this", "->", "tableUpdates", "=", "$", "this", "->", "forgetTable", "(", "$", "action", "->", "getTable", "(", ")", ",", "$", "this", "->", "tableUpdates", ")", ";", "$", "this", "->", "constraints", "=", "$", "this", "->", "forgetTable", "(", "$", "action", "->", "getTable", "(", ")", ",", "$", "this", "->", "constraints", ")", ";", "$", "this", "->", "indexes", "=", "$", "this", "->", "forgetTable", "(", "$", "action", "->", "getTable", "(", ")", ",", "$", "this", "->", "indexes", ")", ";", "}", "}", "$", "this", "->", "tableUpdates", "=", "collection", "(", "$", "this", "->", "tableUpdates", ")", "// Renaming a column and then changing the renamed column is something people do,", "// but it is a conflicting action. Luckily solving the conflict can be done by moving", "// the ChangeColumn action to another AlterTable", "->", "unfold", "(", "new", "ActionSplitter", "(", "RenameColumn", "::", "class", ",", "ChangeColumn", "::", "class", ",", "function", "(", "RenameColumn", "$", "a", ",", "ChangeColumn", "$", "b", ")", "{", "return", "$", "a", "->", "getNewName", "(", ")", "==", "$", "b", "->", "getColumnName", "(", ")", ";", "}", ")", ")", "->", "toList", "(", ")", ";", "$", "this", "->", "constraints", "=", "collection", "(", "$", "this", "->", "constraints", ")", "->", "map", "(", "function", "(", "AlterTable", "$", "alter", ")", "{", "// Dropping indexes used by foreign keys is a conflict, but one we can resolve", "// if the foreign key is also scheduled to be dropped. If we can find sucha a case,", "// we force the execution of the index drop after the foreign key is dropped.", "return", "$", "this", "->", "remapContraintAndIndexConflicts", "(", "$", "alter", ")", ";", "}", ")", "// Changing constraint properties sometimes require dropping it and then", "// creating it again with the new stuff. Unfortunately, we have already bundled", "// everything together in as few AlterTable statements as we could, so we need to", "// resolve this conflict manually", "->", "unfold", "(", "new", "ActionSplitter", "(", "DropForeignKey", "::", "class", ",", "AddForeignKey", "::", "class", ",", "function", "(", "DropForeignKey", "$", "a", ",", "AddForeignKey", "$", "b", ")", "{", "return", "$", "a", "->", "getForeignKey", "(", ")", "->", "getColumns", "(", ")", "===", "$", "b", "->", "getForeignKey", "(", ")", "->", "getColumns", "(", ")", ";", "}", ")", ")", "->", "toList", "(", ")", ";", "}" ]
Deletes certain actions from the plan if they are found to be conflicting or redundant. @return void
[ "Deletes", "certain", "actions", "from", "the", "plan", "if", "they", "are", "found", "to", "be", "conflicting", "or", "redundant", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Plan/Plan.php#L174-L213
train
cakephp/phinx
src/Phinx/Db/Plan/Plan.php
Plan.forgetTable
protected function forgetTable(Table $table, $actions) { $result = []; foreach ($actions as $action) { if ($action->getTable()->getName() === $table->getName()) { continue; } $result[] = $action; } return $result; }
php
protected function forgetTable(Table $table, $actions) { $result = []; foreach ($actions as $action) { if ($action->getTable()->getName() === $table->getName()) { continue; } $result[] = $action; } return $result; }
[ "protected", "function", "forgetTable", "(", "Table", "$", "table", ",", "$", "actions", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "actions", "as", "$", "action", ")", "{", "if", "(", "$", "action", "->", "getTable", "(", ")", "->", "getName", "(", ")", "===", "$", "table", "->", "getName", "(", ")", ")", "{", "continue", ";", "}", "$", "result", "[", "]", "=", "$", "action", ";", "}", "return", "$", "result", ";", "}" ]
Deletes all actions related to the given table and keeps the rest @param Table $table The table to find in the list of actions @param AlterTable[] $actions The actions to transform @return AlterTable[] The list of actions without actions for the given table
[ "Deletes", "all", "actions", "related", "to", "the", "given", "table", "and", "keeps", "the", "rest" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Plan/Plan.php#L223-L234
train
cakephp/phinx
src/Phinx/Db/Plan/Plan.php
Plan.forgetDropIndex
protected function forgetDropIndex(Table $table, array $columns, array $actions) { $dropIndexActions = new ArrayObject(); $indexes = collection($actions) ->map(function ($alter) use ($table, $columns, $dropIndexActions) { if ($alter->getTable()->getName() !== $table->getName()) { return $alter; } $newAlter = new AlterTable($table); collection($alter->getActions()) ->map(function ($action) use ($columns) { if (!$action instanceof DropIndex) { return [$action, null]; } if ($action->getIndex()->getColumns() === $columns) { return [null, $action]; } return [$action, null]; }) ->each(function ($tuple) use ($newAlter, $dropIndexActions) { list($action, $dropIndex) = $tuple; if ($action) { $newAlter->addAction($action); } if ($dropIndex) { $dropIndexActions->append($dropIndex); } }); return $newAlter; }) ->toArray(); return [$indexes, $dropIndexActions->getArrayCopy()]; }
php
protected function forgetDropIndex(Table $table, array $columns, array $actions) { $dropIndexActions = new ArrayObject(); $indexes = collection($actions) ->map(function ($alter) use ($table, $columns, $dropIndexActions) { if ($alter->getTable()->getName() !== $table->getName()) { return $alter; } $newAlter = new AlterTable($table); collection($alter->getActions()) ->map(function ($action) use ($columns) { if (!$action instanceof DropIndex) { return [$action, null]; } if ($action->getIndex()->getColumns() === $columns) { return [null, $action]; } return [$action, null]; }) ->each(function ($tuple) use ($newAlter, $dropIndexActions) { list($action, $dropIndex) = $tuple; if ($action) { $newAlter->addAction($action); } if ($dropIndex) { $dropIndexActions->append($dropIndex); } }); return $newAlter; }) ->toArray(); return [$indexes, $dropIndexActions->getArrayCopy()]; }
[ "protected", "function", "forgetDropIndex", "(", "Table", "$", "table", ",", "array", "$", "columns", ",", "array", "$", "actions", ")", "{", "$", "dropIndexActions", "=", "new", "ArrayObject", "(", ")", ";", "$", "indexes", "=", "collection", "(", "$", "actions", ")", "->", "map", "(", "function", "(", "$", "alter", ")", "use", "(", "$", "table", ",", "$", "columns", ",", "$", "dropIndexActions", ")", "{", "if", "(", "$", "alter", "->", "getTable", "(", ")", "->", "getName", "(", ")", "!==", "$", "table", "->", "getName", "(", ")", ")", "{", "return", "$", "alter", ";", "}", "$", "newAlter", "=", "new", "AlterTable", "(", "$", "table", ")", ";", "collection", "(", "$", "alter", "->", "getActions", "(", ")", ")", "->", "map", "(", "function", "(", "$", "action", ")", "use", "(", "$", "columns", ")", "{", "if", "(", "!", "$", "action", "instanceof", "DropIndex", ")", "{", "return", "[", "$", "action", ",", "null", "]", ";", "}", "if", "(", "$", "action", "->", "getIndex", "(", ")", "->", "getColumns", "(", ")", "===", "$", "columns", ")", "{", "return", "[", "null", ",", "$", "action", "]", ";", "}", "return", "[", "$", "action", ",", "null", "]", ";", "}", ")", "->", "each", "(", "function", "(", "$", "tuple", ")", "use", "(", "$", "newAlter", ",", "$", "dropIndexActions", ")", "{", "list", "(", "$", "action", ",", "$", "dropIndex", ")", "=", "$", "tuple", ";", "if", "(", "$", "action", ")", "{", "$", "newAlter", "->", "addAction", "(", "$", "action", ")", ";", "}", "if", "(", "$", "dropIndex", ")", "{", "$", "dropIndexActions", "->", "append", "(", "$", "dropIndex", ")", ";", "}", "}", ")", ";", "return", "$", "newAlter", ";", "}", ")", "->", "toArray", "(", ")", ";", "return", "[", "$", "indexes", ",", "$", "dropIndexActions", "->", "getArrayCopy", "(", ")", "]", ";", "}" ]
Deletes any DropIndex actions for the given table and exact columns @param Table $table The table to find in the list of actions @param string[] $columns The column names to match @param AlterTable[] $actions The actions to transform @return array A tuple containing the list of actions without actions for dropping the index and a list of drop index actions that were removed.
[ "Deletes", "any", "DropIndex", "actions", "for", "the", "given", "table", "and", "exact", "columns" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Plan/Plan.php#L282-L318
train
cakephp/phinx
src/Phinx/Db/Plan/Plan.php
Plan.gatherCreates
protected function gatherCreates($actions) { collection($actions) ->filter(function ($action) { return $action instanceof CreateTable; }) ->map(function ($action) { return [$action->getTable()->getName(), new NewTable($action->getTable())]; }) ->each(function ($step) { $this->tableCreates[$step[0]] = $step[1]; }); collection($actions) ->filter(function ($action) { return $action instanceof AddColumn || $action instanceof AddIndex; }) ->filter(function ($action) { return isset($this->tableCreates[$action->getTable()->getName()]); }) ->each(function ($action) { $table = $action->getTable(); if ($action instanceof AddColumn) { $this->tableCreates[$table->getName()]->addColumn($action->getColumn()); } if ($action instanceof AddIndex) { $this->tableCreates[$table->getName()]->addIndex($action->getIndex()); } }); }
php
protected function gatherCreates($actions) { collection($actions) ->filter(function ($action) { return $action instanceof CreateTable; }) ->map(function ($action) { return [$action->getTable()->getName(), new NewTable($action->getTable())]; }) ->each(function ($step) { $this->tableCreates[$step[0]] = $step[1]; }); collection($actions) ->filter(function ($action) { return $action instanceof AddColumn || $action instanceof AddIndex; }) ->filter(function ($action) { return isset($this->tableCreates[$action->getTable()->getName()]); }) ->each(function ($action) { $table = $action->getTable(); if ($action instanceof AddColumn) { $this->tableCreates[$table->getName()]->addColumn($action->getColumn()); } if ($action instanceof AddIndex) { $this->tableCreates[$table->getName()]->addIndex($action->getIndex()); } }); }
[ "protected", "function", "gatherCreates", "(", "$", "actions", ")", "{", "collection", "(", "$", "actions", ")", "->", "filter", "(", "function", "(", "$", "action", ")", "{", "return", "$", "action", "instanceof", "CreateTable", ";", "}", ")", "->", "map", "(", "function", "(", "$", "action", ")", "{", "return", "[", "$", "action", "->", "getTable", "(", ")", "->", "getName", "(", ")", ",", "new", "NewTable", "(", "$", "action", "->", "getTable", "(", ")", ")", "]", ";", "}", ")", "->", "each", "(", "function", "(", "$", "step", ")", "{", "$", "this", "->", "tableCreates", "[", "$", "step", "[", "0", "]", "]", "=", "$", "step", "[", "1", "]", ";", "}", ")", ";", "collection", "(", "$", "actions", ")", "->", "filter", "(", "function", "(", "$", "action", ")", "{", "return", "$", "action", "instanceof", "AddColumn", "||", "$", "action", "instanceof", "AddIndex", ";", "}", ")", "->", "filter", "(", "function", "(", "$", "action", ")", "{", "return", "isset", "(", "$", "this", "->", "tableCreates", "[", "$", "action", "->", "getTable", "(", ")", "->", "getName", "(", ")", "]", ")", ";", "}", ")", "->", "each", "(", "function", "(", "$", "action", ")", "{", "$", "table", "=", "$", "action", "->", "getTable", "(", ")", ";", "if", "(", "$", "action", "instanceof", "AddColumn", ")", "{", "$", "this", "->", "tableCreates", "[", "$", "table", "->", "getName", "(", ")", "]", "->", "addColumn", "(", "$", "action", "->", "getColumn", "(", ")", ")", ";", "}", "if", "(", "$", "action", "instanceof", "AddIndex", ")", "{", "$", "this", "->", "tableCreates", "[", "$", "table", "->", "getName", "(", ")", "]", "->", "addIndex", "(", "$", "action", "->", "getIndex", "(", ")", ")", ";", "}", "}", ")", ";", "}" ]
Collects all table creation actions from the given intent @param \Phinx\Db\Action\Action[] $actions The actions to parse @return void
[ "Collects", "all", "table", "creation", "actions", "from", "the", "given", "intent" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Plan/Plan.php#L326-L358
train
cakephp/phinx
src/Phinx/Db/Plan/Plan.php
Plan.gatherUpdates
protected function gatherUpdates($actions) { collection($actions) ->filter(function ($action) { return $action instanceof AddColumn || $action instanceof ChangeColumn || $action instanceof RemoveColumn || $action instanceof RenameColumn; }) // We are only concerned with table changes ->reject(function ($action) { return isset($this->tableCreates[$action->getTable()->getName()]); }) ->each(function ($action) { $table = $action->getTable(); $name = $table->getName(); if (!isset($this->tableUpdates[$name])) { $this->tableUpdates[$name] = new AlterTable($table); } $this->tableUpdates[$name]->addAction($action); }); }
php
protected function gatherUpdates($actions) { collection($actions) ->filter(function ($action) { return $action instanceof AddColumn || $action instanceof ChangeColumn || $action instanceof RemoveColumn || $action instanceof RenameColumn; }) // We are only concerned with table changes ->reject(function ($action) { return isset($this->tableCreates[$action->getTable()->getName()]); }) ->each(function ($action) { $table = $action->getTable(); $name = $table->getName(); if (!isset($this->tableUpdates[$name])) { $this->tableUpdates[$name] = new AlterTable($table); } $this->tableUpdates[$name]->addAction($action); }); }
[ "protected", "function", "gatherUpdates", "(", "$", "actions", ")", "{", "collection", "(", "$", "actions", ")", "->", "filter", "(", "function", "(", "$", "action", ")", "{", "return", "$", "action", "instanceof", "AddColumn", "||", "$", "action", "instanceof", "ChangeColumn", "||", "$", "action", "instanceof", "RemoveColumn", "||", "$", "action", "instanceof", "RenameColumn", ";", "}", ")", "// We are only concerned with table changes", "->", "reject", "(", "function", "(", "$", "action", ")", "{", "return", "isset", "(", "$", "this", "->", "tableCreates", "[", "$", "action", "->", "getTable", "(", ")", "->", "getName", "(", ")", "]", ")", ";", "}", ")", "->", "each", "(", "function", "(", "$", "action", ")", "{", "$", "table", "=", "$", "action", "->", "getTable", "(", ")", ";", "$", "name", "=", "$", "table", "->", "getName", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "tableUpdates", "[", "$", "name", "]", ")", ")", "{", "$", "this", "->", "tableUpdates", "[", "$", "name", "]", "=", "new", "AlterTable", "(", "$", "table", ")", ";", "}", "$", "this", "->", "tableUpdates", "[", "$", "name", "]", "->", "addAction", "(", "$", "action", ")", ";", "}", ")", ";", "}" ]
Collects all alter table actions from the given intent @param \Phinx\Db\Action\Action[] $actions The actions to parse @return void
[ "Collects", "all", "alter", "table", "actions", "from", "the", "given", "intent" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Plan/Plan.php#L366-L389
train
cakephp/phinx
src/Phinx/Db/Plan/Plan.php
Plan.gatherTableMoves
protected function gatherTableMoves($actions) { collection($actions) ->filter(function ($action) { return $action instanceof DropTable || $action instanceof RenameTable || $action instanceof ChangePrimaryKey || $action instanceof ChangeComment; }) ->each(function ($action) { $table = $action->getTable(); $name = $table->getName(); if (!isset($this->tableMoves[$name])) { $this->tableMoves[$name] = new AlterTable($table); } $this->tableMoves[$name]->addAction($action); }); }
php
protected function gatherTableMoves($actions) { collection($actions) ->filter(function ($action) { return $action instanceof DropTable || $action instanceof RenameTable || $action instanceof ChangePrimaryKey || $action instanceof ChangeComment; }) ->each(function ($action) { $table = $action->getTable(); $name = $table->getName(); if (!isset($this->tableMoves[$name])) { $this->tableMoves[$name] = new AlterTable($table); } $this->tableMoves[$name]->addAction($action); }); }
[ "protected", "function", "gatherTableMoves", "(", "$", "actions", ")", "{", "collection", "(", "$", "actions", ")", "->", "filter", "(", "function", "(", "$", "action", ")", "{", "return", "$", "action", "instanceof", "DropTable", "||", "$", "action", "instanceof", "RenameTable", "||", "$", "action", "instanceof", "ChangePrimaryKey", "||", "$", "action", "instanceof", "ChangeComment", ";", "}", ")", "->", "each", "(", "function", "(", "$", "action", ")", "{", "$", "table", "=", "$", "action", "->", "getTable", "(", ")", ";", "$", "name", "=", "$", "table", "->", "getName", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "tableMoves", "[", "$", "name", "]", ")", ")", "{", "$", "this", "->", "tableMoves", "[", "$", "name", "]", "=", "new", "AlterTable", "(", "$", "table", ")", ";", "}", "$", "this", "->", "tableMoves", "[", "$", "name", "]", "->", "addAction", "(", "$", "action", ")", ";", "}", ")", ";", "}" ]
Collects all alter table drop and renames from the given intent @param \Phinx\Db\Action\Action[] $actions The actions to parse @return void
[ "Collects", "all", "alter", "table", "drop", "and", "renames", "from", "the", "given", "intent" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Plan/Plan.php#L397-L416
train
cakephp/phinx
src/Phinx/Db/Plan/Plan.php
Plan.gatherIndexes
protected function gatherIndexes($actions) { collection($actions) ->filter(function ($action) { return $action instanceof AddIndex || $action instanceof DropIndex; }) ->reject(function ($action) { // Indexes for new tables are created inline // so we don't wan't them here too return isset($this->tableCreates[$action->getTable()->getName()]); }) ->each(function ($action) { $table = $action->getTable(); $name = $table->getName(); if (!isset($this->indexes[$name])) { $this->indexes[$name] = new AlterTable($table); } $this->indexes[$name]->addAction($action); }); }
php
protected function gatherIndexes($actions) { collection($actions) ->filter(function ($action) { return $action instanceof AddIndex || $action instanceof DropIndex; }) ->reject(function ($action) { // Indexes for new tables are created inline // so we don't wan't them here too return isset($this->tableCreates[$action->getTable()->getName()]); }) ->each(function ($action) { $table = $action->getTable(); $name = $table->getName(); if (!isset($this->indexes[$name])) { $this->indexes[$name] = new AlterTable($table); } $this->indexes[$name]->addAction($action); }); }
[ "protected", "function", "gatherIndexes", "(", "$", "actions", ")", "{", "collection", "(", "$", "actions", ")", "->", "filter", "(", "function", "(", "$", "action", ")", "{", "return", "$", "action", "instanceof", "AddIndex", "||", "$", "action", "instanceof", "DropIndex", ";", "}", ")", "->", "reject", "(", "function", "(", "$", "action", ")", "{", "// Indexes for new tables are created inline", "// so we don't wan't them here too", "return", "isset", "(", "$", "this", "->", "tableCreates", "[", "$", "action", "->", "getTable", "(", ")", "->", "getName", "(", ")", "]", ")", ";", "}", ")", "->", "each", "(", "function", "(", "$", "action", ")", "{", "$", "table", "=", "$", "action", "->", "getTable", "(", ")", ";", "$", "name", "=", "$", "table", "->", "getName", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "indexes", "[", "$", "name", "]", ")", ")", "{", "$", "this", "->", "indexes", "[", "$", "name", "]", "=", "new", "AlterTable", "(", "$", "table", ")", ";", "}", "$", "this", "->", "indexes", "[", "$", "name", "]", "->", "addAction", "(", "$", "action", ")", ";", "}", ")", ";", "}" ]
Collects all index creation and drops from the given intent @param \Phinx\Db\Action\Action[] $actions The actions to parse @return void
[ "Collects", "all", "index", "creation", "and", "drops", "from", "the", "given", "intent" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Plan/Plan.php#L424-L446
train
cakephp/phinx
src/Phinx/Db/Plan/Plan.php
Plan.gatherConstraints
protected function gatherConstraints($actions) { collection($actions) ->filter(function ($action) { return $action instanceof AddForeignKey || $action instanceof DropForeignKey; }) ->each(function ($action) { $table = $action->getTable(); $name = $table->getName(); if (!isset($this->constraints[$name])) { $this->constraints[$name] = new AlterTable($table); } $this->constraints[$name]->addAction($action); }); }
php
protected function gatherConstraints($actions) { collection($actions) ->filter(function ($action) { return $action instanceof AddForeignKey || $action instanceof DropForeignKey; }) ->each(function ($action) { $table = $action->getTable(); $name = $table->getName(); if (!isset($this->constraints[$name])) { $this->constraints[$name] = new AlterTable($table); } $this->constraints[$name]->addAction($action); }); }
[ "protected", "function", "gatherConstraints", "(", "$", "actions", ")", "{", "collection", "(", "$", "actions", ")", "->", "filter", "(", "function", "(", "$", "action", ")", "{", "return", "$", "action", "instanceof", "AddForeignKey", "||", "$", "action", "instanceof", "DropForeignKey", ";", "}", ")", "->", "each", "(", "function", "(", "$", "action", ")", "{", "$", "table", "=", "$", "action", "->", "getTable", "(", ")", ";", "$", "name", "=", "$", "table", "->", "getName", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "constraints", "[", "$", "name", "]", ")", ")", "{", "$", "this", "->", "constraints", "[", "$", "name", "]", "=", "new", "AlterTable", "(", "$", "table", ")", ";", "}", "$", "this", "->", "constraints", "[", "$", "name", "]", "->", "addAction", "(", "$", "action", ")", ";", "}", ")", ";", "}" ]
Collects all foreign key creation and drops from the given intent @param \Phinx\Db\Action\Action[] $actions The actions to parse @return void
[ "Collects", "all", "foreign", "key", "creation", "and", "drops", "from", "the", "given", "intent" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Plan/Plan.php#L454-L471
train
cakephp/phinx
src/Phinx/Db/Action/DropIndex.php
DropIndex.build
public static function build(Table $table, array $columns = []) { $index = new Index(); $index->setColumns($columns); return new static($table, $index); }
php
public static function build(Table $table, array $columns = []) { $index = new Index(); $index->setColumns($columns); return new static($table, $index); }
[ "public", "static", "function", "build", "(", "Table", "$", "table", ",", "array", "$", "columns", "=", "[", "]", ")", "{", "$", "index", "=", "new", "Index", "(", ")", ";", "$", "index", "->", "setColumns", "(", "$", "columns", ")", ";", "return", "new", "static", "(", "$", "table", ",", "$", "index", ")", ";", "}" ]
Creates a new DropIndex object after assembling the passed arguments. @param Table $table The table where the index is @param array $columns the indexed columns @return DropIndex
[ "Creates", "a", "new", "DropIndex", "object", "after", "assembling", "the", "passed", "arguments", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Action/DropIndex.php#L60-L66
train
cakephp/phinx
src/Phinx/Db/Action/DropIndex.php
DropIndex.buildFromName
public static function buildFromName(Table $table, $name) { $index = new Index(); $index->setName($name); return new static($table, $index); }
php
public static function buildFromName(Table $table, $name) { $index = new Index(); $index->setName($name); return new static($table, $index); }
[ "public", "static", "function", "buildFromName", "(", "Table", "$", "table", ",", "$", "name", ")", "{", "$", "index", "=", "new", "Index", "(", ")", ";", "$", "index", "->", "setName", "(", "$", "name", ")", ";", "return", "new", "static", "(", "$", "table", ",", "$", "index", ")", ";", "}" ]
Creates a new DropIndex when the name of the index to drop is known. @param Table $table The table where the index is @param mixed $name The name of the index @return DropIndex
[ "Creates", "a", "new", "DropIndex", "when", "the", "name", "of", "the", "index", "to", "drop", "is", "known", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Action/DropIndex.php#L76-L82
train
cakephp/phinx
src/Phinx/Db/Action/AddColumn.php
AddColumn.build
public static function build(Table $table, $columnName, $type = null, $options = []) { $column = new Column(); $column->setName($columnName); $column->setType($type); $column->setOptions($options); // map options to column methods return new static($table, $column); }
php
public static function build(Table $table, $columnName, $type = null, $options = []) { $column = new Column(); $column->setName($columnName); $column->setType($type); $column->setOptions($options); // map options to column methods return new static($table, $column); }
[ "public", "static", "function", "build", "(", "Table", "$", "table", ",", "$", "columnName", ",", "$", "type", "=", "null", ",", "$", "options", "=", "[", "]", ")", "{", "$", "column", "=", "new", "Column", "(", ")", ";", "$", "column", "->", "setName", "(", "$", "columnName", ")", ";", "$", "column", "->", "setType", "(", "$", "type", ")", ";", "$", "column", "->", "setOptions", "(", "$", "options", ")", ";", "// map options to column methods", "return", "new", "static", "(", "$", "table", ",", "$", "column", ")", ";", "}" ]
Returns a new AddColumn object after assembling the given commands @param Table $table The table to add the column to @param mixed $columnName The column name @param mixed $type The column type @param mixed $options The column options @return AddColumn
[ "Returns", "a", "new", "AddColumn", "object", "after", "assembling", "the", "given", "commands" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Action/AddColumn.php#L61-L69
train
cakephp/phinx
src/Phinx/Db/Adapter/AdapterFactory.php
AdapterFactory.getClass
protected function getClass($name) { if (empty($this->adapters[$name])) { throw new \RuntimeException(sprintf( 'Adapter "%s" has not been registered', $name )); } return $this->adapters[$name]; }
php
protected function getClass($name) { if (empty($this->adapters[$name])) { throw new \RuntimeException(sprintf( 'Adapter "%s" has not been registered', $name )); } return $this->adapters[$name]; }
[ "protected", "function", "getClass", "(", "$", "name", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "adapters", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'Adapter \"%s\" has not been registered'", ",", "$", "name", ")", ")", ";", "}", "return", "$", "this", "->", "adapters", "[", "$", "name", "]", ";", "}" ]
Get an adapter class by name. @throws \RuntimeException @param string $name @return string
[ "Get", "an", "adapter", "class", "by", "name", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Adapter/AdapterFactory.php#L110-L120
train
cakephp/phinx
src/Phinx/Db/Adapter/AdapterFactory.php
AdapterFactory.getWrapperClass
protected function getWrapperClass($name) { if (empty($this->wrappers[$name])) { throw new \RuntimeException(sprintf( 'Wrapper "%s" has not been registered', $name )); } return $this->wrappers[$name]; }
php
protected function getWrapperClass($name) { if (empty($this->wrappers[$name])) { throw new \RuntimeException(sprintf( 'Wrapper "%s" has not been registered', $name )); } return $this->wrappers[$name]; }
[ "protected", "function", "getWrapperClass", "(", "$", "name", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "wrappers", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'Wrapper \"%s\" has not been registered'", ",", "$", "name", ")", ")", ";", "}", "return", "$", "this", "->", "wrappers", "[", "$", "name", "]", ";", "}" ]
Get a wrapper class by name. @throws \RuntimeException @param string $name @return string
[ "Get", "a", "wrapper", "class", "by", "name", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Adapter/AdapterFactory.php#L164-L174
train
cakephp/phinx
src/Phinx/Migration/AbstractMigration.php
AbstractMigration.preFlightCheck
public function preFlightCheck($direction = null) { if (method_exists($this, MigrationInterface::CHANGE)) { if (method_exists($this, MigrationInterface::UP) || method_exists($this, MigrationInterface::DOWN) ) { $this->output->writeln(sprintf( '<comment>warning</comment> Migration contains both change() and/or up()/down() methods. <options=bold>Ignoring up() and down()</>.' )); } } }
php
public function preFlightCheck($direction = null) { if (method_exists($this, MigrationInterface::CHANGE)) { if (method_exists($this, MigrationInterface::UP) || method_exists($this, MigrationInterface::DOWN) ) { $this->output->writeln(sprintf( '<comment>warning</comment> Migration contains both change() and/or up()/down() methods. <options=bold>Ignoring up() and down()</>.' )); } } }
[ "public", "function", "preFlightCheck", "(", "$", "direction", "=", "null", ")", "{", "if", "(", "method_exists", "(", "$", "this", ",", "MigrationInterface", "::", "CHANGE", ")", ")", "{", "if", "(", "method_exists", "(", "$", "this", ",", "MigrationInterface", "::", "UP", ")", "||", "method_exists", "(", "$", "this", ",", "MigrationInterface", "::", "DOWN", ")", ")", "{", "$", "this", "->", "output", "->", "writeln", "(", "sprintf", "(", "'<comment>warning</comment> Migration contains both change() and/or up()/down() methods. <options=bold>Ignoring up() and down()</>.'", ")", ")", ";", "}", "}", "}" ]
Perform checks on the migration, print a warning if there are potential problems. Right now, the only check is if there is both a `change()` and an `up()` or a `down()` method. @param string|null $direction @return void
[ "Perform", "checks", "on", "the", "migration", "print", "a", "warning", "if", "there", "are", "potential", "problems", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Migration/AbstractMigration.php#L337-L347
train
cakephp/phinx
src/Phinx/Migration/AbstractMigration.php
AbstractMigration.postFlightCheck
public function postFlightCheck($direction = null) { foreach ($this->tables as $table) { if ($table->hasPendingActions()) { throw new \RuntimeException('Migration has pending actions after execution!'); } } }
php
public function postFlightCheck($direction = null) { foreach ($this->tables as $table) { if ($table->hasPendingActions()) { throw new \RuntimeException('Migration has pending actions after execution!'); } } }
[ "public", "function", "postFlightCheck", "(", "$", "direction", "=", "null", ")", "{", "foreach", "(", "$", "this", "->", "tables", "as", "$", "table", ")", "{", "if", "(", "$", "table", "->", "hasPendingActions", "(", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Migration has pending actions after execution!'", ")", ";", "}", "}", "}" ]
Perform checks on the migration after completion Right now, the only check is whether all changes were committed @param string|null $direction direction of migration @return void
[ "Perform", "checks", "on", "the", "migration", "after", "completion" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Migration/AbstractMigration.php#L358-L365
train
cakephp/phinx
src/Phinx/Console/Command/AbstractCommand.php
AbstractCommand.locateConfigFile
protected function locateConfigFile(InputInterface $input) { $configFile = $input->getOption('configuration'); $useDefault = false; if ($configFile === null || $configFile === false) { $useDefault = true; } $cwd = getcwd(); // locate the phinx config file (default: phinx.yml) // TODO - In future walk the tree in reverse (max 10 levels) $locator = new FileLocator([ $cwd . DIRECTORY_SEPARATOR ]); if (!$useDefault) { // Locate() throws an exception if the file does not exist return $locator->locate($configFile, $cwd, $first = true); } $possibleConfigFiles = ['phinx.php', 'phinx.json', 'phinx.yml']; foreach ($possibleConfigFiles as $configFile) { try { return $locator->locate($configFile, $cwd, $first = true); } catch (\InvalidArgumentException $exception) { $lastException = $exception; } } throw $lastException; }
php
protected function locateConfigFile(InputInterface $input) { $configFile = $input->getOption('configuration'); $useDefault = false; if ($configFile === null || $configFile === false) { $useDefault = true; } $cwd = getcwd(); // locate the phinx config file (default: phinx.yml) // TODO - In future walk the tree in reverse (max 10 levels) $locator = new FileLocator([ $cwd . DIRECTORY_SEPARATOR ]); if (!$useDefault) { // Locate() throws an exception if the file does not exist return $locator->locate($configFile, $cwd, $first = true); } $possibleConfigFiles = ['phinx.php', 'phinx.json', 'phinx.yml']; foreach ($possibleConfigFiles as $configFile) { try { return $locator->locate($configFile, $cwd, $first = true); } catch (\InvalidArgumentException $exception) { $lastException = $exception; } } throw $lastException; }
[ "protected", "function", "locateConfigFile", "(", "InputInterface", "$", "input", ")", "{", "$", "configFile", "=", "$", "input", "->", "getOption", "(", "'configuration'", ")", ";", "$", "useDefault", "=", "false", ";", "if", "(", "$", "configFile", "===", "null", "||", "$", "configFile", "===", "false", ")", "{", "$", "useDefault", "=", "true", ";", "}", "$", "cwd", "=", "getcwd", "(", ")", ";", "// locate the phinx config file (default: phinx.yml)", "// TODO - In future walk the tree in reverse (max 10 levels)", "$", "locator", "=", "new", "FileLocator", "(", "[", "$", "cwd", ".", "DIRECTORY_SEPARATOR", "]", ")", ";", "if", "(", "!", "$", "useDefault", ")", "{", "// Locate() throws an exception if the file does not exist", "return", "$", "locator", "->", "locate", "(", "$", "configFile", ",", "$", "cwd", ",", "$", "first", "=", "true", ")", ";", "}", "$", "possibleConfigFiles", "=", "[", "'phinx.php'", ",", "'phinx.json'", ",", "'phinx.yml'", "]", ";", "foreach", "(", "$", "possibleConfigFiles", "as", "$", "configFile", ")", "{", "try", "{", "return", "$", "locator", "->", "locate", "(", "$", "configFile", ",", "$", "cwd", ",", "$", "first", "=", "true", ")", ";", "}", "catch", "(", "\\", "InvalidArgumentException", "$", "exception", ")", "{", "$", "lastException", "=", "$", "exception", ";", "}", "}", "throw", "$", "lastException", ";", "}" ]
Returns config file path @param \Symfony\Component\Console\Input\InputInterface $input @return string
[ "Returns", "config", "file", "path" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Console/Command/AbstractCommand.php#L200-L232
train
cakephp/phinx
src/Phinx/Console/Command/AbstractCommand.php
AbstractCommand.verifyMigrationDirectory
protected function verifyMigrationDirectory($path) { if (!is_dir($path)) { throw new \InvalidArgumentException(sprintf( 'Migration directory "%s" does not exist', $path )); } if (!is_writable($path)) { throw new \InvalidArgumentException(sprintf( 'Migration directory "%s" is not writable', $path )); } }
php
protected function verifyMigrationDirectory($path) { if (!is_dir($path)) { throw new \InvalidArgumentException(sprintf( 'Migration directory "%s" does not exist', $path )); } if (!is_writable($path)) { throw new \InvalidArgumentException(sprintf( 'Migration directory "%s" is not writable', $path )); } }
[ "protected", "function", "verifyMigrationDirectory", "(", "$", "path", ")", "{", "if", "(", "!", "is_dir", "(", "$", "path", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Migration directory \"%s\" does not exist'", ",", "$", "path", ")", ")", ";", "}", "if", "(", "!", "is_writable", "(", "$", "path", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Migration directory \"%s\" is not writable'", ",", "$", "path", ")", ")", ";", "}", "}" ]
Verify that the migration directory exists and is writable. @param string $path @throws \InvalidArgumentException @return void
[ "Verify", "that", "the", "migration", "directory", "exists", "and", "is", "writable", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Console/Command/AbstractCommand.php#L310-L325
train
cakephp/phinx
src/Phinx/Console/Command/AbstractCommand.php
AbstractCommand.verifySeedDirectory
protected function verifySeedDirectory($path) { if (!is_dir($path)) { throw new \InvalidArgumentException(sprintf( 'Seed directory "%s" does not exist', $path )); } if (!is_writable($path)) { throw new \InvalidArgumentException(sprintf( 'Seed directory "%s" is not writable', $path )); } }
php
protected function verifySeedDirectory($path) { if (!is_dir($path)) { throw new \InvalidArgumentException(sprintf( 'Seed directory "%s" does not exist', $path )); } if (!is_writable($path)) { throw new \InvalidArgumentException(sprintf( 'Seed directory "%s" is not writable', $path )); } }
[ "protected", "function", "verifySeedDirectory", "(", "$", "path", ")", "{", "if", "(", "!", "is_dir", "(", "$", "path", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Seed directory \"%s\" does not exist'", ",", "$", "path", ")", ")", ";", "}", "if", "(", "!", "is_writable", "(", "$", "path", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Seed directory \"%s\" is not writable'", ",", "$", "path", ")", ")", ";", "}", "}" ]
Verify that the seed directory exists and is writable. @param string $path @throws \InvalidArgumentException @return void
[ "Verify", "that", "the", "seed", "directory", "exists", "and", "is", "writable", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Console/Command/AbstractCommand.php#L334-L349
train
cakephp/phinx
src/Phinx/Console/Command/SeedRun.php
SeedRun.execute
protected function execute(InputInterface $input, OutputInterface $output) { $this->bootstrap($input, $output); $seedSet = $input->getOption('seed'); $environment = $input->getOption('environment'); if ($environment === null) { $environment = $this->getConfig()->getDefaultEnvironment(); $output->writeln('<comment>warning</comment> no environment specified, defaulting to: ' . $environment); } else { $output->writeln('<info>using environment</info> ' . $environment); } $envOptions = $this->getConfig()->getEnvironment($environment); if (isset($envOptions['adapter'])) { $output->writeln('<info>using adapter</info> ' . $envOptions['adapter']); } if (isset($envOptions['wrapper'])) { $output->writeln('<info>using wrapper</info> ' . $envOptions['wrapper']); } if (isset($envOptions['name'])) { $output->writeln('<info>using database</info> ' . $envOptions['name']); } else { $output->writeln('<error>Could not determine database name! Please specify a database name in your config file.</error>'); return; } if (isset($envOptions['table_prefix'])) { $output->writeln('<info>using table prefix</info> ' . $envOptions['table_prefix']); } if (isset($envOptions['table_suffix'])) { $output->writeln('<info>using table suffix</info> ' . $envOptions['table_suffix']); } $start = microtime(true); if (empty($seedSet)) { // run all the seed(ers) $this->getManager()->seed($environment); } else { // run seed(ers) specified in a comma-separated list of classes foreach ($seedSet as $seed) { $this->getManager()->seed($environment, trim($seed)); } } $end = microtime(true); $output->writeln(''); $output->writeln('<comment>All Done. Took ' . sprintf('%.4fs', $end - $start) . '</comment>'); }
php
protected function execute(InputInterface $input, OutputInterface $output) { $this->bootstrap($input, $output); $seedSet = $input->getOption('seed'); $environment = $input->getOption('environment'); if ($environment === null) { $environment = $this->getConfig()->getDefaultEnvironment(); $output->writeln('<comment>warning</comment> no environment specified, defaulting to: ' . $environment); } else { $output->writeln('<info>using environment</info> ' . $environment); } $envOptions = $this->getConfig()->getEnvironment($environment); if (isset($envOptions['adapter'])) { $output->writeln('<info>using adapter</info> ' . $envOptions['adapter']); } if (isset($envOptions['wrapper'])) { $output->writeln('<info>using wrapper</info> ' . $envOptions['wrapper']); } if (isset($envOptions['name'])) { $output->writeln('<info>using database</info> ' . $envOptions['name']); } else { $output->writeln('<error>Could not determine database name! Please specify a database name in your config file.</error>'); return; } if (isset($envOptions['table_prefix'])) { $output->writeln('<info>using table prefix</info> ' . $envOptions['table_prefix']); } if (isset($envOptions['table_suffix'])) { $output->writeln('<info>using table suffix</info> ' . $envOptions['table_suffix']); } $start = microtime(true); if (empty($seedSet)) { // run all the seed(ers) $this->getManager()->seed($environment); } else { // run seed(ers) specified in a comma-separated list of classes foreach ($seedSet as $seed) { $this->getManager()->seed($environment, trim($seed)); } } $end = microtime(true); $output->writeln(''); $output->writeln('<comment>All Done. Took ' . sprintf('%.4fs', $end - $start) . '</comment>'); }
[ "protected", "function", "execute", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "$", "this", "->", "bootstrap", "(", "$", "input", ",", "$", "output", ")", ";", "$", "seedSet", "=", "$", "input", "->", "getOption", "(", "'seed'", ")", ";", "$", "environment", "=", "$", "input", "->", "getOption", "(", "'environment'", ")", ";", "if", "(", "$", "environment", "===", "null", ")", "{", "$", "environment", "=", "$", "this", "->", "getConfig", "(", ")", "->", "getDefaultEnvironment", "(", ")", ";", "$", "output", "->", "writeln", "(", "'<comment>warning</comment> no environment specified, defaulting to: '", ".", "$", "environment", ")", ";", "}", "else", "{", "$", "output", "->", "writeln", "(", "'<info>using environment</info> '", ".", "$", "environment", ")", ";", "}", "$", "envOptions", "=", "$", "this", "->", "getConfig", "(", ")", "->", "getEnvironment", "(", "$", "environment", ")", ";", "if", "(", "isset", "(", "$", "envOptions", "[", "'adapter'", "]", ")", ")", "{", "$", "output", "->", "writeln", "(", "'<info>using adapter</info> '", ".", "$", "envOptions", "[", "'adapter'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "envOptions", "[", "'wrapper'", "]", ")", ")", "{", "$", "output", "->", "writeln", "(", "'<info>using wrapper</info> '", ".", "$", "envOptions", "[", "'wrapper'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "envOptions", "[", "'name'", "]", ")", ")", "{", "$", "output", "->", "writeln", "(", "'<info>using database</info> '", ".", "$", "envOptions", "[", "'name'", "]", ")", ";", "}", "else", "{", "$", "output", "->", "writeln", "(", "'<error>Could not determine database name! Please specify a database name in your config file.</error>'", ")", ";", "return", ";", "}", "if", "(", "isset", "(", "$", "envOptions", "[", "'table_prefix'", "]", ")", ")", "{", "$", "output", "->", "writeln", "(", "'<info>using table prefix</info> '", ".", "$", "envOptions", "[", "'table_prefix'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "envOptions", "[", "'table_suffix'", "]", ")", ")", "{", "$", "output", "->", "writeln", "(", "'<info>using table suffix</info> '", ".", "$", "envOptions", "[", "'table_suffix'", "]", ")", ";", "}", "$", "start", "=", "microtime", "(", "true", ")", ";", "if", "(", "empty", "(", "$", "seedSet", ")", ")", "{", "// run all the seed(ers)", "$", "this", "->", "getManager", "(", ")", "->", "seed", "(", "$", "environment", ")", ";", "}", "else", "{", "// run seed(ers) specified in a comma-separated list of classes", "foreach", "(", "$", "seedSet", "as", "$", "seed", ")", "{", "$", "this", "->", "getManager", "(", ")", "->", "seed", "(", "$", "environment", ",", "trim", "(", "$", "seed", ")", ")", ";", "}", "}", "$", "end", "=", "microtime", "(", "true", ")", ";", "$", "output", "->", "writeln", "(", "''", ")", ";", "$", "output", "->", "writeln", "(", "'<comment>All Done. Took '", ".", "sprintf", "(", "'%.4fs'", ",", "$", "end", "-", "$", "start", ")", ".", "'</comment>'", ")", ";", "}" ]
Run database seeders. @param \Symfony\Component\Console\Input\InputInterface $input @param \Symfony\Component\Console\Output\OutputInterface $output @return void
[ "Run", "database", "seeders", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Console/Command/SeedRun.php#L69-L123
train
cakephp/phinx
src/Phinx/Db/Adapter/SQLiteAdapter.php
SQLiteAdapter.getDeclaringSql
protected function getDeclaringSql($tableName) { $rows = $this->fetchAll('select * from sqlite_master where `type` = \'table\''); $sql = ''; foreach ($rows as $table) { if ($table['tbl_name'] === $tableName) { $sql = $table['sql']; } } return $sql; }
php
protected function getDeclaringSql($tableName) { $rows = $this->fetchAll('select * from sqlite_master where `type` = \'table\''); $sql = ''; foreach ($rows as $table) { if ($table['tbl_name'] === $tableName) { $sql = $table['sql']; } } return $sql; }
[ "protected", "function", "getDeclaringSql", "(", "$", "tableName", ")", "{", "$", "rows", "=", "$", "this", "->", "fetchAll", "(", "'select * from sqlite_master where `type` = \\'table\\''", ")", ";", "$", "sql", "=", "''", ";", "foreach", "(", "$", "rows", "as", "$", "table", ")", "{", "if", "(", "$", "table", "[", "'tbl_name'", "]", "===", "$", "tableName", ")", "{", "$", "sql", "=", "$", "table", "[", "'sql'", "]", ";", "}", "}", "return", "$", "sql", ";", "}" ]
Returns the original CREATE statement for the give table @param string $tableName The table name to get the create statement for @return string
[ "Returns", "the", "original", "CREATE", "statement", "for", "the", "give", "table" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Adapter/SQLiteAdapter.php#L393-L405
train
cakephp/phinx
src/Phinx/Db/Adapter/SQLiteAdapter.php
SQLiteAdapter.copyDataToNewTable
protected function copyDataToNewTable($tableName, $tmpTableName, $writeColumns, $selectColumns) { $sql = sprintf( 'INSERT INTO %s(%s) SELECT %s FROM %s', $this->quoteTableName($tableName), implode(', ', $writeColumns), implode(', ', $selectColumns), $this->quoteTableName($tmpTableName) ); $this->execute($sql); }
php
protected function copyDataToNewTable($tableName, $tmpTableName, $writeColumns, $selectColumns) { $sql = sprintf( 'INSERT INTO %s(%s) SELECT %s FROM %s', $this->quoteTableName($tableName), implode(', ', $writeColumns), implode(', ', $selectColumns), $this->quoteTableName($tmpTableName) ); $this->execute($sql); }
[ "protected", "function", "copyDataToNewTable", "(", "$", "tableName", ",", "$", "tmpTableName", ",", "$", "writeColumns", ",", "$", "selectColumns", ")", "{", "$", "sql", "=", "sprintf", "(", "'INSERT INTO %s(%s) SELECT %s FROM %s'", ",", "$", "this", "->", "quoteTableName", "(", "$", "tableName", ")", ",", "implode", "(", "', '", ",", "$", "writeColumns", ")", ",", "implode", "(", "', '", ",", "$", "selectColumns", ")", ",", "$", "this", "->", "quoteTableName", "(", "$", "tmpTableName", ")", ")", ";", "$", "this", "->", "execute", "(", "$", "sql", ")", ";", "}" ]
Copies all the data from a tmp table to another table @param string $tableName The table name to copy the data to @param string $tmpTableName The tmp table name where the data is stored @param string[] $writeColumns The list of columns in the target table @param string[] $selectColumns The list of columns in the tmp table @return void
[ "Copies", "all", "the", "data", "from", "a", "tmp", "table", "to", "another", "table" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Adapter/SQLiteAdapter.php#L416-L426
train
cakephp/phinx
src/Phinx/Db/Adapter/SQLiteAdapter.php
SQLiteAdapter.copyAndDropTmpTable
protected function copyAndDropTmpTable($instructions, $tableName) { $instructions->addPostStep(function ($state) use ($tableName) { $this->copyDataToNewTable( $tableName, $state['tmpTableName'], $state['writeColumns'], $state['selectColumns'] ); $this->execute(sprintf('DROP TABLE %s', $this->quoteTableName($state['tmpTableName']))); return $state; }); return $instructions; }
php
protected function copyAndDropTmpTable($instructions, $tableName) { $instructions->addPostStep(function ($state) use ($tableName) { $this->copyDataToNewTable( $tableName, $state['tmpTableName'], $state['writeColumns'], $state['selectColumns'] ); $this->execute(sprintf('DROP TABLE %s', $this->quoteTableName($state['tmpTableName']))); return $state; }); return $instructions; }
[ "protected", "function", "copyAndDropTmpTable", "(", "$", "instructions", ",", "$", "tableName", ")", "{", "$", "instructions", "->", "addPostStep", "(", "function", "(", "$", "state", ")", "use", "(", "$", "tableName", ")", "{", "$", "this", "->", "copyDataToNewTable", "(", "$", "tableName", ",", "$", "state", "[", "'tmpTableName'", "]", ",", "$", "state", "[", "'writeColumns'", "]", ",", "$", "state", "[", "'selectColumns'", "]", ")", ";", "$", "this", "->", "execute", "(", "sprintf", "(", "'DROP TABLE %s'", ",", "$", "this", "->", "quoteTableName", "(", "$", "state", "[", "'tmpTableName'", "]", ")", ")", ")", ";", "return", "$", "state", ";", "}", ")", ";", "return", "$", "instructions", ";", "}" ]
Modifies the passed instructions to copy all data from the tmp table into the provided table and then drops the tmp table. @param AlterInstructions $instructions The instructions to modify @param string $tableName The table name to copy the data to @return AlterInstructions
[ "Modifies", "the", "passed", "instructions", "to", "copy", "all", "data", "from", "the", "tmp", "table", "into", "the", "provided", "table", "and", "then", "drops", "the", "tmp", "table", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Adapter/SQLiteAdapter.php#L436-L452
train
cakephp/phinx
src/Phinx/Db/Adapter/SQLiteAdapter.php
SQLiteAdapter.calculateNewTableColumns
protected function calculateNewTableColumns($tableName, $columnName, $newColumnName) { $columns = $this->fetchAll(sprintf('pragma table_info(%s)', $this->quoteTableName($tableName))); $selectColumns = []; $writeColumns = []; $columnType = null; $found = false; foreach ($columns as $column) { $selectName = $column['name']; $writeName = $selectName; if ($selectName == $columnName) { $writeName = $newColumnName; $found = true; $columnType = $column['type']; $selectName = $newColumnName === false ? $newColumnName : $selectName; } $selectColumns[] = $selectName; $writeColumns[] = $writeName; } $selectColumns = array_filter($selectColumns, 'strlen'); $writeColumns = array_filter($writeColumns, 'strlen'); $selectColumns = array_map([$this, 'quoteColumnName'], $selectColumns); $writeColumns = array_map([$this, 'quoteColumnName'], $writeColumns); if (!$found) { throw new \InvalidArgumentException(sprintf( 'The specified column doesn\'t exist: ' . $columnName )); } return compact('writeColumns', 'selectColumns', 'columnType'); }
php
protected function calculateNewTableColumns($tableName, $columnName, $newColumnName) { $columns = $this->fetchAll(sprintf('pragma table_info(%s)', $this->quoteTableName($tableName))); $selectColumns = []; $writeColumns = []; $columnType = null; $found = false; foreach ($columns as $column) { $selectName = $column['name']; $writeName = $selectName; if ($selectName == $columnName) { $writeName = $newColumnName; $found = true; $columnType = $column['type']; $selectName = $newColumnName === false ? $newColumnName : $selectName; } $selectColumns[] = $selectName; $writeColumns[] = $writeName; } $selectColumns = array_filter($selectColumns, 'strlen'); $writeColumns = array_filter($writeColumns, 'strlen'); $selectColumns = array_map([$this, 'quoteColumnName'], $selectColumns); $writeColumns = array_map([$this, 'quoteColumnName'], $writeColumns); if (!$found) { throw new \InvalidArgumentException(sprintf( 'The specified column doesn\'t exist: ' . $columnName )); } return compact('writeColumns', 'selectColumns', 'columnType'); }
[ "protected", "function", "calculateNewTableColumns", "(", "$", "tableName", ",", "$", "columnName", ",", "$", "newColumnName", ")", "{", "$", "columns", "=", "$", "this", "->", "fetchAll", "(", "sprintf", "(", "'pragma table_info(%s)'", ",", "$", "this", "->", "quoteTableName", "(", "$", "tableName", ")", ")", ")", ";", "$", "selectColumns", "=", "[", "]", ";", "$", "writeColumns", "=", "[", "]", ";", "$", "columnType", "=", "null", ";", "$", "found", "=", "false", ";", "foreach", "(", "$", "columns", "as", "$", "column", ")", "{", "$", "selectName", "=", "$", "column", "[", "'name'", "]", ";", "$", "writeName", "=", "$", "selectName", ";", "if", "(", "$", "selectName", "==", "$", "columnName", ")", "{", "$", "writeName", "=", "$", "newColumnName", ";", "$", "found", "=", "true", ";", "$", "columnType", "=", "$", "column", "[", "'type'", "]", ";", "$", "selectName", "=", "$", "newColumnName", "===", "false", "?", "$", "newColumnName", ":", "$", "selectName", ";", "}", "$", "selectColumns", "[", "]", "=", "$", "selectName", ";", "$", "writeColumns", "[", "]", "=", "$", "writeName", ";", "}", "$", "selectColumns", "=", "array_filter", "(", "$", "selectColumns", ",", "'strlen'", ")", ";", "$", "writeColumns", "=", "array_filter", "(", "$", "writeColumns", ",", "'strlen'", ")", ";", "$", "selectColumns", "=", "array_map", "(", "[", "$", "this", ",", "'quoteColumnName'", "]", ",", "$", "selectColumns", ")", ";", "$", "writeColumns", "=", "array_map", "(", "[", "$", "this", ",", "'quoteColumnName'", "]", ",", "$", "writeColumns", ")", ";", "if", "(", "!", "$", "found", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'The specified column doesn\\'t exist: '", ".", "$", "columnName", ")", ")", ";", "}", "return", "compact", "(", "'writeColumns'", ",", "'selectColumns'", ",", "'columnType'", ")", ";", "}" ]
Returns the columns and type to use when copying a table to another in the process of altering a table @param string $tableName The table to modify @param string $columnName The column name that is about to change @param string|false $newColumnName Optionally the new name for the column @return AlterInstructions
[ "Returns", "the", "columns", "and", "type", "to", "use", "when", "copying", "a", "table", "to", "another", "in", "the", "process", "of", "altering", "a", "table" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Adapter/SQLiteAdapter.php#L463-L498
train
cakephp/phinx
src/Phinx/Db/Adapter/SQLiteAdapter.php
SQLiteAdapter.beginAlterByCopyTable
protected function beginAlterByCopyTable($tableName) { $instructions = new AlterInstructions(); $instructions->addPostStep(function ($state) use ($tableName) { $createSQL = $this->getDeclaringSql($tableName); $tmpTableName = 'tmp_' . $tableName; $this->execute( sprintf( 'ALTER TABLE %s RENAME TO %s', $this->quoteTableName($tableName), $this->quoteTableName($tmpTableName) ) ); return compact('createSQL', 'tmpTableName') + $state; }); return $instructions; }
php
protected function beginAlterByCopyTable($tableName) { $instructions = new AlterInstructions(); $instructions->addPostStep(function ($state) use ($tableName) { $createSQL = $this->getDeclaringSql($tableName); $tmpTableName = 'tmp_' . $tableName; $this->execute( sprintf( 'ALTER TABLE %s RENAME TO %s', $this->quoteTableName($tableName), $this->quoteTableName($tmpTableName) ) ); return compact('createSQL', 'tmpTableName') + $state; }); return $instructions; }
[ "protected", "function", "beginAlterByCopyTable", "(", "$", "tableName", ")", "{", "$", "instructions", "=", "new", "AlterInstructions", "(", ")", ";", "$", "instructions", "->", "addPostStep", "(", "function", "(", "$", "state", ")", "use", "(", "$", "tableName", ")", "{", "$", "createSQL", "=", "$", "this", "->", "getDeclaringSql", "(", "$", "tableName", ")", ";", "$", "tmpTableName", "=", "'tmp_'", ".", "$", "tableName", ";", "$", "this", "->", "execute", "(", "sprintf", "(", "'ALTER TABLE %s RENAME TO %s'", ",", "$", "this", "->", "quoteTableName", "(", "$", "tableName", ")", ",", "$", "this", "->", "quoteTableName", "(", "$", "tmpTableName", ")", ")", ")", ";", "return", "compact", "(", "'createSQL'", ",", "'tmpTableName'", ")", "+", "$", "state", ";", "}", ")", ";", "return", "$", "instructions", ";", "}" ]
Returns the initial instructions to alter a table using the rename-alter-copy strategy @param string $tableName The table to modify @return AlterInstructions
[ "Returns", "the", "initial", "instructions", "to", "alter", "a", "table", "using", "the", "rename", "-", "alter", "-", "copy", "strategy" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Adapter/SQLiteAdapter.php#L507-L526
train
cakephp/phinx
src/Phinx/Db/Adapter/SQLiteAdapter.php
SQLiteAdapter.getIndexSqlDefinition
protected function getIndexSqlDefinition(Table $table, Index $index) { if ($index->getType() === Index::UNIQUE) { $def = 'UNIQUE INDEX'; } else { $def = 'INDEX'; } if (is_string($index->getName())) { $indexName = $index->getName(); } else { $indexName = $table->getName() . '_'; foreach ($index->getColumns() as $column) { $indexName .= $column . '_'; } $indexName .= 'index'; } $def .= ' `' . $indexName . '`'; return $def; }
php
protected function getIndexSqlDefinition(Table $table, Index $index) { if ($index->getType() === Index::UNIQUE) { $def = 'UNIQUE INDEX'; } else { $def = 'INDEX'; } if (is_string($index->getName())) { $indexName = $index->getName(); } else { $indexName = $table->getName() . '_'; foreach ($index->getColumns() as $column) { $indexName .= $column . '_'; } $indexName .= 'index'; } $def .= ' `' . $indexName . '`'; return $def; }
[ "protected", "function", "getIndexSqlDefinition", "(", "Table", "$", "table", ",", "Index", "$", "index", ")", "{", "if", "(", "$", "index", "->", "getType", "(", ")", "===", "Index", "::", "UNIQUE", ")", "{", "$", "def", "=", "'UNIQUE INDEX'", ";", "}", "else", "{", "$", "def", "=", "'INDEX'", ";", "}", "if", "(", "is_string", "(", "$", "index", "->", "getName", "(", ")", ")", ")", "{", "$", "indexName", "=", "$", "index", "->", "getName", "(", ")", ";", "}", "else", "{", "$", "indexName", "=", "$", "table", "->", "getName", "(", ")", ".", "'_'", ";", "foreach", "(", "$", "index", "->", "getColumns", "(", ")", "as", "$", "column", ")", "{", "$", "indexName", ".=", "$", "column", ".", "'_'", ";", "}", "$", "indexName", ".=", "'index'", ";", "}", "$", "def", ".=", "' `'", ".", "$", "indexName", ".", "'`'", ";", "return", "$", "def", ";", "}" ]
Gets the SQLite Index Definition for an Index object. @param \Phinx\Db\Table\Table $table Table @param \Phinx\Db\Table\Index $index Index @return string
[ "Gets", "the", "SQLite", "Index", "Definition", "for", "an", "Index", "object", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Adapter/SQLiteAdapter.php#L1230-L1249
train
cakephp/phinx
src/Phinx/Db/Adapter/SQLiteAdapter.php
SQLiteAdapter.getForeignKeySqlDefinition
protected function getForeignKeySqlDefinition(ForeignKey $foreignKey) { $def = ''; if ($foreignKey->getConstraint()) { $def .= ' CONSTRAINT ' . $this->quoteColumnName($foreignKey->getConstraint()); } else { $columnNames = []; foreach ($foreignKey->getColumns() as $column) { $columnNames[] = $this->quoteColumnName($column); } $def .= ' FOREIGN KEY (' . implode(',', $columnNames) . ')'; $refColumnNames = []; foreach ($foreignKey->getReferencedColumns() as $column) { $refColumnNames[] = $this->quoteColumnName($column); } $def .= ' REFERENCES ' . $this->quoteTableName($foreignKey->getReferencedTable()->getName()) . ' (' . implode(',', $refColumnNames) . ')'; if ($foreignKey->getOnDelete()) { $def .= ' ON DELETE ' . $foreignKey->getOnDelete(); } if ($foreignKey->getOnUpdate()) { $def .= ' ON UPDATE ' . $foreignKey->getOnUpdate(); } } return $def; }
php
protected function getForeignKeySqlDefinition(ForeignKey $foreignKey) { $def = ''; if ($foreignKey->getConstraint()) { $def .= ' CONSTRAINT ' . $this->quoteColumnName($foreignKey->getConstraint()); } else { $columnNames = []; foreach ($foreignKey->getColumns() as $column) { $columnNames[] = $this->quoteColumnName($column); } $def .= ' FOREIGN KEY (' . implode(',', $columnNames) . ')'; $refColumnNames = []; foreach ($foreignKey->getReferencedColumns() as $column) { $refColumnNames[] = $this->quoteColumnName($column); } $def .= ' REFERENCES ' . $this->quoteTableName($foreignKey->getReferencedTable()->getName()) . ' (' . implode(',', $refColumnNames) . ')'; if ($foreignKey->getOnDelete()) { $def .= ' ON DELETE ' . $foreignKey->getOnDelete(); } if ($foreignKey->getOnUpdate()) { $def .= ' ON UPDATE ' . $foreignKey->getOnUpdate(); } } return $def; }
[ "protected", "function", "getForeignKeySqlDefinition", "(", "ForeignKey", "$", "foreignKey", ")", "{", "$", "def", "=", "''", ";", "if", "(", "$", "foreignKey", "->", "getConstraint", "(", ")", ")", "{", "$", "def", ".=", "' CONSTRAINT '", ".", "$", "this", "->", "quoteColumnName", "(", "$", "foreignKey", "->", "getConstraint", "(", ")", ")", ";", "}", "else", "{", "$", "columnNames", "=", "[", "]", ";", "foreach", "(", "$", "foreignKey", "->", "getColumns", "(", ")", "as", "$", "column", ")", "{", "$", "columnNames", "[", "]", "=", "$", "this", "->", "quoteColumnName", "(", "$", "column", ")", ";", "}", "$", "def", ".=", "' FOREIGN KEY ('", ".", "implode", "(", "','", ",", "$", "columnNames", ")", ".", "')'", ";", "$", "refColumnNames", "=", "[", "]", ";", "foreach", "(", "$", "foreignKey", "->", "getReferencedColumns", "(", ")", "as", "$", "column", ")", "{", "$", "refColumnNames", "[", "]", "=", "$", "this", "->", "quoteColumnName", "(", "$", "column", ")", ";", "}", "$", "def", ".=", "' REFERENCES '", ".", "$", "this", "->", "quoteTableName", "(", "$", "foreignKey", "->", "getReferencedTable", "(", ")", "->", "getName", "(", ")", ")", ".", "' ('", ".", "implode", "(", "','", ",", "$", "refColumnNames", ")", ".", "')'", ";", "if", "(", "$", "foreignKey", "->", "getOnDelete", "(", ")", ")", "{", "$", "def", ".=", "' ON DELETE '", ".", "$", "foreignKey", "->", "getOnDelete", "(", ")", ";", "}", "if", "(", "$", "foreignKey", "->", "getOnUpdate", "(", ")", ")", "{", "$", "def", ".=", "' ON UPDATE '", ".", "$", "foreignKey", "->", "getOnUpdate", "(", ")", ";", "}", "}", "return", "$", "def", ";", "}" ]
Gets the SQLite Foreign Key Definition for an ForeignKey object. @param \Phinx\Db\Table\ForeignKey $foreignKey @return string
[ "Gets", "the", "SQLite", "Foreign", "Key", "Definition", "for", "an", "ForeignKey", "object", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Adapter/SQLiteAdapter.php#L1265-L1290
train
cakephp/phinx
src/Phinx/Console/Command/Init.php
Init.execute
protected function execute(InputInterface $input, OutputInterface $output) { $path = $this->resolvePath($input); $format = strtolower($input->getOption('format')); $this->writeConfig($path, $format); $output->writeln("<info>created</info> {$path}"); }
php
protected function execute(InputInterface $input, OutputInterface $output) { $path = $this->resolvePath($input); $format = strtolower($input->getOption('format')); $this->writeConfig($path, $format); $output->writeln("<info>created</info> {$path}"); }
[ "protected", "function", "execute", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "$", "path", "=", "$", "this", "->", "resolvePath", "(", "$", "input", ")", ";", "$", "format", "=", "strtolower", "(", "$", "input", "->", "getOption", "(", "'format'", ")", ")", ";", "$", "this", "->", "writeConfig", "(", "$", "path", ",", "$", "format", ")", ";", "$", "output", "->", "writeln", "(", "\"<info>created</info> {$path}\"", ")", ";", "}" ]
Initializes the application. @param \Symfony\Component\Console\Input\InputInterface $input Interface implemented by all input classes. @param \Symfony\Component\Console\Output\OutputInterface $output Interface implemented by all output classes. @throws \RuntimeException @throws \InvalidArgumentException @return void
[ "Initializes", "the", "application", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Console/Command/Init.php#L68-L75
train
cakephp/phinx
src/Phinx/Console/Command/Rollback.php
Rollback.getTargetFromDate
public function getTargetFromDate($date) { if (!preg_match('/^\d{4,14}$/', $date)) { throw new \InvalidArgumentException('Invalid date. Format is YYYY[MM[DD[HH[II[SS]]]]].'); } // what we need to append to the date according to the possible date string lengths $dateStrlenToAppend = [ 14 => '', 12 => '00', 10 => '0000', 8 => '000000', 6 => '01000000', 4 => '0101000000', ]; if (!isset($dateStrlenToAppend[strlen($date)])) { throw new \InvalidArgumentException('Invalid date. Format is YYYY[MM[DD[HH[II[SS]]]]].'); } $target = $date . $dateStrlenToAppend[strlen($date)]; $dateTime = \DateTime::createFromFormat('YmdHis', $target); if ($dateTime === false) { throw new \InvalidArgumentException('Invalid date. Format is YYYY[MM[DD[HH[II[SS]]]]].'); } return $dateTime->format('YmdHis'); }
php
public function getTargetFromDate($date) { if (!preg_match('/^\d{4,14}$/', $date)) { throw new \InvalidArgumentException('Invalid date. Format is YYYY[MM[DD[HH[II[SS]]]]].'); } // what we need to append to the date according to the possible date string lengths $dateStrlenToAppend = [ 14 => '', 12 => '00', 10 => '0000', 8 => '000000', 6 => '01000000', 4 => '0101000000', ]; if (!isset($dateStrlenToAppend[strlen($date)])) { throw new \InvalidArgumentException('Invalid date. Format is YYYY[MM[DD[HH[II[SS]]]]].'); } $target = $date . $dateStrlenToAppend[strlen($date)]; $dateTime = \DateTime::createFromFormat('YmdHis', $target); if ($dateTime === false) { throw new \InvalidArgumentException('Invalid date. Format is YYYY[MM[DD[HH[II[SS]]]]].'); } return $dateTime->format('YmdHis'); }
[ "public", "function", "getTargetFromDate", "(", "$", "date", ")", "{", "if", "(", "!", "preg_match", "(", "'/^\\d{4,14}$/'", ",", "$", "date", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid date. Format is YYYY[MM[DD[HH[II[SS]]]]].'", ")", ";", "}", "// what we need to append to the date according to the possible date string lengths", "$", "dateStrlenToAppend", "=", "[", "14", "=>", "''", ",", "12", "=>", "'00'", ",", "10", "=>", "'0000'", ",", "8", "=>", "'000000'", ",", "6", "=>", "'01000000'", ",", "4", "=>", "'0101000000'", ",", "]", ";", "if", "(", "!", "isset", "(", "$", "dateStrlenToAppend", "[", "strlen", "(", "$", "date", ")", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid date. Format is YYYY[MM[DD[HH[II[SS]]]]].'", ")", ";", "}", "$", "target", "=", "$", "date", ".", "$", "dateStrlenToAppend", "[", "strlen", "(", "$", "date", ")", "]", ";", "$", "dateTime", "=", "\\", "DateTime", "::", "createFromFormat", "(", "'YmdHis'", ",", "$", "target", ")", ";", "if", "(", "$", "dateTime", "===", "false", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid date. Format is YYYY[MM[DD[HH[II[SS]]]]].'", ")", ";", "}", "return", "$", "dateTime", "->", "format", "(", "'YmdHis'", ")", ";", "}" ]
Get Target from Date @param string $date The date to convert to a target. @return string The target
[ "Get", "Target", "from", "Date" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Console/Command/Rollback.php#L143-L172
train
cakephp/phinx
src/Phinx/Wrapper/TextWrapper.php
TextWrapper.getStatus
public function getStatus($env = null) { $command = ['status']; if ($env ?: $this->hasOption('environment')) { $command += ['-e' => $env ?: $this->getOption('environment')]; } if ($this->hasOption('configuration')) { $command += ['-c' => $this->getOption('configuration')]; } if ($this->hasOption('parser')) { $command += ['-p' => $this->getOption('parser')]; } return $this->executeRun($command); }
php
public function getStatus($env = null) { $command = ['status']; if ($env ?: $this->hasOption('environment')) { $command += ['-e' => $env ?: $this->getOption('environment')]; } if ($this->hasOption('configuration')) { $command += ['-c' => $this->getOption('configuration')]; } if ($this->hasOption('parser')) { $command += ['-p' => $this->getOption('parser')]; } return $this->executeRun($command); }
[ "public", "function", "getStatus", "(", "$", "env", "=", "null", ")", "{", "$", "command", "=", "[", "'status'", "]", ";", "if", "(", "$", "env", "?", ":", "$", "this", "->", "hasOption", "(", "'environment'", ")", ")", "{", "$", "command", "+=", "[", "'-e'", "=>", "$", "env", "?", ":", "$", "this", "->", "getOption", "(", "'environment'", ")", "]", ";", "}", "if", "(", "$", "this", "->", "hasOption", "(", "'configuration'", ")", ")", "{", "$", "command", "+=", "[", "'-c'", "=>", "$", "this", "->", "getOption", "(", "'configuration'", ")", "]", ";", "}", "if", "(", "$", "this", "->", "hasOption", "(", "'parser'", ")", ")", "{", "$", "command", "+=", "[", "'-p'", "=>", "$", "this", "->", "getOption", "(", "'parser'", ")", "]", ";", "}", "return", "$", "this", "->", "executeRun", "(", "$", "command", ")", ";", "}" ]
Returns the output from running the "status" command. @param string $env environment name (optional) @return string
[ "Returns", "the", "output", "from", "running", "the", "status", "command", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Wrapper/TextWrapper.php#L91-L105
train
cakephp/phinx
src/Phinx/Wrapper/TextWrapper.php
TextWrapper.getMigrate
public function getMigrate($env = null, $target = null) { $command = ['migrate']; if ($env ?: $this->hasOption('environment')) { $command += ['-e' => $env ?: $this->getOption('environment')]; } if ($this->hasOption('configuration')) { $command += ['-c' => $this->getOption('configuration')]; } if ($this->hasOption('parser')) { $command += ['-p' => $this->getOption('parser')]; } if ($target) { $command += ['-t' => $target]; } return $this->executeRun($command); }
php
public function getMigrate($env = null, $target = null) { $command = ['migrate']; if ($env ?: $this->hasOption('environment')) { $command += ['-e' => $env ?: $this->getOption('environment')]; } if ($this->hasOption('configuration')) { $command += ['-c' => $this->getOption('configuration')]; } if ($this->hasOption('parser')) { $command += ['-p' => $this->getOption('parser')]; } if ($target) { $command += ['-t' => $target]; } return $this->executeRun($command); }
[ "public", "function", "getMigrate", "(", "$", "env", "=", "null", ",", "$", "target", "=", "null", ")", "{", "$", "command", "=", "[", "'migrate'", "]", ";", "if", "(", "$", "env", "?", ":", "$", "this", "->", "hasOption", "(", "'environment'", ")", ")", "{", "$", "command", "+=", "[", "'-e'", "=>", "$", "env", "?", ":", "$", "this", "->", "getOption", "(", "'environment'", ")", "]", ";", "}", "if", "(", "$", "this", "->", "hasOption", "(", "'configuration'", ")", ")", "{", "$", "command", "+=", "[", "'-c'", "=>", "$", "this", "->", "getOption", "(", "'configuration'", ")", "]", ";", "}", "if", "(", "$", "this", "->", "hasOption", "(", "'parser'", ")", ")", "{", "$", "command", "+=", "[", "'-p'", "=>", "$", "this", "->", "getOption", "(", "'parser'", ")", "]", ";", "}", "if", "(", "$", "target", ")", "{", "$", "command", "+=", "[", "'-t'", "=>", "$", "target", "]", ";", "}", "return", "$", "this", "->", "executeRun", "(", "$", "command", ")", ";", "}" ]
Returns the output from running the "migrate" command. @param string $env environment name (optional) @param string $target target version (optional) @return string
[ "Returns", "the", "output", "from", "running", "the", "migrate", "command", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Wrapper/TextWrapper.php#L113-L130
train
cakephp/phinx
src/Phinx/Wrapper/TextWrapper.php
TextWrapper.getRollback
public function getRollback($env = null, $target = null) { $command = ['rollback']; if ($env ?: $this->hasOption('environment')) { $command += ['-e' => $env ?: $this->getOption('environment')]; } if ($this->hasOption('configuration')) { $command += ['-c' => $this->getOption('configuration')]; } if ($this->hasOption('parser')) { $command += ['-p' => $this->getOption('parser')]; } if (isset($target)) { // Need to use isset() with rollback, because -t0 is a valid option! // See http://docs.phinx.org/en/latest/commands.html#the-rollback-command $command += ['-t' => $target]; } return $this->executeRun($command); }
php
public function getRollback($env = null, $target = null) { $command = ['rollback']; if ($env ?: $this->hasOption('environment')) { $command += ['-e' => $env ?: $this->getOption('environment')]; } if ($this->hasOption('configuration')) { $command += ['-c' => $this->getOption('configuration')]; } if ($this->hasOption('parser')) { $command += ['-p' => $this->getOption('parser')]; } if (isset($target)) { // Need to use isset() with rollback, because -t0 is a valid option! // See http://docs.phinx.org/en/latest/commands.html#the-rollback-command $command += ['-t' => $target]; } return $this->executeRun($command); }
[ "public", "function", "getRollback", "(", "$", "env", "=", "null", ",", "$", "target", "=", "null", ")", "{", "$", "command", "=", "[", "'rollback'", "]", ";", "if", "(", "$", "env", "?", ":", "$", "this", "->", "hasOption", "(", "'environment'", ")", ")", "{", "$", "command", "+=", "[", "'-e'", "=>", "$", "env", "?", ":", "$", "this", "->", "getOption", "(", "'environment'", ")", "]", ";", "}", "if", "(", "$", "this", "->", "hasOption", "(", "'configuration'", ")", ")", "{", "$", "command", "+=", "[", "'-c'", "=>", "$", "this", "->", "getOption", "(", "'configuration'", ")", "]", ";", "}", "if", "(", "$", "this", "->", "hasOption", "(", "'parser'", ")", ")", "{", "$", "command", "+=", "[", "'-p'", "=>", "$", "this", "->", "getOption", "(", "'parser'", ")", "]", ";", "}", "if", "(", "isset", "(", "$", "target", ")", ")", "{", "// Need to use isset() with rollback, because -t0 is a valid option!", "// See http://docs.phinx.org/en/latest/commands.html#the-rollback-command", "$", "command", "+=", "[", "'-t'", "=>", "$", "target", "]", ";", "}", "return", "$", "this", "->", "executeRun", "(", "$", "command", ")", ";", "}" ]
Returns the output from running the "rollback" command. @param string $env environment name (optional) @param mixed $target target version, or 0 (zero) fully revert (optional) @return string
[ "Returns", "the", "output", "from", "running", "the", "rollback", "command", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Wrapper/TextWrapper.php#L168-L187
train
cakephp/phinx
src/Phinx/Wrapper/TextWrapper.php
TextWrapper.getOption
protected function getOption($key) { if (!isset($this->options[$key])) { return null; } return $this->options[$key]; }
php
protected function getOption($key) { if (!isset($this->options[$key])) { return null; } return $this->options[$key]; }
[ "protected", "function", "getOption", "(", "$", "key", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "options", "[", "$", "key", "]", ")", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "options", "[", "$", "key", "]", ";", "}" ]
Get option from options array @param string $key @return string|null
[ "Get", "option", "from", "options", "array" ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Wrapper/TextWrapper.php#L206-L213
train
cakephp/phinx
src/Phinx/Wrapper/TextWrapper.php
TextWrapper.executeRun
protected function executeRun(array $command) { // Output will be written to a temporary stream, so that it can be // collected after running the command. $stream = fopen('php://temp', 'w+'); // Execute the command, capturing the output in the temporary stream // and storing the exit code for debugging purposes. $this->exit_code = $this->app->doRun(new ArrayInput($command), new StreamOutput($stream)); // Get the output of the command and close the stream, which will // destroy the temporary file. $result = stream_get_contents($stream, -1, 0); fclose($stream); return $result; }
php
protected function executeRun(array $command) { // Output will be written to a temporary stream, so that it can be // collected after running the command. $stream = fopen('php://temp', 'w+'); // Execute the command, capturing the output in the temporary stream // and storing the exit code for debugging purposes. $this->exit_code = $this->app->doRun(new ArrayInput($command), new StreamOutput($stream)); // Get the output of the command and close the stream, which will // destroy the temporary file. $result = stream_get_contents($stream, -1, 0); fclose($stream); return $result; }
[ "protected", "function", "executeRun", "(", "array", "$", "command", ")", "{", "// Output will be written to a temporary stream, so that it can be", "// collected after running the command.", "$", "stream", "=", "fopen", "(", "'php://temp'", ",", "'w+'", ")", ";", "// Execute the command, capturing the output in the temporary stream", "// and storing the exit code for debugging purposes.", "$", "this", "->", "exit_code", "=", "$", "this", "->", "app", "->", "doRun", "(", "new", "ArrayInput", "(", "$", "command", ")", ",", "new", "StreamOutput", "(", "$", "stream", ")", ")", ";", "// Get the output of the command and close the stream, which will", "// destroy the temporary file.", "$", "result", "=", "stream_get_contents", "(", "$", "stream", ",", "-", "1", ",", "0", ")", ";", "fclose", "(", "$", "stream", ")", ";", "return", "$", "result", ";", "}" ]
Execute a command, capturing output and storing the exit code. @param array $command @return string
[ "Execute", "a", "command", "capturing", "output", "and", "storing", "the", "exit", "code", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Wrapper/TextWrapper.php#L235-L251
train
cakephp/phinx
src/Phinx/Db/Table/Column.php
Column.setPrecisionAndScale
public function setPrecisionAndScale($precision, $scale) { $this->setLimit($precision); $this->scale = $scale; return $this; }
php
public function setPrecisionAndScale($precision, $scale) { $this->setLimit($precision); $this->scale = $scale; return $this; }
[ "public", "function", "setPrecisionAndScale", "(", "$", "precision", ",", "$", "scale", ")", "{", "$", "this", "->", "setLimit", "(", "$", "precision", ")", ";", "$", "this", "->", "scale", "=", "$", "scale", ";", "return", "$", "this", ";", "}" ]
Sets the number precision and scale for decimal or float column. For example `DECIMAL(5,2)`, 5 is the precision and 2 is the scale, and the column could store value from -999.99 to 999.99. @param int $precision Number precision @param int $scale Number scale @return \Phinx\Db\Table\Column
[ "Sets", "the", "number", "precision", "and", "scale", "for", "decimal", "or", "float", "column", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Table/Column.php#L391-L397
train
cakephp/phinx
src/Phinx/Db/Table/Column.php
Column.setValues
public function setValues($values) { if (!is_array($values)) { $values = preg_split('/,\s*/', $values); } $this->values = $values; return $this; }
php
public function setValues($values) { if (!is_array($values)) { $values = preg_split('/,\s*/', $values); } $this->values = $values; return $this; }
[ "public", "function", "setValues", "(", "$", "values", ")", "{", "if", "(", "!", "is_array", "(", "$", "values", ")", ")", "{", "$", "values", "=", "preg_split", "(", "'/,\\s*/'", ",", "$", "values", ")", ";", "}", "$", "this", "->", "values", "=", "$", "values", ";", "return", "$", "this", ";", "}" ]
Sets field values. @param array|string $values @return \Phinx\Db\Table\Column
[ "Sets", "field", "values", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Table/Column.php#L520-L528
train
cakephp/phinx
src/Phinx/Db/Table/Column.php
Column.setCollation
public function setCollation($collation) { $allowedTypes = [ AdapterInterface::PHINX_TYPE_CHAR, AdapterInterface::PHINX_TYPE_STRING, AdapterInterface::PHINX_TYPE_TEXT, ]; if (!in_array($this->getType(), $allowedTypes)) { throw new \UnexpectedValueException('Collation may be set only for types: ' . implode(', ', $allowedTypes)); } $this->collation = $collation; return $this; }
php
public function setCollation($collation) { $allowedTypes = [ AdapterInterface::PHINX_TYPE_CHAR, AdapterInterface::PHINX_TYPE_STRING, AdapterInterface::PHINX_TYPE_TEXT, ]; if (!in_array($this->getType(), $allowedTypes)) { throw new \UnexpectedValueException('Collation may be set only for types: ' . implode(', ', $allowedTypes)); } $this->collation = $collation; return $this; }
[ "public", "function", "setCollation", "(", "$", "collation", ")", "{", "$", "allowedTypes", "=", "[", "AdapterInterface", "::", "PHINX_TYPE_CHAR", ",", "AdapterInterface", "::", "PHINX_TYPE_STRING", ",", "AdapterInterface", "::", "PHINX_TYPE_TEXT", ",", "]", ";", "if", "(", "!", "in_array", "(", "$", "this", "->", "getType", "(", ")", ",", "$", "allowedTypes", ")", ")", "{", "throw", "new", "\\", "UnexpectedValueException", "(", "'Collation may be set only for types: '", ".", "implode", "(", "', '", ",", "$", "allowedTypes", ")", ")", ";", "}", "$", "this", "->", "collation", "=", "$", "collation", ";", "return", "$", "this", ";", "}" ]
Sets the column collation. @param string $collation @throws \UnexpectedValueException If collation not allowed for type @return $this
[ "Sets", "the", "column", "collation", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Table/Column.php#L548-L562
train
cakephp/phinx
src/Phinx/Db/Table/Column.php
Column.setEncoding
public function setEncoding($encoding) { $allowedTypes = [ AdapterInterface::PHINX_TYPE_CHAR, AdapterInterface::PHINX_TYPE_STRING, AdapterInterface::PHINX_TYPE_TEXT, ]; if (!in_array($this->getType(), $allowedTypes)) { throw new \UnexpectedValueException('Character set may be set only for types: ' . implode(', ', $allowedTypes)); } $this->encoding = $encoding; return $this; }
php
public function setEncoding($encoding) { $allowedTypes = [ AdapterInterface::PHINX_TYPE_CHAR, AdapterInterface::PHINX_TYPE_STRING, AdapterInterface::PHINX_TYPE_TEXT, ]; if (!in_array($this->getType(), $allowedTypes)) { throw new \UnexpectedValueException('Character set may be set only for types: ' . implode(', ', $allowedTypes)); } $this->encoding = $encoding; return $this; }
[ "public", "function", "setEncoding", "(", "$", "encoding", ")", "{", "$", "allowedTypes", "=", "[", "AdapterInterface", "::", "PHINX_TYPE_CHAR", ",", "AdapterInterface", "::", "PHINX_TYPE_STRING", ",", "AdapterInterface", "::", "PHINX_TYPE_TEXT", ",", "]", ";", "if", "(", "!", "in_array", "(", "$", "this", "->", "getType", "(", ")", ",", "$", "allowedTypes", ")", ")", "{", "throw", "new", "\\", "UnexpectedValueException", "(", "'Character set may be set only for types: '", ".", "implode", "(", "', '", ",", "$", "allowedTypes", ")", ")", ";", "}", "$", "this", "->", "encoding", "=", "$", "encoding", ";", "return", "$", "this", ";", "}" ]
Sets the column character set. @param string $encoding @throws \UnexpectedValueException If character set not allowed for type @return $this
[ "Sets", "the", "column", "character", "set", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Table/Column.php#L582-L596
train
cakephp/phinx
src/Phinx/Db/Table/Column.php
Column.setOptions
public function setOptions($options) { $validOptions = $this->getValidOptions(); $aliasOptions = $this->getAliasedOptions(); foreach ($options as $option => $value) { if (isset($aliasOptions[$option])) { // proxy alias -> option $option = $aliasOptions[$option]; } if (!in_array($option, $validOptions, true)) { throw new \RuntimeException(sprintf('"%s" is not a valid column option.', $option)); } $method = 'set' . ucfirst($option); $this->$method($value); } return $this; }
php
public function setOptions($options) { $validOptions = $this->getValidOptions(); $aliasOptions = $this->getAliasedOptions(); foreach ($options as $option => $value) { if (isset($aliasOptions[$option])) { // proxy alias -> option $option = $aliasOptions[$option]; } if (!in_array($option, $validOptions, true)) { throw new \RuntimeException(sprintf('"%s" is not a valid column option.', $option)); } $method = 'set' . ucfirst($option); $this->$method($value); } return $this; }
[ "public", "function", "setOptions", "(", "$", "options", ")", "{", "$", "validOptions", "=", "$", "this", "->", "getValidOptions", "(", ")", ";", "$", "aliasOptions", "=", "$", "this", "->", "getAliasedOptions", "(", ")", ";", "foreach", "(", "$", "options", "as", "$", "option", "=>", "$", "value", ")", "{", "if", "(", "isset", "(", "$", "aliasOptions", "[", "$", "option", "]", ")", ")", "{", "// proxy alias -> option", "$", "option", "=", "$", "aliasOptions", "[", "$", "option", "]", ";", "}", "if", "(", "!", "in_array", "(", "$", "option", ",", "$", "validOptions", ",", "true", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'\"%s\" is not a valid column option.'", ",", "$", "option", ")", ")", ";", "}", "$", "method", "=", "'set'", ".", "ucfirst", "(", "$", "option", ")", ";", "$", "this", "->", "$", "method", "(", "$", "value", ")", ";", "}", "return", "$", "this", ";", "}" ]
Utility method that maps an array of column options to this objects methods. @param array $options Options @return \Phinx\Db\Table\Column
[ "Utility", "method", "that", "maps", "an", "array", "of", "column", "options", "to", "this", "objects", "methods", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Db/Table/Column.php#L652-L672
train
cakephp/phinx
src/Phinx/Config/Config.php
Config.fromYaml
public static function fromYaml($configFilePath) { $configFile = file_get_contents($configFilePath); $configArray = Yaml::parse($configFile); if (!is_array($configArray)) { throw new \RuntimeException(sprintf( 'File \'%s\' must be valid YAML', $configFilePath )); } return new static($configArray, $configFilePath); }
php
public static function fromYaml($configFilePath) { $configFile = file_get_contents($configFilePath); $configArray = Yaml::parse($configFile); if (!is_array($configArray)) { throw new \RuntimeException(sprintf( 'File \'%s\' must be valid YAML', $configFilePath )); } return new static($configArray, $configFilePath); }
[ "public", "static", "function", "fromYaml", "(", "$", "configFilePath", ")", "{", "$", "configFile", "=", "file_get_contents", "(", "$", "configFilePath", ")", ";", "$", "configArray", "=", "Yaml", "::", "parse", "(", "$", "configFile", ")", ";", "if", "(", "!", "is_array", "(", "$", "configArray", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'File \\'%s\\' must be valid YAML'", ",", "$", "configFilePath", ")", ")", ";", "}", "return", "new", "static", "(", "$", "configArray", ",", "$", "configFilePath", ")", ";", "}" ]
Create a new instance of the config class using a Yaml file path. @param string $configFilePath Path to the Yaml File @throws \RuntimeException @return \Phinx\Config\Config
[ "Create", "a", "new", "instance", "of", "the", "config", "class", "using", "a", "Yaml", "file", "path", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Config/Config.php#L79-L92
train
cakephp/phinx
src/Phinx/Config/Config.php
Config.fromJson
public static function fromJson($configFilePath) { $configArray = json_decode(file_get_contents($configFilePath), true); if (!is_array($configArray)) { throw new \RuntimeException(sprintf( 'File \'%s\' must be valid JSON', $configFilePath )); } return new static($configArray, $configFilePath); }
php
public static function fromJson($configFilePath) { $configArray = json_decode(file_get_contents($configFilePath), true); if (!is_array($configArray)) { throw new \RuntimeException(sprintf( 'File \'%s\' must be valid JSON', $configFilePath )); } return new static($configArray, $configFilePath); }
[ "public", "static", "function", "fromJson", "(", "$", "configFilePath", ")", "{", "$", "configArray", "=", "json_decode", "(", "file_get_contents", "(", "$", "configFilePath", ")", ",", "true", ")", ";", "if", "(", "!", "is_array", "(", "$", "configArray", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'File \\'%s\\' must be valid JSON'", ",", "$", "configFilePath", ")", ")", ";", "}", "return", "new", "static", "(", "$", "configArray", ",", "$", "configFilePath", ")", ";", "}" ]
Create a new instance of the config class using a JSON file path. @param string $configFilePath Path to the JSON File @throws \RuntimeException @return \Phinx\Config\Config
[ "Create", "a", "new", "instance", "of", "the", "config", "class", "using", "a", "JSON", "file", "path", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Config/Config.php#L101-L112
train
cakephp/phinx
src/Phinx/Config/Config.php
Config.fromPhp
public static function fromPhp($configFilePath) { ob_start(); /** @noinspection PhpIncludeInspection */ $configArray = include($configFilePath); // Hide console output ob_end_clean(); if (!is_array($configArray)) { throw new \RuntimeException(sprintf( 'PHP file \'%s\' must return an array', $configFilePath )); } return new static($configArray, $configFilePath); }
php
public static function fromPhp($configFilePath) { ob_start(); /** @noinspection PhpIncludeInspection */ $configArray = include($configFilePath); // Hide console output ob_end_clean(); if (!is_array($configArray)) { throw new \RuntimeException(sprintf( 'PHP file \'%s\' must return an array', $configFilePath )); } return new static($configArray, $configFilePath); }
[ "public", "static", "function", "fromPhp", "(", "$", "configFilePath", ")", "{", "ob_start", "(", ")", ";", "/** @noinspection PhpIncludeInspection */", "$", "configArray", "=", "include", "(", "$", "configFilePath", ")", ";", "// Hide console output", "ob_end_clean", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "configArray", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'PHP file \\'%s\\' must return an array'", ",", "$", "configFilePath", ")", ")", ";", "}", "return", "new", "static", "(", "$", "configArray", ",", "$", "configFilePath", ")", ";", "}" ]
Create a new instance of the config class using a PHP file path. @param string $configFilePath Path to the PHP File @throws \RuntimeException @return \Phinx\Config\Config
[ "Create", "a", "new", "instance", "of", "the", "config", "class", "using", "a", "PHP", "file", "path", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Config/Config.php#L121-L138
train
cakephp/phinx
src/Phinx/Config/Config.php
Config.replaceTokens
protected function replaceTokens(array $arr) { // Get environment variables // $_ENV is empty because variables_order does not include it normally $tokens = []; foreach ($_SERVER as $varname => $varvalue) { if (0 === strpos($varname, 'PHINX_')) { $tokens['%%' . $varname . '%%'] = $varvalue; } } // Phinx defined tokens (override env tokens) $tokens['%%PHINX_CONFIG_PATH%%'] = $this->getConfigFilePath(); $tokens['%%PHINX_CONFIG_DIR%%'] = dirname($this->getConfigFilePath()); // Recurse the array and replace tokens return $this->recurseArrayForTokens($arr, $tokens); }
php
protected function replaceTokens(array $arr) { // Get environment variables // $_ENV is empty because variables_order does not include it normally $tokens = []; foreach ($_SERVER as $varname => $varvalue) { if (0 === strpos($varname, 'PHINX_')) { $tokens['%%' . $varname . '%%'] = $varvalue; } } // Phinx defined tokens (override env tokens) $tokens['%%PHINX_CONFIG_PATH%%'] = $this->getConfigFilePath(); $tokens['%%PHINX_CONFIG_DIR%%'] = dirname($this->getConfigFilePath()); // Recurse the array and replace tokens return $this->recurseArrayForTokens($arr, $tokens); }
[ "protected", "function", "replaceTokens", "(", "array", "$", "arr", ")", "{", "// Get environment variables", "// $_ENV is empty because variables_order does not include it normally", "$", "tokens", "=", "[", "]", ";", "foreach", "(", "$", "_SERVER", "as", "$", "varname", "=>", "$", "varvalue", ")", "{", "if", "(", "0", "===", "strpos", "(", "$", "varname", ",", "'PHINX_'", ")", ")", "{", "$", "tokens", "[", "'%%'", ".", "$", "varname", ".", "'%%'", "]", "=", "$", "varvalue", ";", "}", "}", "// Phinx defined tokens (override env tokens)", "$", "tokens", "[", "'%%PHINX_CONFIG_PATH%%'", "]", "=", "$", "this", "->", "getConfigFilePath", "(", ")", ";", "$", "tokens", "[", "'%%PHINX_CONFIG_DIR%%'", "]", "=", "dirname", "(", "$", "this", "->", "getConfigFilePath", "(", ")", ")", ";", "// Recurse the array and replace tokens", "return", "$", "this", "->", "recurseArrayForTokens", "(", "$", "arr", ",", "$", "tokens", ")", ";", "}" ]
Replace tokens in the specified array. @param array $arr Array to replace @return array
[ "Replace", "tokens", "in", "the", "specified", "array", "." ]
229d02f174a904d9ee2a49e95dfb434e73e53e04
https://github.com/cakephp/phinx/blob/229d02f174a904d9ee2a49e95dfb434e73e53e04/src/Phinx/Config/Config.php#L362-L379
train