diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..998f3fd --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/public/htaccess + +/vendor/ + +/.idea/ diff --git a/Comment.php b/Comment.php deleted file mode 100644 index bff2e3c..0000000 --- a/Comment.php +++ /dev/null @@ -1,29 +0,0 @@ -db = new PDO($dsn, $dbconfig['user'], $dbconfig['pass']); - $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - } - - public function create() { - if(!isset($_SESSION['AUTHENTICATED'])) { - die('not auth'); - header("Location: /"); - exit; - } - - $sql = 'INSERT INTO comment (created_by, created_on, story_id, comment) VALUES (?, NOW(), ?, ?)'; - $stmt = $this->db->prepare($sql); - $stmt->execute(array( - $_SESSION['username'], - $_POST['story_id'], - filter_input(INPUT_POST, 'comment', FILTER_SANITIZE_FULL_SPECIAL_CHARS), - )); - header("Location: /story/?id=" . $_POST['story_id']); - } - -} \ No newline at end of file diff --git a/Index.php b/Index.php deleted file mode 100644 index a2aded6..0000000 --- a/Index.php +++ /dev/null @@ -1,42 +0,0 @@ -db = new PDO($dsn, $dbconfig['user'], $dbconfig['pass']); - $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - } - - public function index() { - - $sql = 'SELECT * FROM story ORDER BY created_on DESC'; - $stmt = $this->db->prepare($sql); - $stmt->execute(); - $stories = $stmt->fetchAll(PDO::FETCH_ASSOC); - - $content = '
    '; - - foreach($stories as $story) { - $comment_sql = 'SELECT COUNT(*) as `count` FROM comment WHERE story_id = ?'; - $comment_stmt = $this->db->prepare($comment_sql); - $comment_stmt->execute(array($story['id'])); - $count = $comment_stmt->fetch(PDO::FETCH_ASSOC); - $content .= ' -
  1. - ' . $story['headline'] . '
    - ' . $story['created_by'] . ' | ' . $count['count'] . ' Comments | - ' . date('n/j/Y g:i a', strtotime($story['created_on'])) . ' -
  2. - '; - } - - $content .= '
'; - - require 'layout.phtml'; - } -} - diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..4d2879c --- /dev/null +++ b/composer.json @@ -0,0 +1,23 @@ +{ + "name": "lynxtdc/oop", + "description": "Master OOP Class work", + "license": "MIT", + "authors": [ + { + "name": "Paul McGrane", + "email": "service@lynxtdc.com" + } + ], + "minimum-stability": "dev", + "require": { + "aura/di": "~2.1" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "autoload":{ + "psr-4": { + "Masterclass\\" : "src/" + } + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..80776f4 --- /dev/null +++ b/composer.lock @@ -0,0 +1,1023 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "aa39f992e17da61ac802584c69a27076", + "packages": [ + { + "name": "aura/di", + "version": "2.1.0", + "source": { + "type": "git", + "url": "https://github.com/auraphp/Aura.Di.git", + "reference": "68ffa4f76a2525ce3b7d211c09c71709a882556c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/auraphp/Aura.Di/zipball/68ffa4f76a2525ce3b7d211c09c71709a882556c", + "reference": "68ffa4f76a2525ce3b7d211c09c71709a882556c", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "aura": { + "type": "library" + }, + "branch-alias": { + "dev-develop-2": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Aura\\Di\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Aura.Di Contributors", + "homepage": "https://github.com/auraphp/Aura.Di/contributors" + } + ], + "description": "Provides a dependency injection container system with native support for constructor- and setter-based injection, lazy-loading of services, and inheritable configuration of setters and constructor params.", + "homepage": "https://github.com/auraphp/Aura.Di", + "keywords": [ + "container", + "dependency injection", + "dependency injection container", + "di", + "di container" + ], + "time": "2014-11-06 18:13:34" + } + ], + "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "3d9669e597439e8d205baf315efb757038fb4dea" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/3d9669e597439e8d205baf315efb757038fb4dea", + "reference": "3d9669e597439e8d205baf315efb757038fb4dea", + "shasum": "" + }, + "require": { + "php": ">=5.3,<8.0-DEV" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2015-01-16 19:29:51" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "09352d340640520f1047ff29f7a8e73129e2eb1c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/09352d340640520f1047ff29f7a8e73129e2eb1c", + "reference": "09352d340640520f1047ff29f7a8e73129e2eb1c", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "suggest": { + "dflydev/markdown": "~1.0", + "erusev/parsedown": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "phpDocumentor": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "mike.vanriel@naenius.com" + } + ], + "time": "2015-02-03 20:57:02" + }, + { + "name": "phpspec/prophecy", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "3a9204c44667c302049ab4eadb02daab789e19ed" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/3a9204c44667c302049ab4eadb02daab789e19ed", + "reference": "3a9204c44667c302049ab4eadb02daab789e19ed", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "phpdocumentor/reflection-docblock": "~2.0", + "sebastian/comparator": "~1.1" + }, + "require-dev": { + "phpspec/phpspec": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "psr-0": { + "Prophecy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2015-02-09 17:43:38" + }, + { + "name": "phpunit/php-code-coverage", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "34cc484af1ca149188d0d9e91412191e398e0b67" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/34cc484af1ca149188d0d9e91412191e398e0b67", + "reference": "34cc484af1ca149188d0d9e91412191e398e0b67", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "phpunit/php-file-iterator": "~1.3", + "phpunit/php-text-template": "~1.2", + "phpunit/php-token-stream": "~1.3", + "sebastian/environment": "~1.0", + "sebastian/version": "~1.0" + }, + "require-dev": { + "ext-xdebug": ">=2.1.4", + "phpunit/phpunit": "~4" + }, + "suggest": { + "ext-dom": "*", + "ext-xdebug": ">=2.2.1", + "ext-xmlwriter": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2015-01-24 10:06:35" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.3.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/acd690379117b042d1c8af1fafd61bde001bf6bb", + "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "File/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2013-10-10 15:34:57" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "Text/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2014-01-30 17:20:04" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "PHP/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2013-08-02 07:42:54" + }, + { + "name": "phpunit/php-token-stream", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "db32c18eba00b121c145575fcbcd4d4d24e6db74" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/db32c18eba00b121c145575fcbcd4d4d24e6db74", + "reference": "db32c18eba00b121c145575fcbcd4d4d24e6db74", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2015-01-17 09:51:32" + }, + { + "name": "phpunit/phpunit", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "7c1de6a854a36ba330b352a005a4f5f928619f53" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/7c1de6a854a36ba330b352a005a4f5f928619f53", + "reference": "7c1de6a854a36ba330b352a005a4f5f928619f53", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-pcre": "*", + "ext-reflection": "*", + "ext-spl": "*", + "php": ">=5.3.3", + "phpspec/prophecy": "~1.3.1", + "phpunit/php-code-coverage": "~2.0", + "phpunit/php-file-iterator": "~1.3", + "phpunit/php-text-template": "~1.2", + "phpunit/php-timer": "~1.0", + "phpunit/phpunit-mock-objects": "~2.3", + "sebastian/comparator": "~1.1", + "sebastian/diff": "~1.2", + "sebastian/environment": "~1.2", + "sebastian/exporter": "~1.2", + "sebastian/global-state": "~1.0", + "sebastian/version": "~1.0", + "symfony/yaml": "~2.1|~3.0" + }, + "suggest": { + "phpunit/php-invoker": "~1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.7.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2015-02-09 06:38:12" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "b752b41e3fead4feee99f3a2f2972cef517abb8b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/b752b41e3fead4feee99f3a2f2972cef517abb8b", + "reference": "b752b41e3fead4feee99f3a2f2972cef517abb8b", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "~1.0,>=1.0.2", + "php": ">=5.3.3", + "phpunit/php-text-template": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "4.4.*@dev" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2015-01-18 10:44:19" + }, + { + "name": "sebastian/comparator", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "1dd8869519a225f7f2b9eb663e225298fade819e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1dd8869519a225f7f2b9eb663e225298fade819e", + "reference": "1dd8869519a225f7f2b9eb663e225298fade819e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.2", + "sebastian/exporter": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "http://www.github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2015-01-29 16:28:08" + }, + { + "name": "sebastian/diff", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "6dc90302a4cdf8486c221a0ad3a4da53859fcfa5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/6dc90302a4cdf8486c221a0ad3a4da53859fcfa5", + "reference": "6dc90302a4cdf8486c221a0ad3a4da53859fcfa5", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "http://www.github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2015-01-01 09:20:29" + }, + { + "name": "sebastian/environment", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5a8c7d31914337b69923db26c4221b81ff5a196e", + "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2015-01-01 10:01:08" + }, + { + "name": "sebastian/exporter", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "84839970d05254c73cde183a721c7af13aede943" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/84839970d05254c73cde183a721c7af13aede943", + "reference": "84839970d05254c73cde183a721c7af13aede943", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/recursion-context": "~1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2015-01-27 07:23:06" + }, + { + "name": "sebastian/global-state", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "007c441df427cf0e175372fcbb9d196bce7eb743" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/007c441df427cf0e175372fcbb9d196bce7eb743", + "reference": "007c441df427cf0e175372fcbb9d196bce7eb743", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2015-01-20 04:09:31" + }, + { + "name": "sebastian/recursion-context", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "3989662bbb30a29d20d9faa04a846af79b276252" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/3989662bbb30a29d20d9faa04a846af79b276252", + "reference": "3989662bbb30a29d20d9faa04a846af79b276252", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2015-01-24 09:48:32" + }, + { + "name": "sebastian/version", + "version": "1.0.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "a77d9123f8e809db3fbdea15038c27a95da4058b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/a77d9123f8e809db3fbdea15038c27a95da4058b", + "reference": "a77d9123f8e809db3fbdea15038c27a95da4058b", + "shasum": "" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2014-12-15 14:25:24" + }, + { + "name": "symfony/yaml", + "version": "2.6.x-dev", + "target-dir": "Symfony/Component/Yaml", + "source": { + "type": "git", + "url": "https://github.com/symfony/Yaml.git", + "reference": "60ed7751671113cf1ee7d7778e691642c2e9acd8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/60ed7751671113cf1ee7d7778e691642c2e9acd8", + "reference": "60ed7751671113cf1ee7d7778e691642c2e9acd8", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.6-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Yaml\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Symfony Yaml Component", + "homepage": "http://symfony.com", + "time": "2015-01-25 04:39:26" + } + ], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/config.php b/config.php new file mode 100644 index 0000000..24a22f6 --- /dev/null +++ b/config.php @@ -0,0 +1,22 @@ + array( + 'user' => 'homestead', + 'pass' => 'secret', + 'host' => 'localhost', + 'name' => 'oop_class', + ), + + 'routes' => array( + '' => 'Masterclass\Controller\Index:index', + 'story' => 'Masterclass\Controller\Story:index', + 'story/create' => 'Masterclass\Controller\Story:create', + 'comment/create' => 'Masterclass\Controller\Comment:create', + 'user/create' => 'Masterclass\Controller\User:create', + 'user/account' => 'Masterclass\Controller\User:account', + 'user/login' => 'Masterclass\Controller\User:login', + 'user/logout' => 'Masterclass\Controller\User:logout', + ), +); diff --git a/config.php-init b/config.php-init deleted file mode 100644 index c20d865..0000000 --- a/config.php-init +++ /dev/null @@ -1,22 +0,0 @@ - array( - 'user' => '', - 'pass' => '', - 'host' => '', - 'name' => '', - ), - - 'routes' => array( - '' => 'index/index', - 'story' => 'story/index', - 'story/create' => 'story/create', - 'comment/create' => 'comment/create', - 'user/create' => 'user/create', - 'user/account' => 'user/account', - 'user/login' => 'user/login', - 'user/logout' => 'user/logout', - ), -); diff --git a/public/htaccess-dist b/public/htaccess-dist deleted file mode 100644 index 2aa2589..0000000 --- a/public/htaccess-dist +++ /dev/null @@ -1,8 +0,0 @@ - -RewriteEngine On -RewriteBase / -RewriteRule ^index\.php$ - [L] -RewriteCond %{REQUEST_FILENAME} !-f -RewriteCond %{REQUEST_FILENAME} !-d -RewriteRule . /index.php [L] - \ No newline at end of file diff --git a/public/index.php b/public/index.php index 92c2321..42e864a 100644 --- a/public/index.php +++ b/public/index.php @@ -2,13 +2,9 @@ session_start(); -$config = require_once('../config.php'); -require_once '../MasterController.php'; +require '../vendor/autoload.php'; -require_once '../Comment.php'; -require_once '../User.php'; -require_once '../Story.php'; -require_once '../Index.php'; +$config = require_once('../config.php'); -$framework = new MasterController($config); +$framework = new \Masterclass\MasterController($config); echo $framework->execute(); \ No newline at end of file diff --git a/src/Controller/Comment.php b/src/Controller/Comment.php new file mode 100644 index 0000000..c2313f9 --- /dev/null +++ b/src/Controller/Comment.php @@ -0,0 +1,31 @@ +commentModel = new CommentModel($config); + } + + + public function create() { + if(!isset($_SESSION['AUTHENTICATED'])) { + die('not auth'); + header("Location: /"); + exit; + } + + $this->commentModel->postNewComment($_SESSION['username'], $_POST['story_id'], $_POST['comment']); + + header("Location: /story/?id=" . $_POST['story_id']); + } + +} \ No newline at end of file diff --git a/src/Controller/Index.php b/src/Controller/Index.php new file mode 100644 index 0000000..5512f43 --- /dev/null +++ b/src/Controller/Index.php @@ -0,0 +1,41 @@ +story = new Story($config); + } + + public function index() { + + $stories = $this->story->getStories(); + + $content = '
    '; + + foreach($stories as $story) { + + $content .= ' +
  1. + ' . $story['headline'] . '
    + ' . $story['created_by'] . ' | ' . $story['count'] . ' Comments | + ' . date('n/j/Y g:i a', strtotime($story['created_on'])) . ' +
  2. + '; + } + + $content .= '
'; + + require '../layout.phtml'; + } +} + diff --git a/Story.php b/src/Controller/Story.php similarity index 63% rename from Story.php rename to src/Controller/Story.php index 3e4eaad..45999ca 100644 --- a/Story.php +++ b/src/Controller/Story.php @@ -1,12 +1,26 @@ db = new PDO($dsn, $dbconfig['user'], $dbconfig['pass']); - $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + /** + * @var StoryModel + */ + protected $storyModel; + + /** + * @var array + */ + protected $config; + + public function __construct($config) + { + $this->config = $config; + $this->storyModel = new StoryModel($config); + $this->commentModel = new Comment($config); } public function index() { @@ -15,21 +29,15 @@ public function index() { exit; } - $story_sql = 'SELECT * FROM story WHERE id = ?'; - $story_stmt = $this->db->prepare($story_sql); - $story_stmt->execute(array($_GET['id'])); - if($story_stmt->rowCount() < 1) { + $story = $this->storyModel->getStory($_GET['id']); + if(!$story) { header("Location: /"); exit; } - $story = $story_stmt->fetch(PDO::FETCH_ASSOC); - - $comment_sql = 'SELECT * FROM comment WHERE story_id = ?'; - $comment_stmt = $this->db->prepare($comment_sql); - $comment_stmt->execute(array($story['id'])); - $comment_count = $comment_stmt->rowCount(); - $comments = $comment_stmt->fetchAll(PDO::FETCH_ASSOC); + + $comments = $this->commentModel->getCommentsForStory($story['id']); + $comment_count = count($comments); $content = ' ' . $story['headline'] . '
@@ -55,7 +63,7 @@ public function index() { '; } - require_once 'layout.phtml'; + require_once '../layout.phtml'; } @@ -71,15 +79,7 @@ public function create() { !filter_input(INPUT_POST, 'url', FILTER_VALIDATE_URL)) { $error = 'You did not fill in all the fields or the URL did not validate.'; } else { - $sql = 'INSERT INTO story (headline, url, created_by, created_on) VALUES (?, ?, ?, NOW())'; - $stmt = $this->db->prepare($sql); - $stmt->execute(array( - $_POST['headline'], - $_POST['url'], - $_SESSION['username'], - )); - - $id = $this->db->lastInsertId(); + $id = $this->storyModel->createNewStory($_POST['headline'], $_POST['url'], $_SESSION['username']); header("Location: /story/?id=$id"); exit; } @@ -95,7 +95,7 @@ public function create() { '; - require_once 'layout.phtml'; + require_once '../layout.phtml'; } } \ No newline at end of file diff --git a/User.php b/src/Controller/User.php similarity index 65% rename from User.php rename to src/Controller/User.php index b2ca74c..7d0ad0d 100644 --- a/User.php +++ b/src/Controller/User.php @@ -1,14 +1,18 @@ db = new PDO($dsn, $dbconfig['user'], $dbconfig['pass']); - $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + /** + * @var + */ + protected $userModel; + + public function __construct($config) + { + $this->userModel = new UserModel($config); } public function create() { @@ -34,24 +38,13 @@ public function create() { } if(is_null($error)) { - $check_sql = 'SELECT * FROM user WHERE username = ?'; - $check_stmt = $this->db->prepare($check_sql); - $check_stmt->execute(array($_POST['username'])); - if($check_stmt->rowCount() > 0) { + if($check_username = $this->userModel->checkUsername($_POST['username'])) { $error = 'Your chosen username already exists. Please choose another.'; } } if(is_null($error)) { - $params = array( - $_POST['username'], - $_POST['email'], - md5($_POST['username'] . $_POST['password']), - ); - - $sql = 'INSERT INTO user (username, email, password) VALUES (?, ?, ?)'; - $stmt = $this->db->prepare($sql); - $stmt->execute($params); + $this->userModel->createUser($_POST['username'], $_POST['email'], $_POST['password']); header("Location: /user/login"); exit; } @@ -69,7 +62,7 @@ public function create() { '; - require_once 'layout.phtml'; + require_once '../layout.phtml'; } @@ -86,21 +79,13 @@ public function account() { $error = 'The password fields were blank or they did not match. Please try again.'; } else { - $sql = 'UPDATE user SET password = ? WHERE username = ?'; - $stmt = $this->db->prepare($sql); - $stmt->execute(array( - md5($_SESSION['username'] . $_POST['password']), // THIS IS NOT SECURE. - $_SESSION['username'], - )); + $this->userModel->updatePassword($_SESSION['username'], $_POST['password']); $error = 'Your password was changed.'; } } - - $dsql = 'SELECT * FROM user WHERE username = ?'; - $stmt = $this->db->prepare($dsql); - $stmt->execute(array($_SESSION['username'])); - $details = $stmt->fetch(PDO::FETCH_ASSOC); - + + $details = $this->userModel->getUserInfo($_SESSION['username']); + $content = ' ' . $error . '
@@ -114,21 +99,16 @@ public function account() { '; - require_once 'layout.phtml'; + require_once '../layout.phtml'; } public function login() { $error = null; // Do the login if(isset($_POST['login'])) { - $username = $_POST['user']; - $password = $_POST['pass']; - $password = md5($username . $password); // THIS IS NOT SECURE. DO NOT USE IN PRODUCTION. - $sql = 'SELECT * FROM user WHERE username = ? AND password = ? LIMIT 1'; - $stmt = $this->db->prepare($sql); - $stmt->execute(array($username, $password)); - if($stmt->rowCount() > 0) { - $data = $stmt->fetch(PDO::FETCH_ASSOC); + + + if($data = $this->userModel->validateUser($_POST['user'], $_POST['pass'])) { session_regenerate_id(); $_SESSION['username'] = $data['username']; $_SESSION['AUTHENTICATED'] = true; @@ -149,7 +129,7 @@ public function login() { '; - require_once('layout.phtml'); + require_once('../layout.phtml'); } diff --git a/MasterController.php b/src/MasterController.php similarity index 93% rename from MasterController.php rename to src/MasterController.php index 895be4d..17b6dc8 100644 --- a/MasterController.php +++ b/src/MasterController.php @@ -1,5 +1,7 @@ $controller_method); } } diff --git a/src/Model/Comment.php b/src/Model/Comment.php new file mode 100644 index 0000000..9094166 --- /dev/null +++ b/src/Model/Comment.php @@ -0,0 +1,51 @@ +db = new PDO($dsn, $dbconfig['user'], $dbconfig['pass']); + $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } + + /** + * @param $id + * @return array + */ + public function getCommentsForStory($id){ + $comment_sql = 'SELECT * FROM comment WHERE story_id = ?'; + $comment_stmt = $this->db->prepare($comment_sql); + $comment_stmt->execute(array($id)); + $comments = $comment_stmt->fetchAll(PDO::FETCH_ASSOC); + return $comments; + } + + /** + * @param $username + * @param $story_id + * @param $comment + * @return bool + */ + public function postNewComment($username, $story_id, $comment) + { + $sql = 'INSERT INTO comment (created_by, created_on, story_id, comment) VALUES (?, NOW(), ?, ?)'; + $stmt = $this->db->prepare($sql); + return $stmt->execute(array( + $username, + $story_id, + filter_var($comment, FILTER_SANITIZE_FULL_SPECIAL_CHARS) + )); + } + +} \ No newline at end of file diff --git a/src/Model/Story.php b/src/Model/Story.php new file mode 100644 index 0000000..d01e49f --- /dev/null +++ b/src/Model/Story.php @@ -0,0 +1,65 @@ +db = new PDO($dsn, $dbconfig['user'], $dbconfig['pass']); + $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } + + /** + * @return array + */ + public function getStories() + { + $sql = 'SELECT * FROM story ORDER BY created_on DESC'; + $stmt = $this->db->prepare($sql); + $stmt->execute(); + $stories = $stmt->fetchAll(PDO::FETCH_ASSOC); + + foreach($stories as $key => $story){ + $comment_sql = 'SELECT COUNT(*) as `count` FROM comment WHERE story_id = ?'; + $comment_stmt = $this->db->prepare($comment_sql); + $comment_stmt->execute(array($story['id'])); + $count = $comment_stmt->fetch(PDO::FETCH_ASSOC); + $stories[$key]['count'] = $count['count']; + } + return $stories; + } + + /** + * @param $id + * @return mixed + */ + public function getStory($id) + { + $story_sql = 'SELECT * FROM story WHERE id = ?'; + $story_stmt = $this->db->prepare($story_sql); + $story_stmt->execute(array($id)); + return $story_stmt->fetch(PDO::FETCH_ASSOC); + } + + public function createNewStory($headline, $url, $creator) + { + $sql = 'INSERT INTO story (headline, url, created_by, created_on) VALUES (?, ?, ?, NOW())'; + $stmt = $this->db->prepare($sql); + $stmt->execute(array( + $headline, + $url, + $creator + )); + + return $this->db->lastInsertId(); + } + +} \ No newline at end of file diff --git a/src/Model/User.php b/src/Model/User.php new file mode 100644 index 0000000..439efa3 --- /dev/null +++ b/src/Model/User.php @@ -0,0 +1,84 @@ +db = new PDO($dsn, $dbconfig['user'], $dbconfig['pass']); + $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } + + /** + * @param $username + * @return mixed + */ + public function checkUsername($username) + { + $check_sql = 'SELECT * FROM user WHERE username = ?'; + $check_stmt = $this->db->prepare($check_sql); + $check_stmt->execute(array($username)); + return $check_stmt->fetchAll(PDO::FETCH_ASSOC); + } + + /** + * @param $username + * @param $email + * @param $password + * @return string + */ + public function createUser($username, $email, $password) + { + $sql = 'INSERT INTO user (username, email, password) VALUES (?, ?, ?)'; + $stmt = $this->db->prepare($sql); + $stmt->execute(array( + $username, + $email, + md5($username . $password) + )); + + return $this->db->lastInsertId(); + } + + /** + * @param $username + * @param $password + * @return bool + */ + public function updatePassword($username, $password) + { + $sql = 'UPDATE user SET password = ? WHERE username = ?'; + $stmt = $this->db->prepare($sql); + $stmt->execute(array( + md5($username . $password), // THIS IS NOT SECURE. + $username, + )); + return true; + } + + public function getUserInfo($username) + { + $dsql = 'SELECT * FROM user WHERE username = ?'; + $stmt = $this->db->prepare($dsql); + $stmt->execute(array($username)); + return $stmt->fetch(PDO::FETCH_ASSOC); + } + + public function validateUser($username, $password) + { + $password = md5($username . $password); // THIS IS NOT SECURE. DO NOT USE IN PRODUCTION. + $sql = 'SELECT * FROM user WHERE username = ? AND password = ? LIMIT 1'; + $stmt = $this->db->prepare($sql); + $stmt->execute(array($username, $password)); + return $stmt->fetch(PDO::FETCH_ASSOC); + } + +} \ No newline at end of file