idx
int64
0
60.3k
question
stringlengths
99
4.85k
target
stringlengths
5
718
4,100
public function getQuery ( string $ type = 'select' , ... $ arguments ) : QueryObject { $ allowedTypes = [ 'select' , 'insert' , 'insertignore' , 'replace' , 'delete' , 'update' , 'criteriaonly' , ] ; if ( \ in_array ( strtolower ( $ type ) , $ allowedTypes , true ) === false ) { throw new Exception ( $ type . ' is not...
Returns Query - object .
4,101
public function fireEvents ( string $ name , QueryObject $ queryObject , array $ eventArguments = [ ] ) : void { $ this -> connection -> getEventHandler ( ) -> fireEvents ( $ name , $ queryObject , $ this , $ eventArguments ) ; }
Fires event by given event name
4,102
protected function parseParameterType ( $ value ) : int { if ( $ value === null ) { return PDO :: PARAM_NULL ; } if ( \ is_int ( $ value ) === true || \ is_bool ( $ value ) === true ) { return PDO :: PARAM_INT ; } return PDO :: PARAM_STR ; }
Parse parameter type from value
4,103
protected function addStatement ( string $ key , $ value ) : void { if ( array_key_exists ( $ key , $ this -> statements ) === false ) { $ this -> statements [ $ key ] = ( array ) $ value ; } else { $ this -> statements [ $ key ] = array_merge ( $ this -> statements [ $ key ] , ( array ) $ value ) ; } }
Add new statement to statement - list
4,104
public function from ( $ tables = null ) : IQueryBuilderHandler { if ( $ tables === null ) { $ this -> statements [ 'tables' ] = null ; return $ this ; } if ( \ is_array ( $ tables ) === false ) { $ tables = \ func_get_args ( ) ; } $ tTables = [ ] ; foreach ( ( array ) $ tables as $ key => $ value ) { if ( \ is_string ...
Adds FROM statement to the current query .
4,105
public function subQuery ( QueryBuilderHandler $ queryBuilder , $ alias = null ) : Raw { $ sql = '(' . $ queryBuilder -> getQuery ( ) -> getRawSql ( ) . ')' ; if ( $ alias !== null ) { $ sql = $ sql . ' AS ' . $ this -> adapterInstance -> wrapSanitizer ( $ alias ) ; } return $ queryBuilder -> raw ( $ sql ) ; }
Performs new sub - query . Call this method when you want to add a new sub - query in your where etc .
4,106
public function raw ( string $ value , $ bindings = null ) : Raw { if ( \ is_array ( $ bindings ) === false ) { $ bindings = \ func_get_args ( ) ; array_shift ( $ bindings ) ; } return new Raw ( $ value , $ bindings ) ; }
Adds a raw string to the current query . This query will be ignored from any parsing or formatting by the Query builder and should be used in conjunction with other statements in the query .
4,107
public function delete ( array $ columns = null ) : \ PDOStatement { $ queryObject = $ this -> getQuery ( 'delete' , $ columns ) ; $ this -> connection -> setLastQuery ( $ queryObject ) ; $ this -> fireEvents ( EventHandler :: EVENT_BEFORE_DELETE , $ queryObject ) ; [ $ response , $ executionTime ] = $ this -> statemen...
Forms delete on the current query .
4,108
public function where ( $ key , $ operator = null , $ value = null ) : IQueryBuilderHandler { if ( \ func_num_args ( ) === 2 ) { $ value = $ operator ; $ operator = '=' ; } if ( \ is_bool ( $ value ) === true ) { $ value = ( int ) $ value ; } return $ this -> whereHandler ( $ key , $ operator , $ value ) ; }
Adds WHERE statement to the current query .
4,109
public function getEvent ( string $ name , string $ table = null ) : ? callable { return $ this -> connection -> getEventHandler ( ) -> getEvent ( $ name , $ table ) ; }
Get event by event name
4,110
public function groupBy ( $ field ) : IQueryBuilderHandler { if ( ( $ field instanceof Raw ) === false ) { $ field = $ this -> addTablePrefix ( $ field ) ; } if ( \ is_array ( $ field ) === true ) { $ this -> statements [ 'groupBys' ] = array_merge ( $ this -> statements [ 'groupBys' ] , $ field ) ; } else { $ this -> ...
Adds GROUP BY to the current query .
4,111
public function join ( $ table , $ key = null , $ operator = null , $ value = null , $ type = '' ) : IQueryBuilderHandler { $ joinBuilder = null ; if ( $ key !== null ) { $ joinBuilder = new JoinBuilder ( $ this -> connection ) ; if ( $ key instanceof \ Closure === false ) { $ key = function ( JoinBuilder $ joinBuilder...
Adds new JOIN statement to the current query .
4,112
public function transaction ( \ Closure $ callback ) : Transaction { $ queryTransaction = new Transaction ( $ this -> connection ) ; $ queryTransaction -> statements = $ this -> statements ; try { if ( $ this -> pdo ( ) -> inTransaction ( ) === false ) { $ this -> pdo ( ) -> beginTransaction ( ) ; } $ callback ( $ quer...
Performs the transaction
4,113
public function orHaving ( $ key , $ operator , $ value ) : IQueryBuilderHandler { return $ this -> having ( $ key , $ operator , $ value , 'OR' ) ; }
Adds OR HAVING statement to the current query .
4,114
public function orWhereBetween ( $ key , $ valueFrom , $ valueTo ) : IQueryBuilderHandler { return $ this -> whereHandler ( $ key , 'BETWEEN' , [ $ valueFrom , $ valueTo ] , 'OR' ) ; }
Adds OR WHERE BETWEEN statement to the current query .
4,115
protected function whereNullHandler ( $ key , string $ prefix = '' , string $ operator = '' ) : IQueryBuilderHandler { $ key = $ this -> adapterInstance -> wrapSanitizer ( $ this -> addTablePrefix ( $ key ) ) ; $ prefix = ( $ prefix !== '' ) ? $ prefix . ' ' : $ prefix ; return $ this -> { $ operator . 'Where' } ( $ th...
Handles WHERE NULL statements .
4,116
public function orderBy ( $ fields , string $ direction = 'ASC' ) : IQueryBuilderHandler { if ( \ is_array ( $ fields ) === false ) { $ fields = [ $ fields ] ; } foreach ( ( array ) $ fields as $ key => $ value ) { $ field = $ key ; $ type = $ value ; if ( \ is_int ( $ key ) === true ) { $ field = $ value ; $ type = $ ...
Adds ORDER BY statement to the current query .
4,117
public function query ( string $ sql , array $ bindings = [ ] ) : IQueryBuilderHandler { $ queryObject = new QueryObject ( $ sql , $ bindings , $ this -> getConnection ( ) ) ; $ this -> connection -> setLastQuery ( $ queryObject ) ; $ this -> fireEvents ( EventHandler :: EVENT_BEFORE_QUERY , $ queryObject ) ; [ $ respo...
Performs query .
4,118
public function registerEvent ( string $ name , ? string $ table = null , \ Closure $ action ) : void { $ this -> connection -> getEventHandler ( ) -> registerEvent ( $ name , $ table , $ action ) ; }
Register new event
4,119
public function rightJoin ( $ table , $ key , ? string $ operator = null , $ value = null ) : IQueryBuilderHandler { return $ this -> join ( $ table , $ key , $ operator , $ value , 'right' ) ; }
Adds new right join statement to the current query .
4,120
public function selectDistinct ( $ fields ) { if ( $ this -> overwriteEnabled === true ) { $ this -> statements [ 'distincts' ] = $ fields ; } else { $ this -> addStatement ( 'distincts' , $ fields ) ; } return $ this ; }
Performs select distinct on the current query .
4,121
public function whereBetween ( $ key , $ valueFrom , $ valueTo ) : IQueryBuilderHandler { return $ this -> whereHandler ( $ key , 'BETWEEN' , [ $ valueFrom , $ valueTo ] ) ; }
Adds WHERE BETWEEN statement to the current query .
4,122
public function whereNot ( $ key , $ operator = null , $ value = null ) : IQueryBuilderHandler { if ( \ func_num_args ( ) === 2 ) { $ value = $ operator ; $ operator = '=' ; } return $ this -> whereHandler ( $ key , $ operator , $ value , 'AND NOT' ) ; }
Adds WHERE NOT statement to the current query .
4,123
public function getColumns ( ) : array { $ tSelects = isset ( $ this -> statements [ 'selects' ] ) === true ? $ this -> statements [ 'selects' ] : [ ] ; $ tColumns = [ ] ; foreach ( $ tSelects as $ key => $ value ) { if ( \ is_string ( $ value ) ) { if ( \ is_int ( $ key ) ) { $ tElements = explode ( '.' , $ value ) ; ...
Returns all columns in current query
4,124
public function embedlyToHtml ( ) { if ( filter_var ( $ this -> data [ 'url' ] , FILTER_VALIDATE_URL ) ) { return $ this -> view ( 'embedly.' . $ this -> type , [ 'url' => $ this -> data [ 'url' ] , 'options' => $ this -> config [ 'embedly' ] ?? '' , ] ) ; } return '' ; }
Render of embedly .
4,125
public function add ( $ url , $ method , $ action ) { $ route = $ this -> factory -> create ( $ url , $ method , $ action ) ; $ this -> routes [ ] = $ route ; foreach ( $ route -> getMethod ( ) as $ method ) { $ this -> routesByMethod [ $ method ] [ ] = $ route ; } }
Add new route to routes array
4,126
public function getRoutesByMethod ( $ method ) { return ( $ this -> routesByMethod && isset ( $ this -> routesByMethod [ $ method ] ) ) ? $ this -> routesByMethod [ $ method ] : array ( ) ; }
Get routes by method
4,127
private function assertValidResource ( $ resource ) { $ resource = ( string ) $ resource ; $ resource = strtolower ( $ resource ) ; if ( ! in_array ( $ resource , static :: VALID_RESOURCES ) ) { throw new InvalidResourceException ( $ resource ) ; } return $ resource ; }
Ensure that a given resource name is valid .
4,128
private function normalizeOffsetAndLimit ( $ offset = 0 , $ limit = 25 ) { $ offset = ( int ) $ offset ; $ limit = ( int ) $ limit ; $ offset = max ( $ offset , 0 ) ; $ limit = min ( max ( $ limit , 0 ) , 25 ) ; return [ $ offset , $ limit ] ; }
Normalize the offset and limit parameters into valid formats .
4,129
public function getGames ( $ offset = 0 , $ limit = 25 ) { list ( $ offset , $ limit ) = $ this -> normalizeOffsetAndLimit ( $ offset , $ limit ) ; return $ this -> request ( 'games' , [ 'offset' => $ offset , 'limit' => $ limit , ] ) ; }
Retrieve a list of all games .
4,130
public function getGameById ( $ id ) { $ id = ( int ) $ id ; $ id = max ( 0 , $ id ) ; return $ this -> request ( 'games/' . $ id ) ; }
Get the details for a single game by its ID .
4,131
public function searchGames ( $ query , $ parameters = [ ] , $ offset = 0 , $ limit = 25 ) { list ( $ offset , $ limit ) = $ this -> normalizeOffsetAndLimit ( $ offset , $ limit ) ; $ query = str_replace ( ' ' , '-' , $ query ) ; $ params = array_merge ( $ this -> buildFilterParameters ( $ parameters ) , [ 'q' => $ que...
Search for games based upon the given criteria .
4,132
public function getCompanies ( $ offset = 0 , $ limit = 25 ) { list ( $ offset , $ limit ) = $ this -> normalizeOffsetAndLimit ( $ offset , $ limit ) ; return $ this -> request ( 'companies' , [ 'offset' => $ offset , 'limit' => $ limit , ] ) ; }
Retrieve a list of all companies .
4,133
public function getCompanyById ( $ id ) { $ id = ( int ) $ id ; $ id = max ( 0 , $ id ) ; return $ this -> request ( 'companies/' . $ id ) ; }
Get the details for a single company by its ID .
4,134
public function getGamesByCompany ( $ id , $ offset = 0 , $ limit = 25 ) { list ( $ offset , $ limit ) = $ this -> normalizeOffsetAndLimit ( $ offset , $ limit ) ; $ id = ( int ) $ id ; $ id = max ( 0 , $ id ) ; return $ this -> request ( 'companies/' . $ id . '/games' , [ 'offset' => $ offset , 'limit' => $ limit , ] ...
Get all the games for a specific company .
4,135
public function getPeople ( $ offset = 0 , $ limit = 25 ) { list ( $ offset , $ limit ) = $ this -> normalizeOffsetAndLimit ( $ offset , $ limit ) ; return $ this -> request ( 'people' , [ 'offset' => $ offset , 'limit' => $ limit , ] ) ; }
Retrieve a list of all people .
4,136
public function getPersonById ( $ id ) { $ id = ( int ) $ id ; $ id = max ( 0 , $ id ) ; return $ this -> request ( 'people/' . $ id ) ; }
Get the details for a single person by its ID .
4,137
public function getFranchises ( $ offset = 0 , $ limit = 25 ) { list ( $ offset , $ limit ) = $ this -> normalizeOffsetAndLimit ( $ offset , $ limit ) ; return $ this -> request ( 'franchises' , [ 'offset' => $ offset , 'limit' => $ limit , ] ) ; }
Retrieve a list of all franchises .
4,138
public function getPlatforms ( $ offset = 0 , $ limit = 25 ) { list ( $ offset , $ limit ) = $ this -> normalizeOffsetAndLimit ( $ offset , $ limit ) ; return $ this -> request ( 'platforms' , [ 'offset' => $ offset , 'limit' => $ limit , ] ) ; }
Retrieve a list of all platforms .
4,139
public static function factory ( $ config = array ( ) ) { $ configuration = static :: buildConfig ( $ config ) ; $ client = new self ( $ configuration -> get ( 'base_url' ) , $ configuration ) ; $ client -> addSubscriber ( new KeyAuthPlugin ( $ configuration -> get ( 'key' ) ) ) ; static :: loadDefinitions ( $ client )...
Factory Method to build new Client .
4,140
private function detectManyToMany ( $ prep , $ table ) { $ properties = $ prep [ $ table ] ; $ foreignKeys = $ properties [ 'foreign' ] ; $ primaryKeys = $ properties [ 'primary' ] ; if ( count ( $ foreignKeys ) === 2 ) { $ primaryKeyCountThatAreAlsoForeignKeys = 0 ; foreach ( $ foreignKeys as $ foreign ) { foreach ( $...
and no tables in the database refer to this table?
4,141
public function view ( string $ viewName , array $ params = [ ] , string $ type = '' ) { if ( empty ( $ type ) ) { $ type = $ this -> type ; } $ jsExternal = $ this -> getJsExternal ( ) ; if ( ! empty ( $ jsExternal [ $ this -> output ] [ $ type ] ) ) { $ this -> codejs [ $ type ] = $ jsExternal [ $ this -> output ] [ ...
Personalized views .
4,142
public function resolve ( Router $ router , $ uri , $ method ) { $ routes = $ router -> getRoutesByMethod ( $ method ) ; $ requestedUri = trim ( preg_replace ( '/\?.*/' , '' , $ uri ) , '/' ) ; foreach ( $ routes as $ route ) { $ matches = array ( ) ; if ( $ route -> getUrl ( ) === $ requestedUri || preg_match ( '~^' ....
Resolve the given url and call the method that belongs to the route
4,143
protected function addStandardParameters ( $ httpMethod ) { if ( $ httpMethod != 'GET' ) { return ; } $ this -> addParameter ( 'page' , 'query' , false ) ; $ this -> addParameter ( 'offset' , 'query' , false ) ; $ this -> addParameter ( 'desc' , 'query' , false ) ; $ this -> addParameter ( 'order' , 'query' , false ) ;...
Add default parameters .
4,144
protected function parsePath ( $ path ) { $ uriParams = array ( ) ; $ uriParamsCount = preg_match_all ( "/(:[^\/]*)/" , $ path , $ uriParams ) ; $ translateParams = array ( ) ; foreach ( $ uriParams [ 0 ] as $ rawParam ) { $ param = str_replace ( ':' , '' , $ rawParam ) ; $ this -> addParameter ( $ param , 'uri' , true...
Parse Parameters from Path .
4,145
protected function addParameter ( $ name , $ location , $ required , $ description = null ) { $ name = trim ( $ name ) ; if ( strpos ( $ name , ',' ) !== false ) { foreach ( explode ( ',' , $ name ) as $ subname ) { $ this -> addParameter ( $ subname , $ location , $ required , $ description ) ; } return ; } $ this -> ...
Add a new parameter to definition .
4,146
protected function parseDocumentationPage ( $ file ) { try { if ( $ file -> getExtension ( ) !== 'html' ) { throw new \ OutOfBoundsException ( 'Not HTML.' ) ; } $ crawler = new Crawler ( file_get_contents ( $ file -> getRealPath ( ) ) ) ; if ( $ crawler -> filter ( '#method-info' ) -> count ( ) == 0 ) { throw new \ Out...
Parses Documentation Page .
4,147
public function setMethod ( $ method ) { if ( $ method === null || ! is_array ( $ method ) || empty ( $ method ) ) { throw new InvalidArgumentException ( 'No method provided' ) ; } foreach ( $ method as $ m ) { if ( ! in_array ( $ m , array ( 'GET' , 'POST' , 'PUT' , 'PATCH' , 'DELETE' ) ) ) { throw new InvalidArgument...
Set the method of the current route
4,148
public function create ( $ url , $ method , $ action ) { return new Route ( $ this -> parseUrl ( $ url ) , $ this -> parseArguments ( $ url ) , $ this -> parseMethod ( $ method ) , $ action ) ; }
Create new route
4,149
private function parseUrl ( $ url ) { $ newUrl = preg_replace ( $ this -> patterns , $ this -> replacements , $ url ) ; $ newUrl = trim ( $ newUrl , '\/?' ) ; $ newUrl = trim ( $ newUrl , '\/' ) ; return $ newUrl ; }
Parse url into a regex url
4,150
protected function createMultiResultResponse ( $ response ) { $ response = new MultiResultResponse ( $ response -> getStatusCode ( ) , $ response -> getHeaders ( ) , $ response -> getBody ( ) ) ; return $ response ; }
Create a Multi - Response Object .
4,151
protected function parseResponseIntoArray ( $ response ) { if ( ! $ response -> isContentType ( 'json' ) ) { parse_str ( $ response -> getBody ( true ) , $ array ) ; return $ array ; } return $ response -> json ( ) ; }
Parses response into an array .
4,152
public function validateSectionWhitelist ( string $ attribute ) { $ sections = $ this -> getSections ( ) ; foreach ( $ this -> whitelistedSections as $ section ) { if ( ! isset ( $ sections [ $ section ] ) ) { $ this -> addError ( $ attribute , Craft :: t ( 'section-field' , 'Invalid section selected.' ) ) ; } } }
Ensures the section IDs selected for the whitelist are for valid sections .
4,153
public function validateSections ( ElementInterface $ element ) { $ value = $ element -> getFieldValue ( $ this -> handle ) ; if ( ! is_array ( $ value ) ) { $ value = [ $ value ] ; } $ sections = $ this -> getSections ( ) ; foreach ( $ value as $ section ) { if ( ! isset ( $ sections [ $ section ] ) ) { $ element -> a...
Ensures the section IDs selected are available to the current user .
4,154
private function getSections ( ) { $ sections = array ( ) ; foreach ( Craft :: $ app -> getSections ( ) -> getEditableSections ( ) as $ section ) { $ sections [ $ section -> id ] = Craft :: t ( 'site' , $ section -> name ) ; } return $ sections ; }
Retrieves all sections in an id - name pair suitable for the underlying options display .
4,155
protected function parseMeetupApiData ( ) { $ responseBody = $ this -> parseBodyContent ( ) ; $ this -> data = $ responseBody [ 'results' ] ; $ this -> metadata = $ responseBody [ 'meta' ] ; }
Makes Meetup API Data available on the Data attribute .
4,156
public function map ( Closure $ func ) { $ clone = clone $ this ; $ clone -> data = array_map ( $ func , $ this -> data ) ; $ clone -> updateBody ( ) ; return $ clone ; }
Applies the given function to each element in the collection and returns a new collection with the elements returned by the function .
4,157
private function updateBody ( ) { $ data = array ( 'meta' => $ this -> metadata , 'results' => $ this -> data ) ; $ this -> body = EntityBody :: factory ( $ this -> isContentType ( 'json' ) ? json_encode ( $ data ) : http_build_query ( $ data ) ) ; }
Assigns a new body to the request based on the data it contains .
4,158
public function onBeforeSend ( ) { $ currentAmount = $ this -> rateLimitMax - $ this -> rateLimitRemaining ; $ currentFactor = $ currentAmount / $ this -> rateLimitMax ; if ( $ currentFactor > $ this -> rateLimitFactor ) { $ this -> slowdownRequests ( ) ; } }
Performs slowdown when rate limiting is enabled and nearing it s limit .
4,159
protected function slowdownRequests ( ) { $ sleepInMicroseconds = ( ( int ) $ this -> rateLimitRemaining === 0 ) ? $ this -> rateLimitReset * 1000000 : $ this -> rateLimitReset / $ this -> rateLimitRemaining * 1000000 ; usleep ( ( int ) $ sleepInMicroseconds ) ; }
Implements a wait in the code to space out requests to respect the current limit and the reset time .
4,160
public function getPluginOptions ( ) { if ( $ this -> url !== null ) { $ url = Url :: to ( $ this -> url ) ; $ this -> pluginOptions [ 'load' ] = new JsExpression ( " function (query, callback) { if (!query.length) return callback(); $.getJSON('$url', { query: encode...
Get plugin options in the json format
4,161
public function findBy ( $ attribute , $ value , $ columns = [ '*' ] , $ with = [ ] ) { $ cacheKey = $ this -> generateKey ( [ $ attribute , $ value , $ columns , $ with ] ) ; return $ this -> cacheResults ( get_called_class ( ) , __FUNCTION__ , $ cacheKey , function ( ) use ( $ attribute , $ value , $ columns , $ with...
Find the entity by the given attribute .
4,162
public function findOrFail ( $ id , $ columns = [ '*' ] , $ with = [ ] ) { $ cacheKey = $ this -> generateKey ( [ $ id , $ columns , $ with ] ) ; return $ this -> cacheResults ( get_called_class ( ) , __FUNCTION__ , $ cacheKey , function ( ) use ( $ id , $ columns , $ with ) { return $ this -> model -> with ( $ with ) ...
Find an entity by its primary key or fail if it doesn t exist .
4,163
public function findWhereBetween ( $ attribute , $ values , $ columns = [ '*' ] , $ with = [ ] ) { $ values = $ this -> castRequest ( $ values ) ; $ cacheKey = $ this -> generateKey ( [ $ attribute , $ values , $ columns , $ with ] ) ; return $ this -> cacheResults ( get_called_class ( ) , __FUNCTION__ , $ cacheKey , f...
Find all entities matching whereBetween conditions .
4,164
public function findOrCreate ( $ attributes ) { $ attributes = $ this -> castRequest ( $ attributes ) ; if ( ! is_null ( $ instance = $ this -> findWhere ( $ attributes ) -> first ( ) ) ) { return $ instance ; } return $ this -> create ( $ attributes ) ; }
Find an entity matching the given attributes or create it .
4,165
public function pluck ( $ column , $ key = null ) { $ cacheKey = $ this -> generateKey ( [ $ column , $ key ] ) ; return $ this -> cacheResults ( get_called_class ( ) , __FUNCTION__ , $ cacheKey , function ( ) use ( $ column , $ key ) { return $ this -> model -> pluck ( $ column , $ key ) ; } ) ; }
Get an array with the values of the given column from entities .
4,166
public function paginate ( $ perPage = null , $ columns = [ '*' ] , $ pageName = 'page' , $ page = null ) { $ cacheKey = $ this -> generateKey ( [ $ perPage , $ columns , $ pageName , $ page ] ) ; return $ this -> cacheResults ( get_called_class ( ) , __FUNCTION__ , $ cacheKey , function ( ) use ( $ perPage , $ columns...
Paginate the given query for retrieving entities .
4,167
public function delete ( $ id ) { $ deleted = false ; $ instance = $ id instanceof Model ? $ id : $ this -> find ( $ id ) ; if ( $ instance ) { event ( implode ( '-' , $ this -> tag ) . '.entity.deleting' , [ $ this , $ instance ] ) ; $ deleted = $ instance -> delete ( ) ; event ( implode ( '-' , $ this -> tag ) . '.en...
Delete an entity with the given ID .
4,168
public function videoToHtml ( ) { if ( in_array ( $ this -> provider , $ this -> providers ) ) { $ caption = '' ; if ( ! empty ( $ this -> caption ) ) { $ caption = $ this -> parser -> toHtml ( $ this -> caption ) ; } return $ this -> view ( 'video.' . $ this -> provider , [ 'remote' => $ this -> remoteId , 'caption' =...
Render of video tag .
4,169
public function orOn ( $ key , $ operator , $ value ) : self { return $ this -> on ( $ key , $ operator , $ value , 'OR' ) ; }
Add OR ON join
4,170
protected function cacheResults ( $ class , $ method , $ key , $ closure ) { $ key = $ class . '@' . $ method . '.' . $ key ; if ( method_exists ( app ( ) -> make ( 'cache' ) -> getStore ( ) , 'tags' ) ) { return app ( ) -> make ( 'cache' ) -> tags ( $ this -> tag ) -> remember ( $ key , 60 , $ closure ) ; } return cal...
Execute the provided callback and cache the results .
4,171
public function flushCache ( ) { if ( method_exists ( app ( ) -> make ( 'cache' ) -> getStore ( ) , 'tags' ) ) { app ( ) -> make ( 'cache' ) -> tags ( $ this -> tag ) -> flush ( ) ; event ( implode ( '-' , $ this -> tag ) . '.entity.cache.flushed' , [ $ this ] ) ; } return $ this ; }
Flush the repository cache results .
4,172
public function connect ( ) : self { if ( $ this -> pdoInstance !== null ) { return $ this ; } $ this -> setPdoInstance ( $ this -> getAdapter ( ) -> connect ( $ this -> getAdapterConfig ( ) ) ) ; return $ this ; }
Create the connection adapter and connect to database
4,173
public function blockquoteToHtml ( ) { return $ this -> view ( 'text.blockquote' , [ 'cite' => $ this -> data [ 'cite' ] ?? '' , 'text' => $ this -> parser -> toHtml ( ltrim ( $ this -> data [ 'text' ] , '>' ) ) , ] ) ; }
Converts block quotes to html .
4,174
protected function arrayStr ( array $ pieces , string $ glue = ',' , bool $ wrapSanitizer = true ) : string { $ str = '' ; foreach ( $ pieces as $ key => $ piece ) { if ( $ wrapSanitizer === true ) { $ piece = $ this -> wrapSanitizer ( $ piece ) ; } if ( \ is_int ( $ key ) === false ) { $ piece = ( $ wrapSanitizer ? $ ...
Array concatenating method like implode . But it does wrap sanitizer and trims last glue
4,175
protected function concatenateQuery ( array $ pieces ) : string { $ str = '' ; foreach ( $ pieces as $ piece ) { $ str = trim ( $ str ) . ' ' . trim ( $ piece ) ; } return trim ( $ str ) ; }
Join different part of queries with a space .
4,176
public function criteriaOnly ( array $ statements , $ bindValues = true ) : array { $ sql = $ bindings = [ ] ; if ( isset ( $ statements [ 'criteria' ] ) === false ) { return compact ( 'sql' , 'bindings' ) ; } [ $ sql , $ bindings ] = $ this -> buildCriteria ( $ statements [ 'criteria' ] , $ bindValues ) ; return compa...
Build just criteria part of the query
4,177
protected function buildQueryPart ( string $ section , array $ statements ) : string { switch ( $ section ) { case static :: QUERY_PART_JOIN : return $ this -> buildJoin ( $ statements ) ; case static :: QUERY_PART_LIMIT : return isset ( $ statements [ 'limit' ] ) ? 'LIMIT ' . $ statements [ 'limit' ] : '' ; case stati...
Returns specific part of a query like JOIN LIMIT OFFSET etc .
4,178
protected function buildUnion ( array $ statements , string $ sql ) : string { if ( isset ( $ statements [ 'unions' ] ) === false || \ count ( $ statements [ 'unions' ] ) === 0 ) { return $ sql ; } foreach ( ( array ) $ statements [ 'unions' ] as $ i => $ union ) { $ queryBuilder = $ union [ 'query' ] ; if ( $ i === 0 ...
Adds union query to sql statement
4,179
public function wrapSanitizer ( $ value ) { if ( $ value instanceof Raw ) { return ( string ) $ value ; } if ( $ value instanceof \ Closure ) { return $ value ; } $ valueArr = explode ( '.' , $ value , 2 ) ; foreach ( $ valueArr as $ key => $ subValue ) { $ valueArr [ $ key ] = trim ( $ subValue ) === '*' ? $ subValue ...
Wrap values with adapter s sanitizer like
4,180
public static function build ( $ name , $ version , $ description ) { $ api = new static ( ) ; $ api -> name = $ name ; $ api -> apiVersion = $ version ; $ api -> description = $ description ; return $ api ; }
Build a new API Object .
4,181
public function addOperation ( Operation $ operation ) { $ this -> operations [ $ operation -> name ] = $ operation ; ksort ( $ this -> operations ) ; }
Adds a new operation .
4,182
public function upload ( Request $ request ) { if ( $ request -> hasFile ( 'attachment' ) ) { $ config = config ( 'sir-trevor-js' ) ; $ file = $ request -> file ( 'attachment' ) ; $ file = ( ! method_exists ( $ file , 'getClientOriginalName' ) ) ? $ file [ 'file' ] : $ file ; $ filename = $ file -> getClientOriginalNam...
Upload image .
4,183
protected function parseDocuments ( ) { $ this -> apis = array ( 3 => Api :: build ( 'Meetup' , 3 , 'Meetup API v3 methods' ) , 2 => Api :: build ( 'Meetup' , 2 , 'Meetup API v2 methods' ) , 1 => Api :: build ( 'Meetup' , 1 , 'Meetup API v1 methods' ) , 'stream' => Api :: build ( 'Meetup' , 'stream' , 'Meetup API Strea...
Parse API Docs .
4,184
public function getApiData ( ) { $ client = new Client ( self :: API_DOCS ) ; $ response = $ client -> get ( ) -> send ( ) ; return $ response -> json ( ) ; }
Read API json .
4,185
public function soundcloudToHtml ( ) { $ theme = $ this -> config [ 'soundcloud' ] ?? '' ; if ( 'full' !== $ theme ) { $ theme = 'small' ; } return $ this -> view ( 'sound.soundcloud.' . $ theme , [ 'remote' => $ this -> data [ 'remote_id' ] , ] ) ; }
Soundcloud block .
4,186
public function toHtml ( string $ json ) { if ( empty ( $ this -> view ) ) { $ this -> view = 'sirtrevorjs::html' ; } $ this -> output = 'html' ; return $ this -> convert ( $ json ) ; }
Converts the outputted json from Sir Trevor to Html .
4,187
public function toAmp ( string $ json ) { if ( empty ( $ this -> view ) ) { $ this -> view = 'sirtrevorjs::amp' ; } $ this -> output = 'amp' ; return $ this -> convert ( $ json , false ) ; }
Converts the outputted json from Sir Trevor to Amp .
4,188
public function toFb ( string $ json ) { if ( empty ( $ this -> view ) ) { $ this -> view = 'sirtrevorjs::fb' ; } $ this -> output = 'fb' ; return $ this -> convert ( $ json ) ; }
Converts the outputted json from Sir Trevor to Facebook Articles .
4,189
public function convert ( string $ json , bool $ externalJs = true ) { $ input = json_decode ( $ json , true ) ; $ text = '' ; $ codejs = [ ] ; if ( empty ( $ this -> view ) ) { $ this -> view = 'sirtrevorjs::html' ; } if ( is_array ( $ input ) ) { $ blocks = $ this -> getBlocks ( ) ; foreach ( $ input [ 'data' ] as $ ...
Convert the outputted json from Sir Trevor .
4,190
protected function getBlocks ( ) { $ blocks = [ ] ; foreach ( $ this -> blocks as $ key => $ value ) { $ blocks [ $ key ] = 'Caouecs\\Sirtrevorjs\\Converter\\' . $ value . 'Converter' ; } if ( ! empty ( $ this -> customBlocks ) ) { $ blocks = array_merge ( $ blocks , $ this -> customBlocks ) ; } if ( isset ( $ this -> ...
Return base blocks and custom blocks with good classes .
4,191
public static function transformText ( string $ text ) { $ text = json_decode ( $ text , true ) ; $ return = [ ] ; if ( is_array ( $ text ) && isset ( $ text [ 'data' ] ) ) { foreach ( $ text [ 'data' ] as $ data ) { if ( 'image' === $ data [ 'type' ] && ! isset ( $ data [ 'data' ] [ 'file' ] ) ) { $ return [ ] = [ 'ty...
Transform text with image bug .
4,192
public static function stylesheets ( ) { $ config = config ( 'sir-trevor-js' ) ; $ return = HTML :: style ( $ config [ 'path' ] . 'sir-trevor-icons.css' ) . HTML :: style ( $ config [ 'path' ] . 'sir-trevor.css' ) ; if ( isset ( $ config [ 'stylesheet' ] ) && is_array ( $ config [ 'stylesheet' ] ) ) { foreach ( $ confi...
Stylesheet files see config file .
4,193
public static function scripts ( array $ params = [ ] ) { $ config = self :: config ( $ params ) ; $ return = '' ; if ( isset ( $ config [ 'script' ] ) && is_array ( $ config [ 'script' ] ) ) { foreach ( $ config [ 'script' ] as $ arr ) { if ( file_exists ( public_path ( $ arr ) ) ) { $ return .= HTML :: script ( $ arr...
Javascript files .
4,194
public static function config ( array $ params = [ ] ) { $ config = config ( 'sir-trevor-js' ) ; if ( isset ( $ params [ 'blocktypes' ] ) && ! empty ( $ params [ 'blocktypes' ] ) && is_array ( $ params [ 'blocktypes' ] ) ) { $ blocktypes = $ params [ 'blocktypes' ] ; } elseif ( isset ( $ config [ 'blocktypes' ] ) && ! ...
Configuration of Sir Trevor JS .
4,195
private static function defineParam ( string $ type , array $ params , array $ config = [ ] ) { if ( isset ( $ params [ $ type ] ) && ! empty ( $ params [ $ type ] ) ) { return $ params [ $ type ] ; } elseif ( isset ( $ config [ $ type ] ) && ! empty ( $ config [ $ type ] ) ) { return $ config [ $ type ] ; } return sel...
Define param .
4,196
public static function findImage ( string $ text ) { $ array = json_decode ( $ text , true ) ; if ( ! empty ( $ array [ 'data' ] ) ) { foreach ( $ array [ 'data' ] as $ arr ) { if ( 'image' === $ arr [ 'type' ] && isset ( $ arr [ 'data' ] [ 'file' ] [ 'url' ] ) ) { return $ arr [ 'data' ] [ 'file' ] [ 'url' ] ; } } } r...
Find first image in text from Sir Trevor JS .
4,197
public static function find ( string $ text , string $ blocktype , string $ output = 'json' , int $ nbr = 0 ) { $ array = json_decode ( $ text , true ) ; if ( ! isset ( $ array [ 'data' ] ) ) { return false ; } $ return = [ ] ; $ _nbr = 1 ; foreach ( $ array [ 'data' ] as $ arr ) { if ( $ arr [ 'type' ] == $ blocktype ...
Find occurences of a type of block in a text .
4,198
public static function first ( string $ text , string $ blocktype , string $ output = 'json' ) { return self :: find ( $ text , $ blocktype , $ output , 1 ) ; }
Find first occurence of a type of block in a text .
4,199
protected function signRequest ( $ request ) { $ url = $ request -> getUrl ( true ) ; $ url -> getQuery ( ) -> add ( 'key' , $ this -> key ) ; $ request -> setUrl ( $ url ) ; }
Adds key parameters as a Query Parameter .