idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
100
public function get ( ) { $ modelResult = $ this -> getRequest ( ) -> request ( 'GET' , $ this -> getRequestUrl ( 'models' ) ) ; return $ this -> getModelsFromResult ( $ modelResult ) ; }
Gets All Models
101
public function getById ( $ id ) { $ modelResult = $ this -> getRequest ( ) -> request ( 'GET' , $ this -> getRequestUrl ( sprintf ( 'models/%s' , $ id ) ) ) ; return $ this -> getModelFromResult ( $ modelResult ) ; }
Gets Model By Id
102
public function getModelVersions ( $ id ) { $ modelResult = $ this -> getRequest ( ) -> request ( 'GET' , $ this -> getRequestUrl ( sprintf ( 'models/%s/versions' , $ id ) ) ) ; if ( ! isset ( $ modelResult [ 'model_versions' ] ) ) { throw new \ Exception ( 'Model Versions Not Found' ) ; } $ modelVersions = [ ] ; forea...
Gets Model Versions
103
public function getModelVersionById ( $ modelId , $ versionId ) { $ modelResult = $ this -> getRequest ( ) -> request ( 'GET' , $ this -> getRequestUrl ( sprintf ( 'models/%s/versions/%s' , $ modelId , $ versionId ) ) ) ; if ( isset ( $ modelResult [ 'model_version' ] ) ) { $ modelVersion = new ModelVersion ( $ modelRe...
Gets Model Version By Id
104
public function updateModelConcepts ( array $ modelsArray , $ action ) { $ data [ 'models' ] = [ ] ; foreach ( $ modelsArray as $ modelId => $ modelConcepts ) { $ model = [ ] ; $ model [ 'id' ] = ( string ) $ modelId ; $ model [ 'output_info' ] = [ ] ; $ model [ 'output_info' ] [ 'data' ] = [ ] ; $ model [ 'output_info...
Common Model s Concepts Update Method
105
public function getModelsFromResult ( $ modelResult ) { $ modelsArray = [ ] ; if ( isset ( $ modelResult [ 'models' ] ) ) { foreach ( $ modelResult [ 'models' ] as $ model ) { $ model = new Model ( $ model ) ; $ modelsArray [ ] = $ model ; } } else { throw new \ Exception ( 'Models Not Found' ) ; } return $ modelsArray...
Parses Request Result and gets Models
106
public function addModelConcepts ( array $ data , array $ concepts ) { $ data [ 'concepts' ] = [ ] ; foreach ( $ concepts as $ concept ) { $ data [ 'concepts' ] [ ] = [ 'id' => $ concept -> getId ( ) , ] ; } return $ data ; }
Adds Model s Concepts to Model s Data
107
public function deleteById ( string $ modelId ) { $ deleteResult = $ this -> getRequest ( ) -> request ( 'DELETE' , $ this -> getRequestUrl ( sprintf ( 'models/%s' , $ modelId ) ) ) ; return $ deleteResult [ 'status' ] ; }
Delete Model By Id
108
public function deleteVersionById ( string $ modelId , string $ versionId ) { $ deleteResult = $ this -> getRequest ( ) -> request ( 'DELETE' , $ this -> getRequestUrl ( sprintf ( 'models/%s/versions/%s' , $ modelId , $ versionId ) ) ) ; return $ deleteResult [ 'status' ] ; }
Delete Model Version By Id
109
public function searchByNameAndType ( $ name = null , $ type = null ) { $ searchResult = $ this -> getRequest ( ) -> request ( 'POST' , $ this -> getRequestUrl ( 'models/searches' ) , [ 'model_query' => [ 'name' => $ name , 'type' => $ type , ] , ] ) ; return $ this -> getModelsFromResult ( $ searchResult ) ; }
Searches Models by It s name and type
110
public function setString ( $ context , $ text , $ plural = '' ) { $ this -> context = ( string ) $ context ; $ this -> text = ( string ) $ text ; $ this -> plural = ( string ) $ plural ; $ this -> hash = md5 ( $ this -> plural ? $ this -> context . "\004" . $ this -> text . "\005" . $ this -> plural : $ this -> contex...
Set the translatable text .
111
protected function innerSet ( $ key , $ val ) { $ setMethod = 'set' . ucfirst ( $ key ) ; if ( ! in_array ( $ key , $ this -> notsetters ( ) ) && method_exists ( $ this , $ setMethod ) ) { $ this -> $ setMethod ( $ val ) ; } else { $ validateMethod = 'validate' . ucfirst ( $ key ) ; if ( method_exists ( $ this , $ vali...
This method is reloaded for on - set validation and sanitizing
112
protected function buildRedirectRequest ( RequestInterface $ request , UriInterface $ uri , $ statusCode ) { $ request = $ request -> withUri ( $ uri ) ; if ( false !== $ this -> redirectCodes [ $ statusCode ] [ 'switch' ] && ! in_array ( $ request -> getMethod ( ) , $ this -> redirectCodes [ $ statusCode ] [ 'switch' ...
Builds the redirect request .
113
private function createUri ( ResponseInterface $ response , RequestInterface $ request ) { if ( $ this -> redirectCodes [ $ response -> getStatusCode ( ) ] [ 'multiple' ] && ( ! $ this -> useDefaultForMultiple || ! $ response -> hasHeader ( 'Location' ) ) ) { throw new MultipleRedirectionException ( 'Cannot choose a re...
Creates a new Uri from the old request and the location header .
114
public function invalidateResourceIndex ( FilterInterface $ filter = null ) { $ this -> cache -> deleteItem ( $ this -> getResourceIndexKey ( $ filter ) ) ; }
Invalidates the cached resource index
115
public function invalidateResource ( $ sourcePath , $ version = null ) { $ this -> cache -> deleteItem ( $ this -> getResourceKey ( $ sourcePath , $ version ) ) ; }
Invalidates a cached resource
116
public function invalidateResourceCollection ( $ version = null , FilterInterface $ filter = null ) { $ this -> cache -> deleteItem ( $ this -> getResourceCollectionKey ( $ version , $ filter ) ) ; }
Invalidates the cached resource collection
117
protected function materializeResource ( Resource $ resource ) { foreach ( $ resource as $ method ) { $ request = $ method -> getRequest ( ) ; if ( $ request ) { $ method -> setRequest ( new Schema ( $ request -> getDefinition ( ) ) ) ; } $ responses = $ method -> getResponses ( ) ; foreach ( $ responses as $ statusCod...
A resource can contain schema definitions which are only resolved if we actual call the getDefinition method i . e . the schema is stored in a database . So before we cache the documentation we must get the actual definition object which we can serialize
118
protected function transformResponseToException ( RequestInterface $ request , ResponseInterface $ response ) { if ( $ response -> getStatusCode ( ) >= 400 && $ response -> getStatusCode ( ) < 500 ) { throw new ClientErrorException ( $ response -> getReasonPhrase ( ) , $ request , $ response ) ; } if ( $ response -> ge...
Transform response to an error if possible .
119
public function setRawConcepts ( array $ rawConcepts ) { $ concepts = [ ] ; foreach ( $ rawConcepts as $ rawConcept ) { $ concept = new Concept ( $ rawConcept ) ; $ concepts [ ] = $ concept ; } $ this -> concepts = $ concepts ; return $ this ; }
Sets concepts from Raw Data
120
public function generateRawData ( ) { $ rawData = [ 'id' => $ this -> getId ( ) ] ; $ rawData [ 'output_info' ] = [ ] ; $ rawData [ 'output_info' ] [ 'data' ] = [ ] ; if ( $ this -> getName ( ) ) { $ rawData [ 'name' ] = $ this -> getName ( ) ; } if ( $ this -> getAppId ( ) ) { $ rawData [ 'app_id' ] = $ this -> getApp...
Generates rawData from Model
121
public function getPercentage ( $ round = true ) { if ( $ this -> translated === 0 || $ this -> total === 0 ) { $ result = $ round ? 0 : 0.0 ; } elseif ( $ this -> translated === $ this -> total ) { $ result = $ round ? 100 : 100.0 ; } else { $ result = $ this -> translated * 100.0 / $ this -> total ; if ( $ round ) { ...
Get the translation percentage .
122
public static function getTypesInfo ( ) { $ locale = Localization :: activeLocale ( ) ; if ( ! isset ( self :: $ typesInfo [ $ locale ] ) ) { $ list = [ self :: ADJECTIVE => [ 'name' => tc ( 'TermType' , 'Adjective' ) , 'short' => tc ( 'TermType_short' , 'adj.' ) , 'description' => t ( 'A word that describes a noun or ...
Get all the allowed type names short names and descriptions .
123
public static function isValidType ( $ type ) { if ( $ type === '' ) { $ result = true ; } else { $ valid = self :: getTypesInfo ( ) ; $ result = isset ( $ valid [ $ type ] ) ; } return $ result ; }
Check if a term type is valid .
124
private function lintDir ( $ dir ) { $ finder = Finder :: create ( ) ; $ finder -> files ( ) -> in ( $ dir ) ; $ patterns = $ this -> input -> getOption ( self :: OPTION_PATTERN ) ; if ( ! empty ( $ patterns ) ) { $ patterns = explode ( ',' , $ patterns ) ; foreach ( $ patterns as $ pattern ) { $ finder -> name ( trim ...
lint the content of a directory recursive if defined .
125
private function printReportsOfFilesWithProblems ( ) { $ this -> output -> writeln ( PHP_EOL . '<error>errors:</error>' ) ; foreach ( $ this -> reports as $ report ) { if ( false === $ report -> hasProblems ( ) ) { continue ; } $ file = $ report -> getFile ( ) ; $ this -> output -> writeln ( 'file: ' . $ file -> getPat...
format and print the errors from the queue to the output .
126
private function lintFile ( \ SplFileInfo $ file ) { if ( $ this -> output -> getVerbosity ( ) >= OutputInterface :: VERBOSITY_VERBOSE ) { $ this -> output -> write ( 'lint file ' . $ file . ' ... ' ) ; } $ report = FileReport :: create ( $ file ) ; $ this -> reports [ ] = $ report ; $ status = $ this -> validator -> v...
lint a file pass errors to the queue .
127
public function getIdentify ( $ email , $ name = '' , $ properties = [ ] ) { if ( ! $ email ) { throw new InvalidArgumentException ( 'E-mail cannot be empty or null' ) ; } $ props = [ PayloadProperties :: EMAIL => Encryption :: decode ( $ email ) ] ; if ( $ name ) { $ props [ PayloadProperties :: NAME ] = $ name ; } if...
Generates payload for identify events
128
public function getPageView ( $ url , $ properties = [ ] ) { if ( empty ( $ url ) ) { throw new Exception ( 'url cannot be empty' ) ; } $ props = [ PayloadProperties :: URL => $ url ] ; if ( $ properties ) { $ props [ PayloadProperties :: PROPERTIES ] = $ properties ; } return $ this -> getTrackPayload ( ActionTypes ::...
Generates payload for page view events
129
public function getAddToOrder ( Models \ Product $ product ) { return $ this -> getTrackPayload ( ActionTypes :: ADDED_TO_ORDER , [ PayloadProperties :: PROPERTIES => [ [ PayloadProperties :: PRODUCT => $ product -> toArray ( ) ] ] ] ) ; }
Generates payload for add to order events
130
public function getOrderCompleted ( Models \ Order $ order ) { if ( ! $ order -> hasProducts ( ) ) { throw new \ Exception ( '$order should have at least one product' ) ; } return $ this -> getTrackPayload ( ActionTypes :: ORDER_COMPLETED , [ PayloadProperties :: PROPERTIES => [ [ PayloadProperties :: ORDER_TOTAL_PRICE...
Generates payload for order completed events
131
public function getCustom ( $ event , $ properties = [ ] ) { $ properties = empty ( $ properties ) ? [ ] : [ PayloadProperties :: PROPERTIES => $ properties ] ; return $ this -> getTrackPayload ( $ event , $ properties ) ; }
Generates payload for custom events
132
public function generateRawData ( ) { $ rawData = [ 'id' => $ this -> getId ( ) ] ; if ( $ this -> getValue ( ) ) { $ rawData [ 'value' ] = $ this -> getValue ( ) ; } if ( $ this -> getName ( ) ) { $ rawData [ 'name' ] = $ this -> getName ( ) ; } if ( $ this -> getAppId ( ) ) { $ rawData [ 'app_id' ] = $ this -> getApp...
Generates rawData from Concept
133
protected function registerRegistry ( ) { $ this -> app [ 'registry' ] = $ this -> app -> share ( function ( $ app ) { $ config = $ app -> config -> get ( 'registry' , array ( ) ) ; return new Registry ( $ app [ 'db' ] , $ app [ 'registry.cache' ] , $ config ) ; } ) ; }
Register the collection repository .
134
private function rowSameAsTranslation ( array $ row , GettextTranslation $ translation , $ isPlural , $ pluralCount ) { if ( $ row [ 'text0' ] !== $ translation -> getTranslation ( ) ) { return false ; } if ( $ isPlural === false ) { return true ; } $ same = true ; switch ( $ pluralCount ) { case 6 : if ( $ same && $ r...
Is a database row the same as the translation?
135
protected function buildErrorResponse ( $ error , $ code = null ) { if ( $ code !== null && ( ! is_int ( $ code ) || $ code < 400 ) ) { $ code = null ; } if ( is_object ( $ error ) ) { if ( $ error instanceof AccessDeniedException ) { $ error = $ error -> getMessage ( ) ; if ( $ code === null ) { $ code = Response :: H...
Build an error response .
136
protected function getRequestJson ( ) { if ( $ this -> request -> getContentType ( ) !== 'json' ) { throw new UserMessageException ( t ( 'Invalid request Content-Type: %s' , $ this -> request -> headers -> get ( 'Content-Type' , '' ) ) , Response :: HTTP_NOT_ACCEPTABLE ) ; } $ contentBody = $ this -> request -> getCont...
Check if the request is a JSON request and returns the posted parameters .
137
public function getRateLimit ( ) { $ this -> start ( ) ; try { $ this -> getUserControl ( ) -> checkRateLimit ( ) ; $ this -> getUserControl ( ) -> checkGenericAccess ( __FUNCTION__ ) ; $ rateLimit = $ this -> getUserControl ( ) -> getRateLimit ( ) ; if ( $ rateLimit === null ) { $ result = $ this -> buildJsonResponse ...
Get the current rate limit status .
138
public function getLocales ( ) { $ this -> start ( ) ; try { $ this -> getUserControl ( ) -> checkRateLimit ( ) ; $ this -> getUserControl ( ) -> checkGenericAccess ( __FUNCTION__ ) ; $ locales = $ this -> app -> make ( LocaleRepository :: class ) -> getApprovedLocales ( ) ; $ result = $ this -> buildJsonResponse ( $ t...
Get the list of approved locales .
139
public function getPackages ( ) { $ this -> start ( ) ; try { $ this -> getUserControl ( ) -> checkRateLimit ( ) ; $ this -> getUserControl ( ) -> checkGenericAccess ( __FUNCTION__ ) ; $ repo = $ this -> app -> make ( PackageRepository :: class ) ; $ packages = $ repo -> createQueryBuilder ( 'p' ) -> select ( 'p.handle...
Get the list of packages .
140
public function getPackageVersions ( $ packageHandle ) { $ this -> start ( ) ; try { $ this -> getUserControl ( ) -> checkRateLimit ( ) ; $ this -> getUserControl ( ) -> checkGenericAccess ( __FUNCTION__ ) ; $ package = $ this -> app -> make ( PackageRepository :: class ) -> findOneBy ( [ 'handle' => $ packageHandle ] ...
Get the list of versions of a package .
141
public function getPackageVersionLocales ( $ packageHandle , $ packageVersion , $ minimumLevel = null ) { $ this -> start ( ) ; try { $ this -> getUserControl ( ) -> checkRateLimit ( ) ; $ accessibleLocales = $ this -> getUserControl ( ) -> checkLocaleAccess ( __FUNCTION__ ) ; $ package = $ this -> app -> make ( Packag...
Get some stats about the translations of a package version .
142
public function getPackageVersionTranslations ( $ packageHandle , $ packageVersion , $ localeID , $ formatHandle ) { $ this -> start ( ) ; try { $ this -> getUserControl ( ) -> checkRateLimit ( ) ; $ accessibleLocales = $ this -> getUserControl ( ) -> checkLocaleAccess ( __FUNCTION__ ) ; $ locale = $ this -> app -> mak...
Get the translations of a package version .
143
public function unrecognizedCall ( $ unrecognizedPath = '' ) { $ this -> start ( ) ; if ( $ unrecognizedPath === '' ) { $ message = t ( 'Resource not specified' ) ; } else { $ message = t ( 'Unknown resource %1$s for %2$s method' , $ unrecognizedPath , $ this -> request -> getMethod ( ) ) ; } $ result = $ this -> build...
What to do if the entry point is not recognized .
144
private function getDefaultProviders ( ) { $ defaultProviders = array ( ) ; foreach ( $ this -> defaultProviders as $ provider ) { $ defaultProviders [ $ provider ] = $ this -> getProvider ( $ provider ) ; } return $ defaultProviders ; }
Retrieves array of default providers objects .
145
public function getProvider ( $ label ) { if ( ! isset ( $ this -> providers [ $ label ] ) ) { throw new InvalidArgumentException ( sprintf ( 'Unknown share button provider `%s`' , $ label ) ) ; } return $ this -> providers [ $ label ] ; }
Retrieves a share button provider from collection by its label .
146
public function render ( array $ options = array ( ) ) { if ( ! empty ( $ options [ 'providers' ] ) ) { $ outputProviders = array ( ) ; foreach ( $ options [ 'providers' ] as $ provider ) { $ outputProviders [ ] = $ this -> getProvider ( $ provider ) ; } } else { $ outputProviders = $ this -> getDefaultProviders ( ) ; ...
Renders the share buttons list .
147
public function getUnreviewedInitialTranslations ( LocaleEntity $ locale ) { $ rs = $ this -> app -> make ( TranslationExporter :: class ) -> getUnreviewedSelectQuery ( $ locale ) ; return $ this -> buildInitialTranslations ( $ locale , $ rs ) ; }
Returns the initial translations to be reviewed for the online editor for a specific locale .
148
public function getInitialTranslations ( PackageVersionEntity $ packageVersion , LocaleEntity $ locale ) { $ rs = $ this -> app -> make ( TranslationExporter :: class ) -> getPackageSelectQuery ( $ packageVersion , $ locale , false ) ; return $ this -> buildInitialTranslations ( $ locale , $ rs ) ; }
Returns the initial translations for the online editor for a specific package version .
149
protected function buildInitialTranslations ( LocaleEntity $ locale , \ Concrete \ Core \ Database \ Driver \ PDOStatement $ rs ) { $ approvedSupport = $ this -> app -> make ( Access :: class ) -> getLocaleAccess ( $ locale ) >= Access :: ADMIN ; $ result = [ ] ; $ numPlurals = $ locale -> getPluralCount ( ) ; while ( ...
Builds the initial translations array .
150
public function getTranslatableData ( LocaleEntity $ locale , TranslatableEntity $ translatable , PackageVersionEntity $ packageVersion = null , $ initial = false ) { $ result = [ 'id' => $ translatable -> getID ( ) , 'translations' => $ this -> getTranslations ( $ locale , $ translatable ) , ] ; if ( $ initial ) { $ p...
Returns the data to be used in the editor when editing a string .
151
public function getTranslations ( LocaleEntity $ locale , TranslatableEntity $ translatable ) { $ numPlurals = $ locale -> getPluralCount ( ) ; $ result = [ 'current' => null , 'others' => [ ] , ] ; $ translations = $ this -> app -> make ( TranslationRepository :: class ) -> findBy ( [ 'translatable' => $ translatable ...
Search all the translations associated to a translatable string .
152
public function getComments ( LocaleEntity $ locale , TranslatableEntity $ translatable , TranslatableCommentEntity $ parentComment = null ) { $ repo = $ this -> app -> make ( TranslatableCommentRepository :: class ) ; if ( $ parentComment === null ) { $ qb = $ repo -> createQueryBuilder ( 'c' ) ; $ qb -> where ( 'c.tr...
Get the comments associated to a translatable strings .
153
public function getSuggestions ( LocaleEntity $ locale , TranslatableEntity $ translatable ) { $ result = [ ] ; $ connection = $ this -> app -> make ( EntityManager :: class ) -> getConnection ( ) ; $ rs = $ connection -> executeQuery ( ' select distinct CommunityTranslationTranslatabl...
Search for similar translations .
154
public function getGlossaryTerms ( LocaleEntity $ locale , TranslatableEntity $ translatable ) { $ result = [ ] ; $ connection = $ this -> app -> make ( EntityManager :: class ) -> getConnection ( ) ; $ rs = $ connection -> executeQuery ( ' select CommunityTranslationGlossaryEntries.id...
Search the glossary entries to show when translating a string in a specific locale .
155
public function expandReferences ( array $ references , PackageVersionEntity $ packageVersion ) { if ( empty ( $ references ) ) { return $ references ; } $ gitRepositories = $ this -> app -> make ( GitRepositoryRepository :: class ) -> findBy ( [ 'packageHandle' => $ packageVersion -> getPackage ( ) -> getHandle ( ) ] ...
Expand translatable string references by adding a link to the online repository where they are defined .
156
public function values ( ) : array { $ ret = [ ] ; foreach ( array_keys ( $ this -> __data ) as $ key ) { $ ret [ $ key ] = $ this -> innerGet ( $ key ) ; } return $ ret ; }
Returns array of all object s stored values
157
public function findByHandleAndVersion ( $ packageHandle , $ packageVersion ) { $ result = null ; $ packageHandle = ( string ) $ packageHandle ; if ( $ packageHandle !== '' ) { $ packageVersion = ( string ) $ packageVersion ; if ( $ packageVersion !== '' ) { $ list = $ this -> createQueryBuilder ( 'v' ) -> innerJoin ( ...
Find a version given the package handle and the version .
158
public function addProduct ( $ itemCode , $ itemPrice , $ itemUrl , $ itemQuantity , $ itemTotal = 0 , $ itemName = '' , $ itemImage = '' , $ properties = [ ] ) { $ product = new Product ( $ itemCode , $ itemPrice , $ itemUrl , $ itemQuantity , $ itemTotal , $ itemName , $ itemImage , $ properties ) ; array_push ( $ th...
Adds a new product to order collection
159
public function getInputsFromResult ( $ inputResult ) { $ input_array = [ ] ; if ( ! isset ( $ inputResult [ 'inputs' ] ) ) { throw new \ Exception ( 'Inputs Not Found' ) ; } foreach ( $ inputResult [ 'inputs' ] as $ rawInput ) { $ input = new Input ( $ rawInput ) ; $ input_array [ ] = $ input ; } return $ input_array ...
Parses Request Result and gets Inputs
160
public function init ( $ siteId = '' , $ force = false ) { $ siteId = ! empty ( $ siteId ) ? $ siteId : $ this -> payload -> getSiteId ( ) ; $ hasUserId = $ this -> cookie -> getCookie ( CookieNames :: USER_ID ) ; $ hasUserId = ! empty ( $ hasUserId ) ; $ this -> cookie -> setCookie ( CookieNames :: SITE_ID , $ siteId ...
Stores a cookie that tells if a user is a new one or returned
161
public function create ( $ siteId , $ userAgent = '' , $ requestIPAddress = '' ) { if ( empty ( $ siteId ) ) { throw new \ Exception ( 'Cannot create an instance without a site id' ) ; } $ cookie = new Cookie ( ) ; $ userId = $ cookie -> getCookie ( CookieNames :: USER_ID ) ; $ userId = ! empty ( $ userId ) ? $ userId ...
Creates a Tracker instance
162
private function configureSourceLocale ( ) { $ em = $ this -> app -> make ( EntityManager :: class ) ; $ repo = $ this -> app -> make ( LocaleRepository :: class ) ; if ( $ repo -> findOneBy ( [ 'isSource' => true ] ) === null ) { $ locale = LocaleEntity :: create ( 'en_US' ) ; $ locale -> setIsApproved ( true ) -> set...
Configure the source locale .
163
private function registerCLICommands ( ) { $ console = $ this -> app -> make ( 'console' ) ; $ console -> add ( new TransifexTranslationsCommand ( ) ) ; $ console -> add ( new TransifexGlossaryCommand ( ) ) ; $ console -> add ( new ProcessGitRepositoriesCommand ( ) ) ; $ console -> add ( new AcceptPendingJoinRequestsCo...
Register the CLI commands .
164
private function registerAssets ( ) { $ al = AssetList :: getInstance ( ) ; $ al -> registerMultiple ( [ 'jquery/scroll-to' => [ [ 'javascript' , 'js/jquery.scrollTo.min.js' , [ 'minify' => true , 'combine' => true , 'version' => '2.1.2' ] , $ this ] , ] , 'community_translation/online_translation/bootstrap' => [ [ 'ja...
Register the assets .
165
public function set ( $ id , callable $ resolver ) { $ this -> innerSet ( $ id , $ resolver ) ; unset ( $ this -> resolved [ $ id ] ) ; unset ( $ this -> singletons [ $ id ] ) ; return $ this ; }
Sets a resolver for entry of the container by its identifier .
166
public function singleton ( $ id , callable $ resolver ) { $ this -> innerSet ( $ id , $ resolver ) ; unset ( $ this -> resolved [ $ id ] ) ; $ this -> singletons [ $ id ] = true ; return $ this ; }
Sets a resolver for entry of the container by its identifier as singleton .
167
public function handleRequest ( string $ method , string $ uri = '' , array $ options = [ ] , array $ parameters = [ ] ) { if ( ! empty ( $ parameters ) ) { if ( $ method === 'GET' ) { $ options [ 'query' ] = $ parameters ; } if ( $ method === 'POST' || $ method === 'PATCH' || $ method === 'DELETE' ) { $ options [ 'jso...
Makes a request using Guzzle
168
public function request ( string $ method , string $ path , array $ parameters = [ ] ) { $ options = [ 'headers' => [ 'Authorization' => sprintf ( 'Key %s' , $ this -> apiKey ) , 'User-Agent' => sprintf ( 'Clarifai PHP (https://github.com/darrynten/clarifai-php);v%s;%s' , \ DarrynTen \ Clarifai \ Clarifai :: VERSION , ...
Makes a request to Clarifai
169
public function generateRawData ( ) { $ rawData = [ 'id' => $ this -> getId ( ) ] ; if ( $ this -> getCreatedAt ( ) ) { $ rawData [ 'created_at' ] = $ this -> getCreatedAt ( ) ; } if ( $ this -> getStatusDescription ( ) || $ this -> getStatusCode ( ) ) { $ rawData [ 'status' ] = $ this -> getStatus ( ) ; } return $ raw...
Generates rawData from modelVersion
170
protected function forceTypes ( $ data ) { if ( in_array ( $ data , array ( 'true' , 'false' ) ) ) { $ data = ( $ data === 'true' ? 1 : 0 ) ; } else if ( is_numeric ( $ data ) ) { $ data = ( int ) $ data ; } else if ( gettype ( $ data ) === 'array' ) { foreach ( $ data as $ key => $ value ) { $ data [ $ key ] = $ this ...
Cast values to native PHP variable types .
171
protected function fetchKey ( $ key ) { if ( str_contains ( $ key , '.' ) ) { $ keys = explode ( '.' , $ key ) ; $ search = array_except ( $ keys , 0 ) ; return array ( array_get ( $ keys , 0 ) , implode ( '.' , $ search ) ) ; } return array ( $ key , null ) ; }
Get registry key
172
public function getPaginationHTML ( ) { if ( $ this -> pagination -> haveToPaginate ( ) ) { $ view = new TwitterBootstrap3View ( ) ; $ me = $ this ; $ result = $ view -> render ( $ this -> pagination , function ( $ page ) use ( $ me ) { $ list = $ me -> getItemListObject ( ) ; $ result = ( string ) $ me -> getBaseURL (...
Builds the HTML to be used to control the pagination .
173
public function generateRawData ( ) { $ rawData = [ 'id' => $ this -> getId ( ) ] ; $ rawData [ 'data' ] = [ ] ; $ rawData [ 'data' ] [ 'image' ] = [ ] ; if ( $ this -> getCreatedAt ( ) ) { $ rawData [ 'created_at' ] = $ this -> getCreatedAt ( ) ; } if ( $ this -> getStatusDescription ( ) || $ this -> getStatusCode ( )...
Generates rawData from Input
174
public function splitTimeWindow ( $ timeWindow , $ default = 3600 ) { $ timeWindow = ( int ) $ timeWindow ; if ( $ timeWindow <= 0 ) { $ timeWindow = ( int ) $ default ; } foreach ( array_keys ( $ this -> getTimeWindowUnits ( ) ) as $ u ) { if ( ( $ timeWindow % $ u ) === 0 ) { $ unit = $ u ; } else { break ; } } retur...
Get the representation of a time window expressed in seconds .
175
public function getWidgetHtml ( $ name , $ maxRequests , $ timeWindow ) { list ( $ timeWindowValue , $ timeWindowUnit ) = $ this -> splitTimeWindow ( $ timeWindow ) ; $ html = '<div class="input-group" id="' . $ name . '_container">' ; $ html .= $ this -> form -> number ( $ name . '_maxRequests' , $ maxRequests , [ 'mi...
Create the HTML for a rate limit .
176
public function fromWidgetHtml ( $ name , $ defaultTimeWindow = 3600 ) { $ post = $ this -> request -> request ; $ s = $ post -> get ( $ name . '_maxRequests' ) ; $ maxRequests = ( is_scalar ( $ s ) && is_numeric ( $ s ) ) ? ( int ) $ s : null ; if ( $ maxRequests !== null && $ maxRequests <= 0 ) { throw new UserMessag...
Get the rate limit values from the values of the widget .
177
public function describeRate ( $ maxRequests , $ timeWindow ) { if ( $ maxRequests && $ timeWindow ) { list ( $ value , $ unit ) = $ this -> splitTimeWindow ( $ timeWindow ) ; switch ( $ unit ) { case 60 : $ duration = Unit :: format ( $ value , 'duration/minute' , 'long' ) ; break ; case 3600 : $ duration = Unit :: fo...
Format a rate limit .
178
public function setTranslations ( Locale $ locale , Translations $ translations ) { $ this -> translations [ $ locale -> getID ( ) ] = [ $ locale , $ translations ] ; }
Set the translations for a specific locale .
179
public function getTranslations ( Locale $ locale ) { $ localeID = $ locale -> getID ( ) ; $ translations = isset ( $ this -> translations [ $ localeID ] ) ? $ this -> translations [ $ localeID ] [ 1 ] : null ; if ( $ translations === null ) { $ translations = clone $ this -> getSourceStrings ( true ) ; $ translations ...
Get the translations for a specific locale .
180
public function mergeWith ( Parsed $ other ) { $ mergeMethod = Translations :: MERGE_ADD | Translations :: MERGE_PLURAL ; if ( $ other -> sourceStrings !== null ) { if ( $ this -> sourceStrings === null ) { $ this -> sourceStrings = $ other -> sourceStrings ; } else { $ this -> sourceStrings -> mergeWith ( $ other -> s...
Merge another instance into this one .
181
public function generate ( ) { $ pickChars = str_repeat ( static :: DICTIONARY , static :: LENGTH ) ; for ( ; ; ) { $ value = substr ( str_shuffle ( $ pickChars ) , 0 , static :: LENGTH ) ; if ( preg_match ( static :: TOKEN_GENERATION_REGEX , $ value ) ) { $ this -> insertQuery -> execute ( [ $ value ] ) ; if ( $ this ...
Generate a new API token .
182
public function isGenerated ( $ token ) { $ result = false ; $ token = ( string ) $ token ; if ( $ token !== '' ) { $ this -> searchQuery -> execute ( [ $ token ] ) ; $ row = $ this -> searchQuery -> fetch ( ) ; $ this -> searchQuery -> closeCursor ( ) ; if ( $ row !== false ) { $ result = true ; } } return $ result ; ...
Check if a token has been generated .
183
public function setIsCurrent ( $ value ) { if ( $ value ) { $ this -> current = true ; } else { $ this -> current = null ; } return $ this ; }
Is this the current translation?
184
public function postPersist ( LifecycleEventArgs $ args ) { $ entity = $ args -> getObject ( ) ; if ( $ entity instanceof PackageVersionEntity ) { $ this -> refreshPackageLatestVersion ( $ args -> getObjectManager ( ) , $ entity -> getPackage ( ) ) ; } }
Callback method called when a new entity has been saved .
185
public function postUpdate ( LifecycleEventArgs $ args ) { $ entity = $ args -> getObject ( ) ; if ( $ entity instanceof PackageVersionEntity ) { $ em = $ args -> getObjectManager ( ) ; $ unitOfWork = $ em -> getUnitOfWork ( ) ; $ changeSet = $ unitOfWork -> getEntityChangeSet ( $ entity ) ; if ( in_array ( 'version' ,...
Callback method called when a modified entity is going to be saved .
186
public function getByLocale ( LocaleEntity $ locale ) { $ app = Application :: getFacadeApplication ( ) ; $ result = $ this -> find ( $ locale ) ; if ( $ result === null ) { $ em = $ this -> getEntityManager ( ) ; try { $ numTranslatable = ( int ) $ app -> make ( TranslatableRepository :: class ) -> createQueryBuilder ...
Get the stats for a specific locale . If the stats does not exist yet they are created .
187
public function resetForLocale ( LocaleEntity $ locale ) { $ this -> createQueryBuilder ( 't' ) -> delete ( ) -> where ( 't.locale = :locale' ) -> setParameter ( 'locale' , $ locale ) -> getQuery ( ) -> execute ( ) ; }
Clear the stats for a specific locale .
188
protected function getLocaleGroup ( $ parentName , $ locale ) { if ( ! ( $ locale instanceof LocaleEntity ) ) { $ l = $ this -> app -> make ( LocaleRepository :: class ) -> findApproved ( $ locale ) ; if ( $ l === null ) { throw new UserMessageException ( t ( "The locale identifier '%s' is not valid" , $ locale ) ) ; }...
Get a locale group given its parent group name .
189
public function getGlobalAdministrators ( ) { if ( $ this -> globalAdministrators === null ) { $ this -> globalAdministrators = $ this -> getGroup ( self :: GROUPNAME_GLOBAL_ADMINISTRATORS ) ; } return $ this -> globalAdministrators ; }
Get the global administrators group .
190
public function decodeAspiringTranslatorsGroup ( Group $ group ) { $ result = null ; $ match = null ; if ( preg_match ( '/^\/' . preg_quote ( self :: GROUPNAME_ASPIRING_TRANSLATORS , '/' ) . '\/(.+)$/' , $ group -> getGroupPath ( ) , $ match ) ) { $ result = $ this -> app -> make ( LocaleRepository :: class ) -> findAp...
Check if a group is an aspiring translators group . If so returns the associated locale entity .
191
public function deleteLocaleGroups ( $ localeID ) { foreach ( [ self :: GROUPNAME_LOCALE_ADMINISTRATORS , self :: GROUPNAME_TRANSLATORS , self :: GROUPNAME_ASPIRING_TRANSLATORS , ] as $ parentGroupName ) { $ path = "/$parentGroupName/$localeID" ; $ group = Group :: getByPath ( $ path ) ; if ( $ group !== null ) { $ gro...
Delete the user groups associated to a locale ID .
192
public function clear ( ) { $ i = 0 ; if ( $ glob = @ glob ( $ this -> f3 -> get ( 'ASSETS.public_path' ) . '*' ) ) foreach ( $ glob as $ file ) if ( preg_match ( '/.+?\.(js|css)/i' , basename ( $ file ) ) ) { $ i ++ ; @ unlink ( $ file ) ; } return $ i ; }
reset the temporary public path
193
public function getAssets ( $ group = 'head' , $ type = null ) { $ assets = array ( ) ; if ( ! isset ( $ this -> assets [ $ group ] ) ) return $ assets ; $ types = array_keys ( $ this -> assets [ $ group ] ) ; foreach ( $ types as $ asset_type ) { if ( $ type && $ type != $ asset_type ) continue ; krsort ( $ this -> as...
get sorted unique assets from group
194
public function renderGroup ( $ assets ) { $ out = array ( ) ; if ( $ this -> f3 -> get ( 'ASSETS.trim_public_root' ) ) { $ basePath = $ this -> f3 -> fixslashes ( realpath ( $ this -> f3 -> fixslashes ( $ _SERVER [ 'DOCUMENT_ROOT' ] . $ this -> f3 -> get ( 'BASE' ) ) ) ) ; $ cDir = $ this -> f3 -> fixslashes ( getcwd ...
render asset group
195
public function fixRelativePaths ( $ content , $ path , $ targetDir = null ) { $ f3 = $ this -> f3 ; $ method = $ f3 -> get ( 'ASSETS.fixRelativePaths' ) ; if ( $ method !== FALSE ) { $ webBase = $ f3 -> get ( 'BASE' ) ; $ basePath = $ f3 -> fixslashes ( realpath ( $ f3 -> fixslashes ( $ _SERVER [ 'DOCUMENT_ROOT' ] . $...
Rewrite relative URLs in CSS
196
public function relPath ( $ from , $ to ) { $ expFrom = explode ( '/' , $ from ) ; $ expTo = explode ( '/' , $ to ) ; $ max = max ( count ( $ expFrom ) , count ( $ expTo ) ) ; $ rel = [ ] ; $ base = TRUE ; for ( $ i = 0 ; $ i < $ max ; $ i ++ ) { if ( $ base && isset ( $ expTo [ $ i ] ) && isset ( $ expFrom [ $ i ] ) &...
assemble relative path to go from A to B
197
public function add ( $ path , $ type , $ group = 'head' , $ priority = 5 , $ slot = null , $ params = null ) { if ( ! isset ( $ this -> assets [ $ group ] ) ) $ this -> assets [ $ group ] = array ( ) ; if ( ! isset ( $ this -> assets [ $ group ] [ $ type ] ) ) $ this -> assets [ $ group ] [ $ type ] = array ( ) ; $ as...
add an asset
198
public function addJs ( $ path , $ priority = 5 , $ group = 'footer' , $ slot = null ) { $ this -> add ( $ path , 'js' , $ group , $ priority , $ slot ) ; }
add a javascript asset
199
public function addCss ( $ path , $ priority = 5 , $ group = 'head' , $ slot = null ) { $ this -> add ( $ path , 'css' , $ group , $ priority , $ slot ) ; }
add a css asset