"Fossies" - the Fresh Open Source Software Archive

Member "contao-4.4.48/installation-bundle/src/Database/AbstractVersionUpdate.php" (2 Apr 2020, 1746 Bytes) of package /linux/www/contao-4.4.48.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AbstractVersionUpdate.php" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 4.8.8_vs_4.9.0.

    1 <?php
    2 
    3 /*
    4  * This file is part of Contao.
    5  *
    6  * (c) Leo Feyer
    7  *
    8  * @license LGPL-3.0-or-later
    9  */
   10 
   11 namespace Contao\InstallationBundle\Database;
   12 
   13 use Doctrine\DBAL\Connection;
   14 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
   15 use Symfony\Component\DependencyInjection\ContainerAwareTrait;
   16 
   17 /**
   18  * Parent class for version update classes.
   19  *
   20  * @author Leo Feyer <https://github.com/leofeyer>
   21  */
   22 abstract class AbstractVersionUpdate implements ContainerAwareInterface
   23 {
   24     use ContainerAwareTrait;
   25 
   26     /**
   27      * @var Connection
   28      */
   29     protected $connection;
   30 
   31     /**
   32      * @var array
   33      */
   34     protected $messages = [];
   35 
   36     /**
   37      * Constructor.
   38      *
   39      * @param Connection $connection
   40      */
   41     public function __construct(Connection $connection)
   42     {
   43         $this->connection = $connection;
   44     }
   45 
   46     /**
   47      * Checks if there is a message.
   48      *
   49      * @return bool
   50      */
   51     public function hasMessage()
   52     {
   53         return !empty($this->messages);
   54     }
   55 
   56     /**
   57      * Returns the message.
   58      *
   59      * @return string
   60      */
   61     public function getMessage()
   62     {
   63         return implode('', $this->messages);
   64     }
   65 
   66     /**
   67      * Checks whether the update should be run.
   68      *
   69      * @return bool
   70      */
   71     abstract public function shouldBeRun();
   72 
   73     /**
   74      * Runs the update.
   75      */
   76     abstract public function run();
   77 
   78     /**
   79      * Adds a message.
   80      *
   81      * @param string $message
   82      */
   83     protected function addMessage($message)
   84     {
   85         $this->messages[] = $message;
   86     }
   87 
   88     /**
   89      * Prepends a message.
   90      *
   91      * @param string $message
   92      */
   93     protected function prependMessage($message)
   94     {
   95         array_unshift($this->messages, $message);
   96     }
   97 }