repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
fxpio/fxp-security
Doctrine/ORM/Provider/SharingProvider.php
SharingProvider.addWhereForSharing
private function addWhereForSharing(QueryBuilder $qb, array $subjects, array $sids) { $where = ''; $parameters = []; foreach ($subjects as $i => $subject) { $class = 'subject'.$i.'_class'; $id = 'subject'.$i.'_id'; $parameters[$class] = $subject->getType(); $parameters[$id] = $subject->getIdentifier(); $where .= '' === $where ? '' : ' OR '; $where .= sprintf('(s.subjectClass = :%s AND s.subjectId = :%s)', $class, $id); } $qb->where($where); foreach ($parameters as $key => $value) { $qb->setParameter($key, $value); } return $this->addWhereSecurityIdentitiesForSharing($qb, $sids); }
php
private function addWhereForSharing(QueryBuilder $qb, array $subjects, array $sids) { $where = ''; $parameters = []; foreach ($subjects as $i => $subject) { $class = 'subject'.$i.'_class'; $id = 'subject'.$i.'_id'; $parameters[$class] = $subject->getType(); $parameters[$id] = $subject->getIdentifier(); $where .= '' === $where ? '' : ' OR '; $where .= sprintf('(s.subjectClass = :%s AND s.subjectId = :%s)', $class, $id); } $qb->where($where); foreach ($parameters as $key => $value) { $qb->setParameter($key, $value); } return $this->addWhereSecurityIdentitiesForSharing($qb, $sids); }
[ "private", "function", "addWhereForSharing", "(", "QueryBuilder", "$", "qb", ",", "array", "$", "subjects", ",", "array", "$", "sids", ")", "{", "$", "where", "=", "''", ";", "$", "parameters", "=", "[", "]", ";", "foreach", "(", "$", "subjects", "as",...
Add where condition for sharing. @param QueryBuilder $qb The query builder @param SubjectIdentityInterface[] $subjects The subjects @param SecurityIdentityInterface[] $sids The security identities @return QueryBuilder
[ "Add", "where", "condition", "for", "sharing", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Provider/SharingProvider.php#L209-L230
train
fxpio/fxp-security
Doctrine/ORM/Provider/SharingProvider.php
SharingProvider.addWhereSecurityIdentitiesForSharing
private function addWhereSecurityIdentitiesForSharing(QueryBuilder $qb, array $sids) { if (!empty($sids) && !empty($groupSids = $this->groupSecurityIdentities($sids))) { $where = ''; $parameters = []; $i = 0; foreach ($groupSids as $type => $identifiers) { $qClass = 'sid'.$i.'_class'; $qIdentifiers = 'sid'.$i.'_ids'; $parameters[$qClass] = $type; $parameters[$qIdentifiers] = $identifiers; $where .= '' === $where ? '' : ' OR '; $where .= sprintf('(s.identityClass = :%s AND s.identityName IN (:%s))', $qClass, $qIdentifiers); ++$i; } $qb->andWhere($where); foreach ($parameters as $key => $identifiers) { $qb->setParameter($key, $identifiers); } } return $qb; }
php
private function addWhereSecurityIdentitiesForSharing(QueryBuilder $qb, array $sids) { if (!empty($sids) && !empty($groupSids = $this->groupSecurityIdentities($sids))) { $where = ''; $parameters = []; $i = 0; foreach ($groupSids as $type => $identifiers) { $qClass = 'sid'.$i.'_class'; $qIdentifiers = 'sid'.$i.'_ids'; $parameters[$qClass] = $type; $parameters[$qIdentifiers] = $identifiers; $where .= '' === $where ? '' : ' OR '; $where .= sprintf('(s.identityClass = :%s AND s.identityName IN (:%s))', $qClass, $qIdentifiers); ++$i; } $qb->andWhere($where); foreach ($parameters as $key => $identifiers) { $qb->setParameter($key, $identifiers); } } return $qb; }
[ "private", "function", "addWhereSecurityIdentitiesForSharing", "(", "QueryBuilder", "$", "qb", ",", "array", "$", "sids", ")", "{", "if", "(", "!", "empty", "(", "$", "sids", ")", "&&", "!", "empty", "(", "$", "groupSids", "=", "$", "this", "->", "groupS...
Add security identities where condition for sharing. @param QueryBuilder $qb The query builder @param SecurityIdentityInterface[] $sids The security identities @return QueryBuilder
[ "Add", "security", "identities", "where", "condition", "for", "sharing", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Provider/SharingProvider.php#L240-L265
train
fxpio/fxp-security
Doctrine/ORM/Provider/SharingProvider.php
SharingProvider.groupSecurityIdentities
private function groupSecurityIdentities(array $sids) { $groupSids = []; if (null === $this->sharingManager) { throw new InvalidArgumentException('The "setSharingManager()" must be called before'); } foreach ($sids as $sid) { if (IdentityUtils::isValid($sid)) { $type = $this->sharingManager->getIdentityConfig($sid->getType())->getType(); $groupSids[$type][] = $sid->getIdentifier(); } } return $groupSids; }
php
private function groupSecurityIdentities(array $sids) { $groupSids = []; if (null === $this->sharingManager) { throw new InvalidArgumentException('The "setSharingManager()" must be called before'); } foreach ($sids as $sid) { if (IdentityUtils::isValid($sid)) { $type = $this->sharingManager->getIdentityConfig($sid->getType())->getType(); $groupSids[$type][] = $sid->getIdentifier(); } } return $groupSids; }
[ "private", "function", "groupSecurityIdentities", "(", "array", "$", "sids", ")", "{", "$", "groupSids", "=", "[", "]", ";", "if", "(", "null", "===", "$", "this", "->", "sharingManager", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'The \"set...
Group the security identities definition. @param SecurityIdentityInterface[] $sids The security identities @return array
[ "Group", "the", "security", "identities", "definition", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Provider/SharingProvider.php#L274-L290
train
fxpio/fxp-security
Doctrine/ORM/Provider/SharingProvider.php
SharingProvider.getSecurityIdentities
private function getSecurityIdentities($sids = null) { if (null === $sids) { $sids = $this->sidManager->getSecurityIdentities($this->tokenStorage->getToken()); } return null !== $sids ? $sids : []; }
php
private function getSecurityIdentities($sids = null) { if (null === $sids) { $sids = $this->sidManager->getSecurityIdentities($this->tokenStorage->getToken()); } return null !== $sids ? $sids : []; }
[ "private", "function", "getSecurityIdentities", "(", "$", "sids", "=", "null", ")", "{", "if", "(", "null", "===", "$", "sids", ")", "{", "$", "sids", "=", "$", "this", "->", "sidManager", "->", "getSecurityIdentities", "(", "$", "this", "->", "tokenStor...
Get the security identities. @param null|SecurityIdentityInterface[] $sids The security identities to filter the sharing entries @return SecurityIdentityInterface[]
[ "Get", "the", "security", "identities", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Provider/SharingProvider.php#L299-L308
train
fxpio/fxp-security
Doctrine/ORM/Provider/SharingProvider.php
SharingProvider.getRoleRepository
private function getRoleRepository() { if (null === $this->roleRepo) { $this->roleRepo = $this->getRepository(RoleInterface::class); } return $this->roleRepo; }
php
private function getRoleRepository() { if (null === $this->roleRepo) { $this->roleRepo = $this->getRepository(RoleInterface::class); } return $this->roleRepo; }
[ "private", "function", "getRoleRepository", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "roleRepo", ")", "{", "$", "this", "->", "roleRepo", "=", "$", "this", "->", "getRepository", "(", "RoleInterface", "::", "class", ")", ";", "}", "r...
Get the role repository. @return EntityRepository|ObjectRepository
[ "Get", "the", "role", "repository", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Provider/SharingProvider.php#L315-L322
train
fxpio/fxp-security
Doctrine/ORM/Provider/SharingProvider.php
SharingProvider.getSharingRepository
private function getSharingRepository() { if (null === $this->sharingRepo) { $this->sharingRepo = $this->getRepository(SharingInterface::class); } return $this->sharingRepo; }
php
private function getSharingRepository() { if (null === $this->sharingRepo) { $this->sharingRepo = $this->getRepository(SharingInterface::class); } return $this->sharingRepo; }
[ "private", "function", "getSharingRepository", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "sharingRepo", ")", "{", "$", "this", "->", "sharingRepo", "=", "$", "this", "->", "getRepository", "(", "SharingInterface", "::", "class", ")", ";",...
Get the sharing repository. @return EntityRepository|ObjectRepository
[ "Get", "the", "sharing", "repository", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Provider/SharingProvider.php#L329-L336
train
fxpio/fxp-security
Doctrine/ORM/Provider/SharingProvider.php
SharingProvider.getRepository
private function getRepository($classname) { $om = ManagerUtils::getManager($this->doctrine, $classname); return null !== $om ? $om->getRepository($classname) : null; }
php
private function getRepository($classname) { $om = ManagerUtils::getManager($this->doctrine, $classname); return null !== $om ? $om->getRepository($classname) : null; }
[ "private", "function", "getRepository", "(", "$", "classname", ")", "{", "$", "om", "=", "ManagerUtils", "::", "getManager", "(", "$", "this", "->", "doctrine", ",", "$", "classname", ")", ";", "return", "null", "!==", "$", "om", "?", "$", "om", "->", ...
Get the repository. @param string $classname The class name @return EntityRepository|ObjectRepository
[ "Get", "the", "repository", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Provider/SharingProvider.php#L345-L350
train
fxpio/fxp-security
Listener/GroupSecurityIdentitySubscriber.php
GroupSecurityIdentitySubscriber.addGroupSecurityIdentities
public function addGroupSecurityIdentities(AddSecurityIdentityEvent $event): void { try { $sids = $event->getSecurityIdentities(); $sids = IdentityUtils::merge( $sids, GroupSecurityIdentity::fromToken($event->getToken()) ); $event->setSecurityIdentities($sids); } catch (\InvalidArgumentException $e) { // ignore } }
php
public function addGroupSecurityIdentities(AddSecurityIdentityEvent $event): void { try { $sids = $event->getSecurityIdentities(); $sids = IdentityUtils::merge( $sids, GroupSecurityIdentity::fromToken($event->getToken()) ); $event->setSecurityIdentities($sids); } catch (\InvalidArgumentException $e) { // ignore } }
[ "public", "function", "addGroupSecurityIdentities", "(", "AddSecurityIdentityEvent", "$", "event", ")", ":", "void", "{", "try", "{", "$", "sids", "=", "$", "event", "->", "getSecurityIdentities", "(", ")", ";", "$", "sids", "=", "IdentityUtils", "::", "merge"...
Add group security identities. @param AddSecurityIdentityEvent $event The event
[ "Add", "group", "security", "identities", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Listener/GroupSecurityIdentitySubscriber.php#L42-L54
train
fxpio/fxp-security
Identity/IdentityUtils.php
IdentityUtils.merge
public static function merge(array $sids, array $newSids) { $existingSids = []; foreach ($sids as $sid) { $existingSids[] = $sid->getType().'::'.$sid->getIdentifier(); } foreach ($newSids as $sid) { $key = $sid->getType().'::'.$sid->getIdentifier(); if (!\in_array($key, $existingSids, true)) { $sids[] = $sid; $existingSids[] = $key; } } return $sids; }
php
public static function merge(array $sids, array $newSids) { $existingSids = []; foreach ($sids as $sid) { $existingSids[] = $sid->getType().'::'.$sid->getIdentifier(); } foreach ($newSids as $sid) { $key = $sid->getType().'::'.$sid->getIdentifier(); if (!\in_array($key, $existingSids, true)) { $sids[] = $sid; $existingSids[] = $key; } } return $sids; }
[ "public", "static", "function", "merge", "(", "array", "$", "sids", ",", "array", "$", "newSids", ")", "{", "$", "existingSids", "=", "[", "]", ";", "foreach", "(", "$", "sids", "as", "$", "sid", ")", "{", "$", "existingSids", "[", "]", "=", "$", ...
Merge the security identities. @param SecurityIdentityInterface[] $sids The security identities @param SecurityIdentityInterface[] $newSids The new security identities @return SecurityIdentityInterface[]
[ "Merge", "the", "security", "identities", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Identity/IdentityUtils.php#L31-L49
train
fxpio/fxp-security
Identity/IdentityUtils.php
IdentityUtils.filterRolesIdentities
public static function filterRolesIdentities(array $sids) { $roles = []; foreach ($sids as $sid) { if ($sid instanceof RoleSecurityIdentity && false === strpos($sid->getIdentifier(), 'IS_')) { $roles[] = OrganizationalUtil::format($sid->getIdentifier()); } } return array_values(array_unique($roles)); }
php
public static function filterRolesIdentities(array $sids) { $roles = []; foreach ($sids as $sid) { if ($sid instanceof RoleSecurityIdentity && false === strpos($sid->getIdentifier(), 'IS_')) { $roles[] = OrganizationalUtil::format($sid->getIdentifier()); } } return array_values(array_unique($roles)); }
[ "public", "static", "function", "filterRolesIdentities", "(", "array", "$", "sids", ")", "{", "$", "roles", "=", "[", "]", ";", "foreach", "(", "$", "sids", "as", "$", "sid", ")", "{", "if", "(", "$", "sid", "instanceof", "RoleSecurityIdentity", "&&", ...
Filter the role identities and convert to strings. @param SecurityIdentityInterface[] $sids The security identities @return string[]
[ "Filter", "the", "role", "identities", "and", "convert", "to", "strings", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Identity/IdentityUtils.php#L58-L69
train
fxpio/fxp-security
Identity/IdentityUtils.php
IdentityUtils.isValid
public static function isValid(SecurityIdentityInterface $sid) { return !$sid instanceof RoleSecurityIdentity || ($sid instanceof RoleSecurityIdentity && false === strpos($sid->getIdentifier(), 'IS_')); }
php
public static function isValid(SecurityIdentityInterface $sid) { return !$sid instanceof RoleSecurityIdentity || ($sid instanceof RoleSecurityIdentity && false === strpos($sid->getIdentifier(), 'IS_')); }
[ "public", "static", "function", "isValid", "(", "SecurityIdentityInterface", "$", "sid", ")", "{", "return", "!", "$", "sid", "instanceof", "RoleSecurityIdentity", "||", "(", "$", "sid", "instanceof", "RoleSecurityIdentity", "&&", "false", "===", "strpos", "(", ...
Check if the security identity is valid. @param SecurityIdentityInterface $sid The security identity @return bool
[ "Check", "if", "the", "security", "identity", "is", "valid", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Identity/IdentityUtils.php#L78-L82
train
fxpio/fxp-security
Identity/SecurityIdentityManager.php
SecurityIdentityManager.addCurrentUser
protected function addCurrentUser(TokenInterface $token, array $sids) { if (!$token instanceof AnonymousToken) { try { $sids[] = UserSecurityIdentity::fromToken($token); } catch (\InvalidArgumentException $e) { // ignore, user has no user security identity } } return $sids; }
php
protected function addCurrentUser(TokenInterface $token, array $sids) { if (!$token instanceof AnonymousToken) { try { $sids[] = UserSecurityIdentity::fromToken($token); } catch (\InvalidArgumentException $e) { // ignore, user has no user security identity } } return $sids; }
[ "protected", "function", "addCurrentUser", "(", "TokenInterface", "$", "token", ",", "array", "$", "sids", ")", "{", "if", "(", "!", "$", "token", "instanceof", "AnonymousToken", ")", "{", "try", "{", "$", "sids", "[", "]", "=", "UserSecurityIdentity", "::...
Add the security identity of current user. @param TokenInterface $token The token @param SecurityIdentityInterface[] $sids The security identities @return SecurityIdentityInterface[]
[ "Add", "the", "security", "identity", "of", "current", "user", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Identity/SecurityIdentityManager.php#L124-L135
train
fxpio/fxp-security
Identity/SecurityIdentityManager.php
SecurityIdentityManager.addReachableRoles
protected function addReachableRoles(TokenInterface $token, array $sids) { foreach ($this->roleHierarchy->getReachableRoles($token->getRoles()) as $role) { $sids[] = RoleSecurityIdentity::fromAccount(RoleUtil::formatName($role)); } return $sids; }
php
protected function addReachableRoles(TokenInterface $token, array $sids) { foreach ($this->roleHierarchy->getReachableRoles($token->getRoles()) as $role) { $sids[] = RoleSecurityIdentity::fromAccount(RoleUtil::formatName($role)); } return $sids; }
[ "protected", "function", "addReachableRoles", "(", "TokenInterface", "$", "token", ",", "array", "$", "sids", ")", "{", "foreach", "(", "$", "this", "->", "roleHierarchy", "->", "getReachableRoles", "(", "$", "token", "->", "getRoles", "(", ")", ")", "as", ...
Add the security identities of reachable roles. @param TokenInterface $token The token @param SecurityIdentityInterface[] $sids The security identities @return SecurityIdentityInterface[]
[ "Add", "the", "security", "identities", "of", "reachable", "roles", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Identity/SecurityIdentityManager.php#L145-L152
train
fxpio/fxp-security
Identity/SecurityIdentityManager.php
SecurityIdentityManager.addSpecialRoles
protected function addSpecialRoles(TokenInterface $token, array $sids) { $sids = $this->injectSpecialRoles($sids); if ($this->authenticationTrustResolver->isFullFledged($token)) { $sids[] = new RoleSecurityIdentity('role', AuthenticatedVoter::IS_AUTHENTICATED_FULLY); $sids[] = new RoleSecurityIdentity('role', AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED); $sids[] = new RoleSecurityIdentity('role', AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY); } elseif ($this->authenticationTrustResolver->isRememberMe($token)) { $sids[] = new RoleSecurityIdentity('role', AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED); $sids[] = new RoleSecurityIdentity('role', AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY); } elseif ($this->authenticationTrustResolver->isAnonymous($token)) { $sids[] = new RoleSecurityIdentity('role', AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY); } return $sids; }
php
protected function addSpecialRoles(TokenInterface $token, array $sids) { $sids = $this->injectSpecialRoles($sids); if ($this->authenticationTrustResolver->isFullFledged($token)) { $sids[] = new RoleSecurityIdentity('role', AuthenticatedVoter::IS_AUTHENTICATED_FULLY); $sids[] = new RoleSecurityIdentity('role', AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED); $sids[] = new RoleSecurityIdentity('role', AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY); } elseif ($this->authenticationTrustResolver->isRememberMe($token)) { $sids[] = new RoleSecurityIdentity('role', AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED); $sids[] = new RoleSecurityIdentity('role', AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY); } elseif ($this->authenticationTrustResolver->isAnonymous($token)) { $sids[] = new RoleSecurityIdentity('role', AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY); } return $sids; }
[ "protected", "function", "addSpecialRoles", "(", "TokenInterface", "$", "token", ",", "array", "$", "sids", ")", "{", "$", "sids", "=", "$", "this", "->", "injectSpecialRoles", "(", "$", "sids", ")", ";", "if", "(", "$", "this", "->", "authenticationTrustR...
Add the security identities of special roles. @param TokenInterface $token The token @param SecurityIdentityInterface[] $sids The security identities @return SecurityIdentityInterface[]
[ "Add", "the", "security", "identities", "of", "special", "roles", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Identity/SecurityIdentityManager.php#L162-L178
train
fxpio/fxp-security
Identity/SecurityIdentityManager.php
SecurityIdentityManager.injectSpecialRoles
private function injectSpecialRoles(array $sids) { $roles = $this->getRoleNames($sids); foreach ($this->roles as $role) { if (!\in_array($role, $roles, true)) { $sids[] = RoleSecurityIdentity::fromAccount($role); } } return $sids; }
php
private function injectSpecialRoles(array $sids) { $roles = $this->getRoleNames($sids); foreach ($this->roles as $role) { if (!\in_array($role, $roles, true)) { $sids[] = RoleSecurityIdentity::fromAccount($role); } } return $sids; }
[ "private", "function", "injectSpecialRoles", "(", "array", "$", "sids", ")", "{", "$", "roles", "=", "$", "this", "->", "getRoleNames", "(", "$", "sids", ")", ";", "foreach", "(", "$", "this", "->", "roles", "as", "$", "role", ")", "{", "if", "(", ...
Inject the special roles. @param SecurityIdentityInterface[] $sids The security identities @return SecurityIdentityInterface[]
[ "Inject", "the", "special", "roles", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Identity/SecurityIdentityManager.php#L187-L198
train
fxpio/fxp-security
Identity/SecurityIdentityManager.php
SecurityIdentityManager.getRoleNames
private function getRoleNames(array $sids) { $roles = []; foreach ($sids as $sid) { if ($sid instanceof RoleSecurityIdentity) { $roles[] = $sid->getIdentifier(); } } return $roles; }
php
private function getRoleNames(array $sids) { $roles = []; foreach ($sids as $sid) { if ($sid instanceof RoleSecurityIdentity) { $roles[] = $sid->getIdentifier(); } } return $roles; }
[ "private", "function", "getRoleNames", "(", "array", "$", "sids", ")", "{", "$", "roles", "=", "[", "]", ";", "foreach", "(", "$", "sids", "as", "$", "sid", ")", "{", "if", "(", "$", "sid", "instanceof", "RoleSecurityIdentity", ")", "{", "$", "roles"...
Get the role names of security identities. @param SecurityIdentityInterface[] $sids The security identities @return string[]
[ "Get", "the", "role", "names", "of", "security", "identities", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Identity/SecurityIdentityManager.php#L207-L218
train
fxpio/fxp-security
Doctrine/ORM/Event/GetFilterEvent.php
GetFilterEvent.getRealParameter
public function getRealParameter($name) { $this->getParameter($name); if (null === $this->refParameters) { $this->refParameters = new \ReflectionProperty(SQLFilter::class, 'parameters'); $this->refParameters->setAccessible(true); } $parameters = $this->refParameters->getValue($this->filter); return $parameters[$name]['value']; }
php
public function getRealParameter($name) { $this->getParameter($name); if (null === $this->refParameters) { $this->refParameters = new \ReflectionProperty(SQLFilter::class, 'parameters'); $this->refParameters->setAccessible(true); } $parameters = $this->refParameters->getValue($this->filter); return $parameters[$name]['value']; }
[ "public", "function", "getRealParameter", "(", "$", "name", ")", "{", "$", "this", "->", "getParameter", "(", "$", "name", ")", ";", "if", "(", "null", "===", "$", "this", "->", "refParameters", ")", "{", "$", "this", "->", "refParameters", "=", "new",...
Gets a parameter to use in a query without the output escaping. @param string $name The name of the parameter @throws \InvalidArgumentException @return null|bool|bool[]|float|float[]|int|int[]|string|string[]
[ "Gets", "a", "parameter", "to", "use", "in", "a", "query", "without", "the", "output", "escaping", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Event/GetFilterEvent.php#L176-L188
train
fxpio/fxp-security
Sharing/SharingManager.php
SharingManager.buildSubjects
private function buildSubjects(array $objects) { $subjects = []; foreach ($objects as $object) { $subject = SubjectIdentity::fromObject($object); $id = SharingUtils::getCacheId($subject); if (!\array_key_exists($id, $this->cacheSubjectSharing) && $this->hasIdentityPermissible() && $this->hasSharingVisibility($subject) && $this->hasSubjectConfig($subject->getType())) { $subjects[$id] = $subject; $this->cacheSubjectSharing[$id] = false; } } return $subjects; }
php
private function buildSubjects(array $objects) { $subjects = []; foreach ($objects as $object) { $subject = SubjectIdentity::fromObject($object); $id = SharingUtils::getCacheId($subject); if (!\array_key_exists($id, $this->cacheSubjectSharing) && $this->hasIdentityPermissible() && $this->hasSharingVisibility($subject) && $this->hasSubjectConfig($subject->getType())) { $subjects[$id] = $subject; $this->cacheSubjectSharing[$id] = false; } } return $subjects; }
[ "private", "function", "buildSubjects", "(", "array", "$", "objects", ")", "{", "$", "subjects", "=", "[", "]", ";", "foreach", "(", "$", "objects", "as", "$", "object", ")", "{", "$", "subject", "=", "SubjectIdentity", "::", "fromObject", "(", "$", "o...
Convert the objects into subject identities. @param object[] $objects The objects @return SubjectIdentityInterface[]
[ "Convert", "the", "objects", "into", "subject", "identities", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Sharing/SharingManager.php#L200-L218
train
fxpio/fxp-security
Sharing/SharingManager.php
SharingManager.buildSharingEntries
private function buildSharingEntries(array $subjects) { $entries = []; if (!empty($subjects)) { $res = $this->provider->getSharingEntries(array_values($subjects)); foreach ($res as $sharing) { $id = SharingUtils::getSharingCacheId($sharing); $entries[$id][] = $sharing; } } return $entries; }
php
private function buildSharingEntries(array $subjects) { $entries = []; if (!empty($subjects)) { $res = $this->provider->getSharingEntries(array_values($subjects)); foreach ($res as $sharing) { $id = SharingUtils::getSharingCacheId($sharing); $entries[$id][] = $sharing; } } return $entries; }
[ "private", "function", "buildSharingEntries", "(", "array", "$", "subjects", ")", "{", "$", "entries", "=", "[", "]", ";", "if", "(", "!", "empty", "(", "$", "subjects", ")", ")", "{", "$", "res", "=", "$", "this", "->", "provider", "->", "getSharing...
Build the sharing entries with the subject identities. @param SubjectIdentityInterface[] $subjects The subjects @return array The map of cache id and sharing instance
[ "Build", "the", "sharing", "entries", "with", "the", "subject", "identities", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Sharing/SharingManager.php#L227-L241
train
fxpio/fxp-security
Sharing/SharingManager.php
SharingManager.preloadPermissionsOfSharingRoles
private function preloadPermissionsOfSharingRoles(array $objects): void { if (!$this->hasIdentityRoleable()) { return; } $subjects = $this->buildMapSubject($objects); foreach ($subjects as $id => $subject) { if (!isset($this->cacheRoleSharing[$id]) && isset($this->cacheSubjectSharing[$id]['sharings'])) { $this->buildCacheRoleSharing($this->cacheSubjectSharing[$id]['sharings'], $id); } } }
php
private function preloadPermissionsOfSharingRoles(array $objects): void { if (!$this->hasIdentityRoleable()) { return; } $subjects = $this->buildMapSubject($objects); foreach ($subjects as $id => $subject) { if (!isset($this->cacheRoleSharing[$id]) && isset($this->cacheSubjectSharing[$id]['sharings'])) { $this->buildCacheRoleSharing($this->cacheSubjectSharing[$id]['sharings'], $id); } } }
[ "private", "function", "preloadPermissionsOfSharingRoles", "(", "array", "$", "objects", ")", ":", "void", "{", "if", "(", "!", "$", "this", "->", "hasIdentityRoleable", "(", ")", ")", "{", "return", ";", "}", "$", "subjects", "=", "$", "this", "->", "bu...
Preload permissions of sharing roles. @param object[] $objects The objects
[ "Preload", "permissions", "of", "sharing", "roles", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Sharing/SharingManager.php#L248-L262
train
fxpio/fxp-security
Sharing/SharingManager.php
SharingManager.buildMapSubject
private function buildMapSubject(array $objects) { $subjects = []; foreach ($objects as $object) { $subject = SubjectIdentity::fromObject($object); $id = SharingUtils::getCacheId($subject); $subjects[$id] = $subject; } return $subjects; }
php
private function buildMapSubject(array $objects) { $subjects = []; foreach ($objects as $object) { $subject = SubjectIdentity::fromObject($object); $id = SharingUtils::getCacheId($subject); $subjects[$id] = $subject; } return $subjects; }
[ "private", "function", "buildMapSubject", "(", "array", "$", "objects", ")", "{", "$", "subjects", "=", "[", "]", ";", "foreach", "(", "$", "objects", "as", "$", "object", ")", "{", "$", "subject", "=", "SubjectIdentity", "::", "fromObject", "(", "$", ...
Build the map of subjects with cache ids. @param object[] $objects The objects @return array The map of cache id and subject
[ "Build", "the", "map", "of", "subjects", "with", "cache", "ids", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Sharing/SharingManager.php#L271-L282
train
fxpio/fxp-security
Sharing/SharingManager.php
SharingManager.buildCacheRoleSharing
private function buildCacheRoleSharing(array $sharings, $id): void { $this->cacheRoleSharing[$id] = []; foreach ($sharings as $sharing) { foreach ($sharing->getRoles() as $role) { $this->cacheRoleSharing[$id][] = $role; } } $this->cacheRoleSharing[$id] = array_unique($this->cacheRoleSharing[$id]); }
php
private function buildCacheRoleSharing(array $sharings, $id): void { $this->cacheRoleSharing[$id] = []; foreach ($sharings as $sharing) { foreach ($sharing->getRoles() as $role) { $this->cacheRoleSharing[$id][] = $role; } } $this->cacheRoleSharing[$id] = array_unique($this->cacheRoleSharing[$id]); }
[ "private", "function", "buildCacheRoleSharing", "(", "array", "$", "sharings", ",", "$", "id", ")", ":", "void", "{", "$", "this", "->", "cacheRoleSharing", "[", "$", "id", "]", "=", "[", "]", ";", "foreach", "(", "$", "sharings", "as", "$", "sharing",...
Build the cache role sharing. @param SharingInterface[] $sharings The sharing instances @param string $id The cache id
[ "Build", "the", "cache", "role", "sharing", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Sharing/SharingManager.php#L290-L301
train
fxpio/fxp-security
Sharing/SharingManager.php
SharingManager.doLoadSharingPermissions
private function doLoadSharingPermissions(array $idSubjects, array $roles): void { /** @var RoleInterface[] $mapRoles */ $mapRoles = []; $cRoles = $this->provider->getPermissionRoles($roles); foreach ($cRoles as $role) { $mapRoles[$role->getName()] = $role; } /** @var SubjectIdentityInterface $subject */ foreach ($idSubjects as $id => $subject) { foreach ($this->cacheRoleSharing[$id] as $roleId) { if (isset($mapRoles[$roleId])) { $cRole = $mapRoles[$roleId]; foreach ($cRole->getPermissions() as $perm) { $class = $subject->getType(); $field = PermissionUtils::getMapAction($perm->getField()); $this->cacheSharing[$id][$class][$field][$perm->getOperation()] = true; } } } } }
php
private function doLoadSharingPermissions(array $idSubjects, array $roles): void { /** @var RoleInterface[] $mapRoles */ $mapRoles = []; $cRoles = $this->provider->getPermissionRoles($roles); foreach ($cRoles as $role) { $mapRoles[$role->getName()] = $role; } /** @var SubjectIdentityInterface $subject */ foreach ($idSubjects as $id => $subject) { foreach ($this->cacheRoleSharing[$id] as $roleId) { if (isset($mapRoles[$roleId])) { $cRole = $mapRoles[$roleId]; foreach ($cRole->getPermissions() as $perm) { $class = $subject->getType(); $field = PermissionUtils::getMapAction($perm->getField()); $this->cacheSharing[$id][$class][$field][$perm->getOperation()] = true; } } } } }
[ "private", "function", "doLoadSharingPermissions", "(", "array", "$", "idSubjects", ",", "array", "$", "roles", ")", ":", "void", "{", "/** @var RoleInterface[] $mapRoles */", "$", "mapRoles", "=", "[", "]", ";", "$", "cRoles", "=", "$", "this", "->", "provide...
Action to load the permissions of sharing roles. @param array $idSubjects The map of subject id and subject @param string[] $roles The roles
[ "Action", "to", "load", "the", "permissions", "of", "sharing", "roles", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Sharing/SharingManager.php#L309-L333
train
fxpio/fxp-security
Authorization/Voter/PermissionVoter.php
PermissionVoter.isSubjectSupported
protected function isSubjectSupported($subject) { if (null === $subject || \is_string($subject) || $subject instanceof FieldVote || \is_object($subject)) { return true; } return \is_array($subject) && isset($subject[0], $subject[1]) && (\is_string($subject[0]) || \is_object($subject[0])) && \is_string($subject[1]); }
php
protected function isSubjectSupported($subject) { if (null === $subject || \is_string($subject) || $subject instanceof FieldVote || \is_object($subject)) { return true; } return \is_array($subject) && isset($subject[0], $subject[1]) && (\is_string($subject[0]) || \is_object($subject[0])) && \is_string($subject[1]); }
[ "protected", "function", "isSubjectSupported", "(", "$", "subject", ")", "{", "if", "(", "null", "===", "$", "subject", "||", "\\", "is_string", "(", "$", "subject", ")", "||", "$", "subject", "instanceof", "FieldVote", "||", "\\", "is_object", "(", "$", ...
Check if the subject is supported. @param null|FieldVote|mixed $subject The subject @return bool
[ "Check", "if", "the", "subject", "is", "supported", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Authorization/Voter/PermissionVoter.php#L78-L89
train
fxpio/fxp-security
Identity/SubjectUtils.php
SubjectUtils.getSubjectIdentity
public static function getSubjectIdentity($subject) { if ($subject instanceof SubjectIdentityInterface) { return $subject; } if (\is_string($subject)) { return SubjectIdentity::fromClassname($subject); } if (\is_object($subject)) { return SubjectIdentity::fromObject($subject); } throw new UnexpectedTypeException($subject, SubjectIdentityInterface::class.'|object|string'); }
php
public static function getSubjectIdentity($subject) { if ($subject instanceof SubjectIdentityInterface) { return $subject; } if (\is_string($subject)) { return SubjectIdentity::fromClassname($subject); } if (\is_object($subject)) { return SubjectIdentity::fromObject($subject); } throw new UnexpectedTypeException($subject, SubjectIdentityInterface::class.'|object|string'); }
[ "public", "static", "function", "getSubjectIdentity", "(", "$", "subject", ")", "{", "if", "(", "$", "subject", "instanceof", "SubjectIdentityInterface", ")", "{", "return", "$", "subject", ";", "}", "if", "(", "\\", "is_string", "(", "$", "subject", ")", ...
Get the subject identity. @param object|string|SubjectIdentityInterface $subject The subject instance or classname @return SubjectIdentityInterface
[ "Get", "the", "subject", "identity", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Identity/SubjectUtils.php#L30-L45
train
fxpio/fxp-security
Role/RoleHierarchy.php
RoleHierarchy.doGetReachableRoles
protected function doGetReachableRoles(array $roles, $suffix = '') { if (0 === \count($roles)) { return $roles; } $item = null; $roles = $this->formatRoles($roles); $id = $this->getUniqueId($roles); if (null !== ($reachableRoles = $this->getCachedReachableRoles($id, $item))) { return $reachableRoles; } // build hierarchy /** @var string[] $reachableRoles */ $reachableRoles = RoleUtil::formatNames(parent::getReachableRoles(RoleUtil::formatRoles($roles))); $isPermEnabled = true; if (null !== $this->eventDispatcher) { $event = new PreReachableRoleEvent($reachableRoles); $this->eventDispatcher->dispatch(ReachableRoleEvents::PRE, $event); $reachableRoles = $event->getReachableRoles(); $isPermEnabled = $event->isPermissionEnabled(); } return $this->getAllRoles($reachableRoles, $roles, $id, $item, $isPermEnabled, $suffix); }
php
protected function doGetReachableRoles(array $roles, $suffix = '') { if (0 === \count($roles)) { return $roles; } $item = null; $roles = $this->formatRoles($roles); $id = $this->getUniqueId($roles); if (null !== ($reachableRoles = $this->getCachedReachableRoles($id, $item))) { return $reachableRoles; } // build hierarchy /** @var string[] $reachableRoles */ $reachableRoles = RoleUtil::formatNames(parent::getReachableRoles(RoleUtil::formatRoles($roles))); $isPermEnabled = true; if (null !== $this->eventDispatcher) { $event = new PreReachableRoleEvent($reachableRoles); $this->eventDispatcher->dispatch(ReachableRoleEvents::PRE, $event); $reachableRoles = $event->getReachableRoles(); $isPermEnabled = $event->isPermissionEnabled(); } return $this->getAllRoles($reachableRoles, $roles, $id, $item, $isPermEnabled, $suffix); }
[ "protected", "function", "doGetReachableRoles", "(", "array", "$", "roles", ",", "$", "suffix", "=", "''", ")", "{", "if", "(", "0", "===", "\\", "count", "(", "$", "roles", ")", ")", "{", "return", "$", "roles", ";", "}", "$", "item", "=", "null",...
Returns an array of all roles reachable by the given ones. @param string[] $roles An array of roles @param string $suffix The role name suffix @return string[] An array of role instances
[ "Returns", "an", "array", "of", "all", "roles", "reachable", "by", "the", "given", "ones", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Role/RoleHierarchy.php#L107-L134
train
fxpio/fxp-security
Role/RoleHierarchy.php
RoleHierarchy.getCachedReachableRoles
private function getCachedReachableRoles($id, &$item) { $roles = null; // find the hierarchy in execution cache if (isset($this->cacheExec[$id])) { return $this->cacheExec[$id]; } // find the hierarchy in cache if (null !== $this->cache) { $item = $this->cache->getItem($id); $reachableRoles = $item->get(); if ($item->isHit() && null !== $reachableRoles) { $roles = $reachableRoles; } } return $roles; }
php
private function getCachedReachableRoles($id, &$item) { $roles = null; // find the hierarchy in execution cache if (isset($this->cacheExec[$id])) { return $this->cacheExec[$id]; } // find the hierarchy in cache if (null !== $this->cache) { $item = $this->cache->getItem($id); $reachableRoles = $item->get(); if ($item->isHit() && null !== $reachableRoles) { $roles = $reachableRoles; } } return $roles; }
[ "private", "function", "getCachedReachableRoles", "(", "$", "id", ",", "&", "$", "item", ")", "{", "$", "roles", "=", "null", ";", "// find the hierarchy in execution cache", "if", "(", "isset", "(", "$", "this", "->", "cacheExec", "[", "$", "id", "]", ")"...
Get the reachable roles in cache if available. @param string $id The cache id @param null $item The cache item variable passed by reference @throws @return null|string[]
[ "Get", "the", "reachable", "roles", "in", "cache", "if", "available", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Role/RoleHierarchy.php#L206-L226
train
fxpio/fxp-security
Role/RoleHierarchy.php
RoleHierarchy.findRecords
private function findRecords(array $reachableRoles, array $roles) { $recordRoles = []; $om = ManagerUtils::getManager($this->registry, $this->roleClassname); $repo = $om->getRepository($this->roleClassname); $filters = SqlFilterUtil::findFilters($om, [], true); SqlFilterUtil::disableFilters($om, $filters); if (\count($roles) > 0) { $recordRoles = $repo->findBy(['name' => $this->cleanRoleNames($roles)]); } $loopReachableRoles = [$reachableRoles]; /** @var RoleHierarchicalInterface $eRole */ foreach ($recordRoles as $eRole) { $suffix = $this->buildRoleSuffix($roles[$eRole->getName()] ?? null); $subRoles = RoleUtil::formatNames($eRole->getChildren()->toArray()); $loopReachableRoles[] = $this->doGetReachableRoles($subRoles, $suffix); } SqlFilterUtil::enableFilters($om, $filters); return array_merge(...$loopReachableRoles); }
php
private function findRecords(array $reachableRoles, array $roles) { $recordRoles = []; $om = ManagerUtils::getManager($this->registry, $this->roleClassname); $repo = $om->getRepository($this->roleClassname); $filters = SqlFilterUtil::findFilters($om, [], true); SqlFilterUtil::disableFilters($om, $filters); if (\count($roles) > 0) { $recordRoles = $repo->findBy(['name' => $this->cleanRoleNames($roles)]); } $loopReachableRoles = [$reachableRoles]; /** @var RoleHierarchicalInterface $eRole */ foreach ($recordRoles as $eRole) { $suffix = $this->buildRoleSuffix($roles[$eRole->getName()] ?? null); $subRoles = RoleUtil::formatNames($eRole->getChildren()->toArray()); $loopReachableRoles[] = $this->doGetReachableRoles($subRoles, $suffix); } SqlFilterUtil::enableFilters($om, $filters); return array_merge(...$loopReachableRoles); }
[ "private", "function", "findRecords", "(", "array", "$", "reachableRoles", ",", "array", "$", "roles", ")", "{", "$", "recordRoles", "=", "[", "]", ";", "$", "om", "=", "ManagerUtils", "::", "getManager", "(", "$", "this", "->", "registry", ",", "$", "...
Find the roles in database. @param string[] $reachableRoles The reachable roles @param string[] $roles The role names @throws @return string[]
[ "Find", "the", "roles", "in", "database", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Role/RoleHierarchy.php#L272-L297
train
fxpio/fxp-security
Role/RoleHierarchy.php
RoleHierarchy.getCleanedRoles
private function getCleanedRoles(array $reachableRoles, $suffix = '') { $existingRoles = []; $finalRoles = []; foreach ($reachableRoles as $role) { $name = $this->formatCleanedRoleName($role); if (!\in_array($name, $existingRoles, true)) { $rSuffix = 'ROLE_USER' !== $name && 'ORGANIZATION_ROLE_USER' !== $name ? $suffix : ''; $existingRoles[] = $name; $finalRoles[] = $role.$rSuffix; } } return $finalRoles; }
php
private function getCleanedRoles(array $reachableRoles, $suffix = '') { $existingRoles = []; $finalRoles = []; foreach ($reachableRoles as $role) { $name = $this->formatCleanedRoleName($role); if (!\in_array($name, $existingRoles, true)) { $rSuffix = 'ROLE_USER' !== $name && 'ORGANIZATION_ROLE_USER' !== $name ? $suffix : ''; $existingRoles[] = $name; $finalRoles[] = $role.$rSuffix; } } return $finalRoles; }
[ "private", "function", "getCleanedRoles", "(", "array", "$", "reachableRoles", ",", "$", "suffix", "=", "''", ")", "{", "$", "existingRoles", "=", "[", "]", ";", "$", "finalRoles", "=", "[", "]", ";", "foreach", "(", "$", "reachableRoles", "as", "$", "...
Cleaning the double roles. @param string[] $reachableRoles The reachable roles @param string $suffix The role name suffix @return string[]
[ "Cleaning", "the", "double", "roles", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Role/RoleHierarchy.php#L307-L323
train
fxpio/fxp-security
Doctrine/ORM/Provider/PermissionProvider.php
PermissionProvider.validateMaster
private function validateMaster(PermissionConfigInterface $config, $om): void { if (null === $om) { $msg = 'The doctrine object manager is not found for the class "%s"'; throw new InvalidArgumentException(sprintf($msg, $config->getType())); } if (null === $config->getMaster()) { $msg = 'The permission master association is not configured for the class "%s"'; throw new InvalidArgumentException(sprintf($msg, $config->getType())); } }
php
private function validateMaster(PermissionConfigInterface $config, $om): void { if (null === $om) { $msg = 'The doctrine object manager is not found for the class "%s"'; throw new InvalidArgumentException(sprintf($msg, $config->getType())); } if (null === $config->getMaster()) { $msg = 'The permission master association is not configured for the class "%s"'; throw new InvalidArgumentException(sprintf($msg, $config->getType())); } }
[ "private", "function", "validateMaster", "(", "PermissionConfigInterface", "$", "config", ",", "$", "om", ")", ":", "void", "{", "if", "(", "null", "===", "$", "om", ")", "{", "$", "msg", "=", "'The doctrine object manager is not found for the class \"%s\"'", ";",...
Validate the master config. @param PermissionConfigInterface $config The permission config @param null|ObjectManager $om The doctrine object manager
[ "Validate", "the", "master", "config", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Provider/PermissionProvider.php#L139-L152
train
fxpio/fxp-security
Doctrine/ORM/Provider/PermissionProvider.php
PermissionProvider.addWhereOptionalField
private function addWhereOptionalField(QueryBuilder $qb, $field, $value): void { if (null === $value) { $qb->andWhere('p.'.$field.' IS NULL'); } else { $qb->andWhere('p.'.$field.' = :'.$field)->setParameter($field, $value); } }
php
private function addWhereOptionalField(QueryBuilder $qb, $field, $value): void { if (null === $value) { $qb->andWhere('p.'.$field.' IS NULL'); } else { $qb->andWhere('p.'.$field.' = :'.$field)->setParameter($field, $value); } }
[ "private", "function", "addWhereOptionalField", "(", "QueryBuilder", "$", "qb", ",", "$", "field", ",", "$", "value", ")", ":", "void", "{", "if", "(", "null", "===", "$", "value", ")", "{", "$", "qb", "->", "andWhere", "(", "'p.'", ".", "$", "field"...
Add the optional field condition. @param QueryBuilder $qb The query builder @param string $field The field name @param null|mixed $value The value
[ "Add", "the", "optional", "field", "condition", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Provider/PermissionProvider.php#L161-L168
train
fxpio/fxp-security
Doctrine/ORM/Provider/PermissionProvider.php
PermissionProvider.addWhereContexts
private function addWhereContexts(QueryBuilder $qb, $contexts = null): void { if (null !== $contexts) { $contexts = (array) $contexts; $where = 'p.contexts IS NULL'; foreach ($contexts as $context) { $key = 'context_'.$context; $where .= sprintf(' OR p.contexts LIKE :%s', $key); $qb->setParameter($key, '%"'.$context.'"%'); } $qb->andWhere($where); } }
php
private function addWhereContexts(QueryBuilder $qb, $contexts = null): void { if (null !== $contexts) { $contexts = (array) $contexts; $where = 'p.contexts IS NULL'; foreach ($contexts as $context) { $key = 'context_'.$context; $where .= sprintf(' OR p.contexts LIKE :%s', $key); $qb->setParameter($key, '%"'.$context.'"%'); } $qb->andWhere($where); } }
[ "private", "function", "addWhereContexts", "(", "QueryBuilder", "$", "qb", ",", "$", "contexts", "=", "null", ")", ":", "void", "{", "if", "(", "null", "!==", "$", "contexts", ")", "{", "$", "contexts", "=", "(", "array", ")", "$", "contexts", ";", "...
Add the permission contexts condition. @param QueryBuilder $qb The query builder @param null|string|string[] $contexts The contexts
[ "Add", "the", "permission", "contexts", "condition", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Provider/PermissionProvider.php#L176-L190
train
fxpio/fxp-security
Doctrine/ORM/Provider/PermissionProvider.php
PermissionProvider.getPermissionRepository
private function getPermissionRepository() { if (null === $this->permissionRepo) { /** @var EntityRepository $repo */ $repo = RepositoryUtils::getRepository($this->doctrine, PermissionInterface::class); $this->permissionRepo = $repo; } return $this->permissionRepo; }
php
private function getPermissionRepository() { if (null === $this->permissionRepo) { /** @var EntityRepository $repo */ $repo = RepositoryUtils::getRepository($this->doctrine, PermissionInterface::class); $this->permissionRepo = $repo; } return $this->permissionRepo; }
[ "private", "function", "getPermissionRepository", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "permissionRepo", ")", "{", "/** @var EntityRepository $repo */", "$", "repo", "=", "RepositoryUtils", "::", "getRepository", "(", "$", "this", "->", "d...
Get the permission repository. @return EntityRepository
[ "Get", "the", "permission", "repository", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Provider/PermissionProvider.php#L197-L206
train
fxpio/fxp-security
Doctrine/ORM/Filter/Listener/PrivateSharingSubscriber.php
PrivateSharingSubscriber.getFilter
public function getFilter(GetFilterEvent $event): void { $filter = $this->buildSharingFilter($event); $filter = $this->buildOwnerFilter($event, $filter); $event->setFilterConstraint($filter); }
php
public function getFilter(GetFilterEvent $event): void { $filter = $this->buildSharingFilter($event); $filter = $this->buildOwnerFilter($event, $filter); $event->setFilterConstraint($filter); }
[ "public", "function", "getFilter", "(", "GetFilterEvent", "$", "event", ")", ":", "void", "{", "$", "filter", "=", "$", "this", "->", "buildSharingFilter", "(", "$", "event", ")", ";", "$", "filter", "=", "$", "this", "->", "buildOwnerFilter", "(", "$", ...
Get the sharing filter. @param GetFilterEvent $event The event
[ "Get", "the", "sharing", "filter", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Filter/Listener/PrivateSharingSubscriber.php#L51-L57
train
fxpio/fxp-security
Doctrine/ORM/Filter/Listener/PrivateSharingSubscriber.php
PrivateSharingSubscriber.buildSharingFilter
private function buildSharingFilter(GetFilterEvent $event) { $targetEntity = $event->getTargetEntity(); $targetTableAlias = $event->getTargetTableAlias(); $connection = $event->getConnection(); $classname = $connection->quote($targetEntity->getName()); $meta = $event->getSharingClassMetadata(); $identifier = DoctrineUtils::castIdentifier($targetEntity, $connection); return <<<SELECTCLAUSE {$targetTableAlias}.{$meta->getColumnName('id')} IN (SELECT s.{$meta->getColumnName('subjectId')}{$identifier} FROM {$meta->getTableName()} s WHERE s.{$meta->getColumnName('subjectClass')} = {$classname} AND s.{$meta->getColumnName('enabled')} IS TRUE AND (s.{$meta->getColumnName('startedAt')} IS NULL OR s.{$meta->getColumnName('startedAt')} <= CURRENT_TIMESTAMP) AND (s.{$meta->getColumnName('endedAt')} IS NULL OR s.{$meta->getColumnName('endedAt')} >= CURRENT_TIMESTAMP) AND ({$this->addWhereSecurityIdentitiesForSharing($event, $meta)}) GROUP BY s.{$meta->getColumnName('subjectId')}) SELECTCLAUSE; }
php
private function buildSharingFilter(GetFilterEvent $event) { $targetEntity = $event->getTargetEntity(); $targetTableAlias = $event->getTargetTableAlias(); $connection = $event->getConnection(); $classname = $connection->quote($targetEntity->getName()); $meta = $event->getSharingClassMetadata(); $identifier = DoctrineUtils::castIdentifier($targetEntity, $connection); return <<<SELECTCLAUSE {$targetTableAlias}.{$meta->getColumnName('id')} IN (SELECT s.{$meta->getColumnName('subjectId')}{$identifier} FROM {$meta->getTableName()} s WHERE s.{$meta->getColumnName('subjectClass')} = {$classname} AND s.{$meta->getColumnName('enabled')} IS TRUE AND (s.{$meta->getColumnName('startedAt')} IS NULL OR s.{$meta->getColumnName('startedAt')} <= CURRENT_TIMESTAMP) AND (s.{$meta->getColumnName('endedAt')} IS NULL OR s.{$meta->getColumnName('endedAt')} >= CURRENT_TIMESTAMP) AND ({$this->addWhereSecurityIdentitiesForSharing($event, $meta)}) GROUP BY s.{$meta->getColumnName('subjectId')}) SELECTCLAUSE; }
[ "private", "function", "buildSharingFilter", "(", "GetFilterEvent", "$", "event", ")", "{", "$", "targetEntity", "=", "$", "event", "->", "getTargetEntity", "(", ")", ";", "$", "targetTableAlias", "=", "$", "event", "->", "getTargetTableAlias", "(", ")", ";", ...
Build the query filter with sharing entries. @param GetFilterEvent $event The event @return string
[ "Build", "the", "query", "filter", "with", "sharing", "entries", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Filter/Listener/PrivateSharingSubscriber.php#L66-L89
train
fxpio/fxp-security
Doctrine/ORM/Filter/Listener/PrivateSharingSubscriber.php
PrivateSharingSubscriber.addWhereSecurityIdentitiesForSharing
private function addWhereSecurityIdentitiesForSharing(GetFilterEvent $event, ClassMetadata $meta) { $where = ''; $mapSids = (array) $event->getRealParameter('map_security_identities'); $mapSids = !empty($mapSids) ? $mapSids : ['_without_security_identity' => 'null']; $connection = $event->getConnection(); foreach ($mapSids as $type => $stringIds) { $where .= '' === $where ? '' : ' OR '; $where .= sprintf( '(s.%s = %s AND s.%s IN (%s))', $meta->getColumnName('identityClass'), $connection->quote($type), $meta->getColumnName('identityName'), $stringIds ); } return $where; }
php
private function addWhereSecurityIdentitiesForSharing(GetFilterEvent $event, ClassMetadata $meta) { $where = ''; $mapSids = (array) $event->getRealParameter('map_security_identities'); $mapSids = !empty($mapSids) ? $mapSids : ['_without_security_identity' => 'null']; $connection = $event->getConnection(); foreach ($mapSids as $type => $stringIds) { $where .= '' === $where ? '' : ' OR '; $where .= sprintf( '(s.%s = %s AND s.%s IN (%s))', $meta->getColumnName('identityClass'), $connection->quote($type), $meta->getColumnName('identityName'), $stringIds ); } return $where; }
[ "private", "function", "addWhereSecurityIdentitiesForSharing", "(", "GetFilterEvent", "$", "event", ",", "ClassMetadata", "$", "meta", ")", "{", "$", "where", "=", "''", ";", "$", "mapSids", "=", "(", "array", ")", "$", "event", "->", "getRealParameter", "(", ...
Add the where condition of security identities. @param GetFilterEvent $event The event @param ClassMetadata $meta The class metadata of sharing entity @return string
[ "Add", "the", "where", "condition", "of", "security", "identities", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Filter/Listener/PrivateSharingSubscriber.php#L99-L118
train
fxpio/fxp-security
Doctrine/ORM/Filter/Listener/PrivateSharingSubscriber.php
PrivateSharingSubscriber.buildOwnerFilter
private function buildOwnerFilter(GetFilterEvent $event, $filter) { $class = $event->getTargetEntity()->getName(); $interfaces = class_implements($class); if (\in_array(OwnerableInterface::class, $interfaces, true)) { $filter = $this->buildRequiredOwnerFilter($event, $filter); } elseif (\in_array(OwnerableOptionalInterface::class, $interfaces, true)) { $filter = $this->buildOptionalOwnerFilter($event, $filter); } return $filter; }
php
private function buildOwnerFilter(GetFilterEvent $event, $filter) { $class = $event->getTargetEntity()->getName(); $interfaces = class_implements($class); if (\in_array(OwnerableInterface::class, $interfaces, true)) { $filter = $this->buildRequiredOwnerFilter($event, $filter); } elseif (\in_array(OwnerableOptionalInterface::class, $interfaces, true)) { $filter = $this->buildOptionalOwnerFilter($event, $filter); } return $filter; }
[ "private", "function", "buildOwnerFilter", "(", "GetFilterEvent", "$", "event", ",", "$", "filter", ")", "{", "$", "class", "=", "$", "event", "->", "getTargetEntity", "(", ")", "->", "getName", "(", ")", ";", "$", "interfaces", "=", "class_implements", "(...
Build the query filter with owner. @param GetFilterEvent $event The event @param string $filter The previous filter @return string
[ "Build", "the", "query", "filter", "with", "owner", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Filter/Listener/PrivateSharingSubscriber.php#L128-L140
train
fxpio/fxp-security
Doctrine/ORM/Filter/Listener/PrivateSharingSubscriber.php
PrivateSharingSubscriber.buildRequiredOwnerFilter
private function buildRequiredOwnerFilter(GetFilterEvent $event, $filter) { $connection = $event->getConnection(); $platform = $connection->getDatabasePlatform(); $targetEntity = $event->getTargetEntity(); $targetTableAlias = $event->getTargetTableAlias(); $identifier = DoctrineUtils::castIdentifier($targetEntity, $connection); $ownerId = $event->getRealParameter('user_id'); $ownerColumn = $this->getAssociationColumnName($targetEntity, 'owner'); $ownerFilter = null !== $ownerId ? "{$targetTableAlias}.{$ownerColumn}{$identifier} = {$connection->quote($ownerId)}" : "{$platform->getIsNullExpression($targetTableAlias.'.'.$ownerColumn)}"; return <<<SELECTCLAUSE {$ownerFilter} OR ({$filter}) SELECTCLAUSE; }
php
private function buildRequiredOwnerFilter(GetFilterEvent $event, $filter) { $connection = $event->getConnection(); $platform = $connection->getDatabasePlatform(); $targetEntity = $event->getTargetEntity(); $targetTableAlias = $event->getTargetTableAlias(); $identifier = DoctrineUtils::castIdentifier($targetEntity, $connection); $ownerId = $event->getRealParameter('user_id'); $ownerColumn = $this->getAssociationColumnName($targetEntity, 'owner'); $ownerFilter = null !== $ownerId ? "{$targetTableAlias}.{$ownerColumn}{$identifier} = {$connection->quote($ownerId)}" : "{$platform->getIsNullExpression($targetTableAlias.'.'.$ownerColumn)}"; return <<<SELECTCLAUSE {$ownerFilter} OR ({$filter}) SELECTCLAUSE; }
[ "private", "function", "buildRequiredOwnerFilter", "(", "GetFilterEvent", "$", "event", ",", "$", "filter", ")", "{", "$", "connection", "=", "$", "event", "->", "getConnection", "(", ")", ";", "$", "platform", "=", "$", "connection", "->", "getDatabasePlatfor...
Build the query filter with required owner. @param GetFilterEvent $event The event @param string $filter The previous filter @return string
[ "Build", "the", "query", "filter", "with", "required", "owner", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Filter/Listener/PrivateSharingSubscriber.php#L150-L169
train
fxpio/fxp-security
Doctrine/ORM/Filter/Listener/PrivateSharingSubscriber.php
PrivateSharingSubscriber.getAssociationColumnName
private function getAssociationColumnName(ClassMetadata $meta, $fieldName) { $mapping = $meta->getAssociationMapping($fieldName); return current($mapping['joinColumnFieldNames']); }
php
private function getAssociationColumnName(ClassMetadata $meta, $fieldName) { $mapping = $meta->getAssociationMapping($fieldName); return current($mapping['joinColumnFieldNames']); }
[ "private", "function", "getAssociationColumnName", "(", "ClassMetadata", "$", "meta", ",", "$", "fieldName", ")", "{", "$", "mapping", "=", "$", "meta", "->", "getAssociationMapping", "(", "$", "fieldName", ")", ";", "return", "current", "(", "$", "mapping", ...
Get the column name of association field name. @param ClassMetadata $meta The class metadata @param string $fieldName The field name @return string
[ "Get", "the", "column", "name", "of", "association", "field", "name", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Filter/Listener/PrivateSharingSubscriber.php#L207-L212
train
fxpio/fxp-security
Doctrine/ORM/Listener/RoleHierarchyListener.php
RoleHierarchyListener.getAllCollections
protected function getAllCollections(UnitOfWork $uow) { return array_merge( $uow->getScheduledEntityInsertions(), $uow->getScheduledEntityUpdates(), $uow->getScheduledEntityDeletions(), $uow->getScheduledCollectionUpdates(), $uow->getScheduledCollectionDeletions() ); }
php
protected function getAllCollections(UnitOfWork $uow) { return array_merge( $uow->getScheduledEntityInsertions(), $uow->getScheduledEntityUpdates(), $uow->getScheduledEntityDeletions(), $uow->getScheduledCollectionUpdates(), $uow->getScheduledCollectionDeletions() ); }
[ "protected", "function", "getAllCollections", "(", "UnitOfWork", "$", "uow", ")", "{", "return", "array_merge", "(", "$", "uow", "->", "getScheduledEntityInsertions", "(", ")", ",", "$", "uow", "->", "getScheduledEntityUpdates", "(", ")", ",", "$", "uow", "->"...
Get the merged collection of all scheduled collections. @param UnitOfWork $uow The unit of work @return array
[ "Get", "the", "merged", "collection", "of", "all", "scheduled", "collections", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Listener/RoleHierarchyListener.php#L129-L138
train
fxpio/fxp-security
Doctrine/ORM/Listener/RoleHierarchyListener.php
RoleHierarchyListener.invalidateCache
protected function invalidateCache(UnitOfWork $uow, $object) { if ($this->isCacheableObject($object)) { return $this->invalidateCacheableObject($uow, $object); } if ($object instanceof PersistentCollection && $this->isRequireAssociation($object->getMapping())) { return $this->getPrefix($object->getOwner()); } return false; }
php
protected function invalidateCache(UnitOfWork $uow, $object) { if ($this->isCacheableObject($object)) { return $this->invalidateCacheableObject($uow, $object); } if ($object instanceof PersistentCollection && $this->isRequireAssociation($object->getMapping())) { return $this->getPrefix($object->getOwner()); } return false; }
[ "protected", "function", "invalidateCache", "(", "UnitOfWork", "$", "uow", ",", "$", "object", ")", "{", "if", "(", "$", "this", "->", "isCacheableObject", "(", "$", "object", ")", ")", "{", "return", "$", "this", "->", "invalidateCacheableObject", "(", "$...
Check if the role hierarchy cache must be invalidated. @param UnitOfWork $uow The unit of work @param object $object The object @return false|string
[ "Check", "if", "the", "role", "hierarchy", "cache", "must", "be", "invalidated", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Listener/RoleHierarchyListener.php#L148-L159
train
fxpio/fxp-security
Doctrine/ORM/Listener/RoleHierarchyListener.php
RoleHierarchyListener.isCacheableObject
protected function isCacheableObject($object) { return $object instanceof UserInterface || $object instanceof RoleHierarchicalInterface || $object instanceof GroupInterface || $object instanceof OrganizationUserInterface; }
php
protected function isCacheableObject($object) { return $object instanceof UserInterface || $object instanceof RoleHierarchicalInterface || $object instanceof GroupInterface || $object instanceof OrganizationUserInterface; }
[ "protected", "function", "isCacheableObject", "(", "$", "object", ")", "{", "return", "$", "object", "instanceof", "UserInterface", "||", "$", "object", "instanceof", "RoleHierarchicalInterface", "||", "$", "object", "instanceof", "GroupInterface", "||", "$", "objec...
Check if the object is cacheable or not. @param object $object The object @return bool
[ "Check", "if", "the", "object", "is", "cacheable", "or", "not", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Listener/RoleHierarchyListener.php#L168-L171
train
fxpio/fxp-security
Doctrine/ORM/Listener/RoleHierarchyListener.php
RoleHierarchyListener.isRequireAssociation
protected function isRequireAssociation(array $mapping) { $ref = new \ReflectionClass($mapping['sourceEntity']); if (\in_array(RoleHierarchicalInterface::class, $ref->getInterfaceNames(), true) && 'children' === $mapping['fieldName']) { return true; } if (\in_array(GroupableInterface::class, $ref->getInterfaceNames(), true) && 'groups' === $mapping['fieldName']) { return true; } return false; }
php
protected function isRequireAssociation(array $mapping) { $ref = new \ReflectionClass($mapping['sourceEntity']); if (\in_array(RoleHierarchicalInterface::class, $ref->getInterfaceNames(), true) && 'children' === $mapping['fieldName']) { return true; } if (\in_array(GroupableInterface::class, $ref->getInterfaceNames(), true) && 'groups' === $mapping['fieldName']) { return true; } return false; }
[ "protected", "function", "isRequireAssociation", "(", "array", "$", "mapping", ")", "{", "$", "ref", "=", "new", "\\", "ReflectionClass", "(", "$", "mapping", "[", "'sourceEntity'", "]", ")", ";", "if", "(", "\\", "in_array", "(", "RoleHierarchicalInterface", ...
Check if the association must be flush the cache. @param array $mapping The mapping @return bool
[ "Check", "if", "the", "association", "must", "be", "flush", "the", "cache", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Listener/RoleHierarchyListener.php#L180-L195
train
fxpio/fxp-security
Doctrine/ORM/Listener/RoleHierarchyListener.php
RoleHierarchyListener.getPrefix
protected function getPrefix($object) { $id = 'user'; if (method_exists($object, 'getOrganization')) { $org = $object->getOrganization(); if ($org instanceof OrganizationInterface) { $id = (string) $org->getId(); } } return $id.'__'; }
php
protected function getPrefix($object) { $id = 'user'; if (method_exists($object, 'getOrganization')) { $org = $object->getOrganization(); if ($org instanceof OrganizationInterface) { $id = (string) $org->getId(); } } return $id.'__'; }
[ "protected", "function", "getPrefix", "(", "$", "object", ")", "{", "$", "id", "=", "'user'", ";", "if", "(", "method_exists", "(", "$", "object", ",", "'getOrganization'", ")", ")", "{", "$", "org", "=", "$", "object", "->", "getOrganization", "(", ")...
Get the cache prefix key. @param object $object @return string
[ "Get", "the", "cache", "prefix", "key", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Listener/RoleHierarchyListener.php#L204-L217
train
fxpio/fxp-security
Doctrine/ORM/Listener/RoleHierarchyListener.php
RoleHierarchyListener.invalidateCacheableObject
private function invalidateCacheableObject(UnitOfWork $uow, $object) { $fields = array_keys($uow->getEntityChangeSet($object)); $checkFields = ['roles']; if ($object instanceof RoleHierarchicalInterface || $object instanceof OrganizationUserInterface) { $checkFields = array_merge($checkFields, ['name']); } foreach ($fields as $field) { if (\in_array($field, $checkFields, true)) { return $this->getPrefix($object); } } return false; }
php
private function invalidateCacheableObject(UnitOfWork $uow, $object) { $fields = array_keys($uow->getEntityChangeSet($object)); $checkFields = ['roles']; if ($object instanceof RoleHierarchicalInterface || $object instanceof OrganizationUserInterface) { $checkFields = array_merge($checkFields, ['name']); } foreach ($fields as $field) { if (\in_array($field, $checkFields, true)) { return $this->getPrefix($object); } } return false; }
[ "private", "function", "invalidateCacheableObject", "(", "UnitOfWork", "$", "uow", ",", "$", "object", ")", "{", "$", "fields", "=", "array_keys", "(", "$", "uow", "->", "getEntityChangeSet", "(", "$", "object", ")", ")", ";", "$", "checkFields", "=", "[",...
Check if the object cache must be invalidated. @param UnitOfWork $uow The unit of work @param object $object The object @return bool|string
[ "Check", "if", "the", "object", "cache", "must", "be", "invalidated", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Listener/RoleHierarchyListener.php#L227-L243
train
fxpio/fxp-security
Identity/OrganizationSecurityIdentity.php
OrganizationSecurityIdentity.fromToken
public static function fromToken( TokenInterface $token, OrganizationalContextInterface $context = null, RoleHierarchyInterface $roleHierarchy = null ) { $user = $token->getUser(); if (!$user instanceof UserInterface) { return []; } return null !== $context ? static::getSecurityIdentityForCurrentOrganization($context, $roleHierarchy) : static::getSecurityIdentityForAllOrganizations($user, $roleHierarchy); }
php
public static function fromToken( TokenInterface $token, OrganizationalContextInterface $context = null, RoleHierarchyInterface $roleHierarchy = null ) { $user = $token->getUser(); if (!$user instanceof UserInterface) { return []; } return null !== $context ? static::getSecurityIdentityForCurrentOrganization($context, $roleHierarchy) : static::getSecurityIdentityForAllOrganizations($user, $roleHierarchy); }
[ "public", "static", "function", "fromToken", "(", "TokenInterface", "$", "token", ",", "OrganizationalContextInterface", "$", "context", "=", "null", ",", "RoleHierarchyInterface", "$", "roleHierarchy", "=", "null", ")", "{", "$", "user", "=", "$", "token", "->"...
Creates a organization security identity from a TokenInterface. @param TokenInterface $token The token @param null|OrganizationalContextInterface $context The organizational context @param null|RoleHierarchyInterface $roleHierarchy The role hierarchy @return SecurityIdentityInterface[]
[ "Creates", "a", "organization", "security", "identity", "from", "a", "TokenInterface", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Identity/OrganizationSecurityIdentity.php#L53-L67
train
fxpio/fxp-security
Identity/OrganizationSecurityIdentity.php
OrganizationSecurityIdentity.getSecurityIdentityForAllOrganizations
protected static function getSecurityIdentityForAllOrganizations(UserInterface $user, $roleHierarchy = null) { $sids = []; if ($user instanceof UserOrganizationUsersInterface) { foreach ($user->getUserOrganizations() as $userOrg) { $sids[] = self::fromAccount($userOrg->getOrganization()); $sids = array_merge($sids, static::getOrganizationGroups($userOrg)); $roles = static::getOrganizationUserRoles($userOrg, $roleHierarchy); foreach ($roles as $role) { $sids[] = RoleSecurityIdentity::fromAccount($role); } } } return $sids; }
php
protected static function getSecurityIdentityForAllOrganizations(UserInterface $user, $roleHierarchy = null) { $sids = []; if ($user instanceof UserOrganizationUsersInterface) { foreach ($user->getUserOrganizations() as $userOrg) { $sids[] = self::fromAccount($userOrg->getOrganization()); $sids = array_merge($sids, static::getOrganizationGroups($userOrg)); $roles = static::getOrganizationUserRoles($userOrg, $roleHierarchy); foreach ($roles as $role) { $sids[] = RoleSecurityIdentity::fromAccount($role); } } } return $sids; }
[ "protected", "static", "function", "getSecurityIdentityForAllOrganizations", "(", "UserInterface", "$", "user", ",", "$", "roleHierarchy", "=", "null", ")", "{", "$", "sids", "=", "[", "]", ";", "if", "(", "$", "user", "instanceof", "UserOrganizationUsersInterface...
Get the security identities for all organizations of user. @param UserInterface $user The user @param null|RoleHierarchyInterface $roleHierarchy The role hierarchy @return SecurityIdentityInterface[]
[ "Get", "the", "security", "identities", "for", "all", "organizations", "of", "user", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Identity/OrganizationSecurityIdentity.php#L77-L94
train
fxpio/fxp-security
Identity/OrganizationSecurityIdentity.php
OrganizationSecurityIdentity.getSecurityIdentityForCurrentOrganization
protected static function getSecurityIdentityForCurrentOrganization( OrganizationalContextInterface $context, $roleHierarchy = null ) { $sids = []; $org = $context->getCurrentOrganization(); $userOrg = $context->getCurrentOrganizationUser(); $orgRoles = []; if ($org) { $sids[] = self::fromAccount($org); } if (null !== $userOrg) { $sids = array_merge($sids, static::getOrganizationGroups($userOrg)); $orgRoles = static::getOrganizationUserRoles($userOrg, $roleHierarchy); } elseif ($org && $org->isUserOrganization()) { $orgRoles = static::getOrganizationRoles($org, $roleHierarchy); } foreach ($orgRoles as $role) { $sids[] = RoleSecurityIdentity::fromAccount($role); } return $sids; }
php
protected static function getSecurityIdentityForCurrentOrganization( OrganizationalContextInterface $context, $roleHierarchy = null ) { $sids = []; $org = $context->getCurrentOrganization(); $userOrg = $context->getCurrentOrganizationUser(); $orgRoles = []; if ($org) { $sids[] = self::fromAccount($org); } if (null !== $userOrg) { $sids = array_merge($sids, static::getOrganizationGroups($userOrg)); $orgRoles = static::getOrganizationUserRoles($userOrg, $roleHierarchy); } elseif ($org && $org->isUserOrganization()) { $orgRoles = static::getOrganizationRoles($org, $roleHierarchy); } foreach ($orgRoles as $role) { $sids[] = RoleSecurityIdentity::fromAccount($role); } return $sids; }
[ "protected", "static", "function", "getSecurityIdentityForCurrentOrganization", "(", "OrganizationalContextInterface", "$", "context", ",", "$", "roleHierarchy", "=", "null", ")", "{", "$", "sids", "=", "[", "]", ";", "$", "org", "=", "$", "context", "->", "getC...
Get the security identities for the current organization of user. @param OrganizationalContextInterface $context The organizational context @param null|RoleHierarchyInterface $roleHierarchy The role hierarchy @return SecurityIdentityInterface[]
[ "Get", "the", "security", "identities", "for", "the", "current", "organization", "of", "user", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Identity/OrganizationSecurityIdentity.php#L104-L129
train
fxpio/fxp-security
Identity/OrganizationSecurityIdentity.php
OrganizationSecurityIdentity.getOrganizationGroups
protected static function getOrganizationGroups(OrganizationUserInterface $user) { $sids = []; $orgName = $user->getOrganization()->getName(); if ($user instanceof GroupableInterface) { foreach ($user->getGroups() as $group) { if ($group instanceof GroupInterface) { $sids[] = new GroupSecurityIdentity(ClassUtils::getClass($group), $group->getName().'__'.$orgName); } } } return $sids; }
php
protected static function getOrganizationGroups(OrganizationUserInterface $user) { $sids = []; $orgName = $user->getOrganization()->getName(); if ($user instanceof GroupableInterface) { foreach ($user->getGroups() as $group) { if ($group instanceof GroupInterface) { $sids[] = new GroupSecurityIdentity(ClassUtils::getClass($group), $group->getName().'__'.$orgName); } } } return $sids; }
[ "protected", "static", "function", "getOrganizationGroups", "(", "OrganizationUserInterface", "$", "user", ")", "{", "$", "sids", "=", "[", "]", ";", "$", "orgName", "=", "$", "user", "->", "getOrganization", "(", ")", "->", "getName", "(", ")", ";", "if",...
Get the security identities for organization groups of user. @param OrganizationUserInterface $user The organization user @return GroupSecurityIdentity[]
[ "Get", "the", "security", "identities", "for", "organization", "groups", "of", "user", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Identity/OrganizationSecurityIdentity.php#L138-L152
train
fxpio/fxp-security
Identity/OrganizationSecurityIdentity.php
OrganizationSecurityIdentity.getOrganizationRoles
protected static function getOrganizationRoles(OrganizationInterface $organization, $roleHierarchy = null) { $roles = []; if ($organization instanceof RoleableInterface && $organization instanceof OrganizationInterface) { $roles = self::buildOrganizationRoles([], $organization); if ($roleHierarchy instanceof RoleHierarchyInterface) { $roles = RoleUtil::formatNames($roleHierarchy->getReachableRoles($roles)); } } return $roles; }
php
protected static function getOrganizationRoles(OrganizationInterface $organization, $roleHierarchy = null) { $roles = []; if ($organization instanceof RoleableInterface && $organization instanceof OrganizationInterface) { $roles = self::buildOrganizationRoles([], $organization); if ($roleHierarchy instanceof RoleHierarchyInterface) { $roles = RoleUtil::formatNames($roleHierarchy->getReachableRoles($roles)); } } return $roles; }
[ "protected", "static", "function", "getOrganizationRoles", "(", "OrganizationInterface", "$", "organization", ",", "$", "roleHierarchy", "=", "null", ")", "{", "$", "roles", "=", "[", "]", ";", "if", "(", "$", "organization", "instanceof", "RoleableInterface", "...
Get the organization roles. @param OrganizationInterface $organization The organization @param null|RoleHierarchyInterface $roleHierarchy The role hierarchy @return string[]
[ "Get", "the", "organization", "roles", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Identity/OrganizationSecurityIdentity.php#L162-L175
train
fxpio/fxp-security
Identity/OrganizationSecurityIdentity.php
OrganizationSecurityIdentity.getOrganizationUserRoles
protected static function getOrganizationUserRoles(OrganizationUserInterface $user, $roleHierarchy = null) { $roles = []; if ($user instanceof RoleableInterface && $user instanceof OrganizationUserInterface) { $org = $user->getOrganization(); $roles = self::buildOrganizationUserRoles($roles, $user, $org->getName()); $roles = self::buildOrganizationRoles($roles, $org); if ($roleHierarchy instanceof RoleHierarchyInterface) { $roles = RoleUtil::formatNames($roleHierarchy->getReachableRoles($roles)); } } return $roles; }
php
protected static function getOrganizationUserRoles(OrganizationUserInterface $user, $roleHierarchy = null) { $roles = []; if ($user instanceof RoleableInterface && $user instanceof OrganizationUserInterface) { $org = $user->getOrganization(); $roles = self::buildOrganizationUserRoles($roles, $user, $org->getName()); $roles = self::buildOrganizationRoles($roles, $org); if ($roleHierarchy instanceof RoleHierarchyInterface) { $roles = RoleUtil::formatNames($roleHierarchy->getReachableRoles($roles)); } } return $roles; }
[ "protected", "static", "function", "getOrganizationUserRoles", "(", "OrganizationUserInterface", "$", "user", ",", "$", "roleHierarchy", "=", "null", ")", "{", "$", "roles", "=", "[", "]", ";", "if", "(", "$", "user", "instanceof", "RoleableInterface", "&&", "...
Get the organization roles of user. @param OrganizationUserInterface $user The organization user @param null|RoleHierarchyInterface $roleHierarchy The role hierarchy @return string[]
[ "Get", "the", "organization", "roles", "of", "user", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Identity/OrganizationSecurityIdentity.php#L185-L200
train
fxpio/fxp-security
Identity/OrganizationSecurityIdentity.php
OrganizationSecurityIdentity.buildOrganizationUserRoles
private static function buildOrganizationUserRoles(array $roles, RoleableInterface $user, $orgName) { foreach ($user->getRoles() as $role) { $roles[] = RoleUtil::formatName($role).'__'.$orgName; } return $roles; }
php
private static function buildOrganizationUserRoles(array $roles, RoleableInterface $user, $orgName) { foreach ($user->getRoles() as $role) { $roles[] = RoleUtil::formatName($role).'__'.$orgName; } return $roles; }
[ "private", "static", "function", "buildOrganizationUserRoles", "(", "array", "$", "roles", ",", "RoleableInterface", "$", "user", ",", "$", "orgName", ")", "{", "foreach", "(", "$", "user", "->", "getRoles", "(", ")", "as", "$", "role", ")", "{", "$", "r...
Build the organization user roles. @param string[] $roles The roles @param RoleableInterface $user The organization user @param string $orgName The organization name @return string[]
[ "Build", "the", "organization", "user", "roles", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Identity/OrganizationSecurityIdentity.php#L211-L218
train
fxpio/fxp-security
Identity/OrganizationSecurityIdentity.php
OrganizationSecurityIdentity.buildOrganizationRoles
private static function buildOrganizationRoles(array $roles, OrganizationInterface $org) { $orgName = $org->getName(); if ($org instanceof RoleableInterface) { $existingRoles = []; foreach ($roles as $role) { $existingRoles[] = $role; } foreach ($org->getRoles() as $orgRole) { $roleName = RoleUtil::formatName($orgRole); if (!\in_array($roleName, $existingRoles, true)) { $roles[] = $roleName.'__'.$orgName; $existingRoles[] = $roleName; } } } return $roles; }
php
private static function buildOrganizationRoles(array $roles, OrganizationInterface $org) { $orgName = $org->getName(); if ($org instanceof RoleableInterface) { $existingRoles = []; foreach ($roles as $role) { $existingRoles[] = $role; } foreach ($org->getRoles() as $orgRole) { $roleName = RoleUtil::formatName($orgRole); if (!\in_array($roleName, $existingRoles, true)) { $roles[] = $roleName.'__'.$orgName; $existingRoles[] = $roleName; } } } return $roles; }
[ "private", "static", "function", "buildOrganizationRoles", "(", "array", "$", "roles", ",", "OrganizationInterface", "$", "org", ")", "{", "$", "orgName", "=", "$", "org", "->", "getName", "(", ")", ";", "if", "(", "$", "org", "instanceof", "RoleableInterfac...
Build the user organization roles. @param string[] $roles The roles @param OrganizationInterface $org The organization of user @return string[]
[ "Build", "the", "user", "organization", "roles", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Identity/OrganizationSecurityIdentity.php#L228-L250
train
fxpio/fxp-security
Identity/CacheSecurityIdentityManager.php
CacheSecurityIdentityManager.buildId
protected function buildId(TokenInterface $token) { $id = spl_object_hash($token); $listeners = $this->getCacheIdentityListeners(); foreach ($listeners as $listener) { $id .= '_'.$listener->getCacheId(); } return $id; }
php
protected function buildId(TokenInterface $token) { $id = spl_object_hash($token); $listeners = $this->getCacheIdentityListeners(); foreach ($listeners as $listener) { $id .= '_'.$listener->getCacheId(); } return $id; }
[ "protected", "function", "buildId", "(", "TokenInterface", "$", "token", ")", "{", "$", "id", "=", "spl_object_hash", "(", "$", "token", ")", ";", "$", "listeners", "=", "$", "this", "->", "getCacheIdentityListeners", "(", ")", ";", "foreach", "(", "$", ...
Build the unique identifier for execution cache. @param TokenInterface $token The token @return string
[ "Build", "the", "unique", "identifier", "for", "execution", "cache", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Identity/CacheSecurityIdentityManager.php#L67-L77
train
fxpio/fxp-security
Identity/CacheSecurityIdentityManager.php
CacheSecurityIdentityManager.getCacheIdentityListeners
protected function getCacheIdentityListeners() { if (null === $this->cacheIdentityListeners) { $this->cacheIdentityListeners = []; $listeners = $this->dispatcher->getListeners(SecurityIdentityEvents::RETRIEVAL_ADD); foreach ($listeners as $listener) { $listener = \is_array($listener) && \count($listener) > 1 ? $listener[0] : $listener; if ($listener instanceof CacheSecurityIdentityListenerInterface) { $this->cacheIdentityListeners[] = $listener; } } } return $this->cacheIdentityListeners; }
php
protected function getCacheIdentityListeners() { if (null === $this->cacheIdentityListeners) { $this->cacheIdentityListeners = []; $listeners = $this->dispatcher->getListeners(SecurityIdentityEvents::RETRIEVAL_ADD); foreach ($listeners as $listener) { $listener = \is_array($listener) && \count($listener) > 1 ? $listener[0] : $listener; if ($listener instanceof CacheSecurityIdentityListenerInterface) { $this->cacheIdentityListeners[] = $listener; } } } return $this->cacheIdentityListeners; }
[ "protected", "function", "getCacheIdentityListeners", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "cacheIdentityListeners", ")", "{", "$", "this", "->", "cacheIdentityListeners", "=", "[", "]", ";", "$", "listeners", "=", "$", "this", "->", ...
Get the cache security identity listeners. @return CacheSecurityIdentityListenerInterface[]
[ "Get", "the", "cache", "security", "identity", "listeners", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Identity/CacheSecurityIdentityManager.php#L84-L100
train
fxpio/fxp-security
Doctrine/ORM/Filter/Listener/SharingFilterSubscriber.php
SharingFilterSubscriber.onSharingManagerChange
public function onSharingManagerChange(): void { if (null !== ($filter = $this->getFilter())) { $filter->setParameter('sharing_manager_enabled', $this->sharingManager->isEnabled(), 'boolean'); } }
php
public function onSharingManagerChange(): void { if (null !== ($filter = $this->getFilter())) { $filter->setParameter('sharing_manager_enabled', $this->sharingManager->isEnabled(), 'boolean'); } }
[ "public", "function", "onSharingManagerChange", "(", ")", ":", "void", "{", "if", "(", "null", "!==", "(", "$", "filter", "=", "$", "this", "->", "getFilter", "(", ")", ")", ")", "{", "$", "filter", "->", "setParameter", "(", "'sharing_manager_enabled'", ...
Action when the sharing manager is enabled or disabled.
[ "Action", "when", "the", "sharing", "manager", "is", "enabled", "or", "disabled", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Filter/Listener/SharingFilterSubscriber.php#L109-L114
train
fxpio/fxp-security
Doctrine/ORM/Filter/Listener/SharingFilterSubscriber.php
SharingFilterSubscriber.buildSecurityIdentities
private function buildSecurityIdentities() { $tSids = $this->sidManager->getSecurityIdentities($this->tokenStorage->getToken()); $sids = []; foreach ($tSids as $sid) { if (IdentityUtils::isValid($sid)) { $sids[] = $sid; } } return $sids; }
php
private function buildSecurityIdentities() { $tSids = $this->sidManager->getSecurityIdentities($this->tokenStorage->getToken()); $sids = []; foreach ($tSids as $sid) { if (IdentityUtils::isValid($sid)) { $sids[] = $sid; } } return $sids; }
[ "private", "function", "buildSecurityIdentities", "(", ")", "{", "$", "tSids", "=", "$", "this", "->", "sidManager", "->", "getSecurityIdentities", "(", "$", "this", "->", "tokenStorage", "->", "getToken", "(", ")", ")", ";", "$", "sids", "=", "[", "]", ...
Build the security identities. @return SecurityIdentityInterface[]
[ "Build", "the", "security", "identities", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Filter/Listener/SharingFilterSubscriber.php#L146-L158
train
fxpio/fxp-security
Doctrine/ORM/Filter/Listener/SharingFilterSubscriber.php
SharingFilterSubscriber.getMapSecurityIdentities
private function getMapSecurityIdentities(array $sids) { $connection = $this->entityManager->getConnection(); $mapSids = []; foreach ($sids as $sid) { $type = $this->sharingManager->getIdentityConfig($sid->getType())->getType(); $mapSids[$type][] = $connection->quote($sid->getIdentifier()); } foreach ($mapSids as $type => $ids) { $mapSids[$type] = implode(', ', $ids); } return $mapSids; }
php
private function getMapSecurityIdentities(array $sids) { $connection = $this->entityManager->getConnection(); $mapSids = []; foreach ($sids as $sid) { $type = $this->sharingManager->getIdentityConfig($sid->getType())->getType(); $mapSids[$type][] = $connection->quote($sid->getIdentifier()); } foreach ($mapSids as $type => $ids) { $mapSids[$type] = implode(', ', $ids); } return $mapSids; }
[ "private", "function", "getMapSecurityIdentities", "(", "array", "$", "sids", ")", "{", "$", "connection", "=", "$", "this", "->", "entityManager", "->", "getConnection", "(", ")", ";", "$", "mapSids", "=", "[", "]", ";", "foreach", "(", "$", "sids", "as...
Get the map of the security identities. @param SecurityIdentityInterface[] $sids The security identities @return array
[ "Get", "the", "map", "of", "the", "security", "identities", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Filter/Listener/SharingFilterSubscriber.php#L167-L182
train
fxpio/fxp-security
Doctrine/ORM/Filter/Listener/SharingFilterSubscriber.php
SharingFilterSubscriber.getUserId
private function getUserId() { $id = null; if (null !== $this->tokenStorage && null !== $this->tokenStorage->getToken()) { $user = $this->tokenStorage->getToken()->getUser(); if ($user instanceof UserInterface) { $id = $user->getId(); } } return $id; }
php
private function getUserId() { $id = null; if (null !== $this->tokenStorage && null !== $this->tokenStorage->getToken()) { $user = $this->tokenStorage->getToken()->getUser(); if ($user instanceof UserInterface) { $id = $user->getId(); } } return $id; }
[ "private", "function", "getUserId", "(", ")", "{", "$", "id", "=", "null", ";", "if", "(", "null", "!==", "$", "this", "->", "tokenStorage", "&&", "null", "!==", "$", "this", "->", "tokenStorage", "->", "getToken", "(", ")", ")", "{", "$", "user", ...
Get the current user id. @return null|int|string
[ "Get", "the", "current", "user", "id", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Doctrine/ORM/Filter/Listener/SharingFilterSubscriber.php#L189-L202
train
fxpio/fxp-security
Role/RoleUtil.php
RoleUtil.formatRoles
public static function formatRoles(array $roles, $force = false): array { if ($force || version_compare(Kernel::VERSION, '4.3', '<')) { $roles = array_map(static function ($role) { return !$role instanceof Role ? new Role((string) $role) : $role; }, $roles); } return $roles; }
php
public static function formatRoles(array $roles, $force = false): array { if ($force || version_compare(Kernel::VERSION, '4.3', '<')) { $roles = array_map(static function ($role) { return !$role instanceof Role ? new Role((string) $role) : $role; }, $roles); } return $roles; }
[ "public", "static", "function", "formatRoles", "(", "array", "$", "roles", ",", "$", "force", "=", "false", ")", ":", "array", "{", "if", "(", "$", "force", "||", "version_compare", "(", "Kernel", "::", "VERSION", ",", "'4.3'", ",", "'<'", ")", ")", ...
Format the roles. @param Role[]|string[] $roles The roles @param bool $force Force to convert the role name @return Role[]|string[]
[ "Format", "the", "roles", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Role/RoleUtil.php#L33-L42
train
fxpio/fxp-security
Role/RoleUtil.php
RoleUtil.formatRole
public static function formatRole($role, $force = false) { if ($force || version_compare(Kernel::VERSION, '4.3', '<')) { $role = !$role instanceof Role ? new Role((string) $role) : $role; } return $role; }
php
public static function formatRole($role, $force = false) { if ($force || version_compare(Kernel::VERSION, '4.3', '<')) { $role = !$role instanceof Role ? new Role((string) $role) : $role; } return $role; }
[ "public", "static", "function", "formatRole", "(", "$", "role", ",", "$", "force", "=", "false", ")", "{", "if", "(", "$", "force", "||", "version_compare", "(", "Kernel", "::", "VERSION", ",", "'4.3'", ",", "'<'", ")", ")", "{", "$", "role", "=", ...
Format the role. @param Role|string $role The role @param bool $force Force to convert the role name @return Role|string
[ "Format", "the", "role", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Role/RoleUtil.php#L52-L59
train
fxpio/fxp-security
Role/RoleUtil.php
RoleUtil.formatName
public static function formatName($role): string { if ($role instanceof RoleInterface) { return $role->getName(); } return $role instanceof Role ? $role->getRole() : (string) $role; }
php
public static function formatName($role): string { if ($role instanceof RoleInterface) { return $role->getName(); } return $role instanceof Role ? $role->getRole() : (string) $role; }
[ "public", "static", "function", "formatName", "(", "$", "role", ")", ":", "string", "{", "if", "(", "$", "role", "instanceof", "RoleInterface", ")", "{", "return", "$", "role", "->", "getName", "(", ")", ";", "}", "return", "$", "role", "instanceof", "...
Format the role name. @param Role|RoleInterface|string $role The role @return string
[ "Format", "the", "role", "name", "." ]
f04be8baf1ea16aa91074721eb82a7689e248e96
https://github.com/fxpio/fxp-security/blob/f04be8baf1ea16aa91074721eb82a7689e248e96/Role/RoleUtil.php#L82-L89
train
wikimedia/ToolforgeBundle
Twig/Extension.php
Extension.getFunctions
public function getFunctions(): array { $options = ['is_safe' => ['html']]; return [ new Twig_Function('logged_in_user', [$this, 'getLoggedInUser'], $options), new Twig_Function('msg', [$this, 'msg'], $options), new Twig_Function('bdi', [$this, 'bdi'], $options), new Twig_Function('msg_exists', [$this, 'msgExists'], $options), new Twig_Function('msg_if_exists', [$this, 'msgIfExists'], $options), new Twig_Function('lang', [$this, 'getLang'], $options), new Twig_Function('lang_name', [$this, 'getLangName'], $options), new Twig_Function('all_langs', [$this, 'getAllLangs']), new Twig_Function('is_rtl', [$this, 'isRtl']), new Twig_Function('git_branch', [$this, 'gitBranch']), new Twig_Function('git_hash', [$this, 'gitHash']), new Twig_Function('git_hash_short', [$this, 'gitHashShort']), ]; }
php
public function getFunctions(): array { $options = ['is_safe' => ['html']]; return [ new Twig_Function('logged_in_user', [$this, 'getLoggedInUser'], $options), new Twig_Function('msg', [$this, 'msg'], $options), new Twig_Function('bdi', [$this, 'bdi'], $options), new Twig_Function('msg_exists', [$this, 'msgExists'], $options), new Twig_Function('msg_if_exists', [$this, 'msgIfExists'], $options), new Twig_Function('lang', [$this, 'getLang'], $options), new Twig_Function('lang_name', [$this, 'getLangName'], $options), new Twig_Function('all_langs', [$this, 'getAllLangs']), new Twig_Function('is_rtl', [$this, 'isRtl']), new Twig_Function('git_branch', [$this, 'gitBranch']), new Twig_Function('git_hash', [$this, 'gitHash']), new Twig_Function('git_hash_short', [$this, 'gitHashShort']), ]; }
[ "public", "function", "getFunctions", "(", ")", ":", "array", "{", "$", "options", "=", "[", "'is_safe'", "=>", "[", "'html'", "]", "]", ";", "return", "[", "new", "Twig_Function", "(", "'logged_in_user'", ",", "[", "$", "this", ",", "'getLoggedInUser'", ...
Get all functions that this extension provides. @return Twig_Function[]
[ "Get", "all", "functions", "that", "this", "extension", "provides", "." ]
adab343963a27e623fa481949d18baa060be526a
https://github.com/wikimedia/ToolforgeBundle/blob/adab343963a27e623fa481949d18baa060be526a/Twig/Extension.php#L45-L62
train
wikimedia/ToolforgeBundle
Twig/Extension.php
Extension.msgIfExists
public function msgIfExists(string $message = '', array $vars = []) { $exists = $this->msgExists($message, $vars); if ($exists) { return $this->msg($message, $vars); } return $message; }
php
public function msgIfExists(string $message = '', array $vars = []) { $exists = $this->msgExists($message, $vars); if ($exists) { return $this->msg($message, $vars); } return $message; }
[ "public", "function", "msgIfExists", "(", "string", "$", "message", "=", "''", ",", "array", "$", "vars", "=", "[", "]", ")", "{", "$", "exists", "=", "$", "this", "->", "msgExists", "(", "$", "message", ",", "$", "vars", ")", ";", "if", "(", "$"...
Get an i18n message if the key exists, otherwise treat as plain text. @param string $message @param string[] $vars @return mixed|null|string
[ "Get", "an", "i18n", "message", "if", "the", "key", "exists", "otherwise", "treat", "as", "plain", "text", "." ]
adab343963a27e623fa481949d18baa060be526a
https://github.com/wikimedia/ToolforgeBundle/blob/adab343963a27e623fa481949d18baa060be526a/Twig/Extension.php#L80-L87
train
wikimedia/ToolforgeBundle
Twig/Extension.php
Extension.msg
public function msg(string $message = '', array $vars = []) { return $this->intuition->msg($message, [ 'domain' => $this->domain, 'variables' => $vars, ]); }
php
public function msg(string $message = '', array $vars = []) { return $this->intuition->msg($message, [ 'domain' => $this->domain, 'variables' => $vars, ]); }
[ "public", "function", "msg", "(", "string", "$", "message", "=", "''", ",", "array", "$", "vars", "=", "[", "]", ")", "{", "return", "$", "this", "->", "intuition", "->", "msg", "(", "$", "message", ",", "[", "'domain'", "=>", "$", "this", "->", ...
Get an i18n message. @param string $message @param string[] $vars @return mixed|null|string
[ "Get", "an", "i18n", "message", "." ]
adab343963a27e623fa481949d18baa060be526a
https://github.com/wikimedia/ToolforgeBundle/blob/adab343963a27e623fa481949d18baa060be526a/Twig/Extension.php#L112-L118
train
wikimedia/ToolforgeBundle
Twig/Extension.php
Extension.getAllLangs
public function getAllLangs(): array { $domainInfo = $this->intuition->getDomainInfo($this->domain); $messageFiles = glob($domainInfo['dir'].'/*.json'); $languages = array_values(array_unique(array_map( function ($filename) { return basename($filename, '.json'); }, $messageFiles ))); $availableLanguages = []; foreach ($languages as $lang) { $availableLanguages[$lang] = $this->intuition->getLangName($lang); } ksort($availableLanguages); return $availableLanguages; }
php
public function getAllLangs(): array { $domainInfo = $this->intuition->getDomainInfo($this->domain); $messageFiles = glob($domainInfo['dir'].'/*.json'); $languages = array_values(array_unique(array_map( function ($filename) { return basename($filename, '.json'); }, $messageFiles ))); $availableLanguages = []; foreach ($languages as $lang) { $availableLanguages[$lang] = $this->intuition->getLangName($lang); } ksort($availableLanguages); return $availableLanguages; }
[ "public", "function", "getAllLangs", "(", ")", ":", "array", "{", "$", "domainInfo", "=", "$", "this", "->", "intuition", "->", "getDomainInfo", "(", "$", "this", "->", "domain", ")", ";", "$", "messageFiles", "=", "glob", "(", "$", "domainInfo", "[", ...
Get all available languages in the i18n directory. @return string[] Associative array of langKey => langName
[ "Get", "all", "available", "languages", "in", "the", "i18n", "directory", "." ]
adab343963a27e623fa481949d18baa060be526a
https://github.com/wikimedia/ToolforgeBundle/blob/adab343963a27e623fa481949d18baa060be526a/Twig/Extension.php#L159-L175
train
wikimedia/ToolforgeBundle
Twig/Extension.php
Extension.numberFormat
public function numberFormat($number, int $decimals = 0): string { if (!isset($this->numberFormatter)) { $this->numberFormatter = new NumberFormatter($this->intuition->getLang(), NumberFormatter::DECIMAL); } $this->numberFormatter->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $decimals); return $this->numberFormatter->format($number); }
php
public function numberFormat($number, int $decimals = 0): string { if (!isset($this->numberFormatter)) { $this->numberFormatter = new NumberFormatter($this->intuition->getLang(), NumberFormatter::DECIMAL); } $this->numberFormatter->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $decimals); return $this->numberFormatter->format($number); }
[ "public", "function", "numberFormat", "(", "$", "number", ",", "int", "$", "decimals", "=", "0", ")", ":", "string", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "numberFormatter", ")", ")", "{", "$", "this", "->", "numberFormatter", "=", "n...
Format a number based on language settings. @param int|float $number @param int $decimals Number of decimals to format to. @return string
[ "Format", "a", "number", "based", "on", "language", "settings", "." ]
adab343963a27e623fa481949d18baa060be526a
https://github.com/wikimedia/ToolforgeBundle/blob/adab343963a27e623fa481949d18baa060be526a/Twig/Extension.php#L241-L248
train
ComPHPPuebla/dbal-fixtures
src/Database/Row.php
Row.assignId
public function assignId(int $id): void { if (isset($this->values[$this->primaryKeyColumn])) { return; // This is not an auto-generated key } $this->values[$this->primaryKeyColumn] = $id; }
php
public function assignId(int $id): void { if (isset($this->values[$this->primaryKeyColumn])) { return; // This is not an auto-generated key } $this->values[$this->primaryKeyColumn] = $id; }
[ "public", "function", "assignId", "(", "int", "$", "id", ")", ":", "void", "{", "if", "(", "isset", "(", "$", "this", "->", "values", "[", "$", "this", "->", "primaryKeyColumn", "]", ")", ")", "{", "return", ";", "// This is not an auto-generated key", "...
It will skip the assignment if there's already a value for the primary key column
[ "It", "will", "skip", "the", "assignment", "if", "there", "s", "already", "a", "value", "for", "the", "primary", "key", "column" ]
a20fac4df2ec482f01d0b5f26d64f52364e34b71
https://github.com/ComPHPPuebla/dbal-fixtures/blob/a20fac4df2ec482f01d0b5f26d64f52364e34b71/src/Database/Row.php#L30-L37
train
QoboLtd/cakephp-groups
src/Controller/Component/GroupComponent.php
GroupComponent.getUserGroups
public function getUserGroups(string $userId = ''): array { // if not specified, get current user's id if (empty($userId)) { $userId = $this->Auth->user('id'); } $groups = TableRegistry::get('Groups.Groups'); $query = $groups->find('list', [ 'keyField' => 'id', 'valueField' => 'name' ]); $query->matching('Users', function ($q) use ($userId) { return $q->where(['Users.id' => $userId]); }); return $query->toArray(); }
php
public function getUserGroups(string $userId = ''): array { // if not specified, get current user's id if (empty($userId)) { $userId = $this->Auth->user('id'); } $groups = TableRegistry::get('Groups.Groups'); $query = $groups->find('list', [ 'keyField' => 'id', 'valueField' => 'name' ]); $query->matching('Users', function ($q) use ($userId) { return $q->where(['Users.id' => $userId]); }); return $query->toArray(); }
[ "public", "function", "getUserGroups", "(", "string", "$", "userId", "=", "''", ")", ":", "array", "{", "// if not specified, get current user's id", "if", "(", "empty", "(", "$", "userId", ")", ")", "{", "$", "userId", "=", "$", "this", "->", "Auth", "->"...
Method that retrieves specified user's groups @param string $userId user id @return mixed[]
[ "Method", "that", "retrieves", "specified", "user", "s", "groups" ]
0aaf735365364a9bc2bce6660ef85868e174fb9a
https://github.com/QoboLtd/cakephp-groups/blob/0aaf735365364a9bc2bce6660ef85868e174fb9a/src/Controller/Component/GroupComponent.php#L41-L59
train
ComPHPPuebla/dbal-fixtures
src/Fixture.php
Fixture.load
public function load(string $pathToFixturesFile): void { $tables = $this->loader->load($pathToFixturesFile); foreach ($tables as $table => $rows) { $this->processTableRows($table, $rows); } }
php
public function load(string $pathToFixturesFile): void { $tables = $this->loader->load($pathToFixturesFile); foreach ($tables as $table => $rows) { $this->processTableRows($table, $rows); } }
[ "public", "function", "load", "(", "string", "$", "pathToFixturesFile", ")", ":", "void", "{", "$", "tables", "=", "$", "this", "->", "loader", "->", "load", "(", "$", "pathToFixturesFile", ")", ";", "foreach", "(", "$", "tables", "as", "$", "table", "...
Parse the fixture file and insert the rows in the configured database The process to parse a fixture file is as follows 1. It converts the content of the file to an associative array 2. It process the rows for every table a. It generates the rows if the row identifier is a range definition b. It runs the pre-processors for each row * The foreign key processor replaces any reference `@reference` with a real database ID * The faker processor will replace any formatter `formatter(arg_1..arg_n)` with fake data c. It inserts the row in the database and assigns the auto generated ID to the row if any d. It runs the post-processors for each row * The foreign key processor will save the generated database ID for the rows that might use it as reference, in the pre-insert face
[ "Parse", "the", "fixture", "file", "and", "insert", "the", "rows", "in", "the", "configured", "database" ]
a20fac4df2ec482f01d0b5f26d64f52364e34b71
https://github.com/ComPHPPuebla/dbal-fixtures/blob/a20fac4df2ec482f01d0b5f26d64f52364e34b71/src/Fixture.php#L76-L83
train
ComPHPPuebla/dbal-fixtures
src/Database/DBALConnection.php
DBALConnection.primaryKeyOf
public function primaryKeyOf(string $table): string { $schema = $this->connection->getSchemaManager(); return $schema->listTableDetails($table)->getPrimaryKeyColumns()[0]; }
php
public function primaryKeyOf(string $table): string { $schema = $this->connection->getSchemaManager(); return $schema->listTableDetails($table)->getPrimaryKeyColumns()[0]; }
[ "public", "function", "primaryKeyOf", "(", "string", "$", "table", ")", ":", "string", "{", "$", "schema", "=", "$", "this", "->", "connection", "->", "getSchemaManager", "(", ")", ";", "return", "$", "schema", "->", "listTableDetails", "(", "$", "table", ...
This method is needed in order to keep track of references to other rows in the fixtures @see \ComPHPPuebla\Fixtures\Fixture::processTableRows @throws \Doctrine\DBAL\DBALException
[ "This", "method", "is", "needed", "in", "order", "to", "keep", "track", "of", "references", "to", "other", "rows", "in", "the", "fixtures" ]
a20fac4df2ec482f01d0b5f26d64f52364e34b71
https://github.com/ComPHPPuebla/dbal-fixtures/blob/a20fac4df2ec482f01d0b5f26d64f52364e34b71/src/Database/DBALConnection.php#L37-L41
train
wikimedia/ToolforgeBundle
Controller/AuthController.php
AuthController.loginAction
public function loginAction(Client $oauthClient, Session $session): RedirectResponse { // Automatically log in a development user if defined. $loggedInUser = $this->getParameter('toolforge.oauth.logged_in_user'); if ($loggedInUser) { $this->get('session')->set('logged_in_user', (object)[ 'username' => $loggedInUser, ]); return $this->redirectToRoute('home'); } // Otherwise, continue with OAuth authentication. [$next, $token] = $oauthClient->initiate(); // Save the request token to the session. $session->set('oauth.request_token', $token); // Send the user to Meta Wiki. return new RedirectResponse($next); }
php
public function loginAction(Client $oauthClient, Session $session): RedirectResponse { // Automatically log in a development user if defined. $loggedInUser = $this->getParameter('toolforge.oauth.logged_in_user'); if ($loggedInUser) { $this->get('session')->set('logged_in_user', (object)[ 'username' => $loggedInUser, ]); return $this->redirectToRoute('home'); } // Otherwise, continue with OAuth authentication. [$next, $token] = $oauthClient->initiate(); // Save the request token to the session. $session->set('oauth.request_token', $token); // Send the user to Meta Wiki. return new RedirectResponse($next); }
[ "public", "function", "loginAction", "(", "Client", "$", "oauthClient", ",", "Session", "$", "session", ")", ":", "RedirectResponse", "{", "// Automatically log in a development user if defined.", "$", "loggedInUser", "=", "$", "this", "->", "getParameter", "(", "'too...
Redirect to Meta for Oauth authentication. @Route("/login", name="toolforge_login") @return RedirectResponse
[ "Redirect", "to", "Meta", "for", "Oauth", "authentication", "." ]
adab343963a27e623fa481949d18baa060be526a
https://github.com/wikimedia/ToolforgeBundle/blob/adab343963a27e623fa481949d18baa060be526a/Controller/AuthController.php#L22-L41
train
wikimedia/ToolforgeBundle
Controller/AuthController.php
AuthController.oauthCallbackAction
public function oauthCallbackAction(Request $request, Session $session, Client $client): RedirectResponse { // Give up if the required GET params or stored request token don't exist. if (!$request->get('oauth_verifier')) { throw $this->createNotFoundException('No OAuth verifier given.'); } if (!$session->has('oauth.request_token')) { throw $this->createNotFoundException('No request token found. Please try logging in again.'); } // Complete authentication. $token = $session->get('oauth.request_token'); $verifier = $request->get('oauth_verifier'); $accessToken = $client->complete($token, $verifier); // Store access token, and remove request token. $session->set('oauth.access_token', $accessToken); $session->remove('oauth.request_token'); // Regenerate session ID. $session->migrate(); // Store user identity. $ident = $client->identify($accessToken); $session->set('logged_in_user', $ident); // Send to homepage. return $this->redirectToRoute('home'); }
php
public function oauthCallbackAction(Request $request, Session $session, Client $client): RedirectResponse { // Give up if the required GET params or stored request token don't exist. if (!$request->get('oauth_verifier')) { throw $this->createNotFoundException('No OAuth verifier given.'); } if (!$session->has('oauth.request_token')) { throw $this->createNotFoundException('No request token found. Please try logging in again.'); } // Complete authentication. $token = $session->get('oauth.request_token'); $verifier = $request->get('oauth_verifier'); $accessToken = $client->complete($token, $verifier); // Store access token, and remove request token. $session->set('oauth.access_token', $accessToken); $session->remove('oauth.request_token'); // Regenerate session ID. $session->migrate(); // Store user identity. $ident = $client->identify($accessToken); $session->set('logged_in_user', $ident); // Send to homepage. return $this->redirectToRoute('home'); }
[ "public", "function", "oauthCallbackAction", "(", "Request", "$", "request", ",", "Session", "$", "session", ",", "Client", "$", "client", ")", ":", "RedirectResponse", "{", "// Give up if the required GET params or stored request token don't exist.", "if", "(", "!", "$...
Receive authentication credentials back from the OAuth wiki. @Route("/oauth_callback", name="toolforge_oauth_callback") @param Request $request The HTTP request. @return RedirectResponse
[ "Receive", "authentication", "credentials", "back", "from", "the", "OAuth", "wiki", "." ]
adab343963a27e623fa481949d18baa060be526a
https://github.com/wikimedia/ToolforgeBundle/blob/adab343963a27e623fa481949d18baa060be526a/Controller/AuthController.php#L49-L77
train
QoboLtd/cakephp-groups
src/Shell/Task/SyncLdapGroupsTask.php
SyncLdapGroupsTask.getGroups
protected function getGroups(Table $table): array { /** * @var \Cake\ORM\Query $query */ $query = $table->find('all') ->where(['remote_group_id IS NOT NULL', 'remote_group_id !=' => '']) ->contain(['Users' => function ($q) { return $q->select(['Users.username']); }]); /** * @var array $result */ $result = $query->all(); return $result; }
php
protected function getGroups(Table $table): array { /** * @var \Cake\ORM\Query $query */ $query = $table->find('all') ->where(['remote_group_id IS NOT NULL', 'remote_group_id !=' => '']) ->contain(['Users' => function ($q) { return $q->select(['Users.username']); }]); /** * @var array $result */ $result = $query->all(); return $result; }
[ "protected", "function", "getGroups", "(", "Table", "$", "table", ")", ":", "array", "{", "/**\n * @var \\Cake\\ORM\\Query $query\n */", "$", "query", "=", "$", "table", "->", "find", "(", "'all'", ")", "->", "where", "(", "[", "'remote_group_id IS...
Fetch system groups which are mapped to LDAP group. @param \Cake\ORM\Table $table Table instance @return mixed[]
[ "Fetch", "system", "groups", "which", "are", "mapped", "to", "LDAP", "group", "." ]
0aaf735365364a9bc2bce6660ef85868e174fb9a
https://github.com/QoboLtd/cakephp-groups/blob/0aaf735365364a9bc2bce6660ef85868e174fb9a/src/Shell/Task/SyncLdapGroupsTask.php#L138-L154
train
QoboLtd/cakephp-groups
src/Shell/Task/SyncLdapGroupsTask.php
SyncLdapGroupsTask.getDomain
protected function getDomain(array $config): string { $result = ''; $parts = explode(',', $config['baseDn']); foreach ($parts as $part) { list($key, $value) = explode('=', $part); if ('dc' !== strtolower($key)) { continue; } $result .= '.' . $value; } $result = trim(trim($result, '.')); // fallback value if (empty($result)) { $result = $config['domain'] . '.com'; } return $result; }
php
protected function getDomain(array $config): string { $result = ''; $parts = explode(',', $config['baseDn']); foreach ($parts as $part) { list($key, $value) = explode('=', $part); if ('dc' !== strtolower($key)) { continue; } $result .= '.' . $value; } $result = trim(trim($result, '.')); // fallback value if (empty($result)) { $result = $config['domain'] . '.com'; } return $result; }
[ "protected", "function", "getDomain", "(", "array", "$", "config", ")", ":", "string", "{", "$", "result", "=", "''", ";", "$", "parts", "=", "explode", "(", "','", ",", "$", "config", "[", "'baseDn'", "]", ")", ";", "foreach", "(", "$", "parts", "...
Get LDAP domain. @param mixed[] $config LDAP configuration @return string
[ "Get", "LDAP", "domain", "." ]
0aaf735365364a9bc2bce6660ef85868e174fb9a
https://github.com/QoboLtd/cakephp-groups/blob/0aaf735365364a9bc2bce6660ef85868e174fb9a/src/Shell/Task/SyncLdapGroupsTask.php#L190-L211
train
QoboLtd/cakephp-groups
src/Shell/Task/SyncLdapGroupsTask.php
SyncLdapGroupsTask.getUsers
protected function getUsers(array $data, string $domain): array { /** * @var \CakeDC\Users\Model\Table\UsersTable $table */ $table = $this->getUsersTable(); $result = []; for ($i = 0; $i < $data['count']; $i++) { $username = $data[$i]['userprincipalname'][0]; $username = str_replace('@' . $domain, '', $username); $query = $table->find()->where(['username' => $username]); if ($query->isEmpty()) { continue; } $result[] = $query->first(); } return $result; }
php
protected function getUsers(array $data, string $domain): array { /** * @var \CakeDC\Users\Model\Table\UsersTable $table */ $table = $this->getUsersTable(); $result = []; for ($i = 0; $i < $data['count']; $i++) { $username = $data[$i]['userprincipalname'][0]; $username = str_replace('@' . $domain, '', $username); $query = $table->find()->where(['username' => $username]); if ($query->isEmpty()) { continue; } $result[] = $query->first(); } return $result; }
[ "protected", "function", "getUsers", "(", "array", "$", "data", ",", "string", "$", "domain", ")", ":", "array", "{", "/**\n * @var \\CakeDC\\Users\\Model\\Table\\UsersTable $table\n */", "$", "table", "=", "$", "this", "->", "getUsersTable", "(", ")",...
Fetch system users which are members of LDAP group. @param mixed[] $data LDAP result @param string $domain LDAP domain @return mixed[]
[ "Fetch", "system", "users", "which", "are", "members", "of", "LDAP", "group", "." ]
0aaf735365364a9bc2bce6660ef85868e174fb9a
https://github.com/QoboLtd/cakephp-groups/blob/0aaf735365364a9bc2bce6660ef85868e174fb9a/src/Shell/Task/SyncLdapGroupsTask.php#L220-L241
train
QoboLtd/cakephp-groups
src/Shell/Task/SyncLdapGroupsTask.php
SyncLdapGroupsTask.syncGroupUsers
protected function syncGroupUsers(Table $table, EntityInterface $group, array $users): bool { $userIds = []; foreach ($users as $user) { $userIds[] = $user->id; } if (!empty($group->users)) { foreach ($group->users as $user) { $userIds[] = $user->id; } } $data = [ 'users' => [ '_ids' => $userIds ] ]; $group = $table->patchEntity($group, $data); $result = empty($table) ? false : true; return $result; }
php
protected function syncGroupUsers(Table $table, EntityInterface $group, array $users): bool { $userIds = []; foreach ($users as $user) { $userIds[] = $user->id; } if (!empty($group->users)) { foreach ($group->users as $user) { $userIds[] = $user->id; } } $data = [ 'users' => [ '_ids' => $userIds ] ]; $group = $table->patchEntity($group, $data); $result = empty($table) ? false : true; return $result; }
[ "protected", "function", "syncGroupUsers", "(", "Table", "$", "table", ",", "EntityInterface", "$", "group", ",", "array", "$", "users", ")", ":", "bool", "{", "$", "userIds", "=", "[", "]", ";", "foreach", "(", "$", "users", "as", "$", "user", ")", ...
Synchronizes group users based on mapped LDAP group users. @param \Cake\ORM\Table $table Table instance @param \Cake\Datasource\EntityInterface $group Group entity @param mixed[] $users Group users @return bool
[ "Synchronizes", "group", "users", "based", "on", "mapped", "LDAP", "group", "users", "." ]
0aaf735365364a9bc2bce6660ef85868e174fb9a
https://github.com/QoboLtd/cakephp-groups/blob/0aaf735365364a9bc2bce6660ef85868e174fb9a/src/Shell/Task/SyncLdapGroupsTask.php#L251-L274
train
ComPHPPuebla/dbal-fixtures
src/Processors/FormatterCall.php
FormatterCall.run
public function run(Generator $generator): string { return str_replace( $this->call, $generator->format($this->formatter, $this->parseArguments()), $this->definition ); }
php
public function run(Generator $generator): string { return str_replace( $this->call, $generator->format($this->formatter, $this->parseArguments()), $this->definition ); }
[ "public", "function", "run", "(", "Generator", "$", "generator", ")", ":", "string", "{", "return", "str_replace", "(", "$", "this", "->", "call", ",", "$", "generator", "->", "format", "(", "$", "this", "->", "formatter", ",", "$", "this", "->", "pars...
It calls the formatter, on the given generator, with the arguments defined in this call object
[ "It", "calls", "the", "formatter", "on", "the", "given", "generator", "with", "the", "arguments", "defined", "in", "this", "call", "object" ]
a20fac4df2ec482f01d0b5f26d64f52364e34b71
https://github.com/ComPHPPuebla/dbal-fixtures/blob/a20fac4df2ec482f01d0b5f26d64f52364e34b71/src/Processors/FormatterCall.php#L30-L37
train
ComPHPPuebla/dbal-fixtures
src/Processors/FormatterCall.php
FormatterCall.parseArguments
private function parseArguments(): array { if (empty($this->arguments)) { return []; } $arguments = explode(',', $this->arguments); $trimmedArguments = array_map('trim', $arguments); return array_map( function ($argument) { $argumentWithoutQuotes = str_replace(['\'', '"'], '', $argument); return $argumentWithoutQuotes; }, $trimmedArguments ); }
php
private function parseArguments(): array { if (empty($this->arguments)) { return []; } $arguments = explode(',', $this->arguments); $trimmedArguments = array_map('trim', $arguments); return array_map( function ($argument) { $argumentWithoutQuotes = str_replace(['\'', '"'], '', $argument); return $argumentWithoutQuotes; }, $trimmedArguments ); }
[ "private", "function", "parseArguments", "(", ")", ":", "array", "{", "if", "(", "empty", "(", "$", "this", "->", "arguments", ")", ")", "{", "return", "[", "]", ";", "}", "$", "arguments", "=", "explode", "(", "','", ",", "$", "this", "->", "argum...
The parsing arguments process can be described as follows - Split the list of arguments `arg_1,...,arg_n` using the comma as delimiter - Trim the individual argument values - Remove the quotes from the arguments' values if present
[ "The", "parsing", "arguments", "process", "can", "be", "described", "as", "follows" ]
a20fac4df2ec482f01d0b5f26d64f52364e34b71
https://github.com/ComPHPPuebla/dbal-fixtures/blob/a20fac4df2ec482f01d0b5f26d64f52364e34b71/src/Processors/FormatterCall.php#L77-L92
train
QoboLtd/cakephp-groups
src/Shell/Task/ImportTask.php
ImportTask.getImportErrors
protected function getImportErrors(EntityInterface $entity): array { $result = []; /** * @var array $errors */ $errors = $entity->errors(); if (empty($errors)) { return $result; } foreach ($errors as $field => $error) { $msg = "[$field] "; $msg .= is_array($error) ? implode(', ', $error) : $error; $result[] = $msg; } return $result; }
php
protected function getImportErrors(EntityInterface $entity): array { $result = []; /** * @var array $errors */ $errors = $entity->errors(); if (empty($errors)) { return $result; } foreach ($errors as $field => $error) { $msg = "[$field] "; $msg .= is_array($error) ? implode(', ', $error) : $error; $result[] = $msg; } return $result; }
[ "protected", "function", "getImportErrors", "(", "EntityInterface", "$", "entity", ")", ":", "array", "{", "$", "result", "=", "[", "]", ";", "/**\n * @var array $errors\n */", "$", "errors", "=", "$", "entity", "->", "errors", "(", ")", ";", "...
Get import errors from entity object. @param \Cake\Datasource\EntityInterface $entity Entity instance @return string[]
[ "Get", "import", "errors", "from", "entity", "object", "." ]
0aaf735365364a9bc2bce6660ef85868e174fb9a
https://github.com/QoboLtd/cakephp-groups/blob/0aaf735365364a9bc2bce6660ef85868e174fb9a/src/Shell/Task/ImportTask.php#L76-L96
train
QoboLtd/cakephp-groups
src/Model/Table/GroupsTable.php
GroupsTable.getUserGroups
public function getUserGroups(string $userId, array $options = []): array { $query = $this->find('list', [ 'keyField' => 'id', 'valueField' => 'name' ]); $query->matching('Users', function ($q) use ($userId) { return $q->where(['Users.id' => $userId]); }); $query->applyOptions($options); return $query->toArray(); }
php
public function getUserGroups(string $userId, array $options = []): array { $query = $this->find('list', [ 'keyField' => 'id', 'valueField' => 'name' ]); $query->matching('Users', function ($q) use ($userId) { return $q->where(['Users.id' => $userId]); }); $query->applyOptions($options); return $query->toArray(); }
[ "public", "function", "getUserGroups", "(", "string", "$", "userId", ",", "array", "$", "options", "=", "[", "]", ")", ":", "array", "{", "$", "query", "=", "$", "this", "->", "find", "(", "'list'", ",", "[", "'keyField'", "=>", "'id'", ",", "'valueF...
Method that retrieves specified user's groups as list. @param string $userId user id @param mixed[] $options Query options @return mixed[]
[ "Method", "that", "retrieves", "specified", "user", "s", "groups", "as", "list", "." ]
0aaf735365364a9bc2bce6660ef85868e174fb9a
https://github.com/QoboLtd/cakephp-groups/blob/0aaf735365364a9bc2bce6660ef85868e174fb9a/src/Model/Table/GroupsTable.php#L119-L131
train
QoboLtd/cakephp-groups
src/Model/Table/GroupsTable.php
GroupsTable.getRemoteGroups
public function getRemoteGroups(): array { $result = []; if (!(bool)Configure::read('Groups.remoteGroups.enabled')) { return $result; } if ((bool)Configure::read('Groups.remoteGroups.LDAP.enabled')) { $result = $this->_getLdapGroups(); } return $result; }
php
public function getRemoteGroups(): array { $result = []; if (!(bool)Configure::read('Groups.remoteGroups.enabled')) { return $result; } if ((bool)Configure::read('Groups.remoteGroups.LDAP.enabled')) { $result = $this->_getLdapGroups(); } return $result; }
[ "public", "function", "getRemoteGroups", "(", ")", ":", "array", "{", "$", "result", "=", "[", "]", ";", "if", "(", "!", "(", "bool", ")", "Configure", "::", "read", "(", "'Groups.remoteGroups.enabled'", ")", ")", "{", "return", "$", "result", ";", "}"...
Fetch remote groups. @return mixed[]
[ "Fetch", "remote", "groups", "." ]
0aaf735365364a9bc2bce6660ef85868e174fb9a
https://github.com/QoboLtd/cakephp-groups/blob/0aaf735365364a9bc2bce6660ef85868e174fb9a/src/Model/Table/GroupsTable.php#L157-L170
train
QoboLtd/cakephp-groups
src/Model/Table/GroupsTable.php
GroupsTable._getLdapGroups
protected function _getLdapGroups(): array { $result = []; $config = (array)Configure::read('Groups.remoteGroups.LDAP'); if (!empty(array_diff($this->ldapRequiredParams, array_keys($config)))) { return $result; } $connection = $this->_ldapConnect($config); if (!is_resource($connection)) { return $result; } $search = ldap_search($connection, $config['baseDn'], $config['groupsFilter'], ['cn']); if (!is_resource($search)) { Log::critical('Failed to search LDAP'); return $result; } $result = ldap_get_entries($connection, $search); if (empty($result)) { return $result; } return $this->_normalizeResult($result); }
php
protected function _getLdapGroups(): array { $result = []; $config = (array)Configure::read('Groups.remoteGroups.LDAP'); if (!empty(array_diff($this->ldapRequiredParams, array_keys($config)))) { return $result; } $connection = $this->_ldapConnect($config); if (!is_resource($connection)) { return $result; } $search = ldap_search($connection, $config['baseDn'], $config['groupsFilter'], ['cn']); if (!is_resource($search)) { Log::critical('Failed to search LDAP'); return $result; } $result = ldap_get_entries($connection, $search); if (empty($result)) { return $result; } return $this->_normalizeResult($result); }
[ "protected", "function", "_getLdapGroups", "(", ")", ":", "array", "{", "$", "result", "=", "[", "]", ";", "$", "config", "=", "(", "array", ")", "Configure", "::", "read", "(", "'Groups.remoteGroups.LDAP'", ")", ";", "if", "(", "!", "empty", "(", "arr...
Fetch LDAP groups. @return mixed[]
[ "Fetch", "LDAP", "groups", "." ]
0aaf735365364a9bc2bce6660ef85868e174fb9a
https://github.com/QoboLtd/cakephp-groups/blob/0aaf735365364a9bc2bce6660ef85868e174fb9a/src/Model/Table/GroupsTable.php#L177-L205
train
QoboLtd/cakephp-groups
src/Model/Table/GroupsTable.php
GroupsTable._normalizeResult
protected function _normalizeResult(array $data): array { $result = []; for ($i = 0; $i < $data['count']; $i++) { $item = $data[$i]; // construct label preg_match('/^.*?,OU=(.*?),/i', $item['dn'], $match); $label = !empty($match[1]) ? $match[1] . ' / ' . $item['cn'][0] : $item['cn'][0]; $result[$item['dn']] = $label; } asort($result); return $result; }
php
protected function _normalizeResult(array $data): array { $result = []; for ($i = 0; $i < $data['count']; $i++) { $item = $data[$i]; // construct label preg_match('/^.*?,OU=(.*?),/i', $item['dn'], $match); $label = !empty($match[1]) ? $match[1] . ' / ' . $item['cn'][0] : $item['cn'][0]; $result[$item['dn']] = $label; } asort($result); return $result; }
[ "protected", "function", "_normalizeResult", "(", "array", "$", "data", ")", ":", "array", "{", "$", "result", "=", "[", "]", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "data", "[", "'count'", "]", ";", "$", "i", "++", ")", ...
Normalizes LDAP result. @param mixed[] $data LDAP result @return mixed[]
[ "Normalizes", "LDAP", "result", "." ]
0aaf735365364a9bc2bce6660ef85868e174fb9a
https://github.com/QoboLtd/cakephp-groups/blob/0aaf735365364a9bc2bce6660ef85868e174fb9a/src/Model/Table/GroupsTable.php#L247-L263
train
stefangabos/Zebra_Image
Zebra_Image.php
Zebra_Image._prepare_image
private function _prepare_image($width, $height, $background_color = '#FFFFFF') { // create a blank image $identifier = imagecreatetruecolor((int)$width <= 0 ? 1 : (int)$width, (int)$height <= 0 ? 1 : (int)$height); // if we are creating a transparent image, and image type supports transparency if ($background_color == -1 && $this->target_type != 'jpg') { // disable blending imagealphablending($identifier, false); // allocate a transparent color $background_color = imagecolorallocatealpha($identifier, 0, 0, 0, 127); // we also need to set this for saving gifs imagecolortransparent($identifier, $background_color); // save full alpha channel information imagesavealpha($identifier, true); // if we are not creating a transparent image } else { // convert hex color to rgb $background_color = $this->_hex2rgb($background_color); // prepare the background color $background_color = imagecolorallocate($identifier, $background_color['r'], $background_color['g'], $background_color['b']); } // fill the image with the background color imagefill($identifier, 0, 0, $background_color); // return the image's identifier return $identifier; }
php
private function _prepare_image($width, $height, $background_color = '#FFFFFF') { // create a blank image $identifier = imagecreatetruecolor((int)$width <= 0 ? 1 : (int)$width, (int)$height <= 0 ? 1 : (int)$height); // if we are creating a transparent image, and image type supports transparency if ($background_color == -1 && $this->target_type != 'jpg') { // disable blending imagealphablending($identifier, false); // allocate a transparent color $background_color = imagecolorallocatealpha($identifier, 0, 0, 0, 127); // we also need to set this for saving gifs imagecolortransparent($identifier, $background_color); // save full alpha channel information imagesavealpha($identifier, true); // if we are not creating a transparent image } else { // convert hex color to rgb $background_color = $this->_hex2rgb($background_color); // prepare the background color $background_color = imagecolorallocate($identifier, $background_color['r'], $background_color['g'], $background_color['b']); } // fill the image with the background color imagefill($identifier, 0, 0, $background_color); // return the image's identifier return $identifier; }
[ "private", "function", "_prepare_image", "(", "$", "width", ",", "$", "height", ",", "$", "background_color", "=", "'#FFFFFF'", ")", "{", "// create a blank image\r", "$", "identifier", "=", "imagecreatetruecolor", "(", "(", "int", ")", "$", "width", "<=", "0"...
Creates a blank image of given width, height and background color. @param integer $width Width of the new image. @param integer $height Height of the new image. @param string $background_color (Optional) The hexadecimal color of the background. Can also be -1 case in which the script will try to create a transparent image, if possible. Default is #FFFFFF. @return Returns the identifier of the newly created image. @access private
[ "Creates", "a", "blank", "image", "of", "given", "width", "height", "and", "background", "color", "." ]
ed27cbe49473c309d3915ce97ec475fe885841d3
https://github.com/stefangabos/Zebra_Image/blob/ed27cbe49473c309d3915ce97ec475fe885841d3/Zebra_Image.php#L1558-L1595
train
stefangabos/Zebra_Image
Zebra_Image.php
Zebra_Image._sharpen_image
private function _sharpen_image($image) { // if the "sharpen_images" is set to true and we're running an appropriate version of PHP // (the "imageconvolution" is available only for PHP 5.1.0+) if ($this->sharpen_images && version_compare(PHP_VERSION, '5.1.0') >= 0) { // the convolution matrix as an array of three arrays of three floats $matrix = array( array(-1.2, -1, -1.2), array(-1, 20, -1), array(-1.2, -1, -1.2), ); // the divisor of the matrix $divisor = array_sum(array_map('array_sum', $matrix)); // color offset $offset = 0; // sharpen image imageconvolution($image, $matrix, $divisor, $offset); } // return the image's identifier return $image; }
php
private function _sharpen_image($image) { // if the "sharpen_images" is set to true and we're running an appropriate version of PHP // (the "imageconvolution" is available only for PHP 5.1.0+) if ($this->sharpen_images && version_compare(PHP_VERSION, '5.1.0') >= 0) { // the convolution matrix as an array of three arrays of three floats $matrix = array( array(-1.2, -1, -1.2), array(-1, 20, -1), array(-1.2, -1, -1.2), ); // the divisor of the matrix $divisor = array_sum(array_map('array_sum', $matrix)); // color offset $offset = 0; // sharpen image imageconvolution($image, $matrix, $divisor, $offset); } // return the image's identifier return $image; }
[ "private", "function", "_sharpen_image", "(", "$", "image", ")", "{", "// if the \"sharpen_images\" is set to true and we're running an appropriate version of PHP\r", "// (the \"imageconvolution\" is available only for PHP 5.1.0+)\r", "if", "(", "$", "this", "->", "sharpen_images", "...
Sharpens images. Useful when creating thumbnails. Code taken from the comments at {@link http://docs.php.net/imageconvolution}. <i>This function will yield a result only for PHP version 5.1.0+ and will leave the image unaltered for older versions!</i> @param $identifier identifier An image identifier @access private
[ "Sharpens", "images", ".", "Useful", "when", "creating", "thumbnails", "." ]
ed27cbe49473c309d3915ce97ec475fe885841d3
https://github.com/stefangabos/Zebra_Image/blob/ed27cbe49473c309d3915ce97ec475fe885841d3/Zebra_Image.php#L1609-L1636
train
widop/google-analytics
src/Widop/GoogleAnalytics/Query.php
Query.setMetrics
public function setMetrics(array $metrics) { $this->metrics = array(); foreach ($metrics as $metric) { $this->addMetric($metric); } return $this; }
php
public function setMetrics(array $metrics) { $this->metrics = array(); foreach ($metrics as $metric) { $this->addMetric($metric); } return $this; }
[ "public", "function", "setMetrics", "(", "array", "$", "metrics", ")", "{", "$", "this", "->", "metrics", "=", "array", "(", ")", ";", "foreach", "(", "$", "metrics", "as", "$", "metric", ")", "{", "$", "this", "->", "addMetric", "(", "$", "metric", ...
Sets the google analytics query metrics. @param array $metrics The google analytics query metrics. @return \Widop\GoogleAnalytics\Query The query.
[ "Sets", "the", "google", "analytics", "query", "metrics", "." ]
ba2e5ec50076dce693dc587965024068f6fb54b4
https://github.com/widop/google-analytics/blob/ba2e5ec50076dce693dc587965024068f6fb54b4/src/Widop/GoogleAnalytics/Query.php#L197-L206
train
widop/google-analytics
src/Widop/GoogleAnalytics/Query.php
Query.setDimensions
public function setDimensions(array $dimensions) { $this->dimensions = array(); foreach ($dimensions as $dimension) { $this->addDimension($dimension); } return $this; }
php
public function setDimensions(array $dimensions) { $this->dimensions = array(); foreach ($dimensions as $dimension) { $this->addDimension($dimension); } return $this; }
[ "public", "function", "setDimensions", "(", "array", "$", "dimensions", ")", "{", "$", "this", "->", "dimensions", "=", "array", "(", ")", ";", "foreach", "(", "$", "dimensions", "as", "$", "dimension", ")", "{", "$", "this", "->", "addDimension", "(", ...
Sets the google analytics query dimensions. @param array $dimensions The google analytics query dimensions. @return \Widop\GoogleAnalytics\Query The query.
[ "Sets", "the", "google", "analytics", "query", "dimensions", "." ]
ba2e5ec50076dce693dc587965024068f6fb54b4
https://github.com/widop/google-analytics/blob/ba2e5ec50076dce693dc587965024068f6fb54b4/src/Widop/GoogleAnalytics/Query.php#L249-L258
train
widop/google-analytics
src/Widop/GoogleAnalytics/Query.php
Query.setSorts
public function setSorts(array $sorts) { $this->sorts = array(); foreach ($sorts as $sort) { $this->addSort($sort); } return $this; }
php
public function setSorts(array $sorts) { $this->sorts = array(); foreach ($sorts as $sort) { $this->addSort($sort); } return $this; }
[ "public", "function", "setSorts", "(", "array", "$", "sorts", ")", "{", "$", "this", "->", "sorts", "=", "array", "(", ")", ";", "foreach", "(", "$", "sorts", "as", "$", "sort", ")", "{", "$", "this", "->", "addSort", "(", "$", "sort", ")", ";", ...
Sets the google analytics query sorts. @param array $sorts The google analytics query sorts. @return \Widop\GoogleAnalytics\Query The query.
[ "Sets", "the", "google", "analytics", "query", "sorts", "." ]
ba2e5ec50076dce693dc587965024068f6fb54b4
https://github.com/widop/google-analytics/blob/ba2e5ec50076dce693dc587965024068f6fb54b4/src/Widop/GoogleAnalytics/Query.php#L301-L310
train
widop/google-analytics
src/Widop/GoogleAnalytics/Client.php
Client.setPrivateKeyFile
public function setPrivateKeyFile($privateKeyFile) { if (!file_exists($privateKeyFile)) { throw GoogleAnalyticsException::invalidPrivateKeyFile($privateKeyFile); } $this->privateKeyFile = $privateKeyFile; return $this; }
php
public function setPrivateKeyFile($privateKeyFile) { if (!file_exists($privateKeyFile)) { throw GoogleAnalyticsException::invalidPrivateKeyFile($privateKeyFile); } $this->privateKeyFile = $privateKeyFile; return $this; }
[ "public", "function", "setPrivateKeyFile", "(", "$", "privateKeyFile", ")", "{", "if", "(", "!", "file_exists", "(", "$", "privateKeyFile", ")", ")", "{", "throw", "GoogleAnalyticsException", "::", "invalidPrivateKeyFile", "(", "$", "privateKeyFile", ")", ";", "...
Sets the absolute private key file path. @param string $privateKeyFile The absolute private key file path. @throws \Widop\GoogleAnalytics\Exception\GoogleAnalyticsException If the private key file does not exist. @return \Widop\GoogleAnalytics\Client The client.
[ "Sets", "the", "absolute", "private", "key", "file", "path", "." ]
ba2e5ec50076dce693dc587965024068f6fb54b4
https://github.com/widop/google-analytics/blob/ba2e5ec50076dce693dc587965024068f6fb54b4/src/Widop/GoogleAnalytics/Client.php#L104-L113
train
widop/google-analytics
src/Widop/GoogleAnalytics/Client.php
Client.getAccessToken
public function getAccessToken() { if ($this->accessToken === null) { $headers = array('Content-Type' => 'application/x-www-form-urlencoded'); $content = array( 'grant_type' => 'assertion', 'assertion_type' => 'http://oauth.net/grant_type/jwt/1.0/bearer', 'assertion' => $this->generateJsonWebToken(), ); $response = json_decode($this->httpAdapter->postContent($this->url, $headers, $content)); if (isset($response->error)) { throw GoogleAnalyticsException::invalidAccessToken($response->error); } $this->accessToken = $response->access_token; } return $this->accessToken; }
php
public function getAccessToken() { if ($this->accessToken === null) { $headers = array('Content-Type' => 'application/x-www-form-urlencoded'); $content = array( 'grant_type' => 'assertion', 'assertion_type' => 'http://oauth.net/grant_type/jwt/1.0/bearer', 'assertion' => $this->generateJsonWebToken(), ); $response = json_decode($this->httpAdapter->postContent($this->url, $headers, $content)); if (isset($response->error)) { throw GoogleAnalyticsException::invalidAccessToken($response->error); } $this->accessToken = $response->access_token; } return $this->accessToken; }
[ "public", "function", "getAccessToken", "(", ")", "{", "if", "(", "$", "this", "->", "accessToken", "===", "null", ")", "{", "$", "headers", "=", "array", "(", "'Content-Type'", "=>", "'application/x-www-form-urlencoded'", ")", ";", "$", "content", "=", "arr...
Gets the google OAuth access token. @throws \Widop\GoogleAnalytics\Exception\GoogleAnalyticsException If the access token can not be retrieved. @return string The access token.
[ "Gets", "the", "google", "OAuth", "access", "token", "." ]
ba2e5ec50076dce693dc587965024068f6fb54b4
https://github.com/widop/google-analytics/blob/ba2e5ec50076dce693dc587965024068f6fb54b4/src/Widop/GoogleAnalytics/Client.php#L170-L190
train
widop/google-analytics
src/Widop/GoogleAnalytics/Client.php
Client.generateJsonWebToken
protected function generateJsonWebToken() { $exp = new \DateTime('+1 hours'); $iat = new \DateTime(); $jwtHeader = base64_encode(json_encode(array('alg' => 'RS256', 'typ' => 'JWT'))); $jwtClaimSet = base64_encode( json_encode( array( 'iss' => $this->clientId, 'scope' => self::SCOPE, 'aud' => $this->url, 'exp' => $exp->getTimestamp(), 'iat' => $iat->getTimestamp(), ) ) ); $jwtSignature = base64_encode($this->generateSignature($jwtHeader.'.'.$jwtClaimSet)); return sprintf('%s.%s.%s', $jwtHeader, $jwtClaimSet, $jwtSignature); }
php
protected function generateJsonWebToken() { $exp = new \DateTime('+1 hours'); $iat = new \DateTime(); $jwtHeader = base64_encode(json_encode(array('alg' => 'RS256', 'typ' => 'JWT'))); $jwtClaimSet = base64_encode( json_encode( array( 'iss' => $this->clientId, 'scope' => self::SCOPE, 'aud' => $this->url, 'exp' => $exp->getTimestamp(), 'iat' => $iat->getTimestamp(), ) ) ); $jwtSignature = base64_encode($this->generateSignature($jwtHeader.'.'.$jwtClaimSet)); return sprintf('%s.%s.%s', $jwtHeader, $jwtClaimSet, $jwtSignature); }
[ "protected", "function", "generateJsonWebToken", "(", ")", "{", "$", "exp", "=", "new", "\\", "DateTime", "(", "'+1 hours'", ")", ";", "$", "iat", "=", "new", "\\", "DateTime", "(", ")", ";", "$", "jwtHeader", "=", "base64_encode", "(", "json_encode", "(...
Generates the JWT in order to get the access token. @return string The Json Web Token (JWT).
[ "Generates", "the", "JWT", "in", "order", "to", "get", "the", "access", "token", "." ]
ba2e5ec50076dce693dc587965024068f6fb54b4
https://github.com/widop/google-analytics/blob/ba2e5ec50076dce693dc587965024068f6fb54b4/src/Widop/GoogleAnalytics/Client.php#L197-L219
train
widop/google-analytics
src/Widop/GoogleAnalytics/Client.php
Client.generateSignature
protected function generateSignature($jsonWebToken) { if (!function_exists('openssl_x509_read')) { throw GoogleAnalyticsException::invalidOpenSslExtension(); } $certificate = file_get_contents($this->privateKeyFile); $certificates = array(); if (!openssl_pkcs12_read($certificate, $certificates, 'notasecret')) { throw GoogleAnalyticsException::invalidPKCS12File(); } if (!isset($certificates['pkey']) || !$certificates['pkey']) { throw GoogleAnalyticsException::invalidPKCS12Format(); } $ressource = openssl_pkey_get_private($certificates['pkey']); if (!$ressource) { throw GoogleAnalyticsException::invalidPKCS12PKey(); } $signature = null; if (!openssl_sign($jsonWebToken, $signature, $ressource, 'sha256')) { throw GoogleAnalyticsException::invalidPKCS12Signature(); } openssl_pkey_free($ressource); return $signature; }
php
protected function generateSignature($jsonWebToken) { if (!function_exists('openssl_x509_read')) { throw GoogleAnalyticsException::invalidOpenSslExtension(); } $certificate = file_get_contents($this->privateKeyFile); $certificates = array(); if (!openssl_pkcs12_read($certificate, $certificates, 'notasecret')) { throw GoogleAnalyticsException::invalidPKCS12File(); } if (!isset($certificates['pkey']) || !$certificates['pkey']) { throw GoogleAnalyticsException::invalidPKCS12Format(); } $ressource = openssl_pkey_get_private($certificates['pkey']); if (!$ressource) { throw GoogleAnalyticsException::invalidPKCS12PKey(); } $signature = null; if (!openssl_sign($jsonWebToken, $signature, $ressource, 'sha256')) { throw GoogleAnalyticsException::invalidPKCS12Signature(); } openssl_pkey_free($ressource); return $signature; }
[ "protected", "function", "generateSignature", "(", "$", "jsonWebToken", ")", "{", "if", "(", "!", "function_exists", "(", "'openssl_x509_read'", ")", ")", "{", "throw", "GoogleAnalyticsException", "::", "invalidOpenSslExtension", "(", ")", ";", "}", "$", "certific...
Generates the JWT signature according to the private key file and the JWT content. @param string $jsonWebToken The JWT content. @throws \Widop\GoogleAnalytics\Exception\GoogleAnalyticsException If an error occured when generating the signature. @return string The JWT signature.
[ "Generates", "the", "JWT", "signature", "according", "to", "the", "private", "key", "file", "and", "the", "JWT", "content", "." ]
ba2e5ec50076dce693dc587965024068f6fb54b4
https://github.com/widop/google-analytics/blob/ba2e5ec50076dce693dc587965024068f6fb54b4/src/Widop/GoogleAnalytics/Client.php#L230-L261
train
widop/google-analytics
src/Widop/GoogleAnalytics/Service.php
Service.query
public function query(Query $query) { $accessToken = $this->getClient()->getAccessToken(); $uri = $query->build($accessToken); $content = $this->getClient()->getHttpAdapter()->getContent($uri); $json = json_decode($content, true); if (!is_array($json) || isset($json['error'])) { throw GoogleAnalyticsException::invalidQuery(isset($json['error']) ? $json['error']['message'] : 'Invalid json'); } return new Response($json); }
php
public function query(Query $query) { $accessToken = $this->getClient()->getAccessToken(); $uri = $query->build($accessToken); $content = $this->getClient()->getHttpAdapter()->getContent($uri); $json = json_decode($content, true); if (!is_array($json) || isset($json['error'])) { throw GoogleAnalyticsException::invalidQuery(isset($json['error']) ? $json['error']['message'] : 'Invalid json'); } return new Response($json); }
[ "public", "function", "query", "(", "Query", "$", "query", ")", "{", "$", "accessToken", "=", "$", "this", "->", "getClient", "(", ")", "->", "getAccessToken", "(", ")", ";", "$", "uri", "=", "$", "query", "->", "build", "(", "$", "accessToken", ")",...
Queries the google analytics service. @param \Widop\GoogleAnalytics\Query $query The google analytics query. @throws \Widop\GoogleAnalytics\GoogleAnalyticsException If an error occured when querying the google analytics service. @return \Widop\GoogleAnalytics\Response The google analytics response.
[ "Queries", "the", "google", "analytics", "service", "." ]
ba2e5ec50076dce693dc587965024068f6fb54b4
https://github.com/widop/google-analytics/blob/ba2e5ec50076dce693dc587965024068f6fb54b4/src/Widop/GoogleAnalytics/Service.php#L67-L79
train
XeroAPI/XeroOAuth-PHP
lib/XeroOAuth.php
XeroOAuth.extract_params
function extract_params($body) { $kvs = explode ( '&', $body ); $decoded = array (); foreach ( $kvs as $kv ) { $kv = explode ( '=', $kv, 2 ); $kv [0] = $this->safe_decode ( $kv [0] ); $kv [1] = $this->safe_decode ( $kv [1] ); $decoded [$kv [0]] = $kv [1]; } return $decoded; }
php
function extract_params($body) { $kvs = explode ( '&', $body ); $decoded = array (); foreach ( $kvs as $kv ) { $kv = explode ( '=', $kv, 2 ); $kv [0] = $this->safe_decode ( $kv [0] ); $kv [1] = $this->safe_decode ( $kv [1] ); $decoded [$kv [0]] = $kv [1]; } return $decoded; }
[ "function", "extract_params", "(", "$", "body", ")", "{", "$", "kvs", "=", "explode", "(", "'&'", ",", "$", "body", ")", ";", "$", "decoded", "=", "array", "(", ")", ";", "foreach", "(", "$", "kvs", "as", "$", "kv", ")", "{", "$", "kv", "=", ...
Extracts and decodes OAuth parameters from the passed string @param string $body the response body from an OAuth flow method @return array the response body safely decoded to an array of key => values
[ "Extracts", "and", "decodes", "OAuth", "parameters", "from", "the", "passed", "string" ]
e15c78405cc9661984871a35122a6c3990dac384
https://github.com/XeroAPI/XeroOAuth-PHP/blob/e15c78405cc9661984871a35122a6c3990dac384/lib/XeroOAuth.php#L158-L168
train
XeroAPI/XeroOAuth-PHP
lib/XeroOAuth.php
XeroOAuth.refreshToken
function refreshToken($accessToken, $sessionHandle) { $code = $this->request ( 'GET', $this->url ( 'AccessToken', '' ), array ( 'oauth_token' => $accessToken, 'oauth_session_handle' => $sessionHandle ) ); if ($this->response ['code'] == 200) { $response = $this->extract_params ( $this->response ['response'] ); return $response; } else { $this->response ['helper'] = "TokenFatal"; return $this->response; } }
php
function refreshToken($accessToken, $sessionHandle) { $code = $this->request ( 'GET', $this->url ( 'AccessToken', '' ), array ( 'oauth_token' => $accessToken, 'oauth_session_handle' => $sessionHandle ) ); if ($this->response ['code'] == 200) { $response = $this->extract_params ( $this->response ['response'] ); return $response; } else { $this->response ['helper'] = "TokenFatal"; return $this->response; } }
[ "function", "refreshToken", "(", "$", "accessToken", ",", "$", "sessionHandle", ")", "{", "$", "code", "=", "$", "this", "->", "request", "(", "'GET'", ",", "$", "this", "->", "url", "(", "'AccessToken'", ",", "''", ")", ",", "array", "(", "'oauth_toke...
Refreshes the access token for partner API type applications @param string $accessToken the current access token for the session @param string $sessionHandle the current session handle for the session @return array response array from request
[ "Refreshes", "the", "access", "token", "for", "partner", "API", "type", "applications" ]
e15c78405cc9661984871a35122a6c3990dac384
https://github.com/XeroAPI/XeroOAuth-PHP/blob/e15c78405cc9661984871a35122a6c3990dac384/lib/XeroOAuth.php#L544-L558
train
thephpleague/json-guard
src/Assert.php
Assert.notEmpty
public static function notEmpty(array $value, $keyword, $pointer) { if (!empty($value)) { return; } throw InvalidSchemaException::emptyArray($keyword, $pointer); }
php
public static function notEmpty(array $value, $keyword, $pointer) { if (!empty($value)) { return; } throw InvalidSchemaException::emptyArray($keyword, $pointer); }
[ "public", "static", "function", "notEmpty", "(", "array", "$", "value", ",", "$", "keyword", ",", "$", "pointer", ")", "{", "if", "(", "!", "empty", "(", "$", "value", ")", ")", "{", "return", ";", "}", "throw", "InvalidSchemaException", "::", "emptyAr...
Validate an array has at least one element. @param array $value @param string $keyword @param string $pointer
[ "Validate", "an", "array", "has", "at", "least", "one", "element", "." ]
d03dad6288f3b044f83edaaa3a1adcf71f8c757b
https://github.com/thephpleague/json-guard/blob/d03dad6288f3b044f83edaaa3a1adcf71f8c757b/src/Assert.php#L19-L26
train
thephpleague/json-guard
src/Assert.php
Assert.nonNegative
public static function nonNegative($value, $keyword, $pointer) { if ($value >= 0) { return; } throw InvalidSchemaException::negativeValue( $value, $keyword, $pointer ); }
php
public static function nonNegative($value, $keyword, $pointer) { if ($value >= 0) { return; } throw InvalidSchemaException::negativeValue( $value, $keyword, $pointer ); }
[ "public", "static", "function", "nonNegative", "(", "$", "value", ",", "$", "keyword", ",", "$", "pointer", ")", "{", "if", "(", "$", "value", ">=", "0", ")", "{", "return", ";", "}", "throw", "InvalidSchemaException", "::", "negativeValue", "(", "$", ...
Validate an integer is non-negative. @param integer $value @param string $keyword @param string $pointer
[ "Validate", "an", "integer", "is", "non", "-", "negative", "." ]
d03dad6288f3b044f83edaaa3a1adcf71f8c757b
https://github.com/thephpleague/json-guard/blob/d03dad6288f3b044f83edaaa3a1adcf71f8c757b/src/Assert.php#L35-L46
train
thephpleague/json-guard
src/Assert.php
Assert.type
public static function type($value, $choices, $keyword, $pointer) { $actualType = gettype($value); $choices = is_array($choices) ? $choices : [$choices]; if (in_array($actualType, $choices) || (is_json_number($value) && in_array('number', $choices))) { return; } throw InvalidSchemaException::invalidParameterType( $actualType, $choices, $keyword, $pointer ); }
php
public static function type($value, $choices, $keyword, $pointer) { $actualType = gettype($value); $choices = is_array($choices) ? $choices : [$choices]; if (in_array($actualType, $choices) || (is_json_number($value) && in_array('number', $choices))) { return; } throw InvalidSchemaException::invalidParameterType( $actualType, $choices, $keyword, $pointer ); }
[ "public", "static", "function", "type", "(", "$", "value", ",", "$", "choices", ",", "$", "keyword", ",", "$", "pointer", ")", "{", "$", "actualType", "=", "gettype", "(", "$", "value", ")", ";", "$", "choices", "=", "is_array", "(", "$", "choices", ...
Validate a value is one of the allowed types. @param mixed $value @param array|string $choices @param string $keyword @param string $pointer @throws InvalidSchemaException
[ "Validate", "a", "value", "is", "one", "of", "the", "allowed", "types", "." ]
d03dad6288f3b044f83edaaa3a1adcf71f8c757b
https://github.com/thephpleague/json-guard/blob/d03dad6288f3b044f83edaaa3a1adcf71f8c757b/src/Assert.php#L58-L74
train
thephpleague/json-guard
src/Validator.php
Validator.makeSubSchemaValidator
public function makeSubSchemaValidator($data, $schema, $dataPath = null, $schemaPath = null) { $validator = new Validator($data, $schema, $this->ruleSet); $validator->dataPath = $dataPath ?: $this->dataPath; $validator->baseSchemaPath = $schemaPath ?: $this->getSchemaPath(); $validator->maxDepth = $this->maxDepth; $validator->depth = $this->depth + 1; return $validator; }
php
public function makeSubSchemaValidator($data, $schema, $dataPath = null, $schemaPath = null) { $validator = new Validator($data, $schema, $this->ruleSet); $validator->dataPath = $dataPath ?: $this->dataPath; $validator->baseSchemaPath = $schemaPath ?: $this->getSchemaPath(); $validator->maxDepth = $this->maxDepth; $validator->depth = $this->depth + 1; return $validator; }
[ "public", "function", "makeSubSchemaValidator", "(", "$", "data", ",", "$", "schema", ",", "$", "dataPath", "=", "null", ",", "$", "schemaPath", "=", "null", ")", "{", "$", "validator", "=", "new", "Validator", "(", "$", "data", ",", "$", "schema", ","...
Create a new sub-validator. @param mixed $data @param object $schema @param string|null $dataPath @param string|null $schemaPath @return Validator
[ "Create", "a", "new", "sub", "-", "validator", "." ]
d03dad6288f3b044f83edaaa3a1adcf71f8c757b
https://github.com/thephpleague/json-guard/blob/d03dad6288f3b044f83edaaa3a1adcf71f8c757b/src/Validator.php#L212-L222
train