Overview

Namespaces

  • LeanMapper
    • Bridges
      • Nette
        • DI
    • Exception
    • Reflection
    • Relationship

Classes

  • LeanMapper\Bridges\Nette\DI\LeanMapperExtension
  • LeanMapper\Caller
  • LeanMapper\Connection
  • LeanMapper\DataDifference
  • LeanMapper\DefaultEntityFactory
  • LeanMapper\DefaultMapper
  • LeanMapper\Entity
  • LeanMapper\EntityDataDecoder
  • LeanMapper\Events
  • LeanMapper\Filtering
  • LeanMapper\FilteringResult
  • LeanMapper\FilteringResultDecorator
  • LeanMapper\Fluent
  • LeanMapper\ImplicitFilters
  • LeanMapper\Reflection\Aliases
  • LeanMapper\Reflection\AliasesBuilder
  • LeanMapper\Reflection\AliasesParser
  • LeanMapper\Reflection\AnnotationsParser
  • LeanMapper\Reflection\EntityReflection
  • LeanMapper\Reflection\Property
  • LeanMapper\Reflection\PropertyFactory
  • LeanMapper\Reflection\PropertyFilters
  • LeanMapper\Reflection\PropertyMethods
  • LeanMapper\Reflection\PropertyPasses
  • LeanMapper\Reflection\PropertyType
  • LeanMapper\Reflection\PropertyValuesEnum
  • LeanMapper\Relationship\BelongsTo
  • LeanMapper\Relationship\BelongsToMany
  • LeanMapper\Relationship\BelongsToOne
  • LeanMapper\Relationship\HasMany
  • LeanMapper\Relationship\HasOne
  • LeanMapper\Repository
  • LeanMapper\Result
  • LeanMapper\ResultProxy
  • LeanMapper\Row

Interfaces

  • LeanMapper\IEntityFactory
  • LeanMapper\IMapper

Exceptions

  • LeanMapper\Exception\Exception
  • LeanMapper\Exception\InvalidAnnotationException
  • LeanMapper\Exception\InvalidArgumentException
  • LeanMapper\Exception\InvalidMethodCallException
  • LeanMapper\Exception\InvalidStateException
  • LeanMapper\Exception\InvalidValueException
  • LeanMapper\Exception\MemberAccessException
  • LeanMapper\Exception\UtilityClassException
  • 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: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 
<?php

/**
 * This file is part of the Lean Mapper library (http://www.leanmapper.com)
 *
 * Copyright (c) 2013 Vojtěch Kohout (aka Tharos)
 *
 * For the full copyright and license information, please view the file
 * license.md that was distributed with this source code.
 */

namespace LeanMapper;

/**
 * Pointer to specific position within Result instance
 *
 * @author Vojtěch Kohout
 */
class Row
{

    /** @var Result */
    private $result;

    /** @var int */
    private $id;

    /** @var array */
    private $referencedRows = [];



    /**
     * @param Result $result
     * @param int $id
     */
    public function __construct(Result $result, $id)
    {
        $this->result = $result;
        $this->id = $id;
    }



    /**
     * Gets value of given column
     *
     * @param string $name
     * @return mixed
     */
    public function __get($name)
    {
        return $this->result->getDataEntry($this->id, $name);
    }



    /**
     * Sets value of given column
     *
     * @param string $name
     * @param mixed $value
     */
    public function __set($name, $value)
    {
        if (array_key_exists($name, $this->referencedRows)) {
            if ($value === null) {
                $this->referencedRows[$name] = null;
            } else {
                unset($this->referencedRows[$name]);
            }
        }
        $this->result->setDataEntry($this->id, $name, $value);
    }



    /**
     * Tells whether Row has given column and is not null
     *
     * @param string $name
     * @return bool
     */
    public function __isset($name)
    {
        return $this->hasColumn($name) and $this->$name !== null;
    }



    /**
     * Tells whether Row has given column
     *
     * @param string $name
     * @return bool
     */
    public function hasColumn($name)
    {
        return $this->result->hasDataEntry($this->id, $name);
    }



    /**
     * Unsets given column
     *
     * @param string $name
     */
    public function __unset($name)
    {
        $this->result->unsetDataEntry($this->id, $name);
    }



    /**
     * @param Connection $connection
     */
    public function setConnection(Connection $connection)
    {
        $this->result->setConnection($connection);
    }



    /**
     * @return bool
     */
    public function hasConnection()
    {
        return $this->result->hasConnection();
    }



    /**
     * @param IMapper $mapper
     */
    public function setMapper(IMapper $mapper)
    {
        $this->result->setMapper($mapper);
    }



    /**
     * @return IMapper|null
     */
    public function getMapper()
    {
        return $this->result->getMapper();
    }



    /**
     * Returns values of columns
     *
     * @return array
     */
    public function getData()
    {
        return $this->result->getData($this->id);
    }



