idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
11,500
protected function validateIfDesired ( array $ input , AppliesToResource $ resource = null , $ locale = null ) { if ( ! $ this -> shouldValidate ) { return true ; } $ validator = $ this -> validator ? $ this -> validator : $ this -> validatorFactory -> make ( $ this -> validationRules , $ resource ) ; if ( ! $ validato...
Validate if validate is on .
11,501
public function all ( ) : array { $ out = [ ] ; foreach ( parent :: all ( ) as $ key => $ props ) { $ out [ $ props [ 'originalKey' ] ] = $ props [ 'value' ] ; } return $ out ; }
Return array of HTTP header names and values . This method returns the _original_ header name as specified by the end user .
11,502
public function attach ( $ eventName , callable $ handler , $ priority = 0 ) { if ( is_array ( $ eventName ) ) { foreach ( $ eventName as $ name ) { $ this -> attach ( $ name , $ handler , $ priority ) ; } return ; } if ( ! is_string ( $ eventName ) ) { throw new InvalidArgumentException ( sprintf ( '%s expects argumen...
Attach an handler to an event or multiple events .
11,503
public function detach ( $ eventName , callable $ handler ) { if ( isset ( $ this -> events [ $ eventName ] ) ) { $ this -> events [ $ eventName ] -> remove ( $ handler ) ; if ( 0 == count ( $ this -> events [ $ eventName ] ) ) { unset ( $ this -> events [ $ eventName ] ) ; } } }
Detach an handler from an event .
11,504
public function trigger ( $ eventName , $ target = null ) { $ event = $ this -> createEvent ( $ eventName ) ; $ event -> setTarget ( $ target ) ; $ this -> triggerHandlers ( $ event ) ; }
Create an event from the default event and trigger it s handlers .
11,505
protected function getHandlers ( $ eventName ) { return isset ( $ this -> events [ $ eventName ] ) ? $ this -> events [ $ eventName ] : new CallbackQueue ( ) ; }
Get handlers of an event .
11,506
protected function createEvent ( $ eventName ) { if ( null === $ this -> defaultEvent ) { return new Event ( $ eventName ) ; } $ event = clone $ this -> defaultEvent ; $ event -> setName ( $ eventName ) ; return $ event ; }
Create an event .
11,507
protected function triggerHandlers ( EventInterface $ event ) { foreach ( $ this -> getHandlers ( $ event -> getName ( ) ) as $ handler ) { call_user_func ( $ handler , $ event ) ; if ( $ event -> isPropagationStopped ( ) ) { break ; } } }
Trigger handlers of an event .
11,508
public function find ( $ id , array $ with = [ ] ) { $ query = $ this -> make ( $ with ) ; return $ query -> find ( $ id ) ; }
Find a specific record . Return null if not found .
11,509
public function findOrFail ( $ id , array $ with = [ ] ) { $ query = $ this -> make ( $ with ) ; return $ query -> findOrFail ( $ id ) ; }
Find a specific record . Throws exception if not found .
11,510
public function firstBy ( array $ where = [ ] , array $ with = [ ] ) { $ query = $ this -> make ( $ with ) ; $ query = $ this -> applyWhere ( $ query , $ where ) ; return $ query -> first ( ) ; }
Return the first record querying input parameters . Return null if no record is found .
11,511
public function firstOrFailBy ( array $ where = [ ] , array $ with = [ ] ) { $ query = $ this -> make ( $ with ) ; $ query = $ this -> applyWhere ( $ query , $ where ) ; return $ query -> firstOrFail ( ) ; }
Return the first record querying input parameters . Throws exception if no record is found .
11,512
public function getBy ( array $ where = [ ] , array $ with = [ ] ) { $ query = $ this -> make ( $ with ) ; $ query = $ this -> applyWhere ( $ query , $ where ) ; return $ query -> get ( ) ; }
Return records querying input parameters .
11,513
public function getHas ( string $ relation , array $ where = [ ] , array $ with = [ ] , int $ hasAtLeast = 1 ) { $ query = $ this -> make ( $ with ) ; $ query = $ this -> applyWhere ( $ query , $ where ) ; return $ query -> has ( $ relation , '>=' , $ hasAtLeast ) -> get ( ) ; }
Return all results that have a required relationship .
11,514
public function hasFirst ( string $ relation , array $ where = [ ] , array $ with = [ ] , int $ hasAtLeast = 1 ) { $ query = $ this -> make ( $ with ) ; $ query = $ this -> applyWhere ( $ query , $ where ) ; return $ query -> has ( $ relation , '>=' , $ hasAtLeast ) -> first ( ) ; }
Return the first result that has a required relationship . Return null if no record is found .
11,515
public function hasFirstOrFail ( string $ relation , array $ where = [ ] , array $ with = [ ] , int $ hasAtLeast = 1 ) { $ query = $ this -> make ( $ with ) ; $ query = $ this -> applyWhere ( $ query , $ where ) ; return $ query -> has ( $ relation , '>=' , $ hasAtLeast ) -> firstOrFail ( ) ; }
Return the first result that have a required relationship . Throws exception if no record is found .
11,516
public function whereHas ( $ relation , array $ where = [ ] , array $ whereHas = [ ] , array $ with = [ ] ) { $ query = $ this -> make ( $ with ) ; $ query = $ this -> applyWhere ( $ query , $ where ) ; $ query = $ query -> whereHas ( $ relation , function ( $ q ) use ( $ whereHas ) { $ this -> applyWhere ( $ q , $ whe...
Return all results that have a required relationship with input constraints .
11,517
public function getByPage ( int $ page = 1 , int $ limit = 10 , array $ where = [ ] , array $ with = [ ] , string $ orderBy = null , string $ order = 'desc' ) { $ query = $ this -> make ( $ with ) ; $ query = $ this -> applyWhere ( $ query , $ where ) ; if ( $ orderBy ) { $ query = $ query -> orderBy ( $ orderBy , $ or...
Get ordered results by Page .
11,518
public function insert ( array $ collection ) { foreach ( $ collection as $ key => $ inputs ) { $ collection [ $ key ] = $ this -> purifyInputs ( $ inputs ) ; } return $ this -> model -> insert ( $ collection ) ; }
Create a collection of new records .
11,519
public function update ( array $ inputs ) { $ inputs = $ this -> purifyInputs ( $ inputs ) ; return $ this -> model -> update ( $ inputs ) ; }
Update all records .
11,520
public function updateById ( $ id , array $ inputs ) { $ inputs = $ this -> purifyInputs ( $ inputs ) ; $ model = $ this -> model -> findOrFail ( $ id ) ; return $ model -> update ( $ inputs ) ; }
Update an existing record retrieved by id .
11,521
public function updateBy ( array $ where , array $ inputs ) { $ inputs = $ this -> purifyInputs ( $ inputs ) ; $ query = $ this -> make ( ) ; $ query = $ this -> applyWhere ( $ query , $ where ) ; return $ query -> update ( $ inputs ) ; }
Update all records matching input parameters .
11,522
public function updateOrCreateBy ( array $ where , array $ inputs = [ ] ) { $ inputs = $ this -> purifyInputs ( $ inputs ) ; $ query = $ this -> make ( ) ; $ query = $ this -> applyWhere ( $ query , $ where ) ; $ model = $ query -> first ( ) ; if ( $ model ) { $ model -> update ( $ inputs ) ; return $ model ; } else { ...
Update the record matching input parameters . If no record is found create a new one .
11,523
public function destroyBy ( array $ where ) { $ query = $ this -> make ( ) ; $ query = $ this -> applyWhere ( $ query , $ where ) ; return $ query -> delete ( ) ; }
Retrieve and delete the all records matching input parameters .
11,524
public function countBy ( array $ where = [ ] ) { $ query = $ this -> make ( ) ; $ query = $ this -> applyWhere ( $ query , $ where ) ; return $ query -> count ( ) ; }
Count the number of records matching input parameters .
11,525
public function countWhereHas ( $ relation , array $ where = [ ] , array $ whereHas = [ ] ) { $ query = $ this -> make ( ) ; $ query = $ this -> applyWhere ( $ query , $ where ) ; $ query = $ query -> whereHas ( $ relation , function ( $ q ) use ( $ whereHas ) { $ this -> applyWhere ( $ q , $ whereHas ) ; } ) ; return ...
Count all records that have a required relationship and matching input parameters ..
11,526
public function generate ( $ location , array $ options = [ ] ) { $ uri = $ this -> fetchUrl ( $ location , $ options ) ; $ this -> decorate ( $ uri ) ; return $ uri ; }
Generates an URL location from provided data
11,527
private function fetchUrl ( $ location , array $ options = [ ] ) { $ uri = null ; foreach ( $ this -> transformers as $ transformer ) { $ this -> setContext ( $ transformer ) ; $ object = $ transformer -> transform ( $ location , $ options ) ; if ( $ object instanceof UriInterface ) { $ uri = $ object ; break ; } } ret...
Fetch the URI form the list of transformers
11,528
private function decorate ( UriInterface $ uri = null ) { foreach ( $ this -> decorators as $ decorator ) { $ decorator -> decorate ( $ uri ) ; } }
Applies decorators to the provided URI
11,529
protected function checkType ( $ value ) { if ( ! $ value instanceof AssetContract ) { throw new InvalidArgumentException ( "You can only add values of '{$this->forceType}' to this list" ) ; } if ( ! $ mimeType = $ value -> mimeType ( ) ) { throw new InvalidArgumentException ( 'The added asset must have a mimeType to a...
Checks the type of any added item and throws an exception if it does not match .
11,530
public function getInstance ( $ name , $ parameters = [ ] ) { $ class = $ this -> baseNamespace . ucfirst ( $ name ) ; if ( ! empty ( $ this -> addedClasses [ $ name ] ) ) { $ class = $ this -> addedClasses [ $ name ] ; } if ( ! class_exists ( $ class ) ) { throw new InvalidArgumentException ( "$name is not a known cla...
Returns a constructed instance of the named class .
11,531
protected function arrayToKey ( array $ array ) { if ( $ this -> isSequential ( $ array ) ) { return $ this -> sequentialArrayToKey ( $ array ) ; } $ parts = [ ] ; $ keys = array_keys ( $ array ) ; sort ( $ keys ) ; foreach ( $ keys as $ key ) { $ parts [ ] = $ key ; $ parts [ ] = $ this -> castArrayValue ( $ array [ $...
Turns an array into a key .
11,532
protected function sequentialArrayToKey ( array $ array ) { if ( $ this -> isObjectAndId ( $ array ) ) { return get_class ( $ array [ 0 ] ) . '-' . $ array [ 1 ] ; } $ parts = [ ] ; foreach ( $ array as $ value ) { $ parts [ ] = $ this -> castArrayValue ( $ this -> key ( $ value ) ) ; } return implode ( '_' , $ parts )...
Turns an strictly sequential array into a key .
11,533
protected function objectToKey ( $ object ) { $ typeName = $ object instanceof AppliesToResource ? $ object -> resourceName ( ) : get_class ( $ object ) ; if ( ! $ object instanceof Identifiable ) { throw new InvalidArgumentException ( 'Cannot generate cache id of unknown class ' . get_class ( $ object ) ) ; } return $...
Turns an object into a key .
11,534
protected function castArrayValue ( $ value ) { if ( ! is_object ( $ value ) ) { return $ this -> key ( $ value ) ; } try { if ( $ key = $ this -> objectCategorizer -> key ( $ value ) ) { return $ this -> hashIfToLong ( $ key ) ; } } catch ( Exception $ e ) { } return $ this -> hashIfToLong ( $ this -> objectToKey ( $ ...
Casts an array value . Is used different to avoid endless recursion .
11,535
protected function forkWith ( $ key , $ value ) { $ attributes = $ this -> attributes ; $ attributes [ $ key ] = $ value ; return $ this -> fork ( $ attributes ) ; }
Create a new fork with the given job attribute
11,536
final public static function getServerInfo ( string $ infoname ) : string { switch ( $ infoname ) { case 'PHP_VERSION' : $ rs = phpversion ( ) ; break ; default : try { $ rs = $ _SERVER [ $ infoname ] ; } catch ( \ Exception $ e ) { throw new Server500 ( new \ ArrayObject ( array ( "explain" => "Core Error: The server ...
Get info about current server
11,537
protected function collectAllTraits ( ) { if ( $ this -> _allTraits === null ) { $ this -> _allTraits = Type :: traits ( $ this , true ) ; unset ( $ this -> _allTraits [ TraitMethods :: class ] ) ; } return $ this -> _allTraits ; }
Collect all traits that should be called .
11,538
public function getLanguageValues ( $ asArray = null ) { if ( ! $ this -> owner -> getIsNewRecord ( ) && $ this -> _languageValues === null ) { $ this -> _languageValues = [ ] ; foreach ( $ this -> owner -> { $ this -> languageRelation } as $ language ) { $ this -> _languageValues [ ] = $ language -> getAttribute ( $ t...
Returns languages .
11,539
public function addLanguageValues ( $ values ) { $ this -> _languageValues = array_unique ( array_merge ( $ this -> getLanguageValues ( true ) , $ this -> filterLanguageValues ( $ values ) ) ) ; }
Adds languages .
11,540
public function removeLanguageValues ( $ values ) { $ this -> _languageValues = array_diff ( $ this -> getLanguageValues ( true ) , $ this -> filterLanguageValues ( $ values ) ) ; }
Removes languages .
11,541
public function hasLanguageValues ( $ values ) { $ tagValues = $ this -> getLanguageValues ( true ) ; foreach ( $ this -> filterLanguageValues ( $ values ) as $ value ) { if ( ! in_array ( $ value , $ tagValues ) ) { return false ; } } return true ; }
Returns a value indicating whether languages exists .
11,542
public function filterLanguageValues ( $ values ) { return array_unique ( preg_split ( '/\s*,\s*/u' , preg_replace ( '/\s+/u' , ' ' , is_array ( $ values ) ? implode ( ',' , $ values ) : $ values ) , - 1 , PREG_SPLIT_NO_EMPTY ) ) ; }
Filters languages .
11,543
public function MetaTags ( $ includeTitle = true ) { $ tags = array ( ) ; if ( $ includeTitle && strtolower ( $ includeTitle ) != 'false' ) { $ title = $ this -> owner -> MetaTitle ? $ this -> owner -> MetaTitle : $ this -> owner -> Title ; $ tags [ ] = HTML :: createTag ( 'title' , array ( ) , $ title ) ; } $ generato...
Generate custom meta tags to display on the DataObject view page .
11,544
public function Breadcrumbs ( $ maxDepth = 20 , $ unlinked = false , $ stopAtPageType = false , $ showHidden = false ) { $ page = Controller :: curr ( ) ; $ pages = array ( ) ; $ pages [ ] = $ this -> owner ; while ( $ page && ( ! $ maxDepth || count ( $ pages ) < $ maxDepth ) && ( ! $ stopAtPageType || $ page -> Class...
Produce the correct breadcrumb trail for use on the DataObject Item Page .
11,545
public static function instances ( ) : BaseCollection { $ instances = new BaseCollection ; foreach ( static :: make ( ) -> all ( ) as $ key => $ value ) { if ( $ instance = self :: instance ( $ key ) ) { $ instances -> put ( $ key , $ instance ) ; } } return $ instances ; }
Returns a collection of item instances
11,546
public static function instance ( string $ key ) { $ collection = static :: make ( ) ; $ class = $ collection -> get ( $ key ) ; if ( class_exists ( $ class ) ) { return resolve ( $ class ) ; } return null ; }
Create an instance of a collection item
11,547
function via ( $ key ) { if ( ! $ this -> parent_ ) throw new \ LogicException ( 'Cannot set reference key on basic Result' ) ; $ clone = clone $ this ; if ( $ clone -> single ) { $ clone -> parentKey = $ key ; } else { $ clone -> key = $ key ; } return $ clone ; }
Create result with new reference key
11,548
function execute ( ) { if ( isset ( $ this -> rows ) ) return $ this ; if ( $ this -> parent_ ) { $ this -> where [ ] = $ this -> db -> is ( $ this -> key , $ this -> parent_ -> getGlobalKeys ( $ this -> parentKey ) ) ; } $ root = $ this -> getRoot ( ) ; $ definition = $ this -> getDefinition ( ) ; $ cached = $ root ->...
Execute the select query defined by this result .
11,549
function fetch ( ) { $ this -> execute ( ) ; list ( $ index , $ row ) = each ( $ this -> rows ) ; return $ row ; }
Fetch the next row in this result
11,550
function delete ( ) { if ( $ this -> parent_ || isset ( $ this -> limitCount ) ) { return $ this -> primaryResult ( ) -> delete ( ) ; } return $ this -> db -> delete ( $ this -> table , $ this -> where , $ this -> whereParams ) ; }
Delete all rows matched by this result
11,551
function primaryResult ( ) { $ result = $ this -> db -> table ( $ this -> table ) ; $ primary = $ this -> db -> getPrimary ( $ this -> table ) ; if ( is_array ( $ primary ) ) { $ this -> execute ( ) ; $ or = array ( ) ; foreach ( $ this -> rows as $ row ) { $ and = array ( ) ; foreach ( $ primary as $ column ) { $ and ...
Return a new basic result which selects all rows in this result by primary key
11,552
function select ( $ expr ) { $ clone = clone $ this ; if ( $ clone -> select === null ) { $ clone -> select = func_get_args ( ) ; } else { $ clone -> select = array_merge ( $ clone -> select , func_get_args ( ) ) ; } return $ clone ; }
Return a new result with an additional expression to the SELECT part
11,553
function orderBy ( $ column , $ direction = "ASC" ) { $ clone = clone $ this ; if ( $ direction === true ) { $ clone -> orderBy [ ] = $ column ; } else { $ clone -> orderBy [ ] = $ this -> db -> quoteIdentifier ( $ column ) . " " . $ direction ; } return $ clone ; }
Add an ORDER BY column and direction
11,554
function limit ( $ count , $ offset = null ) { if ( $ this -> parent_ ) { throw new \ LogicException ( 'Cannot limit referenced result' ) ; } $ clone = clone $ this ; $ clone -> limitCount = $ count ; $ clone -> limitOffset = $ offset ; return $ clone ; }
Set a result limit and optionally an offset
11,555
function aggregate ( $ function ) { if ( $ this -> parent_ ) { throw new \ LogicException ( 'Cannot aggregate referenced result' ) ; } $ statement = $ this -> db -> select ( $ this -> table , array ( 'expr' => $ function , 'where' => $ this -> where , 'orderBy' => $ this -> orderBy , 'limitCount' => $ this -> limitCoun...
Execute aggregate function and return value
11,556
function getDefinition ( ) { return json_encode ( array ( 'table' => $ this -> table , 'select' => $ this -> select , 'where' => $ this -> where , 'whereParams' => $ this -> whereParams , 'orderBy' => $ this -> orderBy , 'limitCount' => $ this -> limitCount , 'limitOffset' => $ this -> limitOffset ) ) ; }
Get a JSON string defining the SELECT information of this Result Used as identification in caches
11,557
public static function show ( $ value , $ name = null ) { $ file = __DIR__ . '/../../' . DIR_LANGUAGE . LANGUAGE_CODE . DS . "$name.php" ; if ( is_readable ( $ file ) ) { } else { echo Exception :: langNotLoad ( ) ; } if ( ! empty ( $ array [ $ value ] ) ) { return $ array [ $ value ] ; } else { return $ value ; } }
Get lang for views .
11,558
public function setUrl ( UrlContract $ url ) { $ this -> url = $ url ; $ this -> dirExists = null ; return $ this ; }
Set the directory url
11,559
protected function preloadAllStorages ( ) { if ( $ this -> allStoragesLoaded ) { return $ this -> storages ; } $ filesAndDirs = $ this -> filesystem -> listDirectory ( $ this -> url , true , false ) ; foreach ( $ filesAndDirs as $ file ) { if ( $ this -> filesystem -> extension ( $ file ) != $ this -> fileExtension ( )...
Read all storages to have all the data .
11,560
protected function createFileStorage ( ) { return call_user_func ( $ this -> fileStorageCreator , $ this -> filesystem , $ this -> serializer , $ this -> mimetypes ) ; }
Create a file storage object
11,561
protected function copyOptionsToFileStorage ( SingleFileStorage $ fileStorage ) { foreach ( $ this -> supportedOptions ( ) as $ key ) { $ fileStorage -> setOption ( $ key , $ this -> getOption ( $ key ) ) ; } $ fileStorage -> setSerializeOptions ( $ this -> serializeOptions ) ; $ fileStorage -> setDeserializeOptions ( ...
Apply own options to FileStorage
11,562
protected function fileUrlAndKey ( $ key ) { if ( isset ( $ this -> keyUrlCache [ $ key ] ) ) { return $ this -> keyUrlCache [ $ key ] ; } $ parts = explode ( '.' , $ key ) ; $ url = $ this -> urlOrFail ( ) ; $ partCount = count ( $ parts ) ; if ( $ partCount <= $ this -> nestingLevel ) { $ minLength = $ this -> nestin...
Extract the file url and the key to query the storage .
11,563
public static final function ppath ( $ path ) { while ( ! is_dir ( $ path ) && strlen ( $ path ) > 0 ) { $ path = preg_replace ( '/[^\/]+\/?$/' , null , $ path ) ; } return ! empty ( $ path ) ? $ path : false ; }
Returns first existing parent directory from given path .
11,564
protected function reorder ( $ parentId = 0 ) { $ query = call_user_func ( "$this->ownerClassName::find" ) -> select ( "$this->primaryKey" ) -> orderBy ( "$this->sortField, $this->primaryKey" ) ; if ( $ this -> parentIdField ) { $ query -> where ( [ $ this -> parentIdField => $ parentId ] ) ; } $ data = array_map ( 'in...
Reordering models when no more exist free indexes
11,565
protected function getMinIdx ( $ parentId = 0 , $ moreThen = false ) { $ query = call_user_func ( "$this->ownerClassName::find" ) -> select ( "MIN($this->sortField)" ) ; if ( $ moreThen !== false ) { $ query -> where ( [ '>' , $ this -> sortField , $ moreThen ] ) ; } if ( $ this -> parentIdField ) { $ query -> andWhere...
Find min index
11,566
private function getMaxIdx ( $ parentId = 0 , $ lessThen = false ) { $ query = call_user_func ( "$this->ownerClassName::find" ) -> select ( "MAX($this->sortField)" ) ; if ( $ lessThen !== false ) { $ query -> where ( [ '<' , $ this -> sortField , $ lessThen ] ) ; } if ( $ this -> parentIdField ) { $ query -> andWhere (...
Find max index
11,567
public function moveFirst ( $ parentId = false ) { if ( $ this -> parentIdField && $ parentId === false ) { $ parentId = $ this -> owner -> { $ this -> parentIdField } ; } $ minIdx = $ this -> getMinIdx ( $ parentId ) ; if ( ! $ minIdx ) { $ this -> reorder ( $ parentId ) ; $ minIdx = $ this -> getMinIdx ( $ parentId )...
Move model to first
11,568
public function moveLast ( $ parentId = false ) { if ( $ this -> parentIdField && $ parentId === false ) { $ parentId = $ this -> owner -> { $ this -> parentIdField } ; } $ maxIdx = $ this -> getMaxIdx ( $ parentId ) ; if ( $ maxIdx == $ this -> defaultSortVal ) { $ this -> reorder ( $ parentId ) ; $ maxIdx = $ this ->...
Move model to last
11,569
private static function getChildrenIdRec ( $ ids , $ className , $ primaryKey , $ parentIdField , $ recursive ) { $ subIds = array_map ( 'intval' , $ className :: find ( ) -> select ( $ primaryKey ) -> where ( [ $ parentIdField => $ ids ] ) -> column ( ) ) ; if ( $ subIds ) { if ( $ recursive ) { return array_merge ( $...
Recursive method to get all children id including subid
11,570
public function getChildrenId ( $ includeSelf = true , $ all = true ) { $ cacheKey = [ 'class' => self :: className ( ) , 'ownerClass' => $ this -> ownerClassName , 'method' => 'getChildrenId' , 'id' => $ this -> owner -> { $ this -> primaryKey } , 'all' => $ all , ] ; $ ids = $ this -> cache -> getOrSet ( $ cacheKey ,...
Return all children id including subid
11,571
public function getChildren ( ) { return $ this -> owner -> hasMany ( $ this -> ownerClassName , [ $ this -> parentIdField => $ this -> primaryKey ] ) -> orderBy ( [ "$this->tableName.$this->sortField" => SORT_ASC , "$this->tableName.$this->primaryKey" => SORT_ASC , ] ) ; }
Return next level children
11,572
public function getAllChildren ( $ includeSelf = false ) { return call_user_func ( "$this->ownerClassName::find" ) -> where ( [ $ this -> primaryKey => $ this -> getChildrenId ( $ includeSelf ) , ] ) -> orderBy ( "$this->parentIdField ASC, $this->sortField ASC, $this->primaryKey ASC" ) ; }
Return all children including subchildren
11,573
public function getParentsId ( $ includeSelf = false ) { $ cacheKey = [ 'class' => self :: className ( ) , 'ownerClass' => $ this -> ownerClassName , 'method' => 'getParentsId' , 'id' => $ this -> owner -> { $ this -> primaryKey } , ] ; if ( $ this -> owner -> { $ this -> parentIdField } ) { $ parents = $ this -> cache...
Return parents id ordered by level
11,574
public function getParents ( $ includeSelf = false ) { $ parentsId = $ this -> getParentsId ( $ includeSelf ) ; $ orderBy = [ ] ; foreach ( $ parentsId as $ id ) { $ orderBy [ ] = "`$this->primaryKey` = $id DESC" ; } return call_user_func ( "$this->ownerClassName::find" ) -> where ( [ $ this -> primaryKey => $ parentsI...
Return parents ordered by level
11,575
public function getRoot ( ) { if ( $ this -> owner -> { $ this -> parentIdField } ) { return Yii :: $ app -> db -> cache ( function ( ) { return call_user_func ( "$this->ownerClassName::findOne" , current ( $ this -> getParentsId ( ) ) ) ; } , null , $ this -> getTagDependency ( ) ) ; } else { return $ this -> owner ; ...
Return root model of this model
11,576
private function prepareCrumb ( $ model , $ callable , $ isRoot , $ isLeaf ) { return $ callable ? $ callable ( $ model , $ isRoot , $ isLeaf ) : $ model -> { $ this -> titleField } ; }
Output model as crumb
11,577
public function getFullPath ( $ delimeter = " &rarr; " , $ callable = false ) { $ parents = $ this -> owner -> getParents ( ) -> all ( ) ; if ( ! $ parents ) { return $ this -> prepareCrumb ( $ this -> owner , $ callable , true , true ) ; } else { $ crumbs = [ $ this -> prepareCrumb ( array_shift ( $ parents ) , $ call...
Return full path of model
11,578
public function getJointParent ( $ model , $ includeSelf = false ) { if ( is_numeric ( $ model ) ) { $ model = call_user_func ( "$this->ownerClassName::findOne" , $ model ) ; } if ( $ this -> owner -> { $ this -> parentIdField } == $ model -> { $ this -> parentIdField } ) { return $ this -> getParent ( ) ; } $ ownerPar...
Return joint parent of two models or false if it s not exists .
11,579
public function getTreeIds ( $ includeSelf = true , $ includeParents = false ) { if ( $ includeParents ) { return array_merge ( $ this -> getParentsId ( ) , $ this -> getChildrenId ( $ includeSelf ) ) ; } else { return $ this -> getChildrenId ( $ includeSelf ) ; } }
Returns ids of children and subchildren of current model .
11,580
public function getTree ( $ includeSelf = true , $ includeParents = false ) { return call_user_func ( "$this->ownerClassName::find" ) -> where ( [ $ this -> primaryKey => $ this -> getTreeIds ( $ includeSelf , $ includeParents ) , ] ) -> orderBy ( [ "$this->tableName.$this->parentIdField" => SORT_ASC , "$this->tableNam...
Returns ActiveQuery to select children and subchildren of current model .
11,581
public function validateRequest ( $ token ) { if ( empty ( $ token ) ) { $ this -> _badToken401 ( ) ; } $ validateResponse = $ this -> _validate ( $ token ) ; if ( ( ! is_array ( $ validateResponse ) ) || ( ! array_key_exists ( 'sub' , $ validateResponse ) ) ) { $ this -> _badToken401 ( ) ; } if ( array_key_exists ( 's...
Validates a request and returns a 401 when not authorized
11,582
private function _badToken401 ( ) { $ this -> addCorsHeaders ( ) ; Utils :: header ( "HTTP/1.1 401 Unauthorized" ) ; Utils :: header ( 'Content-type: application/json' ) ; echo json_encode ( ( object ) [ 'tokenService' => $ this -> _tokenServiceUrl . "login?" . http_build_query ( [ 'redirectURL' => $ this -> _refUrl , ...
Returns a 401 response with the referred URL and the app ID in a JSON response
11,583
public function addCorsHeaders ( ) { if ( isset ( $ this -> _corsConfig [ 'origin' ] ) ) { Utils :: header ( "Access-Control-Allow-Origin: " . $ this -> _corsConfig [ 'origin' ] ) ; } else { Utils :: header ( "Access-Control-Allow-Origin: '*'" ) ; } if ( isset ( $ this -> _corsConfig [ 'allowCredentials' ] ) ) { Utils ...
Add the CORS headers to the response .
11,584
private function _validate ( $ token ) { $ request = $ this -> _httpClient -> createRequest ( 'POST' , $ this -> _tokenServiceUrl . 'validate' ) ; $ postBody = $ request -> getBody ( ) ; $ postBody -> setField ( 'service' , $ this -> _appID ) ; $ postBody -> setField ( 'token' , $ token ) ; try { $ response = $ this ->...
Used to _validate an existing token
11,585
private function _setAttributes ( ) { if ( isset ( $ this -> _tokenData [ 'sub' ] ) ) { $ user_data = $ this -> _tokenData ; unset ( $ user_data [ 'sub' ] ) ; unset ( $ user_data [ 'exp' ] ) ; unset ( $ user_data [ 'nbf' ] ) ; unset ( $ user_data [ 'aud' ] ) ; unset ( $ user_data [ 'iss' ] ) ; unset ( $ user_data [ 'jt...
Set the principal s attributes
11,586
public function saved ( Model $ model ) { $ tags = $ this -> processTags ( request ( 'tags' ) ) ; $ this -> syncTags ( $ model , $ tags ) ; }
On save process tags .
11,587
protected function processTags ( $ tags ) { if ( ! $ tags ) { return [ ] ; } $ tags = explode ( ',' , $ tags ) ; foreach ( $ tags as $ key => $ tag ) { $ tags [ $ key ] = trim ( $ tag ) ; } return $ tags ; }
Convert string of tags to array .
11,588
public function buildContent ( ) { $ contents = $ this -> contents ; array_unshift ( $ contents , '#boundary start ' . $ this -> getBoundary ( ) ) ; array_push ( $ contents , '#boundary end ' . $ this -> getBoundary ( ) ) ; return $ contents ; }
Returns new inner content
11,589
public function shuffle ( $ seed = null ) { $ items = $ this -> items ; if ( is_null ( $ seed ) ) { shuffle ( $ items ) ; } else { srand ( $ seed ) ; usort ( $ items , function ( ) { return rand ( - 1 , 1 ) ; } ) ; } return new static ( $ items ) ; }
Shuffle the items in the collection .
11,590
public function importFile ( string $ assetPathToMap ) : void { try { $ filePath = $ this -> namespaceRegistry -> getFilePath ( Asset :: createFromAssetPath ( $ assetPathToMap ) ) ; if ( \ is_file ( $ filePath ) ) { $ map = \ json_decode ( \ file_get_contents ( $ filePath ) , true ) ; if ( null !== $ map ) { $ this -> ...
Imports all dependencies from the given dependencies file
11,591
public function importMap ( string $ basePath , array $ dependencyMap ) : void { $ basePath = rtrim ( $ basePath , "/" ) ; foreach ( $ dependencyMap as $ file => $ dependencies ) { foreach ( $ dependencies as $ dependency ) { if ( "js" === pathinfo ( $ dependency , PATHINFO_EXTENSION ) ) { $ this -> dependencyMap [ "{$...
Imports dependencies from the given map
11,592
public static function toArray ( $ object ) : array { $ array = array ( ) ; $ class = get_class ( $ object ) ; $ methods = get_class_methods ( $ class ) ; foreach ( $ methods as $ method ) { preg_match ( ' /^(get)(.*?)$/i' , $ method , $ results ) ; $ pre = $ results [ 1 ] ?? '' ; $ k = $ results [ 2 ] ?? '' ; $ k = st...
Extract values from an object converting the object to an associative array
11,593
protected function getSwiftMessage ( MessageContract $ message ) { $ swiftMessage = $ message -> _swiftMessage ( ) ; if ( ! $ swiftMessage instanceof Swift_Message ) { throw new UnexpectedValueException ( 'Swift\Transport can only send messages with swift messages' ) ; } return $ swiftMessage ; }
Get the swift message out of an message .
11,594
protected function guessRecipient ( MessageContract $ message ) { if ( $ recipient = $ message -> recipient ( ) ) { return $ recipient ; } $ swiftMessage = $ this -> getSwiftMessage ( $ message ) ; if ( ! $ to = $ swiftMessage -> getTo ( ) ) { return null ; } if ( ! count ( $ to ) ) { return null ; } return $ to [ 0 ] ...
Try to guess the reciepient of the message to add it to the failures .
11,595
public function ruleValue ( $ value = null ) { if ( \ func_num_args ( ) > 0 ) { if ( null !== $ value && $ this -> validateValue ( $ value ) ) { $ this -> value = $ value ; $ this -> updateBound ( ) ; return true ; } return false ; } return $ this -> value ; }
Get or set the value .
11,596
public function counter ( $ metric , $ count = 1 , array $ tags = array ( ) , $ sampleRate = AbstractMetric :: DEFAULT_SAMPLE_RATE ) { try { $ this -> sendMetric ( $ this -> metricFactory -> counter ( $ metric , $ count , $ tags , $ sampleRate ) ) ; } catch ( \ Exception $ exception ) { $ this -> logException ( $ excep...
Sends a counter metric
11,597
public function gauge ( $ metric , $ level , array $ tags = array ( ) , $ sampleRate = AbstractMetric :: DEFAULT_SAMPLE_RATE ) { try { $ this -> sendMetric ( $ this -> metricFactory -> gauge ( $ metric , $ level , $ tags , $ sampleRate ) ) ; } catch ( \ Exception $ exception ) { $ this -> logException ( $ exception ) ;...
Sends a gauge metric
11,598
public function set ( $ metric , $ uniqueValue , array $ tags = array ( ) , $ sampleRate = AbstractMetric :: DEFAULT_SAMPLE_RATE ) { try { $ this -> sendMetric ( $ this -> metricFactory -> set ( $ metric , $ uniqueValue , $ tags , $ sampleRate ) ) ; } catch ( \ Exception $ exception ) { $ this -> logException ( $ excep...
Sends a set metric
11,599
public function histogram ( $ metric , $ duration , array $ tags = array ( ) , $ sampleRate = AbstractMetric :: DEFAULT_SAMPLE_RATE ) { try { $ this -> sendMetric ( $ this -> metricFactory -> histogram ( $ metric , $ duration , $ tags , $ sampleRate ) ) ; } catch ( \ Exception $ exception ) { $ this -> logException ( $...
Sends an histogram