function test()
 {
     $app = new \Silex\Application();
     $app->get('/foo', function () {
     })->bind('foo');
     $app->flush();
     $mock = $this->getMock('\\FrozenSilex\\Freezer', array('freezeRoute'), array($app));
     $mock->expects($this->once())->method('freezeRoute');
     $generator = new FreezingUrlGenerator(new UrlGenerator($app['routes'], $app['request_context']), $mock);
     $generator->generate('foo');
 }
 * @param $data
 * @return string
 */
function buildMessage($message, $data)
{
    $params = ['conversionMessages' => $data['conversionMessages'], 'visitor_fullName' => $data['visitor']['fullName'], 'visitor_city' => $data['visitor']['city'], 'visitor_region' => $data['visitor']['region'], 'visitor_countryCode' => $data['visitor']['countryCode'], 'visitor_conversationBeginPage' => isset($data['visitor']['conversationBeginPage']) ? $data['visitor']['conversationBeginPage'] : '', 'visitor_phoneNumber' => isset($data['visitor']['phoneNumber']) ? $data['visitor']['phoneNumber'] : '', 'visitor_shopDomain' => isset($data['visitor']['customFields']['shopDomain']) ? $data['visitor']['customFields']['shopDomain'] : ''];
    $search = [];
    $replace = [];
    foreach ($params as $key => $value) {
        $search[] = '{{' . $key . '}}';
        $replace[] = $value;
    }
    return str_replace($search, $replace, $message);
}
$app->get('/', function () use($app) {
    return 'Setup olark webhook to this url';
});
$app->post('/', function (Request $request) use($app) {
    // Handle Olark webhook
    $data = json_decode($request->request->get('data'), true);
    // Stop if visitor email not found
    if (!isset($data['visitor']['emailAddress'])) {
        return new JsonResponse(['success' => false, 'error' => 'Visitor email is required']);
    }
    // Build conversion_messages
    $conversionMessages = '';
    $offline = false;
    // If visitor full name not defined
    if (!isset($data['visitor']['fullName'])) {
        $data['visitor']['fullName'] = 'Visitor';
    }
Exemple #3
0
<?php

require '../vendor/autoload.php';
$app = new Silex\Application();
$app['debug'] = true;
// Register the monolog logging service
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => 'php://stderr'));
// Register view rendering
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/views'));
// Our web handlers
$app->get('/', function () use($app) {
    $app['monolog']->addDebug('logging output.');
    return $app['twig']->render('index.twig');
});
$app->get('/page2', function () use($app) {
    $app['monolog']->addDebug('logging output.');
    return $app['twig']->render('page2.twig');
});
$app->run();
Exemple #4
0
/**
 * simple web app that returns info on a subnet through a JSON api
 *
 * @licence GPLv3
 * @author Lucas Bickel <*****@*****.**>
 */
