idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
18,400
public function load ( $ class ) { if ( $ class [ 0 ] == '\\' ) $ class = substr ( $ class , 1 ) ; $ class = str_replace ( array ( '\\' , '_' ) , DIRECTORY_SEPARATOR , $ class ) . '.php' ; foreach ( $ this -> directories as $ directory ) { if ( file_exists ( $ path = $ directory . DIRECTORY_SEPARATOR . $ class ) ) { require_once $ path ; return true ; } } return false ; }
Search and load a specific class . Used for auto - loader .
18,401
private function execute ( $ regex , $ data ) { $ matches = [ ] ; preg_match ( $ regex , ( string ) $ data , $ matches ) ; return $ matches ; }
Ejecuta la comprobacion por medio de regex y devuelve lo se pudo capturar .
18,402
public function writeUInt8 ( int $ value ) : self { $ this -> bytes .= Writer :: bit8 ( $ value ) ; return $ this ; }
Write an unsigned 8 bit integer .
18,403
public function writeUInt16 ( int $ value ) : self { $ this -> bytes .= Writer :: bit16 ( $ value ) ; return $ this ; }
Write an unsigned 16 bit integer .
18,404
public function writeUInt32 ( int $ value ) : self { $ this -> bytes .= Writer :: bit32 ( $ value ) ; return $ this ; }
Write an unsigned 32 bit integer .
18,405
public function actionIndex ( $ page = 1 ) { $ this -> trigger ( self :: EVENT_BEFORE_RECENT_SHOW ) ; $ data [ 'page' ] = ( int ) $ page ; $ data [ 'route' ] = '/' . $ this -> getRoute ( ) ; $ finder = new VideoFinder ( ) ; $ data [ 'videos' ] = $ finder -> getNewVideos ( $ page ) ; $ data [ 'total_items' ] = $ finder -> totalCount ( ) ; $ pagination = new Pagination ( [ 'totalCount' => $ data [ 'total_items' ] , 'defaultPageSize' => Module :: getInstance ( ) -> settings -> get ( 'items_per_page' , 20 ) , 'pageSize' => Module :: getInstance ( ) -> settings -> get ( 'items_per_page' , 20 ) , 'route' => $ data [ 'route' ] , 'forcePageParam' => false , ] ) ; $ settings = Yii :: $ app -> settings -> getAll ( ) ; $ settings [ 'videos' ] = Module :: getInstance ( ) -> settings -> getAll ( ) ; $ this -> trigger ( self :: EVENT_AFTER_RECENT_SHOW ) ; return $ this -> render ( 'recent' , [ 'data' => $ data , 'settings' => $ settings , 'pagination' => $ pagination , ] ) ; }
Lists all Videos models .
18,406
protected function bindParameters ( \ PDOStatement $ statement , array $ parameters , $ prefix = '' ) { foreach ( $ parameters as $ key => $ value ) { if ( is_array ( $ value ) ) { $ statement = $ this -> bindParameters ( $ statement , $ value , $ prefix . $ key ) ; } else { switch ( true ) { case is_int ( $ value ) : $ type = \ PDO :: PARAM_INT ; break ; case is_bool ( $ value ) : $ type = \ PDO :: PARAM_BOOL ; break ; case $ value === null : $ type = \ PDO :: PARAM_NULL ; break ; case $ value instanceof \ DateTimeInterface : $ type = \ PDO :: PARAM_STR ; $ value = $ value -> format ( 'Y-m-d H:i:s.u' ) ; break ; default : $ type = \ PDO :: PARAM_STR ; } $ statement -> bindValue ( $ prefix . $ key , $ value , $ type ) ; } } return $ statement ; }
Bind the parameters to the statement
18,407
protected function readOne ( $ query , $ parameters ) { $ statement = $ this -> execute ( $ query , $ parameters ) ; $ rowCount = $ statement -> rowCount ( ) ; if ( $ rowCount > 1 ) { throw new MultipleRowFoundException ( 'Multiple row found for query: ' . $ query ) ; } if ( $ rowCount === 0 ) { throw new RowNotFoundException ( 'Row not found for query: ' . $ query ) ; } return $ statement ; }
Return the statement checked that the result contains only 1 row
18,408
private function processWithKey ( array $ rows , $ keyField ) { if ( empty ( $ rows ) ) { return [ ] ; } $ first = reset ( $ rows ) ; if ( ! isset ( $ first -> $ keyField ) ) { throw new FieldNotFoundException ( $ keyField . ' field not found in result of the query' ) ; } $ result = [ ] ; foreach ( $ rows as $ row ) { $ result [ $ row -> $ keyField ] = $ row ; } return $ result ; }
Process the queried rows into an array which has the keyField keys
18,409
public static function run ( $ value , string $ type = null ) { switch ( $ type ) { case 'int' : $ regexp = self :: compileRegexp ( self :: INT ) ; break ; case 'float' : $ regexp = self :: compileRegexp ( self :: FLOAT ) ; break ; case 'text' : $ value = self :: fixQuotes ( $ value ) ; $ regexp = self :: compileRegexp ( self :: CHARS_RUS . self :: CHARS_ENG ) ; break ; default : $ value = self :: fixQuotes ( $ value ) ; $ regexp = self :: compileRegexp ( self :: CHARS_RUS . self :: CHARS_ENG . self :: FLOAT . '—~`@%[]/:<>;?&()_!$^-+=' . s lf:: SU PER ) ; break ; } return preg_replace ( $ regexp , '' , $ value ) ; }
Cleanup the value
18,410
public function execute ( Pygmentize $ pygmentize , array $ options ) { $ cmd = sprintf ( '-f %s -l %s -O encoding=%s %s %s' , $ pygmentize -> getFormat ( ) , $ pygmentize -> getLexer ( ) , mb_detect_encoding ( file_get_contents ( $ pygmentize -> getSubject ( ) ) ) , $ this -> generateOptions ( $ options ) , $ pygmentize -> getSubject ( ) ) ; return $ this -> executeCommand ( $ cmd ) ; }
execute a call to pygmentize binary
18,411
public function executeCommand ( $ command ) { $ cmd = sprintf ( '%s %s' , $ this -> binaryPath , $ command ) ; $ p = new Process ( $ cmd ) ; $ p -> run ( ) ; if ( $ p -> isSuccessful ( ) ) { return $ p -> getOutput ( ) ; } else { throw new \ RuntimeException ( sprintf ( 'pygmentize failed with the error: %s' , $ p -> getErrorOutput ( ) ) ) ; } }
executes a command
18,412
public function guessLexer ( $ filename ) { $ cmd = sprintf ( '%s -N %s' , $ this -> binaryPath , $ filename ) ; $ p = new Process ( $ cmd ) ; $ p -> run ( ) ; $ output = trim ( $ p -> getOutput ( ) ) ; if ( 'text' === $ output ) { $ output = $ this -> guessFromExtension ( $ filename ) ; } if ( 'text' === $ output ) { $ output = $ this -> guessFromContent ( $ filename ) ; } return $ output ; }
guess the lexer from the filename
18,413
private function guessFromContent ( $ filename ) { $ output = 'text' ; if ( ! is_file ( $ filename ) ) { return $ output ; } if ( $ fileContents = file_get_contents ( $ filename ) ) { if ( 1 === preg_match ( '/<?xml.*?>/' , $ fileContents ) ) { $ output = 'xml' ; } } return $ output ; }
try to guess lexer from the file content by searching some text
18,414
public function generateCollections ( ) { $ collections = $ this -> collections ; $ this -> collections = [ ] ; foreach ( $ collections as $ category => $ detail ) { foreach ( $ detail [ 'class' ] as $ class ) { if ( ! in_array ( ILinkCollection :: class , class_implements ( $ class ) ) ) { throw new \ LogicException ( "Collection must implement 'Grapesc\GrapeFluid\LinkCollector\ILinkCollection' interface" ) ; } if ( ! isset ( $ detail [ 'name' ] ) ) { $ detail [ 'name' ] = $ category ; } $ detail [ 'icon' ] = isset ( $ detail [ 'icon' ] ) ? $ detail [ 'icon' ] : "" ; $ collection = new $ class ; $ this -> container -> callInjects ( $ collection ) ; $ this -> addCollection ( $ category , $ detail [ 'name' ] , $ detail [ 'icon' ] , $ collection -> getLinks ( ) ) ; } } }
Vygeneruje seznam kolekci dle vsech nakonfigurovanich Collection Collection musi implementovat \ Grapesc \ GrapeFluid \ LinkCollector \ ILinkCollection
18,415
public function exceptionHandler ( $ exception ) { try { $ debug = Factory :: load ( 'Debug' ) ; $ debug -> errorhandler ( $ exception ) ; } catch ( \ Exception $ e ) { echo "<pre>$exception</pre>\n\n" ; echo "<pre>The Debug class threw an exception:\n$e</pre>" ; } }
Will be set by the Constructor as global exception handler .
18,416
public static function getConstList ( ) : array { if ( static :: $ constList === null ) { $ reflection = new ReflectionClass ( get_called_class ( ) ) ; static :: $ constList = array_values ( $ reflection -> getConstants ( ) ) ; } return static :: $ constList ; }
Gets all possible values as an array .
18,417
public static function setForcedScheme ( $ scheme = null ) { if ( ! is_string ( $ scheme ) && ! is_null ( $ scheme ) ) { throw new InvalidArgumentException ( sprintf ( 'Invalid scheme provided; must be an string or a null, "%s" received.' , is_object ( $ scheme ) ? get_class ( $ scheme ) : gettype ( $ scheme ) ) ) ; } static :: $ forcedScheme = $ scheme ; }
Sets the Uri scheme for forced usage .
18,418
public static function retrieve ( array $ server = null ) { if ( empty ( $ server ) ) { $ server = $ _SERVER ; } $ scheme = 'http' ; if ( isset ( $ server [ 'HTTPS' ] ) && 'off' != $ server [ 'HTTPS' ] ) { $ scheme = 'https' ; } return $ scheme ; }
Retrieves the Uri scheme using incoming data ignores a forced scheme . If unable to retrieve the scheme returns http .
18,419
public function execute ( Framework $ framework , WebRequest $ request , Response $ response ) { $ title = $ this -> translate ( 'Activate account' , '\\Zepi\\Web\\AccessControl' ) ; $ this -> setTitle ( $ title ) ; $ uuid = $ request -> getRouteParam ( 'uuid' ) ; $ activationToken = $ request -> getRouteParam ( 'token' ) ; $ result = array ( 'result' => false , 'message' => $ this -> translate ( 'Wrong request parameters.' , '\\Zepi\\Web\\AccessControl' ) ) ; if ( $ uuid != false && $ activationToken != false ) { $ result = $ this -> activateUser ( $ uuid , $ activationToken ) ; } $ response -> setOutput ( $ this -> render ( '\\Zepi\\Web\\AccessControl\\Templates\\Activation' , array ( 'result' => $ result ) ) ) ; }
Deletes a cluster in the database
18,420
protected function activateUser ( $ uuid , $ activationToken ) { if ( ! $ this -> userManager -> hasUserForUuid ( $ uuid ) ) { return array ( 'result' => false , 'message' => $ this -> translate ( 'Account with the given UUID does not exist.' , '\\Zepi\\Web\\AccessControl' ) ) ; } $ user = $ this -> userManager -> getUserForUuid ( $ uuid ) ; if ( $ user -> getMetaData ( 'activationToken' ) !== $ activationToken ) { return array ( 'result' => false , 'message' => $ this -> translate ( 'The given activation token is not valid.' , '\\Zepi\\Web\\AccessControl' ) ) ; } $ this -> accessControlManager -> revokePermission ( $ uuid , get_class ( $ user ) , '\\Global\\Disabled' ) ; $ this -> accessControlManager -> grantPermission ( $ uuid , get_class ( $ user ) , '\\Global\\Active' , 'Activation' ) ; return array ( 'result' => true , 'message' => $ this -> translate ( 'Your account was activated successfully.' , '\\Zepi\\Web\\AccessControl' ) ) ; }
Activates the user or returns an error message
18,421
public static function setApplicationConnection ( Application $ application = null , $ connName ) { if ( is_null ( $ application ) ) { throw new \ InvalidArgumentException ( 'Application instance needed!' ) ; } $ helperSet = $ application -> getHelperSet ( ) ; $ doctrine = $ helperSet -> get ( 'doctrine' ) ; $ connection = $ doctrine -> getConnection ( $ connName ) ; $ helperSet -> set ( new ConnectionHelper ( $ connection ) , 'db' ) ; }
Convenience method to push the helper sets of a given connection into the application .
18,422
protected function fetchURL ( $ URL ) { $ cookieHeader = [ ] ; if ( $ this -> cookie ) { $ cookieHeader [ ] = 'Cookie: ' . $ this -> cookie . ';' ; } $ curl = curl_init ( ) ; curl_setopt ( $ curl , CURLOPT_URL , $ URL ) ; curl_setopt ( $ curl , CURLOPT_HEADER , 1 ) ; curl_setopt ( $ curl , CURLOPT_RETURNTRANSFER , 1 ) ; curl_setopt ( $ curl , CURLOPT_HTTPHEADER , $ cookieHeader ) ; $ body = null ; $ result = curl_exec ( $ curl ) ; if ( $ result ) { $ parts = explode ( "\r\n\r\n" , $ result , 2 ) ; $ headers = explode ( "\r\n" , $ parts [ 0 ] ) ; if ( ! $ this -> cookie ) { $ setCookieString = 'Set-Cookie: ' ; foreach ( $ headers as $ header ) { if ( strpos ( $ header , $ setCookieString ) === 0 ) { $ cookieString = substr ( $ header , strlen ( $ setCookieString ) ) ; $ cookieStringParts = explode ( ';' , $ cookieString ) ; $ this -> cookie = $ cookieStringParts [ 0 ] ; break ; } } } $ body = $ parts [ 1 ] ; } return $ body ; }
Returns the content loaded from the given URL . Uses curl to fetch the cookie from the response and insert it into requests if available .
18,423
public static function escapeShellArg ( $ arg , $ escapeFor = NULL ) { $ escaped = \ Symfony \ Component \ Process \ ProcessUtils :: escapeArgument ( $ arg ) ; return Preg :: replace ( $ escaped , '~(?<!\\\\)\\\\"$~' , '\\\\\\"' ) ; }
This escapes shell arguments on windows correctly
18,424
public function after ( $ response ) { if ( ! $ response instanceof Response ) { $ response = \ Response :: forge ( $ response , $ this -> response_status ) ; } return $ response ; }
This method gets called after the action is called
18,425
public function askYesNo ( string $ prompt ) { $ prompt .= ' (y/n): ' ; $ result = null ; $ result = $ this -> askUntillValid ( $ prompt , function ( $ answer ) { $ answer = strtolower ( $ answer ) ; return $ answer === 'y' || $ answer === 'n' ; } ) ; return $ result === 'y' ; }
Prompt user to supply either a yes or no answer
18,426
public function askUntillValid ( string $ prompt , callable $ validationCallback ) { $ result = null ; while ( $ validationCallback ( $ result ) !== true ) { $ result = $ this -> readLine ( "$prompt" ) ; } return $ result ; }
Prompt user for input untill the given input returns true from the validation callback function .
18,427
private function readline ( string $ prompt ) { if ( PHP_OS == 'WINNT' ) { echo $ prompt ; $ line = stream_get_line ( STDIN , 1024 , PHP_EOL ) ; } else { $ line = readline ( $ prompt ) ; } return $ line ; }
Get user input from commandline
18,428
public function getSystemId ( ) { if ( ! is_null ( $ this -> _systemId ) ) { return $ this -> _systemId ; } preg_match ( '/' . ucfirst ( $ this -> moduleType ) . '([A-Za-z]+)\\\Module/' , get_class ( $ this ) , $ matches ) ; if ( ! isset ( $ matches [ 1 ] ) ) { throw new Exception ( get_class ( $ this ) . " is not set up correctly!" ) ; } return $ this -> _systemId = $ matches [ 1 ] ; }
Get system .
18,429
function mergeWith ( $ data = [ ] ) { if ( is_array ( $ data ) || is_object ( $ data ) ) foreach ( $ data as $ key => $ value ) { $ this -> __data -> { $ key } = $ value ; } return $ this ; }
Adds data to storage
18,430
static protected function parseRule ( $ rule ) { switch ( gettype ( $ rule ) ) { case 'string' : $ type = $ rule ; $ target = null ; $ types = [ ] ; break ; case 'array' : $ type = isset ( $ rule [ 'type' ] ) ? $ rule [ 'type' ] : [ ] ; $ target = isset ( $ rule [ 'target' ] ) ? $ rule [ 'target' ] : [ ] ; $ types = isset ( $ rule [ 'types' ] ) ? $ rule [ 'types' ] : [ ] ; break ; case 'object' : $ type = isset ( $ rule -> type ) ? $ rule -> type : null ; $ target = isset ( $ rule -> target ) ? $ rule -> target : null ; $ types = isset ( $ rule -> types ) ? $ rule -> types : [ ] ; break ; default : $ type = null ; $ target = null ; $ types = [ ] ; } return compact ( 'type' , 'target' , 'types' ) ; }
Standartise type target and types
18,431
protected function parseType ( array $ input ) { extract ( $ input ) ; switch ( $ type ) { case 'array' : if ( ! is_array ( $ this -> { $ key } ) ) return false ; break ; case 'int' : case 'integer' : if ( ! is_int ( $ this -> { $ key } ) ) return false ; break ; case 'or' : $ valid = false ; foreach ( $ types as $ _type ) { if ( gettype ( $ this -> { $ key } ) == $ _type ) { $ valid = true ; break ; } } if ( ! $ valid ) return false ; break ; default : return null ; } return true ; }
Checks if field match type
18,432
public static function cacheAllConfigsFile ( $ application = null ) { if ( empty ( $ application ) ) { $ application = Yii :: $ app ; } $ appKey = UniApplication :: appKey ( $ application ) ; $ cacheKey = static :: $ confFileCacheKey . '/' . $ appKey ; if ( $ application -> cache instanceof Cache && ! empty ( static :: $ _configFiles ) ) { $ application -> cache -> set ( $ cacheKey , static :: $ _configFiles , static :: $ defaultCacheDuration ) ; } }
Save all configs together in cache
18,433
protected function addError ( $ message , $ code = null ) { $ this -> adapter -> add ( $ message , $ code , 'error' ) ; return $ this ; }
add error into container
18,434
protected function addWarning ( $ message , $ code = null ) { $ this -> adapter -> add ( $ message , $ code , 'success' ) ; return $ this ; }
add warning into container
18,435
protected function addInfo ( $ message , $ code = null ) { $ this -> adapter -> add ( $ message , $ code , 'info' ) ; return $ this ; }
add info into container
18,436
protected function addSuccess ( $ message , $ code = null ) { $ this -> adapter -> add ( $ message , $ code , 'success' ) ; return $ this ; }
add success into container
18,437
protected function getDaemonOptions ( ) { return [ [ 'daemon' , null , InputOption :: VALUE_NONE , 'Run the command in daemon mode' ] , [ 'sleep' , null , InputOption :: VALUE_OPTIONAL , 'Number of seconds to sleep when no job is available' , 3 ] , [ 'memory' , null , InputOption :: VALUE_OPTIONAL , 'The memory limit in megabytes' , 128 ] , ] ; }
Get the console daemon options .
18,438
public function loadScanned ( ) { if ( $ this -> app -> environment ( 'local' ) && $ this -> app [ 'config' ] -> get ( 'assets.generate_when_local' , false ) ) { $ this -> scanDirectories ( ) ; } $ scans = $ this -> getDirectories ( ) ; if ( ! empty ( $ scans ) && $ this -> getScanner ( ) -> isScanned ( ) ) { $ this -> getScanner ( ) -> loadScanned ( ) ; } }
Load the scanned assets .
18,439
private function AddValueField ( ) { $ name = 'Value' ; $ field = new Fields \ Textarea ( $ name , $ this -> textarea -> GetValue ( ) ) ; $ this -> AddField ( $ field ) ; }
Adds the value field
18,440
protected function SaveElement ( ) { $ this -> textarea -> SetLabel ( $ this -> Value ( 'Label' ) ) ; $ this -> textarea -> SetName ( $ this -> Value ( 'Name' ) ) ; $ this -> textarea -> SetValue ( $ this -> Value ( 'Value' ) ) ; $ this -> textarea -> SetPattern ( $ this -> Value ( 'Pattern' ) ) ; $ this -> textarea -> SetMinLength ( ( int ) $ this -> Value ( 'MinLength' ) ) ; $ this -> textarea -> SetMaxLength ( ( int ) $ this -> Value ( 'MaxLength' ) ) ; $ this -> textarea -> SetRequired ( ( bool ) $ this -> Value ( 'Required' ) ) ; $ this -> textarea -> SetDisableFrontendValidation ( ( bool ) $ this -> Value ( 'DisableFrontendValidation' ) ) ; return $ this -> textarea ; }
Attaches the basic properties to the textarea element
18,441
protected function next ( ) { $ promiseOrValue = array_shift ( $ this -> queue ) ; $ promise = resolve ( $ promiseOrValue ) ; $ this -> cancellationQueue -> enqueue ( $ promise ) ; return $ promise ; }
Get next promise from queue
18,442
protected function createRejectFunction ( $ reject ) { $ this -> reject = function ( $ reason ) use ( & $ reject ) { $ cancelQueue = $ this -> cancellationQueue ; $ cancelQueue ( ) ; return isset ( $ reject ) ? $ reject ( $ reason ) : null ; } ; }
Create reject function with cancellation queue
18,443
public static function validateCache ( $ file , $ cacheTTL , $ cacheForever ) { $ currentTime = time ( ) ; $ expireTime = $ cacheTTL * 60 * 60 ; $ fileTime = filemtime ( $ file ) ; return ( $ currentTime - $ expireTime < $ fileTime ) or $ cacheForever ; }
Check if a given cache entry is still valid . Will always return true if permanent caching has been set on .
18,444
public function findOrCreateBranch ( RepositoryInterface $ repository , $ branchName ) { try { return $ this -> findOneBy ( [ 'name' => $ branchName , 'repository' => $ repository ] , false ) ; } catch ( NoResultException $ e ) { $ branch = new Branch ( ) ; $ branch -> setName ( $ branchName ) -> setRepository ( $ repository ) ; $ this -> persist ( $ branch ) ; return $ branch ; } }
Tries to find a branch by repository and branch name and throws exception if is not able to do so .
18,445
public function findDataByTypesAndNames ( array $ namesByTypes , array $ modCombinationIds = [ ] ) : array { $ columns = [ 'i.id AS id' , 'IDENTITY(i.file) AS hash' , 'i.type AS type' , 'i.name AS name' , 'mc.order AS order' ] ; $ queryBuilder = $ this -> entityManager -> createQueryBuilder ( ) ; $ queryBuilder -> select ( $ columns ) -> from ( Icon :: class , 'i' ) -> innerJoin ( 'i.modCombination' , 'mc' ) ; $ index = 0 ; $ conditions = [ ] ; foreach ( $ namesByTypes as $ type => $ names ) { $ conditions [ ] = '(i.type = :type' . $ index . ' AND i.name IN (:names' . $ index . '))' ; $ queryBuilder -> setParameter ( 'type' . $ index , $ type ) -> setParameter ( 'names' . $ index , array_values ( $ names ) ) ; ++ $ index ; } $ result = [ ] ; if ( $ index > 0 ) { $ queryBuilder -> andWhere ( '(' . implode ( ' OR ' , $ conditions ) . ')' ) ; if ( count ( $ modCombinationIds ) > 0 ) { $ queryBuilder -> andWhere ( 'mc.id IN (:modCombinationIds)' ) -> setParameter ( 'modCombinationIds' , array_values ( $ modCombinationIds ) ) ; } $ result = $ this -> mapIconDataResult ( $ queryBuilder -> getQuery ( ) -> getResult ( ) ) ; } return $ result ; }
Finds the data of the specified entities .
18,446
public function findDataByHashes ( array $ hashes , array $ modCombinationIds = [ ] ) : array { $ result = [ ] ; if ( count ( $ hashes ) > 0 ) { $ columns = [ 'i.id AS id' , 'IDENTITY(i.file) AS hash' , 'i.type AS type' , 'i.name AS name' , 'mc.order AS order' ] ; $ queryBuilder = $ this -> entityManager -> createQueryBuilder ( ) ; $ queryBuilder -> select ( $ columns ) -> from ( Icon :: class , 'i' ) -> innerJoin ( 'i.modCombination' , 'mc' ) -> andWhere ( 'i.file IN (:hashes)' ) -> setParameter ( 'hashes' , array_map ( 'hex2bin' , array_values ( $ hashes ) ) ) ; if ( count ( $ modCombinationIds ) > 0 ) { $ queryBuilder -> andWhere ( 'mc.id IN (:modCombinationIds)' ) -> setParameter ( 'modCombinationIds' , array_values ( $ modCombinationIds ) ) ; } $ result = $ this -> mapIconDataResult ( $ queryBuilder -> getQuery ( ) -> getResult ( ) ) ; } return $ result ; }
Finds the data of the icons with the specified hashes .
18,447
protected function mapIconDataResult ( array $ iconData ) : array { $ result = [ ] ; foreach ( $ iconData as $ data ) { $ result [ ] = IconData :: createFromArray ( $ data ) ; } return $ result ; }
Maps the query result to instances of IconData .
18,448
public function filter ( callable $ predicate ) : self { if ( $ this -> isPresent ( ) && $ predicate ( $ this -> value ) ) { return $ this ; } return self :: $ null ; }
returns result when value is present and fulfills the predicate
18,449
public function map ( callable $ mapper ) : self { if ( $ this -> isPresent ( ) ) { return new self ( $ mapper ( $ this -> value ) ) ; } return self :: $ null ; }
maps the value using mapper into a different result
18,450
public function whenEmpty ( $ other ) : self { if ( ! $ this -> isEmpty ( $ this -> value ) ) { return $ this ; } return self :: of ( $ other ) ; }
returns the result if value is not empty or result of other
18,451
public function applyWhenEmpty ( callable $ other ) : self { if ( ! $ this -> isEmpty ( $ this -> value ) ) { return $ this ; } return self :: of ( $ other ( ) ) ; }
returns the result if value is not empty or the result of applied other
18,452
public function getEntity ( $ plugin ) { $ plugin = Inflector :: camelize ( $ plugin ) ; $ slug = Str :: low ( $ plugin ) ; $ entity = $ this -> _controller -> Extensions -> findBySlug ( $ slug ) -> first ( ) ; if ( $ entity === null ) { $ entity = $ this -> _controller -> Extensions -> newEntity ( [ 'params' => [ ] , 'slug' => $ slug , 'name' => $ plugin ] ) ; $ config = Plugin :: getData ( $ plugin , 'meta' ) ; $ entity -> set ( 'core' , $ config -> get ( 'core' , false ) ) -> set ( 'name' , $ config -> get ( 'name' , $ plugin ) ) ; } return $ entity ; }
Get current plugin entity .
18,453
protected function afterRender ( ) { $ this -> logger -> debug ( 'application.afterRender.start' ) ; $ manager = $ this -> getEventManager ( ) ; $ manager -> notify ( \ FreeFW \ Constants :: EVENT_AFTER_RENDER ) ; $ this -> logger -> debug ( 'application.afterRender.end' ) ; return $ this ; }
Event de fin
18,454
public function listAction ( ) { $ lockManager = $ this -> get ( 'phlexible_element.element_lock_manager' ) ; $ userManager = $ this -> get ( 'phlexible_user.user_manager' ) ; $ locks = $ lockManager -> findAll ( ) ; $ data = [ ] ; foreach ( $ locks as $ lock ) { $ username = '(unknown user)' ; $ user = $ userManager -> find ( $ lock -> getUserId ( ) ) ; if ( $ user ) { $ username = $ user -> getDisplayName ( ) ; } $ data [ ] = [ 'id' => $ lock -> getId ( ) , 'uid' => $ lock -> getUserId ( ) , 'user' => $ username , 'ts' => $ lock -> getLockedAt ( ) -> format ( 'Y-m-d H:i:s' ) , 'eid' => $ lock -> getElement ( ) -> getEid ( ) , 'lock_type' => $ lock -> getType ( ) , ] ; } return new JsonResponse ( [ 'locks' => $ data ] ) ; }
List locks .
18,455
public function deleteAction ( $ id ) { $ lockManager = $ this -> get ( 'phlexible_element.element_lock_manager' ) ; $ lock = $ lockManager -> find ( $ id ) ; $ lockManager -> deleteLock ( $ lock ) ; return new ResultResponse ( true , 'Lock released.' ) ; }
Delete lock .
18,456
public function deletemyAction ( ) { $ uid = $ this -> getUser ( ) -> getId ( ) ; $ lockManager = $ this -> get ( 'phlexible_element.element_lock_manager' ) ; $ myLocks = $ lockManager -> findBy ( [ 'userId' => $ uid ] ) ; foreach ( $ myLocks as $ lock ) { $ lockManager -> deleteLock ( $ lock ) ; } return new ResultResponse ( true , 'My locks released.' ) ; }
Delete my locks .
18,457
public function lockAction ( Request $ request ) { $ eid = ( int ) $ request -> get ( 'eid' ) ; $ language = $ request -> get ( 'language' ) ; $ elementService = $ this -> get ( 'phlexible_element.element_service' ) ; $ lockManager = $ this -> get ( 'phlexible_element.element_lock_manager' ) ; $ element = $ elementService -> findElement ( $ eid ) ; if ( $ lockManager -> isLocked ( $ element ) ) { return new ResultResponse ( false , 'Element already locked.' ) ; } else { try { $ lockManager -> lock ( $ element , $ this -> getUser ( ) -> getId ( ) ) ; return new ResultResponse ( true , 'Lock aquired.' ) ; } catch ( \ Exception $ e ) { return new ResultResponse ( false , $ e -> getMessage ( ) ) ; } } }
Lock element .
18,458
public function index ( ) { if ( ! $ this -> request -> isPOST ( ) ) { if ( class_exists ( 'ErrorPage' ) ) { $ response = ErrorPage :: response_for ( 404 ) ; if ( ! empty ( $ response ) ) { return parent :: httpError ( 404 , $ response ) ; } } return parent :: httpError ( 404 ) ; } if ( self :: config ( ) -> check_user_agent == true && $ this -> request -> getHeader ( 'User-Agent' ) != 'Kapost XMLRPC::Client' ) { if ( class_exists ( 'ErrorPage' ) ) { $ response = ErrorPage :: response_for ( 404 ) ; if ( ! empty ( $ response ) ) { return parent :: httpError ( 404 , $ response ) ; } } return parent :: httpError ( 404 ) ; } $ methods = array_fill_keys ( $ this -> exposed_methods , array ( 'function' => array ( $ this , 'handleRPCMethod' ) ) ) ; ContentNegotiator :: config ( ) -> enabled = false ; $ this -> response -> addHeader ( 'Content-Type' , 'text/xml' ) ; $ server = new PhpXmlRpc \ Server ( $ methods , false ) ; $ server -> compress_response = true ; if ( Director :: isDev ( ) ) { $ server -> setDebug ( 3 ) ; } $ server -> exception_handling = 2 ; PhpXmlRpc \ PhpXmlRpc :: $ xmlrpc_internalencoding = self :: config ( ) -> database_charset ; try { return $ server -> service ( $ this -> request -> getBody ( ) , true ) ; } catch ( Exception $ e ) { SS_Log :: log ( $ e , SS_Log :: ERR ) ; $ results = $ this -> extend ( 'onException' , $ e ) ; if ( $ results && is_array ( $ results ) ) { $ results = array_filter ( $ results , function ( $ v ) { return ( ! is_null ( $ v ) && $ v instanceof PhpXmlRpc \ Response ) ; } ) ; if ( count ( $ results ) > 0 ) { $ this -> generateErrorResponse ( $ server , array_shift ( $ results ) ) ; } } if ( Director :: isDev ( ) ) { $ response = new PhpXmlRpc \ Response ( 0 , $ e -> getCode ( ) + 100 , _t ( 'KapostService.ERROR_MESSAGE' , '_{message} in {file} line {line_number}' , array ( 'message' => $ e -> getMessage ( ) , 'file' => $ e -> getFile ( ) , 'line_number' => $ e -> getLine ( ) ) ) ) ; } else { $ response = new PhpXmlRpc \ Response ( 0 , 17 , _t ( 'KapostService.SERVER_ERROR' , '_Internal server error' ) ) ; } return $ this -> generateErrorResponse ( $ server , $ response ) ; } }
Handles incoming requests to the kapost service
18,459
public function preview ( ) { $ auth = $ this -> request -> getVar ( 'auth' ) ; $ token = KapostPreviewToken :: get ( ) -> filter ( 'Code' , Convert :: raw2sql ( $ auth ) ) -> first ( ) ; if ( ! empty ( $ token ) && $ token !== false && $ token -> exists ( ) && time ( ) - strtotime ( $ token -> Created ) < self :: config ( ) -> preview_token_expiry * 60 && $ token -> KapostRefID == $ this -> urlParams [ 'ID' ] ) { $ kapostObj = KapostObject :: get ( ) -> filter ( 'KapostRefID' , Convert :: raw2sql ( $ this -> urlParams [ 'ID' ] ) ) -> sort ( '"Created" DESC' ) -> first ( ) ; if ( ! empty ( $ kapostObj ) && $ kapostObj !== false && $ kapostObj -> exists ( ) ) { $ previewController = $ kapostObj -> renderPreview ( ) ; $ this -> extend ( 'updatePreviewDisplay' , $ kapostObj , $ previewController ) ; return $ previewController ; } } if ( class_exists ( 'ErrorPage' ) ) { $ response = ErrorPage :: response_for ( 404 ) ; if ( ! empty ( $ response ) ) { return parent :: httpError ( 404 , $ response ) ; } } return parent :: httpError ( 404 ) ; }
Handles rendering of the preview for an object
18,460
protected function authenticate ( $ username , $ password ) { $ authenticator = $ this -> config ( ) -> authenticator_class ; $ member = $ authenticator :: authenticate ( array ( $ this -> config ( ) -> authenticator_username_field => $ username , 'Password' => $ password ) ) ; return ( ! empty ( $ member ) && $ member !== false && $ member -> exists ( ) == true && Permission :: check ( 'KAPOST_API_ACCESS' , 'any' , $ member ) ) ; }
Checks the authentication of the api request
18,461
protected function getUsersBlogs ( $ app_id ) { if ( SiteConfig :: has_extension ( 'SiteConfigSubsites' ) ) { $ response = array ( ) ; Subsite :: disable_subsite_filter ( ) ; $ subsites = Subsite :: get ( ) ; foreach ( $ subsites as $ subsite ) { $ response [ ] = array ( 'blogid' => $ subsite -> ID , 'blogname' => $ subsite -> Title ) ; } Subsite :: disable_subsite_filter ( false ) ; return $ response ; } $ siteConfig = SiteConfig :: current_site_config ( ) ; return array ( array ( 'blogid' => $ siteConfig -> ID , 'blogname' => $ siteConfig -> Title ) ) ; }
Gets the site config or subsites for the current site
18,462
protected function getCategories ( $ blog_id ) { $ categories = array ( ) ; if ( class_exists ( 'SiteTree' ) ) { $ pageClasses = ClassInfo :: subclassesFor ( 'SiteTree' ) ; foreach ( $ pageClasses as $ class ) { if ( $ class != 'SiteTree' ) { $ categories [ ] = array ( 'categoryId' => 'ss_' . strtolower ( $ class ) , 'categoryName' => singleton ( $ class ) -> i18n_singular_name ( ) , 'parentId' => 0 ) ; } } } $ results = $ this -> extend ( 'getCategories' , $ blog_id ) ; if ( $ results && is_array ( $ results ) ) { $ results = array_filter ( $ results , function ( $ v ) { return ! is_null ( $ v ) ; } ) ; if ( count ( $ results ) > 0 ) { for ( $ i = 0 ; $ i < count ( $ results ) ; $ i ++ ) { $ categories = array_merge ( $ categories , $ results [ $ i ] ) ; } } } return $ categories ; }
Gets the categories
18,463
protected function getPreview ( $ blog_id , $ content , $ content_id ) { $ results = $ this -> extend ( 'getPreview' , $ blog_id , $ content , $ content_id ) ; if ( $ results && is_array ( $ results ) ) { $ results = array_filter ( $ results , function ( $ v ) { return ! is_null ( $ v ) ; } ) ; if ( count ( $ results ) > 0 ) { return array_shift ( $ results ) ; } } $ existing = KapostObject :: get ( ) -> filter ( 'KapostRefID' , Convert :: raw2sql ( $ content_id ) ) -> first ( ) ; if ( ! empty ( $ existing ) && $ existing !== false && $ existing -> exists ( ) ) { $ resultID = $ content_id ; $ this -> editPost ( $ content_id , $ content , false , true ) ; } else { $ resultID = $ this -> newPost ( $ blog_id , $ content , false , true ) ; if ( is_object ( $ resultID ) ) { return $ resultID ; } $ existing = KapostObject :: get ( ) -> filter ( 'KapostRefID' , Convert :: raw2sql ( $ resultID ) ) -> first ( ) ; } if ( is_object ( $ resultID ) ) { return $ resultID ; } $ token = new KapostPreviewToken ( ) ; $ token -> Code = sha1 ( uniqid ( time ( ) . $ resultID ) ) ; $ token -> KapostRefID = $ resultID ; $ token -> write ( ) ; return array ( 'url' => Controller :: join_links ( Director :: absoluteBaseURL ( ) , 'kapost-service/preview' , $ resultID , '?auth=' . $ token -> Code ) , 'id' => $ resultID ) ; }
Handles rendering of the preview
18,464
final protected function struct_to_assoc ( $ struct ) { $ result = array ( ) ; foreach ( $ struct as $ item ) { if ( array_key_exists ( 'key' , $ item ) && array_key_exists ( 'value' , $ item ) ) { if ( array_key_exists ( $ item [ 'key' ] , $ result ) ) { user_error ( 'Duplicate key detected in struct entry, content overwritten by the last entry: [New: ' . print_r ( $ item , true ) . '] [Previous: ' . print_r ( $ result [ $ item [ 'key' ] ] , true ) . ']' , E_USER_WARNING ) ; } $ result [ $ item [ 'key' ] ] = $ item [ 'value' ] ; } else { user_error ( 'Key/Value pair not detected in struct entry: ' . print_r ( $ item , true ) , E_USER_NOTICE ) ; } } return $ result ; }
Converts a struct to an associtive array based on the key value pair in the struct
18,465
private function mergeResultArray ( $ leftArray , $ rightArray ) { foreach ( $ rightArray as $ key => $ value ) { if ( is_array ( $ value ) && array_key_exists ( $ key , $ leftArray ) ) { $ leftArray [ $ key ] = array_merge ( $ leftArray [ $ key ] , $ value ) ; } else { $ leftArray [ $ key ] = $ value ; } } return $ leftArray ; }
Merges two arrays overwriting the keys in the left array with the right array recurrsivly . Meaning that if a value in the right array is it self an array and the key exists in the left array it recurses into it .
18,466
public static function find_file_by_url ( $ url ) { $ url = Director :: makeRelative ( $ url ) ; if ( $ url ) { $ file = File :: get ( ) -> filter ( 'Filename' , Convert :: raw2sql ( $ url ) ) -> first ( ) ; if ( ! empty ( $ file ) && $ file !== false && $ file -> ID > 0 ) { return $ file ; } } return false ; }
Finds a file record based on the url of the file this is needed because Kapost doesn t seem to send anything back other than the url in the cms
18,467
protected function generateErrorResponse ( PhpXmlRpc \ Server $ server , PhpXmlRpc \ Response $ r ) { $ this -> response -> addHeader ( 'Content-Type' , $ r -> content_type ) ; $ this -> response -> addHeader ( 'Vary' , 'Accept-Charset' ) ; $ payload = '<?xml version="1.0"?>' ; if ( empty ( $ r -> payload ) ) { $ r -> serialize ( ) ; } $ payload = $ payload . $ r -> payload ; return $ payload ; }
Takes the xmlrpc object and generates the response to be set back
18,468
public static function instance ( $ instance = null ) { $ class = get_called_class ( ) ; if ( static :: exists ( $ instance ) ) { $ instance = static :: $ _instances [ $ class ] [ $ instance ] ; } else { $ instance = false ; } return $ instance ; }
Return an instance or false
18,469
public static function delete ( $ instance ) { $ class = get_called_class ( ) ; if ( $ instance === true ) { static :: $ _instances [ $ class ] = array ( ) ; return true ; } elseif ( static :: exists ( $ instance ) ) { unset ( static :: $ _instances [ $ class ] [ $ instance ] ) ; return true ; } return false ; }
Deletes an instance if exists
18,470
public function showAction ( ShopSetting $ shopSetting ) { $ editForm = $ this -> createForm ( new ShopSettingType ( ) , $ shopSetting , array ( 'action' => $ this -> generateUrl ( 'admin_amulen_shop_setting_update' , array ( 'id' => $ shopSetting -> getid ( ) ) ) , 'method' => 'PUT' , ) ) ; $ deleteForm = $ this -> createDeleteForm ( $ shopSetting -> getId ( ) , 'admin_amulen_shop_setting_delete' ) ; return array ( 'shop_setting' => $ shopSetting , 'edit_form' => $ editForm -> createView ( ) , 'delete_form' => $ deleteForm -> createView ( ) , ) ; }
Finds and displays a ShopSetting entity .
18,471
public function newAction ( ) { $ shopSetting = new ShopSetting ( ) ; $ form = $ this -> createForm ( new ShopSettingType ( ) , $ shopSetting ) ; return array ( 'shopSetting' => $ shopSetting , 'form' => $ form -> createView ( ) , ) ; }
Displays a form to create a new ShopSetting entity .
18,472
public function createAction ( Request $ request ) { $ shopSetting = new ShopSetting ( ) ; $ form = $ this -> createForm ( new ShopSettingType ( ) , $ shopSetting ) ; if ( $ form -> handleRequest ( $ request ) -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> persist ( $ shopSetting ) ; $ em -> flush ( ) ; return $ this -> redirect ( $ this -> generateUrl ( 'admin_amulen_shop_setting_show' , array ( 'id' => $ shopSetting -> getId ( ) ) ) ) ; } return array ( 'shopSetting' => $ shopSetting , 'form' => $ form -> createView ( ) , ) ; }
Creates a new ShopSetting entity .
18,473
public function updateAction ( ShopSetting $ shopSetting , Request $ request ) { $ editForm = $ this -> createForm ( new ShopSettingType ( ) , $ shopSetting , array ( 'action' => $ this -> generateUrl ( 'admin_amulen_shop_setting_update' , array ( 'id' => $ shopSetting -> getid ( ) ) ) , 'method' => 'PUT' , ) ) ; if ( $ editForm -> handleRequest ( $ request ) -> isValid ( ) ) { $ this -> getDoctrine ( ) -> getManager ( ) -> flush ( ) ; return $ this -> redirect ( $ this -> generateUrl ( 'admin_amulen_shop_setting_show' , array ( 'id' => $ shopSetting -> getId ( ) ) ) ) ; } $ deleteForm = $ this -> createDeleteForm ( $ shopSetting -> getId ( ) , 'admin_amulen_shop_setting_delete' ) ; return array ( 'shopSetting' => $ shopSetting , 'edit_form' => $ editForm -> createView ( ) , 'delete_form' => $ deleteForm -> createView ( ) , ) ; }
Edits an existing ShopSetting entity .
18,474
public function getTopLevelBlocks ( ) { $ ret = array ( ) ; foreach ( $ this -> blockManifest as $ block ) { if ( ! $ block -> getParent ( ) ) { $ ret [ ] = $ block ; } } return $ ret ; }
Gets all the blocks at the top level
18,475
public function addChild ( $ index ) { foreach ( $ this -> children as $ child ) { if ( $ child -> getID ( ) == $ index ) return ; } $ this -> children [ ] = $ this -> reflector -> getBlockByID ( $ index ) ; }
Adds a child block to this block
18,476
public function getChildByName ( $ name ) { foreach ( $ this -> getChildren ( ) as $ child ) { if ( $ child -> getName ( ) == $ name ) return $ child ; } return false ; }
Gets a child block by name
18,477
public function getRelativeOffset ( ) { if ( $ this -> getParent ( ) ) { return $ this -> id - $ this -> getParent ( ) -> getID ( ) ; } return $ this -> id ; }
Gets the offset relative to the parent block
18,478
public function setAdapterType ( $ type ) { $ adapter_type = '\Library\Reporter\Adapter\\' . ucfirst ( $ type ) ; if ( class_exists ( $ adapter_type ) ) { $ this -> setAdapter ( new $ adapter_type ) ; } else { throw new \ RuntimeException ( sprintf ( 'Reporter adapter for type "%s" doesn\'t exist!' , $ adapter_type ) ) ; } return $ this ; }
Set the adapter type to use
18,479
public function setAdapter ( AbstractAdapter $ adapter ) { $ cls = get_class ( $ adapter ) ; foreach ( self :: $ default_masks as $ _mask ) { if ( null === @ constant ( $ cls . '::mask_' . $ _mask ) ) { throw new \ LogicException ( sprintf ( 'Reporter adapter "%s" must define a mask named "%s"!' , $ cls , $ _mask ) ) ; } } $ this -> __adapter = $ adapter ; return $ this ; }
Set the adapter
18,480
public function setOutput ( $ output ) { if ( $ this -> getFlag ( ) & self :: OUTPUT_APPEND ) { $ this -> output .= $ output ; } elseif ( $ this -> getFlag ( ) & self :: OUTPUT_BY_LINE ) { $ this -> output = $ output ; } return $ this ; }
Set some content
18,481
public function write ( $ content , $ tag_type = 'default' , $ args = null ) { if ( is_null ( $ args ) ) $ args = array ( ) ; if ( ! is_array ( $ args ) ) $ args = array ( $ args ) ; $ output = $ this -> getAdapter ( ) -> renderTag ( $ content , $ tag_type , $ args ) ; echo PHP_EOL . $ output . PHP_EOL ; }
Display on screen a content with a specific tag mask
18,482
public function renderMulti ( $ content , $ tag_type = 'default' , array $ multi = array ( ) , $ args = null , $ placeholder_mask = '@%s@' ) { if ( is_null ( $ args ) ) $ args = array ( ) ; if ( ! is_array ( $ args ) ) $ args = array ( $ args ) ; $ placeholders_table = array ( ) ; foreach ( $ multi as $ item => $ item_args ) { $ placeholders_table [ $ item ] = call_user_func_array ( array ( $ this -> getAdapter ( ) , 'renderTag' ) , $ item_args ) ; } $ full_content = $ content ; foreach ( $ placeholders_table as $ name => $ value ) { $ full_content = strtr ( $ full_content , array ( sprintf ( $ placeholder_mask , $ name ) => $ value ) ) ; } $ output = $ this -> getAdapter ( ) -> renderTag ( $ full_content , $ tag_type , $ args ) ; $ this -> setOutput ( $ output ) ; if ( $ this -> getFlag ( ) & self :: OUTPUT_APPEND ) { return $ this ; } elseif ( $ this -> getFlag ( ) & self :: OUTPUT_BY_LINE ) { return $ output ; } }
Render a content with a specific tag mask and some placeholders
18,483
public function update ( \ SplSubject $ subject ) { if ( $ subject -> getAction ( ) === 'ctrlRouterLink_exec_execRoute' ) { $ this -> obtainCtrlRouterInfos ( $ subject ) ; if ( $ this -> ctrlRouterInfos -> isFound === true && $ this -> ctrlRouterInfos -> forWho === $ this -> execRouteSystemName ) { $ this -> run ( ) ; } } }
Observer update method
18,484
protected function run ( ) { if ( PHP_SAPI === 'cli' ) { return ; } if ( $ this -> ctrlRouterInfos -> target === null ) { return ; } $ this -> module -> monolog -> getLogger ( ) -> debug ( 'Execute current route.' , [ 'target' => $ this -> ctrlRouterInfos -> target ] ) ; $ useClass = $ this -> config -> getValue ( 'useClass' ) ; if ( $ useClass === true ) { $ this -> runObject ( ) ; } else { $ this -> runProcedural ( ) ; } }
Run controller system if application is not run in cli mode
18,485
protected function runObject ( ) { $ targetInfos = $ this -> ctrlRouterInfos -> target ; if ( ! is_array ( $ targetInfos ) || ( is_array ( $ targetInfos ) && count ( $ targetInfos ) !== 2 ) ) { throw new Exception ( 'The route target should be an array with the class name ' . '(first value) and the method name (second value).' , self :: ERR_RUN_OBJECT_MISSING_DATAS_INTO_TARGET ) ; } $ class = $ targetInfos [ 0 ] ; $ method = $ targetInfos [ 1 ] ; if ( ! class_exists ( $ class ) ) { throw new Exception ( 'Class ' . $ class . ' not found' , self :: ERR_RUN_OBJECT_CLASS_NOT_FOUND ) ; } $ classInstance = new $ class ; if ( ! method_exists ( $ classInstance , $ method ) ) { throw new Exception ( 'Method ' . $ method . ' not found in class ' . $ class , self :: ERR_RUN_OBJECT_METHOD_NOT_FOUND ) ; } $ classInstance -> { $ method } ( ) ; }
Call controller when is an object .
18,486
protected function runProcedural ( ) { $ routerLinker = $ this -> ctrlRouterInfos ; $ runFct = function ( ) use ( $ routerLinker ) { $ controllerFile = ( string ) $ routerLinker -> target ; if ( ! file_exists ( CTRL_DIR . $ controllerFile ) ) { throw new Exception ( 'Controller file ' . $ controllerFile . ' not found.' , self :: ERR_RUN_PROCEDURAL_FILE_NOT_FOUND ) ; } include ( CTRL_DIR . $ controllerFile ) ; } ; $ runFct ( ) ; }
Call controler when is a procedural file
18,487
private function setCurrentProfile ( string $ name ) : self { if ( ! $ this -> mapOfProfiles -> hasKey ( $ name ) ) { throw UndefinedProfileException :: forProfile ( $ name ) ; } $ this -> resolver = null ; $ this -> currentProfile = $ name ; return $ this ; }
Asigna el perfil
18,488
private function getResolver ( ) : OptionsResolver { if ( ! is_null ( $ this -> resolver ) ) { return $ this -> resolver ; } $ this -> resolver = $ this -> buildResolver ( ) ; return $ this -> resolver ; }
Devuelve el optionsResolver si no existe lo crea y configura
18,489
private function buildResolver ( ) : OptionsResolver { $ resolver = new OptionsResolver ( ) ; $ profile = $ this -> mapOfProfiles -> get ( $ this -> currentProfile ) ; call_user_func ( $ profile , $ resolver ) ; return $ resolver ; }
Devuelve un objeto OptionResolver configurado el perfil actual
18,490
public function validateInstance ( ) { $ instanceName = MoufManager :: getMoufManager ( ) -> findInstanceName ( $ this ) ; if ( ! file_exists ( ROOT_PATH . $ this -> i18nMessagePath . "message.php" ) ) { return new MoufValidatorResult ( MoufValidatorResult :: ERROR , "<b>Fine: </b>Unable to find default translation file for instance: <code>" . ROOT_PATH . $ this -> i18nMessagePath . "message.php</code>.<br/>" . "You should create the following files:<br/>" . $ this -> i18nMessagePath . "message.php <a href='" . ROOT_URL . "vendor/mouf/mouf/editLabels/createMessageFile?name=" . $ instanceName . "&selfedit=false&language=default'>(create this file)</a>" ) ; } else { $ this -> loadAllMessages ( ) ; $ keys = $ this -> getAllKeys ( ) ; foreach ( $ keys as $ key ) { $ msgs = $ this -> getMessageForAllLanguages ( $ key ) ; if ( ! isset ( $ msgs [ 'default' ] ) ) { $ missingDefaultKeys [ $ instanceName ] [ ] = $ key ; } } if ( empty ( $ missingDefaultKeys ) ) { return new MoufValidatorResult ( MoufValidatorResult :: SUCCESS , "<b>Fine: </b>Default translation file found in instance <code>$instanceName</code>.<br /> Default translation is available for all messages." ) ; } else { $ html = "" ; foreach ( $ missingDefaultKeys as $ instanceName => $ missingKeys ) { $ html .= "<b>Fine: </b>A default translation in '" . $ instanceName . "' is missing for these messages: " ; foreach ( $ missingKeys as $ missingDefaultKey ) { $ html .= "<a href='" . ROOT_URL . "vendor/mouf/mouf/editLabels/editLabel?key=" . urlencode ( $ missingDefaultKey ) . "&language=default&backto=" . urlencode ( ROOT_URL ) . "mouf/&msginstancename=" . urlencode ( $ instanceName ) . "'>" . $ missingDefaultKey . "</a> " ; } $ html .= "<hr/>" ; } return new MoufValidatorResult ( MoufValidatorResult :: WARN , $ html ) ; } } }
Runs the validation of the instance . Returns a MoufValidatorResult explaining the result .
18,491
public function forceLanguage ( $ language ) { $ changeLanguage = false ; if ( $ language === null ) { $ language = $ this -> language ; $ this -> initLanguage ( ) ; if ( $ this -> language != $ language ) { $ changeLanguage = true ; } } elseif ( $ this -> language != $ language ) { $ this -> language = $ language ; $ changeLanguage = true ; } if ( $ changeLanguage ) { $ this -> loadFile = array ( ) ; $ this -> msg = null ; } }
Use this function to force the language . Don t forget to call this function with null to restore default parameters . Return true if the language change else the language is the same this function return false
18,492
public function loadAllMessages ( ) { $ files = glob ( ROOT_PATH . $ this -> i18nMessagePath . 'message*.php' ) ; $ defaultFound = false ; foreach ( $ files as $ file ) { $ base = basename ( $ file ) ; if ( $ base == "message.php" ) { $ messageFile = new FineMessageLanguage ( ) ; $ messageFile -> loadAllFile ( ROOT_PATH . $ this -> i18nMessagePath ) ; $ this -> messages [ 'default' ] = $ messageFile ; $ defaultFound = true ; } else { if ( strpos ( $ base , '_custom' ) === false ) { $ phpPos = strpos ( $ base , '.php' ) ; $ language = substr ( $ base , 8 , $ phpPos - 8 ) ; $ messageLanguage = new FineMessageLanguage ( ) ; $ messageLanguage -> loadAllFile ( ROOT_PATH . $ this -> i18nMessagePath , $ language ) ; $ this -> messages [ $ language ] = $ messageLanguage ; } } } if ( ! $ defaultFound ) { $ messageFile = new FineMessageLanguage ( ) ; $ messageFile -> loadAllFile ( ROOT_PATH . $ this -> i18nMessagePath ) ; $ this -> messages [ 'default' ] = $ messageFile ; } }
Load all messages
18,493
public function getAllMessages ( $ language = null ) { $ this -> loadAllMessages ( ) ; $ msgs = array ( ) ; $ keys = $ this -> getAllKeys ( ) ; $ languages = $ this -> getSupportedLanguages ( ) ; foreach ( $ keys as $ key ) { $ msgs [ $ key ] = $ this -> getMessageForAllLanguages ( $ key , $ language ) ; } ksort ( $ msgs ) ; $ response = array ( "languages" => $ languages , "msgs" => $ msgs ) ; return $ response ; }
Loads and returns all the messages with languages in a big array .
18,494
public function getMessageForAllLanguages ( $ key , $ lang = null ) { if ( ! $ this -> messages ) { $ this -> loadAllMessages ( ) ; } $ messageArray = array ( ) ; foreach ( $ this -> messages as $ language => $ messageLanguage ) { if ( is_null ( $ lang ) || $ lang == "" ) $ messageArray [ $ language ] = $ messageLanguage -> getMessage ( $ key ) ; elseif ( $ lang == $ language ) $ messageArray [ $ language ] = $ messageLanguage -> getMessage ( $ key ) ; } return $ messageArray ; }
Get the message for language .
18,495
public function getAllKeys ( ) { $ all_messages = array ( ) ; foreach ( $ this -> messages as $ language => $ message ) { $ all_messages = array_merge ( $ all_messages , $ message -> getAllMessages ( ) ) ; } return array_keys ( $ all_messages ) ; }
Returns the list of all keys that have been defined in all language files . loadAllMessages must have been called first .
18,496
public function createLanguageFile ( $ language ) { if ( $ language == "default" ) { $ file = ROOT_PATH . $ this -> i18nMessagePath . "message.php" ; } else { $ file = ROOT_PATH . $ this -> i18nMessagePath . "message_" . $ language . ".php" ; } if ( ! is_writable ( $ file ) ) { if ( ! file_exists ( $ file ) ) { $ dir = dirname ( $ file ) ; if ( ! file_exists ( $ dir ) ) { $ old = umask ( 0 ) ; $ result = mkdir ( $ dir , 0775 , true ) ; umask ( $ old ) ; if ( $ result == false ) { $ exception = new \ Exception ( "Unable to create directory " . $ dir ) ; throw $ exception ; } } } else { $ exception = new \ Exception ( "Unable to write file " . $ file ) ; throw $ exception ; } } if ( ! file_exists ( $ file ) ) { $ fp = fopen ( $ file , "w" ) ; fclose ( $ fp ) ; chmod ( $ file , 0664 ) ; } }
Creates the file for specified language . If the file already exists the function does nothing .
18,497
public function setMessage ( $ key , $ value , $ language ) { $ messageFile = $ this -> getMessageLanguageForLanguage ( $ language ) ; $ messageFile -> setMessage ( $ key , $ value ) ; $ messageFile -> save ( ) ; }
Sets and saves a new message translation .
18,498
public function setMessages ( array $ messages , $ language ) { $ messageFile = $ this -> getMessageLanguageForLanguage ( $ language ) ; $ messageFile -> setMessages ( $ messages ) ; $ messageFile -> save ( ) ; }
Sets and saves many messages at once for a given language .
18,499
public function deleteMessage ( $ key , $ language ) { $ messageFile = $ this -> getMessageLanguageForLanguage ( $ language ) ; $ messageFile -> deleteMessage ( $ key ) ; $ messageFile -> save ( ) ; }
Deletes a message translation .