idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
20,300
public function fetchValue ( $ data , SplashRequestContext $ context ) { $ key = $ data [ 'key' ] ; $ compulsory = $ data [ 'compulsory' ] ; $ default = $ data [ 'default' ] ?? null ; return $ context -> getParameter ( $ key , $ compulsory , $ default ) ; }
Returns the value to be injected in this parameter .
20,301
public function index ( NewsRequest $ request ) { $ view = $ this -> response -> theme -> listView ( ) ; if ( $ this -> response -> typeIs ( 'json' ) ) { $ function = camel_case ( 'get-' . $ view ) ; return $ this -> repository -> setPresenter ( \ Litecms \ News \ Repositories \ Presenter \ NewsPresenter :: class ) -> $ function ( ) ; } $ news = $ this -> repository -> paginate ( ) ; return $ this -> response -> title ( trans ( 'news::news.names' ) ) -> view ( 'news::news.index' , true ) -> data ( compact ( 'news' ) ) -> output ( ) ; }
Display a list of news .
20,302
public function show ( NewsRequest $ request , News $ news ) { if ( $ news -> exists ) { $ view = 'news::news.show' ; } else { $ view = 'news::news.new' ; } return $ this -> response -> title ( trans ( 'app.view' ) . ' ' . trans ( 'news::news.name' ) ) -> data ( compact ( 'news' ) ) -> view ( $ view , true ) -> output ( ) ; }
Display news .
20,303
public function edit ( NewsRequest $ request , News $ news ) { return $ this -> response -> title ( trans ( 'app.edit' ) . ' ' . trans ( 'news::news.name' ) ) -> view ( 'news::news.edit' , true ) -> data ( compact ( 'news' ) ) -> output ( ) ; }
Show news for editing .
20,304
public function update ( NewsRequest $ request , News $ news ) { try { $ attributes = $ request -> all ( ) ; $ news -> update ( $ attributes ) ; return $ this -> response -> message ( trans ( 'messages.success.updated' , [ 'Module' => trans ( 'news::news.name' ) ] ) ) -> code ( 204 ) -> status ( 'success' ) -> url ( guard_url ( 'news/news/' . $ news -> getRouteKey ( ) ) ) -> redirect ( ) ; } catch ( Exception $ e ) { return $ this -> response -> message ( $ e -> getMessage ( ) ) -> code ( 400 ) -> status ( 'error' ) -> url ( guard_url ( 'news/news/' . $ news -> getRouteKey ( ) ) ) -> redirect ( ) ; } }
Update the news .
20,305
public function destroy ( NewsRequest $ request , News $ news ) { try { $ news -> delete ( ) ; return $ this -> response -> message ( trans ( 'messages.success.deleted' , [ 'Module' => trans ( 'news::news.name' ) ] ) ) -> code ( 202 ) -> status ( 'success' ) -> url ( guard_url ( 'news/news/0' ) ) -> redirect ( ) ; } catch ( Exception $ e ) { return $ this -> response -> message ( $ e -> getMessage ( ) ) -> code ( 400 ) -> status ( 'error' ) -> url ( guard_url ( 'news/news/' . $ news -> getRouteKey ( ) ) ) -> redirect ( ) ; } }
Remove the news .
20,306
private function purgeExpiredRoutes ( ) { $ expireTag = '' ; foreach ( $ this -> routeProviders as $ routeProvider ) { $ expireTag .= $ routeProvider -> getExpirationTag ( ) ; } $ value = md5 ( $ expireTag ) ; $ urlNodesCacheItem = $ this -> cachePool -> getItem ( 'splashExpireTag' ) ; if ( $ urlNodesCacheItem -> isHit ( ) && $ urlNodesCacheItem -> get ( ) === $ value ) { return ; } $ this -> purgeUrlsCache ( ) ; $ urlNodesCacheItem -> set ( $ value ) ; $ this -> cachePool -> save ( $ urlNodesCacheItem ) ; }
Purges the cache if one of the url providers tells us to .
20,307
public function getSplashActionsList ( ) : array { $ urls = array ( ) ; foreach ( $ this -> routeProviders as $ routeProvider ) { $ tmpUrlList = $ routeProvider -> getUrlsList ( null ) ; $ urls = array_merge ( $ urls , $ tmpUrlList ) ; } return $ urls ; }
Returns the list of all SplashActions . This call is LONG and should be cached .
20,308
private function generateUrlNode ( $ urlsList ) { $ urlNode = new SplashUrlNode ( ) ; foreach ( $ urlsList as $ splashAction ) { $ urlNode -> registerCallback ( $ splashAction ) ; } return $ urlNode ; }
Generates the URLNodes from the list of URLS . URLNodes are a very efficient way to know whether we can access our page or not .
20,309
public function analyzeController ( string $ controllerInstanceName ) : array { $ urlsList = array ( ) ; $ controller = $ this -> container -> get ( $ controllerInstanceName ) ; $ refClass = new \ ReflectionClass ( $ controller ) ; foreach ( $ refClass -> getMethods ( ) as $ refMethod ) { $ title = null ; $ titleAnnotation = $ this -> annotationReader -> getMethodAnnotation ( $ refMethod , Title :: class ) ; if ( $ titleAnnotation !== null ) { $ title = $ titleAnnotation -> getTitle ( ) ; } $ actionAnnotation = $ this -> annotationReader -> getMethodAnnotation ( $ refMethod , Action :: class ) ; if ( $ actionAnnotation !== null ) { $ methodName = $ refMethod -> getName ( ) ; if ( $ methodName === 'index' ) { $ url = $ controllerInstanceName . '/' ; } else { $ url = $ controllerInstanceName . '/' . $ methodName ; } $ parameters = $ this -> parameterFetcherRegistry -> mapParameters ( $ refMethod ) ; $ filters = FilterUtils :: getFilters ( $ refMethod , $ this -> annotationReader ) ; $ urlsList [ ] = new SplashRoute ( $ url , $ controllerInstanceName , $ refMethod -> getName ( ) , $ title , $ refMethod -> getDocComment ( ) , $ this -> getSupportedHttpMethods ( $ refMethod ) , $ parameters , $ filters , $ refClass -> getFileName ( ) ) ; } $ annotations = $ this -> annotationReader -> getMethodAnnotations ( $ refMethod ) ; foreach ( $ annotations as $ annotation ) { if ( ! $ annotation instanceof URL ) { continue ; } $ url = $ annotation -> getUrl ( ) ; if ( preg_match_all ( '/[^{]*{\$this->([^\/]*)}[^{]*/' , $ url , $ output ) ) { foreach ( $ output [ 1 ] as $ param ) { $ value = $ this -> readPrivateProperty ( $ controller , $ param ) ; $ url = str_replace ( '{$this->' . $ param . '}' , $ value , $ url ) ; } } $ url = ltrim ( $ url , '/' ) ; $ parameters = $ this -> parameterFetcherRegistry -> mapParameters ( $ refMethod , $ url ) ; $ filters = FilterUtils :: getFilters ( $ refMethod , $ this -> annotationReader ) ; $ urlsList [ ] = new SplashRoute ( $ url , $ controllerInstanceName , $ refMethod -> getName ( ) , $ title , $ refMethod -> getDocComment ( ) , $ this -> getSupportedHttpMethods ( $ refMethod ) , $ parameters , $ filters , $ refClass -> getFileName ( ) ) ; } } return $ urlsList ; }
Returns an array of SplashRoute for the controller passed in parameter .
20,310
public function update ( UserPolicy $ user , Comment $ comment ) { if ( $ user -> canDo ( 'news.comment.edit' ) && $ user -> isAdmin ( ) ) { return true ; } return $ comment -> user_id == user_id ( ) && $ comment -> user_type == user_type ( ) ; }
Determine if the given user can update the given comment .
20,311
public function destroy ( UserPolicy $ user , Comment $ comment ) { return $ comment -> user_id == user_id ( ) && $ comment -> user_type == user_type ( ) ; }
Determine if the given user can delete the given comment .
20,312
public function getExpirationTag ( ) : string { return implode ( '-/-' , $ this -> controllers ) . ( $ this -> controllerDetector !== null ? $ this -> controllerDetector -> getExpirationTag ( ) : '' ) ; }
Returns a unique tag representing the list of SplashRoutes returned . If the tag changes the cache is flushed by Splash .
20,313
public function toArguments ( SplashRequestContext $ context , array $ parametersMap ) : array { $ arguments = [ ] ; foreach ( $ parametersMap as $ parameter ) { $ fetcherid = $ parameter [ 'fetcherId' ] ; $ data = $ parameter [ 'data' ] ; $ arguments [ ] = $ this -> parameterFetchers [ $ fetcherid ] -> fetchValue ( $ data , $ context ) ; } return $ arguments ; }
Maps data returned by mapParameters to real arguments to be passed to the action .
20,314
public function destroy ( UserPolicy $ user , Category $ category ) { return $ category -> user_id == user_id ( ) && $ category -> user_type == user_type ( ) ; }
Determine if the given user can delete the given category .
20,315
public function view ( UserPolicy $ user , News $ news ) { if ( $ user -> canDo ( 'news.news.view' ) && $ user -> isAdmin ( ) ) { return true ; } return $ news -> user_id == user_id ( ) && $ news -> user_type == user_type ( ) ; }
Determine if the given user can view the news .
20,316
public function destroy ( UserPolicy $ user , News $ news ) { return $ news -> user_id == user_id ( ) && $ news -> user_type == user_type ( ) ; }
Determine if the given user can delete the given news .
20,317
public function edit ( CommentRequest $ request , Comment $ comment ) { return $ this -> response -> title ( trans ( 'app.edit' ) . ' ' . trans ( 'news::comment.name' ) ) -> view ( 'news::comment.edit' , true ) -> data ( compact ( 'comment' ) ) -> output ( ) ; }
Show comment for editing .
20,318
public function view ( UserPolicy $ user , Tag $ tag ) { if ( $ user -> canDo ( 'news.tag.view' ) && $ user -> isAdmin ( ) ) { return true ; } return $ tag -> user_id == user_id ( ) && $ tag -> user_type == user_type ( ) ; }
Determine if the given user can view the tag .
20,319
public function destroy ( UserPolicy $ user , Tag $ tag ) { return $ tag -> user_id == user_id ( ) && $ tag -> user_type == user_type ( ) ; }
Determine if the given user can delete the given tag .
20,320
public function index ( TagRequest $ request ) { $ view = $ this -> response -> theme -> listView ( ) ; if ( $ this -> response -> typeIs ( 'json' ) ) { $ function = camel_case ( 'get-' . $ view ) ; return $ this -> repository -> setPresenter ( \ Litecms \ News \ Repositories \ Presenter \ TagPresenter :: class ) -> $ function ( ) ; } $ tags = $ this -> repository -> paginate ( ) ; return $ this -> response -> title ( trans ( 'news::tag.names' ) ) -> view ( 'news::tag.index' , true ) -> data ( compact ( 'tags' ) ) -> output ( ) ; }
Display a list of tag .
20,321
public function show ( TagRequest $ request , Tag $ tag ) { if ( $ tag -> exists ) { $ view = 'news::tag.show' ; } else { $ view = 'news::tag.new' ; } return $ this -> response -> title ( trans ( 'app.view' ) . ' ' . trans ( 'news::tag.name' ) ) -> data ( compact ( 'tag' ) ) -> view ( $ view , true ) -> output ( ) ; }
Display tag .
20,322
public function delete ( TagRequest $ request , $ type ) { try { $ ids = hashids_decode ( $ request -> input ( 'ids' ) ) ; if ( $ type == 'purge' ) { $ this -> repository -> purge ( $ ids ) ; } else { $ this -> repository -> delete ( $ ids ) ; } return $ this -> response -> message ( trans ( 'messages.success.deleted' , [ 'Module' => trans ( 'news::tag.name' ) ] ) ) -> status ( "success" ) -> code ( 202 ) -> url ( guard_url ( 'news/tag' ) ) -> redirect ( ) ; } catch ( Exception $ e ) { return $ this -> response -> message ( $ e -> getMessage ( ) ) -> status ( "error" ) -> code ( 400 ) -> url ( guard_url ( '/news/tag' ) ) -> redirect ( ) ; } }
Remove multiple tag .
20,323
private function walkArray ( array $ urlParts , ServerRequestInterface $ request , array $ parameters , $ closestWildcardRoute = null ) { $ httpMethod = $ request -> getMethod ( ) ; if ( isset ( $ this -> wildcardCallbacks [ $ httpMethod ] ) ) { $ closestWildcardRoute = $ this -> wildcardCallbacks [ $ httpMethod ] ; $ closestWildcardRoute -> setFilledParameters ( $ parameters ) ; } elseif ( isset ( $ this -> wildcardCallbacks [ '' ] ) ) { $ closestWildcardRoute = $ this -> wildcardCallbacks [ '' ] ; $ closestWildcardRoute -> setFilledParameters ( $ parameters ) ; } if ( ! empty ( $ urlParts ) ) { $ key = array_shift ( $ urlParts ) ; if ( isset ( $ this -> children [ $ key ] ) ) { return $ this -> children [ $ key ] -> walkArray ( $ urlParts , $ request , $ parameters , $ closestWildcardRoute ) ; } foreach ( $ this -> parameterizedChildren as $ varName => $ splashUrlNode ) { if ( isset ( $ parameters [ $ varName ] ) ) { throw new SplashException ( "An error occured while looking at the list URL managed in Splash. In a @URL annotation, the parameter '{$parameters[$varName]}' appears twice. That should never happen" ) ; } $ newParams = $ parameters ; $ newParams [ $ varName ] = $ key ; $ result = $ this -> parameterizedChildren [ $ varName ] -> walkArray ( $ urlParts , $ request , $ newParams , $ closestWildcardRoute ) ; if ( $ result !== null ) { return $ result ; } } return $ closestWildcardRoute ; } else { if ( isset ( $ this -> callbacks [ $ httpMethod ] ) ) { $ route = $ this -> callbacks [ $ httpMethod ] ; $ route -> setFilledParameters ( $ parameters ) ; return $ route ; } elseif ( isset ( $ this -> callbacks [ '' ] ) ) { $ route = $ this -> callbacks [ '' ] ; $ route -> setFilledParameters ( $ parameters ) ; return $ route ; } else { return $ closestWildcardRoute ; } } }
Walks through the nodes to find the callback associated to the URL .
20,324
public function CroppableImageForm ( ) { $ image = $ this -> getCroppableImageObject ( ) ; $ action = FormAction :: create ( 'doSaveCroppableImage' , _t ( 'CroppableImageable.SAVE' , 'Save' ) ) -> setUseButtonTag ( 'true' ) ; if ( ! $ this -> isFrontend ) { $ action -> addExtraClass ( 'ss-ui-action-constructive' ) -> setAttribute ( 'data-icon' , 'accept' ) ; } $ image = null ; if ( $ CroppableImageID = ( int ) $ this -> request -> getVar ( 'SaltedCroppableImageID' ) ) { $ image = SaltedCroppableImage :: get ( ) -> byID ( $ CroppableImageID ) ; } $ image = $ image ? $ image : singleton ( 'SaltedCroppableImage' ) ; $ fields = $ image -> getCMSFields ( ) ; $ title = $ image ? _t ( 'CroppableImageable.EDITIMAGE' , 'Edit Image' ) : _t ( 'CroppableImageable.ADDIMAGE' , 'Add Image' ) ; $ fields -> insertBefore ( HeaderField :: create ( 'CroppableImageHeader' , $ title ) , _t ( 'CroppableImageable.TITLE' , 'Title' ) ) ; $ actions = FieldList :: create ( $ action ) ; $ form = Form :: create ( $ this , 'CroppableImageForm' , $ fields , $ actions ) ; if ( $ image ) { $ form -> loadDataFrom ( $ image ) ; if ( ! empty ( $ this -> folderName ) ) { $ fields -> fieldByName ( 'Root.Main.Original' ) -> setFolderName ( $ this -> folderName ) ; } $ fields -> push ( HiddenField :: create ( 'CropperRatio' ) -> setValue ( $ this -> Ratio ) ) ; $ fields -> push ( HiddenField :: create ( 'ContainerX' ) -> setValue ( $ image -> ContainerX ) ) ; $ fields -> push ( HiddenField :: create ( 'ContainerX' ) -> setValue ( $ image -> ContainerX ) ) ; $ fields -> push ( HiddenField :: create ( 'ContainerY' ) -> setValue ( $ image -> ContainerY ) ) ; $ fields -> push ( HiddenField :: create ( 'ContainerWidth' ) -> setValue ( $ image -> ContainerWidth ) ) ; $ fields -> push ( HiddenField :: create ( 'ContainerHeight' ) -> setValue ( $ image -> ContainerHeight ) ) ; $ fields -> push ( HiddenField :: create ( 'CropperX' ) -> setValue ( $ image -> CropperX ) ) ; $ fields -> push ( HiddenField :: create ( 'CropperY' ) -> setValue ( $ image -> CropperY ) ) ; $ fields -> push ( HiddenField :: create ( 'CropperWidth' ) -> setValue ( $ image -> CropperWidth ) ) ; $ fields -> push ( HiddenField :: create ( 'CropperHeight' ) -> setValue ( $ image -> CropperHeight ) ) ; } $ this -> owner -> extend ( 'updateLinkForm' , $ form ) ; return $ form ; }
The CroppableImageForm for the dialog window
20,325
protected function getConfig ( $ name ) { if ( empty ( $ name ) ) { throw new InvalidArgumentException ( "Script Engine 'name' can not be empty." ) ; } $ engines = $ this -> app [ 'config' ] [ 'df.script' ] ; return array_get ( $ engines , $ name , [ ] ) ; }
Get the configuration for a script engine .
20,326
public function makeEngine ( $ type , array $ script_config = [ ] ) { if ( ! empty ( $ disable = config ( 'df.scripting.disable' ) ) ) { switch ( strtolower ( $ disable ) ) { case 'all' : throw new ServiceUnavailableException ( "All scripting is disabled for this instance." ) ; break ; default : if ( ! empty ( $ type ) && ( false !== stripos ( $ disable , $ type ) ) ) { throw new ServiceUnavailableException ( "Scripting with $type is disabled for this instance." ) ; } break ; } } $ config = $ this -> getConfig ( $ type ) ; if ( isset ( $ this -> types [ $ type ] ) ) { return $ this -> types [ $ type ] -> make ( array_merge ( $ config , $ script_config ) ) ; } throw new InvalidArgumentException ( "Unsupported script engine type '$type'." ) ; }
Make the script engine instance .
20,327
protected static function stripPhpTag ( $ script ) { $ script = trim ( $ script ) ; $ tagOpen = strtolower ( substr ( $ script , 0 , 5 ) ) ; $ tagClose = substr ( $ script , strlen ( $ script ) - 2 ) ; if ( '<?php' === $ tagOpen ) { $ script = substr ( $ script , 5 ) ; } if ( '?>' === $ tagClose ) { $ script = substr ( $ script , 0 , ( strlen ( $ script ) - 2 ) ) ; } return $ script ; }
Removes any <?PHP tags .
20,328
public function filterByAttributeAvId ( $ attributeAvId = null , $ comparison = null ) { if ( is_array ( $ attributeAvId ) ) { $ useMinMax = false ; if ( isset ( $ attributeAvId [ 'min' ] ) ) { $ this -> addUsingAlias ( AttributeTypeAvMetaTableMap :: ATTRIBUTE_AV_ID , $ attributeAvId [ 'min' ] , Criteria :: GREATER_EQUAL ) ; $ useMinMax = true ; } if ( isset ( $ attributeAvId [ 'max' ] ) ) { $ this -> addUsingAlias ( AttributeTypeAvMetaTableMap :: ATTRIBUTE_AV_ID , $ attributeAvId [ 'max' ] , Criteria :: LESS_EQUAL ) ; $ useMinMax = true ; } if ( $ useMinMax ) { return $ this ; } if ( null === $ comparison ) { $ comparison = Criteria :: IN ; } } return $ this -> addUsingAlias ( AttributeTypeAvMetaTableMap :: ATTRIBUTE_AV_ID , $ attributeAvId , $ comparison ) ; }
Filter the query on the attribute_av_id column
20,329
public function filterByAttributeAttributeTypeId ( $ attributeAttributeTypeId = null , $ comparison = null ) { if ( is_array ( $ attributeAttributeTypeId ) ) { $ useMinMax = false ; if ( isset ( $ attributeAttributeTypeId [ 'min' ] ) ) { $ this -> addUsingAlias ( AttributeTypeAvMetaTableMap :: ATTRIBUTE_ATTRIBUTE_TYPE_ID , $ attributeAttributeTypeId [ 'min' ] , Criteria :: GREATER_EQUAL ) ; $ useMinMax = true ; } if ( isset ( $ attributeAttributeTypeId [ 'max' ] ) ) { $ this -> addUsingAlias ( AttributeTypeAvMetaTableMap :: ATTRIBUTE_ATTRIBUTE_TYPE_ID , $ attributeAttributeTypeId [ 'max' ] , Criteria :: LESS_EQUAL ) ; $ useMinMax = true ; } if ( $ useMinMax ) { return $ this ; } if ( null === $ comparison ) { $ comparison = Criteria :: IN ; } } return $ this -> addUsingAlias ( AttributeTypeAvMetaTableMap :: ATTRIBUTE_ATTRIBUTE_TYPE_ID , $ attributeAttributeTypeId , $ comparison ) ; }
Filter the query on the attribute_attribute_type_id column
20,330
public function filterByAttributeAv ( $ attributeAv , $ comparison = null ) { if ( $ attributeAv instanceof \ Thelia \ Model \ AttributeAv ) { return $ this -> addUsingAlias ( AttributeTypeAvMetaTableMap :: ATTRIBUTE_AV_ID , $ attributeAv -> getId ( ) , $ comparison ) ; } elseif ( $ attributeAv instanceof ObjectCollection ) { if ( null === $ comparison ) { $ comparison = Criteria :: IN ; } return $ this -> addUsingAlias ( AttributeTypeAvMetaTableMap :: ATTRIBUTE_AV_ID , $ attributeAv -> toKeyValue ( 'PrimaryKey' , 'Id' ) , $ comparison ) ; } else { throw new PropelException ( 'filterByAttributeAv() only accepts arguments of type \Thelia\Model\AttributeAv or Collection' ) ; } }
Filter the query by a related \ Thelia \ Model \ AttributeAv object
20,331
public function useAttributeAvQuery ( $ relationAlias = null , $ joinType = Criteria :: INNER_JOIN ) { return $ this -> joinAttributeAv ( $ relationAlias , $ joinType ) -> useQuery ( $ relationAlias ? $ relationAlias : 'AttributeAv' , '\Thelia\Model\AttributeAvQuery' ) ; }
Use the AttributeAv relation AttributeAv object
20,332
public function useAttributeAttributeTypeQuery ( $ relationAlias = null , $ joinType = Criteria :: INNER_JOIN ) { return $ this -> joinAttributeAttributeType ( $ relationAlias , $ joinType ) -> useQuery ( $ relationAlias ? $ relationAlias : 'AttributeAttributeType' , '\AttributeType\Model\AttributeAttributeTypeQuery' ) ; }
Use the AttributeAttributeType relation AttributeAttributeType object
20,333
public function getBody ( RequestInterface $ request , $ readerType = null ) { $ data = ( string ) $ request -> getBody ( ) ; $ payload = Payload :: create ( $ data , $ request -> getHeader ( 'Content-Type' ) ) -> setRwType ( $ readerType ) ; return $ this -> processor -> parse ( $ payload ) ; }
Returns the result of the reader for the request
20,334
public function find ( $ path ) { $ imgix = $ this -> serializer -> deserialize ( $ path ) ; if ( $ imgix ) { return file_get_contents ( $ this -> source . $ imgix ) ; } throw new NotLoadableException ; }
Retrieve the Image represented by the given path .
20,335
private function Smtp_Ok ( ) { $ _res = str_replace ( "\r\n" , '' , fgets ( $ this -> Smtp_Socket , 512 ) ) ; if ( ! preg_match ( '/^[23]/' , $ _res ) ) { fputs ( $ this -> Smtp_Socket , "QUIT\r\n" ) ; fgets ( $ this -> Smtp_Socket , 512 ) ; return FALSE ; } return TRUE ; }
check the response status code
20,336
private function Run_Cmd ( $ _cmd , $ _args = '' ) { if ( $ _args != '' ) { if ( $ _cmd == '' ) $ _cmd = $ _args ; else $ _cmd = $ _cmd . " " . $ _args ; } fputs ( $ this -> Smtp_Socket , $ _cmd . "\r\n" ) ; return $ this -> Smtp_Ok ( ) ; }
send a cmd to smtp server
20,337
private function Strip_Comment ( $ _address ) { $ _pattern = "/\([^()]*\)/" ; while ( preg_match ( $ _pattern , $ _address ) ) $ _address = preg_replace ( $ _pattern , '' , $ _address ) ; return $ _address ; }
filter all the comment content
20,338
public function getMenuItems ( ) : array { usort ( $ this -> menuItems , function ( $ a , $ b ) { return $ a -> getOrder ( ) > $ b -> getOrder ( ) ; } ) ; return $ this -> menuItems ; }
Returns the menu items .
20,339
public function removeMenuItem ( MenuItemInterface $ item ) : void { $ key = array_search ( $ item , $ this -> menuItems , true ) ; if ( $ key !== false ) { unset ( $ this -> menuItems [ $ key ] ) ; } }
Removes the specified menu item from this container . If the provided item is not in this container this method does nothing .
20,340
public function getOne ( $ languageCode , $ locale = 'en' ) { $ result = $ this -> has ( $ languageCode , $ locale ) ; if ( ! $ result ) { throw new LanguageNotFoundException ( $ languageCode ) ; } return $ result ; }
Returns one language .
20,341
protected function loadData ( $ locale , $ format ) { if ( ! isset ( $ this -> dataCache [ $ locale ] [ $ format ] ) ) { $ file = sprintf ( '%s/%s/language.' . $ format , $ this -> dataDir , $ locale ) ; if ( ! is_file ( $ file ) ) { throw new \ RuntimeException ( sprintf ( 'Unable to load the language data file "%s"' , $ file ) ) ; } $ this -> dataCache [ $ locale ] [ $ format ] = ( $ format == 'php' ) ? require $ file : file_get_contents ( $ file ) ; } return $ this -> sortData ( $ locale , $ this -> dataCache [ $ locale ] [ $ format ] ) ; }
A lazy - loader that loads data from a PHP file if it is not stored in memory yet .
20,342
public function scopeSearch ( Builder $ query , ? string $ keyword , ? array $ columns = null ) : Builder { return $ this -> setupWildcardQueryFilter ( $ query , $ keyword ?? '' , $ columns ?? $ this -> getSearchableColumns ( ) ) ; }
Search based on keyword .
20,343
public function getMetadata ( $ key = null ) { if ( is_null ( $ this -> metadataCache ) ) { $ this -> metadataCache = json_decode ( $ this -> metadata , true ) ; } if ( is_null ( $ key ) ) { return $ this -> metadataCache ; } if ( isset ( $ this -> metadataCache [ $ key ] ) ) { return $ this -> metadataCache [ $ key ] ; } return null ; }
Getter for the metadata
20,344
public function setMetadata ( $ key , $ value ) { if ( is_null ( $ this -> metadataCache ) ) { $ this -> metadataCache = [ ] ; } $ this -> metadataCache [ $ key ] = $ value ; }
Setter for metadata
20,345
private function isArrayResourceData ( $ data ) { if ( ! is_array ( $ data ) || empty ( $ data ) ) { return false ; } foreach ( $ data as $ datum ) { if ( ! $ this -> isResourceData ( $ datum ) ) { return false ; } } return true ; }
Tests whether the provided data represents an array of resource data or an array of links to resources .
20,346
public function request ( $ method , $ url , array $ data = [ ] ) { return $ this -> request -> send ( $ this -> baseUrl . '/' . $ url , $ method , $ data ) ; }
Send a HTTP request to a given URL with given data .
20,347
public function set ( $ name , $ data = [ ] ) { if ( ! is_array ( $ name ) || ( isset ( $ name [ 0 ] ) && is_string ( $ name [ 0 ] ) ) ) { $ this -> setAt ( $ name , $ data ) ; return $ this ; } $ data = $ name ; if ( ! is_array ( $ data ) ) { throw new ORMException ( 'Invalid bulk data for a document.' ) ; } foreach ( $ data as $ name => $ value ) { $ this -> setAt ( $ name , $ value ) ; } return $ this ; }
Sets one or several properties .
20,348
public function hierarchy ( $ prefix = '' , & $ ignore = [ ] , $ index = false ) { $ hash = spl_object_hash ( $ this ) ; if ( isset ( $ ignore [ $ hash ] ) ) { return false ; } $ ignore [ $ hash ] = true ; $ tree = array_fill_keys ( $ this -> schema ( ) -> relations ( ) , true ) ; $ result = [ ] ; $ habtm = [ ] ; foreach ( $ tree as $ field => $ value ) { $ rel = $ this -> schema ( ) -> relation ( $ field ) ; if ( $ rel -> type ( ) === 'hasManyThrough' ) { $ habtm [ $ field ] = $ rel ; continue ; } if ( ! isset ( $ this -> { $ field } ) ) { continue ; } $ entity = $ this -> __get ( $ field ) ; if ( $ entity ) { $ path = $ prefix ? $ prefix . '.' . $ field : $ field ; if ( $ children = $ entity -> hierarchy ( $ path , $ ignore , true ) ) { $ result += $ children ; } elseif ( $ children !== false ) { $ result [ $ path ] = $ path ; } } } foreach ( $ habtm as $ field => $ rel ) { $ using = $ rel -> through ( ) . '.' . $ rel -> using ( ) ; $ path = $ prefix ? $ prefix . '.' . $ using : $ using ; foreach ( $ result as $ key ) { if ( strpos ( $ key , $ path ) === 0 ) { $ path = $ prefix ? $ prefix . '.' . $ field : $ field ; $ result [ $ path ] = $ path ; } } } return $ index ? $ result : array_values ( $ result ) ; }
Returns all included relations accessible through this entity .
20,349
public static function loadScript ( $ name , $ path = null , $ returnContents = true ) { if ( null !== ( $ script = array_get ( static :: $ libraries , $ name ) ) ) { return $ returnContents ? file_get_contents ( $ script ) : $ script ; } $ script = ltrim ( $ script , ' /' ) ; foreach ( static :: $ libraryPaths as $ libPath ) { $ check = $ libPath . '/' . $ script ; if ( is_file ( $ check ) && is_readable ( $ check ) ) { array_set ( static :: $ libraries , $ name , $ check ) ; return $ returnContents ? file_get_contents ( $ check ) : $ check ; } } if ( $ path ) { if ( is_file ( $ path ) && is_readable ( $ path ) ) { array_set ( static :: $ libraries , $ name , $ path ) ; return $ returnContents ? file_get_contents ( $ path ) : $ path ; } } return false ; }
Look through the known paths for a particular script . Returns full path to script file .
20,350
protected static function getLibrary ( $ id , $ file = null ) { if ( null !== $ file || array_key_exists ( $ id , static :: $ libraries ) ) { $ file = $ file ? : static :: $ libraries [ $ id ] ; foreach ( static :: $ libraryPaths as $ name => $ path ) { $ filePath = $ path . DIRECTORY_SEPARATOR . $ file ; if ( file_exists ( $ filePath ) && is_readable ( $ filePath ) ) { return file_get_contents ( $ filePath , 'r' ) ; } } } throw new \ InvalidArgumentException ( 'The library id "' . $ id . '" could not be located.' ) ; }
Locates and loads a library returning the contents
20,351
protected function makeJsonSafe ( $ data , $ base64 = true ) { if ( is_array ( $ data ) ) { foreach ( $ data as $ key => $ value ) { $ data [ $ key ] = $ this -> makeJsonSafe ( $ value , $ base64 ) ; } } if ( ! $ this -> isJsonEncodable ( $ data ) ) { if ( true === $ base64 ) { return 'base64:' . base64_encode ( $ data ) ; } else { return '--non-parsable-data--' ; } } return $ data ; }
Base64 encodes any string or array of strings that cannot be JSON encoded .
20,352
protected function isJsonEncodable ( $ data ) { if ( ! is_array ( $ data ) ) { $ data = [ $ data ] ; } $ json = json_encode ( $ data , JSON_UNESCAPED_SLASHES ) ; if ( $ json === false ) { return false ; } return true ; }
Checks to see if a string can be json encoded .
20,353
private function _exec ( $ params ) { $ params [ 'key' ] = $ this -> _config [ 'api_key' ] ; $ params = json_encode ( $ params ) ; $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_USERAGENT , 'Mandrill-PHP/1.0.52' ) ; curl_setopt ( $ ch , CURLOPT_POST , true ) ; if ( ! ini_get ( 'safe_mode' ) && ! ini_get ( 'open_basedir' ) ) { curl_setopt ( $ ch , CURLOPT_FOLLOWLOCATION , true ) ; } curl_setopt ( $ ch , CURLOPT_HEADER , false ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ ch , CURLOPT_CONNECTTIMEOUT , 30 ) ; curl_setopt ( $ ch , CURLOPT_TIMEOUT , 600 ) ; curl_setopt ( $ ch , CURLOPT_SSL_VERIFYPEER , false ) ; curl_setopt ( $ ch , CURLOPT_URL , 'https://mandrillapp.com/api/1.0/messages/send.json' ) ; curl_setopt ( $ ch , CURLOPT_HTTPHEADER , array ( 'Content-Type: application/json' ) ) ; curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ params ) ; curl_setopt ( $ ch , CURLOPT_VERBOSE , false ) ; $ response_body = curl_exec ( $ ch ) ; if ( curl_error ( $ ch ) ) { throw new Exception ( "API call to messages/send failed: " . curl_error ( $ ch ) ) ; } $ result = json_decode ( $ response_body , true ) ; if ( $ result === null ) throw new Exception ( 'We were unable to decode the JSON response from the Mandrill API: ' . $ response_body ) ; return $ result ; }
Sending API request
20,354
public function saving ( Eloquent $ model ) : void { $ keyword = Keyword :: make ( $ model -> getAttribute ( 'name' ) ) ; if ( $ keyword -> searchIn ( [ 'guest' ] ) !== false ) { throw new InvalidArgumentException ( "Role [{$keyword->getValue()}] is not allowed to be used!" ) ; } }
On saving observer .
20,355
protected function isRestoringModel ( Eloquent $ model ) : bool { if ( ! $ model -> isSoftDeleting ( ) ) { return false ; } $ deleted = $ model -> getDeletedAtColumn ( ) ; return \ is_null ( $ model -> getAttribute ( $ deleted ) ) && ! \ is_null ( $ model -> getOriginal ( $ deleted ) ) ; }
Is restoring model .
20,356
public function register ( ) { $ this -> registerUploadPath ( ) ; $ this -> registerAssetPath ( ) ; $ this -> registerUploadService ( ) ; $ this -> registerDownloadService ( ) ; $ this -> registerCommands ( ) ; }
Registers the service provider
20,357
protected function validate ( Model $ model ) { $ attributes = $ model -> getAttributes ( ) ; $ messages = isset ( $ model -> validationMessages ) ? $ model -> validationMessages : [ ] ; $ validator = $ this -> factory -> make ( $ attributes , $ model -> rules , $ messages ) ; if ( $ validator -> fails ( ) ) { throw new ValidationException ( $ validator -> getMessageBag ( ) ) ; } if ( method_exists ( $ model , 'validate' ) ) { $ model -> validate ( ) ; } }
Validate the given model .
20,358
protected function resolveSearchKeywords ( string $ keyword ) : array { $ basic = [ ] ; $ advanced = [ ] ; $ tags = \ array_map ( function ( $ value ) { [ $ tag , ] = \ explode ( ':' , $ value , 2 ) ; return "{$tag}:" ; } , \ array_keys ( $ this -> getSearchableRules ( ) ) ) ; if ( \ preg_match_all ( '/([\w]+:\"[\w\s]*\"|[\w]+:[\w\S]+|[\w\S]+)\s?/' , $ keyword , $ keywords ) ) { foreach ( $ keywords [ 1 ] as $ index => $ keyword ) { if ( ! Str :: startsWith ( $ keyword , $ tags ) ) { \ array_push ( $ basic , $ keyword ) ; } else { \ array_push ( $ advanced , $ keyword ) ; } } } return [ 'basic' => \ implode ( ' ' , $ basic ) , 'advanced' => $ advanced , ] ; }
Resolve search keywords .
20,359
public function loadNodeCache ( $ nID = - 3 , $ nCache = [ ] ) { if ( sizeof ( $ nCache ) > 0 ) { if ( isset ( $ nCache [ "pID" ] ) ) { $ this -> parentID = $ nCache [ "pID" ] ; } if ( isset ( $ nCache [ "pOrd" ] ) ) { $ this -> parentOrd = $ nCache [ "pOrd" ] ; } if ( isset ( $ nCache [ "opts" ] ) ) { $ this -> nodeOpts = $ nCache [ "opts" ] ; } if ( isset ( $ nCache [ "type" ] ) ) { $ this -> nodeType = $ nCache [ "type" ] ; } if ( isset ( $ nCache [ "branch" ] ) ) { $ this -> dataBranch = $ nCache [ "branch" ] ; } if ( isset ( $ nCache [ "store" ] ) ) { $ this -> dataStore = $ nCache [ "store" ] ; } if ( isset ( $ nCache [ "set" ] ) ) { $ this -> responseSet = $ nCache [ "set" ] ; } if ( isset ( $ nCache [ "def" ] ) ) { $ this -> defaultVal = $ nCache [ "def" ] ; } } return true ; }
maybe initialize this way to lighten the tree s load? ...
20,360
public function getTblFldTypes ( $ tbl ) { $ flds = [ ] ; if ( isset ( $ this -> fldTypes [ $ tbl ] ) && sizeof ( $ this -> fldTypes [ $ tbl ] ) > 0 ) { $ flds = $ this -> fldTypes [ $ tbl ] ; } else { $ tblRow = SLTables :: where ( 'TblName' , $ tbl ) -> first ( ) ; if ( $ tblRow ) { $ chk = SLFields :: where ( 'FldTable' , $ tblRow -> TblID ) -> orderBy ( 'FldOrd' , 'asc' ) -> get ( ) ; if ( $ chk -> isNotEmpty ( ) ) { foreach ( $ chk as $ fldRow ) { $ flds [ $ tblRow -> TblAbbr . $ fldRow -> FldName ] = $ fldRow -> FldType ; } } } } return $ flds ; }
not limited to loaded database
20,361
public function checkSystemInit ( ) { if ( ! session ( ) -> has ( 'chkSysInit' ) || $ GLOBALS [ "SL" ] -> REQ -> has ( 'refresh' ) ) { $ sysChk = User :: select ( 'id' ) -> get ( ) ; if ( $ sysChk -> isEmpty ( ) ) { return $ this -> freshUser ( $ GLOBALS [ "SL" ] -> REQ ) ; } $ sysChk = SLDatabases :: select ( 'DbID' ) -> where ( 'DbUser' , '>' , 0 ) -> get ( ) ; if ( $ sysChk -> isEmpty ( ) ) { return $ this -> redir ( '/fresh/database' , true ) ; } if ( ! $ this -> chkHasTreeOne ( ) ) { return $ this -> redir ( '/fresh/survey' , true ) ; } $ survInst = new SurvLoopInstaller ; $ survInst -> checkSysInit ( ) ; session ( ) -> put ( 'chkSysInit' , 1 ) ; } return '' ; }
Check For Basic System Setup First
20,362
protected function isPageFirstTime ( $ currPage = '' ) { if ( trim ( $ currPage ) == '' ) { $ currPage = $ this -> v [ "currPage" ] [ 0 ] ; } $ chk = SLUsersActivity :: where ( 'UserActUser' , Auth :: user ( ) -> id ) -> where ( 'UserActCurrPage' , 'LIKE' , '%' . $ currPage ) -> get ( ) ; if ( $ chk -> isNotEmpty ( ) ) { return false ; } return true ; }
Is this the first time this user has visited the current page?
20,363
protected function doublecheckSurvTables ( ) { if ( ! session ( ) -> has ( 'doublecheckSurvTables' ) ) { $ chks = [ ] ; $ chks [ ] = "ALTER TABLE `SL_Tree` CHANGE `TreeRootURL` `TreeSlug` VARCHAR(255)" ; $ chks [ ] = "ALTER TABLE `SL_Tree` ADD `TreeOpts` INT(11) DEFAULT 1 AFTER `TreeCoreTable`" ; $ chks [ ] = "ALTER TABLE `SL_DesignTweaks` ADD `TweakUniqueStr` INT(11) DEFAULT NULL AFTER `TweakVersionAB`" ; $ chks [ ] = "ALTER TABLE `SL_DesignTweaks` ADD `TweakIsMobile` VARCHAR(50) DEFAULT NULL AFTER " . "`TweakUniqueStr`" ; ob_start ( ) ; try { foreach ( $ chks as $ chk ) { DB :: select ( $ chk ) ; } } catch ( QueryException $ e ) { } ob_end_clean ( ) ; session ( ) -> put ( 'doublecheckSurvTables' , 1 ) ; } return true ; }
this should really be done using migrations includes SurvLoop database changes since Feb 15 2017
20,364
public function runUpdate ( Request $ request ) { $ user = User :: find ( Auth :: id ( ) ) ; $ this -> validate ( $ request , [ 'old' => 'required' , 'password' => 'required|min:8|confirmed' , ] ) ; if ( Auth :: attempt ( [ 'name' => $ user -> name , 'password' => $ request -> old ] ) ) { $ user -> fill ( [ 'password' => bcrypt ( $ request -> password ) ] ) -> save ( ) ; $ request -> session ( ) -> flash ( 'success' , 'Your password has been changed.' ) ; return redirect ( '/my-profile' ) ; } $ request -> session ( ) -> flash ( 'failure' , 'Your password has not been changed.' ) ; return redirect ( '/my-profile' ) ; }
Update the password for the user .
20,365
protected function encode ( $ data ) { $ data = [ '<?php' , '' , 'return ' . $ this -> render ( $ data , 0 ) . ';' , ] ; return implode ( Data :: LE , $ data ) ; }
Utility Method to serialize the given data
20,366
public function transform ( $ date ) { if ( ! $ date instanceof DateTime ) { $ date = new DateTime ( $ date ) ; } $ current = new DateTime ( 'now' ) ; if ( $ this -> isToday ( $ date ) ) { return $ this -> trans ( 'Today' ) ; } if ( $ this -> isYesterday ( $ date ) ) { return $ this -> trans ( 'Yesterday' ) ; } if ( $ this -> isTomorrow ( $ date ) ) { return $ this -> trans ( 'Tomorrow' ) ; } if ( $ this -> isNextWeek ( $ date ) ) { return $ this -> trans ( 'Next %weekday%' , [ '%weekday%' => $ date -> format ( 'l' ) ] ) ; } if ( $ this -> isLastWeek ( $ date ) ) { return $ this -> trans ( 'Last %weekday%' , [ '%weekday%' => $ date -> format ( 'l' ) ] ) ; } if ( $ this -> isThisYear ( $ date ) ) { return $ date -> format ( 'F j' ) ; } return $ date -> format ( 'F j, Y' ) ; }
Transforms the given date into a human - readable date .
20,367
public function copy ( $ deepCopy = false ) { $ clazz = get_class ( $ this ) ; $ copyObj = new $ clazz ( ) ; $ this -> copyInto ( $ copyObj , $ deepCopy ) ; return $ copyObj ; }
Makes a copy of this object that will be inserted as a new row in table when saved . It creates a new object filling in the simple attributes but skipping any primary keys that are defined for the table .
20,368
public function setAttribute ( ChildAttribute $ v = null ) { if ( $ v === null ) { $ this -> setAttributeId ( NULL ) ; } else { $ this -> setAttributeId ( $ v -> getId ( ) ) ; } $ this -> aAttribute = $ v ; if ( $ v !== null ) { $ v -> addAttributeAttributeType ( $ this ) ; } return $ this ; }
Declares an association between this object and a ChildAttribute object .
20,369
public function getAttribute ( ConnectionInterface $ con = null ) { if ( $ this -> aAttribute === null && ( $ this -> attribute_id !== null ) ) { $ this -> aAttribute = AttributeQuery :: create ( ) -> findPk ( $ this -> attribute_id , $ con ) ; } return $ this -> aAttribute ; }
Get the associated ChildAttribute object
20,370
public function getAttributeType ( ConnectionInterface $ con = null ) { if ( $ this -> aAttributeType === null && ( $ this -> attribute_type_id !== null ) ) { $ this -> aAttributeType = ChildAttributeTypeQuery :: create ( ) -> findPk ( $ this -> attribute_type_id , $ con ) ; } return $ this -> aAttributeType ; }
Get the associated ChildAttributeType object
20,371
public function initAttributeTypeAvMetas ( $ overrideExisting = true ) { if ( null !== $ this -> collAttributeTypeAvMetas && ! $ overrideExisting ) { return ; } $ this -> collAttributeTypeAvMetas = new ObjectCollection ( ) ; $ this -> collAttributeTypeAvMetas -> setModel ( '\AttributeType\Model\AttributeTypeAvMeta' ) ; }
Initializes the collAttributeTypeAvMetas collection .
20,372
public function getAttributeTypeAvMetas ( $ criteria = null , ConnectionInterface $ con = null ) { $ partial = $ this -> collAttributeTypeAvMetasPartial && ! $ this -> isNew ( ) ; if ( null === $ this -> collAttributeTypeAvMetas || null !== $ criteria || $ partial ) { if ( $ this -> isNew ( ) && null === $ this -> collAttributeTypeAvMetas ) { $ this -> initAttributeTypeAvMetas ( ) ; } else { $ collAttributeTypeAvMetas = ChildAttributeTypeAvMetaQuery :: create ( null , $ criteria ) -> filterByAttributeAttributeType ( $ this ) -> find ( $ con ) ; if ( null !== $ criteria ) { if ( false !== $ this -> collAttributeTypeAvMetasPartial && count ( $ collAttributeTypeAvMetas ) ) { $ this -> initAttributeTypeAvMetas ( false ) ; foreach ( $ collAttributeTypeAvMetas as $ obj ) { if ( false == $ this -> collAttributeTypeAvMetas -> contains ( $ obj ) ) { $ this -> collAttributeTypeAvMetas -> append ( $ obj ) ; } } $ this -> collAttributeTypeAvMetasPartial = true ; } reset ( $ collAttributeTypeAvMetas ) ; return $ collAttributeTypeAvMetas ; } if ( $ partial && $ this -> collAttributeTypeAvMetas ) { foreach ( $ this -> collAttributeTypeAvMetas as $ obj ) { if ( $ obj -> isNew ( ) ) { $ collAttributeTypeAvMetas [ ] = $ obj ; } } } $ this -> collAttributeTypeAvMetas = $ collAttributeTypeAvMetas ; $ this -> collAttributeTypeAvMetasPartial = false ; } } return $ this -> collAttributeTypeAvMetas ; }
Gets an array of ChildAttributeTypeAvMeta objects which contain a foreign key that references this object .
20,373
public function countAttributeTypeAvMetas ( Criteria $ criteria = null , $ distinct = false , ConnectionInterface $ con = null ) { $ partial = $ this -> collAttributeTypeAvMetasPartial && ! $ this -> isNew ( ) ; if ( null === $ this -> collAttributeTypeAvMetas || null !== $ criteria || $ partial ) { if ( $ this -> isNew ( ) && null === $ this -> collAttributeTypeAvMetas ) { return 0 ; } if ( $ partial && ! $ criteria ) { return count ( $ this -> getAttributeTypeAvMetas ( ) ) ; } $ query = ChildAttributeTypeAvMetaQuery :: create ( null , $ criteria ) ; if ( $ distinct ) { $ query -> distinct ( ) ; } return $ query -> filterByAttributeAttributeType ( $ this ) -> count ( $ con ) ; } return count ( $ this -> collAttributeTypeAvMetas ) ; }
Returns the number of related AttributeTypeAvMeta objects .
20,374
public function addAttributeTypeAvMeta ( ChildAttributeTypeAvMeta $ l ) { if ( $ this -> collAttributeTypeAvMetas === null ) { $ this -> initAttributeTypeAvMetas ( ) ; $ this -> collAttributeTypeAvMetasPartial = true ; } if ( ! in_array ( $ l , $ this -> collAttributeTypeAvMetas -> getArrayCopy ( ) , true ) ) { $ this -> doAddAttributeTypeAvMeta ( $ l ) ; } return $ this ; }
Method called to associate a ChildAttributeTypeAvMeta object to this object through the ChildAttributeTypeAvMeta foreign key attribute .
20,375
public function getAttributeTypeAvMetasJoinAttributeAv ( $ criteria = null , $ con = null , $ joinBehavior = Criteria :: LEFT_JOIN ) { $ query = ChildAttributeTypeAvMetaQuery :: create ( null , $ criteria ) ; $ query -> joinWith ( 'AttributeAv' , $ joinBehavior ) ; return $ this -> getAttributeTypeAvMetas ( $ query , $ con ) ; }
If this collection has already been initialized with an identical criteria it returns the collection . Otherwise if this AttributeAttributeType is new it will return an empty collection ; or if this AttributeAttributeType has previously been saved it will retrieve related AttributeTypeAvMetas from storage .
20,376
public function getClient ( ) { $ client = $ this -> reduceFirst ( function ( SearchProviderInterface $ provider ) { return $ provider -> getClient ( ) ; } ) ; if ( null === $ client ) { throw new \ RuntimeException ( 'No provider was able to return a client' ) ; } return $ client ; }
Return the client object
20,377
public function getIndex ( $ indexName ) { return $ this -> reduceFirst ( function ( SearchProviderInterface $ provider ) use ( $ indexName ) { return $ provider -> getIndex ( $ this -> indexNamePrefix . $ indexName ) ; } ) ; }
Return the index object
20,378
public function createDocument ( $ document , $ uid , $ indexName = '' , $ indexType = '' ) { return new DocumentReference ( $ document , $ uid , $ this -> indexNamePrefix . $ indexName , $ indexType ) ; }
Create a document
20,379
public function addDocument ( $ indexName , $ indexType , $ document , $ uid ) { if ( "" === $ indexName && $ document instanceof DocumentReference ) { $ indexName = $ document -> getIndexName ( ) ; } else { $ indexName = $ this -> indexNamePrefix . $ indexName ; } $ this -> mapProviders ( function ( SearchProviderInterface $ provider ) use ( $ document , $ uid , $ indexName , $ indexType ) { $ provider -> addDocument ( $ document , $ uid , $ indexName , $ indexType ) ; } ) ; }
Add a document to the index
20,380
public function addDocuments ( $ documents , $ indexName = '' , $ indexType = '' ) { if ( "" === $ indexName && isset ( $ documents [ 0 ] ) ) { $ indexName = $ documents [ 0 ] -> getIndexName ( ) ; } else { $ indexName = $ this -> indexNamePrefix . $ indexName ; } $ this -> mapProviders ( function ( SearchProviderInterface $ provider ) use ( $ documents , $ indexName , $ indexType ) { $ documents = array_map ( function ( DocumentReference $ document ) use ( $ provider ) { return $ provider -> createDocument ( $ document -> getDocument ( ) , $ document -> getUid ( ) , $ document -> getIndexName ( ) , $ document -> getIndexType ( ) ) ; } , $ documents ) ; $ provider -> addDocuments ( $ documents , $ indexName , $ indexType ) ; } ) ; }
Add a collection of documents at once
20,381
public function deleteDocument ( $ indexName , $ indexType , $ uid ) { $ this -> mapProviders ( function ( SearchProviderInterface $ provider ) use ( $ indexName , $ indexType , $ uid ) { $ provider -> deleteDocument ( $ this -> indexNamePrefix . $ indexName , $ indexType , $ uid ) ; } ) ; }
delete a document from the index
20,382
public function deleteIndex ( $ indexName ) { $ this -> mapProviders ( function ( SearchProviderInterface $ provider ) use ( $ indexName ) { try { $ provider -> deleteIndex ( $ this -> indexNamePrefix . $ indexName ) ; } catch ( \ Exception $ e ) { } } ) ; }
Delete an index
20,383
public function handle ( $ command , Closure $ next ) { if ( property_exists ( $ command , 'rules' ) && is_array ( $ command -> rules ) ) { $ this -> validate ( $ command ) ; } return $ next ( $ command ) ; }
Validate the command before execution .
20,384
protected function validate ( $ command ) { if ( method_exists ( $ command , 'validate' ) ) { $ command -> validate ( ) ; } $ messages = property_exists ( $ command , 'validationMessages' ) ? $ command -> validationMessages : [ ] ; $ validator = $ this -> factory -> make ( $ this -> getData ( $ command ) , $ command -> rules , $ messages ) ; if ( $ validator -> fails ( ) ) { throw new ValidationException ( $ validator -> getMessageBag ( ) ) ; } }
Validate the command .
20,385
protected function getData ( $ command ) { $ data = [ ] ; foreach ( ( new ReflectionClass ( $ command ) ) -> getProperties ( ReflectionProperty :: IS_PUBLIC ) as $ property ) { $ name = $ property -> getName ( ) ; $ value = $ property -> getValue ( $ command ) ; if ( in_array ( $ name , [ 'rules' , 'validationMessages' ] , true ) ) { continue ; } $ data [ $ name ] = $ value ; } return $ data ; }
Get the data to be validated .
20,386
private function send ( $ message ) { $ url = self :: BASE_URI . $ this -> token . '/sendMessage' ; $ data = [ 'chat_id' => $ this -> chatId , 'text' => $ message , 'disable_web_page_preview' => true ] ; if ( preg_match ( '/<[^<]+>/' , $ data [ 'text' ] ) !== false ) { $ data [ 'parse_mode' ] = 'HTML' ; } if ( $ this -> useCurl === true && extension_loaded ( 'curl' ) ) { $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_URL , $ url ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ ch , CURLOPT_POSTFIELDS , http_build_query ( $ data ) ) ; curl_setopt ( $ ch , CURLOPT_SSL_VERIFYPEER , $ this -> verifyPeer ) ; curl_setopt ( $ ch , CURLOPT_TIMEOUT , $ this -> timeout ) ; $ result = curl_exec ( $ ch ) ; if ( ! $ result ) { throw new \ RuntimeException ( 'Request to Telegram API failed: ' . curl_error ( $ ch ) ) ; } } else { $ opts = [ 'http' => [ 'method' => 'POST' , 'header' => 'Content-type: application/x-www-form-urlencoded' , 'content' => http_build_query ( $ data ) , 'timeout' => $ this -> timeout , ] , 'ssl' => [ 'verify_peer' => $ this -> verifyPeer , 'verify_peer_name' => $ this -> verifyPeer , ] , ] ; $ result = @ file_get_contents ( $ url , false , stream_context_create ( $ opts ) ) ; if ( ! $ result ) { $ error = error_get_last ( ) ; if ( isset ( $ error [ 'message' ] ) ) { throw new \ RuntimeException ( 'Request to Telegram API failed: ' . $ error [ 'message' ] ) ; } throw new \ RuntimeException ( 'Request to Telegram API failed' ) ; } } $ result = json_decode ( $ result , true ) ; if ( isset ( $ result [ 'ok' ] ) && $ result [ 'ok' ] === true ) { return true ; } if ( isset ( $ result [ 'description' ] ) ) { throw new \ RuntimeException ( 'Telegram API error: ' . $ result [ 'description' ] ) ; } return false ; }
Send sendMessage request to Telegram Bot API
20,387
protected function getParameter ( $ key , $ type = Validate :: TYPE_STRING , array $ filter = array ( ) , $ title = null , $ required = true ) { $ parameter = $ this -> request -> getUri ( ) -> getParameter ( $ key ) ; if ( isset ( $ parameter ) ) { return $ this -> validate -> apply ( $ parameter , $ type , $ filter , $ title , $ required ) ; } else { return null ; } }
Returns a parameter from the query fragment of the request url
20,388
protected function setBody ( $ data ) { $ this -> responseWriter -> setBody ( $ this -> response , $ data , $ this -> request ) ; }
Method to set a response body
20,389
protected function forward ( $ source , array $ parameters = array ( ) ) { $ path = $ this -> reverseRouter -> getPath ( $ source , $ parameters ) ; if ( $ path !== null ) { $ this -> request -> setUri ( $ this -> request -> getUri ( ) -> withPath ( $ path ) ) ; $ this -> loader -> load ( $ this -> request , $ this -> response , $ this -> context ) ; } else { throw new RuntimeException ( 'Could not find route for source ' . $ source ) ; } }
Forwards the request to another controller
20,390
protected function redirect ( $ source , array $ parameters = array ( ) , $ code = 307 ) { if ( $ source instanceof Url ) { $ url = $ source -> toString ( ) ; } elseif ( filter_var ( $ source , FILTER_VALIDATE_URL ) ) { $ url = $ source ; } else { $ url = $ this -> reverseRouter -> getUrl ( $ source , $ parameters ) ; } if ( $ code == 301 ) { throw new StatusCode \ MovedPermanentlyException ( $ url ) ; } elseif ( $ code == 302 ) { throw new StatusCode \ FoundException ( $ url ) ; } elseif ( $ code == 307 ) { throw new StatusCode \ TemporaryRedirectException ( $ url ) ; } else { throw new RuntimeException ( 'Invalid redirect status code' ) ; } }
Throws an redirect exception which sends an Location header . If source is not an url the reverse router is used to determine the url
20,391
public function generateRemotingApi ( ) { $ list = array ( ) ; foreach ( $ this -> remotingBundles as $ bundle ) { $ bundleRef = new \ ReflectionClass ( $ bundle ) ; $ controllerDir = new Finder ( ) ; $ controllerDir -> files ( ) -> in ( dirname ( $ bundleRef -> getFileName ( ) ) . '/Controller/' ) -> name ( '/.*Controller\.php$/' ) ; foreach ( $ controllerDir as $ controllerFile ) { $ controller = $ bundleRef -> getNamespaceName ( ) . "\\Controller\\" . substr ( $ controllerFile -> getFilename ( ) , 0 , - 4 ) ; $ controllerRef = new \ ReflectionClass ( $ controller ) ; foreach ( $ controllerRef -> getMethods ( \ ReflectionMethod :: IS_PUBLIC ) as $ method ) { $ methodDirectAnnotation = $ this -> annoReader -> getMethodAnnotation ( $ method , 'Tpg\ExtjsBundle\Annotation\Direct' ) ; if ( $ methodDirectAnnotation !== null ) { $ nameSpace = str_replace ( "\\" , "." , $ bundleRef -> getNamespaceName ( ) ) ; $ className = str_replace ( "Controller" , "" , $ controllerRef -> getShortName ( ) ) ; $ methodName = str_replace ( "Action" , "" , $ method -> getName ( ) ) ; $ list [ $ nameSpace ] [ $ className ] [ ] = array ( 'name' => $ methodName , 'len' => count ( $ method -> getParameters ( ) ) ) ; } } } } return $ list ; }
Generate Remote API from a list of controllers
20,392
protected function tryToGetJoinColumnNameOfMappedBy ( $ annotation ) { $ annotation = $ this -> tryToGetJoinColumnAnnotationOfMappedBy ( $ annotation ) ; if ( $ annotation !== null ) { if ( $ annotation instanceof JoinColumn ) { return $ annotation -> name ; } else if ( $ annotation instanceof JoinColumns ) { if ( count ( $ annotation -> value ) > 1 ) { throw new \ Exception ( 'Multiple foreign key is not supported' ) ; } return $ annotation -> value [ 0 ] -> name ; } } return '' ; }
Get the join column name .
20,393
protected function tryToGetJoinColumnAnnotationOfMappedBy ( $ annotation ) { $ result = null ; if ( $ annotation -> targetEntity && $ annotation -> mappedBy ) { $ result = $ this -> getAnnotation ( $ annotation -> targetEntity , $ annotation -> mappedBy , 'Doctrine\ORM\Mapping\JoinColumn' ) ; if ( $ result === null ) { $ result = $ this -> getAnnotation ( $ annotation -> targetEntity , $ annotation -> mappedBy , 'Doctrine\ORM\Mapping\JoinColumns' ) ; } } return $ result ; }
Get the join column annotation
20,394
public function getEntityColumnType ( $ entity , $ property ) { $ classRef = new \ ReflectionClass ( $ entity ) ; if ( $ classRef -> hasProperty ( $ property ) ) { $ propertyRef = $ classRef -> getProperty ( $ property ) ; $ columnRef = $ this -> annoReader -> getPropertyAnnotation ( $ propertyRef , 'Doctrine\ORM\Mapping\Column' ) ; } else { foreach ( $ classRef -> getProperties ( ) as $ propertyRef ) { $ columnRef = $ this -> annoReader -> getPropertyAnnotation ( $ propertyRef , 'Doctrine\ORM\Mapping\Column' ) ; if ( $ columnRef -> name == $ property ) { break ; } else { $ columnRef = null ; } } } if ( $ columnRef === null ) { $ idRef = $ this -> annoReader -> getPropertyAnnotation ( $ propertyRef , 'Doctrine\ORM\Mapping\Id' ) ; if ( $ idRef !== null ) { return "int" ; } else { return "string" ; } } else { return $ this -> getColumnType ( $ columnRef -> type ) ; } }
Get Column Type of a model .
20,395
protected function getValidator ( $ name , $ annotation ) { $ validate = array ( ) ; switch ( $ name ) { case 'NotBlank' : case 'NotNull' : $ validate [ 'type' ] = "presence" ; break ; case 'Email' : $ validate [ 'type' ] = "email" ; break ; case 'Length' : $ validate [ 'type' ] = "length" ; $ validate [ 'max' ] = ( int ) $ annotation -> max ; $ validate [ 'min' ] = ( int ) $ annotation -> min ; break ; case 'Regex' : if ( $ annotation -> match ) { $ validate [ 'type' ] = "format" ; $ validate [ 'matcher' ] [ 'skipEncode' ] = true ; $ validate [ 'matcher' ] [ 'value' ] = $ annotation -> pattern ; } break ; case 'MaxLength' : case 'MinLength' : $ validate [ 'type' ] = "length" ; if ( $ name == "MaxLength" ) { $ validate [ 'max' ] = ( int ) $ annotation -> limit ; } else { $ validate [ 'min' ] = ( int ) $ annotation -> limit ; } break ; case 'Choice' : $ validate [ 'type' ] = "inclusion" ; $ validate [ 'list' ] = $ annotation -> choices ; break ; default : $ validate [ 'type' ] = strtolower ( $ name ) ; $ validate += get_object_vars ( $ annotation ) ; break ; } return $ validate ; }
Get the Ext JS Validator
20,396
public function getModelName ( $ entity ) { $ classRef = new \ ReflectionClass ( $ entity ) ; $ classModelAnnotation = $ this -> annoReader -> getClassAnnotation ( $ classRef , 'Tpg\ExtjsBundle\Annotation\Model' ) ; if ( $ classModelAnnotation !== null ) { if ( $ classModelAnnotation -> name ) { return $ classModelAnnotation -> name ; } else { return str_replace ( "\\" , "." , $ classRef -> getName ( ) ) ; } } return null ; }
Get model name of an entity
20,397
public function route ( RequestInterface $ request , ResponseInterface $ response , Context $ context = null ) { $ this -> level ++ ; $ this -> eventDispatcher -> dispatch ( Event :: REQUEST_INCOMING , new RequestIncomingEvent ( $ request ) ) ; if ( $ context === null ) { $ factory = $ this -> config -> get ( 'psx_context_factory' ) ; if ( $ factory instanceof \ Closure ) { $ context = $ factory ( ) ; } else { $ context = new Context ( ) ; } } try { $ this -> loader -> load ( $ request , $ response , $ context ) ; } catch ( StatusCode \ NotModifiedException $ e ) { $ response -> setStatus ( $ e -> getStatusCode ( ) ) ; $ response -> setBody ( new StringStream ( ) ) ; } catch ( StatusCode \ RedirectionException $ e ) { $ response -> setStatus ( $ e -> getStatusCode ( ) ) ; $ response -> setHeader ( 'Location' , $ e -> getLocation ( ) ) ; $ response -> setBody ( new StringStream ( ) ) ; } catch ( \ Throwable $ e ) { $ this -> eventDispatcher -> dispatch ( Event :: EXCEPTION_THROWN , new ExceptionThrownEvent ( $ e , new ControllerContext ( $ request , $ response ) ) ) ; $ this -> handleException ( $ e , $ response ) ; try { $ context -> setException ( $ e ) ; $ class = isset ( $ this -> config [ 'psx_error_controller' ] ) ? $ this -> config [ 'psx_error_controller' ] : ErrorController :: class ; $ controller = $ this -> controllerFactory -> getController ( $ class , $ context ) ; $ this -> loader -> execute ( $ controller , $ request , $ response ) ; } catch ( \ Throwable $ e ) { $ this -> handleException ( $ e , $ response ) ; $ record = $ this -> exceptionConverter -> convert ( $ e ) ; $ response -> setHeader ( 'Content-Type' , 'application/json' ) ; $ response -> setBody ( new StringStream ( Parser :: encode ( $ record , JSON_PRETTY_PRINT ) ) ) ; } } if ( $ request -> getMethod ( ) == 'HEAD' ) { $ response -> setHeader ( 'Content-Length' , $ response -> getBody ( ) -> getSize ( ) ) ; $ response -> setBody ( new StringStream ( '' ) ) ; } $ this -> eventDispatcher -> dispatch ( Event :: RESPONSE_SEND , new ResponseSendEvent ( $ response ) ) ; $ this -> level -- ; return $ response ; }
Routes the request to the fitting controller and returns the response
20,398
public static function consume ( $ name ) { $ config = static :: get ( $ name ) ; if ( empty ( $ config [ 'consume' ] ) ) { throw new Exception ( 'Missing consumer configuration (' . $ name . ')' ) ; } $ config = $ config [ 'consume' ] ; $ config += [ 'connection' => 'rabbit' , 'prefetchCount' => 1 , ] ; if ( ! array_key_exists ( $ name , static :: $ _consumers ) ) { $ connection = ConnectionManager :: get ( $ config [ 'connection' ] ) ; static :: $ _consumers [ $ name ] = $ connection -> queue ( $ config [ 'queue' ] , $ config ) ; } return static :: $ _consumers [ $ name ] ; }
Get the queue object for consumption
20,399
public static function publish ( $ name , $ data , array $ options = [ ] ) { $ config = static :: get ( $ name ) ; if ( empty ( $ config [ 'publish' ] ) ) { throw new Exception ( 'Missing publisher configuration (' . $ name . ')' ) ; } $ config = $ config [ 'publish' ] ; $ config += $ options ; $ config += [ 'connection' => 'rabbit' , 'className' => 'RabbitMQ.RabbitQueue' ] ; if ( ! array_key_exists ( $ name , static :: $ _publishers ) ) { static :: $ _publishers [ $ name ] = ConnectionManager :: get ( $ config [ 'connection' ] ) ; } return static :: $ _publishers [ $ name ] -> send ( $ config [ 'exchange' ] , $ config [ 'routing' ] , $ data , $ config ) ; }
Publish a message to a RabbitMQ exchange