require_once __DIR__ . '/../vendor/autoload.php';
$app = new Silex\Application();
#$app['debug'] = true;
$app['cache_ttl'] = 86400;
$app->register(new Silex\Provider\RoutingServiceProvider());
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../app/views'));
$app->register(new Silex\Provider\HttpCacheServiceProvider(), array('http_cache.cache_dir' => __DIR__ . '/../app/cache/', 'http_cache.options' => ['default_ttl' => $app['cache_ttl']]));
$app->get('/', function () use($app) {
    return $app['twig']->render('index.html.twig');
})->bind('home');
$app->get('/swagger.json', function () use($app) {
    return new Symfony\Component\HttpFoundation\Response($app['twig']->render('swagger.json.twig'), 200, ['Content-Type' => 'application/json']);
})->bind('swagger');
$app->get('/apis.json', function () use($app) {
    return new Symfony\Component\HttpFoundation\Response($app['twig']->render('apis.json.twig'), 200, ['Content-Type' => 'application/json']);
})->bind('apisjson');
$app->get('/subnet/{ip}/{mask}', function ($ip, $mask) use($app) {
    $subnet = $ip . '/' . $mask;
    try {
        $subnet_info = IPTools\Network::parse($subnet)->info;
        unset($subnet_info['class']);
    } catch (Exception $e) {
        $app->abort(400, $e->getMessage());
    }
Exemple #5
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Contact.php";
session_start();
//creates 'list_of_contacts' array if SESSION is empty
if (empty($_SESSION['list_of_contacts'])) {
    $_SESSION['list_of_contacts'] = array();
}
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
//root or homepage route
$app->get("/", function () use($app) {
    return $app['twig']->render('contacts.html.twig', array('contacts' => Contact::getAll()));
});
//saves a new contact and routes the user to /create_contact
$app->post("/create_contact", function () use($app) {
    $contact = new Contact($_POST['create_name'], $_POST['create_phone'], $_POST['create_address']);
    $contact->save();
    return $app['twig']->render('create_contact.html.twig', array('contacts' => Contact::getAll()));
});
//deletes ALL contacts and routes user to /delete_contacts
$app->post('/delete_contacts', function () use($app) {
    Contact::deleteAll();
    return $app['twig']->render('delete_contacts.html.twig');
});
return $app;
Exemple #6
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => array('driver' => 'pdo_sqlite', 'path' => __DIR__ . '/../db/worldcup.db')));
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => array(__DIR__ . '/View')));
$app->get('/', function () use($app) {
    $eventDao = new \Mila\DAO\eventDAO($app['db']);
    return $app['twig']->render('index.twig', array('events' => $eventDao->fetchAll()));
});
$app->get('/event/{id}', function ($id) use($app) {
    $eventDao = new \Mila\DAO\eventDAO($app['db']);
    return $app['twig']->render('event.twig', array('event' => $eventDao->fetchById($id)));
});
$app->get('/hello/{name}', function ($name) use($app) {
    return $app['twig']->render('hello.twig', array('name' => $name));
});
$app->get('/teams', function () use($app) {
    $dao = new \Mila\DAO\teamDAO($app['db']);
    return $app['twig']->render('teams.twig', array('teams' => $dao->fetchAll()));
});
return $app;
Exemple #7
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/cd.php";
$app = new Silex\Application();
$app->get("/", function () {
    $first_cd = new CD("Master of Reality", "Black Sabbath", "images/reality.jpg", 10.99);
    $second_cd = new CD("Electric Ladyland", "Jimi Hendrix", "images/ladyland.jpg", 10.99);
    $third_cd = new CD("Nevermind", "Nirvana", "images/nevermind.jpg", 10.99);
    $fourth_cd = new CD("IDGI", "The Internets", "images/default.jpg", 49.99);
    $cds = array($first_cd, $second_cd, $third_cd, $fourth_cd);
    $output = "";
    foreach ($cds as $album) {
        $output = $output . "<div class='row'>\n                <div class='col-md-6'>\n                    <img src=" . $album->getCoverArt() . ">\n                </div>\n                <div class='col-md-6'>\n                    <p>" . $album->getTitle() . "</p>\n                    <p>By " . $album->getArtist() . "</p>\n                    <p>\$" . $album->getPrice() . "</p>\n                </div>\n            </div>\n            ";
    }
    return $output;
});
return $app;
require_once __DIR__ . '../../vendor/autoload.php';
require_once '../src/Guestbook/Helpers/Form.php';
require_once '../src/Guestbook/Helpers/ModelFactory.php';
require_once '../src/Guestbook/Models/GuestBookFileModel.php';
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), ['twig.path' => '../src/views']);
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app->register(new \Silex\Provider\FormServiceProvider());
$app->register(new Silex\Provider\TranslationServiceProvider(), ['translator.domains' => []]);
$app['debug'] = true;
/**
 * index Action
 */
$app->get('/symfony/', function () use($app) {
    $objModel = GuestBook\Helpers\ModelFactory::getGuestBookModel();
    return $app['twig']->render('index.html.twig', ['entries' => (array) $objModel->getAllEntries()]);
})->bind('home');
/**
 * add action
 */
