Ejemplo n.º 1
0
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('aboutPenguins.twig', <<<EOF
{{ include('_cannotFly.twig', { 'reason': 'little wings' }) }}
EOF
);
    }
Ejemplo n.º 2
0
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('fallCollection.twig', <<<EOF
<header>
    {{ fallCollectionPromoDescription }}
</header>
EOF
);
    }
Ejemplo n.º 3
0
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('fallCollection.twig', <<<EOF
<h1>
    {{ collectionTitle }}
</h1>
EOF
);
    }
Ejemplo n.º 4
0
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('fallCollection.twig', <<<EOF
<h3>
    The sale starts: {{ saleStartsAt|date('F jS') }}
</h3>
EOF
);
    }
Ejemplo n.º 5
0
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('fallCollection.twig', <<<EOF
{% for product in products %}
    <h3>{{ product }}</h3>
{% endfor %}
EOF
);
    }
Ejemplo n.º 6
0
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('singleItem.twig', <<<EOF
<h1>{{ product.name }}</h1>

<div>
    {{ product.description|raw }}
</div>
EOF
);
    }
Ejemplo n.º 7
0
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('fallCollection.twig', <<<EOF
<h2 class="featured-product">
    {{ products[randomProductKey] }}
</h2>

{% for product in products %}
    <h3>{{ product }}</h3>
{% endfor %}
EOF
);
    }
Ejemplo n.º 8
0
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('fallCollection.twig', <<<EOF
{% for product in products %}
    <h3>
        {{ product.name }}

        <div class="stock-status">
            {{ product.quantity > 0 ? product.quantity : 'Out of stock' }}
        </div>
    </h3>
{% endfor %}
EOF
);
    }
Ejemplo n.º 9
0
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('layout.twig', <<<EOF
<html>
    <head>
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    </head>
    <body>
        <div class="container">
            <div class="row">
                {% if block('sidebar') %}
                <div class="col-xs-3">
                    {% block sidebar %}{% endblock %}
                </div>
                {% endif %}

                <div class="{{ block('sidebar') ? 'col-xs-9' : 'col-xs-12' }}">
                    {% block body %}{% endblock %}
                </div>
            </div>
        </div>
    </body>
</html>
EOF
);
    }
Ejemplo n.º 10
0
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('fallCollection.twig', <<<EOF
{% extends 'layout.twig' %}

{% block footer_caption %}
    Winter is coming! Get your pants!
{% endblock %}

{% block body %}
    <h1>{{ fallCollectionTitle }}</h1>
{% endblock %}
EOF
);
        $correctAnswer->setFileContents('layout.twig', <<<EOF
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Penguins Pants Plus!</title>
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    </head>
    <body>
        {% block body %}{% endblock %}

        <footer>
            {% block footer_caption %}
                You're hip, you're cool, you're a penguin!
            {% endblock %}
        </footer>
    </body>
</html>
EOF
);
    }
Ejemplo n.º 11
0
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('fallCollection.twig', <<<EOF
{% for product in products %}
    <h3>
        {{ product.name }}

        <span class="price">{{ product.price }}</span>
    </h3>
{% else %}
    <div class="alert alert-warning">
        No pants for you!
    </div>
{% endfor %}
EOF
);
    }
Ejemplo n.º 12
0
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('_featuredProduct.twig', <<<EOF
<section class="featured-product">
    This week's featured product is a pin-striped full suit, complete
    with cane, monocle and an elegant pocket watch!

    {% if quantityRemaining is defined and quantityRemaining is not odd %}
    <div class="featured-quantity">
        {{ quantityRemaining }}
    </div>
    {% endif %}

    <button class="btn btn-primary">Buy now</button>
</section>
EOF
);
    }
Ejemplo n.º 13
0
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('fallCollection.twig', <<<EOF
{% for product in products %}
    <h3>
        {{ product.name }}

        <span class="price">{{ product.price }}</span>
    </h3>
{% endfor %}

{% if products|length is odd %}
    <div class="alert alert-info">
        We promise, 1 more pair of pants is coming very soon!
    </div>
{% endif %}
EOF
);
    }
Ejemplo n.º 14
0
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('DeathStarII.php', <<<EOF
<?php

class DeathStarII extends DeathStar
{
    public function getLaserRange()
    {
        return parent::getLaserRange() * 2;
    }
}
EOF
);
    }
Ejemplo n.º 15
0
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('fallCollection.twig', <<<EOF
{% extends 'layout.twig' %}

{% block body %}

    <h1>
        {{ fallCollectionTitle }}
    </h1>

    <div>
        The fall products are coming soon!
    </div>

{% endblock %}
EOF
);
    }
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('fallCollection.twig', <<<EOF
{% extends 'layout.twig' %}

{% block body %}

    <h1>{{ fallCollectionTitle }}</h1>

    <div>The fall products are coming soon!</div>

{% endblock %}
EOF
);
        $correctAnswer->setFileContents('mainCollection.twig', <<<EOF
{% extends 'layout.twig' %}

{% block body %}

    <h1>Welcome to our main collection or products</h1>

    <div>The main products are being updated!</div>

{% endblock %}
EOF
);
        $correctAnswer->setFileContents('layout.twig', <<<EOF
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Penguins Pants Plus!</title>
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    </head>
    <body>
        <header>Penguins Pants Plus!</header>

        {% block body %}{% endblock %}
    </body>
</html>
EOF
);
    }
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('index.php', <<<EOF
<?php

require 'DeathStar.php';
require 'DeathStarII.php';

\$deathStar = new DeathStarII();
EOF
);
        $correctAnswer->setFileContents('DeathStarII.php', <<<EOF
<?php

class DeathStarII extends DeathStar
{
}
EOF
);
    }
Ejemplo n.º 18
0
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('fallCollection.twig', <<<EOF
{% for product in products %}
    <h3>
        {{ product.name }}

        <span class="price">
            {{ product.price }}
        </span>

        <span class="released-at">
            <!-- This calls the getFutureReleaseDate() function on PantsProduct -->
            <!-- even though there isn't actually a futureReleaseDate property -->
            {{ product.futureReleaseDate|date('Y-m-d') }}
        </span>
    </h3>
{% endfor %}
EOF
);
    }
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('fallCollection.twig', <<<EOF
<table>
    <thead>
        <tr>
            <th>Name</th>
            <th>Color</th>
        </tr>
    </thead>
    {% for product in products %}
        <tr>
            <td>{{ product }}</td>
            <td>
                {{ random(['black', 'white', 'green'])|upper }}
            </td>
        </tr>
    {% endfor %}
</table>
EOF
);
    }
Ejemplo n.º 20
0
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('fallCollection.twig', <<<EOF
{% extends 'layout.twig' %}
{% import 'macros.twig' as myMacros %}

{% block body %}
    {{ myMacros.printSizingChart(false) }}

    <h1>{{ fallCollectionTitle }}</h1>
{% endblock %}
EOF
);
        $correctAnswer->setFileContents('mainCollection.twig', <<<EOF
{% extends 'layout.twig' %}
{% import 'macros.twig' as myMacros %}

{% block body %}
    {{ myMacros.printSizingChart(true) }}

    <h1>The Main Collection</h1>
{% endblock %}
EOF
);
        $correctAnswer->setFileContents('macros.twig', <<<EOF
{% macro printSizingChart(showXLColumn) %}
    <table class="sizing-chart">
        <tr>
            <th>S</th>
            <th>M</th>
            <th>L</th>
            {% if showXLColumn %}
                <th>XL</th>
            {% endif %}
        </tr>
        <tr>
            <td>5-15 lbs</td>
            <td>16-35 lbs</td>
            <td>36-60 lbs</td>
            {% if showXLColumn %}
                <td>61-85 lbs</td>
            {% endif %}
        </tr>
    </table>
{% endmacro %}
EOF
);
    }
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('DeathStarII.php', <<<EOF
<?php

class DeathStarII extends DeathStar
{
    public function getWeakness()
    {
        return null;
    }
}
EOF
);
    }
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('DeathStar.php', <<<EOF
<?php

class DeathStar
{
    protected \$planetarySuperLaserRange = 2000000;
}
EOF
);
    }
Ejemplo n.º 23
0
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('fallCollection.twig', <<<EOF
{% extends 'layout.twig' %}

{% block body %}
    {{ include('_featuredProduct.twig') }}

    <h1>{{ fallCollectionTitle }}</h1>
{% endblock %}
EOF
);
        $correctAnswer->setFileContents('mainCollection.twig', <<<EOF
{% extends 'layout.twig' %}

{% block body %}
    {{ include('_featuredProduct.twig') }}

    <h1>The Main Collection</h1>
{% endblock %}
EOF
);
        $correctAnswer->setFileContents('_featuredProduct.twig', <<<EOF
<section class="featured-product">
    This week's featured product is a pin-striped full suit, complete
    with cane, monocle and an elegant pocket watch!

    <button class="btn btn-primary">Buy now</button>
</section>
EOF
);
    }
Ejemplo n.º 24
0
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('DeathStarIII.php', <<<EOF
<?php

class DeathStarIII extends AbstractDeathStar
{
    protected function getLaserRange()
    {
        return 3000;
    }
}
EOF
)->setFileContents('index.php', <<<EOF
<?php

require 'AbstractDeathStar.php';
require 'DeathStarIII.php';

\$deathStar3 = new \\DeathStarIII();

?>

<h3>
    The DeathStar 3 -

    <?php echo \$deathStar3->getDescription() ?>
</h3>
EOF
);
    }
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('Cache.php', <<<EOF
<?php

class Cache
{
    public function fetchFromCache(\$key)
    {
        \$cacheFile = \$this->getCacheFilename(\$key);

        if (file_exists(\$cacheFile)) {
            return file_get_contents(\$cacheFile);
        }

        return false;
    }

    public function saveToCache(\$key, \$val)
    {
        \$cacheFile = \$this->getCacheFilename(\$key);

        if (!file_exists(dirname(\$cacheFile))) {
            mkdir(dirname(\$cacheFile));
        }

        return file_put_contents(\$cacheFile, \$val);
    }

    /**
     * Extra credit private method to avoid duplication
     */
    private function getCacheFilename(\$key)
    {
        return __DIR__.'/cache/'.md5(\$key);
    }
}
EOF
)->setFileContents('StringTransformer.php', <<<EOF
<?php

class StringTransformer
{
    private \$cache;

    public function __construct(Cache \$cache)
    {
        \$this->cache = \$cache;
    }

    public function transformString(\$str)
    {
        if (\$result = \$this->cache->fetchFromCache(\$str)) {
            return \$result;
        }

        \$newStr = '';
        foreach (str_split(strrev(\$str), 2) as \$twoChars) {
            // capitalize the first of 2 characters
            \$newStr .= ucfirst(\$twoChars);
        }

        \$this->cache->saveToCache(\$str, \$newStr);

        return \$newStr;
    }
}
EOF
)->setFileContents('index.php', <<<EOF
<?php

require 'Cache.php';
require 'StringTransformer.php';

\$str = 'Judge me by my size, do you?';

\$transformer = new StringTransformer(new Cache());
var_dump(\$transformer->transformString(\$str));
EOF
);
    }
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('LaserWeapon.php', <<<EOF
<?php

class LaserWeapon implements WeaponInterface
{
    /**
     * @return integer The weapon's range in kilometers
     */
    public function getWeaponRange()
    {
        return 2000;
    }

    /**
     * @return bool Is this weapon effective in space
     */
    public function canBeUsedInSpace()
    {
        return true;
    }

    /**
     * @return integer The amount of damage the weapon will cause against the given material
     */
    public function getWeaponStrengthAgainstMaterial(\$material)
    {
        switch (\$material) {
            case 'deathstar':
                \$damageAmount = 50;
                break;
            case 'spaceship':
                \$damageAmount = 100;
                break;
            default:
                \$damageAmount = 200;
        }

        return \$damageAmount;
    }
}
EOF
)->setFileContents('index.php', <<<EOF
<?php

require 'WeaponInterface.php';
require 'LaserWeapon.php';

\$laserWeapon = new LaserWeapon();

?>

<h1>
    Laser weapon range:
    <?php echo \$laserWeapon->getWeaponRange(); ?>
</h1>
EOF
);
    }
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('SolidPlanet.php', <<<EOF
<?php

class SolidPlanet implements PlanetInterface
{
    private \$radius;

    private \$hexColor;

    public function __construct(\$radius, \$hexColor)
    {
        \$this->radius = \$radius;
        \$this->hexColor = \$hexColor;
    }

    public function getRadius()
    {
        return \$this->radius;
    }

    public function getHexColor()
    {
        return \$this->hexColor;
    }
}
EOF
)->setFileContents('GasPlanet.php', <<<EOF
<?php

class GasPlanet implements PlanetInterface
{
    private \$diameter;

    private \$mainElement;

    public function __construct(\$mainElement, \$diameter)
    {
        \$this->diameter = \$diameter;
        \$this->mainElement = \$mainElement;
    }

    public function getRadius()
    {
        return \$this->diameter / 2;
    }

    public function getHexColor()
    {
        // a "fake" map of elements to colors
        switch (\$this->mainElement) {
            case 'ammonia':
                return '663300';
            case 'hydrogen':
            case 'helium':
                return 'FFFF66';
            case 'methane':
                return '0066FF';
            default:
                return '464646';
        }
    }
}
EOF
)->setFileContents('PlanetRenderer.php', <<<EOF
<?php

class PlanetRenderer
{
    public function render(PlanetInterface \$planet)
    {
        return sprintf(
            '<div style="width: %spx; height: %spx; border-radius: %spx; background-color: #%s;"></div>',
            \$planet->getRadius() * 2,
            \$planet->getRadius() * 2,
            \$planet->getRadius(),
            \$planet->getHexColor()
        );
    }
}
EOF
);
    }
Ejemplo n.º 28
0
    public function configureCorrectAnswer(CorrectAnswer $correctAnswer)
    {
        $correctAnswer->setFileContents('AbstractDeathStar.php', <<<EOF
<?php

abstract class AbstractDeathStar
{
    private \$weaponPower;
    
    public function setWeaponPower(\$power)
    {
        \$this->weaponPower = \$power;
    }

    public function getWeaponPower()
    {
        return \$this->weaponPower;
    }

    public function makeFiringNoise()
    {
        echo 'BOOM x '.\$this->weaponPower;
    }
}
EOF
)->setFileContents('DeathStar.php', <<<EOF
<?php

class DeathStar extends AbstractDeathStar
{
    private \$crewSize;
    
    public function setCrewSize(\$numberOfPeople)
    {
        \$this->crewSize = \$numberOfPeople;
    }
    
    public function getCrewSize()
    {
        return \$this->crewSize;
    }
}
EOF
)->setFileContents('DeathStarII.php', <<<EOF
<?php

class DeathStarII extends AbstractDeathStar
{
    // this DeathStar must *always* have 5000 people on it
    public function getCrewSize()
    {
        return 5000;
    }

    public function makeFiringNoise()
    {
        echo 'SUPER BOOM';
    }
}
EOF
);
    }