idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
17,600
public static function register ( $ alias , $ config ) { if ( is_array ( $ config ) ) { $ name = $ config [ 'class' ] ; $ singleton = ! empty ( $ config [ 'singleton' ] ) ; unset ( $ config [ 'class' ] , $ config [ 'singleton' ] ) ; static :: $ classNames [ $ name ] = static :: $ classAliases [ $ alias ] = [ 'singleton' => $ singleton , 'class' => $ name , 'alias' => $ alias , 'properties' => $ config , ] ; } elseif ( is_callable ( $ config ) ) { static :: $ classAliases [ $ alias ] = [ 'class' => $ config , 'alias' => $ alias , 'properties' => [ ] ] ; } else { throw new ContainerException ( 'Configuration must be an array or callable.' ) ; } unset ( static :: $ instances [ $ alias ] ) ; }
Registry class .
17,601
public static function isSingleton ( $ name ) { if ( ! static :: exists ( $ name ) ) { return false ; } if ( empty ( static :: $ classNames [ $ name ] [ 'singleton' ] ) && empty ( static :: $ classAliases [ $ name ] [ 'singleton' ] ) ) { return false ; } return true ; }
Is single of class .
17,602
public function getPagePath ( ) { $ core = $ this -> getLoops ( ) -> getService ( "web_core" ) ; $ page = $ core -> page ; $ pagepath = $ page === $ this ? "" : WebCore :: getPagePathFromClassname ( $ page , $ core -> page_parameter ) ; return implode ( "/" , $ pagepath ? array_merge ( [ $ pagepath ] , $ core -> parameter ) : $ core -> parameter ) ; }
Returns the page path
17,603
public function load ( $ id ) { $ this -> isNew = false ; $ dbr = wfGetDB ( DB_SLAVE ) ; $ entity = $ dbr -> selectRow ( static :: $ table , '*' , array ( 'id' => intval ( $ id ) ) ) ; if ( ! $ entity ) { $ this -> error = true ; return false ; throw new Exception ( get_called_class ( ) . ": there is no entity with id = $id in table " . static :: $ table ) ; } foreach ( $ this -> properties as $ prop => $ type ) { if ( ! isset ( $ entity -> $ prop ) && $ entity -> $ prop !== null ) throw new Exception ( get_called_class ( ) . ": No such field $prop in table " . static :: $ table . "." ) ; if ( $ prop == 'id' ) { $ this -> id = $ entity -> $ prop ; continue ; } if ( $ type == 'int' ) { $ this -> values [ $ prop ] = intval ( $ entity -> $ prop ) ; } else { $ this -> values [ $ prop ] = $ entity -> $ prop ; } } return true ; }
Loads entity from database .
17,604
public function count ( $ where = 'all' , $ options = array ( ) ) { $ dbr = wfGetDB ( DB_SLAVE ) ; if ( ! is_array ( $ where ) && $ where == 'all' ) { $ collection = $ dbr -> select ( static :: $ table , 'id' , array ( ) , __METHOD__ , $ options ) ; } else { $ collection = $ dbr -> select ( static :: $ table , 'id' , $ where , __METHOD__ , $ options ) ; } if ( ! $ collection ) return 0 ; $ count = $ dbr -> numRows ( $ collection ) ; return $ count ; }
Count entities . There some code that should be fixed .
17,605
public function save ( $ propvalues = null , $ reserved = false ) { $ dbr = wfGetDB ( DB_MASTER ) ; $ dbr -> begin ( ) ; $ sourceprops = $ this -> properties ; $ insertId = null ; foreach ( $ sourceprops as $ prop => $ type ) { $ sourceprops [ $ prop ] = ( isset ( $ this -> values [ $ prop ] ) ) ? $ this -> values [ $ prop ] : '' ; } if ( $ propvalues != null && is_array ( $ propvalues ) ) { if ( array_key_exists ( 'id' , $ propvalues ) ) throw new Exception ( 'ORM.Model: `id` parameter cant be passed in poperties array.' ) ; foreach ( $ propvalues as $ prop => $ value ) { if ( isset ( $ this -> properties [ $ prop ] ) ) $ sourceprops [ $ prop ] = $ value ; } } $ sourceprops [ 'id' ] = $ this -> id ; if ( $ this -> isNew ) { $ dbr -> insert ( static :: $ table , $ sourceprops , __METHOD__ ) ; $ insertId = $ dbr -> insertId ( ) ; } else { if ( ! is_numeric ( $ this -> id ) ) throw new Exception ( 'WikivoteVoting: There is no `id` field on exesting entity update. Fatal error.' ) ; $ dbr -> update ( static :: $ table , $ sourceprops , array ( 'id' => $ this -> id ) , __METHOD__ ) ; $ insertId = $ this -> id ; } $ dbr -> commit ( ) ; return $ insertId ; }
Save entity instance in database .
17,606
public static function find ( $ where = 'all' , $ options = array ( ) ) { $ dbr = wfGetDB ( DB_SLAVE ) ; if ( ! is_array ( $ where ) && $ where == 'all' ) { $ collection = $ dbr -> select ( static :: $ table , 'id' , array ( ) , __METHOD__ , $ options ) ; } else { $ collection = $ dbr -> select ( static :: $ table , 'id' , $ where , __METHOD__ , $ options ) ; } if ( ! $ collection ) return array ( ) ; $ entities = array ( ) ; foreach ( $ collection as $ row ) { $ modelClass = get_called_class ( ) ; $ entity = new $ modelClass ( $ row -> id ) ; $ entities [ ] = $ entity ; } if ( ! count ( $ entities ) ) return array ( ) ; return $ entities ; }
Fetch collection of entities
17,607
public function validate ( $ req = array ( ) , $ input = null ) { global $ wgRequest ; if ( ! is_array ( $ req ) ) $ req = array ( $ req ) ; if ( $ input == null ) { $ input = $ wgRequest -> getValues ( ) ; } if ( isset ( $ _POST [ 'title' ] ) ) { $ input [ 'title' ] = htmlspecialchars ( $ _POST [ 'title' ] ) ; } foreach ( $ input as $ param => $ value ) { if ( array_key_exists ( $ param , $ this -> properties ) ) { switch ( $ this -> properties [ $ param ] ) { case 'int' : break ; case 'string' : break ; } if ( ( empty ( $ value ) || $ value == '' ) && array_key_exists ( $ param , $ req ) ) return false ; $ this -> $ param = $ value ; } } return true ; }
Invalidates model from request
17,608
private function initTransports ( ) { $ this -> transports = array ( ) ; foreach ( $ this -> loadTransports ( ) as $ transport ) { if ( ! $ transport instanceof TransportInterface ) { throw new \ InvalidArgumentException ( sprintf ( 'Transport %s should implements TransportInterface' , get_class ( $ transport ) ) ) ; } $ this -> transports [ $ transport -> getName ( ) ] = $ transport ; } }
Initializes the transports .
17,609
protected function mergeValues ( array $ values , $ merge = true ) { $ this -> values = $ merge ? array_merge ( $ this -> values , $ values ) : $ values ; return $ this ; }
Add values to view
17,610
final protected function error ( $ message , $ status = null , $ nl = true ) { $ this -> io -> error ( $ message , $ status , $ nl ) ; }
Write to STDERR
17,611
final protected function silentRead ( $ prompt = null , $ nl = null ) { if ( $ prompt !== null ) { $ this -> io -> write ( $ prompt , false ) ; } return $ this -> io -> silentReadLine ( $ nl ) ; }
Silent read from STDIN
17,612
public static function create ( Query $ query ) : QueryMessage { $ timestamp = DateTime :: now ( ) ; $ id = MessageId :: generate ( ) ; $ metaData = MetaData :: create ( ) ; return new static ( $ id , $ timestamp , $ query , $ metaData ) ; }
Creates instance for a query
17,613
public function middleware ( ... $ middlewares ) { foreach ( $ middlewares as $ middleware ) { $ this -> currentContext -> addMiddleware ( $ middleware ) ; } return $ this ; }
Adds middleware to the current context
17,614
public function request ( string $ path , int $ methods , $ handler ) { $ path = $ this -> currentContext -> getPrefixedPath ( trim ( $ path , "\n\r\t/ " ) ) ; return $ this -> route ( new Route ( $ path , $ methods ) , $ handler ) ; }
Adds a new route with given path to the current context that accepts the given methods requests .
17,615
private function resultToResponse ( $ result ) : Response { switch ( true ) { case $ result instanceof Response : return $ result ; case is_string ( $ result ) || is_numeric ( $ result ) : return new Response ( $ result ) ; case is_array ( $ result ) || is_object ( $ result ) : return new JsonResponse ( $ result ) ; default : throw new Exception ( 'Invalid route handler return value' ) ; } }
Transforms any skalar handler result to a ieu \ Http \ Response object
17,616
public function hookFilter ( $ text , $ filter , & $ filtered ) { if ( ! isset ( $ filtered ) && ( ! isset ( $ filter [ 'filter_id' ] ) || $ filter [ 'filter_id' ] === 'xss' ) ) { $ filtered = $ this -> filter ( $ text ) ; } }
Implements hook filter
17,617
public function has ( $ key ) { $ menu = $ this -> getMenu ( $ key ) ; return ! is_null ( $ menu ) && $ menu -> count ( ) > 0 ; }
Check if there are navigation items .
17,618
public function setUrl ( $ url ) { if ( ! str_contains ( $ this -> cells , ':' ) ) { $ this -> sheet -> getCell ( $ this -> cells ) -> getHyperlink ( ) -> setUrl ( $ url ) ; } return $ this ; }
Set cell url
17,619
protected function setColorStyle ( $ styleType , $ color , $ type = false , $ colorType = 'rgb' ) { $ styles = is_array ( $ color ) ? $ color : [ 'type' => $ type , 'color' => [ $ colorType => str_replace ( '#' , '' , $ color ) ] , ] ; return $ this -> setStyle ( $ styleType , $ styles ) ; }
Set the color style
17,620
public function populate ( array $ values = [ ] ) { foreach ( $ values as $ key => $ value ) { $ methodName = "set{$key}" ; if ( method_exists ( $ this , $ methodName ) ) { if ( in_array ( $ key , $ this -> dateTimeKeys ) ) { $ value = new \ DateTime ( $ value , new \ DateTimeZone ( 'UTC' ) ) ; } elseif ( in_array ( $ key , $ this -> classKeys ) && ! is_null ( $ value ) ) { $ populateValue = $ value ; $ className = sprintf ( '%s\%s' , __NAMESPACE__ , $ key ) ; $ value = new $ className ( ) ; $ value -> populate ( $ populateValue ) ; } elseif ( array_key_exists ( $ key , $ this -> arrayClassKeys ) ) { $ arrayValues = $ value ; $ value = [ ] ; $ className = sprintf ( '%s\%s' , __NAMESPACE__ , $ this -> arrayClassKeys [ $ key ] ) ; foreach ( $ arrayValues as $ v ) { $ class = new $ className ( ) ; $ class -> populate ( $ v ) ; $ value [ ] = $ class ; } } $ this -> $ methodName ( $ value ) ; } } return $ this ; }
Populate the class
17,621
public static function subStringBeforeLast ( $ haystack , $ needle , $ n = 1 ) { while ( $ n > 0 ) { $ haystack = substr ( $ haystack , 0 , strrpos ( $ haystack , $ needle ) ) ; $ n -- ; } return $ haystack ; }
Get the substring before the last occurence of a character
17,622
public static function subStringAfterLast ( $ haystack , $ needle , $ n = 1 ) { $ string = "" ; while ( $ n > 0 ) { $ string .= substr ( $ haystack , strrpos ( $ haystack , $ needle ) + 1 ) ; if ( $ n > 1 ) { $ string = $ needle . $ string ; } $ n -- ; } return $ string ; }
Get the substring after the last occurrence of a character
17,623
protected function _containerUnset ( & $ container , $ key ) { $ origKey = $ key ; $ key = $ this -> _normalizeKey ( $ key ) ; if ( is_array ( $ container ) ) { if ( ! isset ( $ container [ $ key ] ) ) { throw $ this -> _createNotFoundException ( $ this -> __ ( 'Key "%1$s" not found' , [ $ key ] ) , null , null , null , $ key ) ; } unset ( $ container [ $ key ] ) ; return ; } if ( $ container instanceof stdClass ) { if ( ! isset ( $ container -> { $ key } ) ) { throw $ this -> _createNotFoundException ( $ this -> __ ( 'Key "%1$s" not found' , [ $ key ] ) , null , null , null , $ key ) ; } unset ( $ container -> { $ key } ) ; return ; } if ( $ container instanceof ArrayAccess ) { try { $ hasKey = $ container -> offsetExists ( $ key ) ; } catch ( RootException $ e ) { throw $ this -> _createContainerException ( $ this -> __ ( 'Could not check key "%1$s" on container' , [ $ key ] ) , null , $ e , null ) ; } if ( ! $ hasKey ) { throw $ this -> _createNotFoundException ( $ this -> __ ( 'Key "%1$s" not found' , [ $ key ] ) , null , null , null , $ key ) ; } try { $ container -> offsetUnset ( $ key ) ; return ; } catch ( RootException $ e ) { throw $ this -> _createContainerException ( $ this -> __ ( 'Could not unset key "%1$s" on container' , [ $ key ] ) , null , $ e , null ) ; } } throw $ this -> _createInvalidArgumentException ( $ this -> __ ( 'Invalid container' ) , null , null , $ container ) ; }
Unsets a value with the specified key on the given container .
17,624
public static function concat ( $ file ) { $ args = array ( ) ; $ len = func_num_args ( ) ; for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { $ value = func_get_arg ( $ i ) ; $ values = is_array ( $ value ) ? array_values ( $ value ) : array ( $ value ) ; $ args = array_merge ( $ args , $ values ) ; } return rtrim ( preg_replace ( "/\/+/" , "/" , Text :: concat ( "/" , $ args ) ) , "/" ) ; }
Concatenates filenames .
17,625
public static function getHumanSize ( $ size , $ precision = 1 ) { $ units = array ( " bytes" , "K" , "M" , "G" , "T" , "P" , "E" , "Z" , "Y" ) ; $ pow = 1024 ; $ factor = 0 ; while ( $ size + 1 > $ pow ) { $ size /= $ pow ; $ factor ++ ; } return round ( $ size , $ precision ) . $ units [ $ factor ] ; }
Gets a human readable size .
17,626
public static function getAvailName ( $ dir , $ refname = "" , $ refext = "" ) { $ dir = trim ( $ dir ) ; $ refname = trim ( $ refname ) ; $ refext = ltrim ( trim ( $ refext ) , "." ) ; if ( ! is_dir ( $ dir ) ) { throw new SysException ( "Directory not found: $dir" ) ; } if ( Text :: isEmpty ( $ refname ) ) { $ refname = "file" ; } $ refname = basename ( $ refname ) ; $ pos = strrpos ( $ refname , "." ) ; $ name = $ refname ; $ ext = $ refext ; if ( $ pos !== false ) { $ name = substr ( $ refname , 0 , $ pos ) ; if ( Text :: isEmpty ( $ refext ) ) { $ ext = substr ( $ refname , $ pos + 1 ) ; } } for ( $ i = 0 ; $ i < 100 ; $ i ++ ) { $ basename = $ i > 0 ? Text :: concat ( "." , $ name . "_" . $ i , $ ext ) : Text :: concat ( "." , $ name , $ ext ) ; $ filename = SysFile :: concat ( $ dir , $ basename ) ; if ( ! is_file ( $ filename ) ) { break ; } } return $ filename ; }
Gets an available name under a given directory .
17,627
public static function getInfo ( $ path ) { $ info = pathinfo ( $ path ) ; return array ( "dirname" => Arr :: get ( $ info , "dirname" , "" ) , "basename" => Arr :: get ( $ info , "basename" , "" ) , "extension" => Arr :: get ( $ info , "extension" , "" ) , "filename" => Arr :: get ( $ info , "filename" , "" ) ) ; }
Gets the information of a file path .
17,628
protected function insertDeveloper ( ) { $ data = $ this -> getPatchData ( ) ; $ create = $ data -> get ( 'gridguyz-core' , 'developer' , 'Do you want to create a developer user? (y/n)' , 'n' , array ( 'y' , 'n' , 'yes' , 'no' , 't' , 'f' , 'true' , 'false' , '1' , '0' ) ) ; if ( in_array ( strtolower ( $ create ) , array ( 'n' , 'no' , 'f' , 'false' , '0' , '' ) ) ) { return null ; } $ email = $ data -> get ( 'gridguyz-core' , 'developer-email' , 'Type the developer\'s email (must be valid email)' , null , '/^[A-Z0-9\._%\+-]+@[A-Z0-9\.-]+\.[A-Z]{2,4}$/i' , 3 ) ; $ displayName = $ data -> get ( 'gridguyz-core' , 'developer-displayName' , 'Type the developer\'s display name' , strstr ( $ email , '@' , true ) ) ; $ password = $ data -> get ( 'gridguyz-core' , 'developer-password' , 'Type the developer\'s password' , $ this -> createPasswordSalt ( 6 ) , true ) ; return $ this -> insertIntoTable ( 'user' , array ( 'email' => $ email , 'displayName' => $ displayName , 'passwordHash' => $ this -> createPasswordHash ( $ password ) , 'groupId' => static :: DEVELOPER_GROUP , 'state' => 'active' , 'confirmed' => 't' , 'locale' => 'en' , ) , true ) ; }
Insert developer user
17,629
protected function insertPlatformOwner ( ) { $ data = $ this -> getPatchData ( ) ; $ email = $ data -> get ( 'gridguyz-core' , 'platformOwner-email' , 'Type the platform owner\'s email (must be valid email)' , null , '/^[A-Z0-9\._%\+-]+@[A-Z0-9\.-]+\.[A-Z]{2,4}$/i' , 3 ) ; $ displayName = $ data -> get ( 'gridguyz-core' , 'platformOwner-displayName' , 'Type the platform owner\'s display name' , strstr ( $ email , '@' , true ) ) ; $ password = $ data -> get ( 'gridguyz-core' , 'platformOwner-password' , 'Type the platform owner\'s password' , $ this -> createPasswordSalt ( 6 ) , true ) ; return $ this -> insertIntoTable ( 'user' , array ( 'email' => $ email , 'displayName' => $ displayName , 'passwordHash' => $ this -> createPasswordHash ( $ password ) , 'groupId' => static :: SITE_OWNER_GROUP , 'state' => 'active' , 'confirmed' => 't' , 'locale' => 'en' , ) , true ) ; }
Insert platform - owner user
17,630
protected function createPasswordHash ( $ password ) { if ( function_exists ( 'password_hash' ) ) { return password_hash ( $ password , PASSWORD_DEFAULT ) ; } if ( ! defined ( 'CRYPT_BLOWFISH' ) ) { throw new Exception \ RuntimeException ( sprintf ( '%s: CRYPT_BLOWFISH algorithm must be enabled' , __METHOD__ ) ) ; } return crypt ( $ password , ( version_compare ( PHP_VERSION , '5.3.7' ) >= 0 ? '$2y' : '$2a' ) . '$10$' . $ this -> createPasswordSalt ( ) . '$' ) ; }
Create password hash
17,631
private function createPasswordSalt ( $ length = 22 ) { static $ chars = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' ; if ( function_exists ( 'openssl_random_pseudo_bytes' ) && ( version_compare ( PHP_VERSION , '5.3.4' ) >= 0 || strtoupper ( substr ( PHP_OS , 0 , 3 ) ) !== 'WIN' ) ) { $ bytes = openssl_random_pseudo_bytes ( $ length , $ usable ) ; if ( true !== $ usable ) { $ bytes = null ; } } if ( empty ( $ bytes ) && function_exists ( 'mcrypt_create_iv' ) && ( version_compare ( PHP_VERSION , '5.3.7' ) >= 0 || strtoupper ( substr ( PHP_OS , 0 , 3 ) ) !== 'WIN' ) ) { $ bytes = mcrypt_create_iv ( $ length , MCRYPT_DEV_URANDOM ) ; if ( empty ( $ bytes ) || strlen ( $ bytes ) < $ length ) { $ bytes = null ; } } if ( empty ( $ bytes ) ) { $ bytes = '' ; for ( $ i = 0 ; $ i < $ length ; ++ $ i ) { $ bytes .= chr ( mt_rand ( 0 , 255 ) ) ; } } $ pos = 0 ; $ salt = '' ; $ clen = strlen ( $ chars ) ; for ( $ i = 0 ; $ i < $ length ; ++ $ i ) { $ pos = ( $ pos + ord ( $ bytes [ $ i ] ) ) % $ clen ; $ salt .= $ chars [ $ pos ] ; } return $ salt ; }
Create password - salt
17,632
protected function insertDefaultMenu ( $ content ) { $ root = $ this -> insertIntoTable ( 'menu' , array ( 'type' => 'container' , 'left' => 1 , 'right' => 4 , ) , true ) ; $ this -> insertIntoTable ( 'menu_label' , array ( 'menuId' => $ root , 'locale' => 'en' , 'label' => 'Default menu' , ) ) ; $ menuContent = $ this -> insertIntoTable ( 'menu' , array ( 'type' => 'content' , 'left' => 2 , 'right' => 3 , ) , true ) ; $ this -> insertIntoTable ( 'menu_label' , array ( 'menuId' => $ menuContent , 'locale' => 'en' , 'label' => 'Home' , ) ) ; $ this -> insertIntoTable ( 'menu_property' , array ( 'menuId' => $ menuContent , 'name' => 'contentId' , 'value' => $ content , ) ) ; return $ root ; }
Insert default menu
17,633
protected function appendCustomizeGlobalExtra ( $ globalExtraCss , $ schema = null ) { $ where = array ( 'rootParagraphId' => null ) ; $ table = 'customize_extra' ; if ( $ schema ) { $ table = array ( $ schema , $ table ) ; } $ current = $ this -> selectFromTable ( $ table , 'extra' , $ where ) ; if ( null === $ current ) { $ update = $ this -> updateTable ( $ table , array ( 'extra' => $ globalExtraCss , ) , $ where ) ; if ( ! $ update ) { return ( bool ) $ this -> insertIntoTable ( $ table , array ( 'rootParagraphId' => null , 'extra' => $ globalExtraCss , ) , true ) ; } return ( bool ) $ update ; } return ( bool ) $ this -> updateTable ( $ table , array ( 'extra' => $ current . "\n\n" . $ globalExtraCss , ) , $ where ) ; }
Append global extra css to customize
17,634
protected function mergePackagesConfig ( ) { $ this -> getInstaller ( ) -> mergeConfigData ( 'packages.local' , include __DIR__ . '/../../../../config/default.packages.php' , function ( & $ config ) { if ( ! empty ( $ config [ 'modules' ] [ 'Grid\Core' ] [ 'enabledPackages' ] ) ) { foreach ( $ config [ 'modules' ] [ 'Grid\Core' ] [ 'enabledPackages' ] as & $ packages ) { if ( ! is_array ( $ packages ) ) { $ packages = array ( $ packages => ( string ) $ packages ) ; } $ packages = array_unique ( array_map ( 'strtolower' , array_filter ( $ packages , function ( $ package ) { return ( bool ) preg_match ( '#^[a-z0-9_-]+/[a-z0-9_-]+$#i' , $ package ) ; } ) ) ) ; } } return $ config ; } ) ; }
Merge packages config
17,635
public function propertyContextFromReflection ( \ ReflectionProperty $ property , $ original ) { $ property -> setAccessible ( true ) ; $ context = new PropertyContext ( $ property -> name , $ property -> getValue ( $ original ) , $ property -> class ) ; return $ this -> parseAnnotations ( $ context , $ property , $ original ) ; }
Responsible for building property representation from \ ReflectionProperties in the form of PropertyContext
17,636
private function parseAnnotations ( PropertyContext $ context , \ ReflectionProperty $ property , $ original ) { $ annot = $ this -> propertyHandler -> getPropertyAnnotation ( $ property ) ; if ( $ annot ) { $ context = $ this -> handleRepresentProperty ( $ property , $ annot , $ context , $ original ) ; } return $ context ; }
Parses properties for annotations and delegates the handling of those annotations
17,637
private function handleRepresentProperty ( \ ReflectionProperty $ property , Property $ annot , PropertyContext $ context , $ original ) { if ( $ annot -> getName ( ) ) { $ context -> name = $ annot -> getName ( ) ; } if ( $ annot -> getType ( ) ) { $ context -> value = $ this -> propertyHandler -> handleTypeConversion ( $ annot -> getType ( ) , $ property -> getValue ( $ original ) ) ; } return $ context ; }
Handles dealing with Represent \ Property annotation
17,638
public function registerShortcodes ( ) { if ( ! function_exists ( 'add_shortcode' ) ) { return ; } $ this -> shortcodes -> rewind ( ) ; while ( $ this -> shortcodes -> valid ( ) ) { $ shortcode = $ this -> shortcodes -> current ( ) ; add_shortcode ( $ shortcode -> getName ( ) , array ( $ shortcode , 'getCallback' ) ) ; $ this -> shortcodes -> next ( ) ; } }
Registers all shortcodes added
17,639
public function subscribe ( IObserver $ observer ) : IObservable { if ( ! \ in_array ( $ observer , $ this -> _observers , true ) ) { $ this -> _observers [ ] = $ observer ; } return $ this ; }
Subscribe a new observer to this observable implementation .
17,640
public function notify ( $ extras = null ) : IObservable { if ( 1 < \ count ( $ this -> _cache ) ) { $ this -> _cache [ ] = $ extras ; } else { $ this -> _cache = $ extras ; } foreach ( $ this -> _observers as $ ob ) { $ ob -> onUpdate ( $ this , $ this -> _cache ) ; } $ this -> _cache = [ ] ; return $ this ; }
Notify all subscribed observers
17,641
public function isFirstCall ( ) { if ( ! $ this -> stepAction && $ this -> stepCollection -> isFirst ( $ this -> stepCollectionIterator -> current ( ) ) ) return true ; else return false ; }
checks if the wizard is first time called
17,642
public function process ( ) { $ currentStep = $ this -> stepCollectionIterator -> current ( ) ; if ( $ this -> stepAction == self :: WIZARD_STEP_ACTION_PREV && ! $ this -> stepCollection -> isFirst ( $ this -> stepCollectionIterator -> current ( ) ) ) { $ currentStep -> leaveToAncestorStep ( ) ; $ this -> stepCollectionIterator -> previous ( ) ; $ ancestorStep = $ this -> stepCollectionIterator -> current ( ) ; $ ancestorStep -> enterFromDescendant ( ) ; $ this -> resultContent = $ this -> prepareNextStepView ( $ ancestorStep ) ; } elseif ( $ this -> stepAction == self :: WIZARD_STEP_ACTION_PREV && $ this -> stepCollection -> isFirst ( $ this -> stepCollectionIterator -> current ( ) ) ) { $ this -> resultContent = new ResponseConfigurator ( ) ; } if ( $ this -> stepAction == self :: WIZARD_STEP_ACTION_NEXT ) { $ currentStep -> preProcess ( ) ; if ( $ currentStep -> process ( $ currentStep -> standardClosureArguments ( ) ) ) { $ currentStep -> postProcess ( ) ; $ currentStep -> leaveStep ( ) ; $ this -> stepCollectionIterator -> next ( ) ; $ descendantStep = $ this -> stepCollectionIterator -> current ( ) ; $ descendantStep -> enterStep ( ) ; $ this -> resultContent = $ this -> prepareNextStepView ( $ descendantStep ) ; } else { $ this -> resultContent = $ this -> prepareNextStepView ( $ currentStep ) ; $ this -> resultContent -> setVariable ( "errorMessage" , $ currentStep -> getProcessErrorMessage ( ) ) ; } } }
processing the step
17,643
private function createBreadcrumbItems ( StepController $ step ) { $ viewModel = new ViewModel ( ) ; $ viewModel -> setTemplate ( $ this -> breadcrumbTemplatePath ) ; $ viewModel -> setVariable ( "breadcrumbTitle" , $ step -> getBreadCrumbTitle ( ) ) ; $ viewModel -> setVariable ( "stepNumber" , $ step -> getBreadCrumbTitle ( ) ) ; return $ viewModel ; }
generate one elementView for the breadcrumb path
17,644
private function initStepViewModel ( ) { $ currentStep = $ this -> stepCollectionIterator -> current ( ) ; $ isFirstStep = $ this -> getSteps ( ) -> isFirst ( $ currentStep ) ; if ( $ isFirstStep ) { $ firstStep = $ this -> getSteps ( ) -> getFirst ( ) ; $ this -> viewModel -> addChild ( $ firstStep -> getViewModel ( ) , "wizardContent" ) ; $ firstStepFormName = $ firstStep -> getViewModel ( ) -> getVariable ( "formName" , false ) ; if ( empty ( $ firstStepFormName ) ) throw new \ Exception ( "viewModel variable 'formName' must set for Step '" . $ firstStep -> getName ( ) . "'" ) ; } if ( ! ( $ this -> prevButtonDisabled && $ isFirstStep ) ) { $ this -> prevButtonViewModel = new ViewModel ( ) ; $ this -> prevButtonViewModel -> setTemplate ( "wizard/wizardButton" ) ; $ this -> prevButtonViewModel -> setVariable ( "stepActionDirection" , "prev" ) ; $ this -> prevButtonViewModel -> setVariable ( "id" , "prevButton" ) ; } $ this -> nextButtonViewModel = new ViewModel ( ) ; $ this -> nextButtonViewModel -> setTemplate ( "wizard/wizardButton" ) ; $ this -> nextButtonViewModel -> setVariable ( "stepActionDirection" , "next" ) ; $ this -> nextButtonViewModel -> setVariable ( "id" , "nextButton" ) ; $ stepIterator = $ this -> getSteps ( ) -> getIterator ( ) ; while ( $ stepIterator -> valid ( ) ) { $ view = $ this -> createBreadcrumbItems ( $ stepIterator -> current ( ) ) ; $ this -> getSteps ( ) -> isFirst ( $ stepIterator -> current ( ) ) ? $ view -> setVariable ( "extendCssClass" , "active first" ) : false ; $ this -> getSteps ( ) -> isLast ( $ stepIterator -> current ( ) ) ? $ view -> setVariable ( "extendCssClass" , "last" ) : false ; $ view -> setVariable ( "breadcrumbStepName" , $ stepIterator -> current ( ) -> getName ( ) ) ; $ this -> viewModel -> addChild ( $ view , "breadcrumbNavigation" , true ) ; $ stepIterator -> next ( ) ; } $ this -> resultContent = $ this -> viewModel ; $ this -> process ( ) ; }
init the ViewModel for the wizard
17,645
private function toggleStandardWizardButtons ( $ show = true ) { $ this -> prevButtonViewModel -> setVariable ( "btnClass_extend" , ( ! $ show ? "hide" : "" ) , true ) ; $ this -> nextButtonViewModel -> setVariable ( "btnClass_extend" , ( ! $ show ? "hide" : "" ) , true ) ; }
toggle the visibility of the wizardbutton depending on wether the step is the last one or not
17,646
public static function assertLooselyEquals ( $ actual , $ expected , Throwable $ exception ) { static :: makeAssertion ( $ actual == $ expected , $ exception ) ; return $ actual ; }
Asserts that the given values are loosely equals .
17,647
public static function assertEquals ( $ actual , $ expected , Throwable $ exception ) { static :: makeAssertion ( $ actual === $ expected , $ exception ) ; return $ actual ; }
Asserts that the given values are strictly equals .
17,648
public static function assertLooselyNotEquals ( $ actual , $ expected , Throwable $ exception ) { static :: makeAssertion ( $ actual != $ expected , $ exception ) ; return $ actual ; }
Asserts that the given values are loosely not equals .
17,649
public static function assertNotEquals ( $ actual , $ expected , Throwable $ exception ) { static :: makeAssertion ( $ actual !== $ expected , $ exception ) ; return $ actual ; }
Asserts that the given values are strictly not equals .
17,650
public static function assertGreaterThanOrEquals ( $ actual , $ expected , Throwable $ exception ) : bool { static :: makeAssertion ( $ actual >= $ expected , $ exception ) ; return true ; }
Asserts that the given actual value is greater than or equals the expected value .
17,651
public static function assertGreaterThan ( $ actual , $ expected , Throwable $ exception ) : bool { static :: makeAssertion ( $ actual > $ expected , $ exception ) ; return true ; }
Asserts that the given actual value is strictly greater than the expected value .
17,652
public static function assertLessThanOrEquals ( $ actual , $ expected , Throwable $ exception ) : bool { static :: makeAssertion ( $ actual <= $ expected , $ exception ) ; return true ; }
Asserts that the given actual value is less than or equals the expected value .
17,653
public static function assertLessThan ( $ actual , $ expected , Throwable $ exception ) : bool { static :: makeAssertion ( $ actual < $ expected , $ exception ) ; return true ; }
Asserts that the given actual value is strictly less than the expected value .
17,654
public function output ( $ type = null ) { $ session = $ this -> _di -> getService ( "session" ) ; $ messages = $ session -> get ( "__flash__" ) ; if ( $ messages == null ) { return ; } if ( isset ( $ type ) ) { $ messages_type = implode ( $ messages [ $ type ] ) ; $ messages [ $ type ] = array ( ) ; $ session -> set ( "__flash__" , $ messages ) ; return $ messages_type ; } $ all_messages_str = "" ; foreach ( $ messages as $ messages_type ) { $ all_messages_str .= implode ( $ messages_type ) ; } $ session -> set ( "__flash__" , array ( ) ) ; return $ all_messages_str ; }
Returns the messages
17,655
public function contentUriAction ( ) { $ actual = $ this -> getSubDomainModel ( ) -> findActual ( ) ; if ( empty ( $ actual ) ) { $ this -> getResponse ( ) -> setStatusCode ( 404 ) ; return ; } $ uri = $ this -> params ( ) -> fromRoute ( 'uri' ) ; if ( ! mb_check_encoding ( $ uri , 'UTF-8' ) ) { $ this -> getResponse ( ) -> setStatusCode ( 404 ) ; return ; } $ structure = $ this -> getUriModel ( ) -> findBySubdomainUri ( $ actual -> id , $ uri ) ; if ( empty ( $ structure ) ) { $ this -> paragraphLayout ( ) ; $ this -> getResponse ( ) -> setStatusCode ( 404 ) ; return ; } if ( ! $ structure -> default ) { $ default = $ this -> getUriModel ( ) -> findDefaultByContentSubdomain ( $ structure -> contentId , $ actual -> id , $ structure -> locale ) ; if ( $ default -> uri != $ structure -> uri ) { $ response = $ this -> getResponse ( ) ; $ response -> getHeaders ( ) -> addHeaderLine ( 'Location' , '/' . $ default -> safeUri ) ; return $ response -> setStatusCode ( 301 ) ; } } if ( ! empty ( $ structure -> locale ) ) { $ this -> getServiceLocator ( ) -> get ( 'Locale' ) -> setCurrent ( $ structure -> locale ) ; } return $ this -> forward ( ) -> dispatch ( 'Grid\Paragraph\Controller\Render' , array ( 'controller' => 'Grid\Paragraph\Controller\Render' , 'action' => 'paragraph' , 'locale' => ( string ) $ this -> locale ( ) , 'paragraphId' => $ structure -> contentId ) ) ; }
Content - uri action
17,656
public function method ( $ name ) { $ method = new Method ( $ name ) ; $ this -> container -> put ( $ name , $ method ) ; return $ method ; }
Define a new mock method .
17,657
public function parse ( interfaces \ Tokens $ input , values \ Arguments $ arguments , values \ Options $ options ) : void { $ isParsingOptions = true ; $ input = $ input -> all ( ) ; while ( null !== $ token = array_shift ( $ input ) ) { if ( $ isParsingOptions ) { if ( '--' === $ token ) { $ isParsingOptions = false ; continue ; } if ( 0 === strpos ( $ token , '--' ) ) { $ this -> parseLongOption ( $ token , $ options , $ input ) ; continue ; } if ( '-' === $ token [ 0 ] ) { $ this -> parseShortOption ( $ token , $ options , $ input ) ; continue ; } } $ arguments -> push ( $ token ) ; } }
Fill the given Input Arguments and Options based on their definitions and the Argv input given .
17,658
protected function parseLongOption ( string $ token , values \ Options $ options , array & $ input ) : void { $ name = substr ( $ token , 2 ) ; $ value = null ; if ( false !== $ pos = strpos ( $ name , '=' ) ) { $ value = substr ( $ name , $ pos + 1 ) ; $ name = substr ( $ name , 0 , $ pos ) ; } if ( ! isset ( $ value ) && $ definition = $ options -> definitions ( ) -> get ( $ name ) and $ definition -> hasValue ( ) ) { if ( isset ( $ input [ 0 ] ) && '-' !== $ input [ 0 ] [ 0 ] ) { $ value = array_shift ( $ input ) ; } } $ options -> set ( $ name , $ value ) ; }
Parses the given token as a long option and adds it to the Options set .
17,659
protected function parseShortOption ( $ token , values \ Options $ options , array & $ input ) : void { if ( empty ( $ shortcut = substr ( $ token , 1 ) ) ) { return ; } foreach ( $ this -> resolveShortOption ( $ shortcut , $ options ) as $ name => $ value ) { $ options -> set ( $ name , $ value ) ; } }
Parses the given token as a short option and adds it to the Options set .
17,660
private function resolveShortOptionSet ( string $ shortcut , definitions \ Options $ definitions ) : array { $ length = strlen ( $ shortcut ) ; $ result = [ ] ; for ( $ i = 0 ; $ i < $ length ; $ i ++ ) { $ definition = $ definitions -> getByShortcut ( $ shortcut [ $ i ] ) ; if ( $ definition -> hasValue ( ) ) { $ result [ $ definition -> getName ( ) ] = $ i === $ length - 1 ? null : substr ( $ shortcut , $ i + 1 ) ; break ; } $ result [ $ definition -> getName ( ) ] = null ; } return $ result ; }
Takes a set of short options contained in a string and resolves them to full options and their values depending on the Definitions given .
17,661
public function update ( $ other ) { if ( is_array ( $ other ) ) { $ this -> _array = $ other ; return $ this ; } $ this -> _array = array ( ) ; foreach ( $ other as $ key => $ value ) { $ this -> _array [ $ key ] = $ value ; } return $ this ; }
Updates the values of this hash with the values of other .
17,662
public static function fromKeys ( $ keys ) { $ hash = new Dictionary ( ) ; foreach ( $ keys as $ key ) { $ hash [ $ key ] = NULL ; } return $ hash ; }
Constructs a Hash with the passed keys
17,663
public function getAllowedMethods ( ) { $ result = [ ] ; if ( $ this -> get ) { $ result [ ] = HttpMethods :: GET ; } if ( $ this -> post ) { $ result [ ] = HttpMethods :: POST ; } if ( $ this -> put ) { $ result [ ] = HttpMethods :: PUT ; } if ( $ this -> path ) { $ result [ ] = HttpMethods :: PATCH ; } if ( $ this -> delete ) { $ result [ ] = HttpMethods :: DELETE ; } if ( $ this -> head ) { $ result [ ] = HttpMethods :: HEAD ; } if ( $ this -> options ) { $ result [ ] = HttpMethods :: OPTIONS ; } return $ result ; }
Get array of allowed methods for this action
17,664
public function login ( Request $ request ) { $ this -> validateLogin ( $ request ) ; if ( $ this -> hasTooManyLoginAttempts ( $ request ) ) { $ this -> fireLockoutEvent ( $ request ) ; return $ this -> sendLockoutResponse ( $ request ) ; } $ this -> incrementLoginAttempts ( $ request ) ; if ( ! $ this -> attemptLogin ( $ request ) ) { return HCLog :: info ( 'AUTH-002' , trans ( 'HCACL::users.errors.login' ) ) ; } if ( auth ( ) -> user ( ) -> isNotActivated ( ) ) { $ user = auth ( ) -> user ( ) ; $ this -> logout ( $ request ) ; $ response = $ this -> activation -> sendActivationMail ( $ user ) ; return HCLog :: info ( 'AUTH-003' , $ response ) ; } auth ( ) -> user ( ) -> updateLastLogin ( ) ; return response ( [ 'success' => true , 'redirectURL' => session ( ) -> pull ( 'url.intended' , url ( '/' ) ) ] ) ; }
Function which login users
17,665
public function showActivation ( string $ token ) { $ message = null ; $ tokenRecord = DB :: table ( 'hc_users_activations' ) -> where ( 'token' , $ token ) -> first ( ) ; if ( is_null ( $ tokenRecord ) ) { $ message = trans ( 'HCACL::users.activation.token_not_exists' ) ; } else { if ( strtotime ( $ tokenRecord -> created_at ) + 60 * 60 * 24 < time ( ) ) { $ message = trans ( 'HCACL::users.activation.token_expired' ) ; } } return hcview ( 'HCACL::auth.activation' , [ 'token' => $ token , 'message' => $ message ] ) ; }
Show activation page
17,666
public function send ( ) { if ( ! static :: isSent ( ) ) { static :: call ( 'send' , $ this ) ; foreach ( $ this -> headers as $ header => $ value ) { $ this -> setHttpHeader ( $ header , $ value ) ; } http_response_code ( $ this -> status ) ; echo $ this -> body ; static :: $ sent = true ; return true ; } return false ; }
Bastelt den Response zusammen und sendet diesen ab sofern er noch nicht abgesendet wurde .
17,667
protected function isAllModulesLoaded ( array $ modules ) { foreach ( $ modules as $ module ) { if ( ! $ this -> isModuleLoaded ( $ module ) ) { return false ; } } return true ; }
Is all modules loaded
17,668
public function isModulesLoaded ( $ modules ) { if ( $ modules instanceof Traversable ) { $ modules = ArrayUtils :: iteratorToArray ( $ modules ) ; } if ( ! is_array ( $ modules ) ) { $ modules = preg_split ( '/\|{1,2}/' , ( string ) $ modules ) ; } foreach ( $ modules as $ module ) { if ( ! is_array ( $ module ) ) { $ module = preg_split ( '/&{1,2}/' , ( string ) $ module ) ; } if ( $ this -> isAllModulesLoaded ( $ module ) ) { return true ; } } return false ; }
Is any modules loaded
17,669
public static function factory ( $ type ) { if ( $ type instanceof TypeInterface ) return $ type ; if ( strpos ( $ type , "\\" ) === false ) { $ type = ucfirst ( trim ( strval ( $ type ) ) ) ; if ( strripos ( strrev ( $ type ) , strrev ( 'type' ) ) === false ) $ type .= 'Type' ; $ type = "DataEntity\\Type\\" . $ type ; } if ( ! class_exists ( $ type ) || ! in_array ( "DataEntity\\TypeInterface" , class_implements ( $ type ) ) ) throw new \ InvalidArgumentException ( 'Type ' . $ type . ' is invalid.' ) ; return new $ type ; }
Builds type objects
17,670
public static function to_assoc ( $ start = 1 ) { $ segments = array_slice ( static :: segments ( ) , ( $ start - 1 ) ) ; count ( $ segments ) % 2 and $ segments [ ] = null ; return \ Arr :: to_assoc ( $ segments ) ; }
Converts the current URI segments to an associative array . If the URI has an odd number of segments an empty value will be added .
17,671
public static function create ( $ uri = null , $ variables = array ( ) , $ get_variables = array ( ) , $ secure = null ) { $ url = '' ; is_null ( $ uri ) and $ uri = static :: string ( ) ; if ( ! preg_match ( "#^(http|https|ftp)://#i" , $ uri ) ) { $ url .= \ Config :: get ( 'base_url' ) ; if ( $ index_file = \ Config :: get ( 'index_file' ) ) { $ url .= $ index_file . '/' ; } } $ url .= ltrim ( $ uri , '/' ) ; if ( $ url_suffix = \ Config :: get ( 'url_suffix' , false ) and substr ( $ url , - 1 ) != '/' ) { $ current_suffix = strrchr ( $ url , '.' ) ; if ( ! $ current_suffix or strpos ( $ current_suffix , '/' ) !== false ) { $ url .= $ url_suffix ; } } if ( ! empty ( $ get_variables ) ) { $ char = strpos ( $ url , '?' ) === false ? '?' : '&' ; if ( is_string ( $ get_variables ) ) { $ url .= $ char . str_replace ( '%3A' , ':' , $ get_variables ) ; } else { $ url .= $ char . str_replace ( '%3A' , ':' , http_build_query ( $ get_variables ) ) ; } } array_walk ( $ variables , function ( $ val , $ key ) use ( & $ url ) { $ url = str_replace ( ':' . $ key , $ val , $ url ) ; } ) ; is_bool ( $ secure ) and $ url = http_build_url ( $ url , array ( 'scheme' => $ secure ? 'https' : 'http' ) ) ; return $ url ; }
Creates a url with the given uri including the base url
17,672
public static function base ( $ include_index = true ) { $ url = \ Config :: get ( 'base_url' ) ; if ( $ include_index and \ Config :: get ( 'index_file' ) ) { $ url .= \ Config :: get ( 'index_file' ) . '/' ; } return $ url ; }
Gets the base URL including the index_file if wanted .
17,673
public static function build_query_string ( ) { $ params = array ( ) ; foreach ( func_get_args ( ) as $ arg ) { $ arg = is_array ( $ arg ) ? $ arg : array ( $ arg => '1' ) ; $ params = array_merge ( $ params , $ arg ) ; } return http_build_query ( $ params ) ; }
Builds a query string by merging all array and string values passed . If a string is passed it will be assumed to be a switch and converted to string = 1 .
17,674
public static function update_query_string ( $ vars = array ( ) , $ uri = null , $ secure = null ) { if ( ! is_array ( $ vars ) ) { $ vars = array ( $ vars => $ uri ) ; $ uri = null ; } if ( $ uri === null ) { $ uri = static :: current ( ) ; $ vars = array_merge ( \ Input :: get ( ) , $ vars ) ; } return static :: create ( $ uri , array ( ) , $ vars , $ secure ) ; }
Updates the query string of the current or passed URL with the data passed
17,675
public function get_segment ( $ segment , $ default = null ) { if ( isset ( $ this -> segments [ $ segment - 1 ] ) ) { return $ this -> segments [ $ segment - 1 ] ; } return \ Fuel :: value ( $ default ) ; }
Get the specified URI segment return default if it doesn t exist .
17,676
public static function enablePdoConnection ( ) { if ( is_null ( self :: $ instance ) ) { global $ wpdb ; $ capsule = new self ( ) ; $ capsule -> addConnection ( [ 'driver' => 'mysql' , 'host' => DB_HOST , 'database' => DB_NAME , 'username' => DB_USER , 'password' => DB_PASSWORD , 'charset' => 'utf8mb4' , 'collation' => 'utf8mb4_general_ci' , ] ) ; $ capsule -> setAsGlobal ( ) ; $ capsule -> bootEloquent ( ) ; } }
Enable PDO for eloquent
17,677
public function getRequest ( ) { if ( null === $ this -> request ) { $ this -> setRequest ( $ this -> getController ( ) -> getRequest ( ) ) ; } return $ this -> request ; }
Get request to be authenticated
17,678
public function getAuthenticationAdapter ( ) { if ( null === $ this -> authenticationAdapter ) { $ authenticationAdapter = $ this -> getAuthenticationService ( ) -> getAdapter ( ) ; $ this -> setAuthenticationAdapter ( $ authenticationAdapter ) ; } return $ this -> authenticationAdapter ; }
Get authentication adapter
17,679
public static function toUriString ( Request $ request ) { $ uri = clone $ request -> getUri ( ) ; $ uri -> setQuery ( array_merge ( $ uri -> getQueryAsArray ( ) , $ request -> getQuery ( ) -> toArray ( ) ) ) ; return $ uri -> toString ( ) ; }
Converts the request into a url .
17,680
public function attach ( ReaderInterface $ reader , $ last = true ) { if ( $ last ) { $ this -> readers [ ] = $ reader ; } else { array_unshift ( $ this -> readers , $ reader ) ; } $ this -> groups = [ ] ; }
Attach a new config reader
17,681
public function detach ( ReaderInterface $ reader ) { if ( ( $ key = array_search ( $ reader , $ this -> readers ) ) !== false ) { unset ( $ this -> readers [ $ key ] ) ; } $ this -> groups = [ ] ; }
Detach a config reader
17,682
public function load ( $ groupName ) { if ( ! count ( $ this -> readers ) ) { throw new \ RuntimeException ( 'No config readers attached' ) ; } if ( ! $ groupName ) { throw new \ InvalidArgumentException ( 'No config group specified' ) ; } if ( ! is_string ( $ groupName ) ) { throw new \ InvalidArgumentException ( 'Config group must be a string' ) ; } if ( isset ( $ this -> groups [ $ groupName ] ) ) { return $ this -> groups [ $ groupName ] ; } $ config = [ ] ; foreach ( $ this -> readers as $ reader ) { if ( $ groupConfig = $ reader -> load ( $ groupName ) ) { $ config = array_replace_recursive ( $ config , $ groupConfig ) ; } } $ this -> groups [ $ groupName ] = $ config ; return $ this -> groups [ $ groupName ] ; }
Load configuration for a group
17,683
public function registerCall ( $ name , array $ arguments = [ ] ) { $ name = strtolower ( preg_replace ( "/([A-Z]{1})/" , "_$0" , $ name ) ) ; $ this -> calls = array_merge ( $ this -> calls , array_filter ( explode ( "_" , $ name ) ) ) ; if ( count ( $ arguments ) > 0 ) { $ lastIndex = count ( $ this -> calls ) - 1 ; $ this -> calls [ $ lastIndex ] = [ $ this -> calls [ $ lastIndex ] , $ arguments ] ; } }
Registers a call .
17,684
protected function findTemplateFile ( $ file ) { $ ext = pathinfo ( $ file , PATHINFO_EXTENSION ) ; $ file = ( $ ext === '' ) ? $ file . '.' . $ this -> getExtension ( ) : $ file ; $ found = false ; foreach ( $ this -> locations as $ location ) { if ( is_file ( $ location . '/' . $ file ) ) { $ found = true ; $ file = $ location . '/' . $ file ; continue ; } } if ( ! $ found ) { throw new TemplateNotFoundException ( 'This template was not found in any of the registered locations: ' . $ file ) ; } return $ file ; }
Finds the file by looping through locations
17,685
public function validateAuth ( ) { $ response = $ this -> uniRequest -> get ( implode ( [ $ this -> authURL , 'validate/' ] ) , $ this -> headers ) ; if ( in_array ( $ response -> code , $ this -> validCodes ) ) { return $ response ; } else { throw new Exception ( $ response -> body -> message , $ response -> code ) ; } }
Validate Authenticated Session
17,686
public function all ( ) { $ this -> resumeOrStartSession ( ) ; return isset ( $ _SESSION [ $ this -> name ] ) ? $ _SESSION [ $ this -> name ] : [ ] ; }
Get all of the session data .
17,687
public function remove ( $ key ) { if ( isset ( $ _SESSION [ $ this -> name ] [ $ key ] ) ) { $ value = $ _SESSION [ $ this -> name ] [ $ key ] ; unset ( $ _SESSION [ $ this -> name ] [ $ key ] ) ; return $ value ; } return null ; }
Remove an item from the session returning its value .
17,688
public function rollback ( ) : bool { $ sql = 'ROLLBACK' ; if ( ! $ this -> transactionStarted ) { $ event = new TimerEvent ( 'db.query' ) ; $ this -> emitQueryEvent ( $ event , null , $ sql ) ; throw new QueryException ( $ this , $ sql , "Can't rollback unstarted transaction" ) ; } $ this -> query ( $ sql ) ; $ this -> transactionStarted = false ; $ this -> instanceDispatcher ( ) -> emit ( new Event ( 'db.rollback' ) ) ; return true ; }
Rollback a sql transaction .
17,689
public function & __get ( $ property ) { $ getter = 'get' . \ ucfirst ( $ property ) ; if ( \ in_array ( $ property , array ( 'alerts' , 'cfg' , 'status' ) ) ) { return $ this -> { $ property } ; } elseif ( \ method_exists ( $ this , $ getter ) ) { $ return = $ this -> { $ getter } ( ) ; return $ return ; } elseif ( isset ( $ this -> status [ $ property ] ) ) { return $ this -> status [ $ property ] ; } else { $ this -> debug -> log ( 'property' , $ property ) ; } }
Get protected properties
17,690
public function getField ( $ fieldName ) { $ this -> debug -> group ( __METHOD__ , $ fieldName ) ; $ field = false ; if ( \ preg_match ( '|^(.*?)[/.](.*)$|' , $ fieldName , $ matches ) ) { $ pageName = $ matches [ 1 ] ; $ fieldName = $ matches [ 2 ] ; } else { $ pageName = $ this -> status [ 'currentPageName' ] ; } if ( $ pageName == $ this -> status [ 'currentPageName' ] && isset ( $ this -> currentFields [ $ fieldName ] ) ) { $ field = & $ this -> currentFields [ $ fieldName ] ; if ( ! \ is_object ( $ field ) ) { $ field [ 'pageI' ] = $ this -> persist -> get ( 'i' ) ; $ this -> currentFields [ $ fieldName ] = $ this -> buildField ( $ field , $ fieldName ) ; } } elseif ( isset ( $ this -> cfg [ 'pages' ] [ $ pageName ] ) ) { $ pages = $ this -> persist -> get ( 'pages' ) ; foreach ( $ pages as $ pageI => $ page ) { if ( $ page [ 'name' ] != $ pageName ) { continue ; } foreach ( $ this -> cfg [ 'pages' ] [ $ pageName ] as $ k => $ fieldProps ) { if ( $ k === $ fieldName || isset ( $ fieldProps [ 'attribs' ] [ 'name' ] ) && $ fieldProps [ 'attribs' ] [ 'name' ] == $ fieldName || isset ( $ fieldProps [ 'name' ] ) && $ fieldProps [ 'name' ] == $ fieldName ) { $ this -> debug -> info ( 'found field' ) ; $ fieldProps [ 'pageI' ] = $ pageI ; $ field = $ this -> buildField ( $ fieldProps , $ k ) ; $ val = $ this -> getValue ( $ fieldName , $ pageI ) ; $ field -> val ( $ val , false ) ; break 2 ; } } break ; } } $ this -> debug -> groupEnd ( ) ; return $ field ; }
Get form field
17,691
public function getInvalidFields ( ) { $ invalidFields = array ( ) ; foreach ( $ this -> currentFields as $ field ) { if ( ! $ field -> isValid ) { $ invalidFields [ ] = $ field ; } } return $ invalidFields ; }
Get list of invalid fields
17,692
public function setCurrentFields ( $ i = null ) { $ this -> debug -> groupCollapsed ( __METHOD__ , $ i ) ; $ this -> debug -> groupUncollapse ( ) ; $ cfg = & $ this -> cfg ; $ status = & $ this -> status ; if ( isset ( $ i ) ) { $ this -> status [ 'submitted' ] = false ; $ this -> persist -> set ( 'i' , $ i ) ; } $ this -> resetStatus ( ) ; $ this -> currentFields = isset ( $ cfg [ 'pages' ] [ $ status [ 'currentPageName' ] ] ) ? $ cfg [ 'pages' ] [ $ status [ 'currentPageName' ] ] : array ( ) ; $ this -> debug -> log ( 'count(currentFields)' , \ count ( $ this -> currentFields ) ) ; $ this -> currentValues = $ this -> persist -> get ( 'currentPage.values' ) ; if ( ! empty ( $ cfg [ 'pre' ] ) && \ is_callable ( $ cfg [ 'pre' ] ) ) { $ return = \ call_user_func ( $ cfg [ 'pre' ] , $ this ) ; if ( $ return === false ) { $ status [ 'error' ] = 'pre error' ; } } $ this -> buildFields ( ) ; $ this -> debug -> groupEnd ( ) ; return ; }
Set current page
17,693
protected function buildField ( $ fieldProps , $ nameDefault = null ) { $ this -> debug -> group ( __METHOD__ , $ nameDefault ) ; if ( ! isset ( $ fieldProps [ 'attribs' ] [ 'name' ] ) && ! isset ( $ fieldProps [ 'name' ] ) ) { $ fieldProps [ 'attribs' ] [ 'name' ] = $ nameDefault ; } if ( ! empty ( $ fieldProps [ 'newPage' ] ) ) { $ fieldProps [ 'attribs' ] [ 'type' ] = 'newPage' ; $ fieldProps [ 'attribs' ] [ 'value' ] = $ fieldProps [ 'newPage' ] ; unset ( $ fieldProps [ 'newPage' ] ) ; } $ field = $ this -> fieldFactory -> build ( $ fieldProps ) ; if ( $ this -> status [ 'submitted' ] && $ field -> attribs [ 'type' ] != 'newPage' ) { $ pageI = $ this -> persist -> get ( 'i' ) ; $ value = $ this -> persist -> get ( 'pages/' . $ pageI . '/values/' . $ field -> attribs [ 'name' ] ) ; $ field -> val ( $ value , false ) ; } $ this -> debug -> groupEnd ( ) ; return $ field ; }
Build field object
17,694
protected function buildFields ( ) { $ this -> debug -> groupCollapsed ( __METHOD__ ) ; $ status = & $ this -> status ; $ persist = $ this -> persist ; $ pageI = $ this -> persist -> get ( 'i' ) ; $ submitFieldCount = 0 ; $ keys = \ array_keys ( $ this -> currentFields ) ; foreach ( $ keys as $ k ) { $ field = $ this -> currentFields [ $ k ] ; unset ( $ this -> currentFields [ $ k ] ) ; if ( ! \ is_object ( $ field ) ) { $ field = $ this -> buildField ( $ field , $ k ) ; } $ field -> pageI = $ pageI ; if ( $ field -> attribs [ 'type' ] == 'newPage' ) { $ this -> debug -> info ( 'possible new page' , $ field -> attribs [ 'value' ] ) ; if ( $ field -> isRequired ( ) ) { $ this -> debug -> log ( 'adding new page' , $ field -> attribs [ 'value' ] ) ; $ status [ 'additionalPages' ] [ ] = $ field ; } continue ; } elseif ( $ field -> attribs [ 'type' ] == 'submit' ) { $ submitFieldCount ++ ; } elseif ( $ field -> attribs [ 'type' ] == 'file' ) { $ status [ 'multipart' ] = true ; } $ k = \ is_int ( $ k ) ? $ field -> attribs [ 'name' ] : $ k ; $ this -> currentFields [ $ k ] = $ field ; } if ( $ submitFieldCount < 1 ) { $ this -> debug -> info ( 'submit field not set' ) ; $ fieldArray = array ( 'type' => 'submit' , 'label' => ( ! empty ( $ status [ 'additionalPages' ] ) || $ persist -> pageCount ( ) > $ persist -> pageCount ( true ) + 1 ) ? 'Continue' : 'Submit' , 'attribs' => array ( 'class' => array ( 'btn btn-primary' , 'replace' ) ) , 'tagOnly' => true , ) ; $ this -> currentFields [ 'submit' ] = $ this -> fieldFactory -> build ( $ fieldArray ) ; $ this -> debug -> log ( 'array_keys(currentFields)' , \ array_keys ( $ this -> currentFields ) ) ; } if ( $ status [ 'multipart' ] ) { $ this -> debug -> log ( '<a target="_blank" href="http://www.php.net/manual/en/ini.php">post_max_size</a> = ' . Str :: getBytes ( \ ini_get ( 'post_max_size' ) ) ) ; $ this -> debug -> log ( '<a target="_blank" href="http://www.php.net/manual/en/ini.php">upload_max_filesize</a> = ' . Str :: getBytes ( \ ini_get ( 'upload_max_filesize' ) ) ) ; } $ this -> debug -> groupEnd ( ) ; }
Build current fields
17,695
private function initPersist ( ) { $ this -> debug -> groupCollapsed ( __METHOD__ ) ; $ this -> persist = new Persist ( $ this -> cfg [ 'name' ] , array ( 'persist' => $ this -> cfg [ 'persist' ] , 'trashCollectable' => $ this -> cfg [ 'trashCollectable' ] , 'userKey' => $ this -> cfg [ 'verifyKey' ] ? ( isset ( $ _REQUEST [ '_key_' ] ) ? $ _REQUEST [ '_key_' ] : null ) : false , ) ) ; if ( ! $ this -> persist -> pageCount ( ) ) { $ this -> debug -> info ( 'persist just created... add first page' ) ; $ firstPageName = \ key ( $ this -> cfg [ 'pages' ] ) ; $ this -> persist -> appendPages ( array ( $ firstPageName ) ) ; } $ this -> debug -> groupEnd ( ) ; }
Initialize persist object
17,696
private function pagesAddEnd ( $ pagesEnd = array ( ) ) { $ this -> debug -> groupCollapsed ( __METHOD__ ) ; $ this -> persist -> appendPages ( $ pagesEnd ) ; $ this -> debug -> groupEnd ( ) ; }
Add pages to end of form
17,697
private function pagesAddNext ( $ pagesNext = array ( ) ) { $ this -> debug -> groupCollapsed ( __METHOD__ ) ; $ pagesNext = \ array_values ( $ pagesNext ) ; $ pages = $ this -> persist -> get ( 'pages' ) ; $ iCur = $ this -> persist -> get ( 'i' ) ; $ currentPage = $ pages [ $ iCur ] ; $ offset = $ iCur + \ count ( $ currentPage [ 'addPages' ] ) + 1 ; foreach ( $ pages as $ k => $ page ) { foreach ( $ page [ 'addPages' ] as $ k2 => $ i ) { if ( $ i >= $ offset ) { $ pages [ $ k ] [ 'addPages' ] [ $ k2 ] += \ count ( $ pagesNext ) ; } } } foreach ( $ pagesNext as $ i => $ pageName ) { $ pages [ $ k ] [ 'addPages' ] [ ] = $ offset + $ i ; \ array_splice ( $ pages , $ offset + $ i , 0 , array ( array ( 'name' => $ pageName , 'completed' => false , 'values' => array ( ) , 'addPages' => array ( ) , ) ) ) ; } $ this -> persist -> set ( 'pages' , $ pages ) ; $ this -> debug -> groupEnd ( ) ; }
Add pages to be seen immediately after current page
17,698
private function processSubmit ( ) { $ this -> debug -> group ( __METHOD__ ) ; $ this -> debug -> groupUncollapse ( ) ; $ cfg = & $ this -> cfg ; $ status = & $ this -> status ; if ( $ status [ 'submitted' ] ) { $ this -> validate ( ) ; if ( \ is_callable ( $ cfg [ 'post' ] ) ) { $ return = \ call_user_func ( $ cfg [ 'post' ] , $ this ) ; if ( $ return === false ) { $ status [ 'error' ] = true ; } } if ( $ status [ 'error' ] ) { $ this -> alerts -> add ( $ cfg [ 'messages' ] [ 'errorAlert' ] ) ; } elseif ( $ invalidFields = $ this -> getInvalidFields ( ) ) { $ alert = $ cfg [ 'messages' ] [ 'invalidAlert' ] ; foreach ( $ invalidFields as $ field ) { if ( ! \ strlen ( $ field -> attribs [ 'value' ] ) ) { $ alert = $ cfg [ 'messages' ] [ 'unansweredAlert' ] ; break ; } } $ this -> alerts -> add ( $ alert ) ; } else { $ this -> debug -> info ( 'completed ' , $ status [ 'currentPageName' ] ) ; $ this -> persist -> set ( 'currentPage.completed' , true ) ; $ this -> addRemovePages ( ) ; if ( $ this -> persist -> pageCount ( true ) == $ this -> persist -> pageCount ( ) ) { $ this -> debug -> info ( 'completed all pages' ) ; $ status [ 'completed' ] = true ; $ complete = new Complete ( $ this ) ; $ return = $ complete -> complete ( ) ; if ( $ return === false ) { $ status [ 'error' ] = true ; } elseif ( \ is_string ( $ return ) ) { $ cfg [ 'messages' ] [ 'completed' ] = $ return ; } if ( $ status [ 'error' ] ) { $ this -> alerts -> add ( $ this -> cfg [ 'messages' ] [ 'errorAlert' ] ) ; } else { $ this -> alerts -> add ( $ this -> cfg [ 'messages' ] [ 'completedAlert' ] ) ; } if ( $ this -> status [ 'completed' ] && $ cfg [ 'trashOnComplete' ] ) { $ this -> debug -> warn ( 'shutting this whole thing down' ) ; $ this -> persist -> remove ( ) ; } } else { $ this -> debug -> info ( 'more pages to go' ) ; $ nextI = $ this -> persist -> get ( 'nextI' ) ; $ this -> setCurrentFields ( $ nextI ) ; } } } $ this -> debug -> groupEnd ( ) ; }
Process submitted values
17,699
private function redirectPost ( ) { if ( ! isset ( $ _SERVER [ 'REQUEST_URI' ] ) ) { return ; } if ( ! isset ( $ _SERVER [ 'REQUEST_METHOD' ] ) || $ _SERVER [ 'REQUEST_METHOD' ] != 'POST' ) { return ; } if ( ! $ this -> cfg [ 'prg' ] ) { return ; } if ( ! $ this -> status [ 'submitted' ] ) { return ; } $ this -> debug -> log ( 'redirecting' ) ; $ event = $ this -> eventManager -> publish ( 'page.redirect' , null , array ( 'location' => $ _SERVER [ 'REQUEST_URI' ] ) ) ; $ location = $ event [ 'location' ] ; $ this -> debug -> log ( '%cLocation:%c <a href="%s">%s</a>' , 'font-weight:bold;' , '' , $ location , $ location ) ; if ( \ headers_sent ( $ file , $ line ) ) { $ this -> debug -> warn ( 'headers alrady sent from ' . $ file . ' line ' . $ line ) ; return ; } if ( $ event -> isPropagationStopped ( ) ) { $ this -> debug -> alert ( '<i class="fa fa-external-link fa-lg" aria-hidden="true"></i> Location: <a class="alert-link" href="' . \ htmlspecialchars ( $ location ) . '">' . \ htmlspecialchars ( $ location ) . '</a>' , 'info' ) ; } else { \ header ( 'Location: ' . $ location ) ; } throw new \ Exception ( 'exit' ) ; }
Stores submitted values in persistence Redirects if submoitted via POST