Skip to content

Commit bc5cd6c

Browse files
committed
Initial commit of major files
1 parent fdb6a23 commit bc5cd6c

File tree

6 files changed

+334
-0
lines changed

6 files changed

+334
-0
lines changed

CODE_OF_CONDUCT.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
## Our Standards
8+
9+
Examples of behavior that contributes to creating a positive environment include:
10+
11+
* Using welcoming and inclusive language
12+
* Being respectful of differing viewpoints and experiences
13+
* Gracefully accepting constructive criticism
14+
* Focusing on what is best for the community
15+
* Showing empathy towards other community members
16+
17+
Examples of unacceptable behavior by participants include:
18+
19+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
20+
* Trolling, insulting/derogatory comments, and personal or political attacks
21+
* Public or private harassment
22+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
23+
* Other conduct which could reasonably be considered inappropriate in a professional setting
24+
25+
## Our Responsibilities
26+
27+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28+
29+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
## Scope
32+
33+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34+
35+
## Enforcement
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38+
39+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40+
41+
## Attribution
42+
43+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44+
45+
[homepage]: http://contributor-covenant.org
46+
[version]: http://contributor-covenant.org/version/1/4/

src/autoload.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Load the models
4+
*
5+
* Sadly we can't use an autoloader here incase the end-user
6+
* is using one. Multiple autoloaders can cause conflicts
7+
*
8+
* Likel/Session/Handler can be called with the friendly name
9+
* LikelSession, for example:
10+
*
11+
* $session = new LikelSession();
12+
*
13+
* @package php-simple-sessions
14+
* @author Liam Kelly <https://github.com/likel>
15+
* @copyright 2017 Liam Kelly
16+
* @license MIT License <https://github.com/likel/fizz-buzz/blob/master/LICENSE>
17+
* @link https://github.com/likel/php-simple-sessions
18+
* @version 1.0.0
19+
*/
20+
namespace Likel\Session;
21+
22+
// Require the models
23+
require_once(__DIR__ . '/models/Handler.php');
24+
require_once(__DIR__ . '/models/DB.php');
25+
26+
use Likel\Session\Handler as LikelSession;

src/example.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* The index file, we can run our code from here
4+
*
5+
* A program which prints numbers from 1 to 100 with the following conditions:
6+
* multiples of 3 print "Fizz" instead of the number
7+
* multiples of 5 print "Buzz" instead of the number
8+
* multiples of 3 & 5 print "FizzBuzz"
9+
*
10+
* @package fizz-buzz
11+
* @author Liam Kelly <https://github.com/likel>
12+
* @copyright 2017 Liam Kelly
13+
* @license https://github.com/likel/fizz-buzz/blob/master/LICENSE GPL-3.0 License
14+
* @link https://github.com/likel/fizz-buzz
15+
* @version 1.0.0
16+
*/
17+
18+
require_once('autoload.php');
19+
20+
$db = new LikelSession();

src/ini/credentials.ini

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; This .ini file stores the database credentials
2+
;
3+
; Make sure that you set these variables when you install the package on your
4+
; environment. It is highly suggested that you move this .ini file to a location
5+
; not accessible to the public
6+
;
7+
; You can set the .ini path when creating a new LikelSession object like so:
8+
;
9+
; $session = new LikelSession("/path/to/new/ini/credentials.ini");
10+
;
11+
; @package php-simple-sessions
12+
; @author Liam Kelly <https://github.com/likel>
13+
; @copyright 2017 Liam Kelly
14+
; @license MIT License <https://github.com/likel/fizz-buzz/blob/master/LICENSE>
15+
; @link https://github.com/likel/php-simple-sessions
16+
; @version 1.0.0
17+
18+
[likel_db]
19+
host = "localhost"
20+
username = "root"
21+
password = "root"
22+
db_name = "likel_session"
23+
table_prefix = "likel"

