code
stringlengths
52
7.75k
docs
stringlengths
1
5.85k
public function getPropertyRules($property) { if (! isset($this->filteredProperties[$property])) { return null; } return $this->filteredProperties[$property]['rules']; }
{@inheritDoc}
public function mergeRules(ClassMetadataInterface $metadata) { foreach ($metadata->getFilteredProperties() as $property) { foreach ($metadata->getPropertyRules($property) as $rule) { $this->addPropertyRule($property, clone $rule); } } }
{@inheritDoc}
public function addPropertyRule($property, Rule $rule) { if (!isset($this->filteredProperties[$property])) { $this->filteredProperties[$property] = array('rules' => array()); } $this->filteredProperties[$property]['rules'][] = $rule; }
{@inheritDoc}
protected function renderDataCellContent($row, $data) { if (!Yii::app()->user->isAdmin) { echo TbHtml::linkButton( TbHtml::icon(TbHtml::ICON_EYE_OPEN), array( 'color' => TbHtml::BUTTON_COLOR_LINK, 'size' => TbHtml::BUTTON_SIZE_MINI, 'url' => array('view', 'id' => $data->{$this->idColumn}), 'htmlOptions' => array('rel' => 'tooltip', 'title' => Yii::t('AuthModule.main', 'View')), ) ); } }
Renders the data cell content. @param integer $row the row number (zero-based). @param mixed $data the data associated with the row.
public function apply(Rule $rule, $value) { if ($this->useEncoding($rule)) { return mb_strtolower((string) $value, $rule->encoding); } return strtolower((string) $value); }
{@inheritDoc} @param \DMS\Filter\Rules\ToLower $rule
public function useEncoding($rule) { if ($rule->encoding === null) { return false; } if (! function_exists('mb_strtolower')) { throw new FilterException('mbstring is required to use ToLower with an encoding.'); } $encodings = array_map('strtolower', mb_list_encodings()); if (!in_array(strtolower($rule->encoding), $encodings)) { throw new FilterException( "mbstring does not support the '".$rule->encoding."' encoding" ); } return true; }
Verify is encoding is set and if we have the proper function to use it @param \DMS\Filter\Rules\ToLower $rule @throws \DMS\Filter\Exception\FilterException @return boolean
public function apply(Rule $rule, $value) { return preg_replace($rule->regexp, $rule->replacement, $value); }
{@inheritDoc}
public function init() { parent::init(); $this->layout = $this->module->defaultLayout; $this->menu = $this->getSubMenu(); }
Initializes the controller.
public function getItemTypeText($type, $plural = false) { // todo: change the default value for $plural to false. $n = $plural ? 2 : 1; switch ($type) { case CAuthItem::TYPE_OPERATION: $name = Yii::t('AuthModule.main', 'operation|operations', $n); break; case CAuthItem::TYPE_TASK: $name = Yii::t('AuthModule.main', 'task|tasks', $n); break; case CAuthItem::TYPE_ROLE: $name = Yii::t('AuthModule.main', 'role|roles', $n); break; default: throw new CException('Auth item type "' . $type . '" is valid.'); } return $name; }
Returns the authorization item type as a string. @param string $type the item type (0=operation, 1=task, 2=role). @param boolean $plural whether to return the name in plural. @return string the text. @throws CException if the item type is invalid.
public function getItemControllerId($type) { $controllerId = null; switch ($type) { case CAuthItem::TYPE_OPERATION: $controllerId = 'operation'; break; case CAuthItem::TYPE_TASK: $controllerId = 'task'; break; case CAuthItem::TYPE_ROLE: $controllerId = 'role'; break; default: throw new CException('Auth item type "' . $type . '" is valid.'); } return $controllerId; }
Returns the controllerId for the given authorization item. @param string $type the item type (0=operation, 1=task, 2=role). @return string the controllerId. @throws CException if the item type is invalid.
public function capitalize($string) { if (!extension_loaded('mbstring')) { return ucfirst($string); } $encoding = Yii::app()->charset; $firstChar = mb_strtoupper(mb_substr($string, 0, 1, $encoding), $encoding); return $firstChar . mb_substr($string, 1, mb_strlen($string, $encoding) - 1, $encoding); }
Capitalizes the first word in the given string. @param string $string the string to capitalize. @return string the capitalized string. @see http://stackoverflow.com/questions/2517947/ucfirst-function-for-multibyte-character-encodings
protected function getSubMenu() { return array( array( 'label' => Yii::t('AuthModule.main', 'Assignments'), 'url' => array('/auth/assignment/index'), 'active' => $this instanceof AssignmentController, ), array( 'label' => $this->capitalize($this->getItemTypeText(CAuthItem::TYPE_ROLE, true)), 'url' => array('/auth/role/index'), 'active' => $this instanceof RoleController, ), array( 'label' => $this->capitalize($this->getItemTypeText(CAuthItem::TYPE_TASK, true)), 'url' => array('/auth/task/index'), 'active' => $this instanceof TaskController, ), array( 'label' => $this->capitalize($this->getItemTypeText(CAuthItem::TYPE_OPERATION, true)), 'url' => array('/auth/operation/index'), 'active' => $this instanceof OperationController, ), ); }
Returns the sub menu configuration. @return array the configuration.
protected function setDefaults() { parent::setDefaults(); $this->setReferenceNumberLeftAttr(3, 60, 50, 4, null, null, 8); $this->setReferenceNumberRightAttr(125, 33.5, 80, 4); $this->setCodeLineAttr(64, 85, 140, 4, null, 'OCRB10'); $this->setSlipBackground(__DIR__.'/Resources/img/ezs_orange.gif'); return $this; }
Sets the default attributes of the elements for an orange slip @return $this The current instance for a fluent interface.
public function setReferenceNumberLeftAttr( $posX = null, $posY = null, $width = null, $height = null, $background = null, $fontFamily = null, $fontSize = null, $fontColor = null, $lineHeight = null, $textAlign = null ) { $this->setAttributes( $this->referenceNumberLeftAttr, $posX, $posY, $width, $height, $background, $fontFamily, $fontSize, $fontColor, $lineHeight, $textAlign ); return $this; }
Set the left reference number attributes @param float|null $posX The X position. @param float|null $posY The Y Position. @param float|null $width The width. @param float|null $height The height. @param string|null $background The background. @param string|null $fontFamily The font family. @param float|null $fontSize The font size. @param string|null $fontColor The font color. @param float|null $lineHeight The line height. @param string|null $textAlign The text alignment. @return $this The current instance for a fluent interface.
public function setReferenceNumberRightAttr( $posX = null, $posY = null, $width = null, $height = null, $background = null, $fontFamily = null, $fontSize = null, $fontColor = null, $lineHeight = null, $textAlign = null ) { if ($textAlign === null) { $textAlign = 'R'; } $this->setAttributes( $this->referenceNumberRightAttr, $posX, $posY, $width, $height, $background, $fontFamily, $fontSize, $fontColor, $lineHeight, $textAlign ); return $this; }
Set the right reference number attributes @param float|null $posX The X position. @param float|null $posY The Y Position. @param float|null $width The width. @param float|null $height The height. @param string|null $background The background. @param string|null $fontFamily The font family. @param float|null $fontSize The font size. @param string|null $fontColor The font color. @param float|null $lineHeight The line height. @param string|null $textAlign The text alignment. @return $this The current instance for a fluent interface.
public function setCodeLineAttr( $posX = null, $posY = null, $width = null, $height = null, $background = null, $fontFamily = null, $fontSize = null, $fontColor = null, $lineHeight = null, $textAlign = null ) { if ($textAlign === null) { $textAlign = 'R'; } $this->setAttributes( $this->codeLineAttr, $posX, $posY, $width, $height, $background, $fontFamily, $fontSize, $fontColor, $lineHeight, $textAlign ); return $this; }
Set the code line attributes @param float|null $posX The X position. @param float|null $posY The Y Position. @param float|null $width The width. @param float|null $height The height. @param string|null $background The background. @param string|null $fontFamily The font family. @param float|null $fontSize The font size. @param string|null $fontColor The font color. @param float|null $lineHeight The line height. @param string|null $textAlign The text alignment. @return $this The current instance for a fluent interface.
public function setDisplayReferenceNr($displayReferenceNr = true) { $this->isBool($displayReferenceNr, 'displayReferenceNr'); $this->displayReferenceNr = $displayReferenceNr; return $this; }
Set whether or not to display the reference number @param bool $displayReferenceNr True if yes, false if no @return $this The current instance for a fluent interface.
public function setDisplayCodeLine($displayCodeLine = true) { $this->isBool($displayCodeLine, 'displayCodeLine'); $this->displayCodeLine = $displayCodeLine; return $this; }
Set whether or not to display the code line at the bottom @param bool $displayCodeLine True if yes, false if no @return $this The current instance for a fluent interface.
public function getDisplayCodeLine() { if ($this->getPaymentSlipData()->getWithAccountNumber() !== true || $this->getPaymentSlipData()->getWithReferenceNumber() !== true ) { return false; } return $this->displayCodeLine; }
Get whether or not to display the code line at the bottom Overwrites the parent method as it checks additional settings. @return bool True if yes, false if no.
public function getAllElements() { $paymentSlipData = $this->paymentSlipData; $formatted = $this->getReferenceNrFormatted(); $fillZeros = $this->getReferenceNrFillZeros(); $elements = parent::getAllElements(); // Place left reference number if ($this->getDisplayReferenceNr()) { $lines = [ $paymentSlipData->getCompleteReferenceNumber( $formatted, $fillZeros ) ]; $elements['referenceNumberLeft'] = [ 'lines' => $lines, 'attributes' => $this->getReferenceNumberLeftAttr() ]; // Place right reference number // Reuse lines from above $elements['referenceNumberRight'] = [ 'lines' => $lines, 'attributes' => $this->getReferenceNumberRightAttr() ]; } // Place code line if ($this->getDisplayCodeLine()) { $lines = [ $paymentSlipData->getCodeLine($fillZeros)]; $elements['codeLine'] = [ 'lines' => $lines, 'attributes' => $this->getCodeLineAttr() ]; } return $elements; }
Get all elements of the slip @return array All elements with their lines and attributes.
public static function parse(array $parameters) { if (base64_decode($parameters[self::PARAMETER_REQUEST], true) === false) { throw new InvalidRequestException('Failed decoding SAML request, did not receive a valid base64 string'); } $parsed = new self($parameters[self::PARAMETER_REQUEST]); if (isset($parameters[self::PARAMETER_RELAY_STATE])) { $parsed->relayState = $parameters[self::PARAMETER_RELAY_STATE]; } $decoded = $parsed->getDecodedSamlRequest(); $request = ReceivedAuthnRequest::from($decoded); $parsed->receivedRequest = $request; // Return AuthnRequest return $parsed; }
@param array $parameters @return ReceivedAuthnRequestPost @SuppressWarnings(PHPMD.CyclomaticComplexity) Extensive validation @SuppressWarnings(PHPMD.NPathComplexity) Extensive validation
public function getFilterForRule(Rule $rule) { $filterIdentifier = $rule->getFilter(); if (class_exists($filterIdentifier)) { return new $filterIdentifier; } $error = "Unable to locate filter for: $filterIdentifier defined in " . get_class($rule); throw new \UnexpectedValueException($error); }
Finds the filter responsible for executing a specific rule @param Rule $rule @throws \UnexpectedValueException If filter can't be located @return BaseFilter
public function actionView($id) { $formModel = new AddAuthItemForm(); /* @var $am CAuthManager|AuthBehavior */ $am = Yii::app()->getAuthManager(); if (isset($_POST['AddAuthItemForm'])) { $formModel->attributes = $_POST['AddAuthItemForm']; if ($formModel->validate()) { if (!$am->isAssigned($formModel->items, $id)) { $am->assign($formModel->items, $id); if ($am instanceof CPhpAuthManager) { $am->save(); } if ($am instanceof ICachedAuthManager) { $am->flushAccess($formModel->items, $id); } } } } $model = CActiveRecord::model($this->module->userClass)->findByPk($id); $assignments = $am->getAuthAssignments($id); $authItems = $am->getItemsPermissions(array_keys($assignments)); $authItemDp = new AuthItemDataProvider(); $authItemDp->setAuthItems($authItems); $assignmentOptions = $this->getAssignmentOptions($id); if (!empty($assignmentOptions)) { $assignmentOptions = array_merge( array('' => Yii::t('AuthModule.main', 'Select item') . ' ...'), $assignmentOptions ); } $this->render( 'view', array( 'model' => $model, 'authItemDp' => $authItemDp, 'formModel' => $formModel, 'assignmentOptions' => $assignmentOptions, ) ); }
Displays the assignments for the user with the given id. @param string $id the user id.
public function actionRevoke() { if (isset($_GET['itemName'], $_GET['userId'])) { $itemName = $_GET['itemName']; $userId = $_GET['userId']; /* @var $am CAuthManager|AuthBehavior */ $am = Yii::app()->getAuthManager(); if ($am->isAssigned($itemName, $userId)) { $am->revoke($itemName, $userId); if ($am instanceof CPhpAuthManager) { $am->save(); } if ($am instanceof ICachedAuthManager) { $am->flushAccess($itemName, $userId); } } if (!isset($_POST['ajax'])) { $this->redirect(array('view', 'id' => $userId)); } } else { throw new CHttpException(400, Yii::t('AuthModule.main', 'Invalid request.')); } }
Revokes an assignment from the given user. @throws CHttpException if the request is invalid.
protected function getAssignmentOptions($userId) { $options = array(); /* @var $am CAuthManager|AuthBehavior */ $am = Yii::app()->authManager; $assignments = $am->getAuthAssignments($userId); $assignedItems = array_keys($assignments); /* @var $authItems CAuthItem[] */ $authItems = $am->getAuthItems(); foreach ($authItems as $itemName => $item) { if (!in_array($itemName, $assignedItems)) { $options[$this->capitalize($this->getItemTypeText($item->type, true))][$itemName] = $item->description; } } return $options; }
Returns a list of possible assignments for the user with the given id. @param string $userId the user id. @return array the assignment options.
protected function renderDataCellContent($row, $data) { echo CHtml::link(CHtml::value($data, $this->nameColumn), array('view', 'id' => $data->{$this->idColumn})); }
Renders the data cell content. @param integer $row the row number (zero-based). @param mixed $data the data associated with the row.
private function parseOptions($options) { $parseResult = new \stdClass(); $parseResult->invalidOptions = array(); $parseResult->missingOptions = array_flip((array)$this->getRequiredOptions()); //Doctrine parses constructor parameter into 'value' array param, restore it if (is_array($options) && count($options) == 1 && isset($options['value'])) { $options = $options['value']; } //Parse Option Array if (is_array($options) && count($options) > 0 && is_string(key($options))) { $this->parseOptionsArray($options, $parseResult); return $parseResult; } //Parse Single Value if (null !== $options && ! (is_array($options) && count($options) === 0)) { $this->parseSingleOption($options, $parseResult); return $parseResult; } return $parseResult; }
Parses provided options into their properties and returns results for the parsing process @param mixed $options @return \stdClass
private function parseOptionsArray($options, \stdClass $result) { foreach ($options as $option => $value) { if (! property_exists($this, $option)) { $result->invalidOptions[] = $option; continue; } //Define Option $this->$option = $value; unset($result->missingOptions[$option]); } }
Parses Options in the array format @param array $options @param \stdClass $result
private function parseSingleOption($options, \stdClass $result) { $option = $this->getDefaultOption(); //No Default set, unsure what to do if (null === $option) { throw new RuleDefinitionException( sprintf('No default option is configured for rule %s', get_class($this)) ); } //Default option points to invalid one if (! property_exists($this, $option)) { $result->invalidOptions[] = $option; return; } //Define Option $this->$option = $options; unset($result->missingOptions[$option]); }
Parses single option received @param string $options @param \stdClass $result @throws \DMS\Filter\Exception\RuleDefinitionException
private function readProperty(ReflectionProperty $property, ClassMetadataInterface $metadata) { // Skip if this property is not from this class if ($property->getDeclaringClass()->getName() != $metadata->getClassName() ) { return; } //Iterate over all annotations foreach ($this->reader->getPropertyAnnotations($property) as $rule) { //Skip is its not a rule if (! $rule instanceof Rules\Rule) { continue; } //Add Rule $metadata->addPropertyRule($property->getName(), $rule); } }
Reads annotations for a selected property in the class @param ReflectionProperty $property @param ClassMetadataInterface $metadata
public function apply(Rule $rule, $value) { //Build pattern $pattern = ($this->checkUnicodeSupport() && $rule->unicodePattern !== null) ? $rule->unicodePattern : $rule->pattern; return preg_replace($pattern, '', $value); }
{@inheritDoc} @param \DMS\Filter\Rules\RegExp $rule
public function apply(Rule $rule, $value) { return $this->getZendInstance($rule->class, $rule->zendOptions)->filter($value); }
{@inheritDoc} @param ZendRule $rule
public function getZendInstance($class, $options) { if (strpos($class, 'Zend\Filter') === false) { $class = "Zend\Filter\\".$class; } if (! class_exists($class)) { throw new InvalidZendFilterException("Could not find or autoload: $class"); } try { new \ReflectionMethod($class, 'setOptions'); $filter = new $class(); $filter->setOptions($options); return $filter; } catch (\ReflectionException $e) { return new $class($options); } }
Instantiates a configured Zend Filter, if it exists @param string $class @param array $options @return \Zend\Filter\FilterInterface @throws \DMS\Filter\Exception\InvalidZendFilterException
protected function renderDataCellContent($row, $data) { /* @var $am CAuthManager|AuthBehavior */ $am = Yii::app()->getAuthManager(); if ($am->hasParent($this->itemName, $data['name'])) { echo TbHtml::linkButton( TbHtml::icon(TbHtml::ICON_REMOVE), array( 'color' => TbHtml::BUTTON_COLOR_LINK, 'size' => TbHtml::BUTTON_SIZE_MINI, 'url' => array('removeParent', 'itemName' => $this->itemName, 'parentName' => $data['name']), 'rel' => 'tooltip', 'title' => Yii::t('AuthModule.main', 'Remove'), ) ); } else { if ($am->hasChild($this->itemName, $data['name'])) { echo TbHtml::linkButton( TbHtml::icon(TbHtml::ICON_REMOVE), array( 'color' => TbHtml::BUTTON_COLOR_LINK, 'size' => TbHtml::BUTTON_SIZE_MINI, 'url' => array('removeChild', 'itemName' => $this->itemName, 'childName' => $data['name']), 'rel' => 'tooltip', 'title' => Yii::t('AuthModule.main', 'Remove'), ) ); } } }
Renders the data cell content. @param integer $row the row number (zero-based). @param mixed $data the data associated with the row.
protected function setDefaults() { $this->setBankLeftAttr(3, 8, 50, 4); $this->setBankRightAttr(66, 8, 50, 4); $this->setRecipientLeftAttr(3, 23, 50, 4); $this->setRecipientRightAttr(66, 23, 50, 4); $this->setAccountLeftAttr(27, 43, 30, 4); $this->setAccountRightAttr(90, 43, 30, 4); $this->setAmountFrancsLeftAttr(5, 50.5, 35, 4); $this->setAmountFrancsRightAttr(66, 50.5, 35, 4); $this->setAmountCentsLeftAttr(50, 50.5, 6, 4); $this->setAmountCentsRightAttr(111, 50.5, 6, 4); $this->setPayerLeftAttr(3, 65, 50, 4); $this->setPayerRightAttr(125, 48, 50, 4); return $this; }
Sets the common default attributes of the elements @return $this The current instance for a fluent interface.
public function setSlipPosition($slipPosX, $slipPosY) { $this->setSlipPosX($slipPosX); $this->setSlipPosY($slipPosY); return $this; }
Set the starting X & Y position of the slip @param float $slipPosX The starting X position of the slip. @param float $slipPosY The starting Y position of the slip @return $this The current instance for a fluent interface.
public function setSlipSize($slipWidth, $slipHeight) { $this->setSlipHeight($slipHeight); $this->setSlipWidth($slipWidth); return $this; }
Set the height & width of the slip @param float $slipWidth The width of the slip @param float $slipHeight The height of the slip @return $this The current instance for a fluent interface.
public function setBankLeftAttr( $posX = null, $posY = null, $width = null, $height = null, $background = null, $fontFamily = null, $fontSize = null, $fontColor = null, $lineHeight = null, $textAlign = null ) { $this->setAttributes( $this->bankLeftAttr, $posX, $posY, $width, $height, $background, $fontFamily, $fontSize, $fontColor, $lineHeight, $textAlign ); return $this; }
Set the left bank attributes @param float|null $posX The X position. @param float|null $posY The Y Position. @param float|null $width The width. @param float|null $height The height. @param string|null $background The background. @param string|null $fontFamily The font family. @param float|null $fontSize The font size. @param string|null $fontColor The font color. @param float|null $lineHeight The line height. @param string|null $textAlign The text alignment. @return $this The current instance for a fluent interface.
public function setBankRightAttr( $posX = null, $posY = null, $width = null, $height = null, $background = null, $fontFamily = null, $fontSize = null, $fontColor = null, $lineHeight = null, $textAlign = null ) { $this->setAttributes( $this->bankRightAttr, $posX, $posY, $width, $height, $background, $fontFamily, $fontSize, $fontColor, $lineHeight, $textAlign ); return $this; }
Set the right bank attributes @param float|null $posX The X position. @param float|null $posY The Y Position. @param float|null $width The width. @param float|null $height The height. @param string|null $background The background. @param string|null $fontFamily The font family. @param float|null $fontSize The font size. @param string|null $fontColor The font color. @param float|null $lineHeight The line height. @param string|null $textAlign The text alignment. @return $this The current instance for a fluent interface.
public function setRecipientLeftAttr( $posX = null, $posY = null, $width = null, $height = null, $background = null, $fontFamily = null, $fontSize = null, $fontColor = null, $lineHeight = null, $textAlign = null ) { $this->setAttributes( $this->recipientLeftAttr, $posX, $posY, $width, $height, $background, $fontFamily, $fontSize, $fontColor, $lineHeight, $textAlign ); return $this; }
Set the left recipient attributes @param float|null $posX The X position. @param float|null $posY The Y Position. @param float|null $width The width. @param float|null $height The height. @param string|null $background The background. @param string|null $fontFamily The font family. @param float|null $fontSize The font size. @param string|null $fontColor The font color. @param float|null $lineHeight The line height. @param string|null $textAlign The text alignment. @return $this The current instance for a fluent interface.
public function setRecipientRightAttr( $posX = null, $posY = null, $width = null, $height = null, $background = null, $fontFamily = null, $fontSize = null, $fontColor = null, $lineHeight = null, $textAlign = null ) { $this->setAttributes( $this->recipientRightAttr, $posX, $posY, $width, $height, $background, $fontFamily, $fontSize, $fontColor, $lineHeight, $textAlign ); return $this; }
Set the right recipient attributes @param float|null $posX The X position. @param float|null $posY The Y Position. @param float|null $width The width. @param float|null $height The height. @param string|null $background The background. @param string|null $fontFamily The font family. @param float|null $fontSize The font size. @param string|null $fontColor The font color. @param float|null $lineHeight The line height. @param string|null $textAlign The text alignment. @return $this The current instance for a fluent interface.
public function setAccountLeftAttr( $posX = null, $posY = null, $width = null, $height = null, $background = null, $fontFamily = null, $fontSize = null, $fontColor = null, $lineHeight = null, $textAlign = null ) { $this->setAttributes( $this->accountLeftAttr, $posX, $posY, $width, $height, $background, $fontFamily, $fontSize, $fontColor, $lineHeight, $textAlign ); return $this; }
Set the left account attributes @param float|null $posX The X position. @param float|null $posY The Y Position. @param float|null $width The width. @param float|null $height The height. @param string|null $background The background. @param string|null $fontFamily The font family. @param float|null $fontSize The font size. @param string|null $fontColor The font color. @param float|null $lineHeight The line height. @param string|null $textAlign The text alignment. @return $this The current instance for a fluent interface.
public function setAccountRightAttr( $posX = null, $posY = null, $width = null, $height = null, $background = null, $fontFamily = null, $fontSize = null, $fontColor = null, $lineHeight = null, $textAlign = null ) { $this->setAttributes( $this->accountRightAttr, $posX, $posY, $width, $height, $background, $fontFamily, $fontSize, $fontColor, $lineHeight, $textAlign ); return $this; }
Set the right account attributes @param float|null $posX The X position. @param float|null $posY The Y Position. @param float|null $width The width. @param float|null $height The height. @param string|null $background The background. @param string|null $fontFamily The font family. @param float|null $fontSize The font size. @param string|null $fontColor The font color. @param float|null $lineHeight The line height. @param string|null $textAlign The text alignment. @return $this The current instance for a fluent interface.
public function setAmountFrancsLeftAttr( $posX = null, $posY = null, $width = null, $height = null, $background = null, $fontFamily = null, $fontSize = null, $fontColor = null, $lineHeight = null, $textAlign = null ) { if ($textAlign === null) { $textAlign = 'R'; } $this->setAttributes( $this->amountFrancsLeftAttr, $posX, $posY, $width, $height, $background, $fontFamily, $fontSize, $fontColor, $lineHeight, $textAlign ); return $this; }
Set the left francs amount attributes @param float|null $posX The X position. @param float|null $posY The Y Position. @param float|null $width The width. @param float|null $height The height. @param string|null $background The background. @param string|null $fontFamily The font family. @param float|null $fontSize The font size. @param string|null $fontColor The font color. @param float|null $lineHeight The line height. @param string|null $textAlign The text alignment. @return $this The current instance for a fluent interface.
public function setAmountFrancsRightAttr( $posX = null, $posY = null, $width = null, $height = null, $background = null, $fontFamily = null, $fontSize = null, $fontColor = null, $lineHeight = null, $textAlign = null ) { if ($textAlign === null) { $textAlign = 'R'; } $this->setAttributes( $this->amountFrancsRightAttr, $posX, $posY, $width, $height, $background, $fontFamily, $fontSize, $fontColor, $lineHeight, $textAlign ); return $this; }
Set the right francs amount attributes @param float|null $posX The X position. @param float|null $posY The Y Position. @param float|null $width The width. @param float|null $height The height. @param string|null $background The background. @param string|null $fontFamily The font family. @param float|null $fontSize The font size. @param string|null $fontColor The font color. @param float|null $lineHeight The line height. @param string|null $textAlign The text alignment. @return $this The current instance for a fluent interface.
public function setAmountCentsLeftAttr( $posX = null, $posY = null, $width = null, $height = null, $background = null, $fontFamily = null, $fontSize = null, $fontColor = null, $lineHeight = null, $textAlign = null ) { $this->setAttributes( $this->amountCentsLeftAttr, $posX, $posY, $width, $height, $background, $fontFamily, $fontSize, $fontColor, $lineHeight, $textAlign ); return $this; }
Set the left cents amount attributes @param float|null $posX The X position. @param float|null $posY The Y Position. @param float|null $width The width. @param float|null $height The height. @param string|null $background The background. @param string|null $fontFamily The font family. @param float|null $fontSize The font size. @param string|null $fontColor The font color. @param float|null $lineHeight The line height. @param string|null $textAlign The text alignment. @return $this The current instance for a fluent interface.
public function setAmountCentsRightAttr( $posX = null, $posY = null, $width = null, $height = null, $background = null, $fontFamily = null, $fontSize = null, $fontColor = null, $lineHeight = null, $textAlign = null ) { $this->setAttributes( $this->amountCentsRightAttr, $posX, $posY, $width, $height, $background, $fontFamily, $fontSize, $fontColor, $lineHeight, $textAlign ); return $this; }
Set the right cents amount attributes @param float|null $posX The X position. @param float|null $posY The Y Position. @param float|null $width The width. @param float|null $height The height. @param string|null $background The background. @param string|null $fontFamily The font family. @param float|null $fontSize The font size. @param string|null $fontColor The font color. @param float|null $lineHeight The line height. @param string|null $textAlign The text alignment. @return $this The current instance for a fluent interface.
public function setPayerLeftAttr( $posX = null, $posY = null, $width = null, $height = null, $background = null, $fontFamily = null, $fontSize = null, $fontColor = null, $lineHeight = null, $textAlign = null ) { $this->setAttributes( $this->payerLeftAttr, $posX, $posY, $width, $height, $background, $fontFamily, $fontSize, $fontColor, $lineHeight, $textAlign ); return $this; }
Set the left payer attributes @param float|null $posX The X position. @param float|null $posY The Y Position. @param float|null $width The width. @param float|null $height The height. @param string|null $background The background. @param string|null $fontFamily The font family. @param float|null $fontSize The font size. @param string|null $fontColor The font color. @param float|null $lineHeight The line height. @param string|null $textAlign The text alignment. @return $this The current instance for a fluent interface.
public function setPayerRightAttr( $posX = null, $posY = null, $width = null, $height = null, $background = null, $fontFamily = null, $fontSize = null, $fontColor = null, $lineHeight = null, $textAlign = null ) { $this->setAttributes( $this->payerRightAttr, $posX, $posY, $width, $height, $background, $fontFamily, $fontSize, $fontColor, $lineHeight, $textAlign ); return $this; }
Set the right payer attributes @param float|null $posX The X position. @param float|null $posY The Y Position. @param float|null $width The width. @param float|null $height The height. @param string|null $background The background. @param string|null $fontFamily The font family. @param float|null $fontSize The font size. @param string|null $fontColor The font color. @param float|null $lineHeight The line height. @param string|null $textAlign The text alignment. @return $this The current instance for a fluent interface.
public function setDisplayBackground($displayBackground = true) { $this->isBool($displayBackground, 'displayBackground'); $this->displayBackground = $displayBackground; return $this; }
Set whether or not to display the background @param bool $displayBackground True if yes, false if no. @return $this The current instance for a fluent interface..
public function setDisplayAccount($displayAccount = true) { $this->isBool($displayAccount, 'displayAccount'); $this->displayAccount = $displayAccount; return $this; }
Set whether or not to display the account @param bool $displayAccount True if yes, false if no. @return $this The current instance for a fluent interface..
public function setDisplayAmount($displayAmount = true) { $this->isBool($displayAmount, 'displayAmount'); $this->displayAmount = $displayAmount; return $this; }
Set whether or not to display the amount @param bool $displayAmount True if yes, false if no @return $this The current instance for a fluent interface.
public function setDisplayBank($displayBank = true) { $this->isBool($displayBank, 'displayBank'); $this->displayBank = $displayBank; return $this; }
Set whether or not to display the bank @param bool $displayBank True if yes, false if no @return $this The current instance for a fluent interface.
public function setDisplayPayer($displayPayer = true) { $this->isBool($displayPayer, 'displayPayer'); $this->displayPayer = $displayPayer; return $this; }
Set whether or not to display the payer @param bool $displayPayer True if yes, false if no @return $this The current instance for a fluent interface.
public function setDisplayRecipient($displayRecipient = true) { $this->isBool($displayRecipient, 'displayRecipient'); $this->displayRecipient = $displayRecipient; return $this; }
Set whether or not to display the recipient @param bool $displayRecipient True if yes, false if no @return $this The current instance for a fluent interface.
protected function isIntOrFloat($parameter, $varName) { if ((!is_int($parameter) && !is_float($parameter))) { throw new InvalidArgumentException( sprintf( '$%s is neither an integer nor a float.', $varName ) ); } }
Verify that a given parameter is an integer or a float @param mixed $parameter The given parameter to validate. @param string $varName The name of the variable. @return true If the parameter is either an integer or a float. @throws InvalidArgumentException If the parameter is neither an integer nor a float.
public function setWithBank($withBank = true) { $this->isBool($withBank, 'withBank'); $this->withBank = $withBank; if ($withBank === false) { $this->bankName = ''; $this->bankCity = ''; } return $this; }
Set if payment slip has a bank specified Resets the bank data when disabling. @param bool $withBank True for yes, false for no @return $this The current instance for a fluent interface.
public function setWithAccountNumber($withAccountNumber = true) { $this->isBool($withAccountNumber, 'withAccountNumber'); $this->withAccountNumber = $withAccountNumber; if ($withAccountNumber === false) { $this->accountNumber = ''; } return $this; }
Set if payment slip has an account number specified Resets the account number when disabling. @param bool $withAccountNumber True if yes, false if no. @return $this The current instance for a fluent interface.
public function setWithRecipient($withRecipient = true) { $this->isBool($withRecipient, 'withRecipient'); $this->withRecipient = $withRecipient; if ($withRecipient === false) { $this->recipientLine1 = ''; $this->recipientLine2 = ''; $this->recipientLine3 = ''; $this->recipientLine4 = ''; } return $this; }
Set if payment slip has a recipient specified Resets the recipient data when disabling. @param bool $withRecipient True if yes, false if no. @return $this The current instance for a fluent interface.
public function setWithAmount($withAmount = true) { $this->isBool($withAmount, 'withAmount'); $this->withAmount = $withAmount; if ($withAmount === false) { $this->amount = 0.0; } return $this; }
Set if payment slip has an amount specified Resets the amount when disabling. @param bool $withAmount True for yes, false for no. @return $this The current instance for a fluent interface.
public function setWithPayer($withPayer = true) { $this->isBool($withPayer, 'withPayer'); $this->withPayer = $withPayer; if ($withPayer === false) { $this->payerLine1 = ''; $this->payerLine2 = ''; $this->payerLine3 = ''; $this->payerLine4 = ''; } return $this; }
Set if payment slip has a payer specified Resets the payer data when disabling. @param bool $withPayer True if yes, false if no. @return $this The current instance for a fluent interface.
public function setBankData($bankName, $bankCity) { $this->setBankName($bankName); $this->setBankCity($bankCity); return $this; }
Sets the name, city and account number of the bank @param string $bankName Name of the bank. @param string $bankCity City of the bank. @return $this The current instance for a fluent interface.
public function setRecipientData($recipientLine1, $recipientLine2, $recipientLine3 = '', $recipientLine4 = '') { $this->setRecipientLine1($recipientLine1); $this->setRecipientLine2($recipientLine2); $this->setRecipientLine3($recipientLine3); $this->setRecipientLine4($recipientLine4); return $this; }
Sets the four lines of the recipient @param string $recipientLine1 The first line of the recipient, e.g. "My Company Ltd.". @param string $recipientLine2 The second line of the recipient, e.g. "Examplestreet 61". @param string $recipientLine3 The third line of the recipient, e.g. "8000 Zürich". @param string $recipientLine4 The fourth line of the recipient, if needed. @return $this The current instance for a fluent interface.
public function setPayerData($payerLine1, $payerLine2, $payerLine3 = '', $payerLine4 = '') { $this->setPayerLine1($payerLine1); $this->setPayerLine2($payerLine2); $this->setPayerLine3($payerLine3); $this->setPayerLine4($payerLine4); return $this; }
Sets the four lines of the payer At least two lines are necessary. @param string $payerLine1 The first line of the payer, e.g. "Hans Mustermann". @param string $payerLine2 The second line of the payer, e.g. "Main Street 11". @param string $payerLine3 The third line of the payer, e.g. "4052 Basel". @param string $payerLine4 The fourth line of the payer, if needed. @return $this The current instance for a fluent interface.
protected function getAccountDigits() { if (!$this->getWithAccountNumber()) { throw new DisabledDataException('account number'); } if ($this->getNotForPayment()) { return 'XXXXXXXXX'; } $accountNumber = $this->getAccountNumber(); if ($accountNumber === '') { return $accountNumber; } $accountDigits = str_replace('-', '', $accountNumber, $replacedHyphens); if ($replacedHyphens != 2) { throw new PaymentSlipException('Invalid Account number. Does not contain two hyphens.'); } return $accountDigits; }
Clear the account of the two hyphens @return string The account of the two hyphens, 'XXXXXXXXX' if not for payment or else false. @throws DisabledDataException If the data is disabled. @throws PaymentSlipException If account number does not contain two hyphens. @todo Cover the edge cases with tests
public function getAmountFrancs() { if ($this->getNotForPayment()) { return 'XXXXXXXX'; } $amount = $this->getAmount(); $francs = intval($amount); return $francs; }
Get the francs amount without cents @return bool|int Francs amount without cents.
public function getAmountCents() { if ($this->getNotForPayment()) { return 'XX'; } $amount = $this->getAmount(); $francs = intval($amount); $cents = round(($amount - $francs) * 100); return str_pad($cents, 2, '0', STR_PAD_LEFT); }
Get the zero filled, right padded, two digits long cents amount @return bool|string Amount of Cents, zero filled, right padded, two digits long.
public function setNotForPayment($notForPayment = true) { $this->notForPayment = $notForPayment; if ($notForPayment === true) { if ($this->getWithBank() === true) { $this->setBankData('XXXXXX', 'XXXXXX'); } if ($this->getWithAccountNumber() === true) { $this->setAccountNumber('XXXXXX'); } if ($this->getWithRecipient() === true) { $this->setRecipientData('XXXXXX', 'XXXXXX', 'XXXXXX', 'XXXXXX'); } if ($this->getWithPayer() === true) { $this->setPayerData('XXXXXX', 'XXXXXX', 'XXXXXX', 'XXXXXX'); } if ($this->getWithAmount() === true) { $this->setAmount('XXXXXXXX.XX'); } } return $this; }
Set payment slip for not to be used for payment XXXes out all fields to prevent people using the payment slip. @param boolean $notForPayment True if not for payment, else false. @return $this The current instance for a fluent interface.
protected function modulo10($number) { $next = 0; for ($i=0; $i < strlen($number); $i++) { $next = $this->moduloTable[($next + intval(substr($number, $i, 1))) % 10]; } return (10 - $next) % 10; }
Creates Modulo10 recursive check digit @copyright As found on http://www.developers-guide.net/forums/5431,modulo10-rekursiv (thanks, dude!) @param string $number Number to create recursive check digit off. @return int Recursive check digit.
protected function breakStringIntoBlocks($string, $blockSize = 5, $alignFromRight = true) { // Lets reverse the string (because we want the block to be aligned from the right) if ($alignFromRight === true) { $string = strrev($string); } // Chop it into blocks $string = trim(chunk_split($string, $blockSize, ' ')); // Re-reverse if ($alignFromRight === true) { $string = strrev($string); } return $string; }
Get a given string broken down in blocks of a certain size Example: 000000000000000 becomes more readable 00000 00000 00000 @param string $string The to be formatted string. @param int $blockSize The Block size of choice. @param bool $alignFromRight Right aligned, blocks are build from right. @return string Given string divided in blocks of given block size separated by one space.
private function parseHostedConfiguration(array $configuration, ContainerBuilder $container) { $entityId = ['entity_id_route' => $configuration['metadata']['entity_id_route']]; $serviceProvider = array_merge($configuration['service_provider'], $entityId); $identityProvider = array_merge($configuration['identity_provider'], $entityId); $container ->getDefinition('surfnet_saml.saml.attribute_dictionary') ->replaceArgument(0, $configuration['attribute_dictionary']['ignore_unknown_attributes']); $this->parseHostedSpConfiguration($serviceProvider, $container); $this->parseHostedIdpConfiguration($identityProvider, $container); $this->parseMetadataConfiguration($configuration, $container); }
Creates and register MetadataConfiguration object based on the configuration given. @param array $configuration @param ContainerBuilder $container
private function parseRemoteServiceProviderConfiguration( $serviceProvider ) { $configuration = $this->parseCertificateData('surfnet_saml.remote.service_provider[]', $serviceProvider); $configuration['entityId'] = $serviceProvider['entity_id']; $configuration['assertionConsumerUrl'] = $serviceProvider['assertion_consumer_service_url']; $definition = new Definition(ServiceProvider::class, [$configuration]); $definition->setPublic(false); return $definition; }
@param array $serviceProvider @return Definition @throws \Surfnet\SamlBundle\Exception\SamlInvalidConfigurationException
private function parseCertificateData($path, array $provider) { if (isset($provider['certificate_file']) && !isset($provider['certificate'])) { $configuration['certificateFile'] = $provider['certificate_file']; } elseif (isset($provider['certificate'])) { $configuration['certificateData'] = $provider['certificate']; } else { throw SamlInvalidConfigurationException::missingCertificate($path); } return $configuration; }
@param string $path The path where to espect the configuration. @param array $provider The provider configuration. @return array @throws \Surfnet\SamlBundle\Exception\SamlInvalidConfigurationException the certificate data
public function apply(Rule $rule, $value) { $type = $rule->getInputType(); if ($type == CallbackRule::SELF_METHOD_TYPE) { return $this->useObjectMethod($rule->callback, $value); } if ($type == CallbackRule::CALLABLE_TYPE) { return $this->useCallable($rule->callback, $value); } if ($type == CallbackRule::CLOSURE_TYPE) { return $this->useClosure($rule->callback, $value); } throw new InvalidCallbackException("Unsupported callback provided, failed to filter property"); }
{@inheritDoc} @param CallbackRule $rule
protected function useObjectMethod($method, $value) { $currentObject = $this->getCurrentObject(); if ($currentObject === null) { throw new FilterException( "The target object was not provided to the filter, can't execute method. Please report this." ); } if (! method_exists($currentObject, $method)) { throw new InvalidCallbackException( sprintf( "CallbackFilter: Method '%s' not found in object of type '%s'", $method, get_class($currentObject) ) ); } return $currentObject->$method($value); }
Filters by executing a method in the object @param string $method @param mixed $value @throws \DMS\Filter\Exception\FilterException @throws \DMS\Filter\Exception\InvalidCallbackException @return mixed
public function setWithReferenceNumber($withReferenceNumber = true) { $this->isBool($withReferenceNumber, 'withReferenceNumber'); $this->withReferenceNumber = $withReferenceNumber; if ($withReferenceNumber === false) { $this->referenceNumber = ''; } return $this; }
Set if payment slip has a reference number specified Resets the reference number when disabling. @param bool $withReferenceNumber True if yes, false if no. @return $this The current instance for a fluent interface.
public function setWithBankingCustomerId($withBankingCustomerId = true) { $this->isBool($withBankingCustomerId, 'withBankingCustomerId'); $this->withBankingCustomerId = $withBankingCustomerId; if ($withBankingCustomerId === false) { $this->bankingCustomerId = ''; } return $this; }
Set if the payment slip's reference number should contain the banking customer ID Resets the banking customer ID when disabling. @param bool $withBankingCustomerId True if successful, else false. @return $this The current instance for a fluent interface.
public function setNotForPayment($notForPayment = true) { parent::setNotForPayment($notForPayment); if ($notForPayment === true) { if ($this->getWithReferenceNumber() === true) { $this->setReferenceNumber('XXXXXXXXXXXXXXXXXXXX'); } if ($this->getWithBankingCustomerId() === true) { $this->setBankingCustomerId('XXXXXX'); } } return $this; }
Set payment slip for not to be used for payment XXXes out all fields to prevent people using the payment slip. @param boolean $notForPayment True if not for payment, else false. @return $this The current instance for a fluent interface.
public function getCompleteReferenceNumber($formatted = true, $fillZeros = true) { $referenceNumber = $this->getReferenceNumber(); $notForPayment = $this->getNotForPayment(); $completeReferenceNumber = $referenceNumber; if ($notForPayment) { $completeReferenceNumber = str_pad($referenceNumber, 26, 'X', STR_PAD_LEFT); } elseif ($this->getWithBankingCustomerId()) { // Get reference number and fill with zeros $referenceNumber = str_pad($referenceNumber, 20, '0', STR_PAD_LEFT); // Prepend banking customer identification code $completeReferenceNumber = $this->getBankingCustomerId() . $referenceNumber; } elseif ($fillZeros) { // Get reference number and fill with zeros $completeReferenceNumber = str_pad($referenceNumber, 26, '0', STR_PAD_LEFT); } // Add check digit $completeReferenceNumber = $this->appendCheckDigit($completeReferenceNumber, $notForPayment); if ($formatted) { $completeReferenceNumber = $this->breakStringIntoBlocks($completeReferenceNumber); } return $completeReferenceNumber; }
Get complete reference number @param bool $formatted Should the returned reference be formatted in blocks of five (for better readability). @param bool $fillZeros Fill up with leading zeros, only applies to the case where no banking customer ID is used. @return string The complete (with/without bank customer ID), formatted reference number with check digit
protected function appendCheckDigit($referenceNumber, $notForPayment = false) { if ($notForPayment === true) { return $referenceNumber . 'X'; } return $referenceNumber . $this->modulo10($referenceNumber); }
Append the check digit to the reference number Simply appends an 'X' if the slip is not meant for payment. @param string $referenceNumber The reference number to calculate the prefix with. @param bool $notForPayment Whether the payment slip is not ment for payment. @return string The reference number with the appended check digit.
public function getCodeLine($fillZeros = true) { $referenceNumber = $this->getCompleteReferenceNumber(false, $fillZeros); $accountNumber = $this->getAccountDigits(); if ($this->getWithAmount()) { $francs = $this->getAmountFrancs(); $cents = $this->getAmountCents(); $francs = str_pad($francs, 8, '0', STR_PAD_LEFT); $cents = str_pad($cents, 2, '0', STR_PAD_RIGHT); $amountPrefix = '01'; $amountPart = $francs . $cents; $amountCheck = $this->modulo10($amountPrefix . $amountPart); } else { $amountPrefix = '04'; $amountPart = ''; $amountCheck = '2'; } if ($fillZeros) { $referenceNumberPart = str_pad($referenceNumber, 27, '0', STR_PAD_LEFT); } else { $referenceNumberPart = $referenceNumber; } $accountNumberPart = substr($accountNumber, 0, 2) . str_pad(substr($accountNumber, 2), 7, '0', STR_PAD_LEFT); if ($this->getNotForPayment()) { $amountPrefix = 'XX'; $amountCheck = 'X'; } $codeLine = sprintf( '%s%s%s>%s+ %s>', $amountPrefix, $amountPart, $amountCheck, $referenceNumberPart, $accountNumberPart ); return $codeLine; }
Get the full code line at the bottom of the ESR @param bool $fillZeros Whether to fill up the code line with leading zeros. @return string The full code line.
public function getItems($itemName = null) { if ($itemName && isset($this->_items[$itemName])) { return $this->_items[$itemName]; } return $this->_items; }
Return thee parents and children of specific item or all items @param string $itemName name of the item. @return array
public function hasParent($itemName, $parentName) { $parents = $this->getParents($itemName); if (in_array($parentName, $parents)) { return true; } return false; }
Returns whether the given item has a specific parent. @param string $itemName name of the item. @param string $parentName name of the parent. @return boolean the result.
public function hasChild($itemName, $childName) { $children = $this->getChildren($itemName); if (in_array($childName, $children)) { return true; } return false; }
Returns whether the given item has a specific child. @param string $itemName name of the item. @param string $childName name of the child. @return boolean the result.
public function hasAncestor($itemName, $ancestorName) { $ancestors = $this->getAncestors($itemName); return isset($ancestors[$ancestorName]); }
Returns whether the given item has a specific ancestor. @param string $itemName name of the item. @param string $ancestorName name of the ancestor. @return boolean the result.
public function hasDescendant($itemName, $descendantName) { $descendants = $this->getDescendants($itemName); return isset($descendants[$descendantName]); }
Returns whether the given item has a specific descendant. @param string $itemName name of the item. @param string $descendantName name of the descendant. @return boolean the result.
public function getAncestor($itemName, $depth = 0) { $ancestors = array(); $parents = $this->getParents($itemName); if (empty($parents)) { $parents = $this->owner->db->createCommand() ->select('parent') ->from($this->owner->itemChildTable) ->where('child=:child', array(':child' => $itemName)) ->queryColumn(); $this->setItemParents($itemName, $parents); } foreach ($parents as $parent) { $ancestors[] = array( 'name' => $parent, 'item' => $this->owner->getAuthItem($parent), 'parents' => $this->getAncestor($parent, $depth + 1), 'depth' => $depth ); } return $ancestors; }
Returns all ancestors for the given item recursively. @param string $itemName name of the item. @param integer $depth current depth. @return array the ancestors.
public function getDescendant($itemName, $depth = 0) { $descendants = array(); $children = $this->getChildren($itemName); if (empty($children)) { $children = $this->owner->db->createCommand() ->select('child') ->from($this->owner->itemChildTable) ->where('parent=:parent', array(':parent' => $itemName)) ->queryColumn(); $this->setItemChildren($itemName, $children); } foreach ($children as $child) { $descendants[$child] = array( 'name' => $child, 'item' => $this->owner->getAuthItem($child), 'children' => $this->getDescendant($child, $depth + 1), 'depth' => $depth, ); } return $descendants; }
Returns all the descendants for the given item recursively. @param string $itemName name of the item. @param integer $depth current depth. @return array the descendants.
private function getPermissions($items = null, $depth = 0) { $permissions = array(); if ($items === null) { $items = $this->owner->getAuthItems(); } foreach ($items as $itemName => $item) { $permissions[$itemName] = array( 'name' => $itemName, 'item' => $item, 'children' => $this->getPermissions($item, $depth + 1), 'depth' => $depth, ); } return $permissions; }
Returns the permission tree for the given items. @param CAuthItem[] $items items to process. If omitted the complete tree will be returned. @param integer $depth current depth. @return array the permissions.
private function getItemPermissions($itemName) { $item = $this->owner->getAuthItem($itemName); return $item instanceof CAuthItem ? $this->getPermissions($item->getChildren()) : array(); }
Builds the permissions for the given item. @param string $itemName name of the item. @return array the permissions.
public function getItemsPermissions($names) { $permissions = array(); $items = $this->getPermissions(); $flat = $this->flattenPermissions($items); foreach ($flat as $itemName => $item) { if (in_array($itemName, $names)) { $permissions[$itemName] = $item; } } return $permissions; }
Returns the permissions for the items with the given names. @param string[] $names list of item names. @return array the permissions.
public function flattenPermissions($permissions) { $flattened = array(); foreach ($permissions as $itemName => $itemPermissions) { $flattened[$itemName] = $itemPermissions; if (isset($itemPermissions['children'])) { $children = $itemPermissions['children']; unset($itemPermissions['children']); // not needed in a flat tree $flattened = array_merge($flattened, $this->flattenPermissions($children)); } if (isset($itemPermissions['parents'])) { $parents = $itemPermissions['parents']; unset($itemPermissions['parents']); $flattened = array_merge($flattened, $this->flattenPermissions($parents)); } } return $flattened; }
Flattens the given permission tree. @param array $permissions the permissions tree. @return array the permissions.
public function init() { parent::init(); $this->setIsAdmin(in_array($this->name, $this->admins)); }
Initializes the component.
public function checkAccess($operation, $params = array(), $allowCaching = true) { if ($this->getIsAdmin()) { return true; } return parent::checkAccess($operation, $params, $allowCaching); }
Performs access check for this user. @param string $operation the name of the operation that need access check. @param array $params name-value pairs that would be passed to business rules associated with the tasks and roles assigned to the user. @param boolean $allowCaching whether to allow caching the result of access check. @return boolean whether the operations can be performed by this user.
public function filterValue($value, $rule) { if ($rule instanceof Rules\Rule) { $filter = $this->filterLoader->getFilterForRule($rule); return $filter->apply($rule, $value); } return $this->walkRuleChain($value, $rule); }
{@inheritDoc}
protected function walkObject($object, $limitProperty = null) { if ($object === null) { return; } $metadata = $this->metadataFactory->getClassMetadata(get_class($object)); //Get a Object Handler/Walker $walker = new ObjectWalker($object, $this->filterLoader); //Get all filtered properties or limit with selected $properties = ($limitProperty !== null) ? array($limitProperty) : $metadata->getFilteredProperties(); //Iterate over properties with filters foreach ($properties as $property) { $walker->applyFilterRules($property, $metadata->getPropertyRules($property)); } }
Iterates over annotated properties in an object filtering the selected values @param object $object @param string $limitProperty
protected function walkRuleChain($value, $rules) { foreach ($rules as $rule) { $filter = $this->filterLoader->getFilterForRule($rule); $value = $filter->apply($rule, $value); } return $value; }
Iterates over an array of filters applying all to the value @param mixed $value @param array $rules @return mixed
public function actionIndex() { $dataProvider = new AuthItemDataProvider(); $dataProvider->type = $this->type; $this->render( 'index', array( 'dataProvider' => $dataProvider, ) ); }
Displays a list of items of the given type.
public function actionCreate() { $model = new AuthItemForm('create'); if (isset($_POST['AuthItemForm'])) { $model->attributes = $_POST['AuthItemForm']; if ($model->validate()) { /* @var $am CAuthManager|AuthBehavior */ $am = Yii::app()->getAuthManager(); if (($item = $am->getAuthItem($model->name)) === null) { $item = $am->createAuthItem($model->name, $model->type, $model->description); if ($am instanceof CPhpAuthManager) { $am->save(); } } $this->redirect(array('view', 'name' => $item->name)); } } $model->type = $this->type; $this->render( 'create', array( 'model' => $model, ) ); }
Displays a form for creating a new item of the given type.
public function actionUpdate($name) { /* @var $am CAuthManager|AuthBehavior */ $am = Yii::app()->getAuthManager(); $item = $am->getAuthItem($name); if ($item === null) { throw new CHttpException(404, Yii::t('AuthModule.main', 'Page not found.')); } $model = new AuthItemForm('update'); if (isset($_POST['AuthItemForm'])) { $model->attributes = $_POST['AuthItemForm']; if ($model->validate()) { $item->description = $model->description; $am->saveAuthItem($item); if ($am instanceof CPhpAuthManager) { $am->save(); } $this->redirect(array('index')); } } $model->name = $name; $model->description = $item->description; $model->type = $item->type; $this->render( 'update', array( 'item' => $item, 'model' => $model, ) ); }
Displays a form for updating the item with the given name. @param string $name name of the item. @throws CHttpException if the authorization item is not found.