Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Symphony.General (general functions in JS) #1038

Closed
ghost opened this Issue · 14 comments

5 participants

@ghost

Exposing some general functions (like "General::createHandle") to JS.

@brendo
Owner

At this stage it's out of scope for the initial 2.3 release (not because it's difficult, but just because a line has to be drawn somewhere ;)).

The main way I see this working is using AJAX to hit up a dedicated page the exposes some of the General functions (where appropriate) for use in Javascript. Essentially it would work very similar to translations.

Possible exposure targets:

  • createHandle
  • createFilename
  • hash
  • formatFilesize
  • sanitize
  • reverse_sanitize
  • countWords
  • limitWords
  • validateURL
@designermonkey

I was just thinking that, about AJAX.

I don't mind doing this one, once we've got 2.3 out of the door, and the new JS model is laid down.

@nickdunn

Yeah createHandle would be super useful. Would a blocking AJAX request be performant? If not, it should be relatively simple to port most of the regex from the createHandle method to JS.

@nilshoerrmann

We discussed that in another thread here (I don't remember which though) and we concluded that – thinking about maintenance – it wouldn't be the best idea to replicate the needed code in JavaScript. So the idea was to use AJAX

Would a blocking AJAX request be performant?

The question is in which situations these functions are really needed (I cannot think of that many) and if in these cases a synchronous call is needed.

@ghost

If not, it should be relatively simple to port most of the regex from the createHandle method to JS.

I would prefer actually porting needed functions to JS instead of just making them available via Ajax. The latter would be a somewhat hacky approach, I don't think this is a route Symphony should take.

@brendo
Owner

Can you elaborate more about why you feel it's the wrong approach?

Having code in two different locations that does the same thing seems wrong to me. There are some functions in PHP that would cumbersome to replicate in Javascript (and probably vice versa) or might not be able to replicate the functionality which would mean slightly different results which could cause issues.

All Javascript translation is currently implemented with AJAX in a similar fashion to utilise the Lang class, so I don't see a reason why we shouldn't follow in it's footsteps.

@ghost

Can you elaborate more about why you feel it's the wrong approach?

Not really, sorry. Accessing PHP functions from JavaScript just feels wrong to me and I would have never thought of it to begin with, but maybe you're right, at least from a more practical point of view.

I tend to forget with whom I'm discussing here and that you guys already thought stuff through pretty well, at least most of the time.

@brendo
Owner

Heh, that's fine, I understand, it's just one of those 'in my gut it doesn't sit right' feelings :)

@ghost

Exactly ;)

@nilshoerrmann

Thr most important question is: why should we offer these functions in JavaScript? Are we convinced that they are needed?

@nickdunn

Why should we offer these functions in JavaScript? Are we convinced that they are needed?

Extensions. Several times I have recreated a createHandle function for my own use. But other than that I haven't needed the others. Brendo's list looks fine, but we shouldn't just expose them because we can. For sure.

@brendo
Owner

createHandle is probably the essential function.

I can see all of them being useful at some point (Drag & Drop file uploads), but it's a little chicken and egg I guess.

@benesch

I just happened across this issue, but I figured I'd throw in my two cents. I'm with Jens: I'd hate to see Symphony making network requests for what's essentially a couple regular expressions. At the least, you'd need to allow batch requests if someone needed to generate 100 handles on the fly. (Not that I can think of a use case.)

I can see the elegance in exposing the entire interface via AJAX, but if createHandle is the main draw, I think it's worth it to just port the function to Javascript. Ideally, you could store the transliterations as JSON so they'd be accessible to the JS.

@brendo
Owner

Bah. Been going around in circles when this functionality already exists for handles!

/symphony/ajax/handle/?string=Your String will return a handled version.

I think it's safe this is considered the most important function so far, so I'll close this issue.

@brendo brendo closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.