idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
53,700
public static function build ( ) { switch ( true ) { case extension_loaded ( 'apc' ) : $ cacheDriver = new ApcuCache ; break ; case extension_loaded ( 'xcache' ) : $ cacheDriver = new XcacheCache ; break ; case extension_loaded ( 'memcache' ) : $ memcache = new \ Memcache ; $ memcache -> connect ( '127.0.0.1' ) ; $ cacheDriver = new MemcacheCache ; $ cacheDriver -> setMemcache ( $ memcache ) ; break ; case extension_loaded ( 'redis' ) : $ redis = new \ Redis ( ) ; $ redis -> connect ( '127.0.0.1' ) ; $ cacheDriver = new RedisCache ; $ cacheDriver -> setRedis ( $ redis ) ; break ; default : $ cacheDriver = new ArrayCache ; } return $ cacheDriver ; }
Retrieve a newly created doctrine cache driver .
53,701
public function get ( $ token ) { foreach ( $ this -> getDbConnection ( ) -> fetchAll ( 'SELECT * FROM oauth_refresh_token WHERE refresh_token = :token' , [ 'token' => $ token ] ) as $ row ) { if ( $ row ) { return ( new RefreshTokenEntity ( $ this -> server ) ) -> setAccessTokenId ( $ row [ 'access_token' ] ) -> setExpireTime ( $ row [ 'expire_time' ] ) -> setId ( $ row [ 'refresh_token' ] ) ; } } return null ; }
Return a new instance of \ League \ OAuth2 \ Server \ Entity \ RefreshTokenEntity
53,702
public function create ( $ token , $ expireTime , $ accessToken ) { $ this -> getDbConnection ( ) -> insert ( 'oauth_refresh_token' , [ 'refresh_token' => $ token , 'access_token' => $ accessToken , 'expire_time' => $ expireTime ] ) ; }
Create a new refresh token_name
53,703
public function addSnippet ( $ sSnptName ) { $ oSnpt = ViewFactory :: createSnippet ( $ sSnptName ) ; $ this -> snippets [ $ sSnptName ] = $ oSnpt ; }
It adds snippet to the view object .
53,704
public function getSnippet ( $ sSnptName = '' ) { if ( empty ( $ sSnptName ) ) { return $ this -> snippets ; } else { return isset ( $ this -> snippets [ $ sSnptName ] ) ? $ this -> snippets [ $ sSnptName ] : null ; } }
It returns assigned snippet object by the name . If the name not presents then it returns the map with all View - assigned snippets .
53,705
public function apply ( $ testable ) { $ violations = array ( ) ; $ warnings = array ( ) ; $ success = true ; foreach ( $ this -> _rules as $ ruleSet ) { $ rule = $ ruleSet [ 'rule' ] ; $ options = $ ruleSet [ 'options' ] ; $ rule -> apply ( $ testable , $ options ) ; $ warnings = array_merge ( $ warnings , $ rule -> warnings ( ) ) ; if ( ! $ rule -> success ( ) ) { $ success = false ; $ violations = array_merge ( $ violations , $ rule -> violations ( ) ) ; } $ rule -> reset ( ) ; } return compact ( 'violations' , 'success' , 'warnings' ) ; }
Will iterate over each rule calling apply on them
53,706
public function options ( array $ variables ) { foreach ( $ this -> _rules as $ key => & $ rule ) { if ( isset ( $ variables [ $ key ] ) && is_array ( $ variables [ $ key ] ) ) { $ rule [ 'options' ] = $ variables [ $ key ] ; } } }
Will remove unnecessary items and add options .
53,707
public function errorResponse ( $ connection , $ statusCode , $ body = null , $ reason = null , array $ headers = [ ] ) { $ res = new Response ( $ statusCode , $ body ) ; if ( ! $ reason ) { $ res -> statusReason = \ yii \ web \ Response :: $ httpStatuses [ $ statusCode ] ; } if ( $ body === null ) { $ res -> body = \ yii \ web \ Response :: $ httpStatuses [ $ statusCode ] ; $ errpage = $ this -> getErrorPageFile ( $ res -> statusCode ) ; if ( $ errpage ) { ob_start ( ) ; include $ errpage ; $ res -> body = ob_get_clean ( ) ; } } foreach ( $ headers as $ name => $ value ) { $ res -> headers -> add ( $ name , $ value ) ; } $ res -> headers -> remove ( 'Content-Length' ) ; $ res -> headers -> set ( 'Connection' , 'Close' ) ; $ connection -> close ( $ res ) ; }
send error response and close the connection .
53,708
public function sendFile ( $ event , $ req , $ res , $ path ) { clearstatcache ( ) ; $ filesize = sprintf ( "%u" , filesize ( $ path ) ) ; $ res -> headers -> set ( 'Content-Length' , $ filesize ) ; $ res -> headers -> set ( 'Accept-Ranges' , 'bytes' ) ; if ( $ req -> method == 'HEAD' ) { return ; } if ( in_array ( $ res -> mimeType , $ this -> gzip_types ) && $ this -> sendGzipContent ( $ event , $ req , $ res , $ path , $ filesize ) ) { return ; } if ( $ this -> attachFile ( $ event , $ req , $ res , $ path , $ filesize ) ) { $ data = [ 'req' => $ req , 'res' => $ res , 'path' => $ path , 'filesize' => $ filesize ] ; $ event -> sender -> on ( Server :: ON_BUFFER_DRAIN , [ $ this , 'sendPartial' ] , $ data ) ; } }
send static file response .
53,709
protected function sendGzipContent ( $ event , $ req , $ res , $ path , $ filesize ) { if ( ! $ this -> gzip || ! $ req -> gzipSupport ( ) || $ filesize < $ this -> gzip_min_bytes || $ filesize > $ this -> gzip_max_bytes ) { return false ; } $ res -> headers -> set ( 'Content-Encoding' , 'gzip' ) ; $ res -> body = gzencode ( file_get_contents ( $ path ) , $ this -> gzip_level ) ; $ res -> headers -> set ( 'Content-Length' , strlen ( $ res -> body ) ) ; return $ res ; }
send gzip file response .
53,710
protected function attachFile ( $ event , $ req , $ res , $ path , $ size ) { $ range = null ; $ event -> sender -> setAttribute ( 'accept-range' , null ) ; if ( $ req -> headers -> has ( 'Range' ) ) { list ( $ range [ 0 ] , $ range [ 1 ] ) = explode ( '-' , str_ireplace ( 'bytes=' , '' , $ req -> headers -> get ( 'Range' ) ) ) ; if ( ! $ range [ 0 ] ) $ range [ 0 ] = 0 ; if ( ! $ range [ 1 ] ) $ range [ 1 ] = $ size - 1 ; if ( $ range [ 1 ] < $ range [ 0 ] ) { $ res -> statusCode = 416 ; return false ; } } $ info = [ 'name' => $ path , 'range' => $ range , ] ; $ event -> sender -> addFileHandler ( $ this -> fileKey , fopen ( $ path , 'r' ) ) ; if ( ! $ event -> sender -> getFileHandler ( $ this -> fileKey ) ) { Yii :: error ( "cannot open $path" , 'beyod\http' ) ; throw new \ Exception ( "Server internal error" , 503 ) ; } if ( $ range ) { $ event -> sender -> setAttribute ( 'accept-range' , $ range ) ; $ res -> headers -> set ( 'Content-Length' , $ range [ 1 ] - $ range [ 0 ] + 1 ) ; $ res -> headers -> set ( 'Content-Range' , 'bytes ' . ( $ range [ 0 ] ) . '-' . ( $ range [ 1 ] ) . '/' . $ size ) ; fseek ( $ event -> sender -> getFileHandler ( $ this -> fileKey ) , $ range [ 0 ] ) ; $ res -> statusCode = 206 ; } return true ; }
attach file file to be readed for current request .
53,711
public function processPhpFile ( $ event , $ request , $ response , $ file ) { if ( ! $ this -> php_engine ) { $ response -> statusCode = 403 ; $ response -> body = "php engine disabled" ; return ; } if ( ! $ response -> headers -> has ( 'Content-type' ) ) { if ( $ response -> charset === null && $ this -> default_charset ) { $ response -> charset = $ this -> default_charset ; } $ response -> mimeType = $ this -> default_content_type ; } $ _POST = $ request -> _POST ; $ _GET = $ request -> _GET ; $ _FILES = $ request -> _FILES ; $ _COOKIE = $ request -> _COOKIE ; $ _SERVER = $ request -> _SERVER ; ob_start ( ) ; include $ file ; if ( $ response -> gzip && $ request -> gzipSupport ( ) ) { $ response -> headers -> set ( 'Content-Encoding' , 'gzip' ) ; $ response -> body = gzencode ( ob_get_clean ( ) ) ; } else { $ response -> body = ob_get_clean ( ) ; } return ; }
send php file response .
53,712
public function processDir ( $ event , $ req , $ res , $ path ) { foreach ( $ this -> index as $ name ) { $ index_path = realpath ( $ path . '/' . $ name ) ; if ( is_file ( $ index_path ) ) { return $ this -> sendFile ( $ event , $ req , $ res , $ index_path ) ; } } if ( ! $ this -> auto_index ) { throw new \ Exception ( "Directory browsing is Disabled" , 403 ) ; } $ this -> dirList ( $ path , $ res ) ; }
process dir request .
53,713
public function processLocation ( MessageEvent $ event , $ req , $ res , $ path ) { foreach ( $ this -> callback as $ location => $ callable ) { if ( ! preg_match ( $ location , $ path ) ) continue ; $ callable = is_string ( $ callable ) ? [ $ this , $ callable ] : $ callable ; if ( ! is_callable ( $ callable ) ) { return $ this -> errorResponse ( $ event -> sender , 503 , "$location defined invalid callback" ) ; } return call_user_func ( $ callable , $ event , $ req , $ res , $ path ) ; } return false ; }
process location match and callback .
53,714
protected function getErrorPageFile ( $ statusCode ) { $ errorpage = null ; if ( isset ( $ this -> error_pages [ $ statusCode ] ) ) { $ errorpage = $ this -> error_pages [ $ statusCode ] ; } else if ( isset ( $ this -> error_pages [ substr ( $ statusCode , 0 , 2 ) . 'x' ] ) ) { $ errorpage = $ this -> error_pages [ substr ( $ statusCode , 0 , 2 ) . 'x' ] ; } if ( ! $ errorpage || ! is_file ( $ errorpage ) ) return null ; return $ errorpage ; }
find error page file by response status code .
53,715
public function sendPartial ( $ event ) { $ range = $ event -> sender -> getAttribute ( 'accept-range' ) ; $ readSize = $ this -> read_buffer ; $ pos = ftell ( $ event -> sender -> getFileHandler ( $ this -> fileKey ) ) ; if ( $ range ) { $ readSize = min ( $ range [ 1 ] - $ pos + 1 , $ readSize ) ; } if ( $ readSize <= 0 ) { return $ this -> sendPartialFinish ( $ event ) ; } $ c = fread ( $ event -> sender -> getFileHandler ( $ this -> fileKey ) , $ readSize ) ; if ( $ range && $ pos >= $ range [ 1 ] ) { return $ this -> sendPartialFinish ( $ event ) ; } if ( $ c === false ) { \ Yii :: error ( "error while sending file " . $ event -> data [ 'path' ] , 'beyod\http' ) ; return $ event -> sender -> close ( ) ; } if ( feof ( $ event -> sender -> getFileHandler ( $ this -> fileKey ) ) ) { $ this -> sendPartialFinish ( $ event ) ; } $ event -> sender -> send ( $ c , true ) ; }
send partial bytes of file to client .
53,716
public function plugins ( ) { if ( is_array ( $ this -> plugins ) ) { return $ this -> plugins ; } if ( $ this -> plugins ) { $ plugins = apply_filters ( 'all_plugins' , get_plugins ( ) ) ; return array_keys ( $ plugins ) ; } return [ ] ; }
Get a list of plugins to be activated .
53,717
public function theme ( ) { if ( ! $ this -> theme || ! isset ( $ this -> theme -> name ) ) { return false ; } if ( is_string ( $ this -> theme ) ) { return ( object ) [ 'name' => $ this -> theme , 'mods' => [ ] , 'options' => [ ] , 'menus' => [ ] , 'sidebars' => [ ] ] ; } return ( object ) [ 'name' => $ this -> theme -> name , 'mods' => isset ( $ this -> theme -> mods ) ? $ this -> theme -> mods : [ ] , 'options' => isset ( $ this -> theme -> options ) ? $ this -> theme -> options : [ ] , 'menus' => isset ( $ this -> theme -> menus ) ? $ this -> theme -> menus : [ ] , 'sidebars' => isset ( $ this -> theme -> sidebars ) ? $ this -> theme -> sidebars : [ ] ] ; }
Get the theme object or false if not to be set .
53,718
public function getRoutes ( ) { $ routes = array ( 'ezpListAtom' => new ezpRestVersionedRoute ( new ezpMvcRailsRoute ( '/content/node/:nodeId/listAtom' , 'ezpRestAtomController' , array ( 'http-get' => 'collection' ) ) , 1 ) , 'ezpList' => new ezpRestVersionedRoute ( new ezpMvcRegexpRoute ( '@^/content/node/(?P<nodeId>\d+)/list(?:/offset/(?P<offset>\d+))?(?:/limit/(?P<limit>\d+))?(?:/sort/(?P<sortKey>\w+)(?:/(?P<sortType>asc|desc))?)?$@' , 'ezpRestContentController' , array ( 'http-get' => 'list' ) ) , 1 ) , 'ezpNode' => new ezpRestVersionedRoute ( new ezpMvcRailsRoute ( '/content/node/:nodeId' , 'ezpRestContentController' , array ( 'http-get' => 'viewContent' ) ) , 1 ) , 'ezpFieldsByNode' => new ezpRestVersionedRoute ( new ezpMvcRailsRoute ( '/content/node/:nodeId/fields' , 'ezpRestContentController' , array ( 'http-get' => 'viewFields' ) ) , 1 ) , 'ezpFieldByNode' => new ezpRestVersionedRoute ( new ezpMvcRailsRoute ( '/content/node/:nodeId/field/:fieldIdentifier' , 'ezpRestContentController' , array ( 'http-get' => 'viewField' ) ) , 1 ) , 'ezpChildrenCount' => new ezpRestVersionedRoute ( new ezpMvcRailsRoute ( '/content/node/:nodeId/childrenCount' , 'ezpRestContentController' , array ( 'http-get' => 'countChildren' ) ) , 1 ) , 'ezpObject' => new ezpRestVersionedRoute ( new ezpMvcRailsRoute ( '/content/object/:objectId' , 'ezpRestContentController' , array ( 'http-get' => 'viewContent' ) ) , 1 ) , 'ezpFieldsByObject' => new ezpRestVersionedRoute ( new ezpMvcRailsRoute ( '/content/object/:objectId/fields' , 'ezpRestContentController' , array ( 'http-get' => 'viewFields' ) ) , 1 ) , 'ezpFieldByObject' => new ezpRestVersionedRoute ( new ezpMvcRailsRoute ( '/content/object/:objectId/field/:fieldIdentifier' , 'ezpRestContentController' , array ( 'http-get' => 'viewField' ) ) , 1 ) ) ; return $ routes ; }
Returns registered versioned routes for provider
53,719
public static function getNextVersion ( $ module ) { $ root = cradle ( 'global' ) -> path ( 'module' ) ; $ install = $ root . '/' . $ module . '/install' ; if ( ! is_dir ( $ install ) ) { return '0.0.1' ; } $ versions = [ ] ; $ files = scandir ( $ install , 0 ) ; foreach ( $ files as $ file ) { if ( $ file === '.' || $ file === '..' || is_dir ( $ install . '/' . $ file ) ) { continue ; } $ extension = pathinfo ( $ file , PATHINFO_EXTENSION ) ; if ( $ extension !== 'php' && $ extension !== 'sh' && $ extension !== 'sql' ) { continue ; } $ version = pathinfo ( $ file , PATHINFO_FILENAME ) ; if ( ! ( version_compare ( $ version , '0.0.1' , '>=' ) >= 0 ) ) { continue ; } $ versions [ ] = $ version ; } if ( empty ( $ versions ) ) { return '0.0.1' ; } usort ( $ versions , 'version_compare' ) ; $ current = array_pop ( $ versions ) ; $ revisions = explode ( '.' , $ current ) ; $ revisions = array_reverse ( $ revisions ) ; $ found = false ; foreach ( $ revisions as $ i => $ revision ) { if ( ! is_numeric ( $ revision ) ) { continue ; } $ revisions [ $ i ] ++ ; $ found = true ; break ; } if ( ! $ found ) { return $ current . '.1' ; } $ revisions = array_reverse ( $ revisions ) ; return implode ( '.' , $ revisions ) ; }
Checks if a path exists
53,720
public function validatePassed ( $ attr , $ opts = [ ] ) { $ params = $ this -> $ attr ; $ missing = $ invalid = $ columns = [ ] ; $ class = $ this -> modelClass ; $ pk = $ class :: primaryKey ( ) ; $ keys = count ( $ pk ) > 1 ? $ pk : [ 'id' ] ; foreach ( $ keys as $ key ) { if ( ! array_key_exists ( $ key , $ params ) ) { $ missing [ ] = $ key ; } elseif ( is_array ( $ params [ $ key ] ) ) { $ invalid [ ] = $ key ; } else { $ columns [ $ key ] = $ params [ $ key ] ; } } if ( count ( $ missing ) ) { $ this -> addError ( $ attr , \ Yii :: t ( Constants :: MSG_CATEGORY_NAME , 'Missing required parameters: {params}' , [ 'params' => implode ( ', ' , $ missing ) ] ) ) ; return ; } if ( count ( $ invalid ) ) { $ this -> addError ( $ attr , \ Yii :: t ( Constants :: MSG_CATEGORY_NAME , 'Invalid data received for parameters "{params}".' , [ 'params' => implode ( ', ' , $ invalid ) ] ) ) ; return ; } $ this -> _pk = $ columns ; }
Validator for params
53,721
public function getModel ( ) { if ( ! isset ( $ this -> _pk ) ) throw new InvalidCallException ( 'Invalid usage. You must call this method only if load method succeeds' ) ; if ( isset ( $ this -> _model ) ) return $ this -> _model ; $ class = $ this -> modelClass ; return $ this -> _model = $ class :: findOne ( $ this -> _pk ) ; }
Get founded model
53,722
public function addRouteDefinition ( RouteDefinition $ definition ) : void { $ name = $ definition -> getName ( ) ; if ( isset ( $ this -> routesByName [ $ name ] ) ) { throw new \ InvalidArgumentException ( "Route with name '$name' already exists" ) ; } $ routeId = \ count ( $ this -> routeDefinitions ) ; $ segments = $ definition -> getSegments ( ) ; $ this -> routeDefinitions [ $ routeId ] = $ definition -> getDefinitionCache ( ) ; $ this -> routesByName [ $ name ] = $ routeId ; if ( $ definition -> isStatic ( ) ) { $ this -> staticRoutes [ implode ( '/' , $ segments ) ] [ ] = $ routeId ; return ; } foreach ( $ segments as $ i => $ segment ) { $ this -> segmentValues [ $ i ] [ $ segment ] [ $ routeId ] = $ routeId ; if ( ! isset ( $ this -> segmentCounts [ $ i ] ) ) { $ this -> segmentCounts [ $ i ] = [ ] ; } } $ this -> segmentCounts [ \ count ( $ segments ) ] [ $ routeId ] = $ routeId ; }
Adds a new route definition .
53,723
public function getCacheFile ( callable $ encoder = null ) : string { if ( \ is_null ( $ encoder ) ) { $ encoder = function ( $ value ) : string { return var_export ( $ value , true ) ; } ; } $ statics = $ encoder ( $ this -> staticRoutes ) ; $ counts = $ encoder ( $ this -> segmentCounts ) ; $ values = $ encoder ( $ this -> segmentValues ) ; $ definitions = $ encoder ( $ this -> routeDefinitions ) ; $ names = $ encoder ( $ this -> routesByName ) ; return <<<TEMPLATE<?php return new class extends \Simply\Router\RouteDefinitionProvider { protected \$staticRoutes = $statics; protected \$segmentCounts = $counts; protected \$segmentValues = $values; protected \$routeDefinitions = $definitions; protected \$routesByName = $names;};TEMPLATE ; }
Returns PHP code for cached RouteDefinitionProvider that can be stored in file and included .
53,724
public function getRouteDefinition ( int $ routeId ) : RouteDefinition { if ( ! isset ( $ this -> routeDefinitions [ $ routeId ] ) ) { throw new \ InvalidArgumentException ( "Invalid route id '$routeId'" ) ; } return RouteDefinition :: createFromCache ( $ this -> routeDefinitions [ $ routeId ] ) ; }
Returns a route definition by a specific id .
53,725
public function getRouteDefinitionByName ( string $ name ) : RouteDefinition { if ( ! isset ( $ this -> routesByName [ $ name ] ) ) { throw new \ InvalidArgumentException ( "Invalid route name '$name'" ) ; } return $ this -> getRouteDefinition ( $ this -> routesByName [ $ name ] ) ; }
Returns a route definition by the name of the route .
53,726
public function getEmbed ( ) { if ( $ this -> link ) { switch ( $ this -> type ) { case 'argus360' : return '<iframe src="//car360app.com/viewer/portable.php?spin=' . $ this -> getHash ( $ this -> link ) . '&res=1920x1080&maximages=-1&frameSize=1920x1080"></iframe>' ; break ; case 'dailymotion' : return '<iframe frameborder="0" width="480" height="270" src="//www.dailymotion.com/embed/video/' . $ this -> getHash ( $ this -> link ) . '?autoplay=0&mute=1" allowfullscreen></iframe>' ; break ; case 'giphy' : return '<iframe src="//giphy.com/embed/' . $ this -> getHash ( $ this -> link ) . '" width="480" height="270" frameBorder="0" class="giphy-embed" allowFullScreen></iframe>' ; break ; case 'gist' : return '<script src="//gist.github.com/' . $ this -> getHash ( $ this -> link ) . '.js"></script>' ; break ; case 'tweet' : $ json = file_get_contents ( 'https://publish.twitter.com/oembed?url=https:' . urlencode ( $ this -> link ) ) ; return json_decode ( $ json , true ) [ 'html' ] ; break ; case 'vimeo' : return '<iframe src="//player.vimeo.com/video/' . $ this -> getHash ( $ this -> link ) . '?color=ffffff" width="640" height="267" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>' ; break ; case 'youtube' : return '<iframe allowfullscreen width="420" height="315" src="//www.youtube.com/embed/' . $ this -> getHash ( $ this -> link ) . '"></iframe>' ; break ; default : return null ; } } return null ; }
Generate embed according to category
53,727
public function getHash ( $ url ) { switch ( parse_url ( $ url ) [ 'host' ] ) { case 'www.youtube.com' : parse_str ( parse_url ( $ url ) [ 'query' ] , $ result ) ; return $ result [ 'v' ] ; break ; case 'dai.ly' : case 'vimeo.com' : case 'youtu.be' : return ltrim ( parse_url ( $ url ) [ 'path' ] , '/' ) ; break ; case 'www.dailymotion.com' : if ( strpos ( parse_url ( $ url ) [ 'path' ] , 'playlist' ) !== false ) { parse_str ( parse_url ( $ url ) [ 'fragment' ] , $ result ) ; return $ result [ 'video' ] ; } $ temp = ltrim ( strrchr ( parse_url ( $ url ) [ 'path' ] , '/' ) , '/' ) ; if ( stripos ( $ temp , '_' ) ) { return strstr ( $ temp , '_' , true ) ; } return $ temp ; break ; case 'giphy.com' : $ result = ltrim ( strrchr ( parse_url ( $ url ) [ 'path' ] , '/' ) , '/' ) ; if ( strpos ( $ result , '-' ) !== false ) { return ltrim ( strrchr ( $ result , '-' ) , '-' ) ; } return $ result ; break ; case 'gist.github.com' : case 'twitter.com' : case 'www.argus360.fr' : return ltrim ( strrchr ( parse_url ( $ url ) [ 'path' ] , '/' ) , '/' ) ; break ; case 'www.car360app.com' : parse_str ( parse_url ( $ url ) [ 'query' ] , $ result ) ; return $ result [ 'spin' ] ; break ; default : return null ; } }
Get video hash from url
53,728
public function resolve ( ThemeInterface $ theme , Content $ content , Variation $ variation , $ templateName ) { $ templateTypes = $ theme -> getTemplateTypes ( ) ; switch ( true ) { case $ templateName : if ( ! $ templateType = $ templateTypes -> search ( array ( 'name' => $ templateName ) ) -> first ( ) ) { throw new InvalidTemplateException ( sprintf ( 'No template named "%s" registered under "%s" theme. Please check your configuration.' , $ templateName , $ theme -> getName ( ) ) ) ; } break ; case $ templateType = $ templateTypes -> filter ( function ( TemplateType $ templateType ) use ( $ variation ) { return ( bool ) $ variation -> getConfiguration ( 'templates' , $ templateType -> getName ( ) , 'default' ) ; } ) -> first ( ) : break ; default : $ templateType = $ templateTypes -> first ( ) ; } if ( empty ( $ templateType ) ) { throw new InvalidTemplateException ( sprintf ( 'No valid template type found under "%s" theme for "%s" content type. Please check your configuration.' , $ theme -> getName ( ) , $ content -> getType ( ) -> getName ( ) ) ) ; } if ( ! $ template = $ this -> templateLoader -> retrieveDisplayable ( $ templateType , $ content ) ) { throw new InvalidTemplateException ( sprintf ( 'Any "%s" template found under "%s" theme for "%s#%d" content.' , $ templateType -> getName ( ) , $ theme -> getName ( ) , $ content -> getType ( ) -> getName ( ) , $ content -> getContentId ( ) ) ) ; } return $ template -> setContent ( $ content ) ; }
Resolve current template from given Theme and template name .
53,729
public function renderNav ( $ numberOfPages , $ currentPage = 1 , $ queryParameters = array ( ) , $ maxPagesDisplayedAroundCurrent = 2 ) { $ navigation = array ( ) ; $ firstPageDisplayed = 1 ; $ lastPageDisplayed = ( int ) $ numberOfPages ; $ leftPartUrl = $ this -> prepareQueryString ( $ queryParameters ) ; if ( $ currentPage > $ maxPagesDisplayedAroundCurrent ) { $ firstPageDisplayed = $ currentPage - $ maxPagesDisplayedAroundCurrent ; $ navigation [ ] = '<a href="' . $ leftPartUrl . '1" class="navigatorShortcut1">' . $ this -> translator -> trans ( 'open_orchestra_display.twig.navigator.first' ) . '</a>' ; } if ( $ currentPage > 1 ) { $ navigation [ ] = '<a href="' . $ leftPartUrl . ( $ currentPage - 1 ) . ' "class="navigatorShortcut2">' . $ this -> translator -> trans ( 'open_orchestra_display.twig.navigator.previous' ) . '</a>' ; } if ( $ firstPageDisplayed > 1 ) { $ navigation [ ] = '...' ; } if ( $ currentPage < $ numberOfPages - $ maxPagesDisplayedAroundCurrent ) { $ lastPageDisplayed = $ currentPage + $ maxPagesDisplayedAroundCurrent ; } for ( $ i = $ firstPageDisplayed ; $ i <= $ lastPageDisplayed ; $ i ++ ) { if ( $ i == $ currentPage ) { $ navigation [ ] = '<span class="navigatorCurrent">' . $ i . '</span>' ; } else { $ navigation [ ] = ' <a href="' . $ leftPartUrl . $ i . '" class="navigatorPage">' . $ i . '</a>' ; } } if ( $ lastPageDisplayed < $ numberOfPages ) { $ navigation [ ] = '...' ; } if ( $ currentPage < $ numberOfPages ) { $ navigation [ ] = '<a href="' . $ leftPartUrl . ( $ currentPage + 1 ) . '" class="navigatorShortcut2">' . $ this -> translator -> trans ( 'open_orchestra_display.twig.navigator.next' ) . '</a>' ; } if ( $ currentPage < $ numberOfPages - $ maxPagesDisplayedAroundCurrent ) { $ navigation [ ] = '<a href="' . $ leftPartUrl . $ numberOfPages . '" class="navigatorShortcut1">' . $ this -> translator -> trans ( 'open_orchestra_display.twig.navigator.last' ) . '</a>' ; } return implode ( ' ' , $ navigation ) ; }
Render a customizable navigation bar
53,730
protected function prepareQueryString ( $ queryParameters ) { unset ( $ queryParameters [ self :: PARAMETER_PAGE ] ) ; $ queryParameters [ self :: PARAMETER_PAGE ] = '' ; return '?' . http_build_query ( $ queryParameters ) ; }
Generate navigator queryString without page number
53,731
public function calculate ( $ elo0 , $ elo1 , $ win , $ reliability0 = 1.0 , $ reliability1 = 1.0 , $ kFactor0 = null , $ kFactor1 = null ) { self :: checkCoef ( $ reliability0 , 'reliability0' ) ; self :: checkCoef ( $ reliability1 , 'reliability1' ) ; self :: checkCoef ( $ win , 'win' ) ; $ kFactor0 = ( null === $ kFactor0 ) ? $ this -> kFactor : $ kFactor0 ; $ kFactor1 = ( null === $ kFactor1 ) ? $ this -> kFactor : $ kFactor1 ; $ proba = $ this -> proba ( $ elo0 , $ elo1 ) ; $ eloUpdate0 = $ win - $ proba ; $ eloUpdate1 = - $ eloUpdate0 ; self :: rectifyReliabilityCoefs ( $ reliability0 , $ reliability1 ) ; $ eloUpdate0 *= $ kFactor0 * $ reliability1 ; $ eloUpdate1 *= $ kFactor1 * $ reliability0 ; return array ( $ elo0 + $ eloUpdate0 , $ elo1 + $ eloUpdate1 ) ; }
Calculate new elo scores
53,732
public function lose ( $ elo0 , $ elo1 , $ reliability0 = 1.0 , $ reliability1 = 1.0 , $ kFactor0 = null , $ kFactor1 = null ) { return $ this -> calculate ( $ elo0 , $ elo1 , 0 , $ reliability0 , $ reliability1 , $ kFactor0 , $ kFactor1 ) ; }
Player 0 lose against player 1
53,733
private static function rectifyReliabilityCoefs ( & $ coef0 , & $ coef1 ) { $ reliabilityRectification = 1 - max ( $ coef0 , $ coef1 ) ; $ coef0 += $ reliabilityRectification ; $ coef1 += $ reliabilityRectification ; }
Increase coefficients the same value so one of them reaches 1
53,734
protected function dropzoneAttributes ( $ url ) { $ init = new JavaScriptExpression ( $ this -> init ( 'translationImport' ) ) ; $ validator = app ( CsvValidator :: class ) ; $ rules = $ this -> getValidationRules ( 'file' , $ validator ) ; return [ 'container' => 'translationImport' , 'paramName' => 'file' , 'view' => 'antares/translations::admin.partials._dropzone' , 'url' => $ url , 'maxFiles' => 1 , 'acceptedFiles' => '.csv' , 'init' => $ init ] + $ rules ; }
dropzone attributes creator
53,735
public function redirect ( ) { $ this -> execute ( ) ; if ( $ this -> gatewayUrl ) { $ code = 302 ; $ message = $ code . " Found" ; header ( "HTTP/1.1 " . $ message , true , $ code ) ; header ( "Status: " . $ message , true , $ code ) ; header ( "Location: {$this->gatewayUrl}" ) ; exit ; } }
Redirects user to gateway URL
53,736
public function getField ( $ name ) { $ component = $ this -> getComponent ( $ name ) ; if ( $ component instanceof Field === false ) throw new \ UnexpectedValueException ( 'The component with name "' . $ name , '" is not of type Field but of type ' . get_class ( $ component ) ) ; return $ component ; }
Returns a connected form field of this form handler instance selected by its name
53,737
private function prepare ( $ data ) { foreach ( $ data as $ code => & $ item ) { $ item = $ this -> prepareItem ( $ code , $ item ) ; } return $ data ; }
prepare array for sorting
53,738
public function hex_to_base64 ( $ str ) { $ raw = '' ; for ( $ i = 0 ; $ i < strlen ( $ str ) ; $ i += 2 ) { $ raw .= chr ( hexdec ( substr ( $ str , $ i , 2 ) ) ) ; } return base64_encode ( $ raw ) ; }
Convert a HEX value to Base64 .
53,739
public function to_query_string ( $ array ) { $ temp = array ( ) ; foreach ( $ array as $ key => $ value ) { if ( is_string ( $ key ) && ! is_array ( $ value ) ) { $ temp [ ] = rawurlencode ( $ key ) . '=' . rawurlencode ( $ value ) ; } } return implode ( '&' , $ temp ) ; }
Convert an associative array into a query string .
53,740
public function to_signable_string ( $ array ) { $ t = array ( ) ; foreach ( $ array as $ k => $ v ) { $ t [ ] = $ this -> encode_signature2 ( $ k ) . '=' . $ this -> encode_signature2 ( $ v ) ; } return implode ( '&' , $ t ) ; }
Convert an associative array into a sign - able string .
53,741
public function query_to_array ( $ qs ) { $ query = explode ( '&' , $ qs ) ; $ data = array ( ) ; foreach ( $ query as $ q ) { $ q = explode ( '=' , $ q ) ; if ( isset ( $ data [ $ q [ 0 ] ] ) && is_array ( $ data [ $ q [ 0 ] ] ) ) { $ data [ $ q [ 0 ] ] [ ] = urldecode ( $ q [ 1 ] ) ; } else if ( isset ( $ data [ $ q [ 0 ] ] ) && ! is_array ( $ data [ $ q [ 0 ] ] ) ) { $ data [ $ q [ 0 ] ] = array ( $ data [ $ q [ 0 ] ] ) ; $ data [ $ q [ 0 ] ] [ ] = urldecode ( $ q [ 1 ] ) ; } else { $ data [ urldecode ( $ q [ 0 ] ) ] = urldecode ( $ q [ 1 ] ) ; } } return $ data ; }
Convert a query string into an associative array . Multiple identical keys will become an indexed array .
53,742
public function size_readable ( $ size , $ unit = null , $ default = null ) { $ sizes = array ( 'B' , 'kB' , 'MB' , 'GB' , 'TB' , 'PB' , 'EB' ) ; $ mod = 1024 ; $ ii = count ( $ sizes ) - 1 ; $ unit = array_search ( ( string ) $ unit , $ sizes ) ; if ( $ unit === null || $ unit === false ) { $ unit = $ ii ; } if ( $ default === null ) { $ default = '%01.2f %s' ; } $ i = 0 ; while ( $ unit != $ i && $ size >= 1024 && $ i < $ ii ) { $ size /= $ mod ; $ i ++ ; } return sprintf ( $ default , $ size , $ sizes [ $ i ] ) ; }
Return human readable file sizes .
53,743
public function convert_date_to_iso8601 ( $ datestamp ) { if ( ! preg_match ( '/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}((\+|-)\d{2}:\d{2}|Z)/m' , $ datestamp ) ) { return gmdate ( self :: DATE_FORMAT_ISO8601 , strtotime ( $ datestamp ) ) ; } return $ datestamp ; }
Checks to see if a date stamp is ISO - 8601 formatted and if not makes it so .
53,744
public function decode_uhex ( $ s ) { preg_match_all ( '/\\\u([0-9a-f]{4})/i' , $ s , $ matches ) ; $ matches = $ matches [ count ( $ matches ) - 1 ] ; $ map = array ( ) ; foreach ( $ matches as $ match ) { if ( ! isset ( $ map [ $ match ] ) ) { $ map [ '\u' . $ match ] = html_entity_decode ( '&#' . hexdec ( $ match ) . ';' , ENT_NOQUOTES , 'UTF-8' ) ; } } return str_replace ( array_keys ( $ map ) , $ map , $ s ) ; }
Decodes \ uXXXX entities into their real unicode character equivalents .
53,745
public function generate_guid ( ) { return sprintf ( '%04X%04X-%04X-%04X-%04X-%04X%04X%04X' , mt_rand ( 0 , 65535 ) , mt_rand ( 0 , 65535 ) , mt_rand ( 0 , 65535 ) , mt_rand ( 16384 , 20479 ) , mt_rand ( 32768 , 49151 ) , mt_rand ( 0 , 65535 ) , mt_rand ( 0 , 65535 ) , mt_rand ( 0 , 65535 ) ) ; }
Generates a random GUID .
53,746
public function getTtl ( ) { if ( false === $ this -> ttl ) { $ this -> ttl = $ this -> getDefaultTtl ( ) ; } return $ this -> ttl ; }
Set the cache driver
53,747
private function getBeforeEvent ( BeforeEvent $ event ) { $ request = $ event -> getRequest ( ) ; if ( 'api.embed.ly' === $ request -> getHost ( ) ) { $ requestQuery = $ request -> getQuery ( ) ; $ requestQuery -> setEncodingType ( false ) ; $ requestQuery -> set ( 'key' , $ this -> apiKey ) ; $ request -> setQuery ( $ requestQuery ) ; } }
Guzzle event used to set the key parameter .
53,748
public function display ( $ method = null , array $ params = array ( ) ) { $ httpClient = $ this -> getHttpClient ( ) ; if ( trim ( $ method ) ) { $ method = '/' . ltrim ( $ method , '/' ) ; } $ params [ 'key' ] = $ this -> getApiKey ( ) ; $ response = $ httpClient -> get ( 'http://i.embed.ly/1/display' . $ method , [ 'query' => $ params , ] ) ; return ( string ) $ response -> getBody ( ) ; }
The display based routes .
53,749
public function findNext ( ) { if ( ! isset ( $ this -> cache [ 'wdb_next' ] ) ) { $ this -> cache [ 'wdb_next' ] = null ; $ filepath = $ this -> getPathname ( ) ; if ( $ this -> isLink ( ) || $ this -> isRootLink ( ) ) { $ filepath = FilesystemHelper :: slashDirname ( $ this -> getWebPath ( ) ) . $ this -> getFilename ( ) ; } $ dir_realpath = dirname ( realpath ( $ filepath ) ) ; $ dir_targetpath = dirname ( $ filepath ) ; if ( empty ( $ dir_realpath ) ) { $ dir_realpath = $ dir_targetpath ; } $ dir = new FilesystemIterator ( $ dir_realpath , FilesystemIterator :: CURRENT_AS_PATHNAME ) ; $ dir_table = iterator_to_array ( $ dir , false ) ; $ i = array_search ( $ this -> getRealPath ( ) , $ dir_table ) ; if ( false !== $ i ) { $ j = $ i + 1 ; while ( $ j <= count ( $ dir_table ) && array_key_exists ( $ j , $ dir_table ) && ( ( is_dir ( $ dir_table [ $ j ] ) && ! Helper :: isDirValid ( $ dir_table [ $ j ] ) ) || ! Helper :: isFileValid ( $ dir_table [ $ j ] ) || FilesystemHelper :: isDotPath ( $ dir_table [ $ j ] ) || Helper :: isTranslationFile ( $ dir_table [ $ j ] ) ) ) { $ j = $ j + 1 ; } if ( $ j <= count ( $ dir_table ) && array_key_exists ( $ j , $ dir_table ) && ( ( is_dir ( $ dir_table [ $ j ] ) && Helper :: isDirValid ( $ dir_table [ $ j ] ) ) || ( ! is_dir ( $ dir_table [ $ j ] ) && Helper :: isFileValid ( $ dir_table [ $ j ] ) && ! Helper :: isTranslationFile ( $ dir_table [ $ j ] ) ) ) && ! FilesystemHelper :: isDotPath ( $ dir_table [ $ j ] ) ) { $ next = new File ( $ dir_table [ $ j ] ) ; $ this -> cache [ 'wdb_next' ] = $ next -> getWDBStack ( ) ; } } } return $ this -> cache [ 'wdb_next' ] ; }
Find next file in current chapter
53,750
public function optimize ( stdClass $ data ) { $ this -> createRouteFolders ( $ data ) ; $ fi = new FilesystemIterator ( $ data -> rootDirectory . 'app/routes/admin/' , FilesystemIterator :: SKIP_DOTS ) ; $ count = str_pad ( iterator_count ( $ fi ) + 1 , 2 , '0' , STR_PAD_LEFT ) . '_' ; $ data -> serviceRouteName = 'routes.' . $ this -> stringWithDots ( $ data -> serviceURL ) ; $ data -> adminRoutesDestination = $ data -> rootDirectory . 'app/routes/admin/' . $ count . $ data -> serviceRouteName . '.php' ; $ data -> apiRoutesDestination = $ data -> rootDirectory . 'app/routes/api/' . $ count . $ data -> serviceRouteName . '.php' ; $ data -> aclPrefix = $ this -> stringWithUnderscore ( $ data -> directory . $ data -> serviceRouteName ) ; return $ data ; }
Optimizing configuration for routes
53,751
public function generate ( stdClass $ serviceData ) { $ files = [ ] ; $ files [ ] = $ this -> generateRoutes ( $ serviceData , 'admin' ) ; $ files [ ] = $ this -> generateRoutes ( $ serviceData , 'api' ) ; return $ files ; }
Create route files
53,752
private function generateRoutes ( stdClass $ service , string $ type ) { switch ( $ type ) { case 'api' : $ destination = $ service -> apiRoutesDestination ; break ; case 'admin' : $ destination = $ service -> adminRoutesDestination ; break ; default : return '' ; } $ this -> createFileFromTemplate ( [ "destination" => $ destination , "templateDestination" => __DIR__ . '/../templates/service/' . $ type . '.routes.hctpl' , "content" => [ "serviceURL" => $ service -> serviceURL , "controllerNameDotted" => $ service -> serviceRouteName , "acl_prefix" => $ service -> aclPrefix , "controllerName" => $ service -> controllerNameForRoutes , ] , ] ) ; return $ destination ; }
Generating routes file
53,753
public function is_valid ( ) { $ ret = false ; if ( is_null ( $ this -> deleteInsteadOfAppend ) === false && is_null ( $ this -> subscriberIds ) === false && is_null ( $ this -> emails ) === false ) { $ ret = true ; } return $ ret ; }
Validates a subscriber list
53,754
protected function _sort ( ) { if ( $ this -> _dirtyIndex ) { $ newIndex = array ( ) ; $ index = 0 ; foreach ( $ this -> _pages as $ hash => $ page ) { $ order = $ page -> getOrder ( ) ; if ( $ order === null ) { $ newIndex [ $ hash ] = $ index ; $ index ++ ; } else { $ newIndex [ $ hash ] = $ order ; } } asort ( $ newIndex ) ; $ this -> _index = $ newIndex ; $ this -> _dirtyIndex = false ; } }
Sorts the page index according to page order
53,755
public function addPage ( $ page ) { if ( $ page === $ this ) { throw new Exception ( 'A page cannot have itself as a parent' ) ; } if ( is_array ( $ page ) ) { $ page = Page :: factory ( $ page ) ; } elseif ( ! $ page instanceof Page ) { throw new Exception ( 'Invalid argument: $page must be an array' ) ; } $ hash = $ page -> hashCode ( ) ; if ( array_key_exists ( $ hash , $ this -> _index ) ) { return $ this ; } $ this -> _pages [ $ hash ] = $ page ; $ this -> _index [ $ hash ] = $ page -> getOrder ( ) ; $ this -> _dirtyIndex = true ; $ page -> setParent ( $ this ) ; return $ this ; }
Adds a page to the container
53,756
public function addPages ( $ pages ) { if ( $ pages instanceof Container ) { $ pages = iterator_to_array ( $ pages ) ; } if ( ! is_array ( $ pages ) ) { throw new Exception ( 'Invalid argument: $pages must be an array, an instance of Container' ) ; } foreach ( $ pages as $ page ) { $ this -> addPage ( $ page ) ; } return $ this ; }
Adds several pages at once
53,757
public function removePage ( $ page , $ recursive = false ) { if ( $ page instanceof Page ) { $ hash = $ page -> hashCode ( ) ; } elseif ( is_int ( $ page ) ) { $ this -> _sort ( ) ; if ( ! $ hash = array_search ( $ page , $ this -> _index ) ) { return false ; } } else { return false ; } if ( isset ( $ this -> _pages [ $ hash ] ) ) { unset ( $ this -> _pages [ $ hash ] ) ; unset ( $ this -> _index [ $ hash ] ) ; $ this -> _dirtyIndex = true ; return true ; } if ( $ recursive ) { foreach ( $ this -> _pages as $ childPage ) { if ( $ childPage -> hasPage ( $ page , true ) ) { $ childPage -> removePage ( $ page , true ) ; return true ; } } } return false ; }
Removes the given page from the container
53,758
public function hasPage ( Page $ page , $ recursive = false ) { if ( array_key_exists ( $ page -> hashCode ( ) , $ this -> _index ) ) { return true ; } elseif ( $ recursive ) { foreach ( $ this -> _pages as $ childPage ) { if ( $ childPage -> hasPage ( $ page , true ) ) { return true ; } } } return false ; }
Checks if the container has the given page
53,759
public function toArray ( ) { $ pages = array ( ) ; $ this -> _dirtyIndex = true ; $ this -> _sort ( ) ; $ indexes = array_keys ( $ this -> _index ) ; foreach ( $ indexes as $ hash ) { $ pages [ ] = $ this -> _pages [ $ hash ] -> toArray ( ) ; } return $ pages ; }
Returns an array representation of all pages in container
53,760
public function current ( ) { $ this -> _sort ( ) ; current ( $ this -> _index ) ; $ hash = key ( $ this -> _index ) ; if ( isset ( $ this -> _pages [ $ hash ] ) ) { return $ this -> _pages [ $ hash ] ; } else { throw new Exception ( 'Corruption detected in container; ' . 'invalid key found in internal iterator' ) ; } }
Returns current page
53,761
public function getChildren ( ) { $ hash = key ( $ this -> _index ) ; if ( isset ( $ this -> _pages [ $ hash ] ) ) { return $ this -> _pages [ $ hash ] ; } return null ; }
Returns the child container .
53,762
public function debug ( $ message = '' , $ context = [ ] , $ role = 'system' , $ times = 0 , $ ttl = 0 ) { if ( $ this -> isSingle ( ) ) { $ this -> log ( $ message , $ context , Logger :: DEBUG , $ role , $ times , $ ttl ) ; } }
Record debug log
53,763
public function info ( $ message = '' , $ context = [ ] , $ role = 'system' , $ times = 0 , $ ttl = 0 ) { if ( $ this -> isSingle ( ) ) { $ this -> log ( $ message , $ context , Logger :: INFO , $ role , $ times , $ ttl ) ; } }
Record info log
53,764
public function notice ( $ message = '' , $ context = [ ] , $ role = 'system' , $ times = 0 , $ ttl = 0 ) { if ( $ this -> isSingle ( ) ) { $ this -> log ( $ message , $ context , Logger :: NOTICE , $ role , $ times , $ ttl ) ; } }
Record notice log
53,765
public function warning ( $ message = '' , $ context = [ ] , $ role = 'system' , $ times = 0 , $ ttl = 0 ) { if ( $ this -> isSingle ( ) ) { $ this -> log ( $ message , $ context , Logger :: WARNING , $ role , $ times , $ ttl ) ; } }
Record warning log
53,766
public function error ( $ message = '' , $ context = [ ] , $ role = 'system' , $ times = 0 , $ ttl = 0 ) { if ( $ this -> isSingle ( ) ) { $ this -> log ( $ message , $ context , Logger :: ERROR , $ role , $ times , $ ttl ) ; } }
Record error log
53,767
public function critical ( $ message = '' , $ context = [ ] , $ role = 'system' , $ times = 0 , $ ttl = 0 ) { if ( $ this -> isSingle ( ) ) { $ this -> log ( $ message , $ context , Logger :: CRITICAL , $ role , $ times , $ ttl ) ; } }
Record critical log
53,768
public function alert ( $ message = '' , $ context = [ ] , $ role = 'system' , $ times = 0 , $ ttl = 0 ) { if ( $ this -> isSingle ( ) ) { $ this -> log ( $ message , $ context , Logger :: ALERT , $ role , $ times , $ ttl ) ; } }
Record alert log
53,769
public function emergency ( $ message = '' , $ context = [ ] , $ role = 'system' , $ times = 0 , $ ttl = 0 ) { if ( $ this -> isSingle ( ) ) { $ this -> log ( $ message , $ context , Logger :: EMERGENCY , $ role , $ times , $ ttl ) ; } }
Record emergency log
53,770
public function handleRequest ( ) { global $ argv ; if ( ! is_array ( $ argv ) || empty ( $ argv ) ) { throw new Exception ( "Invalid value of the cli args array was given." ) ; } $ oCtrlResolver = new CliCtrlResolver ( $ argv ) ; $ oCtrlResolver -> run ( ) ; }
It processes the call parameters of cli - script and passed them to the CliCtrlResolver object .
53,771
public function getUser ( ) { if ( ! $ this -> getState ( ) ) { $ oauth_verifier = $ this -> request -> get ( 'oauth_verifier' ) ; if ( $ oauth_verifier !== null ) { $ this -> setState ( App :: STATE_AUTHORIZED ) ; $ secret = $ this -> storage -> getRequestSecret ( ) ; $ oauth_token = $ this -> request -> get ( 'oauth_token' ) ; $ credentials = $ this -> ttools -> getAccessTokens ( $ oauth_token , $ secret , $ oauth_verifier ) ; if ( ! empty ( $ credentials [ 'access_token' ] ) ) { if ( ! $ this -> strip_credentials ) { $ credentials = array_merge ( $ credentials , $ this -> getCredentials ( ) ) ; } $ this -> storage -> storeLoggedUser ( $ credentials ) ; $ this -> setState ( App :: STATE_LOGGED ) ; } } } return $ this -> getLoggedUser ( ) ; }
Retrieves the Twitter User . If there s no logged user yet it will check if the user is coming back from the Twitter Auth page and retrieve its tokens .
53,772
public function getLoggedUser ( ) { $ credentials = $ this -> storage -> getLoggedUser ( ) ; return is_array ( $ credentials ) ? new User ( $ credentials ) : null ; }
Returns a User object with ArrayAccess . Returns null if there s no logged user .
53,773
public function get ( $ path , $ params = [ ] ) { return $ this -> ttools -> makeRequest ( TTools :: API_BASE . '/' . TTools :: API_VERSION . $ path , $ params , 'GET' , false ) ; }
Performs a GET request to the Twitter API
53,774
public function post ( $ path , $ params , $ multipart = false ) { return $ this -> ttools -> makeRequest ( TTools :: API_BASE . '/' . TTools :: API_VERSION . $ path , $ params , 'POST' , $ multipart ) ; }
Performs a POST request to the Twitter API
53,775
public function getProfile ( array $ params = null ) { if ( count ( $ params ) ) { return $ this -> get ( '/users/show.json' , $ params ) ; } return $ this -> getCredentials ( ) ; }
Gets a user profile . If you want to get another user s profile you just need to provide an array with either the user_id or the screen_name .
53,776
public function linkify ( $ message ) { $ message = preg_replace ( '/(https?:\/\/.+?)(\s|$)/' , '<a href="$1">$1</a>$2' , $ message ) ; $ message = preg_replace ( '/#(.+?)(\s|$)/' , '<a href="https://twitter.com/hashtag/$1">#$1</a>$2' , $ message ) ; $ message = preg_replace ( '/@([\w]{1,15})(\b)/' , '<a href="https://twitter.com/$1">@$1</a>$2' , $ message ) ; return $ message ; }
Renders links hash tags and account mentions of a Tweet message as clickable links
53,777
protected function getArg ( $ name ) { switch ( $ this -> action ) { case 'get' ; case 'put' : return $ this -> getURLArg ( $ name ) ; break ; case 'post' ; case 'delete' : return $ this -> getPostArg ( $ name ) ; break ; default : return parent :: getArg ( $ name ) ; break ; } }
Return an argument from request
53,778
function createFilter ( $ callbackOrFilterName , $ options = null , $ resursive = false ) { if ( is_callable ( $ callbackOrFilterName ) ) { $ filter = new Callback ( array ( 'callback' => $ callbackOrFilterName , 'arguments' => $ options ) , $ resursive ) ; } elseif ( is_string ( $ callbackOrFilterName ) ) { if ( class_exists ( '\Sirius\Filtration\Filter\\' . $ callbackOrFilterName ) ) { $ callbackOrFilterName = '\Sirius\Filtration\Filter\\' . $ callbackOrFilterName ; } if ( isset ( $ this -> filtersMap [ strtolower ( $ callbackOrFilterName ) ] ) ) { $ callbackOrFilterName = $ this -> filtersMap [ strtolower ( $ callbackOrFilterName ) ] ; } if ( class_exists ( $ callbackOrFilterName ) && is_subclass_of ( $ callbackOrFilterName , '\Sirius\Filtration\Filter\AbstractFilter' ) ) { $ filter = new $ callbackOrFilterName ( $ options , $ resursive ) ; } else { throw new \ InvalidArgumentException ( sprintf ( 'Impossible to determine the filter based on the name %s' , ( string ) $ callbackOrFilterName ) ) ; } } elseif ( is_object ( $ callbackOrFilterName ) && $ callbackOrFilterName instanceof AbstractFilter ) { $ filter = $ callbackOrFilterName ; } if ( ! isset ( $ filter ) ) { throw new \ InvalidArgumentException ( 'Invalid value for the $callbackorFilterName parameter' ) ; } return $ filter ; }
Factory method to create a filter from various options
53,779
public function input ( $ buffer , $ connection ) { $ len = strlen ( $ buffer ) ; $ method = substr ( $ buffer , 0 , strpos ( $ buffer , ' ' ) ) ; if ( $ len >= 8 && ! in_array ( $ method , $ this -> methods ) ) { throw new \ Exception ( 'Bad Request Method' , 400 ) ; } if ( ! strpos ( $ buffer , "\r\n\r\n" ) ) { if ( $ len >= $ this -> max_header_size ) { throw new \ Exception ( 'Too Large Request Header' , 412 ) ; } return 0 ; } list ( $ header , $ body ) = explode ( "\r\n\r\n" , $ buffer , 2 ) ; if ( strlen ( $ header ) >= $ this -> max_header_size ) { throw new \ Exception ( 'Too Large Request Header' , 413 ) ; } return $ this -> getRequestSize ( $ header , $ body , $ method , $ connection ) ; }
parse http request package size
53,780
public function __doRequest ( $ request , $ location , $ action , $ version , $ one_way = 0 ) { $ this -> __last_request = $ request ; if ( empty ( $ this -> headers ) ) { $ headers = array ( 'Connection: Close' , 'Content-Type: application/soap+xml' ) ; } else { $ headers = $ this -> headers ; } $ soapHeaders = array ( sprintf ( 'SOAPAction: "%s"' , $ action ) , sprintf ( 'Content-Length: %d' , strlen ( $ request ) ) ) ; $ headers = array_merge ( $ headers , $ soapHeaders ) ; $ this -> logger -> debug ( 'Request: ' . $ request , $ headers ) ; $ ch = curl_init ( $ location ) ; $ options = $ this -> curlOptions + array ( CURLOPT_FOLLOWLOCATION => true , CURLOPT_SSL_VERIFYHOST => 2 , CURLOPT_SSL_VERIFYPEER => true , CURLOPT_RETURNTRANSFER => true , CURLOPT_HTTPHEADER => $ headers , CURLOPT_POSTFIELDS => $ request ) ; if ( $ this -> logger -> isHandling ( Logger :: DEBUG ) ) { $ tmp = fopen ( 'php://temp' , 'r+' ) ; $ options [ CURLOPT_VERBOSE ] = true ; $ options [ CURLOPT_STDERR ] = $ tmp ; } curl_setopt_array ( $ ch , $ options ) ; $ output = curl_exec ( $ ch ) ; if ( isset ( $ tmp ) && is_resource ( $ tmp ) ) { rewind ( $ tmp ) ; $ this -> logger -> debug ( stream_get_contents ( $ tmp ) ) ; fclose ( $ tmp ) ; } $ this -> logger -> debug ( 'Response: ' . $ output ) ; return $ output ; }
We override this function from parent to use cURL .
53,781
public function setName ( $ name ) { if ( empty ( ( string ) $ name ) ) { throw new ConfigurationException ( 'The configuration must specify a non-empty name for the Tool Provider.' , ConfigurationException :: TOOL_PROVIDER ) ; } else { $ this -> name = ( string ) $ name ; } }
Set human - readable name of Tool Provider
53,782
public function setID ( $ id ) { if ( empty ( ( string ) $ id ) ) { throw new ConfigurationException ( 'The configuration must specify a non-empty (and globally unique) ID for the Tool Provider.' , ConfigurationException :: TOOL_PROVIDER ) ; } else { $ this -> id = ( string ) $ id ; } }
Set globally unique tokenized ID for Tool Provider
53,783
public function setLaunchURL ( $ launchURL ) { if ( empty ( ( string ) $ launchURL ) ) { throw new ConfigurationException ( 'The configuration must specify a valid launch URL for the Tool Provider.' , ConfigurationException :: TOOL_PROVIDER ) ; } else { $ this -> launchURL = ( string ) $ launchURL ; } }
Set the launch URL to which the Tool Consumer will pass the initial request
53,784
public function setDescription ( $ description ) { $ this -> description = ( empty ( ( string ) $ description ) ? false : ( string ) $ description ) ; }
Set the human - readable description of the Tool Provider
53,785
public function setIconURL ( $ iconURL ) { $ this -> iconURL = ( empty ( ( string ) $ iconURL ) ? false : ( string ) $ iconURL ) ; }
Set URL of 16x16 pixel icon image for Tool Provider
53,786
public function setLaunchPrivacy ( $ launchPrivacy ) { if ( ! is_a ( $ launchPrivacy , LaunchPrivacy :: class ) && ! LaunchPrivacy :: isValid ( $ launchPrivacy ) ) { throw new ConfigurationException ( "Invalid launch privacy setting '$launchPrivacy'" , ConfigurationException :: TOOL_PROVIDER ) ; } else { $ this -> launchPrivacy = ( empty ( $ launchPrivacy ) ? LaunchPrivacy :: ANONYMOUS ( ) : $ launchPrivacy ) ; } }
Set the level of user profile privacy requested of the Tool Consumer
53,787
public function setOption ( $ option , array $ properties ) { if ( ! is_a ( $ option , Option :: class ) && ! Option :: isValid ( $ option ) ) { throw new ConfigurationException ( "Invalid configuration option '$option'" , ConfigurationException :: TOOL_PROVIDER ) ; } else { $ this -> options [ ( string ) $ option ] = $ properties ; } }
Set a tool placement option
53,788
public function setOptionProperty ( $ option , $ property , $ value ) { if ( ! is_a ( $ option , Option :: class ) && ! Option :: isValid ( $ option ) ) { throw new ConfigurationException ( "Invalid configuration option '$option'" , ConfigurationException :: TOOL_PROVIDER ) ; } else { $ this -> options [ ( string ) $ option ] [ $ property ] = $ value ; } }
Set a particular property of a particular tool placment option
53,789
private function getOptionsElement ( DOMDocument $ config , $ option , array $ properties ) { if ( is_a ( $ option , Option :: class ) || Option :: isValid ( $ option ) ) { $ options = $ config -> createElementNS ( self :: LTICM , 'lticm:options' ) ; $ options -> setAttribute ( 'name' , $ option ) ; if ( ! array_key_exists ( 'text' , $ properties ) ) { $ properties [ 'text' ] = $ this -> name ; } if ( ! array_key_exists ( 'url' , $ properties ) ) { $ properties [ 'url' ] = $ this -> launchURL ; } foreach ( $ properties as $ name => $ value ) { $ property = $ config -> createElementNS ( self :: LTICM , 'lticm:property' , $ value ) ; $ property -> setAttribute ( 'name' , $ name ) ; $ options -> appendChild ( $ property ) ; } return $ options ; } return null ; }
Build a tool placement option element
53,790
public function field ( $ field ) { return $ this -> fieldFactory -> createFromField ( $ this -> getFieldData ( $ field ) , $ this -> getFieldValue ( $ field ) ) ; }
Get a field from the group .
53,791
private function getFieldData ( $ field ) { if ( ! isset ( $ this -> _fieldData [ $ field ] ) ) { foreach ( $ this -> fields as $ f ) { if ( ( $ f [ 'key' ] === $ field ) || ( $ f [ 'name' ] === $ field ) ) { $ this -> _fieldData [ $ field ] = $ f ; break ; } } } if ( isset ( $ this -> _fieldData [ $ field ] ) ) { return $ this -> _fieldData [ $ field ] ; } else { throw new Exception ( "Field $field does not exist" ) ; } }
Get field data by field name or key .
53,792
private function getFieldValue ( $ field ) { return isset ( $ this -> values [ $ field ] ) ? $ this -> values [ $ field ] : null ; }
Get field value by name or key .
53,793
public function values ( ) { return array_filter ( $ this -> blueprint , function ( $ value ) { return ! is_string ( $ value ) && ! $ value instanceof HasOneRelationship && ! $ value instanceof Dependency ; } ) ; }
Return current blueprint values including dependencies and relationships
53,794
public function mailTo ( String $ mail , String $ value = NULL , Array $ attributes = [ ] ) : String { if ( ! IS :: email ( $ mail ) ) { throw new InvalidArgumentException ( 'Error' , 'emailParameter' , '1.($mail)' ) ; } $ attributes [ 'href' ] = 'mailto:' . $ mail ; return $ this -> _multiElement ( 'a' , $ value ?? $ mail , $ attributes ) ; }
Creates mail to element
53,795
public function font ( String $ str , String $ size = NULL , String $ color = NULL , String $ face = NULL , Array $ attributes = [ ] ) : String { if ( ! empty ( $ size ) ) { $ attributes [ 'size' ] = $ size ; } if ( ! empty ( $ color ) ) { $ attributes [ 'color' ] = $ color ; } if ( ! empty ( $ face ) ) { $ attributes [ 'face' ] = $ face ; } return $ this -> _multiElement ( 'font' , $ str , $ attributes ) ; }
Creates font elements
53,796
public function script ( String $ path ) : String { if ( ! IS :: url ( $ path ) ) { $ path = Request :: getBaseURL ( Base :: suffix ( $ path , '.js' ) ) ; } $ attributes [ 'href' ] = $ path ; $ attributes [ 'type' ] = 'text/javascript' ; return $ this -> _singleElement ( __FUNCTION__ , $ attributes ) ; }
Creates script element
53,797
public function heading ( String $ str , Int $ type = 3 , Array $ attributes = [ ] ) : String { return $ this -> _multiElement ( 'h' . $ type , $ str , $ attributes ) ; }
Gets head element
53,798
public function element ( String $ element , String $ str = NULL , Array $ attributes = [ ] ) : String { return $ this -> _multiElement ( $ element , $ str , $ attributes ) ; }
Gets multiple element
53,799
public function multiAttr ( String $ str , Array $ array = [ ] ) : String { $ perm = $ this -> settings [ 'attr' ] [ 'perm' ] ?? NULL ; if ( is_array ( $ array ) ) { $ open = '' ; $ close = '' ; $ att = '' ; foreach ( $ array as $ k => $ v ) { if ( ! is_numeric ( $ k ) ) { $ element = $ k ; if ( ! is_array ( $ v ) ) { $ att = ' ' . $ v ; } else { $ att = $ this -> attributes ( $ v ) ; } } else { $ element = $ v ; } $ open .= '<' . $ element . $ att . '>' ; $ close = '</' . $ element . '>' . $ close ; } } else { return $ this -> _perm ( $ perm , $ str ) ; } return $ this -> _perm ( $ perm , $ open . $ str . $ close ) ; }
Gets multiple attributes