idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
21,500 | public function check ( EventInterface $ event ) { $ result = $ event -> getResult ( ) ; if ( ! $ result instanceof ViewModel ) { return ; } $ request = $ event -> getRequest ( ) ; if ( $ request -> isXmlHttpRequest ( ) ) { $ result -> setTerminal ( true ) ; $ event -> setViewModel ( $ result ) ; } } | Check for XmlHttpRequest |
21,501 | public function sendMessage ( $ recipients , $ sender , $ subject , $ content ) { $ this -> client -> sendMessage ( $ this -> createMessage ( $ recipients , $ sender , $ subject , $ content ) ) ; } | Send a transactional message . |
21,502 | public function setCallback ( $ callback ) { if ( ! is_callable ( $ callback ) ) { throw new Exception \ InvalidArgumentException ( 'Invalid callback provided' ) ; } $ this -> options [ 'callback' ] = $ callback ; return $ this ; } | Sets the callback to use |
21,503 | public function convertMicrosecondsToTime ( $ time ) { $ ratio = intval ( $ time / $ this -> dayLengthInSeconds ) ; $ timeScale = array_product ( $ this -> ranges ) ; if ( $ this -> dayLengthInMicroSeconds !== $ timeScale ) { $ time = intval ( ( $ time * $ timeScale ) / $ this -> dayLengthInMicroSeconds ) ; } $ len = count ( $ this -> ranges ) ; $ res = array_fill ( 0 , $ len , 0 ) ; for ( $ i = $ len - 1 ; $ i > - 1 ; $ i -- ) { $ res [ $ i ] = $ time % $ this -> ranges [ $ i ] ; $ time = intval ( $ time / $ this -> ranges [ $ i ] ) ; } return new TimeObject ( $ res , $ this -> ranges , $ ratio ) ; } | Convert a time expressed in microseconds into a Time object . |
21,504 | public function convertTimeToMicroseconds ( TimeObject $ time ) { $ meaningfull = $ time -> countMeaningfull ( ) > 0 ; if ( ! $ meaningfull && null !== $ ratio = $ time -> getRatio ( ) ) { return $ ratio * $ this -> dayLengthInSeconds ; } if ( ! $ meaningfull && null !== $ swatch = $ time -> getTransversal ( 0 ) ) { return $ swatch * 1000 * 86400 - 3600 * 1000000 ; } $ len = count ( $ this -> ranges ) ; $ res = 0 ; for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { $ res = $ res * $ this -> ranges [ $ i ] + ( int ) $ time -> get ( $ i ) ; } $ timeScale = array_product ( $ this -> ranges ) ; if ( $ this -> dayLengthInMicroSeconds !== $ timeScale ) { return intval ( ( $ res * $ this -> dayLengthInMicroSeconds ) / $ timeScale ) ; } return $ res ; } | Converts a Time into its value in its lower unit . |
21,505 | public static function make ( array $ server = null ) { if ( empty ( $ server ) ) { $ server = $ _SERVER ; } if ( isset ( $ server [ 'REQUEST_URI' ] ) ) { return parse_url ( $ server [ 'REQUEST_URI' ] , PHP_URL_PATH ) ; } } | Makes a string with Uri path . |
21,506 | public function robots ( $ entity ) { $ robots = [ ] ; $ index = ( bool ) Configure :: read ( 'Settings.Cms.SEO.meta-robots-index' ) ; if ( $ entity -> meta_robots_index !== null ) { $ index = $ entity -> meta_robots_index ; } $ robots [ ] = ( $ index ) ? 'index' : 'noindex' ; $ follow = ( bool ) Configure :: read ( 'Settings.Cms.SEO.meta-robots-follow' ) ; if ( $ entity -> meta_robots_follow !== null ) { $ follow = $ entity -> meta_robots_follow ; } $ robots [ ] = ( $ follow ) ? 'follow' : 'nofollow' ; $ noodp = ( bool ) Configure :: read ( 'Settings.Cms.SEO.meta-robots-noodp' ) || ! empty ( $ entity -> meta_description ) ; if ( $ noodp ) { $ robots [ ] = 'noodp' ; } return $ this -> _render ( self :: ATTR_NAME , __FUNCTION__ , join ( ',' , $ robots ) ) ; } | Render the robots meta tag . |
21,507 | public function opengraph ( $ entity ) { $ attributes = [ 'og:locale' => Wasabi :: contentLanguage ( ) -> lang , 'og:type' => $ entity -> attributes [ 'og:type' ] ?? 'article' , 'og:title' => $ this -> _getTitle ( $ entity ) , 'og:description' => $ entity -> attributes [ 'og:description' ] ?? $ entity -> meta_description , 'og:url' => Router :: url ( null , true ) , 'og:site_name' => Configure :: read ( 'Settings.Cms.SEO.application-name' ) ] ; if ( $ entity -> displayMetaDates ) { $ attributes [ 'og:updated_time' ] = $ entity -> modified -> format ( 'c' ) ; } $ fbPageId = Configure :: read ( 'Settings.Cms.SEO.Social.facebook_page_id' ) ; if ( $ fbPageId !== null ) { $ attributes [ 'fb:admins' ] = $ fbPageId ; } $ out = '' ; foreach ( $ attributes as $ property => $ content ) { if ( $ property === 'og:title' ) { $ out .= $ this -> _render ( self :: ATTR_PROP , $ property , $ content , self :: ATTR_NAME , 'dcterms.title' ) ; } else { $ out .= $ this -> _render ( self :: ATTR_PROP , $ property , $ content ) ; } } return $ out ; } | Render all og meta tags . |
21,508 | public function twitter ( $ entity ) { $ twitterName = Configure :: read ( 'Settings.Cms.SEO.Social.twitter_username' ) ; if ( $ twitterName !== null ) { $ twitterName = '@' . $ twitterName ; } $ attributes = [ 'twitter:card' => 'summary' , 'twitter:title' => $ this -> _getTitle ( $ entity ) , 'twitter:description' => $ entity -> attributes [ 'og:description' ] ?? $ entity -> meta_description , 'twitter:image' => $ this -> _getSocialImage ( $ entity ) , 'twitter:site' => $ twitterName , 'twitter:creator' => $ twitterName , ] ; $ out = '' ; foreach ( $ attributes as $ property => $ content ) { $ out .= $ this -> _render ( self :: ATTR_NAME , $ property , $ content ) ; } return $ out ; } | Render all twitter tags . |
21,509 | public function article ( $ entity ) { if ( ! $ entity -> displayArticleMetaTags ) { return '' ; } $ attributes = [ 'article:publisher' => Configure :: read ( 'Settings.Cms.SEO.Social.facebook_url' ) , 'article:tag' => '' , 'article:section' => '' ] ; if ( $ entity -> displayMetaDates ) { $ attributes [ 'article:published_time' ] = ( $ entity -> published !== null ) ? $ entity -> published -> format ( 'c' ) : null ; $ attributes [ 'article:modified_time' ] = $ entity -> modified -> format ( 'c' ) ; } $ out = '' ; foreach ( $ attributes as $ property => $ content ) { $ out .= $ this -> _render ( self :: ATTR_PROP , $ property , $ content ) ; } return $ out ; } | Render all article meta tags . |
21,510 | public function dcDateIssued ( $ entity ) { if ( ! $ entity -> displayMetaDates ) { return '' ; } $ published = ( $ entity -> published !== null ) ? $ entity -> published -> format ( 'c' ) : null ; return $ this -> _render ( self :: ATTR_PROP , 'DC.date.issued' , $ published ) ; } | Render the DC . date . issued meta tag . |
21,511 | public function googleSiteVerification ( ) { $ token = Configure :: read ( 'Settings.Cms.SEO.google-site-verification' ) ; if ( empty ( $ token ) ) { return '' ; } return $ this -> _render ( self :: ATTR_NAME , 'google-site-verification' , $ token ) ; } | Render the google site verification meta tag . |
21,512 | public function displaySearchBox ( ) { $ displaySearchBox = ( bool ) Configure :: read ( 'Settings.Cms.SEO.display-search-box' ) ; if ( $ displaySearchBox ) { return '' ; } return $ this -> _render ( self :: ATTR_NAME , 'google' , 'nositelinkssearchbox' ) ; } | Render the google nositelinkssearchbox meta tag to not display a search box beneath the search engine result for your site . |
21,513 | public function ldJson ( ) { $ attributes = [ '@context' => 'http://schema.org' , '@type' => 'WebSite' , 'url' => $ this -> Url -> build ( '/' , true ) , 'potentialAction' => [ '@type' => 'SearchAction' , 'query-input' => 'required name=search_term_string' , 'target' => $ this -> Url -> build ( [ 'plugin' => 'Wasabi/Cms' , 'controller' => 'Frontend/Search' , 'action' => 'search' , 'language_id' => Wasabi :: contentLanguage ( ) -> id ] , true ) . '?q={search_term_string}' ] ] ; if ( ! empty ( WasabiCms :: $ instanceName ) ) { $ attributes [ 'name' ] = WasabiCms :: $ instanceName ; } $ sameAsKeys = [ 'Settings.Cms.SEO.Social.facebook_url' , 'Settings.Cms.SEO.Social.instagram_url' , 'Settings.Cms.SEO.Social.linkedin_url' , 'Settings.Cms.SEO.Social.myspace_url' , 'Settings.Cms.SEO.Social.pinterest_url' , 'Settings.Cms.SEO.Social.youtube_url' , 'Settings.Cms.SEO.Social.googleplus_url' ] ; $ sameAs = [ ] ; foreach ( $ sameAsKeys as $ key ) { $ setting = Configure :: read ( $ key ) ; if ( ! empty ( $ setting ) ) { $ sameAs [ ] = $ setting ; } } $ twitterName = Configure :: read ( 'Settings.Cms.SEO.Social.twitter_username' ) ; if ( ! empty ( $ twitterName ) ) { $ sameAs [ ] = 'https://twitter.com/' . $ twitterName ; } if ( ! empty ( $ sameAs ) ) { $ attributes [ 'sameAs' ] = $ sameAs ; } return '<script type="application/ld+json">' . json_encode ( $ attributes ) . '</script>' ; } | Render the ld + json script tag to set the schema . org context for a page . |
21,514 | public function createDirectory ( $ directory ) { $ parent = dirname ( $ directory ) ; if ( ! $ this -> directoryExists ( $ parent ) ) { $ this -> createDirectory ( $ parent ) ; } if ( ftp_mkdir ( $ this -> connection ( ) , $ directory ) === false ) { throw new \ RuntimeException ( sprintf ( 'Could not create directory \'%s\'.' , $ directory ) ) ; } return true ; } | Creates the specified directory recursively |
21,515 | public static function getDocumentRoot ( ) { if ( null === self :: $ docRoot ) { self :: $ docRoot = System :: realPath ( $ _SERVER [ 'DOCUMENT_ROOT' ] ) ; if ( ! self :: $ docRoot ) { self :: $ docRoot = System :: realPath ( getcwd ( ) ) ; } } return self :: $ docRoot ; } | Returns the website s document root if found or current directory . The path is always absolute . |
21,516 | public static function getMethod ( ) { if ( null === self :: $ method ) { self :: $ method = @ strtoupper ( $ _SERVER [ 'REQUEST_METHOD' ] ) ; if ( ! self :: $ method || ! ctype_upper ( self :: $ method ) ) { self :: $ method = '' ; } } return self :: $ method ; } | Returns the method of this request . In the case of HTTP this might be GET POST HEAD etc . |
21,517 | public static function getLanguages ( ) { if ( null === self :: $ languages ) { $ pattern = '/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i' ; $ languages = explode ( ',' , @ trim ( $ _SERVER [ 'HTTP_USER_AGENT' ] ) ) ; $ matches = array ( ) ; if ( preg_match ( $ pattern , $ languages , $ matches ) && 0 < count ( $ matches [ 1 ] ) ) { self :: $ languages = array_combine ( $ matches [ 1 ] , $ matches [ 4 ] ) ; } else { self :: $ languages = [ ] ; } } return self :: $ languages ; } | Returns a list of detected languages that the user - agent currently supports . The accuracy of this list is on par with that of the relevant header sent by the remote browser . |
21,518 | public static function getParams ( array $ methods = null ) { if ( null === $ methods ) { $ methods = [ self :: getMethod ( ) ] ; } $ params = [ ] ; if ( $ methods ) { $ methods = array_flip ( array_flip ( $ methods ) ) ; foreach ( $ methods as $ method ) { switch ( strtoupper ( $ method ) ) { case 'GET' : $ params = array_merge ( $ params , $ _GET ) ; break ; case 'POST' : $ params = array_merge ( $ params , $ _POST ) ; break ; } } } return $ params ; } | Returns a list of parameters associated with the last request . |
21,519 | public static function getContentType ( ) { if ( null === self :: $ contentType ) { self :: $ contentType = @ trim ( $ _SERVER [ 'HTTP_CONTENT_TYPE' ] ) ; if ( ! self :: $ contentType ) { self :: $ contentType = @ trim ( $ _SERVER [ 'CONTENT_TYPE' ] ) ; if ( ! self :: $ contentType ) { self :: $ contentType = false ; } } } return self :: $ contentType ; } | Returns the request s content type as supplied by remote user agent . If none was detected FALSE is returned . |
21,520 | public function range ( $ from , $ to , $ condition = true ) { $ range = new Range ( $ this , ! $ condition ) ; $ range -> setFrom ( $ from ) ; $ range -> setTo ( $ to ) ; return $ range ; } | Returns a Range predicate for the current field |
21,521 | public function post ( string $ url , array $ params = [ ] ) { return $ this -> send ( 'POST' , $ url , [ $ this -> bodyFormat => $ params , ] ) ; } | Executes a POST . |
21,522 | public function patch ( string $ url , array $ params = [ ] ) { return $ this -> send ( 'PATCH' , $ url , [ $ this -> bodyFormat => $ params , ] ) ; } | Executes a PATCH . |
21,523 | public function put ( string $ url , array $ params = [ ] ) { return $ this -> send ( 'PUT' , $ url , [ $ this -> bodyFormat => $ params , ] ) ; } | Executes a PUT . |
21,524 | public function send ( string $ method , string $ url , array $ options ) { try { $ optionsPayload = $ this -> mergeOptions ( [ 'query' => $ this -> parseQueryParams ( $ url ) ] , $ options ) ; $ response = $ this -> buildClient ( ) -> request ( $ method , $ url , $ optionsPayload ) ; return $ this -> buildResponse ( $ response ) ; } catch ( GuzzleException $ exception ) { throw $ exception ; } } | Build the client and send the request . |
21,525 | protected function parseQueryParams ( $ url ) { $ queries = [ ] ; $ querySegment = \ parse_url ( $ url , PHP_URL_QUERY ) ; \ parse_str ( $ querySegment , $ queries ) ; return $ queries ; } | Extracts query params into an array . |
21,526 | public function showAction ( MenuItem $ menuItem ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ deleteForm = $ this -> createDeleteForm ( $ menuItem ) ; return array ( 'entity' => $ menuItem , 'delete_form' => $ deleteForm -> createView ( ) , ) ; } | Finds and displays a MenuItem entity . |
21,527 | public function process ( ) { $ logger = $ this -> getLogger ( ) ; $ logger -> log ( "Starting...\n" ) ; $ formatter = $ this -> createFormatter ( ) ; $ parser = $ this -> createParser ( ) ; $ outputDir = $ this -> configuration -> get ( 'output' ) ; $ sources = $ this -> configuration -> getSources ( ) ; $ count = count ( $ sources ) ; $ logger -> log ( "Using {$outputDir} as output directory.\n\n" ) ; foreach ( $ sources as $ pinocchio ) { $ outputFile = $ outputDir . '/' . $ pinocchio -> getOutputFilename ( $ this -> configuration -> get ( 'source' ) ) ; $ logger -> log ( "Processing {$pinocchio->getTitle()} into {$outputFile}..." ) ; $ formatter -> format ( $ parser -> parse ( $ pinocchio ) , $ outputFile ) ; $ logger -> log ( " Done\n" ) ; } if ( ! $ this -> configuration -> get ( 'skipIndex' ) ) { $ logger -> log ( "\nCreating index page at {$outputDir}/index.html.\n" ) ; $ this -> createIndexFile ( $ sources , $ outputDir ) ; } $ logger -> log ( "\nFinished processing {$count} source files.\n" ) ; } | Process the source files and generate their corresponding output files . |
21,528 | public function createOutputDir ( ) { $ outputDir = $ this -> configuration -> get ( 'output' ) ; if ( ! is_writable ( $ outputDir ) ) { @ mkdir ( $ outputDir , 0777 , true ) ; if ( ! is_writable ( $ outputDir ) ) { throw new \ RuntimeException ( "Output directory {$outputDir} is not writable." ) ; } } } | Create - if needed - the output directory provided by the configuration . |
21,529 | public function getLogger ( ) { if ( $ this -> logger === null ) { if ( $ this -> configuration -> get ( 'silent' ) ) { $ this -> logger = new Logger \ NullLogger ( ) ; } else { $ loggerClass = $ this -> configuration -> get ( 'logger' ) ? : '\\Pinocchio\\Logger\\StandardLogger' ; $ loggerOpts = $ this -> configuration -> get ( 'logger_opts' ) ? : array ( ) ; $ this -> logger = new $ loggerClass ( $ loggerOpts ) ; } } return $ this -> logger ; } | Get the Logger instance . |
21,530 | public function keys ( $ search = null , bool $ strict = true ) : array { return array_keys ( $ this -> getData ( ) , $ search , $ strict ) ; } | Returns all the keys in an array |
21,531 | public function pad ( int $ length , $ value = null ) { $ this -> setData ( array_pad ( $ this -> getData ( ) , $ length , $ value ) ) ; return $ this ; } | Pads out an array to a specified length |
21,532 | public function unshift ( ... $ values ) { array_unshift ( $ this -> getData ( ) , extract ( $ values , EXTR_PREFIX_IF_EXISTS | EXTR_PREFIX_INVALID , '_collection_unshift' ) ) ; return $ this ; } | Add one or more elements to the front of the array |
21,533 | public function newAction ( Request $ request ) { $ slider = new Slider ( ) ; $ form = $ this -> createForm ( 'CoreExtraBundle\Form\SliderType' , $ slider , array ( 'uploadDir' => 'uploads/images/slider' ) ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ this -> get ( 'core_manager' ) -> cleanImageForm ( $ request -> files -> get ( 'slider' ) , $ slider ) ; $ em -> persist ( $ slider ) ; $ em -> flush ( ) ; $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , 'slider.created' ) ; return $ this -> redirectToRoute ( 'coreextra_slider_index' ) ; } return array ( 'entity' => $ slider , 'form' => $ form -> createView ( ) , ) ; } | Creates a new Slider entity . |
21,534 | public function showAction ( Slider $ slider ) { $ deleteForm = $ this -> createDeleteForm ( $ slider ) ; return array ( 'entity' => $ slider , 'delete_form' => $ deleteForm -> createView ( ) , ) ; } | Finds and displays a Slider entity . |
21,535 | public function editAction ( Request $ request , Slider $ slider ) { $ deleteForm = $ this -> createDeleteForm ( $ slider ) ; $ editForm = $ this -> createForm ( 'CoreExtraBundle\Form\SliderType' , $ slider ) ; $ editForm -> handleRequest ( $ request ) ; if ( $ editForm -> isSubmitted ( ) && $ editForm -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; if ( $ slider -> getRemoveImage ( ) ) { $ slider -> setImage ( null ) ; } $ em -> persist ( $ slider ) ; $ em -> flush ( ) ; $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , 'slider.edited' ) ; return $ this -> redirectToRoute ( 'coreextra_slider_index' ) ; } return array ( 'entity' => $ slider , 'edit_form' => $ editForm -> createView ( ) , 'delete_form' => $ deleteForm -> createView ( ) , ) ; } | Displays a form to edit an existing Slider entity . |
21,536 | private function createDeleteForm ( Slider $ slider ) { return $ this -> createFormBuilder ( ) -> setAction ( $ this -> generateUrl ( 'coreextra_slider_delete' , array ( 'id' => $ slider -> getId ( ) ) ) ) -> setMethod ( 'DELETE' ) -> getForm ( ) ; } | Creates a form to delete a Slider entity . |
21,537 | public function register ( $ id , callable $ callback , $ priority = self :: PRIO_EARLY ) { $ priority = intval ( $ priority ) ; if ( self :: PRIO_START <= $ priority && self :: PRIO_END >= $ priority ) { $ this -> registerImpl ( $ id , $ callback , $ priority ) ; } } | Registers a new shutdown callback with the specified priority . |
21,538 | public function prioritize ( $ id , $ newPriority ) { $ newPriority = intval ( $ newPriority ) ; if ( self :: PRIO_START <= $ newPriority && self :: PRIO_END >= $ newPriority ) { if ( isset ( $ this -> priorities [ $ id ] ) && $ newPriority !== ( $ priority = $ this -> priorities [ $ id ] ) ) { $ callback = $ this -> callbacks [ $ priority ] [ $ id ] ; $ this -> releaseImpl ( $ id , $ priority ) ; $ this -> registerImpl ( $ id , $ callback , $ newPriority ) ; } } } | Change a shutdown callback s priority to the specified one . |
21,539 | public function execute ( ) { if ( $ this -> priorities ) { if ( ksort ( $ this -> callbacks ) ) { foreach ( $ this -> callbacks as $ callbacks ) { foreach ( $ callbacks as $ callback ) { call_user_func ( $ callback ) ; } } } $ this -> priorities = null ; $ this -> callbacks = null ; } } | Executes the shutdown routine and call all registered callbacks in the order they were registered . You should never have to call this method in your app as the class will call it on its own . |
21,540 | private function registerImpl ( $ id , callable $ callback , $ priority ) { if ( ! isset ( $ this -> callbacks [ $ priority ] ) ) { $ this -> callbacks [ $ priority ] = [ ] ; } $ this -> priorities [ $ id ] = $ priority ; $ this -> callbacks [ $ priority ] [ $ id ] = $ callback ; } | The actual registration implementation takes place here . If you extend this class you can register the callbacks using this method . |
21,541 | private function releaseImpl ( $ id , $ priority = - 1 ) { if ( - 1 === $ priority ) { $ priority = $ this -> priorities [ $ id ] ; } unset ( $ this -> priorities [ $ id ] ) ; unset ( $ this -> callbacks [ $ priority ] [ $ id ] ) ; } | The actual deregistration implementation takes place here . If you extend this class you can deregister the callbacks using this method . |
21,542 | protected function isValidAttribute ( $ name ) { $ pattern = '~^' . self :: ATTRIBUTE_REGEX . '$~i' ; $ result = @ preg_match ( $ pattern , $ name ) ; return ( bool ) $ result ; } | validate attribute name |
21,543 | public function setAttribute ( $ name ) { if ( ! $ this -> isValidAttribute ( $ name ) ) { throw new exception \ InvalidArgumentException ( sprintf ( 'Invalid attribute name "%s"' , $ name ) ) ; } $ this -> attribute = $ name ; return $ this ; } | set attribute name |
21,544 | public function withSaveHandler ( SessionHandlerInterface $ save_handler ) : SessionMiddleware { return new SessionMiddleware ( $ save_handler , $ this -> name , $ this -> save_path , $ this -> cache_limiter , $ this -> cache_expire , $ this -> cookie_params ) ; } | Return a new session middleware using the given session save handler . |
21,545 | public function withName ( string $ name ) : SessionMiddleware { return new SessionMiddleware ( $ this -> save_handler , $ name , $ this -> save_path , $ this -> cache_limiter , $ this -> cache_expire , $ this -> cookie_params ) ; } | Return a new session middleware using the given session name . |
21,546 | public function withCacheExpire ( int $ cache_expire ) : SessionMiddleware { return new SessionMiddleware ( $ this -> save_handler , $ this -> name , $ this -> save_path , $ this -> cache_limiter , $ cache_expire , $ this -> cookie_params ) ; } | Return a new session middleware using the given session cache expire . |
21,547 | public function withCookieParams ( array $ cookie_params ) : SessionMiddleware { return new SessionMiddleware ( $ this -> save_handler , $ this -> name , $ this -> save_path , $ this -> cache_limiter , $ this -> cache_expire , $ cookie_params ) ; } | Return a new session middleware using the given session cookie params . |
21,548 | public function process ( ServerRequestInterface $ request , RequestHandlerInterface $ handler ) : ResponseInterface { if ( session_status ( ) === PHP_SESSION_DISABLED ) { throw new SessionDisabledException ; } if ( session_status ( ) === PHP_SESSION_ACTIVE ) { throw new SessionAlreadyStartedException ; } if ( ! is_null ( $ this -> save_handler ) ) session_set_save_handler ( $ this -> save_handler ) ; if ( ! is_null ( $ this -> name ) ) session_name ( $ this -> name ) ; if ( ! is_null ( $ this -> save_path ) ) session_save_path ( $ this -> save_path ) ; if ( ! is_null ( $ this -> cache_limiter ) ) session_cache_limiter ( $ this -> cache_limiter ) ; if ( ! is_null ( $ this -> cache_expire ) ) session_cache_expire ( $ this -> cache_expire ) ; if ( $ this -> cookie_params != [ ] ) $ this -> setCookieParams ( $ this -> cookie_params ) ; $ name = session_name ( ) ; $ id = $ request -> getCookieParams ( ) [ $ name ] ?? '' ; session_id ( $ id ) ; if ( session_start ( self :: SESSION_START_OPTIONS ) ) { $ request = $ request -> withAttribute ( Session :: class , new Session ( $ _SESSION ) ) ; $ response = $ handler -> handle ( $ request ) ; session_write_close ( ) ; return $ this -> attachSessionHeaders ( $ response ) ; } throw new SessionStartException ; } | Enable session for the given request handler . |
21,549 | private function setCookieParams ( array $ cookie_params ) { $ params = array_merge ( session_get_cookie_params ( ) , array_change_key_case ( $ cookie_params ) ) ; session_set_cookie_params ( $ params [ 'lifetime' ] , $ params [ 'path' ] , $ params [ 'domain' ] , $ params [ 'secure' ] , $ params [ 'httponly' ] ) ; } | Set the given session cookie params . |
21,550 | private function attachSessionHeaders ( ResponseInterface $ response ) : ResponseInterface { $ time = time ( ) ; $ response = $ this -> attachCacheLimiterHeader ( $ response , $ time ) ; $ response = $ this -> attachSessionCookie ( $ response , $ time ) ; return $ response ; } | Attach the session headers to the given response . |
21,551 | private function attachCacheLimiterHeader ( ResponseInterface $ response , int $ time ) : ResponseInterface { $ cache_limiter = session_cache_limiter ( ) ; switch ( $ cache_limiter ) { case 'public' : return $ this -> attachPublicCacheLimiterHeader ( $ response , $ time ) ; case 'private' : return $ this -> attachPrivateCacheLimiterHeader ( $ response , $ time ) ; case 'private_no_expire' : return $ this -> attachPrivateNoExpireCacheLimiterHeader ( $ response , $ time ) ; case 'nocache' : return $ this -> attachNocacheCacheLimiterHeader ( $ response ) ; default : return $ response ; } } | Attach a session cache limiter header to the given response . |
21,552 | private function attachPublicCacheLimiterHeader ( ResponseInterface $ response , int $ time ) : ResponseInterface { $ cache_expire = session_cache_expire ( ) ; $ max_age = $ cache_expire * 60 ; $ expires = gmdate ( self :: DATE_FORMAT , $ time + $ max_age ) ; $ cache_control = "public, max-age={$max_age}" ; $ last_modified = gmdate ( self :: DATE_FORMAT , $ time ) ; return $ response -> withAddedHeader ( 'Expires' , $ expires ) -> withAddedHeader ( 'Cache-Control' , $ cache_control ) -> withAddedHeader ( 'Last-Modified' , $ last_modified ) ; } | Attach a public cache limiter header to the given response . |
21,553 | private function attachPrivateCacheLimiterHeader ( ResponseInterface $ response , int $ time ) : ResponseInterface { $ response = $ response -> withAddedHeader ( 'Expires' , self :: EXPIRED ) ; return $ this -> attachPrivateNoExpireCacheLimiterHeader ( $ response , $ time ) ; } | Attach a private cache limiter header to the given response . |
21,554 | private function attachPrivateNoExpireCacheLimiterHeader ( ResponseInterface $ response , int $ time ) : ResponseInterface { $ cache_expire = session_cache_expire ( ) ; $ max_age = $ cache_expire * 60 ; $ cache_control = "private, max-age={$max_age}" ; $ last_modified = gmdate ( self :: DATE_FORMAT , $ time ) ; return $ response -> withAddedHeader ( 'Cache-Control' , $ cache_control ) -> withAddedHeader ( 'Last-Modified' , $ last_modified ) ; } | Attach a private_no_expire cache limiter header to the given response . |
21,555 | private function attachNocacheCacheLimiterHeader ( ResponseInterface $ response ) : ResponseInterface { return $ response -> withAddedHeader ( 'Expires' , self :: EXPIRED ) -> withAddedHeader ( 'Cache-Control' , 'no-store, no-cache, must-revalidate' ) -> withAddedHeader ( 'Pragma' , 'no-cache' ) ; } | Attach a nocache cache limiter header to the given response . |
21,556 | private function attachSessionCookie ( ResponseInterface $ response , int $ time ) : ResponseInterface { $ id = session_id ( ) ; $ name = session_name ( ) ; $ options = session_get_cookie_params ( ) ; $ header = urlencode ( $ name ) . '=' . urlencode ( $ id ) ; if ( $ options [ 'lifetime' ] > 0 ) { $ expires = gmdate ( self :: DATE_FORMAT , $ time + $ options [ 'lifetime' ] ) ; $ header .= "; expires={$expires}; max-age={$options['lifetime']}" ; } if ( $ options [ 'path' ] ) $ header .= "; path={$options['path']}" ; if ( $ options [ 'domain' ] ) $ header .= "; domain={$options['domain']}" ; if ( $ options [ 'secure' ] ) $ header .= '; secure' ; if ( $ options [ 'httponly' ] ) $ header .= '; httponly' ; return $ response -> withAddedHeader ( 'set-cookie' , $ header ) ; } | Attach a session cookie to the given response . |
21,557 | public static function assertIsNull ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( null === $ variable , $ exception ) ; return true ; } | Asserts that the variable is NULL . |
21,558 | public static function assertIsResource ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( \ is_resource ( $ variable ) , $ exception ) ; return true ; } | Asserts that the variable is a resource . |
21,559 | public static function assertIsNumeric ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( \ is_numeric ( $ variable ) , $ exception ) ; return true ; } | Asserts that the variable is numeric . |
21,560 | public static function assertIsObject ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( \ is_object ( $ variable ) , $ exception ) ; return true ; } | Asserts that the variable is object . |
21,561 | public static function assertIsCallable ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( \ is_callable ( $ variable ) , $ exception ) ; return true ; } | Asserts that the variable is callable . |
21,562 | public static function assertIsFloat ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( \ is_float ( $ variable ) , $ exception ) ; return true ; } | Asserts that the variable is float . |
21,563 | public static function assertIsInt ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( \ is_int ( $ variable ) , $ exception ) ; return true ; } | Asserts that the variable is an int . |
21,564 | public static function assertIsNumber ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( \ is_int ( $ variable ) || \ is_float ( $ variable ) , $ exception ) ; return true ; } | Asserts that the variable is either an integer or a float . |
21,565 | public static function assertIsString ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( \ is_string ( $ variable ) , $ exception ) ; return true ; } | Asserts that the variable is a string . |
21,566 | public static function assertIsBool ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( \ is_bool ( $ variable ) , $ exception ) ; return true ; } | Asserts that the variable is a bool . |
21,567 | public static function assertIsArray ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( \ is_array ( $ variable ) , $ exception ) ; return true ; } | Asserts that the variable is an array . |
21,568 | public static function assertIsScalar ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( \ is_scalar ( $ variable ) , $ exception ) ; return true ; } | Asserts that the variable is a scalar . |
21,569 | public static function assertIsNotNull ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( null !== $ variable , $ exception ) ; return true ; } | Asserts that the variable is not NULL . |
21,570 | public static function assertIsNotResource ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( ! \ is_resource ( $ variable ) , $ exception ) ; return true ; } | Asserts that the variable is not a resource . |
21,571 | public static function assertIsNotNumeric ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( ! \ is_numeric ( $ variable ) , $ exception ) ; return true ; } | Asserts that the variable is not numeric . |
21,572 | public static function assertIsNotObject ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( ! \ is_object ( $ variable ) , $ exception ) ; return true ; } | Asserts that the variable is not object . |
21,573 | public static function assertIsNotCallable ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( ! \ is_callable ( $ variable ) , $ exception ) ; return true ; } | Asserts that the variable is not callable . |
21,574 | public static function assertIsNotFloat ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( ! \ is_float ( $ variable ) , $ exception ) ; return true ; } | Asserts that the variable is not float . |
21,575 | public static function assertIsNotInt ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( ! \ is_int ( $ variable ) , $ exception ) ; return true ; } | Asserts that the variable is not an int . |
21,576 | public static function assertIsNotString ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( ! \ is_string ( $ variable ) , $ exception ) ; return true ; } | Asserts that the variable is not a string . |
21,577 | public static function assertIsNotBool ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( ! \ is_bool ( $ variable ) , $ exception ) ; return true ; } | Asserts that the variable is not a bool . |
21,578 | public static function assertIsNotArray ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( ! \ is_array ( $ variable ) , $ exception ) ; return true ; } | Asserts that the variable is not an array . |
21,579 | public static function assertIsNotScalar ( $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( ! \ is_scalar ( $ variable ) , $ exception ) ; return true ; } | Asserts that the variable is not a scalar . |
21,580 | public static function assertIsNotTypeOf ( array $ types , $ variable , Throwable $ exception ) : bool { static :: makeAssertion ( ! \ in_array ( \ gettype ( $ variable ) , $ types , true ) , $ exception ) ; return true ; } | Asserts that the variable is not one of the given types . |
21,581 | public function iShouldSeeInDatabaseTableFieldEquals ( $ table , $ field , $ pattern ) { $ found = Sql :: createSql ( $ this -> getAdapter ( ) ) -> select ( $ table ) -> where ( [ "{$table}.{$field} = ?" => $ pattern ] ) -> count ( ) ; Assert :: assertTrue ( $ found > 0 ) ; } | Run query where field equals provided pattern |
21,582 | public function iGetEntityWithId ( $ entityId ) { $ this -> lastEntity = $ this -> entity ; $ this -> entity = $ this -> repository -> get ( $ entityId ) ; } | Gets the entity with |
21,583 | public static function canUserRunAction ( $ actionUid , $ user = null ) { if ( empty ( $ user ) ) $ user = Yii :: $ app -> user ; $ parts = explode ( '/' , $ actionUid ) ; if ( $ parts === false || count ( $ parts ) < 3 ) { throw new Exception ( "Illegal action uniqueId format: '{$actionUid}'" ) ; } else { $ actionId = array_pop ( $ parts ) ; $ controllerId = array_pop ( $ parts ) ; $ moduleUid = implode ( '/' , $ parts ) ; $ module = Yii :: $ app -> getModule ( $ moduleUid ) ; if ( empty ( $ module ) ) { return false ; } else { $ controller = $ module -> createControllerByID ( $ controllerId ) ; if ( $ controller instanceof YiiBaseController ) { $ behaviors = $ controller -> behaviors ( ) ; if ( empty ( $ behaviors [ 'access' ] [ 'rules' ] ) ) { $ rules = [ ] ; } else { $ rules = $ behaviors [ 'access' ] [ 'rules' ] ; } } else { throw new Exception ( "Illegal controller '{$controllerId}' in module '{$moduleUid}'" ) ; } } if ( empty ( $ rules ) ) { $ result = true ; } else { $ ac = Yii :: createObject ( [ 'class' => AccessControl :: className ( ) , 'user' => $ user , 'rules' => $ rules ] ) ; $ action = $ controller -> createAction ( $ actionId ) ; $ request = Yii :: $ app -> getRequest ( ) ; $ result = false ; foreach ( $ ac -> rules as $ rule ) { if ( $ rule -> allows ( $ action , $ user , $ request ) ) { $ result = true ; break ; } } } return $ result ; } } | Check if user can run action . |
21,584 | public function addRadioButton ( RadioButtonInterface $ radioButton ) : void { $ radioButton -> setName ( $ this -> getName ( ) ) ; $ radioButton -> setSelected ( $ radioButton -> getValue ( ) === $ this -> value ) ; $ this -> radioButtons [ ] = $ radioButton ; } | Adds a radio button . |
21,585 | protected function urlFromRoute ( $ path = '' ) { $ url = $ this -> baseURL ; $ url [ ] = $ path ; if ( ! empty ( $ this -> page ) ) $ url [ ] = '?page=' . $ this -> page ; return implode ( '' , $ url ) ; } | URL From Route |
21,586 | public function validateValue ( $ value ) { $ validationResultSet = new ValidationResultSet ( ) ; foreach ( $ this -> validators as $ validator ) { $ validationResultSet -> add ( $ validator -> validate ( $ value ) ) ; } return $ validationResultSet ; } | Validates a value against all given Validators |
21,587 | public function addValidator ( Validator \ ValidatorInterface $ validator ) { $ this -> validators [ get_class ( $ validator ) ] = $ validator ; return $ this ; } | Adds a Validator to this |
21,588 | public function addValidators ( Validator \ ValidatorInterface ... $ validators ) { foreach ( $ validators as $ validator ) { $ this -> addValidator ( $ validator ) ; } return $ this ; } | Assigns several Validators that shall be used to validate this |
21,589 | protected function isMatch ( $ value , $ contextValue , $ name ) { if ( $ contextValue instanceof ToArrayInterface ) { return $ this -> isMatchAnyInArray ( $ value , $ contextValue -> toArray ( ) , $ name ) ; } return \ is_array ( $ contextValue ) ? $ this -> isMatchAnyInArray ( $ value , $ contextValue , $ name ) : $ this -> isMatchAnyWithScalar ( $ value , $ contextValue , $ name ) ; } | Checks if a value of a processor attribute matches a corresponding value from the execution context . |
21,590 | public function get ( Module $ module ) { $ moduleName = $ module -> getName ( ) ; if ( Lang :: has ( "$moduleName::module.title" ) ) { $ module -> localname = Lang :: get ( "$moduleName::module.title" ) ; } else { $ module -> localname = $ module -> getStudlyName ( ) ; } if ( Lang :: has ( "$moduleName::module.description" ) ) { $ module -> description = Lang :: get ( "$moduleName::module.description" ) ; } $ package = $ this -> packageVersion -> getPackageInfo ( "societycms/module-$moduleName" ) ; if ( isset ( $ package -> name ) && strpos ( $ package -> name , '/' ) ) { $ module -> vendor = explode ( '/' , $ package -> name ) [ 0 ] ; } $ module -> version = isset ( $ package -> version ) ? $ package -> version : 'N/A' ; $ module -> versionUrl = '#' ; $ module -> isCore = $ this -> isCoreModule ( $ module ) ; if ( isset ( $ package -> source -> url ) ) { $ packageUrl = str_replace ( '.git' , '' , $ package -> source -> url ) ; $ module -> versionUrl = $ packageUrl . '/tree/' . $ package -> dist -> reference ; } $ module -> license = $ package -> license ; return $ module ; } | Return a modules . |
21,591 | public function all ( ) { $ modules = new Collection ( $ this -> module -> all ( ) ) ; foreach ( $ modules as $ module ) { $ module = $ this -> get ( $ module ) ; } return $ modules ; } | Return all modules . |
21,592 | public function getCoreModulesByName ( ) { $ coreModules = $ this -> config -> get ( 'society.core.core.CoreModules' ) ; $ coreModules = array_flip ( $ coreModules ) ; return collect ( $ coreModules ) ; } | Get the core modules as an array of names . |
21,593 | public function isCoreModule ( Module $ module ) { $ coreModulesByName = $ this -> getCoreModulesByName ( ) ; return $ coreModulesByName -> has ( $ module -> getLowerName ( ) ) ; } | Check if the given module is a core module that should be be disabled . |
21,594 | public function getFlippedEnabledModules ( ) { $ enabledModules = $ this -> module -> enabled ( ) ; $ enabledModules = array_map ( function ( Module $ module ) { return $ module -> getName ( ) ; } , $ enabledModules ) ; return array_flip ( $ enabledModules ) ; } | Get the enabled modules with the module name as the key . |
21,595 | public function disableModules ( $ enabledModules ) { $ coreModules = $ this -> getCoreModules ( ) ; foreach ( $ enabledModules as $ moduleToDisable => $ value ) { if ( isset ( $ coreModules [ $ moduleToDisable ] ) ) { continue ; } $ module = $ this -> module -> get ( $ moduleToDisable ) ; $ module -> disable ( ) ; } } | Disable the given modules . |
21,596 | public function enableModules ( $ modules ) { foreach ( $ modules as $ moduleToEnable => $ value ) { $ module = $ this -> module -> get ( $ moduleToEnable ) ; $ module -> enable ( ) ; } } | Enable the given modules . |
21,597 | public function changelogFor ( Module $ module ) { $ path = $ module -> getPath ( ) . '/CHANGELOG.md' ; if ( ! $ this -> finder -> isFile ( $ path ) ) { return [ ] ; } $ parser = new \ Changelog \ Parser ( file_get_contents ( $ path ) ) ; return $ parser -> getReleases ( ) ; } | Get the changelog for the given module . |
21,598 | public function start ( Request $ request , AuthenticationException $ exception = null ) { if ( $ exception ) { $ message = $ exception -> getMessage ( ) ; if ( empty ( $ message ) && is_callable ( [ $ exception , 'getMessageKey' ] ) ) { $ message = $ e -> getMessageKey ( ) ; } } else { $ message = 'Full authentication is required to access this resource.' ; } $ content = [ 'errors' => [ 'code' => 401 , 'message' => $ this -> translator -> trans ( $ message , [ ] , 'errors' ) ] ] ; return new JsonResponse ( $ content , JsonResponse :: HTTP_UNAUTHORIZED ) ; } | Called when authentication is needed but it s not sent or is invalid |
21,599 | public function emit ( $ name , $ eventData = array ( ) ) { if ( ! is_array ( $ eventData ) ) { throw new \ Exception ( 'Moxy\Event data must be an array' ) ; } if ( isset ( self :: $ _events [ $ name ] ) ) { self :: $ _events [ $ name ] -> dispatch ( $ eventData ) ; } } | Emit an Event |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.