« first day (719 days earlier)      last day (4223 days later) » 

12:03 AM
Word
 
 
2 hours later…
1:34 AM
hi guys, i need a help with Ffmpeg-php...
 
what kind of help ?
 
 
2 hours later…
3:39 AM
stackoverflow.com/questions/12719730/… I would love to have my brain de-noobified
 
4:14 AM
@Stephane i was search for that answer.. its a good question
 
user895378
It's 12am where I live and I'm tired so I'm not going to write out a long answer. I just wanted to say this: I wholeheartedly DISAGREE with the current answers here. IOC is always a better answer than Singleton or globals. Anyone who says otherwise is either not unit-testing their code or not testing their code correctly. I saw that you posted a question over in PHP chat regarding this post. If you can visit the chat during the daytime (USA) there are generally several people around who will be able to help you in this endeavor. — rdlowrey 1 min ago
 
@SVarun Thanks! Please upvote!
 
hello,if possible have a look at this question,its related to jquery but i did not get any help for some time so posting it here.
http://stackoverflow.com/questions/12709986/changing-the-rows-and-columns-of-the-gallerific-plugin-dynamically
 
user895378
@Stephane I'm going to sleep, but there will be people around (as my comment mentions above) including myself who should be able to help you tomorrow
 
user895378
If you haven't gotten a satisfactory answer by then, that is.
 
4:17 AM
@Stephane np
 
@rdlowrey Thank you very much.
 
4:35 AM
@ShyamK I can't talk to you on my chat system right now because I've been locked out (too many server requests, because of AJAX polling). I'll be able to get back on in about an hour.
 
lol... kicked out of your own chat... :D
 
Ahoy hoy
 
Pirate Day again?
 
Every day is pirate day.
 
@ShyamK Well... locked out of my entire website :D
 
4:47 AM
.tk website... where is this tk actually?
nvm... Google says .tk is the Internet country code top-level domain (ccTLD) for Tokelau, a territory of New Zealand located in the South Pacific.
 
@ShyamK .TK domains are also free top-level domains.
 
5:12 AM
top-level?
 
@ShyamK Most free domain services only let you register a subdomain, e.g. example.co.cc or example.co.nr. Top-level domains: example.cc or example.nr.
 
Hello All.
 
hey Paul
 
Good Morning Everyone
 
@Stephane I agree with @rdlowrey you really got a bunch of answers that I also completely disagree with.
 
5:17 AM
@ShaquinTrifonoff oh... okay... I did not know that you could register as a sub-domain... I just assumed that you had to register as a top level one... but now that I think of it blogspot blogs are similar(vaguely) to personal websites and they have sub-domains...
 
4
Q: Dependency Injection: How to pass DB around?

StephaneEdit: This is a conceptual question first and foremost. I can make applications work without knowing this, but I'm trying to learn the concept. I've seen lots of videos with related classes and that makes sense, but when it comes to classes wrapping around other classes, I can't seem to grasp whe...

holy hell
every answer to that question is AWFUL
@Stephane if you're up for it i have a bit of time to help you now
 
@Stephane IOC seems like a lot of work. Everyone is scared that it creates more code to write in place of just creating an object (rather than injecting it). However the benefits you get with it are very real. Testability, plug and play injection of interfaces, a true separation of concerns.
 
that and it really isn't much more work
 
greetings, humans.
 
and in the long run, it is significantly less work to maintain
 
5:21 AM
@Lusitanian dang you're right. those answers suck
brb
 
Each object is a separate unit, your mind is free to think about each object separately.
 
Honestly I just lost five reputation by downvoting five answers consecutively
another case-in-point of you being right about traits
@Paul thinking about everything in terms of interfaces only is quite liberating
interesting --- this looks less crappy that the sf2 DI container
 
what is IOC? Cos when I googled for IOC I got Indian Oil Company
Is it Inversion of Control?
 
yes
 
Yes, type-hinting interfaces in PHP is pretty awesome.
 
5:28 AM
not really limited to php :P
 
@Lusitanian
 
k... gonna read up on that... thanks
 
I'm around if you're up for it. I really appreciate the help
 
i read your question
but now i forgot exactly what your problem is
so hold on while i re-read it
 
Ha
I have two basic questions:
 
5:29 AM
@ShyamK Yes, have a look for Misko Hevery. If you like watching videos he has some really good ones on IOC / Dependency injection (both are very much related).
 
Is it ok to instantiate a class within a class? If so, why? How do you test it?
2) Depends on the answer to 1.
If 1 is "yes" then I might not have an issue
 
