idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
2,400 | public function enumerateImages ( $ aifrom = null , $ aito = null , $ aiprefix = null , $ aiminsize = null , $ aimaxsize = null , $ ailimit = null , $ aidir = null , $ aisha1 = null , $ aisha1base36 = null , array $ aiprop = null , $ aimime = null ) { $ path = '?action=query&list=allimages' ; if ( isset ( $ aifrom ) ) { $ path .= '&aifrom=' . $ aifrom ; } if ( isset ( $ aito ) ) { $ path .= '&aito=' . $ aito ; } if ( isset ( $ aiprefix ) ) { $ path .= '&aiprefix=' . $ aiprefix ; } if ( isset ( $ aiminsize ) ) { $ path .= '&aiminsize=' . $ aiminsize ; } if ( isset ( $ aimaxsize ) ) { $ path .= '&aimaxsize=' . $ aimaxsize ; } if ( isset ( $ ailimit ) ) { $ path .= '&ailimit=' . $ ailimit ; } if ( isset ( $ aidir ) ) { $ path .= '&aidir=' . $ aidir ; } if ( isset ( $ aisha1 ) ) { $ path .= '&aisha1=' . $ aisha1 ; } if ( isset ( $ aisha1base36 ) ) { $ path .= '&$aisha1base36=' . $ aisha1base36 ; } if ( isset ( $ aiprop ) ) { $ path .= '&aiprop=' . $ this -> buildParameter ( $ aiprop ) ; } if ( isset ( $ aimime ) ) { $ path .= '&aimime=' . $ aimime ; } $ response = $ this -> client -> get ( $ this -> fetchUrl ( $ path ) ) ; return $ this -> validateResponse ( $ response ) ; } | Method to enumerate all images . |
2,401 | protected function order ( ) { foreach ( $ this -> orderBy as $ orderBy ) { if ( count ( $ orderBy ) == 1 ) { $ this -> model = $ this -> model -> orderBy ( $ orderBy ) ; } if ( count ( $ orderBy ) == 2 ) { $ this -> model = $ this -> model -> orderBy ( $ orderBy [ 0 ] , $ orderBy [ 1 ] ) ; } } } | Apply order by property to query . |
2,402 | protected function get ( $ id = null ) { $ this -> filter ( ) ; if ( $ this -> eagerLoad ) { $ this -> model = $ this -> model -> with ( $ this -> eagerLoad ) ; } if ( $ id ) { return $ this -> model -> where ( 'id' , $ id ) -> firstOrFail ( ) ; } return $ this -> model -> get ( ) ; } | Run query including eager load . |
2,403 | public function store ( $ input ) { $ this -> model = $ this -> model -> fill ( $ input ) ; $ filteredInput = $ this -> runChecks ( 'store' , $ this -> model -> toArray ( ) ) ; if ( $ filteredInput ) { $ this -> model -> fill ( $ filteredInput ) ; } return $ this -> model -> save ( ) ; } | Store a new resource item . |
2,404 | public function update ( $ id , $ input ) { $ this -> model = $ this -> model -> query ( ) -> findOrFail ( $ id ) ; $ this -> model = $ this -> model -> fill ( $ input ) ; $ filteredInput = $ this -> runChecks ( 'update' , $ this -> model -> toArray ( ) , $ this -> model -> getOriginal ( ) ) ; if ( $ filteredInput ) { $ this -> model -> fill ( $ filteredInput ) ; } return $ this -> model -> save ( ) ; } | Update an existing resource item by ID . |
2,405 | public function destroy ( $ id ) { $ this -> model = $ this -> model -> findOrFail ( $ id ) ; $ this -> runChecks ( 'destroy' , $ this -> model -> toArray ( ) ) ; return $ this -> model -> delete ( ) ; } | Destroy an existing resource item by ID . |
2,406 | function parse ( $ content ) { global $ shortcode_tags ; if ( empty ( $ shortcode_tags ) || ! is_array ( $ shortcode_tags ) ) return $ content ; $ pattern = $ this -> get_shortcode_regex ( ) ; return preg_replace_callback ( '/' . $ pattern . '/s' , array ( $ this , 'do_shortcode_tag' ) , $ content ) ; } | Search content for shortcodes and filter shortcodes through their hooks . |
2,407 | function get_shortcode_regex ( ) { global $ shortcode_tags ; $ tagnames = array_keys ( $ shortcode_tags ) ; $ tagregexp = join ( '|' , array_map ( 'preg_quote' , $ tagnames ) ) ; return '(.?)\[(' . $ tagregexp . ')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)' ; } | Retrieve the shortcode regular expression for searching . |
2,408 | function shortcode_atts ( $ pairs , $ atts ) { $ atts = ( array ) $ atts ; $ out = array ( ) ; foreach ( $ pairs as $ name => $ default ) { if ( array_key_exists ( $ name , $ atts ) ) $ out [ $ name ] = $ atts [ $ name ] ; else $ out [ $ name ] = $ default ; } return $ out ; } | Combine user attributes with known attributes and fill in defaults when needed . |
2,409 | public function getExtendedName ( ) { $ type = $ this -> getType ( ) ; if ( $ type ) { $ extendedName = $ type -> getName ( ) ; } else { $ extendedName = '' ; } $ catTitle = $ this -> getCategoryTitle ( ) ; if ( $ catTitle !== null ) { $ extendedName .= '-' . $ this -> getCategoryTitle ( ) ; } $ extendedName .= '-' . $ this -> getName ( ) ; return $ extendedName ; } | Returns the extended name |
2,410 | public function updatePageOptions ( FieldList $ fields ) { $ pageTypeField = $ fields -> fieldByName ( 'PageType' ) ; foreach ( $ pageTypeField -> getSource ( ) as $ classKey => $ classValue ) { if ( $ classKey == 'PlaceablePage' ) { foreach ( PlaceablePageType :: get ( ) as $ type ) { $ html = sprintf ( '%s<strong class="title">%s</strong><span class="description">%s</span>' , ( $ type -> Icon ( ) -> exists ( ) ) ? '<img class="page-icon" src="' . $ type -> Icon ( ) -> croppedImage ( 16 , 16 ) -> URL . '" />' : '<span class="page-icon"></span>' , $ type -> Title , $ type -> Description ) ; $ PageTypes [ "$classKey-$type->ID" ] = DBField :: create_field ( 'HTMLText' , $ html ) ; } } else { $ PageTypes [ "$classKey-0" ] = $ classValue ; } } $ numericLabelTmpl = '<span class="step-label"><span class="flyout">%d</span><span class="arrow"></span><span class="title">%s</span></span>' ; $ fields -> removeByName ( array ( 'PageType' , 'RestrictedNote' ) ) ; $ fields -> addFields ( array ( OptionsetField :: create ( 'PageTypeFake' , sprintf ( $ numericLabelTmpl , 2 , _t ( 'CMSMain.ChoosePageType' , 'Choose page type' ) ) , $ PageTypes ) , HiddenField :: create ( 'PageType' , 'PageType' ) , HiddenField :: create ( 'PageTypeID' , 'PageTypeID' ) ) ) ; return $ fields ; } | Update add page fields |
2,411 | public function getAggregateHistoryFor ( Identity $ id , $ offset = 0 , $ max = null ) { return new CommittedEvents ( $ id , array_filter ( array_slice ( $ this -> events [ ( string ) $ id ] , $ offset , $ max , true ) , function ( DomainEvent $ event ) use ( $ id ) { return $ event -> getAggregateIdentity ( ) -> equals ( $ id ) ; } ) ) ; } | Gets the events stored as memory and wraps it in \ CommittedEvents |
2,412 | public function member ( $ key ) { foreach ( $ this -> value as $ innerKey => $ value ) { if ( $ key === $ innerKey ) { return true ; } } return false ; } | Return whether or not the map contains the specified key . |
2,413 | public function EscapeSql ( $ String , $ FirstWordOnly = FALSE ) { if ( is_array ( $ String ) ) { $ EscapedArray = array ( ) ; foreach ( $ String as $ k => $ v ) { $ EscapedArray [ $ this -> EscapeSql ( $ k ) ] = $ this -> EscapeSql ( $ v , $ FirstWordOnly ) ; } return $ EscapedArray ; } if ( ctype_alnum ( $ String ) === FALSE ) { if ( strpos ( $ String , '.' ) !== FALSE ) { $ MungedAliases = implode ( '.' , array_keys ( $ this -> _AliasMap ) ) . '.' ; $ TableName = substr ( $ String , 0 , strpos ( $ String , '.' ) + 1 ) ; $ String = ( strpos ( $ MungedAliases , $ TableName ) !== FALSE || strpos ( $ TableName , "'" ) !== FALSE ) ? $ String : $ this -> Database -> DatabasePrefix . $ String ; } $ LeftBound = ( $ FirstWordOnly === TRUE ) ? '' : '|\s|\(' ; $ String = preg_replace ( '/(^' . $ LeftBound . ')([\w\d\-\_]+?)(\s|\)|$)/iS' , '$1`$2`$3' , $ String ) ; } else { return "`{$String}`" ; } $ Exceptions = array ( 'as' , '/' , '-' , '%' , '+' , '*' ) ; foreach ( $ Exceptions as $ Exception ) { if ( stristr ( $ String , " `{$Exception}` " ) !== FALSE ) $ String = preg_replace ( '/ `(' . preg_quote ( $ Exception ) . ')` /i' , ' $1 ' , $ String ) ; } return $ String ; } | Takes a string of SQL and adds backticks if necessary . |
2,414 | public function FetchTableSql ( $ LimitToPrefix = FALSE ) { $ Sql = "show tables" ; if ( is_bool ( $ LimitToPrefix ) && $ LimitToPrefix && $ this -> Database -> DatabasePrefix != '' ) $ Sql .= " like " . $ this -> Database -> Connection ( ) -> quote ( $ this -> Database -> DatabasePrefix . '%' ) ; elseif ( is_string ( $ LimitToPrefix ) && $ LimitToPrefix ) $ Sql .= " like " . $ this -> Database -> Connection ( ) -> quote ( str_replace ( ':_' , $ this -> Database -> DatabasePrefix , $ LimitToPrefix ) ) ; return $ Sql ; echo "<pre>$Sql</pre>" ; } | Returns a platform - specific query to fetch table names . |
2,415 | public function FormatTableName ( $ Table ) { if ( strpos ( $ Table , '.' ) !== FALSE ) { if ( preg_match ( '/^([^\s]+)\s+(?:as\s+)?`?([^`]+)`?$/' , $ Table , $ Matches ) ) { $ DatabaseTable = '`' . str_replace ( '.' , '`.`' , $ Matches [ 1 ] ) . '`' ; $ Table = str_replace ( $ Matches [ 1 ] , $ DatabaseTable , $ Table ) ; } else $ Table = '`' . str_replace ( '.' , '`.`' , $ Table ) . '`' ; } return $ Table ; } | Takes a table name and makes sure it is formatted for this database engine . |
2,416 | public function GetDelete ( $ TableName , $ Wheres = array ( ) ) { $ Conditions = '' ; $ Joins = '' ; $ DeleteFrom = '' ; if ( count ( $ this -> _Joins ) > 0 ) { $ Joins .= "\n" ; $ Joins .= implode ( "\n" , $ this -> _Joins ) ; $ DeleteFroms = array ( ) ; foreach ( $ this -> _Froms as $ From ) { $ Parts = preg_split ( '`\s`' , trim ( $ From ) ) ; if ( count ( $ Parts ) > 1 ) $ DeleteFroms [ ] = $ Parts [ 1 ] . '.*' ; else $ DeleteFroms [ ] = $ Parts [ 0 ] . '.*' ; } $ DeleteFrom = implode ( ', ' , $ DeleteFroms ) ; } if ( count ( $ Wheres ) > 0 ) { $ Conditions = "\nwhere " ; $ Conditions .= implode ( "\n" , $ Wheres ) ; $ this -> _EndQuery ( ) ; } return "delete $DeleteFrom from " . $ TableName . $ Joins . $ Conditions ; } | Returns a delete statement for the specified table and the supplied conditions . |
2,417 | public function GetLimit ( $ Query , $ Limit , $ Offset ) { $ Offset = $ Offset == 0 ? '' : $ Offset . ', ' ; return $ Query . "limit " . $ Offset . $ Limit ; } | Adds a limit clause to the provided query for this database engine . |
2,418 | public function SetEncoding ( $ Encoding ) { if ( $ Encoding != '' && $ Encoding !== FALSE ) { $ SavedNamedParameters = $ this -> _NamedParameters ; $ this -> _NamedParameters = array ( ) ; $ this -> _NamedParameters [ ':encoding' ] = $ Encoding ; $ this -> Query ( 'set names :encoding' ) ; $ this -> _NamedParameters = $ SavedNamedParameters ; } } | Sets the character encoding for this database engine . |
2,419 | protected function openSink ( ) { if ( ! $ this -> uri ) { throw new \ LogicException ( 'Missing stream uri, the stream can not be opened.' ) ; } $ this -> error = null ; set_error_handler ( array ( $ this , 'errorTrap' ) ) ; if ( substr ( $ this -> uri , 0 , 4 ) === 'udp:' ) { $ parsed = parse_url ( $ this -> uri ) ; if ( ! isset ( $ parsed [ 'host' ] ) ) { throw new \ UnexpectedValueException ( sprintf ( 'Udp transport "%s" must specify a host' , $ this -> uri ) ) ; } if ( ! isset ( $ parsed [ 'port' ] ) ) { throw new \ UnexpectedValueException ( sprintf ( 'Udp transport "%s" must specify a port' , $ this -> uri ) ) ; } $ this -> prefix = '' ; if ( isset ( $ parsed [ 'path' ] ) ) { $ this -> prefix = ltrim ( $ parsed [ 'path' ] , '/' ) ; } $ this -> writer = new UdpWriter ( $ parsed [ 'host' ] , $ parsed [ 'port' ] ) ; } else { $ this -> writer = new StreamWriter ( $ this -> uri ) ; } restore_error_handler ( ) ; if ( $ this -> error !== null ) { $ this -> writer = null ; throw new \ UnexpectedValueException ( sprintf ( 'The stream or file "%s" could not be opened: %s' , $ this -> uri , $ this -> error ) ) ; } } | Open the log sink described by our stream URI . |
2,420 | public function setOptions ( $ options ) { foreach ( $ this -> options as $ key => $ option ) { if ( isset ( $ options [ $ key ] ) ) { $ this -> options [ $ key ] = $ options [ $ key ] ; } } } | Set any options if the inputted over write the defaults . |
2,421 | private function _processQueue ( ) { $ results = [ ] ; foreach ( $ this -> fifo as $ command ) { $ results [ ] = $ this -> _run ( $ command ) ; } return isset ( $ results [ 0 ] ) && $ results [ 0 ] === 0 && count ( array_unique ( $ results ) ) === 1 ; } | Process the queue stepping through each item in the queue and running each independently . |
2,422 | private function _run ( $ command ) { if ( $ this -> options [ 'type' ] === self :: TYPE_PHP ) { $ this -> savedFiles [ ] = $ this -> options [ 'tmp-dir' ] . 'async-tmp-' . time ( ) . '.php' ; $ result = file_put_contents ( end ( $ this -> savedFiles ) , $ this -> _generateCode ( $ command ) , LOCK_EX ) ; if ( $ result !== false ) { $ cmd = "php " . end ( $ this -> savedFiles ) ; } else { $ cmd = "php --help" ; } } else { $ cmd = $ command ; } if ( $ this -> options [ 'async' ] ) { $ cmd .= ' > /dev/null 2>&1 &' ; } exec ( $ cmd , $ output , $ exit ) ; if ( $ this -> options [ 'debug' ] ) { echo '<br />Command Run: ' . $ cmd ; } return $ exit === 0 ; } | Actually run the command by detecting the async type and using exec to run it . Will echo data depending of whether the debug flag is on . |
2,423 | private function _generateCode ( $ command ) { $ code = "<?php" . PHP_EOL . $ command . PHP_EOL ; if ( $ this -> options [ 'cleanup' ] ) { $ code .= "unlink('" . end ( $ this -> savedFiles ) . "');" ; } return $ code ; } | Generate the content to save to the temporary file . This adds the necessary php tags and will optionally clean up the temp file afterwards . |
2,424 | protected function deleteFile ( $ fileName ) { if ( null !== $ fileName && $ this -> mediaStorageManager -> exists ( $ fileName ) ) { $ this -> mediaStorageManager -> deleteContent ( $ fileName ) ; } } | Remove a media file if it is stored |
2,425 | public function getNewBuilds ( ) { $ lastBuildFilename = $ this -> getLatestBuildName ( ) ; $ iterator = $ this -> getBuilds ( ) ; $ files = array ( ) ; foreach ( $ iterator as $ fileInfo ) { if ( $ fileInfo -> getFilename ( ) > $ lastBuildFilename ) { array_push ( $ files , $ fileInfo -> getPathname ( ) ) ; } } sort ( $ files ) ; return $ files ; } | Returns an array of new build file names |
2,426 | private function createOperation ( $ accIdDebit , $ accIdCredit , $ amount , $ note ) { $ tran = new ETrans ( ) ; $ tran -> setDebitAccId ( $ accIdDebit ) ; $ tran -> setCreditAccId ( $ accIdCredit ) ; $ tran -> setValue ( $ amount ) ; $ tran -> setNote ( $ note ) ; $ req = new \ Praxigento \ Accounting \ Api \ Service \ Operation \ Create \ Request ( ) ; $ req -> setOperationTypeCode ( Cfg :: CODE_TYPE_OPER_WALLET_REFUND ) ; $ req -> setTransactions ( [ $ tran ] ) ; $ req -> setOperationNote ( $ note ) ; $ resp = $ this -> servOper -> exec ( $ req ) ; $ result = $ resp -> getOperationId ( ) ; return $ result ; } | Create refund operation . |
2,427 | private function refundByTransaction ( $ tranId , \ Magento \ Sales \ Model \ Order $ sale ) { $ saleId = $ sale -> getId ( ) ; $ saleIncId = $ sale -> getIncrementId ( ) ; $ transaction = $ this -> daoTrans -> getById ( $ tranId ) ; $ accIdCust = $ transaction -> getDebitAccId ( ) ; $ accIdSys = $ transaction -> getCreditAccId ( ) ; $ amount = $ transaction -> getValue ( ) ; $ note = "Refund for sale #$saleIncId" ; $ operId = $ this -> createOperation ( $ accIdSys , $ accIdCust , $ amount , $ note ) ; $ this -> logger -> info ( "Refund operation #$operId is created for sale #$saleIncId/$saleId" ) ; } | Load transaction for direct payment and create refund payment . |
2,428 | public function isEmailAvailable ( $ email , $ fields = array ( ) ) { $ fields = ( object ) $ fields ; return $ this -> getMapper ( ) -> isEmailExists ( $ email , empty ( $ fields -> id ) ? null : $ fields -> id ) ? 'user.action.register.email.taken' : true ; } | Is an email name available |
2,429 | public function isEmailNotTaken ( $ email , $ fields = array ( ) ) { $ fields = ( object ) $ fields ; return $ this -> getMapper ( ) -> isEmailTaken ( $ email , empty ( $ fields -> id ) ? null : $ fields -> id ) ? 'user.action.register.email.taken' : true ; } | Is an email not taken |
2,430 | public function isDisplayNameAvailable ( $ displayName , $ fields = array ( ) ) { $ fields = ( object ) $ fields ; $ displayName = Structure :: trimDisplayName ( $ displayName ) ; if ( 3 > mb_strlen ( $ displayName ) ) { return 'user.action.register.displayName.tooShort' ; } return $ this -> getMapper ( ) -> isDisplayNameExists ( $ displayName , empty ( $ fields -> id ) ? null : $ fields -> id ) ? 'user.action.register.displayName.taken' : true ; } | Is a display name available |
2,431 | public function status ( ) { $ auth = $ this -> getAuthenticationService ( ) ; $ loggedIn = $ auth -> hasIdentity ( ) ; $ identity = $ loggedIn ? $ auth -> getIdentity ( ) : null ; return ( object ) array ( 'loggedIn' => $ loggedIn , 'id' => $ loggedIn ? $ identity -> id : null , 'email' => $ loggedIn ? $ identity -> email : null , 'displayName' => $ loggedIn ? $ identity -> displayName : null , ) ; } | Get user status |
2,432 | public static function connect ( ConnectionParameters $ config ) { $ con = new self ( ) ; switch ( \ strtolower ( \ trim ( $ config -> getDriver ( ) ) ) ) { case 'sqlite' : $ con -> Connection = new \ PDO ( \ sprintf ( 'sqlite:%s' , $ config -> getHost ( ) ) , $ config -> getUsername ( ) , $ config -> getPassword ( ) , $ config -> getOptions ( ) ) ; break ; default : $ con -> Connection = new \ PDO ( \ sprintf ( '%s:host=%s;charset=%s;dbname=%s' , $ config -> getDriver ( ) ? $ config -> getDriver ( ) : '' , $ config -> getHost ( ) ? $ config -> getHost ( ) : '' , $ config -> getCharset ( ) ? $ config -> getCharset ( ) : '' , $ config -> getDatabaseName ( ) ? $ config -> getDatabaseName ( ) : '' ) , $ config -> getUsername ( ) , $ config -> getPassword ( ) , $ config -> getOptions ( ) ) ; break ; } return $ con ; } | Attempt to connect to the database . Does nothing if already connected . |
2,433 | public static function addIdpLogoUrls ( & $ sources , $ authSourcesConfig , $ metadataPath ) { $ idpMetadata = Metadata :: getIdpMetadataEntries ( $ metadataPath ) ; $ idpEntries = self :: getIdpsFromAuthSources ( $ authSourcesConfig ) ; foreach ( $ sources as & $ source ) { $ idpLabel = $ source [ 'source' ] ; $ idpEntityId = $ idpEntries [ $ idpLabel ] ; if ( ! isset ( $ idpMetadata [ $ idpEntityId ] ) ) { continue ; } $ idpMdEntry = $ idpMetadata [ $ idpEntityId ] ; if ( ! isset ( $ idpMdEntry [ Utils :: IDP_LOGO_KEY ] ) ) { continue ; } $ logoURL = $ idpMdEntry [ Utils :: IDP_LOGO_KEY ] ; $ logoURL = filter_var ( $ logoURL , FILTER_SANITIZE_URL ) ; $ source [ Utils :: IDP_LOGO_KEY ] = $ logoURL ; } } | Gets the logoURL entries from the IDP s metadata and adds them to the sources array that is available to the multiauth page . Doesn t add an entry at all if it is missing or invalid . |
2,434 | protected function initTrace ( int $ index , string $ trace ) : void { $ lines = explode ( ':' , $ trace , 2 ) ; $ headerKey = sprintf ( 'h%s' , $ index ) ; $ callKey = sprintf ( 'c%s' , $ index ) ; $ this -> templates [ ] = sprintf ( '<exception_trace:%s>' , $ headerKey ) ; $ this -> templates [ ] = sprintf ( "<exception_body:%s>\n" , $ callKey ) ; $ this -> replacements [ $ headerKey ] = $ lines [ 0 ] ; $ this -> replacements [ $ callKey ] = $ lines [ 1 ] ?? '' ; } | Inicializa los elementos deducidos de una linea de traza |
2,435 | public static function scan ( $ xml , DOMDocument $ dom = null ) { if ( self :: isPhpFpm ( ) ) { self :: heuristicScan ( $ xml ) ; } if ( null === $ dom ) { $ simpleXml = true ; $ dom = new DOMDocument ( ) ; } if ( ! self :: isPhpFpm ( ) ) { $ loadEntities = libxml_disable_entity_loader ( true ) ; $ useInternalXmlErrors = libxml_use_internal_errors ( true ) ; } set_error_handler ( array ( 'fproject\common\utils\XmlSecurity' , 'loadXmlErrorHandler' ) , E_WARNING ) ; $ result = $ dom -> loadXML ( $ xml , LIBXML_NONET ) ; restore_error_handler ( ) ; if ( ! $ result ) { if ( ! self :: isPhpFpm ( ) ) { libxml_disable_entity_loader ( $ loadEntities ) ; libxml_use_internal_errors ( $ useInternalXmlErrors ) ; } return false ; } if ( ! self :: isPhpFpm ( ) ) { foreach ( $ dom -> childNodes as $ child ) { if ( $ child -> nodeType === XML_DOCUMENT_TYPE_NODE ) { if ( $ child -> entities -> length > 0 ) { throw new Exception ( self :: ENTITY_DETECT ) ; } } } } if ( ! self :: isPhpFpm ( ) ) { libxml_disable_entity_loader ( $ loadEntities ) ; libxml_use_internal_errors ( $ useInternalXmlErrors ) ; } if ( isset ( $ simpleXml ) ) { $ result = simplexml_import_dom ( $ dom ) ; if ( ! $ result instanceof SimpleXMLElement ) { return false ; } return $ result ; } return $ dom ; } | Scan XML string for potential XXE and XEE attacks |
2,436 | protected function _getArgsStack ( array & $ args = array ( ) , $ scope = null , $ default = array ( ) , $ unset = true ) { $ found_args = $ default ; if ( isset ( $ args [ $ scope ] ) ) { $ found_args = $ args [ $ scope ] ; if ( true === $ unset ) { unset ( $ args [ $ scope ] ) ; } } return $ found_args ; } | Find a specific entry in arguments and unset it |
2,437 | protected function _doList ( & $ content , array & $ args = array ( ) , $ tag_type = 'unordered_list' ) { $ items_content = '' ; $ items_args = $ this -> _getArgsStack ( $ args , 'items' ) ; $ i = 0 ; foreach ( $ content as $ i => $ item_str ) { $ item_args = array_merge_recursive ( $ items_args , $ this -> _getArgsStack ( $ args , 'item' . $ i ) ) ; $ items_content .= $ this -> _tagComposer ( $ item_str , $ tag_type . '_item' , $ item_args ) ; $ i ++ ; } $ content = $ items_content ; } | Process a list content |
2,438 | protected function _doDefinitions ( & $ content , array & $ args = array ( ) ) { $ items_content = '' ; $ terms_args = $ this -> _getArgsStack ( $ args , 'term' ) ; $ descriptions_args = $ this -> _getArgsStack ( $ args , 'description' ) ; $ i = 0 ; foreach ( $ content as $ term => $ def ) { $ term_args = array_merge_recursive ( $ terms_args , $ this -> _getArgsStack ( $ args , 'term' . $ i ) ) ; $ description_args = array_merge_recursive ( $ descriptions_args , $ this -> _getArgsStack ( $ args , 'description' . $ i ) ) ; $ items_content .= $ this -> _tagComposer ( $ term , 'definition_term' , $ term_args ) . $ this -> _tagComposer ( $ def , 'definition_description' , $ description_args ) ; $ i ++ ; } $ content = $ items_content ; } | Process a definitions list content |
2,439 | protected function _doTable ( & $ content , array & $ args = array ( ) ) { $ table = new TableTool ( isset ( $ content [ 'body' ] ) && is_array ( $ content [ 'body' ] ) ? $ content [ 'body' ] : array ( $ content ) , isset ( $ content [ 'head' ] ) && is_array ( $ content [ 'head' ] ) ? $ content [ 'head' ] : array ( ) , isset ( $ content [ 'foot' ] ) && is_array ( $ content [ 'foot' ] ) ? $ content [ 'foot' ] : array ( ) ) ; $ table_stacks = $ table -> getTable ( ) ; $ table_content = '' ; foreach ( self :: $ table_scopes as $ scope ) { $ scope_lines = '' ; if ( isset ( $ table_stacks [ $ scope ] ) && is_array ( $ table_stacks [ $ scope ] ) && ! empty ( $ table_stacks [ $ scope ] ) ) { $ my_line = '' ; foreach ( $ table_stacks [ $ scope ] as $ line ) { $ this -> _doTableLine ( $ line , $ args , $ scope ) ; $ my_line .= $ line ; } $ scope_lines .= $ my_line ; } $ scope_args = $ this -> _getArgsStack ( $ args , $ scope ) ; $ scope_tag = 'table_' . $ scope ; $ table_content .= $ this -> _tagComposer ( $ scope_lines , $ scope_tag , $ scope_args ) ; } if ( isset ( $ table_stacks [ 'title' ] ) ) { $ caption_args = $ this -> _getArgsStack ( $ args , 'title' ) ; $ caption_tag = 'table_title' ; $ caption = $ this -> _tagComposer ( $ table_stacks [ 'title' ] , $ caption_tag , $ caption_args ) ; $ table_content = $ caption . $ table_content ; } $ this -> _purgeArgsStackForTable ( $ args , 'cell' ) ; $ this -> _purgeArgsStackForTable ( $ args , 'line' ) ; $ content = $ table_content ; } | Process a table content |
2,440 | protected function _doTableLine ( & $ content , array & $ args = array ( ) , $ scope = 'body' ) { $ my_line = '' ; $ cell_args = $ this -> _getArgsStackForTable ( $ args , 'cell' , $ scope ) ; $ cell_tag = 'table_' . $ scope . '_cell' ; foreach ( $ content as $ cell ) { $ my_line .= $ this -> _tagComposer ( $ cell , $ cell_tag , $ cell_args ) ; } $ line_args = $ this -> _getArgsStackForTable ( $ args , 'line' , $ scope ) ; $ line_tag = 'table_' . $ scope . '_line' ; $ content = $ this -> _tagComposer ( $ my_line , $ line_tag , $ line_args ) ; } | Process a table line |
2,441 | protected function _getArgsStackForTable ( array & $ args , $ entry , $ scope ) { $ found_args = array ( ) ; $ global_args = $ this -> _getArgsStack ( $ args , $ entry , array ( ) , false ) ; if ( ! empty ( $ global_args ) ) { if ( array_key_exists ( $ scope , $ global_args ) ) { $ found_args = $ this -> _getArgsStack ( $ args [ $ entry ] , $ scope , array ( ) , false ) ; } else { $ scope_defined = false ; foreach ( self :: $ table_scopes as $ _scope ) { if ( array_key_exists ( $ _scope , $ global_args ) ) { $ scope_defined = true ; } } if ( false === $ scope_defined ) { $ found_args = $ this -> _getArgsStack ( $ args , $ entry , array ( ) , false ) ; } } } return $ found_args ; } | Fallback system to find a specific entry in arguments for table scopes |
2,442 | public function importCookies ( ) { foreach ( $ this -> cookies as $ cookie ) { if ( ! empty ( $ cookie -> getValue ( ) ) ) { setcookie ( $ cookie -> getName ( ) , $ cookie -> getValue ( ) , $ cookie -> getExpires ( ) , $ cookie -> getPath ( ) , $ cookie -> getDomain ( ) , $ cookie -> getSecure ( ) ?? false , $ cookie -> getHttpOnly ( ) ) ; } else { unset ( $ _COOKIE [ $ cookie [ "name" ] ] ) ; setcookie ( $ cookie [ "name" ] , null , time ( ) - 3600 ) ; } } } | Imports the cookies from the HTTP response . If the cookie already exists it is replaced by the value in the HTTP response . |
2,443 | public static function getPrimaryModel ( $ models ) { if ( empty ( $ models ) ) { return false ; } \ d ( $ models ) ; exit ; foreach ( $ models as $ tabKey => $ model ) { if ( $ tabKey === static :: getPrimaryTabularId ( static :: baseClassName ( ) ) ) { return $ model ; } } return false ; } | Get primary model . |
2,444 | public function getCacheSize ( ) { $ n = 0 ; foreach ( static :: $ _cache as $ model => $ cache ) { $ n += count ( $ cache ) ; } return $ n ; } | Get cache size . |
2,445 | public function getSortOptions ( ) { $ options = [ ] ; $ descriptorSort = [ ] ; $ modelDescriptorFields = $ this -> descriptorField ; if ( ! is_array ( $ modelDescriptorFields ) ) { $ modelDescriptorFields = [ $ modelDescriptorFields ] ; } foreach ( $ modelDescriptorFields as $ field ) { if ( $ this -> hasAttribute ( $ field ) ) { $ descriptorSort [ $ field ] = SORT_ASC ; } } if ( ! empty ( $ descriptorSort ) ) { $ options [ $ this -> descriptorLabel ] = $ descriptorSort ; } if ( empty ( $ options ) && $ this -> hasAttribute ( 'created' ) ) { $ options [ 'Created' ] = [ 'created' => SORT_ASC ] ; } return $ options ; } | Get sort options . |
2,446 | public function getDescriptorDefaultOrder ( $ alias = '{alias}' , $ order = SORT_ASC ) { $ descriptorField = $ this -> descriptorField ; if ( ! is_array ( $ descriptorField ) ) { $ descriptorField = [ $ descriptorField ] ; } $ descriptorField = array_reverse ( $ descriptorField ) ; $ sortBy = [ ] ; foreach ( $ descriptorField as $ field ) { if ( ! $ this -> hasAttribute ( $ field ) ) { continue ; } $ sortBy [ $ alias . '.' . $ field ] = $ order ; } return $ sortBy ; } | Get descriptor default order . |
2,447 | public function getDefaultOrder ( $ alias = 't' ) { if ( is_null ( $ this -> _defaultOrder ) ) { $ this -> _defaultOrder = $ this -> getDescriptorDefaultOrder ( '{alias}' ) ; } $ sortBy = [ ] ; foreach ( $ this -> _defaultOrder as $ key => $ value ) { $ sortBy [ strtr ( $ key , [ '{alias}' => $ alias ] ) ] = $ value ; } return $ sortBy ; } | Get default order . |
2,448 | public function getPrimarySubdescriptor ( $ context = null ) { $ subdescriptor = [ ] ; foreach ( $ this -> getSubdescriptor ( $ context ) as $ subValue ) { if ( ! empty ( $ subValue ) ) { if ( is_array ( $ subValue ) && isset ( $ subValue [ 'plain' ] ) ) { $ subdescriptor [ ] = $ subValue [ 'plain' ] ; } elseif ( is_array ( $ subValue ) && isset ( $ subValue [ 'rich' ] ) ) { $ subdescriptor [ ] = strip_tags ( $ subValue [ 'rich' ] ) ; } elseif ( is_string ( $ subValue ) || is_numeric ( $ subValue ) ) { $ subdescriptor [ ] = strip_tags ( $ subValue ) ; } } } return isset ( $ subdescriptor [ 0 ] ) ? $ subdescriptor [ 0 ] : null ; } | Get primary subdescriptor . |
2,449 | public function getLocalFieldValue ( $ field , $ options = [ ] , $ context = null , $ formatted = true ) { if ( isset ( $ this -> { $ field } ) ) { return $ this -> { $ field } ; } return ; } | Get local field value . |
2,450 | public function getPackage ( $ urlAction = 'view' ) { $ p = [ ] ; $ p [ 'id' ] = $ this -> primaryKey ; $ p [ 'descriptor' ] = $ this -> descriptor ; $ p [ 'url' ] = false ; if ( method_exists ( $ this , 'getUrl' ) ) { $ p [ 'url' ] = Url :: to ( $ this -> getUrl ( $ urlAction ) ) ; } return $ p ; } | Get package . |
2,451 | public function createRedirect ( $ from , $ to , $ permanent = false ) { $ route = new Route ( $ from , function ( Request $ request , Response $ response ) use ( $ from , $ to , $ permanent ) { $ urlVariables = VariableUrl :: extractUrlVariables ( $ request -> getRequestUri ( ) , $ to ) ; if ( ! empty ( $ urlVariables ) ) { $ to = VariableUrl :: applyUrlVariables ( $ to , $ urlVariables ) ; } $ response -> doRedirect ( $ to , $ permanent ) ; } ) ; $ this -> register ( $ route ) ; return $ route ; } | Creates and registers a new redirection route . |
2,452 | public function setSubdirectory ( $ subdirectory ) { $ this -> subdirectory = $ subdirectory ; foreach ( $ this -> routes as $ route ) { $ route -> setSubdirectory ( $ subdirectory ) ; } return $ this ; } | Sets the base subdirectory for all requests processed by this router . |
2,453 | public function getOptions ( Request $ request ) { $ routes = [ ] ; foreach ( $ this -> routes as $ route ) { if ( $ route -> matchesPattern ( $ request ) ) { $ routes [ ] = $ route ; } } return $ routes ; } | Gets all routing options for a given request . |
2,454 | public function dispatch ( Route $ route , Request $ request = null ) { $ context = $ this -> context ; if ( empty ( $ this -> context ) && ! empty ( $ request ) ) { $ context = new Context ( ) ; $ context -> registerInstance ( $ request ) ; } if ( ! empty ( $ context ) ) { $ context -> registerInstance ( $ route ) ; if ( ! empty ( $ request ) ) { $ pathVariables = VariableUrl :: extractUrlVariables ( $ request -> getRequestUri ( ) , $ route -> getPattern ( ) ) ; foreach ( $ pathVariables as $ name => $ value ) { $ context -> registerVariable ( $ name , $ value ) ; } } } return $ route -> action ( $ context ) ; } | Dispatches a Route executing its action . |
2,455 | protected function getParameterValueForCommand ( $ command , ArrayAccess $ source , ReflectionParameter $ parameter , array $ extras = array ( ) ) { if ( array_key_exists ( $ parameter -> name , $ extras ) ) { return $ extras [ $ parameter -> name ] ; } if ( isset ( $ source [ $ parameter -> name ] ) ) { return $ source [ $ parameter -> name ] ; } if ( $ parameter -> isDefaultValueAvailable ( ) ) { return $ parameter -> getDefaultValue ( ) ; } MarshalException :: whileMapping ( $ command , $ parameter ) ; } | Get a parameter value for a marshaled command . |
2,456 | public function hydrateObject ( $ targetObject , $ payload ) { if ( ! $ payload ) { return $ targetObject ; } if ( is_object ( $ payload ) || is_array ( $ payload ) ) { foreach ( $ payload as $ param => $ value ) { if ( is_int ( $ param ) ) { foreach ( $ value as $ par => $ val ) { $ setter = $ this -> prefixer ( self :: PREFIX_ADDER , $ par ) ; $ this -> hydrateMethod ( $ targetObject , $ setter , $ val ) ; } continue ; } $ setter = $ this -> prefixer ( self :: PREFIX_SETTER , $ param ) ; $ this -> hydrateMethod ( $ targetObject , $ setter , $ value ) ; } } return $ targetObject ; } | Hydrate Object . |
2,457 | protected function hydrateCollection ( $ object , $ valueArray ) { if ( ! method_exists ( $ object , 'getValueClass' ) || ! method_exists ( $ object , 'setCollection' ) ) { return $ object ; } $ collection = [ ] ; $ class = $ object -> getValueClass ( ) ; if ( class_exists ( $ class ) ) { foreach ( $ valueArray as $ key => $ value ) { $ dryItem = new $ class ( ) ; $ item = $ this -> hydrateObject ( $ dryItem , $ value ) ; $ collection [ $ key ] = $ item ; } } $ object -> setCollection ( $ collection ) ; return $ object ; } | Hydrate Collection . |
2,458 | protected function hydrateMethod ( $ targetObject , $ method , $ value ) { if ( method_exists ( $ targetObject , $ method ) ) { $ dryObject = $ this -> getParameterClassObject ( $ targetObject , $ method ) ; if ( $ dryObject && is_object ( $ dryObject ) ) { $ hydratedObject = null ; if ( method_exists ( $ dryObject , 'setCollection' ) && method_exists ( $ dryObject , 'getValueClass' ) ) { $ hydratedObject = $ this -> hydrateCollection ( $ dryObject , $ value ) ; } if ( ! $ hydratedObject ) { $ hydratedObject = $ this -> hydrateObject ( $ dryObject , $ value ) ; } $ targetObject -> $ method ( $ hydratedObject ) ; return ; } if ( $ value && is_object ( $ value ) ) { $ value = ( array ) $ value ; } $ targetObject -> $ method ( $ value ) ; } } | Hydrate Method . |
2,459 | public function getParameterClassObject ( $ object , $ method ) { $ reflectionClass = new \ ReflectionClass ( get_class ( $ object ) ) ; $ parameters = $ reflectionClass -> getMethod ( $ method ) -> getParameters ( ) ; if ( $ parameters && isset ( $ parameters [ 0 ] ) ) { $ refClass = $ parameters [ 0 ] -> getClass ( ) ; if ( $ refClass ) { $ class = $ refClass -> getName ( ) ; return new $ class ( ) ; } } } | Get Parameter Class Object . |
2,460 | public function uploadString ( $ name , $ content , $ contentType = 'text/plain' ) { $ fileName = $ this -> path . '/' . $ this -> getFilePathAndUniquePrefix ( ) . $ name ; if ( $ contentType === 'application/json' ) { $ content = Json :: prettyPrint ( $ content ) ; } ( new Filesystem ) -> dumpFile ( $ fileName , $ content ) ; return $ fileName ; } | Writes log message to file |
2,461 | public function css ( $ file = false , $ theme = null ) { $ this -> secondaryTheme ( $ theme ) ; $ css = $ this -> enqueueFiles ( $ file , $ this -> container -> getCSS ( ) , 'css' ) ; if ( is_string ( $ css ) ) return $ css ; foreach ( $ css as $ value ) { $ value = $ this -> buildPublicTmp ( $ value ) ; print '<link rel="stylesheet" type="text/css" href="' . Filter :: httpPublicTmp ( $ value ) . '"/>' . PHP_EOL ; } } | Include all files . css |
2,462 | public function js ( $ file = false , $ theme = null ) { $ this -> secondaryTheme ( $ theme ) ; $ js = $ this -> enqueueFiles ( $ file , $ this -> container -> getJS ( ) , 'js' ) ; if ( is_string ( $ js ) ) return $ js ; foreach ( $ js as $ value ) { $ value = $ this -> buildPublicTmp ( $ value ) ; print '<script type="text/javascript" src="' . Filter :: httpPublicTmp ( $ value ) . '"></script>' . PHP_EOL ; } } | Include all files . js |
2,463 | public function img ( $ file , $ ext = null , $ theme = null ) { $ this -> secondaryTheme ( $ theme ) ; $ img = $ this -> enqueueFiles ( $ file , $ this -> container -> getIMG ( ) , $ ext ) ; return $ img ; } | Include files of images |
2,464 | public function assets ( $ file , $ lib = null , $ theme = null ) { $ this -> secondaryTheme ( $ theme ) ; $ assets = $ this -> enqueueFiles ( $ file , $ this -> container -> getFolderAssets ( $ lib ) ) ; return $ assets ; } | Include files of folder assets |
2,465 | public function enqueue ( $ file , $ theme = null ) { $ this -> secondaryTheme ( $ theme ) ; $ stack = $ this -> enqueueFiles ( $ file , $ this -> container -> getMainFolder ( ) . "/" . $ this -> container -> getThemeActivated ( ) ) ; return $ stack ; } | Include any file |
2,466 | protected function secondaryTheme ( $ theme = null ) { if ( $ theme ) { $ this -> origin = $ this -> container -> getThemeActivated ( ) ; $ this -> container -> setThemeActivated ( $ theme ) ; } } | Configuration of theme secondary |
2,467 | protected function destroySecondaryTheme ( ) { if ( $ this -> origin ) $ this -> container -> setThemeActivated ( $ this -> origin ) ; $ this -> origin = null ; } | Destroy theme secondary |
2,468 | public function buildPublicTmp ( $ path ) { $ repository = $ this -> themeRepository ( ) ; $ repository = Filter :: realPath ( $ repository ) ; $ repository_tmp = $ this -> getFolderTmpTheme ( ) ; $ pos = strpos ( $ path , $ repository ) ; if ( $ pos === 0 ) return $ repository_tmp . substr ( $ path , strlen ( $ repository ) ) ; return $ path ; } | Generate folder to files temporary of themes |
2,469 | private static function getFromSession ( ) { if ( empty ( $ _SESSION [ 'current_user' ] ) ) { $ entityClassName = static :: ENTITIES_CLASS_NAME ; $ user = new $ entityClassName ( array ( 'source' => 'cookie' , ) ) ; self :: setCurrent ( $ user ) ; } else { Logger :: get ( ) -> debug ( 'Found user in session.' ) ; if ( time ( ) > ( $ _SESSION [ 'timestamp' ] + + self :: SESSION_DURATION ) ) { Logger :: get ( ) -> debug ( 'Regenerated session ID.' ) ; session_regenerate_id ( ) ; } } return $ _SESSION [ 'current_user' ] ; } | Obtains a user reference from a cookie . |
2,470 | public static function getFromIdentityProvider ( Provider $ identityProvider ) { $ identityProvider -> authenticate ( ) ; $ userId = $ identityProvider -> getUserId ( ) ; try { Logger :: get ( ) -> debug ( sprintf ( 'Checking OpenID user %s...' , $ userId ) ) ; $ user = Users :: getInstance ( ) -> findEntity ( $ userId ) ; $ user -> authenticate ( $ identityProvider ) ; } catch ( NotFoundException $ exception ) { Logger :: get ( ) -> warning ( sprintf ( 'OpenID user %s is not known.' , $ userId ) ) ; throw new NotAuthorisedException ( 'OpenID user is not authorised.' ) ; } return $ user ; } | Use the specified identity provider to establish an authenticated user . |
2,471 | private function _load ( $ pClassName ) { if ( array_key_exists ( $ pClassName , self :: $ _aliases ) ) { return class_alias ( self :: $ _aliases [ $ pClassName ] , $ pClassName ) ; } if ( strpos ( $ pClassName , self :: AGL_POOL ) === 0 ) { $ path = self :: _loadFromAgl ( $ pClassName ) ; $ realPath = AGL_PATH . $ path . Agl :: PHP_EXT ; } else { $ realPath = self :: _loadFromApp ( $ pClassName ) ; } if ( $ realPath and is_readable ( $ realPath ) ) { require ( $ realPath ) ; } } | Load class file if exists . |
2,472 | private static function _loadFromApp ( $ pClassName ) { $ classNameArr = explode ( '_' , StringData :: fromCamelCase ( $ pClassName ) ) ; $ pool = array_pop ( $ classNameArr ) ; return APP_PATH . Agl :: APP_PHP_DIR . $ pool . DS . implode ( DS , $ classNameArr ) . Agl :: PHP_EXT ; } | Retrieve the class path in the application pool . |
2,473 | public function hasChildren ( ) { $ item = $ this -> data [ $ this -> keys [ $ this -> position ] ] ; return ( is_object ( $ item ) && $ item instanceof \ Octris \ Db \ Type \ SubObject ) ; } | Returns if an iterator can be created fot the current item . |
2,474 | protected function loadRules ( ) { $ old_cwd = getcwd ( ) ; chdir ( __DIR__ ) ; $ path = 'Validate' . DIRECTORY_SEPARATOR . 'Rules' ; if ( ! is_dir ( $ path ) ) { throw new ValidateException ( "Rules Directory " . $ path . " isn't a directory..." ) ; } $ files = new \ RecursiveIteratorIterator ( new \ RecursiveDirectoryIterator ( $ path ) , \ RecursiveIteratorIterator :: LEAVES_ONLY ) ; foreach ( $ files as $ file ) { if ( ! $ file -> isDir ( ) ) { $ name = '\\JaegerApp\\' . str_replace ( '/' , '\\' , str_replace ( '.php' , '' , $ file -> getPathname ( ) ) ) ; $ class = $ name ; if ( class_exists ( $ class ) ) { $ rule = new $ class ( ) ; if ( $ rule instanceof Validate \ RuleInterface ) { self :: addRule ( $ rule -> getName ( ) , array ( $ rule , 'validate' ) , $ rule -> getErrorMessage ( ) ) ; } } } } chdir ( $ old_cwd ) ; } | Adds all the custom rules |
2,475 | public function val ( array $ data ) { $ this -> _fields = $ data ; $ labels = array ( ) ; foreach ( $ data as $ key => $ value ) { $ labels [ $ key ] = ucwords ( str_replace ( '_' , ' ' , $ key ) ) ; } $ this -> labels ( $ labels ) ; return parent :: validate ( ) ; } | Processes the validation group |
2,476 | public static function thumb ( $ path , array $ params , Template $ template ) { if ( empty ( $ path ) ) { if ( empty ( $ params [ 'dummy' ] ) ) { return '' ; } $ path = $ params [ 'dummy' ] ; } $ const = Helper :: getValue ( $ params [ 'const' ] , 1 , true ) ; $ imageProvider = Instance :: ensure ( isset ( $ params [ 'imageProvider' ] ) ? $ params [ 'imageProvider' ] : 'imageProvider' ) ; $ src = $ imageProvider -> get ( $ path , Helper :: getValue ( $ params [ 'w' ] ) , Helper :: getValue ( $ params [ 'h' ] ) ) ; if ( ! ( $ const & ThumbInterface :: WITHOUT_WIDTH_HEIGHT ) ) { $ params [ 'width' ] = $ imageProvider -> width ; $ params [ 'height' ] = $ imageProvider -> height ; } unset ( $ params [ 'h' ] , $ params [ 'w' ] , $ params [ 'type' ] , $ params [ 'const' ] ) ; if ( ! empty ( $ params [ 'alt' ] ) ) { $ params [ 'alt' ] = $ template -> replace ( $ params [ 'alt' ] ) ; } return $ const & ThumbInterface :: OUTPUT_IMG ? Html :: img ( $ src , $ params ) : $ src ; } | Get thumb . |
2,477 | private function _prepareCondition ( ConditionInterface $ condition = null ) { $ this -> condition = $ this -> expressionBuilderFactory -> create ( $ condition ) -> build ( ) ; } | Fill the property condition in a well format for the process method . |
2,478 | private function _prepareOrderBy ( array $ orderByArray ) { if ( count ( $ orderByArray ) === 1 ) { foreach ( $ orderByArray as $ orderMode => $ column ) { $ this -> orderBy = 'ORDER BY ' . $ column -> getColumnName ( ) . ' ' . $ orderMode . ' ' ; } } } | Fill the property orderBy in a well format for the process method . |
2,479 | public static function registerNamespace ( $ namespace , $ directory , $ extension = '.php' , $ prioritize = false ) { if ( self :: $ _namespaces === null ) { self :: $ _namespaces = array ( ) ; } $ directory = str_replace ( '\\' , '/' , realpath ( $ directory ) ) . '/' ; if ( $ prioritize ) { array_unshift ( self :: $ _namespaces , array ( $ namespace , $ directory , strlen ( $ namespace ) , $ extension ) ) ; } else { self :: $ _namespaces [ ] = array ( $ namespace , $ directory , strlen ( $ namespace ) , $ extension ) ; } } | Registers a namespace for auto loading . |
2,480 | public static function onAutoLoad ( $ class ) { if ( isset ( self :: $ customMappings [ $ class ] ) ) { require_once ( self :: $ customMappings [ $ class ] ) ; return true ; } if ( self :: $ _namespaces !== null ) { foreach ( self :: $ _namespaces as $ data ) { $ ns = $ data [ 0 ] ; $ nsl = $ data [ 2 ] ; if ( substr ( $ class , 0 , $ nsl ) !== $ ns ) { continue ; } $ dir = $ data [ 1 ] ; $ ext = $ data [ 3 ] ; $ file = $ dir . str_replace ( '\\' , '/' , substr ( $ class , $ nsl ) ) . $ ext ; if ( is_file ( $ file ) ) { require_once ( $ file ) ; return true ; } } } return false ; } | Will be called by PHP to invoke the auto loader . |
2,481 | protected function findOS ( ) { if ( isset ( $ this -> os ) ) return $ this -> os ; switch ( true ) { case stristr ( PHP_OS , 'DAR' ) : return $ this -> os = static :: OS_OSX ; case stristr ( PHP_OS , 'WIN' ) : return $ this -> os = static :: OS_WIN ; case stristr ( PHP_OS , 'LINUX' ) : return $ this -> os = static :: OS_LINUX ; default : return $ this -> os = static :: OS_OTHER ; } } | Figure out which operating system we re running on |
2,482 | public function get ( $ key = null , $ default = null ) { if ( is_null ( $ key ) ) { return $ this -> config ; } if ( isset ( $ this -> config [ $ key ] ) ) { return $ this -> config [ $ key ] ; } $ tmp = $ this -> config ; foreach ( explode ( '.' , $ key ) as $ segment ) { if ( ! is_array ( $ tmp ) || ! array_key_exists ( $ segment , $ tmp ) ) { return $ default ; } $ tmp = $ tmp [ $ segment ] ; } return $ tmp ; } | Get the value for the key using dot expansion . |
2,483 | protected function parse ( ) { $ sectionName = static :: GLOBAL_SECTION ; $ values = [ ] ; try { while ( $ line = fgets ( $ this -> handle ) ) { $ this -> linenumber ++ ; $ line = trim ( $ line ) ; if ( empty ( $ line ) || substr ( $ line , 0 , 1 ) === ';' ) { continue ; } if ( $ this -> isSectionHeader ( $ line ) ) { if ( $ sectionName === static :: GLOBAL_SECTION ) { $ this -> config = $ values ; } else { $ tokens = explode ( $ this -> delimiter , $ sectionName ) ; $ this -> config = array_merge_recursive ( $ this -> config , $ this -> subdivide ( $ tokens , $ values ) ) ; unset ( $ tokens ) ; } $ sectionName = $ this -> getSectionHeader ( $ line ) ; $ values = [ ] ; continue ; } list ( $ key , $ value ) = array_pad ( preg_split ( static :: SPLIT_PATTERN , trim ( $ line ) , 2 ) , 2 , '' ) ; if ( $ this -> isArrayKey ( $ key ) ) { if ( is_null ( $ array_key = $ this -> parseArrayKey ( $ key ) ) ) { $ key = trim ( trim ( $ key ) , '[]' ) ; $ values [ $ key ] [ ] = $ this -> parseValue ( $ value ) ; } else { $ key = trim ( substr ( $ key , 0 , strpos ( $ key , '[' ) ) ) ; if ( ! isset ( $ values [ $ key ] ) ) { $ values [ $ key ] = [ ] ; } $ values [ $ key ] [ $ array_key ] = $ this -> parseValue ( $ value ) ; } } else { $ values [ trim ( $ key ) ] = $ this -> parseValue ( $ value ) ; } } } catch ( \ Exception $ ex ) { throw new \ RuntimeException ( "{$ex->getMessage()} Line: {$this->linenumber}." ) ; } finally { $ this -> close ( ) ; } if ( $ sectionName === static :: GLOBAL_SECTION ) { $ this -> config = $ values ; } else { $ section = $ this -> subdivide ( explode ( $ this -> delimiter , $ sectionName ) , $ values ) ; $ this -> config = array_merge ( $ this -> config , $ section ) ; } } | Parse the ini file . |
2,484 | protected function parseValue ( $ value ) { if ( $ this -> isQuoted ( $ value ) ) { return trim ( preg_replace ( static :: ESCAPED_QUOTE_PATTERN , '\1' , $ value ) , static :: QUOTE_CHARS ) ; } elseif ( $ this -> opensQuote ( $ value ) ) { $ value = $ this -> parseMultilineValue ( ltrim ( $ value , static :: QUOTE_CHARS ) ) ; if ( $ value === false ) { throw new \ RuntimeException ( 'Error parsing ini.' ) ; } return $ value ; } elseif ( is_numeric ( $ value ) ) { if ( strpos ( $ value , '.' ) !== false ) { return floatval ( $ value ) ; } return intval ( $ value ) ; } elseif ( in_array ( strtolower ( $ value ) , [ 'true' , 'false' ] ) ) { return ( strtolower ( $ value ) === 'true' ) ; } else { return $ value ; } } | Parse the value for a key . |
2,485 | protected function parseMultilineValue ( $ seed = '' ) { $ closed = false ; $ lines = empty ( $ seed ) ? [ ] : [ $ seed ] ; while ( $ line = fgets ( $ this -> handle ) ) { $ line = trim ( $ line ) ; $ this -> linenumber ++ ; if ( $ this -> closesQuote ( $ line ) ) { $ closed = true ; $ lines [ ] = rtrim ( $ line , static :: QUOTE_CHARS ) ; break ; } else { $ lines [ ] = "$line\n" ; } unset ( $ trimmed ) ; } return ( $ closed ) ? join ( "\n" , $ lines ) : false ; } | Parse a multiline string value . |
2,486 | protected function parseArrayKey ( $ key ) { preg_match ( static :: ARRAY_KEY_PATTERN , $ key , $ matches ) ; return ( isset ( $ matches [ 'array_key' ] ) ? $ matches [ 'array_key' ] : null ) ; } | Parse associative array key from ini array key value . |
2,487 | protected function subdivide ( $ sections , $ value ) { if ( empty ( $ sections ) ) { return $ value ; } $ section = array_shift ( $ sections ) ; return [ $ section => $ this -> subdivide ( $ sections , $ value ) , ] ; } | Expand delimited section headers into nested arrays . |
2,488 | protected function getContentType ( ResponseInterface $ response ) { if ( $ response -> hasHeader ( 'Content-Type' ) ) { $ header = $ response -> getHeaderLine ( 'Content-Type' ) ; $ parts = explode ( ';' , $ header ) ; return trim ( $ parts [ 0 ] ) ; } return null ; } | Check if the request has an attribute set with a mime type that should be used . This is typically a result of content negotiation . If no attribute exists check for an accept header instead . |
2,489 | private function rearrangeHostHeaderKey ( ) { if ( ! isset ( $ this -> headers [ 'Host' ] ) ) { return ; } $ tmp = $ this -> headers [ 'Host' ] ; $ keys = array_keys ( $ this -> headers ) ; $ hostIndex = array_search ( 'Host' , $ keys , true ) ; if ( false === $ hostIndex ) { return ; } array_splice ( $ this -> headers , $ hostIndex , 1 ) ; $ this -> headers = [ 'Host' => $ tmp ] + $ this -> headers ; } | Rearrange Host value of current HTTP header into first entry . |
2,490 | private function changeHostFromUri ( ) { $ host = $ this -> uri -> getHost ( ) ; if ( $ host === '' ) { return ; } if ( ( $ port = $ this -> uri -> getPort ( ) ) !== null ) { $ host .= ':' . $ port ; } $ this -> headers [ 'Host' ] = [ $ host ] ; $ this -> rearrangeHostHeaderKey ( ) ; } | If this object is considered immutable and original host is not preserved better change it to the new one . |
2,491 | protected function clean ( $ values , $ reverse = true ) { $ clean = array_diff_key ( $ this -> config , array_flip ( self :: $ options ) ) ; return $ reverse ? array_merge ( $ values , $ clean ) : array_merge ( $ clean , $ values ) ; } | Removes additional configuration keys from a list of values |
2,492 | protected function getListMappingExpression ( ) { $ group = $ this -> hasOption ( 'query.group' ) ? $ this -> getOption ( 'query.group' ) : null ; $ index = $ this -> hasOption ( 'query.index' ) ? $ this -> getOption ( 'query.index' ) : null ; return $ this -> buildListExpression ( $ this -> entityProfile , $ index , $ group ) ; } | Obtains a list mapping expression for the current configuration |
2,493 | protected function getSelectColumns ( ) { if ( $ this -> hasOption ( 'query.attrs' ) ) { $ columns = [ ] ; foreach ( $ this -> getOption ( 'query.attrs' ) as $ attr ) { if ( $ attr instanceof Attr ) $ name = $ attr -> getName ( ) ; elseif ( is_string ( $ attr ) ) $ name = $ attr ; else throw new \ InvalidArgumentException ( "Method 'attrs' expects a list of strings or instances of \eMapper\Query\Attr" ) ; if ( ! $ this -> entityProfile -> hasProperty ( $ name ) ) throw new \ InvalidArgumentException ( sprintf ( "Attribute '%s' not found in class '%s'" , $ name , $ this -> entityProfile -> getReflectionClass ( ) -> getName ( ) ) ) ; $ column = $ this -> entityProfile -> getProperty ( $ name ) -> getColumn ( ) ; if ( ! array_key_exists ( $ column , $ columns ) ) $ columns [ $ column ] = new Column ( $ column ) ; } return $ columns ; } return $ this -> selectColumns ; } | Obtains a list of Column instances with the list of columns to fetch |
2,494 | protected function getFilter ( ) { $ filter = $ this -> getOption ( 'query.filter' ) ; $ negate = false ; if ( $ this -> hasOption ( 'query.negate' ) ) $ negate = ( bool ) $ this -> getOption ( 'query.negate' ) ; if ( is_array ( $ filter ) ) return new Filter ( $ filter , $ negate ) ; return new Filter ( [ $ filter ] , $ negate ) ; } | Obtains configured filter |
2,495 | protected function getOrderBy ( ) { $ order = [ ] ; foreach ( $ this -> getOption ( 'query.orderBy' ) as $ attr ) { $ type = null ; if ( $ attr instanceof Attr ) { $ name = $ attr -> getName ( ) ; $ type = $ attr -> getType ( ) ; } elseif ( is_string ( $ attr ) ) { $ expr = explode ( ' ' , $ attr ) ; $ name = $ expr [ 0 ] ; if ( count ( $ expr ) > 1 ) { $ type = strtolower ( $ expr [ 1 ] ) ; if ( $ type != 'asc' && $ type != 'desc' ) $ type = null ; } } else throw new \ InvalidArgumentException ( "Invalid order attribute defined: Expected a string or \eMapper\Query\Attr instance" ) ; $ order [ ] = Attr :: __callstatic ( $ name ) -> type ( $ type ) ; } return $ order ; } | Obtains the list of ordering columns |
2,496 | public function index ( $ index = null ) { if ( is_null ( $ index ) ) return $ this -> discard ( 'query.index' ) ; if ( $ index instanceof Column ) { $ map = $ this -> entityProfile -> getPropertyMap ( ) ; if ( ! in_array ( $ index -> getName ( ) , $ map ) ) throw new \ InvalidArgumentException ( sprintf ( "Column '%s' is unknown for class '%s'" , $ index -> getName ( ) , $ this -> entityProfile -> getReflectionClass ( ) -> getName ( ) ) ) ; $ name = array_flip ( $ map ) [ $ index -> getName ( ) ] ; } elseif ( $ index instanceof Attr ) $ name = $ index -> getName ( ) ; elseif ( is_string ( $ index ) ) $ name = $ index ; else throw new \ InvalidArgumentException ( "Index must be specified through an Attr instance or a valid property name" ) ; $ type = ( $ index instanceof Field ) ? $ index -> getType ( ) : null ; if ( isset ( $ type ) ) return $ this -> merge ( [ 'query.index' => $ name . ':' . $ type ] ) ; return $ this -> merge ( [ 'query.index' => $ name ] ) ; } | Sets index attribute |
2,497 | public function group ( $ group = null ) { if ( is_null ( $ group ) ) return $ this -> discard ( 'query.group' ) ; if ( $ group instanceof Column ) { $ map = $ this -> entityProfile -> getPropertyMap ( ) ; if ( ! in_array ( $ group -> getName ( ) , $ map ) ) throw new \ InvalidArgumentException ( sprintf ( "Column '%s' is unknown for class '%s'" , $ group -> getName ( ) , $ this -> entityProfile -> getReflectionClass ( ) -> getName ( ) ) ) ; $ name = array_flip ( $ map ) [ $ group -> getName ( ) ] ; } elseif ( $ group instanceof Attr ) $ name = $ group -> getName ( ) ; elseif ( is_string ( $ group ) ) $ name = $ group ; else throw new \ InvalidArgumentException ( "Group must be specified through an Attr instance or a valid property name" ) ; $ type = $ group -> getType ( ) ; if ( isset ( $ type ) ) return $ this -> merge ( [ 'query.group' => $ group -> getName ( ) . ':' . $ type ] ) ; return $ this -> merge ( [ 'query.group' => $ group -> getName ( ) ] ) ; } | Sets group attribute |
2,498 | public function orderBy ( $ order = null ) { if ( is_null ( $ order ) ) return $ this -> discard ( 'query.orderBy' ) ; return $ this -> merge ( [ 'query.orderBy' => func_get_args ( ) ] ) ; } | Sets order attributes |
2,499 | public function limit ( $ limit = null ) { if ( is_null ( $ limit ) ) return $ this -> discard ( 'query.limit' ) ; return $ this -> merge ( [ 'query.limit' => intval ( $ limit ) ] ) ; } | Sets rows limit |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.