idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
54,900
|
protected function _rtl ( ) { $ this -> _chars ( ) -> rewind ( ) ; while ( $ this -> _chars ( ) -> valid ) { if ( $ this -> _chars ( ) -> current ( ) -> ltr ) return false ; $ this -> _chars ( ) -> next ; } return true ; }
|
Checks whether the whole string is right to left .
|
54,901
|
protected function _ltr ( ) { $ this -> _chars ( ) -> rewind ( ) ; while ( $ this -> _chars ( ) -> valid ) { if ( $ this -> _chars ( ) -> current ( ) -> rtl ) return false ; $ this -> _chars ( ) -> next ; } return true ; }
|
Checks whether the whole string is written from the left to the right .
|
54,902
|
public function tag ( $ tag_expr ) { self :: mustBeString ( $ tag_expr , 'Tag expression' ) ; $ arr = array ( ) ; $ tags = preg_split ( '/\s+/ui' , $ tag_expr ) ; $ detectId = function ( $ str , & $ tag ) { if ( preg_match ( '/#/ui' , $ str ) ) { $ id = preg_split ( '/#/ui' , $ str ) ; $ out = array_shift ( $ id ) ; if ( count ( $ id ) > 1 || ! empty ( $ tag -> id ) ) { throw new \ RuntimeException ( 'XML tag cannot have more than one ID attribute!' ) ; } $ tag -> id = array_pop ( $ id ) ; return $ out ; } return $ str ; } ; foreach ( $ tags as $ t ) { if ( preg_match ( '/^[#\.]+/ui' , $ t ) ) { throw new \ RuntimeException ( 'Empty class name are not allowed!' ) ; } $ tag = new \ stdClass ( ) ; $ tag -> classes = array ( ) ; $ tag -> id = null ; $ classes = preg_split ( '/\./ui' , $ t ) ; $ tag -> name = $ detectId ( array_shift ( $ classes ) , $ tag ) ; if ( ! empty ( $ classes ) ) { foreach ( $ classes as $ c ) { $ tag -> classes [ ] = $ detectId ( $ c , $ tag ) ; } } $ arr [ ] = $ tag ; } if ( ! empty ( $ arr ) ) { $ str = $ this -> value ; $ arr = array_reverse ( $ arr ) ; foreach ( $ arr as $ t ) { $ start = $ t -> name ; $ end = $ t -> name ; if ( ! empty ( $ t -> classes ) ) { $ start .= sprintf ( ' class="%s"' , implode ( ' ' , $ t -> classes ) ) ; } if ( ! empty ( $ t -> id ) ) { $ start .= sprintf ( ' id="%s"' , $ t -> id ) ; } $ str = sprintf ( '<%s>%s</%s>' , $ start , $ str , $ end ) ; } return new self ( $ str ) ; } return $ this ; }
|
Embeds current string into one or more tags .
|
54,903
|
public function untag ( $ tag = null ) { if ( ! is_null ( $ tag ) ) { $ allowed = '' ; $ tagify = function ( $ tag ) { $ output = function ( $ str ) { $ str = preg_replace ( '@[</>]+@' , '' , $ str ) ; return '<' . $ str . '>' ; } ; if ( $ tag instanceof \ DOMNode ) { return $ output ( $ tag -> nodeName ) ; } elseif ( ( is_object ( $ tag ) && method_exists ( $ tag , '__toString' ) ) || is_string ( $ tag ) ) { $ prov_str = "$tag" ; $ prov_str = preg_replace ( '@[</>\s]+@' , ' ' , $ prov_str ) ; $ arr = preg_split ( '/[ ,;|]/ui' , $ prov_str ) ; $ str = '' ; foreach ( $ arr as $ a ) { $ str .= $ output ( $ a ) ; } return $ str ; } else { throw new \ InvalidArgumentException ( 'Allowed tags not recognized. Bad type?' ) ; } } ; if ( $ tag instanceof A || $ tag instanceof H || is_array ( $ tag ) ) { if ( is_object ( $ tag ) ) { $ tag = array_values ( $ tag -> array ) ; } foreach ( $ tag as $ t ) { $ allowed .= $ tagify ( $ t ) ; } } elseif ( $ tag instanceof \ DOMNode || ( is_object ( $ tag ) && method_exists ( $ tag , '__toString' ) ) || is_string ( $ tag ) ) { $ allowed .= $ tagify ( $ tag ) ; } else { throw new \ InvalidArgumentException ( 'Allowed tags not recognized. Bad type?' ) ; } return new self ( strip_tags ( $ this -> value , $ allowed ) ) ; } return new self ( strip_tags ( $ this -> value ) ) ; }
|
Removes HTML and XML tags .
|
54,904
|
private function _nl ( $ type , $ after = true ) { if ( $ after ) { return new self ( $ this -> value . $ type ) ; } else { return new self ( $ type . $ this -> value ) ; } }
|
Add new CR LF CRLF or PHP_EOL before or after the string .
|
54,905
|
public function transform ( SplFileInfo $ file ) { try { $ taxonomyFile = $ this -> fileToTaxonomyFile -> transform ( $ file ) ; $ taxonomy = $ this -> buildTaxonomy ( $ taxonomyFile ) ; return $ taxonomy ; } catch ( \ Exception $ e ) { throw new TransformationFailure ( $ e -> getMessage ( ) , 0 , $ e , $ file -> getRealPath ( ) ) ; } }
|
Transforms a file into a Taxonomy
|
54,906
|
public static function exceptionHandler ( \ Exception $ e ) { $ error = Error :: createFromException ( $ e , Response :: STATUS_ERROR ) ; $ status = method_exists ( $ e , 'getStatus' ) ? $ e -> getStatus ( ) : Response :: STATUS_ERROR ; Container :: get ( 'response' ) -> setStatus ( $ status ) ; Container :: get ( 'controller' ) -> addError ( $ error ) -> serve ( ) ; }
|
Internal exception handler
|
54,907
|
public static function shutdownHandler ( $ type = E_ERROR ) { $ error = error_get_last ( ) ; if ( $ error [ "type" ] & $ type ) { self :: errorHandler ( $ error [ "type" ] , $ error [ "message" ] , $ error [ "file" ] , $ error [ "line" ] ) ; } }
|
Internal shutdown handler
|
54,908
|
public static function getRawData ( $ data_str ) { if ( is_string ( $ data_str ) && ( $ data_str == "''" || $ data_str == '""' ) ) { $ data = '' ; } else { $ data = $ data_str ; } if ( ! empty ( $ data ) && ( $ data { 0 } == '{' || $ data { 0 } == '[' ) ) { try { $ data = self :: json_decode ( $ data ) ; } catch ( \ Exception $ e ) { throw $ e ; } } return $ data ; }
|
Get a final data transformed if it was JSON encoded
|
54,909
|
public function getApplication ( ) { if ( ! is_null ( $ this -> session ) ) { return $ this -> session -> getApplication ( ) ; } else { return $ this -> context -> getSystem ( ) -> getApplication ( ) ; } }
|
Shortcut to Application object either provided by Session or by Context
|
54,910
|
public function getUser ( ) { if ( ! is_null ( $ this -> session ) ) { return $ this -> session -> getUser ( ) ; } else { return $ this -> context -> getSystem ( ) -> getUser ( ) ; } }
|
Shortcut to User object either provided by Session or by Context
|
54,911
|
public function getIntent ( ) { if ( $ this -> getRequest ( ) -> getType ( ) != 'IntentRequest' ) { throw new InvalidArgumentException ( 'This request is not an IntentRequest.' ) ; } $ request = $ this -> getRequest ( ) ; return $ request -> getIntent ( ) ; }
|
Shortcut to Intent object
|
54,912
|
private function _tableExists ( ) { try { $ result = mysqli_query ( $ this -> link , "SELECT 1 FROM $this->table_name LIMIT 1" ) ; } catch ( \ Exception $ e ) { return FALSE ; } return $ result !== FALSE ; }
|
Check if a table exists in the current database .
|
54,913
|
protected function _t_loader_namespacestack_getMatchedFromStack ( $ name , $ recursivelyNamespaceStack = null ) { $ matched = array ( ) ; if ( empty ( $ recursivelyNamespaceStack ) && $ recursivelyNamespaceStack !== null ) return $ matched ; if ( $ this -> _t_loader_namespacestack_cache_SortNamespaces !== $ this -> _t_loader_namespacestack_Namespaces ) { uksort ( $ this -> _t_loader_namespacestack_Namespaces , 'strcasecmp' ) ; $ this -> _t_loader_namespacestack_cache_SortNamespaces = $ this -> _t_loader_namespacestack_Namespaces ; } $ recursivelyNamespaceStack = ( $ recursivelyNamespaceStack === null ) ? $ this -> _t_loader_namespacestack_Namespaces : $ recursivelyNamespaceStack ; $ keys = array_keys ( $ recursivelyNamespaceStack ) ; $ midKey = intval ( count ( $ keys ) / 2 ) ; $ curRegisteredName = trim ( $ keys [ $ midKey ] , \ Poirot \ Loader \ SEPARATOR_NAMESPACES ) ; if ( $ curRegisteredName == '*' || $ curRegisteredName == '**' ) return $ matched ; $ term = strncasecmp ( $ curRegisteredName , $ name , strlen ( $ curRegisteredName ) ) ; if ( $ term === 0 ) { array_push ( $ matched , $ curRegisteredName ) ; for ( $ i = $ midKey - 1 ; $ i >= 0 ; $ i -- ) { $ curRegisteredName = trim ( $ keys [ $ i ] , \ Poirot \ Loader \ SEPARATOR_NAMESPACES ) ; $ term = strncasecmp ( $ curRegisteredName , $ name , strlen ( $ curRegisteredName ) ) ; if ( $ term !== 0 ) break ; array_push ( $ matched , $ curRegisteredName ) ; } for ( $ i = $ midKey + 1 ; $ i < count ( $ keys ) ; $ i ++ ) { $ curRegisteredName = trim ( $ keys [ $ i ] , \ Poirot \ Loader \ SEPARATOR_NAMESPACES ) ; $ term = strncasecmp ( $ curRegisteredName , $ name , strlen ( $ curRegisteredName ) ) ; if ( $ term !== 0 ) break ; array_unshift ( $ matched , $ curRegisteredName ) ; } return $ matched ; } if ( $ term > 0 ) return $ this -> _t_loader_namespacestack_getMatchedFromStack ( $ name , array_splice ( $ recursivelyNamespaceStack , 0 , $ midKey ) ) ; $ matched = $ this -> _t_loader_namespacestack_getMatchedFromStack ( $ name , array_splice ( $ recursivelyNamespaceStack , $ midKey , count ( $ keys ) - 1 ) ) ; if ( ! $ matched ) { foreach ( $ keys as $ canMatch ) { if ( 0 === strncasecmp ( $ canMatch , $ name , strlen ( $ canMatch ) ) ) array_push ( $ matched , $ canMatch ) ; else break ; } } return $ matched ; }
|
Binary search for matching with requested resource namespace
|
54,914
|
protected function _t_loader_namespacestack_watchAndResolve ( $ name , $ match , $ resolveWatch ) { ( $ resolveWatch !== null ) ? : $ resolveWatch = function ( $ resource ) { return ( $ resource ) ? $ resource : false ; } ; $ this -> _t_loader_namespacestack_fixResourceList ( $ match ) ; $ return = false ; foreach ( $ this -> _t_loader_namespacestack_Namespaces [ $ match ] as $ resource ) { if ( $ return = $ resolveWatch ( $ name , $ resource , $ match ) ) break ; } return $ return ; }
|
- usually watch closure implemented by extended classes it s just simple resolver filter
|
54,915
|
public function configureByConfigString ( $ configString ) { $ successsfullyConfigured = false ; if ( true === is_string ( $ configString ) && '' !== $ configString && 3 === mb_substr_count ( $ configString , self :: FEATURE_CONFIGSTRING_SECTION_DELIMITER ) ) { list ( $ percentageString , $ usersString , $ rolesString , $ groupsString ) = explode ( self :: FEATURE_CONFIGSTRING_SECTION_DELIMITER , $ configString ) ; $ this -> setPercentage ( ( integer ) 0 ) ; if ( true === is_numeric ( $ percentageString ) ) { $ this -> setPercentage ( ( integer ) $ percentageString ) ; } $ this -> setUsers ( array ( ) ) ; if ( true === is_string ( $ usersString ) && '' !== $ usersString ) { $ userIds = explode ( self :: FEATURE_CONFIGSTRING_ENTRY_DELIMITER , $ usersString ) ; $ this -> setUsers ( $ userIds ) ; } $ this -> setRoles ( array ( ) ) ; if ( true === is_string ( $ rolesString ) && '' !== $ rolesString ) { $ roleNames = explode ( self :: FEATURE_CONFIGSTRING_ENTRY_DELIMITER , $ rolesString ) ; $ this -> setRoles ( $ roleNames ) ; } $ this -> setGroups ( array ( ) ) ; if ( true === is_string ( $ groupsString ) && '' !== $ groupsString ) { $ groupNames = explode ( self :: FEATURE_CONFIGSTRING_ENTRY_DELIMITER , $ groupsString ) ; $ this -> setGroups ( $ groupNames ) ; } $ successsfullyConfigured = true ; } return $ successsfullyConfigured ; }
|
Configure the feature with a single string
|
54,916
|
public function clearConfig ( ) { $ this -> setPercentage ( ( integer ) 0 ) ; $ this -> setUsers ( array ( ) ) ; $ this -> setRoles ( array ( ) ) ; $ this -> setGroups ( array ( ) ) ; return $ this ; }
|
Resets the feature config
|
54,917
|
public function isActive ( RolloutAbstract $ rollout , DeterminableUserInterface $ user = null ) { if ( 100 === $ this -> getPercentage ( ) ) { return true ; } if ( ! $ user instanceof DeterminableUserInterface ) { return false ; } $ userId = $ user -> getId ( ) ; if ( true === $ this -> isUserInPercentage ( $ userId ) || true === $ this -> isUserInActiveUsers ( $ userId ) || true === $ this -> isUserInActiveRole ( $ user , $ rollout ) || true === $ this -> isUserInActiveGroup ( $ user , $ rollout ) ) { return true ; } return false ; }
|
Check if this feature is active for the given userId
|
54,918
|
public function addUser ( $ userId ) { if ( true === is_numeric ( $ userId ) && false === in_array ( $ userId , $ this -> users ) ) { $ this -> users [ ] = ( int ) $ userId ; } return $ this ; }
|
Adds a user to the list of user IDs that should be explicitly enabled for this feature
|
54,919
|
public function removeUser ( $ userId ) { if ( true === is_numeric ( $ userId ) && true === in_array ( $ userId , $ this -> users ) ) { foreach ( array_keys ( $ this -> users , ( int ) $ userId , true ) as $ key ) { unset ( $ this -> users [ $ key ] ) ; } } return $ this ; }
|
Removes a user from the list of user IDs that should be explicitly enabled for this feature
|
54,920
|
public function addRole ( $ roleName ) { if ( true === is_string ( $ roleName ) && false === in_array ( $ roleName , $ this -> roles ) ) { $ this -> roles [ ] = $ roleName ; } return $ this ; }
|
Adds a role to the list of role names that should be enabled for this feature
|
54,921
|
public function removeRole ( $ roleName ) { if ( true === is_string ( $ roleName ) && true === in_array ( $ roleName , $ this -> roles ) ) { foreach ( array_keys ( $ this -> roles , ( string ) $ roleName , true ) as $ key ) { unset ( $ this -> roles [ $ key ] ) ; } } return $ this ; }
|
Removes a role from the list of role names that should be enabled for this feature
|
54,922
|
public function addGroup ( $ groupName ) { if ( true === is_string ( $ groupName ) && false === in_array ( $ groupName , $ this -> groups ) ) { $ this -> groups [ ] = $ groupName ; } return $ this ; }
|
Adds a group to the list of group names that should be enabled for this feature
|
54,923
|
public function removeGroup ( $ groupName ) { if ( true === is_string ( $ groupName ) && true === in_array ( $ groupName , $ this -> groups ) ) { foreach ( array_keys ( $ this -> groups , ( string ) $ groupName , true ) as $ key ) { unset ( $ this -> groups [ $ key ] ) ; } } return $ this ; }
|
Removes a group from the list of group names that should be enabled for this feature
|
54,924
|
protected function checkUserIds ( array $ userIds ) { $ checkedUserIds = array ( ) ; foreach ( $ userIds as $ userId ) { if ( true === is_numeric ( $ userId ) && false === in_array ( $ userId , $ checkedUserIds ) ) { $ checkedUserIds [ ] = ( int ) $ userId ; } } return $ checkedUserIds ; }
|
Checks the user IDs and returns only the valid ones
|
54,925
|
protected function checkRoles ( array $ roles ) { $ checkedRoles = array ( ) ; foreach ( $ roles as $ role ) { if ( true === is_string ( $ role ) && false === in_array ( $ role , $ checkedRoles ) ) { $ checkedRoles [ ] = ( string ) $ role ; } } return $ checkedRoles ; }
|
Checks the roles and returns only the valid ones
|
54,926
|
protected function checkGroups ( array $ groups ) { $ checkedGroups = array ( ) ; foreach ( $ groups as $ group ) { if ( true === is_string ( $ group ) && false === in_array ( $ group , $ checkedGroups ) ) { $ checkedGroups [ ] = ( string ) $ group ; } } return $ checkedGroups ; }
|
Checks the groups and returns only the valid ones
|
54,927
|
public function writeLogMessage ( IncrementalOutputReceivedEvent $ event ) { $ project = $ event -> getProject ( ) ; $ process = $ event -> getProcess ( ) ; $ incrementalOutput = $ event -> getIncrementalOutput ( ) ; $ command = $ process -> getCommandLine ( ) ; $ filename = sprintf ( '%s%s.project.log' , $ this -> logPath , strtolower ( $ project -> getName ( ) ) ) ; $ dateTime = new \ DateTime ( ) ; $ timestamp = $ dateTime -> format ( 'Y-m-d H:i:s' ) ; $ fs = new Filesystem ( ) ; if ( ! isset ( $ this -> lastCommand [ $ project -> getName ( ) ] ) || $ this -> lastCommand [ $ project -> getName ( ) ] != $ command ) { if ( file_exists ( $ filename ) && file_get_contents ( $ filename ) != '' ) { $ fs -> appendToFile ( $ filename , "\n" ) ; } $ fs -> appendToFile ( $ filename , sprintf ( '[%s][Command]: %s' . "\n" . '[%s][Command output]:' . "\n" , $ timestamp , $ command , $ timestamp ) ) ; } $ fs -> appendToFile ( $ filename , sprintf ( '%s' . "\n" , $ incrementalOutput ) ) ; $ this -> lastCommand [ $ project -> getName ( ) ] = $ process -> getCommandLine ( ) ; }
|
Writes the incremental output received into a log file .
|
54,928
|
public function getUrl ( $ languageCode = null ) { if ( $ languageCode && in_array ( $ languageCode , Language :: getAllowedLanguages ( ) ) ) { return $ this -> url . '&lang=' . $ languageCode ; } return $ this -> url ; }
|
Get the url of the Invoice
|
54,929
|
public function getController ( ) { if ( $ controllerData = $ this -> component -> getData ( '_controller' ) ) { return $ controllerData ; } return $ this -> variation -> getConfiguration ( 'components' , $ this -> component -> getComponentType ( ) -> getName ( ) , 'controller' , $ this -> component -> getComponentType ( ) -> getController ( ) ) ; }
|
Returns context component controller .
|
54,930
|
public function getTemplatePath ( ) { if ( $ templateData = $ this -> component -> getData ( '_template' ) ) { return $ templateData ; } return $ this -> variation -> getConfiguration ( 'components' , $ this -> component -> getComponentType ( ) -> getName ( ) , 'path' , $ this -> component -> getComponentType ( ) -> getTemplatePath ( ) ) ; }
|
Returns context component template path .
|
54,931
|
public function match ( $ mixed ) { if ( ! ( $ mixed instanceof Request ) && ! is_string ( $ mixed ) ) { throw new \ InvalidArgumentException ( sprintf ( "Invalid Argument Error: Invalid type param, it can be a url string or a Request object, '%s' given." , gettype ( $ mixed ) ) ) ; } if ( $ this -> sortRoutesEnabled ) { $ this -> sortRoutes ( ) ; } foreach ( $ this -> routes as $ name => $ route ) { if ( ( $ params = $ route -> match ( $ mixed ) ) !== false ) { return $ params ; } } $ url = is_string ( $ mixed ) ? $ mixed : $ mixed -> getPathInfo ( ) ; throw new Exception \ ResourceNotFoundException ( $ url ) ; }
|
Match a url string given as parameter or with Request info .
|
54,932
|
protected function sortRoutes ( ) { $ routes = array ( ) ; foreach ( $ this -> routes as $ i => $ item ) { $ this -> routes [ $ i ] [ 'patCount' ] = count ( explode ( '/' , $ item -> getPattern ( ) ) ) ; $ this -> routes [ $ i ] [ 'reqCount' ] = count ( $ item -> getRequirements ( ) ) ; $ this -> routes [ $ i ] [ 'varCount' ] = count ( $ item -> getVars ( ) ) ; $ this -> routes [ $ i ] [ 'pop' ] = trim ( array_pop ( explode ( '/' , $ item -> getPattern ( ) ) ) ) ; } $ list = $ this -> routes ; usort ( $ list , function ( $ a , $ b ) { if ( $ b [ 'patCount' ] == $ a [ 'patCount' ] ) { return 0 ; } return $ b [ 'patCount' ] < $ a [ 'patCount' ] ? 1 : - 1 ; } ) ; $ n = count ( $ list ) ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) { $ j = $ i - 1 ; while ( $ j >= 0 && $ list [ $ j ] [ 'patCount' ] == $ list [ $ i ] [ 'patCount' ] && $ list [ $ j ] [ 'varCount' ] > $ list [ $ i ] [ 'varCount' ] ) { $ this -> swapValues ( $ list [ $ j + 1 ] , $ list [ $ j ] ) ; $ j -- ; } } for ( $ i = 1 ; $ i < $ n ; $ i ++ ) { $ j = $ i - 1 ; while ( $ j >= 0 && $ list [ $ j ] [ 'patCount' ] == $ list [ $ i ] [ 'patCount' ] && $ list [ $ j ] [ 'varCount' ] >= $ list [ $ i ] [ 'varCount' ] && $ list [ $ j ] [ 'reqCount' ] < $ list [ $ i ] [ 'reqCount' ] ) { $ this -> swapValues ( $ list [ $ j + 1 ] , $ list [ $ j ] ) ; $ j -- ; } } $ this -> routes = $ list ; }
|
This method sorts all routes connected to the mapper
|
54,933
|
protected function isCached ( $ filename ) { if ( ! empty ( $ this -> cacheDir ) ) { return false ; } $ cacheFile = $ this -> cacheDir . DIRECTORY_SEPARATOR . $ filename . ".cache" ; if ( file_exists ( $ cacheFile ) && is_array ( $ this -> cacheContent = include ( $ cacheFile ) ) && $ this -> cacheContent [ "_chk" ] == filemtime ( $ cacheFile ) ) { return true ; } return false ; }
|
Verify is a file is cached
|
54,934
|
protected function saveInCache ( $ filename , $ content ) { if ( empty ( $ this -> cacheDir ) || ! is_dir ( $ this -> cacheDir ) || ! is_writable ( $ this -> cacheDir ) ) { return false ; } $ content [ "_chk" ] = filemtime ( $ filename ) ; file_put_contents ( $ this -> cacheDir . DIRECTORY_SEPARATOR . basename ( $ filename ) . ".cache" , "<?php return " . var_export ( $ content , true ) . ";" ) ; return true ; }
|
Save in cache
|
54,935
|
protected function configureMachine ( array $ config ) { $ this -> loadMachineConfig ( $ config , [ 'table' , 'table_alias' , 'state_select' , 'filters' ] ) ; if ( $ this -> properties === null ) { if ( empty ( $ config [ 'properties' ] ) ) { $ this -> scanTableColumns ( ) ; } } parent :: configureMachine ( $ config ) ; if ( $ this -> pk_columns === null ) { $ this -> pk_columns = array ( ) ; foreach ( $ this -> properties as $ property => $ p ) { if ( ! empty ( $ p [ 'is_pk' ] ) ) { $ this -> pk_columns [ ] = $ property ; } } } if ( empty ( $ this -> pk_columns ) ) { throw new InvalidArgumentException ( 'Primary key is missing in table ' . var_export ( $ this -> table , true ) ) ; } $ this -> composed_properties = array ( ) ; $ this -> json_columns = array ( ) ; foreach ( $ this -> properties as $ property => $ p ) { if ( ! empty ( $ p [ 'components' ] ) ) { $ this -> composed_properties [ $ property ] = $ p [ 'components' ] ; } if ( isset ( $ p [ 'column_encoding' ] ) && $ p [ 'column_encoding' ] == 'json' ) { $ this -> json_columns [ ] = $ property ; } } }
|
Define state machine used by all instances of this type .
|
54,936
|
protected function scanTableColumns ( ) { $ driver = $ this -> flupdo -> getAttribute ( \ PDO :: ATTR_DRIVER_NAME ) ; switch ( $ driver ) { case 'sqlite' : $ r = $ this -> flupdo -> query ( 'PRAGMA table_info(' . $ this -> flupdo -> quoteIdent ( $ this -> table ) . ')' ) ; $ this -> properties = array ( ) ; foreach ( $ r as $ cm ) { $ this -> properties [ $ cm [ 'name' ] ] = array ( 'name' => $ cm [ 'name' ] , 'type' => $ cm [ 'type' ] , 'is_pk' => ( bool ) $ cm [ 'pk' ] , ) ; } break ; default : $ r = $ this -> flupdo -> select ( '*' ) -> from ( $ this -> flupdo -> quoteIdent ( $ this -> table ) ) -> where ( 'NULL' ) -> limit ( 0 ) -> query ( ) ; $ col_cnt = $ r -> columnCount ( ) ; $ this -> properties = array ( ) ; for ( $ i = 0 ; $ i < $ col_cnt ; $ i ++ ) { $ cm = $ r -> getColumnMeta ( $ i ) ; $ this -> properties [ $ cm [ 'name' ] ] = array ( 'name' => $ cm [ 'name' ] , 'type' => $ cm [ 'native_type' ] , 'is_pk' => in_array ( 'primary_key' , $ cm [ 'flags' ] ) , ) ; } break ; } }
|
Scan table in database and populate properties .
|
54,937
|
protected function checkAccessPolicy ( $ access_policy_name , Reference $ ref ) { if ( empty ( $ access_policy_name ) ) { return true ; } if ( ! isset ( $ this -> access_policies [ $ access_policy_name ] ) ) { throw new \ InvalidArgumentException ( 'Unknown policy: ' . $ access_policy_name ) ; } $ access_policy = $ this -> access_policies [ $ access_policy_name ] ; if ( $ this -> auth -> isAllMighty ( ) ) { return true ; } switch ( $ access_policy [ 'type' ] ) { case 'anyone' : return true ; case 'nobody' : return false ; case 'anonymous' : $ user_id = $ this -> auth -> getUserId ( ) ; return $ user_id === null ; case 'user' : $ user_id = $ this -> auth -> getUserId ( ) ; return $ user_id !== null ; case 'owner' : if ( $ ref -> isNullRef ( ) ) { return true ; } $ properties = $ ref -> properties ; $ user_id = $ this -> auth -> getUserId ( ) ; $ owner_property = $ access_policy [ 'owner_property' ] ; if ( isset ( $ access_policy [ 'session_state' ] ) ) { $ session_machine = $ this -> auth -> getSessionMachine ( ) ; if ( ! $ session_machine || $ session_machine -> state != $ access_policy [ 'session_state' ] ) { return false ; } } return $ user_id !== null ? $ user_id == $ properties [ $ owner_property ] : $ properties [ $ owner_property ] === null ; case 'role' : return $ this -> auth -> hasUserRoles ( $ access_policy [ 'required_role' ] ) ; case 'condition' : if ( $ ref -> isNullRef ( ) ) { return false ; } $ properties = $ ref -> properties ; return ! empty ( $ properties [ '_access_policy_' . $ access_policy_name ] ) ; case 'user_relation' : if ( $ ref -> isNullRef ( ) ) { return false ; } $ properties = $ ref -> properties ; return ! empty ( $ properties [ '_access_policy_' . $ access_policy_name ] ) ; default : return false ; } throw new \ RuntimeException ( 'Policy ' . $ policy . ' did not decide.' ) ; }
|
Returns true if user has required access_policy .
|
54,938
|
protected function queryAddAccessPolicyCondition ( $ access_policy_name , $ query ) { if ( empty ( $ access_policy_name ) ) { return ; } if ( ! isset ( $ this -> access_policies [ $ access_policy_name ] ) ) { throw new \ InvalidArgumentException ( 'Unknown policy: ' . $ access_policy_name ) ; } $ access_policy = $ this -> access_policies [ $ access_policy_name ] ; if ( $ this -> auth -> isAllMighty ( ) ) { return ; } switch ( $ access_policy [ 'type' ] ) { case 'anyone' : return ; case 'anonymous' : $ user_id = $ this -> auth -> getUserId ( ) ; $ query -> where ( $ user_id === null ? 'TRUE' : 'FALSE' ) ; return ; case 'user' : $ user_id = $ this -> auth -> getUserId ( ) ; $ query -> where ( $ user_id !== null ? 'TRUE' : 'FALSE' ) ; return ; case 'owner' : $ user_id = $ this -> auth -> getUserId ( ) ; $ owner_property = $ query -> quoteIdent ( $ access_policy [ 'owner_property' ] ) ; $ table = $ query -> quoteIdent ( $ this -> table ) ; if ( isset ( $ access_policy [ 'session_state' ] ) ) { if ( $ this -> auth -> getSessionMachine ( ) -> state != $ access_policy [ 'session_state' ] ) { $ query -> where ( 'FALSE' ) ; return ; } } if ( $ user_id === null ) { $ query -> where ( "$table.$owner_property IS NULL" ) ; return ; } else { $ query -> where ( "$table.$owner_property = ?" , $ user_id ) ; return ; } case 'role' : $ query -> where ( $ this -> auth -> hasUserRoles ( $ access_policy [ 'required_role' ] ) ? 'TRUE' : 'FALSE' ) ; return ; case 'condition' : $ this -> queryAddSimpleAccessPolicyCondition ( $ access_policy_name , $ access_policy , $ query , 'where' ) ; return ; case 'user_relation' : $ this -> queryAddUserRelationAccessPolicyCondition ( $ access_policy_name , $ access_policy , $ query , 'where' ) ; return ; default : $ query -> where ( 'FALSE' ) ; return ; } throw new \ RuntimeException ( 'Policy ' . $ policy . ' did not decide.' ) ; }
|
Adds conditions to enforce read access_policy to query object .
|
54,939
|
public function createListing ( $ filters , $ filtering_flags = 0 ) { $ q = $ this -> createQueryBuilder ( ) ; $ this -> queryAddStateSelect ( $ q ) ; $ this -> queryAddPropertiesSelect ( $ q ) ; if ( isset ( $ this -> listing_access_policy ) ) { $ this -> queryAddAccessPolicyCondition ( $ this -> listing_access_policy , $ q ) ; } if ( isset ( $ this -> default_filters ) ) { $ filters = array_replace ( $ this -> default_filters , $ filters ) ; } return new \ Smalldb \ StateMachine \ FlupdoGenericListing ( $ this , $ q , $ this -> sphinx , $ filters , $ this -> table , $ this -> filters , $ this -> properties , $ this -> references , $ this -> additional_filters_data , $ this -> state_select , $ filtering_flags ) ; }
|
Create generic listing on this machine type .
|
54,940
|
public function createQueryBuilder ( ) { $ q = $ this -> flupdo -> select ( ) ; $ this -> queryAddFrom ( $ q ) ; $ this -> queryAddAccessPolicyCondition ( $ this -> read_access_policy , $ q ) ; return $ q ; }
|
Create query builder .
|
54,941
|
protected function queryGetThisTable ( $ query ) { if ( $ this -> table_alias ) { return $ query -> quoteIdent ( $ this -> table ) . ' AS ' . $ query -> quoteIdent ( $ this -> table_alias ) ; } else { return $ query -> quoteIdent ( $ this -> table ) ; } }
|
Get table name with alias
|
54,942
|
private function queryAddPropertySelect ( \ Smalldb \ Flupdo \ FlupdoBuilder $ query , string $ table_alias , string $ property_name , array $ property , string $ property_prefix = '' ) { $ table_q = $ query -> quoteIdent ( $ table_alias ) ; $ p_q = $ query -> quoteIdent ( $ property_name ) ; $ pa_q = $ query -> quoteIdent ( $ property_prefix . $ property_name ) ; if ( ! empty ( $ property [ 'components' ] ) ) { foreach ( $ property [ 'components' ] as $ component => $ column ) { if ( ! isset ( $ this -> properties [ $ column ] ) ) { $ column_q = $ query -> quoteIdent ( $ column ) ; $ alias_q = $ property_prefix !== '' ? $ query -> quoteIdent ( $ property_prefix . $ column ) : $ column_q ; $ query -> select ( "$table_q.$column_q AS $alias_q" ) ; } } } else if ( ( ! empty ( $ property [ 'is_calculated' ] ) || ! empty ( $ property [ 'calculated' ] ) ) && isset ( $ property [ 'sql_select' ] ) ) { $ query -> select ( "({$property['sql_select']}) AS $pa_q" ) ; } else { $ query -> select ( "$table_q.$p_q AS $pa_q" ) ; } }
|
Add a single property to the query .
|
54,943
|
protected function queryAddPrimaryKeyWhere ( $ query , $ id , $ clause = 'where' ) { $ table = $ query -> quoteIdent ( $ this -> table_alias ? $ this -> table_alias : $ this -> table ) ; if ( $ id === null || $ id === array ( ) || $ id === false || $ id === '' ) { throw new InvalidArgumentException ( 'Empty ID.' ) ; } else if ( count ( $ id ) != count ( $ this -> describeId ( ) ) ) { throw new InvalidArgumentException ( sprintf ( 'Malformed ID: got %d pieces of %d.' , count ( $ id ) , count ( $ this -> describeId ( ) ) ) ) ; } foreach ( array_combine ( $ this -> describeId ( ) , ( array ) $ id ) as $ col => $ val ) { $ query -> $ clause ( $ table . '.' . $ query -> quoteIdent ( $ col ) . ' = ?' , $ val ) ; } return $ query ; }
|
Add primary key condition to where clause . Result should contain only one row now .
|
54,944
|
public function getProperties ( $ id , & $ state_cache = null ) { if ( $ id === null || $ id === array ( ) ) { throw new InstanceDoesNotExistException ( 'State machine instance does not exist (null ID).' ) ; } $ q = $ this -> createQueryBuilder ( ) -> select ( null ) -> limit ( 1 ) ; $ this -> queryAddPropertiesSelect ( $ q ) ; $ this -> queryAddPrimaryKeyWhere ( $ q , $ id ) ; if ( $ this -> load_state_with_properties ) { $ this -> queryAddStateSelect ( $ q ) ; } $ r = $ q -> query ( ) ; $ props = $ r -> fetch ( \ PDO :: FETCH_ASSOC ) ; $ r -> closeCursor ( ) ; if ( $ props === false ) { throw new InstanceDoesNotExistException ( 'State machine instance not found: ' . json_encode ( $ id , JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK ) ) ; } if ( $ this -> load_state_with_properties ) { $ state_cache = array_pop ( $ props ) ; } return $ this -> decodeProperties ( $ props ) ; }
|
Get all properties of state machine including it s state .
|
54,945
|
public function encodeProperties ( $ properties ) { foreach ( $ properties as $ k => & $ v ) { if ( isset ( $ this -> properties [ $ k ] ) ) { $ prop = $ this -> properties [ $ k ] ; if ( empty ( $ prop [ 'required' ] ) && ( $ v === array ( ) || ( is_string ( $ v ) && ctype_space ( $ v ) ) ) ) { $ v = null ; } } else { unset ( $ properties [ $ k ] ) ; } } foreach ( $ this -> composed_properties as $ property => $ components ) { foreach ( $ components as $ component => $ column ) { if ( isset ( $ properties [ $ property ] [ $ component ] ) ) { $ properties [ $ column ] = $ properties [ $ property ] [ $ component ] ; } else { $ properties [ $ column ] = null ; } } unset ( $ properties [ $ property ] ) ; } foreach ( $ this -> json_columns as $ column_name ) { if ( isset ( $ properties [ $ column_name ] ) ) { $ json_data = json_encode ( $ properties [ $ column_name ] , JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK ) ; if ( $ json_data === FALSE ) { switch ( json_last_error ( ) ) { case JSON_ERROR_NONE : $ json_error = 'No error has occurred' ; break ; case JSON_ERROR_DEPTH : $ json_error = 'The maximum stack depth has been exceeded' ; break ; case JSON_ERROR_STATE_MISMATCH : $ json_error = 'Invalid or malformed JSON' ; break ; case JSON_ERROR_CTRL_CHAR : $ json_error = 'Control character error, possibly incorrectly encoded' ; break ; case JSON_ERROR_SYNTAX : $ json_error = 'Syntax error' ; break ; case JSON_ERROR_UTF8 : $ json_error = 'Malformed UTF-8 characters, possibly incorrectly encoded' ; break ; case JSON_ERROR_RECURSION : $ json_error = 'One or more recursive references in the value to be encoded' ; break ; case JSON_ERROR_INF_OR_NAN : $ json_error = 'One or more NAN or INF values in the value to be encoded' ; break ; case JSON_ERROR_UNSUPPORTED_TYPE : $ json_error = 'A value of a type that cannot be encoded was given' ; break ; default : $ json_error = 'Error ' . json_last_error ( ) ; break ; } throw new \ InvalidArgumentException ( 'Failed to serialize invoice data to JSON: ' . $ json_error ) ; } $ properties [ $ column_name ] = $ json_data ; } } return $ properties ; }
|
Encode properties to database representation .
|
54,946
|
public function decodeProperties ( $ properties ) { foreach ( $ this -> composed_properties as $ property => $ components ) { $ value = array ( ) ; foreach ( $ components as $ component => $ column ) { $ value [ $ component ] = isset ( $ properties [ $ column ] ) ? $ properties [ $ column ] : null ; } $ properties [ $ property ] = $ value ; } foreach ( $ this -> json_columns as $ column_name ) { if ( isset ( $ properties [ $ column_name ] ) ) { $ properties [ $ column_name ] = json_decode ( $ properties [ $ column_name ] , TRUE , 512 , JSON_BIGINT_AS_STRING ) ; } } return $ properties ; }
|
Decode properties from database representation
|
54,947
|
public function isSupported ( array $ data ) { try { new DateTime ( $ data [ $ this -> getProperty ( ) ] ) ; } catch ( Exception $ e ) { return false ; } return true ; }
|
Is data supported?
|
54,948
|
private function getColumnAnnotation ( $ reflectionProperty ) { $ columnAnnotation = $ this -> getReader ( ) -> getPropertyAnnotation ( $ reflectionProperty , Column :: class ) ; if ( null === $ columnAnnotation ) { return null ; } return $ columnAnnotation -> type ; }
|
Get Column Annotation
|
54,949
|
public function thickbox ( ) { ?> <script type="text/javascript"> jQuery(document).ready(function ($) { $(document).on('click', '#ibd-wp-notifications-template-tags- <?php echo self :: $ count ; ?> ', function (e) { var tag = jQuery("#ibd-wp-notifications-add-tag-value- <?php echo self :: $ count ; ?> ").val(); if (tag.length == 0 || tag == -1) { alert(" <?php echo esc_js ( $ this -> translations [ 'mustSelectItem' ] ) ; ?> "); return; } window.send_to_editor(tag); tb_remove(); }); }); </script> <div id="ibd-wp-notifications-select-tag- <?php echo self :: $ count ; ?> " style="display: none"> <div class="wrap"> <div> <p> <?php echo $ this -> translations [ 'selectTemplateTag' ] ; ?> </p> <label for="ibd-wp-notifications-add-tag-value- <?php echo self :: $ count ; ?> "> <?php echo $ this -> translations [ 'templateTag' ] ; ?> </label><br> <select id="ibd-wp-notifications-add-tag-value- <?php echo self :: $ count ; ?> "> <option value="-1"> <?php echo $ this -> translations [ 'selectATag' ] ; ?> </option> <?php foreach ( $ this -> manager -> get_listeners ( ) as $ listener ) : ?> <option value=" <?php echo esc_attr ( "{" . $ listener -> get_tag ( ) . "}" ) ; ?> "> <?php echo $ listener ; ?> </option> <?php endforeach ; ?> </select> </div> <div style="padding: 15px 15px 15px 0"> <input type="button" class="button-primary" id="ibd-wp-notifications-template-tags- <?php echo self :: $ count ; ?> " value=" <?php echo esc_attr ( $ this -> translations [ 'insertTag' ] ) ; ?> " /> <a class="button" style="color:#bbb;" href="#" onclick="tb_remove(); return false;"> <?php echo $ this -> translations [ 'cancel' ] ; ?> </a> </div> </div> </div> <?php }
|
Render the thickbox .
|
54,950
|
public function display_template_tag_button ( ) { add_thickbox ( ) ; $ id = 'ibd-wp-notifications-select-tag-' . self :: $ count ; $ class = 'thickbox button ibd-wp-notifications-tags' ; $ title = $ this -> translations [ 'insertTemplateTag' ] ; echo '<a href="#TB_inline?width=150height=250&inlineId=' . $ id . '" class="' . $ class . '" title="' . $ title . '"> ' . $ title . '</a>' ; }
|
Display the template tag button button .
|
54,951
|
protected function ask ( $ question , $ default = null , $ validator = null ) { return $ this -> output -> ask ( $ question , $ default , $ validator ) ; }
|
To ask question
|
54,952
|
protected function call ( $ command , $ params = [ ] ) { $ parameters [ 'command' ] = $ command ; foreach ( $ params as $ key => $ value ) { $ parameters [ $ key ] = $ value ; } $ command = $ this -> getApplication ( ) -> find ( $ command ) ; return $ command -> run ( new ArrayInput ( $ parameters ) , $ this -> output ) ; }
|
To call another console command
|
54,953
|
protected function createFile ( $ folder , $ filename , $ stubs , $ defaultFolder = '' ) { if ( ! empty ( $ folder = implode ( '/' , $ folder ) ) ) { $ dir = app_path ( ) . "{$defaultFolder}/{$folder}" ; $ this -> filesystem -> createDirectory ( $ dir ) ; $ this -> filesystem -> create ( "{$dir}/{$filename}.php" , $ stubs ) ; } else { $ this -> filesystem -> create ( app_path ( ) . "{$defaultFolder}/{$filename}.php" , $ stubs ) ; } }
|
Create file from stubs
|
54,954
|
protected function _setRenderer ( $ renderer ) { if ( $ renderer !== null && ! ( $ renderer instanceof RendererInterface ) ) { throw $ this -> _createInvalidArgumentException ( $ this -> __ ( 'Invalid renderer' ) , null , null , $ renderer ) ; } $ this -> renderer = $ renderer ; }
|
Sets the renderer for this instance .
|
54,955
|
public function append ( $ list = null ) { if ( is_string ( $ list ) ) { $ this -> _list [ ] = $ list ; } if ( is_array ( $ list ) ) { $ this -> _list = array_merge ( $ this -> _list , $ list ) ; } return $ this ; }
|
Append Path or List to List
|
54,956
|
public function get ( $ js = null , $ compress = true ) { if ( null === $ js ) { foreach ( ( array ) $ this -> _list as $ src ) { if ( ! file_exists ( $ src ) ) { continue ; } $ js .= file_get_contents ( $ src ) ; } } $ this -> _list = [ ] ; return $ compress ? $ this -> parse ( $ js ) : $ js ; }
|
Get Packed JavaScript
|
54,957
|
public function save ( $ dest = null , $ compress = true ) { if ( ! file_exists ( dirname ( $ dest ) ) ) { mkdir ( dirname ( $ dest ) , 0755 , true ) ; } file_put_contents ( $ dest , $ this -> get ( null , $ compress ) ) ; }
|
Save JavaScript to File
|
54,958
|
public function getWebPath ( ) { return sprintf ( '%s%s%s' , $ this -> load ( 'assetsWebPath' ) , $ this -> file -> getStorePath ( ) , $ this -> file -> getName ( ) ) ; }
|
Return Media web path .
|
54,959
|
protected function bbcode_action ( $ tag , $ part , $ position , $ tag_extended = false ) { for ( $ i = 1 ; $ i <= $ this -> array_size ; $ i ++ ) { if ( $ this -> bbcode_list [ $ this -> array_size - $ i ] [ 'bbcode_tag' ] == $ tag ) { if ( ! $ this -> bbcode_list [ $ this -> array_size - $ i ] [ $ part ] ) { $ this -> bbcode_list [ $ this -> array_size - $ i ] [ $ part ] = $ position ; if ( $ tag_extended ) { $ this -> bbcode_list [ $ this -> array_size - $ i ] [ 'bbcode_tag' ] = $ tag_extended ; } return ; } } } }
|
Add position to a listed bbcode
|
54,960
|
public function remove_bbcodes_after ( ) { for ( $ i = 1 ; $ i <= $ this -> array_size ; $ i ++ ) { if ( $ this -> bbcode_list [ $ this -> array_size - $ i ] [ 'open_start' ] >= $ this -> trim_position ) { unset ( $ this -> bbcode_list [ $ this -> array_size - $ i ] ) ; } } $ this -> array_size = sizeof ( $ this -> bbcode_list ) ; }
|
Removes all BBcodes after a given position
|
54,961
|
public function get_open_bbcodes_after ( $ position ) { $ bbcodes = array ( ) ; for ( $ i = 1 ; $ i <= $ this -> array_size ; $ i ++ ) { if ( ( $ this -> bbcode_list [ $ this -> array_size - $ i ] [ 'open_start' ] < $ position ) && ( $ this -> bbcode_list [ $ this -> array_size - $ i ] [ 'close_start' ] >= $ position ) ) { $ bbcodes [ ] = $ this -> bbcode_list [ $ this -> array_size - $ i ] [ 'bbcode_tag' ] ; } } return $ bbcodes ; }
|
Returns an array with BBCodes that need to be closed after the position .
|
54,962
|
public function get_content_position ( $ content , $ allowed_length ) { $ content = $ this -> restore_square_brackets_in_smilies ( $ content ) ; if ( utf8_strpos ( utf8_substr ( $ content , 0 , $ allowed_length ) , '<' ) === false ) { return $ allowed_length ; } $ content_length = $ allowed_length ; $ start_position = 0 ; $ last_smiley = false ; while ( ( $ last_html_opening = utf8_strpos ( utf8_substr ( $ content , 0 , $ content_length ) , '<' , $ start_position ) ) !== false ) { $ last_html_closing = utf8_strpos ( $ content , '>' , $ last_html_opening ) ; $ content_length += ( $ last_html_closing - $ last_html_opening ) + 1 ; $ smiley_code = utf8_substr ( $ content , $ last_html_opening + 6 , ( $ last_html_closing - $ last_html_opening - 9 ) ) ; if ( ( $ smiley_code != '--' ) && ( utf8_strpos ( $ smiley_code , 'c="{SMILIES_PATH}/' ) === false ) ) { if ( $ last_smiley == $ smiley_code ) { $ content_length -= utf8_strlen ( $ smiley_code ) ; $ last_smiley = false ; } else { $ last_smiley = $ smiley_code ; } } $ start_position = $ last_html_opening + 1 ; } return $ content_length ; }
|
Get the position in the text where we need to cut the message .
|
54,963
|
protected function replace_square_brackets_in_smilies ( ) { if ( utf8_strpos ( $ this -> message , '<' ) !== false ) { $ this -> bracket_replacement = '{' . md5 ( $ this -> message ) . '}' ; while ( utf8_strpos ( $ this -> message , $ this -> bracket_replacement ) !== false ) { $ this -> bracket_replacement = '{' . $ this -> bracket_replacement . '}' ; } $ smilie_starts = explode ( '<' , $ this -> message ) ; $ new_message = array ( ) ; foreach ( $ smilie_starts as $ smilie_test ) { $ find_end = explode ( '>' , $ smilie_test ) ; if ( sizeof ( $ find_end ) > 1 ) { $ find_end [ 0 ] = str_replace ( '[' , $ this -> bracket_replacement , $ find_end [ 0 ] ) ; $ new_message [ ] = implode ( '>' , $ find_end ) ; } else { $ new_message [ ] = $ smilie_test ; } } $ this -> message = implode ( '<' , $ new_message ) ; } }
|
Replace square brackets in smiley codes
|
54,964
|
public function encode ( $ numbers ) { if ( ! is_array ( $ numbers ) ) { $ numbers = [ $ numbers ] ; } if ( $ this -> signed ) { $ numbers = Signed :: encodeBlock ( $ numbers ) ; } $ digits = [ ] ; $ bits = $ this -> bits ; $ cBit = $ this -> cBit ; foreach ( $ numbers as $ number ) { do { $ digit = ( $ number % $ this -> cBit ) ; $ number >>= $ bits ; $ continue = ( $ number > 0 ) ; if ( $ continue ) { $ digit += $ cBit ; } $ digits [ ] = $ digit ; } while ( $ continue ) ; } return $ digits ; }
|
Encodes a block of numbers to a VLQ - sequence
|
54,965
|
public function decode ( array $ digits ) { $ result = [ ] ; $ current = 0 ; $ cBit = $ this -> cBit ; $ bits = $ this -> bits ; $ shift = 0 ; foreach ( $ digits as $ digit ) { $ current += ( ( $ digit % $ cBit ) << $ shift ) ; if ( $ digit < $ cBit ) { $ result [ ] = $ current ; $ current = 0 ; $ shift = 0 ; } else { $ shift += $ bits ; } } if ( $ current > 0 ) { throw new InvalidVLQSequence ( $ digits ) ; } if ( $ this -> signed ) { $ result = Signed :: decodeBlock ( $ result ) ; } return $ result ; }
|
Decodes a VLQ - sequence to a block of numbers
|
54,966
|
private function registerObserver ( ) { if ( $ this -> observer ) { return ; } $ this -> observer = new \ chilimatic \ lib \ session \ observer \ Session ( $ this ) ; $ this -> engine -> attach ( $ this -> observer ) ; }
|
attaches the observer to the subject within the engine
|
54,967
|
public function extendQueryBuilder ( QueryBuilder $ queryBuilder ) { $ queryBuilder -> setFirstResult ( $ this -> getFirstResult ( ) ) -> setMaxResults ( $ this -> getLimit ( ) ) ; return $ this ; }
|
Extend Query Builder
|
54,968
|
protected function formatGatewayClassName ( $ name ) { if ( class_exists ( $ name ) ) { return $ name ; } $ name = $ this -> camelCase ( $ name ) ; return __NAMESPACE__ . "\\Gateways\\{$name}Gateway" ; }
|
Format gateway name .
|
54,969
|
protected function callCustomCreator ( $ gateway ) { return call_user_func ( $ this -> customCreators [ $ gateway ] , $ this -> config -> get ( $ gateway ) ) ; }
|
Call a custom gateway creator .
|
54,970
|
public function apply ( array $ properties ) { $ properties = $ this -> applyDefaultAttrValues ( $ properties ) ; foreach ( $ properties as $ key => $ value ) { if ( true === $ this -> isAttribute ( $ key ) ) { $ this -> set ( $ key , $ value ) ; continue ; } if ( true === $ this -> isEmbedHasOne ( $ key ) ) { if ( empty ( $ value ) ) { $ this -> clear ( $ key ) ; continue ; } $ embed = $ this -> get ( $ key ) ? : $ this -> createEmbedFor ( $ key , $ value ) ; if ( ! is_array ( $ value ) ) { continue ; } $ embed -> apply ( $ value ) ; $ this -> set ( $ key , $ embed ) ; continue ; } } foreach ( $ this -> getMetadata ( ) -> getEmbeds ( ) as $ key => $ embeddedPropMeta ) { if ( true === $ embeddedPropMeta -> isOne ( ) || ! isset ( $ properties [ $ key ] ) ) { continue ; } $ collection = $ this -> getStore ( ) -> createEmbedCollection ( $ embeddedPropMeta , $ properties [ $ key ] ) ; if ( $ collection -> getHash ( ) === $ this -> get ( $ key ) -> getHash ( ) ) { continue ; } $ this -> clear ( $ key ) ; foreach ( $ collection as $ value ) { $ this -> pushEmbed ( $ key , $ value ) ; } } $ this -> doDirtyCheck ( ) ; return $ this ; }
|
Applies an array of raw model properties to the model instance .
|
54,971
|
public function clear ( $ key ) { if ( true === $ this -> isAttribute ( $ key ) ) { return $ this -> setAttribute ( $ key , null ) ; } if ( true === $ this -> isEmbedHasOne ( $ key ) ) { return $ this -> setEmbedHasOne ( $ key , null ) ; } if ( true === $ this -> isEmbedHasMany ( $ key ) ) { $ collection = $ this -> hasManyEmbeds -> get ( $ key ) ; $ collection -> clear ( ) ; $ this -> doDirtyCheck ( ) ; return $ this ; } return $ this ; }
|
Clears a property value . For an attribute will set the value to null . For collections will clear the collection contents .
|
54,972
|
public function createEmbedFor ( $ key ) { if ( false === $ this -> isEmbed ( $ key ) ) { throw new \ RuntimeException ( sprintf ( 'Unable to create an Embed instance for property key "%s" - the property is not an embed.' , $ key ) ) ; } $ embedMeta = $ this -> getMetadata ( ) -> getEmbed ( $ key ) -> embedMeta ; $ embed = $ this -> getStore ( ) -> loadEmbed ( $ embedMeta , [ ] ) ; $ embed -> getState ( ) -> setNew ( ) ; return $ embed ; }
|
Creates a new Embed model instance for the provided property key .
|
54,973
|
public function get ( $ key ) { if ( true === $ this -> isAttribute ( $ key ) ) { return $ this -> getAttribute ( $ key ) ; } if ( true === $ this -> isEmbed ( $ key ) ) { return $ this -> getEmbed ( $ key ) ; } }
|
Gets a model property . Returns null if the property does not exist on the model or is not set .
|
54,974
|
public function getChangeSet ( ) { return [ 'attributes' => $ this -> filterNotSavedProperties ( $ this -> attributes -> calculateChangeSet ( ) ) , 'embedOne' => $ this -> hasOneEmbeds -> calculateChangeSet ( ) , 'embedMany' => $ this -> hasManyEmbeds -> calculateChangeSet ( ) , ] ; }
|
Gets the current change set of properties .
|
54,975
|
public function initialize ( array $ properties = null ) { $ attributes = [ ] ; $ embedOne = [ ] ; $ embedMany = [ ] ; if ( null !== $ properties ) { $ attributes = $ this -> applyDefaultAttrValues ( $ attributes ) ; foreach ( $ properties as $ key => $ value ) { if ( true === $ this -> isAttribute ( $ key ) ) { $ attributes [ $ key ] = $ this -> convertAttributeValue ( $ key , $ value ) ; } else if ( true === $ this -> isEmbedHasOne ( $ key ) && is_array ( $ value ) ) { $ embedOne [ $ key ] = $ this -> getStore ( ) -> loadEmbed ( $ this -> getMetadata ( ) -> getEmbed ( $ key ) -> embedMeta , $ value ) ; } } } foreach ( $ this -> getMetadata ( ) -> getEmbeds ( ) as $ key => $ embeddedPropMeta ) { if ( true === $ embeddedPropMeta -> isOne ( ) ) { continue ; } $ embeds = ! isset ( $ properties [ $ key ] ) ? [ ] : $ properties [ $ key ] ; $ embedMany [ $ key ] = $ this -> getStore ( ) -> createEmbedCollection ( $ embeddedPropMeta , $ embeds ) ; } $ this -> attributes = ( null === $ this -> attributes ) ? new Attributes ( $ attributes ) : $ this -> attributes -> replace ( $ attributes ) ; $ this -> hasOneEmbeds = ( null === $ this -> hasOneEmbeds ) ? new Embeds \ HasOne ( $ embedOne ) : $ this -> hasOneEmbeds -> replace ( $ embedOne ) ; $ this -> hasManyEmbeds = ( null === $ this -> hasManyEmbeds ) ? new Embeds \ HasMany ( $ embedMany ) : $ this -> hasManyEmbeds -> replace ( $ embedMany ) ; if ( true === $ this -> getState ( ) -> is ( 'new' ) ) { $ this -> apply ( [ ] ) ; } $ this -> doDirtyCheck ( ) ; return $ this ; }
|
Initializes the model and loads its attributes and relationships .
|
54,976
|
public function isDirty ( ) { return true === $ this -> attributes -> areDirty ( ) || true === $ this -> hasOneEmbeds -> areDirty ( ) || true === $ this -> hasManyEmbeds -> areDirty ( ) ; }
|
Determines if the model is currently dirty .
|
54,977
|
public function isEmbedHasMany ( $ key ) { if ( false === $ this -> isEmbed ( $ key ) ) { return false ; } return $ this -> getMetadata ( ) -> getEmbed ( $ key ) -> isMany ( ) ; }
|
Determines if a property key is a has - many embed .
|
54,978
|
public function isEmbedHasOne ( $ key ) { if ( false === $ this -> isEmbed ( $ key ) ) { return false ; } return $ this -> getMetadata ( ) -> getEmbed ( $ key ) -> isOne ( ) ; }
|
Determines if a property key is a has - one embed .
|
54,979
|
public function removeEmbed ( $ key , Embed $ embed ) { if ( false === $ this -> isEmbedHasMany ( $ key ) ) { return $ this ; } $ this -> touch ( ) ; $ collection = $ this -> hasManyEmbeds -> get ( $ key ) ; $ collection -> remove ( $ embed ) ; $ this -> doDirtyCheck ( ) ; return $ this ; }
|
Removes a specific Embed from a has - many embed collection .
|
54,980
|
public function rollback ( ) { $ this -> attributes -> rollback ( ) ; $ this -> hasOneEmbeds -> rollback ( ) ; $ this -> hasManyEmbeds -> rollback ( ) ; $ this -> doDirtyCheck ( ) ; return $ this ; }
|
Rolls back a model to its original values .
|
54,981
|
public function set ( $ key , $ value ) { if ( true === $ this -> isAttribute ( $ key ) ) { return $ this -> setAttribute ( $ key , $ value ) ; } if ( true === $ this -> isEmbed ( $ key ) ) { return $ this -> setEmbed ( $ key , $ value ) ; } }
|
Sets a model property .
|
54,982
|
protected function applyDefaultAttrValues ( array $ attributes = [ ] ) { foreach ( $ this -> getMetadata ( ) -> getAttributes ( ) as $ key => $ attrMeta ) { if ( ! isset ( $ attrMeta -> defaultValue ) || isset ( $ attributes [ $ key ] ) ) { continue ; } $ attributes [ $ key ] = $ this -> convertAttributeValue ( $ key , $ attrMeta -> defaultValue ) ; } return $ attributes ; }
|
Applies default attribute values from metadata if set .
|
54,983
|
protected function convertAttributeValue ( $ key , $ value ) { return $ this -> store -> convertAttributeValue ( $ this -> getDataType ( $ key ) , $ value ) ; }
|
Converts an attribute value to the appropriate data type .
|
54,984
|
protected function filterNotSavedProperties ( array $ properties ) { foreach ( $ this -> getMetadata ( ) -> getAttributes ( ) as $ fieldKey => $ propMeta ) { if ( true === $ propMeta -> shouldSave ( ) || ! isset ( $ properties [ $ fieldKey ] ) ) { continue ; } unset ( $ properties [ $ fieldKey ] ) ; } return $ properties ; }
|
Removes properties marked as non - saved .
|
54,985
|
protected function getAttribute ( $ key ) { if ( true === $ this -> isCalculatedAttribute ( $ key ) ) { return $ this -> getCalculatedAttribute ( $ key ) ; } $ this -> touch ( ) ; return $ this -> attributes -> get ( $ key ) ; }
|
Gets an attribute value .
|
54,986
|
protected function getCalculatedAttribute ( $ key ) { $ attrMeta = $ this -> getMetadata ( ) -> getAttribute ( $ key ) ; $ class = $ attrMeta -> calculated [ 'class' ] ; $ method = $ attrMeta -> calculated [ 'method' ] ; $ value = $ class :: $ method ( $ this ) ; return $ this -> convertAttributeValue ( $ key , $ value ) ; }
|
Gets a calculated attribute value .
|
54,987
|
protected function getEmbed ( $ key ) { if ( true === $ this -> isEmbedHasOne ( $ key ) ) { $ this -> touch ( ) ; return $ this -> hasOneEmbeds -> get ( $ key ) ; } if ( true === $ this -> isEmbedHasMany ( $ key ) ) { $ this -> touch ( ) ; return $ this -> hasManyEmbeds -> get ( $ key ) ; } return null ; }
|
Gets an embed value .
|
54,988
|
protected function isCalculatedAttribute ( $ key ) { if ( false === $ this -> isAttribute ( $ key ) ) { return false ; } return $ this -> getMetadata ( ) -> getAttribute ( $ key ) -> isCalculated ( ) ; }
|
Determines if an attribute key is calculated .
|
54,989
|
protected function setEmbed ( $ key , $ value ) { if ( true === $ this -> isEmbedHasOne ( $ key ) ) { return $ this -> setEmbedHasOne ( $ key , $ value ) ; } if ( true === $ this -> isEmbedHasMany ( $ key ) ) { throw new \ RuntimeException ( 'You cannot set a hasMany embed directly. Please access using pushEmbed(), clear(), and/or remove()' ) ; } return $ this ; }
|
Sets an embed value .
|
54,990
|
protected function setEmbedHasOne ( $ key , Embed $ embed = null ) { if ( null !== $ embed ) { $ this -> validateEmbedSet ( $ key , $ embed -> getName ( ) ) ; } $ this -> touch ( ) ; $ this -> hasOneEmbeds -> set ( $ key , $ embed ) ; $ this -> doDirtyCheck ( ) ; return $ this ; }
|
Sets a has - one embed .
|
54,991
|
public static function get ( $ slug ) { return isset ( self :: $ queues [ $ slug ] ) ? self :: $ queues [ $ slug ] : null ; }
|
Retrieve a queue .
|
54,992
|
protected function _extractContent ( $ tokenId , $ tokens ) { $ token = $ tokens [ $ tokenId ] ; $ body = $ this -> _controlContent ( $ tokenId , $ tokens ) ; $ line = $ token [ 'line' ] ; while ( -- $ tokenId >= 0 && $ tokens [ $ tokenId ] [ 'line' ] === $ line ) { $ body = $ tokens [ $ tokenId ] [ 'content' ] . $ body ; } return $ body ; }
|
Extract the Control content and its prefix
|
54,993
|
protected function _controlContent ( $ tokenId , $ tokens , $ root = true ) { $ token = $ tokens [ $ tokenId ] ; $ body = $ token [ 'content' ] ; foreach ( $ token [ 'children' ] as $ childrenId ) { if ( ! $ tokens [ $ childrenId ] [ 'children' ] ) { $ body .= $ tokens [ $ childrenId ] [ 'content' ] ; } elseif ( $ root && $ tokens [ $ childrenId ] [ 'content' ] === '{' ) { $ body .= $ tokens [ $ childrenId ] [ 'content' ] ; break ; } else { $ body .= $ this -> _controlContent ( $ childrenId , $ tokens , false ) ; } } return $ body ; }
|
Extract the control content
|
54,994
|
protected function _matchPattern ( $ patterns , $ body ) { foreach ( $ patterns as $ pattern ) { if ( preg_match ( String :: insert ( $ pattern , $ this -> _regexMap ) , $ body ) === 1 ) { return true ; } } return false ; }
|
Abstracts the matching out . Will return true if any of the patterns match correctly .
|
54,995
|
public function discover ( $ url , array $ args = [ ] ) { $ url = trim ( $ url ) ; $ html = HtmlExplorer :: fromWeb ( $ url , $ this -> http ) ; $ typePattern = '#^(' . join ( '|' , array_keys ( $ this -> formats ) ) . ')\+oembed$#' ; $ nodes = $ html -> findTags ( 'link' ) ; foreach ( $ nodes as $ node ) { $ rel = strtolower ( trim ( $ node -> getAttribute ( 'rel' ) ) ) ; $ type = strtolower ( trim ( $ node -> getAttribute ( 'type' ) ) ) ; if ( in_array ( $ rel , [ 'alternate' , 'alternative' ] ) && preg_match ( $ typePattern , $ type , $ matches ) ) { $ url = trim ( $ node -> getAttribute ( 'href' ) ) ; $ result = $ this -> queryProvider ( $ url , null , null , $ args ) ; if ( $ result -> success ) { $ parser = $ this -> formats [ $ matches [ 1 ] ] ; return $ parser ( $ result -> data ) ; } } } return false ; }
|
Tries to fetch data for the given content URL using discovery .
|
54,996
|
public function fetch ( $ url , $ endpoint , array $ args = [ ] ) { $ url = trim ( $ url ) ; $ endpoint = trim ( $ endpoint ) ; foreach ( $ this -> formats as $ type => $ parser ) { $ type = explode ( '/' , $ type ) ; $ result = $ this -> queryProvider ( $ endpoint , $ url , $ type [ 1 ] , $ args ) ; if ( $ result -> success ) { return $ parser ( $ result -> data ) ; } } return false ; }
|
Fetches the data for the given content URL .
|
54,997
|
public function getHtml ( $ url , $ endpoint = null , array $ args = [ ] ) { if ( $ endpoint !== null ) { $ data = $ this -> fetch ( $ url , $ endpoint , $ args ) ; } else { $ data = $ this -> discover ( $ url , $ args ) ; } if ( ! $ data ) { return false ; } return $ this -> toHtml ( $ data ) ; }
|
Returns the HTML representation for the given content URL .
|
54,998
|
public function toHtml ( $ data ) { if ( ! is_object ( $ data ) && ! is_array ( $ data ) ) { throw new \ InvalidArgumentException ( 'The $data parameter takes only an object or an array.' ) ; } $ data = ( array ) $ data ; $ type = ( string ) $ data [ 'type' ] ; switch ( $ type ) { case 'photo' : if ( empty ( $ data [ 'width' ] ) || empty ( $ data [ 'height' ] ) ) { return false ; } case 'link' : if ( empty ( $ data [ 'url' ] ) || ! $ this -> isSafeUrl ( $ data [ 'url' ] ) ) { return false ; } break ; case 'video' : case 'rich' : if ( empty ( $ data [ 'html' ] ) || ! $ this -> isSafeHtml ( $ data [ 'html' ] ) ) { return false ; } break ; default : return false ; } return $ this -> render ( $ type , $ data ) ; }
|
Generates an HTML code from the given data .
|
54,999
|
public function queryProvider ( $ endpoint , $ url = null , $ format = 'json' , array $ args = [ ] ) { if ( $ url !== null ) { if ( $ format === null ) { throw new \ InvalidArgumentException ( 'The request format must be defined in manual mode.' ) ; } $ args [ 'url' ] = ( string ) $ url ; $ args [ 'format' ] = ( string ) $ format ; $ concat = '?' ; } else { $ concat = parse_url ( $ endpoint , PHP_URL_QUERY ) != '' ? '&' : '?' ; } $ query = http_build_query ( array_replace ( $ this -> args , $ args ) ) ; return $ this -> http -> get ( $ endpoint . $ concat . $ query ) ; }
|
Queries the oEmbed endpoint of the provider .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.