idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
23,700
function _optimize_index ( $ index ) { static $ cmp = false ; $ poff = $ index * 8 + 32 ; $ this -> _sync_nodes = array ( ) ; $ this -> _load_tree_nodes ( $ poff ) ; $ count = count ( $ this -> _sync_nodes ) ; if ( $ count < 3 ) return ; if ( $ cmp == false ) $ cmp = create_function ( '$a,$b' , 'return strcmp($a[key],$b[key]);' ) ; usort ( $ this -> _sync_nodes , $ cmp ) ; $ this -> _reset_tree_nodes ( $ poff , 0 , $ count - 1 ) ; unset ( $ this -> _sync_nodes ) ; }
optimize a node
23,701
function _load_tree_nodes ( $ poff ) { fseek ( $ this -> fd , $ poff , SEEK_SET ) ; $ buf = fread ( $ this -> fd , 8 ) ; if ( strlen ( $ buf ) != 8 ) return ; $ tmp = unpack ( 'Ioff/Ilen' , $ buf ) ; if ( $ tmp [ 'len' ] == 0 ) return ; fseek ( $ this -> fd , $ tmp [ 'off' ] , SEEK_SET ) ; $ rlen = XDB_MAXKLEN + 17 ; if ( $ rlen > $ tmp [ 'len' ] ) $ rlen = $ tmp [ 'len' ] ; $ buf = fread ( $ this -> fd , $ rlen ) ; $ rec = unpack ( 'Iloff/Illen/Iroff/Irlen/Cklen' , substr ( $ buf , 0 , 17 ) ) ; $ rec [ 'off' ] = $ tmp [ 'off' ] ; $ rec [ 'len' ] = $ tmp [ 'len' ] ; $ rec [ 'key' ] = substr ( $ buf , 17 , $ rec [ 'klen' ] ) ; $ this -> _sync_nodes [ ] = $ rec ; unset ( $ buf ) ; if ( $ rec [ 'llen' ] != 0 ) $ this -> _load_tree_nodes ( $ tmp [ 'off' ] ) ; if ( $ rec [ 'rlen' ] != 0 ) $ this -> _load_tree_nodes ( $ tmp [ 'off' ] + 8 ) ; }
load tree nodes
23,702
function _reset_tree_nodes ( $ poff , $ low , $ high ) { if ( $ low <= $ high ) { $ mid = ( $ low + $ high ) >> 1 ; $ node = $ this -> _sync_nodes [ $ mid ] ; $ buf = pack ( 'II' , $ node [ 'off' ] , $ node [ 'len' ] ) ; $ this -> _reset_tree_nodes ( $ node [ 'off' ] , $ low , $ mid - 1 ) ; $ this -> _reset_tree_nodes ( $ node [ 'off' ] + 8 , $ mid + 1 , $ high ) ; } else { $ buf = pack ( 'II' , 0 , 0 ) ; } fseek ( $ this -> fd , $ poff , SEEK_SET ) ; fwrite ( $ this -> fd , $ buf , 8 ) ; }
sync the tree
23,703
function _check_header ( $ fd ) { fseek ( $ fd , 0 , SEEK_SET ) ; $ buf = fread ( $ fd , 32 ) ; if ( strlen ( $ buf ) !== 32 ) return false ; $ hdr = unpack ( 'a3tag/Cver/Ibase/Iprime/Ifsize/fcheck/a12reversed' , $ buf ) ; if ( $ hdr [ 'tag' ] != XDB_TAGNAME ) return false ; $ fstat = fstat ( $ fd ) ; if ( $ fstat [ 'size' ] != $ hdr [ 'fsize' ] ) return false ; $ this -> hash_base = $ hdr [ 'base' ] ; $ this -> hash_prime = $ hdr [ 'prime' ] ; $ this -> version = $ hdr [ 'ver' ] ; $ this -> fsize = $ hdr [ 'fsize' ] ; return true ; }
Check XDB Header
23,704
function _write_header ( $ fd ) { $ buf = pack ( 'a3CiiIfa12' , XDB_TAGNAME , $ this -> version , $ this -> hash_base , $ this -> hash_prime , 0 , XDB_FLOAT_CHECK , '' ) ; fseek ( $ fd , 0 , SEEK_SET ) ; fwrite ( $ fd , $ buf , 32 ) ; }
Write XDB Header
23,705
function _get_record ( $ key ) { $ this -> _io_times = 1 ; $ index = ( $ this -> hash_prime > 1 ? $ this -> _get_index ( $ key ) : 0 ) ; $ poff = $ index * 8 + 32 ; fseek ( $ this -> fd , $ poff , SEEK_SET ) ; $ buf = fread ( $ this -> fd , 8 ) ; if ( strlen ( $ buf ) == 8 ) $ tmp = unpack ( 'Ioff/Ilen' , $ buf ) ; else $ tmp = array ( 'off' => 0 , 'len' => 0 ) ; return $ this -> _tree_get_record ( $ tmp [ 'off' ] , $ tmp [ 'len' ] , $ poff , $ key ) ; }
get the record by first key
23,706
function _tree_get_record ( $ off , $ len , $ poff = 0 , $ key = '' ) { if ( $ len == 0 ) return ( array ( 'poff' => $ poff ) ) ; $ this -> _io_times ++ ; fseek ( $ this -> fd , $ off , SEEK_SET ) ; $ rlen = XDB_MAXKLEN + 17 ; if ( $ rlen > $ len ) $ rlen = $ len ; $ buf = fread ( $ this -> fd , $ rlen ) ; $ rec = unpack ( 'Iloff/Illen/Iroff/Irlen/Cklen' , substr ( $ buf , 0 , 17 ) ) ; $ fkey = substr ( $ buf , 17 , $ rec [ 'klen' ] ) ; $ cmp = ( $ key ? strcmp ( $ key , $ fkey ) : 0 ) ; if ( $ cmp > 0 ) { unset ( $ buf ) ; return $ this -> _tree_get_record ( $ rec [ 'roff' ] , $ rec [ 'rlen' ] , $ off + 8 , $ key ) ; } else if ( $ cmp < 0 ) { unset ( $ buf ) ; return $ this -> _tree_get_record ( $ rec [ 'loff' ] , $ rec [ 'llen' ] , $ off , $ key ) ; } else { $ rec [ 'poff' ] = $ poff ; $ rec [ 'off' ] = $ off ; $ rec [ 'len' ] = $ len ; $ rec [ 'voff' ] = $ off + 17 + $ rec [ 'klen' ] ; $ rec [ 'vlen' ] = $ len - 17 - $ rec [ 'klen' ] ; $ rec [ 'key' ] = $ fkey ; fseek ( $ this -> fd , $ rec [ 'voff' ] , SEEK_SET ) ; $ rec [ 'value' ] = fread ( $ this -> fd , $ rec [ 'vlen' ] ) ; return $ rec ; } }
get the record by tree
23,707
public function read ( ReadOptionsInterface $ options , SectionConfig $ sectionConfig = null ) : \ ArrayIterator { $ sectionData = new \ ArrayIterator ( ) ; $ this -> dispatcher -> dispatch ( SectionBeforeRead :: NAME , new SectionBeforeRead ( $ sectionData , $ options , $ sectionConfig ) ) ; if ( $ sectionConfig === null && count ( $ options -> getSection ( ) ) > 0 ) { $ sectionConfig = $ this -> sectionManager -> readByHandle ( $ options -> getSection ( ) [ 0 ] -> toHandle ( ) ) -> getConfig ( ) ; } if ( count ( $ options -> getSection ( ) ) > 0 ) { $ optionsArray = $ options -> toArray ( ) ; $ optionsArray [ ReadOptions :: SECTION ] = ( string ) $ sectionConfig -> getFullyQualifiedClassName ( ) ; $ options = ReadOptions :: fromArray ( $ optionsArray ) ; } foreach ( $ this -> readers as $ reader ) { foreach ( $ reader -> read ( $ options , $ sectionConfig ) as $ entry ) { $ sectionData -> append ( $ entry ) ; } } $ this -> dispatcher -> dispatch ( SectionDataRead :: NAME , new SectionDataRead ( $ sectionData , $ options , $ sectionConfig ) ) ; return $ sectionData ; }
Read from one or more data - sources
23,708
private function nextTimeout ( ) : ? int { $ time = \ microtime ( true ) ; while ( ! $ this -> scheduler -> isEmpty ( ) ) { list ( $ watcher , $ scheduled ) = $ this -> scheduler -> top ( ) ; if ( $ watcher -> enabled && $ watcher -> scheduled === $ scheduled ) { return ( int ) \ max ( 0 , ( $ watcher -> due - $ time ) * 1000000 ) ; } } return null ; }
Get the number of microseconds until the next timer watcher is due .
23,709
private function notifyPolls ( array $ selected , array & $ watchers ) : void { foreach ( $ selected as $ k => $ stream ) { $ k = $ k ? : ( int ) $ stream ; if ( isset ( $ watchers [ $ k ] ) ) { foreach ( $ watchers [ $ k ] as $ watcher ) { if ( isset ( $ watchers [ $ k ] [ $ watcher -> id ] ) ) { ( $ watcher -> callback ) ( $ watcher -> id , $ stream ) ; } } } } }
Trigger all stream watchers for the selected resources .
23,710
public function addToContext ( string $ key , $ value , string $ behavior ) : View { switch ( $ behavior ) { case View :: REPLACE : $ this -> _context_ [ $ key ] = $ value ; return $ this ; case View :: MERGE : if ( array_key_exists ( $ key , $ this -> _context_ ) ) { $ this -> _context_ = array_merge_recursive ( $ this -> _context_ , [ $ key => $ value ] ) ; return $ this ; } $ this -> _context_ [ $ key ] = $ value ; return $ this ; case View :: ADD_ONLY : if ( array_key_exists ( $ key , $ this -> _context_ ) ) { return $ this ; } $ this -> _context_ [ $ key ] = $ value ; return $ this ; case View :: REPLACE_ONLY : if ( ! array_key_exists ( $ key , $ this -> _context_ ) ) { return $ this ; } $ this -> _context_ [ $ key ] = $ value ; return $ this ; case View :: MERGE_ONLY : if ( ! array_key_exists ( $ key , $ this -> _context_ ) ) { return $ this ; } $ this -> _context_ = array_merge_recursive ( $ this -> _context_ , [ $ key => $ value ] ) ; return $ this ; default : throw new InvalidContextAddingBehavior ( sprintf ( _ ( 'Invalid behavior "%s" for adding to the context of view "%s".' ) , $ key , $ this -> _uri_ ) ) ; } }
Add information to the context .
23,711
protected function assimilateContext ( array $ context = [ ] ) { $ this -> _context_ = $ context ; foreach ( $ context as $ key => $ value ) { $ this -> $ key = $ value ; } }
Assimilate the context to make it available as properties .
23,712
public static function doDelete ( $ values , ConnectionInterface $ con = null ) { if ( null === $ con ) { $ con = Propel :: getServiceContainer ( ) -> getWriteConnection ( FeatureTypeI18nTableMap :: DATABASE_NAME ) ; } if ( $ values instanceof Criteria ) { $ criteria = $ values ; } elseif ( $ values instanceof \ FeatureType \ Model \ FeatureTypeI18n ) { $ criteria = $ values -> buildPkeyCriteria ( ) ; } else { $ criteria = new Criteria ( FeatureTypeI18nTableMap :: DATABASE_NAME ) ; if ( count ( $ values ) == count ( $ values , COUNT_RECURSIVE ) ) { $ values = array ( $ values ) ; } foreach ( $ values as $ value ) { $ criterion = $ criteria -> getNewCriterion ( FeatureTypeI18nTableMap :: ID , $ value [ 0 ] ) ; $ criterion -> addAnd ( $ criteria -> getNewCriterion ( FeatureTypeI18nTableMap :: LOCALE , $ value [ 1 ] ) ) ; $ criteria -> addOr ( $ criterion ) ; } } $ query = FeatureTypeI18nQuery :: create ( ) -> mergeWith ( $ criteria ) ; if ( $ values instanceof Criteria ) { FeatureTypeI18nTableMap :: clearInstancePool ( ) ; } elseif ( ! is_object ( $ values ) ) { foreach ( ( array ) $ values as $ singleval ) { FeatureTypeI18nTableMap :: removeInstanceFromPool ( $ singleval ) ; } } return $ query -> delete ( $ con ) ; }
Performs a DELETE on the database given a FeatureTypeI18n or Criteria object OR a primary key value .
23,713
public function load ( $ object ) { if ( get_class ( $ object ) !== $ this -> objectClass ) { throw new \ LogicException ( sprintf ( 'Invalid object type. Expected "%s" but got "%s".' , $ this -> objectClass , get_class ( $ object ) ) ) ; } $ hydrator = $ this -> objectManager -> getHydratorFor ( $ this -> objectClass ) ; $ hydrator -> load ( $ object ) ; }
Load an object . Some properties can be loaded only when needed for performance reason .
23,714
public function loadProperty ( $ object , $ propertyName ) { if ( get_class ( $ object ) !== $ this -> objectClass ) { throw new \ LogicException ( sprintf ( 'Invalid object type. Expected "%s" but got "%s".' , $ this -> objectClass , get_class ( $ object ) ) ) ; } if ( $ this -> objectManager -> isPropertyLoaded ( $ object , $ propertyName ) ) { return ; } $ hydrator = $ this -> objectManager -> getHydratorFor ( $ this -> objectClass ) ; $ hydrator -> loadProperty ( $ object , $ propertyName ) ; }
Load an object property . This property can be loaded only if needed for performance reason .
23,715
public function defer ( $ enable ) { $ this -> deferred = $ enable ; if ( ! $ this -> deferred && isset ( $ this -> request ) ) { return $ this -> doSend ( ) ; } }
Setting up deferred request . If setting false and there are defered request it will send together .
23,716
private function doSend ( ) { try { if ( ! empty ( $ this -> sentContentIds ) && count ( $ this -> sentContentIds ) > $ this -> batchLimit ) { throw new InvalidCallException ( sprintf ( "Request limit reached! Max %d requests per batch is accepted!" , $ this -> batchLimit ) ) ; } $ response = $ this -> request -> send ( ) ; $ this -> request = null ; if ( $ response instanceof ApiResponse ) { $ response = [ $ response ] ; } $ responses = [ ] ; $ index = 0 ; foreach ( $ response as $ _response ) { $ responses [ $ _response -> id ?? $ index ] = $ this -> handleResponse ( $ _response ) ; $ index ++ ; } foreach ( $ this -> sentContentIds as $ sentContentId ) { if ( ! array_key_exists ( $ sentContentId , $ responses ) ) { $ responses [ $ sentContentId ] = new ApiResponse ( [ 'success' => false , 'error' => new ResponseError ( [ 'type' => BadGatewayHttpException :: class , 'code' => ResponseError :: ERRORCODE_HTTP_RESPONSE_ERROR , 'message' => [ 'httpError' => 'Sent content not found in response!' ] , ] ) , ] ) ; } } return $ responses ; } finally { $ this -> sentContentIds = [ ] ; } }
Sending deffered request .
23,717
public static function create ( $ modelAlias = null , $ criteria = null ) { if ( $ criteria instanceof \ FeatureType \ Model \ FeatureFeatureTypeQuery ) { return $ criteria ; } $ query = new \ FeatureType \ Model \ FeatureFeatureTypeQuery ( ) ; if ( null !== $ modelAlias ) { $ query -> setModelAlias ( $ modelAlias ) ; } if ( $ criteria instanceof Criteria ) { $ query -> mergeWith ( $ criteria ) ; } return $ query ; }
Returns a new ChildFeatureFeatureTypeQuery object .
23,718
public function filterByFeatureId ( $ featureId = null , $ comparison = null ) { if ( is_array ( $ featureId ) ) { $ useMinMax = false ; if ( isset ( $ featureId [ 'min' ] ) ) { $ this -> addUsingAlias ( FeatureFeatureTypeTableMap :: FEATURE_ID , $ featureId [ 'min' ] , Criteria :: GREATER_EQUAL ) ; $ useMinMax = true ; } if ( isset ( $ featureId [ 'max' ] ) ) { $ this -> addUsingAlias ( FeatureFeatureTypeTableMap :: FEATURE_ID , $ featureId [ 'max' ] , Criteria :: LESS_EQUAL ) ; $ useMinMax = true ; } if ( $ useMinMax ) { return $ this ; } if ( null === $ comparison ) { $ comparison = Criteria :: IN ; } } return $ this -> addUsingAlias ( FeatureFeatureTypeTableMap :: FEATURE_ID , $ featureId , $ comparison ) ; }
Filter the query on the feature_id column
23,719
public function filterByFeatureTypeId ( $ featureTypeId = null , $ comparison = null ) { if ( is_array ( $ featureTypeId ) ) { $ useMinMax = false ; if ( isset ( $ featureTypeId [ 'min' ] ) ) { $ this -> addUsingAlias ( FeatureFeatureTypeTableMap :: FEATURE_TYPE_ID , $ featureTypeId [ 'min' ] , Criteria :: GREATER_EQUAL ) ; $ useMinMax = true ; } if ( isset ( $ featureTypeId [ 'max' ] ) ) { $ this -> addUsingAlias ( FeatureFeatureTypeTableMap :: FEATURE_TYPE_ID , $ featureTypeId [ 'max' ] , Criteria :: LESS_EQUAL ) ; $ useMinMax = true ; } if ( $ useMinMax ) { return $ this ; } if ( null === $ comparison ) { $ comparison = Criteria :: IN ; } } return $ this -> addUsingAlias ( FeatureFeatureTypeTableMap :: FEATURE_TYPE_ID , $ featureTypeId , $ comparison ) ; }
Filter the query on the feature_type_id column
23,720
public function filterByFeature ( $ feature , $ comparison = null ) { if ( $ feature instanceof \ Thelia \ Model \ Feature ) { return $ this -> addUsingAlias ( FeatureFeatureTypeTableMap :: FEATURE_ID , $ feature -> getId ( ) , $ comparison ) ; } elseif ( $ feature instanceof ObjectCollection ) { if ( null === $ comparison ) { $ comparison = Criteria :: IN ; } return $ this -> addUsingAlias ( FeatureFeatureTypeTableMap :: FEATURE_ID , $ feature -> toKeyValue ( 'PrimaryKey' , 'Id' ) , $ comparison ) ; } else { throw new PropelException ( 'filterByFeature() only accepts arguments of type \Thelia\Model\Feature or Collection' ) ; } }
Filter the query by a related \ Thelia \ Model \ Feature object
23,721
public function useFeatureQuery ( $ relationAlias = null , $ joinType = Criteria :: INNER_JOIN ) { return $ this -> joinFeature ( $ relationAlias , $ joinType ) -> useQuery ( $ relationAlias ? $ relationAlias : 'Feature' , '\Thelia\Model\FeatureQuery' ) ; }
Use the Feature relation Feature object
23,722
public function filterByFeatureTypeAvMeta ( $ featureTypeAvMeta , $ comparison = null ) { if ( $ featureTypeAvMeta instanceof \ FeatureType \ Model \ FeatureTypeAvMeta ) { return $ this -> addUsingAlias ( FeatureFeatureTypeTableMap :: ID , $ featureTypeAvMeta -> getFeatureFeatureTypeId ( ) , $ comparison ) ; } elseif ( $ featureTypeAvMeta instanceof ObjectCollection ) { return $ this -> useFeatureTypeAvMetaQuery ( ) -> filterByPrimaryKeys ( $ featureTypeAvMeta -> getPrimaryKeys ( ) ) -> endUse ( ) ; } else { throw new PropelException ( 'filterByFeatureTypeAvMeta() only accepts arguments of type \FeatureType\Model\FeatureTypeAvMeta or Collection' ) ; } }
Filter the query by a related \ FeatureType \ Model \ FeatureTypeAvMeta object
23,723
public function useFeatureTypeAvMetaQuery ( $ relationAlias = null , $ joinType = Criteria :: INNER_JOIN ) { return $ this -> joinFeatureTypeAvMeta ( $ relationAlias , $ joinType ) -> useQuery ( $ relationAlias ? $ relationAlias : 'FeatureTypeAvMeta' , '\FeatureType\Model\FeatureTypeAvMetaQuery' ) ; }
Use the FeatureTypeAvMeta relation FeatureTypeAvMeta object
23,724
public function map ( $ method , string $ route , string $ action , string $ controller ) { $ proxy = $ this -> proxy_factory ; if ( ! \ is_array ( $ method ) ) { $ method = [ ( string ) $ method ] ; } \ array_walk ( $ method , function ( $ v ) { if ( ! \ in_array ( $ v , [ 'GET' , 'POST' , 'PUT' , 'DELETE' ] ) ) { throw new \ InvalidArgumentException ( \ sprintf ( 'Unknown http method: "%s"' , $ v ) ) ; } } ) ; foreach ( $ method as $ m ) { $ this -> klein -> respond ( $ m , $ route , function ( $ request , $ response ) use ( & $ proxy , $ action , $ controller ) { return $ proxy ( $ controller ) -> setRequest ( $ request ) -> setResponse ( $ response ) -> $ action ( ) ; } ) ; } return $ this ; }
Map HTTP method and route to some action and controller .
23,725
public function dispatch ( Request $ request , ControllerFactory $ actual_factory ) { $ this -> proxy_factory -> replace ( $ actual_factory ) -> close ( ) ; $ this -> klein -> dispatch ( $ request ) ; }
Dispatch request .
23,726
public function add ( SecurityContextConfiguration $ configuration ) { $ this -> contexts [ $ configuration -> getName ( ) ] = $ configuration ; $ this -> updateMappings ( $ configuration , $ this -> container -> make ( EntityManagerInterface :: class ) ) ; }
Add a security context .
23,727
public function bindContext ( $ context , Request $ request ) { $ security = $ this -> getSecurity ( $ context ) ; $ this -> container -> instance ( SecurityApi :: class , $ security ) ; $ this -> container -> bind ( UrlGeneratorContract :: class , function ( ) use ( $ security ) { return $ security -> url ( ) ; } ) ; $ this -> container -> bind ( UrlGenerator :: class , function ( Container $ container ) use ( $ security ) { $ url = $ container -> make ( PermissionAwareUrlGeneratorExtension :: class ) ; $ url -> setUrlGenerator ( $ security -> url ( ) ) ; return $ url ; } ) ; $ this -> container -> alias ( UrlGenerator :: class , 'url' ) ; $ request -> setUserResolver ( function ( ) use ( $ security ) { return $ security -> getUser ( ) ; } ) ; }
Bind the given security context to the Request and Container .
23,728
public function getSecurity ( $ context ) { if ( array_key_exists ( $ context , $ this -> instances ) ) { return $ this -> instances [ $ context ] ; } $ configuration = $ this -> getConfigurationFor ( $ context ) ; $ this -> addPermissionsFactoryListener ( $ context ) ; return $ this -> instances [ $ context ] = $ this -> getSecurityFactory ( ) -> create ( $ context , $ configuration ) ; }
Get the Security instance for the given context .
23,729
public function runHooks ( $ name , AbstractContext $ context , $ reverse = false ) { $ parent = $ this -> getParent ( ) ; $ hooks = $ this -> hooks [ $ name ] ; if ( $ reverse ) { foreach ( array_reverse ( $ hooks ) as $ hook ) { $ hook -> run ( $ context ) ; } if ( $ parent ) { $ parent -> runHooks ( $ name , $ context , $ reverse ) ; } } else { if ( $ parent ) { $ parent -> runHooks ( $ name , $ context , $ reverse ) ; } foreach ( $ hooks as $ hook ) { $ hook -> run ( $ context ) ; } } }
Traverse ancestry running hooks
23,730
public function total ( ) { $ total = array_reduce ( $ this -> examples , function ( $ x , $ e ) { $ x += $ e instanceof Example ? 1 : $ e -> total ( ) ; return $ x ; } , 0 ) ; return $ total ; }
Get total number of tests
23,731
public function setErrorHandler ( ) { set_error_handler ( function ( $ errno , $ errstr , $ errfile , $ errline ) { throw new \ ErrorException ( $ errstr , 0 , $ errno , $ errfile , $ errline ) ; } ) ; }
Set error handler
23,732
function _rule_get ( $ str ) { if ( ! isset ( $ this -> _rd [ $ str ] ) ) return false ; return $ this -> _rd [ $ str ] ; }
get the ruleset
23,733
function _rule_checkbit ( $ str , $ bit ) { if ( ! isset ( $ this -> _rd [ $ str ] ) ) return false ; $ bit2 = $ this -> _rd [ $ str ] [ 'bit' ] ; return ( $ bit & $ bit2 ? true : false ) ; }
check the bit with str
23,734
function _rule_check ( $ rule , $ str ) { if ( ( $ rule [ 'flag' ] & PSCWS4_ZRULE_INCLUDE ) && ! $ this -> _rule_checkbit ( $ str , $ rule [ 'bit' ] ) ) return false ; if ( ( $ rule [ 'flag' ] & PSCWS4_ZRULE_EXCLUDE ) && $ this -> _rule_checkbit ( $ str , $ rule [ 'bit' ] ) ) return false ; return true ; }
check the rule include | exclude
23,735
function _dict_query ( $ word ) { if ( ! $ this -> _xd ) return false ; $ value = $ this -> _xd -> Get ( $ word ) ; if ( ! $ value ) return false ; $ tmp = unpack ( 'ftf/fidf/Cflag/a3attr' , $ value ) ; return $ tmp ; }
query the dict
23,736
function _get_zs ( $ i , $ j = - 1 ) { if ( $ j == - 1 ) $ j = $ i ; return substr ( $ this -> _txt , $ this -> _zmap [ $ i ] [ 'start' ] , $ this -> _zmap [ $ j ] [ 'end' ] - $ this -> _zmap [ $ i ] [ 'start' ] ) ; }
get one z by ZMAP
23,737
public function setSalt ( $ value ) { if ( ( string ) $ value !== $ this -> getSalt ( ) ) { $ this -> values [ 'salt' ] = ( string ) $ value ; $ this -> setModified ( ) ; } return $ this ; }
Sets the password salt
23,738
public function parse ( Context $ context , ? Request $ request = null ) : \ Generator { $ header = \ unpack ( 'nid/nflags/nqc/nac/nauth/nadd' , yield $ this -> stream -> readBuffer ( $ context , 12 ) ) ; $ this -> offset += 12 ; $ response = new Response ( $ header [ 'id' ] ) ; $ response -> setFlags ( $ header [ 'flags' ] ) ; if ( $ request && $ response -> getId ( ) !== $ request -> getId ( ) ) { throw new \ RuntimeException ( \ sprintf ( 'Expected DNS message ID is %u, server returned %u' , $ request -> getId ( ) , $ response -> getId ( ) ) ) ; } $ response -> setAuthorityCount ( $ header [ 'auth' ] ) ; $ response -> setAdditionalCount ( $ header [ 'add' ] ) ; for ( $ i = 0 ; $ i < $ header [ 'qc' ] ; $ i ++ ) { yield from $ this -> parseQuestion ( $ context , $ response ) ; } if ( $ request && $ response -> getQuestions ( ) !== $ request -> getQuestions ( ) ) { throw new \ RuntimeException ( 'DNS server did not return the question(s) in the response message' ) ; } for ( $ i = 0 ; $ i < $ header [ 'ac' ] ; $ i ++ ) { yield from $ this -> parseAnswer ( $ context , $ response ) ; } return $ response ; }
Read and parse a DNS response message .
23,739
protected function parseQuestion ( Context $ context , Response $ response ) : \ Generator { $ host = yield from $ this -> readLabel ( $ context ) ; $ question = \ unpack ( 'ntype/nclass' , yield $ this -> stream -> readBuffer ( $ context , 4 ) ) ; $ this -> offset += 4 ; $ response -> addQuestion ( $ host , $ question [ 'type' ] , $ question [ 'class' ] ) ; }
Parse a DNS question record and add it the given response .
23,740
protected function parseAnswer ( Context $ context , Response $ response ) : \ Generator { $ host = yield from $ this -> readLabel ( $ context ) ; $ answer = \ unpack ( 'ntype/nclass/Nttl/nlen' , yield $ this -> stream -> readBuffer ( $ context , 10 ) ) ; $ this -> offset += 10 ; $ ttl = $ answer [ 'ttl' ] ; $ len = $ answer [ 'len' ] ; if ( $ response -> isTruncated ( ) ) { $ data = yield $ this -> stream -> readBuffer ( $ context , $ len ) ; $ this -> offset += $ len ; return ; } switch ( $ answer [ 'type' ] ) { case Message :: TYPE_A : case Message :: TYPE_AAAA : $ data = \ inet_ntop ( yield $ this -> stream -> readBuffer ( $ context , $ len ) ) ; $ this -> offset += $ len ; break ; case Message :: TYPE_CNAME : $ data = yield from $ this -> readLabel ( $ context ) ; break ; default : $ data = yield $ this -> stream -> readBuffer ( $ context , $ len ) ; $ this -> offset += $ len ; } if ( $ ttl & 0x80000000 ) { $ ttl = ( $ ttl - 0xFFFFFFFF ) ; } $ response -> addAnswer ( $ host , $ answer [ 'type' ] , $ answer [ 'class' ] , $ data , $ ttl ) ; }
Parse a DNS answer record and add it to the given response .
23,741
public function nextOutdent ( ) { $ oldLevel = $ this -> getIndentLevel ( ) ; $ expected = $ this -> getLevel ( ) ; if ( $ expected < $ oldLevel ) { $ newLevel = $ this -> outdent ( ) ; if ( $ newLevel < $ expected ) { $ this -> throwException ( 'Inconsistent indentation. ' . 'Expecting either ' . $ newLevel . ' or ' . $ oldLevel . ' spaces/tabs.' ) ; } return $ newLevel ; } return false ; }
Return new outdent level if current above expected or false if expected level reached .
23,742
public function indent ( $ level = null ) { $ level = $ level ? : $ this -> getLevel ( ) ; array_push ( $ this -> indentStack , $ level ) ; return $ level ; }
Indent and return the new level .
23,743
public function scan ( $ scanners ) { $ scanners = $ this -> filterScanners ( $ scanners ) ; foreach ( $ scanners as $ key => $ scanner ) { $ success = false ; foreach ( $ scanner -> scan ( $ this ) as $ token ) { if ( ! ( $ token instanceof TokenInterface ) ) { $ this -> throwException ( 'Scanner ' . get_class ( $ scanner ) . ' generated a result that is not a ' . TokenInterface :: class ) ; } yield $ token ; $ success = true ; } if ( $ success ) { return ; } } }
Runs all passed scanners once on the input string .
23,744
public function loopScan ( $ scanners , $ required = false ) { while ( $ this -> reader -> hasLength ( ) ) { $ success = false ; foreach ( $ this -> scan ( $ scanners ) as $ token ) { $ success = true ; yield $ token ; } if ( ! $ success ) { break ; } } if ( $ this -> reader -> hasLength ( ) && $ required ) { $ this -> throwException ( 'Unexpected ' . $ this -> reader -> peek ( 20 ) ) ; } }
Continuously scans with all scanners passed as the first argument .
23,745
public function createToken ( $ className ) { if ( ! is_subclass_of ( $ className , TokenInterface :: class ) ) { $ this -> throwException ( "$className is not a valid token sub-class" ) ; } return new $ className ( $ this -> createCurrentSourceLocation ( ) , $ this -> level , str_repeat ( $ this -> getIndentStyle ( ) , $ this -> getIndentWidth ( ) ) ) ; }
Creates a new instance of a token .
23,746
public function scanToken ( $ className , $ pattern , $ modifiers = null ) { if ( ! $ this -> reader -> match ( $ pattern , $ modifiers ) ) { return ; } $ data = $ this -> reader -> getMatchData ( ) ; $ token = $ this -> createToken ( $ className ) ; $ this -> reader -> consume ( ) ; foreach ( $ data as $ key => $ value ) { $ method = 'set' . ucfirst ( $ key ) ; if ( method_exists ( $ token , $ method ) ) { call_user_func ( [ $ token , $ method ] , $ value ) ; } } yield $ this -> endToken ( $ token ) ; }
Quickly scans for a token by a single regular expression pattern .
23,747
private function filterScanners ( $ scanners ) { $ scannerInstances = [ ] ; $ scanners = is_array ( $ scanners ) ? $ scanners : [ $ scanners ] ; foreach ( $ scanners as $ key => $ scanner ) { if ( ! is_a ( $ scanner , ScannerInterface :: class , true ) ) { throw new \ InvalidArgumentException ( "The passed scanner with key `$key` doesn't seem to be either a valid " . ScannerInterface :: class . ' instance or extended class' ) ; } $ scannerInstances [ ] = $ scanner instanceof ScannerInterface ? $ scanner : new $ scanner ( ) ; } return $ scannerInstances ; }
Filters and validates the passed scanners .
23,748
public function getRedirectResponse ( string $ routeName , array $ routeParameters = [ ] ) : RedirectResponse { $ url = $ this -> router -> generate ( $ routeName , $ routeParameters ) ; return new RedirectResponse ( $ url ) ; }
Returns the redirect response that is used to redirect to url generated by given route and parameters
23,749
protected function registerCategoryProvider ( ) { $ this -> app [ 'categorize.category' ] = $ this -> app -> share ( function ( $ app ) { $ model = $ app [ 'config' ] -> get ( 'categorize::categories.model' ) ; return new CategoryProvider ( $ model ) ; } ) ; }
Register category provider .
23,750
protected function registerCategoryHierarchyProvider ( ) { $ this -> app [ 'categorize.categoryHierarchy' ] = $ this -> app -> share ( function ( $ app ) { $ model = $ app [ 'config' ] -> get ( 'categorize::categoryHierarchy.model' ) ; return new CategoryHierarchyProvider ( $ model ) ; } ) ; }
Register category hierarchy provider .
23,751
protected function registerCategoryRelateProvider ( ) { $ this -> app [ 'categorize.categoryRelate' ] = $ this -> app -> share ( function ( $ app ) { $ model = $ app [ 'config' ] -> get ( 'categorize::categoryRelates.model' ) ; return new CategoryRelateProvider ( $ model ) ; } ) ; }
Register category relate provider .
23,752
protected function configureRobotsFile ( RobotsFileInterface $ robots ) { $ robots -> setCrawlDelay ( $ this -> robots [ 'crawl_delay' ] ) ; foreach ( $ this -> robots [ 'allow' ] as $ path => $ userAgent ) { if ( strpos ( $ path , '/' ) === false ) { $ path = $ this -> router -> generate ( $ path ) ; } $ robots -> addAllowEntry ( $ path , $ userAgent ) ; } foreach ( $ this -> robots [ 'disallow' ] as $ path => $ userAgent ) { if ( strpos ( $ path , '/' ) === false ) { $ path = $ this -> router -> generate ( $ path ) ; } $ robots -> addDisallowEntry ( $ path , $ userAgent ) ; } foreach ( $ this -> robots [ 'clean_param' ] as $ path => $ value ) { $ robots -> addCleanParamEntry ( $ value [ 'parameters' ] , $ path ) ; } }
Modify robots file by configuration
23,753
protected function bulkSave ( array $ throttles ) { $ entityManager = $ this -> getEntityManager ( ) ; foreach ( $ throttles as $ throttle ) { $ entityManager -> persist ( $ throttle ) ; } $ entityManager -> flush ( ) ; }
Persist an array of Throttles and flush them together .
23,754
protected function configure ( $ options = array ( ) , $ attributes = array ( ) ) { $ this -> addOption ( 'culture' , sfContext :: getInstance ( ) -> getUser ( ) -> getCulture ( ) ) ; $ this -> addOption ( 'width' , sfConfig :: get ( 'sf_sfSelect2Widgets_width' ) ) ; $ this -> addRequiredOption ( 'model' ) ; $ this -> addOption ( 'add_empty' , false ) ; $ this -> addOption ( 'method' , '__toString' ) ; $ this -> addOption ( 'key_method' , 'getPrimaryKey' ) ; $ this -> addOption ( 'order_by' , null ) ; $ this -> addOption ( 'query_methods' , array ( ) ) ; $ this -> addOption ( 'criteria' , null ) ; $ this -> addOption ( 'connection' , null ) ; $ this -> addOption ( 'multiple' , false ) ; $ this -> addOption ( 'peer_method' , 'doSelect' ) ; parent :: configure ( $ options , $ attributes ) ; $ this -> setOption ( 'type' , 'hidden' ) ; }
Configures the current widget .
23,755
public function findUserByPersistenceCode ( $ code ) { $ persistence = $ this -> findByPersistenceCode ( $ code ) ; if ( $ persistence ) { return $ persistence -> getUser ( ) ; } return false ; }
Finds a user by persistence code .
23,756
public function persist ( PersistableInterface $ persistable , $ remember = false ) { try { if ( $ this -> single ) { $ this -> flush ( $ persistable ) ; } $ code = $ persistable -> generatePersistenceCode ( ) ; $ this -> session -> put ( $ code ) ; if ( $ remember === true ) { $ this -> cookie -> put ( $ code ) ; } $ persistence = $ this -> create ( $ persistable , $ code ) ; $ entityManager = $ this -> getEntityManager ( ) ; $ entityManager -> persist ( $ persistence ) ; $ entityManager -> flush ( ) ; return true ; } catch ( \ Exception $ e ) { return false ; } }
Adds a new user persistence to the current session and attaches the user .
23,757
public function remove ( $ code ) { $ entityManager = $ this -> getEntityManager ( ) ; $ queryBuilder = $ entityManager -> createQueryBuilder ( ) ; $ queryBuilder -> delete ( $ this -> entityName ( ) , 'p' ) -> where ( 'p.code = :code' ) -> setParameter ( 'code' , $ code ) ; return $ queryBuilder -> getQuery ( ) -> execute ( ) ; }
Removes the given persistence code .
23,758
public function flush ( PersistableInterface $ persistable , $ forget = true ) { if ( $ forget ) { $ this -> forget ( ) ; } $ code = $ this -> check ( ) ; $ entityManager = $ this -> getEntityManager ( ) ; $ queryBuilder = $ entityManager -> createQueryBuilder ( ) ; $ queryBuilder -> delete ( $ this -> entityName ( ) , 'p' ) -> where ( 'p.user = :persistable' ) -> andWhere ( 'p.code != :code' ) ; $ queryBuilder -> setParameters ( [ 'persistable' => $ persistable , 'code' => $ code ] ) ; $ queryBuilder -> getQuery ( ) -> execute ( ) ; }
Flushes persistences for the given user .
23,759
public function Run ( ) { parent :: PreRun ( ) ; list ( $ jobMethod , $ params ) = $ this -> completeJobAndParams ( ) ; $ this -> $ jobMethod ( $ params ) ; return $ this ; }
Run PHAR compilation process print output to CLI or browser
23,760
public function loadPicture ( $ image , $ worker = NULL ) { if ( $ this -> pictureLoader ) { return $ this -> pictureLoader -> loadPicture ( $ image , $ this , $ worker ) ; } return new Picture ( $ image , $ this , $ worker , $ this -> fallbackImage ) ; }
Get picture instance for transformation performs by this picture generator .
23,761
public function save ( Picture $ picture ) { $ pictureFile = $ this -> getPath ( $ picture ) ; if ( ! $ this -> isFileActual ( $ pictureFile , $ picture ) ) { $ picture -> save ( $ pictureFile ) ; } }
Save picture variant to generator storage .
23,762
protected function isFileActual ( $ file , Picture $ picture ) { if ( file_exists ( $ file ) ) { if ( @ filemtime ( $ file ) === @ filemtime ( $ picture -> getImage ( ) ) ) { return TRUE ; } else { return NULL ; } } return FALSE ; }
Check if picture variant exists and is actual
23,763
public function setFallbackImage ( $ fallbackImage ) { $ fallbackImagePath = realpath ( $ fallbackImage ) ; if ( file_exists ( $ fallbackImagePath ) && is_readable ( $ fallbackImagePath ) ) { $ this -> fallbackImage = $ fallbackImagePath ; return ; } throw new Exception ( "Default image missing or not readable, path: $fallbackImage" ) ; }
Set fallback image witch is used when requred image is not found .
23,764
public function getTemplateQuery ( $ template ) { if ( isset ( $ this -> template [ $ template ] ) ) { return $ this -> template [ $ template ] ; } return FALSE ; }
Get defined template image query
23,765
protected function unifyPath ( $ path , $ slash = DIRECTORY_SEPARATOR ) { return preg_replace ( '/\\' . $ slash . '+/' , $ slash , str_replace ( array ( '/' , "\\" ) , $ slash , $ path ) ) ; }
Unify filesystem path
23,766
protected function settle ( PromiseInterface $ promise ) { $ handlers = $ this -> handlers ; $ this -> result = $ promise ; $ this -> handlers = [ ] ; foreach ( $ handlers as $ handler ) { $ handler ( $ promise ) ; } return $ promise ; }
Settle Promise with another Promise .
23,767
protected function getResult ( ) { while ( $ this -> result instanceof Promise && null !== $ this -> result -> result ) { $ this -> result = $ this -> result -> result ; } return $ this -> result ; }
Get Promise result . Returns fulfilled rejected or cancelled Promise for settled Promises or null for pending .
23,768
protected function mutate ( callable $ resolver = null ) { if ( $ resolver === null ) { return ; } try { $ resolver ( function ( $ value = null ) { $ this -> resolve ( $ value ) ; } , function ( $ reason = null ) { $ this -> reject ( $ reason ) ; } , function ( $ reason = null ) { $ this -> cancel ( $ reason ) ; } ) ; } catch ( Error $ ex ) { $ this -> reject ( $ ex ) ; } catch ( Exception $ ex ) { $ this -> reject ( $ ex ) ; } }
Mutate resolver .
23,769
public function getNext ( ) { if ( $ this -> currentToken !== null || strlen ( $ this -> currentInput ) > 0 ) { $ this -> parseNextToken ( ) ; return $ this -> currentToken ; } return null ; }
Get next token
23,770
private function scanNextType ( $ string ) { foreach ( $ this -> patterns as $ type => $ pattern ) { if ( preg_match ( '/^(' . $ pattern . ')/sS' , $ string , $ matches ) === 1 ) { return [ 'type' => $ type , 'match' => $ matches [ 1 ] , 'length' => strlen ( $ matches [ 1 ] ) , ] ; } } return null ; }
Determines the next type of the given string
23,771
private function getAnyType ( $ string ) { $ anyString = '' ; do { $ anyString .= $ string [ 0 ] ; $ string = substr ( $ string , 1 ) ; $ typeInfo = $ this -> scanNextType ( $ string ) ; if ( $ typeInfo [ 'type' ] !== self :: T_MARKUP_OPEN && $ typeInfo [ 'type' ] !== self :: T_MARKUP_OPEN_ESCAPED ) { $ typeInfo = null ; } } while ( $ typeInfo === null && $ string ) ; return [ 'type' => self :: T_ANY , 'match' => $ anyString , 'length' => strlen ( $ anyString ) , ] ; }
Get next ANY - type which is a string that does not match to any token
23,772
public function beforeFilter ( ) { if ( defined ( 'PHPUNIT_TESTSUITE' ) ) { return ; } $ maintenancePage = Environment :: read ( 'MAINTENANCE_PAGE_REDIRECT_URL' ) ; $ currentUrl = $ this -> _controller -> getRequest ( ) -> here ; $ accessibleUrls = explode ( '|' , Environment :: read ( 'MAINTENANCE_ACCESSIBLE_URLS' ) ) ; $ accessibleUrls [ ] = $ maintenancePage ; if ( ! self :: isMaintenanceActive ( ) ) { if ( in_array ( $ currentUrl , $ accessibleUrls ) && substr ( $ maintenancePage , - strlen ( $ currentUrl ) ) === $ currentUrl ) { $ maintenanceBasePage = Environment :: read ( 'MAINTENANCE_BASE_URL' ) ; return $ this -> _controller -> redirect ( $ maintenanceBasePage ) ; } return ; } $ cookieName = Environment :: read ( 'MAINTENANCE_COOKIE_NAME' ) ; $ cookieExists = ( $ this -> _controller -> Cookie -> read ( $ cookieName ) !== null ) ; if ( $ cookieExists ) { return ; } $ headerActive = Environment :: read ( 'MAINTENANCE_HEADER_ACTIVE' ) ; $ headerName = Environment :: read ( 'MAINTENANCE_HEADER_NAME' ) ; $ headerValue = Environment :: read ( 'MAINTENANCE_HEADER_VALUE' ) ; $ successUrl = Environment :: read ( 'MAINTENANCE_PASSWORD_SUCCESS_URL' ) ; if ( $ headerActive && ! empty ( $ this -> _controller -> request -> getHeader ( $ headerName ) ) && $ this -> _controller -> request -> getHeader ( $ headerName ) === $ headerValue ) { $ this -> _controller -> Cookie -> write ( $ cookieName , true ) ; return $ this -> _controller -> redirect ( $ successUrl ) ; } $ passwordUrl = Environment :: read ( 'MAINTENANCE_PASSWORD_URL' ) ; $ accessibleUrls [ ] = $ passwordUrl ; if ( ! in_array ( $ currentUrl , $ accessibleUrls ) ) { return $ this -> _controller -> redirect ( $ maintenancePage ) ; } if ( $ currentUrl != $ passwordUrl ) { return ; } $ user = Environment :: read ( 'MAINTENANCE_USER' ) ; $ password = Environment :: read ( 'MAINTENANCE_PASSWORD' ) ; if ( $ currentUrl == $ passwordUrl ) { if ( ! isset ( $ _SERVER [ 'PHP_AUTH_USER' ] ) ) { header ( 'WWW-Authenticate: Basic realm="Maintenance Realm"' ) ; header ( 'HTTP/1.0 401 Unauthorized' ) ; echo 'Unauthorized' ; exit ; } if ( $ _SERVER [ 'PHP_AUTH_USER' ] === $ user && $ _SERVER [ 'PHP_AUTH_PW' ] === $ password ) { $ this -> _controller -> Cookie -> write ( $ cookieName , true ) ; return $ this -> _controller -> redirect ( $ successUrl ) ; } return $ this -> _controller -> redirect ( $ maintenancePage ) ; } return $ this -> _controller -> redirect ( $ maintenancePage ) ; }
Maintenance redirect logic
23,773
function Get ( $ key ) { if ( ! $ this -> fd ) { trigger_error ( "XDB:Get(), null db handler." , E_USER_WARNING ) ; return false ; } $ klen = strlen ( $ key ) ; if ( $ klen == 0 || $ klen > XDB_MAXKLEN ) return false ; $ rec = $ this -> _get_record ( $ key ) ; if ( ! isset ( $ rec [ 'vlen' ] ) || $ rec [ 'vlen' ] == 0 ) return false ; return $ rec [ 'value' ] ; }
Read the value by key
23,774
public function root ( ) { $ category = $ this -> createModel ( ) ; $ category = $ category -> whereExists ( function ( $ query ) { $ query -> select ( \ DB :: raw ( 1 ) ) -> from ( 'category_hierarchy' ) -> whereRaw ( DB :: getTablePrefix ( ) . 'categories.id = ' . DB :: getTablePrefix ( ) . 'category_hierarchy.category_id' ) -> where ( 'category_hierarchy.category_parent_id' , 0 ) ; } ) ; return $ category ; }
Get only root category .
23,775
static function exec ( $ method , & $ result ) { $ ini = eZINI :: instance ( 'ezmultiupload.ini' ) ; $ handlers = $ ini -> variable ( 'MultiUploadSettings' , 'MultiuploadHandlers' ) ; if ( ! $ handlers ) return false ; foreach ( $ handlers as $ hanlder ) { if ( ! call_user_func ( array ( $ hanlder , $ method ) , $ result ) ) eZDebug :: writeWarning ( 'Multiupload handler implementation not found' ) ; } return true ; }
Call preUpload or postUpload user definied functions .
23,776
public function findOrMakeCart ( ) { $ cookies = $ this -> cookiesSupported ( ) ; $ session = $ this -> getSession ( ) ; $ classname = self :: config ( ) -> model ; $ cart = null ; $ write = false ; $ member = Security :: getCurrentUser ( ) ; if ( $ cookies ) { $ cart_id = Cookie :: get ( self :: COOKIE_NAME ) ; } else { $ cart_id = $ session -> get ( self :: COOKIE_NAME ) ; } if ( isset ( $ cart_id ) ) { $ cart = $ classname :: get ( ) -> find ( 'AccessKey' , $ cart_id ) ; } if ( empty ( $ cart ) && isset ( $ member ) && $ member -> getCart ( ) ) { $ cart = $ member -> getCart ( ) ; } if ( empty ( $ cart ) ) { $ cart = $ classname :: create ( ) ; } return $ cart ; }
Either find an existing cart or create a new one .
23,777
public function cleanOld ( ) { $ siteconfig = SiteConfig :: current_site_config ( ) ; $ date = $ siteconfig -> dbobject ( "LastEstimateClean" ) ; $ request = Injector :: inst ( ) -> get ( HTTPRequest :: class ) ; if ( ! $ date || ( $ date && ! $ date -> IsToday ( ) ) ) { $ task = Injector :: inst ( ) -> create ( CleanExpiredEstimatesTask :: class ) ; $ task -> setSilent ( true ) ; $ task -> run ( $ request ) ; $ siteconfig -> LastEstimateClean = DBDatetime :: now ( ) -> Value ; $ siteconfig -> write ( ) ; } }
Run the task to clean old shopping carts
23,778
public function cookiesSupported ( ) { Cookie :: set ( self :: TEST_COOKIE , 1 ) ; $ cookie = Cookie :: get ( self :: TEST_COOKIE ) ; Cookie :: force_expiry ( self :: TEST_COOKIE ) ; return ( empty ( $ cookie ) ) ? false : true ; }
Test to see if the current user supports cookies
23,779
public function addItem ( $ item , $ customisations = [ ] ) { $ cart = $ this -> getCurrent ( ) ; $ stock_item = $ item -> FindStockItem ( ) ; $ added = false ; if ( ! $ item instanceof LineItem ) { throw new ValidationException ( _t ( "ShoppingCart.WrongItemClass" , "Item needs to be of class {class}" , [ "class" => LineItem :: class ] ) ) ; } if ( ! $ item -> exists ( ) ) { $ item -> write ( ) ; } if ( ! is_array ( $ customisations ) ) { $ customisations = [ $ customisations ] ; } $ custom_association = null ; $ custom_associations = array_merge ( $ item -> hasMany ( ) , $ item -> manyMany ( ) ) ; foreach ( $ custom_associations as $ key => $ value ) { $ class = $ value :: create ( ) ; if ( $ class instanceof LineItemCustomisation ) { $ custom_association = $ key ; break ; } } if ( isset ( $ custom_association ) ) { $ item -> write ( ) ; foreach ( $ customisations as $ customisation ) { if ( $ customisation instanceof LineItemCustomisation ) { if ( ! $ customisation -> exists ( ) ) { $ customisation -> write ( ) ; } $ item -> { $ custom_association } ( ) -> add ( $ customisation ) ; } } } $ item -> write ( ) ; if ( ! $ cart -> exists ( ) ) { $ this -> save ( ) ; } $ existing_item = $ cart -> Items ( ) -> find ( "Key" , $ item -> Key ) ; if ( isset ( $ existing_item ) ) { $ this -> updateItem ( $ existing_item , $ existing_item -> Quantity + $ item -> Quantity ) ; $ item -> delete ( ) ; $ added = true ; } if ( ! $ added ) { if ( $ stock_item && ( $ stock_item -> Stocked || $ this -> config ( ) -> check_stock_levels ) ) { if ( $ item -> checkStockLevel ( $ item -> Quantity ) < 0 ) { throw new ValidationException ( _t ( "ShoppingCart.NotEnoughStock" , "There are not enough '{title}' in stock" , [ 'title' => $ stock_item -> Title ] ) ) ; } } $ item -> ParentID = $ cart -> ID ; $ item -> write ( ) ; } $ this -> save ( ) ; return $ this ; }
Add an item to the shopping cart . By default this should be a line item but this method will determine if the correct object has been provided before attempting to add .
23,780
public function removeItem ( $ item ) { if ( ! $ item instanceof LineItem ) { throw new ValidationException ( _t ( "ShoppingCart.WrongItemClass" , "Item needs to be of class {class}" , [ "class" => LineItem :: class ] ) ) ; } $ item -> delete ( ) ; $ this -> save ( ) ; return $ this ; }
Remove a LineItem from ShoppingCart
23,781
public function delete ( ) { $ cookies = $ this -> cookiesSupported ( ) ; $ cart = $ this -> getCurrent ( ) ; if ( $ cart -> exists ( ) ) { $ cart -> delete ( ) ; } if ( $ cookies ) { Cookie :: force_expiry ( self :: COOKIE_NAME ) ; } else { $ this -> getSession ( ) -> clear ( self :: COOKIE_NAME ) ; } return $ this ; }
Destroy current shopping cart
23,782
public function parse ( AbstractStream $ stream ) { if ( ! ( $ this -> dataSet instanceof DataSet ) ) { $ this -> dataSet = new DataSet ; } $ this -> rewind ( ) ; do { $ field = $ this -> current ( ) ; $ field -> setDataSet ( $ this -> getDataSet ( ) ) ; if ( $ field instanceof Conditional ) { $ field = $ field -> resolveField ( ) ; } if ( $ field instanceof self ) { $ this -> dataSet -> push ( $ this -> key ( ) ) ; $ field -> parse ( $ stream ) ; $ this -> dataSet -> pop ( ) ; } else { $ this -> dataSet -> setValue ( $ this -> key ( ) , $ field -> parse ( $ stream ) ) ; } $ this -> next ( ) ; } while ( $ this -> valid ( ) ) ; if ( isset ( $ this -> assert ) ) { $ this -> validate ( $ this -> dataSet -> getValueByCurrentPath ( ) ) ; } return $ this -> dataSet -> getData ( ) ; }
Recursively call parse method of all children and store values in associated DataSet .
23,783
private function initFromArray ( array $ fieldArray = [ ] ) { foreach ( $ fieldArray as $ fieldName => $ fieldParams ) { $ this -> addField ( $ fieldName , Factory :: get ( $ fieldParams ) ) ; } }
Recursively creates field instances form their declarations .
23,784
public function addFile ( $ file , $ type = '' , $ locale = null , $ filename = null , $ keepOriginal = false ) : void { if ( $ file instanceof Traversable || is_array ( $ file ) ) { $ this -> addFiles ( $ file , $ type , $ locale , $ keepOriginal ) ; } else { $ locale = $ this -> normalizeLocaleString ( $ locale ) ; if ( is_string ( $ file ) ) { $ asset = AssetUploader :: uploadFromBase64 ( $ file , $ filename , $ keepOriginal ) ; } else { $ asset = AssetUploader :: upload ( $ file , $ filename , $ keepOriginal ) ; } if ( $ asset instanceof Asset ) { $ asset -> attachToModel ( $ this , $ type , $ locale ) ; } } }
Adds a file to this model accepts a type and locale to be saved with the file .
23,785
public function addFiles ( $ files , $ type = '' , $ locale = null , $ keepOriginal = false ) : void { $ files = ( array ) $ files ; $ locale = $ this -> normalizeLocaleString ( $ locale ) ; if ( is_string ( array_values ( $ files ) [ 0 ] ) ) { foreach ( $ files as $ filename => $ file ) { $ this -> addFile ( $ file , $ type , $ locale , $ filename , $ keepOriginal ) ; } } else { foreach ( $ files as $ filename => $ file ) { $ this -> addFile ( $ file , $ type , $ locale , $ filename , $ keepOriginal ) ; } } }
Adds multiple files to this model accepts a type and locale to be saved with the file .
23,786
public function replaceAsset ( $ replace , $ with ) { $ old = $ this -> assets ( ) -> findOrFail ( $ replace ) ; $ this -> assets ( ) -> detach ( $ old -> id ) ; $ old -> delete ( ) ; $ this -> addFile ( Asset :: findOrFail ( $ with ) , $ old -> pivot -> type , $ old -> pivot -> locale ) ; }
Remove the asset and attaches a new one .
23,787
protected function collectInput ( ) { $ password = $ this -> generateRandomPassword ( ) ; return [ 'name' => $ this -> argument ( 'name' ) ? $ this -> argument ( 'name' ) : '' , 'email' => $ this -> argument ( 'email' ) , 'password' => $ password , 'password_confirmation' => $ password , ] ; }
Returns an array with all required input .
23,788
protected function registerUser ( array $ input ) { $ this -> dispatch ( new RegisterUserJob ( array_get ( $ input , 'name' ) , array_get ( $ input , 'email' ) , array_get ( $ input , 'password' ) ) ) ; $ this -> info ( trans ( 'authentication::user.console.created' , $ input ) ) ; }
Performs the user registration .
23,789
public function exampleFailed ( Example $ example ) { $ this -> failures [ ] = $ example ; $ event = new ExampleFailEvent ( $ example ) ; $ this -> dispatcher -> dispatch ( Events :: EXAMPLE_FAIL , $ event ) ; }
An example failed
23,790
public function examplePassed ( Example $ example ) { $ this -> passes [ ] = $ example ; $ event = new ExamplePassEvent ( $ example ) ; $ this -> dispatcher -> dispatch ( Events :: EXAMPLE_PASS , $ event ) ; }
An example passed
23,791
public function examplePending ( Example $ example ) { $ this -> pending [ ] = $ example ; $ event = new ExamplePendEvent ( $ example ) ; $ this -> dispatcher -> dispatch ( Events :: EXAMPLE_PEND , $ event ) ; }
An example is pending
23,792
public function exampleSkipped ( Example $ example ) { $ this -> skipped [ ] = $ example ; $ event = new ExampleSkipEvent ( $ example ) ; $ this -> dispatcher -> dispatch ( Events :: EXAMPLE_SKIP , $ event ) ; }
An example is skipped
23,793
public static function optimize ( string $ key , string $ typeName , string $ optimizedType ) : void { self :: $ replacements [ $ typeName ] [ $ key ] = $ optimizedType ; }
Register an optimized version of a class .
23,794
public static function autoload ( string $ typeName ) : bool { static $ enabled ; if ( \ defined ( 'KOOLKODE_ASYNC_OPTIMIZATIONS' ) ) { if ( $ enabled === null ) { $ enabled = \ array_map ( 'trim' , \ explode ( ',' , \ strtolower ( \ KOOLKODE_ASYNC_OPTIMIZATIONS ) ) ) ; } if ( isset ( self :: $ replacements [ $ typeName ] ) ) { foreach ( $ enabled as $ key ) { if ( isset ( self :: $ replacements [ $ typeName ] [ $ key ] ) ) { return \ class_alias ( self :: $ replacements [ $ typeName ] [ $ key ] , $ typeName , true ) ; } } } } return false ; }
Triggered by SPL autoload when a class needs to be loaded .
23,795
public function add ( $ for , $ for_id , $ user_id , $ action , $ data = '' ) { $ history = new $ this -> model ; $ history -> for = $ for ; $ history -> for_id = $ for_id ; $ history -> user_id = $ user_id ; $ history -> action = $ action ; $ history -> data = is_array ( $ data ) ? json_encode ( $ data ) : $ data ; $ history -> save ( ) ; return $ history ; }
Adds a new history record
23,796
public function get ( $ for , $ for_id , $ limit = false ) { return $ this -> model -> whereFor ( $ for ) -> whereForId ( $ for_id ) -> orderBy ( 'created_at' , 'desc' ) -> take ( $ limit ) -> get ( ) ; }
Returns all the history for a specified for and for_id
23,797
protected function expandAggregateInspectionData ( InspectionInterface $ inspection ) { if ( $ inspection instanceof AggregateInspection ) { return array_map ( function ( InspectionInterface $ inspection ) { return [ static :: PARAM_INSPECTION => $ inspection , static :: PARAM_INSPECTION_DATA => $ this -> expandAggregateInspectionData ( $ inspection ) , static :: PARAM_INSPECTION_CLASS => get_class ( $ inspection ) , ] ; } , $ inspection -> getInspectionData ( ) ) ; } return $ inspection -> getInspectionData ( ) ; }
Expand the data from an aggregate inspection recursively providing useful data for the produced view model
23,798
public function handleEncodePropertyValueFromWidget ( EncodePropertyValueFromWidgetEvent $ event ) { $ attribute = $ this -> getSupportedAttribute ( $ event ) ; if ( ! $ attribute ) { return ; } $ date = \ DateTime :: createFromFormat ( $ attribute -> getDateTimeFormatString ( ) , $ event -> getValue ( ) ) ; if ( $ date ) { $ event -> setValue ( $ date -> getTimestamp ( ) ) ; } }
Encode an timestamp attribute value from a widget value .
23,799
public function handleDecodePropertyValueForWidgetEvent ( DecodePropertyValueForWidgetEvent $ event ) { $ attribute = $ this -> getSupportedAttribute ( $ event ) ; if ( ! $ attribute ) { return ; } $ dispatcher = $ event -> getEnvironment ( ) -> getEventDispatcher ( ) ; $ value = $ event -> getValue ( ) ; if ( \ is_numeric ( $ value ) ) { $ dateEvent = new ParseDateEvent ( $ value , $ attribute -> getDateTimeFormatString ( ) ) ; $ dispatcher -> dispatch ( ContaoEvents :: DATE_PARSE , $ dateEvent ) ; $ event -> setValue ( $ dateEvent -> getResult ( ) ) ; } }
Decode an timestamp attribute value for a widget value .