DbPatch_Core_Application::main PHP Method

main() public method

Initialize the dbpatch application Typically called from bin/dbpatch.php
public main ( ) : void
return void
    public function main()
    {
        $console = $this->getConsole($_SERVER['argv']);
        $writer = $this->getWriter();
        $runner = $this->getCommandRunner($writer);
        $configFile = $console->getOptionValue('config', null);
        $useColor = $console->getOptionValue('color', false);
        // Show dbpatch version
        $writer->version();
        if ($console->issetOption('version')) {
            return;
        }
        // Setup command
        if ($console->getCommand() == 'setup') {
            try {
                return $runner->getCommand('setup', $console)->execute();
            } catch (Exception $e) {
                $writer->error($e->getMessage())->line();
                $runner->showHelp();
                exit(1);
            }
        }
        // Load the right config file
        try {
            if ($this->config === null) {
                $config = $this->getConfig($configFile);
            } else {
                $config = $this->config;
            }
            if ($useColor || isset($config->color) && $config->color) {
                $writer->setColor($this->getWriterColor());
            }
            if (isset($config->debug) && $config->debug) {
                $writer->setDebug($config->debug);
            }
        } catch (Exception $e) {
            $writer->error($e->getMessage())->line();
            $runner->showHelp();
            exit(1);
        }
        // Finally execute the right command
        try {
            $db = $this->getDb($config);
            $command = $console->getCommand();
            if ($command == '') {
                $runner->showHelp();
                exit(0);
            }
            $runner->getCommand($command, $console)->setConfig($config)->setDb($db)->init()->execute();
        } catch (Exception $e) {
            $writer->error($e->getMessage())->line();
            $runner->showHelp();
            exit(1);
        }
        exit(0);
    }

Usage Example

Example #1
0
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

// determine base include folder, if @php_bin@ contains @php_bin then we do not install via PEAR
$base_include_folder = (strpos('@php_dir@', '@php_dir') === 0)
    ? dirname(__FILE__) . '/../src'
    : '@php_dir@/DbPatch/src';

// set path to add lib folder, load the Zend Autoloader and include the symfony timer
set_include_path(realpath($base_include_folder) . PATH_SEPARATOR . get_include_path());

require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('DbPatch_');

$application = new DbPatch_Core_Application();
$application->main();

// disable E_STRICT reporting on the end to prevent PEAR from throwing Strict warnings.
error_reporting(error_reporting() & ~E_STRICT);