PHPackages                             milantex/tpc - 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. milantex/tpc

ActiveLibrary

milantex/tpc
============

This project provides a mechanism to specify types for class properties. Also, property types have additional parameters, such as the regular expression pattern for strings, minimum and maximum value for integers etc. The special setter method handles type checking and will set the given value only if it is valid for the given type and its additional parameters. Check the documentation for an example.

1.0.3(9y ago)014AGPL-3.0PHPPHP &gt;=7.0.0

Since Apr 11Pushed 8y agoCompare

[ Source](https://github.com/Milantex/milantex-tpc)[ Packagist](https://packagist.org/packages/milantex/tpc)[ RSS](/packages/milantex-tpc/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

[![Build Status](https://camo.githubusercontent.com/2a5a3ae0ef609c744f4c20e2f479bce15ccf8b9ffb0f4ea07566f83c27b83201/68747470733a2f2f7472617669732d63692e6f72672f4d696c616e7465782f6d696c616e7465782d7470632e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Milantex/milantex-tpc)[![codecov](https://camo.githubusercontent.com/94a8a80724639ff20bad8800f73f08402d41dfb536b225788d073a40fedc1340/68747470733a2f2f636f6465636f762e696f2f67682f4d696c616e7465782f6d696c616e7465782d7470632f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/Milantex/milantex-tpc)[![Code Climate](https://camo.githubusercontent.com/0edcd2440a8159e12af4f375c0044092d2bca4e8285bf133a629e2a0f96b9c95/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f4d696c616e7465782f6d696c616e7465782d7470632f6261646765732f6770612e737667)](https://codeclimate.com/github/Milantex/milantex-tpc)[![Latest Stable Version](https://camo.githubusercontent.com/79d57ddd5ad3cc3e5b796aa940a9aba1524587d4ac013399f72c92ea2353670e/68747470733a2f2f706f7365722e707567782e6f72672f6d696c616e7465782f7470632f762f737461626c65)](https://packagist.org/packages/milantex/tpc)[![Total Downloads](https://camo.githubusercontent.com/c70017d54f1b8898dda22c65598ceab3f5832f21bd6590d49e03d9cfb02dcae2/68747470733a2f2f706f7365722e707567782e6f72672f6d696c616e7465782f7470632f646f776e6c6f616473)](https://packagist.org/packages/milantex/tpc)[![License](https://camo.githubusercontent.com/d450f0e76fe192dea4087e35cdc3838a1c19077226d4744f816e20c53afec2c7/68747470733a2f2f706f7365722e707567782e6f72672f6d696c616e7465782f7470632f6c6963656e7365)](https://packagist.org/packages/milantex/tpc)[![SensioLabsInsight](https://camo.githubusercontent.com/2b195dde68764bba752f7f555f4b8a2825f26e67a2ebe5abef70a567a84030ab/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f34643531643533612d663762622d346265362d626336612d6166346563626261393930332f6d696e692e706e67)](https://insight.sensiolabs.com/projects/4d51d53a-f7bb-4be6-bc6a-af4ecbba9903)

What are Milantex Typed Property Classes?
=========================================

[](#what-are-milantex-typed-property-classes)

This project provides a mechanism to specify types for class properties. Also, property types have additional parameters, such as the regular expression pattern for strings, minimum and maximum value for integers etc. The special setter method handles type checking and will set the given value only if it is valid for the given type and its additional parameters. Check the documentation for an example.

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

[](#installation)

#### Using composer in the command line

[](#using-composer-in-the-command-line)

You can use composer to install the package using the following command from within your project's source directory:

`composer require milantex/tpc`

Make sure to update your autoloader if needed:

`composer dump-autoload -o`

#### Requiring the package as a dependency in composer.json

[](#requiring-the-package-as-a-dependency-in-composerjson)

Add the following code to your composer.json. Here is an example of a composer.json file with the milantex/tpc package required:

```
{
    "name": "your-name/your-project",
    "description": "Your project's description",
    "type": "project",
    "license": "MIT",
    "authors": [
        {
            "name": "Your Name",
            "email": "your@mail.tld"
        }
    ],
    "require": {
        "milantex/tpc": "*"
    }
}
```

Make sure to run the composer command to install dependencies:

`composer install`

Using it in your project
------------------------

[](#using-it-in-your-project)

Make sure that you require the vendor autoload file first.

```
require_once 'vendor/autoload.php';
```

After that, to create a class with typed properties, it must extend the Milantex\\TPC\\TypedPropertyClass.

Class properties must be marked as protected (not private) and should never be left as public.

To define the type and add any additional type specific parameters, use the annotation comment.

The type class should be specified using the fully-qualified path, including the namespace and should be set for the @type tag.

Different types provide different parameters. Each parameter should be specified as a tag in the annotation comment.

To create setter methods, use the inherited setProperty method.

Look at the following example of a Student class with a couple of properties with different types, each specifying additional parameters and setter methods for each of the properties.

```
