Overview

Namespaces

  • CzProject
    • SqlSchema

Classes

  • CzProject\SqlSchema\Column
  • CzProject\SqlSchema\ForeignKey
  • CzProject\SqlSchema\Index
  • CzProject\SqlSchema\IndexColumn
  • CzProject\SqlSchema\Schema
  • CzProject\SqlSchema\Table

Exceptions

  • CzProject\SqlSchema\DuplicateException
  • CzProject\SqlSchema\EmptyException
  • CzProject\SqlSchema\Exception
  • CzProject\SqlSchema\OutOfRangeException
  • CzProject\SqlSchema\StaticClassException
  • Overview
  • Namespace
  • Class
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 
<?php

    namespace CzProject\SqlSchema;


    class Index
    {
        const TYPE_INDEX = 'INDEX';
        const TYPE_PRIMARY = 'PRIMARY';
        const TYPE_UNIQUE = 'UNIQUE';
        const TYPE_FULLTEXT = 'FULLTEXT';

        /** @var string */
        private $name;

        /** @var string */
        private $type;

        /** @var IndexColumn[] */
        private $columns = array();


        /**
         * @param  string|NULL
         * @param  string
         * @param  string[]|string
         */
        public function __construct($name, $type = self::TYPE_INDEX, $columns = array())
        {
            $this->name = $name;
            $this->setType($type);

            if (!is_array($columns)) {
                $columns = array($columns);
            }

            foreach ($columns as $column) {
                $this->addColumn($column);
            }
        }


        /**
         * @return string|NULL
         */
        public function getName()
        {
            return $this->name;
        }


        /**
         * @param  string
         * @return self
         */
        public function setType($type)
        {
            $type = (string) $type;
            $exists = $type === self::TYPE_INDEX
                || $type === self::TYPE_PRIMARY
                || $type === self::TYPE_UNIQUE
                || $type === self::TYPE_FULLTEXT;

            if (!$exists) {
                throw new OutOfRangeException("Index type '$type' not found.");
            }

            $this->type = $type;
            return $this;
        }


        /**
         * @return string
         */
        public function getType()
        {
            return $this->type;
        }


        /**
         * @param  IndexColumn|string
         * @return IndexColumn
         */
        public function addColumn($column)
        {
            if (!($column instanceof IndexColumn)) {
                $column = new IndexColumn($column);
            }

            return $this->columns[] = $column;
        }


        /**
         * @return IndexColumn[]
         */
        public function getColumns()
        {
            return $this->columns;
        }
    }
czproject/sql-schema v1.0.0 API documentation API documentation generated by ApiGen