idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
26,300
public function decryptValue ( $ value ) { $ decoded = base64_decode ( $ value ) ; $ iv_size = mcrypt_get_iv_size ( MCRYPT_RIJNDAEL_256 , MCRYPT_MODE_ECB ) ; $ iv = mcrypt_create_iv ( $ iv_size , MCRYPT_RAND ) ; $ text = mcrypt_decrypt ( MCRYPT_RIJNDAEL_256 , $ this -> salt , $ decoded , MCRYPT_MODE_ECB , $ iv ) ; return trim ( $ text ) ; }
Decrypts a value
26,301
public function generateTokenByUser ( $ user ) { return $ this -> builder -> set ( 'user' , $ user ) -> sign ( new Sha256 ( ) , env ( 'JWT_SECRET' ) ) -> getToken ( ) ; }
Create object of a token .
26,302
private function flattenParametersFromConfig ( ContainerBuilder $ container , $ configs , $ root ) { $ parameters = [ ] ; foreach ( $ configs as $ key => $ value ) { $ parameterKey = sprintf ( '%s_%s' , $ root , $ key ) ; if ( is_array ( $ value ) ) { $ parameters = array_merge ( $ parameters , $ this -> flattenParametersFromConfig ( $ container , $ value , $ parameterKey ) ) ; continue ; } $ parameters [ $ parameterKey ] = $ value ; } return $ parameters ; }
Flatten multi - dimensional Symfony configuration array into a one - dimensional parameters array .
26,303
protected function loadInternal ( array $ configs , ContainerBuilder $ container ) { $ parameters = $ this -> flattenParametersFromConfig ( $ container , $ configs , 'vm_pro_api' ) ; foreach ( $ parameters as $ key => $ value ) { $ container -> setParameter ( $ key , $ value ) ; } $ loader = new YamlFileLoader ( $ container , new FileLocator ( __DIR__ . '/../Resources/config' ) ) ; $ loader -> load ( 'services/main.yml' ) ; if ( array_key_exists ( 'vm_pro_api_rating_meta_data_fields_average' , $ parameters ) && array_key_exists ( 'vm_pro_api_rating_meta_data_fields_count' , $ parameters ) ) { $ loader -> load ( 'services/ratings.yml' ) ; } if ( version_compare ( ClientInterface :: VERSION , '6.0' , '>=' ) ) { $ loader -> load ( 'services/guzzle6.yml' ) ; } else { $ loader -> load ( 'services/guzzle5.yml' ) ; } if ( version_compare ( Kernel :: VERSION , '3.3' , '>=' ) ) { $ loader -> load ( 'services/symfony3.yml' ) ; } }
Load the appropriate service container configurations based on which GuzzleHttp library is present in the project .
26,304
public function render ( $ controller , $ template , $ data ) { $ view = new View ( $ controller ) ; $ css = array ( ) ; $ html = $ view -> mail ( $ template , $ data , $ css ) ; $ cssToInlineStyles = new CssToInlineStyles ( ) ; $ cssToInlineStyles -> setCSS ( $ this -> getCss ( $ css ) ) ; $ cssToInlineStyles -> setHTML ( $ html ) ; return $ cssToInlineStyles -> convert ( ) ; }
Genera una vista del email compatible con clientes de correo
26,305
private function patchExtractor ( $ path , $ extractor , $ wantedAuthors ) { if ( ! ( $ this -> diff && $ extractor instanceof PatchingExtractor ) ) { return false ; } $ original = \ explode ( "\n" , $ extractor -> getBuffer ( $ path ) ) ; $ new = \ explode ( "\n" , $ extractor -> getBuffer ( $ path , $ wantedAuthors ) ) ; $ diff = new \ Diff ( $ original , $ new ) ; $ patch = $ diff -> render ( $ this -> diff ) ; if ( empty ( $ patch ) ) { return false ; } $ patchFile = $ path ; foreach ( $ this -> config -> getIncludedPaths ( ) as $ prefix ) { $ prefixLength = \ strlen ( $ prefix ) ; if ( strpos ( $ path , $ prefix ) === 0 ) { $ patchFile = \ substr ( $ path , $ prefixLength ) ; if ( strncmp ( $ patchFile , '/' , 1 ) === 0 ) { $ patchFile = \ substr ( $ patchFile , 1 ) ; } break ; } } $ this -> patchSet [ ] = 'diff ' . $ patchFile . ' ' . $ patchFile . "\n" . '--- ' . $ patchFile . "\n" . '+++ ' . $ patchFile . "\n" . $ patch ; return true ; }
Handle the patching cycle for a extractor .
26,306
private function determineSuperfluous ( $ mentionedAuthors , $ wantedAuthors , $ path ) { $ superfluous = [ ] ; foreach ( \ array_diff_key ( $ mentionedAuthors , $ wantedAuthors ) as $ key => $ author ) { if ( ! $ this -> config -> isCopyLeftAuthor ( $ author , $ path ) ) { $ superfluous [ $ key ] = $ author ; } } return $ superfluous ; }
Determine the superfluous authors from the passed arrays .
26,307
private function comparePath ( AuthorExtractor $ current , AuthorExtractor $ should , ProgressBar $ progressBar , $ path ) { $ validates = true ; $ mentionedAuthors = $ current -> extractAuthorsFor ( $ path ) ; $ multipleAuthors = $ current -> extractMultipleAuthorsFor ( $ path ) ; $ wantedAuthors = array_merge ( $ should -> extractAuthorsFor ( $ path ) , $ this -> config -> getCopyLeftAuthors ( $ path ) ) ; if ( $ mentionedAuthors === null ) { if ( $ this -> output -> getVerbosity ( ) >= OutputInterface :: VERBOSITY_VERBOSE ) { $ this -> output -> writeln ( \ sprintf ( 'Skipped check of <info>%s</info> as it is not present.' , $ path ) ) ; } if ( $ this -> useProgressBar ) { $ progressBar -> advance ( 1 ) ; $ progressBar -> setMessage ( 'Author validation is in progress...' ) ; } return true ; } $ superfluousMentions = $ this -> determineSuperfluous ( $ mentionedAuthors , $ wantedAuthors , $ path ) ; $ missingMentions = \ array_diff_key ( $ wantedAuthors , $ mentionedAuthors ) ; if ( \ count ( $ superfluousMentions ) ) { $ this -> output -> writeln ( \ sprintf ( PHP_EOL . PHP_EOL . 'The file <info>%s</info> is mentioning superfluous author(s):' . PHP_EOL . '<comment>%s</comment>' . PHP_EOL , $ path , \ implode ( PHP_EOL , $ superfluousMentions ) ) ) ; $ validates = false ; } if ( \ count ( $ missingMentions ) ) { $ this -> output -> writeln ( \ sprintf ( PHP_EOL . PHP_EOL . 'The file <info>%s</info> is not mentioning its author(s):' . PHP_EOL . '<comment>%s</comment>' . PHP_EOL , $ path , \ implode ( PHP_EOL , $ missingMentions ) ) ) ; $ validates = false ; } if ( \ count ( $ multipleAuthors ) ) { $ this -> output -> writeln ( \ sprintf ( PHP_EOL . PHP_EOL . 'The file <info>%s</info> multiple author(s):' . PHP_EOL . '<comment>%s</comment>' . PHP_EOL , $ path , \ implode ( PHP_EOL , $ multipleAuthors ) ) ) ; $ validates = false ; } if ( ! $ validates ) { $ this -> patchExtractor ( $ path , $ current , $ wantedAuthors ) ; } if ( $ this -> useProgressBar ) { $ progressBar -> advance ( 1 ) ; $ progressBar -> setMessage ( 'Author validation is in progress...' ) ; } return $ validates ; }
Run comparison for a given path .
26,308
public function compare ( AuthorExtractor $ current , AuthorExtractor $ should ) { $ shouldPaths = $ should -> getFilePaths ( ) ; $ currentPaths = $ current -> getFilePaths ( ) ; $ allPaths = \ array_intersect ( $ shouldPaths , $ currentPaths ) ; $ validates = true ; $ progressBar = new ProgressBar ( $ this -> output , \ count ( $ allPaths ) ) ; if ( $ this -> useProgressBar ) { $ progressBar -> start ( ) ; $ progressBar -> setMessage ( 'Start author validation.' ) ; $ progressBar -> setFormat ( '%current%/%max% [%bar%] %message% %elapsed:6s%' ) ; } foreach ( $ allPaths as $ pathname ) { $ validates = $ this -> comparePath ( $ current , $ should , $ progressBar , $ pathname ) && $ validates ; } if ( $ this -> useProgressBar ) { $ progressBar -> setMessage ( 'Finished author validation.' ) ; $ progressBar -> finish ( ) ; $ this -> output -> writeln ( PHP_EOL ) ; } return $ validates ; }
Compare two author lists against each other .
26,309
protected function getObjectDataManager ( Request $ request ) { $ objectDataManager = $ this -> container -> get ( ObjectDataManager :: class ) ; $ resolver = new OptionsResolver ( ) ; $ resolver -> setDefaults ( [ "folder" => null , ] ) ; $ resolver -> setRequired ( [ "returnUrl" , "objectId" , "objectType" ] ) ; $ config = $ resolver -> resolve ( $ request -> get ( "_conf" ) ) ; $ objectDataManager -> configure ( $ config [ "objectId" ] , $ config [ "objectType" ] ) ; $ objectDataManager -> documents ( ) -> folder ( $ config [ "folder" ] ) ; $ this -> config = $ config ; return $ objectDataManager ; }
Obtiene y configura desde el request el ObjectDataManager
26,310
protected function setPlatformOptions ( InputInterface $ input , OutputInterface $ output ) { $ platform = ProjectX :: getPlatformType ( ) ; if ( ! $ platform instanceof NullPlatformType && $ platform instanceof OptionFormAwareInterface ) { $ classname = get_class ( $ platform ) ; $ command_io = new SymfonyStyle ( $ input , $ output ) ; $ command_io -> newLine ( 2 ) ; $ command_io -> title ( sprintf ( '%s Platform Options' , $ classname :: getLabel ( ) ) ) ; $ form = $ platform -> optionForm ( ) ; $ form -> setInput ( $ input ) -> setOutput ( $ output ) -> setHelperSet ( $ this -> getHelperSet ( ) ) -> process ( ) ; $ this -> options [ $ classname :: getTypeId ( ) ] = $ form -> getResults ( ) ; } return $ this ; }
Set project platform options .
26,311
protected function setProjectOptions ( InputInterface $ input , OutputInterface $ output ) { $ project = ProjectX :: getProjectType ( ) ; if ( $ project instanceof OptionFormAwareInterface ) { $ classname = get_class ( $ project ) ; $ command_io = new SymfonyStyle ( $ input , $ output ) ; $ command_io -> newLine ( 2 ) ; $ command_io -> title ( sprintf ( '%s Project Options' , $ classname :: getLabel ( ) ) ) ; $ form = $ project -> optionForm ( ) ; $ form -> setInput ( $ input ) -> setOutput ( $ output ) -> setHelperSet ( $ this -> getHelperSet ( ) ) -> process ( ) ; $ this -> options [ $ classname :: getTypeId ( ) ] = $ form -> getResults ( ) ; } return $ this ; }
Set project options .
26,312
protected function setDeployOptions ( InputInterface $ input , OutputInterface $ output ) { $ project = ProjectX :: getProjectType ( ) ; if ( $ project instanceof DeployAwareInterface ) { $ command_io = new SymfonyStyle ( $ input , $ output ) ; $ command_io -> title ( 'Deploy Build Options' ) ; $ form = ( new Form ( ) ) -> setInput ( $ input ) -> setOutput ( $ output ) -> setHelperSet ( $ this -> getHelperSet ( ) ) -> addFields ( [ ( new BooleanField ( 'deploy' , 'Setup build deploy?' ) ) -> setDefault ( false ) -> setSubform ( function ( $ subform , $ value ) { if ( true === $ value ) { $ subform -> addFields ( [ ( new TextField ( 'repo_url' , 'Repository URL' ) ) , ] ) ; } } ) ] ) -> process ( ) ; $ results = $ form -> getResults ( ) ; if ( isset ( $ results [ 'deploy' ] ) && ! empty ( $ results [ 'deploy' ] ) ) { $ this -> options [ 'deploy' ] = $ results [ 'deploy' ] ; } } return $ this ; }
Set project deployment options .
26,313
protected function setEngineServiceOptions ( ) { $ project = ProjectX :: getProjectType ( ) ; if ( $ project instanceof EngineServiceInterface ) { $ engine = ProjectX :: getEngineType ( ) ; $ classname = get_class ( $ engine ) ; $ this -> options [ $ classname :: getTypeId ( ) ] = [ 'services' => $ project -> defaultServices ( ) ] ; } return $ this ; }
Set the project engine services options .
26,314
static public function generate ( ) { if ( ! extension_loaded ( 'openssl' ) ) { throw new \ RuntimeException ( "Can only generate a remote desktop certificate when OpenSSL PHP extension is installed." ) ; } $ config = array ( 'config' => __DIR__ . '/../Resources/config/openssl.cnf' ) ; $ privkey = openssl_pkey_new ( $ config ) ; $ dn = array ( "commonName" => "AzureDistributionBundle for Symfony Tools" ) ; $ csr = openssl_csr_new ( $ dn , $ privkey , $ config ) ; $ sscert = openssl_csr_sign ( $ csr , null , $ privkey , 365 , $ config ) ; return new self ( $ privkey , $ sscert ) ; }
Generate a pkcs12 file and private key to use with remote desktoping .
26,315
public function export ( $ directory , $ filePrefix , $ keyPassword , $ overwrite = false ) { if ( ! is_writeable ( $ directory ) ) { throw new \ RuntimeException ( "Key Export directory is not writable: " . $ directory ) ; } $ pkcs12File = $ directory . "/" . $ filePrefix . ".pfx" ; $ x509File = $ directory . "/" . $ filePrefix . ".cer" ; if ( ! $ overwrite && file_exists ( $ pkcs12File ) ) { throw new \ RuntimeException ( "PKCS12 File at " . $ pkcs12File . " already exists and is not overwritten." ) ; } if ( ! $ overwrite && file_exists ( $ x509File ) ) { throw new \ RuntimeException ( "X509 Certificate File at " . $ x509File . " already exists and is not overwritten." ) ; } $ args = array ( 'friendly_name' => 'AzureDistributionBundle for Symfony Tools' ) ; openssl_pkcs12_export_to_file ( $ this -> certificate , $ pkcs12File , $ this -> privKey , $ keyPassword , $ args ) ; openssl_x509_export_to_file ( $ this -> certificate , $ x509File , true ) ; return $ x509File ; }
Given this Remote Desktop instance generate files with pkcs12 and x509 certificate to a given directory using a password for the desktop and the private key .
26,316
public function encryptAccountPassword ( $ x509File , $ desktopPassword ) { $ directory = sys_get_temp_dir ( ) ; $ filePrefix = "azure" ; $ pkcs7In = $ directory . "/" . $ filePrefix . "_in.pkcs7" ; $ pkcs7Out = $ directory . "/" . $ filePrefix . "_out.pkcs7" ; $ certificate = openssl_x509_read ( file_get_contents ( $ x509File ) ) ; file_put_contents ( $ pkcs7In , $ desktopPassword ) ; $ ret = openssl_pkcs7_encrypt ( $ pkcs7In , $ pkcs7Out , $ certificate , array ( ) ) ; if ( ! $ ret ) { throw new \ RuntimeException ( "Encrypting Password failed." ) ; } $ parts = explode ( "\n\n" , file_get_contents ( $ pkcs7Out ) ) ; $ body = str_replace ( "\n" , "" , $ parts [ 1 ] ) ; unlink ( $ pkcs7In ) ; unlink ( $ pkcs7Out ) ; return $ body ; }
Encrypt Account Password
26,317
public function getThumbprint ( ) { $ resource = openssl_x509_read ( $ this -> certificate ) ; $ thumbprint = null ; $ output = null ; $ result = openssl_x509_export ( $ resource , $ output ) ; if ( $ result !== false ) { $ output = str_replace ( '-----BEGIN CERTIFICATE-----' , '' , $ output ) ; $ output = str_replace ( '-----END CERTIFICATE-----' , '' , $ output ) ; $ output = base64_decode ( $ output ) ; $ thumbprint = sha1 ( $ output ) ; } return $ thumbprint ; }
Generate SHA1 THumbprint of the X509 Certificate
26,318
public function build ( ) : string { $ path = collect ( [ $ this -> prepends , $ this -> resourceKey , $ this -> id , $ this -> appends , ] ) -> filter ( ) -> implode ( '/' ) ; $ uri = "{$path}.{$this->format}" ; return $ this -> hasParams ( ) ? $ uri . '?' . http_build_query ( $ this -> params ) : $ uri ; }
Build the path .
26,319
public function format ( string $ format ) : self { if ( ! in_array ( $ format , self :: VALID_FORMATS ) ) { throw new Exception ( 'Invalid format provided to path.' ) ; } $ this -> format = $ format ; return $ this ; }
Set the return format .
26,320
public function buildTab ( ) { $ tab = $ this -> tab ; $ tab -> setParameters ( $ this -> parametersToView ) ; $ this -> tab = null ; $ this -> parametersToView = [ ] ; return $ tab ; }
Retorna la tab listas
26,321
public function convert ( $ currency ) { if ( $ this -> isAvailable ( $ currency ) ) { $ rate = 1 / $ this -> rates [ $ currency ] ; return round ( $ this -> base * $ rate , 2 ) ; } else { throw new RuntimeException ( sprintf ( 'Target currency "%s" does not belong to the registered map of rates' , $ currency ) ) ; } }
Returns converted value
26,322
public function getSign ( ) { foreach ( $ this -> getMap ( ) as $ name => $ method ) { if ( call_user_func ( array ( $ this , $ method ) ) ) { return $ name ; } } return false ; }
Gets a zodiacal sign based on a month and a day
26,323
private function isValidMonth ( $ month ) { $ list = array ( self :: MONTH_JANUARY , self :: MONTH_FEBRUARY , self :: MONTH_MARCH , self :: MONTH_APRIL , self :: MONTH_MAY , self :: MONTH_JUNE , self :: MONTH_JULY , self :: MONTH_AUGUST , self :: MONTH_SEPTEMBER , self :: MONTH_OCTOBER , self :: MONTH_NOVEMBER , self :: MONTH_DECEMBER ) ; return in_array ( $ month , $ list ) ; }
Checks whether month is supported
26,324
public function isAries ( ) { return ( $ this -> month === self :: MONTH_MARCH ) && ( $ this -> day >= 21 ) && ( $ this -> day <= 31 ) || ( $ this -> month === self :: MONTH_APRIL ) && ( $ this -> day <= 20 ) ; }
Checks whether the sign is Aries
26,325
public function isTaurus ( ) { return ( $ this -> month === self :: MONTH_APRIL ) && ( $ this -> day >= 21 ) && ( $ this -> day <= 30 ) || ( $ this -> month === self :: MONTH_MAY ) && ( $ this -> day <= 21 ) ; }
Checks whether the sign is Taurus
26,326
public function isGemini ( ) { return ( $ this -> month === self :: MONTH_MAY ) && ( $ this -> day >= 22 ) && ( $ this -> day <= 31 ) || ( $ this -> month === self :: MONTH_JULY ) && ( $ this -> day <= 21 ) ; }
Checks whether the sign is Gemini
26,327
public function isCancer ( ) { return ( $ this -> month === self :: MONTH_JUNE ) && ( $ this -> day >= 22 ) && ( $ this -> day <= 30 ) || ( $ this -> month === self :: MONTH_JULY ) && ( $ this -> day <= 22 ) ; }
Checks whether the sign is Cancer
26,328
public function isLeo ( ) { return ( $ this -> month === self :: MONTH_JULY ) && ( $ this -> day >= 23 ) && ( $ this -> day <= 30 ) || ( $ this -> month === self :: MONTH_MAY ) && ( $ this -> day <= 22 ) ; }
Checks whether the sign is Leo
26,329
public function isVirgo ( ) { return ( $ this -> month === self :: MONTH_AUGUST ) && ( $ this -> day >= 23 ) && ( $ this -> day <= 30 ) || ( $ this -> month === self :: MONTH_SEPTEMBER ) && ( $ this -> day <= 23 ) ; }
Checks whether the sign is Virgo
26,330
public function isScorpio ( ) { return ( $ this -> month === self :: MONTH_OCTOBER ) && ( $ this -> day >= 24 ) && ( $ this -> day <= 30 ) || ( $ this -> month === self :: MONTH_NOVEMBER ) && ( $ this -> day <= 22 ) ; }
Checks whether the sign is Scorpio
26,331
public function isLibra ( ) { return ( $ this -> month === self :: MONTH_SEPTEMBER ) && ( $ this -> day >= 24 ) && ( $ this -> day <= 30 ) || ( $ this -> month === self :: MONTH_OCTOBER ) && ( $ this -> day <= 23 ) ; }
Checks whether the sign is Libra
26,332
public function isSagittarius ( ) { return ( $ this -> month === self :: MONTH_NOVEMBER ) && ( $ this -> day >= 23 ) && ( $ this -> day <= 30 ) || ( $ this -> month === self :: MONTH_DECEMBER ) && ( $ this -> day <= 21 ) ; }
Checks whether the sign is Sagittarius
26,333
public function isCapricorn ( ) { return ( $ this -> month === self :: MONTH_DECEMBER ) && ( $ this -> day >= 22 ) && ( $ this -> day <= 30 ) || ( $ this -> month === self :: MONTH_JANUARY ) && ( $ this -> day <= 20 ) ; }
Checks whether the sign is Capricorn
26,334
public function isAquarius ( ) { return ( $ this -> month === self :: MONTH_JANUARY ) && ( $ this -> day >= 21 ) && ( $ this -> day <= 30 ) || ( $ this -> month === self :: MONTH_FEBRUARY ) && ( $ this -> day <= 19 ) ; }
Checks whether the sign is Aquarius
26,335
public function isPisces ( ) { return ( $ this -> month === self :: MONTH_FEBRUARY ) && ( $ this -> day >= 20 ) && ( $ this -> day <= 30 ) || ( $ this -> month === self :: MONTH_MARCH ) && ( $ this -> day <= 20 ) ; }
Checks whether the sign is Pisces
26,336
public function embed ( string $ filePath ) : string { $ id = $ this -> getAttachmentId ( $ filePath ) ; $ this -> embeddedAttachments [ $ id ] = $ filePath ; return $ id ; }
Embed the given file into this message .
26,337
public function drupalInstall ( $ opts = [ 'db-name' => null , 'db-user' => null , 'db-pass' => null , 'db-host' => null , 'db-port' => null , 'db-protocol' => null , 'localhost' => false , ] ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ database = $ this -> buildDatabase ( $ opts ) ; $ this -> getProjectInstance ( ) -> setDatabaseOverride ( $ database ) -> setupDrupalInstall ( $ opts [ 'localhost' ] ) ; $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; return $ this ; }
Install Drupal on the current environment .
26,338
public function drupalLocalSetup ( $ opts = [ 'db-name' => null , 'db-user' => null , 'db-pass' => null , 'db-host' => null , 'db-port' => null , 'db-protocol' => null , 'no-engine' => false , 'no-browser' => false , 'restore-method' => null , 'localhost' => false , ] ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ database = $ this -> buildDatabase ( $ opts ) ; $ this -> getProjectInstance ( ) -> setDatabaseOverride ( $ database ) -> setupExistingProject ( $ opts [ 'no-engine' ] , $ opts [ 'restore-method' ] , $ opts [ 'no-browser' ] , $ opts [ 'localhost' ] ) ; $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; return $ this ; }
Setup local environment for already built projects .
26,339
public function drupalLetmein ( $ opts = [ 'user' => null , 'path' => null ] ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ instance = $ this -> getProjectInstance ( ) ; $ instance -> createDrupalLoginLink ( $ opts [ 'user' ] , $ opts [ 'path' ] ) ; $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; }
Takeover a Drupal users account .
26,340
public function drupalDrush ( array $ drush_command , $ opts = [ 'silent' => false , 'localhost' => false , ] ) { $ instance = $ this -> getProjectInstance ( ) ; return $ instance -> runDrushCommand ( implode ( ' ' , $ drush_command ) , $ opts [ 'silent' ] , $ opts [ 'localhost' ] ) ; }
Execute arbitrary drush command .
26,341
public function drupalLocalSync ( ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ instance = $ this -> getProjectInstance ( ) ; if ( $ instance -> getProjectVersion ( ) >= 8 ) { $ drush = new DrushCommand ( ) ; $ local_alias = $ this -> determineDrushLocalAlias ( ) ; $ remote_alias = $ this -> determineDrushRemoteAlias ( ) ; if ( isset ( $ local_alias ) && isset ( $ remote_alias ) ) { $ skip_tables = implode ( ',' , [ 'cache_bootstrap' , 'cache_config' , 'cache_container' , 'cache_data' , 'cache_default' , 'cache_discovery' , 'cache_dynamic_page_cache' , 'cache_entity' , 'cache_menu' , 'cache_render' , 'history' , 'search_index' , 'sessions' , 'watchdog' ] ) ; $ drush -> command ( "sql-sync --sanitize --skip-tables-key='$skip_tables' '@$remote_alias' '@$local_alias'" , true ) ; } $ drush -> command ( 'cim' ) -> command ( 'updb --entity-updates' ) -> command ( 'cr' ) ; $ instance -> runDrushCommand ( $ drush ) ; } $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; return $ this ; }
Refresh the local environment with remote data and configuration changes .
26,342
public function drupalRefresh ( $ opts = [ 'db-name' => null , 'db-user' => null , 'db-pass' => null , 'db-host' => null , 'db-port' => null , 'db-protocol' => null , 'hard' => false , 'localhost' => false , ] ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ localhost = $ opts [ 'localhost' ] ; $ instance = $ this -> getProjectInstance ( ) ; $ version = $ instance -> getProjectVersion ( ) ; $ this -> taskComposerInstall ( ) -> run ( ) ; if ( $ opts [ 'hard' ] ) { $ database = $ this -> buildDatabase ( $ opts ) ; $ instance -> setDatabaseOverride ( $ database ) -> setupDrupalInstall ( $ localhost ) ; if ( $ version >= 8 ) { $ instance -> setDrupalUuid ( $ localhost ) ; } } $ drush = new DrushCommand ( null , $ localhost ) ; if ( $ version >= 8 ) { $ instance -> runDrushCommand ( 'updb --entity-updates' , false , $ localhost ) ; $ instance -> importDrupalConfig ( 1 , $ localhost ) ; $ drush -> command ( 'cr' ) ; } else { $ drush -> command ( 'updb' ) -> command ( 'cc all' ) ; } $ instance -> runDrushCommand ( $ drush , false , $ localhost ) ; $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; return $ this ; }
Refresh the local Drupal instance .
26,343
public function drupalDrushAlias ( $ opts = [ 'exclude-remote' => false ] ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ instance = $ this -> getProjectInstance ( ) ; $ instance -> setupDrushAlias ( $ opts [ 'exclude-remote' ] ) ; $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; return $ this ; }
Setup local project drush alias .
26,344
protected function buildDatabase ( array $ options ) { return ( new Database ( ) ) -> setPort ( $ options [ 'db-port' ] ) -> setUser ( $ options [ 'db-user' ] ) -> setPassword ( $ options [ 'db-pass' ] ) -> setDatabase ( $ options [ 'db-name' ] ) -> setHostname ( $ options [ 'db-host' ] ) -> setProtocol ( $ options [ 'db-protocol' ] ) ; }
Build database object based on options .
26,345
protected function getDrushAliasKeys ( $ realm ) { $ aliases = $ this -> loadDrushAliasesByRelam ( $ realm ) ; $ alias_keys = array_keys ( $ aliases ) ; array_walk ( $ alias_keys , function ( & $ key ) use ( $ realm ) { $ key = "$realm.$key" ; } ) ; return $ alias_keys ; }
Get Drush alias keys .
26,346
protected function determineDrushAlias ( $ realm , array $ options ) { if ( count ( $ options ) > 1 ) { return $ this -> askChoiceQuestion ( sprintf ( 'Select the %s drush alias that should be used:' , $ realm ) , $ options , 0 ) ; } return reset ( $ options ) ? : null ; }
Determine what Drush alias to use ask if more then one option .
26,347
protected function loadDrushAliasesByRelam ( $ realm ) { static $ cached = [ ] ; if ( empty ( $ cached [ $ realm ] ) ) { $ project_root = ProjectX :: projectRoot ( ) ; if ( ! file_exists ( "$project_root/drush" ) ) { return [ ] ; } $ drush_alias_dir = "$project_root/drush/site-aliases" ; if ( ! file_exists ( $ drush_alias_dir ) ) { return [ ] ; } if ( ! file_exists ( "$drush_alias_dir/$realm.aliases.drushrc.php" ) ) { return [ ] ; } include_once "$drush_alias_dir/$realm.aliases.drushrc.php" ; $ cached [ $ realm ] = isset ( $ aliases ) ? $ aliases : array ( ) ; } return $ cached [ $ realm ] ; }
Load Drush local aliases .
26,348
protected function dumpLemmas ( array $ lemmas ) { $ content = var_export ( $ lemmas , true ) ; $ content = $ this -> decodeKey ( $ content ) ; return $ this -> dumpLangArray ( "<?php\n\nreturn {$content};" ) ; }
Dump the final lemmas into a string for storing in a PHP file .
26,349
protected function saveChanges ( ) { $ this -> line ( '' ) ; if ( count ( $ this -> jobs ) > 0 ) { $ do = true ; if ( $ this -> config ( 'ask_for_value' ) === false ) { $ do = ( $ this -> ask ( 'Do you wish to apply these changes now? [yes|no]' ) === 'yes' ) ; } if ( $ do === true ) { $ this -> line ( '' ) ; $ this -> line ( 'Save files:' ) ; foreach ( $ this -> jobs as $ file_lang_path => $ file_content ) { file_put_contents ( $ file_lang_path , $ file_content ) ; $ this -> line ( " <info>" . $ this -> getShortPath ( $ file_lang_path ) ) ; } $ this -> line ( '' ) ; $ this -> info ( 'Process done!' ) ; } else { $ this -> comment ( 'Process aborted. No file have been changed.' ) ; } } else { if ( $ this -> has_new && ( $ this -> is_dirty === true || $ this -> option ( 'force' ) ) === false ) { $ this -> comment ( 'Not all translations are up to date.' ) ; } else { $ this -> info ( 'All translations are up to date.' ) ; } } $ this -> line ( '' ) ; }
Save all changes made to the lemmas .
26,350
protected function processObsoleteLemmas ( $ family , array $ old_lemmas = [ ] , array $ new_lemmas = [ ] ) { $ lemmas = array_diff_key ( $ old_lemmas , $ new_lemmas ) ; if ( count ( $ lemmas ) > 0 ) { ksort ( $ lemmas ) ; foreach ( $ lemmas as $ key => $ value ) { $ id = $ this -> decodeKey ( $ key ) ; if ( $ this -> neverObsolete ( $ id ) ) { Arr :: set ( $ this -> final_lemmas , $ key , str_replace ( '%LEMMA' , $ value , $ this -> option ( 'new-value' ) ) ) ; unset ( $ lemmas [ $ key ] ) ; } } } if ( count ( $ lemmas ) > 0 ) { $ this -> is_dirty = true ; $ this -> comment ( " " . count ( $ lemmas ) . " obsolete strings (will be deleted)" ) ; if ( $ this -> option ( 'verbose' ) ) { foreach ( $ lemmas as $ key => $ value ) { $ this -> line ( " <comment>" . $ this -> decodeKey ( $ key ) . "</comment>" ) ; } } } }
Process obsolete lemmas .
26,351
protected function processExistingLemmas ( $ family , array $ old_lemmas = [ ] , array $ new_lemmas = [ ] ) { $ lemmas = array_intersect_key ( $ old_lemmas , $ new_lemmas ) ; if ( count ( $ lemmas ) > 0 ) { ksort ( $ lemmas ) ; if ( $ this -> option ( 'verbose' ) ) { $ this -> line ( " " . count ( $ lemmas ) . " already translated strings" ) ; } foreach ( $ lemmas as $ key => $ value ) { Arr :: set ( $ this -> final_lemmas , $ key , $ value ) ; } return true ; } return false ; }
Process existing lemmas .
26,352
protected function processNewLemmas ( $ family , array $ new_lemmas = [ ] , array $ old_lemmas = [ ] ) { $ lemmas = array_diff_key ( $ new_lemmas , $ old_lemmas ) ; if ( $ this -> config ( 'ask_for_value' ) === false ) { $ lemmas = array_filter ( $ lemmas , function ( $ key ) { if ( $ this -> neverObsolete ( $ key ) ) { $ this -> line ( " <comment>Manually add:</comment> <info>{$key}</info>" ) ; $ this -> has_new = true ; return false ; } return true ; } , ARRAY_FILTER_USE_KEY ) ; } if ( count ( $ lemmas ) > 0 ) { $ this -> is_dirty = true ; $ this -> has_new = true ; ksort ( $ lemmas ) ; $ this -> info ( " " . count ( $ lemmas ) . " new strings to translate" ) ; foreach ( $ lemmas as $ key => $ path ) { $ value = $ this -> decodeKey ( $ key ) ; if ( $ this -> option ( 'dirty' ) === false && $ this -> config ( 'ask_for_value' ) === true ) { $ value = $ this -> ask ( "{$family}.{$value}" , $ this -> createSuggestion ( $ value ) ) ; } if ( $ this -> option ( 'verbose' ) ) { $ this -> line ( " <info>{$key}</info> in " . $ this -> getShortPath ( $ path ) ) ; } Arr :: set ( $ this -> final_lemmas , $ key , str_replace ( '%LEMMA' , $ value , $ this -> option ( 'new-value' ) ) ) ; } return true ; } return false ; }
Process new lemmas .
26,353
protected function getLanguages ( array $ paths = [ ] ) { $ dir_lang = $ this -> getLangPath ( ) ; if ( $ this -> config ( 'default_locale_only' ) ) { return [ $ this -> default_locale => "{$dir_lang}/{$this->default_locale}" , ] ; } foreach ( glob ( "{$dir_lang}/*" , GLOB_ONLYDIR ) as $ path ) { $ paths [ basename ( $ path ) ] = $ path ; } return $ paths ; }
Get all languages and their s paths .
26,354
protected function createSuggestion ( $ value ) { if ( empty ( $ this -> obsolete_regex ) === false ) { $ value = preg_replace ( "/^({$this->obsolete_regex})\./i" , '' , $ value ) ; } return Str :: title ( str_replace ( '_' , ' ' , $ value ) ) ; }
Create a key value suggestion .
26,355
protected function neverObsolete ( $ value ) { foreach ( $ this -> config ( 'never_obsolete_keys' , [ ] ) as $ remove ) { $ remove = "{$remove}." ; if ( substr ( $ value , 0 , strlen ( $ remove ) ) === $ remove || strpos ( $ value , ".{$remove}" ) !== false ) { return true ; } } return false ; }
Check key to ensure it isn t a never obsolete key .
26,356
protected function getLemmasStructured ( array $ structured = [ ] ) { foreach ( $ this -> getLemmas ( ) as $ key => $ value ) { $ family = substr ( $ key , 0 , strpos ( $ key , '.' ) ) ; if ( in_array ( $ family , $ this -> config ( 'ignore_lang_files' , [ ] ) ) ) { if ( $ this -> option ( 'verbose' ) ) { $ this -> line ( '' ) ; $ this -> info ( " ! Skip lang file '{$family}' !" ) ; } continue ; } if ( strpos ( $ key , '.' ) === false ) { $ this -> line ( ' <error>' . $ key . '</error> in file <comment>' . $ this -> getShortPath ( $ value ) . '</comment> <error>will not be included because it has no parent</error>' ) ; } else { Arr :: set ( $ structured , $ this -> encodeKey ( $ key ) , $ value ) ; } } return $ structured ; }
Convert dot lemmas to structured lemmas .
26,357
protected function getLemmas ( array $ lemmas = [ ] ) { $ folders = $ this -> getPath ( $ this -> config ( 'folders' , [ ] ) ) ; foreach ( $ folders as $ path ) { if ( $ this -> option ( 'verbose' ) ) { $ this -> line ( ' <info>' . $ path . '</info>' ) ; } foreach ( $ this -> getPhpFiles ( $ path ) as $ php_file_path => $ dumb ) { $ lemma = [ ] ; foreach ( $ this -> extractTranslationFromFile ( $ php_file_path ) as $ k => $ v ) { $ real_value = eval ( "return $k;" ) ; $ lemma [ $ real_value ] = $ php_file_path ; } $ lemmas = array_merge ( $ lemmas , $ lemma ) ; } } if ( count ( $ lemmas ) === 0 ) { $ this -> comment ( "No lemma have been found in the code." ) ; $ this -> line ( "In these directories:" ) ; foreach ( $ this -> config ( 'folders' , [ ] ) as $ path ) { $ path = $ this -> getPath ( $ path ) ; $ this -> line ( " {$path}" ) ; } $ this -> line ( "For these functions/methods:" ) ; foreach ( $ this -> config ( 'trans_methods' , [ ] ) as $ k => $ v ) { $ this -> line ( " {$k}" ) ; } die ( ) ; } $ this -> line ( ( count ( $ lemmas ) > 1 ) ? count ( $ lemmas ) . " lemmas have been found in the code" : "1 lemma has been found in the code" ) ; if ( $ this -> option ( 'verbose' ) ) { foreach ( $ lemmas as $ key => $ value ) { if ( strpos ( $ key , '.' ) !== false ) { $ this -> line ( ' <info>' . $ key . '</info> in file <comment>' . $ this -> getShortPath ( $ value ) . '</comment>' ) ; } } } return $ lemmas ; }
Get the lemmas values from the provided directories .
26,358
protected function getOldLemmas ( $ file_lang_path , array $ values = [ ] ) { if ( ! is_writable ( dirname ( $ file_lang_path ) ) ) { $ this -> error ( " > Unable to write file in directory " . dirname ( $ file_lang_path ) ) ; die ( ) ; } if ( ! file_exists ( $ file_lang_path ) ) { $ this -> info ( " > File has been created" ) ; } if ( ! touch ( $ file_lang_path ) ) { $ this -> error ( " > Unable to touch file {$file_lang_path}" ) ; die ( ) ; } if ( ! is_readable ( $ file_lang_path ) ) { $ this -> error ( " > Unable to read file {$file_lang_path}" ) ; die ( ) ; } if ( ! is_writable ( $ file_lang_path ) ) { $ this -> error ( " > Unable to write in file {$file_lang_path}" ) ; die ( ) ; } $ lang = include ( $ file_lang_path ) ; $ lang = is_array ( $ lang ) ? Arr :: dot ( $ lang ) : [ ] ; foreach ( $ lang as $ key => $ value ) { $ values [ $ this -> encodeKey ( $ key ) ] = $ value ; } return $ values ; }
Get the old lemmas values .
26,359
public static function build ( $ pdo , $ table ) { $ mapper = new CacheMapper ( new NativeSerializer ( ) , $ pdo , $ table ) ; return new SqlCacheEngine ( $ mapper ) ; }
Builds cache engine
26,360
public function canCreate ( $ member = null ) { if ( ! $ member ) { $ member = Member :: currentUser ( ) ; } $ extended = $ this -> extendedCan ( 'canCreate' , $ member ) ; if ( $ extended !== null ) { return $ extended ; } if ( $ member ) { return true ; } else { return false ; } }
Anyone logged in can create
26,361
public function login ( $ username , $ password ) { if ( @ ftp_login ( $ this -> stream , $ username , $ password ) ) { $ this -> loggedIn = true ; return true ; } else { return false ; } }
Logins using username and password
26,362
public function text ( $ text , $ fontFile , $ size , array $ rgb = array ( 0 , 0 , 0 ) , $ corner = self :: IMG_CENTER_CORNER , $ offsetX = 0 , $ offsetY = 0 , $ angle = 0 ) { $ box = imagettfbbox ( $ size , $ angle , $ fontFile , $ text ) ; $ height = $ box [ 1 ] - $ box [ 7 ] ; $ width = $ box [ 2 ] - $ box [ 0 ] ; switch ( $ corner ) { case self :: IMG_CENTER_CORNER : $ x = floor ( ( $ this -> width - $ width ) / 2 ) ; $ y = floor ( ( $ this -> height - $ height ) / 2 ) ; break ; case self :: IMG_LEFT_TOP_CORNER : $ x = $ offsetX ; $ y = $ offsetY ; break ; case self :: IMG_RIGHT_TOP_CORNER : $ x = $ this -> width - $ width - $ offsetX ; $ y = $ offsetY ; break ; case self :: IMG_LEFT_BOTTOM_CORNER : $ x = $ offsetX ; $ y = $ this -> height - $ height - $ offsetY ; break ; case self :: IMG_RIGHT_BOTTOM_CORNER : $ x = $ this -> width - $ width - $ offsetX ; $ y = $ this -> height - $ height - $ offsetY ; break ; default : throw new UnexpectedValueException ( 'unsupported corner value supplied' ) ; } $ color = imagecolorallocate ( $ this -> image , $ rgb [ 0 ] , $ rgb [ 1 ] , $ rgb [ 2 ] ) ; imagettftext ( $ this -> image , $ size , $ angle , $ x , $ y + $ height , $ color , $ fontFile , $ text ) ; return $ this ; }
Adds a text on image
26,363
public function flip ( $ type ) { $ x = 0 ; $ y = 0 ; $ width = $ this -> width ; $ height = $ this -> height ; switch ( $ type ) { case self :: IMG_FLIP_BOTH : $ x = $ this -> width - 1 ; $ y = $ this -> height - 1 ; $ width = - $ this -> width ; $ height = - $ this -> height ; break ; case self :: IMG_FLIP_HORIZONTAL : $ x = $ this -> width - 1 ; $ width = - $ this -> width ; break ; case self :: IMG_FLIP_VERTICAL : $ y = $ this -> height - 1 ; $ height = - $ this -> height ; break ; default : throw new UnexpectedValueException ( "Invalid flip type's value supplied" ) ; } $ image = imagecreatetruecolor ( $ this -> width , $ this -> height ) ; $ this -> preserveTransparency ( $ image ) ; imagecopyresampled ( $ image , $ this -> image , 0 , 0 , $ x , $ y , $ this -> width , $ this -> height , $ width , $ height ) ; $ this -> setImage ( $ image ) ; return $ this ; }
Flips the image
26,364
public function watermark ( $ watermarkFile , $ corner = self :: IMG_RIGHT_BOTTOM_CORNER , $ offsetX = 10 , $ offsetY = 10 ) { $ watermark = new ImageFile ( $ watermarkFile ) ; $ x = 0 ; $ y = 0 ; switch ( $ corner ) { case self :: IMG_RIGHT_BOTTOM_CORNER : $ x = $ this -> width - $ watermark -> getWidth ( ) - $ offsetX ; $ y = $ this -> height - $ watermark -> getHeight ( ) - $ offsetY ; break ; case self :: IMG_RIGHT_TOP : $ x = $ this -> width - $ watermark -> getWidth ( ) - $ offsetX ; $ y = $ offsetY ; break ; case self :: IMG_LEFT_CORNER : $ x = $ offsetX ; $ y = $ offsetY ; break ; case self :: IMG_LEFT_BOTTOM_CORNER : $ x = $ offsetX ; $ y = $ this -> height - $ watermark -> getHeight ( ) - $ offsetY ; break ; case self :: CORNER_CENTER : $ x = floor ( ( $ this -> width - $ watermark -> getWidth ( ) ) / 2 ) ; $ y = floor ( ( $ this -> height - $ watermark -> getHeight ( ) ) / 2 ) ; break ; default : throw new UnexpectedValueException ( sprintf ( "Unexpected corner's value provided '%s'" , $ corner ) ) ; } imagecopy ( $ this -> image , $ watermark -> getImage ( ) , $ x , $ y , 0 , 0 , $ watermark -> getWidth ( ) , $ watermark -> getHeight ( ) ) ; unset ( $ watermark ) ; return $ this ; }
Adds a watermark on current image
26,365
public function blackwhite ( ) { imagefilter ( $ this -> image , \ IMG_FILTER_GRAYSCALE ) ; imagefilter ( $ this -> image , \ IMG_FILTER_CONTRAST , - 1000 ) ; return $ this ; }
Makes black and white
26,366
public function resize ( $ x , $ y , $ proportional = true ) { if ( $ x === null || $ x > $ this -> width ) { $ x = $ this -> width ; } if ( $ y === null || $ y > $ this -> height ) { $ y = $ this -> height ; } if ( $ proportional === true ) { $ height = $ y ; $ width = round ( $ height / $ this -> height * $ this -> width ) ; if ( $ width < $ x ) { $ width = $ x ; $ height = round ( $ width / $ this -> width * $ this -> height ) ; } } else { $ width = $ x ; $ height = $ y ; } $ image = imagecreatetruecolor ( $ width , $ height ) ; $ this -> preserveTransparency ( $ image ) ; imagecopyresampled ( $ image , $ this -> image , 0 , 0 , 0 , 0 , $ width , $ height , $ this -> width , $ this -> height ) ; $ this -> setImage ( $ image ) ; $ this -> width = $ width ; $ this -> height = $ height ; return $ this ; }
Resizes the image
26,367
public function crop ( $ width , $ height , $ startX = null , $ startY = null ) { if ( $ width === null ) { $ width = $ this -> width ; } if ( $ height === null ) { $ height = $ this -> height ; } if ( $ startX === null ) { $ startX = floor ( ( $ this -> width - $ width ) / 2 ) ; } if ( $ startY === null ) { $ startY = floor ( ( $ this -> height - $ height ) / 2 ) ; } $ startX = max ( 0 , min ( $ this -> width , $ startX ) ) ; $ startY = max ( 0 , min ( $ this -> height , $ startY ) ) ; $ width = min ( $ width , $ this -> width - $ startX ) ; $ height = min ( $ height , $ this -> height - $ startY ) ; $ image = imagecreatetruecolor ( $ width , $ height ) ; $ this -> preserveTransparency ( $ image ) ; imagecopyresampled ( $ image , $ this -> image , 0 , 0 , $ startX , $ startY , $ width , $ height , $ width , $ height ) ; $ this -> setImage ( $ image ) ; $ this -> width = $ width ; $ this -> height = $ height ; return $ this ; }
Crops an image
26,368
public function thumb ( $ width , $ height ) { $ this -> resize ( $ width , $ height ) -> crop ( $ width , $ height ) ; return $ this ; }
Resizes and crops to its best fit the image
26,369
public function rotate ( $ degrees ) { $ degrees = ( int ) $ degrees ; $ this -> image = imagerotate ( $ this -> image , $ degrees , 0 ) ; $ this -> width = imagesx ( $ this -> image ) ; $ this -> height = imagesy ( $ this -> image ) ; return $ this ; }
Rotates the image
26,370
private function preserveTransparency ( $ image ) { $ transparencyColor = array ( 0 , 0 , 0 ) ; switch ( $ this -> type ) { case \ IMAGETYPE_GIF : $ color = imagecolorallocate ( $ image , $ transparencyColor [ 0 ] , $ transparencyColor [ 1 ] , $ transparencyColor [ 2 ] ) ; imagecolortransparent ( $ image , $ color ) ; imagetruecolortopalette ( $ image , false , 256 ) ; break ; case \ IMAGETYPE_PNG : imagealphablending ( $ image , false ) ; $ color = imagecolorallocatealpha ( $ image , $ transparencyColor [ 0 ] , $ transparencyColor [ 1 ] , $ transparencyColor [ 2 ] , 0 ) ; imagefill ( $ image , 0 , 0 , $ color ) ; imagesavealpha ( $ image , true ) ; break ; } }
We need this for GIFs and PNGs
26,371
public function attach ( $ event , Closure $ listener ) { if ( ! is_callable ( $ listener ) ) { throw new InvalidArgumentException ( sprintf ( 'Second argument must be callable not "%s"' , gettype ( $ listener ) ) ) ; } if ( ! is_string ( $ event ) ) { throw new InvalidArgumentException ( sprintf ( 'First argument must be string, got "%s"' , gettype ( $ event ) ) ) ; } $ this -> listeners [ $ event ] = $ listener ; return $ this ; }
Attaches a new event
26,372
public function attachMany ( array $ collection ) { foreach ( $ collection as $ event => $ listener ) { $ this -> attach ( $ event , $ listener ) ; } return $ this ; }
Attaches several events at once
26,373
public function detach ( $ event ) { if ( $ this -> has ( $ event ) ) { unset ( $ this -> listeners [ $ event ] ) ; } else { throw new RuntimeException ( sprintf ( 'Cannot detach non-existing event "%s"' , $ event ) ) ; } }
Detaches an event
26,374
public function hasMany ( array $ events ) { foreach ( $ events as $ event ) { if ( ! $ this -> has ( $ event ) ) { return false ; } } return true ; }
Checks whether event names are registered
26,375
public function envUp ( $ opts = [ 'native' => false , 'no-hostname' => false , 'no-browser' => false ] ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ engine = $ this -> engineInstance ( ) ; if ( $ engine instanceof DockerEngineType ) { if ( $ opts [ 'native' ] ) { $ engine -> disableDockerSync ( ) ; } } $ status = $ engine -> up ( ) ; if ( $ status !== false ) { $ this -> invokeEngineEvent ( 'onEngineUp' ) ; if ( ! $ opts [ 'no-hostname' ] ) { $ this -> addHostName ( $ opts [ 'no-browser' ] ) ; } } $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; return $ this ; }
Startup environment engine .
26,376
public function envRebuild ( ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ this -> engineInstance ( ) -> rebuild ( ) ; $ this -> projectInstance ( ) -> rebuildSettings ( ) ; $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; return $ this ; }
Rebuild environment engine configurations .
26,377
public function envDown ( $ opts = [ 'include-network' => false , ] ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ this -> engineInstance ( ) -> down ( $ opts [ 'include-network' ] ) ; $ this -> invokeEngineEvent ( 'onEngineDown' ) ; $ this -> removeHostName ( ) ; $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; return $ this ; }
Shutdown environment engine .
26,378
public function envResume ( ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ this -> engineInstance ( ) -> start ( ) ; $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; return $ this ; }
Resume environment engine .
26,379
public function envRestart ( ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ this -> engineInstance ( ) -> restart ( ) ; $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; return $ this ; }
Restart environment engine .
26,380
public function envReboot ( $ opts = [ 'include-network' => false , ] ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ this -> engineInstance ( ) -> reboot ( $ opts [ 'include-network' ] ) ; $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; return $ this ; }
Reboot environment engine .
26,381
public function envHalt ( ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ this -> engineInstance ( ) -> suspend ( ) ; $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; }
Halt environment engine .
26,382
public function envInstall ( ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ this -> engineInstance ( ) -> install ( ) ; $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; return $ this ; }
Install environment engine configurations .
26,383
public function envSsh ( $ opts = [ 'service' => null ] ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ this -> engineInstance ( ) -> ssh ( $ opts [ 'service' ] ) ; $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; return $ this ; }
SSH into the environment engine .
26,384
public function envLogs ( $ opts = [ 'show' => 'all' , 'follow' => false , 'service' => null ] ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ this -> engineInstance ( ) -> logs ( $ opts [ 'show' ] , $ opts [ 'follow' ] , $ opts [ 'service' ] ) ; $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; return $ this ; }
Display logs for the environment engine .
26,385
public function envExec ( array $ execute_command , $ opts = [ 'service' => null ] ) { $ this -> executeCommandHook ( __FUNCTION__ , 'before' ) ; $ this -> engineInstance ( ) -> exec ( implode ( ' ' , $ execute_command ) , $ opts [ 'service' ] ) ; $ this -> executeCommandHook ( __FUNCTION__ , 'after' ) ; return $ this ; }
Execute an arbitrary command in the environment engine .
26,386
protected function addHostName ( $ no_browser ) { $ host = ProjectX :: getProjectConfig ( ) -> getHost ( ) ; if ( ! empty ( $ host ) ) { $ hostsfile = ( new HostsFile ( ) ) -> setLine ( '127.0.0.1' , $ host [ 'name' ] ) ; ( new HostsFileWriter ( $ hostsfile ) ) -> add ( ) ; $ this -> say ( sprintf ( 'Added %s to hosts file.' , $ host [ 'name' ] ) ) ; if ( ! $ no_browser && $ host [ 'open_on_startup' ] == 'true' ) { $ this -> taskOpenBrowser ( 'http://' . $ host [ 'name' ] ) -> run ( ) ; } } return $ this ; }
Add hostname to hosts file .
26,387
protected function removeHostName ( ) { $ host = ProjectX :: getProjectConfig ( ) -> getHost ( ) ; if ( ! empty ( $ host ) ) { $ hostsfile = ( new HostsFile ( ) ) -> setLine ( '127.0.0.1' , $ host [ 'name' ] ) ; ( new HostsFileWriter ( $ hostsfile ) ) -> remove ( ) ; $ this -> say ( sprintf ( 'Removed %s from hosts file.' , $ host [ 'name' ] ) ) ; } return $ this ; }
Remove hostname from hosts file .
26,388
protected function invokeEngineEvent ( $ method ) { $ project = $ this -> getProjectInstance ( ) ; if ( $ project instanceof EngineEventInterface ) { call_user_func_array ( [ $ project , $ method ] , [ ] ) ; } $ platform = $ this -> getPlatformInstance ( ) ; if ( $ platform instanceof EngineEventInterface ) { call_user_func_array ( [ $ platform , $ method ] , [ ] ) ; } }
Invoke the engine event .
26,389
public function setFile ( UploadedFile $ file = null ) { $ this -> file = $ file ; $ this -> name = $ file -> getClientOriginalName ( ) ; if ( isset ( $ this -> path ) ) { $ this -> temp = $ this -> path ; $ this -> path = null ; } else { $ this -> path = 'initial' ; } }
Sets file .
26,390
public static function exists ( $ string ) { $ instance = self :: getInstance ( ) ; foreach ( $ instance -> getModules ( ) as $ module ) { if ( $ module -> title === $ string ) { return true ; } } return false ; }
Si el modulo existe entonces devuelve true en cualquier otro caso false .
26,391
public static function existsController ( $ key ) { $ instance = self :: getInstance ( ) ; foreach ( $ instance -> getModules ( ) as $ module ) { foreach ( $ module -> getControllers ( ) as $ controller => $ file ) { if ( $ key == $ controller ) { return true ; } } } return false ; }
Comprueba que exista el controlador
26,392
public function run ( $ url = null , $ method = null ) { $ request = new Request ( $ method , $ url ) ; try { Profiler :: start ( 'router' ) ; if ( $ match = $ this -> router -> match ( $ url , $ method ) ) { if ( $ match [ 'name' ] === 'handleFilesystem' ) { Profiler :: stop ( 'router' ) ; return $ this -> handleFilesystem ( $ match [ 'params' ] , $ request ) ; } else { $ target = $ match [ 'target' ] ; $ module = $ target [ 0 ] ; if ( $ module instanceof Module ) { if ( $ this -> isEnabled ( $ module -> title ) ) { $ this -> runningModule = $ module ; $ controller = $ target [ 1 ] ; $ request -> setParams ( $ match [ 'params' ] ) ; Profiler :: stop ( 'router' ) ; return $ module -> run ( $ controller , $ request ) ; } else { Profiler :: stop ( 'router' ) ; return $ this -> mainModule -> run ( new ErrorController ( "This module is disabled by your policy" ) , $ request ) ; } } } } Profiler :: stop ( 'router' ) ; return $ this -> mainModule -> run ( new ErrorController ( "Controller for '$url' not found. " . $ this -> getRoutes ( ) ) , $ request ) ; } catch ( \ Exception $ ex ) { Events :: dispatch ( 'onException' , $ ex ) ; return $ this -> mainModule -> run ( new ExceptionController ( $ ex ) , $ request ) ; } catch ( \ Throwable $ ex ) { Events :: dispatch ( 'onError' , $ ex ) ; return $ this -> mainModule -> run ( new ExceptionController ( $ ex ) , $ request ) ; } }
Ejecutar la ruta
26,393
public function getRoutes ( ) { if ( $ this -> config [ 'app' ] [ 'debug' ] ) { $ html = '<pre>' ; $ result = array ( ) ; foreach ( $ this -> modules as $ module ) { $ list = $ module -> getControllersUrlRoutes ( ) ; $ result = array_merge ( $ list , $ result ) ; } $ html .= implode ( "\n" , $ result ) ; $ html .= '</pre>' ; return $ html ; } return "" ; }
Listado de rutas
26,394
public function handleFilesystem ( $ args , $ request ) { $ file = urldecode ( $ args [ 'name' ] ) ; $ filesystem = new Filesystem ( $ file ) ; if ( $ filesystem -> exists ( ) ) { if ( $ filesystem -> isPublic ( ) ) { header ( 'Content-Type: ' . mime_content_type ( $ filesystem -> getAbsolutePath ( ) ) ) ; $ filesystem -> read ( true ) ; die ( ) ; } else { return $ this -> mainModule -> run ( new ErrorController ( 'Este archivo no es descargable' ) , $ request ) ; } } else { return $ this -> mainModule -> run ( new ErrorController ( 'No se ha encontrado este archivo!' ) , $ request ) ; } }
Llamada a los archivos del sistema
26,395
public function trashAction ( ) { if ( false === $ this -> admin -> isGranted ( 'LIST' ) ) { throw new AccessDeniedException ( ) ; } $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> getFilters ( ) -> disable ( 'softdeleteable' ) ; $ em -> getFilters ( ) -> enable ( 'softdeleteabletrash' ) ; $ em -> getFilters ( ) -> getFilter ( "softdeleteabletrash" ) -> enableForEntity ( $ this -> admin -> getClass ( ) ) ; $ datagrid = $ this -> admin -> getDatagrid ( ) ; $ formView = $ datagrid -> getForm ( ) -> createView ( ) ; $ this -> get ( 'twig' ) -> getExtension ( 'form' ) -> renderer -> setTheme ( $ formView , $ this -> admin -> getFilterTheme ( ) ) ; return $ this -> render ( $ this -> admin -> getTemplate ( 'trash' ) , array ( 'action' => 'trash' , 'form' => $ formView , 'datagrid' => $ datagrid , 'csrf_token' => $ this -> getCsrfToken ( 'sonata.batch' ) , ) ) ; }
return the Response object associated to the trash action
26,396
function formatToArrayStandard ( $ route = null , array $ parameters = array ( ) ) { $ links = array ( 'self' => array ( 'href' => '' ) , 'first' => array ( 'href' => '' ) , 'last' => array ( 'href' => '' ) , 'next' => array ( 'href' => '' ) , 'previous' => array ( 'href' => '' ) , ) ; $ paginator = array ( 'currentPage' => $ this -> getCurrentPage ( ) , 'maxPerPage' => $ this -> getMaxPerPage ( ) , 'totalPages' => $ this -> getNbPages ( ) , 'totalResults' => $ this -> getNbResults ( ) , ) ; $ pageResult = $ this -> getCurrentPageResults ( ) ; if ( is_array ( $ pageResult ) ) { $ results = $ pageResult ; } else { $ results = $ this -> getCurrentPageResults ( ) -> getArrayCopy ( ) ; } return array ( 'links' => $ this -> getLinks ( $ route , $ parameters ) , 'meta' => $ paginator , 'data' => $ results , ) ; }
Formato estandarizado y sencillo
26,397
function formatToArrayDataTables ( $ route = null , array $ parameters = array ( ) ) { $ results = $ this -> getCurrentPageResults ( ) -> getArrayCopy ( ) ; $ data = array ( 'draw' => $ this -> draw , 'recordsTotal' => $ this -> getNbResults ( ) , 'recordsFiltered' => $ this -> getNbResults ( ) , 'data' => $ results , '_links' => $ this -> getLinks ( $ route , $ parameters ) , ) ; return $ data ; }
Formato de paginacion de datatables
26,398
function toArray ( $ route = null , array $ parameters = array ( ) , $ format = null ) { if ( $ format === null ) { $ format = $ this -> defaultFormat ; } if ( in_array ( $ format , $ this -> formatArray ) ) { $ method = 'formatToArray' . ucfirst ( $ format ) ; return $ this -> $ method ( $ route , $ parameters ) ; } }
Convierte los resultados de la pagina actual en array
26,399
protected function generateUrl ( $ route , array $ parameters ) { return $ this -> container -> get ( 'router' ) -> generate ( $ route , $ parameters , Router :: ABSOLUTE_URL ) ; }
Genera una url