idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
47,300
public function init ( array $ params = array ( ) ) { if ( isset ( $ _SESSION [ self :: SESSION_PREFIX . '_' . $ this -> id ] ) ) { $ this -> token = $ _SESSION [ self :: SESSION_PREFIX . '_' . $ this -> id ] ; } parent :: init ( $ params ) ; }
Social network initialization
47,301
protected function setUser ( array $ userData , & $ user = null ) { $ user -> birthday = date ( 'Y-m-d H:i:s' , strtotime ( $ user -> birthday ) ) ; if ( isset ( $ user ) ) { $ this -> user = & $ user ; } }
Fill object User
47,302
protected function & storeUserData ( & $ user = null ) { if ( ! isset ( $ user ) ) { $ user = new $ this -> dbTable ( false ) ; } $ user [ $ this -> dbIdField ] = $ this -> user -> socialID ; $ user [ $ this -> dbNameField ] = strlen ( $ this -> user -> name ) ? $ this -> user -> name : $ user [ $ this -> dbNameField ] ; $ user [ $ this -> dbSurnameField ] = strlen ( $ this -> user -> surname ) ? $ this -> user -> surname : $ user [ $ this -> dbSurnameField ] ; $ user [ $ this -> dbGenderField ] = strlen ( $ this -> user -> gender ) ? $ this -> user -> gender : $ user [ $ this -> dbGenderField ] ; $ user [ $ this -> dbBirthdayField ] = max ( $ user [ $ this -> dbBirthdayField ] , $ this -> user -> birthday ) ; $ user [ $ this -> dbPhotoField ] = strlen ( $ this -> user -> photo ) ? $ this -> user -> photo : $ user [ $ this -> dbPhotoField ] ; if ( ! strlen ( $ this -> user -> email ) ) { if ( ! strlen ( $ user -> email ) ) { $ user [ $ this -> dbEmailField ] = md5 ( $ this -> user -> socialID ) ; } } else { $ user [ $ this -> dbEmailField ] = $ this -> user -> email ; } $ user -> save ( ) ; return $ user ; }
Store current social user data in database
47,303
public function & friends ( $ count = null , $ offset = null ) { $ result = array ( ) ; if ( isset ( $ this -> active ) ) { $ result = & $ this -> active -> friends ( $ count , $ offset ) ; } return $ result ; }
Get user fiends list
47,304
public static function IsSpam ( $ RecordType , $ Data , $ Options = array ( ) ) { if ( self :: $ Disabled ) return FALSE ; if ( $ RecordType == 'Registration' ) { TouchValue ( 'Username' , $ Data , $ Data [ 'Name' ] ) ; } else { TouchValue ( 'InsertUserID' , $ Data , Gdn :: Session ( ) -> UserID ) ; $ User = Gdn :: UserModel ( ) -> GetID ( GetValue ( 'InsertUserID' , $ Data ) , DATASET_TYPE_ARRAY ) ; if ( $ User ) { if ( GetValue ( 'Verified' , $ User ) ) { return FALSE ; } TouchValue ( 'Username' , $ Data , $ User [ 'Name' ] ) ; TouchValue ( 'Email' , $ Data , $ User [ 'Email' ] ) ; TouchValue ( 'IPAddress' , $ Data , $ User [ 'LastIPAddress' ] ) ; } } if ( ! isset ( $ Data [ 'Body' ] ) && isset ( $ Data [ 'Story' ] ) ) { $ Data [ 'Body' ] = $ Data [ 'Story' ] ; } TouchValue ( 'IPAddress' , $ Data , Gdn :: Request ( ) -> IpAddress ( ) ) ; $ Sp = self :: _Instance ( ) ; $ Sp -> EventArguments [ 'RecordType' ] = $ RecordType ; $ Sp -> EventArguments [ 'Data' ] = & $ Data ; $ Sp -> EventArguments [ 'Options' ] = & $ Options ; $ Sp -> EventArguments [ 'IsSpam' ] = FALSE ; $ Sp -> FireEvent ( 'CheckSpam' ) ; $ Spam = $ Sp -> EventArguments [ 'IsSpam' ] ; if ( $ Spam && GetValue ( 'Log' , $ Options , TRUE ) ) { $ LogOptions = array ( ) ; switch ( $ RecordType ) { case 'Registration' : $ LogOptions [ 'GroupBy' ] = array ( 'RecordIPAddress' ) ; break ; case 'Comment' : case 'Discussion' : case 'Activity' : case 'ActivityComment' : $ LogOptions [ 'GroupBy' ] = array ( 'RecordID' ) ; break ; } LogModel :: Insert ( 'Spam' , $ RecordType , $ Data , $ LogOptions ) ; } return $ Spam ; }
Check whether or not the record is spam .
47,305
public static function clear ( $ path = null ) { if ( empty ( $ path ) ) { self :: $ _items = array ( ) ; return ; } if ( Hash :: check ( self :: $ _items , $ path ) ) { self :: $ _items = Hash :: insert ( self :: $ _items , $ path , array ( ) ) ; } }
Clear all menus .
47,306
public static function order ( $ items ) { if ( empty ( $ items ) ) { return array ( ) ; } $ _items = array_combine ( array_keys ( $ items ) , Hash :: extract ( $ items , '{s}.weight' ) ) ; asort ( $ _items ) ; foreach ( array_keys ( $ _items ) as $ key ) { $ _items [ $ key ] = $ items [ $ key ] ; } return $ items ; }
Orders items by weight .
47,307
public function findMultiple ( $ classes = [ ] , $ interfaces = [ ] , $ traits = [ ] ) { $ this -> init ( ) ; $ classes = $ this -> normalizeArray ( $ classes ) ; $ interfaces = $ this -> normalizeArray ( $ interfaces ) ; $ traits = $ this -> normalizeArray ( $ traits ) ; $ foundClasses = [ ] ; if ( $ classes !== false ) { foreach ( $ classes as $ class ) { $ foundClasses = array_merge ( $ foundClasses , $ this -> findExtends ( $ class ) ) ; } } if ( $ interfaces !== false ) { foreach ( $ interfaces as $ interface ) { $ foundClasses = array_merge ( $ foundClasses , $ this -> findImplements ( $ interface ) ) ; } } if ( $ traits !== false ) { foreach ( $ traits as $ trait ) { $ foundClasses = array_merge ( $ foundClasses , $ this -> findTraitUse ( $ trait ) ) ; } } return $ this -> arrayUniqueObject ( $ foundClasses ) ; }
Can find multiple classes at once .
47,308
protected function findImplementsOrTraitUse ( $ fullQualifiedNamespace , $ type ) { $ fullQualifiedNamespace = $ this -> trimNamespace ( $ fullQualifiedNamespace ) ; $ phpClasses = [ ] ; $ method = 'get' . ucfirst ( $ type ) ; foreach ( $ this -> localCache as $ phpClass ) { $ implementsOrTrait = $ phpClass -> $ method ( ) ; if ( is_array ( $ implementsOrTrait ) && in_array ( $ fullQualifiedNamespace , $ implementsOrTrait ) ) { $ phpClasses [ ] = $ phpClass ; $ phpClasses = array_merge ( $ phpClasses , $ this -> findExtends ( $ phpClass -> getFullQualifiedNamespace ( ) ) ) ; } } return $ this -> arrayUniqueObject ( $ phpClasses ) ; }
Can find implements or detect trait use
47,309
protected function arrayUniqueObject ( $ phpClasses ) { $ hashes = [ ] ; foreach ( $ phpClasses as $ key => $ phpClass ) { $ hashes [ $ key ] = spl_object_hash ( $ phpClass ) ; } $ hashes = array_unique ( $ hashes ) ; $ uniqueArray = [ ] ; foreach ( $ hashes as $ key => $ hash ) { $ uniqueArray [ $ key ] = $ phpClasses [ $ key ] ; } return $ uniqueArray ; }
Makes an array of object unique using the spl_object_hash function
47,310
public function getValue ( $ key ) { if ( isset ( $ this -> a [ $ key ] ) ) { return $ this -> a [ $ key ] ; } else { return NULL ; } }
Getter method for a specific value referenced by the given key .
47,311
protected function getMessagesFromSourcePath ( $ path , $ namespace ) { $ messages = [ ] ; if ( ! $ this -> file -> exists ( $ path ) ) { throw new \ Exception ( "${path} doesn't exists!" ) ; } foreach ( $ this -> file -> allFiles ( $ path ) as $ file ) { $ pathName = $ file -> getRelativePathName ( ) ; if ( $ this -> file -> extension ( $ pathName ) !== 'php' ) { continue ; } $ key = substr ( $ pathName , 0 , - 4 ) ; $ key = str_replace ( '\\' , '.' , $ key ) ; $ key = str_replace ( '/' , '.' , $ key ) ; $ array = explode ( '.' , $ key , 2 ) ; $ keyWithNamespace = $ array [ 0 ] . '.' . $ namespace . '::' . $ array [ 1 ] ; $ messages [ $ keyWithNamespace ] = include "${path}/${pathName}" ; } return $ messages ; }
Return language messages for a path .
47,312
protected function prepareTarget ( $ target ) { $ dirname = dirname ( $ target ) ; if ( ! $ this -> file -> exists ( $ dirname ) ) { $ this -> file -> makeDirectory ( $ dirname ) ; } }
Prepare the target directoy .
47,313
public static function redirect ( Url $ url , $ clientId , $ redirectUri = null , $ scope = null , $ state = null ) { $ parameters = $ url -> getParameters ( ) ; $ parameters [ 'response_type' ] = 'code' ; $ parameters [ 'client_id' ] = $ clientId ; if ( isset ( $ redirectUri ) ) { $ parameters [ 'redirect_uri' ] = $ redirectUri ; } if ( isset ( $ scope ) ) { $ parameters [ 'scope' ] = $ scope ; } if ( isset ( $ state ) ) { $ parameters [ 'state' ] = $ state ; } throw new StatusCode \ TemporaryRedirectException ( $ url -> withScheme ( 'https' ) -> withParameters ( $ parameters ) -> toString ( ) ) ; }
Helper method to start the flow by redirecting the user to the authentication server . The getAccessToken method must be used when the server redirects the user back to the redirect uri
47,314
public static function count ( string $ text = '' , bool $ includeSpaces = false ) : int { if ( \ trim ( $ text ) === '' ) { return 0 ; } $ text = StripTags :: strip ( $ text ) ; $ text = \ htmlspecialchars_decode ( ( string ) $ text , ENT_COMPAT | ENT_HTML5 ) ; $ text = \ preg_replace ( '/\s+/' , $ includeSpaces ? ' ' : '' , $ text ) ; $ text = \ trim ( $ text ) ; return \ mb_strlen ( $ text , 'UTF-8' ) ; }
Counts characters . Strips HTML tags . Treats multiple spaces as one .
47,315
public function & SetView ( \ MvcCore \ IView & $ view ) { parent :: SetView ( $ view ) ; return $ this -> SetLangAndLocale ( $ this -> request -> GetLang ( ) , $ this -> request -> GetLocale ( ) ) ; }
Set up view properties and language and locale by request object in every view rendering change .
47,316
public static function Atciq ( $ rc , $ dc , $ pr , $ pd , $ px , $ rv , iauASTROM $ astrom , & $ ri , & $ di ) { $ pco = [ ] ; $ pnat = [ ] ; $ ppr = [ ] ; $ pi = [ ] ; $ w ; IAU :: Pmpx ( $ rc , $ dc , $ pr , $ pd , $ px , $ rv , $ astrom -> pmt , $ astrom -> eb , $ pco ) ; IAU :: Ldsun ( $ pco , $ astrom -> eh , $ astrom -> em , $ pnat ) ; IAU :: Ab ( $ pnat , $ astrom -> v , $ astrom -> em , $ astrom -> bm1 , $ ppr ) ; IAU :: Rxp ( $ astrom -> bpn , $ ppr , $ pi ) ; IAU :: C2s ( $ pi , $ w , $ di ) ; $ ri = IAU :: Anp ( $ w ) ; }
- - - - - - - - - i a u A t c i q - - - - - - - - -
47,317
public static function tag ( $ tag , $ attr = [ ] , $ html = '' ) { $ attributes = [ ] ; foreach ( $ attr as $ name => $ value ) { $ attributes [ ] = $ name . '="' . $ value . '"' ; } if ( in_array ( $ tag , self :: $ voidElements ) ) { return '<' . $ tag . ( ! empty ( $ attributes ) ? ' ' . implode ( ' ' , $ attributes ) : '' ) . '>' ; } else { return '<' . $ tag . ( ! empty ( $ attributes ) ? ' ' . implode ( ' ' , $ attributes ) : '' ) . '>' . $ html . '</' . $ tag . '>' ; } }
Generate the HTML code for an element .
47,318
protected function routeContainsParent ( ) { $ route = parse_url ( $ _SERVER [ 'REQUEST_URI' ] , PHP_URL_PATH ) ; $ parts = explode ( '/' , $ route ) ; $ resourcePosition = array_search ( $ this -> config -> getResource ( ) , $ parts ) ; return isset ( $ parts [ $ resourcePosition - 2 ] ) ; }
Checks if the current route contains the parents id .
47,319
protected function _connection ( array $ config ) { $ redis = new \ Redis ; $ host = empty ( $ config [ 'host' ] ) ? self :: DEFAULT_HOST : $ config [ 'host' ] ; $ port = empty ( $ config [ 'port' ] ) ? self :: DEFAULT_PORT : $ config [ 'port' ] ; $ timeout = empty ( $ config [ 'timeout' ] ) ? self :: DEFAULT_TIMEOUT : $ config [ 'timeout' ] ; $ connect = empty ( $ config [ 'persistent' ] ) ? 'connect' : 'pconnect' ; $ redis -> $ connect ( $ host , $ port , $ timeout ) ; return $ redis ; }
Redis connect and return the redis instance
47,320
protected function _master ( ) { if ( null === $ this -> _master ) { $ this -> _master = $ this -> _connection ( $ this -> _config_master ) ; } return $ this -> _master ; }
Get the master connection
47,321
protected function _slave ( ) { if ( empty ( $ this -> _config_slaves ) ) { return $ this -> _master ( ) ; } if ( null === $ this -> _slave ) { $ count = count ( $ this -> _config_slaves ) ; $ index = mt_rand ( 0 , $ count - 1 ) ; $ config = $ this -> _config_slaves [ $ index ] ; $ this -> _slave = $ this -> _connection ( $ config ) ; } return $ this -> _slave ; }
Get the slave connection
47,322
public function run ( ) { $ this -> init ( ) ; $ requestsHandled = 0 ; while ( $ this -> maxRequests === null || $ requestsHandled < $ this -> maxRequests ) { $ this -> doStep ( ) ; $ requestsHandled ++ ; } }
Starts the adapter and keeps handling requests in a loop . This method never returns and will typically be the last call in an adapter implementation script .
47,323
private function init ( ) { if ( $ this -> encoder === null ) { $ config = new AdapterConfig ( $ this -> codec -> getName ( ) , $ this -> getAdapterType ( ) , $ this -> getExtraConfig ( ) ) ; Codecs :: json ( ) -> newEncoder ( $ this -> output ) -> useNewlines ( false ) -> encode ( $ config ) ; $ this -> decoder = $ this -> codec -> newDecoder ( $ this -> input ) ; $ this -> encoder = $ this -> codec -> newEncoder ( $ this -> output ) ; } }
Prepare this adapter for communication . Will send the adapter configuration to the nervus host and set up an encoder and decoder for further communication .
47,324
protected function generateTraitMethods ( ) { if ( empty ( $ this -> _traitMethodsAliases ) ) { return ; } $ this -> addProperty ( ' classMocker_traitMethods' , $ this -> _traitMethodsAliases , PropertyGenerator :: FLAG_PRIVATE | PropertyGenerator :: FLAG_STATIC ) ; foreach ( array_keys ( $ this -> _traitMethodsAliases ) as $ methodName ) { if ( ! $ this -> canGenerateMethod ( $ methodName ) ) { continue ; } if ( ! $ this -> isValidTraitMethod ( $ methodName ) ) { throw new \ RuntimeException ( sprintf ( "Trait magic method %s::%s() is not valid, use %s() instead" , $ this -> getName ( ) , $ methodName , '_' . $ methodName ) ) ; } $ this -> generateMethod ( $ methodName ) ; } }
Generate foot print of all methods specified by all traits registered to this mock class
47,325
public function canGenerateMethod ( $ methodName ) { switch ( $ methodName ) { case BaseMock :: CALL : case BaseMock :: CONSTRUCTOR : case BaseMock :: GETTER : case BaseMock :: SETTER : case BaseMock :: INIT : return false ; } return true ; }
Check if method can be generated
47,326
public function useTrait ( \ ReflectionClass $ trait ) { $ alias = 'trait' . ( $ this -> _traitsIdx ++ ) ; $ alias .= '_' . str_replace ( '\\' , '__' , $ trait -> getName ( ) ) ; $ alias = 'Trait_' . substr ( md5 ( $ alias ) , 0 , 10 ) . '_' . $ trait -> getShortName ( ) ; $ this -> addUse ( $ trait -> getName ( ) , $ alias ) ; $ this -> addTrait ( $ alias ) ; foreach ( $ trait -> getMethods ( ) as $ method ) { if ( $ method -> isAbstract ( ) ) { continue ; } $ this -> registerTraitMethod ( $ alias , $ method ) ; } return $ this ; }
Use a trait and save all methods so in case a second trait will overwrite any
47,327
protected function registerTraitMethod ( $ trait , \ ReflectionMethod $ method ) { $ name = $ method -> getName ( ) ; $ this -> _method [ $ name ] = $ method ; $ alias = '__' . lcfirst ( $ trait ) . ucfirst ( $ name ) ; $ this -> addTraitAlias ( $ trait . '::' . $ name , $ alias ) ; $ this -> addTraitMethod ( $ trait , $ name ) ; if ( ! isset ( $ this -> _traitMethodsAliases [ $ name ] ) ) { $ this -> _traitMethodsAliases [ $ name ] = [ ] ; } $ this -> _traitMethodsAliases [ $ name ] [ ] = $ alias ; }
Register magic method alias
47,328
protected function addTraitMethod ( $ trait , $ method ) { if ( ! isset ( $ this -> _traitMethods [ $ method ] ) ) { $ this -> _traitMethods [ $ method ] = [ ] ; } else { foreach ( $ this -> _traitMethods [ $ method ] as $ prefTrait ) { $ this -> removeTraitOverride ( $ prefTrait . '::' . $ method ) ; } $ traits = implode ( ', ' , $ this -> _traitMethods [ $ method ] ) ; $ this -> addTraitOverride ( $ trait . '::' . $ method , $ traits ) ; } $ this -> _traitMethods [ $ method ] [ ] = $ trait ; }
Register trait method this will overwrite all previously registered methods
47,329
public function encode ( $ result ) { if ( 'form' == $ this -> type ) { array_walk_recursive ( $ result [ 0 ] , array ( $ this , 'utf8' ) ) ; $ response = new SfResponse ( "<html><body><textarea>" . json_encode ( $ result [ 0 ] ) . "</textarea></body></html>" ) ; $ response -> headers -> set ( 'Content-Type' , 'text/html' ) ; return $ response ; } else { if ( $ this -> responseEncode ) { array_walk_recursive ( $ result , array ( $ this , 'utf8' ) ) ; } $ response = new SfResponse ( json_encode ( $ result ) ) ; $ response -> headers -> set ( 'Content-Type' , 'application/json' ) ; return $ response ; } }
Encode the response into a valid json ExtDirect result .
47,330
private function utf8 ( & $ value , & $ key ) { if ( is_string ( $ value ) ) { $ value = utf8_encode ( $ value ) ; } if ( is_array ( $ value ) ) { array_walk_recursive ( $ value , array ( $ this , 'utf8' ) ) ; } }
Encode the result recursivily as utf8 .
47,331
public function setCompilerRoot ( $ path ) { $ path = realpath ( $ path ) ; if ( is_dir ( $ path ) ) { $ this -> root = $ path ; } }
Set compiler root
47,332
public function addWatcher ( Watcher \ WatcherInterface $ watcher ) { $ type = $ watcher -> getType ( ) ; $ this -> watchers [ $ type ] = $ watcher ; }
Add named watcher instance
47,333
public function addConfig ( $ config , $ watcher ) { if ( ! $ this -> root ) { return ; } $ config = realpath ( $ config ) ; $ filesystem = new Filesystem ( ) ; $ relativePath = $ filesystem -> makePathRelative ( $ config , $ this -> root ) ; if ( substr ( $ relativePath , 0 , 2 ) == ".." ) { return ; } if ( ! isset ( $ this -> configs [ $ watcher ] ) ) { $ this -> configs [ $ watcher ] = array ( ) ; } $ this -> configs [ $ watcher ] [ ] = $ config ; }
Add config path to watch
47,334
public function compile ( ) { if ( ! $ this -> enabled || $ this -> env !== "dev" ) { return ; } foreach ( $ this -> watchers as $ name => $ watcher ) { if ( isset ( $ this -> configs [ $ name ] ) ) { foreach ( $ this -> configs [ $ name ] as $ configPath ) { $ files = $ watcher -> getChildren ( $ configPath ) ; if ( $ this -> cache -> isFresh ( $ configPath , $ files ) ) { $ watcher -> compile ( $ configPath ) ; $ this -> cache -> write ( $ configPath , $ files ) ; } } } } }
Compile watchers files
47,335
protected function getInstaller ( ) : BaseInstaller { return Installer :: create ( $ this -> io , $ this -> composer , $ this -> input ) ; }
Get configured installer instance .
47,336
protected function findBestVersionForPackage ( string $ name ) : string { $ package = $ this -> versionSelector -> findBestCandidate ( $ name , null , null , 'stable' ) ; if ( $ package === false ) { throw new InvalidArgumentException ( \ sprintf ( 'Could not find package %s at any version for your minimum-stability (%s).' . ' Check the package spelling or your minimum-stability.' , $ name , $ this -> stability ) ) ; } return $ this -> versionSelector -> findRecommendedRequireVersion ( $ package ) ; }
Try to find the best version fot the package .
47,337
protected function updateRootComposerJson ( array $ requires , array $ devRequires , int $ type ) : RootPackageInterface { $ this -> io -> writeError ( 'Updating root package' ) ; $ this -> updateRootPackageRequire ( $ requires , $ type ) ; $ this -> updateRootPackageDevRequire ( $ devRequires , $ type ) ; return $ this -> rootPackage ; }
Update the root package require and dev - require .
47,338
protected function updateComposerJson ( array $ requires , array $ devRequires , int $ type ) : void { $ this -> io -> writeError ( 'Updating composer.json' ) ; if ( $ type === self :: ADD ) { $ jsonManipulator = new JsonManipulator ( \ file_get_contents ( $ this -> jsonFile -> getPath ( ) ) ) ; $ sortPackages = $ this -> composer -> getConfig ( ) -> get ( 'sort-packages' ) ?? false ; foreach ( $ requires as $ name => $ version ) { $ jsonManipulator -> addLink ( 'require' , $ name , $ version , $ sortPackages ) ; } foreach ( $ devRequires as $ name => $ version ) { $ jsonManipulator -> addLink ( 'require-dev' , $ name , $ version , $ sortPackages ) ; } \ file_put_contents ( $ this -> jsonFile -> getPath ( ) , $ jsonManipulator -> getContents ( ) ) ; } elseif ( $ type === self :: REMOVE ) { $ jsonFileContent = $ this -> jsonFile -> read ( ) ; foreach ( $ requires as $ packageName => $ version ) { unset ( $ jsonFileContent [ 'require' ] [ $ packageName ] ) ; } foreach ( $ devRequires as $ packageName => $ version ) { unset ( $ jsonFileContent [ 'require-dev' ] [ $ packageName ] ) ; } $ this -> jsonFile -> write ( $ jsonFileContent ) ; } }
Manipulate root composer . json with the new packages and dump it .
47,339
protected function runInstaller ( RootPackageInterface $ rootPackage , array $ whitelistPackages ) : int { $ this -> io -> writeError ( 'Running an update to install dependent packages' ) ; $ this -> composer -> setPackage ( $ rootPackage ) ; $ installer = $ this -> getInstaller ( ) ; $ installer -> setUpdateWhitelist ( $ whitelistPackages ) ; return $ installer -> run ( ) ; }
Install selected packages .
47,340
protected function updateRootPackageRequire ( array $ packages , int $ type ) : void { $ requires = $ this -> manipulateRootPackage ( $ packages , $ type , $ this -> rootPackage -> getRequires ( ) ) ; $ this -> rootPackage -> setRequires ( $ requires ) ; }
Update the root required packages .
47,341
protected function updateRootPackageDevRequire ( array $ packages , int $ type ) : void { $ devRequires = $ this -> manipulateRootPackage ( $ packages , $ type , $ this -> rootPackage -> getDevRequires ( ) ) ; $ this -> rootPackage -> setDevRequires ( $ devRequires ) ; }
Update the root dev - required packages .
47,342
protected function manipulateRootPackage ( array $ packages , int $ type , array $ requires ) : array { if ( $ type === self :: ADD ) { foreach ( $ packages as $ packageName => $ version ) { $ requires [ $ packageName ] = new Link ( '__root__' , $ packageName , ( new VersionParser ( ) ) -> parseConstraints ( $ version ) , 'relates to' , $ version ) ; } } elseif ( $ type === self :: REMOVE ) { foreach ( $ packages as $ packageName => $ version ) { unset ( $ requires [ $ packageName ] ) ; } } return $ requires ; }
Manipulates the given requires with the new added packages .
47,343
public function actionIndex ( ) { $ searchModel = new UserSearch ( ) ; $ dataProvider = $ searchModel -> search ( Yii :: $ app -> request -> queryParams ) ; $ statusArray = User :: getStatusArray ( ) ; $ roleArray = ArrayHelper :: map ( Yii :: $ app -> authManager -> getRoles ( ) , 'name' , 'description' ) ; return $ this -> render ( 'index' , [ 'searchModel' => $ searchModel , 'dataProvider' => $ dataProvider , 'statusArray' => $ statusArray , 'roleArray' => $ roleArray ] ) ; }
Users list page .
47,344
public function actionUpdate ( $ id ) { $ roles = ArrayHelper :: map ( Yii :: $ app -> authManager -> getRoles ( ) , 'name' , 'description' ) ; $ user_permit = array_keys ( Yii :: $ app -> authManager -> getRolesByUser ( $ id ) ) ; $ user = $ this -> findUser ( $ id ) ; return $ this -> render ( 'update' , [ 'user' => $ user , 'roles' => $ roles , 'user_permit' => $ user_permit , 'moduleName' => Yii :: $ app -> controller -> module -> id ] ) ; }
Updates an existing Users model . If update is successful the browser will be redirected to the view page .
47,345
public function actionMassDelete ( ) { if ( ( $ ids = Yii :: $ app -> request -> post ( 'ids' ) ) !== null ) { $ models = $ this -> findUser ( $ ids ) ; foreach ( $ models as $ model ) { $ model -> delete ( $ model ) ; } return $ this -> redirect ( [ 'index' ] ) ; } else { throw new HttpException ( 400 ) ; } }
Delete multiple users page .
47,346
private function findUser ( $ id ) { if ( is_array ( $ id ) ) { $ model = User :: findIdentities ( $ id ) ; } else { $ model = User :: findIdentity ( $ id ) ; } if ( $ model !== null ) { return $ model ; } else { throw new NotFoundHttpException ( 'User not found' ) ; } }
Find User model by ID
47,347
public function getBackLink ( $ fallback = '' ) { $ url = '' ; if ( $ this -> owner -> Request ) { if ( $ this -> owner -> Request -> requestVar ( 'BackURL' ) ) { $ url = $ this -> owner -> Request -> requestVar ( 'BackURL' ) ; } else { if ( $ this -> owner -> Request -> isAjax ( ) && $ this -> owner -> Request -> getHeader ( 'X-Backurl' ) ) { $ url = $ this -> owner -> Request -> getHeader ( 'X-Backurl' ) ; } else { if ( $ this -> owner -> Request -> getHeader ( 'Referer' ) ) { $ url = $ this -> owner -> Request -> getHeader ( 'Referer' ) ; } } } } if ( ! $ url ) { $ url = $ fallback ? $ fallback : singleton ( 'director' ) -> baseURL ( ) ; } return $ url ; }
Find a back link for current controller
47,348
public function displayNiceView ( $ controller = null , $ url = '' , $ action = '' ) { if ( ! $ controller ) { $ controller = $ this -> owner ; } return singleton ( 'director' ) -> create_view ( $ controller , $ url , $ action ) ; }
Display a controller using a Page view
47,349
public function respondToFormAppropriately ( array $ params , $ form = null , $ redirect = '' ) { if ( $ redirect && ! isset ( $ params [ 'redirect' ] ) ) { $ params [ 'redirect' ] = $ redirect ; } if ( $ this -> owner -> Request -> isAjax ( ) ) { if ( ! isset ( $ params [ 'code' ] ) ) { $ params [ 'code' ] = 200 ; } if ( ! isset ( $ params [ 'code' ] ) ) { $ params [ 'status' ] = 'success' ; } return singleton ( 'director' ) -> ajax_response ( $ params , $ params [ 'code' ] , $ params [ 'status' ] ) ; } else { if ( isset ( $ params [ 'redirect' ] ) ) { $ this -> owner -> redirect ( $ params [ 'redirect' ] ) ; } if ( $ form && isset ( $ params [ 'message' ] ) ) { $ form -> sessionMessage ( $ params [ 'message' ] , 'good' ) ; } if ( ! $ this -> owner -> redirectedTo ( ) ) { $ this -> owner -> redirectBack ( ) ; } } }
Respond to a form view ajax or redirect
47,350
protected function _invokeIsset ( $ name ) { if ( ! self :: __isInvokable ( $ name ) ) { return $ this ; } $ is_static = self :: __isStatic ( $ name ) ; $ property = $ this -> findPropertyName ( $ name ) ; return ! empty ( $ property ) ; }
Internal magic checker
47,351
protected function _invokeReset ( $ name ) { if ( ! self :: __isInvokable ( $ name ) ) { return $ this ; } $ is_static = self :: __isStatic ( $ name ) ; $ property = $ this -> findPropertyName ( $ name ) ; if ( ! empty ( $ property ) ) { if ( $ is_static ) { return $ this -> _invokeUnset ( $ name ) ; } else { $ classname = get_class ( $ this ) ; $ reflection = new ReflectionClass ( $ classname ) ; $ properties = $ reflection -> getDefaultProperties ( ) ; if ( ! empty ( $ properties ) && array_key_exists ( $ property , $ properties ) ) { $ this -> { $ property } = $ properties [ $ property ] ; } } } return $ this ; }
Internal magic re - setter
47,352
protected function _invokeGet ( $ name , $ default = null ) { if ( ! self :: __isInvokable ( $ name ) ) { return null ; } $ is_static = self :: __isStatic ( $ name ) ; $ property = $ this -> findPropertyName ( $ name ) ; if ( ! empty ( $ property ) ) { return $ is_static ? @ $ this :: $ { $ property } : @ $ this -> { $ property } ; } return $ default ; }
Internal magic getter
47,353
protected function _invokeSet ( $ name , $ value ) { if ( ! self :: __isInvokable ( $ name ) ) { return $ this ; } $ is_static = self :: __isStatic ( $ name ) ; $ property = $ this -> findPropertyName ( $ name ) ; if ( ! empty ( $ property ) ) { if ( $ is_static ) { $ this :: $ { $ property } = $ value ; } else { $ this -> { $ property } = $ value ; } } return $ this ; }
Internal magic setter
47,354
private function __isInvokable ( $ name ) { if ( ! $ this -> __isCalled ) { $ property = $ this -> findPropertyName ( $ name ) ; if ( ! empty ( $ property ) ) { $ reflection = new ReflectionProperty ( get_class ( $ this ) , $ property ) ; return $ reflection -> isPublic ( ) ; } } return true ; }
Check if a property is invokable in the final object
47,355
private function __isStatic ( $ name ) { $ property = $ this -> findPropertyName ( $ name ) ; if ( ! empty ( $ property ) ) { $ reflection = new ReflectionProperty ( get_class ( $ this ) , $ property ) ; return $ reflection -> isStatic ( ) ; } return true ; }
Check if a property is static in the final object
47,356
private static function __isInvokableStatic ( $ name ) { $ classname = get_called_class ( ) ; $ reflection_class = new ReflectionClass ( $ classname ) ; $ properties = $ reflection_class -> getStaticProperties ( ) ; $ property = self :: findPropertyNameStatic ( $ name , $ classname ) ; if ( ! empty ( $ property ) ) { $ reflection = new ReflectionProperty ( $ classname , $ property ) ; return ( bool ) ! ( $ reflection -> isPrivate ( ) ) ; } return true ; }
Check if a property is statically invokable in the final object
47,357
public static function findPropertyNameStatic ( $ name , $ object ) { $ property = null ; if ( property_exists ( $ object , $ name ) ) { $ property = $ name ; } else { $ underscore_name = '_' . $ name ; if ( property_exists ( $ object , $ underscore_name ) ) { $ property = $ underscore_name ; } else { $ doubleunderscore_name = '__' . $ name ; if ( property_exists ( $ object , $ doubleunderscore_name ) ) { $ property = $ doubleunderscore_name ; } } } return $ property ; }
Search a property name in the current object with one or tow leading underscores
47,358
public function isValid ( $ value , array $ context = null ) { $ this -> setValue ( $ value ) ; $ token = $ this -> getToken ( ) ; if ( ! $ this -> getLiteral ( ) && $ context !== null ) { if ( is_array ( $ token ) ) { while ( is_array ( $ token ) ) { $ key = key ( $ token ) ; if ( ! isset ( $ context [ $ key ] ) ) { break ; } $ context = $ context [ $ key ] ; $ token = $ token [ $ key ] ; } } if ( is_array ( $ token ) || ! isset ( $ context [ $ token ] ) ) { $ token = $ this -> getToken ( ) ; } else { $ token = $ context [ $ token ] ; } } if ( $ token === null ) { $ this -> error ( self :: MISSING_TOKEN ) ; return false ; } $ strict = $ this -> getStrict ( ) ; if ( ! ( $ strict && ( $ value !== $ token ) ) || ( ! $ strict && ( $ value != $ token ) ) ) { $ this -> error ( self :: SAME ) ; return false ; } return true ; }
Returns true if and only if a token has been set and the provided value matches that token .
47,359
public function setEntityClass ( $ className ) { if ( ! class_exists ( $ className ) || ! is_subclass_of ( $ className , EntityInterface :: class ) ) { throw new InvalidEntityClassException ( "Class '{$className}' does not implements the " . "Slick\Orm\EntityInterface interface." ) ; } $ this -> entityClass = $ className ; return $ this ; }
Set FQ entity class name
47,360
public function getEntityClassName ( ) { if ( null == $ this -> entityClass ) { $ this -> setEntityClass ( get_class ( $ this -> getEntity ( ) ) ) ; } return $ this -> entityClass ; }
Get the entity FQ class name
47,361
public function makeFromEnvironment ( ) { $ env = new EnvUtils ( ) ; if ( ! $ env -> hasBearerKey ( ) ) { throw new Exception ( 'TUTUM_AUTH is not set. Unable to create from environment' ) ; } $ client = new Client ( '' , '' ) ; $ client -> setBearerKey ( $ env -> getBearerKey ( ) ) ; return $ client ; }
Build a client using configuration from the environment
47,362
public function executeSQL ( $ key , $ query , $ disable_foreign_key_checks = true , $ entity = null ) { if ( $ entity !== null && $ entity != $ this -> last_entity ) { $ this -> log ( "------------------------------------------------------" ) ; $ this -> log ( "Entity: '$entity'" ) ; $ this -> log ( "------------------------------------------------------" ) ; $ this -> last_entity = $ entity ; } $ this -> log ( " * Sync::executeSQL '$key'..." ) ; $ total_time_start = microtime ( true ) ; if ( $ disable_foreign_key_checks ) { $ this -> adapter -> query ( 'set foreign_key_checks=0' ) ; $ this -> log ( " * FK : Foreign key check disabled" ) ; } try { $ time_start = microtime ( true ) ; $ result = $ this -> adapter -> query ( $ query , ZendDb :: QUERY_MODE_EXECUTE ) ; $ affected_rows = $ result -> getAffectedRows ( ) ; $ time_stop = microtime ( true ) ; $ time = number_format ( ( $ time_stop - $ time_start ) , 2 ) ; $ formatted_query = preg_replace ( '/(\n)|(\r)|(\t)/' , ' ' , $ query ) ; $ formatted_query = preg_replace ( '/(\ )+/' , ' ' , $ formatted_query ) ; $ this -> log ( " * SQL: " . substr ( trim ( $ formatted_query ) , 0 , 70 ) . '...' ) ; $ this -> log ( " * SQL: Query time $time sec(s))" ) ; } catch ( \ Exception $ e ) { $ err = $ e -> getMessage ( ) ; $ msg = "Error running query ({$err}) : \n--------------------\n$query\n------------------\n" ; $ this -> log ( "[+] $msg\n" ) ; if ( $ disable_foreign_key_checks ) { $ this -> log ( "[Error] Error restoring foreign key checks" ) ; $ this -> adapter -> query ( 'set foreign_key_checks=1' ) ; } throw new \ Exception ( $ msg ) ; } if ( $ disable_foreign_key_checks ) { $ time_start = microtime ( true ) ; $ this -> adapter -> query ( 'set foreign_key_checks=1' ) ; $ time_stop = microtime ( true ) ; $ time = number_format ( ( $ time_stop - $ time_start ) , 2 ) ; $ this -> log ( " * FK : Foreign keys restored" ) ; } $ time_stop = microtime ( true ) ; $ time = number_format ( ( $ time_stop - $ total_time_start ) , 2 ) ; $ this -> log ( " * Time: $time secs, affected rows $affected_rows." ) ; }
Execute a query on the database and logs it
47,363
public function applyConfig ( array $ config = [ ] ) { $ parent = $ this ; $ defaults = isset ( $ this -> _config ) ? $ this -> _config : [ ] ; while ( $ parent = get_parent_class ( $ parent ) ) { $ props = get_class_vars ( $ parent ) ; if ( isset ( $ props [ '_config' ] ) ) { $ defaults = Hash :: merge ( $ props [ '_config' ] , $ defaults ) ; } } $ this -> __config = new ConfigAugment ( $ config , $ defaults ) ; return $ this ; }
Merge the custom configuration with the defaults and inherit from parent classes .
47,364
public function setEmail ( $ email ) { $ email = ( string ) $ email ; if ( $ this -> exists ( ) && $ this -> email !== $ email ) { $ this -> updated [ 'email' ] = true ; } $ this -> email = $ email ; return $ this ; }
Set value for field user_email
47,365
public function setPassword ( $ password ) { $ password = ( string ) $ password ; if ( $ this -> exists ( ) && $ this -> password !== $ password ) { $ this -> updated [ 'password' ] = true ; } $ this -> password = $ password ; return $ this ; }
Set value for field user_password
47,366
public function setPseudo ( $ pseudo ) { $ pseudo = ( string ) $ pseudo ; if ( $ this -> exists ( ) && $ this -> pseudo !== $ pseudo ) { $ this -> updated [ 'pseudo' ] = true ; } $ this -> pseudo = $ pseudo ; return $ this ; }
Set value for field user_pseudo
47,367
public function setFirstname ( $ firstname ) { $ firstname = ( $ firstname === null ? $ firstname : ( string ) $ firstname ) ; if ( $ this -> exists ( ) && $ this -> firstname !== $ firstname ) { $ this -> updated [ 'firstname' ] = true ; } $ this -> firstname = $ firstname ; return $ this ; }
Set value for field user_firstname
47,368
public function setLastname ( $ lastname ) { $ lastname = ( $ lastname === null ? $ lastname : ( string ) $ lastname ) ; if ( $ this -> exists ( ) && $ this -> lastname !== $ lastname ) { $ this -> updated [ 'lastname' ] = true ; } $ this -> lastname = $ lastname ; return $ this ; }
Set value for field user_lastname
47,369
public function setDateRegister ( $ dateRegister ) { $ dateRegister = ( $ dateRegister === null ? $ dateRegister : ( string ) $ dateRegister ) ; if ( $ this -> exists ( ) && $ this -> dateRegister !== $ dateRegister ) { $ this -> updated [ 'dateRegister' ] = true ; } $ this -> dateRegister = $ dateRegister ; return $ this ; }
Set value for field user_date_register
47,370
public function setIsActivated ( $ isActivated ) { $ isActivated = ( int ) $ isActivated ; if ( $ this -> exists ( ) && $ this -> isActivated !== $ isActivated ) { $ this -> updated [ 'isActivated' ] = true ; } $ this -> isActivated = $ isActivated ; return $ this ; }
Set value for field user_is_activated
47,371
public function setDateActivation ( $ dateActivation ) { $ dateActivation = ( $ dateActivation === null ? $ dateActivation : ( string ) $ dateActivation ) ; if ( $ this -> exists ( ) && $ this -> dateActivation !== $ dateActivation ) { $ this -> updated [ 'dateActivation' ] = true ; } $ this -> dateActivation = $ dateActivation ; return $ this ; }
Set value for field user_date_activation
47,372
public function setCodeActivation ( $ codeActivation ) { $ codeActivation = ( $ codeActivation === null ? $ codeActivation : ( string ) $ codeActivation ) ; if ( $ this -> exists ( ) && $ this -> codeActivation !== $ codeActivation ) { $ this -> updated [ 'codeActivation' ] = true ; } $ this -> codeActivation = $ codeActivation ; return $ this ; }
Set value for field user_code_activation
47,373
public function setAvatar ( $ avatar ) { $ avatar = ( string ) $ avatar ; if ( $ this -> exists ( ) && $ this -> avatar !== $ avatar ) { $ this -> updated [ 'avatar' ] = true ; } $ this -> avatar = $ avatar ; return $ this ; }
Set value for field user_avatar
47,374
public function getShowById ( $ showId ) { $ response = $ this -> request ( '/GetShowById/' . $ showId ) ; if ( $ response -> response -> status == 'false' ) return null ; $ show = $ response -> response ; $ show = $ this -> formatShow ( $ show ) ; return $ show ; }
Get a show by Bierdopje showId
47,375
public function findShowByName ( $ showName ) { $ response = $ this -> request ( '/FindShowByName/' . $ showName ) ; if ( $ response -> response -> status == 'false' ) return null ; $ shows = $ response -> response -> results -> result ; if ( count ( $ shows ) <= 0 ) return null ; $ show = $ shows [ 0 ] ; $ show = $ this -> formatShow ( $ show ) ; return $ show ; }
Search a show by name
47,376
public function getShowByName ( $ showName , $ isLinkName = false ) { $ response = $ this -> request ( '/GetShowByName/' . $ showName . '/' . $ isLinkName ) ; if ( $ response -> response -> status == 'false' ) return null ; $ show = $ response -> response ; $ show = $ this -> formatShow ( $ show ) ; return $ show ; }
Get a show by exact name .
47,377
public function getShowByTvdbId ( $ tvdbId ) { $ response = $ this -> request ( '/GetShowByTVDBID/' . $ tvdbId ) ; if ( $ response -> response -> status == 'false' ) return null ; $ show = $ this -> formatShow ( $ response -> response ) ; return $ show ; }
Search a show by a TVDB showId
47,378
public function getEpisodesOfSeason ( $ showId , $ season ) { $ response = $ this -> request ( '/GetEpisodesForSeason/' . $ showId . '/' . $ season ) ; if ( $ response -> response -> status == 'false' ) return null ; $ episodes = $ response -> response -> results -> result ; if ( count ( $ episodes ) <= 0 ) return null ; $ episodeList = [ ] ; foreach ( $ episodes as $ episode ) $ episodeList [ ] = $ this -> formatEpisode ( $ episode ) ; return $ episodeList ; }
Search episodes by season and Bierdopje showId
47,379
public function getEpisodeById ( $ episodeId ) { $ response = $ this -> request ( '/GetEpisodeById/' . $ episodeId ) ; if ( $ response -> response -> status == 'false' ) return null ; if ( $ response -> response -> cached == 'false' ) { $ episode = $ response -> response ; } else { $ episode = $ response -> response -> results ; } $ episode = $ this -> formatEpisode ( $ episode ) ; return $ episode ; }
Search an episode by its Bierdopje Id
47,380
private function formatEpisode ( $ original ) { $ show = new \ stdClass ( ) ; $ show -> id = ( int ) $ original -> episodeid ; $ show -> tvdbId = ( int ) $ original -> tvdbid ; $ show -> title = ( string ) $ original -> title ; $ show -> showlink = ( string ) $ original -> showlink ; $ show -> episodelink = ( string ) $ original -> episodelink ; $ show -> airDate = strlen ( $ original -> airdate ) ? Carbon :: createFromFormat ( "d-m-Y" , ( string ) $ original -> airdate ) : null ; $ show -> season = ( int ) $ original -> season ; $ show -> episode = ( int ) $ original -> episode ; $ show -> epNumber = ( int ) $ original -> epnumber ; $ show -> score = ( float ) str_replace ( ',' , '.' , $ original -> score ) ; $ show -> votes = ( int ) $ original -> votes ; $ show -> formatted = ( string ) $ original -> formatted ; $ show -> is_special = ( ( string ) $ original -> is_special ) === "true" ; $ show -> summary = ( string ) $ original -> summary ; $ show -> updated = Carbon :: createFromTimestamp ( ( int ) $ original -> updated ) ; return $ show ; }
Format an Episode response
47,381
private function formatShow ( $ original ) { $ show = new \ stdClass ( ) ; $ show -> id = ( int ) $ original -> showid ; $ show -> tvdbId = ( int ) $ original -> tvdbid ; $ show -> name = ( string ) $ original -> showname ; $ show -> link = ( string ) $ original -> showlink ; $ show -> firstAired = strlen ( $ original -> firstaired ) ? Carbon :: createFromFormat ( 'Y-m-d' , ( string ) $ original -> firstaired ) : null ; $ show -> lastAired = strlen ( $ original -> lastaired ) ? Carbon :: createFromFormat ( 'Y-m-d' , ( string ) $ original -> lastaired ) : null ; $ show -> nextEpisode = strlen ( $ original -> nextepisode ) ? Carbon :: createFromFormat ( 'Y-m-d' , ( string ) $ original -> nextepisode ) : null ; $ show -> seasons = ( int ) $ original -> seasons ; $ show -> episodes = ( int ) $ original -> episodes ; $ show -> genres = $ original -> genres -> result ; $ show -> score = ( float ) str_replace ( ',' , '.' , $ original -> score ) ; $ show -> runtime = ( float ) str_replace ( ',' , '.' , $ original -> runtime ) ; $ show -> favorites = ( int ) $ original -> favorites ; $ show -> showstatus = ( string ) $ original -> showstatus ; $ show -> airtime = ( string ) $ original -> airtime ; $ show -> summary = ( string ) $ original -> summary ; $ show -> updated = Carbon :: createFromTimestamp ( ( int ) $ original -> updated ) ; $ genres = [ ] ; foreach ( $ show -> genres as $ key => $ genre ) { $ genre = ( string ) $ genre ; $ genre = ucfirst ( $ genre ) ; $ genres [ ] = $ genre ; } $ show -> genres = $ genres ; return $ show ; }
Format a Show response
47,382
protected function request ( $ path ) { $ response = $ this -> client -> get ( $ this -> url . $ path ) ; if ( $ response -> getStatusCode ( ) != 200 ) throw new \ Exception ( 'Bierdopje.com not available' ) ; $ response = $ this -> xmlToObj ( $ response -> getBody ( ) ) ; return $ response ; }
Make an HTTP request and format the XML resposne
47,383
private function xmlToObj ( $ fileContents ) { $ fileContents = str_replace ( array ( "\n" , "\r" , "\t" ) , '' , $ fileContents ) ; $ fileContents = trim ( str_replace ( '"' , "'" , $ fileContents ) ) ; $ simpleXml = simplexml_load_string ( $ fileContents , null , LIBXML_NOCDATA ) ; return $ simpleXml ; }
Convert XML string to object
47,384
public static function slice ( $ string , $ start , $ length = null ) { if ( function_exists ( 'mb_substr' ) ) { return mb_substr ( $ string , $ start , $ length , '8bit' ) ; } return substr ( $ string , $ start , $ length ) ; }
Returns the portion of byte string specified by the start and length parameters .
47,385
public static function base64Encode ( $ data , $ url = false ) { if ( $ url ) { return rtrim ( strtr ( base64_encode ( $ data ) , '+/' , '-_' ) , '=' ) ; } else { return base64_encode ( $ data ) ; } }
Encode binary data using base64 .
47,386
public static function base64Decode ( $ data , $ url = true ) { if ( $ url ) { return base64_decode ( strtr ( $ data , '-_' , '+/' ) ) ; } else { return base64_decode ( $ data ) ; } }
Decode base64 encoded string .
47,387
public function generateCode ( $ secret , $ counter , $ algorithm = 'sha512' ) { $ key = $ this -> base32 -> decode ( $ secret ) ; if ( empty ( $ counter ) ) { return '' ; } $ hash = hash_hmac ( $ algorithm , $ this -> getBinaryCounter ( $ counter ) , $ key , true ) ; return str_pad ( $ this -> truncate ( $ hash ) , $ this -> code_length , '0' , STR_PAD_LEFT ) ; }
Generates code based on timestamp and secret
47,388
public function checkTOTP ( $ secret , $ code , $ hash_type = 'sha512' ) { $ time = $ this -> getTimestampCounter ( time ( ) ) ; for ( $ i = - 1 ; $ i <= 1 ; $ i ++ ) { if ( $ this -> stringCompare ( $ code , $ this -> generateCode ( $ secret , $ time + $ i , $ hash_type ) ) === true ) { return true ; } } return false ; }
Check if supplied TOTP code is valid
47,389
public function checkHOTP ( $ secret , $ counter , $ code , $ hash_type = 'sha512' ) { return $ this -> stringCompare ( $ code , $ this -> generateCode ( $ secret , $ counter , $ hash_type ) ) ; }
Check if supplied HOTP code is valid
47,390
protected function truncate ( $ hash ) { $ truncated_hash = 0 ; $ offset = ord ( substr ( $ hash , - 1 ) ) & 0xF ; for ( $ i = 0 ; $ i < 4 ; ++ $ i ) { $ truncated_hash <<= 8 ; $ truncated_hash |= ord ( $ hash [ $ offset + $ i ] ) ; } $ truncated_hash &= 0x7FFFFFFF ; $ truncated_hash %= self :: VERIFICATION_CODE_MODULUS ; return $ truncated_hash ; }
Truncate HMAC hash to binary for generating a TOTP code
47,391
public function stringCompare ( $ string_a , $ string_b ) { $ diff = strlen ( $ string_a ) ^ strlen ( $ string_b ) ; for ( $ i = 0 ; $ i < strlen ( $ string_a ) && $ i < strlen ( $ string_b ) ; $ i ++ ) { $ diff |= ord ( $ string_a [ $ i ] ) ^ ord ( $ string_b [ $ i ] ) ; } return $ diff === 0 ; }
Compare two strings in constant time to prevent timing attacks .
47,392
public function generateSecret ( $ length = 10 ) { $ strong_secret = false ; for ( $ i = 0 ; $ i < 5 ; $ i ++ ) { $ secret = openssl_random_pseudo_bytes ( $ length , $ strong_secret ) ; if ( $ strong_secret === true ) { return $ this -> base32 -> encode ( $ secret ) ; } } return '' ; }
Generate secret with specified length
47,393
public function getIdentifier ( ) { $ identifier = $ this -> getFromNode ( ) -> getIdentifier ( ) . '-' . $ this -> getType ( ) . '-' . $ this -> getToNode ( ) -> getIdentifier ( ) ; return $ identifier ; }
Returns the unique identifier of this node
47,394
public function addSource ( string $ sourceName , ISource $ source ) : Translator { $ source -> setLocale ( $ this -> _locale ) ; $ this -> _sources [ $ sourceName ] = $ source ; return $ this ; }
Adds a source with an associated name .
47,395
public function read ( $ identifier , ? string $ sourceName = null , $ defaultTranslation = false ) { if ( null !== $ sourceName && isset ( $ this -> _sources [ $ sourceName ] ) ) { return $ this -> _sources [ $ sourceName ] -> read ( $ identifier , $ defaultTranslation ) ; } foreach ( $ this -> _sources as $ source ) { $ result = $ source -> read ( $ identifier , static :: USS ) ; if ( static :: USS !== $ result ) { return $ result ; } } return $ defaultTranslation ; }
Reads the translation and return it .
47,396
public static function GetInstance ( ) : Translator { if ( null === self :: $ _instance ) { self :: $ _instance = new Translator ( ) ; } return self :: $ _instance ; }
Gets the global Translator instance . If none is define a empty one is created .
47,397
private function emptyConstruct ( ) { $ this -> getModel ( ) ; $ this -> getTable ( ) ; $ this -> columns ( ) ; $ this -> key ( ) ; $ this -> _state = CRUD :: CREATE_STAT ; }
the empty constructor .
47,398
private function mainConstruct ( $ key = null , $ fail = false ) { $ this -> getModel ( ) ; $ this -> getTable ( ) ; $ this -> columns ( ) ; $ this -> key ( ) ; if ( ! is_null ( $ key ) ) { $ this -> struct ( $ key , $ fail ) ; $ this -> _state = CRUD :: UPDATE_STAT ; } else { $ this -> _state = CRUD :: CREATE_STAT ; } }
the main constructor to search that from database .
47,399
private function secondConstruct ( $ data ) { $ this -> getModel ( $ data ) ; $ this -> getTable ( $ data ) ; $ this -> columns ( $ data ) ; $ this -> key ( $ data ) ; $ this -> fill ( $ data ) ; $ this -> _state = CRUD :: UPDATE_STAT ; }
the second Construct to fil data from array .