Turning XSD into documentation file

This XSD stuff is not for me, f*cking unreadable:/ Thanks god there is a stylesheet that makes it prettier, like a documentation.
First download it http://www.w3.org/2008/09/xsd.xsl due browser cross domain restriction, so you can avoid (fastest solution for me now)

Unsafe attempt to load URL https://www.w3.org/2008/09/xsd.xsl from frame with URL http://localhost/kovoinox/temp/stock.xsd. Domains, protocols and ports must match.

After download put it next to the XSD file and insert the following line as the 2nd row in the XSD:

<?xml version="1.0" encoding="Windows-1250"?>
<?xml-stylesheet type="text/xsl" href="xsd.xsl"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 ... the rest of the XSD ...

After opening the XSD in the browser you get a much nicer interpretation.


Solution from http://stackoverflow.com/questions/6686124/how-to-turn-xsd-files-into-documentation-file

Posted in bestpractice, Uncategorized | Tagged , , | Leave a comment

Solving No matching global declaration available for the validation root.

Had to create a custom XML for Pohoda accounting software, but hit some errors so I decided to make a PHPUnit test for validating it against its XML schema definition (XSD) with PHPs DOMDocument::schemaValidate

/** @test */
public function validateStockXml()
$xml = new \DOMDocument();

$isValid = $xml->schemaValidate('http://www.stormware.cz/schema/version_2/stock.xsd');

Stuck with the following error for a couple of hours😦

Element ‘{http://www.stormware.cz/schema/version_2/data.xsd}dataPack’: No matching global declaration available for the validation root.

After a lot of trial and error decided to google more and more I finally found the solution at http://www.scriptscoop.me/t/81762e7e42e7/php-xml-validation-no-matching-global-declaration-available-for-the-valida.html

Changing the schema URL to http://www.stormware.cz/schema/version_2/data.xsd instead using http://www.stormware.cz/schema/version_2/stock.xsd solved the problem.

So easy, huh🙂 Always learning.

Posted in php, Uncategorized | Tagged , , , , | Leave a comment

Improving PHP autocompletion in VIM

After watching VIM as PHP IDE I revisited my config, specifically pimped ctags according to articles Vim Autocompletion for PHP and Exuberant ctags with PHP in Vim

So my current $HOME/.ctags is:

--regex-PHP=/abstract class ([^ ]*)/\1/c/
--regex-PHP=/interface ([^ ]*)/\1/c/
--regex-PHP=/trait ([^ ]*)/\1/c/
--regex-PHP=/(public |static |abstract |protected |private )+ function +([^ \(]*)/\2/f/
Posted in Uncategorized, vim | Tagged , , | Leave a comment

Enabling MySQL 5.7 query logging on OSX

I got used to it that sometimes I need to check the queries run by MySQL. After clean OSX upgrade I forgot to enable it.

So I added the following to /etc/mysql/my.cnf:



general_log = 1
general_log_file = /usr/local/mysql/data/mysqld.query.log

slow_query_log = 1
long_query_time = 1 # second
slow_query_log_file = /usr/local/mysql/data/mysqld.slow.log
log_queries_not_using_indexes = 0

The default one that comes with the package is at /usr/local/mysql/support-files/my-default.cnf

There’s also an option to set logging via SQL queries.

Posted in log, Uncategorized | Tagged , , | Leave a comment

Using PHPloy for PHP project deployment in sync with GIT repo

Finally had some time to work on my deployment workflow and its automation.

Special thanks to Baki for PHPloy I think it might be a good candidate for Continuous Delivery solution for some use cases.

Made a simple screencast using it (no sound, enjoy it with your favourit music🙂

For a more robust tool check out deployer

Posted in php, Uncategorized | Tagged , , | Leave a comment

Link checking as cache warmup or integration testing

Sometimes I use wget awesome recursive spidering (crawling) feature (alternative to linkchecker) beside broken link check also for cache warmup or looking for PHP errors after commit.

On production for some projects I use PHP error logging into separate log directory per day:

if (!is_dir(DOC_ROOT.'/log')) {

ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 1);
ini_set('error_log', DOC_ROOT.'/log/php-error-'.date('d').'.log');

So after crawling I check if there is a log file.
And the wget shell script that crawls the site is:


timestamp=$(date +"%Y%m%d%H%M%S")

cd /tmp
time wget -4 --spider -r --delete-after \
     --no-cache --no-http-keep-alive --no-dns-cache \
     -U "Wget" \
     -X/blog \
     http://www.example.com -o"/tmp/wget-example-com-$timestamp.log"

During the crawling your site is hit and cache is generated if you have some implemented, for example phpFastCache.
I just only crawl via IPv4 without HTTP keep alive (only for better performance). Setting some unique user agent is good for parsing in access_log, too.
-X stands for excluding, also handy for improving performance on large sites.
-o outputs the wget status report where you can search for HTTP status codes as 404, 403, 500, etc.
Remember the excluded path, you might run another wget in parallel if you need. Unfortunately wget can’t run parallel threads as of writing.

Posted in bestpractice, Uncategorized | Tagged , , , , | Leave a comment

Hack Symfony2 database password for admin

Had to get in the admin of a Symfony2 version 2.6 app and I had only code and database access.
I just added some rows to the loginAction() method to get the salt and password for my own plaintext password.

public function loginAction(Request $request) {
    $user = new User();
    $plainPassword = 'YOUR_pass_HERE';
    $encoder = $this->container->get('security.password_encoder');
    echo 'Salt:<br>'.$user->getSalt();
    echo '<br>Password:<br>'.$encoder->encodePassword($user, $plainPassword);

    // loginAction code continues ....


Symfony2 password change

Salt and encoded password for user

Changed the values in the database and login was successful.
You could also flush and persist the new user if you would like, but username needs to be set.
For more help visit the awesome docs page at http://symfony.com/doc/2.6/components/security/authentication.html#using-password-encoders

Posted in symfony | Tagged , | Leave a comment