idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
35,800
public function onShutdown ( ) { if ( ! $ error = error_get_last ( ) ) { return ; } $ fatal = array ( E_ERROR , E_PARSE , E_CORE_ERROR , E_COMPILE_ERROR , E_USER_ERROR , E_RECOVERABLE_ERROR ) ; if ( ! in_array ( $ error [ 'type' ] , $ fatal ) ) { return ; } $ message = '[Shutdown Error]: %s' ; $ message = sprintf ( $ message , $ error [ 'message' ] ) ; $ backtrace = array ( array ( 'file' => $ error [ 'file' ] , 'line' => $ error [ 'line' ] ) ) ; $ this -> client -> notifyOnError ( $ message , $ backtrace , 'error' ) ; error_log ( $ message . ' in: ' . $ error [ 'file' ] . ':' . $ error [ 'line' ] ) ; }
Handles the PHP shutdown event .
35,801
public function getHelpLanguages ( array $ parameters = array ( ) , $ multipart = false , $ appOnlyAuth = false ) { return $ this -> get ( "help/languages" , $ parameters , $ multipart , $ appOnlyAuth ) ; }
Returns the list of languages supported by Twitter along with the language code supported by Twitter .
35,802
public function getHelpPrivacy ( array $ parameters = array ( ) , $ multipart = false , $ appOnlyAuth = false ) { return $ this -> get ( "help/privacy" , $ parameters , $ multipart , $ appOnlyAuth ) ; }
Returns Twitter s Privacy Policy .
35,803
public function getApplicationRateLimitStatus ( array $ parameters = array ( ) , $ multipart = false , $ appOnlyAuth = false ) { return $ this -> get ( "application/race_limit_status" , $ parameters , $ multipart , $ appOnlyAuth ) ; }
Returns the current rate limits for methods belonging to the specified resource families .
35,804
public function attachment ( $ name , $ content ) { if ( ! is_string ( $ content ) && ( ! is_resource ( $ content ) || get_resource_type ( $ content ) != 'stream' ) ) { throw new Exception \ InvalidArgumentException ( sprintf ( "Attachment content must be either string or stream, %s passed" ) ) ; } $ this -> attachments [ $ name ] = [ 'content' => $ content ] ; }
Just a quicker way to add an attachment .
35,805
public function inlineAttachment ( $ name , $ content ) { if ( ! is_string ( $ content ) && ( ! is_resource ( $ content ) || get_resource_type ( $ content ) != 'stream' ) ) { throw new Exception \ InvalidArgumentException ( sprintf ( "Attachment content must be either string or stream, %s passed" ) ) ; } $ this -> attachments [ $ name ] = [ 'content' => $ content , 'inline' => true ] ; }
Just a quicker way to add an inline attachment .
35,806
protected function getRanges ( string $ selector ) : Collection { return Factory :: create ( explode ( ';' , $ selector ) ) -> map ( function ( $ range ) { $ separator = $ this -> dotDotSeparator ( $ range ) ; if ( false != $ separator ) { return Factory :: create ( [ ( int ) substr ( $ range , 0 , $ separator ) , ( int ) substr ( $ range , $ separator + 2 ) ] ) ; } $ separator = $ this -> columnSeparator ( $ range ) ; if ( false != $ separator ) { return Factory :: create ( [ ( int ) substr ( $ range , 0 , $ separator ) , ( int ) substr ( $ range , $ separator + 1 ) ] ) ; } $ separator = $ this -> dashSeparator ( $ range ) ; if ( false != $ separator ) { return Factory :: create ( [ ( int ) substr ( $ range , 0 , $ separator ) , ( int ) substr ( $ range , $ separator + 1 ) ] ) ; } $ separator = $ this -> commaSeparator ( $ range ) ; if ( false != $ separator ) { return Factory :: create ( [ ( int ) substr ( $ range , 0 , $ separator ) , ( int ) substr ( $ range , 0 , $ separator ) + ( int ) ( substr ( $ range , $ separator + 1 ) - 1 ) , ] ) ; } return Factory :: create ( [ ( int ) $ range , ( int ) $ range ] ) ; } ) ; }
Explode the selector to get ranges .
35,807
public function setFacet ( $ name ) { if ( $ this -> getSearchParam ( 'facet' ) === null ) { $ this -> setSearchParams ( 'facet' , 'true' ) ; } $ this -> setSearchParams ( 'facet.field' , $ name ) ; return $ this ; }
Set the facet to search on
35,808
private function sortItemsToDays ( $ items ) { $ all = [ ] ; foreach ( $ items as $ item ) { $ timestamp = strtotime ( $ item -> created_at ) * 1000 ; $ day = Carbon :: createFromFormat ( 'Y-m-d H:i:s' , $ item -> created_at ) -> format ( 'Y-m-d' ) ; if ( ! isset ( $ all [ $ day ] ) ) { $ all [ $ day ] = [ 'timestamp' => $ timestamp , 'date' => $ day , 'count' => 0 , ] ; } $ all [ $ day ] [ 'count' ] ++ ; } return $ all ; }
Sort items by day .
35,809
public function create ( RouteCollection $ routes ) : Tree { $ routesArray = $ routes -> all ( ) ; $ routesPaths = array_map ( function ( Route $ route ) { return $ this -> serializer -> serialize ( $ route -> getPath ( ) ) ; } , $ routesArray ) ; $ tree = new Tree ( ) ; foreach ( $ routesPaths as $ index => $ pathArray ) { $ route = $ routesArray [ $ index ] ; $ treeNode = $ tree ; foreach ( $ pathArray as $ path ) { $ treeNode = $ this -> addPathPartToTree ( $ treeNode , $ path , $ route , $ index ) ; } } return $ tree ; }
Creates new tree from the route collection .
35,810
private function addPathPartToTree ( TreeNode $ node , RoutePath $ path , Route $ route , int $ index ) : TreeNode { $ pathNode = $ this -> pathToNode ( $ path , $ route , $ index ) ; foreach ( $ node -> getChildren ( ) as $ child ) { if ( $ child -> withoutChildren ( ) == $ pathNode -> withoutChildren ( ) ) { return $ child ; } } $ node -> addChild ( $ pathNode ) ; return $ pathNode ; }
Adds route path to the given node . Merges with existing one if possible otherwise creates new tree node .
35,811
private function pathToNode ( RoutePath $ path , Route $ route , int $ index ) : TreeNode { if ( $ path instanceof AttributePath ) { return $ this -> createAttributeNode ( $ path ) ; } if ( $ path instanceof StaticPath ) { return $ this -> createStaticNode ( $ path ) ; } if ( $ path instanceof OptionalPath ) { return $ this -> createOptionalNode ( ) ; } return $ this -> createLeafNode ( $ route , $ index ) ; }
Converts the given route path to a tree node .
35,812
public function content ( $ name = null ) { if ( $ name && isset ( self :: $ _content_for [ $ name ] ) ) return self :: $ _content_for [ $ name ] ; }
Yield seems to be a reserved keyword in PHP 5 . 5 . Forced to change the name of the yield method to content .
35,813
public function getIconVendor ( $ class ) { foreach ( $ this -> _config [ 'iconVendorPrefixes' ] as $ iconVendorPrefix ) { $ regex = sprintf ( '/^(?<!<"\')(%s[\s-]){1,}/' , $ iconVendorPrefix , $ iconVendorPrefix ) ; if ( preg_match ( $ regex , $ class ) ) { return $ iconVendorPrefix ; } } return null ; }
Returns icon vendor from class if found .
35,814
public function panelBody ( $ html , $ options = array ( ) ) { $ defaults = array ( 'class' => '' ) ; $ options = array_merge ( $ defaults , $ options ) ; $ options = $ this -> addClass ( $ options , 'panel-body' ) ; return $ this -> tag ( 'div' , $ html , $ options ) ; }
Render a panel body
35,815
public function panel ( $ headingHtml , $ bodyHtml = null , $ footerHtml = null , $ options = array ( ) ) { $ defaults = array ( 'class' => 'panel-default' , 'headingOptions' => array ( ) , 'footerOptions' => array ( ) , 'bodyOptions' => array ( ) , 'wrapHeading' => true , 'wrapFooter' => true , 'wrapBody' => true ) ; if ( $ this -> _blockRendering ) { $ options = $ bodyHtml ; } $ options = Hash :: merge ( $ defaults , $ options ) ; $ options = $ this -> addClass ( $ options , 'panel' ) ; if ( ! $ this -> _blockRendering ) { $ heading = $ options [ 'wrapHeading' ] ? $ this -> panelHeading ( $ headingHtml , $ options [ 'headingOptions' ] ) : $ headingHtml ; $ footer = $ options [ 'wrapFooter' ] && $ footerHtml ? $ this -> panelFooter ( $ footerHtml , $ options [ 'footerOptions' ] ) : $ footerHtml ; $ body = $ options [ 'wrapBody' ] ? $ this -> panelBody ( $ bodyHtml , $ options [ 'bodyOptions' ] ) : $ bodyHtml ; $ html = $ heading . $ body . $ footer ; } else { $ html = $ headingHtml ; } unset ( $ options [ 'headingOptions' ] , $ options [ 'footerOptions' ] , $ options [ 'bodyOptions' ] , $ options [ 'wrapFooter' ] , $ options [ 'wrapHeading' ] , $ options [ 'wrapBody' ] ) ; return $ this -> tag ( 'div' , $ html , $ options ) ; }
Render a panel
35,816
public function accordion ( $ items = array ( ) , $ options = array ( ) ) { $ defaults = array ( 'class' => '' , 'id' => str_replace ( '.' , '' , uniqid ( 'accordion_' , true ) ) , ) ; $ options = Hash :: merge ( $ defaults , $ options ) ; $ options = $ this -> addClass ( $ options , 'panel-group' ) ; if ( is_array ( $ items ) ) { $ html = '' ; foreach ( $ items as $ itemHeading => $ itemBody ) { $ html .= $ this -> accordionItem ( $ itemHeading , $ itemBody , array ( 'accordionId' => $ options [ 'id' ] ) ) ; } } else { $ html = $ items ; } return $ this -> tag ( 'div' , $ html , $ options ) ; }
Render an accordion
35,817
public function accordionItem ( $ titleHtml , $ bodyHtml = null , $ options = array ( ) ) { $ itemBodyId = str_replace ( '.' , '' , uniqid ( 'accordion_body_' , true ) ) ; $ titleLink = $ this -> link ( $ titleHtml , '#' . $ itemBodyId , array ( 'data-toggle' => 'collapse' , 'data-parent' => '#' . $ options [ 'accordionId' ] ) ) ; $ heading = $ this -> tag ( 'h4' , $ titleLink , array ( 'class' => 'panel-title' ) ) ; $ body = $ this -> tag ( 'div' , $ this -> panelBody ( $ bodyHtml ) , array ( 'class' => 'panel-collapse collapse in' , 'id' => $ itemBodyId ) ) ; $ blockRendering = $ this -> _blockRendering ; $ this -> _blockRendering = false ; $ itemHtml = $ this -> panel ( $ heading , $ body , null , array ( 'wrapBody' => false ) ) ; $ this -> _blockRendering = $ blockRendering ; return $ itemHtml ; }
Render an accordion item
35,818
private function generateEncryptRequest ( InputInterface $ input , OutputInterface $ output ) { $ algorithmId = $ input -> getArgument ( 'algorithm_id' ) ; $ plaintextValue = $ input -> getArgument ( 'plaintext_value' ) ; $ key = $ input -> getOption ( 'key' ) ; $ keyProvided = $ input -> hasParameterOption ( [ '--key' , '-k' ] ) ; $ questionText = 'Plaintext value to be encrypted (hidden input): ' ; $ plaintextAsker = $ this -> questionAskerGenerator -> generateHiddenInputQuestionAsker ( $ questionText , $ input , $ output ) ; return $ this -> encryptRequestFactory -> createEncryptRequest ( $ algorithmId , $ key , $ keyProvided , $ plaintextAsker , $ plaintextValue ) ; }
Generate encrypt request .
35,819
protected function extractReturnFile ( ) { $ header = $ this -> registries [ 0 ] ; return [ 'sequence' => ( int ) $ header -> file_sequence , 'emission' => static :: parseDate ( $ header -> record_date ) , 'charging' => $ this -> extractCharging ( ) , ] ; }
Extracts data about the Return File
35,820
protected function detectAssignment ( Registry $ title ) { return Models \ Assignment :: getInstance ( [ 'bank' => $ this -> bank -> id , 'agency' => $ title -> assignment_agency , 'account' => $ title -> assignment_account , 'cnab' => ( string ) $ this -> cnab , ] ) ; }
Detects an Assignment in the database
35,821
protected static function detectTitle ( array $ title ) { $ assignment = $ title [ 'assignment' ] ; if ( $ assignment === null ) { return ; } $ where = array_merge ( Utils \ Utils :: arrayWhitelist ( $ title , [ 'assignment' , 'our_number' , 'due' , ] ) , [ 'ORDER' => [ 'stamp' => 'DESC' , 'id' => 'DESC' , ] , ] ) ; $ ids = Models \ Title :: dump ( $ where , 'id' ) ; if ( empty ( $ ids ) ) { return ; } return $ ids [ 0 ] ; }
Detects a Title in the database
35,822
protected static function parseDate ( string $ date , string $ format = null , string $ output = null ) { $ d = \ DateTime :: createFromFormat ( $ format ?? static :: DATE_FORMAT , $ date ) ; return ( $ d ? $ d -> format ( $ output ?? 'Y-m-d' ) : null ) ; }
Parses a date to Y - m - d
35,823
private function initializeServiceDefinitions ( array $ mergedConfig , ContainerBuilder $ container ) { $ initManager = $ container -> get ( ServiceNames :: SERVICE_DEFINITION_INITIALIZATION_MANAGER ) ; $ initManager -> initializeServiceDefinitions ( $ mergedConfig , $ container ) ; }
Initialize service definitions .
35,824
private function loadBundleServiceDefinitions ( ContainerBuilder $ container ) { $ fileLocator = new FileLocator ( self :: SERVICES_CONFIG_DIRECTORY_RELATIVE_PATH ) ; $ loader = new XmlFileLoader ( $ container , $ fileLocator ) ; $ loader -> load ( 'services.xml' ) ; }
Load bundle service definitions .
35,825
protected function getSubPluginSettings ( $ pluginClassName , array $ defaults ) { $ settings = $ this -> getSettingValue ( $ pluginClassName , $ defaults ) ; $ settings = $ this -> mergeArraysRecursive ( $ defaults , $ settings ) ; return $ settings ; }
Get settings defined for a sub - plugin of this plugin . If your plugin uses other plugins internally to solve the task then the configuration file can contain overrides for settings of each plugin by adding a sub - array indexed by the class name of the plugin that gets used .
35,826
public function buildView ( FormView $ view , FormInterface $ form , array $ options ) { $ formName = $ form -> getName ( ) ; if ( '__' === substr ( $ formName , 0 , 2 ) ) { return ; } if ( ! empty ( $ options [ 'group' ] ) ) { $ group = $ options [ 'group' ] ; $ type = 'group' ; } else { $ group = 'single_' . $ formName ; $ type = 'single' ; } $ root = $ view -> parent ; if ( ! isset ( $ root -> vars [ 'groups' ] [ $ group ] ) ) { $ root -> vars [ 'groups' ] [ $ group ] = [ 'type' => $ type , 'items' => [ ] , ] ; } $ root -> vars [ 'groups' ] [ $ group ] [ 'items' ] [ ] = $ formName ; }
Preprocess view variables
35,827
public function multiFilterBy ( $ columns ) { foreach ( $ columns as $ column => $ value ) { if ( strpos ( $ column , '.' ) ) { $ this -> filterByRelation ( $ column , $ value ) ; } else { $ this -> filterBy ( $ column , $ value ) ; } } return $ this ; }
Append many column filters to query builder .
35,828
public function filterByRelation ( $ column , $ value = null ) { $ relations = explode ( '.' , $ column ) ; $ column = $ this -> getColumn ( $ column = array_pop ( $ relations ) , $ relations ) ; $ relations = array_map ( function ( $ relation ) { return camel_case ( $ relation ) ; } , $ relations ) ; $ this -> instance -> whereHas ( implode ( '.' , $ relations ) , function ( Builder $ builder ) use ( $ column , $ value ) { $ value = in_array ( $ value , [ 'true' , 'false' ] ) ? ( $ value === 'false' ? false : true ) : $ value ; is_bool ( $ value ) ? $ builder -> where ( $ column , $ value ) : $ builder -> where ( $ column , $ this -> getLikeOperator ( ) , "%$value%" ) ; } ) ; return $ this ; }
Append relation column filter to query builder .
35,829
protected function getColumn ( $ column , array $ relations = [ ] ) { $ model = $ this -> repository -> makeModel ( ) ; if ( empty ( $ relations ) ) { return "{$model->getTable()}.{$column}" ; } foreach ( $ relations as $ relation ) { $ model = $ model instanceof Model ? $ model -> { camel_case ( $ relation ) } ( ) : $ model -> getRelated ( ) -> { camel_case ( $ relation ) } ( ) ; } return "{$model->getRelated()->getTable()}.{$column}" ; }
Returns column name prefixed with table name .
35,830
public function filterBy ( $ column , $ value = null ) { $ value = in_array ( $ value , [ 'true' , 'false' ] ) ? ( $ value === 'false' ? false : true ) : $ value ; is_bool ( $ value ) ? $ this -> instance -> where ( $ column , $ value ) : $ this -> instance -> where ( $ column , $ this -> getLikeOperator ( ) , "%$value%" ) ; return $ this ; }
Append column filter to query builder .
35,831
public function hasPermission ( $ assertionName , $ value , array $ attributes ) { $ assertion = $ this -> assertionPluginManager -> get ( $ assertionName ) ; if ( ! $ assertion ) { throw new Exception \ AssertionNotFound ( sprintf ( 'The assertion \"%s\" was not found' , is_object ( $ assertion ) ? get_class ( $ assertion ) : gettype ( $ assertion ) ) ) ; } return $ assertion -> hasPermission ( $ value , $ attributes ) ; }
Check assertion for permissions
35,832
public function utf162utf8 ( $ utf16 ) { if ( $ this -> _mb_convert_encoding ) { return mb_convert_encoding ( $ utf16 , 'UTF-8' , 'UTF-16' ) ; } $ bytes = ( ord ( $ utf16 { 0 } ) << 8 ) | ord ( $ utf16 { 1 } ) ; switch ( true ) { case ( 0x7F & $ bytes ) == $ bytes : return chr ( 0x7F & $ bytes ) ; case ( 0x07FF & $ bytes ) == $ bytes : return chr ( 0xC0 | ( ( $ bytes >> 6 ) & 0x1F ) ) . chr ( 0x80 | ( $ bytes & 0x3F ) ) ; case ( 0xFFFF & $ bytes ) == $ bytes : return chr ( 0xE0 | ( ( $ bytes >> 12 ) & 0x0F ) ) . chr ( 0x80 | ( ( $ bytes >> 6 ) & 0x3F ) ) . chr ( 0x80 | ( $ bytes & 0x3F ) ) ; } return '' ; }
convert a string from one UTF - 16 char to one UTF - 8 char .
35,833
public function utf82utf16 ( $ utf8 ) { if ( $ this -> _mb_convert_encoding ) { return mb_convert_encoding ( $ utf8 , 'UTF-16' , 'UTF-8' ) ; } switch ( $ this -> strlen8 ( $ utf8 ) ) { case 1 : return $ utf8 ; case 2 : return chr ( 0x07 & ( ord ( $ utf8 { 0 } ) >> 2 ) ) . chr ( ( 0xC0 & ( ord ( $ utf8 { 0 } ) << 6 ) ) | ( 0x3F & ord ( $ utf8 { 1 } ) ) ) ; case 3 : return chr ( ( 0xF0 & ( ord ( $ utf8 { 0 } ) << 4 ) ) | ( 0x0F & ( ord ( $ utf8 { 1 } ) >> 2 ) ) ) . chr ( ( 0xC0 & ( ord ( $ utf8 { 1 } ) << 6 ) ) | ( 0x7F & ord ( $ utf8 { 2 } ) ) ) ; } return '' ; }
convert a string from one UTF - 8 char to one UTF - 16 char .
35,834
protected function value_in_format ( $ value , $ format ) { if ( $ format === '*' ) return true ; $ formats = explode ( ',' , $ format ) ; foreach ( $ formats as $ format ) { if ( ctype_digit ( $ format ) ) { if ( $ value === ( int ) $ format ) return true ; continue ; } $ values = $ this -> expand_format_expression ( $ format ) ; if ( in_array ( $ value , $ values ) ) return true ; } return false ; }
Actually detect if value satisifes format
35,835
protected function expand_format_expression ( $ format ) { $ increment = 1 ; if ( strpos ( $ format , '/' ) !== false ) { list ( $ format , $ increment ) = explode ( '/' , $ format , 2 ) ; $ increment = ( $ increment === '*' ) ? 1 : ( int ) $ increment ; } $ parts = explode ( '-' , $ format , 2 ) ; $ start = array_shift ( $ parts ) ; $ end = array_shift ( $ parts ) ; if ( $ start === '*' ) $ start = $ this -> min ; if ( $ end === null ) $ end = $ this -> max ; $ start = max ( $ this -> min , $ start ) ; $ end = min ( $ this -> max , $ end ) ; if ( ( $ end - $ start ) < $ increment ) return array ( $ start ) ; return range ( $ start , $ end , $ increment ) ; }
Expand sub - list within a format
35,836
protected function initRegistries ( ) { $ this -> roleRegistry = new Registry ( ) ; $ this -> resourceRegistry = new Registry ( ) ; $ this -> permissionRegistry = new Registry ( ) ; $ this -> globalRegistry = new GlobalRegistry ( ) ; }
Initalizes the registries
35,837
public function addRole ( string ... $ role ) { foreach ( $ role as $ _role ) { $ this -> roleRegistry -> save ( $ _role ) ; } }
Add a new role object to the registry
35,838
public function addResource ( string ... $ resource ) { foreach ( $ resource as $ _resource ) { $ this -> resourceRegistry -> save ( $ _resource ) ; } }
Add a new resource object to the registry
35,839
public function addPermission ( string ... $ permission ) { foreach ( $ permission as $ _permission ) { $ this -> permissionRegistry -> save ( $ _permission ) ; } }
Add a new permission object to the registry
35,840
public function add ( ObjectInterface ... $ objects ) { foreach ( $ objects as $ object ) { if ( $ object instanceof RoleInterface ) { $ this -> addRole ( ( string ) $ object ) ; } else if ( $ object instanceof ResourceInterface ) { $ this -> addResource ( ( string ) $ object ) ; } else if ( $ object instanceof PermissionInterface ) { $ this -> addPermission ( ( string ) $ object ) ; } else { throw new \ Exception ( sprintf ( "%s must implement one of RoleInterface, '. 'ResourceInterface and PermissionInterface" , $ object ) ) ; } } }
Adds objects lazily .
35,841
public function inherits ( string ... $ roles ) { foreach ( $ roles as $ role ) { if ( ! $ this -> roleRegistry -> exists ( $ role ) ) { throw new \ Exception ( sprintf ( "The role: %s doesnt exist" , ( string ) $ role ) ) ; } $ this -> roleRegistry -> setRegistryValue ( $ this -> session [ "role" ] , $ role ) ; } $ this -> initSession ( ) ; }
Allows roles to inherit from the registries of other roles
35,842
public function allow ( string $ role , string $ permission , string $ resource , bool $ status = null ) { $ status = $ status ?? true ; if ( ! $ this -> roleRegistry -> exists ( $ role ) ) { throw new \ Exception ( sprintf ( "The role: %s doesnt exist" , ( string ) $ role ) ) ; } if ( ! $ this -> permissionRegistry -> exists ( $ permission ) ) { throw new \ Exception ( sprintf ( "The permission: %s doesnt exist" , ( string ) $ permission ) ) ; } if ( ! $ this -> resourceRegistry -> exists ( $ resource ) ) { throw new \ Exception ( sprintf ( "The resource: %s doesnt exist" , ( string ) $ resource ) ) ; } $ this -> globalRegistry -> save ( $ role , $ resource , $ permission , $ status ) ; }
Change the status option of an assigned permission to true
35,843
public function deny ( string $ role , string $ permission , string $ resource ) { $ this -> allow ( $ role , $ permission , $ resource , false ) ; }
Change the status option of an assigned permission to false
35,844
public function getPermissionStatus ( string $ role , string $ permission , string $ resource ) : bool { if ( ! $ this -> roleRegistry -> exists ( $ role ) ) { throw new \ Exception ( sprintf ( "The role: %s doesnt exist" , ( string ) $ role ) ) ; } if ( ! $ this -> permissionRegistry -> exists ( $ permission ) ) { throw new \ Exception ( sprintf ( "The permission: %s doesnt exist" , ( string ) $ permission ) ) ; } if ( ! $ this -> resourceRegistry -> exists ( $ resource ) ) { throw new \ Exception ( sprintf ( "The resource: %s doesnt exist" , ( string ) $ resource ) ) ; } $ roleObject = $ this -> globalRegistry -> get ( $ role ) ; if ( isset ( $ roleObject [ $ resource ] [ $ permission ] [ "status" ] ) ) { return $ roleObject [ $ resource ] [ $ permission ] [ "status" ] ; } $ parents = $ this -> roleRegistry -> getRegistry ( ) [ $ role ] ; foreach ( $ parents as $ parentRole ) { $ permissionStatus = $ this -> getPermissionStatus ( $ parentRole , $ permission , $ resource ) ; if ( $ permissionStatus ) { return true ; } } return false ; }
Retrieve the status of a permission assigned to a role
35,845
private function processMainConfiguration ( array & $ serviceConnArguments , $ resolvedConnConfig ) { if ( array_key_exists ( 'master' , $ serviceConnArguments ) ) { $ this -> replaceConnectionArguments ( $ serviceConnArguments [ 'master' ] , $ resolvedConnConfig ) ; } elseif ( array_key_exists ( 'global' , $ serviceConnArguments ) ) { $ this -> replaceConnectionArguments ( $ serviceConnArguments [ 'global' ] , $ resolvedConnConfig ) ; } else { $ this -> replaceConnectionArguments ( $ serviceConnArguments , $ resolvedConnConfig ) ; } }
Process main configuration for this connection .
35,846
private function processShardConfigurationsIfExist ( array & $ serviceConnArguments , array $ resolvedConnConfig ) { if ( array_key_exists ( 'shards' , $ serviceConnArguments ) ) { foreach ( $ serviceConnArguments [ 'shards' ] as $ shardName => & $ shardConfig ) { $ this -> replaceConnectionArguments ( $ shardConfig , $ resolvedConnConfig [ 'shards' ] [ $ shardName ] ) ; } } }
Process shard configurations if they exist .
35,847
private function processSlaveConfigurationsIfExist ( array & $ serviceConnArguments , array $ resolvedConnConfig ) { if ( array_key_exists ( 'slaves' , $ serviceConnArguments ) ) { foreach ( $ serviceConnArguments [ 'slaves' ] as $ slaveName => & $ slaveConfig ) { $ this -> replaceConnectionArguments ( $ slaveConfig , $ resolvedConnConfig [ 'slaves' ] [ $ slaveName ] ) ; } } }
Process slave configurations if they exist .
35,848
private function replaceConnectionArguments ( array & $ serviceConnArguments , array $ resolvedConnConfig ) { $ serviceConnArguments = $ this -> argumentReplacer -> replaceArgumentIfExists ( $ serviceConnArguments , $ resolvedConnConfig , 'host' ) ; $ serviceConnArguments = $ this -> argumentReplacer -> replaceArgumentIfExists ( $ serviceConnArguments , $ resolvedConnConfig , 'port' ) ; $ serviceConnArguments = $ this -> argumentReplacer -> replaceArgumentIfExists ( $ serviceConnArguments , $ resolvedConnConfig , 'dbname' ) ; $ serviceConnArguments = $ this -> argumentReplacer -> replaceArgumentIfExists ( $ serviceConnArguments , $ resolvedConnConfig , 'user' ) ; $ serviceConnArguments = $ this -> argumentReplacer -> replaceArgumentIfExists ( $ serviceConnArguments , $ resolvedConnConfig , 'password' ) ; $ serviceConnArguments = $ this -> argumentReplacer -> replaceArgumentIfExists ( $ serviceConnArguments , $ resolvedConnConfig , 'url' ) ; }
Replace connection arguments .
35,849
public function generateForm ( array $ data ) { $ form = new $ this -> formClass ; if ( array_key_exists ( 'attributes' , $ data ) ) { $ form -> setAttributes ( $ data [ 'attributes' ] ) ; } if ( array_key_exists ( 'content' , $ data ) ) { $ content = $ this -> generate ( $ data [ 'content' ] ) ; $ form -> setContents ( $ content ) ; } return $ form ; }
Attempts to generate a form from the given
35,850
public function generateInput ( $ type , array $ data ) { $ class = $ this -> getElementInstance ( $ type ) ; if ( array_key_exists ( 'attributes' , $ data ) ) { $ class -> setAttributes ( $ data [ 'attributes' ] ) ; } if ( array_key_exists ( 'content' , $ data ) ) { $ class -> setContents ( $ this -> generate ( $ data [ 'content' ] ) ) ; } if ( array_key_exists ( 'name' , $ data ) ) { $ class -> setName ( $ data [ 'name' ] ) ; } if ( array_key_exists ( 'value' , $ data ) ) { $ class -> setValue ( $ data [ 'value' ] ) ; } if ( array_key_exists ( 'label' , $ data ) ) { $ class -> setLabel ( $ data [ 'label' ] ) ; } return $ class ; }
Attempts to generate an InputElement .
35,851
public function beforeRender ( $ event , $ viewFile ) { if ( Configure :: read ( 'Altair.escape' ) ) { $ event -> getSubject ( ) -> viewVars = $ this -> automate ( $ event -> getSubject ( ) -> viewVars ) ; } }
beforeRender Get the variables that are set in the object
35,852
private function automate ( $ viewVars ) { $ rawDataObj = new \ stdClass ( ) ; foreach ( $ viewVars as $ key => $ var ) { $ rawDataObj -> $ key = $ var ; $ viewVars [ $ key ] = $ this -> escape ( $ var ) ; } $ viewVars [ 'raws' ] = $ rawDataObj ; return $ viewVars ; }
It divides the processing by the type of variable
35,853
private function escapeArray ( $ value ) { if ( ! is_array ( $ value ) ) { return $ this -> escape ( $ value ) ; } foreach ( $ value as $ key => $ prop ) { $ value [ $ key ] = $ this -> escape ( $ prop ) ; } return $ value ; }
Escape recursive the Array type of variable
35,854
private function escapeObject ( $ value ) { if ( ! is_object ( $ value ) ) { return $ value ; } if ( isset ( $ value -> escape ) && $ value -> escape === false ) { return $ value ; } if ( $ value instanceof Entity ) { $ errors = $ value -> getErrors ( ) ; $ invalid = $ value -> getInvalid ( ) ; $ properties = $ value -> visibleProperties ( ) ; foreach ( $ properties as $ prop ) { $ value -> set ( $ prop , $ this -> escape ( $ value -> { $ prop } ) , [ 'setter' => false ] ) ; } foreach ( $ errors as $ field => $ err ) { $ value -> setError ( $ field , $ err ) ; } $ value -> setInvalid ( $ invalid ) ; return $ value ; } if ( $ this -> hasIterator ( $ value ) ) { foreach ( $ value as $ key => $ prop ) { $ value -> { $ key } = $ this -> escape ( $ prop ) ; } return $ value ; } return $ value ; }
Escape recursive the Object type of variable
35,855
private function hasIterator ( $ obj ) { $ hasIterator = false ; foreach ( $ obj as $ key => $ dummy ) { $ hasIterator = true ; break ; } return $ hasIterator ; }
Check that object have iterator
35,856
public static function checkDigitOurNumberAlgorithm ( $ our_number , $ base = 9 ) { $ digit = Utils \ Validation :: mod11 ( $ our_number , $ base ) ; $ digit = ( $ digit > 1 ) ? $ digit - 11 : 0 ; return abs ( $ digit ) ; }
Calculates Our number check digit
35,857
public function getActualValue ( ) { $ val = $ this -> value + ( $ this -> tax_included ? 0 : $ this -> tax_value ) ; return ( float ) $ val ; }
Returns the Title value considering its tax
35,858
public function getCurrencyCode ( ) { if ( ! isset ( $ this -> currency , $ this -> assignment -> bank ) ) { return null ; } return CurrencyCode :: getInstance ( [ 'currency' => $ this -> currency -> id , 'bank' => $ this -> assignment -> bank -> id ] ) ; }
Returns the correct CurrencyCode
35,859
public function getReport ( $ exclude = [ ] ) { $ finder = new Finder ( ) ; $ iter = new ClassIterator ( $ finder -> in ( '.' ) ) ; $ iter -> enableAutoloading ( ) ; $ result = $ this -> getBackendAuditManager ( ) -> checkGeneral ( ) ; foreach ( $ iter -> type ( 'yii\db\ActiveRecord' ) as $ name => $ class ) { if ( in_array ( $ name , $ exclude ) ) { continue ; } $ result [ $ name ] = $ this -> getBackendAuditManager ( ) -> checkModel ( new $ name ) ; } return $ result ; }
For every model found in the application and all modules checks if audit objects exist and are valid .
35,860
public function createRequests ( array $ items , array $ regions ) { foreach ( $ items as $ item ) { foreach ( $ regions as $ region ) { array_push ( $ this -> regionAndItemPairs , [ $ region , $ item ] ) ; array_push ( $ this -> createdRequests , new Request ( 'GET' , 'https://crest-tq.eveonline.com/market/' . $ region . '/history/?type=https://crest-tq.eveonline.com/inventory/types/' . $ item . '/' ) ) ; } } }
Create a set of requests .
35,861
public function getItemHistoryForRegion ( $ howManyItemsBack , $ successCallbackFunction , $ rejectedCallbackFunction ) { $ pool = new Pool ( $ this -> client , $ this -> createdRequests , $ this -> getOptions ( $ howManyItemsBack , $ successCallbackFunction , $ rejectedCallbackFunction ) ) ; $ promise = $ pool -> promise ( ) ; $ promise -> wait ( ) ; }
Get the item history for the a region .
35,862
public static function create ( RouteCollection $ routes , ? string $ prefix = null ) : self { $ uriFactory = new UriFactory ( ) ; return new self ( $ routes , $ uriFactory , $ prefix ) ; }
Creates new URI generator .
35,863
public function generate ( string $ name , array $ attributes = [ ] , ? string $ prefix = null ) : string { $ prefix = $ prefix ?? $ this -> prefix ?? "" ; $ route = $ this -> routes -> oneNamed ( $ name ) ; if ( $ route === null ) { throw RouteNotFound :: named ( $ name ) ; } $ path = $ route -> getPath ( ) ; $ uri = $ this -> uriFactory -> create ( $ path , $ attributes ) ; return $ prefix . $ uri ; }
Generates the URI of route with given name filled with provided attributes and with specified prefix .
35,864
public function setNamespace ( $ namespace ) { if ( $ namespace === null || $ namespace === '' || $ namespace === '\\' ) { $ this -> namespace = null ; return ; } if ( $ namespace [ 0 ] === '\\' ) { $ namespace = substr ( $ namespace , 1 ) ; } if ( $ this -> isNamespaceValid ( $ namespace ) !== true ) { throw new InvalidArgumentException ( 'Namespace name is not valid.' ) ; } $ this -> namespace = $ namespace ; }
Set the namespace name .
35,865
public static function extractNamespaceFromQualifiedName ( $ name ) { if ( ( $ pos = strrpos ( $ name , '\\' ) ) !== false ) { return substr ( $ name , 0 , $ pos ) ; } else { return null ; } }
Extract the namespace from the a fully qualified name .
35,866
protected function getView ( Medools \ Model $ model ) { $ assignment = $ model -> assignment ; $ view_class = __NAMESPACE__ . "\\Views\\Cnab$assignment->cnab\\" . BankInterchange \ Utils :: toPascalCase ( $ assignment -> bank -> name ) ; return new $ view_class ( $ model ) ; }
Returns a ShippingFile View
35,867
public static function withBillets ( Resource $ resource ) { $ controller = new static ; $ list = $ resource -> getList ( ) ; if ( empty ( $ list ) ) { return false ; } foreach ( $ list as $ id ) { if ( ! $ controller -> generate ( $ id ) ) { return false ; } $ title_list = BankInterchange \ Models \ Title :: dump ( [ 'shipping_file' => $ id [ 'id' ] ] , BankInterchange \ Models \ Title :: PRIMARY_KEY ) ; $ bankbillet = new BankInterchange \ BankBillet \ Controller ; foreach ( $ title_list as $ title_id ) { if ( ! $ bankbillet -> generate ( $ title_id ) ) { return false ; } } $ billets = $ bankbillet -> dump ( ) ?? [ ] ; if ( $ resource -> kind === 'collection' ) { $ model = ( static :: MODEL_CLASS ) :: getInstance ( $ id ) ; $ directory = "{$model->assignment->id}-$model->counter/" ; $ current = count ( $ controller -> views ) - 1 ; $ filename = $ controller -> views [ $ current ] [ 'name' ] ; $ controller -> views [ $ current ] [ 'name' ] = $ directory . $ filename ; foreach ( $ billets as $ billet_id => $ billet ) { $ billets [ $ billet_id ] [ 'name' ] = $ directory . $ billet [ 'name' ] ; } } $ controller -> views = array_merge ( $ controller -> views , $ billets ) ; } $ controller -> zip ( ) ; return true ; }
Creates a zip file with shipping files and their billets
35,868
public function renderCreateColumns ( ) { $ columns = $ this -> getTableColumns ( ) ; if ( ! $ columns ) { return '' ; } $ source = '' ; foreach ( $ columns as $ column ) { $ attributes = [ $ this -> serializeArrayToAttributes ( $ column -> getName ( ) ) ] ; $ type = $ column -> getType ( ) -> getName ( ) ; switch ( $ type ) { case Type :: INTEGER : $ method = 'integer' ; break ; case Type :: SMALLINT : $ method = 'smallInteger' ; break ; case Type :: BIGINT : $ method = 'bigInteger' ; break ; case Type :: STRING : $ attributes [ ] = $ column -> getLength ( ) ; $ method = 'string' ; break ; case Type :: GUID : case Type :: TEXT : $ method = 'text' ; break ; case Type :: FLOAT : $ method = 'float' ; break ; case Type :: DECIMAL : $ attributes [ ] = $ column -> getPrecision ( ) ; $ attributes [ ] = $ column -> getScale ( ) ; $ method = 'decimal' ; break ; case Type :: BOOLEAN : $ method = 'boolean' ; break ; case Type :: DATETIME : case Type :: DATETIMETZ : $ method = 'dateTime' ; break ; case Type :: DATE : $ method = 'date' ; break ; case Type :: TIME : $ method = 'time' ; break ; case Type :: BINARY : case Type :: BLOB : $ method = 'binary' ; break ; case Type :: JSON_ARRAY : $ method = 'json' ; break ; default : throw new DbExporterException ( 'Not supported database column type' . $ type ) ; break ; } $ source .= '$table->' . $ method . '(' . implode ( ', ' , $ attributes ) . ')' ; if ( $ column -> getUnsigned ( ) ) { $ source .= "\n" . ' ->unsigned()' ; } if ( ! $ column -> getNotnull ( ) ) { $ source .= "\n" . ' ->nullable()' ; } if ( $ column -> getDefault ( ) || $ column -> getDefault ( ) === null && ! $ column -> getNotnull ( ) ) { $ source .= "\n" . ' ->default(' . var_export ( $ column -> getDefault ( ) , true ) . ')' ; } $ source .= ';' . "\n" ; } return trim ( $ source ) ; }
Render table columns create schema builder methods
35,869
public function renderCreateIndexes ( ) { $ indexes = $ this -> getTableIndexes ( ) ; if ( ! $ indexes ) { return '' ; } $ source = '' ; foreach ( $ indexes as $ index ) { $ columns = $ this -> serializeArrayToAttributes ( $ index -> getColumns ( ) ) ; $ name = $ this -> serializeIndexNameToAttribute ( $ index -> getName ( ) ) ; if ( $ index -> isPrimary ( ) ) { $ source .= "\n" . '$table->primary(' . $ columns . ', ' . $ name . ');' ; } elseif ( $ index -> isUnique ( ) ) { $ source .= "\n" . '$table->unique(' . $ columns . ', ' . $ name . ');' ; } else { $ source .= "\n" . '$table->index(' . $ columns . ', ' . $ name . ');' ; } } return trim ( $ source ) ; }
Render table indexes create schema builder methods
35,870
public function renderCreateForeignKeys ( ) { $ foreignKeys = $ this -> getTableForeignKeys ( ) ; if ( ! $ foreignKeys ) { return '' ; } $ source = '' ; foreach ( $ foreignKeys as $ foreignKey ) { $ name = $ this -> serializeIndexNameToAttribute ( $ foreignKey -> getName ( ) ) ; $ localColumns = $ this -> serializeArrayToAttributes ( $ foreignKey -> getLocalColumns ( ) ) ; $ foreignColumns = $ this -> serializeArrayToAttributes ( $ foreignKey -> getForeignColumns ( ) ) ; $ foreignTableName = '\'' . snake_case ( $ foreignKey -> getForeignTableName ( ) ) . '\'' ; $ source .= "\n" . '$table->foreign(' . $ localColumns . ', ' . $ name . ')' ; $ source .= "\n" . ' ->references(' . $ foreignColumns . ')' ; $ source .= "\n" . ' ->on(' . $ foreignTableName . ')' ; if ( ( $ onDelete = $ foreignKey -> getOption ( 'onUpdate' ) ) !== null ) { $ onDelete = var_export ( $ onDelete , true ) ; $ source .= "\n" . ' ->onUpdate(' . $ onDelete . ')' ; } if ( ( $ onUpdate = $ foreignKey -> getOption ( 'onDelete' ) ) !== null ) { $ onUpdate = var_export ( $ onUpdate , true ) ; $ source .= "\n" . ' ->onUpdate(' . $ onUpdate . ')' ; } $ source .= ';' . "\n" ; } return trim ( $ source ) ; }
Render table foreign keys create schema builder methods
35,871
public function renderDropForeignKeys ( ) { $ foreignKeys = $ this -> getTableForeignKeys ( ) ; if ( ! $ foreignKeys ) { return '' ; } $ source = '' ; foreach ( $ foreignKeys as $ foreignKey ) { $ name = $ this -> serializeIndexNameToAttribute ( $ foreignKey -> getName ( ) ) ; $ source .= "\n" . '$table->dropForeign(' . $ name . ');' ; } return trim ( $ source ) ; }
Render table foreign keys drop schema builder methods
35,872
public function orderConfirmationAction ( Request $ request , $ id ) { $ locale = $ this -> getLocaleManager ( ) -> retrieveLocale ( $ this -> getUser ( ) , $ request -> get ( 'locale' ) ) ; $ this -> get ( 'translator' ) -> setLocale ( $ locale ) ; try { $ orderApiEntity = $ this -> getOrderManager ( ) -> findByIdAndLocale ( $ id , $ locale , false ) ; $ order = $ orderApiEntity -> getEntity ( ) ; } catch ( OrderNotFoundException $ exc ) { throw new OrderNotFoundException ( $ id ) ; } $ pdf = $ this -> getOrderPdfManager ( ) -> createOrderConfirmation ( $ orderApiEntity ) ; $ pdfName = $ this -> getOrderPdfManager ( ) -> getPdfName ( $ order , true ) ; $ responseType = $ this -> container -> getParameter ( 'sulu_sales_order.pdf_response_type' ) ; return new Response ( $ pdf , 200 , [ 'Content-Type' => 'application/pdf' , 'Content-Disposition' => sprintf ( '%s; filename="%s"' , $ responseType , $ pdfName ) , ] ) ; }
Finds an order object by a given id from the url and returns a rendered pdf in a download window .
35,873
public function orderPdfAction ( Request $ request , $ id ) { $ locale = $ request -> getLocale ( ) ; $ this -> get ( 'translator' ) -> setLocale ( $ locale ) ; $ orderApiEntity = $ this -> getOrderManager ( ) -> findByIdAndLocale ( $ id , $ locale , false ) ; $ order = $ orderApiEntity -> getEntity ( ) ; $ pdf = $ this -> getOrderPdfManager ( ) -> createOrderPdfDynamically ( $ orderApiEntity ) ; $ pdfName = $ this -> getOrderPdfManager ( ) -> getPdfName ( $ order , false ) ; $ responseType = $ this -> container -> getParameter ( 'sulu_sales_order.pdf_response_type' ) ; return new Response ( $ pdf , 200 , [ 'Content-Type' => 'application/pdf' , 'Content-Disposition' => sprintf ( '%s; filename="%s"' , $ responseType , $ pdfName ) , ] ) ; }
Finds an order object by a given id from the url and renders a configurable template . Then returns it as pdf in a new tab .
35,874
public static function isNumericallyIndexed ( array $ values ) : bool { if ( empty ( $ values ) ) { return true ; } reset ( $ values ) ; return is_int ( key ( $ values ) ) ; }
Find out if the given array is numerically indexed?
35,875
protected function fetchDocumentData ( $ options ) { $ documents = $ this -> dependencyManager -> getDocuments ( $ options [ 'orderId' ] , $ options [ 'locale' ] ) ; if ( ! empty ( $ documents ) ) { foreach ( $ documents as $ document ) { $ data = $ document -> getSalesDocumentData ( ) ; parent :: addEntry ( $ this -> getProperty ( $ data , 'id' ) , $ this -> getProperty ( $ data , 'number' ) , $ this -> getProperty ( $ data , 'icon' ) , $ this -> getProperty ( $ data , 'date' ) , parent :: getRoute ( $ data [ 'id' ] , $ data [ 'type' ] , 'details' ) , $ this -> getProperty ( $ data , 'pdfBaseUrl' ) , $ this -> getProperty ( $ data , 'translationKey' ) ) ; } } }
Retrieves document data for a specific order and adds it to the entries .
35,876
public function fetch ( $ page = 1 , $ perPage = 15 , array $ columns = [ '*' ] , array $ filter = [ ] , array $ sort = [ ] ) { $ this -> instance = $ this -> repository -> makeQuery ( ) ; $ this -> multiFilterBy ( $ filter ) -> multiSortBy ( $ sort ) ; $ this -> parseAliases ( $ this -> instance ) ; $ count = $ this -> instance -> count ( ) ; $ items = $ this -> instance -> forPage ( $ page , $ perPage ) -> get ( $ columns ) ; $ options = [ 'path' => $ this -> app -> make ( 'request' ) -> url ( ) , 'query' => compact ( 'page' , 'perPage' ) , ] ; return new LengthAwarePaginator ( $ items , $ count , $ perPage , $ page , $ options ) ; }
Fetch collection ordered and filtrated by specified columns for specified page as paginator .
35,877
protected function parseAliases ( Builder $ query ) { $ aliases = [ ] ; if ( ! empty ( $ query -> getQuery ( ) -> columns ) ) { $ aliases = $ this -> getAliases ( $ query ) ; } if ( ! empty ( $ aliases ) && ! empty ( $ query -> getQuery ( ) -> wheres ) ) { $ this -> replaceAliases ( $ query , $ aliases ) ; } return $ query ; }
Replace alias name in where closure with sub - queries from select .
35,878
protected function getAliases ( Builder $ query ) { $ aliases = [ ] ; foreach ( $ query -> getQuery ( ) -> columns as $ column ) { if ( preg_match ( "~AS (\w+)~i" , $ column , $ matches ) ) { $ aliases [ $ query -> getModel ( ) -> getTable ( ) . '.' . $ matches [ 1 ] ] = \ DB :: raw ( str_replace ( $ matches [ 0 ] , '' , $ column ) ) ; } } return $ aliases ; }
Get sub queries and aliases from select statement .
35,879
protected function replaceAliases ( Builder $ query , $ aliases ) { foreach ( $ query -> getQuery ( ) -> wheres as $ key => $ value ) { if ( in_array ( $ value [ 'column' ] , array_keys ( $ aliases ) ) ) { $ query -> getQuery ( ) -> wheres [ $ key ] [ 'column' ] = $ aliases [ $ value [ 'column' ] ] ; } } }
Replace aliases in where statement with sub queries .
35,880
public function setIndentationLevel ( $ value ) { if ( $ value < 0 || ( ! is_string ( $ value ) && is_infinite ( $ value ) ) ) { throw new Exceptions \ InvalidArgumentException ( 'The indentation level can not be negative or infinite.' ) ; } $ this -> indentationLevel = intval ( $ value ) ; return $ this ; }
Set current indentation level .
35,881
public function addIndentationLevel ( $ value ) { $ this -> indentationLevel = max ( 0 , $ this -> indentationLevel + ( int ) $ value ) ; return $ this ; }
Add an indentation level on the current level .
35,882
function convert ( $ source ) { $ this -> onConvert ( ) ; $ lines = explode ( PHP_EOL , $ source ) ; $ sectionName = null ; $ msgid = null ; $ msgstr = null ; foreach ( $ lines as $ line ) { if ( ! empty ( $ line ) ) { if ( $ line [ 0 ] === '#' ) { if ( $ msgid != null ) { $ this -> onEntry ( $ msgid , $ msgstr ) ; } if ( $ sectionName !== null ) { $ this -> afterSection ( $ sectionName ) ; } $ sectionName = trim ( str_replace ( '#' , '' , $ line ) ) ; $ msgid = null ; $ msgstr = null ; $ this -> beforeSection ( $ sectionName ) ; } elseif ( substr ( $ line , 0 , 6 ) === 'msgid ' ) { if ( $ msgid != null ) { $ this -> onEntry ( $ msgid , $ msgstr ) ; } preg_match ( '/^msgid \"(.*)\"\s*$/' , $ line , $ matches ) ; $ msgid = $ matches [ 1 ] ; $ msgstr = null ; } elseif ( substr ( $ line , 0 , 7 ) === 'msgstr ' ) { preg_match ( '/^msgstr \"(.*)\"\s*$/' , $ line , $ matches ) ; $ msgstr = $ matches [ 1 ] ; } elseif ( preg_match ( '/^\s*\"(.*)\"\s*$/' , $ line , $ matches ) ) { if ( $ msgstr === null ) { $ msgid .= $ matches [ 1 ] ; } else { $ msgstr .= $ matches [ 1 ] ; } } } } if ( $ msgid != null ) { $ this -> onEntry ( $ msgid , $ msgstr ) ; } if ( $ sectionName !== null ) { $ this -> afterSection ( $ sectionName ) ; } return $ this -> toString ( ) ; }
This method convert from a format to another .
35,883
public function multiSortBy ( array $ columns ) { foreach ( $ columns as $ column => $ direction ) { if ( strpos ( $ column , '.' ) ) { $ this -> sortByRelation ( $ column , $ direction ) ; } else { $ this -> sortBy ( $ column , $ direction ) ; } } return $ this ; }
Append many column sorting to query builder .
35,884
public function sortByRelation ( $ column , $ direction = 'ASC' ) { $ relations = explode ( '.' , $ column ) ; $ column = array_pop ( $ relations ) ; $ model = $ this -> repository -> makeModel ( ) ; $ this -> instance -> getQuery ( ) -> orders = [ ] ; foreach ( $ relations as $ relation ) { $ this -> joinRelation ( $ relationClass = $ model -> { camel_case ( $ relation ) } ( ) ) ; $ model = $ relationClass -> getRelated ( ) ; } $ selectedColumns = $ this -> instance -> getQuery ( ) -> columns ; $ addColumn = DB :: raw ( "{$this->repository->makeModel()->getTable()}.*" ) ; if ( is_array ( $ selectedColumns ) && array_search ( '*' , $ selectedColumns , true ) !== null ) { $ this -> instance -> getQuery ( ) -> columns [ array_search ( '*' , $ selectedColumns , true ) ] = $ addColumn ; } else { $ this -> instance -> select ( $ addColumn ) ; } $ this -> instance -> orderBy ( "{$model->getTable()}.{$column}" , $ direction ) ; return $ this ; }
Append relation column sorting to query builder .
35,885
protected function joinRelation ( Relation $ relationClass ) { switch ( get_class ( $ relationClass ) ) { case BelongsToMany :: class : $ this -> joinBelongsToMany ( $ relationClass ) ; break ; case BelongsTo :: class : $ this -> joinBelongsTo ( $ relationClass ) ; break ; case HasOne :: class : case HasMany :: class : $ this -> joinHasOneOrMany ( $ relationClass ) ; break ; } }
Add joining the tables to query based on the type of relationship .
35,886
protected function joinBelongsToMany ( BelongsToMany $ relation ) { return $ this -> instance -> join ( $ relation -> getTable ( ) , $ relation -> getParent ( ) -> getTable ( ) . '.' . $ relation -> getParent ( ) -> getKeyName ( ) , '=' , $ relation -> getForeignKey ( ) ) -> join ( $ relation -> getRelated ( ) -> getTable ( ) , $ relation -> getRelated ( ) -> getTable ( ) . '.' . $ relation -> getRelated ( ) -> getKeyName ( ) , '=' , $ relation -> getOtherKey ( ) ) ; }
Join a belongs to many relationship .
35,887
protected function joinBelongsTo ( BelongsTo $ relation ) { return $ this -> instance -> join ( $ relation -> getRelated ( ) -> getTable ( ) , $ relation -> getQualifiedOtherKeyName ( ) , '=' , $ relation -> getQualifiedForeignKey ( ) ) ; }
Join a belongs to relationship .
35,888
protected function joinHasOneOrMany ( HasOneOrMany $ relation ) { return $ this -> instance -> join ( $ relation -> getRelated ( ) -> getTable ( ) , $ relation -> getRelated ( ) -> getTable ( ) . '.' . $ relation -> getParent ( ) -> getForeignKey ( ) , '=' , $ relation -> getParent ( ) -> getTable ( ) . '.' . $ relation -> getParent ( ) -> getKeyName ( ) ) ; }
Join a has one relationship .
35,889
public function formatWithoutCurrency ( $ value ) { $ formatter = new NumberFormatter ( $ this -> locale ( ) , NumberFormatter :: DECIMAL ) ; $ code = $ this -> code ( $ value ) ; $ divisor = $ this -> divisor ( $ code ) ; $ amount = $ this -> convert ( $ value , $ divisor ) ; return $ formatter -> formatCurrency ( $ amount , $ code ) ; }
Format an input to a price without currency
35,890
public function trigger ( $ event , $ object ) { if ( $ this -> _corked ) { $ this -> _queue [ ] = func_get_args ( ) ; } else { foreach ( ( array ) $ event as $ e ) { $ callbacks = $ this -> _callbacksFor ( $ e ) ; foreach ( $ callbacks as $ callback ) call_user_func ( $ callback , $ e , $ object ) ; } if ( isset ( $ this -> _upstream ) ) $ this -> _upstream -> trigger ( $ event , $ object ) ; } return $ this ; }
Triggers an event against the registered handlers
35,891
public function unregister ( $ event = null ) { if ( ! empty ( $ event ) && $ event != '*' ) $ this -> _handlers [ $ event ] = array ( ) ; else $ this -> _handlers = array ( ) ; return $ this ; }
Unregisters an event handler based on event or all
35,892
public function setDefaultMode ( string $ mode = null ) : RauthInterface { if ( ! in_array ( $ mode , self :: MODES ) ) { throw new \ InvalidArgumentException ( 'Mode ' . $ mode . ' not accepted!' ) ; } $ this -> defaultMode = $ mode ; return $ this ; }
Set a default mode for auth blocks without one defined .
35,893
private function normalize ( array $ matches ) : array { $ keys = $ matches [ 1 ] ; $ values = $ matches [ 2 ] ; $ return = [ ] ; foreach ( $ keys as $ i => $ key ) { $ key = strtolower ( trim ( $ key ) ) ; if ( $ key == 'mode' ) { $ value = strtolower ( $ values [ $ i ] ) ; } else { $ value = array_map ( function ( $ el ) { return trim ( $ el , ', ' ) ; } , explode ( ',' , $ values [ $ i ] ) ) ; } $ return [ $ key ] = $ value ; } return $ return ; }
Turns a pregexed array of auth blocks into a decent array
35,894
public function authorize ( $ class , string $ method = null , array $ attr = [ ] ) : bool { $ auth = $ this -> extractAuth ( $ class , $ method ) ; if ( empty ( $ auth ) ) { return true ; } $ mode = $ auth [ 'mode' ] ?? $ this -> defaultMode ; $ e = new AuthException ( $ mode ) ; unset ( $ auth [ 'mode' ] ) ; $ this -> handleBans ( $ auth , $ attr ) ; switch ( $ mode ) { case self :: MODE_AND : foreach ( $ auth as $ set => $ values ) { if ( ! isset ( $ attr [ $ set ] ) ) { $ e -> addReason ( new Reason ( $ set , [ ] , $ values ) ) ; } else { $ attr [ $ set ] = ( array ) $ attr [ $ set ] ; sort ( $ values ) ; sort ( $ attr [ $ set ] ) ; if ( $ values != $ attr [ $ set ] ) { $ e -> addReason ( new Reason ( $ set , $ attr [ $ set ] , $ values ) ) ; } } } if ( $ e -> hasReasons ( ) ) { throw $ e ; } return true ; case self :: MODE_NONE : foreach ( $ auth as $ set => $ values ) { if ( isset ( $ attr [ $ set ] ) && count ( array_intersect ( ( array ) $ attr [ $ set ] , $ values ) ) ) { $ e -> addReason ( new Reason ( $ set , ( array ) ( $ attr [ $ set ] ?? [ ] ) , $ values ) ) ; } } if ( $ e -> hasReasons ( ) ) { throw $ e ; } return true ; case self :: MODE_OR : foreach ( $ auth as $ set => $ values ) { if ( isset ( $ attr [ $ set ] ) && count ( array_intersect ( ( array ) $ attr [ $ set ] , $ values ) ) ) { return true ; } $ e -> addReason ( new Reason ( $ set , ( array ) ( $ attr [ $ set ] ?? [ ] ) , $ values ) ) ; } throw $ e ; default : throw new \ InvalidArgumentException ( 'Durrrr' ) ; } }
Either passes or fails an authorization attempt .
35,895
public static function prepare_attr_value ( $ text ) { if ( is_array ( $ text ) ) { foreach ( $ text as & $ t ) { $ t = static :: prepare_attr_value ( $ t ) ; } return $ text ; } return strtr ( $ text , [ '&' => '&amp;' , '"' => '&quot;' , '\'' => '&apos;' , '<' => '&lt;' , '>' => '&gt;' ] ) ; }
Prepare text to be used as value for html attribute value
35,896
protected static function wrap ( $ in , $ data , $ tag ) { $ data = static :: smart_array_merge ( is_array ( $ in ) ? $ in : [ 'in' => $ in ] , is_array ( $ data ) ? $ data : [ ] ) ; $ in = $ attributes = '' ; $ level = 1 ; if ( isset ( $ data [ 'level' ] ) ) { $ level = $ data [ 'level' ] ; unset ( $ data [ 'level' ] ) ; } static :: pre_processing ( $ tag , $ data ) ; if ( ! static :: data_prepare ( $ data , $ tag , $ in , $ attributes ) ) { return false ; } if ( ! $ in && $ in !== 0 && $ in !== '0' ) { $ in = '' ; } elseif ( $ level && ( strpos ( $ in , "\n" ) !== false || strpos ( $ in , '<' ) !== false ) ) { $ in = "\n" . static :: level ( "$in\n" , $ level ) ; } return "<$tag$attributes>$in</$tag>" . ( $ level ? "\n" : '' ) ; }
Wrapper for paired tags rendering
35,897
protected static function u_wrap ( $ data , $ tag ) { $ in = $ attributes = '' ; static :: pre_processing ( $ tag , $ data ) ; if ( ! static :: data_prepare ( $ data , $ tag , $ in , $ attributes ) ) { return false ; } return "<$tag$attributes>" . ( $ in ? " $in" : '' ) . "\n" ; }
Wrapper for unpaired tags rendering
35,898
public static function form ( $ in = '' , $ data = [ ] ) { if ( isset ( $ in [ 'insert' ] ) || isset ( $ data [ 'insert' ] ) ) { return static :: __callStatic_internal ( __FUNCTION__ , func_get_args ( ) ) ; } if ( $ in === false ) { return '' ; } if ( is_array ( $ in ) ) { return static :: __callStatic_internal ( __FUNCTION__ , [ $ in , $ data ] ) ; } if ( isset ( $ in [ 'method' ] ) ) { $ data [ 'method' ] = $ in [ 'method' ] ; } if ( ! isset ( $ data [ 'method' ] ) ) { $ data [ 'method' ] = 'post' ; } if ( strtolower ( $ data [ 'method' ] ) == 'post' ) { if ( ! is_array ( $ in ) ) { $ in .= static :: form_csrf ( ) ; } else { $ in [ 'in' ] .= static :: form_csrf ( ) ; } } return static :: wrap ( $ in , $ data , __FUNCTION__ ) ; }
Rendering of form tag default method is post if form method is post - special session key in hidden input is added for security .
35,899
protected static function select_common_normalize ( $ in ) { $ has_in = isset ( $ in [ 'in' ] ) ; $ has_value = isset ( $ in [ 'value' ] ) ; if ( ! $ has_value && $ has_in && is_array ( $ in [ 'in' ] ) ) { $ in [ 'value' ] = & $ in [ 'in' ] ; } elseif ( ! $ has_in && $ has_value && is_array ( $ in [ 'value' ] ) ) { $ in [ 'in' ] = & $ in [ 'value' ] ; } elseif ( ( ! $ has_in || ! is_array ( $ in [ 'in' ] ) ) && ( ! $ has_value || ! is_array ( $ in [ 'value' ] ) ) ) { $ in = [ 'in' => $ in , 'value' => $ in ] ; } return $ in ; }
Ensures that both in and value elements are present in array