idx int64 0 60.3k | question stringlengths 99 4.85k | target stringlengths 5 718 |
|---|---|---|
1,000 | public function regionFillField ( $ field , $ value , $ region ) { $ field = $ this -> fixStepArgument ( $ field ) ; $ value = $ this -> fixStepArgument ( $ value ) ; $ regionObj = $ this -> getRegion ( $ region ) ; $ regionObj -> fillField ( $ field , $ value ) ; } | Fills in a form field with id|name|title|alt|value in the specified region . |
1,001 | public function assertRegionHeading ( $ heading , $ region ) { $ regionObj = $ this -> getRegion ( $ region ) ; foreach ( array ( 'h1' , 'h2' , 'h3' , 'h4' , 'h5' , 'h6' ) as $ tag ) { $ elements = $ regionObj -> findAll ( 'css' , $ tag ) ; if ( ! empty ( $ elements ) ) { foreach ( $ elements as $ element ) { if ( trim ( $ element -> getText ( ) ) === $ heading ) { return ; } } } } throw new \ Exception ( sprintf ( 'The heading "%s" was not found in the "%s" region on the page %s' , $ heading , $ region , $ this -> getSession ( ) -> getCurrentUrl ( ) ) ) ; } | Find a heading in a specific region . |
1,002 | protected function getUser ( ) { trigger_error ( 'DrupalSubContextBase::getUser() is deprecated. Use RawDrupalContext::getUserManager()->getCurrentUser() instead.' , E_USER_DEPRECATED ) ; $ user = $ this -> getUserManager ( ) -> getCurrentUser ( ) ; if ( empty ( $ user ) ) { throw new \ Exception ( 'No user is logged in.' ) ; } return $ user ; } | Get the currently logged in user from DrupalContext . |
1,003 | public function getDrupalParameter ( $ name ) { return isset ( $ this -> drupalParameters [ $ name ] ) ? $ this -> drupalParameters [ $ name ] : null ; } | Returns a specific Drupal parameter . |
1,004 | public function getDrupalText ( $ name ) { $ text = $ this -> getDrupalParameter ( 'text' ) ; if ( ! isset ( $ text [ $ name ] ) ) { throw new \ Exception ( sprintf ( 'No such Drupal string: %s' , $ name ) ) ; } return $ text [ $ name ] ; } | Returns a specific Drupal text value . |
1,005 | public function getDrupalSelector ( $ name ) { $ text = $ this -> getDrupalParameter ( 'selectors' ) ; if ( ! isset ( $ text [ $ name ] ) ) { throw new \ Exception ( sprintf ( 'No such selector configured: %s' , $ name ) ) ; } return $ text [ $ name ] ; } | Returns a specific CSS selector . |
1,006 | public static function alterNodeParameters ( BeforeNodeCreateScope $ scope ) { $ node = $ scope -> getEntity ( ) ; $ api_version = null ; $ driver = $ scope -> getContext ( ) -> getDrupal ( ) -> getDriver ( ) ; if ( $ driver instanceof \ Drupal \ Driver \ DrupalDriver ) { $ api_version = $ scope -> getContext ( ) -> getDrupal ( ) -> getDriver ( ) -> version ; } switch ( $ api_version ) { case 8 : foreach ( array ( 'changed' , 'created' , 'revision_timestamp' ) as $ field ) { if ( ! empty ( $ node -> $ field ) && ! is_numeric ( $ node -> $ field ) ) { $ node -> $ field = strtotime ( $ node -> $ field ) ; } } break ; } } | Massage node values to match the expectations on different Drupal versions . |
1,007 | public function cleanNodes ( ) { foreach ( $ this -> nodes as $ node ) { $ this -> getDriver ( ) -> nodeDelete ( $ node ) ; } $ this -> nodes = array ( ) ; } | Remove any created nodes . |
1,008 | public function cleanUsers ( ) { if ( $ this -> userManager -> hasUsers ( ) ) { foreach ( $ this -> userManager -> getUsers ( ) as $ user ) { $ this -> getDriver ( ) -> userDelete ( $ user ) ; } $ this -> getDriver ( ) -> processBatch ( ) ; $ this -> userManager -> clearUsers ( ) ; if ( $ this -> getAuthenticationManager ( ) instanceof FastLogoutInterface ) { $ this -> logout ( true ) ; } elseif ( $ this -> loggedIn ( ) ) { $ this -> logout ( ) ; } } } | Remove any created users . |
1,009 | public function cleanTerms ( ) { foreach ( $ this -> terms as $ term ) { $ this -> getDriver ( ) -> termDelete ( $ term ) ; } $ this -> terms = array ( ) ; } | Remove any created terms . |
1,010 | public function cleanRoles ( ) { foreach ( $ this -> roles as $ rid ) { $ this -> getDriver ( ) -> roleDelete ( $ rid ) ; } $ this -> roles = array ( ) ; } | Remove any created roles . |
1,011 | public function cleanLanguages ( ) { foreach ( $ this -> languages as $ language ) { $ this -> getDriver ( ) -> languageDelete ( $ language ) ; unset ( $ this -> languages [ $ language -> langcode ] ) ; } } | Remove any created languages . |
1,012 | protected function dispatchHooks ( $ scopeType , \ stdClass $ entity ) { $ fullScopeClass = 'Drupal\\DrupalExtension\\Hook\\Scope\\' . $ scopeType ; $ scope = new $ fullScopeClass ( $ this -> getDrupal ( ) -> getEnvironment ( ) , $ this , $ entity ) ; $ callResults = $ this -> dispatcher -> dispatchScopeHooks ( $ scope ) ; foreach ( $ callResults as $ result ) { if ( $ result -> hasException ( ) ) { $ exception = $ result -> getException ( ) ; throw $ exception ; } } } | Dispatch scope hooks . |
1,013 | public function nodeCreate ( $ node ) { $ this -> dispatchHooks ( 'BeforeNodeCreateScope' , $ node ) ; $ this -> parseEntityFields ( 'node' , $ node ) ; $ saved = $ this -> getDriver ( ) -> createNode ( $ node ) ; $ this -> dispatchHooks ( 'AfterNodeCreateScope' , $ saved ) ; $ this -> nodes [ ] = $ saved ; return $ saved ; } | Create a node . |
1,014 | public function parseEntityFields ( $ entity_type , \ stdClass $ entity ) { $ multicolumn_field = '' ; $ multicolumn_fields = array ( ) ; foreach ( clone $ entity as $ field => $ field_value ) { if ( strpos ( $ field , ':' ) === false ) { $ multicolumn_field = '' ; } elseif ( strpos ( $ field , ':' , 1 ) !== false ) { list ( $ multicolumn_field , $ multicolumn_column ) = explode ( ':' , $ field ) ; } elseif ( empty ( $ multicolumn_field ) ) { throw new \ Exception ( 'Field name missing for ' . $ field ) ; } else { $ multicolumn_column = substr ( $ field , 1 ) ; } $ is_multicolumn = $ multicolumn_field && $ multicolumn_column ; $ field_name = $ multicolumn_field ? : $ field ; if ( $ this -> getDriver ( ) -> isField ( $ entity_type , $ field_name ) ) { $ values = array ( ) ; foreach ( str_getcsv ( $ field_value ) as $ key => $ value ) { $ value = trim ( $ value ) ; $ columns = $ value ; if ( strstr ( $ value , ' - ' ) !== false ) { $ columns = array ( ) ; foreach ( explode ( ' - ' , $ value ) as $ column ) { if ( ! $ is_multicolumn && strpos ( $ column , ': ' , 1 ) !== false ) { list ( $ key , $ column ) = explode ( ': ' , $ column ) ; $ columns [ $ key ] = $ column ; } else { $ columns [ ] = $ column ; } } } if ( $ is_multicolumn ) { $ multicolumn_fields [ $ multicolumn_field ] [ $ key ] [ $ multicolumn_column ] = $ columns ; unset ( $ entity -> $ field ) ; } else { $ values [ ] = $ columns ; } } if ( ! $ is_multicolumn ) { $ entity -> $ field_name = $ values ; if ( $ field_value === '' ) { unset ( $ entity -> $ field_name ) ; } } } } foreach ( $ multicolumn_fields as $ field_name => $ columns ) { if ( count ( array_filter ( $ columns , function ( $ var ) { return ( $ var !== '' ) ; } ) ) > 0 ) { $ entity -> $ field_name = $ columns ; } } } | Parses the field values and turns them into the format expected by Drupal . |
1,015 | public function termCreate ( $ term ) { $ this -> dispatchHooks ( 'BeforeTermCreateScope' , $ term ) ; $ this -> parseEntityFields ( 'taxonomy_term' , $ term ) ; $ saved = $ this -> getDriver ( ) -> createTerm ( $ term ) ; $ this -> dispatchHooks ( 'AfterTermCreateScope' , $ saved ) ; $ this -> terms [ ] = $ saved ; return $ saved ; } | Create a term . |
1,016 | public function languageCreate ( \ stdClass $ language ) { $ this -> dispatchHooks ( 'BeforeLanguageCreateScope' , $ language ) ; $ language = $ this -> getDriver ( ) -> languageCreate ( $ language ) ; if ( $ language ) { $ this -> dispatchHooks ( 'AfterLanguageCreateScope' , $ language ) ; $ this -> languages [ $ language -> langcode ] = $ language ; } return $ language ; } | Creates a language . |
1,017 | protected function getContext ( $ class ) { $ environment = $ this -> drupal -> getEnvironment ( ) ; if ( ! $ environment instanceof InitializedContextEnvironment ) { throw new \ Exception ( 'Cannot retrieve contexts when the environment is not yet initialized.' ) ; } foreach ( $ environment -> getContexts ( ) as $ context ) { if ( $ context instanceof $ class ) { return $ context ; } } return false ; } | Returns the Behat context that corresponds with the given class name . |
1,018 | private function findSubContextClasses ( ) { $ class_names = array ( ) ; if ( isset ( $ this -> parameters [ 'subcontexts' ] ) ) { $ paths = array ( ) ; if ( $ this -> parameters [ 'subcontexts' ] [ 'autoload' ] ) { foreach ( $ this -> drupal -> getDrivers ( ) as $ name => $ driver ) { if ( $ driver instanceof SubDriverFinderInterface ) { $ paths += $ driver -> getSubDriverPaths ( ) ; } } } if ( isset ( $ this -> parameters [ 'subcontexts' ] [ 'paths' ] ) ) { $ paths = array_merge ( $ paths , $ this -> parameters [ 'subcontexts' ] [ 'paths' ] ) ; } foreach ( $ paths as $ path ) { if ( $ subcontexts = $ this -> findAvailableSubContexts ( $ path ) ) { $ this -> loadSubContexts ( $ subcontexts ) ; } } $ classes = get_declared_classes ( ) ; foreach ( $ classes as $ class ) { $ reflect = new \ ReflectionClass ( $ class ) ; if ( ! $ reflect -> isAbstract ( ) && $ reflect -> implementsInterface ( 'Drupal\DrupalExtension\Context\DrupalSubContextInterface' ) ) { $ class_names [ ] = $ class ; } } } return $ class_names ; } | Finds and loads available subcontext classes . |
1,019 | private function findAvailableSubContexts ( $ path , $ pattern = '/^.+\.behat\.inc/i' ) { if ( isset ( static :: $ subContexts [ $ pattern ] [ $ path ] ) ) { return static :: $ subContexts [ $ pattern ] [ $ path ] ; } static :: $ subContexts [ $ pattern ] [ $ path ] = array ( ) ; $ fileIterator = new RegexIterator ( new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $ path ) ) , $ pattern , RegexIterator :: MATCH ) ; foreach ( $ fileIterator as $ found ) { static :: $ subContexts [ $ pattern ] [ $ path ] [ $ found -> getRealPath ( ) ] = $ found -> getFileName ( ) ; } return static :: $ subContexts [ $ pattern ] [ $ path ] ; } | Find Sub - contexts matching a given pattern located at the passed path . |
1,020 | private function loadSubContexts ( $ subcontexts ) { foreach ( $ subcontexts as $ path => $ subcontext ) { if ( ! file_exists ( $ path ) ) { throw new \ RuntimeException ( sprintf ( 'Subcontext path %s path does not exist.' , $ path ) ) ; } require_once $ path ; } } | Load each subcontext file . |
1,021 | public function castUsersTable ( TableNode $ user_table ) { $ aliases = array ( 'country' => 'field_post_address:country' , 'city' => 'field_post_address:locality' , 'street' => 'field_post_address:thoroughfare' , 'postcode' => 'field_post_address:postal_code' , ) ; $ table = $ user_table -> getTable ( ) ; reset ( $ table ) ; $ first_row = key ( $ table ) ; foreach ( $ table [ $ first_row ] as $ key => $ alias ) { if ( array_key_exists ( $ alias , $ aliases ) ) { $ table [ $ first_row ] [ $ key ] = $ aliases [ $ alias ] ; } } return new TableNode ( $ table ) ; } | Transforms long address field columns into shorter aliases . |
1,022 | public function transformPostContentTable ( TableNode $ post_table ) { $ aliases = array ( 'reference' => 'field_post_reference' , 'date' => 'field_post_date' , 'links' => 'field_post_links' , 'select' => 'field_post_select' , 'address' => 'field_post_address' , ) ; $ table = $ post_table -> getTable ( ) ; array_walk ( $ table , function ( & $ row ) use ( $ aliases ) { if ( array_key_exists ( $ row [ 0 ] , $ aliases ) ) { $ row [ 0 ] = $ aliases [ $ row [ 0 ] ] ; } } ) ; return new TableNode ( $ table ) ; } | Transforms human readable field names into machine names . |
1,023 | public function assertAuthenticatedByUsernameAndPassword ( $ name , $ password ) { $ user = ( object ) [ 'name' => $ name , 'pass' => $ password , ] ; $ this -> userCreate ( $ user ) ; $ this -> login ( $ user ) ; } | Creates and authenticates a user with the given username and password . |
1,024 | public function fileShouldContain ( $ path , PyStringNode $ text ) { $ path = $ this -> workingDir . '/' . $ path ; PHPUnit_Framework_Assert :: assertFileExists ( $ path ) ; $ fileContent = trim ( file_get_contents ( $ path ) ) ; if ( "\n" !== PHP_EOL ) { $ fileContent = str_replace ( PHP_EOL , "\n" , $ fileContent ) ; } PHPUnit_Framework_Assert :: assertEquals ( $ this -> getExpectedOutput ( $ text ) , $ fileContent ) ; } | Checks whether specified file exists and contains specified string . |
1,025 | private function loadParameters ( ContainerBuilder $ container , array $ config ) { $ drupal_parameters = array ( ) ; foreach ( $ config as $ key => $ value ) { $ drupal_parameters [ $ key ] = $ value ; } $ container -> setParameter ( 'drupal.parameters' , $ drupal_parameters ) ; $ container -> setParameter ( 'drupal.region_map' , $ config [ 'region_map' ] ) ; } | Load test parameters . |
1,026 | private function loadDrupal ( FileLoader $ loader , ContainerBuilder $ container , array $ config ) { if ( isset ( $ config [ 'drupal' ] ) ) { $ loader -> load ( 'drivers/drupal.yml' ) ; $ container -> setParameter ( 'drupal.driver.drupal.drupal_root' , $ config [ 'drupal' ] [ 'drupal_root' ] ) ; } } | Load the Drupal driver . |
1,027 | private function loadDrush ( FileLoader $ loader , ContainerBuilder $ container , array $ config ) { if ( isset ( $ config [ 'drush' ] ) ) { $ loader -> load ( 'drivers/drush.yml' ) ; if ( ! isset ( $ config [ 'drush' ] [ 'alias' ] ) && ! isset ( $ config [ 'drush' ] [ 'root' ] ) ) { throw new \ RuntimeException ( 'Drush `alias` or `root` path is required for the Drush driver.' ) ; } $ config [ 'drush' ] [ 'alias' ] = isset ( $ config [ 'drush' ] [ 'alias' ] ) ? $ config [ 'drush' ] [ 'alias' ] : false ; $ container -> setParameter ( 'drupal.driver.drush.alias' , $ config [ 'drush' ] [ 'alias' ] ) ; $ config [ 'drush' ] [ 'binary' ] = isset ( $ config [ 'drush' ] [ 'binary' ] ) ? $ config [ 'drush' ] [ 'binary' ] : 'drush' ; $ container -> setParameter ( 'drupal.driver.drush.binary' , $ config [ 'drush' ] [ 'binary' ] ) ; $ config [ 'drush' ] [ 'root' ] = isset ( $ config [ 'drush' ] [ 'root' ] ) ? $ config [ 'drush' ] [ 'root' ] : false ; $ container -> setParameter ( 'drupal.driver.drush.root' , $ config [ 'drush' ] [ 'root' ] ) ; $ this -> setDrushOptions ( $ container , $ config ) ; } } | Load the Drush driver . |
1,028 | private function setDrushOptions ( ContainerBuilder $ container , array $ config ) { if ( isset ( $ config [ 'drush' ] [ 'global_options' ] ) ) { $ definition = $ container -> getDefinition ( 'drupal.driver.drush' ) ; $ definition -> addMethodCall ( 'setArguments' , array ( $ config [ 'drush' ] [ 'global_options' ] ) ) ; } } | Set global drush arguments . |
1,029 | private function processEnvironmentReaderPass ( ContainerBuilder $ container ) { $ references = $ this -> processor -> findAndSortTaggedServices ( $ container , ContextExtension :: READER_TAG ) ; $ definition = $ container -> getDefinition ( 'drupal.context.environment.reader' ) ; foreach ( $ references as $ reference ) { $ definition -> addMethodCall ( 'registerContextReader' , array ( $ reference ) ) ; } } | Process the Environment Reader pass . |
1,030 | private function processClassGenerator ( ContainerBuilder $ container ) { $ definition = new Definition ( 'Drupal\DrupalExtension\Context\ContextClass\ClassGenerator' ) ; $ container -> setDefinition ( ContextExtension :: CLASS_GENERATOR_TAG . '.simple' , $ definition ) ; } | Switch to custom class generator . |
1,031 | public function getTableRow ( Element $ element , $ search ) { $ rows = $ element -> findAll ( 'css' , 'tr' ) ; if ( empty ( $ rows ) ) { throw new \ Exception ( sprintf ( 'No rows found on the page %s' , $ this -> getSession ( ) -> getCurrentUrl ( ) ) ) ; } foreach ( $ rows as $ row ) { if ( strpos ( $ row -> getText ( ) , $ search ) !== false ) { return $ row ; } } throw new \ Exception ( sprintf ( 'Failed to find a row containing "%s" on the page %s' , $ search , $ this -> getSession ( ) -> getCurrentUrl ( ) ) ) ; } | Retrieve a table row containing specified text from a given element . |
1,032 | public function assertTextInTableRow ( $ text , $ rowText ) { $ row = $ this -> getTableRow ( $ this -> getSession ( ) -> getPage ( ) , $ rowText ) ; if ( strpos ( $ row -> getText ( ) , $ text ) === false ) { throw new \ Exception ( sprintf ( 'Found a row containing "%s", but it did not contain the text "%s".' , $ rowText , $ text ) ) ; } } | Find text in a table row containing given text . |
1,033 | public function createNode ( $ type , $ title ) { $ node = ( object ) array ( 'title' => $ title , 'type' => $ type , ) ; $ saved = $ this -> nodeCreate ( $ node ) ; $ this -> getSession ( ) -> visit ( $ this -> locatePath ( '/node/' . $ saved -> nid ) ) ; } | Creates content of the given type . |
1,034 | public function createMyNode ( $ type , $ title ) { if ( $ this -> getUserManager ( ) -> currentUserIsAnonymous ( ) ) { throw new \ Exception ( sprintf ( 'There is no current logged in user to create a node for.' ) ) ; } $ node = ( object ) array ( 'title' => $ title , 'type' => $ type , 'body' => $ this -> getRandom ( ) -> name ( 255 ) , 'uid' => $ this -> getUserManager ( ) -> getCurrentUser ( ) -> uid , ) ; $ saved = $ this -> nodeCreate ( $ node ) ; $ this -> getSession ( ) -> visit ( $ this -> locatePath ( '/node/' . $ saved -> nid ) ) ; } | Creates content authored by the current user . |
1,035 | public function assertEditNodeOfType ( $ type ) { $ node = ( object ) array ( 'type' => $ type , 'title' => "Test $type" , ) ; $ saved = $ this -> nodeCreate ( $ node ) ; $ this -> getSession ( ) -> visit ( $ this -> locatePath ( '/node/' . $ saved -> nid . '/edit' ) ) ; $ this -> assertSession ( ) -> statusCodeEquals ( '200' ) ; } | Asserts that a given content type is editable . |
1,036 | public function createTerm ( $ vocabulary , $ name ) { $ term = ( object ) array ( 'name' => $ name , 'vocabulary_machine_name' => $ vocabulary , 'description' => $ this -> getRandom ( ) -> name ( 255 ) , ) ; $ saved = $ this -> termCreate ( $ term ) ; $ this -> getSession ( ) -> visit ( $ this -> locatePath ( '/taxonomy/term/' . $ saved -> tid ) ) ; } | Creates a term on an existing vocabulary . |
1,037 | public function createUsers ( TableNode $ usersTable ) { foreach ( $ usersTable -> getHash ( ) as $ userHash ) { $ roles = array ( ) ; if ( isset ( $ userHash [ 'roles' ] ) ) { $ roles = explode ( ',' , $ userHash [ 'roles' ] ) ; $ roles = array_filter ( array_map ( 'trim' , $ roles ) ) ; unset ( $ userHash [ 'roles' ] ) ; } $ user = ( object ) $ userHash ; if ( ! isset ( $ user -> pass ) ) { $ user -> pass = $ this -> getRandom ( ) -> name ( ) ; } $ this -> userCreate ( $ user ) ; foreach ( $ roles as $ role ) { $ this -> getDriver ( ) -> userAddRole ( $ user , $ role ) ; } } } | Creates multiple users . |
1,038 | public function createTerms ( $ vocabulary , TableNode $ termsTable ) { foreach ( $ termsTable -> getHash ( ) as $ termsHash ) { $ term = ( object ) $ termsHash ; $ term -> vocabulary_machine_name = $ vocabulary ; $ this -> termCreate ( $ term ) ; } } | Creates one or more terms on an existing vocabulary . |
1,039 | public function createLanguages ( TableNode $ langcodesTable ) { foreach ( $ langcodesTable -> getHash ( ) as $ row ) { $ language = ( object ) array ( 'langcode' => $ row [ 'languages' ] , ) ; $ this -> languageCreate ( $ language ) ; } } | Creates one or more languages . |
1,040 | public function iPutABreakpoint ( ) { fwrite ( STDOUT , "\033[s \033[93m[Breakpoint] Press \033[1;93m[RETURN]\033[0;93m to continue, or 'q' to quit...\033[0m" ) ; do { $ line = trim ( fgets ( STDIN , 1024 ) ) ; $ charCode = ord ( $ line ) ; switch ( $ charCode ) { case 0 : case 121 : case 89 : break 2 ; case 113 : case 81 : throw new \ Exception ( "Exiting test intentionally." ) ; default : fwrite ( STDOUT , sprintf ( "\nInvalid entry '%s'. Please enter 'y', 'q', or the enter key.\n" , $ line ) ) ; break ; } } while ( true ) ; fwrite ( STDOUT , "\033[u" ) ; } | Pauses the scenario until the user presses a key . Useful when debugging a scenario . |
1,041 | protected function getTags ( ) { $ featureTags = $ this -> getFeature ( ) -> getTags ( ) ; $ scenarioTags = $ this -> getScenario ( ) -> getTags ( ) ; return array_unique ( array_merge ( $ featureTags , $ scenarioTags ) ) ; } | Returns all tags for the current scenario and feature . |
1,042 | public function disableMail ( $ event ) { $ tags = array_merge ( $ event -> getFeature ( ) -> getTags ( ) , $ event -> getScenario ( ) -> getTags ( ) ) ; if ( ! in_array ( 'sendmail' , $ tags ) && ! in_array ( 'sendemail' , $ tags ) ) { $ this -> getMailManager ( ) -> disableMail ( ) ; $ this -> mailCount = [ ] ; } } | By default prevent mail from being actually sent out during tests . |
1,043 | public function enableMail ( $ event ) { $ tags = array_merge ( $ event -> getFeature ( ) -> getTags ( ) , $ event -> getScenario ( ) -> getTags ( ) ) ; if ( ! in_array ( 'sendmail' , $ tags ) && ! in_array ( 'sendemail' , $ tags ) ) { $ this -> getMailManager ( ) -> enableMail ( ) ; } } | Restore mail sending . |
1,044 | public function drupalSendsMail ( TableNode $ fields ) { $ mail = [ 'body' => $ this -> getRandom ( ) -> name ( 255 ) , 'subject' => $ this -> getRandom ( ) -> name ( 20 ) , 'to' => $ this -> getRandom ( ) -> name ( 10 ) . '@anonexample.com' , 'langcode' => '' , ] ; foreach ( $ fields -> getRowsHash ( ) as $ field => $ value ) { $ mail [ $ field ] = $ value ; } $ this -> getDriver ( ) -> sendMail ( $ mail [ 'body' ] , $ mail [ 'subject' ] , $ mail [ 'to' ] , $ mail [ 'langcode' ] ) ; } | This is mainly useful for testing this context . |
1,045 | protected function getMailManager ( ) { if ( is_null ( $ this -> mailManager ) ) { $ this -> mailManager = new DrupalMailManager ( $ this -> getDriver ( ) ) ; } return $ this -> mailManager ; } | Get the mail manager service that handles stored test mail . |
1,046 | protected function getMail ( $ matches = [ ] , $ new = false , $ index = null , $ store = 'default' ) { $ mail = $ this -> getMailManager ( ) -> getMail ( $ store ) ; $ previousMailCount = $ this -> getMailCount ( $ store ) ; $ this -> mailCount [ $ store ] = count ( $ mail ) ; if ( $ new ) { $ mail = array_slice ( $ mail , $ previousMailCount ) ; } $ mail = array_values ( array_filter ( $ mail , function ( $ singleMail ) use ( $ matches ) { return ( $ this -> matchesMail ( $ singleMail , $ matches ) ) ; } ) ) ; if ( is_null ( $ index ) || count ( $ mail ) === 0 ) { return $ mail ; } else { return array_slice ( $ mail , $ index , 1 ) [ 0 ] ; } } | Get collected mail matching certain specifications . |
1,047 | protected function getMailCount ( $ store ) { if ( array_key_exists ( $ store , $ this -> mailCount ) ) { $ count = $ this -> mailCount [ $ store ] ; } else { $ count = 0 ; } return $ count ; } | Get the number of mails received in a particular mail store . |
1,048 | protected function matchesMail ( $ mail = [ ] , $ matches = [ ] ) { $ matches = array_filter ( $ matches , 'strlen' ) ; foreach ( $ matches as $ field => $ value ) { if ( stripos ( $ mail [ $ field ] , $ value ) === false ) { return false ; } } return true ; } | Determine if a mail meets criteria . |
1,049 | protected function compareMail ( $ actualMail , $ expectedMail ) { $ expectedCount = count ( $ expectedMail ) ; $ this -> assertMailCount ( $ actualMail , $ expectedCount ) ; $ actualMail = $ this -> sortMail ( $ actualMail ) ; $ expectedMail = $ this -> sortMail ( $ expectedMail ) ; foreach ( $ expectedMail as $ index => $ expectedMailItem ) { foreach ( $ expectedMailItem as $ fieldName => $ fieldValue ) { $ expectedField = [ $ fieldName => $ fieldValue ] ; $ match = $ this -> matchesMail ( $ actualMail [ $ index ] , $ expectedField ) ; if ( ! $ match ) { throw new \ Exception ( sprintf ( "The #%s mail did not have '%s' in its %s field. It had:\n'%s'" , $ index , $ fieldValue , $ fieldName , mb_strimwidth ( $ actualMail [ $ index ] [ $ fieldName ] , 0 , 30 , "..." ) ) ) ; } } } } | Compare actual mail with expected mail . |
1,050 | protected function assertMailCount ( $ actualMail , $ expectedCount = null ) { $ actualCount = count ( $ actualMail ) ; if ( is_null ( $ expectedCount ) ) { if ( $ actualCount === 0 ) { throw new \ Exception ( "Expected some mail, but none found." ) ; } } else { if ( $ expectedCount != $ actualCount ) { $ prettyActualMail = [ ] ; foreach ( $ actualMail as $ singleActualMail ) { $ prettyActualMail [ ] = [ 'to' => $ singleActualMail [ 'to' ] , 'subject' => $ singleActualMail [ 'subject' ] , ] ; } throw new \ Exception ( sprintf ( "Expected %s mail, but %s found:\n\n%s" , $ expectedCount , $ actualCount , print_r ( $ prettyActualMail , true ) ) ) ; } } } | Assert there is the expected number of mails or that there are some mails if the exact number expected is not specified . |
1,051 | protected function sortMail ( $ mail ) { if ( count ( $ mail ) === 0 ) { return [ ] ; } foreach ( $ mail as $ key => $ row ) { if ( ! array_key_exists ( 'to' , $ row ) ) { $ mail [ $ key ] [ 'to' ] = '' ; } if ( ! array_key_exists ( 'subject' , $ row ) ) { $ mail [ $ key ] [ 'subject' ] = '' ; } if ( ! array_key_exists ( 'body' , $ row ) ) { $ mail [ $ key ] [ 'body' ] = '' ; } } foreach ( $ mail as $ key => $ row ) { if ( array_key_exists ( 'to' , $ row ) ) { $ to [ $ key ] = $ row [ 'to' ] ; } if ( array_key_exists ( 'subject' , $ row ) ) { $ subject [ $ key ] = $ row [ 'subject' ] ; } if ( array_key_exists ( 'body' , $ row ) ) { $ body [ $ key ] = $ row [ 'body' ] ; } } array_multisort ( $ to , SORT_ASC , $ subject , SORT_ASC , $ body , SORT_ASC , $ mail ) ; return $ mail ; } | Sort mail by to subject and body . |
1,052 | public function process ( ContainerBuilder $ container ) { if ( ! $ container -> hasDefinition ( 'drupal.drupal' ) ) { return ; } $ drupalDefinition = $ container -> getDefinition ( 'drupal.drupal' ) ; foreach ( $ container -> findTaggedServiceIds ( 'drupal.driver' ) as $ id => $ attributes ) { foreach ( $ attributes as $ attribute ) { if ( isset ( $ attribute [ 'alias' ] ) && $ name = $ attribute [ 'alias' ] ) { $ drupalDefinition -> addMethodCall ( 'registerDriver' , array ( $ name , new Reference ( $ id ) ) ) ; } } if ( 'drupal.driver.drupal' === $ id ) { $ drupalDriverDefinition = $ container -> getDefinition ( $ id ) ; $ availableCores = array ( ) ; foreach ( $ container -> findTaggedServiceIds ( 'drupal.core' ) as $ coreId => $ coreAttributes ) { foreach ( $ coreAttributes as $ attribute ) { if ( isset ( $ attribute [ 'alias' ] ) && $ name = $ attribute [ 'alias' ] ) { $ availableCores [ $ name ] = $ container -> getDefinition ( $ coreId ) ; } } } $ drupalDriverDefinition -> addMethodCall ( 'setCore' , array ( $ availableCores ) ) ; } } $ drupalDefinition -> addMethodCall ( 'setDefaultDriverName' , array ( $ container -> getParameter ( 'drupal.drupal.default_driver' ) ) ) ; } | Register Drupal drivers . |
1,053 | public function transformVariables ( $ message ) { $ patterns = [ ] ; $ replacements = [ ] ; preg_match_all ( static :: VARIABLE_REGEX , $ message , $ matches ) ; foreach ( $ matches [ 0 ] as $ variable ) { $ replacements [ ] = $ this -> values [ $ variable ] ; $ patterns [ ] = '#' . preg_quote ( $ variable ) . '#' ; } $ message = preg_replace ( $ patterns , $ replacements , $ message ) ; return $ message ; } | Transform random variables . |
1,054 | public function beforeScenarioSetVariables ( BeforeScenarioScope $ scope ) { $ steps = [ ] ; if ( $ scope -> getFeature ( ) -> hasBackground ( ) ) { $ steps = $ scope -> getFeature ( ) -> getBackground ( ) -> getSteps ( ) ; } $ steps = array_merge ( $ steps , $ scope -> getScenario ( ) -> getSteps ( ) ) ; foreach ( $ steps as $ step ) { preg_match_all ( static :: VARIABLE_REGEX , $ step -> getText ( ) , $ matches ) ; $ variables_found = $ matches [ 0 ] ; $ step_argument = $ step -> getArguments ( ) ; if ( ! empty ( $ step_argument ) && $ step_argument [ 0 ] instanceof TableNode ) { preg_match_all ( static :: VARIABLE_REGEX , $ step_argument [ 0 ] -> getTableAsString ( ) , $ matches ) ; $ variables_found = array_filter ( array_merge ( $ variables_found , $ matches [ 0 ] ) ) ; } foreach ( $ variables_found as $ variable_name ) { if ( ! isset ( $ this -> values [ $ variable_name ] ) ) { $ value = $ this -> getDriver ( ) -> getRandom ( ) -> name ( 10 ) ; $ this -> values [ $ variable_name ] = strtolower ( $ value ) ; } } } } | Set values for each random variable found in the current scenario . |
1,055 | protected function getCurrentScenarioTags ( StepScope $ scope ) { $ featureTags = $ scope -> getFeature ( ) -> getTags ( ) ; $ scenarioTags = $ this -> getScenario ( ) -> getTags ( ) ; return array_merge ( $ featureTags , $ scenarioTags ) ; } | Get all tags for the current scenario . |
1,056 | public function registerDriver ( $ name , DriverInterface $ driver ) { $ name = strtolower ( $ name ) ; $ this -> drivers [ $ name ] = $ driver ; } | Register a new driver . |
1,057 | public function getDriver ( $ name = null ) { $ name = strtolower ( $ name ) ? : $ this -> defaultDriverName ; if ( null === $ name ) { throw new \ InvalidArgumentException ( 'Specify a Drupal driver to get.' ) ; } if ( ! isset ( $ this -> drivers [ $ name ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Driver "%s" is not registered' , $ name ) ) ; } $ driver = $ this -> drivers [ $ name ] ; if ( ! $ driver -> isBootstrapped ( ) ) { $ driver -> bootstrap ( ) ; } return $ driver ; } | Return a registered driver by name or the default driver . |
1,058 | public function assertMultipleErrors ( TableNode $ messages ) { $ this -> assertValidMessageTable ( $ messages , 'error messages' ) ; foreach ( $ messages -> getHash ( ) as $ key => $ value ) { $ value = array_change_key_case ( $ value ) ; $ message = trim ( $ value [ 'error messages' ] ) ; $ this -> assertErrorVisible ( $ message ) ; } } | Checks if the current page contains the given set of error messages |
1,059 | public function assertNotMultipleErrors ( TableNode $ messages ) { $ this -> assertValidMessageTable ( $ messages , 'error messages' ) ; foreach ( $ messages -> getHash ( ) as $ key => $ value ) { $ value = array_change_key_case ( $ value ) ; $ message = trim ( $ value [ 'error messages' ] ) ; $ this -> assertNotErrorVisible ( $ message ) ; } } | Checks if the current page does not contain the given set error messages |
1,060 | public function assertMultipleSuccessMessage ( TableNode $ messages ) { $ this -> assertValidMessageTable ( $ messages , 'success messages' ) ; foreach ( $ messages -> getHash ( ) as $ key => $ value ) { $ value = array_change_key_case ( $ value ) ; $ message = trim ( $ value [ 'success messages' ] ) ; $ this -> assertSuccessMessage ( $ message ) ; } } | Checks if the current page contains the given set of success messages |
1,061 | public function assertNotMultipleSuccessMessage ( TableNode $ messages ) { $ this -> assertValidMessageTable ( $ messages , 'success messages' ) ; foreach ( $ messages -> getHash ( ) as $ key => $ value ) { $ value = array_change_key_case ( $ value ) ; $ message = trim ( $ value [ 'success messages' ] ) ; $ this -> assertNotSuccessMessage ( $ message ) ; } } | Checks if the current page does not contain the given set of success messages |
1,062 | public function assertMultipleWarningMessage ( TableNode $ messages ) { $ this -> assertValidMessageTable ( $ messages , 'warning messages' ) ; foreach ( $ messages -> getHash ( ) as $ key => $ value ) { $ value = array_change_key_case ( $ value ) ; $ message = trim ( $ value [ 'warning messages' ] ) ; $ this -> assertWarningMessage ( $ message ) ; } } | Checks if the current page contains the given set of warning messages |
1,063 | public function assertNotMultipleWarningMessage ( TableNode $ messages ) { $ this -> assertValidMessageTable ( $ messages , 'warning messages' ) ; foreach ( $ messages -> getHash ( ) as $ key => $ value ) { $ value = array_change_key_case ( $ value ) ; $ message = trim ( $ value [ 'warning messages' ] ) ; $ this -> assertNotWarningMessage ( $ message ) ; } } | Checks if the current page does not contain the given set of warning messages |
1,064 | protected function assertValidMessageTable ( TableNode $ messages , $ expected_header ) { $ header_row = $ messages -> getRow ( 0 ) ; $ column_count = count ( $ header_row ) ; if ( $ column_count != 1 ) { throw new \ RuntimeException ( "The list of $expected_header should only contain 1 column. It has $column_count columns." ) ; } $ actual_header = reset ( $ header_row ) ; if ( strtolower ( trim ( $ actual_header ) ) !== $ expected_header ) { $ capitalized_header = ucfirst ( $ expected_header ) ; throw new \ RuntimeException ( "The list of $expected_header should have the header '$capitalized_header'." ) ; } } | Checks whether the given list of messages is valid . |
1,065 | private function assert ( $ message , $ selectorId , $ exceptionMsgNone , $ exceptionMsgMissing ) { $ selector = $ this -> getDrupalSelector ( $ selectorId ) ; $ selectorObjects = $ this -> getSession ( ) -> getPage ( ) -> findAll ( "css" , $ selector ) ; if ( empty ( $ selectorObjects ) ) { throw new ExpectationException ( sprintf ( $ exceptionMsgNone , $ this -> getSession ( ) -> getCurrentUrl ( ) ) , $ this -> getSession ( ) -> getDriver ( ) ) ; } foreach ( $ selectorObjects as $ selectorObject ) { if ( strpos ( trim ( $ selectorObject -> getText ( ) ) , $ message ) !== false ) { return ; } } throw new ExpectationException ( sprintf ( $ exceptionMsgMissing , $ this -> getSession ( ) -> getCurrentUrl ( ) , $ message ) , $ this -> getSession ( ) -> getDriver ( ) ) ; } | Internal callback to check for a specific message in a given context . |
1,066 | private function assertNot ( $ message , $ selectorId , $ exceptionMsg ) { $ selector = $ this -> getDrupalSelector ( $ selectorId ) ; $ selectorObjects = $ this -> getSession ( ) -> getPage ( ) -> findAll ( "css" , $ selector ) ; if ( ! empty ( $ selectorObjects ) ) { foreach ( $ selectorObjects as $ selectorObject ) { if ( strpos ( trim ( $ selectorObject -> getText ( ) ) , $ message ) !== false ) { throw new ExpectationException ( sprintf ( $ exceptionMsg , $ this -> getSession ( ) -> getCurrentUrl ( ) , $ message ) , $ this -> getSession ( ) -> getDriver ( ) ) ; } } } } | Internal callback to check if the current page does not contain the given message |
1,067 | public function thereIsAnItemInTheSystemQueue ( TableNode $ table ) { $ fields = $ table -> getRowsHash ( ) ; if ( empty ( $ fields [ 'data' ] ) ) { $ fields [ 'data' ] = json_encode ( [ ] ) ; } $ query = db_insert ( 'queue' ) -> fields ( array ( 'name' => $ fields [ 'name' ] ? : user_password ( ) , 'data' => serialize ( json_decode ( $ fields [ 'data' ] ) ) , 'created' => $ fields [ 'created' ] ? : REQUEST_TIME , 'expire' => $ fields [ 'expire' ] ? : 0 , ) ) ; if ( ! $ query -> execute ( ) ) { throw new Exception ( 'Unable to create the queue item.' ) ; } } | Creates a queue item . Defaults inputs if none are available . |
1,068 | public function assertRegionButton ( $ button , $ region ) { $ regionObj = $ this -> getRegion ( $ region ) ; $ buttonObj = $ regionObj -> findButton ( $ button ) ; if ( empty ( $ buttonObj ) ) { throw new \ Exception ( sprintf ( "The button '%s' was not found in the region '%s' on the page %s" , $ button , $ region , $ this -> getSession ( ) -> getCurrentUrl ( ) ) ) ; } } | Checks if a button with id|name|title|alt|value exists in a region |
1,069 | public static function preg_match ( $ pattern , $ subject , & $ matches = null , $ flags = 0 , $ offset = 0 ) { if ( false === $ ret = preg_match ( $ pattern , $ subject , $ matches , $ flags , $ offset ) ) { switch ( preg_last_error ( ) ) { case PREG_INTERNAL_ERROR : $ error = 'Internal PCRE error.' ; break ; case PREG_BACKTRACK_LIMIT_ERROR : $ error = 'pcre.backtrack_limit reached.' ; break ; case PREG_RECURSION_LIMIT_ERROR : $ error = 'pcre.recursion_limit reached.' ; break ; case PREG_BAD_UTF8_ERROR : $ error = 'Malformed UTF-8 data.' ; break ; case PREG_BAD_UTF8_OFFSET_ERROR : $ error = 'Offset doesn\'t correspond to the begin of a valid UTF-8 code point.' ; break ; default : $ error = 'Error.' ; } throw new ParseException ( $ error ) ; } return $ ret ; } | A local wrapper for preg_match which will throw a ParseException if there is an internal error in the PCRE engine . |
1,070 | protected function setNameLabels ( ) { $ this -> one = ( $ this -> data [ 'labels.has_one' ] ? $ this -> data [ 'labels.has_one' ] : ucfirst ( $ this -> name ) ) ; $ this -> many = ( $ this -> data [ 'labels.has_many' ] ? $ this -> data [ 'labels.has_many' ] : ucfirst ( $ this -> name . 's' ) ) ; $ this -> i18n = ( $ this -> data [ 'labels.text_domain' ] ? $ this -> data [ 'labels.text_domain' ] : 'sober' ) ; } | Set required labels |
1,071 | protected function setLabels ( ) { if ( $ this -> data [ 'labels.overrides' ] ) { $ this -> labels = array_replace ( $ this -> labels , $ this -> data [ 'labels.overrides' ] ) ; } } | Set label overrides |
1,072 | protected function setDefaultConfig ( ) { if ( $ this -> data [ 'config' ] ) { $ this -> config = $ this -> data [ 'config' ] ; } if ( in_array ( $ this -> data [ 'type' ] , [ 'cat' , 'category' ] ) ) { $ this -> config = [ 'hierarchical' => true ] ; } if ( $ this -> data [ 'links' ] ) { $ this -> links = $ this -> data [ 'links' ] ; } return $ this ; } | Set config defaults |
1,073 | private static function parseSequence ( $ sequence , $ flags , & $ i = 0 , $ references = array ( ) ) { $ output = array ( ) ; $ len = \ strlen ( $ sequence ) ; ++ $ i ; while ( $ i < $ len ) { if ( ']' === $ sequence [ $ i ] ) { return $ output ; } if ( ',' === $ sequence [ $ i ] || ' ' === $ sequence [ $ i ] ) { ++ $ i ; continue ; } $ tag = self :: parseTag ( $ sequence , $ i , $ flags ) ; switch ( $ sequence [ $ i ] ) { case '[' : $ value = self :: parseSequence ( $ sequence , $ flags , $ i , $ references ) ; break ; case '{' : $ value = self :: parseMapping ( $ sequence , $ flags , $ i , $ references ) ; break ; default : $ isQuoted = \ in_array ( $ sequence [ $ i ] , array ( '"' , "'" ) ) ; $ value = self :: parseScalar ( $ sequence , $ flags , array ( ',' , ']' ) , $ i , null === $ tag , $ references ) ; if ( \ is_string ( $ value ) && ! $ isQuoted && false !== strpos ( $ value , ': ' ) ) { try { $ pos = 0 ; $ value = self :: parseMapping ( '{' . $ value . '}' , $ flags , $ pos , $ references ) ; } catch ( \ InvalidArgumentException $ e ) { } } -- $ i ; } if ( null !== $ tag ) { $ value = new TaggedValue ( $ tag , $ value ) ; } $ output [ ] = $ value ; ++ $ i ; } throw new ParseException ( sprintf ( 'Malformed inline YAML string: %s.' , $ sequence ) , self :: $ parsedLineNumber + 1 , null , self :: $ parsedFilename ) ; } | Parses a YAML sequence . |
1,074 | private function getPathFromArray ( $ path ) { $ paths = array ( ) ; foreach ( $ path as $ unverifiedPath ) { try { if ( $ unverifiedPath [ 0 ] !== '?' ) { $ paths = array_merge ( $ paths , $ this -> getValidPath ( $ unverifiedPath ) ) ; continue ; } $ optionalPath = ltrim ( $ unverifiedPath , '?' ) ; $ paths = array_merge ( $ paths , $ this -> getValidPath ( $ optionalPath ) ) ; } catch ( FileNotFoundException $ e ) { if ( $ unverifiedPath [ 0 ] === '?' ) { continue ; } throw $ e ; } } return $ paths ; } | Gets an array of paths |
1,075 | protected function getPath ( ) { $ default = ( file_exists ( dirname ( get_template_directory ( ) ) . '/app' ) ? dirname ( get_template_directory ( ) ) . '/app/models' : get_stylesheet_directory ( ) . '/models' ) ; $ this -> path = ( has_filter ( 'sober/models/path' ) ? apply_filters ( 'sober/models/path' , rtrim ( $ this -> path ) ) : $ default ) ; } | Get custom path |
1,076 | protected function route ( $ config ) { if ( in_array ( $ config [ 'type' ] , [ 'post-type' , 'cpt' , 'posttype' , 'post_type' ] ) ) { ( new PostType ( $ config ) ) -> run ( ) ; } if ( in_array ( $ config [ 'type' ] , [ 'taxonomy' , 'tax' , 'category' , 'cat' , 'tag' ] ) ) { ( new Taxonomy ( $ config ) ) -> run ( ) ; } } | Route to class |
1,077 | protected function expandDottedKey ( $ data ) { foreach ( $ data as $ key => $ value ) { if ( ( $ found = strpos ( $ key , '.' ) ) !== false ) { $ newKey = substr ( $ key , 0 , $ found ) ; $ remainder = substr ( $ key , $ found + 1 ) ; $ expandedValue = $ this -> expandDottedKey ( array ( $ remainder => $ value ) ) ; if ( isset ( $ data [ $ newKey ] ) ) { $ data [ $ newKey ] = array_merge_recursive ( $ data [ $ newKey ] , $ expandedValue ) ; } else { $ data [ $ newKey ] = $ expandedValue ; } unset ( $ data [ $ key ] ) ; } } return $ data ; } | Expand array with dotted keys to multidimensional array |
1,078 | public function unescapeDoubleQuotedString ( $ value ) { $ callback = function ( $ match ) { return $ this -> unescapeCharacter ( $ match [ 0 ] ) ; } ; return preg_replace_callback ( '/' . self :: REGEX_ESCAPED_CHARACTER . '/u' , $ callback , $ value ) ; } | Unescapes a double quoted string . |
1,079 | protected function setDefaultLabels ( ) { $ this -> labels = [ 'name' => _x ( $ this -> many , 'Post type general name' , $ this -> i18n ) , 'singular_name' => _x ( $ this -> one , 'Post type singular name' , $ this -> i18n ) , 'menu_name' => _x ( $ this -> many , 'Admin Menu text' , $ this -> i18n ) , 'name_admin_bar' => _x ( $ this -> one , 'Add New on Toolbar' , $ this -> i18n ) , 'add_new_item' => __ ( 'Add New ' . $ this -> one , $ this -> i18n ) , 'edit_item' => __ ( 'Edit ' . $ this -> one , $ this -> i18n ) , 'new_item' => __ ( 'New ' . $ this -> one , $ this -> i18n ) , 'view_item' => __ ( 'View ' . $ this -> one , $ this -> i18n ) , 'view_items' => __ ( 'View ' . $ this -> many , $ this -> i18n ) , 'search_items' => __ ( 'Search ' . $ this -> many , $ this -> i18n ) , 'not_found' => __ ( 'No ' . strtolower ( $ this -> many ) . ' found.' , $ this -> i18n ) , 'not_found_in_trash' => __ ( 'No ' . strtolower ( $ this -> many ) . ' found in Trash.' , $ this -> i18n ) , 'parent_item_colon' => __ ( 'Parent ' . $ this -> many . ':' , $ this -> i18n ) , 'all_items' => __ ( 'All ' . $ this -> many , $ this -> i18n ) , 'archives' => __ ( $ this -> one . ' Archives' , $ this -> i18n ) , 'attributes' => __ ( $ this -> one . ' Attributes' , $ this -> i18n ) , 'insert_into_item' => __ ( 'Insert into ' . strtolower ( $ this -> one ) , $ this -> i18n ) , 'uploaded_to_this_item' => __ ( 'Uploaded to this ' . strtolower ( $ this -> one ) , $ this -> i18n ) , 'filter_items_list' => __ ( 'Filter ' . strtolower ( $ this -> many ) . ' list' , $ this -> i18n ) , 'items_list_navigation' => __ ( $ this -> many . ' list navigation' , $ this -> i18n ) , 'items_list' => __ ( $ this -> many . ' list' , $ this -> i18n ) ] ; return $ this ; } | Set default labels |
1,080 | public function getUserAgent ( ) : string { $ userAgent = '' ; foreach ( $ this -> userAgentHeaders as $ header ) { if ( array_key_exists ( $ header , $ this -> source ) && $ this -> source [ $ header ] ) { $ userAgent = $ this -> cleanParam ( $ this -> source [ $ header ] ) ; break ; } } return $ userAgent ; } | detect the useragent |
1,081 | public static function getAllPatternCacheSubkeys ( ) : array { $ subkeys = [ ] ; $ chars = [ '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'a' , 'b' , 'c' , 'd' , 'e' , 'f' ] ; foreach ( $ chars as $ charOne ) { foreach ( $ chars as $ charTwo ) { $ subkeys [ $ charOne . $ charTwo ] = '' ; } } return $ subkeys ; } | Gets all subkeys for the pattern cache files |
1,082 | public static function getAllIniPartCacheSubKeys ( ) : array { $ subKeys = [ ] ; $ chars = [ '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'a' , 'b' , 'c' , 'd' , 'e' , 'f' ] ; foreach ( $ chars as $ charOne ) { foreach ( $ chars as $ charTwo ) { foreach ( $ chars as $ charThree ) { $ subKeys [ ] = $ charOne . $ charTwo . $ charThree ; } } } return $ subKeys ; } | Gets all sub keys for the inipart cache files |
1,083 | public static function createDefaultLogger ( OutputInterface $ output ) : LoggerInterface { $ logger = new Logger ( 'browscap' ) ; $ consoleLogger = new ConsoleLogger ( $ output ) ; $ psrHandler = new PsrHandler ( $ consoleLogger ) ; $ logger -> pushHandler ( $ psrHandler ) ; $ memoryProcessor = new MemoryUsageProcessor ( true ) ; $ logger -> pushProcessor ( $ memoryProcessor ) ; $ peakMemoryProcessor = new MemoryPeakUsageProcessor ( true ) ; $ logger -> pushProcessor ( $ peakMemoryProcessor ) ; ErrorHandler :: register ( $ logger ) ; return $ logger ; } | creates a \ Monolog \ Logger instance |
1,084 | public function convertFile ( string $ iniFile ) : void { if ( empty ( $ iniFile ) ) { throw new FileNameMissingException ( 'the file name can not be empty' ) ; } if ( ! is_readable ( $ iniFile ) ) { throw new FileNotFoundException ( 'it was not possible to read the local file ' . $ iniFile ) ; } $ iniString = file_get_contents ( $ iniFile ) ; if ( false === $ iniString ) { throw new ErrorReadingFileException ( 'an error occured while converting the local file into the cache' ) ; } $ this -> convertString ( $ iniString ) ; } | reads and parses an ini file and writes the results into the cache |
1,085 | public function fetch ( string $ file , string $ remoteFile = IniLoaderInterface :: PHP_INI ) : void { try { $ cachedVersion = $ this -> checkUpdate ( ) ; } catch ( NoNewVersionException $ e ) { return ; } catch ( NoCachedVersionException $ e ) { $ cachedVersion = 0 ; } $ this -> logger -> debug ( 'started fetching remote file' ) ; $ loader = new IniLoader ( ) ; $ loader -> setRemoteFilename ( $ remoteFile ) ; $ uri = $ loader -> getRemoteIniUrl ( ) ; try { $ response = $ this -> client -> request ( 'get' , $ uri , [ 'connect_timeout' => $ this -> connectTimeout ] ) ; } catch ( \ GuzzleHttp \ Exception \ GuzzleException $ e ) { throw new FetcherException ( sprintf ( 'an error occured while fetching remote data from URI %s' , $ uri ) , 0 , $ e ) ; } if ( 200 !== $ response -> getStatusCode ( ) ) { throw new FetcherException ( sprintf ( 'an error occured while fetching remote data from URI %s: StatusCode was %d' , $ uri , $ response -> getStatusCode ( ) ) ) ; } try { $ content = $ response -> getBody ( ) -> getContents ( ) ; } catch ( \ Exception $ e ) { throw new FetcherException ( 'an error occured while fetching remote data' , 0 , $ e ) ; } if ( empty ( $ content ) ) { $ error = error_get_last ( ) ; throw FetcherException :: httpError ( $ uri , $ error [ 'message' ] ) ; } $ this -> logger -> debug ( 'finished fetching remote file' ) ; $ this -> logger -> debug ( 'started storing remote file into local file' ) ; $ content = $ this -> sanitizeContent ( $ content ) ; $ converter = new Converter ( $ this -> logger , $ this -> cache ) ; $ iniVersion = $ converter -> getIniVersion ( $ content ) ; if ( $ iniVersion > $ cachedVersion ) { $ fs = new Filesystem ( ) ; $ fs -> dumpFile ( $ file , $ content ) ; } $ this -> logger -> debug ( 'finished storing remote file into local file' ) ; } | fetches a remote file and stores it into a local folder |
1,086 | public function update ( string $ remoteFile = IniLoaderInterface :: PHP_INI ) : void { $ this -> logger -> debug ( 'started fetching remote file' ) ; try { $ cachedVersion = $ this -> checkUpdate ( ) ; } catch ( NoNewVersionException $ e ) { return ; } catch ( NoCachedVersionException $ e ) { $ cachedVersion = 0 ; } $ loader = new IniLoader ( ) ; $ loader -> setRemoteFilename ( $ remoteFile ) ; $ uri = $ loader -> getRemoteIniUrl ( ) ; try { $ response = $ this -> client -> request ( 'get' , $ uri , [ 'connect_timeout' => $ this -> connectTimeout ] ) ; } catch ( \ GuzzleHttp \ Exception \ GuzzleException $ e ) { throw new FetcherException ( sprintf ( 'an error occured while fetching remote data from URI %s' , $ uri ) , 0 , $ e ) ; } if ( 200 !== $ response -> getStatusCode ( ) ) { throw new FetcherException ( sprintf ( 'an error occured while fetching remote data from URI %s: StatusCode was %d' , $ uri , $ response -> getStatusCode ( ) ) ) ; } try { $ content = $ response -> getBody ( ) -> getContents ( ) ; } catch ( \ Exception $ e ) { throw new FetcherException ( 'an error occured while fetching remote data' , 0 , $ e ) ; } if ( empty ( $ content ) ) { $ error = error_get_last ( ) ; throw FetcherException :: httpError ( $ uri , $ error [ 'message' ] ?? '' ) ; } $ this -> logger -> debug ( 'finished fetching remote file' ) ; $ this -> logger -> debug ( 'started updating cache from remote file' ) ; $ converter = new Converter ( $ this -> logger , $ this -> cache ) ; $ this -> storeContent ( $ converter , $ content , $ cachedVersion ) ; $ this -> logger -> debug ( 'finished updating cache from remote file' ) ; } | fetches a remote file parses it and writes the result into the cache if the local stored information are in the same version as the remote data no actions are taken |
1,087 | public function checkUpdate ( ) : ? int { $ success = null ; try { $ cachedVersion = $ this -> cache -> getItem ( 'browscap.version' , false , $ success ) ; } catch ( InvalidArgumentException $ e ) { throw new ErrorCachedVersionException ( 'an error occured while reading the data version from the cache' , 0 , $ e ) ; } if ( ! $ cachedVersion ) { throw new NoCachedVersionException ( 'there is no cached version available, please update from remote' ) ; } $ uri = ( new IniLoader ( ) ) -> getRemoteVersionUrl ( ) ; try { $ response = $ this -> client -> request ( 'get' , $ uri , [ 'connect_timeout' => $ this -> connectTimeout ] ) ; } catch ( \ GuzzleHttp \ Exception \ GuzzleException $ e ) { throw new FetcherException ( sprintf ( 'an error occured while fetching version data from URI %s' , $ uri ) , 0 , $ e ) ; } if ( 200 !== $ response -> getStatusCode ( ) ) { throw new FetcherException ( sprintf ( 'an error occured while fetching version data from URI %s: StatusCode was %d' , $ uri , $ response -> getStatusCode ( ) ) ) ; } try { $ remoteVersion = $ response -> getBody ( ) -> getContents ( ) ; } catch ( \ Throwable $ e ) { throw new FetcherException ( sprintf ( 'an error occured while fetching version data from URI %s: StatusCode was %d' , $ uri , $ response -> getStatusCode ( ) ) , 0 , $ e ) ; } if ( ! $ remoteVersion ) { throw new FetcherException ( 'could not load version from remote location' ) ; } if ( $ cachedVersion && $ remoteVersion && $ remoteVersion <= $ cachedVersion ) { throw new NoNewVersionException ( 'there is no newer version available' ) ; } $ this -> logger -> info ( 'a newer version is available, local version: ' . $ cachedVersion . ', remote version: ' . $ remoteVersion ) ; return ( int ) $ cachedVersion ; } | checks if an update on a remote location for the local file or the cache |
1,088 | public function createIniParts ( string $ content ) : \ Generator { preg_match_all ( '/(?<=\[)(?:[^\r\n]+)(?=\])/m' , $ content , $ patternPositions ) ; $ patternPositions = $ patternPositions [ 0 ] ; $ iniParts = preg_split ( '/\[[^\r\n]+\]/' , $ content ) ; if ( false === $ iniParts ) { throw new \ UnexpectedValueException ( 'an error occured while splitting content into parts' ) ; } $ contents = [ ] ; $ propertyFormatter = new PropertyFormatter ( new PropertyHolder ( ) ) ; foreach ( $ patternPositions as $ position => $ pattern ) { $ pattern = strtolower ( $ pattern ) ; $ patternhash = Pattern :: getHashForParts ( $ pattern ) ; $ subkey = SubKey :: getIniPartCacheSubKey ( $ patternhash ) ; if ( ! isset ( $ contents [ $ subkey ] ) ) { $ contents [ $ subkey ] = [ ] ; } if ( ! array_key_exists ( $ position + 1 , $ iniParts ) ) { throw new \ OutOfRangeException ( sprintf ( 'could not find position %d inside iniparts' , $ position + 1 ) ) ; } $ browserProperties = parse_ini_string ( $ iniParts [ ( $ position + 1 ) ] , false , INI_SCANNER_RAW ) ; if ( false === $ browserProperties ) { throw new \ UnexpectedValueException ( sprintf ( 'could ini parse position %d inside iniparts' , $ position + 1 ) ) ; } foreach ( array_keys ( $ browserProperties ) as $ property ) { $ browserProperties [ $ property ] = $ propertyFormatter -> formatPropertyValue ( $ browserProperties [ $ property ] , $ property ) ; } try { $ contents [ $ subkey ] [ ] = $ patternhash . "\t" . \ ExceptionalJSON \ encode ( $ browserProperties , JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP ) ; } catch ( EncodeErrorException $ e ) { throw new \ UnexpectedValueException ( 'json encoding content failed' , 0 , $ e ) ; } } unset ( $ patternPositions , $ iniParts ) ; $ subkeys = array_flip ( SubKey :: getAllIniPartCacheSubKeys ( ) ) ; foreach ( $ contents as $ subkey => $ cacheContent ) { yield $ subkey => $ cacheContent ; unset ( $ subkeys [ $ subkey ] ) ; } foreach ( array_keys ( $ subkeys ) as $ subkey ) { $ subkey = ( string ) $ subkey ; yield $ subkey => '' ; } } | Creates new ini part cache files |
1,089 | public function setRemoteFilename ( string $ name ) : void { if ( empty ( $ name ) ) { throw new Exception ( 'the filename can not be empty' , Exception :: INI_FILE_MISSING ) ; } $ this -> remoteFilename = $ name ; } | sets the name of the local ini file |
1,090 | public function getParser ( ) : ParserInterface { if ( null === $ this -> parser ) { $ patternHelper = new Parser \ Helper \ GetPattern ( $ this -> cache , $ this -> logger ) ; $ dataHelper = new Parser \ Helper \ GetData ( $ this -> cache , $ this -> logger , new Quoter ( ) ) ; $ this -> parser = new Parser \ Ini ( $ patternHelper , $ dataHelper , $ this -> formatter ) ; } return $ this -> parser ; } | returns an instance of the used parser class |
1,091 | public function getBrowser ( string $ userAgent = null ) : \ stdClass { if ( null === $ this -> cache -> getVersion ( ) ) { throw new Exception ( 'there is no active cache available, please use the BrowscapUpdater and run the update command' ) ; } if ( ! is_string ( $ userAgent ) ) { $ support = new Helper \ Support ( $ _SERVER ) ; $ userAgent = $ support -> getUserAgent ( ) ; } try { $ formatter = $ this -> getParser ( ) -> getBrowser ( $ userAgent ) ; } catch ( \ UnexpectedValueException $ e ) { $ this -> logger -> error ( sprintf ( 'could not parse useragent "%s"' , $ userAgent ) ) ; $ formatter = null ; } if ( null === $ formatter ) { $ formatter = $ this -> formatter ; } return $ formatter -> getData ( ) ; } | parses the given user agent to get the information about the browser |
1,092 | public function pregUnQuote ( string $ pattern ) : string { if ( ! preg_match ( '/[^a-z\s]/i' , $ pattern ) ) { return $ pattern ; } $ origPattern = $ pattern ; $ pattern = preg_replace ( [ '/(?<!\\\\)\\.\\*/' , '/(?<!\\\\)\\./' , '/(?<!\\\\)\\\\x/' ] , [ '\\*' , '\\?' , '\\x' ] , $ pattern ) ; if ( null === $ pattern ) { throw new \ UnexpectedValueException ( sprintf ( 'an error occured while handling pattern %s' , $ origPattern ) ) ; } $ pattern = str_replace ( [ '\\\\' , '\\+' , '\\*' , '\\?' , '\\[' , '\\^' , '\\]' , '\\$' , '\\(' , '\\)' , '\\{' , '\\}' , '\\=' , '\\!' , '\\<' , '\\>' , '\\|' , '\\:' , '\\-' , '\\.' , '\\/' , ] , [ '\\' , '+' , '*' , '?' , '[' , '^' , ']' , '$' , '(' , ')' , '{' , '}' , '=' , '!' , '<' , '>' , '|' , ':' , '-' , '.' , '/' , ] , $ pattern ) ; return $ pattern ; } | Reverts the quoting of a pattern . |
1,093 | protected function askEmail ( ) { $ email = $ this -> ask ( 'E-mail' ) ; if ( ! filter_var ( $ email , FILTER_VALIDATE_EMAIL ) ) { $ this -> error ( "'$email' is not an email address." ) ; exit ( 2 ) ; } elseif ( UserProxy :: where ( 'email' , $ email ) -> first ( ) ) { $ this -> error ( "User '$email' already exists" ) ; exit ( 3 ) ; } return $ email ; } | Asks for and validates E - mail address |
1,094 | public function registerEnumIcons ( $ enumClass , array $ icons ) { $ this -> map = array_merge ( $ this -> map , [ shorten ( $ enumClass ) => $ icons ] ) ; } | Register icon mapping for a specific enum class |
1,095 | public function icon ( Enum $ enum ) { return array_get ( $ this -> map , sprintf ( '%s.%s' , shorten ( get_class ( $ enum ) ) , $ enum -> value ( ) ) , config ( 'konekt.app_shell.icon.default' , 'default' ) ) ; } | Returns the icon for the given enum instance |
1,096 | protected function registerThirdPartyProviders ( ) { if ( 'testing' == $ this -> app -> environment ( ) || version_compare ( Application :: VERSION , '5.5.0' , '<' ) ) { $ this -> registerMenuComponent ( ) ; $ this -> registerFormComponent ( ) ; $ this -> registerFlashComponent ( ) ; $ this -> registerBreadcrumbsComponent ( ) ; $ this -> registerSluggableComponent ( ) ; } $ this -> mergeBreadCrumbsConfig ( ) ; } | Registers 3rd party providers AppShell is built on top of |
1,097 | protected function initializeMenus ( ) { foreach ( $ this -> config ( 'menu' ) as $ name => $ config ) { Menu :: create ( $ name , $ config ) ; } if ( $ appshellMenu = Menu :: get ( 'appshell' ) ) { $ crm = $ appshellMenu -> addItem ( 'crm_group' , __ ( 'CRM' ) ) ; $ crm -> addSubItem ( 'customers' , __ ( 'Customers' ) , [ 'route' => 'appshell.customer.index' ] ) -> data ( 'icon' , 'accounts-list' ) -> allowIfUserCan ( 'list customers' ) ; $ settings = $ appshellMenu -> addItem ( 'settings_group' , __ ( 'Settings' ) ) ; $ settings -> addSubItem ( 'users' , __ ( 'Users' ) , [ 'route' => 'appshell.user.index' ] ) -> data ( 'icon' , 'accounts' ) -> allowIfUserCan ( 'list users' ) ; $ settings -> addSubItem ( 'roles' , __ ( 'Permissions' ) , [ 'route' => 'appshell.role.index' ] ) -> data ( 'icon' , 'shield-security' ) -> allowIfUserCan ( 'list roles' ) ; $ settings -> addSubItem ( 'settings' , __ ( 'Settings' ) , [ 'route' => 'appshell.settings.index' ] ) -> data ( 'icon' , 'settings' ) -> allowIfUserCan ( 'list settings' ) ; } } | Initializes menus set in the configuration |
1,098 | private function registerFormComponent ( ) { $ this -> app -> register ( \ Collective \ Html \ HtmlServiceProvider :: class ) ; $ this -> concord -> registerAlias ( 'Form' , \ Collective \ Html \ FormFacade :: class ) ; $ this -> concord -> registerAlias ( 'Html' , \ Collective \ Html \ HtmlFacade :: class ) ; } | Register Laravel Collective Form Component |
1,099 | private function registerMenuComponent ( ) { $ this -> app -> register ( \ Konekt \ Menu \ MenuServiceProvider :: class ) ; $ this -> concord -> registerAlias ( 'Menu' , \ Konekt \ Menu \ Facades \ Menu :: class ) ; } | Registers Konekt Menu Component |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.