idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
30,200
protected function _createURL ( $ base , $ controller , $ action , $ params , $ searchDefined = true ) { $ params [ 'controller' ] = $ controller ; $ params [ 'action' ] = $ action ; foreach ( $ this -> urlRoutes as $ route => $ defined ) { $ cBase = $ base ; $ preparedParams = $ params ; if ( $ searchDefined ) { if ( is_numeric ( $ route ) ) { continue ; } $ match = true ; foreach ( $ defined as $ def => $ value ) { if ( ( $ value || '0' === $ value ) && ( ! isset ( $ params [ $ def ] ) || $ params [ $ def ] != $ value ) ) { $ match = false ; } else { unset ( $ preparedParams [ $ def ] ) ; if ( 'module' == $ def ) { if ( substr ( $ cBase , - 1 * strlen ( $ value . '/' ) ) == $ value . '/' ) { $ cBase = substr ( $ cBase , 0 , strlen ( $ cBase ) - strlen ( $ value . '/' ) ) ; } } } } if ( ! $ match ) { continue ; } } $ match = true ; preg_match_all ( '/\(\?<([a-z0-9_\-]+)>.*?\)/' , is_numeric ( $ route ) ? $ defined : $ route , $ matches ) ; if ( ! $ matches ) { continue ; } $ toReplace = array ( '\/' => '/' ) ; foreach ( $ matches [ 1 ] as $ k => $ word ) { $ match = $ match & isset ( $ params [ $ word ] ) ; if ( $ match ) { $ toReplace [ $ matches [ 0 ] [ $ k ] ] = $ params [ $ word ] ; unset ( $ preparedParams [ $ word ] ) ; } else { break ; } } if ( $ match ) { unset ( $ preparedParams [ 'module' ] ) ; return $ cBase . str_replace ( array_keys ( $ toReplace ) , array_values ( $ toReplace ) , is_numeric ( $ route ) ? $ defined : $ route ) . $ this -> _params2string ( $ preparedParams ) . '.html' ; } } if ( $ searchDefined ) { return $ this -> _createURL ( $ base , $ controller , $ action , $ params , false ) ; } }
Create url by checking all routes .
30,201
protected function _params2string ( $ params ) { if ( ! count ( $ params ) ) { return '' ; } $ paramsPart = array ( ) ; foreach ( $ params as $ name => $ value ) { if ( ! $ value && ( '0' !== $ value ) ) { continue ; } $ paramsPart [ ] = str_replace ( array ( '{name}' , '{value}' ) , array ( $ name , urlencode ( $ value ) ) , $ this -> paramsPairStructure ) ; } if ( ! count ( $ paramsPart ) ) { return '' ; } return '/' . implode ( $ this -> paramsSeparator , $ paramsPart ) ; }
Get query params from array .
30,202
public function getModuleNamespace ( ) { if ( ! $ this -> module || '\\' == $ this -> module || '/' == $ this -> module ) { return '\app' ; } if ( isset ( $ this -> modules [ $ this -> module ] [ 'namespace' ] ) ) { return $ this -> modules [ $ this -> module ] [ 'namespace' ] ; } return '\app\modules\\' . $ this -> module ; }
Get current module namespace .
30,203
public function simulateURI ( $ uri ) { $ this -> currentURL = $ this -> baseURL . ( '/' == $ uri [ 0 ] ? substr ( $ uri , 1 ) : $ uri ) ; }
Will replace current HTML request with selected URI . This is used by HtmlRequest unit test .
30,204
private function getModuleName ( $ class ) { $ controllerClass = get_class ( $ this ) ; $ moduleName = substr ( $ controllerClass , 0 , strpos ( $ controllerClass , '\\' ) ) ; return $ moduleName ; }
This will get the module name of the class
30,205
private function structureDatasArray ( $ arrayDatas = [ ] , $ tableColumns = [ ] ) { foreach ( $ arrayDatas as $ arrayData ) { $ datasArray [ $ arrayData [ 'pros_id' ] ] = [ ] ; foreach ( $ tableColumns as $ columnKey => $ columnValue ) { foreach ( $ arrayData as $ dataKey => $ dataValue ) { if ( $ columnValue == $ dataKey ) { $ datasArray [ $ arrayData [ 'pros_id' ] ] = $ datasArray [ $ arrayData [ 'pros_id' ] ] + [ $ dataKey => $ dataValue ] ; break ; } } } } return $ datasArray ; }
Returns structured data array
30,206
public static function replace ( String $ file , $ data , $ replace ) : String { $ file = Info :: rpath ( $ file ) ; if ( ! is_file ( $ file ) ) { return false ; } return Filesystem :: replaceData ( $ file , $ data , $ replace ) ; }
Performs data modification on the file .
30,207
public static function reglace ( String $ file , $ pattern , $ replace ) : String { $ file = Info :: rpath ( $ file ) ; if ( ! is_file ( $ file ) ) { throw new Exception \ FileNotFoundException ( NULL , $ file ) ; } $ contents = file_get_contents ( $ file ) ; $ replaceContents = Regex :: replace ( $ pattern , $ replace , $ contents ) ; if ( $ contents !== $ replaceContents ) { file_put_contents ( $ file , $ replaceContents ) ; } return $ replaceContents ; }
Performs data modification on the file with ZN regex .
30,208
public static function zipExtract ( String $ source , String $ target = NULL ) : Bool { $ source = Info :: rpath ( $ source ) ; $ target = Info :: rpath ( $ target ) ; $ source = Base :: suffix ( $ source , '.zip' ) ; if ( ! file_exists ( $ source ) ) { throw new Exception \ FileNotFoundException ( NULL , $ source ) ; } if ( empty ( $ target ) ) { $ target = Extension :: remove ( $ source ) ; } $ zip = new ZipArchive ; if ( $ zip -> open ( $ source ) === true ) { $ zip -> extractTo ( $ target ) ; $ zip -> close ( ) ; return true ; } else { return false ; } }
Extracts a zip file to the specified location .
30,209
public static function createZip ( String $ path , Array $ data ) : Bool { $ path = Info :: rpath ( $ path ) ; $ zip = new ZipArchive ; $ zipPath = Base :: suffix ( $ path , ".zip" ) ; if ( file_exists ( $ zipPath ) ) { unlink ( $ zipPath ) ; } if ( ! is_dir ( $ pathDirName = Info :: pathInfo ( $ path , 'dirname' ) ) ) { mkdir ( $ pathDirName ) ; } if ( $ zip -> open ( $ zipPath , ZipArchive :: CREATE ) !== true ) { return false ; } $ status = '' ; if ( ! empty ( $ data ) ) foreach ( $ data as $ key => $ val ) { if ( is_numeric ( $ key ) ) { $ file = $ val ; $ fileName = NULL ; } else { $ file = $ key ; $ fileName = $ val ; } if ( is_dir ( $ file ) ) { $ allFiles = FileList :: allFiles ( $ file , true ) ; foreach ( $ allFiles as $ f ) { $ status = $ zip -> addFile ( $ f , $ f ) ; } } else { $ status = $ zip -> addFile ( $ file , $ fileName ) ; } } return $ zip -> close ( ) ; }
Create a zip file .
30,210
public static function rename ( String $ oldName , String $ newName ) : Bool { $ oldName = Info :: rpath ( $ oldName ) ; if ( ! file_exists ( $ oldName ) ) { throw new Exception \ FileNotFoundException ( NULL , $ oldName ) ; } return rename ( $ oldName , $ newName ) ; }
Change the name of a file .
30,211
public static function permission ( String $ name , Int $ permission = 0755 ) : Bool { $ name = Info :: rpath ( $ name ) ; if ( ! file_exists ( $ name ) ) { throw new Exception \ FileNotFoundException ( NULL , $ name ) ; } return chmod ( $ name , $ permission ) ; }
Changes file mode .
30,212
public static function copy ( String $ source , String $ target ) : Bool { return Filesystem :: copy ( Info :: rpath ( $ source ) , Info :: rpath ( $ target ) ) ; }
Used to copy a directory to another specified location . This includes other subdirectories and files of the directory to be copied .
30,213
public static function changeFolder ( String $ name ) : Bool { $ name = Info :: rpath ( $ name ) ; if ( ! is_dir ( $ name ) ) { throw new Exception \ FolderNotFoundException ( NULL , $ name ) ; } return chdir ( $ name ) ; }
It is used to change the active working directory of PHP .
30,214
protected function getMetadata ( $ class ) { if ( array_key_exists ( $ class , $ this -> cache ) ) { return $ this -> cache [ $ class ] ; } $ this -> cache [ $ class ] = null ; foreach ( $ this -> registry -> getManagers ( ) as $ name => $ em ) { try { return $ this -> cache [ $ class ] = [ $ em -> getClassMetadata ( $ class ) , $ name ] ; } catch ( MappingException $ e ) { } catch ( LegacyMappingException $ e ) { } } return $ this -> cache [ $ class ] ; }
Get class metadata .
30,215
public static function get ( $ config = [ ] ) { $ key = md5 ( get_called_class ( ) . serialize ( $ config ) ) ; if ( ! isset ( self :: $ _instances [ $ key ] ) ) self :: $ _instances [ $ key ] = new static ( $ config ) ; return self :: $ _instances [ $ key ] ; }
Return a instance for helper .
30,216
static public function flushRoutesCache ( ) { $ cachePath = Config :: getCommon ( 'router.cache_file' ) ; if ( FileHelper :: delete ( $ cachePath ) ) { return ErrorInfo :: success ( 'flush routes cache success' ) ; } else { return ErrorInfo :: error ( 'flush routes cache fail, please check config[router.cache_file]' ) ; } }
flush routes cache
30,217
public function clear ( ) { if ( is_file ( $ this -> path ) ) { unlink ( $ this -> path ) ; } $ this -> path = '' ; echo $ this -> path ; return $ this ; }
Clear the current temp file
30,218
public function getQuery ( ) { return isset ( $ this -> query ) && $ this -> query ? $ this -> query : $ this -> query = new Query ( ) ; }
get query instance
30,219
static public function isSql ( $ query ) { if ( is_string ( $ query ) && ! is_numeric ( $ query ) ) { if ( preg_match ( '/^\s*(select|insert|update|delete|show|create|alter|rename|drop|grant|revoke|exec|TRUNCATE|set|declare)\s+/i' , $ query ) ) { return true ; } } return false ; }
is directly sql
30,220
public function getQueryModel ( $ model = null , $ self = true ) { if ( ! $ model ) { $ model = static :: getFirstTable ( ) ; } if ( $ model && is_string ( $ model ) ) { $ model = preg_replace ( '/^' . $ this -> getTablePrefix ( ) . '/' , '' , $ model , 1 ) ; return static :: getTableInfo ( $ model ) ; } else { return $ model ? : ( $ self ? $ this : null ) ; } }
get current query model
30,221
static public function formatQueryOptions ( $ options = null ) { if ( ! isset ( $ options ) ) { return [ ] ; } if ( is_scalar ( $ options ) ) { $ options = [ 'where' => [ $ options ] ] ; } elseif ( isset ( $ options [ 'where' ] ) ) { $ options [ 'where' ] = ( array ) $ options [ 'where' ] ; } else { $ isWhere = true ; foreach ( $ options as $ k => $ v ) { if ( is_numeric ( $ k ) ) { unset ( $ options [ $ k ] ) ; $ options [ 'where' ] [ ] = $ v ; } elseif ( in_array ( $ k , [ 'distinct' , 'fields' , 'from' , 'table' , 'order' , 'pagesize' , 'page' , 'result_key' ] ) ) { $ isWhere = false ; break ; } } if ( $ isWhere ) { $ options = [ 'where' => $ options ] ; } else { $ options [ 'where' ] = [ ] ; } } return $ options ; }
format query options
30,222
static public function formatQueryTableAlias ( $ data = null , $ table_alias = null , $ in_fields = null ) { if ( $ data && isset ( $ table_alias ) ) { if ( is_array ( $ data ) ) { foreach ( $ data as $ k => $ v ) { if ( ! is_numeric ( $ k ) && strpos ( $ k , '.' ) === false ) { if ( isset ( $ in_fields ) && ! in_array ( $ k , $ in_fields ) ) continue ; $ data [ $ table_alias . '.' . $ k ] = $ v ; unset ( $ data [ $ k ] ) ; } } } elseif ( strpos ( $ data , ',' ) ) { $ data = explode ( ',' , $ data ) ; foreach ( $ data as $ k => $ v ) { $ v = trim ( $ v ) ; if ( isset ( $ in_fields ) && ! in_array ( $ v , $ in_fields ) ) continue ; $ data [ $ k ] = $ table_alias . '.' . $ v ; } $ data = implode ( ',' , $ data ) ; } elseif ( strpos ( $ data , '.' ) === false ) { $ data = trim ( $ data ) ; if ( isset ( $ in_fields ) && in_array ( $ data , $ in_fields ) ) { $ data = $ table_alias . '.' . $ data ; } } } return $ data ; }
format table alias for fields or where
30,223
public function getFirstTable ( $ tables = null ) { if ( ! $ tables ) { $ tables = static :: getQuery ( ) -> get ( 'table' ) ; } if ( $ tables ) { if ( is_string ( $ tables ) ) { return DataHelper :: explode ( ',\s*' , $ tables ) [ 0 ] ; } elseif ( is_array ( $ tables ) ) { return static :: getFirstTable ( current ( $ tables ) ) ; } } return $ tables ; }
get first table
30,224
public function getFirstTableAlias ( $ table = null ) { if ( ! $ table ) { $ table = static :: getQuery ( ) -> get ( 'table' ) ; } if ( $ table ) { if ( is_array ( $ table ) ) { return static :: getFirstTableAlias ( current ( $ table ) ) ; } $ table = preg_split ( '/(\,|(left|right)\s+join)/' , $ table ) [ 0 ] ; $ table = preg_split ( '/\s+(as\s+)?/' , $ table ) ; $ table = isset ( $ table [ 1 ] ) && $ table [ 1 ] ? $ table [ 1 ] : static :: buildRealTableName ( $ table [ 0 ] , false ) ; $ table = trim ( $ table ) ; } return $ table ; }
get first table alias
30,225
public function buildRealTableName ( $ table , $ include_dbname = true ) { $ table = explode ( ' ' , $ table ) [ 0 ] ; $ table = str_replace ( '#' , '.' , $ table ) ; if ( ( $ pos = strpos ( $ table , '.' ) ) !== false ) { $ database = substr ( $ table , 0 , $ pos ) ; $ table = substr ( $ table , $ pos + 1 ) ; } elseif ( $ prefix = $ this -> getTablePrefix ( ) ) { $ database = $ this -> getDatabase ( ) ; $ table = strpos ( $ table , $ prefix ) === 0 ? $ table : $ prefix . $ table ; } return $ include_dbname && $ database ? $ database . '.' . $ table : $ table ; }
build real table name like database . tablePrefix + tableName
30,226
public function formatInput ( $ data ) { if ( $ data ) { if ( is_numeric ( key ( $ data ) ) ) { foreach ( $ data as $ k => $ v ) { if ( is_numeric ( $ k ) && is_array ( $ v ) ) { $ data [ $ k ] = static :: formatInputRecord ( $ v ) ; } } } else { $ data = static :: formatInputRecord ( $ data ) ; } } return $ data ; }
format one or more record input for insert or update it will remove filed which not in master_fields
30,227
public function formatInputRecord ( $ data ) { $ model = static :: getQueryModel ( ) ; if ( ! $ data || ! isset ( $ model [ 'primary_key' ] ) || ! isset ( $ model [ 'fields' ] ) ) { return $ data ; } $ fdata = [ ] ; $ fields_names = isset ( $ model [ 'master_fields' ] ) ? $ model [ 'master_fields' ] : array_keys ( $ model [ 'fields' ] ) ; ; foreach ( $ data as $ k => $ v ) { if ( is_numeric ( $ k ) ) { $ fdata [ $ k ] = $ v ; } elseif ( in_array ( $ k , $ fields_names ) ) { $ fdata [ $ k ] = FieldInputHandler :: formatValue ( $ model [ 'fields' ] [ $ k ] , $ v ) ; } } if ( in_array ( 'update_time' , $ fields_names ) && ! isset ( $ fdata [ 'update_time' ] ) ) { $ fdata [ 'update_time' ] = time ( ) ; } return $ fdata ; }
format one record input for insert or update it will remove filed which not in master_fields
30,228
public function formatOutput ( $ data , $ model = null ) { if ( $ data ) { if ( is_numeric ( key ( $ data ) ) ) { foreach ( $ data as $ k => $ v ) { if ( is_numeric ( $ k ) && is_array ( $ v ) ) { $ data [ $ k ] = static :: formatOutputRecord ( $ v , $ model ) ; } } } else { $ data = static :: formatOutputRecord ( $ data , $ model ) ; } } return $ data ; }
format one or more record output
30,229
public function count ( $ field = '*' ) { $ this -> getQuery ( ) -> type ( 'select' ) -> remove ( 'fields' ) -> set ( 'count' , $ field ) ; $ result = $ this -> query ( ) ; if ( $ result ) { $ result = current ( $ result [ 0 ] ) ; } else { $ result = 0 ; } return $ result ; }
get rows num
30,230
public function exists ( $ where = null ) { if ( $ where ) { $ this -> getQuery ( ) -> where ( $ where ) ; } return $ this -> count ( ) > 0 ; }
is exists record
30,231
public function findById ( $ id , $ format = false ) { $ query = $ this -> getQuery ( ) ; if ( isset ( $ query [ 'table' ] ) ) { $ pk = $ this -> getPrimaryKey ( $ query [ 'table' ] [ 0 ] ) ; } else { $ pk = $ this -> getPrimarykey ( ) ; } if ( ! isset ( $ pk ) ) { throw new Exception ( 'Can\'t get primary key of table:' . $ this -> getTableName ( ) ) ; } if ( ! is_array ( $ id ) ) { $ pk = StringHelper :: toArray ( $ pk ) [ 0 ] ; $ where = [ $ pk => intval ( $ id ) ] ; } else { foreach ( $ pk as $ num => $ field ) { $ where [ ] = array ( $ field => intval ( $ id [ $ num ] ) ) ; } } return $ this -> where ( $ where ) -> find ( null , $ format ) ; }
find one by pk if pk is multi param is value array param order must the pk order .
30,232
public function findField ( $ field = null , $ options = null ) { if ( $ field ) { $ this -> select ( $ field ) ; } $ ret = $ this -> find ( $ options ) ; return $ ret ? array_values ( $ ret ) [ 0 ] : null ; }
find one field of one record
30,233
public function fetchField ( $ field = null , $ options = null ) { $ this -> getQuery ( ) -> type ( 'select' ) ; if ( $ options ) { $ this -> getQuery ( ) -> set ( static :: formatQueryOptions ( $ options ) ) ; } if ( $ field ) { $ this -> getQuery ( ) -> remove ( 'fields' ) -> set ( 'fields' , $ field ) ; } $ fields = StringHelper :: explode ( ',' , $ this -> getQuery ( ) [ 'fields' ] ) ; $ fields = array_map ( function ( $ v ) { $ vs = preg_split ( '/(as)?\s+/' , trim ( $ v ) ) ; return $ vs [ count ( $ vs ) - 1 ] ; } , $ fields ) ; $ rows = $ this -> query ( ) ; $ result = [ ] ; if ( $ rows ) foreach ( $ rows as $ v ) { $ result [ ] = $ v [ $ fields [ 0 ] ] ; } return $ result ; }
select one filed values
30,234
public function modify ( $ data = null , $ where = null ) { $ this -> set ( $ data , $ where ) ; $ query = static :: getQuery ( ) ; $ mdata = $ query -> get ( 'data' ) ; $ mwhere = $ query -> get ( 'where' ) ; if ( ! $ query -> formatted ( ) ) { $ mdata = static :: formatInput ( $ mdata ) ; $ query -> remove ( 'data' ) -> setRaw ( 'data' , $ mdata ) ; $ res = static :: verifyData ( $ mdata ) ; if ( $ res [ 'errcode' ] ) { return $ res ; } } if ( static :: isEmptyData ( $ mdata ) ) { return ErrorInfo :: success ( 'donot need modify.' ) ; } if ( ! $ mwhere ) { $ clone = $ query -> clone ( ) ; $ res = $ this -> setQuery ( $ clone ) -> verifyUnique ( $ mdata , $ mwhere ) ; if ( $ res -> isError ( ) ) { return $ res ; } } $ ret = $ this -> setQuery ( $ query ) -> update ( ) -> query ( ) ; return ErrorInfo :: instance ( $ ret === false ? - 1 : 0 ) ; }
update only return false if update It is different of save save can be insert or update
30,235
public function disable ( $ where = null ) { $ model = static :: getQueryModel ( ) ; $ deletedField = isset ( $ model [ 'deleted_field' ] ) ? $ model [ 'deleted_field' ] : ( isset ( $ model [ 'fields' ] [ 'deleted' ] ) ? 'deleted' : null ) ; if ( ! $ deletedField ) { return ErrorInfo :: error ( 'deleted filed is not exists.' ) ; } $ data [ ] = "$deletedField = ($deletedField + 1) % 2" ; $ deleteTimeField = isset ( $ model [ 'fields' ] [ 'delete_time' ] ) ? 'delete_time' : null ; if ( $ deleteTimeField ) { $ data [ $ deleteTimeField ] = time ( ) ; } if ( $ where ) { $ this -> getQuery ( ) -> where ( $ where ) ; } $ mwhere = $ this -> getQuery ( ) -> get ( 'where' ) ; $ res = $ this -> update ( ) -> set ( $ data ) -> query ( ) ; if ( $ this [ 'table_name' ] == $ model [ 'table_name' ] ) { if ( is_numeric ( $ where ) ) { $ model -> cacheFlushByRecord ( [ $ model [ 'primary_key' ] => $ where ] ) ; } elseif ( $ mwhere ) { $ model -> cacheFlushByRecord ( $ mwhere ) ; } } return ErrorInfo :: instance ( $ res === false ? - 1 : 0 ) ; }
disable modify deleted field auto flush cache
30,236
public function where ( $ where , $ op = null , $ value = null ) { $ this -> getQuery ( ) -> where ( $ where , $ op , $ value ) ; return $ this ; }
set where of query
30,237
public function set ( $ data = null , $ where = null ) { if ( $ data ) { $ this -> getQuery ( ) -> set ( 'data' , $ data ) ; } if ( $ where ) { $ this -> where ( $ where ) ; } return $ this ; }
set update data
30,238
public function getChildTemplates ( string $ context ) : array { Splash :: log ( ) -> Deb ( 'Loading Standalone Connector Templates for ' . $ context ) ; $ result = array ( ) ; if ( ! in_array ( $ context , array ( 'New' , 'Offline' , 'Connected' ) , true ) ) { return $ result ; } foreach ( $ this -> getAvailableObjects ( ) as $ objectType ) { $ objectService = $ this -> getObjectService ( $ objectType ) ; if ( method_exists ( $ objectService , 'get' . $ context . 'Template' ) ) { $ result [ ] = $ objectService -> { 'get' . $ context . 'Template' } ( ) ; } } return $ result ; }
Collect List of Objects & Widgets Templates for Profiles Rendering
30,239
public function getUtcNowForDb ( ) { $ dt = $ this -> getUtcNow ( ) ; $ result = $ this -> hlpFormat -> dateTimeForDb ( $ dt ) ; return $ result ; }
Return UTC now formatted as DB timestamp .
30,240
public function hasAlias ( $ hasAlias = null ) { if ( is_null ( $ hasAlias ) ) { return ( bool ) $ this -> hasAlias [ 0 ] ; } $ this -> hasAlias = $ hasAlias ; return $ this ; }
get or set query hasAlias
30,241
public function type ( $ type = null ) { if ( isset ( $ type ) ) { $ this -> data [ 'type' ] = $ type ; return $ this ; } return isset ( $ this -> data [ 'type' ] ) ? $ this -> data [ 'type' ] : 'select' ; }
get or set type
30,242
public function where ( $ where , $ op = null , $ value = null ) { if ( $ where ) { if ( is_array ( $ where ) ) { $ this -> set ( 'where' , $ where ) ; } elseif ( ! is_null ( $ op ) ) { if ( ! is_null ( $ value ) ) { $ value = [ $ op , $ value ] ; } else { $ value = $ op ; } $ this -> set ( 'where' , [ $ where => $ value ] ) ; } else { $ this -> set ( 'where' , $ where ) ; } } return $ this ; }
where method if params count is 2 then op be value
30,243
public function formatted ( $ isFormatted = null ) { if ( isset ( $ isFormatted ) ) { $ this -> data [ 'formatted' ] = $ isFormatted ; return $ this ; } return isset ( $ this -> data [ 'formatted' ] ) ? $ this -> data [ 'formatted' ] : false ; }
get or set isFormatted set true then donot format where and input data
30,244
function get ( $ name ) { if ( isset ( $ this -> items [ $ name ] ) ) return $ this -> items [ $ name ] ; throw new \ OutOfBoundsException ( sprintf ( "%s is not registered on %s.%sCurrently registered: %s" , $ name , static :: class , PHP_EOL , $ this -> items ? implode ( ', ' , array_keys ( $ this -> items ) ) : '(empty)' ) ) ; }
Retrieves an item by name .
30,245
function register ( $ nameOrItems , $ item = null ) { if ( is_array ( $ nameOrItems ) ) $ this -> items = array_merge ( $ this -> items , $ nameOrItems ) ; else $ this -> items [ $ nameOrItems ] = $ item ; return $ this ; }
Registers one or more items under the specified names .
30,246
function unregister ( $ nameOrNames ) { if ( is_array ( $ nameOrNames ) ) unset ( $ this -> items [ $ nameOrNames ] ) ; else foreach ( $ this -> items as $ i ) unset ( $ this -> items [ $ i ] ) ; return $ this ; }
Removes one or more items by name if they exist .
30,247
private function keyToName ( $ key ) { $ parts = explode ( '_' , $ key ) ; $ name = '' ; foreach ( $ parts as $ part ) { $ name .= ucfirst ( $ part ) ; } return $ name ; }
Transforma uma chave em um nome capitalizado .
30,248
public function setRequestFactory ( HttpRequestFactory $ requestFactory = null ) { if ( ! $ requestFactory ) { $ requestFactory = $ this -> apiDiscoveryProxy -> discoverRequestFactory ( ) ; } $ this -> requestFactory = $ requestFactory ; return $ this ; }
Sets factory for PSR - 7 requests .
30,249
public function createPaymentRequest ( $ customerExtId , $ amount , $ description , $ operative , $ service ) { return $ this -> createRequest ( 'POST' , '/payment' , [ 'customer_ext_id' => ( string ) $ customerExtId , 'amount' => $ amount , 'operative' => $ operative , 'service' => $ service , 'description' => $ description , ] ) ; }
Returns a PSR - 7 request to create a payment order into Paylands .
30,250
public function createCustomerCardsRequest ( $ customerExtId , $ status , $ unique ) { $ resource = sprintf ( '/customer/%s/cards?status=%s&unique=%s' , $ customerExtId , $ status , $ unique ) ; return $ this -> createRequest ( 'GET' , $ resource ) ; }
Returns a PSR - 7 request to retrieve customer s cards from Paylands .
30,251
public function createRefundPaymentRequest ( $ orderUuid , $ amount = null ) { $ amountData = is_null ( $ amount ) ? [ ] : [ 'amount' => $ amount , ] ; return $ this -> createRequest ( 'POST' , '/payment/refund' , [ 'order_uuid' => $ orderUuid , ] + $ amountData ) ; }
Returns a PSR - 7 request to create a refund of a payment into Paylands .
30,252
public function createSaveCardRequest ( $ customerExtId , $ cardHolder , $ cardPan , $ cardExpiryYear , $ cardExpiryMonth , $ cardCVV , $ validate , $ service , $ additional ) { $ validationService = ! $ validate ? [ ] : [ 'service' => $ service , ] ; return $ this -> createRequest ( 'POST' , '/payment-method/card' , [ 'customer_ext_id' => $ customerExtId , 'card_holder' => $ cardHolder , 'card_pan' => $ cardPan , 'card_expiry_year' => $ cardExpiryYear , 'card_expiry_month' => $ cardExpiryMonth , 'card_cvv' => $ cardCVV , 'validate' => $ validate , 'additional' => $ additional , 'signature' => $ this -> apiSignature , ] + $ validationService ) ; }
Returns a PSR - 7 request to save a credit card into Paylands .
30,253
private function createRequest ( $ method , $ resource , array $ data = [ ] ) { if ( ! empty ( $ data ) ) { $ data [ 'signature' ] = $ this -> apiSignature ; } return $ this -> requestFactory -> createRequest ( $ method , $ resource , [ ] , $ this -> encode ( $ data ) ) ; }
Uses a PSR - 7 compliant request factory to build up the expected request .
30,254
public function run ( $ args ) { if ( ! isset ( $ args [ 0 ] ) || ! $ args [ 0 ] ) { return "> Producer: Project directory required.\n" ; } $ name = trim ( $ args [ 0 ] ) ; if ( ! is_dir ( $ path = $ this -> cwd . '/repository/' . $ name ) ) { return "> Producer: Project directory 'repository/{$name}' not found.\n" ; } echo $ this -> info ( "Reset progect '{$name}'" ) ; $ repo = trim ( $ this -> exec ( 'reset-origin' , [ $ path ] ) ) ; $ purge = new PurgeCommand ( $ this -> cwd ) ; echo $ purge -> run ( [ $ name ] ) ; $ clone = new CloneCommand ( $ this -> cwd ) ; echo $ clone -> run ( [ $ repo , $ name ] ) ; }
Run reset command .
30,255
public function percent ( $ value , $ showSymbol = false , $ spacer = ' ' ) { if ( true === $ showSymbol ) { $ formatted = $ spacer . '%' ; } else { $ formatted = '' ; } return number_format ( $ value , $ this -> getConfiguration ( ) -> number -> minor_unit , $ this -> getConfiguration ( ) -> number -> decimal_point , $ this -> getConfiguration ( ) -> number -> thousands_separator ) . $ formatted ; }
Formats value as percentage value .
30,256
public function password ( $ request , $ match ) { $ msg = array ( 'message' => 'succcess' ) ; if ( array_key_exists ( 'email' , $ request -> REQUEST ) ) { $ sql = new Pluf_SQL ( 'email=%s' , array ( $ request -> REQUEST [ 'email' ] ) ) ; $ user = $ request -> user -> getOne ( $ sql -> gen ( ) ) ; if ( $ user ) { $ this -> sendPasswordToken ( $ request , $ user ) ; } return $ msg ; } if ( array_key_exists ( 'login' , $ request -> REQUEST ) ) { $ sql = new Pluf_SQL ( 'login=%s' , array ( $ request -> REQUEST [ 'login' ] ) ) ; $ user = $ request -> user -> getOne ( $ sql -> gen ( ) ) ; if ( $ user ) { $ this -> sendPasswordToken ( $ request , $ user ) ; } return $ msg ; } if ( array_key_exists ( 'token' , $ request -> REQUEST ) ) { $ token = new User_PasswordToken ( ) ; $ sql = new Pluf_SQL ( 'token=%s' , array ( $ request -> REQUEST [ 'token' ] ) ) ; $ token = $ token -> getOne ( $ sql -> gen ( ) ) ; if ( ! $ token || $ token -> isExpired ( ) ) { throw new Pluf_Exception_DoesNotExist ( 'Token not exist' ) ; } $ user = $ token -> get_user ( ) ; $ user -> setPassword ( $ request -> REQUEST [ 'new' ] ) ; $ user -> update ( ) ; $ token -> delete ( ) ; return $ msg ; } if ( array_key_exists ( 'old' , $ request -> REQUEST ) || array_key_exists ( 'old_password' , $ request -> REQUEST ) ) { $ oldPass = array_key_exists ( 'old' , $ request -> REQUEST ) ? $ request -> REQUEST [ 'old' ] : $ request -> REQUEST [ 'old_password' ] ; if ( $ request -> user -> isAnonymous ( ) ) { throw new Pluf_Exception_Unauthorized ( ) ; } $ cred = User_Credential :: getCredential ( $ request -> user -> id ) ; if ( ! $ cred -> checkPassword ( $ oldPass ) ) { throw new Pluf_Exception_MismatchParameter ( 'Old pass is not currect' ) ; } $ newPass = array_key_exists ( 'new' , $ request -> REQUEST ) ? $ request -> REQUEST [ 'new' ] : $ request -> REQUEST [ 'password' ] ; $ cred -> setPassword ( $ newPass ) ; $ cred -> update ( ) ; return $ msg ; } throw new Pluf_Exception_MismatchParameter ( 'Invalid request params' ) ; }
Manages user password
30,257
private function generateCallback ( $ request , $ token ) { if ( ! array_key_exists ( 'callback' , $ request -> REQUEST ) ) { return null ; } $ calback = $ request -> REQUEST [ 'callback' ] ; $ user = $ token -> get_user ( ) ; $ calback = str_replace ( "{{token}}" , $ token -> token , $ calback ) ; $ calback = str_replace ( "{{host}}" , Pluf_Tenant :: current ( ) -> domain , $ calback ) ; $ calback = str_replace ( "{{userId}}" , $ user -> id , $ calback ) ; $ calback = str_replace ( "{{userLogin}}" , $ user -> login , $ calback ) ; return $ calback ; }
Generates token callback
30,258
public function editAction ( ) { $ user = $ this -> getUser ( ) ; if ( ! is_object ( $ user ) || ! $ user instanceof UserInterface ) { throw new AccessDeniedException ( 'This user does not have access to this section.' ) ; } $ formProfile = $ this -> createForm ( new ProfileFormType ( $ this -> container -> getParameter ( 'fos_user.model.user.class' ) ) , $ user ) ; $ formPassword = $ this -> container -> get ( 'fos_user.change_password.form' ) ; $ formProfile -> handleRequest ( $ this -> getRequest ( ) ) ; if ( $ formProfile -> isValid ( ) ) { $ userManager = $ this -> get ( 'fos_user.user_manager' ) ; $ userManager -> updateUser ( $ user ) ; $ this -> container -> get ( 'session' ) -> getFlashBag ( ) -> set ( 'success' , $ this -> get ( 'translator' ) -> trans ( 'profile.flash.updated' , array ( ) , 'FOSUserBundle' ) ) ; return $ this -> redirect ( $ this -> generateUrl ( 'olix_security_profile_edit' ) ) ; } return $ this -> container -> get ( 'olix.admin' ) -> render ( 'OlixSecurityBundle:Profile:edit.html.twig' , null , array ( 'user' => $ user , 'tab' => 'profile' , 'form' => array ( 'profile' => $ formProfile -> createView ( ) , 'password' => $ formPassword -> createView ( ) , ) , ) ) ; }
Modification du profil
30,259
public function avatarAction ( ) { $ finder = new Finder ( ) ; $ result = array ( ) ; $ finder -> files ( ) -> in ( __DIR__ . '/../Resources/public/avatar' ) -> name ( '*.png' ) ; foreach ( $ finder as $ files ) { $ result [ $ files -> getRelativePath ( ) ] [ ] = $ files -> getRelativePathname ( ) ; } $ user = $ this -> getUser ( ) ; $ gravatar = new Gravatar ( ) ; $ gravatar -> setAvatarSize ( 150 ) ; return $ this -> render ( 'OlixSecurityBundle:Profile:avatar.html.twig' , array ( 'avatars' => $ result , 'gravatar' => $ gravatar -> get ( $ user -> getEmail ( ) ) , ) ) ; }
Affichage de la liste des avatars disponibles dans un popup
30,260
public function changePasswordAction ( ) { $ user = $ this -> getUser ( ) ; if ( ! is_object ( $ user ) || ! $ user instanceof UserInterface ) { throw new AccessDeniedException ( 'This user does not have access to this section.' ) ; } $ formProfile = $ this -> createForm ( new ProfileFormType ( $ this -> container -> getParameter ( 'fos_user.model.user.class' ) ) , $ user ) ; $ formPassword = $ this -> container -> get ( 'fos_user.change_password.form' ) ; $ formHandler = $ this -> container -> get ( 'fos_user.change_password.form.handler' ) ; $ process = $ formHandler -> process ( $ user ) ; if ( $ process ) { $ this -> container -> get ( 'session' ) -> getFlashBag ( ) -> set ( 'success' , $ this -> get ( 'translator' ) -> trans ( 'change_password.flash.success' , array ( ) , 'FOSUserBundle' ) ) ; return $ this -> redirect ( $ this -> generateUrl ( 'olix_security_profile_edit' ) ) ; } return $ this -> container -> get ( 'olix.admin' ) -> render ( 'OlixSecurityBundle:Profile:edit.html.twig' , null , array ( 'user' => $ user , 'tab' => 'password' , 'form' => array ( 'profile' => $ formProfile -> createView ( ) , 'password' => $ formPassword -> createView ( ) , ) , ) ) ; }
Changement du mot de passe
30,261
protected function respondRelatedAddresses ( $ addressableId , $ objectType ) { $ addresses = Address :: where ( 'addressable_id' , $ addressableId ) -> orderBy ( 'created_at' , 'desc' ) -> get ( ) ; return fractal ( $ addresses , new AddressTransformer ( ) ) -> withResourceName ( "{$objectType}Address" ) -> respond ( ) ; }
Produce a list of Addresses related to a selected object
30,262
private function registerStandaloneActions ( ContainerBuilder $ container ) { $ definition = $ container -> getDefinition ( 'splash.connectors.standalone' ) ; $ taggedObjects = $ container -> findTaggedServiceIds ( 'splash.standalone.action' ) ; foreach ( $ taggedObjects as $ serviceTags ) { foreach ( $ serviceTags as $ attributes ) { if ( ! isset ( $ attributes [ "type" ] ) ) { throw new Exception ( 'Tagged Standalone Action as no "type" attribute. Action Type is the last part of Action Url' ) ; } if ( ! isset ( $ attributes [ "action" ] ) ) { throw new Exception ( 'Tagged Standalone Action as no "action" attribute. Action is full controller name to use for this action.' ) ; } $ definition -> addMethodCall ( 'registerStandaloneAction' , array ( $ attributes [ "type" ] , $ attributes [ "action" ] ) ) ; } } }
Register Tagged Standalone Connector Actions
30,263
private function registerStandaloneObjects ( ContainerBuilder $ container ) { $ definition = $ container -> getDefinition ( 'splash.connectors.standalone' ) ; $ taggedObjects = $ container -> findTaggedServiceIds ( 'splash.standalone.object' ) ; foreach ( $ taggedObjects as $ id => $ serviceTags ) { foreach ( $ serviceTags as $ attributes ) { if ( ! isset ( $ attributes [ "type" ] ) ) { throw new Exception ( 'Tagged Standalone Object Service as no "type" attribute.' ) ; } $ definition -> addMethodCall ( 'registerObjectService' , array ( $ attributes [ "type" ] , new Reference ( $ id ) ) ) ; } } }
Register Tagged Objects Services to Standalone Connector
30,264
private function registerStandaloneWidgets ( ContainerBuilder $ container ) { $ definition = $ container -> getDefinition ( 'splash.connectors.standalone' ) ; $ taggedWidgets = $ container -> findTaggedServiceIds ( 'splash.standalone.widget' ) ; foreach ( $ taggedWidgets as $ id => $ serviceTags ) { foreach ( $ serviceTags as $ attributes ) { if ( ! isset ( $ attributes [ "type" ] ) ) { throw new Exception ( 'Tagged Standalone Widget Service as no "type" attribute.' ) ; } $ definition -> addMethodCall ( 'registerWidgetService' , array ( $ attributes [ "type" ] , new Reference ( $ id ) ) ) ; } } }
Register Tagged Widgets Services to Standalone Connector
30,265
public function previous_state ( ) { $ id = ( int ) ps ( 'ID' ) ; if ( ! $ id ) { return ; } $ this -> prev_permlink = permlinkurl_id ( $ id ) ; $ this -> prev_status = fetch ( 'Status' , 'textpattern' , 'ID' , $ id ) ; unset ( $ GLOBALS [ 'permlinks' ] [ $ id ] ) ; }
Fetches old article data .
30,266
public function update ( $ event , $ step , $ r ) { global $ app_mode ; $ this -> permlink = permlinkurl_id ( $ r [ 'ID' ] ) ; callback_event ( 'rah_bitly.update' , '' , false , $ r ) ; if ( ! $ this -> permlink || $ r [ 'Status' ] < STATUS_LIVE ) { return ; } if ( $ this -> prev_permlink !== $ this -> permlink || empty ( $ r [ 'custom_' . $ this -> field ] ) || $ this -> prev_status != $ r [ 'Status' ] ) { $ uri = $ this -> fetch ( $ this -> permlink ) ; } if ( empty ( $ uri ) ) { return ; } $ fields = getCustomFields ( ) ; if ( ! isset ( $ fields [ $ this -> field ] ) ) { return ; } safe_update ( 'textpattern' , 'custom_' . intval ( $ this -> field ) . "='" . doSlash ( $ uri ) . "'" , "ID='" . doSlash ( $ r [ 'ID' ] ) . "'" ) ; $ js = '$(document).ready(function(){' . '$(\'input[name="custom_' . $ this -> field . '"]\').val("' . escape_js ( $ uri ) . '");' . '});' ; if ( $ app_mode == 'async' ) { send_script_response ( $ js ) ; } }
Hooks to article saving process and updates short URLs .
30,267
protected function fetch ( $ permlink , $ timeout = 10 ) { if ( ! $ permlink || ! function_exists ( 'curl_init' ) ) { return ; } $ uri = 'https://api-ssl.bitly.com/v3/shorten' . '?login=' . urlencode ( $ this -> login ) . '&apiKey=' . urlencode ( $ this -> apikey ) . '&longUrl=' . urlencode ( $ permlink ) . '&format=txt' ; $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_URL , $ uri ) ; curl_setopt ( $ ch , CURLOPT_FAILONERROR , 1 ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , 1 ) ; curl_setopt ( $ ch , CURLOPT_CONNECTTIMEOUT , $ timeout ) ; curl_setopt ( $ ch , CURLOPT_TIMEOUT , $ timeout ) ; $ bitcode = curl_exec ( $ ch ) ; curl_close ( $ ch ) ; return $ bitcode && strpos ( $ bitcode , 'http' ) === 0 ? txpspecialchars ( trim ( $ bitcode ) ) : '' ; }
Fetches a Bitly short URL .
30,268
public function index ( $ user_uid ) { $ user = Subbly :: api ( 'subbly.user' ) -> find ( $ user_uid ) ; $ options = $ this -> getParams ( 'offset' , 'limit' , 'includes' , 'order_by' ) ; $ userAddresses = Subbly :: api ( 'subbly.user_address' ) -> findByUser ( $ user , $ options ) ; return $ this -> jsonCollectionResponse ( 'user_addresses' , $ userAddresses ) ; }
Get list of UserAddress for a User .
30,269
public function index ( $ userId ) { $ user = User :: with ( 'addresses' ) -> findOrFail ( $ userId ) ; $ this -> authorize ( 'view' , $ user ) ; return fractal ( $ user -> addresses , new AddressTransformer ( ) ) -> withResourceName ( 'userAddress' ) -> respond ( ) ; }
Produce a list of Addresss related to a selected User
30,270
public function clean ( $ mixed , $ stripTags = true , $ htmlEntities = true ) { if ( is_array ( $ mixed ) ) { foreach ( $ mixed as $ key => $ value ) { $ mixed [ $ key ] = self :: clean ( $ value , $ stripTags , $ htmlEntities ) ; } } else { if ( $ stripTags === true ) { $ mixed = strip_tags ( $ mixed ) ; } if ( $ htmlEntities === true ) { $ mixed = htmlentities ( $ mixed ) ; } } return $ mixed ; }
Cleans the input variable . This method removes tags with strip_tags and afterwards it turns all non - safe characters to its htmlentities .
30,271
public function setAvatarSize ( $ size ) { $ this -> size = intval ( $ size ) ; if ( $ this -> size > 512 || $ this -> size < 0 ) { throw new InvalidArgumentException ( 'Avatar size must be within 0 pixels and 512 pixels' ) ; } return $ this ; }
Affecte la taille de l image
30,272
public function setRating ( $ rating ) { $ rating = strtolower ( $ rating ) ; $ validRatings = array ( 'g' , 'pg' , 'r' , 'x' ) ; if ( ! in_array ( $ rating , $ validRatings ) ) { throw new InvalidArgumentException ( sprintf ( 'Invalid rating "%s" specified, only "g", "pg", "r", or "x" are allowed to be used.' , $ rating ) ) ; } $ this -> rating = $ rating ; return $ this ; }
Affecte le rating
30,273
public function copyTo ( $ dest , $ full = true ) { if ( $ full ) { if ( strpos ( $ this -> path , DIRECTORY_SEPARATOR ) !== false ) { $ folder = substr ( $ this -> path , ( strrpos ( $ this -> path , DIRECTORY_SEPARATOR ) + 1 ) ) ; } else { $ folder = $ this -> path ; } if ( ! file_exists ( $ dest . DIRECTORY_SEPARATOR . $ folder ) ) { mkdir ( $ dest . DIRECTORY_SEPARATOR . $ folder ) ; } $ dest = $ dest . DIRECTORY_SEPARATOR . $ folder ; } return static :: copy ( $ this -> path , $ dest , true ) ; }
Copy an entire directory recursively
30,274
public function emptyDir ( $ remove = false , $ path = null ) { if ( null === $ path ) { $ path = $ this -> path ; } if ( ! $ dh = @ opendir ( $ path ) ) { return ; } while ( false !== ( $ obj = readdir ( $ dh ) ) ) { if ( $ obj == '.' || $ obj == '..' ) { continue ; } if ( ! @ unlink ( $ path . DIRECTORY_SEPARATOR . $ obj ) ) { $ this -> emptyDir ( true , $ path . DIRECTORY_SEPARATOR . $ obj ) ; } } closedir ( $ dh ) ; if ( $ remove ) { @ rmdir ( $ path ) ; } }
Empty an entire directory
30,275
protected function buildTree ( \ DirectoryIterator $ it ) { $ result = [ ] ; foreach ( $ it as $ key => $ child ) { if ( $ child -> isDot ( ) ) { continue ; } $ name = $ child -> getBasename ( ) ; if ( $ child -> isDir ( ) ) { $ subdir = new \ DirectoryIterator ( $ child -> getPathname ( ) ) ; $ result [ DIRECTORY_SEPARATOR . $ name ] = $ this -> buildTree ( $ subdir ) ; } else { $ result [ ] = $ name ; } } return $ result ; }
Build the directory tree
30,276
protected function buildDirectory ( $ filePath ) { $ directory = dirname ( $ filePath ) ; if ( ! is_dir ( $ directory ) ) { mkdir ( $ directory , 0777 , true ) ; } }
Determine if a style directory needs to be built and if so create it .
30,277
protected function setPermissions ( $ filePath , $ overrideFilePermissions ) { if ( $ overrideFilePermissions ) { chmod ( $ filePath , $ overrideFilePermissions & ~ umask ( ) ) ; } elseif ( is_null ( $ overrideFilePermissions ) ) { chmod ( $ filePath , 0666 & ~ umask ( ) ) ; } }
Set the file permissions of a file upload Does not ignore umask .
30,278
protected function moveFile ( $ file , $ filePath ) { if ( ! rename ( $ file , $ filePath ) ) { $ error = error_get_last ( ) ; throw new Exceptions \ FileException ( sprintf ( 'Could not move the file "%s" to "%s" (%s)' , $ file , $ filePath , strip_tags ( $ error [ 'message' ] ) ) ) ; } }
Attempt to move and uploaded file to it s intended location on disk .
30,279
protected function emptyDirectory ( $ directory , $ deleteDirectory = false ) { if ( ! is_dir ( $ directory ) || ! ( $ directoryHandle = opendir ( $ directory ) ) ) { return ; } while ( false !== ( $ object = readdir ( $ directoryHandle ) ) ) { if ( $ object == '.' || $ object == '..' ) { continue ; } if ( ! is_dir ( $ directory . '/' . $ object ) ) { unlink ( $ directory . '/' . $ object ) ; } else { $ this -> emptyDirectory ( $ directory . '/' . $ object , true ) ; } } if ( $ deleteDirectory ) { closedir ( $ directoryHandle ) ; rmdir ( $ directory ) ; } }
Recursively delete the files in a directory .
30,280
public function formatOptionsArray ( $ options ) : array { if ( $ this -> isGrouped ( ) ) { return $ options ; } if ( ! is_array ( $ options ) && ! count ( $ options ) ) { return $ options ; } if ( ! isset ( $ options [ 0 ] [ 'value' ] ) ) { $ ret = [ ] ; foreach ( $ options as $ value => $ text ) { $ ret [ ] = [ 'value' => $ value , 'text' => $ text , ] ; } return $ ret ; } return $ options ; }
Thus method is used to ensure the correct format of options array .
30,281
private function getObjectLocalClass ( string $ objectType ) : AbstractObject { if ( ! in_array ( $ objectType , array_keys ( self :: $ objectsMap ) , true ) ) { throw new Exception ( sprintf ( "Unknown Object Type : %s" , $ objectType ) ) ; } $ className = static :: $ objectsMap [ $ objectType ] ; if ( true !== $ this -> isValidObjectClass ( $ className ) ) { throw new Exception ( $ this -> isValidObjectClass ( $ className ) ) ; } $ genericObject = new $ className ( $ this ) ; if ( is_subclass_of ( $ className , AbstractStandaloneObject :: class ) ) { $ genericObject -> configure ( $ objectType , $ this -> getWebserviceId ( ) , $ this -> getConfiguration ( ) ) ; } return $ genericObject ; }
Return a New Intance of Requested Object Type Class
30,282
private function isValidObjectClass ( $ className ) { if ( ! is_string ( $ className ) ) { return "Object Type is Not a String" ; } if ( ! class_exists ( $ className ) ) { return "Object Class Not Found" ; } if ( ! is_subclass_of ( $ className , AbstractObject :: class ) ) { return "Object Class MUST extends " . AbstractObject :: class ; } return true ; }
Validate Object Class Name
30,283
function Accessor ( ) { if ( ! $ this -> accessor ) { $ this -> accessor = $ this -> CreateAccessor ( ) ; $ this -> accessor -> LoadCurrent ( ) ; } return $ this -> accessor ; }
Gets the current accesor
30,284
public static function createGUID ( ) { if ( function_exists ( 'com_create_guid' ) ) { return substr ( com_create_guid ( ) , 1 , 36 ) ; } else { mt_srand ( ( double ) microtime ( ) * 10000 ) ; $ charid = strtoupper ( md5 ( uniqid ( rand ( ) , true ) ) ) ; $ hyphen = chr ( 45 ) ; $ uuid = substr ( $ charid , 0 , 8 ) . $ hyphen . substr ( $ charid , 8 , 4 ) . $ hyphen . substr ( $ charid , 12 , 4 ) . $ hyphen . substr ( $ charid , 16 , 4 ) . $ hyphen . substr ( $ charid , 20 , 12 ) ; return $ uuid ; } }
Creates a globally unique 36 character id
30,285
public static function createTimestamp ( $ time = null , $ format = 'Y-m-d H:i:s' ) { if ( $ time === null ) { $ time = time ( ) ; } elseif ( is_string ( $ time ) ) { $ time = strtotime ( $ time ) ; } return date ( $ format , $ time ) ; }
Creates a date timestamp
30,286
public static function compressArray ( array $ array , $ keys = null ) { $ return = array ( ) ; if ( $ keys && ! is_array ( $ keys ) ) { $ keys = array ( $ keys ) ; } else if ( ! $ keys ) { $ keys = array ( ) ; } foreach ( $ array as $ ky => $ value ) { if ( ! is_array ( $ value ) && stristr ( $ value , '__:DS:__' ) ) { $ value = explode ( '__:DS:__' , $ value ) ; } if ( is_array ( $ value ) ) { $ return = array_merge_recursive ( $ return , self :: compressArray ( $ value , $ keys ) ) ; continue ; } if ( ( $ keys && in_array ( $ ky , $ keys ) ) || ! $ keys ) { if ( array_key_exists ( $ ky , $ return ) ) { if ( is_array ( $ return [ $ ky ] ) ) $ return [ $ ky ] [ ] = $ value ; else $ return [ $ ky ] = array ( $ return [ $ ky ] , $ value ) ; } else { $ return [ $ ky ] = $ value ; } } } return $ return ; }
Compresses an array of arrays into a single array merging identical keys into one with their values as an array
30,287
public static function updateConfig ( $ path , array $ data = array ( ) , $ recursiveMerge = false , $ configArray = null ) { if ( is_null ( $ configArray ) ) { if ( is_readable ( $ path ) ) $ configArray = include $ path ; else { $ configArray = array ( ) ; } } $ config = ( $ recursiveMerge ) ? array_replace_recursive ( $ configArray , $ data ) : array_replace ( $ configArray , $ data ) ; $ content = str_replace ( "=> \n" , '=>' , var_export ( $ config , true ) ) ; return ( file_put_contents ( $ path , '<' . '?php' . "\r\n\treturn " . $ content . ';' ) === FALSE ) ? false : true ; }
Updates a configuration file
30,288
public static function run ( $ name , $ data = array ( ) , $ useMasterKey = false ) { $ sessionToken = null ; if ( AVUser :: getCurrentUser ( ) ) { $ sessionToken = AVUser :: getCurrentUser ( ) -> getSessionToken ( ) ; } $ response = AVClient :: _request ( 'POST' , '/functions/' . $ name , $ sessionToken , json_encode ( AVClient :: _encode ( $ data , null , false ) ) , $ useMasterKey ) ; return AVClient :: _decode ( $ response [ 'result' ] ) ; }
Makes a call to a Cloud function
30,289
public function getData ( ) { return [ 'user user__view_profile' => 'View user profile' , 'user user__view_own_profile' => [ 'type' => Item :: TYPE_PERMISSION , 'description' => 'View user own profile' , 'rule' => new UpdateOwnDataRule ( ) , 'children' => [ 'user user__view_profile' ] ] , 'user' => [ 'type' => Item :: TYPE_ROLE , 'description' => 'User' , 'children' => [ 'user user__view_own_profile' ] , ] , 'admin' => [ 'type' => Item :: TYPE_ROLE , 'description' => 'Admin' , 'children' => [ 'user user__view_profile' ] ] , 'owner' => [ 'type' => Item :: TYPE_ROLE , 'description' => 'Application owner' , 'children' => [ 'admin' ] , ] ] ; }
Gets config data as array
30,290
protected function loadFieldValues ( ) { $ meta = get_post_meta ( $ this -> ID , $ this -> fieldsMetaID , true ) ; if ( is_array ( $ meta ) ) { foreach ( $ this -> fields -> toArray ( ) as $ name => $ field ) { $ fieldName = sanitize_title ( $ name ) ; if ( isset ( $ meta [ $ fieldName ] ) ) { $ this -> fields ( $ name ) -> setValue ( $ meta [ $ fieldName ] ) ; } } } if ( true !== $ this -> serializeDataStorage ) { foreach ( $ this -> fields -> toArray ( ) as $ id => $ field ) { $ fieldID = $ this -> fieldsPrefix . sanitize_title ( $ id ) ; $ fieldName = sanitize_title ( $ id ) ; $ fieldValue = get_post_meta ( $ this -> ID , $ fieldID , true ) ; $ fieldValue = ( empty ( $ fieldValue ) ? ( isset ( $ meta [ $ fieldName ] ) ? $ meta [ $ fieldName ] : '' ) : $ fieldValue ) ; $ this -> fields ( $ id ) -> setValue ( $ fieldValue ) ; } } return $ this ; }
Load on constructor
30,291
protected function headersAndBody ( MessageInterface $ message ) { $ string = '' ; foreach ( $ message -> getHeaders ( ) as $ name => $ values ) { foreach ( $ values as $ value ) { $ string .= $ name . ': ' . $ value . "\n" ; } } $ string .= "\n" ; $ string .= ( string ) $ message -> getBody ( ) ; return $ string ; }
Generate the headers and body part of the message .
30,292
final public function clearCollection ( ) { $ reset = [ & $ this -> collection , & $ this -> collectionRaw , ] ; foreach ( $ reset as & $ property ) { $ property = [ ] ; } }
Clears the collections - Both the raw and the normal one .
30,293
final public function clearContent ( ) { $ reset = [ & $ this -> content , & $ this -> contentRaw , ] ; foreach ( $ reset as & $ property ) { $ property = [ ] ; } }
Clears the contents - Both the raw and the normal one .
30,294
protected function string ( $ content ) { if ( false === is_string ( $ content ) ) { $ content = var_export ( $ content , true ) ; } return $ content ; }
Takes the passed content and return it as string . This method use var_export PHP function .
30,295
protected function format ( $ string = '' , $ type = '' , $ lineBreak = false ) { $ formatted = $ string ; if ( isset ( $ string [ 1 ] ) ) { $ formatted = ' ' . ( strlen ( $ type ) ? $ type . ':' : '' ) . ' ' . $ string . ( ( $ lineBreak ) ? $ this -> lineBreak : '' ) ; } return $ formatted ; }
Formats the passed string with the passed type and the line - break to a complete log - line .
30,296
public static function getLocation ( $ array = false ) { $ folder = realpath ( dirname ( __FILE__ ) . '/../' ) . '/' . self :: DB_FOLDER ; $ filepath = $ folder . '/' . self :: DB_FILENAME ; if ( ! $ array ) { return $ filepath ; } return array ( 'folder' => $ folder , 'file' => self :: DB_FILENAME , ) ; }
Get the location of the database file .
30,297
public function getReleaseDate ( $ release ) { if ( ! $ this -> config -> hasKey ( $ release ) ) { return false ; } return DateTime :: createFromFormat ( 'Y-m-d' , $ this -> config -> getKey ( $ release ) ) ; }
Get the date of a specific release .
30,298
protected function respondRelatedNotes ( $ noteableId , $ objectType ) { $ notes = Note :: where ( 'noteable_id' , $ noteableId ) -> orderBy ( 'created_at' , 'desc' ) -> get ( ) ; return fractal ( $ notes , new NoteTransformer ( ) ) -> withResourceName ( "{$objectType}Note" ) -> respond ( ) ; }
Produce a list of Notes related to a selected object
30,299
public function attach ( Time $ time ) { $ time -> setFormat ( $ this -> format ) ; $ this -> add ( $ time ) ; return $ this ; }
Attaches a time object to collection