idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
43,400
protected function getCurrentPathRelativeToBase ( $ path = null ) { if ( ! $ path ) { $ path = $ _SERVER [ 'REQUEST_URI' ] ; } $ base_path = $ this -> app [ 'request' ] -> getBasePath ( ) ; return substr ( strtok ( $ path , '?' ) , strlen ( $ base_path ) ) ; }
Get current path relative to base path .
43,401
public function debugDumpParams ( ) { if ( ! is_resource ( $ this -> resource ) ) { throw new LikePDOException ( "There is no active statement" ) ; return false ; } else { $ parameters = array ( ) ; if ( count ( $ this -> parametersBound ) > 0 ) { foreach ( $ this -> parametersBound as $ key => $ param ) { if ( ! isset ( $ this -> parameters [ $ key ] ) ) { $ parameters [ ] = array ( "key" => is_string ( $ key ) == true ? "Name: [" . strlen ( $ key ) . "] " . $ key : "Position #" . $ key , "paramno" => is_string ( $ key ) == true ? - 1 : $ key , "name" => is_string ( $ key ) == true ? "[" . strlen ( $ key ) . "] \"" . $ key . "\"" : "[0] \"\"" , "is_param" => 1 , "param_type" => $ param [ 'data_type' ] ) ; } } } if ( count ( $ this -> parameters ) > 0 ) { foreach ( $ this -> parameters as $ key => $ param ) { if ( ! isset ( $ this -> parametersBound [ $ key ] ) ) { $ parameters [ ] = array ( "key" => is_string ( $ key ) == true ? "Name: [" . strlen ( $ key ) . "] " . $ key : "Position #" . $ key . ":" , "paramno" => is_string ( $ key ) == true ? - 1 : $ key , "name" => is_string ( $ key ) == true ? "[" . strlen ( $ key ) . "] \"" . $ key . "\"" : "[0] \"\"" , "is_param" => 1 , "param_type" => $ param [ 'data_type' ] ) ; } } } printf ( "SQL: [%d] %s" . PHP_EOL . "Params: %d" . PHP_EOL . PHP_EOL , strlen ( $ this -> queryString ) , $ this -> queryString , count ( $ parameters ) ) ; if ( count ( $ parameters ) > 0 ) { foreach ( $ parameters as $ param ) { printf ( "Key: %s" . PHP_EOL , $ param [ 'key' ] ) ; printf ( "paramno=%d" . PHP_EOL , $ param [ 'paramno' ] ) ; printf ( "name=%s" . PHP_EOL , $ param [ 'name' ] ) ; printf ( "is_param=%d" . PHP_EOL , $ param [ 'is_param' ] ) ; printf ( "param_type=%d" . PHP_EOL , $ param [ 'param_type' ] ) ; } } return true ; } }
Dump an SQL prepared command
43,402
public function nextRowset ( ) { if ( ! is_resource ( $ this -> resource ) ) { throw new LikePDOException ( "There is no active statement" ) ; return false ; } else { return $ this -> pdo -> driver -> nextResult ( $ this -> resource ) ; } }
Advances to the next rowset in a multi - rowset statement handle
43,403
public function getFilters ( ) { $ filters = [ ] ; $ names = explode ( '_' , $ this -> name ) ; $ base = '' ; $ filters = [ ] ; while ( $ name = array_shift ( $ names ) ) { $ filter = $ this -> _searchInControllerDir ( $ base , 'filter.yml' ) ; if ( $ filter ) $ filters [ ] = $ filter ; if ( count ( $ names ) > 0 ) { $ base = $ base . DS . ucfirst ( $ name ) ; } else { $ filter = $ this -> _searchInControllerDir ( $ base , "{$name}.filter.yml" ) ; if ( $ filter ) $ filters [ ] = $ filter ; } } return $ filters ; }
Get filter paths
43,404
public function getFilterKey ( $ action = null ) { $ controller = $ this -> getName ( ) ; return $ action ? $ controller . '.' . $ action : $ controller ; }
Get filter key
43,405
public function task ( $ name , array $ options = [ ] ) { $ this -> taskProcessor -> setOutput ( $ this ) ; $ this -> taskProcessor -> execute ( $ name , $ options ) ; }
get a task .
43,406
private function _searchInControllerDir ( $ base_dir , $ file_name ) { $ dirs = $ this -> application -> getControllerDirectories ( ) ; foreach ( $ dirs as $ dir ) { $ filter = $ this -> finder -> path ( $ dir . $ base_dir ) -> name ( $ file_name ) -> find ( ) -> first ( ) ; if ( $ filter ) return $ filter ; } }
search in controller dirs
43,407
private function addPHPFiles ( Phar $ phar ) { $ finder = new Finder ( ) ; $ finder -> files ( ) -> ignoreVCS ( true ) -> name ( '*.php' ) -> notName ( 'Compiler.php' ) -> in ( realpath ( __DIR__ . '/../../src' ) ) ; foreach ( $ finder as $ file ) { $ this -> addFile ( $ phar , $ file ) ; } return $ this ; }
Add php files
43,408
private function addVendorFiles ( Phar $ phar ) { $ vendorPath = __DIR__ . '/../../vendor/' ; $ requiredDependencies = [ realpath ( $ vendorPath . 'symfony/' ) , realpath ( $ vendorPath . 'doctrine/' ) , realpath ( $ vendorPath . 'guzzlehttp' ) , realpath ( $ vendorPath . 'psr' ) , ] ; $ finder = new Finder ( ) ; $ finder -> files ( ) -> ignoreVCS ( true ) -> name ( '*.php' ) -> exclude ( [ 'Tests' , 'tests' ] ) -> in ( $ requiredDependencies ) ; foreach ( $ finder as $ file ) { $ this -> addFile ( $ phar , $ file ) ; } return $ this ; }
Add vendor files
43,409
private function addComposerVendorFiles ( Phar $ phar ) { $ vendorPath = __DIR__ . '/../../vendor/' ; $ this -> addFile ( $ phar , new \ SplFileInfo ( $ vendorPath . 'autoload.php' ) ) -> addFile ( $ phar , new \ SplFileInfo ( $ vendorPath . 'composer/autoload_namespaces.php' ) ) -> addFile ( $ phar , new \ SplFileInfo ( $ vendorPath . 'composer/autoload_psr4.php' ) ) -> addFile ( $ phar , new \ SplFileInfo ( $ vendorPath . 'composer/autoload_classmap.php' ) ) -> addFile ( $ phar , new \ SplFileInfo ( $ vendorPath . 'composer/autoload_real.php' ) ) -> addFile ( $ phar , new \ SplFileInfo ( $ vendorPath . 'composer/autoload_static.php' ) ) -> addFile ( $ phar , new \ SplFileInfo ( $ vendorPath . 'composer/ClassLoader.php' ) ) ; return $ this ; }
Add composer vendor files
43,410
public static function Ee00a ( $ date1 , $ date2 ) { $ dpsipr ; $ depspr ; $ epsa ; $ dpsi ; $ deps ; $ ee ; IAU :: Pr00 ( $ date1 , $ date2 , $ dpsipr , $ depspr ) ; $ epsa = IAU :: Obl80 ( $ date1 , $ date2 ) + $ depspr ; IAU :: Nut00a ( $ date1 , $ date2 , $ dpsi , $ deps ) ; $ ee = IAU :: Ee00 ( $ date1 , $ date2 , $ epsa , $ dpsi ) ; return $ ee ; }
- - - - - - - - - i a u E e 0 0 a - - - - - - - - -
43,411
public static function assumeSocket ( $ address , $ port = 0 ) : void { $ socket = @ socket_create ( AF_INET , SOCK_STREAM , SOL_TCP ) ; assumeThat ( $ socket , is ( not ( false ) ) , self :: $ SOCK_ERR_MSG . socket_last_error ( $ socket ) ) ; assumeThat ( @ socket_connect ( $ socket , $ address , $ port ) , is ( not ( false ) ) , 'Unable to connect: ' . $ address . ':' . $ port ) ; }
Assumes that a specified socket connection could be established .
43,412
public static function normalize ( $ pointer , array $ context = null ) { if ( is_object ( $ pointer ) ) { return [ 'value' => $ pointer ] ; } if ( is_string ( $ pointer ) ) { return [ 'classname' => $ pointer ] ; } if ( $ pointer === null ) { return [ ] ; } if ( $ pointer === false ) { throw new Disabled ( '' ) ; } if ( ! is_array ( $ pointer ) ) { throw new InvalidPointer ( 'invalid pointer type' ) ; } if ( ! isset ( $ pointer [ 0 ] ) ) { return $ pointer ; } return self :: normalizeNumeric ( $ pointer , $ context ) ; }
Normalizes the pointer format
43,413
public function unsubscribe ( $ token ) { if ( ! $ this -> model -> isTokenValid ( $ token ) ) { return view ( 'lasallecrmlistmanagement::subscribe-unsubscribe-list.token_invalid' , [ 'title' => 'Invalid Unsubscribe Token' , ] ) ; } $ emailID = $ this -> model -> getEmailIdByToken ( $ token ) ; $ listID = $ this -> model -> getListIdByToken ( $ token ) ; $ email = $ this -> emailRepository -> getEmailByEmailId ( $ emailID ) ; $ listName = $ this -> listRepository -> getListnameByListId ( $ listID ) ; $ this -> model -> deleteAllTokensForListIDandEmailID ( $ listID , $ emailID ) ; $ this -> list_EmailRepository -> enabledFalse ( $ emailID , $ listID ) ; return view ( 'lasallecrmlistmanagement::subscribe-unsubscribe-list.unsubscribe_success' , [ 'title' => 'Unsubscribe Successful' , 'email' => $ email , 'listName' => $ listName ] ) ; }
Unsubscribe from a LaSalleCRM email list
43,414
public function get ( $ configurationIdentifier , $ defaultValue = null ) { if ( ! array_key_exists ( $ configurationIdentifier , $ this -> configurationElements ) ) { if ( ! is_null ( $ defaultValue ) ) { return $ defaultValue ; } throw new ConfigurationParameterNotFoundException ( ) ; } $ valueIsCached = $ this -> cache -> contains ( $ configurationIdentifier ) ; if ( false !== $ valueIsCached ) { return $ this -> cache -> fetch ( $ configurationIdentifier ) ; } list ( $ configurationNamespace , $ configurationKey ) = $ this -> splitConfigurationKey ( $ configurationIdentifier ) ; $ configurationLoaded = $ this -> loadConfiguration ( $ configurationNamespace , $ configurationKey ) ; if ( ! ( $ configurationLoaded instanceof ConfigurationInterface ) ) { $ configurationElement = $ this -> configurationElements [ $ configurationIdentifier ] ; $ configurationValue = isset ( $ configurationElement [ 'reference' ] ) ? $ this -> parameterBag -> get ( $ configurationElement [ 'reference' ] ) : $ configurationElement [ 'default_value' ] ; if ( empty ( $ configurationValue ) && ! $ configurationElement [ 'can_be_empty' ] ) { $ message = $ configurationElement [ 'empty_message' ] ? : 'The configuration element "' . $ configurationIdentifier . '" cannot be resolved' ; throw new Exception ( $ message ) ; } $ configurationLoaded = $ this -> createConfigurationInstance ( $ configurationIdentifier , $ configurationNamespace , $ configurationKey , $ configurationValue ) ; $ this -> flushConfiguration ( $ configurationLoaded ) ; } $ configurationValueUnserialized = $ this -> flushConfigurationToCache ( $ configurationLoaded , $ configurationIdentifier ) ; return $ configurationValueUnserialized ; }
Loads a parameter given the format namespace . key .
43,415
public function delete ( $ configurationIdentifier ) { if ( ! array_key_exists ( $ configurationIdentifier , $ this -> configurationElements ) ) { throw new ConfigurationParameterNotFoundException ( ) ; } if ( is_array ( $ this -> configurationElements [ $ configurationIdentifier ] ) && $ this -> configurationElements [ $ configurationIdentifier ] [ 'read_only' ] === true ) { throw new ConfigurationNotEditableException ( ) ; } $ valueIsCached = $ this -> cache -> contains ( $ configurationIdentifier ) ; if ( false !== $ valueIsCached ) { $ this -> cache -> delete ( $ configurationIdentifier ) ; } list ( $ configurationNamespace , $ configurationKey ) = $ this -> splitConfigurationKey ( $ configurationIdentifier ) ; $ configurationLoaded = $ this -> loadConfiguration ( $ configurationNamespace , $ configurationKey ) ; if ( $ configurationLoaded instanceof ConfigurationInterface ) { $ this -> deleteConfiguration ( $ configurationLoaded ) ; return true ; } return false ; }
Deletes a parameter given the format namespace . key .
43,416
private function loadConfiguration ( $ configurationNamespace , $ configurationKey ) { $ configurationEntity = $ this -> configurationRepository -> find ( [ 'namespace' => $ configurationNamespace , 'key' => $ configurationKey , ] ) ; return $ configurationEntity ; }
Loads a configuration .
43,417
private function flushConfiguration ( ConfigurationInterface $ configuration ) { $ this -> configurationObjectManager -> persist ( $ configuration ) ; $ this -> configurationObjectManager -> flush ( $ configuration ) ; return $ this ; }
Flushes a configuration instance .
43,418
private function deleteConfiguration ( ConfigurationInterface $ configuration ) { $ this -> configurationObjectManager -> remove ( $ configuration ) ; $ this -> configurationObjectManager -> flush ( $ configuration ) ; return $ this ; }
Deletes a configuration instance .
43,419
private function createConfigurationInstance ( $ configurationIdentifier , $ configurationNamespace , $ configurationKey , $ configurationValue ) { if ( ! $ this -> configurationElements [ $ configurationIdentifier ] ) { throw new ConfigurationParameterNotFoundException ( ) ; } $ configurationType = $ this -> configurationElements [ $ configurationIdentifier ] [ 'type' ] ; $ configurationValue = $ this -> serializeValue ( $ configurationValue , $ configurationType ) ; $ configurationEntity = $ this -> configurationFactory -> create ( ) -> setKey ( $ configurationKey ) -> setNamespace ( $ configurationNamespace ) -> setName ( $ this -> configurationElements [ $ configurationIdentifier ] [ 'name' ] ) -> setType ( $ configurationType ) -> setValue ( $ configurationValue ) ; return $ configurationEntity ; }
Creates a new configuration instance and serializes .
43,420
private function flushConfigurationToCache ( ConfigurationInterface $ configuration , $ configurationIdentifier ) { $ configurationValue = $ this -> unserializeValue ( $ configuration -> getValue ( ) , $ configuration -> getType ( ) ) ; $ this -> cache -> save ( $ configurationIdentifier , $ configurationValue ) ; return $ configurationValue ; }
Saves configuration into cache .
43,421
private function splitConfigurationKey ( $ configurationIdentifier ) { $ configurationIdentifier = explode ( '.' , $ configurationIdentifier , 2 ) ; if ( count ( $ configurationIdentifier ) === 1 ) { array_unshift ( $ configurationIdentifier , '' ) ; } return $ configurationIdentifier ; }
Split the configuration identifier and return each part .
43,422
private function unserializeValue ( $ configurationValue , $ configurationType ) { switch ( $ configurationType ) { case ElcodiConfigurationTypes :: TYPE_BOOLEAN : $ configurationValue = ( boolean ) $ configurationValue ; break ; case ElcodiConfigurationTypes :: TYPE_ARRAY : $ configurationValue = json_decode ( $ configurationValue , true ) ; break ; } return $ configurationValue ; }
Unserialize configuration value .
43,423
private function serializeValue ( $ configurationValue , $ configurationType ) { switch ( $ configurationType ) { case ElcodiConfigurationTypes :: TYPE_ARRAY : $ configurationValue = json_encode ( $ configurationValue ) ; break ; } return $ configurationValue ; }
Serialize configuration value .
43,424
public function transform ( $ content , $ options = [ ] ) { if ( ! $ content instanceof \ DateInterval ) { return 0 ; } $ decTime = 0 ; $ decTime += ( $ content -> d ? $ content -> d * 60 * 24 : 0 ) ; $ decTime += ( $ content -> h ? $ content -> h * 60 : 0 ) ; $ decTime += $ content -> i ; $ decTime += ( $ content -> s ? $ content -> s / 60 : 0 ) ; return $ decTime ; }
calculates the time down to the minutes
43,425
protected function prepareInput ( ) { $ arguments = [ '--optimize' => ( bool ) $ this -> file -> get ( self :: SETTING_OPTIMIZE ) , '--no-dev' => true , ] ; $ input = new ArrayInput ( $ arguments ) ; $ input -> setInteractive ( false ) ; return $ input ; }
Prepare the input interface for the command .
43,426
private function resolveParameterWithoutConfigService ( ContainerInterface $ container , $ requestedName ) { return function ( ReflectionParameter $ parameter ) use ( $ container , $ requestedName ) { return $ this -> resolveParameter ( $ parameter , $ container , $ requestedName ) ; } ; }
Resolve a parameter to a value .
43,427
private function resolveParameterWithConfigService ( ContainerInterface $ container , $ requestedName ) { return function ( ReflectionParameter $ parameter ) use ( $ container , $ requestedName ) { if ( $ parameter -> isArray ( ) && $ parameter -> getName ( ) === 'config' ) { return $ container -> get ( 'config' ) ; } return $ this -> resolveParameter ( $ parameter , $ container , $ requestedName ) ; } ; }
Returns a callback for resolving a parameter to a value including mapping config arguments .
43,428
private function resolveParameter ( ReflectionParameter $ parameter , ContainerInterface $ container , $ requestedName ) { if ( $ parameter -> isArray ( ) ) { return [ ] ; } if ( ! $ parameter -> getClass ( ) ) { if ( ! $ parameter -> isDefaultValueAvailable ( ) ) { throw new ServiceNotFoundException ( sprintf ( 'Unable to create service "%s"; unable to resolve parameter "%s" ' . 'to a class, interface, or array type' , $ requestedName , $ parameter -> getName ( ) ) ) ; } return $ parameter -> getDefaultValue ( ) ; } $ type = $ parameter -> getClass ( ) -> getName ( ) ; $ type = isset ( $ this -> aliases [ $ type ] ) ? $ this -> aliases [ $ type ] : $ type ; if ( $ container -> has ( $ type ) ) { return $ container -> get ( $ type ) ; } if ( ! $ parameter -> isOptional ( ) ) { throw new ServiceNotFoundException ( sprintf ( 'Unable to create service "%s"; unable to resolve parameter "%s" using type hint "%s"' , $ requestedName , $ parameter -> getName ( ) , $ type ) ) ; } return $ parameter -> getDefaultValue ( ) ; }
Logic common to all parameter resolution .
43,429
public function load ( array $ configs , ContainerBuilder $ container ) { $ loader = new XmlFileLoader ( $ container , new FileLocator ( __DIR__ . '/../Resources/config' ) ) ; $ loader -> load ( 'mandango.xml' ) ; $ processor = new Processor ( ) ; $ configuration = new Configuration ( $ container -> getParameter ( 'kernel.debug' ) ) ; $ config = $ processor -> process ( $ configuration -> getConfigTree ( ) , $ configs ) ; if ( isset ( $ config [ 'model_dir' ] ) ) { $ container -> setParameter ( 'mandango.model_dir' , $ config [ 'model_dir' ] ) ; } if ( isset ( $ config [ 'logging' ] ) && $ config [ 'logging' ] ) { $ container -> getDefinition ( 'mandango' ) -> addArgument ( array ( new Reference ( 'mandango.logger' ) , 'logQuery' ) ) ; } if ( isset ( $ config [ 'default_connection' ] ) ) { $ container -> getDefinition ( 'mandango' ) -> addMethodCall ( 'setDefaultConnectionName' , array ( $ config [ 'default_connection' ] ) ) ; } $ container -> setParameter ( 'mandango.extra_config_classes_dirs' , $ config [ 'extra_config_classes_dirs' ] ) ; foreach ( $ config [ 'connections' ] as $ name => $ connection ) { $ definition = new Definition ( $ connection [ 'class' ] , array ( $ connection [ 'server' ] , $ connection [ 'database' ] , $ connection [ 'options' ] , ) ) ; $ connectionDefinitionName = sprintf ( 'mandango.%s_connection' , $ name ) ; $ container -> setDefinition ( $ connectionDefinitionName , $ definition ) ; $ container -> getDefinition ( 'mandango' ) -> addMethodCall ( 'setConnection' , array ( $ name , new Reference ( $ connectionDefinitionName ) , ) ) ; } }
Responds to the mandango configuration parameter .
43,430
public function & setContent ( $ content ) { switch ( true ) { case ( $ content instanceof FormGroup ) : $ this -> type = 'group' ; break ; case ( $ content instanceof ControlsCollectionInterface ) : $ this -> type = 'collection' ; break ; case ( $ content instanceof AbstractForm ) : $ this -> type = 'control' ; break ; case ( $ content instanceof AbstractHtml ) : $ this -> type = 'factory' ; break ; default : $ this -> type = 'html' ; } $ this -> content = $ content ; return $ content ; }
Sets the element .
43,431
public function download ( $ file = null , $ type = null , $ file_name = null ) { if ( ! empty ( $ file ) && @ file_exists ( $ file ) ) { if ( is_null ( $ file_name ) ) { $ file_name_parts = explode ( '/' , $ file ) ; $ file_name = end ( $ file_name_parts ) ; } $ this -> addHeader ( 'Content-disposition' , 'attachment; filename=' . $ file_name ) ; $ this -> addHeader ( 'Content-Type' , 'application/force-download' ) ; $ this -> addHeader ( 'Content-Transfer-Encoding' , $ type ) ; $ this -> addHeader ( 'Content-Length' , filesize ( $ file ) ) ; $ this -> addHeader ( 'Pragma' , 'no-cache' ) ; $ this -> addHeader ( 'Cache-Control' , 'must-revalidate, post-check=0, pre-check=0, public' ) ; $ this -> addHeader ( 'Expires' , '0' ) ; $ this -> renderHeaders ( ) ; readfile ( $ file ) ; exit ; } return ; }
Force client to download a file
43,432
public function UserModel_BeforeDeleteUser_Handler ( $ Sender ) { $ UserID = GetValue ( 'UserID' , $ Sender -> EventArguments ) ; $ Options = GetValue ( 'Options' , $ Sender -> EventArguments , array ( ) ) ; $ Options = is_array ( $ Options ) ? $ Options : array ( ) ; $ Content = & $ Sender -> EventArguments [ 'Content' ] ; $ this -> DeleteUserData ( $ UserID , $ Options , $ Content ) ; }
Remove Vanilla data when deleting a user .
43,433
public function UserModel_GetCategoryViewPermission_Create ( $ Sender ) { static $ PermissionModel = NULL ; $ UserID = ArrayValue ( 0 , $ Sender -> EventArguments , '' ) ; $ CategoryID = ArrayValue ( 1 , $ Sender -> EventArguments , '' ) ; $ Permission = GetValue ( 2 , $ Sender -> EventArguments , 'Vanilla.Discussions.View' ) ; if ( $ UserID && $ CategoryID ) { if ( $ PermissionModel === NULL ) $ PermissionModel = new PermissionModel ( ) ; $ Category = CategoryModel :: Categories ( $ CategoryID ) ; if ( $ Category ) $ PermissionCategoryID = $ Category [ 'PermissionCategoryID' ] ; else $ PermissionCategoryID = - 1 ; $ Result = $ PermissionModel -> GetUserPermissions ( $ UserID , $ Permission , 'Category' , 'PermissionCategoryID' , 'CategoryID' , $ PermissionCategoryID ) ; return ( GetValue ( $ Permission , GetValue ( 0 , $ Result ) , FALSE ) ) ? TRUE : FALSE ; } return FALSE ; }
Check whether a user has access to view discussions in a particular category .
43,434
public function Base_Render_Before ( $ Sender ) { $ Session = Gdn :: Session ( ) ; if ( $ Sender -> Menu ) $ Sender -> Menu -> AddLink ( 'Discussions' , T ( 'Discussions' ) , '/discussions' , FALSE , array ( 'Standard' => TRUE ) ) ; }
Adds Discussion item to menu .
43,435
public function ProfileController_AddProfileTabs_Handler ( $ Sender ) { if ( is_object ( $ Sender -> User ) && $ Sender -> User -> UserID > 0 ) { $ UserID = $ Sender -> User -> UserID ; $ DiscussionsLabel = Sprite ( 'SpDiscussions' ) . ' ' . T ( 'Discussions' ) ; $ CommentsLabel = Sprite ( 'SpComments' ) . ' ' . T ( 'Comments' ) ; if ( C ( 'Vanilla.Profile.ShowCounts' , TRUE ) ) { $ DiscussionsLabel .= '<span class="Aside">' . CountString ( GetValueR ( 'User.CountDiscussions' , $ Sender , NULL ) , "/profile/count/discussions?userid=$UserID" ) . '</span>' ; $ CommentsLabel .= '<span class="Aside">' . CountString ( GetValueR ( 'User.CountComments' , $ Sender , NULL ) , "/profile/count/comments?userid=$UserID" ) . '</span>' ; } $ Sender -> AddProfileTab ( T ( 'Discussions' ) , 'profile/discussions/' . $ Sender -> User -> UserID . '/' . rawurlencode ( $ Sender -> User -> Name ) , 'Discussions' , $ DiscussionsLabel ) ; $ Sender -> AddProfileTab ( T ( 'Comments' ) , 'profile/comments/' . $ Sender -> User -> UserID . '/' . rawurlencode ( $ Sender -> User -> Name ) , 'Comments' , $ CommentsLabel ) ; $ Sender -> AddJsFile ( 'jquery.gardenmorepager.js' ) ; $ Sender -> AddJsFile ( 'discussions.js' ) ; } }
Adds Discussions tab to profiles and adds CSS & JS files to their head .
43,436
public function ProfileController_AfterPreferencesDefined_Handler ( $ Sender ) { $ Sender -> Preferences [ 'Notifications' ] [ 'Email.DiscussionComment' ] = T ( 'Notify me when people comment on my discussions.' ) ; $ Sender -> Preferences [ 'Notifications' ] [ 'Email.BookmarkComment' ] = T ( 'Notify me when people comment on my bookmarked discussions.' ) ; $ Sender -> Preferences [ 'Notifications' ] [ 'Email.Mention' ] = T ( 'Notify me when people mention me.' ) ; $ Sender -> Preferences [ 'Notifications' ] [ 'Popup.DiscussionComment' ] = T ( 'Notify me when people comment on my discussions.' ) ; $ Sender -> Preferences [ 'Notifications' ] [ 'Popup.BookmarkComment' ] = T ( 'Notify me when people comment on my bookmarked discussions.' ) ; $ Sender -> Preferences [ 'Notifications' ] [ 'Popup.Mention' ] = T ( 'Notify me when people mention me.' ) ; if ( Gdn :: Session ( ) -> CheckPermission ( 'Garden.AdvancedNotifications.Allow' ) ) { $ PostBack = $ Sender -> Form -> IsPostBack ( ) ; $ Set = array ( ) ; $ DoHeadings = C ( 'Vanilla.Categories.DoHeadings' ) ; $ Categories = array ( ) ; $ Prefixes = array ( 'Email.NewDiscussion' , 'Popup.NewDiscussion' , 'Email.NewComment' , 'Popup.NewComment' ) ; foreach ( CategoryModel :: Categories ( ) as $ Category ) { if ( ! $ Category [ 'PermsDiscussionsView' ] || $ Category [ 'Depth' ] <= 0 || $ Category [ 'Depth' ] > 2 || $ Category [ 'Archived' ] ) continue ; $ Category [ 'Heading' ] = ( $ DoHeadings && $ Category [ 'Depth' ] <= 1 ) ; $ Categories [ ] = $ Category ; if ( $ PostBack ) { foreach ( $ Prefixes as $ Prefix ) { $ FieldName = "$Prefix.{$Category['CategoryID']}" ; $ Value = $ Sender -> Form -> GetFormValue ( $ FieldName , NULL ) ; if ( ! $ Value ) $ Value = NULL ; $ Set [ $ FieldName ] = $ Value ; } } } $ Sender -> SetData ( 'CategoryNotifications' , $ Categories ) ; if ( $ PostBack ) { UserModel :: SetMeta ( $ Sender -> User -> UserID , $ Set , 'Preferences.' ) ; } } }
Adds email notification options to profiles .
43,437
public function ProfileController_Comments_Create ( $ Sender , $ UserReference = '' , $ Username = '' , $ Page = '' , $ UserID = '' ) { $ Sender -> EditMode ( FALSE ) ; $ View = $ Sender -> View ; $ Sender -> GetUserInfo ( $ UserReference , $ Username , $ UserID ) ; $ Sender -> _SetBreadcrumbs ( T ( 'Comments' ) , UserUrl ( $ Sender -> User , '' , 'comments' ) ) ; $ Sender -> SetTabView ( 'Comments' , 'profile' , 'Discussion' , 'Vanilla' ) ; $ PageSize = Gdn :: Config ( 'Vanilla.Discussions.PerPage' , 30 ) ; list ( $ Offset , $ Limit ) = OffsetLimit ( $ Page , $ PageSize ) ; $ CommentModel = new CommentModel ( ) ; $ Comments = $ CommentModel -> GetByUser2 ( $ Sender -> User -> UserID , $ Limit , $ Offset , $ Sender -> Request -> Get ( 'lid' ) ) ; $ TotalRecords = $ Offset + $ CommentModel -> LastCommentCount + 1 ; $ PagerFactory = new Gdn_PagerFactory ( ) ; $ Sender -> Pager = $ PagerFactory -> GetPager ( 'MorePager' , $ Sender ) ; $ Sender -> Pager -> MoreCode = 'More Comments' ; $ Sender -> Pager -> LessCode = 'Newer Comments' ; $ Sender -> Pager -> ClientID = 'Pager' ; $ Sender -> Pager -> Configure ( $ Offset , $ Limit , $ TotalRecords , UserUrl ( $ Sender -> User , '' , 'comments' ) . '?page={Page}' ) ; if ( $ Sender -> DeliveryType ( ) != DELIVERY_TYPE_ALL && $ Offset > 0 ) { $ Sender -> SetJson ( 'LessRow' , $ Sender -> Pager -> ToString ( 'less' ) ) ; $ Sender -> SetJson ( 'MoreRow' , $ Sender -> Pager -> ToString ( 'more' ) ) ; $ Sender -> View = 'profilecomments' ; } $ Sender -> SetData ( 'Comments' , $ Comments ) ; $ Sender -> HandlerType = HANDLER_TYPE_NORMAL ; $ Sender -> ShowOptions = FALSE ; if ( $ Sender -> Head ) { $ Sender -> Head -> AddTag ( 'meta' , array ( 'name' => 'robots' , 'content' => 'noindex,noarchive' ) ) ; } $ Sender -> Render ( ) ; }
Creates virtual Comments method in ProfileController .
43,438
public function ProfileController_Discussions_Create ( $ Sender , $ UserReference = '' , $ Username = '' , $ Page = '' , $ UserID = '' ) { $ Sender -> EditMode ( FALSE ) ; $ Sender -> GetUserInfo ( $ UserReference , $ Username , $ UserID ) ; $ Sender -> _SetBreadcrumbs ( T ( 'Discussions' ) , UserUrl ( $ Sender -> User , '' , 'discussions' ) ) ; $ Sender -> SetTabView ( 'Discussions' , 'Profile' , 'Discussions' , 'Vanilla' ) ; $ Sender -> CountCommentsPerPage = C ( 'Vanilla.Comments.PerPage' , 30 ) ; list ( $ Offset , $ Limit ) = OffsetLimit ( $ Page , Gdn :: Config ( 'Vanilla.Discussions.PerPage' , 30 ) ) ; $ DiscussionModel = new DiscussionModel ( ) ; $ Discussions = $ DiscussionModel -> GetByUser ( $ Sender -> User -> UserID , $ Limit , $ Offset ) ; $ CountDiscussions = $ Offset + $ DiscussionModel -> LastDiscussionCount + 1 ; $ Sender -> DiscussionData = $ Sender -> SetData ( 'Discussions' , $ Discussions ) ; $ PagerFactory = new Gdn_PagerFactory ( ) ; $ Sender -> Pager = $ PagerFactory -> GetPager ( 'MorePager' , $ Sender ) ; $ Sender -> Pager -> MoreCode = 'More Discussions' ; $ Sender -> Pager -> LessCode = 'Newer Discussions' ; $ Sender -> Pager -> ClientID = 'Pager' ; $ Sender -> Pager -> Configure ( $ Offset , $ Limit , $ CountDiscussions , UserUrl ( $ Sender -> User , '' , 'discussions' ) . '?page={Page}' ) ; if ( $ Sender -> DeliveryType ( ) != DELIVERY_TYPE_ALL && $ Offset > 0 ) { $ Sender -> SetJson ( 'LessRow' , $ Sender -> Pager -> ToString ( 'less' ) ) ; $ Sender -> SetJson ( 'MoreRow' , $ Sender -> Pager -> ToString ( 'more' ) ) ; $ Sender -> View = 'discussions' ; } $ Sender -> HandlerType = HANDLER_TYPE_NORMAL ; $ Sender -> ShowOptions = FALSE ; if ( $ Sender -> Head ) { $ Sender -> Head -> AddTag ( 'meta' , array ( 'name' => 'robots' , 'content' => 'noindex,noarchive' ) ) ; } $ Sender -> Render ( ) ; }
Creates virtual Discussions method in ProfileController .
43,439
public function Base_GetAppSettingsMenuItems_Handler ( $ Sender ) { $ Menu = & $ Sender -> EventArguments [ 'SideMenu' ] ; $ Menu -> AddLink ( 'Moderation' , T ( 'Flood Control' ) , 'vanilla/settings/floodcontrol' , 'Garden.Settings.Manage' ) ; $ Menu -> AddLink ( 'Forum' , T ( 'Categories' ) , 'vanilla/settings/managecategories' , 'Garden.Settings.Manage' ) ; $ Menu -> AddLink ( 'Forum' , T ( 'Advanced' ) , 'vanilla/settings/advanced' , 'Garden.Settings.Manage' ) ; $ Menu -> AddLink ( 'Forum' , T ( 'Blog Comments' ) , 'dashboard/embed/comments' , 'Garden.Settings.Manage' ) ; $ Menu -> AddLink ( 'Forum' , T ( 'Embed Forum' ) , 'dashboard/embed/forum' , 'Garden.Settings.Manage' ) ; }
Adds items to dashboard menu .
43,440
public function Setup ( ) { $ Database = Gdn :: Database ( ) ; $ Config = Gdn :: Factory ( Gdn :: AliasConfig ) ; $ Drop = Gdn :: Config ( 'Vanilla.Version' ) === FALSE ? TRUE : FALSE ; $ Explicit = TRUE ; $ Validation = new Gdn_Validation ( ) ; include ( PATH_APPLICATIONS . DS . 'vanilla' . DS . 'settings' . DS . 'structure.php' ) ; SaveToConfig ( 'Routes.DefaultController' , 'discussions' ) ; }
Automatically executed when application is enabled .
43,441
protected function getInstance ( $ id , array $ args ) { list ( $ rawId , $ scopedId , $ scope ) = $ this -> realScopeInfo ( $ id ) ; if ( isset ( $ this -> pool [ $ scopedId ] ) ) { return $ this -> pool [ $ scopedId ] ; } $ instance = $ this -> createInstance ( $ rawId , $ args ) ; if ( empty ( $ args ) && ScopeInterface :: SCOPE_SINGLE !== $ scope ) { $ this -> pool [ $ scopedId ] = $ instance ; } return $ instance ; }
Get the instance either from the pool or create it
43,442
protected function realScopeInfo ( $ id ) { list ( $ rawId , $ scope ) = $ this -> scopedInfo ( $ id ) ; if ( isset ( $ this -> loop [ $ scope ] ) ) { $ scope .= '_' . $ this -> loop [ $ scope ] ; } return [ $ rawId , $ this -> scopedId ( $ rawId , $ scope ) , $ scope ] ; }
Full scope info with consideration of ancestor instances
43,443
protected function createInstance ( $ rawId , array $ args ) { $ serviceId = ObjectResolver :: getServiceId ( $ rawId ) ; if ( isset ( $ this -> loop [ $ serviceId ] ) ) { throw new LogicException ( Message :: get ( Message :: DI_LOOP_DETECTED , $ rawId ) , Message :: DI_LOOP_DETECTED ) ; } else { $ this -> loop [ $ serviceId ] = ++ $ this -> counter ; $ obj = $ this -> getFactory ( ) -> createInstance ( $ rawId , $ args ) ; unset ( $ this -> loop [ $ serviceId ] ) ; return $ obj ; } }
Create the instance with loop detection
43,444
protected function initContainer ( ) { $ initNode = $ this -> getResolver ( ) -> getSectionId ( '' , 'init' ) ; if ( $ this -> getResolver ( ) -> has ( $ initNode ) ) { $ this -> getFactory ( ) -> executeMethodBatch ( $ this -> getResolver ( ) -> get ( $ initNode ) ) ; } return $ this ; }
execute init methods defined in di . init node
43,445
public function emit ( ResponseInterface $ response ) { $ filename = $ linenum = null ; if ( headers_sent ( $ filename , $ linenum ) ) { throw new RuntimeException ( sprintf ( 'Unable to emit response; headers already sent in "%s" ' . 'on line "%s".' , $ filename , $ linenum ) ) ; } $ this -> emitStatusLine ( $ response ) -> emitHeaders ( $ response ) -> emitBody ( $ response ) ; }
Emits the response .
43,446
protected function emitStatusLine ( ResponseInterface $ response ) { $ reasonPhrase = $ response -> getReasonPhrase ( ) ; header ( sprintf ( 'HTTP/%s %d%s' , $ response -> getProtocolVersion ( ) , $ response -> getStatusCode ( ) , ( $ reasonPhrase ? ' ' . $ reasonPhrase : '' ) ) ) ; return $ this ; }
Emits the status line .
43,447
protected function emitHeaders ( ResponseInterface $ response ) { $ normalize = function ( $ headerName ) { $ name = str_replace ( '-' , ' ' , $ headerName ) ; $ filtered = str_replace ( ' ' , '-' , ucwords ( $ name ) ) ; return $ filtered ; } ; foreach ( $ response -> getHeaders ( ) as $ headerName => $ values ) { $ name = $ normalize ( $ headerName ) ; $ first = true ; foreach ( $ values as $ value ) { header ( sprintf ( '%s: %s' , $ name , $ value ) , $ first ) ; $ first = false ; } } return $ this ; }
Emits headers .
43,448
protected function emitBody ( ResponseInterface $ response ) { while ( ob_get_level ( ) ) { ob_end_flush ( ) ; } $ body = $ response -> getBody ( ) ; if ( $ body -> getSize ( ) ) { echo $ body ; } return $ this ; }
Emits body .
43,449
public function findWithPermission ( $ permission ) { return array_filter ( $ this -> findAll ( ) , function ( $ role ) use ( $ permission ) { return $ role -> has ( $ permission ) ; } ) ; }
Find roles with permission
43,450
public function findWithoutPermission ( $ permission ) { return array_filter ( $ this -> findAll ( ) , function ( $ role ) use ( $ permission ) { return $ role -> hasnt ( $ permission ) ; } ) ; }
Find roles without permission
43,451
public function load ( Container $ object ) { $ pks = [ ] ; $ values = $ this -> parameters ; $ identifier = $ this -> identifier ; foreach ( $ this -> primaryKey as $ key ) { if ( isset ( $ object -> $ key ) ) { $ pks [ $ key ] = sprintf ( '%s.%s = ?' , $ identifier , $ key ) ; $ values [ ] = $ object -> $ key ; } else { throw new Exception \ PrimaryKey ( $ identifier , $ key ) ; } } $ fields = $ this -> fields ; foreach ( $ fields as & $ field ) { $ field = "$identifier.$field" ; } $ identifier .= $ this -> generateJoin ( $ fields ) ; $ sql = "SELECT %s FROM %s WHERE %s" ; $ stmt = $ this -> getStatement ( sprintf ( $ sql , implode ( ', ' , $ fields ) , $ identifier , implode ( ' AND ' , $ pks ) ) ) ; $ stmt -> setFetchMode ( Base :: FETCH_INTO , $ object ) ; $ stmt -> execute ( $ values ) ; $ stmt -> fetch ( ) ; $ object -> markClean ( ) ; }
Load data into a single model .
43,452
protected function generateJoin ( array & $ fields ) { $ annotations = $ this -> annotations [ 'class' ] ; $ props = $ this -> annotations [ 'properties' ] ; $ table = '' ; foreach ( [ 'Require' => '' , 'Include' => 'LEFT ' ] as $ type => $ join ) { if ( isset ( $ annotations [ $ type ] ) ) { foreach ( $ annotations [ $ type ] as $ local => $ joinCond ) { if ( is_numeric ( $ local ) ) { foreach ( $ joinCond as $ local => $ joinCond ) { } } $ joinCond = AnnotationParser :: getAnnotations ( '/** @joinCond ' . implode ( ', ' , $ joinCond ) . ' */' ) [ 'joincond' ] ; $ table .= sprintf ( ' %1$sJOIN %2$s ON ' , $ join , $ local ) ; $ conds = [ ] ; foreach ( $ joinCond as $ ref => $ me ) { if ( $ me == '?' ) { $ conds [ ] = sprintf ( "%s.%s = $me" , $ local , $ ref ) ; } else { $ conds [ ] = sprintf ( "%s.%s = %s.%s" , $ local , $ ref , $ this -> identifier , $ me ) ; } } $ table .= implode ( " AND " , $ conds ) ; } } } foreach ( $ fields as & $ field ) { $ name = str_replace ( "{$this->identifier}." , '' , $ field ) ; if ( isset ( $ props [ $ name ] [ 'From' ] ) ) { $ field = sprintf ( '%s %s' , $ props [ $ name ] [ 'From' ] , $ name ) ; } } return $ table ; }
Internal helper to generate a JOIN statement .
43,453
protected function getStatement ( $ sql ) { if ( ! isset ( $ this -> statements [ $ sql ] ) ) { $ this -> statements [ $ sql ] = $ this -> adapter -> prepare ( $ sql ) ; } return $ this -> statements [ $ sql ] ; }
Protected helper to either get or create a PDOStatement .
43,454
public static function routeExists ( $ route , sfContext $ context ) { try { if ( $ route { 0 } == '@' ) { $ context -> getRouting ( ) -> generate ( substr ( $ route , 1 ) ) ; } return true ; } catch ( Exception $ e ) { return false ; } }
Check if the supplied route exists
43,455
public function query ( $ pQuery , array $ pParams = array ( ) ) { $ this -> _stm = Agl :: app ( ) -> getDb ( ) -> getConnection ( ) -> prepare ( $ pQuery ) ; if ( ! $ this -> _stm -> execute ( $ pParams ) ) { $ error = $ this -> _stm -> errorInfo ( ) ; throw new Exception ( "The query failed with message '" . $ error [ 2 ] . "'" ) ; } if ( Agl :: app ( ) -> isDebugMode ( ) ) { Agl :: app ( ) -> getDb ( ) -> incrementCounter ( ) ; } return $ this -> _stm -> fetchAll ( PDO :: FETCH_ASSOC ) ; }
Commit the query to the database and return the result .
43,456
private static function extractConstants ( ) { $ oClass = new \ ReflectionClass ( get_called_class ( ) ) ; $ constants = $ oClass -> getConstants ( ) ; unset ( $ constants [ 'IS_IMPLICIT_ABSTRACT' ] , $ constants [ 'IS_EXPLICIT_ABSTRACT' ] , $ constants [ 'IS_FINAL' ] ) ; return $ constants ; }
Extract constants using ReflectionClass
43,457
protected static function updateHiddenValue ( $ list , $ name ) { $ sid = $ list [ $ name ] ; unset ( $ list [ $ name ] ) ; preg_match ( "/" . self :: $ hiddenSidNamePattern . "/" , $ name , $ match ) ; $ list [ $ match [ 1 ] ] = $ sid ; return $ list ; }
Update hidden value s name by removing leading _
43,458
public static function getList ( bool $ full = false ) { $ class = get_called_class ( ) ; if ( empty ( self :: $ list [ $ class ] ) ) { self :: $ list [ $ class ] = self :: loadList ( ) ; } $ list = self :: $ list [ $ class ] ; foreach ( $ list as $ name => $ sid ) { if ( static :: isHidden ( $ name ) ) { if ( ! $ full ) unset ( $ list [ $ name ] ) ; else $ list = self :: updateHiddenValue ( $ list , $ name ) ; } } return $ list ; }
Get full sid list
43,459
public static function getNameById ( $ sid ) { $ list = self :: getList ( true ) ; $ key = array_search ( $ sid , $ list ) ; if ( $ key === false ) throw new SidItemNotFound ( 'Sid not exists' ) ; return $ key ; }
Return constant name from SID .
43,460
public static function getTitle ( $ id , $ lang , $ context = 'default' ) { $ name = self :: getNameById ( $ id ) ; $ class = self :: getClassWithoutNamespace ( ) ; return call_user_func ( self :: getCallback ( $ lang ) , $ name , $ class , $ context ) ; }
Get Sid title from vocabulary
43,461
public function getTimeAgo ( $ field = null , $ options = [ ] ) { $ attribute = $ this -> attribute ; if ( $ field !== null ) { $ attribute = $ field ; } $ year = $ options [ 'year' ] ?? 'full:{day} {month} {year}' ; $ month = $ options [ 'month' ] ?? 'full:{day} {month}' ; if ( $ this -> owner -> hasAttribute ( $ attribute ) ) { $ value = $ this -> owner { $ attribute } ; if ( ! is_numeric ( $ this -> owner { $ attribute } ) ) { $ value = strtotime ( $ this -> owner { $ attribute } ) ; } $ updatedM = date ( 'm' , $ value ) ; $ currM = date ( 'm' , time ( ) ) ; $ updatedY = date ( 'Y' , $ value ) ; $ currY = date ( 'Y' , time ( ) ) ; if ( $ updatedY !== $ currY ) { return Html :: tag ( 'time' , Yii :: $ app -> formatter -> asDate ( $ value , 'long' ) ) ; } if ( $ updatedM < $ currM ) { return Html :: tag ( 'time' , Yii :: $ app -> formatter -> asDate ( $ value , 'medium' ) ) ; } return TimeAgo :: widget ( [ 'timestamp' => $ value , 'language' => Yii :: $ app -> language ] ) ; } return null ; }
Get a date in the time ago format
43,462
public static function bindSort ( \ Criteria $ criteria , $ sort ) { $ direction = $ sort [ 'direction' ] ; switch ( $ direction ) { case self :: SORT_DIRECTION_DESC : $ criteria -> addDescendingOrderByColumn ( $ sort [ 'column' ] ) ; break ; case self :: SORT_DIRECTION_ASC : $ criteria -> addAscendingOrderByColumn ( $ sort [ 'column' ] ) ; break ; default : throw new RuntimeException ( 'Unsupport Ext direct sort direction:' . $ direction ) ; } }
bind Ext direct sort to Propel Criteria
43,463
public function areAllowed ( array $ actions , ClassMetadata $ metadata , $ document = null , ChangeSet $ changeSet = null ) { if ( ! $ metadata -> hasProperty ( 'permissions' ) ) { return new AllowedResult ( false ) ; } $ result = $ this -> checkRolesAgainstActions ( [ 'guest' ] , $ actions , $ metadata ) ; if ( ! $ result -> getAllowed ( ) || $ result -> hasCriteria ( ) ) { $ roles = $ this -> getRoles ( $ metadata , $ document ) ; $ result = $ this -> checkRolesAgainstActions ( $ roles , $ actions , $ metadata ) ; } if ( isset ( $ document ) ) { return $ this -> testCritieraAgainstDocument ( $ metadata , $ document , $ changeSet , $ result ) ; } return $ result ; }
Determines if an action can be done by the current User
43,464
private function looksLikeConcatenatedJsString ( string $ url ) : bool { $ patternBody = "^'\s+\+\s+.*\s+\+\s+'$" ; $ pattern = '/' . $ patternBody . '/i' ; return preg_match ( $ pattern , $ url ) > 0 ; }
Determine if the URL value from an element attribute looks like a concatenated JS string
43,465
protected function fputcsv ( $ filePointer , $ dataArray , $ delimiter = "," , $ enclosure = "\"" ) { $ string = "" ; $ writeDelimiter = false ; foreach ( $ dataArray as $ dataElement ) { $ dataElement = str_replace ( "\"" , "\"\"" , $ dataElement ) ; if ( $ writeDelimiter ) { $ string .= $ delimiter ; } if ( $ enclosure ) { $ string .= $ enclosure . $ dataElement . $ enclosure ; } else { $ string .= $ dataElement ; } $ writeDelimiter = true ; } $ string .= "\n" ; fwrite ( $ filePointer , $ string ) ; }
Write a line to a file
43,466
protected function writeDataInIO ( $ fp ) { if ( $ this -> useAssociativeArray ) { foreach ( $ this -> data as $ donnee ) { foreach ( $ donnee as & $ champ ) { $ champ = ( is_string ( $ champ ) ) ? iconv ( "UTF-8" , "Windows-1252//TRANSLIT" , $ champ ) : $ champ ; } $ this -> fputcsv ( $ fp , $ donnee , ';' , $ this -> enclosures ) ; } } else { for ( $ i = 0 ; $ i < count ( $ this -> data ) ; $ i ++ ) { for ( $ j = 0 ; $ j < count ( $ this -> data [ $ i ] ) ; $ j ++ ) { $ this -> fputcsv ( $ fp , $ this -> data [ $ i ] [ $ j ] , ';' , $ this -> enclosures ) ; } } } }
Ecrit dans le flux de sortie
43,467
private function sendErrorDocument ( ResponseInterface $ response ) : ResponseInterface { if ( $ this -> errorDocument && preg_match ( "/^(4|5){1}[0-2]{1}[0-9]{1}$/" , $ response -> getStatusCode ( ) ) ) { $ this -> errorDocument = str_replace ( "{status}" , $ response -> getStatusCode ( ) , $ this -> errorDocument ) ; if ( $ this -> errorDocument !== filter_input ( INPUT_SERVER , "REQUEST_URI" ) ) { $ response = $ response -> withHeader ( Response :: HEADER_REFRESH , "0; " . $ this -> errorDocument ) ; } } return $ response ; }
Send error document
43,468
public function setPrefix ( string $ prefix ) : RouterInterface { $ prefix = trim ( $ prefix , '/' ) ; $ this -> prefix = $ prefix . ( strlen ( $ prefix ) ? '/' : '' ) ; return $ this ; }
Set the prefix for all future URLs used mainly internally .
43,469
public function add ( $ method , $ url = null , $ handler = null ) : RouterInterface { $ temp = [ 'method' => [ 'GET' , 'POST' ] , 'url' => '' , 'handler' => null ] ; foreach ( func_get_args ( ) as $ arg ) { if ( is_callable ( $ arg ) ) { $ temp [ 'handler' ] = $ arg ; } else if ( in_array ( $ arg , [ 'GET' , 'HEAD' , 'POST' , 'PATCH' , 'DELETE' , 'PUT' , 'OPTIONS' , 'REPORT' ] ) ) { $ temp [ 'method' ] = $ arg ; } else { $ temp [ 'url' ] = $ arg ; } } list ( $ method , $ url , $ handler ) = array_values ( $ temp ) ; if ( ! $ url && $ this -> prefix ) { $ url = $ this -> prefix ; } else { if ( ! $ url ) { $ url = '{**}' ; } $ url = $ this -> prefix . $ url ; } if ( ! $ method ) { $ method = [ 'GET' , 'POST' ] ; } if ( ! is_array ( $ method ) ) { $ method = [ $ method ] ; } if ( ! is_callable ( $ handler ) ) { throw new RouterException ( 'No valid handler found' ) ; } foreach ( $ method as $ m ) { if ( ! isset ( $ this -> routes [ $ m ] ) ) { $ this -> routes [ $ m ] = [ ] ; } $ this -> routes [ $ m ] [ $ url ] = $ handler ; } return $ this ; }
Add a route . All params are optional and each of them can be omitted independently .
43,470
public function userHasAccess ( User $ user ) { if ( $ this -> getWhitelisted ( ) === false ) { return true ; } $ criteria = Criteria :: create ( ) -> where ( Criteria :: expr ( ) -> eq ( 'user' , $ user ) ) -> setMaxResults ( 1 ) ; $ serverUsers = $ this -> users -> matching ( $ criteria ) ; if ( $ serverUsers -> count ( ) === 0 ) { return false ; } $ serverUser = $ serverUsers -> first ( ) ; if ( $ serverUser -> getBanned ( ) === true ) { return false ; } if ( $ this -> getRequiresApproval ( ) === true && $ serverUser -> getApproved ( ) === false ) { return false ; } return true ; }
Get whether the user has access
43,471
protected function buildUserForm ( FormBuilderInterface $ builder , array $ options ) { $ now = new \ DateTime ( ) ; $ builder -> add ( 'username' , null , array ( 'label' => 'form.label_username' , 'translation_domain' => 'SonataUserBundle' ) ) -> add ( 'email' , 'email' , array ( 'label' => 'form.label_email' , 'translation_domain' => 'SonataUserBundle' , 'read_only' => true , 'attr' => array ( 'class' => 'span12' ) ) ) -> add ( 'firstname' , null , array ( 'label' => 'form.label_firstname' , 'translation_domain' => 'SonataUserBundle' , 'attr' => array ( 'class' => 'span12' ) ) ) -> add ( 'lastname' , null , array ( 'label' => 'form.label_lastname' , 'translation_domain' => 'SonataUserBundle' , 'attr' => array ( 'class' => 'span12' ) ) ) -> add ( 'website' , null , array ( 'label' => 'form.label_website' , 'translation_domain' => 'SonataUserBundle' , 'attr' => array ( 'class' => 'span12' ) ) ) -> add ( 'phone' , null , array ( 'required' => false , 'label' => 'form.label_phone' , 'translation_domain' => 'SonataUserBundle' , 'attr' => array ( 'class' => 'span12' ) ) ) -> add ( 'dateOfBirth' , 'sonata_type_date_picker' , array ( 'years' => range ( 1900 , $ now -> format ( 'Y' ) ) , 'dp_min_date' => '1-1-1900' , 'dp_max_date' => $ now -> format ( 'c' ) , 'required' => false , ) ) -> add ( 'gender' , 'choice' , array ( 'label' => 'form.label_gender' , 'choices' => array ( UserInterface :: GENDER_UNKNOWN => 'gender_unknown' , UserInterface :: GENDER_FEMALE => 'gender_female' , UserInterface :: GENDER_MAN => 'gender_male' , ) , 'required' => true , 'translation_domain' => 'SonataUserBundle' , 'attr' => array ( 'class' => 'span12' ) ) ) ; }
Builds the embedded form representing the user .
43,472
public function set ( $ name , $ rule = null ) { if ( ! is_array ( $ name ) ) { $ name = [ $ name => $ rule ] ; } $ this -> _handlers = $ name + $ this -> _handlers ; }
Sets one or several validation rules .
43,473
public function has ( $ name ) { $ checker = $ this -> _classes [ 'checker' ] ; return isset ( $ this -> _handlers [ $ name ] ) || $ checker :: has ( $ name ) ; }
Checks if a validation handler exists .
43,474
public function get ( $ name ) { if ( isset ( $ this -> _handlers [ $ name ] ) ) { return $ this -> _handlers [ $ name ] ; } $ checker = $ this -> _classes [ 'checker' ] ; if ( $ checker :: has ( $ name ) ) { return $ checker :: get ( $ name ) ; } throw new InvalidArgumentException ( "Unexisting `{$name}` as validation handler." ) ; }
Returns a validation handler .
43,475
public function rule ( $ field , $ rules = [ ] ) { $ defaults = [ 'message' => null , 'required' => true , 'skipEmpty' => false , 'format' => 'any' , 'not' => false , 'on' => null ] ; $ rules = $ rules ? ( array ) $ rules : [ ] ; foreach ( $ rules as $ name => $ options ) { if ( is_numeric ( $ name ) ) { $ name = $ options ; $ options = [ ] ; } if ( is_string ( $ options ) ) { $ options = [ 'message' => $ options ] ; } $ options += $ defaults ; $ this -> _rules [ $ field ] [ $ name ] = $ options ; } }
Sets a rule .
43,476
public function validates ( $ data , $ options = [ ] ) { $ events = ( array ) ( isset ( $ options [ 'events' ] ) ? $ options [ 'events' ] : null ) ; $ this -> _errors = [ ] ; $ error = $ this -> _error ; foreach ( $ this -> _rules as $ field => $ rules ) { $ values = static :: values ( $ data , explode ( '.' , $ field ) ) ; foreach ( $ rules as $ name => $ rule ) { $ rule += $ options ; $ rule [ 'field' ] = $ field ; if ( $ events && $ rule [ 'on' ] && ! array_intersect ( $ events , ( array ) $ rule [ 'on' ] ) ) { continue ; } if ( ! $ values && $ rule [ 'required' ] ) { $ rule [ 'message' ] = null ; $ this -> _errors [ $ field ] [ ] = $ error ( 'required' , $ rule , $ this -> _meta ) ; break ; } else { foreach ( $ values as $ key => $ value ) { if ( empty ( $ value ) && $ rule [ 'skipEmpty' ] ) { continue ; } if ( ! $ this -> is ( $ name , $ value , $ rule + compact ( 'data' ) , $ params ) ) { $ this -> _errors [ $ key ] [ ] = $ error ( $ name , $ params + $ rule , $ this -> _meta ) ; } } } } } return ! $ this -> _errors ; }
Validates a set of values against a specified rules list . This method may be used to validate any arbitrary array of data against a set of validation rules .
43,477
public function is ( $ name , $ value , $ options = [ ] , & $ params = [ ] ) { $ not = false ; if ( strncmp ( $ name , 'not:' , 4 ) === 0 ) { $ name = substr ( $ name , 4 ) ; $ not = true ; } $ handlers = $ this -> get ( $ name ) ; $ handlers = is_array ( $ handlers ) ? $ handlers : [ $ handlers ] ; $ checker = $ this -> _classes [ 'checker' ] ; return $ checker :: check ( $ value , $ handlers , $ options , $ params ) !== $ not ; }
Checks a single value against a validation handler .
43,478
public static function values ( $ data , $ path = [ ] , $ base = null ) { if ( ! $ path ) { $ base = $ base ? : 0 ; return [ $ base => $ data ] ; } $ field = array_shift ( $ path ) ; if ( $ field === '*' ) { $ values = [ ] ; foreach ( $ data as $ key => $ value ) { $ values = array_merge ( $ values , static :: values ( $ value , $ path , $ base . '.' . $ key ) ) ; } return $ values ; } elseif ( ! isset ( $ data [ $ field ] ) ) { return [ ] ; } elseif ( ! $ path ) { return [ $ base ? $ base . '.' . $ field : $ field => $ data [ $ field ] ] ; } else { return static :: values ( $ data [ $ field ] , $ path , $ base ? $ base . '.' . $ field : $ field ) ; } }
Extracts all values corresponding to a field names path .
43,479
public function addLoader ( Loader $ loader ) { $ loader -> setLocator ( $ this -> locator ) ; $ this -> resolver -> addLoader ( $ loader ) ; }
Adds the loader .
43,480
public function get ( $ file , $ values = null , array & $ imported = array ( ) ) { if ( ( null !== $ values ) && ( false === is_array ( $ values ) ) ) { if ( false === ( $ values instanceof ArrayAccess ) ) { throw new InvalidArgumentException ( 'The value of $values is not an array or an instance of ArrayAccess.' ) ; } } if ( null !== $ values ) { $ values = $ this -> mergeValues ( $ this -> values , $ values ) ; } else { $ values = $ this -> values ; } $ new = dirname ( $ file ) . DIRECTORY_SEPARATOR . $ this -> prefix . basename ( $ file ) ; try { $ found = $ this -> locator -> locate ( $ new ) ; } catch ( InvalidArgumentException $ first ) { if ( empty ( $ this -> prefix ) ) { throw $ first ; } try { $ found = $ this -> locator -> locate ( $ file ) ; } catch ( InvalidArgumentException $ second ) { throw $ first ; } } if ( in_array ( $ found , $ imported ) ) { throw new LogicException ( sprintf ( 'Circular dependency detected for: %s' , $ found ) ) ; } $ imported [ ] = $ found ; if ( false === empty ( $ this -> cache ) ) { $ cache = new ConfigCache ( $ this -> cache . DIRECTORY_SEPARATOR . $ file . '.php' , $ this -> debug ) ; if ( $ cache -> isFresh ( ) ) { return $ this -> import ( require $ cache , $ values , $ imported ) ; } } if ( false === ( $ loader = $ this -> resolver -> resolve ( $ file ) ) ) { throw new InvalidArgumentException ( sprintf ( 'No loader available for file: %s' , $ file ) ) ; } $ loader -> setValues ( $ values ) ; $ data = $ loader -> load ( $ found ) ; if ( isset ( $ cache ) ) { $ cache -> write ( '<?php return ' . var_export ( $ data , true ) . ';' , array ( new FileResource ( $ found ) ) ) ; } return $ this -> import ( $ data , $ values , $ imported ) ; }
Returns the data for the configuration file .
43,481
public function import ( array $ data , $ values = null , array & $ imported = array ( ) ) { if ( false === isset ( $ data [ 'imports' ] ) ) { return $ data ; } $ imports = $ data [ 'imports' ] ; unset ( $ data [ 'imports' ] ) ; foreach ( $ imports as $ resource ) { $ data = array_replace_recursive ( $ this -> get ( $ resource , $ values , $ imported ) , $ data ) ; } return $ data ; }
Manages the imports directive in configuration files .
43,482
public function setValues ( $ values ) { if ( ( null !== $ values ) && ( false === is_array ( $ values ) ) ) { if ( false === ( $ values instanceof ArrayAccess ) ) { throw new InvalidArgumentException ( 'The value of $values is not an array or an instance of ArrayAccess.' ) ; } } $ this -> values = $ values ; }
Sets the default replacement values .
43,483
private function mergeValues ( $ a , $ b ) { $ x = array ( ) ; $ y = array ( ) ; if ( is_array ( $ a ) ) { $ x = $ a ; } foreach ( $ b as $ key => $ value ) { $ x [ $ key ] = $ value ; } return $ x ; }
Merges two sets of replacement values .
43,484
public function suspend ( $ code = null ) { if ( ! $ code ) { $ code = $ this -> data -> code ; } $ response = $ this -> client -> put ( '/{code}/suspend' , [ $ code ] ) ; if ( ! $ response -> hasErrors ( ) ) { $ this -> event -> dispatch ( 'SUBSCRIPTION.SUSPENDED' , new SubscriptionsEvent ( $ this -> data ) ) ; } return $ this ; }
Suspend a subscription
43,485
public function setNextInvoiceDate ( $ date ) { $ date = DateTime :: createFromFormat ( 'Y-m-d' , $ date ) ; $ this -> next_invoice_date = new stdClass ( ) ; $ this -> next_invoice_date -> day = $ date -> format ( 'd' ) ; $ this -> next_invoice_date -> month = $ date -> format ( 'm' ) ; $ this -> next_invoice_date -> year = $ date -> format ( 'Y' ) ; return $ this ; }
Set next invoice date
43,486
public function setNewCustomer ( Customers $ customer ) { $ this -> client -> addQueryString ( 'new_customer' , true ) ; $ this -> data -> customer = $ customer -> jsonSerialize ( ) ; return $ this ; }
Set New Customer
43,487
public function getRepositoryFactory ( ) : RepositoryFactoryInterface { if ( null !== $ this -> repositoryFactory ) { return $ this -> repositoryFactory ; } $ factory = new DefaultRepositoryFactory ( ) ; $ factory -> setDefaultRepositoryClassName ( $ this -> getDefaultRepositoryClassName ( ) ) ; return $ factory ; }
Sets the repository factory .
43,488
public static function Utctai ( $ utc1 , $ utc2 , & $ tai1 , & $ tai2 ) { $ big1 ; $ iy ; $ im ; $ id ; $ j ; $ iyt ; $ imt ; $ idt ; $ u1 ; $ u2 ; $ fd ; $ dat0 ; $ dat12 ; $ w ; $ dat24 ; $ dlod ; $ dleap ; $ z1 ; $ z2 ; $ a2 ; $ big1 = ( $ utc1 >= $ utc2 ) ; if ( $ big1 ) { $ u1 = $ utc1 ; $ u2 = $ utc2 ; } else { $ u1 = $ utc2 ; $ u2 = $ utc1 ; } $ j = IAU :: Jd2cal ( $ u1 , $ u2 , $ iy , $ im , $ id , $ fd ) ; if ( $ j != 0 ) return j ; $ j = IAU :: Dat ( $ iy , $ im , $ id , 0.0 , $ dat0 ) ; if ( $ j < 0 ) return $ j ; $ j = IAU :: Dat ( $ iy , $ im , $ id , 0.5 , $ dat12 ) ; if ( $ j < 0 ) return $ j ; $ j = IAU :: Jd2cal ( $ u1 + 1.5 , $ u2 - $ fd , $ iyt , $ imt , $ idt , $ w ) ; if ( $ j != 0 ) return $ j ; $ j = IAU :: Dat ( $ iyt , $ imt , $ idt , 0.0 , $ dat24 ) ; if ( $ j < 0 ) return $ j ; $ dlod = 2.0 * ( $ dat12 - $ dat0 ) ; $ dleap = $ dat24 - ( $ dat0 + $ dlod ) ; $ fd *= ( DAYSEC + $ dleap ) / DAYSEC ; $ fd *= ( DAYSEC + $ dlod ) / DAYSEC ; if ( IAU :: Cal2jd ( $ iy , $ im , $ id , $ z1 , $ z2 ) ) return - 1 ; $ a2 = $ z1 - $ u1 ; $ a2 += $ z2 ; $ a2 += $ fd + $ dat0 / DAYSEC ; if ( $ big1 ) { $ tai1 = $ u1 ; $ tai2 = $ a2 ; } else { $ tai1 = $ a2 ; $ tai2 = $ u1 ; } return $ j ; }
- - - - - - - - - - i a u U t c t a i - - - - - - - - - -
43,489
protected function simpleRoute ( $ name , $ data ) { if ( is_string ( $ data ) ) { return $ this -> map -> get ( $ name , $ data ) ; } return $ this -> createRoute ( $ name , $ data ) ; }
Check if the data is a simple string create a get with it
43,490
protected function setRouteProperties ( Route $ route , array $ data ) { $ methods = get_class_methods ( Route :: class ) ; $ methods = array_diff ( $ methods , [ "allows" , "path" ] ) ; foreach ( $ data as $ method => $ args ) { if ( in_array ( $ method , $ methods ) ) { $ route -> $ method ( $ args ) ; } } return $ route ; }
Parses data array to set route properties
43,491
public function apply ( ModelCriteria $ query ) { if ( ! empty ( $ this -> modifiers ) ) { foreach ( $ this -> modifiers as $ modifier ) { if ( $ this -> hasAllRequiredData ( $ modifier ) ) { $ modifier [ 'property' ] = str_replace ( '/' , '.' , $ modifier [ 'property' ] ) ; if ( strpos ( $ modifier [ 'property' ] , '.' ) !== false ) { $ propertyParts = explode ( '.' , $ modifier [ 'property' ] ) ; $ propertyField = array_pop ( $ propertyParts ) ; $ relationName = array_pop ( $ propertyParts ) ; $ this -> applyModifier ( $ query , $ this -> buildClause ( $ propertyField , $ relationName ) , $ modifier ) ; } else { $ this -> applyModifier ( $ query , $ this -> buildClause ( $ modifier [ 'property' ] , $ query -> getModelShortName ( ) ) , $ modifier ) ; } } } } }
Apply the filter to the ModelQuery
43,492
public static function get ( $ message1 , $ message2 = null , $ n = null ) { $ in = self :: getInstance ( ) ; return $ in -> getText ( $ message1 , $ message2 , $ n ) ; }
Little helper method .
43,493
public static function fromXml ( \ DOMNodeList $ xml ) { $ items = array ( ) ; foreach ( $ xml as $ xmlTag ) { $ items [ ] = Expense :: fromXml ( $ xmlTag ) ; } return new static ( $ items ) ; }
Builds a ExpenseCollection object from XML .
43,494
public static function make ( array $ server = null ) { if ( empty ( $ server ) ) { $ server = $ _SERVER ; } if ( isset ( $ server [ 'REQUEST_URI' ] ) ) { return parse_url ( $ server [ 'REQUEST_URI' ] , PHP_URL_QUERY ) ; } }
Makes a string with Uri query .
43,495
public function onKernelRequest ( GetResponseEvent $ event ) { if ( null === $ module = $ event -> getRequest ( ) -> get ( 'module' ) ) { return ; } if ( ! $ module instanceof ModuleInterface ) { $ module = $ this -> getModularRouter ( ) -> getModuleByRequest ( $ event -> getRequest ( ) ) ; } $ this -> getModuleManager ( ) -> setCurrentModule ( $ module ) ; }
Handles actions before the kernel matches the controller .
43,496
public function createConnection ( array $ config ) { if ( ! isset ( $ config [ 'host' ] ) ) { throw new InvalidArgumentException ( "No host provided." ) ; } $ this -> setHost ( $ config [ 'host' ] ) ; if ( isset ( $ config [ 'headers' ] ) ) { $ this -> setHeaders ( $ config [ 'headers' ] ) ; } return $ this ; }
Initialize connector .
43,497
public function prepare ( array $ query ) { $ client = new Client ; $ this -> client = $ client ; $ this -> request = $ client -> createRequest ( $ this -> prepareMethod ( $ query ) , $ this -> prepareRequestUrl ( $ query ) , [ 'headers' => $ this -> prepareHeaders ( $ query ) , 'body' => $ this -> prepareBody ( $ query ) , ] ) ; return $ this ; }
Prepare a new request for execution .
43,498
protected function prepareRequestUrl ( array $ query ) { $ path = isset ( $ query [ 'from' ] [ 'path' ] ) ? $ query [ 'from' ] [ 'path' ] : null ; $ wheres = isset ( $ query [ 'wheres' ] ) ? $ query [ 'wheres' ] : null ; $ baseUrl = $ this -> host . $ path ; if ( ! is_null ( $ wheres ) ) { return $ baseUrl . '?' . $ wheres ; } return $ baseUrl ; }
Prepare request URL from query .
43,499
protected function prepareBody ( array $ query ) { $ method = isset ( $ query [ 'from' ] [ 'method' ] ) ? $ query [ 'from' ] [ 'method' ] : null ; if ( $ method === 'POST' ) { return isset ( $ query [ 'body' ] ) ? $ query [ 'body' ] : null ; } }
Prepare body from query .