Skip to content

Commit

Permalink
Add generic, non-annotation traits
Browse files Browse the repository at this point in the history
Traits without annotations for easy integration purposes.
  • Loading branch information
MisatoTremor committed Oct 9, 2014
1 parent b1c3643 commit 3cc1c10
Show file tree
Hide file tree
Showing 8 changed files with 292 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/blameable.md
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ Easy like that, any suggestions on improvements are very welcome

You can use blameable traits for quick **createdBy** **updatedBy** string definitions
when using annotation mapping.
There is also a trait without annotations for easy integration purposes.

**Note:** this feature is only available since php **5.4.0**. And you are not required
to use the Traits provided by extensions.
Expand Down
1 change: 1 addition & 0 deletions doc/ip_traceable.md
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ Easy like that, any suggestions on improvements are very welcome

You can use IpTraceable traits for quick **createdFromIp** **updatedFromIp** string definitions
when using annotation mapping.
There is also a trait without annotations for easy integration purposes.

**Note:** this feature is only available since php **5.4.0**. And you are not required
to use the Traits provided by extensions.
Expand Down
1 change: 1 addition & 0 deletions doc/timestampable.md
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ This example is based off [Handling different Timezones with the DateTime Type][

You can use timestampable traits for quick **createdAt** **updatedAt** timestamp definitions
when using annotation mapping.
There is also a trait without annotations for easy integration purposes.

**Note:** this feature is only available since php **5.4.0**. And you are not required
to use the Traits provided by extensions.
Expand Down
68 changes: 68 additions & 0 deletions lib/Gedmo/Blameable/Traits/Blameable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace Gedmo\Blameable\Traits;

/**
* Blameable Trait, usable with PHP >= 5.4
*
* @author David Buchmann <[email protected]>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
trait Blameable
{
/**
* @var string
*/
private $createdBy;

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

/**
* Sets createdBy.
*
* @param string $createdBy
* @return $this
*/
public function setCreatedBy($createdBy)
{
$this->createdBy = $createdBy;

return $this;
}

/**
* Returns createdBy.
*
* @return string
*/
public function getCreatedBy()
{
return $this->createdBy;
}

/**
* Sets updatedBy.
*
* @param string $updatedBy
* @return $this
*/
public function setUpdatedBy($updatedBy)
{
$this->updatedBy = $updatedBy;

return $this;
}

/**
* Returns updatedBy.
*
* @return string
*/
public function getUpdatedBy()
{
return $this->updatedBy;
}
}
68 changes: 68 additions & 0 deletions lib/Gedmo/IpTraceable/Traits/IpTraceable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace Gedmo\IpTraceable\Traits;

/**
* IpTraceable Trait, usable with PHP >= 5.4
*
* @author Pierre-Charles Bertineau <[email protected]>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
trait IpTraceable
{
/**
* @var string
*/
protected $createdFromIp;

/**
* @var string
*/
protected $updatedFromIp;

/**
* Sets createdFromIp.
*
* @param string $createdFromIp
* @return $this
*/
public function setCreatedFromIp($createdFromIp)
{
$this->createdFromIp = $createdFromIp;

return $this;
}

/**
* Returns createdFromIp.
*
* @return string
*/
public function getCreatedFromIp()
{
return $this->createdFromIp;
}

/**
* Sets updatedFromIp.
*
* @param string $updatedFromIp
* @return $this
*/
public function setUpdatedFromIp($updatedFromIp)
{
$this->updatedFromIp = $updatedFromIp;

return $this;
}

/**
* Returns updatedFromIp.
*
* @return string
*/
public function getUpdatedFromIp()
{
return $this->updatedFromIp;
}
}
51 changes: 51 additions & 0 deletions lib/Gedmo/SoftDeleteable/Traits/SoftDeleteable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Gedmo\SoftDeleteable\Traits;

/**
* SoftDeletable Trait, usable with PHP >= 5.4
*
* @author Wesley van Opdorp <[email protected]>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
trait SoftDeleteable
{
/**
* @var \DateTime
*/
protected $deletedAt;

/**
* Sets deletedAt.
*
* @param \Datetime|null $deletedAt
*
* @return $this
*/
public function setDeletedAt(\DateTime $deletedAt = null)
{
$this->deletedAt = $deletedAt;

return $this;
}

/**
* Returns deletedAt.
*
* @return \DateTime
*/
public function getDeletedAt()
{
return $this->deletedAt;
}

/**
* Is deleted?
*
* @return bool
*/
public function isDeleted()
{
return null !== $this->deletedAt;
}
}
68 changes: 68 additions & 0 deletions lib/Gedmo/Timestampable/Traits/Timestampable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace Gedmo\Timestampable\Traits;

/**
* Timestampable Trait, usable with PHP >= 5.4
*
* @author Gediminas Morkevicius <[email protected]>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
trait Timestampable
{
/**
* @var \DateTime
*/
protected $createdAt;

/**
* @var \DateTime
*/
protected $updatedAt;

/**
* Sets createdAt.
*
* @param \DateTime $createdAt
* @return $this
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;

return $this;
}

/**
* Returns createdAt.
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}

/**
* Sets updatedAt.
*
* @param \DateTime $updatedAt
* @return $this
*/
public function setUpdatedAt(\DateTime $updatedAt)
{
$this->updatedAt = $updatedAt;

return $this;
}

/**
* Returns updatedAt.
*
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
}
34 changes: 34 additions & 0 deletions lib/Gedmo/Tree/Traits/NestedSet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Gedmo\Tree\Traits;

/**
* NestedSet Trait, usable with PHP >= 5.4
*
* @author Renaat De Muynck <[email protected]>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
trait NestedSet
{

/**
* @var integer
*/
private $root;

/**
* @var integer
*/
private $level;

/**
* @var integer
*/
private $left;

/**
* @var integer
*/
private $right;

}

0 comments on commit 3cc1c10

Please sign in to comment.