repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
webforge-labs/psc-cms | lib/Psc/Doctrine/PhpParser.php | PhpParser.parseClass | public function parseClass(\ReflectionClass $class)
{
if (false === $filename = $class->getFilename()) {
return array();
}
$content = $this->getFileContent($filename, $class->getStartLine());
$namespace = str_replace('\\', '\\\\', $class->getNamespaceName());
$content = preg_replace('/^.*?(\bnamespace\s+' . $namespace . '\s*[;{].*)$/s', '\\1', $content);
$this->tokens = token_get_all('<?php ' . $content);
$this->numTokens = count($this->tokens);
$this->pointer = 0;
$statements = $this->parseUseStatements($class->getNamespaceName());
return $statements;
} | php | public function parseClass(\ReflectionClass $class)
{
if (false === $filename = $class->getFilename()) {
return array();
}
$content = $this->getFileContent($filename, $class->getStartLine());
$namespace = str_replace('\\', '\\\\', $class->getNamespaceName());
$content = preg_replace('/^.*?(\bnamespace\s+' . $namespace . '\s*[;{].*)$/s', '\\1', $content);
$this->tokens = token_get_all('<?php ' . $content);
$this->numTokens = count($this->tokens);
$this->pointer = 0;
$statements = $this->parseUseStatements($class->getNamespaceName());
return $statements;
} | [
"public",
"function",
"parseClass",
"(",
"\\",
"ReflectionClass",
"$",
"class",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"filename",
"=",
"$",
"class",
"->",
"getFilename",
"(",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"content",
"=",
"$",
"this",
"->",
"getFileContent",
"(",
"$",
"filename",
",",
"$",
"class",
"->",
"getStartLine",
"(",
")",
")",
";",
"$",
"namespace",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'\\\\\\\\'",
",",
"$",
"class",
"->",
"getNamespaceName",
"(",
")",
")",
";",
"$",
"content",
"=",
"preg_replace",
"(",
"'/^.*?(\\bnamespace\\s+'",
".",
"$",
"namespace",
".",
"'\\s*[;{].*)$/s'",
",",
"'\\\\1'",
",",
"$",
"content",
")",
";",
"$",
"this",
"->",
"tokens",
"=",
"token_get_all",
"(",
"'<?php '",
".",
"$",
"content",
")",
";",
"$",
"this",
"->",
"numTokens",
"=",
"count",
"(",
"$",
"this",
"->",
"tokens",
")",
";",
"$",
"this",
"->",
"pointer",
"=",
"0",
";",
"$",
"statements",
"=",
"$",
"this",
"->",
"parseUseStatements",
"(",
"$",
"class",
"->",
"getNamespaceName",
"(",
")",
")",
";",
"return",
"$",
"statements",
";",
"}"
] | Parses a class.
@param \ReflectionClass $class A <code>ReflectionClass</code> object.
@return array A list with use statements in the form (Alias => FQN). | [
"Parses",
"a",
"class",
"."
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/PhpParser.php#L58-L74 |
webforge-labs/psc-cms | lib/Psc/Doctrine/PhpParser.php | PhpParser.parseUseStatement | private function parseUseStatement()
{
$class = '';
$alias = '';
$statements = array();
$explicitAlias = false;
while (($token = $this->next())) {
$isNameToken = $token[0] === T_STRING || $token[0] === T_NS_SEPARATOR;
if (!$explicitAlias && $isNameToken) {
$class .= $token[1];
$alias = $token[1];
} else if ($explicitAlias && $isNameToken) {
$alias .= $token[1];
} else if ($token[0] === T_AS) {
$explicitAlias = true;
$alias = '';
} else if ($token === ',') {
$statements[$alias] = $class;
$class = '';
$alias = '';
$explicitAlias = false;
} else if ($token === ';') {
$statements[$alias] = $class;
break;
} else {
break;
}
}
return $statements;
} | php | private function parseUseStatement()
{
$class = '';
$alias = '';
$statements = array();
$explicitAlias = false;
while (($token = $this->next())) {
$isNameToken = $token[0] === T_STRING || $token[0] === T_NS_SEPARATOR;
if (!$explicitAlias && $isNameToken) {
$class .= $token[1];
$alias = $token[1];
} else if ($explicitAlias && $isNameToken) {
$alias .= $token[1];
} else if ($token[0] === T_AS) {
$explicitAlias = true;
$alias = '';
} else if ($token === ',') {
$statements[$alias] = $class;
$class = '';
$alias = '';
$explicitAlias = false;
} else if ($token === ';') {
$statements[$alias] = $class;
break;
} else {
break;
}
}
return $statements;
} | [
"private",
"function",
"parseUseStatement",
"(",
")",
"{",
"$",
"class",
"=",
"''",
";",
"$",
"alias",
"=",
"''",
";",
"$",
"statements",
"=",
"array",
"(",
")",
";",
"$",
"explicitAlias",
"=",
"false",
";",
"while",
"(",
"(",
"$",
"token",
"=",
"$",
"this",
"->",
"next",
"(",
")",
")",
")",
"{",
"$",
"isNameToken",
"=",
"$",
"token",
"[",
"0",
"]",
"===",
"T_STRING",
"||",
"$",
"token",
"[",
"0",
"]",
"===",
"T_NS_SEPARATOR",
";",
"if",
"(",
"!",
"$",
"explicitAlias",
"&&",
"$",
"isNameToken",
")",
"{",
"$",
"class",
".=",
"$",
"token",
"[",
"1",
"]",
";",
"$",
"alias",
"=",
"$",
"token",
"[",
"1",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"explicitAlias",
"&&",
"$",
"isNameToken",
")",
"{",
"$",
"alias",
".=",
"$",
"token",
"[",
"1",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"token",
"[",
"0",
"]",
"===",
"T_AS",
")",
"{",
"$",
"explicitAlias",
"=",
"true",
";",
"$",
"alias",
"=",
"''",
";",
"}",
"else",
"if",
"(",
"$",
"token",
"===",
"','",
")",
"{",
"$",
"statements",
"[",
"$",
"alias",
"]",
"=",
"$",
"class",
";",
"$",
"class",
"=",
"''",
";",
"$",
"alias",
"=",
"''",
";",
"$",
"explicitAlias",
"=",
"false",
";",
"}",
"else",
"if",
"(",
"$",
"token",
"===",
"';'",
")",
"{",
"$",
"statements",
"[",
"$",
"alias",
"]",
"=",
"$",
"class",
";",
"break",
";",
"}",
"else",
"{",
"break",
";",
"}",
"}",
"return",
"$",
"statements",
";",
"}"
] | Parse a single use statement.
@return array A list with all found class names for a use statement. | [
"Parse",
"a",
"single",
"use",
"statement",
"."
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/PhpParser.php#L195-L225 |
yuncms/framework | src/oauth2/grant/types/ClientCredentials.php | ClientCredentials.getUser | protected function getUser()
{
if ($this->_user === null) {
$this->_user = $this->getClient()->user;
}
return $this->_user;
} | php | protected function getUser()
{
if ($this->_user === null) {
$this->_user = $this->getClient()->user;
}
return $this->_user;
} | [
"protected",
"function",
"getUser",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_user",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_user",
"=",
"$",
"this",
"->",
"getClient",
"(",
")",
"->",
"user",
";",
"}",
"return",
"$",
"this",
"->",
"_user",
";",
"}"
] | Finds user
@return \yuncms\user\models\User|null
@throws \yuncms\oauth2\Exception | [
"Finds",
"user"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/oauth2/grant/types/ClientCredentials.php#L108-L114 |
antonmedv/silicone | src/Silicone/Routing/Loader/AnnotatedRouteControllerLoader.php | AnnotatedRouteControllerLoader.getDefaultRouteName | protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method)
{
$routeName = parent::getDefaultRouteName($class, $method);
return preg_replace(array(
'/(module_|controller_?)/',
'/__/'
), array(
'_',
'_'
), $routeName);
} | php | protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method)
{
$routeName = parent::getDefaultRouteName($class, $method);
return preg_replace(array(
'/(module_|controller_?)/',
'/__/'
), array(
'_',
'_'
), $routeName);
} | [
"protected",
"function",
"getDefaultRouteName",
"(",
"\\",
"ReflectionClass",
"$",
"class",
",",
"\\",
"ReflectionMethod",
"$",
"method",
")",
"{",
"$",
"routeName",
"=",
"parent",
"::",
"getDefaultRouteName",
"(",
"$",
"class",
",",
"$",
"method",
")",
";",
"return",
"preg_replace",
"(",
"array",
"(",
"'/(module_|controller_?)/'",
",",
"'/__/'",
")",
",",
"array",
"(",
"'_'",
",",
"'_'",
")",
",",
"$",
"routeName",
")",
";",
"}"
] | Makes the default route name more sane by removing common keywords.
@param \ReflectionClass $class A ReflectionClass instance
@param \ReflectionMethod $method A ReflectionMethod instance
@return string | [
"Makes",
"the",
"default",
"route",
"name",
"more",
"sane",
"by",
"removing",
"common",
"keywords",
"."
] | train | https://github.com/antonmedv/silicone/blob/e4a67ed41f0f419984df642b303f2a491c9a3933/src/Silicone/Routing/Loader/AnnotatedRouteControllerLoader.php#L36-L47 |
webforge-labs/psc-cms | lib/Psc/UI/jqx/TabsSpecification.php | TabsSpecification.getWidgetOptions | public function getWidgetOptions() {
$options = new \stdClass;
foreach (array('width','height','disabled','scrollAnimationDuration','enabledHover','collapsible','animationType','enableScrollAnimation','contentTransitionDuration','toggleMode','selectedItem','position','selectionTracker','scrollable','scrollPosition','scrollStep','autoHeight','showCloseButtons','closeButtonSize','initTabContent','keyboardNavigation','reorder','enableDropAnimation','dropAnimationDuration') as $option) {
if ($this->$option !== "__spec__undefined") {
$options->$option = $this->$option;
}
}
return $options;
} | php | public function getWidgetOptions() {
$options = new \stdClass;
foreach (array('width','height','disabled','scrollAnimationDuration','enabledHover','collapsible','animationType','enableScrollAnimation','contentTransitionDuration','toggleMode','selectedItem','position','selectionTracker','scrollable','scrollPosition','scrollStep','autoHeight','showCloseButtons','closeButtonSize','initTabContent','keyboardNavigation','reorder','enableDropAnimation','dropAnimationDuration') as $option) {
if ($this->$option !== "__spec__undefined") {
$options->$option = $this->$option;
}
}
return $options;
} | [
"public",
"function",
"getWidgetOptions",
"(",
")",
"{",
"$",
"options",
"=",
"new",
"\\",
"stdClass",
";",
"foreach",
"(",
"array",
"(",
"'width'",
",",
"'height'",
",",
"'disabled'",
",",
"'scrollAnimationDuration'",
",",
"'enabledHover'",
",",
"'collapsible'",
",",
"'animationType'",
",",
"'enableScrollAnimation'",
",",
"'contentTransitionDuration'",
",",
"'toggleMode'",
",",
"'selectedItem'",
",",
"'position'",
",",
"'selectionTracker'",
",",
"'scrollable'",
",",
"'scrollPosition'",
",",
"'scrollStep'",
",",
"'autoHeight'",
",",
"'showCloseButtons'",
",",
"'closeButtonSize'",
",",
"'initTabContent'",
",",
"'keyboardNavigation'",
",",
"'reorder'",
",",
"'enableDropAnimation'",
",",
"'dropAnimationDuration'",
")",
"as",
"$",
"option",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"$",
"option",
"!==",
"\"__spec__undefined\"",
")",
"{",
"$",
"options",
"->",
"$",
"option",
"=",
"$",
"this",
"->",
"$",
"option",
";",
"}",
"}",
"return",
"$",
"options",
";",
"}"
] | Gibt alle gesetzten Optionen des Widgets zurück
@return stdClass | [
"Gibt",
"alle",
"gesetzten",
"Optionen",
"des",
"Widgets",
"zurück"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/UI/jqx/TabsSpecification.php#L495-L503 |
periaptio/empress-generator | src/Commands/ResourceMakeCommand.php | ResourceMakeCommand.handle | public function handle()
{
$params = [
'tables' => $this->argument('tables'),
'--tables' => $this->option('tables'),
'--ignore' => $this->option('ignore'),
];
$this->call('generator:make:migration', $params);
$params['--models'] = $this->option('models');
$this->call('generator:make:scaffold', $params);
$this->call('generator:make:factory', $params);
} | php | public function handle()
{
$params = [
'tables' => $this->argument('tables'),
'--tables' => $this->option('tables'),
'--ignore' => $this->option('ignore'),
];
$this->call('generator:make:migration', $params);
$params['--models'] = $this->option('models');
$this->call('generator:make:scaffold', $params);
$this->call('generator:make:factory', $params);
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"$",
"params",
"=",
"[",
"'tables'",
"=>",
"$",
"this",
"->",
"argument",
"(",
"'tables'",
")",
",",
"'--tables'",
"=>",
"$",
"this",
"->",
"option",
"(",
"'tables'",
")",
",",
"'--ignore'",
"=>",
"$",
"this",
"->",
"option",
"(",
"'ignore'",
")",
",",
"]",
";",
"$",
"this",
"->",
"call",
"(",
"'generator:make:migration'",
",",
"$",
"params",
")",
";",
"$",
"params",
"[",
"'--models'",
"]",
"=",
"$",
"this",
"->",
"option",
"(",
"'models'",
")",
";",
"$",
"this",
"->",
"call",
"(",
"'generator:make:scaffold'",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"call",
"(",
"'generator:make:factory'",
",",
"$",
"params",
")",
";",
"}"
] | Execute the command.
@return void | [
"Execute",
"the",
"command",
"."
] | train | https://github.com/periaptio/empress-generator/blob/749fb4b12755819e9c97377ebfb446ee0822168a/src/Commands/ResourceMakeCommand.php#L31-L46 |
Double-Opt-in/php-client-api | src/Client/Api.php | Api.resolveClient | private function resolveClient($client)
{
$client = ! empty($client)
? $client
: new Client();
$client->setBaseUrl(Properties::baseUrl())
->setUserAgent('Double Opt-in php-api/' . self::VERSION);
$httpClientConfig = $this->config->getHttpClientConfig();
if (array_key_exists('verify', $httpClientConfig)
&& $httpClientConfig['verify'] === false)
{
$client->setSslVerification(false, false);
}
return $client;
} | php | private function resolveClient($client)
{
$client = ! empty($client)
? $client
: new Client();
$client->setBaseUrl(Properties::baseUrl())
->setUserAgent('Double Opt-in php-api/' . self::VERSION);
$httpClientConfig = $this->config->getHttpClientConfig();
if (array_key_exists('verify', $httpClientConfig)
&& $httpClientConfig['verify'] === false)
{
$client->setSslVerification(false, false);
}
return $client;
} | [
"private",
"function",
"resolveClient",
"(",
"$",
"client",
")",
"{",
"$",
"client",
"=",
"!",
"empty",
"(",
"$",
"client",
")",
"?",
"$",
"client",
":",
"new",
"Client",
"(",
")",
";",
"$",
"client",
"->",
"setBaseUrl",
"(",
"Properties",
"::",
"baseUrl",
"(",
")",
")",
"->",
"setUserAgent",
"(",
"'Double Opt-in php-api/'",
".",
"self",
"::",
"VERSION",
")",
";",
"$",
"httpClientConfig",
"=",
"$",
"this",
"->",
"config",
"->",
"getHttpClientConfig",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'verify'",
",",
"$",
"httpClientConfig",
")",
"&&",
"$",
"httpClientConfig",
"[",
"'verify'",
"]",
"===",
"false",
")",
"{",
"$",
"client",
"->",
"setSslVerification",
"(",
"false",
",",
"false",
")",
";",
"}",
"return",
"$",
"client",
";",
"}"
] | resolves a http client
@param ClientInterface|null $client
@return ClientInterface|Client | [
"resolves",
"a",
"http",
"client"
] | train | https://github.com/Double-Opt-in/php-client-api/blob/2f17da58ec20a408bbd55b2cdd053bc689f995f4/src/Client/Api.php#L84-L101 |
Double-Opt-in/php-client-api | src/Client/Api.php | Api.setupOAuth2Plugin | private function setupOAuth2Plugin()
{
$oauth2AuthorizationClient = $this->resolveClient(null);
$oauth2AuthorizationClient->setBaseUrl(Properties::authorizationUrl());
$clientCredentials = new ClientCredentials($oauth2AuthorizationClient, $this->config->toArray());
$oauth2Plugin = new OAuth2Plugin($clientCredentials);
$oauth2Plugin->setCache($this->config->getAccessTokenCacheFile());
$this->client->addSubscriber($oauth2Plugin);
} | php | private function setupOAuth2Plugin()
{
$oauth2AuthorizationClient = $this->resolveClient(null);
$oauth2AuthorizationClient->setBaseUrl(Properties::authorizationUrl());
$clientCredentials = new ClientCredentials($oauth2AuthorizationClient, $this->config->toArray());
$oauth2Plugin = new OAuth2Plugin($clientCredentials);
$oauth2Plugin->setCache($this->config->getAccessTokenCacheFile());
$this->client->addSubscriber($oauth2Plugin);
} | [
"private",
"function",
"setupOAuth2Plugin",
"(",
")",
"{",
"$",
"oauth2AuthorizationClient",
"=",
"$",
"this",
"->",
"resolveClient",
"(",
"null",
")",
";",
"$",
"oauth2AuthorizationClient",
"->",
"setBaseUrl",
"(",
"Properties",
"::",
"authorizationUrl",
"(",
")",
")",
";",
"$",
"clientCredentials",
"=",
"new",
"ClientCredentials",
"(",
"$",
"oauth2AuthorizationClient",
",",
"$",
"this",
"->",
"config",
"->",
"toArray",
"(",
")",
")",
";",
"$",
"oauth2Plugin",
"=",
"new",
"OAuth2Plugin",
"(",
"$",
"clientCredentials",
")",
";",
"$",
"oauth2Plugin",
"->",
"setCache",
"(",
"$",
"this",
"->",
"config",
"->",
"getAccessTokenCacheFile",
"(",
")",
")",
";",
"$",
"this",
"->",
"client",
"->",
"addSubscriber",
"(",
"$",
"oauth2Plugin",
")",
";",
"}"
] | setting up the oauth2 plugin for authorizing the requests | [
"setting",
"up",
"the",
"oauth2",
"plugin",
"for",
"authorizing",
"the",
"requests"
] | train | https://github.com/Double-Opt-in/php-client-api/blob/2f17da58ec20a408bbd55b2cdd053bc689f995f4/src/Client/Api.php#L106-L116 |
Double-Opt-in/php-client-api | src/Client/Api.php | Api.send | public function send(ClientCommand $command)
{
$request = $this->client->createRequest(
$command->method(),
$this->client->getBaseUrl() . $command->uri($this->cryptographyEngine),
$this->headers($command->apiVersion(), $command->format(), $command->headers()),
$command->body($this->cryptographyEngine),
$this->config->getHttpClientConfig()
);
try {
$response = $request->send();
} catch (ClientErrorResponseException $exception) {
$response = $exception->getResponse();
} catch (ServerErrorResponseException $exception) {
$response = $exception->getResponse();
}
return $command->response($response, $this->cryptographyEngine);
} | php | public function send(ClientCommand $command)
{
$request = $this->client->createRequest(
$command->method(),
$this->client->getBaseUrl() . $command->uri($this->cryptographyEngine),
$this->headers($command->apiVersion(), $command->format(), $command->headers()),
$command->body($this->cryptographyEngine),
$this->config->getHttpClientConfig()
);
try {
$response = $request->send();
} catch (ClientErrorResponseException $exception) {
$response = $exception->getResponse();
} catch (ServerErrorResponseException $exception) {
$response = $exception->getResponse();
}
return $command->response($response, $this->cryptographyEngine);
} | [
"public",
"function",
"send",
"(",
"ClientCommand",
"$",
"command",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"client",
"->",
"createRequest",
"(",
"$",
"command",
"->",
"method",
"(",
")",
",",
"$",
"this",
"->",
"client",
"->",
"getBaseUrl",
"(",
")",
".",
"$",
"command",
"->",
"uri",
"(",
"$",
"this",
"->",
"cryptographyEngine",
")",
",",
"$",
"this",
"->",
"headers",
"(",
"$",
"command",
"->",
"apiVersion",
"(",
")",
",",
"$",
"command",
"->",
"format",
"(",
")",
",",
"$",
"command",
"->",
"headers",
"(",
")",
")",
",",
"$",
"command",
"->",
"body",
"(",
"$",
"this",
"->",
"cryptographyEngine",
")",
",",
"$",
"this",
"->",
"config",
"->",
"getHttpClientConfig",
"(",
")",
")",
";",
"try",
"{",
"$",
"response",
"=",
"$",
"request",
"->",
"send",
"(",
")",
";",
"}",
"catch",
"(",
"ClientErrorResponseException",
"$",
"exception",
")",
"{",
"$",
"response",
"=",
"$",
"exception",
"->",
"getResponse",
"(",
")",
";",
"}",
"catch",
"(",
"ServerErrorResponseException",
"$",
"exception",
")",
"{",
"$",
"response",
"=",
"$",
"exception",
"->",
"getResponse",
"(",
")",
";",
"}",
"return",
"$",
"command",
"->",
"response",
"(",
"$",
"response",
",",
"$",
"this",
"->",
"cryptographyEngine",
")",
";",
"}"
] | get all actions
@param ClientCommand $command
@return Response|CommandResponse|DecryptedCommandResponse|StatusResponse | [
"get",
"all",
"actions"
] | train | https://github.com/Double-Opt-in/php-client-api/blob/2f17da58ec20a408bbd55b2cdd053bc689f995f4/src/Client/Api.php#L125-L144 |
lode/fem | src/login_token.php | login_token.get_by_token | public static function get_by_token($token) {
$mysql = bootstrap::get_library('mysql');
$sql = "SELECT * FROM `login_tokens` WHERE `code` = '%s';";
$login = $mysql::select('row', $sql, $token);
if (empty($login)) {
return false;
}
return new static($login['id']);
} | php | public static function get_by_token($token) {
$mysql = bootstrap::get_library('mysql');
$sql = "SELECT * FROM `login_tokens` WHERE `code` = '%s';";
$login = $mysql::select('row', $sql, $token);
if (empty($login)) {
return false;
}
return new static($login['id']);
} | [
"public",
"static",
"function",
"get_by_token",
"(",
"$",
"token",
")",
"{",
"$",
"mysql",
"=",
"bootstrap",
"::",
"get_library",
"(",
"'mysql'",
")",
";",
"$",
"sql",
"=",
"\"SELECT * FROM `login_tokens` WHERE `code` = '%s';\"",
";",
"$",
"login",
"=",
"$",
"mysql",
"::",
"select",
"(",
"'row'",
",",
"$",
"sql",
",",
"$",
"token",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"login",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"new",
"static",
"(",
"$",
"login",
"[",
"'id'",
"]",
")",
";",
"}"
] | checks whether the given token match one on file
@param string $token
@return $this|boolean false when the token is not found | [
"checks",
"whether",
"the",
"given",
"token",
"match",
"one",
"on",
"file"
] | train | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/login_token.php#L80-L90 |
lode/fem | src/login_token.php | login_token.is_valid | public function is_valid($mark_as_used=true) {
if (!empty($this->data['used'])) {
return false;
}
if (time() > $this->data['expire_at']) {
return false;
}
if ($mark_as_used) {
$this->mark_as_used();
}
return true;
} | php | public function is_valid($mark_as_used=true) {
if (!empty($this->data['used'])) {
return false;
}
if (time() > $this->data['expire_at']) {
return false;
}
if ($mark_as_used) {
$this->mark_as_used();
}
return true;
} | [
"public",
"function",
"is_valid",
"(",
"$",
"mark_as_used",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"data",
"[",
"'used'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"time",
"(",
")",
">",
"$",
"this",
"->",
"data",
"[",
"'expire_at'",
"]",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"mark_as_used",
")",
"{",
"$",
"this",
"->",
"mark_as_used",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] | check if the token is still valid
also marks the token as used to prevent more people getting in
@param boolean $mark_as_used set to false to validate w/o user action
@return boolean | [
"check",
"if",
"the",
"token",
"is",
"still",
"valid",
"also",
"marks",
"the",
"token",
"as",
"used",
"to",
"prevent",
"more",
"people",
"getting",
"in"
] | train | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/login_token.php#L99-L112 |
lode/fem | src/login_token.php | login_token.mark_as_used | public function mark_as_used() {
$mysql = bootstrap::get_library('mysql');
$sql = "UPDATE `login_tokens` SET `used` = 1, `last_used_at` = %d WHERE `id` = %d;";
$binds = [time(), $this->data['id']];
$mysql::query($sql, $binds);
} | php | public function mark_as_used() {
$mysql = bootstrap::get_library('mysql');
$sql = "UPDATE `login_tokens` SET `used` = 1, `last_used_at` = %d WHERE `id` = %d;";
$binds = [time(), $this->data['id']];
$mysql::query($sql, $binds);
} | [
"public",
"function",
"mark_as_used",
"(",
")",
"{",
"$",
"mysql",
"=",
"bootstrap",
"::",
"get_library",
"(",
"'mysql'",
")",
";",
"$",
"sql",
"=",
"\"UPDATE `login_tokens` SET `used` = 1, `last_used_at` = %d WHERE `id` = %d;\"",
";",
"$",
"binds",
"=",
"[",
"time",
"(",
")",
",",
"$",
"this",
"->",
"data",
"[",
"'id'",
"]",
"]",
";",
"$",
"mysql",
"::",
"query",
"(",
"$",
"sql",
",",
"$",
"binds",
")",
";",
"}"
] | prevents a token to be re-used
is usually called directly by ::is_valid()
@return void | [
"prevents",
"a",
"token",
"to",
"be",
"re",
"-",
"used",
"is",
"usually",
"called",
"directly",
"by",
"::",
"is_valid",
"()"
] | train | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/login_token.php#L129-L135 |
lode/fem | src/login_token.php | login_token.create | public static function create($user_id) {
$text = bootstrap::get_library('text');
$mysql = bootstrap::get_library('mysql');
$new_token = $text::generate_token(self::TOKEN_LENGTH);
$expiration = (time() + self::EXPIRATION);
$sql = "INSERT INTO `login_tokens` SET `code` = '%s', `user_id` = %d, `expire_at` = %d;";
$binds = [$new_token, $user_id, $expiration];
$mysql::query($sql, $binds);
return new static($mysql::$insert_id);
} | php | public static function create($user_id) {
$text = bootstrap::get_library('text');
$mysql = bootstrap::get_library('mysql');
$new_token = $text::generate_token(self::TOKEN_LENGTH);
$expiration = (time() + self::EXPIRATION);
$sql = "INSERT INTO `login_tokens` SET `code` = '%s', `user_id` = %d, `expire_at` = %d;";
$binds = [$new_token, $user_id, $expiration];
$mysql::query($sql, $binds);
return new static($mysql::$insert_id);
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"user_id",
")",
"{",
"$",
"text",
"=",
"bootstrap",
"::",
"get_library",
"(",
"'text'",
")",
";",
"$",
"mysql",
"=",
"bootstrap",
"::",
"get_library",
"(",
"'mysql'",
")",
";",
"$",
"new_token",
"=",
"$",
"text",
"::",
"generate_token",
"(",
"self",
"::",
"TOKEN_LENGTH",
")",
";",
"$",
"expiration",
"=",
"(",
"time",
"(",
")",
"+",
"self",
"::",
"EXPIRATION",
")",
";",
"$",
"sql",
"=",
"\"INSERT INTO `login_tokens` SET `code` = '%s', `user_id` = %d, `expire_at` = %d;\"",
";",
"$",
"binds",
"=",
"[",
"$",
"new_token",
",",
"$",
"user_id",
",",
"$",
"expiration",
"]",
";",
"$",
"mysql",
"::",
"query",
"(",
"$",
"sql",
",",
"$",
"binds",
")",
";",
"return",
"new",
"static",
"(",
"$",
"mysql",
"::",
"$",
"insert_id",
")",
";",
"}"
] | create a new temporary login token
@param int $user_id
@return $this | [
"create",
"a",
"new",
"temporary",
"login",
"token"
] | train | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/login_token.php#L143-L155 |
2amigos/yiifoundation | helpers/Icon.php | Icon.icon | public static function icon($icon, $htmlOptions = array(), $tagName = 'i')
{
if (is_string($icon)) {
if (strpos($icon, 'foundicon-') === false) {
$icon = 'foundicon-' . implode(' foundicon-', array_unique(explode(' ', $icon)));
}
ArrayHelper::addValue('class', $icon, $htmlOptions);
return \CHtml::openTag($tagName, $htmlOptions) . \CHtml::closeTag($tagName);
}
return '';
} | php | public static function icon($icon, $htmlOptions = array(), $tagName = 'i')
{
if (is_string($icon)) {
if (strpos($icon, 'foundicon-') === false) {
$icon = 'foundicon-' . implode(' foundicon-', array_unique(explode(' ', $icon)));
}
ArrayHelper::addValue('class', $icon, $htmlOptions);
return \CHtml::openTag($tagName, $htmlOptions) . \CHtml::closeTag($tagName);
}
return '';
} | [
"public",
"static",
"function",
"icon",
"(",
"$",
"icon",
",",
"$",
"htmlOptions",
"=",
"array",
"(",
")",
",",
"$",
"tagName",
"=",
"'i'",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"icon",
")",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"icon",
",",
"'foundicon-'",
")",
"===",
"false",
")",
"{",
"$",
"icon",
"=",
"'foundicon-'",
".",
"implode",
"(",
"' foundicon-'",
",",
"array_unique",
"(",
"explode",
"(",
"' '",
",",
"$",
"icon",
")",
")",
")",
";",
"}",
"ArrayHelper",
"::",
"addValue",
"(",
"'class'",
",",
"$",
"icon",
",",
"$",
"htmlOptions",
")",
";",
"return",
"\\",
"CHtml",
"::",
"openTag",
"(",
"$",
"tagName",
",",
"$",
"htmlOptions",
")",
".",
"\\",
"CHtml",
"::",
"closeTag",
"(",
"$",
"tagName",
")",
";",
"}",
"return",
"''",
";",
"}"
] | Generates an icon.
@param string $icon the icon type.
@param array $htmlOptions additional HTML attributes.
@param string $tagName the icon HTML tag.
@return string the generated icon. | [
"Generates",
"an",
"icon",
"."
] | train | https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/helpers/Icon.php#L28-L38 |
2amigos/yiifoundation | helpers/Icon.php | Icon.registerIconFontSet | public static function registerIconFontSet($fontName, $forceCopyAssets = false)
{
if (!in_array($fontName, static::getAvailableIconFontSets())) {
return false;
}
$fontPath = \Yii::getPathOfAlias('foundation.fonts.foundation_icons_' . $fontName);
$fontUrl = \Yii::app()->assetManager->publish($fontPath, true, -1, $forceCopyAssets);
\Yii::app()->clientScript->registerCssFile($fontUrl . "/stylesheets/{$fontName}_foundicons.css");
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7.0')) {
\Yii::app()->clientScript->registerCssFile($fontUrl . "/stylesheets/{$fontName}_foundicons_ie7.css");
}
} | php | public static function registerIconFontSet($fontName, $forceCopyAssets = false)
{
if (!in_array($fontName, static::getAvailableIconFontSets())) {
return false;
}
$fontPath = \Yii::getPathOfAlias('foundation.fonts.foundation_icons_' . $fontName);
$fontUrl = \Yii::app()->assetManager->publish($fontPath, true, -1, $forceCopyAssets);
\Yii::app()->clientScript->registerCssFile($fontUrl . "/stylesheets/{$fontName}_foundicons.css");
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7.0')) {
\Yii::app()->clientScript->registerCssFile($fontUrl . "/stylesheets/{$fontName}_foundicons_ie7.css");
}
} | [
"public",
"static",
"function",
"registerIconFontSet",
"(",
"$",
"fontName",
",",
"$",
"forceCopyAssets",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"fontName",
",",
"static",
"::",
"getAvailableIconFontSets",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"fontPath",
"=",
"\\",
"Yii",
"::",
"getPathOfAlias",
"(",
"'foundation.fonts.foundation_icons_'",
".",
"$",
"fontName",
")",
";",
"$",
"fontUrl",
"=",
"\\",
"Yii",
"::",
"app",
"(",
")",
"->",
"assetManager",
"->",
"publish",
"(",
"$",
"fontPath",
",",
"true",
",",
"-",
"1",
",",
"$",
"forceCopyAssets",
")",
";",
"\\",
"Yii",
"::",
"app",
"(",
")",
"->",
"clientScript",
"->",
"registerCssFile",
"(",
"$",
"fontUrl",
".",
"\"/stylesheets/{$fontName}_foundicons.css\"",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"_SERVER",
"[",
"'HTTP_USER_AGENT'",
"]",
",",
"'MSIE 7.0'",
")",
")",
"{",
"\\",
"Yii",
"::",
"app",
"(",
")",
"->",
"clientScript",
"->",
"registerCssFile",
"(",
"$",
"fontUrl",
".",
"\"/stylesheets/{$fontName}_foundicons_ie7.css\"",
")",
";",
"}",
"}"
] | Registers a specific Icon Set. They are registered individually
@param $fontName
@param $forceCopyAssets
@return bool | [
"Registers",
"a",
"specific",
"Icon",
"Set",
".",
"They",
"are",
"registered",
"individually"
] | train | https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/helpers/Icon.php#L46-L60 |
phossa2/config | src/Config/Loader/ConfigFileLoader.php | ConfigFileLoader.load | public function load(
/*# string */ $group,
/*# string */ $environment = ''
)/*# : array */ {
$data = [];
$env = $environment ?: $this->environment;
foreach ($this->globFiles($group, $env) as $file) {
$grp = basename($file, '.' . $this->file_type);
if (!isset($data[$grp])) {
$data[$grp] = [];
}
$data[$grp] = array_replace_recursive(
$data[$grp],
(array) Reader::readFile($file)
);
}
return $data;
} | php | public function load(
/*# string */ $group,
/*# string */ $environment = ''
)/*# : array */ {
$data = [];
$env = $environment ?: $this->environment;
foreach ($this->globFiles($group, $env) as $file) {
$grp = basename($file, '.' . $this->file_type);
if (!isset($data[$grp])) {
$data[$grp] = [];
}
$data[$grp] = array_replace_recursive(
$data[$grp],
(array) Reader::readFile($file)
);
}
return $data;
} | [
"public",
"function",
"load",
"(",
"/*# string */",
"$",
"group",
",",
"/*# string */",
"$",
"environment",
"=",
"''",
")",
"/*# : array */",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"$",
"env",
"=",
"$",
"environment",
"?",
":",
"$",
"this",
"->",
"environment",
";",
"foreach",
"(",
"$",
"this",
"->",
"globFiles",
"(",
"$",
"group",
",",
"$",
"env",
")",
"as",
"$",
"file",
")",
"{",
"$",
"grp",
"=",
"basename",
"(",
"$",
"file",
",",
"'.'",
".",
"$",
"this",
"->",
"file_type",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
"grp",
"]",
")",
")",
"{",
"$",
"data",
"[",
"$",
"grp",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"data",
"[",
"$",
"grp",
"]",
"=",
"array_replace_recursive",
"(",
"$",
"data",
"[",
"$",
"grp",
"]",
",",
"(",
"array",
")",
"Reader",
"::",
"readFile",
"(",
"$",
"file",
")",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/phossa2/config/blob/7c046fd2c97633b69545b4745d8bffe28e19b1df/src/Config/Loader/ConfigFileLoader.php#L91-L109 |
phossa2/config | src/Config/Loader/ConfigFileLoader.php | ConfigFileLoader.setRootDir | public function setRootDir(/*# string */ $rootDir)
{
$dir = realpath($rootDir);
if (false === $dir) {
throw new InvalidArgumentException(
Message::get(Message::CONFIG_ROOT_INVALID, $rootDir),
Message::CONFIG_ROOT_INVALID
);
}
$this->root_dir = $dir . \DIRECTORY_SEPARATOR;
return $this;
} | php | public function setRootDir(/*# string */ $rootDir)
{
$dir = realpath($rootDir);
if (false === $dir) {
throw new InvalidArgumentException(
Message::get(Message::CONFIG_ROOT_INVALID, $rootDir),
Message::CONFIG_ROOT_INVALID
);
}
$this->root_dir = $dir . \DIRECTORY_SEPARATOR;
return $this;
} | [
"public",
"function",
"setRootDir",
"(",
"/*# string */",
"$",
"rootDir",
")",
"{",
"$",
"dir",
"=",
"realpath",
"(",
"$",
"rootDir",
")",
";",
"if",
"(",
"false",
"===",
"$",
"dir",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"Message",
"::",
"get",
"(",
"Message",
"::",
"CONFIG_ROOT_INVALID",
",",
"$",
"rootDir",
")",
",",
"Message",
"::",
"CONFIG_ROOT_INVALID",
")",
";",
"}",
"$",
"this",
"->",
"root_dir",
"=",
"$",
"dir",
".",
"\\",
"DIRECTORY_SEPARATOR",
";",
"return",
"$",
"this",
";",
"}"
] | Set config file root directory
@param string $rootDir
@return $this
@throws InvalidArgumentException if root dir is unknown
@access public
@api | [
"Set",
"config",
"file",
"root",
"directory"
] | train | https://github.com/phossa2/config/blob/7c046fd2c97633b69545b4745d8bffe28e19b1df/src/Config/Loader/ConfigFileLoader.php#L120-L134 |
phossa2/config | src/Config/Loader/ConfigFileLoader.php | ConfigFileLoader.setFileType | public function setFileType(/*# string */ $fileType)
{
if (!Reader::isSupported($fileType)) {
throw new InvalidArgumentException(
Message::get(Message::CONFIG_FILE_TYPE_UNKNOWN, $fileType),
Message::CONFIG_FILE_TYPE_UNKNOWN
);
}
$this->file_type = $fileType;
return $this;
} | php | public function setFileType(/*# string */ $fileType)
{
if (!Reader::isSupported($fileType)) {
throw new InvalidArgumentException(
Message::get(Message::CONFIG_FILE_TYPE_UNKNOWN, $fileType),
Message::CONFIG_FILE_TYPE_UNKNOWN
);
}
$this->file_type = $fileType;
return $this;
} | [
"public",
"function",
"setFileType",
"(",
"/*# string */",
"$",
"fileType",
")",
"{",
"if",
"(",
"!",
"Reader",
"::",
"isSupported",
"(",
"$",
"fileType",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"Message",
"::",
"get",
"(",
"Message",
"::",
"CONFIG_FILE_TYPE_UNKNOWN",
",",
"$",
"fileType",
")",
",",
"Message",
"::",
"CONFIG_FILE_TYPE_UNKNOWN",
")",
";",
"}",
"$",
"this",
"->",
"file_type",
"=",
"$",
"fileType",
";",
"return",
"$",
"this",
";",
"}"
] | Set config file type
@param string $fileType
@return $this
@throws InvalidArgumentException if unsupported file type
@access public
@api | [
"Set",
"config",
"file",
"type"
] | train | https://github.com/phossa2/config/blob/7c046fd2c97633b69545b4745d8bffe28e19b1df/src/Config/Loader/ConfigFileLoader.php#L145-L156 |
phossa2/config | src/Config/Loader/ConfigFileLoader.php | ConfigFileLoader.globFiles | protected function globFiles(
/*# string */ $group,
/*# string */ $environment
)/*# : array */ {
$files = [];
$group = '' === $group ? '*' : $group;
foreach ($this->getSearchDirs($environment) as $dir) {
$file = $dir . $group . '.' . $this->file_type;
$files = array_merge($files, glob($file));
}
return $files;
} | php | protected function globFiles(
/*# string */ $group,
/*# string */ $environment
)/*# : array */ {
$files = [];
$group = '' === $group ? '*' : $group;
foreach ($this->getSearchDirs($environment) as $dir) {
$file = $dir . $group . '.' . $this->file_type;
$files = array_merge($files, glob($file));
}
return $files;
} | [
"protected",
"function",
"globFiles",
"(",
"/*# string */",
"$",
"group",
",",
"/*# string */",
"$",
"environment",
")",
"/*# : array */",
"{",
"$",
"files",
"=",
"[",
"]",
";",
"$",
"group",
"=",
"''",
"===",
"$",
"group",
"?",
"'*'",
":",
"$",
"group",
";",
"foreach",
"(",
"$",
"this",
"->",
"getSearchDirs",
"(",
"$",
"environment",
")",
"as",
"$",
"dir",
")",
"{",
"$",
"file",
"=",
"$",
"dir",
".",
"$",
"group",
".",
"'.'",
".",
"$",
"this",
"->",
"file_type",
";",
"$",
"files",
"=",
"array_merge",
"(",
"$",
"files",
",",
"glob",
"(",
"$",
"file",
")",
")",
";",
"}",
"return",
"$",
"files",
";",
"}"
] | Returns an array of files to read from
@param string $group
@param string $environment
@return array
@access protected | [
"Returns",
"an",
"array",
"of",
"files",
"to",
"read",
"from"
] | train | https://github.com/phossa2/config/blob/7c046fd2c97633b69545b4745d8bffe28e19b1df/src/Config/Loader/ConfigFileLoader.php#L181-L192 |
phossa2/config | src/Config/Loader/ConfigFileLoader.php | ConfigFileLoader.getSearchDirs | protected function getSearchDirs(/*# string */ $env)/*# : array */
{
if (!isset($this->sub_dirs[$env])) {
$this->sub_dirs[$env] = $this->buildSearchDirs($env);
}
return $this->sub_dirs[$env];
} | php | protected function getSearchDirs(/*# string */ $env)/*# : array */
{
if (!isset($this->sub_dirs[$env])) {
$this->sub_dirs[$env] = $this->buildSearchDirs($env);
}
return $this->sub_dirs[$env];
} | [
"protected",
"function",
"getSearchDirs",
"(",
"/*# string */",
"$",
"env",
")",
"/*# : array */",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"sub_dirs",
"[",
"$",
"env",
"]",
")",
")",
"{",
"$",
"this",
"->",
"sub_dirs",
"[",
"$",
"env",
"]",
"=",
"$",
"this",
"->",
"buildSearchDirs",
"(",
"$",
"env",
")",
";",
"}",
"return",
"$",
"this",
"->",
"sub_dirs",
"[",
"$",
"env",
"]",
";",
"}"
] | Get the search directories
@param string $env
@return array
@access protected | [
"Get",
"the",
"search",
"directories"
] | train | https://github.com/phossa2/config/blob/7c046fd2c97633b69545b4745d8bffe28e19b1df/src/Config/Loader/ConfigFileLoader.php#L201-L207 |
phossa2/config | src/Config/Loader/ConfigFileLoader.php | ConfigFileLoader.buildSearchDirs | protected function buildSearchDirs(/*# string */ $env)/*# : array */
{
$path = $this->root_dir;
$part = preg_split(
'/[\/\\\]/',
trim($env, '/\\'),
0,
\PREG_SPLIT_NO_EMPTY
);
$subdirs = [$path];
foreach ($part as $dir) {
$path .= $dir . \DIRECTORY_SEPARATOR;
if (false === file_exists($path)) {
trigger_error(
Message::get(Message::CONFIG_ENV_UNKNOWN, $env),
\E_USER_WARNING
);
break;
}
$subdirs[] = $path;
}
return $subdirs;
} | php | protected function buildSearchDirs(/*# string */ $env)/*# : array */
{
$path = $this->root_dir;
$part = preg_split(
'/[\/\\\]/',
trim($env, '/\\'),
0,
\PREG_SPLIT_NO_EMPTY
);
$subdirs = [$path];
foreach ($part as $dir) {
$path .= $dir . \DIRECTORY_SEPARATOR;
if (false === file_exists($path)) {
trigger_error(
Message::get(Message::CONFIG_ENV_UNKNOWN, $env),
\E_USER_WARNING
);
break;
}
$subdirs[] = $path;
}
return $subdirs;
} | [
"protected",
"function",
"buildSearchDirs",
"(",
"/*# string */",
"$",
"env",
")",
"/*# : array */",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"root_dir",
";",
"$",
"part",
"=",
"preg_split",
"(",
"'/[\\/\\\\\\]/'",
",",
"trim",
"(",
"$",
"env",
",",
"'/\\\\'",
")",
",",
"0",
",",
"\\",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"$",
"subdirs",
"=",
"[",
"$",
"path",
"]",
";",
"foreach",
"(",
"$",
"part",
"as",
"$",
"dir",
")",
"{",
"$",
"path",
".=",
"$",
"dir",
".",
"\\",
"DIRECTORY_SEPARATOR",
";",
"if",
"(",
"false",
"===",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"trigger_error",
"(",
"Message",
"::",
"get",
"(",
"Message",
"::",
"CONFIG_ENV_UNKNOWN",
",",
"$",
"env",
")",
",",
"\\",
"E_USER_WARNING",
")",
";",
"break",
";",
"}",
"$",
"subdirs",
"[",
"]",
"=",
"$",
"path",
";",
"}",
"return",
"$",
"subdirs",
";",
"}"
] | Build search directories
@param string $env
@return array
@access protected | [
"Build",
"search",
"directories"
] | train | https://github.com/phossa2/config/blob/7c046fd2c97633b69545b4745d8bffe28e19b1df/src/Config/Loader/ConfigFileLoader.php#L216-L238 |
spiral-modules/scaffolder | source/Scaffolder/Declarations/ControllerDeclaration.php | ControllerDeclaration.addAction | public function addAction(string $action): ClassDeclaration\MethodDeclaration
{
$method = $this->method($action . $this->actionPostfix);
return $method->setAccess(ClassDeclaration\MethodDeclaration::ACCESS_PROTECTED);
} | php | public function addAction(string $action): ClassDeclaration\MethodDeclaration
{
$method = $this->method($action . $this->actionPostfix);
return $method->setAccess(ClassDeclaration\MethodDeclaration::ACCESS_PROTECTED);
} | [
"public",
"function",
"addAction",
"(",
"string",
"$",
"action",
")",
":",
"ClassDeclaration",
"\\",
"MethodDeclaration",
"{",
"$",
"method",
"=",
"$",
"this",
"->",
"method",
"(",
"$",
"action",
".",
"$",
"this",
"->",
"actionPostfix",
")",
";",
"return",
"$",
"method",
"->",
"setAccess",
"(",
"ClassDeclaration",
"\\",
"MethodDeclaration",
"::",
"ACCESS_PROTECTED",
")",
";",
"}"
] | @param string $action
@return ClassDeclaration\MethodDeclaration | [
"@param",
"string",
"$action"
] | train | https://github.com/spiral-modules/scaffolder/blob/9be9dd0da6e4b02232db24e797fe5c288afbbddf/source/Scaffolder/Declarations/ControllerDeclaration.php#L47-L52 |
ConnectHolland/tulip-api-client | src/Client.php | Client.getServiceUrl | public function getServiceUrl($serviceName, $action)
{
return sprintf('%s/api/%s/%s/%s', $this->tulipUrl, $this->apiVersion, $serviceName, $action);
} | php | public function getServiceUrl($serviceName, $action)
{
return sprintf('%s/api/%s/%s/%s', $this->tulipUrl, $this->apiVersion, $serviceName, $action);
} | [
"public",
"function",
"getServiceUrl",
"(",
"$",
"serviceName",
",",
"$",
"action",
")",
"{",
"return",
"sprintf",
"(",
"'%s/api/%s/%s/%s'",
",",
"$",
"this",
"->",
"tulipUrl",
",",
"$",
"this",
"->",
"apiVersion",
",",
"$",
"serviceName",
",",
"$",
"action",
")",
";",
"}"
] | Returns the full Tulip API URL for the specified service and action.
@param string $serviceName
@param string $action
@return string | [
"Returns",
"the",
"full",
"Tulip",
"API",
"URL",
"for",
"the",
"specified",
"service",
"and",
"action",
"."
] | train | https://github.com/ConnectHolland/tulip-api-client/blob/641325e2d57c1c272ede7fd8b47d4f2b67b73507/src/Client.php#L85-L88 |
ConnectHolland/tulip-api-client | src/Client.php | Client.callService | public function callService($serviceName, $action, array $parameters = array(), array $files = array())
{
$httpClient = $this->getHTTPClient();
$url = $this->getServiceUrl($serviceName, $action);
$request = new Request('POST', $url, $this->getRequestHeaders($url, $parameters), $this->getRequestBody($parameters, $files));
try {
$response = $httpClient->send($request);
} catch (GuzzleRequestException $exception) {
$response = $exception->getResponse();
}
$this->validateAPIResponseCode($request, $response);
return $response;
} | php | public function callService($serviceName, $action, array $parameters = array(), array $files = array())
{
$httpClient = $this->getHTTPClient();
$url = $this->getServiceUrl($serviceName, $action);
$request = new Request('POST', $url, $this->getRequestHeaders($url, $parameters), $this->getRequestBody($parameters, $files));
try {
$response = $httpClient->send($request);
} catch (GuzzleRequestException $exception) {
$response = $exception->getResponse();
}
$this->validateAPIResponseCode($request, $response);
return $response;
} | [
"public",
"function",
"callService",
"(",
"$",
"serviceName",
",",
"$",
"action",
",",
"array",
"$",
"parameters",
"=",
"array",
"(",
")",
",",
"array",
"$",
"files",
"=",
"array",
"(",
")",
")",
"{",
"$",
"httpClient",
"=",
"$",
"this",
"->",
"getHTTPClient",
"(",
")",
";",
"$",
"url",
"=",
"$",
"this",
"->",
"getServiceUrl",
"(",
"$",
"serviceName",
",",
"$",
"action",
")",
";",
"$",
"request",
"=",
"new",
"Request",
"(",
"'POST'",
",",
"$",
"url",
",",
"$",
"this",
"->",
"getRequestHeaders",
"(",
"$",
"url",
",",
"$",
"parameters",
")",
",",
"$",
"this",
"->",
"getRequestBody",
"(",
"$",
"parameters",
",",
"$",
"files",
")",
")",
";",
"try",
"{",
"$",
"response",
"=",
"$",
"httpClient",
"->",
"send",
"(",
"$",
"request",
")",
";",
"}",
"catch",
"(",
"GuzzleRequestException",
"$",
"exception",
")",
"{",
"$",
"response",
"=",
"$",
"exception",
"->",
"getResponse",
"(",
")",
";",
"}",
"$",
"this",
"->",
"validateAPIResponseCode",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Call a Tulip API service.
@param string $serviceName
@param string $action
@param array $parameters
@param array $files
@return ResponseInterface
@throws RequestException | [
"Call",
"a",
"Tulip",
"API",
"service",
"."
] | train | https://github.com/ConnectHolland/tulip-api-client/blob/641325e2d57c1c272ede7fd8b47d4f2b67b73507/src/Client.php#L112-L128 |
ConnectHolland/tulip-api-client | src/Client.php | Client.getHTTPClient | private function getHTTPClient()
{
if ($this->httpClient instanceof ClientInterface === false) {
$this->httpClient = new HTTPClient();
}
return $this->httpClient;
} | php | private function getHTTPClient()
{
if ($this->httpClient instanceof ClientInterface === false) {
$this->httpClient = new HTTPClient();
}
return $this->httpClient;
} | [
"private",
"function",
"getHTTPClient",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"httpClient",
"instanceof",
"ClientInterface",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"httpClient",
"=",
"new",
"HTTPClient",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"httpClient",
";",
"}"
] | Returns a ClientInterface instance.
@return ClientInterface | [
"Returns",
"a",
"ClientInterface",
"instance",
"."
] | train | https://github.com/ConnectHolland/tulip-api-client/blob/641325e2d57c1c272ede7fd8b47d4f2b67b73507/src/Client.php#L135-L142 |
ConnectHolland/tulip-api-client | src/Client.php | Client.getRequestHeaders | private function getRequestHeaders($url, array $parameters)
{
$headers = array();
if (isset($this->clientId) && isset($this->sharedSecret)) {
$objectIdentifier = null;
if ($this->apiVersion === '1.1' && isset($parameters['id'])) {
$objectIdentifier = $parameters['id'];
} elseif ($this->apiVersion === '1.0' && isset($parameters['api_id'])) {
$objectIdentifier = $parameters['api_id'];
}
$headers['X-Tulip-Client-ID'] = $this->clientId;
$headers['X-Tulip-Client-Authentication'] = hash_hmac('sha256', $this->clientId.$url.$objectIdentifier, $this->sharedSecret);
}
return $headers;
} | php | private function getRequestHeaders($url, array $parameters)
{
$headers = array();
if (isset($this->clientId) && isset($this->sharedSecret)) {
$objectIdentifier = null;
if ($this->apiVersion === '1.1' && isset($parameters['id'])) {
$objectIdentifier = $parameters['id'];
} elseif ($this->apiVersion === '1.0' && isset($parameters['api_id'])) {
$objectIdentifier = $parameters['api_id'];
}
$headers['X-Tulip-Client-ID'] = $this->clientId;
$headers['X-Tulip-Client-Authentication'] = hash_hmac('sha256', $this->clientId.$url.$objectIdentifier, $this->sharedSecret);
}
return $headers;
} | [
"private",
"function",
"getRequestHeaders",
"(",
"$",
"url",
",",
"array",
"$",
"parameters",
")",
"{",
"$",
"headers",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"clientId",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"sharedSecret",
")",
")",
"{",
"$",
"objectIdentifier",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"apiVersion",
"===",
"'1.1'",
"&&",
"isset",
"(",
"$",
"parameters",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"objectIdentifier",
"=",
"$",
"parameters",
"[",
"'id'",
"]",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"apiVersion",
"===",
"'1.0'",
"&&",
"isset",
"(",
"$",
"parameters",
"[",
"'api_id'",
"]",
")",
")",
"{",
"$",
"objectIdentifier",
"=",
"$",
"parameters",
"[",
"'api_id'",
"]",
";",
"}",
"$",
"headers",
"[",
"'X-Tulip-Client-ID'",
"]",
"=",
"$",
"this",
"->",
"clientId",
";",
"$",
"headers",
"[",
"'X-Tulip-Client-Authentication'",
"]",
"=",
"hash_hmac",
"(",
"'sha256'",
",",
"$",
"this",
"->",
"clientId",
".",
"$",
"url",
".",
"$",
"objectIdentifier",
",",
"$",
"this",
"->",
"sharedSecret",
")",
";",
"}",
"return",
"$",
"headers",
";",
"}"
] | Returns the request authentication headers when a client ID and shared secret are provided.
@param string $url
@param array $parameters
@return array | [
"Returns",
"the",
"request",
"authentication",
"headers",
"when",
"a",
"client",
"ID",
"and",
"shared",
"secret",
"are",
"provided",
"."
] | train | https://github.com/ConnectHolland/tulip-api-client/blob/641325e2d57c1c272ede7fd8b47d4f2b67b73507/src/Client.php#L152-L169 |
ConnectHolland/tulip-api-client | src/Client.php | Client.getRequestBody | private function getRequestBody(array $parameters, array $files)
{
$body = array();
foreach ($parameters as $parameterName => $parameterValue) {
if (is_scalar($parameterValue) || (is_null($parameterValue) && $parameterName !== 'id')) {
$body[] = array(
'name' => $parameterName,
'contents' => strval($parameterValue),
);
}
}
foreach ($files as $parameterName => $fileResource) {
if (is_resource($fileResource)) {
$metaData = stream_get_meta_data($fileResource);
$body[] = array(
'name' => $parameterName,
'contents' => $fileResource,
'filename' => basename($metaData['uri']),
);
}
}
return new MultipartStream($body);
} | php | private function getRequestBody(array $parameters, array $files)
{
$body = array();
foreach ($parameters as $parameterName => $parameterValue) {
if (is_scalar($parameterValue) || (is_null($parameterValue) && $parameterName !== 'id')) {
$body[] = array(
'name' => $parameterName,
'contents' => strval($parameterValue),
);
}
}
foreach ($files as $parameterName => $fileResource) {
if (is_resource($fileResource)) {
$metaData = stream_get_meta_data($fileResource);
$body[] = array(
'name' => $parameterName,
'contents' => $fileResource,
'filename' => basename($metaData['uri']),
);
}
}
return new MultipartStream($body);
} | [
"private",
"function",
"getRequestBody",
"(",
"array",
"$",
"parameters",
",",
"array",
"$",
"files",
")",
"{",
"$",
"body",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"parameterName",
"=>",
"$",
"parameterValue",
")",
"{",
"if",
"(",
"is_scalar",
"(",
"$",
"parameterValue",
")",
"||",
"(",
"is_null",
"(",
"$",
"parameterValue",
")",
"&&",
"$",
"parameterName",
"!==",
"'id'",
")",
")",
"{",
"$",
"body",
"[",
"]",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"parameterName",
",",
"'contents'",
"=>",
"strval",
"(",
"$",
"parameterValue",
")",
",",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"files",
"as",
"$",
"parameterName",
"=>",
"$",
"fileResource",
")",
"{",
"if",
"(",
"is_resource",
"(",
"$",
"fileResource",
")",
")",
"{",
"$",
"metaData",
"=",
"stream_get_meta_data",
"(",
"$",
"fileResource",
")",
";",
"$",
"body",
"[",
"]",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"parameterName",
",",
"'contents'",
"=>",
"$",
"fileResource",
",",
"'filename'",
"=>",
"basename",
"(",
"$",
"metaData",
"[",
"'uri'",
"]",
")",
",",
")",
";",
"}",
"}",
"return",
"new",
"MultipartStream",
"(",
"$",
"body",
")",
";",
"}"
] | Returns the multipart request body with the parameters and files.
@param array $parameters
@param array $files
@return MultipartStream | [
"Returns",
"the",
"multipart",
"request",
"body",
"with",
"the",
"parameters",
"and",
"files",
"."
] | train | https://github.com/ConnectHolland/tulip-api-client/blob/641325e2d57c1c272ede7fd8b47d4f2b67b73507/src/Client.php#L179-L204 |
ConnectHolland/tulip-api-client | src/Client.php | Client.validateAPIResponseCode | private function validateAPIResponseCode(RequestInterface $request, ResponseInterface $response)
{
$responseParser = new ResponseParser($response);
switch ($responseParser->getResponseCode()) {
case ResponseCodes::SUCCESS:
break;
case ResponseCodes::NOT_AUTHORIZED:
throw new NotAuthorizedException($responseParser->getErrorMessage(), $request, $response);
case ResponseCodes::UNKNOWN_SERVICE:
throw new UnknownServiceException($responseParser->getErrorMessage(), $request, $response);
case ResponseCodes::PARAMETERS_REQUIRED:
throw new ParametersRequiredException($responseParser->getErrorMessage(), $request, $response);
case ResponseCodes::NON_EXISTING_OBJECT:
throw new NonExistingObjectException($responseParser->getErrorMessage(), $request, $response);
case ResponseCodes::UNKNOWN_ERROR:
default:
throw new UnknownErrorException($responseParser->getErrorMessage(), $request, $response);
}
} | php | private function validateAPIResponseCode(RequestInterface $request, ResponseInterface $response)
{
$responseParser = new ResponseParser($response);
switch ($responseParser->getResponseCode()) {
case ResponseCodes::SUCCESS:
break;
case ResponseCodes::NOT_AUTHORIZED:
throw new NotAuthorizedException($responseParser->getErrorMessage(), $request, $response);
case ResponseCodes::UNKNOWN_SERVICE:
throw new UnknownServiceException($responseParser->getErrorMessage(), $request, $response);
case ResponseCodes::PARAMETERS_REQUIRED:
throw new ParametersRequiredException($responseParser->getErrorMessage(), $request, $response);
case ResponseCodes::NON_EXISTING_OBJECT:
throw new NonExistingObjectException($responseParser->getErrorMessage(), $request, $response);
case ResponseCodes::UNKNOWN_ERROR:
default:
throw new UnknownErrorException($responseParser->getErrorMessage(), $request, $response);
}
} | [
"private",
"function",
"validateAPIResponseCode",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"responseParser",
"=",
"new",
"ResponseParser",
"(",
"$",
"response",
")",
";",
"switch",
"(",
"$",
"responseParser",
"->",
"getResponseCode",
"(",
")",
")",
"{",
"case",
"ResponseCodes",
"::",
"SUCCESS",
":",
"break",
";",
"case",
"ResponseCodes",
"::",
"NOT_AUTHORIZED",
":",
"throw",
"new",
"NotAuthorizedException",
"(",
"$",
"responseParser",
"->",
"getErrorMessage",
"(",
")",
",",
"$",
"request",
",",
"$",
"response",
")",
";",
"case",
"ResponseCodes",
"::",
"UNKNOWN_SERVICE",
":",
"throw",
"new",
"UnknownServiceException",
"(",
"$",
"responseParser",
"->",
"getErrorMessage",
"(",
")",
",",
"$",
"request",
",",
"$",
"response",
")",
";",
"case",
"ResponseCodes",
"::",
"PARAMETERS_REQUIRED",
":",
"throw",
"new",
"ParametersRequiredException",
"(",
"$",
"responseParser",
"->",
"getErrorMessage",
"(",
")",
",",
"$",
"request",
",",
"$",
"response",
")",
";",
"case",
"ResponseCodes",
"::",
"NON_EXISTING_OBJECT",
":",
"throw",
"new",
"NonExistingObjectException",
"(",
"$",
"responseParser",
"->",
"getErrorMessage",
"(",
")",
",",
"$",
"request",
",",
"$",
"response",
")",
";",
"case",
"ResponseCodes",
"::",
"UNKNOWN_ERROR",
":",
"default",
":",
"throw",
"new",
"UnknownErrorException",
"(",
"$",
"responseParser",
"->",
"getErrorMessage",
"(",
")",
",",
"$",
"request",
",",
"$",
"response",
")",
";",
"}",
"}"
] | Validates the Tulip API response code.
@param RequestInterface $request
@param ResponseInterface $response
@throws NotAuthorizedException when not authenticated / authorized correctly.
@throws UnknownServiceException when the called API service is not found within the Tulip API.
@throws ParametersRequiredException when the required parameters for the service / action were not provided or incorrect.
@throws NonExistingObjectException when a requested object was not found.
@throws UnknownErrorException when an error occurs within the Tulip API. | [
"Validates",
"the",
"Tulip",
"API",
"response",
"code",
"."
] | train | https://github.com/ConnectHolland/tulip-api-client/blob/641325e2d57c1c272ede7fd8b47d4f2b67b73507/src/Client.php#L218-L236 |
webforge-labs/psc-cms | lib/Psc/Data/Set.php | Set.get | public function get($field) {
// wir machen hier erstmal nicht so performant immer einen meta-check
$this->meta->getFieldType($field); // throws FieldNotDefinedException
return $this->fields->get($field, NULL, NULL); // returned immer NULL wenn nicht gesetzt
} | php | public function get($field) {
// wir machen hier erstmal nicht so performant immer einen meta-check
$this->meta->getFieldType($field); // throws FieldNotDefinedException
return $this->fields->get($field, NULL, NULL); // returned immer NULL wenn nicht gesetzt
} | [
"public",
"function",
"get",
"(",
"$",
"field",
")",
"{",
"// wir machen hier erstmal nicht so performant immer einen meta-check",
"$",
"this",
"->",
"meta",
"->",
"getFieldType",
"(",
"$",
"field",
")",
";",
"// throws FieldNotDefinedException",
"return",
"$",
"this",
"->",
"fields",
"->",
"get",
"(",
"$",
"field",
",",
"NULL",
",",
"NULL",
")",
";",
"// returned immer NULL wenn nicht gesetzt",
"}"
] | Gibt die Daten für das Feld zurück
ist das Feld in Meta definiert, aber keine Daten gesetzt worden wird NULL zurückgegeben
@param array|string wenn string dann ebenen mit . getrennt
@return mixed|NULL
@throws FieldNotDefinedException | [
"Gibt",
"die",
"Daten",
"für",
"das",
"Feld",
"zurück"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Data/Set.php#L43-L48 |
webforge-labs/psc-cms | lib/Psc/Data/Set.php | Set.setFieldsFromArray | public function setFieldsFromArray(Array $fields) {
foreach ($fields as $field => $value) {
$this->set($field, $value);
}
return $this;
} | php | public function setFieldsFromArray(Array $fields) {
foreach ($fields as $field => $value) {
$this->set($field, $value);
}
return $this;
} | [
"public",
"function",
"setFieldsFromArray",
"(",
"Array",
"$",
"fields",
")",
"{",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"$",
"field",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Setzt mehrere Felder aus einem Array
die Felder die als Schlüssel angegeben werden, müssen alle als Meta existieren
@param array $fields Schlüssel sind mit . getrennte strings Werte sind die Werte der Felder | [
"Setzt",
"mehrere",
"Felder",
"aus",
"einem",
"Array"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Data/Set.php#L112-L117 |
webforge-labs/psc-cms | lib/Psc/Data/Set.php | Set.getWalkableFields | public function getWalkableFields() {
$fields = array();
// hier so umständlich, weil meta->getTypes() uns die fields "geflattet" zurückgibt (und das wollen wir)
foreach ($this->meta->getTypes() as $field => $type) {
$fields[$field] = $this->get($field);
}
return $fields;
} | php | public function getWalkableFields() {
$fields = array();
// hier so umständlich, weil meta->getTypes() uns die fields "geflattet" zurückgibt (und das wollen wir)
foreach ($this->meta->getTypes() as $field => $type) {
$fields[$field] = $this->get($field);
}
return $fields;
} | [
"public",
"function",
"getWalkableFields",
"(",
")",
"{",
"$",
"fields",
"=",
"array",
"(",
")",
";",
"// hier so umständlich, weil meta->getTypes() uns die fields \"geflattet\" zurückgibt (und das wollen wir)",
"foreach",
"(",
"$",
"this",
"->",
"meta",
"->",
"getTypes",
"(",
")",
"as",
"$",
"field",
"=>",
"$",
"type",
")",
"{",
"$",
"fields",
"[",
"$",
"field",
"]",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"field",
")",
";",
"}",
"return",
"$",
"fields",
";",
"}"
] | /* INTERFACE: Walkable | [
"/",
"*",
"INTERFACE",
":",
"Walkable"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Data/Set.php#L142-L149 |
webforge-labs/psc-cms | lib/Psc/Data/Set.php | Set.createFromStruct | public static function createFromStruct(Array $struct, SetMeta $meta = NULL) {
if (!isset($meta)) $meta = new SetMeta();
$set = new static(array(), $meta);
foreach ($struct as $field => $list) {
list($value, $type) = $list;
$set->set($field, $value, $type);
}
return $set;
} | php | public static function createFromStruct(Array $struct, SetMeta $meta = NULL) {
if (!isset($meta)) $meta = new SetMeta();
$set = new static(array(), $meta);
foreach ($struct as $field => $list) {
list($value, $type) = $list;
$set->set($field, $value, $type);
}
return $set;
} | [
"public",
"static",
"function",
"createFromStruct",
"(",
"Array",
"$",
"struct",
",",
"SetMeta",
"$",
"meta",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"meta",
")",
")",
"$",
"meta",
"=",
"new",
"SetMeta",
"(",
")",
";",
"$",
"set",
"=",
"new",
"static",
"(",
"array",
"(",
")",
",",
"$",
"meta",
")",
";",
"foreach",
"(",
"$",
"struct",
"as",
"$",
"field",
"=>",
"$",
"list",
")",
"{",
"list",
"(",
"$",
"value",
",",
"$",
"type",
")",
"=",
"$",
"list",
";",
"$",
"set",
"->",
"set",
"(",
"$",
"field",
",",
"$",
"value",
",",
"$",
"type",
")",
";",
"}",
"return",
"$",
"set",
";",
"}"
] | Erstellt ein Set mit angegebenen Metadaten
Shortcoming um die Felder des Sets nicht doppelt bezeichnen zu müssen
struct ist ein Array von Listen mit jeweils genau 2 elementen (key 0 und key 1)
@param list[] $struct die Listen sind von der Form: list(mixed $fieldValue, Webforge\Types\Type $fieldType). Die Schlüssel sind die Feldnamen
@return Set | [
"Erstellt",
"ein",
"Set",
"mit",
"angegebenen",
"Metadaten"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Data/Set.php#L166-L176 |
zodream/thirdparty | src/OAuth/TaoBao.php | TaoBao.info | public function info() {
$this->identity = $this->get('taobao_user_id');
$this->username = urldecode($this->get('taobao_user_nick'));
return $this->get();
} | php | public function info() {
$this->identity = $this->get('taobao_user_id');
$this->username = urldecode($this->get('taobao_user_nick'));
return $this->get();
} | [
"public",
"function",
"info",
"(",
")",
"{",
"$",
"this",
"->",
"identity",
"=",
"$",
"this",
"->",
"get",
"(",
"'taobao_user_id'",
")",
";",
"$",
"this",
"->",
"username",
"=",
"urldecode",
"(",
"$",
"this",
"->",
"get",
"(",
"'taobao_user_nick'",
")",
")",
";",
"return",
"$",
"this",
"->",
"get",
"(",
")",
";",
"}"
] | 获取用户信息
@return array | [
"获取用户信息"
] | train | https://github.com/zodream/thirdparty/blob/b9d39087913850f1c5c7c9165105fec22a128f8f/src/OAuth/TaoBao.php#L99-L103 |
mihai-stancu/serializer | Serializer/Normalizer/ParamsDenormalizer.php | ParamsDenormalizer.denormalize | public function denormalize($data, $class, $format = null, array $context = array())
{
/** @var \ReflectionParameter[] $params */
$params = $context['params'];
$indexBy = isset($context['indexBy']) ? $context['indexBy'] : 'name';
$arguments = [];
foreach ($params as $param) {
$index = $param->getPosition();
$arguments[$index] = $this->denormalizeParam($data, $param, $format, $context);
}
ksort($arguments);
$output = [];
foreach ($params as $param) {
$name = $param->getName();
$index = $param->getPosition();
$key = $indexBy === 'name' ? $name : $index;
$output[$key] = $arguments[$index];
}
return $output;
} | php | public function denormalize($data, $class, $format = null, array $context = array())
{
/** @var \ReflectionParameter[] $params */
$params = $context['params'];
$indexBy = isset($context['indexBy']) ? $context['indexBy'] : 'name';
$arguments = [];
foreach ($params as $param) {
$index = $param->getPosition();
$arguments[$index] = $this->denormalizeParam($data, $param, $format, $context);
}
ksort($arguments);
$output = [];
foreach ($params as $param) {
$name = $param->getName();
$index = $param->getPosition();
$key = $indexBy === 'name' ? $name : $index;
$output[$key] = $arguments[$index];
}
return $output;
} | [
"public",
"function",
"denormalize",
"(",
"$",
"data",
",",
"$",
"class",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"/** @var \\ReflectionParameter[] $params */",
"$",
"params",
"=",
"$",
"context",
"[",
"'params'",
"]",
";",
"$",
"indexBy",
"=",
"isset",
"(",
"$",
"context",
"[",
"'indexBy'",
"]",
")",
"?",
"$",
"context",
"[",
"'indexBy'",
"]",
":",
"'name'",
";",
"$",
"arguments",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
")",
"{",
"$",
"index",
"=",
"$",
"param",
"->",
"getPosition",
"(",
")",
";",
"$",
"arguments",
"[",
"$",
"index",
"]",
"=",
"$",
"this",
"->",
"denormalizeParam",
"(",
"$",
"data",
",",
"$",
"param",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"}",
"ksort",
"(",
"$",
"arguments",
")",
";",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
")",
"{",
"$",
"name",
"=",
"$",
"param",
"->",
"getName",
"(",
")",
";",
"$",
"index",
"=",
"$",
"param",
"->",
"getPosition",
"(",
")",
";",
"$",
"key",
"=",
"$",
"indexBy",
"===",
"'name'",
"?",
"$",
"name",
":",
"$",
"index",
";",
"$",
"output",
"[",
"$",
"key",
"]",
"=",
"$",
"arguments",
"[",
"$",
"index",
"]",
";",
"}",
"return",
"$",
"output",
";",
"}"
] | @param array $data
@param string $class
@param string $format
@param array $context
@return array | [
"@param",
"array",
"$data",
"@param",
"string",
"$class",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
] | train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/ParamsDenormalizer.php#L31-L55 |
mihai-stancu/serializer | Serializer/Normalizer/ParamsDenormalizer.php | ParamsDenormalizer.denormalizeParam | protected function denormalizeParam($data, $param, $format, $context)
{
$name = $param->getName();
$index = $param->getPosition();
if (array_key_exists($name, $data)) {
$value = $data[$name];
} elseif (array_key_exists($index, $data)) {
$value = $data[$index];
} elseif ($param->isDefaultValueAvailable()) {
$value = $param->getDefaultValue();
} else {
$message = sprintf('Missing parameter #%s: %s', $index, $name);
throw new \RuntimeException($message);
}
if ($param->getClass()) {
$class = $param->getClass()->getName();
} elseif ($this->serializer->supportsDenormalization($value, MixedDenormalizer::TYPE, $format)) {
$class = MixedDenormalizer::TYPE;
}
if (isset($class)) {
$value = $this->serializer->denormalize($value, $class, $format, $context);
}
return $value;
} | php | protected function denormalizeParam($data, $param, $format, $context)
{
$name = $param->getName();
$index = $param->getPosition();
if (array_key_exists($name, $data)) {
$value = $data[$name];
} elseif (array_key_exists($index, $data)) {
$value = $data[$index];
} elseif ($param->isDefaultValueAvailable()) {
$value = $param->getDefaultValue();
} else {
$message = sprintf('Missing parameter #%s: %s', $index, $name);
throw new \RuntimeException($message);
}
if ($param->getClass()) {
$class = $param->getClass()->getName();
} elseif ($this->serializer->supportsDenormalization($value, MixedDenormalizer::TYPE, $format)) {
$class = MixedDenormalizer::TYPE;
}
if (isset($class)) {
$value = $this->serializer->denormalize($value, $class, $format, $context);
}
return $value;
} | [
"protected",
"function",
"denormalizeParam",
"(",
"$",
"data",
",",
"$",
"param",
",",
"$",
"format",
",",
"$",
"context",
")",
"{",
"$",
"name",
"=",
"$",
"param",
"->",
"getName",
"(",
")",
";",
"$",
"index",
"=",
"$",
"param",
"->",
"getPosition",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"data",
")",
")",
"{",
"$",
"value",
"=",
"$",
"data",
"[",
"$",
"name",
"]",
";",
"}",
"elseif",
"(",
"array_key_exists",
"(",
"$",
"index",
",",
"$",
"data",
")",
")",
"{",
"$",
"value",
"=",
"$",
"data",
"[",
"$",
"index",
"]",
";",
"}",
"elseif",
"(",
"$",
"param",
"->",
"isDefaultValueAvailable",
"(",
")",
")",
"{",
"$",
"value",
"=",
"$",
"param",
"->",
"getDefaultValue",
"(",
")",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'Missing parameter #%s: %s'",
",",
"$",
"index",
",",
"$",
"name",
")",
";",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"$",
"message",
")",
";",
"}",
"if",
"(",
"$",
"param",
"->",
"getClass",
"(",
")",
")",
"{",
"$",
"class",
"=",
"$",
"param",
"->",
"getClass",
"(",
")",
"->",
"getName",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"serializer",
"->",
"supportsDenormalization",
"(",
"$",
"value",
",",
"MixedDenormalizer",
"::",
"TYPE",
",",
"$",
"format",
")",
")",
"{",
"$",
"class",
"=",
"MixedDenormalizer",
"::",
"TYPE",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"class",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"serializer",
"->",
"denormalize",
"(",
"$",
"value",
",",
"$",
"class",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | @param array $data
@param \ReflectionParameter $param
@param string $format
@param array $context
@return object | [
"@param",
"array",
"$data",
"@param",
"\\",
"ReflectionParameter",
"$param",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
] | train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/ParamsDenormalizer.php#L65-L92 |
webforge-labs/psc-cms | lib/Psc/PHP/Lexer.php | Lexer.init | public function init($source) {
$this->source = $source; // für debug
$this->scan($source);
$this->reset();
} | php | public function init($source) {
$this->source = $source; // für debug
$this->scan($source);
$this->reset();
} | [
"public",
"function",
"init",
"(",
"$",
"source",
")",
"{",
"$",
"this",
"->",
"source",
"=",
"$",
"source",
";",
"// für debug",
"$",
"this",
"->",
"scan",
"(",
"$",
"source",
")",
";",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"}"
] | Initialisiert den Lexer
der Sourcecode wird gelesen und in tokens übersetzt
nach diesem Befehl ist der erste token in $this->token gesetzt | [
"Initialisiert",
"den",
"Lexer"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/PHP/Lexer.php#L114-L118 |
webforge-labs/psc-cms | lib/Psc/PHP/Lexer.php | Lexer.moveNext | public function moveNext() {
$this->token = NULL;
/* wir könnten zwar auch token = lookahead machen (aus performance gründen), dies ist aber nicht so
gut wenn skipTokens umgesetzt werden, oder die Funktion aus reset() aufgerufen wird. Bei reset() müssten wir
dann diesen Programmcode hier duplizieren, was nicht so schön ist */
while (array_key_exists(++$this->position, $this->tokens)) {
if (!in_array($this->tokens[$this->position]['type'], $this->skipTokens)) {
$this->token = $this->tokens[$this->position];
break;
}
}
/* lookahead auf das nächstes element setzen, welches nicht übersprungen werden soll */
$this->lookahead = NULL;
$lookaheadPosition = $this->position; // wir machen eine kopie, damit wir beim nächsten moveNext nicht vom lookahead ausgehen
while (array_key_exists(++$lookaheadPosition, $this->tokens)) {
if (!in_array($this->tokens[$lookaheadPosition]['type'], $this->skipTokens)) {
$this->lookahead = $this->tokens[$lookaheadPosition];
break;
}
}
return $this->hasNext();
} | php | public function moveNext() {
$this->token = NULL;
/* wir könnten zwar auch token = lookahead machen (aus performance gründen), dies ist aber nicht so
gut wenn skipTokens umgesetzt werden, oder die Funktion aus reset() aufgerufen wird. Bei reset() müssten wir
dann diesen Programmcode hier duplizieren, was nicht so schön ist */
while (array_key_exists(++$this->position, $this->tokens)) {
if (!in_array($this->tokens[$this->position]['type'], $this->skipTokens)) {
$this->token = $this->tokens[$this->position];
break;
}
}
/* lookahead auf das nächstes element setzen, welches nicht übersprungen werden soll */
$this->lookahead = NULL;
$lookaheadPosition = $this->position; // wir machen eine kopie, damit wir beim nächsten moveNext nicht vom lookahead ausgehen
while (array_key_exists(++$lookaheadPosition, $this->tokens)) {
if (!in_array($this->tokens[$lookaheadPosition]['type'], $this->skipTokens)) {
$this->lookahead = $this->tokens[$lookaheadPosition];
break;
}
}
return $this->hasNext();
} | [
"public",
"function",
"moveNext",
"(",
")",
"{",
"$",
"this",
"->",
"token",
"=",
"NULL",
";",
"/* wir könnten zwar auch token = lookahead machen (aus performance gründen), dies ist aber nicht so\n gut wenn skipTokens umgesetzt werden, oder die Funktion aus reset() aufgerufen wird. Bei reset() müssten wir\n dann diesen Programmcode hier duplizieren, was nicht so schön ist */",
"while",
"(",
"array_key_exists",
"(",
"++",
"$",
"this",
"->",
"position",
",",
"$",
"this",
"->",
"tokens",
")",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"position",
"]",
"[",
"'type'",
"]",
",",
"$",
"this",
"->",
"skipTokens",
")",
")",
"{",
"$",
"this",
"->",
"token",
"=",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"position",
"]",
";",
"break",
";",
"}",
"}",
"/* lookahead auf das nächstes element setzen, welches nicht übersprungen werden soll */",
"$",
"this",
"->",
"lookahead",
"=",
"NULL",
";",
"$",
"lookaheadPosition",
"=",
"$",
"this",
"->",
"position",
";",
"// wir machen eine kopie, damit wir beim nächsten moveNext nicht vom lookahead ausgehen",
"while",
"(",
"array_key_exists",
"(",
"++",
"$",
"lookaheadPosition",
",",
"$",
"this",
"->",
"tokens",
")",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"this",
"->",
"tokens",
"[",
"$",
"lookaheadPosition",
"]",
"[",
"'type'",
"]",
",",
"$",
"this",
"->",
"skipTokens",
")",
")",
"{",
"$",
"this",
"->",
"lookahead",
"=",
"$",
"this",
"->",
"tokens",
"[",
"$",
"lookaheadPosition",
"]",
";",
"break",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"hasNext",
"(",
")",
";",
"}"
] | Bewegt den Cursor auf die den nächsten Token
Der nächste Token wird in lookahead gespeichert (letzten Token ist dieser dann === NULL)
der aktuelle Token ist in token
Gibt TRUE zurueck wenn noch ein weiteres mal moveNext() ausgeführt werden kann
@return bool | [
"Bewegt",
"den",
"Cursor",
"auf",
"die",
"den",
"nächsten",
"Token"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/PHP/Lexer.php#L264-L287 |
webforge-labs/psc-cms | lib/Psc/PHP/Lexer.php | Lexer.skipUntil | public function skipUntil($type) {
while (!$this->isToken($type) && $this->hasNext()) {
$this->moveNext();
}
return $this;
} | php | public function skipUntil($type) {
while (!$this->isToken($type) && $this->hasNext()) {
$this->moveNext();
}
return $this;
} | [
"public",
"function",
"skipUntil",
"(",
"$",
"type",
")",
"{",
"while",
"(",
"!",
"$",
"this",
"->",
"isToken",
"(",
"$",
"type",
")",
"&&",
"$",
"this",
"->",
"hasNext",
"(",
")",
")",
"{",
"$",
"this",
"->",
"moveNext",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Bewegt den Cursor auf den nächsten Token mit angegebem Typ
@chainable | [
"Bewegt",
"den",
"Cursor",
"auf",
"den",
"nächsten",
"Token",
"mit",
"angegebem",
"Typ"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/PHP/Lexer.php#L322-L328 |
webforge-labs/psc-cms | lib/Psc/PHP/Lexer.php | Lexer.reset | public function reset() {
$this->token = NULL;
$this->lookahead = NULL;
$this->position = -1;
$this->moveNext();
} | php | public function reset() {
$this->token = NULL;
$this->lookahead = NULL;
$this->position = -1;
$this->moveNext();
} | [
"public",
"function",
"reset",
"(",
")",
"{",
"$",
"this",
"->",
"token",
"=",
"NULL",
";",
"$",
"this",
"->",
"lookahead",
"=",
"NULL",
";",
"$",
"this",
"->",
"position",
"=",
"-",
"1",
";",
"$",
"this",
"->",
"moveNext",
"(",
")",
";",
"}"
] | Setzt die Position auf den Anfang zurück | [
"Setzt",
"die",
"Position",
"auf",
"den",
"Anfang",
"zurück"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/PHP/Lexer.php#L420-L426 |
webforge-labs/psc-cms | lib/Psc/Doctrine/EntityRepository.php | EntityRepository.save | public function save(Entity $entity) {
$this->_em->persist($entity);
$this->_em->flush();
return $this;
} | php | public function save(Entity $entity) {
$this->_em->persist($entity);
$this->_em->flush();
return $this;
} | [
"public",
"function",
"save",
"(",
"Entity",
"$",
"entity",
")",
"{",
"$",
"this",
"->",
"_em",
"->",
"persist",
"(",
"$",
"entity",
")",
";",
"$",
"this",
"->",
"_em",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Persisted das Entity und flushed den EntityManager | [
"Persisted",
"das",
"Entity",
"und",
"flushed",
"den",
"EntityManager"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/EntityRepository.php#L40-L44 |
webforge-labs/psc-cms | lib/Psc/Doctrine/EntityRepository.php | EntityRepository.remove | public function remove(Entity $entity) {
if (method_exists($entity,'remove')) {
$entity->remove();
}
$this->_em->remove($entity);
return $this;
} | php | public function remove(Entity $entity) {
if (method_exists($entity,'remove')) {
$entity->remove();
}
$this->_em->remove($entity);
return $this;
} | [
"public",
"function",
"remove",
"(",
"Entity",
"$",
"entity",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"entity",
",",
"'remove'",
")",
")",
"{",
"$",
"entity",
"->",
"remove",
"(",
")",
";",
"}",
"$",
"this",
"->",
"_em",
"->",
"remove",
"(",
"$",
"entity",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Ruft auch remove() auf dem Entity auf, wenn die Funktion existiert
@ducktyped
ruft keinen flush auf | [
"Ruft",
"auch",
"remove",
"()",
"auf",
"dem",
"Entity",
"auf",
"wenn",
"die",
"Funktion",
"existiert"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/EntityRepository.php#L57-L64 |
webforge-labs/psc-cms | lib/Psc/Doctrine/EntityRepository.php | EntityRepository.delete | public function delete(Entity $entity) {
$this->remove($entity);
$this->_em->flush();
return $this;
} | php | public function delete(Entity $entity) {
$this->remove($entity);
$this->_em->flush();
return $this;
} | [
"public",
"function",
"delete",
"(",
"Entity",
"$",
"entity",
")",
"{",
"$",
"this",
"->",
"remove",
"(",
"$",
"entity",
")",
";",
"$",
"this",
"->",
"_em",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Ruft auch remove() auf dem Entity auf, wenn die Funktion existiert
@ducktyped
ruft direkt flush auf | [
"Ruft",
"auch",
"remove",
"()",
"auf",
"dem",
"Entity",
"auf",
"wenn",
"die",
"Funktion",
"existiert"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/EntityRepository.php#L72-L77 |
webforge-labs/psc-cms | lib/Psc/Doctrine/EntityRepository.php | EntityRepository.hydrate | public function hydrate($identifier) {
$entity = $this->find($identifier);
if (!($entity instanceof $this->_entityName)) {
throw new EntityNotFoundException(
sprintf("Entity: '%s' nicht gefunden: identifier: %s",
$this->_entityName, Code::varInfo($identifier)));
}
return $entity;
} | php | public function hydrate($identifier) {
$entity = $this->find($identifier);
if (!($entity instanceof $this->_entityName)) {
throw new EntityNotFoundException(
sprintf("Entity: '%s' nicht gefunden: identifier: %s",
$this->_entityName, Code::varInfo($identifier)));
}
return $entity;
} | [
"public",
"function",
"hydrate",
"(",
"$",
"identifier",
")",
"{",
"$",
"entity",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"identifier",
")",
";",
"if",
"(",
"!",
"(",
"$",
"entity",
"instanceof",
"$",
"this",
"->",
"_entityName",
")",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"sprintf",
"(",
"\"Entity: '%s' nicht gefunden: identifier: %s\"",
",",
"$",
"this",
"->",
"_entityName",
",",
"Code",
"::",
"varInfo",
"(",
"$",
"identifier",
")",
")",
")",
";",
"}",
"return",
"$",
"entity",
";",
"}"
] | Sowie find() aber mit Exception, erwartet nur ein Ergebnis
@throws \Psc\Doctrine\EntityNotFoundException
@TODO was passiert hier bei uneindeutigkeit? | [
"Sowie",
"find",
"()",
"aber",
"mit",
"Exception",
"erwartet",
"nur",
"ein",
"Ergebnis"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/EntityRepository.php#L86-L96 |
webforge-labs/psc-cms | lib/Psc/Doctrine/EntityRepository.php | EntityRepository.hydrateRole | public function hydrateRole($role, $identifier) {
return $this->_em->getRepository($this->_class->namespace.'\\'.ucfirst($role))->hydrate($identifier);
} | php | public function hydrateRole($role, $identifier) {
return $this->_em->getRepository($this->_class->namespace.'\\'.ucfirst($role))->hydrate($identifier);
} | [
"public",
"function",
"hydrateRole",
"(",
"$",
"role",
",",
"$",
"identifier",
")",
"{",
"return",
"$",
"this",
"->",
"_em",
"->",
"getRepository",
"(",
"$",
"this",
"->",
"_class",
"->",
"namespace",
".",
"'\\\\'",
".",
"ucfirst",
"(",
"$",
"role",
")",
")",
"->",
"hydrate",
"(",
"$",
"identifier",
")",
";",
"}"
] | Returns an entity of the project, which implements a specific Psc\CMS\Role
@return Psc\CMS\Role\$role.toCamelCase() | [
"Returns",
"an",
"entity",
"of",
"the",
"project",
"which",
"implements",
"a",
"specific",
"Psc",
"\\",
"CMS",
"\\",
"Role"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/EntityRepository.php#L104-L106 |
webforge-labs/psc-cms | lib/Psc/Doctrine/EntityRepository.php | EntityRepository.findOneByCriterias | public function findOneByCriterias(Array $criterias) {
foreach ($criterias as $criteria) {
try {
if (!is_array($criteria)) throw new \InvalidArgumentException('Elemente von $criterias müssen Arrays sein. '.Code::varInfo($criterias));
$object = $this->findOneBy($criteria);
if ($object != null) return $object;
} catch (NoResultException $e) {
}
}
throw new NoResultException();
} | php | public function findOneByCriterias(Array $criterias) {
foreach ($criterias as $criteria) {
try {
if (!is_array($criteria)) throw new \InvalidArgumentException('Elemente von $criterias müssen Arrays sein. '.Code::varInfo($criterias));
$object = $this->findOneBy($criteria);
if ($object != null) return $object;
} catch (NoResultException $e) {
}
}
throw new NoResultException();
} | [
"public",
"function",
"findOneByCriterias",
"(",
"Array",
"$",
"criterias",
")",
"{",
"foreach",
"(",
"$",
"criterias",
"as",
"$",
"criteria",
")",
"{",
"try",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"criteria",
")",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Elemente von $criterias müssen Arrays sein. '.",
"C",
"ode:",
":v",
"arInfo(",
"$",
"c",
"riterias)",
")",
";",
"\r",
"$",
"object",
"=",
"$",
"this",
"->",
"findOneBy",
"(",
"$",
"criteria",
")",
";",
"if",
"(",
"$",
"object",
"!=",
"null",
")",
"return",
"$",
"object",
";",
"}",
"catch",
"(",
"NoResultException",
"$",
"e",
")",
"{",
"}",
"}",
"throw",
"new",
"NoResultException",
"(",
")",
";",
"}"
] | Prüft nach und nach in allen $criteria-Arrays in $criterias nach einem Vorkommen in diesem Repository
wird keins gefunden, wird eine Doctrine\ORM\NoResultException geworden
@throws Doctrine\ORM\NoResultException | [
"Prüft",
"nach",
"und",
"nach",
"in",
"allen",
"$criteria",
"-",
"Arrays",
"in",
"$criterias",
"nach",
"einem",
"Vorkommen",
"in",
"diesem",
"Repository"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/EntityRepository.php#L115-L128 |
webforge-labs/psc-cms | lib/Psc/Doctrine/EntityRepository.php | EntityRepository.hydrateBy | public function hydrateBy(array $criterias) {
$entity = $this->findOneBy($criterias);
if (!($entity instanceof $this->_entityName)) {
throw new EntityNotFoundException(sprintf('Entity %s nicht gefunden: criterias: %s', $this->_entityName, Code::varInfo($criterias)));
}
return $entity;
} | php | public function hydrateBy(array $criterias) {
$entity = $this->findOneBy($criterias);
if (!($entity instanceof $this->_entityName)) {
throw new EntityNotFoundException(sprintf('Entity %s nicht gefunden: criterias: %s', $this->_entityName, Code::varInfo($criterias)));
}
return $entity;
} | [
"public",
"function",
"hydrateBy",
"(",
"array",
"$",
"criterias",
")",
"{",
"$",
"entity",
"=",
"$",
"this",
"->",
"findOneBy",
"(",
"$",
"criterias",
")",
";",
"if",
"(",
"!",
"(",
"$",
"entity",
"instanceof",
"$",
"this",
"->",
"_entityName",
")",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"sprintf",
"(",
"'Entity %s nicht gefunden: criterias: %s'",
",",
"$",
"this",
"->",
"_entityName",
",",
"Code",
"::",
"varInfo",
"(",
"$",
"criterias",
")",
")",
")",
";",
"}",
"return",
"$",
"entity",
";",
"}"
] | Sowie findOneBy aber mit exception
@throws \Psc\Exception | [
"Sowie",
"findOneBy",
"aber",
"mit",
"exception"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/EntityRepository.php#L135-L143 |
webforge-labs/psc-cms | lib/Psc/Doctrine/EntityRepository.php | EntityRepository.autoCompleteTerm | public function autoCompleteTerm(Array $fields, $term = NULL, Array $filters = array(), $maxResults = NULL) {
$qb = $this->buildQueryAutoCompleteTerm($fields, $term);
$q = $qb->getQuery();
if ($maxResults) {
$q->setMaxResults($maxResults);
}
return $q->getResult();
} | php | public function autoCompleteTerm(Array $fields, $term = NULL, Array $filters = array(), $maxResults = NULL) {
$qb = $this->buildQueryAutoCompleteTerm($fields, $term);
$q = $qb->getQuery();
if ($maxResults) {
$q->setMaxResults($maxResults);
}
return $q->getResult();
} | [
"public",
"function",
"autoCompleteTerm",
"(",
"Array",
"$",
"fields",
",",
"$",
"term",
"=",
"NULL",
",",
"Array",
"$",
"filters",
"=",
"array",
"(",
")",
",",
"$",
"maxResults",
"=",
"NULL",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"buildQueryAutoCompleteTerm",
"(",
"$",
"fields",
",",
"$",
"term",
")",
";",
"$",
"q",
"=",
"$",
"qb",
"->",
"getQuery",
"(",
")",
";",
"if",
"(",
"$",
"maxResults",
")",
"{",
"$",
"q",
"->",
"setMaxResults",
"(",
"$",
"maxResults",
")",
";",
"}",
"return",
"$",
"q",
"->",
"getResult",
"(",
")",
";",
"}"
] | @param $field das Feld auf welches der $term untersucht werden soll
ist Term nicht gesetzt werden alle Elemente zurückgegeben
$filters können zusätzliche filter sein (für ableitende klassen)
achtung! Vorsicht beim Ableiten mit JOINS von Autocomplete term und maxresults | [
"@param",
"$field",
"das",
"Feld",
"auf",
"welches",
"der",
"$term",
"untersucht",
"werden",
"soll",
"ist",
"Term",
"nicht",
"gesetzt",
"werden",
"alle",
"Elemente",
"zurückgegeben"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/EntityRepository.php#L166-L176 |
webforge-labs/psc-cms | lib/Psc/Doctrine/EntityRepository.php | EntityRepository.configureUniqueConstraintValidator | public function configureUniqueConstraintValidator(UniqueConstraintValidator $validator = NULL) {
$uniqueConstraints = $this->getUniqueConstraints();
if (!isset($validator)) {
// erstelle einen neuen
$constraint = array_shift($uniqueConstraints);
$validator = new UniqueConstraintValidator($constraint);
}
// benutze den bestehenden / füge die restlichen UniqueConstraints hinzu
foreach ($uniqueConstraints as $constraint) {
$validator->addUniqueConstraint($constraint);
}
/* verarbeiten die Daten für alle Constraints */
foreach ($validator->getUniqueConstraints() as $constraint) {
$validator->updateIndex($constraint, $this->getUniqueIndex($constraint));
}
return $validator;
} | php | public function configureUniqueConstraintValidator(UniqueConstraintValidator $validator = NULL) {
$uniqueConstraints = $this->getUniqueConstraints();
if (!isset($validator)) {
// erstelle einen neuen
$constraint = array_shift($uniqueConstraints);
$validator = new UniqueConstraintValidator($constraint);
}
// benutze den bestehenden / füge die restlichen UniqueConstraints hinzu
foreach ($uniqueConstraints as $constraint) {
$validator->addUniqueConstraint($constraint);
}
/* verarbeiten die Daten für alle Constraints */
foreach ($validator->getUniqueConstraints() as $constraint) {
$validator->updateIndex($constraint, $this->getUniqueIndex($constraint));
}
return $validator;
} | [
"public",
"function",
"configureUniqueConstraintValidator",
"(",
"UniqueConstraintValidator",
"$",
"validator",
"=",
"NULL",
")",
"{",
"$",
"uniqueConstraints",
"=",
"$",
"this",
"->",
"getUniqueConstraints",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"validator",
")",
")",
"{",
"// erstelle einen neuen\r",
"$",
"constraint",
"=",
"array_shift",
"(",
"$",
"uniqueConstraints",
")",
";",
"$",
"validator",
"=",
"new",
"UniqueConstraintValidator",
"(",
"$",
"constraint",
")",
";",
"}",
"// benutze den bestehenden / füge die restlichen UniqueConstraints hinzu\r",
"foreach",
"(",
"$",
"uniqueConstraints",
"as",
"$",
"constraint",
")",
"{",
"$",
"validator",
"->",
"addUniqueConstraint",
"(",
"$",
"constraint",
")",
";",
"}",
"/* verarbeiten die Daten für alle Constraints */\r",
"foreach",
"(",
"$",
"validator",
"->",
"getUniqueConstraints",
"(",
")",
"as",
"$",
"constraint",
")",
"{",
"$",
"validator",
"->",
"updateIndex",
"(",
"$",
"constraint",
",",
"$",
"this",
"->",
"getUniqueIndex",
"(",
"$",
"constraint",
")",
")",
";",
"}",
"return",
"$",
"validator",
";",
"}"
] | Setzt einen UniqueConstraintValidator mit den passenden UniqueConstraints des Entities
sind keine Unique-Constraints für diese Klasse gesetzt, wird eine \Psc\Doctrine\NoUniqueConstraintException geworfen
@throws Psc\Doctrine\UniqueConstraintException, wenn $this->getUniqueIndex() einen inkonsistenten Index zurückgibt (index mit duplikaten) | [
"Setzt",
"einen",
"UniqueConstraintValidator",
"mit",
"den",
"passenden",
"UniqueConstraints",
"des",
"Entities"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/EntityRepository.php#L222-L242 |
webforge-labs/psc-cms | lib/Psc/Doctrine/EntityRepository.php | EntityRepository.deliverQuery | public function deliverQuery($queryBuilder, $qbFunction, $returnDefault) {
$qbFunction = $this->compileQBFunction($qbFunction);
$return = $qbFunction($queryBuilder) ?: $returnDefault;
if ($queryBuilder instanceof \Doctrine\ORM\QueryBuilder) {
$query = $queryBuilder->getQuery();
} elseif ($queryBuilder instanceof \Doctrine\ORM\AbstractQuery) {
$query = $queryBuilder;
} else {
throw new \Psc\Exception('Parameter 1 kann nur QueryBuilder oder Query sein.');
}
try {
if ($return === 'return') {
return $queryBuilder;
} elseif ($return === 'result') {
return $query->getResult();
} elseif ($return === 'single') {
return $query->getSingleResult();
} elseif ($return === 'scalar') {
return $query->getScalarResult();
} elseif (mb_strtolower($return) === 'singleornull') {
try {
return $query->getSingleResult();
} catch (\Doctrine\ORM\NoResultException $e) {
return NULL;
}
} else {
return $query->getResult();
}
} catch (\Doctrine\ORM\Query\QueryException $e) {
throw new \Psc\Doctrine\QueryException(sprintf("%s \n\nDQL: '%s'",$e->getMessage(), $query->getDQL()));
} catch (\Doctrine\ORM\NoResultException $e) {
throw \Psc\Doctrine\EntityNotFoundException::fromQuery($query);
} catch (\Doctrine\ORM\NonUniqueResultException $e) {
throw \Psc\Doctrine\EntityNonUniqueResultException::fromQuery($query);
}
} | php | public function deliverQuery($queryBuilder, $qbFunction, $returnDefault) {
$qbFunction = $this->compileQBFunction($qbFunction);
$return = $qbFunction($queryBuilder) ?: $returnDefault;
if ($queryBuilder instanceof \Doctrine\ORM\QueryBuilder) {
$query = $queryBuilder->getQuery();
} elseif ($queryBuilder instanceof \Doctrine\ORM\AbstractQuery) {
$query = $queryBuilder;
} else {
throw new \Psc\Exception('Parameter 1 kann nur QueryBuilder oder Query sein.');
}
try {
if ($return === 'return') {
return $queryBuilder;
} elseif ($return === 'result') {
return $query->getResult();
} elseif ($return === 'single') {
return $query->getSingleResult();
} elseif ($return === 'scalar') {
return $query->getScalarResult();
} elseif (mb_strtolower($return) === 'singleornull') {
try {
return $query->getSingleResult();
} catch (\Doctrine\ORM\NoResultException $e) {
return NULL;
}
} else {
return $query->getResult();
}
} catch (\Doctrine\ORM\Query\QueryException $e) {
throw new \Psc\Doctrine\QueryException(sprintf("%s \n\nDQL: '%s'",$e->getMessage(), $query->getDQL()));
} catch (\Doctrine\ORM\NoResultException $e) {
throw \Psc\Doctrine\EntityNotFoundException::fromQuery($query);
} catch (\Doctrine\ORM\NonUniqueResultException $e) {
throw \Psc\Doctrine\EntityNonUniqueResultException::fromQuery($query);
}
} | [
"public",
"function",
"deliverQuery",
"(",
"$",
"queryBuilder",
",",
"$",
"qbFunction",
",",
"$",
"returnDefault",
")",
"{",
"$",
"qbFunction",
"=",
"$",
"this",
"->",
"compileQBFunction",
"(",
"$",
"qbFunction",
")",
";",
"$",
"return",
"=",
"$",
"qbFunction",
"(",
"$",
"queryBuilder",
")",
"?",
":",
"$",
"returnDefault",
";",
"if",
"(",
"$",
"queryBuilder",
"instanceof",
"\\",
"Doctrine",
"\\",
"ORM",
"\\",
"QueryBuilder",
")",
"{",
"$",
"query",
"=",
"$",
"queryBuilder",
"->",
"getQuery",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"queryBuilder",
"instanceof",
"\\",
"Doctrine",
"\\",
"ORM",
"\\",
"AbstractQuery",
")",
"{",
"$",
"query",
"=",
"$",
"queryBuilder",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Psc",
"\\",
"Exception",
"(",
"'Parameter 1 kann nur QueryBuilder oder Query sein.'",
")",
";",
"}",
"try",
"{",
"if",
"(",
"$",
"return",
"===",
"'return'",
")",
"{",
"return",
"$",
"queryBuilder",
";",
"}",
"elseif",
"(",
"$",
"return",
"===",
"'result'",
")",
"{",
"return",
"$",
"query",
"->",
"getResult",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"return",
"===",
"'single'",
")",
"{",
"return",
"$",
"query",
"->",
"getSingleResult",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"return",
"===",
"'scalar'",
")",
"{",
"return",
"$",
"query",
"->",
"getScalarResult",
"(",
")",
";",
"}",
"elseif",
"(",
"mb_strtolower",
"(",
"$",
"return",
")",
"===",
"'singleornull'",
")",
"{",
"try",
"{",
"return",
"$",
"query",
"->",
"getSingleResult",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Doctrine",
"\\",
"ORM",
"\\",
"NoResultException",
"$",
"e",
")",
"{",
"return",
"NULL",
";",
"}",
"}",
"else",
"{",
"return",
"$",
"query",
"->",
"getResult",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Doctrine",
"\\",
"ORM",
"\\",
"Query",
"\\",
"QueryException",
"$",
"e",
")",
"{",
"throw",
"new",
"\\",
"Psc",
"\\",
"Doctrine",
"\\",
"QueryException",
"(",
"sprintf",
"(",
"\"%s \\n\\nDQL: '%s'\"",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"query",
"->",
"getDQL",
"(",
")",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Doctrine",
"\\",
"ORM",
"\\",
"NoResultException",
"$",
"e",
")",
"{",
"throw",
"\\",
"Psc",
"\\",
"Doctrine",
"\\",
"EntityNotFoundException",
"::",
"fromQuery",
"(",
"$",
"query",
")",
";",
"}",
"catch",
"(",
"\\",
"Doctrine",
"\\",
"ORM",
"\\",
"NonUniqueResultException",
"$",
"e",
")",
"{",
"throw",
"\\",
"Psc",
"\\",
"Doctrine",
"\\",
"EntityNonUniqueResultException",
"::",
"fromQuery",
"(",
"$",
"query",
")",
";",
"}",
"}"
] | Ruft den qbFunction-Hook auf dem QueryBuilder auf und gibt entsprechend ein Result oder den QueryBuilder zurück
der Hook kann unterbrechen, dass das Query direkt ausgeführt wird (return) oder bestimmen in welcher Form das Result zurückgegeben werden soll
die qbFunction kann folgende Strings zurückgeben umn das Verhalten von deliverQuery zu steuern:
- return: gibt den QueryBuilder zurück
- result erstellt das Query und gibt das Ergebnis von query::getResult() zurück
- single erstellt das Query und gibt das Ergebnis von query::getSingleResult() zurück
- scalar erstellt das Query und gibt das Ergebnis von query::getScalarResult() zurück
die qbFunction erhält nur einen Parameter dies ist der QueryBuilder
@param string $returnDefault ist qbFunction nicht gesetzt, wird dies als rückgabe Wert genommen (selbes format wie strings oben)
@return mixed | [
"Ruft",
"den",
"qbFunction",
"-",
"Hook",
"auf",
"dem",
"QueryBuilder",
"auf",
"und",
"gibt",
"entsprechend",
"ein",
"Result",
"oder",
"den",
"QueryBuilder",
"zurück"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/EntityRepository.php#L317-L359 |
davidgorges/color-contrast-php | src/ColorContrast.php | ColorContrast.addColors | public function addColors($colors)
{
$args = func_get_args();
foreach ($args as $arg) {
if (is_array($arg)) {
foreach ($arg as $color) {
$this->addColor($color);
}
} else {
$this->addColor($arg);
}
}
} | php | public function addColors($colors)
{
$args = func_get_args();
foreach ($args as $arg) {
if (is_array($arg)) {
foreach ($arg as $color) {
$this->addColor($color);
}
} else {
$this->addColor($arg);
}
}
} | [
"public",
"function",
"addColors",
"(",
"$",
"colors",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"arg",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"arg",
")",
")",
"{",
"foreach",
"(",
"$",
"arg",
"as",
"$",
"color",
")",
"{",
"$",
"this",
"->",
"addColor",
"(",
"$",
"color",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"addColor",
"(",
"$",
"arg",
")",
";",
"}",
"}",
"}"
] | add
@param mixed $colors | [
"add"
] | train | https://github.com/davidgorges/color-contrast-php/blob/11edc6e04ce73d8d9b0bffeda1586f2c2fa22e71/src/ColorContrast.php#L48-L60 |
davidgorges/color-contrast-php | src/ColorContrast.php | ColorContrast.getCombinations | public function getCombinations($minContrast = 0.0)
{
$combinations = array();
foreach ($this->colors as $backgroundColor) {
foreach ($this->colors as $foregroundColor) {
if ($backgroundColor == $foregroundColor) {
continue;
}
$contrast = $this->algorithm->calculate($foregroundColor, $backgroundColor);
if ($contrast > $minContrast) {
$combinations[] = new ColorCombination($foregroundColor, $backgroundColor, $contrast);
}
}
}
return $combinations;
} | php | public function getCombinations($minContrast = 0.0)
{
$combinations = array();
foreach ($this->colors as $backgroundColor) {
foreach ($this->colors as $foregroundColor) {
if ($backgroundColor == $foregroundColor) {
continue;
}
$contrast = $this->algorithm->calculate($foregroundColor, $backgroundColor);
if ($contrast > $minContrast) {
$combinations[] = new ColorCombination($foregroundColor, $backgroundColor, $contrast);
}
}
}
return $combinations;
} | [
"public",
"function",
"getCombinations",
"(",
"$",
"minContrast",
"=",
"0.0",
")",
"{",
"$",
"combinations",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"colors",
"as",
"$",
"backgroundColor",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"colors",
"as",
"$",
"foregroundColor",
")",
"{",
"if",
"(",
"$",
"backgroundColor",
"==",
"$",
"foregroundColor",
")",
"{",
"continue",
";",
"}",
"$",
"contrast",
"=",
"$",
"this",
"->",
"algorithm",
"->",
"calculate",
"(",
"$",
"foregroundColor",
",",
"$",
"backgroundColor",
")",
";",
"if",
"(",
"$",
"contrast",
">",
"$",
"minContrast",
")",
"{",
"$",
"combinations",
"[",
"]",
"=",
"new",
"ColorCombination",
"(",
"$",
"foregroundColor",
",",
"$",
"backgroundColor",
",",
"$",
"contrast",
")",
";",
"}",
"}",
"}",
"return",
"$",
"combinations",
";",
"}"
] | @param float $minContrast
@return ColorCombination[] | [
"@param",
"float",
"$minContrast"
] | train | https://github.com/davidgorges/color-contrast-php/blob/11edc6e04ce73d8d9b0bffeda1586f2c2fa22e71/src/ColorContrast.php#L85-L102 |
davidgorges/color-contrast-php | src/ColorContrast.php | ColorContrast.parseColor | private function parseColor($color)
{
try {
if ($color instanceof ColorJizz) {
return $color;
}
if (is_string($color)) {
if (substr($color, 0, 1) == '#') {
return Hex::fromString(substr($color, 1));
}
if (strlen($color) == 6) {
return Hex::fromString($color);
}
}
if (is_integer($color)) {
return new Hex($color);
}
} catch (InvalidArgumentException $e) {
throw new InvalidColorException('Could not parse color. Currently supported formats are 0x000000, #ff0000 and ff0000', 0, $e);
}
throw new InvalidColorException(sprintf('Could not detect color %s', $color));
} | php | private function parseColor($color)
{
try {
if ($color instanceof ColorJizz) {
return $color;
}
if (is_string($color)) {
if (substr($color, 0, 1) == '#') {
return Hex::fromString(substr($color, 1));
}
if (strlen($color) == 6) {
return Hex::fromString($color);
}
}
if (is_integer($color)) {
return new Hex($color);
}
} catch (InvalidArgumentException $e) {
throw new InvalidColorException('Could not parse color. Currently supported formats are 0x000000, #ff0000 and ff0000', 0, $e);
}
throw new InvalidColorException(sprintf('Could not detect color %s', $color));
} | [
"private",
"function",
"parseColor",
"(",
"$",
"color",
")",
"{",
"try",
"{",
"if",
"(",
"$",
"color",
"instanceof",
"ColorJizz",
")",
"{",
"return",
"$",
"color",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"color",
")",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"color",
",",
"0",
",",
"1",
")",
"==",
"'#'",
")",
"{",
"return",
"Hex",
"::",
"fromString",
"(",
"substr",
"(",
"$",
"color",
",",
"1",
")",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"color",
")",
"==",
"6",
")",
"{",
"return",
"Hex",
"::",
"fromString",
"(",
"$",
"color",
")",
";",
"}",
"}",
"if",
"(",
"is_integer",
"(",
"$",
"color",
")",
")",
"{",
"return",
"new",
"Hex",
"(",
"$",
"color",
")",
";",
"}",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"throw",
"new",
"InvalidColorException",
"(",
"'Could not parse color. Currently supported formats are 0x000000, #ff0000 and ff0000'",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"throw",
"new",
"InvalidColorException",
"(",
"sprintf",
"(",
"'Could not detect color %s'",
",",
"$",
"color",
")",
")",
";",
"}"
] | @param $color
@return Hex
@throws InvalidColorException
@throws InvalidArgumentException | [
"@param",
"$color"
] | train | https://github.com/davidgorges/color-contrast-php/blob/11edc6e04ce73d8d9b0bffeda1586f2c2fa22e71/src/ColorContrast.php#L119-L142 |
davidgorges/color-contrast-php | src/ColorContrast.php | ColorContrast.complimentaryTheme | public function complimentaryTheme($color)
{
$parsedColor = $this->parseColor($color);
$yiq = $this->calculateYIQValue($parsedColor->toRGB());
if ($yiq > 128) {
return self::DARK;
} else {
return self::LIGHT;
}
} | php | public function complimentaryTheme($color)
{
$parsedColor = $this->parseColor($color);
$yiq = $this->calculateYIQValue($parsedColor->toRGB());
if ($yiq > 128) {
return self::DARK;
} else {
return self::LIGHT;
}
} | [
"public",
"function",
"complimentaryTheme",
"(",
"$",
"color",
")",
"{",
"$",
"parsedColor",
"=",
"$",
"this",
"->",
"parseColor",
"(",
"$",
"color",
")",
";",
"$",
"yiq",
"=",
"$",
"this",
"->",
"calculateYIQValue",
"(",
"$",
"parsedColor",
"->",
"toRGB",
"(",
")",
")",
";",
"if",
"(",
"$",
"yiq",
">",
"128",
")",
"{",
"return",
"self",
"::",
"DARK",
";",
"}",
"else",
"{",
"return",
"self",
"::",
"LIGHT",
";",
"}",
"}"
] | Tries to detect what font-color you should use as complimentary color.
e.g. complimentaryTheme('#ffffff') would return ColorContrast::DARK
@param $color
@return string ColorContrast::LIGHT or ColorContrast::DARK | [
"Tries",
"to",
"detect",
"what",
"font",
"-",
"color",
"you",
"should",
"use",
"as",
"complimentary",
"color",
".",
"e",
".",
"g",
".",
"complimentaryTheme",
"(",
"#ffffff",
")",
"would",
"return",
"ColorContrast",
"::",
"DARK",
"@param",
"$color"
] | train | https://github.com/davidgorges/color-contrast-php/blob/11edc6e04ce73d8d9b0bffeda1586f2c2fa22e71/src/ColorContrast.php#L151-L160 |
davidgorges/color-contrast-php | src/ColorContrast.php | ColorContrast.calculateYIQValue | private function calculateYIQValue(RGB $color)
{
$yiq = (($color->getRed() * 299) + ($color->getGreen() * 587) + ($color->getBlue() * 114)) / 1000;
return $yiq;
} | php | private function calculateYIQValue(RGB $color)
{
$yiq = (($color->getRed() * 299) + ($color->getGreen() * 587) + ($color->getBlue() * 114)) / 1000;
return $yiq;
} | [
"private",
"function",
"calculateYIQValue",
"(",
"RGB",
"$",
"color",
")",
"{",
"$",
"yiq",
"=",
"(",
"(",
"$",
"color",
"->",
"getRed",
"(",
")",
"*",
"299",
")",
"+",
"(",
"$",
"color",
"->",
"getGreen",
"(",
")",
"*",
"587",
")",
"+",
"(",
"$",
"color",
"->",
"getBlue",
"(",
")",
"*",
"114",
")",
")",
"/",
"1000",
";",
"return",
"$",
"yiq",
";",
"}"
] | calculates the YIQ value for a given color.
@param RGB $color
@return float 0-255 | [
"calculates",
"the",
"YIQ",
"value",
"for",
"a",
"given",
"color",
"."
] | train | https://github.com/davidgorges/color-contrast-php/blob/11edc6e04ce73d8d9b0bffeda1586f2c2fa22e71/src/ColorContrast.php#L169-L173 |
aryelgois/yasql-php | src/Parser.php | Parser.extractKeyword | protected static function extractKeyword(
string $haystack,
string $needle,
&$matches = null
) {
$pattern = '/' . (strpos($needle, '^') === 0 ? '' : ' ?') . $needle
. (strrpos($needle, '$') === strlen($needle)-1 ? '' : ' ?') . '/i';
if (preg_match($pattern, $haystack, $matches, PREG_OFFSET_CAPTURE)) {
$m = $matches[0];
$haystack = substr_replace($haystack, ' ', $m[1], strlen($m[0]));
return trim($haystack);
}
return false;
} | php | protected static function extractKeyword(
string $haystack,
string $needle,
&$matches = null
) {
$pattern = '/' . (strpos($needle, '^') === 0 ? '' : ' ?') . $needle
. (strrpos($needle, '$') === strlen($needle)-1 ? '' : ' ?') . '/i';
if (preg_match($pattern, $haystack, $matches, PREG_OFFSET_CAPTURE)) {
$m = $matches[0];
$haystack = substr_replace($haystack, ' ', $m[1], strlen($m[0]));
return trim($haystack);
}
return false;
} | [
"protected",
"static",
"function",
"extractKeyword",
"(",
"string",
"$",
"haystack",
",",
"string",
"$",
"needle",
",",
"&",
"$",
"matches",
"=",
"null",
")",
"{",
"$",
"pattern",
"=",
"'/'",
".",
"(",
"strpos",
"(",
"$",
"needle",
",",
"'^'",
")",
"===",
"0",
"?",
"''",
":",
"' ?'",
")",
".",
"$",
"needle",
".",
"(",
"strrpos",
"(",
"$",
"needle",
",",
"'$'",
")",
"===",
"strlen",
"(",
"$",
"needle",
")",
"-",
"1",
"?",
"''",
":",
"' ?'",
")",
".",
"'/i'",
";",
"if",
"(",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"haystack",
",",
"$",
"matches",
",",
"PREG_OFFSET_CAPTURE",
")",
")",
"{",
"$",
"m",
"=",
"$",
"matches",
"[",
"0",
"]",
";",
"$",
"haystack",
"=",
"substr_replace",
"(",
"$",
"haystack",
",",
"' '",
",",
"$",
"m",
"[",
"1",
"]",
",",
"strlen",
"(",
"$",
"m",
"[",
"0",
"]",
")",
")",
";",
"return",
"trim",
"(",
"$",
"haystack",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Extracts a keyword from a string
@param string $haystack String to look for the keyword
@param string $needle PCRE subpattern with the keyword (insensitive)
@param string $matches @see \preg_match() $matches (PREG_OFFSET_CAPTURE)
@return false If the keyword was not found
@return string The string without the keyword | [
"Extracts",
"a",
"keyword",
"from",
"a",
"string"
] | train | https://github.com/aryelgois/yasql-php/blob/f428b180d35bfc1ddf1f9b3323f9b085fbc09ac7/src/Parser.php#L404-L418 |
aryelgois/yasql-php | src/Parser.php | Parser.strContains | protected static function strContains($str, array $arr)
{
foreach ($arr as $a) {
if (stripos($str, $a) !== false) {
return true;
}
}
return false;
} | php | protected static function strContains($str, array $arr)
{
foreach ($arr as $a) {
if (stripos($str, $a) !== false) {
return true;
}
}
return false;
} | [
"protected",
"static",
"function",
"strContains",
"(",
"$",
"str",
",",
"array",
"$",
"arr",
")",
"{",
"foreach",
"(",
"$",
"arr",
"as",
"$",
"a",
")",
"{",
"if",
"(",
"stripos",
"(",
"$",
"str",
",",
"$",
"a",
")",
"!==",
"false",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Tells if a string contains any items in an array (case insensitive)
@author zombat
@link https://stackoverflow.com/a/2124557
@param string $str A string to be tested
@param array $arr List of substrings that could be in $str
@return bool | [
"Tells",
"if",
"a",
"string",
"contains",
"any",
"items",
"in",
"an",
"array",
"(",
"case",
"insensitive",
")"
] | train | https://github.com/aryelgois/yasql-php/blob/f428b180d35bfc1ddf1f9b3323f9b085fbc09ac7/src/Parser.php#L441-L449 |
titon/db | src/Titon/Db/Database.php | Database.getDriver | public function getDriver($key) {
if (isset($this->_drivers[$key])) {
return $this->_drivers[$key];
}
throw new MissingDriverException(sprintf('Driver %s does not exist', $key));
} | php | public function getDriver($key) {
if (isset($this->_drivers[$key])) {
return $this->_drivers[$key];
}
throw new MissingDriverException(sprintf('Driver %s does not exist', $key));
} | [
"public",
"function",
"getDriver",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_drivers",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_drivers",
"[",
"$",
"key",
"]",
";",
"}",
"throw",
"new",
"MissingDriverException",
"(",
"sprintf",
"(",
"'Driver %s does not exist'",
",",
"$",
"key",
")",
")",
";",
"}"
] | Return a driver by key.
@param string $key
@return \Titon\Db\Driver
@throws \Titon\Db\Exception\MissingDriverException | [
"Return",
"a",
"driver",
"by",
"key",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Database.php#L49-L55 |
PeekAndPoke/psi | src/Operation/FullSet/SortByOperation.php | SortByOperation.apply | public function apply(\Iterator $set)
{
$func = $this->function;
$data = iterator_to_array($set);
usort($data, function ($i1, $i2) use ($func) {
$val1 = $func($i1);
$val2 = $func($i2);
if ($val1 === $val2) {
return 0;
}
return $val1 > $val2 ? 1 : -1;
});
return new \ArrayIterator($data);
} | php | public function apply(\Iterator $set)
{
$func = $this->function;
$data = iterator_to_array($set);
usort($data, function ($i1, $i2) use ($func) {
$val1 = $func($i1);
$val2 = $func($i2);
if ($val1 === $val2) {
return 0;
}
return $val1 > $val2 ? 1 : -1;
});
return new \ArrayIterator($data);
} | [
"public",
"function",
"apply",
"(",
"\\",
"Iterator",
"$",
"set",
")",
"{",
"$",
"func",
"=",
"$",
"this",
"->",
"function",
";",
"$",
"data",
"=",
"iterator_to_array",
"(",
"$",
"set",
")",
";",
"usort",
"(",
"$",
"data",
",",
"function",
"(",
"$",
"i1",
",",
"$",
"i2",
")",
"use",
"(",
"$",
"func",
")",
"{",
"$",
"val1",
"=",
"$",
"func",
"(",
"$",
"i1",
")",
";",
"$",
"val2",
"=",
"$",
"func",
"(",
"$",
"i2",
")",
";",
"if",
"(",
"$",
"val1",
"===",
"$",
"val2",
")",
"{",
"return",
"0",
";",
"}",
"return",
"$",
"val1",
">",
"$",
"val2",
"?",
"1",
":",
"-",
"1",
";",
"}",
")",
";",
"return",
"new",
"\\",
"ArrayIterator",
"(",
"$",
"data",
")",
";",
"}"
] | @param \Iterator $set
@return \Iterator | [
"@param",
"\\",
"Iterator",
"$set"
] | train | https://github.com/PeekAndPoke/psi/blob/cfd45d995d3a2c2ea6ba5b1ce7b5fcc71179456f/src/Operation/FullSet/SortByOperation.php#L25-L43 |
mihai-stancu/serializer | Serializer/Normalizer/StreamNormalizer.php | StreamNormalizer.normalize | public function normalize($stream, $format = null, array $context = array())
{
$string = stream_get_contents($stream);
return parent::normalize($string, $format, $context);
} | php | public function normalize($stream, $format = null, array $context = array())
{
$string = stream_get_contents($stream);
return parent::normalize($string, $format, $context);
} | [
"public",
"function",
"normalize",
"(",
"$",
"stream",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"$",
"string",
"=",
"stream_get_contents",
"(",
"$",
"stream",
")",
";",
"return",
"parent",
"::",
"normalize",
"(",
"$",
"string",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"}"
] | @param resource $stream
@param string $format
@param array $context
@return array|bool|float|int|null|string | [
"@param",
"resource",
"$stream",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
] | train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/StreamNormalizer.php#L28-L33 |
mihai-stancu/serializer | Serializer/Normalizer/StreamNormalizer.php | StreamNormalizer.denormalize | public function denormalize($data, $class, $format = null, array $context = array())
{
$string = parent::denormalize($data, $class, $format, $context);
return fopen('data:,'.$string, 'r');
} | php | public function denormalize($data, $class, $format = null, array $context = array())
{
$string = parent::denormalize($data, $class, $format, $context);
return fopen('data:,'.$string, 'r');
} | [
"public",
"function",
"denormalize",
"(",
"$",
"data",
",",
"$",
"class",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"$",
"string",
"=",
"parent",
"::",
"denormalize",
"(",
"$",
"data",
",",
"$",
"class",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"return",
"fopen",
"(",
"'data:,'",
".",
"$",
"string",
",",
"'r'",
")",
";",
"}"
] | @param string $data
@param string $class
@param string $format
@param array $context
@return resource | [
"@param",
"string",
"$data",
"@param",
"string",
"$class",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
] | train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/StreamNormalizer.php#L54-L59 |
zodream/thirdparty | src/ALi/Rsa.php | Rsa.encrypt | public function encrypt($data){
$maxlength = $this->getMaxEncryptBlockSize($this->publicKey);
$output='';
while(strlen($data)){
$input = substr($data, 0, $maxlength);
$data = substr($data, $maxlength);
openssl_public_encrypt($input, $encrypted, $this->publicKey);
$output .= $encrypted;
}
$encryptedData = base64_encode($output);
return $encryptedData;
} | php | public function encrypt($data){
$maxlength = $this->getMaxEncryptBlockSize($this->publicKey);
$output='';
while(strlen($data)){
$input = substr($data, 0, $maxlength);
$data = substr($data, $maxlength);
openssl_public_encrypt($input, $encrypted, $this->publicKey);
$output .= $encrypted;
}
$encryptedData = base64_encode($output);
return $encryptedData;
} | [
"public",
"function",
"encrypt",
"(",
"$",
"data",
")",
"{",
"$",
"maxlength",
"=",
"$",
"this",
"->",
"getMaxEncryptBlockSize",
"(",
"$",
"this",
"->",
"publicKey",
")",
";",
"$",
"output",
"=",
"''",
";",
"while",
"(",
"strlen",
"(",
"$",
"data",
")",
")",
"{",
"$",
"input",
"=",
"substr",
"(",
"$",
"data",
",",
"0",
",",
"$",
"maxlength",
")",
";",
"$",
"data",
"=",
"substr",
"(",
"$",
"data",
",",
"$",
"maxlength",
")",
";",
"openssl_public_encrypt",
"(",
"$",
"input",
",",
"$",
"encrypted",
",",
"$",
"this",
"->",
"publicKey",
")",
";",
"$",
"output",
".=",
"$",
"encrypted",
";",
"}",
"$",
"encryptedData",
"=",
"base64_encode",
"(",
"$",
"output",
")",
";",
"return",
"$",
"encryptedData",
";",
"}"
] | rsa加密
@param $data 要加密的数据
@return string 加密后的密文 | [
"rsa加密"
] | train | https://github.com/zodream/thirdparty/blob/b9d39087913850f1c5c7c9165105fec22a128f8f/src/ALi/Rsa.php#L28-L39 |
zodream/thirdparty | src/ALi/Rsa.php | Rsa.decrypt | public function decrypt($data){
$data = base64_decode($data);
$maxlength = $this->getMaxDecryptBlockSize($this->privateKey);
$output='';
while(strlen($data)){
$input = substr($data, 0, $maxlength);
$data = substr($data, $maxlength);
openssl_private_decrypt($input, $out, $this->privateKey);
$output .= $out;
}
return $output;
} | php | public function decrypt($data){
$data = base64_decode($data);
$maxlength = $this->getMaxDecryptBlockSize($this->privateKey);
$output='';
while(strlen($data)){
$input = substr($data, 0, $maxlength);
$data = substr($data, $maxlength);
openssl_private_decrypt($input, $out, $this->privateKey);
$output .= $out;
}
return $output;
} | [
"public",
"function",
"decrypt",
"(",
"$",
"data",
")",
"{",
"$",
"data",
"=",
"base64_decode",
"(",
"$",
"data",
")",
";",
"$",
"maxlength",
"=",
"$",
"this",
"->",
"getMaxDecryptBlockSize",
"(",
"$",
"this",
"->",
"privateKey",
")",
";",
"$",
"output",
"=",
"''",
";",
"while",
"(",
"strlen",
"(",
"$",
"data",
")",
")",
"{",
"$",
"input",
"=",
"substr",
"(",
"$",
"data",
",",
"0",
",",
"$",
"maxlength",
")",
";",
"$",
"data",
"=",
"substr",
"(",
"$",
"data",
",",
"$",
"maxlength",
")",
";",
"openssl_private_decrypt",
"(",
"$",
"input",
",",
"$",
"out",
",",
"$",
"this",
"->",
"privateKey",
")",
";",
"$",
"output",
".=",
"$",
"out",
";",
"}",
"return",
"$",
"output",
";",
"}"
] | 解密
@param $data 要解密的数据
@return string 解密后的明文 | [
"解密"
] | train | https://github.com/zodream/thirdparty/blob/b9d39087913850f1c5c7c9165105fec22a128f8f/src/ALi/Rsa.php#L46-L57 |
aedart/laravel-helpers | src/Traits/Http/RequestTrait.php | RequestTrait.getRequest | public function getRequest(): ?Request
{
if (!$this->hasRequest()) {
$this->setRequest($this->getDefaultRequest());
}
return $this->request;
} | php | public function getRequest(): ?Request
{
if (!$this->hasRequest()) {
$this->setRequest($this->getDefaultRequest());
}
return $this->request;
} | [
"public",
"function",
"getRequest",
"(",
")",
":",
"?",
"Request",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasRequest",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setRequest",
"(",
"$",
"this",
"->",
"getDefaultRequest",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"request",
";",
"}"
] | Get request
If no request has been set, this method will
set and return a default request, if any such
value is available
@see getDefaultRequest()
@return Request|null request or null if none request has been set | [
"Get",
"request"
] | train | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Http/RequestTrait.php#L53-L59 |
claroline/ForumBundle | Controller/ForumController.php | ForumController.openAction | public function openAction(Forum $forum)
{
$em = $this->getDoctrine()->getManager();
$this->checkAccess($forum);
$categories = $em->getRepository('ClarolineForumBundle:Forum')->findCategories($forum);
$user = $this->tokenStorage->getToken()->getUser();
$hasSubscribed = $user === 'anon.' ?
false :
$this->manager->hasSubscribed($user, $forum);
$isModerator = $this->authorization->isGranted(
'moderate',
new ResourceCollection(array($forum->getResourceNode()))
) && $user !== 'anon.';
return array(
'search' => null,
'_resource' => $forum,
'isModerator' => $isModerator,
'categories' => $categories,
'hasSubscribed' => $hasSubscribed,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
} | php | public function openAction(Forum $forum)
{
$em = $this->getDoctrine()->getManager();
$this->checkAccess($forum);
$categories = $em->getRepository('ClarolineForumBundle:Forum')->findCategories($forum);
$user = $this->tokenStorage->getToken()->getUser();
$hasSubscribed = $user === 'anon.' ?
false :
$this->manager->hasSubscribed($user, $forum);
$isModerator = $this->authorization->isGranted(
'moderate',
new ResourceCollection(array($forum->getResourceNode()))
) && $user !== 'anon.';
return array(
'search' => null,
'_resource' => $forum,
'isModerator' => $isModerator,
'categories' => $categories,
'hasSubscribed' => $hasSubscribed,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
} | [
"public",
"function",
"openAction",
"(",
"Forum",
"$",
"forum",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"this",
"->",
"checkAccess",
"(",
"$",
"forum",
")",
";",
"$",
"categories",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'ClarolineForumBundle:Forum'",
")",
"->",
"findCategories",
"(",
"$",
"forum",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"tokenStorage",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"$",
"hasSubscribed",
"=",
"$",
"user",
"===",
"'anon.'",
"?",
"false",
":",
"$",
"this",
"->",
"manager",
"->",
"hasSubscribed",
"(",
"$",
"user",
",",
"$",
"forum",
")",
";",
"$",
"isModerator",
"=",
"$",
"this",
"->",
"authorization",
"->",
"isGranted",
"(",
"'moderate'",
",",
"new",
"ResourceCollection",
"(",
"array",
"(",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
")",
")",
")",
"&&",
"$",
"user",
"!==",
"'anon.'",
";",
"return",
"array",
"(",
"'search'",
"=>",
"null",
",",
"'_resource'",
"=>",
"$",
"forum",
",",
"'isModerator'",
"=>",
"$",
"isModerator",
",",
"'categories'",
"=>",
"$",
"categories",
",",
"'hasSubscribed'",
"=>",
"$",
"hasSubscribed",
",",
"'workspace'",
"=>",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
"->",
"getWorkspace",
"(",
")",
")",
";",
"}"
] | @Route(
"/{forum}/category",
name="claro_forum_categories",
defaults={"page"=1}
)
@Template("ClarolineForumBundle::index.html.twig")
@param Forum $forum
@param User $user | [
"@Route",
"(",
"/",
"{",
"forum",
"}",
"/",
"category",
"name",
"=",
"claro_forum_categories",
"defaults",
"=",
"{",
"page",
"=",
"1",
"}",
")",
"@Template",
"(",
"ClarolineForumBundle",
"::",
"index",
".",
"html",
".",
"twig",
")"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L77-L99 |
claroline/ForumBundle | Controller/ForumController.php | ForumController.subjectsAction | public function subjectsAction(Category $category, $page, $max)
{
$forum = $category->getForum();
$this->checkAccess($forum);
$pager = $this->manager->getSubjectsPager($category, $page, $max);
$subjectsIds = array();
$lastMessages = array();
foreach ($pager as $subject) {
$subjectsIds[] = $subject['id'];
}
$messages = $this->manager->getLastMessagesBySubjectsIds($subjectsIds);
foreach ($messages as $message) {
$lastMessages[$message->getSubject()->getId()] = $message;
}
$collection = new ResourceCollection(array($forum->getResourceNode()));
$isAnon = $this->isAnon();
$canCreateSubject = $this->authorization->isGranted('post', $collection);
$isModerator = $this->authorization->isGranted('moderate', $collection) &&
!$isAnon;
$logs = array();
if (!$isAnon) {
$securityToken = $this->tokenStorage->getToken();
if (!is_null($securityToken)) {
$user = $securityToken->getUser();
$logs = $this->manager->getSubjectsReadingLogs($user, $forum->getResourceNode());
}
}
$lastAccessDates = array();
foreach ($logs as $log) {
$details = $log->getDetails();
$subjectId = $details['subject']['id'];
if (!isset($lastAccessDates[$subjectId])) {
$lastAccessDates[$subjectId] = $log->getDateLog();
}
}
return array(
'pager' => $pager,
'_resource' => $forum,
'canCreateSubject' => $canCreateSubject,
'isModerator' => $isModerator,
'category' => $category,
'max' => $max,
'lastMessages' => $lastMessages,
'workspace' => $forum->getResourceNode()->getWorkspace(),
'lastAccessDates' => $lastAccessDates,
'isAnon' => $isAnon
);
} | php | public function subjectsAction(Category $category, $page, $max)
{
$forum = $category->getForum();
$this->checkAccess($forum);
$pager = $this->manager->getSubjectsPager($category, $page, $max);
$subjectsIds = array();
$lastMessages = array();
foreach ($pager as $subject) {
$subjectsIds[] = $subject['id'];
}
$messages = $this->manager->getLastMessagesBySubjectsIds($subjectsIds);
foreach ($messages as $message) {
$lastMessages[$message->getSubject()->getId()] = $message;
}
$collection = new ResourceCollection(array($forum->getResourceNode()));
$isAnon = $this->isAnon();
$canCreateSubject = $this->authorization->isGranted('post', $collection);
$isModerator = $this->authorization->isGranted('moderate', $collection) &&
!$isAnon;
$logs = array();
if (!$isAnon) {
$securityToken = $this->tokenStorage->getToken();
if (!is_null($securityToken)) {
$user = $securityToken->getUser();
$logs = $this->manager->getSubjectsReadingLogs($user, $forum->getResourceNode());
}
}
$lastAccessDates = array();
foreach ($logs as $log) {
$details = $log->getDetails();
$subjectId = $details['subject']['id'];
if (!isset($lastAccessDates[$subjectId])) {
$lastAccessDates[$subjectId] = $log->getDateLog();
}
}
return array(
'pager' => $pager,
'_resource' => $forum,
'canCreateSubject' => $canCreateSubject,
'isModerator' => $isModerator,
'category' => $category,
'max' => $max,
'lastMessages' => $lastMessages,
'workspace' => $forum->getResourceNode()->getWorkspace(),
'lastAccessDates' => $lastAccessDates,
'isAnon' => $isAnon
);
} | [
"public",
"function",
"subjectsAction",
"(",
"Category",
"$",
"category",
",",
"$",
"page",
",",
"$",
"max",
")",
"{",
"$",
"forum",
"=",
"$",
"category",
"->",
"getForum",
"(",
")",
";",
"$",
"this",
"->",
"checkAccess",
"(",
"$",
"forum",
")",
";",
"$",
"pager",
"=",
"$",
"this",
"->",
"manager",
"->",
"getSubjectsPager",
"(",
"$",
"category",
",",
"$",
"page",
",",
"$",
"max",
")",
";",
"$",
"subjectsIds",
"=",
"array",
"(",
")",
";",
"$",
"lastMessages",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"pager",
"as",
"$",
"subject",
")",
"{",
"$",
"subjectsIds",
"[",
"]",
"=",
"$",
"subject",
"[",
"'id'",
"]",
";",
"}",
"$",
"messages",
"=",
"$",
"this",
"->",
"manager",
"->",
"getLastMessagesBySubjectsIds",
"(",
"$",
"subjectsIds",
")",
";",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"message",
")",
"{",
"$",
"lastMessages",
"[",
"$",
"message",
"->",
"getSubject",
"(",
")",
"->",
"getId",
"(",
")",
"]",
"=",
"$",
"message",
";",
"}",
"$",
"collection",
"=",
"new",
"ResourceCollection",
"(",
"array",
"(",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
")",
")",
";",
"$",
"isAnon",
"=",
"$",
"this",
"->",
"isAnon",
"(",
")",
";",
"$",
"canCreateSubject",
"=",
"$",
"this",
"->",
"authorization",
"->",
"isGranted",
"(",
"'post'",
",",
"$",
"collection",
")",
";",
"$",
"isModerator",
"=",
"$",
"this",
"->",
"authorization",
"->",
"isGranted",
"(",
"'moderate'",
",",
"$",
"collection",
")",
"&&",
"!",
"$",
"isAnon",
";",
"$",
"logs",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"$",
"isAnon",
")",
"{",
"$",
"securityToken",
"=",
"$",
"this",
"->",
"tokenStorage",
"->",
"getToken",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"securityToken",
")",
")",
"{",
"$",
"user",
"=",
"$",
"securityToken",
"->",
"getUser",
"(",
")",
";",
"$",
"logs",
"=",
"$",
"this",
"->",
"manager",
"->",
"getSubjectsReadingLogs",
"(",
"$",
"user",
",",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
")",
";",
"}",
"}",
"$",
"lastAccessDates",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"logs",
"as",
"$",
"log",
")",
"{",
"$",
"details",
"=",
"$",
"log",
"->",
"getDetails",
"(",
")",
";",
"$",
"subjectId",
"=",
"$",
"details",
"[",
"'subject'",
"]",
"[",
"'id'",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"lastAccessDates",
"[",
"$",
"subjectId",
"]",
")",
")",
"{",
"$",
"lastAccessDates",
"[",
"$",
"subjectId",
"]",
"=",
"$",
"log",
"->",
"getDateLog",
"(",
")",
";",
"}",
"}",
"return",
"array",
"(",
"'pager'",
"=>",
"$",
"pager",
",",
"'_resource'",
"=>",
"$",
"forum",
",",
"'canCreateSubject'",
"=>",
"$",
"canCreateSubject",
",",
"'isModerator'",
"=>",
"$",
"isModerator",
",",
"'category'",
"=>",
"$",
"category",
",",
"'max'",
"=>",
"$",
"max",
",",
"'lastMessages'",
"=>",
"$",
"lastMessages",
",",
"'workspace'",
"=>",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
"->",
"getWorkspace",
"(",
")",
",",
"'lastAccessDates'",
"=>",
"$",
"lastAccessDates",
",",
"'isAnon'",
"=>",
"$",
"isAnon",
")",
";",
"}"
] | @Route(
"/category/{category}/subjects/page/{page}/max/{max}",
name="claro_forum_subjects",
defaults={"page"=1, "max"=20},
options={"expose"=true}
)
@Template()
@param Category $category
@param integer $page
@param integer $max | [
"@Route",
"(",
"/",
"category",
"/",
"{",
"category",
"}",
"/",
"subjects",
"/",
"page",
"/",
"{",
"page",
"}",
"/",
"max",
"/",
"{",
"max",
"}",
"name",
"=",
"claro_forum_subjects",
"defaults",
"=",
"{",
"page",
"=",
"1",
"max",
"=",
"20",
"}",
"options",
"=",
"{",
"expose",
"=",
"true",
"}",
")",
"@Template",
"()"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L114-L170 |
claroline/ForumBundle | Controller/ForumController.php | ForumController.subjectFormAction | public function subjectFormAction(Category $category)
{
$forum = $category->getForum();
$collection = new ResourceCollection(array($forum->getResourceNode()));
if (!$this->authorization->isGranted('post', $collection)) {
throw new AccessDeniedException($collection->getErrorsForDisplay());
}
$formSubject = $this->get('form.factory')->create(new SubjectType());
return array(
'_resource' => $forum,
'form' => $formSubject->createView(),
'category' => $category,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
} | php | public function subjectFormAction(Category $category)
{
$forum = $category->getForum();
$collection = new ResourceCollection(array($forum->getResourceNode()));
if (!$this->authorization->isGranted('post', $collection)) {
throw new AccessDeniedException($collection->getErrorsForDisplay());
}
$formSubject = $this->get('form.factory')->create(new SubjectType());
return array(
'_resource' => $forum,
'form' => $formSubject->createView(),
'category' => $category,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
} | [
"public",
"function",
"subjectFormAction",
"(",
"Category",
"$",
"category",
")",
"{",
"$",
"forum",
"=",
"$",
"category",
"->",
"getForum",
"(",
")",
";",
"$",
"collection",
"=",
"new",
"ResourceCollection",
"(",
"array",
"(",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"authorization",
"->",
"isGranted",
"(",
"'post'",
",",
"$",
"collection",
")",
")",
"{",
"throw",
"new",
"AccessDeniedException",
"(",
"$",
"collection",
"->",
"getErrorsForDisplay",
"(",
")",
")",
";",
"}",
"$",
"formSubject",
"=",
"$",
"this",
"->",
"get",
"(",
"'form.factory'",
")",
"->",
"create",
"(",
"new",
"SubjectType",
"(",
")",
")",
";",
"return",
"array",
"(",
"'_resource'",
"=>",
"$",
"forum",
",",
"'form'",
"=>",
"$",
"formSubject",
"->",
"createView",
"(",
")",
",",
"'category'",
"=>",
"$",
"category",
",",
"'workspace'",
"=>",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
"->",
"getWorkspace",
"(",
")",
")",
";",
"}"
] | @Route(
"/form/subject/{category}",
name="claro_forum_form_subject_creation"
)
@ParamConverter("authenticatedUser", options={"authenticatedUser" = true})
@Template()
@param Category $category | [
"@Route",
"(",
"/",
"form",
"/",
"subject",
"/",
"{",
"category",
"}",
"name",
"=",
"claro_forum_form_subject_creation",
")",
"@ParamConverter",
"(",
"authenticatedUser",
"options",
"=",
"{",
"authenticatedUser",
"=",
"true",
"}",
")",
"@Template",
"()"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L182-L199 |
claroline/ForumBundle | Controller/ForumController.php | ForumController.categoryFormAction | public function categoryFormAction(Forum $forum)
{
$collection = new ResourceCollection(array($forum->getResourceNode()));
if (!$this->authorization->isGranted('post', $collection)) {
throw new AccessDeniedException($collection->getErrorsForDisplay());
}
$formCategory = $this->get('form.factory')->create(new CategoryType());
return array(
'_resource' => $forum,
'form' => $formCategory->createView(),
'workspace' => $forum->getResourceNode()->getWorkspace()
);
} | php | public function categoryFormAction(Forum $forum)
{
$collection = new ResourceCollection(array($forum->getResourceNode()));
if (!$this->authorization->isGranted('post', $collection)) {
throw new AccessDeniedException($collection->getErrorsForDisplay());
}
$formCategory = $this->get('form.factory')->create(new CategoryType());
return array(
'_resource' => $forum,
'form' => $formCategory->createView(),
'workspace' => $forum->getResourceNode()->getWorkspace()
);
} | [
"public",
"function",
"categoryFormAction",
"(",
"Forum",
"$",
"forum",
")",
"{",
"$",
"collection",
"=",
"new",
"ResourceCollection",
"(",
"array",
"(",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"authorization",
"->",
"isGranted",
"(",
"'post'",
",",
"$",
"collection",
")",
")",
"{",
"throw",
"new",
"AccessDeniedException",
"(",
"$",
"collection",
"->",
"getErrorsForDisplay",
"(",
")",
")",
";",
"}",
"$",
"formCategory",
"=",
"$",
"this",
"->",
"get",
"(",
"'form.factory'",
")",
"->",
"create",
"(",
"new",
"CategoryType",
"(",
")",
")",
";",
"return",
"array",
"(",
"'_resource'",
"=>",
"$",
"forum",
",",
"'form'",
"=>",
"$",
"formCategory",
"->",
"createView",
"(",
")",
",",
"'workspace'",
"=>",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
"->",
"getWorkspace",
"(",
")",
")",
";",
"}"
] | @Route(
"/form/category/{forum}",
name="claro_forum_form_category_creation"
)
@ParamConverter("authenticatedUser", options={"authenticatedUser" = true})
@Template()
@param Forum $forum | [
"@Route",
"(",
"/",
"form",
"/",
"category",
"/",
"{",
"forum",
"}",
"name",
"=",
"claro_forum_form_category_creation",
")",
"@ParamConverter",
"(",
"authenticatedUser",
"options",
"=",
"{",
"authenticatedUser",
"=",
"true",
"}",
")",
"@Template",
"()"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L211-L226 |
claroline/ForumBundle | Controller/ForumController.php | ForumController.createSubjectAction | public function createSubjectAction(Category $category)
{
$forum = $category->getForum();
$collection = new ResourceCollection(array($forum->getResourceNode()));
if (!$this->authorization->isGranted('post', $collection)) {
throw new AccessDeniedException($collection->getErrorsForDisplay());
}
$form = $this->get('form.factory')->create(new SubjectType(), new Subject);
$form->handleRequest($this->get('request'));
if ($form->isValid()) {
$user = $this->tokenStorage->getToken()->getUser();
$subject = $form->getData();
$subject->setCreator($user);
$subject->setAuthor($user->getFirstName() . ' ' . $user->getLastName());
//instantiation of the new resources
$subject->setCategory($category);
$this->manager->createSubject($subject);
$dataMessage = $form->get('message')->getData();
if ($dataMessage['content'] !== null) {
$message = new Message();
$message->setContent($dataMessage['content']);
$message->setCreator($user);
$message->setAuthor($user->getFirstName() . ' ' . $user->getLastName());
$message->setSubject($subject);
$this->manager->createMessage($message, $subject);
return new RedirectResponse(
$this->generateUrl('claro_forum_subjects', array('category' => $category->getId()))
);
}
}
$form->get('message')->addError(
new FormError($this->get('translator')->trans('field_content_required', array(), 'forum'))
);
return array(
'form' => $form->createView(),
'_resource' => $forum,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
} | php | public function createSubjectAction(Category $category)
{
$forum = $category->getForum();
$collection = new ResourceCollection(array($forum->getResourceNode()));
if (!$this->authorization->isGranted('post', $collection)) {
throw new AccessDeniedException($collection->getErrorsForDisplay());
}
$form = $this->get('form.factory')->create(new SubjectType(), new Subject);
$form->handleRequest($this->get('request'));
if ($form->isValid()) {
$user = $this->tokenStorage->getToken()->getUser();
$subject = $form->getData();
$subject->setCreator($user);
$subject->setAuthor($user->getFirstName() . ' ' . $user->getLastName());
//instantiation of the new resources
$subject->setCategory($category);
$this->manager->createSubject($subject);
$dataMessage = $form->get('message')->getData();
if ($dataMessage['content'] !== null) {
$message = new Message();
$message->setContent($dataMessage['content']);
$message->setCreator($user);
$message->setAuthor($user->getFirstName() . ' ' . $user->getLastName());
$message->setSubject($subject);
$this->manager->createMessage($message, $subject);
return new RedirectResponse(
$this->generateUrl('claro_forum_subjects', array('category' => $category->getId()))
);
}
}
$form->get('message')->addError(
new FormError($this->get('translator')->trans('field_content_required', array(), 'forum'))
);
return array(
'form' => $form->createView(),
'_resource' => $forum,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
} | [
"public",
"function",
"createSubjectAction",
"(",
"Category",
"$",
"category",
")",
"{",
"$",
"forum",
"=",
"$",
"category",
"->",
"getForum",
"(",
")",
";",
"$",
"collection",
"=",
"new",
"ResourceCollection",
"(",
"array",
"(",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"authorization",
"->",
"isGranted",
"(",
"'post'",
",",
"$",
"collection",
")",
")",
"{",
"throw",
"new",
"AccessDeniedException",
"(",
"$",
"collection",
"->",
"getErrorsForDisplay",
"(",
")",
")",
";",
"}",
"$",
"form",
"=",
"$",
"this",
"->",
"get",
"(",
"'form.factory'",
")",
"->",
"create",
"(",
"new",
"SubjectType",
"(",
")",
",",
"new",
"Subject",
")",
";",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"this",
"->",
"get",
"(",
"'request'",
")",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"tokenStorage",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"$",
"subject",
"=",
"$",
"form",
"->",
"getData",
"(",
")",
";",
"$",
"subject",
"->",
"setCreator",
"(",
"$",
"user",
")",
";",
"$",
"subject",
"->",
"setAuthor",
"(",
"$",
"user",
"->",
"getFirstName",
"(",
")",
".",
"' '",
".",
"$",
"user",
"->",
"getLastName",
"(",
")",
")",
";",
"//instantiation of the new resources",
"$",
"subject",
"->",
"setCategory",
"(",
"$",
"category",
")",
";",
"$",
"this",
"->",
"manager",
"->",
"createSubject",
"(",
"$",
"subject",
")",
";",
"$",
"dataMessage",
"=",
"$",
"form",
"->",
"get",
"(",
"'message'",
")",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"$",
"dataMessage",
"[",
"'content'",
"]",
"!==",
"null",
")",
"{",
"$",
"message",
"=",
"new",
"Message",
"(",
")",
";",
"$",
"message",
"->",
"setContent",
"(",
"$",
"dataMessage",
"[",
"'content'",
"]",
")",
";",
"$",
"message",
"->",
"setCreator",
"(",
"$",
"user",
")",
";",
"$",
"message",
"->",
"setAuthor",
"(",
"$",
"user",
"->",
"getFirstName",
"(",
")",
".",
"' '",
".",
"$",
"user",
"->",
"getLastName",
"(",
")",
")",
";",
"$",
"message",
"->",
"setSubject",
"(",
"$",
"subject",
")",
";",
"$",
"this",
"->",
"manager",
"->",
"createMessage",
"(",
"$",
"message",
",",
"$",
"subject",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'claro_forum_subjects'",
",",
"array",
"(",
"'category'",
"=>",
"$",
"category",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}",
"}",
"$",
"form",
"->",
"get",
"(",
"'message'",
")",
"->",
"addError",
"(",
"new",
"FormError",
"(",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'field_content_required'",
",",
"array",
"(",
")",
",",
"'forum'",
")",
")",
")",
";",
"return",
"array",
"(",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
"'_resource'",
"=>",
"$",
"forum",
",",
"'workspace'",
"=>",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
"->",
"getWorkspace",
"(",
")",
")",
";",
"}"
] | The form submission is working but I had to do some weird things to make it works.
@Route(
"/subject/create/{category}",
name="claro_forum_create_subject"
)
@ParamConverter("authenticatedUser", options={"authenticatedUser" = true})
@Template("ClarolineForumBundle:Forum:subjectForm.html.twig")
@param Category $category
@throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
@throws \Exception
@return array|\Symfony\Component\HttpFoundation\RedirectResponse | [
"The",
"form",
"submission",
"is",
"working",
"but",
"I",
"had",
"to",
"do",
"some",
"weird",
"things",
"to",
"make",
"it",
"works",
"."
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L272-L317 |
claroline/ForumBundle | Controller/ForumController.php | ForumController.messagesAction | public function messagesAction(Subject $subject, $page, $max)
{
$forum = $subject->getCategory()->getForum();
$this->checkAccess($forum);
$isAnon = $this->isAnon();
$isModerator = $this->authorization->isGranted(
'moderate',
new ResourceCollection(array($forum->getResourceNode()))
) && !$isAnon;
$pager = $this->manager->getMessagesPager($subject, $page, $max);
$collection = new ResourceCollection(array($forum->getResourceNode()));
$canPost = $this->authorization->isGranted('post', $collection);
$form = $this->get('form.factory')->create(new MessageType());
if (!$isAnon) {
$securityToken = $this->tokenStorage->getToken();
if (!is_null($securityToken)) {
$user = $securityToken->getUser();
$event = new ReadSubjectEvent($subject);
$event->setDoer($user);
$this->dispatch($event);
}
}
return array(
'subject' => $subject,
'pager' => $pager,
'_resource' => $forum,
'isModerator' => $isModerator,
'form' => $form->createView(),
'category' => $subject->getCategory(),
'max' => $max,
'canPost' => $canPost,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
} | php | public function messagesAction(Subject $subject, $page, $max)
{
$forum = $subject->getCategory()->getForum();
$this->checkAccess($forum);
$isAnon = $this->isAnon();
$isModerator = $this->authorization->isGranted(
'moderate',
new ResourceCollection(array($forum->getResourceNode()))
) && !$isAnon;
$pager = $this->manager->getMessagesPager($subject, $page, $max);
$collection = new ResourceCollection(array($forum->getResourceNode()));
$canPost = $this->authorization->isGranted('post', $collection);
$form = $this->get('form.factory')->create(new MessageType());
if (!$isAnon) {
$securityToken = $this->tokenStorage->getToken();
if (!is_null($securityToken)) {
$user = $securityToken->getUser();
$event = new ReadSubjectEvent($subject);
$event->setDoer($user);
$this->dispatch($event);
}
}
return array(
'subject' => $subject,
'pager' => $pager,
'_resource' => $forum,
'isModerator' => $isModerator,
'form' => $form->createView(),
'category' => $subject->getCategory(),
'max' => $max,
'canPost' => $canPost,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
} | [
"public",
"function",
"messagesAction",
"(",
"Subject",
"$",
"subject",
",",
"$",
"page",
",",
"$",
"max",
")",
"{",
"$",
"forum",
"=",
"$",
"subject",
"->",
"getCategory",
"(",
")",
"->",
"getForum",
"(",
")",
";",
"$",
"this",
"->",
"checkAccess",
"(",
"$",
"forum",
")",
";",
"$",
"isAnon",
"=",
"$",
"this",
"->",
"isAnon",
"(",
")",
";",
"$",
"isModerator",
"=",
"$",
"this",
"->",
"authorization",
"->",
"isGranted",
"(",
"'moderate'",
",",
"new",
"ResourceCollection",
"(",
"array",
"(",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
")",
")",
")",
"&&",
"!",
"$",
"isAnon",
";",
"$",
"pager",
"=",
"$",
"this",
"->",
"manager",
"->",
"getMessagesPager",
"(",
"$",
"subject",
",",
"$",
"page",
",",
"$",
"max",
")",
";",
"$",
"collection",
"=",
"new",
"ResourceCollection",
"(",
"array",
"(",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
")",
")",
";",
"$",
"canPost",
"=",
"$",
"this",
"->",
"authorization",
"->",
"isGranted",
"(",
"'post'",
",",
"$",
"collection",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"get",
"(",
"'form.factory'",
")",
"->",
"create",
"(",
"new",
"MessageType",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"isAnon",
")",
"{",
"$",
"securityToken",
"=",
"$",
"this",
"->",
"tokenStorage",
"->",
"getToken",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"securityToken",
")",
")",
"{",
"$",
"user",
"=",
"$",
"securityToken",
"->",
"getUser",
"(",
")",
";",
"$",
"event",
"=",
"new",
"ReadSubjectEvent",
"(",
"$",
"subject",
")",
";",
"$",
"event",
"->",
"setDoer",
"(",
"$",
"user",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"$",
"event",
")",
";",
"}",
"}",
"return",
"array",
"(",
"'subject'",
"=>",
"$",
"subject",
",",
"'pager'",
"=>",
"$",
"pager",
",",
"'_resource'",
"=>",
"$",
"forum",
",",
"'isModerator'",
"=>",
"$",
"isModerator",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
"'category'",
"=>",
"$",
"subject",
"->",
"getCategory",
"(",
")",
",",
"'max'",
"=>",
"$",
"max",
",",
"'canPost'",
"=>",
"$",
"canPost",
",",
"'workspace'",
"=>",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
"->",
"getWorkspace",
"(",
")",
")",
";",
"}"
] | @Route(
"/subject/{subject}/messages/page/{page}/max/{max}",
name="claro_forum_messages",
defaults={"page"=1, "max"= 20},
options={"expose"=true}
)
@Template()
@param Subject $subject
@param integer $page
@param integer $max | [
"@Route",
"(",
"/",
"subject",
"/",
"{",
"subject",
"}",
"/",
"messages",
"/",
"page",
"/",
"{",
"page",
"}",
"/",
"max",
"/",
"{",
"max",
"}",
"name",
"=",
"claro_forum_messages",
"defaults",
"=",
"{",
"page",
"=",
"1",
"max",
"=",
"20",
"}",
"options",
"=",
"{",
"expose",
"=",
"true",
"}",
")",
"@Template",
"()"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L332-L368 |
claroline/ForumBundle | Controller/ForumController.php | ForumController.createMessageAction | public function createMessageAction(Subject $subject)
{
$form = $this->container->get('form.factory')->create(new MessageType, new Message());
$form->handleRequest($this->get('request'));
if ($form->isValid()) {
$message = $form->getData();
$this->manager->createMessage($message, $subject);
}
return new RedirectResponse(
$this->generateUrl('claro_forum_messages', array('subject' => $subject->getId()))
);
} | php | public function createMessageAction(Subject $subject)
{
$form = $this->container->get('form.factory')->create(new MessageType, new Message());
$form->handleRequest($this->get('request'));
if ($form->isValid()) {
$message = $form->getData();
$this->manager->createMessage($message, $subject);
}
return new RedirectResponse(
$this->generateUrl('claro_forum_messages', array('subject' => $subject->getId()))
);
} | [
"public",
"function",
"createMessageAction",
"(",
"Subject",
"$",
"subject",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'form.factory'",
")",
"->",
"create",
"(",
"new",
"MessageType",
",",
"new",
"Message",
"(",
")",
")",
";",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"this",
"->",
"get",
"(",
"'request'",
")",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"message",
"=",
"$",
"form",
"->",
"getData",
"(",
")",
";",
"$",
"this",
"->",
"manager",
"->",
"createMessage",
"(",
"$",
"message",
",",
"$",
"subject",
")",
";",
"}",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'claro_forum_messages'",
",",
"array",
"(",
"'subject'",
"=>",
"$",
"subject",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}"
] | @Route(
"/create/message/{subject}",
name="claro_forum_create_message"
)
@ParamConverter("authenticatedUser", options={"authenticatedUser" = true})
@param Subject $subject | [
"@Route",
"(",
"/",
"create",
"/",
"message",
"/",
"{",
"subject",
"}",
"name",
"=",
"claro_forum_create_message",
")",
"@ParamConverter",
"(",
"authenticatedUser",
"options",
"=",
"{",
"authenticatedUser",
"=",
"true",
"}",
")"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L379-L393 |
claroline/ForumBundle | Controller/ForumController.php | ForumController.editMessageAction | public function editMessageAction(Message $message)
{
$subject = $message->getSubject();
$forum = $subject->getCategory()->getForum();
$isModerator = $this->authorization->isGranted('moderate', new ResourceCollection(array($forum->getResourceNode())));
if (!$isModerator && $this->tokenStorage->getToken()->getUser() !== $message->getCreator()) {
throw new AccessDeniedException();
}
$oldContent = $message->getContent();
$form = $this->container->get('form.factory')->create(new MessageType, new Message());
$form->handleRequest($this->get('request'));
if ($form->isValid()) {
$newContent = $form->get('content')->getData();
$this->manager->editMessage($message, $oldContent, $newContent);
return new RedirectResponse(
$this->generateUrl('claro_forum_messages', array('subject' => $subject->getId()))
);
}
return array(
'subject' => $subject,
'form' => $form->createView(),
'message' => $message,
'_resource' => $forum,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
} | php | public function editMessageAction(Message $message)
{
$subject = $message->getSubject();
$forum = $subject->getCategory()->getForum();
$isModerator = $this->authorization->isGranted('moderate', new ResourceCollection(array($forum->getResourceNode())));
if (!$isModerator && $this->tokenStorage->getToken()->getUser() !== $message->getCreator()) {
throw new AccessDeniedException();
}
$oldContent = $message->getContent();
$form = $this->container->get('form.factory')->create(new MessageType, new Message());
$form->handleRequest($this->get('request'));
if ($form->isValid()) {
$newContent = $form->get('content')->getData();
$this->manager->editMessage($message, $oldContent, $newContent);
return new RedirectResponse(
$this->generateUrl('claro_forum_messages', array('subject' => $subject->getId()))
);
}
return array(
'subject' => $subject,
'form' => $form->createView(),
'message' => $message,
'_resource' => $forum,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
} | [
"public",
"function",
"editMessageAction",
"(",
"Message",
"$",
"message",
")",
"{",
"$",
"subject",
"=",
"$",
"message",
"->",
"getSubject",
"(",
")",
";",
"$",
"forum",
"=",
"$",
"subject",
"->",
"getCategory",
"(",
")",
"->",
"getForum",
"(",
")",
";",
"$",
"isModerator",
"=",
"$",
"this",
"->",
"authorization",
"->",
"isGranted",
"(",
"'moderate'",
",",
"new",
"ResourceCollection",
"(",
"array",
"(",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
")",
")",
")",
";",
"if",
"(",
"!",
"$",
"isModerator",
"&&",
"$",
"this",
"->",
"tokenStorage",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
"!==",
"$",
"message",
"->",
"getCreator",
"(",
")",
")",
"{",
"throw",
"new",
"AccessDeniedException",
"(",
")",
";",
"}",
"$",
"oldContent",
"=",
"$",
"message",
"->",
"getContent",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'form.factory'",
")",
"->",
"create",
"(",
"new",
"MessageType",
",",
"new",
"Message",
"(",
")",
")",
";",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"this",
"->",
"get",
"(",
"'request'",
")",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"newContent",
"=",
"$",
"form",
"->",
"get",
"(",
"'content'",
")",
"->",
"getData",
"(",
")",
";",
"$",
"this",
"->",
"manager",
"->",
"editMessage",
"(",
"$",
"message",
",",
"$",
"oldContent",
",",
"$",
"newContent",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'claro_forum_messages'",
",",
"array",
"(",
"'subject'",
"=>",
"$",
"subject",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}",
"return",
"array",
"(",
"'subject'",
"=>",
"$",
"subject",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
"'message'",
"=>",
"$",
"message",
",",
"'_resource'",
"=>",
"$",
"forum",
",",
"'workspace'",
"=>",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
"->",
"getWorkspace",
"(",
")",
")",
";",
"}"
] | @Route(
"/edit/message/{message}",
name="claro_forum_edit_message"
)
@Template("ClarolineForumBundle:Forum:editMessageForm.html.twig")
@param Message $message | [
"@Route",
"(",
"/",
"edit",
"/",
"message",
"/",
"{",
"message",
"}",
"name",
"=",
"claro_forum_edit_message",
")"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L433-L463 |
claroline/ForumBundle | Controller/ForumController.php | ForumController.deleteCategory | public function deleteCategory(Category $category)
{
$forum = $category->getForum();
if ($this->authorization->isGranted('moderate', new ResourceCollection(array($category->getForum()->getResourceNode())))) {
$this->manager->deleteCategory($category);
return new RedirectResponse(
$this->generateUrl('claro_forum_categories', array('forum' => $forum->getId()))
);
}
throw new AccessDeniedException();
} | php | public function deleteCategory(Category $category)
{
$forum = $category->getForum();
if ($this->authorization->isGranted('moderate', new ResourceCollection(array($category->getForum()->getResourceNode())))) {
$this->manager->deleteCategory($category);
return new RedirectResponse(
$this->generateUrl('claro_forum_categories', array('forum' => $forum->getId()))
);
}
throw new AccessDeniedException();
} | [
"public",
"function",
"deleteCategory",
"(",
"Category",
"$",
"category",
")",
"{",
"$",
"forum",
"=",
"$",
"category",
"->",
"getForum",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"authorization",
"->",
"isGranted",
"(",
"'moderate'",
",",
"new",
"ResourceCollection",
"(",
"array",
"(",
"$",
"category",
"->",
"getForum",
"(",
")",
"->",
"getResourceNode",
"(",
")",
")",
")",
")",
")",
"{",
"$",
"this",
"->",
"manager",
"->",
"deleteCategory",
"(",
"$",
"category",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'claro_forum_categories'",
",",
"array",
"(",
"'forum'",
"=>",
"$",
"forum",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}",
"throw",
"new",
"AccessDeniedException",
"(",
")",
";",
"}"
] | @Route(
"/delete/category/{category}",
name="claro_forum_delete_category"
)
@param Category $category | [
"@Route",
"(",
"/",
"delete",
"/",
"category",
"/",
"{",
"category",
"}",
"name",
"=",
"claro_forum_delete_category",
")"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L531-L545 |
claroline/ForumBundle | Controller/ForumController.php | ForumController.deleteMessageAction | public function deleteMessageAction(Message $message)
{
if ($this->authorization->isGranted('moderate', new ResourceCollection(array($message->getSubject()->getCategory()->getForum()->getResourceNode())))) {
$this->manager->deleteMessage($message);
return new RedirectResponse(
$this->generateUrl('claro_forum_messages', array('subject' => $message->getSubject()->getId()))
);
}
throw new AccessDeniedException();
} | php | public function deleteMessageAction(Message $message)
{
if ($this->authorization->isGranted('moderate', new ResourceCollection(array($message->getSubject()->getCategory()->getForum()->getResourceNode())))) {
$this->manager->deleteMessage($message);
return new RedirectResponse(
$this->generateUrl('claro_forum_messages', array('subject' => $message->getSubject()->getId()))
);
}
throw new AccessDeniedException();
} | [
"public",
"function",
"deleteMessageAction",
"(",
"Message",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"authorization",
"->",
"isGranted",
"(",
"'moderate'",
",",
"new",
"ResourceCollection",
"(",
"array",
"(",
"$",
"message",
"->",
"getSubject",
"(",
")",
"->",
"getCategory",
"(",
")",
"->",
"getForum",
"(",
")",
"->",
"getResourceNode",
"(",
")",
")",
")",
")",
")",
"{",
"$",
"this",
"->",
"manager",
"->",
"deleteMessage",
"(",
"$",
"message",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'claro_forum_messages'",
",",
"array",
"(",
"'subject'",
"=>",
"$",
"message",
"->",
"getSubject",
"(",
")",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}",
"throw",
"new",
"AccessDeniedException",
"(",
")",
";",
"}"
] | @Route(
"/delete/message/{message}",
name="claro_forum_delete_message"
)
@param \Claroline\ForumBundle\Entity\Message $message | [
"@Route",
"(",
"/",
"delete",
"/",
"message",
"/",
"{",
"message",
"}",
"name",
"=",
"claro_forum_delete_message",
")"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L659-L670 |
claroline/ForumBundle | Controller/ForumController.php | ForumController.subscribeAction | public function subscribeAction(Forum $forum, User $user)
{
$this->manager->subscribe($forum, $user);
return new RedirectResponse(
$this->generateUrl('claro_forum_categories', array('forum' => $forum->getId()))
);
} | php | public function subscribeAction(Forum $forum, User $user)
{
$this->manager->subscribe($forum, $user);
return new RedirectResponse(
$this->generateUrl('claro_forum_categories', array('forum' => $forum->getId()))
);
} | [
"public",
"function",
"subscribeAction",
"(",
"Forum",
"$",
"forum",
",",
"User",
"$",
"user",
")",
"{",
"$",
"this",
"->",
"manager",
"->",
"subscribe",
"(",
"$",
"forum",
",",
"$",
"user",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'claro_forum_categories'",
",",
"array",
"(",
"'forum'",
"=>",
"$",
"forum",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}"
] | @Route(
"/subscribe/forum/{forum}",
name="claro_forum_subscribe"
)
@EXT\ParamConverter("user", options={"authenticatedUser" = true})
@param Forum $forum
@param User $user | [
"@Route",
"(",
"/",
"subscribe",
"/",
"forum",
"/",
"{",
"forum",
"}",
"name",
"=",
"claro_forum_subscribe",
")",
"@EXT",
"\\",
"ParamConverter",
"(",
"user",
"options",
"=",
"{",
"authenticatedUser",
"=",
"true",
"}",
")"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L682-L689 |
claroline/ForumBundle | Controller/ForumController.php | ForumController.unsubscribeAction | public function unsubscribeAction(Forum $forum, User $user)
{
$this->manager->unsubscribe($forum, $user);
return new RedirectResponse(
$this->generateUrl('claro_forum_categories', array('forum' => $forum->getId()))
);
} | php | public function unsubscribeAction(Forum $forum, User $user)
{
$this->manager->unsubscribe($forum, $user);
return new RedirectResponse(
$this->generateUrl('claro_forum_categories', array('forum' => $forum->getId()))
);
} | [
"public",
"function",
"unsubscribeAction",
"(",
"Forum",
"$",
"forum",
",",
"User",
"$",
"user",
")",
"{",
"$",
"this",
"->",
"manager",
"->",
"unsubscribe",
"(",
"$",
"forum",
",",
"$",
"user",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'claro_forum_categories'",
",",
"array",
"(",
"'forum'",
"=>",
"$",
"forum",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}"
] | @Route(
"/unsubscribe/forum/{forum}",
name="claro_forum_unsubscribe"
)
@EXT\ParamConverter("user", options={"authenticatedUser" = true})
@param Forum $forum
@param User $user | [
"@Route",
"(",
"/",
"unsubscribe",
"/",
"forum",
"/",
"{",
"forum",
"}",
"name",
"=",
"claro_forum_unsubscribe",
")",
"@EXT",
"\\",
"ParamConverter",
"(",
"user",
"options",
"=",
"{",
"authenticatedUser",
"=",
"true",
"}",
")"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L701-L708 |
claroline/ForumBundle | Controller/ForumController.php | ForumController.deleteSubjectAction | public function deleteSubjectAction(Subject $subject)
{
if ($this->authorization->isGranted('moderate', new ResourceCollection(array($subject->getCategory()->getForum()->getResourceNode())))) {
$this->manager->deleteSubject($subject);
return new RedirectResponse(
$this->generateUrl('claro_forum_subjects', array('category' => $subject->getCategory()->getId()))
);
}
throw new AccessDeniedException();
} | php | public function deleteSubjectAction(Subject $subject)
{
if ($this->authorization->isGranted('moderate', new ResourceCollection(array($subject->getCategory()->getForum()->getResourceNode())))) {
$this->manager->deleteSubject($subject);
return new RedirectResponse(
$this->generateUrl('claro_forum_subjects', array('category' => $subject->getCategory()->getId()))
);
}
throw new AccessDeniedException();
} | [
"public",
"function",
"deleteSubjectAction",
"(",
"Subject",
"$",
"subject",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"authorization",
"->",
"isGranted",
"(",
"'moderate'",
",",
"new",
"ResourceCollection",
"(",
"array",
"(",
"$",
"subject",
"->",
"getCategory",
"(",
")",
"->",
"getForum",
"(",
")",
"->",
"getResourceNode",
"(",
")",
")",
")",
")",
")",
"{",
"$",
"this",
"->",
"manager",
"->",
"deleteSubject",
"(",
"$",
"subject",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'claro_forum_subjects'",
",",
"array",
"(",
"'category'",
"=>",
"$",
"subject",
"->",
"getCategory",
"(",
")",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}",
"throw",
"new",
"AccessDeniedException",
"(",
")",
";",
"}"
] | @Route(
"/delete/subject/{subject}",
name="claro_forum_delete_subject"
)
@param Subject $subject | [
"@Route",
"(",
"/",
"delete",
"/",
"subject",
"/",
"{",
"subject",
"}",
"name",
"=",
"claro_forum_delete_subject",
")"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L718-L730 |
claroline/ForumBundle | Controller/ForumController.php | ForumController.moveMessageAction | public function moveMessageAction(Message $message, Subject $newSubject)
{
$forum = $newSubject->getCategory()->getForum();
$this->checkAccess($forum);
$this->manager->moveMessage($message, $newSubject);
return new RedirectResponse(
$this->generateUrl('claro_forum_subjects', array('category' => $newSubject->getCategory()->getId()))
);
} | php | public function moveMessageAction(Message $message, Subject $newSubject)
{
$forum = $newSubject->getCategory()->getForum();
$this->checkAccess($forum);
$this->manager->moveMessage($message, $newSubject);
return new RedirectResponse(
$this->generateUrl('claro_forum_subjects', array('category' => $newSubject->getCategory()->getId()))
);
} | [
"public",
"function",
"moveMessageAction",
"(",
"Message",
"$",
"message",
",",
"Subject",
"$",
"newSubject",
")",
"{",
"$",
"forum",
"=",
"$",
"newSubject",
"->",
"getCategory",
"(",
")",
"->",
"getForum",
"(",
")",
";",
"$",
"this",
"->",
"checkAccess",
"(",
"$",
"forum",
")",
";",
"$",
"this",
"->",
"manager",
"->",
"moveMessage",
"(",
"$",
"message",
",",
"$",
"newSubject",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'claro_forum_subjects'",
",",
"array",
"(",
"'category'",
"=>",
"$",
"newSubject",
"->",
"getCategory",
"(",
")",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}"
] | @EXT\Route(
"/message/{message}/move/{newSubject}",
name="claro_message_move",
options={"expose"=true}
)
@EXT\Method("GET")
@param Message $message
@param Subject $newSubject | [
"@EXT",
"\\",
"Route",
"(",
"/",
"message",
"/",
"{",
"message",
"}",
"/",
"move",
"/",
"{",
"newSubject",
"}",
"name",
"=",
"claro_message_move",
"options",
"=",
"{",
"expose",
"=",
"true",
"}",
")",
"@EXT",
"\\",
"Method",
"(",
"GET",
")"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L819-L828 |
claroline/ForumBundle | Controller/ForumController.php | ForumController.moveSubjectAction | public function moveSubjectAction(Subject $subject, Category $newCategory)
{
$forum = $newCategory->getForum();
$this->checkAccess($forum);
$this->manager->moveSubject($subject, $newCategory);
return new RedirectResponse(
$this->generateUrl('claro_forum_categories', array('forum' => $forum->getId()))
);
} | php | public function moveSubjectAction(Subject $subject, Category $newCategory)
{
$forum = $newCategory->getForum();
$this->checkAccess($forum);
$this->manager->moveSubject($subject, $newCategory);
return new RedirectResponse(
$this->generateUrl('claro_forum_categories', array('forum' => $forum->getId()))
);
} | [
"public",
"function",
"moveSubjectAction",
"(",
"Subject",
"$",
"subject",
",",
"Category",
"$",
"newCategory",
")",
"{",
"$",
"forum",
"=",
"$",
"newCategory",
"->",
"getForum",
"(",
")",
";",
"$",
"this",
"->",
"checkAccess",
"(",
"$",
"forum",
")",
";",
"$",
"this",
"->",
"manager",
"->",
"moveSubject",
"(",
"$",
"subject",
",",
"$",
"newCategory",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'claro_forum_categories'",
",",
"array",
"(",
"'forum'",
"=>",
"$",
"forum",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}"
] | @EXT\Route(
"/subject/{subject}/move/{newCategory}",
name="claro_subject_move",
options={"expose"=true}
)
@EXT\Method("GET")
@param Subject $subject
@param Category $newCategory | [
"@EXT",
"\\",
"Route",
"(",
"/",
"subject",
"/",
"{",
"subject",
"}",
"/",
"move",
"/",
"{",
"newCategory",
"}",
"name",
"=",
"claro_subject_move",
"options",
"=",
"{",
"expose",
"=",
"true",
"}",
")",
"@EXT",
"\\",
"Method",
"(",
"GET",
")"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L841-L850 |
claroline/ForumBundle | Controller/ForumController.php | ForumController.stickSubjectAction | public function stickSubjectAction(Subject $subject)
{
$forum = $subject->getCategory()->getForum();
$this->checkAccess($forum);
$this->manager->stickSubject($subject);
return new RedirectResponse(
$this->generateUrl('claro_forum_subjects', array('category' => $subject->getCategory()->getId()))
);
} | php | public function stickSubjectAction(Subject $subject)
{
$forum = $subject->getCategory()->getForum();
$this->checkAccess($forum);
$this->manager->stickSubject($subject);
return new RedirectResponse(
$this->generateUrl('claro_forum_subjects', array('category' => $subject->getCategory()->getId()))
);
} | [
"public",
"function",
"stickSubjectAction",
"(",
"Subject",
"$",
"subject",
")",
"{",
"$",
"forum",
"=",
"$",
"subject",
"->",
"getCategory",
"(",
")",
"->",
"getForum",
"(",
")",
";",
"$",
"this",
"->",
"checkAccess",
"(",
"$",
"forum",
")",
";",
"$",
"this",
"->",
"manager",
"->",
"stickSubject",
"(",
"$",
"subject",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'claro_forum_subjects'",
",",
"array",
"(",
"'category'",
"=>",
"$",
"subject",
"->",
"getCategory",
"(",
")",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}"
] | @EXT\Route(
"/stick/subject/{subject}",
name="claro_subject_stick",
options={"expose"=true}
)
@EXT\Method("GET")
@param Subject $subject | [
"@EXT",
"\\",
"Route",
"(",
"/",
"stick",
"/",
"subject",
"/",
"{",
"subject",
"}",
"name",
"=",
"claro_subject_stick",
"options",
"=",
"{",
"expose",
"=",
"true",
"}",
")",
"@EXT",
"\\",
"Method",
"(",
"GET",
")"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L862-L871 |
claroline/ForumBundle | Controller/ForumController.php | ForumController.unstickSubjectAction | public function unstickSubjectAction(Subject $subject)
{
$forum = $subject->getCategory()->getForum();
$this->checkAccess($forum);
$this->manager->unstickSubject($subject);
return new RedirectResponse(
$this->generateUrl('claro_forum_subjects', array('category' => $subject->getCategory()->getId()))
);
} | php | public function unstickSubjectAction(Subject $subject)
{
$forum = $subject->getCategory()->getForum();
$this->checkAccess($forum);
$this->manager->unstickSubject($subject);
return new RedirectResponse(
$this->generateUrl('claro_forum_subjects', array('category' => $subject->getCategory()->getId()))
);
} | [
"public",
"function",
"unstickSubjectAction",
"(",
"Subject",
"$",
"subject",
")",
"{",
"$",
"forum",
"=",
"$",
"subject",
"->",
"getCategory",
"(",
")",
"->",
"getForum",
"(",
")",
";",
"$",
"this",
"->",
"checkAccess",
"(",
"$",
"forum",
")",
";",
"$",
"this",
"->",
"manager",
"->",
"unstickSubject",
"(",
"$",
"subject",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'claro_forum_subjects'",
",",
"array",
"(",
"'category'",
"=>",
"$",
"subject",
"->",
"getCategory",
"(",
")",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}"
] | @EXT\Route(
"/unstick/subject/{subject}",
name="claro_subject_unstick",
options={"expose"=true}
)
@EXT\Method("GET")
@param Subject $subject | [
"@EXT",
"\\",
"Route",
"(",
"/",
"unstick",
"/",
"subject",
"/",
"{",
"subject",
"}",
"name",
"=",
"claro_subject_unstick",
"options",
"=",
"{",
"expose",
"=",
"true",
"}",
")",
"@EXT",
"\\",
"Method",
"(",
"GET",
")"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L883-L892 |
claroline/ForumBundle | Controller/ForumController.php | ForumController.closeSubjectAction | public function closeSubjectAction(Subject $subject)
{
$forum = $subject->getCategory()->getForum();
$this->checkAccess($forum);
$this->manager->closeSubject($subject);
return new RedirectResponse(
$this->generateUrl('claro_forum_subjects', array('category' => $subject->getCategory()->getId()))
);
} | php | public function closeSubjectAction(Subject $subject)
{
$forum = $subject->getCategory()->getForum();
$this->checkAccess($forum);
$this->manager->closeSubject($subject);
return new RedirectResponse(
$this->generateUrl('claro_forum_subjects', array('category' => $subject->getCategory()->getId()))
);
} | [
"public",
"function",
"closeSubjectAction",
"(",
"Subject",
"$",
"subject",
")",
"{",
"$",
"forum",
"=",
"$",
"subject",
"->",
"getCategory",
"(",
")",
"->",
"getForum",
"(",
")",
";",
"$",
"this",
"->",
"checkAccess",
"(",
"$",
"forum",
")",
";",
"$",
"this",
"->",
"manager",
"->",
"closeSubject",
"(",
"$",
"subject",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'claro_forum_subjects'",
",",
"array",
"(",
"'category'",
"=>",
"$",
"subject",
"->",
"getCategory",
"(",
")",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}"
] | @EXT\Route(
"/close/subject/{subject}",
name="claro_subject_close",
options={"expose"=true}
)
@EXT\Method("GET")
@param Subject $subject | [
"@EXT",
"\\",
"Route",
"(",
"/",
"close",
"/",
"subject",
"/",
"{",
"subject",
"}",
"name",
"=",
"claro_subject_close",
"options",
"=",
"{",
"expose",
"=",
"true",
"}",
")",
"@EXT",
"\\",
"Method",
"(",
"GET",
")"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L904-L913 |
claroline/ForumBundle | Controller/ForumController.php | ForumController.openSubjectAction | public function openSubjectAction(Subject $subject)
{
$forum = $subject->getCategory()->getForum();
$this->checkAccess($forum);
$this->manager->openSubject($subject);
return new RedirectResponse(
$this->generateUrl('claro_forum_subjects', array('category' => $subject->getCategory()->getId()))
);
} | php | public function openSubjectAction(Subject $subject)
{
$forum = $subject->getCategory()->getForum();
$this->checkAccess($forum);
$this->manager->openSubject($subject);
return new RedirectResponse(
$this->generateUrl('claro_forum_subjects', array('category' => $subject->getCategory()->getId()))
);
} | [
"public",
"function",
"openSubjectAction",
"(",
"Subject",
"$",
"subject",
")",
"{",
"$",
"forum",
"=",
"$",
"subject",
"->",
"getCategory",
"(",
")",
"->",
"getForum",
"(",
")",
";",
"$",
"this",
"->",
"checkAccess",
"(",
"$",
"forum",
")",
";",
"$",
"this",
"->",
"manager",
"->",
"openSubject",
"(",
"$",
"subject",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'claro_forum_subjects'",
",",
"array",
"(",
"'category'",
"=>",
"$",
"subject",
"->",
"getCategory",
"(",
")",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}"
] | @EXT\Route(
"/open/subject/{subject}",
name="claro_subject_open",
options={"expose"=true}
)
@EXT\Method("GET")
@param Subject $subject | [
"@EXT",
"\\",
"Route",
"(",
"/",
"open",
"/",
"subject",
"/",
"{",
"subject",
"}",
"name",
"=",
"claro_subject_open",
"options",
"=",
"{",
"expose",
"=",
"true",
"}",
")",
"@EXT",
"\\",
"Method",
"(",
"GET",
")"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L925-L934 |
claroline/ForumBundle | Controller/ForumController.php | ForumController.replyMessageAction | public function replyMessageAction(Message $message)
{
$subject = $message->getSubject();
$forum = $subject->getCategory()->getForum();
$reply = new Message();
$form = $this->container->get('form.factory')->create(new MessageType, $reply);
$form->handleRequest($this->get('request'));
if ($form->isValid()) {
$newMsg = $form->getData();
$this->manager->createMessage($newMsg, $subject);
return new RedirectResponse(
$this->generateUrl('claro_forum_messages', array('subject' => $subject->getId()))
);
}
return array(
'subject' => $subject,
'form' => $form->createView(),
'message' => $message,
'_resource' => $forum,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
} | php | public function replyMessageAction(Message $message)
{
$subject = $message->getSubject();
$forum = $subject->getCategory()->getForum();
$reply = new Message();
$form = $this->container->get('form.factory')->create(new MessageType, $reply);
$form->handleRequest($this->get('request'));
if ($form->isValid()) {
$newMsg = $form->getData();
$this->manager->createMessage($newMsg, $subject);
return new RedirectResponse(
$this->generateUrl('claro_forum_messages', array('subject' => $subject->getId()))
);
}
return array(
'subject' => $subject,
'form' => $form->createView(),
'message' => $message,
'_resource' => $forum,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
} | [
"public",
"function",
"replyMessageAction",
"(",
"Message",
"$",
"message",
")",
"{",
"$",
"subject",
"=",
"$",
"message",
"->",
"getSubject",
"(",
")",
";",
"$",
"forum",
"=",
"$",
"subject",
"->",
"getCategory",
"(",
")",
"->",
"getForum",
"(",
")",
";",
"$",
"reply",
"=",
"new",
"Message",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'form.factory'",
")",
"->",
"create",
"(",
"new",
"MessageType",
",",
"$",
"reply",
")",
";",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"this",
"->",
"get",
"(",
"'request'",
")",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"newMsg",
"=",
"$",
"form",
"->",
"getData",
"(",
")",
";",
"$",
"this",
"->",
"manager",
"->",
"createMessage",
"(",
"$",
"newMsg",
",",
"$",
"subject",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'claro_forum_messages'",
",",
"array",
"(",
"'subject'",
"=>",
"$",
"subject",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}",
"return",
"array",
"(",
"'subject'",
"=>",
"$",
"subject",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
"'message'",
"=>",
"$",
"message",
",",
"'_resource'",
"=>",
"$",
"forum",
",",
"'workspace'",
"=>",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
"->",
"getWorkspace",
"(",
")",
")",
";",
"}"
] | @Route(
"/reply/message/{message}",
name="claro_forum_reply_message_form"
)
@ParamConverter("authenticatedUser", options={"authenticatedUser" = true})
@Template("ClarolineForumBundle:Forum:replyMessageForm.html.twig")
@param Message $message | [
"@Route",
"(",
"/",
"reply",
"/",
"message",
"/",
"{",
"message",
"}",
"name",
"=",
"claro_forum_reply_message_form",
")",
"@ParamConverter",
"(",
"authenticatedUser",
"options",
"=",
"{",
"authenticatedUser",
"=",
"true",
"}",
")"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L946-L971 |
claroline/ForumBundle | Controller/ForumController.php | ForumController.activateGlobalNotificationsAction | public function activateGlobalNotificationsAction(Forum $forum)
{
$collection = new ResourceCollection(array($forum->getResourceNode()));
if (!$this->authorization->isGranted('MODERATE', $collection)) {
throw new AccessDeniedException($collection->getErrorsForDisplay());
}
$this->manager->activateGlobalNotifications($forum);
return new RedirectResponse(
$this->generateUrl('claro_forum_categories', array('forum' => $forum->getId()))
);
} | php | public function activateGlobalNotificationsAction(Forum $forum)
{
$collection = new ResourceCollection(array($forum->getResourceNode()));
if (!$this->authorization->isGranted('MODERATE', $collection)) {
throw new AccessDeniedException($collection->getErrorsForDisplay());
}
$this->manager->activateGlobalNotifications($forum);
return new RedirectResponse(
$this->generateUrl('claro_forum_categories', array('forum' => $forum->getId()))
);
} | [
"public",
"function",
"activateGlobalNotificationsAction",
"(",
"Forum",
"$",
"forum",
")",
"{",
"$",
"collection",
"=",
"new",
"ResourceCollection",
"(",
"array",
"(",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"authorization",
"->",
"isGranted",
"(",
"'MODERATE'",
",",
"$",
"collection",
")",
")",
"{",
"throw",
"new",
"AccessDeniedException",
"(",
"$",
"collection",
"->",
"getErrorsForDisplay",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"manager",
"->",
"activateGlobalNotifications",
"(",
"$",
"forum",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'claro_forum_categories'",
",",
"array",
"(",
"'forum'",
"=>",
"$",
"forum",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}"
] | @Route(
"/{forum}/notifications/activate",
name="claro_forum_activate_global_notifications"
)
@param Forum $forum | [
"@Route",
"(",
"/",
"{",
"forum",
"}",
"/",
"notifications",
"/",
"activate",
"name",
"=",
"claro_forum_activate_global_notifications",
")"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L1019-L1032 |
claroline/ForumBundle | Controller/ForumController.php | ForumController.disableGlobalNotificationsAction | public function disableGlobalNotificationsAction(Forum $forum)
{
$collection = new ResourceCollection(array($forum->getResourceNode()));
if (!$this->authorization->isGranted('MODERATE', $collection)) {
throw new AccessDeniedException($collection->getErrorsForDisplay());
}
$this->manager->disableGlobalNotifications($forum);
return new RedirectResponse(
$this->generateUrl('claro_forum_categories', array('forum' => $forum->getId()))
);
} | php | public function disableGlobalNotificationsAction(Forum $forum)
{
$collection = new ResourceCollection(array($forum->getResourceNode()));
if (!$this->authorization->isGranted('MODERATE', $collection)) {
throw new AccessDeniedException($collection->getErrorsForDisplay());
}
$this->manager->disableGlobalNotifications($forum);
return new RedirectResponse(
$this->generateUrl('claro_forum_categories', array('forum' => $forum->getId()))
);
} | [
"public",
"function",
"disableGlobalNotificationsAction",
"(",
"Forum",
"$",
"forum",
")",
"{",
"$",
"collection",
"=",
"new",
"ResourceCollection",
"(",
"array",
"(",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"authorization",
"->",
"isGranted",
"(",
"'MODERATE'",
",",
"$",
"collection",
")",
")",
"{",
"throw",
"new",
"AccessDeniedException",
"(",
"$",
"collection",
"->",
"getErrorsForDisplay",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"manager",
"->",
"disableGlobalNotifications",
"(",
"$",
"forum",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'claro_forum_categories'",
",",
"array",
"(",
"'forum'",
"=>",
"$",
"forum",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}"
] | @Route(
"/{forum}/notifications/disable",
name="claro_forum_disable_global_notifications"
)
@param Forum $forum | [
"@Route",
"(",
"/",
"{",
"forum",
"}",
"/",
"notifications",
"/",
"disable",
"name",
"=",
"claro_forum_disable_global_notifications",
")"
] | train | https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L1042-L1055 |
anexia-it/anexia-laravel-encryption | src/DatabaseEncryptionScope.php | DatabaseEncryptionScope.apply | public function apply(Builder $builder, Model $model)
{
$encryptedFields = $model::getEncryptedFields();
if (!empty($encryptedFields)) {
$builder->setEncryptionModel($model);
foreach ($encryptedFields as $encryptedField) {
$builder->addEncryptionSelect([
'column' => $encryptedField,
'alias' => "{$encryptedField}_encrypted",
'select' => DB::raw("$encryptedField as {$encryptedField}_encrypted")
]);
}
}
} | php | public function apply(Builder $builder, Model $model)
{
$encryptedFields = $model::getEncryptedFields();
if (!empty($encryptedFields)) {
$builder->setEncryptionModel($model);
foreach ($encryptedFields as $encryptedField) {
$builder->addEncryptionSelect([
'column' => $encryptedField,
'alias' => "{$encryptedField}_encrypted",
'select' => DB::raw("$encryptedField as {$encryptedField}_encrypted")
]);
}
}
} | [
"public",
"function",
"apply",
"(",
"Builder",
"$",
"builder",
",",
"Model",
"$",
"model",
")",
"{",
"$",
"encryptedFields",
"=",
"$",
"model",
"::",
"getEncryptedFields",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"encryptedFields",
")",
")",
"{",
"$",
"builder",
"->",
"setEncryptionModel",
"(",
"$",
"model",
")",
";",
"foreach",
"(",
"$",
"encryptedFields",
"as",
"$",
"encryptedField",
")",
"{",
"$",
"builder",
"->",
"addEncryptionSelect",
"(",
"[",
"'column'",
"=>",
"$",
"encryptedField",
",",
"'alias'",
"=>",
"\"{$encryptedField}_encrypted\"",
",",
"'select'",
"=>",
"DB",
"::",
"raw",
"(",
"\"$encryptedField as {$encryptedField}_encrypted\"",
")",
"]",
")",
";",
"}",
"}",
"}"
] | Apply the scope to a given Eloquent query builder.
@param \Illuminate\Database\Eloquent\Builder $builder
@param \Illuminate\Database\Eloquent\Model $model
@return void | [
"Apply",
"the",
"scope",
"to",
"a",
"given",
"Eloquent",
"query",
"builder",
"."
] | train | https://github.com/anexia-it/anexia-laravel-encryption/blob/b7c72d99916ebca2d2cf2dbab1d4c0f84e383081/src/DatabaseEncryptionScope.php#L26-L40 |
anexia-it/anexia-laravel-encryption | src/DatabaseEncryptionScope.php | DatabaseEncryptionScope.addWithDecryptKey | protected function addWithDecryptKey(Builder $builder)
{
$builder->macro('withDecryptKey', function (Builder $builder, $decryptKey) {
$model = $builder->getModel();
$encryptedFields = $model::getEncryptedFields();
if (!empty($encryptedFields)) {
$builder->setEncryptionModel($model);
/** @var DatabaseEncryptionServiceInterface $encryptionService */
$encryptionService = $model::getEncryptionService();
foreach ($encryptedFields as $encryptedField) {
$decryptStmt = $encryptionService->getDecryptExpression($encryptedField, $decryptKey);
$builder->addEncryptionSelect([
'column' => $encryptedField,
'select' => DB::raw("$decryptStmt as $encryptedField")
]);
}
}
return $builder;
});
} | php | protected function addWithDecryptKey(Builder $builder)
{
$builder->macro('withDecryptKey', function (Builder $builder, $decryptKey) {
$model = $builder->getModel();
$encryptedFields = $model::getEncryptedFields();
if (!empty($encryptedFields)) {
$builder->setEncryptionModel($model);
/** @var DatabaseEncryptionServiceInterface $encryptionService */
$encryptionService = $model::getEncryptionService();
foreach ($encryptedFields as $encryptedField) {
$decryptStmt = $encryptionService->getDecryptExpression($encryptedField, $decryptKey);
$builder->addEncryptionSelect([
'column' => $encryptedField,
'select' => DB::raw("$decryptStmt as $encryptedField")
]);
}
}
return $builder;
});
} | [
"protected",
"function",
"addWithDecryptKey",
"(",
"Builder",
"$",
"builder",
")",
"{",
"$",
"builder",
"->",
"macro",
"(",
"'withDecryptKey'",
",",
"function",
"(",
"Builder",
"$",
"builder",
",",
"$",
"decryptKey",
")",
"{",
"$",
"model",
"=",
"$",
"builder",
"->",
"getModel",
"(",
")",
";",
"$",
"encryptedFields",
"=",
"$",
"model",
"::",
"getEncryptedFields",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"encryptedFields",
")",
")",
"{",
"$",
"builder",
"->",
"setEncryptionModel",
"(",
"$",
"model",
")",
";",
"/** @var DatabaseEncryptionServiceInterface $encryptionService */",
"$",
"encryptionService",
"=",
"$",
"model",
"::",
"getEncryptionService",
"(",
")",
";",
"foreach",
"(",
"$",
"encryptedFields",
"as",
"$",
"encryptedField",
")",
"{",
"$",
"decryptStmt",
"=",
"$",
"encryptionService",
"->",
"getDecryptExpression",
"(",
"$",
"encryptedField",
",",
"$",
"decryptKey",
")",
";",
"$",
"builder",
"->",
"addEncryptionSelect",
"(",
"[",
"'column'",
"=>",
"$",
"encryptedField",
",",
"'select'",
"=>",
"DB",
"::",
"raw",
"(",
"\"$decryptStmt as $encryptedField\"",
")",
"]",
")",
";",
"}",
"}",
"return",
"$",
"builder",
";",
"}",
")",
";",
"}"
] | Add the with-decrypt-key extension to the builder.
@param \Illuminate\Database\Eloquent\Builder $builder
@return void | [
"Add",
"the",
"with",
"-",
"decrypt",
"-",
"key",
"extension",
"to",
"the",
"builder",
"."
] | train | https://github.com/anexia-it/anexia-laravel-encryption/blob/b7c72d99916ebca2d2cf2dbab1d4c0f84e383081/src/DatabaseEncryptionScope.php#L61-L81 |
dms-org/package.blog | src/Domain/Entities/BlogCategory.php | BlogCategory.defineEntity | protected function defineEntity(ClassDefinition $class)
{
$class->property($this->name)->asString();
$class->property($this->slug)->asString();
$class->property($this->articles)->asType(BlogArticle::collectionType());
$class->property($this->published)->asBool();
$class->property($this->createdAt)->asObject(DateTime::class);
$class->property($this->updatedAt)->asObject(DateTime::class);
$this->defineMetadata($class);
} | php | protected function defineEntity(ClassDefinition $class)
{
$class->property($this->name)->asString();
$class->property($this->slug)->asString();
$class->property($this->articles)->asType(BlogArticle::collectionType());
$class->property($this->published)->asBool();
$class->property($this->createdAt)->asObject(DateTime::class);
$class->property($this->updatedAt)->asObject(DateTime::class);
$this->defineMetadata($class);
} | [
"protected",
"function",
"defineEntity",
"(",
"ClassDefinition",
"$",
"class",
")",
"{",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"name",
")",
"->",
"asString",
"(",
")",
";",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"slug",
")",
"->",
"asString",
"(",
")",
";",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"articles",
")",
"->",
"asType",
"(",
"BlogArticle",
"::",
"collectionType",
"(",
")",
")",
";",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"published",
")",
"->",
"asBool",
"(",
")",
";",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"createdAt",
")",
"->",
"asObject",
"(",
"DateTime",
"::",
"class",
")",
";",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"updatedAt",
")",
"->",
"asObject",
"(",
"DateTime",
"::",
"class",
")",
";",
"$",
"this",
"->",
"defineMetadata",
"(",
"$",
"class",
")",
";",
"}"
] | Defines the structure of this entity.
@param ClassDefinition $class | [
"Defines",
"the",
"structure",
"of",
"this",
"entity",
"."
] | train | https://github.com/dms-org/package.blog/blob/1500f6fad20d81289a0dfa617fc1c54699f01e16/src/Domain/Entities/BlogCategory.php#L86-L101 |
VincentChalnot/SidusAdminBundle | Twig/AdminExtension.php | AdminExtension.getAdmin | public function getAdmin($code): Admin
{
if ($code instanceof Admin) {
return $code;
}
return $this->adminRegistry->getAdmin($code);
} | php | public function getAdmin($code): Admin
{
if ($code instanceof Admin) {
return $code;
}
return $this->adminRegistry->getAdmin($code);
} | [
"public",
"function",
"getAdmin",
"(",
"$",
"code",
")",
":",
"Admin",
"{",
"if",
"(",
"$",
"code",
"instanceof",
"Admin",
")",
"{",
"return",
"$",
"code",
";",
"}",
"return",
"$",
"this",
"->",
"adminRegistry",
"->",
"getAdmin",
"(",
"$",
"code",
")",
";",
"}"
] | @param string $code
@throws UnexpectedValueException
@return Admin | [
"@param",
"string",
"$code"
] | train | https://github.com/VincentChalnot/SidusAdminBundle/blob/3366f3f1525435860cf275ed2f1f0b58cf6eea18/Twig/AdminExtension.php#L74-L81 |
neilime/zf2-browscap | src/Browscap/BrowscapService.php | BrowscapService.factory | public static function factory($aOptions){
if($aOptions instanceof \Traversable)$aOptions = \Zend\Stdlib\ArrayUtils::iteratorToArray($aOptions);
elseif(!is_array($aOptions))throw new \InvalidArgumentException(__METHOD__.' expects an array or Traversable object; received "'.(is_object($aOptions)?get_class($aOptions):gettype($aOptions)).'"');
$oBrowscapService = new static();
//Browscap.ini file path
if(isset($aOptions['browscap_ini_path']))$oBrowscapService->setBrowscapIniPath($aOptions['browscap_ini_path']);
//Cache
if(isset($aOptions['cache']))$oBrowscapService->setCache($aOptions['cache']);
if(isset($aOptions['allows_native_get_browser']))$oBrowscapService->setAllowsNativeGetBrowser(!!$aOptions['allows_native_get_browser']);
return $oBrowscapService;
} | php | public static function factory($aOptions){
if($aOptions instanceof \Traversable)$aOptions = \Zend\Stdlib\ArrayUtils::iteratorToArray($aOptions);
elseif(!is_array($aOptions))throw new \InvalidArgumentException(__METHOD__.' expects an array or Traversable object; received "'.(is_object($aOptions)?get_class($aOptions):gettype($aOptions)).'"');
$oBrowscapService = new static();
//Browscap.ini file path
if(isset($aOptions['browscap_ini_path']))$oBrowscapService->setBrowscapIniPath($aOptions['browscap_ini_path']);
//Cache
if(isset($aOptions['cache']))$oBrowscapService->setCache($aOptions['cache']);
if(isset($aOptions['allows_native_get_browser']))$oBrowscapService->setAllowsNativeGetBrowser(!!$aOptions['allows_native_get_browser']);
return $oBrowscapService;
} | [
"public",
"static",
"function",
"factory",
"(",
"$",
"aOptions",
")",
"{",
"if",
"(",
"$",
"aOptions",
"instanceof",
"\\",
"Traversable",
")",
"$",
"aOptions",
"=",
"\\",
"Zend",
"\\",
"Stdlib",
"\\",
"ArrayUtils",
"::",
"iteratorToArray",
"(",
"$",
"aOptions",
")",
";",
"elseif",
"(",
"!",
"is_array",
"(",
"$",
"aOptions",
")",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"' expects an array or Traversable object; received \"'",
".",
"(",
"is_object",
"(",
"$",
"aOptions",
")",
"?",
"get_class",
"(",
"$",
"aOptions",
")",
":",
"gettype",
"(",
"$",
"aOptions",
")",
")",
".",
"'\"'",
")",
";",
"$",
"oBrowscapService",
"=",
"new",
"static",
"(",
")",
";",
"//Browscap.ini file path",
"if",
"(",
"isset",
"(",
"$",
"aOptions",
"[",
"'browscap_ini_path'",
"]",
")",
")",
"$",
"oBrowscapService",
"->",
"setBrowscapIniPath",
"(",
"$",
"aOptions",
"[",
"'browscap_ini_path'",
"]",
")",
";",
"//Cache",
"if",
"(",
"isset",
"(",
"$",
"aOptions",
"[",
"'cache'",
"]",
")",
")",
"$",
"oBrowscapService",
"->",
"setCache",
"(",
"$",
"aOptions",
"[",
"'cache'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"aOptions",
"[",
"'allows_native_get_browser'",
"]",
")",
")",
"$",
"oBrowscapService",
"->",
"setAllowsNativeGetBrowser",
"(",
"!",
"!",
"$",
"aOptions",
"[",
"'allows_native_get_browser'",
"]",
")",
";",
"return",
"$",
"oBrowscapService",
";",
"}"
] | Instantiate AccessControl Authentication Service
@param array|Traversable $aConfiguration
@param \Zend\ServiceManager\ServiceLocatorInterface $oServiceLocator
@throws \InvalidArgumentException
@return \BoilerAppAccessControl\Authentication\AccessControlAuthenticationService | [
"Instantiate",
"AccessControl",
"Authentication",
"Service"
] | train | https://github.com/neilime/zf2-browscap/blob/490a4d573a2f6340c67a4254d5a46d3276583e1b/src/Browscap/BrowscapService.php#L41-L56 |
neilime/zf2-browscap | src/Browscap/BrowscapService.php | BrowscapService.loadBrowscapIni | public function loadBrowscapIni(){
$sBrowscapIniPath = $this->getBrowscapIniPath();
//Local file
if(is_readable($sBrowscapIniPath)){
$aBrowscap = parse_ini_file($this->getBrowscapIniPath(), true, INI_SCANNER_RAW);
if($aBrowscap === false)throw new \RuntimeException('Error appends while parsing browscap.ini file "'.$sBrowscapIniPath.'"');
}
//Remote file
else{
if(($oFileHandle = @fopen($sBrowscapIniPath, 'r')) === false)throw new \InvalidArgumentException('Unable to load browscap.ini file "'.$sBrowscapIniPath.'"');
$sBrowscapIniContents = '';
while(($sContent = fgets($oFileHandle)) !== false) {
$sBrowscapIniContents .= $sContent.PHP_EOL;
}
if(!feof($oFileHandle))throw new \RuntimeException('Unable to retrieve contents from browscap.ini file "'.$sBrowscapIniPath.'"');
fclose($oFileHandle);
$aBrowscap = parse_ini_string($sBrowscapIniContents, true, INI_SCANNER_RAW);
if($aBrowscap === false)throw new \RuntimeException('Error appends while parsing browscap.ini file "'.$sBrowscapIniPath.'"');
}
$aBrowscapKeys = array_keys($aBrowscap);
$aBrowscap = array_combine($aBrowscapKeys, array_map(function($aUserAgentInfos, $sUserAgent){
$aUserAgentInfos = array_map(function($sValue){
if($sValue === 'true')return 1;
elseif($sValue === 'false')return '';
else return $sValue;
}, $aUserAgentInfos);
//Define browser name regex
$aUserAgentInfos['browser_name_regex'] = '^'.str_replace(
array('\\','.','?','*','^','$','[',']','|','(',')','+','{','}','%'),
array('\\\\','\\.','.','.*','\\^','\\$','\\[','\\]','\\|','\\(','\\)','\\+','\\{','\\}','\\%'),
$sUserAgent
).'$';
return array_change_key_case($aUserAgentInfos,CASE_LOWER);
},$aBrowscap,$aBrowscapKeys));
uksort($aBrowscap,function($sUserAgentA,$sUserAgentB){
if(($sUserAgentALength = strlen($sUserAgentA)) > ($sUserAgentBLength = strlen($sUserAgentB)))return -1;
elseif($sUserAgentALength < $sUserAgentBLength)return 1;
else return strcasecmp($sUserAgentA,$sUserAgentB);
});
return $this->setBrowscap($aBrowscap);
} | php | public function loadBrowscapIni(){
$sBrowscapIniPath = $this->getBrowscapIniPath();
//Local file
if(is_readable($sBrowscapIniPath)){
$aBrowscap = parse_ini_file($this->getBrowscapIniPath(), true, INI_SCANNER_RAW);
if($aBrowscap === false)throw new \RuntimeException('Error appends while parsing browscap.ini file "'.$sBrowscapIniPath.'"');
}
//Remote file
else{
if(($oFileHandle = @fopen($sBrowscapIniPath, 'r')) === false)throw new \InvalidArgumentException('Unable to load browscap.ini file "'.$sBrowscapIniPath.'"');
$sBrowscapIniContents = '';
while(($sContent = fgets($oFileHandle)) !== false) {
$sBrowscapIniContents .= $sContent.PHP_EOL;
}
if(!feof($oFileHandle))throw new \RuntimeException('Unable to retrieve contents from browscap.ini file "'.$sBrowscapIniPath.'"');
fclose($oFileHandle);
$aBrowscap = parse_ini_string($sBrowscapIniContents, true, INI_SCANNER_RAW);
if($aBrowscap === false)throw new \RuntimeException('Error appends while parsing browscap.ini file "'.$sBrowscapIniPath.'"');
}
$aBrowscapKeys = array_keys($aBrowscap);
$aBrowscap = array_combine($aBrowscapKeys, array_map(function($aUserAgentInfos, $sUserAgent){
$aUserAgentInfos = array_map(function($sValue){
if($sValue === 'true')return 1;
elseif($sValue === 'false')return '';
else return $sValue;
}, $aUserAgentInfos);
//Define browser name regex
$aUserAgentInfos['browser_name_regex'] = '^'.str_replace(
array('\\','.','?','*','^','$','[',']','|','(',')','+','{','}','%'),
array('\\\\','\\.','.','.*','\\^','\\$','\\[','\\]','\\|','\\(','\\)','\\+','\\{','\\}','\\%'),
$sUserAgent
).'$';
return array_change_key_case($aUserAgentInfos,CASE_LOWER);
},$aBrowscap,$aBrowscapKeys));
uksort($aBrowscap,function($sUserAgentA,$sUserAgentB){
if(($sUserAgentALength = strlen($sUserAgentA)) > ($sUserAgentBLength = strlen($sUserAgentB)))return -1;
elseif($sUserAgentALength < $sUserAgentBLength)return 1;
else return strcasecmp($sUserAgentA,$sUserAgentB);
});
return $this->setBrowscap($aBrowscap);
} | [
"public",
"function",
"loadBrowscapIni",
"(",
")",
"{",
"$",
"sBrowscapIniPath",
"=",
"$",
"this",
"->",
"getBrowscapIniPath",
"(",
")",
";",
"//Local file",
"if",
"(",
"is_readable",
"(",
"$",
"sBrowscapIniPath",
")",
")",
"{",
"$",
"aBrowscap",
"=",
"parse_ini_file",
"(",
"$",
"this",
"->",
"getBrowscapIniPath",
"(",
")",
",",
"true",
",",
"INI_SCANNER_RAW",
")",
";",
"if",
"(",
"$",
"aBrowscap",
"===",
"false",
")",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Error appends while parsing browscap.ini file \"'",
".",
"$",
"sBrowscapIniPath",
".",
"'\"'",
")",
";",
"}",
"//Remote file",
"else",
"{",
"if",
"(",
"(",
"$",
"oFileHandle",
"=",
"@",
"fopen",
"(",
"$",
"sBrowscapIniPath",
",",
"'r'",
")",
")",
"===",
"false",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Unable to load browscap.ini file \"'",
".",
"$",
"sBrowscapIniPath",
".",
"'\"'",
")",
";",
"$",
"sBrowscapIniContents",
"=",
"''",
";",
"while",
"(",
"(",
"$",
"sContent",
"=",
"fgets",
"(",
"$",
"oFileHandle",
")",
")",
"!==",
"false",
")",
"{",
"$",
"sBrowscapIniContents",
".=",
"$",
"sContent",
".",
"PHP_EOL",
";",
"}",
"if",
"(",
"!",
"feof",
"(",
"$",
"oFileHandle",
")",
")",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Unable to retrieve contents from browscap.ini file \"'",
".",
"$",
"sBrowscapIniPath",
".",
"'\"'",
")",
";",
"fclose",
"(",
"$",
"oFileHandle",
")",
";",
"$",
"aBrowscap",
"=",
"parse_ini_string",
"(",
"$",
"sBrowscapIniContents",
",",
"true",
",",
"INI_SCANNER_RAW",
")",
";",
"if",
"(",
"$",
"aBrowscap",
"===",
"false",
")",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Error appends while parsing browscap.ini file \"'",
".",
"$",
"sBrowscapIniPath",
".",
"'\"'",
")",
";",
"}",
"$",
"aBrowscapKeys",
"=",
"array_keys",
"(",
"$",
"aBrowscap",
")",
";",
"$",
"aBrowscap",
"=",
"array_combine",
"(",
"$",
"aBrowscapKeys",
",",
"array_map",
"(",
"function",
"(",
"$",
"aUserAgentInfos",
",",
"$",
"sUserAgent",
")",
"{",
"$",
"aUserAgentInfos",
"=",
"array_map",
"(",
"function",
"(",
"$",
"sValue",
")",
"{",
"if",
"(",
"$",
"sValue",
"===",
"'true'",
")",
"return",
"1",
";",
"elseif",
"(",
"$",
"sValue",
"===",
"'false'",
")",
"return",
"''",
";",
"else",
"return",
"$",
"sValue",
";",
"}",
",",
"$",
"aUserAgentInfos",
")",
";",
"//Define browser name regex",
"$",
"aUserAgentInfos",
"[",
"'browser_name_regex'",
"]",
"=",
"'^'",
".",
"str_replace",
"(",
"array",
"(",
"'\\\\'",
",",
"'.'",
",",
"'?'",
",",
"'*'",
",",
"'^'",
",",
"'$'",
",",
"'['",
",",
"']'",
",",
"'|'",
",",
"'('",
",",
"')'",
",",
"'+'",
",",
"'{'",
",",
"'}'",
",",
"'%'",
")",
",",
"array",
"(",
"'\\\\\\\\'",
",",
"'\\\\.'",
",",
"'.'",
",",
"'.*'",
",",
"'\\\\^'",
",",
"'\\\\$'",
",",
"'\\\\['",
",",
"'\\\\]'",
",",
"'\\\\|'",
",",
"'\\\\('",
",",
"'\\\\)'",
",",
"'\\\\+'",
",",
"'\\\\{'",
",",
"'\\\\}'",
",",
"'\\\\%'",
")",
",",
"$",
"sUserAgent",
")",
".",
"'$'",
";",
"return",
"array_change_key_case",
"(",
"$",
"aUserAgentInfos",
",",
"CASE_LOWER",
")",
";",
"}",
",",
"$",
"aBrowscap",
",",
"$",
"aBrowscapKeys",
")",
")",
";",
"uksort",
"(",
"$",
"aBrowscap",
",",
"function",
"(",
"$",
"sUserAgentA",
",",
"$",
"sUserAgentB",
")",
"{",
"if",
"(",
"(",
"$",
"sUserAgentALength",
"=",
"strlen",
"(",
"$",
"sUserAgentA",
")",
")",
">",
"(",
"$",
"sUserAgentBLength",
"=",
"strlen",
"(",
"$",
"sUserAgentB",
")",
")",
")",
"return",
"-",
"1",
";",
"elseif",
"(",
"$",
"sUserAgentALength",
"<",
"$",
"sUserAgentBLength",
")",
"return",
"1",
";",
"else",
"return",
"strcasecmp",
"(",
"$",
"sUserAgentA",
",",
"$",
"sUserAgentB",
")",
";",
"}",
")",
";",
"return",
"$",
"this",
"->",
"setBrowscap",
"(",
"$",
"aBrowscap",
")",
";",
"}"
] | Load and parse browscap.ini file
@throws \RuntimeException
@return \Neilime\Browscap\BrowscapService | [
"Load",
"and",
"parse",
"browscap",
".",
"ini",
"file"
] | train | https://github.com/neilime/zf2-browscap/blob/490a4d573a2f6340c67a4254d5a46d3276583e1b/src/Browscap/BrowscapService.php#L182-L228 |
egeloen/IvorySerializerBundle | Type/FormErrorType.php | FormErrorType.convert | public function convert($data, TypeMetadataInterface $type, ContextInterface $context)
{
if ($context->getDirection() === Direction::DESERIALIZATION) {
throw new \RuntimeException(sprintf('Deserializing a "%s" is not supported.', FormError::class));
}
return $context->getVisitor()->visitString($this->translateError($data), $type, $context);
} | php | public function convert($data, TypeMetadataInterface $type, ContextInterface $context)
{
if ($context->getDirection() === Direction::DESERIALIZATION) {
throw new \RuntimeException(sprintf('Deserializing a "%s" is not supported.', FormError::class));
}
return $context->getVisitor()->visitString($this->translateError($data), $type, $context);
} | [
"public",
"function",
"convert",
"(",
"$",
"data",
",",
"TypeMetadataInterface",
"$",
"type",
",",
"ContextInterface",
"$",
"context",
")",
"{",
"if",
"(",
"$",
"context",
"->",
"getDirection",
"(",
")",
"===",
"Direction",
"::",
"DESERIALIZATION",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Deserializing a \"%s\" is not supported.'",
",",
"FormError",
"::",
"class",
")",
")",
";",
"}",
"return",
"$",
"context",
"->",
"getVisitor",
"(",
")",
"->",
"visitString",
"(",
"$",
"this",
"->",
"translateError",
"(",
"$",
"data",
")",
",",
"$",
"type",
",",
"$",
"context",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/IvorySerializerBundle/blob/a2bdd912bf715c61b823cf7257ee232d5c823dd3/Type/FormErrorType.php#L42-L49 |
egeloen/IvorySerializerBundle | Type/FormErrorType.php | FormErrorType.translateError | private function translateError(FormError $error)
{
if ($this->translator === null) {
return $error->getMessage();
}
if ($error->getMessagePluralization() !== null) {
return $this->translator->transChoice(
$error->getMessageTemplate(),
$error->getMessagePluralization(),
$error->getMessageParameters(),
'validators'
);
}
return $this->translator->trans(
$error->getMessageTemplate(),
$error->getMessageParameters(),
'validators'
);
} | php | private function translateError(FormError $error)
{
if ($this->translator === null) {
return $error->getMessage();
}
if ($error->getMessagePluralization() !== null) {
return $this->translator->transChoice(
$error->getMessageTemplate(),
$error->getMessagePluralization(),
$error->getMessageParameters(),
'validators'
);
}
return $this->translator->trans(
$error->getMessageTemplate(),
$error->getMessageParameters(),
'validators'
);
} | [
"private",
"function",
"translateError",
"(",
"FormError",
"$",
"error",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"translator",
"===",
"null",
")",
"{",
"return",
"$",
"error",
"->",
"getMessage",
"(",
")",
";",
"}",
"if",
"(",
"$",
"error",
"->",
"getMessagePluralization",
"(",
")",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"translator",
"->",
"transChoice",
"(",
"$",
"error",
"->",
"getMessageTemplate",
"(",
")",
",",
"$",
"error",
"->",
"getMessagePluralization",
"(",
")",
",",
"$",
"error",
"->",
"getMessageParameters",
"(",
")",
",",
"'validators'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"$",
"error",
"->",
"getMessageTemplate",
"(",
")",
",",
"$",
"error",
"->",
"getMessageParameters",
"(",
")",
",",
"'validators'",
")",
";",
"}"
] | @param FormError $error
@return string | [
"@param",
"FormError",
"$error"
] | train | https://github.com/egeloen/IvorySerializerBundle/blob/a2bdd912bf715c61b823cf7257ee232d5c823dd3/Type/FormErrorType.php#L56-L76 |
left-right/center | src/controllers/FileController.php | FileController.image | public function image() {
if (Request::hasFile('image') && Request::has('table_name') && Request::has('field_name')) {
return json_encode(self::saveImage(
Request::input('table_name'),
Request::input('field_name'),
Request::file('image'),
null,
Request::file('image')->getClientOriginalExtension()
));
} elseif (!Request::hasFile('image')) {
return 'no image';
} elseif (!Request::hasFile('table_name')) {
return 'no table_name';
} elseif (!Request::hasFile('field_name')) {
return 'no field_name';
}
} | php | public function image() {
if (Request::hasFile('image') && Request::has('table_name') && Request::has('field_name')) {
return json_encode(self::saveImage(
Request::input('table_name'),
Request::input('field_name'),
Request::file('image'),
null,
Request::file('image')->getClientOriginalExtension()
));
} elseif (!Request::hasFile('image')) {
return 'no image';
} elseif (!Request::hasFile('table_name')) {
return 'no table_name';
} elseif (!Request::hasFile('field_name')) {
return 'no field_name';
}
} | [
"public",
"function",
"image",
"(",
")",
"{",
"if",
"(",
"Request",
"::",
"hasFile",
"(",
"'image'",
")",
"&&",
"Request",
"::",
"has",
"(",
"'table_name'",
")",
"&&",
"Request",
"::",
"has",
"(",
"'field_name'",
")",
")",
"{",
"return",
"json_encode",
"(",
"self",
"::",
"saveImage",
"(",
"Request",
"::",
"input",
"(",
"'table_name'",
")",
",",
"Request",
"::",
"input",
"(",
"'field_name'",
")",
",",
"Request",
"::",
"file",
"(",
"'image'",
")",
",",
"null",
",",
"Request",
"::",
"file",
"(",
"'image'",
")",
"->",
"getClientOriginalExtension",
"(",
")",
")",
")",
";",
"}",
"elseif",
"(",
"!",
"Request",
"::",
"hasFile",
"(",
"'image'",
")",
")",
"{",
"return",
"'no image'",
";",
"}",
"elseif",
"(",
"!",
"Request",
"::",
"hasFile",
"(",
"'table_name'",
")",
")",
"{",
"return",
"'no table_name'",
";",
"}",
"elseif",
"(",
"!",
"Request",
"::",
"hasFile",
"(",
"'field_name'",
")",
")",
"{",
"return",
"'no field_name'",
";",
"}",
"}"
] | handle image upload route | [
"handle",
"image",
"upload",
"route"
] | train | https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/FileController.php#L28-L44 |
left-right/center | src/controllers/FileController.php | FileController.saveImage | public static function saveImage($table_name, $field_name, $file_name, $row_id=null, $extension=null) {
//get field info
$table = config('center.tables.' . $table_name);
$field = $table->fields->{$field_name};
$unique = Str::random(5);
//make path
$path = implode('/', [
config('center.files.path'),
$table->name,
$unique,
]);
//also make path in the filesystem
mkdir(public_path() . $path, 0777, true);
//get name and extension
$name = substr($field->name, 0, -3);
$file = file_get_contents($file_name);
if (!$extension) $extension = pathinfo($file_name, PATHINFO_EXTENSION);
$url = $path . '/' . $name . '.' . $extension;
//process and save image
if (!empty($field->width) && !empty($field->height)) {
Image::make($file)
->fit((int)$field->width, (int)$field->height)
->save(public_path() . $url);
} elseif (!empty($field->width)) {
Image::make($file)
->widen((int)$field->width)
->save(public_path() . $url);
} elseif (!empty($field->height)) {
Image::make($file)
->heighten(null, (int)$field->height)
->save(public_path() . $url);
} else {
Image::make($file)
->save(public_path() . $url);
}
//try to delete file
@unlink($file_name);
//try to delete previous value(s)
if ($row_id) {
$previous_images = DB::table(config('center.db.files'))
->where('table', $table->name)
->where('field', $field->name)
->where('row_id', $row_id);
foreach ($previous_images as $previous_image) {
@unlink($previous_image->url);
}
}
//get dimensions
list($width, $height, $type, $attr) = getimagesize(public_path() . $url);
//get size
$size = filesize(public_path() . $url);
//insert record for image
$file_id = DB::table(config('center.db.files'))->insertGetId([
'table' => $table->name,
'field' => $field->name,
'url' => $url,
'width' => $width,
'row_id' => $row_id,
'height' => $height,
'size' => $size,
'created_at' => new DateTime,
'created_by' => Auth::guest() ? null : Auth::user()->id,
'precedence' => DB::table(config('center.db.files'))
->where('table', $table->name)
->where('field', $field->name)
->max('precedence') + 1,
]);
//come up with adjusted display size based on user-defined maxima
list($screenwidth, $screenheight) = self::getImageDimensions($width, $height);
//return array
return [
'file_id' => $file_id,
'url' => $url,
'width' => $width,
'height' => $height,
'screenwidth' => $screenwidth,
'screenheight' => $screenheight,
];
} | php | public static function saveImage($table_name, $field_name, $file_name, $row_id=null, $extension=null) {
//get field info
$table = config('center.tables.' . $table_name);
$field = $table->fields->{$field_name};
$unique = Str::random(5);
//make path
$path = implode('/', [
config('center.files.path'),
$table->name,
$unique,
]);
//also make path in the filesystem
mkdir(public_path() . $path, 0777, true);
//get name and extension
$name = substr($field->name, 0, -3);
$file = file_get_contents($file_name);
if (!$extension) $extension = pathinfo($file_name, PATHINFO_EXTENSION);
$url = $path . '/' . $name . '.' . $extension;
//process and save image
if (!empty($field->width) && !empty($field->height)) {
Image::make($file)
->fit((int)$field->width, (int)$field->height)
->save(public_path() . $url);
} elseif (!empty($field->width)) {
Image::make($file)
->widen((int)$field->width)
->save(public_path() . $url);
} elseif (!empty($field->height)) {
Image::make($file)
->heighten(null, (int)$field->height)
->save(public_path() . $url);
} else {
Image::make($file)
->save(public_path() . $url);
}
//try to delete file
@unlink($file_name);
//try to delete previous value(s)
if ($row_id) {
$previous_images = DB::table(config('center.db.files'))
->where('table', $table->name)
->where('field', $field->name)
->where('row_id', $row_id);
foreach ($previous_images as $previous_image) {
@unlink($previous_image->url);
}
}
//get dimensions
list($width, $height, $type, $attr) = getimagesize(public_path() . $url);
//get size
$size = filesize(public_path() . $url);
//insert record for image
$file_id = DB::table(config('center.db.files'))->insertGetId([
'table' => $table->name,
'field' => $field->name,
'url' => $url,
'width' => $width,
'row_id' => $row_id,
'height' => $height,
'size' => $size,
'created_at' => new DateTime,
'created_by' => Auth::guest() ? null : Auth::user()->id,
'precedence' => DB::table(config('center.db.files'))
->where('table', $table->name)
->where('field', $field->name)
->max('precedence') + 1,
]);
//come up with adjusted display size based on user-defined maxima
list($screenwidth, $screenheight) = self::getImageDimensions($width, $height);
//return array
return [
'file_id' => $file_id,
'url' => $url,
'width' => $width,
'height' => $height,
'screenwidth' => $screenwidth,
'screenheight' => $screenheight,
];
} | [
"public",
"static",
"function",
"saveImage",
"(",
"$",
"table_name",
",",
"$",
"field_name",
",",
"$",
"file_name",
",",
"$",
"row_id",
"=",
"null",
",",
"$",
"extension",
"=",
"null",
")",
"{",
"//get field info",
"$",
"table",
"=",
"config",
"(",
"'center.tables.'",
".",
"$",
"table_name",
")",
";",
"$",
"field",
"=",
"$",
"table",
"->",
"fields",
"->",
"{",
"$",
"field_name",
"}",
";",
"$",
"unique",
"=",
"Str",
"::",
"random",
"(",
"5",
")",
";",
"//make path",
"$",
"path",
"=",
"implode",
"(",
"'/'",
",",
"[",
"config",
"(",
"'center.files.path'",
")",
",",
"$",
"table",
"->",
"name",
",",
"$",
"unique",
",",
"]",
")",
";",
"//also make path in the filesystem",
"mkdir",
"(",
"public_path",
"(",
")",
".",
"$",
"path",
",",
"0777",
",",
"true",
")",
";",
"//get name and extension",
"$",
"name",
"=",
"substr",
"(",
"$",
"field",
"->",
"name",
",",
"0",
",",
"-",
"3",
")",
";",
"$",
"file",
"=",
"file_get_contents",
"(",
"$",
"file_name",
")",
";",
"if",
"(",
"!",
"$",
"extension",
")",
"$",
"extension",
"=",
"pathinfo",
"(",
"$",
"file_name",
",",
"PATHINFO_EXTENSION",
")",
";",
"$",
"url",
"=",
"$",
"path",
".",
"'/'",
".",
"$",
"name",
".",
"'.'",
".",
"$",
"extension",
";",
"//process and save image",
"if",
"(",
"!",
"empty",
"(",
"$",
"field",
"->",
"width",
")",
"&&",
"!",
"empty",
"(",
"$",
"field",
"->",
"height",
")",
")",
"{",
"Image",
"::",
"make",
"(",
"$",
"file",
")",
"->",
"fit",
"(",
"(",
"int",
")",
"$",
"field",
"->",
"width",
",",
"(",
"int",
")",
"$",
"field",
"->",
"height",
")",
"->",
"save",
"(",
"public_path",
"(",
")",
".",
"$",
"url",
")",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"field",
"->",
"width",
")",
")",
"{",
"Image",
"::",
"make",
"(",
"$",
"file",
")",
"->",
"widen",
"(",
"(",
"int",
")",
"$",
"field",
"->",
"width",
")",
"->",
"save",
"(",
"public_path",
"(",
")",
".",
"$",
"url",
")",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"field",
"->",
"height",
")",
")",
"{",
"Image",
"::",
"make",
"(",
"$",
"file",
")",
"->",
"heighten",
"(",
"null",
",",
"(",
"int",
")",
"$",
"field",
"->",
"height",
")",
"->",
"save",
"(",
"public_path",
"(",
")",
".",
"$",
"url",
")",
";",
"}",
"else",
"{",
"Image",
"::",
"make",
"(",
"$",
"file",
")",
"->",
"save",
"(",
"public_path",
"(",
")",
".",
"$",
"url",
")",
";",
"}",
"//try to delete file",
"@",
"unlink",
"(",
"$",
"file_name",
")",
";",
"//try to delete previous value(s)",
"if",
"(",
"$",
"row_id",
")",
"{",
"$",
"previous_images",
"=",
"DB",
"::",
"table",
"(",
"config",
"(",
"'center.db.files'",
")",
")",
"->",
"where",
"(",
"'table'",
",",
"$",
"table",
"->",
"name",
")",
"->",
"where",
"(",
"'field'",
",",
"$",
"field",
"->",
"name",
")",
"->",
"where",
"(",
"'row_id'",
",",
"$",
"row_id",
")",
";",
"foreach",
"(",
"$",
"previous_images",
"as",
"$",
"previous_image",
")",
"{",
"@",
"unlink",
"(",
"$",
"previous_image",
"->",
"url",
")",
";",
"}",
"}",
"//get dimensions",
"list",
"(",
"$",
"width",
",",
"$",
"height",
",",
"$",
"type",
",",
"$",
"attr",
")",
"=",
"getimagesize",
"(",
"public_path",
"(",
")",
".",
"$",
"url",
")",
";",
"//get size",
"$",
"size",
"=",
"filesize",
"(",
"public_path",
"(",
")",
".",
"$",
"url",
")",
";",
"//insert record for image",
"$",
"file_id",
"=",
"DB",
"::",
"table",
"(",
"config",
"(",
"'center.db.files'",
")",
")",
"->",
"insertGetId",
"(",
"[",
"'table'",
"=>",
"$",
"table",
"->",
"name",
",",
"'field'",
"=>",
"$",
"field",
"->",
"name",
",",
"'url'",
"=>",
"$",
"url",
",",
"'width'",
"=>",
"$",
"width",
",",
"'row_id'",
"=>",
"$",
"row_id",
",",
"'height'",
"=>",
"$",
"height",
",",
"'size'",
"=>",
"$",
"size",
",",
"'created_at'",
"=>",
"new",
"DateTime",
",",
"'created_by'",
"=>",
"Auth",
"::",
"guest",
"(",
")",
"?",
"null",
":",
"Auth",
"::",
"user",
"(",
")",
"->",
"id",
",",
"'precedence'",
"=>",
"DB",
"::",
"table",
"(",
"config",
"(",
"'center.db.files'",
")",
")",
"->",
"where",
"(",
"'table'",
",",
"$",
"table",
"->",
"name",
")",
"->",
"where",
"(",
"'field'",
",",
"$",
"field",
"->",
"name",
")",
"->",
"max",
"(",
"'precedence'",
")",
"+",
"1",
",",
"]",
")",
";",
"//come up with adjusted display size based on user-defined maxima",
"list",
"(",
"$",
"screenwidth",
",",
"$",
"screenheight",
")",
"=",
"self",
"::",
"getImageDimensions",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"//return array",
"return",
"[",
"'file_id'",
"=>",
"$",
"file_id",
",",
"'url'",
"=>",
"$",
"url",
",",
"'width'",
"=>",
"$",
"width",
",",
"'height'",
"=>",
"$",
"height",
",",
"'screenwidth'",
"=>",
"$",
"screenwidth",
",",
"'screenheight'",
"=>",
"$",
"screenheight",
",",
"]",
";",
"}"
] | genericized function to handle upload, available externally via service provider
destroys file after complete | [
"genericized",
"function",
"to",
"handle",
"upload",
"available",
"externally",
"via",
"service",
"provider",
"destroys",
"file",
"after",
"complete"
] | train | https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/FileController.php#L50-L139 |
left-right/center | src/controllers/FileController.php | FileController.getImageDimensions | public static function getImageDimensions($width=false, $height=false) {
$max_width = config('center.img.max.width');
$max_height = config('center.img.max.height');
$max_area = config('center.img.max.area');
//too wide?
if ($width && $width > $max_width) {
if ($height) $height *= $max_width / $width;
$width = $max_width;
}
//too tall?
if ($height && $height > $max_height) {
if ($width) $width *= $max_height / $height;
$height = $max_height;
}
//not specified?
if (!$width) $width = config('center.img.default.width');
if (!$height) $height = config('center.img.default.height');
//too large?
$area = $width * $height;
if ($width * $height > $max_area) {
$width *= $max_area / $area;
$height *= $max_area / $area;
}
return array($width, $height);
} | php | public static function getImageDimensions($width=false, $height=false) {
$max_width = config('center.img.max.width');
$max_height = config('center.img.max.height');
$max_area = config('center.img.max.area');
//too wide?
if ($width && $width > $max_width) {
if ($height) $height *= $max_width / $width;
$width = $max_width;
}
//too tall?
if ($height && $height > $max_height) {
if ($width) $width *= $max_height / $height;
$height = $max_height;
}
//not specified?
if (!$width) $width = config('center.img.default.width');
if (!$height) $height = config('center.img.default.height');
//too large?
$area = $width * $height;
if ($width * $height > $max_area) {
$width *= $max_area / $area;
$height *= $max_area / $area;
}
return array($width, $height);
} | [
"public",
"static",
"function",
"getImageDimensions",
"(",
"$",
"width",
"=",
"false",
",",
"$",
"height",
"=",
"false",
")",
"{",
"$",
"max_width",
"=",
"config",
"(",
"'center.img.max.width'",
")",
";",
"$",
"max_height",
"=",
"config",
"(",
"'center.img.max.height'",
")",
";",
"$",
"max_area",
"=",
"config",
"(",
"'center.img.max.area'",
")",
";",
"//too wide?",
"if",
"(",
"$",
"width",
"&&",
"$",
"width",
">",
"$",
"max_width",
")",
"{",
"if",
"(",
"$",
"height",
")",
"$",
"height",
"*=",
"$",
"max_width",
"/",
"$",
"width",
";",
"$",
"width",
"=",
"$",
"max_width",
";",
"}",
"//too tall?",
"if",
"(",
"$",
"height",
"&&",
"$",
"height",
">",
"$",
"max_height",
")",
"{",
"if",
"(",
"$",
"width",
")",
"$",
"width",
"*=",
"$",
"max_height",
"/",
"$",
"height",
";",
"$",
"height",
"=",
"$",
"max_height",
";",
"}",
"//not specified?",
"if",
"(",
"!",
"$",
"width",
")",
"$",
"width",
"=",
"config",
"(",
"'center.img.default.width'",
")",
";",
"if",
"(",
"!",
"$",
"height",
")",
"$",
"height",
"=",
"config",
"(",
"'center.img.default.height'",
")",
";",
"//too large?",
"$",
"area",
"=",
"$",
"width",
"*",
"$",
"height",
";",
"if",
"(",
"$",
"width",
"*",
"$",
"height",
">",
"$",
"max_area",
")",
"{",
"$",
"width",
"*=",
"$",
"max_area",
"/",
"$",
"area",
";",
"$",
"height",
"*=",
"$",
"max_area",
"/",
"$",
"area",
";",
"}",
"return",
"array",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"}"
] | # Get display size for create and edit views | [
"#",
"Get",
"display",
"size",
"for",
"create",
"and",
"edit",
"views"
] | train | https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/FileController.php#L142-L172 |
ppetermann/king23 | src/Http/Router.php | Router.addRoute | public function addRoute($route, $class, $action, $parameters = [], $hostparameters = [])
{
$this->log->debug('adding route : ' . $route . ' to class ' . $class . ' and action ' . $action);
$this->routes[$route] = [
"class" => $class,
"action" => $action,
"parameters" => $parameters,
"hostparameters" => $hostparameters
];
return $this;
} | php | public function addRoute($route, $class, $action, $parameters = [], $hostparameters = [])
{
$this->log->debug('adding route : ' . $route . ' to class ' . $class . ' and action ' . $action);
$this->routes[$route] = [
"class" => $class,
"action" => $action,
"parameters" => $parameters,
"hostparameters" => $hostparameters
];
return $this;
} | [
"public",
"function",
"addRoute",
"(",
"$",
"route",
",",
"$",
"class",
",",
"$",
"action",
",",
"$",
"parameters",
"=",
"[",
"]",
",",
"$",
"hostparameters",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"debug",
"(",
"'adding route : '",
".",
"$",
"route",
".",
"' to class '",
".",
"$",
"class",
".",
"' and action '",
".",
"$",
"action",
")",
";",
"$",
"this",
"->",
"routes",
"[",
"$",
"route",
"]",
"=",
"[",
"\"class\"",
"=>",
"$",
"class",
",",
"\"action\"",
"=>",
"$",
"action",
",",
"\"parameters\"",
"=>",
"$",
"parameters",
",",
"\"hostparameters\"",
"=>",
"$",
"hostparameters",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | add route to list of known routes
@param String $route beginning string of the route
@param String $class to be used for this route
@param String $action method to be called
@param string[] $parameters list of parameters that should be retrieved from url
@param array $hostparameters - allows to use subdomains as parameters
@return self | [
"add",
"route",
"to",
"list",
"of",
"known",
"routes"
] | train | https://github.com/ppetermann/king23/blob/603896083ec89f5ac4d744abd3b1b4db3e914c95/src/Http/Router.php#L87-L98 |
ppetermann/king23 | src/Http/Router.php | Router.setBaseHost | public function setBaseHost($baseHost = null)
{
$this->log->debug('Setting Router baseHost to ' . $baseHost);
$this->baseHost = $baseHost;
return $this;
} | php | public function setBaseHost($baseHost = null)
{
$this->log->debug('Setting Router baseHost to ' . $baseHost);
$this->baseHost = $baseHost;
return $this;
} | [
"public",
"function",
"setBaseHost",
"(",
"$",
"baseHost",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"debug",
"(",
"'Setting Router baseHost to '",
".",
"$",
"baseHost",
")",
";",
"$",
"this",
"->",
"baseHost",
"=",
"$",
"baseHost",
";",
"return",
"$",
"this",
";",
"}"
] | method to set the basicHost for hostparameters in routing
@see King23_Router::$basicHost
@param String $baseHost
@return self | [
"method",
"to",
"set",
"the",
"basicHost",
"for",
"hostparameters",
"in",
"routing"
] | train | https://github.com/ppetermann/king23/blob/603896083ec89f5ac4d744abd3b1b4db3e914c95/src/Http/Router.php#L107-L112 |
ppetermann/king23 | src/Http/Router.php | Router.handleRoute | private function handleRoute($info, ServerRequestInterface $request, $route) : ResponseInterface
{
// initialize router attributes for the request
$attributes = [
'params' => [
'url' => [],
'host' => []
]
];
// prepare parameters
if ($paramstr = substr($request->getUri()->getPath(), strlen($route))) {
$attributes['params']['url'] = $this->filterParameters($info['parameters'], explode("/", $paramstr));
}
// check host parameters
if (count($info["hostparameters"]) > 0) {
$attributes['params']['host'] = $this->extractHostParameters($request, $info);
}
// put route parameters into king23.router.parameters attribute
$request = $request->withAttribute('king23.router', $attributes);
/** @var \King23\Controller\Controller $controller */
$controller = $this->container->get($info["class"]);
return $controller->dispatch($info["action"], $request);
} | php | private function handleRoute($info, ServerRequestInterface $request, $route) : ResponseInterface
{
// initialize router attributes for the request
$attributes = [
'params' => [
'url' => [],
'host' => []
]
];
// prepare parameters
if ($paramstr = substr($request->getUri()->getPath(), strlen($route))) {
$attributes['params']['url'] = $this->filterParameters($info['parameters'], explode("/", $paramstr));
}
// check host parameters
if (count($info["hostparameters"]) > 0) {
$attributes['params']['host'] = $this->extractHostParameters($request, $info);
}
// put route parameters into king23.router.parameters attribute
$request = $request->withAttribute('king23.router', $attributes);
/** @var \King23\Controller\Controller $controller */
$controller = $this->container->get($info["class"]);
return $controller->dispatch($info["action"], $request);
} | [
"private",
"function",
"handleRoute",
"(",
"$",
"info",
",",
"ServerRequestInterface",
"$",
"request",
",",
"$",
"route",
")",
":",
"ResponseInterface",
"{",
"// initialize router attributes for the request",
"$",
"attributes",
"=",
"[",
"'params'",
"=>",
"[",
"'url'",
"=>",
"[",
"]",
",",
"'host'",
"=>",
"[",
"]",
"]",
"]",
";",
"// prepare parameters",
"if",
"(",
"$",
"paramstr",
"=",
"substr",
"(",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"getPath",
"(",
")",
",",
"strlen",
"(",
"$",
"route",
")",
")",
")",
"{",
"$",
"attributes",
"[",
"'params'",
"]",
"[",
"'url'",
"]",
"=",
"$",
"this",
"->",
"filterParameters",
"(",
"$",
"info",
"[",
"'parameters'",
"]",
",",
"explode",
"(",
"\"/\"",
",",
"$",
"paramstr",
")",
")",
";",
"}",
"// check host parameters",
"if",
"(",
"count",
"(",
"$",
"info",
"[",
"\"hostparameters\"",
"]",
")",
">",
"0",
")",
"{",
"$",
"attributes",
"[",
"'params'",
"]",
"[",
"'host'",
"]",
"=",
"$",
"this",
"->",
"extractHostParameters",
"(",
"$",
"request",
",",
"$",
"info",
")",
";",
"}",
"// put route parameters into king23.router.parameters attribute",
"$",
"request",
"=",
"$",
"request",
"->",
"withAttribute",
"(",
"'king23.router'",
",",
"$",
"attributes",
")",
";",
"/** @var \\King23\\Controller\\Controller $controller */",
"$",
"controller",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"info",
"[",
"\"class\"",
"]",
")",
";",
"return",
"$",
"controller",
"->",
"dispatch",
"(",
"$",
"info",
"[",
"\"action\"",
"]",
",",
"$",
"request",
")",
";",
"}"
] | Handle a regular route
@param array $info
@param ServerRequestInterface $request
@param string $route
@return ResponseInterface
@throws \King23\Controller\Exceptions\ActionDoesNotExistException | [
"Handle",
"a",
"regular",
"route"
] | train | https://github.com/ppetermann/king23/blob/603896083ec89f5ac4d744abd3b1b4db3e914c95/src/Http/Router.php#L149-L176 |
ppetermann/king23 | src/Http/Router.php | Router.extractHostParameters | private function extractHostParameters($request, $info)
{
$hostname = $this->cleanHostName($request);
if (empty($hostname)) {
$params = [];
} else {
$params = array_reverse(explode(".", $hostname));
}
$parameters = $this->filterParameters($info['hostparameters'], $params);
return $parameters;
} | php | private function extractHostParameters($request, $info)
{
$hostname = $this->cleanHostName($request);
if (empty($hostname)) {
$params = [];
} else {
$params = array_reverse(explode(".", $hostname));
}
$parameters = $this->filterParameters($info['hostparameters'], $params);
return $parameters;
} | [
"private",
"function",
"extractHostParameters",
"(",
"$",
"request",
",",
"$",
"info",
")",
"{",
"$",
"hostname",
"=",
"$",
"this",
"->",
"cleanHostName",
"(",
"$",
"request",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"hostname",
")",
")",
"{",
"$",
"params",
"=",
"[",
"]",
";",
"}",
"else",
"{",
"$",
"params",
"=",
"array_reverse",
"(",
"explode",
"(",
"\".\"",
",",
"$",
"hostname",
")",
")",
";",
"}",
"$",
"parameters",
"=",
"$",
"this",
"->",
"filterParameters",
"(",
"$",
"info",
"[",
"'hostparameters'",
"]",
",",
"$",
"params",
")",
";",
"return",
"$",
"parameters",
";",
"}"
] | extract parameters from hostname
@param ServerRequestInterface $request
@param array $info
@return array | [
"extract",
"parameters",
"from",
"hostname"
] | train | https://github.com/ppetermann/king23/blob/603896083ec89f5ac4d744abd3b1b4db3e914c95/src/Http/Router.php#L203-L215 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.