idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
26,900
public static function filter ( callable $ function , $ traversable ) { Arguments :: define ( Boa :: func ( ) , Boa :: traversable ( ) ) -> check ( $ function , $ traversable ) ; $ aggregation = [ ] ; foreach ( $ traversable as $ key => $ value ) { if ( $ function ( $ value , $ key ) ) { $ aggregation [ $ key ] = $ value ; } } return $ aggregation ; }
Filter a list by calling a callback on each element .
26,901
public static function curryArgs ( callable $ function , $ args ) { Arguments :: define ( Boa :: func ( ) , Boa :: arr ( ) ) -> check ( $ function , $ args ) ; $ required = function ( ) use ( $ function ) { return ( new ReflectionFunction ( $ function ) ) -> getNumberOfRequiredParameters ( ) ; } ; $ isFulfilled = function ( callable $ function , $ args ) use ( $ required ) { return count ( $ args ) >= $ required ( $ function ) ; } ; if ( $ isFulfilled ( $ function , $ args ) ) { return static :: apply ( $ function , $ args ) ; } return function ( ... $ funcArgs ) use ( $ function , $ args , $ required , $ isFulfilled ) { $ newArgs = ArrayList :: of ( $ args ) -> append ( ArrayList :: of ( $ funcArgs ) ) -> toArray ( ) ; if ( $ isFulfilled ( $ function , $ newArgs ) ) { return static :: apply ( $ function , $ newArgs ) ; } return static :: curryArgs ( $ function , $ newArgs ) ; } ; }
Left - curry the provided function with the provided array of arguments .
26,902
public static function poll ( callable $ function , $ times ) { Arguments :: define ( Boa :: func ( ) , Boa :: integer ( ) ) -> check ( $ function , $ times ) ; for ( $ ii = 0 ; $ ii < $ times ; $ ii ++ ) { static :: call ( $ function , $ ii ) ; } }
Call a function N times .
26,903
public static function retry ( callable $ function , $ attempts ) { Arguments :: define ( Boa :: func ( ) , Boa :: integer ( ) ) -> check ( $ function , $ attempts ) ; for ( $ ii = 0 ; $ ii < $ attempts ; $ ii ++ ) { try { $ result = static :: call ( $ function , $ ii ) ; return $ result ; } catch ( Exception $ e ) { continue ; } } return null ; }
Attempt call the provided function a number of times until it no longer throws an exception .
26,904
public static function castToBool ( $ mixed ) { if ( is_string ( $ mixed ) || $ mixed instanceof Rope ) { $ lower = Rope :: of ( $ mixed ) -> toLower ( ) ; if ( $ lower -> equals ( Rope :: of ( 'true' ) ) ) { return true ; } elseif ( $ lower -> equals ( Rope :: of ( 'false' ) ) ) { return false ; } throw new CoreException ( 'Unable to cast into a bool.' ) ; } elseif ( is_int ( $ mixed ) ) { if ( $ mixed === 1 ) { return true ; } elseif ( $ mixed === 0 ) { return false ; } throw new CoreException ( 'Unable to cast into a bool.' ) ; } elseif ( is_float ( $ mixed ) ) { if ( $ mixed === 1.0 ) { return true ; } elseif ( $ mixed === 0.0 ) { return false ; } throw new CoreException ( 'Unable to cast into a bool.' ) ; } elseif ( is_bool ( $ mixed ) ) { return $ mixed ; } throw new CoreException ( 'Unable to cast into a bool.' ) ; }
Attempt to cast a value into a bool .
26,905
public function render ( ) : string { $ html = '<div id="app">' ; $ html .= ' <transition name="fade" mode="out-in"> <router-view></router-view> </transition>' ; $ html .= '</div>' ; $ title = env ( 'APP_NAME' ) ; $ html .= '<script src="/assets/application.js"></script>' ; $ html .= $ this -> scripts ( ) ; return '<body>' . $ html . '</body>' ; }
Function for return rendered body html
26,906
public function AddSideMenu ( $ CurrentUrl = FALSE ) { if ( ! $ CurrentUrl ) $ CurrentUrl = strtolower ( $ this -> SelfUrl ) ; if ( $ this -> _DeliveryType == DELIVERY_TYPE_ALL ) { $ SideMenu = new SideMenuModule ( $ this ) ; $ SideMenu -> EventName = 'GetAppSettingsMenuItems' ; $ SideMenu -> HtmlId = '' ; $ SideMenu -> HighlightRoute ( $ CurrentUrl ) ; $ SideMenu -> Sort = C ( 'Garden.DashboardMenu.Sort' ) ; $ this -> AddModule ( $ SideMenu , 'Panel' ) ; } }
Build and add the Dashboard s side navigation menu .
26,907
protected function fetchMessagesFromNamespace ( $ namespace ) { $ this -> setNamespace ( $ namespace ) ; if ( $ this -> hasMessages ( ) ) { $ messages = $ this -> getMessagesFromNamespace ( $ namespace ) ; $ this -> setNamespace ( ) ; return $ this -> buildMessage ( $ namespace , $ messages ) ; } return '' ; }
Gets messages from flash messenger plugin namespace
26,908
protected function getAlert ( $ namespace , $ message , $ title = null , $ titleTag = 'h4' , $ isBlock = false ) { $ namespace = $ this -> classMessages [ $ namespace ] ; $ html = ( $ title ) ? sprintf ( $ this -> titleFormat , $ titleTag , $ title , $ titleTag ) : '' ; $ html .= $ message . PHP_EOL ; $ alert = $ this -> getAlertHelper ( ) -> $ namespace ( $ html , $ isBlock ) ; return $ alert ; }
Get the alert string
26,909
protected function getAlertHelper ( ) { if ( $ this -> alertHelper ) { return $ this -> alertHelper ; } $ this -> alertHelper = $ this -> view -> plugin ( 'tbAlert' ) ; return $ this -> alertHelper ; }
Retrieve the alert helper
26,910
public function getPluginFlashMessenger ( ) { if ( $ this -> pluginFlashMessenger ) { return $ this -> pluginFlashMessenger ; } $ this -> pluginFlashMessenger = new PluginFlashMessenger ( ) ; return $ this -> pluginFlashMessenger ; }
Retrieve the flash messenger plugin
26,911
public function fetch ( string $ strDate ) { $ this -> validateDate ( $ strDate ) ; $ strDateStart = $ strDate . ' 00:00:00' ; if ( $ this -> iTimezoneOffset ) { $ strDateStart = date ( 'Y-m-d H:i:s' , strtotime ( $ strDateStart . ( $ this -> iTimezoneOffset < 0 ? ' +' : ' ' ) . - $ this -> iTimezoneOffset . ' hours' ) ) ; } $ strDateEnd = date ( 'Y-m-d H:i:s' , strtotime ( $ strDateStart . ' + 1 day - 1 second' ) ) ; $ aResults = $ this -> queryDay ( $ strDateStart , $ strDateEnd ) ; usort ( $ aResults , function ( $ aResult1 , $ aResult2 ) { return $ aResult1 [ 'session_at' ] <=> $ aResult2 [ 'session_at' ] ? : $ aResult1 [ 'starts_at' ] <=> $ aResult2 [ 'starts_at' ] ; } ) ; return $ aResults ; }
Fetch today s event sessions from the database .
26,912
public function save ( SkeVent & $ skeVent ) { $ mReturn = false ; if ( $ this -> validateEvent ( $ skeVent ) ) { $ aValues = $ skeVent -> toArray ( false ) ; unset ( $ aValues [ 'lead_time_num' ] , $ aValues [ 'lead_time_unit' ] ) ; $ this -> beginTransaction ( ) ; try { $ mReturn = $ this -> saveEvent ( $ aValues ) ; $ this -> saveEventTags ( $ mReturn , $ skeVent -> getTags ( ) ) ; $ this -> saveEventMembers ( $ mReturn , $ skeVent -> getMembers ( ) ) ; } catch ( \ Exception $ e ) { $ mReturn = false ; $ skeVent -> addError ( 2 , $ e -> getMessage ( ) ) ; } $ this -> endTransaction ( ( bool ) $ mReturn ) ; } return $ mReturn ; }
Persist data to the database .
26,913
protected function validateEvent ( SkeVent & $ skeVent ) { $ bValid = true ; $ skeVent -> resetErrors ( ) ; $ aData = $ skeVent -> toArray ( ) ; foreach ( Sked :: form ( ) -> getFieldDefinitions ( ) as $ strKey => $ aDefinition ) { if ( ! isset ( $ aData [ $ strKey ] ) && ( $ aDefinition [ 'required' ] ?? false ) && ! isset ( $ aData [ 'id' ] ) ) { $ bValid = false ; $ skeVent -> addError ( $ strKey , 'The "' . $ aDefinition [ 'attribs' ] [ 'label' ] . '" field is required.' ) ; } elseif ( ! $ this -> validateOption ( $ aData [ $ strKey ] ?? null , $ aDefinition [ 'options' ] ?? null ) ) { $ bValid = false ; $ skeVent -> addError ( $ strKey , 'An invalid ' . $ strKey . ' option was given.' ) ; } } if ( isset ( $ aData [ 'lead_time_num' ] ) || isset ( $ aData [ 'lead_time_unit' ] ) ) { if ( ! isset ( $ aData [ 'lead_time_num' ] ) || ! isset ( $ aData [ 'lead_time_unit' ] ) ) { $ bValid = false ; $ skeVent -> addError ( isset ( $ aData [ 'lead_time_num' ] ) ? 'lead_time_unit' : 'lead_time_num' , 'Both Reminder fields should be filled out (or clear them both).' ) ; } } if ( isset ( $ aData [ 'ends_at' ] ) ) { if ( ! isset ( $ aData [ 'frequency' ] ) ) { $ bValid = false ; $ skeVent -> addError ( 'frequency' , 'A frequency is required for recurring events.' ) ; } if ( ! isset ( $ aData [ 'interval' ] ) || SkeVent :: INTERVAL_ONCE === $ aData [ 'interval' ] ) { $ bValid = false ; $ skeVent -> addError ( 'interval' , 'An interval (daily, weekly, etc.) is required for recurring events.' ) ; } } if ( isset ( $ aData [ 'frequency' ] ) && ! isset ( $ aData [ 'interval' ] ) ) { $ bValid = false ; $ skeVent -> addError ( 'interval' , 'An interval (daily, weekly, etc.) is required when a frequency is selected.' ) ; } if ( isset ( $ aData [ 'interval' ] ) ) { if ( SkeVent :: INTERVAL_DAILY === $ aData [ 'interval' ] && isset ( $ aData [ 'weekdays' ] ) ) { $ bValid = false ; $ skeVent -> addError ( 'weekdays' , 'A day of the week cannot be selected for daily events.' ) ; } } return $ bValid ; }
Validate the event data .
26,914
protected function validateOption ( $ mValue , array $ aOptions = null ) { return is_null ( $ mValue ) || is_null ( $ aOptions ) || array_key_exists ( $ mValue , $ aOptions ) ; }
Check if value is a valid option .
26,915
public function scanSourceFolders ( ) { $ this -> addons = [ ] ; foreach ( $ this -> sources as $ sourceDir ) { $ this -> scanSource ( $ sourceDir ) ; } }
Scan all source folders
26,916
public function scanSource ( $ sourceDir ) { $ this -> log ( LogLevel :: INFO , "Scanning addon source: {$sourceDir}" ) ; $ addonsCandidates = scandir ( $ sourceDir ) ; foreach ( $ addonsCandidates as $ addonCandidate ) { $ char = substr ( $ addonCandidate , 0 , 1 ) ; if ( $ char == '.' ) { continue ; } $ definitionFile = paths ( $ sourceDir , $ addonCandidate , "addon.json" ) ; if ( ! file_exists ( $ definitionFile ) ) { continue ; } try { $ addon = new Addon ( realpath ( $ definitionFile ) ) ; } catch ( \ Exception $ ex ) { $ this -> log ( LogLevel :: WARNING , " failed loading addon '{definition}': {message}" , [ 'definition' => $ definitionFile , 'message' => $ ex -> getMessage ( ) ] ) ; continue ; } $ this -> log ( LogLevel :: INFO , " found addon: {name} v{version} (provides {classes} classes from {path})" , [ 'name' => $ addon -> getInfo ( 'name' ) , 'version' => $ addon -> getInfo ( 'version' ) , 'path' => $ addon -> getPath ( ) , 'classes' => count ( $ addon -> getClasses ( ) ) ] ) ; $ this -> addons [ $ addon -> getInfo ( 'name' ) ] = $ addon ; } }
Scan source dir for addons
26,917
public function startAddon ( $ addonName , $ level = 0 ) { $ nest = str_repeat ( ' ' , $ level ) ; $ this -> log ( LogLevel :: NOTICE , "{$nest} start addon: {addon}" , [ 'addon' => $ addonName ] ) ; if ( $ this -> isStarted ( $ addonName ) ) { $ this -> log ( LogLevel :: INFO , "{$nest} already started" ) ; return true ; } $ addon = $ this -> getAddon ( $ addonName ) ; if ( ! $ addon ) { $ this -> log ( LogLevel :: WARNING , "{$nest} unknown addon, not loaded" ) ; return false ; } $ requiredAddons = $ addon -> getInfo ( 'requires' ) ?? [ ] ; if ( count ( $ requiredAddons ) ) { $ txtRequirements = implode ( ',' , $ requiredAddons ) ; $ this -> log ( LogLevel :: INFO , "{$nest} addon has requirements: {requirements}" , [ 'requirements' => $ txtRequirements ] ) ; $ missing = [ ] ; foreach ( $ requiredAddons as $ requiredAddon ) { if ( ! $ this -> isAvailable ( $ requiredAddon ) ) { $ missing [ ] = $ requiredAddon ; } } if ( count ( $ missing ) ) { $ txtMissing = implode ( ',' , $ missing ) ; $ this -> log ( LogLevel :: WARNING , "{$nest} missing requirements: {missing}" , [ 'missing' => $ txtMissing ] ) ; return false ; } $ startedRequirements = [ ] ; $ loadedAllRequirements = true ; foreach ( $ requiredAddons as $ requiredAddon ) { if ( ! $ this -> isStarted ( $ requiredAddon ) ) { $ loadedRequirement = false ; if ( $ this -> isAvailable ( $ requiredAddon ) ) { $ loadedRequirement = $ this -> startAddon ( $ requiredAddon , $ level + 1 ) ; } $ loadedAllRequirements &= $ loadedRequirement ; if ( ! $ loadedRequirement ) { $ this -> log ( LogLevel :: WARNING , "{$nest} failed starting required addon: {addon}" , [ 'addon' => $ requiredAddon ] ) ; return false ; } $ startedRequirements [ ] = $ requiredAddon ; } } } $ this -> autoload = array_merge ( $ this -> autoload , $ addon -> getClasses ( ) ) ; $ addonClass = $ addon -> getAddonClass ( ) ; if ( $ addonClass ) { $ this -> log ( LogLevel :: INFO , "{$nest} creating addon instance: {$addonClass}" ) ; $ instance = $ this -> di -> getArgs ( $ addonClass , [ new Reference ( [ AbstractConfig :: class , "addons.addon.{$addonName}" ] ) ] ) ; $ instance -> setAddon ( $ addon ) ; $ this -> instances [ $ addonName ] = $ instance ; $ instance -> start ( ) ; } $ this -> enabled [ $ addonName ] = true ; return true ; }
Start an addon
26,918
public function getInstance ( $ addonName ) { if ( ! $ this -> isStarted ( $ addonName ) ) { throw new \ Exception ( "Tried to get instance of inactive addon '{$addonName}'" ) ; } if ( ! array_key_exists ( $ addonName , $ this -> instances ) || ! ( $ this -> instances [ $ addonName ] instanceof AddonInterface ) ) { throw new \ Exception ( "Addon '{$addonName}' has no instance" ) ; } return $ this -> instances [ $ addonName ] ; }
Get addon instance
26,919
public function lookupCounterpartyTransactionType ( array $ tx , $ protocol_version = null ) { $ data = $ this -> parseBitcoinTransaction ( $ tx , $ protocol_version ) ; if ( $ data === null ) { return null ; } return $ data [ 'type' ] ; }
parses a transaction and determines the counterparty transaction type
26,920
public function parseBitcoinTransaction ( array $ tx , $ protocol_version = null ) { if ( $ protocol_version === null ) { $ protocol_version = self :: DEFAULT_PROTOCOL_VERSION ; } switch ( $ protocol_version ) { case 1 : return $ this -> parseBitcoinTransactionVersion1 ( $ tx ) ; case 2 : return $ this -> parseBitcoinTransactionVersion2 ( $ tx ) ; default : throw new Exception ( "Unknown protocol version" , 1 ) ; } }
parses a transaction and returns the raw counterparty data
26,921
protected static function typeIDToType ( $ type_id ) { if ( $ type_id === 0 ) { return 'send' ; } else if ( $ type_id === 2 ) { return 'enhanced_send' ; } else if ( $ type_id === 10 ) { return 'order' ; } else if ( $ type_id === 11 ) { return 'btcpay' ; } else if ( $ type_id === 20 ) { return 'issuance' ; } else if ( $ type_id === 30 ) { return 'broadcast' ; } else if ( $ type_id === 40 ) { return 'bet' ; } else if ( $ type_id === 50 ) { return 'dividend' ; } else if ( $ type_id === 70 ) { return 'cancel' ; } else if ( $ type_id === 21 ) { return 'callback' ; } else if ( $ type_id === 80 ) { return 'rps' ; } else if ( $ type_id === 81 ) { return 'rpsresolve' ; } return null ; }
map type id number to counterparty transaction type
26,922
protected function renderPlainText ( ServerRequestInterface $ request , ResponseInterface $ response , array $ allowedMethods ) { printf ( "Method %s is not allowed\r\n" , $ request -> getMethod ( ) ) ; if ( $ this -> isDisplayError ( ) ) { printf ( "Request method must be one of: (%s).\r\n" , implode ( ', ' , $ allowedMethods ) ) ; } }
Render Plain Text Output
26,923
protected function renderXML ( ServerRequestInterface $ request , ResponseInterface $ response , array $ allowedMethods ) { $ message = sprintf ( 'Method %s is not allowed' , $ request -> getMethod ( ) ) ; $ baseSep = str_repeat ( ' ' , 4 ) ; $ sep = str_repeat ( $ baseSep , 2 ) ; $ xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" . "<root>\n" . "{$baseSep}<error>\n" . "{$sep}<message>{$message}</message>\n" ; if ( $ this -> isDisplayError ( ) ) { $ method = htmlentities ( $ request -> getMethod ( ) ) ; $ allowedMethodXML = '' ; foreach ( $ allowedMethods as $ value ) { $ value = htmlentities ( $ value ) ; $ allowedMethodXML .= "{$baseSep}<method>{$value}</method>\n{$sep}" ; } $ xml .= "{$sep}<request_method>{$method}</request_method>\n" ; $ xml .= "{$sep}<allowed_methods>\n{$sep}{$allowedMethodXML}</allowed_methods>\n" ; } $ xml .= "{$baseSep}</error>\n</root>" ; echo $ xml ; }
Render XML Output
26,924
public function setAlpha ( $ alpha ) { $ alpha = ( float ) $ alpha ; if ( $ alpha < 0 || $ alpha > 1 ) { throw new \ UnexpectedValueException ( 'value must be within [0, 1]' ) ; } $ this -> _alpha = $ alpha ; }
alpha 0 = > 100% transparency alpha 1 = > opaque 0% transparency
26,925
public function getParentEntityDescriptor ( ) { if ( is_null ( $ this -> parentEntityDescriptor ) ) { $ this -> setParentEntityDescriptor ( EntityDescriptorRegistry :: getInstance ( ) -> getDescriptorFor ( $ this -> parentEntity ) ) ; } return $ this -> parentEntityDescriptor ; }
Gets the parent or related entity descriptor
26,926
protected function normalizeFieldName ( $ tableName ) { $ tableName = Text :: camelCaseToSeparator ( $ tableName , '#' ) ; $ parts = explode ( '#' , $ tableName ) ; $ lastName = array_pop ( $ parts ) ; $ lastName = Text :: singular ( strtolower ( $ lastName ) ) ; array_push ( $ parts , ucfirst ( $ lastName ) ) ; return lcfirst ( implode ( '' , $ parts ) ) ; }
Normalizes the key field by convention
26,927
protected function registerEntity ( $ entity ) { Orm :: getRepository ( $ this -> getParentEntity ( ) ) -> getIdentityMap ( ) -> set ( $ entity ) ; return $ entity ; }
Register the retrieved entities in the repository identity map
26,928
public function getAdapter ( ) { if ( null == $ this -> adapter ) { $ className = $ this -> getEntityDescriptor ( ) -> className ( ) ; $ repository = Orm :: getRepository ( $ className ) ; $ this -> setAdapter ( $ repository -> getAdapter ( ) ) ; } return $ this -> adapter ; }
Gets relation adapter
26,929
public function parse ( $ date , $ locale = null ) { $ result = new \ DateTime ( ) ; $ result -> setTimestamp ( $ this -> parseTimestamp ( $ date , $ locale ) ) ; return $ result ; }
Parse a string representation of a date to a \ DateTime
26,930
private function parseTimestamp ( $ date , $ locale = null ) { foreach ( $ this -> formats as $ timeFormat ) { foreach ( $ this -> formats as $ dateFormat ) { $ dateFormater = \ IntlDateFormatter :: create ( $ locale ? : \ Locale :: getDefault ( ) , $ dateFormat , $ timeFormat , date_default_timezone_get ( ) ) ; $ timestamp = $ dateFormater -> parse ( $ date ) ; if ( $ dateFormater -> getErrorCode ( ) == 0 ) { return $ timestamp ; } } } $ formats = array ( 'MMMM yyyy' , ) ; foreach ( $ formats as $ format ) { $ dateFormater = \ IntlDateFormatter :: create ( $ locale ? : \ Locale :: getDefault ( ) , $ this -> formats [ 'none' ] , $ this -> formats [ 'none' ] , date_default_timezone_get ( ) , \ IntlDateFormatter :: GREGORIAN , $ format ) ; $ timestamp = $ dateFormater -> parse ( $ date ) ; if ( $ dateFormater -> getErrorCode ( ) == 0 ) { return $ timestamp ; } } throw new \ Exception ( '"' . $ date . '" could not be converted to \DateTime' ) ; }
Parse a string representation of a date to a timestamp .
26,931
public static function spec ( $ constraints , $ defaults = [ ] , $ required = [ ] , $ messages = [ ] ) { return new static ( Spec :: define ( $ constraints , $ defaults , $ required ) , $ messages ) ; }
Shortcut for defining a validator using a Spec .
26,932
public function check ( array $ input ) { $ result = $ this -> spec -> check ( $ input ) ; return new SpecResult ( $ result -> getMissing ( ) , Arr :: walkCopy ( $ result -> getFailed ( ) , function ( $ key , $ value , & $ array , $ path ) { $ array [ $ key ] = Std :: coalesce ( Std :: firstBias ( Arr :: dotGet ( $ this -> messages , Std :: nonempty ( $ path , $ key ) ) !== null , [ Arr :: dotGet ( $ this -> messages , Std :: nonempty ( $ path , $ key ) ) ] , null ) , Std :: firstBias ( $ value instanceof AbstractConstraint , function ( ) use ( $ value ) { return $ value -> getDescription ( ) ; } , null ) , Std :: firstBias ( is_array ( $ value ) , function ( ) use ( $ value ) { return array_map ( function ( AbstractConstraint $ item ) { return $ item -> getDescription ( ) ; } , $ value ) ; } , $ value ) ) ; } , true , '' , false ) , $ result -> getStatus ( ) ) ; }
Check that the spec matches and overlay help messaged .
26,933
public function register ( ) { $ bindings = $ this -> bindings ( ) ; count ( $ bindings ) > 0 && App :: bind ( $ bindings ) ; $ providers = $ this -> providers ( ) ; count ( $ providers ) > 0 && App :: register ( $ providers ) ; $ config = $ this -> config ( ) ; count ( $ config ) > 0 && Config :: push ( $ config ) ; $ subscribers = $ this -> subscribers ( ) ; count ( $ subscribers ) > 0 && Event :: register ( $ subscribers ) ; $ this -> routes ( ) ; }
Called after pushing a service provider to the container
26,934
public function singleton ( $ name , $ object ) { if ( IOC :: hasSingleton ( $ name ) ) { return IOC :: singleton ( $ name ) ; } else { IOC :: singleton ( $ name , $ object ) ; return $ object ; } }
Tells the container the service should be a singleton
26,935
public static function makeTimestamp ( $ time ) { if ( is_numeric ( $ time ) ) return ( int ) $ time ; elseif ( $ time instanceof \ DateTime ) return $ time -> getTimestamp ( ) ; $ ts = strtotime ( $ time ) ; if ( $ ts === false ) throw new \ LogicException ( "Unable convert {$time} to a valid timestamp" ) ; return $ ts ; }
Convert a value to a timestamp .
26,936
private function tryCompile ( $ string , \ Closure $ afterEvents = null , $ flags = null ) { foreach ( $ this -> compilers as $ compiler => $ priority ) { if ( ! class_exists ( $ compiler ) ) { throw new NotFoundException ( "PytoTPL compiler ({$compiler}) couldn't be found!" ) ; } elseif ( ! is_subclass_of ( $ compiler , "PytoTPL\Compilers\AbstractCompiler" ) ) { throw new InvalidCompilerException ( "Compiler ({$compiler}) must extend (PytoTPL\Compilers\AbstractCompiler)!" ) ; } $ string = $ this -> run ( $ compiler , $ string ) ; } return $ string ; }
Load all the available compilers and run each one
26,937
private function run ( $ compiler , $ string ) { $ compiler = $ this -> getCompilerInstance ( $ compiler ) ; return preg_replace_callback ( $ compiler -> getPattern ( ) , function ( $ matches ) use ( $ compiler ) { return $ compiler -> compile ( $ matches ) ; } , $ string ) ; }
Run the compiler
26,938
public function wrap ( $ content , $ end = ';' , $ newLine = false ) { return '<?php ' . $ content . $ end . ' ?>' . ( $ newLine === true ? PHP_EOL : '' ) ; }
Wrap the given value in PHP tags
26,939
public function setTheme ( View $ view , $ themes ) { $ cacheKey = $ this -> getCacheKey ( $ view ) ; $ this -> themes [ $ cacheKey ] = $ themes ; }
Sets a theme for a table view
26,940
private function loadTemplates ( array $ themes ) { $ templates = array ( ) ; foreach ( $ themes as $ theme ) { $ key = is_object ( $ theme ) ? spl_object_hash ( $ theme ) : $ theme ; if ( ! isset ( $ this -> templates [ $ key ] ) ) { $ template = $ this -> twig -> load ( $ theme ) ; $ this -> templates [ $ key ] = $ template ; } $ templates [ ] = $ this -> templates [ $ key ] ; } return $ templates ; }
Loads the templates used by current theme .
26,941
public function moveNode ( $ headId , $ targetId = null , $ mode = self :: MODE_UNDER ) { $ head = $ this -> getNode ( $ headId ) ; $ target = $ this -> getNode ( $ targetId ) ; switch ( $ mode ) { case self :: MODE_BEFORE : $ operation = new MoveBefore ( $ head , $ target , $ this -> config , $ this ) ; break ; case self :: MODE_AFTER : $ operation = new MoveAfter ( $ head , $ target , $ this -> config , $ this ) ; break ; case self :: MODE_UNDER : $ operation = new MoveUnderEnd ( $ head , $ target , $ this -> config , $ this ) ; break ; } $ operation -> run ( ) ; }
Move head node to target node .
26,942
public function deleteNode ( $ nodeId ) { $ node = $ this -> getNode ( $ nodeId ) ; $ operation = new Operations \ Delete ( $ node , $ this -> config , $ this ) ; $ operation -> run ( ) ; }
Delete node and its children .
26,943
public function isChildOf ( $ head , $ target ) { if ( ! is_array ( $ head ) ) { $ head = $ this -> getNode ( $ head ) ; } if ( ! is_array ( $ target ) ) { $ target = $ this -> getNode ( $ target ) ; } $ config = $ this -> config ; $ headLft = $ head [ $ config [ 'lft' ] ] ; $ headRgt = $ head [ $ config [ 'rgt' ] ] ; $ targetLft = $ target [ $ config [ 'lft' ] ] ; $ targetRgt = $ target [ $ config [ 'rgt' ] ] ; if ( $ headLft > $ targetLft && $ headRgt < $ targetRgt ) { return TRUE ; } else { return FALSE ; } }
Is head node child of target node?
26,944
public function getChildren ( $ headId , $ relativeDepth = null , $ summarize = false ) { $ head = $ this -> getNode ( $ headId ) ; $ config = $ this -> config ; $ query = $ this -> table ( ) -> select ( null ) -> select ( "$config[id] AS id" ) -> where ( "$config[lft] > ?" , $ head [ 'lft' ] ) -> where ( "$config[rgt] < ?" , $ head [ 'rgt' ] ) ; if ( ! is_null ( $ relativeDepth ) ) { $ absoluteDepth = $ relativeDepth + $ head [ 'dpt' ] ; if ( $ summarize ) { $ query -> where ( "$config[dpt] <= ?" , $ absoluteDepth ) ; } else { $ query -> where ( "$config[dpt] = ?" , $ absoluteDepth ) ; } } $ children = $ query -> fetchAll ( ) ; return array_map ( function ( $ key ) { return $ key [ 'id' ] ; } , $ children ) ; }
Get IDs of children nodes .
26,945
public function getParents ( $ headId ) { $ head = $ this -> getNode ( $ headId ) ; $ config = $ this -> config ; $ parents = $ this -> table ( ) -> select ( null ) -> select ( "$config[id] AS id" ) -> where ( "$config[lft] < ?" , $ head [ 'lft' ] ) -> where ( "$config[rgt] > ?" , $ head [ 'rgt' ] ) -> where ( "$config[dpt] < ?" , $ head [ 'dpt' ] ) -> orderBy ( $ config [ 'lft' ] ) -> fetchAll ( ) ; return array_map ( function ( $ key ) { return $ key [ 'id' ] ; } , $ parents ) ; }
Get parents in order the big boss first .
26,946
protected function getNode ( $ id ) { $ config = $ this -> config ; return $ this -> table ( ) -> select ( null ) -> select ( "$config[id] AS id, $config[lft] AS lft, $config[rgt] AS rgt, $config[dpt] AS dpt, $config[prt] AS prt" ) -> where ( $ config [ 'id' ] , $ id ) -> fetch ( ) ; }
Return single node tree data .
26,947
public function setMustPass ( $ ref ) { if ( null !== $ this -> getMask ( $ ref ) ) { $ this -> must_pass = $ ref ; } else { throw new \ Exception ( sprintf ( "Unknown standard [%s] in Hostname validation!" , $ ref ) ) ; } }
Defines the RFC to validate
26,948
public function prepare ( InputRequest $ request ) { $ routeOptions = $ this -> getOptions ( ) ; if ( ! isset ( $ routeOptions [ 'session' ] ) || $ routeOptions [ 'session' ] ) { startSession ( ) ; } }
Prepare environment for this route
26,949
protected static function extractVariable ( $ str , & $ var = null , & $ regex = null ) { list ( $ p1 , $ p2 ) = explodeList ( ':' , $ str , 2 ) ; if ( $ p2 ) { $ var = $ p2 ; $ regex = $ p1 ; if ( ctype_alpha ( $ regex ) && isset ( static :: $ typesRegex [ $ regex ] ) ) { $ regex = static :: $ typesRegex [ $ regex ] ; } } else { $ var = $ p1 ; $ regex = '[^\/]+' ; } }
Extract variable from configuration string
26,950
protected function generatePathRegex ( ) { if ( $ this -> pathRegex ) { return ; } $ variables = array ( ) ; $ this -> pathRegex = preg_replace_callback ( '#\{([^\}]+)\}#sm' , function ( $ matches ) use ( & $ variables ) { $ regex = $ var = null ; static :: extractVariable ( str_replace ( '\.' , '.' , $ matches [ 1 ] ) , $ var , $ regex ) ; $ variables [ ] = $ var ; return '(' . $ regex . ')' ; } , str_replace ( '.' , '\.' , $ this -> path ) ) ; $ this -> pathVariables = $ variables ; }
Generate all regex of the path from extracted variables
26,951
public function getCheckedUidsAsArray ( $ property ) { $ array = array ( ) ; $ entities = $ this -> { 'get' . ucfirst ( $ property ) } ( ) ; foreach ( $ entities as $ item ) { $ array [ $ item -> getUid ( ) ] = $ item -> getUid ( ) ; } return $ array ; }
Returns the UIDs of releated entites as array
26,952
public function has ( $ property ) { if ( is_array ( $ property ) ) { foreach ( $ property as $ item ) { if ( is_a ( $ this -> { $ item } , '\\TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage' ) ) { return ( $ this -> { $ item } -> count ( ) ) ? true : false ; } else { return ( ! empty ( $ this -> { $ item } ) ) ? true : false ; } } } else { if ( is_a ( $ this -> { $ property } , '\\TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage' ) ) { return ( $ this -> { $ property } -> count ( ) ) ? true : false ; } else { return ( ! empty ( $ this -> { $ property } ) ) ? true : false ; } } }
Checks if a property has value
26,953
public static function dashesToCamelCase ( $ dashes ) { $ words = explode ( '-' , $ dashes ) ; $ camelCase = '' ; foreach ( $ words as $ word ) { $ camelCase .= ucfirst ( $ word ) ; } return $ camelCase ; }
Convert a lowercase dash - separated name to a camel case class - name . E . g . from camel - case to CamelCase .
26,954
public static function underscoresToCamelCase ( $ underscores ) { $ words = explode ( '_' , $ underscores ) ; $ camelCase = '' ; foreach ( $ words as $ word ) { $ camelCase .= ucfirst ( $ word ) ; } return $ camelCase ; }
Convert a lowercase underscore - separated name to a camel case class - name . E . g . from camel_case to CamelCase .
26,955
public static function getNamespace ( $ className ) { if ( is_object ( $ className ) ) { $ className = get_class ( $ className ) ; } if ( strpos ( $ className , '\\' ) === false ) { return '' ; } return preg_replace ( '/\\\\[^\\\\]+$/' , '' , $ className ) ; }
Get namespace part of a class name .
26,956
public static function getClassName ( $ className ) { if ( is_object ( $ className ) ) { $ className = get_class ( $ className ) ; } $ className = array_slice ( explode ( '\\' , $ className ) , - 1 ) ; return $ className [ 0 ] ; }
Get class name part of a qualified class name .
26,957
public static function getCaller ( ) { $ backtrace = debug_backtrace ( DEBUG_BACKTRACE_IGNORE_ARGS , 3 ) ; if ( isset ( $ backtrace [ 2 ] ) ) { $ caller = '' ; if ( isset ( $ backtrace [ 2 ] [ 'class' ] ) ) { $ caller = $ backtrace [ 2 ] [ 'class' ] . $ backtrace [ 2 ] [ 'type' ] ; } $ caller .= $ backtrace [ 2 ] [ 'function' ] ; return $ caller ; } return '{null}' ; }
Get caller class and method .
26,958
public static function create ( array $ data ) : Player { $ player = new Player ( ) ; parent :: fill ( $ data , $ player ) ; if ( is_array ( $ player -> clan ) ) { $ player -> clan = Clan :: create ( $ player -> clan ) ; } if ( is_array ( $ player -> league ) ) { $ player -> league = League :: create ( $ player -> league ) ; } return $ player ; }
Creates a player object with the given data
26,959
public function stopBlock ( $ name = null ) { if ( empty ( $ this -> currentBlockName ) ) { throw new InvalidParamException ( "Unexpected stopBlock in '{$this->processingViewFile}'" ) ; } if ( ! empty ( $ name ) && $ this -> currentBlockName != $ name ) { throw new InvalidParamException ( "Expected current closed block name '{$this->currentBlockName}' instead of '{$name}'" . " in '{$this->processingViewFile}'" ) ; } $ name = $ this -> currentBlockName ; $ fullBlockName = $ this -> getCurrentBlockFullName ( ) ; array_pop ( static :: $ _blocksStack ) ; $ content = ob_get_clean ( ) ; if ( ! $ this -> viewBlocks ( $ this -> processingViewFile ) -> exists ( $ fullBlockName ) ) { $ this -> viewBlocks ( $ this -> processingViewFile ) -> add ( $ fullBlockName , $ content ) ; } $ savedContent = $ this -> findProperBlock ( $ fullBlockName , $ this -> processingViewFile ) ; if ( $ savedContent !== false ) { $ content = $ savedContent ; } if ( $ savedContent !== false && empty ( $ this -> _extendingParent [ $ this -> processingViewFile ] ) ) { $ n = $ this -> hasParentBlock ( $ savedContent ) ; while ( $ n -- ) { $ savedContent = $ this -> replaceParentBlock ( $ savedContent ) ; } echo $ savedContent ; } else { echo $ content ; } }
Stop block with save or echo .
26,960
protected function replaceParentBlock ( $ savedContent ) { $ pattern = sprintf ( self :: TMPL_RENDER_PARENT , "([^']+)" , "([^|]+)" ) ; $ result = preg_match ( "/{$pattern}/" , $ savedContent , $ matches ) ; if ( ! $ result ) { return $ savedContent ; } else { $ fullBlockName = $ matches [ 1 ] ; $ viewFileName = $ matches [ 2 ] ; $ replacement = $ this -> findParentBlock ( $ fullBlockName , $ viewFileName ) ; $ out = preg_replace ( "/{$pattern}/" , $ replacement , $ savedContent ) ; return $ out ; } }
Replace in block tag with parentBlock info .
26,961
protected function findParentBlock ( $ fullBlockName , $ viewFileName ) { $ parentViewFile = $ this -> findParentViewFile ( $ viewFileName ) ; $ viewFilesChain = $ this -> getViewFilesChain ( $ parentViewFile ) ; $ savedContent = '' ; foreach ( $ viewFilesChain as $ viewFile ) { if ( $ this -> viewBlocks ( $ viewFile ) -> exists ( $ fullBlockName ) ) { $ savedContent = $ this -> viewBlocks ( $ viewFile ) -> get ( $ fullBlockName ) ; break ; } } return $ savedContent ; }
Find parent block .
26,962
public function startParent ( $ addParentData = [ ] ) { if ( ! empty ( $ this -> _extendingParent [ $ this -> processingViewFile ] ) ) { throw new InvalidParamException ( "Nested startParent() impossible in '{$this->processingViewFile}'" ) ; } $ this -> _extendingParent [ $ this -> processingViewFile ] = true ; $ this -> _addParentData [ $ this -> processingViewFile ] = $ addParentData ; ob_start ( ) ; ob_implicit_flush ( false ) ; }
Begin extend parent view file .
26,963
public function stopParent ( ) { if ( ! empty ( $ this -> currentBlockName ) ) { throw new InvalidParamException ( "Unclosed startBlock detected in '{$this->processingViewFile}'" ) ; } if ( empty ( $ this -> _extendingParent [ $ this -> processingViewFile ] ) ) { throw new InvalidParamException ( "stopParent unexpected here without startParent in '{$this->processingViewFile}'" ) ; } $ this -> _extendingParent [ $ this -> processingViewFile ] = false ; $ lost = ob_get_clean ( ) ; $ parentFile = $ this -> findParentViewFile ( $ this -> processingViewFile ) ; if ( $ parentFile ) { $ this -> _currentViewFile [ $ this -> viewFile ] = $ parentFile ; $ parentDataFile = $ this -> viewFile ; $ params = empty ( $ this -> _viewsParams [ $ parentDataFile ] ) ? [ ] : $ this -> _viewsParams [ $ parentDataFile ] ; if ( ! empty ( $ this -> _addParentData [ $ parentDataFile ] ) ) { $ addParentData = $ this -> _addParentData [ $ parentDataFile ] ; $ params = ArrayHelper :: merge ( $ params , $ addParentData ) ; } $ result = $ this -> renderPhpFile ( $ parentFile , $ params ) ; $ n = $ this -> hasParentBlock ( $ result ) ; while ( $ n -- ) { $ result = $ this -> replaceParentBlock ( $ result ) ; } if ( $ this -> hasParentBlock ( $ result ) ) { throw new InvalidParamException ( "Unprocessed nested parentBlock found in '{$this->processingViewFile}'" ) ; } echo $ result ; } }
End extend parent view file .
26,964
protected function getViewsSubSubdir ( $ currentViewFile ) { $ viewsSubSubdir = false ; $ currentViewFile = realpath ( $ currentViewFile ) ; $ currentViewPath = dirname ( $ currentViewFile ) ; $ module = $ this -> context -> module ; $ pathList = $ module -> getBasePathList ( ) ; foreach ( $ pathList as $ modulePath ) { $ viewsPath = realpath ( $ modulePath ) . DIRECTORY_SEPARATOR . $ module :: $ viewsSubdir ; if ( strpos ( $ currentViewPath , $ viewsPath ) === 0 ) { $ viewsSubSubdir = substr ( $ currentViewPath , strlen ( $ viewsPath ) + 1 ) ; return $ viewsSubSubdir ; } } throw new InvalidParamException ( "Unexpected view file '{$currentViewFile}' is out of module's '{$module->className()}' parents chain" ) ; }
Get views sub subdir .
26,965
public function getStatus ( $ code ) { $ filename = __DIR__ . '/../../data/' . substr ( $ code , 0 , 1 ) . '.json' ; if ( file_exists ( $ filename ) ) { return json_decode ( file_get_contents ( $ filename ) , true ) [ $ code ] ; } return [ ] ; }
Get status full description from code
26,966
protected static function parentCancellerFunction ( self & $ parent ) { return function ( ) use ( & $ parent ) { -- $ parent -> requiredCancelRequests ; if ( $ parent -> requiredCancelRequests <= 0 ) { $ parent -> cancel ( ) ; } $ parent = null ; } ; }
Creates a static parent canceller callback that is not bound to a promise instance .
26,967
protected static function rejectFunction ( self & $ target ) { return function ( $ reason = null ) use ( & $ target ) { if ( $ target !== null ) { $ target -> reject ( $ reason ) ; $ target = null ; } } ; }
Creates a static rejection callback that is not bound to a promise instance .
26,968
protected static function notifyFunction ( & $ progressHandlers ) { return function ( $ update = null ) use ( & $ progressHandlers ) { foreach ( $ progressHandlers as $ handler ) { $ handler ( $ update ) ; } } ; }
Creates a static progress callback that is not bound to a promise instance .
26,969
private function setSelect2Options ( $ select2options ) { foreach ( $ select2options as $ key => $ option ) $ this -> select2options [ $ key ] = $ option ; return $ this ; }
Merges the options
26,970
public function setPlaceholder ( $ placeholder = null ) { if ( $ placeholder === false ) $ this -> usePlaceholder = false ; else { $ this -> setSelect2Options ( array ( self :: SELECT2_OPTION_PLACEHOLDER => $ placeholder === null ? $ this -> label : $ placeholder ) ) ; $ this -> usePlaceholder = true ; } return $ this ; }
Determines the placeholder behaviour . Set to FALSE if the first option should be selected on default . Set to NULL if the label should be used . Otherwise specify a placeholder .
26,971
protected function isSelected ( $ v ) { return $ this -> value === $ v || ( is_array ( $ this -> value ) && in_array ( $ v , $ this -> value ) ) ; }
Determines whether the given value is currently selected
26,972
public function orderBy ( $ orderBy = null ) { if ( is_array ( $ orderBy ) ) $ this -> orderByClause = $ orderBy ; else $ this -> orderByClause = func_get_args ( ) ; return $ this ; }
Sets order by clauses
26,973
public function groupBy ( $ groupBy ) { if ( is_array ( $ groupBy ) ) $ this -> groupByClause = $ groupBy ; else $ this -> groupByClause = func_get_args ( ) ; return $ this ; }
Sets group by clauses
26,974
public function fetch ( $ mappingType = null ) { list ( $ query , $ args ) = $ this -> build ( ) ; if ( is_null ( $ mappingType ) ) $ mapper = empty ( $ this -> config ) ? $ this -> fluent -> getMapper ( ) : $ this -> fluent -> getMapper ( ) -> merge ( $ this -> config ) ; else { $ config = empty ( $ this -> config ) ? [ 'map.type' => $ mappingType ] : array_merge ( $ this -> config , [ 'map.type' => $ mappingType ] ) ; $ mapper = $ this -> fluent -> getMapper ( ) -> merge ( $ config ) ; } return empty ( $ args ) ? $ mapper -> query ( $ query ) : $ mapper -> execute ( $ query , $ args ) ; }
Fetchs the current query with an optional mapping type
26,975
public function exists ( $ cookie_name = null ) { if ( ! empty ( $ cookie_name ) ) { $ this -> setName ( $ cookie_name ) ; } return isset ( $ _COOKIE [ $ this -> getName ( ) ] ) ; }
Test if a cookie exists
26,976
public function read ( $ cookie_name = null ) { if ( ! empty ( $ cookie_name ) ) { $ this -> setName ( $ cookie_name ) ; } $ val = isset ( $ _COOKIE [ $ this -> getName ( ) ] ) ? $ _COOKIE [ $ this -> getName ( ) ] : null ; if ( $ val && is_string ( $ val ) && ( $ this -> getFlag ( ) & self :: FLATNESS_ARRAY ) ) { parse_str ( $ val , $ tmp_val ) ; if ( ! empty ( $ tmp_val ) && $ tmp_val != $ val ) { $ val = $ tmp_val ; } } $ this -> setValue ( $ val ) ; return $ this -> getValue ( ) ; }
Get a cookie value
26,977
public function addInCookie ( $ variable_name , $ variable_value , $ cookie_name = null ) { if ( ! empty ( $ cookie_name ) ) { $ this -> setName ( $ cookie_name ) ; } if ( ! empty ( $ variable_value ) ) { $ this -> setValue ( $ variable_value ) ; } return $ this -> setName ( $ this -> getName ( ) . '[' . $ variable_name . ']' ) -> send ( ) ; }
Add a variable value in a cookie
26,978
public function clear ( $ cookie_name = null ) { if ( ! empty ( $ cookie_name ) ) { $ this -> setName ( $ cookie_name ) ; } return $ this -> setValue ( null ) -> setExpire ( - 1000 ) -> send ( ) ; }
Clear a cookie
26,979
public static function parse ( $ value ) { if ( \ is_string ( $ value ) ) { $ operator = null ; if ( \ strpos ( $ value , AbstractMatcher :: OPERATOR_AND ) ) { $ operator = AbstractMatcher :: OPERATOR_AND ; $ value = \ explode ( AbstractMatcher :: OPERATOR_AND , $ value ) ; } elseif ( \ strpos ( $ value , AbstractMatcher :: OPERATOR_OR ) ) { $ operator = AbstractMatcher :: OPERATOR_OR ; $ value = \ explode ( AbstractMatcher :: OPERATOR_OR , $ value ) ; } elseif ( 0 === \ strpos ( $ value , AbstractMatcher :: OPERATOR_NOT ) ) { $ value = [ AbstractMatcher :: OPERATOR_NOT => \ substr ( $ value , 1 ) ] ; } if ( null !== $ operator ) { return [ $ operator => \ array_map ( function ( $ val ) { return 0 === \ strpos ( $ val , AbstractMatcher :: OPERATOR_NOT ) ? [ AbstractMatcher :: OPERATOR_NOT => \ substr ( $ val , 1 ) ] : $ val ; } , $ value ) ] ; } } return $ value ; }
Checks if the given expression is a string and if so parses it and returns an array contains the parsed expression that is ready to be used in matchers .
26,980
private function seedOptions ( ) { $ options = [ 'general' => [ 'site_name' => [ ] , 'site_desc' => [ ] , 'default_page_size' => [ ] , 'cookies_policy_url' => [ ] , ] , 'seo' => [ 'desc_length' => [ ] , 'google_analytics_id' => [ ] , ] ] ; foreach ( $ options as $ categoryKey => $ category ) { foreach ( $ options [ $ categoryKey ] as $ key => $ option ) { foreach ( Language :: all ( ) -> toArray ( ) as $ lang ) { if ( $ categoryKey != 'general' ) { $ options [ $ categoryKey ] [ $ key ] [ $ lang [ 'code' ] ] = config ( 'gzero.' . $ categoryKey . '.' . $ key ) ; } else { $ value = $ this -> getDefaultValueForGeneral ( $ key ) ; $ options [ $ categoryKey ] [ $ key ] [ $ lang [ 'code' ] ] = $ value ; } } } } foreach ( $ options as $ category => $ option ) { OptionCategory :: create ( [ 'key' => $ category ] ) ; foreach ( $ option as $ key => $ value ) { OptionCategory :: find ( $ category ) -> options ( ) -> create ( [ 'key' => $ key , 'value' => $ value ] ) ; } } }
Seed options from gzero config to main category
26,981
private function getDefaultValueForGeneral ( $ key ) { switch ( $ key ) { case 'site_name' : $ value = config ( 'app.name' ) ; break ; case 'site_desc' : $ value = "GZERO-CMS Content management system." ; break ; default : $ value = config ( 'gzero.' . $ key ) ; return $ value ; } return $ value ; }
It generates default value for general options
26,982
public function link ( ? string $ link = null ) : self { $ this -> control -> href = $ link ; return $ this ; }
Ulozi link odkazu
26,983
private function getKey ( string $ id = null ) : string { $ id = $ id ? : session_id ( ) ; return sprintf ( '%s/session/%s' , session_name ( ) , $ id ) ; }
Helper to get a formatted key for memcached based on a session ID .
26,984
public function actionSignup ( $ defaultUrl = null ) { $ user = $ this -> module -> model ( 'User' ) ; $ configProfileForm = [ 'user' => $ user , 'scenario' => ProfileForm :: SCENARIO_CREATE , 'captchaActionUid' => $ this -> uniqueId . '/' . static :: $ captchaActionId , ] ; $ model = $ this -> module -> model ( 'ProfileForm' , [ $ configProfileForm ] ) ; $ post = Yii :: $ app -> request -> post ( ) ; $ loaded = $ model -> load ( $ post ) ; if ( $ loaded && $ model -> save ( true ) ) { $ this -> sendSignupEmail ( $ model ) ; if ( $ defaultUrl === null ) { $ defaultUrl = Yii :: $ app -> getHomeUrl ( ) ; } return $ this -> goBack ( $ defaultUrl ) ; } else { return $ this -> render ( 'profile-form' , [ 'model' => $ model , ] ) ; } }
Create user s profile .
26,985
public function actionConfirm ( $ token ) { $ user = $ this -> module -> model ( 'User' ) ; $ user = $ this -> findModel ( [ 'auth_key' => $ token , 'status' => $ user :: STATUS_REGISTERED , ] ) ; if ( empty ( $ user ) ) { Yii :: $ app -> session -> setFlash ( 'error' , Yii :: t ( $ this -> tcModule , 'Such unconfirmed user not found or already confirmed.' ) . ' ' . Yii :: t ( $ this -> tcModule , 'Try to login or signup again.' ) ) ; return $ this -> redirect ( [ 'login' ] ) ; } if ( $ this -> confirmExpireDays ) { $ confirmExpirePeriod = 60 * 60 * 24 * $ this -> confirmExpireDays ; if ( time ( ) > ( $ user -> created_at + $ confirmExpirePeriod ) ) { $ user -> delete ( ) ; Yii :: $ app -> session -> setFlash ( 'error' , Yii :: t ( $ this -> tcModule , 'Token expired please register again.' ) ) ; return $ this -> redirect ( [ 'signup' ] ) ; } } $ user -> status = $ this -> waitModeration ? $ user :: STATUS_WAIT : $ user :: STATUS_ACTIVE ; $ user -> auth_key = $ user -> generateAuthKey ( ) ; $ result = $ user -> save ( ) ; if ( $ result ) { $ msg = Yii :: t ( $ this -> tcModule , 'Registration confirmed.' ) ; if ( $ this -> waitModeration ) { $ msg .= ' ' . Yii :: t ( $ this -> tcModule , 'Wait moderation.' ) ; } Yii :: $ app -> session -> setFlash ( 'success' , $ msg ) ; } else { $ msg = Yii :: t ( $ this -> tcModule , 'User registration confirmation error.' ) ; Yii :: trace ( $ msg . ' ' . var_export ( $ user -> errors , true ) . ' ' . var_export ( $ user -> attributes , true ) ) ; Yii :: $ app -> session -> setFlash ( 'error' , $ msg . ' ' . Yii :: t ( $ this -> tcModule , 'Apply to support.' ) ) ; } return $ this -> goHome ( ) ; }
Confirm registration by click on link in email .
26,986
public function setViewOptions ( $ template , array $ view_data = array ( ) ) { $ this -> view_options = $ view_data ; $ this -> view_template = $ template ; return $ this ; }
Compiles the options to use for the view
26,987
public function getMailer ( ) { if ( is_null ( $ this -> mailer ) ) { if ( class_exists ( '\Swift' ) ) { if ( version_compare ( \ Swift :: VERSION , 4 , '<=' ) && version_compare ( \ Swift :: VERSION , 3 , '>=' ) ) { $ mailer = new Email \ Swift3 ( $ this -> config ) ; } else { $ mailer = new Email \ Swift5 ( $ this -> config ) ; } } else { $ mailer = new Email \ Swift5 ( $ this -> config ) ; } $ this -> mailer = $ mailer ; } return $ this -> mailer ; }
Returns an instance of the mail object
26,988
public function clear ( ) { $ this -> mailer = null ; $ this -> to = $ this -> attachemnts = array ( ) ; $ this -> subject = $ this -> message = false ; return $ this ; }
Resets the email object
26,989
public function send ( array $ vars = array ( ) ) { if ( count ( $ this -> getTo ( ) ) == 0 ) { throw new \ InvalidArgumentException ( 'A "To" email address is requried' ) ; } if ( $ this -> getSubject ( ) == '' ) { throw new \ InvalidArgumentException ( 'A subject for the email must be set' ) ; } if ( $ this -> getMessage ( ) == '' ) { throw new \ InvalidArgumentException ( 'There isn\'t a message set' ) ; } $ valid_emails = array ( ) ; foreach ( $ this -> getTo ( ) as $ to ) { if ( filter_var ( trim ( $ to ) , FILTER_VALIDATE_EMAIL ) ) { $ valid_emails [ ] = trim ( $ to ) ; } } if ( ! $ valid_emails ) { return ; } $ mailer = $ this -> getMailer ( ) ; $ subject = $ this -> getView ( ) -> render ( $ this -> getSubject ( ) , $ vars ) ; $ body_message = $ this -> getView ( ) -> render ( $ this -> getMessage ( ) , $ vars ) ; $ message = $ mailer -> getMessage ( $ valid_emails , $ this -> config [ 'from_email' ] , $ this -> config [ 'sender_name' ] , $ subject , $ body_message , $ this -> getAttachments ( ) , $ this -> getMailtype ( ) ) ; if ( ! $ mailer -> send ( $ message ) ) { throw new EmailException ( $ this -> getMailer ( ) -> ErrorInfo ) ; } $ this -> clear ( ) ; }
Sends the email
26,990
public function canHandle ( ehough_shortstop_api_HttpRequest $ request ) { $ scheme = $ request -> getUrl ( ) -> getScheme ( ) ; return preg_match_all ( '/https?/' , $ scheme , $ matches ) === 1 ; }
Determines if this transport can handle the given request .
26,991
public function fmap ( callable $ closure ) { return $ this -> bind ( function ( $ a ) use ( $ closure ) { return $ this -> of ( $ closure ( $ a ) ) ; } ) ; }
Apply a function .
26,992
public function set ( float $ x , float $ y ) { $ this -> setX ( $ x ) ; $ this -> setY ( $ y ) ; }
Set the X and Y coordinate of the vector .
26,993
public static function Taiutc ( $ tai1 , $ tai2 , & $ utc1 , & $ utc2 ) { $ big1 ; $ i ; $ j ; $ a1 ; $ a2 ; $ u1 ; $ u2 ; $ g1 ; $ g2 ; $ big1 = ( $ tai1 >= $ tai2 ) ; if ( $ big1 ) { $ a1 = $ tai1 ; $ a2 = $ tai2 ; } else { $ a1 = $ tai2 ; $ a2 = $ tai1 ; } $ u1 = $ a1 ; $ u2 = $ a2 ; for ( $ i = 0 ; $ i < 3 ; $ i ++ ) { $ j = IAU :: Utctai ( $ u1 , $ u2 , $ g1 , $ g2 ) ; if ( $ j < 0 ) return $ j ; $ u2 += $ a1 - $ g1 ; $ u2 += $ a2 - $ g2 ; } if ( $ big1 ) { $ utc1 = $ u1 ; $ utc2 = $ u2 ; } else { $ utc1 = $ u2 ; $ utc2 = $ u1 ; } return $ j ; }
- - - - - - - - - - i a u T a i u t c - - - - - - - - - -
26,994
public function validateQuery ( $ query ) { if ( ! is_string ( $ query ) && ! method_exists ( $ query , '__toString' ) ) { throw new InvalidArgumentException ( 'Query must be a string' ) ; } if ( strpos ( $ query , '#' ) !== false ) { throw new InvalidArgumentException ( 'Query must not contain a URI fragment' ) ; } }
Validate query .
26,995
private function isReserved ( string $ host ) : bool { $ hosts = [ $ host ] ; if ( ! \ preg_match ( '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/' , $ host ) ) { $ tmp = \ gethostbynamel ( $ host ) ; $ hosts = $ tmp !== false ? $ tmp : [ ] ; } $ res = true ; $ flags = FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ; foreach ( $ hosts as $ host ) { if ( \ filter_var ( $ host , FILTER_VALIDATE_IP , [ 'flags' => $ flags ] ) !== false ) { $ res = false ; break ; } } return $ res ; }
Checks whether host IP is private or reserved
26,996
private function mxCheck ( string $ value = '' ) : bool { $ mxHosts = [ ] ; $ weight = [ ] ; if ( @ \ getmxrr ( $ value , $ mxHosts , $ weight ) !== false ) { if ( ! empty ( $ mxHosts ) && ! empty ( $ weight ) ) { $ mxHosts = \ array_combine ( $ mxHosts , $ weight ) ; } \ arsort ( $ mxHosts ) ; } elseif ( ( $ result = @ \ gethostbynamel ( $ value ) ) !== false ) { $ mxHosts = \ array_flip ( $ result ) ; } $ isValid = true ; if ( empty ( $ mxHosts ) ) { $ isValid = false ; } elseif ( $ this -> options [ 'deep-mx-check' ] === true ) { $ isValid = $ this -> deepMxCheck ( $ mxHosts ) ; } if ( ! $ isValid ) { $ this -> setError ( self :: VALIDATOR_ERROR_EMAIL_INVALID_MX ) ; } return $ isValid ; }
Performs MX check
26,997
private function deepMxCheck ( array $ value = [ ] ) : bool { $ isValid = false ; foreach ( $ value as $ host => $ weight ) { $ res = $ this -> isReserved ( $ host ) ; if ( ! $ res && ( \ checkdnsrr ( $ host , 'A' ) || \ checkdnsrr ( $ host , 'AAAA' ) || \ checkdnsrr ( $ host , 'A6' ) ) ) { $ isValid = true ; break ; } } return $ isValid ; }
Performs deep MX check
26,998
public function deleteAllItemsByUser ( $ userId ) { if ( empty ( $ userId ) ) { return [ ] ; } $ command = \ Yii :: $ app -> getDb ( ) -> createCommand ( ) ; $ command -> delete ( $ this -> assignmentTable , 'user_id = :user_id' , [ 'user_id' => $ userId ] ) ; return $ command -> execute ( ) ; }
Deleted roles and permissions assigned to user .
26,999
public static function propertyBatchLoad ( int $ batch_size = 8 , int $ modify_replace = 0 ) { $ batchSizeList = [ 1 => 1 , 2 => 2 , 3 => 4 , 4 => 8 , 5 => 16 , 6 => 32 , 7 => 64 , 8 => 128 , 9 => 256 , ] ; $ per_page = $ batchSizeList [ $ batch_size ] ?? 128 ; $ first_page = \ Drupal :: service ( 'nt8tabsio.tabs_service' ) -> get ( "property" , [ "page" => 1 , "pageSize" => $ per_page ] ) ; $ first_page = json_decode ( $ first_page ) ; $ search_instance_id = $ first_page -> searchId ; $ total_results = $ first_page -> totalResults ; $ batch = [ 'title' => t ( 'Loading all properties from API.' ) , 'operations' => [ ] , 'progress_message' => t ( 'Processed @current out of @total.' ) , 'finished' => '\Drupal\nt8property\Batch\NT8PropertyBatch::propertyBatchLoadFinishedCallback' , ] ; $ pages = ceil ( $ total_results / $ per_page ) ; $ last_page = $ total_results - ( $ per_page * ( $ pages - 1 ) ) ; for ( $ page_counter = 0 ; $ page_counter < $ pages ; $ page_counter ++ ) { $ batch [ "operations" ] [ ] = [ '\Drupal\nt8property\Batch\NT8PropertyBatch::propertyBatchLoadCallback' , [ $ page_counter , [ 'per_page' => $ per_page , 'last_page' => $ last_page , 'pages' => $ pages , ] , $ search_instance_id , $ modify_replace , ] , ] ; } batch_set ( $ batch ) ; }
Instantiates and handles a Drupal batch property load .