Home: https://itools.search.ch/
License: https://itools.search.ch/git/itools.git/plain/COPYING
Installing: git clone https://itools.search.ch/git/itools.git
Reference: https://itools.search.ch/
Tutorial video: https://itools.search.ch/2007-11-14-itools-demo.mov
ITools is a collection of PHP functions and classes which make a few common tasks in PHP easier. It works in PHP 7.0 and up.
Our examples omit array() around function parameters and use dangling commas. To get that, you can either use our just-in-time syntax converter or use our patch for PHP (see https://cschneid.com/php/ for info). To use the syntax converter, see the chapter about it_auto_prepend.php below.
If you include this with the PHP auto_prepend_file ini setting you get the following benefits:
# Put this line in .htaccess or httpd.conf to set up ITools environment php_value auto_prepend_file YOUR_PATH_TO_ITOOLS/it_auto_prepend.php
php_value auto_prepend_file YOUR_PATH_TO_ITOOLS/it_auto_prepend.php
it_html creates a global function for each common html tag. Those functions accept variable arguments, key=>value pairs are considered attributes.
new it_html; # Not necessary if using it_auto_prepend.php echo html( head('title' => "welcome earth"), body( p('style' => "margin:1em", a('href' => U("https://google.com/search", 'q' => "Hello World"), "Hello World"), ), ), );
echo html( head('title' => "welcome earth"), body( p('style' => "margin:1em", a('href' => U("https://google.com/search", 'q' => "Hello World"), "Hello World"), ), ), );
head('title' => "welcome earth"), body( p('style' => "margin:1em", a('href' => U("https://google.com/search", 'q' => "Hello World"), "Hello World"), ), ), );
body( p('style' => "margin:1em", a('href' => U("https://google.com/search", 'q' => "Hello World"), "Hello World"), ), ), );
p('style' => "margin:1em", a('href' => U("https://google.com/search", 'q' => "Hello World"), "Hello World"), ), ), );
a('href' => U("https://google.com/search", 'q' => "Hello World"), "Hello World"), ), ), );
), ), );
), );
);
The dbi object is a simple mysql interface. For each table in your database, a class is created automatically. Queries are encoded as arrays which ensures correct quoting, see select(). Errors are by default reported within dbi. If "dyncols" exists in schema, unknown columns are mapped to a dynamic column.
it_dbi::createclasses(); # Not necessary if using it_auto_prepend.php $record = new T_Customers('ID' => 'mueller'); $record->update('email' => "mueller@spam.com"); $response = "Email added for $record->name"; # Using Iterators: foreach (new T_Customers as $customer) { ... } # Iterate all customers foreach (new T_Customers('age' => 42) as $customer) { ... } foreach (new T_Customers as $id => $customer) { ... } # $id = $customer->_key # ... you can iterate over any query (also multiple times): $customers->select('age' => 42); foreach ($customers as $customer) { foo($customer); } foreach ($customers as $customer) { bar($customer); }
$record = new T_Customers('ID' => 'mueller'); $record->update('email' => "mueller@spam.com"); $response = "Email added for $record->name"; # Using Iterators: foreach (new T_Customers as $customer) { ... } # Iterate all customers foreach (new T_Customers('age' => 42) as $customer) { ... } foreach (new T_Customers as $id => $customer) { ... } # $id = $customer->_key # ... you can iterate over any query (also multiple times): $customers->select('age' => 42); foreach ($customers as $customer) { foo($customer); } foreach ($customers as $customer) { bar($customer); }
$record->update('email' => "mueller@spam.com"); $response = "Email added for $record->name"; # Using Iterators: foreach (new T_Customers as $customer) { ... } # Iterate all customers foreach (new T_Customers('age' => 42) as $customer) { ... } foreach (new T_Customers as $id => $customer) { ... } # $id = $customer->_key # ... you can iterate over any query (also multiple times): $customers->select('age' => 42); foreach ($customers as $customer) { foo($customer); } foreach ($customers as $customer) { bar($customer); }
$response = "Email added for $record->name"; # Using Iterators: foreach (new T_Customers as $customer) { ... } # Iterate all customers foreach (new T_Customers('age' => 42) as $customer) { ... } foreach (new T_Customers as $id => $customer) { ... } # $id = $customer->_key # ... you can iterate over any query (also multiple times): $customers->select('age' => 42); foreach ($customers as $customer) { foo($customer); } foreach ($customers as $customer) { bar($customer); }
# Using Iterators: foreach (new T_Customers as $customer) { ... } # Iterate all customers foreach (new T_Customers('age' => 42) as $customer) { ... } foreach (new T_Customers as $id => $customer) { ... } # $id = $customer->_key # ... you can iterate over any query (also multiple times): $customers->select('age' => 42); foreach ($customers as $customer) { foo($customer); } foreach ($customers as $customer) { bar($customer); }
foreach (new T_Customers as $customer) { ... } # Iterate all customers foreach (new T_Customers('age' => 42) as $customer) { ... } foreach (new T_Customers as $id => $customer) { ... } # $id = $customer->_key # ... you can iterate over any query (also multiple times): $customers->select('age' => 42); foreach ($customers as $customer) { foo($customer); } foreach ($customers as $customer) { bar($customer); }
foreach (new T_Customers('age' => 42) as $customer) { ... } foreach (new T_Customers as $id => $customer) { ... } # $id = $customer->_key # ... you can iterate over any query (also multiple times): $customers->select('age' => 42); foreach ($customers as $customer) { foo($customer); } foreach ($customers as $customer) { bar($customer); }
foreach (new T_Customers as $id => $customer) { ... } # $id = $customer->_key # ... you can iterate over any query (also multiple times): $customers->select('age' => 42); foreach ($customers as $customer) { foo($customer); } foreach ($customers as $customer) { bar($customer); }
# ... you can iterate over any query (also multiple times): $customers->select('age' => 42); foreach ($customers as $customer) { foo($customer); } foreach ($customers as $customer) { bar($customer); }
$customers->select('age' => 42); foreach ($customers as $customer) { foo($customer); } foreach ($customers as $customer) { bar($customer); }
foreach ($customers as $customer) { foo($customer); } foreach ($customers as $customer) { bar($customer); }
foreach ($customers as $customer) { bar($customer); }
it_text finds the best language to use from browser and override settings. It then reads texts.php in the format documented in the constructor. You can then use T() to translate a label. Unknown labels are reported using it::error()
echo T('hello') . ' ' . Q($customer->name); echo T('greeting', 'name' => $customer->name);
echo T('greeting', 'name' => $customer->name);
it_debug is used for debugging. The function ED($foo, $bar) echoes the values of $foo and $bar AND prepends it with the names of the variables. EDX() does the same and exits. EDC('verbose', $foo) only echoes if $GLOBALS['debug_verbose'] is set. it_debug::backtrace() outputs a compact stackdump.
ED($foo, $bar); # echoes name and value of $foo and $bar EDC('verbose', $foo);
EDC('verbose', $foo);
it.class provides various statically callable functions. The main groups are:
$from = it::match('From: (.*)', $mail); $page = it::replace('<.*?>' => '', ' +' => ' ', $page); it::error('title'=>"cannot connect", 'id'=>"db"); # suppress sporadic errors it::fatal("internal error"); $diff = it::exec("diff -wu {old} {new}", 'old' => $old, 'new' => $new); it::imageconvert('in' => "src.jpg", 'out' => "dst.jpg", 'size' => "80x80");
$page = it::replace('<.*?>' => '', ' +' => ' ', $page); it::error('title'=>"cannot connect", 'id'=>"db"); # suppress sporadic errors it::fatal("internal error"); $diff = it::exec("diff -wu {old} {new}", 'old' => $old, 'new' => $new); it::imageconvert('in' => "src.jpg", 'out' => "dst.jpg", 'size' => "80x80");
it::error('title'=>"cannot connect", 'id'=>"db"); # suppress sporadic errors it::fatal("internal error"); $diff = it::exec("diff -wu {old} {new}", 'old' => $old, 'new' => $new); it::imageconvert('in' => "src.jpg", 'out' => "dst.jpg", 'size' => "80x80");
it::fatal("internal error"); $diff = it::exec("diff -wu {old} {new}", 'old' => $old, 'new' => $new); it::imageconvert('in' => "src.jpg", 'out' => "dst.jpg", 'size' => "80x80");
$diff = it::exec("diff -wu {old} {new}", 'old' => $old, 'new' => $new); it::imageconvert('in' => "src.jpg", 'out' => "dst.jpg", 'size' => "80x80");
it::imageconvert('in' => "src.jpg", 'out' => "dst.jpg", 'size' => "80x80");
Helper functions dealing with URLs.
$filename = it_url::get_cache( 'url' => "https://static.php.net/www.php.net/images/php.gif", 'timeout' => 5, 'cachedir' => $_SERVER['DOCUMENT_ROOT'] . "/cache", );
'url' => "https://static.php.net/www.php.net/images/php.gif", 'timeout' => 5, 'cachedir' => $_SERVER['DOCUMENT_ROOT'] . "/cache", );
'timeout' => 5, 'cachedir' => $_SERVER['DOCUMENT_ROOT'] . "/cache", );
'cachedir' => $_SERVER['DOCUMENT_ROOT'] . "/cache", );
This allows maintaining session cookies and authentication status for users. Not documented yet, check the source.
This will parse an XML string and returns a tree of PHP objects; similar to simplexml, supports a streaming mode for huge XML files. Not documented yet, check the source.