An open API service indexing awesome lists of open source software.

https://github.com/remithomas/rt-extends

A list of ZF2 useful tools. To provide some utilities: languages list, flash messenger, Sql query (on duplicate key update), Snippets, Validators and more
https://github.com/remithomas/rt-extends

Last synced: 10 months ago
JSON representation

A list of ZF2 useful tools. To provide some utilities: languages list, flash messenger, Sql query (on duplicate key update), Snippets, Validators and more

Awesome Lists containing this project

README

          

rt-extends [![Build Status](https://travis-ci.org/remithomas/rt-extends.png?branch=master)](https://travis-ci.org/remithomas/rt-extends)
==========

A list of ZF2 useful tools. To provide some utilities to generate list of languages, Sql query (on duplicate key update), flashmessenger, countries states and more

---------------------------------------
# Features / Goals

* **Sql** : Db\Sql\DuplicateInsert ON DUPLICATE KEY UPDATE option
* **Validators** : Date is later, is Earlier
* **Uri**
* **Thumbnail** : Get Thumbnail from URI
* **Type** : Get the type of the media
* **Meta** : Get metadata of the media
* **Useful**
* **Location** : List of countries, states list, zipcode search
* **I18n** : continents list, languages list, Timezones list
* **Data** : Fake data *Lorem Ipsum* generator
* **File** : create Zip Archive, unzip archive, get Favicon
* **PHP** : [sprintf](http://php.net/manual/en/function.sprintf.php) with dynamic variables
* **View\Helper** : extended Flash messenger (sub-message and messages are translated)
* **Date** : CountDown
* **BodyClasses** : manage your body CSS classes from controller
* **Snippets** : create basic CSRF quickly

---------------------------------------
# Ask for contributions
Some ideas [to implement](https://github.com/remithomas/rt-extends/pulls) to this useful code ? Or ups [some errors appear](https://github.com/remithomas/rt-extends/issues)

# Requirements

* [Zend Framework 2](https://github.com/zendframework/zf2) (latest master)
* [umpirsky/country-list](https://github.com/umpirsky/country-list) (latest master)
* ZipArchive
* CURL extension

# Installation
---------------------------------------
## How to install ?

### Using composer.json

```json
{
"name": "zendframework/skeleton-application",
"description": "Skeleton Application for ZF2",
"license": "BSD-3-Clause",
"keywords": [
"framework",
"zf2"
],
"minimum-stability": "dev",
"homepage": "http://framework.zend.com/",
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": "dev-master",
"remithomas/rt-extends": "dev-master"
}
}
```

### Activate the module :

application.config.php
```php
array(
'Application',
'RtExtends',
)
);
?>
```

# Examples
---------------------------------------
## Db\Sql
Sql class including DuplicateInsert.php

```php
$value = array(
'user_id' => 2,
'value' => 'myvalue'
);

$sql = new \RtExtends\Db\Sql($adapter, 'mytable');

$DuplicateInsert = $sql->duplicateInsert();
$DuplicateInsert->values($values);

$sqlString = $sql->getSqlStringForSqlObject($DuplicateInsert);
$adapter->query($sqlString, Adapter::QUERY_MODE_EXECUTE);
```

## Db\Sql\DuplicateInsert

```php
2,
'value' => 'myvalue'
);

$DuplicateInsert = new RtExtends\Db\Sql\DuplicateInsert("user");
$DuplicateInsert->values($value);

$statment = $this->dbAdapter->createStatement();
$DuplicateInsert->prepareStatement($this->dbAdapter, $statment);
$statment->execute();
?>
```

the above code generates this query

```sql
INSERT INTO `user` (`user_id`, `value`)
VALUES (2, 'myvalue')
ON DUPLICATE KEY UPDATE `user_id`=VALUES(`user_id`), `value`=VALUES(`value`);
```

## Validator\Date\IsLater

```php
public function getInputFilterSpecification()
{
return array(
'datestart' => array(
'required' => true,
'validators' => array(
array(
'name' => "RtExtends\Validator\Date\IsLater",
'options' => array(
'min' => date ("d F Y - H:i", mktime()),
'format' => 'd F Y - H:i',
'timezone' => 'Europe/London'
)
)
),
),
);
}
```

## Validator\Date\IsEarlier

```php
public function getInputFilterSpecification()
{
return array(
'dateend' => array(
'required' => true,
'validators' => array(
array(
'name' => "RtExtends\Validator\Date\IsEarlier",
'options' => array(
'max' => date ("d F Y - H:i", mktime()),
'format' => 'd F Y - H:i',
'timezone' => 'Europe/London'
)
)
),
),
);
}
```

## Uri
### Uri\Thumb
Get list of thumbnail of an URI
```php
$uri = "http://www.dailymotion.com/video/x9003r_pac-man-remi-gaillard_fun";
$uri = "http://www.youtube.com/watch?v=1VVkIOxRcX0"; // youtube
$thumbUri = new \RtExtends\Uri\Thumb();
var_dump($thumbUri->getThumbs($uri));

// limit the number of thumbnails
var_dump($thumbUri->getThumbs($uri, 2));
```

Get one thumbnail of an URI
```php
$uri = "http://framework.zend.com/blog/";
$thumbUri = new \RtExtends\Uri\Thumb();
var_dump($thumbUri->getThumb($uri));
```

### Uri\Type
Get the type of the media
```php
$typeUri = new \RtExtends\Uri\Type();
$typeUri->getType("http://www.youtube.com/watch?v=1VVkIOxRcX0"); // return youtube
```

### Uri\MetaData
Get the meta of the media. All URI gets title and description
```php
$metadataUri = new \RtExtends\Uri\MetaData();
$metadataUri->getMetaData("http://www.youtube.com/watch?v=1VVkIOxRcX0");
/*
return array(
'title' => 'media title',
'description' => 'media description',
// ...
)
*/
```

## Useful\I18n\Languages
List of languages
```php
var_dump(RtExtends\Useful\I18n\Languages::getSimpleCodeLanguages());
// array("fr"=>"Français","en"=>"English",'pt'=>'Português',....)
```

```php
var_dump(RtExtends\Useful\I18n\Languages::getLanguages());
// array('lv_LV'=>'Latvija - Latviešu','en_LB'=>'Lebanon - English','lt_LT'=>'Lietuva - Lietuvių','fr_LU'=>'Luxembourg - Français',,....)
```

## Useful\Location
List of countries (array returned)
```php
\RtExtends\Useful\Location\Countries::getCountries();
```

Zipcode
```php
\RtExtends\Useful\Location\Ziptastic::dataLocation("US", "33330");
/*
Return a stdClass object
object(stdClass)#748 (3) {
["city"] => string(15) "Fort Lauderdale"
["state"] => string(7) "Florida"
["country"] => string(2) "US"
}
*/
```

States of countries (DE,FR,US are available)
```php
\RtExtends\Useful\Location\Country\Us::states();
\RtExtends\Useful\Location\Country\Us::statesFIPS(); // FIPS codes
\RtExtends\Useful\Location\Country\Fr::states();
\RtExtends\Useful\Location\Country\De::states();
```

Counties of countries (FR,US are available)
```php
\RtExtends\Useful\Location\Country\Fr::counties();
\RtExtends\Useful\Location\Country\Fr::countiesStructured(); // by states
\RtExtends\Useful\Location\Country\Us::counties();
\RtExtends\Useful\Location\Country\Us::countiesStructured(); // by states
```

## Useful\File\Zip
Create zip file

```php

```

Unzip archive
```php

```

## Useful\Data\Fake

### Lorem Ipsum : Paragraph
Generate paragraphs
```php
) with class 'lead'
echo \RtExtends\Useful\Data\Fake::getParagraphLoremIpsum(3,"p",array("class"=>"lead"));

// generate 2 divs (element

) with class 'alert alert-info'
echo \RtExtends\Useful\Data\Fake::getParagraphLoremIpsum(2,"div",array("class"=>"alert alert-info"));
?>
```

If you don't need to get a list of random paragraphs, just do like that
```php
echo \RtExtends\Useful\Data\Fake::getParagraphLoremIpsum(2,"div",array("class"=>"alert alert-info"),false);
?>
```

### Lorem Ipsum : Words
```php
// simple use : 10 words
echo \RtExtends\Useful\Data\Fake::getWordLoremIpsum(10);

// include in tag (ex:

"John Doe"
));

$subMessageSecond = new FlashMessageSub();
$subMessageSecond->setMessage("Please check here %(url)s"); // first message
$subMessageSecond->setVariables(array(
'url' => "http://php.net"
));

$flashMessage = new FlashMessage();
$flashMessage->setTitle("Sorry");
$flashMessage->setMessages(array($subMessage,$subMessageSecond));

$this->flashmessenger()->addErrorMessage($flashMessage);
```

### Date view helper : countdown
```php
date_default_timezone_set('America/Montreal');
$date = new \DateTime('NOW');

// countdown result in ARRAY
$countDown = $this->rtCountDown($date->getTimestamp()+167890, $date->getTimestamp(), true);

// string (is default param)
$countDown = $this->rtCountDown($date->getTimestamp()+167890, $date->getTimestamp(), false);
<<<<<<< HEAD
```

### BodyClasses view helper

Inside your controller

```php
$this->BodyClasses()->addClass("my-css-class");
$this->BodyClasses()->addClass(array("my-css-class", "blue-bck"));
```

Inside your view script
```php
?>


=======
>>>>>>> FETCH_HEAD
```

## Snippets
Some quick snippets
### Snippets\Form\Element
```php
$form = new Form('my-form');
$form->add(\RtExtends\Snippets\Form\Element\Csrf::getCreateElementArray("crsf", 60*60));
/* generate
$form->add(array(
'type' => 'Zend\Form\Element\Csrf',
'name' => 'crsf',
'options' => array(
'csrf_options' => array(
'timeout' => '3600'
)
)
));*/
```

### Snippets\Js
Jquery
```php

```
Jquery UI
```php

```

# Thanks
---------------------------------------
* To [Saša Stamenković](https://github.com/umpirsky) for [his great module](https://github.com/umpirsky/country-list).
* To [Thomas Schultz](https://twitter.com/#!/daspecster) for [Ziptastic](http://daspecster.github.io/ziptastic/index.html) and don't forget to support this module!

# Todo
---------------------------------------
* many other validators
* Fake data (more tool)
* some good helpers
* Currency
* More countries