idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
400 | private static function myParse ( string $ emailAddress , ? string & $ username = null , ? HostInterface & $ host = null , ? string & $ error = null ) : bool { if ( $ emailAddress === '' ) { $ error = 'Email address "" is empty.' ; return false ; } $ parts = explode ( '@' , $ emailAddress , 2 ) ; if ( count ( $ parts ) < 2 ) { $ error = 'Email address "' . $ emailAddress . '" is invalid: Character "@" is missing.' ; return false ; } $ username = $ parts [ 0 ] ; $ hostname = $ parts [ 1 ] ; if ( ! self :: myValidateUsername ( $ username , $ error ) ) { $ error = 'Email address "' . $ emailAddress . '" is invalid: ' . $ error ; return false ; } if ( ! self :: myParseHostname ( $ hostname , $ host , $ error ) ) { $ error = 'Email address "' . $ emailAddress . '" is invalid: ' . $ error ; return false ; } return true ; } | Tries to parse an email address and returns the result or error text . |
401 | private static function myParseHostname ( string $ hostname , ? HostInterface & $ host = null , ? string & $ error = null ) : bool { if ( strlen ( $ hostname ) > 2 && substr ( $ hostname , 0 , 1 ) === '[' && substr ( $ hostname , - 1 ) === ']' ) { $ ipAddress = substr ( $ hostname , 1 , - 1 ) ; try { $ host = Host :: fromIPAddress ( IPAddress :: parse ( $ ipAddress ) ) ; } catch ( IPAddressInvalidArgumentException $ exception ) { $ error = $ exception -> getMessage ( ) ; return false ; } return true ; } try { $ host = Host :: fromHostname ( Hostname :: parse ( $ hostname ) ) ; } catch ( HostnameInvalidArgumentException $ exception ) { $ error = $ exception -> getMessage ( ) ; return false ; } return true ; } | Parses the hostname . |
402 | private static function myValidateUsername ( string $ username , ? string & $ error = null ) : bool { if ( $ username === '' ) { $ error = 'Username "" is empty.' ; return false ; } if ( strpos ( $ username , '..' ) !== false ) { $ error = 'Username "' . $ username . '" contains "..".' ; return false ; } if ( strlen ( $ username ) > 64 ) { $ error = 'Username "' . $ username . '" is too long: Maximum length is 64.' ; return false ; } if ( preg_match ( '/[^0-9a-zA-Z.!#$%&\'*+\/=?^_`{|}~-]/' , $ username , $ matches ) ) { $ error = 'Username "' . $ username . '" contains invalid character "' . $ matches [ 0 ] . '".' ; return false ; } return true ; } | Validates the username . |
403 | public function request ( ) { if ( ENOLA_MODE == 'HTTP' ) { $ this -> loadHttpModule ( ) ; } else { $ this -> loadCronModule ( ) ; } $ this -> view = new Support \ View ( ) ; $ this -> loadUserConfig ( ) ; if ( ENOLA_MODE == 'HTTP' ) { $ this -> httpCore -> executeHttpRequest ( ) ; } else { $ this -> cronCore -> executeCronController ( ) ; } } | Responde al requerimiento analizando el tipo del mismo HTTP CLI ETC . |
404 | protected function loadFunctionsFiles ( ) { require $ this -> context -> getPathFra ( ) . 'Support/fn_error.php' ; require $ this -> context -> getPathFra ( ) . 'Support/fn_load_files.php' ; require $ this -> context -> getPathFra ( ) . 'Support/fn_view.php' ; } | Carga de modulos de soporte para que el framework trabaje correctamente |
405 | protected function loadLibraries ( ) { foreach ( $ this -> context -> getLibrariesDefinition ( ) as $ libreria ) { $ dir = $ libreria [ 'path' ] ; Support \ import_librarie ( $ dir ) ; } } | Carga todas las librerias particulares de la aplicacion que se cargaran automaticamente indicadas en el archivo de configuracion |
406 | protected function loadCronModule ( ) { global $ argv , $ argc ; if ( $ argc >= 2 ) { $ this -> cronCore = new Cron \ CronCore ( $ this , $ argv ) ; } else { Error :: general_error ( 'Cron Controller' , 'There isent define any cron controller name' ) ; } } | Carga el modulo cron y ejecuta el Cron correspondiente |
407 | public function getRequest ( ) { if ( $ this -> httpCore != NULL ) { return $ this -> httpCore -> httpRequest ; } else { return $ this -> cronCore -> cronRequest ; } } | Retorna el Requerimiento actual |
408 | public function getResponse ( ) { if ( $ this -> httpCore != NULL ) { return $ this -> httpCore -> httpResponse ; } else { return $ this -> cronCore -> cronResponse ; } } | Retorna el Response actual |
409 | public function setAttribute ( $ key , $ value ) { return $ this -> cache -> store ( $ this -> prefixApp . $ key , $ value ) ; } | Guarda un atributo en cache a nivel aplicacion . Por tiempo indefinido . |
410 | public function setObject ( $ object ) { if ( ! is_object ( $ object ) ) { throw new Exception \ InvalidArgumentException ( sprintf ( '%s expects an object argument; received "%s"' , __METHOD__ , gettype ( $ object ) ) ) ; } if ( property_exists ( $ this , 'hydrator' ) && $ this -> hydrator ) { $ values = $ this -> getHydrator ( ) -> extract ( $ object ) ; foreach ( $ this -> getFieldsets ( ) as $ name => $ fieldset ) { if ( isset ( $ values [ $ name ] ) && is_object ( $ values [ $ name ] ) ) { $ fieldset -> setObject ( $ values [ $ name ] ) ; } } } if ( property_exists ( $ this , 'object' ) ) { $ this -> object = $ object ; } return $ this ; } | Set the object used by the hydrator |
411 | public function onPostInstall ( Event $ event ) { $ lockFile = new JsonFile ( $ this -> lockFile ) ; if ( $ lockFile -> exists ( ) ) { $ this -> loadPackages ( $ lockFile ) ; } else { $ this -> scanPackages ( ) ; } $ this -> runAction ( 'install' ) ; } | Perform install . Called by composer after install . |
412 | public function findPackage ( $ name , $ composer = null ) { if ( $ composer === null ) { $ composer = $ this -> composer ; } return $ this -> composer -> getRepositoryManager ( ) -> findPackage ( 'beelab/bowerphp' , '*' ) ; } | Returns package with given name if exists . |
413 | protected function scanPackages ( ) { $ rootPackage = $ this -> composer -> getPackage ( ) ; if ( $ rootPackage ) { $ extra = $ rootPackage -> getExtra ( ) ; foreach ( $ this -> managers as $ manager ) { $ var = $ manager -> getName ( ) . '-asset-library' ; if ( isset ( $ extra [ 'asset-installer-paths' ] [ $ var ] ) ) { $ manager -> setDestination ( $ extra [ 'asset-installer-paths' ] [ $ var ] ) ; } } } foreach ( $ this -> getPackages ( ) as $ package ) { if ( $ package instanceof \ Composer \ Package \ CompletePackageInterface ) { $ this -> scanAssetDependencies ( $ package ) ; } } foreach ( $ this -> getPackages ( ) as $ package ) { if ( $ package instanceof \ Composer \ Package \ CompletePackageInterface ) { foreach ( $ this -> managers as $ manager ) { $ manager -> scanPackage ( $ package ) ; } } } } | Scan packages from the composer objects . |
414 | protected function loadPackages ( JsonFile $ lockFile ) { $ lock = $ lockFile -> read ( ) ; foreach ( $ this -> managers as $ name => $ m ) { $ m -> setConfig ( $ lock [ $ name ] ) ; } } | Load packages from given lock file . |
415 | private function addSchema ( Schema $ schema ) { if ( array_key_exists ( $ schema -> getName ( ) , $ this -> schemas ) ) { throw new \ Exception ( sprintf ( 'Schema "%s" is allready registered.' , $ schema -> getName ( ) ) ) ; } $ this -> schemas [ $ schema -> getName ( ) ] = $ schema ; return $ this ; } | Adds a schema . |
416 | private function load ( ) { if ( $ this -> loaded ) { return $ this ; } if ( 0 == count ( $ this -> dirs ) ) { return $ this ; } $ loaderResolver = new LoaderResolver ( array ( new YamlLoader ( ) ) ) ; $ loader = new DelegatingLoader ( $ loaderResolver ) ; $ finder = new Finder ( ) ; $ finder -> files ( ) -> in ( $ this -> dirs ) -> name ( 'schemas.yml' ) ; foreach ( $ finder as $ file ) { $ schemas = $ loader -> load ( ( string ) $ file ) ; foreach ( $ schemas as $ schema ) { $ this -> addSchema ( $ schema ) ; } } $ this -> loaded = true ; return $ this ; } | Loads the schemas . |
417 | public function single ( $ sql , $ params = array ( ) ) { $ query = $ this -> query ( $ sql , $ params ) ; $ data = $ query -> fetch ( ) ; return isset ( $ data [ 0 ] ) ? $ data [ 0 ] : null ; } | Execute a query and return the first value found . Note that this function returns null when no value is found but can also return null where the first value found in the DB is null . |
418 | public function insert ( $ sql , $ params = array ( ) ) { $ this -> query ( $ sql , $ params ) ; return $ this -> pdo -> lastInsertId ( ) ; } | Execute a query and return the insert ID |
419 | public function get ( $ key = null ) { if ( $ key === null ) { return $ this -> config ; } else { $ keys = ( strpos ( $ key , ' ' ) !== false ) ? explode ( ' ' , $ key ) : [ $ key ] ; $ value = $ this -> config ; foreach ( $ keys as $ key ) { if ( ! array_key_exists ( $ key , $ value ) ) { throw new \ Exception ( sprintf ( 'No such key `%s` in array `%s`' , $ key , $ keys ) ) ; } $ value = $ value [ $ key ] ; } return $ value ; } } | Get array of values or filter down to specific key . |
420 | public function & __get ( $ name ) { switch ( $ name ) { case 'global' : if ( is_null ( static :: $ global ) ) { static :: $ global = new Container ; } return static :: $ global ; break ; case 'session' : if ( is_null ( static :: $ session ) ) { static :: $ session = new Session ; } return static :: $ session ; break ; case 'request' : case 'dir' : case 'url' : case 'html' : return $ this -> $ name ; break ; default : return $ this -> html [ strtolower ( $ name ) ] ; break ; } } | A magic getter for our private properties . |
421 | public function tag ( $ name , array $ attributes , $ content = null ) { $ args = func_get_args ( ) ; $ tag = array_shift ( $ args ) ; $ attributes = array_shift ( $ args ) ; foreach ( $ attributes as $ key => $ value ) { if ( is_array ( $ value ) ) { $ value = implode ( ' ' , array_unique ( array_filter ( $ value ) ) ) ; } if ( $ value === '' ) { unset ( $ attributes [ $ key ] ) ; } elseif ( ! is_numeric ( $ key ) ) { $ attributes [ $ key ] = $ key . '="' . $ value . '"' ; } elseif ( isset ( $ attributes [ $ value ] ) ) { unset ( $ attributes [ $ key ] ) ; } } $ attributes = ( ! empty ( $ attributes ) ) ? ' ' . implode ( ' ' , $ attributes ) : '' ; $ html = '<' . $ tag . $ attributes . '>' ; if ( ! empty ( $ args ) ) { $ html .= implode ( ' ' , array_filter ( $ args ) ) ; $ html .= '</' . strstr ( $ tag . ' ' , ' ' , true ) . '>' ; } return $ html ; } | Generate an HTML tag programatically . |
422 | public function id ( $ prefix = '' ) { static $ id = 0 ; ++ $ id ; $ result = '' ; $ lookup = array ( 'M' => 1000 , 'CM' => 900 , 'D' => 500 , 'CD' => 400 , 'C' => 100 , 'XC' => 90 , 'L' => 50 , 'XL' => 40 , 'X' => 10 , 'IX' => 9 , 'V' => 5 , 'IV' => 4 , 'I' => 1 ) ; $ number = $ id ; if ( $ number < 100 ) { $ lookup = array_slice ( $ lookup , 4 ) ; } foreach ( $ lookup as $ roman => $ value ) { $ matches = intval ( $ number / $ value ) ; $ result .= str_repeat ( $ roman , $ matches ) ; $ number = $ number % $ value ; } return $ prefix . $ result ; } | We use this in the Form component to avoid input name collisions . We use it in the Bootstrap component for accordions carousels and the like . The problem with just incrementing a number and adding it onto something else is that css and jQuery don t like numbered id s . So we use roman numerals instead and that solves the problem for us . |
423 | public function filter ( $ section , callable $ function , array $ params = array ( 'this' ) , $ order = 10 ) { if ( $ section == 'response' ) { foreach ( $ params as $ key => $ value ) { if ( empty ( $ value ) || $ value == 'this' ) { unset ( $ params [ $ key ] ) ; } } $ key = false ; } elseif ( ! in_array ( $ section , array ( 'metadata' , 'css' , 'styles' , 'html' , 'javascript' , 'scripts' , 'head' , 'body' , 'page' ) ) ) { $ error = "'{$section}' cannot be filtered" ; } else { if ( false === $ key = array_search ( 'this' , $ params ) ) { $ error = "'this' must be listed in the \$params so that we can give you something to filter" ; } } if ( isset ( $ error ) ) { throw new \ LogicException ( $ error ) ; } $ this -> filters [ $ section ] [ ] = array ( 'function' => $ function , 'params' => $ params , 'order' => $ order , 'key' => $ key ) ; } | Enables you to modify just about anything throughout the creation process of your page . |
424 | public function commonDir ( array $ files ) { $ files = array_values ( $ files ) ; $ cut = 0 ; $ count = count ( $ files ) ; $ shortest = min ( array_map ( 'mb_strlen' , $ files ) ) ; while ( $ cut < $ shortest ) { $ char = $ files [ 0 ] [ $ cut ] ; for ( $ i = 1 ; $ i < $ count ; ++ $ i ) { if ( $ files [ $ i ] [ $ cut ] !== $ char ) { break 2 ; } } ++ $ cut ; } $ dir = mb_substr ( $ files [ 0 ] , 0 , $ cut ) ; if ( false !== $ slash = mb_strrpos ( $ dir , '/' ) ) { $ dir = mb_substr ( $ dir , 0 , $ slash + 1 ) ; } elseif ( false !== $ slash = mb_strrpos ( $ dir , '\\' ) ) { $ dir = mb_substr ( $ dir , 0 , $ slash + 1 ) ; } else { $ dir = '' ; } return $ dir ; } | An internal method we use that comes in handy elsewhere as well . |
425 | protected function redirect ( ) { $ redirect = false ; $ file = $ this -> file ( '301.txt' ) ; if ( is_file ( $ file ) ) { $ map = array ( ) ; foreach ( array_filter ( array_map ( 'trim' , file ( $ file ) ) ) as $ url ) { if ( $ url [ 0 ] == '[' && substr ( $ url , - 1 ) == ']' ) { $ new = substr ( $ url , 1 , - 1 ) ; } elseif ( isset ( $ new ) && ! isset ( $ map [ $ url ] ) ) { $ map [ $ url ] = $ new ; } } $ endless = array ( ) ; $ path = $ this -> url [ 'path' ] ; parse_str ( ltrim ( $ this -> url [ 'query' ] , '?' ) , $ params ) ; while ( $ route = $ this -> routes ( $ map , $ path ) ) { $ path = $ route [ 'target' ] ; $ params += $ route [ 'params' ] ; if ( in_array ( $ path , $ endless ) || count ( $ endless ) > 5 ) { return false ; } else { $ endless [ ] = $ path ; $ redirect = rtrim ( $ path . '?' . http_build_query ( $ params ) , '?' ) ; } } } return $ redirect ; } | Determine if the current page requires a 301 redirect . |
426 | public function fromFile ( string $ filename = '' , bool $ returnArray = false ) { if ( empty ( $ filename ) ) { throw new InvalidArgumentException ( 'File name must be specified' ) ; } \ set_error_handler ( function ( $ error , $ message = '' ) use ( $ filename ) { $ exMsg = \ sprintf ( 'Error reading from "%s": %s' , $ filename , $ message ) ; throw new RuntimeException ( $ exMsg , $ error ) ; } , E_WARNING ) ; try { $ config = $ this -> transform ( \ file_get_contents ( $ filename ) ) ; \ restore_error_handler ( ) ; return $ returnArray ? $ config : new Config ( $ config ) ; } catch ( RuntimeException $ e ) { \ restore_error_handler ( ) ; throw $ e ; } } | Reads configuration from file and converts it to array |
427 | public function persist ( $ model , $ errors = array ( ) , $ data = array ( ) ) { if ( is_a ( $ model , 'Model' ) ) { $ errors = $ model -> validationErrors ; $ data = $ model -> data ; $ model = $ model -> alias ; } return $ this -> Session -> write ( "$this->sessionKey.$model" , compact ( 'data' , 'errors' ) ) ; } | Manually force errors to persist . |
428 | public function build ( ) { foreach ( $ this -> modules -> enabled ( ) as $ module ) { $ name = studly_case ( $ module -> getName ( ) ) ; $ class = 'Modules\\' . $ name . '\\MenuExtenders\\SidebarExtender' ; if ( class_exists ( $ class ) ) { $ extender = $ this -> container -> make ( $ class ) ; $ this -> menu -> add ( $ extender -> extendWith ( $ this -> menu ) ) ; } } } | Build your sidebar implementation here . |
429 | public function get ( $ key , $ expiration = false ) { $ item = $ this -> psr6Cache -> getItem ( $ key ) ; return $ item -> isHit ( ) ? $ item -> get ( ) : false ; } | Retrieves the data for the given key or false if they key is unknown or expired |
430 | public function description ( ) { if ( substr ( $ this -> description , 0 , 5 ) == 'lang:' ) { $ description = substr ( $ this -> description , 5 ) ; if ( $ desc = $ this -> CI -> lang -> line ( $ description ) ) { return $ desc ; } return $ description ; } return $ this -> description ; } | Get command description |
431 | public function findChild ( $ id ) { foreach ( $ this -> getChildren ( ) as $ child ) { $ result = $ this -> findChildInNode ( $ child , $ id ) ; if ( $ result ) { return $ result ; } } return null ; } | Find a child item by id |
432 | public static function groupByColumn ( array $ array , $ keyColumn , $ valueColumn = null ) : array { $ result = [ ] ; foreach ( $ array as $ item ) { if ( ! isset ( $ item [ $ keyColumn ] ) ) { continue ; } $ key = $ item [ $ keyColumn ] ; if ( ! isset ( $ result [ $ key ] ) ) { $ result [ $ key ] = [ ] ; } if ( null !== $ valueColumn ) { $ result [ $ key ] [ ] = $ item [ $ valueColumn ] ; } else { $ result [ $ key ] [ ] = $ item ; } } return $ result ; } | Group array items by column . |
433 | public static function columnToKey ( array $ array , $ keyColumn , $ valueColumn = null ) : array { $ keys = array_column ( $ array , $ keyColumn ) ; $ values = null === $ valueColumn ? $ array : array_column ( $ array , $ valueColumn ) ; return array_combine ( $ keys , $ values ) ; } | Creates an array where the column is used as keys . |
434 | public static function searchByColumnValue ( array $ array , $ column , $ value , bool $ strict = false ) { foreach ( $ array as $ row ) { if ( ! $ strict && $ row [ $ column ] == $ value ) { return $ row ; } elseif ( $ strict && $ row [ $ column ] === $ value ) { return $ row ; } } return null ; } | Returns the array element where the column is equal to the specified value . |
435 | private function clearSigHandlers ( ) { pcntl_signal ( SIGTERM , SIG_DFL ) ; pcntl_signal ( SIGINT , SIG_DFL ) ; pcntl_signal ( SIGQUIT , SIG_DFL ) ; pcntl_signal ( SIGUSR1 , SIG_DFL ) ; pcntl_signal ( SIGUSR2 , SIG_DFL ) ; pcntl_signal ( SIGCONT , SIG_DFL ) ; } | Clear all previously registered signal handlers |
436 | private function fork ( & $ socket ) { $ pair = [ ] ; if ( socket_create_pair ( AF_UNIX , SOCK_STREAM , 0 , $ pair ) === false ) { $ this -> logger -> error ( '{type}: Unable to create socket pair; ' . socket_strerror ( socket_last_error ( $ pair [ 0 ] ) ) , $ this -> logContext ) ; exit ( 0 ) ; } $ PID = Qless :: fork ( ) ; if ( $ PID !== 0 ) { $ this -> childProcesses ++ ; $ socket = $ pair [ 0 ] ; socket_close ( $ pair [ 1 ] ) ; socket_set_option ( $ socket , SOL_SOCKET , SO_RCVTIMEO , [ 'sec' => 0 , 'usec' => 10000 ] ) ; return $ PID ; } $ socket = $ pair [ 1 ] ; socket_close ( $ pair [ 0 ] ) ; $ reserved = str_repeat ( 'x' , 20240 ) ; register_shutdown_function ( function ( ) use ( & $ reserved , $ socket ) { if ( null === $ error = error_get_last ( ) ) { return ; } unset ( $ reserved ) ; $ type = $ error [ 'type' ] ; if ( ! isset ( self :: $ ERROR_CODES [ $ type ] ) ) { return ; } $ this -> logger -> debug ( 'Sending error to master' , $ this -> logContext ) ; $ data = serialize ( $ error ) ; while ( ( $ len = socket_write ( $ socket , $ data ) ) > 0 ) { $ data = substr ( $ data , $ len ) ; } } ) ; return $ PID ; } | Forks and creates a socket pair for communication between parent and child process |
437 | protected function timestamped_endpoint ( $ url ) { $ time = substr ( date_i18n ( 'YmdHi' , false , true ) , 0 , - 1 ) . '0' ; return add_query_arg ( [ 'timestamp' => $ time , ] , $ url ) ; } | Add timestamp for endpoint . |
438 | protected function parse_result ( $ response ) { if ( is_wp_error ( $ response ) ) { return ( object ) [ 'success' => false , 'version' => false , 'error' => $ response -> get_error_code ( ) , 'message' => $ response -> get_error_message ( ) , ] ; } else { $ result = json_decode ( $ response ) ; if ( is_null ( $ result ) ) { return ( object ) [ 'success' => false , 'version' => false , 'error' => '500' , 'message' => 'Parser Error' , ] ; } else { return $ result ; } } } | Parse result from remote server . |
439 | protected function remote_get_version ( ) { $ key = $ this -> cache_key ; $ version = get_site_transient ( $ key ) ; if ( false !== $ version ) { return $ version ; } $ url = $ this -> timestamped_endpoint ( $ this -> endpoint ( ) ) ; $ response = wp_remote_get ( $ url ) ; if ( is_wp_error ( $ response ) ) { $ version = $ this -> parse_result ( $ response ) ; } else { $ version = $ this -> parse_result ( $ response [ 'body' ] ) ; } set_site_transient ( $ key , $ version , $ this -> ttl ) ; return $ version ; } | Get remote version file . |
440 | public function has_update ( ) { $ info = $ this -> remote_get_version ( ) ; if ( ! isset ( $ info -> version ) || ! $ info -> version ) { return false ; } else { return version_compare ( $ this -> version , $ info -> version , '<' ) ; } } | Detect if plugin has update . |
441 | public function wp_get_update_data ( $ update_data , $ titles ) { if ( $ this -> has_update ( ) ) { $ update_data [ 'counts' ] [ 'plugins' ] ++ ; $ update_data [ 'counts' ] [ 'total' ] ++ ; $ titles [ 'plugins' ] = sprintf ( _n ( '%d Plugin Update' , '%d Plugin Updates' , $ update_data [ 'counts' ] [ 'plugins' ] , 'hametwoo' ) , $ update_data [ 'counts' ] [ 'plugins' ] ) ; $ update_data [ 'title' ] = esc_attr ( implode ( ', ' , $ titles ) ) ; } return $ update_data ; } | Update message . |
442 | public function activate ( Composer $ composer , IOInterface $ io ) { $ this -> package = $ composer -> getPackage ( ) ; $ this -> io = $ io ; $ this -> projectRoot = realpath ( dirname ( $ composer -> getConfig ( ) -> get ( 'vendor-dir' ) ) ) ; } | Activate Wordpress plugin |
443 | public function initialiseWordpress ( Event $ event ) { $ webroot = $ this -> getWebroot ( ) ; $ defaultSettings = array ( 'copy-paths' => array ( ) ) ; $ extraConfig = $ this -> package -> getExtra ( ) ; if ( ! isset ( $ extraConfig [ 'wordpress' ] ) ) { $ extraConfig [ 'wordpress' ] = array ( ) ; } $ settings = array_merge ( $ defaultSettings , $ extraConfig [ 'wordpress' ] ) ; foreach ( $ settings [ 'copy-paths' ] as $ path ) { if ( is_string ( $ path ) ) { $ this -> copyFrom ( $ webroot , $ path ) ; } elseif ( is_array ( $ path ) && count ( $ path ) === 2 && is_string ( $ path [ 0 ] ) && is_string ( $ path [ 1 ] ) ) { $ this -> copyFrom ( $ webroot , $ path [ 0 ] , $ path [ 1 ] ) ; } else { throw new \ RuntimeException ( 'Unrecognised path format. Must be source path or array of source and destination paths' ) ; } } } | Initialise the project |
444 | public function getDispatcherFactory ( ContainerInterface $ container ) : DispatcherFactoryInterface { $ autowired = $ container -> get ( 'ellipse.dispatcher.autowiring.status' ) ; if ( $ autowired ) { $ interfaces = $ container -> get ( 'ellipse.dispatcher.autowiring.interfaces' ) ; $ container = new ReflectionContainer ( $ container , $ interfaces ) ; } return new DefaultResolver ( $ container ) ; } | Return an instance of default resolver as DispatcherFactoryInterface . |
445 | public function Initialize ( ) { parent :: Initialize ( ) ; Gdn_Theme :: Section ( 'Dashboard' ) ; if ( $ this -> Menu ) $ this -> Menu -> HighlightRoute ( '/dashboard/settings' ) ; } | Hightlight menu path . Automatically run on every use . |
446 | public function Homepage ( ) { $ this -> Permission ( 'Garden.Settings.Manage' ) ; $ this -> AddSideMenu ( 'dashboard/settings/homepage' ) ; $ this -> Title ( T ( 'Homepage' ) ) ; $ CurrentRoute = GetValue ( 'Destination' , Gdn :: Router ( ) -> GetRoute ( 'DefaultController' ) , '' ) ; $ this -> SetData ( 'CurrentTarget' , $ CurrentRoute ) ; if ( ! $ this -> Form -> AuthenticatedPostBack ( ) ) { $ this -> Form -> SetData ( array ( 'Target' => $ CurrentRoute ) ) ; } else { $ NewRoute = GetValue ( 'Target' , $ this -> Form -> FormValues ( ) , '' ) ; Gdn :: Router ( ) -> DeleteRoute ( 'DefaultController' ) ; Gdn :: Router ( ) -> SetRoute ( 'DefaultController' , $ NewRoute , 'Internal' ) ; $ this -> SetData ( 'CurrentTarget' , $ NewRoute ) ; SaveToConfig ( array ( 'Vanilla.Discussions.Layout' => GetValue ( 'DiscussionsLayout' , $ this -> Form -> FormValues ( ) , '' ) , 'Vanilla.Categories.Layout' => GetValue ( 'CategoriesLayout' , $ this -> Form -> FormValues ( ) , '' ) ) ) ; $ this -> InformMessage ( T ( "Your changes were saved successfully." ) ) ; } $ this -> Render ( ) ; } | Homepage management screen . |
447 | public function Email ( ) { $ this -> Permission ( 'Garden.Settings.Manage' ) ; $ this -> AddSideMenu ( 'dashboard/settings/email' ) ; $ this -> AddJsFile ( 'email.js' ) ; $ this -> Title ( T ( 'Outgoing Email' ) ) ; $ Validation = new Gdn_Validation ( ) ; $ ConfigurationModel = new Gdn_ConfigurationModel ( $ Validation ) ; $ ConfigurationModel -> SetField ( array ( 'Garden.Email.SupportName' , 'Garden.Email.SupportAddress' , 'Garden.Email.UseSmtp' , 'Garden.Email.SmtpHost' , 'Garden.Email.SmtpUser' , 'Garden.Email.SmtpPassword' , 'Garden.Email.SmtpPort' , 'Garden.Email.SmtpSecurity' ) ) ; $ this -> Form -> SetModel ( $ ConfigurationModel ) ; if ( $ this -> Form -> AuthenticatedPostBack ( ) === FALSE ) { $ this -> Form -> SetData ( $ ConfigurationModel -> Data ) ; } else { $ ConfigurationModel -> Validation -> ApplyRule ( 'Garden.Email.SupportName' , 'Required' ) ; $ ConfigurationModel -> Validation -> ApplyRule ( 'Garden.Email.SupportAddress' , 'Required' ) ; $ ConfigurationModel -> Validation -> ApplyRule ( 'Garden.Email.SupportAddress' , 'Email' ) ; if ( $ this -> Form -> Save ( ) !== FALSE ) $ this -> InformMessage ( T ( "Your settings have been saved." ) ) ; } $ this -> Render ( ) ; } | Outgoing Email management screen . |
448 | public function xIndex ( ) { $ this -> AddJsFile ( 'settings.js' ) ; $ this -> Title ( T ( 'Dashboard' ) ) ; $ this -> RequiredAdminPermissions [ ] = 'Garden.Settings.Manage' ; $ this -> RequiredAdminPermissions [ ] = 'Garden.Users.Add' ; $ this -> RequiredAdminPermissions [ ] = 'Garden.Users.Edit' ; $ this -> RequiredAdminPermissions [ ] = 'Garden.Users.Delete' ; $ this -> RequiredAdminPermissions [ ] = 'Garden.Users.Approve' ; $ this -> FireEvent ( 'DefineAdminPermissions' ) ; $ this -> Permission ( $ this -> RequiredAdminPermissions , FALSE ) ; $ this -> AddSideMenu ( 'dashboard/settings' ) ; $ UserModel = Gdn :: UserModel ( ) ; $ this -> ActiveUserData = $ UserModel -> GetActiveUsers ( 5 ) ; $ this -> AddUpdateCheck ( ) ; $ this -> FireEvent ( 'DashboardData' ) ; $ this -> Render ( ) ; } | Main dashboard . |
449 | public function AddUpdateCheck ( ) { if ( C ( 'Garden.NoUpdateCheck' ) ) return ; $ UpdateCheckDate = Gdn :: Config ( 'Garden.UpdateCheckDate' , '' ) ; if ( $ UpdateCheckDate == '' || ! IsTimestamp ( $ UpdateCheckDate ) || $ UpdateCheckDate < strtotime ( "-1 day" ) ) { $ UpdateData = array ( ) ; $ Plugins = Gdn :: PluginManager ( ) -> AvailablePlugins ( ) ; foreach ( $ Plugins as $ Plugin => $ Info ) { $ Name = ArrayValue ( 'Name' , $ Info , $ Plugin ) ; $ Version = ArrayValue ( 'Version' , $ Info , '' ) ; if ( $ Version != '' ) $ UpdateData [ ] = array ( 'Name' => $ Name , 'Version' => $ Version , 'Type' => 'Plugin' ) ; } $ ApplicationManager = Gdn :: Factory ( 'ApplicationManager' ) ; $ Applications = $ ApplicationManager -> AvailableApplications ( ) ; foreach ( $ Applications as $ Application => $ Info ) { $ Name = ArrayValue ( 'Name' , $ Info , $ Application ) ; $ Version = ArrayValue ( 'Version' , $ Info , '' ) ; if ( $ Version != '' ) $ UpdateData [ ] = array ( 'Name' => $ Name , 'Version' => $ Version , 'Type' => 'Application' ) ; } $ ThemeManager = new Gdn_ThemeManager ; $ Themes = $ ThemeManager -> AvailableThemes ( ) ; foreach ( $ Themes as $ Theme => $ Info ) { $ Name = ArrayValue ( 'Name' , $ Info , $ Theme ) ; $ Version = ArrayValue ( 'Version' , $ Info , '' ) ; if ( $ Version != '' ) $ UpdateData [ ] = array ( 'Name' => $ Name , 'Version' => $ Version , 'Type' => 'Theme' ) ; } $ this -> AddDefinition ( 'UpdateChecks' , Gdn_Format :: Serialize ( $ UpdateData ) ) ; } } | Adds information to the definition list that causes the app to phone home and see if there are upgrades available . |
450 | public function Plugins ( $ Filter = '' , $ PluginName = '' , $ TransientKey = '' ) { $ this -> Permission ( 'Garden.Settings.Manage' ) ; $ this -> AddJsFile ( 'addons.js' ) ; $ this -> Title ( T ( 'Plugins' ) ) ; $ this -> AddSideMenu ( 'dashboard/settings/plugins' ) ; $ Session = Gdn :: Session ( ) ; $ PluginName = $ Session -> ValidateTransientKey ( $ TransientKey ) ? $ PluginName : '' ; if ( ! in_array ( $ Filter , array ( 'enabled' , 'disabled' ) ) ) $ Filter = 'all' ; $ this -> Filter = $ Filter ; $ this -> EnabledPlugins = Gdn :: PluginManager ( ) -> EnabledPlugins ( ) ; self :: SortAddons ( $ this -> EnabledPlugins ) ; $ this -> AvailablePlugins = Gdn :: PluginManager ( ) -> AvailablePlugins ( ) ; self :: SortAddons ( $ this -> AvailablePlugins ) ; if ( $ PluginName != '' ) { try { $ this -> EventArguments [ 'PluginName' ] = $ PluginName ; if ( array_key_exists ( $ PluginName , $ this -> EnabledPlugins ) === TRUE ) { Gdn :: PluginManager ( ) -> DisablePlugin ( $ PluginName ) ; Gdn_LibraryMap :: ClearCache ( ) ; $ this -> FireEvent ( 'AfterDisablePlugin' ) ; } else { $ Validation = new Gdn_Validation ( ) ; if ( ! Gdn :: PluginManager ( ) -> EnablePlugin ( $ PluginName , $ Validation ) ) $ this -> Form -> SetValidationResults ( $ Validation -> Results ( ) ) ; else Gdn_LibraryMap :: ClearCache ( ) ; $ this -> EventArguments [ 'Validation' ] = $ Validation ; $ this -> FireEvent ( 'AfterEnablePlugin' ) ; } } catch ( Exception $ e ) { $ this -> Form -> AddError ( $ e ) ; } if ( $ this -> Form -> ErrorCount ( ) == 0 ) Redirect ( '/settings/plugins/' . $ this -> Filter ) ; } $ this -> Render ( ) ; } | Manage list of plugins . |
451 | public static function SortAddons ( & $ Array , $ Filter = TRUE ) { foreach ( $ Array as $ Key => $ Value ) { if ( $ Filter && GetValue ( 'Hidden' , $ Value ) ) { unset ( $ Array [ $ Key ] ) ; continue ; } $ Name = GetValue ( 'Name' , $ Value , $ Key ) ; SetValue ( 'Name' , $ Array [ $ Key ] , $ Name ) ; } uasort ( $ Array , array ( 'SettingsController' , 'CompareAddonName' ) ) ; } | Sort list of addons for display . |
452 | public function ThemeOptions ( $ Style = NULL ) { $ this -> Permission ( 'Garden.Settings.Manage' ) ; try { $ this -> AddJsFile ( 'addons.js' ) ; $ this -> AddSideMenu ( 'dashboard/settings/themeoptions' ) ; $ ThemeManager = new Gdn_ThemeManager ( ) ; $ this -> SetData ( 'ThemeInfo' , $ ThemeManager -> EnabledThemeInfo ( ) ) ; if ( $ this -> Form -> IsPostBack ( ) ) { $ StyleKey = $ this -> Form -> GetFormValue ( 'StyleKey' ) ; $ ConfigSaveData = array ( 'Garden.ThemeOptions.Styles.Key' => $ StyleKey , 'Garden.ThemeOptions.Styles.Value' => $ this -> Data ( "ThemeInfo.Options.Styles.$StyleKey.Basename" ) ) ; $ Translations = array ( ) ; foreach ( $ this -> Data ( 'ThemeInfo.Options.Text' , array ( ) ) as $ Key => $ Default ) { $ Value = $ this -> Form -> GetFormValue ( $ this -> Form -> EscapeString ( 'Text_' . $ Key ) ) ; $ ConfigSaveData [ "ThemeOption.{$Key}" ] = $ Value ; } SaveToConfig ( $ ConfigSaveData ) ; $ this -> InformMessage ( T ( "Your changes have been saved." ) ) ; } elseif ( $ Style ) { SaveToConfig ( array ( 'Garden.ThemeOptions.Styles.Key' => $ Style , 'Garden.ThemeOptions.Styles.Value' => $ this -> Data ( "ThemeInfo.Options.Styles.$Style.Basename" ) ) ) ; } $ this -> SetData ( 'ThemeOptions' , C ( 'Garden.ThemeOptions' ) ) ; $ StyleKey = $ this -> Data ( 'ThemeOptions.Styles.Key' ) ; if ( ! $ this -> Form -> IsPostBack ( ) ) { foreach ( $ this -> Data ( 'ThemeInfo.Options.Text' , array ( ) ) as $ Key => $ Options ) { $ Default = GetValue ( 'Default' , $ Options , '' ) ; $ Value = C ( "ThemeOption.{$Key}" , '#DEFAULT#' ) ; if ( $ Value === '#DEFAULT#' ) $ Value = $ Default ; $ this -> Form -> SetFormValue ( $ this -> Form -> EscapeString ( 'Text_' . $ Key ) , $ Value ) ; } } $ this -> SetData ( 'ThemeFolder' , $ ThemeManager -> EnabledTheme ( ) ) ; $ this -> Title ( T ( 'Theme Options' ) ) ; $ this -> Form -> AddHidden ( 'StyleKey' , $ StyleKey ) ; } catch ( Exception $ Ex ) { $ this -> Form -> AddError ( $ Ex ) ; } $ this -> Render ( ) ; } | Manage options for a theme . |
453 | public function Themes ( $ ThemeName = '' , $ TransientKey = '' ) { $ this -> AddJsFile ( 'addons.js' ) ; $ this -> SetData ( 'Title' , T ( 'Themes' ) ) ; $ this -> Permission ( 'Garden.Settings.Manage' ) ; $ this -> AddSideMenu ( 'dashboard/settings/themes' ) ; $ ThemeInfo = Gdn :: ThemeManager ( ) -> EnabledThemeInfo ( TRUE ) ; $ this -> SetData ( 'EnabledThemeFolder' , GetValue ( 'Folder' , $ ThemeInfo ) ) ; $ this -> SetData ( 'EnabledTheme' , Gdn :: ThemeManager ( ) -> EnabledThemeInfo ( ) ) ; $ this -> SetData ( 'EnabledThemeName' , GetValue ( 'Name' , $ ThemeInfo , GetValue ( 'Index' , $ ThemeInfo ) ) ) ; $ Themes = Gdn :: ThemeManager ( ) -> AvailableThemes ( ) ; uasort ( $ Themes , array ( 'SettingsController' , '_NameSort' ) ) ; $ Remove = array ( ) ; foreach ( $ Themes as $ Index => $ Theme ) { $ Archived = GetValue ( 'Archived' , $ Theme ) ; if ( $ Archived ) $ Remove [ ] = $ Index ; } foreach ( $ Remove as $ Index ) { unset ( $ Themes [ $ Index ] ) ; } $ this -> SetData ( 'AvailableThemes' , $ Themes ) ; if ( Gdn :: Session ( ) -> ValidateTransientKey ( $ TransientKey ) && $ ThemeName != '' ) { try { $ ThemeInfo = Gdn :: ThemeManager ( ) -> GetThemeInfo ( $ ThemeName ) ; if ( $ ThemeInfo === FALSE ) throw new Exception ( sprintf ( T ( "Could not find a theme identified by '%s'" ) , $ ThemeName ) ) ; Gdn :: Session ( ) -> SetPreference ( array ( 'PreviewThemeName' => '' , 'PreviewThemeFolder' => '' ) ) ; Gdn :: ThemeManager ( ) -> EnableTheme ( $ ThemeName ) ; $ this -> EventArguments [ 'ThemeName' ] = $ ThemeName ; $ this -> EventArguments [ 'ThemeInfo' ] = $ ThemeInfo ; $ this -> FireEvent ( 'AfterEnableTheme' ) ; } catch ( Exception $ Ex ) { $ this -> Form -> AddError ( $ Ex ) ; } if ( $ this -> Form -> ErrorCount ( ) == 0 ) Redirect ( '/settings/themes' ) ; } $ this -> Render ( ) ; } | Themes management screen . |
454 | public function PreviewTheme ( $ ThemeName = '' ) { $ this -> Permission ( 'Garden.Settings.Manage' ) ; $ ThemeInfo = Gdn :: ThemeManager ( ) -> GetThemeInfo ( $ ThemeName ) ; $ PreviewThemeName = $ ThemeName ; $ PreviewThemeFolder = GetValue ( 'Folder' , $ ThemeInfo ) ; if ( $ ThemeInfo === FALSE ) { $ PreviewThemeName = '' ; $ PreviewThemeFolder = '' ; } Gdn :: Session ( ) -> SetPreference ( array ( 'PreviewThemeName' => $ PreviewThemeName , 'PreviewThemeFolder' => $ PreviewThemeFolder ) ) ; Redirect ( '/' ) ; } | Show a preview of a theme . |
455 | public function RemoveAddon ( $ Type , $ Name , $ TransientKey = '' ) { $ RequiredPermission = 'Undefined' ; switch ( $ Type ) { case SettingsModule :: TYPE_APPLICATION : $ Manager = Gdn :: Factory ( 'ApplicationManager' ) ; $ Enabled = 'EnabledApplications' ; $ Remove = 'RemoveApplication' ; $ RequiredPermission = 'Garden.Settings.Manage' ; break ; case SettingsModule :: TYPE_PLUGIN : $ Manager = Gdn :: Factory ( 'PluginManager' ) ; $ Enabled = 'EnabledPlugins' ; $ Remove = 'RemovePlugin' ; $ RequiredPermission = 'Garden.Settings.Manage' ; break ; } $ Session = Gdn :: Session ( ) ; if ( $ Session -> ValidateTransientKey ( $ TransientKey ) && $ Session -> CheckPermission ( $ RequiredPermission ) ) { try { if ( array_key_exists ( $ Name , $ Manager -> $ Enabled ( ) ) === FALSE ) { $ Manager -> $ Remove ( $ Name ) ; } } catch ( Exception $ e ) { $ this -> Form -> AddError ( strip_tags ( $ e -> getMessage ( ) ) ) ; } } if ( $ this -> Form -> ErrorCount ( ) == 0 ) Redirect ( '/settings/plugins' ) ; } | Remove an addon . |
456 | public function GettingStarted ( ) { $ this -> Permission ( 'Garden.Settings.Manage' ) ; $ this -> SetData ( 'Title' , T ( 'Getting Started' ) ) ; $ this -> AddSideMenu ( 'dashboard/settings/gettingstarted' ) ; $ this -> TextEnterEmails = T ( 'TextEnterEmails' , 'Type email addresses separated by commas here' ) ; if ( $ this -> Form -> AuthenticatedPostBack ( ) ) { $ Message = $ this -> Form -> GetFormValue ( 'InvitationMessage' ) ; $ Message .= "\n\n" . Gdn :: Request ( ) -> Url ( '/' , TRUE ) ; $ Message = trim ( $ Message ) ; $ Recipients = $ this -> Form -> GetFormValue ( 'Recipients' ) ; if ( $ Recipients == $ this -> TextEnterEmails ) $ Recipients = '' ; $ Recipients = explode ( ',' , $ Recipients ) ; $ CountRecipients = 0 ; foreach ( $ Recipients as $ Recipient ) { if ( trim ( $ Recipient ) != '' ) { $ CountRecipients ++ ; if ( ! ValidateEmail ( $ Recipient ) ) $ this -> Form -> AddError ( sprintf ( T ( '%s is not a valid email address' ) , $ Recipient ) ) ; } } if ( $ CountRecipients == 0 ) $ this -> Form -> AddError ( T ( 'You must provide at least one recipient' ) ) ; if ( $ this -> Form -> ErrorCount ( ) == 0 ) { $ Email = new Gdn_Email ( ) ; $ Email -> Subject ( T ( 'Check out my new community!' ) ) ; $ Email -> Message ( $ Message ) ; foreach ( $ Recipients as $ Recipient ) { if ( trim ( $ Recipient ) != '' ) { $ Email -> To ( $ Recipient ) ; try { $ Email -> Send ( ) ; } catch ( Exception $ ex ) { $ this -> Form -> AddError ( $ ex ) ; } } } } if ( $ this -> Form -> ErrorCount ( ) == 0 ) $ this -> InformMessage ( T ( 'Your invitations were sent successfully.' ) ) ; } $ this -> Render ( ) ; } | Prompts new admins how to get started using new install . |
457 | public function editAction ( ) { $ default = false ; $ params = $ this -> params ( ) ; $ request = $ this -> getRequest ( ) ; $ locator = $ this -> getServiceLocator ( ) ; $ model = $ locator -> get ( 'Grid\Core\Model\SubDomain\Model' ) ; $ form = $ locator -> get ( 'Form' ) -> create ( 'Grid\Core\SubDomain' ) ; if ( ( $ id = $ params -> fromRoute ( 'id' ) ) ) { $ subDomain = $ model -> find ( $ id ) ; if ( empty ( $ subDomain ) ) { $ this -> getResponse ( ) -> setStatusCode ( 404 ) ; return ; } if ( empty ( $ subDomain -> subdomain ) ) { $ default = true ; $ form -> get ( 'subdomain' ) -> setRequired ( false ) ; } } else { if ( ! $ this -> getServiceLocator ( ) -> get ( 'Grid\User\Model\Permissions\Model' ) -> isAllowed ( 'subDomain' , 'create' ) ) { $ this -> getResponse ( ) -> setStatusCode ( 403 ) ; return ; } $ subDomain = $ model -> create ( array ( ) ) ; } $ form -> setHydrator ( $ model -> getMapper ( ) ) -> bind ( $ subDomain ) ; if ( $ request -> isPost ( ) ) { $ form -> setData ( $ request -> getPost ( ) ) ; if ( $ form -> isValid ( ) && $ subDomain -> save ( ) ) { if ( $ default && ! empty ( $ subDomain -> subdomain ) ) { $ newDefault = $ model -> create ( array ( 'subdomain' => '' , 'locale' => $ subDomain -> locale , 'defaultLayoutId' => $ subDomain -> defaultLayoutId , 'defaultContentId' => $ subDomain -> defaultContentId , ) ) ; $ newDefault -> save ( ) ; } $ this -> messenger ( ) -> add ( 'subDomain.form.success' , 'subDomain' , Message :: LEVEL_INFO ) ; return $ this -> redirect ( ) -> toRoute ( 'Grid\Core\SubDomain\List' , array ( 'locale' => ( string ) $ this -> locale ( ) , ) ) ; } else { $ this -> messenger ( ) -> add ( 'subDomain.form.failed' , 'subDomain' , Message :: LEVEL_ERROR ) ; } } $ form -> setCancel ( $ this -> url ( ) -> fromRoute ( 'Grid\Core\SubDomain\List' , array ( 'locale' => ( string ) $ this -> locale ( ) , ) ) ) ; return array ( 'form' => $ form , 'subDomain' => $ subDomain , ) ; } | Edit a sub - domain |
458 | protected function collectIndexedColumns ( $ indexName , $ columns , & $ collectedIndexes ) { $ indexedColumns = array ( ) ; foreach ( $ columns as $ column ) { $ indexedColumns [ ] = $ column ; $ indexedColumnsHash = $ this -> getColumnList ( $ indexedColumns ) ; if ( ! array_key_exists ( $ indexedColumnsHash , $ collectedIndexes ) ) { $ collectedIndexes [ $ indexedColumnsHash ] = array ( ) ; } $ collectedIndexes [ $ indexedColumnsHash ] [ ] = $ indexName ; } } | Helper function to collect indexed columns . |
459 | public function addColumn ( $ data ) { if ( $ data instanceof Column ) { $ col = $ data ; $ col -> setTable ( $ this ) ; if ( $ col -> isInheritance ( ) ) { $ this -> inheritanceColumn = $ col ; } if ( isset ( $ this -> columnsByName [ $ col -> getName ( ) ] ) ) { throw new EngineException ( 'Duplicate column declared: ' . $ col -> getName ( ) ) ; } $ this -> columnList [ ] = $ col ; $ this -> columnsByName [ $ col -> getName ( ) ] = $ col ; $ this -> columnsByLowercaseName [ strtolower ( $ col -> getName ( ) ) ] = $ col ; $ this -> columnsByPhpName [ $ col -> getPhpName ( ) ] = $ col ; $ col -> setPosition ( count ( $ this -> columnList ) ) ; $ this -> needsTransactionInPostgres |= $ col -> requiresTransactionInPostgres ( ) ; return $ col ; } else { $ col = new Column ( ) ; $ col -> setTable ( $ this ) ; $ col -> loadFromXML ( $ data ) ; return $ this -> addColumn ( $ col ) ; } } | A utility function to create a new column from attrib and add it to this table . |
460 | private function processArguments ( array $ arguments ) { foreach ( $ arguments as $ argument ) { if ( is_array ( $ argument ) ) { $ this -> processArguments ( $ argument ) ; } elseif ( $ argument instanceof Reference ) { $ this -> graph -> connect ( $ this -> currentId , $ this -> currentDefinition , $ this -> getDefinitionId ( ( string ) $ argument ) , $ this -> getDefinition ( ( string ) $ argument ) , $ argument ) ; } elseif ( $ argument instanceof Definition ) { $ this -> processArguments ( $ argument -> getArguments ( ) ) ; $ this -> processArguments ( $ argument -> getMethodCalls ( ) ) ; $ this -> processArguments ( $ argument -> getProperties ( ) ) ; if ( is_array ( $ argument -> getFactory ( ) ) ) { $ this -> processArguments ( $ argument -> getFactory ( ) ) ; } } } } | Processes service definitions for arguments to find relationships for the service graph . |
461 | private function getDefinition ( $ id ) { $ id = $ this -> getDefinitionId ( $ id ) ; return null === $ id ? null : $ this -> container -> getDefinition ( $ id ) ; } | Returns a service definition given the full name or an alias . |
462 | protected function doFetch ( array $ ids ) { if ( ! $ ids ) { return [ ] ; } return $ this -> redis -> hmget ( $ this -> namespace , $ this -> keys ( $ ids ) ) ; } | Fetches several cache items . |
463 | protected function doSave ( array $ values , $ lifetime ) { $ this -> redis -> hmset ( $ this -> namespace , $ this -> keys ( $ values ) ) ; return true ; } | Persists several cache items immediately . |
464 | public function loadManifest ( ) { if ( $ this -> files -> exists ( $ this -> manifestPath ) ) { $ manifest = json_decode ( $ this -> files -> get ( $ this -> manifestPath ) , true ) ; return array_merge ( [ 'when' => [ ] ] , $ manifest ) ; } } | Load the service provider manifest JSON file . |
465 | public static function itIsNotConsideredValid ( MapsProperty $ property , $ value ) : Throwable { if ( is_object ( $ value ) ) { return new self ( sprintf ( 'Cannot assign the `%s` to property `%s`: ' . 'The value did not satisfy the specifications.' , get_class ( $ value ) , $ property -> name ( ) ) ) ; } return new self ( sprintf ( 'Cannot assign `%s` to property `%s`: ' . 'The value did not satisfy the specifications.' , $ value , $ property -> name ( ) ) ) ; } | Notifies the client code when the input is not accepted by the constraint . |
466 | public function findByPattern ( $ rulePattern ) { $ logger = $ GLOBALS [ 'logger' ] ; $ path = 'rules/' ; $ request = $ this -> _remoteServer -> get ( $ path ) ; $ query = $ request -> getQuery ( ) ; $ query -> set ( 'pattern' , $ rulePattern ) ; $ logger -> info ( print_r ( $ query , 1 ) ) ; try { $ response = $ request -> send ( ) ; if ( $ response -> getStatusCode ( ) !== 200 ) { throw new \ Exception ( 'Unable to handle request' ) ; } $ rawResponse = $ response -> getBody ( 'true' ) ; return $ rawResponse ; } catch ( \ Exception $ e ) { throw $ e ; } } | Find the rules by pattern |
467 | public function saveRule ( $ rule ) { $ logger = $ GLOBALS [ 'logger' ] ; $ path = 'rules/create' ; $ request = $ this -> _remoteServer -> post ( $ path , array ( 'Content-Type' => 'application/json' ) , $ rule ) ; try { $ response = $ request -> send ( ) ; if ( $ response -> getStatusCode ( ) !== 200 ) { throw new \ Exception ( 'Unable to handle request' ) ; } $ rawResponse = $ response -> getBody ( 'true' ) ; return $ rawResponse ; } catch ( \ Exception $ e ) { throw $ e ; } } | Save Rule in Database |
468 | public function updateRule ( $ rule ) { $ logger = $ GLOBALS [ 'logger' ] ; $ path = 'rules/update' ; $ request = $ this -> _remoteServer -> put ( $ path , array ( 'Content-Type' => 'application/json' ) , $ rule ) ; try { $ response = $ request -> send ( ) ; if ( $ response -> getStatusCode ( ) !== 200 ) { throw new \ Exception ( 'Unable to handle request' ) ; } $ rawResponse = $ response -> getBody ( 'true' ) ; return $ rawResponse ; } catch ( \ Exception $ e ) { throw $ e ; } } | Update Rule in Database |
469 | public function evaluateRules ( $ ruleData ) { $ logger = $ GLOBALS [ 'logger' ] ; $ path = 'rules/execute' ; $ request = $ this -> _remoteServer -> post ( $ path , array ( 'Content-Type' => 'application/json' ) , $ ruleData ) ; try { $ response = $ request -> send ( ) ; if ( $ response -> getStatusCode ( ) !== 200 ) { throw new \ Exception ( 'Unable to handle request' ) ; } $ rawResponse = $ response -> getBody ( 'true' ) ; $ logger -> debug ( 'Rule Evaluation Outcome = ' . print_r ( $ rawResponse , 1 ) ) ; return $ rawResponse ; } catch ( \ Exception $ e ) { throw $ e ; } } | Evaluate incoming data against available rules . |
470 | public static function parse ( $ range ) { $ matches = array ( ) ; if ( preg_match ( self :: REGEX , $ range , $ matches ) !== 1 ) { throw new InvalidArgumentException ( sprintf ( 'Provided range "%s" does not match Ruby syntax.' , $ range ) ) ; } return new self ( $ matches [ 1 ] + 0 , $ matches [ 3 ] + 0 , $ matches [ 2 ] === '.' ) ; } | Parses a range in Ruby syntax and returns a Range instance . |
471 | public function doHigh ( $ function_name , $ workload , $ unique = null ) { return parent :: doHigh ( Task :: getName ( $ function_name ) , $ workload , $ unique ) ; } | Runs a single high priority task and returns a string representation of the result . It is up to the GearmanClient and GearmanWorker to agree on the format of the result . High priority tasks will get precedence over normal and low priority tasks in the job queue . |
472 | public function doNormal ( $ function_name , $ workload , $ unique = null ) { return parent :: doNormal ( Task :: getName ( $ function_name ) , $ workload , $ unique ) ; } | Runs a single task and returns a string representation of the result . It is up to the GearmanClient and GearmanWorker to agree on the format of the result . Normal and high priority tasks will get precedence over low priority tasks in the job queue . |
473 | public function doLow ( $ function_name , $ workload , $ unique = null ) { return parent :: doLow ( Task :: getName ( $ function_name ) , $ workload , $ unique ) ; } | Runs a single low priority task and returns a string representation of the result . It is up to the GearmanClient and GearmanWorker to agree on the format of the result . Normal and high priority tasks will get precedence over low priority tasks in the job queue . |
474 | public function doHighBackground ( $ function_name , $ workload , $ unique = null ) { return parent :: doHighBackground ( Task :: getName ( $ function_name ) , $ workload , $ unique ) ; } | Runs a high priority task in the background returning a job handle which can be used to get the status of the running task . High priority tasks take precedence over normal and low priority tasks in the job queue . |
475 | public function doLowBackground ( $ function_name , $ workload , $ unique = null ) { return parent :: doLowBackground ( Task :: getName ( $ function_name ) , $ workload , $ unique ) ; } | Runs a low priority task in the background returning a job handle which can be used to get the status of the running task . Normal and high priority tasks take precedence over low priority tasks in the job queue . |
476 | protected function transformResult ( array $ result ) { if ( $ this -> columnTransformers -> count ( ) ) { foreach ( $ result as $ index => $ row ) { $ result [ $ index ] = $ this -> transformRow ( $ row ) ; } } return $ result ; } | Transforms the results using additional data transformers |
477 | protected function transformRow ( $ row ) { foreach ( $ row as $ field => $ value ) { if ( $ this -> columnTransformers -> has ( $ field ) ) { $ row [ $ field ] = $ this -> columnTransformers -> get ( $ field ) -> transformValue ( $ value ) ; } } return $ row ; } | Processes the row data |
478 | public static function invertBits ( $ n ) { $ bits = \ floor ( \ log ( $ n , 2 ) ) + 1 ; $ mask = ( 1 << $ bits ) - 1 ; return $ n ^ $ mask ; } | Inverts the bits of a number |
479 | public function toDate ( $ date ) { $ this -> current = ( is_string ( $ date ) ? new \ DateTime ( $ date , self :: $ utc ) : $ date ) ; } | Sets the current value! |
480 | public function getModel ( ) { if ( is_null ( $ this -> _model ) ) { $ modelClass = $ this -> modelClass ; $ this -> _model = new $ modelClass ( ) ; } return $ this -> _model ; } | Get model . |
481 | public function formatFilesize ( $ size , $ decimals = 0 , $ binarySuffix = false ) { $ size = ( float ) ceil ( $ size ) ; if ( ! $ size ) { return 0 ; } if ( ! $ binarySuffix ) { $ divisor = 1000 ; $ suffixes = array ( 'Byte' , 'kB' , 'MB' , 'GB' , 'TB' , 'PB' ) ; } else { $ divisor = 1024 ; $ suffixes = array ( 'Byte' , 'KiB' , 'MiB' , 'GiB' , 'TiB' , 'PiB' ) ; } $ last = end ( $ suffixes ) ; foreach ( $ suffixes as $ suffix ) { if ( $ size < $ divisor ) { break ; } if ( $ suffix === $ last ) { break ; } $ size /= $ divisor ; } if ( $ decimals && $ suffix !== $ suffixes [ 0 ] ) { $ locale = localeconv ( ) ; $ decPoint = $ locale [ 'decimal_point' ] ; $ thousandsSep = $ locale [ 'thousands_sep' ] ; $ size = number_format ( $ size , $ decimals , $ decPoint , $ thousandsSep ) ; } else { $ size = ceil ( $ size ) ; } return sprintf ( '%s %s' , $ size , $ suffix ) ; } | Format a human readable filesize . |
482 | public function addGlobalConfigPath ( string ... $ globalConfigPaths ) : ApplicationBuilder { foreach ( $ globalConfigPaths as $ globalConfigPath ) { $ this -> globalConfigPaths [ ] = $ globalConfigPath ; } return $ this ; } | Add global config path for glob . |
483 | public function addConfig ( LoaderInterface ... $ loaders ) : ApplicationBuilder { foreach ( $ loaders as $ loader ) { $ this -> configs [ ] = $ loader ; } return $ this ; } | Add config loader . |
484 | public function setCacheEnabled ( bool $ cacheEnabled = null ) : ApplicationBuilder { $ this -> cacheEnabled = $ cacheEnabled ?? true ; return $ this ; } | Set cache enabled . |
485 | public function setFrameworkEnabled ( bool $ frameworkEnabled = null ) : ApplicationBuilder { $ this -> frameworkEnabled = $ frameworkEnabled ?? true ; return $ this ; } | Set framework enabled . |
486 | public function addModule ( ModuleInterface ... $ modules ) : ApplicationBuilder { foreach ( $ modules as $ module ) { $ this -> modules [ ] = $ module ; } return $ this ; } | Add module . |
487 | protected function getConfig ( ) : array { $ loader = null ; if ( $ this -> isCacheEnabled ( ) === true ) { $ loader = $ this -> getLoader ( ) ; $ cached = $ loader -> load ( ) ; if ( empty ( $ cached ) === false ) { return $ cached ; } } if ( $ this -> isFrameworkEnabled ( ) === true ) { $ this -> addFrameworkConfigs ( ) ; } $ merged = [ ] ; $ merger = $ this -> getMerger ( ) ; foreach ( $ this -> getConfigs ( ) as $ config ) { $ merged = $ merger -> merge ( $ merged , $ config -> load ( ) ) ; } foreach ( $ this -> getGlobalConfig ( ) as $ global ) { $ merged = $ merger -> merge ( $ merged , $ global ) ; } foreach ( $ this -> getModuleConfig ( ) as $ module ) { $ merged = $ merger -> merge ( $ merged , $ module ) ; } if ( $ this -> isCacheEnabled ( ) === true ) { if ( $ loader instanceof CacheLoader ) { $ loader -> save ( $ merged ) ; } } return $ merged ; } | Get merged global and module config . |
488 | protected function addFrameworkConfigs ( ) : ApplicationBuilder { foreach ( $ this -> getFrameworkConfigs ( ) as $ loader ) { $ loader = new $ loader ; if ( $ loader instanceof LoaderInterface ) { $ this -> addConfig ( $ loader ) ; } } return $ this ; } | Add framework configs . |
489 | protected function getModuleConfig ( ) : array { $ merged = [ ] ; $ merger = $ this -> getMerger ( ) ; foreach ( $ this -> getModules ( ) as $ module ) { if ( $ module instanceof ConditionProviderInterface && $ module -> isConditioned ( ) === true ) { continue ; } if ( $ module instanceof ConfigProviderInterface ) { $ merged = $ merger -> merge ( $ merged , $ module -> getConfig ( ) -> load ( ) ) ; } } return $ merged ; } | Get config from modules . |
490 | protected function getGlobalConfig ( ) : array { $ loader = new FileLoader ( ) ; foreach ( $ this -> globalConfigPaths as $ path ) { $ loader -> addPath ( $ path ) ; } return $ loader -> load ( ) ; } | Get global config . |
491 | protected function getServiceLocatorFactory ( ) : ServiceLocatorFactoryInterface { if ( ! $ this -> factory instanceof ServiceLocatorFactoryInterface ) { $ this -> factory = new ServiceLocatorFactory ( ) ; } return $ this -> factory ? : new ServiceLocatorFactory ( ) ; } | Get service locator factory . |
492 | protected function getLoader ( ) : LoaderInterface { if ( ! $ this -> loader instanceof LoaderInterface ) { $ this -> loader = new CacheLoader ( sprintf ( '%s/%s.php' , rtrim ( $ this -> getCacheLocation ( ) , '/' ) , $ this -> getCacheFilename ( ) ) ) ; } return $ this -> loader ; } | Get global config loader . |
493 | protected function getMerger ( ) : MergerInterface { if ( ! $ this -> merger instanceof MergerInterface ) { $ this -> merger = new RecursiveMerger ( ) ; } return $ this -> merger ; } | Get config merger . |
494 | protected function reset ( ) : void { $ this -> frameworkEnabled = true ; $ this -> globalConfigPaths = [ ] ; $ this -> cacheLocation = null ; $ this -> cacheFilename = null ; $ this -> cacheEnabled = null ; $ this -> modules = [ ] ; $ this -> configs = [ ] ; $ this -> loader = null ; $ this -> merger = null ; $ this -> factory = null ; } | Reset builder . |
495 | public function filterGeneralAttachmentsForObject ( AttachableObjectInterface $ object ) { return $ this -> filterAllAttachmentsForObject ( $ object ) -> useAttachmentLinkQuery ( ) -> filterByModelField ( null , Criteria :: ISNULL ) -> endUse ( ) ; } | Filter attachments for the given object only returning those that are not linked to a specific field name . |
496 | public function filterSpecificAttachmentsForObject ( AttachableObjectInterface $ object , $ fieldName ) { return $ this -> filterAllAttachmentsForObject ( $ object ) -> useAttachmentLinkQuery ( ) -> filterByModelField ( $ fieldName ) -> endUse ( ) ; } | Filter attachments for the given object only returning those that are linked to the given field name |
497 | public function parse ( $ names = null , bool $ isTable = false ) : array { $ ret = [ ] ; if ( $ names === null || $ names == '*' ) { $ ret [ ] = '*' ; } elseif ( \ is_string ( $ names ) ) { $ ret [ ] = $ names ; $ this -> aliases [ ] = $ names . ( $ isTable === true ? '\\.' : '' ) ; } elseif ( \ is_array ( $ names ) ) { foreach ( $ names as $ name => $ alias ) { if ( \ is_string ( $ name ) ) { if ( \ in_array ( $ alias , [ - 1 , 1 ] ) ) { $ ret [ ] = \ sprintf ( '%s %s' , $ name , \ str_replace ( [ - 1 , 1 ] , [ 'DESC' , 'ASC' ] , $ alias ) ) ; } elseif ( \ is_string ( $ alias ) ) { $ ret [ ] = \ sprintf ( '%s %s' , $ name , $ alias ) ; $ this -> aliases [ ] = \ str_replace ( [ '(' , ')' , '[' , ']' , '{' , '}' , '*' , '+' , '.' , '?' , '/' , '\\' ] , [ '\\(' , '\\)' , '\\[' , '\\]' , '\\{' , '\\}' , '\\*' , '\\+' , '\\.' , '\\?' , '\\/' , '\\\\' ] , $ name ) ; $ this -> aliases [ ] = $ alias . ( $ isTable === true ? '\\.' : '' ) ; } } elseif ( \ is_string ( $ alias ) ) { $ ret [ ] = $ alias ; $ this -> aliases [ ] = $ alias . ( $ isTable === true ? '\\.' : '' ) ; } } } return $ ret ; } | Parses names to array of strings . |
498 | public static function forge ( $ presenter , $ method = 'view' , $ auto_filter = null , $ view = null ) { is_null ( $ view ) and $ view = $ presenter ; $ presenter = \ Inflector :: words_to_upper ( str_replace ( array ( '/' , DS ) , '_' , strpos ( $ presenter , '.' ) === false ? $ presenter : substr ( $ presenter , 0 , - strlen ( strrchr ( $ presenter , '.' ) ) ) ) ) ; $ namespace = \ Request :: active ( ) ? ucfirst ( \ Request :: active ( ) -> module ) : '' ; $ classes = array ( $ namespace . '\\' . static :: $ ns_prefix . $ presenter ) ; empty ( $ namespace ) or $ classes [ ] = static :: $ ns_prefix . $ presenter ; $ classes [ ] = $ namespace . '\\' . $ presenter ; empty ( $ namespace ) or $ classes [ ] = $ presenter ; foreach ( $ classes as $ class ) { if ( class_exists ( $ class ) ) { return new $ class ( $ method , $ auto_filter , $ view ) ; } } throw new \ OutOfBoundsException ( 'Presenter "' . reset ( $ classes ) . '" could not be found.' ) ; } | Factory for fetching the Presenter |
499 | public function & get ( $ key = null , $ default = null ) { if ( is_null ( $ default ) and func_num_args ( ) === 1 ) { return $ this -> _view -> get ( $ key ) ; } return $ this -> _view -> get ( $ key , $ default ) ; } | Gets a variable from the template |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.