PHPackages                             carrooi/contactable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. carrooi/contactable

ActiveLibrary[Framework](/categories/framework)

carrooi/contactable
===================

Contactable module for Nette framework and Doctrine

18PHP

Since Feb 12Pushed 11y ago1 watchersCompare

[ Source](https://github.com/Carrooi/Nette-Contactable)[ Packagist](https://packagist.org/packages/carrooi/contactable)[ RSS](/packages/carrooi-contactable/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Carrooi/Addressable
===================

[](#carrooiaddressable)

[![Build Status](https://camo.githubusercontent.com/e0f48c2e1233b141a73457ec73cbf1012661fff7d1f2767fb4b0306629632df7/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f436172726f6f692f4e657474652d436f6e7461637461626c652e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/Carrooi/Nette-Contactable)[![Donate](https://camo.githubusercontent.com/7f8b0c0980ad316210d1ec0c7d3298ace87d2f7c0eb6911977c0644951af5bd2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f6e6174652d50617950616c2d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SZRZJA7TCK4N2)

Contactable module for Nette framework and Doctrine.

Installation
------------

[](#installation)

```
$ composer require carrooi/contactable
$ composer update

```

Configuration
-------------

[](#configuration)

```
extensions:
	contactable: Carrooi\Contactable\DI\ContactableExtension

contactable:
	contactItemClass: App\Model\Entities\ContactItem
	associations:
		App\Model\Entities\User: user
```

- **contactItemClass**: entity with associations between contact types and eg. user entity
- **associations**: list of contactable entities with field names which are manyToOne associations in `contactItemClass`

Contactable entity
------------------

[](#contactable-entity)

Entity which implements `Carrooi\Contactable\Model\Entities\IContactableEntity` interface with these methods:

- `getId()`: returns identifier
- `getContacts()`: returns array of `Carrooi\Contactable\Model\Entities\IContactItem` entities
- `addContact()`: adds new `Carrooi\Contactable\Model\Entities\IContactItem` entity to collection
- `removeContact()`: removes `Carrooi\Contactable\Model\Entities\IContactItem` entity from collection

Of course you don't need to implement all required methods on your own (except for `getId()` method). Just use prepared trait `Carrooi\Contactable\Model\Entities\TContactable`.

```
namespace App\Model\Entities;

use Carrooi\Contactable\Model\Entities\IContactableEntity;
use Carrooi\Contactable\Model\Entities\TContactable;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @author David Kudera
 */
class User implements IContactableEntity
{

	use TContactable;

	// ...

	/**
	 * @return int
	 */
	public function getId()
	{
		return $this->id;
	}

}
```

Contact item entity
-------------------

[](#contact-item-entity)

Entity which holds the actual value of contact, eg. actual email address of user. This entity must implement `Carrooi\Contactable\Model\Entities\IContactItem` interface with these methods:

- `getId()`: returns identifier
- `getContactType()` returns `Carrooi\Contactable\Model\Entities\IContactType` entity
- `setContactType()` sets `Carrooi\Contactable\Model\Entities\IContactType` entity
- `getValue()`: returns value of contact
- `setValue()`: sets value of contact
- `validateValue()` validate value against pattern in contact type

Again, you can use prepared trait `Carrooi\Contactable\Model\Entities\TContactItem`.

```
namespace App\Model\Entities;

use Carrooi\Contactable\Model\Entities\IContactItem;
use Carrooi\Contactable\Model\Entities\TContactItem;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @author David Kudera
 */
class ContactItem implements IContactItem
{

	use TContactItem;

	/**
	 * @ORM\Id
	 * @ORM\Column(type="integer")
	 * @var int
	 */
	private $id;

	/**
	 * @ORM\ManyToOne(targetEntity="\App\Model\Entities\User")
	 * @var \App\Model\Entities\User
	 */
	private $user;

	// ... some getters and setters for all fields

}
```

As you can see, we've got `user` field which corresponding with `associations` setup in your configuration.

Contact types
-------------

[](#contact-types)

You can create as many types as you want, eg. mails, facebook, phone numbers etc.

There is already prepared service for that: `Carrooi\Contactable\Model\Facades\ContactTypesFacade`.

**Create contact type**:

```
$type = $types->create('mail', 'Email', [
	'pattern' => '[a-z]+@[a-z]+\.[a-z]{2,3}',    // really naive mail regex
	'url' => 'mail.org',
]);
```

arguments:

- `name`: required "system" name
- `title`: required "public" name
- `values`:
    - not required list of other values
    - `pattern`: not required pattern for all contact values of this type
    - `url`: not required url to contact

**Update contact type**:

```
$types->update($type, [
	'name' => 'email',
	'title' => 'Email address',
	'pattern' => '.+',            // no more naive, just stupid
	'url' => 'mail.com',
]);
```

**Remove contact type**:

```
$types->remove($type);
```

**Get all contact types**:

```
foreach ($types->findAll() as $type) {
	// ...
}
```

**Get id =&gt; names pairs**:

```
foreach ($types->findAllNames() as $id => $name) {
	// ...
}
```

**Find contact type by id**:

```
$type = $types->findOneById($id);
```

**Find contact type by name**:

```
$type = $types->findOneByName($name);
```

Contact items facade
--------------------

[](#contact-items-facade)

There is also service `Carrooi\Contactable\Model\Facades\ContactItemsFacade` which can be used for adding contacts to contactable entities.

**Add contact**:

```
$item = $items->addContact($user, $type, 'lorem@ipsum.com');
```

**Update contact**:

```
$items->update($item, [
	'contactType' => $anotherType,
	'value' => '999888777',
]);
```

**Remove contact**:

```
$items->remove($item);
```

**Find by id**:

```
$item = $items->findOneById($id);
```

**Find all by entity**:

```
foreach ($items->findAllByEntity($user) as $item) {
	// ...
}
```

Changelog
---------

[](#changelog)

- 1.0.0
    - Initial version

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/838c6933d498fdb2a31f251ed45006a6ef97935ea2a27f38dab7738038939fc9?d=identicon)[david\_kudera](/maintainers/david_kudera)

---

Top Contributors

[![davidkudera](https://avatars.githubusercontent.com/u/1174072?v=4)](https://github.com/davidkudera "davidkudera (1 commits)")

### Embed Badge

![Health badge](/badges/carrooi-contactable/health.svg)

```
[![Health](https://phpackages.com/badges/carrooi-contactable/health.svg)](https://phpackages.com/packages/carrooi-contactable)
```

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M192](/packages/laravel-telescope)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M259](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M596](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
