idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
54,500
public function is ( $ filter ) : bool { if ( $ filter instanceof Entity ) { return $ this -> isSameAsEntity ( $ filter ) ; } if ( is_associative_array ( $ filter ) ) { return $ this -> matchesFilter ( $ filter ) ; } return $ this -> matchedId ( $ filter ) ; }
Check if entity is the same as the provided entity or matches id or filter . For a filter scalars are compared as string .
54,501
public static function display ( \ Exception $ e , $ title = 'Application Error' ) { @ ob_get_clean ( ) ; echo ' <html> <head> <title>' . $ title . '</title> <style> body{margin:0;padding:30px;font:14px/1.5 Helvetica,Arial,Verdana,sans-serif;} span{line-height:30px;} h1{margin:0 0 30px;font-size:40px;font-weight:normal;line-height:54px;border-bottom: 2px solid #CCCCCC;} h2{margin:0 0 20px;font-size:30px;font-weight:normal;line-height:50px;border-bottom: 1px solid #CCCCCC;} h3,h4{margin:0 0 20px;font-size:20px;font-weight:normal;line-height:40px;border-bottom: 1px solid #CCCCCC;} a{color:#428bca;text-decoration:underline;} a:hover{color:#2a6496;} div.file-preview{display:block;height:300px;overflow-x:auto;} table{min-width:100%;line-height:30px;} td.cell-left{padding-right:10px;text-align:right;border-right:1px solid #CCCCCC;} td.cell-right{padding-left:10px;text-align:left;} td.width50{width:50px;} td.width15p{width:15%;} .highlight{background:yellow;} td.code-case{font-family:monospace !important;} </style> </head> <body> <h1>' . $ title . '</h1> <h2><strong>Exception: </strong><br /><code>' . get_class ( $ e ) . '</code></h2> <p> <strong>Line: </strong>' . $ e -> getLine ( ) . '<br /> <strong>File: </strong>' . $ e -> getFile ( ) . '<br /> <strong>Code: </strong>' . $ e -> getCode ( ) . ' </p> <h3>Message</h3> <p> <strong>' . $ e -> getMessage ( ) . '</strong><br /> </p> <h3>Additional Information:</h3> <p> ' . self :: getMoreInformationFromException ( $ e ) . ' </p> <h3>Trace</h3> <p> <pre><code>' . $ e -> getTraceAsString ( ) . '</code></pre><br /> </p> ' . self :: getSnippetFromFile ( $ e -> getFile ( ) , $ e -> getLine ( ) ) . ' </body> </html> ' ; return ; }
Format an exception and show it .
54,502
protected static function getSnippetFromFile ( $ file , $ line ) { $ defaultSnippet = '<code><strong>Snippet not available</strong></code>' ; if ( file_exists ( $ file ) ) { $ start = $ line ; if ( $ start > 21 ) { $ start = $ line - 20 ; } $ end = $ start + 40 ; $ highlight = highlight_file ( $ file , true ) ; if ( ! $ highlight ) { return $ defaultSnippet ; } $ highlight = str_replace ( array ( '<code>' , '</code>' ) , array ( '' , '' ) , $ highlight ) ; $ pieces = explode ( '<br />' , $ highlight ) ; if ( ! $ pieces ) { return $ defaultSnippet ; } $ i = 0 ; $ str = '<h4><strong>File Preview: </strong>' . $ file . '</h4>' ; $ str .= '<div class="file-preview">' ; $ str .= '<table><tr><td valign="top" class="cell-left width50">' ; for ( $ l = 0 ; $ l < count ( $ pieces ) + 1 ; $ l ++ ) { $ str .= '' . ( $ l + 1 ) . '<br />' ; } $ str .= '</td><td valign="top" class="cell-right code-case">' ; foreach ( $ pieces as $ piece ) { $ i ++ ; if ( $ i == $ line ) { $ str .= '<div class="highlight">' . $ piece . '</div>' ; } else { $ str .= $ piece ; } $ str .= '<br />' ; } $ str .= '</td></tr></table>' ; $ str .= '</div>' ; return $ str ; } return $ defaultSnippet ; }
Get a snippet of the file
54,503
public static function getMoreInformationFromException ( \ Exception $ e ) { $ default = 'No further information available.' ; if ( ! property_exists ( $ e , 'additionalData' ) ) { return $ default ; } if ( ! is_array ( $ e -> additionalData ) ) { return $ default ; } if ( empty ( $ e -> additionalData ) ) { return $ default ; } $ data = '<table>' ; foreach ( $ e -> additionalData as $ k => $ v ) { if ( is_int ( $ k ) || is_string ( $ k ) ) { $ data .= '<tr>' ; $ data .= '<td valign="top" class="cell-left width15p"><strong>' . $ k . '</strong></td>' ; $ data .= '<td valign="top" class="cell-right">' ; if ( is_object ( $ v ) ) { $ data .= '<xmp>' . serialize ( $ v ) . '</xmp>' ; } elseif ( is_array ( $ v ) ) { $ data .= '<xmp>' . json_encode ( $ v ) . '</xmp>' ; } else { $ data .= '<xmp>' . $ v . '</xmp>' ; } $ data .= '</td>' ; $ data .= '</tr>' ; } } $ data .= '</table>' ; return $ data ; }
Get further information from Exception if it has the property additionalData
54,504
protected function createDefaultDDL ( $ default ) { $ dataType = $ this -> getDataType ( ) ; if ( is_array ( $ default ) ) { foreach ( $ default as $ k => $ option ) { $ default [ $ k ] = $ this -> getDataType ( ) -> quote ( $ option ) ; } $ default = '(' . implode ( ',' , $ default ) . ')' ; } elseif ( $ dataType instanceof TimeTypeInterface && $ this -> getDefault ( ) == self :: DEFAULT_CURRENT_TIMESTAMP ) { $ precision = $ dataType -> hasPrecision ( ) ? '(' . $ dataType -> getPrecision ( ) . ')' : null ; $ default = self :: DEFAULT_CURRENT_TIMESTAMP . $ precision ; } else { $ default = $ this -> getDefault ( ) === null ? 'NULL' : $ this -> getDataType ( ) -> quote ( $ default ) ; } return $ default ; }
Creates the portion of DDL for the column default value .
54,505
protected function createOnUpdateCurrentTimestampDDL ( ) { $ onUpdateDDL = null ; $ dataType = $ this -> getDataType ( ) ; if ( $ this -> isOnUpdateCurrentTimestamp ( ) ) { $ precision = null ; if ( $ dataType instanceof TimeTypeInterface && $ dataType -> hasPrecision ( ) ) { $ precision = '(' . $ dataType -> getPrecision ( ) . ')' ; } $ onUpdateDDL = 'ON UPDATE CURRENT_TIMESTAMP' . $ precision ; } return $ onUpdateDDL ; }
Creates the portion of DDL for setting column value to the current time on update .
54,506
protected function handleAssetRequest ( array $ params ) { $ response = new Response ( ) ; $ assetsConf = $ this -> config -> getSection ( 'asset_resolv' ) ; $ assetsDir = $ this -> config -> get ( 'app.public_dir' ) . '/assets' ; if ( ! empty ( $ assetsConf [ 'current' ] ) ) { $ file = $ assetsDir . '/' . $ assetsConf [ 'current' ] . '/' . $ params [ 'filename' ] ; if ( file_exists ( $ file ) ) { $ fileResource = new Http \ File \ File ( $ file ) ; $ mtime = filemtime ( $ fileResource -> getPathname ( ) ) ; $ response -> headers -> set ( 'Content-Type' , $ fileResource -> getMimeType ( ) ) ; $ response -> setContent ( file_get_contents ( $ fileResource -> getPathname ( ) ) ) ; $ response -> setCache ( array ( 'public' => true , 'last_modified' => new \ DateTime ( gmdate ( "D, d M Y H:i:s" , $ mtime ) ) ) ) ; $ response -> setExpires ( new \ DateTime ( gmdate ( "D, j M Y H:i:s" , time ( ) + MONTH ) ) ) ; $ response -> isNotModified ( $ this -> request ) ; return $ response ; } } elseif ( ! empty ( $ assetsConf [ 'fallback' ] ) ) { } }
Handle a asset request
54,507
protected function handleMetaUi ( array $ data , $ annotation , $ targetView , Request $ request = null ) { if ( empty ( $ annotation ) ) { return $ targetView ; } $ annotation -> prepare ( ) ; $ metaPath = $ this -> config -> get ( 'app.meta_dir' ) ; $ elementName = $ annotation -> name ; $ metaFile = $ annotation -> metaFile ; $ attributes = $ annotation -> attributes ; $ layout = $ annotation -> layout ; if ( empty ( $ layout ) ) { if ( $ request -> isMobile ( ) ) { if ( $ request -> isIpad ( ) ) { $ layout = $ this -> config -> get ( 'layout.mobile' ) ; } else { $ layout = $ this -> config -> get ( 'layout.mobile' ) ; } } else { $ layout = $ this -> config -> get ( 'layout.default' ) ; } } $ this -> uiEngine -> setTargetBundle ( $ layout ) ; $ this -> uiEngine -> setMetaFile ( $ metaPath . DS . $ annotation -> metaFile ) ; $ elementData = array ( ) ; if ( array_key_exists ( $ elementName , $ data ) && is_array ( $ data [ $ elementName ] ) ) { $ elementData = $ data [ $ elementName ] ; } $ element = $ this -> uiEngine -> build ( $ elementData , $ attributes ) ; if ( ! empty ( $ annotation -> id ) ) { $ element -> setId ( $ annotation -> id ) ; } $ elementType = $ element -> getXtype ( ) ; $ elementId = $ element -> getId ( ) ; $ elementCollection = new \ StdClass ( ) ; $ elementCollection -> $ elementId = $ element ; $ targetView -> assign ( $ elementType , $ elementCollection ) ; $ template = empty ( $ targetView ) ? $ element -> getXtype ( ) . '_page' : $ element -> getXtype ( ) ; try { $ view = $ this -> createView ( $ template , $ data ) ; $ view -> assign ( $ element -> getXtype ( ) , $ element ) ; if ( empty ( $ targetView ) ) { return $ view ; } $ targetView -> setUiElement ( $ element -> getId ( ) , $ view -> getOutput ( ) ) ; $ elementObject = new \ StdClass ( ) ; $ elementObject -> $ elementId = $ element ; $ targetView -> set ( $ element -> getXtype ( ) , $ elementObject ) ; } catch ( \ Exception $ e ) { if ( $ e -> getCode ( ) !== 404 ) { throw $ e ; } } return $ targetView ; }
This method handle a Meta - UI
54,508
protected function handleView ( $ class , $ method , $ data , $ annotation ) { if ( empty ( $ annotation ) ) { return null ; } $ annotation -> prepare ( ) ; $ template = $ annotation -> template ; if ( empty ( $ template ) ) { $ nsSepPos = strrpos ( $ class , '\\' ) ; $ class = preg_replace ( '/([A-Z])/' , '_$1' , substr ( $ class , $ nsSepPos + 1 , - 10 ) ) ; $ class = strtolower ( ltrim ( $ class , "_" ) ) ; $ method = substr ( $ method , 0 , - 6 ) ; $ template = $ class . DS . $ method ; } $ view = $ this -> createView ( $ template , $ data , $ annotation -> engine ) ; $ registeredVars = array ( ) ; if ( $ registerAnnotation = $ this -> annotationReader -> getAnnotation ( 'RegisterJavascript' ) ) { $ registeredVars = $ registerAnnotation -> all ( ) ; $ publicBasePath = $ this -> config -> get ( 'app.public_dir' ) . DS ; $ sourceBasePath = $ this -> config -> get ( 'app.view_scripts_javascript_dir' ) . DS ; $ jsBaseUrl = 'assets/cache/' ; foreach ( $ registeredVars as $ i => $ jsFile ) { if ( ! file_exists ( $ sourceBasePath . $ jsFile ) ) { throw new \ Exception ( sprintf ( "File Not Found Error: File %s doesn't exist!." , $ jsFile ) ) ; } $ jsPath = substr ( $ jsFile , 0 , strrpos ( $ jsFile , DS ) ) ; $ fileSum = md5_file ( $ sourceBasePath . $ jsFile ) ; $ jsCacheFile = rtrim ( $ jsFile , '.js' ) . '-' . $ fileSum . '.js' ; if ( ! is_file ( $ publicBasePath . $ jsBaseUrl . $ jsCacheFile ) ) { if ( ! is_dir ( $ publicBasePath . $ jsBaseUrl . $ jsPath ) ) { self :: createDir ( $ publicBasePath . $ jsBaseUrl . $ jsPath ) ; } $ oldCacheFiles = glob ( $ publicBasePath . $ jsBaseUrl . rtrim ( $ jsFile , '.js' ) . '-*' ) ; if ( count ( $ oldCacheFiles ) > 0 ) { foreach ( $ oldCacheFiles as $ oldCacheFile ) { @ unlink ( $ oldCacheFile ) ; } } copy ( $ sourceBasePath . $ jsFile , $ publicBasePath . $ jsBaseUrl . $ jsCacheFile ) ; } $ registeredVars [ $ i ] = $ jsBaseUrl . $ jsCacheFile ; } } $ view -> assign ( 'javascript' , $ registeredVars ) ; return $ view ; }
handle the view layer
54,509
protected function prepareRequestParams ( array $ data ) { $ params = array ( ) ; foreach ( $ data as $ listParams ) { $ params = array_merge ( $ params , $ listParams ) ; } $ params [ '_controllerClass' ] = $ params [ '_controller' ] ; $ params [ '_controllerMethod' ] = $ params [ '_action' ] ; $ params [ '_controller' ] = $ params [ '_controllerClass' ] . '::' . $ params [ '_controllerMethod' ] ; return $ params ; }
This method prepares the request parameters to be consumed by Controller Resolver
54,510
public function getUserNames ( $ entity ) { $ users = $ this -> getDoctrine ( ) -> getRepository ( $ entity ) -> findBy ( [ 'enabled' => true , ] , [ 'id' => 'asc' , ] ) ; return CollectionUtility :: get ( 'username' , $ users ) ; }
Get Usernames as array
54,511
private function validate ( $ uri ) { try { $ validate = [ ] ; if ( strpos ( $ uri , self :: VALIDATION_PREFIX ) === false && strpos ( $ uri , $ this -> getDelimiter ( ) ) === false ) { return false ; } $ parts = explode ( $ this -> _delimiter , $ uri ) ; for ( $ i = 0 , $ c = count ( $ parts ) ; $ i < $ c ; $ i ++ ) { if ( empty ( $ parts [ $ i ] ) ) { continue ; } elseif ( ( strpos ( $ parts [ $ i ] , self :: VALIDATION_PREFIX ) ) === false ) { $ this -> urlPart [ ] = $ parts [ $ i ] ; continue ; } $ this -> urlPart [ ] = $ parts [ $ i ] ; $ validate [ ] = new Validator ( $ parts [ $ i ] ) ; $ this -> validate = true ; } unset ( $ parts , $ c , $ i , $ uri ) ; } catch ( RouteException $ e ) { throw $ e ; } return $ validate ; }
validates a url and adds the validator to the mapping part
54,512
private function init ( $ uri , $ callback ) { try { $ this -> validate ( $ uri ) ; switch ( true ) { case ( is_array ( $ callback ) || ( is_object ( $ callback ) && ! is_callable ( $ callback ) ) ) : $ this -> setType ( self :: TYPE_O ) ; $ this -> strategy = StrategyFactory :: make ( self :: TYPE_O , $ callback , new RouteMethodAnnotaionParser ( ) ) ; break ; case ( is_string ( $ callback ) ) : $ this -> setType ( self :: TYPE_F ) ; $ this -> strategy = StrategyFactory :: make ( self :: TYPE_F , $ callback ) ; if ( ! function_exists ( $ callback ) ) { throw new RouteException ( sprintf ( _ ( 'There is no such Function like %s' ) , $ callback ) ) ; } break ; case ( is_callable ( $ callback ) ) : $ this -> setType ( self :: TYPE_LF ) ; $ this -> strategy = StrategyFactory :: make ( self :: TYPE_LF , $ callback ) ; break ; } } catch ( RouteException $ e ) { throw $ e ; } return true ; }
initlializes the mapping
54,513
public function deleteSalesDiscount ( int $ id ) : bool { Assert :: that ( $ id ) -> greaterThan ( 0 , '$id must be positive' ) ; return ( bool ) $ this -> master -> doRequest ( 'DELETE' , sprintf ( '/admin/WEBAPI/Endpoints/v1_0/DiscountService/{KEY}/salesDiscount/%d' , $ id ) ) ; }
Deletes a sales discount
54,514
public function process ( $ cmd , $ descriptors , $ cwd = null , $ env = null , $ options = null ) { $ this -> beginProcess ( $ cmd , $ descriptors , $ cwd , $ env , $ options ) ; return $ this -> endProcess ( ) ; }
Runs a process .
54,515
public function beginProcess ( $ cmd , $ descriptors , $ cwd = null , $ env = null , $ options = null ) { if ( isset ( $ this -> _process ) ) { throw new CException ( 'Failed to start process. Process is already running.' ) ; } echo "Running command: $cmd ... " ; $ this -> _process = proc_open ( $ cmd , $ descriptors , $ this -> _pipes , $ cwd , $ env , $ options ) ; if ( ! is_resource ( $ this -> _process ) ) { throw new CException ( 'Failed to start process. Process could not be opened.' ) ; } }
Opens a process .
54,516
public function endProcess ( ) { if ( isset ( $ this -> _process ) ) { $ error = $ this -> getError ( ) ; foreach ( array_keys ( $ this -> _pipes ) as $ descriptor ) { $ this -> closeResource ( $ descriptor ) ; } $ return = proc_close ( $ this -> _process ) ; if ( $ return !== 0 ) { throw new CException ( sprintf ( 'Process failed with error "%s"' , $ error ) , $ return ) ; } $ this -> _process = null ; echo "done\n" ; return $ return ; } return 0 ; }
Closes all open pipes and ends the current process .
54,517
public function writeToResource ( $ index , $ string , $ length = null ) { return isset ( $ this -> _pipes [ $ index ] ) ? fwrite ( $ this -> _pipes [ $ index ] , $ string , $ length ) : false ; }
Writes to a specific resource .
54,518
public function readFromResource ( $ descriptor , $ close = true ) { if ( isset ( $ this -> _pipes [ $ descriptor ] ) ) { $ contents = stream_get_contents ( $ this -> _pipes [ $ descriptor ] ) ; if ( $ close ) { $ this -> closeResource ( $ descriptor ) ; } return $ contents ; } return false ; }
Reads from a specific resource .
54,519
public function closeResource ( $ descriptor ) { if ( isset ( $ this -> _pipes [ $ descriptor ] ) ) { $ success = fclose ( $ this -> _pipes [ $ descriptor ] ) ; unset ( $ this -> _pipes [ $ descriptor ] ) ; return $ success ; } return false ; }
Closes a specific resource .
54,520
public function getResource ( $ descriptor ) { return isset ( $ this -> _pipes [ $ descriptor ] ) ? $ this -> _pipes [ $ descriptor ] : null ; }
Returns a specific resource .
54,521
public function apply ( $ testable , array $ config = array ( ) ) { $ tokens = $ testable -> tokens ( ) ; $ lines = $ testable -> lines ( ) ; $ typeCache = $ testable -> typeCache ( ) ; $ matches = array ( ) ; if ( ! isset ( $ typeCache [ T_USE ] ) ) { return ; } foreach ( $ typeCache [ T_USE ] as $ tokenId ) { $ token = $ tokens [ $ tokenId ] ; $ line = $ lines [ $ token [ 'line' ] - 1 ] ; if ( preg_match ( '/^use (?:([^ ]+ as )|(.*\\\))?(.*);$/i' , $ line , $ matches ) === 1 ) { $ count = 0 ; if ( in_array ( $ matches [ 3 ] , $ this -> _ignored ) ) { continue ; } foreach ( $ typeCache [ T_STRING ] as $ stringId ) { if ( strcasecmp ( $ tokens [ $ stringId ] [ 'content' ] , $ matches [ 3 ] ) === 0 ) { $ count ++ ; } if ( $ count === 2 ) { break ; } } if ( $ count < 2 ) { $ this -> addViolation ( array ( 'message' => 'Class ' . $ matches [ 3 ] . ' was never called' , 'line' => $ token [ 'line' ] , ) ) ; } } } }
Iterates over T_USE tokens gets the aliased name into an array and validates it was used within the script .
54,522
protected function setPathInfo ( ) { $ query = $ this -> server -> get ( 'QUERY_STRING' , '' ) ; $ script = $ this -> server -> get ( 'SCRIPT_NAME' , '' ) ; $ uri = $ this -> server -> get ( 'REQUEST_URI' , '/' ) ; $ path = preg_replace ( [ '/\A' . preg_quote ( $ script , '/' ) . '/' , '/\A' . preg_quote ( dirname ( $ script ) , '/' ) . '/' , '/\?' . preg_quote ( $ query , '/' ) . '\z/' ] , '' , $ uri ) ; $ this -> path_info = '/' . ltrim ( $ path , '/' ) ; }
Set path_info based on QUERY_STRING SCRIPT_NAME and REQUEST_URI .
54,523
protected function getCached ( string $ playerName , string $ cacheKey ) { $ playerCacheKey = strtolower ( $ playerName ) ; if ( ! isset ( $ this -> cache [ $ cacheKey ] [ $ playerCacheKey ] ) ) { return null ; } return $ this -> cache [ $ cacheKey ] [ $ playerCacheKey ] ; }
Returns an object from cache or null if it isn t cached .
54,524
protected function fetch ( string $ playerName , string $ cacheKey , array $ fetchStrategies ) { $ playerCacheKey = strtolower ( $ playerName ) ; if ( isset ( $ this -> cache [ $ cacheKey ] [ $ playerCacheKey ] ) ) { return $ this -> cache [ $ cacheKey ] [ $ playerCacheKey ] ; } $ firstException = null ; foreach ( $ fetchStrategies as $ url => $ conversionMethod ) { try { $ url = sprintf ( $ url , urlencode ( $ playerName ) ) ; $ data = $ this -> fetchUrl ( $ url ) ; $ result = call_user_func ( [ $ this -> dataConverter , $ conversionMethod ] , $ data ) ; $ targetObject = false ; foreach ( $ result as $ resultCacheKey => $ resultObject ) { if ( ! isset ( $ this -> cache [ $ resultCacheKey ] [ $ playerCacheKey ] ) ) { $ this -> cache [ $ resultCacheKey ] [ $ playerCacheKey ] = $ resultObject ; } if ( $ resultCacheKey === $ cacheKey ) { $ targetObject = $ resultObject ; } } if ( $ targetObject ) { return $ targetObject ; } } catch ( Exception $ exception ) { if ( $ exception instanceof FetchFailedException || $ exception instanceof DataConversionException ) { if ( ! $ firstException ) { $ firstException = $ exception ; } } else { throw $ exception ; } } } throw new FetchFailedException ( sprintf ( "None of the fetch strategies (%s) succeeded in retrieving the player's %s." , implode ( ", " , $ fetchStrategies ) , $ cacheKey ) , 0 , $ firstException ) ; }
Fetches an item from cache or obtains it freshly using the given functions .
54,525
protected function fetchUrl ( string $ url ) : string { $ curl = curl_init ( $ url ) ; curl_setopt_array ( $ curl , [ CURLOPT_RETURNTRANSFER => true , CURLOPT_TIMEOUT => $ this -> timeOut ] ) ; $ data = curl_exec ( $ curl ) ; $ statusCode = curl_getinfo ( $ curl , CURLINFO_HTTP_CODE ) ; $ error = curl_error ( $ curl ) ; curl_close ( $ curl ) ; if ( $ error ) { throw new FetchFailedException ( sprintf ( "A cURL error occurred for \"%s\": %s" , $ url , $ error ) ) ; } if ( $ statusCode !== 200 ) { throw new FetchFailedException ( sprintf ( "URL \"%s\" responded with status code %d." , $ url , $ statusCode ) ) ; } if ( ! $ data ) { throw new FetchFailedException ( sprintf ( "URL \"%s\" returned no data." , $ url ) ) ; } return $ data ; }
Fetches data from the given URL .
54,526
public function getControllerName ( ) { if ( null === $ this -> _controller ) { $ this -> _controller = $ this -> getParam ( $ this -> getControllerKey ( ) ) ; } return $ this -> _controller ; }
Retrieve the controller name
54,527
public function setActionName ( $ value ) { $ this -> _action = $ value ; if ( null === $ value ) { $ this -> setParam ( $ this -> getActionKey ( ) , $ value ) ; } return $ this ; }
Set the action name
54,528
public function getParam ( $ key , $ default = null ) { $ key = ( string ) $ key ; if ( isset ( $ this -> _params [ $ key ] ) ) { return $ this -> _params [ $ key ] ; } return $ default ; }
Get an action parameter
54,529
public function setParams ( array $ array ) { $ this -> _params = $ this -> _params + ( array ) $ array ; foreach ( $ array as $ key => $ value ) { if ( null === $ value ) { unset ( $ this -> _params [ $ key ] ) ; } } return $ this ; }
Set action parameters en masse ; does not overwrite
54,530
public function fetchAssociatedRepository ( $ entity_property ) { $ entity_class = $ this -> getClassName ( ) ; $ class_meta_data = $ this -> getEntityManager ( ) -> getClassMetaData ( $ entity_class ) ; $ associated_mapping = $ class_meta_data -> getAssociationMapping ( $ entity_property ) ; return $ this -> getEntityManager ( ) -> getRepository ( $ associated_mapping [ 'targetEntity' ] ) ; }
Fetch an associated repository by property name
54,531
private function makeComparison ( $ builder , $ field , $ operator , $ value , $ pcount = NULL ) { $ method_translations = [ '=' => 'eq' , '<' => 'lt' , '>' => 'gt' , '!' => 'neq' , '~' => 'like' , 'in' => 'in' , '!in' => 'notIn' , '==' => 'eq' , '!=' => 'neq' , '<>' => 'neq' , '<=' => 'lte' , '>=' => 'gte' ] ; if ( ! isset ( $ method_translations [ $ operator ] ) ) { throw new InvalidArgumentException ( 'Build terms contains invalid operator ' . $ operator ) ; } $ method = $ method_translations [ $ operator ] ; if ( is_null ( $ value ) ) { switch ( $ method ) { case 'eq' : $ method = 'isNull' ; break ; case 'neq' : $ method = 'isNotNull' ; break ; } } elseif ( is_array ( $ value ) ) { switch ( $ method ) { case 'eq' : $ method = 'in' ; break ; case 'neq' : $ method = 'notIn' ; break ; } } if ( $ method == 'like' ) { $ field = 'LOWER(' . $ field . ')' ; } return ( $ pcount !== NULL ) ? $ builder -> expr ( ) -> $ method ( $ field , '?' . $ pcount ) : $ builder -> expr ( ) -> $ method ( $ field ) ; }
Makes a comparison based on shortened operators
54,532
final protected function createSelectQuery ( Query $ query ) { $ select = $ this -> getDatabase ( ) -> select ( 'node' , 'n' ) -> fields ( 'n' , [ 'nid' ] ) -> addTag ( 'node_access' ) ; if ( $ this -> addGroupby ( ) ) { $ select -> groupBy ( 'n.nid' ) ; } return $ select ; }
Create node select query override this to change it
54,533
final protected function process ( \ SelectQuery $ select , Query $ query ) { $ sortOrder = Query :: SORT_DESC === $ query -> getSortOrder ( ) ? 'desc' : 'asc' ; if ( $ query -> hasSortField ( ) ) { $ select -> orderBy ( $ query -> getSortField ( ) , $ sortOrder ) ; } $ select -> orderBy ( $ this -> getPredictibleOrderColumn ( ) , $ sortOrder ) ; if ( $ searchString = $ query -> getSearchString ( ) ) { $ select -> condition ( 'n.title' , '%' . db_like ( $ searchString ) . '%' , 'LIKE' ) ; } if ( $ query -> has ( 'history_user_id' ) ) { $ select -> leftJoin ( 'history' , 'h' , "h.nid = n.nid AND h.uid = :history_uid" , [ ':history_uid' => $ query -> get ( 'history_user_id' ) ] ) ; } else { $ select -> leftJoin ( 'history' , 'h' , "h.nid = n.nid AND 1 = 0" ) ; } if ( $ query -> has ( 'revision_user_id' ) ) { $ revSelect = $ this -> database -> select ( 'node_revision' , 'r' ) -> condition ( 'r.uid' , $ query -> has ( 'revision_user_id' ) ) -> where ( "r.nid = n.nid" ) -> range ( 0 , 1 ) ; $ revSelect -> addExpression ( '1' ) ; $ select -> exists ( $ revSelect ) ; } $ this -> applyFilters ( $ select , $ query ) ; $ this -> pager = $ select -> extend ( DrupalPager :: class ) ; $ this -> pager -> setDatasourceQuery ( $ query ) ; return $ this -> pager ; }
Implementors must set the node table with n as alias and call this method for the datasource to work correctly .
54,534
protected function generateImage ( $ id , $ word ) { $ font = $ this -> getFont ( ) ; if ( empty ( $ font ) ) { throw new Exception \ NoFontProvidedException ( 'Image CAPTCHA requires font' ) ; } $ w = $ this -> getWidth ( ) ; $ h = $ this -> getHeight ( ) ; $ fsize = $ this -> getFontSize ( ) ; $ img_file = $ this -> getImgDir ( ) . $ id . $ this -> getSuffix ( ) ; if ( empty ( $ this -> startImage ) ) { $ img = new Imagick ( ) ; $ img -> newImage ( $ w , $ h , new ImagickPixel ( '#FFFFFF' ) , 'png' ) ; } else { $ img = new Imagick ( $ this -> startImage ) ; $ w = $ img -> getImageWidth ( ) ; $ h = $ img -> getImageHeight ( ) ; } $ text = new ImagickDraw ( ) ; $ text -> setFillColor ( '#000000' ) ; $ text -> setFont ( $ font ) ; $ text -> setFontSize ( empty ( $ fsize ) ? $ h - 10 : $ fsize ) ; $ text -> setGravity ( Imagick :: GRAVITY_CENTER ) ; $ text -> annotation ( 0 , 0 , $ word ) ; $ img -> drawImage ( $ text ) ; $ noise = new ImagickDraw ( ) ; $ noise -> setFilLColor ( '#000000' ) ; for ( $ i = 0 ; $ i < $ this -> dotNoiseLevel ; $ i ++ ) { $ x = mt_rand ( 0 , $ w ) ; $ y = mt_rand ( 0 , $ h ) ; $ noise -> circle ( $ x , $ y , $ x + mt_rand ( 0.3 , 1.7 ) , $ y + mt_rand ( 0.3 , 1.7 ) ) ; } for ( $ i = 0 ; $ i < $ this -> lineNoiseLevel ; $ i ++ ) { $ noise -> line ( mt_rand ( 0 , $ w ) , mt_rand ( 0 , $ h ) , mt_rand ( 0 , $ w ) , mt_rand ( 0 , $ h ) ) ; } $ img -> waveImage ( 5 , mt_rand ( 60 , 100 ) ) ; $ img -> scaleimage ( $ w , $ h ) ; $ img -> drawImage ( $ noise ) ; $ img -> swirlImage ( mt_rand ( 10 , 30 ) ) ; file_put_contents ( $ img_file , $ img ) ; unset ( $ img ) ; }
Generate image captcha
54,535
public function appendParameter ( Parameter $ Parameter , $ Handler = null ) { switch ( true ) { case $ Parameter instanceof Option : $ this -> parameters [ $ Parameter -> getLong ( ) ] = $ Parameter ; if ( ! is_null ( $ Handler ) ) { if ( $ Handler instanceof Closure ) { $ this -> setEvent ( $ Parameter , $ Handler ) ; } else { throw new ParameterEventTypeException ( ) ; } } $ this -> clearCache ( ) ; break ; default : throw new UnsupportedParameterTypeException ( ) ; } }
Append parameter method
54,536
public function appendHelpParameter ( $ description ) { $ Option = new HelpOption ( $ description ) ; $ Self = $ this ; $ this -> appendParameter ( $ Option , function ( ) use ( $ Self ) { $ Self -> displayHelp ( ) ; } ) ; }
Append help parameter
54,537
public function setEvent ( Parameter $ Parameter , Closure $ Handler ) { switch ( true ) { case $ Parameter instanceof Option : $ long = $ Parameter -> getLong ( ) ; if ( isset ( $ this -> parameters [ $ long ] ) ) { $ this -> events [ $ long ] = $ Handler ; } else { throw new ParameterNotFoundException ( ) ; } break ; default : throw new UnsupportedParameterTypeException ( ) ; } }
Set event for added parameter
54,538
public function content ( $ index = 0 ) { if ( isset ( $ this -> _contentView [ $ index ] ) ) { $ this -> _contentView [ $ index ] -> render ( ) ; } }
Show the content in the layout
54,539
public function addAndTerm ( $ term , $ value ) { $ value = trim ( $ value ) ; if ( $ this -> query !== '' ) { $ this -> query .= ' AND ' ; } $ this -> query .= $ term . ':' . $ value ; }
Adds a query term to the query with AND . This should only be used by Arachnid as it takes a term of ANDS and hands it to everyman index - > query .
54,540
public function create ( $ name , $ type , array $ options ) { if ( is_string ( $ type ) ) { $ type = $ this -> registry -> getType ( $ type ) ; } if ( ! $ type instanceof WidgetTypeInterface ) { throw new \ InvalidArgumentException ( 'Unexpected widget type.' ) ; } $ options [ 'name' ] = $ name ; $ resolver = new OptionsResolver ( ) ; $ type -> configureOptions ( $ resolver ) ; $ options = $ resolver -> resolve ( $ options ) ; $ widget = new Widget ( $ name , $ type ) ; $ type -> buildWidget ( $ widget , $ options ) ; return $ widget ; }
Creates the widget .
54,541
public function guardar ( $ llave , $ valor , $ expiracion = 0 ) { return $ this -> gestor -> set ( $ llave , $ valor , $ expiracion ) ; }
Guarda los datos de la llave en el servidor cache .
54,542
public function connect ( array $ parameters = null ) : Connection { if ( is_null ( $ parameters ) ) { $ parameters = $ this -> data ; } $ config = new Configuration ( ) ; $ this -> connection = DriverManager :: getConnection ( $ parameters , $ config ) ; return $ this -> connection ; }
Connects into database .
54,543
private function identifyIndexes ( string $ rute ) { $ array = explode ( '/' , substr ( $ rute , 1 , strlen ( $ rute ) ) ) ; for ( $ index = 0 ; $ index < count ( $ array ) ; $ index ++ ) { if ( preg_match ( '/[:][a-z]/' , $ array [ $ index ] ) ) { $ this -> indexes -> add ( $ index ) ; } } }
Identificar el indice de los paramatros contenidos en la ruta .
54,544
private function clean ( string $ actual , string $ peticion ) { $ this -> buffer1 -> addAll ( explode ( '/' , substr ( $ actual , 1 , strlen ( $ actual ) ) ) ) ; $ this -> buffer2 -> addAll ( explode ( '/' , substr ( $ peticion , 1 , strlen ( $ peticion ) ) ) ) ; $ this -> indexes -> each ( function ( $ number ) { $ this -> mybuffer -> add ( substr ( $ this -> buffer1 -> get ( $ number ) , 1 , strlen ( $ this -> buffer1 -> get ( $ number ) ) ) , $ this -> buffer2 -> get ( $ number ) ) ; $ this -> buffer1 -> remove ( $ number ) ; $ this -> buffer2 -> remove ( $ number ) ; } ) ; $ this -> actual = $ this -> buffer1 -> reducer ( function ( $ acumulator , $ current ) { return $ acumulator . '/' . $ current ; } , '' ) ; $ this -> peticion = $ this -> buffer2 -> reducer ( function ( $ acumulator , $ current ) { return $ acumulator . '/' . $ current ; } , '' ) ; $ this -> indexes -> removeAll ( ) ; $ this -> buffer1 -> removeAll ( ) ; $ this -> buffer2 -> removeAll ( ) ; }
Limpiar las ruta de los parametros .
54,545
public function compareRute ( string $ actual , string $ peticion ) : bool { $ this -> identifyIndexes ( $ actual ) ; $ this -> clean ( $ actual , $ peticion ) ; return $ this -> actual === $ this -> peticion ; }
Permite haser una comparacion de las rutas al detalle .
54,546
public function existRutes ( $ actual , $ peticion ) : bool { $ this -> buffer1 -> addAll ( explode ( '/' , substr ( $ actual , 1 , strlen ( $ actual ) ) ) ) ; $ this -> buffer2 -> addAll ( explode ( '/' , substr ( $ peticion , 1 , strlen ( $ peticion ) ) ) ) ; $ temp = $ this -> buffer1 -> lenght ( ) === $ this -> buffer2 -> lenght ( ) ; $ this -> buffer1 -> removeAll ( ) ; $ this -> buffer2 -> removeAll ( ) ; return $ temp ; }
Verifica si existe alguna ruta que se pueda ejecutar
54,547
public function isRoot ( string $ actual , string $ peticion ) : bool { $ temp = false ; if ( $ actual === $ peticion || $ actual . '/' === $ peticion ) { $ temp = true ; } return $ temp ; }
Saber si es la heme page o no .
54,548
public static function validateConstructorArgs ( $ name , $ globalThreshold , $ metric , $ metricFactor , $ componentThreshold , $ components , $ validMetrics ) { if ( ! self :: validateName ( $ name ) ) throw new \ Franzip \ Throttler \ Exceptions \ InvalidArgumentException ( 'Invalid Throttler $name: please supply a valid non-empty string.' ) ; if ( ! self :: validateGlobalThreshold ( $ globalThreshold ) ) throw new \ Franzip \ Throttler \ Exceptions \ InvalidArgumentException ( 'Invalid Throttler $globalThreshold: please supply a positive integer.' ) ; if ( ! self :: validateMetric ( $ metric , $ validMetrics ) ) throw new \ Franzip \ Throttler \ Exceptions \ InvalidArgumentException ( 'Invalid Throttler $metric. Valid choices are "sec", "min", "hrs".' ) ; if ( ! self :: validateMetricFactor ( $ metricFactor ) ) throw new \ Franzip \ Throttler \ Exceptions \ InvalidArgumentException ( 'Invalid Throttler $metricFactor: please supply a positive integer.' ) ; if ( ! self :: validateComponentThreshold ( $ componentThreshold ) ) throw new \ Franzip \ Throttler \ Exceptions \ InvalidArgumentException ( 'Invalid Throttler $componentThreshold: please supply a positive integer or null.' ) ; if ( ! self :: compareThresholds ( $ componentThreshold , $ globalThreshold ) ) throw new \ Franzip \ Throttler \ Exceptions \ InvalidArgumentException ( 'Invalid Throttler $componentThreshold: $componentThreshold must be lower than $globalThreshold.' ) ; if ( ! self :: validateComponents ( $ components ) ) throw new \ Franzip \ Throttler \ Exceptions \ InvalidArgumentException ( 'Invalid Throttler $components: $components must be an array.' ) ; if ( ! self :: validateComponentsName ( $ components ) ) throw new \ Franzip \ Throttler \ Exceptions \ InvalidArgumentException ( 'Invalid Throttler $components: $components entries must be non empty strings.' ) ; }
Validate Throttler constructor args .
54,549
protected function addOptimizableClasses ( ) { $ collection = $ this -> compiler -> run ( ) ; $ this -> displayAddedFiles ( $ collection ) ; $ this -> displayMissingFiles ( $ collection ) ; }
Add list of classes to be optimized .
54,550
protected function displayAddedFiles ( Fluent $ collection ) { if ( $ this -> getOutput ( ) -> getVerbosity ( ) >= OutputInterface :: VERBOSITY_VERY_VERBOSE ) { foreach ( $ collection -> get ( 'added' ) as $ file ) { $ this -> info ( "File added: [{$file}]" ) ; } } }
Display added files .
54,551
protected function displayMissingFiles ( Fluent $ collection ) { if ( $ this -> getOutput ( ) -> getVerbosity ( ) >= OutputInterface :: VERBOSITY_VERBOSE ) { foreach ( $ collection -> get ( 'missing' ) as $ file ) { $ this -> comment ( "File not found: [{$file}]" ) ; } } }
Display missing files .
54,552
public function reset ( $ name = null ) { if ( $ name === 'violations' ) { $ this -> _violations = array ( ) ; } elseif ( $ name === 'warnings' ) { $ this -> _warnings = array ( ) ; } else { $ this -> _violations = array ( ) ; $ this -> _warnings = array ( ) ; } }
Will reset the current list of violations
54,553
public function handle ( ) { $ whoops = new \ Whoops \ Run ( ) ; $ whoops -> pushHandler ( new \ Whoops \ Handler \ PlainTextHandler ( ) ) ; $ whoops -> pushHandler ( new \ Whoops \ Handler \ PrettyPageHandler ( ) ) ; $ whoops -> allowQuit ( false ) ; $ whoops -> writeToOutput ( false ) ; return $ whoops -> handleException ( $ this -> exception ) ; }
Handle an error with Whoops
54,554
protected function _setTemplate ( $ template ) { if ( $ template !== null && ! ( $ template instanceof TemplateInterface ) ) { throw $ this -> _createInvalidArgumentException ( $ this -> __ ( 'Invalid template' ) , null , null , $ template ) ; } $ this -> template = $ template ; }
Assigns the template to this instance ..
54,555
public function init ( ) { if ( ! Yii :: app ( ) -> hasModule ( 'user' ) ) { return false ; } if ( ! Yii :: app ( ) -> getModule ( 'user' ) -> user ( ) ) { return false ; } Yii :: app ( ) -> urlManager -> parseUrl ( Yii :: app ( ) -> getRequest ( ) ) ; $ preferred = null ; if ( isset ( $ _GET [ $ this -> data_key ] ) && preg_match ( '/^\d+$/' , $ _GET [ $ this -> data_key ] ) ) { $ preferred = $ _GET [ $ this -> data_key ] ; if ( ! $ this -> isValidUserCompany ( $ preferred ) ) { throw new CHttpException ( 404 , "Company '{$_GET[$this->data_key ]}' is not available." ) ; } $ this -> _setActiveCompany ( $ preferred ) ; return TRUE ; } if ( $ this -> getActiveCompany ( ) ) { $ preferred = $ this -> getActiveCompany ( ) ; if ( $ this -> isValidUserCompany ( $ preferred ) ) { $ this -> _setActiveCompany ( $ preferred ) ; return TRUE ; } } $ a = $ this -> getClientCompanies ( ) ; if ( empty ( $ a ) ) { throw new CHttpException ( 404 , "For user companies are not available." ) ; } $ this -> _setActiveCompany ( $ a [ 0 ] [ 'ccmp_id' ] ) ; }
Handles company detection and application setting by URL parm specified in DATA_KEY
54,556
public function getClientCompanies ( ) { if ( $ this -> _aUserCompanies === FALSE ) { $ sql = " SELECT DISTINCT ccmp_id, ccmp_name FROM ccuc_user_company INNER JOIN ccmp_company ON ccmp_id = ccuc_ccmp_id WHERE ccuc_person_id = " . Yii :: app ( ) -> getModule ( 'user' ) -> user ( ) -> profile -> person_id . " AND ccuc_status = '" . $ this -> ccuc_status . "' ORDER BY ccmp_name " ; $ this -> _aUserCompanies = Yii :: app ( ) -> db -> createCommand ( $ sql ) -> queryAll ( ) ; } return $ this -> _aUserCompanies ; }
get all client companies
54,557
private function _setActiveCompany ( $ ccmp_id ) { if ( Yii :: app ( ) -> getModule ( 'user' ) -> user ( ) -> profile -> ccmp_id != $ ccmp_id ) { $ sSql = " UPDATE profiles SET " . $ this -> profiles_ccmp_field . " = " . $ ccmp_id . " WHERE user_id = " . Yii :: app ( ) -> getModule ( 'user' ) -> user ( ) -> id ; Yii :: app ( ) -> db -> createCommand ( $ sSql ) -> query ( ) ; } $ this -> _activeCompany = $ ccmp_id ; foreach ( $ this -> getClientCompanies ( ) as $ company ) { if ( $ ccmp_id == $ company [ 'ccmp_id' ] ) { $ sql = " SELECT * FROM ccmp_company inner JOIN cccd_custom_data ON ccmp_id = cccd_ccmp_id WHERE ccmp_id = " . $ ccmp_id . " " ; $ this -> _company_attributes = Yii :: app ( ) -> db -> createCommand ( $ sql ) -> queryRow ( ) ; $ this -> _activeCompanyName = $ this -> _company_attributes [ 'ccmp_name' ] ; return TRUE ; } } throw new CHttpException ( 404 , "For ccmp_id=" . $ ccmp_id . "neatrada nosaukumu" ) ; }
colect active company data and set actice company in user prifle table
54,558
public function checkUA ( $ name ) { if ( empty ( $ this -> _auth_items ) ) { $ this -> getAuthItemChild ( ) ; } return isset ( $ this -> _auth_items [ $ name ] ) ; }
chek user access
54,559
public function Set ( $ name , $ value , $ expiry = self :: OneYear , $ path = '/' , $ domain = false ) { $ retval = false ; if ( ! headers_sent ( ) ) { if ( $ domain === false ) $ domain = $ _SERVER [ 'HTTP_HOST' ] ; if ( $ expiry === - 1 ) $ expiry = 1893456000 ; elseif ( is_numeric ( $ expiry ) ) $ expiry += time ( ) ; else $ expiry = strtotime ( $ expiry ) ; $ retval = setcookie ( $ name , $ value , $ expiry , $ path , $ domain ) ; if ( $ retval ) $ _COOKIE [ $ name ] = $ value ; } return $ retval ; }
Set a cookie . Silently does nothing if headers have already been sent .
54,560
public function execute ( $ cmd , array $ projects , BufferedOutputInterface $ output ) { foreach ( $ projects as $ name => $ data ) { $ project = new Project ( $ name , $ data [ 'path' ] ) ; if ( ! empty ( $ data [ 'foreground_color' ] ) ) { $ project -> setForegroundColor ( $ data [ 'foreground_color' ] ) ; } else { $ project -> setForegroundColor ( $ this -> getRandomColorCode ( ) ) ; } if ( ! empty ( $ data [ 'background_color' ] ) ) { $ project -> setBackgroundColor ( $ data [ 'background_color' ] ) ; } $ projects [ $ name ] = $ project ; } $ this -> executeStrategy = $ this -> factory -> createCombinedOutputDisplayStrategy ( ) ; $ this -> executeStrategy -> execute ( $ cmd , $ projects , $ output ) ; }
Executes a shell command asynchronously in all registered projects .
54,561
private function getRandomColorCode ( ) { do { $ colorCode = rand ( 0 , 255 ) ; } while ( in_array ( $ colorCode , $ this -> usedColorCodes ) ) ; $ this -> usedColorCodes [ ] = $ colorCode ; return $ colorCode ; }
Returns a random not yet used color code .
54,562
public function copy ( $ source ) { if ( ! array_key_exists ( $ source , $ this -> getCatalog ( ) ) ) { throw new SkeletonException ( 'Invalid source file' ) ; } $ target = $ this -> getCatalog ( ) [ $ source ] ; if ( ! $ this -> canICopyTo ( $ target ) ) { throw new SkeletonException ( 'Target is not writable' ) ; } $ this -> makeDir ( $ target ) ; if ( ! copy ( $ source , $ target ) ) { throw new SkeletonException ( 'Error while copying file' ) ; } return $ this ; }
Copy declared resources to Composer project
54,563
protected function allWarehouseContent ( ) { $ warehouseContent = new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $ this -> getWarehousePath ( ) ) ) ; $ warehouseContent = iterator_to_array ( $ warehouseContent ) ; $ warehouseContent = array_map ( function ( SplFileInfo $ file ) { return $ file -> getPathname ( ) ; } , $ warehouseContent ) ; return $ warehouseContent ; }
Generates an array of all directories and files in warehouse dir
54,564
protected function toBasePath ( $ warehouseFilePath ) { $ target = $ this -> getBasePath ( ) ; $ target .= DIRECTORY_SEPARATOR ; $ target .= str_replace ( $ this -> getWarehousePath ( ) , '' , $ warehouseFilePath ) ; return $ target ; }
Replaces warehouse path to base path this allow to change a source path to a target path .
54,565
protected function canICopyTo ( $ target ) { $ fileExists = file_exists ( $ target ) ; $ emptyFile = $ fileExists ? filesize ( $ target ) === 0 : false ; return ( ! $ fileExists || $ emptyFile ) ; }
Returns true if target file doesn t exist or if it s empty therefore the file can be safely written or overwritten .
54,566
protected function retrieveWarehousePath ( ) { foreach ( self :: WAREHOUSE_DIRS as $ candidate ) { $ warehousePath = sprintf ( $ candidate , $ this -> getBasePath ( ) ) ; if ( is_dir ( $ warehousePath ) ) { return $ warehousePath ; } } throw new SkeletonException ( 'Cannot locate warehouse dir' ) ; }
Returns the location of warehouse directory
54,567
public static function fromArray ( array $ data ) { $ config = isset ( $ data [ 'config' ] ) ? $ data [ 'config' ] : [ ] ; return new static ( $ data [ 'name' ] , $ data [ 'pluralName' ] , $ data [ 'uri' ] , $ config ) ; }
Constructs the Taxonomy from an array of data
54,568
public function getGroups ( $ area , $ locale ) { return $ this -> model -> where ( 'area' , $ area ) -> whereHas ( 'language' , function ( $ query ) use ( $ locale ) { $ query -> where ( 'code' , $ locale ) ; } ) -> groupBy ( 'group' ) -> orderBy ( 'group' , 'desc' ) -> get ( ) ; }
get translation groups
54,569
public function getList ( $ area , $ locale ) { $ model = $ this -> app -> make ( $ this -> model ( ) ) ; $ group = str_replace ( [ "\n" , "\r" , ' ' ] , '' , $ this -> app -> make ( 'languages' ) -> getTranslationNamedGroup ( ) ) ; return $ model -> where ( 'area' , $ area ) -> where ( function ( $ query ) use ( $ locale , $ group ) { $ query -> where ( 'locale' , $ locale ) ; if ( strlen ( $ group ) > 0 ) { $ query -> where ( 'group' , $ group ) ; } } ) ; }
get translations by type and locale
54,570
public function importTranslations ( $ path , $ type ) { $ separator = app ( 'config' ) -> get ( 'antares/translations::export.separator' ) ; $ content = explode ( PHP_EOL , file_get_contents ( $ path ) ) ; $ list = [ ] ; foreach ( $ content as $ index => $ line ) { if ( $ index == 0 ) { continue ; } array_push ( $ list , explode ( $ separator , $ line ) ) ; } $ locale = $ list [ 0 ] [ 1 ] ; $ language = Languages :: where ( 'code' , $ locale ) -> first ( ) ; try { DB :: transaction ( function ( ) use ( $ language , $ list , $ type ) { $ area = request ( ) -> segment ( 6 ) ; DB :: table ( 'tbl_translations' ) -> where ( 'lang_id' , $ language -> id ) -> where ( 'area' , $ area ) -> delete ( ) ; $ insert = [ ] ; foreach ( $ list as $ item ) { if ( ! isset ( $ item [ 2 ] ) or ! isset ( $ item [ 3 ] ) ) { continue ; } try { $ value = iconv ( 'WINDOWS-1250' , 'UTF-8' , $ item [ 3 ] ) ; } catch ( Exception $ ex ) { $ value = $ item [ 3 ] ; } $ insert [ ] = [ 'locale' => $ language -> code , 'area' => $ area , 'group' => 'antares/' . $ item [ 0 ] , 'lang_id' => $ language -> id , 'key' => trim ( $ item [ 2 ] , '"' ) , 'value' => trim ( $ value , '"' ) , ] ; } DB :: table ( 'tbl_translations' ) -> insert ( $ insert ) ; } ) ; return true ; } catch ( Exception $ e ) { Log :: warning ( $ e ) ; return false ; } }
saves translations in database
54,571
public function deleteByCollection ( $ langId , $ area , $ list ) { if ( empty ( $ list ) ) { return ; } foreach ( $ list as $ group => $ element ) { DB :: table ( 'tbl_translations' ) -> where ( 'lang_id' , $ langId ) -> where ( 'group' , $ group ) -> where ( 'area' , $ area ) -> where ( 'key' , key ( $ element ) ) -> where ( 'value' , current ( $ element ) ) -> delete ( ) ; } return true ; }
delete translations using collection
54,572
public function updateTranslations ( $ params , $ type ) { if ( is_null ( $ translations = array_get ( $ params , 'name' ) ) ) { return false ; } try { DB :: transaction ( function ( ) use ( $ translations , $ type ) { foreach ( $ translations as $ id => $ value ) { $ where = [ 'id' => $ id , 'area' => $ type ] ; $ model = $ this -> makeModel ( ) -> newQuery ( ) -> where ( $ where ) -> first ( ) ; $ model -> value = $ value ; $ model -> save ( ) ; } } ) ; return true ; } catch ( Exception $ ex ) { Log :: emergency ( $ ex ) ; return false ; } }
mass update translations
54,573
public function getCategories ( $ id , $ locale ) { $ groups = $ this -> getGroups ( $ id , $ locale ) -> toArray ( ) ; $ available = antares ( 'memory' ) -> get ( 'extensions.available' ) ; $ list = [ 'all' => 'All' , 'foundation' => trans ( 'Core' ) ] ; array_walk ( $ groups , function ( $ item ) use ( $ available , & $ list ) { $ group = str_replace ( 'antares/' , '' , $ item [ 'group' ] ) ; foreach ( $ available as $ extension ) { if ( $ group == $ extension [ 'name' ] ) { $ list [ $ group ] = $ extension [ 'full_name' ] ; } } } ) ; $ return = [ 'all' => 'All' , 'core' => [ 'label' => trans ( 'antares/translations::messages.group.core' ) , 'extensions' => [ ] ] , 'configuration' => [ 'label' => trans ( 'antares/translations::messages.group.configuration' ) , 'extensions' => [ ] ] , ] ; foreach ( $ list as $ name => $ value ) { if ( in_array ( $ name , [ 'foundation' , 'widgets' , 'search' , 'control' ] ) ) { $ return [ 'core' ] [ 'extensions' ] [ $ name ] = $ value ; } elseif ( in_array ( $ name , [ 'two_factor_auth' , 'api' ] ) ) { $ return [ 'configuration' ] [ 'extensions' ] [ $ name ] = $ value ; } else { $ return [ $ name ] = $ value ; } } return $ return ; }
Gets translation categories
54,574
public function count ( $ area , $ locale ) { return $ this -> makeModel ( ) -> newQuery ( ) -> where ( [ 'area' => $ area , 'locale' => $ locale ] ) -> count ( ) ; }
Counts translations by area
54,575
public function setPageStructure ( array $ structure ) { foreach ( $ structure as $ _ref ) { HtmlHelper :: getNewId ( $ _ref , true ) ; } $ this -> registry -> setEntry ( 'page_structure' , $ structure ) ; return $ this ; }
Set the page structure
54,576
public function setToTemplate ( $ var , $ val ) { $ args = func_get_args ( ) ; array_shift ( $ args ) ; $ this -> templateFallback ( $ var , $ args , 'set' ) ; return $ this ; }
Set to Template object
54,577
public function templateFallback ( $ name , array $ args = array ( ) , $ fallback = null ) { return $ this -> _runFallbackMethod ( $ this -> template , $ name , $ args , ( $ this -> getFlags ( ) & TemplateEngine :: THROW_TEMPLATE_ERRORS ) , $ fallback ) ; }
Fallback system to call a Template object s method
54,578
public function setToView ( $ var , $ val ) { $ args = func_get_args ( ) ; array_shift ( $ args ) ; $ this -> viewFallback ( $ var , $ args , 'set' ) ; return $ this ; }
Set to View object
54,579
public function viewFallback ( $ name , array $ args = array ( ) , $ fallback = null ) { return $ this -> _runFallbackMethod ( $ this -> view , $ name , $ args , ( $ this -> getFlags ( ) & TemplateEngine :: THROW_VIEW_ERRORS ) , $ fallback ) ; }
Fallback system to call a View object s method
54,580
public function useAssetsPreset ( $ preset_name = null ) { $ preset = $ this -> assets_loader -> getPreset ( $ preset_name ) ; $ preset -> load ( ) ; }
Automatic assets loading from an Assets preset declare in a composer . json
54,581
public function includePackagesViewsFunctions ( ) { $ _assets_package = Package :: createFromAssetsLoader ( $ this -> assets_loader ) ; foreach ( $ this -> assets_loader -> getAssetsDb ( ) as $ package => $ config ) { if ( ! empty ( $ config [ 'views_functions' ] ) ) { $ assets_package = clone $ _assets_package ; $ assets_package -> loadFromArray ( $ config ) ; foreach ( $ assets_package -> getViewsFunctionsPaths ( ) as $ fcts ) { $ fct_file = $ assets_package -> getFullPath ( $ fcts ) ; if ( @ file_exists ( $ fct_file ) ) { @ include_once $ fct_file ; } } } } }
Automatic loading of assets views functions
54,582
protected function _prepareRendering ( ) { $ this -> view -> addDefaultViewParam ( '_template' , $ this ) ; $ structure = $ this -> getPageStructure ( ) ; if ( empty ( $ structure ) ) { $ this -> setPageStructure ( self :: $ default_page_structure ) ; } }
Required settings before rendering
54,583
public function renderLayout ( $ view = null , array $ params = array ( ) , $ display = false , $ exit = false ) { if ( is_null ( $ view ) ) { $ view = $ this -> getPageLayout ( ) ; } return $ this -> render ( $ view , $ params , $ display , $ exit ) ; }
Rendering of a layout
54,584
protected function _getFallbackMethod ( $ varname , array $ arguments = array ( ) , $ throw_errors = false , $ fallback = null ) { $ var = $ this -> _getFallbackVarname ( $ varname ) ; $ template_val = $ this -> _runFallbackMethod ( $ this -> template , $ var , $ arguments , $ throw_errors , $ fallback ) ; if ( ! empty ( $ template_val ) ) { return $ template_val ; } $ view_val = $ this -> _runFallbackMethod ( $ this -> view , $ var , $ arguments , $ throw_errors , $ fallback ) ; if ( ! empty ( $ view_val ) ) { return $ view_val ; } return null ; }
Process a fallback method on Template and View and returns the result
54,585
protected function _getFallbackVarname ( $ name ) { if ( false === strpos ( $ name , '_' ) ) { return $ name ; } $ parts = explode ( '_' , $ name ) ; $ str = '' ; foreach ( $ parts as $ _part ) { $ str .= strlen ( $ str ) ? ucfirst ( $ _part ) : $ _part ; } return $ str ; }
Get a variable name in CamelCase
54,586
protected function _runFallbackMethod ( $ object , $ varname , array $ arguments = array ( ) , $ throw_errors = false , $ fallback = null ) { if ( property_exists ( $ object , $ varname ) ) { try { $ object -> { $ varname } = $ args ; return $ object ; } catch ( \ Exception $ e ) { } } if ( method_exists ( $ object , $ varname ) ) { try { $ val = call_user_func_array ( array ( $ object , $ varname ) , $ arguments ) ; return $ val ; } catch ( \ Exception $ e ) { } } if ( ! empty ( $ fallback ) ) { $ _meth = $ fallback . ucfirst ( $ varname ) ; if ( method_exists ( $ object , $ _meth ) ) { try { $ val = call_user_func_array ( array ( $ object , $ _meth ) , $ arguments ) ; return $ val ; } catch ( \ Exception $ e ) { } } } if ( $ throw_errors ) { if ( ! empty ( $ _meth ) ) { $ msg = sprintf ( 'Neither variable "%s" nor method "%s" or "%s" were found in object "%s"!' , $ varname , $ varname , $ _meth , get_class ( $ object ) ) ; } else { $ msg = sprintf ( 'Neither variable "%s" nor method "%s" were found in object "%s"!' , $ varname , $ varname , get_class ( $ object ) ) ; } throw new TemplateEngineException ( $ msg ) ; } return null ; }
Process a fallback method on an object
54,587
public function offsetExists ( $ offset ) { $ val = $ this -> registry -> getEntry ( $ offset , null ) ; if ( empty ( $ val ) ) { $ val = $ this -> _getFallbackMethod ( $ offset , array ( ) , false , 'get' ) ; } return ( bool ) null !== $ val ; }
Check existence of a variable by array access to the TemplateEngine
54,588
public function offsetGet ( $ offset ) { $ val = $ this -> registry -> getEntry ( $ offset , null ) ; if ( empty ( $ val ) ) { $ val = $ this -> _getFallbackMethod ( $ offset , array ( ) , false , 'get' ) ; } return $ val ; }
Get a variable by array access to the TemplateEngine
54,589
public function setAssetsLoader ( AssetsLoader $ loader ) { $ this -> assets_loader = $ loader ; $ assets_db = $ this -> assets_loader -> getAssets ( ) ; if ( ! empty ( $ assets_db ) ) { $ _assets_package = Package :: createFromAssetsLoader ( $ this -> assets_loader ) ; foreach ( $ assets_db as $ package => $ config ) { if ( ! empty ( $ config [ 'views_path' ] ) ) { $ assets_package = clone $ _assets_package ; $ assets_package -> loadFromArray ( $ config ) ; foreach ( $ assets_package -> getViewsPaths ( ) as $ path ) { $ full_path = $ assets_package -> getFullPath ( $ path ) ; if ( @ file_exists ( $ full_path ) ) { $ this -> setToView ( 'setIncludePath' , $ full_path ) ; } } } } } return $ this ; }
Set the object Assets Loader instance
54,590
public function guessFromAssetsLoader ( AssetsLoader $ loader ) { $ this -> setAssetsLoader ( $ loader ) ; $ this -> setLayoutsDir ( $ this -> assets_loader -> getAssetsRealPath ( ) ) -> setToTemplate ( 'setWebRootPath' , $ this -> assets_loader -> getAssetsWebPath ( ) ) -> setToView ( 'addDefaultViewParam' , 'assets' , $ this -> assets_loader -> getAssetsWebPath ( ) ) -> setToTemplate ( 'setWebRootPath' , $ this -> assets_loader -> getDocumentRoot ( ) ) ; return $ this ; }
Set the object Assets Loader instance and dispatch required template envionement
54,591
public static function __error ( $ message = 'View error' , $ file = null , $ line = null ) { if ( ! is_null ( $ file ) ) { $ message .= sprintf ( ' in file "%s"' , $ file ) ; if ( ! is_null ( $ line ) ) { $ message .= sprintf ( ' at line %s' , $ line ) ; } } trigger_error ( $ message , E_USER_WARNING ) ; }
Write a simple error during view rendering
54,592
public static function __closurable ( $ value , array $ arguments = array ( ) ) { if ( is_callable ( $ value ) ) { try { $ val = call_user_func_array ( $ value , $ arguments ) ; return $ val ; } catch ( Exception $ e ) { self :: __error ( sprintf ( 'Closure error: "%s"!' , $ e -> getMessage ( ) ) , $ e -> getFile ( ) , $ e -> getLine ( ) ) ; } } else { return $ value ; } }
Try to execute a closure sending an error if necessary
54,593
public static function __string ( $ value , $ glue = ', ' ) { if ( is_object ( $ value ) ) { if ( method_exists ( $ value , '__toString' ) ) { return $ value -> __toString ( ) ; } if ( $ value instanceof ArrayAccess ) { return implode ( $ glue , $ value ) ; } return get_class ( $ value ) ; } elseif ( is_array ( $ value ) ) { return implode ( $ glue , $ value ) ; } elseif ( is_bool ( $ value ) ) { return ( true === $ value ? 'true' : 'false' ) ; } elseif ( is_callable ( $ value ) ) { return self :: __closurable ( $ value ) ; } return ( string ) $ value ; }
Get safely a string from any kind of variable
54,594
public function navigate ( ) { if ( $ this -> url ) { $ this -> session -> url ( $ this -> url ) ; } else { $ this -> session -> navigate ( $ this -> presenterName , $ this -> presenterParameters ) ; } return $ this ; }
Navigates to this page .
54,595
public function checkState ( ) { if ( $ this -> url ) { if ( ( $ actualUrl = $ this -> session -> url ( ) ) !== $ this -> url ) { throw new ViewStateException ( __METHOD__ . ": URL '$this->url' was expected, actual URL is '$actualUrl'." ) ; } } else { $ appRequest = $ this -> session -> appRequest ; if ( $ appRequest -> presenterName !== $ this -> presenterName ) { throw new ViewStateException ( __METHOD__ . ": Presenter '$this->presenterName' was expected, actual presenter is '$appRequest->presenterName'." ) ; } foreach ( Utils :: strToArray ( $ this -> presenterParameters ) as $ name => $ value ) { if ( $ appRequest -> parameters [ $ name ] !== $ value ) { throw new ViewStateException ( __METHOD__ . ": Parameter '$name' is expected to be '$value', but is '{$appRequest->parameters[$name]}'." ) ; } } } }
Checks that this page is open in the browser .
54,596
public function run ( Job $ job ) { $ this -> logger -> info ( 'Starting Job: ' . $ job -> id . ' | ' . $ job -> command ) ; $ callback = array ( $ this , 'notifyExecutionEnd' ) ; $ runner = $ this -> getJobRunner ( $ job ) ; if ( $ this -> hasDependency ( $ job ) ) { $ job_dep = $ this -> getDependency ( $ job ) ; if ( $ job_dep -> exit_code == self :: EXIT_CODE_NORMAL && $ this -> isValid ( $ job_dep ) ) { $ this -> logger -> info ( 'Job has dependency and his dependency is OK | dependency: ' . $ job_dep -> id . ' | ' . $ job_dep -> command ) ; $ job -> status_code = 1 ; $ this -> execute ( $ job , $ runner , $ callback ) ; } else if ( $ this -> isRunning ( $ job_dep ) || $ this -> isWaiting ( $ job ) ) { $ this -> logger -> info ( 'Job has dependency and his dependency is working | dependency: ' . $ job_dep -> id . ' | ' . $ job_dep -> command ) ; $ job -> status_code = 4 ; $ this -> execute ( $ job , $ runner , $ callback ) ; } else { $ this -> logger -> error ( 'Job has dependency and his dependency get some error, aborting | dependency: ' . $ job_dep -> id . ' | ' . $ job_dep -> command ) ; $ job -> status_code = 2 ; } } else { $ job -> status_code = 1 ; $ this -> execute ( $ job , $ runner , $ callback ) ; } }
Runs a single command
54,597
private function execute ( Job $ job , JobRunner $ runner , $ callback ) { $ runner -> runIt ( $ job , $ callback ) ; }
Just run the job
54,598
public function Contains ( $ path = '' , $ async = FALSE , $ defer = FALSE , $ doNotMinify = FALSE ) { $ result = FALSE ; $ scriptsGroup = & $ this -> _getScriptsGroupContainer ( $ this -> actualGroupName ) ; foreach ( $ scriptsGroup as & $ item ) { if ( $ item -> path == $ path ) { if ( $ item -> async == $ async && $ item -> defer == $ defer && $ item -> doNotMinify == $ doNotMinify ) { $ result = TRUE ; break ; } } } return $ result ; }
Check if script is already presented in scripts group
54,599
public function AppendExternal ( $ path = '' , $ async = FALSE , $ defer = FALSE , $ doNotMinify = FALSE ) { return $ this -> Append ( $ path , $ async , $ defer , $ doNotMinify , TRUE ) ; }
Append script after all group scripts for later render process with downloading external content