PHP code example of valorin / version

1. Go to this page and download the library: Download valorin/version library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

valorin / version example snippets


    
    return array(
        // ...
        'modules' => array(
            'Application',
            // ...
            'ValVersion',
        ),
        // ...
    );
    

    
    return array(
        // ...
        'valversion' => Array(
            'DbAdapter' => Array(
                'class_dir'       => __DIR__ ."/../../data/versions",
                'class_namespace' => "\Application\Version",
            ),
        ),
        // ...
    );
    

    
    namespace Application\Version;

    use ValVersion\Script\VersionAbstract;

    class CreateStructure extends VersionAbstract
    {
        public function upgrade($adapter)
        {
            $sql = Array(
                "CREATE TABLE `table1` (
                  // ...
                )",

                "CREATE TABLE `table2` (
                  // ...
                )",
            );

            foreach ($sql as $query) {
                $adapter->query($query, \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE);
            }

            return true;
        }


        public function downgrade($adapter)
        {
            $sql = Array(
                "DROP TABLE IF EXISTS `table1`",
                "DROP TABLE IF EXISTS `table2`",
            );


            foreach ($sql as $query) {
                $adapter->query($query, \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE);
            }

            return true;
        }
    }
   
bash
    valorin@gandalf:~/workspace/zf$ php ./public/index.php
    > ValVersion module v2.0.0 alpha

    Version Management
      index.php version status              Display the current version status of application.
      index.php version upgrade             Upgrade the application to the latest version.
      index.php version upgrade   TARGET    Upgrade the application to the specified version.
      index.php version downgrade TARGET    Downgrade the application to the specified version.