firefly-iii/app/TransactionRules/Triggers/AbstractTrigger.php
2017-12-29 09:05:35 +01:00

126 lines
3.1 KiB
PHP

<?php
/**
* AbstractTrigger.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
use FireflyIII\Models\RuleTrigger;
use FireflyIII\Models\TransactionJournal;
/**
* This class will be magical!
*
* Class AbstractTrigger
* @method triggered
*/
class AbstractTrigger
{
/** @var bool Whether to stop processing after this one is checked. */
public $stopProcessing;
/** @var string Value to check for */
protected $checkValue;
/** @var TransactionJournal Journal to check */
protected $journal;
/** @var RuleTrigger Trigger object */
protected $trigger;
/** @var string Trigger value */
protected $triggerValue;
/**
* Make a new trigger from the value given in the string.
*
* @codeCoverageIgnore
*
* @param string $triggerValue
* @param bool $stopProcessing
*
* @return static
*/
public static function makeFromStrings(string $triggerValue, bool $stopProcessing)
{
$self = new static;
$self->triggerValue = $triggerValue;
$self->stopProcessing = $stopProcessing;
return $self;
}
/**
* Make a new trigger from the rule trigger in the parameter
*
* @codeCoverageIgnore
*
* @param RuleTrigger $trigger
*
* @return AbstractTrigger
*/
public static function makeFromTrigger(RuleTrigger $trigger)
{
$self = new static;
$self->trigger = $trigger;
$self->triggerValue = $trigger->trigger_value;
$self->stopProcessing = $trigger->stop_processing;
return $self;
}
/**
* Make a new trigger from a trigger value.
*
* @codeCoverageIgnore
*
* @param string $triggerValue
*
* @return AbstractTrigger
*/
public static function makeFromTriggerValue(string $triggerValue)
{
$self = new static;
$self->triggerValue = $triggerValue;
return $self;
}
/**
* Returns trigger
*
* @codeCoverageIgnore
*
* @return RuleTrigger
*/
public function getTrigger(): RuleTrigger
{
return $this->trigger;
}
/**
* Returns trigger value
*
* @codeCoverageIgnore
*
* @return string
*/
public function getTriggerValue(): string
{
return $this->triggerValue;
}
}