Overview

Namespaces

  • LeanMapper
    • Exception
    • Reflection
    • Relationship

Classes

  • LeanMapper\Entity
  • 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\PropertyType
  • LeanMapper\Relationship\BelongsTo
  • LeanMapper\Relationship\BelongsToMany
  • LeanMapper\Relationship\BelongsToOne
  • LeanMapper\Relationship\HasMany
  • LeanMapper\Relationship\HasOne
  • LeanMapper\Repository
  • LeanMapper\Result
  • LeanMapper\Row

Exceptions

  • LeanMapper\Exception\InvalidAnnotationException
  • LeanMapper\Exception\InvalidArgumentException
  • LeanMapper\Exception\InvalidMethodCallException
  • LeanMapper\Exception\InvalidStateException
  • LeanMapper\Exception\InvalidValueException
  • LeanMapper\Exception\MemberAccessException
  • LeanMapper\Exception\RuntimeException
  • 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: 
<?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-mit.txt that was distributed with this source code.
 */

namespace LeanMapper;

use Closure;
use DibiConnection;

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

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

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


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

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

    /**
     * Sets value of given field
     *
     * @param string $name
     * @param mixed $value
     */
    public function __set($name, $value)
    {
        $this->result->setDataEntry($this->id, $name, $value);
    }

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

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

    /**
     * Marks row as detached (it means non-persisted)
     */
    public function detach()
    {
        $this->result->detach($this->id);
    }

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

    /**
     * Marks row as persisted
     *
     * @param int $id
     * @param string $table
     * @param DibiConnection $connection
     */
    public function markAsCreated($id, $table, DibiConnection $connection)
    {
        $this->id = $id;
        $this->result->markAsCreated($this->id, $table, $connection);
    }

    /**
     * Returns array of modified fields with new values
     *
     * @return array
     */
    public function getModifiedData()
    {
        return $this->result->getModifiedData($this->id);
    }

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

    /**
     * Returns referenced LeanMapper\Row instance
     *
     * @param string $table
     * @param Closure|null $filter
     * @param string|null $viaColumn
     * @return Row
     */
    public function referenced($table, Closure $filter = null, $viaColumn = null)
    {
        return $this->result->getReferencedRow($this->id, $table, $filter, $viaColumn);
    }

    /**
     * Returns array of LeanMapper\Row instances referencing current row
     *
     * @param string $table
     * @param Closure|null $filter
     * @param string|null $viaColumn
     * @return Row[]
     */
    public function referencing($table, Closure $filter = null, $viaColumn = null)
    {
        return $this->result->getReferencingRows($this->id, $table, $filter, $viaColumn);
    }

}
tharos/leanmapper v1.3.0 API documentation API documentation generated by ApiGen