idx
int64
0
241k
question
stringlengths
64
6.21k
target
stringlengths
5
803
230,700
public function rebuild ( $ force = false ) { $ alreadyValid = forward_static_call ( [ get_class ( $ this -> model ) , 'isValidNestedSet' ] ) ; if ( ! $ force && $ alreadyValid ) return true ; $ self = $ this ; $ this -> model -> getConnection ( ) -> transaction ( function ( ) use ( $ self ) { foreach ( $ self -> roots...
Perform the re - calculation of the left and right indexes of the whole nested set tree structure .
230,701
public function roots ( ) { return $ this -> model -> newQuery ( ) -> whereNull ( $ this -> model -> getQualifiedParentColumnName ( ) ) -> orderBy ( $ this -> model -> getQualifiedLeftColumnName ( ) ) -> orderBy ( $ this -> model -> getQualifiedRightColumnName ( ) ) -> orderBy ( $ this -> model -> getQualifiedKeyName (...
Return all root nodes for the current database table appropiately sorted .
230,702
public function children ( $ model ) { $ query = $ this -> model -> newQuery ( ) ; $ query -> where ( $ this -> model -> getQualifiedParentColumnName ( ) , '=' , $ model -> getKey ( ) ) ; foreach ( $ this -> scopedAttributes ( $ model ) as $ fld => $ value ) $ query -> where ( $ this -> qualify ( $ fld ) , '=' , $ valu...
Return all children for the specified node .
230,703
protected function scopedAttributes ( $ model ) { $ keys = $ this -> model -> getScopedColumns ( ) ; if ( count ( $ keys ) == 0 ) return [ ] ; $ values = array_map ( function ( $ column ) use ( $ model ) { return $ model -> getAttribute ( $ column ) ; } , $ keys ) ; return array_combine ( $ keys , $ values ) ; }
Return an array of the scoped attributes of the supplied node .
230,704
public static function createUserFromPostValues ( $ postValues ) { if ( isset ( $ postValues [ 'username' ] ) ) { $ user = new \ stdClass ( ) ; $ user -> username = $ postValues [ 'username' ] ; $ user -> slug = StringUtil :: slugify ( $ postValues [ 'username' ] ) ; $ user -> rights = array ( ) ; if ( isset ( $ postVa...
Create user from POST values
230,705
public function actionSave ( $ id = null , $ languageId ) { if ( ! empty ( $ languageId ) ) { if ( ! empty ( $ id ) ) { $ model = $ this -> findModel ( $ id ) ; } else { $ model = new OrderStatus ( ) ; } $ modelTranslation = $ this -> findOrCreateModelTranslation ( $ model -> id , $ languageId ) ; if ( $ modelTranslati...
Creates a new or updates existing OrderStatus and OrderStatusTranslation models . If creation is successful the browser will be redirected to the view page .
230,706
public function actionDelete ( $ id ) { if ( ! empty ( $ id ) ) { if ( $ id != OrderStatus :: STATUS_INCOMPLETE && $ id != OrderStatus :: STATUS_CONFIRMED ) { $ status = $ this -> findModel ( $ id ) ; if ( ! empty ( $ status ) ) { \ Yii :: $ app -> session -> setFlash ( 'success' , Yii :: t ( 'cart' , 'The status was s...
Deletes an existing OrderStatus model . If deletion is successful the browser will be redirected to the index page .
230,707
protected function findOrCreateModelTranslation ( $ id , $ languageId ) { $ modelTranslations = OrderStatusTranslation :: find ( ) -> where ( [ 'order_status_id' => $ id , 'language_id' => $ languageId ] ) -> one ( ) ; return ( ! empty ( $ modelTranslations ) ) ? $ modelTranslations : new OrderStatusTranslation ( ) ; }
Finds the OrderStatusTranslation model based on order_status_id property . If the model is not found a new model will be created .
230,708
public static function createFromServerRequest ( ServerRequest $ serverRequest ) { return new Request ( $ serverRequest -> getMethod ( ) , $ serverRequest -> getUri ( ) , $ serverRequest -> getHeaders ( ) , $ serverRequest -> getBody ( ) , $ serverRequest -> getProtocolVersion ( ) ) ; }
Build Request from a server Request .
230,709
private function replaceHostHeader ( UriInterface $ uri ) { $ host = $ uri -> getHost ( ) ; if ( ! empty ( $ host ) ) { $ port = $ uri -> getPort ( ) ; if ( ! empty ( $ port ) ) { $ host .= ':' . $ port ; } $ this -> headersOriginal = [ 'Host' => [ $ host ] ] + $ this -> headersOriginal ; $ this -> headers = [ 'host' =...
Update host header if host is not empty .
230,710
public function unserialize ( $ serialized ) { $ string = unserialize ( $ serialized , [ ] ) ; $ this -> data = RamseyUUID :: fromString ( $ string ) ; }
Restore the object from serialized data .
230,711
public function getClass ( ) { if ( is_string ( $ this -> fn ) ) { return $ this -> fn ; } $ hash = sha1 ( mt_rand ( ) . microtime ( true ) ) ; return "sndsgd\\field\\rule\\Closure($hash)" ; }
Ensure that multiple Closure rules can be added to a field
230,712
protected function getAssets ( array $ config ) { $ bootstrapBasePath = $ config [ 'bootstrap' ] [ 'dist_path' ] ; $ assets = array ( 'symboo_bootstrap_css' => array ( 'inputs' => array ( $ bootstrapBasePath . '/css/bootstrap.min.css' ) , 'filters' => array ( 'cssrewrite' ) , 'output' => 'css/bootstrap.css' ) , 'symboo...
Returns the assets to be added
230,713
public function boot ( ) { $ this -> publishes ( [ dirname ( dirname ( __DIR__ ) ) . '/config/repositories.php' => config_path ( 'repositories.php' ) , ] ) ; foreach ( config ( 'repositories.repositories' , [ ] ) as $ respository_contract => $ repository ) { $ this -> app -> bind ( $ respository_contract , $ repository...
Register any repositories .
230,714
public static function executeInBackground ( Task $ task , $ progressReportedCallback = null , BackgroundTaskStatus $ persistentStatus = null ) { if ( ! $ persistentStatus ) { $ persistentStatus = new BackgroundTaskStatus ( ) ; $ persistentStatus -> TaskClass = get_class ( $ task ) ; $ persistentStatus -> save ( ) ; } ...
Executes a task and provisions a BackgroundTaskStatus model to store a persistent record of the state .
230,715
public static function buildQueryDelete ( QuoteInterface $ quoting , $ table , array $ data , array $ returning = null ) { if ( ! count ( $ data ) === 0 ) { throw new NothingToDoException ( "Nothing to generate." ) ; } $ keys = self :: keyTuple ( $ quoting , $ data ) ; $ tuples = self :: dataTuples ( $ data ) ; return ...
Delete query for a data array
230,716
public static function buildQueryUpdate ( QuoteInterface $ quoting , $ table , array $ primaryKeys , array $ data , array $ dataInitial , array $ returning = null ) { if ( ! count ( $ data ) === 0 ) { throw new NothingToDoException ( "Nothing to generate." ) ; } $ columnNames = array_keys ( $ data [ 0 ] ) ; $ columnNam...
Update query for a data array
230,717
protected static function getReturningClause ( QuoteInterface $ quoting , array $ returning = null , $ table = '' ) { if ( $ returning === null ) { return 'RETURNING *' ; } elseif ( $ returning === array ( ) ) { return '' ; } elseif ( ! empty ( $ table ) ) { foreach ( $ returning as & $ value ) { $ value = "{$table}.{$...
Turn a array of columns into a comma separated identifier list suitable for being passed into a RETURNING
230,718
protected static function validateQueryDatas ( array & $ datas , array $ modifiers ) { foreach ( $ datas as $ key => & $ data ) { self :: validateQueryData ( $ data , $ modifiers ) ; } }
Validate a array of query datas arrays
230,719
protected static function validateQueryData ( array & $ data , array $ modifiers ) { foreach ( $ data as $ column => & $ value ) { $ value = $ modifiers [ $ column ] -> exec ( $ value ) ; } }
Validate a query datas array
230,720
protected static function buildChainTasks ( \ Bond \ Entity \ Base $ entity , $ columns ) { $ tasks = array ( ) ; foreach ( $ columns as $ column ) { $ value = $ entity -> get ( $ column ) ; if ( is_object ( $ value ) and $ value instanceof ChainSavingInterface ) { $ value -> chainSaving ( $ tasks , $ column ) ; } } re...
Get chain tasks
230,721
protected function itemSupportsMethodCall ( IsMetInterface $ item , $ methodName ) { $ hash = spl_object_hash ( $ item ) ; if ( empty ( $ this -> methodNamesPerItem ) || ! isset ( $ this -> methodNamesPerItem [ $ hash ] ) ) { $ itemMethods = array_flip ( get_class_methods ( $ item ) ) ; $ this -> methodNamesPerItem [ $...
Checks if item implements method name
230,722
public function registerVertex ( Vertex $ vertex ) { $ this -> vertexes -> set ( $ vertex -> getName ( ) , $ vertex ) ; return $ this ; }
register a new vertex into metadata
230,723
protected static function getSuppliedCSRF ( ) { $ headers = function_exists ( 'getallheaders' ) === true ? getallheaders ( ) : [ ] ; $ requestArguments = [ ] ; parse_str ( file_get_contents ( 'php://input' ) , $ requestArguments ) ; $ requestArguments = array_merge ( $ _POST , $ requestArguments ) ; if ( array_key_exis...
Get the CSRF token presented as a header a PUT parameter or a POST parameter .
230,724
public function importFile ( $ localPath , FileInterface $ folder = null ) { if ( ! $ folder -> isDir ( ) ) { throw new RuntimeException ( 'Files can only be moved into directories' ) ; } $ fileName = basename ( $ localPath ) ; $ targetPath = $ folder ? $ folder -> getPath ( ) . "$fileName" : $ fileName ; $ this -> fil...
Import a local file into the FileDB
230,725
protected function validateTimestamps ( array $ payload ) { if ( isset ( $ payload [ 'nbf' ] ) && Utils :: timestamp ( $ payload [ 'nbf' ] ) -> isFuture ( ) ) { throw new TokenInvalidException ( 'Not Before (nbf) timestamp cannot be in the future' , 400 ) ; } if ( isset ( $ payload [ 'iat' ] ) && Utils :: timestamp ( $...
Validate the payload timestamps .
230,726
public function accountPv ( \ Magento \ Sales \ Api \ Data \ OrderInterface $ order ) { $ orderId = $ order -> getEntityId ( ) ; $ this -> updateDatePaid ( $ orderId ) ; $ req = new \ Praxigento \ Pv \ Api \ Service \ Sale \ Account \ Pv \ Request ( ) ; $ req -> setSaleOrderId ( $ orderId ) ; $ this -> srvPvAccount -> ...
Collect order data and call service method to transfer PV to customer account .
230,727
private function getServiceItemForMageItem ( \ Magento \ Sales \ Api \ Data \ OrderItemInterface $ item , $ stockId = null ) { $ result = new \ Praxigento \ Pv \ Service \ Sale \ Data \ Item ( ) ; $ prodId = $ item -> getProductId ( ) ; $ itemId = $ item -> getItemId ( ) ; $ qty = $ item -> getQtyOrdered ( ) ; $ result...
Convert Magento SaleOrderItem to service item .
230,728
public function savePv ( \ Magento \ Sales \ Api \ Data \ OrderInterface $ order ) { $ orderId = $ order -> getId ( ) ; $ state = $ order -> getState ( ) ; $ dateCreated = $ order -> getCreatedAt ( ) ; $ itemsData = $ this -> getServiceItemsForMageSaleOrder ( $ order ) ; $ req = new \ Praxigento \ Pv \ Service \ Sale \...
Collect orders data and call service method to register order PV .
230,729
private function updateDatePaid ( $ orderId ) { $ datePaid = $ this -> hlpDate -> getUtcNowForDb ( ) ; $ data = [ ESale :: A_DATE_PAID => $ datePaid ] ; $ this -> daoSale -> updateById ( $ orderId , $ data ) ; $ this -> logger -> info ( "Update paid date in PV registry when sale order (#$orderId) is paid." ) ; }
Update paid date in sale order registry of PV module .
230,730
public function setForm ( ControlCollection $ form = null ) : Control { $ this -> control -> setForm ( $ form ) ; return parent :: setForm ( $ form ) ; }
Set control form .
230,731
public function distance ( Geo $ other ) { if ( $ other === $ this ) { return 0.0 ; } else { return self :: DEG_KM * rad2deg ( acos ( ( sin ( deg2rad ( $ this -> latitude ) ) * sin ( deg2rad ( $ other -> latitude ) ) ) + ( cos ( deg2rad ( $ this -> latitude ) ) * cos ( deg2rad ( $ other -> latitude ) ) * cos ( deg2rad ...
Uses the Haversine formula to calculate kilometer point distance .
230,732
public function getIndexedDocuments ( ) { $ db = $ this -> getSearchDbHandle ( ) ; $ sql = ' SELECT count(DISTINCT documentPath) AS indexedDocuments FROM term_frequency ' ; if ( ! $ stmt = $ db -> query ( $ sql ) ) { $ errorInfo = $ db -> errorInfo ( ) ; $ errorMsg = $ errorInfo [ 2 ] ; throw new \ RuntimeExcept...
Returns the amount of distinct documents that are currently in the search index .
230,733
private function queryTokens ( ) { $ tokens = $ this -> getTokens ( ) ; $ queryNorm = $ this -> getQueryNorm ( $ tokens ) ; $ results = array ( ) ; foreach ( $ tokens as $ token ) { $ results [ $ token ] = $ this -> getResultsForToken ( $ token , $ queryNorm ) ; } return $ results ; }
Queries each token present in the Tokenizer and returns SearchResult objects for the found documents
230,734
private function getSearchSuggestions ( ) { $ tokens = $ this -> getTokens ( ) ; $ allResults = array ( ) ; foreach ( $ tokens as $ token ) { $ allResults = $ this -> getSearchSuggestion ( $ token , $ allResults ) ; } return $ allResults ; }
Uses the levenshtein algorithm to determine the term that is closest to the token that was input for the search
230,735
private function getTokens ( ) { $ tokenVector = array ( 'query' => array ( ) , ) ; $ tokenVector [ 'query' ] = $ this -> tokenizer -> getTokenVector ( ) ; $ tokens = $ this -> applyFilters ( $ tokenVector ) ; if ( ! empty ( $ tokens ) ) { $ tokens = array_keys ( $ tokens [ 'query' ] ) ; } return $ tokens ; }
Retrieves all tokens from the tokenizer
230,736
public function delete ( ) { if ( count ( $ this ) == 0 ) { return ; } $ ids = $ this -> getPrimaryKeyList ( ) ; $ hitman = new $ this -> className ( ) ; $ hitman -> in ( $ hitman -> getPrimaryKey ( ) , $ ids ) -> delete ( ) ; }
Functions to operate on all elements of the ResultSet at once
230,737
public function update ( $ data ) { if ( count ( $ this ) == 0 ) { return ; } $ ids = $ this -> getPrimaryKeyList ( ) ; $ updater = new $ this -> className ( ) ; $ updater -> in ( $ updater -> getPrimaryKey ( ) , $ ids ) -> update ( $ data ) ; }
Update all entries in this ResultSet with the same values
230,738
public function getPrimaryKeyList ( ) { $ ids = [ ] ; if ( count ( $ this ) > 0 ) { foreach ( $ this as $ row ) { $ ids [ ] = $ row -> getPrimaryKeyValue ( ) ; } } return $ ids ; }
Returns an array of all primary keys contained in the ResultSet
230,739
private static function parse ( string $ headers ) : array { $ header = [ ] ; $ matches = [ ] ; preg_match_all ( '=^(.[^: ]+): ([^\r\n]*)=m' , $ headers , $ matches , PREG_SET_ORDER ) ; foreach ( $ matches as $ line ) { $ header [ $ line [ 1 ] ] = $ line [ 2 ] ; } return $ header ; }
parses given header string and returns a list of headers
230,740
public function append ( $ headers ) : self { if ( is_string ( $ headers ) ) { $ append = self :: parse ( $ headers ) ; } elseif ( is_array ( $ headers ) ) { $ append = $ headers ; } elseif ( $ headers instanceof self ) { $ append = $ headers -> headers ; } else { throw new \ InvalidArgumentException ( 'Given headers m...
appends given headers
230,741
public function put ( string $ key , $ value ) : self { if ( ! is_scalar ( $ value ) ) { throw new \ InvalidArgumentException ( 'Argument 2 passed to ' . __METHOD__ . ' must be an instance of a scalar value.' ) ; } $ this -> headers [ $ key ] = ( string ) $ value ; return $ this ; }
creates header with value for key
230,742
public function remove ( string $ key ) : self { if ( isset ( $ this -> headers [ $ key ] ) == true ) { unset ( $ this -> headers [ $ key ] ) ; } return $ this ; }
removes header with given key
230,743
public function putCookie ( array $ cookieValues ) : self { $ cookieValue = '' ; foreach ( $ cookieValues as $ key => $ value ) { $ cookieValue .= $ key . '=' . urlencode ( $ value ) . ';' ; } $ this -> put ( 'Cookie' , $ cookieValue ) ; return $ this ; }
creates header for cookie
230,744
public function putAuthorization ( string $ user , string $ password ) : self { $ this -> put ( 'Authorization' , 'BASIC ' . base64_encode ( $ user . ':' . $ password ) ) ; return $ this ; }
creates header for authorization
230,745
public function putDate ( int $ timestamp = null ) : self { if ( null === $ timestamp ) { $ date = gmdate ( 'D, d M Y H:i:s' ) ; } else { $ date = gmdate ( 'D, d M Y H:i:s' , $ timestamp ) ; } $ this -> put ( 'Date' , $ date . ' GMT' ) ; return $ this ; }
adds a date header
230,746
public function getTypeOfChildProperty ( $ targetType , $ propertyName , PropertyMappingConfigurationInterface $ configuration ) { $ specificTargetType = $ this -> objectContainer -> getImplementationClassName ( $ targetType ) ; if ( Core :: get ( ) -> classExists ( $ specificTargetType ) ) { $ propertyTags = $ this ->...
Will check the type of the given class property if reflection gives no result the parent function is called .
230,747
public static function build ( array $ constructorArguments = array ( ) , $ additionalProperties = array ( ) ) { $ constructorDefaults = array ( 'message' => null , 'code' => null , 'previous' => null ) ; $ constructorArguments = array_merge ( $ constructorDefaults , $ constructorArguments ) ; $ message = self :: prepa...
Helper method to prepare all but the most complex exceptions
230,748
public function __isset ( string $ name ) { if ( $ this -> hasWritableProperty ( $ name , $ setterName ) ) { return true ; } return parent :: __isset ( $ name ) ; }
Magic isset implementation .
230,749
public function hasWritableProperty ( string $ name , & $ setterName ) : bool { if ( \ in_array ( $ name , $ this -> ignoreSetProperties ) ) { return false ; } $ setterName = 'set' . \ ucfirst ( $ name ) ; return \ method_exists ( $ this , $ setterName ) ; }
Returns if a property with the defined name exists for write access .
230,750
public static function getInstanceByPath ( $ path , $ cacheDir = '' ) { $ instance = new self ( ) ; $ instance -> pathFile = $ path ; if ( ! empty ( $ cacheDir ) ) { $ instance -> setCacheDir ( $ cacheDir ) ; $ instance -> setCachePath ( ) ; } $ instance -> readImage ( ) ; return $ instance ; }
Creates a new image from file or URL .
230,751
public static function getInstanceByCreate ( $ width , $ height ) { $ instance = new self ( ) ; $ instance -> width = ( int ) $ width ; $ instance -> height = ( int ) $ height ; $ instance -> createImage ( ) ; return $ instance ; }
Creates a new image in memory .
230,752
public function merge ( Image $ srcImage , $ dstX , $ dstY , $ strategy = self :: MERGE_SCALE_SRC ) { if ( ! is_resource ( $ this -> image ) || ! is_resource ( $ srcImage -> image ) ) { throw new \ RuntimeException ( 'Attempt to merge image data using an invalid image resource.' ) ; } switch ( $ strategy ) { case self ...
Copies the given Image image stream into the image stream of the active instance using a scaling strategy .
230,753
public function mergeAlpha ( Image $ srcImage , $ dstX , $ dstY , $ alpha = 127 ) { if ( ! is_resource ( $ this -> image ) || ! is_resource ( $ srcImage -> image ) ) { throw new \ RuntimeException ( 'Attempt to merge image data using an invalid image resource.' ) ; } $ percent = 100 - min ( max ( round ( ( $ alpha / 12...
Copies the given Image image stream into the image stream of the active instance while applying the given alpha transparency .
230,754
public function render ( ) { if ( ! is_resource ( $ this -> image ) ) { throw new \ RuntimeException ( 'Attempt to render invalid resource as image.' ) ; } header ( 'Content-type: image/png' ) ; imagepng ( $ this -> image , null , 9 , PNG_ALL_FILTERS ) ; return $ this ; }
Outputs the image stream to the browser .
230,755
protected function setCacheDir ( $ path ) { if ( ! is_dir ( $ path ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Cache directory at %s could not be found' , $ path ) ) ; } if ( ! is_readable ( $ path ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Cache directory at %s is not readable' , $ path ) ) ; ...
Sets the path to the cache directory .
230,756
protected function isCached ( ) { $ cacheTime = self :: CACHE_TIME * 60 ; if ( ! is_file ( $ this -> pathCache ) ) { return false ; } $ cachedTime = filemtime ( $ this -> pathCache ) ; $ cacheAge = $ this -> time - $ cachedTime ; return $ cacheAge < $ cacheTime ; }
Checks if the image file exists in the cache .
230,757
protected function readImage ( ) { $ path = $ this -> pathFile ; if ( ! empty ( $ this -> pathCache ) ) { if ( ! $ this -> isCached ( ) ) { $ this -> writeCache ( ) ; } if ( $ this -> isCached ( ) ) { $ path = $ this -> pathCache ; } } $ read = @ getimagesize ( $ path ) ; if ( false === $ read ) { throw new \ RuntimeEx...
Reads the image file .
230,758
protected function createImage ( ) { $ this -> image = @ imagecreatetruecolor ( $ this -> width , $ this -> height ) ; $ this -> mimeType = 'image/png' ; $ this -> modified = time ( ) ; }
Creates a new true color image .
230,759
protected function Init ( ) { $ this -> repeater = ContentRepeater :: Schema ( ) -> ByContent ( $ this -> content ) ; $ this -> current = $ this -> tree -> FirstChildOf ( $ this -> item ) ; $ this -> isEmpty = ! $ this -> current ; return parent :: Init ( ) ; }
Initializes the repeater frontend module
230,760
protected function NextChild ( ) { $ item = $ this -> current ; $ this -> current = $ this -> tree -> NextOf ( $ item ) ; return $ item ; }
Gets the next child
230,761
public static function prepareAliases ( array $ defaultAliasConfig , array $ aliasArray ) : array { $ factory = new static ( $ defaultAliasConfig ) ; foreach ( $ aliasArray as $ name => $ config ) { $ name = ( string ) $ name ; $ aliasArray [ $ name ] = $ factory -> createAlias ( $ name , $ config ) ; } return $ aliasA...
Prepares aliases config in proper view .
230,762
public static function install ( $ request , $ object ) { $ spa = Tenant_SpaService :: installFromRepository ( $ object -> id ) ; return Tenant_Shortcuts_SpaManager ( $ spa ) -> apply ( $ spa , 'create' ) ; }
Install an spa
230,763
public static function getPossibleValues ( ) : array { if ( ( static :: $ possibleValues [ static :: class ] ?? null ) === null ) { static :: $ possibleValues [ static :: class ] = [ ] ; try { $ reflectionClass = new \ ReflectionClass ( static :: class ) ; } catch ( \ ReflectionException $ reflectionException ) { throw...
Overload this by basic array with listed constants . Taking them via Reflection is not the fastest way .
230,764
public function getMolecule ( string $ canonicalSMILE ) { $ this -> operations = new Operations ( ) ; $ atoms = array ( ) ; $ this -> operations -> addBranches ( $ canonicalSMILE , $ atoms ) ; $ this -> operations -> addLoopBonds ( $ atoms ) ; $ this -> operations -> atomsToCanonicalSMILE ( $ atoms ) ; $ factoryType = ...
FactoryClient constructor .
230,765
public static function sortBy ( $ array , $ sortByKeys , $ sorters , $ orders = [ ] ) { if ( is_string ( $ sortByKeys ) ) { $ sortByKeys = explode ( '.' , $ sortByKeys ) ; } $ sortByKeys = array_values ( ( array ) $ sortByKeys ) ; $ sorters = array_values ( ( array ) $ sorters ) ; uasort ( $ array , function ( $ a , $ ...
Sort by multiple keys
230,766
public static function groupBy ( $ array , $ groupBy = "id" ) { return static :: reduce ( $ array , function ( $ arr , $ item ) use ( $ groupBy ) { if ( is_closure ( $ groupBy ) ) { $ value = $ groupBy ( $ item ) ; } else { $ value = pisc \ upperscore \ def ( $ item , $ groupBy ) ; } if ( isset ( $ arr [ $ value ] ) ) ...
Group an array of objects by an attribute of an object or the result of a closure
230,767
public static function type ( $ array ) { $ last_key = - 1 ; $ type = 'index' ; foreach ( $ array as $ key => $ val ) { if ( ! is_int ( $ key ) || $ key < 0 ) { return 'assoc' ; } if ( $ type !== 'sparse' ) { if ( $ key !== $ last_key + 1 ) { $ type = 'sparse' ; } $ last_key = $ key ; } } return $ type ; }
Find whether the array is indexed or an associative array If it is indexed find if its sparse or not
230,768
public function start ( ) { if ( ! $ this -> started ) { if ( PHP_SAPI !== 'cli' ) { if ( ( PHP_VERSION_ID >= 50400 && session_status ( ) === PHP_SESSION_ACTIVE ) || ( PHP_VERSION_ID < 50400 && session_id ( ) ) ) { throw new \ RuntimeException ( 'Failed to start the session: Session already started.' ) ; } if ( headers...
start session and load session data into SessionDataBag
230,769
private function setSaveHandler ( ) { if ( PHP_VERSION_ID >= 50400 ) { $ this -> storageEngine = new NativeSessionWrapper ( ) ; if ( ! session_set_save_handler ( $ this -> storageEngine , FALSE ) ) { throw new \ RuntimeException ( 'Could not set session save handler.' ) ; } } }
set custom save handler for PHP 5 . 4 +
230,770
public function getRedirects ( ) { $ redirects = $ this -> repository -> redirects ; if ( $ redirects === null ) { $ redirects = array ( ) ; } usort ( $ redirects , array ( $ this , 'cmp' ) ) ; return $ redirects ; }
Get all redirects
230,771
public function addRedirect ( $ postValues ) { $ redirectObject = RedirectsFactory :: createRedirectFromPostValues ( $ postValues ) ; $ redirects = $ this -> repository -> redirects ; $ redirects [ ] = $ redirectObject ; $ this -> repository -> redirects = $ redirects ; $ this -> save ( ) ; }
Add a new redirect
230,772
public function getRedirectBySlug ( $ slug ) { $ redirects = $ this -> repository -> redirects ; foreach ( $ redirects as $ redirect ) { if ( $ redirect -> slug == $ slug ) { return $ redirect ; } } return null ; }
Get a redirect by it s slug
230,773
public function saveRedirect ( $ slug , $ postValues ) { $ redirectObject = RedirectsFactory :: createRedirectFromPostValues ( $ postValues ) ; $ redirects = $ this -> repository -> redirects ; foreach ( $ redirects as $ key => $ redirect ) { if ( $ redirect -> slug == $ slug ) { $ redirects [ $ key ] = $ redirectObjec...
Save a redirect by it s slug
230,774
public function deleteRedirectBySlug ( $ slug ) { $ redirects = $ this -> repository -> redirects ; foreach ( $ redirects as $ key => $ redirect ) { if ( $ redirect -> slug == $ slug ) { unset ( $ redirects [ $ key ] ) ; } } $ redirects = array_values ( $ redirects ) ; $ this -> repository -> redirects = $ redirects ; ...
Delete a redirect by it s slug
230,775
private function createTokenNode ( $ tokenName , $ defaultClass , $ tokenInterface , $ defaultTtl ) { $ builder = new TreeBuilder ( ) ; $ node = $ builder -> root ( $ tokenName ) ; $ node -> addDefaultsIfNotSet ( ) -> children ( ) -> integerNode ( 'ttl' ) -> defaultValue ( $ defaultTtl ) -> end ( ) -> scalarNode ( 'cla...
Create a token configuration node .
230,776
protected static function isInsideJailDir ( $ path ) { $ jailDir = __DIR__ . '/' . self :: $ jailDir ; return strpos ( realpath ( $ path ) , realpath ( $ jailDir ) ) !== false ; }
Compare users selected path with jaildir path
230,777
protected static function isWhitelisted ( $ file ) { if ( ! is_array ( self :: $ whitelist ) || count ( self :: $ whitelist ) === 0 ) { return true ; } foreach ( self :: $ whitelist as $ fileName ) { if ( strpos ( $ file , $ fileName ) ) { return true ; } } return false ; }
Compare users selected filename against whitelist
230,778
protected static function parseUrl ( $ url ) { $ url = isset ( $ url ) ? $ url : "//$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ; $ url = parse_url ( $ url ) ; $ url [ 'browse' ] = './' ; if ( array_key_exists ( 'browse' , self :: $ requestMethod ) && ! empty ( self :: $ requestMethod [ 'browse' ] ) ) { $ url [ 'browse' ...
Pare URL into array
230,779
public static function get_all_locations ( ) { $ menus = [ ] ; $ locations = get_nav_menu_locations ( ) ; foreach ( $ locations as $ location => $ menu_id ) { $ menus [ $ location ] = [ ] ; $ menu_items = wp_get_nav_menu_items ( $ menu_id ) ; $ menu_items = is_array ( $ menu_items ) ? $ menu_items : [ ] ; foreach ( $ m...
Returns an array of menu locations with the assigned menu in each .
230,780
public static function getFirePHP ( $ options = null ) { if ( ! isset ( self :: $ _FirePHP ) || ! empty ( $ options ) ) { if ( ! class_exists ( '\FirePHP' ) ) { throw new THEDEBUGException ( "FirePHP not available" ) ; } if ( ! isset ( self :: $ _FirePHP ) ) { ob_start ( ) ; } if ( ! empty ( $ options ) ) { \ FB :: set...
Retrieve an instance of FirePHP
230,781
public static function getChromePHP ( ) { if ( ! isset ( self :: $ _ChromePHP ) ) { self :: $ _ChromePHP = X \ THEDEBUG \ ChromePhp :: getInstance ( ) ; } return self :: $ _ChromePHP ; }
Retrieve an instance of ChromePHP
230,782
public static function debug ( $ variable ) { if ( ! self :: $ _enabled ) { return ; } if ( self :: $ ensureByGet && ! isset ( $ _GET [ 'debug' ] ) ) { return ; } $ debug = new THEDEBUG \ ADEBUG ( func_get_args ( ) ) ; $ debug -> put ( ) ; return $ variable ; }
Create an ADEBUG object and put it .
230,783
public static function diebug ( ) { if ( ! self :: $ _enabled ) { return ; } if ( self :: $ ensureByGet && ! isset ( $ _GET [ 'debug' ] ) ) { return ; } $ args = func_get_args ( ) ; $ debug = new THEDEBUG \ ADEBUG ( $ args ) ; if ( ! empty ( $ args ) ) { $ debug -> put ( ) ; } $ debug -> variable = 'Script got murdered...
The Killer debug the passed variable die!
230,784
public static function getDebugObject ( $ variable ) { if ( ! self :: $ _enabled ) { return ; } if ( self :: $ ensureByGet && ! isset ( $ _GET [ 'debug' ] ) ) { return ; } return new THEDEBUG \ ADEBUG ( func_get_args ( ) ) ; }
Just return the ADEBUG instance for later usage .
230,785
public static function deprecate ( $ alternative = '' , $ continue = true ) { if ( ! self :: $ _enabled ) { return ; } if ( self :: $ ensureByGet && ! isset ( $ _GET [ 'debug' ] ) ) { return ; } $ debug = new THEDEBUG \ ADEBUG ( ) ; $ scope = $ debug -> getScope ( ) ; if ( $ scope -> type === 'global' ) { return ; } $ ...
Flag a function as deprecated by placing this method inside it .
230,786
public static function count ( $ message = '' ) { if ( ! self :: $ _enabled ) { return ; } if ( self :: $ ensureByGet && ! isset ( $ _GET [ 'debug' ] ) ) { return ; } $ debug = new THEDEBUG \ ADEBUG ( array ( 1 ) ) ; $ ID = $ debug -> getID ( ) ; if ( isset ( self :: $ counts [ $ ID ] ) ) { unset ( $ debug ) ; self :: ...
Count how often this line is visited and put the debug at the end of the script .
230,787
private static function traverse ( $ name , $ type , $ tmp_name , $ error , $ size , Dictionary $ dict , $ path ) { if ( is_array ( $ name ) ) { $ keys = array_keys ( $ name ) ; foreach ( $ keys as $ key ) { $ new_path = $ path ; $ new_path [ ] = $ key ; if ( ! array_key_exists ( $ key , $ name ) || ! array_key_exists ...
Helper function to recursively traverse the uploaded files array .
230,788
public function baseURL ( $ path = '' ) { if ( is_null ( $ this -> baseURL ) ) { $ self = $ _SERVER [ 'PHP_SELF' ] ; $ server = $ _SERVER [ 'HTTP_HOST' ] . rtrim ( str_replace ( strstr ( $ self , 'index.php' ) , '' , $ self ) , '/' ) ; if ( ( ! empty ( $ _SERVER [ 'HTTPS' ] ) && $ _SERVER [ 'HTTPS' ] != 'off' ) || ! em...
Return the baseURL
230,789
protected function determineRedirectURL ( ) { $ this -> redirectURL = trim ( $ this -> getRoutedParameter ( 'url' ) ) ; if ( empty ( $ this -> redirectURL ) ) { $ this -> setNotReady ( "Invalid or missing redirect `url` parameter." , null , 404 ) ; } }
Determine redirect url
230,790
protected function determineRedirectType ( ) { $ this -> redirectType = intval ( $ this -> getRoutedParameter ( 'type' , $ this -> redirectType ) ) ; if ( ! in_array ( $ this -> redirectType , [ 301 , 302 ] ) ) { $ this -> setNotReady ( "Invalid redirect type specified." , null , 404 ) ; } }
Determine redirect type
230,791
protected function validateRedirectURL ( ) { if ( ! filter_var ( $ this -> redirectURL , FILTER_VALIDATE_URL ) ) { if ( ! preg_match ( '#^/[a-zA-Z0-9_/.-]*#' , $ this -> redirectURL ) ) { $ this -> setNotReady ( "Invalid redirect URL entered." , null , 404 ) ; return ; } } }
Validate redirect URL
230,792
protected function buildOutputObject ( ) { $ output = new \ Slab \ Controllers \ Response ( static :: DEFAULT_REDIRECT_RESOLVER , $ this -> data , $ this -> redirectType , $ this -> displayHeaders ) ; return $ output ; }
Build the output object
230,793
static function getDatabase ( $ link ) { if ( $ link instanceof \ PDO ) { $ class = 'Pdo' ; } elseif ( $ link instanceof \ Zend \ Db \ Adapter \ Adapter ) { $ class = 'ZendDb2' ; } elseif ( $ link instanceof \ Zend_Db_Adapter_Abstract ) { $ class = 'ZendDb' ; } elseif ( $ link instanceof \ MDB2_Driver_Common ) { $ clas...
Factory method to create database interface
230,794
private function prepareContent ( $ content ) { $ this -> content = $ content ; if ( ! ( $ this -> content instanceof StreamInterface ) ) { $ this -> content = Stream :: factory ( $ this -> content ) ; } elseif ( $ this -> content instanceof MultipartBody ) { if ( ! $ this -> hasHeader ( 'Content-Disposition' ) ) { $ d...
Prepares the contents of a POST file .
230,795
private function prepareDefaultHeaders ( ) { if ( ! $ this -> hasHeader ( 'Content-Disposition' ) ) { $ this -> headers [ 'Content-Disposition' ] = sprintf ( 'form-data; name="%s"; filename="%s"' , $ this -> name , basename ( $ this -> filename ) ) ; } if ( ! $ this -> hasHeader ( 'Content-Type' ) ) { $ this -> headers...
Applies default Content - Disposition and Content - Type headers if needed .
230,796
public function getLicense ( ) { if ( $ this -> _license === null ) { $ this -> _license = $ this -> take ( 'package' ) -> getLicense ( ) ; } return $ this -> _license ; }
Get license .
230,797
protected function extractDefaultValues ( $ pattern ) { $ regex = '~\{([a-zA-Z][a-zA-Z0-9_]*+)[^\}]*(=[a-zA-Z0-9._]++)\}~' ; if ( preg_match_all ( $ regex , $ pattern , $ matches , \ PREG_SET_ORDER ) ) { $ srch = $ repl = $ vals = [ ] ; foreach ( $ matches as $ m ) { $ srch [ ] = $ m [ 0 ] ; $ repl [ ] = str_replace ( ...
Extract default values from the pattern
230,798
private function setCommonTemplateParameters ( ) { $ this -> setTemplateParameter ( 'application' , APPLICATION ) ; $ this -> setTemplateParameter ( 'area' , AREA ) ; $ this -> setTemplateParameter ( 'subject' , $ this -> name ) ; $ this -> setTemplateParameter ( 'language' , LANGUAGE ) ; $ this -> setTemplateParameter...
Sets common template parameters
230,799
protected function buildTemplateFunctions ( ) { $ this -> templateEngine -> addFunction ( 'pathToArea' , function ( $ language = false ) { return implode ( '/' , $ this -> buildPathToArea ( $ language ) ) . '/' ; } ) ; $ this -> templateEngine -> addFunction ( 'pathToSubject' , function ( $ language = false ) { return ...
Builds functions used into templates