Skip to content

Instantly share code, notes, and snippets.

View useless-stuff's full-sized avatar
🤓
Learning

1317 useless-stuff

🤓
Learning
View GitHub Profile
@useless-stuff
useless-stuff / php_closure.php
Last active February 16, 2016 10:11
PHP - Closure
<?php
/**
* Class Basket
*/
class Basket
{
protected $productsQuantityCollection;
protected $productsCollection;
protected $tax = 1.2;
@useless-stuff
useless-stuff / php_iterator.php
Last active February 16, 2016 10:51
PHP - Iterator
<?php
/**
* Class AdsTypeCollection
*/
class AdsTypeCollection implements Iterator{
const PANORAMA_980x120 = 'PANORAMA_980x120';
const TOP_BANNER = 'TOP_BANNER_930x180';
const NETBOARD = 'NETBOARD_580x400';
const VERTICAL_RECTANGLE = 'VERTICAL_RECTANGLE_240x400';
@useless-stuff
useless-stuff / php_iteratoriterator.php
Created February 11, 2016 12:10
PHP - IteratorIterator
<?php
// IteratorIterator is a wrapper to work with others Iterator
/**
* Class ImagesFilter
*/
class ImagesFilter extends IteratorIterator
{
/**
* @param $status
@useless-stuff
useless-stuff / php_recursive_iterator.php
Last active August 18, 2023 12:54
PHP - Recursive Iterator
<?php
/**
* Class Skills
*/
class Skills implements RecursiveIterator{
protected $data;
protected $position;
/**
* Skills constructor.
@useless-stuff
useless-stuff / php_seekable_iterator.php
Last active February 12, 2016 11:08
PHP - SeekableIterator
<?php
/**
* Class ObjectPicker
*/
class ObjectPicker implements SeekableIterator{
protected $data = array();
protected $position = 0;
/**
@useless-stuff
useless-stuff / php_countable.php
Last active February 12, 2016 11:35
PHP - Countable
<?php
/**
* Class EmployeesCollection
*/
class EmployeesCollection implements Countable
{
protected $employees = array();
/**
@useless-stuff
useless-stuff / php_array_iterator.php
Last active February 12, 2016 14:57
PHP - ArrayIterator
<?php
// Example 1, alphabetic order
$availableServices = ['Building a website', 'SEO', 'SEM', 'Logo design', 'Mobile applications'];
$servicesCollection = new ArrayIterator($availableServices);
$servicesCollection->natsort();
foreach ($servicesCollection as $service) {
print_r((array)$service);
}
/*
@useless-stuff
useless-stuff / php_recursive_array_iterator.php
Last active February 16, 2016 10:03
PHP - RecursiveArrayIterator
<?php
/**
* Class Message
*/
class Message
{
public $title;
public $body;
public $attachments = array();
@useless-stuff
useless-stuff / php_recursive_iterator_iterator.php
Created February 15, 2016 16:10
PHP - Recursive iterator iterator
<?php
$userInput = array(
'user' => array(
'name' => 'Mario',
'surname' => 'Rossi',
'address' => array(
'home' => 'via di qui, 23',
'work' => 'wherever plaza',
)
),
@useless-stuff
useless-stuff / php_filter_iterator.php
Created February 16, 2016 09:56
PHP - Filter iterator
<?php
/**
* Class ServerList
*/
class ServersList extends RecursiveArrayIterator
{
}
/**