idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
3,300
public function make ( $ key ) { switch ( $ key ) { case 'config' : return $ this -> config ; case 'em' : return $ this -> entityManager ; case 'extension' : return $ this -> extensionManager ; case 'migration' : return $ this -> migrationManager ; case 'log' : return $ this -> logger ; case 'file' : return $ this -> files ; default : return $ this ; } }
application s interface maker
3,301
final public function start ( ) { try { $ this -> register ( ) ; $ this -> boot ( ) ; } catch ( HttpValidationException $ exception ) { $ validations = json_decode ( $ exception -> getMessage ( ) , true ) ; response ( $ validations , $ exception -> getCode ( ) ) -> send ( ) ; } catch ( HttpException $ exception ) { response ( [ 'code' => $ exception -> getCode ( ) , 'message' => $ exception -> getMessage ( ) ] , $ exception -> getCode ( ) ) -> send ( ) ; } catch ( \ Exception $ exception ) { app ( 'log' ) -> alert ( 'DOWN' , $ exception -> getTrace ( ) ) ; response ( $ exception -> getMessage ( ) , $ exception -> getCode ( ) ) -> send ( ) ; } catch ( \ Error $ error ) { app ( 'log' ) -> emergency ( 'DOWN' , $ error -> getTrace ( ) ) ; response ( $ error -> getMessage ( ) , 500 ) -> send ( ) ; } return $ this ; }
run all the services
3,302
public function dispatch ( $ event ) { if ( $ event instanceof AbstractEvent ) { $ this -> dispatcher -> dispatch ( $ event -> getEventName ( ) , $ event ) ; } else { $ this -> dispatcher -> dispatch ( $ event ) ; } return $ this ; }
dispatch an event
3,303
public function listen ( $ event , $ handler ) { if ( $ event instanceof AbstractEvent ) { $ event = $ event -> getEventName ( ) ; } $ this -> dispatcher -> addListener ( $ event , $ handler ) ; return $ this ; }
listen an event
3,304
protected function config ( $ host , $ database , $ user , $ password ) { return [ 'host' => $ this -> setLocal ( $ host ? $ host : Config :: get ( 'database.host' ) ) , 'database' => $ database ? $ database : Config :: get ( 'database.database' ) , 'user' => $ user ? $ user : Config :: get ( 'database.username' ) , 'password' => $ password ? $ password : Config :: get ( 'database.password' ) , ] ; }
get Connection configuration .
3,305
public function ConversationQuery ( $ ViewingUserID , $ Join = '' ) { $ this -> SQL -> Select ( 'c.*' ) -> Select ( 'lm.InsertUserID' , '' , 'LastMessageUserID' ) -> Select ( 'lm.DateInserted' , '' , 'DateLastMessage' ) -> Select ( 'lm.Body' , '' , 'LastMessage' ) -> Select ( 'lm.Format' ) -> Select ( 'lmu.Name' , '' , 'LastMessageName' ) -> Select ( 'lmu.Photo' , '' , 'LastMessagePhoto' ) -> From ( 'Conversation c' ) ; if ( $ ViewingUserID !== FALSE ) { $ this -> SQL -> Select ( 'c.CountMessages - uc.CountReadMessages' , '' , 'CountNewMessages' ) -> Select ( 'uc.LastMessageID, uc.CountReadMessages, uc.DateLastViewed, uc.Bookmarked' ) -> Join ( 'UserConversation uc' , "c.ConversationID = uc.ConversationID and uc.UserID = $ViewingUserID" ) -> Join ( 'ConversationMessage lm' , 'uc.LastMessageID = lm.MessageID' ) -> Join ( 'User lmu' , 'lm.InsertUserID = lmu.UserID' ) -> Where ( 'uc.Deleted' , 0 ) ; } else { $ this -> SQL -> Select ( '0' , '' , 'CountNewMessages' ) -> Select ( 'c.CountMessages' , '' , 'CountReadMessages' ) -> Select ( 'lm.DateInserted' , '' , 'DateLastViewed' ) -> Select ( '0' , '' , 'Bookmarked' ) -> Join ( 'ConversationMessage lm' , 'c.LastMessageID = lm.MessageID' ) -> Join ( 'User lmu' , 'lm.InsertUserID = lmu.UserID' ) ; } }
Build generic part of conversation query .
3,306
public function Get ( $ ViewingUserID , $ Offset = '0' , $ Limit = '' ) { if ( $ Limit == '' ) $ Limit = Gdn :: Config ( 'Conversations.Conversations.PerPage' , 30 ) ; $ Offset = ! is_numeric ( $ Offset ) || $ Offset < 0 ? 0 : $ Offset ; $ Data = $ this -> SQL -> Select ( 'c.*' ) -> Select ( 'uc.CountReadMessages' ) -> Select ( 'uc.LastMessageID' , '' , 'UserLastMessageID' ) -> From ( 'UserConversation uc' ) -> Join ( 'Conversation c' , 'uc.ConversationID = c.ConversationID' ) -> Where ( 'uc.UserID' , $ ViewingUserID ) -> Where ( 'uc.Deleted' , 0 ) -> OrderBy ( 'c.DateUpdated' , 'desc' ) -> Limit ( $ Limit , $ Offset ) -> Get ( ) -> ResultArray ( ) ; $ this -> JoinLastMessages ( $ Data ) ; return $ Data ; }
Get list of conversations .
3,307
public function GetCount ( $ ViewingUserID , $ Wheres = '' ) { if ( is_array ( $ Wheres ) ) $ this -> SQL -> Where ( $ Wheres ) ; return $ this -> SQL -> Select ( 'uc.UserID' , 'count' , 'Count' ) -> From ( 'UserConversation uc' ) -> Where ( 'uc.UserID' , $ ViewingUserID ) -> Get ( ) -> Value ( 'Count' , 0 ) ; }
Get number of conversations involving current user .
3,308
public function GetID ( $ ConversationID , $ ViewingUserID = FALSE ) { $ Conversation = $ this -> GetWhere ( array ( 'ConversationID' => $ ConversationID ) ) -> FirstRow ( DATASET_TYPE_ARRAY ) ; if ( $ ViewingUserID ) { $ Data = $ this -> SQL -> GetWhere ( 'UserConversation' , array ( 'ConversationID' => $ ConversationID , 'UserID' => $ ViewingUserID ) ) -> FirstRow ( DATASET_TYPE_ARRAY ) ; $ UserConversation = ArrayTranslate ( $ Data , array ( 'LastMessageID' , 'CountReadMessages' , 'DateLastViewed' , 'Bookmarked' ) ) ; $ UserConversation [ 'CountNewMessages' ] = $ Conversation [ 'CountMessages' ] - $ Data [ 'CountReadMessages' ] ; } else { $ UserConversation = array ( 'CountNewMessages' => 0 , 'CountReadMessages' => $ Conversation [ 'CountMessages' ] , 'DateLastViewed' => $ Conversation [ 'DateUpdated' ] ) ; } $ Conversation = array_merge ( $ Conversation , $ UserConversation ) ; return ( object ) $ Conversation ; }
Get meta data of a single conversation .
3,309
public function GetRecipients ( $ ConversationID , $ IgnoreUserID = '0' ) { $ Data = $ this -> SQL -> Select ( 'uc.*' ) -> From ( 'UserConversation uc' ) -> Where ( 'uc.ConversationID' , $ ConversationID ) -> Get ( ) ; Gdn :: UserModel ( ) -> JoinUsers ( $ Data -> Result ( ) , array ( 'UserID' ) ) ; return $ Data ; }
Get all users involved in conversation .
3,310
public function Clear ( $ ConversationID , $ ClearingUserID ) { $ this -> SQL -> Update ( 'UserConversation' ) -> Set ( 'Deleted' , 1 ) -> Set ( 'DateLastViewed' , Gdn_Format :: ToDateTime ( ) ) -> Where ( 'UserID' , $ ClearingUserID ) -> Where ( 'ConversationID' , $ ConversationID ) -> Put ( ) ; $ this -> CountUnread ( $ ClearingUserID ) ; }
Clear a conversation for a specific user id .
3,311
public function MarkRead ( $ ConversationID , $ ReadingUserID ) { $ this -> SQL -> Update ( 'UserConversation uc' ) -> Join ( 'Conversation c' , 'c.ConversationID = uc.ConversationID' ) -> Set ( 'uc.CountReadMessages' , 'c.CountMessages' , FALSE ) -> Set ( 'uc.DateLastViewed' , Gdn_Format :: ToDateTime ( ) ) -> Set ( 'uc.LastMessageID' , 'c.LastMessageID' , FALSE ) -> Where ( 'c.ConversationID' , $ ConversationID ) -> Where ( 'uc.ConversationID' , $ ConversationID ) -> Where ( 'uc.UserID' , $ ReadingUserID ) -> Put ( ) ; $ CountUnread = $ this -> CountUnread ( $ ReadingUserID ) ; if ( $ ReadingUserID > 0 && $ ReadingUserID == Gdn :: Session ( ) -> UserID ) Gdn :: Session ( ) -> User -> CountUnreadConversations = $ CountUnread ; }
Update a conversation as read for a specific user id .
3,312
public function AddUserToConversation ( $ ConversationID , $ UserID ) { if ( ! is_array ( $ UserID ) ) $ UserID = array ( $ UserID ) ; $ OldContributorData = $ this -> GetRecipients ( $ ConversationID ) ; $ OldContributorData = Gdn_DataSet :: Index ( $ OldContributorData , 'UserID' ) ; $ AddedUserIDs = array ( ) ; $ ConversationData = $ this -> SQL -> Select ( 'LastMessageID' ) -> Select ( 'DateUpdated' ) -> Select ( 'CountMessages' ) -> From ( 'Conversation' ) -> Where ( 'ConversationID' , $ ConversationID ) -> Get ( ) -> FirstRow ( ) ; foreach ( $ UserID as $ NewUserID ) { if ( ! array_key_exists ( $ NewUserID , $ OldContributorData ) ) { $ AddedUserIDs [ ] = $ NewUserID ; $ this -> SQL -> Insert ( 'UserConversation' , array ( 'UserID' => $ NewUserID , 'ConversationID' => $ ConversationID , 'LastMessageID' => $ ConversationData -> LastMessageID , 'CountReadMessages' => 0 , 'DateConversationUpdated' => $ ConversationData -> DateUpdated ) ) ; } elseif ( $ OldContributorData [ $ NewUserID ] -> Deleted ) { $ AddedUserIDs [ ] = $ NewUserID ; $ this -> SQL -> Put ( 'UserConversation' , array ( 'Deleted' => 0 ) , array ( 'ConversationID' => $ ConversationID , 'UserID' => $ NewUserID ) ) ; } } if ( count ( $ AddedUserIDs ) > 0 ) { $ Session = Gdn :: Session ( ) ; $ Contributors = array_unique ( array_merge ( $ AddedUserIDs , array_keys ( $ OldContributorData ) ) ) ; sort ( $ Contributors ) ; $ this -> SQL -> Update ( 'Conversation' ) -> Set ( 'Contributors' , Gdn_Format :: Serialize ( $ Contributors ) ) -> Where ( 'ConversationID' , $ ConversationID ) -> Put ( ) ; $ ActivityModel = new ActivityModel ( ) ; foreach ( $ AddedUserIDs as $ AddedUserID ) { $ ActivityModel -> Queue ( array ( 'ActivityType' => 'AddedToConversation' , 'NotifyUserID' => $ AddedUserID , 'HeadlineFormat' => T ( 'You were added to a conversation.' , '{ActivityUserID,User} added you to a <a href="{Url,htmlencode}">conversation</a>.' ) , 'Route' => '/messages/' . $ ConversationID ) , 'ConversationMessage' ) ; } $ ActivityModel -> SaveQueue ( ) ; $ this -> UpdateUserUnreadCount ( $ AddedUserIDs ) ; } }
Add another user to the conversation .
3,313
public function createUser ( string $ username , string $ email , string $ password ) : bool { $ existing = $ this -> getUser ( - 1 , $ username , $ email ) ; if ( $ existing !== null ) { return false ; } else { $ username = htmlspecialchars ( $ username , ENT_QUOTES , 'UTF-8' ) ; $ email = htmlspecialchars ( $ email , ENT_QUOTES , 'UTF-8' ) ; $ pwHash = password_hash ( $ password , PASSWORD_BCRYPT ) ; $ confirmationToken = bin2hex ( random_bytes ( 64 ) ) ; $ stmt = $ this -> db -> prepare ( "INSERT INTO accounts(" . " username, email, pw_hash, confirmation" . ") " . "VALUES (?, ?, ?, ?);" ) ; $ stmt -> bind_param ( "ssss" , $ username , $ email , $ pwHash , $ confirmationToken ) ; $ stmt -> execute ( ) ; $ this -> db -> commit ( ) ; return true ; } }
Creates a new user provided that user does not already exist or use the same email address or username
3,314
public function getUser ( int $ id , string $ username , string $ email ) : ? User { $ stmt = $ this -> db -> prepare ( "SELECT id, username, email, pw_hash, confirmation " . "FROM accounts " . "WHERE id=? " . "OR username=? " . "OR email=?;" ) ; $ stmt -> bind_param ( "iss" , $ id , $ username , $ email ) ; $ stmt -> execute ( ) ; $ result = $ stmt -> get_result ( ) ; if ( $ result -> num_rows !== 1 ) { return null ; } else { $ values = $ result -> fetch_array ( MYSQLI_ASSOC ) ; return new User ( $ this -> db , ( int ) $ values [ "id" ] , ( string ) $ values [ "username" ] , ( string ) $ values [ "email" ] , ( string ) $ values [ "pw_hash" ] , ( string ) $ values [ "confirmation" ] ) ; } }
Tries to retrieve a user from the database . If the user does not exist this method returns null .
3,315
public function deleteUser ( User $ user , string $ password ) : bool { if ( $ user -> doesPasswordMatch ( $ password ) ) { $ stmt = $ this -> db -> prepare ( "DELETE FROM accounts " . "WHERE id=? AND username=? AND email=?;" ) ; $ stmt -> bind_param ( "iss" , $ user -> id , $ user -> username , $ user -> email ) ; $ stmt -> execute ( ) ; $ this -> db -> commit ( ) ; return true ; } else { return false ; } }
Deletes a user from the database completely
3,316
public function getAllUsers ( ) : array { $ result = $ this -> db -> query ( "SELECT id FROM accounts;" ) ; $ users = [ ] ; foreach ( $ result -> fetch_all ( MYSQLI_ASSOC ) as $ user ) { $ users [ ( int ) $ user [ "id" ] ] = $ this -> getUserFromId ( ( int ) $ user [ "id" ] ) ; } return $ users ; }
Retrieves all users from the database
3,317
public static function singularize ( $ word ) { $ singular = array ( '/(quiz)zes$/i' => '\1' , '/(matr)ices$/i' => '\1ix' , '/(vert|ind)ices$/i' => '\1ex' , '/^(ox)en/i' => '\1' , '/(alias|status)es$/i' => '\1' , '/([octop|vir])i$/i' => '\1us' , '/(cris|ax|test)es$/i' => '\1is' , '/(shoe)s$/i' => '\1' , '/(o)es$/i' => '\1' , '/(bus)es$/i' => '\1' , '/([m|l])ice$/i' => '\1ouse' , '/(x|ch|ss|sh)es$/i' => '\1' , '/(m)ovies$/i' => '\1ovie' , '/(s)eries$/i' => '\1eries' , '/([^aeiouy]|qu)ies$/i' => '\1y' , '/([lr])ves$/i' => '\1f' , '/(tive)s$/i' => '\1' , '/(hive)s$/i' => '\1' , '/([^f])ves$/i' => '\1fe' , '/(^analy)ses$/i' => '\1sis' , '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis' , '/([ti])a$/i' => '\1um' , '/(n)ews$/i' => '\1ews' , '/s$/i' => '' , ) ; $ uncountable = array ( 'equipment' , 'information' , 'rice' , 'money' , 'species' , 'series' , 'fish' , 'sheep' ) ; $ irregular = array ( 'person' => 'people' , 'man' => 'men' , 'child' => 'children' , 'sex' => 'sexes' , 'move' => 'moves' ) ; $ lowercased_word = strtolower ( $ word ) ; foreach ( $ uncountable as $ _uncountable ) { if ( substr ( $ lowercased_word , ( - 1 * strlen ( $ _uncountable ) ) ) == $ _uncountable ) { return $ word ; } } foreach ( $ irregular as $ _plural => $ _singular ) { if ( preg_match ( '/(' . $ _singular . ')$/i' , $ word , $ arr ) ) { return preg_replace ( '/(' . $ _singular . ')$/i' , substr ( $ arr [ 0 ] , 0 , 1 ) . substr ( $ _plural , 1 ) , $ word ) ; } } foreach ( $ singular as $ rule => $ replacement ) { if ( preg_match ( $ rule , $ word ) ) { return preg_replace ( $ rule , $ replacement , $ word ) ; } } return $ word ; }
Singularizes English nouns .
3,318
public function init ( ) { if ( ! empty ( $ this -> registry [ $ this -> section ] ) ) { throw new RegistryException ( RegistryException :: DUPLICATE_INITIATION_ATTEMPT_TEXT . '(section: ' . $ this -> section . ')' , RegistryException :: DUPLICATE_INITIATION_ATTEMPT_CODE ) ; } $ this -> registry [ $ this -> section ] = array ( ) ; }
Initates a registry .
3,319
public function isRegistered ( $ identifier ) { $ this -> verifySectionName ( $ identifier ) ; return array_key_exists ( $ identifier , $ this -> registry [ $ this -> section ] ) ; }
Determines if the given identifier refers to a world .
3,320
public function addVisit ( \ BlackForest \ PiwikBundle \ Entity \ PiwikVisit $ visit ) { $ this -> visit [ ] = $ visit ; return $ this ; }
Add visit .
3,321
public function removeVisit ( \ BlackForest \ PiwikBundle \ Entity \ PiwikVisit $ visit ) { return $ this -> visit -> removeElement ( $ visit ) ; }
Remove visit .
3,322
public function setCountry ( \ BlackForest \ PiwikBundle \ Entity \ PiwikCountry $ country = null ) { $ this -> country = $ country ; return $ this ; }
Set country .
3,323
public static function listFilesRecursive ( $ dirPath , \ Closure $ filter = null ) { $ files = [ ] ; foreach ( new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $ dirPath , FilesystemIterator :: SKIP_DOTS ) , RecursiveIteratorIterator :: CHILD_FIRST ) as $ finfo ) { if ( $ finfo -> isFile ( ) ) { if ( $ filter ) { if ( $ filter ( $ finfo ) ) { $ files [ ] = $ finfo ; } } else { $ files [ ] = $ finfo ; } } } return $ files ; }
Iterates over a tree and takes all files . Files can be filtered with a function that will receive a SplFileInfo object as parameter and must return true for the file to be included in the results . Finally returns an array of SplFileInfo objects .
3,324
public static function listDirsRecusrive ( $ root ) { $ dirs = [ ] ; foreach ( new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $ root , FilesystemIterator :: SKIP_DOTS ) , RecursiveIteratorIterator :: CHILD_FIRST ) as $ path ) { if ( $ path -> isDir ( ) ) { $ dirs [ ] = $ path -> getPathname ( ) ; } } return $ dirs ; }
Lists all directories and subdirectories found in a path .
3,325
public function onPreCreate ( UserEvent $ event ) { $ user = $ event -> getResource ( ) ; if ( 0 === strlen ( $ user -> getPlainPassword ( ) ) ) { $ this -> userManager -> generatePassword ( $ user ) ; $ user -> setEnabled ( true ) ; $ password = $ user -> getPlainPassword ( ) ; $ event -> addMessage ( new ResourceMessage ( sprintf ( 'Generated password : "%s".' , $ password ) , ResourceMessage :: TYPE_INFO ) ) -> addData ( 'password' , $ password ) ; } $ this -> userManager -> updatePassword ( $ user ) ; $ this -> userManager -> updateCanonicalFields ( $ user ) ; }
Pre create resource event handler .
3,326
public function onPostCreate ( UserEvent $ event ) { if ( ! $ event -> hasData ( 'password' ) ) { return ; } $ user = $ event -> getResource ( ) ; if ( ! $ user -> getSendCreationEmail ( ) ) { return ; } if ( 0 < $ this -> mailer -> sendCreationEmailMessage ( $ user , $ event -> getData ( 'password' ) ) ) { $ event -> addMessage ( new ResourceMessage ( 'ekyna_user.user.event.credentials_sent' ) ) ; } }
Post create resource event handler .
3,327
public function onPreUpdate ( UserEvent $ event ) { $ user = $ event -> getResource ( ) ; $ this -> userManager -> updatePassword ( $ user ) ; $ this -> userManager -> updateCanonicalFields ( $ user ) ; }
Pre update resource event handler .
3,328
public function onPostUpdate ( UserEvent $ event ) { if ( ! $ event -> hasData ( 'password' ) ) { return ; } $ user = $ event -> getResource ( ) ; if ( 0 < $ this -> mailer -> sendNewPasswordEmailMessage ( $ user , $ event -> getData ( 'password' ) ) ) { $ event -> addMessage ( new ResourceMessage ( 'ekyna_user.user.event.credentials_sent' ) ) ; } }
Post update resource event handler .
3,329
public function cardDisplayFilter ( CardDecoratedInterface $ object , string $ property ) { $ decorator = $ object -> getCardDecorator ( ) ; $ accessor = PropertyAccess :: createPropertyAccessor ( ) ; if ( ! $ accessor -> isReadable ( $ decorator , $ property ) ) { throw new InvalidCardDecoratorPropertyException ( $ decorator , $ property ) ; } return $ accessor -> getValue ( $ decorator , $ property ) ; }
Filter to get card decorated property
3,330
private function _prepareTables ( array $ tablesArray ) { if ( count ( $ tablesArray ) === 0 ) { throw new \ Exception ( '"table"-method of the statement have to invoked before!' ) ; } $ tables = ' ' ; foreach ( $ tablesArray as $ table ) { $ tables .= $ table -> getExpression ( ) . ', ' ; } $ tables = substr ( $ tables , 0 , strlen ( $ tables ) - 2 ) ; $ this -> tables = $ tables . ' ' ; }
Fill the property tables in a well format for the process method .
3,331
private function _prepareColumns ( array $ columnsArray ) { if ( count ( $ columnsArray ) === 0 ) { throw new \ Exception ( '"column"-method of the statement have to invoked before!' ) ; } $ columns = ' ' ; foreach ( $ columnsArray as $ column ) { $ columns .= $ column -> getExpression ( ) . ', ' ; } $ columns = substr ( $ columns , 0 , strlen ( $ columns ) - 2 ) ; $ this -> columns = $ columns . ' ' ; }
Fill the property columns in a well format for the process method .
3,332
private function _prepareGroupBy ( array $ groupByArray ) { if ( count ( $ groupByArray ) === 1 ) { foreach ( $ groupByArray as $ orderMode => $ column ) { $ this -> groupBy = 'GROUP BY ' . $ column -> getColumnName ( ) . ' ' ; if ( is_string ( $ orderMode ) ) { $ this -> groupBy .= $ orderMode . ' ' ; } } } }
Fill the property groupBy in a well format for the process method .
3,333
private function _prepareJoin ( array $ joinArray ) { if ( count ( $ joinArray ) > 0 ) { $ factory = $ this -> expressionBuilderFactory -> create ( $ joinArray [ 0 ] ) ; foreach ( $ joinArray as $ number => $ join ) { if ( $ number === 0 ) { $ this -> join = $ factory -> build ( ) ; } else { $ this -> join .= $ factory -> rebuild ( $ join ) ; } } } }
Fill the property join in a well format for the process method .
3,334
private function _prepareLimit ( array $ limitArray ) { if ( count ( $ limitArray ) === 1 ) { foreach ( $ limitArray as $ begin => $ amount ) { $ this -> limit = 'LIMIT ' . $ begin . ', ' . $ amount . ' ' ; } } }
Fill the property limit in a well format for the process method .
3,335
private function require_file ( $ path ) { $ path = realpath ( $ path ) ; if ( file_exists ( $ path ) ) { require_once $ path ; $ opcache_enabled = ini_get ( 'opcache.enable' ) ; $ opcache_cli_enabled = ini_get ( 'opcache.enable_cli' ) ; if ( ( php_sapi_name ( ) == 'cli' and $ opcache_cli_enabled ) or ( php_sapi_name ( ) != 'cli' and $ opcache_enabled ) ) { if ( function_exists ( 'opcache_is_script_cached' ) and function_exists ( 'opcache_compile_file' ) ) { if ( ! opcache_is_script_cached ( $ path ) ) { if ( @ opcache_compile_file ( $ path ) === false ) { opcache_invalidate ( $ path , true ) ; } } } } return true ; } else { throw new \ Exception ( 'File not found' ) ; } }
Require a file
3,336
public function add ( BroadcasterInterface $ broadcaster ) { if ( $ this -> has ( $ broadcaster -> getName ( ) ) ) { throw new InvalidArgumentException ( sprintf ( 'Broadcaster with name "%s" already registered.' , $ broadcaster -> getName ( ) ) ) ; } $ this -> broadcasters [ $ broadcaster -> getName ( ) ] = $ broadcaster ; }
Register a broadcaster .
3,337
public function runInstallers ( Event $ event ) { foreach ( $ this -> finder -> getDependentPackages ( $ event -> isDevMode ( ) ) as $ package ) { $ this -> runner -> runInstallers ( $ package , $ event -> isDevMode ( ) ) ; } }
Run the installers
3,338
public function loadConfig ( $ name ) { if ( ! $ this -> configExists ( $ name ) ) $ this -> config [ $ name ] = $ this -> getConfigObjectFromDatabase ( $ name ) ; }
load config use reloadConfig if you want to get the data fresh from the database
3,339
private function reloadConfig ( $ name , $ data = null , $ json = false ) { if ( empty ( $ data ) ) { $ this -> config [ $ name ] = $ this -> getConfigObjectFromDatabase ( $ name ) ; } else { $ this -> config [ $ name ] = $ this -> createConfigObject ( $ name , $ data , $ json ) ; } }
reload config from database
3,340
public function loadConfigsByHook ( $ hook , $ reload = false ) { $ data = $ this -> app -> db -> conn ( ) -> prepare ( 'SELECT * FROM ' . $ this -> app -> db -> getPrefix ( ) . 'config WHERE `config_loadhook` = ?' ) ; $ data -> execute ( array ( $ hook ) ) ; $ data = $ data -> fetchAll ( \ PDO :: FETCH_ASSOC ) ; foreach ( $ data as $ config ) { if ( $ reload || ! $ this -> configExists ( $ config [ 'config_name' ] ) ) { $ this -> config [ $ config [ 'config_name' ] ] = $ this -> createConfigObject ( $ config [ 'config_name' ] , $ config [ 'config_data' ] , true ) ; } } }
load configs by hook
3,341
private function createConfigObject ( $ name , $ data , $ json ) { $ class_name = self :: class . '\\Config' . ucfirst ( strtolower ( $ name ) ) ; if ( ! class_exists ( $ class_name ) ) { $ class_name = self :: class . '\\ConfigData' ; } return new $ class_name ( $ data , $ json ) ; }
create config object
3,342
private function getConfigObjectFromDatabase ( $ name ) { $ config = $ this -> app -> db -> conn ( ) -> prepare ( 'SELECT * FROM ' . $ this -> app -> db -> getPrefix ( ) . 'config WHERE `config_name` = ? LIMIT 1' ) ; $ config -> execute ( array ( $ name ) ) ; $ config = $ config -> fetch ( \ PDO :: FETCH_ASSOC ) ; return $ this -> createConfigObject ( $ config [ 'config_name' ] , $ config [ 'config_data' ] , true ) ; }
create config object from db
3,343
public function configObject ( $ name ) { if ( ! $ this -> configExists ( $ name ) ) { $ this -> reloadConfig ( $ name ) ; } return $ this -> config [ $ name ] ; }
get access on a config object
3,344
private function loadVersion ( ) { $ headers = $ this -> request -> header ( ) ; if ( isset ( $ headers [ 'api-version' ] ) ) { $ rawVersion = array_shift ( $ headers [ 'api-version' ] ) ; $ version = strtolower ( $ rawVersion ) ; if ( is_numeric ( $ version ) ) { $ this -> version = 'v' . $ version ; } else { $ this -> version = $ version ; } } else { $ this -> version = self :: DEFAULT_VERSION ; } if ( ! in_array ( $ this -> version , $ this -> versions ) ) { throw new VersionException ( $ rawVersion . " is an invalid version number." ) ; } }
Resolve the requested api version .
3,345
public function has ( $ event ) { list ( $ event , $ payload ) = $ this -> parseEventAndPayload ( $ event , [ ] ) ; return array_key_exists ( $ event , $ this -> listeners ) ; }
Check if event has listeners .
3,346
protected function getBundleName ( ) { $ pattern = "/(.*)Bundle/" ; $ matches = array ( ) ; preg_match ( $ pattern , $ this -> getRequest ( ) -> get ( '_controller' ) , $ matches ) ; return empty ( $ matches ) ? null : $ matches [ 1 ] ; }
Get the bundle name
3,347
public function each ( \ Closure $ callback ) { foreach ( $ this -> items as $ name => $ properties ) { if ( $ callback ( $ properties , $ name ) === false ) { break ; } } return $ this ; }
Each module items
3,348
public function installed ( $ name ) { if ( ! is_array ( $ name ) ) { $ name = [ $ name ] ; } if ( ! count ( $ name ) ) { return false ; } foreach ( $ name as $ module_name ) { if ( is_numeric ( $ module_name ) ) { if ( ! $ this -> offsetExists ( $ module_name ) ) { return false ; } } else if ( $ this -> getId ( $ module_name ) === false ) { return false ; } } return true ; }
Has module or modules install .
3,349
private static function getHydratorClosure ( $ object ) { if ( ! isset ( self :: $ hydratorClosure ) ) { self :: $ hydratorClosure = function ( $ object , array $ data ) { foreach ( $ data as $ name => $ value ) { $ object -> $ name = $ value ; } } ; } $ class = get_class ( $ object ) ; if ( ! isset ( self :: $ hydratorClosureCache [ $ class ] ) ) { self :: $ hydratorClosureCache [ $ class ] = \ Closure :: bind ( self :: $ hydratorClosure , null , $ class ) ; } return self :: $ hydratorClosureCache [ $ class ] ; }
Returns a closure for hydration
3,350
private static function getExtractorClosure ( $ object ) { if ( ! isset ( self :: $ extractorClosure ) ) { self :: $ extractorClosure = function ( $ object ) { return get_object_vars ( $ object ) ; } ; } $ class = get_class ( $ object ) ; if ( ! isset ( self :: $ extractorClosureCache [ $ class ] ) ) { self :: $ extractorClosureCache [ $ class ] = \ Closure :: bind ( self :: $ extractorClosure , null , $ class ) ; } return self :: $ extractorClosureCache [ $ class ] ; }
Returns a closure for extraction
3,351
public function validate ( $ plugin ) { if ( ! $ plugin instanceof $ this -> instanceOf ) { throw new InvalidServiceException ( sprintf ( '%s expects only to create instances of %s; %s is invalid' , get_class ( $ this ) , $ this -> instanceOf , ( is_object ( $ plugin ) ? get_class ( $ plugin ) : gettype ( $ plugin ) ) ) ) ; } }
Validate an instance
3,352
public function __isset ( $ property ) { switch ( $ property ) { case 'plurals' : case 'pluralExpr' : return $ this -> $ property ; default : if ( isset ( $ this -> messages [ '[Locale::' . $ property . ']' ] ) ) { return true ; } return isset ( self :: $ defaultProperties [ $ property ] ) ; } }
Whether a property exists and has a value .
3,353
public static function convertExpr ( $ expr ) { preg_match_all ( '/(==|!=|<=|>=|&&|\|\||<<|>>|[-!?:+*\/&|^~%<>()n]|[0-9]+)/' , $ expr , $ matches ) ; $ tokens = $ matches [ 0 ] ; $ expr = '' ; $ stack = array ( ) ; foreach ( $ tokens as $ token ) { if ( $ token == 'n' ) { $ expr .= '$n' ; } elseif ( $ token == ':' ) { array_push ( $ stack , ':' ) ; $ expr .= ':(' ; } elseif ( $ token == '(' ) { array_push ( $ stack , '(' ) ; $ expr .= '(' ; } elseif ( $ token == ')' ) { while ( count ( $ stack ) > 0 ) { $ c = array_pop ( $ stack ) ; $ expr .= ')' ; if ( $ c == '(' ) { break ; } } } else { $ expr .= $ token ; } } while ( count ( $ stack ) > 0 ) { array_pop ( $ stack ) ; $ expr .= ')' ; } return $ expr ; }
Converts simple gettext C expressions to PHP .
3,354
public function extend ( Locale $ l ) { $ this -> messages = array_merge ( $ this -> messages , $ l -> messages ) ; }
Extend this localization with additional messages from another one .
3,355
public function set ( $ messageId , $ translation ) { if ( is_array ( $ translation ) ) { $ this -> messages [ $ messageId ] = $ translation ; } else { if ( ! isset ( $ this -> messages [ $ messageId ] ) ) { $ this -> messages [ $ messageId ] = array ( ) ; } $ this -> messages [ $ messageId ] [ ] = $ translation ; } }
Set translation string .
3,356
public function replacePlaceholders ( $ message , $ values = array ( ) ) { $ length = count ( $ values ) ; $ i = 1 ; foreach ( $ values as $ value ) { if ( is_array ( $ value ) ) { $ message = preg_replace_callback ( '/%' . $ i . '\{(.*?)\}\{(.*?)\}/' , function ( $ matches ) use ( $ value ) { $ length = count ( $ value ) ; $ list = '' ; for ( $ i = 0 ; $ i < $ length ; $ i ++ ) { $ list .= $ value [ $ i ] ; if ( $ i != ( $ length - 1 ) ) { if ( $ i == ( $ length - 2 ) ) { $ list .= $ matches [ 2 ] ; } else { $ list .= $ matches [ 1 ] ; } } } return $ list ; } , $ message ) ; } else { $ message = str_replace ( '%' . $ i , $ value , $ message ) ; } $ i ++ ; } return $ message ; }
Replace placeholders in a translation string .
3,357
public static function fromCommand ( CommandInterface $ command ) { $ file = new self ( ) ; $ file -> setParameters ( $ command -> getResponse ( ) -> json ( ) + array ( 'path' => $ command [ 'path' ] ) ) ; $ file -> finishUpload ( ) ; return $ file -> getParameters ( ) ; }
Create a new model instance from a command .
3,358
public function finishUpload ( $ requiredHeaders = array ( ) ) { $ parameters = $ this -> getParameters ( ) ; if ( isset ( $ parameters [ '_requiredHeaders' ] ) ) $ requiredHeaders = $ parameters [ '_requiredHeaders' ] ; $ client = new Client ; $ request = $ client -> put ( $ parameters [ '_uploadURL' ] , $ requiredHeaders , fopen ( $ parameters [ 'path' ] , 'r' ) ) ; $ response = $ request -> send ( ) ; unset ( $ parameters [ 'path' ] ) ; $ this -> setParameters ( $ parameters ) ; }
Perform the file upload operation .
3,359
protected function doRun ( ) { $ config = $ this -> config ; if ( $ this -> target [ 'id' ] != $ this -> head [ 'id' ] ) { $ this -> canMove ( ) ; $ movingNodes = $ this -> getMovingNodes ( ) ; $ movingNodesRange = $ this -> getMovingNodesRange ( ) ; $ shiftingNodes = $ this -> getShiftingNodes ( ) ; $ shiftingNodesRange = $ this -> getShiftingNodesRange ( ) ; $ this -> updateIndexes ( $ movingNodes , self :: INDEX_LFT , $ this -> head [ 'lft' ] , $ this -> head [ 'rgt' ] , $ shiftingNodesRange * - 1 * $ this -> getMoveDirection ( ) ) ; $ this -> updateIndexes ( $ movingNodes , self :: INDEX_RGT , $ this -> head [ 'lft' ] , $ this -> head [ 'rgt' ] , $ shiftingNodesRange * - 1 * $ this -> getMoveDirection ( ) ) ; $ this -> updateDepths ( $ movingNodes , $ this -> getDepthModifier ( ) ) ; $ this -> updateNodeParent ( $ this -> head [ 'id' ] , $ this -> getHeadNodeNewParent ( ) ) ; $ limits = $ this -> getShiftingIndexesLimits ( ) ; $ this -> updateIndexes ( $ shiftingNodes , self :: INDEX_LFT , $ limits [ 'min' ] , $ limits [ 'max' ] , $ movingNodesRange * $ this -> getMoveDirection ( ) ) ; $ this -> updateIndexes ( $ shiftingNodes , self :: INDEX_RGT , $ limits [ 'min' ] , $ limits [ 'max' ] , $ movingNodesRange * $ this -> getMoveDirection ( ) ) ; } }
Run the logic .
3,360
public function get ( ) { if ( null !== $ this -> value ) { return $ this -> value ; } $ key = [ $ this -> getCacheItemPool ( ) -> getPoolName ( ) , $ this -> getKey ( ) ] ; $ key = $ this -> getCacheItemPool ( ) -> getDriver ( ) -> buildKey ( $ key ) ; $ response = $ this -> getCacheItemPool ( ) -> getDriver ( ) -> get ( $ key ) ; if ( false === $ response ) { $ this -> isHit = false ; return null ; } $ this -> value = $ this -> phpUnserialize ( $ response ) ; $ this -> isHit = true ; return $ this -> value ; }
Retrieves the value of the item from the cache associated with this objects key .
3,361
public function exists ( ) { $ key = [ $ this -> getCacheItemPool ( ) -> getPoolName ( ) , $ this -> getKey ( ) ] ; $ key = $ this -> getCacheItemPool ( ) -> getDriver ( ) -> buildKey ( $ key ) ; return $ this -> getCacheItemPool ( ) -> getDriver ( ) -> exists ( $ key ) ; }
Confirms if the cache item exists in the cache .
3,362
public function getExpiration ( ) { if ( $ this -> isHit ( ) && null === $ this -> expiration ) { $ key = [ $ this -> getCacheItemPool ( ) -> getPoolName ( ) , $ this -> getKey ( ) ] ; $ key = $ this -> getCacheItemPool ( ) -> getDriver ( ) -> buildKey ( $ key ) ; $ this -> expiration = $ this -> getCacheItemPool ( ) -> getDriver ( ) -> getExpiration ( $ key ) ; } return $ this -> expiration ; }
Returns the expiration time of a not - yet - expired cache item .
3,363
public function isValidState ( Model $ Model , $ check , $ valid = array ( ) , $ ruleset = array ( ) ) { $ settings = $ this -> settings [ $ Model -> alias ] [ 'fields' ] ; $ field = current ( array_keys ( ( array ) $ check ) ) ; $ value = current ( ( array ) $ check ) ; if ( empty ( $ ruleset ) ) { $ ruleset = $ valid ; $ valid = $ settings [ $ field ] [ 'values' ] ; } return empty ( $ valid ) || in_array ( $ value , ( array ) $ valid ) ; }
Checks if a given value is a valid state .
3,364
public function createNew ( int $ sourceId , string $ name , $ value , $ type = null ) : array { if ( $ type === null ) { $ type = $ this -> typeInfer ( $ value ) ; } return $ this -> sendPost ( sprintf ( '/profiles/%s/features' , $ this -> userName ) , [ ] , [ 'source_id' => $ sourceId , 'name' => $ name , 'value' => $ value , 'type' => $ type ] ) ; }
Creates a new feature for the given user .
3,365
public function upsertOne ( int $ sourceId , string $ name , $ value , $ type = null ) : array { if ( $ type === null ) { $ type = $ this -> typeInfer ( $ value ) ; } return $ this -> sendPut ( sprintf ( '/profiles/%s/features' , $ this -> userName ) , [ ] , [ 'source_id' => $ sourceId , 'name' => $ name , 'value' => $ value , 'type' => $ type ] ) ; }
Tries to update a feature and if it doesnt exists creates a new feature .
3,366
public function updateOne ( int $ featureId , $ value , string $ type ) : array { return $ this -> sendPatch ( sprintf ( '/profiles/%s/features/%s' , $ this -> userName , $ featureId ) , [ ] , [ 'value' => $ value , 'type' => $ type ] ) ; }
Updates a feature given its slug .
3,367
public static function createHash ( $ string ) { $ salt = substr ( str_replace ( '+' , '.' , base64_encode ( pack ( 'N4' , mt_rand ( ) , mt_rand ( ) , mt_rand ( ) , mt_rand ( ) ) ) ) , 0 , 22 ) ; return crypt ( $ string , '$2a$10$' . $ salt . '$' ) ; }
Creates a 60 characters long hash by using the crypt function with the Blowfish algorithm .
3,368
protected function _clearDir ( $ dir ) { $ dirPath = $ this -> Dir -> pwd ( ) . $ dir ; if ( ! $ this -> isExistFolder ( $ dir ) ) { $ this -> err ( "Error : directory {$dir} not exist" ) ; return false ; } if ( ! $ this -> Dir -> delete ( $ dirPath ) ) { $ this -> err ( "Error : delete directory {$dir} failed" ) ; $ this -> verbose ( $ this -> Dir -> errors ( ) ) ; return false ; } if ( ! $ this -> Dir -> create ( $ dirPath , 0777 ) ) { $ this -> err ( "Error : recreate directory {$dir} failed" ) ; $ this -> verbose ( $ this -> Dir -> errors ( ) ) ; return false ; } return true ; }
Clear a dir
3,369
private function apiRequest ( $ options ) { $ params = new \ DerivativeRequest ( $ this -> getRequest ( ) , $ options ) ; $ api = new \ ApiMain ( $ params ) ; $ api -> execute ( ) ; return $ api -> getResult ( ) -> getResultData ( ) ; }
Send a request to the MediaWiki API .
3,370
private function getTextFromArticle ( $ title ) { $ title = \ Title :: newFromText ( $ title ) ; $ revision = \ Revision :: newFromId ( $ title -> getLatestRevID ( ) ) ; if ( isset ( $ revision ) ) { return \ ContentHandler :: getContentText ( $ revision -> getContent ( \ Revision :: RAW ) ) ; } else { return ; } }
Extract text content from an article .
3,371
public static function getCategoryTree ( \ Title $ title ) { global $ wgCountryCategory ; if ( $ title -> getNamespace ( ) == NS_ADDRESS_NEWS ) { $ title = \ Title :: newFromText ( $ title -> getText ( ) , NS_ADDRESS ) ; } $ parenttree = $ title -> getParentCategoryTree ( ) ; CategoryBreadcrumb :: checkParentCategory ( $ parenttree ) ; CategoryBreadcrumb :: checkTree ( $ parenttree ) ; $ flatTree = CategoryBreadcrumb :: getFlatTree ( $ parenttree ) ; $ return = '' ; $ categories = array_reverse ( $ flatTree ) ; if ( isset ( $ categories [ 0 ] ) ) { $ catTitle = \ Title :: newFromText ( $ categories [ 0 ] ) ; $ return .= \ Linker :: link ( $ catTitle , htmlspecialchars ( $ catTitle -> getText ( ) ) ) ; if ( isset ( $ categories [ 1 ] ) ) { $ catTitle = \ Title :: newFromText ( $ categories [ 1 ] ) ; $ return .= ' > ' . \ Linker :: link ( $ catTitle , htmlspecialchars ( $ catTitle -> getText ( ) ) ) ; } } return $ return ; }
Get a category tree from an article .
3,372
public function execute ( $ subPage ) { global $ wgCountryCategory , $ wgTitle ; $ article = new \ Article ( $ wgTitle ) ; $ this -> languageCode = $ article -> getContext ( ) -> getLanguage ( ) -> getCode ( ) ; $ output = $ this -> getOutput ( ) ; $ this -> setHeaders ( ) ; $ this -> outputFocus ( ) ; $ this -> outputSearch ( ) ; $ output -> addHTML ( '<div class="association-block" data-equalizer data-equalize-on="medium">' ) ; $ this -> outputAbout ( ) ; $ this -> outputNews ( ) ; $ output -> addHTML ( '</div>' ) ; $ output -> addHTML ( '<div class="latest-block">' ) ; $ this -> outputRecentChanges ( ) ; $ this -> outputRecentComments ( ) ; $ output -> addHTML ( '</div>' ) ; }
Display the special page .
3,373
public static function rehydrate ( $ serialised , ExecHelper $ execHelper , LoggerInterface $ logger = null ) { $ view = unserialize ( $ serialised ) ; $ view -> setExec ( $ execHelper ) ; $ view -> handleDependencyInjection ( ) ; $ view -> setLogger ( $ logger ) ; $ view -> log ( "Rehydrated" , LogLevel :: DEBUG ) ; return $ view ; }
Use this to unserialise ViewComponents
3,374
protected function getRootComponent ( ) { $ cur = $ this ; while ( $ cur -> parent !== null ) { $ cur = $ cur -> parent ; } return $ cur ; }
Get the root component of the hierarchy
3,375
protected function getPath ( ) { if ( null === $ this -> parent ) { return null ; } if ( null !== ( $ pPath = $ this -> parent -> getPath ( ) ) ) { return $ pPath . '.' . $ this -> handle ; } else { return $ this -> handle ; } }
Return the this object s path in the current component hierarchy
3,376
protected function addOrUpdateChild ( $ handle , $ type , array $ props = [ ] ) { $ this -> log ( "Adding/updating child '{$handle}' of type {$type}" , LogLevel :: DEBUG ) ; if ( ! isset ( $ this -> childComponents [ $ handle ] ) ) { if ( ! class_exists ( $ type ) ) { throw new \ Exception ( "Class '{$type}' for sub-component does not exist." ) ; } $ child = new $ type ( $ handle , $ this , $ this -> exec , $ this -> logger ) ; $ this -> childComponents [ $ handle ] = $ child ; } else { $ child = $ this -> childComponents [ $ handle ] ; } $ child -> updateProps ( $ props ) ; $ child -> updateState ( ) ; }
Can create a child component on this component and return it .
3,377
public function renderChild ( $ handle ) { if ( ! $ this -> childComponents [ $ handle ] ) { $ message = "Attempted to render nonexistent child component with handle '{$handle}'" ; $ this -> log ( $ message , LogLevel :: CRITICAL ) ; throw new \ Exception ( $ message ) ; } return $ this -> childComponents [ $ handle ] -> render ( ) -> content ; }
Render a child component .
3,378
public function buildAcl ( ) { if ( $ this -> builded ) { return $ this ; } $ config = $ this -> getConfig ( ) ; $ this -> buildCommonRoles ( ) -> deny ( self :: ROLE_PUBLIC ) ; foreach ( $ config [ 'controller' ] as $ controller => $ roles ) { $ this -> addResource ( $ controller ) ; $ this -> allows ( $ roles , $ controller ) ; } foreach ( $ config [ 'action' ] as $ controller => $ actions ) { foreach ( $ actions as $ action => $ roles ) { $ resource = $ this -> buildResource ( $ controller , $ action ) ; if ( ! $ roles ) { $ this -> addResource ( $ resource , $ controller ) ; } else { $ this -> addResource ( $ resource ) ; } $ this -> allows ( $ roles , $ resource ) ; } } foreach ( $ config [ 'admin' ] as $ admin ) { if ( ! $ this -> hasRole ( $ admin ) ) { $ this -> addRole ( $ admin , [ self :: ROLE_ADMIN , self :: ROLE_LOGGED , self :: ROLE_PUBLIC ] ) ; } $ this -> allow ( $ admin ) ; } $ this -> builded = true ; return $ this ; }
Build acl if needed
3,379
public function isAllowed ( $ role = null , $ resource = null , $ privilege = null ) { $ this -> buildAcl ( ) ; return ( bool ) parent :: isAllowed ( $ role , $ resource , $ privilege ) ; }
Returns true if and only if the Role has access to the Resource
3,380
public function hasResourceParams ( $ controller , $ action = null ) { $ this -> buildAcl ( ) ; $ resource = $ this -> buildResource ( $ controller , $ action ) ; return parent :: hasResource ( $ resource ) ; }
Does the resource exists?
3,381
public function hasErrors ( $ attribute = null ) : bool { $ errors = $ this -> getErrors ( ) ; return $ attribute === null ? ! empty ( $ errors ) : isset ( $ errors [ $ attribute ] ) ; }
Identify whether there are any errors
3,382
public function getErrors ( $ attribute = null ) : array { if ( $ attribute === null ) { return $ this -> errors === null ? [ ] : $ this -> errors ; } else { return isset ( $ this -> errors [ $ attribute ] ) ? $ this -> errors [ $ attribute ] : [ ] ; } }
Returns the errors for all attribute or a single attribute .
3,383
public function getFirstError ( $ attribute ) { $ errors = $ this -> getErrors ( ) ; return isset ( $ errors [ $ attribute ] ) ? reset ( $ errors [ $ attribute ] ) : null ; }
Returns the first error of the specified attribute .
3,384
public function clearErrors ( $ attribute = null ) { if ( $ attribute === null ) { $ this -> errors = [ ] ; } else { unset ( $ this -> errors [ $ attribute ] ) ; } }
Removes errors for all attributes or a single attribute .
3,385
public function hasExecutableActivities ( Campaign $ campaign ) { $ activities = $ this -> em -> getRepository ( 'CampaignChainCoreBundle:Activity' ) -> findBy ( array ( 'campaign' => $ campaign , 'mustValidate' => true ) ) ; if ( count ( $ activities ) ) { foreach ( $ activities as $ activity ) { $ isExecutable = $ this -> activityService -> isExecutableByCampaign ( $ activity ) ; if ( ! $ isExecutable [ 'status' ] ) { return $ isExecutable ; } } } return array ( 'status' => true , ) ; }
Checks whether the Activities belonging to a Campaign and marked with mustValidate are executable .
3,386
public static function sanitizeIDs ( $ ids ) { if ( ! is_array ( $ ids ) ) { $ return_string = true ; $ ids = explode ( ',' , $ ids ) ; } if ( ! Arr :: iterable ( $ ids ) ) { return false ; } $ ids = array_map ( 'trim' , $ ids ) ; $ ids = array_filter ( $ ids , 'strlen' ) ; $ ids = array_map ( 'intval' , $ ids ) ; $ ids = array_map ( 'abs' , $ ids ) ; return ( $ return_string ) ? join ( ',' , $ ids ) : $ ids ; }
Sanitize a list of numeric IDs and return the same format
3,387
public function parse ( $ string ) { $ hashModes = [ ] ; foreach ( $ this -> hashLibrary as $ hash ) { if ( preg_match ( '/' . $ hash [ 'regex' ] . '/i' , $ string ) ) { foreach ( $ hash [ 'modes' ] as $ mode ) { $ hashModes [ ] = new HashMode ( [ 'name' => $ mode [ 'name' ] , 'hashcat' => $ mode [ 'hashcat' ] , 'john' => $ mode [ 'john' ] , 'extended' => $ mode [ 'extended' ] , ] ) ; } } } $ this -> modes = $ hashModes ; return $ this ; }
Parse the string
3,388
public function activate ( Puli $ puli ) { $ this -> puli = $ puli ; $ puli -> getEventDispatcher ( ) -> addListener ( ConsoleEvents :: CONFIG , array ( $ this , 'handleConfigEvent' ) ) ; $ puli -> getEventDispatcher ( ) -> addListener ( PuliEvents :: GENERATE_FACTORY , array ( $ this , 'handleGenerateFactoryEvent' ) ) ; }
Activates the plugin .
3,389
public function getInstallTargetManager ( ) { if ( ! $ this -> installTargetManager ) { $ this -> installTargetManager = new PackageFileInstallTargetManager ( $ this -> getPuli ( ) -> getRootPackageFileManager ( ) , $ this -> getInstallerManager ( ) ) ; } return $ this -> installTargetManager ; }
Returns the install target manager .
3,390
public static function boot ( ICms $ cms ) { $ cms -> getLang ( ) -> addResourceDirectory ( 'package.analytics' , __DIR__ . '/../resources/lang/' ) ; $ cms -> getIocContainer ( ) -> bind ( IIocContainer :: SCOPE_SINGLETON , IAnalyticsDriverConfigRepository :: class , DbAnalyticsDriverConfigRepository :: class ) ; }
Boots the package
3,391
public static function cleanForOrder ( string $ str ) : string { $ str = self :: removeAccents ( $ str ) ; $ str = preg_replace ( "/^[^a-z0-9 ]/i" , "" , $ str ) ; $ str = trim ( $ str ) ; return $ str ; }
Clean for usort callback
3,392
public static function cleanTextarea ( $ str ) { $ str = str_replace ( '&nbsp;' , ' ' , $ str ) ; $ str = preg_replace ( "/[\r\n]{2,}/" , "\n\n" , $ str ) ; $ str = preg_replace ( "/<br([^>]*)>/" , "\n" , $ str ) ; if ( ! preg_match ( "/<(p|table|figure|div|h[1-6])>.+<\/$1>/" , $ str ) ) { $ str = '<p>' . $ str . '</p>' ; } $ str = preg_replace ( "/\n\n/" , "</p> <p>" , $ str ) ; $ str = trim ( $ str ) ; $ str = preg_replace ( "/<p>\s*<\/p>/" , "" , $ str ) ; $ str = preg_replace ( "/\n/" , "<br />" , $ str ) ; $ str = trim ( $ str ) ; return $ str ; }
Clean textarea field content
3,393
public static function toCamelCase ( $ str ) { $ str = self :: toSpaceSeparated ( $ str ) ; $ str = ucwords ( $ str ) ; $ str = str_ireplace ( ' ' , '' , $ str ) ; return $ str ; }
Convert a string into camel case .
3,394
public static function toVariable ( $ str ) { $ str = self :: toSpaceSeparated ( $ str ) ; $ str = self :: toCamelCase ( $ str ) ; $ str = preg_replace ( '#^[0-9]+.*$#' , '' , $ str ) ; $ first = substr ( $ str , 0 , 1 ) ; $ first = mb_strtolower ( $ first ) ; $ str = substr_replace ( $ str , $ first , 0 , 1 ) ; return $ str ; }
Convert a string into variable form .
3,395
public static function toKey ( $ str ) { $ str = self :: toUnderscoreSeparated ( $ str ) ; $ str = mb_strtolower ( $ str ) ; return $ str ; }
Convert a string into key form .
3,396
public static function toRoman ( $ num ) { $ num = ( int ) $ num ; switch ( $ num ) { case 1 : $ roman = 'I' ; break ; case 2 : $ roman = 'II' ; break ; case 3 : $ roman = 'III' ; break ; case 4 : $ roman = 'IV' ; break ; case 5 : $ roman = 'V' ; break ; case 6 : $ roman = 'VI' ; break ; case 7 : $ roman = 'VII' ; break ; case 8 : $ roman = 'VIII' ; break ; case 9 : $ roman = 'IX' ; break ; case 10 : $ roman = 'X' ; break ; default : $ roman = ( string ) $ num ; break ; } return $ roman ; }
Convertt number to Roman
3,397
private function createView ( $ view , $ viewFile , $ type , $ moduleDir ) { $ template = file_get_contents ( __DIR__ . DIRECTORY_SEPARATOR . "templates" . DIRECTORY_SEPARATOR . "view_" . $ type . ".tpl" ) ; $ template = str_replace ( '$VIEW' , $ view , $ template ) ; file_put_contents ( $ viewFile , $ template ) ; }
Cria o template da view .
3,398
public function setWsdl ( $ wsdl ) { if ( ! is_string ( $ wsdl ) || strlen ( trim ( $ wsdl ) ) == 0 ) throw new InvalidArgumentException ( __METHOD__ . '; Invalid wsdl given, must be a non empty string' ) ; $ this -> wsdl = $ wsdl ; }
Set the WSDL of this Client
3,399
protected function getSoapClient ( ) { if ( ! isset ( $ this -> wsdl ) ) throw new Exception ( __METHOD__ . '; No WSDL set' ) ; if ( ! ( is_null ( $ this -> client ) && $ this -> client instanceof SoapClient ) ) $ this -> client = new SoapClient ( $ this -> wsdl ) ; return $ this -> client ; }
Get instance of SoapClient for this Client