id int32 0 241k | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
35,700 | ouqiang/etcd-php | src/Client.php | Client.changeUserPassword | public function changeUserPassword($user, $password)
{
$params = [
'name' => $user,
'password' => $password,
];
$body = $this->request(self::URI_AUTH_USER_CHANGE_PASSWORD, $params);
return $body;
} | php | public function changeUserPassword($user, $password)
{
$params = [
'name' => $user,
'password' => $password,
];
$body = $this->request(self::URI_AUTH_USER_CHANGE_PASSWORD, $params);
return $body;
} | [
"public",
"function",
"changeUserPassword",
"(",
"$",
"user",
",",
"$",
"password",
")",
"{",
"$",
"params",
"=",
"[",
"'name'",
"=>",
"$",
"user",
",",
"'password'",
"=>",
"$",
"password",
",",
"]",
";",
"$",
"body",
"=",
"$",
"this",
"->",
"request",
"(",
"self",
"::",
"URI_AUTH_USER_CHANGE_PASSWORD",
",",
"$",
"params",
")",
";",
"return",
"$",
"body",
";",
"}"
] | change the password of a specified user.
@param string $user
@param string $password
@return array
@throws \GuzzleHttp\Exception\BadResponseException | [
"change",
"the",
"password",
"of",
"a",
"specified",
"user",
"."
] | 8d16ee71fadb50e055b83509da78e21ff959fe2c | https://github.com/ouqiang/etcd-php/blob/8d16ee71fadb50e055b83509da78e21ff959fe2c/src/Client.php#L595-L605 |
35,701 | ouqiang/etcd-php | src/Client.php | Client.grantRolePermission | public function grantRolePermission($role, $permType, $key, $rangeEnd = null)
{
$params = [
'name' => $role,
'perm' => [
'permType' => $permType,
'key' => base64_encode($key),
],
];
if ($rangeEnd !== null) {
$params['perm']['range_end'] = base64_encode($rangeEnd);
}
$body = $this->request(self::URI_AUTH_ROLE_GRANT, $params);
return $body;
} | php | public function grantRolePermission($role, $permType, $key, $rangeEnd = null)
{
$params = [
'name' => $role,
'perm' => [
'permType' => $permType,
'key' => base64_encode($key),
],
];
if ($rangeEnd !== null) {
$params['perm']['range_end'] = base64_encode($rangeEnd);
}
$body = $this->request(self::URI_AUTH_ROLE_GRANT, $params);
return $body;
} | [
"public",
"function",
"grantRolePermission",
"(",
"$",
"role",
",",
"$",
"permType",
",",
"$",
"key",
",",
"$",
"rangeEnd",
"=",
"null",
")",
"{",
"$",
"params",
"=",
"[",
"'name'",
"=>",
"$",
"role",
",",
"'perm'",
"=>",
"[",
"'permType'",
"=>",
"$",
"permType",
",",
"'key'",
"=>",
"base64_encode",
"(",
"$",
"key",
")",
",",
"]",
",",
"]",
";",
"if",
"(",
"$",
"rangeEnd",
"!==",
"null",
")",
"{",
"$",
"params",
"[",
"'perm'",
"]",
"[",
"'range_end'",
"]",
"=",
"base64_encode",
"(",
"$",
"rangeEnd",
")",
";",
"}",
"$",
"body",
"=",
"$",
"this",
"->",
"request",
"(",
"self",
"::",
"URI_AUTH_ROLE_GRANT",
",",
"$",
"params",
")",
";",
"return",
"$",
"body",
";",
"}"
] | grant a permission of a specified key or range to a specified role.
@param string $role
@param int $permType
@param string $key
@param string|null $rangeEnd
@return array
@throws \GuzzleHttp\Exception\BadResponseException | [
"grant",
"a",
"permission",
"of",
"a",
"specified",
"key",
"or",
"range",
"to",
"a",
"specified",
"role",
"."
] | 8d16ee71fadb50e055b83509da78e21ff959fe2c | https://github.com/ouqiang/etcd-php/blob/8d16ee71fadb50e055b83509da78e21ff959fe2c/src/Client.php#L617-L633 |
35,702 | ouqiang/etcd-php | src/Client.php | Client.revokeRolePermission | public function revokeRolePermission($role, $key, $rangeEnd = null)
{
$params = [
'role' => $role,
'key' => $key,
];
if ($rangeEnd !== null) {
$params['range_end'] = $rangeEnd;
}
$body = $this->request(self::URI_AUTH_ROLE_REVOKE, $params);
return $body;
} | php | public function revokeRolePermission($role, $key, $rangeEnd = null)
{
$params = [
'role' => $role,
'key' => $key,
];
if ($rangeEnd !== null) {
$params['range_end'] = $rangeEnd;
}
$body = $this->request(self::URI_AUTH_ROLE_REVOKE, $params);
return $body;
} | [
"public",
"function",
"revokeRolePermission",
"(",
"$",
"role",
",",
"$",
"key",
",",
"$",
"rangeEnd",
"=",
"null",
")",
"{",
"$",
"params",
"=",
"[",
"'role'",
"=>",
"$",
"role",
",",
"'key'",
"=>",
"$",
"key",
",",
"]",
";",
"if",
"(",
"$",
"rangeEnd",
"!==",
"null",
")",
"{",
"$",
"params",
"[",
"'range_end'",
"]",
"=",
"$",
"rangeEnd",
";",
"}",
"$",
"body",
"=",
"$",
"this",
"->",
"request",
"(",
"self",
"::",
"URI_AUTH_ROLE_REVOKE",
",",
"$",
"params",
")",
";",
"return",
"$",
"body",
";",
"}"
] | revoke a key or range permission of a specified role.
@param string $role
@param string $key
@param string|null $rangeEnd
@return array
@throws BadResponseException | [
"revoke",
"a",
"key",
"or",
"range",
"permission",
"of",
"a",
"specified",
"role",
"."
] | 8d16ee71fadb50e055b83509da78e21ff959fe2c | https://github.com/ouqiang/etcd-php/blob/8d16ee71fadb50e055b83509da78e21ff959fe2c/src/Client.php#L644-L657 |
35,703 | ouqiang/etcd-php | src/Client.php | Client.grantUserRole | public function grantUserRole($user, $role)
{
$params = [
'user' => $user,
'role' => $role,
];
$body = $this->request(self::URI_AUTH_USER_GRANT, $params);
return $body;
} | php | public function grantUserRole($user, $role)
{
$params = [
'user' => $user,
'role' => $role,
];
$body = $this->request(self::URI_AUTH_USER_GRANT, $params);
return $body;
} | [
"public",
"function",
"grantUserRole",
"(",
"$",
"user",
",",
"$",
"role",
")",
"{",
"$",
"params",
"=",
"[",
"'user'",
"=>",
"$",
"user",
",",
"'role'",
"=>",
"$",
"role",
",",
"]",
";",
"$",
"body",
"=",
"$",
"this",
"->",
"request",
"(",
"self",
"::",
"URI_AUTH_USER_GRANT",
",",
"$",
"params",
")",
";",
"return",
"$",
"body",
";",
"}"
] | grant a role to a specified user.
@param string $user
@param string $role
@return array
@throws BadResponseException | [
"grant",
"a",
"role",
"to",
"a",
"specified",
"user",
"."
] | 8d16ee71fadb50e055b83509da78e21ff959fe2c | https://github.com/ouqiang/etcd-php/blob/8d16ee71fadb50e055b83509da78e21ff959fe2c/src/Client.php#L667-L677 |
35,704 | ouqiang/etcd-php | src/Client.php | Client.revokeUserRole | public function revokeUserRole($user, $role)
{
$params = [
'name' => $user,
'role' => $role,
];
$body = $this->request(self::URI_AUTH_USER_REVOKE, $params);
return $body;
} | php | public function revokeUserRole($user, $role)
{
$params = [
'name' => $user,
'role' => $role,
];
$body = $this->request(self::URI_AUTH_USER_REVOKE, $params);
return $body;
} | [
"public",
"function",
"revokeUserRole",
"(",
"$",
"user",
",",
"$",
"role",
")",
"{",
"$",
"params",
"=",
"[",
"'name'",
"=>",
"$",
"user",
",",
"'role'",
"=>",
"$",
"role",
",",
"]",
";",
"$",
"body",
"=",
"$",
"this",
"->",
"request",
"(",
"self",
"::",
"URI_AUTH_USER_REVOKE",
",",
"$",
"params",
")",
";",
"return",
"$",
"body",
";",
"}"
] | revoke a role of specified user.
@param string $user
@param string $role
@return array
@throws \GuzzleHttp\Exception\BadResponseException | [
"revoke",
"a",
"role",
"of",
"specified",
"user",
"."
] | 8d16ee71fadb50e055b83509da78e21ff959fe2c | https://github.com/ouqiang/etcd-php/blob/8d16ee71fadb50e055b83509da78e21ff959fe2c/src/Client.php#L687-L697 |
35,705 | XavRsl/Cas | src/Xavrsl/Cas/CasManager.php | CasManager.connection | public function connection()
{
if ( empty($this->connection))
{
$this->connection = $this->createConnection();
}
return $this->connection;
} | php | public function connection()
{
if ( empty($this->connection))
{
$this->connection = $this->createConnection();
}
return $this->connection;
} | [
"public",
"function",
"connection",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"connection",
")",
")",
"{",
"$",
"this",
"->",
"connection",
"=",
"$",
"this",
"->",
"createConnection",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"connection",
";",
"}"
] | Get a Cas connection instance.
@return Xavrsl\Cas\Directory | [
"Get",
"a",
"Cas",
"connection",
"instance",
"."
] | 2f9dc56844e5e6b463bcb751d651a62c9e76111b | https://github.com/XavRsl/Cas/blob/2f9dc56844e5e6b463bcb751d651a62c9e76111b/src/Xavrsl/Cas/CasManager.php#L31-L39 |
35,706 | XavRsl/Cas | src/Xavrsl/Cas/Sso.php | Sso.initializeCas | private function initializeCas()
{
$this->configureDebug();
// initialize CAS client
$this->configureCasClient();
$this->configureSslValidation();
phpCAS::handleLogoutRequests();
$this->configureProxyChain();
} | php | private function initializeCas()
{
$this->configureDebug();
// initialize CAS client
$this->configureCasClient();
$this->configureSslValidation();
phpCAS::handleLogoutRequests();
$this->configureProxyChain();
} | [
"private",
"function",
"initializeCas",
"(",
")",
"{",
"$",
"this",
"->",
"configureDebug",
"(",
")",
";",
"// initialize CAS client",
"$",
"this",
"->",
"configureCasClient",
"(",
")",
";",
"$",
"this",
"->",
"configureSslValidation",
"(",
")",
";",
"phpCAS",
"::",
"handleLogoutRequests",
"(",
")",
";",
"$",
"this",
"->",
"configureProxyChain",
"(",
")",
";",
"}"
] | Make PHPCAS Initialization
Initialize phpCAS before authentication
@return none | [
"Make",
"PHPCAS",
"Initialization"
] | 2f9dc56844e5e6b463bcb751d651a62c9e76111b | https://github.com/XavRsl/Cas/blob/2f9dc56844e5e6b463bcb751d651a62c9e76111b/src/Xavrsl/Cas/Sso.php#L38-L48 |
35,707 | XavRsl/Cas | src/Xavrsl/Cas/Sso.php | Sso.configureDebug | private function configureDebug()
{
if($debug = $this->config['cas_debug'])
{
$path = (gettype($debug) == 'string') ? $debug : '';
phpCAS::setDebug($path);
// https://github.com/Jasig/phpCAS/commit/bb382f5038f6241c7c577fb55430ad505f1f6e23
phpCAS::setVerbose(true);
}
} | php | private function configureDebug()
{
if($debug = $this->config['cas_debug'])
{
$path = (gettype($debug) == 'string') ? $debug : '';
phpCAS::setDebug($path);
// https://github.com/Jasig/phpCAS/commit/bb382f5038f6241c7c577fb55430ad505f1f6e23
phpCAS::setVerbose(true);
}
} | [
"private",
"function",
"configureDebug",
"(",
")",
"{",
"if",
"(",
"$",
"debug",
"=",
"$",
"this",
"->",
"config",
"[",
"'cas_debug'",
"]",
")",
"{",
"$",
"path",
"=",
"(",
"gettype",
"(",
"$",
"debug",
")",
"==",
"'string'",
")",
"?",
"$",
"debug",
":",
"''",
";",
"phpCAS",
"::",
"setDebug",
"(",
"$",
"path",
")",
";",
"// https://github.com/Jasig/phpCAS/commit/bb382f5038f6241c7c577fb55430ad505f1f6e23",
"phpCAS",
"::",
"setVerbose",
"(",
"true",
")",
";",
"}",
"}"
] | Configure CAS debug | [
"Configure",
"CAS",
"debug"
] | 2f9dc56844e5e6b463bcb751d651a62c9e76111b | https://github.com/XavRsl/Cas/blob/2f9dc56844e5e6b463bcb751d651a62c9e76111b/src/Xavrsl/Cas/Sso.php#L53-L62 |
35,708 | XavRsl/Cas | src/Xavrsl/Cas/Sso.php | Sso.configureCasClient | private function configureCasClient()
{
$method = !$this->config['cas_proxy'] ? 'client' : 'proxy';
// Last argument of method (proxy or client) is $changeSessionID. It is true by default. It means it will
// override the framework's session_id. This allows for Single Sign Out. And it means that there is no point
// in using the framework's session and authentication objects. If CAS destroys the session, it will destroy it
// for everyone and you only need to deal with one session.
phpCAS::$method(
!$this->config['cas_saml'] ? CAS_VERSION_2_0 : SAML_VERSION_1_1,
$this->config['cas_hostname'],
(integer) $this->config['cas_port'],
$this->config['cas_uri']
);
} | php | private function configureCasClient()
{
$method = !$this->config['cas_proxy'] ? 'client' : 'proxy';
// Last argument of method (proxy or client) is $changeSessionID. It is true by default. It means it will
// override the framework's session_id. This allows for Single Sign Out. And it means that there is no point
// in using the framework's session and authentication objects. If CAS destroys the session, it will destroy it
// for everyone and you only need to deal with one session.
phpCAS::$method(
!$this->config['cas_saml'] ? CAS_VERSION_2_0 : SAML_VERSION_1_1,
$this->config['cas_hostname'],
(integer) $this->config['cas_port'],
$this->config['cas_uri']
);
} | [
"private",
"function",
"configureCasClient",
"(",
")",
"{",
"$",
"method",
"=",
"!",
"$",
"this",
"->",
"config",
"[",
"'cas_proxy'",
"]",
"?",
"'client'",
":",
"'proxy'",
";",
"// Last argument of method (proxy or client) is $changeSessionID. It is true by default. It means it will",
"// override the framework's session_id. This allows for Single Sign Out. And it means that there is no point",
"// in using the framework's session and authentication objects. If CAS destroys the session, it will destroy it",
"// for everyone and you only need to deal with one session.",
"phpCAS",
"::",
"$",
"method",
"(",
"!",
"$",
"this",
"->",
"config",
"[",
"'cas_saml'",
"]",
"?",
"CAS_VERSION_2_0",
":",
"SAML_VERSION_1_1",
",",
"$",
"this",
"->",
"config",
"[",
"'cas_hostname'",
"]",
",",
"(",
"integer",
")",
"$",
"this",
"->",
"config",
"[",
"'cas_port'",
"]",
",",
"$",
"this",
"->",
"config",
"[",
"'cas_uri'",
"]",
")",
";",
"}"
] | Configure CAS Client | [
"Configure",
"CAS",
"Client"
] | 2f9dc56844e5e6b463bcb751d651a62c9e76111b | https://github.com/XavRsl/Cas/blob/2f9dc56844e5e6b463bcb751d651a62c9e76111b/src/Xavrsl/Cas/Sso.php#L68-L81 |
35,709 | XavRsl/Cas | src/Xavrsl/Cas/Sso.php | Sso.configureSslValidation | private function configureSslValidation()
{
// set SSL validation for the CAS server
if ($this->config['cas_validation'] == 'ca' || $this->config['cas_validation'] == 'self')
{
phpCAS::setCasServerCACert($this->config['cas_cert']);
}
else
{
phpCAS::setNoCasServerValidation();
}
} | php | private function configureSslValidation()
{
// set SSL validation for the CAS server
if ($this->config['cas_validation'] == 'ca' || $this->config['cas_validation'] == 'self')
{
phpCAS::setCasServerCACert($this->config['cas_cert']);
}
else
{
phpCAS::setNoCasServerValidation();
}
} | [
"private",
"function",
"configureSslValidation",
"(",
")",
"{",
"// set SSL validation for the CAS server",
"if",
"(",
"$",
"this",
"->",
"config",
"[",
"'cas_validation'",
"]",
"==",
"'ca'",
"||",
"$",
"this",
"->",
"config",
"[",
"'cas_validation'",
"]",
"==",
"'self'",
")",
"{",
"phpCAS",
"::",
"setCasServerCACert",
"(",
"$",
"this",
"->",
"config",
"[",
"'cas_cert'",
"]",
")",
";",
"}",
"else",
"{",
"phpCAS",
"::",
"setNoCasServerValidation",
"(",
")",
";",
"}",
"}"
] | Configure SSL Validation
Having some kind of server cert validation in production
is highly recommended. | [
"Configure",
"SSL",
"Validation"
] | 2f9dc56844e5e6b463bcb751d651a62c9e76111b | https://github.com/XavRsl/Cas/blob/2f9dc56844e5e6b463bcb751d651a62c9e76111b/src/Xavrsl/Cas/Sso.php#L89-L100 |
35,710 | XavRsl/Cas | src/Xavrsl/Cas/Sso.php | Sso.configureProxyChain | private function configureProxyChain()
{
if (is_array($this->config['cas_proxied_services'])
&& !empty($this->config['cas_proxied_services']))
{
phpCAS::allowProxyChain(new \CAS_ProxyChain($this->config['cas_proxied_services']));
}
} | php | private function configureProxyChain()
{
if (is_array($this->config['cas_proxied_services'])
&& !empty($this->config['cas_proxied_services']))
{
phpCAS::allowProxyChain(new \CAS_ProxyChain($this->config['cas_proxied_services']));
}
} | [
"private",
"function",
"configureProxyChain",
"(",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"config",
"[",
"'cas_proxied_services'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"config",
"[",
"'cas_proxied_services'",
"]",
")",
")",
"{",
"phpCAS",
"::",
"allowProxyChain",
"(",
"new",
"\\",
"CAS_ProxyChain",
"(",
"$",
"this",
"->",
"config",
"[",
"'cas_proxied_services'",
"]",
")",
")",
";",
"}",
"}"
] | Configure Cas Proxy Chain
Cas can proxy services. Here you can specify which ones are allowed. | [
"Configure",
"Cas",
"Proxy",
"Chain"
] | 2f9dc56844e5e6b463bcb751d651a62c9e76111b | https://github.com/XavRsl/Cas/blob/2f9dc56844e5e6b463bcb751d651a62c9e76111b/src/Xavrsl/Cas/Sso.php#L107-L114 |
35,711 | bpolaszek/bentools-etl | src/Exception/UnexpectedTypeException.php | UnexpectedTypeException.throwIfNot | public static function throwIfNot($actualObject, string $expectedType, bool $allowNull = false): void
{
if (!is_a($expectedType, $expectedType, true)) {
if (\gettype($actualObject) !== $expectedType) {
if (null === $actualObject && $allowNull) {
return;
}
throw new self($expectedType, $actualObject);
}
return;
}
if (!$actualObject instanceof $expectedType) {
if (null === $actualObject && $allowNull) {
return;
}
throw new self($expectedType, $actualObject);
}
} | php | public static function throwIfNot($actualObject, string $expectedType, bool $allowNull = false): void
{
if (!is_a($expectedType, $expectedType, true)) {
if (\gettype($actualObject) !== $expectedType) {
if (null === $actualObject && $allowNull) {
return;
}
throw new self($expectedType, $actualObject);
}
return;
}
if (!$actualObject instanceof $expectedType) {
if (null === $actualObject && $allowNull) {
return;
}
throw new self($expectedType, $actualObject);
}
} | [
"public",
"static",
"function",
"throwIfNot",
"(",
"$",
"actualObject",
",",
"string",
"$",
"expectedType",
",",
"bool",
"$",
"allowNull",
"=",
"false",
")",
":",
"void",
"{",
"if",
"(",
"!",
"is_a",
"(",
"$",
"expectedType",
",",
"$",
"expectedType",
",",
"true",
")",
")",
"{",
"if",
"(",
"\\",
"gettype",
"(",
"$",
"actualObject",
")",
"!==",
"$",
"expectedType",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"actualObject",
"&&",
"$",
"allowNull",
")",
"{",
"return",
";",
"}",
"throw",
"new",
"self",
"(",
"$",
"expectedType",
",",
"$",
"actualObject",
")",
";",
"}",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"actualObject",
"instanceof",
"$",
"expectedType",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"actualObject",
"&&",
"$",
"allowNull",
")",
"{",
"return",
";",
"}",
"throw",
"new",
"self",
"(",
"$",
"expectedType",
",",
"$",
"actualObject",
")",
";",
"}",
"}"
] | Throw an UnexpectedTypeException if actual object doesn't match expected type.
@param $actualObject
@param string $expectedType
@param bool $allowNull
@throws UnexpectedTypeException | [
"Throw",
"an",
"UnexpectedTypeException",
"if",
"actual",
"object",
"doesn",
"t",
"match",
"expected",
"type",
"."
] | d76dea73c5949866a9773ace19a4006f111e4b71 | https://github.com/bpolaszek/bentools-etl/blob/d76dea73c5949866a9773ace19a4006f111e4b71/src/Exception/UnexpectedTypeException.php#L30-L48 |
35,712 | bpolaszek/bentools-etl | src/Etl.php | Etl.process | public function process($data, ...$initLoaderArgs): void
{
$flushCounter = $totalCounter = 0;
$this->start();
foreach ($this->extract($data) as $key => $item) {
if ($this->shouldSkip) {
$this->skip($item, $key);
continue;
}
if ($this->shouldStop) {
$this->stop($item, $key);
break;
}
$transformed = $this->transform($item, $key);
if ($this->shouldSkip) {
$this->skip($item, $key);
continue;
}
if ($this->shouldStop) {
$this->stop($item, $key);
break;
}
$flushCounter++;
$totalCounter++;
if (1 === $totalCounter) {
$this->initLoader($item, $key, ...$initLoaderArgs);
}
$flush = (null === $this->flushEvery ? false : (0 === ($totalCounter % $this->flushEvery)));
$this->load($transformed(), $item, $key, $flush, $flushCounter, $totalCounter);
}
$this->end($flushCounter, $totalCounter);
} | php | public function process($data, ...$initLoaderArgs): void
{
$flushCounter = $totalCounter = 0;
$this->start();
foreach ($this->extract($data) as $key => $item) {
if ($this->shouldSkip) {
$this->skip($item, $key);
continue;
}
if ($this->shouldStop) {
$this->stop($item, $key);
break;
}
$transformed = $this->transform($item, $key);
if ($this->shouldSkip) {
$this->skip($item, $key);
continue;
}
if ($this->shouldStop) {
$this->stop($item, $key);
break;
}
$flushCounter++;
$totalCounter++;
if (1 === $totalCounter) {
$this->initLoader($item, $key, ...$initLoaderArgs);
}
$flush = (null === $this->flushEvery ? false : (0 === ($totalCounter % $this->flushEvery)));
$this->load($transformed(), $item, $key, $flush, $flushCounter, $totalCounter);
}
$this->end($flushCounter, $totalCounter);
} | [
"public",
"function",
"process",
"(",
"$",
"data",
",",
"...",
"$",
"initLoaderArgs",
")",
":",
"void",
"{",
"$",
"flushCounter",
"=",
"$",
"totalCounter",
"=",
"0",
";",
"$",
"this",
"->",
"start",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"extract",
"(",
"$",
"data",
")",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"shouldSkip",
")",
"{",
"$",
"this",
"->",
"skip",
"(",
"$",
"item",
",",
"$",
"key",
")",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"shouldStop",
")",
"{",
"$",
"this",
"->",
"stop",
"(",
"$",
"item",
",",
"$",
"key",
")",
";",
"break",
";",
"}",
"$",
"transformed",
"=",
"$",
"this",
"->",
"transform",
"(",
"$",
"item",
",",
"$",
"key",
")",
";",
"if",
"(",
"$",
"this",
"->",
"shouldSkip",
")",
"{",
"$",
"this",
"->",
"skip",
"(",
"$",
"item",
",",
"$",
"key",
")",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"shouldStop",
")",
"{",
"$",
"this",
"->",
"stop",
"(",
"$",
"item",
",",
"$",
"key",
")",
";",
"break",
";",
"}",
"$",
"flushCounter",
"++",
";",
"$",
"totalCounter",
"++",
";",
"if",
"(",
"1",
"===",
"$",
"totalCounter",
")",
"{",
"$",
"this",
"->",
"initLoader",
"(",
"$",
"item",
",",
"$",
"key",
",",
"...",
"$",
"initLoaderArgs",
")",
";",
"}",
"$",
"flush",
"=",
"(",
"null",
"===",
"$",
"this",
"->",
"flushEvery",
"?",
"false",
":",
"(",
"0",
"===",
"(",
"$",
"totalCounter",
"%",
"$",
"this",
"->",
"flushEvery",
")",
")",
")",
";",
"$",
"this",
"->",
"load",
"(",
"$",
"transformed",
"(",
")",
",",
"$",
"item",
",",
"$",
"key",
",",
"$",
"flush",
",",
"$",
"flushCounter",
",",
"$",
"totalCounter",
")",
";",
"}",
"$",
"this",
"->",
"end",
"(",
"$",
"flushCounter",
",",
"$",
"totalCounter",
")",
";",
"}"
] | Run the ETL on the given input.
@param $data
@param ...$initLoaderArgs - Optional arguments for loader init
@throws EtlException | [
"Run",
"the",
"ETL",
"on",
"the",
"given",
"input",
"."
] | d76dea73c5949866a9773ace19a4006f111e4b71 | https://github.com/bpolaszek/bentools-etl/blob/d76dea73c5949866a9773ace19a4006f111e4b71/src/Etl.php#L104-L144 |
35,713 | bpolaszek/bentools-etl | src/Etl.php | Etl.skip | private function skip($item, $key): void
{
$this->shouldSkip = false;
$this->eventDispatcher->dispatch(new ItemEvent(EtlEvents::SKIP, $item, $key, $this));
} | php | private function skip($item, $key): void
{
$this->shouldSkip = false;
$this->eventDispatcher->dispatch(new ItemEvent(EtlEvents::SKIP, $item, $key, $this));
} | [
"private",
"function",
"skip",
"(",
"$",
"item",
",",
"$",
"key",
")",
":",
"void",
"{",
"$",
"this",
"->",
"shouldSkip",
"=",
"false",
";",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"new",
"ItemEvent",
"(",
"EtlEvents",
"::",
"SKIP",
",",
"$",
"item",
",",
"$",
"key",
",",
"$",
"this",
")",
")",
";",
"}"
] | Process item skip.
@param $item
@param $key | [
"Process",
"item",
"skip",
"."
] | d76dea73c5949866a9773ace19a4006f111e4b71 | https://github.com/bpolaszek/bentools-etl/blob/d76dea73c5949866a9773ace19a4006f111e4b71/src/Etl.php#L166-L170 |
35,714 | bpolaszek/bentools-etl | src/Etl.php | Etl.stopProcessing | public function stopProcessing(bool $rollback = false): void
{
$this->shouldStop = true;
$this->shouldRollback = $rollback;
} | php | public function stopProcessing(bool $rollback = false): void
{
$this->shouldStop = true;
$this->shouldRollback = $rollback;
} | [
"public",
"function",
"stopProcessing",
"(",
"bool",
"$",
"rollback",
"=",
"false",
")",
":",
"void",
"{",
"$",
"this",
"->",
"shouldStop",
"=",
"true",
";",
"$",
"this",
"->",
"shouldRollback",
"=",
"$",
"rollback",
";",
"}"
] | Ask the ETl to stop.
@param bool $rollback - if the loader should rollback instead of flushing. | [
"Ask",
"the",
"ETl",
"to",
"stop",
"."
] | d76dea73c5949866a9773ace19a4006f111e4b71 | https://github.com/bpolaszek/bentools-etl/blob/d76dea73c5949866a9773ace19a4006f111e4b71/src/Etl.php#L177-L181 |
35,715 | bpolaszek/bentools-etl | src/Etl.php | Etl.reset | private function reset(): void
{
$this->shouldSkip = false;
$this->shouldStop = false;
$this->shouldRollback = false;
} | php | private function reset(): void
{
$this->shouldSkip = false;
$this->shouldStop = false;
$this->shouldRollback = false;
} | [
"private",
"function",
"reset",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"shouldSkip",
"=",
"false",
";",
"$",
"this",
"->",
"shouldStop",
"=",
"false",
";",
"$",
"this",
"->",
"shouldRollback",
"=",
"false",
";",
"}"
] | Reset the ETL. | [
"Reset",
"the",
"ETL",
"."
] | d76dea73c5949866a9773ace19a4006f111e4b71 | https://github.com/bpolaszek/bentools-etl/blob/d76dea73c5949866a9773ace19a4006f111e4b71/src/Etl.php#L195-L200 |
35,716 | bpolaszek/bentools-etl | src/Etl.php | Etl.extract | private function extract($data): iterable
{
$items = null === $this->extract ? $data : ($this->extract)($data, $this);
if (null === $items) {
$items = new \EmptyIterator();
}
if (!\is_iterable($items)) {
throw new EtlException('Could not extract data.');
}
try {
foreach ($items as $key => $item) {
try {
$this->shouldSkip = false;
$this->eventDispatcher->dispatch(new ItemEvent(EtlEvents::EXTRACT, $item, $key, $this));
yield $key => $item;
} catch (\Exception $e) {
continue;
}
}
} catch (\Throwable $e) {
/** @var ItemExceptionEvent $event */
$event = $this->eventDispatcher->dispatch(new ItemExceptionEvent(EtlEvents::EXTRACT_EXCEPTION, $item ?? null, $key ?? null, $this, $e));
if ($event->shouldThrowException()) {
throw $e;
}
}
} | php | private function extract($data): iterable
{
$items = null === $this->extract ? $data : ($this->extract)($data, $this);
if (null === $items) {
$items = new \EmptyIterator();
}
if (!\is_iterable($items)) {
throw new EtlException('Could not extract data.');
}
try {
foreach ($items as $key => $item) {
try {
$this->shouldSkip = false;
$this->eventDispatcher->dispatch(new ItemEvent(EtlEvents::EXTRACT, $item, $key, $this));
yield $key => $item;
} catch (\Exception $e) {
continue;
}
}
} catch (\Throwable $e) {
/** @var ItemExceptionEvent $event */
$event = $this->eventDispatcher->dispatch(new ItemExceptionEvent(EtlEvents::EXTRACT_EXCEPTION, $item ?? null, $key ?? null, $this, $e));
if ($event->shouldThrowException()) {
throw $e;
}
}
} | [
"private",
"function",
"extract",
"(",
"$",
"data",
")",
":",
"iterable",
"{",
"$",
"items",
"=",
"null",
"===",
"$",
"this",
"->",
"extract",
"?",
"$",
"data",
":",
"(",
"$",
"this",
"->",
"extract",
")",
"(",
"$",
"data",
",",
"$",
"this",
")",
";",
"if",
"(",
"null",
"===",
"$",
"items",
")",
"{",
"$",
"items",
"=",
"new",
"\\",
"EmptyIterator",
"(",
")",
";",
"}",
"if",
"(",
"!",
"\\",
"is_iterable",
"(",
"$",
"items",
")",
")",
"{",
"throw",
"new",
"EtlException",
"(",
"'Could not extract data.'",
")",
";",
"}",
"try",
"{",
"foreach",
"(",
"$",
"items",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"shouldSkip",
"=",
"false",
";",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"new",
"ItemEvent",
"(",
"EtlEvents",
"::",
"EXTRACT",
",",
"$",
"item",
",",
"$",
"key",
",",
"$",
"this",
")",
")",
";",
"yield",
"$",
"key",
"=>",
"$",
"item",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"continue",
";",
"}",
"}",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
"/** @var ItemExceptionEvent $event */",
"$",
"event",
"=",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"new",
"ItemExceptionEvent",
"(",
"EtlEvents",
"::",
"EXTRACT_EXCEPTION",
",",
"$",
"item",
"??",
"null",
",",
"$",
"key",
"??",
"null",
",",
"$",
"this",
",",
"$",
"e",
")",
")",
";",
"if",
"(",
"$",
"event",
"->",
"shouldThrowException",
"(",
")",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"}",
"}"
] | Extract data.
@param $data
@return iterable
@throws EtlException | [
"Extract",
"data",
"."
] | d76dea73c5949866a9773ace19a4006f111e4b71 | https://github.com/bpolaszek/bentools-etl/blob/d76dea73c5949866a9773ace19a4006f111e4b71/src/Etl.php#L209-L238 |
35,717 | bpolaszek/bentools-etl | src/Etl.php | Etl.transform | private function transform($item, $key)
{
$transformed = ($this->transform)($item, $key, $this);
if (!$transformed instanceof \Generator) {
throw new EtlException('The transformer must return a generator.');
}
// Traverse generator to trigger events
try {
$transformed = \iterator_to_array($transformed);
$this->eventDispatcher->dispatch(new ItemEvent(EtlEvents::TRANSFORM, $item, $key, $this));
} catch (\Exception $e) {
/** @var ItemExceptionEvent $event */
$event = $this->eventDispatcher->dispatch(new ItemExceptionEvent(EtlEvents::TRANSFORM_EXCEPTION, $item, $key, $this, $e));
if ($event->shouldThrowException()) {
throw $e;
}
}
return function () use ($transformed) {
yield from $transformed;
};
} | php | private function transform($item, $key)
{
$transformed = ($this->transform)($item, $key, $this);
if (!$transformed instanceof \Generator) {
throw new EtlException('The transformer must return a generator.');
}
// Traverse generator to trigger events
try {
$transformed = \iterator_to_array($transformed);
$this->eventDispatcher->dispatch(new ItemEvent(EtlEvents::TRANSFORM, $item, $key, $this));
} catch (\Exception $e) {
/** @var ItemExceptionEvent $event */
$event = $this->eventDispatcher->dispatch(new ItemExceptionEvent(EtlEvents::TRANSFORM_EXCEPTION, $item, $key, $this, $e));
if ($event->shouldThrowException()) {
throw $e;
}
}
return function () use ($transformed) {
yield from $transformed;
};
} | [
"private",
"function",
"transform",
"(",
"$",
"item",
",",
"$",
"key",
")",
"{",
"$",
"transformed",
"=",
"(",
"$",
"this",
"->",
"transform",
")",
"(",
"$",
"item",
",",
"$",
"key",
",",
"$",
"this",
")",
";",
"if",
"(",
"!",
"$",
"transformed",
"instanceof",
"\\",
"Generator",
")",
"{",
"throw",
"new",
"EtlException",
"(",
"'The transformer must return a generator.'",
")",
";",
"}",
"// Traverse generator to trigger events",
"try",
"{",
"$",
"transformed",
"=",
"\\",
"iterator_to_array",
"(",
"$",
"transformed",
")",
";",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"new",
"ItemEvent",
"(",
"EtlEvents",
"::",
"TRANSFORM",
",",
"$",
"item",
",",
"$",
"key",
",",
"$",
"this",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"/** @var ItemExceptionEvent $event */",
"$",
"event",
"=",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"new",
"ItemExceptionEvent",
"(",
"EtlEvents",
"::",
"TRANSFORM_EXCEPTION",
",",
"$",
"item",
",",
"$",
"key",
",",
"$",
"this",
",",
"$",
"e",
")",
")",
";",
"if",
"(",
"$",
"event",
"->",
"shouldThrowException",
"(",
")",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"}",
"return",
"function",
"(",
")",
"use",
"(",
"$",
"transformed",
")",
"{",
"yield",
"from",
"$",
"transformed",
";",
"}",
";",
"}"
] | Transform data.
@param $item
@param $key
@return callable
@throws EtlException | [
"Transform",
"data",
"."
] | d76dea73c5949866a9773ace19a4006f111e4b71 | https://github.com/bpolaszek/bentools-etl/blob/d76dea73c5949866a9773ace19a4006f111e4b71/src/Etl.php#L248-L271 |
35,718 | bpolaszek/bentools-etl | src/Etl.php | Etl.initLoader | private function initLoader($item, $key, ...$initLoaderArgs): void
{
$this->eventDispatcher->dispatch(new ItemEvent(EtlEvents::LOADER_INIT, $item, $key, $this));
if (null === $this->init) {
return;
}
($this->init)(...$initLoaderArgs);
} | php | private function initLoader($item, $key, ...$initLoaderArgs): void
{
$this->eventDispatcher->dispatch(new ItemEvent(EtlEvents::LOADER_INIT, $item, $key, $this));
if (null === $this->init) {
return;
}
($this->init)(...$initLoaderArgs);
} | [
"private",
"function",
"initLoader",
"(",
"$",
"item",
",",
"$",
"key",
",",
"...",
"$",
"initLoaderArgs",
")",
":",
"void",
"{",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"new",
"ItemEvent",
"(",
"EtlEvents",
"::",
"LOADER_INIT",
",",
"$",
"item",
",",
"$",
"key",
",",
"$",
"this",
")",
")",
";",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"init",
")",
"{",
"return",
";",
"}",
"(",
"$",
"this",
"->",
"init",
")",
"(",
"...",
"$",
"initLoaderArgs",
")",
";",
"}"
] | Init the loader on the 1st item. | [
"Init",
"the",
"loader",
"on",
"the",
"1st",
"item",
"."
] | d76dea73c5949866a9773ace19a4006f111e4b71 | https://github.com/bpolaszek/bentools-etl/blob/d76dea73c5949866a9773ace19a4006f111e4b71/src/Etl.php#L276-L285 |
35,719 | bpolaszek/bentools-etl | src/Etl.php | Etl.flush | private function flush(int &$flushCounter, bool $partial): void
{
if (null === $this->flush) {
return;
}
($this->flush)($partial);
$this->eventDispatcher->dispatch(new FlushEvent($this, $flushCounter, $partial));
$flushCounter = 0;
} | php | private function flush(int &$flushCounter, bool $partial): void
{
if (null === $this->flush) {
return;
}
($this->flush)($partial);
$this->eventDispatcher->dispatch(new FlushEvent($this, $flushCounter, $partial));
$flushCounter = 0;
} | [
"private",
"function",
"flush",
"(",
"int",
"&",
"$",
"flushCounter",
",",
"bool",
"$",
"partial",
")",
":",
"void",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"flush",
")",
"{",
"return",
";",
"}",
"(",
"$",
"this",
"->",
"flush",
")",
"(",
"$",
"partial",
")",
";",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"new",
"FlushEvent",
"(",
"$",
"this",
",",
"$",
"flushCounter",
",",
"$",
"partial",
")",
")",
";",
"$",
"flushCounter",
"=",
"0",
";",
"}"
] | Flush elements. | [
"Flush",
"elements",
"."
] | d76dea73c5949866a9773ace19a4006f111e4b71 | https://github.com/bpolaszek/bentools-etl/blob/d76dea73c5949866a9773ace19a4006f111e4b71/src/Etl.php#L315-L324 |
35,720 | bpolaszek/bentools-etl | src/Etl.php | Etl.rollback | private function rollback(int &$flushCounter): void
{
if (null === $this->rollback) {
return;
}
($this->rollback)();
$this->eventDispatcher->dispatch(new RollbackEvent($this, $flushCounter));
$flushCounter = 0;
} | php | private function rollback(int &$flushCounter): void
{
if (null === $this->rollback) {
return;
}
($this->rollback)();
$this->eventDispatcher->dispatch(new RollbackEvent($this, $flushCounter));
$flushCounter = 0;
} | [
"private",
"function",
"rollback",
"(",
"int",
"&",
"$",
"flushCounter",
")",
":",
"void",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"rollback",
")",
"{",
"return",
";",
"}",
"(",
"$",
"this",
"->",
"rollback",
")",
"(",
")",
";",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"new",
"RollbackEvent",
"(",
"$",
"this",
",",
"$",
"flushCounter",
")",
")",
";",
"$",
"flushCounter",
"=",
"0",
";",
"}"
] | Restore loader's initial state. | [
"Restore",
"loader",
"s",
"initial",
"state",
"."
] | d76dea73c5949866a9773ace19a4006f111e4b71 | https://github.com/bpolaszek/bentools-etl/blob/d76dea73c5949866a9773ace19a4006f111e4b71/src/Etl.php#L329-L338 |
35,721 | bpolaszek/bentools-etl | src/Etl.php | Etl.end | private function end(int $flushCounter, int $totalCounter): void
{
if ($this->shouldRollback) {
$this->rollback($flushCounter);
$totalCounter = max(0, $totalCounter - $flushCounter);
} else {
$this->flush($flushCounter, false);
}
$this->eventDispatcher->dispatch(new EndProcessEvent($this, $totalCounter));
$this->reset();
} | php | private function end(int $flushCounter, int $totalCounter): void
{
if ($this->shouldRollback) {
$this->rollback($flushCounter);
$totalCounter = max(0, $totalCounter - $flushCounter);
} else {
$this->flush($flushCounter, false);
}
$this->eventDispatcher->dispatch(new EndProcessEvent($this, $totalCounter));
$this->reset();
} | [
"private",
"function",
"end",
"(",
"int",
"$",
"flushCounter",
",",
"int",
"$",
"totalCounter",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"shouldRollback",
")",
"{",
"$",
"this",
"->",
"rollback",
"(",
"$",
"flushCounter",
")",
";",
"$",
"totalCounter",
"=",
"max",
"(",
"0",
",",
"$",
"totalCounter",
"-",
"$",
"flushCounter",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"flush",
"(",
"$",
"flushCounter",
",",
"false",
")",
";",
"}",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"new",
"EndProcessEvent",
"(",
"$",
"this",
",",
"$",
"totalCounter",
")",
")",
";",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"}"
] | Process the end of the ETL.
@param int $flushCounter
@param int $totalCounter | [
"Process",
"the",
"end",
"of",
"the",
"ETL",
"."
] | d76dea73c5949866a9773ace19a4006f111e4b71 | https://github.com/bpolaszek/bentools-etl/blob/d76dea73c5949866a9773ace19a4006f111e4b71/src/Etl.php#L346-L356 |
35,722 | bpolaszek/bentools-etl | src/Iterator/TextLinesIterator.php | TextLinesIterator.traverseWithStrTok | private function traverseWithStrTok()
{
$tok = \strtok($this->content, "\r\n");
while (false !== $tok) {
$line = $tok;
$tok = \strtok("\n\r");
yield $line;
}
} | php | private function traverseWithStrTok()
{
$tok = \strtok($this->content, "\r\n");
while (false !== $tok) {
$line = $tok;
$tok = \strtok("\n\r");
yield $line;
}
} | [
"private",
"function",
"traverseWithStrTok",
"(",
")",
"{",
"$",
"tok",
"=",
"\\",
"strtok",
"(",
"$",
"this",
"->",
"content",
",",
"\"\\r\\n\"",
")",
";",
"while",
"(",
"false",
"!==",
"$",
"tok",
")",
"{",
"$",
"line",
"=",
"$",
"tok",
";",
"$",
"tok",
"=",
"\\",
"strtok",
"(",
"\"\\n\\r\"",
")",
";",
"yield",
"$",
"line",
";",
"}",
"}"
] | Uses strtok to split lines. Provides better performance, but skips empty lines.
@return \Generator|string[] | [
"Uses",
"strtok",
"to",
"split",
"lines",
".",
"Provides",
"better",
"performance",
"but",
"skips",
"empty",
"lines",
"."
] | d76dea73c5949866a9773ace19a4006f111e4b71 | https://github.com/bpolaszek/bentools-etl/blob/d76dea73c5949866a9773ace19a4006f111e4b71/src/Iterator/TextLinesIterator.php#L59-L67 |
35,723 | bpolaszek/bentools-etl | src/Iterator/KeysAwareCsvIterator.php | KeysAwareCsvIterator.combine | private static function combine(array $keys, array $values): array
{
$nbKeys = \count($keys);
$nbValues = \count($values);
if ($nbKeys < $nbValues) {
return \array_combine($keys, \array_slice(\array_values($values), 0, $nbKeys));
}
if ($nbKeys > $nbValues) {
return \array_combine($keys, \array_merge($values, \array_fill(0, $nbKeys - $nbValues, null)));
}
return \array_combine($keys, $values);
} | php | private static function combine(array $keys, array $values): array
{
$nbKeys = \count($keys);
$nbValues = \count($values);
if ($nbKeys < $nbValues) {
return \array_combine($keys, \array_slice(\array_values($values), 0, $nbKeys));
}
if ($nbKeys > $nbValues) {
return \array_combine($keys, \array_merge($values, \array_fill(0, $nbKeys - $nbValues, null)));
}
return \array_combine($keys, $values);
} | [
"private",
"static",
"function",
"combine",
"(",
"array",
"$",
"keys",
",",
"array",
"$",
"values",
")",
":",
"array",
"{",
"$",
"nbKeys",
"=",
"\\",
"count",
"(",
"$",
"keys",
")",
";",
"$",
"nbValues",
"=",
"\\",
"count",
"(",
"$",
"values",
")",
";",
"if",
"(",
"$",
"nbKeys",
"<",
"$",
"nbValues",
")",
"{",
"return",
"\\",
"array_combine",
"(",
"$",
"keys",
",",
"\\",
"array_slice",
"(",
"\\",
"array_values",
"(",
"$",
"values",
")",
",",
"0",
",",
"$",
"nbKeys",
")",
")",
";",
"}",
"if",
"(",
"$",
"nbKeys",
">",
"$",
"nbValues",
")",
"{",
"return",
"\\",
"array_combine",
"(",
"$",
"keys",
",",
"\\",
"array_merge",
"(",
"$",
"values",
",",
"\\",
"array_fill",
"(",
"0",
",",
"$",
"nbKeys",
"-",
"$",
"nbValues",
",",
"null",
")",
")",
")",
";",
"}",
"return",
"\\",
"array_combine",
"(",
"$",
"keys",
",",
"$",
"values",
")",
";",
"}"
] | Combine keys & values
@param array $keys
@param array $values
@return array | [
"Combine",
"keys",
"&",
"values"
] | d76dea73c5949866a9773ace19a4006f111e4b71 | https://github.com/bpolaszek/bentools-etl/blob/d76dea73c5949866a9773ace19a4006f111e4b71/src/Iterator/KeysAwareCsvIterator.php#L68-L82 |
35,724 | jumilla/laravel-extension | sources/Commands/TailCommand.php | TailCommand.tailLocalLogs | protected function tailLocalLogs($path)
{
$output = $this->output;
$lines = $this->option('lines');
(new Process('tail -f -n '.$lines.' '.escapeshellarg($path)))->setTimeout(null)->run(function ($type, $line) use ($output) {
$output->write($line);
});
} | php | protected function tailLocalLogs($path)
{
$output = $this->output;
$lines = $this->option('lines');
(new Process('tail -f -n '.$lines.' '.escapeshellarg($path)))->setTimeout(null)->run(function ($type, $line) use ($output) {
$output->write($line);
});
} | [
"protected",
"function",
"tailLocalLogs",
"(",
"$",
"path",
")",
"{",
"$",
"output",
"=",
"$",
"this",
"->",
"output",
";",
"$",
"lines",
"=",
"$",
"this",
"->",
"option",
"(",
"'lines'",
")",
";",
"(",
"new",
"Process",
"(",
"'tail -f -n '",
".",
"$",
"lines",
".",
"' '",
".",
"escapeshellarg",
"(",
"$",
"path",
")",
")",
")",
"->",
"setTimeout",
"(",
"null",
")",
"->",
"run",
"(",
"function",
"(",
"$",
"type",
",",
"$",
"line",
")",
"use",
"(",
"$",
"output",
")",
"{",
"$",
"output",
"->",
"write",
"(",
"$",
"line",
")",
";",
"}",
")",
";",
"}"
] | Tail a local log file for the application.
@param string $path
@return string | [
"Tail",
"a",
"local",
"log",
"file",
"for",
"the",
"application",
"."
] | a0ed9065fb1416eca947164dbf355ba3dc669cb3 | https://github.com/jumilla/laravel-extension/blob/a0ed9065fb1416eca947164dbf355ba3dc669cb3/sources/Commands/TailCommand.php#L93-L102 |
35,725 | jumilla/laravel-extension | sources/Generators/GeneratorCommandTrait.php | GeneratorCommandTrait.getAddon | protected function getAddon()
{
if ($addon = $this->option('addon')) {
$env = app(AddonEnvironment::class);
if (!$env->exists($addon)) {
throw new UnexpectedValueException("Addon '$addon' is not found.");
}
return $env->addon($addon);
} else {
return;
}
} | php | protected function getAddon()
{
if ($addon = $this->option('addon')) {
$env = app(AddonEnvironment::class);
if (!$env->exists($addon)) {
throw new UnexpectedValueException("Addon '$addon' is not found.");
}
return $env->addon($addon);
} else {
return;
}
} | [
"protected",
"function",
"getAddon",
"(",
")",
"{",
"if",
"(",
"$",
"addon",
"=",
"$",
"this",
"->",
"option",
"(",
"'addon'",
")",
")",
"{",
"$",
"env",
"=",
"app",
"(",
"AddonEnvironment",
"::",
"class",
")",
";",
"if",
"(",
"!",
"$",
"env",
"->",
"exists",
"(",
"$",
"addon",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"\"Addon '$addon' is not found.\"",
")",
";",
"}",
"return",
"$",
"env",
"->",
"addon",
"(",
"$",
"addon",
")",
";",
"}",
"else",
"{",
"return",
";",
"}",
"}"
] | Get addon.
@return string | [
"Get",
"addon",
"."
] | a0ed9065fb1416eca947164dbf355ba3dc669cb3 | https://github.com/jumilla/laravel-extension/blob/a0ed9065fb1416eca947164dbf355ba3dc669cb3/sources/Generators/GeneratorCommandTrait.php#L59-L72 |
35,726 | jumilla/laravel-extension | sources/Generators/GeneratorCommandTrait.php | GeneratorCommandTrait.getRootDirectory | protected function getRootDirectory()
{
if ($this->addon) {
$directories = $this->addon->config('addon.directories');
if (! $directories) {
$directories = ['classes'];
}
return $this->addon->path($directories[0]);
}
else {
return parent::getRootDirectory();
}
} | php | protected function getRootDirectory()
{
if ($this->addon) {
$directories = $this->addon->config('addon.directories');
if (! $directories) {
$directories = ['classes'];
}
return $this->addon->path($directories[0]);
}
else {
return parent::getRootDirectory();
}
} | [
"protected",
"function",
"getRootDirectory",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"addon",
")",
"{",
"$",
"directories",
"=",
"$",
"this",
"->",
"addon",
"->",
"config",
"(",
"'addon.directories'",
")",
";",
"if",
"(",
"!",
"$",
"directories",
")",
"{",
"$",
"directories",
"=",
"[",
"'classes'",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"addon",
"->",
"path",
"(",
"$",
"directories",
"[",
"0",
"]",
")",
";",
"}",
"else",
"{",
"return",
"parent",
"::",
"getRootDirectory",
"(",
")",
";",
"}",
"}"
] | Get the directory path for root namespace.
@return string | [
"Get",
"the",
"directory",
"path",
"for",
"root",
"namespace",
"."
] | a0ed9065fb1416eca947164dbf355ba3dc669cb3 | https://github.com/jumilla/laravel-extension/blob/a0ed9065fb1416eca947164dbf355ba3dc669cb3/sources/Generators/GeneratorCommandTrait.php#L109-L123 |
35,727 | oat-sa/extension-tao-outcomekeyvalue | models/classes/class.KeyValueResultStorage.php | taoAltResultStorage_models_classes_KeyValueResultStorage.extractResultVariableProperty | public function extractResultVariableProperty($variableId)
{
$variableIds = explode('http://',$variableId);
$parts = explode(static::PROPERTY_SEPARATOR, $variableIds[2]);
$itemUri = $variableIds[0] . 'http://' . $parts[0];
$propertyName = empty($parts[1]) ? 'RESPONSE' : $parts[1];
return [
$itemUri,
$propertyName
];
} | php | public function extractResultVariableProperty($variableId)
{
$variableIds = explode('http://',$variableId);
$parts = explode(static::PROPERTY_SEPARATOR, $variableIds[2]);
$itemUri = $variableIds[0] . 'http://' . $parts[0];
$propertyName = empty($parts[1]) ? 'RESPONSE' : $parts[1];
return [
$itemUri,
$propertyName
];
} | [
"public",
"function",
"extractResultVariableProperty",
"(",
"$",
"variableId",
")",
"{",
"$",
"variableIds",
"=",
"explode",
"(",
"'http://'",
",",
"$",
"variableId",
")",
";",
"$",
"parts",
"=",
"explode",
"(",
"static",
"::",
"PROPERTY_SEPARATOR",
",",
"$",
"variableIds",
"[",
"2",
"]",
")",
";",
"$",
"itemUri",
"=",
"$",
"variableIds",
"[",
"0",
"]",
".",
"'http://'",
".",
"$",
"parts",
"[",
"0",
"]",
";",
"$",
"propertyName",
"=",
"empty",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
"?",
"'RESPONSE'",
":",
"$",
"parts",
"[",
"1",
"]",
";",
"return",
"[",
"$",
"itemUri",
",",
"$",
"propertyName",
"]",
";",
"}"
] | Returns the variable property key from the absolute variable key.
@param string $variableId
@return array | [
"Returns",
"the",
"variable",
"property",
"key",
"from",
"the",
"absolute",
"variable",
"key",
"."
] | c5b4c1b20d5a9c7db643243c779fe7a3e51d5a0c | https://github.com/oat-sa/extension-tao-outcomekeyvalue/blob/c5b4c1b20d5a9c7db643243c779fe7a3e51d5a0c/models/classes/class.KeyValueResultStorage.php#L398-L410 |
35,728 | oat-sa/lib-generis-search | src/factory/QueryCriterionFactory.php | QueryCriterionFactory.get | public function get($className,array $options = array()) {
$Param = $this->getServiceLocator()->get($className);
if($this->isValidClass($Param)) {
$Param->setName($options[0])
->setOperator($options[1])
->setValue($options[2])
->setServiceLocator($this->getServiceLocator());
return $Param;
}
} | php | public function get($className,array $options = array()) {
$Param = $this->getServiceLocator()->get($className);
if($this->isValidClass($Param)) {
$Param->setName($options[0])
->setOperator($options[1])
->setValue($options[2])
->setServiceLocator($this->getServiceLocator());
return $Param;
}
} | [
"public",
"function",
"get",
"(",
"$",
"className",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"Param",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"$",
"className",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isValidClass",
"(",
"$",
"Param",
")",
")",
"{",
"$",
"Param",
"->",
"setName",
"(",
"$",
"options",
"[",
"0",
"]",
")",
"->",
"setOperator",
"(",
"$",
"options",
"[",
"1",
"]",
")",
"->",
"setValue",
"(",
"$",
"options",
"[",
"2",
"]",
")",
"->",
"setServiceLocator",
"(",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
")",
";",
"return",
"$",
"Param",
";",
"}",
"}"
] | return a new Query param
@param string $className
@param array $options
@return \oat\search\factory\QueryCriterionInterface
@throws \InvalidArgumentException | [
"return",
"a",
"new",
"Query",
"param"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/factory/QueryCriterionFactory.php#L42-L54 |
35,729 | oat-sa/lib-generis-search | src/Query.php | Query.addOr | public function addOr($value , $operator = null) {
/*@var $criterion QueryCriterionInterface */
$criterion = end($this->storedQueryCriteria);
$criterion->addOr($value, $operator);
return $this;
} | php | public function addOr($value , $operator = null) {
/*@var $criterion QueryCriterionInterface */
$criterion = end($this->storedQueryCriteria);
$criterion->addOr($value, $operator);
return $this;
} | [
"public",
"function",
"addOr",
"(",
"$",
"value",
",",
"$",
"operator",
"=",
"null",
")",
"{",
"/*@var $criterion QueryCriterionInterface */",
"$",
"criterion",
"=",
"end",
"(",
"$",
"this",
"->",
"storedQueryCriteria",
")",
";",
"$",
"criterion",
"->",
"addOr",
"(",
"$",
"value",
",",
"$",
"operator",
")",
";",
"return",
"$",
"this",
";",
"}"
] | add a new condition on same property with OR separator
@param mixed $value
@param string|null $operator
@return $this | [
"add",
"a",
"new",
"condition",
"on",
"same",
"property",
"with",
"OR",
"separator"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/Query.php#L205-L211 |
35,730 | oat-sa/lib-generis-search | src/DbSql/TaoRdf/Command/AbstractRdfOperator.php | AbstractRdfOperator.setPropertyName | protected function setPropertyName($name) {
if(!empty($name)) {
$name = $this->getDriverEscaper()->escape($name);
$name = $this->getDriverEscaper()->quote($name);
return $this->getDriverEscaper()->reserved('predicate') . ' = ' . $name . ' '
. $this->getDriverEscaper()->dbCommand('AND') . ' ( ';
}
return '';
} | php | protected function setPropertyName($name) {
if(!empty($name)) {
$name = $this->getDriverEscaper()->escape($name);
$name = $this->getDriverEscaper()->quote($name);
return $this->getDriverEscaper()->reserved('predicate') . ' = ' . $name . ' '
. $this->getDriverEscaper()->dbCommand('AND') . ' ( ';
}
return '';
} | [
"protected",
"function",
"setPropertyName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"escape",
"(",
"$",
"name",
")",
";",
"$",
"name",
"=",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"quote",
"(",
"$",
"name",
")",
";",
"return",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"reserved",
"(",
"'predicate'",
")",
".",
"' = '",
".",
"$",
"name",
".",
"' '",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"dbCommand",
"(",
"'AND'",
")",
".",
"' ( '",
";",
"}",
"return",
"''",
";",
"}"
] | set up predicate name condition
@param string $name
@return string | [
"set",
"up",
"predicate",
"name",
"condition"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/DbSql/TaoRdf/Command/AbstractRdfOperator.php#L46-L54 |
35,731 | oat-sa/lib-generis-search | src/DbSql/AbstractSqlQuerySerialyser.php | AbstractSqlQuerySerialyser.prefixQuery | public function prefixQuery() {
$options = $this->getOptions();
if ($this->validateOptions($options)) {
$this->queryPrefix = $this->getDriverEscaper()->dbCommand('SELECT') . ' ';
$fields = $this->setFieldList($options);
$this->queryPrefix .= $fields . ' ' . $this->getDriverEscaper()->dbCommand('FROM') . ' ' . $this->getDriverEscaper()->reserved($options['table']) . ' ' . $this->getDriverEscaper()->dbCommand('WHERE') . ' ';
}
return $this;
} | php | public function prefixQuery() {
$options = $this->getOptions();
if ($this->validateOptions($options)) {
$this->queryPrefix = $this->getDriverEscaper()->dbCommand('SELECT') . ' ';
$fields = $this->setFieldList($options);
$this->queryPrefix .= $fields . ' ' . $this->getDriverEscaper()->dbCommand('FROM') . ' ' . $this->getDriverEscaper()->reserved($options['table']) . ' ' . $this->getDriverEscaper()->dbCommand('WHERE') . ' ';
}
return $this;
} | [
"public",
"function",
"prefixQuery",
"(",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"getOptions",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"validateOptions",
"(",
"$",
"options",
")",
")",
"{",
"$",
"this",
"->",
"queryPrefix",
"=",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"dbCommand",
"(",
"'SELECT'",
")",
".",
"' '",
";",
"$",
"fields",
"=",
"$",
"this",
"->",
"setFieldList",
"(",
"$",
"options",
")",
";",
"$",
"this",
"->",
"queryPrefix",
".=",
"$",
"fields",
".",
"' '",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"dbCommand",
"(",
"'FROM'",
")",
".",
"' '",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"reserved",
"(",
"$",
"options",
"[",
"'table'",
"]",
")",
".",
"' '",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"dbCommand",
"(",
"'WHERE'",
")",
".",
"' '",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | create base query for SQL single table query
@return $this | [
"create",
"base",
"query",
"for",
"SQL",
"single",
"table",
"query"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/DbSql/AbstractSqlQuerySerialyser.php#L40-L51 |
35,732 | oat-sa/lib-generis-search | src/DbSql/AbstractSqlQuerySerialyser.php | AbstractSqlQuerySerialyser.setFieldList | protected function setFieldList(array $options) {
$fields = $this->getDriverEscaper()->getAllFields();
if (array_key_exists('fields', $options)) {
$fieldsList = [];
foreach ($options['fields'] as $field) {
$fieldsList[] = $this->getDriverEscaper()->reserved($field);
}
$fields = implode(' ' . $this->getDriverEscaper()->getFieldsSeparator() . ' ', $fieldsList);
}
return $fields;
} | php | protected function setFieldList(array $options) {
$fields = $this->getDriverEscaper()->getAllFields();
if (array_key_exists('fields', $options)) {
$fieldsList = [];
foreach ($options['fields'] as $field) {
$fieldsList[] = $this->getDriverEscaper()->reserved($field);
}
$fields = implode(' ' . $this->getDriverEscaper()->getFieldsSeparator() . ' ', $fieldsList);
}
return $fields;
} | [
"protected",
"function",
"setFieldList",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"getAllFields",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'fields'",
",",
"$",
"options",
")",
")",
"{",
"$",
"fieldsList",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"options",
"[",
"'fields'",
"]",
"as",
"$",
"field",
")",
"{",
"$",
"fieldsList",
"[",
"]",
"=",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"reserved",
"(",
"$",
"field",
")",
";",
"}",
"$",
"fields",
"=",
"implode",
"(",
"' '",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"getFieldsSeparator",
"(",
")",
".",
"' '",
",",
"$",
"fieldsList",
")",
";",
"}",
"return",
"$",
"fields",
";",
"}"
] | set up selected field list
@param array $options
@return string | [
"set",
"up",
"selected",
"field",
"list"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/DbSql/AbstractSqlQuerySerialyser.php#L57-L67 |
35,733 | oat-sa/lib-generis-search | src/DbSql/AbstractSqlQuerySerialyser.php | AbstractSqlQuerySerialyser.addLimit | protected function addLimit($limit, $offset = null) {
$limitQuery = '';
if (intval($limit) > 0) {
$limitQuery .= $this->getDriverEscaper()->dbCommand('LIMIT') . ' ' . $limit;
if (!is_null($offset)) {
$limitQuery .= ' ' . $this->getDriverEscaper()->dbCommand('OFFSET') . ' ' . $offset;
}
}
return $limitQuery;
} | php | protected function addLimit($limit, $offset = null) {
$limitQuery = '';
if (intval($limit) > 0) {
$limitQuery .= $this->getDriverEscaper()->dbCommand('LIMIT') . ' ' . $limit;
if (!is_null($offset)) {
$limitQuery .= ' ' . $this->getDriverEscaper()->dbCommand('OFFSET') . ' ' . $offset;
}
}
return $limitQuery;
} | [
"protected",
"function",
"addLimit",
"(",
"$",
"limit",
",",
"$",
"offset",
"=",
"null",
")",
"{",
"$",
"limitQuery",
"=",
"''",
";",
"if",
"(",
"intval",
"(",
"$",
"limit",
")",
">",
"0",
")",
"{",
"$",
"limitQuery",
".=",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"dbCommand",
"(",
"'LIMIT'",
")",
".",
"' '",
".",
"$",
"limit",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"offset",
")",
")",
"{",
"$",
"limitQuery",
".=",
"' '",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"dbCommand",
"(",
"'OFFSET'",
")",
".",
"' '",
".",
"$",
"offset",
";",
"}",
"}",
"return",
"$",
"limitQuery",
";",
"}"
] | create limit part for query
@param integer $limit
@param integer $offset
@return string | [
"create",
"limit",
"part",
"for",
"query"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/DbSql/AbstractSqlQuerySerialyser.php#L123-L135 |
35,734 | oat-sa/lib-generis-search | src/AbstractQuerySerialyser.php | AbstractQuerySerialyser.pretty | public function pretty($pretty) {
if($pretty) {
$this->operationSeparator = $this->prettyChar ;
} else {
$this->operationSeparator = $this->unPrettyChar ;
}
return $this;
} | php | public function pretty($pretty) {
if($pretty) {
$this->operationSeparator = $this->prettyChar ;
} else {
$this->operationSeparator = $this->unPrettyChar ;
}
return $this;
} | [
"public",
"function",
"pretty",
"(",
"$",
"pretty",
")",
"{",
"if",
"(",
"$",
"pretty",
")",
"{",
"$",
"this",
"->",
"operationSeparator",
"=",
"$",
"this",
"->",
"prettyChar",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"operationSeparator",
"=",
"$",
"this",
"->",
"unPrettyChar",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | change operation separator
to pretty print or unpretty print
@param boolean $pretty
@return $this | [
"change",
"operation",
"separator",
"to",
"pretty",
"print",
"or",
"unpretty",
"print"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/AbstractQuerySerialyser.php#L95-L102 |
35,735 | oat-sa/lib-generis-search | src/AbstractQuerySerialyser.php | AbstractQuerySerialyser.serialyse | public function serialyse() {
$this->query = $this->queryPrefix;
foreach ($this->criteriaList->getStoredQueries() as $query) {
$this->setNextSeparator(false);
$this->parseQuery($query);
}
$this->finishQuery();
return $this->query;
} | php | public function serialyse() {
$this->query = $this->queryPrefix;
foreach ($this->criteriaList->getStoredQueries() as $query) {
$this->setNextSeparator(false);
$this->parseQuery($query);
}
$this->finishQuery();
return $this->query;
} | [
"public",
"function",
"serialyse",
"(",
")",
"{",
"$",
"this",
"->",
"query",
"=",
"$",
"this",
"->",
"queryPrefix",
";",
"foreach",
"(",
"$",
"this",
"->",
"criteriaList",
"->",
"getStoredQueries",
"(",
")",
"as",
"$",
"query",
")",
"{",
"$",
"this",
"->",
"setNextSeparator",
"(",
"false",
")",
";",
"$",
"this",
"->",
"parseQuery",
"(",
"$",
"query",
")",
";",
"}",
"$",
"this",
"->",
"finishQuery",
"(",
")",
";",
"return",
"$",
"this",
"->",
"query",
";",
"}"
] | generate query exploitable by driver
@return string | [
"generate",
"query",
"exploitable",
"by",
"driver"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/AbstractQuerySerialyser.php#L117-L129 |
35,736 | oat-sa/lib-generis-search | src/AbstractQuerySerialyser.php | AbstractQuerySerialyser.parseQuery | protected function parseQuery(QueryInterface $query) {
$operationList = $query->getStoredQueryCriteria();
$pos = 0;
foreach ($operationList as $operation) {
if($pos > 0) {
$this->addSeparator(true);
}
$this->parseOperation($operation);
$pos++;
}
return $this;
} | php | protected function parseQuery(QueryInterface $query) {
$operationList = $query->getStoredQueryCriteria();
$pos = 0;
foreach ($operationList as $operation) {
if($pos > 0) {
$this->addSeparator(true);
}
$this->parseOperation($operation);
$pos++;
}
return $this;
} | [
"protected",
"function",
"parseQuery",
"(",
"QueryInterface",
"$",
"query",
")",
"{",
"$",
"operationList",
"=",
"$",
"query",
"->",
"getStoredQueryCriteria",
"(",
")",
";",
"$",
"pos",
"=",
"0",
";",
"foreach",
"(",
"$",
"operationList",
"as",
"$",
"operation",
")",
"{",
"if",
"(",
"$",
"pos",
">",
"0",
")",
"{",
"$",
"this",
"->",
"addSeparator",
"(",
"true",
")",
";",
"}",
"$",
"this",
"->",
"parseOperation",
"(",
"$",
"operation",
")",
";",
"$",
"pos",
"++",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | parse QueryInterface criteria
@param QueryInterface $query
@return $this | [
"parse",
"QueryInterface",
"criteria"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/AbstractQuerySerialyser.php#L136-L148 |
35,737 | oat-sa/lib-generis-search | src/AbstractQuerySerialyser.php | AbstractQuerySerialyser.parseOperation | protected function parseOperation(QueryCriterionInterface $operation) {
$operation->setValue($this->getOperationValue($operation->getValue()));
$command = $this->prepareOperator()->getOperator($operation->getOperator())->convert($operation);
$this->setConditions($command , $operation->getAnd(), 'and');
$this->setConditions($command , $operation->getOr(), 'or');
$this->addOperator($command);
return $this;
} | php | protected function parseOperation(QueryCriterionInterface $operation) {
$operation->setValue($this->getOperationValue($operation->getValue()));
$command = $this->prepareOperator()->getOperator($operation->getOperator())->convert($operation);
$this->setConditions($command , $operation->getAnd(), 'and');
$this->setConditions($command , $operation->getOr(), 'or');
$this->addOperator($command);
return $this;
} | [
"protected",
"function",
"parseOperation",
"(",
"QueryCriterionInterface",
"$",
"operation",
")",
"{",
"$",
"operation",
"->",
"setValue",
"(",
"$",
"this",
"->",
"getOperationValue",
"(",
"$",
"operation",
"->",
"getValue",
"(",
")",
")",
")",
";",
"$",
"command",
"=",
"$",
"this",
"->",
"prepareOperator",
"(",
")",
"->",
"getOperator",
"(",
"$",
"operation",
"->",
"getOperator",
"(",
")",
")",
"->",
"convert",
"(",
"$",
"operation",
")",
";",
"$",
"this",
"->",
"setConditions",
"(",
"$",
"command",
",",
"$",
"operation",
"->",
"getAnd",
"(",
")",
",",
"'and'",
")",
";",
"$",
"this",
"->",
"setConditions",
"(",
"$",
"command",
",",
"$",
"operation",
"->",
"getOr",
"(",
")",
",",
"'or'",
")",
";",
"$",
"this",
"->",
"addOperator",
"(",
"$",
"command",
")",
";",
"return",
"$",
"this",
";",
"}"
] | parse QueryCriterionInterface criteria
@param QueryCriterionInterface $operation
@return $this | [
"parse",
"QueryCriterionInterface",
"criteria"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/AbstractQuerySerialyser.php#L155-L167 |
35,738 | oat-sa/lib-generis-search | src/AbstractQuerySerialyser.php | AbstractQuerySerialyser.getOperationValue | protected function getOperationValue($value) {
if(is_a($value, '\\oat\\search\\base\\QueryBuilderInterface')) {
$serialyser = new self();
$serialyser->setDriverEscaper($this->getDriverEscaper())->setServiceLocator($this->getServiceLocator())->setOptions($this->getOptions());
$value = $serialyser->setCriteriaList($value)->prefixQuery()->serialyse();
}
return $value;
} | php | protected function getOperationValue($value) {
if(is_a($value, '\\oat\\search\\base\\QueryBuilderInterface')) {
$serialyser = new self();
$serialyser->setDriverEscaper($this->getDriverEscaper())->setServiceLocator($this->getServiceLocator())->setOptions($this->getOptions());
$value = $serialyser->setCriteriaList($value)->prefixQuery()->serialyse();
}
return $value;
} | [
"protected",
"function",
"getOperationValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_a",
"(",
"$",
"value",
",",
"'\\\\oat\\\\search\\\\base\\\\QueryBuilderInterface'",
")",
")",
"{",
"$",
"serialyser",
"=",
"new",
"self",
"(",
")",
";",
"$",
"serialyser",
"->",
"setDriverEscaper",
"(",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
")",
"->",
"setServiceLocator",
"(",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
")",
"->",
"setOptions",
"(",
"$",
"this",
"->",
"getOptions",
"(",
")",
")",
";",
"$",
"value",
"=",
"$",
"serialyser",
"->",
"setCriteriaList",
"(",
"$",
"value",
")",
"->",
"prefixQuery",
"(",
")",
"->",
"serialyse",
"(",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | convert value to string if it's an object
@param mixed $value
@return string | [
"convert",
"value",
"to",
"string",
"if",
"it",
"s",
"an",
"object"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/AbstractQuerySerialyser.php#L174-L182 |
35,739 | oat-sa/lib-generis-search | src/AbstractQuerySerialyser.php | AbstractQuerySerialyser.setConditions | protected function setConditions(&$command , array $conditionList , $separator = 'and') {
foreach($conditionList as $condition) {
$addCondition = $this->getOperator($condition->getOperator())->convert($condition);
$this->mergeCondition($command , $addCondition , $separator);
}
return $command;
} | php | protected function setConditions(&$command , array $conditionList , $separator = 'and') {
foreach($conditionList as $condition) {
$addCondition = $this->getOperator($condition->getOperator())->convert($condition);
$this->mergeCondition($command , $addCondition , $separator);
}
return $command;
} | [
"protected",
"function",
"setConditions",
"(",
"&",
"$",
"command",
",",
"array",
"$",
"conditionList",
",",
"$",
"separator",
"=",
"'and'",
")",
"{",
"foreach",
"(",
"$",
"conditionList",
"as",
"$",
"condition",
")",
"{",
"$",
"addCondition",
"=",
"$",
"this",
"->",
"getOperator",
"(",
"$",
"condition",
"->",
"getOperator",
"(",
")",
")",
"->",
"convert",
"(",
"$",
"condition",
")",
";",
"$",
"this",
"->",
"mergeCondition",
"(",
"$",
"command",
",",
"$",
"addCondition",
",",
"$",
"separator",
")",
";",
"}",
"return",
"$",
"command",
";",
"}"
] | generate and add to query a condition
exploitable by database driver
@param type $command
@param array $conditionList
@param type $separator
@return string | [
"generate",
"and",
"add",
"to",
"query",
"a",
"condition",
"exploitable",
"by",
"database",
"driver"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/AbstractQuerySerialyser.php#L193-L201 |
35,740 | oat-sa/lib-generis-search | src/AbstractQuerySerialyser.php | AbstractQuerySerialyser.getOperator | protected function getOperator($operator) {
/**
* @todo change that for a factory
*/
if(array_key_exists($operator, $this->supportedOperators)) {
$operatorClass = $this->operatorNameSpace . '\\' . ($this->supportedOperators[$operator]);
$operator = $this->getServiceLocator()->get($operatorClass);
$operator->setDriverEscaper($this->getDriverEscaper());
return $operator;
}
throw new QueryParsingException('this driver doesn\'t support ' . $operator . ' operator');
} | php | protected function getOperator($operator) {
/**
* @todo change that for a factory
*/
if(array_key_exists($operator, $this->supportedOperators)) {
$operatorClass = $this->operatorNameSpace . '\\' . ($this->supportedOperators[$operator]);
$operator = $this->getServiceLocator()->get($operatorClass);
$operator->setDriverEscaper($this->getDriverEscaper());
return $operator;
}
throw new QueryParsingException('this driver doesn\'t support ' . $operator . ' operator');
} | [
"protected",
"function",
"getOperator",
"(",
"$",
"operator",
")",
"{",
"/**\n * @todo change that for a factory\n */",
"if",
"(",
"array_key_exists",
"(",
"$",
"operator",
",",
"$",
"this",
"->",
"supportedOperators",
")",
")",
"{",
"$",
"operatorClass",
"=",
"$",
"this",
"->",
"operatorNameSpace",
".",
"'\\\\'",
".",
"(",
"$",
"this",
"->",
"supportedOperators",
"[",
"$",
"operator",
"]",
")",
";",
"$",
"operator",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"$",
"operatorClass",
")",
";",
"$",
"operator",
"->",
"setDriverEscaper",
"(",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
")",
";",
"return",
"$",
"operator",
";",
"}",
"throw",
"new",
"QueryParsingException",
"(",
"'this driver doesn\\'t support '",
".",
"$",
"operator",
".",
"' operator'",
")",
";",
"}"
] | operator command factory
@param type $operator
@return \oat\search\base\command\OperatorConverterInterface
@throws QueryParsingException | [
"operator",
"command",
"factory"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/AbstractQuerySerialyser.php#L211-L223 |
35,741 | oat-sa/lib-generis-search | src/AbstractQuerySerialyser.php | AbstractQuerySerialyser.setNextSeparator | protected function setNextSeparator($and) {
if(!is_null($this->nextSeparator)) {
$this->addSeparator($this->nextSeparator);
}
$this->nextSeparator = $and;
return $this;
} | php | protected function setNextSeparator($and) {
if(!is_null($this->nextSeparator)) {
$this->addSeparator($this->nextSeparator);
}
$this->nextSeparator = $and;
return $this;
} | [
"protected",
"function",
"setNextSeparator",
"(",
"$",
"and",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"nextSeparator",
")",
")",
"{",
"$",
"this",
"->",
"addSeparator",
"(",
"$",
"this",
"->",
"nextSeparator",
")",
";",
"}",
"$",
"this",
"->",
"nextSeparator",
"=",
"$",
"and",
";",
"return",
"$",
"this",
";",
"}"
] | change next separator to "and" or "or"
@param boolean $and
@return $this | [
"change",
"next",
"separator",
"to",
"and",
"or",
"or"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/AbstractQuerySerialyser.php#L230-L237 |
35,742 | oat-sa/lib-generis-search | src/DbSql/TaoRdf/UnionQuerySerialyser.php | UnionQuerySerialyser.mergeCondition | protected function mergeCondition(&$command, $condition, $separator = null) {
$command .= (is_null($separator)) ? '' : ' ' . $this->getDriverEscaper()->dbCommand($separator);
$command .= ' ' . $condition . $this->operationSeparator;
return $this;
} | php | protected function mergeCondition(&$command, $condition, $separator = null) {
$command .= (is_null($separator)) ? '' : ' ' . $this->getDriverEscaper()->dbCommand($separator);
$command .= ' ' . $condition . $this->operationSeparator;
return $this;
} | [
"protected",
"function",
"mergeCondition",
"(",
"&",
"$",
"command",
",",
"$",
"condition",
",",
"$",
"separator",
"=",
"null",
")",
"{",
"$",
"command",
".=",
"(",
"is_null",
"(",
"$",
"separator",
")",
")",
"?",
"''",
":",
"' '",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"dbCommand",
"(",
"$",
"separator",
")",
";",
"$",
"command",
".=",
"' '",
".",
"$",
"condition",
".",
"$",
"this",
"->",
"operationSeparator",
";",
"return",
"$",
"this",
";",
"}"
] | merge multiple condition QueryCriterion
@param string $command
@param string $condition
@param string $separator
@return $this | [
"merge",
"multiple",
"condition",
"QueryCriterion"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/DbSql/TaoRdf/UnionQuerySerialyser.php#L199-L205 |
35,743 | oat-sa/lib-generis-search | src/DbSql/TaoRdf/UnionQuerySerialyser.php | UnionQuerySerialyser.sortedQueryPrefix | protected function sortedQueryPrefix(array $aliases) {
$sortFields = [];
$result = $this->getDriverEscaper()->dbCommand('SELECT') . ' ' .
$this->getDriverEscaper()->reserved('subject') . ' ' .
$this->getDriverEscaper()->dbCommand('FROM') .
$this->operationSeparator . '(' .
$this->getDriverEscaper()->dbCommand('SELECT') . ' ' .
$this->getDriverEscaper()->reserved('mainq') . '.' .
$this->getDriverEscaper()->reserved('subject') .
$this->getDriverEscaper()->getFieldsSeparator();
foreach ($aliases as $alias) {
$sortFields[] = $this->getDriverEscaper()->reserved($alias['name']) . '.' .
$this->getDriverEscaper()->reserved('object') . ' ' .
$this->getDriverEscaper()->dbCommand('AS') . ' ' . $alias['name'];
}
$result .= implode($this->getDriverEscaper()->getFieldsSeparator(), $sortFields)
. ' ' .
$this->getDriverEscaper()->dbCommand('FROM') . ' ' .
' ( ' . $this->query . ' ) AS mainq ' .
$this->operationSeparator;
return $result;
} | php | protected function sortedQueryPrefix(array $aliases) {
$sortFields = [];
$result = $this->getDriverEscaper()->dbCommand('SELECT') . ' ' .
$this->getDriverEscaper()->reserved('subject') . ' ' .
$this->getDriverEscaper()->dbCommand('FROM') .
$this->operationSeparator . '(' .
$this->getDriverEscaper()->dbCommand('SELECT') . ' ' .
$this->getDriverEscaper()->reserved('mainq') . '.' .
$this->getDriverEscaper()->reserved('subject') .
$this->getDriverEscaper()->getFieldsSeparator();
foreach ($aliases as $alias) {
$sortFields[] = $this->getDriverEscaper()->reserved($alias['name']) . '.' .
$this->getDriverEscaper()->reserved('object') . ' ' .
$this->getDriverEscaper()->dbCommand('AS') . ' ' . $alias['name'];
}
$result .= implode($this->getDriverEscaper()->getFieldsSeparator(), $sortFields)
. ' ' .
$this->getDriverEscaper()->dbCommand('FROM') . ' ' .
' ( ' . $this->query . ' ) AS mainq ' .
$this->operationSeparator;
return $result;
} | [
"protected",
"function",
"sortedQueryPrefix",
"(",
"array",
"$",
"aliases",
")",
"{",
"$",
"sortFields",
"=",
"[",
"]",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"dbCommand",
"(",
"'SELECT'",
")",
".",
"' '",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"reserved",
"(",
"'subject'",
")",
".",
"' '",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"dbCommand",
"(",
"'FROM'",
")",
".",
"$",
"this",
"->",
"operationSeparator",
".",
"'('",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"dbCommand",
"(",
"'SELECT'",
")",
".",
"' '",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"reserved",
"(",
"'mainq'",
")",
".",
"'.'",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"reserved",
"(",
"'subject'",
")",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"getFieldsSeparator",
"(",
")",
";",
"foreach",
"(",
"$",
"aliases",
"as",
"$",
"alias",
")",
"{",
"$",
"sortFields",
"[",
"]",
"=",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"reserved",
"(",
"$",
"alias",
"[",
"'name'",
"]",
")",
".",
"'.'",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"reserved",
"(",
"'object'",
")",
".",
"' '",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"dbCommand",
"(",
"'AS'",
")",
".",
"' '",
".",
"$",
"alias",
"[",
"'name'",
"]",
";",
"}",
"$",
"result",
".=",
"implode",
"(",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"getFieldsSeparator",
"(",
")",
",",
"$",
"sortFields",
")",
".",
"' '",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"dbCommand",
"(",
"'FROM'",
")",
".",
"' '",
".",
"' ( '",
".",
"$",
"this",
"->",
"query",
".",
"' ) AS mainq '",
".",
"$",
"this",
"->",
"operationSeparator",
";",
"return",
"$",
"result",
";",
"}"
] | add prefix if query is sorted
@param array $aliases
@return string | [
"add",
"prefix",
"if",
"query",
"is",
"sorted"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/DbSql/TaoRdf/UnionQuerySerialyser.php#L251-L277 |
35,744 | oat-sa/lib-generis-search | src/DbSql/TaoRdf/UnionQuerySerialyser.php | UnionQuerySerialyser.orderByPart | protected function orderByPart(array $aliases) {
$sortFields = [];
foreach ($aliases as $alias) {
$sortFields[] = $this->getDriverEscaper()->reserved($alias['name']) . '.' .
$this->getDriverEscaper()->reserved('object') . ' ' .
$alias['dir'] . $this->operationSeparator;
}
$result = $this->getDriverEscaper()->dbCommand('ORDER BY') . ' ' .
implode($this->getDriverEscaper()->getFieldsSeparator(), $sortFields)
. $this->operationSeparator;
return $result;
} | php | protected function orderByPart(array $aliases) {
$sortFields = [];
foreach ($aliases as $alias) {
$sortFields[] = $this->getDriverEscaper()->reserved($alias['name']) . '.' .
$this->getDriverEscaper()->reserved('object') . ' ' .
$alias['dir'] . $this->operationSeparator;
}
$result = $this->getDriverEscaper()->dbCommand('ORDER BY') . ' ' .
implode($this->getDriverEscaper()->getFieldsSeparator(), $sortFields)
. $this->operationSeparator;
return $result;
} | [
"protected",
"function",
"orderByPart",
"(",
"array",
"$",
"aliases",
")",
"{",
"$",
"sortFields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aliases",
"as",
"$",
"alias",
")",
"{",
"$",
"sortFields",
"[",
"]",
"=",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"reserved",
"(",
"$",
"alias",
"[",
"'name'",
"]",
")",
".",
"'.'",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"reserved",
"(",
"'object'",
")",
".",
"' '",
".",
"$",
"alias",
"[",
"'dir'",
"]",
".",
"$",
"this",
"->",
"operationSeparator",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"dbCommand",
"(",
"'ORDER BY'",
")",
".",
"' '",
".",
"implode",
"(",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"getFieldsSeparator",
"(",
")",
",",
"$",
"sortFields",
")",
".",
"$",
"this",
"->",
"operationSeparator",
";",
"return",
"$",
"result",
";",
"}"
] | return Order by string
@param array $aliases
@return string | [
"return",
"Order",
"by",
"string"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/DbSql/TaoRdf/UnionQuerySerialyser.php#L284-L298 |
35,745 | oat-sa/lib-generis-search | src/DbSql/TaoRdf/UnionQuerySerialyser.php | UnionQuerySerialyser.addRandomSort | protected function addRandomSort() {
$random = '';
$this->query .= $this->operationSeparator .
$this->getDriverEscaper()->dbCommand('ORDER BY') . ' ' .
$this->getDriverEscaper()->random() .
$this->operationSeparator;
return $random;
} | php | protected function addRandomSort() {
$random = '';
$this->query .= $this->operationSeparator .
$this->getDriverEscaper()->dbCommand('ORDER BY') . ' ' .
$this->getDriverEscaper()->random() .
$this->operationSeparator;
return $random;
} | [
"protected",
"function",
"addRandomSort",
"(",
")",
"{",
"$",
"random",
"=",
"''",
";",
"$",
"this",
"->",
"query",
".=",
"$",
"this",
"->",
"operationSeparator",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"dbCommand",
"(",
"'ORDER BY'",
")",
".",
"' '",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"random",
"(",
")",
".",
"$",
"this",
"->",
"operationSeparator",
";",
"return",
"$",
"random",
";",
"}"
] | set sort as random
@return string | [
"set",
"sort",
"as",
"random"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/DbSql/TaoRdf/UnionQuerySerialyser.php#L365-L374 |
35,746 | oat-sa/lib-generis-search | src/QueryBuilder.php | QueryBuilder.newQuery | public function newQuery() {
$factory = $this->factory;
$factory->setServiceLocator($this->serviceLocator);
return $factory->get($this->queryClassName)->setParent($this);
} | php | public function newQuery() {
$factory = $this->factory;
$factory->setServiceLocator($this->serviceLocator);
return $factory->get($this->queryClassName)->setParent($this);
} | [
"public",
"function",
"newQuery",
"(",
")",
"{",
"$",
"factory",
"=",
"$",
"this",
"->",
"factory",
";",
"$",
"factory",
"->",
"setServiceLocator",
"(",
"$",
"this",
"->",
"serviceLocator",
")",
";",
"return",
"$",
"factory",
"->",
"get",
"(",
"$",
"this",
"->",
"queryClassName",
")",
"->",
"setParent",
"(",
"$",
"this",
")",
";",
"}"
] | generate a new query
@return \oat\search\base\QueryInterface | [
"generate",
"a",
"new",
"query"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/QueryBuilder.php#L80-L84 |
35,747 | oat-sa/lib-generis-search | src/DbSql/TaoRdf/Command/In.php | In.setValuesList | protected function setValuesList(array $values) {
$parseValues = [];
foreach ($values as $value) {
$parseValues[] = $this->getDriverEscaper()->quote($this->getDriverEscaper()->escape($value));
}
return '(' . implode(' ' . $this->getDriverEscaper()->getFieldsSeparator() . ' ' , $parseValues) . ')';
} | php | protected function setValuesList(array $values) {
$parseValues = [];
foreach ($values as $value) {
$parseValues[] = $this->getDriverEscaper()->quote($this->getDriverEscaper()->escape($value));
}
return '(' . implode(' ' . $this->getDriverEscaper()->getFieldsSeparator() . ' ' , $parseValues) . ')';
} | [
"protected",
"function",
"setValuesList",
"(",
"array",
"$",
"values",
")",
"{",
"$",
"parseValues",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"parseValues",
"[",
"]",
"=",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"quote",
"(",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"escape",
"(",
"$",
"value",
")",
")",
";",
"}",
"return",
"'('",
".",
"implode",
"(",
"' '",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"getFieldsSeparator",
"(",
")",
".",
"' '",
",",
"$",
"parseValues",
")",
".",
"')'",
";",
"}"
] | create condition for object
@param array $values
@return string | [
"create",
"condition",
"for",
"object"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/DbSql/TaoRdf/Command/In.php#L46-L52 |
35,748 | oat-sa/lib-generis-search | src/factory/FactoryAbstract.php | FactoryAbstract.isValidClass | protected function isValidClass($object) {
if(is_a($object, $this->validInterface)) {
return true;
}
throw new \InvalidArgumentException(get_class($object) . ' doesn\'t implements ' . $this->validInterface );
} | php | protected function isValidClass($object) {
if(is_a($object, $this->validInterface)) {
return true;
}
throw new \InvalidArgumentException(get_class($object) . ' doesn\'t implements ' . $this->validInterface );
} | [
"protected",
"function",
"isValidClass",
"(",
"$",
"object",
")",
"{",
"if",
"(",
"is_a",
"(",
"$",
"object",
",",
"$",
"this",
"->",
"validInterface",
")",
")",
"{",
"return",
"true",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"get_class",
"(",
"$",
"object",
")",
".",
"' doesn\\'t implements '",
".",
"$",
"this",
"->",
"validInterface",
")",
";",
"}"
] | verify if class implements valid interface
@param Object $object
@throws \InvalidArgumentException
@return boolean | [
"verify",
"if",
"class",
"implements",
"valid",
"interface"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/factory/FactoryAbstract.php#L47-L53 |
35,749 | oat-sa/lib-generis-search | src/Command/OperatorAbstractfactory.php | OperatorAbstractfactory.canCreateServiceWithName | public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) {
$interface = 'oat\search\base\command\OperatorConverterInterface';
return (class_exists($requestedName) && in_array($interface , class_implements($requestedName)));
} | php | public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) {
$interface = 'oat\search\base\command\OperatorConverterInterface';
return (class_exists($requestedName) && in_array($interface , class_implements($requestedName)));
} | [
"public",
"function",
"canCreateServiceWithName",
"(",
"ServiceLocatorInterface",
"$",
"serviceLocator",
",",
"$",
"name",
",",
"$",
"requestedName",
")",
"{",
"$",
"interface",
"=",
"'oat\\search\\base\\command\\OperatorConverterInterface'",
";",
"return",
"(",
"class_exists",
"(",
"$",
"requestedName",
")",
"&&",
"in_array",
"(",
"$",
"interface",
",",
"class_implements",
"(",
"$",
"requestedName",
")",
")",
")",
";",
"}"
] | verify if class name is an existing operator
@param ServiceLocatorInterface $serviceLocator
@param type $name
@param type $requestedName
@return boolean | [
"verify",
"if",
"class",
"name",
"is",
"an",
"existing",
"operator"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/Command/OperatorAbstractfactory.php#L51-L54 |
35,750 | oat-sa/lib-generis-search | src/DbSql/TaoRdf/QuerySerialyser.php | QuerySerialyser.setLanguageCondition | public function setLanguageCondition($language , $emptyAvailable = false) {
$languageField = $this->getDriverEscaper()->reserved('l_language');
$languageValue = $this->getDriverEscaper()->escape($language);
$sql = '(';
$sql .= $languageField .' = ' . $this->getDriverEscaper()->quote($languageValue) . '';
if($emptyAvailable) {
$sql .= ' ' . $this->getDriverEscaper()->dbCommand('OR') . ' ' . $languageField . ' = ' . $this->getDriverEscaper()->getEmpty();
}
$sql .= ') ' . $this->getDriverEscaper()->dbCommand('AND') . $this->operationSeparator;
return $sql;
} | php | public function setLanguageCondition($language , $emptyAvailable = false) {
$languageField = $this->getDriverEscaper()->reserved('l_language');
$languageValue = $this->getDriverEscaper()->escape($language);
$sql = '(';
$sql .= $languageField .' = ' . $this->getDriverEscaper()->quote($languageValue) . '';
if($emptyAvailable) {
$sql .= ' ' . $this->getDriverEscaper()->dbCommand('OR') . ' ' . $languageField . ' = ' . $this->getDriverEscaper()->getEmpty();
}
$sql .= ') ' . $this->getDriverEscaper()->dbCommand('AND') . $this->operationSeparator;
return $sql;
} | [
"public",
"function",
"setLanguageCondition",
"(",
"$",
"language",
",",
"$",
"emptyAvailable",
"=",
"false",
")",
"{",
"$",
"languageField",
"=",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"reserved",
"(",
"'l_language'",
")",
";",
"$",
"languageValue",
"=",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"escape",
"(",
"$",
"language",
")",
";",
"$",
"sql",
"=",
"'('",
";",
"$",
"sql",
".=",
"$",
"languageField",
".",
"' = '",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"quote",
"(",
"$",
"languageValue",
")",
".",
"''",
";",
"if",
"(",
"$",
"emptyAvailable",
")",
"{",
"$",
"sql",
".=",
"' '",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"dbCommand",
"(",
"'OR'",
")",
".",
"' '",
".",
"$",
"languageField",
".",
"' = '",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"getEmpty",
"(",
")",
";",
"}",
"$",
"sql",
".=",
"') '",
".",
"$",
"this",
"->",
"getDriverEscaper",
"(",
")",
"->",
"dbCommand",
"(",
"'AND'",
")",
".",
"$",
"this",
"->",
"operationSeparator",
";",
"return",
"$",
"sql",
";",
"}"
] | return an SQL string with language filter condition
@param string $language
@param boolean $emptyAvailable
@return string | [
"return",
"an",
"SQL",
"string",
"with",
"language",
"filter",
"condition"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/DbSql/TaoRdf/QuerySerialyser.php#L134-L144 |
35,751 | oat-sa/lib-generis-search | src/factory/QueryFactory.php | QueryFactory.get | public function get($className , array $options = array()) {
$Query = $this->getServiceLocator()->get($className);
if($this->isValidClass($Query)) {
return $Query->setServiceLocator($this->getServiceLocator())->setOptions($options);
}
} | php | public function get($className , array $options = array()) {
$Query = $this->getServiceLocator()->get($className);
if($this->isValidClass($Query)) {
return $Query->setServiceLocator($this->getServiceLocator())->setOptions($options);
}
} | [
"public",
"function",
"get",
"(",
"$",
"className",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"Query",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"$",
"className",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isValidClass",
"(",
"$",
"Query",
")",
")",
"{",
"return",
"$",
"Query",
"->",
"setServiceLocator",
"(",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
")",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"}",
"}"
] | return a new Query
@param string $className
@param array $options
@return \oat\search\factory\QueryInterface
@throws \InvalidArgumentException | [
"return",
"a",
"new",
"Query"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/factory/QueryFactory.php#L45-L51 |
35,752 | oat-sa/lib-generis-search | src/AbstractSearchGateWay.php | AbstractSearchGateWay.init | public function init() {
$options = $this->getServiceLocator()->get('search.options');
$this->setOptions($options);
$this->driverName = $options['driver'];
$this->setDriverEscaper($this->getServiceLocator()->get($this->driverList[$this->driverName]));
return $this;
} | php | public function init() {
$options = $this->getServiceLocator()->get('search.options');
$this->setOptions($options);
$this->driverName = $options['driver'];
$this->setDriverEscaper($this->getServiceLocator()->get($this->driverList[$this->driverName]));
return $this;
} | [
"public",
"function",
"init",
"(",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'search.options'",
")",
";",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"$",
"this",
"->",
"driverName",
"=",
"$",
"options",
"[",
"'driver'",
"]",
";",
"$",
"this",
"->",
"setDriverEscaper",
"(",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"$",
"this",
"->",
"driverList",
"[",
"$",
"this",
"->",
"driverName",
"]",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | init the gateway
@return $this | [
"init",
"the",
"gateway"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/AbstractSearchGateWay.php#L87-L94 |
35,753 | oat-sa/lib-generis-search | src/AbstractSearchGateWay.php | AbstractSearchGateWay.serialyse | public function serialyse(QueryBuilderInterface $Builder) {
$this->parsedQuery = $this->getSerialyser()->setCriteriaList($Builder)->serialyse();
return $this;
} | php | public function serialyse(QueryBuilderInterface $Builder) {
$this->parsedQuery = $this->getSerialyser()->setCriteriaList($Builder)->serialyse();
return $this;
} | [
"public",
"function",
"serialyse",
"(",
"QueryBuilderInterface",
"$",
"Builder",
")",
"{",
"$",
"this",
"->",
"parsedQuery",
"=",
"$",
"this",
"->",
"getSerialyser",
"(",
")",
"->",
"setCriteriaList",
"(",
"$",
"Builder",
")",
"->",
"serialyse",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | parse QueryBuilder and store parsed query
@param QueryBuilderInterface $Builder
@return $this | [
"parse",
"QueryBuilder",
"and",
"store",
"parsed",
"query"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/AbstractSearchGateWay.php#L101-L104 |
35,754 | oat-sa/lib-generis-search | src/AbstractSearchGateWay.php | AbstractSearchGateWay.getSerialyser | public function getSerialyser() {
$serialyser = $this->getServiceLocator()->get($this->serialyserList[$this->driverName]);
$serialyser->setServiceLocator($this->serviceLocator)->setDriverEscaper($this->driverEscaper)->setOptions($this->options)->prefixQuery();
return $serialyser;
} | php | public function getSerialyser() {
$serialyser = $this->getServiceLocator()->get($this->serialyserList[$this->driverName]);
$serialyser->setServiceLocator($this->serviceLocator)->setDriverEscaper($this->driverEscaper)->setOptions($this->options)->prefixQuery();
return $serialyser;
} | [
"public",
"function",
"getSerialyser",
"(",
")",
"{",
"$",
"serialyser",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"$",
"this",
"->",
"serialyserList",
"[",
"$",
"this",
"->",
"driverName",
"]",
")",
";",
"$",
"serialyser",
"->",
"setServiceLocator",
"(",
"$",
"this",
"->",
"serviceLocator",
")",
"->",
"setDriverEscaper",
"(",
"$",
"this",
"->",
"driverEscaper",
")",
"->",
"setOptions",
"(",
"$",
"this",
"->",
"options",
")",
"->",
"prefixQuery",
"(",
")",
";",
"return",
"$",
"serialyser",
";",
"}"
] | query serialyser factory
@return QuerySerialyserInterface | [
"query",
"serialyser",
"factory"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/AbstractSearchGateWay.php#L135-L139 |
35,755 | oat-sa/lib-generis-search | src/AbstractSearchGateWay.php | AbstractSearchGateWay.query | public function query() {
$builder = $this->getServiceLocator()->get($this->builderClassName);
$builder->setOptions($this->options)->setServiceLocator($this->serviceLocator);
return $builder;
} | php | public function query() {
$builder = $this->getServiceLocator()->get($this->builderClassName);
$builder->setOptions($this->options)->setServiceLocator($this->serviceLocator);
return $builder;
} | [
"public",
"function",
"query",
"(",
")",
"{",
"$",
"builder",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"$",
"this",
"->",
"builderClassName",
")",
";",
"$",
"builder",
"->",
"setOptions",
"(",
"$",
"this",
"->",
"options",
")",
"->",
"setServiceLocator",
"(",
"$",
"this",
"->",
"serviceLocator",
")",
";",
"return",
"$",
"builder",
";",
"}"
] | query builder factory
@return QueryBuilder | [
"query",
"builder",
"factory"
] | bf19991d7fb807341f7889f7e786f09668013a13 | https://github.com/oat-sa/lib-generis-search/blob/bf19991d7fb807341f7889f7e786f09668013a13/src/AbstractSearchGateWay.php#L163-L167 |
35,756 | apfelbox/PHP-File-Download | src/FileDownload.php | FileDownload.sendDownload | public function sendDownload ($filename, $forceDownload = true)
{
if (headers_sent())
{
throw new \RuntimeException("Cannot send file to the browser, since the headers were already sent.");
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Type: {$this->getMimeType($filename)}");
if ($forceDownload)
{
header("Content-Disposition: attachment; filename=\"{$filename}\";" );
}
else
{
header("Content-Disposition: filename=\"{$filename}\";" );
}
header("Content-Transfer-Encoding: binary");
header("Content-Length: {$this->getFileSize()}");
@ob_clean();
rewind($this->filePointer);
fpassthru($this->filePointer);
} | php | public function sendDownload ($filename, $forceDownload = true)
{
if (headers_sent())
{
throw new \RuntimeException("Cannot send file to the browser, since the headers were already sent.");
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Type: {$this->getMimeType($filename)}");
if ($forceDownload)
{
header("Content-Disposition: attachment; filename=\"{$filename}\";" );
}
else
{
header("Content-Disposition: filename=\"{$filename}\";" );
}
header("Content-Transfer-Encoding: binary");
header("Content-Length: {$this->getFileSize()}");
@ob_clean();
rewind($this->filePointer);
fpassthru($this->filePointer);
} | [
"public",
"function",
"sendDownload",
"(",
"$",
"filename",
",",
"$",
"forceDownload",
"=",
"true",
")",
"{",
"if",
"(",
"headers_sent",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Cannot send file to the browser, since the headers were already sent.\"",
")",
";",
"}",
"header",
"(",
"\"Pragma: public\"",
")",
";",
"header",
"(",
"\"Expires: 0\"",
")",
";",
"header",
"(",
"\"Cache-Control: must-revalidate, post-check=0, pre-check=0\"",
")",
";",
"header",
"(",
"\"Cache-Control: private\"",
",",
"false",
")",
";",
"header",
"(",
"\"Content-Type: {$this->getMimeType($filename)}\"",
")",
";",
"if",
"(",
"$",
"forceDownload",
")",
"{",
"header",
"(",
"\"Content-Disposition: attachment; filename=\\\"{$filename}\\\";\"",
")",
";",
"}",
"else",
"{",
"header",
"(",
"\"Content-Disposition: filename=\\\"{$filename}\\\";\"",
")",
";",
"}",
"header",
"(",
"\"Content-Transfer-Encoding: binary\"",
")",
";",
"header",
"(",
"\"Content-Length: {$this->getFileSize()}\"",
")",
";",
"@",
"ob_clean",
"(",
")",
";",
"rewind",
"(",
"$",
"this",
"->",
"filePointer",
")",
";",
"fpassthru",
"(",
"$",
"this",
"->",
"filePointer",
")",
";",
"}"
] | Sends the download to the browser
@param string $filename
@param bool $forceDownload
@throws \RuntimeException is thrown, if the headers are already sent | [
"Sends",
"the",
"download",
"to",
"the",
"browser"
] | ac97f04d89fe8a9ad9de811162953db3f07685b1 | https://github.com/apfelbox/PHP-File-Download/blob/ac97f04d89fe8a9ad9de811162953db3f07685b1/src/FileDownload.php#L55-L84 |
35,757 | apfelbox/PHP-File-Download | src/FileDownload.php | FileDownload.getMimeType | private function getMimeType ($fileName)
{
$fileExtension = pathinfo($fileName, PATHINFO_EXTENSION);
$mimeTypeHelper = Mimetypes::getInstance();
$mimeType = $mimeTypeHelper->fromExtension($fileExtension);
return !is_null($mimeType) ? $mimeType : "application/force-download";
} | php | private function getMimeType ($fileName)
{
$fileExtension = pathinfo($fileName, PATHINFO_EXTENSION);
$mimeTypeHelper = Mimetypes::getInstance();
$mimeType = $mimeTypeHelper->fromExtension($fileExtension);
return !is_null($mimeType) ? $mimeType : "application/force-download";
} | [
"private",
"function",
"getMimeType",
"(",
"$",
"fileName",
")",
"{",
"$",
"fileExtension",
"=",
"pathinfo",
"(",
"$",
"fileName",
",",
"PATHINFO_EXTENSION",
")",
";",
"$",
"mimeTypeHelper",
"=",
"Mimetypes",
"::",
"getInstance",
"(",
")",
";",
"$",
"mimeType",
"=",
"$",
"mimeTypeHelper",
"->",
"fromExtension",
"(",
"$",
"fileExtension",
")",
";",
"return",
"!",
"is_null",
"(",
"$",
"mimeType",
")",
"?",
"$",
"mimeType",
":",
"\"application/force-download\"",
";",
"}"
] | Returns the mime type of a file name
@param string $fileName
@return string | [
"Returns",
"the",
"mime",
"type",
"of",
"a",
"file",
"name"
] | ac97f04d89fe8a9ad9de811162953db3f07685b1 | https://github.com/apfelbox/PHP-File-Download/blob/ac97f04d89fe8a9ad9de811162953db3f07685b1/src/FileDownload.php#L95-L102 |
35,758 | apfelbox/PHP-File-Download | src/FileDownload.php | FileDownload.createFromFilePath | public static function createFromFilePath ($filePath)
{
if (!is_file($filePath))
{
throw new \InvalidArgumentException("File does not exist");
}
else if (!is_readable($filePath))
{
throw new \InvalidArgumentException("File to download is not readable.");
}
return new FileDownload(fopen($filePath, "rb"));
} | php | public static function createFromFilePath ($filePath)
{
if (!is_file($filePath))
{
throw new \InvalidArgumentException("File does not exist");
}
else if (!is_readable($filePath))
{
throw new \InvalidArgumentException("File to download is not readable.");
}
return new FileDownload(fopen($filePath, "rb"));
} | [
"public",
"static",
"function",
"createFromFilePath",
"(",
"$",
"filePath",
")",
"{",
"if",
"(",
"!",
"is_file",
"(",
"$",
"filePath",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"File does not exist\"",
")",
";",
"}",
"else",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"filePath",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"File to download is not readable.\"",
")",
";",
"}",
"return",
"new",
"FileDownload",
"(",
"fopen",
"(",
"$",
"filePath",
",",
"\"rb\"",
")",
")",
";",
"}"
] | Creates a new file download from a file path
@static
@param string $filePath
@throws \InvalidArgumentException is thrown, if the given file does not exist or is not readable
@return FileDownload | [
"Creates",
"a",
"new",
"file",
"download",
"from",
"a",
"file",
"path"
] | ac97f04d89fe8a9ad9de811162953db3f07685b1 | https://github.com/apfelbox/PHP-File-Download/blob/ac97f04d89fe8a9ad9de811162953db3f07685b1/src/FileDownload.php#L130-L142 |
35,759 | goto-bus-stop/recanalyst | src/Analyzers/PlayerMetaAnalyzer.php | PlayerMetaAnalyzer.readPlayerMeta | protected function readPlayerMeta($i)
{
$player = new Player($this->rec);
$player->number = $i;
$player->index = $this->readHeader('l', 4);
$human = $this->readHeader('l', 4);
$length = $this->readHeader('L', 4);
if ($length) {
$player->name = $this->readHeaderRaw($length);
} else {
$player->name = '';
}
$player->humanRaw = $human;
$player->human = $human === 0x02;
$player->spectator = $human === 0x06;
return $player;
} | php | protected function readPlayerMeta($i)
{
$player = new Player($this->rec);
$player->number = $i;
$player->index = $this->readHeader('l', 4);
$human = $this->readHeader('l', 4);
$length = $this->readHeader('L', 4);
if ($length) {
$player->name = $this->readHeaderRaw($length);
} else {
$player->name = '';
}
$player->humanRaw = $human;
$player->human = $human === 0x02;
$player->spectator = $human === 0x06;
return $player;
} | [
"protected",
"function",
"readPlayerMeta",
"(",
"$",
"i",
")",
"{",
"$",
"player",
"=",
"new",
"Player",
"(",
"$",
"this",
"->",
"rec",
")",
";",
"$",
"player",
"->",
"number",
"=",
"$",
"i",
";",
"$",
"player",
"->",
"index",
"=",
"$",
"this",
"->",
"readHeader",
"(",
"'l'",
",",
"4",
")",
";",
"$",
"human",
"=",
"$",
"this",
"->",
"readHeader",
"(",
"'l'",
",",
"4",
")",
";",
"$",
"length",
"=",
"$",
"this",
"->",
"readHeader",
"(",
"'L'",
",",
"4",
")",
";",
"if",
"(",
"$",
"length",
")",
"{",
"$",
"player",
"->",
"name",
"=",
"$",
"this",
"->",
"readHeaderRaw",
"(",
"$",
"length",
")",
";",
"}",
"else",
"{",
"$",
"player",
"->",
"name",
"=",
"''",
";",
"}",
"$",
"player",
"->",
"humanRaw",
"=",
"$",
"human",
";",
"$",
"player",
"->",
"human",
"=",
"$",
"human",
"===",
"0x02",
";",
"$",
"player",
"->",
"spectator",
"=",
"$",
"human",
"===",
"0x06",
";",
"return",
"$",
"player",
";",
"}"
] | Reads a player meta info block for a single player. This just includes
their nickname, index and "human" status. More information about players
is stored later on in the recorded game file and is read by the
PlayerInfoBlockAnalyzer.
Player meta structure:
int32 index;
int32 human; // indicates whether player is AI/human/spectator
uint32 nameLength;
char name[nameLength];
@return \RecAnalyst\Model\Player | [
"Reads",
"a",
"player",
"meta",
"info",
"block",
"for",
"a",
"single",
"player",
".",
"This",
"just",
"includes",
"their",
"nickname",
"index",
"and",
"human",
"status",
".",
"More",
"information",
"about",
"players",
"is",
"stored",
"later",
"on",
"in",
"the",
"recorded",
"game",
"file",
"and",
"is",
"read",
"by",
"the",
"PlayerInfoBlockAnalyzer",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Analyzers/PlayerMetaAnalyzer.php#L61-L77 |
35,760 | goto-bus-stop/recanalyst | src/Analyzers/PlayerMetaAnalyzer.php | PlayerMetaAnalyzer.seek | private function seek()
{
$version = $this->get(VersionAnalyzer::class);
$constant2 = pack('c*', 0x9A, 0x99, 0x99, 0x99, 0x99, 0x99, 0xF9, 0x3F);
$separator = pack('c*', 0x9D, 0xFF, 0xFF, 0xFF);
$playersByIndex = [];
$size = strlen($this->header);
$this->position = 0;
$triggerInfoPos = strrpos($this->header, $constant2, $this->position) + strlen($constant2);
$gameSettingsPos = strrpos($this->header, $separator, -($size - $triggerInfoPos)) + strlen($separator);
$this->position = $gameSettingsPos + 8;
if (!$version->isAoK) {
// Skip Map ID.
$this->position += 4;
}
// Skip difficulty & diplomacy lock.
$this->position += 8;
// TODO Is 12.3 the correct cutoff point?
if ($version->subVersion >= 12.3) {
// TODO what are theeeese?
$this->position += 16;
}
} | php | private function seek()
{
$version = $this->get(VersionAnalyzer::class);
$constant2 = pack('c*', 0x9A, 0x99, 0x99, 0x99, 0x99, 0x99, 0xF9, 0x3F);
$separator = pack('c*', 0x9D, 0xFF, 0xFF, 0xFF);
$playersByIndex = [];
$size = strlen($this->header);
$this->position = 0;
$triggerInfoPos = strrpos($this->header, $constant2, $this->position) + strlen($constant2);
$gameSettingsPos = strrpos($this->header, $separator, -($size - $triggerInfoPos)) + strlen($separator);
$this->position = $gameSettingsPos + 8;
if (!$version->isAoK) {
// Skip Map ID.
$this->position += 4;
}
// Skip difficulty & diplomacy lock.
$this->position += 8;
// TODO Is 12.3 the correct cutoff point?
if ($version->subVersion >= 12.3) {
// TODO what are theeeese?
$this->position += 16;
}
} | [
"private",
"function",
"seek",
"(",
")",
"{",
"$",
"version",
"=",
"$",
"this",
"->",
"get",
"(",
"VersionAnalyzer",
"::",
"class",
")",
";",
"$",
"constant2",
"=",
"pack",
"(",
"'c*'",
",",
"0x9A",
",",
"0x99",
",",
"0x99",
",",
"0x99",
",",
"0x99",
",",
"0x99",
",",
"0xF9",
",",
"0x3F",
")",
";",
"$",
"separator",
"=",
"pack",
"(",
"'c*'",
",",
"0x9D",
",",
"0xFF",
",",
"0xFF",
",",
"0xFF",
")",
";",
"$",
"playersByIndex",
"=",
"[",
"]",
";",
"$",
"size",
"=",
"strlen",
"(",
"$",
"this",
"->",
"header",
")",
";",
"$",
"this",
"->",
"position",
"=",
"0",
";",
"$",
"triggerInfoPos",
"=",
"strrpos",
"(",
"$",
"this",
"->",
"header",
",",
"$",
"constant2",
",",
"$",
"this",
"->",
"position",
")",
"+",
"strlen",
"(",
"$",
"constant2",
")",
";",
"$",
"gameSettingsPos",
"=",
"strrpos",
"(",
"$",
"this",
"->",
"header",
",",
"$",
"separator",
",",
"-",
"(",
"$",
"size",
"-",
"$",
"triggerInfoPos",
")",
")",
"+",
"strlen",
"(",
"$",
"separator",
")",
";",
"$",
"this",
"->",
"position",
"=",
"$",
"gameSettingsPos",
"+",
"8",
";",
"if",
"(",
"!",
"$",
"version",
"->",
"isAoK",
")",
"{",
"// Skip Map ID.",
"$",
"this",
"->",
"position",
"+=",
"4",
";",
"}",
"// Skip difficulty & diplomacy lock.",
"$",
"this",
"->",
"position",
"+=",
"8",
";",
"// TODO Is 12.3 the correct cutoff point?",
"if",
"(",
"$",
"version",
"->",
"subVersion",
">=",
"12.3",
")",
"{",
"// TODO what are theeeese?",
"$",
"this",
"->",
"position",
"+=",
"16",
";",
"}",
"}"
] | Find the position of the small player metadata block. | [
"Find",
"the",
"position",
"of",
"the",
"small",
"player",
"metadata",
"block",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Analyzers/PlayerMetaAnalyzer.php#L82-L110 |
35,761 | goto-bus-stop/recanalyst | src/Model/Team.php | Team.addPlayer | public function addPlayer(Player $player)
{
$this->players[] = $player;
if ($this->index == -1) {
$this->index = $player->team;
}
} | php | public function addPlayer(Player $player)
{
$this->players[] = $player;
if ($this->index == -1) {
$this->index = $player->team;
}
} | [
"public",
"function",
"addPlayer",
"(",
"Player",
"$",
"player",
")",
"{",
"$",
"this",
"->",
"players",
"[",
"]",
"=",
"$",
"player",
";",
"if",
"(",
"$",
"this",
"->",
"index",
"==",
"-",
"1",
")",
"{",
"$",
"this",
"->",
"index",
"=",
"$",
"player",
"->",
"team",
";",
"}",
"}"
] | Adds a player to the team.
@param \RecAnalyst\Model\Player $player The player we wish to add
@return void | [
"Adds",
"a",
"player",
"to",
"the",
"team",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Model/Team.php#L30-L36 |
35,762 | goto-bus-stop/recanalyst | src/ResourcePacks/AgeOfEmpires/Civilization.php | Civilization.isAoKCiv | public static function isAoKCiv($id)
{
return in_array($id, [
self::BRITONS,
self::FRANKS,
self::GOTHS,
self::TEUTONS,
self::JAPANESE,
self::CHINESE,
self::BYZANTINES,
self::PERSIANS,
self::SARACENS,
self::TURKS,
self::VIKINGS,
self::MONGOLS,
self::CELTS,
]);
} | php | public static function isAoKCiv($id)
{
return in_array($id, [
self::BRITONS,
self::FRANKS,
self::GOTHS,
self::TEUTONS,
self::JAPANESE,
self::CHINESE,
self::BYZANTINES,
self::PERSIANS,
self::SARACENS,
self::TURKS,
self::VIKINGS,
self::MONGOLS,
self::CELTS,
]);
} | [
"public",
"static",
"function",
"isAoKCiv",
"(",
"$",
"id",
")",
"{",
"return",
"in_array",
"(",
"$",
"id",
",",
"[",
"self",
"::",
"BRITONS",
",",
"self",
"::",
"FRANKS",
",",
"self",
"::",
"GOTHS",
",",
"self",
"::",
"TEUTONS",
",",
"self",
"::",
"JAPANESE",
",",
"self",
"::",
"CHINESE",
",",
"self",
"::",
"BYZANTINES",
",",
"self",
"::",
"PERSIANS",
",",
"self",
"::",
"SARACENS",
",",
"self",
"::",
"TURKS",
",",
"self",
"::",
"VIKINGS",
",",
"self",
"::",
"MONGOLS",
",",
"self",
"::",
"CELTS",
",",
"]",
")",
";",
"}"
] | Checks if a civilization is included in the Age of Kings base game.
@param int $id Civilization ID.
@return bool True if the given civilization exists in AoK, false
otherwise. | [
"Checks",
"if",
"a",
"civilization",
"is",
"included",
"in",
"the",
"Age",
"of",
"Kings",
"base",
"game",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/ResourcePacks/AgeOfEmpires/Civilization.php#L84-L101 |
35,763 | goto-bus-stop/recanalyst | src/ResourcePacks/AgeOfEmpires/Civilization.php | Civilization.isAoCCiv | public static function isAoCCiv($id)
{
return in_array($id, [
self::SPANISH,
self::AZTECS,
self::MAYANS,
self::HUNS,
self::KOREANS,
]);
} | php | public static function isAoCCiv($id)
{
return in_array($id, [
self::SPANISH,
self::AZTECS,
self::MAYANS,
self::HUNS,
self::KOREANS,
]);
} | [
"public",
"static",
"function",
"isAoCCiv",
"(",
"$",
"id",
")",
"{",
"return",
"in_array",
"(",
"$",
"id",
",",
"[",
"self",
"::",
"SPANISH",
",",
"self",
"::",
"AZTECS",
",",
"self",
"::",
"MAYANS",
",",
"self",
"::",
"HUNS",
",",
"self",
"::",
"KOREANS",
",",
"]",
")",
";",
"}"
] | Checks if a civilization was added in the Age of Conquerors expansion.
@param int $id Civilization ID.
@return bool True if the given civilization is part of AoC, false
otherwise. | [
"Checks",
"if",
"a",
"civilization",
"was",
"added",
"in",
"the",
"Age",
"of",
"Conquerors",
"expansion",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/ResourcePacks/AgeOfEmpires/Civilization.php#L110-L119 |
35,764 | goto-bus-stop/recanalyst | src/ResourcePacks/AgeOfEmpires/Civilization.php | Civilization.isForgottenCiv | public static function isForgottenCiv($id)
{
return in_array($id, [
self::ITALIANS,
self::INDIANS,
self::INCAS,
self::MAGYARS,
self::SLAVS,
]);
} | php | public static function isForgottenCiv($id)
{
return in_array($id, [
self::ITALIANS,
self::INDIANS,
self::INCAS,
self::MAGYARS,
self::SLAVS,
]);
} | [
"public",
"static",
"function",
"isForgottenCiv",
"(",
"$",
"id",
")",
"{",
"return",
"in_array",
"(",
"$",
"id",
",",
"[",
"self",
"::",
"ITALIANS",
",",
"self",
"::",
"INDIANS",
",",
"self",
"::",
"INCAS",
",",
"self",
"::",
"MAGYARS",
",",
"self",
"::",
"SLAVS",
",",
"]",
")",
";",
"}"
] | Checks if a civilization was added in the Forgotten Empires expansion.
@param int $id Civilization ID.
@return bool True if the given civilization is part of The Forgotten,
false otherwise. | [
"Checks",
"if",
"a",
"civilization",
"was",
"added",
"in",
"the",
"Forgotten",
"Empires",
"expansion",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/ResourcePacks/AgeOfEmpires/Civilization.php#L128-L137 |
35,765 | goto-bus-stop/recanalyst | src/Processors/MapName.php | MapName.run | public function run()
{
$header = $this->rec->header();
$messages = $header->messages;
$instructions = $messages->instructions;
$lines = explode("\n", $instructions);
foreach ($lines as $line) {
// We don't know what language the game was played in, so we try
// every language we know.
foreach ($this->mapTypeRegexes as $rx) {
$matches = [];
if (preg_match($rx, $line, $matches)) {
return $matches[1];
}
}
}
} | php | public function run()
{
$header = $this->rec->header();
$messages = $header->messages;
$instructions = $messages->instructions;
$lines = explode("\n", $instructions);
foreach ($lines as $line) {
// We don't know what language the game was played in, so we try
// every language we know.
foreach ($this->mapTypeRegexes as $rx) {
$matches = [];
if (preg_match($rx, $line, $matches)) {
return $matches[1];
}
}
}
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"header",
"=",
"$",
"this",
"->",
"rec",
"->",
"header",
"(",
")",
";",
"$",
"messages",
"=",
"$",
"header",
"->",
"messages",
";",
"$",
"instructions",
"=",
"$",
"messages",
"->",
"instructions",
";",
"$",
"lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"instructions",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"// We don't know what language the game was played in, so we try",
"// every language we know.",
"foreach",
"(",
"$",
"this",
"->",
"mapTypeRegexes",
"as",
"$",
"rx",
")",
"{",
"$",
"matches",
"=",
"[",
"]",
";",
"if",
"(",
"preg_match",
"(",
"$",
"rx",
",",
"$",
"line",
",",
"$",
"matches",
")",
")",
"{",
"return",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"}",
"}",
"}"
] | Run the processor.
@return string|null The map name, if found. | [
"Run",
"the",
"processor",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Processors/MapName.php#L68-L84 |
35,766 | goto-bus-stop/recanalyst | src/Analyzers/BodyAnalyzer.php | BodyAnalyzer.processGameStart | private function processGameStart()
{
$this->syncChecksumInterval = $this->readBody('l', 4);
if ($this->version->isMgl) {
// not sure what difference is vs mgx and up
$this->position += 28;
$ver = ord($this->body[$this->position]);
$this->position += 4;
} else {
// These are also stored in the header.
$isMultiplayer = $this->readBody('l', 4);
$pov = $this->readBody('l', 4);
$revealMap = $this->readBody('l', 4);
$this->containsSequenceNumbers = $this->readBody('l', 4);
$this->numberOfChapters = $this->readBody('l', 4);
}
} | php | private function processGameStart()
{
$this->syncChecksumInterval = $this->readBody('l', 4);
if ($this->version->isMgl) {
// not sure what difference is vs mgx and up
$this->position += 28;
$ver = ord($this->body[$this->position]);
$this->position += 4;
} else {
// These are also stored in the header.
$isMultiplayer = $this->readBody('l', 4);
$pov = $this->readBody('l', 4);
$revealMap = $this->readBody('l', 4);
$this->containsSequenceNumbers = $this->readBody('l', 4);
$this->numberOfChapters = $this->readBody('l', 4);
}
} | [
"private",
"function",
"processGameStart",
"(",
")",
"{",
"$",
"this",
"->",
"syncChecksumInterval",
"=",
"$",
"this",
"->",
"readBody",
"(",
"'l'",
",",
"4",
")",
";",
"if",
"(",
"$",
"this",
"->",
"version",
"->",
"isMgl",
")",
"{",
"// not sure what difference is vs mgx and up",
"$",
"this",
"->",
"position",
"+=",
"28",
";",
"$",
"ver",
"=",
"ord",
"(",
"$",
"this",
"->",
"body",
"[",
"$",
"this",
"->",
"position",
"]",
")",
";",
"$",
"this",
"->",
"position",
"+=",
"4",
";",
"}",
"else",
"{",
"// These are also stored in the header.",
"$",
"isMultiplayer",
"=",
"$",
"this",
"->",
"readBody",
"(",
"'l'",
",",
"4",
")",
";",
"$",
"pov",
"=",
"$",
"this",
"->",
"readBody",
"(",
"'l'",
",",
"4",
")",
";",
"$",
"revealMap",
"=",
"$",
"this",
"->",
"readBody",
"(",
"'l'",
",",
"4",
")",
";",
"$",
"this",
"->",
"containsSequenceNumbers",
"=",
"$",
"this",
"->",
"readBody",
"(",
"'l'",
",",
"4",
")",
";",
"$",
"this",
"->",
"numberOfChapters",
"=",
"$",
"this",
"->",
"readBody",
"(",
"'l'",
",",
"4",
")",
";",
"}",
"}"
] | Process the game start data. | [
"Process",
"the",
"game",
"start",
"data",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Analyzers/BodyAnalyzer.php#L393-L409 |
35,767 | goto-bus-stop/recanalyst | src/Analyzers/BodyAnalyzer.php | BodyAnalyzer.processChatMessage | private function processChatMessage()
{
$length = $this->readBody('l', 4);
if ($length <= 0) {
return;
}
$chat = $this->readBodyRaw($length);
// Chat messages are stored as "@#%dPlayerName: Message", where %d is a
// digit from 1 to 8 indicating player's index (or colour).
if ($chat[0] == '@' && $chat[1] == '#' && $chat[2] >= '1' && $chat[2] <= '8') {
$chat = rtrim($chat); // Remove null terminator
if (substr($chat, 3, 2) == '--' && substr($chat, -2) == '--') {
// Skip messages like "--Warning: You are under attack... --"
return;
} else if (!empty($this->playersByNumber[$chat[2]])) {
$player = $this->playersByNumber[$chat[2]];
} else {
// Shouldn't happen, but we'll let the ChatMessage factory
// create a fake player for this message.
// TODO that auto-create behaviour is probably not desirable…
$player = null;
}
$this->chatMessages[] = ChatMessage::create(
$this->currentTime,
$player,
substr($chat, 3)
);
}
} | php | private function processChatMessage()
{
$length = $this->readBody('l', 4);
if ($length <= 0) {
return;
}
$chat = $this->readBodyRaw($length);
// Chat messages are stored as "@#%dPlayerName: Message", where %d is a
// digit from 1 to 8 indicating player's index (or colour).
if ($chat[0] == '@' && $chat[1] == '#' && $chat[2] >= '1' && $chat[2] <= '8') {
$chat = rtrim($chat); // Remove null terminator
if (substr($chat, 3, 2) == '--' && substr($chat, -2) == '--') {
// Skip messages like "--Warning: You are under attack... --"
return;
} else if (!empty($this->playersByNumber[$chat[2]])) {
$player = $this->playersByNumber[$chat[2]];
} else {
// Shouldn't happen, but we'll let the ChatMessage factory
// create a fake player for this message.
// TODO that auto-create behaviour is probably not desirable…
$player = null;
}
$this->chatMessages[] = ChatMessage::create(
$this->currentTime,
$player,
substr($chat, 3)
);
}
} | [
"private",
"function",
"processChatMessage",
"(",
")",
"{",
"$",
"length",
"=",
"$",
"this",
"->",
"readBody",
"(",
"'l'",
",",
"4",
")",
";",
"if",
"(",
"$",
"length",
"<=",
"0",
")",
"{",
"return",
";",
"}",
"$",
"chat",
"=",
"$",
"this",
"->",
"readBodyRaw",
"(",
"$",
"length",
")",
";",
"// Chat messages are stored as \"@#%dPlayerName: Message\", where %d is a",
"// digit from 1 to 8 indicating player's index (or colour).",
"if",
"(",
"$",
"chat",
"[",
"0",
"]",
"==",
"'@'",
"&&",
"$",
"chat",
"[",
"1",
"]",
"==",
"'#'",
"&&",
"$",
"chat",
"[",
"2",
"]",
">=",
"'1'",
"&&",
"$",
"chat",
"[",
"2",
"]",
"<=",
"'8'",
")",
"{",
"$",
"chat",
"=",
"rtrim",
"(",
"$",
"chat",
")",
";",
"// Remove null terminator",
"if",
"(",
"substr",
"(",
"$",
"chat",
",",
"3",
",",
"2",
")",
"==",
"'--'",
"&&",
"substr",
"(",
"$",
"chat",
",",
"-",
"2",
")",
"==",
"'--'",
")",
"{",
"// Skip messages like \"--Warning: You are under attack... --\"",
"return",
";",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"playersByNumber",
"[",
"$",
"chat",
"[",
"2",
"]",
"]",
")",
")",
"{",
"$",
"player",
"=",
"$",
"this",
"->",
"playersByNumber",
"[",
"$",
"chat",
"[",
"2",
"]",
"]",
";",
"}",
"else",
"{",
"// Shouldn't happen, but we'll let the ChatMessage factory",
"// create a fake player for this message.",
"// TODO that auto-create behaviour is probably not desirable…",
"$",
"player",
"=",
"null",
";",
"}",
"$",
"this",
"->",
"chatMessages",
"[",
"]",
"=",
"ChatMessage",
"::",
"create",
"(",
"$",
"this",
"->",
"currentTime",
",",
"$",
"player",
",",
"substr",
"(",
"$",
"chat",
",",
"3",
")",
")",
";",
"}",
"}"
] | Read a chat message. | [
"Read",
"a",
"chat",
"message",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Analyzers/BodyAnalyzer.php#L414-L443 |
35,768 | goto-bus-stop/recanalyst | src/Analyzers/HeaderAnalyzer.php | HeaderAnalyzer.readChat | protected function readChat(array $players)
{
$playersByNumber = [];
foreach ($players as $player) {
$playersByNumber[$player->number] = $player;
}
$messages = [];
$messageCount = $this->readHeader('l', 4);
for ($i = 0; $i < $messageCount; $i += 1) {
$length = $this->readHeader('l', 4);
if ($length <= 0) {
continue;
}
$chat = $this->readHeaderRaw($length);
// pre-game chat messages are stored as "@#%dPlayerName: Message",
// where %d is a digit from 1 to 8 indicating player's index (or
// colour)
if ($chat[0] == '@' && $chat[1] == '#' && $chat[2] >= '1' && $chat[2] <= '8') {
$chat = rtrim($chat); // throw null-termination character
if (!empty($playersByNumber[$chat[2]])) {
$player = $playersByNumber[$chat[2]];
} else {
// this player left before the game started
$player = null;
}
$messages[] = ChatMessage::create(null, $player, substr($chat, 3));
}
}
return $messages;
} | php | protected function readChat(array $players)
{
$playersByNumber = [];
foreach ($players as $player) {
$playersByNumber[$player->number] = $player;
}
$messages = [];
$messageCount = $this->readHeader('l', 4);
for ($i = 0; $i < $messageCount; $i += 1) {
$length = $this->readHeader('l', 4);
if ($length <= 0) {
continue;
}
$chat = $this->readHeaderRaw($length);
// pre-game chat messages are stored as "@#%dPlayerName: Message",
// where %d is a digit from 1 to 8 indicating player's index (or
// colour)
if ($chat[0] == '@' && $chat[1] == '#' && $chat[2] >= '1' && $chat[2] <= '8') {
$chat = rtrim($chat); // throw null-termination character
if (!empty($playersByNumber[$chat[2]])) {
$player = $playersByNumber[$chat[2]];
} else {
// this player left before the game started
$player = null;
}
$messages[] = ChatMessage::create(null, $player, substr($chat, 3));
}
}
return $messages;
} | [
"protected",
"function",
"readChat",
"(",
"array",
"$",
"players",
")",
"{",
"$",
"playersByNumber",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"players",
"as",
"$",
"player",
")",
"{",
"$",
"playersByNumber",
"[",
"$",
"player",
"->",
"number",
"]",
"=",
"$",
"player",
";",
"}",
"$",
"messages",
"=",
"[",
"]",
";",
"$",
"messageCount",
"=",
"$",
"this",
"->",
"readHeader",
"(",
"'l'",
",",
"4",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"messageCount",
";",
"$",
"i",
"+=",
"1",
")",
"{",
"$",
"length",
"=",
"$",
"this",
"->",
"readHeader",
"(",
"'l'",
",",
"4",
")",
";",
"if",
"(",
"$",
"length",
"<=",
"0",
")",
"{",
"continue",
";",
"}",
"$",
"chat",
"=",
"$",
"this",
"->",
"readHeaderRaw",
"(",
"$",
"length",
")",
";",
"// pre-game chat messages are stored as \"@#%dPlayerName: Message\",",
"// where %d is a digit from 1 to 8 indicating player's index (or",
"// colour)",
"if",
"(",
"$",
"chat",
"[",
"0",
"]",
"==",
"'@'",
"&&",
"$",
"chat",
"[",
"1",
"]",
"==",
"'#'",
"&&",
"$",
"chat",
"[",
"2",
"]",
">=",
"'1'",
"&&",
"$",
"chat",
"[",
"2",
"]",
"<=",
"'8'",
")",
"{",
"$",
"chat",
"=",
"rtrim",
"(",
"$",
"chat",
")",
";",
"// throw null-termination character",
"if",
"(",
"!",
"empty",
"(",
"$",
"playersByNumber",
"[",
"$",
"chat",
"[",
"2",
"]",
"]",
")",
")",
"{",
"$",
"player",
"=",
"$",
"playersByNumber",
"[",
"$",
"chat",
"[",
"2",
"]",
"]",
";",
"}",
"else",
"{",
"// this player left before the game started",
"$",
"player",
"=",
"null",
";",
"}",
"$",
"messages",
"[",
"]",
"=",
"ChatMessage",
"::",
"create",
"(",
"null",
",",
"$",
"player",
",",
"substr",
"(",
"$",
"chat",
",",
"3",
")",
")",
";",
"}",
"}",
"return",
"$",
"messages",
";",
"}"
] | Read a block containing chat messages.
Chat block structure:
int32 count;
ChatMessage messages[count];
Chat message structure:
int32 length;
char contents[length];
Not much data is encoded in the chat message structure, so we derive
a lot of it from the `contents` string instead.
@param array $players Array of `$playerId => $playerObject`, used to
associate player objects with chat messages.
@return array | [
"Read",
"a",
"block",
"containing",
"chat",
"messages",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Analyzers/HeaderAnalyzer.php#L269-L300 |
35,769 | goto-bus-stop/recanalyst | src/Analyzers/HeaderAnalyzer.php | HeaderAnalyzer.skipTriggerInfo | protected function skipTriggerInfo()
{
// Effects and triggers are of variable size, but conditions are
// constant.
$conditionSize = (
(11 * 4) + // 11 ints
(4 * 4) + // area (4 ints)
(3 * 4) // 3 ints
);
if ($this->version->isHDPatch4) {
$conditionSize += 2 * 4; // 2 ints
}
$numTriggers = $this->readHeader('l', 4);
for ($i = 0; $i < $numTriggers; $i += 1) {
$this->position += 4 + (2 * 1) + (3 * 4); // int, 2 bools, 3 ints
$descriptionLength = $this->readHeader('l', 4);
// HD edition 4.x saves a length of -1 when the string is absent,
// whereas older versions would use 0. That used to work fine
// without this guard, but now we should only skip if the length is
// positive.
if ($descriptionLength > 0) {
$this->position += $descriptionLength;
}
$nameLength = $this->readHeader('l', 4);
if ($nameLength > 0) {
$this->position += $nameLength;
}
$numEffects = $this->readHeader('l', 4);
for ($j = 0; $j < $numEffects; $j += 1) {
$this->position += 6 * 4; // 6 ints
$numSelectedObjects = $this->readHeader('l', 4);
if ($numSelectedObjects === -1) {
$numSelectedObjects = 0;
}
$this->position += 9 * 4; // 9 ints
$this->position += 2 * 4; // location (2 ints)
$this->position += 4 * 4; // area (2 locations)
$this->position += 3 * 4; // 3 ints
if ($this->version->isHDPatch4) {
$this->position += 4; // int for the new Attack Stance effect
}
$textLength = $this->readHeader('l', 4);
if ($textLength > 0) {
$this->position += $textLength;
}
$soundFileNameLength = $this->readHeader('l', 4);
if ($soundFileNameLength > 0) {
$this->position += $soundFileNameLength;
}
$this->position += $numSelectedObjects * 4; // unit IDs (one int each)
}
$this->position += $numEffects * 4; // effect order (list of ints)
$numConditions = $this->readHeader('l', 4);
$this->position += $numConditions * $conditionSize; // conditions
$this->position += $numConditions * 4; // conditions order (list of ints)
}
if ($numTriggers > 0) {
$this->position += $numTriggers * 4; // trigger order (list of ints)
// TODO perhaps also set game type to Scenario here?
}
} | php | protected function skipTriggerInfo()
{
// Effects and triggers are of variable size, but conditions are
// constant.
$conditionSize = (
(11 * 4) + // 11 ints
(4 * 4) + // area (4 ints)
(3 * 4) // 3 ints
);
if ($this->version->isHDPatch4) {
$conditionSize += 2 * 4; // 2 ints
}
$numTriggers = $this->readHeader('l', 4);
for ($i = 0; $i < $numTriggers; $i += 1) {
$this->position += 4 + (2 * 1) + (3 * 4); // int, 2 bools, 3 ints
$descriptionLength = $this->readHeader('l', 4);
// HD edition 4.x saves a length of -1 when the string is absent,
// whereas older versions would use 0. That used to work fine
// without this guard, but now we should only skip if the length is
// positive.
if ($descriptionLength > 0) {
$this->position += $descriptionLength;
}
$nameLength = $this->readHeader('l', 4);
if ($nameLength > 0) {
$this->position += $nameLength;
}
$numEffects = $this->readHeader('l', 4);
for ($j = 0; $j < $numEffects; $j += 1) {
$this->position += 6 * 4; // 6 ints
$numSelectedObjects = $this->readHeader('l', 4);
if ($numSelectedObjects === -1) {
$numSelectedObjects = 0;
}
$this->position += 9 * 4; // 9 ints
$this->position += 2 * 4; // location (2 ints)
$this->position += 4 * 4; // area (2 locations)
$this->position += 3 * 4; // 3 ints
if ($this->version->isHDPatch4) {
$this->position += 4; // int for the new Attack Stance effect
}
$textLength = $this->readHeader('l', 4);
if ($textLength > 0) {
$this->position += $textLength;
}
$soundFileNameLength = $this->readHeader('l', 4);
if ($soundFileNameLength > 0) {
$this->position += $soundFileNameLength;
}
$this->position += $numSelectedObjects * 4; // unit IDs (one int each)
}
$this->position += $numEffects * 4; // effect order (list of ints)
$numConditions = $this->readHeader('l', 4);
$this->position += $numConditions * $conditionSize; // conditions
$this->position += $numConditions * 4; // conditions order (list of ints)
}
if ($numTriggers > 0) {
$this->position += $numTriggers * 4; // trigger order (list of ints)
// TODO perhaps also set game type to Scenario here?
}
} | [
"protected",
"function",
"skipTriggerInfo",
"(",
")",
"{",
"// Effects and triggers are of variable size, but conditions are",
"// constant.",
"$",
"conditionSize",
"=",
"(",
"(",
"11",
"*",
"4",
")",
"+",
"// 11 ints",
"(",
"4",
"*",
"4",
")",
"+",
"// area (4 ints)",
"(",
"3",
"*",
"4",
")",
"// 3 ints",
")",
";",
"if",
"(",
"$",
"this",
"->",
"version",
"->",
"isHDPatch4",
")",
"{",
"$",
"conditionSize",
"+=",
"2",
"*",
"4",
";",
"// 2 ints",
"}",
"$",
"numTriggers",
"=",
"$",
"this",
"->",
"readHeader",
"(",
"'l'",
",",
"4",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"numTriggers",
";",
"$",
"i",
"+=",
"1",
")",
"{",
"$",
"this",
"->",
"position",
"+=",
"4",
"+",
"(",
"2",
"*",
"1",
")",
"+",
"(",
"3",
"*",
"4",
")",
";",
"// int, 2 bools, 3 ints",
"$",
"descriptionLength",
"=",
"$",
"this",
"->",
"readHeader",
"(",
"'l'",
",",
"4",
")",
";",
"// HD edition 4.x saves a length of -1 when the string is absent,",
"// whereas older versions would use 0. That used to work fine",
"// without this guard, but now we should only skip if the length is",
"// positive.",
"if",
"(",
"$",
"descriptionLength",
">",
"0",
")",
"{",
"$",
"this",
"->",
"position",
"+=",
"$",
"descriptionLength",
";",
"}",
"$",
"nameLength",
"=",
"$",
"this",
"->",
"readHeader",
"(",
"'l'",
",",
"4",
")",
";",
"if",
"(",
"$",
"nameLength",
">",
"0",
")",
"{",
"$",
"this",
"->",
"position",
"+=",
"$",
"nameLength",
";",
"}",
"$",
"numEffects",
"=",
"$",
"this",
"->",
"readHeader",
"(",
"'l'",
",",
"4",
")",
";",
"for",
"(",
"$",
"j",
"=",
"0",
";",
"$",
"j",
"<",
"$",
"numEffects",
";",
"$",
"j",
"+=",
"1",
")",
"{",
"$",
"this",
"->",
"position",
"+=",
"6",
"*",
"4",
";",
"// 6 ints",
"$",
"numSelectedObjects",
"=",
"$",
"this",
"->",
"readHeader",
"(",
"'l'",
",",
"4",
")",
";",
"if",
"(",
"$",
"numSelectedObjects",
"===",
"-",
"1",
")",
"{",
"$",
"numSelectedObjects",
"=",
"0",
";",
"}",
"$",
"this",
"->",
"position",
"+=",
"9",
"*",
"4",
";",
"// 9 ints",
"$",
"this",
"->",
"position",
"+=",
"2",
"*",
"4",
";",
"// location (2 ints)",
"$",
"this",
"->",
"position",
"+=",
"4",
"*",
"4",
";",
"// area (2 locations)",
"$",
"this",
"->",
"position",
"+=",
"3",
"*",
"4",
";",
"// 3 ints",
"if",
"(",
"$",
"this",
"->",
"version",
"->",
"isHDPatch4",
")",
"{",
"$",
"this",
"->",
"position",
"+=",
"4",
";",
"// int for the new Attack Stance effect",
"}",
"$",
"textLength",
"=",
"$",
"this",
"->",
"readHeader",
"(",
"'l'",
",",
"4",
")",
";",
"if",
"(",
"$",
"textLength",
">",
"0",
")",
"{",
"$",
"this",
"->",
"position",
"+=",
"$",
"textLength",
";",
"}",
"$",
"soundFileNameLength",
"=",
"$",
"this",
"->",
"readHeader",
"(",
"'l'",
",",
"4",
")",
";",
"if",
"(",
"$",
"soundFileNameLength",
">",
"0",
")",
"{",
"$",
"this",
"->",
"position",
"+=",
"$",
"soundFileNameLength",
";",
"}",
"$",
"this",
"->",
"position",
"+=",
"$",
"numSelectedObjects",
"*",
"4",
";",
"// unit IDs (one int each)",
"}",
"$",
"this",
"->",
"position",
"+=",
"$",
"numEffects",
"*",
"4",
";",
"// effect order (list of ints)",
"$",
"numConditions",
"=",
"$",
"this",
"->",
"readHeader",
"(",
"'l'",
",",
"4",
")",
";",
"$",
"this",
"->",
"position",
"+=",
"$",
"numConditions",
"*",
"$",
"conditionSize",
";",
"// conditions",
"$",
"this",
"->",
"position",
"+=",
"$",
"numConditions",
"*",
"4",
";",
"// conditions order (list of ints)",
"}",
"if",
"(",
"$",
"numTriggers",
">",
"0",
")",
"{",
"$",
"this",
"->",
"position",
"+=",
"$",
"numTriggers",
"*",
"4",
";",
"// trigger order (list of ints)",
"// TODO perhaps also set game type to Scenario here?",
"}",
"}"
] | Skip a scenario triggers info block. See ScenarioTriggersAnalyzer for
contents of a trigger block. | [
"Skip",
"a",
"scenario",
"triggers",
"info",
"block",
".",
"See",
"ScenarioTriggersAnalyzer",
"for",
"contents",
"of",
"a",
"trigger",
"block",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Analyzers/HeaderAnalyzer.php#L374-L437 |
35,770 | goto-bus-stop/recanalyst | src/Analyzers/HeaderAnalyzer.php | HeaderAnalyzer.readScenarioHeader | protected function readScenarioHeader()
{
$nextUnitId = $this->readHeader('l', 4);
$this->position += 4;
// Player names
for ($i = 0; $i < 16; $i++) {
$this->position += 256; // rtrim(readHeaderRaw(), \0)
}
// Player names (string table)
for ($i = 0; $i < 16; $i++) {
$this->position += 4; // int
}
for ($i = 0; $i < 16; $i++) {
$this->position += 4; // bool isActive
$this->position += 4; // bool isHuman
$this->position += 4; // int civilization
$this->position += 4; // const 0x00000004
}
$this->position += 5;
$elapsedTime = $this->readHeader('f', 4);
$nameLen = $this->readHeader('v', 2);
$filename = $this->readHeaderRaw($nameLen);
// These should be string IDs for messages?
if ($this->version->isMgl) {
$this->position += 20;
} else {
$this->position += 24;
}
$this->analysis->scenarioFilename = $filename;
} | php | protected function readScenarioHeader()
{
$nextUnitId = $this->readHeader('l', 4);
$this->position += 4;
// Player names
for ($i = 0; $i < 16; $i++) {
$this->position += 256; // rtrim(readHeaderRaw(), \0)
}
// Player names (string table)
for ($i = 0; $i < 16; $i++) {
$this->position += 4; // int
}
for ($i = 0; $i < 16; $i++) {
$this->position += 4; // bool isActive
$this->position += 4; // bool isHuman
$this->position += 4; // int civilization
$this->position += 4; // const 0x00000004
}
$this->position += 5;
$elapsedTime = $this->readHeader('f', 4);
$nameLen = $this->readHeader('v', 2);
$filename = $this->readHeaderRaw($nameLen);
// These should be string IDs for messages?
if ($this->version->isMgl) {
$this->position += 20;
} else {
$this->position += 24;
}
$this->analysis->scenarioFilename = $filename;
} | [
"protected",
"function",
"readScenarioHeader",
"(",
")",
"{",
"$",
"nextUnitId",
"=",
"$",
"this",
"->",
"readHeader",
"(",
"'l'",
",",
"4",
")",
";",
"$",
"this",
"->",
"position",
"+=",
"4",
";",
"// Player names",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"16",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"position",
"+=",
"256",
";",
"// rtrim(readHeaderRaw(), \\0)",
"}",
"// Player names (string table)",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"16",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"position",
"+=",
"4",
";",
"// int",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"16",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"position",
"+=",
"4",
";",
"// bool isActive",
"$",
"this",
"->",
"position",
"+=",
"4",
";",
"// bool isHuman",
"$",
"this",
"->",
"position",
"+=",
"4",
";",
"// int civilization",
"$",
"this",
"->",
"position",
"+=",
"4",
";",
"// const 0x00000004",
"}",
"$",
"this",
"->",
"position",
"+=",
"5",
";",
"$",
"elapsedTime",
"=",
"$",
"this",
"->",
"readHeader",
"(",
"'f'",
",",
"4",
")",
";",
"$",
"nameLen",
"=",
"$",
"this",
"->",
"readHeader",
"(",
"'v'",
",",
"2",
")",
";",
"$",
"filename",
"=",
"$",
"this",
"->",
"readHeaderRaw",
"(",
"$",
"nameLen",
")",
";",
"// These should be string IDs for messages?",
"if",
"(",
"$",
"this",
"->",
"version",
"->",
"isMgl",
")",
"{",
"$",
"this",
"->",
"position",
"+=",
"20",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"position",
"+=",
"24",
";",
"}",
"$",
"this",
"->",
"analysis",
"->",
"scenarioFilename",
"=",
"$",
"filename",
";",
"}"
] | Read the scenario info header. Contains information about configured
players and the scenario file.
@return void | [
"Read",
"the",
"scenario",
"info",
"header",
".",
"Contains",
"information",
"about",
"configured",
"players",
"and",
"the",
"scenario",
"file",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Analyzers/HeaderAnalyzer.php#L445-L477 |
35,771 | goto-bus-stop/recanalyst | src/Analyzers/HeaderAnalyzer.php | HeaderAnalyzer.readMessages | protected function readMessages()
{
$len = $this->readHeader('v', 2);
$instructions = rtrim($this->readHeaderRaw($len), "\0");
$len = $this->readHeader('v', 2);
$hints = rtrim($this->readHeaderRaw($len), "\0");
$len = $this->readHeader('v', 2);
$victory = rtrim($this->readHeaderRaw($len), "\0");
$len = $this->readHeader('v', 2);
$loss = rtrim($this->readHeaderRaw($len), "\0");
$len = $this->readHeader('v', 2);
$history = rtrim($this->readHeaderRaw($len), "\0");
$len = $this->readHeader('v', 2);
$scouts = rtrim($this->readHeaderRaw($len), "\0");
return (object) [
'instructions' => $instructions,
'hints' => $hints,
'victory' => $victory,
'loss' => $loss,
'history' => $history,
'scouts' => $scouts,
];
} | php | protected function readMessages()
{
$len = $this->readHeader('v', 2);
$instructions = rtrim($this->readHeaderRaw($len), "\0");
$len = $this->readHeader('v', 2);
$hints = rtrim($this->readHeaderRaw($len), "\0");
$len = $this->readHeader('v', 2);
$victory = rtrim($this->readHeaderRaw($len), "\0");
$len = $this->readHeader('v', 2);
$loss = rtrim($this->readHeaderRaw($len), "\0");
$len = $this->readHeader('v', 2);
$history = rtrim($this->readHeaderRaw($len), "\0");
$len = $this->readHeader('v', 2);
$scouts = rtrim($this->readHeaderRaw($len), "\0");
return (object) [
'instructions' => $instructions,
'hints' => $hints,
'victory' => $victory,
'loss' => $loss,
'history' => $history,
'scouts' => $scouts,
];
} | [
"protected",
"function",
"readMessages",
"(",
")",
"{",
"$",
"len",
"=",
"$",
"this",
"->",
"readHeader",
"(",
"'v'",
",",
"2",
")",
";",
"$",
"instructions",
"=",
"rtrim",
"(",
"$",
"this",
"->",
"readHeaderRaw",
"(",
"$",
"len",
")",
",",
"\"\\0\"",
")",
";",
"$",
"len",
"=",
"$",
"this",
"->",
"readHeader",
"(",
"'v'",
",",
"2",
")",
";",
"$",
"hints",
"=",
"rtrim",
"(",
"$",
"this",
"->",
"readHeaderRaw",
"(",
"$",
"len",
")",
",",
"\"\\0\"",
")",
";",
"$",
"len",
"=",
"$",
"this",
"->",
"readHeader",
"(",
"'v'",
",",
"2",
")",
";",
"$",
"victory",
"=",
"rtrim",
"(",
"$",
"this",
"->",
"readHeaderRaw",
"(",
"$",
"len",
")",
",",
"\"\\0\"",
")",
";",
"$",
"len",
"=",
"$",
"this",
"->",
"readHeader",
"(",
"'v'",
",",
"2",
")",
";",
"$",
"loss",
"=",
"rtrim",
"(",
"$",
"this",
"->",
"readHeaderRaw",
"(",
"$",
"len",
")",
",",
"\"\\0\"",
")",
";",
"$",
"len",
"=",
"$",
"this",
"->",
"readHeader",
"(",
"'v'",
",",
"2",
")",
";",
"$",
"history",
"=",
"rtrim",
"(",
"$",
"this",
"->",
"readHeaderRaw",
"(",
"$",
"len",
")",
",",
"\"\\0\"",
")",
";",
"$",
"len",
"=",
"$",
"this",
"->",
"readHeader",
"(",
"'v'",
",",
"2",
")",
";",
"$",
"scouts",
"=",
"rtrim",
"(",
"$",
"this",
"->",
"readHeaderRaw",
"(",
"$",
"len",
")",
",",
"\"\\0\"",
")",
";",
"return",
"(",
"object",
")",
"[",
"'instructions'",
"=>",
"$",
"instructions",
",",
"'hints'",
"=>",
"$",
"hints",
",",
"'victory'",
"=>",
"$",
"victory",
",",
"'loss'",
"=>",
"$",
"loss",
",",
"'history'",
"=>",
"$",
"history",
",",
"'scouts'",
"=>",
"$",
"scouts",
",",
"]",
";",
"}"
] | Read messages.
@return \StdClass | [
"Read",
"messages",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Analyzers/HeaderAnalyzer.php#L484-L506 |
35,772 | goto-bus-stop/recanalyst | src/Analyzers/HeaderAnalyzer.php | HeaderAnalyzer.buildTeams | protected function buildTeams($players)
{
$teams = [];
$teamsByIndex = [];
foreach ($players as $player) {
/**
* Team = 0 can mean two things: either this player has no team,
* i.e. is in a team on their own, or this player is cooping with
* another player who _is_ part of a team.
*/
if ($player->team == 0) {
$found = false;
foreach ($teams as $team) {
if ($team->index() != $player->team) {
continue;
}
foreach ($team->players() as $coopPlayer) {
if ($coopPlayer->index == $player->index) {
$team->addPlayer($player);
$found = true;
break;
}
}
}
// Not a cooping player, so add them to their own team.
if (!$found) {
$team = new Team();
$team->addPlayer($player);
$teams[] = $team;
$teamsByIndex[$player->team] = $team;
}
} else {
if (array_key_exists($player->team, $teamsByIndex)) {
$teamsByIndex[$player->team]->addPlayer($player);
} else {
$team = new Team();
$team ->addPlayer($player);
$teams[] = $team;
$teamsByIndex[$player->team] = $team;
}
}
}
return $teams;
} | php | protected function buildTeams($players)
{
$teams = [];
$teamsByIndex = [];
foreach ($players as $player) {
/**
* Team = 0 can mean two things: either this player has no team,
* i.e. is in a team on their own, or this player is cooping with
* another player who _is_ part of a team.
*/
if ($player->team == 0) {
$found = false;
foreach ($teams as $team) {
if ($team->index() != $player->team) {
continue;
}
foreach ($team->players() as $coopPlayer) {
if ($coopPlayer->index == $player->index) {
$team->addPlayer($player);
$found = true;
break;
}
}
}
// Not a cooping player, so add them to their own team.
if (!$found) {
$team = new Team();
$team->addPlayer($player);
$teams[] = $team;
$teamsByIndex[$player->team] = $team;
}
} else {
if (array_key_exists($player->team, $teamsByIndex)) {
$teamsByIndex[$player->team]->addPlayer($player);
} else {
$team = new Team();
$team ->addPlayer($player);
$teams[] = $team;
$teamsByIndex[$player->team] = $team;
}
}
}
return $teams;
} | [
"protected",
"function",
"buildTeams",
"(",
"$",
"players",
")",
"{",
"$",
"teams",
"=",
"[",
"]",
";",
"$",
"teamsByIndex",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"players",
"as",
"$",
"player",
")",
"{",
"/**\n * Team = 0 can mean two things: either this player has no team,\n * i.e. is in a team on their own, or this player is cooping with\n * another player who _is_ part of a team.\n */",
"if",
"(",
"$",
"player",
"->",
"team",
"==",
"0",
")",
"{",
"$",
"found",
"=",
"false",
";",
"foreach",
"(",
"$",
"teams",
"as",
"$",
"team",
")",
"{",
"if",
"(",
"$",
"team",
"->",
"index",
"(",
")",
"!=",
"$",
"player",
"->",
"team",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"team",
"->",
"players",
"(",
")",
"as",
"$",
"coopPlayer",
")",
"{",
"if",
"(",
"$",
"coopPlayer",
"->",
"index",
"==",
"$",
"player",
"->",
"index",
")",
"{",
"$",
"team",
"->",
"addPlayer",
"(",
"$",
"player",
")",
";",
"$",
"found",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"// Not a cooping player, so add them to their own team.",
"if",
"(",
"!",
"$",
"found",
")",
"{",
"$",
"team",
"=",
"new",
"Team",
"(",
")",
";",
"$",
"team",
"->",
"addPlayer",
"(",
"$",
"player",
")",
";",
"$",
"teams",
"[",
"]",
"=",
"$",
"team",
";",
"$",
"teamsByIndex",
"[",
"$",
"player",
"->",
"team",
"]",
"=",
"$",
"team",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"player",
"->",
"team",
",",
"$",
"teamsByIndex",
")",
")",
"{",
"$",
"teamsByIndex",
"[",
"$",
"player",
"->",
"team",
"]",
"->",
"addPlayer",
"(",
"$",
"player",
")",
";",
"}",
"else",
"{",
"$",
"team",
"=",
"new",
"Team",
"(",
")",
";",
"$",
"team",
"->",
"addPlayer",
"(",
"$",
"player",
")",
";",
"$",
"teams",
"[",
"]",
"=",
"$",
"team",
";",
"$",
"teamsByIndex",
"[",
"$",
"player",
"->",
"team",
"]",
"=",
"$",
"team",
";",
"}",
"}",
"}",
"return",
"$",
"teams",
";",
"}"
] | Group players into teams.
@param \RecAnalyst\Model\Player[] $players Array of players.
@return \RecAnalyst\Model\Team[] | [
"Group",
"players",
"into",
"teams",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Analyzers/HeaderAnalyzer.php#L515-L559 |
35,773 | goto-bus-stop/recanalyst | src/Analyzers/VersionAnalyzer.php | VersionAnalyzer.run | protected function run()
{
$versionString = rtrim($this->readHeaderRaw(8));
$subVersion = round($this->readHeader('f', 4), 2);
$version = $this->getVersion($versionString, $subVersion);
$analysis = new Version($this->rec, $versionString, $subVersion);
$analysis->version = $version;
$analysis->isTrial = in_array($version, $this->trialVersions);
$analysis->isAoK = in_array($version, $this->aokVersions);
$analysis->isUserPatch = in_array($version, $this->userpatchVersions);
$analysis->isUserPatch15 = $version === Version::VERSION_USERPATCH15;
$analysis->isHDEdition = in_array($version, $this->hdVersions);
$analysis->isHDPatch4 = $analysis->isHDEdition && $subVersion >= 12.00;
$analysis->isAoC = $analysis->isUserPatch || $analysis->isHDEdition ||
in_array($version, $this->aocVersions);
$analysis->isMgl = $analysis->isAoK;
$analysis->isMgx = $analysis->isAoC;
$analysis->isMgz = $analysis->isUserPatch;
// FIXME Not sure if this is the correct cutoff point.
//
// test/recs/versions/mgx2_simple.mgx2
// has subVersion == 12.31
// test/recs/versions/MP Replay v4.3 @2015.09.11 221142 (2).msx
// has subVersion == 12.34
// So it's somewhere between those two.
$analysis->isMsx = $subVersion >= 12.32;
$analysis->isAoe2Record = $subVersion >= 12.36;
return $analysis;
} | php | protected function run()
{
$versionString = rtrim($this->readHeaderRaw(8));
$subVersion = round($this->readHeader('f', 4), 2);
$version = $this->getVersion($versionString, $subVersion);
$analysis = new Version($this->rec, $versionString, $subVersion);
$analysis->version = $version;
$analysis->isTrial = in_array($version, $this->trialVersions);
$analysis->isAoK = in_array($version, $this->aokVersions);
$analysis->isUserPatch = in_array($version, $this->userpatchVersions);
$analysis->isUserPatch15 = $version === Version::VERSION_USERPATCH15;
$analysis->isHDEdition = in_array($version, $this->hdVersions);
$analysis->isHDPatch4 = $analysis->isHDEdition && $subVersion >= 12.00;
$analysis->isAoC = $analysis->isUserPatch || $analysis->isHDEdition ||
in_array($version, $this->aocVersions);
$analysis->isMgl = $analysis->isAoK;
$analysis->isMgx = $analysis->isAoC;
$analysis->isMgz = $analysis->isUserPatch;
// FIXME Not sure if this is the correct cutoff point.
//
// test/recs/versions/mgx2_simple.mgx2
// has subVersion == 12.31
// test/recs/versions/MP Replay v4.3 @2015.09.11 221142 (2).msx
// has subVersion == 12.34
// So it's somewhere between those two.
$analysis->isMsx = $subVersion >= 12.32;
$analysis->isAoe2Record = $subVersion >= 12.36;
return $analysis;
} | [
"protected",
"function",
"run",
"(",
")",
"{",
"$",
"versionString",
"=",
"rtrim",
"(",
"$",
"this",
"->",
"readHeaderRaw",
"(",
"8",
")",
")",
";",
"$",
"subVersion",
"=",
"round",
"(",
"$",
"this",
"->",
"readHeader",
"(",
"'f'",
",",
"4",
")",
",",
"2",
")",
";",
"$",
"version",
"=",
"$",
"this",
"->",
"getVersion",
"(",
"$",
"versionString",
",",
"$",
"subVersion",
")",
";",
"$",
"analysis",
"=",
"new",
"Version",
"(",
"$",
"this",
"->",
"rec",
",",
"$",
"versionString",
",",
"$",
"subVersion",
")",
";",
"$",
"analysis",
"->",
"version",
"=",
"$",
"version",
";",
"$",
"analysis",
"->",
"isTrial",
"=",
"in_array",
"(",
"$",
"version",
",",
"$",
"this",
"->",
"trialVersions",
")",
";",
"$",
"analysis",
"->",
"isAoK",
"=",
"in_array",
"(",
"$",
"version",
",",
"$",
"this",
"->",
"aokVersions",
")",
";",
"$",
"analysis",
"->",
"isUserPatch",
"=",
"in_array",
"(",
"$",
"version",
",",
"$",
"this",
"->",
"userpatchVersions",
")",
";",
"$",
"analysis",
"->",
"isUserPatch15",
"=",
"$",
"version",
"===",
"Version",
"::",
"VERSION_USERPATCH15",
";",
"$",
"analysis",
"->",
"isHDEdition",
"=",
"in_array",
"(",
"$",
"version",
",",
"$",
"this",
"->",
"hdVersions",
")",
";",
"$",
"analysis",
"->",
"isHDPatch4",
"=",
"$",
"analysis",
"->",
"isHDEdition",
"&&",
"$",
"subVersion",
">=",
"12.00",
";",
"$",
"analysis",
"->",
"isAoC",
"=",
"$",
"analysis",
"->",
"isUserPatch",
"||",
"$",
"analysis",
"->",
"isHDEdition",
"||",
"in_array",
"(",
"$",
"version",
",",
"$",
"this",
"->",
"aocVersions",
")",
";",
"$",
"analysis",
"->",
"isMgl",
"=",
"$",
"analysis",
"->",
"isAoK",
";",
"$",
"analysis",
"->",
"isMgx",
"=",
"$",
"analysis",
"->",
"isAoC",
";",
"$",
"analysis",
"->",
"isMgz",
"=",
"$",
"analysis",
"->",
"isUserPatch",
";",
"// FIXME Not sure if this is the correct cutoff point.",
"//",
"// test/recs/versions/mgx2_simple.mgx2",
"// has subVersion == 12.31",
"// test/recs/versions/MP Replay v4.3 @2015.09.11 221142 (2).msx",
"// has subVersion == 12.34",
"// So it's somewhere between those two.",
"$",
"analysis",
"->",
"isMsx",
"=",
"$",
"subVersion",
">=",
"12.32",
";",
"$",
"analysis",
"->",
"isAoe2Record",
"=",
"$",
"subVersion",
">=",
"12.36",
";",
"return",
"$",
"analysis",
";",
"}"
] | Read recorded game version metadata.
Recorded game version information is encoded as:
char version[8]; // something like "VER 9.C\0"
float subVersion;
@return object | [
"Read",
"recorded",
"game",
"version",
"metadata",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Analyzers/VersionAnalyzer.php#L86-L119 |
35,774 | goto-bus-stop/recanalyst | src/Analyzers/VersionAnalyzer.php | VersionAnalyzer.getVersion | private function getVersion($version, $subVersion)
{
switch ($version) {
case 'TRL 9.3':
return $this->isMgx ? Version::VERSION_AOCTRIAL : Version::VERSION_AOKTRIAL;
case 'VER 9.3':
return Version::VERSION_AOK;
case 'VER 9.4':
if ($subVersion >= 12.50) {
return Version::VERSION_HD50;
}
if ($subVersion >= 12.49) {
return Version::VERSION_HD48;
}
if ($subVersion >= 12.36) {
// Patch versions 4.6 and 4.7.
return Version::VERSION_HD46;
}
if ($subVersion >= 12.34) {
// Probably versions 4.3 through 4.5?
return Version::VERSION_HD43;
}
if ($subVersion > 11.76) {
return Version::VERSION_HD;
}
return Version::VERSION_AOC;
case 'VER 9.5':
return Version::VERSION_AOFE21;
case 'VER 9.8':
return Version::VERSION_USERPATCH12;
case 'VER 9.9':
return Version::VERSION_USERPATCH13;
// UserPatch 1.4 RC 1
case 'VER 9.A':
// UserPatch 1.4 RC 2
case 'VER 9.B':
case 'VER 9.C':
case 'VER 9.D':
return Version::VERSION_USERPATCH14;
case 'VER 9.E':
case 'VER 9.F':
return Version::VERSION_USERPATCH15;
default:
return $version;
}
} | php | private function getVersion($version, $subVersion)
{
switch ($version) {
case 'TRL 9.3':
return $this->isMgx ? Version::VERSION_AOCTRIAL : Version::VERSION_AOKTRIAL;
case 'VER 9.3':
return Version::VERSION_AOK;
case 'VER 9.4':
if ($subVersion >= 12.50) {
return Version::VERSION_HD50;
}
if ($subVersion >= 12.49) {
return Version::VERSION_HD48;
}
if ($subVersion >= 12.36) {
// Patch versions 4.6 and 4.7.
return Version::VERSION_HD46;
}
if ($subVersion >= 12.34) {
// Probably versions 4.3 through 4.5?
return Version::VERSION_HD43;
}
if ($subVersion > 11.76) {
return Version::VERSION_HD;
}
return Version::VERSION_AOC;
case 'VER 9.5':
return Version::VERSION_AOFE21;
case 'VER 9.8':
return Version::VERSION_USERPATCH12;
case 'VER 9.9':
return Version::VERSION_USERPATCH13;
// UserPatch 1.4 RC 1
case 'VER 9.A':
// UserPatch 1.4 RC 2
case 'VER 9.B':
case 'VER 9.C':
case 'VER 9.D':
return Version::VERSION_USERPATCH14;
case 'VER 9.E':
case 'VER 9.F':
return Version::VERSION_USERPATCH15;
default:
return $version;
}
} | [
"private",
"function",
"getVersion",
"(",
"$",
"version",
",",
"$",
"subVersion",
")",
"{",
"switch",
"(",
"$",
"version",
")",
"{",
"case",
"'TRL 9.3'",
":",
"return",
"$",
"this",
"->",
"isMgx",
"?",
"Version",
"::",
"VERSION_AOCTRIAL",
":",
"Version",
"::",
"VERSION_AOKTRIAL",
";",
"case",
"'VER 9.3'",
":",
"return",
"Version",
"::",
"VERSION_AOK",
";",
"case",
"'VER 9.4'",
":",
"if",
"(",
"$",
"subVersion",
">=",
"12.50",
")",
"{",
"return",
"Version",
"::",
"VERSION_HD50",
";",
"}",
"if",
"(",
"$",
"subVersion",
">=",
"12.49",
")",
"{",
"return",
"Version",
"::",
"VERSION_HD48",
";",
"}",
"if",
"(",
"$",
"subVersion",
">=",
"12.36",
")",
"{",
"// Patch versions 4.6 and 4.7.",
"return",
"Version",
"::",
"VERSION_HD46",
";",
"}",
"if",
"(",
"$",
"subVersion",
">=",
"12.34",
")",
"{",
"// Probably versions 4.3 through 4.5?",
"return",
"Version",
"::",
"VERSION_HD43",
";",
"}",
"if",
"(",
"$",
"subVersion",
">",
"11.76",
")",
"{",
"return",
"Version",
"::",
"VERSION_HD",
";",
"}",
"return",
"Version",
"::",
"VERSION_AOC",
";",
"case",
"'VER 9.5'",
":",
"return",
"Version",
"::",
"VERSION_AOFE21",
";",
"case",
"'VER 9.8'",
":",
"return",
"Version",
"::",
"VERSION_USERPATCH12",
";",
"case",
"'VER 9.9'",
":",
"return",
"Version",
"::",
"VERSION_USERPATCH13",
";",
"// UserPatch 1.4 RC 1",
"case",
"'VER 9.A'",
":",
"// UserPatch 1.4 RC 2",
"case",
"'VER 9.B'",
":",
"case",
"'VER 9.C'",
":",
"case",
"'VER 9.D'",
":",
"return",
"Version",
"::",
"VERSION_USERPATCH14",
";",
"case",
"'VER 9.E'",
":",
"case",
"'VER 9.F'",
":",
"return",
"Version",
"::",
"VERSION_USERPATCH15",
";",
"default",
":",
"return",
"$",
"version",
";",
"}",
"}"
] | Get the version ID from a version string and sub-version number.
@param string $version Version string, found at the start of the file
header.
@param float $subVersion Sub-version number.
@return int Game version ID. | [
"Get",
"the",
"version",
"ID",
"from",
"a",
"version",
"string",
"and",
"sub",
"-",
"version",
"number",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Analyzers/VersionAnalyzer.php#L129-L174 |
35,775 | goto-bus-stop/recanalyst | src/ResourcePacks/AgeOfEmpires/Map.php | Map.isRealWorldMap | public static function isRealWorldMap($id)
{
return in_array($id, [
self::IBERIA, self::BRITAIN, self::MIDEAST, self::TEXAS,
self::ITALY, self::CENTRALAMERICA, self::FRANCE, self::NORSELANDS,
self::SEAOFJAPAN, self::BYZANTINUM,
]);
} | php | public static function isRealWorldMap($id)
{
return in_array($id, [
self::IBERIA, self::BRITAIN, self::MIDEAST, self::TEXAS,
self::ITALY, self::CENTRALAMERICA, self::FRANCE, self::NORSELANDS,
self::SEAOFJAPAN, self::BYZANTINUM,
]);
} | [
"public",
"static",
"function",
"isRealWorldMap",
"(",
"$",
"id",
")",
"{",
"return",
"in_array",
"(",
"$",
"id",
",",
"[",
"self",
"::",
"IBERIA",
",",
"self",
"::",
"BRITAIN",
",",
"self",
"::",
"MIDEAST",
",",
"self",
"::",
"TEXAS",
",",
"self",
"::",
"ITALY",
",",
"self",
"::",
"CENTRALAMERICA",
",",
"self",
"::",
"FRANCE",
",",
"self",
"::",
"NORSELANDS",
",",
"self",
"::",
"SEAOFJAPAN",
",",
"self",
"::",
"BYZANTINUM",
",",
"]",
")",
";",
"}"
] | Check whether a builtin map is a "Real World" map, such as Byzantinum or
Texas.
@param int $id Map ID of a builtin map.
@return bool True if the map is a "Real World" map, false otherwise. | [
"Check",
"whether",
"a",
"builtin",
"map",
"is",
"a",
"Real",
"World",
"map",
"such",
"as",
"Byzantinum",
"or",
"Texas",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/ResourcePacks/AgeOfEmpires/Map.php#L73-L80 |
35,776 | goto-bus-stop/recanalyst | src/ResourcePacks/AgeOfEmpires/Map.php | Map.isStandardMap | public static function isStandardMap($id)
{
return in_array($id, [
self::ARABIA, self::ARCHIPELAGO, self::BALTIC, self::BLACKFOREST,
self::COASTAL, self::CONTINENTAL, self::CRATERLAKE,
self::FORTRESS, self::GOLDRUSH, self::HIGHLAND, self::ISLANDS,
self::MEDITERRANEAN, self::MIGRATION, self::RIVERS,
self::TEAMISLANDS, self::SCANDINAVIA, self::MONGOLIA,
self::YUCATAN, self::SALTMARSH, self::ARENA, self::KINGOFTHEHILL,
self::OASIS, self::GHOSTLAKE, self::NOMAD,
self::RANDOM,
]);
} | php | public static function isStandardMap($id)
{
return in_array($id, [
self::ARABIA, self::ARCHIPELAGO, self::BALTIC, self::BLACKFOREST,
self::COASTAL, self::CONTINENTAL, self::CRATERLAKE,
self::FORTRESS, self::GOLDRUSH, self::HIGHLAND, self::ISLANDS,
self::MEDITERRANEAN, self::MIGRATION, self::RIVERS,
self::TEAMISLANDS, self::SCANDINAVIA, self::MONGOLIA,
self::YUCATAN, self::SALTMARSH, self::ARENA, self::KINGOFTHEHILL,
self::OASIS, self::GHOSTLAKE, self::NOMAD,
self::RANDOM,
]);
} | [
"public",
"static",
"function",
"isStandardMap",
"(",
"$",
"id",
")",
"{",
"return",
"in_array",
"(",
"$",
"id",
",",
"[",
"self",
"::",
"ARABIA",
",",
"self",
"::",
"ARCHIPELAGO",
",",
"self",
"::",
"BALTIC",
",",
"self",
"::",
"BLACKFOREST",
",",
"self",
"::",
"COASTAL",
",",
"self",
"::",
"CONTINENTAL",
",",
"self",
"::",
"CRATERLAKE",
",",
"self",
"::",
"FORTRESS",
",",
"self",
"::",
"GOLDRUSH",
",",
"self",
"::",
"HIGHLAND",
",",
"self",
"::",
"ISLANDS",
",",
"self",
"::",
"MEDITERRANEAN",
",",
"self",
"::",
"MIGRATION",
",",
"self",
"::",
"RIVERS",
",",
"self",
"::",
"TEAMISLANDS",
",",
"self",
"::",
"SCANDINAVIA",
",",
"self",
"::",
"MONGOLIA",
",",
"self",
"::",
"YUCATAN",
",",
"self",
"::",
"SALTMARSH",
",",
"self",
"::",
"ARENA",
",",
"self",
"::",
"KINGOFTHEHILL",
",",
"self",
"::",
"OASIS",
",",
"self",
"::",
"GHOSTLAKE",
",",
"self",
"::",
"NOMAD",
",",
"self",
"::",
"RANDOM",
",",
"]",
")",
";",
"}"
] | Check whether a map ID denotes a builtin map.
@see \RecAnalyst\ResourcePacks\AgeOfEmpires::isCustomMap
For the inverse.
@param int $id Map ID.
@return bool True if the map is builtin, false otherwise. | [
"Check",
"whether",
"a",
"map",
"ID",
"denotes",
"a",
"builtin",
"map",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/ResourcePacks/AgeOfEmpires/Map.php#L103-L115 |
35,777 | goto-bus-stop/recanalyst | src/StreamExtractor.php | StreamExtractor.manuallyDetermineHeaderLength | private function manuallyDetermineHeaderLength()
{
// This separator is part of the Start Game command, which is the very
// first command in the recorded game body. It's … reasonably accurate.
$separator = pack('c*', 0xF4, 0x01, 0x00, 0x00);
// We need to reset the file pointer when we're done
$initialBase = ftell($this->fp);
$base = $initialBase;
$buffer = '';
while (($buffer = fread($this->fp, 8192)) !== false) {
$index = strpos($buffer, $separator);
if ($index !== false) {
$this->headerLen = $base + $index - 4;
break;
}
$base += strlen($buffer);
}
fseek($this->fp, $initialBase);
} | php | private function manuallyDetermineHeaderLength()
{
// This separator is part of the Start Game command, which is the very
// first command in the recorded game body. It's … reasonably accurate.
$separator = pack('c*', 0xF4, 0x01, 0x00, 0x00);
// We need to reset the file pointer when we're done
$initialBase = ftell($this->fp);
$base = $initialBase;
$buffer = '';
while (($buffer = fread($this->fp, 8192)) !== false) {
$index = strpos($buffer, $separator);
if ($index !== false) {
$this->headerLen = $base + $index - 4;
break;
}
$base += strlen($buffer);
}
fseek($this->fp, $initialBase);
} | [
"private",
"function",
"manuallyDetermineHeaderLength",
"(",
")",
"{",
"// This separator is part of the Start Game command, which is the very",
"// first command in the recorded game body. It's … reasonably accurate.",
"$",
"separator",
"=",
"pack",
"(",
"'c*'",
",",
"0xF4",
",",
"0x01",
",",
"0x00",
",",
"0x00",
")",
";",
"// We need to reset the file pointer when we're done",
"$",
"initialBase",
"=",
"ftell",
"(",
"$",
"this",
"->",
"fp",
")",
";",
"$",
"base",
"=",
"$",
"initialBase",
";",
"$",
"buffer",
"=",
"''",
";",
"while",
"(",
"(",
"$",
"buffer",
"=",
"fread",
"(",
"$",
"this",
"->",
"fp",
",",
"8192",
")",
")",
"!==",
"false",
")",
"{",
"$",
"index",
"=",
"strpos",
"(",
"$",
"buffer",
",",
"$",
"separator",
")",
";",
"if",
"(",
"$",
"index",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"headerLen",
"=",
"$",
"base",
"+",
"$",
"index",
"-",
"4",
";",
"break",
";",
"}",
"$",
"base",
"+=",
"strlen",
"(",
"$",
"buffer",
")",
";",
"}",
"fseek",
"(",
"$",
"this",
"->",
"fp",
",",
"$",
"initialBase",
")",
";",
"}"
] | Determine the header length if the Header Length field was not set in the
file. | [
"Determine",
"the",
"header",
"length",
"if",
"the",
"Header",
"Length",
"field",
"was",
"not",
"set",
"in",
"the",
"file",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/StreamExtractor.php#L73-L92 |
35,778 | goto-bus-stop/recanalyst | src/StreamExtractor.php | StreamExtractor.determineHeaderLength | private function determineHeaderLength()
{
$rawRead = fread($this->fp, 4);
if ($rawRead === false || strlen($rawRead) < 4) {
throw new RecAnalystException(
'Unable to read the header length',
RecAnalystException::HEADERLEN_READERROR
);
}
list (, $this->headerLen) = unpack('V', $rawRead);
if (!$this->headerLen) {
$this->manuallyDetermineHeaderLength();
}
if (!$this->headerLen) {
throw new RecAnalystException(
'Header length is zero',
RecAnalystException::EMPTY_HEADER
);
}
// In MGL files, the header starts immediately after the header length
// bytes. In MGX files, another int32 is stored first, possibly indicating
// the position of possible further headers(? something for saved chapters,
// at least, or perhaps saved & restored games).
// The gzip-compressed header always starts with a series of bytes that
// decodes to a really high number. So if the next 4 bytes _don't_
// encode to a really high number, they must refer to the next header.
$rawRead = fread($this->fp, 4);
list (, $nextPos) = unpack('V', $rawRead);
$hasNextPos = $nextPos === 0 || $nextPos < $this->getFileSize();
$this->headerStart = $hasNextPos ? 8 : 4;
$this->headerLen -= $this->headerStart;
} | php | private function determineHeaderLength()
{
$rawRead = fread($this->fp, 4);
if ($rawRead === false || strlen($rawRead) < 4) {
throw new RecAnalystException(
'Unable to read the header length',
RecAnalystException::HEADERLEN_READERROR
);
}
list (, $this->headerLen) = unpack('V', $rawRead);
if (!$this->headerLen) {
$this->manuallyDetermineHeaderLength();
}
if (!$this->headerLen) {
throw new RecAnalystException(
'Header length is zero',
RecAnalystException::EMPTY_HEADER
);
}
// In MGL files, the header starts immediately after the header length
// bytes. In MGX files, another int32 is stored first, possibly indicating
// the position of possible further headers(? something for saved chapters,
// at least, or perhaps saved & restored games).
// The gzip-compressed header always starts with a series of bytes that
// decodes to a really high number. So if the next 4 bytes _don't_
// encode to a really high number, they must refer to the next header.
$rawRead = fread($this->fp, 4);
list (, $nextPos) = unpack('V', $rawRead);
$hasNextPos = $nextPos === 0 || $nextPos < $this->getFileSize();
$this->headerStart = $hasNextPos ? 8 : 4;
$this->headerLen -= $this->headerStart;
} | [
"private",
"function",
"determineHeaderLength",
"(",
")",
"{",
"$",
"rawRead",
"=",
"fread",
"(",
"$",
"this",
"->",
"fp",
",",
"4",
")",
";",
"if",
"(",
"$",
"rawRead",
"===",
"false",
"||",
"strlen",
"(",
"$",
"rawRead",
")",
"<",
"4",
")",
"{",
"throw",
"new",
"RecAnalystException",
"(",
"'Unable to read the header length'",
",",
"RecAnalystException",
"::",
"HEADERLEN_READERROR",
")",
";",
"}",
"list",
"(",
",",
"$",
"this",
"->",
"headerLen",
")",
"=",
"unpack",
"(",
"'V'",
",",
"$",
"rawRead",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"headerLen",
")",
"{",
"$",
"this",
"->",
"manuallyDetermineHeaderLength",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"headerLen",
")",
"{",
"throw",
"new",
"RecAnalystException",
"(",
"'Header length is zero'",
",",
"RecAnalystException",
"::",
"EMPTY_HEADER",
")",
";",
"}",
"// In MGL files, the header starts immediately after the header length",
"// bytes. In MGX files, another int32 is stored first, possibly indicating",
"// the position of possible further headers(? something for saved chapters,",
"// at least, or perhaps saved & restored games).",
"// The gzip-compressed header always starts with a series of bytes that",
"// decodes to a really high number. So if the next 4 bytes _don't_",
"// encode to a really high number, they must refer to the next header.",
"$",
"rawRead",
"=",
"fread",
"(",
"$",
"this",
"->",
"fp",
",",
"4",
")",
";",
"list",
"(",
",",
"$",
"nextPos",
")",
"=",
"unpack",
"(",
"'V'",
",",
"$",
"rawRead",
")",
";",
"$",
"hasNextPos",
"=",
"$",
"nextPos",
"===",
"0",
"||",
"$",
"nextPos",
"<",
"$",
"this",
"->",
"getFileSize",
"(",
")",
";",
"$",
"this",
"->",
"headerStart",
"=",
"$",
"hasNextPos",
"?",
"8",
":",
"4",
";",
"$",
"this",
"->",
"headerLen",
"-=",
"$",
"this",
"->",
"headerStart",
";",
"}"
] | Find the header length. | [
"Find",
"the",
"header",
"length",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/StreamExtractor.php#L109-L141 |
35,779 | goto-bus-stop/recanalyst | src/StreamExtractor.php | StreamExtractor.getHeader | public function getHeader()
{
if ($this->headerContents) {
return $this->headerContents;
}
if (!$this->headerLen) {
$this->determineHeaderLength();
}
fseek($this->fp, $this->headerStart, SEEK_SET);
$read = 0;
$bindata = '';
while ($read < $this->headerLen && ($buff = fread($this->fp, $this->headerLen - $read))) {
$read += strlen($buff);
$bindata .= $buff;
}
unset($buff);
$this->headerContents = gzinflate($bindata, $this->options['memoryLimit']);
unset($bindata);
if (!strlen($this->headerContents)) {
throw new RecAnalystException(
'Cannot decompress header section',
RecAnalystException::HEADER_DECOMPRESSERROR
);
}
return $this->headerContents;
} | php | public function getHeader()
{
if ($this->headerContents) {
return $this->headerContents;
}
if (!$this->headerLen) {
$this->determineHeaderLength();
}
fseek($this->fp, $this->headerStart, SEEK_SET);
$read = 0;
$bindata = '';
while ($read < $this->headerLen && ($buff = fread($this->fp, $this->headerLen - $read))) {
$read += strlen($buff);
$bindata .= $buff;
}
unset($buff);
$this->headerContents = gzinflate($bindata, $this->options['memoryLimit']);
unset($bindata);
if (!strlen($this->headerContents)) {
throw new RecAnalystException(
'Cannot decompress header section',
RecAnalystException::HEADER_DECOMPRESSERROR
);
}
return $this->headerContents;
} | [
"public",
"function",
"getHeader",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"headerContents",
")",
"{",
"return",
"$",
"this",
"->",
"headerContents",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"headerLen",
")",
"{",
"$",
"this",
"->",
"determineHeaderLength",
"(",
")",
";",
"}",
"fseek",
"(",
"$",
"this",
"->",
"fp",
",",
"$",
"this",
"->",
"headerStart",
",",
"SEEK_SET",
")",
";",
"$",
"read",
"=",
"0",
";",
"$",
"bindata",
"=",
"''",
";",
"while",
"(",
"$",
"read",
"<",
"$",
"this",
"->",
"headerLen",
"&&",
"(",
"$",
"buff",
"=",
"fread",
"(",
"$",
"this",
"->",
"fp",
",",
"$",
"this",
"->",
"headerLen",
"-",
"$",
"read",
")",
")",
")",
"{",
"$",
"read",
"+=",
"strlen",
"(",
"$",
"buff",
")",
";",
"$",
"bindata",
".=",
"$",
"buff",
";",
"}",
"unset",
"(",
"$",
"buff",
")",
";",
"$",
"this",
"->",
"headerContents",
"=",
"gzinflate",
"(",
"$",
"bindata",
",",
"$",
"this",
"->",
"options",
"[",
"'memoryLimit'",
"]",
")",
";",
"unset",
"(",
"$",
"bindata",
")",
";",
"if",
"(",
"!",
"strlen",
"(",
"$",
"this",
"->",
"headerContents",
")",
")",
"{",
"throw",
"new",
"RecAnalystException",
"(",
"'Cannot decompress header section'",
",",
"RecAnalystException",
"::",
"HEADER_DECOMPRESSERROR",
")",
";",
"}",
"return",
"$",
"this",
"->",
"headerContents",
";",
"}"
] | Read or return the Recorded Game file's header block.
@return string | [
"Read",
"or",
"return",
"the",
"Recorded",
"Game",
"file",
"s",
"header",
"block",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/StreamExtractor.php#L148-L179 |
35,780 | goto-bus-stop/recanalyst | src/StreamExtractor.php | StreamExtractor.getBody | public function getBody()
{
if ($this->bodyContents) {
return $this->bodyContents;
}
if (!$this->headerLen) {
$this->determineHeaderLength();
}
fseek($this->fp, $this->headerStart + $this->headerLen, SEEK_SET);
$this->bodyContents = '';
while (!feof($this->fp)) {
$this->bodyContents .= fread($this->fp, 8192);
}
fclose($this->fp);
return $this->bodyContents;
} | php | public function getBody()
{
if ($this->bodyContents) {
return $this->bodyContents;
}
if (!$this->headerLen) {
$this->determineHeaderLength();
}
fseek($this->fp, $this->headerStart + $this->headerLen, SEEK_SET);
$this->bodyContents = '';
while (!feof($this->fp)) {
$this->bodyContents .= fread($this->fp, 8192);
}
fclose($this->fp);
return $this->bodyContents;
} | [
"public",
"function",
"getBody",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"bodyContents",
")",
"{",
"return",
"$",
"this",
"->",
"bodyContents",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"headerLen",
")",
"{",
"$",
"this",
"->",
"determineHeaderLength",
"(",
")",
";",
"}",
"fseek",
"(",
"$",
"this",
"->",
"fp",
",",
"$",
"this",
"->",
"headerStart",
"+",
"$",
"this",
"->",
"headerLen",
",",
"SEEK_SET",
")",
";",
"$",
"this",
"->",
"bodyContents",
"=",
"''",
";",
"while",
"(",
"!",
"feof",
"(",
"$",
"this",
"->",
"fp",
")",
")",
"{",
"$",
"this",
"->",
"bodyContents",
".=",
"fread",
"(",
"$",
"this",
"->",
"fp",
",",
"8192",
")",
";",
"}",
"fclose",
"(",
"$",
"this",
"->",
"fp",
")",
";",
"return",
"$",
"this",
"->",
"bodyContents",
";",
"}"
] | Read or return the Recorded Game file's body.
@return string | [
"Read",
"or",
"return",
"the",
"Recorded",
"Game",
"file",
"s",
"body",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/StreamExtractor.php#L186-L205 |
35,781 | goto-bus-stop/recanalyst | src/Model/VictorySettings.php | VictorySettings.getVictoryString | public function getVictoryString()
{
if (!isset(RecAnalystConst::$VICTORY_CONDITIONS[$this->_victoryCondition])) {
return '';
}
$result = RecAnalystConst::$VICTORY_CONDITIONS[$this->_victoryCondition];
switch ($this->_victoryCondition) {
case self::TIMELIMIT:
if ($this->_timeLimit) {
return sprintf('%s (%d years)', $result, $this->_timeLimit);
}
break;
case self::SCORELIMIT:
if ($this->_scoreLimit) {
return sprintf('%s (%d)', $result, $this->_scoreLimit);
}
break;
}
return $result;
} | php | public function getVictoryString()
{
if (!isset(RecAnalystConst::$VICTORY_CONDITIONS[$this->_victoryCondition])) {
return '';
}
$result = RecAnalystConst::$VICTORY_CONDITIONS[$this->_victoryCondition];
switch ($this->_victoryCondition) {
case self::TIMELIMIT:
if ($this->_timeLimit) {
return sprintf('%s (%d years)', $result, $this->_timeLimit);
}
break;
case self::SCORELIMIT:
if ($this->_scoreLimit) {
return sprintf('%s (%d)', $result, $this->_scoreLimit);
}
break;
}
return $result;
} | [
"public",
"function",
"getVictoryString",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"RecAnalystConst",
"::",
"$",
"VICTORY_CONDITIONS",
"[",
"$",
"this",
"->",
"_victoryCondition",
"]",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"result",
"=",
"RecAnalystConst",
"::",
"$",
"VICTORY_CONDITIONS",
"[",
"$",
"this",
"->",
"_victoryCondition",
"]",
";",
"switch",
"(",
"$",
"this",
"->",
"_victoryCondition",
")",
"{",
"case",
"self",
"::",
"TIMELIMIT",
":",
"if",
"(",
"$",
"this",
"->",
"_timeLimit",
")",
"{",
"return",
"sprintf",
"(",
"'%s (%d years)'",
",",
"$",
"result",
",",
"$",
"this",
"->",
"_timeLimit",
")",
";",
"}",
"break",
";",
"case",
"self",
"::",
"SCORELIMIT",
":",
"if",
"(",
"$",
"this",
"->",
"_scoreLimit",
")",
"{",
"return",
"sprintf",
"(",
"'%s (%d)'",
",",
"$",
"result",
",",
"$",
"this",
"->",
"_scoreLimit",
")",
";",
"}",
"break",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns victory string.
@return string | [
"Returns",
"victory",
"string",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Model/VictorySettings.php#L64-L83 |
35,782 | goto-bus-stop/recanalyst | src/Model/GameSettings.php | GameSettings.mapStyleName | public function mapStyleName()
{
$mapStyle = $this->rec->getResourcePack()
->getMapStyle($this->mapId);
return $this->rec->trans('map_styles', $mapStyle);
} | php | public function mapStyleName()
{
$mapStyle = $this->rec->getResourcePack()
->getMapStyle($this->mapId);
return $this->rec->trans('map_styles', $mapStyle);
} | [
"public",
"function",
"mapStyleName",
"(",
")",
"{",
"$",
"mapStyle",
"=",
"$",
"this",
"->",
"rec",
"->",
"getResourcePack",
"(",
")",
"->",
"getMapStyle",
"(",
"$",
"this",
"->",
"mapId",
")",
";",
"return",
"$",
"this",
"->",
"rec",
"->",
"trans",
"(",
"'map_styles'",
",",
"$",
"mapStyle",
")",
";",
"}"
] | Returns map style string.
@return string | [
"Returns",
"map",
"style",
"string",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Model/GameSettings.php#L145-L150 |
35,783 | goto-bus-stop/recanalyst | src/Model/GameSettings.php | GameSettings.mapName | public function mapName($options = [])
{
$extractRmsName = isset($options['extractRMSName']) ? $options['extractRMSName'] : true;
if ($extractRmsName && $this->isCustomMap()) {
$nameExtractor = new MapNameExtractor($this->rec);
$likelyName = $nameExtractor->run();
if ($likelyName) {
return $likelyName;
}
}
return $this->rec->trans('map_names', $this->mapId);
} | php | public function mapName($options = [])
{
$extractRmsName = isset($options['extractRMSName']) ? $options['extractRMSName'] : true;
if ($extractRmsName && $this->isCustomMap()) {
$nameExtractor = new MapNameExtractor($this->rec);
$likelyName = $nameExtractor->run();
if ($likelyName) {
return $likelyName;
}
}
return $this->rec->trans('map_names', $this->mapId);
} | [
"public",
"function",
"mapName",
"(",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"extractRmsName",
"=",
"isset",
"(",
"$",
"options",
"[",
"'extractRMSName'",
"]",
")",
"?",
"$",
"options",
"[",
"'extractRMSName'",
"]",
":",
"true",
";",
"if",
"(",
"$",
"extractRmsName",
"&&",
"$",
"this",
"->",
"isCustomMap",
"(",
")",
")",
"{",
"$",
"nameExtractor",
"=",
"new",
"MapNameExtractor",
"(",
"$",
"this",
"->",
"rec",
")",
";",
"$",
"likelyName",
"=",
"$",
"nameExtractor",
"->",
"run",
"(",
")",
";",
"if",
"(",
"$",
"likelyName",
")",
"{",
"return",
"$",
"likelyName",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"rec",
"->",
"trans",
"(",
"'map_names'",
",",
"$",
"this",
"->",
"mapId",
")",
";",
"}"
] | Get the map name.
@param array $options Options.
- `$options['extractRMSName']` - Whether to attempt to find the RMS
file names of custom random maps. Defaults to `true`.
@return string Map name. | [
"Get",
"the",
"map",
"name",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Model/GameSettings.php#L231-L242 |
35,784 | goto-bus-stop/recanalyst | src/BasicTranslator.php | BasicTranslator.get | private function get($arr, $path)
{
foreach (explode('.', $path) as $prop) {
$arr = $arr[$prop];
}
return $arr;
} | php | private function get($arr, $path)
{
foreach (explode('.', $path) as $prop) {
$arr = $arr[$prop];
}
return $arr;
} | [
"private",
"function",
"get",
"(",
"$",
"arr",
",",
"$",
"path",
")",
"{",
"foreach",
"(",
"explode",
"(",
"'.'",
",",
"$",
"path",
")",
"as",
"$",
"prop",
")",
"{",
"$",
"arr",
"=",
"$",
"arr",
"[",
"$",
"prop",
"]",
";",
"}",
"return",
"$",
"arr",
";",
"}"
] | Get a value from a dotted property path.
@param array $arr Array.
@param string $path Path, properties separated by '.'s.
@return mixed (But probably a string because it's for translations.) | [
"Get",
"a",
"value",
"from",
"a",
"dotted",
"property",
"path",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/BasicTranslator.php#L66-L72 |
35,785 | goto-bus-stop/recanalyst | src/Model/ChatMessage.php | ChatMessage.create | public static function create($time, $player, $chat)
{
$group = '';
// This is directed someplace (@All, @Team, @Enemy, etc.)
// Voobly adds @Rating messages too, which we might wish to parse into
// the player objects later as a `->rating` property.
if ($chat[0] === '<') {
// Standard directed chat messages have a format like:
// <All>PlayerName: message
// Voobly rating messages however:
// <Rating> PlayerName: message
// ...adds a space character before the name, so we deal with it
// separately.
if (substr($chat, 0, 9) === '<Rating> ') {
$group = 'Rating';
$chat = substr($chat, 9);
} else {
$end = strpos($chat, '>');
$group = substr($chat, 1, $end - 1);
$chat = substr($chat, $end + 1);
}
}
if (is_null($player)) {
$player = new Player();
$player->name = substr($chat, 0, strpos($chat, ': '));
if ($player->name[0] === ' ') {
$player->name = substr($player->name, 1);
}
}
// Cut the player name out of the message contents.
$chat = substr($chat, strlen($player->name) + 2);
return new self($time, $player, $chat, $group);
} | php | public static function create($time, $player, $chat)
{
$group = '';
// This is directed someplace (@All, @Team, @Enemy, etc.)
// Voobly adds @Rating messages too, which we might wish to parse into
// the player objects later as a `->rating` property.
if ($chat[0] === '<') {
// Standard directed chat messages have a format like:
// <All>PlayerName: message
// Voobly rating messages however:
// <Rating> PlayerName: message
// ...adds a space character before the name, so we deal with it
// separately.
if (substr($chat, 0, 9) === '<Rating> ') {
$group = 'Rating';
$chat = substr($chat, 9);
} else {
$end = strpos($chat, '>');
$group = substr($chat, 1, $end - 1);
$chat = substr($chat, $end + 1);
}
}
if (is_null($player)) {
$player = new Player();
$player->name = substr($chat, 0, strpos($chat, ': '));
if ($player->name[0] === ' ') {
$player->name = substr($player->name, 1);
}
}
// Cut the player name out of the message contents.
$chat = substr($chat, strlen($player->name) + 2);
return new self($time, $player, $chat, $group);
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"time",
",",
"$",
"player",
",",
"$",
"chat",
")",
"{",
"$",
"group",
"=",
"''",
";",
"// This is directed someplace (@All, @Team, @Enemy, etc.)",
"// Voobly adds @Rating messages too, which we might wish to parse into",
"// the player objects later as a `->rating` property.",
"if",
"(",
"$",
"chat",
"[",
"0",
"]",
"===",
"'<'",
")",
"{",
"// Standard directed chat messages have a format like:",
"// <All>PlayerName: message",
"// Voobly rating messages however:",
"// <Rating> PlayerName: message",
"// ...adds a space character before the name, so we deal with it",
"// separately.",
"if",
"(",
"substr",
"(",
"$",
"chat",
",",
"0",
",",
"9",
")",
"===",
"'<Rating> '",
")",
"{",
"$",
"group",
"=",
"'Rating'",
";",
"$",
"chat",
"=",
"substr",
"(",
"$",
"chat",
",",
"9",
")",
";",
"}",
"else",
"{",
"$",
"end",
"=",
"strpos",
"(",
"$",
"chat",
",",
"'>'",
")",
";",
"$",
"group",
"=",
"substr",
"(",
"$",
"chat",
",",
"1",
",",
"$",
"end",
"-",
"1",
")",
";",
"$",
"chat",
"=",
"substr",
"(",
"$",
"chat",
",",
"$",
"end",
"+",
"1",
")",
";",
"}",
"}",
"if",
"(",
"is_null",
"(",
"$",
"player",
")",
")",
"{",
"$",
"player",
"=",
"new",
"Player",
"(",
")",
";",
"$",
"player",
"->",
"name",
"=",
"substr",
"(",
"$",
"chat",
",",
"0",
",",
"strpos",
"(",
"$",
"chat",
",",
"': '",
")",
")",
";",
"if",
"(",
"$",
"player",
"->",
"name",
"[",
"0",
"]",
"===",
"' '",
")",
"{",
"$",
"player",
"->",
"name",
"=",
"substr",
"(",
"$",
"player",
"->",
"name",
",",
"1",
")",
";",
"}",
"}",
"// Cut the player name out of the message contents.",
"$",
"chat",
"=",
"substr",
"(",
"$",
"chat",
",",
"strlen",
"(",
"$",
"player",
"->",
"name",
")",
"+",
"2",
")",
";",
"return",
"new",
"self",
"(",
"$",
"time",
",",
"$",
"player",
",",
"$",
"chat",
",",
"$",
"group",
")",
";",
"}"
] | Helper method to create a chat message from a chat string more easily.
Messages actually have the player name and sometimes a group specifier
(<Team>, <Enemy>, etc) included in their message body which is lame.
Sometimes players that don't end up in the player info blocks of the
recorded games sent messages anyway (particularly pre-game chat by people
who joined the multiplayer lobby and then left) so we deal with that too.
@param int $time Time at which this message was sent in milliseconds
since the start of the game.
@param \RecAnalyst\Model\Player $player Message Sender.
@param string $chat Message contents.
@return ChatMessage | [
"Helper",
"method",
"to",
"create",
"a",
"chat",
"message",
"from",
"a",
"chat",
"string",
"more",
"easily",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Model/ChatMessage.php#L78-L110 |
35,786 | goto-bus-stop/recanalyst | src/RecordedGame.php | RecordedGame.getAnalysis | public function getAnalysis($analyzerName, $arg = null, $startAt = 0)
{
$key = $analyzerName . ':' . $startAt;
if (!array_key_exists($key, $this->analyses)) {
$analyzer = new $analyzerName($arg);
$analyzer->position = $startAt;
$result = new \StdClass;
$result->analysis = $this->runAnalyzer($analyzer);
$result->position = $analyzer->position;
$this->analyses[$key] = $result;
}
return $this->analyses[$key];
} | php | public function getAnalysis($analyzerName, $arg = null, $startAt = 0)
{
$key = $analyzerName . ':' . $startAt;
if (!array_key_exists($key, $this->analyses)) {
$analyzer = new $analyzerName($arg);
$analyzer->position = $startAt;
$result = new \StdClass;
$result->analysis = $this->runAnalyzer($analyzer);
$result->position = $analyzer->position;
$this->analyses[$key] = $result;
}
return $this->analyses[$key];
} | [
"public",
"function",
"getAnalysis",
"(",
"$",
"analyzerName",
",",
"$",
"arg",
"=",
"null",
",",
"$",
"startAt",
"=",
"0",
")",
"{",
"$",
"key",
"=",
"$",
"analyzerName",
".",
"':'",
".",
"$",
"startAt",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"analyses",
")",
")",
"{",
"$",
"analyzer",
"=",
"new",
"$",
"analyzerName",
"(",
"$",
"arg",
")",
";",
"$",
"analyzer",
"->",
"position",
"=",
"$",
"startAt",
";",
"$",
"result",
"=",
"new",
"\\",
"StdClass",
";",
"$",
"result",
"->",
"analysis",
"=",
"$",
"this",
"->",
"runAnalyzer",
"(",
"$",
"analyzer",
")",
";",
"$",
"result",
"->",
"position",
"=",
"$",
"analyzer",
"->",
"position",
";",
"$",
"this",
"->",
"analyses",
"[",
"$",
"key",
"]",
"=",
"$",
"result",
";",
"}",
"return",
"$",
"this",
"->",
"analyses",
"[",
"$",
"key",
"]",
";",
"}"
] | Get an analysis result for a specific analyzer, running it if necessary.
@param string $analyzerName Fully qualified name of the analyzer class.
@param mixed $arg Optional argument to the analyzer.
@param int $startAt Position to start at.
@return mixed | [
"Get",
"an",
"analysis",
"result",
"for",
"a",
"specific",
"analyzer",
"running",
"it",
"if",
"necessary",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/RecordedGame.php#L136-L148 |
35,787 | goto-bus-stop/recanalyst | src/RecordedGame.php | RecordedGame.getPlayer | public function getPlayer($id)
{
foreach ($this->header()->players as $player) {
if ($player->index === $id) {
return $player;
}
}
} | php | public function getPlayer($id)
{
foreach ($this->header()->players as $player) {
if ($player->index === $id) {
return $player;
}
}
} | [
"public",
"function",
"getPlayer",
"(",
"$",
"id",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"header",
"(",
")",
"->",
"players",
"as",
"$",
"player",
")",
"{",
"if",
"(",
"$",
"player",
"->",
"index",
"===",
"$",
"id",
")",
"{",
"return",
"$",
"player",
";",
"}",
"}",
"}"
] | Get a player by their index.
@param int $id Player index.
@return \RecAnalyst\Model\Player|null | [
"Get",
"a",
"player",
"by",
"their",
"index",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/RecordedGame.php#L291-L298 |
35,788 | goto-bus-stop/recanalyst | src/RecordedGame.php | RecordedGame.getTranslateKey | private function getTranslateKey($args)
{
// Game version names are in their own file, not in with resource packs.
if ($args[0] === 'game_versions') {
$key = implode('.', $args);
} else {
$pack = get_class($this->resourcePack);
$key = $pack::NAME . '.' . implode('.', $args);
}
if ($this->isLaravel) {
return 'recanalyst::' . $key;
}
return $key;
} | php | private function getTranslateKey($args)
{
// Game version names are in their own file, not in with resource packs.
if ($args[0] === 'game_versions') {
$key = implode('.', $args);
} else {
$pack = get_class($this->resourcePack);
$key = $pack::NAME . '.' . implode('.', $args);
}
if ($this->isLaravel) {
return 'recanalyst::' . $key;
}
return $key;
} | [
"private",
"function",
"getTranslateKey",
"(",
"$",
"args",
")",
"{",
"// Game version names are in their own file, not in with resource packs.",
"if",
"(",
"$",
"args",
"[",
"0",
"]",
"===",
"'game_versions'",
")",
"{",
"$",
"key",
"=",
"implode",
"(",
"'.'",
",",
"$",
"args",
")",
";",
"}",
"else",
"{",
"$",
"pack",
"=",
"get_class",
"(",
"$",
"this",
"->",
"resourcePack",
")",
";",
"$",
"key",
"=",
"$",
"pack",
"::",
"NAME",
".",
"'.'",
".",
"implode",
"(",
"'.'",
",",
"$",
"args",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isLaravel",
")",
"{",
"return",
"'recanalyst::'",
".",
"$",
"key",
";",
"}",
"return",
"$",
"key",
";",
"}"
] | Get a translate key for use with Symfony or Laravel Translations.
@return string A translation key. | [
"Get",
"a",
"translate",
"key",
"for",
"use",
"with",
"Symfony",
"or",
"Laravel",
"Translations",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/RecordedGame.php#L316-L329 |
35,789 | goto-bus-stop/recanalyst | src/ResourcePacks/AgeOfEmpires.php | AgeOfEmpires.isGateUnit | public function isGateUnit($id)
{
return $id === Unit::GATE
|| $id === Unit::GATE2
|| $id === Unit::GATE3
|| $id === Unit::GATE4;
} | php | public function isGateUnit($id)
{
return $id === Unit::GATE
|| $id === Unit::GATE2
|| $id === Unit::GATE3
|| $id === Unit::GATE4;
} | [
"public",
"function",
"isGateUnit",
"(",
"$",
"id",
")",
"{",
"return",
"$",
"id",
"===",
"Unit",
"::",
"GATE",
"||",
"$",
"id",
"===",
"Unit",
"::",
"GATE2",
"||",
"$",
"id",
"===",
"Unit",
"::",
"GATE3",
"||",
"$",
"id",
"===",
"Unit",
"::",
"GATE4",
";",
"}"
] | Checks whether a unit type ID is a Gate unit.
@param int $id Unit type ID.
@return bool True if the unit type is a gate, false otherwise. | [
"Checks",
"whether",
"a",
"unit",
"type",
"ID",
"is",
"a",
"Gate",
"unit",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/ResourcePacks/AgeOfEmpires.php#L111-L117 |
35,790 | goto-bus-stop/recanalyst | src/ResourcePacks/AgeOfEmpires.php | AgeOfEmpires.isPalisadeGateUnit | public function isPalisadeGateUnit($id)
{
return $id === Unit::PALISADE_GATE
|| $id === Unit::PALISADE_GATE2
|| $id === Unit::PALISADE_GATE3
|| $id === Unit::PALISADE_GATE4;
} | php | public function isPalisadeGateUnit($id)
{
return $id === Unit::PALISADE_GATE
|| $id === Unit::PALISADE_GATE2
|| $id === Unit::PALISADE_GATE3
|| $id === Unit::PALISADE_GATE4;
} | [
"public",
"function",
"isPalisadeGateUnit",
"(",
"$",
"id",
")",
"{",
"return",
"$",
"id",
"===",
"Unit",
"::",
"PALISADE_GATE",
"||",
"$",
"id",
"===",
"Unit",
"::",
"PALISADE_GATE2",
"||",
"$",
"id",
"===",
"Unit",
"::",
"PALISADE_GATE3",
"||",
"$",
"id",
"===",
"Unit",
"::",
"PALISADE_GATE4",
";",
"}"
] | Checks whether a unit type ID is a Palisade Gate unit.
@param int $id Unit type ID.
@return bool True if the unit type is a palisade gate, false otherwise. | [
"Checks",
"whether",
"a",
"unit",
"type",
"ID",
"is",
"a",
"Palisade",
"Gate",
"unit",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/ResourcePacks/AgeOfEmpires.php#L125-L131 |
35,791 | goto-bus-stop/recanalyst | src/ResourcePacks/AgeOfEmpires.php | AgeOfEmpires.isGaiaObject | public function isGaiaObject($id)
{
return $id >= Unit::CLIFF1 && $id <= Unit::CLIFF10
|| $id === Unit::GOLDMINE
|| $id === Unit::STONEMINE
|| $id === Unit::FORAGEBUSH;
} | php | public function isGaiaObject($id)
{
return $id >= Unit::CLIFF1 && $id <= Unit::CLIFF10
|| $id === Unit::GOLDMINE
|| $id === Unit::STONEMINE
|| $id === Unit::FORAGEBUSH;
} | [
"public",
"function",
"isGaiaObject",
"(",
"$",
"id",
")",
"{",
"return",
"$",
"id",
">=",
"Unit",
"::",
"CLIFF1",
"&&",
"$",
"id",
"<=",
"Unit",
"::",
"CLIFF10",
"||",
"$",
"id",
"===",
"Unit",
"::",
"GOLDMINE",
"||",
"$",
"id",
"===",
"Unit",
"::",
"STONEMINE",
"||",
"$",
"id",
"===",
"Unit",
"::",
"FORAGEBUSH",
";",
"}"
] | Checks whether a unit type ID is a GAIA object type. Used to determine
which objects to draw on a map.
@param int $id Unit type ID.
@return bool True if the unit type is a GAIA object, false otherwise. | [
"Checks",
"whether",
"a",
"unit",
"type",
"ID",
"is",
"a",
"GAIA",
"object",
"type",
".",
"Used",
"to",
"determine",
"which",
"objects",
"to",
"draw",
"on",
"a",
"map",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/ResourcePacks/AgeOfEmpires.php#L151-L157 |
35,792 | goto-bus-stop/recanalyst | src/ResourcePacks/AgeOfEmpires.php | AgeOfEmpires.isGaiaUnit | public function isGaiaUnit($id)
{
return $id === Unit::RELIC
|| $id === Unit::DEER
|| $id === Unit::BOAR
|| $id === Unit::JAVELINA
|| $id === Unit::TURKEY
|| $id === Unit::SHEEP;
} | php | public function isGaiaUnit($id)
{
return $id === Unit::RELIC
|| $id === Unit::DEER
|| $id === Unit::BOAR
|| $id === Unit::JAVELINA
|| $id === Unit::TURKEY
|| $id === Unit::SHEEP;
} | [
"public",
"function",
"isGaiaUnit",
"(",
"$",
"id",
")",
"{",
"return",
"$",
"id",
"===",
"Unit",
"::",
"RELIC",
"||",
"$",
"id",
"===",
"Unit",
"::",
"DEER",
"||",
"$",
"id",
"===",
"Unit",
"::",
"BOAR",
"||",
"$",
"id",
"===",
"Unit",
"::",
"JAVELINA",
"||",
"$",
"id",
"===",
"Unit",
"::",
"TURKEY",
"||",
"$",
"id",
"===",
"Unit",
"::",
"SHEEP",
";",
"}"
] | Checks whether a unit type ID is a GAIA unit. Used to determine which
units to draw on a map as not belonging to any player.
@param int $id Unit type ID.
@return bool True if the unit type is a GAIA unit, false otherwise. | [
"Checks",
"whether",
"a",
"unit",
"type",
"ID",
"is",
"a",
"GAIA",
"unit",
".",
"Used",
"to",
"determine",
"which",
"units",
"to",
"draw",
"on",
"a",
"map",
"as",
"not",
"belonging",
"to",
"any",
"player",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/ResourcePacks/AgeOfEmpires.php#L166-L174 |
35,793 | goto-bus-stop/recanalyst | src/Model/GameInfo.php | GameInfo.getPOV | public function getPOV()
{
foreach ($this->owner->players as $player) {
if ($player->owner) {
return $player->name;
}
}
return '';
} | php | public function getPOV()
{
foreach ($this->owner->players as $player) {
if ($player->owner) {
return $player->name;
}
}
return '';
} | [
"public",
"function",
"getPOV",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"owner",
"->",
"players",
"as",
"$",
"player",
")",
"{",
"if",
"(",
"$",
"player",
"->",
"owner",
")",
"{",
"return",
"$",
"player",
"->",
"name",
";",
"}",
"}",
"return",
"''",
";",
"}"
] | Returns the point of view.
@return string | [
"Returns",
"the",
"point",
"of",
"view",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Model/GameInfo.php#L79-L87 |
35,794 | goto-bus-stop/recanalyst | src/Model/GameInfo.php | GameInfo.ingameCoop | public function ingameCoop()
{
foreach ($this->owner->players as $player) {
if ($player->isCooping) {
return true;
}
}
return false;
} | php | public function ingameCoop()
{
foreach ($this->owner->players as $player) {
if ($player->isCooping) {
return true;
}
}
return false;
} | [
"public",
"function",
"ingameCoop",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"owner",
"->",
"players",
"as",
"$",
"player",
")",
"{",
"if",
"(",
"$",
"player",
"->",
"isCooping",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Determines if there is a cooping player in the game.
@return bool True, if there is a cooping player in the game, false otherwise. | [
"Determines",
"if",
"there",
"is",
"a",
"cooping",
"player",
"in",
"the",
"game",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Model/GameInfo.php#L127-L135 |
35,795 | goto-bus-stop/recanalyst | examples/laravel.php | RecAnalystController.showMapImage | public function showMapImage(Request $request)
{
// The RecordedGame constructor accepts SplFileInfo instances,
// so uploaded files can be passed straight to it:
$rec = new RecordedGame($request->file('game'));
// `mapImage()` returns an instance of \Intervention\Image, which has a
// Laravel-compatible `response()` method.
return $rec->mapImage()->response('png');
} | php | public function showMapImage(Request $request)
{
// The RecordedGame constructor accepts SplFileInfo instances,
// so uploaded files can be passed straight to it:
$rec = new RecordedGame($request->file('game'));
// `mapImage()` returns an instance of \Intervention\Image, which has a
// Laravel-compatible `response()` method.
return $rec->mapImage()->response('png');
} | [
"public",
"function",
"showMapImage",
"(",
"Request",
"$",
"request",
")",
"{",
"// The RecordedGame constructor accepts SplFileInfo instances,",
"// so uploaded files can be passed straight to it:",
"$",
"rec",
"=",
"new",
"RecordedGame",
"(",
"$",
"request",
"->",
"file",
"(",
"'game'",
")",
")",
";",
"// `mapImage()` returns an instance of \\Intervention\\Image, which has a",
"// Laravel-compatible `response()` method.",
"return",
"$",
"rec",
"->",
"mapImage",
"(",
")",
"->",
"response",
"(",
"'png'",
")",
";",
"}"
] | Render a PNG map image and send it to the browser. | [
"Render",
"a",
"PNG",
"map",
"image",
"and",
"send",
"it",
"to",
"the",
"browser",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/examples/laravel.php#L16-L25 |
35,796 | goto-bus-stop/recanalyst | src/Model/Player.php | Player.team | public function team()
{
$teams = $this->rec->teams();
foreach ($teams as $team) {
if ($team->index() === $this->teamIndex) {
return $team;
}
}
} | php | public function team()
{
$teams = $this->rec->teams();
foreach ($teams as $team) {
if ($team->index() === $this->teamIndex) {
return $team;
}
}
} | [
"public",
"function",
"team",
"(",
")",
"{",
"$",
"teams",
"=",
"$",
"this",
"->",
"rec",
"->",
"teams",
"(",
")",
";",
"foreach",
"(",
"$",
"teams",
"as",
"$",
"team",
")",
"{",
"if",
"(",
"$",
"team",
"->",
"index",
"(",
")",
"===",
"$",
"this",
"->",
"teamIndex",
")",
"{",
"return",
"$",
"team",
";",
"}",
"}",
"}"
] | Get the player's team.
@return \RecAnalyst\Model\Team|null | [
"Get",
"the",
"player",
"s",
"team",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Model/Player.php#L177-L185 |
35,797 | goto-bus-stop/recanalyst | src/Model/Player.php | Player.color | public function color()
{
if (is_null($this->rec)) {
return null;
}
$resourcePack = $this->rec->getResourcePack();
return $resourcePack->getPlayerColor($this->colorId);
} | php | public function color()
{
if (is_null($this->rec)) {
return null;
}
$resourcePack = $this->rec->getResourcePack();
return $resourcePack->getPlayerColor($this->colorId);
} | [
"public",
"function",
"color",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"rec",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"resourcePack",
"=",
"$",
"this",
"->",
"rec",
"->",
"getResourcePack",
"(",
")",
";",
"return",
"$",
"resourcePack",
"->",
"getPlayerColor",
"(",
"$",
"this",
"->",
"colorId",
")",
";",
"}"
] | Get the hex color of this player.
@return string Hexadecimal representation of this player's color. | [
"Get",
"the",
"hex",
"color",
"of",
"this",
"player",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Model/Player.php#L263-L270 |
35,798 | goto-bus-stop/recanalyst | src/Model/Player.php | Player.addResearch | public function addResearch($id, $time)
{
$this->researchesById[$id] = new Research($this->rec, $id, $time);
} | php | public function addResearch($id, $time)
{
$this->researchesById[$id] = new Research($this->rec, $id, $time);
} | [
"public",
"function",
"addResearch",
"(",
"$",
"id",
",",
"$",
"time",
")",
"{",
"$",
"this",
"->",
"researchesById",
"[",
"$",
"id",
"]",
"=",
"new",
"Research",
"(",
"$",
"this",
"->",
"rec",
",",
"$",
"id",
",",
"$",
"time",
")",
";",
"}"
] | Add a research action.
@param int $id Research ID.
@param int $time Research completion time. | [
"Add",
"a",
"research",
"action",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Model/Player.php#L293-L296 |
35,799 | goto-bus-stop/recanalyst | src/Model/Player.php | Player.civName | public function civName()
{
if (!is_null($this->rec)) {
return $this->rec->trans('civilizations', $this->civId);
}
return 'Civ #' . $this->civId;
} | php | public function civName()
{
if (!is_null($this->rec)) {
return $this->rec->trans('civilizations', $this->civId);
}
return 'Civ #' . $this->civId;
} | [
"public",
"function",
"civName",
"(",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"rec",
")",
")",
"{",
"return",
"$",
"this",
"->",
"rec",
"->",
"trans",
"(",
"'civilizations'",
",",
"$",
"this",
"->",
"civId",
")",
";",
"}",
"return",
"'Civ #'",
".",
"$",
"this",
"->",
"civId",
";",
"}"
] | Get the name of this player's civilization.
@return string | [
"Get",
"the",
"name",
"of",
"this",
"player",
"s",
"civilization",
"."
] | daec4916d04a73cf89f9325ad77bfaf0644fda06 | https://github.com/goto-bus-stop/recanalyst/blob/daec4916d04a73cf89f9325ad77bfaf0644fda06/src/Model/Player.php#L311-L317 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.