| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace kalanis\kw_files_mapper\Processing\MapperNoRoot; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use kalanis\kw_files\FilesException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use kalanis\kw_files\Interfaces\IFLTranslations; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use kalanis\kw_files\Interfaces\IProcessNodes; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use kalanis\kw_files\Traits\TLang; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use kalanis\kw_files_mapper\Support\Process; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use kalanis\kw_mapper\MapperException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use kalanis\kw_mapper\Records\ARecord; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * Class ProcessNode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * @package kalanis\kw_files_mapper\Processing\MapperNoRoot | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * Process nodes in basic ways | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | class ProcessNode implements IProcessNodes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     use TEntryLookup; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     use TLang; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     protected ARecord $record; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 | 7 |  |     public function __construct(ARecord $record, ?Process\Translate $translate = null, ?IFLTranslations $lang = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 7 |  |         $this->setFlLang($lang); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 7 |  |         $this->record = $record; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 7 |  |         $this->setTranslation($translate); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 | 7 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 | 3 |  |     public function exists(array $entry): bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 3 |  |             return !is_null($this->getEntry($entry)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 1 |  |         } catch (MapperException $ex) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 1 |  |             throw new FilesException($ex->getMessage(), $ex->getCode(), $ex); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 1 |  |     public function isReadable(array $entry): bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 1 |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 1 |  |     public function isWritable(array $entry): bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 1 |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 53 | 3 |  |     public function isDir(array $entry): bool | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |         try { | 
            
                                                                        
                            
            
                                    
            
            
                | 56 | 3 |  |             $entry = $this->getEntry($entry); | 
            
                                                                        
                            
            
                                    
            
            
                | 57 | 2 |  |             if (is_null($entry)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 58 | 2 |  |                 return false; | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 60 | 1 |  |             return static::STORAGE_NODE_KEY === strval($entry->__get($this->getTranslation()->getContentKey())); | 
            
                                                                        
                            
            
                                    
            
            
                | 61 | 1 |  |         } catch (MapperException $ex) { | 
            
                                                                        
                            
            
                                    
            
            
                | 62 | 1 |  |             throw new FilesException($ex->getMessage(), $ex->getCode(), $ex); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 3 |  |     public function isFile(array $entry): bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 3 |  |             $entry = $this->getEntry($entry); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 | 2 |  |             if (is_null($entry)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 2 |  |                 return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 1 |  |             return static::STORAGE_NODE_KEY !== strval($entry->__get($this->getTranslation()->getContentKey())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 1 |  |         } catch (MapperException $ex) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 1 |  |             throw new FilesException($ex->getMessage(), $ex->getCode(), $ex); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 3 |  |     public function size(array $entry): ?int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 3 |  |         if (empty($entry)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 1 |  |             return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 | 2 |  |             $entry = $this->getEntry($entry); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 | 1 |  |             if (is_null($entry)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 | 1 |  |                 return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 | 1 |  |             return strlen(strval($entry->__get($this->getTranslation()->getContentKey()))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 | 1 |  |         } catch (MapperException $ex) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 1 |  |             throw new FilesException($ex->getMessage(), $ex->getCode(), $ex); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 | 3 |  |     public function created(array $entry): ?int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 | 3 |  |         if (empty($entry) || is_null($this->getTranslation()->getCreatedKey())) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 | 1 |  |             return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 2 |  |             $entry = $this->getEntry($entry); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 | 1 |  |             if (is_null($entry)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 1 |  |                 return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 | 1 |  |             return intval(strval($entry->__get($this->getTranslation()->getCreatedKey()))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 | 1 |  |         } catch (MapperException $ex) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 | 1 |  |             throw new FilesException($ex->getMessage(), $ex->getCode(), $ex); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 | 1 |  |     protected function getLookupRecord(): ARecord | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 | 1 |  |         return clone $this->record; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 115 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 116 |  |  |  |