idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
35,900 | public static function button ( $ 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 ( is_array ( $ in ) ) { if ( ! isset ( $ in [ 'type' ] ) ) { $ in [ 'type' ] = 'button' ; } } elseif ( is_array ( $ data ) ) { if ( ! isset ( $ data [ 'type' ] ) ) { $ data [ 'type' ] = 'button' ; } } return static :: wrap ( $ in , $ data , __FUNCTION__ ) ; } | Rendering of button tag if button type is not specified - it will be button type |
35,901 | protected static function smart_array_merge ( $ array1 , $ array2 ) { if ( isset ( $ array1 [ 'class' ] , $ array2 [ 'class' ] ) ) { $ array1 [ 'class' ] .= " $array2[class]" ; unset ( $ array2 [ 'class' ] ) ; } if ( isset ( $ array1 [ 'style' ] , $ array2 [ 'style' ] ) ) { $ array1 [ 'style' ] = trim ( $ array1 [ 'style' ] , ';' ) . ";$array2[style]" ; unset ( $ array2 [ 'style' ] ) ; } return array_merge ( $ array1 , $ array2 ) ; } | Merging of arrays but joining all class and style items supports only 2 arrays as input |
35,902 | protected static function __callStatic_fast_render ( $ selector , $ data ) { if ( is_array ( $ data ) && isset ( $ data [ 0 ] ) && count ( $ data ) == 1 && strpos ( $ selector , ' ' ) === false && strpos ( $ selector , '[' ) === false && strpos ( $ selector , '.' ) === false && strpos ( $ selector , '#' ) === false ) { if ( is_scalar ( $ data [ 0 ] ) ) { return static :: render_tag ( $ selector , $ data [ 0 ] , [ ] ) ; } if ( ! isset ( $ data [ 0 ] [ 'in' ] ) && ! isset ( $ data [ 0 ] [ 'insert' ] ) && static :: is_array_assoc ( $ data [ 0 ] ) ) { return static :: render_tag ( $ selector , '' , $ data [ 0 ] ) ; } } return null ; } | Trying to render faster many practical use cases fit here so overhead should worth it |
35,903 | public function setFields ( $ fields = [ ] ) { $ existingSchema = $ this -> get ( ) ; $ request = [ ] ; foreach ( $ fields as $ field ) { $ mode = $ this -> hasField ( $ field [ 'name' ] , $ existingSchema ) ? 'replace-field' : 'add-field' ; $ request [ $ mode ] [ ] = $ field ; } return $ this -> request ( $ request ) ; } | Update field definition if field exists otherwise add |
35,904 | public function hasField ( $ fieldName , $ existingSchema = null ) { $ field = $ this -> getField ( $ fieldName , $ existingSchema ) ; return $ field === null ? false : true ; } | Check if a field already exists in the schema |
35,905 | public static function IVCreate ( ) { return base64_encode ( mcrypt_create_iv ( mcrypt_get_iv_size ( self :: $ crypt_cipher , self :: $ crypt_mode ) , self :: $ crypt_rand ) ) ; } | generate usable IV for config |
35,906 | public static function keyCreate ( ) { return base64_encode ( mcrypt_create_iv ( mcrypt_get_key_size ( self :: $ crypt_cipher , self :: $ crypt_mode ) , self :: $ crypt_rand ) ) ; } | generate usable key for config |
35,907 | protected function verifyKey ( ) { $ key_size = mcrypt_get_key_size ( self :: $ crypt_cipher , self :: $ crypt_mode ) ; if ( ! isset ( $ this -> key ) || is_null ( $ this -> key ) ) { throw new Exception ( 'No encryption key defined in config' ) ; } if ( strlen ( base64_decode ( $ this -> key ) ) < $ key_size ) { throw new Exception ( 'Encryption key is too short, required length: ' . $ key_size ) ; } return true ; } | verify existence and size of key |
35,908 | protected function verifyIV ( ) { $ iv_size = mcrypt_get_iv_size ( self :: $ crypt_cipher , self :: $ crypt_mode ) ; if ( ! isset ( $ this -> iv ) || is_null ( $ this -> iv ) ) { throw new Exception ( 'No IV key defined in config' ) ; } if ( strlen ( base64_decode ( $ this -> iv ) ) < $ iv_size ) { throw new Exception ( 'Encryption IV is too shorted, required length: ' . $ iv_size ) ; } return true ; } | verify existencve and size of iv |
35,909 | public function encrypt ( $ plain_string , $ base64_encode = true ) { if ( ! $ this -> verified ) $ this -> verify ( ) ; $ size = pack ( 'N' , strlen ( $ plain_string ) ) ; $ plain_string = $ size . $ plain_string ; $ enc_string = mcrypt_encrypt ( self :: $ crypt_cipher , base64_decode ( $ this -> key ) , $ plain_string , self :: $ crypt_mode , base64_decode ( $ this -> iv ) ) ; if ( $ base64_encode ) return base64_encode ( $ enc_string ) ; return $ enc_string ; } | encrypt string and optionally base64_encode |
35,910 | function decrypt ( $ enc_string , $ base64_decode = true ) { if ( is_null ( $ enc_string ) || empty ( $ enc_string ) ) return NULL ; if ( ! $ this -> verified ) $ this -> verify ( ) ; if ( $ base64_decode ) $ enc_string = base64_decode ( $ enc_string ) ; $ plain_string = mcrypt_decrypt ( self :: $ crypt_cipher , base64_decode ( $ this -> key ) , $ enc_string , self :: $ crypt_mode , base64_decode ( $ this -> iv ) ) ; $ size = unpack ( 'N' , substr ( $ plain_string , 0 , 4 ) ) ; $ size = array_shift ( $ size ) ; $ plain_string = substr ( $ plain_string , 4 , $ size ) ; return $ plain_string ; } | decrypt string from an optionally base64_encoded source |
35,911 | protected function loadViews ( ) { $ view_path = __DIR__ . '/../resources/views' ; $ this -> loadViewsFrom ( $ view_path , 'crudapi' ) ; $ this -> publishes ( [ $ view_path => base_path ( 'resources/views/Taskforcedev/crudapi' ) , ] , 'crudapi-views' ) ; } | Load the packages views . |
35,912 | protected function log ( $ message , $ level = Logger :: INFO ) { $ this -> logger -> log ( $ message , $ level ) ; } | Log a message via the logger |
35,913 | public function getConsumedReadUnits ( $ table = null ) { if ( is_null ( $ table ) ) { return array_sum ( $ this -> readUnit ) ; } else { return ( isset ( $ this -> readUnit [ $ table ] ) ? $ this -> readUnit [ $ table ] : 0 ) ; } } | Return the number of read units consumed |
35,914 | protected function addConsumedReadUnits ( $ table , $ units ) { if ( null !== $ this -> logger ) { $ this -> log ( $ units . ' consumed read units on table ' . $ table ) ; } if ( isset ( $ this -> readUnit [ $ table ] ) ) { $ this -> readUnit [ $ table ] += $ units ; } else { $ this -> readUnit [ $ table ] = $ units ; } } | Update the Read Units counter |
35,915 | public function getConsumedWriteUnits ( $ table = null ) { if ( is_null ( $ table ) ) { return array_sum ( $ this -> writeUnit ) ; } else { return ( isset ( $ this -> writeUnit [ $ table ] ) ? $ this -> writeUnit [ $ table ] : 0 ) ; } } | Return the number of write units consumed |
35,916 | protected function addConsumedWriteUnits ( $ table , $ units ) { if ( null !== $ this -> logger ) { $ this -> log ( $ units . ' consumed write units on table ' . $ table ) ; } if ( isset ( $ this -> writeUnit [ $ table ] ) ) { $ this -> writeUnit [ $ table ] += $ units ; } else { $ this -> writeUnit [ $ table ] = $ units ; } } | Update the Write Units counter |
35,917 | public function resetConsumedUnits ( $ table = null ) { if ( is_null ( $ table ) ) { if ( null !== $ this -> logger ) { $ this -> log ( 'Reset all consumed units counters' ) ; } $ this -> readUnit = array ( ) ; $ this -> writeUnit = array ( ) ; } else { if ( null !== $ this -> logger ) { $ this -> log ( 'Reset consumed units counters for table ' . $ table ) ; } unset ( $ this -> readUnit [ $ table ] , $ this -> writeUnit [ $ table ] ) ; } } | Reset the read and write unit counter |
35,918 | public function put ( Item $ item , Context \ Put $ context = null ) { $ table = $ item -> getTable ( ) ; if ( null !== $ this -> logger ) { $ this -> log ( 'Put on table ' . $ table ) ; } if ( empty ( $ table ) ) { throw new \ Riverline \ DynamoDB \ Exception \ AttributesException ( 'Item do not have table defined' ) ; } $ attributes = array ( ) ; foreach ( $ item as $ name => $ attribute ) { if ( "" !== $ attribute -> getValue ( ) ) { $ attributes [ $ name ] = $ attribute -> getForDynamoDB ( ) ; } } $ parameters = array ( 'TableName' => $ table , 'Item' => $ attributes , ) ; if ( null !== $ context ) { $ parameters += $ context -> getForDynamoDB ( ) ; } if ( null !== $ this -> logger ) { $ this -> log ( 'Put request paramaters : ' . print_r ( $ parameters , true ) , Logger :: DEBUG ) ; } $ response = $ this -> connector -> putItem ( $ parameters ) ; if ( null !== $ this -> logger ) { $ this -> log ( 'Put request response : ' . print_r ( $ response , true ) , Logger :: DEBUG ) ; } $ this -> addConsumedWriteUnits ( $ table , floatval ( $ response [ 'ConsumedCapacityUnits' ] ) ) ; return $ this -> populateAttributes ( $ response ) ; } | Add an item to DynamoDB via the put_item call |
35,919 | public function delete ( $ table , $ hash , $ range = null , Context \ Delete $ context = null ) { if ( null !== $ this -> logger ) { $ this -> log ( 'Delete on table ' . $ table ) ; } $ hash = new Attribute ( $ hash ) ; $ key = array ( 'HashKeyElement' => $ hash -> getForDynamoDB ( ) ) ; if ( null !== $ range ) { $ range = new Attribute ( $ range ) ; $ key [ 'RangeKeyElement' ] = $ range -> getForDynamoDB ( ) ; } $ parameters = array ( 'TableName' => $ table , 'Key' => $ key ) ; if ( null !== $ context ) { $ parameters += $ context -> getForDynamoDB ( ) ; } if ( null !== $ this -> logger ) { $ this -> log ( 'Delete request paramaters : ' . print_r ( $ parameters , true ) , Logger :: DEBUG ) ; } $ response = $ this -> connector -> deleteItem ( $ parameters ) ; if ( null !== $ this -> logger ) { $ this -> log ( 'Delete request response : ' . print_r ( $ response , true ) , Logger :: DEBUG ) ; } $ this -> addConsumedWriteUnits ( $ table , floatval ( $ response [ 'ConsumedCapacityUnits' ] ) ) ; return $ this -> populateAttributes ( $ response ) ; } | Delete an item via the delete_item call |
35,920 | public function get ( $ table , $ hash , $ range = null , Context \ Get $ context = null ) { if ( null !== $ this -> logger ) { $ this -> log ( 'Get on table ' . $ table ) ; } $ hash = new Attribute ( $ hash ) ; $ parameters = array ( 'TableName' => $ table , 'Key' => array ( 'HashKeyElement' => $ hash -> getForDynamoDB ( ) ) ) ; if ( null !== $ range ) { $ range = new Attribute ( $ range ) ; $ parameters [ 'Key' ] [ 'RangeKeyElement' ] = $ range -> getForDynamoDB ( ) ; } if ( null !== $ context ) { $ parameters += $ context -> getForDynamoDB ( ) ; } if ( null !== $ this -> logger ) { $ this -> log ( 'Get request paramaters : ' . print_r ( $ parameters , true ) , Logger :: DEBUG ) ; } $ response = $ this -> connector -> getItem ( $ parameters ) ; if ( null !== $ this -> logger ) { $ this -> log ( 'Get request response : ' . print_r ( $ response , true ) , Logger :: DEBUG ) ; } $ this -> addConsumedReadUnits ( $ table , floatval ( $ response [ 'ConsumedCapacityUnits' ] ) ) ; if ( isset ( $ response [ 'Item' ] ) ) { $ item = new Item ( $ table ) ; $ item -> populateFromDynamoDB ( $ response [ 'Item' ] ) ; return $ item ; } else { if ( null !== $ this -> logger ) { $ this -> log ( 'Didn\'t find item' ) ; } return null ; } } | Get an item via the get_item call |
35,921 | public function update ( $ table , $ hash , $ range = null , AttributeUpdate $ update , Context \ Update $ context = null ) { if ( null !== $ this -> logger ) { $ this -> log ( 'Update on table' . $ table ) ; } $ hash = new Attribute ( $ hash ) ; $ key = array ( 'HashKeyElement' => $ hash -> getForDynamoDB ( ) ) ; if ( null !== $ range ) { $ range = new Attribute ( $ range ) ; $ key [ 'RangeKeyElement' ] = $ range -> getForDynamoDB ( ) ; } $ attributes = array ( ) ; foreach ( $ update as $ name => $ attribute ) { $ attributes [ $ name ] = $ attribute -> getForDynamoDB ( ) ; } $ parameters = array ( 'TableName' => $ table , 'Key' => $ key , 'AttributeUpdates' => $ attributes , ) ; if ( null !== $ context ) { $ parameters += $ context -> getForDynamoDB ( ) ; } if ( null !== $ this -> logger ) { $ this -> log ( 'Update request paramaters : ' . print_r ( $ parameters , true ) , Logger :: DEBUG ) ; } $ response = $ this -> connector -> updateItem ( $ parameters ) ; if ( null !== $ this -> logger ) { $ this -> log ( 'Update request response : ' . print_r ( $ response , true ) , Logger :: DEBUG ) ; } $ this -> addConsumedWriteUnits ( $ table , floatval ( $ response [ 'ConsumedCapacityUnits' ] ) ) ; return $ this -> populateAttributes ( $ response ) ; } | Update an item via the update_item call |
35,922 | public function scan ( $ table , Context \ Scan $ context = null ) { if ( null !== $ this -> logger ) { $ this -> log ( 'Scan on table ' . $ table ) ; } $ parameters = array ( 'TableName' => $ table ) ; if ( null !== $ context ) { $ parameters += $ context -> getForDynamoDB ( ) ; } if ( null !== $ this -> logger ) { $ this -> log ( 'Scan request paramaters : ' . print_r ( $ parameters , true ) , Logger :: DEBUG ) ; } $ response = $ this -> connector -> scan ( $ parameters ) ; if ( null !== $ this -> logger ) { $ this -> log ( 'Scan request response : ' . print_r ( $ response , true ) , Logger :: DEBUG ) ; $ this -> log ( $ response [ 'ScannedCount' ] . ' scanned items' ) ; } $ this -> addConsumedReadUnits ( $ table , floatval ( $ response [ 'ConsumedCapacityUnits' ] ) ) ; if ( isset ( $ response [ 'LastEvaluatedKey' ] ) ) { if ( null === $ context ) { $ nextContext = new Context \ Scan ( ) ; } else { $ nextContext = clone $ context ; } $ nextContext -> setExclusiveStartKey ( $ response [ 'LastEvaluatedKey' ] ) ; if ( null !== $ this -> logger ) { $ this -> log ( 'More Items to retrieve' ) ; } } else { $ nextContext = null ; } $ items = new Collection ( $ nextContext , $ response [ 'Count' ] ) ; if ( ! empty ( $ response [ 'Items' ] ) ) { foreach ( $ response [ 'Items' ] as $ responseItem ) { $ item = new Item ( $ table ) ; $ item -> populateFromDynamoDB ( $ responseItem ) ; $ items -> add ( $ item ) ; } } if ( null !== $ this -> logger ) { $ this -> log ( 'Find ' . count ( $ items ) . ' Items' ) ; } return $ items ; } | Get items via the scan call |
35,923 | public function batchGet ( Context \ BatchGet $ context ) { if ( null !== $ this -> logger ) { $ this -> log ( 'BatchGet' ) ; } if ( 0 === count ( $ context ) ) { $ message = "BatchGet context doesn't contain any key to get" ; if ( null !== $ this -> logger ) { $ this -> log ( $ message , Logger :: ERROR ) ; } throw new Exception \ AttributesException ( $ message ) ; } $ parameters = $ context -> getForDynamoDB ( ) ; if ( null !== $ this -> logger ) { $ this -> log ( 'BatchGet request paramaters : ' . print_r ( $ parameters , true ) , Logger :: DEBUG ) ; } $ response = $ this -> connector -> batchGetItem ( $ parameters ) ; if ( null !== $ this -> logger ) { $ this -> log ( 'BatchGet request response : ' . print_r ( $ response , true ) , Logger :: DEBUG ) ; } if ( count ( ( array ) $ response [ 'UnprocessedKeys' ] ) ) { $ unprocessKeyContext = new Context \ BatchGet ( ) ; foreach ( $ response [ 'UnprocessedKeys' ] as $ table => $ tableParameters ) { foreach ( $ tableParameters -> Keys as $ key ) { $ unprocessKeyContext -> addKey ( $ table , current ( $ key -> HashKeyElement ) , current ( $ key -> RangeKeyElement ) ) ; } if ( ! empty ( $ tableParameters -> AttributesToGet ) ) { $ unprocessKeyContext -> setAttributesToGet ( $ table , $ tableParameters -> AttributesToGet ) ; } } } else { $ unprocessKeyContext = null ; } $ collection = new Batch \ BatchCollection ( $ unprocessKeyContext ) ; foreach ( $ response [ 'Responses' ] as $ table => $ responseItems ) { $ this -> addConsumedReadUnits ( $ table , floatval ( $ responseItems [ 'ConsumedCapacityUnits' ] ) ) ; $ items = new Collection ( ) ; foreach ( $ responseItems [ 'Items' ] as $ responseItem ) { $ item = new Item ( $ table ) ; $ item -> populateFromDynamoDB ( $ responseItem ) ; $ items -> add ( $ item ) ; } if ( null !== $ this -> logger ) { $ this -> log ( 'Find ' . count ( $ items ) . ' Items on table ' . $ table ) ; } $ collection -> setItems ( $ table , $ items ) ; } return $ collection ; } | Get a batch of items |
35,924 | public function batchWrite ( Context \ BatchWrite $ context ) { if ( null !== $ this -> logger ) { $ this -> log ( 'BatchWrite' ) ; } if ( 0 === count ( $ context ) ) { $ message = "BatchWrite context doesn't contain anything to write" ; if ( null !== $ this -> logger ) { $ this -> log ( $ message , Logger :: ERROR ) ; } throw new Exception \ AttributesException ( $ message ) ; } $ parameters = $ context -> getForDynamoDB ( ) ; if ( null !== $ this -> logger ) { $ this -> log ( 'BatchWrite request paramaters : ' . print_r ( $ parameters , true ) , Logger :: DEBUG ) ; } $ response = $ this -> connector -> batchWriteItem ( $ parameters ) ; if ( null !== $ this -> logger ) { $ this -> log ( 'BatchWrite request response : ' . print_r ( $ response , true ) , Logger :: DEBUG ) ; } if ( count ( ( array ) $ response [ 'UnprocessedItems' ] ) ) { $ newContext = new Context \ BatchWrite ( ) ; foreach ( $ response [ 'UnprocessedItems' ] as $ table => $ tableParameters ) { foreach ( $ tableParameters as $ request ) { if ( isset ( $ request [ 'DeleteRequest' ] ) ) { $ keys = $ request [ 'DeleteRequest' ] [ 'Key' ] ; $ newContext -> addKeyToDelete ( $ table , current ( $ keys [ 'HashKeyElement' ] ) , ( isset ( $ keys [ 'RangeKeyElement' ] ) ? current ( $ keys [ 'RangeKeyElement' ] ) : null ) ) ; } elseif ( isset ( $ request [ 'PutRequest' ] ) ) { $ item = new Item ( $ table ) ; $ item -> populateFromDynamoDB ( $ request [ 'PutRequest' ] [ 'Item' ] ) ; $ newContext -> addItemToPut ( $ item ) ; } } } if ( null !== $ this -> logger ) { $ this -> log ( 'More unprocessed Items' ) ; } } else { $ newContext = null ; } foreach ( $ response [ 'Responses' ] as $ table => $ responseItems ) { $ this -> addConsumedWriteUnits ( $ table , floatval ( $ responseItems [ 'ConsumedCapacityUnits' ] ) ) ; } return $ newContext ; } | Put Items and delete Keys by batch |
35,925 | public function createTable ( $ table , Table \ KeySchema $ keySchama , Table \ ProvisionedThroughput $ provisionedThroughput ) { if ( null !== $ this -> logger ) { $ this -> log ( 'Create table ' . $ table ) ; } $ parameters = array ( 'TableName' => $ table , 'KeySchema' => $ keySchama -> getForDynamoDB ( ) , 'ProvisionedThroughput' => $ provisionedThroughput -> getForDynamoDB ( ) ) ; if ( null !== $ this -> logger ) { $ this -> log ( 'TableCreate request paramaters : ' . print_r ( $ parameters , true ) , Logger :: DEBUG ) ; } $ response = $ this -> connector -> createTable ( $ parameters ) ; if ( null !== $ this -> logger ) { $ this -> log ( 'TableCreate request response : ' . print_r ( $ response , true ) , Logger :: DEBUG ) ; } } | Create table via the create_table call |
35,926 | public function deleteTable ( $ table ) { if ( null !== $ this -> logger ) { $ this -> log ( 'Delete table ' . $ table ) ; } $ parameters = array ( 'TableName' => $ table , ) ; if ( null !== $ this -> logger ) { $ this -> log ( 'DeleteTable request paramaters : ' . print_r ( $ parameters , true ) , Logger :: DEBUG ) ; } $ response = $ this -> connector -> deleteTable ( $ parameters ) ; if ( null !== $ this -> logger ) { $ this -> log ( 'DeleteTable request response : ' . print_r ( $ response , true ) , Logger :: DEBUG ) ; } } | Delete table via the delete_table call |
35,927 | public function describeTable ( $ table ) { if ( null !== $ this -> logger ) { $ this -> log ( 'Describe table ' . $ table ) ; } $ parameters = array ( 'TableName' => $ table , ) ; if ( null !== $ this -> logger ) { $ this -> log ( 'DescribeTable request paramaters : ' . print_r ( $ parameters , true ) , Logger :: DEBUG ) ; } $ response = $ this -> connector -> describeTable ( $ parameters ) ; if ( null !== $ this -> logger ) { $ this -> log ( 'DescribeTable request response : ' . print_r ( $ response , true ) , Logger :: DEBUG ) ; } $ tableDescription = new Table \ TableDescription ( ) ; $ tableDescription -> populateFromDynamoDB ( $ response [ 'Table' ] ) ; return $ tableDescription ; } | Describe table via the describe_table call |
35,928 | public function listTables ( $ limit = null , $ exclusiveStartTableName = null ) { if ( null !== $ this -> logger ) { $ this -> log ( 'List tables' ) ; } $ parameters = array ( ) ; if ( null !== $ limit ) { $ parameters [ 'Limit' ] = $ limit ; } if ( null !== $ exclusiveStartTableName ) { $ parameters [ 'ExclusiveStartTableName' ] = $ exclusiveStartTableName ; } if ( null !== $ this -> logger ) { $ this -> log ( 'ListTable request paramaters : ' . print_r ( $ parameters , true ) , Logger :: DEBUG ) ; } $ response = $ this -> connector -> listTables ( $ parameters ) ; if ( null !== $ this -> logger ) { $ this -> log ( 'ListTable request response : ' . print_r ( $ response , true ) , Logger :: DEBUG ) ; } $ tables = new Table \ TableCollection ( ( isset ( $ response [ 'LastEvaluatedTableName' ] ) ? $ response [ 'LastEvaluatedTableName' ] : null ) ) ; if ( ! empty ( $ response [ 'TableNames' ] ) ) { foreach ( $ response [ 'TableNames' ] as $ table ) { $ tables -> add ( $ table ) ; } } return $ tables ; } | List tables via the list_tables call |
35,929 | protected function populateAttributes ( \ Guzzle \ Service \ Resource \ Model $ data ) { if ( isset ( $ data [ 'Attributes' ] ) ) { $ attributes = array ( ) ; foreach ( $ data [ 'Attributes' ] as $ name => $ value ) { list ( $ type , $ value ) = each ( $ value ) ; $ attributes [ $ name ] = new Attribute ( $ value , $ type ) ; } return $ attributes ; } else { return null ; } } | Extract the attributes array from response data |
35,930 | protected function detect ( array $ registries ) { $ length = max ( array_map ( 'strlen' , $ registries ) ) ; $ found = false ; foreach ( self :: DETECT_LAYOUT as $ cnab => $ start ) { if ( $ length <= $ cnab ) { $ found = true ; break ; } } if ( ! $ found ) { throw new \ DomainException ( 'Could not detect Return File layout' ) ; } $ this -> bank_code = substr ( $ registries [ 0 ] , $ start , 3 ) ; $ this -> cnab = $ cnab ; } | Detects the CNAB layout and the Bank Code |
35,931 | public function extract ( ) { $ bank = BankInterchange \ Models \ Bank :: getInstance ( [ 'code' => $ this -> bank_code , ] ) ; if ( $ bank === null ) { $ message = "Extractor class for CNAB$this->config not found" ; throw new \ LogicException ( $ message ) ; } $ extractor_class = __NAMESPACE__ . "\\Extractors\\Cnab$this->cnab\\" . BankInterchange \ Utils :: toPascalCase ( $ bank -> name ) ; return new $ extractor_class ( $ this ) ; } | Extracts useful data from the parsed registries in a fixed layout |
35,932 | protected function loadConfig ( ) { if ( self :: $ config_path === null ) { throw new \ BadMethodCallException ( 'Config path is null' ) ; } $ key = "$this->cnab/$this->bank_code" ; if ( ! array_key_exists ( $ key , self :: $ cache ) ) { $ config_file = self :: $ config_path . "/cnab$key.yml" ; if ( file_exists ( $ config_file ) ) { self :: $ cache [ $ key ] = Yaml :: parseFile ( $ config_file ) ; } else { throw new \ RuntimeException ( sprintf ( "Config file for Bank '%s' in CNAB%s not found" , $ this -> bank_code , $ this -> cnab ) ) ; } } $ this -> config = $ key ; } | Loads YAML config file into cache |
35,933 | protected function parse ( array $ structure , int $ offset = null ) { $ result = [ ] ; $ current = $ offset ?? 0 ; $ count_structure = 0 ; foreach ( $ structure as $ registry_group ) { if ( is_array ( $ registry_group ) ) { $ buffer = [ ] ; do { try { $ rec = $ this -> parse ( $ registry_group , $ current ) ; $ nested = ( count ( $ registry_group ) > 1 ) ? [ $ rec [ 'registries' ] ] : $ rec [ 'registries' ] ; $ buffer = array_merge ( $ buffer , $ nested ) ; $ current = $ rec [ 'offset' ] ; } catch ( ParseException $ e ) { if ( count ( $ buffer ) === 0 ) { throw $ e ; } else { $ first = $ registry_group [ 0 ] ; if ( is_string ( $ first ) ) { $ first = explode ( ' ' , $ first ) ; } $ in_first = array_intersect ( $ first , $ e -> getRegistries ( ) ) ; if ( count ( $ in_first ) === 0 ) { throw $ e ; } break ; } } } while ( $ current < count ( $ this -> registries ) ) ; $ nested = ( count ( $ registry_group ) > 1 ) ? $ buffer : [ $ buffer ] ; $ result = array_merge ( $ result , $ nested ) ; } else { $ types = explode ( ' ' , $ registry_group ) ; $ registry = $ this -> pregRegistry ( $ current , $ types ) ; if ( $ registry !== null ) { $ result [ ] = $ registry ; $ current ++ ; } elseif ( count ( $ result ) === 0 || $ count_structure > 0 ) { throw new ParseException ( $ this -> config , $ types , $ current + 1 ) ; } } $ count_structure ++ ; } return [ 'offset' => $ current , 'registries' => $ result , ] ; } | Recursively follows the Return File structure to preg - match its fields |
35,934 | protected function pregRegistry ( int $ id , array $ types ) { $ registry_types = Utils \ Utils :: arrayWhitelist ( self :: $ cache [ $ this -> config ] [ 'registries' ] , $ types ) ; $ result = null ; foreach ( $ registry_types as $ type => $ matcher ) { if ( preg_match ( $ matcher [ 'pattern' ] , $ this -> registries [ $ id ] ?? '' , $ matches ) ) { $ match = array_combine ( $ matcher [ 'map' ] , array_map ( 'trim' , array_slice ( $ matches , 1 ) ) ) ; $ result = new Registry ( $ this -> config , $ type , $ match ) ; break ; } } return $ result ; } | Preg - match fields from a Return File registry to fill a Registry instance |
35,935 | public function setName ( $ name ) { $ endsWithBrackets = substr_compare ( $ name , '[]' , - 2 , 2 ) === 0 ; if ( $ this -> isAutoArray ( ) && ! $ endsWithBrackets ) { $ name .= '[]' ; } $ this -> itSetName ( $ name ) ; foreach ( $ this -> getContents ( ) as $ item ) { $ item -> setName ( $ this -> getName ( ) ) ; } return $ this ; } | Sets the name of this group . Any children added will have their name updated to match as they are in the same group . |
35,936 | public function set ( $ key , $ value ) { if ( ! $ value instanceof Toggle ) { throw new \ InvalidArgumentException ( 'You can only add Toggle objects to a ToggleGroup.' ) ; } return parent :: set ( $ key , $ value ) ; } | Extends DataContainer s set method to ensure only Toggle objects can be added . |
35,937 | public function getEmailAddressOfContact ( ContactInterface $ contact , $ useFallback = true ) { $ contactMainEmail = $ contact -> getMainEmail ( ) ; if ( $ contact && $ contactMainEmail ) { return $ contactMainEmail ; } $ account = $ contact -> getMainAccount ( ) ; if ( $ useFallback && $ account ) { return $ this -> getEmailAddressOfAccount ( $ account ) ; } return null ; } | Gets email address of a contact |
35,938 | protected function getProviderFactoryBasedOnConfig ( UserConfig $ userConfig ) { $ areaId = $ userConfig -> provider -> getAreaId ( ) ; $ area = $ this -> twoFactorProvidersService -> getAreaManager ( ) -> getById ( $ areaId ) ; $ provider = $ this -> twoFactorProvidersService -> getEnabledInArea ( $ area ) ; $ data = [ 'id' => array_get ( $ provider -> settings , 'client_id' ) , 'key' => array_get ( $ provider -> settings , 'secret_key' ) , ] ; return new Yubikey ( $ data ) ; } | Setups the Yubikey factory based on area settings . |
35,939 | public function removeTagsByName ( $ tagName ) { $ this -> tags = array_filter ( $ this -> tags , function ( TagInterface $ tag ) use ( $ tagName ) { return $ tag -> getTagName ( ) !== $ tagName ; } ) ; } | Remove all tags that have a specific name . |
35,940 | protected function processMigration ( & $ index , array $ migrations , Migration $ migration ) { if ( in_array ( $ migration -> getStatus ( ) , [ Migration :: STATUS_MIGRATED , Migration :: STATUS_RECURSIVE_FOREIGN_KEY ] , true ) ) { return ; } $ migration -> setStatus ( Migration :: STATUS_IN_PROGRESS ) ; $ tableNames = $ migration -> getTable ( ) -> getForeignTableNames ( ) ; foreach ( $ tableNames as $ tableName ) { if ( $ migration -> getTable ( ) -> getTableName ( ) === $ tableName ) { continue ; } if ( isset ( $ migrations [ $ tableName ] ) && $ migrations [ $ tableName ] -> getStatus ( ) === Migration :: STATUS_IN_PROGRESS ) { $ migration -> setStatus ( Migration :: STATUS_RECURSIVE_FOREIGN_KEY ) ; continue ; } $ this -> processMigration ( $ index , $ migrations , $ migrations [ $ tableName ] ) ; } $ migration -> writeTableOut ( $ index , $ this -> output , $ this -> option ( 'force' ) ) ; if ( $ migration -> getStatus ( ) !== Migration :: STATUS_RECURSIVE_FOREIGN_KEY ) { $ migration -> setStatus ( Migration :: STATUS_MIGRATED ) ; } $ index ++ ; } | Export table to file |
35,941 | protected function filterByProperty ( array $ locales , $ property ) { $ filtered = [ ] ; foreach ( $ locales as $ locale ) { if ( ! empty ( $ locale -> $ property ) && ! in_array ( $ locale -> $ property , $ filtered ) ) { $ filtered [ ] = $ locale -> $ property ; } } return $ filtered ; } | Filter by a Locale property . |
35,942 | public function assets ( $ assets , array $ options = [ ] ) : string { if ( is_string ( $ assets ) ) { return $ this -> assetEngine -> assetFile ( $ assets , $ options ) ; } return $ this -> assetEngine -> assetFiles ( $ assets , $ options ) ; } | Render and compress assets content . |
35,943 | public function register ( Application $ app , array $ addons ) { foreach ( $ addons as $ addon ) { $ this -> loadFiles ( $ addon , $ addon -> config ( 'addon.files' , [ ] ) ) ; } foreach ( $ addons as $ addon ) { $ this -> loadConfigurationFiles ( $ addon ) ; $ providers = $ addon -> config ( 'addon.providers' , [ ] ) ; foreach ( $ providers as $ provider ) { $ app -> register ( $ provider ) ; } $ commands = $ addon -> config ( 'addon.commands' , $ addon -> config ( 'addon.console.commands' , [ ] ) ) ; if ( ! is_array ( $ commands ) ) $ commands = [ $ commands ] ; Artisan :: starting ( function ( $ artisan ) use ( $ commands ) { $ artisan -> resolveCommands ( $ commands ) ; } ) ; $ middlewares = $ addon -> config ( 'addon.middleware' , $ addon -> config ( 'addon.http.route_middlewares' , [ ] ) ) ; foreach ( $ middlewares as $ name => $ middleware ) { if ( is_array ( $ middleware ) ) { $ app [ 'router' ] -> middlewareGroup ( $ name , $ middleware ) ; } else { $ app [ 'router' ] -> aliasMiddleware ( $ name , $ middleware ) ; } } } } | register files . |
35,944 | protected function loadFiles ( Addon $ addon , array $ files ) { foreach ( $ files as $ filename ) { $ path = $ addon -> path ( $ filename ) ; if ( ! file_exists ( $ path ) ) { $ message = "Warning: PHP Script '$path' is nothing." ; info ( $ message ) ; echo $ message ; continue ; } require_once $ path ; } } | load addon initial script files . |
35,945 | protected function getConfigurationFiles ( $ directoryPath ) { $ files = [ ] ; if ( is_dir ( $ directoryPath ) ) { foreach ( Finder :: create ( ) -> files ( ) -> in ( $ directoryPath ) as $ file ) { $ group = basename ( $ file -> getRealPath ( ) , '.php' ) ; $ files [ $ group ] = $ file -> getRealPath ( ) ; } } return $ files ; } | Get all of the configuration files for the directory . |
35,946 | public function boot ( Application $ app , array $ addons ) { foreach ( $ addons as $ addon ) { $ this -> registerPackage ( $ app , $ addon ) ; } } | boot addon . |
35,947 | protected function parseMainContact ( ContactInterface $ contact ) { if ( $ contact ) { $ data = [ ] ; $ data [ 'id' ] = $ contact -> getId ( ) ; $ data [ 'fullName' ] = $ contact -> getFullName ( ) ; $ data [ 'phone' ] = $ contact -> getMainPhone ( ) ; $ data [ 'email' ] = $ contact -> getMainEmail ( ) ; return $ data ; } else { return null ; } } | Returns the data needed for the account list - sidebar . |
35,948 | protected function generateFileHeader ( ) { $ shipping_file = $ this -> shipping_file ; $ assignment = $ shipping_file -> assignment ; $ assignor_person = $ assignment -> assignor -> person ; $ bank = $ assignment -> bank ; $ format = '%03.3s%04.4s%01.1s%-9.9s%01.1s%014.14s%020.20s%05.5s%-1.1s' . '%012.12s%-1.1s%-1.1s%-30.30s%-30.30s%-10.10s%01.1s%08.8s%06.6s' . '%06.6s%03.3s%05.5s%-20.20s%-20.20s%-29.29s' ; $ data = [ $ bank -> code , '0' , '0' , '' , $ assignor_person -> getDocumentType ( ) , $ assignor_person -> document , $ assignment -> covenant , '0' , '' , '0' , '' , '' , Utils :: cleanSpaces ( $ assignor_person -> name ) , $ bank -> name , '' , '1' , static :: date ( 'dmY' , $ shipping_file -> stamp ) , static :: date ( 'His' , $ shipping_file -> stamp ) , $ shipping_file -> counter , static :: VERSION_FILE_LAYOUT , '0' , '' , $ shipping_file -> notes , '' , ] ; return vsprintf ( $ format , static :: normalize ( $ data ) ) ; } | Generates FileHeader registry |
35,949 | protected function generateLotHeader ( ) { $ assignment = $ this -> shipping_file -> assignment ; $ assignor_person = $ assignment -> assignor -> person ; $ bank = $ assignment -> bank ; $ format = '%03.3s%04.4s%01.1s%-1.1s%02.2s%-2.2s%03.3s%-1.1s%01.1s' . '%015.15s%020.20s%05.5s%-1.1s%012.12s%-1.1s%-1.1s%-30.30s%-40.40s' . '%-40.40s%08.8s%08.8s%08.8s%-33.33s' ; $ data = [ $ bank -> code , $ this -> lot_count , '1' , 'R' , '1' , '' , static :: VERSION_LOT_LAYOUT , '' , $ assignor_person -> getDocumentType ( ) , $ assignor_person -> document , $ assignment -> covenant , '0' , '' , '0' , '' , '' , Utils :: cleanSpaces ( $ assignor_person -> name ) , '' , '' , '0' , '0' , '0' , '' , ] ; return vsprintf ( $ format , static :: normalize ( $ data ) ) ; } | Generates LotHeader registry |
35,950 | protected function generateLotTrailer ( ) { $ format = '%03.3s%04.4s%01.1s%-9.9s%06.6s%06.6s%017.17s%06.6s%017.17s' . '%06.6s%017.17s%06.6s%017.17s%-8.8s%-117.117s' ; $ data = [ $ this -> shipping_file -> assignment -> bank -> code , $ this -> lot_count , '5' , '' , $ this -> current_lot , '0' , '0' , '0' , '0' , '0' , '0' , '0' , '0' , '' , '' , ] ; return vsprintf ( $ format , static :: normalize ( $ data ) ) ; } | Generates LotTrailer registry |
35,951 | protected function generateFileTrailer ( ) { $ format = '%03.3s%04.4s%01.1s%-9.9s%06.6s%06.6s%06.6s%-205.205s' ; $ data = [ $ this -> shipping_file -> assignment -> bank -> code , '9999' , '9' , '' , $ this -> lot_count , $ this -> registry_count , '0' , '' , ] ; return vsprintf ( $ format , static :: normalize ( $ data ) ) ; } | Generates FileTrailer registry |
35,952 | public function outputLong ( ) { return implode ( "\n" , array_filter ( [ implode ( ', ' , array_filter ( [ $ this -> place , $ this -> number , $ this -> detail , ( $ this -> detail == '' ? $ this -> neighborhood : '' ) , ] ) ) , implode ( ', ' , array_filter ( [ ( $ this -> detail != '' ? $ this -> neighborhood : '' ) , implode ( ' - CEP: ' , array_filter ( [ $ this -> county -> name . '/' . $ this -> county -> state -> code , Validation :: cep ( $ this -> zipcode ) , ] ) ) , ] ) ) , ] ) ) ; } | Outputs Model s data in a long format |
35,953 | public function outputShort ( ) { return implode ( ', ' , array_filter ( [ $ this -> place , $ this -> number , $ this -> detail , $ this -> neighborhood , implode ( ' ' , array_filter ( [ $ this -> county -> name . '/' . $ this -> county -> state -> code , Validation :: cep ( $ this -> zipcode ) , ] ) ) ] ) ) ; } | Outputs Model s data in a short format |
35,954 | public function setVisibility ( $ visibility ) { switch ( $ visibility ) { case Modifiers :: VISIBILITY_PUBLIC : $ this -> removeModifier ( Modifiers :: MODIFIER_PRIVATE | Modifiers :: MODIFIER_PROTECTED ) ; $ this -> addModifier ( Modifiers :: MODIFIER_PUBLIC ) ; break ; case Modifiers :: VISIBILITY_PROTECTED : $ this -> removeModifier ( Modifiers :: MODIFIER_PRIVATE | Modifiers :: MODIFIER_PUBLIC ) ; $ this -> addModifier ( Modifiers :: MODIFIER_PROTECTED ) ; break ; case Modifiers :: VISIBILITY_PRIVATE : $ this -> removeModifier ( Modifiers :: MODIFIER_PUBLIC | Modifiers :: MODIFIER_PROTECTED ) ; $ this -> addModifier ( Modifiers :: MODIFIER_PRIVATE ) ; break ; default : throw new InvalidArgumentException ( 'Unknown visibility to set.' ) ; } } | Set the visibility of the entity . |
35,955 | public function getVisibility ( ) { if ( ( $ this -> modifiers & Modifiers :: MODIFIER_PRIVATE ) !== 0 ) { return Modifiers :: VISIBILITY_PRIVATE ; } elseif ( ( $ this -> modifiers & Modifiers :: MODIFIER_PROTECTED ) !== 0 ) { return Modifiers :: VISIBILITY_PROTECTED ; } else { return Modifiers :: VISIBILITY_PUBLIC ; } } | Get the visibility of the entity . |
35,956 | public function setData ( $ element ) { $ rules = $ this -> processRules ( $ element ) ; $ this -> ruleProvider -> setData ( $ rules ) ; return $ this ; } | Adds some processing to turn input objects into arrays of validation rules |
35,957 | protected function processRules ( $ element ) { if ( $ element instanceof Form or $ element instanceof Fieldset ) { $ result = [ ] ; foreach ( $ element as $ field ) { $ result += $ this -> processRules ( $ field ) ; } return $ result ; } $ metaData = $ element -> getMetaContainer ( ) ; if ( isset ( $ metaData [ 'validation' ] ) ) { $ label = $ element -> getLabel ( ) ; if ( is_null ( $ label ) ) { $ label = $ element -> getName ( ) ; } return [ $ element -> getName ( ) => [ $ this -> ruleProvider -> getRuleKey ( ) => $ metaData [ 'validation' ] , $ this -> ruleProvider -> getLabelKey ( ) => $ label , ] ] ; } return [ $ element -> getName ( ) => [ ] ] ; } | Generates a rule set that the parent FromArray can parse for fields |
35,958 | protected function setAddonConfigNamespaces ( ) { if ( file_exists ( $ this -> addon -> path ( 'addon.php' ) ) ) { $ search = [ "namespace {$this->currentNamespace}" , "'namespace' => '{$this->currentNamespace}'" , "'{$this->currentNamespace}\\" , "\"{$this->currentNamespace}\\" , "\\{$this->currentNamespace}\\" , ] ; $ replace = [ "namespace {$this->newNamespace}" , "'namespace' => '{$this->newNamespace}'" , "'{$this->newNamespace}\\" , "\"{$this->newNamespace}\\" , "\\{$this->newNamespace}\\" , ] ; $ this -> replaceIn ( $ this -> addon -> path ( 'addon.php' ) , $ search , $ replace ) ; } } | Set the namespace in addon . php file . |
35,959 | protected function setAddonJsonNamespaces ( ) { if ( file_exists ( $ this -> addon -> path ( 'addon.json' ) ) ) { $ currentNamespace = str_replace ( '\\' , '\\\\' , $ this -> currentNamespace ) ; $ newNamespace = str_replace ( '\\' , '\\\\' , $ this -> newNamespace ) ; $ search = [ "\"namespace\": \"{$currentNamespace}\"" , "\"{$currentNamespace}\\\\" , "\\\\{$currentNamespace}\\\\" , ] ; $ replace = [ "\"namespace\": \"{$newNamespace}\"" , "\"{$newNamespace}\\\\" , "\\\\{$newNamespace}\\\\" , ] ; $ this -> replaceIn ( $ this -> addon -> path ( 'addon.json' ) , $ search , $ replace ) ; } } | Set the namespace in addon . json file . |
35,960 | protected function setClassNamespace ( ) { $ classDirectories = $ this -> addon -> config ( 'addon.directories' , [ ] ) ; if ( count ( $ this -> addon -> config ( 'addon.directories' , [ ] ) ) === 0 ) { return ; } $ files = Finder :: create ( ) ; foreach ( $ classDirectories as $ path ) { $ files -> in ( $ this -> addon -> path ( $ path ) ) ; } $ files -> name ( '*.php' ) ; $ search = [ $ this -> currentNamespace . '\\' , 'namespace ' . $ this -> currentNamespace . ';' , ] ; $ replace = [ $ this -> newNamespace . '\\' , 'namespace ' . $ this -> newNamespace . ';' , ] ; foreach ( $ files as $ file ) { $ this -> replaceIn ( $ file , $ search , $ replace ) ; } } | Set the namespace on the files in the class directory . |
35,961 | protected function setConfigNamespaces ( ) { $ configPath = $ this -> addon -> path ( $ this -> addon -> config ( 'paths.config' , 'config' ) ) ; if ( $ this -> filesystem -> isDirectory ( $ configPath ) ) { $ files = Finder :: create ( ) -> in ( $ configPath ) -> name ( '*.php' ) ; foreach ( $ files as $ file ) { $ this -> replaceConfigNamespaces ( $ file -> getRealPath ( ) ) ; } } } | Set the namespace in the appropriate configuration files . |
35,962 | public function details ( $ href , $ responseCallBack ) { $ response = $ this -> client -> request ( 'GET' , $ href ) ; return call_user_func_array ( $ responseCallBack , array ( $ response ) ) ; } | When passed a url you will get back the items details . |
35,963 | public function addContentAsLast ( Content $ content ) { if ( null === $ this -> contents ) { $ this -> contents = array ( ) ; } $ this -> contents [ ] = $ content ; } | Add Content to the last place of Area |
35,964 | public function getContentByIndex ( $ index ) { $ index = intval ( $ index ) ; return array_key_exists ( $ index , $ this -> contents ) ? $ this -> contents [ $ index ] : null ; } | Get area content by index |
35,965 | protected function close ( ) { if ( $ this -> current_lot !== null ) { $ this -> registry_count ++ ; $ this -> current_lot += 2 ; $ this -> registries [ ] = $ this -> generateLotTrailer ( ) ; $ this -> current_lot = null ; } $ this -> registry_count ++ ; $ this -> registries [ ] = $ this -> generateFileTrailer ( ) ; } | Does final steps for creating a shipping file |
35,966 | public function writeTableOut ( $ index , OutputInterface $ output = null , $ force = false ) { if ( $ this -> status !== self :: STATUS_IN_PROGRESS && $ this -> status !== self :: STATUS_RECURSIVE_FOREIGN_KEY ) { return ; } $ class = studly_case ( 'create_' . snake_case ( $ this -> table -> getTableName ( ) ) . '_table' ) ; $ fileName = date ( 'Y_m_d_' ) . str_pad ( $ index , 6 , '0' , STR_PAD_LEFT ) . '_' . snake_case ( $ class ) . '.php' ; $ this -> writeToFileFromTemplate ( $ this -> path . '/' . $ fileName , 'migrationCreateTable' , $ output , [ 'className' => $ class , 'tableName' => snake_case ( $ this -> table -> getTableName ( ) ) , 'columns' => $ this -> table -> renderCreateColumns ( ) , 'indexes' => $ this -> table -> renderCreateIndexes ( ) , 'foreignKeys' => $ this -> status === self :: STATUS_IN_PROGRESS ? $ this -> table -> renderCreateForeignKeys ( ) : '' , ] , $ force ) ; } | Render migration create table class and write out to file |
35,967 | public function writeForeignKeysOut ( $ index , OutputInterface $ output = null , $ force = false ) { if ( $ this -> status !== self :: STATUS_RECURSIVE_FOREIGN_KEY ) { return ; } $ class = studly_case ( 'add_foreign_keys_to_' . snake_case ( $ this -> table -> getTableName ( ) ) . '_table' ) ; $ fileName = date ( 'Y_m_d_' ) . str_pad ( $ index , 6 , '0' , STR_PAD_LEFT ) . '_' . snake_case ( $ class ) . '.php' ; $ this -> writeToFileFromTemplate ( $ this -> path . '/' . $ fileName , 'migrationAddForeignKey' , $ output , [ 'className' => $ class , 'tableName' => snake_case ( $ this -> table -> getTableName ( ) ) , 'createForeignKeys' => $ this -> table -> renderCreateForeignKeys ( ) , 'dropForeignKeys' => $ this -> table -> renderDropForeignKeys ( ) , ] , $ force ) ; } | Render migration add foreign keys to table class and write out to file |
35,968 | public function getSlice ( $ offset , $ length , $ params = array ( ) ) { $ searchResult = $ this -> handler -> search ( $ this -> form , $ this -> criteriaBuilder , $ this -> resultConverter , $ offset , $ length , $ params ) ; if ( ! isset ( $ this -> nbResults ) ) { $ this -> nbResults = $ searchResult -> totalCount ; } return $ searchResult -> searchHits ; } | Returns as slice of the results as SearchHit objects . |
35,969 | private static function _getOptions ( $ options , $ default ) { if ( is_array ( $ options ) ) { foreach ( $ default as $ key => $ value ) { if ( isset ( $ options [ $ key ] ) ) { $ default [ $ key ] = $ options [ $ key ] ; } } } return $ default ; } | Return a mixed array of options according the defaults values provided |
35,970 | public static function toASCII ( $ str , $ charset = 'UTF-8' ) { $ asciistr = '' ; if ( mb_detect_encoding ( $ str , 'UTF-8' , true ) === false ) { $ str = utf8_encode ( $ str ) ; } if ( version_compare ( PHP_VERSION , '5.6.0' ) < 0 ) { iconv_set_encoding ( 'input_encoding' , 'UTF-8' ) ; iconv_set_encoding ( 'internal_encoding' , 'UTF-8' ) ; iconv_set_encoding ( 'output_encoding' , $ charset ) ; } $ str = html_entity_decode ( $ str , ENT_QUOTES , $ charset ) ; $ strlen = iconv_strlen ( $ str , $ charset ) ; for ( $ i = 0 ; $ i < $ strlen ; $ i ++ ) { $ char = iconv_substr ( $ str , $ i , 1 , $ charset ) ; if ( ! preg_match ( '/[`\'^~"]+/' , $ char ) ) { if ( 'UTF-8' === $ charset ) { $ asciistr .= preg_replace ( '/[`\'^~"]+/' , '' , iconv ( $ charset , 'ASCII//TRANSLIT//IGNORE' , $ char ) ) ; } else { $ asciistr .= preg_replace ( '/[`\'^~"]+/' , '' , iconv ( 'UTF-8' , $ charset . '//TRANSLIT//IGNORE' , $ char ) ) ; } } else { $ asciistr .= $ char ; } } return $ asciistr ; } | Convert a string to ASCII |
35,971 | public static function toUTF8 ( $ str ) { if ( ! is_null ( $ str ) && false === mb_detect_encoding ( $ str , 'UTF-8' , true ) ) { $ str = utf8_encode ( $ str ) ; } return $ str ; } | Convert string to utf - 8 encoding if need |
35,972 | public static function toPath ( $ str , $ options = null , $ charset = 'UTF-8' ) { $ options = self :: _getOptions ( $ options , array ( 'extension' => '' , 'spacereplace' => null , 'lengthlimit' => 2000 , ) ) ; $ str = trim ( preg_replace ( '/(?:[^\w\-\.~\+% ]+|%(?![A-Fa-f0-9]{2}))/' , '' , self :: toASCII ( $ str , $ charset ) ) ) ; $ str = preg_replace ( '/\s+/' , null === $ options [ 'spacereplace' ] ? '' : $ options [ 'spacereplace' ] , $ str ) ; return substr ( $ str , 0 , $ options [ 'lengthlimit' ] ) . $ options [ 'extension' ] ; } | Normalize a string to a valid path file name |
35,973 | public static function replaceSpecialChars ( $ str ) { return preg_replace ( array_keys ( self :: $ specialCharsArray ) , array_values ( self :: $ specialCharsArray ) , $ str ) ; } | Replace special characters in a given string |
35,974 | public static function toXmlCompliant ( $ str , $ striptags = true ) { if ( true === $ striptags ) { $ str = strip_tags ( $ str ) ; } $ str = html_entity_decode ( $ str , ENT_COMPAT , 'UTF-8' ) ; $ str = str_replace ( array ( '<' , '>' , '&' ) , array ( '<' , '>' , '&' ) , $ str ) ; return $ str ; } | Return an XML compliant form of string |
35,975 | public static function truncateText ( $ text , $ length = 30 , $ truncate_string = '...' , $ truncate_lastspace = false ) { if ( $ text == '' ) { return '' ; } $ mbstring = extension_loaded ( 'mbstring' ) ; if ( $ mbstring ) { $ old_encoding = mb_internal_encoding ( ) ; mb_internal_encoding ( mb_detect_encoding ( $ text ) ) ; } $ strlen = ( $ mbstring ) ? 'mb_strlen' : 'strlen' ; $ substr = ( $ mbstring ) ? 'mb_substr' : 'substr' ; if ( $ strlen ( $ text ) > $ length ) { $ truncate_text = $ substr ( $ text , 0 , $ length - $ strlen ( $ truncate_string ) ) ; if ( $ truncate_lastspace ) { $ truncate_text = preg_replace ( '/\s+?(\S+)?$/' , '' , $ truncate_text ) ; } $ text = $ truncate_text . $ truncate_string ; } if ( $ mbstring ) { mb_internal_encoding ( $ old_encoding ) ; } return $ text ; } | truncate a string |
35,976 | public static function toBoolean ( $ str ) { if ( ! is_string ( $ str ) ) { throw new InvalidArgumentException ( sprintf ( 'String expected, %s received' , gettype ( $ str ) ) ) ; } $ booleanTrue = array ( '1' , 'on' , 'true' , 'yes' , ) ; if ( in_array ( $ str , $ booleanTrue , true ) ) { return true ; } $ booleanFalse = array ( '0' , 'off' , 'false' , 'no' , ) ; if ( in_array ( $ str , $ booleanFalse , true ) ) { return false ; } return false ; } | Converts a string to boolean |
35,977 | public function where ( $ sql = null , $ params = array ( ) ) { $ this -> _where = new Criteria ( $ sql , $ params ) ; return $ this ; } | Sets the where clause to the provided sql optionally binding parameters into the string . |
35,978 | public function andWhere ( $ sql = null , $ params = array ( ) ) { if ( ! isset ( $ this -> _where ) ) $ this -> _where = new Criteria ( ) ; $ this -> _where -> and ( new Criteria ( $ sql , $ params ) ) ; return $ this ; } | Adds an extra criteria to the where clause with an AND |
35,979 | public function orWhere ( $ sql = null , $ params = array ( ) ) { if ( ! isset ( $ this -> _where ) ) $ this -> _where = new Criteria ( ) ; $ this -> _where -> or ( new Criteria ( $ sql , $ params ) ) ; return $ this ; } | Adds an extra criteria to the where clause with an OR |
35,980 | public function having ( $ sql = null , $ params = array ( ) ) { $ this -> _having = new Criteria ( $ sql , $ params ) ; return $ this ; } | Sets the having clause to the provided sql optionally binding parameters into the string . |
35,981 | public function groupBy ( $ sql , $ params = array ( ) ) { $ binder = new Binder ( ) ; $ this -> _group = $ binder -> magicBind ( $ sql , ( array ) $ params ) ; return $ this ; } | Adds an group by clause |
35,982 | public function orderBy ( $ sql , $ params = array ( ) ) { $ binder = new Binder ( ) ; $ this -> _order = array ( $ binder -> magicBind ( $ sql , ( array ) $ params ) ) ; return $ this ; } | Adds an order by clause |
35,983 | public function andOrderBy ( $ sql , $ params = array ( ) ) { $ binder = new Binder ( ) ; $ this -> _order [ ] = $ binder -> magicBind ( $ sql , ( array ) $ params ) ; return $ this ; } | Convenience method for orderBy to be consistent with where and andWhere . |
35,984 | public function toSql ( ) { return implode ( ' ' , array_filter ( array ( $ this -> _clause ( ( $ this -> _distinct ? 'SELECT DISTINCT' : 'SELECT' ) , $ this -> _select ) , $ this -> _clause ( 'FROM' , $ this -> _from ) , implode ( ' ' , $ this -> _joins ) , $ this -> _clause ( 'WHERE' , $ this -> _where ) , $ this -> _clause ( 'GROUP BY' , $ this -> _group ) , $ this -> _clause ( 'HAVING' , $ this -> _having ) , $ this -> _clause ( 'ORDER BY' , $ this -> _order ) , $ this -> _limit , $ this -> _lock ) ) ) ; } | Returns the sql for the query |
35,985 | private function _join ( $ type , $ mixed , $ criteria , $ alias = '' ) { if ( is_object ( $ mixed ) ) { $ this -> _joins [ ] = sprintf ( '%s (%s) %s %s' , $ type , $ mixed , $ alias ? : 'derived' , $ criteria ) ; } elseif ( $ alias ) { $ this -> _joins [ ] = sprintf ( '%s `%s` AS `%s` %s' , $ type , $ mixed , $ alias , $ criteria ) ; } else { $ this -> _joins [ ] = sprintf ( '%s `%s` %s' , $ type , $ mixed , $ criteria ) ; } return $ this ; } | private helper methods |
35,986 | public function count ( ) { if ( isset ( $ this -> _resultset ) ) { return $ this -> _resultset -> count ( ) ; } elseif ( isset ( $ this -> _limit ) || isset ( $ this -> _group ) ) { return $ this -> execute ( ) -> count ( ) ; } else { $ query = clone $ this ; return ( int ) $ query -> select ( "count(*) count" ) -> execute ( ) -> scalar ( ) ; } } | kicker methods execute the query |
35,987 | public static function fromReflection ( ReflectionMethod $ reflectionMethod ) { $ method = new static ( $ reflectionMethod -> getName ( ) ) ; foreach ( $ reflectionMethod -> getParameters ( ) as $ parameter ) { $ method -> addParameter ( ParameterGenerator :: fromReflection ( $ parameter ) ) ; } $ method -> setFinal ( $ reflectionMethod -> isFinal ( ) ) ; $ method -> setAbstract ( $ reflectionMethod -> isAbstract ( ) ) ; if ( $ reflectionMethod -> isStatic ( ) === true ) { $ method -> setStatic ( true ) ; } if ( $ reflectionMethod -> isPrivate ( ) === true ) { $ method -> setVisibility ( Modifiers :: VISIBILITY_PRIVATE ) ; } elseif ( $ reflectionMethod -> isProtected ( ) === true ) { $ method -> setVisibility ( Modifiers :: VISIBILITY_PROTECTED ) ; } else { $ method -> setVisibility ( Modifiers :: VISIBILITY_PUBLIC ) ; } if ( $ reflectionMethod -> getReflectionDocComment ( ) -> isEmpty ( ) !== true ) { $ method -> setDocumentation ( DocCommentGenerator :: fromReflection ( $ reflectionMethod -> getReflectionDocComment ( ) ) ) ; } if ( $ reflectionMethod -> isAbstract ( ) !== true ) { $ body = trim ( $ reflectionMethod -> getBody ( ) ) ; if ( $ body !== '' ) { $ method -> setBody ( $ body ) ; } } return $ method ; } | Create a new method from reflection . |
35,988 | public function generateSignature ( ) { if ( $ this -> isFinal ( ) === true && $ this -> isAbstract ( ) === true ) { throw new RuntimeException ( 'A method can not be "abstract" and "final".' ) ; } if ( $ this -> isAbstract ( ) === true && $ this -> getVisibility ( ) === Modifiers :: VISIBILITY_PRIVATE ) { throw new RuntimeException ( 'A method can not be "abstract" and "private".' ) ; } $ signature = $ this -> getIndentation ( ) ; if ( $ this -> isFinal ( ) === true ) { $ signature .= 'final ' ; } elseif ( $ this -> isAbstract ( ) ) { $ signature .= 'abstract ' ; } $ signature .= $ this -> getVisibility ( ) ; if ( $ this -> isStatic ( ) === true ) { $ signature .= ' static' ; } return $ signature . ' function ' . $ this -> name . '(' . implode ( ', ' , $ this -> parameters ) . ')' ; } | Generate the signature of the method . |
35,989 | protected function generateTraitUsesLines ( ) { $ code = array ( ) ; foreach ( $ this -> traitUses as $ use ) { $ use -> setIndentationString ( $ this -> getIndentationString ( ) ) ; $ use -> setIndentationLevel ( $ this -> getIndentationLevel ( ) + 1 ) ; $ code [ ] = $ use -> generate ( ) ; $ code [ ] = null ; } return $ code ; } | Generate the uses lines . |
35,990 | private function parse_format ( $ format ) { $ format = strtoupper ( $ format ) ; $ format = str_replace ( '?' , '*' , $ format ) ; $ parts = explode ( ' ' , $ format ) ; $ count = count ( $ parts ) ; if ( $ count < 5 or $ count > 6 ) throw new \ InvalidArgumentException ( 'Invalid Cron Format expression provided' ) ; return array ( 'minute' => new Field_Minute ( $ parts [ 0 ] ) , 'hour' => new Field_Hour ( $ parts [ 1 ] ) , 'dom' => new Field_DayOfMonth ( $ parts [ 2 ] ) , 'month' => new Field_Month ( $ parts [ 3 ] ) , 'dow' => new Field_DayOfWeek ( $ parts [ 4 ] ) , 'year' => new Field_Year ( $ count === 6 ? $ parts [ 5 ] : '*' ) , ) ; } | Given an input format break it down into Fields |
35,991 | public function render ( Render $ renderer ) { $ legend = '' ; if ( ! is_null ( $ this -> getLegend ( ) ) ) { $ legend = Html :: tag ( 'legend' , [ ] , $ this -> getLegend ( ) ) ; } $ elements = $ legend ; foreach ( $ this -> getContents ( ) as $ element ) { $ elements .= "\n" . $ renderer -> render ( $ element ) ; } return Html :: tag ( 'fieldset' , $ this -> getAttributes ( ) , $ elements ) ; } | Renders the Fieldset to html |
35,992 | public function next ( $ pp = 10 ) { $ nextPageParams = $ this -> params ; $ nextPageParams [ 'start' ] = $ this -> params [ 'start' ] + $ pp ; return $ this -> client -> search ( $ nextPageParams ) ; } | Return the next page SolrSearchResult |
35,993 | public function convert ( $ input ) { $ result = new SearchResult ( array ( 'time' => 0 , 'maxScore' => 0 , 'totalCount' => $ input [ 'SearchCount' ] , ) ) ; $ contentService = $ this -> repository -> getContentService ( ) ; foreach ( $ input [ 'SearchResult' ] as $ doc ) { $ contentObject = $ contentService -> loadContent ( $ doc -> ContentObjectID ) ; $ searchHit = new SearchAndFilterHit ( array ( 'score' => 0 , 'valueObject' => $ contentObject , 'objectStates' => $ this -> loadContentObjectStates ( $ contentObject -> contentInfo ) ) ) ; $ result -> searchHits [ ] = $ searchHit ; } return $ result ; } | Builds search result |
35,994 | public function match ( $ url , $ to = null , array $ params = array ( ) ) { if ( ! $ params && is_array ( $ to ) ) { $ params = $ to ; $ to = null ; } $ this -> createAndAddRoute ( $ url , $ to , $ params ) ; } | Must specify a verb through the via parameter . |
35,995 | public function namespaced ( $ namespace , Closure $ block ) { $ this -> paths [ ] = $ namespace ; $ this -> modules [ ] = $ namespace ; $ this -> routeNames [ ] = $ namespace ; $ block ( ) ; array_pop ( $ this -> paths ) ; array_pop ( $ this -> modules ) ; array_pop ( $ this -> routeNames ) ; } | Namespace is a mix of module + path options . |
35,996 | public function drawRoutes ( Closure $ block ) { $ block = $ block -> bindTo ( $ this ) ; $ block ( ) ; if ( ! $ this -> routeSet -> rootRoute ( ) ) { $ this -> root ( self :: ROOT_DEFAULT_TO ) ; } $ this -> createPanelRoute ( ) ; $ this -> createAssetsRoute ( ) ; } | Used by Rails . |
35,997 | public function primary ( ) { $ columns = array_filter ( $ this -> _props , function ( $ property ) { return $ property -> type -> options ( ) -> primary ; } ) ; if ( empty ( $ columns ) ) throw new Exception ( "No primary key defined for {$this->_class}" ) ; return $ columns ; } | Returns an array of Properties that form the primary keys |
35,998 | public function defaults ( ) { $ defaults = array ( ) ; foreach ( $ this -> _props as $ key => $ prop ) $ defaults [ $ key ] = $ prop -> defaultValue ( ) ; return $ defaults ; } | Returns an array with properties with default values |
35,999 | public function relationship ( $ name ) { if ( ! isset ( $ this -> _rels [ $ name ] ) ) throw new \ InvalidArgumentException ( "Unknown relationship $name" ) ; return $ this -> _rels [ $ name ] ; } | Returns a particular Relationship |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.