idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
16,500
|
public function collectControllerData ( FilterControllerEvent $ event ) { if ( HttpKernelInterface :: SUB_REQUEST === $ event -> getRequestType ( ) ) { return ; } $ controller = $ this -> getClassName ( $ event -> getController ( ) [ 0 ] ) ; $ action = $ event -> getController ( ) [ 1 ] ; $ this -> setController ( $ controller ) ; $ this -> setAction ( $ action ) ; }
|
Collect data from controller .
|
16,501
|
public function resendAction ( Request $ request , User $ user = null ) { $ currentUser = $ this -> getUser ( ) ; if ( null === $ user ) { $ user = $ currentUser ; if ( ! is_object ( $ user ) || ! $ user instanceof UserInterface ) { throw new AccessDeniedException ( 'This user does not have access to this section.' ) ; } } else if ( ! $ this -> isGranted ( 'ROLE_SUPER_ADMIN' ) ) { throw new AccessDeniedException ( 'You cannot resend the confirmation for another user.' ) ; } $ isCurrentUser = $ user -> getId ( ) === $ currentUser -> getId ( ) ; $ redirect = $ request -> headers -> get ( 'referer' , $ this -> generateUrl ( 'fos_user_security_login' ) ) ; if ( $ user -> isEnabled ( ) ) { if ( $ isCurrentUser ) { $ this -> addFlash ( 'warning' , 'Your account is already enabled.' ) ; } else { $ this -> addFlash ( 'warning' , 'The user is already enabled.' ) ; } return $ this -> redirect ( $ redirect ) ; } if ( null === $ user -> getConfirmationToken ( ) ) { $ user -> setConfirmationToken ( $ this -> get ( 'fos_user.util.token_generator' ) -> generateToken ( ) ) ; $ this -> get ( 'fos_user.user_manager' ) -> updateUser ( $ user ) ; } $ this -> get ( 'fos_user.mailer' ) -> sendConfirmationEmailMessage ( $ user ) ; if ( $ isCurrentUser ) { $ this -> addFlash ( 'success' , 'Your account activation email has been resent.' ) ; } else { $ this -> addFlash ( 'success' , 'The account activation email has been resent.' ) ; } return $ this -> redirect ( $ redirect ) ; }
|
Resends the account activation link typically sent during registration .
|
16,502
|
public function getFormByName ( $ name , InputInterface $ input , OutputInterface $ output ) { if ( ! isset ( $ this -> forms [ $ name ] ) ) { throw new \ Exception ( sprintf ( 'Unable to find %s form.' , $ name ) ) ; } return $ this -> createInstance ( $ input , $ output , $ this -> forms [ $ name ] ) ; }
|
Get form by name .
|
16,503
|
protected function createInstance ( InputInterface $ input , OutputInterface $ output , Form $ form = null ) { if ( ! isset ( $ form ) ) { $ form = new Form ( ) ; } return $ form -> setInput ( $ input ) -> setOutput ( $ output ) -> setHelperSet ( $ this -> getHelperSet ( ) ) ; }
|
Create form instance .
|
16,504
|
public function addTo ( $ address , $ title = '' ) { array_push ( $ this -> toAddresses , $ this -> formatEmailAddress ( $ address , $ title ) ) ; return $ this ; }
|
Setter method for adding recipients
|
16,505
|
public function addCC ( $ address , $ title = '' ) { if ( ! isset ( $ this -> headers [ 'CC' ] ) ) { $ this -> headers [ 'CC' ] = array ( ) ; } array_push ( $ this -> headers [ 'CC' ] , $ this -> formatEmailAddress ( $ address , $ title ) ) ; return $ this ; }
|
Setter method for adding cc recipients
|
16,506
|
public function addBCC ( $ address , $ title = '' ) { if ( ! isset ( $ this -> headers [ 'BCC' ] ) ) { $ this -> headers [ 'BCC' ] = array ( ) ; } array_push ( $ this -> headers [ 'BCC' ] , $ this -> formatEmailAddress ( $ address , $ title ) ) ; return $ this ; }
|
Setter method for adding bcc recipients
|
16,507
|
public function setFrom ( $ address , $ title = '' ) { $ this -> headers [ 'From' ] = $ this -> formatEmailAddress ( $ address , $ title ) ; return $ this ; }
|
Setter method for setting the single from field
|
16,508
|
public function setReplyTo ( $ address , $ title = '' ) { $ this -> headers [ 'Reply-To' ] = $ this -> formatEmailAddress ( $ address , $ title ) ; return $ this ; }
|
Setter method for setting the single reply - to field
|
16,509
|
public function addAttachment ( $ path , $ type , $ title = '' ) { array_push ( $ this -> attachments , array ( 'path' => $ path , 'type' => $ type , 'title' => $ title , ) ) ; return $ this ; }
|
Setter method for adding attachments
|
16,510
|
protected function checkRequiredFields ( ) { if ( empty ( $ this -> toAddresses ) ) { return false ; } if ( empty ( $ this -> subject ) ) { return false ; } if ( empty ( $ this -> plainMessage ) && empty ( $ this -> htmlMessage ) && empty ( $ this -> attachments ) ) { return false ; } return true ; }
|
Call to check the minimum required fields
|
16,511
|
protected function buildMessage ( ) { if ( empty ( $ this -> plainMessage ) && empty ( $ this -> htmlMessage ) ) { return '' ; } if ( ! empty ( $ this -> plainMessage ) && empty ( $ this -> htmlMessage ) ) { return $ this -> plainMessage ; } if ( empty ( $ this -> plainMessage ) && ! empty ( $ this -> htmlMessage ) ) { return $ this -> htmlMessage ; } $ message = array ( ) ; array_push ( $ message , "--{$this->boundaryAlternative}" ) ; $ message = array_merge ( $ message , $ this -> buildPlainMessageHeader ( ) ) ; array_push ( $ message , $ this -> plainMessage ) ; array_push ( $ message , "--{$this->boundaryAlternative}" ) ; $ message = array_merge ( $ message , $ this -> buildHtmlMessageHeader ( ) ) ; array_push ( $ message , $ this -> htmlMessage ) ; array_push ( $ message , "--{$this->boundaryAlternative}--" ) ; return implode ( self :: LINE_BREAK , $ message ) ; }
|
Returns a simple email message without attachments
|
16,512
|
protected function buildMessageWithAttachments ( ) { $ message = array ( ) ; if ( ! empty ( $ this -> plainMessage ) || ! empty ( $ this -> htmlMessage ) ) { array_push ( $ message , "--{$this->boundaryMixed}" ) ; } if ( ! empty ( $ this -> plainMessage ) && ! empty ( $ this -> htmlMessage ) ) { array_push ( $ message , "Content-Type: multipart/alternative; boundary={$this->boundaryAlternative}" ) ; array_push ( $ message , '' ) ; array_push ( $ message , "--{$this->boundaryAlternative}" ) ; $ message = array_merge ( $ message , $ this -> buildPlainMessageHeader ( ) ) ; array_push ( $ message , $ this -> plainMessage ) ; array_push ( $ message , "--{$this->boundaryAlternative}" ) ; $ message = array_merge ( $ message , $ this -> buildHtmlMessageHeader ( ) ) ; array_push ( $ message , $ this -> htmlMessage ) ; array_push ( $ message , "--{$this->boundaryAlternative}--" ) ; array_push ( $ message , '' ) ; } elseif ( ! empty ( $ this -> plainMessage ) ) { $ message = array_merge ( $ message , $ this -> buildPlainMessageHeader ( ) ) ; array_push ( $ message , $ this -> plainMessage ) ; } elseif ( ! empty ( $ this -> htmlMessage ) ) { $ message = array_merge ( $ message , $ this -> buildHtmlMessageHeader ( ) ) ; array_push ( $ message , $ this -> htmlMessage ) ; } foreach ( $ this -> attachments as $ attachment ) { array_push ( $ message , "--{$this->boundaryMixed}" ) ; array_push ( $ message , "Content-Type: {$attachment['type']}; name=\"{$attachment['title']}\"" ) ; array_push ( $ message , 'Content-Transfer-Encoding: base64' ) ; array_push ( $ message , 'Content-Disposition: attachment' ) ; array_push ( $ message , '' ) ; array_push ( $ message , $ this -> buildAttachmentContent ( $ attachment [ 'path' ] ) ) ; } array_push ( $ message , "--{$this->boundaryMixed}--" ) ; return implode ( self :: LINE_BREAK , $ message ) ; }
|
Build multi - part message with attachments
|
16,513
|
protected function buildHeaders ( ) { $ headers = array ( ) ; foreach ( $ this -> headers as $ key => $ value ) { if ( $ key == 'CC' || $ key == 'BCC' ) { $ value = implode ( ', ' , $ value ) ; } array_push ( $ headers , sprintf ( '%s: %s' , $ key , $ value ) ) ; } if ( ! empty ( $ this -> attachments ) ) { array_push ( $ headers , "Content-Type: multipart/mixed; boundary=\"{$this->boundaryMixed}\"" ) ; } elseif ( ! empty ( $ this -> plainMessage ) && ! empty ( $ this -> htmlMessage ) ) { array_push ( $ headers , "Content-Type: multipart/alternative; boundary=\"{$this->boundaryAlternative}\"" ) ; } elseif ( ! empty ( $ this -> htmlMessage ) ) { array_push ( $ headers , 'Content-type: text/html; charset="iso-8859-1"' ) ; } return implode ( self :: LINE_BREAK , $ headers ) ; }
|
Builder for the additional headers needed for multipart emails
|
16,514
|
protected function buildAttachmentContent ( $ path ) { if ( ! file_exists ( $ path ) ) { $ this -> logger -> error ( "Could not find file {$path} for attaching to Archangel mail." ) ; return '' ; } $ handle = fopen ( $ path , 'r' ) ; $ contents = fread ( $ handle , filesize ( $ path ) ) ; fclose ( $ handle ) ; $ contents = base64_encode ( $ contents ) ; $ contents = chunk_split ( $ contents ) ; return $ contents ; }
|
File reader for attachments
|
16,515
|
private function registerScript ( ) { ZeroClipboardAsset :: register ( $ this -> getView ( ) ) ; $ clipboardVar = 'client' . preg_replace ( '/[^0-9a-zA-Z_$]/' , '_' , $ this -> id ) ; $ this -> getView ( ) -> registerJs ( 'var ' . $ clipboardVar . ';' , View :: POS_HEAD ) ; $ this -> getView ( ) -> registerJs ( $ clipboardVar . " = new ZeroClipboard($('#" . $ this -> id . "')); " . $ clipboardVar . ".on('copy', function (event) { var clipboard = event.clipboardData; clipboard.setData('text/plain', " . $ this -> text . '); });' ) ; if ( $ this -> enableAftercopy ) { $ this -> getView ( ) -> registerJs ( $ clipboardVar . ".on('aftercopy', function(event) { var oldLabel = $('#" . $ this -> id . "').html(); $('#" . $ this -> id . "').html('" . $ this -> afterCopyLabel . "'); setTimeout(function() { $('#" . $ this -> id . "').html(oldLabel); }, 1000); });" ) ; } }
|
Register button scripts
|
16,516
|
public static function convertCsvToJson ( $ csvFilepath , $ jsonFilepath , $ compressed ) { $ lines = file ( $ csvFilepath ) ; $ jsonFile = fopen ( $ jsonFilepath , "w" ) ; $ headers = array ( ) ; if ( $ compressed ) { fwrite ( $ jsonFile , "[" ) ; } else { fwrite ( $ jsonFile , "[" . PHP_EOL ) ; } foreach ( $ lines as $ lineIndex => $ line ) { if ( $ lineIndex === 0 ) { $ headers = str_getcsv ( $ line ) ; } else { $ data = str_getcsv ( $ line ) ; $ obj = new \ stdClass ( ) ; foreach ( $ headers as $ headerIndex => $ header ) { $ obj -> $ header = $ data [ $ headerIndex ] ; } if ( $ compressed ) { $ jsonString = json_encode ( $ obj , JSON_UNESCAPED_SLASHES ) ; } else { $ jsonString = json_encode ( $ obj , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) ; } if ( ! $ compressed ) { $ jsonStringLines = explode ( PHP_EOL , $ jsonString ) ; foreach ( $ jsonStringLines as $ jsonStringLineIndex => $ line ) { $ jsonStringLines [ $ jsonStringLineIndex ] = " " . $ line ; } $ jsonString = implode ( PHP_EOL , $ jsonStringLines ) ; } if ( $ lineIndex > 1 ) { if ( $ compressed ) { $ jsonString = "," . $ jsonString ; } else { $ jsonString = "," . PHP_EOL . $ jsonString ; } } fwrite ( $ jsonFile , $ jsonString ) ; } } fwrite ( $ jsonFile , "]" ) ; }
|
Converts a CSV file into a JSON file .
|
16,517
|
public static function convertArrayToCsv ( string $ filepath , array $ rows , bool $ addHeader , string $ delimiter = "," , string $ enclosure = '"' ) { $ fileHandle = fopen ( $ filepath , 'w' ) ; if ( $ fileHandle === FALSE ) { throw new \ Exception ( "Failed to open {$filepath} for writing." ) ; } if ( count ( $ rows ) === 0 ) { throw new \ Exception ( "Cannot create CSV file with no data." ) ; } $ firstRow = ArrayLib :: getFirstElement ( $ rows ) ; if ( ArrayLib :: isAssoc ( $ firstRow ) === FALSE ) { throw new \ Exception ( "convertArrayToCsv expects a list of assosciative arrays." ) ; } $ keys = array_keys ( $ firstRow ) ; if ( $ addHeader ) { fputcsv ( $ fileHandle , $ keys , $ delimiter , $ enclosure ) ; } foreach ( $ rows as $ index => $ row ) { if ( count ( $ keys ) != count ( $ row ) ) { $ msg = "Cannot convert array to CSV. Number of keys: " . count ( $ keys ) . " is not the same as the number of values: " . count ( $ row ) ; throw new \ Exception ( $ msg ) ; } $ rowOfValues = array ( ) ; foreach ( $ keys as $ key ) { if ( ! isset ( $ row [ $ key ] ) ) { $ keys = array_keys ( $ row ) ; if ( in_array ( $ key , $ keys ) === FALSE ) { throw new \ Exception ( "row missing expected key {$key} on row {$index}" ) ; } else { $ value = null ; } } else { $ value = $ row [ $ key ] ; } $ rowOfValues [ ] = $ value ; } fputcsv ( $ fileHandle , $ rowOfValues , $ delimiter , $ enclosure ) ; } }
|
Create a CSV file from the provided array of data . This is done in a memory efficient manner of writing one line at a time to the file rather then building a massive string and dumping the entire string to the file .
|
16,518
|
public static function trim ( $ filepath , $ delimiter ) { $ tmpFile = tmpfile ( ) ; $ uploaded_fh = fopen ( $ filepath , "r" ) ; if ( $ uploaded_fh ) { while ( ! feof ( $ uploaded_fh ) ) { $ lineArray = fgetcsv ( $ uploaded_fh , 0 , $ delimiter ) ; if ( ! empty ( $ lineArray ) ) { foreach ( $ lineArray as $ index => $ value ) { $ lineArray [ $ index ] = trim ( $ value ) ; } fputcsv ( $ tmpFile , $ lineArray , "," ) ; } } fclose ( $ uploaded_fh ) ; $ meta_data = stream_get_meta_data ( $ tmpFile ) ; $ tmpFileName = $ meta_data [ "uri" ] ; rename ( $ tmpFileName , $ filepath ) ; } else { throw new \ Exception ( "Failed to open upload file for trimming." ) ; } }
|
Go through the CSV file and trim the values . This saves memory by working line by line rather than reading everything into memory This will replace the existing file s contents so if you need to keep that make a copy first .
|
16,519
|
public static function removeColumns ( $ filepath , array $ columnIndexes , $ delimiter = "," , $ enclosure = '"' ) { $ tmpFile = tmpfile ( ) ; $ fileHandle = fopen ( $ filepath , "r" ) ; $ lineNumber = 1 ; if ( $ fileHandle ) { while ( ! feof ( $ fileHandle ) ) { $ lineArray = fgetcsv ( $ fileHandle , 0 , $ delimiter , $ enclosure ) ; if ( ! empty ( $ lineArray ) ) { foreach ( $ columnIndexes as $ columnHumanIndex ) { $ columnIndex = $ columnHumanIndex - 1 ; if ( ! isset ( $ lineArray [ $ columnIndex ] ) ) { $ msg = "removeColumns: source CSV file does not have " . "column: " . $ columnIndex . " on line: " . $ lineNumber ; throw new \ Exception ( $ msg ) ; } unset ( $ lineArray [ $ columnIndex ] ) ; } fputcsv ( $ tmpFile , $ lineArray , $ delimiter , $ enclosure ) ; } $ lineNumber ++ ; } fclose ( $ fileHandle ) ; $ meta_data = stream_get_meta_data ( $ tmpFile ) ; $ tmpFileName = $ meta_data [ "uri" ] ; rename ( $ tmpFileName , $ filepath ) ; } else { throw new \ Exception ( "removeColumns: failed to open CSV file for trimming." ) ; } }
|
Remove columns from a CSV file .
|
16,520
|
public static function removeRows ( $ filepath , array $ rowIndexes , $ delimiter = "," , $ enclosure = '"' ) { $ tmpFile = tmpfile ( ) ; $ fileHandle = fopen ( $ filepath , "r" ) ; $ lineNumber = 1 ; if ( $ fileHandle ) { while ( ! feof ( $ fileHandle ) ) { $ lineArray = fgetcsv ( $ fileHandle , 0 , $ delimiter , $ enclosure ) ; if ( $ lineArray ) { if ( ! in_array ( $ lineNumber , $ rowIndexes ) ) { fputcsv ( $ tmpFile , $ lineArray , $ delimiter , $ enclosure ) ; } } $ lineNumber ++ ; } fclose ( $ fileHandle ) ; $ meta_data = stream_get_meta_data ( $ tmpFile ) ; $ tmpFileName = $ meta_data [ "uri" ] ; rename ( $ tmpFileName , $ filepath ) ; } else { throw new \ Exception ( "removeRows: Failed to open CSV file for trimming." ) ; } }
|
Remove rows from a CSV file .
|
16,521
|
public static function decimalDiff ( $ filepath1 , $ filepath2 , $ delimiter = "," , $ enclosure = '"' ) { $ newFileName = tempnam ( sys_get_temp_dir ( ) , "" ) ; $ newFileHandle = fopen ( $ newFileName , "w" ) ; if ( ! $ newFileHandle ) { throw new \ Exception ( "Cannot create file to store diff in." ) ; } $ fileHandle1 = fopen ( $ filepath1 , "r" ) ; $ fileHandle2 = fopen ( $ filepath2 , "r" ) ; $ lineNumber = 0 ; if ( $ fileHandle1 && $ fileHandle2 ) { while ( ! feof ( $ fileHandle1 ) ) { $ lineArray1 = fgetcsv ( $ fileHandle1 , 0 , $ delimiter , $ enclosure ) ; $ lineArray2 = fgetcsv ( $ fileHandle2 , 0 , $ delimiter , $ enclosure ) ; $ resultArray = array ( ) ; if ( $ lineArray1 ) { foreach ( $ lineArray1 as $ index => $ value1 ) { if ( ! isset ( $ lineArray2 [ $ index ] ) ) { throw new \ Exception ( "decimalDiff: rows do not have the same column count." ) ; } $ value2 = $ lineArray2 [ $ index ] ; if ( is_numeric ( $ value1 ) && is_numeric ( $ value2 ) ) { $ resultArray [ $ index ] = $ value1 - $ value2 ; } else { if ( $ value1 === $ value2 ) { $ resultArray [ $ index ] = $ value1 ; } else { $ resultArray [ $ index ] = $ value1 . "|" . $ value2 ; } } } } fputcsv ( $ newFileHandle , $ resultArray , $ delimiter , $ enclosure ) ; $ lineNumber ++ ; } fclose ( $ fileHandle1 ) ; fclose ( $ fileHandle2 ) ; fclose ( $ newFileHandle ) ; return $ newFileName ; } else { throw new \ Exception ( "decimalDiff: Failed to open CSV file for processing." ) ; } return $ newFileName ; }
|
Calculate the mathematical differences between two CSV files . If this comes across string values it will check if they are the same and put the the string in if they are otherwise it will concatenate the two values with a | divider . WARNING - this expects the two files to have the same number of columns and rows .
|
16,522
|
public static function diffTolerance ( $ filepath1 , $ filepath2 , array $ tolerances , $ compareOtherColumns = true , $ delimiter = "," , $ enclosure = '"' ) { $ hasFailed = false ; $ humanRowNumber = 1 ; $ fileHandle1 = fopen ( $ filepath1 , "r" ) ; $ fileHandle2 = fopen ( $ filepath2 , "r" ) ; if ( ! $ fileHandle1 || ! $ fileHandle2 ) { throw new \ Exception ( "diffTolerance: Failed to open CSV files for comparison." ) ; } while ( ! feof ( $ fileHandle1 ) && $ hasFailed === FALSE ) { $ lineArray1 = fgetcsv ( $ fileHandle1 , 0 , $ delimiter , $ enclosure ) ; $ lineArray2 = fgetcsv ( $ fileHandle2 , 0 , $ delimiter , $ enclosure ) ; if ( $ lineArray1 ) { foreach ( $ lineArray1 as $ index => $ value1 ) { $ humanColumnNumber = $ index + 1 ; if ( ! isset ( $ lineArray2 [ $ index ] ) ) { throw new \ Exception ( "decimalDiff: rows do not have the same column count." ) ; } $ value2 = $ lineArray2 [ $ index ] ; if ( $ compareOtherColumns || ( isset ( $ tolerances [ $ humanColumnNumber ] ) ) ) { if ( is_numeric ( $ value1 ) && is_numeric ( $ value2 ) ) { $ numericDifference = abs ( $ value1 - $ value2 ) ; if ( isset ( $ tolerances [ $ humanColumnNumber ] ) ) { if ( $ numericDifference > $ tolerances [ $ humanColumnNumber ] ) { $ hasFailed = TRUE ; } } else { if ( $ numericDifference > 0 ) { $ hasFailed = TRUE ; } } } else { if ( isset ( $ tolerances [ $ humanColumnNumber ] ) ) { $ msg = "diffTolerance: Trying to perform numeric tolerance " . "diff on non numeric column. Column: $humanColumnNumber " . "Row: $humanRowNumber" ; throw new \ Exception ( $ msg ) ; } } } else { } } } $ humanRowNumber ++ ; } fclose ( $ fileHandle1 ) ; fclose ( $ fileHandle2 ) ; $ passed = ! $ hasFailed ; return $ passed ; }
|
Perform a diff on two CSV files with a tolerance of values being different by the amount specified . This can be useful in situations with floating point values where the last decimal place may be different .
|
16,523
|
public function registerHandler ( string $ commandClass , string $ serviceName ) : void { if ( ! Validate :: implementsInterface ( $ commandClass , Command :: class ) ) { $ message = sprintf ( 'Invalid command class: %s' , $ commandClass ) ; throw new DomainException ( $ message ) ; } $ type = Type :: create ( $ commandClass ) -> toString ( ) ; $ this -> handlers [ $ type ] = $ serviceName ; }
|
Registers a command handler
|
16,524
|
protected function registerModule ( $ name , \ OtherCode \ FController \ Modules \ BaseModule $ module ) { $ name = strtolower ( $ name ) ; if ( ! array_key_exists ( $ name , $ this -> modules ) ) { $ module -> connect ( $ this -> services , $ this -> storage , $ this -> messages ) ; $ this -> modules [ $ name ] = $ module ; return true ; } return false ; }
|
Register and instantiate a new module
|
16,525
|
public function unregisterModule ( $ name ) { if ( array_key_exists ( $ name , $ this -> modules ) ) { unset ( $ this -> modules [ $ name ] ) ; return true ; } return false ; }
|
Un register a module
|
16,526
|
protected function registerService ( $ name , $ service ) { $ name = strtolower ( $ name ) ; if ( ! isset ( $ this -> services -> $ name ) ) { $ this -> services -> $ name = $ service ; return true ; } return false ; }
|
Register and instantiate a new service
|
16,527
|
public function unregisterService ( $ name ) { $ name = strtolower ( $ name ) ; if ( isset ( $ this -> services -> $ name ) ) { unset ( $ this -> services -> $ name ) ; return true ; } return false ; }
|
Un register a service
|
16,528
|
public function run ( $ path , $ data = null ) { $ model = array ( ) ; $ callPath = $ this -> route ( $ path ) ; $ payload = array ( $ this -> modules [ $ callPath -> module ] , $ callPath -> method ) ; if ( isset ( $ data ) ) { foreach ( $ data as $ key => $ argument ) { $ model [ $ key ] = $ argument ; } } return call_user_func_array ( $ payload , $ model ) ; }
|
Perform the main call of the module method
|
16,529
|
protected function route ( $ path ) { if ( ! preg_match ( '/[a-zA-Z0-9]\.[a-zA-Z0-9]/' , $ path ) ) { throw new \ OtherCode \ FController \ Exceptions \ FControllerException ( "Incorrect module call pattern" , 400 ) ; } $ callPath = explode ( "." , $ path ) ; $ module = strtolower ( $ callPath [ 0 ] ) ; $ method = $ callPath [ 1 ] ; if ( ! array_key_exists ( $ module , $ this -> modules ) ) { throw new \ OtherCode \ FController \ Exceptions \ NotFoundException ( "Module instance not found" , 404 ) ; } if ( ! method_exists ( $ this -> modules [ $ module ] , $ method ) ) { throw new \ OtherCode \ FController \ Exceptions \ NotFoundException ( "Module method requested is not available" , 405 ) ; } return ( object ) array ( 'module' => $ module , 'method' => $ method ) ; }
|
Check and build the payload call
|
16,530
|
public function xor ( Set $ set ) : SetInterface { $ set = new \ DS \ Set ( $ set ) ; $ items = $ this -> items -> xor ( $ set ) ; return $ this -> duplicate ( $ items ) ; }
|
Creates a new set using values in either this set or in another set but not in both .
|
16,531
|
public function filter ( ? callable $ callback = null ) : SetInterface { $ items = $ callback ? $ this -> items -> filter ( $ callback ) : $ this -> items -> filter ( ) ; return $ this -> duplicate ( $ items ) ; }
|
Returns a new set containing only the values for which a callback returns true . A boolean test will be used if a callback is not provided .
|
16,532
|
public function sort ( ? callable $ comparator = null ) : SetInterface { $ comparator ? $ this -> items -> sort ( $ comparator ) : $ this -> items -> sort ( ) ; return $ this ; }
|
Sorts the set in - place based on an optional callable comparator .
|
16,533
|
public static function fromFile ( string $ file , string $ package ) { $ html = '' ; if ( file_exists ( $ file ) ) { $ html = file_get_contents ( $ file ) ; $ html = preg_replace ( "/{(.*)template(.*)}/" , "/templates/" . template ( ) . "/" . $ package , $ html ) ; } return $ html ; }
|
Function for return html from file in template
|
16,534
|
public function has ( string ... $ path ) : bool { try { $ this -> get ( ... $ path ) ; } catch ( ConfigKeyNotFoundException $ e ) { return false ; } return true ; }
|
Check whether the config has a specific key .
|
16,535
|
public function get ( string ... $ path ) { if ( count ( $ path ) === 1 ) { if ( ! $ this -> offsetExists ( $ path [ 0 ] ) ) { throw ConfigKeyNotFoundException :: fromPath ( $ path ) ; } return $ this -> offsetGet ( $ path [ 0 ] ) ; } $ keys = array_reverse ( $ path ) ; $ arr = $ this -> getArrayCopy ( ) ; while ( count ( $ keys ) > 0 ) { $ key = array_pop ( $ keys ) ; if ( ! isset ( $ arr [ $ key ] ) ) { throw ConfigKeyNotFoundException :: fromPath ( $ path ) ; } $ arr = $ arr [ $ key ] ; } return $ arr ; }
|
Get the value for a specific key .
|
16,536
|
public function setOption ( $ name , $ value ) { $ this -> validateName ( $ name ) ; $ this -> config [ $ name ] = $ value ; }
|
Declares a non - transient configuration value
|
16,537
|
public function attach ( $ id , $ instance ) { if ( $ this -> has ( $ id ) ) { return $ this ; } $ this -> instances [ $ id ] = $ instance ; return $ this ; }
|
Attach new instance of any class to this container . If already exists does not attach the new instance .
|
16,538
|
protected static function encodeValue ( $ valueToEncode ) { return openssl_encrypt ( $ valueToEncode , self :: $ encodeMethod , self :: $ privateKey , false , self :: $ initializationVector ) ; }
|
Encode une valeur
|
16,539
|
public function get ( string $ key , $ default = null ) { $ keys = explode ( "." , $ key ) ; $ config_file = $ this -> context_directory . DIRECTORY_SEPARATOR . array_shift ( $ keys ) . ".php" ; if ( ! isset ( $ this -> config_content [ $ config_file ] ) ) { if ( ! is_file ( $ config_file ) ) { throw new \ Exception ( "Config file was not found: " . $ config_file ) ; } $ config_content = require ( $ config_file ) ; } else { $ config_content = $ this -> config_content [ $ config_file ] ; } try { return $ this -> getNestedVar ( $ config_content , $ keys ) ; } catch ( \ Exception $ e ) { return $ default ; } }
|
get config value or fallback gracefully
|
16,540
|
public function validateElements ( ) { $ this -> _isValid = true ; $ values = $ this -> getParams ( ) ; $ this -> recValidateElements ( $ this -> _elements , $ values ) ; }
|
Will run a check on all elements to check if their values are correct . Will also parse the values of the elements to whom parser validators are applied .
|
16,541
|
public function addDisplayElement ( \ OWeb \ types \ Controller $ element ) { $ this -> _displayElements [ ] = $ element ; if ( $ element instanceof \ Controller \ OWeb \ Helpers \ Form \ Elements \ AbstractElement ) { $ this -> _elements [ ] = $ element ; } }
|
Add a display element to the Form . If this element is also a Form Element then it will automatically be added to the list of form elements .
|
16,542
|
public function addElement ( \ Controller \ OWeb \ Helpers \ Form \ Elements \ AbstractElement $ element ) { $ this -> _elements [ ] = $ element ; }
|
Adds an Form Element to the Form without adding it to the Display List .
|
16,543
|
public function setAction ( $ actionName ) { $ this -> _action = new Elements \ Hidden ( ) ; $ this -> _action -> setName ( 'action' ) ; $ this -> _action -> setVal ( $ actionName ) ; $ this -> _action -> init ( ) ; }
|
Set the action of the form . It will generate a hidden element with name action and the desired action name
|
16,544
|
public function setFormat ( string $ format ) { $ no_render_format = [ 'json' , 'xml' , 'css' , 'js' , 'file' ] ; if ( in_array ( $ format , $ no_render_format ) ) { $ this -> render = false ; } $ this -> format = $ format ; }
|
Sets the output format
|
16,545
|
public function ajax ( $ selector = '#content' ) { $ this -> ajax = $ this -> di -> get ( 'core.ajax' ) ; $ cmd = new DomCommand ( $ selector , 'html' , '--empty--' ) ; $ this -> ajax_cmd = $ cmd ; $ content = $ this -> run ( ) ; if ( $ content !== false ) { $ this -> ajax_cmd -> setArgs ( $ content ) ; $ this -> ajax_cmd -> setId ( get_called_class ( ) . '::' . $ this -> action ) ; if ( empty ( $ this -> ajax_cmd -> getSelector ( ) ) && ! empty ( $ selector ) ) { $ this -> ajax_cmd -> setSelector ( $ selector ) ; } $ this -> ajax -> addCommand ( $ this -> ajax_cmd ) ; } }
|
Ajax method to send the result of an action as ajax html command
|
16,546
|
protected function redirect ( string $ target , array $ params = [ ] , bool $ clear_post = true ) { if ( empty ( $ params ) ) { $ params = $ this -> params ; } $ this -> redirect = [ $ target , $ params , $ clear_post ] ; return $ this ; }
|
Redirects from one action to another
|
16,547
|
protected function checkControllerAccess ( $ force = false ) : bool { if ( method_exists ( $ this -> app , 'Access' ) && $ this -> app -> Access ( ) === false ) { return false ; } if ( empty ( $ this -> access ) ) { return true ; } $ perm = [ ] ; if ( array_key_exists ( '*' , $ this -> access ) ) { if ( ! is_array ( $ this -> access [ '*' ] ) ) { $ this -> access [ '*' ] = ( array ) $ this -> access [ '*' ] ; } $ perm += $ this -> access [ '*' ] ; } else { if ( ! array_key_exists ( $ this -> action , $ this -> access ) ) { return true ; } } if ( isset ( $ this -> access [ $ this -> action ] ) ) { if ( ! is_array ( $ this -> access [ $ this -> action ] ) ) { $ this -> access [ $ this -> action ] = ( array ) $ this -> access [ $ this -> action ] ; } $ perm += $ this -> access [ $ this -> action ] ; } if ( $ perm ) { return $ this -> checkAccess ( $ perm ) ; } return false ; }
|
Checks the controller access of the user
|
16,548
|
protected function getFormDesigner ( $ id = '' ) { $ fd = new FormDesigner ( $ this -> app -> getName ( true ) ) ; if ( ! $ id ) { $ pieces = [ ] ; $ string = new CamelCase ( $ this -> app -> getName ( ) ) ; $ pieces [ ] = $ string -> uncamelize ( ) ; $ string -> setString ( $ this -> name ) ; $ pieces [ ] = $ string -> uncamelize ( ) ; $ dbt = debug_backtrace ( DEBUG_BACKTRACE_IGNORE_ARGS , 2 ) ; if ( isset ( $ dbt [ 1 ] [ 'function' ] ) ) { $ string -> setString ( $ dbt [ 1 ] [ 'function' ] ) ; $ pieces [ ] = $ string -> uncamelize ( ) ; } $ id = implode ( '-' , $ pieces ) ; } if ( $ id ) { $ fd -> setId ( $ id ) ; } if ( isset ( $ this -> route ) ) { $ fd -> html -> setAction ( $ this -> app -> url ( $ this -> route , $ this -> params ) ) ; } $ fd -> setToken ( $ this -> di -> get ( 'core.security.form.token.name' ) , $ this -> di -> get ( 'core.security.form.token' ) ) ; return $ fd ; }
|
Shorthand method for a FormDesigner instance with auto attached model
|
16,549
|
protected function setAjaxTarget ( $ target ) { if ( ! empty ( $ this -> ajax_cmd ) ) { $ this -> ajax_cmd -> setSelector ( $ target ) ; } return $ this ; }
|
Sets the selector name to where the result is ajaxed .
|
16,550
|
protected function redirectExit ( $ location = '' , $ permanent = false ) { $ this -> render = false ; if ( empty ( $ location ) ) { $ location = BASEURL ; } if ( preg_match ( '~^(ftp|http)[s]?://~' , $ location ) == 0 && substr ( $ location , 0 , 6 ) != 'about:' ) { $ location = BASEURL . $ location ; } $ _SESSION [ 'Core' ] [ 'redirect' ] = [ 'location' => $ location , 'permanent' => $ permanent ] ; }
|
Redirect function to make sure the browser doesn t come back and repost the form data
|
16,551
|
public static function connection ( $ name = 'default' ) { $ databaseConfig = self :: getConnectionConfiguration ( $ name ) ; $ driver = self :: driver ( $ name ) ; $ username = isset ( $ databaseConfig [ 'username' ] ) ? $ databaseConfig [ 'username' ] : null ; $ password = isset ( $ databaseConfig [ 'password' ] ) ? $ databaseConfig [ 'password' ] : null ; $ options = isset ( $ databaseConfig [ 'options' ] ) ? $ databaseConfig [ 'options' ] : array ( ) ; if ( ! isset ( self :: $ connections [ $ name ] ) ) { $ connection = $ driver -> connect ( $ databaseConfig , $ username , $ password , $ options ) ; self :: $ connections [ $ name ] = $ connection ; } return self :: $ connections [ $ name ] ; }
|
Get connection instance for connection name .
|
16,552
|
public static function entityManager ( $ name = 'default' ) { if ( isset ( self :: $ entityManagers [ $ name ] ) ) { return self :: $ entityManagers [ $ name ] ; } $ databaseConnection = self :: connection ( $ name ) -> getDbalConnection ( ) ; if ( Configuration :: get ( 'app.env' ) == 'development' ) { $ cache = new ArrayCache ( ) ; } else { $ cache = new FilesystemCache ( Configuration :: get ( 'app.cache' ) ) ; } $ config = new \ Doctrine \ ORM \ Configuration ( ) ; $ config -> setMetadataCacheImpl ( $ cache ) ; $ driver = $ config -> newDefaultAnnotationDriver ( [ APPPATH . 'Entity' ] , false ) ; $ config -> setMetadataDriverImpl ( $ driver ) ; $ config -> setQueryCacheImpl ( $ cache ) ; $ proxyDir = APPPATH . 'Proxy' ; $ proxyNamespace = 'App\Proxy' ; $ config -> setProxyDir ( $ proxyDir ) ; $ config -> setProxyNamespace ( $ proxyNamespace ) ; Autoloader :: register ( $ proxyDir , $ proxyNamespace ) ; $ loggerChain = new LoggerChain ( ) ; if ( Configuration :: get ( 'app.env' ) == 'development' ) { $ config -> setAutoGenerateProxyClasses ( true ) ; $ loggerChain -> addLogger ( new DoctrineLogBridge ( \ Logger :: getInstance ( ) -> getMonologInstance ( ) ) ) ; $ loggerChain -> addLogger ( DebugBarHelper :: getInstance ( ) -> getDebugStack ( ) ) ; } else { $ config -> setAutoGenerateProxyClasses ( false ) ; } $ em = EntityManager :: create ( $ databaseConnection , $ config ) ; $ em -> getConnection ( ) -> getConfiguration ( ) -> setSQLLogger ( $ loggerChain ) ; $ em -> getConfiguration ( ) -> setSQLLogger ( $ loggerChain ) ; self :: $ entityManagers [ $ name ] = $ em ; return $ em ; }
|
Get entity manager for the connection and apps .
|
16,553
|
public static function driver ( $ name = 'default' , $ driverName = null ) { if ( $ name !== null && $ driverName === null ) { $ databaseConfig = self :: getConnectionConfiguration ( $ name ) ; $ driverName = $ databaseConfig [ 'driver' ] ; } if ( ! isset ( self :: $ drivers [ $ driverName ] ) ) { $ driverClass = new \ ReflectionClass ( "\\Arvici\\Heart\\Database\\Driver\\$driverName\\Driver" ) ; self :: $ drivers [ $ driverName ] = $ driverClass -> newInstance ( ) ; } return self :: $ drivers [ $ driverName ] ; }
|
Get driver instance for connection name or driver name .
|
16,554
|
public static function typeOfValue ( $ value ) { if ( is_null ( $ value ) ) { return self :: TYPE_NULL ; } if ( is_int ( $ value ) ) { return self :: TYPE_INT ; } if ( is_bool ( $ value ) ) { return self :: TYPE_BOOL ; } return self :: TYPE_STR ; }
|
Get type of value .
|
16,555
|
protected function setError ( $ field , $ errorType , $ error ) { if ( is_array ( $ error ) ) { if ( ! array_key_exists ( 'status' , $ error ) ) { $ error [ 'status' ] = 400 ; } $ error = $ this -> getFactory ( ) -> newError ( $ error ) ; } return $ this -> setJsonApiError ( $ field , $ errorType , $ error ) ; }
|
Make it easier to set errors on objects
|
16,556
|
public function indexAction ( ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ roles = $ em -> getRepository ( 'CoreBundle:Role' ) -> findAll ( ) ; return array ( 'roles' => $ roles , ) ; }
|
Lists all role entities .
|
16,557
|
public function addAction ( Request $ request , $ id ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ actor = $ em -> getRepository ( $ this -> get ( 'core_manager' ) -> getActorBundleName ( ) . ':Actor' ) -> findOneById ( $ id ) ; $ trans = $ this -> get ( 'translator' ) ; $ form = $ this -> container -> get ( 'form.factory' ) -> create ( 'CoreBundle\Form\ActorRoleType' ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isSubmitted ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ data = $ request -> request -> get ( $ form -> getName ( ) ) ; $ role = $ em -> getRepository ( 'CoreBundle:Role' ) -> find ( $ data [ 'roles' ] ) ; $ actor -> addRole ( $ role ) ; try { $ em -> persist ( $ actor ) ; $ em -> flush ( $ actor ) ; return new JsonResponse ( array ( 'status' => 'success' , 'id' => $ actor -> getId ( ) , 'message' => $ trans -> trans ( 'role.created' ) ) ) ; } catch ( \ Exception $ exc ) { return new JsonResponse ( array ( 'status' => 'error' , 'message' => $ trans -> trans ( 'role.duplicate' ) ) ) ; } } return new JsonResponse ( array ( 'status' => 'error' , 'message' => $ trans -> trans ( 'role.form.notsubmit' ) ) ) ; }
|
Add role by ajax
|
16,558
|
public function newAction ( Request $ request ) { $ role = new Role ( ) ; $ form = $ this -> createForm ( 'CoreBundle\Form\RoleType' , $ role ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> persist ( $ role ) ; $ em -> flush ( $ role ) ; if ( $ request -> isXMLHttpRequest ( ) ) { return new JsonResponse ( array ( 'id' => $ role -> getId ( ) , ) ) ; } $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , 'role.created' ) ; return $ this -> redirectToRoute ( 'core_role_show' , array ( 'id' => $ role -> getId ( ) ) ) ; } return array ( 'role' => $ role , 'form' => $ form -> createView ( ) , ) ; }
|
Creates a new role entity .
|
16,559
|
public function showAction ( Role $ role ) { $ deleteForm = $ this -> createDeleteForm ( $ role ) ; return array ( 'role' => $ role , 'delete_form' => $ deleteForm -> createView ( ) , ) ; }
|
Finds and displays a role entity .
|
16,560
|
public function editAction ( Request $ request , Role $ role ) { $ deleteForm = $ this -> createDeleteForm ( $ role ) ; $ editForm = $ this -> createForm ( 'CoreBundle\Form\RoleType' , $ role ) ; $ editForm -> handleRequest ( $ request ) ; if ( $ editForm -> isSubmitted ( ) && $ editForm -> isValid ( ) ) { $ this -> getDoctrine ( ) -> getManager ( ) -> flush ( ) ; if ( $ request -> isXMLHttpRequest ( ) ) { return new JsonResponse ( array ( 'id' => $ role -> getId ( ) , ) ) ; } $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , 'role.edited' ) ; return $ this -> redirectToRoute ( 'core_role_edit' , array ( 'id' => $ role -> getId ( ) ) ) ; } return array ( 'role' => $ role , 'edit_form' => $ editForm -> createView ( ) , 'delete_form' => $ deleteForm -> createView ( ) , ) ; }
|
Displays a form to edit an existing role entity .
|
16,561
|
public function deleteRoleActorAction ( Request $ request , Role $ role , $ actor ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ actor = $ em -> getRepository ( $ this -> get ( 'core_manager' ) -> getActorBundleName ( ) . ':Actor' ) -> findOneById ( $ actor ) ; $ actor -> getRolesCollection ( ) -> removeElement ( $ role ) ; $ em -> flush ( ) ; $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , 'role.deleted' ) ; if ( $ request -> query -> get ( 'redirect' ) != '' ) { return $ this -> redirect ( $ request -> query -> get ( 'redirect' ) ) ; } return $ this -> redirectToRoute ( 'core_role_index' ) ; }
|
Deletes a role entity .
|
16,562
|
private function createDeleteForm ( Role $ role ) { return $ this -> createFormBuilder ( ) -> setAction ( $ this -> generateUrl ( 'core_role_delete' , array ( 'id' => $ role -> getId ( ) ) ) ) -> setMethod ( 'DELETE' ) -> getForm ( ) ; }
|
Creates a form to delete a role entity .
|
16,563
|
public function populateAppIds ( $ e ) { $ appsArray = $ e -> getParam ( 'apps' ) ; $ appService = $ e -> getTarget ( ) -> getServiceManager ( ) -> get ( 'playgroundfacebook_app_service' ) ; $ apps = $ appService -> getAvailableApps ( ) ; foreach ( $ apps as $ app ) { $ app_label = '' ; if ( $ app -> getAppName ( ) ) { $ app_label .= $ app -> getAppName ( ) ; } if ( $ app -> getAppId ( ) ) { $ app_label .= ' (' . $ app -> getAppId ( ) . ')' ; } $ appsArray [ $ app -> getAppId ( ) ] = $ app_label ; } return $ appsArray ; }
|
This method get the Fb apps and add them as array to PlaygroundGame form so that there is non adherence between modules ... not that satisfied neither
|
16,564
|
private function validateType ( ) : bool { switch ( $ this -> options [ 'type' ] ) { case 'integer' : $ isValid = \ is_int ( $ this -> value ) ? true : false ; break ; case 'float' : $ isValid = \ is_int ( $ this -> value ) || \ is_float ( $ this -> value ) ? true : false ; break ; default : $ isValid = \ is_int ( $ this -> value ) || \ is_float ( $ this -> value ) ? true : false ; break ; } if ( ! $ isValid ) { $ this -> setError ( self :: VALIDATOR_ERROR_NUMBER_INCORRECT_TYPE ) ; } return $ isValid ; }
|
Checks whether number is of required type . Integers are treated as valid floats .
|
16,565
|
private function validateGreaterThan ( ) : bool { if ( $ this -> options [ 'min' ] !== null ) { if ( $ this -> options [ 'inclusive' ] === false && $ this -> value <= $ this -> options [ 'min' ] ) { $ this -> setError ( self :: VALIDATOR_ERROR_NUMBER_MUST_BE_HIGHER_THAN_MIN ) ; return false ; } if ( $ this -> value < $ this -> options [ 'min' ] ) { $ this -> setError ( self :: VALIDATOR_ERROR_NUMBER_MUST_BE_HIGHER_OR_EQUAL_TO_MIN ) ; return false ; } } return true ; }
|
Checks whether number is greater than specified min number
|
16,566
|
private function validateLowerThan ( ) : bool { if ( $ this -> options [ 'max' ] !== null ) { if ( $ this -> options [ 'inclusive' ] === false && $ this -> value >= $ this -> options [ 'max' ] ) { $ this -> setError ( self :: VALIDATOR_ERROR_NUMBER_MUST_BE_LOWER_THAN_MAX ) ; return false ; } if ( $ this -> value > $ this -> options [ 'max' ] ) { $ this -> setError ( self :: VALIDATOR_ERROR_NUMBER_MUST_BE_LOWER_OR_EQUAL_TO_MAX ) ; return false ; } } return true ; }
|
Checks whether number is lower than specified max number
|
16,567
|
public function validate ( string ... $ constantNames ) : ResultInterface { $ notDefined = array_filter ( $ constantNames , function ( string $ key ) : bool { return ! defined ( $ key ) ; } ) ; return $ this -> report ( ... $ notDefined ) ; }
|
Validates constants are defined .
|
16,568
|
public static function assert ( $ test , $ message , $ code = null ) { if ( ! is_callable ( $ test ) ) { throw new self ( 'Test for assert is not callable' , 500 ) ; } if ( $ test ( ) === true ) { throw new static ( $ message , $ code ) ; } }
|
Assert a test and throw this exception if it returns true
|
16,569
|
private function validate ( $ hash , string $ validation_regex ) : void { if ( ! is_string ( $ hash ) || preg_match ( $ validation_regex , $ hash ) === 0 ) { throw new InvalidArgumentException ( 'Expected hash, but got ' . var_export ( $ hash , true ) . '] instead' ) ; } }
|
Ensures the hash passed in is valid
|
16,570
|
public function done ( ) { if ( array_diff ( $ this -> registered , $ this -> serviceProvider -> provides ( ) ) ) { throw new ServiceProviderException ( get_class ( $ this -> serviceProvider ) . ' said it would provide: "' . join ( ', ' , $ this -> serviceProvider -> provides ( ) ) . '" but ended up providing "' . join ( ', ' , $ this -> registered ) . '"' ) ; } }
|
Check all the items that were promised were actually registered
|
16,571
|
public static function assoc_to_keyval ( $ assoc , $ keyField , $ valField ) { if ( ! is_array ( $ assoc ) and ! $ assoc instanceof Iterator ) { throw new InvalidArgumentException ( 'The first parameter must be an array.' ) ; } $ output = [ ] ; foreach ( $ assoc as $ row ) { if ( isset ( $ row [ $ keyField ] ) and isset ( $ row [ $ valField ] ) ) { $ output [ $ row [ $ keyField ] ] = $ row [ $ valField ] ; } } return $ output ; }
|
Converts a multi - dimensional associative array into an array of key = > values with the provided field names .
|
16,572
|
public static function reverse_flatten ( $ array , $ glue = ':' ) { $ return = [ ] ; foreach ( $ array as $ key => $ value ) { if ( stripos ( $ key , $ glue ) !== false ) { $ keys = explode ( $ glue , $ key ) ; $ temp = & $ return ; while ( count ( $ keys ) > 1 ) { $ key = array_shift ( $ keys ) ; $ key = is_numeric ( $ key ) ? ( int ) $ key : $ key ; if ( ! isset ( $ temp [ $ key ] ) or ! is_array ( $ temp [ $ key ] ) ) { $ temp [ $ key ] = [ ] ; } $ temp = & $ temp [ $ key ] ; } $ key = array_shift ( $ keys ) ; $ key = is_numeric ( $ key ) ? ( int ) $ key : $ key ; $ temp [ $ key ] = $ value ; } else { $ key = is_numeric ( $ key ) ? ( int ) $ key : $ key ; $ return [ $ key ] = $ value ; } } return $ return ; }
|
Reverse a flattened array in its original form .
|
16,573
|
public static function filter_prefixed ( $ array , $ prefix , $ removePrefix = true ) { $ return = [ ] ; foreach ( $ array as $ key => $ val ) { if ( preg_match ( '/^' . $ prefix . '/' , $ key ) ) { if ( $ removePrefix === true ) { $ key = preg_replace ( '/^' . $ prefix . '/' , '' , $ key ) ; } $ return [ $ key ] = $ val ; } } return $ return ; }
|
Filters an array on prefixed associative keys .
|
16,574
|
public static function replaceAssoc ( array $ replace , string $ subject ) { return str_replace ( array_keys ( $ replace ) , array_values ( $ replace ) , $ subject ) ; }
|
Associative analogue str_replace .
|
16,575
|
public function badge ( $ label , $ colorOrStatus = null , $ toolTipLabel = null ) { switch ( true ) { case ! isset ( $ this -> list [ $ this -> listCount - 1 ] ) : Checkers :: notice ( 'Unable to put badge [' . $ label . '] in list group, no element.' ) ; break ; case $ this -> list [ $ this -> listCount - 1 ] instanceof Button : Checkers :: notice ( 'Unable to badge a list group button. Use an element instead.' ) ; break ; case is_array ( $ this -> list [ $ this -> listCount - 1 ] ) : $ this -> badges [ $ this -> listCount - 1 ] [ ] = $ this -> getBadgeHtml ( $ label , $ colorOrStatus , $ toolTipLabel ) ; break ; default : Checkers :: notice ( 'Unable to find what to do with your badge [' . $ label . ']...' ) ; } return $ this ; }
|
Add a badge to current item
|
16,576
|
public function addItem ( $ label , $ url = null , $ status = null , $ active = false , array $ cssClasses = [ ] , array $ attrs = [ ] ) { return $ this -> addContentItem ( $ label , null , $ url , $ status , $ active , $ cssClasses , $ attrs ) ; }
|
Simple list item
|
16,577
|
public function addContentItem ( $ label , $ content , $ url = null , $ status = null , $ active = false , array $ cssClasses = [ ] , array $ attrs = [ ] ) { Checkers :: checkUrl ( $ url ) ; $ status === null || Checkers :: checkStatus ( $ status , null , true ) ; $ url === null || $ this -> ulList = false ; $ this -> list [ ] = [ ( string ) $ label , $ url , ( string ) $ content , $ status , ( bool ) $ active , $ cssClasses , $ attrs ] ; $ this -> listCount ++ ; return $ this ; }
|
List item with content
|
16,578
|
public function getColumnDDL ( Column $ col ) { $ domain = $ col -> getDomain ( ) ; $ ddl = array ( $ this -> quoteIdentifier ( $ col -> getName ( ) ) ) ; $ sqlType = $ domain -> getSqlType ( ) ; if ( $ this -> hasSize ( $ sqlType ) ) { $ ddl [ ] = $ sqlType . $ domain -> printSize ( ) ; } else { $ ddl [ ] = $ sqlType ; } if ( $ default = $ this -> getColumnDefaultValueDDL ( $ col ) ) { $ ddl [ ] = $ default ; } if ( $ notNull = $ this -> getNullString ( $ col -> isNotNull ( ) ) ) { $ ddl [ ] = $ notNull ; } if ( $ autoIncrement = $ col -> getAutoIncrementString ( ) ) { $ ddl [ ] = $ autoIncrement ; } return implode ( ' ' , $ ddl ) ; }
|
Builds the DDL SQL for a Column object .
|
16,579
|
public static function last ( $ name ) { if ( ! $ name ) { $ database = config ( 'database.database' ) ; $ path = root ( ) . 'database/backup' ; $ files = glob ( $ path . '/*.sql' ) ; if ( ! is_null ( $ files ) ) { for ( $ i = count ( $ files ) - 1 ; $ i >= 0 ; $ i -- ) { $ file = $ files [ $ i ] ; $ file = explode ( root ( ) . 'database/backup/' . $ database . '_' , $ file ) ; $ file = $ file [ 1 ] ; $ file = explode ( '.sql' , $ file ) ; $ file = $ file [ 0 ] ; if ( is_numeric ( $ file ) ) { return root ( ) . 'database/backup/' . $ database . '_' . $ file . '.sql' ; } } } } elseif ( $ name ) { return root ( ) . 'database/backup/' . $ name . '.sql' ; } }
|
Get the last database save .
|
16,580
|
public static function import ( $ name = null ) { $ file = static :: last ( $ name ) ; if ( ! is_null ( $ file ) ) { $ query = ( new Filesystem ( ) ) -> get ( $ file ) ; Database :: exec ( $ query ) ; return true ; } }
|
Import the last save or custom save .
|
16,581
|
public static function create ( $ name = null ) { $ name = $ name ? $ name : self :: generateName ( ) ; $ container = new Container ( $ name ) ; $ container -> register ( 'Container' , $ container ) ; self :: $ containers [ $ name ] = $ container ; return $ container ; }
|
Create container .
|
16,582
|
public static function get ( $ name = null ) { if ( $ name === null ) { $ name = array_shift ( array_keys ( self :: $ containers ) ) ; } return self :: $ containers [ $ name ] ? self :: $ containers [ $ name ] : null ; }
|
Get container .
|
16,583
|
public static function utf8 ( string $ in_p ) { $ value = str_replace ( "<br>" , "\n" , $ in_p ) ; $ value = str_replace ( " " , " " , $ value ) ; $ value = preg_replace ( '/<([\s\S]*?)>/u' , '' , $ value ) ; $ value = preg_replace ( '/<\/([\s\S]*?)>/u' , '' , $ value ) ; return $ value ; }
|
transform the given string into utf8 format strings
|
16,584
|
public static function unix_dir ( string $ path ) { $ path = str_replace ( '\\' , '/' , $ path ) ; $ path = preg_replace ( '|(?<=.)/+|' , '/' , $ path ) ; if ( ':' === substr ( $ path , 1 , 1 ) ) { $ path = ucfirst ( $ path ) ; } return $ path ; }
|
change windows directory into unix directory
|
16,585
|
public static function windows_dir ( string $ path ) { $ path = str_replace ( '/' , '\\' , $ path ) ; $ path = preg_replace ( '|(?<=.)/+|' , '\\' , $ path ) ; if ( ':' === substr ( $ path , 1 , 1 ) ) { $ path = ucfirst ( $ path ) ; } return $ path ; }
|
change unix directory into windows directory
|
16,586
|
public function getCurrentPage ( ) { $ givenRelativeFile = str_replace ( $ this -> environment -> getSourceDirectory ( ) , '' , $ this -> environment -> getSourceFile ( ) ) ; return str_replace ( '.twig' , '' , $ givenRelativeFile ) ; }
|
will return current parsed page
|
16,587
|
public function getBasepath ( $ suffix = null ) { $ relativeDirectory = '.' ; $ givenRelativePath = dirname ( $ this -> getCurrentPage ( ) ) ; if ( $ givenRelativePath === '/' ) { $ givenRelativePath = '' ; } $ depth = substr_count ( $ givenRelativePath , '/' ) ; for ( $ i = 0 ; $ i < $ depth ; $ i ++ ) { $ relativeDirectory .= '/..' ; } if ( $ suffix ) { return $ relativeDirectory . '/' . $ suffix ; } else { return $ relativeDirectory ; } }
|
calculates the relative basepath
|
16,588
|
public function jsonSerialize ( ) { $ data = new stdClass ( ) ; $ vars = get_object_vars ( $ this ) ; foreach ( $ vars as $ property => $ value ) { if ( $ value === null ) { continue ; } $ data -> { $ property } = $ value ; } return $ data ; }
|
Get data for JSON serialization .
|
16,589
|
public function validateProperty ( $ property , $ type , $ value , $ class = __CLASS__ ) { $ aType = gettype ( $ value ) ; if ( $ aType !== $ type ) { throw new JsonModelException ( JsonModelException :: BAD_PROPERTY_TYPE , [ $ property , $ type , $ aType ] ) ; } if ( $ value === null ) { throw new JsonModelException ( JsonModelException :: PROPERTY_EMPTY , [ $ class , $ property , $ aType ] ) ; } return true ; }
|
Verify that a property exists and its value is of a specified type .
|
16,590
|
public function sendJsonLoad ( $ json , $ httpVerb = 'POST' ) { $ communicationId = uniqid ( date ( "Y-m-d-His_" ) ) ; $ this -> logCommunication ( $ json , $ httpVerb , $ communicationId ) ; $ ch = curl_init ( $ this -> apiUrl ) ; curl_setopt_array ( $ ch , array ( CURLOPT_RETURNTRANSFER => true , CURLOPT_POSTFIELDS => $ json , CURLOPT_SSL_VERIFYPEER => false , CURLOPT_SSL_VERIFYHOST => false , ) ) ; switch ( $ httpVerb ) { case 'POST' : curl_setopt ( $ ch , CURLOPT_POST , true ) ; case 'GET' : case 'DELETE' : curl_setopt_array ( $ ch , array ( CURLOPT_HTTPHEADER => array ( 'Content-Type: application/json' ) , ) ) ; if ( in_array ( $ httpVerb , array ( 'GET' , 'DELETE' ) ) ) { curl_setopt ( $ ch , CURLOPT_CUSTOMREQUEST , $ httpVerb ) ; } break ; case 'PUT' : curl_setopt_array ( $ ch , array ( CURLOPT_HTTPHEADER => array ( 'Content-Type: application/json' , 'Content-Length: ' . strlen ( $ json ) ) , CURLOPT_CUSTOMREQUEST => 'PUT' , ) ) ; break ; default : $ this -> logger -> error ( "Unknown verb {$httpVerb}" ) ; return false ; } $ result = curl_exec ( $ ch ) ; if ( $ result ) { $ this -> logCommunication ( $ result , 'resp' , $ communicationId ) ; } elseif ( ! is_null ( $ this -> logger ) ) { $ this -> logger -> error ( "Curl failed with (" . curl_errno ( $ ch ) . ") " . curl_error ( $ ch ) ) ; } return $ result ; }
|
Send a JSON to the API and returns whatever is to return
|
16,591
|
public function getJsonArray ( $ json ) { $ response = $ this -> sendJsonLoad ( $ json ) ; $ result = json_decode ( $ response , true ) ; if ( ! $ result && ! is_null ( $ this -> logger ) ) { $ this -> logger -> error ( "json decode failed for " . substr ( $ response , 0 , 100 ) . " that resulted from " . substr ( $ json , 0 , 100 ) ) ; } return $ result ; }
|
Sends JSON and return array decoded from the received JSON response
|
16,592
|
public static function instance ( $ id ) { $ class = get_called_class ( ) ; if ( empty ( static :: $ instances [ $ class ] [ $ id ] ) ) { static :: $ instances [ $ class ] [ $ id ] = new static ( $ id ) ; } return static :: $ instances [ $ class ] [ $ id ] ; }
|
Create and return a cached instance
|
16,593
|
protected function getNullableDataModel ( $ type , $ shallow , $ object , ... $ properties ) { $ object = $ this -> getNullable ( $ object , ... $ properties ) ; if ( $ object == null ) { return null ; } return $ this -> getDataModel ( $ object , $ type , $ shallow ) ; }
|
Returns a data object that can be a null
|
16,594
|
public function notify ( $ message , $ color = Client :: COLOR_YELLOW , $ alert = false , $ format = Client :: FORMAT_TEXT ) { $ query = json_encode ( [ 'message' => $ message , 'color' => $ color , 'notify' => $ alert , 'format' => $ format ] ) ; $ response = $ this -> client -> post ( "/v2/room/{$this->room}/notification" , $ query ) ; if ( $ response -> getStatusCode ( ) === 204 ) { return true ; } throw new \ Exception ( $ response -> getBody ( ) , $ response -> getStatusCode ( ) ) ; }
|
Send a notification to the given room .
|
16,595
|
public static function A2tf ( $ ndp , $ angle , & $ sign , array & $ ihmsf ) { static :: D2tf ( $ ndp , $ angle / D2PI , $ sign , $ ihmsf ) ; return ; }
|
- - - - - - - - i a u A 2 t f - - - - - - - -
|
16,596
|
public function get ( $ objectType ) { do { if ( isset ( $ this -> permissionCollections [ $ objectType ] ) ) { return $ this -> permissionCollections [ $ objectType ] ; } $ actualObjectType = $ objectType ; $ objectType = get_parent_class ( $ objectType ) ; } while ( $ objectType !== false ) ; throw new InvalidArgumentException ( "No permissions for type $actualObjectType found." ) ; }
|
Return permissions for object type .
|
16,597
|
public function toMap ( bool $ mutable ) : ArrayMap { if ( $ mutable ) { return new MutableMap ( $ this -> data ) ; } else { return new ImmutableMap ( $ this -> data ) ; } }
|
Copy the data of this list into a map . Keys are preserved .
|
16,598
|
public function reduce ( callable $ callback , $ initialValue = null ) { $ data = $ initialValue ; foreach ( $ this -> data as $ value ) { $ data = $ callback ( $ value , $ data ) ; } return $ data ; }
|
Reduce the list to a single value using a user - provided callback .
|
16,599
|
public function getElement ( Parser $ parser , ElementInterface $ parent = null ) { $ parser -> getReader ( ) -> open ( $ this -> src ) ; $ parsed = $ parser -> getReader ( ) -> parse ( ) ; return $ parser -> parseElements ( $ parsed [ 'value' ] , $ parent ) ; }
|
Get an instance of ElementInterface for this reservation
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.