idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
4,000
private function jqFilterQuery ( ) { if ( ( $ filter = \ Input :: get ( 'filter' ) ) && is_array ( $ filter ) ) { $ this -> setJqGridQuery ( $ this -> jqGridQuery -> where ( function ( $ query ) use ( $ filter ) { foreach ( $ filter as $ k => $ val ) { $ field = $ this -> getJqFilterField ( $ k ) ; if ( is_array ( $ va...
Build query for filters .
4,001
private function jqOrderQuery ( ) { if ( $ orderIndex = \ Input :: get ( 'sidx' ) ) { $ this -> setJqGridQuery ( $ this -> jqGridQuery -> orderBy ( $ this -> getJqSearchField ( $ orderIndex ) , \ Input :: get ( 'sord' ) ) ? : 'asc' ) ; } return $ this ; }
Build query for order .
4,002
public function makeJqGrid ( ) { $ data = $ this -> jqSearchQuery ( ) -> jqFilterQuery ( ) -> jqOrderQuery ( ) -> getJqGridQuery ( ) -> paginate ( ( \ Input :: get ( 'rows' ) ? : 15 ) ) ; $ out = $ data -> getCollection ( ) -> toArray ( ) ; return [ 'Page' => $ data -> getCurrentPage ( ) , 'Total' => ceil ( $ data -> g...
Return formatted data to be parsed by jqgrid .
4,003
public function has ( string $ key ) : bool { if ( ! array_key_exists ( $ key , $ this -> data ) ) { return false ; } return true ; }
Checks if an entry exists .
4,004
protected function includeControllersModelsEntities ( $ class ) { foreach ( $ this -> internalStructure as $ Directory ) { if ( $ this -> includeTheFile ( $ this -> autoloadPath . '/' . $ Directory . '/' . $ class . '.php' ) ) { return true ; } } return false ; }
Include the common directories of .
4,005
protected function includeTheFile ( $ path ) { $ path = $ this -> urlBase . $ path ; if ( file_exists ( $ path ) ) { require_once ( $ path ) ; return true ; } return false ; }
Include the file if exists
4,006
public function getUser ( ) { if ( null === $ token = $ this -> security -> getToken ( ) ) { return null ; } $ user = $ token -> getUser ( ) ; if ( ! is_object ( $ user ) ) { return null ; } return $ user ; }
Get a user from the Security Context Borrowed from Silex \ Application \ SecurityTrait
4,007
protected function taskPhpCs ( $ dir = null , $ standard = "PSR1,PSR2" , $ extensions = [ 'php' , 'inc' ] ) { return $ this -> task ( PhpCs :: class , $ dir , $ standard , $ extensions ) ; }
Creates a PhpCs task .
4,008
public function getShortDescription ( ) { $ comments = preg_split ( "/(\n|\r|\r\n)/" , $ this -> method -> getDocComment ( ) ) ; foreach ( $ comments as $ comment ) { $ comment = trim ( $ comment ) ; if ( $ comment === '/**' ) continue ; return preg_replace ( '/^\s*\*\s*/' , '' , $ comment ) ; } return '' ; }
get short description
4,009
public function onContentPrepare ( $ context , & $ row , & $ params , $ page = 0 ) { $ canProceed = $ context == 'com_content.article' ; if ( ! $ canProceed ) { return ; } if ( is_object ( $ row ) ) { return $ this -> render ( $ row -> text , $ params ) ; } return $ this -> render ( $ row , $ params ) ; }
Plugin that adds a pagebreak into the text and truncates text at that point
4,010
protected function createSchema ( Closure $ blueprint ) { if ( $ this -> hasConnection ( ) ) { Schema :: connection ( $ this -> getConnection ( ) ) -> create ( $ this -> getTableName ( ) , $ blueprint ) ; } else { Schema :: create ( $ this -> getTableName ( ) , $ blueprint ) ; } }
Create Table Schema .
4,011
private static function generateMockClassName ( \ ReflectionClass $ rc ) : string { $ src_class_name = $ rc -> getName ( ) ; $ pos = strrpos ( $ src_class_name , '\\' ) ; if ( $ pos === false ) { $ dest_class_name = $ src_class_name ; } else { $ dest_class_name = substr ( $ src_class_name , $ pos + 1 ) ; } return Code ...
Generate mock class file into cache directory
4,012
private function generateClassCode ( \ ReflectionClass $ rc ) : array { $ mocked_class_name = self :: generateMockClassName ( $ rc ) ; $ namespace = $ rc -> getNamespaceName ( ) ; $ mock_target_class = $ rc -> getShortName ( ) ; $ methods = $ rc -> getMethods ( ) ; $ methods = array_filter ( $ methods , function ( $ it...
Generate class mock code
4,013
private function generateMethodCode ( \ ReflectionMethod $ rm ) : array { $ method_name = $ rm -> getName ( ) ; $ modifiers = $ rm -> getModifiers ( ) ; $ params = $ rm -> getParameters ( ) ; $ has_return_type = $ rm -> hasReturnType ( ) ; $ return_type = $ rm -> getReturnType ( ) ; $ is_static = Util :: isAllBitSet ( ...
Generate method mock code
4,014
private static function generateParameterPrototypeCode ( \ ReflectionParameter $ rp ) : string { $ param_name = $ rp -> getName ( ) ; $ has_type = $ rp -> hasType ( ) ; $ type = $ rp -> getType ( ) ; $ class = $ rp -> getClass ( ) ; $ optional = $ rp -> isOptional ( ) ; $ default = $ optional ? self :: describeDefault ...
Generate method parameter prototype code
4,015
protected function redirectToStep ( $ step ) { $ routeMatch = $ this -> getEvent ( ) -> getRouteMatch ( ) ; return $ this -> redirect ( ) -> toRoute ( $ routeMatch -> getMatchedRouteName ( ) , ArrayUtils :: merge ( $ routeMatch -> getParams ( ) , array ( 'step' => $ step ) ) ) ; }
Get redirect uri according to a step
4,016
protected function getStore ( ) { $ store = $ this -> getSessionContainer ( ) ; if ( empty ( $ store [ 'stack' ] ) ) { $ store [ 'stack' ] = array ( ) ; } if ( empty ( $ store [ 'steps' ] ) ) { $ store [ 'steps' ] = array ( ) ; } return $ store ; }
Get session container
4,017
protected function pushStepStack ( $ step ) { $ store = $ this -> getStore ( ) ; $ stack = $ store [ 'stack' ] ; array_push ( $ stack , ( string ) $ step ) ; $ store [ 'stack' ] = $ stack ; return $ this ; }
Push step - stack
4,018
protected function popStepStack ( ) { $ store = $ this -> getStore ( ) ; $ stack = $ store [ 'stack' ] ; $ step = array_pop ( $ stack ) ; $ store [ 'stack' ] = $ stack ; return $ step ; }
Pop step - stack
4,019
protected function topStepStack ( ) { $ store = $ this -> getStore ( ) ; $ stack = $ store [ 'stack' ] ; if ( empty ( $ stack ) ) { return null ; } return end ( $ stack ) ; }
Top step - stack
4,020
public function getStepStore ( $ step ) { $ store = $ this -> getStore ( ) ; $ steps = $ store [ 'steps' ] ; $ step = ( string ) $ step ; if ( empty ( $ steps [ $ step ] ) ) { $ steps [ $ step ] = array ( ) ; $ store [ 'steps' ] = $ steps ; } return $ steps [ $ step ] ; }
Get step - store
4,021
public function getStepStores ( $ flat = true ) { $ store = $ this -> getStore ( ) ; $ steps = $ store [ 'steps' ] ; $ result = array ( ) ; foreach ( $ store [ 'stack' ] as $ step ) { $ stepStore = $ steps [ $ step ] ; if ( $ flat ) { $ result = array_merge ( $ result , $ stepStore ) ; } else { $ result [ $ step ] = $ ...
Get step - stores
4,022
public function setStepStore ( $ step , array $ data ) { $ store = $ this -> getStore ( ) ; $ steps = $ store [ 'steps' ] ; $ step = ( string ) $ step ; $ steps [ $ step ] = $ data ; $ store [ 'steps' ] = $ steps ; return $ this ; }
Set step - store
4,023
public function PreDispatch ( ) { parent :: PreDispatch ( ) ; if ( $ this -> translateOptions ) { $ form = & $ this -> form ; foreach ( $ this -> options as $ key => $ value ) $ this -> options [ $ key ] = $ form -> Translate ( $ key ) ; } }
This INTERNAL method is called from \ MvcCore \ Ext \ Form just before field is naturally rendered . It sets up field for rendering process . Do not use this method even if you don t develop any form field . - Set up field render mode if not defined . - Translate options if necessary .
4,024
public static function factory ( RendererInterface $ renderer , BaseDataObject $ object , $ urlType , array $ attributes = array ( ) ) { $ htmlRenderer = new self ( ) ; $ htmlRenderer -> setRenderer ( $ renderer ) ; $ htmlRenderer -> setObject ( $ object ) ; $ htmlRenderer -> setUrlType ( $ urlType ) ; $ htmlRenderer -...
Standard factory method to instantiate a populated object .
4,025
private function _getData ( $ primaryKey ) { $ table = $ this -> table ; $ db = $ this -> db ; $ query = "SELECT * FROM {$table->getTableName()} WHERE {$table->getPrimaryKey()} = $primaryKey" ; $ sth = $ table -> getAdapter ( ) -> prepare ( $ query ) ; $ sth -> execute ( ) ; return $ sth -> fetch ( $ db :: FETCH_ASSOC ...
Populate row data
4,026
private function checkRelationship ( $ method ) { $ table = $ this -> table ; $ one = $ table -> getOneRelationship ( ) ; $ many = $ table -> getManyRelationship ( ) ; $ belongsTo = $ table -> getBelongsToRelationship ( ) ; $ type = null ; $ params = null ; if ( ! is_null ( $ one ) && array_key_exists ( $ method , $ on...
Check if exist relationship alias
4,027
public function equals ( Money $ money ) { return $ this -> isSameCurrency ( $ money ) && $ this -> amount -> equals ( $ money -> amount , $ this -> getInnerPrecision ( ) ) ; }
Checks whether the value represented by this object equals to the other
4,028
public function compare ( Money $ money ) { $ this -> assertSameCurrency ( $ money ) ; return $ this -> amount -> comp ( $ money -> amount , $ this -> getInnerPrecision ( ) ) ; }
Returns an integer less than equal to or greater than zero if the value of this object is considered to be respectively less than equal to or greater than the other
4,029
public function toSubunits ( $ roundingMode = self :: ROUND_HALF_UP ) { $ this -> assertRoundingMode ( $ roundingMode ) ; $ precision = $ this -> getPrecision ( ) ; if ( null === $ roundingMode ) { $ amount = $ this -> amount -> round ( $ precision ) ; } else { $ amount = Math :: bcround ( $ this -> amount , $ precisio...
Returns the value represented by this object
4,030
public function add ( Money $ money ) { $ this -> assertSameCurrency ( $ money ) ; $ amount = $ this -> amount -> add ( $ money -> amount , $ this -> getInnerPrecision ( ) ) ; return $ this -> newInstance ( $ amount ) ; }
Returns a new Money object that represents the sum of this and an other Money object
4,031
public function subtract ( Money $ money ) { $ this -> assertSameCurrency ( $ money ) ; $ amount = $ this -> amount -> sub ( $ money -> amount , $ this -> getInnerPrecision ( ) ) ; return $ this -> newInstance ( $ amount ) ; }
Returns a new Money object that represents the difference of this and an other Money object
4,032
private function assertIntegerBounds ( $ int ) { if ( $ int > PHP_INT_MAX ) { throw new Exception \ OverflowException ; } elseif ( $ int < ~ PHP_INT_MAX ) { throw new Exception \ UnderflowException ; } }
Asserts that an integer value didn t become something else
4,033
private function assertRoundingMode ( $ roundingMode ) { if ( $ roundingMode !== null && ! in_array ( $ roundingMode , $ this -> roundingModes ) ) { throw new Exception \ InvalidArgumentException ( sprintf ( 'Rounding mode should be %s' , implode ( ' | ' , array_map ( function ( $ constant ) { return __CLASS__ . '::' ....
Asserts that rounding mode is a valid integer value
4,034
public function multiply ( $ multiplier , $ roundingMode = self :: ROUND_HALF_UP , $ precision = self :: PRECISION_GAAP ) { $ this -> assertRoundingMode ( $ roundingMode ) ; $ multiplier = $ this -> castOperand ( $ multiplier ) ; $ precision = $ this -> castPrecision ( $ precision ) ; $ amount = $ this -> amount -> mul...
Returns a new Money object that represents the multiplied value by the given factor
4,035
public function divide ( $ divisor , $ roundingMode = self :: ROUND_HALF_UP , $ precision = self :: PRECISION_GAAP ) { $ this -> assertRoundingMode ( $ roundingMode ) ; $ divisor = $ this -> castOperand ( $ divisor ) ; $ precision = $ this -> castPrecision ( $ precision ) ; $ innerPrecision = $ this -> getInnerPrecisio...
Returns a new Money object that represents the divided value by the given factor
4,036
public function allocate ( array $ ratios , $ precision = self :: PRECISION_CURRENCY ) { $ precision = $ this -> castPrecision ( $ precision ) ; $ remainder = $ this -> amount ; $ results = [ ] ; $ total = Decimal :: create ( array_sum ( $ ratios ) , $ precision ) ; foreach ( $ ratios as $ ratio ) { $ share = $ this ->...
Allocate the money according to a list of ratios
4,037
public function allocateTo ( $ n , $ precision = self :: PRECISION_CURRENCY ) { if ( ! is_int ( $ n ) ) { throw new Exception \ InvalidArgumentException ( 'Number of targets must be an integer' ) ; } return $ this -> allocate ( array_fill ( 0 , $ n , 1 ) , $ precision ) ; }
Allocate the money among N targets
4,038
protected function getData ( $ key ) { $ path = $ this -> path ( $ key ) ; if ( ! $ this -> fileSystem -> isFile ( $ path ) ) { return [ 'data' => null , 'time' => null ] ; } $ content = $ this -> fileSystem -> get ( $ path ) ; $ expire = substr ( $ content , 0 , 10 ) ; if ( time ( ) > $ expire ) { $ this -> delete ( $...
get data from file
4,039
public function getQualityBadgeUrl ( $ slug , $ type , $ qualityBadgeHash ) { return sprintf ( '%s/%s/%s/%s?s=%s' , $ this -> host , $ type , $ slug , 'badges/quality-score.png' , $ qualityBadgeHash ) ; }
Get quality badge url
4,040
public function getCoverageBadgeUrl ( $ slug , $ type , $ coverageBadgeHash ) { return sprintf ( '%s/%s/%s/%s?s=%s' , $ this -> host , $ type , $ slug , 'badges/coverage.png' , $ coverageBadgeHash ) ; }
Get coverage badge url
4,041
public function icon ( $ icon , $ color = null , bool $ animated = null ) : self { Checkers :: checkIcon ( $ icon , null , $ this -> iconIsNullable ) ; $ this -> icon = $ icon ; $ this -> setIconColor ( $ color ) ; $ this -> iconAnimated = $ animated !== null ? $ animated : $ this -> iconAnimated ; return $ this ; }
Valid bootstrap icon
4,042
public function setIconColor ( $ color = null ) { $ color === null || Checkers :: checkColor ( $ color , null ) ; $ this -> iconColor = $ color ; return $ this ; }
Color of attached icon
4,043
protected function buildIcon ( string $ icon , bool $ animated , array $ cssClasses ) : string { return Html :: buildHtmlElement ( 'i' , [ ] , null , true , $ this -> getIconCssClasses ( $ icon , $ animated , $ cssClasses ) ) ; }
Build the HTML code of the icon
4,044
public function findByID ( $ aid , $ associationsFilter = null ) { $ xmlQuery = $ this -> associationsApiService -> getAssociation ( $ aid , $ associationsFilter ) ; $ association = new Association ( ) ; $ mapper = new \ RGU \ Dvoconnector \ Mapper \ Association ( $ xmlQuery ) ; $ mapper -> mapToAbstractEntity ( $ asso...
return a association
4,045
public function setContent ( $ content ) { if ( ! $ json = json_encode ( $ content ) ) { $ this -> setResponseCode ( self :: HTTP_INTERNAL_SERVER_ERROR ) ; $ json = json_encode ( [ 'status' => 'error' , 'error_message' => json_last_error_msg ( ) ] ) ; } $ this -> content = $ json ; return $ this ; }
Trys to JSON encode the given content .
4,046
private function processBlockquote ( $ text , $ inline = false ) { if ( $ inline ) { $ length = 0 ; $ text = str_replace ( self :: BLOCKQUOTE_INLINE_START , '' , $ text ) ; } else { $ length = strlen ( self :: BLOCKQUOTE_BLOCK_START ) ; $ text = mb_substr ( $ text , $ length ) ; } $ end = $ this -> findBlockquoteEnd ( ...
Processes text wrapped in markup saying it s emphasized
4,047
private function findBlockquoteEnd ( $ text , $ inline = false ) { $ end = $ this -> lookAhead ( $ text , ( $ inline ? "\n" : self :: BLOCKQUOTE_BLOCK_START ) ) ; if ( $ end === false && ! $ inline ) { $ end = $ this -> lookAhead ( $ text , str_replace ( "\n" , '' , self :: BLOCKQUOTE_BLOCK_START ) ) ; } if ( $ end ===...
Looks for an end of blockqoute and returns the possition of the end
4,048
private function processLink ( $ text , $ link ) { $ link = rtrim ( $ link , '.' ) ; $ pipe = explode ( '|' , $ text ) ; if ( mb_strlen ( $ pipe [ 0 ] ) !== mb_strlen ( $ text ) ) { $ pipe = explode ( '[' , $ pipe [ 0 ] ) ; $ linkText = $ pipe [ 1 ] ; $ search = '[' . $ linkText . '|' . $ link . ']' ; $ replace = sprin...
Processes text with a link markup
4,049
public function getCompiler ( ) { if ( $ this -> compiler == null ) { $ this -> compiler = new \ PytoTPL \ Compiler ( $ this , $ this -> config ) ; } return $ this -> compiler ; }
Create and return an instance of the compiler
4,050
public function getEventEmitter ( ) { if ( $ this -> eventEmitter == null ) { $ this -> eventEmitter = new \ Evenement \ EventEmitter ( ) ; } return $ this -> eventEmitter ; }
Return an instance of the Event emitter
4,051
private function isEventEmitterEnabled ( ) { if ( ! isset ( $ this -> isEmitterEnabled ) ) { $ this -> isEmitterEnabled = $ this -> getConfig ( 'event_emitter' ) != false ; } return $ this -> isEmitterEnabled ; }
Indicate if the Event emitter should be enabled
4,052
protected function validateConfig ( ) { $ defaults = [ 'tpl_folder' , 'cache_folder' , 'tpl_file_format' , ] ; foreach ( $ defaults as $ key ) { if ( ! isset ( $ this -> config [ $ key ] ) ) { throw new InvalidConfigException ( sprintf ( "Missing a configuration key (%s)" , $ key ) ) ; } } }
Check if the required configuration keys are provided
4,053
public function assign ( $ key , $ value = null ) { if ( ! is_array ( $ key ) || $ value instanceof Closure ) { $ this -> vars [ $ key ] = $ value ; } else { $ this -> vars = array_merge ( $ this -> vars , $ key ) ; } return $ this ; }
Assign a value to a key
4,054
public function renderString ( $ template , array $ params = null ) { if ( ! empty ( $ params ) ) { $ this -> assign ( $ params ) ; } $ compiled = $ this -> getCompiler ( ) -> compile ( $ template ) ; $ tempFile = tempnam ( sys_get_temp_dir ( ) , __FUNCTION__ ) ; $ this -> writeToFile ( $ tempFile , $ compiled ) ; $ te...
Render a string
4,055
public function render ( $ page , array $ params = null ) { $ this -> setFile ( $ page ) ; try { if ( ! file_exists ( $ file = $ this -> getFile ( ) ) ) { throw new NotFoundException ( "Template file couldn't be found: " . $ file ) ; } if ( ! empty ( $ params ) ) { $ this -> assign ( $ params ) ; } $ template = $ this ...
Render a specified view
4,056
private function compile ( $ file ) { $ this -> dispatchEvent ( 'before.compile' , $ file ) ; $ compiled = $ this -> getCompiler ( ) -> compile ( file_get_contents ( $ file ) ) ; $ this -> dispatchEvent ( 'after.compile' , $ file ) ; return $ compiled ; }
Compile the specified view to valid PHP
4,057
private function readBuffer ( $ template ) { try { mb_internal_encoding ( 'UTF-8' ) ; $ this -> assignDefaults ( ) ; $ this -> incrementRendering ( ) ; $ obLevel = ob_get_level ( ) ; ob_start ( ) ; extract ( $ this -> shared + $ this -> vars , EXTR_OVERWRITE ) ; include ( $ template ) ; $ contents = ob_get_clean ( ) ; ...
Read the buffer of the template file
4,058
public function flushCache ( ) { $ iterator = new \ DirectoryIterator ( $ this -> getConfig ( 'cache_folder' ) ) ; foreach ( $ iterator as $ file ) { if ( ! $ file -> isDot ( ) ) { unlink ( $ file -> getPathname ( ) ) ; } } }
Flush the cache folder
4,059
private function tryCompile ( $ template ) { $ cache = $ this -> getMaskedFileName ( $ template ) ; $ path = $ this -> getConfig ( 'cache_folder' ) ; if ( ! file_exists ( $ path ) ) { mkdir ( $ path , 0777 , true ) ; } if ( file_exists ( $ cache ) && ( filemtime ( $ cache ) > filemtime ( $ template ) ) ) { } else { $ t...
Compile the template and retrieve the contents
4,060
private function getMaskedFileName ( $ file , $ format = '.php' ) { return $ this -> getConfig ( 'cache_folder' ) . self :: cacheFilePrefix . '.' . $ this -> fileName . strtoupper ( substr ( md5 ( $ file ) , - 19 ) ) . $ format ; }
Get the full path to the cached template file
4,061
private function writeToFile ( $ file , $ content , $ origin = 'n/a' ) { return file_put_contents ( $ file , $ this -> getFileSignature ( $ origin ) . $ content ) ; }
Write the compiled PHP code to the template file
4,062
private function decrementRendering ( ) { if ( $ this -> renderCounter > 0 ) { $ this -> renderCounter -- ; $ this -> dispatchEvent ( 'rendering.decremented' , $ this -> renderCounter ) ; } return $ this ; }
Decrement the view rendering
4,063
private function setFile ( $ name ) { $ this -> fileName = $ name . '.' ; $ this -> file = $ this -> getConfig ( 'tpl_folder' ) . str_replace ( '.' , '/' , $ name ) . $ this -> getConfig ( 'tpl_file_format' , '.pytotpl.php' ) ; }
Set the current template file name
4,064
private function snakeCase ( $ key ) { if ( ! ctype_lower ( $ key ) ) { $ key = preg_replace ( '/\s+/u' , '' , $ key ) ; $ key = mb_strtolower ( preg_replace ( '/(.)(?=[A-Z])/u' , '$1' . '_' , $ key ) , 'UTF-8' ) ; } return $ key ; }
Convert a string to snake case
4,065
private function getFileSignature ( $ origin ) { return "<?php " . sprintf ( self :: blockDirectAccessMSG , get_class ( $ this ) ) . PHP_EOL . "/*" . PHP_EOL . "[{$origin}] Compiled by PytoTPL Engine (" . date ( "Y-m-d H:i:s" ) . ")" . PHP_EOL . "*/" . PHP_EOL . "?>" ; }
Get the compiled file signature
4,066
protected function _setupAdminProfileNavBar ( ) { Nav :: add ( 'profile' , 'profile' , [ 'weight' => 10 , 'icon' => 'user' , 'title' => __d ( 'community' , 'My profile' ) , 'url' => [ 'action' => 'edit' , 'controller' => 'Users' , 'plugin' => 'Community' , $ this -> _controller -> Auth -> user ( 'id' ) ] ] ) ; Nav :: a...
Setup profile nav bar for admin .
4,067
public function getAllMetadata ( ) : array { $ metadatas = [ ] ; foreach ( $ this -> loader -> getAllClassNames ( ) as $ className ) { $ metadatas [ ] = $ this -> getMetadataFor ( $ className ) ; } return $ metadatas ; }
Gets all the metadata available in this factory .
4,068
public static function dateIntervalToSeconds ( \ DateInterval $ i ) { return $ i -> days * 86400 + $ i -> h * 3600 + $ i -> i * 60 + $ i -> s ; }
Gets the total number of seconds from a DateInterval
4,069
public static function relativeTime ( \ DateTime $ d ) { $ second = 1 ; $ minute = 60 * $ second ; $ hour = 60 * $ minute ; $ day = 24 * $ hour ; $ month = 30 * $ day ; $ delta = \ time ( ) - $ d -> getTimestamp ( ) ; if ( $ delta < 1 * $ minute ) { return $ delta === 1 ? 'one second ago' : $ delta . ' seconds ago' ; }...
Calculates the time in human - readable form from the given date
4,070
public static function validateInternetIPAddress ( $ addr , $ private = false , $ loopback = false ) { $ flags = \ FILTER_FLAG_IPV4 | \ FILTER_FLAG_NO_RES_RANGE ; if ( ! $ private ) { $ flags |= \ FILTER_FLAG_NO_PRIV_RANGE ; } $ ip = \ trim ( $ addr ) ; if ( \ filter_var ( $ ip , \ FILTER_VALIDATE_IP , $ flags ) === fa...
Validates an IPv4 Address
4,071
public function put ( $ text = "" , $ color = null , $ bgColor = null ) { $ this -> zend ( 'writeLine' , [ $ text , $ this -> properColor ( $ color ) , $ this -> properColor ( $ bgColor ) ] ) ; }
Alias for writeLine
4,072
public function findOrCreate ( array $ attributes ) { $ foundAttributes = $ this -> model -> whereIn ( 'value' , $ attributes ) -> get ( ) ; $ returnAttributes = [ ] ; if ( $ foundAttributes ) { foreach ( $ foundAttributes as $ attribute ) { $ pos = array_search ( $ attribute -> value , $ attributes ) ; if ( $ pos !== ...
Find existing attributes or create if they don t exist .
4,073
public static function get ( $ array = NULL , $ item = NULL , $ default = NULL ) { if ( $ array === NULL ) return isset ( $ default ) ? $ default : $ item ; if ( is_object ( $ array ) && isset ( $ array -> $ item ) ) return $ array -> $ item ; if ( is_array ( $ array ) ) return isset ( $ array [ $ item ] ) && ! empty (...
Checks for the existance of an item at a given array index and returns that object if it exists
4,074
public static function setApplicationLanguage ( ) { $ app = Yii :: app ( ) ; if ( $ app -> language != 'en_US' ) return $ app -> language ; if ( php_sapi_name ( ) == 'cli' ) return $ app -> language ; if ( Cii :: get ( $ _POST , '_lang' , false ) ) $ app -> language = $ _POST [ '_lang' ] ; else if ( isset ( $ app -> se...
Sets the application language
4,075
public static function getUserConfig ( $ key , $ default = NULL ) { $ uid = Yii :: app ( ) -> user -> id ; $ data = Yii :: app ( ) -> db -> createCommand ( 'SELECT value FROM user_metadata AS t WHERE t.key = :key AND t.user_id = :id' ) -> bindParam ( ':id' , $ uid ) -> bindParam ( ':key' , $ key ) -> queryAll ( ) ; if ...
Gets a configuration value from user_metadata
4,076
public static function formatDate ( $ date , $ format = NULL ) { if ( $ format == NULL ) $ format = Cii :: getConfig ( 'dateFormat' ) . ' @ ' . Cii :: getConfig ( 'timeFormat' ) ; if ( $ format == ' @ ' ) $ format = 'F jS, Y @ H:i UTC' ; return gmdate ( $ format , $ date ) ; }
Provides methods to format a date throughout a model By forcing all components through this method we can provide a comprehensive and consistent date format for the entire site
4,077
public static function timeago ( $ date , $ format = NULL ) { Yii :: app ( ) -> controller -> widget ( 'vendor.yiqing-95.YiiTimeAgo.timeago.JTimeAgo' , array ( 'selector' => ' .timeago' , 'useLocale' => false , 'settings' => array ( 'refreshMillis' => 60000 , 'allowFuture' => true , 'strings' => array ( 'prefixAgo' => ...
Automatically handles TimeAgo for UTC
4,078
public static function getHybridAuthProviders ( ) { $ providers = Yii :: app ( ) -> cache -> get ( 'hybridauth_providers' ) ; if ( $ providers === false ) { $ providers = array ( ) ; $ response = Yii :: app ( ) -> db -> createCommand ( 'SELECT REPLACE(`key`, "ha_", "") AS `key`, value FROM `configuration` WHERE `key` L...
Returns an array of HybridAuth providers to be used by HybridAuth and other parts of CiiMS
4,079
public static function getEncryptionKey ( ) { $ key = self :: getConfig ( 'encryptionKey' , NULL , 'settings_' , true ) ; if ( $ key == NULL || $ key == "" ) { try { $ key = Crypto :: CreateNewRandomKey ( ) ; } catch ( CryptoTestFailedException $ ex ) { throw new CException ( 'Encryption key generation failed' ) ; } ca...
Retrieves the encryption key from cache or generations a new one in the instance one does not exists
4,080
public static function getVersion ( ) { $ version = Yii :: app ( ) -> cache -> get ( 'ciims_version' ) ; if ( $ version === false ) { $ version = file_get_contents ( Yii :: getPathOfAlias ( 'application.config.VERSION' ) ) ; Yii :: app ( ) -> cache -> set ( 'ciims_version' , $ version ) ; } return $ version ; }
Returns the current CiiMS Version
4,081
public static function generateSafeHash ( $ length = 16 ) { $ factory = new CryptLib \ Random \ Factory ; return preg_replace ( '/[^A-Za-z0-9\-]/' , '' , $ factory -> getLowStrengthGenerator ( ) -> generateString ( $ length ) ) ; }
Generates a Safe Hash to use throughout CiiMS
4,082
public static function loadUserInfo ( ) { if ( defined ( 'CIIMS_INSTALL' ) ) return ; if ( isset ( Yii :: app ( ) -> user ) ) { $ json = CJSON :: encode ( array ( 'email' => Cii :: get ( Yii :: app ( ) -> user , 'email' ) , 'token' => Cii :: getUserConfig ( 'api_key' , false ) , 'role' => Cii :: get ( Yii :: app ( ) ->...
Loads the user information
4,083
public static function toArray ( ) { $ self = new \ ReflectionClass ( get_called_class ( ) ) ; $ return = array ( ) ; foreach ( $ self -> getConstants ( ) as $ value ) { array_push ( $ return , $ value ) ; } return $ return ; }
This method returns an array with the static properties of the called class .
4,084
public function getBankList ( $ use_cache = true ) { if ( $ use_cache && self :: $ listOfBanks != null ) { return self :: $ listOfBanks ; } $ params = array ( 'a' => 'banklist' , 'testmode' => ( $ this -> testMode ) ? 'true' : 'false' , ) ; $ xml = $ this -> request ( 'ideal' , $ params ) ; $ banks = array ( ) ; foreac...
Returns an array of Bank - instances the customer can choose from .
4,085
public function details ( $ placeId , $ query = [ ] ) { if ( ! $ placeId ) { throw new InvalidArgumentException ( 'placeId must be a string' ) ; } try { $ response = $ this -> httpClient -> request ( 'GET' , $ this -> url , [ 'query' => array_merge ( [ 'placeid' => $ placeId , 'key' => $ this -> auth -> key ( ) , ] , $...
Send request for place details by place id .
4,086
public function resolveElement ( Element $ element ) { $ elementtype = $ this -> elementService -> findElementtype ( $ element ) ; return $ this -> resolveElementtype ( $ elementtype ) ; }
Resolve element to icon .
4,087
public function resolveTreeNode ( TreeNodeInterface $ treeNode , $ language ) { $ parameters = [ ] ; if ( ! $ treeNode -> isRoot ( ) ) { $ tree = $ treeNode -> getTree ( ) ; if ( $ tree -> isPublished ( $ treeNode , $ language ) ) { $ parameters [ 'status' ] = $ tree -> isAsync ( $ treeNode , $ language ) ? 'async' : '...
Resolve tree node to icon .
4,088
public function resolveTeaser ( Teaser $ teaser , $ language ) { $ parameters = [ ] ; if ( $ this -> teaserManager -> isPublished ( $ teaser , $ language ) ) { $ parameters [ 'status' ] = $ this -> teaserManager -> isAsync ( $ teaser , $ language ) ? 'async' : 'online' ; } if ( $ this -> teaserManager -> isInstance ( $...
Resolve teaser to icon .
4,089
public function prepare ( callable $ queryResolver ) { $ this -> unresolved = $ this -> unresolved -> merge ( collect ( $ this -> parameters ) -> except ( self :: getDefaultQueryParameters ( ) ) ) -> filter ( function ( $ parameter ) { return ! is_null ( $ parameter ) ; } ) -> map ( function ( $ parameter ) { return ne...
Prepare the query
4,090
protected function parseWhere ( ) { $ conditions = decode_where ( $ this -> parameters [ 'where' ] ) ; $ unresolved = [ ] ; foreach ( $ conditions as $ field => $ valueExpression ) { $ valueExpression = new ValueExpression ( $ valueExpression ) ; if ( $ this -> modelInformation -> isDate ( $ field ) ) { $ this -> parse...
Parse the request s where constraints
4,091
protected function parseDate ( $ field , ValueExpression $ valueExpression ) { if ( strpos ( $ field , '_' ) <= 0 ) { $ field = snake_case ( $ field ) ; } $ dateValue = $ valueExpression -> getValue ( ) ; $ this -> query -> where ( $ field , $ valueExpression -> getExpression ( ) , $ dateValue -> toDateTimeString ( ) )...
Add a date constraint to the query object
4,092
protected function parseRelation ( $ field , ValueExpression $ valueExpression ) { $ this -> query -> has ( $ field , $ valueExpression -> getValue ( ) ) ; }
Add a relation constraint to the query object
4,093
protected function parseInclude ( ) { $ eagerLoadingKeys = explode ( ',' , $ this -> parameters [ 'include' ] ) ; foreach ( $ eagerLoadingKeys as $ eagerLoadingKey ) { $ this -> query -> load ( array_diff ( $ this -> modelInformation -> getRelations ( ) , $ eagerLoadingKey ) ) ; } }
Speed up response generation with eager loading
4,094
public function paginate ( ) { try { $ this -> query = $ this -> query -> paginate ( $ this -> getPaginationConfig ( ) ) ; } catch ( \ Exception $ e ) { throw new QueryException ( $ e ) ; } }
Execute the query and paginate the results according to request or config
4,095
protected function getPaginationConfig ( ) { $ limit = 0 ; if ( array_has ( $ this -> parameters , 'limit' ) && is_numeric ( $ this -> parameters [ 'limit' ] ) ) { $ limit = intval ( $ this -> parameters [ 'limit' ] ) ; $ limit = abs ( $ limit ) ; } return ( $ limit > 0 ) ? $ limit : config ( 'transfugio.itemsPerPage' ...
Get number of items per page
4,096
public function shouldBeIgnored ( $ name ) : bool { foreach ( $ this -> ignores as $ regex ) { if ( preg_match ( $ regex , $ name ) ) { return true ; } } return false ; }
Determine whether an object should be ignored as per config .
4,097
public function addSchema ( string $ schema ) : void { $ work = $ schema ; if ( $ work { 0 } != '/' ) { $ work = getcwd ( ) . "/$work" ; } if ( ! file_exists ( $ work ) ) { $ this -> notice ( "`\"$schema\"` for `{$this->database}` not found, skipping." ) ; return ; } $ this -> schemas [ ] = file_get_contents ( $ work )...
Add schema data from an SQL file .
4,098
protected function sql ( string $ description , array $ sqls ) : array { global $ argv ; $ description = trim ( $ description ) ; if ( strlen ( $ description ) > 94 ) { $ description = substr ( preg_replace ( "@\s+@m" , ' ' , $ description ) , 0 , 94 ) . " \033[0;33m[...]" ; } if ( ! $ this -> silent ) { fwrite ( STDOU...
Execute a batch of SQL statements and display feedback .
4,099
public function & getService ( $ service ) { $ classServiceName = basename ( $ service ) ; if ( isset ( $ this -> $ classServiceName ) ) { return $ this -> $ classServiceName ; } else { $ service = ucfirst ( $ service ) ; $ factoryClass = $ service . "Factory" ; if ( class_exists ( $ factoryClass ) ) { $ factory = new ...
You can use this as is If you have cyclic dependencies you need to passback by reference with &