idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
3,400
public function addPath ( $ path ) { $ paths = ( array ) $ path ; foreach ( $ paths as $ path ) { $ this -> paths [ ] = rtrim ( $ path , "\\/" ) . DIRECTORY_SEPARATOR ; } }
Adds a search paths .
3,401
public function buildCacheKey ( ) { $ this -> setCacheKey ( $ this -> getCacheDirname ( ) . sprintf ( Helper :: getOption ( 'cache_filename_mask' , '%s.xml' ) , md5 ( $ this -> getFeedUrl ( ) ) ) ) ; return $ this ; }
Get the key of the current cached item
3,402
public function isCached ( ) { $ cache_lifetime = Helper :: getOption ( 'cache_lifetime' , 0 ) ; if ( $ cache_lifetime > 0 ) { return ( @ file_exists ( $ this -> getCacheKey ( ) ) && ( filemtime ( $ this -> getCacheKey ( ) ) + $ cache_lifetime ) > time ( ) ) ; } else { return ( @ file_exists ( $ this -> getCacheKey ( ) ) ) ; } }
Test if an item is already cached and if its cache is still valid
3,403
public function getCache ( ) { if ( @ file_exists ( $ this -> getCacheKey ( ) ) ) { ob_start ( ) ; include $ this -> getCacheKey ( ) ; $ cache = ob_get_contents ( ) ; ob_end_clean ( ) ; return $ cache ; } return null ; }
Get a cache content for an item
3,404
public function setCache ( $ content ) { if ( ! empty ( $ content ) && $ content -> getXml ( ) !== null ) { return ( ! empty ( $ content ) ) ? file_put_contents ( $ this -> getCacheKey ( ) , $ content -> getXml ( ) -> asXML ( ) ) : false ; } return false ; }
Set a cache content for an item
3,405
public function castTypes ( Query $ query , array $ data ) { if ( $ columns = $ query -> getRepository ( ) -> getSchema ( ) -> getColumns ( ) ) { foreach ( $ columns as $ column ) { $ field = $ column [ 'field' ] ; if ( array_key_exists ( $ field , $ data ) ) { if ( $ data [ $ field ] !== null ) { $ data [ $ field ] = AbstractType :: factory ( $ column [ 'type' ] , $ this -> getDriver ( ) ) -> to ( $ data [ $ field ] ) ; } } else if ( in_array ( $ query -> getType ( ) , [ Query :: INSERT , Query :: MULTI_INSERT ] , true ) && array_key_exists ( 'default' , $ column ) ) { $ data [ $ field ] = $ column [ 'default' ] ; } } } return $ data ; }
Loop through the data and cast types on each field represented in the schema .
3,406
public function executeTruncate ( MongoCollection $ collection , Query $ query ) { $ response = $ collection -> remove ( [ ] , $ query -> getAttributes ( ) + [ 'w' => 1 ] ) ; $ response [ 'params' ] = [ ] ; return $ response ; }
MongoDB doesn t support truncation so simply remove all records .
3,407
public function formatSubPredicate ( Predicate $ predicate ) { $ output = [ ] ; foreach ( $ predicate -> getParams ( ) as $ param ) { if ( $ param instanceof Predicate ) { $ output [ ] = $ this -> formatSubPredicate ( $ param ) ; } else if ( $ param instanceof Expr ) { $ output [ ] = $ this -> formatExpression ( $ param ) ; } } return [ $ this -> getClause ( $ predicate -> getType ( ) ) => $ output ] ; }
Nested predicates need to have individual values wrapped in arrays .
3,408
public function enqueue ( $ queue , $ class , $ args = null , $ track_status = false ) { ResqueLib :: enqueue ( $ queue , $ class , $ args , $ track_status ) ; }
Enqueue a Resque job
3,409
public function all ( ) : array { $ data = array_merge ( $ this -> data , $ this -> data [ self :: FLASH ] ?? [ ] ) ; unset ( $ data [ self :: FLASH ] ) ; $ previous = array_diff_key ( $ this -> flash , $ data ) ; return array_merge ( $ data , $ previous ) ; }
Return all the session data .
3,410
public function has ( string $ key ) : bool { return isset ( $ this -> flash [ $ key ] ) || isset ( $ this -> data [ $ key ] ) || isset ( $ this -> data [ self :: FLASH ] [ $ key ] ) ; }
Return whether the given key is set .
3,411
public function get ( string $ key , $ default = null ) { return $ this -> data [ $ key ] ?? $ this -> data [ self :: FLASH ] [ $ key ] ?? $ this -> flash [ $ key ] ?? $ default ; }
Return the value associated with the given key when set or the optional given default value when it is not .
3,412
public function flash ( string $ key , $ value ) { unset ( $ this -> data [ $ key ] ) ; $ this -> data [ self :: FLASH ] [ $ key ] = $ value ; }
Associate the given key with the given value within the flash namespace .
3,413
public function delete ( ) { foreach ( array_keys ( $ this -> data ) as $ key ) { unset ( $ this -> data [ $ key ] ) ; } foreach ( array_keys ( $ this -> flash ) as $ key ) { unset ( $ this -> flash [ $ key ] ) ; } }
Unset all keys .
3,414
public function PostController_DiscussionFormOptions_Handler ( PostController $ sender , $ args ) { $ sender -> Data [ 'DiscussionTypes' ] = [ ] ; foreach ( $ this -> getAvailableDiscussionTypesPlugins ( ) as $ pluginSpec ) { $ typeName = $ pluginSpec [ 'DiscussionTypes' ] [ 'Name' ] ; $ typeInstance = call_user_func ( sprintf ( 'DiscussionType_%sModel::instance' , $ typeName ) ) -> GetWhere ( [ 'DiscussionID' => $ sender -> Data [ 'Discussion' ] -> DiscussionID ] ) -> FirstRow ( DATASET_TYPE_ARRAY ) ; $ sender -> Data [ 'DiscussionTypes' ] [ $ typeName ] = $ typeInstance ; } echo $ this -> fetchTypesView ( 'postcontroller/formoptions' , $ sender -> Data [ 'Discussion' ] -> DiscussionID , $ sender ) ; }
Render form options for each activated discussion type .
3,415
public function DiscussionModel_AfterSaveDiscussion_Handler ( DiscussionModel $ sender ) { $ FormPostValues = val ( 'FormPostValues' , $ sender -> EventArguments , [ ] ) ; $ DiscussionID = val ( 'DiscussionID' , $ sender -> EventArguments ) ; $ FormPostValues [ 'DiscussionID' ] = $ DiscussionID ; $ types = $ this -> extractDiscussionTypes ( $ FormPostValues ) ; foreach ( $ types as $ type ) { call_user_func ( sprintf ( 'DiscussionType_%sModel::instance' , $ type ) ) -> save ( $ FormPostValues ) ; } }
Save discussion types additional properties to database .
3,416
public function DiscussionsController_BeforeDiscussionName_Handler ( DiscussionsController $ sender , $ args ) { foreach ( $ this -> getAvailableDiscussionTypesPlugins ( ) as $ pluginSpec ) { $ typeName = $ pluginSpec [ 'DiscussionTypes' ] [ 'Name' ] ; $ model = call_user_func ( sprintf ( 'DiscussionType_%sModel::instance' , $ typeName ) ) ; if ( $ model -> GetWhere ( [ 'DiscussionID' => $ sender -> EventArguments [ 'Discussion' ] -> DiscussionID ] ) -> count ( ) ) { $ args [ 'CssClass' ] .= ' ' . $ pluginSpec [ 'Index' ] ; } } }
Adds discussion type class name as CSS class if appropriate .
3,417
private function extractDiscussionTypes ( array $ FormPostValues ) { $ types = [ ] ; foreach ( array_keys ( $ FormPostValues ) as $ key ) { $ matches = [ ] ; if ( preg_match ( '/^DiscussionType_(\w+)_.+$/' , $ key , $ matches ) ) { $ types [ ] = $ matches [ 1 ] ; } } return array_unique ( $ types ) ; }
Extracts distinct discussion types names a key value array similar to what you get from Vanilla forms .
3,418
private function getAvailableDiscussionTypesPlugins ( ) { $ available = [ ] ; foreach ( Gdn :: pluginManager ( ) -> availablePlugins ( ) as $ name => $ spec ) { if ( strpos ( $ name , 'DiscussionType_' ) === 0 && isset ( $ spec [ 'DiscussionTypes' ] ) ) { $ available [ $ name ] = $ spec ; } } return $ available ; }
Returns the list of compatible plugins .
3,419
private function fetchTypesView ( $ view , $ discussionId , Gdn_Pluggable $ sender ) { $ out = '' ; $ sender -> Data [ 'DiscussionTypes' ] = [ ] ; foreach ( $ this -> getAvailableDiscussionTypesPlugins ( ) as $ pluginSpec ) { if ( isset ( $ discussionId ) ) { $ typeModelClass = sprintf ( '%sModel' , $ pluginSpec [ 'Index' ] ) ; $ typeName = $ pluginSpec [ 'DiscussionTypes' ] [ 'Name' ] ; $ model = call_user_func ( sprintf ( '%s::instance' , $ typeModelClass ) ) ; $ discussionTypeInstance = $ model -> GetWhere ( [ 'DiscussionID' => $ discussionId ] ) ; if ( $ discussionTypeInstance -> count ( ) ) { $ sender -> Data [ 'DiscussionTypes' ] [ $ typeName ] = $ discussionTypeInstance -> firstRow ( DATASET_TYPE_ARRAY ) ; } else { unset ( $ sender -> Data [ 'DiscussionTypes' ] [ $ typeName ] ) ; } } $ viewPath = sprintf ( '%s/views/%s.php' , $ pluginSpec [ 'PluginRoot' ] , $ view ) ; $ out .= $ sender -> fetchView ( $ viewPath ) ; } return $ out ; }
Renders a same view for all activated discussion type plugins .
3,420
public function setConfig ( $ key = null , $ value = null ) { if ( is_array ( $ key ) ) { $ this -> config = $ key ; } else { $ this -> config [ $ key ] = $ value ; } return $ this ; }
Set database configuration
3,421
public function getConnection ( ) { if ( null === $ this -> conn ) { $ this -> checkConfiguration ( ) ; try { $ this -> conn = new SQL ( $ this -> buildDsn ( ) , $ this -> config [ 'username' ] , $ this -> config [ 'password' ] ) ; } catch ( Exception $ e ) { throw new RuntimeException ( static :: E_CONNECT ) ; } } return $ this -> conn ; }
Get DB \ SQL instance
3,422
public function pdoWithoutDB ( ) { $ this -> checkConfiguration ( ) ; try { return new PDO ( $ this -> buildDsn ( false ) , $ this -> config [ 'username' ] , $ this -> config [ 'password' ] ) ; } catch ( Exception $ e ) { throw new RuntimeException ( static :: E_CONNECT ) ; } }
Get PDO without database name
3,423
public function getStatus ( ) { $ tables = count ( $ this -> getTables ( ) ) ; $ unhealth = count ( $ this -> getUnhealthyTable ( ) ) ; if ( $ tables ) { $ healthy = $ tables - $ unhealth ; return ( $ healthy / $ tables ) * 100 ; } return 100 ; }
Get table status percentage
3,424
public function checkTables ( array $ tables ) { $ check = implode ( ',' , $ tables ) ; $ result = $ this -> getConnection ( ) -> pdo ( ) -> query ( "CHECK TABLE $check" ) ; return $ result ? $ result -> fetchAll ( PDO :: FETCH_ASSOC ) : $ result ; }
Perform table checking
3,425
public function getUnhealthyTable ( ) { $ app = Base :: instance ( ) ; $ key = 'CACHE.db_unhealthy' ; if ( $ app -> devoid ( $ key ) ) { $ tables = $ this -> getTables ( ) ; $ unhealthy = [ ] ; if ( $ tables ) { foreach ( $ this -> checkTables ( $ tables ) as $ result ) { if ( ! in_array ( $ result [ 'Msg_text' ] , [ 'OK' , 'Table is already up to date' ] ) ) { $ unhealthy [ ] = $ result [ 'Table' ] ; } } } $ app -> set ( $ key , $ unhealthy , 60 ) ; } return $ app -> get ( $ key ) ; }
Get unhealthy table
3,426
protected function buildDsn ( $ withDatabase = true ) { $ dsn = 'mysql:host=' . $ this -> config [ 'host' ] ; if ( $ withDatabase ) { $ dsn .= ';dbname=' . $ this -> config [ 'name' ] ; } if ( ! empty ( $ this -> config [ 'port' ] ) ) { $ dsn .= ';port=' . $ this -> config [ 'port' ] ; } return $ dsn ; }
Build dsn string based on config
3,427
public function delete ( $ id ) { $ model = $ this -> get ( $ id ) ; if ( $ model === null ) { return new NotFound ( [ 'message' => 'Position not found.' ] ) ; } $ this -> dispatch ( PositionEvent :: PRE_DELETE , $ model ) ; $ model -> delete ( ) ; if ( $ model -> isDeleted ( ) ) { $ this -> dispatch ( PositionEvent :: POST_DELETE , $ model ) ; return new Deleted ( [ 'model' => $ model ] ) ; } return new NotDeleted ( [ 'message' => 'Could not delete Position' ] ) ; }
Deletes a Position with the given id
3,428
public function paginate ( Parameters $ params ) { $ sysPrefs = $ this -> getServiceContainer ( ) -> getPreferenceLoader ( ) -> getSystemPreferences ( ) ; $ defaultSize = $ sysPrefs -> getPaginationSize ( ) ; $ page = $ params -> getPage ( 'number' ) ; $ size = $ params -> getPage ( 'size' , $ defaultSize ) ; $ query = PositionQuery :: create ( ) ; $ sort = $ params -> getSort ( Position :: getSerializer ( ) -> getSortFields ( ) ) ; foreach ( $ sort as $ field => $ order ) { $ method = 'orderBy' . NameUtils :: toStudlyCase ( $ field ) ; $ query -> $ method ( $ order ) ; } $ filter = $ params -> getFilter ( ) ; if ( ! empty ( $ filter ) ) { $ this -> applyFilter ( $ query , $ filter ) ; } if ( $ size == - 1 ) { $ model = $ query -> findAll ( ) ; } else { $ model = $ query -> paginate ( $ page , $ size ) ; } return new Found ( [ 'model' => $ model ] ) ; }
Returns a paginated result
3,429
public function setSkillId ( $ id , $ relatedId ) { $ model = $ this -> get ( $ id ) ; if ( $ model === null ) { return new NotFound ( [ 'message' => 'Position not found.' ] ) ; } if ( $ this -> doSetSkillId ( $ model , $ relatedId ) ) { $ this -> dispatch ( PositionEvent :: PRE_SKILL_UPDATE , $ model ) ; $ this -> dispatch ( PositionEvent :: PRE_SAVE , $ model ) ; $ model -> save ( ) ; $ this -> dispatch ( PositionEvent :: POST_SKILL_UPDATE , $ model ) ; $ this -> dispatch ( PositionEvent :: POST_SAVE , $ model ) ; return Updated ( [ 'model' => $ model ] ) ; } return NotUpdated ( [ 'model' => $ model ] ) ; }
Sets the Skill id
3,430
static function registerForm ( Form $ form ) { if ( ! in_array ( $ form , self :: $ forms ) ) array_push ( self :: $ forms , $ form ) ; }
Registers given form globally
3,431
static function getForm ( $ slug ) { foreach ( self :: $ forms as $ form ) if ( $ form -> getGlobalSlug ( ) == $ slug ) return $ form ; return null ; }
Retrieves a form by its slug
3,432
protected function normalizeAccessKey ( $ key , $ index_name = null ) { if ( empty ( $ index_name ) ) { @ list ( $ index_name , $ key ) = explode ( '.' , $ key ) ; if ( empty ( $ key ) ) { $ key = $ index_name ; $ index_name = 'default' ; } } return [ $ index_name , $ key ] ; }
Allows compound keys to get to indexed config groups .
3,433
public function forget ( $ key , $ index_name = null ) { list ( $ index_name , $ key ) = $ this -> normalizeAccessKey ( $ key , $ index_name ) ; if ( $ this -> has ( $ key , $ index_name ) ) { unset ( $ this -> items [ $ index_name ] [ $ key ] ) ; } }
Remove an item from the container .
3,434
public function get ( $ key , $ default_value = null , $ index_name = null ) { list ( $ index_name_x , $ key ) = $ this -> normalizeAccessKey ( $ key , $ index_name ) ; if ( ! empty ( $ index_name_x ) ) { $ index_name = $ index_name_x ; } if ( array_key_exists ( $ index_name , $ this -> items ) ) { return $ this -> evaluate ( $ this -> walkConfig ( $ this -> items [ $ index_name ] , $ key , $ default_value ) ) ; } else { return $ this -> evaluate ( $ default_value ) ; } }
Get an item from the container .
3,435
public function all ( $ index = null ) { if ( empty ( $ index ) ) { return $ this -> items ; } elseif ( array_key_exists ( $ index , $ this -> items ) && is_array ( $ this -> items [ $ index ] ) ) { return $ this -> items [ $ index ] ; } else { return [ ] ; } }
Get all items from the container .
3,436
public static function array_merge_deep ( array $ array1 , array $ array2 ) { $ merged = $ array1 ; foreach ( $ array2 as $ key => $ value ) { if ( is_array ( $ value ) && isset ( $ merged [ $ key ] ) && is_array ( $ merged [ $ key ] ) ) { $ merged [ $ key ] = self :: array_merge_deep ( $ merged [ $ key ] , $ value ) ; } elseif ( is_numeric ( $ key ) ) { if ( ! in_array ( $ value , $ merged ) ) { $ merged [ ] = $ value ; } } else { $ merged [ $ key ] = $ value ; } } return $ merged ; }
Recursively perform an array merge preserving keys and overriding dupes .
3,437
public function copyDatabase ( $ source , $ target ) { $ this -> dropDatabase ( $ target ) ; $ this -> createDatabase ( $ target , null ) ; $ src = escapeshellarg ( $ source ) ; $ tgt = escapeshellarg ( $ tgt ) ; $ cmd = String ( "pg_dump {0} | psql {1}" ) -> format ( $ src , $ tgt ) ; $ failure = false ; passthru ( $ cmd , $ failure ) ; if ( $ failure ) { throw new RuntimeException ( "Unable to copy database $source to $target" ) ; } }
Copy the specified source database to the target . If the target already exists it will be dropped . Note that since pg_dump is used to copy the database and pg_dump doesn t accept command line passwords this will only work if run as a user with appropriate permissions .
3,438
public function execute ( $ files ) { $ files = $ files -> filter_by ( array ( & $ this , 'filter_by_type' ) ) ; Application :: db ( ) -> store ( 'page_list' , $ files ) ; }
Make the database from the loaded content .
3,439
public static function getModelTable ( LightModel $ model ) : Table { if ( ! isset ( self :: $ tables [ $ model -> getTableName ( ) ] ) ) { self :: $ tables [ $ model -> getTableName ( ) ] = new Table ( $ model -> getTableName ( ) ) ; } return self :: $ tables [ $ model -> getTableName ( ) ] ; }
We only want to ever load a table once so we check if we already have an instantiated instance of it before loading .
3,440
public function make ( $ view , array $ data = [ ] ) { $ location = $ this -> finder -> find ( $ view ) ; if ( ! $ location ) { throw new \ Exception ( sprintf ( 'View `%s` cannot be found!' , $ view ) ) ; } return new View ( $ location , $ view , $ data ) ; }
Creates a new view object ready to use
3,441
protected function getClientUrl ( ) { $ protocol = isset ( $ _SERVER [ 'HTTP_X_FORWARDED_PROTO' ] ) ? $ _SERVER [ 'HTTP_X_FORWARDED_PROTO' ] : isset ( $ _SERVER [ 'REQUEST_SCHEME' ] ) ? $ _SERVER [ 'REQUEST_SCHEME' ] : ( isset ( $ _SERVER [ 'HTTPS' ] ) && $ _SERVER [ 'HTTPS' ] === 'on' ) ? 'https' : 'http' ; $ host = $ _SERVER [ 'HTTP_HOST' ] ; $ request_uri = $ _SERVER [ 'REQUEST_URI' ] ; return $ protocol . '://' . $ host . $ request_uri ; }
Get the current url
3,442
public static function tryingToMapItem ( MapsProperty $ mapping , Throwable $ exception ) : UnmappableInput { return new self ( sprintf ( 'Failed to map the %s relation of the `%s` property: %s' , justThe ( endOfThe ( classOfThe ( $ mapping ) , '\\' ) , 1 ) , $ mapping -> name ( ) , $ exception -> getMessage ( ) ) , 0 , $ exception ) ; }
Notifies the client code when an object could not be hydrated .
3,443
public static function write ( $ level , $ msg , $ method = null ) { static $ oldlabels = array ( 1 => 'Error' , 2 => 'Warning' , 3 => 'Debug' , 4 => 'Info' , ) ; $ loglabels = \ Config :: get ( 'log_threshold' ) ; if ( $ loglabels == \ Fuel :: L_NONE ) { return false ; } if ( ! is_array ( $ loglabels ) ) { $ a = array ( ) ; foreach ( static :: $ levels as $ l => $ label ) { $ l >= $ loglabels and $ a [ ] = $ l ; } $ loglabels = $ a ; } if ( \ Config :: get ( 'profiling' ) ) { \ Console :: log ( $ method . ' - ' . $ msg ) ; } if ( is_int ( $ level ) and isset ( $ oldlabels [ $ level ] ) ) { $ level = strtoupper ( $ oldlabels [ $ level ] ) ; } if ( is_string ( $ level ) ) { if ( ! $ level = array_search ( $ level , static :: $ levels ) ) { $ level = 250 ; } } if ( ( is_int ( $ level ) and ! isset ( static :: $ levels [ $ level ] ) ) or ( is_string ( $ level ) and ! array_search ( strtoupper ( $ level ) , static :: $ levels ) ) ) { throw new \ FuelException ( 'Invalid level "' . $ level . '" passed to logger()' ) ; } if ( ! in_array ( $ level , $ loglabels ) ) { return false ; } static :: instance ( ) -> log ( $ level , ( empty ( $ method ) ? '' : $ method . ' - ' ) . $ msg ) ; return true ; }
Write Log File
3,444
public function render ( $ content , array $ attribs = [ ] ) { if ( isset ( $ attribs [ 'tagName' ] ) ) { $ tagName = $ attribs [ 'tagName' ] ; unset ( $ attribs [ 'tagName' ] ) ; } else { $ tagName = $ this -> getTagName ( ) ; } if ( ! $ tagName ) { return $ this -> renderContent ( $ content ) ; } if ( ! $ content && ! $ this -> closeTag ) { $ openTag = trim ( $ this -> getOpenTag ( $ tagName , $ attribs ) ) ; return substr_replace ( $ openTag , $ this -> getClosingBracket ( ) , - 1 ) ; } return $ this -> getOpenTag ( $ tagName , $ attribs ) . $ this -> renderContent ( $ content ) . $ this -> getCloseTag ( $ tagName ) ; }
Render HTML container
3,445
public function setOptions ( array $ options ) : self { $ this -> _options = array_replace_recursive ( $ this -> getDefaultOptions ( ) , $ options ) ; return $ this ; }
Sets the value of field options .
3,446
public function validate ( $ subject ) : bool { if ( \ is_int ( $ this -> schema [ 'minProperties' ] ) && $ this -> schema [ 'minProperties' ] >= 0 ) { if ( \ count ( $ subject ) < $ this -> schema [ 'minProperties' ] ) { return false ; } } return true ; }
Validates subject against minProperties
3,447
protected function prepareDocument ( ) { $ app = JFactory :: getApplication ( ) ; $ menus = $ app -> getMenu ( ) ; $ menu = $ menus -> getActive ( ) ; if ( $ menu ) { $ this -> params -> def ( 'page_heading' , $ this -> params -> get ( 'page_title' , $ menu -> title ) ) ; } else { $ this -> params -> def ( 'page_heading' , JText :: _ ( $ this -> pageHeading ) ) ; } $ title = $ this -> params -> get ( 'page_title' , '' ) ; if ( empty ( $ title ) ) { $ title = $ app -> get ( 'sitename' ) ; } elseif ( $ app -> get ( 'sitename_pagetitles' , 0 ) == 1 ) { $ title = JText :: sprintf ( 'JPAGETITLE' , $ app -> get ( 'sitename' ) , $ title ) ; } elseif ( $ app -> get ( 'sitename_pagetitles' , 0 ) == 2 ) { $ title = JText :: sprintf ( 'JPAGETITLE' , $ title , $ app -> get ( 'sitename' ) ) ; } $ this -> document -> setTitle ( $ title ) ; if ( $ this -> params -> get ( 'menu-meta_description' ) ) { $ this -> document -> setDescription ( $ this -> params -> get ( 'menu-meta_description' ) ) ; } if ( $ this -> params -> get ( 'menu-meta_keywords' ) ) { $ this -> document -> setMetadata ( 'keywords' , $ this -> params -> get ( 'menu-meta_keywords' ) ) ; } if ( $ this -> params -> get ( 'robots' ) ) { $ this -> document -> setMetadata ( 'robots' , $ this -> params -> get ( 'robots' ) ) ; } }
Prepares the document
3,448
private static function getSourceFunction ( ? int $ imgType = null ) : ? string { switch ( $ imgType ) { case IMAGETYPE_JPEG : $ src [ 'function' ] = 'imagecreatefromjpeg' ; break ; case IMAGETYPE_PNG : $ src [ 'function' ] = 'imagecreatefrompng' ; break ; case IMAGETYPE_GIF : $ src [ 'function' ] = 'imagecreatefromgif' ; break ; default : $ src [ 'function' ] = null ; break ; } return $ src [ 'function' ] ; }
Returns source image function
3,449
private static function getDestinationFunction ( string $ imgExtension = null ) : ? string { switch ( $ imgExtension ) { case 'jpg' : case 'jpeg' : $ dst [ 'function' ] = 'imagejpeg' ; break ; case 'png' : $ dst [ 'function' ] = 'imagepng' ; break ; case 'gif' : $ dst [ 'function' ] = 'imagegif' ; break ; default : $ dst [ 'function' ] = null ; break ; } return $ dst [ 'function' ] ; }
Returns destination image function
3,450
private static function setQuality ( int $ quality = 90 ) : void { $ quality = $ quality < 10 || $ quality > 100 ? 90 : $ quality ; static :: $ quality = $ quality ; static :: $ qualityPNG = ( int ) \ round ( ( 100 - $ quality ) / 10 , 0 ) ; }
Sets output quality
3,451
private static function getDestinationQuality ( ? string $ imgExtension = null ) : int { switch ( $ imgExtension ) { case 'png' : $ quality = static :: $ qualityPNG ; break ; default : $ quality = static :: $ quality ; break ; } return $ quality ; }
Return destination image quality
3,452
private static function calculateResizeData ( array $ srcSize = [ ] , array $ dstOptions = [ ] ) : array { $ srcRatio = $ srcSize [ 'w' ] / $ srcSize [ 'h' ] ; $ dstSize = [ 'w' => 0 , 'h' => 0 ] ; if ( $ dstOptions [ 'w' ] > $ srcSize [ 'w' ] ) { $ dstOptions [ 'w' ] = $ srcSize [ 'w' ] ; } if ( $ dstOptions [ 'h' ] > $ srcSize [ 'h' ] ) { $ dstOptions [ 'h' ] = $ srcSize [ 'h' ] ; } if ( $ dstOptions [ 'w' ] <= 0 && $ dstOptions [ 'h' ] <= 0 ) { $ dstOptions [ 'w' ] = $ srcSize [ 'w' ] ; $ dstOptions [ 'h' ] = $ srcSize [ 'h' ] ; } elseif ( $ dstOptions [ 'w' ] <= 0 ) { $ dstOptions [ 'w' ] = $ dstOptions [ 'h' ] * $ srcRatio ; } elseif ( $ dstOptions [ 'h' ] <= 0 ) { $ dstOptions [ 'h' ] = $ dstOptions [ 'w' ] / $ srcRatio ; } $ dstRatio = $ dstOptions [ 'w' ] / $ dstOptions [ 'h' ] ; $ dstSize [ 'w' ] = ( int ) \ floor ( $ dstOptions [ 'w' ] ) ; $ dstSize [ 'h' ] = ( int ) \ floor ( $ dstOptions [ 'h' ] ) ; $ dstSize [ 'src-box' ] = static :: calculateSourceBox ( $ srcSize , $ srcRatio , $ dstSize , $ dstRatio ) ; return $ dstSize ; }
Calculates resize data
3,453
private static function calculateSourceBox ( array $ srcSize = [ ] , float $ srcRatio = 1 , array $ dstSize = [ ] , float $ dstRatio = 1 ) : array { $ srcBox = [ 'x' => 0 , 'y' => 0 , 'w' => $ srcSize [ 'w' ] , 'h' => $ srcSize [ 'h' ] ] ; if ( $ srcRatio != $ dstRatio ) { $ srcBox [ 'w' ] = $ dstSize [ 'w' ] ; $ srcBox [ 'h' ] = $ dstSize [ 'h' ] ; while ( $ srcBox [ 'w' ] < $ srcSize [ 'w' ] && $ srcBox [ 'h' ] < $ srcSize [ 'h' ] ) { $ srcBox [ 'w' ] *= 10 ; $ srcBox [ 'h' ] *= 10 ; } if ( $ srcBox [ 'w' ] > $ srcSize [ 'w' ] ) { $ srcBox [ 'w' ] = $ srcSize [ 'w' ] ; $ srcBox [ 'h' ] = ( int ) \ floor ( $ srcSize [ 'w' ] / $ dstRatio ) ; } if ( $ srcBox [ 'h' ] > $ srcSize [ 'h' ] ) { $ srcBox [ 'h' ] = $ srcSize [ 'h' ] ; $ srcBox [ 'w' ] = ( int ) \ floor ( $ srcSize [ 'h' ] * $ dstRatio ) ; } $ srcBox [ 'x' ] = 0 ; $ srcBox [ 'y' ] = ( int ) \ floor ( ( $ srcSize [ 'h' ] - $ srcBox [ 'h' ] ) / 2 ) ; if ( $ srcBox [ 'w' ] < $ srcSize [ 'w' ] ) { $ srcBox [ 'x' ] = ( int ) \ floor ( ( $ srcSize [ 'w' ] - $ srcBox [ 'w' ] ) / 2 ) ; $ srcBox [ 'y' ] = 0 ; } } return $ srcBox ; }
Calculates source box
3,454
public function createAction ( Request $ request ) { $ entity = new Menu ( ) ; $ form = $ this -> createCreateForm ( $ entity ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> persist ( $ entity ) ; $ em -> flush ( ) ; $ rootItem = new MenuItem ( ) ; $ rootItem -> setName ( $ entity -> getName ( ) . " Root Item" ) ; $ rootItem -> setIsRoot ( true ) ; $ rootItem -> setMenu ( $ entity ) ; $ em -> persist ( $ rootItem ) ; $ em -> flush ( ) ; return $ this -> redirect ( $ this -> generateUrl ( 'admin_menu_show' , array ( 'id' => $ entity -> getId ( ) ) ) ) ; } return array ( 'entity' => $ entity , 'form' => $ form -> createView ( ) , ) ; }
Creates a new Menu entity .
3,455
private function createCreateForm ( Menu $ entity ) { $ form = $ this -> createForm ( new MenuType ( ) , $ entity , array ( 'action' => $ this -> generateUrl ( 'admin_menu_create' ) , 'method' => 'POST' , ) ) ; $ form -> add ( 'submit' , 'submit' , array ( 'label' => 'Create' ) ) ; return $ form ; }
Creates a form to create a Menu entity .
3,456
private function createEditForm ( Menu $ entity ) { $ form = $ this -> createForm ( new MenuType ( ) , $ entity , array ( 'action' => $ this -> generateUrl ( 'admin_menu_update' , array ( 'id' => $ entity -> getId ( ) ) ) , 'method' => 'PUT' , ) ) ; $ form -> add ( 'submit' , 'submit' , array ( 'label' => 'Update' ) ) ; return $ form ; }
Creates a form to edit a Menu entity .
3,457
public function itemsAction ( Menu $ menu ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ entities = $ em -> getRepository ( 'AmulenPageBundle:MenuItem' ) -> childrenHierarchy ( null , false , array ( "childSort" => array ( "position" => "ASC" ) , ) , null ) ; return array ( 'menu' => $ menu , 'entities' => $ entities , ) ; }
Finds and displays menu items ..
3,458
private function createMenuItemCreateForm ( MenuItem $ entity ) { $ form = $ this -> createForm ( new MenuItemType ( ) , $ entity , array ( 'action' => $ this -> generateUrl ( 'admin_menu_item_create' , array ( 'id' => $ entity -> getMenu ( ) -> getId ( ) ) ) , 'method' => 'POST' , ) ) ; $ form -> add ( 'submit' , 'submit' , array ( 'label' => 'Create' ) ) ; return $ form ; }
Creates a form to create a MenuItem entity .
3,459
private function createMenuItemEditForm ( MenuItem $ entity ) { $ form = $ this -> createForm ( new MenuItemType ( ) , $ entity , array ( 'action' => $ this -> generateUrl ( 'admin_menu_item_update' , array ( 'id' => $ entity -> getId ( ) ) ) , 'method' => 'PUT' , ) ) ; $ form -> add ( 'submit' , 'submit' , array ( 'label' => 'Update' ) ) ; return $ form ; }
Creates a form to edit a MenuItem entity .
3,460
public function select ( array $ filter , array $ sorting = [ ] ) { $ this -> filter = $ filter ; $ this -> sorting = $ sorting ; $ this -> prefetch = false ; $ this -> items = null ; return $ this ; }
Select entities fetch on demand .
3,461
public function fetch ( array $ filter , array $ sorting = [ ] ) { $ this -> filter = $ filter ; $ this -> sorting = $ sorting ; $ this -> prefetch = true ; $ this -> items = null ; return $ this ; }
Select and fetch entities .
3,462
protected function initKeys ( $ constraints = '' , $ joins = '' , $ sorting = '' ) { $ this -> items = [ ] ; $ query = implode ( ' ' , [ 'SELECT t0.`' . $ this -> adapter -> getSchema ( $ this -> table , 'primary' ) . '` FROM' , '`' . $ this -> table . '` AS t0' ] ) ; $ rows = $ this -> adapter -> getDriver ( ) -> query ( $ query . $ joins . $ constraints . $ sorting ) -> fetchAll ( ) ; if ( is_array ( $ rows ) ) { $ this -> items = array_flip ( $ rows ) ; } }
Initialize primary keys only
3,463
protected function initEntities ( $ constraints = '' , $ joins = '' , $ sorting = '' ) { $ this -> items = [ ] ; $ query = implode ( ' ' , [ 'SELECT t0.* FROM' , '`' . $ this -> table . '` AS t0' ] ) ; $ statement = $ this -> adapter -> getDriver ( ) -> query ( $ query . $ joins . $ constraints . $ sorting ) ; $ class = $ this -> adapter -> getSchema ( $ this -> table , 'class' ) ; do { $ row = $ statement -> fetchAssoc ( ) ; if ( is_array ( $ row ) ) { $ entity = new $ class ( $ this -> adapter ) ; $ entity -> fromArray ( $ row ) ; $ this -> items [ $ row [ $ this -> adapter -> getSchema ( $ this -> table , 'primary' ) ] ] = $ entity ; } } while ( false !== $ row ) ; }
Initialize primary keys and entities
3,464
protected function translate ( array $ filters , array $ sorting = [ ] , array $ joins = [ ] ) { $ constraints = [ ] ; foreach ( $ filters as $ index => $ filter ) { if ( array_key_exists ( 'column' , $ filter ) && array_key_exists ( 'value' , $ filter ) ) { $ constraints [ ] = $ this -> translateCriteria ( $ filter , $ joins ) ; continue ; } list ( $ constraint , $ sorting , $ joins ) = $ this -> translate ( $ filter , $ sorting , $ joins ) ; $ this -> translateOperation ( $ index , $ constraint , $ constraints ) ; } return [ $ constraints , $ sorting , $ joins ] ; }
Recursive filter array translation
3,465
protected function translateCriteria ( array $ filter , array & $ joins ) { list ( $ column , $ type ) = $ this -> join ( explode ( '.' , $ filter [ 'column' ] ) , $ joins ) ; switch ( true ) { case is_array ( $ filter [ 'value' ] ) : $ values = [ ] ; foreach ( $ filter [ 'value' ] as $ value ) { $ values [ ] = $ this -> adapter -> getDriver ( ) -> quote ( $ value , $ type ) ; } $ comparison = ' IN (' . implode ( ', ' , $ values ) . ')' ; break ; case is_null ( $ filter [ 'value' ] ) : $ comparison = ' IS NULL' ; break ; default : $ comparison = ' = ' . $ this -> adapter -> getDriver ( ) -> quote ( $ filter [ 'value' ] , $ type ) ; } return $ column . $ comparison ; }
Translate single filter criteria into SQL - like query constraint
3,466
protected function handleException ( \ Exception $ e , $ request , $ type ) { $ event = new FilterExceptionEvent ( $ this , $ request , $ type ) ; $ event -> setException ( $ e ) ; $ this -> getDispatcher ( ) -> dispatch ( KernelEvents :: EXCEPTION , $ event ) ; $ e = $ event -> getException ( ) ; if ( ! $ event -> hasResponse ( ) ) { throw $ e ; } $ response = $ event -> getResponse ( ) ; if ( ! $ response -> isClientError ( ) && ! $ response -> isServerError ( ) && ! $ response -> isRedirect ( ) ) { if ( $ e instanceof HttpExceptionInterface ) { $ response -> setStatusCode ( $ e -> getStatusCode ( ) ) ; $ response -> headers -> add ( $ e -> getHeaders ( ) ) ; } else { $ response -> setStatusCode ( 500 ) ; } } try { return $ this -> filterResponse ( $ response , $ request , $ type ) ; } catch ( \ Exception $ e ) { return $ response ; } }
Handle uncaught exceptions in application .
3,467
protected function matchRoute ( Request $ request , $ type ) { $ router = $ this -> container -> get ( 'router' ) ; if ( ! $ request -> attributes -> has ( '_controller' ) ) { try { $ matched = $ router -> match ( $ request -> getPathInfo ( ) ) ; } catch ( ResourceNotFoundException $ e ) { throw new NotFoundHttpException ( sprintf ( 'No route found for path "%s".' , $ request -> getPath ( ) ) ) ; } } else { $ matched = [ '_controller' => $ request -> attributes -> get ( '_controller' ) ] ; } return $ matched ; }
Match a route to a controller .
3,468
protected function filterResponse ( Response $ response , Request $ request , $ type ) { $ event = new FilterResponseEvent ( $ this , $ request , $ type , $ response ) ; $ this -> getDispatcher ( ) -> dispatch ( KernelEvents :: RESPONSE , $ event ) ; return $ event -> getResponse ( ) ; }
Filter response .
3,469
public function terminate ( Request $ request , Response $ response ) { $ event = new PostResponseEvent ( $ this , $ request , $ response ) ; $ this -> getDispatcher ( ) -> dispatch ( KernelEvents :: TERMINATE , $ event ) ; }
Terminate the application .
3,470
public function boot ( ) { try { $ this -> initialiseConfiguration ( ) ; $ this -> initialiseSession ( ) ; $ this -> initialiseContainer ( ) ; $ this -> initialiseModules ( ) ; } catch ( \ Exception $ e ) { $ this -> setSafeMode ( true ) ; $ this -> boot ( ) ; throw $ e ; } $ this -> booted = true ; }
Boot the application . Initialise all of the components .
3,471
protected function initialiseConfiguration ( ) { $ configuration = $ this -> registerConfiguration ( $ this -> environment ) ; if ( ! is_array ( $ configuration ) ) { throw new \ RuntimeException ( sprintf ( 'The configuration must be a valid array (%s given).' , $ this -> varToString ( $ configuration ) ) ) ; } return $ this -> configuration = new Configuration ( $ configuration ) ; }
Initialise the application configuration
3,472
protected function initialiseModules ( ) { $ this -> modules = array ( ) ; $ exceptions = array ( ) ; foreach ( $ this -> registerModules ( $ this -> environment ) as $ module ) { if ( $ this -> isSafeMode ( ) && ! $ module -> isCoreModule ( ) ) { continue ; } $ name = $ module -> getName ( ) ; if ( isset ( $ this -> modules [ $ name ] ) ) { throw new \ LogicException ( sprintf ( 'Trying to register two modules with the same name "%s"' , $ name ) ) ; } $ module -> boot ( $ this -> getContainer ( ) ) ; $ this -> modules [ $ module -> getName ( ) ] = $ module ; } foreach ( $ this -> modules as $ module ) { $ module -> postBoot ( $ this -> getContainer ( ) ) ; } return $ this -> modules ; }
Initialise the modules register them in the kernel
3,473
protected function initialiseSession ( ) { $ session = $ this -> session ? : new Session ( ) ; if ( ! $ session -> isStarted ( ) ) { $ session -> start ( ) ; } return $ this -> session = $ session ; }
Initialise the session and attach it to the request .
3,474
protected function initialiseContainer ( ) { $ container = $ this -> buildContainer ( ) ; $ this -> prepareContainer ( $ container ) ; $ this -> container = $ container ; return $ this -> container ; }
Initialise the service container
3,475
protected function prepareContainer ( Container $ container ) { foreach ( $ this -> getKernelParameters ( ) as $ key => $ value ) { $ container [ $ key ] = $ value ; } $ container -> set ( 'kernel' , $ this ) ; $ container -> set ( 'configuration' , $ this -> configuration ) ; $ container -> set ( 'request' , $ this -> request ) ; $ container -> set ( 'request_stack' , $ this -> requestStack ) ; $ container -> set ( 'session' , $ this -> session ) ; }
Insert services into the container at application boot
3,476
public function getKernelParameters ( ) { return [ 'kernel.debug' => $ this -> debug , 'kernel.environment' => $ this -> environment , 'kernel.cache_dir' => $ this -> getCacheDir ( ) , 'kernel.charset' => $ this -> getCharset ( ) , 'kernel.logs_dir' => $ this -> getLogDir ( ) , 'kernel.name' => $ this -> getName ( ) , 'kernel.root_dir' => $ this -> getRootDir ( ) , 'kernel.version' => self :: VERSION ] ; }
Get kernel parameters
3,477
public function offsetGet ( $ offset ) { if ( $ pair = static :: __ResolveTrait_hasObjectAnnotation ( $ this , $ offset ) ) { if ( $ this -> $ offset === NULL && $ pair [ 0 ] -> auto_resolve ) { $ this -> $ offset = $ pair [ 0 ] -> factory ( $ this , $ pair [ 1 ] ) ; } return $ this -> $ offset ; } user_error ( "Undefined index: $offset" , E_USER_NOTICE ) ; }
Returns the property at the offset .
3,478
public function checkExpirationDate ( ExecutionContext $ context ) { $ expirationDate = $ this -> expirationDate ; if ( is_null ( $ expirationDate ) ) { $ context -> addViolationAt ( "expirationDate" , "La fecha de vencimiento es invalida" , array ( ) , null ) ; } else { $ ts = $ expirationDate -> format ( 'U' ) ; if ( $ ts <= time ( ) ) { $ context -> addViolationAt ( "expirationDate" , "La fecha de vencimiento es invalida" , array ( ) , null ) ; } } }
Checks if the expiration date is valid
3,479
public static function toArray ( ) { $ reflectionClass = new \ ReflectionClass ( get_called_class ( ) ) ; $ parentRelectionClass = $ reflectionClass -> getParentClass ( ) ; return array_diff ( $ reflectionClass -> getConstants ( ) , $ parentRelectionClass -> getConstants ( ) ) ; }
Returns all enum constant values in an array
3,480
private function prepareArgs ( ActionModel $ targetAction , $ indexedArgs , $ searchHashedArgs ) { $ preparedArgs = [ ] ; $ paramIndex = 0 ; $ params = [ ] ; foreach ( $ targetAction -> getParamCollection ( ) as $ param ) { $ params [ $ paramIndex ] = $ param ; $ paramName = $ param -> getName ( ) ; if ( isset ( $ indexedArgs [ $ paramIndex ] ) ) { $ preparedArgs [ $ paramIndex ] = $ indexedArgs [ $ paramIndex ] ; } foreach ( $ searchHashedArgs as $ searchHashedArg ) { if ( is_object ( $ searchHashedArg ) && $ searchHashedArg -> $ paramName ) { $ paramClass = $ param -> getType ( ) ; if ( $ paramClass ) { $ dryObject = new $ paramClass ( ) ; $ hydrator = new Hydrator ( ) ; $ hydratedObj = $ hydrator -> hydrateObject ( $ dryObject , $ searchHashedArg -> $ paramName ) ; $ preparedArgs [ $ paramIndex ] = $ hydratedObj ; continue ; } $ preparedArgs [ $ paramIndex ] = $ searchHashedArg -> $ paramName ; continue ; } if ( isset ( $ searchHashedArg [ $ paramName ] ) ) { $ obj = json_decode ( $ searchHashedArg [ $ paramName ] ) ; if ( $ obj ) { $ paramClass = $ param -> getType ( ) ; $ preparedArgs [ $ paramIndex ] = $ obj ; $ dryObject = new $ paramClass ( ) ; $ hydrator = new Hydrator ( ) ; $ hydratedObj = $ hydrator -> hydrateObject ( $ dryObject , $ obj ) ; $ preparedArgs [ $ paramIndex ] = $ hydratedObj ; continue ; } $ preparedArgs [ $ paramIndex ] = $ searchHashedArg [ $ paramName ] ; } } $ paramIndex ++ ; } return [ $ preparedArgs , $ params ] ; }
Prepare Args .
3,481
public function register ( ) { if ( isset ( $ this -> host , $ this -> port ) && ( $ cs = Yii :: app ( ) -> getComponent ( $ this -> clientScriptID ) ) !== null ) { $ cs -> registerScriptFile ( "//{$this->host}:{$this->port}/livereload.js" , CClientScript :: POS_END ) ; } }
Registers the live reload servers .
3,482
public function asString ( ) { $ query = '' ; if ( ! empty ( $ this -> list ) ) { foreach ( $ this -> list as $ clause ) { $ query .= $ clause -> asString ( ) ; } } return $ query ; }
Return the join of clauses as a string
3,483
protected function findFilesAsSplFileInfo ( string $ regex , string $ path ) { $ objects = new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $ path ) , RecursiveIteratorIterator :: SELF_FIRST ) ; $ filter = new RegexIterator ( $ objects , $ regex ) ; $ map = [ ] ; foreach ( $ filter as $ entry ) { $ map [ ] = $ entry ; } return count ( $ map ) > 0 ? $ map : [ ] ; }
Search config files
3,484
public function getThumbPath ( ) { return ( ! empty ( $ this -> thumb_path ) ? str_replace ( $ this -> getThumbRootDir ( ) , '' , DirectoryHelper :: slashDirname ( $ this -> thumb_path ) ) : '' ) ; }
Get the object s thumb web path
3,485
public function getVideoInfos ( ) { if ( ! $ this -> exists ( ) ) { return false ; } $ vid = new \ finfo ( FILEINFO_MIME_TYPE ) ; $ data = $ vid -> file ( $ this -> getRealPath ( ) ) ; return $ data ; }
Scan video standrad infos
3,486
public function thumbExists ( ) { $ thumb = $ this -> getThumbRealPath ( ) ; return ! empty ( $ thumb ) && @ file_exists ( $ thumb ) && @ is_file ( $ thumb ) ; }
Check if the thumb exists
3,487
public function create ( $ data ) { $ processPayload = $ this -> process ( __FUNCTION__ , $ data ) ; if ( ! $ processPayload -> isStatus ( Payload :: STATUS_VALID ) ) { return $ processPayload ; } $ entityContext = $ this -> formatEntityType ( $ processPayload -> getData ( ) [ 'entity_type' ] ) ; $ entityPayload = $ this -> aggregate [ $ entityContext ] -> create ( $ processPayload -> getData ( ) ) ; if ( $ entityPayload -> getStatus ( ) != 'created' ) { return $ entityPayload ; } $ identifierPayload = $ this -> createIdentifier ( $ entityPayload -> getData ( ) ) ; if ( $ identifierPayload -> getStatus ( ) != 'created' ) { return $ identifierPayload ; } $ createdEntityPayload = $ this -> getOneByUuid ( $ entityPayload -> getData ( ) -> getUuid ( ) ) ; if ( $ createdEntityPayload -> getStatus ( ) !== 'found' ) { return $ createdEntityPayload ; } return new Payload ( $ createdEntityPayload -> getData ( ) , $ entityPayload -> getStatus ( ) ) ; }
Create an Entity .
3,488
public function getOneByKey ( $ key ) { switch ( gettype ( $ key ) ) { case 'object' : return $ this -> getOneByIdentifier ( $ key ) ; break ; case 'array' : return $ this -> getOneByCompoundKey ( $ key ) ; break ; case 'string' : return $ this -> getOneByUuid ( $ key ) ; break ; default : return new Payload ( $ key , 'invalid_key_type' ) ; } }
Get an Entity by it s key .
3,489
protected function updateByType ( $ data , $ entity ) { switch ( gettype ( $ entity ) ) { case 'string' : $ entityPayload = $ this -> getOneByUuid ( $ entity ) ; if ( $ entityPayload -> getStatus ( ) != 'found' ) { return $ entityPayload ; } return $ this -> updateByEntity ( $ data , $ entityPayload -> getData ( ) -> first ( ) ) ; break ; case 'object' : switch ( $ entity -> getType ( true ) ) { case IdentifierServiceProvider :: getProviderKey ( ) : return $ this -> updateByIdentifier ( $ entity , $ data ) ; break ; default : if ( array_key_exists ( $ entity -> getType ( true ) , $ this -> getAggregate ( ) ) ) { return $ this -> updateByEntity ( $ data , $ entity ) ; } else { return new Payload ( null , $ entity -> getType ( ) . '_' . 'not_configured' ) ; } } break ; case 'array' : $ entityPayload = $ this -> getOneByCompoundKey ( $ entity ) ; if ( $ entityPayload -> getStatus ( ) != 'found' ) { return $ entityPayload ; } return $ this -> updateByEntity ( $ data , $ entityPayload -> getData ( ) ) ; break ; default : return new Payload ( null , 'invalid_entity' ) ; } }
Update an Entity by based on entity type .
3,490
protected function getOneByIdentifier ( $ identifier ) { return $ this -> aggregate [ IdentifierServiceProvider :: getProviderKey ( ) ] -> get ( [ [ 'field' => 'id' , 'value' => $ identifier -> getEntityKey ( ) , 'operator' => '=' , 'or' => false ] ] ) ; }
Get an Entity by a given EntityIdentifier .
3,491
protected function getOneByCompoundKey ( $ key ) { $ sanitizedKey = [ ] ; if ( $ this -> isAssociativeArray ( $ key ) ) { if ( array_key_exists ( 'entity_type' , $ key ) && array_key_exists ( 'entity_id' , $ key ) ) { $ sanitizedKey [ 'entity_type' ] = $ key [ 'entity_type' ] ; $ sanitizedKey [ 'entity_id' ] = $ key [ 'entity_id' ] ; } else { return new Payload ( null , 'insufficient_entity_key' ) ; } } else { $ sanitizedKey [ 'entity_type' ] = $ key [ 0 ] ; $ sanitizedKey [ 'entity_id' ] = $ key [ 1 ] ; } return $ this -> aggregate [ $ this -> formatEntityType ( $ sanitizedKey [ 'entity_type' ] ) ] -> get ( [ [ 'field' => 'id' , 'value' => $ sanitizedKey [ 'entity_id' ] , 'operator' => '=' , 'or' => false ] ] ) ; }
Get an Entity by it s compound key .
3,492
protected function setParameter ( $ key , $ value ) { if ( null !== $ this -> response ) { throw new RuntimeException ( 'Request cannot be modified after it has been sent!' ) ; } return $ this -> setParameterTrait ( $ key , $ value ) ; }
Set a single parameter
3,493
public function indexOf ( $ str , $ from = 0 , $ cs = CaseSensitivity :: CASE_INSENSITIVE ) { $ toSearch = ( string ) $ str ; switch ( $ cs ) { case CaseSensitivity :: CASE_INSENSITIVE : $ pos = stripos ( $ this -> text , $ toSearch , $ from ) ; break ; case CaseSensitivity :: CASE_SENSITIVE : $ pos = strpos ( $ this -> text , $ toSearch , $ from ) ; break ; default : throw new MWrongTypeException ( "\$cs" , "CaseSensitivity" , $ cs ) ; break ; } if ( $ pos === false ) { return - 1 ; } return $ pos ; }
Returns the index position of the first occurrence of the string str in this string searching forward from index position from . Returns - 1 if str is not found .
3,494
public function insert ( $ position , $ str ) { $ string = ( string ) $ str ; $ string = substr_replace ( $ this -> text , $ string , $ position , 0 ) ; return new MString ( $ string ) ; }
Inserts the string str at the given index position and returns a reference to this string .
3,495
public function remove ( $ pos , $ n ) { $ subString = substr ( ( string ) $ this , $ pos , $ n ) ; return $ this -> replace ( $ subString , MString :: EMPTY_STRING ) ; }
Removes n characters from the string starting at the given position index and returns a reference to the string . If the specified position index is within the string but position + n is beyond the end of the string the string is truncated at the specified position .
3,496
public function postChangePassword ( ) { $ user = Sentinel :: getUser ( ) ; $ validation = array ( 'password' => 'required|between:3,32' , 'password_confirm' => 'required|same:password' , ) ; $ validator = Validator :: make ( Input :: all ( ) , $ validation ) ; if ( $ validator -> fails ( ) ) { return Redirect :: back ( ) -> withInput ( ) -> withErrors ( $ validator ) ; } try { $ password = Input :: get ( 'password' ) ; if ( Sentinel :: validateCredentials ( $ user , [ 'email' => $ user -> email , 'password' => Input :: get ( 'old-password' ) ] ) ) { $ user -> password = Hash :: make ( $ password ) ; $ redirect = 'change-password' ; if ( $ user -> force_new_password ) { $ user -> force_new_password = 0 ; $ redirect = 'home' ; } if ( $ user -> save ( ) ) { $ success = Lang :: get ( 'base.auth.account.changed' ) ; Mail :: queue ( 'emails.account.password-changed' , [ 'user' => $ user ] , function ( $ m ) use ( $ user ) { $ m -> to ( $ user -> email , $ user -> first_name . ' ' . $ user -> last_name ) ; $ m -> subject ( Lang :: get ( 'base.mails.password_changed' ) ) ; } ) ; Base :: Log ( $ user -> username . ' (' . $ user -> first_name . ' ' . $ user -> last_name . ') changed its password account. ' ) ; return Redirect :: route ( $ redirect ) -> with ( 'success' , $ success ) ; } } else { $ error = Lang :: get ( 'base.auth.wrong_password' ) ; $ validator -> messages ( ) -> add ( 'old-password' , Lang :: get ( 'base.auth.wrong_password' ) ) ; return Redirect :: route ( 'change-password' ) -> withInput ( ) -> withErrors ( $ validator ) -> with ( 'error' , $ error ) ; } } catch ( Exception $ e ) { } $ error = Lang :: get ( 'base.base.error' ) ; return Redirect :: route ( 'change-password' ) -> withInput ( ) -> with ( 'error' , $ error ) ; }
Change password form processing page .
3,497
public function adminShow ( $ id ) { $ user = Sentinel :: findUserById ( $ id ) ; if ( $ user == null ) { $ error = Lang :: get ( 'base.auth.not_found' ) ; return Redirect :: route ( 'users' ) -> with ( 'error' , $ error ) ; } $ possibleStatus = $ this -> status ; $ logs = Base :: getLogsRepository ( ) -> where ( 'created_by' , $ user -> id ) -> orWhere ( 'target' , $ user -> id ) -> orderBy ( 'created_at' , 'desc' ) -> take ( 300 ) -> get ( [ 'ip' , 'log' , 'created_at' , 'created_by' , 'target' ] ) ; $ ips = Base :: getLogsRepository ( ) -> where ( 'created_by' , $ user -> id ) -> where ( 'log' , 'LIKE' , '%logged%' ) -> orderBy ( 'created_at' , 'desc' ) -> select ( 'ip' , DB :: raw ( 'count(*) as counter' ) , DB :: raw ( '(SELECT created_at FROM Logs WHERE IP=ip ORDER BY created_at DESC LIMIT 1 ) as created_at' ) ) -> groupBy ( 'ip' ) -> take ( 300 ) -> get ( ) ; return View ( 'admin.users.show' , compact ( 'user' , 'possibleStatus' , 'logs' , 'ips' ) ) ; }
Display specified user profile .
3,498
public function getAdminDelete ( $ id = null ) { $ user = Sentinel :: findById ( $ id ) ; if ( $ user == null ) { $ error = Lang :: get ( 'base.auth.not_found' ) ; return Redirect :: route ( 'users' ) -> with ( 'error' , $ error ) ; } if ( $ user -> id === Sentinel :: getUser ( ) -> id ) { $ error = Lang :: get ( 'base.base.error' ) ; return Redirect :: route ( 'users' ) -> with ( 'error' , $ error ) ; } Sentinel :: createModel ( ) -> destroy ( $ id ) ; $ success = Lang :: get ( 'base.auth.account.deleted' ) ; return Redirect :: route ( 'users' ) -> with ( 'success' , $ success ) ; }
Delete the given user .
3,499
public function getAdminRestore ( $ id = null ) { $ user = Sentinel :: createModel ( ) -> withTrashed ( ) -> find ( $ id ) ; if ( $ user == null ) { $ error = Lang :: get ( 'base.auth.not_found' ) ; return Redirect :: route ( 'users.deleted' ) -> with ( 'error' , $ error ) ; } $ user -> restore ( ) ; $ success = Lang :: get ( 'base.auth.account.restored' ) ; return Redirect :: route ( 'users.deleted' ) -> with ( 'success' , $ success ) ; }
Restore a deleted user .