Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP interview assignment

  • 21-09-2010 3: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