In general the answer is no. "Don't look for things" is the simplified premise.
 
@ShyamK The link from Stephane's question, has a really good one.
 
so in a controller
 
@Paul I love watching videos... But I tend to get bored with videos after a couple of videos...
 
5:30 AM
it seems like people usually instantiate things there.. am I wrong?
 
@Paul I shall check that out... thanks :)
 
Well, who's definition of controller...
 
@ShyamK that video is really nice
 
you're probably right but referring to misguided people
 
yours
 
5:31 AM
the problem is, if we're talking M2VC
every web framework that i can think of gets the architecture entirely wrong
 
Pick any architecture
I'm totally open
 
okay
i'll go with MVP
simple, describes certain web frameworks that claim to be "MVC" well, etc
 
I just want to learn a pure way and then I can abandon it if I want/need/am pulling my hair out
 
lol
okay so you're concerned about passing the database object around, it seems
 
everything
let's start at the bottom of the stack
index.php
new Controller
yes?
 
5:33 AM
yes
now in some form or another
 
I used to have a call to new Controller, but now I have a call to new ControllerFactory
 
at your "front controller" (index.php, whatever term you want to use)
 
ok
 
you'll want to determine the dependencies necessary
@Paul shhhh --- we're doing this as simplified as possible
and for the record, if it's MVP it shouldn't really be called a controller but that's somewhat semantic so i'll set it aside
 
lol, things are never simple
 
5:34 AM
So I can have either a bunch of methods relating to actions/modules or a switch statement or soemthing?
what is it in MVP? Presentation?
 
presentor
 
@Paul true
 
I'd get whacked by @tereško for saying this [likely] but using a DIC properly isn't an anti-pattern, IMHO.
 
DIC?
 
dependency injection container
 
5:35 AM
Ah, I know what that is (but I haven't use one yet)
 
generally how i would implement it is, again simplified
an object which has a private array of closures
which each return an instance
 
example?
 
i'll try to find an implementation, too lazy to write one up now and can't pull one out of things i've written [for legal, not lazy reasons]
 
let's go with a url like: site.com/module/action/?stuff
 
that's an über-simple DIC
but if we forgo that for now....
so it hits your router
and we want to call ModulePresentor::action with the parameter stuff
 
5:39 AM
I'll have to dig into that link later. Thanks for finding that
ok
 
wow, this is already diverging pretty wildly from what I'd do. Interesting.
 
so as @Paul said you would probably want to use a factory to instantiate the presentor/controller/magical class that dumps stuff onto the screen
@Paul how so?
 
and what is the presenter's responsiblity?
 
oh, presentor = controller?
 
just to assemble classes?
 
5:40 AM
sorta ish
no
@Paul have you ever looked at an example symfony2 application that claims to be MVC?
It's actually MVP and what they call a controller is actually a presenter
 
teresko started talking to me about active views and I got all confused about controllers after that
 
This is, by the way, an architecture that is pretty bad in terms of code re-use.
 
not for a long time. That diagram looks good. oh, its bad?
 
That's what I thought MVC was: Presenter gets the info and passes it to the appropriate view
But then the model and view are instantiated in the presenter?
 
I wouldn't call it "bad" but RoR took the term MVC and made it to mean this.
@Stephane no, what you'd do
is inject the model factory/view factory or whatever you need into the presenter
and then get the models/views from the factories within the presenter
 
5:43 AM
so:
new view
new model
new presenter (view, model)
 
meh
that would work if you were sure that that's what you need
but say you have logic that determines which view you need
 
these are layers of things, I'm simplifying
 
okay, fair enough
then yes --- factories are your friend though, generally
 
but I'm happy to go deeper too
ok
 
inception? sorry bad joke
 
5:44 AM
reference? not intentional
:)
 
nah ignore me
it's 1:44 am and i should be doing homework anyway but i find this more fun
 
What are you studying?
 
various subjects, i'm in high school still
 
It turns out that this didn't diverge from what I do at all. That sounds good.
 
@Paul it's either good or bad, depending on what pattern you're trying to implement :)
 
5:46 AM
I don't know if this is a good time to ask this, but I'm curious about how to assemble multiple models at the factory level
I can give you a concrete example if you want
 
please do if you don't mind
 
Ok, so an application I actually work on is a school information system
and I have procedural functions that add and remove students from classes
 
I'm just putting the wikimedia MVC diagram here for reference because it shows the contrast between MVP/MVC
but okay fair enough
 
