Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Laravel Watcher
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Clinbio
Packagist
Laravel Watcher
Commits
57298fb1
Commit
57298fb1
authored
Aug 2, 2021
by
Dillenn Terumalai
Browse files
Options
Downloads
Patches
Plain Diff
// WIP
parent
7095770b
Branches
Branches containing commit
Tags
v1.0.1
Tags containing commit
No related merge requests found
Pipeline
#2283
passed
Aug 2, 2021
Stage: build
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Events/FileEvent.php
+20
-11
20 additions, 11 deletions
src/Events/FileEvent.php
src/Watcher.php
+5
-5
5 additions, 5 deletions
src/Watcher.php
tests/Feature/WatcherCommandTest.php
+14
-6
14 additions, 6 deletions
tests/Feature/WatcherCommandTest.php
with
39 additions
and
22 deletions
src/Events/FileEvent.php
+
20
−
11
View file @
57298fb1
...
...
@@ -5,11 +5,18 @@ namespace Dterumal\Watcher\Events;
class
FileEvent
{
/**
* The
file directory
* The
watcher identifier
*
* @var string
*/
public
string
$directory
;
public
string
$watcher
;
/**
* The file path
*
* @var string
*/
public
string
$path
;
/**
* The file mask
...
...
@@ -23,7 +30,7 @@ class FileEvent
*
* @var string
*/
public
string
$name
;
public
string
$
file
name
;
/**
* The file cookie
...
...
@@ -35,21 +42,23 @@ class FileEvent
/**
* Create a new event instance.
*
* @param string $directory
* @param string $watcher
* @param string $filename
* @param int $mask
* @param string $name
* @param int $cookie
*/
public
function
__construct
(
string
$
directory
,
string
$name
,
string
$
watcher
,
string
$
file
name
,
int
$mask
,
int
$cookie
)
{
$this
->
directory
=
$directory
;
$this
->
name
=
$name
;
)
{
$this
->
watcher
=
$watcher
;
$this
->
filename
=
$filename
;
$this
->
mask
=
$mask
;
$this
->
cookie
=
$cookie
;
$this
->
path
=
collect
(
config
(
'watcher.watchers'
))
->
first
(
function
(
$value
,
$key
)
{
return
$key
===
$this
->
watcher
;
})[
'path'
];
}
}
This diff is collapsed.
Click to expand it.
src/Watcher.php
+
5
−
5
View file @
57298fb1
...
...
@@ -129,10 +129,10 @@ class Watcher
if
(
!
empty
(
$events
))
{
foreach
(
$events
as
$event
)
{
[
$
directory
,
$filename
,
$mask
,
$cookie
]
=
[
$this
->
watchers
[
$event
[
'wd'
]],
$event
[
'name'
],
$event
[
'mask'
],
$event
[
'cookie'
]];
[
$
watcher
,
$filename
,
$mask
,
$cookie
]
=
[
$this
->
watchers
[
$event
[
'wd'
]],
$event
[
'name'
],
$event
[
'mask'
],
$event
[
'cookie'
]];
$this
->
raiseOnFileEvent
(
$
directory
,
$
watcher
,
$filename
,
$mask
,
$cookie
...
...
@@ -410,16 +410,16 @@ class Watcher
/**
* Raise after a watcher creation.
*
* @param string $
directory
* @param string $
watcher
* @param string $filename
* @param int $mask
* @param int $cookie
* @return void
*/
protected
function
raiseOnFileEvent
(
string
$
directory
,
string
$filename
,
int
$mask
,
int
$cookie
):
void
protected
function
raiseOnFileEvent
(
string
$
watcher
,
string
$filename
,
int
$mask
,
int
$cookie
):
void
{
$this
->
events
->
dispatch
(
new
FileEvent
(
$
directory
,
$
watcher
,
$filename
,
$mask
,
$cookie
...
...
This diff is collapsed.
Click to expand it.
tests/Feature/WatcherCommandTest.php
+
14
−
6
View file @
57298fb1
...
...
@@ -46,6 +46,9 @@ class WatcherCommandTest extends TestCase
{
Event
::
fake
();
// Directory watched
$directory
=
storage_path
(
'app'
);
// File created
$fooFile
=
storage_path
(
'app/test.txt'
);
...
...
@@ -71,11 +74,12 @@ class WatcherCommandTest extends TestCase
$this
->
assertSame
(
0
,
$exitCode
);
// Check that the watcher was created
Event
::
assertDispatched
(
FileEvent
::
class
,
function
(
$event
)
{
return
$event
->
directory
===
'default'
&&
Event
::
assertDispatched
(
FileEvent
::
class
,
function
(
$event
)
use
(
$directory
)
{
return
$event
->
watcher
===
'default'
&&
$event
->
mask
===
256
&&
$event
->
cookie
===
0
&&
$event
->
name
===
'test.txt'
;
$event
->
filename
===
'test.txt'
&&
$event
->
path
===
$directory
;
});
}
...
...
@@ -84,6 +88,9 @@ class WatcherCommandTest extends TestCase
{
Event
::
fake
();
// Directory watched
$directory
=
storage_path
(
'app'
);
// File created
$fooFile
=
storage_path
(
'app/test.txt'
);
...
...
@@ -109,11 +116,12 @@ class WatcherCommandTest extends TestCase
$this
->
assertSame
(
0
,
$exitCode
);
// Check that the watcher was created
Event
::
assertDispatched
(
FileEvent
::
class
,
function
(
$event
)
{
return
$event
->
directory
===
'default'
&&
Event
::
assertDispatched
(
FileEvent
::
class
,
function
(
$event
)
use
(
$directory
)
{
return
$event
->
watcher
===
'default'
&&
$event
->
mask
===
256
&&
$event
->
cookie
===
0
&&
$event
->
name
===
'test.txt'
;
$event
->
filename
===
'test.txt'
&&
$event
->
path
===
$directory
;
});
// Check that the watcher was stopped
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment