idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
42,700 | public function getExcerpt ( $ length = 200 , $ includeTitle = false , $ focus = null , $ stripFields = [ ] ) { $ title = null ; if ( $ includeTitle && $ this -> title !== null ) { $ title = Html :: trimText ( strip_tags ( $ this -> title ) , $ length ) ; $ length -= strlen ( $ title ) ; } if ( $ this -> body instanceo... | Get the excerpt of a given piece of text . |
42,701 | private function extractLocations ( array $ words , $ fulltext ) { $ locations = [ ] ; foreach ( $ words as $ word ) { $ wordLen = strlen ( $ word ) ; $ loc = stripos ( $ fulltext , $ word ) ; while ( $ loc !== false ) { $ locations [ ] = $ loc ; $ loc = stripos ( $ fulltext , $ word , $ loc + $ wordLen ) ; } } $ locat... | Find the locations of each of the words . Nothing exciting here . The array_unique is required unless you decide to make the words unique before passing in . |
42,702 | public function onKernelException ( GetResponseForExceptionEvent $ event ) { $ request = $ event -> getRequest ( ) ; $ exception = $ event -> getException ( ) ; if ( ! $ exception instanceof HttpExceptionInterface || Zone :: isBackend ( $ request ) ) { return ; } if ( $ exception -> getStatusCode ( ) !== Response :: HT... | Render the not found page if on frontend and http exception . |
42,703 | private function renderNotFound ( GetResponseForExceptionEvent $ event , $ template , array $ context = [ ] ) { try { $ html = $ this -> twig -> resolveTemplate ( $ template ) -> render ( $ context ) ; $ event -> setResponse ( new Response ( $ html , Response :: HTTP_NOT_FOUND ) ) ; } catch ( RuntimeError $ e ) { throw... | Render a not found template . |
42,704 | public function add ( $ filename , FileInterface & $ removed = null ) { $ this -> initialize ( ) ; $ file = $ this -> matcher -> getFile ( $ filename ) ; if ( ! $ this -> isStackable ( $ file ) ) { throw new FileNotStackableException ( $ file ) ; } array_unshift ( $ this -> files , $ file ) ; if ( count ( $ this ) > st... | Add a file to the stack . |
42,705 | public function delete ( $ filename ) { $ this -> initialize ( ) ; try { $ file = $ this -> matcher -> getFile ( $ filename ) ; } catch ( FileNotFoundException $ e ) { return ; } foreach ( $ this -> files as $ key => $ item ) { if ( $ item -> getFullPath ( ) === $ file -> getFullPath ( ) ) { unset ( $ this -> files [ $... | Delete a file from the stack . |
42,706 | public function contains ( $ filename ) { $ this -> initialize ( ) ; try { $ file = $ this -> matcher -> getFile ( $ filename ) ; } catch ( FileNotFoundException $ e ) { return false ; } foreach ( $ this -> files as $ item ) { if ( $ item -> getFullPath ( ) === $ file -> getFullPath ( ) ) { return true ; } } return fal... | Check if a given file is present on the stack . |
42,707 | public function isStackable ( $ filename ) { try { $ file = $ this -> matcher -> getFile ( $ filename ) ; } catch ( FileNotFoundException $ e ) { return false ; } if ( ! in_array ( $ file -> getExtension ( ) , $ this -> acceptedFileTypes ) ) { return false ; } return ! $ this -> contains ( $ file ) ; } | Check if a given file can be added to the stack . |
42,708 | private function initialize ( ) { if ( $ this -> initialized ) { return ; } if ( $ this -> session -> isStarted ( ) && $ this -> session -> get ( 'stack' ) !== null ) { $ paths = $ this -> session -> get ( 'stack' ) ; $ this -> files = $ this -> hydrateList ( $ paths ) ; } else { $ paths = $ this -> users -> getCurrent... | Initialize file list for current user either from session or database . |
42,709 | private function persist ( ) { $ items = $ this -> persistableList ( ) ; $ this -> session -> set ( 'stack' , $ items ) ; $ user = $ this -> users -> getCurrentUser ( ) ; $ user [ 'stack' ] = $ items ; $ this -> users -> saveUser ( $ user ) ; } | Persist the contents of the current stack to the session as well as the database . |
42,710 | private function hydrateList ( $ paths ) { $ files = array_filter ( array_map ( function ( $ path ) { try { return $ this -> matcher -> getFile ( $ path ) ; } catch ( FileNotFoundException $ e ) { return null ; } } , ( array ) $ paths ) ) ; $ files = array_slice ( $ files , 0 , self :: MAX_ITEMS ) ; return $ files ; } | Converts a list of paths to file objects . |
42,711 | public static function installAssets ( Event $ event , $ checkForCreateProject = true ) { global $ argv ; if ( $ checkForCreateProject && strpos ( implode ( ' ' , $ argv ) , 'create-project' ) > 0 ) { return ; } static :: runUpdateProjectFromAssets ( $ event ) ; $ syncer = DirectorySyncer :: fromEvent ( $ event ) ; $ s... | Install Bolt s assets . |
42,712 | public static function installThemesAndFiles ( Event $ event ) { $ syncer = DirectorySyncer :: fromEvent ( $ event ) ; $ syncer -> sync ( 'files' , 'files' ) ; $ syncer -> sync ( '%vendor%/bolt/themes' , 'themes' , true , [ 'base-2016' , 'base-2018' , 'skeleton' ] ) ; } | Install Bolt s default themes and files . |
42,713 | public static function configureProject ( Event $ event ) { DirectoryConfigurator :: fromEvent ( $ event ) -> run ( ) ; BundleConfigurator :: fromEvent ( $ event ) -> run ( ) ; static :: installAssets ( $ event , false ) ; } | Configures installation s directory structure and default site bundle . |
42,714 | protected function getGuzzleResponse ( Url $ url , array $ options = [ ] ) { if ( version_compare ( Client :: VERSION , '6.0.0' , '<' ) ) { $ options [ 'allow_redirects' ] = [ 'max' => 10 , ] ; $ response = $ this -> client -> get ( ( string ) $ url , $ options ) ; $ redirectUri = $ response -> getEffectiveUrl ( ) ? : ... | Execute a Guzzle request and return an API response . |
42,715 | public function execute ( array $ packages ) { if ( empty ( $ packages ) ) { throw new PackageManagerException ( 'No package specified for removal' ) ; } $ jsonFile = $ this -> getOptions ( ) -> composerJson ( ) ; $ composerJson = $ composerBackup = $ jsonFile -> parse ( ) ; $ type = $ this -> getOptions ( ) -> dev ( )... | Remove packages from the root install . |
42,716 | public function onView ( GetResponseForControllerResultEvent $ event ) { $ result = $ event -> getControllerResult ( ) ; if ( ! $ result instanceof TemplateView ) { return ; } $ response = $ this -> render ( $ result ) ; $ event -> setResponse ( $ response ) ; } | If controller result is a TemplateView convert it to a TemplateResponse . |
42,717 | public function render ( TemplateView $ view ) { $ content = $ this -> twig -> render ( $ view -> getTemplate ( ) , $ view -> getContext ( ) -> toArray ( ) ) ; $ response = new TemplateResponse ( $ view -> getTemplate ( ) , $ view -> getContext ( ) , $ content ) ; return $ response ; } | Render TemplateView to a TemplateResponse . |
42,718 | public function editlink ( $ record ) { $ perm = 'contenttype:' . $ record -> contenttype [ 'slug' ] . ':edit:' . $ record -> id ; if ( $ this -> users -> isAllowed ( $ perm ) ) { return $ this -> urlGenerator -> generate ( 'editcontent' , [ 'contenttypeslug' => $ record -> contenttype [ 'slug' ] , 'id' => $ record -> ... | Generate a backend edit link for a given record if the user has the permission |
42,719 | public function htmlLang ( ) { $ request = $ this -> requestStack -> getCurrentRequest ( ) ; $ locale = $ request ? $ request -> getLocale ( ) : $ this -> locale ; return str_replace ( '_' , '-' , $ locale ) ; } | Returns the language value for in tags where the language attribute is required . The underscore _ in the locale will be replaced with a hyphen - . |
42,720 | public function isMobileClient ( ) { $ request = $ this -> requestStack -> getCurrentRequest ( ) ; if ( $ request === null ) { return false ; } return preg_match ( '/(android|blackberry|htc|iemobile|iphone|ipad|ipaq|ipod|nokia|playbook|smartphone)/i' , $ request -> headers -> get ( 'User-Agent' ) ) ; } | Check if the page is viewed on a mobile device . |
42,721 | public function getComposerJSON ( ) { if ( ! $ this -> composerJsonLoaded && ! $ this -> composerJson ) { $ this -> composerJsonLoaded = true ; $ this -> composerJson = null ; $ jsonFile = new JsonFile ( __DIR__ . '/composer.json' ) ; if ( $ jsonFile -> exists ( ) ) { $ this -> composerJson = $ jsonFile -> read ( ) ; }... | Get the contents of the extension s composer . json file lazy - loading as needed . |
42,722 | public function setComposerConfiguration ( array $ configuration ) { $ this -> composerJsonLoaded = true ; $ this -> composerJson = null ; $ this -> composerJson = $ configuration ; return $ this -> composerJson ; } | This allows write access to the composer config allowing simulation of this feature even if the extension doesn t have a physical composer . json file . |
42,723 | public function getExtensionConfig ( ) { if ( ! is_array ( $ this -> extensionConfig ) ) { $ composerjson = $ this -> getComposerJSON ( ) ; if ( is_array ( $ composerjson ) ) { $ this -> extensionConfig = [ strtolower ( $ composerjson [ 'name' ] ) => [ 'name' => $ this -> getName ( ) , 'json' => $ composerjson , ] , ] ... | Builds an array suitable for conversion to JSON which in turn will end up in a consolidated JSON file containing the configurations of all installed extensions . |
42,724 | public function getSnippets ( ) { $ snippets = [ ] ; foreach ( $ this -> app [ 'asset.queue.snippet' ] -> getQueue ( ) as $ snippet ) { $ snippets [ ] = ( string ) $ snippet ; } return $ snippets ; } | Return the available Snippets used in \ Bolt \ Extensions . |
42,725 | public function add ( Request $ request ) { $ fileName = $ request -> request -> get ( 'filename' ) ; $ stack = $ this -> app [ 'stack' ] ; $ twig = $ this -> app [ 'twig' ] ; $ file = $ stack -> add ( $ fileName , $ removed ) ; $ type = $ file -> getType ( ) ; $ type = ! in_array ( $ type , [ 'image' , 'document' ] ) ... | Add a file to the user s stack . |
42,726 | public function show ( Request $ request ) { $ count = $ request -> query -> get ( 'count' , \ Bolt \ Stack :: MAX_ITEMS ) ; $ options = $ request -> query -> get ( 'options' ) ; if ( $ options === 'ck' ) { $ template = '@bolt/components/stack/ck.twig' ; } elseif ( $ options === 'list' ) { $ template = '@bolt/component... | Render a user s current stack . |
42,727 | public function get ( $ entity ) { $ key = $ this -> mapping [ 'fieldname' ] ; $ valueMethod = 'get' . ucfirst ( $ key ) ; $ value = $ entity -> $ valueMethod ( ) ; return $ value ; } | Reads the current value of the field from an entity and returns value . |
42,728 | protected function getStorageTypeObject ( ) { $ type = $ this -> getStorageType ( ) ; if ( is_string ( $ type ) ) { $ type = Type :: getType ( $ type ) ; } return $ type ; } | Helper method to bridge compatibility between old and new Field interfaces . Previously a string storage type was allowed whereas new behaviour is to expect a Type object . |
42,729 | public function setContenttype ( $ contenttype ) { if ( is_string ( $ contenttype ) ) { $ contenttype = $ this -> app [ 'storage' ] -> getContenttype ( $ contenttype ) ; } $ this -> contenttype = $ contenttype ; } | Set the Contenttype for the record . |
42,730 | public function getDecodedValue ( $ name ) { $ value = null ; if ( isset ( $ this -> values [ $ name ] ) ) { $ fieldtype = $ this -> fieldType ( $ name ) ; $ fieldinfo = $ this -> fieldInfo ( $ name ) ; $ allowtwig = ! empty ( $ fieldinfo [ 'allowtwig' ] ) ; switch ( $ fieldtype ) { case 'markdown' : $ value = $ this -... | Get the decoded version of a value of the current object . |
42,731 | public function preParse ( $ snippet , $ allowtwig ) { if ( ! $ allowtwig || ! preg_match ( '/[{][{%#]/' , $ snippet ) ) { return $ snippet ; } $ request = $ this -> app [ 'request_stack' ] -> getCurrentRequest ( ) ; if ( $ request && $ request -> request -> getBoolean ( '_live-editor-preview' ) ) { return $ snippet ; ... | If passed snippet contains Twig tags parse the string as Twig and return the results . |
42,732 | public function previous ( $ field = 'datepublish' , $ where = [ ] ) { list ( $ field , $ asc ) = $ this -> app [ 'storage' ] -> getSortOrder ( $ field ) ; $ operator = $ asc ? '<' : '>' ; $ order = $ asc ? ' DESC' : ' ASC' ; $ value = isset ( $ this -> values [ $ field ] ) ? $ this -> values [ $ field ] : null ; $ par... | Get the previous record . In this case previous is defined as latest one published before this one by default . You can pass a parameter like id or - title to use that as the column to sort on . |
42,733 | public function getSchemaTables ( Schema $ schema ) { $ tables = [ ] ; foreach ( $ this -> tables -> keys ( ) as $ name ) { $ table = $ this -> tables [ $ name ] ; $ tables [ $ name ] = $ table -> buildTable ( $ schema , $ name , $ this -> charset , $ this -> collate ) ; } return $ tables ; } | Build the schema for base Bolt tables . |
42,734 | public static function service ( $ name , $ since = null , $ suggest = '' ) { if ( $ suggest && preg_match ( '/\s/' , $ suggest ) === 0 ) { $ suggest = sprintf ( "Use \$app['%s'] instead." , $ suggest ) ; } static :: warn ( sprintf ( "Accessing \$app['%s']" , $ name ) , $ since , $ suggest ) ; } | Shortcut for triggering a deprecation warning for a DI service . |
42,735 | public function onResponse ( FilterResponseEvent $ event ) { if ( ! $ event -> isMasterRequest ( ) ) { return ; } $ request = $ event -> getRequest ( ) ; if ( Zone :: isAsync ( $ request ) || $ request -> isXmlHttpRequest ( ) ) { return ; } $ response = $ event -> getResponse ( ) ; if ( $ response -> isRedirection ( ) ... | Callback for response event . |
42,736 | protected function addSnippets ( ) { $ queue = null ; foreach ( $ this -> queues as $ q ) { if ( $ q instanceof SnippetQueue ) { $ queue = $ q ; break ; } } if ( ! $ queue ) { return ; } $ generatorSnippet = ( new Snippet ( ) ) -> setLocation ( Target :: END_OF_HEAD ) -> setCallback ( '<meta name="generator" content="B... | Add base snippets to the response . |
42,737 | protected function encode ( $ str ) { $ args = func_get_args ( ) ; array_shift ( $ args ) ; $ args = array_map ( function ( $ str ) { return htmlspecialchars ( $ str , ENT_QUOTES ) ; } , $ args ) ; array_unshift ( $ args , $ str ) ; return call_user_func_array ( 'sprintf' , $ args ) ; } | Encode the snippet string and make it HTML safe . |
42,738 | protected function getTitleColumnName ( $ contentType ) { Deprecated :: method ( ) ; $ names = $ this -> getTitleColumnNames ( $ contentType ) ; return reset ( $ names ) ; } | Get the likely column name of the title . |
42,739 | public function initRendering ( ) { $ this -> register ( new Provider \ TwigServiceProvider ( ) ) -> register ( new Provider \ RenderServiceProvider ( ) ) -> register ( new Silex \ Provider \ HttpCacheServiceProvider ( ) ) ; $ this [ 'http_cache.cache_dir' ] = function ( ) { return $ this [ 'path_resolver' ] -> resolve... | Initialize the rendering providers . |
42,740 | public static function makeSafe ( $ str , $ strict = false , $ extrachars = '' ) { $ str = str_replace ( '&' , '' , $ str ) ; $ delim = '/' ; if ( $ extrachars != '' ) { $ extrachars = preg_quote ( $ extrachars , $ delim ) ; } if ( $ strict ) { $ slugify = Slugify :: create ( [ 'regexp' => '/[^a-z0-9_' . $ extracha... | Returns a safe version of the given string - basically only US - ASCII and numbers . Needed because filenames and titles and such can t use all characters . |
42,741 | public function widgets ( Environment $ env , $ location = null , $ zone = Zone :: FRONTEND , $ wrapper = 'widgetwrapper.twig' ) { if ( $ location === null && $ env -> isStrictVariables ( ) ) { throw new \ InvalidArgumentException ( 'widgets() requires a location, none given' ) ; } return $ this -> widgetQueue -> rende... | Renders a particular widget type on the given location . |
42,742 | protected function addConsoleCommand ( Command $ command ) { Deprecated :: method ( 3.0 , 'registerNutCommands' ) ; $ app = $ this -> getContainer ( ) ; $ app [ 'nut.commands.add' ] ( $ command ) ; } | Add a console command . |
42,743 | public function editable ( $ html , Content $ content , $ field ) { $ contentTypeName = $ content -> contenttype [ 'slug' ] ; $ output = sprintf ( '<div class="Bolt-editable" data-id="%s" data-contenttype="%s" data-field="%s">%s</div>' , $ content -> id , $ contentTypeName , $ field , $ html ) ; return $ output ; } | Makes a piece of HTML editable . |
42,744 | public function markdown ( $ content ) { $ output = $ this -> markdown -> text ( $ content ) ; $ config = $ this -> config -> get ( 'general/htmlcleaner' ) ; $ allowedTags = ! empty ( $ config [ 'allowed_tags' ] ) ? $ config [ 'allowed_tags' ] : [ 'div' , 'p' , 'br' , 'hr' , 's' , 'u' , 'strong' , 'em' , 'i' , 'b' , 'l... | Formats the given string as Markdown in HTML . |
42,745 | public function menu ( Environment $ env , $ identifier = '' , $ template = '_sub_menu.twig' , $ params = [ ] ) { $ menu = $ this -> menu -> menu ( $ identifier ) ; $ context = [ 'name' => $ menu -> getName ( ) , 'menu' => $ menu -> getItems ( ) , ] ; $ context += ( array ) $ params ; return $ env -> render ( $ templat... | Output a menu . |
42,746 | public function action ( Request $ request ) { $ this -> validateCsrfToken ( ) ; $ contentType = $ request -> get ( 'contenttype' ) ; $ actionData = $ request -> get ( 'actions' ) ; if ( $ actionData === null ) { throw new \ UnexpectedValueException ( 'No content action data provided in the request.' ) ; } foreach ( $ ... | Perform an action on a ContentType record . |
42,747 | public function info ( $ package , $ bolt ) { $ url = $ this -> urls [ 'info' ] ; $ params = [ 'package' => $ package , 'bolt' => $ bolt ] ; return $ this -> execute ( $ url , $ params ) ; } | Make an extension package info request . |
42,748 | public function getResponseStrings ( ) { $ response = [ ] ; foreach ( array_keys ( $ this -> pending ) as $ tableName ) { $ message = isset ( $ this -> titles [ $ tableName ] ) ? $ this -> titles [ $ tableName ] . ' ' : '' ; if ( ! empty ( $ this -> messages [ $ tableName ] ) ) { $ message .= implode ( ', ' , $ this ->... | Get the response messages as a string . |
42,749 | public function addTitle ( $ tableName , $ title ) { $ this -> pending [ $ tableName ] = true ; $ this -> titles [ $ tableName ] = $ title ; } | Add title message . |
42,750 | public function checkDiff ( $ tableName , TableDiff $ diff ) { $ this -> diffs [ $ tableName ] = $ diff ; $ this -> getAddedColumns ( $ tableName , $ diff ) ; $ this -> getAddedIndexes ( $ tableName , $ diff ) ; $ this -> getAddedForeignKeys ( $ tableName , $ diff ) ; $ this -> getChangedColumns ( $ tableName , $ diff ... | Check a Comparator diff and store the messages that make it up . |
42,751 | private function getAddedColumns ( $ tableName , TableDiff $ diff ) { foreach ( $ diff -> addedColumns as $ col ) { $ this -> addMessage ( $ tableName , sprintf ( 'missing column `%s`' , $ col -> getName ( ) ) ) ; } } | Record added columns . |
42,752 | private function getAddedIndexes ( $ tableName , TableDiff $ diff ) { foreach ( $ diff -> addedIndexes as $ index ) { $ this -> addMessage ( $ tableName , sprintf ( 'missing index on `%s`' , implode ( ', ' , $ index -> getUnquotedColumns ( ) ) ) ) ; } } | Record added indexes . |
42,753 | private function getChangedColumns ( $ tableName , TableDiff $ diff ) { foreach ( $ diff -> changedColumns as $ col ) { $ this -> addMessage ( $ tableName , sprintf ( 'invalid column `%s`' , $ col -> oldColumnName ) ) ; } } | Record changed columns . |
42,754 | private function getChangedIndexes ( $ tableName , TableDiff $ diff ) { foreach ( $ diff -> changedIndexes as $ index ) { $ this -> addMessage ( $ tableName , sprintf ( 'invalid index on `%s`' , implode ( ', ' , $ index -> getUnquotedColumns ( ) ) ) ) ; } } | Record changed indexes . |
42,755 | private function getRemovedColumns ( $ tableName , TableDiff $ diff ) { foreach ( array_keys ( $ diff -> removedColumns ) as $ colName ) { $ this -> addMessage ( $ tableName , sprintf ( 'removed column `%s`' , $ colName ) ) ; } } | Record removed columns . |
42,756 | private function getRemovedIndexes ( $ tableName , TableDiff $ diff ) { foreach ( array_keys ( $ diff -> removedIndexes ) as $ indexName ) { $ this -> addMessage ( $ tableName , sprintf ( 'removed index `%s`' , $ indexName ) ) ; } } | Record removed indexes . |
42,757 | private function getRenamedColumns ( $ tableName , TableDiff $ diff ) { foreach ( array_keys ( $ diff -> renamedColumns ) as $ colName ) { $ this -> addMessage ( $ tableName , sprintf ( 'renamed column `%s`' , $ colName ) ) ; } } | Record renamed columns . |
42,758 | private function addForeignKeysMessage ( $ tableName , ForeignKeyConstraint $ foreignKey , $ format ) { $ this -> addMessage ( $ tableName , sprintf ( $ format , implode ( ', ' , $ foreignKey -> getUnquotedLocalColumns ( ) ) , $ foreignKey -> getForeignTableName ( ) , implode ( ', ' . $ foreignKey -> getForeignTableNam... | Add a message for a foreign key change . |
42,759 | protected function checkChangedProperties ( TableDiff $ tableDiff , array $ schemaUpdateType , $ alterName , IgnoredChange $ ignoredChange ) { foreach ( $ schemaUpdateType as $ columnName => $ changeObject ) { $ func = $ this -> paramMap [ $ alterName ] ; $ needsUnset = call_user_func ( [ $ this , $ func ] , $ changeOb... | Check individual diff properties . |
42,760 | protected function checkColumn ( Column $ column , IgnoredChange $ ignoredChange ) { if ( $ ignoredChange -> getPropertyName ( ) !== $ column -> getName ( ) ) { return false ; } return false ; } | Do checks for columns . |
42,761 | protected function checkColumnDiff ( ColumnDiff $ columnDiff , IgnoredChange $ ignoredChange ) { if ( count ( $ columnDiff -> changedProperties ) !== 1 && ! $ columnDiff -> hasChanged ( $ ignoredChange -> getPropertyName ( ) ) ) { return false ; } $ propertyName = $ columnDiff -> changedProperties [ 0 ] ; $ before = $ ... | Do checks for column diffs . |
42,762 | protected function checkIndex ( Index $ index , IgnoredChange $ ignoredChange ) { if ( $ ignoredChange -> getPropertyName ( ) !== $ index -> getName ( ) ) { return false ; } return false ; } | Do checks for indexes . |
42,763 | protected function checkForeignKeyConstraint ( ForeignKeyConstraint $ foreignKeyConstraint , IgnoredChange $ ignoredChange ) { if ( $ ignoredChange -> getPropertyName ( ) !== $ foreignKeyConstraint -> getName ( ) ) { return false ; } return false ; } | Do checks for foreignKey constraints . |
42,764 | private function chunk ( $ text , $ width ) { $ chunks = [ ] ; $ current = '' ; $ currentLength = 0 ; $ styleStack = [ ] ; $ bufferLength = mb_strwidth ( $ text ) ; for ( $ i = 0 ; $ i < $ bufferLength ; ++ $ i ) { if ( $ text [ $ i ] === "\033" ) { $ length = strpos ( $ text , 'm' , $ i ) - $ i ; $ style = substr ( $ ... | Splits buffer into parts of given width accounting for ANSI styling . |
42,765 | public static function earlyExceptionVersion ( ) { $ message = <<<EOMBolt requires PHP <u>5.5.9</u>, or higher. <br><br>You are running PHP <u>%s</u>, so Bolt will not run on your current setup.EOM ; $ message = sprintf ( $ message , htmlspecialchars ( PHP_VERSION , ENT_QUOTES ) ) ; echo sprintf ( static :: getEarlyEx... | Exception due to a PHP version being unsupported . |
42,766 | private function updateAutomatically ( ) { $ source = $ this -> event -> getComposer ( ) -> getConfig ( ) -> getConfigSource ( ) ; $ file = new JsonFile ( $ source -> getName ( ) , null , $ this -> io ) ; $ contents = $ file -> read ( ) ; $ this -> scripts = $ contents [ 'scripts' ] = $ this -> modifyScripts ( $ conten... | Update composer . json file . |
42,767 | private function showHow ( ) { if ( ! $ this -> scripts ) { $ scripts = $ this -> event -> getComposer ( ) -> getPackage ( ) -> getScripts ( ) ; $ scripts = $ this -> modifyScripts ( $ scripts ) ; } else { $ scripts = $ this -> scripts ; } $ scripts = substr ( JsonFile :: encode ( [ 'scripts' => $ scripts ] ) , 1 , - 1... | Tell users of the change and show how the composer . json file should be updated . |
42,768 | private function modifyScripts ( $ scripts ) { $ updateScripts = ( array ) $ scripts [ ScriptEvents :: POST_UPDATE_CMD ] ; $ index = array_search ( ScriptHandler :: class . '::installAssets' , $ updateScripts ) ? : 0 ; array_splice ( $ updateScripts , $ index , 1 , [ ScriptHandler :: class . '::updateProject' , ScriptH... | Add updateProject handler right before installAssets handler . |
42,769 | public function omnisearch ( Request $ request ) { $ query = $ request -> query -> get ( 'q' , '' ) ; $ records = [ ] ; $ others = [ ] ; if ( strlen ( $ query ) >= 3 ) { foreach ( $ this -> app [ 'omnisearch' ] -> query ( $ query , true ) as $ result ) { if ( isset ( $ result [ 'slug' ] ) ) { $ records [ $ result [ 'sl... | Show the Omnisearch results . |
42,770 | public function prefill ( Request $ request ) { $ choices = [ ] ; foreach ( $ this -> getOption ( 'contenttypes' ) as $ key => $ contentType ) { $ nameKey = 'contenttypes.' . $ key . '.name.plural' ; $ nameTrans = Trans :: __ ( $ nameKey , [ ] , 'contenttypes' ) ; $ name = ( $ nameTrans === $ nameKey ) ? $ contentType ... | Generate Lorem Ipsum records in the database for given ContentTypes . |
42,771 | private function getTranslationData ( MutableBag $ tr ) { $ translation = new TranslationFile ( $ this -> app , $ tr -> get ( 'domain' ) , $ tr -> get ( 'locale' ) ) ; list ( $ tr [ 'path' ] , $ tr [ 'shortPath' ] ) = $ translation -> path ( ) ; $ tr -> set ( 'writeallowed' , $ translation -> isWriteAllowed ( ) ) ; $ t... | Get the translation data . |
42,772 | private function saveTranslationFile ( $ contents , MutableBag $ tr ) { $ contents = Input :: cleanPostedData ( $ contents ) . "\n" ; $ this -> flashes ( ) -> clear ( ) ; $ file = $ this -> filesystem ( ) -> getFile ( 'bolt://' . $ tr -> get ( 'shortPath' ) ) ; try { $ file -> put ( $ contents ) ; } catch ( IOException... | Attempt to save the POST data for a translation file edit . |
42,773 | public function whitelistParameters ( array $ queryParams , Repository $ repo ) { $ metadata = $ repo -> getClassMetadata ( ) ; $ allowedParams = array_keys ( $ metadata -> getFieldMappings ( ) ) ; $ cleanParams = [ ] ; foreach ( $ queryParams as $ fieldSelect => $ valueSelect ) { $ stack = [ ] ; if ( is_string ( $ val... | This block is added to deal with the possibility that a requested filter is not an allowable option on the database table . If the requested field filter is not a valid field on this table then we completely skip the query because no results will be expected if the field does not exist . The exception to this is if the... |
42,774 | public static function catchFatalErrorsEarly ( ) { $ error = error_get_last ( ) ; if ( ( $ error [ 'type' ] === E_ERROR || $ error [ 'type' ] === E_PARSE ) ) { echo nl2br ( str_replace ( dirname ( dirname ( __DIR__ ) ) , '' , $ error [ 'message' ] ) ) ; } } | Catch and display errors that occur before the Application object has been instantiated . |
42,775 | private static function cleanHTML ( $ output ) { $ output = preg_replace ( '/<title>.*<\/title>/smi' , '' , $ output ) ; $ output = preg_replace ( '/<style>.*<\/style>/smi' , '' , $ output ) ; $ output = strip_tags ( $ output ) ; $ output = preg_replace ( '/(\n+)(\s+)/smi' , "\n" , $ output ) ; $ output = preg_replace ... | Remove HTML elements from the error output . |
42,776 | public function doRunScheduledJobs ( Event $ event , $ eventName ) { switch ( $ eventName ) { case CronEvents :: CRON_MINUTE : $ this -> cronMinute ( ) ; break ; case CronEvents :: CRON_HOURLY : $ this -> cronHourly ( ) ; break ; case CronEvents :: CRON_DAILY : $ this -> cronDaily ( ) ; break ; case CronEvents :: CRON_... | Process jobs . |
42,777 | private function cronMinute ( ) { $ timedRecords = $ this -> app [ 'storage.event_processor.timed' ] ; if ( $ timedRecords -> isDuePublish ( ) ) { $ this -> notify ( 'Publishing timed records' ) ; $ timedRecords -> publishTimedRecords ( ) ; } if ( $ timedRecords -> isDueHold ( ) ) { $ this -> notify ( 'De-publishing ti... | Minute by minute jobs . |
42,778 | private function cronWeekly ( ) { $ this -> app [ 'cache' ] -> flushAll ( ) ; $ this -> notify ( 'Clearing cache' ) ; $ this -> app [ 'logger.manager' ] -> trim ( 'system' ) ; $ this -> app [ 'logger.manager' ] -> trim ( 'change' ) ; $ this -> notify ( 'Trimming logs' ) ; } | Weekly jobs . |
42,779 | public function getTableName ( ) { if ( $ this -> tableName ) { return $ this -> tableName ; } return $ this -> namingStrategy -> classToTableName ( $ this -> name ) ; } | Gets the fully - qualified class name of this persistent class . |
42,780 | private function addResolvedRoute ( array $ context , $ template ) { if ( ! isset ( $ context [ 'record' ] ) ) { return ; } $ content = $ context [ 'record' ] ; $ request = $ this -> app [ 'request_stack' ] -> getCurrentRequest ( ) ; $ homepage = $ this -> getOption ( 'theme/homepage' ) ? : $ this -> getOption ( 'gener... | Update the route attributes to change the canonical URL generated . |
42,781 | protected function createFormBuilder ( $ type = FormType :: class , $ data = null , array $ options = [ ] ) { return $ this -> app [ 'form.factory' ] -> createBuilder ( $ type , $ data , $ options ) ; } | Returns a form builder . |
42,782 | protected function validateCsrfToken ( $ value = null , $ id = 'bolt' ) { if ( ! $ this -> isCsrfTokenValid ( $ value , $ id ) ) { $ this -> abort ( Response :: HTTP_BAD_REQUEST , Trans :: __ ( 'general.phrase.something-went-wrong' ) ) ; } } | Validates CSRF token and throws HttpException if not . |
42,783 | protected function isCsrfTokenValid ( $ value = null , $ id = 'bolt' ) { $ token = new CsrfToken ( $ id , $ value ? : $ this -> app [ 'request_stack' ] -> getCurrentRequest ( ) -> get ( 'bolt_csrf_token' ) ) ; return $ this -> app [ 'csrf' ] -> isTokenValid ( $ token ) ; } | Check if csrf token is valid . |
42,784 | protected function hasUsers ( ) { try { $ users = $ this -> app [ 'users' ] -> getUsers ( ) ; if ( empty ( $ users ) ) { return false ; } return true ; } catch ( TableNotFoundException $ e ) { return false ; } } | Check to see if the user table exists and has records . |
42,785 | protected function getUser ( $ userId = null ) { if ( $ userId === null ) { if ( $ this -> session ( ) -> isStarted ( ) && $ sessionAuth = $ this -> session ( ) -> get ( 'authentication' ) ) { return $ sessionAuth -> getUser ( ) ; } return false ; } $ repo = $ this -> storage ( ) -> getRepository ( Entity \ Users :: cl... | Return current user or user by ID . |
42,786 | protected function getContentTypeUserPermissions ( $ contentTypeSlug , $ user = null ) { if ( $ user === null ) { return $ this -> app [ 'permissions' ] -> getContentTypePermissions ( ) ; } return $ this -> app [ 'permissions' ] -> getContentTypeUserPermissions ( $ contentTypeSlug , $ user ) ; } | Helper to get a user s permissions for a ContentType . |
42,787 | protected function getRefererQueryParameters ( Request $ request ) { $ referer = $ request -> server -> get ( 'HTTP_REFERER' ) ; $ request = Request :: create ( $ referer ) ; return ( array ) $ request -> query -> getIterator ( ) ; } | Get an array of query parameters used in the request . |
42,788 | public function handle ( $ path , $ width , $ height , $ action ) { $ file = $ this -> filesystem -> getFile ( $ path ) ; return $ this -> urlGenerator -> generate ( 'thumb' , [ 'width' => $ width , 'height' => $ height , 'action' => $ action [ 0 ] , 'file' => $ file -> getPath ( ) , ] ) ; } | Generate thumbnail url . |
42,789 | public function checks ( ) { foreach ( $ this -> check as $ checkName => $ className ) { $ this -> getValidator ( $ className , $ checkName ) -> check ( ) ; } } | Run system installation checks . |
42,790 | private function getValidator ( $ className , $ constructorArgs ) { $ validator = is_string ( $ className ) ? new $ className ( $ constructorArgs ) : $ className ; if ( ! $ validator instanceof ValidationInterface ) { throw new BootException ( sprintf ( 'System validator was given a validation class %s that does not im... | Get a validator object from a given class name . |
42,791 | public function onResponse ( FilterResponseEvent $ event ) { $ request = $ event -> getRequest ( ) ; if ( $ request -> isMethodSafe ( false ) ) { return ; } $ route = $ request -> attributes -> get ( '_internal_route' , $ request -> attributes -> get ( '_route' ) ) ; if ( ! in_array ( $ route , $ this -> routes ) ) { r... | Add X - XSS - Protection header if route matches request is unsafe and response has body . |
42,792 | protected function setupDefaults ( ) { $ this -> addHandler ( 'select' , new SelectQueryHandler ( ) ) ; $ this -> addHandler ( 'search' , new SearchQueryHandler ( ) ) ; $ this -> addHandler ( 'random' , new RandomQueryHandler ( ) ) ; $ this -> addHandler ( 'first' , new FirstQueryHandler ( ) ) ; $ this -> addHandler ( ... | Internal method to initialise the default handlers . |
42,793 | protected function parseContent ( ) { $ contentString = strtok ( $ this -> query , '/' ) ; $ content = [ ] ; $ delim = '(),' ; $ tok = strtok ( $ contentString , $ delim ) ; while ( $ tok !== false ) { $ content [ ] = $ tok ; $ tok = strtok ( $ delim ) ; } $ this -> contentTypes = $ content ; } | Parses the content area of the query string . |
42,794 | protected function parseOperation ( ) { $ operation = 'select' ; $ queryParts = explode ( '/' , $ this -> query ) ; array_shift ( $ queryParts ) ; if ( ! count ( $ queryParts ) ) { $ this -> operation = $ operation ; return ; } if ( in_array ( $ queryParts [ 0 ] , $ this -> operations , true ) ) { $ operation = array_s... | Internal method that takes the query part of the input and parses it into one of the various operations supported . |
42,795 | protected function parseDirectives ( ) { $ this -> directives = [ ] ; if ( ! $ this -> params ) { return ; } foreach ( $ this -> params as $ key => $ value ) { if ( $ this -> hasDirectiveHandler ( $ key ) ) { $ this -> directives [ $ key ] = $ value ; unset ( $ this -> params [ $ key ] ) ; } } } | Directives are all of the other parameters supported by Bolt that do not relate to an actual filter query . Some examples include printquery limit order or returnsingle . |
42,796 | public function runDirectives ( QueryInterface $ query , array $ skipDirective = [ ] ) { foreach ( $ this -> directives as $ key => $ value ) { if ( in_array ( $ key , $ skipDirective , true ) ) { continue ; } if ( ! $ this -> hasDirectiveHandler ( $ key ) ) { continue ; } if ( is_callable ( $ this -> getDirectiveHandl... | This runs the callbacks attached to each directive command . |
42,797 | public function getDirective ( $ key ) { if ( array_key_exists ( $ key , $ this -> directives ) ) { return $ this -> directives [ $ key ] ; } return null ; } | Returns a directive from the parsed list . |
42,798 | public function addDirectiveHandler ( $ key , callable $ callback = null ) { if ( ! array_key_exists ( $ key , $ this -> directiveHandlers ) ) { $ this -> directiveHandlers [ $ key ] = $ callback ; } } | Adds a handler for the named directive . |
42,799 | public function addHandler ( $ operation , callable $ callback ) { $ this -> handlers [ $ operation ] = $ callback ; $ this -> addOperation ( $ operation ) ; } | Adds a handler AND operation for the named operation . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.