and when I add a student, I also have to add them to the attendance system and to the attendance reminder system
which involves the following areas of the application: students, teachers, attendance, roster, classes, and probably more.
this is not uncommon at all
 
alrighty
and that's all mapped to some sort of database i'd imagine?
 
5:48 AM
yes, although I'm trying to remove the 1:1 mapping of DB to model files
 
@Lusitanian (although, I think that is irrelevant)
 
?
@Stephane how are you mapping out of curiosity --- i'm guessing your own datamapper pattern implementation
 
yes, thats what makes it irrelevant the datamapper.
 
right -- it should be irrelevant but if its activerecord it isnt -- which is why activerecord is bad, violates separation of concerns
 
Well, right now the app is in transition. It has files called managers which have functions that extend a base manager for crud
and the model files do validation and list the properties (DB fields)
PDO
no ORM
 
5:50 AM
models can validate themselves, that's fine
how do you marshal the relations between the objects?
 
index call modules/mod-modulename.php:main
main has a switch based on the action
 
no i mean
In your database, you probably have a many-to-many relationship between students and teachers
 
if I have to update the attendance record, I do this: $DB = new DB();
$attender = new AttendManager($DB, new Attend());
$attender->insert($record);
for example
 
okay
alright, so your "Manager" classes are ostensibly data-mappers
i won't worry about the implementation
 
yes, and for now they are pretty inflexible. I don't have any caching or slave DBs.
yes, good. Ignore my implementation
 
5:54 AM
but what i do want to know is this
 
Oh I didn't see your relation question
 
if I say $student = $studentManager->fetchById(5);
then I can say
 
ok
 
$student->getAttendanceRecords();, etc? or am I mistaken? -- just not familiar with your codebase
 
Um, right now it would probably be in the attendanceManager, but I think that's because I'm used to doing things in a DB-centric way.
But yes, I do have functions like that
 
5:56 AM
yeah that's not good --- the relations should be marshalled to the objects
 
in the managers
 
but okay
 
explain?
marshalled?
 
literally just means assembled in order :P
 
ok
 
5:57 AM
so assuming we're eager loading all relations
when you do that fetch on the student
it should join its attendance records and teachers
then populate the object with them
 
This is an example of different IOC's. A hardcoded call to modules/mod-modulename.php:main vs having an injected datamapper that you call the fetch / save method on.
 
ok, so one question i have:
if I create an object class Student
 
@Paul of all the people I've ever tried to teach anything related to OOP here, this guy's actually learning. i'm really encouraged hehehe
 
@Lusitanian hehe, you've got a live one.
 
okay go on
 
5:58 AM
and I have properties like first_name, last_name, id, etc, I've debated having a property like Classes
because some of my methods pull data into groups of objects within an object
but that seems messy
 
what do you mean?
 
classes would be the classes the student has
 
right
if it's a relation to your database
and you actually want to map that relation to your code
it should be a property on the student object
 
even if I only use that property in one place?
 
well, that's where the concept of lazy loading comes in
 
6:00 AM
so I could have dozens or hundreds of properties?
 
dozens or hundreds? explain
 
Ok, so classes (the ones in classrooms) for instance.
 
lazy loading relations is a good idea depending on whether or not you always use those relations
 
they have a ton of info I could pull, like teachers, roster, class averages, etc
ok
it throws a notice, so I didn't know if that was ok
 
right and you don't want to populate a massive object graph from the database
 
6:01 AM
I would rather lazy load
 
what throws a notice?
huh?
 
doing: $student->non-declared-property = 'lazy load';
 
or $this->
 
that's not what i mean :)
 
6:02 AM
oh ha
 
okay, let's take lazy loading by proxy ---- which i believe is pretty common
so say we have a Student object that looks like this
 
i write a script for open poupbox, after page load when you click on button first time only loading image is displayed popup not open but when you click second time without page refresh its work.. hows?
 
class Student {
   private $id;
   private $name;
   private $classes; /// we don't want to automatically populate this

   // getters and setters go here
}
 
@Maulikpatel link to code helps
yes, great
 
@Stephane so instead of ALWAYS populating classes and then continuing down the object graph
you subclass Student like so
class ProxyStudent extends Student
and you don't override any of the methods for id/name because there's no point --- those are plain fields (string/integer/whatever) and will always be populated with the object
but you override your getClasses() method
 
6:05 AM
@Stephane corrently i working on local machine, so i think jqury loading problem?
 
so that it calls your mapper and tells it to fill in the relations
 
if I have 10 different types of student objects I want to use, would you suggest I make 10 extended classes?
 
tbh
i don't know enough about your application to tell you
 
