|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Rx\React; |
| 4 | + |
| 5 | +class WatchEvent |
| 6 | +{ |
| 7 | + private $bitwise; |
| 8 | + private $file; |
| 9 | + private $events = []; |
| 10 | + |
| 11 | + const NO_OP = 0; |
| 12 | + const PLATFORM_SPECIFIC = 1; |
| 13 | + const CREATED = 2; |
| 14 | + const UPDATED = 4; |
| 15 | + const REMOVED = 8; |
| 16 | + const RENAMED = 16; |
| 17 | + const OWNER_MODIFIED = 32; |
| 18 | + const ATTRIBUTE_MODIFIED = 64; |
| 19 | + const MOVED_FROM = 128; |
| 20 | + const MOVED_TO = 256; |
| 21 | + const IS_FILE = 512; |
| 22 | + const IS_DIR = 1024; |
| 23 | + const IS_SYM_LINK = 2048; |
| 24 | + const LINK = 4096; |
| 25 | + const OVERFLOW = 8192; |
| 26 | + |
| 27 | + public function __construct($file, $bitwise) |
| 28 | + { |
| 29 | + $this->bitwise = $bitwise; |
| 30 | + $this->file = $file; |
| 31 | + } |
| 32 | + |
| 33 | + public function getBitwise() |
| 34 | + { |
| 35 | + return $this->bitwise; |
| 36 | + } |
| 37 | + |
| 38 | + public function getFile() |
| 39 | + { |
| 40 | + return $this->file; |
| 41 | + } |
| 42 | + |
| 43 | + public function getEvents() |
| 44 | + { |
| 45 | + if ($this->bitwise & self::NO_OP) $this->events[] = "NO_OP"; |
| 46 | + if ($this->bitwise & self::ATTRIBUTE_MODIFIED) $this->events[] = "ATTRIBUTE_MODIFIED"; |
| 47 | + if ($this->bitwise & self::OWNER_MODIFIED) $this->events[] = "OWNER_MODIFIED"; |
| 48 | + if ($this->bitwise & self::CREATED) $this->events[] = "CREATED"; |
| 49 | + if ($this->bitwise & self::REMOVED) $this->events[] = "REMOVED"; |
| 50 | + if ($this->bitwise & self::RENAMED) $this->events[] = "RENAMED"; |
| 51 | + if ($this->bitwise & self::UPDATED) $this->events[] = "UPDATED"; |
| 52 | + if ($this->bitwise & self::MOVED_FROM) $this->events[] = "MOVED_FROM"; |
| 53 | + if ($this->bitwise & self::MOVED_TO) $this->events[] = "MOVED_TO"; |
| 54 | + if ($this->bitwise & self::OVERFLOW) $this->events[] = "OVERFLOW"; |
| 55 | + |
| 56 | + return $this->events; |
| 57 | + } |
| 58 | + |
| 59 | + public function isFile() |
| 60 | + { |
| 61 | + return (bool)$this->bitwise & self::IS_FILE; |
| 62 | + } |
| 63 | + |
| 64 | + public function isDir() |
| 65 | + { |
| 66 | + return (bool)$this->bitwise & self::IS_DIR; |
| 67 | + } |
| 68 | + |
| 69 | + public function isSymbolicLink() |
| 70 | + { |
| 71 | + return (bool)$this->bitwise & self::IS_SYM_LINK; |
| 72 | + } |
| 73 | + |
| 74 | + public function isLink() |
| 75 | + { |
| 76 | + return (bool)$this->bitwise & self::LINK; |
| 77 | + } |
| 78 | + |
| 79 | + public function noOp() |
| 80 | + { |
| 81 | + return (bool)$this->bitwise & self::NO_OP; |
| 82 | + } |
| 83 | + |
| 84 | + public function attributeModified() |
| 85 | + { |
| 86 | + return (bool)$this->bitwise & self::ATTRIBUTE_MODIFIED; |
| 87 | + } |
| 88 | + |
| 89 | + public function ownerModified() |
| 90 | + { |
| 91 | + return (bool)$this->bitwise & self::OWNER_MODIFIED; |
| 92 | + } |
| 93 | + |
| 94 | + public function created() |
| 95 | + { |
| 96 | + return (bool)$this->bitwise & self::CREATED; |
| 97 | + } |
| 98 | + |
| 99 | + public function removed() |
| 100 | + { |
| 101 | + return (bool)$this->bitwise & self::REMOVED; |
| 102 | + } |
| 103 | + |
| 104 | + public function renamed() |
| 105 | + { |
| 106 | + return (bool)$this->bitwise & self::RENAMED; |
| 107 | + } |
| 108 | + |
| 109 | + public function updated() |
| 110 | + { |
| 111 | + return (bool)$this->bitwise & self::UPDATED; |
| 112 | + } |
| 113 | +} |
0 commit comments