idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
900 | private function wrapEqualityCriteria ( ) { if ( $ this -> currentField && ! isset ( $ this -> query [ $ this -> currentField ] ) && ! array_key_exists ( $ this -> currentField , $ this -> query ) ) { return ; } if ( $ this -> currentField ) { $ query = & $ this -> query [ $ this -> currentField ] ; } else { $ query = & $ this -> query ; } if ( is_array ( $ query ) && ( empty ( $ query ) || strpos ( key ( $ query ) , '$' ) === 0 ) ) { return ; } $ query = array ( '$in' => array ( $ query ) ) ; } | Wraps equality criteria with an operator . |
901 | protected function sentRegistrationMail ( ) { $ emailConfig = $ this -> getConfig ( 'email' ) ; foreach ( [ 'bodyTemplate' , 'from' , 'to' , 'subject' , 'smtpOptions' ] as $ option ) { if ( ! isset ( $ emailConfig [ $ option ] ) ) { throw new InvalidArgumentException ( "Invalid '{$option}' option for email config" ) ; } } $ userId = $ this -> googleClient -> getIdToken ( ) ; $ email = $ this -> googleClient -> getUserEmail ( ) ; $ emailMessageTemplate = $ emailConfig [ 'bodyTemplate' ] ; $ emailMessage = str_replace ( [ ':email' , ':userId' ] , [ $ email , $ userId ] , $ emailMessageTemplate ) ; $ mail = new Message ( ) ; $ mail -> setBody ( $ emailMessage ) ; $ mail -> setFrom ( $ emailConfig [ 'from' ] ) ; $ mail -> setSubject ( $ emailConfig [ 'subject' ] ) ; $ mail -> addTo ( $ emailConfig [ 'to' ] ) ; $ transport = new Smtp ( ) ; $ options = new SmtpOptions ( $ emailConfig [ 'smtpOptions' ] ) ; $ transport -> setOptions ( $ options ) ; $ this -> logger -> debug ( json_encode ( [ 'Email for registration' , 'Email body: ' . $ emailMessage , 'Email from: ' . $ emailConfig [ 'from' ] , 'Email subject: ' . $ emailConfig [ 'subject' ] , 'Email to: ' . $ emailConfig [ 'to' ] , 'Email SMTP options: ' . json_encode ( $ emailConfig [ 'smtpOptions' ] ) , ] ) ) ; $ transport -> send ( $ mail ) ; } | Send email to approve registration |
902 | public function setProtectedProperty ( $ object , string $ property , $ value ) { if ( ! is_object ( $ object ) ) { $ msg = $ this -> getErrorMessage ( 1 , __METHOD__ , $ object ) ; throw new InvalidArgumentException ( $ msg ) ; } $ class = new ReflectionClass ( $ object ) ; $ property = $ class -> getProperty ( $ property ) ; $ property -> setAccessible ( true ) ; $ property -> setValue ( $ object , $ value ) ; } | Sets a protected or private property . |
903 | public function run ( ) { $ states = $ state_names = $ counties = [ ] ; $ id_states = $ id_counties = 0 ; foreach ( $ this -> data [ 'states' ] as $ state ) { $ states [ ] = sprintf ( "(%s, %s, '%s', '%s')" , ++ $ id_states , $ this -> data [ 'country' ] , $ state [ 'code' ] , str_replace ( "'" , "\\'" , $ state [ 'name' ] ) ) ; foreach ( $ state [ 'counties' ] as $ county ) { $ counties [ $ id_states ] [ ] = sprintf ( "(%s, %s, '%s')" , ++ $ id_counties , $ id_states , str_replace ( "'" , "\\'" , $ county ) ) ; } $ state_names [ $ id_states ] = $ state [ 'name' ] ; } $ count = count ( $ this -> data [ 'states' ] ) ; $ states_sql = "-- $count State" . ( $ count > 1 ? 's' : '' ) . ":\n\n" . self :: generateChunks ( 'INSERT INTO `states` (`id`, `country`, `code`, `name`) VALUES' , $ states ) ; $ counties_sql = '' ; foreach ( $ counties as $ id => $ block ) { $ counties_sql .= "-- $state_names[$id]\n\n" . self :: generateChunks ( 'INSERT INTO `counties` (`id`, `state`, `name`) VALUES' , $ block ) ; } return $ states_sql . $ counties_sql ; } | Generates SQL to populate the Address table |
904 | protected function generateChunks ( string $ stmt , array $ entries ) { $ result = '' ; foreach ( array_chunk ( $ entries , self :: CHUNK_SIZE ) as $ chunk ) { $ result .= $ stmt . "\n" . implode ( "\n" , Utils :: arrayAppendLast ( $ chunk , ";\n\n" , ',' ) ) ; } return $ result ; } | Generates chunks of entries with the same statement |
905 | public function created ( CategoryTranslation $ categoryTranslation ) { DB :: table ( 'netcore_category__category_translations' ) -> where ( 'id' , $ categoryTranslation -> id ) -> update ( [ 'full_slug' => $ categoryTranslation -> getFullSlug ( ) ] ) ; } | Listen to the CategoryTranslation created event . |
906 | public function updated ( CategoryTranslation $ categoryTranslation ) { DB :: table ( 'netcore_category__category_translations' ) -> where ( 'id' , $ categoryTranslation -> id ) -> update ( [ 'full_slug' => $ categoryTranslation -> getFullSlug ( ) ] ) ; dispatch ( new RegenerateCategoryFullSlugs ( $ categoryTranslation -> category , $ categoryTranslation -> language ) ) ; } | Listen to the CategoryTranslation updated event . |
907 | public function hydrate ( Entity & $ model ) { foreach ( $ model -> getAsserts ( ) as $ field => $ asserts ) { if ( $ this -> app [ 'request' ] -> files -> has ( $ field ) ) { $ file = $ this -> app [ 'request' ] -> files -> get ( $ field ) ; if ( $ file instanceof UploadedFile ) { $ model -> dispatch ( 'upload' , [ $ field , $ file ] ) ; } } else { $ value = trim ( $ this -> app [ 'request' ] -> get ( $ field ) ) ; if ( empty ( strip_tags ( $ value ) ) ) { $ value = '' ; } $ model -> $ field = $ value ; } } } | Hydrates a model from a request |
908 | protected function verifyMainEntries ( $ priorities , WebRequest $ request ) { foreach ( $ priorities as $ priority => $ entries ) { $ priorities [ $ priority ] = $ this -> verifyEntries ( $ entries , $ request ) ; } return $ priorities ; } | Verifies the main access levels for the given entries . |
909 | protected function verifyEntries ( $ entries , WebRequest $ request ) { foreach ( $ entries as $ key => $ entry ) { if ( $ entry instanceof \ Zepi \ Web \ General \ Entity \ ProtectedMenuEntry ) { $ result = $ this -> verifyProtectedEntry ( $ entry , $ request ) ; if ( ! $ result ) { unset ( $ entries [ $ key ] ) ; } } if ( $ entry -> hasChildren ( ) ) { $ children = $ this -> verifyEntries ( $ entry -> getChildren ( ) , $ request ) ; $ entry -> setChildren ( $ children ) ; } } return $ entries ; } | Verifies the access levels for the given entries . |
910 | protected function verifyProtectedEntry ( ProtectedMenuEntry $ protectedEntry , WebRequest $ request ) { if ( ! $ request -> hasSession ( ) ) { return false ; } if ( $ request -> hasSession ( ) && $ protectedEntry -> getAccessLevelKey ( ) === '' ) { return true ; } if ( $ request -> getSession ( ) -> hasAccess ( $ protectedEntry -> getAccessLevelKey ( ) ) ) { return true ; } return false ; } | Verifies a protected menu entry . |
911 | public static function make ( $ apiKey = null , $ registerDefaultCallback = true ) { $ config = new Config ( $ apiKey ? : getenv ( 'AFTERBUG_API_KEY' ) ) ; $ client = new static ( $ config , static :: makeGuzzle ( $ config ) ) ; if ( $ registerDefaultCallback ) { $ client -> registerDefaultCallbacks ( ) ; } return $ client ; } | Create new AfterBug instance . |
912 | public function registerCallback ( callable $ callback ) { $ this -> pipeline -> pipe ( $ callback ) -> process ( $ this -> config ) ; return $ this ; } | Register custom callback . |
913 | public function registerDefaultCallbacks ( ) { $ this -> registerCallback ( new Http ( $ this -> request ) ) -> registerCallback ( new RequestUser ( $ this -> request ) ) -> registerCallback ( new HostName ( ) ) ; return $ this ; } | Register default callbacks . |
914 | private function send ( $ data ) { if ( version_compare ( ClientInterface :: VERSION , '5' ) === 1 ) { return $ this -> guzzle -> post ( '/' , [ 'headers' => [ 'AfterBug-Token' => $ this -> config -> getApiKey ( ) , ] , 'json' => $ data , ] ) ; } return $ this -> guzzle -> request ( 'POST' , '/' , [ RequestOptions :: JSON => $ data , ] ) ; } | Send exception data to AfterBug . |
915 | public function catchException ( $ exception ) { if ( in_array ( get_class ( $ exception ) , $ this -> config -> getExcludeExceptions ( ) ) ) { return ; } try { $ this -> send ( Formatter :: make ( $ exception , $ this -> config ) -> toArray ( ) ) ; } catch ( Exception $ exception ) { error_log ( 'AfterBug Error: Couldn\'t notify. ' . $ exception -> getMessage ( ) ) ; } } | Notify AfterBug of an exception . |
916 | private function validateType ( array $ types ) : bool { $ value = $ this -> value ; $ length = \ strlen ( $ value ) ; $ foundPrefix = false ; $ foundLength = false ; foreach ( $ types as $ type ) { foreach ( $ this -> validationData [ $ type ] [ 'prefixes' ] as $ prefix ) { if ( \ substr ( $ value , 0 , \ strlen ( $ prefix ) ) == $ prefix ) { $ foundPrefix = true ; if ( \ in_array ( $ length , $ this -> validationData [ $ type ] [ 'length' ] ) ) { $ foundLength = true ; break 2 ; } } } } if ( ! $ foundPrefix ) { $ this -> setError ( self :: VALIDATOR_ERROR_CREDIT_CARD_NUMBER_PREFIX_NOT_MATCH ) ; } if ( ! $ foundLength ) { $ this -> setError ( self :: VALIDATOR_ERROR_CREDIT_CARD_NUMBER_LENGTH_NOT_MATCH ) ; } return $ foundPrefix === true && $ foundLength === true ; } | Validates credit card type |
917 | private function validateNumber ( ) : bool { $ value = $ this -> value ; $ length = \ strlen ( $ value ) ; $ sum = 0 ; $ weight = 2 ; if ( $ length < 2 ) { $ this -> setError ( self :: VALIDATOR_ERROR_CREDIT_CARD_NUMBER_NOT_VALID ) ; return false ; } for ( $ i = $ length - 2 ; $ i >= 0 ; $ i -- ) { $ digit = $ weight * $ value [ $ i ] ; $ sum += \ floor ( $ digit / 10 ) + $ digit % 10 ; $ weight = $ weight % 2 + 1 ; } if ( ( 10 - $ sum % 10 ) % 10 != $ value [ $ length - 1 ] ) { $ this -> setError ( self :: VALIDATOR_ERROR_CREDIT_CARD_NUMBER_NOT_VALID ) ; return false ; } return true ; } | Validates credit card number |
918 | public function predictException ( callable $ capture , string $ exceptionClass ) { try { call_user_func ( $ capture ) ; throw new PredictExceptionFailure ( "Capture was expected to throw '$exceptionClass' but did not." ) ; } catch ( \ Throwable $ ex ) { $ actualExceptionClass = get_class ( $ ex ) ; if ( $ actualExceptionClass === PredictExceptionFailure :: class ) { throw $ ex ; } if ( $ actualExceptionClass !== $ exceptionClass ) { throw new PredictExceptionFailure ( "Capture threw an Exception. Expected '$exceptionClass', but got '$actualExceptionClass'." ) ; } } } | Method to assure that a piece of code executed inside of a capture throws an exception and compare the type of it with a given class name |
919 | public function execute ( string $ uri = null ) : ApplicationInterface { $ route = App :: resolve ( 'Router' ) -> getRoute ( $ uri ) ; $ middleware = App :: resolve ( 'Middleware' , [ $ route -> getMiddlewares ( ) ] ) ; $ this -> results = $ middleware -> dispatch ( function ( ) use ( $ route , $ uri ) { return App :: resolve ( 'FrontController' ) -> dispatch ( $ route ) -> getResult ( ) ; } ) ; return $ this ; } | Executes instructions from route |
920 | private function buildQuery ( $ limit = null , $ username = null ) { if ( $ username !== null ) { $ this -> base -> where ( 'username' , $ username ) ; } if ( $ limit !== null ) { $ this -> base -> limit ( $ limit ) ; } return $ this -> base ; } | build database query |
921 | protected function _containerListHas ( $ key , $ list ) { $ list = $ this -> _normalizeIterable ( $ list ) ; foreach ( $ list as $ _container ) { if ( $ this -> _containerHas ( $ _container , $ key ) ) { return true ; } } return false ; } | Checks if a list of containers has the specified key . |
922 | public function createTable ( $ nbColonnes = 4 , $ styleTableau = 'border:1px;' , $ classTableau = '' , $ cellProperty = '' , $ tableauProperties = '' ) { return $ this -> createHtmlTableFromArray ( $ nbColonnes , $ styleTableau , $ classTableau , $ cellProperty , $ tableauProperties ) ; } | alias de la fonction suivante |
923 | public function displayArrayFromMysqlRes ( $ res ) { $ nbColonnes = 0 ; $ i = 0 ; while ( $ fetch = mysql_fetch_assoc ( $ res ) ) { if ( $ i == 0 ) { foreach ( $ fetch as $ nomField => $ value ) { $ this -> addValue ( $ nomField , "style='font-weight:bold;'" ) ; $ nbColonnes ++ ; } } foreach ( $ fetch as $ nomField => $ value ) { $ this -> addValue ( $ value ) ; } $ i ++ ; } return $ this -> createHtmlTableFromArray ( $ nbColonnes ) ; } | affiche un tableau a partir d un resultat de requete mysql |
924 | private function generateRule ( $ ruleset ) { $ regex = '' ; $ content = 'index.php' ; $ count = 0 ; $ total = count ( $ ruleset ) ; foreach ( $ ruleset as $ ruleChunk ) { $ count ++ ; if ( $ count === 1 ) { $ content .= '?post_type=' . $ this -> postType -> postType ; } if ( preg_match ( '/\{\w+\}/' , $ ruleChunk ) ) { $ regex .= '/([^/]+)' ; $ string = preg_match ( '/\{(.*?)\}/' , $ ruleChunk , $ matches ) ; $ index = '$matches[' . ( $ count - 1 ) . ']' ; $ content .= '&' . $ matches [ 1 ] . '=' . $ index ; } else { $ regex .= '/' . $ ruleChunk ; } } $ regex .= '/?$' ; return array ( $ regex , $ content ) ; } | Generate a rule for an array that Wordpress can understand . |
925 | public static function S2pv ( $ theta , $ phi , $ r , $ td , $ pd , $ rd , array & $ pv ) { $ st ; $ ct ; $ sp ; $ cp ; $ rcp ; $ x ; $ y ; $ rpd ; $ w ; $ st = sin ( $ theta ) ; $ ct = cos ( $ theta ) ; $ sp = sin ( $ phi ) ; $ cp = cos ( $ phi ) ; $ rcp = $ r * $ cp ; $ x = $ rcp * $ ct ; $ y = $ rcp * $ st ; $ rpd = $ r * $ pd ; $ w = $ rpd * $ sp - $ cp * $ rd ; $ pv [ 0 ] [ 0 ] = $ x ; $ pv [ 0 ] [ 1 ] = $ y ; $ pv [ 0 ] [ 2 ] = $ r * $ sp ; $ pv [ 1 ] [ 0 ] = - $ y * $ td - $ w * $ ct ; $ pv [ 1 ] [ 1 ] = $ x * $ td - $ w * $ st ; $ pv [ 1 ] [ 2 ] = $ rpd * $ cp + $ sp * $ rd ; return ; } | - - - - - - - - i a u S 2 p v - - - - - - - - |
926 | public function add ( $ func ) { ValidationException :: assert ( function ( ) use ( $ func ) { return ! is_callable ( $ func ) ; } , 'function is not callable' ) ; $ this -> func [ ] = $ func ; return $ this ; } | Add a validator |
927 | public static function createSub ( $ name = '' , $ content = null ) { $ class = get_called_class ( ) ; $ element = new $ class ( $ name , $ content ) ; $ element -> sub = true ; return $ element ; } | Creates a subtree . |
928 | public function getParent ( $ n = null ) { return ( $ n > 1 ) ? $ this -> parent -> getParent ( -- $ n ) : $ this -> parent ; } | Returns the parent element . |
929 | public function setOptions ( $ options ) { if ( ! isset ( $ options [ self :: OPTION_LINE_BREAK ] ) && ! isset ( $ options [ self :: OPTION_INDENTATION ] ) && ! isset ( $ options [ self :: OPTION_TEXT_MODE ] ) ) return $ this ; if ( ! $ this -> isAncestor ( ) ) { $ prevAncestor = $ this -> getAncestor ( ) ; $ this -> setAncestor ( $ this ) ; $ this -> options = [ self :: OPTION_LINE_BREAK => $ prevAncestor -> options [ self :: OPTION_LINE_BREAK ] , self :: OPTION_INDENTATION => $ prevAncestor -> options [ self :: OPTION_INDENTATION ] , self :: OPTION_TEXT_MODE => $ prevAncestor -> options [ self :: OPTION_TEXT_MODE ] ] ; } $ this -> setAncestorOption ( $ options , self :: OPTION_LINE_BREAK ) ; $ this -> setAncestorOption ( $ options , self :: OPTION_INDENTATION ) ; $ this -> setAncestorOption ( $ options , self :: OPTION_TEXT_MODE ) ; return $ this ; } | Sets options for the current element and its childs . |
930 | public function append ( $ name , $ content = null ) { if ( is_array ( $ content ) ) { $ first = $ this -> append ( $ name , $ content [ 0 ] ) ; for ( $ i = 1 ; $ i < count ( $ content ) ; $ i ++ ) { $ this -> append ( $ name , $ content [ $ i ] ) ; } return $ first ; } return $ this -> appendChild ( $ this -> newChild ( $ name , $ content ) ) ; } | Adds a child element . |
931 | public function inject ( Xml $ element ) { $ element -> setAncestor ( $ this -> getAncestor ( ) ) ; $ element -> setRoot ( $ this -> getRoot ( ) ) ; $ element -> parent = $ this ; return $ this -> appendChild ( $ element ) ; } | Appends a previously created subtree . |
932 | public function getMarkup ( $ indentation = '' ) { $ line = $ this -> getOption ( self :: OPTION_LINE_BREAK ) ; $ tab = $ this -> getOption ( self :: OPTION_INDENTATION ) ; $ xmlString = '' ; if ( empty ( $ this -> name ) ) { $ last = count ( $ this -> children ) - 1 ; foreach ( $ this -> children as $ i => $ child ) { $ xmlString .= $ child -> getMarkup ( $ indentation ) ; if ( $ i < $ last ) { $ xmlString .= $ line ; } } return $ xmlString ; } $ indent1 = $ indentation ; if ( $ line == '' ) { $ indent2 = '' ; $ indent3 = '' ; } else { $ indent2 = $ indentation . $ tab ; $ indent3 = $ indentation ; } if ( $ this -> isRoot ( ) && ! $ this -> sub ) { if ( static :: XML_DECLARATION ) { $ xmlString .= $ this -> xmlDecl ( ) ; } if ( count ( $ this -> processingInstr ) > 0 ) { foreach ( $ this -> processingInstr as $ instr ) { $ xmlString .= $ instr -> getMarkup ( ) . $ line ; } } if ( static :: DOCTYPE ) { $ xmlString .= static :: DOCTYPE . $ line ; } } if ( count ( $ this -> children ) > 0 ) { $ xmlString .= $ indent1 . $ this -> openingTag ( ) . $ line ; if ( $ this -> cdata ) { $ xmlString .= $ indent3 . self :: CDATA_START . $ line ; } if ( $ this -> content != null ) { $ xmlString .= $ indent2 . $ this -> prepareContent ( $ this -> content , $ indent2 , $ line ) . $ line ; } foreach ( $ this -> children as $ child ) { if ( is_string ( $ child ) ) { $ xmlString .= $ indent2 . $ this -> prepareContent ( $ child , $ indent2 , $ line ) . $ line ; } else { $ xmlString .= $ child -> getMarkup ( $ indent2 ) . $ line ; } } if ( $ this -> cdata ) { $ xmlString .= $ indent3 . self :: CDATA_STOP . $ line ; } $ xmlString .= $ indent3 . $ this -> closingTag ( ) ; } else { $ xmlString .= $ indent1 . $ this -> element ( $ indent1 , $ line , $ this -> cdata ) ; } return $ xmlString ; } | Generates the desired markup . |
933 | public static function headerfields ( $ filename = null , $ addExtension = true ) { if ( ! empty ( $ filename ) ) { header ( self :: getContentDispositionHeaderfield ( $ filename , $ addExtension ) ) ; } header ( self :: getContentTypeHeaderfield ( ) ) ; } | Sets the header fields Content - Type and Content - Disposition . |
934 | protected function newChild ( $ name , $ content = null ) { $ class = get_class ( $ this ) ; return new $ class ( $ name , $ content , $ this -> getRoot ( ) , $ this -> getAncestor ( ) , $ this ) ; } | Creates a child element . |
935 | protected function mapAttributToProperty ( $ xmlEntry , $ attributName , $ stackEntity ) { switch ( $ xmlEntry -> getName ( ) ) { case 'date' : switch ( $ attributName ) { case 'start' : return 'startDate' ; break ; case 'end' : return 'endDate' ; break ; default : return $ attributName ; break ; } break ; default : switch ( $ attributName ) { case 'associationid' : return 'id' ; break ; default : return $ attributName ; break ; } break ; } } | map attributName to property |
936 | public function init ( ) { $ this -> setup -> load_options ( 'AxelSpringer\WP\Bootstrap\__OPTION__' ) ; $ this -> settings = new Settings ( __ ( __TRANSLATE__ :: SETTINGS_PAGE_TITLE ) , __ ( __TRANSLATE__ :: SETTINGS_MENU_TITLE ) , __PLUGIN__ :: SETTINGS_PAGE , __PLUGIN__ :: SETTINGS_PERMISSION , $ this -> setup -> version ) ; } | Initializes the plugin |
937 | public function enqueue_admin_scripts ( ) { wp_register_style ( 'bootstrap-admin-style' , $ this -> plugin_url ( 'admin/admin.css' ) , false , $ this -> setup -> version ) ; wp_register_script ( 'bootstrap-admin-script' , $ this -> plugin_url ( 'admin/admin.js' ) , array ( 'jquery' , 'wp-util' ) , $ this -> setup -> version , true ) ; wp_enqueue_style ( 'bootstrap-admin-style' ) ; wp_enqueue_script ( 'bootstrap-admin-script' ) ; } | Enqueue shared styles and scripts |
938 | public function hasAnyTags ( $ tags , string $ group = null , string $ locale = null ) : bool { $ tags = $ this -> parseTags ( $ tags , $ group , $ locale ) ; return ! $ this -> tags -> pluck ( 'id' ) -> intersect ( $ tags ) -> isEmpty ( ) ; } | Determine if the model has any of the given tags . |
939 | public static function parseDelimitedTags ( $ tags ) : array { if ( is_string ( $ tags ) && mb_strpos ( $ tags , static :: $ tagsDelimiter ) !== false ) { $ delimiter = preg_quote ( static :: $ tagsDelimiter , '#' ) ; $ tags = array_map ( 'trim' , preg_split ( "#[{$delimiter}]#" , $ tags , - 1 , PREG_SPLIT_NO_EMPTY ) ) ; } return array_unique ( array_filter ( ( array ) $ tags ) ) ; } | Parse delimited tags . |
940 | public function attachTags ( $ tags ) { $ this -> tags ( ) -> sync ( $ this -> parseTags ( $ tags ) , false ) ; return $ this ; } | Attach model tags . |
941 | public function syncTags ( $ tags , bool $ detaching = true ) { $ this -> tags ( ) -> sync ( $ this -> parseTags ( $ tags , null , null , true ) , $ detaching ) ; return $ this ; } | Sync model tags . |
942 | public function detachTags ( $ tags = null ) { ! $ tags || $ tags = $ this -> parseTags ( $ tags ) ; $ this -> tags ( ) -> detach ( $ tags ) ; return $ this ; } | Detach model tags . |
943 | protected function parseTags ( $ rawTags , string $ group = null , string $ locale = null , $ create = false ) : array { ( is_iterable ( $ rawTags ) || is_null ( $ rawTags ) ) || $ rawTags = [ $ rawTags ] ; [ $ strings , $ tags ] = collect ( $ rawTags ) -> map ( function ( $ tag ) { ! is_numeric ( $ tag ) || $ tag = ( int ) $ tag ; ! $ tag instanceof Model || $ tag = [ $ tag -> getKey ( ) ] ; ! $ tag instanceof Collection || $ tag = $ tag -> modelKeys ( ) ; ! $ tag instanceof BaseCollection || $ tag = $ tag -> toArray ( ) ; return $ tag ; } ) -> partition ( function ( $ item ) { return is_string ( $ item ) ; } ) ; return $ tags -> merge ( app ( 'rinvex.tags.tag' ) -> { $ create ? 'findByNameOrCreate' : 'findByName' } ( $ strings -> toArray ( ) , $ group , $ locale ) -> pluck ( 'id' ) ) -> toArray ( ) ; } | Parse tags . |
944 | protected function normalizeHeaderName ( $ name ) { return preg_replace_callback ( '/\-(.)/' , function ( $ match ) { return '-' . strtoupper ( $ match [ 1 ] ) ; } , strtr ( ucfirst ( strtolower ( $ name ) ) , '_' , '-' ) ) ; } | Retrieves a normalized Header . |
945 | public function set ( $ key , $ value ) { if ( ! $ value instanceof AdapterInterface ) { throw new InvalidArgumentException ( 'Adding an object that does not implement AdapterInterface ' . 'to AdaptersMap.' ) ; } return parent :: set ( $ key , $ value ) ; } | Puts a new adapter in the map . |
946 | protected function _containerSet ( & $ container , $ key , $ value ) { $ key = $ this -> _normalizeKey ( $ key ) ; try { if ( is_array ( $ container ) ) { $ container [ $ key ] = $ value ; return ; } if ( $ container instanceof ArrayAccess ) { $ container -> offsetSet ( $ key , $ value ) ; return ; } if ( $ container instanceof stdClass ) { $ container -> { $ key } = $ value ; return ; } } catch ( RootException $ e ) { throw $ this -> _createContainerException ( $ this -> __ ( 'Could not write to container key "%1$s"' , [ $ key ] ) , null , $ e ) ; } throw $ this -> _createInvalidArgumentException ( $ this -> __ ( 'Not a valid container' ) , null , null , $ container ) ; } | Sets data on the container . |
947 | public function run ( ) { if ( ! $ this -> overrideFile ( ) ) { $ this -> output -> writeln ( "<info>File was skipped. The controller was not created.</info>" ) ; return true ; } $ data = $ this -> getControllerMetaData ( ) -> getData ( ) ; $ data = array_merge ( $ data , [ 'controllerName' => $ this -> controllerName , 'namespace' => $ this -> namespace , 'basePath' => $ this -> getBasePath ( ) ] ) ; $ content = $ this -> getTemplateEngine ( ) -> parse ( $ this -> template ) -> process ( $ data ) ; file_put_contents ( $ this -> getControllerFile ( ) , $ content ) ; return true ; } | Runs this task |
948 | public function getControllerMetaData ( ) { if ( null == $ this -> controllerMetaData ) { $ controller = new Controller ( ) ; $ this -> configureController ( $ controller ) ; $ this -> setControllerMetaData ( $ controller ) ; } return $ this -> controllerMetaData ; } | Gets controllerMetaData property |
949 | public function getTemplateEngine ( ) { if ( null == $ this -> templateEngine ) { Template :: addPath ( dirname ( dirname ( __DIR__ ) ) . '/templates' ) ; $ template = ( new Template ( ) ) -> initialize ( ) ; $ this -> setTemplateEngine ( $ template ) ; } return $ this -> templateEngine ; } | Gets templateEngine property |
950 | public function getBasePath ( ) { if ( null == $ this -> basePath ) { $ this -> basePath = strtolower ( $ this -> controllerName ) ; } return $ this -> basePath ; } | Gets basePath property |
951 | public function getQuestionHelper ( ) { if ( null == $ this -> questionHelper ) { $ this -> setQuestionHelper ( $ this -> getCommand ( ) -> getHelper ( 'question' ) ) ; } return $ this -> questionHelper ; } | Gets questionHelper property |
952 | protected function overrideFile ( ) { if ( ! is_file ( $ this -> getControllerFile ( ) ) ) { return true ; } $ question = new ConfirmationQuestion ( "\nThe file <comment>{$this->controllerFile}</comment> already " . "exists. Override it (y,N)? " , false , '/^(y|yes)/i' ) ; return ( boolean ) $ this -> getQuestionHelper ( ) -> ask ( $ this -> input , $ this -> output , $ question ) ; } | Check controller file existence and ask if can be overridden |
953 | protected function checkPause ( ) { parent :: checkPause ( ) ; foreach ( $ this -> slaves as $ slave ) { $ this -> checkSlave ( $ slave ) ; } } | Check whether necessary to pause for slave lag |
954 | protected function checkSlave ( Connection $ connection ) { $ paused = 0 ; while ( ( $ lag = $ this -> getLag ( $ connection ) ) > $ this -> options [ 'max_lag' ] ) { $ this -> paused = true ; $ for = $ this -> options [ 'pause_lag' ] ; $ this -> logger -> notice ( 'Chunk detected lag of {lag} on {database}, pausing for {for}' , [ 'lag' => $ lag , 'database' => sprintf ( '%s/%s' , $ connection -> getHost ( ) , $ connection -> getDatabase ( ) ) , 'for' => $ for ] ) ; usleep ( $ for ) ; $ paused += $ for ; if ( $ paused > $ this -> options [ 'max_pause_lag' ] ) { if ( $ this -> options [ 'continue_lag' ] ) { break ; } else { throw new RuntimeException ( 'Slave lag did not recover after processing chunk. Aborting.' ) ; } } } } | Checks the given slave connection for lag |
955 | public function printException ( DefinitionInterface $ definition , $ exception ) { $ traceAsString = $ this -> getTraceAsString ( $ definition , $ exception ) ; $ this -> printError ( "\nError %s #%s during test %s \n%s \nin %s\n\n%s" , get_class ( $ exception ) , $ exception -> getCode ( ) , $ this -> getTestDescriptionForDefinition ( $ definition ) , $ exception -> getMessage ( ) , $ this -> getTestLocationForDefinitionAndException ( $ definition , $ exception ) , $ traceAsString ) ; return $ this ; } | Prints the exception for the given test definition |
956 | private function fromCamelCase ( $ input ) { $ a = preg_split ( '/(^[^A-Z]+|[A-Z][^A-Z]+)/' , $ input , - 1 , PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ) ; return strtolower ( join ( $ a , "-" ) ) ; } | Converts camelCase string to have spaces between each . |
957 | public static function exists ( $ currency ) { if ( $ currency instanceof CurrencyInterface ) { $ currency = $ currency -> getIsoCode ( ) ; } self :: loadSpecifications ( ) ; return array_key_exists ( strtolower ( $ currency ) , self :: $ specifications ) ; } | Checks whether a currency is allowed in the current context |
958 | private static function loadSpecifications ( ) { if ( ! self :: $ specifications ) { $ content = file_get_contents ( __DIR__ . '/../data/currencies.json' ) ; self :: $ specifications = Json :: decode ( $ content , Json :: TYPE_ARRAY ) ; } } | Loads currencies specs |
959 | public function render ( Renderable $ renderable , $ render = null ) { $ render = $ this -> renderProvider -> get ( $ render ) ; return $ render -> render ( $ renderable ) ; } | Renders a form |
960 | public function actionUpdate ( ) { $ activeTheme = ThemeManager :: getActiveTheme ( ) ; $ model = new DynamicModel ( [ 'activeIndex' => $ activeTheme === false ? false : key ( $ activeTheme ) ] ) ; $ model -> addRule ( 'activeIndex' , 'safe' ) ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) ) { ThemeManager :: setActiveTheme ( $ model -> activeIndex === '' ? false : $ model -> activeIndex ) ; Yii :: $ app -> session -> setFlash ( 'success' , Module :: t ( 'message' , 'Update succeed.' ) ) ; return $ this -> refresh ( ) ; } return $ this -> render ( 'update' , [ 'model' => $ model , 'themes' => ThemeManager :: getThemes ( ) ] ) ; } | Updates an active theme index . |
961 | final static function parseWith ( $ optionsResource , array $ _ = null ) { if ( ! static :: isConfigurableWith ( $ optionsResource ) ) throw new \ InvalidArgumentException ( sprintf ( 'Resource must be an array or string, given: (%s).' , \ Poirot \ Std \ flatten ( $ optionsResource ) ) ) ; $ self = new static ; ( empty ( $ _ ) ) ? : $ self -> with ( $ _ ) ; if ( is_string ( $ optionsResource ) ) $ optionsResource = $ self -> doParseFromString ( $ optionsResource ) ; return $ optionsResource ; } | Build Path From Given Resources |
962 | public function cloneQueryBuilder ( ) { $ paramContent = $ this -> newParamName ( ) ; $ subQuery = clone $ this -> queryBuilder ; $ subQuery -> resetDQLParts ( ) ; $ subQuery -> setParameters ( [ ] ) ; $ subQuery -> select ( $ paramContent ) -> from ( 'OpiferCmsBundle:Content' , $ paramContent ) ; return $ subQuery ; } | Clone the query builder |
963 | public function getQueryResults ( $ limit = null ) { if ( isset ( $ limit ) ) { $ this -> queryBuilder -> setMaxResults ( $ limit ) ; } if ( ! $ this -> queryBuilder -> getDQLPart ( 'orderBy' ) ) { $ this -> queryBuilder -> orderBy ( 'a.createdAt' , 'ASC' ) ; } return $ this -> queryBuilder -> getQuery ( ) -> getResult ( ) ; } | Get the query result |
964 | protected function retrieveHandler ( array & $ data ) { $ controller = array_shift ( $ data ) ; $ action = array_shift ( $ data ) ; return [ $ controller , $ action ] ; } | Retrieve controller action pair |
965 | protected function retrieveParams ( array $ data ) { $ params = [ ] ; foreach ( $ data as $ i => $ val ) { if ( 0 === $ i % 2 ) { $ params [ $ val ] = $ data [ $ i + 1 ] ; } } return $ params ; } | Retrieve pair of params |
966 | public function isForPackage ( PackageInterface $ package ) { if ( $ this -> getForPackage ( ) !== $ package -> getName ( ) ) { return false ; } $ fpv = $ this -> getForPackageVersion ( ) ; if ( $ fpv !== null ) { $ pv = new Constraint ( '=' , $ package -> getVersion ( ) ) ; if ( ! $ fpv -> matches ( $ pv ) ) { return false ; } } return true ; } | Check if this patch is for a package . |
967 | public function getHash ( ) { if ( $ this -> hash === null ) { $ this -> hash = sha1_file ( $ this -> getLocalPath ( ) ) ; } return $ this -> hash ; } | Get the hash of this patch . |
968 | public function addNewContent ( $ text , $ renderer ) { $ sortorder = $ this -> getContents ( ) -> count ( ) ; $ newContent = new Content ; $ newContent -> setContent ( $ text ) ; $ newContent -> setRenderer ( $ renderer ) ; $ newContent -> generatePermid ( ) ; $ newContent -> setSortorder ( ++ $ sortorder ) ; $ newContent -> setSection ( $ this ) ; $ this -> addContent ( $ newContent ) ; return $ newContent ; } | Add new content by text and renderer |
969 | public function write ( string $ id , array $ data ) : bool { static $ create , $ update , $ delete ; $ values = $ data + compact ( 'id' ) ; unset ( $ values [ 'dateactive' ] ) ; if ( ! isset ( $ create , $ update ) ) { $ fields = [ ] ; $ placeholders = [ ] ; $ updates = [ ] ; foreach ( $ values as $ key => & $ value ) { if ( $ key == 'data' ) { $ value = base64_encode ( $ value ) ; } $ fields [ ] = $ key ; $ placeholders [ ] = ":$key" ; if ( $ key != 'id' ) { $ updates [ ] = "$key = :$key" ; } } $ create = $ this -> pdo -> prepare ( sprintf ( "INSERT INTO cesession_session (%s) VALUES (%s)" , implode ( ', ' , $ fields ) , implode ( ', ' , $ placeholders ) ) ) ; $ update = $ this -> pdo -> prepare ( sprintf ( "UPDATE cesession_session SET %s WHERE id = :id" , implode ( ', ' , $ updates ) ) ) ; $ delete = $ this -> pdo -> prepare ( "DELETE FROM cesession_session WHERE id = :id" ) ; } if ( $ this -> exists ) { $ update -> execute ( $ values ) ; return ( bool ) $ update -> rowCount ( ) ; } else { $ delete -> execute ( compact ( 'id' ) ) ; try { $ create -> execute ( $ values ) ; return ( $ affectedRows = $ create -> rowCount ( ) ) && $ affectedRows ; } catch ( PDOException $ e ) { $ update -> execute ( $ values ) ; return ( bool ) $ update -> rowCount ( ) ; } } } | Write back data . |
970 | public function gc ( int $ maxlifetime ) : bool { static $ stmt ; if ( ! isset ( $ stmt ) ) { $ stmt = $ this -> pdo -> prepare ( "DELETE FROM cesession_session WHERE dateactive < ?" ) ; } $ stmt -> execute ( [ date ( 'Y-m-d H:i:s' , strtotime ( "-$maxlifetime second" ) ) ] ) ; return ( $ affectedRows = $ stmt -> rowCount ( ) ) && $ affectedRows ; } | Run garbase collection . |
971 | public function delete ( ) { if ( empty ( static :: $ table ) ) $ table = strtolower ( substr ( static :: class , strpos ( static :: class , '\\' ) + 1 ) ) ; else $ table = static :: $ table ; if ( $ table != '' ) { if ( $ this -> _id != '' || ( is_array ( $ this -> _id ) && count ( $ this -> _id ) > 0 ) ) { $ before = $ this -> before ( ) ; if ( is_array ( $ before ) && count ( $ before ) > 1 ) { if ( isset ( $ before [ 'delete' ] ) ) { $ delete = $ before [ 'delete' ] ; while ( list ( $ field , $ value ) = each ( $ delete ) ) $ this -> _id [ $ field ] = $ value ; } } $ ret = self :: $ db -> $ table -> delete ( $ this -> _id ) ; $ after = $ this -> after ( ) ; if ( is_array ( $ after ) && count ( $ after ) > 1 ) { if ( isset ( $ after [ 'delete' ] ) && is_callable ( $ after [ 'delete' ] ) ) { $ delete = $ after [ 'delete' ] ; $ delete ( $ this -> _id ) ; } } $ this -> _data [ $ table ] = array ( ) ; } else $ ret = FALSE ; } return $ ret ; } | delete Fungsi untuk menghapus record |
972 | protected static function _run ( $ name , $ type ) { $ version = \ Cli :: option ( 'v' , \ Cli :: option ( 'version' , '' ) ) ; if ( $ version === true ) { \ Cli :: write ( 'Currently installed migrations for ' . $ type . ':' . $ name . ':' , 'green' ) ; foreach ( \ Config :: get ( 'migrations.version.' . $ type . '.' . $ name , array ( ) ) as $ version ) { \ Cli :: write ( '- ' . $ version ) ; } return ; } elseif ( $ version !== '' ) { if ( static :: $ default + static :: $ module_count + static :: $ package_count > 1 ) { \ Cli :: write ( 'Migration: version only accepts 1 item.' ) ; return ; } $ migrations = \ Migrate :: version ( $ version , $ name , $ type , \ Cli :: option ( 'catchup' , false ) ) ; } else { $ migrations = \ Migrate :: latest ( $ name , $ type , \ Cli :: option ( 'catchup' , false ) ) ; } if ( $ migrations ) { \ Cli :: write ( 'Performed migrations for ' . $ type . ':' . $ name . ':' , 'green' ) ; foreach ( $ migrations as $ migration ) { \ Cli :: write ( $ migration ) ; } } else { if ( $ migrations === false ) { \ Cli :: write ( 'Some migrations where skipped for ' . $ type . ':' . $ name . '. Please re-run the migrations.' , 'cyan' ) ; } elseif ( $ version !== '' ) { \ Cli :: write ( 'No migrations were found for ' . $ type . ':' . $ name . '.' ) ; } else { \ Cli :: write ( 'Already on the latest migration for ' . $ type . ':' . $ name . '.' ) ; } } } | migrates to the latest version unless - version is specified |
973 | protected static function _current ( $ name , $ type ) { if ( \ Cli :: option ( 'v' , \ Cli :: option ( 'version' , '' ) ) !== '' ) { \ Cli :: write ( 'You can not define a version when using the "current" command.' , 'red' ) ; } $ migrations = \ Migrate :: current ( $ name , $ type ) ; if ( $ migrations ) { \ Cli :: write ( 'Newly installed migrations for ' . $ type . ':' . $ name . ':' , 'green' ) ; foreach ( $ migrations as $ migration ) { \ Cli :: write ( '- ' . $ migration ) ; } } else { \ Cli :: write ( 'Already on the current migration version for ' . $ type . ':' . $ name . '.' ) ; } } | migrates item to current config version |
974 | protected static function _up ( $ name , $ type ) { $ version = \ Cli :: option ( 'v' , \ Cli :: option ( 'version' , null ) ) ; if ( $ version and ( static :: $ default + static :: $ module_count + static :: $ package_count > 1 ) ) { \ Cli :: write ( 'Migration: version only accepts 1 item.' ) ; return ; } $ migrations = \ Migrate :: up ( $ version , $ name , $ type ) ; if ( $ migrations ) { \ Cli :: write ( 'Newly installed migrations for ' . $ type . ':' . $ name . ':' , 'green' ) ; foreach ( $ migrations as $ migration ) { \ Cli :: write ( '- ' . $ migration ) ; } } else { \ Cli :: write ( 'You are already on the latest migration version for ' . $ type . ':' . $ name . '.' ) ; } } | migrates item up to the given version |
975 | protected static function _down ( $ name , $ type ) { $ version = \ Cli :: option ( 'v' , \ Cli :: option ( 'version' , null ) ) ; if ( $ version and ( static :: $ default + static :: $ module_count + static :: $ package_count > 1 ) ) { \ Cli :: write ( 'Migration: version only accepts 1 item.' ) ; return ; } $ migrations = \ Migrate :: down ( $ version , $ name , $ type ) ; if ( $ migrations ) { \ Cli :: write ( 'Reverted migrations for ' . $ type . ':' . $ name . ':' , 'green' ) ; foreach ( $ migrations as $ migration ) { \ Cli :: write ( '- ' . $ migration ) ; } } else { \ Cli :: write ( 'There are no migrations installed to revert for ' . $ type . ':' . $ name . '.' ) ; } } | migrates item down to the given version |
976 | public function loadDictionary ( ) { if ( self :: $ dictionary_loaded ) { return true ; } $ xmldoc = new \ DOMDocument ( ) ; if ( ! $ xmldoc -> load ( $ this -> localization_path . "texts.xml" ) ) { throw new \ Exception ( "Translation file '" . $ this -> localization_path . "texts.xml" . "' cannot be loaded!" ) ; } $ xsdpath = new \ DOMXPath ( $ xmldoc ) ; $ nodes = $ xsdpath -> evaluate ( "/document/interface_languages/language" ) ; foreach ( $ nodes as $ node ) { $ lang_code = $ node -> getAttribute ( "id" ) ; if ( ! empty ( $ lang_code ) ) { self :: $ supported_languages [ $ lang_code ] = $ lang_code ; } } $ nodes = $ xsdpath -> evaluate ( "/document/languages/language/*" ) ; foreach ( $ nodes as $ node ) { $ pnode = $ node -> parentNode ; $ lang_code = $ node -> nodeName ; $ text_id = $ pnode -> getAttribute ( "id" ) ; if ( ! empty ( $ lang_code ) && ! empty ( $ text_id ) && ! empty ( $ node -> nodeValue ) ) { self :: $ languages [ $ lang_code ] [ $ text_id ] = $ node -> nodeValue ; } } $ nodes = $ xsdpath -> evaluate ( "/document/countries/country/*" ) ; foreach ( $ nodes as $ node ) { $ pnode = $ node -> parentNode ; $ lang_code = $ node -> nodeName ; $ text_id = $ pnode -> getAttribute ( "id" ) ; if ( ! empty ( $ lang_code ) && ! empty ( $ text_id ) && ! empty ( $ node -> nodeValue ) ) { self :: $ countries [ $ lang_code ] [ $ text_id ] = $ node -> nodeValue ; } } $ nodes = $ xsdpath -> evaluate ( "/document/texts/text/*" ) ; foreach ( $ nodes as $ node ) { $ pnode = $ node -> parentNode ; $ lang_code = $ node -> nodeName ; $ text_id = $ pnode -> getAttribute ( "id" ) ; if ( ! empty ( $ lang_code ) && ! empty ( $ text_id ) && ! empty ( $ node -> nodeValue ) ) { self :: $ texts [ $ lang_code ] [ $ text_id ] = $ node -> nodeValue ; } } self :: $ dictionary_loaded = true ; foreach ( self :: $ supported_languages as $ lng ) { self :: $ current_language = $ lng ; break ; } return true ; } | This is internal auxiliary function for loading the translations from the source XML file . |
977 | public function detectLanguage ( $ context = "default" ) { self :: $ context = $ context ; $ language = "en" ; foreach ( self :: $ supported_languages as $ lng ) { $ language = $ lng ; break ; } if ( isset ( $ _SERVER [ "HTTP_ACCEPT_LANGUAGE" ] ) && trim ( $ _SERVER [ "HTTP_ACCEPT_LANGUAGE" ] ) != "" ) { $ accepted = explode ( ',' , $ _SERVER [ "HTTP_ACCEPT_LANGUAGE" ] ) ; foreach ( $ accepted as $ key => $ name ) { $ code = explode ( ';' , $ name ) ; $ code = explode ( "-" , $ code [ 0 ] ) ; if ( ! empty ( self :: $ supported_languages [ $ code [ 0 ] ] ) ) { $ language = $ code [ 0 ] ; break ; } } } if ( ! empty ( $ _COOKIE [ self :: $ context . "_language" ] ) && ! empty ( self :: $ supported_languages [ $ _COOKIE [ self :: $ context . "_language" ] ] ) ) { $ language = $ _COOKIE [ self :: $ context . "_language" ] ; } if ( ! empty ( session ( ) -> vars ( ) [ self :: $ context . "_language" ] ) && ! empty ( self :: $ supported_languages [ session ( ) -> vars ( ) [ self :: $ context . "_language" ] ] ) ) { $ language = $ _COOKIE [ self :: $ context . "_language" ] ; } if ( ! empty ( $ _REQUEST [ "language" ] ) && ! empty ( self :: $ supported_languages [ $ _REQUEST [ "language" ] ] ) ) { $ language = $ _REQUEST [ "language" ] ; } $ this -> setCurrentLanguage ( $ language ) ; } | This function should detect the current language based on cookies browser languages etc . |
978 | public function setCurrentLanguage ( $ language ) { if ( empty ( self :: $ supported_languages [ $ language ] ) ) { return false ; } self :: $ current_language = $ language ; session ( ) -> vars ( ) [ self :: $ context . "_language" ] = $ language ; setcookie ( self :: $ context . "_language" , $ language , time ( ) + 365 * 24 * 3600 ) ; return true ; } | Sets the current language . |
979 | public function text ( $ text_id , $ lng = "" , $ warn_missing = true , $ default_text = "" ) { if ( empty ( $ lng ) ) { $ lng = $ this -> getCurrentLanguage ( ) ; } if ( empty ( self :: $ texts [ $ lng ] [ $ text_id ] ) ) { if ( $ warn_missing ) { trigger_error ( "No translation for the text '$text_id' in the language [$lng]!" , E_USER_NOTICE ) ; } if ( empty ( $ default_text ) ) { return $ text_id ; } else { return $ default_text ; } } return self :: $ texts [ $ lng ] [ $ text_id ] ; } | Provides the text translation for the text ID for the given langauge . |
980 | public function hasTranslation ( $ text_id , $ lng = "" ) { if ( empty ( $ lng ) ) { $ lng = $ this -> getCurrentLanguage ( ) ; } return ! empty ( self :: $ texts [ $ lng ] [ $ text_id ] ) ; } | Checks whether the text translation for the text ID for the given langauge exists . |
981 | public function getLanguageName ( $ code , $ lng = "" , $ warn_missing = true ) { if ( empty ( $ lng ) ) { $ lng = $ this -> getCurrentLanguage ( ) ; } if ( empty ( self :: $ languages [ $ lng ] [ $ code ] ) ) { if ( $ warn_missing ) { trigger_error ( "No translation for the language name [$code] in the language [$lng]!" , E_USER_NOTICE ) ; } return $ code ; } return self :: $ languages [ $ lng ] [ $ code ] ; } | Provides the text translation for the language name by the code for the given langauge . |
982 | public function getLanguageCode ( $ lang_name ) { foreach ( self :: $ supported_languages as $ lng ) { if ( empty ( self :: $ languages [ $ lng ] ) ) { continue ; } foreach ( self :: $ languages [ $ lng ] as $ code => $ translation ) { if ( strcasecmp ( $ lang_name , $ translation ) == 0 ) { return $ code ; } } } return "" ; } | Tries to find the language code by the given name . |
983 | public function getLanguageList ( & $ language_list , $ lng = "" ) { if ( empty ( $ lng ) ) { $ lng = $ this -> getCurrentLanguage ( ) ; } if ( empty ( self :: $ languages [ $ lng ] ) ) { return false ; } $ language_list += self :: $ languages [ $ lng ] ; asort ( $ language_list , SORT_LOCALE_STRING ) ; return true ; } | Provides the list of languages for the given language in the form code = > translation . |
984 | public function getCountryName ( $ code , $ lng = "" , $ warn_missing = true ) { if ( empty ( $ lng ) ) { $ lng = $ this -> getCurrentLanguage ( ) ; } if ( empty ( self :: $ countries [ $ lng ] [ $ code ] ) ) { if ( $ warn_missing ) { trigger_error ( "No translation for the country name [$code] in the language [$lng]!" , E_USER_NOTICE ) ; } return $ code ; } return self :: $ countries [ $ lng ] [ $ code ] ; } | Provides the text translation for the country name by the code for the given langauge . |
985 | public function getCountryCode ( $ country_name ) { foreach ( self :: $ supported_languages as $ lng ) { if ( empty ( self :: $ countries [ $ lng ] ) ) { continue ; } foreach ( self :: $ countries [ $ lng ] as $ code => $ translation ) { if ( strcasecmp ( $ country_name , $ translation ) == 0 ) { return $ code ; } } } return "" ; } | Tries to find the country code by the given name . |
986 | public function getCountryList ( & $ country_list , $ lng = "" ) { if ( empty ( $ lng ) ) { $ lng = $ this -> getCurrentLanguage ( ) ; } if ( empty ( self :: $ countries [ $ lng ] ) ) { return false ; } $ country_list += self :: $ countries [ $ lng ] ; asort ( $ country_list , SORT_LOCALE_STRING ) ; return true ; } | Provides the list of countries for the given language in the form code = > translation . |
987 | private function add_slugify_helper ( ) { $ this -> engine -> addHelper ( 'slugify' , function ( $ template , $ context , $ args ) { $ arg = $ context -> get ( $ args ) ; return slugify ( $ arg ) ; } ) ; } | Slugify Helper - lets you slugify any string |
988 | private function add_strip_tags ( ) { $ this -> engine -> addHelper ( 'strip_tags' , function ( $ template , $ context , $ args ) { $ arg = $ context -> get ( $ args ) ; return strip_tags ( $ arg ) ; } ) ; } | No Tags Formatter |
989 | private function add_html_special_chars_handler ( ) { $ this -> engine -> addHelper ( 'html_special_chars' , function ( $ template , $ context , $ args ) { $ that = $ context -> get ( 'this' ) ; if ( array_key_exists ( $ args , $ that ) ) { return htmlspecialchars ( $ that [ $ args ] ) ; } } ) ; } | Helper function html_special_chars |
990 | private function add_conditional_operators ( ) { $ this -> engine -> addHelper ( 'if_cond' , function ( $ template , $ context , $ args ) { $ that = $ context -> get ( 'this' ) ; $ handlebars_arguments = new Arguments ( $ args ) ; $ arguments = $ handlebars_arguments -> getPositionalArguments ( ) ; $ value_a = $ arguments [ 0 ] ; $ operator = $ arguments [ 1 ] ; $ value_b = $ arguments [ 2 ] ; $ value_a = $ this -> get_real_value ( $ value_a , $ that ) ; $ value_b = $ this -> get_real_value ( $ value_b , $ that ) ; if ( $ this -> is_conditional_true ( $ value_a , $ value_b , $ operator ) ) { $ template -> setStopToken ( 'else' ) ; $ buffer = $ this -> render ( $ template , $ context , array ( ) , true ) ; $ template -> setStopToken ( false ) ; $ template -> discard ( $ context ) ; } else { $ template -> setStopToken ( 'else' ) ; $ template -> discard ( $ context ) ; $ template -> setStopToken ( false ) ; $ buffer = $ this -> render ( $ template , $ context , array ( ) , true ) ; } return $ buffer ; } ) ; } | Helper function if_cond |
991 | public function handler ( $ name , Args $ args ) { if ( ! $ this -> checkLevel ( $ args -> get ( 'level' ) ) || ! $ this -> checkSource ( $ args -> get ( 'source' ) ) ) { return ; } switch ( $ name ) { case ':onAddHandler:' : $ args -> set ( 'message' , sprintf ( "Adding handler %s, %s" , $ this -> handlerToString ( $ args -> get ( 'handler' ) , $ args -> get ( 'name' ) ) , $ args -> get ( 'added' , false ) ? "successfully" : "failed (duplicate handler)" ) ) ; break ; case ':onEventStart:' : $ args -> set ( 'message' , sprintf ( "{ '%s' (%s), args [%s]" , $ args -> get ( 'name' ) , $ args -> get ( 'uid' ) , implode ( ', ' , array_keys ( $ args -> get ( ) ) ) ) ) ; break ; case ':onHandlerFound:' : $ args -> set ( 'message' , sprintf ( "Handler %s found" , $ this -> handlerToString ( $ args -> get ( 'handler' ) ) ) ) ; break ; case ':onEventEnd:' : $ args -> set ( 'message' , sprintf ( "} '%s' (%s), args [%s]" , $ args -> get ( 'name' ) , $ args -> get ( 'uid' ) , implode ( ', ' , array_keys ( $ args -> get ( ) ) ) ) ) ; break ; case ':onDropHandlers:' : $ args -> set ( 'message' , sprintf ( "Dropping handler %s" , $ this -> handlerToString ( $ args -> get ( 'handler' ) , $ args -> get ( 'name' ) ) ) ) ; break ; case ':onDisableHandler:' : $ args -> set ( 'message' , sprintf ( "Disabling handler %s" , $ this -> handlerToString ( $ args -> get ( 'handler' ) , $ args -> get ( 'name' ) ) ) ) ; break ; case ':onEnableHandler:' : $ args -> set ( 'message' , sprintf ( "Enabling handler %s" , $ this -> handlerToString ( $ args -> get ( 'handler' ) , $ args -> get ( 'name' ) ) ) ) ; break ; } $ this -> log ( $ args ) ; } | Logging handler . |
992 | public function onUpdateRegistry ( $ name , Args $ args ) { $ conditions = $ args -> get ( 'conditions' ) ; foreach ( $ conditions as $ key => $ expected ) { $ actual = $ this -> registry -> get ( $ key , null , false ) ; if ( "/" !== substr ( $ expected , 0 , 1 ) ? $ expected !== $ actual : ! preg_match ( $ expected , $ actual ) ) { return ; } } $ changes = $ args -> get ( 'changes' ) ; foreach ( $ changes as $ key => $ value ) { $ this -> registry -> set ( $ key , $ value ) ; } } | Updating method registry handler . |
993 | protected function init ( Manager $ evtManager ) { $ this -> evtManager = $ evtManager ; $ events = $ this -> evtManager -> getDebugEvents ( ) ; foreach ( $ events as $ event ) { $ this -> evtManager -> addHandler ( $ event , [ $ this , 'handler' ] ) ; } $ this -> evtManager -> addHandler ( ':updateLogRegistry:' , [ $ this , 'onUpdateRegistry' ] ) ; } | Adds event handlers . |
994 | protected function checkSource ( $ source ) { $ sources = $ this -> registry -> get ( 'source' , [ ] ) ; $ result = in_array ( $ source , $ sources ) || in_array ( '*' , $ sources ) ; return $ result ; } | Returns true if passed source published in config file . |
995 | protected function checkLevel ( $ level ) { $ cfgLevel = $ this -> registry -> get ( 'level' , self :: DEFAULT_LEVEL ) ; if ( is_numeric ( $ cfgLevel ) ) { $ cfgLevel = ( int ) $ cfgLevel ; } else if ( is_string ( $ cfgLevel ) && preg_match ( '/^[A-Z_&|^ ]+$/' , $ cfgLevel ) ) { $ cfgLevel = eval ( sprintf ( "return %s;" , $ cfgLevel ) ) ; } else { throw new \ RuntimeException ( sprintf ( "Invalid log level '%s' passed!" , $ cfgLevel ) ) ; } $ result = ( bool ) ( $ cfgLevel & $ level ) ; return $ result ; } | Returns true if passed level published in config file . |
996 | protected function handlerToString ( $ handler , $ name = '' ) { if ( is_array ( $ handler ) ) { if ( is_object ( $ handler [ 0 ] ) ) { $ class = get_class ( $ handler [ 0 ] ) ; $ call = '->' ; } else { $ class = $ handler [ 0 ] ; $ call = '::' ; } $ result = "{$class}{$call}{$handler[1]}" ; } else { $ result = 'function' . ( '' != $ handler ? " {$handler}" : '' ) ; } $ result .= "({$name})" ; return $ result ; } | Returns stringified event handler . |
997 | protected function render ( Args $ args ) { $ format = $ this -> registry -> get ( sprintf ( 'format/%s/%s' , $ this -> registry -> get ( 'env' ) , self :: $ reverseLevel [ $ args -> get ( 'level' ) ] ) , self :: DEFAULT_FORMAT ) ; $ backtrace = debug_backtrace ( DEBUG_BACKTRACE_IGNORE_ARGS , 5 ) ; $ message = str_replace ( [ '%DATE%' , '%TIME%' , '%LEVEL%' , '%SOURCE%' , '%FILE%' , '%LINE%' , '%MESSAGE%' , ] , [ date ( 'Y-m-d' ) , date ( 'H:i:s' ) , self :: $ levelToString [ $ args -> get ( 'level' ) ] , $ args -> get ( 'source' ) , $ backtrace [ 4 ] [ 'file' ] , $ backtrace [ 4 ] [ 'line' ] , $ args -> get ( 'message' ) ] , $ format ) ; return $ message ; } | Renders message according ro format . |
998 | public function isRemoteCheckRequired ( ) { if ( $ this -> uid && $ this -> sessionToken && $ this -> recheck ) { if ( $ this -> recheck > ( new DateTime ( 'NOW' ) ) ) { return false ; } } return true ; } | Check whether we need to remotely check the session or not |
999 | public function getSessionCheckUrl ( ) { $ url = Maestrano :: with ( $ this -> _preset ) -> sso ( ) -> getSessionCheckUrl ( $ this -> uid , $ this -> sessionToken ) ; return $ url ; } | Return the full url from which session check should be performed |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.