idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
45,600
public function setAliasId ( ) { $ url = parse_url ( $ this -> getUrl ( ) , PHP_URL_PATH ) ; if ( $ url ) { $ this -> aliasId = md5 ( $ url ) ; } }
Set Alias Id .
45,601
protected function getElementValue ( Model $ model , NamedFormElement $ el ) { $ attribute = $ el -> getModelAttributeKey ( ) ; if ( strpos ( $ attribute , '->' ) === false ) { return $ model -> getAttribute ( $ attribute ) ; } $ casts = collect ( $ model -> getCasts ( ) ) ; $ jsonParts = collect ( explode ( '->' , $ a...
Returns value from model for given element .
45,602
protected function forEachElement ( Collection $ elements , $ callback ) { foreach ( $ this -> flatNamedElements ( $ elements ) as $ element ) { $ callback ( $ element ) ; } }
Applies given callback to every element of form .
45,603
protected function flatNamedElements ( Collection $ elements ) { return $ elements -> reduce ( function ( Collection $ initial , $ element ) { if ( $ element instanceof NamedFormElement ) { $ initial -> push ( $ element ) ; } elseif ( $ element instanceof FormElements ) { return $ initial -> merge ( $ this -> flatNamed...
Returns flat collection of elements in form ignoring everything but NamedFormElement . Works recursive .
45,604
public function save ( Request $ request ) { $ connection = app ( \ Illuminate \ Database \ ConnectionInterface :: class ) ; $ this -> prepareRelatedValues ( $ this -> getRequestData ( ) ) ; $ this -> transactionLevel = $ connection -> transactionLevel ( ) ; $ connection -> beginTransaction ( ) ; }
Saves request .
45,605
public function exceedsLimit ( ) { if ( $ this -> limit === null ) { return false ; } return $ this -> relatedValues -> count ( ) >= $ this -> limit ; }
Checks if count of relations to be created exceeds limit .
45,606
protected function addOrGetRelated ( $ key ) { $ related = $ this -> relatedValues -> get ( $ key ) ?? $ this -> getFreshModelForElements ( ) ; if ( ! $ related -> exists && ! $ this -> exceedsLimit ( ) ) { $ this -> relatedValues -> put ( $ key , $ related ) ; } return $ related ; }
Appends fresh related model if total count is not exceeding limit .
45,607
protected function getValueFromObject ( $ instance , $ name ) { if ( $ name instanceof Closure ) { return $ name ( $ instance ) ; } if ( strpos ( $ name , '.' ) === false && strpos ( $ name , '->' ) !== false ) { $ casts = collect ( $ instance -> getCasts ( ) ) ; $ jsonParts = collect ( explode ( '->' , $ name ) ) ; $ ...
Get column value from instance .
45,608
protected function registerWidgets ( ) { $ widgetsRegistry = $ this -> app [ WidgetsRegistryInterface :: class ] ; foreach ( $ this -> widgets as $ widget ) { $ widgetsRegistry -> registerWidget ( $ widget ) ; } }
Global register widgets .
45,609
protected function registerMessages ( ) { $ messageTypes = [ 'error' => ErrorMessages :: class , 'info' => InfoMessages :: class , 'success' => SuccessMessages :: class , 'warning' => WarningMessages :: class , ] ; foreach ( $ messageTypes as $ messageType ) { $ this -> app [ WidgetsRegistryInterface :: class ] -> regi...
Global register messages of adminpanel .
45,610
protected function registerBootstrap ( ) { $ directory = $ this -> getBootstrapPath ( ) ; if ( ! is_dir ( $ directory ) ) { return ; } $ files = Finder :: create ( ) -> files ( ) -> name ( '/^.+\.php$/' ) -> notName ( 'routes.php' ) -> notName ( 'navigation.php' ) -> in ( $ directory ) -> sort ( function ( SplFileInfo ...
Register bootstrap file .
45,611
protected function registerCustomRoutes ( ) { if ( file_exists ( $ file = $ this -> getBootstrapPath ( 'routes.php' ) ) ) { $ this -> registerRoutes ( function ( Router $ route ) use ( $ file ) { require $ file ; } ) ; } }
Register Custom Routes From Users .
45,612
protected function registerDefaultRoutes ( ) { $ this -> registerRoutes ( function ( Router $ router ) { ( new ModelRouter ( $ this -> app , $ router ) ) -> register ( $ this -> app [ 'sleeping_owl' ] -> getModels ( ) ) ; if ( file_exists ( $ routesFile = __DIR__ . '/../Http/routes.php' ) ) { require $ routesFile ; } A...
Register Default Admin Routes .
45,613
protected function registerSupportRoutes ( ) { $ domain = config ( 'sleeping_owl.domain' , false ) ; $ middlewares = collect ( $ this -> getConfig ( 'middleware' ) ) ; $ configGroup = collect ( [ 'prefix' => $ this -> getConfig ( 'url_prefix' ) , 'middleware' => $ middlewares , ] ) ; if ( $ domain ) { $ configGroup -> ...
Register CKEditor Upload and D&D plugins .
45,614
protected function registerNavigationFile ( ) { if ( file_exists ( $ navigation = $ this -> getBootstrapPath ( 'navigation.php' ) ) ) { $ items = include $ navigation ; if ( is_array ( $ items ) ) { $ this -> app [ 'sleeping_owl.navigation' ] -> setFromArray ( $ items ) ; } } }
Register navigation file .
45,615
protected function isEditable ( ) { return $ this -> editable && ! $ this -> isTrashed ( ) && $ this -> getModelConfiguration ( ) -> isEditable ( $ this -> getModel ( ) ) ; }
Check if instance editable .
45,616
protected function isDeletable ( ) { return $ this -> deletable && ! $ this -> isTrashed ( ) && $ this -> getModelConfiguration ( ) -> isDeletable ( $ this -> getModel ( ) ) ; }
Check if instance is deletable .
45,617
protected function isDestroyable ( ) { return $ this -> destroyable && $ this -> isTrashed ( ) && $ this -> getModelConfiguration ( ) -> isDestroyable ( $ this -> getModel ( ) ) ; }
Check if instance is force deletable .
45,618
protected function isRestorable ( ) { return $ this -> restorable && $ this -> isTrashed ( ) && $ this -> getModelConfiguration ( ) -> isRestorable ( $ this -> getModel ( ) ) ; }
Check if instance is restorable .
45,619
public function setAliasesId ( Collection $ pages ) { $ pages -> each ( function ( PageInterface $ page ) { $ page -> setAliasId ( ) ; if ( $ page -> getPages ( ) -> count ( ) ) { $ this -> setAliasesId ( $ page -> getPages ( ) ) ; } } ) ; }
Set Alias Id to Page .
45,620
protected function detectType ( ) { $ model = $ this -> getModel ( ) ; $ traits = trait_uses_recursive ( $ model ) ; $ type = SimpleTreeType :: class ; if ( $ model instanceof \ Baum \ Node ) { $ type = BaumNodeType :: class ; } elseif ( class_exists ( 'Kalnoy\Nestedset\Node' ) && $ model instanceof \ Kalnoy \ Nestedse...
Detect tree type .
45,621
public function initialize ( ) { parent :: initialize ( ) ; $ this -> setHtmlAttribute ( 'data-type' , 'range' ) ; $ this -> setHtmlAttribute ( 'class' , 'column-filter' ) ; $ this -> getFrom ( ) -> initialize ( ) ; $ this -> getTo ( ) -> initialize ( ) ; $ this -> getFrom ( ) -> removeHtmlAttribute ( 'data-type' ) ; $...
Initialize column filter .
45,622
public function initialize ( ) { $ this -> initializeElements ( ) ; $ tabs = $ this -> getTabs ( ) ; foreach ( $ tabs as $ tab ) { if ( method_exists ( $ tab -> getContent ( ) , 'getElements' ) ) { $ elements = $ tab -> getContent ( ) -> getElements ( ) ; foreach ( $ elements as $ element ) { if ( $ element instanceof ...
Initialize tabbed interface .
45,623
protected function getChildren ( $ collection , $ id ) { $ parentField = $ this -> repository -> getParentField ( ) ; $ result = [ ] ; foreach ( $ collection as $ instance ) { if ( ( int ) $ instance -> $ parentField != $ id ) { continue ; } $ instance -> setRelation ( 'children' , $ this -> getChildren ( $ collection ...
Get children for simple tree type structure .
45,624
public function toArray ( ) { return [ 'asset_dir' => $ this -> assetDir ( ) , 'view_namespace' => $ this -> getViewNamespace ( ) , 'name' => $ this -> name ( ) , 'version' => $ this -> version ( ) , 'homepage' => $ this -> homepage ( ) , ] ; }
Render func .
45,625
public function unique ( array $ columns , string $ message = null ) { $ this -> initializeUniqueValidator ( $ message ) ; $ this -> unique = $ columns ; return $ this ; }
Columns that should be unique .
45,626
protected static function getFiles ( $ file ) { if ( empty ( $ file ) ) { throw new InvalidArgumentException ( 'There is not any file defined' ) ; } if ( is_string ( $ file ) ) { if ( ! is_file ( $ file ) ) { throw new InvalidArgumentException ( "'$file' is not a valid file" ) ; } if ( ! is_readable ( $ file ) ) { thro...
Checks and returns all files .
45,627
protected static function readFile ( $ file ) { $ length = filesize ( $ file ) ; if ( ! ( $ fd = fopen ( $ file , 'rb' ) ) ) { throw new Exception ( "Cannot read the file '$file', probably permissions" ) ; } $ content = $ length ? fread ( $ fd , $ length ) : '' ; fclose ( $ fd ) ; return $ content ; }
Reads and returns the content of a file .
45,628
public static function generate ( Translations $ translations , array $ options = [ ] ) { $ options += static :: $ options ; return self :: toArray ( $ translations , $ options [ 'includeHeaders' ] , true ) ; }
Generates an array with the translations .
45,629
public function getClone ( $ context = null , $ original = null ) { $ new = clone $ this ; if ( $ context !== null ) { $ new -> context = ( string ) $ context ; } if ( $ original !== null ) { $ new -> original = ( string ) $ original ; } return $ new ; }
Clones this translation .
45,630
public function is ( $ context , $ original = '' ) { return ( ( $ this -> context === $ context ) && ( $ this -> original === $ original ) ) ? true : false ; }
Checks whether the translation matches with the arguments .
45,631
public function addReference ( $ filename , $ line = null ) { $ key = "{$filename}:{$line}" ; $ this -> references [ $ key ] = [ $ filename , $ line ] ; return $ this ; }
Adds a new reference for this translation .
45,632
public function addComment ( $ comment ) { if ( ! in_array ( $ comment , $ this -> comments , true ) ) { $ this -> comments [ ] = $ comment ; } return $ this ; }
Adds a new comment for this translation .
45,633
public function addFlag ( $ flag ) { if ( ! in_array ( $ flag , $ this -> flags , true ) ) { $ this -> flags [ ] = $ flag ; } return $ this ; }
Adds a new flag for this translation .
45,634
public function mergeWith ( Translation $ translation , $ options = Merge :: DEFAULTS ) { Merge :: mergeTranslation ( $ translation , $ this , $ options ) ; Merge :: mergeReferences ( $ translation , $ this , $ options ) ; Merge :: mergeComments ( $ translation , $ this , $ options ) ; Merge :: mergeExtractedComments (...
Merges this translation with other translation .
45,635
private static function fromArray ( array $ messages , Translations $ translations ) { foreach ( $ messages as $ original => $ translation ) { if ( $ original === '' ) { self :: extractHeaders ( $ translation , $ translations ) ; continue ; } $ translations -> insert ( null , $ original ) -> setTranslation ( $ translat...
Extract the entries from a dictionary .
45,636
protected function parsePhpComment ( $ value , $ line ) { if ( $ this -> extractComments === false ) { return null ; } $ comment = ParsedComment :: create ( $ value , $ line ) ; $ prefixes = array_filter ( ( array ) $ this -> extractComments ) ; if ( $ comment && $ comment -> checkPrefixes ( $ prefixes ) ) { return $ c...
Extract the actual text from a PHP comment .
45,637
public function nextArgument ( ) { if ( $ this -> argumentIndex === - 1 ) { $ this -> argumentIndex = 1 ; } else { ++ $ this -> argumentIndex ; } $ this -> argumentStopped = false ; }
Go to the next argument because we a comma was found .
45,638
public function addArgumentChunk ( $ chunk ) { if ( $ this -> argumentStopped === false ) { if ( $ this -> argumentIndex === - 1 ) { $ this -> argumentIndex = 0 ; } if ( isset ( $ this -> arguments [ $ this -> argumentIndex ] ) ) { $ this -> arguments [ $ this -> argumentIndex ] .= $ chunk ; } else { $ this -> argument...
Add a string to the current argument .
45,639
public function addComment ( $ comment ) { if ( $ this -> comments === null ) { $ this -> comments = [ ] ; } $ this -> comments [ ] = $ comment ; }
Add a comment associated to this function .
45,640
public function read ( $ bytes ) { $ data = substr ( $ this -> str , $ this -> pos , $ bytes ) ; $ this -> seekto ( $ this -> pos + $ bytes ) ; return $ data ; }
Read and returns a part of the string .
45,641
public function seekto ( $ pos ) { $ this -> pos = ( $ this -> strlen < $ pos ) ? $ this -> strlen : $ pos ; return $ this -> pos ; }
Move the cursor to a specific position .
45,642
public function loadTranslations ( $ translations ) { if ( is_object ( $ translations ) && $ translations instanceof Translations ) { $ translations = PhpArray :: generate ( $ translations , [ 'includeHeaders' => false ] ) ; } elseif ( is_string ( $ translations ) && is_file ( $ translations ) ) { $ translations = incl...
Loads translation from a Translations instance a file on an array .
45,643
protected function getPluralIndex ( $ domain , $ n , $ fallback ) { if ( ! isset ( $ this -> plurals [ $ domain ] ) || $ fallback === true ) { return $ n == 1 ? 0 : 1 ; } if ( ! isset ( $ this -> plurals [ $ domain ] [ 'function' ] ) ) { $ code = self :: fixTerseIfs ( $ this -> plurals [ $ domain ] [ 'code' ] ) ; $ thi...
Executes the plural decision code given the number to decide which plural version to take .
45,644
public static function create ( $ value , $ line ) { $ lastLine = $ line + substr_count ( $ value , "\n" ) ; $ lines = array_map ( function ( $ line ) { if ( '' === trim ( $ line ) ) { return null ; } $ line = ltrim ( $ line , '#*/ ' ) ; $ line = rtrim ( $ line , '#*/ ' ) ; return trim ( $ line ) ; } , explode ( "\n" ,...
Create new object from raw comment data .
45,645
public function checkPrefixes ( array $ prefixes ) { if ( '' === $ this -> comment ) { return false ; } if ( empty ( $ prefixes ) ) { return true ; } foreach ( $ prefixes as $ prefix ) { if ( strpos ( $ this -> comment , $ prefix ) === 0 ) { return true ; } } return false ; }
Whether the comment matches the required prefixes .
45,646
private static function getScriptTranslationsFromString ( $ scriptContents , Translations $ translations , array $ options = [ ] , $ lineOffset = 0 ) { $ functions = new JsFunctionsScanner ( $ scriptContents ) ; $ options [ 'lineOffset' ] = $ lineOffset ; $ functions -> saveGettextFunctions ( $ translations , $ options...
Extract translations from script part
45,647
private static function getVueAttributeExpressions ( array $ attributePrefixes , DOMElement $ dom , array & $ expressionByLine = [ ] ) { $ children = $ dom -> childNodes ; for ( $ i = 0 ; $ i < $ children -> length ; $ i ++ ) { $ node = $ children -> item ( $ i ) ; if ( ! ( $ node instanceof DOMElement ) ) { continue ;...
Loop DOM element recursively and parse out all dynamic vue attributes which are basically JS expressions
45,648
private static function parseOneTemplateLine ( $ line ) { $ line = trim ( $ line ) ; if ( ! $ line ) { return [ ] ; } $ regex = '#\{\{(.*?)\}\}#' ; preg_match_all ( $ regex , $ line , $ matches ) ; $ matched = array_map ( function ( $ v ) { return trim ( $ v , '\'"{}' ) ; } , $ matches [ 1 ] ) ; return $ matched ; }
Match JS expressions in a template line
45,649
protected function status ( $ match = null ) { $ status = isset ( $ this -> status [ 0 ] ) ? $ this -> status [ 0 ] : null ; if ( $ match !== null ) { return $ status === $ match ; } return $ status ; }
Get the current context of the scan .
45,650
protected static function convertString ( $ value ) { if ( strpos ( $ value , '\\' ) === false ) { return $ value ; } return preg_replace_callback ( '/\\\(n|r|t|v|e|f|"|\\\)/' , function ( $ match ) { switch ( $ match [ 1 ] [ 0 ] ) { case 'n' : return "\n" ; case 'r' : return "\r" ; case 't' : return "\t" ; case 'v' : ...
Decodes a string with an argument .
45,651
private static function toArray ( Translations $ translations , $ includeHeaders , $ forceArray = false ) { $ pluralForm = $ translations -> getPluralForms ( ) ; $ pluralSize = is_array ( $ pluralForm ) ? ( $ pluralForm [ 0 ] - 1 ) : null ; $ messages = [ ] ; if ( $ includeHeaders ) { $ messages [ '' ] = [ '' => [ self...
Returns a multidimensional array .
45,652
private static function fromArray ( array $ messages , Translations $ translations ) { if ( ! empty ( $ messages [ 'domain' ] ) ) { $ translations -> setDomain ( $ messages [ 'domain' ] ) ; } if ( ! empty ( $ messages [ 'plural-forms' ] ) ) { $ translations -> setHeader ( Translations :: HEADER_PLURAL , $ messages [ 'p...
Extract the entries from a multidimensional array .
45,653
public function offsetSet ( $ index , $ value ) { if ( ! ( $ value instanceof Translation ) ) { throw new InvalidArgumentException ( 'Only instances of Gettext\\Translation must be added to a Gettext\\Translations' ) ; } $ id = $ value -> getId ( ) ; if ( $ this -> offsetExists ( $ id ) ) { $ this [ $ id ] -> mergeWith...
Control the new translations added .
45,654
public function setPluralForms ( $ count , $ rule ) { if ( preg_match ( '/[a-z]/i' , str_replace ( 'n' , '' , $ rule ) ) ) { throw new \ InvalidArgumentException ( 'Invalid Plural form: ' . $ rule ) ; } $ this -> setHeader ( self :: HEADER_PLURAL , "nplurals={$count}; plural={$rule};" ) ; return $ this ; }
Set the plural definition .
45,655
public function setHeader ( $ name , $ value ) { $ name = trim ( $ name ) ; $ this -> headers [ $ name ] = trim ( $ value ) ; return $ this ; }
Set a new header .
45,656
public function find ( $ context , $ original = '' ) { if ( $ context instanceof Translation ) { $ id = $ context -> getId ( ) ; } else { $ id = Translation :: generateId ( $ context , $ original ) ; } return $ this -> offsetExists ( $ id ) ? $ this [ $ id ] : false ; }
Search for a specific translation .
45,657
public function mergeWith ( Translations $ translations , $ options = Merge :: DEFAULTS ) { Merge :: mergeHeaders ( $ translations , $ this , $ options ) ; Merge :: mergeTranslations ( $ translations , $ this , $ options ) ; return $ this ; }
Merges this translations with other translations .
45,658
public static function mergeFlags ( Translation $ from , Translation $ to , $ options = self :: DEFAULTS ) { if ( $ options & self :: FLAGS_THEIRS ) { $ to -> deleteFlags ( ) ; } if ( ! ( $ options & self :: FLAGS_OURS ) ) { foreach ( $ from -> getFlags ( ) as $ flag ) { $ to -> addFlag ( $ flag ) ; } } }
Merge the flags of two translations .
45,659
public static function mergeExtractedComments ( Translation $ from , Translation $ to , $ options = self :: DEFAULTS ) { if ( $ options & self :: EXTRACTED_COMMENTS_THEIRS ) { $ to -> deleteExtractedComments ( ) ; } if ( ! ( $ options & self :: EXTRACTED_COMMENTS_OURS ) ) { foreach ( $ from -> getExtractedComments ( ) ...
Merge the extracted comments of two translations .
45,660
public static function mergeComments ( Translation $ from , Translation $ to , $ options = self :: DEFAULTS ) { if ( $ options & self :: COMMENTS_THEIRS ) { $ to -> deleteComments ( ) ; } if ( ! ( $ options & self :: COMMENTS_OURS ) ) { foreach ( $ from -> getComments ( ) as $ comment ) { $ to -> addComment ( $ comment...
Merge the comments of two translations .
45,661
public static function mergeReferences ( Translation $ from , Translation $ to , $ options = self :: DEFAULTS ) { if ( $ options & self :: REFERENCES_THEIRS ) { $ to -> deleteReferences ( ) ; } if ( ! ( $ options & self :: REFERENCES_OURS ) ) { foreach ( $ from -> getReferences ( ) as $ reference ) { $ to -> addReferen...
Merge the references of two translations .
45,662
public static function mergeHeaders ( Translations $ from , Translations $ to , $ options = self :: DEFAULTS ) { if ( $ options & self :: HEADERS_REMOVE ) { foreach ( array_keys ( $ to -> getHeaders ( ) ) as $ name ) { if ( $ from -> getHeader ( $ name ) === null ) { $ to -> deleteHeader ( $ name ) ; } } } foreach ( $ ...
Merge the headers of two translations .
45,663
public function setLanguage ( $ language , $ category = null ) { if ( $ category === null ) { $ category = defined ( 'LC_MESSAGES' ) ? LC_MESSAGES : LC_ALL ; } setlocale ( $ category , $ language ) ; putenv ( 'LANGUAGE=' . $ language ) ; return $ this ; }
Define the current locale .
45,664
public function loadDomain ( $ domain , $ path = null , $ default = true ) { bindtextdomain ( $ domain , $ path ) ; bind_textdomain_codeset ( $ domain , 'UTF-8' ) ; if ( $ default ) { textdomain ( $ domain ) ; } return $ this ; }
Loads a gettext domain .
45,665
protected function getParentClasses ( string $ name ) : array { $ parentClasses = [ ] ; $ parentClasses = $ this -> getReflectionService ( ) -> getParentClasses ( $ name ) ; foreach ( array_reverse ( $ parentClasses ) as $ parentClass ) { if ( $ this -> getDriver ( ) -> isTransient ( $ parentClass ) ) { continue ; } $ ...
Gets an array of parent classes for the given entity class .
45,666
public function addNamespacePrefixes ( array $ prefixes ) : void { $ this -> prefixes = array_merge ( $ this -> prefixes , $ prefixes ) ; $ this -> paths = array_merge ( $ this -> paths , array_keys ( $ prefixes ) ) ; }
Adds Namespace Prefixes .
45,667
public function addExcludePaths ( array $ paths ) : void { $ this -> excludePaths = array_unique ( array_merge ( $ this -> excludePaths , $ paths ) ) ; }
Append exclude lookup paths to metadata driver .
45,668
public static function detectImageDriver ( ) { $ extension = mb_strtolower ( Craft :: $ app -> getConfig ( ) -> getGeneral ( ) -> imageDriver ) ; if ( $ extension === 'gd' ) { self :: $ imageDriver = 'gd' ; } else if ( $ extension === 'imagick' ) { self :: $ imageDriver = 'imagick' ; } else { self :: $ imageDriver = Cr...
Detects which image driver to use
45,669
public function srcset ( $ images , $ descriptor = 'w' ) : string { $ r = '' ; $ generated = [ ] ; if ( ! \ is_array ( $ images ) ) { return '' ; } foreach ( $ images as $ image ) { switch ( $ descriptor ) { case 'w' : if ( ! isset ( $ generated [ $ image -> getWidth ( ) ] ) ) { $ r .= $ image -> getUrl ( ) . ' ' . $ i...
Creates srcset string
45,670
public function isAnimated ( $ asset ) : bool { $ source = new LocalSourceImageModel ( $ asset ) ; $ source -> getLocalCopy ( ) ; if ( $ source -> extension !== 'gif' ) { return false ; } if ( ! ( $ fh = @ fopen ( $ source -> getFilePath ( ) , 'rb' ) ) ) { return false ; } $ count = 0 ; while ( ! feof ( $ fh ) && $ cou...
Checks if asset is animated .
45,671
public function removeTransformsForAsset ( Asset $ asset ) { $ config = self :: getConfig ( ) ; try { $ sourceModel = new LocalSourceImageModel ( $ asset ) ; $ targetModel = new LocalTargetImageModel ( $ sourceModel , [ ] ) ; if ( strpos ( $ targetModel -> path , $ config -> imagerSystemPath ) !== false ) { try { FileH...
Remove transforms for a given asset
45,672
public function deleteImageTransformCaches ( ) { $ path = Plugin :: $ plugin -> getSettings ( ) -> imagerSystemPath ; try { FileHelper :: clearDirectory ( FileHelper :: normalizePath ( $ path ) ) ; } catch ( ErrorException $ e ) { Craft :: error ( 'Could not clear directory "' . $ path . '" (' . $ e -> getMessage ( ) ....
Clear all image transforms caches
45,673
public function deleteRemoteImageCaches ( ) { $ path = Craft :: $ app -> getPath ( ) -> getRuntimePath ( ) . '/imager/' ; try { FileHelper :: clearDirectory ( FileHelper :: normalizePath ( $ path ) ) ; } catch ( ErrorException $ e ) { Craft :: error ( 'Could not clear directory "' . $ path . '" (' . $ e -> getMessage (...
Clear all remote image caches
45,674
private function fillTransforms ( $ transforms ) : array { $ r = [ ] ; $ attributeName = self :: $ transformConfig -> fillAttribute ; $ interval = self :: $ transformConfig -> fillInterval ; $ r [ ] = $ transforms [ 0 ] ; for ( $ i = 1 , $ l = \ count ( $ transforms ) ; $ i < $ l ; $ i ++ ) { $ prevTransform = $ transf...
Fills in the missing transform objects
45,675
private function normalizeTransform ( $ transform ) : array { if ( isset ( $ transform [ 'mode' ] , $ transform [ 'position' ] ) && ( ( $ transform [ 'mode' ] !== 'crop' ) && ( $ transform [ 'mode' ] !== 'croponly' ) ) ) { unset ( $ transform [ 'position' ] ) ; } if ( isset ( $ transform [ 'quality' ] ) ) { $ value = $...
Normalize transform object and values
45,676
public function actionClearTransforms ( ) { $ config = Plugin :: $ plugin -> getSettings ( ) ; $ request = Craft :: $ app -> getRequest ( ) ; $ key = $ request -> getParam ( 'key' , '' ) ; $ setKey = $ config -> clearKey ; if ( $ setKey === '' || $ key != $ setKey ) { throw new \ Exception ( 'Unautorized key' ) ; } Plu...
Controller action to clear image transforms
45,677
public function actionClearRemoteImages ( ) { $ config = Plugin :: $ plugin -> getSettings ( ) ; $ request = Craft :: $ app -> getRequest ( ) ; $ key = $ request -> getParam ( 'key' , '' ) ; $ setKey = $ config -> clearKey ; if ( $ setKey === '' || $ key != $ setKey ) { throw new \ Exception ( 'Unautorized key' ) ; } P...
Controller action to clear remote images
45,678
public function transformImage ( $ file , $ transform , $ transformDefaults = null , $ configOverrides = null ) { $ image = Plugin :: $ plugin -> imager -> transformImage ( $ file , $ transform , $ transformDefaults , $ configOverrides ) ; return $ image ; }
Transforms an image
45,679
public function getDominantColor ( $ image , $ quality = 10 , $ colorValue = 'hex' ) { return Plugin :: $ plugin -> color -> getDominantColor ( $ image , $ quality , $ colorValue ) ; }
Gets the dominant color of an image
45,680
public function getColorPalette ( $ image , $ colorCount = 8 , $ quality = 10 , $ colorValue = 'hex' ) { return Plugin :: $ plugin -> color -> getColorPalette ( $ image , $ colorCount , $ quality , $ colorValue ) ; }
Gets a palette of colors from an image
45,681
public static function getCropSize ( $ originalSize , $ transform , $ allowUpscale ) : Box { $ width = $ originalSize -> getWidth ( ) ; $ height = $ originalSize -> getHeight ( ) ; $ aspect = $ width / $ height ; if ( isset ( $ transform [ 'width' ] , $ transform [ 'height' ] ) ) { $ width = ( int ) $ transform [ 'widt...
Creates the destination crop size box
45,682
private static function enforceMaxSize ( $ width , $ height , $ originalSize , $ maintainAspect , $ zoomFactor = 1.0 ) : array { $ adjustedWidth = $ width ; $ adjustedHeight = $ height ; if ( $ adjustedWidth > $ originalSize -> getWidth ( ) * $ zoomFactor ) { $ adjustedWidth = floor ( $ originalSize -> getWidth ( ) * $...
Enforces a max size if allowUpscale is false
45,683
public static function getCropPoint ( $ resizeSize , $ cropSize , $ position ) : Point { list ( $ leftOffset , $ topOffset ) = explode ( ' ' , $ position ) ; $ leftPos = floor ( $ resizeSize -> getWidth ( ) * ( $ leftOffset / 100 ) ) - floor ( $ cropSize -> getWidth ( ) / 2 ) ; $ topPos = floor ( $ resizeSize -> getHei...
Gets crop point
45,684
public static function getTransformPathForAsset ( $ asset ) : string { try { $ volume = $ asset -> getVolume ( ) ; } catch ( InvalidConfigException $ e ) { \ Craft :: error ( $ e -> getMessage ( ) , __METHOD__ ) ; throw new ImagerException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } $ config = ImagerServic...
Returns the transform path for a given asset .
45,685
public static function getTransformPathForPath ( $ path ) : string { $ config = ImagerService :: getConfig ( ) ; $ hashPath = $ config -> hashPath ; $ pathParts = pathinfo ( $ path ) ; if ( $ hashPath ) { return FileHelper :: normalizePath ( '/' . md5 ( $ pathParts [ 'dirname' ] ) ) ; } return FileHelper :: normalizePa...
Returns the transform path for a given local path .
45,686
public static function getTransformPathForUrl ( $ url ) : string { $ config = ImagerService :: getConfig ( ) ; $ urlParts = parse_url ( $ url ) ; $ pathParts = pathinfo ( $ urlParts [ 'path' ] ) ; $ hashRemoteUrl = $ config -> getSetting ( 'hashRemoteUrl' ) ; $ hashPath = $ config -> getSetting ( 'hashPath' ) ; $ short...
Returns the transform path for a given url .
45,687
public static function createTransformFilestring ( $ transform ) : string { $ r = '' ; foreach ( $ transform as $ k => $ v ) { if ( $ k === 'effects' || $ k === 'preEffects' ) { $ effectString = '' ; foreach ( $ v as $ eff => $ param ) { if ( \ is_array ( $ param ) ) { if ( \ is_array ( $ param [ 0 ] ) ) { $ effectStri...
Creates additional file string that is appended to filename
45,688
public static function normalizeAssetTransformToObject ( $ assetTransform ) : array { $ transformArray = $ assetTransform -> toArray ( ) ; $ validParams = [ 'width' , 'height' , 'format' , 'mode' , 'position' , 'interlace' , 'quality' ] ; $ r = [ ] ; foreach ( $ validParams as $ param ) { if ( isset ( $ transformArray ...
Converts a native asset transform object into an Imager transform .
45,689
public static function moveArrayKeyToPos ( $ key , $ pos , $ arr ) : array { if ( ! isset ( $ arr [ $ key ] ) ) { return $ arr ; } $ tempValue = $ arr [ $ key ] ; unset ( $ arr [ $ key ] ) ; if ( $ pos === 0 ) { return [ $ key => $ tempValue ] + $ arr ; } if ( $ pos > \ count ( $ arr ) ) { return $ arr + [ $ key => $ t...
Moves a named key in an associative array to a given position
45,690
public static function fixSlashes ( $ str , $ removeInitial = false , $ removeTrailing = false ) { $ r = str_replace ( '//' , '/' , $ str ) ; if ( \ strlen ( $ r ) > 0 ) { if ( $ removeInitial && ( $ r [ 0 ] === '/' ) ) { $ r = substr ( $ r , 1 ) ; } if ( $ removeTrailing && ( $ r [ \ strlen ( $ r ) - 1 ] === '/' ) ) {...
Fixes slashes in path
45,691
public function performAction ( ElementQueryInterface $ query ) : bool { $ imagesToPurge = $ query -> kind ( 'image' ) -> all ( ) ; if ( empty ( $ imagesToPurge ) ) { $ this -> setMessage ( Craft :: t ( 'imager' , 'No images to purge' ) ) ; return true ; } $ imagerPlugin = Plugin :: $ plugin ; try { foreach ( $ imagesT...
Purges selected image Assets from Imgix
45,692
public function getDominantColor ( $ image , $ quality , $ colorValue ) { try { $ source = new LocalSourceImageModel ( $ image ) ; $ source -> getLocalCopy ( ) ; } catch ( ImagerException $ e ) { return null ; } $ dominantColor = ColorThief :: getColor ( $ source -> getFilePath ( ) , $ quality ) ; ImagerService :: clea...
Get dominant color of image
45,693
public function getColorPalette ( $ image , $ colorCount , $ quality , $ colorValue ) { try { $ source = new LocalSourceImageModel ( $ image ) ; $ source -> getLocalCopy ( ) ; } catch ( ImagerException $ e ) { return null ; } $ palette = ColorThief :: getPalette ( $ source -> getFilePath ( ) , $ colorCount , $ quality ...
Gets color palette for image
45,694
public static function hex2rgb ( $ hex ) : array { $ hex = str_replace ( '#' , '' , $ hex ) ; if ( \ strlen ( $ hex ) === 3 ) { $ r = hexdec ( $ hex [ 0 ] . $ hex [ 0 ] ) ; $ g = hexdec ( $ hex [ 1 ] . $ hex [ 1 ] ) ; $ b = hexdec ( $ hex [ 2 ] . $ hex [ 2 ] ) ; } else { $ r = hexdec ( $ hex [ 0 ] . $ hex [ 1 ] ) ; $ g...
Convert hex color to rgb
45,695
private function paletteToHex ( $ palette ) : array { $ r = [ ] ; foreach ( $ palette as $ paletteColor ) { $ r [ ] = self :: rgb2hex ( $ paletteColor ) ; } return $ r ; }
Convert palette to array of hex colors
45,696
public function placeholder ( $ config = null ) : string { $ config = array_merge ( $ this -> defaults , $ config ?? [ ] ) ; switch ( $ config [ 'type' ] ) { case 'svg' : return $ this -> placeholderSVG ( $ config ) ; case 'gif' : return $ this -> placeholderGIF ( $ config ) ; case 'silhouette' : return $ this -> place...
Main public placeholder method .
45,697
private function placeholderSVG ( $ config ) : string { $ width = $ config [ 'width' ] ; $ height = $ config [ 'height' ] ; $ color = $ config [ 'color' ] ?? 'transparent' ; return 'data:image/svg+xml;charset=utf-8,' . rawurlencode ( "<svg xmlns='http://www.w3.org/2000/svg' width='$width' height='$height' style='backgr...
Returns a SVG placeholder
45,698
private function placeholderGIF ( $ config ) : string { $ width = $ config [ 'width' ] ; $ height = $ config [ 'height' ] ; $ color = $ config [ 'color' ] ?? 'transparent' ; if ( $ width === 1 && $ height === 1 && $ color === 'transparent' ) { return 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAA...
Returns a GIF placeholder .
45,699
private function placeholderSilhuette ( $ config ) : string { $ source = $ config [ 'source' ] ?? null ; $ size = $ config [ 'size' ] ; $ color = $ config [ 'color' ] ?? '#fefefe' ; $ fgColor = $ config [ 'fgColor' ] ?? '#e0e0e0' ; $ silhouetteType = $ config [ 'silhouetteType' ] ; if ( $ source === null ) { throw new ...
Returns a silhouette placeholder .