idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
23,600
protected static function normalizePort ( ? int $ port , ? string $ scheme ) : ? int { if ( $ port === null ) { return null ; } if ( $ scheme && isset ( static :: $ defaultPorts [ $ scheme ] ) && ( $ port == static :: $ defaultPorts [ $ scheme ] ) ) { return null ; } return $ port ; }
Validates and normalizes the port
23,601
protected static function encodePath ( string $ path ) : string { $ excluded = static :: UNRESERVED_SET . static :: SUB_DELIMS_SET . ':@\/' ; return static :: encode ( $ path , $ excluded ) ; }
Encodes the path
23,602
protected static function encodeQuery ( string $ query ) : string { $ excluded = static :: UNRESERVED_SET . static :: SUB_DELIMS_SET . ':@\/\?' ; return static :: encode ( $ query , $ excluded ) ; }
Encodes the query
23,603
protected static function encodeFragment ( string $ fragment ) : string { $ excluded = static :: UNRESERVED_SET . static :: SUB_DELIMS_SET . ':@\/\?' ; return static :: encode ( $ fragment , $ excluded ) ; }
Encodes the fragment
23,604
protected static function encodeUserInfo ( string $ userInfo ) : string { $ excluded = static :: UNRESERVED_SET . static :: SUB_DELIMS_SET . ':' ; return static :: encode ( $ userInfo , $ excluded ) ; }
Encodes the user info
23,605
protected static function encodeHost ( string $ host ) : string { if ( $ host [ 0 ] === '[' ) { $ excluded = static :: UNRESERVED_SET . static :: SUB_DELIMS_SET . '\[\]:' ; return static :: encode ( $ host , $ excluded ) ; } $ excluded = static :: UNRESERVED_SET . static :: SUB_DELIMS_SET ; return static :: encode ( $ host , $ excluded ) ; }
Encodes the host
23,606
protected static function encode ( string $ component , string $ excluded ) : string { return preg_replace_callback ( static :: encodingRegex ( $ excluded ) , function ( array $ matches ) { return rawurlencode ( $ matches [ 0 ] ) ; } , $ component ) ; }
Encodes a component
23,607
protected static function decode ( string $ component , string $ allowed ) : string { $ allowed = sprintf ( '/[%s]/' , $ allowed ) ; $ encoded = sprintf ( '/%s/' , static :: PCT_ENCODED_SET ) ; return preg_replace_callback ( $ encoded , function ( $ matches ) use ( $ allowed ) { $ char = rawurldecode ( $ matches [ 0 ] ) ; if ( preg_match ( $ allowed , $ char ) ) { return $ char ; } return strtoupper ( $ matches [ 0 ] ) ; } , $ component ) ; }
Decodes a component
23,608
protected static function removeDotSegments ( string $ path ) : string { $ output = '' ; while ( $ path ) { if ( '..' == $ path || '.' == $ path ) { break ; } switch ( true ) { case ( './' == substr ( $ path , 0 , 2 ) ) : $ path = substr ( $ path , 2 ) ; break ; case ( '../' == substr ( $ path , 0 , 3 ) ) : $ path = substr ( $ path , 3 ) ; break ; case ( '/./' == substr ( $ path , 0 , 3 ) ) : $ path = substr ( $ path , 2 ) ; break ; case ( '/../' == substr ( $ path , 0 , 4 ) ) : $ path = '/' . substr ( $ path , 4 ) ; $ pos = strrpos ( $ output , '/' , - 1 ) ; if ( $ pos !== false ) { $ output = substr ( $ output , 0 , $ pos ) ; } break ; case ( '/..' == substr ( $ path , 0 , 3 ) && ( in_array ( substr ( $ path , 3 , 1 ) , [ false , '' , '/' ] , true ) ) ) : $ path = '/' . substr ( $ path , 3 ) ; $ pos = strrpos ( $ output , '/' , - 1 ) ; if ( $ pos !== false ) { $ output = substr ( $ output , 0 , $ pos ) ; } break ; case ( '/.' == substr ( $ path , 0 , 2 ) && ( in_array ( substr ( $ path , 2 , 1 ) , [ false , '' , '/' ] , true ) ) ) : $ path = '/' . substr ( $ path , 2 ) ; break ; default : $ nextSlash = strpos ( $ path , '/' , 1 ) ; if ( false === $ nextSlash ) { $ segment = $ path ; } else { $ segment = substr ( $ path , 0 , $ nextSlash ) ; } $ output .= $ segment ; $ path = substr ( $ path , strlen ( $ segment ) ) ; break ; } } return $ output ; }
Removes dot segments
23,609
protected static function mergePaths ( Uri $ baseUri , string $ relative ) : string { $ basePath = $ baseUri -> path ( ) ; if ( $ baseUri -> authority ( ) !== null && $ basePath === '' ) { return sprintf ( '/%s' , $ relative ) ; } $ last = strrpos ( $ basePath , '/' ) ; if ( $ last !== false ) { return sprintf ( '%s/%s' , substr ( $ basePath , 0 , $ last ) , $ relative ) ; } return $ relative ; }
Merges a base URI and relative path
23,610
protected static function isValidScheme ( ? string $ scheme ) : bool { if ( $ scheme === null || $ scheme === '' ) { return false ; } return ! ! preg_match ( static :: SCHEME_PATTERN , $ scheme ) ; }
Checks if a scheme is valid
23,611
protected static function isValidPath ( string $ path ) : bool { if ( $ path === '' ) { return true ; } $ pattern = sprintf ( '/\A(?:(?:[%s%s:@]|(?:%s))*\/?)*\z/' , static :: UNRESERVED_SET , static :: SUB_DELIMS_SET , static :: PCT_ENCODED_SET ) ; return ! ! preg_match ( $ pattern , $ path ) ; }
Checks if a path is valid
23,612
protected static function isValidQuery ( ? string $ query ) : bool { if ( $ query === null || $ query === '' ) { return true ; } $ pattern = sprintf ( '/\A(?:[%s%s\/?:@]|(?:%s))*\z/' , static :: UNRESERVED_SET , static :: SUB_DELIMS_SET , static :: PCT_ENCODED_SET ) ; return ! ! preg_match ( $ pattern , $ query ) ; }
Checks if a query is valid
23,613
protected static function isValidFragment ( ? string $ fragment ) : bool { if ( $ fragment === null || $ fragment === '' ) { return true ; } $ pattern = sprintf ( '/\A(?:[%s%s\/?:@]|(?:%s))*\z/' , static :: UNRESERVED_SET , static :: SUB_DELIMS_SET , static :: PCT_ENCODED_SET ) ; return ! ! preg_match ( $ pattern , $ fragment ) ; }
Checks if a fragment is valid
23,614
protected static function isValidUserInfo ( string $ userInfo ) : bool { $ pattern = sprintf ( '/\A(?:[%s%s:]|(?:%s))*\z/' , static :: UNRESERVED_SET , static :: SUB_DELIMS_SET , static :: PCT_ENCODED_SET ) ; return ! ! preg_match ( $ pattern , $ userInfo ) ; }
Checks if user info is valid
23,615
protected static function isValidHost ( string $ host ) : bool { if ( strpos ( $ host , '[' ) !== false ) { return static :: isValidIpLiteral ( $ host ) ; } $ dec = '(?:(?:2[0-4]|1[0-9]|[1-9])?[0-9]|25[0-5])' ; $ ipV4 = sprintf ( '/\A(?:%s\.){3}%s\z/' , $ dec , $ dec ) ; if ( preg_match ( $ ipV4 , $ host ) ) { return true ; } $ pattern = sprintf ( '/\A(?:[%s%s]|(?:%s))*\z/' , static :: UNRESERVED_SET , static :: SUB_DELIMS_SET , static :: PCT_ENCODED_SET ) ; return ! ! preg_match ( $ pattern , $ host ) ; }
Checks if a host is valid
23,616
protected static function isValidIpLiteral ( string $ ip ) : bool { $ length = strlen ( $ ip ) ; if ( $ ip [ 0 ] !== '[' || $ ip [ $ length - 1 ] !== ']' ) { return false ; } $ ip = substr ( $ ip , 1 , $ length - 2 ) ; $ pattern = sprintf ( '/\A[v](?:[a-f0-9]+)\.[%s%s:]+\z/i' , static :: UNRESERVED_SET , static :: SUB_DELIMS_SET ) ; if ( preg_match ( $ pattern , $ ip ) ) { return true ; } return filter_var ( $ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 ) !== false ; }
Checks if a IP literal is valid
23,617
public function search ( $ srsearch , array $ srnamespace = null , $ srwhat = null , array $ srinfo = null , array $ srprop = null , $ srredirects = null , $ sroffest = null , $ srlimit = null ) { $ path = '?action=query&list=search' ; if ( isset ( $ srsearch ) ) { $ path .= '&srsearch=' . $ srsearch ; } if ( isset ( $ srnamespace ) ) { $ path .= '&srnamespace=' . $ this -> buildParameter ( $ srnamespace ) ; } if ( isset ( $ srwhat ) ) { $ path .= '&srwhat=' . $ srwhat ; } if ( isset ( $ srinfo ) ) { $ path .= '&srinfo=' . $ this -> buildParameter ( $ srinfo ) ; } if ( isset ( $ srprop ) ) { $ path .= '&srprop=' . $ this -> buildParameter ( $ srprop ) ; } if ( $ srredirects ) { $ path .= '&srredirects=' ; } if ( isset ( $ sroffest ) ) { $ path .= '&sroffest=' . $ sroffest ; } if ( isset ( $ srlimit ) ) { $ path .= '&srlimit=' . $ srlimit ; } $ response = $ this -> client -> get ( $ this -> fetchUrl ( $ path ) ) ; return $ this -> validateResponse ( $ response ) ; }
Method to perform a full text search .
23,618
public function openSearch ( $ search , $ limit = null , array $ namespace = null , $ suggest = null , $ format = null ) { $ path = '?action=query&list=search' ; if ( isset ( $ search ) ) { $ path .= '&search=' . $ search ; } if ( isset ( $ limit ) ) { $ path .= '&limit=' . $ limit ; } if ( isset ( $ namespace ) ) { $ path .= '&namespace=' . $ this -> buildParameter ( $ namespace ) ; } if ( isset ( $ suggest ) ) { $ path .= '&suggest=' . $ suggest ; } if ( isset ( $ format ) ) { $ path .= '&format=' . $ format ; } $ response = $ this -> client -> get ( $ this -> fetchUrl ( $ path ) ) ; return $ this -> validateResponse ( $ response ) ; }
Method to search the wiki using opensearch protocol .
23,619
public function push ( $ value ) : QueueInterface { $ this -> resolver -> value ( function ( $ value ) : void { $ this -> items -> push ( $ value ) ; } , $ value ) ; return $ this ; }
Pushes one value onto the top of the queue .
23,620
public function isSelectorAvailable ( $ selector , $ fields = array ( ) , $ rootId = null ) { if ( is_scalar ( $ fields ) ) { $ media = ( string ) $ fields ; $ id = null ; } else { $ fields = ( object ) $ fields ; $ media = empty ( $ fields -> media ) ? '' : $ fields -> media ; $ rootId = empty ( $ fields -> rootParagraphId ) ? null : ( int ) $ fields -> rootParagraphId ; $ id = empty ( $ fields -> id ) ? null : ( int ) $ fields -> id ; } if ( $ this -> getRuleMapper ( ) -> isSelectorExists ( $ selector , $ media , $ rootId , $ id ) ) { return static :: SELECTOR_TAKEN ; } $ matches = array ( ) ; if ( preg_match ( '/#paragraph-(\\d+)/' , $ selector , $ matches ) ) { if ( ! $ this -> getParagraphMapper ( ) -> isParagraphIdExists ( $ matches [ 1 ] ) ) { return static :: SELECTOR_PARAGRAPH_NOT_EXISTS ; } } return static :: SUCCESS ; }
Is selector available
23,621
public function extract ( ) { $ iterator = new \ RecursiveDirectoryIterator ( $ this -> path ) ; $ iterator = new \ RecursiveIteratorIterator ( $ iterator ) ; $ pages = [ ] ; $ files = iterator_to_array ( $ iterator ) ; $ files = array_filter ( $ files , function ( $ file ) { return $ file -> isFile ( ) ; } ) ; foreach ( $ files as $ path ) { $ pages [ $ this -> exclude ( $ path ) ] = compact ( 'path' ) ; } return $ pages ; }
Extract web pages from file system from given path
23,622
public function beginTransaction ( ) { if ( $ this -> supportTransaction == false ) { throw new LikePDOException ( "This driver doesn't support transactions" ) ; return false ; } elseif ( $ this -> inTransaction == true ) { throw new LikePDOException ( "There is already an active transaction" ) ; return false ; } else { if ( ! $ this -> driver -> beginTransaction ( ) ) { throw new LikePDOException ( "Failed to begin transaction" ) ; return false ; } return true ; } }
Initiates a transaction
23,623
public function errorInfo ( ) { return array ( 0 => $ this -> driver -> getSQLState ( ) , 1 => $ this -> driver -> getErrorCode ( ) , 2 => $ this -> driver -> getLastMessage ( ) ) ; }
Fetch extended error information associated with the last operation on the database handle
23,624
public function getAvailableDrivers ( ) { $ drivers = array ( ) ; if ( count ( $ this -> drivers ) > 0 ) { foreach ( $ this -> drivers as $ driver ) { if ( class_exists ( "LikePDO\\Drivers\\" . $ driver . "Driver" ) ) { $ drivers [ ] = $ driver ; } } } return $ drivers ; }
Return an array of available LikePDO drivers
23,625
public function query ( $ statement , $ fetch_type = NULL , $ fetch_arga = NULL , $ fetch_argb = NULL ) { if ( ! $ fetch_type ) $ fetch_type = LikePDO :: FETCH_ASSOC ; $ statement = new LikePDOStatement ( $ statement , $ this ) ; $ statement -> setFetchMode ( $ fetch_type , $ fetch_arga , $ fetch_argb ) ; $ statement -> execute ( ) ; return $ statement -> fetchAll ( ) ; }
Executes an SQL statement returning a result set as a LikePDOStatement object
23,626
private function jssCompiler ( $ config ) { if ( ! isset ( $ config -> filename ) ) { echo "ERROR!!\n" ; return false ; } $ content = "var JSS = Array();\n" ; $ width = 4096 ; if ( isset ( $ config -> css ) ) { $ tmp = $ this -> minify ( false , $ config -> css , $ this -> yuicompressor , $ this -> config -> baseDir ) ; $ tmp = explode ( "\n" , str_replace ( "'" , "\'" , $ tmp ) ) ; foreach ( $ tmp as $ k => $ v ) { $ v = trim ( $ v ) ; if ( $ v == '' ) { continue ; } if ( substr ( $ v , - 1 ) == '\\' ) { $ v .= '\\' ; } $ content .= 'JSS[' . $ k . '] = \'' . $ v . "';\n" ; } } $ content .= 'for(var i in JSS){var etmp=document.createElement("STYLE");etmp.type="text/css";etmp.innerHTML=JSS[i];document.head.appendChild(etmp);}document.getElementsByClassName("container")[0].style.display="block";document.getElementById("loader").style.display="none";' . "\n" ; if ( isset ( $ config -> js ) ) { $ content .= $ this -> minify ( false , $ config -> js , $ this -> yuicompressor , $ this -> config -> baseDir ) ; } file_put_contents ( $ config -> filename , $ content ) ; echo "\n\n Saving: " . $ config -> filename . "\n" ; }
Jointer JS & CSS
23,627
public function renameAction ( Request $ request ) { $ volumeId = $ request -> get ( 'site_id' ) ; $ folderId = $ request -> get ( 'folder_id' ) ; $ folderName = $ request -> get ( 'folder_name' ) ; $ volume = $ this -> getVolume ( $ volumeId ) ; $ folder = $ volume -> findFolder ( $ folderId ) ; $ volume -> renameFolder ( $ folder , $ folderName , $ this -> getUser ( ) -> getId ( ) ) ; return new ResultResponse ( true , 'Folder renamed.' , [ 'folder_name' => $ folderName , ] ) ; }
Rename folder .
23,628
public function moveAction ( Request $ request ) { $ volumeId = $ request -> get ( 'site_id' ) ; $ targetId = $ request -> get ( 'target_id' ) ; $ sourceId = $ request -> get ( 'source_id' ) ; $ volume = $ this -> getVolume ( $ volumeId ) ; $ folder = $ volume -> findFolder ( $ sourceId ) ; $ targetFolder = $ volume -> findFolder ( $ targetId ) ; $ volume -> moveFolder ( $ folder , $ targetFolder , $ this -> getUser ( ) -> getId ( ) ) ; return new ResultResponse ( true ) ; }
Move folder .
23,629
public function propertiesAction ( Request $ request ) { $ folderId = $ request -> get ( 'folder_id' ) ; $ volumeManager = $ this -> get ( 'phlexible_media_manager.volume_manager' ) ; $ volume = $ volumeManager -> getByFolderId ( $ folderId ) ; try { $ folder = $ volume -> findFolder ( $ folderId ) ; $ calculator = new SizeCalculator ( ) ; $ calculatedSize = $ calculator -> calculate ( $ volume , $ folder ) ; $ data = [ 'title' => $ folder -> getName ( ) , 'type' => 'folder' , 'path' => '/' . $ folder -> getPath ( ) , 'size' => $ calculatedSize -> getSize ( ) , 'files' => $ calculatedSize -> getNumFiles ( ) , 'folders' => $ calculatedSize -> getNumFolders ( ) , 'create_time' => $ folder -> getCreatedAt ( ) -> format ( 'U' ) * 1000 , 'create_user' => $ folder -> getCreateUserId ( ) , 'modify_time' => $ folder -> getModifiedAt ( ) -> format ( 'U' ) * 1000 , 'modify_user' => $ folder -> getModifyUserId ( ) , ] ; } catch ( \ Exception $ e ) { $ data = [ ] ; } return new JsonResponse ( $ data ) ; }
Folder properties .
23,630
public static function isValidIP ( $ ipAddr , $ allowipv6 = false ) { $ validator = new ZendIp ( array ( 'allowipv6' => $ allowipv6 ) ) ; return $ validator -> isValid ( $ ipAddr ) ; }
Check if string is a valid ip address
23,631
protected static function cidrMatch32bit ( $ ipAddr , $ cidr ) { list ( $ subNet , $ bits ) = explode ( '/' , $ cidr ) ; $ ipLong = \ ip2long ( $ ipAddr ) ; $ subnetLong = \ ip2long ( $ subNet ) ; $ mask = - 1 << ( 32 - $ bits ) ; $ subnetLong &= $ mask ; return ( $ ipLong & $ mask ) == $ subnetLong ; }
32 bit processor CIDR match
23,632
protected static function cidrMatch64bit ( $ ipAddr , $ cidr ) { list ( $ sn , $ bits ) = explode ( '/' , $ cidr ) ; $ ipLong = self :: ip2long64 ( $ ipAddr , $ bits ) ; $ subnet = self :: ip2long64 ( $ sn , $ bits ) ; $ mask = - 1 << ( 32 - $ bits ) ; return ( $ ipLong & $ mask ) == $ subnet ; }
64 bit processor CIDR match
23,633
public function buildThumbFilename ( $ filename ) { $ extension = pathinfo ( $ filename , PATHINFO_EXTENSION ) ; if ( ! $ extension ) { $ filename .= '.' . pathinfo ( $ this -> relative , PATHINFO_EXTENSION ) ; } return $ this -> getThumbFolder ( ) . '/' . $ filename ; }
Builds the filename for thumb image
23,634
public function getSavePath ( ) { if ( empty ( $ this -> savePath ) ) { $ this -> savePath = sprintf ( static :: SAVE_PATH , $ this -> getSiteInfo ( ) -> getSchema ( ) ) ; $ dir = rtrim ( $ this -> savePath , '/' ) ; if ( ! is_dir ( $ dir ) ) { @ mkdir ( $ dir , 0777 , true ) ; } } return $ this -> savePath ; }
Get save path
23,635
public function findAll ( ) { return new CallbackMapIterator ( new FilesystemIterator ( $ this -> getSavePath ( ) , FilesystemIterator :: SKIP_DOTS | FilesystemIterator :: KEY_AS_FILENAME | FilesystemIterator :: CURRENT_AS_FILEINFO ) , function ( SplFileInfo $ info ) { return $ info -> getFilename ( ) ; } ) ; }
Find all snippets
23,636
protected function getAccessibleProperties ( $ className ) { $ refl = $ className :: getReflection ( ) ; $ props = [ ] ; foreach ( $ refl -> getProperties ( ) as $ prop ) { if ( $ prop -> getDeclaringClass ( ) -> getName ( ) == 'Rails\ActiveModel\Base' || $ prop -> getDeclaringClass ( ) -> getName ( ) == 'Rails\ActiveRecord\Base' || $ prop -> getDeclaringClass ( ) -> getName ( ) == 'Rails\ActiveRecord\Mongo\Base' ) { break ; } if ( $ prop -> isPublic ( ) ) { $ props [ $ prop -> getName ( ) ] = [ 'propName' => $ prop -> getName ( ) ] ; } else { $ params = [ ] ; $ getterMethodName = $ prop -> getName ( ) ; if ( $ refl -> hasMethod ( $ getterMethodName ) && ( $ method = $ refl -> getMethod ( $ getterMethodName ) ) && $ method -> isPublic ( ) ) { $ params [ ] = $ getterMethodName ; } else { $ params [ ] = false ; } $ setterMethodName = 'set' . ucfirst ( $ prop -> getName ( ) ) ; if ( $ refl -> hasMethod ( $ setterMethodName ) && ( $ method = $ refl -> getMethod ( $ setterMethodName ) ) && $ method -> isPublic ( ) ) { $ params [ ] = $ setterMethodName ; } else { $ params [ ] = false ; } $ props [ $ prop -> getName ( ) ] = $ params ; } } return $ props ; }
Get accessible properties . An accessible property is either a public property or a property that has a setter method named like setPropName . Returns an array whose keys are the property name and the value is the setter name if the property has a setter or an array with the actual property name under the propName key if its a public property .
23,637
private function getLoginProvider ( ) { if ( ! $ this -> loginProviderClassName ) { return Container :: instance ( LoginProvider :: class ) ; } $ provider = $ this -> loginProviderClassName ; return new $ provider ( ) ; }
Returns the login provider for this presenter .
23,638
protected function beforeRenderView ( ) { $ login = $ this -> getLoginProvider ( ) ; if ( isset ( $ _GET [ "logout" ] ) ) { $ login -> logOut ( ) ; } if ( $ login -> isLoggedIn ( ) ) { $ this -> onSuccess ( ) ; } }
Called just before the view is rendered .
23,639
public function getUserDetails ( $ id ) { $ user = new User ( ) ; $ user -> setDb ( $ this -> di -> get ( "db" ) ) ; $ user -> find ( "id" , $ id ) ; return $ user ; }
Get user details to load form with .
23,640
public function getWelcome ( ) { $ stub = $ this -> getCfgValue ( 'demo.pages.welcome' , 'welcome' ) ; $ this -> getLogger ( ) -> addInfo ( 'Got stub: ' . $ stub ) ; $ pageMgr = $ this -> getDataManager ( PageDataManager :: class ) ; return $ pageMgr -> getPage ( $ stub ) -> getTitle ( ) ; }
Get Welcome .
23,641
public static function flash ( $ name = '' , $ message = '' , $ class = 'success fadeout-message' ) { if ( ! empty ( $ name ) ) { if ( ! empty ( $ message ) && empty ( $ _SESSION [ $ name ] ) ) { if ( ! empty ( $ _SESSION [ $ name ] ) ) { unset ( $ _SESSION [ $ name ] ) ; } if ( ! empty ( $ _SESSION [ $ name . '_class' ] ) ) { unset ( $ _SESSION [ $ name . '_class' ] ) ; } $ _SESSION [ $ name ] = $ message ; $ _SESSION [ $ name . '_class' ] = $ class ; } elseif ( ! empty ( $ _SESSION [ $ name ] ) && empty ( $ message ) ) { $ class = ! empty ( $ _SESSION [ $ name . '_class' ] ) ? $ _SESSION [ $ name . '_class' ] : 'success' ; $ message = $ _SESSION [ $ name ] ; echo '<div class="ui ' . $ class . ' message">' . $ message . '</div>' ; unset ( $ _SESSION [ $ name ] ) ; unset ( $ _SESSION [ $ name . '_class' ] ) ; } } }
Function to create and display error and success messages
23,642
public static function decimalToAlphanumeric ( $ number , $ base = 64 , $ index = false ) { if ( ! $ base ) { $ base = strlen ( $ index ) ; } elseif ( ! $ index ) { $ index = substr ( "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" , 0 , $ base ) ; } $ out = "" ; for ( $ i = floor ( log10 ( $ number ) / log10 ( $ base ) ) ; $ i >= 0 ; $ i -- ) { $ no = floor ( $ num / pow ( $ base , $ i ) ) ; $ out = $ out . substr ( $ index , $ no , 1 ) ; $ number = $ number - ( $ no * pow ( $ base , $ i ) ) ; } return $ out ; }
Decimal To Alphanumeric
23,643
public static function dateRangeArray ( $ strDateFrom , $ strDateTo , $ dateFormat = 'Y-m-d' ) { $ arrayRange = array ( ) ; $ t1 = $ this -> splitDate ( $ strDateFrom , 'int' ) ; $ t2 = $ this -> splitDate ( $ strDateTo , 'int' ) ; $ iDateFrom = mktime ( 1 , 0 , 0 , $ t1 [ 'month' ] , $ t1 [ 'date' ] , $ t1 [ 'year' ] ) ; $ iDateTo = mktime ( 1 , 0 , 0 , $ t2 [ 'month' ] , $ t2 [ 'date' ] , $ t2 [ 'year' ] ) ; if ( $ iDateTo >= $ iDateFrom ) { array_push ( $ arrayRange , date ( $ dateFormat , $ iDateFrom ) ) ; while ( $ iDateFrom < $ iDateTo ) { $ iDateFrom += 86400 ; array_push ( $ arrayRange , date ( $ dateFormat , $ iDateFrom ) ) ; } } return $ arrayRange ; }
Date Range Array
23,644
public static function dateToSQL ( $ tahun , $ bulan , $ tanggal , $ minTahun = "" , $ maxTahun = "" ) { $ tahun = ( int ) $ tahun ; $ bulan = ( int ) $ bulan ; $ tanggal = ( int ) $ tanggal ; if ( $ tanggal <= 0 || $ tanggal > 31 ) { $ tanggalX = "01" ; } else if ( $ tanggal < 10 ) { $ tanggalX = "0" . $ tanggal ; } else { $ tanggalX = $ tanggal ; } if ( $ bulan <= 0 || $ bulan > 12 ) { $ bulanX = "01" ; } else if ( $ bulan < 10 ) { $ bulanX = "0" . $ bulan ; } else { $ bulanX = $ bulan ; } if ( $ minTahun != "" ) { if ( $ tahun >= $ minTahun ) { if ( $ maxTahun != "" ) { if ( $ tahun <= $ maxTahun ) { $ tahunX = $ tahun ; } else { $ tahunX = date ( "Y" ) ; } } else { $ tahunX = $ tahun ; } } else { $ tahunX = date ( "Y" ) ; } } else { if ( strlen ( $ tahun ) == 4 ) { $ tahunX = $ tahun ; } else { $ tahunX = date ( "Y" ) ; } } $ tanggalSql = $ tahunX . "-" . $ bulanX . "-" . $ tanggalX ; return $ tanggalSql ; }
Date To SQL
23,645
public static function displayDateTime ( $ date ) { $ namaBulan = $ this -> monthList ( ) ; $ dateInt = $ this -> splitDate ( $ date ) ; $ dateString = $ this -> splitDate ( $ date , 'string' ) ; return $ namaBulan [ $ dateInt [ 'month' ] ] . ' ' . $ dateInt [ 'date' ] . ', ' . $ dateInt [ 'year' ] . ' ' . $ dateString [ 'hour' ] . ':' . $ dateString [ 'minute' ] . ':' . $ dateString [ 'second' ] ; }
Display Date Time
23,646
public static function validDateForm ( $ date ) { $ isOK = true ; if ( preg_match ( "/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{2,4})/" , $ date ) ) { list ( $ d , $ m , $ y ) = explode ( "/" , $ date ) ; $ month = ( int ) $ m ; $ day = ( int ) $ d ; $ year = ( int ) $ y ; if ( ! checkdate ( $ month , $ day , $ year ) ) { $ isOK = false ; } } else { $ isOK = false ; } if ( $ isOK == false ) { $ date = date ( 'd/m/Y' ) ; } return $ date ; }
Validate Date Form
23,647
public static function dateFormToSQL ( $ date ) { list ( $ d , $ m , $ y ) = @ explode ( "/" , $ date ) ; $ month = ( int ) $ m ; $ day = ( int ) $ d ; $ year = ( int ) $ y ; if ( checkdate ( $ month , $ day , $ year ) ) { if ( $ day < 10 ) { $ day = '0' . $ day ; } if ( $ month < 10 ) { $ month = '0' . $ month ; } return $ y . '-' . $ month . '-' . $ day ; } else { return '' ; } }
Date Form To SQL
23,648
public static function dateSQLToForm ( $ date ) { if ( $ this -> isDateSQL ( $ date ) ) { $ arr = explode ( '-' , $ date ) ; $ thn = ( int ) $ arr [ 0 ] ; $ bln = ( int ) $ arr [ 1 ] ; $ tgl = ( int ) $ arr [ 2 ] ; if ( $ thn > 2000 AND $ bln <= 12 AND $ bln >= 1 AND $ tgl <= 31 AND $ tgl >= 1 ) { if ( $ tgl < 10 ) $ tgl = '0' . $ tgl ; if ( $ bln < 10 ) $ bln = '0' . $ bln ; if ( $ thn < 10 ) $ thn = '0' . $ thn ; return $ tgl . '/' . $ bln . '/' . $ thn ; } } return '' ; }
SQL Date To Date Form
23,649
public static function dateRangeInWeek ( $ week = 0 , $ year = 0 ) { $ year = ( int ) $ year ; $ week = ( int ) $ week ; if ( $ year < 1970 ) { $ year = date ( "Y" ) ; $ week = date ( "W" ) ; } if ( $ week <= 0 || $ week > 54 ) { $ week = date ( "W" ) ; $ year = date ( "Y" ) ; } $ mingguTanggalAwalTahun = date ( "W" , mktime ( 1 , 0 , 0 , 1 , 1 , $ year ) ) ; $ jumlahDetikDalamSehari = 24 * 60 * 60 ; $ jumlahDetikDalamSeminggu = $ jumlahDetikDalamSehari * 7 ; $ hariAwalTahun = date ( "w" , mktime ( 1 , 0 , 0 , 1 , 1 , $ year ) ) ; $ detikAwalTahun = date ( "U" , mktime ( 1 , 0 , 0 , 1 , 1 , $ year ) ) ; if ( $ hariAwalTahun == 0 ) { $ hariAwalTahun = 7 ; } $ jumlahHariPadaMingguPertama = ( 7 - $ hariAwalTahun ) + 1 ; $ detikTambahan = ( ( $ week - 1 ) * $ jumlahDetikDalamSeminggu ) + ( $ jumlahHariPadaMingguPertama * $ jumlahDetikDalamSehari ) ; if ( $ mingguTanggalAwalTahun == 1 ) { $ tanggalUnixSenin = $ detikAwalTahun + $ detikTambahan ; } else { $ tanggalUnixSenin = $ detikAwalTahun + $ detikTambahan + $ jumlahDetikDalamSeminggu ; } $ dateRange = array ( ) ; for ( $ i = 1 ; $ i <= 7 ; $ i ++ ) { $ dateRange [ $ i ] = date ( "Y-m-d" , ( $ tanggalUnixSenin + ( ( $ i - 1 ) * $ jumlahDetikDalamSehari ) - $ jumlahDetikDalamSeminggu ) ) ; } return $ dateRange ; }
Date Range In Week
23,650
public static function weekRangeInMonth ( $ month , $ year ) { $ year = ( int ) $ year ; $ month = ( int ) $ month ; if ( $ year < 1970 ) { $ month = date ( "n" ) ; $ year = date ( "Y" ) ; } if ( $ month <= 0 || $ month > 12 ) { $ month = date ( "n" ) ; $ year = date ( "Y" ) ; } if ( $ month < 10 ) { $ month2 = '0' . $ month ; } else { $ month2 = $ month ; } $ weekAwal = ( int ) $ this -> weekNumber ( $ year . '-' . $ month2 . '-01' ) ; $ weekAkhir = ( int ) $ this -> weekNumber ( $ year . '-' . $ month2 . '-' . $ this -> maxDateInMonth ( $ month , $ year ) ) ; if ( $ weekAwal > $ weekAkhir ) { $ weekAwal = 1 ; } $ a = 0 ; for ( $ i = $ weekAwal ; $ i <= $ weekAkhir ; $ i ++ ) { $ a ++ ; $ weekRange [ $ a ] = ( int ) $ i ; } return $ weekRange ; }
Week Range In Month
23,651
public static function getDateSQLToForm ( $ datetime ) { $ t = $ this -> splitDate ( $ datetime , false ) ; return $ t [ 'date' ] . '/' . $ t [ 'month' ] . '/' . $ t [ 'year' ] ; }
Date SQL to Form
23,652
public static function timeToSec ( $ time ) { $ split_time = explode ( ':' , $ time ) ; $ hour = $ split_time [ 0 ] * 3600 ; $ minutes = $ split_time [ 1 ] * 60 ; $ second = $ split_time [ 2 ] * 1 ; $ timetosec = ( int ) ( $ hour + $ minutes + $ second ) ; return $ timetosec ; }
Time To Sec
23,653
public static function secToTime ( $ sec ) { $ hour = ( int ) floor ( $ sec / 3600 ) ; $ minutes = ( int ) floor ( ( $ sec % 3600 ) / 60 ) ; $ second = ( int ) $ sec - ( ( $ hour * 3600 ) + ( $ minutes * 60 ) ) ; if ( $ hour <= 9 ) { $ hour = '0' . $ hour ; } if ( $ minutes <= 9 ) { $ minutes = '0' . $ minutes ; } if ( $ second <= 9 ) { $ second = '0' . $ second ; } return $ hour . ':' . $ minutes . ':' . $ second ; }
Sec to Time
23,654
public static function timeToInt ( $ time ) { $ timeHour = substr ( $ time , 0 , 2 ) ; if ( substr ( $ time , 0 , 1 ) == '0' ) { $ timeHour = substr ( $ time , 1 , 1 ) ; } $ timeMin = substr ( $ time , 3 , 5 ) ; $ timeHourMin = ( ( int ) $ timeHour * 60 ) + ( ( int ) $ timeMin / 1 ) ; $ values = $ timeHourMin ; return $ values ; }
Time to Integer
23,655
public static function timeToText ( $ time ) { $ timeHour = ceil ( $ time * 60 ) ; $ modMinutes = $ timeHour % 60 ; $ hour = floor ( $ time ) ; return $ hour . ' h ' . $ modMinutes . ' m' ; }
Time To Text
23,656
public static function countMonthBetweenDate ( $ startDate , $ endDate ) { $ d1 = strtotime ( $ startDate ) ; $ d2 = strtotime ( $ endDate ) ; $ min_date = min ( $ d1 , $ d2 ) ; $ max_date = max ( $ d1 , $ d2 ) ; $ i = 0 ; while ( ( $ min_date = strtotime ( "+1 MONTH" , $ min_date ) ) <= $ max_date ) { $ i ++ ; } echo $ i ; }
Count Month Between Date
23,657
public static function monthListBetweenDate ( $ startDate , $ endDate ) { $ output = [ ] ; $ time = strtotime ( $ startDate ) ; $ last = date ( 'm-Y' , strtotime ( $ endDate ) ) ; do { $ month = date ( 'm-Y' , $ time ) ; $ total = date ( 't' , $ time ) ; $ output [ ] = [ 'month' => $ month , 'total' => $ total , ] ; $ time = strtotime ( '+1 month' , $ time ) ; } while ( $ month != $ last ) ; }
Get Month List And Month Total
23,658
public function get ( $ modelName ) { $ modelNamespace = Configuration :: read ( 'mvc.model.namespace' ) ; $ modelNamespace = $ modelNamespace . '\\' . ucFirst ( $ modelName ) ; if ( ! class_exists ( $ modelNamespace ) ) { trigger_error ( 'Model "' . $ modelNamespace . '" doesn\'t exist.' , E_USER_ERROR ) ; return false ; } return new $ modelNamespace ( ) ; }
Call a model class
23,659
public function path ( $ path = null ) { return is_null ( $ path ) ? Path :: join ( $ this -> path , $ this -> ref ) : Path :: join ( $ this -> path , $ this -> ref , $ path ) ; }
Get the absolute path to a file in the project using the current ref
23,660
public function getDocumentsMenu ( ) { $ yaml = $ this -> files -> get ( Path :: join ( $ this -> path , $ this -> ref , 'menu.yml' ) ) ; $ array = Yaml :: parse ( $ yaml ) ; $ this -> factory -> getMenus ( ) -> forget ( 'project_sidebar_menu' ) ; $ menu = $ this -> resolveDocumentsMenu ( $ array [ 'menu' ] ) ; $ menu -> setView ( 'docit::menus/project-sidebar' ) ; $ this -> runHook ( 'project:documents-menu' , [ $ this , $ menu ] ) ; return $ menu ; }
Returns the menu for this project
23,661
protected function resolveDocumentsMenu ( $ items , $ parentId = 'root' ) { $ menu = $ this -> factory -> getMenus ( ) -> add ( 'project_sidebar_menu' ) ; foreach ( $ items as $ item ) { $ link = '#' ; if ( array_key_exists ( 'document' , $ item ) ) { $ path = Str :: endsWith ( $ item [ 'document' ] , '.md' , false ) ? Str :: remove ( $ item [ 'document' ] , '.md' ) : $ item [ 'document' ] ; $ link = $ this -> factory -> url ( $ this , $ this -> ref , $ path ) ; } elseif ( array_key_exists ( 'href' , $ item ) ) { $ link = $ item [ 'href' ] ; } $ id = md5 ( $ item [ 'name' ] . $ link ) ; $ node = $ menu -> add ( $ id , $ item [ 'name' ] , $ parentId ) ; $ node -> setAttribute ( 'href' , $ link ) ; $ node -> setAttribute ( 'id' , $ id ) ; if ( isset ( $ item [ 'icon' ] ) ) { $ node -> setMeta ( 'icon' , $ item [ 'icon' ] ) ; } if ( isset ( $ item [ 'children' ] ) ) { $ this -> resolveDocumentsMenu ( $ item [ 'children' ] , $ id ) ; } } return $ menu ; }
Resolves and creates the documents menu from the parsed menu . yml
23,662
public function getSortedRefs ( ) { $ versions = $ this -> versions ; usort ( $ versions , function ( version $ v1 , version $ v2 ) { return version :: gt ( $ v1 , $ v2 ) ? - 1 : 1 ; } ) ; $ versions = array_map ( function ( version $ v ) { return $ v -> getVersion ( ) ; } , $ versions ) ; return array_merge ( $ this -> branches , $ versions ) ; }
Get refs sorted by the configured order .
23,663
public static function url ( $ url ) { $ url = static :: _nullValue ( $ url ) ; if ( ! $ url ) { return $ url ; } $ query = parse_url ( $ url , PHP_URL_QUERY ) ; if ( ! $ query ) { return $ url ; } parse_str ( $ query , $ query_parts ) ; $ query_parts = array_map ( 'static::_nested_urldecode' , $ query_parts ) ; return strtok ( $ url , '?' ) . '?' . http_build_query ( $ query_parts ) ; }
This will rebuild the url with all the query - parts url_encoded .
23,664
public static function replaceHttpsUrls ( $ value ) { $ value = str_ireplace ( 'http://cdn.prtl.eu' , '//cdn.prtl.eu' , $ value ) ; $ value = str_ireplace ( 'http://cdn2.prtl.eu' , '//cdn2.prtl.eu' , $ value ) ; $ value = str_ireplace ( 'http://studyportals-cdn2.imgix.net' , '//studyportals-cdn2.imgix.net' , $ value ) ; $ value = str_ireplace ( 'http://www.admissiontestportal.com' , 'https://www.admissiontestportal.com' , $ value ) ; $ value = str_ireplace ( 'http://www.preparationcoursesportal.com' , 'https://www.preparationcoursesportal.com' , $ value ) ; return $ value ; }
Find en replaces all http urls which should be https .
23,665
public function url ( $ project = null , $ ref = null , $ doc = null ) { $ uri = $ this -> config ( 'base_route' ) ; if ( ! is_null ( $ project ) ) { if ( ! $ project instanceof Project ) { $ project = $ this -> getProject ( $ project ) ; } $ uri .= '/' . $ project -> getName ( ) ; if ( ! is_null ( $ ref ) ) { $ uri .= '/' . $ ref ; } else { $ uri .= '/' . $ project -> getDefaultRef ( ) ; } if ( ! is_null ( $ doc ) ) { $ uri .= '/' . $ doc ; } } return url ( $ uri ) ; }
Generate a URL to a project s default page and version .
23,666
public function without ( $ array ) { $ values = func_get_args ( ) ; unset ( $ values [ 0 ] ) ; if ( $ values ) { foreach ( $ values as $ value ) { unset ( $ array [ array_search ( $ value , $ array ) ] ) ; } } return $ array ; }
Produces a new version of the array that does not contain any of the specified values
23,667
public function pluck ( $ array , $ property , & $ return = false ) { $ return = [ ] ; if ( count ( $ array ) > 0 ) { foreach ( $ array as $ item ) { if ( is_array ( $ item ) ) { $ this -> pluck ( $ array , $ property , $ return ) ; } $ return [ ] = $ item -> $ property ; } } return $ return ; }
Fetch the same property for all the elements .
23,668
public function toXML ( $ data , $ rootNodeName = 'ResultSet' , & $ xml = null ) { if ( ini_get ( 'zend.ze1_compatibility_mode' ) == 1 ) { ini_set ( 'zend.ze1_compatibility_mode' , 0 ) ; } if ( is_null ( $ xml ) ) { $ xml = simplexml_load_string ( "<?xml version='1.0' encoding='utf-8'?><$rootNodeName />" ) ; } foreach ( $ data as $ key => $ value ) { if ( is_numeric ( $ key ) ) { $ numeric = 1 ; $ key = $ rootNodeName ; } $ key = preg_replace ( '/[^a-z0-9\-\_\.\:]/i' , '' , $ key ) ; if ( is_array ( $ value ) ) { $ node = $ this -> isAssoc ( $ value ) || $ numeric ? $ xml -> addChild ( $ key ) : $ xml ; if ( $ numeric ) { $ key = 'anon' ; } $ this -> toXML ( $ value , $ key , $ node ) ; } else { $ value = htmlentities ( $ value ) ; $ xml -> addAttribute ( $ key , $ value ) ; } } $ doc = new DOMDocument ( '1.0' ) ; $ doc -> preserveWhiteSpace = false ; $ doc -> loadXML ( $ xml -> asXML ( ) ) ; $ doc -> formatOutput = true ; return $ doc -> saveXML ( ) ; }
Pass in a multi dimensional array and this recrusively loops through and builds up an XML document .
23,669
public function getRandom ( $ byteLength = 16 , $ rawBytes = false ) { $ randomBytes = random_bytes ( $ byteLength ) ; if ( $ rawBytes ) { return $ randomBytes ; } return bin2hex ( $ randomBytes ) ; }
Get a random byte string .
23,670
public function readFile ( $ filePath ) { if ( false === $ fileContent = @ file_get_contents ( $ filePath ) ) { throw new RuntimeException ( sprintf ( 'unable to read file "%s"' , $ filePath ) ) ; } return $ fileContent ; }
Read a file from the file system .
23,671
public function readFolder ( $ folderPath , $ fileFilter = '*' ) { if ( '/' !== substr ( $ folderPath , - 1 ) ) { $ folderPath .= '/' ; } $ searchPattern = $ folderPath . $ fileFilter ; $ fileList = @ glob ( $ searchPattern , GLOB_MARK | GLOB_ERR ) ; if ( false === $ fileList ) { return [ ] ; } return $ fileList ; }
Read a folder and return a list of files in that folder .
23,672
public function writeFile ( $ filePath , $ fileContent , $ createParentDir = false , $ dirMask = 0750 ) { if ( $ createParentDir ) { $ parentDir = dirname ( $ filePath ) ; if ( false === @ file_exists ( $ parentDir ) ) { if ( false === @ mkdir ( $ parentDir , $ dirMask , true ) ) { throw new RuntimeException ( sprintf ( 'unable to create directory "%s"' , $ parentDir ) ) ; } } } if ( false === @ file_put_contents ( $ filePath , $ fileContent ) ) { throw new RuntimeException ( sprintf ( 'unable to write file "%s"' , $ filePath ) ) ; } }
Write a file to the file system .
23,673
public static function makeFromFiles ( string ... $ paths ) : ConfigCollection { $ definitions = array_map ( function ( string $ path ) : array { try { $ definitions = ( array ) Toml :: parseFile ( $ path ) ; } catch ( ParseException $ _parseException ) { $ definitions = [ ] ; } return $ definitions ; } , $ paths ) ; $ mergedDefinitions = array_reduce ( $ definitions , function ( array $ merged , array $ definition ) : array { return self :: arrayMergeRecursiveDistinct ( $ merged , $ definition ) ; } , [ ] ) ; return new ConfigCollection ( $ mergedDefinitions ) ; }
Parses the TOML and returns a config instance .
23,674
private static function arrayMergeRecursiveDistinct ( array $ merged , array $ other ) : array { foreach ( $ other as $ key => $ value ) { if ( is_array ( $ value ) && is_array ( $ merged [ $ key ] ?? [ ] ) ) { $ merged [ $ key ] = self :: arrayMergeRecursiveDistinct ( $ merged [ $ key ] ?? [ ] , $ value ) ; } elseif ( is_int ( $ key ) ) { $ merged = array_unique ( array_merge ( $ merged , [ $ value ] ) ) ; } else { $ merged [ $ key ] = $ value ; } } return $ merged ; }
This does not change the data types of the values in the arrays . Matching keys values in the second array overwrite those in the first array as is the case with array_merge .
23,675
public function connect ( ) { $ connectTimeout = 1 ; $ errstr = '' ; $ errno = 0 ; $ stream = @ stream_socket_client ( $ this -> nodeUrl , $ errno , $ errstr , $ connectTimeout ) ; if ( ! $ stream ) { $ this -> log -> warning ( 'unable to connect to ' . $ this -> nodeUrl . ': ' . $ errstr ) ; throw new ConnectException ( 'Unable to connect to resource ' . $ this -> nodeUrl . '. ' . $ errstr , $ errno ) ; } $ this -> log -> info ( 'connected to ' . $ this -> nodeUrl ) ; $ this -> stream = $ stream ; return true ; }
Connect the stream .
23,676
public function readLine ( ) { $ this -> log -> debug ( 'going to read a line from the stream' ) ; $ line = $ this -> streamReadLine ( $ this -> stream ) ; if ( false === $ line ) { $ meta = $ this -> streamMeta ( $ this -> stream ) ; $ this -> log -> warning ( 'fgets returned false' , $ meta ) ; throw new StreamException ( StreamException :: OP_READ , 'stream_get_line returned false' ) ; } $ this -> log -> debug ( 'readLine()' , [ $ line ] ) ; return $ line ; }
Read a line from the stream .
23,677
public function readBytes ( $ maxlen = null ) { $ this -> log -> debug ( 'calling readbytes()' , array ( 'maxlen' => $ maxlen ) ) ; $ out = $ this -> streamReadBytes ( $ this -> stream , $ maxlen ) ; $ this -> log -> debug ( 'readBytes()' , [ $ maxlen , $ out ] ) ; if ( false === $ out ) { $ meta = $ this -> streamMeta ( $ this -> stream ) ; $ this -> log -> warning ( 'stream_get_contents returned false' , $ meta ) ; throw new StreamException ( StreamException :: OP_READ , 'stream_get_contents returned false' ) ; } return $ out ; }
Read bytes off from the stream .
23,678
public static function load ( string $ dir , int $ depth = 6 , array $ priority = [ ] , array $ extensions = [ 'php' ] ) { if ( $ depth == 0 ) { return ; } foreach ( $ priority as $ file ) { self :: load ( $ file , 1 , [ ] , $ extensions ) ; } $ filesAndFolders = glob ( $ dir . DIRECTORY_SEPARATOR . "*" ) ; foreach ( $ filesAndFolders as $ path ) { if ( is_dir ( $ path ) ) { self :: load ( $ path , $ depth - 1 , [ ] , $ extensions ) ; } elseif ( in_array ( pathinfo ( $ path , PATHINFO_EXTENSION ) , $ extensions ) ) { require_once $ path ; } } }
Load files in the given directory and the files under its folders with maximum depth
23,679
public static function getAllChildClasses ( $ class ) : array { $ type = gettype ( $ class ) ; $ className = '' ; if ( $ type == 'object' ) { $ className = get_class ( $ class ) ; } elseif ( $ type == 'string' ) { $ className = $ class ; } $ classes = [ ] ; foreach ( get_declared_classes ( ) as $ class ) { if ( is_subclass_of ( $ class , $ className ) ) { $ classes [ ] = $ class ; } } return $ classes ; }
Get all child classes of a class
23,680
public function load ( $ dir , $ env = null , $ basename = 'config' , $ extension = 'yml' ) { $ filepath = $ dir . '/' . $ basename . '.' . $ extension ; if ( ! file_exists ( $ filepath ) ) { throw new \ Exception ( sprintf ( "Config file \"%s\" does not exist" , $ filepath ) ) ; } $ parameters = Yaml :: parse ( $ filepath ) ; if ( $ env ) { $ filepath = $ dir . '/' . $ basename . '_' . $ env . '.' . $ extension ; if ( file_exists ( $ filepath ) ) { $ envParameters = Yaml :: parse ( $ filepath ) ; if ( $ envParameters ) { $ parameters = $ this -> deepMerge ( $ parameters , $ envParameters ) ; } } } return $ parameters ; }
Load the config
23,681
protected function deepMerge ( $ leftSide , $ rightSide ) { if ( ! is_array ( $ rightSide ) ) { return $ rightSide ; } foreach ( $ rightSide as $ k => $ v ) { if ( ! array_key_exists ( $ k , $ leftSide ) ) { $ leftSide [ $ k ] = $ v ; continue ; } $ leftSide [ $ k ] = $ this -> deepMerge ( $ leftSide [ $ k ] , $ v ) ; } return $ leftSide ; }
Do a deep merge of two arrays
23,682
private function resolveParameters ( string $ id , array $ parameters , ContainerInterface $ container ) : array { $ resolved = [ ] ; foreach ( $ parameters as $ parameter ) { $ resolved [ ] = $ this -> getParameterValue ( $ id , $ parameter , $ container ) ; } return $ resolved ; }
Resolve the parameters
23,683
private function getParameterValue ( string $ id , ReflectionParameter $ parameter , ContainerInterface $ container ) { if ( ! ( $ class = $ parameter -> getClass ( ) ) ) { if ( $ parameter -> isDefaultValueAvailable ( ) ) { return $ parameter -> getDefaultValue ( ) ; } throw new FatalNotFoundException ( "Cannot resolve '" . $ parameter -> getName ( ) . "' for class '" . $ id . "'" ) ; } try { return $ container -> get ( $ class -> getName ( ) ) ; } catch ( NotFoundException $ e ) { if ( $ parameter -> isDefaultValueAvailable ( ) ) { return $ parameter -> getDefaultValue ( ) ; } throw $ e ; } }
Get the parameter value
23,684
public function render ( $ with_headers = false ) { $ contents = array ( ) ; $ headers = $ this -> getHeaders ( ) ; if ( $ with_headers && $ headers ) { foreach ( $ headers as $ key => $ value ) { $ key = join ( '-' , array_map ( 'ucfirst' , explode ( '-' , $ key ) ) ) ; $ contents [ ] = sprintf ( '%s: %s' , $ key , $ value ) ; } $ contents [ ] = '' ; } $ contents [ ] = $ this -> content ; return join ( "\n" , $ contents ) ; }
build and return content string .
23,685
protected function getEntityGenerator ( ) { $ entityGenerator = new EntityGenerator ( ) ; $ entityGenerator -> setFieldVisibility ( EntityGenerator :: FIELD_VISIBLE_PROTECTED ) ; $ entityGenerator -> setGenerateAnnotations ( false ) ; $ entityGenerator -> setGenerateStubMethods ( true ) ; $ entityGenerator -> setRegenerateEntityIfExists ( false ) ; $ entityGenerator -> setUpdateEntityIfExists ( true ) ; $ entityGenerator -> setNumSpaces ( 4 ) ; $ entityGenerator -> setAnnotationPrefix ( 'ORM\\' ) ; if ( $ this -> configuration [ 'with_interface' ] ) { $ entityGenerator -> setClassToInterface ( $ this -> configuration [ 'namespace' ] . '\\' . $ this -> model . 'Interface' ) ; } return $ entityGenerator ; }
get entity generator
23,686
public function visit ( AccountInfoList $ accountList ) { $ list = new Simplified \ AccountList ( ) ; foreach ( $ accountList -> accountInfo as $ accountInfo ) { $ list -> accounts [ ] = $ this -> visitAccount ( $ accountInfo ) ; } return $ list ; }
Visit account info list
23,687
public function set_options ( array $ options ) { foreach ( $ options as $ key => $ val ) { $ this -> options [ $ key ] = $ val ; } return $ this ; }
Sets options on the driver
23,688
public function set_header ( $ header , $ content = null ) { if ( is_null ( $ content ) ) { $ this -> headers [ ] = $ header ; } else { $ this -> headers [ $ header ] = $ content ; } return $ this ; }
set a request http header
23,689
public function get_headers ( ) { $ headers = array ( ) ; foreach ( $ this -> headers as $ key => $ value ) { $ headers [ ] = is_int ( $ key ) ? $ value : $ key . ': ' . $ value ; } return $ headers ; }
Collect all headers and parse into consistent string
23,690
public function set_mime_type ( $ mime ) { if ( array_key_exists ( $ mime , static :: $ supported_formats ) ) { $ mime = static :: $ supported_formats [ $ mime ] ; } $ this -> set_header ( 'Accept' , $ mime ) ; return $ this ; }
Set mime - type accept header
23,691
protected function set_defaults ( ) { $ this -> options = $ this -> default_options ; $ this -> params = $ this -> default_params ; return $ this ; }
Reset before doing another request
23,692
protected function mime_in_header ( $ mime , $ accept_header ) { if ( empty ( $ mime ) or empty ( $ accept_header ) ) { return true ; } $ accept_mimes = array ( ) ; $ accept_header = explode ( ',' , $ accept_header ) ; foreach ( $ accept_header as $ accept_def ) { $ accept_def = explode ( ';' , $ accept_def ) ; $ accept_def = trim ( $ accept_def [ 0 ] ) ; if ( ! in_array ( $ accept_def , $ accept_mimes ) ) { $ accept_mimes [ ] = $ accept_def ; } } if ( in_array ( '*/*' , $ accept_mimes ) ) { return true ; } if ( in_array ( $ mime , $ accept_mimes ) ) { return true ; } $ mime = substr ( $ mime , 0 , strpos ( $ mime , '/' ) ) . '/*' ; if ( in_array ( $ mime , $ accept_mimes ) ) { return true ; } return false ; }
Validate if a given mime type is accepted according to an accept header
23,693
public function set_response ( $ body , $ status , $ mime = null , $ headers = array ( ) , $ accept_header = null ) { if ( ! $ this -> mime_in_header ( $ mime , $ accept_header ) ) { throw new \ OutOfRangeException ( 'The mimetype "' . $ mime . '" of the returned response is not acceptable according to the accept header send.' ) ; } if ( $ this -> auto_format and array_key_exists ( $ mime , static :: $ auto_detect_formats ) ) { $ body = \ Format :: forge ( $ body , static :: $ auto_detect_formats [ $ mime ] ) -> to_array ( ) ; } $ this -> response = \ Response :: forge ( $ body , $ status , $ headers ) ; return $ this -> response ; }
Creates the Response and optionally attempts to auto - format the output
23,694
public function response_info ( $ key = null , $ default = null ) { if ( func_num_args ( ) == 0 ) { return $ this -> response_info ; } return \ Arr :: get ( $ this -> response_info , $ key , $ default ) ; }
Fetch the response info or a key from it
23,695
public static function filterMarkdownContent ( ? string $ content , bool $ compute , bool $ fullMarkdown = false ) : ? string { return $ compute ? ( $ fullMarkdown ? self :: escapeAndMarkdown ( $ content ) : self :: escapeAndMarkdownLight ( $ content ) ) : $ content ; }
Common filter for markdown content for getters
23,696
public static function filterContent ( ? string $ content , bool $ escape , bool $ nl2br = false ) : ? string { return $ escape ? Html :: escape ( $ content , $ nl2br ) : $ content ; }
Common filter for general content for getters
23,697
public function showAction ( Localidad $ localidad ) { $ deleteForm = $ this -> createDeleteForm ( $ localidad ) ; return $ this -> render ( 'UbicacionBundle:localidad:show.html.twig' , array ( 'localidad' => $ localidad , 'delete_form' => $ deleteForm -> createView ( ) , ) ) ; }
Finds and displays a Localidad entity .
23,698
public function editAction ( Request $ request , Localidad $ localidad ) { $ deleteForm = $ this -> createDeleteForm ( $ localidad ) ; $ editForm = $ this -> createForm ( 'Matudelatower\UbicacionBundle\Form\Type\LocalidadType' , $ localidad ) ; $ editForm -> handleRequest ( $ request ) ; if ( $ editForm -> isSubmitted ( ) && $ editForm -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> persist ( $ localidad ) ; $ em -> flush ( ) ; return $ this -> redirectToRoute ( 'localidad_edit' , array ( 'id' => $ localidad -> getId ( ) ) ) ; } return $ this -> render ( 'UbicacionBundle:localidad:edit.html.twig' , array ( 'localidad' => $ localidad , 'edit_form' => $ editForm -> createView ( ) , 'delete_form' => $ deleteForm -> createView ( ) , ) ) ; }
Displays a form to edit an existing Localidad entity .
23,699
public function deleteAction ( Request $ request , Localidad $ localidad ) { $ form = $ this -> createDeleteForm ( $ localidad ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> remove ( $ localidad ) ; $ em -> flush ( ) ; } return $ this -> redirectToRoute ( 'localidad_index' ) ; }
Deletes a Localidad entity .