$app->get('/symfony/add', function () use($app) {
    return $app['twig']->render('add.html.twig', ['form' => GuestBook\Helpers\Form::getGuestBookForm($app)->createView()]);
})->bind('add');
/**
* Save Action
*/
$app->post('/symfony/save', function () use($app) {
    $objModel = GuestBook\Helpers\ModelFactory::getGuestBookModel();
    $objFormBuilder = GuestBook\Helpers\Form::getGuestBookForm($app);
    $objFormBuilder->handleRequest(\Symfony\Component\HttpFoundation\Request::createFromGlobals());
    if ($objFormBuilder->isValid()) {
Exemple #9
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/RepeatCounter.php";
// Silex and Twig framworks for organization.
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
//Set path to homepage.
$app->get("/", function () use($app) {
    return $app['twig']->render('counter_form.html.twig');
});
//Set path to results page. Push users input through countRepeats method and return results.
$app->get("/results", function () use($app) {
    $counter = new RepeatCounter();
    $counter_result = $counter->countRepeats($_GET['word'], $_GET['phrase']);
    return $app['twig']->render('counter_results.html.twig', array('result' => $counter_result));
});
return $app;
Exemple #10
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Task.php";
require_once __DIR__ . "/../src/Category.php";
$app = new Silex\Application();
$app["debug"] = true;
$server = 'mysql:host=localhost;dbname=todo';
$username = '******';
$password = '******';
//setting up connection to our database
$DB = new PDO($server, $username, $password);
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get("/", function () use($app) {
    $person = "will ferrel";
    $person2 = 'linda';
    return $app['twig']->render('index.html.twig', array('best_friend' => $person, 'mom' => $person2));
});
$app->get("/tasks", function () use($app) {
    return $app['twig']->render('tasks.html.twig', array('tasks' => Task::getAll()));
});
$app->post("/tasks", function () use($app) {
    $task = new Task($_POST['description']);
    $task->save();
    return $app['twig']->render('tasks.html.twig', array('newtask' => $task, 'tasks' => Task::getAll()));
});
$app->get("/categories", function () use($app) {
    return $app['twig']->render('categories.html.twig', array('categories' => Category::getAll()));
});
$app->post("/categories", function () use($app) {
    $category = new Category($_POST['name']);
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use TwitterOAuth\Auth\ApplicationOnlyAuth;
use TwitterOAuth\Serializer\ArraySerializer;
$credentials = ['consumer_key' => "q76Uz7tqlYNMRkjc2kBsAFsv5", 'consumer_secret' => "j1nDGT3uRRJQKtLy3dyjPjCuBUexXKFZc1vqPi2lY7B6Gx7Xwd"];
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../'));
$app->get('/', function () use($app) {
    return $app['twig']->render('index.twig');
});
$app->get('/get-tweet/{username}', function ($username) use($app, $credentials) {
    $auth = new ApplicationOnlyAuth($credentials, new ArraySerializer());
    $params = array('screen_name' => $username, 'count' => 50, 'exclude_replies' => true);
    $tweets = $auth->get('statuses/user_timeline', $params);
    //echo '<pre>'; print_r($auth->getHeaders()); echo '</pre>';
    //echo '<pre>'; print_r($response); echo '</pre><hr />';
    return makeTweet($tweets);
});
function makeTweet($tweets)
{
    $commonWords = getCommonWords($tweets);
    $sentence = createSentence($commonWords);
    $sentence = $sentence . " " . getRandomHashtag();
    return json_encode($sentence);
}
function getCommonWords($tweets)
{
    $words = getWordCounts($tweets);
    $words = removeStupidWords($words);
Exemple #12
0
$snippets_model = new Snippets_model($pdo);
$app = new Silex\Application();
$app['debug'] = true;
// Twig
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/views'));
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
// Used for requests
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
$app->before(function () use($app, $snippets_model) {
    $categories = $snippets_model->get_categories();
    $app["twig"]->addGlobal("categories", $categories);
});
$app->get('/', function ($page) use($app, $snippets_model) {
    $snippets = $snippets_model->get_all();
    $pages = $snippets_model->get_pages_all();
    $app["twig"]->addGlobal("actualPage", array("page" => "home", "category" => "all"));
    return $app['twig']->render('snippets.twig', array('snippets' => $snippets, "pages" => $pages));
})->value('page', 1)->bind('home');
$app->get('/category/{category}/{page}', function ($category = "all", $page = 1) use($app, $snippets_model) {
    if ($category == "all") {
        $snippets = $snippets_model->get_all($page);
        $pages = $snippets_model->get_pages_all($page);
        $cat_details = array('slug' => 'all', 'title' => 'All', 'count' => $snippets_model->get_snippets_count());
    } else {
        $cat_details = $snippets_model->get_cat_details($category);
        $cat_details = $cat_details[0];
        $snippets = $snippets_model->get_by_category($category, $page);
        $pages = $snippets_model->get_pages_by_category($cat_details['id'], $page);
    }
    $app["twig"]->addGlobal("actualPage", array("page" => "category", "category" => $category));
    return $app['twig']->render('snippets.twig', array('snippets' => $snippets, "pages" => $pages, 'catdetails' => $cat_details));
Exemple #13
0
require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Brand.php";
require_once __DIR__ . "/../src/Store.php";
$app = new Silex\Application();
$app['debug'] = true;
$server = 'mysql:host=localhost;dbname=shoes';
$username = '******';
$password = '******';
$DB = new PDO($server, $username, $password);
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
use Symfony\Component\HttpFoundation\Request;
Request::enableHttpMethodParameterOverride();
//Routes
$app->get('/', function () use($app) {
    return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'brands' => Brand::getAll()));
});
$app->post('/add_store', function () use($app) {
    $id = null;
    $store_name = $_POST['store_name'];
    $new_store = new Store($store_name, $id);
    $new_store->save();
    return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'brands' => Brand::getAll()));
});
$app->post('/delete_stores', function () use($app) {
    Store::deleteAll();
    return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'brands' => Brand::getAll()));
});
$app->post('/add_brand', function () use($app) {
    $id = null;
    $name = $_POST['brand_name'];
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Rectangle.php";
$app = new Silex\Application();
$app->get("/", function () {
    return "Home";
});
$app->get("/new_rectangle", function () {
    return "<!DOCTYPE html>\n        <html>\n        <head>\n            <link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css'>\n            <title>Make a rectangle!</title>\n        </head>\n        <body>\n            <div class='container'>\n                <h1>Geometry Checker</h1>\n                <p>Enter the dimensions of your rectangle to see if it's a square.</p>\n                <form action='/view_rectangle'>\n                    <div class='form-group'>\n                      <label for='length'>Enter the length:</label>\n                      <input id='length' name='length' class='form-control' type='number'>\n                    </div>\n                    <div class='form-group'>\n                      <label for='width'>Enter the width:</label>\n                      <input id='width' name='width' class='form-control' type='number'>\n                    </div>\n                    <button type='submit' class='btn-success'>Create</button>\n                </form>\n            </div>\n        </body>\n        </html>";
});
$app->get("/view_rectangle", function () {
    $my_rectangle = new Rectangle($_GET['length'], $_GET['width']);
    $area = $my_rectangle->getArea();
    if ($my_rectangle->isSquare()) {
        return "<h1>Congratulations! You made a square! Its area is {$area}.</h1>\n                    <a href='/new_rectangle'>Back!</a>";
    } else {
        return "<h1>Sorry! This isn't a square. Its area is {$area}.</h1>\n            <a href='/new_rectangle'>Back!</a>";
    }
});
return $app;
Exemple #15
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . '/../src/RockPaperScissors.php';
$app = new Silex\Application();
//$app['debug'] = true;
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
//Main page
$app->get("/", function () use($app) {
    return $app['twig']->render('gameselect.html.twig');
});
//Playing the computer
$app->get("/single_player_mode", function () use($app) {
    return $app['twig']->render('oneplayer.html.twig');
});
//Playing your friends or ... enemy
$app->get("/two_player_mode", function () use($app) {
    return $app['twig']->render('ropasc.html.twig');
});
//Results page, tells you who won
$app->get("/winner_results", function () use($app) {
    $new_RockPaperScissors = new RockPaperScissors();
    $player_outcome = $new_RockPaperScissors->play_rockPaperScissors($_GET['player1'], $_GET['player2']);
    return $app['twig']->render('winner_results.html.twig', array('results' => $player_outcome));
});
$app->get("/computer_results", function () use($app) {
    $new_RockPaperScissors = new RockPaperScissors();
    $computer_array = array("rock", "paper", "scissors");
    $outcome = $new_RockPaperScissors->play_rockPaperScissors($_GET['player1'], $computer_array[rand(0, 2)]);
    return $app['twig']->render('winner_results_computer.html.twig', array('results' => $outcome));
});
Exemple #16
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/TitleCaseGenerator.php";
//require_once __DIR__."/../vendor/bin/phpunit";
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get("/", function () use($app) {
    return $app['twig']->render('index.html.twig');
});
$app->get("/view_title_case", function () use($app) {
    $my_TitleCaseGenerator = new TitleCaseGenerator();
    $title_cased_phrase = $my_TitleCaseGenerator->makeTitleCase($_GET['phrase']);
    return $app['twig']->render('title_cased.html.twig', array('result' => $title_cased_phrase));
});
return $app;
Exemple #17
0
require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Book.php";
require_once __DIR__ . "/../src/Patron.php";
require_once __DIR__ . "/../src/Copy.php";
require_once __DIR__ . "/../src/Author.php";
$app = new Silex\Application();
$server = 'mysql:host=localhost;dbname=library';
$username = '******';
$password = '******';
$DB = new PDO($server, $username, $password);
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
use Symfony\Component\HttpFoundation\Request;
Request::enableHttpMethodParameterOverride();
// HOME PAGE - DISPLAYS ADMIN LINK AND PATRON LINK
$app->get('/', function () use($app) {
    return $app['twig']->render('index.html.twig');
});
// ADMIN PAGE - DISPLAYS BOOK CATALOG
$app->get("/main_admin", function () use($app) {
    $books = Book::getAll();
    $authors = Author::getAll();
    return $app['twig']->render("main_admin.html.twig", array('books' => $books, 'authors' => $authors));
});
$app->post("/delete_books", function () use($app) {
    $GLOBALS['DB']->exec("DELETE FROM books;");
    Book::deleteAll();
    return $app['twig']->render('main_admin.html.twig', array('books' => Book::getAll()));
});
//add new book with author
$app->post("/book_added", function () use($app) {
    // create new book from user entry "add book"
Exemple #18
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../src/Coin.php';
// use Symfony\Component\Debug\Debug;
// Debug::enable();
$app = new Silex\Application();
// $app['debug'] = TRUE;
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get('/', function () use($app) {
    return $app['twig']->render('coin.html.twig');
});
$app->get('combination', function () use($app) {
    $my_Coin = new Coin();
    $combinations = $my_Coin->changeDue($_GET['amount']);
    return $app['twig']->render('combination.html.twig', array('combinations' => $combinations));
});
return $app;
Exemple #19
0
                    $error = 'Could not save the password. Please make sure your server can write the directory (<code>/app/config/secure/</code>).';
                }
            } else {
                $error = 'The provided Passwords do not match.';
            }
        }
        return $app['twig']->render('set_pwd.html.twig', array('error' => $error));
    })->bind("home")->method('POST|GET');
    $app->match('/{url}', function (\Symfony\Component\HttpFoundation\Request $request) use($app) {
        return $app->redirect($app['url_generator']->generate('home'));
    })->assert('url', '.+');
    // Match any route;
} else {
    $app->get('/', function () use($app) {
        if (!is_readable(CONFIG_FILE)) {
            throw new \Syonix\LogViewer\Exceptions\ConfigFileMissingException();
        }
        return $app->redirect($app['url_generator']->generate('home'));
    });
    $app->get('/login', function (\Symfony\Component\HttpFoundation\Request $request) use($app) {
        return $app['twig']->render('login.html.twig', array('create_success' => false, 'error' => $app['security.last_error']($request)));
    })->bind("login");
    $app->get('/logs', function () use($app) {
        $viewer = new Syonix\LogViewer\LogViewer($app['config']['logs']);
        $client = $viewer->getFirstClient();
        $log = $client->getFirstLog();
        return $app->redirect($app['url_generator']->generate('log', array('clientSlug' => $client->getSlug(), 'logSlug' => $log->getSlug())));
    })->bind("home");
    $app->get('/logs/{clientSlug}', function ($clientSlug) use($app) {
        $viewer = new Syonix\LogViewer\LogViewer($app['config']['logs']);
        $client = $viewer->getClient($clientSlug);
        $log = $client->getFirstLog();
Exemple #20
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../src/CashMoney.php';
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get("/", function () use($app) {
    return $app['twig']->render('form.html.twig');
});
$app->get("/view_cashmoney", function () use($app) {
    $my_Cash_Money = new CashMoney();
    $your_Cash_Money = $my_Cash_Money->getCashMoney($_GET['cents']);
    $your_Cash_Money = explode(" ", $your_Cash_Money);
    $string = $your_Cash_Money[0] . " 100s, " . $your_Cash_Money[1] . " 50s, " . $your_Cash_Money[2] . " 20s, " . $your_Cash_Money[3] . " 10s " . $your_Cash_Money[4] . " 5s " . $your_Cash_Money[5] . " 1s " . $your_Cash_Money[6] . " quarters, " . $your_Cash_Money[7] . " dimes " . $your_Cash_Money[8] . " nickels, " . $your_Cash_Money[9] . " pennies.";
    return $app['twig']->render('view.html.twig', array('result' => $string));
});
return $app;
Exemple #21
0
<?php

require_once __DIR__ . '/../functions.php';
require_once __DIR__ . '/../silex.phar';
$app = new Silex\Application();
$app->register(new Silex\Extension\TwigExtension(), array('twig.class_path' => __DIR__ . '/../vendor/twig/lib', 'twig.path' => __DIR__ . '/twig'));
$app['autoloader']->registerNamespace('SilexExtension', __DIR__ . '/../src');
$app->register(new SilexExtension\MarkdownExtension(), array('markdown.class_path' => __DIR__ . '/../vendor/knplabs-markdown', 'markdown.features' => array('header' => true, 'list' => true, 'horizontal_rule' => true, 'table' => true, 'foot_note' => true, 'fenced_code_block' => true, 'abbreviation' => true, 'definition_list' => true, 'inline_link' => true, 'reference_link' => true, 'shortcut_link' => true, 'block_quote' => true, 'code_block' => true, 'html_block' => true, 'auto_link' => true, 'auto_mailto' => true, 'entities' => false)));
$app->get('/', function () use($app) {
    return $app['twig']->render('markdown.twig');
});
$app->run();
Exemple #22
0
// link to autoload and CONTACT CLASS
require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Contact.php";
// needed to start the session
session_start();
// load list of contacts
if (empty($_SESSION['list_of_contacts'])) {
    $_SESSION['list_of_contacts'] = array();
}
//load silex and turn on debug
$app = new Silex\Application();
$app['debug'] = true;
// needed for twig
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
// used to link to home page
$app->get('/', function () use($app) {
    // get all conacts via twig
    return $app['twig']->render('contacts.html.twig', array('contacts' => Contact::getAll()));
});
//post a new contact
$app->post('/create_contact', function () use($app) {
    $contact = new Contact($_POST['name'], $_POST['phone'], $_POST['address']);
    $contact->save();
    return $app['twig']->render('create_contact.html.twig', array('newcontact' => $contact));
});
// delte a contact
$app->post('/delete_contacts', function () use($app) {
    Contact::deleteALL();
    return $app['twig']->render('delete_contacts.html.twig');
});
return $app;
Exemple #23
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/CoinCombo.php";
$app = new Silex\Application();
$app["debug"] = true;
//make sure this is AFTER APP STARTS
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . "/../views"));
$app->get("/", function () use($app) {
    return $app['twig']->render('index.html.twig');
});
$app->get("/result", function () use($app) {
    $my_coinCombo = new CoinCombo();
    $initialAmt = $my_coinCombo->divideOutput($_GET['amount']);
    return $app['twig']->render('index.html.twig', array('resultAmt' => $initialAmt));
});
return $app;
Exemple #24
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Task.php";
require_once __DIR__ . "/../src/Category.php";
$app = new Silex\Application();
$app['debug'] = true;
$server = 'mysql:host=localhost;dbname=to_do';
$username = '******';
$password = '******';
$DB = new PDO($server, $username, $password);
use Symfony\Component\HttpFoundation\Request;
Request::enableHttpMethodParameterOverride();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get("/", function () use($app) {
    return $app['twig']->render('index.html.twig', array('categories' => Category::getAll(), 'tasks' => Task::getAll()));
});
$app->get("/tasks", function () use($app) {
    return $app['twig']->render('tasks.html.twig', array('tasks' => Task::getAll()));
});
$app->get("/categories", function () use($app) {
    return $app['twig']->render('categories.html.twig', array('categories' => Category::getAll()));
});
$app->get("/categories/{id}", function ($id) use($app) {
    $category = Category::find($id);
    return $app['twig']->render('category.html.twig', array('category' => $category, 'tasks' => $category->getTasks(), 'all_tasks' => Task::getAll()));
});
$app->post("/tasks", function () use($app) {
    $description = $_POST['description'];
    $due_date = $_POST['due_date'];
    $task = new Task($description, $due_date);
Exemple #25
0
require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Task.php";
require_once __DIR__ . "/../src/Category.php";
//session_start();
//if (empty($_SESSION['list_of_tasks'])) {
//    $_SESSION['list_of_tasks'] = array();
//}
$app = new Silex\Application();
$server = 'mysql:host=localhost;dbname=to_do';
$username = '******';
$password = '******';
$DB = new PDO($server, $username, $password);
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get("/", function () use($app) {
    return $app['twig']->render('index.html.twig');
});
$app->get("/tasks", function () use($app) {
    return $app['twig']->render('tasks.html.twig', array('tasks' => Task::getAll()));
});
$app->get("/categories", function () use($app) {
    return $app['twig']->render('categories.html.twig', array('categories' => Category::getAll()));
});
$app->post("/tasks", function () use($app) {
    $task = new task($_POST['description']);
    $task->save();
    return $app['twig']->render('tasks.html.twig', array('tasks' => Task::getAll()));
});
$app->post("/delete_tasks", function () use($app) {
    Task::deleteAll();
    return $app['twig']->render('index.html.twig');
Exemple #26
0
<?php

use Igorw\Middleware\Stack;
use Symfony\Component\HttpFoundation\Request;
// Default configuration
require_once 'config.init.php';
// Actual configuration
require_once '/var/baztille-data/config/config.php';
// Require Silex
require_once $g_config['silex_autoload_location'];
require_once 'version.php';
$app = new Silex\Application();
$app['debug'] = false;
///////////////// Service routing /////////////////////////////
$app->get('/', function () use($app) {
    return file_get_contents('landing/index.html');
});
$app->get('/confirm', function () use($app) {
    return file_get_contents('landing/confirm.html');
});
$app->get('/thankyou', function () use($app) {
    return file_get_contents('landing/thankyou.html');
});
$app->get('/faq', function () use($app) {
    return file_get_contents('landing/faq.html');
});
$app->get('/template', function () use($app) {
    return file_get_contents('landing/elements.html');
});
$app->register(new Silex\Provider\SessionServiceProvider(), array('session.storage.options' => array('cookie_domain' => $g_config['app_domain'])));
$app->run();
Exemple #27
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/car.php";
$app = new Silex\Application();
$app->get("/", function () {
    return "\n        <!DOCTYPE html>\n        <html>\n        <head>\n          <link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css'>\n          <title>CARS!</title>\n        </head>\n        <body>\n            <div class='container'>\n                <h1>Enter Max Mileage and Max Price</h1>\n                <form action='/view_cars'>\n                    <div class='form-group'>\n                        <label for='max_mileage'>Maximum Mileage:</label>\n                        <input id='max_mileage' name='max_mileage' class='form-control' type='number'>\n                    </div>\n                    <div class='form-group'>\n                        <label for='max_price'>Maximum Price:</label>\n                        <input id='max_price' name='max_price' class='form-control' type='number'>\n                    </div>\n                    <button type='submit' class='btn'>Go!</button>\n                </form>\n            </div>\n        </body>\n        </html>";
});
$app->get("/view_cars", function () {
    $firstCar = new Car("Tesla X", 100000, 0, "pictures/tesla.jpg");
    $secondCar = new Car("Honda Accord", 10000, 50000, "pictures/honda.jpg");
    $thirdCar = new Car("Ferrari Enzo", 350000, 15000, "pictures/ferrari-enzo.jpg");
    $fourthCar = new Car("Toyota Corolla", 6000, 100000, "pictures/toyota-corolla.jpg");
    $fifthCar = new Car("Mitsubishi Lancer", 20000, 100, "pictures/mitsubishi-lancer.jpg");
    $allCars = array($firstCar, $secondCar, $thirdCar, $fourthCar, $fifthCar);
    function searchCar($maxPrice, $maxMileage, $cars)
    {
        $searchedCars = array();
        foreach ($cars as $car) {
            $price = $car->getPrice();
            $mileage = $car->getMiles();
            if ($price <= $maxPrice && $mileage <= $maxMileage) {
                array_push($searchedCars, $car);
            }
        }
        return $searchedCars;
    }
    $matchingCars = searchCar($_GET["max_price"], $_GET["max_mileage"], $allCars);
    $output = '';
    $output .= '<h1>Available Cars</h1>' . "\n ";
    if (empty($matchingCars)) {
Exemple #28
0
    }
    /*==========  Sectors  ==========*/
    public function getSectors()
    {
        $sql = "SELECT * FROM company_sectors";
        return $this->db->fetchAll($sql);
    }
}
$DataProvider = new DataProvider($app['db']);
/*===============================
=            CLIENTS            =
===============================*/
$app->get('/clients', function () use($app, $DataProvider) {
    $clients = $DataProvider->getClients();
    $response = new JsonResponse();
    $response->setEncodingOptions(JSON_NUMERIC_CHECK);
    $response->setData($clients);
    return $response;
});
$app->get('/client/{clientId}', function ($clientId) use($app, $DataProvider) {
    $clientDetails = $DataProvider->getClient($clientId);
    if (!$clientDetails) {
        return $app->json(['errorMessage' => 'Client Not Found'], 404);
    }
    return $app->json($clientDetails);
});
$app->put('/client/{clientId}', function (Request $request, $clientId) use($app, $DataProvider) {
    $clientDetails = $DataProvider->getClient($clientId);
    if (!$clientDetails) {
        return $app->json(['errorMessage' => 'Client Not Found'], 404);
    }
Exemple #29
0
require_once __DIR__ . '/../vendor/autoload.php';
define('GOOGLE_API_KEY', '389361308386-0lc02qa6gs3q0pf7j86hhj169to93jh9.apps.googleusercontent.com');
define('GOOGLE_API_SECRET', 'nijEu5O05kXBLQv9pawzrF9Z');
$app = new Silex\Application();
error_reporting(E_ALL);
ini_set('display_errors', 1);
$app['debug'] = true;
$app->register(new Gigablah\Silex\OAuth\OAuthServiceProvider(), array('oauth.services' => array('Google' => array('key' => GOOGLE_API_KEY, 'secret' => GOOGLE_API_SECRET, 'scope' => array('https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile'), 'user_endpoint' => 'https://www.googleapis.com/oauth2/v1/userinfo'))));
// Provides URL generation
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
// Provides CSRF token generation
$app->register(new Silex\Provider\FormServiceProvider());
// Provides session storage
$app->register(new Silex\Provider\SessionServiceProvider(), array('session.storage.save_path' => __DIR__ . '/../cache'));
// Provides Twig template engine
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__));
$app->register(new Silex\Provider\SecurityServiceProvider(), array('security.firewalls' => array('default' => array('pattern' => '^/', 'anonymous' => true, 'oauth' => array('failure_path' => '/', 'with_csrf' => true), 'logout' => array('logout_path' => '/logout', 'with_csrf' => true), 'users' => new Gigablah\Silex\OAuth\Security\User\Provider\OAuthInMemoryUserProvider())), 'security.access_rules' => array(array('^/auth', 'ROLE_USER'))));
$app->before(function (Symfony\Component\HttpFoundation\Request $request) use($app) {
    $token = $app['security']->getToken();
    $app['user'] = null;
    if ($token && !$app['security.trust_resolver']->isAnonymous($token)) {
        $app['user'] = $token->getUser();
    }
});
$app->get('/', function () use($app) {
    return $app['twig']->render('index.twig', array('login_paths' => $app['oauth.login_paths'], 'logout_path' => $app['url_generator']->generate('logout', array('_csrf_token' => $app['oauth.csrf_token']('logout')))));
});
$app->match('/logout', function () {
})->bind('logout');
$app->run();
Exemple #30
0
require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Brand.php";
require_once __DIR__ . "/../src/Store.php";
$app = new Silex\Application();
$app['debug'] = true;
$server = 'mysql:host=localhost;dbname=shoes';
$username = '******';
$password = '******';
$DB = new PDO($server, $username, $password);
use Symfony\Component\HttpFoundation\Request;
Request::enableHttpMethodParameterOverride();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
//GETS
$app->get("/", function () use($app) {
    return $app['twig']->render('index.html.twig');
});
$app->get("/stores", function () use($app) {
    return $app['twig']->render('stores.html.twig', array('stores' => Store::getAll()));
});
$app->get("/brands", function () use($app) {
    return $app['twig']->render('brands.html.twig', array('brands' => Brand::getAll()));
});
//POSTS
$app->post("/stores", function () use($app) {
    $store = new Store($_POST['store_name']);
    $store->save();
    return $app['twig']->render('stores.html.twig', array('stores' => Store::getAll()));
});
$app->post("/brands", function () use($app) {
    $brand = new Brand($_POST['brand_name']);