Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP interview assignment

  • 21-09-2010 04:30PM
    #1
    Closed Accounts Posts: 698 ✭✭✭


    I had an interview recently and was given the following test to be completed in 1 hour. Can anyone illustrate the best way of refactoring the code?

    Tasks
    • Make any refactoring changes to PHP code / architecture that you think will improve it.
    • Move all of the language-specific content from the public/index.php file into the language/en.php file, following the convention used for the “index_page_title” tag.
    • Add to and extend the library and language code as appropriate.
    • Make any changes to the HTML code in the public/index.php file that you think will improve it.

    public/index.php
    [PHP]<?php
    require_once('../library/Translate.php');
    $myName = 'Andy';
    ?>
    <html>

    <body>

    <b><?php echo htmlentities(translate('index_page_title')); ?></b>

    <hr/>

    I am from the United Kingdom.</b><br/>
    I live in <strong>London</strong>.<br/>
    My favourite search tool is <a href="http://www.google.co.uk">Google</a>.<br/&gt;
    My national flag is <img src="http://footballsuperstars.com/pages/includes/leaderboard/images/Flags/GB.png&quot; alt="United Kingdom flag">.<br/>

    <hr/>

    My Football Superstars main character is called "Arw".<br/>
    <br/>
    Arw's favourite top is her bright pink jacket.<br/>
    Arw celebrates her first competitive goal.<br/>
    Arw buys her first pink jacket.<br/>

    <hr/>

    My Football Superstars alt character is called "Solay".<br/>
    <br/>
    Solay's favourite top is his black Puma shirt.<br/>
    Solay celebrates his first competitive assist.<br/>
    Solay buys his first pair of Puma football boots.<br/>

    </body>

    </html>[/PHP]

    library/Translate.php
    [PHP]<?php

    $languageFile = dirname(__FILE__) .'/../language/en.php';

    function translate($messageId, $params = array()) {
    global $languageFile;
    require $languageFile;
    $str = $messageId;
    if (isset($text[$messageId])) {
    $str = $text[$messageId];
    }
    foreach ($params as $k => $v) {
    $str = str_replace('%%'.$k.'%%', $v, $str);
    }
    return $str;
    }[/PHP]

    language/en.php
    [PHP]<?php

    $text = array(
    'index_page_title' => 'Welcome to the CyberSports technical test, %%NAME%%',
    );
    ?>[/PHP]


Comments

  • Closed Accounts Posts: 103 ✭✭Enter Username


    I take it you didnt get the Job?


  • Closed Accounts Posts: 698 ✭✭✭nitrogen


    I take it you didnt get the Job?

    Don't know yet. Just thought I'd post incase I missed anything.


  • Registered Users, Registered Users 2 Posts: 1,071 ✭✭✭Art_Wolf


    A Person object, with variables for nationality, location, search tool url, search tool and superstar, superstar alt - location in en.php

    Nationality class with name and flag - name in en.php

    SuperStar, subtype of Person with name, favorite top, celebration, purchase, gener - top, celebration, purchase and gender in en.php

    Remaining text in en.php as standard blocks or such


Advertisement