    /**
     * Returns values of columns that were modified
     *
     * @return array
     */
    public function getModifiedData()
    {
        return $this->result->getModifiedData($this->id);
    }



    /**
     * Tells whether Row is in modified state
     *
     * @return bool
     */
    public function isModified()
    {
        return $this->result->isModified($this->id);
    }



    /**
     * Tells whether Row is in detached state
     *
     * @return bool
     */
    public function isDetached()
    {
        return $this->result->isDetached();
    }



    /**
     * Detaches Row (it means mark it as non-persisted)
     */
    public function detach()
    {
        $data = $this->result->getData($this->id);
        $this->result = Result::createDetachedInstance();
        foreach ($data as $key => $value) {
            $this->result->setDataEntry(Result::DETACHED_ROW_ID, $key, $value);
        }
        $this->id = Result::DETACHED_ROW_ID;
    }



    /**
     * Marks Row as attached
     *
     * @param int $id
     * @param string $table
     */
    public function attach($id, $table)
    {
        $this->result->attach($id, $table);
        $this->id = $id;
    }



    /**
     * Marks Row as non-modified (isModified returns false right after this method call)
     */
    public function markAsUpdated()
    {
        $this->result->markAsUpdated($this->id);
    }



    /**
     * Gets referenced Row instance
     *
     * @param string $table
     * @param string|null $viaColumn
     * @param Filtering|null $filtering
     * @return Row|null
     */
    public function referenced($table, $viaColumn = null, Filtering $filtering = null)
    {
        if (array_key_exists($viaColumn, $this->referencedRows)) {
            return $this->referencedRows[$viaColumn];
        }
        return $this->result->getReferencedRow($this->id, $table, $viaColumn, $filtering);
    }



    /**
     * Gets array of Row instances referencing current Row
     *
     * @param string $table
     * @param string|null $viaColumn
     * @param Filtering|null $filtering
     * @param string|null $strategy
     * @return Row[]
     */
    public function referencing($table, $viaColumn = null, Filtering $filtering = null, $strategy = null)
    {
        return $this->result->getReferencingRows($this->id, $table, $viaColumn, $filtering, $strategy);
    }



    /**
     * @param Row $row
     * @param string $viaColumn
     */
    public function setReferencedRow(self $row = null, $viaColumn)
    {
        $this->referencedRows[$viaColumn] = $row;
    }



    /**
     * Adds new data entry to referencing Result
     *
     * @param array $values
     * @param string $table
     * @param string|null $viaColumn
     * @param Filtering|null $filtering
     * @param string|null $strategy
     */
    public function addToReferencing(array $values, $table, $viaColumn = null, Filtering $filtering = null, $strategy = null)
    {
        $this->result->addToReferencing($values, $table, $viaColumn, $filtering, $strategy);
    }



    /**
     * Remove given data entry from referencing Result
     *
     * @param array $values
     * @param string $table
     * @param string|null $viaColumn
     * @param Filtering|null $filtering
     * @param string|null $strategy
     */
    public function removeFromReferencing(array $values, $table, $viaColumn = null, Filtering $filtering = null, $strategy = null)
    {
        $this->result->removeFromReferencing($values, $table, $viaColumn, $filtering, $strategy);
    }



    /**
     * @param string $table
     * @param string|null $viaColumn
     * @param Filtering|null $filtering
     * @param string|null $strategy
     * @return DataDifference
     */
    public function createReferencingDataDifference($table, $viaColumn = null, Filtering $filtering = null, $strategy = null)
    {
        return $this->result->createReferencingDataDifference($table, $viaColumn, $filtering, $strategy);
    }



    /**
     * Cleans in-memory cache with referenced rows
     *
     * @param string|null $table
     * @param string|null $viaColumn
     */
    public function cleanReferencedRowsCache($table = null, $viaColumn = null)
    {
        $this->result->cleanReferencedResultsCache($table, $viaColumn);
    }



    /**
     * Cleans in-memory cache with referencing rows
     *
     * @param string|null $table
     * @param string|null $viaColumn
     */
    public function cleanReferencingRowsCache($table = null, $viaColumn = null)
    {
        $this->result->cleanReferencingResultsCache($table, $viaColumn);
    }



    /**
     * @param string $table
     * @param string|null $viaColumn
     * @param Filtering|null $filtering
     * @param string|null $strategy
     */
    public function cleanReferencingAddedAndRemovedMeta($table, $viaColumn = null, Filtering $filtering = null, $strategy = null)
    {
        $this->result->cleanReferencingAddedAndRemovedMeta($table, $viaColumn, $filtering, $strategy);
    }



    /**
     * @param string $proxyClass
     * @return ResultProxy
     */
    public function getResultProxy($proxyClass = 'LeanMapper\ResultProxy')
    {
        return $this->result->getProxy($proxyClass);
    }

}
tharos/leanmapper v3.1.0 API documentation API documentation generated by ApiGen