src/models/DB.php

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
<?php
2+
/**
3+
* This is the DB object
4+
*
5+
* @package php-simple-sessions
6+
* @author Liam Kelly <https://github.com/likel>
7+
* @copyright 2017 Liam Kelly
8+
* @license MIT License <https://github.com/likel/fizz-buzz/blob/master/LICENSE>
9+
* @link https://github.com/likel/php-simple-sessions
10+
* @version 1.0.0
11+
*/
12+
namespace Likel\Session;
13+
14+
class DB
15+
{
16+
private $dbh;
17+
private $stmt;
18+
19+
public function __construct($credentials_location = __DIR__ . '/../ini/credentials.ini')
20+
{
21+
try {
22+
$db_credentials = parse_ini_file($credentials_location, true);
23+
$this->dbh = loadDatabase($db_credentials["likel_db"]);
24+
} catch (Exception $ex) {
25+
throw $ex;
26+
}
27+
}
28+
29+
private function loadDatabase($credentials) {
30+
if(!empty($credentials["likel_db"])){
31+
try {
32+
$dsn = 'mysql:host=' . $credentials["likel_db"]['host'] . ';dbname=' . $credentials["likel_db"]['db_name'];
33+
34+
$options = array(
35+
PDO::ATTR_PERSISTENT => true,
36+
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
37+
);
38+
39+
$pdo_object = new PDO($dsn, $credentials["likel_db"]['username'], $credentials["likel_db"]['password'], $options);
40+
41+
return $pdo_object;
42+
43+
} catch(PDOException $e) {
44+
throw new Exception('An error occured when attempting to connect to the database.');
45+
}
46+
47+
} else {
48+
throw new Exception('The credential file could not be located or is empty.');
49+
}
50+
}
51+
52+
/**
53+
* Prepare the query from a supplied query string.
54+
*/
55+
public function query($query)
56+
{
57+
$this->stmt = $this->dbh->prepare($query);
58+
}
59+
60+
/**
61+
* Bind properties to the statement.
62+
* E.G. $DB->bind(':fname', 'Liam');
63+
*/
64+
public function bind($param, $value, $type = null)
65+
{
66+
if (is_null($type)) {
67+
switch (true) {
68+
case is_int($value):
69+
$type = PDO::PARAM_INT;
70+
break;
71+
case is_bool($value):
72+
$type = PDO::PARAM_BOOL;
73+
break;
74+
case is_null($value):
75+
$type = PDO::PARAM_NULL;
76+
break;
77+
default:
78+
$type = PDO::PARAM_STR;
79+
}
80+
}
81+
82+
$this->stmt->bindValue($param, $value, $type);
83+
}
84+
85+
/**
86+
* Execute the statement.
87+
* Use result()/results() for insert queries.
88+
*/
89+
public function execute()
90+
{
91+
return $this->stmt->execute();
92+
}
93+
94+
/**
95+
* Return multiple rows.
96+
*/
97+
public function results()
98+
{
99+
$this->execute();
100+
return $this->stmt->fetchAll(PDO::FETCH_ASSOC);
101+
}
102+
103+
/**
104+
* Return a single row.
105+
*/
106+
public function result()
107+
{
108+
$this->execute();
109+
return $this->stmt->fetch(PDO::FETCH_ASSOC);
110+
}
111+
112+
/**
113+
* Return the row count.
114+
*/
115+
public function rowCount()
116+
{
117+
return $this->stmt->rowCount();
118+
}
119+
120+
/**
121+
* Return if rows exists.
122+
*/
123+
public function rowsExist()
124+
{
125+
return $this->rowCount() != 0;
126+
}
127+
128+
/**
129+
* Return the id of the last inserted row.
130+
*/
131+
public function lastInsertId()
132+
{
133+
return $this->dbh->lastInsertId();
134+
}
135+
136+
/**
137+
* Begin a transaction for multiple statements.
138+
*/
139+
public function beginTransaction()
140+
{
141+
return $this->dbh->beginTransaction();
142+
}
143+
144+
/**
145+
* Commit the transaction for multiple statements.
146+
*/
147+
public function endTransaction()
148+
{
149+
return $this->dbh->commit();
150+
}
151+
152+
/**
153+
* Roll back the transaction.
154+
*/
155+
public function cancelTransaction()
156+
{
157+
return $this->dbh->rollBack();
158+
}
159+
160+
/**
161+
* Return the table name with prefix
162+
*/
163+
public function tb($tablename)
164+
{
165+
return $this->tableprefix.$tablename;
166+
}
167+
168+
/**
169+
* Dump the statement's current parameters.
170+
*/
171+
public function dumpStatement()
172+
{
173+
return $this->stmt->debugDumpParams();
174+
}
175+
}

src/models/Handler.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* This is the session handler
4+
*
5+
* @package php-simple-sessions
6+
* @author Liam Kelly <https://github.com/likel>
7+
* @copyright 2017 Liam Kelly
8+
* @license MIT License <https://github.com/likel/fizz-buzz/blob/master/LICENSE>
9+
* @link https://github.com/likel/php-simple-sessions
10+
* @version 1.0.0
11+
*/
12+
namespace Likel\Session;
13+
14+
class Handler
15+
{
16+
// Helper variables used in the object
17+
private $DB;
18+
19+
/**
20+
* Construct the FizzBuzz object
21+
* Sets up the range, defaults to 1-100 if no range set
22+
*
23+
* @param int $range_min The minimum range for the sequence
24+
* @param int $range_max The maximum range for the sequence
25+
* @return void
26+
*/
27+
function __construct()
28+
{
29+
$this->DB = new Likel\Session\DB();
30+
}
31+
32+
/**
33+
* Sets the range for the FizzBuzz test
34+
* Expects is_numeric params
35+
*
36+
* @param int $range_min The minimum range for the sequence
37+
* @param int $range_max The maximum range for the sequence
38+
* @return void
39+
*/
40+
public function setRange($range_min, $range_max)
41+
{
42+
43+
}
44+
}

0 commit comments

Comments
 (0)