Skip to content

Commit

Permalink
Merge pull request #17 from SergioMendolia/master
Browse files Browse the repository at this point in the history
Use a CrontabAdapterInterface instead of the class
  • Loading branch information
TiBeN authored May 2, 2023
2 parents 9eba6bd + 06043f9 commit 79ade7b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ $crontabJob->setEnabled(false);
This will prepend your cron job with a `#` in your
crontab when persisting it.

### Write your own adapter
Additionally, if you cannot read another user's crontabs or if you are on a distributed architecture where crons are not
run on the machine executing the jobs, you can create any other Adapter for your architecture
by implementing the `CrontabAdapterInterface`.

You can then instantiate the `CrontabRepository` with your adapter.

Unit tests
----------

Expand Down
2 changes: 1 addition & 1 deletion src/CrontabManager/CrontabAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
* @author TiBeN
*/
class CrontabAdapter
class CrontabAdapter implements CrontabAdapterInterface
{
private $userName;

Expand Down
44 changes: 44 additions & 0 deletions src/CrontabManager/CrontabAdapterInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/*
* Copyright 2013 Benjamin Legendre
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace TiBeN\CrontabManager;

/**
* Crontab adapter.
* Retrieve and write cron jobs data using the "crontab" command line.
*
* @author TiBeN
*/
interface CrontabAdapterInterface
{

/**
* Read the crontab and return
* raw data
*
* @return String $output the crontab raw data
*/
public function readCrontab();

/**
* Write the raw crontab data to the crontab.
*
* @param String $crontabRawData
*/
public function writeCrontab($crontabRawData);
}
2 changes: 1 addition & 1 deletion src/CrontabManager/CrontabRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CrontabRepository
*
* @param CrontabAdapter $crontabAdapter
*/
public function __construct(CrontabAdapter $crontabAdapter)
public function __construct(CrontabAdapterInterface $crontabAdapter)
{
$this->crontabAdapter = $crontabAdapter;
$this->readCrontab();
Expand Down

0 comments on commit 79ade7b

Please sign in to comment.