idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
14,000
public function getFullUrl ( $ path ) { if ( 0 === strpos ( $ path , 'http' ) || 0 === strpos ( $ path , 'mailto:' ) || 0 === strpos ( $ path , '#' ) ) { return $ path ; } $ router = $ this -> get ( 'router' ) ; if ( '/' != $ path [ 0 ] ) { $ path = '/' . $ path ; } $ baseUrl = $ router -> getContext ( ) -> getBaseUrl ...
Absolutize an URL .
14,001
public function getTrackingAnalytics ( ) { $ ret = null ; $ ua = $ this -> getAnalyticsUA ( ) ; if ( $ ua ) { $ ret = "<script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a....
Get tracking code for analytics if parametered .
14,002
public function getAsseticVersionUrl ( $ url ) { $ tmp = $ this -> getParameter ( 'assetic_versions' ) ; if ( $ tmp && is_array ( $ tmp ) ) { $ tmpUrl = basename ( $ url ) ; $ url .= '?' . ( isset ( $ tmp [ $ tmpUrl ] ) && $ tmp [ $ tmpUrl ] ? $ tmp [ $ tmpUrl ] : ( isset ( $ tmp [ 'global' ] ) ? $ tmp [ 'global' ] : '...
Get url with assetic version if configured .
14,003
public function getNewUniqRandomKey ( ObjectRepository $ repository , $ field , $ length ) { $ entity = true ; while ( $ entity ) { $ random = $ this -> randomStr ( $ length ) ; $ entity = $ repository -> findOneBy ( array ( $ field => $ random ) ) ; } return $ random ; }
Get a new random uniq key for a specific field on a given repository .
14,004
public function getPager ( $ route , $ routePrm , $ total , $ page , $ nbPerPage ) { return new Pager ( $ this , $ route , $ routePrm , $ total , $ page , $ nbPerPage ) ; }
Create a pager .
14,005
public function getUniqFileName ( $ dir , $ name , $ sep = '-' ) { list ( $ name , $ ext ) = $ this -> standardizeFileName ( $ name , true ) ; $ nameF = $ name . '.' . $ ext ; $ i = 2 ; while ( isset ( $ this -> uniqFileNames [ $ dir . '/' . $ nameF ] ) || file_exists ( $ dir . '/' . $ nameF ) ) { $ nameF = $ name . $ ...
Get a new uniq filename in a directory .
14,006
public function standardizeFileName ( $ name , $ asArray = false ) { $ name = mb_strtolower ( $ name ) ; $ ext = $ this -> getExt ( $ name ) ; if ( $ ext ) { $ pos = strpos ( $ name , $ ext ) ; if ( $ pos > 0 ) { $ name = substr ( $ name , 0 , $ pos ) ; } } $ name = $ this -> urlify ( $ name ) ; return $ asArray ? [ $ ...
Standardize filename using urlify function and keeping the extension .
14,007
public function humanFileSize ( $ file ) { $ size = filesize ( $ file ) ; $ mod = 1024 ; $ units = explode ( ' ' , 'B KB MB GB TB PB' ) ; for ( $ i = 0 ; $ size > $ mod ; ++ $ i ) { $ size /= $ mod ; } return round ( $ size , 2 ) . ' ' . $ units [ $ i ] ; }
Get a human file size .
14,008
public function html2text ( $ html ) { if ( ! $ this -> html2textLoaded ) { require dirname ( __FILE__ ) . '/../Utility/Html2Text.php' ; $ this -> html2textLoaded = true ; } $ html2text = new Html2Text ( $ html ) ; return $ html2text -> get_text ( ) ; }
Transform HTML content into text .
14,009
public function joinRows ( $ rows , $ separator = ', ' ) { $ ret = array ( ) ; foreach ( $ rows as $ r ) { $ ret [ ] = $ r . '' ; } return implode ( $ separator , $ ret ) ; }
Join rows in a single string .
14,010
public function redirectIfNotUrl ( $ url , array $ allowParams = array ( ) ) { if ( $ url != $ this -> getRequest ( ) -> getRequestUri ( ) ) { $ redirect = true ; $ newArgs = array ( ) ; try { $ tmp = parse_url ( $ this -> getRequest ( ) -> getRequestUri ( ) ) ; if ( isset ( $ tmp [ 'path' ] ) && $ tmp [ 'path' ] == $ ...
Check if the current URL is matching the desired URL and return a redirect response if not .
14,011
public function formatDate ( \ DateTime $ datetime , $ format , $ useOffset = null ) { if ( is_null ( $ useOffset ) ) { $ useOffset = $ this -> getParameter ( 'nyroDev_utility.dateFormatUseOffsetDefault' ) ; } $ offset = 0 ; if ( $ useOffset ) { $ tz = new \ DateTimeZone ( date_default_timezone_get ( ) ) ; $ offset = -...
Format a date using strftime .
14,012
public function truncate ( $ text , $ limit , $ isFile = false , $ encoding = 'UTF-8' ) { $ ext = null ; if ( $ isFile ) { $ ext = $ this -> getExt ( $ text ) ; if ( $ ext ) { $ limit -= mb_strlen ( $ ext , $ encoding ) ; $ text = mb_substr ( $ text , 0 , - mb_strlen ( $ ext , $ encoding ) - 1 ) ; } } if ( mb_strlen ( ...
Truncate text to not be too large .
14,013
public function handleGetAttributesFromDca ( GetAttributesFromDcaEvent $ event ) { $ widgetAdapter = $ this -> framework -> getAdapter ( Widget :: class ) ; $ event -> setResult ( $ widgetAdapter -> getAttributesFromDca ( $ event -> getFieldConfiguration ( ) , $ event -> getWidgetName ( ) , $ event -> getValue ( ) , $ ...
Handle the widget preparation .
14,014
protected function setSessionConfig ( ) { $ oneWeek = time ( ) + 60 * 60 * 24 * 7 ; $ this -> expire = $ this -> expire ?? $ oneWeek ; $ this -> path = $ this -> path ?? "/" ; $ this -> domain = $ this -> domain ?? NULL ; $ this -> secure = $ this -> secure ?? NULL ; $ this -> httponly = $ this -> httponly ?? TRUE ; se...
Sets session cofiguration before session starts .
14,015
public function cofigureSession ( string $ name , $ value ) : bool { if ( ! property_exists ( $ this , $ name ) ) return FALSE ; $ allowedProperties = [ 'expire' , 'path' , 'domain' , 'secure' , 'httponly' ] ; if ( ! in_array ( strtolower ( $ name ) , $ allowedProperties ) ) return FALSE ; $ this -> $ name = $ value ; ...
Configures session .
14,016
public function log ( $ level , $ message , array $ context = [ ] ) { $ logLevel = new LogLevel ( ) ; $ context += [ 'facility' => 16 , 'hostname' => gethostname ( ) , 'program' => 'logger' ] ; if ( ! $ logLevel -> isValidLevel ( $ level ) ) { throw new InvalidArgumentException ( 'Invalid log level.' ) ; } $ severity =...
Log a message to Papertrail
14,017
protected function writeToSocket ( $ socket , $ message ) { socket_sendto ( $ socket , $ message , strlen ( $ message ) , 0 , PAPERTRAIL_HOST , PAPERTRAIL_PORT ) ; }
Writes to the socket
14,018
public static function TokenizedTypeFromXmlType ( $ type ) { if ( is_null ( $ type ) || ! is_string ( $ type ) ) { return XmlTokenizedType :: None ; } $ types = SchemaTypes :: getInstance ( ) ; $ atom = $ types -> getAtomicType ( $ type ) ; return isset ( XmlTokenizedType :: $ typeToCodeMap [ $ atom ] ) ? XmlTokenizedT...
Get a type code for an Xml type name
14,019
public static function REMOVE_EMPTY ( array $ data ) { $ a = array ( ) ; foreach ( $ data as $ key => $ value ) { $ a [ $ key ] = is_array ( $ value ) ? array_filter ( $ value ) : $ value ; } return array_filter ( $ a ) ; }
two level filter array a default for dataCleaner callback
14,020
public function transcodeWithPreset ( $ inFile , $ preset , $ outFile = false , $ conflictMode = self :: ONCONFLICT_INCREMENT , $ dirMode = self :: ONDIR_EXCEPTION , $ failMode = self :: ONFAIL_DELETE ) { $ inputPath = ( $ inFile instanceof File ) ? $ inFile -> getRealPath ( ) : $ inFile ; $ presetKey = ( $ preset inst...
The core method of the transcode process . Takes file input validates runs a transcode process validates return and returns file output .
14,021
public function transcodeWithAdapter ( $ inFile , $ adapterName , $ options = array ( ) , $ outFile = false , $ conflictMode = self :: ONCONFLICT_INCREMENT , $ dirMode = self :: ONDIR_EXCEPTION , $ failMode = self :: ONFAIL_DELETE ) { $ preset = new Preset ( 'dynamic' , $ adapterName , $ options ) ; return $ this -> tr...
Transcode a file with a specific adapter directly . Internally builds a dynamic preset with the specified options .
14,022
public function getOutfilePath ( $ inFile , $ preset , $ outFile = false , $ conflictMode = self :: ONCONFLICT_INCREMENT , $ dirMode = self :: ONDIR_EXCEPTION , $ failMode = self :: ONFAIL_DELETE ) { $ inputPath = ( $ inFile instanceof File ) ? $ inFile -> getRealPath ( ) : $ inFile ; $ presetKey = ( $ preset instanceo...
Retrieve the outfile path of a hypothetical transcode process
14,023
protected function processOutputFilepath ( $ outputPath , $ conflictMode , $ dirMode ) { $ outputIsDirectory = $ this -> pathIsDirectory ( $ outputPath ) ; if ( file_exists ( $ outputPath ) ) { if ( $ conflictMode === self :: ONCONFLICT_EXCEPTION ) { throw new Exception \ FileAlreadyExistsException ( sprintf ( "File %s...
Scan an output path to make sure there are no conflicts . Handle conflicts according to mode . Check to make sure final path is actually writable . Returns the final output path which may have been altered depending on the mode .
14,024
protected function incrementConflictingPath ( $ path ) { $ isDir = $ this -> pathIsDirectory ( $ path ) ; $ expPath = explode ( DIRECTORY_SEPARATOR , $ path ) ; $ oldFileName = array_pop ( $ expPath ) ; $ basePath = implode ( DIRECTORY_SEPARATOR , $ expPath ) ; if ( $ isDir ) { $ i = 1 ; while ( file_exists ( $ newFile...
If a previous file exists create a new path numerically incrementing a number in the string to avoid conflicts .
14,025
protected function removeDirectory ( $ path ) { foreach ( scandir ( $ path ) as $ item ) { if ( ! in_array ( $ item , array ( '.' , '..' ) ) ) { @ unlink ( $ path . DIRECTORY_SEPARATOR . $ item ) ; $ this -> dispatcher -> dispatch ( TranscodeEvents :: DIR_REMOVED , new FileEvent ( $ outputPath ) ) ; } } if ( ! rmdir ( ...
Remove a directory and all of its contents
14,026
protected function cleanOutputFile ( File $ file ) { $ path = $ file -> getRealPath ( ) ; if ( $ file -> isDir ( ) ) { chmod ( $ path , $ this -> getDirectoryCreationMode ( ) ) ; $ this -> dispatcher -> dispatch ( TranscodeEvents :: DIR_MODIFIED , new FileEvent ( $ path ) ) ; } else { chmod ( $ path , $ this -> getFile...
Post process newly created files by setting proper file permissions based on set permission modes
14,027
protected function cleanFailedTranscode ( Adapter $ adapter , $ outputFilePath , $ failMode ) { if ( file_exists ( $ outputFilePath ) ) { if ( $ failMode === self :: ONFAIL_DELETE ) { @ unlink ( $ outputFilePath ) ; $ this -> dispatcher -> dispatch ( TranscodeEvents :: FILE_REMOVED , new FileEvent ( $ outputFilePath ) ...
Cleanup after a failed transcode - this may entail deleting newly created files depending on the mode in which the transcode process executed
14,028
public function dispatch ( $ name , Event $ e = null ) { return $ this -> dispatcher -> dispatch ( $ name , $ e ) ; }
Dispatch event used by Adapters to notify adapter specific events
14,029
public function getAdapter ( $ key ) { if ( ! isset ( $ this -> adapters [ $ key ] ) ) { throw new Exception \ AdapterNotFoundException ( sprintf ( "Requested adapter %s was not found in the Transcoder." , $ key ) ) ; } return $ this -> adapters [ $ key ] ; }
Return an adapter instance by key
14,030
public function registerAdapter ( Adapter $ adapter ) { $ adapter -> setTranscoder ( $ this ) ; $ this -> adapters [ $ adapter -> getKey ( ) ] = $ adapter ; return $ this ; }
Register an adapter instance with the Transcoder
14,031
public function removeAdapter ( $ key ) { if ( isset ( $ this -> adapters [ $ key ] ) ) { $ this -> adapters [ $ key ] -> setTranscoder ( ) ; unset ( $ this -> adapters [ $ key ] ) ; } return $ this ; }
Remove an adapter instance with the given key from the Transcoder
14,032
public function getPreset ( $ key ) { if ( ! isset ( $ this -> presets [ $ key ] ) ) { throw new Exception \ PresetNotFoundException ( sprintf ( "Requested preset %s was not found in the Transcoder." , $ key ) ) ; } return $ this -> presets [ $ key ] ; }
Get a preset instance with the given key
14,033
public function removePreset ( $ key ) { if ( isset ( $ this -> presets [ $ key ] ) ) { unset ( $ this -> presets [ $ key ] ) ; } return $ this ; }
Remove a preset with the given key
14,034
public function setFileCreationMode ( $ mode ) { if ( 0 != $ mode [ 0 ] ) { $ mode = "0" . $ mode ; } $ this -> fileCreationMode = intval ( $ mode , 8 ) ; return $ this ; }
Set the file creation mode to use when new files are created during a transcode process .
14,035
public function setDirectoryCreationMode ( $ mode ) { if ( 0 != $ mode [ 0 ] ) { $ mode = "0" . $ mode ; } $ this -> directoryCreationMode = intval ( $ mode , 8 ) ; return $ this ; }
Set the file creation mode to use when new directories are created during a transcode process .
14,036
public function add ( $ provider ) { if ( is_object ( $ provider ) && $ provider instanceof Provider ) return $ this -> register ( $ provider ) ; if ( $ this -> lateRegistry == true ) { $ this -> providers [ $ provider ] = false ; return $ this ; } if ( method_exists ( $ provider , 'provides' ) && is_array ( $ dependen...
A flexible prover registrar Register the provider given the class name Or if the Provider itself register
14,037
public function boot ( ) { foreach ( $ this -> providers as $ provider => $ registered ) { if ( $ registered === false ) $ this -> register ( new $ provider ) ; } }
Boot all the late registry providers
14,038
public function listen ( $ name ) { if ( ! isset ( $ this -> providersDeferred [ $ name ] ) ) return ; $ this -> register ( new $ this -> providersDeferred [ $ name ] ) ; unset ( $ this -> providersDeferred [ $ name ] ) ; }
Differed providers register Invoked on application container dependency search
14,039
private static function init ( ) { if ( ! self :: $ data_initialized ) { self :: $ data_initialized = true ; $ page_components_collection = new PageComponentEntityRepository ( ) ; $ page_components_collection -> setWherePageId ( PAGE_ID ) ; $ page_components_collection -> addWhereFieldIsLike ( 'component' , 'select_plu...
Preload all data of plugins
14,040
public function getRequired ( string $ key ) { if ( ! isset ( $ this -> values [ $ key ] ) ) { throw new \ RuntimeException ( "the required config value '$key' was not found" ) ; } return $ this -> values [ $ key ] ; }
Retrieve a value that must exist
14,041
public function label ( $ label = null ) { if ( $ label ) { $ this -> label = $ label ; } else { return isset ( $ this -> label ) ? $ this -> label : $ this -> name ( ) ; } }
Returns the label for the input
14,042
public function add_path ( string $ path ) { $ path = \ trailingslashit ( $ path ) ; $ this -> paths [ ] = $ path ; $ this -> parse_files ( $ path ) ; }
Add a new config folder path .
14,043
public function add_default_path ( string $ path ) { $ path = \ trailingslashit ( $ path ) ; $ this -> paths [ ] = $ path ; $ this -> parse_files ( $ path , false ) ; }
Add a new config folder path but any found config keys will not overwrite an existing entry .
14,044
private function parse_files ( $ path , $ overwrite = true ) { if ( \ is_dir ( $ path ) ) { $ files = \ glob ( $ path . '*.php' ) ; } if ( ! empty ( $ files ) ) { foreach ( $ files as $ file ) { $ parsed_options = require $ file ; $ option_set = $ this -> get_filename ( $ file ) ; if ( ! \ is_array ( $ parsed_options )...
Scans a path for config files and merges them into the config .
14,045
private function recurse_through_config ( array $ values , $ path = null ) { if ( empty ( $ values ) ) { $ this -> has ( $ path ) ; } foreach ( $ values as $ key => $ value ) { if ( ! \ is_string ( $ key ) ) { $ this -> has ( $ path ) ; continue ; } if ( \ is_array ( $ value ) ) { $ this -> recurse_through_config ( $ v...
Primes the cache array .
14,046
public function getFile ( $ path ) { $ dirPath = realpath ( $ this -> path ) ; if ( $ dirPath === false ) { throw new InvalidPath ( 'Path "' . $ this -> path . '" doesn\'t exists or inaccsessible' , null , null , $ this -> path ) ; } return new File ( $ dirPath . DIRECTORY_SEPARATOR . $ path ) ; }
Get a file from directory
14,047
public function addImagesDroplist ( $ configs ) { add_filter ( 'image_size_names_choose' , function ( $ sizes ) use ( $ configs ) { $ new_sizes = [ ] ; foreach ( $ configs as $ key => $ props ) { if ( 4 !== count ( $ props ) ) { continue ; } $ label = array_pop ( $ props ) ; if ( empty ( $ label ) ) { continue ; } $ ne...
Add images names to droplist .
14,048
protected function getEnvironmentEndpoint ( ? string $ group = null ) : ? string { $ environment = $ this -> getEnvironment ( ) ; if ( \ is_null ( $ group ) || empty ( $ group ) ) { return static :: $ endpoints [ $ environment ] ; } return static :: $ endpoints [ $ environment ] [ $ group ] ?? null ; }
Get environment endpoint .
14,049
protected static function initializeColumns ( \ Template $ template ) { $ layout = Bootstrap :: getLayout ( ) ; switch ( $ layout -> cols ) { case '2cll' : $ template -> leftClass = $ layout -> bootstrap_leftClass ; $ template -> mainClass = $ layout -> bootstrap_mainClass ; $ template -> mainClassAttribute = sprintf (...
initialize layout columns
14,050
protected static function initializeRows ( $ template ) { $ layout = Bootstrap :: getLayout ( ) ; switch ( $ layout -> rows ) { case '2rwh' : $ template -> headerClass = $ layout -> bootstrap_headerClass ; $ template -> headerClassAttribute = sprintf ( static :: $ classAttribute , $ layout -> bootstrap_headerClass ) ; ...
initialize layout rows
14,051
public function replace ( $ id , $ config = array ( ) , $ events = array ( ) ) { $ out = "" ; if ( ! $ this -> initialized ) { $ out .= $ this -> init ( ) ; } $ _config = $ this -> configSettings ( $ config , $ events ) ; $ js = $ this -> returnGlobalEvents ( ) ; if ( ! empty ( $ _config ) ) { $ js .= "CKEDITOR.replace...
Replaces a &lt ; textarea&gt ; with a %CKEditor instance .
14,052
private function returnGlobalEvents ( ) { static $ returnedEvents ; $ out = "" ; if ( ! isset ( $ returnedEvents ) ) { $ returnedEvents = array ( ) ; } if ( ! empty ( $ this -> globalEvents ) ) { foreach ( $ this -> globalEvents as $ eventName => $ handlers ) { foreach ( $ handlers as $ handler => $ code ) { if ( ! iss...
Return global event handlers .
14,053
protected function verifyAccessToken ( $ oAuthVerifier ) { $ uri = new Uri ( 'https://api.twitter.com/oauth/access_token' ) ; $ request = Request :: create ( $ uri , 'POST' , array ( 'oauth_verifier' => $ oAuthVerifier ) ) ; $ request = $ this -> requestSignatureGenerator -> signRequest ( $ request ) ; $ request -> set...
Request the final token and secret with the given oauth_verifier .
14,054
protected function createOrUpdateAccount ( $ token , $ tokenSecret ) { $ uri = new Uri ( 'https://api.twitter.com/1.1/account/verify_credentials.json' ) ; $ request = Request :: create ( $ uri , 'GET' ) ; $ request = $ this -> requestSignatureGenerator -> signRequest ( $ request ) ; $ request -> setHeader ( 'Content-Ty...
check for an existing user account and either return that or create a fresh account for the authenticated user .
14,055
public function init ( ) { $ sapi = php_sapi_name ( ) ; if ( $ sapi == 'cli' ) return ; if ( Yii :: getPathOfAlias ( 'analytics' ) === false ) Yii :: setPathOfAlias ( 'analytics' , realpath ( dirname ( __FILE__ ) . '/..' ) ) ; parent :: init ( ) ; $ providers = $ this -> getProviders ( ) ; if ( empty ( $ providers ) ) ...
Registers Analytics . js and initializes the tracking code
14,056
private function fetchFieldsContainsMany ( array $ fetchFields , FullyQualifiedClassName $ section ) : bool { $ sectionClass = ( string ) $ section ; $ fields = $ sectionClass :: fieldInfo ( ) ; foreach ( $ fetchFields as $ fetchField ) { if ( ! is_null ( $ this -> isManyRelationship ( $ fetchField , $ fields ) ) ) { r...
The fetch fields class is momentarily not ready to handle to - many relationships so skip them .
14,057
public static function write ( $ filename , $ data , $ permission = 0777 , $ flags = LOCK_EX , $ relative = true ) { if ( $ relative && $ filename [ 0 ] == '.' ) { $ path = \ Application :: get ( 'application.path_full' ) ; $ info = pathinfo ( $ filename ) ; $ filename = realpath ( $ path . $ info [ 'dirname' ] ) . DIR...
Write content to file and sets permissions
14,058
public static function iterate ( string $ dir , array $ options = [ ] ) : array { $ result = [ ] ; $ relative_path = realpath ( $ dir ) ; if ( empty ( $ options [ 'recursive' ] ) ) { $ iterator = new \ DirectoryIterator ( $ dir ) ; } else { $ iterator = new \ RecursiveIteratorIterator ( new \ RecursiveDirectoryIterator...
Iterate over directory
14,059
private static function iterateProcessPathInnerHelper ( string $ dir , string $ relative_path ) { if ( $ relative_path == '' ) { return $ dir ; } else { $ dir = trim2 ( $ dir , '^' . $ relative_path , '' ) ; $ dir = ltrim ( $ dir , DIRECTORY_SEPARATOR ) ; return $ dir ; } }
Function to remove absolute path
14,060
public static function replace ( string $ filename , string $ find , string $ replace ) : bool { if ( ! file_exists ( $ filename ) ) return false ; $ lines = file ( $ filename , FILE_IGNORE_NEW_LINES ) ; foreach ( $ lines as $ k => $ v ) { if ( stripos ( $ v , $ find ) !== false ) { $ lines [ $ k ] = $ replace ; } } re...
Replace string in a file
14,061
public static function getTempFilename ( string $ path = '' , string $ prefix = '' , string $ extension = '' ) : string { if ( $ path === '' ) { $ path = sys_get_temp_dir ( ) ; } if ( $ extension !== '' && substr ( $ extension , 0 , 1 ) !== '.' ) { $ extension = '.' . $ extension ; } $ filename = Str :: unique ( $ pref...
Get temp filename .
14,062
public static function getLines ( string $ filename , array $ defaultValue = [ ] ) : array { $ content = self :: get ( $ filename ) ; $ content = str_replace ( "\r" , '' , $ content ) ; if ( trim ( $ content ) !== '' ) { return explode ( "\n" , $ content ) ; } return $ defaultValue ; }
Get lines .
14,063
public static function putLines ( string $ filename , array $ lines , string $ separator = "\n" ) : int { return self :: put ( $ filename , implode ( $ separator , $ lines ) ) ; }
Put lines .
14,064
public static function appendLines ( string $ filename , array $ lines , string $ separator = "\n" ) : int { if ( self :: exist ( $ filename ) ) { $ existingLines = self :: getLines ( $ filename ) ; $ lines = array_merge ( $ existingLines , $ lines ) ; return self :: putLines ( $ filename , $ lines , $ separator ) ; } ...
Append lines .
14,065
public static function getStub ( string $ filename , array $ tokens = [ ] , string $ defaultContent = '' ) : string { return self :: getTemplate ( $ filename , $ tokens , $ defaultContent , 'stub' ) ; }
Get stub .
14,066
public static function getJson ( string $ filename , array $ defaultValue = [ ] ) : array { if ( ! Str :: endsWith ( $ filename , '.json' ) ) { $ filename .= '.json' ; } $ data = self :: get ( $ filename ) ; if ( $ data === '' ) { return $ defaultValue ; } $ data = json_decode ( $ data , true ) ; if ( $ data === null |...
Load json .
14,067
public static function putJson ( string $ filename , array $ data , bool $ prettyPrint = true ) : void { if ( ! Str :: endsWith ( $ filename , '.json' ) ) { $ filename .= '.json' ; } $ options = JSON_UNESCAPED_SLASHES ; if ( $ prettyPrint ) { $ options += JSON_PRETTY_PRINT ; } $ data = json_encode ( $ data , $ options ...
Save json .
14,068
public function setBaseUrl ( $ url ) { if ( $ url === '/' || $ url === '//' ) { $ this -> baseUrl = $ url ; return ; } $ this -> baseUrl = rtrim ( $ url , '/' ) . '/' ; return $ this ; }
Set the base url
14,069
public function getPath ( ) { if ( $ this -> isLocal ) { return $ this -> basePath . DIRECTORY_SEPARATOR . $ this -> name ; } return $ this -> basePath . $ this -> name ; }
Get full path to the resource
14,070
public function getUrl ( ) { $ url = $ this -> baseUrl . $ this -> name ; if ( $ this -> hashAppend ) { $ meta = $ this -> getMetadata ( ) ; if ( $ meta !== false ) { $ url .= '?' . $ meta -> hash ; } } return $ url ; }
Get URL of the resource
14,071
protected function getMetadata ( ) { if ( $ this -> metadataManager === null ) { throw new Exceptions \ MetadataError ( 'Metadata manager was not set' ) ; } return $ this -> metadataManager -> getMetadata ( $ this ) ; }
Get metadata for the file resource
14,072
public function prependResource ( $ resource ) { $ resource = $ this -> handleResource ( $ resource ) ; $ this -> resources -> unshift ( $ resource ) ; return $ resource ; }
Prepend the source
14,073
public function appendResource ( $ resource ) { $ resource = $ this -> handleResource ( $ resource ) ; $ this -> resources [ ] = $ resource ; return $ resource ; }
Append the source
14,074
protected function handleResource ( $ resource ) { if ( $ resource instanceof Resource ) { return $ resource ; } if ( preg_match ( '~^[a-z]+:~' , $ resource ) ) { $ slashPos = strrpos ( $ resource , '/' ) ; $ base = substr ( $ resource , 0 , $ slashPos ) ; $ name = substr ( $ resource , $ slashPos + 1 ) ; $ resource = ...
Handle the resource
14,075
public function getUser ( $ id = null ) : ? Authenticatable { if ( $ id === null ) { return $ this -> getModel ( ) ; } if ( is_int ( $ id ) ) { return $ this -> getById ( $ id ) ; } if ( filter_var ( $ id , FILTER_VALIDATE_EMAIL ) !== false ) { return $ this -> getByEmail ( $ id ) ; } return $ this -> getModel ( ) ; }
Fetch a user .
14,076
public function getByToken ( int $ id , string $ token , int $ type = self :: TOKEN_TYPE_REMEMBER ) : ? Authenticatable { return $ type === self :: TOKEN_TYPE_REMEMBER ? $ this -> getByRememberToken ( $ id , $ token ) : $ this -> getByApiToken ( $ id , $ token ) ; }
Retrieve a user by their unique identifier and token .
14,077
public function getByApiToken ( int $ id , string $ token ) : ? Authenticatable { $ model = $ this -> getModel ( ) ; $ user = $ model -> newQuery ( ) -> where ( $ model -> getAuthIdentifierName ( ) , $ id ) -> first ( ) ; if ( $ user === null ) { return null ; } $ apiToken = $ user -> getApiToken ( ) ; return ! empty (...
Retrieve a user by their unique identifier and api token .
14,078
public function from ( $ table , $ columns = null ) { $ this -> _criteria -> setModelName ( $ table ) ; if ( $ columns !== null ) { $ this -> _criteria -> columns ( $ columns ) ; } return $ this ; }
From which table or collection
14,079
public function where ( $ condition , $ value = null , $ type = null ) { $ this -> _criteria -> andWhere ( $ condition ) ; return $ this ; }
Add the where condition
14,080
public function orWhere ( $ condition , $ value = null , $ type = null ) { $ this -> _criteria -> orWhere ( $ condition ) ; return $ this ; }
Add the or where condition
14,081
public function limit ( $ limit , $ offset = null ) { $ this -> _criteria -> limit ( $ limit , $ offset ) ; $ this -> _limit = ( int ) $ limit ; return $ this ; }
Set the limit of a rows or documents
14,082
public function append ( $ node ) { $ current = $ this -> getCurrentNode ( ) ; $ current ? $ current -> appendChild ( $ node ) : $ this -> setCurrentNode ( $ node ) ; return $ this ; }
Append to current node or set as current if node selected .
14,083
private function getNamedHandler ( $ handler ) { if ( ! isset ( $ this -> namedHandlers [ $ handler ] ) ) { $ this -> namedHandlers [ $ handler ] = new $ handler ( ) ; } return $ this -> namedHandlers [ $ handler ] ; }
Instanciate a new handler by name or return the previous instancied one with the same name .
14,084
public function handleToken ( TokenInterface $ token = null ) { $ token = $ token ? : $ this -> getToken ( ) ; $ className = get_class ( $ token ) ; $ tokenHandlers = $ this -> getOption ( 'token_handlers' ) ; if ( ! isset ( $ tokenHandlers [ $ className ] ) ) { $ this -> throwException ( "Unexpected token `$className`...
Handles any kind of token returned by the lexer .
14,085
public function lookUp ( array $ types ) { while ( $ this -> hasTokens ( ) ) { $ token = $ this -> getToken ( ) ; if ( ! in_array ( get_class ( $ token ) , $ types , true ) ) { break ; } yield $ token ; $ this -> nextToken ( ) ; } }
Yields tokens as long as the given types match .
14,086
public function throwException ( $ message , $ code = 0 , TokenInterface $ relatedToken = null , $ previous = null ) { $ pattern = "Failed to parse: %s \nNear: %s \nLine: %s \nOffset: %s" ; $ lexer = $ this -> parser -> getLexer ( ) ; $ location = $ relatedToken && $ relatedToken -> getSourceLocation ( ) ? clone $ rela...
Throws a parser - exception .
14,087
public function setProject ( $ project ) { if ( $ project instanceof Project ) { $ this -> project = $ project -> getSlug ( ) ; return $ this ; } $ this -> project = ( string ) $ project ; return $ this ; }
Set the project .
14,088
public function setFromResult ( $ data ) { $ this -> setCategories ( $ data [ 'categories' ] ) ; $ this -> setI18nType ( $ data [ 'i18n_type' ] ) ; $ this -> setSourceLanguageCode ( $ data [ 'source_language_code' ] ) ; $ this -> setName ( $ data [ 'name' ] ) ; $ this -> setSlug ( $ data [ 'slug' ] ) ; if ( isset ( $ d...
Set all values from the passed result .
14,089
public function create ( ) { $ params = array ( 'slug' => $ this -> ensureParameter ( 'slug' ) , 'name' => $ this -> ensureParameter ( 'name' ) , 'i18n_type' => $ this -> ensureParameter ( 'i18nType' ) , 'content' => $ this -> ensureParameter ( 'content' ) , ) ; $ this -> post ( sprintf ( 'project/%s/resources/' , $ th...
Create the resource on transifex .
14,090
public function updateContent ( ) { $ params = array ( 'content' => $ this -> ensureParameter ( 'content' ) , ) ; $ this -> put ( sprintf ( 'project/%s/resource/%s/content/' , $ this -> ensureParameter ( 'project' ) , $ this -> ensureParameter ( 'slug' ) ) , $ params ) ; return $ this ; }
Update the content on transifex .
14,091
public function fetchDetails ( ) { $ response = $ this -> executeJson ( sprintf ( 'project/%s/resource/%s' , $ this -> ensureParameter ( 'project' ) , $ this -> ensureParameter ( 'slug' ) ) , array ( 'details' => '' ) ) ; $ this -> setFromResult ( $ response ) ; return $ this ; }
Retrieve the details of the resource .
14,092
public function fetchContent ( ) { $ response = $ this -> executeJson ( sprintf ( 'project/%s/resource/%s/content/' , $ this -> ensureParameter ( 'project' ) , $ this -> ensureParameter ( 'slug' ) ) ) ; $ this -> setContent ( $ response [ 'content' ] ) ; $ this -> setMimetype ( $ response [ 'mimetype' ] ) ; return $ th...
Fetch the file content .
14,093
public function fetchTranslation ( $ langcode , $ mode = 'reviewed' ) { $ parameters = array ( 'file' => '' , 'mode' => $ mode ) ; return $ this -> execute ( sprintf ( 'project/%s/resource/%s/translation/%s' , $ this -> ensureParameter ( 'project' ) , $ this -> ensureParameter ( 'slug' ) , $ langcode ) , $ parameters )...
Fetch a certain translation of the resource .
14,094
public function index ( GluggiFinder $ finder , GluggiConfig $ config ) { return $ this -> render ( "@Gluggi/Gluggi/index.html.twig" , [ "types" => $ finder -> getAllTypes ( ) , "pageTitle" => "Index" , "infoAction" => $ config -> getInfoAction ( ) , "customTitle" => $ config -> getTitle ( ) , ] ) ; }
Renders the index page
14,095
public function component ( GluggiFinder $ finder , ComponentConfiguration $ componentConfiguration , string $ type , string $ key ) { try { $ component = $ finder -> findComponent ( $ type , $ key ) ; if ( null === $ component || $ component -> isHidden ( ) ) { $ message = null === $ component ? "No component found: '...
Renders a component in single view
14,096
public function htmlTitle ( GluggiConfig $ config , $ pageTitle ) { $ segments = ! is_array ( $ pageTitle ) ? [ $ pageTitle ] : $ pageTitle ; $ mainTitle = "Gluggi" ; if ( null !== $ config -> getTitle ( ) ) { $ mainTitle .= " ({$config->getTitle()})" ; } $ segments [ ] = $ mainTitle ; return new Response ( htmlspecial...
Renders the HTML title
14,097
public function layoutAssets ( GluggiConfig $ config , AssetHtmlGenerator $ htmlGenerator , string $ type , array $ addAssets = [ ] , array $ overrideAssets = [ ] ) : Response { $ overrideAssets = $ overrideAssets [ $ type ] ?? [ ] ; if ( ! empty ( $ overrideAssets ) ) { $ assetPaths = $ overrideAssets ; } else { switc...
Renders the layout assets
14,098
public static function to_snake ( $ string ) { if ( \ ctype_lower ( $ string ) ) { return $ string ; } $ string = \ preg_replace ( '/\s+/u' , '' , \ ucwords ( $ string ) ) ; $ string = \ trim ( \ preg_replace ( '/([^_])(?=[A-Z])/' , '$1_' , $ string ) , '_' ) ; return \ strtolower ( $ string ) ; }
Transform a string into valid snake case .
14,099
public function outputController ( ) : self { if ( ! $ this -> controller ) { return $ this ; } if ( ! isset ( self :: $ controllers [ $ this -> controller ] ) ) { if ( ! class_exists ( $ this -> controller ) ) { $ this -> controller = str_replace ( '_' , '' , $ this -> controller ) ; } $ controller = new $ this -> con...
Get data from controller