@Maulikpatel you can paste it online and post a link
 
and i'm not advocating that this is the best way of loading relations lazily from a db
 
6:06 AM
I understand
I'll consider that
 
@Stephane but i have no FTP credential
 
That's pretty cool until I get into wanting to extend one way for classes and another way for grades realizing that I can't extend both into grades + classes
 
that doesn't make sense
 
Why? You can't in a diamond shape. Single inheritance, no?
I would have to create a new class.
That's ok though.
 
no, i mean
i don't understand what you're asking
 
6:09 AM
@Maulikpatel Yes, I think it is javascript. Its probably best to ask it in the javascript room.
 
in your proxy you'd lazily load both classes and grades
you don't need a separate class each
 
@Paul ya i know, but in js room no one available
 
Oh, I see. So if you needed condition A, B, A+B, you would just make a proxy for A+B
 
yeah, don't read too much into the whole proxy thing
i was just trying to explain lazy loading to you
 
@Maulikpatel you can also just make a post and link it to us
 
6:10 AM
but if you want to see an actual, not grossly oversimplified implementation
 
i want to know what the situation possible to occure this
 
@Lusitanian ok, I get it
 
you can look at doctrine2
 
ok, noted
So, I feel better about my models, didn't know I was going to get that. Let's see if I remember what you told me
Presenter gets passed a factoried model layer and a view layer?
 
@Maulikpatel That is not true. Anders said jsfiddle to you. Nobody can help you without seeing the code. Post it in the javascript room, not here.
 
6:13 AM
@Stephane more correctly, it gets passed the dependencies it needs
 
Ah, right
That's actually what I meant
 
so say you utilize the repository pattern
it gets passed your repository and a view instance
gets data from the repository
formats it someway or acts on it
 
how does the factory know what to assemble?
 
sends it to the view for rendering
that's what people do with symfony2 (which is btw explicitly labeled as NOT an MVC framework ---- thankfully)
 
do you think I should look at symfony code?
 
6:14 AM
no
don't
 
ok
 
imho you should understand patterns first before looking at implementations --- especially something like symfony which doesn't tbh have a clearly defined pattern
 
so let's say I'm trying to display Fred's classes
 
because it depends on people's usages of it
 
ok
 
6:15 AM
info.system/students/fred/classes
 
great
 
so you pass it to your router
it determines that we want the classes presenter
with a param $student = 'fred';
 
ok
 
what you get out of that totally depends on your routing rules
 
and I have a presenter for every view type?
 
6:16 AM
probably
alright so let's say we're favoring convention over configuration, and we know in our code
 
ok, some way of breaking up incoming requests into logical bunches
 
that if it's a presenter for "Classes" then we use our inflector to singularize it and know that we now need the "ClassRepository"
or we typehint or dependencies on the presenter's constructor
 
define inflector?
 
if we do that then the presentor's constructor looks like function __construct(ClassRepository $classRepo, View $view);
 
ah
ok
but we still need the $classRepo from some factory/repository/composer
 
6:19 AM
wait
getting to that
 
ok
 
so now let's jump back to our application entry point
which has just determined that we want to instantiate our ClassPresentor
so we use the reflection api of php and determine we need a ClassRepository and a View
now, depending on the complexity of your application you might mark different "services" with identifiers
and configure each controller so that it accepts a service like "main.class.repository" which is an instance of ClassRepository and "blah.view"
 
Ok, so the router broke up the request in variables which meant that classes gave us our presentor
 
but anyway
sorry i'm getting very tired and thus more unintelligible + i do have to go soon
 
ha that's ok, this is great. I really appreciate this
 
6:22 AM
thanks
so now we instantiate our presentor and give its dependencies via the constructor
then call the action on it ("show" or whatever)
with the parameters we've determined we have from the router
 
so we need to pass the request in
yes?
 
well
that depends if you consider it a dependency
 
or set it in the view
 
it might just be certain parameters from the query string or something -- who knows
 
or repository
yeah
I'm going to try to build something in the next couple of days. Maybe I'll find you on here again and show it to you.
 
6:24 AM
Hey @ShyamK, I managed to get back into my own site :P
 
alright
i idle here often
anyway i'm going to go to bed now
 
good night. Thank you for your time
 
yup
night
 
night @Lusitanian @Stephane If what you write is functional it would be a good thing for codereview.stackexchange.com
 
@Paul thanks, that's an awesome idea
I should be able to get something reasonably bare yet functional
 
7:25 AM
hi friends
any one there?
 

« first day (719 days earlier)      last day (4223 days later) »